Skip to content

Commit a9a91ad

Browse files
Romain GuyAndroid (Google) Code Review
authored andcommitted
Merge "Improve screenshot animation performance Bug #5525888" into ics-mr1
2 parents 564fee3 + 8279acb commit a9a91ad

File tree

2 files changed

+50
-85
lines changed

2 files changed

+50
-85
lines changed

packages/SystemUI/res/layout/global_screenshot.xml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,18 @@
1919
<ImageView android:id="@+id/global_screenshot_background"
2020
android:layout_width="match_parent"
2121
android:layout_height="match_parent"
22-
android:background="#FF000000"
22+
android:src="@android:color/black"
2323
android:visibility="gone" />
24-
<FrameLayout
25-
android:id="@+id/global_screenshot_container"
24+
<ImageView android:id="@+id/global_screenshot"
2625
android:layout_width="wrap_content"
2726
android:layout_height="wrap_content"
2827
android:layout_gravity="center"
2928
android:background="@drawable/screenshot_panel"
30-
android:visibility="gone">
31-
<ImageView android:id="@+id/global_screenshot"
32-
android:layout_width="wrap_content"
33-
android:layout_height="wrap_content"
34-
android:adjustViewBounds="true" />
35-
</FrameLayout>
29+
android:visibility="gone"
30+
android:adjustViewBounds="true" />
3631
<ImageView android:id="@+id/global_screenshot_flash"
3732
android:layout_width="match_parent"
3833
android:layout_height="match_parent"
39-
android:background="#FFFFFFFF"
34+
android:src="@android:color/white"
4035
android:visibility="gone" />
4136
</FrameLayout>

packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java

Lines changed: 45 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,17 @@
3838
import android.os.AsyncTask;
3939
import android.os.Environment;
4040
import android.os.Process;
41-
import android.os.ServiceManager;
4241
import android.provider.MediaStore;
4342
import android.util.DisplayMetrics;
4443
import android.view.Display;
45-
import android.view.IWindowManager;
4644
import android.view.LayoutInflater;
4745
import android.view.MotionEvent;
4846
import android.view.Surface;
4947
import android.view.View;
5048
import android.view.ViewGroup;
5149
import android.view.WindowManager;
5250
import android.view.animation.Interpolator;
53-
import android.widget.FrameLayout;
5451
import android.widget.ImageView;
55-
5652
import com.android.systemui.R;
5753

5854
import java.io.File;
@@ -77,19 +73,15 @@ class SaveImageInBackgroundData {
7773
*/
7874
class SaveImageInBackgroundTask extends AsyncTask<SaveImageInBackgroundData, Void,
7975
SaveImageInBackgroundData> {
80-
private static final String TAG = "SaveImageInBackgroundTask";
8176
private static final String SCREENSHOTS_DIR_NAME = "Screenshots";
8277
private static final String SCREENSHOT_FILE_NAME_TEMPLATE = "Screenshot_%s.png";
8378
private static final String SCREENSHOT_FILE_PATH_TEMPLATE = "%s/%s/%s";
8479

8580
private int mNotificationId;
8681
private NotificationManager mNotificationManager;
8782
private Notification.Builder mNotificationBuilder;
88-
private Intent mLaunchIntent;
89-
private String mImageDir;
9083
private String mImageFileName;
9184
private String mImageFilePath;
92-
private String mImageDate;
9385
private long mImageTime;
9486

9587
// WORKAROUND: We want the same notification across screenshots that we update so that we don't
@@ -105,11 +97,11 @@ class SaveImageInBackgroundTask extends AsyncTask<SaveImageInBackgroundData, Voi
10597

10698
// Prepare all the output metadata
10799
mImageTime = System.currentTimeMillis();
108-
mImageDate = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date(mImageTime));
109-
mImageDir = Environment.getExternalStoragePublicDirectory(
100+
String imageDate = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date(mImageTime));
101+
String imageDir = Environment.getExternalStoragePublicDirectory(
110102
Environment.DIRECTORY_PICTURES).getAbsolutePath();
111-
mImageFileName = String.format(SCREENSHOT_FILE_NAME_TEMPLATE, mImageDate);
112-
mImageFilePath = String.format(SCREENSHOT_FILE_PATH_TEMPLATE, mImageDir,
103+
mImageFileName = String.format(SCREENSHOT_FILE_NAME_TEMPLATE, imageDate);
104+
mImageFilePath = String.format(SCREENSHOT_FILE_PATH_TEMPLATE, imageDir,
113105
SCREENSHOTS_DIR_NAME, mImageFileName);
114106

115107
// Create the large notification icon
@@ -190,7 +182,7 @@ protected SaveImageInBackgroundData doInBackground(SaveImageInBackgroundData...
190182
}
191183

192184
return params[0];
193-
};
185+
}
194186

195187
@Override
196188
protected void onPostExecute(SaveImageInBackgroundData params) {
@@ -202,14 +194,14 @@ protected void onPostExecute(SaveImageInBackgroundData params) {
202194
Resources r = params.context.getResources();
203195

204196
// Create the intent to show the screenshot in gallery
205-
mLaunchIntent = new Intent(Intent.ACTION_VIEW);
206-
mLaunchIntent.setDataAndType(params.imageUri, "image/png");
207-
mLaunchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
197+
Intent launchIntent = new Intent(Intent.ACTION_VIEW);
198+
launchIntent.setDataAndType(params.imageUri, "image/png");
199+
launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
208200

209201
mNotificationBuilder
210202
.setContentTitle(r.getString(R.string.screenshot_saved_title))
211203
.setContentText(r.getString(R.string.screenshot_saved_text))
212-
.setContentIntent(PendingIntent.getActivity(params.context, 0, mLaunchIntent, 0))
204+
.setContentIntent(PendingIntent.getActivity(params.context, 0, launchIntent, 0))
213205
.setWhen(System.currentTimeMillis())
214206
.setAutoCancel(true);
215207

@@ -218,7 +210,7 @@ protected void onPostExecute(SaveImageInBackgroundData params) {
218210
mNotificationManager.notify(mNotificationId, n);
219211
}
220212
params.finisher.run();
221-
};
213+
}
222214
}
223215

224216
/**
@@ -228,7 +220,6 @@ protected void onPostExecute(SaveImageInBackgroundData params) {
228220
* type of gallery?
229221
*/
230222
class GlobalScreenshot {
231-
private static final String TAG = "GlobalScreenshot";
232223
private static final int SCREENSHOT_NOTIFICATION_ID = 789;
233224
private static final int SCREENSHOT_FLASH_TO_PEAK_DURATION = 130;
234225
private static final int SCREENSHOT_DROP_IN_DURATION = 430;
@@ -244,8 +235,6 @@ class GlobalScreenshot {
244235
private static final float SCREENSHOT_DROP_OUT_MIN_SCALE_OFFSET = 0f;
245236

246237
private Context mContext;
247-
private LayoutInflater mLayoutInflater;
248-
private IWindowManager mIWindowManager;
249238
private WindowManager mWindowManager;
250239
private WindowManager.LayoutParams mWindowLayoutParams;
251240
private NotificationManager mNotificationManager;
@@ -256,7 +245,6 @@ class GlobalScreenshot {
256245
private Bitmap mScreenBitmap;
257246
private View mScreenshotLayout;
258247
private ImageView mBackgroundView;
259-
private FrameLayout mScreenshotContainerView;
260248
private ImageView mScreenshotView;
261249
private ImageView mScreenshotFlash;
262250

@@ -273,14 +261,13 @@ class GlobalScreenshot {
273261
public GlobalScreenshot(Context context) {
274262
Resources r = context.getResources();
275263
mContext = context;
276-
mLayoutInflater = (LayoutInflater)
264+
LayoutInflater layoutInflater = (LayoutInflater)
277265
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
278266

279267
// Inflate the screenshot layout
280268
mDisplayMatrix = new Matrix();
281-
mScreenshotLayout = mLayoutInflater.inflate(R.layout.global_screenshot, null);
269+
mScreenshotLayout = layoutInflater.inflate(R.layout.global_screenshot, null);
282270
mBackgroundView = (ImageView) mScreenshotLayout.findViewById(R.id.global_screenshot_background);
283-
mScreenshotContainerView = (FrameLayout) mScreenshotLayout.findViewById(R.id.global_screenshot_container);
284271
mScreenshotView = (ImageView) mScreenshotLayout.findViewById(R.id.global_screenshot);
285272
mScreenshotFlash = (ImageView) mScreenshotLayout.findViewById(R.id.global_screenshot_flash);
286273
mScreenshotLayout.setFocusable(true);
@@ -293,8 +280,6 @@ public boolean onTouch(View v, MotionEvent event) {
293280
});
294281

295282
// Setup the window that we are going to use
296-
mIWindowManager = IWindowManager.Stub.asInterface(
297-
ServiceManager.getService(Context.WINDOW_SERVICE));
298283
mWindowLayoutParams = new WindowManager.LayoutParams(
299284
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 0, 0,
300285
WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY,
@@ -428,8 +413,8 @@ public void onAnimationEnd(Animator animation) {
428413
mScreenshotLayout.post(new Runnable() {
429414
@Override
430415
public void run() {
431-
mScreenshotContainerView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
432-
mScreenshotContainerView.buildLayer();
416+
mScreenshotView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
417+
mScreenshotView.buildLayer();
433418
mScreenshotAnimation.start();
434419
}
435420
});
@@ -463,20 +448,16 @@ public float getInterpolation(float x) {
463448
anim.addListener(new AnimatorListenerAdapter() {
464449
@Override
465450
public void onAnimationStart(Animator animation) {
466-
mBackgroundView.setFastAlpha(0f);
451+
mBackgroundView.setAlpha(0f);
467452
mBackgroundView.setVisibility(View.VISIBLE);
468-
mBackgroundView.fastInvalidate();
469-
mScreenshotContainerView.setFastAlpha(0f);
470-
mScreenshotContainerView.setFastTranslationX(0f);
471-
mScreenshotContainerView.setFastTranslationY(0f);
472-
mScreenshotContainerView.setFastScaleX(SCREENSHOT_SCALE + mBgPaddingScale);
473-
mScreenshotContainerView.setFastScaleY(SCREENSHOT_SCALE + mBgPaddingScale);
474-
mScreenshotContainerView.setVisibility(View.VISIBLE);
475-
mScreenshotContainerView.fastInvalidate();
476-
mScreenshotFlash.setFastAlpha(0f);
453+
mScreenshotView.setAlpha(0f);
454+
mScreenshotView.setTranslationX(0f);
455+
mScreenshotView.setTranslationY(0f);
456+
mScreenshotView.setScaleX(SCREENSHOT_SCALE + mBgPaddingScale);
457+
mScreenshotView.setScaleY(SCREENSHOT_SCALE + mBgPaddingScale);
458+
mScreenshotView.setVisibility(View.VISIBLE);
459+
mScreenshotFlash.setAlpha(0f);
477460
mScreenshotFlash.setVisibility(View.VISIBLE);
478-
mScreenshotFlash.fastInvalidate();
479-
mScreenshotLayout.invalidate();
480461
}
481462
@Override
482463
public void onAnimationEnd(android.animation.Animator animation) {
@@ -486,19 +467,15 @@ public void onAnimationEnd(android.animation.Animator animation) {
486467
anim.addUpdateListener(new AnimatorUpdateListener() {
487468
@Override
488469
public void onAnimationUpdate(ValueAnimator animation) {
489-
float t = ((Float) animation.getAnimatedValue()).floatValue();
470+
float t = (Float) animation.getAnimatedValue();
490471
float scaleT = (SCREENSHOT_SCALE + mBgPaddingScale)
491-
- (float) scaleInterpolator.getInterpolation(t)
472+
- scaleInterpolator.getInterpolation(t)
492473
* (SCREENSHOT_SCALE - SCREENSHOT_DROP_IN_MIN_SCALE);
493-
mBackgroundView.setFastAlpha(scaleInterpolator.getInterpolation(t) * BACKGROUND_ALPHA);
494-
mBackgroundView.fastInvalidate();
495-
mScreenshotContainerView.setFastAlpha(t);
496-
mScreenshotContainerView.setFastScaleX(scaleT);
497-
mScreenshotContainerView.setFastScaleY(scaleT);
498-
mScreenshotContainerView.fastInvalidate();
499-
mScreenshotFlash.setFastAlpha(flashAlphaInterpolator.getInterpolation(t));
500-
mScreenshotFlash.fastInvalidate();
501-
mScreenshotLayout.invalidate();
474+
mBackgroundView.setAlpha(scaleInterpolator.getInterpolation(t) * BACKGROUND_ALPHA);
475+
mScreenshotView.setAlpha(t);
476+
mScreenshotView.setScaleX(scaleT);
477+
mScreenshotView.setScaleY(scaleT);
478+
mScreenshotFlash.setAlpha(flashAlphaInterpolator.getInterpolation(t));
502479
}
503480
});
504481
return anim;
@@ -511,8 +488,8 @@ private ValueAnimator createScreenshotDropOutAnimation(int w, int h, boolean sta
511488
@Override
512489
public void onAnimationEnd(Animator animation) {
513490
mBackgroundView.setVisibility(View.GONE);
514-
mScreenshotContainerView.setVisibility(View.GONE);
515-
mScreenshotContainerView.setLayerType(View.LAYER_TYPE_NONE, null);
491+
mScreenshotView.setVisibility(View.GONE);
492+
mScreenshotView.setLayerType(View.LAYER_TYPE_NONE, null);
516493
}
517494
});
518495

@@ -522,17 +499,13 @@ public void onAnimationEnd(Animator animation) {
522499
anim.addUpdateListener(new AnimatorUpdateListener() {
523500
@Override
524501
public void onAnimationUpdate(ValueAnimator animation) {
525-
float t = ((Float) animation.getAnimatedValue()).floatValue();
502+
float t = (Float) animation.getAnimatedValue();
526503
float scaleT = (SCREENSHOT_DROP_IN_MIN_SCALE + mBgPaddingScale)
527-
- (float) t * (SCREENSHOT_DROP_IN_MIN_SCALE
528-
- SCREENSHOT_FAST_DROP_OUT_MIN_SCALE);
529-
mBackgroundView.setFastAlpha((1f - t) * BACKGROUND_ALPHA);
530-
mBackgroundView.fastInvalidate();
531-
mScreenshotContainerView.setFastAlpha(1f - t);
532-
mScreenshotContainerView.setFastScaleX(scaleT);
533-
mScreenshotContainerView.setFastScaleY(scaleT);
534-
mScreenshotContainerView.fastInvalidate();
535-
mScreenshotLayout.invalidate();
504+
- t * (SCREENSHOT_DROP_IN_MIN_SCALE - SCREENSHOT_FAST_DROP_OUT_MIN_SCALE);
505+
mBackgroundView.setAlpha((1f - t) * BACKGROUND_ALPHA);
506+
mScreenshotView.setAlpha(1f - t);
507+
mScreenshotView.setScaleX(scaleT);
508+
mScreenshotView.setScaleY(scaleT);
536509
}
537510
});
538511
} else {
@@ -563,19 +536,16 @@ public float getInterpolation(float x) {
563536
anim.addUpdateListener(new AnimatorUpdateListener() {
564537
@Override
565538
public void onAnimationUpdate(ValueAnimator animation) {
566-
float t = ((Float) animation.getAnimatedValue()).floatValue();
539+
float t = (Float) animation.getAnimatedValue();
567540
float scaleT = (SCREENSHOT_DROP_IN_MIN_SCALE + mBgPaddingScale)
568-
- (float) scaleInterpolator.getInterpolation(t)
541+
- scaleInterpolator.getInterpolation(t)
569542
* (SCREENSHOT_DROP_IN_MIN_SCALE - SCREENSHOT_DROP_OUT_MIN_SCALE);
570-
mBackgroundView.setFastAlpha((1f - t) * BACKGROUND_ALPHA);
571-
mBackgroundView.fastInvalidate();
572-
mScreenshotContainerView.setFastAlpha(1f - scaleInterpolator.getInterpolation(t));
573-
mScreenshotContainerView.setFastScaleX(scaleT);
574-
mScreenshotContainerView.setFastScaleY(scaleT);
575-
mScreenshotContainerView.setFastTranslationX(t * finalPos.x);
576-
mScreenshotContainerView.setFastTranslationY(t * finalPos.y);
577-
mScreenshotContainerView.fastInvalidate();
578-
mScreenshotLayout.invalidate();
543+
mBackgroundView.setAlpha((1f - t) * BACKGROUND_ALPHA);
544+
mScreenshotView.setAlpha(1f - scaleInterpolator.getInterpolation(t));
545+
mScreenshotView.setScaleX(scaleT);
546+
mScreenshotView.setScaleY(scaleT);
547+
mScreenshotView.setTranslationX(t * finalPos.x);
548+
mScreenshotView.setTranslationY(t * finalPos.y);
579549
}
580550
});
581551
}

0 commit comments

Comments
 (0)