Merge "Update Resource Builders." into androidx-main
diff --git a/wear/tiles/tiles/src/main/java/androidx/wear/tiles/EventBuilders.java b/wear/tiles/tiles/src/main/java/androidx/wear/tiles/EventBuilders.java
index 17e5741..71b74da 100644
--- a/wear/tiles/tiles/src/main/java/androidx/wear/tiles/EventBuilders.java
+++ b/wear/tiles/tiles/src/main/java/androidx/wear/tiles/EventBuilders.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 The Android Open Source Project
+ * Copyright 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,28 +25,46 @@
public final class EventBuilders {
private EventBuilders() {}
- /** Event fired when a tile has been added to the carousel. */
+ /**
+ * Event fired when a tile has been added to the carousel.
+ *
+ * @since 1.0
+ */
public static final class TileAddEvent {
private final EventProto.TileAddEvent mImpl;
- private TileAddEvent(EventProto.TileAddEvent impl) {
+ TileAddEvent(EventProto.TileAddEvent impl) {
this.mImpl = impl;
}
- /** @hide */
+ /**
+ * Creates a new wrapper instance from the proto.
+ *
+ * @hide
+ */
@RestrictTo(Scope.LIBRARY_GROUP)
@NonNull
public static TileAddEvent fromProto(@NonNull EventProto.TileAddEvent proto) {
return new TileAddEvent(proto);
}
- /** @hide */
+ /**
+ * Returns the internal proto instance.
+ *
+ * @hide
+ */
@RestrictTo(Scope.LIBRARY_GROUP)
@NonNull
public EventProto.TileAddEvent toProto() {
return mImpl;
}
+ @Override
+ @NonNull
+ public String toString() {
+ return "TileAddEvent{" + "}";
+ }
+
/** Builder for {@link TileAddEvent} */
public static final class Builder {
private final EventProto.TileAddEvent.Builder mImpl =
@@ -62,28 +80,46 @@
}
}
- /** Event fired when a tile has been removed from the carousel. */
+ /**
+ * Event fired when a tile has been removed from the carousel.
+ *
+ * @since 1.0
+ */
public static final class TileRemoveEvent {
private final EventProto.TileRemoveEvent mImpl;
- private TileRemoveEvent(EventProto.TileRemoveEvent impl) {
+ TileRemoveEvent(EventProto.TileRemoveEvent impl) {
this.mImpl = impl;
}
- /** @hide */
+ /**
+ * Creates a new wrapper instance from the proto.
+ *
+ * @hide
+ */
@RestrictTo(Scope.LIBRARY_GROUP)
@NonNull
public static TileRemoveEvent fromProto(@NonNull EventProto.TileRemoveEvent proto) {
return new TileRemoveEvent(proto);
}
- /** @hide */
+ /**
+ * Returns the internal proto instance.
+ *
+ * @hide
+ */
@RestrictTo(Scope.LIBRARY_GROUP)
@NonNull
public EventProto.TileRemoveEvent toProto() {
return mImpl;
}
+ @Override
+ @NonNull
+ public String toString() {
+ return "TileRemoveEvent{" + "}";
+ }
+
/** Builder for {@link TileRemoveEvent} */
public static final class Builder {
private final EventProto.TileRemoveEvent.Builder mImpl =
@@ -99,28 +135,46 @@
}
}
- /** Event fired when a tile is swiped to by the user (i.e. it's visible on screen). */
+ /**
+ * Event fired when a tile is swiped to by the user (i.e. it's visible on screen).
+ *
+ * @since 1.0
+ */
public static final class TileEnterEvent {
private final EventProto.TileEnterEvent mImpl;
- private TileEnterEvent(EventProto.TileEnterEvent impl) {
+ TileEnterEvent(EventProto.TileEnterEvent impl) {
this.mImpl = impl;
}
- /** @hide */
+ /**
+ * Creates a new wrapper instance from the proto.
+ *
+ * @hide
+ */
@RestrictTo(Scope.LIBRARY_GROUP)
@NonNull
public static TileEnterEvent fromProto(@NonNull EventProto.TileEnterEvent proto) {
return new TileEnterEvent(proto);
}
- /** @hide */
+ /**
+ * Returns the internal proto instance.
+ *
+ * @hide
+ */
@RestrictTo(Scope.LIBRARY_GROUP)
@NonNull
public EventProto.TileEnterEvent toProto() {
return mImpl;
}
+ @Override
+ @NonNull
+ public String toString() {
+ return "TileEnterEvent{" + "}";
+ }
+
/** Builder for {@link TileEnterEvent} */
public static final class Builder {
private final EventProto.TileEnterEvent.Builder mImpl =
@@ -139,28 +193,44 @@
/**
* Event fired when a tile is swiped away from by the user (i.e. it's no longer visible on
* screen).
+ *
+ * @since 1.0
*/
public static final class TileLeaveEvent {
private final EventProto.TileLeaveEvent mImpl;
- private TileLeaveEvent(EventProto.TileLeaveEvent impl) {
+ TileLeaveEvent(EventProto.TileLeaveEvent impl) {
this.mImpl = impl;
}
- /** @hide */
+ /**
+ * Creates a new wrapper instance from the proto.
+ *
+ * @hide
+ */
@RestrictTo(Scope.LIBRARY_GROUP)
@NonNull
public static TileLeaveEvent fromProto(@NonNull EventProto.TileLeaveEvent proto) {
return new TileLeaveEvent(proto);
}
- /** @hide */
+ /**
+ * Returns the internal proto instance.
+ *
+ * @hide
+ */
@RestrictTo(Scope.LIBRARY_GROUP)
@NonNull
public EventProto.TileLeaveEvent toProto() {
return mImpl;
}
+ @Override
+ @NonNull
+ public String toString() {
+ return "TileLeaveEvent{" + "}";
+ }
+
/** Builder for {@link TileLeaveEvent} */
public static final class Builder {
private final EventProto.TileLeaveEvent.Builder mImpl =
diff --git a/wear/tiles/tiles/src/main/java/androidx/wear/tiles/TileAddEventData.java b/wear/tiles/tiles/src/main/java/androidx/wear/tiles/TileAddEventData.java
index feef838..f296d5b 100644
--- a/wear/tiles/tiles/src/main/java/androidx/wear/tiles/TileAddEventData.java
+++ b/wear/tiles/tiles/src/main/java/androidx/wear/tiles/TileAddEventData.java
@@ -20,7 +20,7 @@
import androidx.annotation.RestrictTo;
/**
- * Holder for Tiles' TileAddEvent class, to be parceled and transferred to a tile service.
+ * Holder for Tiles' TileAddEvent class, to be parceled and transferred to a Tile Service.
*
* <p>All this does is to serialize TileAddEvent as a protobuf and transmit it.
*
diff --git a/wear/tiles/tiles/src/main/java/androidx/wear/tiles/TileEnterEventData.java b/wear/tiles/tiles/src/main/java/androidx/wear/tiles/TileEnterEventData.java
index 4dae195..fda2841 100644
--- a/wear/tiles/tiles/src/main/java/androidx/wear/tiles/TileEnterEventData.java
+++ b/wear/tiles/tiles/src/main/java/androidx/wear/tiles/TileEnterEventData.java
@@ -20,7 +20,7 @@
import androidx.annotation.RestrictTo;
/**
- * Holder for Tiles' TileEnterEvent class, to be parceled and transferred to a tile service.
+ * Holder for Tiles' TileEnterEvent class, to be parceled and transferred to a Tile Service.
*
* <p>All this does is to serialize TileEnterEvent as a protobuf and transmit it.
*
diff --git a/wear/tiles/tiles/src/main/java/androidx/wear/tiles/TileRemoveEventData.java b/wear/tiles/tiles/src/main/java/androidx/wear/tiles/TileRemoveEventData.java
index 921a74b..9bccf59 100644
--- a/wear/tiles/tiles/src/main/java/androidx/wear/tiles/TileRemoveEventData.java
+++ b/wear/tiles/tiles/src/main/java/androidx/wear/tiles/TileRemoveEventData.java
@@ -20,7 +20,7 @@
import androidx.annotation.RestrictTo;
/**
- * Holder for Tiles' TileRemoveEvent class, to be parceled and transferred to a tile service.
+ * Holder for Tiles' TileRemoveEvent class, to be parceled and transferred to a Tile Service.
*
* <p>All this does is to serialize TileRemoveEvent as a protobuf and transmit it.
*
diff --git a/wear/watchface/watchface-editor/src/androidTest/java/androidx/wear/watchface/editor/EditorSessionTest.kt b/wear/watchface/watchface-editor/src/androidTest/java/androidx/wear/watchface/editor/EditorSessionTest.kt
index a2ab862..c6c602b 100644
--- a/wear/watchface/watchface-editor/src/androidTest/java/androidx/wear/watchface/editor/EditorSessionTest.kt
+++ b/wear/watchface/watchface-editor/src/androidTest/java/androidx/wear/watchface/editor/EditorSessionTest.kt
@@ -592,8 +592,30 @@
previewScreenshotParams: PreviewScreenshotParams? = null
): ActivityScenario<OnWatchFaceEditingTestActivity> {
val userStyleRepository = CurrentUserStyleRepository(UserStyleSchema(userStyleSettings))
+ val mockSurfaceHolder = `mock`(SurfaceHolder::class.java)
+ `when`(mockSurfaceHolder.surfaceFrame).thenReturn(screenBounds)
+ @Suppress("Deprecation")
+ val fakeRenderer = object : Renderer.CanvasRenderer(
+ mockSurfaceHolder,
+ userStyleRepository,
+ MutableWatchState().asWatchState(),
+ CanvasType.HARDWARE,
+ interactiveDrawModeUpdateDelayMillis = 16,
+ clearWithBackgroundTintBeforeRenderingHighlightLayer = false
+ ) {
+ override fun render(canvas: Canvas, bounds: Rect, zonedDateTime: ZonedDateTime) {
+ }
+
+ override fun renderHighlightLayer(
+ canvas: Canvas,
+ bounds: Rect,
+ zonedDateTime: ZonedDateTime
+ ) {
+ }
+ }
+
val complicationSlotsManager =
- ComplicationSlotsManager(complicationSlots, userStyleRepository)
+ ComplicationSlotsManager(complicationSlots, userStyleRepository, fakeRenderer)
complicationSlotsManager.watchState = placeholderWatchState
complicationSlotsManager.listenForStyleChanges(CoroutineScope(Dispatchers.Main.immediate))
diff --git a/wear/watchface/watchface-editor/src/main/java/androidx/wear/watchface/editor/EditorSession.kt b/wear/watchface/watchface-editor/src/main/java/androidx/wear/watchface/editor/EditorSession.kt
index 5e52e91..53832df 100644
--- a/wear/watchface/watchface-editor/src/main/java/androidx/wear/watchface/editor/EditorSession.kt
+++ b/wear/watchface/watchface-editor/src/main/java/androidx/wear/watchface/editor/EditorSession.kt
@@ -632,21 +632,6 @@
?.key
}
- override fun getComplicationSlotIdAt(@Px x: Int, @Px y: Int): Int? {
- requireNotClosed()
- return complicationSlotsState.value.entries
- .firstOrNull {
- it.value.isEnabled &&
- when (it.value.boundsType) {
- ComplicationSlotBoundsType.ROUND_RECT -> it.value.bounds.contains(x, y)
- ComplicationSlotBoundsType.BACKGROUND -> false
- ComplicationSlotBoundsType.EDGE -> false
- else -> false
- }
- }
- ?.key
- }
-
/**
* Returns the complication data source's preview [ComplicationData] if possible or fallback
* preview data based on complication data source icon and name if not. If the slot is
@@ -1041,6 +1026,11 @@
override val showComplicationRationaleDialogIntent
get() = editorDelegate.complicationRationaleDialogIntent
+
+ override fun getComplicationSlotIdAt(@Px x: Int, @Px y: Int): Int? {
+ requireNotClosed()
+ return editorDelegate.complicationSlotsManager.getComplicationSlotAt(x, y)?.id
+ }
}
@RequiresApi(27)
@@ -1130,6 +1120,21 @@
init {
fetchComplicationsData(coroutineScope)
}
+
+ override fun getComplicationSlotIdAt(@Px x: Int, @Px y: Int): Int? {
+ requireNotClosed()
+ return complicationSlotsState.value.entries
+ .firstOrNull {
+ it.value.isEnabled &&
+ when (it.value.boundsType) {
+ ComplicationSlotBoundsType.ROUND_RECT -> it.value.bounds.contains(x, y)
+ ComplicationSlotBoundsType.BACKGROUND -> false
+ ComplicationSlotBoundsType.EDGE -> false
+ else -> false
+ }
+ }
+ ?.key
+ }
}
internal class ComplicationDataSourceChooserRequest(
diff --git a/wear/watchface/watchface/src/main/java/androidx/wear/watchface/ComplicationSlotsManager.kt b/wear/watchface/watchface/src/main/java/androidx/wear/watchface/ComplicationSlotsManager.kt
index ea17261..bd4843b 100644
--- a/wear/watchface/watchface/src/main/java/androidx/wear/watchface/ComplicationSlotsManager.kt
+++ b/wear/watchface/watchface/src/main/java/androidx/wear/watchface/ComplicationSlotsManager.kt
@@ -133,8 +133,10 @@
public var configExtrasChangeCallback: WatchFace.ComplicationSlotConfigExtrasChangeCallback? =
null
+ /** @hide */
+ @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
@VisibleForTesting
- internal constructor(
+ public constructor(
complicationSlotCollection: Collection<ComplicationSlot>,
currentUserStyleRepository: CurrentUserStyleRepository,
renderer: Renderer