summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Adrian Roos <roosa@google.com> 2014-10-27 17:04:10 +0100
committer Adrian Roos <roosa@google.com> 2014-11-17 16:44:14 +0100
commit05054bd6ac3d1a492e763b5778b1452dbc25e47c (patch)
tree7382595933705b868c820d7c4c2e9f4af2444387
parent4d269ba32037485bfa5ffba4dd23f796cbf10c43 (diff)
Add animations for the system bar color views
Smoothly animates them in and out when their visibility changes. Bug: 17882303 Change-Id: I04bf585bb253c655b4be2f5cc2304d5060cb1657
-rw-r--r--core/res/res/anim/dock_bottom_enter.xml2
-rw-r--r--core/res/res/anim/dock_bottom_exit.xml2
-rw-r--r--core/res/res/anim/dock_top_enter.xml2
-rw-r--r--core/res/res/anim/dock_top_exit.xml2
-rw-r--r--core/res/res/values/integers.xml1
-rw-r--r--core/res/res/values/symbols.xml1
-rw-r--r--policy/src/com/android/internal/policy/impl/PhoneWindow.java173
7 files changed, 139 insertions, 44 deletions
diff --git a/core/res/res/anim/dock_bottom_enter.xml b/core/res/res/anim/dock_bottom_enter.xml
index 4f2f753169d0..bfb97b6d9b80 100644
--- a/core/res/res/anim/dock_bottom_enter.xml
+++ b/core/res/res/anim/dock_bottom_enter.xml
@@ -20,5 +20,5 @@
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:interpolator/decelerate_cubic">
<translate android:fromYDelta="100%" android:toYDelta="0"
- android:duration="250"/>
+ android:duration="@integer/dock_enter_exit_duration"/>
</set>
diff --git a/core/res/res/anim/dock_bottom_exit.xml b/core/res/res/anim/dock_bottom_exit.xml
index afbe24b82aa0..4e15448aba3e 100644
--- a/core/res/res/anim/dock_bottom_exit.xml
+++ b/core/res/res/anim/dock_bottom_exit.xml
@@ -20,5 +20,5 @@
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:interpolator/accelerate_cubic">
<translate android:fromYDelta="0" android:toYDelta="100%"
- android:startOffset="100" android:duration="250"/>
+ android:startOffset="100" android:duration="@integer/dock_enter_exit_duration"/>
</set>
diff --git a/core/res/res/anim/dock_top_enter.xml b/core/res/res/anim/dock_top_enter.xml
index 1f74e4827aaa..f763fb5c1cc9 100644
--- a/core/res/res/anim/dock_top_enter.xml
+++ b/core/res/res/anim/dock_top_enter.xml
@@ -20,5 +20,5 @@
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:interpolator/decelerate_cubic">
<translate android:fromYDelta="-100%" android:toYDelta="0"
- android:duration="250"/>
+ android:duration="@integer/dock_enter_exit_duration"/>
</set>
diff --git a/core/res/res/anim/dock_top_exit.xml b/core/res/res/anim/dock_top_exit.xml
index 4d2fea94f322..995b7d0ffc8c 100644
--- a/core/res/res/anim/dock_top_exit.xml
+++ b/core/res/res/anim/dock_top_exit.xml
@@ -20,5 +20,5 @@
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:interpolator/accelerate_cubic">
<translate android:fromYDelta="0" android:toYDelta="-100%"
- android:startOffset="100" android:duration="250"/>
+ android:startOffset="100" android:duration="@integer/dock_enter_exit_duration"/>
</set>
diff --git a/core/res/res/values/integers.xml b/core/res/res/values/integers.xml
index 0343cfa8aa9d..8e272267efc9 100644
--- a/core/res/res/values/integers.xml
+++ b/core/res/res/values/integers.xml
@@ -22,4 +22,5 @@
<integer name="button_pressed_animation_duration">100</integer>
<integer name="button_pressed_animation_delay">100</integer>
<integer name="disabled_alpha_animation_duration">100</integer>
+ <integer name="dock_enter_exit_duration">250</integer>
</resources>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index c592f4962ac9..78a8d593fd50 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -1845,6 +1845,7 @@
<java-symbol type="string" name="usb_storage_stop_title" />
<java-symbol type="string" name="usb_storage_title" />
<java-symbol type="style" name="Animation.RecentApplications" />
+ <java-symbol type="integer" name="dock_enter_exit_duration" />
<!-- ImfTest -->
<java-symbol type="layout" name="auto_complete_list" />
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindow.java b/policy/src/com/android/internal/policy/impl/PhoneWindow.java
index c34316b5d013..30a271e0aa96 100644
--- a/policy/src/com/android/internal/policy/impl/PhoneWindow.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindow.java
@@ -101,6 +101,7 @@ import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
+import android.view.animation.Interpolator;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.PopupWindow;
@@ -2153,6 +2154,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
}
private final class DecorView extends FrameLayout implements RootViewSurfaceTaker {
+
/* package */int mDefaultOpacity = PixelFormat.OPAQUE;
/** The feature ID of the panel, or -1 if this is the application's DecorView */
@@ -2182,19 +2184,45 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
// View added at runtime to draw under the navigation bar area
private View mNavigationGuard;
- private View mStatusColorView;
- private View mNavigationColorView;
+ private final ColorViewState mStatusColorViewState = new ColorViewState(
+ SYSTEM_UI_FLAG_FULLSCREEN, FLAG_TRANSLUCENT_STATUS,
+ Gravity.TOP,
+ STATUS_BAR_BACKGROUND_TRANSITION_NAME,
+ com.android.internal.R.id.statusBarBackground,
+ FLAG_FULLSCREEN);
+ private final ColorViewState mNavigationColorViewState = new ColorViewState(
+ SYSTEM_UI_FLAG_HIDE_NAVIGATION, FLAG_TRANSLUCENT_NAVIGATION,
+ Gravity.BOTTOM,
+ NAVIGATION_BAR_BACKGROUND_TRANSITION_NAME,
+ com.android.internal.R.id.navigationBarBackground,
+ 0 /* hideWindowFlag */);
+
+ private final Interpolator mShowInterpolator;
+ private final Interpolator mHideInterpolator;
+ private final int mBarEnterExitDuration;
+
private final BackgroundFallback mBackgroundFallback = new BackgroundFallback();
private int mLastTopInset = 0;
private int mLastBottomInset = 0;
private int mLastRightInset = 0;
+ private boolean mLastHasTopStableInset = false;
+ private boolean mLastHasBottomStableInset = false;
+ private int mLastWindowFlags = 0;
private int mRootScrollY = 0;
public DecorView(Context context, int featureId) {
super(context);
mFeatureId = featureId;
+
+ mShowInterpolator = AnimationUtils.loadInterpolator(context,
+ android.R.interpolator.linear_out_slow_in);
+ mHideInterpolator = AnimationUtils.loadInterpolator(context,
+ android.R.interpolator.fast_out_linear_in);
+
+ mBarEnterExitDuration = context.getResources().getInteger(
+ R.integer.dock_enter_exit_duration);
}
public void setBackgroundFallback(int resId) {
@@ -2787,13 +2815,13 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
@Override
public void onWindowSystemUiVisibilityChanged(int visible) {
- updateColorViews(null /* insets */);
+ updateColorViews(null /* insets */, true /* animate */);
}
@Override
public WindowInsets onApplyWindowInsets(WindowInsets insets) {
mFrameOffsets.set(insets.getSystemWindowInsets());
- insets = updateColorViews(insets);
+ insets = updateColorViews(insets, true /* animate */);
insets = updateStatusGuard(insets);
updateNavigationGuard(insets);
if (getForeground() != null) {
@@ -2807,11 +2835,16 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
return false;
}
- private WindowInsets updateColorViews(WindowInsets insets) {
+ private WindowInsets updateColorViews(WindowInsets insets, boolean animate) {
WindowManager.LayoutParams attrs = getAttributes();
int sysUiVisibility = attrs.systemUiVisibility | getWindowSystemUiVisibility();
if (!mIsFloating && ActivityManager.isHighEndGfx()) {
+ boolean disallowAnimate = !isLaidOut();
+ disallowAnimate |= ((mLastWindowFlags ^ attrs.flags)
+ & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0;
+ mLastWindowFlags = attrs.flags;
+
if (insets != null) {
mLastTopInset = Math.min(insets.getStableInsetTop(),
insets.getSystemWindowInsetTop());
@@ -2819,19 +2852,23 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
insets.getSystemWindowInsetBottom());
mLastRightInset = Math.min(insets.getStableInsetRight(),
insets.getSystemWindowInsetRight());
+
+ // Don't animate if the presence of stable insets has changed, because that
+ // indicates that the window was either just added and received them for the
+ // first time, or the window size or position has changed.
+ boolean hasTopStableInset = insets.getStableInsetTop() != 0;
+ disallowAnimate |= hasTopStableInset && !mLastHasTopStableInset;
+ mLastHasTopStableInset = hasTopStableInset;
+
+ boolean hasBottomStableInset = insets.getStableInsetBottom() != 0;
+ disallowAnimate |= hasBottomStableInset && !mLastHasBottomStableInset;
+ mLastHasBottomStableInset = hasBottomStableInset;
}
- mStatusColorView = updateColorViewInt(mStatusColorView, sysUiVisibility,
- SYSTEM_UI_FLAG_FULLSCREEN, FLAG_TRANSLUCENT_STATUS,
- mStatusBarColor, mLastTopInset, Gravity.TOP,
- STATUS_BAR_BACKGROUND_TRANSITION_NAME,
- com.android.internal.R.id.statusBarBackground,
- (getAttributes().flags & FLAG_FULLSCREEN) != 0);
- mNavigationColorView = updateColorViewInt(mNavigationColorView, sysUiVisibility,
- SYSTEM_UI_FLAG_HIDE_NAVIGATION, FLAG_TRANSLUCENT_NAVIGATION,
- mNavigationBarColor, mLastBottomInset, Gravity.BOTTOM,
- NAVIGATION_BAR_BACKGROUND_TRANSITION_NAME,
- com.android.internal.R.id.navigationBarBackground,
- false /* hiddenByWindowFlag */);
+
+ updateColorViewInt(mStatusColorViewState, sysUiVisibility, mStatusBarColor,
+ mLastTopInset, animate && !disallowAnimate);
+ updateColorViewInt(mNavigationColorViewState, sysUiVisibility, mNavigationBarColor,
+ mLastBottomInset, animate && !disallowAnimate);
}
// When we expand the window with FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS, we still need
@@ -2875,28 +2912,35 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
return insets;
}
- private View updateColorViewInt(View view, int sysUiVis, int systemUiHideFlag,
- int translucentFlag, int color, int height, int verticalGravity,
- String transitionName, int id, boolean hiddenByWindowFlag) {
- boolean show = height > 0 && (sysUiVis & systemUiHideFlag) == 0
- && !hiddenByWindowFlag
- && (getAttributes().flags & translucentFlag) == 0
+ private void updateColorViewInt(final ColorViewState state, int sysUiVis, int color,
+ int height, boolean animate) {
+ boolean show = height > 0 && (sysUiVis & state.systemUiHideFlag) == 0
+ && (getAttributes().flags & state.hideWindowFlag) == 0
+ && (getAttributes().flags & state.translucentFlag) == 0
&& (color & Color.BLACK) != 0
&& (getAttributes().flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0;
+ boolean visibilityChanged = false;
+ View view = state.view;
+
if (view == null) {
if (show) {
- view = new View(mContext);
+ state.view = view = new View(mContext);
view.setBackgroundColor(color);
- view.setTransitionName(transitionName);
- view.setId(id);
+ view.setTransitionName(state.transitionName);
+ view.setId(state.id);
+ visibilityChanged = true;
+ view.setVisibility(INVISIBLE);
+ state.targetVisibility = VISIBLE;
+
addView(view, new LayoutParams(LayoutParams.MATCH_PARENT, height,
- Gravity.START | verticalGravity));
+ Gravity.START | state.verticalGravity));
updateColorViewTranslations();
}
} else {
int vis = show ? VISIBLE : INVISIBLE;
- view.setVisibility(vis);
+ visibilityChanged = state.targetVisibility != vis;
+ state.targetVisibility = vis;
if (show) {
LayoutParams lp = (LayoutParams) view.getLayoutParams();
if (lp.height != height) {
@@ -2906,18 +2950,43 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
view.setBackgroundColor(color);
}
}
- return view;
+ if (visibilityChanged) {
+ view.animate().cancel();
+ if (animate) {
+ if (show) {
+ if (view.getVisibility() != VISIBLE) {
+ view.setVisibility(VISIBLE);
+ view.setAlpha(0.0f);
+ }
+ view.animate().alpha(1.0f).setInterpolator(mShowInterpolator).
+ setDuration(mBarEnterExitDuration);
+ } else {
+ view.animate().alpha(0.0f).setInterpolator(mHideInterpolator)
+ .setDuration(mBarEnterExitDuration)
+ .withEndAction(new Runnable() {
+ @Override
+ public void run() {
+ state.view.setAlpha(1.0f);
+ state.view.setVisibility(INVISIBLE);
+ }
+ });
+ }
+ } else {
+ view.setAlpha(1.0f);
+ view.setVisibility(show ? VISIBLE : INVISIBLE);
+ }
+ }
}
private void updateColorViewTranslations() {
// Put the color views back in place when they get moved off the screen
// due to the the ViewRootImpl panning.
int rootScrollY = mRootScrollY;
- if (mStatusColorView != null) {
- mStatusColorView.setTranslationY(rootScrollY > 0 ? rootScrollY : 0);
+ if (mStatusColorViewState.view != null) {
+ mStatusColorViewState.view.setTranslationY(rootScrollY > 0 ? rootScrollY : 0);
}
- if (mNavigationColorView != null) {
- mNavigationColorView.setTranslationY(rootScrollY < 0 ? rootScrollY : 0);
+ if (mNavigationColorViewState.view != null) {
+ mNavigationColorViewState.view.setTranslationY(rootScrollY < 0 ? rootScrollY : 0);
}
}
@@ -2948,7 +3017,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
mStatusGuard = new View(mContext);
mStatusGuard.setBackgroundColor(mContext.getResources()
.getColor(R.color.input_method_navigation_guard));
- addView(mStatusGuard, indexOfChild(mStatusColorView),
+ addView(mStatusGuard, indexOfChild(mStatusColorViewState.view),
new LayoutParams(LayoutParams.MATCH_PARENT,
mlp.topMargin, Gravity.START | Gravity.TOP));
} else {
@@ -3008,9 +3077,10 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
mNavigationGuard = new View(mContext);
mNavigationGuard.setBackgroundColor(mContext.getResources()
.getColor(R.color.input_method_navigation_guard));
- addView(mNavigationGuard, indexOfChild(mNavigationColorView), new LayoutParams(
- LayoutParams.MATCH_PARENT, insets.getSystemWindowInsetBottom(),
- Gravity.START | Gravity.BOTTOM));
+ addView(mNavigationGuard, indexOfChild(mNavigationColorViewState.view),
+ new LayoutParams(LayoutParams.MATCH_PARENT,
+ insets.getSystemWindowInsetBottom(),
+ Gravity.START | Gravity.BOTTOM));
} else {
LayoutParams lp = (LayoutParams) mNavigationGuard.getLayoutParams();
lp.height = insets.getSystemWindowInsetBottom();
@@ -3912,7 +3982,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
protected void dispatchWindowAttributesChanged(WindowManager.LayoutParams attrs) {
super.dispatchWindowAttributesChanged(attrs);
if (mDecor != null) {
- mDecor.updateColorViews(null /* insets */);
+ mDecor.updateColorViews(null /* insets */, true /* animate */);
}
}
@@ -4639,6 +4709,29 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
}
}
+ private static class ColorViewState {
+ View view = null;
+ int targetVisibility = View.INVISIBLE;
+
+ final int id;
+ final int systemUiHideFlag;
+ final int translucentFlag;
+ final int verticalGravity;
+ final String transitionName;
+ final int hideWindowFlag;
+
+ ColorViewState(int systemUiHideFlag,
+ int translucentFlag, int verticalGravity,
+ String transitionName, int id, int hideWindowFlag) {
+ this.id = id;
+ this.systemUiHideFlag = systemUiHideFlag;
+ this.translucentFlag = translucentFlag;
+ this.verticalGravity = verticalGravity;
+ this.transitionName = transitionName;
+ this.hideWindowFlag = hideWindowFlag;
+ }
+ }
+
void sendCloseSystemWindows() {
PhoneWindowManager.sendCloseSystemWindows(getContext(), null);
}
@@ -4657,7 +4750,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
mStatusBarColor = color;
mForcedStatusBarColor = true;
if (mDecor != null) {
- mDecor.updateColorViews(null);
+ mDecor.updateColorViews(null, false /* animate */);
}
}
@@ -4671,7 +4764,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
mNavigationBarColor = color;
mForcedNavigationBarColor = true;
if (mDecor != null) {
- mDecor.updateColorViews(null);
+ mDecor.updateColorViews(null, false /* animate */);
}
}
}