Adds support for new permissions in Wear 2.0 Complications. am: 1304413d06 am: 2d2b4af02f am: feea80e551 am: e59f7138db
am: a154206c13
Change-Id: I49ef0032a15c785f9f2d38637e17ff0a850e487c
diff --git a/wearable/wear/WatchFace/Wearable/src/main/AndroidManifest.xml b/wearable/wear/WatchFace/Wearable/src/main/AndroidManifest.xml
index a922297..693a435 100644
--- a/wearable/wear/WatchFace/Wearable/src/main/AndroidManifest.xml
+++ b/wearable/wear/WatchFace/Wearable/src/main/AndroidManifest.xml
@@ -26,6 +26,10 @@
<!-- Required to act as a custom watch face. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
+ <!-- Required for complications to receive complication data and open the provider chooser. -->
+ <uses-permission
+ android:name="com.google.android.wearable.permission.RECEIVE_COMPLICATION_DATA" />
+
<!-- Calendar permission used by CalendarWatchFaceService -->
<uses-permission android:name="android.permission.READ_CALENDAR" />
@@ -157,6 +161,9 @@
<category android:name="com.google.android.wearable.watchface.category.WATCH_FACE"/>
</intent-filter>
</service>
+
+ <activity android:name="android.support.wearable.complications.ComplicationHelperActivity"/>
+
<activity
android:name=".ComplicationSimpleConfigActivity"
android:label="@string/complication_simple">
@@ -310,7 +317,8 @@
<service
android:name=".provider.RandomNumberProviderService"
android:label="@string/complications_provider_random_number"
- android:icon="@drawable/ic_launcher">
+ android:icon="@drawable/ic_launcher"
+ android:permission="com.google.android.wearable.permission.BIND_COMPLICATION_PROVIDER">
<intent-filter>
<action android:name="android.support.wearable.complications.ACTION_COMPLICATION_UPDATE_REQUEST"/>
diff --git a/wearable/wear/WatchFace/Wearable/src/main/java/com/example/android/wearable/watchface/ComplicationSimpleConfigActivity.java b/wearable/wear/WatchFace/Wearable/src/main/java/com/example/android/wearable/watchface/ComplicationSimpleConfigActivity.java
index 66e208c..6d4e521 100644
--- a/wearable/wear/WatchFace/Wearable/src/main/java/com/example/android/wearable/watchface/ComplicationSimpleConfigActivity.java
+++ b/wearable/wear/WatchFace/Wearable/src/main/java/com/example/android/wearable/watchface/ComplicationSimpleConfigActivity.java
@@ -22,6 +22,8 @@
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
+import android.support.wearable.complications.ComplicationHelperActivity;
+import android.support.wearable.complications.ComplicationProviderInfo;
import android.support.wearable.complications.ProviderChooserIntent;
import android.support.wearable.view.WearableListView;
import android.util.Log;
@@ -64,6 +66,13 @@
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PROVIDER_CHOOSER_REQUEST_CODE
&& resultCode == RESULT_OK) {
+
+ // Retrieves information for selected Complication provider.
+ ComplicationProviderInfo complicationProviderInfo =
+ data.getParcelableExtra(ProviderChooserIntent.EXTRA_PROVIDER_INFO);
+
+ Log.d(TAG, "Selected Provider: " + complicationProviderInfo);
+
finish();
}
}
@@ -77,10 +86,16 @@
Integer tag = (Integer) viewHolder.itemView.getTag();
ComplicationItem complicationItem = mAdapter.getItem(tag);
- startActivityForResult(ProviderChooserIntent.createProviderChooserIntent(
- complicationItem.watchFace,
- complicationItem.complicationId,
- complicationItem.supportedTypes), PROVIDER_CHOOSER_REQUEST_CODE);
+ // Note: If you were previously using ProviderChooserIntent.createProviderChooserIntent()
+ // (now deprecated), you will want to switch to
+ // ComplicationHelperActivity.createProviderChooserHelperIntent()
+ startActivityForResult(
+ ComplicationHelperActivity.createProviderChooserHelperIntent(
+ getApplicationContext(),
+ complicationItem.watchFace,
+ complicationItem.complicationId,
+ complicationItem.supportedTypes),
+ PROVIDER_CHOOSER_REQUEST_CODE);
}
private List<ComplicationItem> getComplicationItems() {
@@ -187,5 +202,4 @@
return mItems.get(position);
}
}
-
}
\ No newline at end of file
diff --git a/wearable/wear/WatchFace/Wearable/src/main/java/com/example/android/wearable/watchface/ComplicationSimpleWatchFaceService.java b/wearable/wear/WatchFace/Wearable/src/main/java/com/example/android/wearable/watchface/ComplicationSimpleWatchFaceService.java
index 9eca2c3..4905293 100644
--- a/wearable/wear/WatchFace/Wearable/src/main/java/com/example/android/wearable/watchface/ComplicationSimpleWatchFaceService.java
+++ b/wearable/wear/WatchFace/Wearable/src/main/java/com/example/android/wearable/watchface/ComplicationSimpleWatchFaceService.java
@@ -18,6 +18,7 @@
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
+import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
@@ -35,6 +36,7 @@
import android.os.Message;
import android.support.v7.graphics.Palette;
import android.support.wearable.complications.ComplicationData;
+import android.support.wearable.complications.ComplicationHelperActivity;
import android.support.wearable.complications.ComplicationText;
import android.support.wearable.watchface.CanvasWatchFaceService;
import android.support.wearable.watchface.WatchFaceService;
@@ -362,16 +364,34 @@
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "onComplicationTap()");
}
+
ComplicationData complicationData =
mActiveComplicationDataSparseArray.get(complicationId);
- if ((complicationData != null) && (complicationData.getTapAction() != null)) {
- try {
- complicationData.getTapAction().send();
- } catch (PendingIntent.CanceledException e) {
- Log.e(TAG, "On complication tap action error " + e);
+ if (complicationData != null) {
+
+ if (complicationData.getTapAction() != null) {
+ try {
+ complicationData.getTapAction().send();
+ } catch (PendingIntent.CanceledException e) {
+ Log.e(TAG, "On complication tap action error " + e);
+ }
+
+ } else if (complicationData.getType() == ComplicationData.TYPE_NO_PERMISSION) {
+
+ // Watch face does not have permission to receive complication data, so launch
+ // permission request.
+ ComponentName componentName = new ComponentName(
+ getApplicationContext(),
+ ComplicationSimpleWatchFaceService.class);
+
+ Intent permissionRequestIntent =
+ ComplicationHelperActivity.createPermissionRequestHelperIntent(
+ getApplicationContext(), componentName);
+
+ startActivity(permissionRequestIntent);
}
- invalidate();
+
} else {
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "No PendingIntent for complication " + complicationId + ".");
@@ -551,50 +571,57 @@
complicationData = mActiveComplicationDataSparseArray.get(COMPLICATION_IDS[i]);
if ((complicationData != null)
- && (complicationData.isActive(currentTimeMillis))
- && (complicationData.getType() == ComplicationData.TYPE_SHORT_TEXT)) {
+ && (complicationData.isActive(currentTimeMillis))) {
- ComplicationText mainText = complicationData.getShortText();
- ComplicationText subText = complicationData.getShortTitle();
+ // Both Short Text and No Permission Types can be rendered with the same code.
+ // No Permission will display "--" with an Intent to launch a permission prompt.
+ // If you want to support more types, just add a "else if" below with your
+ // rendering code inside.
+ if (complicationData.getType() == ComplicationData.TYPE_SHORT_TEXT
+ || complicationData.getType() == ComplicationData.TYPE_NO_PERMISSION) {
- CharSequence complicationMessage =
- mainText.getText(getApplicationContext(), currentTimeMillis);
+ ComplicationText mainText = complicationData.getShortText();
+ ComplicationText subText = complicationData.getShortTitle();
- /* In most cases you would want the subText (Title) under the mainText (Text),
- * but to keep it simple for the code lab, we are concatenating them all on one
- * line.
- */
- if (subText != null) {
- complicationMessage = TextUtils.concat(
- complicationMessage,
- " ",
- subText.getText(getApplicationContext(), currentTimeMillis));
- }
+ CharSequence complicationMessage =
+ mainText.getText(getApplicationContext(), currentTimeMillis);
- //Log.d(TAG, "Comp id: " + COMPLICATION_IDS[i] + "\t" + complicationMessage);
- double textWidth =
- mComplicationPaint.measureText(
+ /* In most cases you would want the subText (Title) under the
+ * mainText (Text), but to keep it simple for the code lab, we are
+ * concatenating them all on one line.
+ */
+ if (subText != null) {
+ complicationMessage = TextUtils.concat(
complicationMessage,
- 0,
- complicationMessage.length());
+ " ",
+ subText.getText(getApplicationContext(), currentTimeMillis));
+ }
- int complicationsX;
+ //Log.d(TAG, "Com id: " + COMPLICATION_IDS[i] + "\t" + complicationMessage);
+ double textWidth =
+ mComplicationPaint.measureText(
+ complicationMessage,
+ 0,
+ complicationMessage.length());
- if (COMPLICATION_IDS[i] == LEFT_DIAL_COMPLICATION) {
- complicationsX = (int) ((mWidth / 2) - textWidth) / 2;
- } else {
- // RIGHT_DIAL_COMPLICATION calculations
- int offset = (int) ((mWidth / 2) - textWidth) / 2;
- complicationsX = (mWidth / 2) + offset;
+ int complicationsX;
+
+ if (COMPLICATION_IDS[i] == LEFT_DIAL_COMPLICATION) {
+ complicationsX = (int) ((mWidth / 2) - textWidth) / 2;
+ } else {
+ // RIGHT_DIAL_COMPLICATION calculations
+ int offset = (int) ((mWidth / 2) - textWidth) / 2;
+ complicationsX = (mWidth / 2) + offset;
+ }
+
+ canvas.drawText(
+ complicationMessage,
+ 0,
+ complicationMessage.length(),
+ complicationsX,
+ mComplicationsY,
+ mComplicationPaint);
}
-
- canvas.drawText(
- complicationMessage,
- 0,
- complicationMessage.length(),
- complicationsX,
- mComplicationsY,
- mComplicationPaint);
}
}
}
diff --git a/wearable/wear/WatchFace/gradle/wrapper/gradle-wrapper.properties b/wearable/wear/WatchFace/gradle/wrapper/gradle-wrapper.properties
index 128405e..95524ef 100644
--- a/wearable/wear/WatchFace/gradle/wrapper/gradle-wrapper.properties
+++ b/wearable/wear/WatchFace/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Thu May 12 20:18:40 PDT 2016
+#Wed Aug 24 16:01:26 PDT 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
diff --git a/wearable/wear/WatchFace/template-params.xml b/wearable/wear/WatchFace/template-params.xml
index 5692e01..a0a13a4 100644
--- a/wearable/wear/WatchFace/template-params.xml
+++ b/wearable/wear/WatchFace/template-params.xml
@@ -28,9 +28,9 @@
<dependency>com.google.android.support:wearable:1.4.0</dependency>
<dependency>com.google.android.gms:play-services-fitness</dependency>
- <dependency_wearable>com.android.support:palette-v7:23.3.0</dependency_wearable>
+ <dependency_wearable>com.android.support:palette-v7:24.1.1</dependency_wearable>
- <preview_wearable_support_dependency>com.google.android.support:wearable:2.0.0-alpha1</preview_wearable_support_dependency>
+ <preview_wearable_support_dependency>com.google.android.support:wearable:2.0.0-alpha3</preview_wearable_support_dependency>
<dependency_wearable>com.google.android.gms:play-services-fitness</dependency_wearable>
<wearable>