public interface ClockPlugin extends Plugin {
String ACTION = "com.android.systemui.action.PLUGIN_CLOCK";
- int VERSION = 3;
+ int VERSION = 4;
/**
* Get the name of the clock face.
}
/**
+ * Allows the plugin to clean up resources when no longer needed.
+ *
+ * Called when the view previously created by {@link ClockPlugin#getView()} has been detached
+ * from the view hierarchy.
+ */
+ void onDestroyView();
+
+ /**
* Set clock paint style.
* @param style The new style to set in the paint.
*/
mBigClockContainer.removeAllViews();
updateBigClockVisibility();
}
+ mClockPlugin.onDestroyView();
mClockPlugin = null;
}
if (plugin == null) {
}
@Override
+ public void onDestroyView() {
+ mView = null;
+ mDigitalClock = null;
+ mAnalogClock = null;
+ mLockClockContainer = null;
+ mLockClock = null;
+ mDarkController = null;
+ }
+
+ @Override
public String getName() {
return "bubble";
}
}
@Override
+ public void onDestroyView() {
+ mView = null;
+ mTextTime = null;
+ mTextDate = null;
+ }
+
+ @Override
public String getName() {
return "default";
}
mDarkController = new CrossFadeDarkController(mDigitalClock, mLockClock);
}
+
+ @Override
+ public void onDestroyView() {
+ mBigClockView = null;
+ mDigitalClock = null;
+ mAnalogClock = null;
+ mView = null;
+ mLockClock = null;
+ mDarkController = null;
+ }
+
@Override
public String getName() {
return "stretch";
}
@Override
+ public void onDestroyView() {
+ mView = null;
+ mTypeClock = null;
+ mLockClock = null;
+ mDarkController = null;
+ }
+
+ @Override
public String getName() {
return "type";
}
}
@Test
+ public void onPluginDisconnected_onDestroyView() {
+ // GIVEN a plugin is connected
+ ClockPlugin clockPlugin = mock(ClockPlugin.class);
+ when(clockPlugin.getView()).thenReturn(new TextClock(getContext()));
+ ClockManager.ClockChangedListener listener = mKeyguardClockSwitch.getClockChangedListener();
+ listener.onClockChanged(clockPlugin);
+ // WHEN the plugin is disconnected
+ listener.onClockChanged(null);
+ // THEN onDestroyView is called on the plugin
+ verify(clockPlugin).onDestroyView();
+ }
+
+ @Test
public void setTextColor_defaultClockSetTextColor() {
mKeyguardClockSwitch.setTextColor(Color.YELLOW);