Skip to content

Commit

Permalink
Merge pull request #328 from ianhanniballake/complications
Browse files Browse the repository at this point in the history
Improve complications: long text, small image, system health
  • Loading branch information
ianhanniballake committed Jan 31, 2017
2 parents 168b22a + b2801c8 commit 34e3d88
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 5 deletions.
5 changes: 5 additions & 0 deletions art/ic_complication.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions wearable/src/main/AndroidManifest.xml
Expand Up @@ -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">
Expand All @@ -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" />
Expand All @@ -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>
Expand Down
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Expand Up @@ -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;

Expand All @@ -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) {
Expand Down Expand Up @@ -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());
}
}
25 changes: 25 additions & 0 deletions wearable/src/main/res/drawable/ic_complication.xml
@@ -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.