private boolean mFullyPulsing;
private float mAodFrontScrimOpacity = 0;
+ private Runnable mSetDozeInFrontAlphaDelayed;
public DozeScrimController(ScrimController scrimController, Context context) {
mContext = context;
mDozingAborted = false;
abortAnimations();
mScrimController.setDozeBehindAlpha(1f);
- mScrimController.setDozeInFrontAlpha(
- mDozeParameters.getAlwaysOn() ? mAodFrontScrimOpacity : 1f);
+ setDozeInFrontAlpha(mDozeParameters.getAlwaysOn() ? mAodFrontScrimOpacity : 1f);
} else {
cancelPulsing();
if (animate) {
} else {
abortAnimations();
mScrimController.setDozeBehindAlpha(0f);
- mScrimController.setDozeInFrontAlpha(0f);
+ setDozeInFrontAlpha(0f);
}
}
}
mAodFrontScrimOpacity = scrimOpacity;
if (mDozing && !isPulsing() && !mDozingAborted && !mWakeAndUnlocking
&& mDozeParameters.getAlwaysOn()) {
- mScrimController.setDozeInFrontAlpha(mAodFrontScrimOpacity);
+ setDozeInFrontAlpha(mAodFrontScrimOpacity);
}
}
if (!mWakeAndUnlocking) {
mWakeAndUnlocking = true;
mScrimController.setDozeBehindAlpha(0f);
- mScrimController.setDozeInFrontAlpha(0f);
+ setDozeInFrontAlpha(0f);
}
}
// be invoked when we're done so that the caller can drop the pulse wakelock.
mPulseCallback = callback;
mPulseReason = reason;
- mScrimController.setDozeInFrontAlpha(1f);
+ setDozeInFrontAlpha(1f);
mHandler.post(mPulseIn);
}
cancelPulsing();
if (mDozing && !mWakeAndUnlocking) {
mScrimController.setDozeBehindAlpha(1f);
- mScrimController.setDozeInFrontAlpha(
- mDozeParameters.getAlwaysOn() && !mDozingAborted ?
- mAodFrontScrimOpacity : 1f);
+ setDozeInFrontAlpha(mDozeParameters.getAlwaysOn() && !mDozingAborted
+ ? mAodFrontScrimOpacity : 1f);
}
}
: mScrimController.getDozeBehindAlpha();
}
+ private void setDozeInFrontAlpha(float opacity) {
+ setDozeInFrontAlphaDelayed(opacity, 0 /* delay */);
+
+ }
+
+ private void setDozeInFrontAlphaDelayed(float opacity, long delayMs) {
+ if (mSetDozeInFrontAlphaDelayed != null) {
+ mHandler.removeCallbacks(mSetDozeInFrontAlphaDelayed);
+ mSetDozeInFrontAlphaDelayed = null;
+ }
+ if (delayMs < 0) {
+ mScrimController.setDozeInFrontAlpha(opacity);
+ } else {
+ mHandler.postDelayed(mSetDozeInFrontAlphaDelayed = () -> {
+ setDozeInFrontAlpha(opacity);
+ }, delayMs);
+ }
+ }
+
private final Runnable mPulseIn = new Runnable() {
@Override
public void run() {
// Signal that the pulse is all finished so we can turn the screen off now.
DozeScrimController.this.pulseFinished();
if (mDozeParameters.getAlwaysOn()) {
- mScrimController.setDozeInFrontAlpha(mAodFrontScrimOpacity);
+ // Setting power states can happen after we push out the frame. Make sure we
+ // stay fully opaque until the power state request reaches the lower levels.
+ setDozeInFrontAlphaDelayed(mAodFrontScrimOpacity, 30);
}
}
};