Hide smartspace dream complication in preview mode.
Test: atest DreamOverlayStateControllerTest Test: locally on device Bug: 219747041 Change-Id: I5fa9eed525dc04fa70e5aa7b899ad25dabbc320b
This commit is contained in:
@@ -131,6 +131,7 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ
|
||||
mStateController.setOverlayActive(false);
|
||||
mPreviewComplication.setDreamLabel(null);
|
||||
mStateController.removeComplication(mPreviewComplication);
|
||||
mStateController.setPreviewMode(false);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@@ -139,6 +140,7 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ
|
||||
setCurrentState(Lifecycle.State.STARTED);
|
||||
mExecutor.execute(() -> {
|
||||
mStateController.setShouldShowComplications(shouldShowComplications());
|
||||
mStateController.setPreviewMode(isPreviewMode());
|
||||
if (isPreviewMode()) {
|
||||
mPreviewComplication.setDreamLabel(getDreamLabel());
|
||||
mStateController.addComplication(mPreviewComplication);
|
||||
|
||||
@@ -50,6 +50,7 @@ public class DreamOverlayStateController implements
|
||||
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
|
||||
|
||||
public static final int STATE_DREAM_OVERLAY_ACTIVE = 1 << 0;
|
||||
public static final int STATE_PREVIEW_MODE = 1 << 1;
|
||||
|
||||
private static final int OP_CLEAR_STATE = 1;
|
||||
private static final int OP_SET_STATE = 2;
|
||||
@@ -249,4 +250,18 @@ public class DreamOverlayStateController implements
|
||||
mCallbacks.forEach(Callback::onAvailableComplicationTypesChanged);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether the dream is running in preview mode.
|
||||
*/
|
||||
public void setPreviewMode(boolean isPreviewMode) {
|
||||
modifyState(isPreviewMode ? OP_SET_STATE : OP_CLEAR_STATE, STATE_PREVIEW_MODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the dream is running in preview mode.
|
||||
*/
|
||||
public boolean isPreviewMode() {
|
||||
return containsState(STATE_PREVIEW_MODE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,19 @@ public class SmartSpaceComplication implements Complication {
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
if (mSmartSpaceController.isEnabled()) {
|
||||
addOrRemoveOverlay();
|
||||
mDreamOverlayStateController.addCallback(new DreamOverlayStateController.Callback() {
|
||||
@Override
|
||||
public void onStateChanged() {
|
||||
addOrRemoveOverlay();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void addOrRemoveOverlay() {
|
||||
if (mDreamOverlayStateController.isPreviewMode()) {
|
||||
mDreamOverlayStateController.removeComplication(mComplication);
|
||||
} else if (mSmartSpaceController.isEnabled()) {
|
||||
mDreamOverlayStateController.addComplication(mComplication);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ public class DreamOverlayStateControllerTest extends SysuiTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStateChange() {
|
||||
public void testStateChange_overlayActive() {
|
||||
final DreamOverlayStateController stateController = new DreamOverlayStateController(
|
||||
mExecutor);
|
||||
stateController.addCallback(mCallback);
|
||||
@@ -82,6 +82,38 @@ public class DreamOverlayStateControllerTest extends SysuiTestCase {
|
||||
assertThat(stateController.isOverlayActive()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStateChange_isPreviewMode() {
|
||||
final DreamOverlayStateController stateController = new DreamOverlayStateController(
|
||||
mExecutor);
|
||||
stateController.addCallback(mCallback);
|
||||
stateController.setPreviewMode(true);
|
||||
mExecutor.runAllReady();
|
||||
|
||||
verify(mCallback).onStateChanged();
|
||||
assertThat(stateController.isPreviewMode()).isTrue();
|
||||
|
||||
Mockito.clearInvocations(mCallback);
|
||||
stateController.setPreviewMode(true);
|
||||
mExecutor.runAllReady();
|
||||
verify(mCallback, never()).onStateChanged();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreviewModeFalseByDefault() {
|
||||
final DreamOverlayStateController stateController = new DreamOverlayStateController(
|
||||
mExecutor);
|
||||
assertThat(stateController.isPreviewMode()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreviewModeSetToTrue() {
|
||||
final DreamOverlayStateController stateController = new DreamOverlayStateController(
|
||||
mExecutor);
|
||||
stateController.setPreviewMode(true);
|
||||
assertThat(stateController.isPreviewMode()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCallback() {
|
||||
final DreamOverlayStateController stateController = new DreamOverlayStateController(
|
||||
|
||||
Reference in New Issue
Block a user