summaryrefslogtreecommitdiffstats
path: root/samples/browseable/WatchFace
diff options
context:
space:
mode:
authorDan Pasanen <invisiblek@cyanogenmod.org>2016-12-05 20:36:13 -0600
committerDan Pasanen <invisiblek@cyanogenmod.org>2016-12-05 20:36:13 -0600
commited637d91e3aa6e5cdbdb81f11ba32a6b19b2983d (patch)
treee89077d112782e7660e8705f75f7728128d1f65c /samples/browseable/WatchFace
parentf5d1658b33ceb3bc6630b604d5ad65f669ceb47b (diff)
parentcb39ace70f326cc13c6ea0b2053f73d3e14d5c9c (diff)
downloadandroid_development-cm-14.1_prerebase.tar.gz
android_development-cm-14.1_prerebase.tar.bz2
android_development-cm-14.1_prerebase.zip
Merge tag 'android-7.1.1_r4' into cm-14.1cm-14.1_prerebase
Android 7.1.1 release 4 # gpg: Signature made Thu Dec 1 13:06:51 2016 CST # gpg: using DSA key E8AD3F819AB10E78 # gpg: Can't check signature: No public key
Diffstat (limited to 'samples/browseable/WatchFace')
-rw-r--r--samples/browseable/WatchFace/Wearable/AndroidManifest.xml198
-rw-r--r--samples/browseable/WatchFace/Wearable/src/com.example.android.wearable.watchface/ComplicationSimpleConfigActivity.java24
-rw-r--r--samples/browseable/WatchFace/Wearable/src/com.example.android.wearable.watchface/ComplicationSimpleWatchFaceService.java119
-rw-r--r--samples/browseable/WatchFace/Wearable/src/com.example.android.wearable.watchface/provider/RandomNumberProviderService.java25
-rw-r--r--samples/browseable/WatchFace/Wearable/src/com.example.android.wearable.watchface/provider/UpdateComplicationDataService.java63
5 files changed, 287 insertions, 142 deletions
diff --git a/samples/browseable/WatchFace/Wearable/AndroidManifest.xml b/samples/browseable/WatchFace/Wearable/AndroidManifest.xml
index a92229711..7dd5b69a9 100644
--- a/samples/browseable/WatchFace/Wearable/AndroidManifest.xml
+++ b/samples/browseable/WatchFace/Wearable/AndroidManifest.xml
@@ -14,125 +14,132 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.example.android.wearable.watchface" >
+<manifest package="com.example.android.wearable.watchface"
+ xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk
android:minSdkVersion="21"
- android:targetSdkVersion="23" />
+ android:targetSdkVersion="23"/>
- <uses-feature android:name="android.hardware.type.watch" />
+ <uses-feature android:name="android.hardware.type.watch"/>
<!-- Required to act as a custom watch face. -->
- <uses-permission android:name="android.permission.WAKE_LOCK" />
+ <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" />
+ <uses-permission android:name="android.permission.READ_CALENDAR"/>
<!-- Location permission used by FitDistanceWatchFaceService -->
- <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
+
+ <android:uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
+ <android:uses-permission android:name="android.permission.READ_PHONE_STATE"/>
+ <android:uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
- android:label="@string/app_name" >
-
+ android:label="@string/app_name">
<meta-data
android:name="com.google.android.gms.version"
- android:value="@integer/google_play_services_version" />
+ android:value="@integer/google_play_services_version"/>
- <uses-library android:name="com.google.android.wearable" android:required="false" />
+ <uses-library
+ android:name="com.google.android.wearable"
+ android:required="false"/>
<service
android:name=".AnalogWatchFaceService"
android:label="@string/analog_name"
- android:permission="android.permission.BIND_WALLPAPER" >
+ android:permission="android.permission.BIND_WALLPAPER">
<meta-data
android:name="android.service.wallpaper"
- android:resource="@xml/watch_face" />
+ android:resource="@xml/watch_face"/>
<meta-data
android:name="com.google.android.wearable.watchface.preview"
- android:resource="@drawable/preview_analog" />
+ android:resource="@drawable/preview_analog"/>
<meta-data
android:name="com.google.android.wearable.watchface.preview_circular"
- android:resource="@drawable/preview_analog_circular" />
+ android:resource="@drawable/preview_analog_circular"/>
<meta-data
android:name="com.google.android.wearable.watchface.companionConfigurationAction"
- android:value="com.example.android.wearable.watchface.CONFIG_ANALOG" />
+ android:value="com.example.android.wearable.watchface.CONFIG_ANALOG"/>
<intent-filter>
- <action android:name="android.service.wallpaper.WallpaperService" />
+ <action android:name="android.service.wallpaper.WallpaperService"/>
- <category android:name="com.google.android.wearable.watchface.category.WATCH_FACE" />
+ <category android:name="com.google.android.wearable.watchface.category.WATCH_FACE"/>
</intent-filter>
</service>
<service
android:name=".SweepWatchFaceService"
android:label="@string/sweep_name"
- android:permission="android.permission.BIND_WALLPAPER" >
+ android:permission="android.permission.BIND_WALLPAPER">
<meta-data
android:name="android.service.wallpaper"
- android:resource="@xml/watch_face" />
+ android:resource="@xml/watch_face"/>
<meta-data
android:name="com.google.android.wearable.watchface.preview"
- android:resource="@drawable/preview_analog" />
+ android:resource="@drawable/preview_analog"/>
<meta-data
android:name="com.google.android.wearable.watchface.preview_circular"
- android:resource="@drawable/preview_analog_circular" />
+ android:resource="@drawable/preview_analog_circular"/>
<intent-filter>
- <action android:name="android.service.wallpaper.WallpaperService" />
+ <action android:name="android.service.wallpaper.WallpaperService"/>
- <category android:name="com.google.android.wearable.watchface.category.WATCH_FACE" />
+ <category android:name="com.google.android.wearable.watchface.category.WATCH_FACE"/>
</intent-filter>
</service>
<service
android:name=".OpenGLWatchFaceService"
android:label="@string/opengl_name"
- android:permission="android.permission.BIND_WALLPAPER" >
+ android:permission="android.permission.BIND_WALLPAPER">
<meta-data
android:name="android.service.wallpaper"
- android:resource="@xml/watch_face" />
+ android:resource="@xml/watch_face"/>
<meta-data
android:name="com.google.android.wearable.watchface.preview"
- android:resource="@drawable/preview_opengl" />
+ android:resource="@drawable/preview_opengl"/>
<meta-data
android:name="com.google.android.wearable.watchface.preview_circular"
- android:resource="@drawable/preview_opengl_circular" />
+ android:resource="@drawable/preview_opengl_circular"/>
<meta-data
android:name="com.google.android.wearable.watchface.companionConfigurationAction"
- android:value="com.example.android.wearable.watchface.CONFIG_OPENGL" />
+ android:value="com.example.android.wearable.watchface.CONFIG_OPENGL"/>
<intent-filter>
- <action android:name="android.service.wallpaper.WallpaperService" />
+ <action android:name="android.service.wallpaper.WallpaperService"/>
- <category android:name="com.google.android.wearable.watchface.category.WATCH_FACE" />
+ <category android:name="com.google.android.wearable.watchface.category.WATCH_FACE"/>
</intent-filter>
</service>
<service
android:name=".CardBoundsWatchFaceService"
android:label="@string/card_bounds_name"
- android:permission="android.permission.BIND_WALLPAPER" >
+ android:permission="android.permission.BIND_WALLPAPER">
<meta-data
android:name="android.service.wallpaper"
- android:resource="@xml/watch_face" />
+ android:resource="@xml/watch_face"/>
<meta-data
android:name="com.google.android.wearable.watchface.preview"
- android:resource="@drawable/preview_card_bounds" />
+ android:resource="@drawable/preview_card_bounds"/>
<meta-data
android:name="com.google.android.wearable.watchface.preview_circular"
- android:resource="@drawable/preview_card_bounds_circular" />
+ android:resource="@drawable/preview_card_bounds_circular"/>
<meta-data
android:name="com.google.android.wearable.watchface.companionConfigurationAction"
- android:value="com.example.android.wearable.watchface.CONFIG_CARD_BOUNDS" />
+ android:value="com.example.android.wearable.watchface.CONFIG_CARD_BOUNDS"/>
<intent-filter>
- <action android:name="android.service.wallpaper.WallpaperService" />
+ <action android:name="android.service.wallpaper.WallpaperService"/>
- <category android:name="com.google.android.wearable.watchface.category.WATCH_FACE" />
+ <category android:name="com.google.android.wearable.watchface.category.WATCH_FACE"/>
</intent-filter>
</service>
-
<service
android:name=".ComplicationSimpleWatchFaceService"
android:enabled="true"
@@ -157,6 +164,8 @@
<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">
@@ -171,47 +180,47 @@
<service
android:name=".InteractiveWatchFaceService"
android:label="@string/interactive_name"
- android:permission="android.permission.BIND_WALLPAPER" >
+ android:permission="android.permission.BIND_WALLPAPER">
<meta-data
android:name="android.service.wallpaper"
- android:resource="@xml/watch_face" />
+ android:resource="@xml/watch_face"/>
<meta-data
android:name="com.google.android.wearable.watchface.preview"
- android:resource="@drawable/preview_interactive" />
+ android:resource="@drawable/preview_interactive"/>
<meta-data
android:name="com.google.android.wearable.watchface.preview_circular"
- android:resource="@drawable/preview_interactive_circular" />
+ android:resource="@drawable/preview_interactive_circular"/>
<intent-filter>
- <action android:name="android.service.wallpaper.WallpaperService" />
+ <action android:name="android.service.wallpaper.WallpaperService"/>
- <category android:name="com.google.android.wearable.watchface.category.WATCH_FACE" />
+ <category android:name="com.google.android.wearable.watchface.category.WATCH_FACE"/>
</intent-filter>
</service>
<service
android:name=".DigitalWatchFaceService"
android:label="@string/digital_name"
- android:permission="android.permission.BIND_WALLPAPER" >
+ android:permission="android.permission.BIND_WALLPAPER">
<meta-data
android:name="android.service.wallpaper"
- android:resource="@xml/watch_face" />
+ android:resource="@xml/watch_face"/>
<meta-data
android:name="com.google.android.wearable.watchface.preview"
- android:resource="@drawable/preview_digital" />
+ android:resource="@drawable/preview_digital"/>
<meta-data
android:name="com.google.android.wearable.watchface.preview_circular"
- android:resource="@drawable/preview_digital_circular" />
+ android:resource="@drawable/preview_digital_circular"/>
<meta-data
android:name="com.google.android.wearable.watchface.companionConfigurationAction"
- android:value="com.example.android.wearable.watchface.CONFIG_DIGITAL" />
+ android:value="com.example.android.wearable.watchface.CONFIG_DIGITAL"/>
<meta-data
android:name="com.google.android.wearable.watchface.wearableConfigurationAction"
- android:value="com.example.android.wearable.watchface.CONFIG_DIGITAL" />
+ android:value="com.example.android.wearable.watchface.CONFIG_DIGITAL"/>
<intent-filter>
- <action android:name="android.service.wallpaper.WallpaperService" />
+ <action android:name="android.service.wallpaper.WallpaperService"/>
- <category android:name="com.google.android.wearable.watchface.category.WATCH_FACE" />
+ <category android:name="com.google.android.wearable.watchface.category.WATCH_FACE"/>
</intent-filter>
</service>
@@ -223,95 +232,99 @@
<activity
android:name=".DigitalWatchFaceWearableConfigActivity"
- android:label="@string/digital_config_name" >
+ android:label="@string/digital_config_name">
<intent-filter>
- <action android:name="com.example.android.wearable.watchface.CONFIG_DIGITAL" />
+ <action android:name="com.example.android.wearable.watchface.CONFIG_DIGITAL"/>
- <category android:name="com.google.android.wearable.watchface.category.WEARABLE_CONFIGURATION" />
- <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="com.google.android.wearable.watchface.category.WEARABLE_CONFIGURATION"/>
+ <category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<service
android:name=".CalendarWatchFaceService"
android:label="@string/calendar_name"
- android:permission="android.permission.BIND_WALLPAPER" >
+ android:permission="android.permission.BIND_WALLPAPER">
<meta-data
android:name="android.service.wallpaper"
- android:resource="@xml/watch_face" />
+ android:resource="@xml/watch_face"/>
<meta-data
android:name="com.google.android.wearable.watchface.preview"
- android:resource="@drawable/preview_calendar" />
+ android:resource="@drawable/preview_calendar"/>
<meta-data
android:name="com.google.android.wearable.watchface.preview_circular"
- android:resource="@drawable/preview_calendar_circular" />
+ android:resource="@drawable/preview_calendar_circular"/>
<intent-filter>
- <action android:name="android.service.wallpaper.WallpaperService" />
+ <action android:name="android.service.wallpaper.WallpaperService"/>
- <category android:name="com.google.android.wearable.watchface.category.WATCH_FACE" />
+ <category android:name="com.google.android.wearable.watchface.category.WATCH_FACE"/>
</intent-filter>
</service>
- <service android:name=".DigitalWatchFaceConfigListenerService" >
+ <service android:name=".DigitalWatchFaceConfigListenerService">
<intent-filter>
- <action android:name="com.google.android.gms.wearable.MESSAGE_RECEIVED" />
- <data android:scheme="wear" android:host="*" android:pathPrefix="/"/>
+ <action android:name="com.google.android.gms.wearable.MESSAGE_RECEIVED"/>
+
+ <data
+ android:host="*"
+ android:pathPrefix="/"
+ android:scheme="wear"/>
</intent-filter>
</service>
<service
android:name=".FitDistanceWatchFaceService"
android:label="@string/fit_distance_name"
- android:permission="android.permission.BIND_WALLPAPER" >
+ android:permission="android.permission.BIND_WALLPAPER">
<meta-data
android:name="android.service.wallpaper"
- android:resource="@xml/watch_face" />
+ android:resource="@xml/watch_face"/>
<meta-data
android:name="com.google.android.wearable.watchface.preview"
- android:resource="@drawable/preview_distance" />
+ android:resource="@drawable/preview_distance"/>
<meta-data
android:name="com.google.android.wearable.watchface.preview_circular"
- android:resource="@drawable/preview_distance_circular" />
+ android:resource="@drawable/preview_distance_circular"/>
<meta-data
android:name="com.google.android.wearable.watchface.companionConfigurationAction"
- android:value="com.example.android.wearable.watchface.CONFIG_FIT_DISTANCE" />
+ android:value="com.example.android.wearable.watchface.CONFIG_FIT_DISTANCE"/>
<intent-filter>
- <action android:name="android.service.wallpaper.WallpaperService" />
+ <action android:name="android.service.wallpaper.WallpaperService"/>
- <category android:name="com.google.android.wearable.watchface.category.WATCH_FACE" />
+ <category android:name="com.google.android.wearable.watchface.category.WATCH_FACE"/>
</intent-filter>
</service>
<service
android:name=".FitStepsWatchFaceService"
android:label="@string/fit_steps_name"
- android:permission="android.permission.BIND_WALLPAPER" >
+ android:permission="android.permission.BIND_WALLPAPER">
<meta-data
android:name="android.service.wallpaper"
- android:resource="@xml/watch_face" />
+ android:resource="@xml/watch_face"/>
<meta-data
android:name="com.google.android.wearable.watchface.preview"
- android:resource="@drawable/preview_fit" />
+ android:resource="@drawable/preview_fit"/>
<meta-data
android:name="com.google.android.wearable.watchface.preview_circular"
- android:resource="@drawable/preview_fit_circular" />
+ android:resource="@drawable/preview_fit_circular"/>
<intent-filter>
- <action android:name="android.service.wallpaper.WallpaperService" />
+ <action android:name="android.service.wallpaper.WallpaperService"/>
- <category android:name="com.google.android.wearable.watchface.category.WATCH_FACE" />
+ <category android:name="com.google.android.wearable.watchface.category.WATCH_FACE"/>
</intent-filter>
</service>
<activity
android:name=".CalendarWatchFacePermissionActivity"
- android:label="@string/title_activity_calendar_watch_face_permission" >
+ android:label="@string/title_activity_calendar_watch_face_permission">
</activity>
<service
android:name=".provider.RandomNumberProviderService"
+ android:icon="@drawable/ic_launcher"
android:label="@string/complications_provider_random_number"
- 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"/>
</intent-filter>
@@ -322,19 +335,24 @@
<!--
When your complication data provider is active, UPDATE_PERIOD_SECONDS specifies how
often you want the system to check for updates to the data. In this case, the time is
- specified to a relatively short 120 seconds, so we can observe the result of this code
- lab. In everyday use, developers should consider intervals in the order of minutes.
+ specified to 600 seconds (10 minutes).
+
+ In general, you want to set this value high and manually trigger updates only when your
+ complication data actually changes via ProviderUpdateRequester (check
+ UpdateComplicationDataService.java for an example).
+
+ In everyday use, developers should consider intervals in the order of minutes.
Also, remember that this is only a guidance for the system. Android Wear may update less
frequently.
-
- If your app needs to push updates instead of updating on a regular schedule, you should
- set this value to 0 and use ProviderUpdateRequester.requestUpdate() to trigger an update
- request when you need one.
-->
<meta-data
android:name="android.support.wearable.complications.UPDATE_PERIOD_SECONDS"
- android:value="120"/>
+ android:value="600"/>
+ </service>
+ <service
+ android:name=".provider.UpdateComplicationDataService"
+ android:exported="false">
</service>
</application>
-</manifest>
+</manifest> \ No newline at end of file
diff --git a/samples/browseable/WatchFace/Wearable/src/com.example.android.wearable.watchface/ComplicationSimpleConfigActivity.java b/samples/browseable/WatchFace/Wearable/src/com.example.android.wearable.watchface/ComplicationSimpleConfigActivity.java
index 66e208c2e..6d4e521a1 100644
--- a/samples/browseable/WatchFace/Wearable/src/com.example.android.wearable.watchface/ComplicationSimpleConfigActivity.java
+++ b/samples/browseable/WatchFace/Wearable/src/com.example.android.wearable.watchface/ComplicationSimpleConfigActivity.java
@@ -22,6 +22,8 @@ import android.content.Intent;
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 @@ public class ComplicationSimpleConfigActivity extends Activity implements
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 @@ public class ComplicationSimpleConfigActivity extends Activity implements
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 @@ public class ComplicationSimpleConfigActivity extends Activity implements
return mItems.get(position);
}
}
-
} \ No newline at end of file
diff --git a/samples/browseable/WatchFace/Wearable/src/com.example.android.wearable.watchface/ComplicationSimpleWatchFaceService.java b/samples/browseable/WatchFace/Wearable/src/com.example.android.wearable.watchface/ComplicationSimpleWatchFaceService.java
index 9eca2c33b..4905293dd 100644
--- a/samples/browseable/WatchFace/Wearable/src/com.example.android.wearable.watchface/ComplicationSimpleWatchFaceService.java
+++ b/samples/browseable/WatchFace/Wearable/src/com.example.android.wearable.watchface/ComplicationSimpleWatchFaceService.java
@@ -18,6 +18,7 @@ package com.example.android.wearable.watchface;
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.Handler;
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 @@ public class ComplicationSimpleWatchFaceService extends CanvasWatchFaceService {
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 @@ public class ComplicationSimpleWatchFaceService extends CanvasWatchFaceService {
complicationData = mActiveComplicationDataSparseArray.get(COMPLICATION_IDS[i]);
if ((complicationData != null)
- && (complicationData.isActive(currentTimeMillis))
- && (complicationData.getType() == ComplicationData.TYPE_SHORT_TEXT)) {
-
- ComplicationText mainText = complicationData.getShortText();
- ComplicationText subText = complicationData.getShortTitle();
-
- CharSequence complicationMessage =
- mainText.getText(getApplicationContext(), currentTimeMillis);
-
- /* 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));
- }
-
- //Log.d(TAG, "Comp id: " + COMPLICATION_IDS[i] + "\t" + complicationMessage);
- double textWidth =
- mComplicationPaint.measureText(
+ && (complicationData.isActive(currentTimeMillis))) {
+
+ // 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) {
+
+ ComplicationText mainText = complicationData.getShortText();
+ ComplicationText subText = complicationData.getShortTitle();
+
+ CharSequence complicationMessage =
+ mainText.getText(getApplicationContext(), currentTimeMillis);
+
+ /* 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());
+
+ 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;
+ }
- 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/samples/browseable/WatchFace/Wearable/src/com.example.android.wearable.watchface/provider/RandomNumberProviderService.java b/samples/browseable/WatchFace/Wearable/src/com.example.android.wearable.watchface/provider/RandomNumberProviderService.java
index 916f90fd9..17d03c272 100644
--- a/samples/browseable/WatchFace/Wearable/src/com.example.android.wearable.watchface/provider/RandomNumberProviderService.java
+++ b/samples/browseable/WatchFace/Wearable/src/com.example.android.wearable.watchface/provider/RandomNumberProviderService.java
@@ -1,5 +1,7 @@
package com.example.android.wearable.watchface.provider;
+import android.app.PendingIntent;
+import android.content.Intent;
import android.support.wearable.complications.ComplicationData;
import android.support.wearable.complications.ComplicationManager;
import android.support.wearable.complications.ComplicationProviderService;
@@ -42,7 +44,7 @@ public class RandomNumberProviderService extends ComplicationProviderService {
@Override
public void onComplicationUpdate(
int complicationId, int dataType, ComplicationManager complicationManager) {
- Log.d(TAG, "onComplicationUpdate()");
+ Log.d(TAG, "onComplicationUpdate() id: " + complicationId);
// Retrieve your data, in this case, we simply create a random number to display.
@@ -51,6 +53,24 @@ public class RandomNumberProviderService extends ComplicationProviderService {
String randomNumberText =
String.format(Locale.getDefault(), "%d!", randomNumber);
+ // Create Tap Action so that the user can trigger an update by tapping the complication.
+ Intent updateIntent =
+ new Intent(getApplicationContext(), UpdateComplicationDataService.class);
+ updateIntent.setAction(UpdateComplicationDataService.ACTION_UPDATE_COMPLICATION);
+ // We pass the complication id, so we can only update the specific complication tapped.
+ updateIntent.putExtra(UpdateComplicationDataService.EXTRA_COMPLICATION_ID, complicationId);
+
+ PendingIntent pendingIntent = PendingIntent.getService(
+ getApplicationContext(),
+ // Set the requestCode to the complication id. This ensures the system doesn't
+ // combine other PendingIntents with the same context with this one (basically it
+ // would then reuse the Extra you set in the initial PendingIntent). If you don't
+ // do this and multiple complications with your data are active, every PendingIntent
+ // assigned for tap, would use the same complication id (first one created).
+ complicationId,
+ updateIntent,
+ 0);
+
ComplicationData complicationData = null;
switch (dataType) {
@@ -60,17 +80,20 @@ public class RandomNumberProviderService extends ComplicationProviderService {
.setMinValue(0)
.setMaxValue(10)
.setShortText(ComplicationText.plainText(randomNumberText))
+ .setTapAction(pendingIntent)
.build();
break;
case ComplicationData.TYPE_SHORT_TEXT:
complicationData = new ComplicationData.Builder(ComplicationData.TYPE_SHORT_TEXT)
.setShortText(ComplicationText.plainText(randomNumberText))
+ .setTapAction(pendingIntent)
.build();
break;
case ComplicationData.TYPE_LONG_TEXT:
complicationData = new ComplicationData.Builder(ComplicationData.TYPE_LONG_TEXT)
.setLongText(
ComplicationText.plainText("Random Number: " + randomNumberText))
+ .setTapAction(pendingIntent)
.build();
break;
default:
diff --git a/samples/browseable/WatchFace/Wearable/src/com.example.android.wearable.watchface/provider/UpdateComplicationDataService.java b/samples/browseable/WatchFace/Wearable/src/com.example.android.wearable.watchface/provider/UpdateComplicationDataService.java
new file mode 100644
index 000000000..203e491c2
--- /dev/null
+++ b/samples/browseable/WatchFace/Wearable/src/com.example.android.wearable.watchface/provider/UpdateComplicationDataService.java
@@ -0,0 +1,63 @@
+package com.example.android.wearable.watchface.provider;
+
+import android.app.IntentService;
+import android.content.ComponentName;
+import android.content.Intent;
+import android.support.wearable.complications.ProviderUpdateRequester;
+import android.util.Log;
+
+/**
+ * Simple {@link IntentService} subclass for asynchronously requesting an update for the random
+ * number complication (triggered via TapAction on complication).
+ */
+public class UpdateComplicationDataService extends IntentService {
+
+ private static final String TAG = "UpdateCompService";
+
+ public static final String ACTION_UPDATE_COMPLICATION =
+ "com.example.android.wearable.watchface.provider.action.UPDATE_COMPLICATION";
+
+ public static final String EXTRA_COMPLICATION_ID =
+ "com.example.android.wearable.watchface.provider.action.COMPLICATION_ID";
+
+ public UpdateComplicationDataService() {
+ super("UpdateComplicationDataService");
+ }
+
+ @Override
+ protected void onHandleIntent(Intent intent) {
+
+ if (intent != null) {
+
+ final String action = intent.getAction();
+
+ if (ACTION_UPDATE_COMPLICATION.equals(action)) {
+
+ int complicationId = intent.getIntExtra(EXTRA_COMPLICATION_ID, -1);
+ handleActionUpdateComplicationData(complicationId);
+ }
+ }
+ }
+
+ /**
+ * Handle action UpdateComplicationData in the provided background thread with the provided
+ * parameters.
+ */
+ private void handleActionUpdateComplicationData(int complicationId) {
+
+ Log.d(TAG, "Complication id to update via service: " + complicationId);
+
+ ComponentName componentName =
+ new ComponentName(getApplicationContext(), RandomNumberProviderService.class);
+
+ ProviderUpdateRequester providerUpdateRequester =
+ new ProviderUpdateRequester(getApplicationContext(), componentName);
+
+ if (complicationId > 0) {
+ // This method only updates the specific complication tapped on the watch, if you
+ // wanted to update all active complications associated with your data, you would
+ // call providerUpdateRequester.requestUpdateAll().
+ providerUpdateRequester.requestUpdate(complicationId);
+ }
+ }
+} \ No newline at end of file