Permalink
Browse files

Merge pull request #328 from ianhanniballake/complications

Improve complications: long text, small image, system health
  • Loading branch information...
2 parents 168b22a + b2801c8 commit 34e3d8885865a1635f9c0fc9637a8b365131840a @ianhanniballake ianhanniballake committed on GitHub Jan 31, 2017
@@ -0,0 +1,5 @@
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 27 27">
+ <g>
+ <path fill="#FFF" d="M21.711 16.212c.057-.303.175-.739.356-1.307l.568-1.79c.199-.625.374-1.226.526-1.804.15-.578.227-1.01.227-1.293 0-.966-.374-1.714-1.122-2.245-.749-.53-1.786-.795-3.112-.795-.53.34-1.075.947-1.634 1.818-.559.872-1.132 1.989-1.719 3.353l-.199.028c.057-.284.123-.558.2-.824.037-.227.08-.464.127-.71.047-.246.071-.464.071-.654 0-.947-.365-1.685-1.094-2.216-.73-.53-1.747-.795-3.054-.795-.53.34-1.075.947-1.634 1.818-.559.872-1.132 1.989-1.719 3.353l-.199.028c.076-.511.17-1.023.284-1.534.114-.512.218-.966.313-1.364l.34-1.364-.397-.596c-.72.056-1.459.113-2.216.17-.644.038-1.336.076-2.074.114-.74.038-1.421.056-2.046.056l-.341 2.33h.795c.379 0 .64.09.782.27.142.18.184.498.128.952a33.29 33.29 0 0 0-.142.867c-.057.37-.124.786-.2 1.25-.075.464-.156.962-.24 1.492-.086.53-.167 1.051-.242 1.562-.21 1.213-.427 2.52-.654 3.922l.568.653c.53 0 1.047-.038 1.549-.114a6.59 6.59 0 0 0 1.321-.326c.379-.142.687-.299.924-.47.236-.17.373-.359.412-.567l.198-1.677c.303-.89.616-1.71.938-2.458.322-.748.625-1.392.91-1.932.284-.54.544-.96.78-1.264.237-.303.431-.455.583-.455.36 0 .54.218.54.654 0 .133-.028.35-.085.653-.057.303-.128.654-.213 1.052-.085.397-.18.828-.284 1.292-.105.465-.213.924-.327 1.378-.266 1.08-.568 2.274-.91 3.58l.569.654c.53 0 1.046-.038 1.548-.114a6.91 6.91 0 0 0 1.336-.326c.388-.142.7-.299.938-.47.236-.17.364-.359.383-.567l.142-1.364c.36-.928.72-1.785 1.08-2.572.36-.786.7-1.463 1.023-2.031.322-.569.62-1.013.895-1.336.274-.322.497-.483.668-.483.34 0 .511.266.511.796 0 .265-.09.715-.27 1.35-.18.634-.38 1.311-.597 2.031-.218.72-.416 1.402-.596 2.046-.18.644-.27 1.118-.27 1.42 0 .588.146 1.014.44 1.28.294.264.772.397 1.435.397.398 0 .79-.071 1.18-.213.387-.142.81-.384 1.264-.725.454-.34.966-.79 1.534-1.35a44.251 44.251 0 0 0 1.989-2.116l-.54-1.364-.682-.114c-.568.493-.937.81-1.108.952-.17.142-.294.213-.37.213l-.085-.085z"/>
+ </g>
+</svg>
@@ -65,6 +65,7 @@
<service
android:name="com.google.android.apps.muzei.complications.ArtworkComplicationProviderService"
+ android:icon="@drawable/ic_complication"
android:label="@string/complication_artwork_label"
android:enabled="false"
tools:ignore="ExportedService">
@@ -74,7 +75,7 @@
<meta-data
android:name="android.support.wearable.complications.SUPPORTED_TYPES"
- android:value="LARGE_IMAGE" />
+ android:value="LONG_TEXT,SMALL_IMAGE,LARGE_IMAGE" />
<meta-data
android:name="android.support.wearable.complications.UPDATE_PERIOD_SECONDS"
android:value="0" />
@@ -84,7 +85,8 @@
android:exported="true"
android:permission="android.permission.BIND_JOB_SERVICE" />
<receiver
- android:name="com.google.android.apps.muzei.complications.ArtworkComplicationBootReceiver">
+ android:name="com.google.android.apps.muzei.complications.ArtworkComplicationBootReceiver"
+ android:enabled="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
@@ -24,6 +24,7 @@
import android.content.ComponentName;
import android.content.Context;
import android.content.SharedPreferences;
+import android.content.pm.PackageManager;
import android.os.Build;
import android.preference.PreferenceManager;
import android.support.wearable.complications.ProviderUpdateRequester;
@@ -48,11 +49,21 @@ static void scheduleComplicationUpdateJob(Context context) {
MuzeiContract.Artwork.CONTENT_URI,
JobInfo.TriggerContentUri.FLAG_NOTIFY_FOR_DESCENDANTS))
.build());
+ // Enable the BOOT_COMPLETED receiver to reschedule the job on reboot
+ ComponentName bootReceivedComponentName = new ComponentName(context,
+ ArtworkComplicationBootReceiver.class);
+ context.getPackageManager().setComponentEnabledSetting(bootReceivedComponentName,
+ PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
}
static void cancelComplicationUpdateJob(Context context) {
JobScheduler jobScheduler = context.getSystemService(JobScheduler.class);
jobScheduler.cancel(ARTWORK_COMPLICATION_JOB_ID);
+ // Disable the BOOT_COMPLETED receiver to reduce memory pressure on boot
+ ComponentName bootReceivedComponentName = new ComponentName(context,
+ ArtworkComplicationBootReceiver.class);
+ context.getPackageManager().setComponentEnabledSetting(bootReceivedComponentName,
+ PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
}
@Override
@@ -17,14 +17,21 @@
package com.google.android.apps.muzei.complications;
import android.annotation.TargetApi;
+import android.app.PendingIntent;
+import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.Icon;
import android.os.Build;
+import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.wearable.complications.ComplicationData;
import android.support.wearable.complications.ComplicationManager;
import android.support.wearable.complications.ComplicationProviderService;
+import android.support.wearable.complications.ComplicationText;
+import android.text.TextUtils;
+import com.google.android.apps.muzei.FullScreenActivity;
+import com.google.android.apps.muzei.api.Artwork;
import com.google.android.apps.muzei.api.MuzeiContract;
import com.google.firebase.analytics.FirebaseAnalytics;
@@ -49,7 +56,9 @@ public void onCreate() {
@Override
public void onComplicationActivated(int complicationId, int type, ComplicationManager manager) {
addComplication(complicationId);
- FirebaseAnalytics.getInstance(this).logEvent("complication_artwork_activated", null);
+ Bundle bundle = new Bundle();
+ bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, Integer.toString(type));
+ FirebaseAnalytics.getInstance(this).logEvent("complication_artwork_activated", bundle);
}
private void addComplication(int complicationId) {
@@ -84,8 +93,44 @@ public void onComplicationUpdate(int complicationId, int type, ComplicationManag
if (!complications.contains(Integer.toString(complicationId))) {
addComplication(complicationId);
}
- ComplicationData.Builder builder = new ComplicationData.Builder(type)
- .setLargeImage(Icon.createWithContentUri(MuzeiContract.Artwork.CONTENT_URI));
+ Artwork artwork = MuzeiContract.Artwork.getCurrentArtwork(this);
+ if (artwork == null) {
+ complicationManager.updateComplicationData(complicationId,
+ new ComplicationData.Builder(ComplicationData.TYPE_NO_DATA).build());
+ return;
+ }
+ ComplicationData.Builder builder = new ComplicationData.Builder(type);
+ Intent intent = new Intent(this, FullScreenActivity.class);
+ PendingIntent tapAction = PendingIntent.getActivity(this, 0, intent, 0);
+ switch (type) {
+ case ComplicationData.TYPE_LONG_TEXT:
+ String title = artwork.getTitle();
+ String byline = artwork.getByline();
+ if (TextUtils.isEmpty(title) && TextUtils.isEmpty(byline)) {
+ // Both are empty so we don't have any data to show
+ complicationManager.updateComplicationData(complicationId,
+ new ComplicationData.Builder(ComplicationData.TYPE_NO_DATA).build());
+ return;
+ } else if (TextUtils.isEmpty(title)) {
+ // We only have the byline, so use that as the long text
+ builder.setLongText(ComplicationText.plainText(byline));
+ } else {
+ if (!TextUtils.isEmpty(byline)) {
+ builder.setLongTitle(ComplicationText.plainText(byline));
+ }
+ builder.setLongText(ComplicationText.plainText(title));
+ }
+ builder.setTapAction(tapAction);
+ break;
+ case ComplicationData.TYPE_SMALL_IMAGE:
+ builder.setImageStyle(ComplicationData.IMAGE_STYLE_PHOTO)
+ .setSmallImage(Icon.createWithContentUri(MuzeiContract.Artwork.CONTENT_URI));
+ builder.setTapAction(tapAction);
+ break;
+ case ComplicationData.TYPE_LARGE_IMAGE:
+ builder.setLargeImage(Icon.createWithContentUri(MuzeiContract.Artwork.CONTENT_URI));
+ break;
+ }
complicationManager.updateComplicationData(complicationId, builder.build());
}
}
@@ -0,0 +1,25 @@
+<!--
+ Copyright 2014 Google Inc.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="48dp"
+ android:height="48dp"
+ android:viewportWidth="27.0"
+ android:viewportHeight="27.0">
+ <path
+ android:pathData="M21.711,16.212c0.057,-0.303 0.175,-0.739 0.356,-1.307l0.568,-1.79c0.199,-0.625 0.374,-1.226 0.526,-1.804 0.15,-0.578 0.227,-1.01 0.227,-1.293 0,-0.966 -0.374,-1.714 -1.122,-2.245 -0.749,-0.53 -1.786,-0.795 -3.112,-0.795 -0.53,0.34 -1.075,0.947 -1.634,1.818 -0.559,0.872 -1.132,1.989 -1.719,3.353l-0.199,0.028c0.057,-0.284 0.123,-0.558 0.2,-0.824 0.037,-0.227 0.08,-0.464 0.127,-0.71 0.047,-0.246 0.071,-0.464 0.071,-0.654 0,-0.947 -0.365,-1.685 -1.094,-2.216 -0.73,-0.53 -1.747,-0.795 -3.054,-0.795 -0.53,0.34 -1.075,0.947 -1.634,1.818 -0.559,0.872 -1.132,1.989 -1.719,3.353l-0.199,0.028c0.076,-0.511 0.17,-1.023 0.284,-1.534 0.114,-0.512 0.218,-0.966 0.313,-1.364l0.34,-1.364 -0.397,-0.596c-0.72,0.056 -1.459,0.113 -2.216,0.17 -0.644,0.038 -1.336,0.076 -2.074,0.114 -0.74,0.038 -1.421,0.056 -2.046,0.056l-0.341,2.33h0.795c0.379,0 0.64,0.09 0.782,0.27 0.142,0.18 0.184,0.498 0.128,0.952a33.29,33.29 0,0 0,-0.142 0.867c-0.057,0.37 -0.124,0.786 -0.2,1.25 -0.075,0.464 -0.156,0.962 -0.24,1.492 -0.086,0.53 -0.167,1.051 -0.242,1.562 -0.21,1.213 -0.427,2.52 -0.654,3.922l0.568,0.653c0.53,0 1.047,-0.038 1.549,-0.114a6.59,6.59 0,0 0,1.321 -0.326c0.379,-0.142 0.687,-0.299 0.924,-0.47 0.236,-0.17 0.373,-0.359 0.412,-0.567l0.198,-1.677c0.303,-0.89 0.616,-1.71 0.938,-2.458 0.322,-0.748 0.625,-1.392 0.91,-1.932 0.284,-0.54 0.544,-0.96 0.78,-1.264 0.237,-0.303 0.431,-0.455 0.583,-0.455 0.36,0 0.54,0.218 0.54,0.654 0,0.133 -0.028,0.35 -0.085,0.653 -0.057,0.303 -0.128,0.654 -0.213,1.052 -0.085,0.397 -0.18,0.828 -0.284,1.292 -0.105,0.465 -0.213,0.924 -0.327,1.378 -0.266,1.08 -0.568,2.274 -0.91,3.58l0.569,0.654c0.53,0 1.046,-0.038 1.548,-0.114a6.91,6.91 0,0 0,1.336 -0.326c0.388,-0.142 0.7,-0.299 0.938,-0.47 0.236,-0.17 0.364,-0.359 0.383,-0.567l0.142,-1.364c0.36,-0.928 0.72,-1.785 1.08,-2.572 0.36,-0.786 0.7,-1.463 1.023,-2.031 0.322,-0.569 0.62,-1.013 0.895,-1.336 0.274,-0.322 0.497,-0.483 0.668,-0.483 0.34,0 0.511,0.266 0.511,0.796 0,0.265 -0.09,0.715 -0.27,1.35 -0.18,0.634 -0.38,1.311 -0.597,2.031 -0.218,0.72 -0.416,1.402 -0.596,2.046 -0.18,0.644 -0.27,1.118 -0.27,1.42 0,0.588 0.146,1.014 0.44,1.28 0.294,0.264 0.772,0.397 1.435,0.397 0.398,0 0.79,-0.071 1.18,-0.213 0.387,-0.142 0.81,-0.384 1.264,-0.725 0.454,-0.34 0.966,-0.79 1.534,-1.35a44.251,44.251 0,0 0,1.989 -2.116l-0.54,-1.364 -0.682,-0.114c-0.568,0.493 -0.937,0.81 -1.108,0.952 -0.17,0.142 -0.294,0.213 -0.37,0.213l-0.085,-0.085z"
+ android:fillColor="#FFF"/>
+</vector>

0 comments on commit 34e3d88

Please sign in to comment.