Merge "Properly size KG camera animation for translucent bars." into klp-dev

This commit is contained in:
Daniel Sandler
2013-10-10 20:40:28 +00:00
committed by Android (Google) Code Review
2 changed files with 73 additions and 12 deletions

View File

@@ -19,11 +19,13 @@ package com.android.keyguard;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point; import android.graphics.Point;
import android.graphics.Rect; import android.graphics.Rect;
import android.os.Handler; import android.os.Handler;
import android.os.SystemClock; import android.os.SystemClock;
import android.util.Log; import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
@@ -55,15 +57,17 @@ public class CameraWidgetFrame extends KeyguardWidgetFrame implements View.OnCli
private final WindowManager mWindowManager; private final WindowManager mWindowManager;
private final Point mRenderedSize = new Point(); private final Point mRenderedSize = new Point();
private final int[] mTmpLoc = new int[2]; private final int[] mTmpLoc = new int[2];
private final Rect mTmpRect = new Rect();
private long mLaunchCameraStart; private long mLaunchCameraStart;
private boolean mActive; private boolean mActive;
private boolean mTransitioning; private boolean mTransitioning;
private boolean mDown; private boolean mDown;
private final Rect mInsets = new Rect();
private FixedSizeFrameLayout mPreview; private FixedSizeFrameLayout mPreview;
private View mFullscreenPreview; private View mFullscreenPreview;
private View mFakeNavBar;
private final Runnable mTransitionToCameraRunnable = new Runnable() { private final Runnable mTransitionToCameraRunnable = new Runnable() {
@Override @Override
@@ -211,10 +215,11 @@ public class CameraWidgetFrame extends KeyguardWidgetFrame implements View.OnCli
private void render() { private void render() {
final View root = getRootView(); final View root = getRootView();
final int width = root.getWidth(); final int width = root.getWidth() - mInsets.right; // leave room
final int height = root.getHeight(); final int height = root.getHeight() - mInsets.bottom; // for bars
if (mRenderedSize.x == width && mRenderedSize.y == height) { if (mRenderedSize.x == width && mRenderedSize.y == height) {
if (DEBUG) Log.d(TAG, String.format("Already rendered at size=%sx%s", width, height)); if (DEBUG) Log.d(TAG, String.format("Already rendered at size=%sx%s %d%%",
width, height, (int)(100*mPreview.getScaleX())));
return; return;
} }
if (width == 0 || height == 0) { if (width == 0 || height == 0) {
@@ -246,8 +251,8 @@ public class CameraWidgetFrame extends KeyguardWidgetFrame implements View.OnCli
mPreview.setTranslationY(pvTransY); mPreview.setTranslationY(pvTransY);
mRenderedSize.set(width, height); mRenderedSize.set(width, height);
if (DEBUG) Log.d(TAG, String.format("Rendered camera widget size=%sx%s instance=%s", if (DEBUG) Log.d(TAG, String.format("Rendered camera widget size=%sx%s %d%% instance=%s",
width, height, instanceId())); width, height, (int)(100*mPreview.getScaleX()), instanceId()));
} }
private void transitionToCamera() { private void transitionToCamera() {
@@ -257,24 +262,34 @@ public class CameraWidgetFrame extends KeyguardWidgetFrame implements View.OnCli
enableWindowExitAnimation(false); enableWindowExitAnimation(false);
final int navHeight = mInsets.bottom;
final int navWidth = mInsets.right;
mPreview.getLocationInWindow(mTmpLoc); mPreview.getLocationInWindow(mTmpLoc);
final float pvHeight = mPreview.getHeight() * mPreview.getScaleY(); final float pvHeight = mPreview.getHeight() * mPreview.getScaleY();
final float pvCenter = mTmpLoc[1] + pvHeight / 2f; final float pvCenter = mTmpLoc[1] + pvHeight / 2f;
final ViewGroup root = (ViewGroup) getRootView(); final ViewGroup root = (ViewGroup) getRootView();
if (DEBUG) {
Log.d(TAG, "root = " + root.getLeft() + "," + root.getTop() + " "
+ root.getWidth() + "x" + root.getHeight());
}
if (mFullscreenPreview == null) { if (mFullscreenPreview == null) {
mFullscreenPreview = getPreviewWidget(mContext, mWidgetInfo); mFullscreenPreview = getPreviewWidget(mContext, mWidgetInfo);
mFullscreenPreview.setClickable(false); mFullscreenPreview.setClickable(false);
root.addView(mFullscreenPreview); root.addView(mFullscreenPreview, new FrameLayout.LayoutParams(
root.getWidth() - navWidth,
root.getHeight() - navHeight));
} }
root.getWindowVisibleDisplayFrame(mTmpRect); final float fsHeight = root.getHeight() - navHeight;
final float fsHeight = mTmpRect.height(); final float fsCenter = root.getTop() + fsHeight / 2;
final float fsCenter = mTmpRect.top + fsHeight / 2;
final float fsScaleY = pvHeight / fsHeight; final float fsScaleY = mPreview.getScaleY();
final float fsTransY = pvCenter - fsCenter; final float fsTransY = pvCenter - fsCenter;
final float fsScaleX = mPreview.getScaleX(); final float fsScaleX = fsScaleY;
mPreview.setVisibility(View.GONE); mPreview.setVisibility(View.GONE);
mFullscreenPreview.setVisibility(View.VISIBLE); mFullscreenPreview.setVisibility(View.VISIBLE);
@@ -290,6 +305,36 @@ public class CameraWidgetFrame extends KeyguardWidgetFrame implements View.OnCli
.setDuration(WIDGET_ANIMATION_DURATION) .setDuration(WIDGET_ANIMATION_DURATION)
.withEndAction(mPostTransitionToCameraEndAction) .withEndAction(mPostTransitionToCameraEndAction)
.start(); .start();
if (navHeight > 0 || navWidth > 0) {
final boolean atBottom = navHeight > 0;
if (mFakeNavBar == null) {
mFakeNavBar = new View(mContext);
mFakeNavBar.setBackgroundColor(Color.BLACK);
root.addView(mFakeNavBar, new FrameLayout.LayoutParams(
atBottom ? FrameLayout.LayoutParams.MATCH_PARENT
: navWidth,
atBottom ? navHeight
: FrameLayout.LayoutParams.MATCH_PARENT,
atBottom ? Gravity.BOTTOM|Gravity.FILL_HORIZONTAL
: Gravity.RIGHT|Gravity.FILL_VERTICAL));
mFakeNavBar.setPivotY(navHeight);
mFakeNavBar.setPivotX(navWidth);
}
mFakeNavBar.setAlpha(0f);
if (atBottom) {
mFakeNavBar.setScaleY(0.5f);
} else {
mFakeNavBar.setScaleX(0.5f);
}
mFakeNavBar.setVisibility(View.VISIBLE);
mFakeNavBar.animate()
.alpha(1f)
.scaleY(1f)
.scaleY(1f)
.setDuration(WIDGET_ANIMATION_DURATION)
.start();
}
mCallbacks.onLaunchingCamera(); mCallbacks.onLaunchingCamera();
} }
@@ -397,6 +442,10 @@ public class CameraWidgetFrame extends KeyguardWidgetFrame implements View.OnCli
mFullscreenPreview.animate().cancel(); mFullscreenPreview.animate().cancel();
mFullscreenPreview.setVisibility(View.GONE); mFullscreenPreview.setVisibility(View.GONE);
} }
if (mFakeNavBar != null) {
mFakeNavBar.animate().cancel();
mFakeNavBar.setVisibility(View.GONE);
}
enableWindowExitAnimation(true); enableWindowExitAnimation(true);
} }
@@ -404,6 +453,10 @@ public class CameraWidgetFrame extends KeyguardWidgetFrame implements View.OnCli
protected void onSizeChanged(int w, int h, int oldw, int oldh) { protected void onSizeChanged(int w, int h, int oldw, int oldh) {
if (DEBUG) Log.d(TAG, String.format("onSizeChanged new=%sx%s old=%sx%s at %s", if (DEBUG) Log.d(TAG, String.format("onSizeChanged new=%sx%s old=%sx%s at %s",
w, h, oldw, oldh, SystemClock.uptimeMillis())); w, h, oldw, oldh, SystemClock.uptimeMillis()));
if ((w != oldw && oldw > 0) || (h != oldh && oldh > 0)) {
// we can't trust the old geometry anymore; force a re-render
mRenderedSize.x = mRenderedSize.y = -1;
}
mHandler.post(mRenderRunnable); mHandler.post(mRenderRunnable);
super.onSizeChanged(w, h, oldw, oldh); super.onSizeChanged(w, h, oldw, oldh);
} }
@@ -454,4 +507,9 @@ public class CameraWidgetFrame extends KeyguardWidgetFrame implements View.OnCli
private String instanceId() { private String instanceId() {
return Integer.toHexString(hashCode()); return Integer.toHexString(hashCode());
} }
public void setInsets(Rect insets) {
if (DEBUG) Log.d(TAG, "setInsets: " + insets);
mInsets.set(insets);
}
} }

View File

@@ -1454,6 +1454,9 @@ public class KeyguardHostView extends KeyguardViewBase {
mInsets.set(insets); mInsets.set(insets);
if (mSlidingChallengeLayout != null) mSlidingChallengeLayout.setInsets(mInsets); if (mSlidingChallengeLayout != null) mSlidingChallengeLayout.setInsets(mInsets);
if (mMultiPaneChallengeLayout != null) mMultiPaneChallengeLayout.setInsets(mInsets); if (mMultiPaneChallengeLayout != null) mMultiPaneChallengeLayout.setInsets(mInsets);
final CameraWidgetFrame cameraWidget = findCameraPage();
if (cameraWidget != null) cameraWidget.setInsets(mInsets);
} }
@Override @Override