Skip to content
This repository was archived by the owner on Sep 6, 2019. It is now read-only.

Commit dc69cc5

Browse files
Auto-update
1 parent ed1656a commit dc69cc5

16 files changed

Lines changed: 1214 additions & 8 deletions

Application/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
}
66

77
dependencies {
8-
classpath 'com.android.tools.build:gradle:2.0.0'
8+
classpath 'com.android.tools.build:gradle:2.1.0'
99
}
1010
}
1111

@@ -19,7 +19,7 @@ dependencies {
1919
compile "com.android.support:support-v4:23.3.0"
2020
compile "com.android.support:support-v13:23.3.0"
2121
compile "com.android.support:cardview-v7:23.3.0"
22-
compile 'com.google.android.support:wearable:1.3.0'
22+
compile 'com.google.android.support:wearable:1.4.0'
2323
compile 'com.google.android.gms:play-services-fitness:8.4.0'
2424
compile 'com.google.android.gms:play-services-wearable:8.4.0'
2525
compile 'com.android.support:support-v13:23.3.0'
@@ -36,7 +36,7 @@ List<String> dirs = [
3636

3737
android {
3838
compileSdkVersion 23
39-
buildToolsVersion "24.0.0 rc3"
39+
buildToolsVersion "23.0.3"
4040

4141
defaultConfig {
4242
minSdkVersion 18

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Pre-requisites
1616
--------------
1717

1818
- Android SDK v23
19-
- Android Build Tools v24.0.0 rc3
19+
- Android Build Tools v23.0.3
2020
- Android Support Repository
2121

2222
Getting Started

Wearable/build.gradle

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
}
66

77
dependencies {
8-
classpath 'com.android.tools.build:gradle:2.0.0'
8+
classpath 'com.android.tools.build:gradle:2.1.0'
99
}
1010
}
1111

@@ -15,13 +15,15 @@ apply plugin: 'com.android.application'
1515

1616
dependencies {
1717

18+
compile 'com.google.android.gms:play-services-wearable:8.4.0'
1819
compile 'com.android.support:palette-v7:23.3.0'
20+
compile 'com.google.android.support:wearable:2.0.0-alpha1'
1921
compile 'com.google.android.gms:play-services-fitness:8.4.0'
2022

2123

2224
compile 'com.google.android.gms:play-services-wearable:8.4.0'
2325
compile 'com.android.support:support-v13:23.3.0'
24-
compile 'com.google.android.support:wearable:1.3.0'
26+
compile 'com.google.android.support:wearable:1.4.0'
2527
}
2628

2729
// The sample build uses multiple directories to
@@ -35,12 +37,18 @@ List<String> dirs = [
3537
android {
3638
compileSdkVersion 23
3739

38-
buildToolsVersion "24.0.0 rc3"
40+
buildToolsVersion "23.0.3"
3941

4042
defaultConfig {
4143
versionCode 1
4244
versionName "1.0"
4345

46+
47+
minSdkVersion 18
48+
49+
50+
51+
4452
targetSdkVersion 23
4553
}
4654

Wearable/src/main/AndroidManifest.xml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,42 @@
132132
<category android:name="com.google.android.wearable.watchface.category.WATCH_FACE" />
133133
</intent-filter>
134134
</service>
135+
136+
<service
137+
android:name=".ComplicationSimpleWatchFaceService"
138+
android:enabled="true"
139+
android:label="@string/complication_simple"
140+
android:permission="android.permission.BIND_WALLPAPER">
141+
<meta-data
142+
android:name="android.service.wallpaper"
143+
android:resource="@xml/watch_face"/>
144+
<meta-data
145+
android:name="com.google.android.wearable.watchface.preview"
146+
android:resource="@drawable/preview_complication_simple"/>
147+
<meta-data
148+
android:name="com.google.android.wearable.watchface.preview_circular"
149+
android:resource="@drawable/preview_complication_simple"/>
150+
<meta-data
151+
android:name="com.google.android.wearable.watchface.wearableConfigurationAction"
152+
android:value="com.example.android.wearable.watchface.CONFIG_COMPLICATION_SIMPLE"/>
153+
154+
<intent-filter>
155+
<action android:name="android.service.wallpaper.WallpaperService"/>
156+
157+
<category android:name="com.google.android.wearable.watchface.category.WATCH_FACE"/>
158+
</intent-filter>
159+
</service>
160+
<activity
161+
android:name=".ComplicationSimpleConfigActivity"
162+
android:label="@string/complication_simple">
163+
<intent-filter>
164+
<action android:name="com.example.android.wearable.watchface.CONFIG_COMPLICATION_SIMPLE"/>
165+
166+
<category android:name="com.google.android.wearable.watchface.category.WEARABLE_CONFIGURATION"/>
167+
<category android:name="android.intent.category.DEFAULT"/>
168+
</intent-filter>
169+
</activity>
170+
135171
<service
136172
android:name=".InteractiveWatchFaceService"
137173
android:label="@string/interactive_name"
@@ -270,6 +306,35 @@
270306
android:name=".CalendarWatchFacePermissionActivity"
271307
android:label="@string/title_activity_calendar_watch_face_permission" >
272308
</activity>
309+
310+
<service
311+
android:name=".provider.RandomNumberProviderService"
312+
android:label="@string/complications_provider_random_number"
313+
android:icon="@drawable/ic_launcher">
314+
315+
<intent-filter>
316+
<action android:name="android.support.wearable.complications.ACTION_COMPLICATION_UPDATE_REQUEST"/>
317+
</intent-filter>
318+
319+
<meta-data
320+
android:name="android.support.wearable.complications.SUPPORTED_TYPES"
321+
android:value="RANGED_VALUE,SHORT_TEXT,LONG_TEXT"/>
322+
<!--
323+
When your complication data provider is active, UPDATE_PERIOD_SECONDS specifies how
324+
often you want the system to check for updates to the data. In this case, the time is
325+
specified to a relatively short 120 seconds, so we can observe the result of this code
326+
lab. In everyday use, developers should consider intervals in the order of minutes.
327+
Also, remember that this is only a guidance for the system. Android Wear may update less
328+
frequently.
329+
330+
If your app needs to push updates instead of updating on a regular schedule, you should
331+
set this value to 0 and use ProviderUpdateRequester.requestUpdate() to trigger an update
332+
request when you need one.
333+
-->
334+
<meta-data
335+
android:name="android.support.wearable.complications.UPDATE_PERIOD_SECONDS"
336+
android:value="120"/>
337+
</service>
273338
</application>
274339

275340
</manifest>
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
/*
2+
* Copyright (C) 2014 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.example.android.wearable.watchface;
17+
18+
import android.app.Activity;
19+
import android.content.ComponentName;
20+
import android.content.Context;
21+
import android.content.Intent;
22+
import android.content.res.TypedArray;
23+
import android.graphics.drawable.Drawable;
24+
import android.os.Bundle;
25+
import android.support.wearable.complications.ProviderChooserIntent;
26+
import android.support.wearable.view.WearableListView;
27+
import android.util.Log;
28+
import android.view.LayoutInflater;
29+
import android.view.View;
30+
import android.view.ViewGroup;
31+
import android.widget.ImageView;
32+
import android.widget.TextView;
33+
34+
import java.util.ArrayList;
35+
import java.util.List;
36+
37+
/**
38+
* The watch-side config activity for {@link ComplicationSimpleWatchFaceService}, which
39+
* allows for setting complications on the left and right of watch face.
40+
*/
41+
public class ComplicationSimpleConfigActivity extends Activity implements
42+
WearableListView.ClickListener {
43+
44+
private static final String TAG = "CompSimpleConfig";
45+
46+
private static final int PROVIDER_CHOOSER_REQUEST_CODE = 1;
47+
48+
private WearableListView mWearableConfigListView;
49+
private ConfigurationAdapter mAdapter;
50+
51+
@Override
52+
protected void onCreate(Bundle savedInstanceState) {
53+
super.onCreate(savedInstanceState);
54+
setContentView(R.layout.activity_complication_simple_config);
55+
56+
mAdapter = new ConfigurationAdapter(getApplicationContext(), getComplicationItems());
57+
58+
mWearableConfigListView = (WearableListView) findViewById(R.id.wearable_list);
59+
mWearableConfigListView.setAdapter(mAdapter);
60+
mWearableConfigListView.setClickListener(this);
61+
}
62+
63+
@Override
64+
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
65+
if (requestCode == PROVIDER_CHOOSER_REQUEST_CODE
66+
&& resultCode == RESULT_OK) {
67+
finish();
68+
}
69+
}
70+
71+
@Override
72+
public void onClick(WearableListView.ViewHolder viewHolder) {
73+
if (Log.isLoggable(TAG, Log.DEBUG)) {
74+
Log.d(TAG, "onClick()");
75+
}
76+
77+
Integer tag = (Integer) viewHolder.itemView.getTag();
78+
ComplicationItem complicationItem = mAdapter.getItem(tag);
79+
80+
startActivityForResult(ProviderChooserIntent.createProviderChooserIntent(
81+
complicationItem.watchFace,
82+
complicationItem.complicationId,
83+
complicationItem.supportedTypes), PROVIDER_CHOOSER_REQUEST_CODE);
84+
}
85+
86+
private List<ComplicationItem> getComplicationItems() {
87+
ComponentName watchFace = new ComponentName(
88+
getApplicationContext(), ComplicationSimpleWatchFaceService.class);
89+
90+
String[] complicationNames =
91+
getResources().getStringArray(R.array.complication_simple_names);
92+
93+
int[] complicationIds = ComplicationSimpleWatchFaceService.COMPLICATION_IDS;
94+
95+
TypedArray icons = getResources().obtainTypedArray(R.array.complication_simple_icons);
96+
97+
List<ComplicationItem> items = new ArrayList<>();
98+
for (int i = 0; i < complicationIds.length; i++) {
99+
items.add(new ComplicationItem(watchFace,
100+
complicationIds[i],
101+
ComplicationSimpleWatchFaceService.COMPLICATION_SUPPORTED_TYPES[i],
102+
icons.getDrawable(i),
103+
complicationNames[i]));
104+
}
105+
return items;
106+
}
107+
108+
@Override
109+
public void onTopEmptyRegionClick() {
110+
if (Log.isLoggable(TAG, Log.DEBUG)) {
111+
Log.d(TAG, "onTopEmptyRegionClick()");
112+
}
113+
}
114+
115+
/*
116+
* Inner class representing items of the ConfigurationAdapter (WearableListView.Adapter) class.
117+
*/
118+
private final class ComplicationItem {
119+
ComponentName watchFace;
120+
int complicationId;
121+
int[] supportedTypes;
122+
Drawable icon;
123+
String title;
124+
125+
public ComplicationItem(ComponentName watchFace, int complicationId, int[] supportedTypes,
126+
Drawable icon, String title) {
127+
this.watchFace = watchFace;
128+
this.complicationId = complicationId;
129+
this.supportedTypes = supportedTypes;
130+
this.icon = icon;
131+
this.title = title;
132+
}
133+
}
134+
135+
private static class ConfigurationAdapter extends WearableListView.Adapter {
136+
137+
private Context mContext;
138+
private final LayoutInflater mInflater;
139+
private List<ComplicationItem> mItems;
140+
141+
142+
public ConfigurationAdapter (Context context, List<ComplicationItem> items) {
143+
mContext = context;
144+
mInflater = LayoutInflater.from(mContext);
145+
mItems = items;
146+
}
147+
148+
// Provides a reference to the type of views you're using
149+
public static class ItemViewHolder extends WearableListView.ViewHolder {
150+
private ImageView iconImageView;
151+
private TextView textView;
152+
public ItemViewHolder(View itemView) {
153+
super(itemView);
154+
iconImageView = (ImageView) itemView.findViewById(R.id.icon);
155+
textView = (TextView) itemView.findViewById(R.id.name);
156+
}
157+
}
158+
159+
@Override
160+
public WearableListView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
161+
162+
// Inflate custom layout for list items.
163+
return new ItemViewHolder(
164+
mInflater.inflate(R.layout.activity_complication_simple_list_item, null));
165+
}
166+
167+
@Override
168+
public void onBindViewHolder(WearableListView.ViewHolder holder, int position) {
169+
170+
ItemViewHolder itemHolder = (ItemViewHolder) holder;
171+
172+
ImageView imageView = itemHolder.iconImageView;
173+
imageView.setImageDrawable(mItems.get(position).icon);
174+
175+
TextView textView = itemHolder.textView;
176+
textView.setText(mItems.get(position).title);
177+
178+
holder.itemView.setTag(position);
179+
}
180+
181+
@Override
182+
public int getItemCount() {
183+
return mItems.size();
184+
}
185+
186+
public ComplicationItem getItem(int position) {
187+
return mItems.get(position);
188+
}
189+
}
190+
191+
}

0 commit comments

Comments
 (0)