Merge "Support nav button color transitions"
This commit is contained in:
@@ -19,6 +19,7 @@ package android.inputmethodservice;
|
||||
import static android.content.Intent.ACTION_OVERLAY_CHANGED;
|
||||
import static android.view.WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS;
|
||||
|
||||
import android.animation.ValueAnimator;
|
||||
import android.annotation.FloatRange;
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
@@ -44,6 +45,8 @@ import android.view.Window;
|
||||
import android.view.WindowInsets;
|
||||
import android.view.WindowInsetsController.Appearance;
|
||||
import android.view.WindowManagerPolicyConstants;
|
||||
import android.view.animation.Interpolator;
|
||||
import android.view.animation.PathInterpolator;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import java.util.Objects;
|
||||
@@ -115,6 +118,12 @@ final class NavigationBarController {
|
||||
}
|
||||
|
||||
private static final class Impl implements Callback {
|
||||
private static final int DEFAULT_COLOR_ADAPT_TRANSITION_TIME = 1700;
|
||||
|
||||
// Copied from com.android.systemui.animation.Interpolators#LEGACY_DECELERATE
|
||||
private static final Interpolator LEGACY_DECELERATE =
|
||||
new PathInterpolator(0f, 0f, 0.2f, 1f);
|
||||
|
||||
@NonNull
|
||||
private final InputMethodService mService;
|
||||
|
||||
@@ -133,6 +142,12 @@ final class NavigationBarController {
|
||||
@Appearance
|
||||
private int mAppearance;
|
||||
|
||||
@FloatRange(from = 0.0f, to = 1.0f)
|
||||
private float mDarkIntensity;
|
||||
|
||||
@Nullable
|
||||
private ValueAnimator mTintAnimator;
|
||||
|
||||
Impl(@NonNull InputMethodService inputMethodService) {
|
||||
mService = inputMethodService;
|
||||
}
|
||||
@@ -368,6 +383,10 @@ final class NavigationBarController {
|
||||
if (mDestroyed) {
|
||||
return;
|
||||
}
|
||||
if (mTintAnimator != null) {
|
||||
mTintAnimator.cancel();
|
||||
mTintAnimator = null;
|
||||
}
|
||||
if (mSystemOverlayChangedReceiver != null) {
|
||||
mService.unregisterReceiver(mSystemOverlayChangedReceiver);
|
||||
mSystemOverlayChangedReceiver = null;
|
||||
@@ -416,10 +435,24 @@ final class NavigationBarController {
|
||||
}
|
||||
|
||||
final float targetDarkIntensity = calculateTargetDarkIntensity(mAppearance);
|
||||
setIconTintInternal(targetDarkIntensity);
|
||||
|
||||
if (mTintAnimator != null) {
|
||||
mTintAnimator.cancel();
|
||||
}
|
||||
mTintAnimator = ValueAnimator.ofFloat(mDarkIntensity, targetDarkIntensity);
|
||||
mTintAnimator.addUpdateListener(
|
||||
animation -> setIconTintInternal((Float) animation.getAnimatedValue()));
|
||||
mTintAnimator.setDuration(DEFAULT_COLOR_ADAPT_TRANSITION_TIME);
|
||||
mTintAnimator.setStartDelay(0);
|
||||
mTintAnimator.setInterpolator(LEGACY_DECELERATE);
|
||||
mTintAnimator.start();
|
||||
}
|
||||
|
||||
private void setIconTintInternal(float darkIntensity) {
|
||||
mDarkIntensity = darkIntensity;
|
||||
if (mNavigationBarFrame == null) {
|
||||
return;
|
||||
}
|
||||
final NavigationBarView navigationBarView =
|
||||
mNavigationBarFrame.findViewByPredicate(NavigationBarView.class::isInstance);
|
||||
if (navigationBarView == null) {
|
||||
@@ -439,6 +472,7 @@ final class NavigationBarController {
|
||||
return "{mRenderGesturalNavButtons=" + mRenderGesturalNavButtons
|
||||
+ " mNavigationBarFrame=" + mNavigationBarFrame
|
||||
+ " mAppearance=0x" + Integer.toHexString(mAppearance)
|
||||
+ " mDarkIntensity=" + mDarkIntensity
|
||||
+ "}";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user