Merge "Quickscrub will hide the most right buttons on nav bar" into pi-dev

This commit is contained in:
android-build-team Robot
2018-05-02 23:40:06 +00:00
committed by Android (Google) Code Review
5 changed files with 84 additions and 22 deletions

View File

@@ -16,6 +16,7 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:systemui="http://schemas.android.com/apk/res-auto"
android:id="@+id/menu_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
>

View File

@@ -14,8 +14,12 @@
package com.android.systemui.statusbar.phone;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.view.View;
import com.android.systemui.Interpolators;
import com.android.systemui.plugins.statusbar.phone.NavBarButtonProvider.ButtonInterface;
import com.android.systemui.statusbar.policy.KeyButtonDrawable;
@@ -26,6 +30,8 @@ import java.util.ArrayList;
* multiples of the same nav bar icon appearing.
*/
public class ButtonDispatcher {
private final static int FADE_DURATION_IN = 150;
private final static int FADE_DURATION_OUT = 100;
private final ArrayList<View> mViews = new ArrayList<>();
@@ -36,13 +42,24 @@ public class ButtonDispatcher {
private View.OnLongClickListener mLongClickListener;
private View.OnHoverListener mOnHoverListener;
private Boolean mLongClickable;
private Integer mAlpha;
private Float mAlpha;
private Float mDarkIntensity;
private Integer mVisibility = -1;
private Boolean mDelayTouchFeedback;
private KeyButtonDrawable mImageDrawable;
private View mCurrentView;
private boolean mVertical;
private ValueAnimator mFadeAnimator;
private final ValueAnimator.AnimatorUpdateListener mAlphaListener = animation ->
setAlpha((float) animation.getAnimatedValue());
private final AnimatorListenerAdapter mFadeListener = new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
setVisibility(getAlpha() == 1 ? View.VISIBLE : View.INVISIBLE);
}
};
public ButtonDispatcher(int id) {
mId = id;
@@ -64,19 +81,22 @@ public class ButtonDispatcher {
if (mAlpha != null) {
view.setAlpha(mAlpha);
}
if (mDarkIntensity != null) {
((ButtonInterface) view).setDarkIntensity(mDarkIntensity);
}
if (mVisibility != null) {
if (mVisibility != null && mVisibility != -1) {
view.setVisibility(mVisibility);
}
if (mImageDrawable != null) {
((ButtonInterface) view).setImageDrawable(mImageDrawable);
if (view instanceof ButtonInterface) {
final ButtonInterface button = (ButtonInterface) view;
if (mDarkIntensity != null) {
button.setDarkIntensity(mDarkIntensity);
}
if (mImageDrawable != null) {
button.setImageDrawable(mImageDrawable);
}
if (mDelayTouchFeedback != null) {
button.setDelayTouchFeedback(mDelayTouchFeedback);
}
button.setVertical(mVertical);
}
if (mDelayTouchFeedback != null) {
((ButtonInterface) view).setDelayTouchFeedback(mDelayTouchFeedback);
}
((ButtonInterface) view).setVertical(mVertical);
}
public int getId() {
@@ -99,7 +119,9 @@ public class ButtonDispatcher {
mImageDrawable = drawable;
final int N = mViews.size();
for (int i = 0; i < N; i++) {
((ButtonInterface) mViews.get(i)).setImageDrawable(mImageDrawable);
if (mViews.get(i) instanceof ButtonInterface) {
((ButtonInterface) mViews.get(i)).setImageDrawable(mImageDrawable);
}
}
}
@@ -116,11 +138,13 @@ public class ButtonDispatcher {
// This seems to be an instantaneous thing, so not going to persist it.
final int N = mViews.size();
for (int i = 0; i < N; i++) {
((ButtonInterface) mViews.get(i)).abortCurrentGesture();
if (mViews.get(i) instanceof ButtonInterface) {
((ButtonInterface) mViews.get(i)).abortCurrentGesture();
}
}
}
public void setAlpha(int alpha) {
public void setAlpha(float alpha) {
mAlpha = alpha;
final int N = mViews.size();
for (int i = 0; i < N; i++) {
@@ -132,7 +156,9 @@ public class ButtonDispatcher {
mDarkIntensity = darkIntensity;
final int N = mViews.size();
for (int i = 0; i < N; i++) {
((ButtonInterface) mViews.get(i)).setDarkIntensity(darkIntensity);
if (mViews.get(i) instanceof ButtonInterface) {
((ButtonInterface) mViews.get(i)).setDarkIntensity(darkIntensity);
}
}
}
@@ -140,7 +166,9 @@ public class ButtonDispatcher {
mDelayTouchFeedback = delay;
final int N = mViews.size();
for (int i = 0; i < N; i++) {
((ButtonInterface) mViews.get(i)).setDelayTouchFeedback(delay);
if (mViews.get(i) instanceof ButtonInterface) {
((ButtonInterface) mViews.get(i)).setDelayTouchFeedback(delay);
}
}
}
@@ -192,6 +220,19 @@ public class ButtonDispatcher {
}
}
public void animateFade(boolean in) {
if (mFadeAnimator != null) {
mFadeAnimator.cancel();
}
mFadeAnimator = ValueAnimator.ofFloat(getAlpha(), in ? 1 : 0);
mFadeAnimator.setDuration(in? FADE_DURATION_IN : FADE_DURATION_OUT);
mFadeAnimator.setInterpolator(in ? Interpolators.ALPHA_IN : Interpolators.ALPHA_OUT);
mFadeAnimator.addListener(mFadeListener);
mFadeAnimator.addUpdateListener(mAlphaListener);
mFadeAnimator.start();
setVisibility(View.VISIBLE);
}
public ArrayList<View> getViews() {
return mViews;
}

View File

@@ -168,10 +168,10 @@ public class NavigationBarInflaterView extends FrameLayout
}
}
public void setButtonDispatchers(SparseArray<ButtonDispatcher> buttonDisatchers) {
mButtonDispatchers = buttonDisatchers;
for (int i = 0; i < buttonDisatchers.size(); i++) {
initiallyFill(buttonDisatchers.valueAt(i));
public void setButtonDispatchers(SparseArray<ButtonDispatcher> buttonDispatchers) {
mButtonDispatchers = buttonDispatchers;
for (int i = 0; i < buttonDispatchers.size(); i++) {
initiallyFill(buttonDispatchers.valueAt(i));
}
}
@@ -220,7 +220,8 @@ public class NavigationBarInflaterView extends FrameLayout
// and will only happen once.
if (parent.getChildAt(i).getId() == buttonDispatcher.getId()) {
buttonDispatcher.addView(parent.getChildAt(i));
} else if (parent.getChildAt(i) instanceof ViewGroup) {
}
if (parent.getChildAt(i) instanceof ViewGroup) {
addAll(buttonDispatcher, (ViewGroup) parent.getChildAt(i));
}
}
@@ -411,7 +412,8 @@ public class NavigationBarInflaterView extends FrameLayout
final int indexOfKey = mButtonDispatchers.indexOfKey(v.getId());
if (indexOfKey >= 0) {
mButtonDispatchers.valueAt(indexOfKey).addView(v);
} else if (v instanceof ViewGroup) {
}
if (v instanceof ViewGroup) {
final ViewGroup viewGroup = (ViewGroup)v;
final int N = viewGroup.getChildCount();
for (int i = 0; i < N; i++) {

View File

@@ -260,6 +260,8 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
new ButtonDispatcher(R.id.accessibility_button));
mButtonDispatchers.put(R.id.rotate_suggestion,
new ButtonDispatcher(R.id.rotate_suggestion));
mButtonDispatchers.put(R.id.menu_container,
new ButtonDispatcher(R.id.menu_container));
mDeadZone = new DeadZone(this);
}
@@ -368,6 +370,10 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
return mButtonDispatchers.get(R.id.rotate_suggestion);
}
public ButtonDispatcher getMenuContainer() {
return mButtonDispatchers.get(R.id.menu_container);
}
public SparseArray<ButtonDispatcher> getButtonDispatchers() {
return mButtonDispatchers;
}
@@ -796,6 +802,10 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
public boolean isRotateButtonVisible() { return mShowRotateButton; }
public void setMenuContainerVisibility(boolean visible) {
getMenuContainer().animateFade(visible);
}
@Override
public void onFinishInflate() {
mNavigationInflaterView = (NavigationBarInflaterView) findViewById(

View File

@@ -401,6 +401,10 @@ public class QuickStepController implements GestureHelper {
mDarkTrackColor = mContext.getColor(R.color.quick_step_track_background_dark);
mTrackAnimator.setFloatValues(0, 1);
mTrackAnimator.start();
// Hide menu buttons on nav bar until quick scrub has ended
mNavigationBarView.setMenuContainerVisibility(false /* visible */);
try {
mOverviewEventSender.getProxy().onQuickScrubStart();
if (DEBUG_OVERVIEW_PROXY) {
@@ -416,6 +420,10 @@ public class QuickStepController implements GestureHelper {
private void endQuickScrub(boolean animate) {
if (mQuickScrubActive || mDragScrubActive) {
animateEnd();
// Restore the nav bar menu buttons visibility
mNavigationBarView.setMenuContainerVisibility(true /* visible */);
if (mQuickScrubActive) {
try {
mOverviewEventSender.getProxy().onQuickScrubEnd();