diff options
3 files changed, 47 insertions, 16 deletions
diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml index baa2055a1736..039eca694e24 100644 --- a/packages/SystemUI/res/values/dimens.xml +++ b/packages/SystemUI/res/values/dimens.xml @@ -37,7 +37,13 @@ <dimen name="navigation_handle_radius">1dp</dimen> <dimen name="navigation_handle_bottom">6dp</dimen> <dimen name="navigation_handle_horizontal_margin">30dp</dimen> - <dimen name="navigation_home_handle_width">280dp</dimen> + <dimen name="navigation_handle_sample_horizontal_margin">10dp</dimen> + <dimen name="navigation_home_handle_width">72dp</dimen> + + <!-- Luminance threshold to determine black/white contrast for the navigation affordances --> + <item name="navigation_luminance_threshold" type="dimen" format="float">0.5</item> + <!-- Luminance change threshold that allows applying new value if difference was exceeded --> + <item name="navigation_luminance_change_threshold" type="dimen" format="float">0.05</item> <!-- Height of notification icons in the status bar --> <dimen name="status_bar_icon_size">@*android:dimen/status_bar_icon_size</dimen> diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavBarTintController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavBarTintController.java index 9cfb1aa192b1..bf5b60a9437b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavBarTintController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavBarTintController.java @@ -19,11 +19,14 @@ package com.android.systemui.statusbar.phone; import static android.view.Display.DEFAULT_DISPLAY; import android.content.Context; +import android.content.res.Resources; +import android.graphics.Point; import android.graphics.Rect; import android.os.Handler; import android.view.CompositionSamplingListener; import android.view.View; +import com.android.systemui.R; import com.android.systemui.shared.system.QuickStepContract; import java.io.PrintWriter; @@ -37,9 +40,6 @@ public class NavBarTintController implements View.OnAttachStateChangeListener, public static final int MIN_COLOR_ADAPT_TRANSITION_TIME = 400; public static final int DEFAULT_COLOR_ADAPT_TRANSITION_TIME = 1700; - // Passing the threshold of this luminance value will make the button black otherwise white - private static final float LUMINANCE_THRESHOLD = 0.3f; - private final Handler mHandler = new Handler(); private final NavigationBarView mNavigationBarView; private final LightBarTransitionsController mLightBarController; @@ -50,9 +50,17 @@ public class NavBarTintController implements View.OnAttachStateChangeListener, private boolean mSamplingEnabled = false; private boolean mSamplingListenerRegistered = false; - private float mLastMediaLuma; + private float mLastMedianLuma; + private float mCurrentMedianLuma; private boolean mUpdateOnNextDraw; + private final int mNavBarHeight; + private final int mNavColorSampleMargin; + + // Passing the threshold of this luminance value will make the button black otherwise white + private final float mLuminanceThreshold; + private final float mLuminanceChangeThreshold; + public NavBarTintController(NavigationBarView navigationBarView, LightBarTransitionsController lightBarController) { mSamplingListener = new CompositionSamplingListener( @@ -66,6 +74,13 @@ public class NavBarTintController implements View.OnAttachStateChangeListener, mNavigationBarView.addOnAttachStateChangeListener(this); mNavigationBarView.addOnLayoutChangeListener(this); mLightBarController = lightBarController; + + final Resources res = navigationBarView.getResources(); + mNavBarHeight = res.getDimensionPixelSize(R.dimen.navigation_bar_height); + mNavColorSampleMargin = + res.getDimensionPixelSize(R.dimen.navigation_handle_sample_horizontal_margin); + mLuminanceThreshold = res.getFloat(R.dimen.navigation_luminance_threshold); + mLuminanceChangeThreshold = res.getFloat(R.dimen.navigation_luminance_change_threshold); } void onDraw() { @@ -109,8 +124,11 @@ public class NavBarTintController implements View.OnAttachStateChangeListener, if (view != null) { int[] pos = new int[2]; view.getLocationOnScreen(pos); - final Rect samplingBounds = new Rect(pos[0], pos[1], - pos[0] + view.getWidth(), pos[1] + view.getHeight()); + Point displaySize = new Point(); + view.getContext().getDisplay().getRealSize(displaySize); + final Rect samplingBounds = new Rect(pos[0] - mNavColorSampleMargin, + displaySize.y - mNavBarHeight, pos[0] + view.getWidth() + mNavColorSampleMargin, + displaySize.y); if (!samplingBounds.equals(mSamplingBounds)) { mSamplingBounds.set(samplingBounds); requestUpdateSamplingListener(); @@ -144,13 +162,19 @@ public class NavBarTintController implements View.OnAttachStateChangeListener, } private void updateTint(float medianLuma) { - mLastMediaLuma = medianLuma; - if (medianLuma > LUMINANCE_THRESHOLD) { - // Black - mLightBarController.setIconsDark(true /* dark */, true /* animate */); - } else { - // White - mLightBarController.setIconsDark(false /* dark */, true /* animate */); + mLastMedianLuma = medianLuma; + + // If the difference between the new luma and the current luma is larger than threshold + // then apply the current luma, this is to prevent small changes causing colors to flicker + if (Math.abs(mCurrentMedianLuma - mLastMedianLuma) > mLuminanceChangeThreshold) { + if (medianLuma > mLuminanceThreshold) { + // Black + mLightBarController.setIconsDark(true /* dark */, true /* animate */); + } else { + // White + mLightBarController.setIconsDark(false /* dark */, true /* animate */); + } + mCurrentMedianLuma = medianLuma; } } @@ -162,7 +186,8 @@ public class NavBarTintController implements View.OnAttachStateChangeListener, : "false")); pw.println(" mSamplingListenerRegistered: " + mSamplingListenerRegistered); pw.println(" mSamplingBounds: " + mSamplingBounds); - pw.println(" mLastMediaLuma: " + mLastMediaLuma); + pw.println(" mLastMedianLuma: " + mLastMedianLuma); + pw.println(" mCurrentMedianLuma: " + mCurrentMedianLuma); } public static boolean isEnabled(Context context) { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationHandle.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationHandle.java index 968074c6af59..81a425cd5eba 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationHandle.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationHandle.java @@ -68,7 +68,7 @@ public class NavigationHandle extends View implements ButtonInterface { int height = mRadius * 2; int width = getWidth(); int y = (navHeight - mBottom - height); - canvas.drawRoundRect(mRadius, y, width - mRadius, y + height, mRadius, mRadius, mPaint); + canvas.drawRoundRect(0, y, width, y + height, mRadius, mRadius, mPaint); } @Override |