diff options
author | Dianne Hackborn <hackbod@google.com> | 2011-08-17 16:20:47 -0700 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2011-08-17 17:45:05 -0700 |
commit | fc8fa638617efb5695a1f89ea75375faebbe2a40 (patch) | |
tree | 685aeed4995ea17399accf5d46545038235d5105 /packages/SystemUI/src/com/android/systemui/screenshot | |
parent | 9a5505f0253a9114aea6192a22da6ec1c1b85ed2 (diff) | |
download | frameworks_base-fc8fa638617efb5695a1f89ea75375faebbe2a40.zip frameworks_base-fc8fa638617efb5695a1f89ea75375faebbe2a40.tar.gz frameworks_base-fc8fa638617efb5695a1f89ea75375faebbe2a40.tar.bz2 |
Fix issue #5128639: SystemUI grows by 10MB after taking a screenshot
We now do the screenshot in a separate process.
Also change the recents panel to not use hardware acceleration
on lower-end devices. And improve how it gets shown to not
load all data up-front which results in a long delay when you have
lots of recents.
Change-Id: Ia309a90f9939e5405758621b3f7114597bd0c02a
Diffstat (limited to 'packages/SystemUI/src/com/android/systemui/screenshot')
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java | 17 | ||||
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/screenshot/TakeScreenshotService.java | 32 |
2 files changed, 36 insertions, 13 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java b/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java index 86dc9a6..fe255cb 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java @@ -69,6 +69,7 @@ import java.util.Date; class SaveImageInBackgroundData { Context context; Bitmap image; + Runnable finisher; int result; } @@ -141,6 +142,7 @@ class SaveImageInBackgroundTask extends AsyncTask<SaveImageInBackgroundData, Voi Toast.makeText(params.context, R.string.screenshot_saving_toast, Toast.LENGTH_SHORT).show(); } + params.finisher.run(); }; } @@ -231,11 +233,9 @@ class GlobalScreenshot { WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED_SYSTEM - | WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED, PixelFormat.TRANSLUCENT); - mWindowLayoutParams.token = new Binder(); mWindowLayoutParams.setTitle("ScreenshotAnimation"); mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); mDisplay = mWindowManager.getDefaultDisplay(); @@ -244,10 +244,11 @@ class GlobalScreenshot { /** * Creates a new worker thread and saves the screenshot to the media store. */ - private void saveScreenshotInWorkerThread() { + private void saveScreenshotInWorkerThread(Runnable finisher) { SaveImageInBackgroundData data = new SaveImageInBackgroundData(); data.context = mContext; data.image = mScreenBitmap; + data.finisher = finisher; new SaveImageInBackgroundTask().execute(data); } @@ -269,7 +270,7 @@ class GlobalScreenshot { /** * Takes a screenshot of the current display and shows an animation. */ - void takeScreenshot() { + void takeScreenshot(Runnable finisher) { // We need to orient the screenshot correctly (and the Surface api seems to take screenshots // only in the natural orientation of the device :!) mDisplay.getRealMetrics(mDisplayMetrics); @@ -302,18 +303,19 @@ class GlobalScreenshot { if (mScreenBitmap == null) { Toast.makeText(mContext, R.string.screenshot_failed_toast, Toast.LENGTH_SHORT).show(); + finisher.run(); return; } // Start the post-screenshot animation - startAnimation(); + startAnimation(finisher); } /** * Starts the animation after taking the screenshot */ - private void startAnimation() { + private void startAnimation(final Runnable finisher) { // Add the view for the animation mScreenshotView.setImageBitmap(mScreenBitmap); mScreenshotLayout.requestFocus(); @@ -332,8 +334,7 @@ class GlobalScreenshot { @Override public void onAnimationEnd(Animator animation) { // Save the screenshot once we have a bit of time now - saveScreenshotInWorkerThread(); - + saveScreenshotInWorkerThread(finisher); mWindowManager.removeView(mScreenshotLayout); } }); diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/TakeScreenshotService.java b/packages/SystemUI/src/com/android/systemui/screenshot/TakeScreenshotService.java index 35eaedf..05ff8be 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/TakeScreenshotService.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/TakeScreenshotService.java @@ -26,7 +26,11 @@ import android.net.Uri; import android.hardware.usb.UsbAccessory; import android.hardware.usb.UsbManager; import android.os.Bundle; +import android.os.Handler; import android.os.IBinder; +import android.os.Message; +import android.os.Messenger; +import android.os.RemoteException; import android.util.Log; import com.android.internal.app.AlertActivity; @@ -39,12 +43,30 @@ public class TakeScreenshotService extends Service { private static GlobalScreenshot mScreenshot; + private Handler mHandler = new Handler() { + @Override + public void handleMessage(Message msg) { + switch (msg.what) { + case 1: + final Messenger callback = msg.replyTo; + if (mScreenshot == null) { + mScreenshot = new GlobalScreenshot(TakeScreenshotService.this); + } + mScreenshot.takeScreenshot(new Runnable() { + @Override public void run() { + Message reply = Message.obtain(null, 1); + try { + callback.send(reply); + } catch (RemoteException e) { + } + } + }); + } + } + }; + @Override public IBinder onBind(Intent intent) { - if (mScreenshot == null) { - mScreenshot = new GlobalScreenshot(this); - } - mScreenshot.takeScreenshot(); - return null; + return new Messenger(mHandler).getBinder(); } } |