Merge changes from topic "211446330"
* changes: Marshal access to DreamOverlayStateController. Refactor Dream Overlay.
This commit is contained in:
@@ -714,19 +714,19 @@
|
||||
<bool name="config_enablePrivacyDot">true</bool>
|
||||
|
||||
<!-- The positions widgets can be in defined as View.Gravity constants -->
|
||||
<integer-array name="config_dreamOverlayPositions">
|
||||
<integer-array name="config_dreamComplicationPositions">
|
||||
</integer-array>
|
||||
|
||||
<!-- Widget components to show as dream overlays -->
|
||||
<string-array name="config_dreamOverlayComponents" translatable="false">
|
||||
<!-- Widget components to show as dream complications -->
|
||||
<string-array name="config_dreamAppWidgetComplications" translatable="false">
|
||||
</string-array>
|
||||
|
||||
<!-- Width percentage of dream overlay components -->
|
||||
<item name="config_dreamOverlayComponentWidthPercent" translatable="false" format="float"
|
||||
<!-- Width percentage of dream complications -->
|
||||
<item name="config_dreamComplicationWidthPercent" translatable="false" format="float"
|
||||
type="dimen">0.33</item>
|
||||
|
||||
<!-- Height percentage of dream overlay components -->
|
||||
<item name="config_dreamOverlayComponentHeightPercent" translatable="false" format="float"
|
||||
<!-- Height percentage of dream complications -->
|
||||
<item name="config_dreamComplicationHeightPercent" translatable="false" format="float"
|
||||
type="dimen">0.25</item>
|
||||
|
||||
<!-- Flag to enable dream overlay service and its registration -->
|
||||
|
||||
@@ -25,7 +25,7 @@ import com.android.systemui.accessibility.WindowMagnification;
|
||||
import com.android.systemui.biometrics.AuthController;
|
||||
import com.android.systemui.communal.CommunalManagerUpdater;
|
||||
import com.android.systemui.dreams.DreamOverlayRegistrant;
|
||||
import com.android.systemui.dreams.appwidgets.AppWidgetOverlayPrimer;
|
||||
import com.android.systemui.dreams.appwidgets.ComplicationPrimer;
|
||||
import com.android.systemui.globalactions.GlobalActionsComponent;
|
||||
import com.android.systemui.keyguard.KeyguardViewMediator;
|
||||
import com.android.systemui.keyguard.dagger.KeyguardModule;
|
||||
@@ -202,9 +202,9 @@ public abstract class SystemUIBinder {
|
||||
/** Inject into AppWidgetOverlayPrimer. */
|
||||
@Binds
|
||||
@IntoMap
|
||||
@ClassKey(AppWidgetOverlayPrimer.class)
|
||||
@ClassKey(ComplicationPrimer.class)
|
||||
public abstract CoreStartable bindAppWidgetOverlayPrimer(
|
||||
AppWidgetOverlayPrimer appWidgetOverlayPrimer);
|
||||
ComplicationPrimer complicationPrimer);
|
||||
|
||||
/** Inject into CommunalManagerUpdater. */
|
||||
@Binds
|
||||
|
||||
@@ -19,29 +19,29 @@ package com.android.systemui.dreams;
|
||||
import android.view.View;
|
||||
|
||||
/**
|
||||
* A collection of interfaces related to hosting an overlay.
|
||||
* A collection of interfaces related to hosting a complication.
|
||||
*/
|
||||
public abstract class OverlayHost {
|
||||
public abstract class ComplicationHost {
|
||||
/**
|
||||
* An interface for the callback from the overlay provider to indicate when the overlay is
|
||||
* ready.
|
||||
* An interface for the callback from the complication provider to indicate when the
|
||||
* complication is ready.
|
||||
*/
|
||||
public interface CreationCallback {
|
||||
/**
|
||||
* Called to inform the overlay view is ready to be placed within the visual space.
|
||||
* @param view The view representing the overlay.
|
||||
* Called to inform the complication view is ready to be placed within the visual space.
|
||||
* @param view The view representing the complication.
|
||||
* @param layoutParams The parameters to create the view with.
|
||||
*/
|
||||
void onCreated(View view, OverlayHostView.LayoutParams layoutParams);
|
||||
void onCreated(View view, ComplicationHostView.LayoutParams layoutParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* An interface for the callback from the overlay provider to signal interactions in the
|
||||
* overlay.
|
||||
* An interface for the callback from the complication provider to signal interactions in the
|
||||
* complication.
|
||||
*/
|
||||
public interface InteractionCallback {
|
||||
/**
|
||||
* Called to signal the calling overlay would like to exit the dream.
|
||||
* Called to signal the calling complication would like to exit the dream.
|
||||
*/
|
||||
void onExit();
|
||||
}
|
||||
@@ -22,22 +22,23 @@ import android.util.AttributeSet;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
|
||||
/**
|
||||
* {@link OverlayHostView} is the container view for housing overlays ontop of a dream.
|
||||
* {@link ComplicationHostView} is the container view for housing complications above of a dream.
|
||||
*/
|
||||
public class OverlayHostView extends ConstraintLayout {
|
||||
public OverlayHostView(Context context) {
|
||||
public class ComplicationHostView extends ConstraintLayout {
|
||||
public ComplicationHostView(Context context) {
|
||||
super(context, null);
|
||||
}
|
||||
|
||||
public OverlayHostView(Context context, AttributeSet attrs) {
|
||||
public ComplicationHostView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs, 0);
|
||||
}
|
||||
|
||||
public OverlayHostView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
public ComplicationHostView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr, 0);
|
||||
}
|
||||
|
||||
public OverlayHostView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
public ComplicationHostView(Context context, AttributeSet attrs, int defStyleAttr,
|
||||
int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
}
|
||||
@@ -19,18 +19,18 @@ package com.android.systemui.dreams;
|
||||
import android.content.Context;
|
||||
|
||||
/**
|
||||
* {@link OverlayProvider} is an interface for defining entities that can supply overlays to show
|
||||
* over a dream. Presentation components such as the {@link DreamOverlayService} supply
|
||||
* {@link ComplicationProvider} is an interface for defining entities that can supply complications
|
||||
* to show over a dream. Presentation components such as the {@link DreamOverlayService} supply
|
||||
* implementations with the necessary context for constructing such overlays.
|
||||
*/
|
||||
public interface OverlayProvider {
|
||||
public interface ComplicationProvider {
|
||||
/**
|
||||
* Called when the {@link OverlayHost} requests the associated overlay be produced.
|
||||
* Called when the {@link ComplicationHost} requests the associated complication be produced.
|
||||
*
|
||||
* @param context The {@link Context} used to construct the view.
|
||||
* @param creationCallback The callback to inform when the overlay has been created.
|
||||
* @param interactionCallback The callback to inform when the overlay has been interacted with.
|
||||
* @param creationCallback The callback to inform the complication has been created.
|
||||
* @param interactionCallback The callback to inform the complication has been interacted with.
|
||||
*/
|
||||
void onCreateOverlay(Context context, OverlayHost.CreationCallback creationCallback,
|
||||
OverlayHost.InteractionCallback interactionCallback);
|
||||
void onCreateComplication(Context context, ComplicationHost.CreationCallback creationCallback,
|
||||
ComplicationHost.InteractionCallback interactionCallback);
|
||||
}
|
||||
@@ -40,7 +40,7 @@ import java.util.concurrent.Executor;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* The {@link DreamOverlayService} is responsible for placing overlays on top of a dream. The
|
||||
* The {@link DreamOverlayService} is responsible for placing an overlay on top of a dream. The
|
||||
* dream reaches directly out to the service with a Window reference (via LayoutParams), which the
|
||||
* service uses to insert its own child Window into the dream's parent Window.
|
||||
*/
|
||||
@@ -52,7 +52,7 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ
|
||||
private final Context mContext;
|
||||
// The Executor ensures actions and ui updates happen on the same thread.
|
||||
private final Executor mExecutor;
|
||||
// The state controller informs the service of updates to the overlays present.
|
||||
// The state controller informs the service of updates to the complications present.
|
||||
private final DreamOverlayStateController mStateController;
|
||||
// The component used to resolve dream overlay dependencies.
|
||||
private final DreamOverlayComponent mDreamOverlayComponent;
|
||||
@@ -64,8 +64,8 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ
|
||||
private final DreamOverlayStateController.Callback mOverlayStateCallback =
|
||||
new DreamOverlayStateController.Callback() {
|
||||
@Override
|
||||
public void onOverlayChanged() {
|
||||
mExecutor.execute(() -> reloadOverlaysLocked());
|
||||
public void onComplicationsChanged() {
|
||||
mExecutor.execute(() -> reloadComplicationsLocked());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -87,7 +87,7 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ
|
||||
}
|
||||
};
|
||||
|
||||
// A hook into the internal inset calculation where we declare the overlays as the only
|
||||
// A hook into the internal inset calculation where we declare the complications as the only
|
||||
// touchable regions.
|
||||
private final ViewTreeObserver.OnComputeInternalInsetsListener
|
||||
mOnComputeInternalInsetsListener =
|
||||
@@ -129,20 +129,20 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ
|
||||
mExecutor.execute(() -> addOverlayWindowLocked(layoutParams));
|
||||
}
|
||||
|
||||
private void reloadOverlaysLocked() {
|
||||
private void reloadComplicationsLocked() {
|
||||
if (mDreamOverlayContentView == null) {
|
||||
return;
|
||||
}
|
||||
mDreamOverlayContentView.removeAllViews();
|
||||
for (OverlayProvider overlayProvider : mStateController.getOverlays()) {
|
||||
addOverlay(overlayProvider);
|
||||
for (ComplicationProvider complicationProvider : mStateController.getComplications()) {
|
||||
addComplication(complicationProvider);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts {@link Window} to host dream overlays into the dream's parent window. Must be called
|
||||
* from the main executing thread. The window attributes closely mirror those that are set by
|
||||
* the {@link android.service.dreams.DreamService} on the dream Window.
|
||||
* Inserts {@link Window} to host the dream overlay into the dream's parent window. Must be
|
||||
* called from the main executing thread. The window attributes closely mirror those that are
|
||||
* set by the {@link android.service.dreams.DreamService} on the dream Window.
|
||||
* @param layoutParams The {@link android.view.WindowManager.LayoutParams} which allow inserting
|
||||
* into the dream window.
|
||||
*/
|
||||
@@ -173,12 +173,12 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ
|
||||
|
||||
final WindowManager windowManager = mContext.getSystemService(WindowManager.class);
|
||||
windowManager.addView(window.getDecorView(), window.getAttributes());
|
||||
mExecutor.execute(this::reloadOverlaysLocked);
|
||||
mExecutor.execute(this::reloadComplicationsLocked);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected void addOverlay(OverlayProvider provider) {
|
||||
provider.onCreateOverlay(mContext,
|
||||
protected void addComplication(ComplicationProvider provider) {
|
||||
provider.onCreateComplication(mContext,
|
||||
(view, layoutParams) -> {
|
||||
// Always move UI related work to the main thread.
|
||||
mExecutor.execute(() -> {
|
||||
|
||||
@@ -17,45 +17,51 @@
|
||||
package com.android.systemui.dreams;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.concurrent.futures.CallbackToFutureAdapter;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.systemui.dagger.SysUISingleton;
|
||||
import com.android.systemui.dagger.qualifiers.Main;
|
||||
import com.android.systemui.statusbar.policy.CallbackController;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* {@link DreamOverlayStateController} is the source of truth for Dream overlay configurations.
|
||||
* Clients can register as listeners for changes to the overlay composition and can query for the
|
||||
* overlays on-demand.
|
||||
* {@link DreamOverlayStateController} is the source of truth for Dream overlay configurations and
|
||||
* state. Clients can register as listeners for changes to the overlay composition and can query for
|
||||
* the complications on-demand.
|
||||
*/
|
||||
@SysUISingleton
|
||||
public class DreamOverlayStateController implements
|
||||
CallbackController<DreamOverlayStateController.Callback> {
|
||||
// A counter for guaranteeing unique overlay tokens within the scope of this state controller.
|
||||
private int mNextOverlayTokenId = 0;
|
||||
// A counter for guaranteeing unique complications tokens within the scope of this state
|
||||
// controller.
|
||||
private int mNextComplicationTokenId = 0;
|
||||
|
||||
/**
|
||||
* {@link OverlayToken} provides a unique key for identifying {@link OverlayProvider}
|
||||
* {@link ComplicationToken} provides a unique key for identifying {@link ComplicationProvider}
|
||||
* instances registered with {@link DreamOverlayStateController}.
|
||||
*/
|
||||
public static class OverlayToken {
|
||||
public static class ComplicationToken {
|
||||
private final int mId;
|
||||
|
||||
private OverlayToken(int id) {
|
||||
private ComplicationToken(int id) {
|
||||
mId = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof OverlayToken)) return false;
|
||||
OverlayToken that = (OverlayToken) o;
|
||||
if (!(o instanceof ComplicationToken)) return false;
|
||||
ComplicationToken that = (ComplicationToken) o;
|
||||
return mId == that.mId;
|
||||
}
|
||||
|
||||
@@ -70,81 +76,97 @@ public class DreamOverlayStateController implements
|
||||
*/
|
||||
public interface Callback {
|
||||
/**
|
||||
* Called when the visibility of the communal view changes.
|
||||
* Called when the composition of complications changes.
|
||||
*/
|
||||
default void onOverlayChanged() {
|
||||
default void onComplicationsChanged() {
|
||||
}
|
||||
}
|
||||
|
||||
private final Executor mExecutor;
|
||||
private final ArrayList<Callback> mCallbacks = new ArrayList<>();
|
||||
private final HashMap<OverlayToken, OverlayProvider> mOverlays = new HashMap<>();
|
||||
private final HashMap<ComplicationToken, ComplicationProvider> mComplications = new HashMap<>();
|
||||
|
||||
@VisibleForTesting
|
||||
@Inject
|
||||
public DreamOverlayStateController() {
|
||||
public DreamOverlayStateController(@Main Executor executor) {
|
||||
mExecutor = executor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an overlay to be presented on top of dreams.
|
||||
* @param provider The {@link OverlayProvider} providing the dream.
|
||||
* @return The {@link OverlayToken} tied to the supplied {@link OverlayProvider}.
|
||||
* Adds a complication to be presented on top of dreams.
|
||||
* @param provider The {@link ComplicationProvider} providing the dream.
|
||||
* @return The {@link ComplicationToken} tied to the supplied {@link ComplicationProvider}.
|
||||
*/
|
||||
public OverlayToken addOverlay(OverlayProvider provider) {
|
||||
final OverlayToken token = new OverlayToken(mNextOverlayTokenId++);
|
||||
mOverlays.put(token, provider);
|
||||
notifyCallbacks();
|
||||
return token;
|
||||
public ListenableFuture<ComplicationToken> addComplication(ComplicationProvider provider) {
|
||||
return CallbackToFutureAdapter.getFuture(completer -> {
|
||||
mExecutor.execute(() -> {
|
||||
final ComplicationToken token = new ComplicationToken(mNextComplicationTokenId++);
|
||||
mComplications.put(token, provider);
|
||||
notifyCallbacks();
|
||||
completer.set(token);
|
||||
});
|
||||
return "DreamOverlayStateController::addComplication";
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an overlay from being shown on dreams.
|
||||
* @param token The {@link OverlayToken} associated with the {@link OverlayProvider} to be
|
||||
* removed.
|
||||
* @return The removed {@link OverlayProvider}, {@code null} if not found.
|
||||
* Removes a complication from being shown on dreams.
|
||||
* @param token The {@link ComplicationToken} associated with the {@link ComplicationProvider}
|
||||
* to be removed.
|
||||
* @return The removed {@link ComplicationProvider}, {@code null} if not found.
|
||||
*/
|
||||
public OverlayProvider removeOverlay(OverlayToken token) {
|
||||
final OverlayProvider removedOverlay = mOverlays.remove(token);
|
||||
public ListenableFuture<ComplicationProvider> removeComplication(ComplicationToken token) {
|
||||
return CallbackToFutureAdapter.getFuture(completer -> {
|
||||
mExecutor.execute(() -> {
|
||||
final ComplicationProvider removedComplication = mComplications.remove(token);
|
||||
|
||||
if (removedOverlay != null) {
|
||||
notifyCallbacks();
|
||||
}
|
||||
if (removedComplication != null) {
|
||||
notifyCallbacks();
|
||||
}
|
||||
completer.set(removedComplication);
|
||||
});
|
||||
|
||||
return removedOverlay;
|
||||
return "DreamOverlayStateController::removeComplication";
|
||||
});
|
||||
}
|
||||
|
||||
private void notifyCallbacks() {
|
||||
for (Callback callback : mCallbacks) {
|
||||
callback.onOverlayChanged();
|
||||
callback.onComplicationsChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCallback(@NonNull Callback callback) {
|
||||
Objects.requireNonNull(callback, "Callback must not be null. b/128895449");
|
||||
if (mCallbacks.contains(callback)) {
|
||||
return;
|
||||
}
|
||||
mExecutor.execute(() -> {
|
||||
Objects.requireNonNull(callback, "Callback must not be null. b/128895449");
|
||||
if (mCallbacks.contains(callback)) {
|
||||
return;
|
||||
}
|
||||
|
||||
mCallbacks.add(callback);
|
||||
mCallbacks.add(callback);
|
||||
|
||||
if (mOverlays.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (mComplications.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
callback.onOverlayChanged();
|
||||
callback.onComplicationsChanged();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeCallback(@NonNull Callback callback) {
|
||||
Objects.requireNonNull(callback, "Callback must not be null. b/128895449");
|
||||
mCallbacks.remove(callback);
|
||||
mExecutor.execute(() -> {
|
||||
Objects.requireNonNull(callback, "Callback must not be null. b/128895449");
|
||||
mCallbacks.remove(callback);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all registered {@link OverlayProvider} instances.
|
||||
* @return A collection of {@link OverlayProvider}.
|
||||
* Returns all registered {@link ComplicationProvider} instances.
|
||||
* @return A collection of {@link ComplicationProvider}.
|
||||
*/
|
||||
public Collection<OverlayProvider> getOverlays() {
|
||||
return mOverlays.values();
|
||||
public Collection<ComplicationProvider> getComplications() {
|
||||
return mComplications.values();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,8 +34,8 @@ import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* {@link AppWidgetProvider} is a singleton for accessing app widgets within SystemUI. This
|
||||
* consolidates resources such as the App Widget Host across potentially multiple
|
||||
* {@link AppWidgetOverlayProvider} instances and other usages.
|
||||
* consolidates resources such as the {@link AppWidgetHost} across potentially multiple
|
||||
* {@link ComplicationProvider} instances and other usages.
|
||||
*/
|
||||
@SysUISingleton
|
||||
public class AppWidgetProvider {
|
||||
@@ -87,8 +87,8 @@ public class AppWidgetProvider {
|
||||
final float density = mResources.getDisplayMetrics().density;
|
||||
final int height = Math.round((bottom - top) / density);
|
||||
final int width = Math.round((right - left) / density);
|
||||
appWidgetView.updateAppWidgetSize(null, width, height, width,
|
||||
height);
|
||||
appWidgetView.updateAppWidgetSize(null, width, height,
|
||||
width, height);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -26,25 +26,25 @@ import androidx.constraintlayout.widget.ConstraintSet;
|
||||
import com.android.systemui.CoreStartable;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.dagger.qualifiers.Main;
|
||||
import com.android.systemui.dreams.ComplicationHostView;
|
||||
import com.android.systemui.dreams.DreamOverlayStateController;
|
||||
import com.android.systemui.dreams.OverlayHostView;
|
||||
import com.android.systemui.dreams.dagger.AppWidgetOverlayComponent;
|
||||
import com.android.systemui.dreams.appwidgets.dagger.AppWidgetComponent;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* {@link AppWidgetOverlayPrimer} reads the configured App Widget Overlay from resources on start
|
||||
* {@link ComplicationPrimer} reads the configured AppWidget Complications from resources on start
|
||||
* and populates them into the {@link DreamOverlayStateController}.
|
||||
*/
|
||||
public class AppWidgetOverlayPrimer extends CoreStartable {
|
||||
public class ComplicationPrimer extends CoreStartable {
|
||||
private final Resources mResources;
|
||||
private final DreamOverlayStateController mDreamOverlayStateController;
|
||||
private final AppWidgetOverlayComponent.Factory mComponentFactory;
|
||||
private final AppWidgetComponent.Factory mComponentFactory;
|
||||
|
||||
@Inject
|
||||
public AppWidgetOverlayPrimer(Context context, @Main Resources resources,
|
||||
public ComplicationPrimer(Context context, @Main Resources resources,
|
||||
DreamOverlayStateController overlayStateController,
|
||||
AppWidgetOverlayComponent.Factory appWidgetOverlayFactory) {
|
||||
AppWidgetComponent.Factory appWidgetOverlayFactory) {
|
||||
super(context);
|
||||
mResources = resources;
|
||||
mDreamOverlayStateController = overlayStateController;
|
||||
@@ -62,17 +62,18 @@ public class AppWidgetOverlayPrimer extends CoreStartable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the {@link OverlayHostView.LayoutParams} for a given gravity. Default dimension
|
||||
* constraints are also included in the params.
|
||||
* Generates the {@link ComplicationHostView.LayoutParams} for a given gravity. Default
|
||||
* dimension constraints are also included in the params.
|
||||
* @param gravity The gravity for the layout as defined by {@link Gravity}.
|
||||
* @param resources The resourcs from which default dimensions will be extracted from.
|
||||
* @return {@link OverlayHostView.LayoutParams} representing the provided gravity and default
|
||||
* parameters.
|
||||
* @return {@link ComplicationHostView.LayoutParams} representing the provided gravity and
|
||||
* default parameters.
|
||||
*/
|
||||
private static OverlayHostView.LayoutParams getLayoutParams(int gravity, Resources resources) {
|
||||
final OverlayHostView.LayoutParams params = new OverlayHostView.LayoutParams(
|
||||
OverlayHostView.LayoutParams.MATCH_CONSTRAINT,
|
||||
OverlayHostView.LayoutParams.MATCH_CONSTRAINT);
|
||||
private static ComplicationHostView.LayoutParams getLayoutParams(int gravity,
|
||||
Resources resources) {
|
||||
final ComplicationHostView.LayoutParams params = new ComplicationHostView.LayoutParams(
|
||||
ComplicationHostView.LayoutParams.MATCH_CONSTRAINT,
|
||||
ComplicationHostView.LayoutParams.MATCH_CONSTRAINT);
|
||||
|
||||
if ((gravity & Gravity.BOTTOM) == Gravity.BOTTOM) {
|
||||
params.bottomToBottom = ConstraintSet.PARENT_ID;
|
||||
@@ -92,28 +93,28 @@ public class AppWidgetOverlayPrimer extends CoreStartable {
|
||||
|
||||
// For now, apply the same sizing constraints on every widget.
|
||||
params.matchConstraintPercentHeight =
|
||||
resources.getFloat(R.dimen.config_dreamOverlayComponentHeightPercent);
|
||||
resources.getFloat(R.dimen.config_dreamComplicationHeightPercent);
|
||||
params.matchConstraintPercentWidth =
|
||||
resources.getFloat(R.dimen.config_dreamOverlayComponentWidthPercent);
|
||||
resources.getFloat(R.dimen.config_dreamComplicationWidthPercent);
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Helper method for loading widgets based on configuration.
|
||||
*/
|
||||
private void loadDefaultWidgets() {
|
||||
final int[] positions = mResources.getIntArray(R.array.config_dreamOverlayPositions);
|
||||
final int[] positions = mResources.getIntArray(R.array.config_dreamComplicationPositions);
|
||||
final String[] components =
|
||||
mResources.getStringArray(R.array.config_dreamOverlayComponents);
|
||||
mResources.getStringArray(R.array.config_dreamAppWidgetComplications);
|
||||
|
||||
for (int i = 0; i < Math.min(positions.length, components.length); i++) {
|
||||
final AppWidgetOverlayComponent component = mComponentFactory.build(
|
||||
final AppWidgetComponent component = mComponentFactory.build(
|
||||
ComponentName.unflattenFromString(components[i]),
|
||||
getLayoutParams(positions[i], mResources));
|
||||
|
||||
mDreamOverlayStateController.addOverlay(component.getAppWidgetOverlayProvider());
|
||||
mDreamOverlayStateController.addComplication(
|
||||
component.getAppWidgetComplicationProvider());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,30 +22,30 @@ import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
import com.android.systemui.dreams.OverlayHost;
|
||||
import com.android.systemui.dreams.OverlayHostView;
|
||||
import com.android.systemui.dreams.OverlayProvider;
|
||||
import com.android.systemui.dreams.ComplicationHost;
|
||||
import com.android.systemui.dreams.ComplicationHostView;
|
||||
import com.android.systemui.plugins.ActivityStarter;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* {@link AppWidgetOverlayProvider} is an implementation of {@link OverlayProvider} for providing
|
||||
* app widget-based overlays.
|
||||
* {@link ComplicationProvider} is an implementation of
|
||||
* {@link com.android.systemui.dreams.ComplicationProvider} for providing app widget-based
|
||||
* complications.
|
||||
*/
|
||||
public class AppWidgetOverlayProvider implements OverlayProvider {
|
||||
private static final String TAG = "AppWdgtOverlayProvider";
|
||||
public class ComplicationProvider implements com.android.systemui.dreams.ComplicationProvider {
|
||||
private static final String TAG = "AppWidgetCompProvider";
|
||||
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
|
||||
|
||||
private final ActivityStarter mActivityStarter;
|
||||
private final AppWidgetProvider mAppWidgetProvider;
|
||||
private final ComponentName mComponentName;
|
||||
private final OverlayHostView.LayoutParams mLayoutParams;
|
||||
private final ComplicationHostView.LayoutParams mLayoutParams;
|
||||
|
||||
@Inject
|
||||
public AppWidgetOverlayProvider(ActivityStarter activityStarter,
|
||||
public ComplicationProvider(ActivityStarter activityStarter,
|
||||
ComponentName componentName, AppWidgetProvider widgetProvider,
|
||||
OverlayHostView.LayoutParams layoutParams) {
|
||||
ComplicationHostView.LayoutParams layoutParams) {
|
||||
mActivityStarter = activityStarter;
|
||||
mComponentName = componentName;
|
||||
mAppWidgetProvider = widgetProvider;
|
||||
@@ -53,8 +53,9 @@ public class AppWidgetOverlayProvider implements OverlayProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOverlay(Context context, OverlayHost.CreationCallback creationCallback,
|
||||
OverlayHost.InteractionCallback interactionCallback) {
|
||||
public void onCreateComplication(Context context,
|
||||
ComplicationHost.CreationCallback creationCallback,
|
||||
ComplicationHost.InteractionCallback interactionCallback) {
|
||||
final AppWidgetHostView widget = mAppWidgetProvider.getWidget(mComponentName);
|
||||
|
||||
if (widget == null) {
|
||||
@@ -14,26 +14,26 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.systemui.dreams.dagger;
|
||||
package com.android.systemui.dreams.appwidgets.dagger;
|
||||
|
||||
import android.content.ComponentName;
|
||||
|
||||
import com.android.systemui.dreams.OverlayHostView;
|
||||
import com.android.systemui.dreams.appwidgets.AppWidgetOverlayProvider;
|
||||
import com.android.systemui.dreams.ComplicationHostView;
|
||||
import com.android.systemui.dreams.appwidgets.ComplicationProvider;
|
||||
|
||||
import dagger.BindsInstance;
|
||||
import dagger.Subcomponent;
|
||||
|
||||
/** */
|
||||
@Subcomponent
|
||||
public interface AppWidgetOverlayComponent {
|
||||
public interface AppWidgetComponent {
|
||||
/** */
|
||||
@Subcomponent.Factory
|
||||
interface Factory {
|
||||
AppWidgetOverlayComponent build(@BindsInstance ComponentName component,
|
||||
@BindsInstance OverlayHostView.LayoutParams layoutParams);
|
||||
AppWidgetComponent build(@BindsInstance ComponentName component,
|
||||
@BindsInstance ComplicationHostView.LayoutParams layoutParams);
|
||||
}
|
||||
|
||||
/** Builds a {@link AppWidgetOverlayProvider}. */
|
||||
AppWidgetOverlayProvider getAppWidgetOverlayProvider();
|
||||
/** Builds a {@link ComplicationProvider}. */
|
||||
ComplicationProvider getAppWidgetComplicationProvider();
|
||||
}
|
||||
@@ -16,11 +16,15 @@
|
||||
|
||||
package com.android.systemui.dreams.dagger;
|
||||
|
||||
import com.android.systemui.dreams.appwidgets.dagger.AppWidgetComponent;
|
||||
|
||||
import dagger.Module;
|
||||
|
||||
/**
|
||||
* Dagger Module providing Communal-related functionality.
|
||||
*/
|
||||
@Module(subcomponents = {AppWidgetOverlayComponent.class, DreamOverlayComponent.class})
|
||||
@Module(subcomponents = {
|
||||
AppWidgetComponent.class,
|
||||
DreamOverlayComponent.class})
|
||||
public interface DreamModule {
|
||||
}
|
||||
|
||||
@@ -33,8 +33,8 @@ import androidx.test.filters.SmallTest;
|
||||
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
import com.android.systemui.SysuiTestableContext;
|
||||
import com.android.systemui.dreams.appwidgets.AppWidgetOverlayProvider;
|
||||
import com.android.systemui.dreams.appwidgets.AppWidgetProvider;
|
||||
import com.android.systemui.dreams.appwidgets.ComplicationProvider;
|
||||
import com.android.systemui.plugins.ActivityStarter;
|
||||
import com.android.systemui.utils.leaks.LeakCheckedTest;
|
||||
|
||||
@@ -48,7 +48,7 @@ import org.mockito.MockitoAnnotations;
|
||||
|
||||
@SmallTest
|
||||
@RunWith(AndroidTestingRunner.class)
|
||||
public class AppWidgetOverlayProviderTest extends SysuiTestCase {
|
||||
public class ComplicationProviderTest extends SysuiTestCase {
|
||||
@Mock
|
||||
ActivityStarter mActivityStarter;
|
||||
|
||||
@@ -62,10 +62,10 @@ public class AppWidgetOverlayProviderTest extends SysuiTestCase {
|
||||
AppWidgetHostView mAppWidgetHostView;
|
||||
|
||||
@Mock
|
||||
OverlayHost.CreationCallback mCreationCallback;
|
||||
ComplicationHost.CreationCallback mCreationCallback;
|
||||
|
||||
@Mock
|
||||
OverlayHost.InteractionCallback mInteractionCallback;
|
||||
ComplicationHost.InteractionCallback mInteractionCallback;
|
||||
|
||||
@Mock
|
||||
PendingIntent mPendingIntent;
|
||||
@@ -73,7 +73,7 @@ public class AppWidgetOverlayProviderTest extends SysuiTestCase {
|
||||
@Mock
|
||||
RemoteViews.RemoteResponse mRemoteResponse;
|
||||
|
||||
AppWidgetOverlayProvider mOverlayProvider;
|
||||
ComplicationProvider mComplicationProvider;
|
||||
|
||||
RemoteViews.InteractionHandler mInteractionHandler;
|
||||
|
||||
@@ -84,8 +84,9 @@ public class AppWidgetOverlayProviderTest extends SysuiTestCase {
|
||||
public SysuiTestableContext mContext = new SysuiTestableContext(
|
||||
InstrumentationRegistry.getContext(), mLeakCheck);
|
||||
|
||||
OverlayHostView.LayoutParams mLayoutParams = new OverlayHostView.LayoutParams(
|
||||
OverlayHostView.LayoutParams.MATCH_PARENT, OverlayHostView.LayoutParams.MATCH_PARENT);
|
||||
ComplicationHostView.LayoutParams mLayoutParams = new ComplicationHostView.LayoutParams(
|
||||
ComplicationHostView.LayoutParams.MATCH_PARENT,
|
||||
ComplicationHostView.LayoutParams.MATCH_PARENT);
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
@@ -93,7 +94,7 @@ public class AppWidgetOverlayProviderTest extends SysuiTestCase {
|
||||
when(mPendingIntent.isActivity()).thenReturn(true);
|
||||
when(mAppWidgetProvider.getWidget(mComponentName)).thenReturn(mAppWidgetHostView);
|
||||
|
||||
mOverlayProvider = new AppWidgetOverlayProvider(
|
||||
mComplicationProvider = new ComplicationProvider(
|
||||
mActivityStarter,
|
||||
mComponentName,
|
||||
mAppWidgetProvider,
|
||||
@@ -103,7 +104,8 @@ public class AppWidgetOverlayProviderTest extends SysuiTestCase {
|
||||
final ArgumentCaptor<RemoteViews.InteractionHandler> creationCallbackCapture =
|
||||
ArgumentCaptor.forClass(RemoteViews.InteractionHandler.class);
|
||||
|
||||
mOverlayProvider.onCreateOverlay(mContext, mCreationCallback, mInteractionCallback);
|
||||
mComplicationProvider.onCreateComplication(mContext, mCreationCallback,
|
||||
mInteractionCallback);
|
||||
verify(mAppWidgetHostView, times(1))
|
||||
.setInteractionHandler(creationCallbackCapture.capture());
|
||||
mInteractionHandler = creationCallbackCapture.getValue();
|
||||
@@ -74,7 +74,7 @@ public class DreamOverlayServiceTest extends SysuiTestCase {
|
||||
WindowManagerImpl mWindowManager;
|
||||
|
||||
@Mock
|
||||
OverlayProvider mProvider;
|
||||
ComplicationProvider mProvider;
|
||||
|
||||
@Mock
|
||||
DreamOverlayStateController mDreamOverlayStateController;
|
||||
@@ -124,16 +124,16 @@ public class DreamOverlayServiceTest extends SysuiTestCase {
|
||||
verify(mWindowManager).addView(any(), any());
|
||||
|
||||
// Add overlay.
|
||||
service.addOverlay(mProvider);
|
||||
service.addComplication(mProvider);
|
||||
mMainExecutor.runAllReady();
|
||||
|
||||
final ArgumentCaptor<OverlayHost.CreationCallback> creationCallbackCapture =
|
||||
ArgumentCaptor.forClass(OverlayHost.CreationCallback.class);
|
||||
final ArgumentCaptor<OverlayHost.InteractionCallback> interactionCallbackCapture =
|
||||
ArgumentCaptor.forClass(OverlayHost.InteractionCallback.class);
|
||||
final ArgumentCaptor<ComplicationHost.CreationCallback> creationCallbackCapture =
|
||||
ArgumentCaptor.forClass(ComplicationHost.CreationCallback.class);
|
||||
final ArgumentCaptor<ComplicationHost.InteractionCallback> interactionCallbackCapture =
|
||||
ArgumentCaptor.forClass(ComplicationHost.InteractionCallback.class);
|
||||
|
||||
// Ensure overlay provider is asked to create view.
|
||||
verify(mProvider).onCreateOverlay(any(), creationCallbackCapture.capture(),
|
||||
verify(mProvider).onCreateComplication(any(), creationCallbackCapture.capture(),
|
||||
interactionCallbackCapture.capture());
|
||||
mMainExecutor.runAllReady();
|
||||
|
||||
@@ -169,12 +169,12 @@ public class DreamOverlayServiceTest extends SysuiTestCase {
|
||||
ArgumentCaptor.forClass(DreamOverlayStateController.Callback.class);
|
||||
|
||||
verify(mDreamOverlayStateController).addCallback(callbackCapture.capture());
|
||||
when(mDreamOverlayStateController.getOverlays()).thenReturn(Arrays.asList(mProvider));
|
||||
callbackCapture.getValue().onOverlayChanged();
|
||||
when(mDreamOverlayStateController.getComplications()).thenReturn(Arrays.asList(mProvider));
|
||||
callbackCapture.getValue().onComplicationsChanged();
|
||||
mMainExecutor.runAllReady();
|
||||
|
||||
// Verify provider is asked to create overlay.
|
||||
verify(mProvider).onCreateOverlay(any(), any(), any());
|
||||
verify(mProvider).onCreateComplication(any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -27,6 +27,10 @@ import android.testing.AndroidTestingRunner;
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
import com.android.systemui.util.concurrency.FakeExecutor;
|
||||
import com.android.systemui.util.time.FakeSystemClock;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -43,7 +47,9 @@ public class DreamOverlayStateControllerTest extends SysuiTestCase {
|
||||
DreamOverlayStateController.Callback mCallback;
|
||||
|
||||
@Mock
|
||||
OverlayProvider mProvider;
|
||||
ComplicationProvider mProvider;
|
||||
|
||||
final FakeExecutor mExecutor = new FakeExecutor(new FakeSystemClock());
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
@@ -51,36 +57,43 @@ public class DreamOverlayStateControllerTest extends SysuiTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCallback() {
|
||||
final DreamOverlayStateController stateController = new DreamOverlayStateController();
|
||||
public void testCallback() throws Exception {
|
||||
final DreamOverlayStateController stateController = new DreamOverlayStateController(
|
||||
mExecutor);
|
||||
stateController.addCallback(mCallback);
|
||||
|
||||
// Add overlay and verify callback is notified.
|
||||
final DreamOverlayStateController.OverlayToken token =
|
||||
stateController.addOverlay(mProvider);
|
||||
// Add complication and verify callback is notified.
|
||||
final ListenableFuture<DreamOverlayStateController.ComplicationToken> tokenFuture =
|
||||
stateController.addComplication(mProvider);
|
||||
|
||||
verify(mCallback, times(1)).onOverlayChanged();
|
||||
mExecutor.runAllReady();
|
||||
|
||||
final Collection<OverlayProvider> providers = stateController.getOverlays();
|
||||
verify(mCallback, times(1)).onComplicationsChanged();
|
||||
|
||||
final Collection<ComplicationProvider> providers = stateController.getComplications();
|
||||
assertEquals(providers.size(), 1);
|
||||
assertTrue(providers.contains(mProvider));
|
||||
|
||||
clearInvocations(mCallback);
|
||||
|
||||
// Remove overlay and verify callback is notified.
|
||||
stateController.removeOverlay(token);
|
||||
verify(mCallback, times(1)).onOverlayChanged();
|
||||
// Remove complication and verify callback is notified.
|
||||
stateController.removeComplication(tokenFuture.get());
|
||||
mExecutor.runAllReady();
|
||||
verify(mCallback, times(1)).onComplicationsChanged();
|
||||
assertTrue(providers.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotifyOnCallbackAdd() {
|
||||
final DreamOverlayStateController stateController = new DreamOverlayStateController();
|
||||
final DreamOverlayStateController.OverlayToken token =
|
||||
stateController.addOverlay(mProvider);
|
||||
final DreamOverlayStateController stateController =
|
||||
new DreamOverlayStateController(mExecutor);
|
||||
|
||||
stateController.addComplication(mProvider);
|
||||
mExecutor.runAllReady();
|
||||
|
||||
// Verify callback occurs on add when an overlay is already present.
|
||||
stateController.addCallback(mCallback);
|
||||
verify(mCallback, times(1)).onOverlayChanged();
|
||||
mExecutor.runAllReady();
|
||||
verify(mCallback, times(1)).onComplicationsChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ import com.android.systemui.R;
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
import com.android.systemui.SysuiTestableContext;
|
||||
import com.android.systemui.dreams.DreamOverlayStateController;
|
||||
import com.android.systemui.dreams.dagger.AppWidgetOverlayComponent;
|
||||
import com.android.systemui.dreams.appwidgets.dagger.AppWidgetComponent;
|
||||
import com.android.systemui.utils.leaks.LeakCheckedTest;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -50,7 +50,7 @@ import org.mockito.MockitoAnnotations;
|
||||
|
||||
@SmallTest
|
||||
@RunWith(AndroidTestingRunner.class)
|
||||
public class AppWidgetOverlayPrimerTest extends SysuiTestCase {
|
||||
public class ComplicationPrimerTest extends SysuiTestCase {
|
||||
@Rule
|
||||
public final LeakCheckedTest.SysuiLeakCheck mLeakCheck = new LeakCheckedTest.SysuiLeakCheck();
|
||||
|
||||
@@ -62,56 +62,57 @@ public class AppWidgetOverlayPrimerTest extends SysuiTestCase {
|
||||
Resources mResources;
|
||||
|
||||
@Mock
|
||||
AppWidgetOverlayComponent mAppWidgetOverlayComponent1;
|
||||
AppWidgetComponent mAppWidgetComplicationComponent1;
|
||||
@Mock
|
||||
AppWidgetOverlayComponent mAppWidgetOverlayComponent2;
|
||||
AppWidgetComponent mAppWidgetComplicationComponent2;
|
||||
|
||||
@Mock
|
||||
AppWidgetOverlayProvider mAppWidgetOverlayProvider1;
|
||||
ComplicationProvider mComplicationProvider1;
|
||||
|
||||
@Mock
|
||||
AppWidgetOverlayProvider mAppWidgetOverlayProvider2;
|
||||
ComplicationProvider mComplicationProvider2;
|
||||
|
||||
final ComponentName mAppOverlayComponent1 =
|
||||
final ComponentName mAppComplicationComponent1 =
|
||||
ComponentName.unflattenFromString("com.foo.bar/.Baz");
|
||||
final ComponentName mAppOverlayComponent2 =
|
||||
final ComponentName mAppComplicationComponent2 =
|
||||
ComponentName.unflattenFromString("com.foo.bar/.Baz2");
|
||||
|
||||
final int mAppOverlayGravity1 = Gravity.BOTTOM | Gravity.START;
|
||||
final int mAppOverlayGravity2 = Gravity.BOTTOM | Gravity.END;
|
||||
final int mAppComplicationGravity1 = Gravity.BOTTOM | Gravity.START;
|
||||
final int mAppComplicationGravity2 = Gravity.BOTTOM | Gravity.END;
|
||||
|
||||
final String[] mComponents = new String[]{mAppOverlayComponent1.flattenToString(),
|
||||
mAppOverlayComponent2.flattenToString() };
|
||||
final int[] mPositions = new int[]{ mAppOverlayGravity1, mAppOverlayGravity2 };
|
||||
final String[] mComponents = new String[]{mAppComplicationComponent1.flattenToString(),
|
||||
mAppComplicationComponent2.flattenToString() };
|
||||
final int[] mPositions = new int[]{mAppComplicationGravity1, mAppComplicationGravity2};
|
||||
|
||||
@Mock
|
||||
DreamOverlayStateController mDreamOverlayStateController;
|
||||
|
||||
@Mock
|
||||
AppWidgetOverlayComponent.Factory mAppWidgetOverlayProviderFactory;
|
||||
AppWidgetComponent.Factory mAppWidgetComplicationProviderFactory;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mAppWidgetOverlayProviderFactory.build(eq(mAppOverlayComponent1), any()))
|
||||
.thenReturn(mAppWidgetOverlayComponent1);
|
||||
when(mAppWidgetOverlayComponent1.getAppWidgetOverlayProvider())
|
||||
.thenReturn(mAppWidgetOverlayProvider1);
|
||||
when(mAppWidgetOverlayProviderFactory.build(eq(mAppOverlayComponent2), any()))
|
||||
.thenReturn(mAppWidgetOverlayComponent2);
|
||||
when(mAppWidgetOverlayComponent2.getAppWidgetOverlayProvider())
|
||||
.thenReturn(mAppWidgetOverlayProvider2);
|
||||
when(mResources.getIntArray(R.array.config_dreamOverlayPositions)).thenReturn(mPositions);
|
||||
when(mResources.getStringArray(R.array.config_dreamOverlayComponents))
|
||||
when(mAppWidgetComplicationProviderFactory.build(eq(mAppComplicationComponent1), any()))
|
||||
.thenReturn(mAppWidgetComplicationComponent1);
|
||||
when(mAppWidgetComplicationComponent1.getAppWidgetComplicationProvider())
|
||||
.thenReturn(mComplicationProvider1);
|
||||
when(mAppWidgetComplicationProviderFactory.build(eq(mAppComplicationComponent2), any()))
|
||||
.thenReturn(mAppWidgetComplicationComponent2);
|
||||
when(mAppWidgetComplicationComponent2.getAppWidgetComplicationProvider())
|
||||
.thenReturn(mComplicationProvider2);
|
||||
when(mResources.getIntArray(R.array.config_dreamComplicationPositions))
|
||||
.thenReturn(mPositions);
|
||||
when(mResources.getStringArray(R.array.config_dreamAppWidgetComplications))
|
||||
.thenReturn(mComponents);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoading() {
|
||||
final AppWidgetOverlayPrimer primer = new AppWidgetOverlayPrimer(mContext,
|
||||
final ComplicationPrimer primer = new ComplicationPrimer(mContext,
|
||||
mResources,
|
||||
mDreamOverlayStateController,
|
||||
mAppWidgetOverlayProviderFactory);
|
||||
mAppWidgetComplicationProviderFactory);
|
||||
|
||||
// Inform primer to begin.
|
||||
primer.onBootCompleted();
|
||||
@@ -120,7 +121,8 @@ public class AppWidgetOverlayPrimerTest extends SysuiTestCase {
|
||||
{
|
||||
final ArgumentCaptor<ConstraintLayout.LayoutParams> layoutParamsArgumentCaptor =
|
||||
ArgumentCaptor.forClass(ConstraintLayout.LayoutParams.class);
|
||||
verify(mAppWidgetOverlayProviderFactory, times(1)).build(eq(mAppOverlayComponent1),
|
||||
verify(mAppWidgetComplicationProviderFactory, times(1))
|
||||
.build(eq(mAppComplicationComponent1),
|
||||
layoutParamsArgumentCaptor.capture());
|
||||
|
||||
assertEquals(layoutParamsArgumentCaptor.getValue().startToStart,
|
||||
@@ -129,14 +131,15 @@ public class AppWidgetOverlayPrimerTest extends SysuiTestCase {
|
||||
ConstraintLayout.LayoutParams.PARENT_ID);
|
||||
|
||||
verify(mDreamOverlayStateController, times(1))
|
||||
.addOverlay(eq(mAppWidgetOverlayProvider1));
|
||||
.addComplication(eq(mComplicationProvider1));
|
||||
}
|
||||
|
||||
// Verify the second component is added to the state controller with the proper position.
|
||||
{
|
||||
final ArgumentCaptor<ConstraintLayout.LayoutParams> layoutParamsArgumentCaptor =
|
||||
ArgumentCaptor.forClass(ConstraintLayout.LayoutParams.class);
|
||||
verify(mAppWidgetOverlayProviderFactory, times(1)).build(eq(mAppOverlayComponent2),
|
||||
verify(mAppWidgetComplicationProviderFactory, times(1))
|
||||
.build(eq(mAppComplicationComponent2),
|
||||
layoutParamsArgumentCaptor.capture());
|
||||
|
||||
assertEquals(layoutParamsArgumentCaptor.getValue().endToEnd,
|
||||
@@ -144,19 +147,19 @@ public class AppWidgetOverlayPrimerTest extends SysuiTestCase {
|
||||
assertEquals(layoutParamsArgumentCaptor.getValue().bottomToBottom,
|
||||
ConstraintLayout.LayoutParams.PARENT_ID);
|
||||
verify(mDreamOverlayStateController, times(1))
|
||||
.addOverlay(eq(mAppWidgetOverlayProvider1));
|
||||
.addComplication(eq(mComplicationProvider1));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoComponents() {
|
||||
when(mResources.getStringArray(R.array.config_dreamOverlayComponents))
|
||||
when(mResources.getStringArray(R.array.config_dreamAppWidgetComplications))
|
||||
.thenReturn(new String[]{});
|
||||
|
||||
final AppWidgetOverlayPrimer primer = new AppWidgetOverlayPrimer(mContext,
|
||||
final ComplicationPrimer primer = new ComplicationPrimer(mContext,
|
||||
mResources,
|
||||
mDreamOverlayStateController,
|
||||
mAppWidgetOverlayProviderFactory);
|
||||
mAppWidgetComplicationProviderFactory);
|
||||
|
||||
// Inform primer to begin.
|
||||
primer.onBootCompleted();
|
||||
@@ -164,25 +167,25 @@ public class AppWidgetOverlayPrimerTest extends SysuiTestCase {
|
||||
|
||||
// Make sure there is no request to add a widget if no components are specified by the
|
||||
// product.
|
||||
verify(mAppWidgetOverlayProviderFactory, never()).build(any(), any());
|
||||
verify(mDreamOverlayStateController, never()).addOverlay(any());
|
||||
verify(mAppWidgetComplicationProviderFactory, never()).build(any(), any());
|
||||
verify(mDreamOverlayStateController, never()).addComplication(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoPositions() {
|
||||
when(mResources.getIntArray(R.array.config_dreamOverlayPositions))
|
||||
when(mResources.getIntArray(R.array.config_dreamComplicationPositions))
|
||||
.thenReturn(new int[]{});
|
||||
|
||||
final AppWidgetOverlayPrimer primer = new AppWidgetOverlayPrimer(mContext,
|
||||
final ComplicationPrimer primer = new ComplicationPrimer(mContext,
|
||||
mResources,
|
||||
mDreamOverlayStateController,
|
||||
mAppWidgetOverlayProviderFactory);
|
||||
mAppWidgetComplicationProviderFactory);
|
||||
|
||||
primer.onBootCompleted();
|
||||
|
||||
// Make sure there is no request to add a widget if no positions are specified by the
|
||||
// product.
|
||||
verify(mAppWidgetOverlayProviderFactory, never()).build(any(), any());
|
||||
verify(mDreamOverlayStateController, never()).addOverlay(any());
|
||||
verify(mAppWidgetComplicationProviderFactory, never()).build(any(), any());
|
||||
verify(mDreamOverlayStateController, never()).addComplication(any());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user