Merge "Manage keyguard nav elements using transitions." into klp-dev

This commit is contained in:
John Spurlock
2013-11-01 18:48:00 +00:00
committed by Android (Google) Code Review
18 changed files with 232 additions and 109 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 953 B

After

Width:  |  Height:  |  Size: 685 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 701 B

After

Width:  |  Height:  |  Size: 537 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 939 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

@ -55,8 +55,7 @@ public class CommandQueue extends IStatusBar.Stub {
private static final int MSG_TOGGLE_RECENT_APPS = 13 << MSG_SHIFT;
private static final int MSG_PRELOAD_RECENT_APPS = 14 << MSG_SHIFT;
private static final int MSG_CANCEL_PRELOAD_RECENT_APPS = 15 << MSG_SHIFT;
private static final int MSG_SET_NAVIGATION_ICON_HINTS = 16 << MSG_SHIFT;
private static final int MSG_SET_WINDOW_STATE = 17 << MSG_SHIFT;
private static final int MSG_SET_WINDOW_STATE = 16 << MSG_SHIFT;
public static final int FLAG_EXCLUDE_NONE = 0;
public static final int FLAG_EXCLUDE_SEARCH_PANEL = 1 << 0;
@ -98,7 +97,6 @@ public class CommandQueue extends IStatusBar.Stub {
public void showSearchPanel();
public void hideSearchPanel();
public void cancelPreloadRecentApps();
public void setNavigationIconHints(int hints);
public void setWindowState(int window, int state);
}
@ -227,13 +225,6 @@ public class CommandQueue extends IStatusBar.Stub {
}
}
public void setNavigationIconHints(int hints) {
synchronized (mList) {
mHandler.removeMessages(MSG_SET_NAVIGATION_ICON_HINTS);
mHandler.obtainMessage(MSG_SET_NAVIGATION_ICON_HINTS, hints, 0, null).sendToTarget();
}
}
public void setWindowState(int window, int state) {
synchronized (mList) {
// don't coalesce these
@ -318,9 +309,6 @@ public class CommandQueue extends IStatusBar.Stub {
case MSG_CANCEL_PRELOAD_RECENT_APPS:
mCallbacks.cancelPreloadRecentApps();
break;
case MSG_SET_NAVIGATION_ICON_HINTS:
mCallbacks.setNavigationIconHints(msg.arg1);
break;
case MSG_SET_WINDOW_STATE:
mCallbacks.setWindowState(msg.arg1, msg.arg2);
break;

View File

@ -99,6 +99,10 @@ public class BarTransitions {
mBarBackground.finishAnimation();
}
public void setContentVisible(boolean visible) {
// for subclasses
}
private static class BarBackgroundDrawable extends Drawable {
private final int mOpaque;
private final int mSemiTransparent;

View File

@ -30,6 +30,9 @@ import com.android.systemui.statusbar.policy.KeyButtonView;
public final class NavigationBarTransitions extends BarTransitions {
private static final float KEYGUARD_QUIESCENT_ALPHA = 0.5f;
private static final int CONTENT_FADE_DURATION = 200;
private final NavigationBarView mView;
private final IStatusBarService mBarService;
@ -73,18 +76,57 @@ public final class NavigationBarTransitions extends BarTransitions {
private void applyMode(int mode, boolean animate, boolean force) {
// apply to key buttons
final boolean isOpaque = mode == MODE_OPAQUE || mode == MODE_LIGHTS_OUT;
final float alpha = isOpaque ? KeyButtonView.DEFAULT_QUIESCENT_ALPHA : 1f;
setKeyButtonViewQuiescentAlpha(mView.getBackButton(), alpha, animate);
final float alpha = alphaForMode(mode);
setKeyButtonViewQuiescentAlpha(mView.getHomeButton(), alpha, animate);
setKeyButtonViewQuiescentAlpha(mView.getRecentsButton(), alpha, animate);
setKeyButtonViewQuiescentAlpha(mView.getMenuButton(), alpha, animate);
setKeyButtonViewQuiescentAlpha(mView.getCameraButton(), alpha, animate);
setKeyButtonViewQuiescentAlpha(mView.getSearchLight(), KEYGUARD_QUIESCENT_ALPHA, animate);
setKeyButtonViewQuiescentAlpha(mView.getCameraButton(), KEYGUARD_QUIESCENT_ALPHA, animate);
applyBackButtonQuiescentAlpha(mode, animate);
// apply to lights out
applyLightsOut(mode == MODE_LIGHTS_OUT, animate, force);
}
private float alphaForMode(int mode) {
final boolean isOpaque = mode == MODE_OPAQUE || mode == MODE_LIGHTS_OUT;
return isOpaque ? KeyButtonView.DEFAULT_QUIESCENT_ALPHA : 1f;
}
public void applyBackButtonQuiescentAlpha(int mode, boolean animate) {
float backAlpha = 0;
backAlpha = maxVisibleQuiescentAlpha(backAlpha, mView.getSearchLight());
backAlpha = maxVisibleQuiescentAlpha(backAlpha, mView.getCameraButton());
backAlpha = maxVisibleQuiescentAlpha(backAlpha, mView.getHomeButton());
backAlpha = maxVisibleQuiescentAlpha(backAlpha, mView.getRecentsButton());
backAlpha = maxVisibleQuiescentAlpha(backAlpha, mView.getMenuButton());
if (backAlpha > 0) {
setKeyButtonViewQuiescentAlpha(mView.getBackButton(), backAlpha, animate);
}
}
private static float maxVisibleQuiescentAlpha(float max, View v) {
if ((v instanceof KeyButtonView) && v.isShown()) {
return Math.max(max, ((KeyButtonView)v).getQuiescentAlpha());
}
return max;
}
@Override
public void setContentVisible(boolean visible) {
final float alpha = visible ? 1 : 0;
fadeContent(mView.getCameraButton(), alpha);
fadeContent(mView.getSearchLight(), alpha);
}
private void fadeContent(View v, float alpha) {
if (v != null) {
v.animate().alpha(alpha).setDuration(CONTENT_FADE_DURATION);
}
}
private void setKeyButtonViewQuiescentAlpha(View button, float alpha, boolean animate) {
if (button instanceof KeyButtonView) {
((KeyButtonView) button).setQuiescentAlpha(alpha, animate);

View File

@ -17,6 +17,10 @@
package com.android.systemui.statusbar.phone;
import android.animation.LayoutTransition;
import android.animation.LayoutTransition.TransitionListener;
import android.animation.ObjectAnimator;
import android.animation.TimeInterpolator;
import android.animation.ValueAnimator;
import android.app.ActivityManagerNative;
import android.app.StatusBarManager;
import android.app.admin.DevicePolicyManager;
@ -48,12 +52,12 @@ import com.android.systemui.R;
import com.android.systemui.statusbar.BaseStatusBar;
import com.android.systemui.statusbar.DelegateViewHelper;
import com.android.systemui.statusbar.policy.DeadZone;
import com.android.systemui.statusbar.policy.KeyButtonView;
import java.io.FileDescriptor;
import java.io.PrintWriter;
public class NavigationBarView extends LinearLayout {
private static final int CAMERA_BUTTON_FADE_DURATION = 200;
final static boolean DEBUG = false;
final static String TAG = "PhoneStatusBar/NavigationBarView";
@ -89,6 +93,54 @@ public class NavigationBarView extends LinearLayout {
// used to disable the camera icon in navbar when disabled by DPM
private boolean mCameraDisabledByDpm;
// performs manual animation in sync with layout transitions
private final NavTransitionListener mTransitionListener = new NavTransitionListener();
private class NavTransitionListener implements TransitionListener {
private boolean mBackTransitioning;
private boolean mHomeAppearing;
private long mStartDelay;
private long mDuration;
private TimeInterpolator mInterpolator;
@Override
public void startTransition(LayoutTransition transition, ViewGroup container,
View view, int transitionType) {
if (view.getId() == R.id.back) {
mBackTransitioning = true;
} else if (view.getId() == R.id.home && transitionType == LayoutTransition.APPEARING) {
mHomeAppearing = true;
mStartDelay = transition.getStartDelay(transitionType);
mDuration = transition.getDuration(transitionType);
mInterpolator = transition.getInterpolator(transitionType);
}
}
@Override
public void endTransition(LayoutTransition transition, ViewGroup container,
View view, int transitionType) {
if (view.getId() == R.id.back) {
mBackTransitioning = false;
} else if (view.getId() == R.id.home && transitionType == LayoutTransition.APPEARING) {
mHomeAppearing = false;
}
}
public void onBackAltCleared() {
// When dismissing ime during unlock, force the back button to run the same appearance
// animation as home (if we catch this condition early enough).
if (!mBackTransitioning && getBackButton().getVisibility() == VISIBLE
&& mHomeAppearing && getHomeButton().getAlpha() == 0) {
getBackButton().setAlpha(0);
ValueAnimator a = ObjectAnimator.ofFloat(getBackButton(), "alpha", 0, 1);
a.setStartDelay(mStartDelay);
a.setDuration(mDuration);
a.setInterpolator(mInterpolator);
a.start();
}
}
}
// simplified click handler to be used when device is in accessibility mode
private final OnClickListener mAccessibilityClickListener = new OnClickListener() {
@Override
@ -108,12 +160,12 @@ public class NavigationBarView extends LinearLayout {
case MotionEvent.ACTION_DOWN:
// disable search gesture while interacting with camera
mDelegateHelper.setDisabled(true);
transitionCameraAndSearchButtonAlpha(0.0f);
mBarTransitions.setContentVisible(false);
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
mDelegateHelper.setDisabled(false);
transitionCameraAndSearchButtonAlpha(1.0f);
mBarTransitions.setContentVisible(true);
break;
}
return KeyguardTouchDelegate.getInstance(getContext()).dispatch(event);
@ -163,17 +215,6 @@ public class NavigationBarView extends LinearLayout {
watchForDevicePolicyChanges();
}
protected void transitionCameraAndSearchButtonAlpha(float alpha) {
View cameraButtonView = getCameraButton();
if (cameraButtonView != null) {
cameraButtonView.animate().alpha(alpha).setDuration(CAMERA_BUTTON_FADE_DURATION);
}
View searchLight = getSearchLight();
if (searchLight != null) {
searchLight.animate().alpha(alpha).setDuration(CAMERA_BUTTON_FADE_DURATION);
}
}
private void watchForDevicePolicyChanges() {
final IntentFilter filter = new IntentFilter();
filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
@ -277,7 +318,10 @@ public class NavigationBarView extends LinearLayout {
public void setNavigationIconHints(int hints, boolean force) {
if (!force && hints == mNavigationIconHints) return;
final boolean backAlt = (hints & StatusBarManager.NAVIGATION_HINT_BACK_ALT) != 0;
if ((mNavigationIconHints & StatusBarManager.NAVIGATION_HINT_BACK_ALT) != 0 && !backAlt) {
mTransitionListener.onBackAltCleared();
}
if (DEBUG) {
android.widget.Toast.makeText(mContext,
"Navigation icon hints = " + hints,
@ -286,15 +330,7 @@ public class NavigationBarView extends LinearLayout {
mNavigationIconHints = hints;
getBackButton().setAlpha(
(0 != (hints & StatusBarManager.NAVIGATION_HINT_BACK_NOP)) ? 0.5f : 1.0f);
getHomeButton().setAlpha(
(0 != (hints & StatusBarManager.NAVIGATION_HINT_HOME_NOP)) ? 0.5f : 1.0f);
getRecentsButton().setAlpha(
(0 != (hints & StatusBarManager.NAVIGATION_HINT_RECENT_NOP)) ? 0.5f : 1.0f);
((ImageView)getBackButton()).setImageDrawable(
(0 != (hints & StatusBarManager.NAVIGATION_HINT_BACK_ALT))
((ImageView)getBackButton()).setImageDrawable(backAlt
? (mVertical ? mBackAltLandIcon : mBackAltIcon)
: (mVertical ? mBackLandIcon : mBackIcon));
@ -322,13 +358,20 @@ public class NavigationBarView extends LinearLayout {
setSlippery(disableHome && disableRecent && disableBack && disableSearch);
}
if (!mScreenOn && mCurrentView != null) {
ViewGroup navButtons = (ViewGroup) mCurrentView.findViewById(R.id.nav_buttons);
LayoutTransition lt = navButtons == null ? null : navButtons.getLayoutTransition();
ViewGroup navButtons = (ViewGroup) mCurrentView.findViewById(R.id.nav_buttons);
if (navButtons != null) {
LayoutTransition lt = navButtons.getLayoutTransition();
if (lt != null) {
lt.disableTransitionType(
LayoutTransition.CHANGE_APPEARING | LayoutTransition.CHANGE_DISAPPEARING |
LayoutTransition.APPEARING | LayoutTransition.DISAPPEARING);
if (!lt.getTransitionListeners().contains(mTransitionListener)) {
lt.addTransitionListener(mTransitionListener);
}
if (!mScreenOn && mCurrentView != null) {
lt.disableTransitionType(
LayoutTransition.CHANGE_APPEARING |
LayoutTransition.CHANGE_DISAPPEARING |
LayoutTransition.APPEARING |
LayoutTransition.DISAPPEARING);
}
}
}
@ -336,12 +379,17 @@ public class NavigationBarView extends LinearLayout {
getHomeButton() .setVisibility(disableHome ? View.INVISIBLE : View.VISIBLE);
getRecentsButton().setVisibility(disableRecent ? View.INVISIBLE : View.VISIBLE);
final boolean shouldShowSearch = disableHome && !disableSearch;
getSearchLight().setVisibility(shouldShowSearch ? View.VISIBLE : View.GONE);
final View cameraButton = getCameraButton();
if (cameraButton != null) {
cameraButton.setVisibility(
shouldShowSearch && !mCameraDisabledByDpm ? View.VISIBLE : View.GONE);
final boolean showSearch = disableHome && !disableSearch;
final boolean showCamera = showSearch && !mCameraDisabledByDpm;
setVisibleOrGone(getSearchLight(), showSearch);
setVisibleOrGone(getCameraButton(), showCamera);
mBarTransitions.applyBackButtonQuiescentAlpha(mBarTransitions.getMode(), true /*animate*/);
}
private void setVisibleOrGone(View view, boolean visible) {
if (view != null) {
view.setVisibility(visible ? VISIBLE : GONE);
}
}
@ -574,28 +622,31 @@ public class NavigationBarView extends LinearLayout {
mVertical ? "true" : "false",
mShowMenu ? "true" : "false"));
final View back = getBackButton();
final View home = getHomeButton();
final View recent = getRecentsButton();
final View menu = getMenuButton();
dumpButton(pw, "back", getBackButton());
dumpButton(pw, "home", getHomeButton());
dumpButton(pw, "rcnt", getRecentsButton());
dumpButton(pw, "menu", getMenuButton());
dumpButton(pw, "srch", getSearchLight());
dumpButton(pw, "cmra", getCameraButton());
pw.println(" back: "
+ PhoneStatusBar.viewInfo(back)
+ " " + visibilityToString(back.getVisibility())
);
pw.println(" home: "
+ PhoneStatusBar.viewInfo(home)
+ " " + visibilityToString(home.getVisibility())
);
pw.println(" rcnt: "
+ PhoneStatusBar.viewInfo(recent)
+ " " + visibilityToString(recent.getVisibility())
);
pw.println(" menu: "
+ PhoneStatusBar.viewInfo(menu)
+ " " + visibilityToString(menu.getVisibility())
);
pw.println(" }");
}
private static void dumpButton(PrintWriter pw, String caption, View button) {
pw.print(" " + caption + ": ");
if (button == null) {
pw.print("null");
} else {
pw.print(PhoneStatusBar.viewInfo(button)
+ " " + visibilityToString(button.getVisibility())
+ " alpha=" + button.getAlpha()
);
if (button instanceof KeyButtonView) {
pw.print(" drawingAlpha=" + ((KeyButtonView)button).getDrawingAlpha());
pw.print(" quiescentAlpha=" + ((KeyButtonView)button).getQuiescentAlpha());
}
}
pw.println();
}
}

View File

@ -53,6 +53,7 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.PowerManager;
import android.os.RemoteException;
import android.os.SystemClock;
import android.os.UserHandle;
@ -632,6 +633,10 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode {
}
}
PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
mBroadcastReceiver.onReceive(mContext,
new Intent(pm.isScreenOn() ? Intent.ACTION_SCREEN_ON : Intent.ACTION_SCREEN_OFF));
// receive broadcasts
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
@ -649,14 +654,14 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode {
@Override
protected void onShowSearchPanel() {
if (mNavigationBarView != null) {
mNavigationBarView.transitionCameraAndSearchButtonAlpha(0.0f);
mNavigationBarView.getBarTransitions().setContentVisible(false);
}
}
@Override
protected void onHideSearchPanel() {
if (mNavigationBarView != null) {
mNavigationBarView.transitionCameraAndSearchButtonAlpha(1.0f);
mNavigationBarView.getBarTransitions().setContentVisible(true);
}
}
@ -802,7 +807,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode {
}
private void repositionNavigationBar() {
if (mNavigationBarView == null) return;
if (mNavigationBarView == null || !mNavigationBarView.isAttachedToWindow()) return;
prepareNavigationBarView();
@ -1807,8 +1812,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode {
return mGestureRec;
}
@Override // CommandQueue
public void setNavigationIconHints(int hints) {
private void setNavigationIconHints(int hints) {
if (hints == mNavigationIconHints) return;
mNavigationIconHints = hints;
@ -2045,7 +2049,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode {
boolean altBack = (backDisposition == InputMethodService.BACK_DISPOSITION_WILL_DISMISS)
|| ((vis & InputMethodService.IME_VISIBLE) != 0);
mCommandQueue.setNavigationIconHints(
setNavigationIconHints(
altBack ? (mNavigationIconHints | NAVIGATION_HINT_BACK_ALT)
: (mNavigationIconHints & ~NAVIGATION_HINT_BACK_ALT));
if (mQS != null) mQS.setImeWindowStatus(vis > 0);

View File

@ -36,6 +36,7 @@ import android.view.MotionEvent;
import android.view.SoundEffectConstants;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewDebug;
import android.view.accessibility.AccessibilityEvent;
import android.widget.ImageView;
@ -53,10 +54,13 @@ public class KeyButtonView extends ImageView {
int mTouchSlop;
Drawable mGlowBG;
int mGlowWidth, mGlowHeight;
float mGlowAlpha = 0f, mGlowScale = 1f, mDrawingAlpha = 1f;
float mGlowAlpha = 0f, mGlowScale = 1f;
@ViewDebug.ExportedProperty(category = "drawing")
float mDrawingAlpha = 1f;
@ViewDebug.ExportedProperty(category = "drawing")
float mQuiescentAlpha = DEFAULT_QUIESCENT_ALPHA;
boolean mSupportsLongpress = true;
RectF mRect = new RectF(0f,0f,0f,0f);
RectF mRect = new RectF();
AnimatorSet mPressedAnim;
Animator mAnimateToQuiescent = new ObjectAnimator();
@ -90,8 +94,8 @@ public class KeyButtonView extends ImageView {
mSupportsLongpress = a.getBoolean(R.styleable.KeyButtonView_keyRepeat, true);
mGlowBG = a.getDrawable(R.styleable.KeyButtonView_glowBackground);
setDrawingAlpha(mQuiescentAlpha);
if (mGlowBG != null) {
setDrawingAlpha(mQuiescentAlpha);
mGlowWidth = mGlowBG.getIntrinsicWidth();
mGlowHeight = mGlowBG.getIntrinsicHeight();
}
@ -126,16 +130,14 @@ public class KeyButtonView extends ImageView {
public void setQuiescentAlpha(float alpha, boolean animate) {
mAnimateToQuiescent.cancel();
alpha = Math.min(Math.max(alpha, 0), 1);
if (alpha == mQuiescentAlpha) return;
if (alpha == mQuiescentAlpha && alpha == mDrawingAlpha) return;
mQuiescentAlpha = alpha;
if (DEBUG) Log.d(TAG, "New quiescent alpha = " + mQuiescentAlpha);
if (mGlowBG != null) {
if (animate) {
mAnimateToQuiescent = animateToQuiescent();
mAnimateToQuiescent.start();
} else {
setDrawingAlpha(mQuiescentAlpha);
}
if (mGlowBG != null && animate) {
mAnimateToQuiescent = animateToQuiescent();
mAnimateToQuiescent.start();
} else {
setDrawingAlpha(mQuiescentAlpha);
}
}
@ -143,13 +145,15 @@ public class KeyButtonView extends ImageView {
return ObjectAnimator.ofFloat(this, "drawingAlpha", mQuiescentAlpha);
}
public float getQuiescentAlpha() {
return mQuiescentAlpha;
}
public float getDrawingAlpha() {
if (mGlowBG == null) return 0;
return mDrawingAlpha;
}
public void setDrawingAlpha(float x) {
if (mGlowBG == null) return;
// Calling setAlpha(int), which is an ImageView-specific
// method that's different from setAlpha(float). This sets
// the alpha on this ImageView's drawable directly

View File

@ -88,10 +88,6 @@ public class TvStatusBar extends BaseStatusBar {
public void toggleRecentApps() {
}
@Override // CommandQueue
public void setNavigationIconHints(int hints) {
}
@Override // CommandQueue
public void setWindowState(int window, int state) {
}