Merge "Move RegionSamplingHelper to SysUI shared" into sc-v2-dev

This commit is contained in:
Tracy Zhou
2021-08-17 04:53:08 +00:00
committed by Android (Google) Code Review
4 changed files with 16 additions and 18 deletions

View File

@@ -56,11 +56,6 @@
<!-- The amount by which the arrow is shifted to avoid the finger--> <!-- The amount by which the arrow is shifted to avoid the finger-->
<dimen name="navigation_edge_finger_offset">48dp</dimen> <dimen name="navigation_edge_finger_offset">48dp</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>
<dimen name="floating_rotation_button_diameter">40dp</dimen> <dimen name="floating_rotation_button_diameter">40dp</dimen>
<dimen name="floating_rotation_button_min_margin">20dp</dimen> <dimen name="floating_rotation_button_min_margin">20dp</dimen>
<dimen name="floating_rotation_button_taskbar_left_margin">20dp</dimen> <dimen name="floating_rotation_button_taskbar_left_margin">20dp</dimen>

View File

@@ -14,12 +14,13 @@
* limitations under the License. * limitations under the License.
*/ */
package com.android.systemui.navigationbar.gestural; package com.android.systemui.shared.navigationbar;
import static android.view.Display.DEFAULT_DISPLAY; import static android.view.Display.DEFAULT_DISPLAY;
import android.content.res.Resources; import android.annotation.TargetApi;
import android.graphics.Rect; import android.graphics.Rect;
import android.os.Build;
import android.os.Handler; import android.os.Handler;
import android.view.CompositionSamplingListener; import android.view.CompositionSamplingListener;
import android.view.SurfaceControl; import android.view.SurfaceControl;
@@ -27,17 +28,22 @@ import android.view.View;
import android.view.ViewRootImpl; import android.view.ViewRootImpl;
import android.view.ViewTreeObserver; import android.view.ViewTreeObserver;
import com.android.systemui.R;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
/** /**
* A helper class to sample regions on the screen and inspect its luminosity. * A helper class to sample regions on the screen and inspect its luminosity.
*/ */
@TargetApi(Build.VERSION_CODES.Q)
public class RegionSamplingHelper implements View.OnAttachStateChangeListener, public class RegionSamplingHelper implements View.OnAttachStateChangeListener,
View.OnLayoutChangeListener { View.OnLayoutChangeListener {
// Luminance threshold to determine black/white contrast for the navigation affordances.
// Passing the threshold of this luminance value will make the button black otherwise white
private static final float NAVIGATION_LUMINANCE_THRESHOLD = 0.5f;
// Luminance change threshold that allows applying new value if difference was exceeded
private static final float NAVIGATION_LUMINANCE_CHANGE_THRESHOLD = 0.05f;
private final Handler mHandler = new Handler(); private final Handler mHandler = new Handler();
private final View mSampledView; private final View mSampledView;
@@ -62,9 +68,6 @@ public class RegionSamplingHelper implements View.OnAttachStateChangeListener,
private boolean mWaitingOnDraw; private boolean mWaitingOnDraw;
private boolean mIsDestroyed; private boolean mIsDestroyed;
// Passing the threshold of this luminance value will make the button black otherwise white
private final float mLuminanceThreshold;
private final float mLuminanceChangeThreshold;
private boolean mFirstSamplingAfterStart; private boolean mFirstSamplingAfterStart;
private boolean mWindowVisible; private boolean mWindowVisible;
private boolean mWindowHasBlurs; private boolean mWindowHasBlurs;
@@ -100,9 +103,6 @@ public class RegionSamplingHelper implements View.OnAttachStateChangeListener,
mSampledView.addOnAttachStateChangeListener(this); mSampledView.addOnAttachStateChangeListener(this);
mSampledView.addOnLayoutChangeListener(this); mSampledView.addOnLayoutChangeListener(this);
final Resources res = sampledView.getResources();
mLuminanceThreshold = res.getFloat(R.dimen.navigation_luminance_threshold);
mLuminanceChangeThreshold = res.getFloat(R.dimen.navigation_luminance_change_threshold);
mCallback = samplingCallback; mCallback = samplingCallback;
} }
@@ -217,8 +217,10 @@ public class RegionSamplingHelper implements View.OnAttachStateChangeListener,
// If the difference between the new luma and the current luma is larger than threshold // 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 // then apply the current luma, this is to prevent small changes causing colors to flicker
if (Math.abs(mCurrentMedianLuma - mLastMedianLuma) > mLuminanceChangeThreshold) { if (Math.abs(mCurrentMedianLuma - mLastMedianLuma)
mCallback.onRegionDarknessChanged(medianLuma < mLuminanceThreshold /* isRegionDark */); > NAVIGATION_LUMINANCE_CHANGE_THRESHOLD) {
mCallback.onRegionDarknessChanged(
medianLuma < NAVIGATION_LUMINANCE_THRESHOLD /* isRegionDark */);
mLastMedianLuma = medianLuma; mLastMedianLuma = medianLuma;
} }
} }

View File

@@ -79,7 +79,7 @@ import com.android.systemui.navigationbar.buttons.NearestTouchFrame;
import com.android.systemui.navigationbar.buttons.RotationContextButton; import com.android.systemui.navigationbar.buttons.RotationContextButton;
import com.android.systemui.navigationbar.gestural.EdgeBackGestureHandler; import com.android.systemui.navigationbar.gestural.EdgeBackGestureHandler;
import com.android.systemui.navigationbar.gestural.FloatingRotationButton; import com.android.systemui.navigationbar.gestural.FloatingRotationButton;
import com.android.systemui.navigationbar.gestural.RegionSamplingHelper; import com.android.systemui.shared.navigationbar.RegionSamplingHelper;
import com.android.systemui.recents.OverviewProxyService; import com.android.systemui.recents.OverviewProxyService;
import com.android.systemui.recents.Recents; import com.android.systemui.recents.Recents;
import com.android.systemui.shared.system.ActivityManagerWrapper; import com.android.systemui.shared.system.ActivityManagerWrapper;

View File

@@ -55,6 +55,7 @@ import com.android.systemui.Dependency;
import com.android.systemui.R; import com.android.systemui.R;
import com.android.systemui.animation.Interpolators; import com.android.systemui.animation.Interpolators;
import com.android.systemui.plugins.NavigationEdgeBackPlugin; import com.android.systemui.plugins.NavigationEdgeBackPlugin;
import com.android.systemui.shared.navigationbar.RegionSamplingHelper;
import com.android.systemui.statusbar.VibratorHelper; import com.android.systemui.statusbar.VibratorHelper;
import java.io.PrintWriter; import java.io.PrintWriter;