Port over improvements from code lab to watch face.
Bug: 32214858
Change-Id: I506dcb6165d5397fd442d9c33e956fe85c4fe022
diff --git a/wearable/wear/WatchFace/Wearable/src/main/java/com/example/android/wearable/watchface/config/AnalogComplicationConfigRecyclerViewAdapter.java b/wearable/wear/WatchFace/Wearable/src/main/java/com/example/android/wearable/watchface/config/AnalogComplicationConfigRecyclerViewAdapter.java
index ff6e197..096a380 100644
--- a/wearable/wear/WatchFace/Wearable/src/main/java/com/example/android/wearable/watchface/config/AnalogComplicationConfigRecyclerViewAdapter.java
+++ b/wearable/wear/WatchFace/Wearable/src/main/java/com/example/android/wearable/watchface/config/AnalogComplicationConfigRecyclerViewAdapter.java
@@ -17,9 +17,6 @@
package com.example.android.wearable.watchface.config;
import static com.example.android.wearable.watchface.config.ColorSelectionActivity.EXTRA_SHARED_PREF;
-import static com.example.android.wearable.watchface.watchface.AnalogComplicationWatchFaceService.COMPLICATION_IDS;
-import static com.example.android.wearable.watchface.watchface.AnalogComplicationWatchFaceService.LEFT_COMPLICATION_ID;
-import static com.example.android.wearable.watchface.watchface.AnalogComplicationWatchFaceService.RIGHT_COMPLICATION_ID;
import android.app.Activity;
import android.content.ComponentName;
@@ -112,6 +109,9 @@
// Selected complication id by user.
private int mSelectedComplicationId;
+ private int mLeftComplicationId;
+ private int mRightComplicationId;
+
// Required to retrieve complication data from watch face for preview.
private ProviderInfoRetriever mProviderInfoRetriever;
@@ -131,6 +131,11 @@
// Default value is invalid (only changed when user taps to change complication).
mSelectedComplicationId = -1;
+ mLeftComplicationId =
+ AnalogComplicationWatchFaceService.getComplicationId(ComplicationLocation.LEFT);
+ mRightComplicationId =
+ AnalogComplicationWatchFaceService.getComplicationId(ComplicationLocation.RIGHT);
+
mSharedPref = context.getSharedPreferences(
context.getString(R.string.analog_complication_preference_file_key),
Context.MODE_PRIVATE);
@@ -417,22 +422,17 @@
int[] supportedTypes = AnalogComplicationWatchFaceService
.getSupportedComplicationTypes(complicationLocation);
- if (supportedTypes.length > 0) {
+ ComponentName watchFace = new ComponentName(
+ currentActivity,
+ AnalogComplicationWatchFaceService.class);
- ComponentName watchFace = new ComponentName(
- currentActivity,
- AnalogComplicationWatchFaceService.class);
-
- currentActivity.startActivityForResult(
- ComplicationHelperActivity.createProviderChooserHelperIntent(
- currentActivity,
- watchFace,
- mSelectedComplicationId,
- supportedTypes),
- AnalogComplicationConfigActivity.COMPLICATION_CONFIG_REQUEST_CODE);
- } else {
- Log.d(TAG, "Complication has no supported types.");
- }
+ currentActivity.startActivityForResult(
+ ComplicationHelperActivity.createProviderChooserHelperIntent(
+ currentActivity,
+ watchFace,
+ mSelectedComplicationId,
+ supportedTypes),
+ AnalogComplicationConfigActivity.COMPLICATION_CONFIG_REQUEST_CODE);
} else {
Log.d(TAG, "Complication not supported by watch face.");
@@ -456,7 +456,7 @@
Log.d(TAG, "updateComplicationViews(): id: " + watchFaceComplicationId);
Log.d(TAG, "\tinfo: " + complicationProviderInfo);
- if (watchFaceComplicationId == LEFT_COMPLICATION_ID) {
+ if (watchFaceComplicationId == mLeftComplicationId) {
if (complicationProviderInfo != null) {
mLeftComplication.setImageIcon(complicationProviderInfo.providerIcon);
mLeftComplicationBackground.setVisibility(View.VISIBLE);
@@ -466,7 +466,7 @@
mLeftComplicationBackground.setVisibility(View.INVISIBLE);
}
- } else if (watchFaceComplicationId == RIGHT_COMPLICATION_ID) {
+ } else if (watchFaceComplicationId == mRightComplicationId) {
if (complicationProviderInfo != null) {
mRightComplication.setImageIcon(complicationProviderInfo.providerIcon);
mRightComplicationBackground.setVisibility(View.VISIBLE);
@@ -480,6 +480,8 @@
public void retrieveInitialComplicationsData() {
+ final int[] complicationIds = new int[] {mLeftComplicationId, mRightComplicationId};
+
mProviderInfoRetriever.retrieveProviderInfo(
new OnProviderInfoReceivedCallback() {
@Override
@@ -495,7 +497,7 @@
}
},
mWatchFaceComponentName,
- COMPLICATION_IDS);
+ complicationIds);
}
}
diff --git a/wearable/wear/WatchFace/Wearable/src/main/java/com/example/android/wearable/watchface/watchface/AnalogComplicationWatchFaceService.java b/wearable/wear/WatchFace/Wearable/src/main/java/com/example/android/wearable/watchface/watchface/AnalogComplicationWatchFaceService.java
index 77d485f..2779658 100644
--- a/wearable/wear/WatchFace/Wearable/src/main/java/com/example/android/wearable/watchface/watchface/AnalogComplicationWatchFaceService.java
+++ b/wearable/wear/WatchFace/Wearable/src/main/java/com/example/android/wearable/watchface/watchface/AnalogComplicationWatchFaceService.java
@@ -51,14 +51,14 @@
// Unique IDs for each complication. The settings activity that supports allowing users
// to select their complication data provider requires numbers to be >= 0.
- public static final int LEFT_COMPLICATION_ID = 0;
- public static final int RIGHT_COMPLICATION_ID = 1;
+ private static final int LEFT_COMPLICATION_ID = 0;
+ private static final int RIGHT_COMPLICATION_ID = 1;
// Left and right complication IDs as array for Complication API.
- public static final int[] COMPLICATION_IDS = {LEFT_COMPLICATION_ID, RIGHT_COMPLICATION_ID};
+ private static final int[] COMPLICATION_IDS = {LEFT_COMPLICATION_ID, RIGHT_COMPLICATION_ID};
// Left and right dial supported types.
- public static final int[][] COMPLICATION_SUPPORTED_TYPES = {
+ private static final int[][] COMPLICATION_SUPPORTED_TYPES = {
{
ComplicationData.TYPE_RANGED_VALUE,
ComplicationData.TYPE_ICON,
@@ -417,9 +417,9 @@
mActiveComplicationDataSparseArray.put(complicationId, complicationData);
// Updates correct ComplicationDrawable with updated data.
- mComplicationDrawableSparseArray
- .get(complicationId)
- .setComplicationData(complicationData);
+ ComplicationDrawable complicationDrawable =
+ mComplicationDrawableSparseArray.get(complicationId);
+ complicationDrawable.setComplicationData(complicationData);
invalidate();
}
@@ -443,6 +443,8 @@
private int getTappedComplicationId(int x, int y) {
int complicationId;
ComplicationData complicationData;
+ ComplicationDrawable complicationDrawable;
+
long currentTimeMillis = System.currentTimeMillis();
for (int i = 0; i < COMPLICATION_IDS.length; i++) {
@@ -454,8 +456,8 @@
&& (complicationData.getType() != ComplicationData.TYPE_NOT_CONFIGURED)
&& (complicationData.getType() != ComplicationData.TYPE_EMPTY)) {
- Rect complicationBoundingRect =
- mComplicationDrawableSparseArray.get(complicationId).getBounds();
+ complicationDrawable = mComplicationDrawableSparseArray.get(complicationId);
+ Rect complicationBoundingRect = complicationDrawable.getBounds();
if (complicationBoundingRect.width() > 0) {
if (complicationBoundingRect.contains(x, y)) {
@@ -643,7 +645,10 @@
verticalOffset,
(horizontalOffset + sizeOfComplication),
(verticalOffset + sizeOfComplication));
- mComplicationDrawableSparseArray.get(LEFT_COMPLICATION_ID).setBounds(leftBounds);
+
+ ComplicationDrawable leftComplicationDrawable =
+ mComplicationDrawableSparseArray.get(LEFT_COMPLICATION_ID);
+ leftComplicationDrawable.setBounds(leftBounds);
Rect rightBounds =
// Left, Top, Right, Bottom
@@ -652,7 +657,10 @@
verticalOffset,
(midpointOfScreen + horizontalOffset + sizeOfComplication),
(verticalOffset + sizeOfComplication));
- mComplicationDrawableSparseArray.get(RIGHT_COMPLICATION_ID).setBounds(rightBounds);
+
+ ComplicationDrawable rightComplicationDrawable =
+ mComplicationDrawableSparseArray.get(RIGHT_COMPLICATION_ID);
+ rightComplicationDrawable.setBounds(rightBounds);
/* Scale loaded background image (more efficient) if surface dimensions change. */
/* TODO (jewalker): code to be reused with followup CL for complication Background image
@@ -745,17 +753,13 @@
private void drawComplications(Canvas canvas, long currentTimeMillis) {
int complicationId;
- ComplicationData complicationData;
+ ComplicationDrawable complicationDrawable;
for (int i = 0; i < COMPLICATION_IDS.length; i++) {
complicationId = COMPLICATION_IDS[i];
- complicationData = mActiveComplicationDataSparseArray.get(complicationId);
+ complicationDrawable = mComplicationDrawableSparseArray.get(complicationId);
- if ((complicationData != null) && (complicationData.isActive(currentTimeMillis))) {
- mComplicationDrawableSparseArray
- .get(complicationId)
- .draw(canvas, currentTimeMillis);
- }
+ complicationDrawable.draw(canvas, currentTimeMillis);
}
}
diff --git a/wearable/wear/WatchFace/Wearable/src/main/res/layout/config_list_preview_and_complications_item.xml b/wearable/wear/WatchFace/Wearable/src/main/res/layout/config_list_preview_and_complications_item.xml
index 7b80ff9..c1a925d 100644
--- a/wearable/wear/WatchFace/Wearable/src/main/res/layout/config_list_preview_and_complications_item.xml
+++ b/wearable/wear/WatchFace/Wearable/src/main/res/layout/config_list_preview_and_complications_item.xml
@@ -29,7 +29,6 @@
android:layout_height="@dimen/analog_complication_settings_preview_size"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
- android:scaleType="center"
android:background="@drawable/settings_watch_face_preview_background"/>
<View
diff --git a/wearable/wear/WatchFace/Wearable/src/main/res/values/dimens.xml b/wearable/wear/WatchFace/Wearable/src/main/res/values/dimens.xml
index c219e6c..ab69db5 100644
--- a/wearable/wear/WatchFace/Wearable/src/main/res/values/dimens.xml
+++ b/wearable/wear/WatchFace/Wearable/src/main/res/values/dimens.xml
@@ -37,6 +37,7 @@
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
+ <!-- TODO: 180 H1, 140, H2 -->
<dimen name="analog_complication_settings_preview_size">180dp</dimen>
<dimen name="analog_complication_color_picker_size">70dp</dimen>
</resources>
diff --git a/wearable/wear/WatchFace/template-params.xml b/wearable/wear/WatchFace/template-params.xml
index aae1add..10ade0e 100644
--- a/wearable/wear/WatchFace/template-params.xml
+++ b/wearable/wear/WatchFace/template-params.xml
@@ -23,14 +23,14 @@
<package>com.example.android.wearable.watchface</package>
<minSdk>18</minSdk>
- <minSdkVersionWear>23</minSdkVersionWear>
+ <minSdkVersionWear>24</minSdkVersionWear>
<targetSdkVersion>25</targetSdkVersion>
<targetSdkVersionWear>25</targetSdkVersionWear>
<dependency>com.google.android.support:wearable:2.0.0</dependency>
<dependency_wearable>com.android.support:palette-v7:25.1.1</dependency_wearable>
- <preview_wearable_support_provided_dependency>com.google.android.wearable:wearable:2.0.0</preview_wearable_support_provided_dependency>
+ <preview_wearable_support_provided_dependency>com.google.android.wearable:wearable:2.0.1</preview_wearable_support_provided_dependency>
<preview_wearable_support_dependency>com.google.android.support:wearable:2.0.2-preview</preview_wearable_support_dependency>
<wearable>