Merge "Last update for screenshot animations for MR0. (Bug: 5333706)" into ics-mr0

This commit is contained in:
Winson Chung
2011-10-21 11:07:06 -07:00
committed by Android (Google) Code Review
9 changed files with 99 additions and 66 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 358 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 595 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 358 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 404 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 671 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 797 B

View File

@@ -26,11 +26,16 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
android:background="@drawable/global_screenshot_background" android:background="@drawable/screenshot_panel"
android:visibility="gone"> android:visibility="gone">
<ImageView android:id="@+id/global_screenshot" <ImageView android:id="@+id/global_screenshot"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:adjustViewBounds="true" /> android:adjustViewBounds="true" />
</FrameLayout> </FrameLayout>
<ImageView android:id="@+id/global_screenshot_flash"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFFFF"
android:visibility="gone" />
</FrameLayout> </FrameLayout>

View File

@@ -89,9 +89,6 @@
<dimen name="collapse_accel">2000dp</dimen> <dimen name="collapse_accel">2000dp</dimen>
<!-- The padding on the global screenshot background image --> <!-- The padding on the global screenshot background image -->
<dimen name="global_screenshot_bg_padding">0dp</dimen> <dimen name="global_screenshot_bg_padding">20dp</dimen>
<!-- The top-left offset for the screenshot drop animation target bounds -->
<dimen name="global_screenshot_drop_offset_x">6dp</dimen>
<dimen name="global_screenshot_drop_offset_y">0dp</dimen>
</resources> </resources>

View File

@@ -34,7 +34,6 @@ import android.graphics.Canvas;
import android.graphics.Matrix; import android.graphics.Matrix;
import android.graphics.PixelFormat; import android.graphics.PixelFormat;
import android.graphics.PointF; import android.graphics.PointF;
import android.graphics.RectF;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Environment; import android.os.Environment;
@@ -52,6 +51,7 @@ import android.view.ViewGroup;
import android.view.WindowManager; import android.view.WindowManager;
import android.view.animation.AccelerateInterpolator; import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator; import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ImageView; import android.widget.ImageView;
@@ -229,15 +229,18 @@ class SaveImageInBackgroundTask extends AsyncTask<SaveImageInBackgroundData, Voi
class GlobalScreenshot { class GlobalScreenshot {
private static final String TAG = "GlobalScreenshot"; private static final String TAG = "GlobalScreenshot";
private static final int SCREENSHOT_NOTIFICATION_ID = 789; private static final int SCREENSHOT_NOTIFICATION_ID = 789;
private static final int SCREENSHOT_FADE_IN_DURATION = 250; private static final int SCREENSHOT_FLASH_TO_PEAK_DURATION = 130;
private static final int SCREENSHOT_FADE_OUT_DELAY = 750; private static final int SCREENSHOT_DROP_IN_DURATION = 430;
private static final int SCREENSHOT_FADE_OUT_DURATION = 500; private static final int SCREENSHOT_DROP_OUT_DELAY = 500;
private static final int SCREENSHOT_FAST_FADE_OUT_DURATION = 350; private static final int SCREENSHOT_DROP_OUT_DURATION = 430;
private static final float BACKGROUND_ALPHA = 0.65f; private static final int SCREENSHOT_DROP_OUT_SCALE_DURATION = 370;
private static final float SCREENSHOT_SCALE_FUDGE = 0.075f; // To account for the border padding private static final int SCREENSHOT_FAST_DROP_OUT_DURATION = 320;
private static final float SCREENSHOT_SCALE = 0.55f; private static final float BACKGROUND_ALPHA = 0.5f;
private static final float SCREENSHOT_FADE_IN_MIN_SCALE = SCREENSHOT_SCALE * 0.975f; private static final float SCREENSHOT_SCALE = 1f;
private static final float SCREENSHOT_FADE_OUT_MIN_SCALE = SCREENSHOT_SCALE * 0.925f; private static final float SCREENSHOT_DROP_IN_MIN_SCALE = SCREENSHOT_SCALE * 0.725f;
private static final float SCREENSHOT_DROP_OUT_MIN_SCALE = SCREENSHOT_SCALE * 0.45f;
private static final float SCREENSHOT_FAST_DROP_OUT_MIN_SCALE = SCREENSHOT_SCALE * 0.6f;
private static final float SCREENSHOT_DROP_OUT_MIN_SCALE_OFFSET = 0f;
private Context mContext; private Context mContext;
private LayoutInflater mLayoutInflater; private LayoutInflater mLayoutInflater;
@@ -254,13 +257,11 @@ class GlobalScreenshot {
private ImageView mBackgroundView; private ImageView mBackgroundView;
private FrameLayout mScreenshotContainerView; private FrameLayout mScreenshotContainerView;
private ImageView mScreenshotView; private ImageView mScreenshotView;
private ImageView mScreenshotFlash;
private AnimatorSet mScreenshotAnimation; private AnimatorSet mScreenshotAnimation;
private int mStatusBarIconSize;
private int mNotificationIconSize; private int mNotificationIconSize;
private float mDropOffsetX;
private float mDropOffsetY;
private float mBgPadding; private float mBgPadding;
private float mBgPaddingScale; private float mBgPaddingScale;
@@ -280,6 +281,7 @@ class GlobalScreenshot {
mBackgroundView = (ImageView) mScreenshotLayout.findViewById(R.id.global_screenshot_background); mBackgroundView = (ImageView) mScreenshotLayout.findViewById(R.id.global_screenshot_background);
mScreenshotContainerView = (FrameLayout) mScreenshotLayout.findViewById(R.id.global_screenshot_container); mScreenshotContainerView = (FrameLayout) mScreenshotLayout.findViewById(R.id.global_screenshot_container);
mScreenshotView = (ImageView) mScreenshotLayout.findViewById(R.id.global_screenshot); mScreenshotView = (ImageView) mScreenshotLayout.findViewById(R.id.global_screenshot);
mScreenshotFlash = (ImageView) mScreenshotLayout.findViewById(R.id.global_screenshot_flash);
mScreenshotLayout.setFocusable(true); mScreenshotLayout.setFocusable(true);
mScreenshotLayout.setOnTouchListener(new View.OnTouchListener() { mScreenshotLayout.setOnTouchListener(new View.OnTouchListener() {
@Override @Override
@@ -309,16 +311,12 @@ class GlobalScreenshot {
mDisplay.getRealMetrics(mDisplayMetrics); mDisplay.getRealMetrics(mDisplayMetrics);
// Get the various target sizes // Get the various target sizes
mStatusBarIconSize =
r.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_icon_size);
mNotificationIconSize = mNotificationIconSize =
r.getDimensionPixelSize(android.R.dimen.notification_large_icon_height); r.getDimensionPixelSize(android.R.dimen.notification_large_icon_height);
mDropOffsetX = r.getDimensionPixelSize(R.dimen.global_screenshot_drop_offset_x);
mDropOffsetY = r.getDimensionPixelSize(R.dimen.global_screenshot_drop_offset_y);
// Scale has to account for both sides of the bg // Scale has to account for both sides of the bg
mBgPadding = (float) r.getDimensionPixelSize(R.dimen.global_screenshot_bg_padding); mBgPadding = (float) r.getDimensionPixelSize(R.dimen.global_screenshot_bg_padding);
mBgPaddingScale = (2f * mBgPadding) / mDisplayMetrics.widthPixels; mBgPaddingScale = mBgPadding / mDisplayMetrics.widthPixels;
} }
/** /**
@@ -413,11 +411,11 @@ class GlobalScreenshot {
} }
mWindowManager.addView(mScreenshotLayout, mWindowLayoutParams); mWindowManager.addView(mScreenshotLayout, mWindowLayoutParams);
ValueAnimator screenshotFadeInAnim = createScreenshotFadeInAnimation(); ValueAnimator screenshotDropInAnim = createScreenshotDropInAnimation();
ValueAnimator screenshotFadeOutAnim = createScreenshotFadeOutAnimation(w, h, ValueAnimator screenshotFadeOutAnim = createScreenshotDropOutAnimation(w, h,
statusBarVisible, navBarVisible); statusBarVisible, navBarVisible);
mScreenshotAnimation = new AnimatorSet(); mScreenshotAnimation = new AnimatorSet();
mScreenshotAnimation.play(screenshotFadeInAnim).before(screenshotFadeOutAnim); mScreenshotAnimation.playSequentially(screenshotDropInAnim, screenshotFadeOutAnim);
mScreenshotAnimation.addListener(new AnimatorListenerAdapter() { mScreenshotAnimation.addListener(new AnimatorListenerAdapter() {
@Override @Override
public void onAnimationEnd(Animator animation) { public void onAnimationEnd(Animator animation) {
@@ -435,42 +433,71 @@ class GlobalScreenshot {
} }
}); });
} }
private ValueAnimator createScreenshotFadeInAnimation() { private ValueAnimator createScreenshotDropInAnimation() {
final float flashPeakDurationPct = ((float) (SCREENSHOT_FLASH_TO_PEAK_DURATION)
/ SCREENSHOT_DROP_IN_DURATION);
final float flashDurationPct = 2f * flashPeakDurationPct;
final Interpolator flashAlphaInterpolator = new Interpolator() {
@Override
public float getInterpolation(float x) {
// Flash the flash view in and out quickly
if (x <= flashDurationPct) {
return (float) Math.sin(Math.PI * (x / flashDurationPct));
}
return 0;
}
};
final Interpolator scaleInterpolator = new Interpolator() {
@Override
public float getInterpolation(float x) {
// We start scaling when the flash is at it's peak
if (x < flashPeakDurationPct) {
return 0;
}
return (x - flashDurationPct) / (1f - flashDurationPct);
}
};
ValueAnimator anim = ValueAnimator.ofFloat(0f, 1f); ValueAnimator anim = ValueAnimator.ofFloat(0f, 1f);
anim.setInterpolator(new AccelerateInterpolator(1.5f)); anim.setDuration(SCREENSHOT_DROP_IN_DURATION);
anim.setDuration(SCREENSHOT_FADE_IN_DURATION);
anim.addListener(new AnimatorListenerAdapter() { anim.addListener(new AnimatorListenerAdapter() {
@Override @Override
public void onAnimationStart(Animator animation) { public void onAnimationStart(Animator animation) {
mBackgroundView.setAlpha(0f); mBackgroundView.setAlpha(0f);
mBackgroundView.setVisibility(View.VISIBLE); mBackgroundView.setVisibility(View.VISIBLE);
mScreenshotContainerView.setAlpha(0f);
mScreenshotContainerView.setTranslationX(0f); mScreenshotContainerView.setTranslationX(0f);
mScreenshotContainerView.setTranslationY(0f); mScreenshotContainerView.setTranslationY(0f);
mScreenshotContainerView.setScaleX(SCREENSHOT_FADE_IN_MIN_SCALE); mScreenshotContainerView.setScaleX(SCREENSHOT_SCALE + mBgPaddingScale);
mScreenshotContainerView.setScaleY(SCREENSHOT_FADE_IN_MIN_SCALE); mScreenshotContainerView.setScaleY(SCREENSHOT_SCALE + mBgPaddingScale);
mScreenshotContainerView.setAlpha(0f);
mScreenshotContainerView.setVisibility(View.VISIBLE); mScreenshotContainerView.setVisibility(View.VISIBLE);
mScreenshotFlash.setAlpha(0f);
mScreenshotFlash.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationEnd(android.animation.Animator animation) {
mScreenshotFlash.setVisibility(View.GONE);
} }
}); });
anim.addUpdateListener(new AnimatorUpdateListener() { anim.addUpdateListener(new AnimatorUpdateListener() {
@Override @Override
public void onAnimationUpdate(ValueAnimator animation) { public void onAnimationUpdate(ValueAnimator animation) {
float t = ((Float) animation.getAnimatedValue()).floatValue(); float t = ((Float) animation.getAnimatedValue()).floatValue();
float scaleT = (SCREENSHOT_FADE_IN_MIN_SCALE) float scaleT = (SCREENSHOT_SCALE + mBgPaddingScale)
+ (float) t * (SCREENSHOT_SCALE - SCREENSHOT_FADE_IN_MIN_SCALE); - (float) scaleInterpolator.getInterpolation(t)
mBackgroundView.setAlpha(t * BACKGROUND_ALPHA); * (SCREENSHOT_SCALE - SCREENSHOT_DROP_IN_MIN_SCALE);
mBackgroundView.setAlpha(scaleInterpolator.getInterpolation(t) * BACKGROUND_ALPHA);
mScreenshotContainerView.setAlpha(t);
mScreenshotContainerView.setScaleX(scaleT); mScreenshotContainerView.setScaleX(scaleT);
mScreenshotContainerView.setScaleY(scaleT); mScreenshotContainerView.setScaleY(scaleT);
mScreenshotContainerView.setAlpha(t); mScreenshotFlash.setAlpha(flashAlphaInterpolator.getInterpolation(t));
} }
}); });
return anim; return anim;
} }
private ValueAnimator createScreenshotFadeOutAnimation(int w, int h, boolean statusBarVisible, private ValueAnimator createScreenshotDropOutAnimation(int w, int h, boolean statusBarVisible,
boolean navBarVisible) { boolean navBarVisible) {
ValueAnimator anim = ValueAnimator.ofFloat(0f, 1f); ValueAnimator anim = ValueAnimator.ofFloat(0f, 1f);
anim.setInterpolator(new DecelerateInterpolator(0.5f)); anim.setStartDelay(SCREENSHOT_DROP_OUT_DELAY);
anim.setStartDelay(SCREENSHOT_FADE_OUT_DELAY);
anim.addListener(new AnimatorListenerAdapter() { anim.addListener(new AnimatorListenerAdapter() {
@Override @Override
public void onAnimationEnd(Animator animation) { public void onAnimationEnd(Animator animation) {
@@ -482,54 +509,58 @@ class GlobalScreenshot {
if (!statusBarVisible || !navBarVisible) { if (!statusBarVisible || !navBarVisible) {
// There is no status bar/nav bar, so just fade the screenshot away in place // There is no status bar/nav bar, so just fade the screenshot away in place
anim.setDuration(SCREENSHOT_FAST_FADE_OUT_DURATION); anim.setDuration(SCREENSHOT_FAST_DROP_OUT_DURATION);
anim.addUpdateListener(new AnimatorUpdateListener() { anim.addUpdateListener(new AnimatorUpdateListener() {
@Override @Override
public void onAnimationUpdate(ValueAnimator animation) { public void onAnimationUpdate(ValueAnimator animation) {
float t = ((Float) animation.getAnimatedValue()).floatValue(); float t = ((Float) animation.getAnimatedValue()).floatValue();
float scaleT = (SCREENSHOT_FADE_OUT_MIN_SCALE) float scaleT = (SCREENSHOT_DROP_IN_MIN_SCALE + mBgPaddingScale)
+ (float) (1f - t) * (SCREENSHOT_SCALE - SCREENSHOT_FADE_OUT_MIN_SCALE); - (float) t * (SCREENSHOT_DROP_IN_MIN_SCALE
- SCREENSHOT_FAST_DROP_OUT_MIN_SCALE);
mBackgroundView.setAlpha((1f - t) * BACKGROUND_ALPHA); mBackgroundView.setAlpha((1f - t) * BACKGROUND_ALPHA);
mScreenshotContainerView.setAlpha((1f - t) * BACKGROUND_ALPHA); mScreenshotContainerView.setAlpha(1f - t);
mScreenshotContainerView.setScaleX(scaleT); mScreenshotContainerView.setScaleX(scaleT);
mScreenshotContainerView.setScaleY(scaleT); mScreenshotContainerView.setScaleY(scaleT);
} }
}); });
} else { } else {
// In the case where there is a status bar, animate to the origin of the bar (top-left)
final float scaleDurationPct = (float) SCREENSHOT_DROP_OUT_SCALE_DURATION
/ SCREENSHOT_DROP_OUT_DURATION;
final Interpolator scaleInterpolator = new Interpolator() {
@Override
public float getInterpolation(float x) {
if (x < scaleDurationPct) {
// Decelerate, and scale the input accordingly
return (float) (1f - Math.pow(1f - (x / scaleDurationPct), 2f));
}
return 1f;
}
};
// Determine the bounds of how to scale // Determine the bounds of how to scale
float halfScreenWidth = (w - 2f * mBgPadding) / 2f; float halfScreenWidth = (w - 2f * mBgPadding) / 2f;
float halfScreenHeight = (h - 2f * mBgPadding) / 2f; float halfScreenHeight = (h - 2f * mBgPadding) / 2f;
final RectF finalBounds = new RectF(mDropOffsetX, mDropOffsetY, final float offsetPct = SCREENSHOT_DROP_OUT_MIN_SCALE_OFFSET;
mDropOffsetX + mStatusBarIconSize, final PointF finalPos = new PointF(
mDropOffsetY + mStatusBarIconSize); -halfScreenWidth + (SCREENSHOT_DROP_OUT_MIN_SCALE + offsetPct) * halfScreenWidth,
final PointF currentPos = new PointF(0f, 0f); -halfScreenHeight + (SCREENSHOT_DROP_OUT_MIN_SCALE + offsetPct) * halfScreenHeight);
final PointF finalPos = new PointF(-halfScreenWidth + finalBounds.centerX(),
-halfScreenHeight + finalBounds.centerY());
final DecelerateInterpolator d = new DecelerateInterpolator(2f);
// Note: since the scale origin is in the center of the view, divide difference by 2
float tmpMinScale = 0f;
if (w > h) {
tmpMinScale = finalBounds.width() / (2f * w);
} else {
tmpMinScale = finalBounds.height() / (2f * h);
}
final float minScale = tmpMinScale;
// Animate the screenshot to the status bar // Animate the screenshot to the status bar
anim.setDuration(SCREENSHOT_FADE_OUT_DURATION); anim.setDuration(SCREENSHOT_DROP_OUT_DURATION);
anim.addUpdateListener(new AnimatorUpdateListener() { anim.addUpdateListener(new AnimatorUpdateListener() {
@Override @Override
public void onAnimationUpdate(ValueAnimator animation) { public void onAnimationUpdate(ValueAnimator animation) {
float t = ((Float) animation.getAnimatedValue()).floatValue(); float t = ((Float) animation.getAnimatedValue()).floatValue();
float scaleT = minScale float scaleT = (SCREENSHOT_DROP_IN_MIN_SCALE + mBgPaddingScale)
+ (float) (1f - t) * (SCREENSHOT_SCALE - minScale - mBgPaddingScale) - (float) scaleInterpolator.getInterpolation(t)
+ mBgPaddingScale; * (SCREENSHOT_DROP_IN_MIN_SCALE - SCREENSHOT_DROP_OUT_MIN_SCALE);
mScreenshotContainerView.setAlpha(d.getInterpolation(1f - t)); mBackgroundView.setAlpha((1f - t) * BACKGROUND_ALPHA);
mScreenshotContainerView.setTranslationX(d.getInterpolation(t) * finalPos.x); mScreenshotContainerView.setAlpha(1f - scaleInterpolator.getInterpolation(t));
mScreenshotContainerView.setTranslationY(d.getInterpolation(t) * finalPos.y);
mScreenshotContainerView.setScaleX(scaleT); mScreenshotContainerView.setScaleX(scaleT);
mScreenshotContainerView.setScaleY(scaleT); mScreenshotContainerView.setScaleY(scaleT);
mBackgroundView.setAlpha((1f - t) * BACKGROUND_ALPHA); mScreenshotContainerView.setTranslationX(t * finalPos.x);
mScreenshotContainerView.setTranslationY(t * finalPos.y);
} }
}); });
} }