Merge "Don't register multiple predraw listeners" into sc-v2-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
e07b60ab9e
@@ -89,6 +89,7 @@ public class KeyguardClockSwitch extends RelativeLayout {
|
|||||||
|
|
||||||
private int mClockSwitchYAmount;
|
private int mClockSwitchYAmount;
|
||||||
@VisibleForTesting boolean mChildrenAreLaidOut = false;
|
@VisibleForTesting boolean mChildrenAreLaidOut = false;
|
||||||
|
private OnPreDrawListener mPreDrawListener;
|
||||||
|
|
||||||
public KeyguardClockSwitch(Context context, AttributeSet attrs) {
|
public KeyguardClockSwitch(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
@@ -284,15 +285,14 @@ public class KeyguardClockSwitch extends RelativeLayout {
|
|||||||
if (mChildrenAreLaidOut) {
|
if (mChildrenAreLaidOut) {
|
||||||
animateClockChange(clockSize == LARGE);
|
animateClockChange(clockSize == LARGE);
|
||||||
mDisplayedClockSize = clockSize;
|
mDisplayedClockSize = clockSize;
|
||||||
} else {
|
} else if (mPreDrawListener == null) {
|
||||||
getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
|
mPreDrawListener = () -> {
|
||||||
@Override
|
switchToClock(clockSize);
|
||||||
public boolean onPreDraw() {
|
getViewTreeObserver().removeOnPreDrawListener(mPreDrawListener);
|
||||||
switchToClock(clockSize);
|
mPreDrawListener = null;
|
||||||
getViewTreeObserver().removeOnPreDrawListener(this);
|
return true;
|
||||||
return true;
|
};
|
||||||
}
|
getViewTreeObserver().addOnPreDrawListener(mPreDrawListener);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -303,6 +303,13 @@ public class KeyguardClockSwitch extends RelativeLayout {
|
|||||||
mChildrenAreLaidOut = true;
|
mChildrenAreLaidOut = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void onViewDetached() {
|
||||||
|
if (mPreDrawListener != null) {
|
||||||
|
getViewTreeObserver().removeOnPreDrawListener(mPreDrawListener);
|
||||||
|
mPreDrawListener = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Paint getPaint() {
|
public Paint getPaint() {
|
||||||
return mClockView.getPaint();
|
return mClockView.getPaint();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -238,6 +238,7 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
|
|||||||
}
|
}
|
||||||
mColorExtractor.removeOnColorsChangedListener(mColorsListener);
|
mColorExtractor.removeOnColorsChangedListener(mColorsListener);
|
||||||
mView.setClockPlugin(null, mStatusBarStateController.getState());
|
mView.setClockPlugin(null, mStatusBarStateController.getState());
|
||||||
|
mView.onViewDetached();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ public class KeyguardClockSwitchControllerTest extends SysuiTestCase {
|
|||||||
verifyAttachment(times(1));
|
verifyAttachment(times(1));
|
||||||
|
|
||||||
listenerArgumentCaptor.getValue().onViewDetachedFromWindow(mView);
|
listenerArgumentCaptor.getValue().onViewDetachedFromWindow(mView);
|
||||||
|
verify(mView).onViewDetached();
|
||||||
verify(mColorExtractor).removeOnColorsChangedListener(
|
verify(mColorExtractor).removeOnColorsChangedListener(
|
||||||
any(ColorExtractor.OnColorsChangedListener.class));
|
any(ColorExtractor.OnColorsChangedListener.class));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user