diff options
author | Pankaj Garg <pgarg@codeaurora.org> | 2015-08-04 16:19:14 -0700 |
---|---|---|
committer | jrizzoli <joey@cyanogenmoditalia.it> | 2015-08-28 13:15:47 +0200 |
commit | b4b4f0102799b11184fd28655ed47e33cc78afdb (patch) | |
tree | e016d7dc4181150605e299fd8bfde57839c40f69 | |
parent | 13531caab583da2d6d6398bccf7bb6d98ddfae03 (diff) | |
download | android_packages_apps_Gello-b4b4f0102799b11184fd28655ed47e33cc78afdb.tar.gz android_packages_apps_Gello-b4b4f0102799b11184fd28655ed47e33cc78afdb.tar.bz2 android_packages_apps_Gello-b4b4f0102799b11184fd28655ed47e33cc78afdb.zip |
Added timer to unblock UI for tab switching
- A timer that unblocks UI if capture does not return
when user presses tab switcher
Change-Id: Ibabaf4af804a1f2de236e4617fba6d66c8a8a4ca
-rw-r--r-- | src/com/android/browser/PhoneUi.java | 94 | ||||
-rw-r--r-- | src/com/android/browser/Tab.java | 2 |
2 files changed, 67 insertions, 29 deletions
diff --git a/src/com/android/browser/PhoneUi.java b/src/com/android/browser/PhoneUi.java index 063a21c3..ab4174fd 100644 --- a/src/com/android/browser/PhoneUi.java +++ b/src/com/android/browser/PhoneUi.java @@ -26,6 +26,7 @@ import android.content.Context; import android.graphics.Bitmap; import android.graphics.Matrix; import android.os.Bundle; +import android.os.CountDownTimer; import android.util.Log; import android.view.ActionMode; import android.view.KeyEvent; @@ -60,6 +61,8 @@ public class PhoneUi extends BaseUi { boolean mShowNav = false; private ComboView mComboView; + private CountDownTimer mCaptureTimer; + private static final int mCaptureMaxWaitMS = 1000; /** * @param browser @@ -269,41 +272,75 @@ public class PhoneUi extends BaseUi { mNavScreenRequested = false; } + private void thumbnailUpdated(Tab t) { + mTabControl.setOnThumbnailUpdatedListener(null); + + // Discard the callback if the req is interrupted + if (!mNavScreenRequested) { + unblockEvents(); + return; + } + + Bitmap bm = t.getScreenshot(); + if (bm == null) { + t.initCaptureBitmap(); + bm = t.getScreenshot(); + } + + Bitmap sbm; + WebView webView = getWebView(); + if (webView != null) { + int view_width = webView.getWidth(); + int capture_width = mActivity.getResources().getDimensionPixelSize( + R.dimen.tab_thumbnail_width); + + float scale = (float) view_width / capture_width; + + //Upscale the low-res bitmap to the needed size + Matrix m = new Matrix(); + m.postScale(scale, scale); + sbm = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), + bm.getHeight(), m, false); + } else { + sbm = bm; + } + + onShowNavScreenContinue(sbm); + } + + private void startCaptureTimer(final Tab tab) { + mCaptureTimer = new CountDownTimer(mCaptureMaxWaitMS, mCaptureMaxWaitMS) { + @Override + public void onTick(long millisUntilFinished) { + // Do nothing + } + + @Override + public void onFinish() { + Log.e(LOGTAG, "Screen capture timed out while showing navigation screen"); + thumbnailUpdated(tab); + } + }.start(); + } + + private void stopCaptureTimer() { + if (mCaptureTimer != null) { + mCaptureTimer.cancel(); + mCaptureTimer = null; + } + } + void showNavScreen() { blockEvents(); + stopCaptureTimer(); + mNavScreenRequested = true; mTabControl.setOnThumbnailUpdatedListener( new TabControl.OnThumbnailUpdatedListener() { @Override public void onThumbnailUpdated(Tab t) { - mTabControl.setOnThumbnailUpdatedListener(null); - - // Discard the callback if the req is interrupted - if (!mNavScreenRequested) { - unblockEvents(); - return; - } - - Bitmap bm = t.getScreenshot(); - Bitmap sbm; - WebView webView = getWebView(); - if (webView != null) { - int view_width = webView.getWidth(); - int capture_width = mActivity.getResources().getDimensionPixelSize( - R.dimen.tab_thumbnail_width); - - float scale = (float) view_width / capture_width; - - //Upscale the low-res bitmap to the needed size - Matrix m = new Matrix(); - m.postScale(scale, scale); - sbm = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), - bm.getHeight(), m, false); - } else { - sbm = bm; - } - - onShowNavScreenContinue(sbm); + stopCaptureTimer(); + thumbnailUpdated(t); } }); if (!BrowserSettings.getInstance().isPowerSaveModeEnabled()) { @@ -311,6 +348,7 @@ public class PhoneUi extends BaseUi { NetworkServices.hintUpcomingUserActivity(); } mActiveTab.capture(); + startCaptureTimer(mActiveTab); } void onShowNavScreenContinue(Bitmap viewportBitmap) { diff --git a/src/com/android/browser/Tab.java b/src/com/android/browser/Tab.java index bb1ec9da..e18cb2ac 100644 --- a/src/com/android/browser/Tab.java +++ b/src/com/android/browser/Tab.java @@ -1202,7 +1202,7 @@ class Tab implements PictureListener { mTabHistoryUpdateObservable = new Observable(); } - private void initCaptureBitmap() { + public void initCaptureBitmap() { mCapture = Bitmap.createBitmap(mCaptureWidth, mCaptureHeight, Bitmap.Config.RGB_565); mCapture.eraseColor(Color.WHITE); } |