diff --git a/build/sdk.atree b/build/sdk.atree
index 791461c14..b40c405a1 100644
--- a/build/sdk.atree
+++ b/build/sdk.atree
@@ -271,7 +271,20 @@ developers/build/prebuilts/gradle/SwipeRefreshMultipleViews sam
developers/build/prebuilts/gradle/MediaRouter samples/${PLATFORM_NAME}/media/MediaRouter
# Wearable sample tree
-development/samples/wearable/Notifications samples/${PLATFORM_NAME}/wearable/Notifications
+development/samples/wearable/AgendaData samples/${PLATFORM_NAME}/wearable/AgendaData
+development/samples/wearable/DataLayer samples/${PLATFORM_NAME}/wearable/DataLayer
+development/samples/wearable/DelayedConfirmation samples/${PLATFORM_NAME}/wearable/DelayedConfirmation
+development/samples/wearable/ElizaChat samples/${PLATFORM_NAME}/wearable/ElizaChat
+development/samples/wearable/FindMyPhone samples/${PLATFORM_NAME}/wearable/FindMyPhone
+development/samples/wearable/Flashlight samples/${PLATFORM_NAME}/wearable/Flashlight
+development/samples/wearable/Geofencing samples/${PLATFORM_NAME}/wearable/Geofencing
+development/samples/wearable/JumpingJack samples/${PLATFORM_NAME}/wearable/JumpingJack
+development/samples/wearable/Notifications samples/${PLATFORM_NAME}/wearable/Notifications
+development/samples/wearable/Quiz samples/${PLATFORM_NAME}/wearable/Quiz
+development/samples/wearable/RecipeAssistant samples/${PLATFORM_NAME}/wearable/RecipeAssistant
+development/samples/wearable/SkeletonWearableApp samples/${PLATFORM_NAME}/wearable/SkeletonWearableApp
+development/samples/wearable/Timer samples/${PLATFORM_NAME}/wearable/Timer
+development/samples/wearable/WatchViewStub samples/${PLATFORM_NAME}/wearable/WatchViewStub
# Old sample tree
development/samples/AccelerometerPlay samples/${PLATFORM_NAME}/legacy/AccelerometerPlay
diff --git a/samples/wearable/AgendaData/Application/build.gradle b/samples/wearable/AgendaData/Application/build.gradle
new file mode 100644
index 000000000..7de0d36a1
--- /dev/null
+++ b/samples/wearable/AgendaData/Application/build.gradle
@@ -0,0 +1,30 @@
+apply plugin: 'android'
+
+android {
+ compileSdkVersion 20
+ buildToolsVersion '20'
+
+ defaultConfig {
+ minSdkVersion 18
+ targetSdkVersion 20
+ versionCode 1
+ versionName "1.0"
+ }
+
+ buildTypes {
+ release {
+ runProguard false
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
+ }
+ }
+
+ aaptOptions {
+ noCompress 'apk'
+ }
+}
+
+dependencies {
+ compile 'com.google.android.gms:play-services:5.0.+@aar'
+ compile "com.android.support:support-v4:20.0.+"
+ wearApp project(':Wearable')
+}
\ No newline at end of file
diff --git a/samples/wearable/AgendaData/Application/proguard-rules.txt b/samples/wearable/AgendaData/Application/proguard-rules.txt
new file mode 100644
index 000000000..824a322c1
--- /dev/null
+++ b/samples/wearable/AgendaData/Application/proguard-rules.txt
@@ -0,0 +1,28 @@
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
+-dontwarn android.support.wearable.view.DelayedConfirmationView
+-dontwarn android.support.wearable.view.CircledImageView
+
+-keep class android.support.wearable.view.WearableListView {
+ private void setScrollAnimator(int);
+ private void setScrollVertically(int);
+}
+
diff --git a/samples/wearable/AgendaData/Application/project.properties b/samples/wearable/AgendaData/Application/project.properties
new file mode 100644
index 000000000..4ab125693
--- /dev/null
+++ b/samples/wearable/AgendaData/Application/project.properties
@@ -0,0 +1,14 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system edit
+# "ant.properties", and override values to adapt the script to your
+# project structure.
+#
+# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
+#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
+
+# Project target.
+target=android-19
diff --git a/samples/wearable/AgendaData/Application/src/main/AndroidManifest.xml b/samples/wearable/AgendaData/Application/src/main/AndroidManifest.xml
new file mode 100644
index 000000000..d96efd8d5
--- /dev/null
+++ b/samples/wearable/AgendaData/Application/src/main/AndroidManifest.xml
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/wearable/AgendaData/Application/src/main/java/com/example/android/wearable/agendadata/CalendarQueryService.java b/samples/wearable/AgendaData/Application/src/main/java/com/example/android/wearable/agendadata/CalendarQueryService.java
new file mode 100644
index 000000000..c55fb2c2e
--- /dev/null
+++ b/samples/wearable/AgendaData/Application/src/main/java/com/example/android/wearable/agendadata/CalendarQueryService.java
@@ -0,0 +1,251 @@
+package com.example.android.wearable.agendadata;
+
+
+import static com.example.android.wearable.agendadata.Constants.TAG;
+import static com.example.android.wearable.agendadata.Constants.CONNECTION_TIME_OUT_MS;
+import static com.example.android.wearable.agendadata.Constants.CAL_DATA_ITEM_PATH_PREFIX;
+import static com.example.android.wearable.agendadata.Constants.ALL_DAY;
+import static com.example.android.wearable.agendadata.Constants.BEGIN;
+import static com.example.android.wearable.agendadata.Constants.DATA_ITEM_URI;
+import static com.example.android.wearable.agendadata.Constants.DESCRIPTION;
+import static com.example.android.wearable.agendadata.Constants.END;
+import static com.example.android.wearable.agendadata.Constants.EVENT_ID;
+import static com.example.android.wearable.agendadata.Constants.ID;
+import static com.example.android.wearable.agendadata.Constants.PROFILE_PIC;
+import static com.example.android.wearable.agendadata.Constants.TITLE;
+
+import android.app.IntentService;
+import android.content.ContentResolver;
+import android.content.ContentUris;
+import android.content.Context;
+import android.content.Intent;
+import android.content.res.Resources;
+import android.database.Cursor;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.net.Uri;
+import android.os.Bundle;
+import android.provider.CalendarContract;
+import android.provider.ContactsContract.CommonDataKinds.Email;
+import android.provider.ContactsContract.Contacts;
+import android.provider.ContactsContract.Data;
+import android.text.format.Time;
+import android.util.Log;
+
+import com.google.android.gms.common.ConnectionResult;
+import com.google.android.gms.common.api.GoogleApiClient;
+import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
+import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
+import com.google.android.gms.wearable.Asset;
+import com.google.android.gms.wearable.DataMap;
+import com.google.android.gms.wearable.PutDataMapRequest;
+import com.google.android.gms.wearable.Wearable;
+
+import java.io.ByteArrayOutputStream;
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Queries calendar events using Android Calendar Provider API and creates a data item for each
+ * event.
+ */
+public class CalendarQueryService extends IntentService
+ implements ConnectionCallbacks, OnConnectionFailedListener {
+
+ private static final String[] INSTANCE_PROJECTION = {
+ CalendarContract.Instances._ID,
+ CalendarContract.Instances.EVENT_ID,
+ CalendarContract.Instances.TITLE,
+ CalendarContract.Instances.BEGIN,
+ CalendarContract.Instances.END,
+ CalendarContract.Instances.ALL_DAY,
+ CalendarContract.Instances.DESCRIPTION,
+ CalendarContract.Instances.ORGANIZER
+ };
+
+ private static final String[] CONTACT_PROJECTION = new String[] { Data._ID, Data.CONTACT_ID };
+ private static final String CONTACT_SELECTION = Email.ADDRESS + " = ?";
+
+ private GoogleApiClient mGoogleApiClient;
+
+ public CalendarQueryService() {
+ super(CalendarQueryService.class.getSimpleName());
+ }
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ mGoogleApiClient = new GoogleApiClient.Builder(this)
+ .addApi(Wearable.API)
+ .addConnectionCallbacks(this)
+ .addOnConnectionFailedListener(this)
+ .build();
+ }
+
+ @Override
+ protected void onHandleIntent(Intent intent) {
+ mGoogleApiClient.blockingConnect(CONNECTION_TIME_OUT_MS, TimeUnit.MILLISECONDS);
+ // Query calendar events in the next 24 hours.
+ Time time = new Time();
+ time.setToNow();
+ long beginTime = time.toMillis(true);
+ time.monthDay++;
+ time.normalize(true);
+ long endTime = time.normalize(true);
+
+ List events = queryEvents(this, beginTime, endTime);
+ for (Event event : events) {
+ final PutDataMapRequest putDataMapRequest = event.toPutDataMapRequest();
+ if (mGoogleApiClient.isConnected()) {
+ Wearable.DataApi.putDataItem(
+ mGoogleApiClient, putDataMapRequest.asPutDataRequest()).await();
+ } else {
+ Log.e(TAG, "Failed to send data item: " + putDataMapRequest
+ + " - Client disconnected from Google Play Services");
+ }
+ }
+ mGoogleApiClient.disconnect();
+ }
+
+ private static String makeDataItemPath(long eventId, long beginTime) {
+ return CAL_DATA_ITEM_PATH_PREFIX + eventId + "/" + beginTime;
+ }
+
+ private static List queryEvents(Context context, long beginTime, long endTime) {
+ ContentResolver contentResolver = context.getContentResolver();
+ Uri.Builder builder = CalendarContract.Instances.CONTENT_URI.buildUpon();
+ ContentUris.appendId(builder, beginTime);
+ ContentUris.appendId(builder, endTime);
+
+ Cursor cursor = contentResolver.query(builder.build(), INSTANCE_PROJECTION,
+ null /* selection */, null /* selectionArgs */, null /* sortOrder */);
+ try {
+ int idIdx = cursor.getColumnIndex(CalendarContract.Instances._ID);
+ int eventIdIdx = cursor.getColumnIndex(CalendarContract.Instances.EVENT_ID);
+ int titleIdx = cursor.getColumnIndex(CalendarContract.Instances.TITLE);
+ int beginIdx = cursor.getColumnIndex(CalendarContract.Instances.BEGIN);
+ int endIdx = cursor.getColumnIndex(CalendarContract.Instances.END);
+ int allDayIdx = cursor.getColumnIndex(CalendarContract.Instances.ALL_DAY);
+ int descIdx = cursor.getColumnIndex(CalendarContract.Instances.DESCRIPTION);
+ int ownerEmailIdx = cursor.getColumnIndex(CalendarContract.Instances.ORGANIZER);
+
+ List events = new ArrayList(cursor.getCount());
+ while (cursor.moveToNext()) {
+ Event event = new Event();
+ event.id = cursor.getLong(idIdx);
+ event.eventId = cursor.getLong(eventIdIdx);
+ event.title = cursor.getString(titleIdx);
+ event.begin = cursor.getLong(beginIdx);
+ event.end = cursor.getLong(endIdx);
+ event.allDay = cursor.getInt(allDayIdx) != 0;
+ event.description = cursor.getString(descIdx);
+ String ownerEmail = cursor.getString(ownerEmailIdx);
+ Cursor contactCursor = contentResolver.query(Data.CONTENT_URI,
+ CONTACT_PROJECTION, CONTACT_SELECTION, new String[] {ownerEmail}, null);
+ int ownerIdIdx = contactCursor.getColumnIndex(Data.CONTACT_ID);
+ long ownerId = -1;
+ if (contactCursor.moveToFirst()) {
+ ownerId = contactCursor.getLong(ownerIdIdx);
+ }
+ contactCursor.close();
+ // Use event organizer's profile picture as the notification background.
+ event.ownerProfilePic = getProfilePicture(contentResolver, context, ownerId);
+ events.add(event);
+ }
+ return events;
+ } finally {
+ cursor.close();
+ }
+ }
+
+ @Override
+ public void onConnected(Bundle connectionHint) {
+ }
+
+ @Override
+ public void onConnectionSuspended(int cause) {
+ }
+
+ @Override
+ public void onConnectionFailed(ConnectionResult result) {
+ }
+
+ private static Asset getDefaultProfile(Resources res) {
+ Bitmap bitmap = BitmapFactory.decodeResource(res, R.drawable.nobody);
+ return Asset.createFromBytes(toByteArray(bitmap));
+ }
+
+ private static Asset getProfilePicture(ContentResolver contentResolver, Context context,
+ long contactId) {
+ if (contactId != -1) {
+ // Try to retrieve the profile picture for the given contact.
+ Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
+ InputStream inputStream = Contacts.openContactPhotoInputStream(contentResolver,
+ contactUri, true /*preferHighres*/);
+
+ if (null != inputStream) {
+ try {
+ Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
+ if (bitmap != null) {
+ return Asset.createFromBytes(toByteArray(bitmap));
+ } else {
+ Log.e(TAG, "Cannot decode profile picture for contact " + contactId);
+ }
+ } finally {
+ closeQuietly(inputStream);
+ }
+ }
+ }
+ // Use a default background image if the user has no profile picture or there was an error.
+ return getDefaultProfile(context.getResources());
+ }
+
+ private static byte[] toByteArray(Bitmap bitmap) {
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
+ byte[] byteArray = stream.toByteArray();
+ closeQuietly(stream);
+ return byteArray;
+ }
+
+ private static void closeQuietly(Closeable closeable) {
+ try {
+ closeable.close();
+ } catch (IOException e) {
+ Log.e(TAG, "IOException while closing closeable.", e);
+ }
+ }
+
+ private static class Event {
+
+ public long id;
+ public long eventId;
+ public String title;
+ public long begin;
+ public long end;
+ public boolean allDay;
+ public String description;
+ public Asset ownerProfilePic;
+
+ public PutDataMapRequest toPutDataMapRequest(){
+ final PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(
+ makeDataItemPath(eventId, begin));
+ DataMap data = putDataMapRequest.getDataMap();
+ data.putString(DATA_ITEM_URI, putDataMapRequest.getUri().toString());
+ data.putLong(ID, id);
+ data.putLong(EVENT_ID, eventId);
+ data.putString(TITLE, title);
+ data.putLong(BEGIN, begin);
+ data.putLong(END, end);
+ data.putBoolean(ALL_DAY, allDay);
+ data.putString(DESCRIPTION, description);
+ data.putAsset(PROFILE_PIC, ownerProfilePic);
+
+ return putDataMapRequest;
+ }
+ }
+}
diff --git a/samples/wearable/AgendaData/Application/src/main/java/com/example/android/wearable/agendadata/Constants.java b/samples/wearable/AgendaData/Application/src/main/java/com/example/android/wearable/agendadata/Constants.java
new file mode 100644
index 000000000..1b9a0f078
--- /dev/null
+++ b/samples/wearable/AgendaData/Application/src/main/java/com/example/android/wearable/agendadata/Constants.java
@@ -0,0 +1,23 @@
+package com.example.android.wearable.agendadata;
+
+/** Constants used in companion app. */
+public final class Constants {
+ private Constants() {
+ }
+
+ public static final String TAG = "AgendaDataSample";
+
+ public static final String CAL_DATA_ITEM_PATH_PREFIX = "/event";
+ // Timeout for making a connection to GoogleApiClient (in milliseconds).
+ public static final long CONNECTION_TIME_OUT_MS = 100;
+
+ public static final String EVENT_ID = "event_id";
+ public static final String ID = "id";
+ public static final String TITLE = "title";
+ public static final String DESCRIPTION = "description";
+ public static final String BEGIN = "begin";
+ public static final String END = "end";
+ public static final String DATA_ITEM_URI = "data_item_uri";
+ public static final String ALL_DAY = "all_day";
+ public static final String PROFILE_PIC = "profile_pic";
+}
diff --git a/samples/wearable/AgendaData/Application/src/main/java/com/example/android/wearable/agendadata/MainActivity.java b/samples/wearable/AgendaData/Application/src/main/java/com/example/android/wearable/agendadata/MainActivity.java
new file mode 100644
index 000000000..046fc8d62
--- /dev/null
+++ b/samples/wearable/AgendaData/Application/src/main/java/com/example/android/wearable/agendadata/MainActivity.java
@@ -0,0 +1,186 @@
+package com.example.android.wearable.agendadata;
+
+import static com.example.android.wearable.agendadata.Constants.TAG;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.content.IntentSender;
+import android.net.Uri;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.widget.ScrollView;
+import android.widget.TextView;
+
+import com.google.android.gms.common.ConnectionResult;
+import com.google.android.gms.common.api.GoogleApiClient;
+import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
+import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
+import com.google.android.gms.common.api.ResultCallback;
+import com.google.android.gms.common.data.FreezableUtils;
+import com.google.android.gms.wearable.DataApi;
+import com.google.android.gms.wearable.DataItem;
+import com.google.android.gms.wearable.DataItemBuffer;
+import com.google.android.gms.wearable.Node;
+import com.google.android.gms.wearable.NodeApi;
+import com.google.android.gms.wearable.Wearable;
+
+import java.util.List;
+
+public class MainActivity extends Activity implements NodeApi.NodeListener, ConnectionCallbacks,
+ OnConnectionFailedListener {
+
+ /** Request code for launching the Intent to resolve Google Play services errors. */
+ private static final int REQUEST_RESOLVE_ERROR = 1000;
+
+ private GoogleApiClient mGoogleApiClient;
+ private boolean mResolvingError = false;
+
+ private TextView mLogTextView;
+ ScrollView mScroller;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.main);
+ mLogTextView = (TextView) findViewById(R.id.log);
+ mScroller = (ScrollView) findViewById(R.id.scroller);
+ mGoogleApiClient = new GoogleApiClient.Builder(this)
+ .addApi(Wearable.API)
+ .addConnectionCallbacks(this)
+ .addOnConnectionFailedListener(this)
+ .build();
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ if (!mResolvingError) {
+ mGoogleApiClient.connect();
+ }
+ }
+
+ @Override
+ protected void onStop() {
+ if (mGoogleApiClient.isConnected()) {
+ Wearable.NodeApi.removeListener(mGoogleApiClient, this);
+ }
+ mGoogleApiClient.disconnect();
+ super.onStop();
+ }
+
+ public void onGetEventsClicked(View v) {
+ startService(new Intent(this, CalendarQueryService.class));
+ }
+
+ public void onDeleteEventsClicked(View v) {
+ if (mGoogleApiClient.isConnected()) {
+ Wearable.DataApi.getDataItems(mGoogleApiClient)
+ .setResultCallback(new ResultCallback() {
+ @Override
+ public void onResult(DataItemBuffer result) {
+ if (result.getStatus().isSuccess()) {
+ deleteDataItems(result);
+ } else {
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "onDeleteEventsClicked(): failed to get Data Items");
+ }
+ }
+ result.close();
+ }
+ });
+ } else {
+ Log.e(TAG, "Failed to delete data items"
+ + " - Client disconnected from Google Play Services");
+ }
+ }
+
+ private void deleteDataItems(DataItemBuffer dataItems) {
+ if (mGoogleApiClient.isConnected()) {
+ // Store the DataItem URIs in a List and close the buffer. Then use these URIs
+ // to delete the DataItems.
+ final List dataItemList = FreezableUtils.freezeIterable(dataItems);
+ dataItems.close();
+ for (final DataItem dataItem : dataItemList) {
+ final Uri dataItemUri = dataItem.getUri();
+ // In a real calendar application, this might delete the corresponding calendar
+ // event from the calendar data provider. In this sample, we simply delete the
+ // DataItem, but leave the phone's calendar data intact.
+ Wearable.DataApi.deleteDataItems(mGoogleApiClient, dataItemUri)
+ .setResultCallback(new ResultCallback() {
+ @Override
+ public void onResult(DataApi.DeleteDataItemsResult deleteResult) {
+ if (deleteResult.getStatus().isSuccess()) {
+ appendLog("Successfully deleted data item: " + dataItemUri);
+ } else {
+ appendLog("Failed to delete data item:" + dataItemUri);
+ }
+ }
+ });
+ }
+ } else {
+ Log.e(TAG, "Failed to delete data items"
+ + " - Client disconnected from Google Play Services");
+ }
+ }
+
+ private void appendLog(final String s) {
+ mLogTextView.post(new Runnable() {
+ @Override
+ public void run() {
+ mLogTextView.append(s);
+ mLogTextView.append("\n");
+ mScroller.fullScroll(View.FOCUS_DOWN);
+ }
+ });
+ }
+
+ @Override
+ public void onPeerConnected(Node peer) {
+ appendLog("Device connected");
+ }
+
+ @Override
+ public void onPeerDisconnected(Node peer) {
+ appendLog("Device disconnected");
+ }
+
+ @Override
+ public void onConnected(Bundle connectionHint) {
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "Connected to Google Api Service");
+ }
+ mResolvingError = false;
+ Wearable.NodeApi.addListener(mGoogleApiClient, this);
+ }
+
+ @Override
+ public void onConnectionSuspended(int cause) {
+ // Ignore
+ }
+
+ @Override
+ public void onConnectionFailed(ConnectionResult result) {
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "Disconnected from Google Api Service");
+ }
+ if (null != Wearable.NodeApi) {
+ Wearable.NodeApi.removeListener(mGoogleApiClient, this);
+ }
+ if (mResolvingError) {
+ // Already attempting to resolve an error.
+ return;
+ } else if (result.hasResolution()) {
+ try {
+ mResolvingError = true;
+ result.startResolutionForResult(this, REQUEST_RESOLVE_ERROR);
+ } catch (IntentSender.SendIntentException e) {
+ // There was an error with the resolution intent. Try again.
+ mGoogleApiClient.connect();
+ }
+ } else {
+ mResolvingError = false;
+ }
+ }
+}
diff --git a/samples/wearable/AgendaData/Application/src/main/res/drawable-hdpi/ic_launcher.png b/samples/wearable/AgendaData/Application/src/main/res/drawable-hdpi/ic_launcher.png
new file mode 100644
index 000000000..0564717bb
Binary files /dev/null and b/samples/wearable/AgendaData/Application/src/main/res/drawable-hdpi/ic_launcher.png differ
diff --git a/samples/wearable/AgendaData/Application/src/main/res/drawable-mdpi/ic_launcher.png b/samples/wearable/AgendaData/Application/src/main/res/drawable-mdpi/ic_launcher.png
new file mode 100644
index 000000000..0f4034743
Binary files /dev/null and b/samples/wearable/AgendaData/Application/src/main/res/drawable-mdpi/ic_launcher.png differ
diff --git a/samples/wearable/AgendaData/Application/src/main/res/drawable-nodpi/nobody.png b/samples/wearable/AgendaData/Application/src/main/res/drawable-nodpi/nobody.png
new file mode 100644
index 000000000..5a33d60e0
Binary files /dev/null and b/samples/wearable/AgendaData/Application/src/main/res/drawable-nodpi/nobody.png differ
diff --git a/samples/wearable/AgendaData/Application/src/main/res/drawable-xhdpi/ic_launcher.png b/samples/wearable/AgendaData/Application/src/main/res/drawable-xhdpi/ic_launcher.png
new file mode 100644
index 000000000..d7705cfb0
Binary files /dev/null and b/samples/wearable/AgendaData/Application/src/main/res/drawable-xhdpi/ic_launcher.png differ
diff --git a/samples/wearable/AgendaData/Application/src/main/res/drawable-xxhdpi/ic_launcher.png b/samples/wearable/AgendaData/Application/src/main/res/drawable-xxhdpi/ic_launcher.png
new file mode 100644
index 000000000..f07299fd2
Binary files /dev/null and b/samples/wearable/AgendaData/Application/src/main/res/drawable-xxhdpi/ic_launcher.png differ
diff --git a/samples/wearable/AgendaData/Application/src/main/res/layout/main.xml b/samples/wearable/AgendaData/Application/src/main/res/layout/main.xml
new file mode 100644
index 000000000..acd634024
--- /dev/null
+++ b/samples/wearable/AgendaData/Application/src/main/res/layout/main.xml
@@ -0,0 +1,43 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/wearable/AgendaData/Application/src/main/res/values/strings.xml b/samples/wearable/AgendaData/Application/src/main/res/values/strings.xml
new file mode 100644
index 000000000..423858e48
--- /dev/null
+++ b/samples/wearable/AgendaData/Application/src/main/res/values/strings.xml
@@ -0,0 +1,7 @@
+
+
+ Android Wear AgendaData Example Application
+ Sync calendar events to wearable
+ Delete calendar events from wearable
+ Log
+
diff --git a/samples/wearable/AgendaData/Application/src/main/res/values/styles.xml b/samples/wearable/AgendaData/Application/src/main/res/values/styles.xml
new file mode 100644
index 000000000..929c8f4aa
--- /dev/null
+++ b/samples/wearable/AgendaData/Application/src/main/res/values/styles.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
diff --git a/samples/wearable/AgendaData/Wearable/build.gradle b/samples/wearable/AgendaData/Wearable/build.gradle
new file mode 100644
index 000000000..a1921f0d5
--- /dev/null
+++ b/samples/wearable/AgendaData/Wearable/build.gradle
@@ -0,0 +1,26 @@
+apply plugin: 'android'
+
+android {
+ compileSdkVersion 20
+ buildToolsVersion '20'
+
+ defaultConfig {
+ minSdkVersion 20
+ targetSdkVersion 20
+ versionCode 1
+ versionName "1.0"
+ }
+
+ buildTypes {
+ release {
+ runProguard false
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
+ }
+ }
+}
+
+dependencies {
+ compile 'com.google.android.gms:play-services:5.+@aar'
+ compile "com.android.support:support-v4:20.0.+"
+ compile "com.google.android.support:wearable:1.0.+"
+}
\ No newline at end of file
diff --git a/samples/wearable/AgendaData/Wearable/proguard-rules.txt b/samples/wearable/AgendaData/Wearable/proguard-rules.txt
new file mode 100644
index 000000000..08e5bdc8d
--- /dev/null
+++ b/samples/wearable/AgendaData/Wearable/proguard-rules.txt
@@ -0,0 +1,22 @@
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
+-dontwarn android.support.wearable.view.DelayedConfirmationView
+-dontwarn android.support.wearable.view.CircledImageView
diff --git a/samples/wearable/AgendaData/Wearable/project.properties b/samples/wearable/AgendaData/Wearable/project.properties
new file mode 100644
index 000000000..4ab125693
--- /dev/null
+++ b/samples/wearable/AgendaData/Wearable/project.properties
@@ -0,0 +1,14 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system edit
+# "ant.properties", and override values to adapt the script to your
+# project structure.
+#
+# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
+#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
+
+# Project target.
+target=android-19
diff --git a/samples/wearable/AgendaData/Wearable/src/main/AndroidManifest.xml b/samples/wearable/AgendaData/Wearable/src/main/AndroidManifest.xml
new file mode 100644
index 000000000..f986b3aa3
--- /dev/null
+++ b/samples/wearable/AgendaData/Wearable/src/main/AndroidManifest.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/wearable/AgendaData/Wearable/src/main/java/com/example/android/wearable/agendadata/Constants.java b/samples/wearable/AgendaData/Wearable/src/main/java/com/example/android/wearable/agendadata/Constants.java
new file mode 100644
index 000000000..669a1a5d0
--- /dev/null
+++ b/samples/wearable/AgendaData/Wearable/src/main/java/com/example/android/wearable/agendadata/Constants.java
@@ -0,0 +1,19 @@
+package com.example.android.wearable.agendadata;
+
+/** Constants used in wearable app. */
+public final class Constants {
+
+ private Constants() {
+ }
+
+ public static final String TAG = "AgendaDataSample";
+
+ public static final String TITLE = "title";
+ public static final String DESCRIPTION = "description";
+ public static final String BEGIN = "begin";
+ public static final String END = "end";
+ public static final String ALL_DAY = "all_day";
+ public static final String PROFILE_PIC = "profile_pic";
+
+ public static final String EXTRA_SILENT = "silent";
+}
diff --git a/samples/wearable/AgendaData/Wearable/src/main/java/com/example/android/wearable/agendadata/DeleteService.java b/samples/wearable/AgendaData/Wearable/src/main/java/com/example/android/wearable/agendadata/DeleteService.java
new file mode 100644
index 000000000..906c0eeed
--- /dev/null
+++ b/samples/wearable/AgendaData/Wearable/src/main/java/com/example/android/wearable/agendadata/DeleteService.java
@@ -0,0 +1,102 @@
+package com.example.android.wearable.agendadata;
+
+import static com.example.android.wearable.agendadata.Constants.TAG;
+import static com.example.android.wearable.agendadata.Constants.EXTRA_SILENT;
+
+import android.app.IntentService;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Bundle;
+import android.support.wearable.activity.ConfirmationActivity;
+import android.util.Log;
+
+import com.google.android.gms.common.ConnectionResult;
+import com.google.android.gms.common.api.GoogleApiClient;
+import com.google.android.gms.wearable.DataApi;
+import com.google.android.gms.wearable.Wearable;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Handles "Delete" button on calendar event card.
+ */
+public class DeleteService extends IntentService implements GoogleApiClient.ConnectionCallbacks,
+ GoogleApiClient.OnConnectionFailedListener {
+
+ /* Timeout for making a connection to GoogleApiClient (in milliseconds) */
+ private static final long TIME_OUT = 100;
+
+ private GoogleApiClient mGoogleApiClient;
+
+ public DeleteService() {
+ super(DeleteService.class.getSimpleName());
+ }
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ mGoogleApiClient = new GoogleApiClient.Builder(this)
+ .addApi(Wearable.API)
+ .addConnectionCallbacks(this)
+ .addOnConnectionFailedListener(this)
+ .build();
+ }
+
+ @Override
+ protected void onHandleIntent(Intent intent) {
+ mGoogleApiClient.blockingConnect(TIME_OUT, TimeUnit.MILLISECONDS);
+ Uri dataItemUri = intent.getData();
+ if (Log.isLoggable(TAG, Log.VERBOSE)) {
+ Log.v(TAG, "DeleteService.onHandleIntent=" + dataItemUri);
+ }
+ if (mGoogleApiClient.isConnected()) {
+ DataApi.DeleteDataItemsResult result = Wearable.DataApi
+ .deleteDataItems(mGoogleApiClient, dataItemUri).await();
+ if (result.getStatus().isSuccess() && !intent.getBooleanExtra(EXTRA_SILENT, false)) {
+ // Show the success animation on the watch unless Silent extra is true.
+ startConfirmationActivity(ConfirmationActivity.SUCCESS_ANIMATION,
+ getString(R.string.delete_successful));
+ } else {
+ if (Log.isLoggable(TAG, Log.VERBOSE)) {
+ Log.v(TAG, "DeleteService.onHandleIntent: Failed to delete dataItem:"
+ + dataItemUri);
+ }
+ // Show the failure animation on the watch unless Silent extra is true.
+ if (!intent.getBooleanExtra(EXTRA_SILENT, false)) {
+ startConfirmationActivity(ConfirmationActivity.FAILURE_ANIMATION,
+ getString(R.string.delete_unsuccessful));
+ }
+ }
+ } else {
+ Log.e(TAG, "Failed to delete data item: " + dataItemUri
+ + " - Client disconnected from Google Play Services");
+ // Show the failure animation on the watch unless Silent extra is true.
+ if (!intent.getBooleanExtra(EXTRA_SILENT, false)) {
+ startConfirmationActivity(ConfirmationActivity.FAILURE_ANIMATION,
+ getString(R.string.delete_unsuccessful));
+ }
+ }
+ mGoogleApiClient.disconnect();
+ }
+
+ private void startConfirmationActivity(int animationType, String message) {
+ Intent confirmationActivity = new Intent(this, ConfirmationActivity.class)
+ .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION)
+ .putExtra(ConfirmationActivity.EXTRA_ANIMATION_TYPE, animationType)
+ .putExtra(ConfirmationActivity.EXTRA_MESSAGE, message);
+ startActivity(confirmationActivity);
+ }
+
+ @Override
+ public void onConnected(Bundle connectionHint) {
+ }
+
+ @Override
+ public void onConnectionSuspended(int cause) {
+ }
+
+ @Override
+ public void onConnectionFailed(ConnectionResult result) {
+ }
+
+}
\ No newline at end of file
diff --git a/samples/wearable/AgendaData/Wearable/src/main/java/com/example/android/wearable/agendadata/HomeListenerService.java b/samples/wearable/AgendaData/Wearable/src/main/java/com/example/android/wearable/agendadata/HomeListenerService.java
new file mode 100644
index 000000000..7e702f458
--- /dev/null
+++ b/samples/wearable/AgendaData/Wearable/src/main/java/com/example/android/wearable/agendadata/HomeListenerService.java
@@ -0,0 +1,164 @@
+package com.example.android.wearable.agendadata;
+
+import static com.example.android.wearable.agendadata.Constants.TAG;
+import static com.example.android.wearable.agendadata.Constants.EXTRA_SILENT;
+
+import static com.example.android.wearable.agendadata.Constants.ALL_DAY;
+import static com.example.android.wearable.agendadata.Constants.BEGIN;
+import static com.example.android.wearable.agendadata.Constants.DESCRIPTION;
+import static com.example.android.wearable.agendadata.Constants.END;
+import static com.example.android.wearable.agendadata.Constants.PROFILE_PIC;
+import static com.example.android.wearable.agendadata.Constants.TITLE;
+
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.content.Intent;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.net.Uri;
+import android.text.TextUtils;
+import android.text.format.DateFormat;
+import android.util.Log;
+
+import com.google.android.gms.common.api.GoogleApiClient;
+import com.google.android.gms.wearable.Asset;
+import com.google.android.gms.wearable.DataApi;
+import com.google.android.gms.wearable.DataEvent;
+import com.google.android.gms.wearable.DataEventBuffer;
+import com.google.android.gms.wearable.DataItem;
+import com.google.android.gms.wearable.DataMap;
+import com.google.android.gms.wearable.DataMapItem;
+import com.google.android.gms.wearable.MessageEvent;
+import com.google.android.gms.wearable.Wearable;
+import com.google.android.gms.wearable.WearableListenerService;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Listens to DataItem events on the home device.
+ */
+public class HomeListenerService extends WearableListenerService {
+
+ private static final Map sNotificationIdByDataItemUri =
+ new HashMap();
+ private static int sNotificationId = 1;
+ private GoogleApiClient mGoogleApiClient;
+
+ @Override
+ public void onDataChanged(DataEventBuffer dataEvents) {
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "onDataChanged: " + dataEvents + " for " + getPackageName());
+ }
+ for (DataEvent event : dataEvents) {
+ if (event.getType() == DataEvent.TYPE_DELETED) {
+ deleteDataItem(event.getDataItem());
+ } else if (event.getType() == DataEvent.TYPE_CHANGED) {
+ UpdateNotificationForDataItem(event.getDataItem());
+ }
+ }
+ dataEvents.close();
+ }
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ mGoogleApiClient = new GoogleApiClient.Builder(this.getApplicationContext())
+ .addApi(Wearable.API)
+ .build();
+ mGoogleApiClient.connect();
+ }
+
+ /**
+ * Posts a local notification to show calendar card.
+ */
+ private void UpdateNotificationForDataItem(DataItem dataItem) {
+ DataMapItem mapDataItem = DataMapItem.fromDataItem(dataItem);
+ DataMap data = mapDataItem.getDataMap();
+
+ String description = data.getString(DESCRIPTION);
+ if (TextUtils.isEmpty(description)) {
+ description = "";
+ } else {
+ // Add a space between the description and the time of the event.
+ description += " ";
+ }
+ String contentText;
+ if (data.getBoolean(ALL_DAY)) {
+ contentText = getString(R.string.desc_all_day, description);
+ } else {
+ String startTime = DateFormat.getTimeFormat(this).format(new Date(data.getLong(BEGIN)));
+ String endTime = DateFormat.getTimeFormat(this).format(new Date(data.getLong(END)));
+ contentText = getString(R.string.desc_time_period, description, startTime, endTime);
+ }
+
+ Intent deleteOperation = new Intent(this, DeleteService.class);
+ // Use a unique identifier for the delete action.
+ String deleteAction = "action_delete" + dataItem.getUri().toString() + sNotificationId;
+ deleteOperation.setAction(deleteAction);
+ deleteOperation.setData(dataItem.getUri());
+ PendingIntent deleteIntent = PendingIntent.getService(this, 0, deleteOperation,
+ PendingIntent.FLAG_ONE_SHOT);
+ PendingIntent silentDeleteIntent = PendingIntent.getService(this, 1,
+ deleteOperation.putExtra(EXTRA_SILENT, true), PendingIntent.FLAG_ONE_SHOT);
+
+ Notification.Builder notificationBuilder = new Notification.Builder(this)
+ .setContentTitle(data.getString(TITLE))
+ .setContentText(contentText)
+ .setSmallIcon(R.drawable.ic_launcher)
+ .addAction(R.drawable.ic_menu_delete, getText(R.string.delete), deleteIntent)
+ .setDeleteIntent(silentDeleteIntent) // Delete DataItem if notification dismissed.
+ .setLocalOnly(true)
+ .setPriority(Notification.PRIORITY_MIN);
+
+ // Set the event owner's profile picture as the notification background.
+ Asset asset = data.getAsset(PROFILE_PIC);
+ if (null != asset) {
+ if (mGoogleApiClient.isConnected()) {
+ DataApi.GetFdForAssetResult assetFdResult =
+ Wearable.DataApi.getFdForAsset(mGoogleApiClient, asset).await();
+ if (assetFdResult.getStatus().isSuccess()) {
+ Bitmap profilePic = BitmapFactory.decodeStream(assetFdResult.getInputStream());
+ notificationBuilder.extend(new Notification.WearableExtender()
+ .setBackground(profilePic));
+ } else if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "asset fetch failed with statusCode: "
+ + assetFdResult.getStatus().getStatusCode());
+ }
+ } else {
+ Log.e(TAG, "Failed to set notification background"
+ + " - Client disconnected from Google Play Services");
+ }
+ }
+ Notification card = notificationBuilder.build();
+
+ ((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
+ .notify(sNotificationId, card);
+
+ sNotificationIdByDataItemUri.put(dataItem.getUri(), sNotificationId++);
+ }
+
+ /**
+ * Deletes the calendar card associated with the data item.
+ */
+ private void deleteDataItem(DataItem dataItem) {
+ if (Log.isLoggable(TAG, Log.VERBOSE)) {
+ Log.v(TAG, "onDataItemDeleted:DataItem=" + dataItem.getUri());
+ }
+ Integer notificationId = sNotificationIdByDataItemUri.remove(dataItem.getUri());
+ if (notificationId != null) {
+ ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).cancel(notificationId);
+ }
+ }
+
+ @Override
+ public void onMessageReceived(MessageEvent messageEvent) {
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "onMessageReceived: " + messageEvent.getPath()
+ + " " + messageEvent.getData() + " for " + getPackageName());
+ }
+ }
+
+}
diff --git a/samples/wearable/AgendaData/Wearable/src/main/res/drawable-hdpi/ic_launcher.png b/samples/wearable/AgendaData/Wearable/src/main/res/drawable-hdpi/ic_launcher.png
new file mode 100644
index 000000000..0564717bb
Binary files /dev/null and b/samples/wearable/AgendaData/Wearable/src/main/res/drawable-hdpi/ic_launcher.png differ
diff --git a/samples/wearable/AgendaData/Wearable/src/main/res/drawable-hdpi/ic_menu_delete.png b/samples/wearable/AgendaData/Wearable/src/main/res/drawable-hdpi/ic_menu_delete.png
new file mode 100644
index 000000000..24d8f6a4b
Binary files /dev/null and b/samples/wearable/AgendaData/Wearable/src/main/res/drawable-hdpi/ic_menu_delete.png differ
diff --git a/samples/wearable/AgendaData/Wearable/src/main/res/drawable-mdpi/ic_launcher.png b/samples/wearable/AgendaData/Wearable/src/main/res/drawable-mdpi/ic_launcher.png
new file mode 100644
index 000000000..0f4034743
Binary files /dev/null and b/samples/wearable/AgendaData/Wearable/src/main/res/drawable-mdpi/ic_launcher.png differ
diff --git a/samples/wearable/AgendaData/Wearable/src/main/res/drawable-mdpi/ic_menu_delete.png b/samples/wearable/AgendaData/Wearable/src/main/res/drawable-mdpi/ic_menu_delete.png
new file mode 100644
index 000000000..e2c8700c3
Binary files /dev/null and b/samples/wearable/AgendaData/Wearable/src/main/res/drawable-mdpi/ic_menu_delete.png differ
diff --git a/samples/wearable/AgendaData/Wearable/src/main/res/drawable-xhdpi/ic_launcher.png b/samples/wearable/AgendaData/Wearable/src/main/res/drawable-xhdpi/ic_launcher.png
new file mode 100644
index 000000000..d7705cfb0
Binary files /dev/null and b/samples/wearable/AgendaData/Wearable/src/main/res/drawable-xhdpi/ic_launcher.png differ
diff --git a/samples/wearable/AgendaData/Wearable/src/main/res/drawable-xhdpi/ic_menu_delete.png b/samples/wearable/AgendaData/Wearable/src/main/res/drawable-xhdpi/ic_menu_delete.png
new file mode 100644
index 000000000..65b9caed1
Binary files /dev/null and b/samples/wearable/AgendaData/Wearable/src/main/res/drawable-xhdpi/ic_menu_delete.png differ
diff --git a/samples/wearable/AgendaData/Wearable/src/main/res/drawable-xxhdpi/ic_launcher.png b/samples/wearable/AgendaData/Wearable/src/main/res/drawable-xxhdpi/ic_launcher.png
new file mode 100644
index 000000000..f07299fd2
Binary files /dev/null and b/samples/wearable/AgendaData/Wearable/src/main/res/drawable-xxhdpi/ic_launcher.png differ
diff --git a/samples/wearable/AgendaData/Wearable/src/main/res/drawable-xxhdpi/ic_menu_delete.png b/samples/wearable/AgendaData/Wearable/src/main/res/drawable-xxhdpi/ic_menu_delete.png
new file mode 100644
index 000000000..8e9e78d43
Binary files /dev/null and b/samples/wearable/AgendaData/Wearable/src/main/res/drawable-xxhdpi/ic_menu_delete.png differ
diff --git a/samples/wearable/AgendaData/Wearable/src/main/res/values/strings.xml b/samples/wearable/AgendaData/Wearable/src/main/res/values/strings.xml
new file mode 100644
index 000000000..a4b3dcd86
--- /dev/null
+++ b/samples/wearable/AgendaData/Wearable/src/main/res/values/strings.xml
@@ -0,0 +1,9 @@
+
+
+ Android Wear AgendaData Example Application
+ Delete
+ %s(All day)
+ %1$s(%2$s - %3$s)
+ Event deleted
+ Unable to delete event
+
diff --git a/samples/wearable/AgendaData/build.gradle b/samples/wearable/AgendaData/build.gradle
new file mode 100644
index 000000000..07be865b5
--- /dev/null
+++ b/samples/wearable/AgendaData/build.gradle
@@ -0,0 +1,14 @@
+buildscript {
+ repositories {
+ mavenCentral()
+ }
+ dependencies {
+ classpath 'com.android.tools.build:gradle:0.11.+'
+ }
+}
+
+allprojects {
+ repositories {
+ mavenCentral()
+ }
+}
\ No newline at end of file
diff --git a/samples/wearable/AgendaData/gradle.properties b/samples/wearable/AgendaData/gradle.properties
new file mode 100644
index 000000000..5d08ba75b
--- /dev/null
+++ b/samples/wearable/AgendaData/gradle.properties
@@ -0,0 +1,18 @@
+# Project-wide Gradle settings.
+
+# IDE (e.g. Android Studio) users:
+# Settings specified in this file will override any Gradle settings
+# configured through the IDE.
+
+# For more details on how to configure your build environment visit
+# http://www.gradle.org/docs/current/userguide/build_environment.html
+
+# Specifies the JVM arguments used for the daemon process.
+# The setting is particularly useful for tweaking memory settings.
+# Default value: -Xmx10248m -XX:MaxPermSize=256m
+# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
+
+# When configured, Gradle will run in incubating parallel mode.
+# This option should only be used with decoupled projects. More details, visit
+# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
+# org.gradle.parallel=true
\ No newline at end of file
diff --git a/samples/wearable/AgendaData/gradle/wrapper/gradle-wrapper.jar b/samples/wearable/AgendaData/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 000000000..583859812
Binary files /dev/null and b/samples/wearable/AgendaData/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/samples/wearable/AgendaData/gradle/wrapper/gradle-wrapper.properties b/samples/wearable/AgendaData/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 000000000..e83e46081
--- /dev/null
+++ b/samples/wearable/AgendaData/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Fri Mar 14 14:02:22 PDT 2014
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-all.zip
diff --git a/samples/wearable/AgendaData/gradlew b/samples/wearable/AgendaData/gradlew
new file mode 100755
index 000000000..91a7e269e
--- /dev/null
+++ b/samples/wearable/AgendaData/gradlew
@@ -0,0 +1,164 @@
+#!/usr/bin/env bash
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+ echo "$*"
+}
+
+die ( ) {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+esac
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched.
+if $cygwin ; then
+ [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+fi
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >&-
+APP_HOME="`pwd -P`"
+cd "$SAVED" >&-
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+ JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
diff --git a/samples/wearable/AgendaData/gradlew.bat b/samples/wearable/AgendaData/gradlew.bat
new file mode 100644
index 000000000..aec99730b
--- /dev/null
+++ b/samples/wearable/AgendaData/gradlew.bat
@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windowz variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%@eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/samples/wearable/AgendaData/settings.gradle b/samples/wearable/AgendaData/settings.gradle
new file mode 100644
index 000000000..f3f25a547
--- /dev/null
+++ b/samples/wearable/AgendaData/settings.gradle
@@ -0,0 +1 @@
+include 'Wearable', 'Application'
diff --git a/samples/wearable/DataLayer/Application/build.gradle b/samples/wearable/DataLayer/Application/build.gradle
new file mode 100644
index 000000000..9568da46f
--- /dev/null
+++ b/samples/wearable/DataLayer/Application/build.gradle
@@ -0,0 +1,30 @@
+apply plugin: 'android'
+
+android {
+ compileSdkVersion 19
+ buildToolsVersion '20'
+
+ defaultConfig {
+ minSdkVersion 18
+ targetSdkVersion 19
+ versionCode 1
+ versionName "1.0"
+ }
+
+ buildTypes {
+ release {
+ runProguard false
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
+ }
+ }
+
+ aaptOptions {
+ noCompress 'apk'
+ }
+}
+
+dependencies {
+ compile 'com.google.android.gms:play-services:5.0.+@aar'
+ compile "com.android.support:support-v4:20.0.+"
+ wearApp project(':Wearable')
+}
\ No newline at end of file
diff --git a/samples/wearable/DataLayer/Application/proguard-rules.txt b/samples/wearable/DataLayer/Application/proguard-rules.txt
new file mode 100644
index 000000000..f2fe1559a
--- /dev/null
+++ b/samples/wearable/DataLayer/Application/proguard-rules.txt
@@ -0,0 +1,20 @@
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
diff --git a/samples/wearable/DataLayer/Application/src/main/AndroidManifest.xml b/samples/wearable/DataLayer/Application/src/main/AndroidManifest.xml
new file mode 100644
index 000000000..12a18f05d
--- /dev/null
+++ b/samples/wearable/DataLayer/Application/src/main/AndroidManifest.xml
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/wearable/DataLayer/Application/src/main/java/com/example/android/wearable/datalayer/MainActivity.java b/samples/wearable/DataLayer/Application/src/main/java/com/example/android/wearable/datalayer/MainActivity.java
new file mode 100644
index 000000000..4a960ae45
--- /dev/null
+++ b/samples/wearable/DataLayer/Application/src/main/java/com/example/android/wearable/datalayer/MainActivity.java
@@ -0,0 +1,468 @@
+package com.example.android.wearable.datalayer;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentSender;
+import android.content.pm.PackageManager;
+import android.graphics.Bitmap;
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.os.Handler;
+import android.provider.MediaStore;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.ImageView;
+import android.widget.ListView;
+import android.widget.TextView;
+
+import com.google.android.gms.common.ConnectionResult;
+import com.google.android.gms.common.api.ResultCallback;
+import com.google.android.gms.common.api.GoogleApiClient;
+import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
+import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
+import com.google.android.gms.common.data.FreezableUtils;
+import com.google.android.gms.wearable.Asset;
+import com.google.android.gms.wearable.DataApi.DataItemResult;
+import com.google.android.gms.wearable.DataEvent;
+import com.google.android.gms.wearable.DataEventBuffer;
+import com.google.android.gms.wearable.MessageApi.SendMessageResult;
+import com.google.android.gms.wearable.DataApi;
+import com.google.android.gms.wearable.MessageApi;
+import com.google.android.gms.wearable.MessageEvent;
+import com.google.android.gms.wearable.Node;
+import com.google.android.gms.wearable.NodeApi;
+import com.google.android.gms.wearable.PutDataMapRequest;
+import com.google.android.gms.wearable.PutDataRequest;
+import com.google.android.gms.wearable.Wearable;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Receives its own events using a listener API designed for foreground activities. Updates a data
+ * item every second while it is open. Also allows user to take a photo and send that as an asset to
+ * the paired wearable.
+ */
+public class MainActivity extends Activity implements DataApi.DataListener,
+ MessageApi.MessageListener, NodeApi.NodeListener, ConnectionCallbacks,
+ OnConnectionFailedListener {
+
+ private static final String TAG = "MainActivity";
+
+ /** Request code for launching the Intent to resolve Google Play services errors. */
+ private static final int REQUEST_RESOLVE_ERROR = 1000;
+
+ private static final String START_ACTIVITY_PATH = "/start-activity";
+ private static final String COUNT_PATH = "/count";
+ private static final String IMAGE_PATH = "/image";
+ private static final String IMAGE_KEY = "photo";
+ private static final String COUNT_KEY = "count";
+
+ private GoogleApiClient mGoogleApiClient;
+ private boolean mResolvingError = false;
+ private boolean mCameraSupported = false;
+
+ private ListView mDataItemList;
+ private Button mTakePhotoBtn;
+ private Button mSendPhotoBtn;
+ private ImageView mThumbView;
+ private Bitmap mImageBitmap;
+ private View mStartActivityBtn;
+
+ private DataItemAdapter mDataItemListAdapter;
+ private Handler mHandler;
+
+ // Send DataItems.
+ private ScheduledExecutorService mGeneratorExecutor;
+ private ScheduledFuture> mDataItemGeneratorFuture;
+
+ static final int REQUEST_IMAGE_CAPTURE = 1;
+
+ @Override
+ public void onCreate(Bundle b) {
+ super.onCreate(b);
+ mHandler = new Handler();
+ LOGD(TAG, "onCreate");
+ mCameraSupported = getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA);
+ setContentView(R.layout.main_activity);
+ setupViews();
+
+ // Stores DataItems received by the local broadcaster or from the paired watch.
+ mDataItemListAdapter = new DataItemAdapter(this, android.R.layout.simple_list_item_1);
+ mDataItemList.setAdapter(mDataItemListAdapter);
+
+ mGeneratorExecutor = new ScheduledThreadPoolExecutor(1);
+
+ mGoogleApiClient = new GoogleApiClient.Builder(this)
+ .addApi(Wearable.API)
+ .addConnectionCallbacks(this)
+ .addOnConnectionFailedListener(this)
+ .build();
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
+ Bundle extras = data.getExtras();
+ mImageBitmap = (Bitmap) extras.get("data");
+ mThumbView.setImageBitmap(mImageBitmap);
+ }
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ if (!mResolvingError) {
+ mGoogleApiClient.connect();
+ }
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ mDataItemGeneratorFuture = mGeneratorExecutor.scheduleWithFixedDelay(
+ new DataItemGenerator(), 1, 5, TimeUnit.SECONDS);
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ mDataItemGeneratorFuture.cancel(true /* mayInterruptIfRunning */);
+ }
+
+ @Override
+ protected void onStop() {
+ if (!mResolvingError) {
+ Wearable.DataApi.removeListener(mGoogleApiClient, this);
+ Wearable.MessageApi.removeListener(mGoogleApiClient, this);
+ Wearable.NodeApi.removeListener(mGoogleApiClient, this);
+ mGoogleApiClient.disconnect();
+ }
+ super.onStop();
+ }
+
+ @Override //ConnectionCallbacks
+ public void onConnected(Bundle connectionHint) {
+ LOGD(TAG, "Google API Client was connected");
+ mResolvingError = false;
+ mStartActivityBtn.setEnabled(true);
+ mSendPhotoBtn.setEnabled(mCameraSupported);
+ Wearable.DataApi.addListener(mGoogleApiClient, this);
+ Wearable.MessageApi.addListener(mGoogleApiClient, this);
+ Wearable.NodeApi.addListener(mGoogleApiClient, this);
+ }
+
+ @Override //ConnectionCallbacks
+ public void onConnectionSuspended(int cause) {
+ LOGD(TAG, "Connection to Google API client was suspended");
+ mStartActivityBtn.setEnabled(false);
+ mSendPhotoBtn.setEnabled(false);
+ }
+
+ @Override //OnConnectionFailedListener
+ public void onConnectionFailed(ConnectionResult result) {
+ if (mResolvingError) {
+ // Already attempting to resolve an error.
+ return;
+ } else if (result.hasResolution()) {
+ try {
+ mResolvingError = true;
+ result.startResolutionForResult(this, REQUEST_RESOLVE_ERROR);
+ } catch (IntentSender.SendIntentException e) {
+ // There was an error with the resolution intent. Try again.
+ mGoogleApiClient.connect();
+ }
+ } else {
+ Log.e(TAG, "Connection to Google API client has failed");
+ mResolvingError = false;
+ mStartActivityBtn.setEnabled(false);
+ mSendPhotoBtn.setEnabled(false);
+ Wearable.DataApi.removeListener(mGoogleApiClient, this);
+ Wearable.MessageApi.removeListener(mGoogleApiClient, this);
+ Wearable.NodeApi.removeListener(mGoogleApiClient, this);
+ }
+ }
+
+ @Override //DataListener
+ public void onDataChanged(DataEventBuffer dataEvents) {
+ LOGD(TAG, "onDataChanged: " + dataEvents);
+ final List events = FreezableUtils.freezeIterable(dataEvents);
+ dataEvents.close();
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ for (DataEvent event : events) {
+ if (event.getType() == DataEvent.TYPE_CHANGED) {
+ mDataItemListAdapter.add(
+ new Event("DataItem Changed", event.getDataItem().toString()));
+ } else if (event.getType() == DataEvent.TYPE_DELETED) {
+ mDataItemListAdapter.add(
+ new Event("DataItem Deleted", event.getDataItem().toString()));
+ }
+ }
+ }
+ });
+ }
+
+ @Override //MessageListener
+ public void onMessageReceived(final MessageEvent messageEvent) {
+ LOGD(TAG, "onMessageReceived() A message from watch was received:" + messageEvent
+ .getRequestId() + " " + messageEvent.getPath());
+ mHandler.post(new Runnable() {
+ @Override
+ public void run() {
+ mDataItemListAdapter.add(new Event("Message from watch", messageEvent.toString()));
+ }
+ });
+
+ }
+
+ @Override //NodeListener
+ public void onPeerConnected(final Node peer) {
+ LOGD(TAG, "onPeerConnected: " + peer);
+ mHandler.post(new Runnable() {
+ @Override
+ public void run() {
+ mDataItemListAdapter.add(new Event("Connected", peer.toString()));
+ }
+ });
+
+ }
+
+ @Override //NodeListener
+ public void onPeerDisconnected(final Node peer) {
+ LOGD(TAG, "onPeerDisconnected: " + peer);
+ mHandler.post(new Runnable() {
+ @Override
+ public void run() {
+ mDataItemListAdapter.add(new Event("Disconnected", peer.toString()));
+ }
+ });
+ }
+
+ /**
+ * A View Adapter for presenting the Event objects in a list
+ */
+ private static class DataItemAdapter extends ArrayAdapter {
+
+ private final Context mContext;
+
+ public DataItemAdapter(Context context, int unusedResource) {
+ super(context, unusedResource);
+ mContext = context;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ ViewHolder holder;
+ if (convertView == null) {
+ holder = new ViewHolder();
+ LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
+ Context.LAYOUT_INFLATER_SERVICE);
+ convertView = inflater.inflate(android.R.layout.two_line_list_item, null);
+ convertView.setTag(holder);
+ holder.text1 = (TextView) convertView.findViewById(android.R.id.text1);
+ holder.text2 = (TextView) convertView.findViewById(android.R.id.text2);
+ } else {
+ holder = (ViewHolder) convertView.getTag();
+ }
+ Event event = getItem(position);
+ holder.text1.setText(event.title);
+ holder.text2.setText(event.text);
+ return convertView;
+ }
+
+ private class ViewHolder {
+
+ TextView text1;
+ TextView text2;
+ }
+ }
+
+ private class Event {
+
+ String title;
+ String text;
+
+ public Event(String title, String text) {
+ this.title = title;
+ this.text = text;
+ }
+ }
+
+ private Collection getNodes() {
+ HashSet results = new HashSet();
+ NodeApi.GetConnectedNodesResult nodes =
+ Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).await();
+
+ for (Node node : nodes.getNodes()) {
+ results.add(node.getId());
+ }
+
+ return results;
+ }
+
+ private void sendStartActivityMessage(String node) {
+ Wearable.MessageApi.sendMessage(
+ mGoogleApiClient, node, START_ACTIVITY_PATH, new byte[0]).setResultCallback(
+ new ResultCallback() {
+ @Override
+ public void onResult(SendMessageResult sendMessageResult) {
+ if (!sendMessageResult.getStatus().isSuccess()) {
+ Log.e(TAG, "Failed to send message with status code: "
+ + sendMessageResult.getStatus().getStatusCode());
+ }
+ }
+ }
+ );
+ }
+
+ private class StartWearableActivityTask extends AsyncTask {
+
+ @Override
+ protected Void doInBackground(Void... args) {
+ Collection nodes = getNodes();
+ for (String node : nodes) {
+ sendStartActivityMessage(node);
+ }
+ return null;
+ }
+ }
+
+ /** Sends an RPC to start a fullscreen Activity on the wearable. */
+ public void onStartWearableActivityClick(View view) {
+ LOGD(TAG, "Generating RPC");
+
+ // Trigger an AsyncTask that will query for a list of connected nodes and send a
+ // "start-activity" message to each connected node.
+ new StartWearableActivityTask().execute();
+ }
+
+ /** Generates a DataItem based on an incrementing count. */
+ private class DataItemGenerator implements Runnable {
+
+ private int count = 0;
+
+ @Override
+ public void run() {
+ PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(COUNT_PATH);
+ putDataMapRequest.getDataMap().putInt(COUNT_KEY, count++);
+ PutDataRequest request = putDataMapRequest.asPutDataRequest();
+
+ LOGD(TAG, "Generating DataItem: " + request);
+ if (!mGoogleApiClient.isConnected()) {
+ return;
+ }
+ Wearable.DataApi.putDataItem(mGoogleApiClient, request)
+ .setResultCallback(new ResultCallback() {
+ @Override
+ public void onResult(DataItemResult dataItemResult) {
+ if (!dataItemResult.getStatus().isSuccess()) {
+ Log.e(TAG, "ERROR: failed to putDataItem, status code: "
+ + dataItemResult.getStatus().getStatusCode());
+ }
+ }
+ });
+ }
+ }
+
+ /**
+ * Dispatches an {@link android.content.Intent} to take a photo. Result will be returned back
+ * in onActivityResult().
+ */
+ private void dispatchTakePictureIntent() {
+ Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
+ if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
+ startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
+ }
+ }
+
+ /**
+ * Builds an {@link com.google.android.gms.wearable.Asset} from a bitmap. The image that we get
+ * back from the camera in "data" is a thumbnail size. Typically, your image should not exceed
+ * 320x320 and if you want to have zoom and parallax effect in your app, limit the size of your
+ * image to 640x400. Resize your image before transferring to your wearable device.
+ */
+ private static Asset toAsset(Bitmap bitmap) {
+ ByteArrayOutputStream byteStream = null;
+ try {
+ byteStream = new ByteArrayOutputStream();
+ bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteStream);
+ return Asset.createFromBytes(byteStream.toByteArray());
+ } finally {
+ if (null != byteStream) {
+ try {
+ byteStream.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ }
+ }
+
+ /**
+ * Sends the asset that was created form the photo we took by adding it to the Data Item store.
+ */
+ private void sendPhoto(Asset asset) {
+ PutDataMapRequest dataMap = PutDataMapRequest.create(IMAGE_PATH);
+ dataMap.getDataMap().putAsset(IMAGE_KEY, asset);
+ dataMap.getDataMap().putLong("time", new Date().getTime());
+ PutDataRequest request = dataMap.asPutDataRequest();
+ Wearable.DataApi.putDataItem(mGoogleApiClient, request)
+ .setResultCallback(new ResultCallback() {
+ @Override
+ public void onResult(DataItemResult dataItemResult) {
+ LOGD(TAG, "Sending image was successful: " + dataItemResult.getStatus()
+ .isSuccess());
+ }
+ });
+
+ }
+
+ public void onTakePhotoClick(View view) {
+ dispatchTakePictureIntent();
+ }
+
+ public void onSendPhotoClick(View view) {
+ if (null != mImageBitmap && mGoogleApiClient.isConnected()) {
+ sendPhoto(toAsset(mImageBitmap));
+ }
+ }
+
+ /**
+ * Sets up UI components and their callback handlers.
+ */
+ private void setupViews() {
+ mTakePhotoBtn = (Button) findViewById(R.id.takePhoto);
+ mSendPhotoBtn = (Button) findViewById(R.id.sendPhoto);
+
+ // Shows the image received from the handset
+ mThumbView = (ImageView) findViewById(R.id.imageView);
+ mDataItemList = (ListView) findViewById(R.id.data_item_list);
+
+ mStartActivityBtn = findViewById(R.id.start_wearable_activity);
+ }
+
+ /**
+ * As simple wrapper around Log.d
+ */
+ private static void LOGD(final String tag, String message) {
+ if (Log.isLoggable(tag, Log.DEBUG)) {
+ Log.d(tag, message);
+ }
+ }
+
+}
diff --git a/samples/wearable/DataLayer/Application/src/main/res/drawable-hdpi/ic_content_picture.png b/samples/wearable/DataLayer/Application/src/main/res/drawable-hdpi/ic_content_picture.png
new file mode 100644
index 000000000..597997ca3
Binary files /dev/null and b/samples/wearable/DataLayer/Application/src/main/res/drawable-hdpi/ic_content_picture.png differ
diff --git a/samples/wearable/DataLayer/Application/src/main/res/drawable-hdpi/ic_launcher.png b/samples/wearable/DataLayer/Application/src/main/res/drawable-hdpi/ic_launcher.png
new file mode 100755
index 000000000..589f229d1
Binary files /dev/null and b/samples/wearable/DataLayer/Application/src/main/res/drawable-hdpi/ic_launcher.png differ
diff --git a/samples/wearable/DataLayer/Application/src/main/res/drawable-mdpi/ic_content_picture.png b/samples/wearable/DataLayer/Application/src/main/res/drawable-mdpi/ic_content_picture.png
new file mode 100644
index 000000000..c23f4c039
Binary files /dev/null and b/samples/wearable/DataLayer/Application/src/main/res/drawable-mdpi/ic_content_picture.png differ
diff --git a/samples/wearable/DataLayer/Application/src/main/res/drawable-mdpi/ic_launcher.png b/samples/wearable/DataLayer/Application/src/main/res/drawable-mdpi/ic_launcher.png
new file mode 100755
index 000000000..77dd57139
Binary files /dev/null and b/samples/wearable/DataLayer/Application/src/main/res/drawable-mdpi/ic_launcher.png differ
diff --git a/samples/wearable/DataLayer/Application/src/main/res/drawable-xhdpi/ic_content_picture.png b/samples/wearable/DataLayer/Application/src/main/res/drawable-xhdpi/ic_content_picture.png
new file mode 100644
index 000000000..289adf11a
Binary files /dev/null and b/samples/wearable/DataLayer/Application/src/main/res/drawable-xhdpi/ic_content_picture.png differ
diff --git a/samples/wearable/DataLayer/Application/src/main/res/drawable-xhdpi/ic_launcher.png b/samples/wearable/DataLayer/Application/src/main/res/drawable-xhdpi/ic_launcher.png
new file mode 100755
index 000000000..fe34ebe13
Binary files /dev/null and b/samples/wearable/DataLayer/Application/src/main/res/drawable-xhdpi/ic_launcher.png differ
diff --git a/samples/wearable/DataLayer/Application/src/main/res/drawable-xxhdpi/ic_content_picture.png b/samples/wearable/DataLayer/Application/src/main/res/drawable-xxhdpi/ic_content_picture.png
new file mode 100644
index 000000000..073ad553e
Binary files /dev/null and b/samples/wearable/DataLayer/Application/src/main/res/drawable-xxhdpi/ic_content_picture.png differ
diff --git a/samples/wearable/DataLayer/Application/src/main/res/drawable-xxhdpi/ic_launcher.png b/samples/wearable/DataLayer/Application/src/main/res/drawable-xxhdpi/ic_launcher.png
new file mode 100755
index 000000000..ab80bcd13
Binary files /dev/null and b/samples/wearable/DataLayer/Application/src/main/res/drawable-xxhdpi/ic_launcher.png differ
diff --git a/samples/wearable/DataLayer/Application/src/main/res/drawable/divider.xml b/samples/wearable/DataLayer/Application/src/main/res/drawable/divider.xml
new file mode 100644
index 000000000..f9f182e91
--- /dev/null
+++ b/samples/wearable/DataLayer/Application/src/main/res/drawable/divider.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/samples/wearable/DataLayer/Application/src/main/res/layout/main_activity.xml b/samples/wearable/DataLayer/Application/src/main/res/layout/main_activity.xml
new file mode 100644
index 000000000..6f5dbfd0e
--- /dev/null
+++ b/samples/wearable/DataLayer/Application/src/main/res/layout/main_activity.xml
@@ -0,0 +1,72 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/samples/wearable/DataLayer/Application/src/main/res/values/strings.xml b/samples/wearable/DataLayer/Application/src/main/res/values/strings.xml
new file mode 100644
index 000000000..ae2aeab94
--- /dev/null
+++ b/samples/wearable/DataLayer/Application/src/main/res/values/strings.xml
@@ -0,0 +1,8 @@
+
+
+ Data Layer Sample App
+ Start Wearable Activity
+ Start
+ Take a Photo
+ Send Photo
+
diff --git a/samples/wearable/DataLayer/Application/src/main/res/values/style.xml b/samples/wearable/DataLayer/Application/src/main/res/values/style.xml
new file mode 100644
index 000000000..219aeb7dd
--- /dev/null
+++ b/samples/wearable/DataLayer/Application/src/main/res/values/style.xml
@@ -0,0 +1,8 @@
+
+
+
+
\ No newline at end of file
diff --git a/samples/wearable/DataLayer/Wearable/build.gradle b/samples/wearable/DataLayer/Wearable/build.gradle
new file mode 100644
index 000000000..9bf690c7b
--- /dev/null
+++ b/samples/wearable/DataLayer/Wearable/build.gradle
@@ -0,0 +1,25 @@
+apply plugin: 'android'
+
+android {
+ compileSdkVersion 19
+ buildToolsVersion '20'
+
+ defaultConfig {
+ minSdkVersion 19
+ targetSdkVersion 19
+ versionCode 1
+ versionName "1.0"
+ }
+
+ buildTypes {
+ release {
+ runProguard false
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
+ }
+ }
+}
+
+dependencies {
+ compile 'com.google.android.gms:play-services:5.0.+@aar'
+ compile "com.android.support:support-v13:20.0.+"
+}
\ No newline at end of file
diff --git a/samples/wearable/DataLayer/Wearable/proguard-rules.txt b/samples/wearable/DataLayer/Wearable/proguard-rules.txt
new file mode 100644
index 000000000..f2fe1559a
--- /dev/null
+++ b/samples/wearable/DataLayer/Wearable/proguard-rules.txt
@@ -0,0 +1,20 @@
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
diff --git a/samples/wearable/DataLayer/Wearable/src/main/AndroidManifest.xml b/samples/wearable/DataLayer/Wearable/src/main/AndroidManifest.xml
new file mode 100644
index 000000000..52aeb743e
--- /dev/null
+++ b/samples/wearable/DataLayer/Wearable/src/main/AndroidManifest.xml
@@ -0,0 +1,38 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/wearable/DataLayer/Wearable/src/main/java/com/example/android/wearable/datalayer/DataLayerListenerService.java b/samples/wearable/DataLayer/Wearable/src/main/java/com/example/android/wearable/datalayer/DataLayerListenerService.java
new file mode 100644
index 000000000..d82cb7eb4
--- /dev/null
+++ b/samples/wearable/DataLayer/Wearable/src/main/java/com/example/android/wearable/datalayer/DataLayerListenerService.java
@@ -0,0 +1,104 @@
+package com.example.android.wearable.datalayer;
+
+import android.content.Intent;
+import android.net.Uri;
+import android.util.Log;
+
+import com.google.android.gms.common.ConnectionResult;
+import com.google.android.gms.common.api.GoogleApiClient;
+import com.google.android.gms.common.data.FreezableUtils;
+import com.google.android.gms.wearable.DataEvent;
+import com.google.android.gms.wearable.DataEventBuffer;
+import com.google.android.gms.wearable.MessageEvent;
+import com.google.android.gms.wearable.Node;
+import com.google.android.gms.wearable.Wearable;
+import com.google.android.gms.wearable.WearableListenerService;
+
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Listens to DataItems and Messages from the local node.
+ */
+public class DataLayerListenerService extends WearableListenerService {
+
+ private static final String TAG = "DataLayerListenerServic";
+
+ private static final String START_ACTIVITY_PATH = "/start-activity";
+ private static final String DATA_ITEM_RECEIVED_PATH = "/data-item-received";
+ public static final String COUNT_PATH = "/count";
+ public static final String IMAGE_PATH = "/image";
+ public static final String IMAGE_KEY = "photo";
+ private static final String COUNT_KEY = "count";
+ private static final int MAX_LOG_TAG_LENGTH = 23;
+ GoogleApiClient mGoogleApiClient;
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ mGoogleApiClient = new GoogleApiClient.Builder(this)
+ .addApi(Wearable.API)
+ .build();
+ mGoogleApiClient.connect();
+ }
+
+ @Override
+ public void onDataChanged(DataEventBuffer dataEvents) {
+ LOGD(TAG, "onDataChanged: " + dataEvents);
+ final List events = FreezableUtils.freezeIterable(dataEvents);
+ dataEvents.close();
+ if(!mGoogleApiClient.isConnected()) {
+ ConnectionResult connectionResult = mGoogleApiClient
+ .blockingConnect(30, TimeUnit.SECONDS);
+ if (!connectionResult.isSuccess()) {
+ Log.e(TAG, "DataLayerListenerService failed to connect to GoogleApiClient.");
+ return;
+ }
+ }
+
+ // Loop through the events and send a message back to the node that created the data item.
+ for (DataEvent event : events) {
+ Uri uri = event.getDataItem().getUri();
+ String path = uri.getPath();
+ if (COUNT_PATH.equals(path)) {
+ // Get the node id of the node that created the data item from the host portion of
+ // the uri.
+ String nodeId = uri.getHost();
+ // Set the data of the message to be the bytes of the Uri.
+ byte[] payload = uri.toString().getBytes();
+
+ // Send the rpc
+ Wearable.MessageApi.sendMessage(mGoogleApiClient, nodeId, DATA_ITEM_RECEIVED_PATH,
+ payload);
+ }
+ }
+ }
+
+ @Override
+ public void onMessageReceived(MessageEvent messageEvent) {
+ LOGD(TAG, "onMessageReceived: " + messageEvent);
+
+ // Check to see if the message is to start an activity
+ if (messageEvent.getPath().equals(START_ACTIVITY_PATH)) {
+ Intent startIntent = new Intent(this, MainActivity.class);
+ startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ startActivity(startIntent);
+ }
+ }
+
+ @Override
+ public void onPeerConnected(Node peer) {
+ LOGD(TAG, "onPeerConnected: " + peer);
+ }
+
+ @Override
+ public void onPeerDisconnected(Node peer) {
+ LOGD(TAG, "onPeerDisconnected: " + peer);
+ }
+
+ public static void LOGD(final String tag, String message) {
+ if (Log.isLoggable(tag, Log.DEBUG)) {
+ Log.d(tag, message);
+ }
+ }
+}
diff --git a/samples/wearable/DataLayer/Wearable/src/main/java/com/example/android/wearable/datalayer/MainActivity.java b/samples/wearable/DataLayer/Wearable/src/main/java/com/example/android/wearable/datalayer/MainActivity.java
new file mode 100644
index 000000000..d9faa8df6
--- /dev/null
+++ b/samples/wearable/DataLayer/Wearable/src/main/java/com/example/android/wearable/datalayer/MainActivity.java
@@ -0,0 +1,239 @@
+package com.example.android.wearable.datalayer;
+
+import static com.example.android.wearable.datalayer.DataLayerListenerService.LOGD;
+
+import android.app.Activity;
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.drawable.BitmapDrawable;
+import android.os.Bundle;
+import android.os.Handler;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.WindowManager;
+import android.widget.ArrayAdapter;
+import android.widget.ListView;
+import android.widget.TextView;
+
+import com.google.android.gms.common.ConnectionResult;
+import com.google.android.gms.common.api.GoogleApiClient;
+import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
+import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
+import com.google.android.gms.common.data.FreezableUtils;
+import com.google.android.gms.wearable.Asset;
+import com.google.android.gms.wearable.DataApi;
+import com.google.android.gms.wearable.DataEvent;
+import com.google.android.gms.wearable.DataEventBuffer;
+import com.google.android.gms.wearable.DataMapItem;
+import com.google.android.gms.wearable.MessageApi;
+import com.google.android.gms.wearable.MessageEvent;
+import com.google.android.gms.wearable.Node;
+import com.google.android.gms.wearable.NodeApi;
+import com.google.android.gms.wearable.Wearable;
+
+import java.io.InputStream;
+import java.util.List;
+
+/**
+ * Shows events and photo from the Wearable APIs.
+ */
+public class MainActivity extends Activity implements ConnectionCallbacks,
+ OnConnectionFailedListener, DataApi.DataListener, MessageApi.MessageListener,
+ NodeApi.NodeListener {
+
+ private static final String TAG = "MainActivity";
+
+ private GoogleApiClient mGoogleApiClient;
+ private ListView mDataItemList;
+ private TextView mIntroText;
+ private DataItemAdapter mDataItemListAdapter;
+ private View mLayout;
+ private Handler mHandler;
+
+ @Override
+ public void onCreate(Bundle b) {
+ super.onCreate(b);
+ mHandler = new Handler();
+ LOGD(TAG, "onCreate");
+ setContentView(R.layout.main_activity);
+ getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
+ mDataItemList = (ListView) findViewById(R.id.dataItem_list);
+ mIntroText = (TextView) findViewById(R.id.intro);
+ mLayout = findViewById(R.id.layout);
+
+ // Stores data events received by the local broadcaster.
+ mDataItemListAdapter = new DataItemAdapter(this, android.R.layout.simple_list_item_1);
+ mDataItemList.setAdapter(mDataItemListAdapter);
+
+ mGoogleApiClient = new GoogleApiClient.Builder(this)
+ .addApi(Wearable.API)
+ .addConnectionCallbacks(this)
+ .addOnConnectionFailedListener(this)
+ .build();
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ mGoogleApiClient.connect();
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ Wearable.DataApi.removeListener(mGoogleApiClient, this);
+ Wearable.MessageApi.removeListener(mGoogleApiClient, this);
+ Wearable.NodeApi.removeListener(mGoogleApiClient, this);
+ mGoogleApiClient.disconnect();
+ }
+
+ @Override
+ public void onConnected(Bundle connectionHint) {
+ LOGD(TAG, "onConnected(): Successfully connected to Google API client");
+ Wearable.DataApi.addListener(mGoogleApiClient, this);
+ Wearable.MessageApi.addListener(mGoogleApiClient, this);
+ Wearable.NodeApi.addListener(mGoogleApiClient, this);
+ }
+
+ @Override
+ public void onConnectionSuspended(int cause) {
+ LOGD(TAG, "onConnectionSuspended(): Connection to Google API client was suspended");
+ }
+
+ @Override
+ public void onConnectionFailed(ConnectionResult result) {
+ Log.e(TAG, "onConnectionFailed(): Failed to connect, with result: " + result);
+ }
+
+ private void generateEvent(final String title, final String text) {
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ mIntroText.setVisibility(View.INVISIBLE);
+ mDataItemListAdapter.add(new Event(title, text));
+ }
+ });
+ }
+
+ @Override
+ public void onDataChanged(DataEventBuffer dataEvents) {
+ LOGD(TAG, "onDataChanged(): " + dataEvents);
+
+ final List events = FreezableUtils.freezeIterable(dataEvents);
+ dataEvents.close();
+ for (DataEvent event : events) {
+ if (event.getType() == DataEvent.TYPE_CHANGED) {
+ String path = event.getDataItem().getUri().getPath();
+ if (DataLayerListenerService.IMAGE_PATH.equals(path)) {
+ DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem());
+ Asset photo = dataMapItem.getDataMap()
+ .getAsset(DataLayerListenerService.IMAGE_KEY);
+ final Bitmap bitmap = loadBitmapFromAsset(mGoogleApiClient, photo);
+ mHandler.post(new Runnable() {
+ @Override
+ public void run() {
+ Log.d(TAG, "Setting background image..");
+ mLayout.setBackground(new BitmapDrawable(getResources(), bitmap));
+ }
+ });
+
+ } else if (DataLayerListenerService.COUNT_PATH.equals(path)) {
+ LOGD(TAG, "Data Changed for COUNT_PATH");
+ generateEvent("DataItem Changed", event.getDataItem().toString());
+ } else {
+ LOGD(TAG, "Unrecognized path: " + path);
+ }
+
+ } else if (event.getType() == DataEvent.TYPE_DELETED) {
+ generateEvent("DataItem Deleted", event.getDataItem().toString());
+ } else {
+ generateEvent("Unknown data event type", "Type = " + event.getType());
+ }
+ }
+ }
+
+ /**
+ * Extracts {@link android.graphics.Bitmap} data from the
+ * {@link com.google.android.gms.wearable.Asset}
+ */
+ private Bitmap loadBitmapFromAsset(GoogleApiClient apiClient, Asset asset) {
+ if (asset == null) {
+ throw new IllegalArgumentException("Asset must be non-null");
+ }
+
+ InputStream assetInputStream = Wearable.DataApi.getFdForAsset(
+ apiClient, asset).await().getInputStream();
+
+ if (assetInputStream == null) {
+ Log.w(TAG, "Requested an unknown Asset.");
+ return null;
+ }
+ return BitmapFactory.decodeStream(assetInputStream);
+ }
+
+ @Override
+ public void onMessageReceived(MessageEvent event) {
+ LOGD(TAG, "onMessageReceived: " + event);
+ generateEvent("Message", event.toString());
+ }
+
+ @Override
+ public void onPeerConnected(Node node) {
+ generateEvent("Node Connected", node.getId());
+ }
+
+ @Override
+ public void onPeerDisconnected(Node node) {
+ generateEvent("Node Disconnected", node.getId());
+ }
+
+ private static class DataItemAdapter extends ArrayAdapter {
+
+ private final Context mContext;
+
+ public DataItemAdapter(Context context, int unusedResource) {
+ super(context, unusedResource);
+ mContext = context;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ ViewHolder holder;
+ if (convertView == null) {
+ holder = new ViewHolder();
+ LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
+ Context.LAYOUT_INFLATER_SERVICE);
+ convertView = inflater.inflate(android.R.layout.two_line_list_item, null);
+ convertView.setTag(holder);
+ holder.text1 = (TextView) convertView.findViewById(android.R.id.text1);
+ holder.text2 = (TextView) convertView.findViewById(android.R.id.text2);
+ } else {
+ holder = (ViewHolder) convertView.getTag();
+ }
+ Event event = getItem(position);
+ holder.text1.setText(event.title);
+ holder.text2.setText(event.text);
+ return convertView;
+ }
+
+ private class ViewHolder {
+
+ TextView text1;
+ TextView text2;
+ }
+ }
+
+ private class Event {
+
+ String title;
+ String text;
+
+ public Event(String title, String text) {
+ this.title = title;
+ this.text = text;
+ }
+ }
+}
diff --git a/samples/wearable/DataLayer/Wearable/src/main/res/drawable-hdpi/ic_launcher.png b/samples/wearable/DataLayer/Wearable/src/main/res/drawable-hdpi/ic_launcher.png
new file mode 100755
index 000000000..589f229d1
Binary files /dev/null and b/samples/wearable/DataLayer/Wearable/src/main/res/drawable-hdpi/ic_launcher.png differ
diff --git a/samples/wearable/DataLayer/Wearable/src/main/res/drawable-mdpi/ic_launcher.png b/samples/wearable/DataLayer/Wearable/src/main/res/drawable-mdpi/ic_launcher.png
new file mode 100755
index 000000000..77dd57139
Binary files /dev/null and b/samples/wearable/DataLayer/Wearable/src/main/res/drawable-mdpi/ic_launcher.png differ
diff --git a/samples/wearable/DataLayer/Wearable/src/main/res/drawable-xhdpi/ic_launcher.png b/samples/wearable/DataLayer/Wearable/src/main/res/drawable-xhdpi/ic_launcher.png
new file mode 100755
index 000000000..fe34ebe13
Binary files /dev/null and b/samples/wearable/DataLayer/Wearable/src/main/res/drawable-xhdpi/ic_launcher.png differ
diff --git a/samples/wearable/DataLayer/Wearable/src/main/res/drawable-xxhdpi/ic_launcher.png b/samples/wearable/DataLayer/Wearable/src/main/res/drawable-xxhdpi/ic_launcher.png
new file mode 100755
index 000000000..ab80bcd13
Binary files /dev/null and b/samples/wearable/DataLayer/Wearable/src/main/res/drawable-xxhdpi/ic_launcher.png differ
diff --git a/samples/wearable/DataLayer/Wearable/src/main/res/layout/main_activity.xml b/samples/wearable/DataLayer/Wearable/src/main/res/layout/main_activity.xml
new file mode 100644
index 000000000..e88c6d128
--- /dev/null
+++ b/samples/wearable/DataLayer/Wearable/src/main/res/layout/main_activity.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/samples/wearable/DataLayer/Wearable/src/main/res/values/strings.xml b/samples/wearable/DataLayer/Wearable/src/main/res/values/strings.xml
new file mode 100644
index 000000000..5582c7ab7
--- /dev/null
+++ b/samples/wearable/DataLayer/Wearable/src/main/res/values/strings.xml
@@ -0,0 +1,5 @@
+
+
+ Data Layer Sample Wearable App
+ Waiting for data to arrive\u2026
+
diff --git a/samples/wearable/DataLayer/build.gradle b/samples/wearable/DataLayer/build.gradle
new file mode 100644
index 000000000..07be865b5
--- /dev/null
+++ b/samples/wearable/DataLayer/build.gradle
@@ -0,0 +1,14 @@
+buildscript {
+ repositories {
+ mavenCentral()
+ }
+ dependencies {
+ classpath 'com.android.tools.build:gradle:0.11.+'
+ }
+}
+
+allprojects {
+ repositories {
+ mavenCentral()
+ }
+}
\ No newline at end of file
diff --git a/samples/wearable/DataLayer/gradle/wrapper/gradle-wrapper.jar b/samples/wearable/DataLayer/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 000000000..583859812
Binary files /dev/null and b/samples/wearable/DataLayer/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/samples/wearable/DataLayer/gradle/wrapper/gradle-wrapper.properties b/samples/wearable/DataLayer/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 000000000..e83e46081
--- /dev/null
+++ b/samples/wearable/DataLayer/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Fri Mar 14 14:02:22 PDT 2014
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-all.zip
diff --git a/samples/wearable/DataLayer/gradlew b/samples/wearable/DataLayer/gradlew
new file mode 100755
index 000000000..91a7e269e
--- /dev/null
+++ b/samples/wearable/DataLayer/gradlew
@@ -0,0 +1,164 @@
+#!/usr/bin/env bash
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+ echo "$*"
+}
+
+die ( ) {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+esac
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched.
+if $cygwin ; then
+ [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+fi
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >&-
+APP_HOME="`pwd -P`"
+cd "$SAVED" >&-
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+ JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
diff --git a/samples/wearable/DataLayer/gradlew.bat b/samples/wearable/DataLayer/gradlew.bat
new file mode 100644
index 000000000..aec99730b
--- /dev/null
+++ b/samples/wearable/DataLayer/gradlew.bat
@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windowz variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%@eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/samples/wearable/DataLayer/settings.gradle b/samples/wearable/DataLayer/settings.gradle
new file mode 100644
index 000000000..68726d456
--- /dev/null
+++ b/samples/wearable/DataLayer/settings.gradle
@@ -0,0 +1 @@
+include 'Application', 'Wearable'
\ No newline at end of file
diff --git a/samples/wearable/DelayedConfirmation/Application/_index.html b/samples/wearable/DelayedConfirmation/Application/_index.html
new file mode 100644
index 000000000..6996cc757
--- /dev/null
+++ b/samples/wearable/DelayedConfirmation/Application/_index.html
@@ -0,0 +1,5 @@
+
Demonstrates how to create a DelayedConfirmationView in your wearable app. In this sample,
+pressing a button on the phone app sends a message to the wearable to start a simple activity. This
+activity displays a DelayedConfirmationView that starts when the user presses "Start Timer." Then,
+callbacks are implemented on both the wearable and phone to show when the timer is selected or
+finishes.
\ No newline at end of file
diff --git a/samples/wearable/DelayedConfirmation/Application/build.gradle b/samples/wearable/DelayedConfirmation/Application/build.gradle
new file mode 100644
index 000000000..ef83ddd2c
--- /dev/null
+++ b/samples/wearable/DelayedConfirmation/Application/build.gradle
@@ -0,0 +1,33 @@
+apply plugin: 'android'
+
+android {
+ compileSdkVersion 20
+ buildToolsVersion '20'
+
+ defaultConfig {
+ minSdkVersion 18
+ targetSdkVersion 20
+ versionCode 1
+ versionName "1.0"
+ }
+
+ buildTypes {
+ release {
+ runProguard false
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
+ }
+ }
+
+ aaptOptions {
+ noCompress 'apk'
+ }
+
+ lintOptions {
+ abortOnError false
+ }
+}
+
+dependencies {
+ compile 'com.google.android.gms:play-services:5.0.+@aar'
+ wearApp project(':Wearable')
+}
\ No newline at end of file
diff --git a/samples/wearable/DelayedConfirmation/Application/proguard-rules.txt b/samples/wearable/DelayedConfirmation/Application/proguard-rules.txt
new file mode 100644
index 000000000..f2fe1559a
--- /dev/null
+++ b/samples/wearable/DelayedConfirmation/Application/proguard-rules.txt
@@ -0,0 +1,20 @@
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
diff --git a/samples/wearable/DelayedConfirmation/Application/src/main/AndroidManifest.xml b/samples/wearable/DelayedConfirmation/Application/src/main/AndroidManifest.xml
new file mode 100644
index 000000000..cff91a4ee
--- /dev/null
+++ b/samples/wearable/DelayedConfirmation/Application/src/main/AndroidManifest.xml
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/wearable/DelayedConfirmation/Application/src/main/java/com/example/android/wearable/delayedconfirmation/MainActivity.java b/samples/wearable/DelayedConfirmation/Application/src/main/java/com/example/android/wearable/delayedconfirmation/MainActivity.java
new file mode 100644
index 000000000..4bc17ba82
--- /dev/null
+++ b/samples/wearable/DelayedConfirmation/Application/src/main/java/com/example/android/wearable/delayedconfirmation/MainActivity.java
@@ -0,0 +1,118 @@
+package com.example.android.wearable.delayedconfirmation;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.widget.Toast;
+
+import com.google.android.gms.common.ConnectionResult;
+import com.google.android.gms.common.api.GoogleApiClient;
+import com.google.android.gms.common.api.ResultCallback;
+import com.google.android.gms.wearable.MessageApi;
+import com.google.android.gms.wearable.MessageEvent;
+import com.google.android.gms.wearable.Node;
+import com.google.android.gms.wearable.NodeApi;
+import com.google.android.gms.wearable.Wearable;
+
+/**
+ * Has a single button, used to start the Wearable MainActivity.
+ */
+public class MainActivity extends Activity implements MessageApi.MessageListener,
+ GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
+
+ private static final String TAG = "DelayedConfirmation";
+ private static final String START_ACTIVITY_PATH = "/start-activity";
+ private static final String TIMER_SELECTED_PATH = "/timer_selected";
+ private static final String TIMER_FINISHED_PATH = "/timer_finished";
+ private GoogleApiClient mGoogleApiClient;
+
+ @Override
+ public void onCreate(Bundle b) {
+ super.onCreate(b);
+ setContentView(R.layout.main_activity);
+ mGoogleApiClient = new GoogleApiClient.Builder(this)
+ .addApi(Wearable.API)
+ .addConnectionCallbacks(this)
+ .addOnConnectionFailedListener(this)
+ .build();
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ if (!mGoogleApiClient.isConnected()) {
+ mGoogleApiClient.connect();
+ }
+ }
+
+ @Override
+ protected void onDestroy() {
+ if (mGoogleApiClient.isConnected()) {
+ mGoogleApiClient.disconnect();
+ }
+ super.onDestroy();
+ }
+
+ @Override
+ public void onConnected(Bundle bundle) {
+ Wearable.MessageApi.addListener(mGoogleApiClient, this);
+ }
+
+ @Override
+ public void onConnectionSuspended(int i) {
+ Wearable.MessageApi.removeListener(mGoogleApiClient, this);
+ }
+
+ @Override
+ public void onMessageReceived(final MessageEvent messageEvent) {
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ if (messageEvent.getPath().equals(TIMER_SELECTED_PATH)) {
+ Toast.makeText(getApplicationContext(), R.string.toast_timer_selected,
+ Toast.LENGTH_SHORT).show();
+ } else if (messageEvent.getPath().equals(TIMER_FINISHED_PATH)) {
+ Toast.makeText(getApplicationContext(), R.string.toast_timer_finished,
+ Toast.LENGTH_SHORT).show();
+ }
+ }
+ });
+
+ }
+
+ @Override
+ public void onConnectionFailed(ConnectionResult connectionResult) {
+ Log.e(TAG, "Failed to connect to Google Api Client with error code "
+ + connectionResult.getErrorCode());
+ }
+
+ /**
+ * Sends a message to Wearable MainActivity when button is pressed.
+ */
+ public void onStartWearableActivityClick(View view) {
+ Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).setResultCallback(
+ new ResultCallback() {
+ @Override
+ public void onResult(NodeApi.GetConnectedNodesResult getConnectedNodesResult) {
+ for (final Node node : getConnectedNodesResult.getNodes()) {
+ Wearable.MessageApi.sendMessage(
+ mGoogleApiClient, node.getId(), START_ACTIVITY_PATH, new byte[0])
+ .setResultCallback(getSendMessageResultCallback());
+ }
+ }
+ });
+ }
+
+ private ResultCallback getSendMessageResultCallback() {
+ return new ResultCallback() {
+ @Override
+ public void onResult(MessageApi.SendMessageResult sendMessageResult) {
+ if (!sendMessageResult.getStatus().isSuccess()) {
+ Log.e(TAG, "Failed to connect to Google Api Client with status "
+ + sendMessageResult.getStatus());
+ }
+ }
+ };
+ }
+}
diff --git a/samples/wearable/DelayedConfirmation/Application/src/main/res/drawable-hdpi/ic_launcher.png b/samples/wearable/DelayedConfirmation/Application/src/main/res/drawable-hdpi/ic_launcher.png
new file mode 100755
index 000000000..589f229d1
Binary files /dev/null and b/samples/wearable/DelayedConfirmation/Application/src/main/res/drawable-hdpi/ic_launcher.png differ
diff --git a/samples/wearable/DelayedConfirmation/Application/src/main/res/drawable-mdpi/ic_launcher.png b/samples/wearable/DelayedConfirmation/Application/src/main/res/drawable-mdpi/ic_launcher.png
new file mode 100755
index 000000000..77dd57139
Binary files /dev/null and b/samples/wearable/DelayedConfirmation/Application/src/main/res/drawable-mdpi/ic_launcher.png differ
diff --git a/samples/wearable/DelayedConfirmation/Application/src/main/res/drawable-xhdpi/ic_launcher.png b/samples/wearable/DelayedConfirmation/Application/src/main/res/drawable-xhdpi/ic_launcher.png
new file mode 100755
index 000000000..fe34ebe13
Binary files /dev/null and b/samples/wearable/DelayedConfirmation/Application/src/main/res/drawable-xhdpi/ic_launcher.png differ
diff --git a/samples/wearable/DelayedConfirmation/Application/src/main/res/drawable-xxhdpi/ic_launcher.png b/samples/wearable/DelayedConfirmation/Application/src/main/res/drawable-xxhdpi/ic_launcher.png
new file mode 100755
index 000000000..ab80bcd13
Binary files /dev/null and b/samples/wearable/DelayedConfirmation/Application/src/main/res/drawable-xxhdpi/ic_launcher.png differ
diff --git a/samples/wearable/DelayedConfirmation/Application/src/main/res/layout/main_activity.xml b/samples/wearable/DelayedConfirmation/Application/src/main/res/layout/main_activity.xml
new file mode 100644
index 000000000..39f3a40b9
--- /dev/null
+++ b/samples/wearable/DelayedConfirmation/Application/src/main/res/layout/main_activity.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
diff --git a/samples/wearable/DelayedConfirmation/Application/src/main/res/values/strings.xml b/samples/wearable/DelayedConfirmation/Application/src/main/res/values/strings.xml
new file mode 100644
index 000000000..7b5ee4793
--- /dev/null
+++ b/samples/wearable/DelayedConfirmation/Application/src/main/res/values/strings.xml
@@ -0,0 +1,9 @@
+
+
+ Delayed Confirmation Sample App
+ Start Wearable Activity
+ Start
+
+ Timer Selected
+ Timer Finished
+
diff --git a/samples/wearable/DelayedConfirmation/Wearable/build.gradle b/samples/wearable/DelayedConfirmation/Wearable/build.gradle
new file mode 100644
index 000000000..fa6b67ab0
--- /dev/null
+++ b/samples/wearable/DelayedConfirmation/Wearable/build.gradle
@@ -0,0 +1,31 @@
+apply plugin: 'android'
+
+android {
+ compileSdkVersion 20
+ buildToolsVersion '20'
+
+ defaultConfig {
+ minSdkVersion 20
+ targetSdkVersion 20
+ versionCode 1
+ versionName "1.0"
+ }
+
+ buildTypes {
+ release {
+ runProguard false
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
+ }
+ }
+
+ lintOptions {
+ abortOnError false
+ }
+
+}
+
+dependencies {
+ compile 'com.google.android.gms:play-services:5.0.+@aar'
+ compile "com.android.support:support-v13:20.0.+"
+ compile "com.google.android.support:wearable:1.0.+"
+}
\ No newline at end of file
diff --git a/samples/wearable/DelayedConfirmation/Wearable/proguard-rules.txt b/samples/wearable/DelayedConfirmation/Wearable/proguard-rules.txt
new file mode 100644
index 000000000..2ddbcfcdd
--- /dev/null
+++ b/samples/wearable/DelayedConfirmation/Wearable/proguard-rules.txt
@@ -0,0 +1,21 @@
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
+-dontwarn android.support.wearable.view.DelayedConfirmationView
diff --git a/samples/wearable/DelayedConfirmation/Wearable/src/main/AndroidManifest.xml b/samples/wearable/DelayedConfirmation/Wearable/src/main/AndroidManifest.xml
new file mode 100644
index 000000000..81bda1be7
--- /dev/null
+++ b/samples/wearable/DelayedConfirmation/Wearable/src/main/AndroidManifest.xml
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/wearable/DelayedConfirmation/Wearable/src/main/java/com/example/android/wearable/delayedconfirmation/MainActivity.java b/samples/wearable/DelayedConfirmation/Wearable/src/main/java/com/example/android/wearable/delayedconfirmation/MainActivity.java
new file mode 100644
index 000000000..0303aa6e2
--- /dev/null
+++ b/samples/wearable/DelayedConfirmation/Wearable/src/main/java/com/example/android/wearable/delayedconfirmation/MainActivity.java
@@ -0,0 +1,128 @@
+package com.example.android.wearable.delayedconfirmation;
+
+import android.app.Activity;
+import android.app.Notification;
+import android.os.Bundle;
+import android.support.v4.app.NotificationCompat;
+import android.support.v4.app.NotificationManagerCompat;
+import android.support.wearable.view.DelayedConfirmationView;
+import android.util.Log;
+import android.view.View;
+
+import com.google.android.gms.common.ConnectionResult;
+import com.google.android.gms.common.api.GoogleApiClient;
+import com.google.android.gms.common.api.ResultCallback;
+import com.google.android.gms.wearable.MessageApi;
+import com.google.android.gms.wearable.Node;
+import com.google.android.gms.wearable.NodeApi;
+import com.google.android.gms.wearable.Wearable;
+
+
+public class MainActivity extends Activity implements
+ DelayedConfirmationView.DelayedConfirmationListener,
+ GoogleApiClient.OnConnectionFailedListener {
+
+ private static final String TAG = "DelayedConfirmation";
+ private static final int NUM_SECONDS = 5;
+
+ private static final String TIMER_SELECTED_PATH = "/timer_selected";
+ private static final String TIMER_FINISHED_PATH = "/timer_finished";
+
+ private DelayedConfirmationView delayedConfirmationView;
+ private GoogleApiClient mGoogleApiClient;
+
+ @Override
+ public void onCreate(Bundle b) {
+ super.onCreate(b);
+ setContentView(R.layout.main_activity);
+ delayedConfirmationView = (DelayedConfirmationView) findViewById(R.id.delayed_confirmation);
+ delayedConfirmationView.setTotalTimeMs(NUM_SECONDS * 1000);
+ mGoogleApiClient = new GoogleApiClient.Builder(this)
+ .addApi(Wearable.API)
+ .addOnConnectionFailedListener(this)
+ .build();
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ if (!mGoogleApiClient.isConnected()) {
+ mGoogleApiClient.connect();
+ }
+ }
+
+ @Override
+ protected void onDestroy() {
+ if (mGoogleApiClient.isConnected()) {
+ mGoogleApiClient.disconnect();
+ }
+ super.onDestroy();
+ }
+
+ /**
+ * Starts the DelayedConfirmationView when user presses "Start Timer" button.
+ */
+ public void onStartTimer(View view) {
+ delayedConfirmationView.start();
+ delayedConfirmationView.setListener(this);
+ }
+
+ @Override
+ public void onTimerSelected(View v) {
+ v.setPressed(true);
+ Notification notification = new NotificationCompat.Builder(this)
+ .setSmallIcon(R.drawable.ic_launcher)
+ .setContentTitle(getString(R.string.notification_title))
+ .setContentText(getString(R.string.notification_timer_selected))
+ .build();
+ NotificationManagerCompat.from(this).notify(0, notification);
+ sendMessageToCompanion(TIMER_SELECTED_PATH);
+ // Prevent onTimerFinished from being heard.
+ ((DelayedConfirmationView) v).setListener(null);
+ finish();
+ }
+
+ @Override
+ public void onTimerFinished(View v) {
+ Notification notification = new NotificationCompat.Builder(this)
+ .setSmallIcon(R.drawable.ic_launcher)
+ .setContentTitle(getString(R.string.notification_title))
+ .setContentText(getString(R.string.notification_timer_finished))
+ .build();
+ NotificationManagerCompat.from(this).notify(0, notification);
+ sendMessageToCompanion(TIMER_FINISHED_PATH);
+ finish();
+ }
+
+ @Override
+ public void onConnectionFailed(ConnectionResult connectionResult) {
+ Log.e(TAG, "Failed to connect to Google Api Client");
+ }
+
+ private void sendMessageToCompanion(final String path) {
+ Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).setResultCallback(
+ new ResultCallback() {
+ @Override
+ public void onResult(NodeApi.GetConnectedNodesResult getConnectedNodesResult) {
+ for (final Node node : getConnectedNodesResult.getNodes()) {
+ Wearable.MessageApi.sendMessage(mGoogleApiClient, node.getId(), path,
+ new byte[0]).setResultCallback(getSendMessageResultCallback());
+ }
+ }
+ }
+ );
+
+ }
+
+ private ResultCallback getSendMessageResultCallback() {
+ return new ResultCallback() {
+ @Override
+ public void onResult(MessageApi.SendMessageResult sendMessageResult) {
+ if (!sendMessageResult.getStatus().isSuccess()) {
+ Log.e(TAG, "Failed to connect to Google Api Client with status "
+ + sendMessageResult.getStatus());
+ }
+ }
+ };
+ }
+}
diff --git a/samples/wearable/DelayedConfirmation/Wearable/src/main/java/com/example/android/wearable/delayedconfirmation/WearableMessageListenerService.java b/samples/wearable/DelayedConfirmation/Wearable/src/main/java/com/example/android/wearable/delayedconfirmation/WearableMessageListenerService.java
new file mode 100644
index 000000000..881de2ef2
--- /dev/null
+++ b/samples/wearable/DelayedConfirmation/Wearable/src/main/java/com/example/android/wearable/delayedconfirmation/WearableMessageListenerService.java
@@ -0,0 +1,22 @@
+package com.example.android.wearable.delayedconfirmation;
+
+import android.content.Intent;
+
+import com.google.android.gms.wearable.MessageEvent;
+import com.google.android.gms.wearable.WearableListenerService;
+
+/**
+ * Listens for a message telling it to start the Wearable MainActivity.
+ */
+public class WearableMessageListenerService extends WearableListenerService {
+ private static final String START_ACTIVITY_PATH = "/start-activity";
+
+ @Override
+ public void onMessageReceived(MessageEvent event) {
+ if (event.getPath().equals(START_ACTIVITY_PATH)) {
+ Intent startIntent = new Intent(this, MainActivity.class);
+ startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ startActivity(startIntent);
+ }
+ }
+}
diff --git a/samples/wearable/DelayedConfirmation/Wearable/src/main/res/drawable-hdpi/ic_launcher.png b/samples/wearable/DelayedConfirmation/Wearable/src/main/res/drawable-hdpi/ic_launcher.png
new file mode 100755
index 000000000..589f229d1
Binary files /dev/null and b/samples/wearable/DelayedConfirmation/Wearable/src/main/res/drawable-hdpi/ic_launcher.png differ
diff --git a/samples/wearable/DelayedConfirmation/Wearable/src/main/res/drawable-mdpi/ic_launcher.png b/samples/wearable/DelayedConfirmation/Wearable/src/main/res/drawable-mdpi/ic_launcher.png
new file mode 100755
index 000000000..77dd57139
Binary files /dev/null and b/samples/wearable/DelayedConfirmation/Wearable/src/main/res/drawable-mdpi/ic_launcher.png differ
diff --git a/samples/wearable/DelayedConfirmation/Wearable/src/main/res/drawable-xhdpi/ic_launcher.png b/samples/wearable/DelayedConfirmation/Wearable/src/main/res/drawable-xhdpi/ic_launcher.png
new file mode 100755
index 000000000..fe34ebe13
Binary files /dev/null and b/samples/wearable/DelayedConfirmation/Wearable/src/main/res/drawable-xhdpi/ic_launcher.png differ
diff --git a/samples/wearable/DelayedConfirmation/Wearable/src/main/res/drawable-xxhdpi/ic_launcher.png b/samples/wearable/DelayedConfirmation/Wearable/src/main/res/drawable-xxhdpi/ic_launcher.png
new file mode 100755
index 000000000..ab80bcd13
Binary files /dev/null and b/samples/wearable/DelayedConfirmation/Wearable/src/main/res/drawable-xxhdpi/ic_launcher.png differ
diff --git a/samples/wearable/DelayedConfirmation/Wearable/src/main/res/layout/main_activity.xml b/samples/wearable/DelayedConfirmation/Wearable/src/main/res/layout/main_activity.xml
new file mode 100644
index 000000000..970af037a
--- /dev/null
+++ b/samples/wearable/DelayedConfirmation/Wearable/src/main/res/layout/main_activity.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/wearable/DelayedConfirmation/Wearable/src/main/res/values/dimens.xml b/samples/wearable/DelayedConfirmation/Wearable/src/main/res/values/dimens.xml
new file mode 100644
index 000000000..a04399445
--- /dev/null
+++ b/samples/wearable/DelayedConfirmation/Wearable/src/main/res/values/dimens.xml
@@ -0,0 +1,6 @@
+
+ 10dp
+ 5dp
+ 60dp
+ 55dp
+
diff --git a/samples/wearable/DelayedConfirmation/Wearable/src/main/res/values/strings.xml b/samples/wearable/DelayedConfirmation/Wearable/src/main/res/values/strings.xml
new file mode 100644
index 000000000..ad9ce88b0
--- /dev/null
+++ b/samples/wearable/DelayedConfirmation/Wearable/src/main/res/values/strings.xml
@@ -0,0 +1,10 @@
+
+
+
+ Delayed Confirmation
+ Start Timer (5 seconds)
+
+ DelayedConfirmation
+ Timer Selected
+ Timer Finished
+
diff --git a/samples/wearable/DelayedConfirmation/build.gradle b/samples/wearable/DelayedConfirmation/build.gradle
new file mode 100644
index 000000000..07be865b5
--- /dev/null
+++ b/samples/wearable/DelayedConfirmation/build.gradle
@@ -0,0 +1,14 @@
+buildscript {
+ repositories {
+ mavenCentral()
+ }
+ dependencies {
+ classpath 'com.android.tools.build:gradle:0.11.+'
+ }
+}
+
+allprojects {
+ repositories {
+ mavenCentral()
+ }
+}
\ No newline at end of file
diff --git a/samples/wearable/DelayedConfirmation/gradle.properties b/samples/wearable/DelayedConfirmation/gradle.properties
new file mode 100644
index 000000000..5d08ba75b
--- /dev/null
+++ b/samples/wearable/DelayedConfirmation/gradle.properties
@@ -0,0 +1,18 @@
+# Project-wide Gradle settings.
+
+# IDE (e.g. Android Studio) users:
+# Settings specified in this file will override any Gradle settings
+# configured through the IDE.
+
+# For more details on how to configure your build environment visit
+# http://www.gradle.org/docs/current/userguide/build_environment.html
+
+# Specifies the JVM arguments used for the daemon process.
+# The setting is particularly useful for tweaking memory settings.
+# Default value: -Xmx10248m -XX:MaxPermSize=256m
+# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
+
+# When configured, Gradle will run in incubating parallel mode.
+# This option should only be used with decoupled projects. More details, visit
+# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
+# org.gradle.parallel=true
\ No newline at end of file
diff --git a/samples/wearable/DelayedConfirmation/gradle/wrapper/gradle-wrapper.jar b/samples/wearable/DelayedConfirmation/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 000000000..583859812
Binary files /dev/null and b/samples/wearable/DelayedConfirmation/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/samples/wearable/DelayedConfirmation/gradle/wrapper/gradle-wrapper.properties b/samples/wearable/DelayedConfirmation/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 000000000..e83e46081
--- /dev/null
+++ b/samples/wearable/DelayedConfirmation/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Fri Mar 14 14:02:22 PDT 2014
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-all.zip
diff --git a/samples/wearable/DelayedConfirmation/gradlew b/samples/wearable/DelayedConfirmation/gradlew
new file mode 100755
index 000000000..91a7e269e
--- /dev/null
+++ b/samples/wearable/DelayedConfirmation/gradlew
@@ -0,0 +1,164 @@
+#!/usr/bin/env bash
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+ echo "$*"
+}
+
+die ( ) {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+esac
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched.
+if $cygwin ; then
+ [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+fi
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >&-
+APP_HOME="`pwd -P`"
+cd "$SAVED" >&-
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+ JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
diff --git a/samples/wearable/DelayedConfirmation/gradlew.bat b/samples/wearable/DelayedConfirmation/gradlew.bat
new file mode 100644
index 000000000..aec99730b
--- /dev/null
+++ b/samples/wearable/DelayedConfirmation/gradlew.bat
@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windowz variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%@eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/samples/wearable/DelayedConfirmation/settings.gradle b/samples/wearable/DelayedConfirmation/settings.gradle
new file mode 100644
index 000000000..68726d456
--- /dev/null
+++ b/samples/wearable/DelayedConfirmation/settings.gradle
@@ -0,0 +1 @@
+include 'Application', 'Wearable'
\ No newline at end of file
diff --git a/samples/wearable/ElizaChat/_index.html b/samples/wearable/ElizaChat/_index.html
new file mode 100644
index 000000000..bdf250804
--- /dev/null
+++ b/samples/wearable/ElizaChat/_index.html
@@ -0,0 +1,19 @@
+
This sample is a phone application that provides a chat experience in which
+users can respond to messages with a quick voice response. New messages create
+a notification with a "Reply" action. The notification is bridged from phone
+to wearable, and selecting the "Reply" action on the wearable opens the voice
+transcription UI allowing the user to speak a response.
+
+
To keep the example simple and self-contained, instead of a real chat
+application (which would require a server or a peer-to-peer connection), the
+conversation is conducted with an chat bot on the phone. Each time the bot
+responds, the phone app updates the notification and allows the user to write
+back. This sample is primarily intended to demonstrate the voice-reply
+capabilities provided by the Android Wear notification API.
+
+
When using the emulator you can type a response instead of speaking it
+aloud. To allow typed responses, ensure that your emulator image has the
+"hardware keyboard present" option enabled. After typing your message into
+the emulator window, hit the enter key and wait a few seconds for your
+message to be sent.
+
diff --git a/samples/wearable/ElizaChat/build.gradle b/samples/wearable/ElizaChat/build.gradle
new file mode 100644
index 000000000..0b1d4e621
--- /dev/null
+++ b/samples/wearable/ElizaChat/build.gradle
@@ -0,0 +1,41 @@
+// Top-level build file where you can add configuration options common to all sub-projects/modules.
+
+buildscript {
+ repositories {
+ mavenCentral()
+ }
+ dependencies {
+ classpath 'com.android.tools.build:gradle:0.11.+'
+ }
+}
+
+allprojects {
+ repositories {
+ mavenCentral()
+ }
+}
+
+apply plugin: 'android'
+
+android {
+ compileSdkVersion 19
+ buildToolsVersion '20'
+
+ defaultConfig {
+ minSdkVersion 18
+ targetSdkVersion 19
+ versionCode 1
+ versionName "1.0"
+ }
+
+ buildTypes {
+ release {
+ runProguard false
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
+ }
+ }
+}
+
+dependencies {
+ compile "com.android.support:support-v4:20.0.+"
+}
\ No newline at end of file
diff --git a/samples/wearable/ElizaChat/gradle.properties b/samples/wearable/ElizaChat/gradle.properties
new file mode 100644
index 000000000..5d08ba75b
--- /dev/null
+++ b/samples/wearable/ElizaChat/gradle.properties
@@ -0,0 +1,18 @@
+# Project-wide Gradle settings.
+
+# IDE (e.g. Android Studio) users:
+# Settings specified in this file will override any Gradle settings
+# configured through the IDE.
+
+# For more details on how to configure your build environment visit
+# http://www.gradle.org/docs/current/userguide/build_environment.html
+
+# Specifies the JVM arguments used for the daemon process.
+# The setting is particularly useful for tweaking memory settings.
+# Default value: -Xmx10248m -XX:MaxPermSize=256m
+# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
+
+# When configured, Gradle will run in incubating parallel mode.
+# This option should only be used with decoupled projects. More details, visit
+# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
+# org.gradle.parallel=true
\ No newline at end of file
diff --git a/samples/wearable/ElizaChat/gradle/wrapper/gradle-wrapper.jar b/samples/wearable/ElizaChat/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 000000000..583859812
Binary files /dev/null and b/samples/wearable/ElizaChat/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/samples/wearable/ElizaChat/gradle/wrapper/gradle-wrapper.properties b/samples/wearable/ElizaChat/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 000000000..e83e46081
--- /dev/null
+++ b/samples/wearable/ElizaChat/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Fri Mar 14 14:02:22 PDT 2014
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-all.zip
diff --git a/samples/wearable/ElizaChat/gradlew b/samples/wearable/ElizaChat/gradlew
new file mode 100755
index 000000000..91a7e269e
--- /dev/null
+++ b/samples/wearable/ElizaChat/gradlew
@@ -0,0 +1,164 @@
+#!/usr/bin/env bash
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+ echo "$*"
+}
+
+die ( ) {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+esac
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched.
+if $cygwin ; then
+ [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+fi
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >&-
+APP_HOME="`pwd -P`"
+cd "$SAVED" >&-
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+ JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
diff --git a/samples/wearable/ElizaChat/gradlew.bat b/samples/wearable/ElizaChat/gradlew.bat
new file mode 100644
index 000000000..aec99730b
--- /dev/null
+++ b/samples/wearable/ElizaChat/gradlew.bat
@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windowz variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%@eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/samples/wearable/ElizaChat/proguard-rules.txt b/samples/wearable/ElizaChat/proguard-rules.txt
new file mode 100644
index 000000000..08e5bdc8d
--- /dev/null
+++ b/samples/wearable/ElizaChat/proguard-rules.txt
@@ -0,0 +1,22 @@
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
+-dontwarn android.support.wearable.view.DelayedConfirmationView
+-dontwarn android.support.wearable.view.CircledImageView
diff --git a/samples/wearable/ElizaChat/src/main/AndroidManifest.xml b/samples/wearable/ElizaChat/src/main/AndroidManifest.xml
new file mode 100644
index 000000000..fef722443
--- /dev/null
+++ b/samples/wearable/ElizaChat/src/main/AndroidManifest.xml
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/wearable/ElizaChat/src/main/java/com/example/android/wearable/elizachat/ElizaResponder.java b/samples/wearable/ElizaChat/src/main/java/com/example/android/wearable/elizachat/ElizaResponder.java
new file mode 100644
index 000000000..4062ae867
--- /dev/null
+++ b/samples/wearable/ElizaChat/src/main/java/com/example/android/wearable/elizachat/ElizaResponder.java
@@ -0,0 +1,152 @@
+package com.example.android.wearable.elizachat;
+
+import android.text.TextUtils;
+
+/**
+ * A basic chat bot based on ELIZA, one of the earliest programs to employ primitive natural
+ * language processing. Like ELIZA, this bot can simulate a Rogerian psychotherapist using a
+ * collection of vague and generic responses.
+ */
+public class ElizaResponder {
+
+ private static final String[] CONVERSATION_KEYWORDS = {
+ "CAN YOU", "CAN I", "YOU ARE", "YOURE", "I DONT", "I FEEL", "WHY DONT YOU", "WHY CANT I",
+ "ARE YOU", "I CANT", "I AM", " IM ", "YOU", "I WANT", "WHAT", "HOW", "WHO", "WHERE",
+ "WHEN", "WHY", "NAME", "CAUSE", "SORRY", "DREAM", "HELLO", "HI", "MAYBE", "NO", "YOUR",
+ "ALWAYS", "THINK", "ALIKE", "YES", "FRIEND", "COMPUTER", "NOKEYFOUND" };
+
+ private static String[] WORDS_TO_REPLACE = {"ARE","AM","WERE","WAS","YOU","I","YOUR","MY",
+ "IVE","YOUVE","IM","YOURE", "YOU", "ME"};
+
+ private static String[] QUESTIONS = {
+ "DON'T YOU BELIEVE THAT I CAN.", "PERHAPS YOU WOULD LIKE TO BE ABLE TO.",
+ "YOU WANT ME TO BE ABLE TO*", "PERHAPS YOU DON'T WANT TO*",
+ "DO YOU WANT TO BE ABLE TO*", "WHAT MAKES YOU THINK I AM*",
+ "DOES IT PLEASE YOU TO BELIEVE I AM*", "PERHAPS YOU WOULD LIKE TO BE*",
+ "DO YOU SOMETIMES WISH YOU WERE*", "DON'T YOU REALLY*", "WHY DON'T YOU*",
+ "DO YOU WISH TO BE ABLE TO*", "DOES THAT TROUBLE YOU?",
+ "TELL ME MORE ABOUT SUCH FEELINGS*", "DO YOU OFTEN FEEL*",
+ "DO YOU ENJOY FEELING*", "DO YOU REALLY BELIEVE I DON'T*",
+ "PERHAPS IN TIME I WILL*", "DO YOU WANT ME TO*",
+ "DO YOU THINK YOU SHOULD BE ABLE TO*", "WHY CAN'T YOU*",
+ "WHAT MAKES YOU WONDER WHETHER OR NOT I AM*",
+ "WOULD YOU PREFER IF I WERE NOT*", "PERHAPS IN YOUR FANTASIES I AM*",
+ "HOW DO YOU KNOW YOU CAN'T*", "HAVE YOU TRIED?", "PERHAPS YOU CAN NOW*",
+ "DID YOU COME TO ME BECAUSE YOU ARE*", "HOW LONG HAVE YOU BEEN*",
+ "DO YOU BELIEVE IT IS NORMAL TO BE*", "DO YOU ENJOY BEING*",
+ "I AM MORE INTERESTED IN TALKING ABOUT YOU.", "OH, I*",
+ "ARE YOU REALLY SO INTERESTED IN SOMEONE LIKE ME?",
+ "WHAT WOULD IT MEAN TO YOU IF YOU GOT*", "WHY DO YOU WANT*",
+ "SUPPOSE YOU SOON GOT*", "WHAT IF YOU NEVER GOT*", "I SOMETIMES ALSO WANT*",
+ "WHY DO YOU ASK?", "DOES THAT QUESTION INTEREST YOU?",
+ "WHAT ANSWER WOULD PLEASE YOU THE MOST?", "WHAT DO YOU THINK?",
+ "ARE SUCH QUESTIONS ON YOUR MIND OFTEN?",
+ "WHAT IS IT THAT YOU REALLY WANT TO KNOW?", "HAVE YOU ASKED ANYONE ELSE?",
+ "HAVE YOU ASKED SUCH QUESTIONS BEFORE?",
+ "WHAT ELSE COMES TO MIND WHEN YOU ASK THAT?", "WE CAN KEEP THIS ANONYMOUS.",
+ "NO NEED TO SPECIFY ANY NAMES-- PLEASE GO ON.", "IS THAT THE REAL REASON?",
+ "DON'T ANY OTHER REASONS COME TO MIND?",
+ "DOES THAT REASON EXPLAIN ANYTHING ELSE?", "WHAT OTHER REASONS MIGHT THERE BE?",
+ "PLEASE DON'T APOLOGIZE.", "APOLOGIES ARE NOT NECESSARY.",
+ "WHAT FEELINGS DO YOU HAVE WHEN YOU APOLOGIZE?", "NO NEED TO BE DEFENSIVE!",
+ "WHAT DOES THAT DREAM SUGGEST TO YOU?", "DO YOU DREAM OFTEN?",
+ "WHAT PERSONS APPEAR IN YOUR DREAMS?", "DO YOU HAVE PLEASANT DREAMS?",
+ "HOW DO YOU DO ... PLEASE STATE YOUR PROBLEM.", "YOU DON'T SEEM QUITE CERTAIN.",
+ "WHY THE UNCERTAIN TONE?", "LET'S TRY TO KEEP THIS POSITIVE.", "YOU AREN'T SURE?",
+ "DON'T YOU KNOW?", "IS THAT A DEFINITE NO OR MIGHT YOU CHANGE YOUR MIND?",
+ "I AM SENSING SOME NEGATIVITY.", "WHY NOT?", "ARE YOU SURE?", "WHY NO?",
+ "WHY ARE YOU CONCERNED ABOUT MY*", "WHAT ABOUT YOUR OWN*",
+ "CAN'T YOU THINK OF A SPECIFIC EXAMPLE?", "WHEN?", "WHAT ARE YOU THINKING OF?",
+ "REALLY. ALWAYS?", "DO YOU REALLY THINK SO?", "BUT YOU ARE NOT SURE YOU.",
+ "BELIEVE IN YOURSELF.", "IN WHAT WAY?", "WHAT RESEMBLANCE DO YOU SEE?",
+ "WHAT DOES THE SIMILARITY SUGGEST TO YOU?",
+ "WHAT OTHER CONNECTIONS DO YOU SEE?", "COULD THERE REALLY BE SOME CONNECTION?",
+ "HOW?", "YOU SEEM QUITE POSITIVE.", "ARE YOU SURE?", "I SEE.", "I UNDERSTAND.",
+ "TELL ME ABOUT YOUR FRIENDS.", "ARE YOU WORRIED ABOUT YOUR FRIENDS?",
+ "DO YOUR FRIENDS EVER GIVE YOU A HARD TIME?", "WHAT DO YOU LIKE ABOUT YOUR FRIENDS?",
+ "DO YOU LOVE YOUR FRIENDS?", "PERHAPS YOUR LOVE FOR FRIENDS WORRIES YOU.",
+ "DO COMPUTERS EXCITE YOU?", "ARE YOU TALKING ABOUT ME IN PARTICULAR?",
+ "HOW DO YOU LIKE YOUR WATCH?", "WHY DO YOU MENTION COMPUTERS?",
+ "DO YOU FIND MACHINES AS FASCINATING AS I DO?",
+ "DON'T YOU THINK COMPUTERS CAN HELP PEOPLE?",
+ "WHAT ABOUT MACHINES EXCITES YOU THE MOST?",
+ "HEY THERE, HOW CAN I HELP YOU?",
+ "WHAT DOES THAT SUGGEST TO YOU?", "I SEE.",
+ "I'M NOT SURE I UNDERSTAND YOU FULLY.", "COME COME ELUCIDATE YOUR THOUGHTS.",
+ "CAN YOU ELABORATE ON THAT?", "THAT IS QUITE INTERESTING."};
+
+ private static char[] CONVERSATION_TO_RESPONSES_MAP = {
+ 1,3,4,2,6,4,6,4,10,4,14,3,17,3,20,2,22,3,25,3,
+ 28,4,28,4,32,3,35,5,40,9,40,9,40,9,40,9,40,9,40,9,
+ 49,2,51,4,55,4,59,4,63,1,63,1,64,5,69,5,74,2,76,4,
+ 80,3,83,7,90,3,93,6,99,7,106,6};
+
+ private int[] responseStarts = new int[36];
+ private int[] responseCurrentIndices = new int[36];
+ private int[] responseEnds = new int[36];
+ private String previousInput = null;
+
+ public ElizaResponder() {
+ for (int i = 0; i < CONVERSATION_TO_RESPONSES_MAP.length / 2; i++) {
+ responseStarts[i] = CONVERSATION_TO_RESPONSES_MAP[2 * i];
+ responseCurrentIndices[i] = CONVERSATION_TO_RESPONSES_MAP[2 * i];
+ responseEnds[i] = responseStarts[i] + CONVERSATION_TO_RESPONSES_MAP[2 * i + 1];
+ }
+ }
+
+ public String elzTalk(String input) {
+ if (null == input) {
+ input = "";
+ }
+ String result = "";
+
+ input = " " + input.toUpperCase().replace("\'", "") + " ";
+
+ if (previousInput != null && input.equals(previousInput)) {
+ return "DIDN'T YOU JUST SAY THAT?\n";
+ }
+ previousInput = input;
+
+ int keywordIndex = 0;
+ for (; keywordIndex < CONVERSATION_KEYWORDS.length; ++keywordIndex) {
+ int index = input.indexOf(CONVERSATION_KEYWORDS[keywordIndex]);
+ if (index != -1) {
+ break;
+ }
+ }
+
+ String afterKeyword = "";
+ if (keywordIndex == CONVERSATION_KEYWORDS.length) {
+ keywordIndex = 35;
+ } else {
+ int index = input.indexOf(CONVERSATION_KEYWORDS[keywordIndex]);
+ afterKeyword = input.substring(index + CONVERSATION_KEYWORDS[keywordIndex].length());
+ String[] parts = afterKeyword.split("\\s+");
+ for (int i = 0; i < WORDS_TO_REPLACE.length / 2; i++) {
+ String first = WORDS_TO_REPLACE[i * 2];
+ String second = WORDS_TO_REPLACE[i * 2 + 1];
+ for (int j = 0; j < parts.length; ++j) {
+ if (parts[j].equals(first)) {
+ parts[j] = second;
+ } else if (parts[j].equals(second)) {
+ parts[j] = first;
+ }
+ }
+ }
+ afterKeyword = TextUtils.join(" ", parts);
+ }
+
+ String question = QUESTIONS[responseCurrentIndices[keywordIndex] - 1];
+ responseCurrentIndices[keywordIndex] = responseCurrentIndices[keywordIndex] + 1;
+ if (responseCurrentIndices[keywordIndex] > responseEnds[keywordIndex]) {
+ responseCurrentIndices[keywordIndex] = responseStarts[keywordIndex];
+ }
+ result += question;
+ if (result.endsWith("*")) {
+ result = result.substring(0, result.length() - 1);
+ result += " " + afterKeyword;
+ }
+
+ return result;
+ }
+}
diff --git a/samples/wearable/ElizaChat/src/main/java/com/example/android/wearable/elizachat/MainActivity.java b/samples/wearable/ElizaChat/src/main/java/com/example/android/wearable/elizachat/MainActivity.java
new file mode 100644
index 000000000..920953683
--- /dev/null
+++ b/samples/wearable/ElizaChat/src/main/java/com/example/android/wearable/elizachat/MainActivity.java
@@ -0,0 +1,94 @@
+package com.example.android.wearable.elizachat;
+
+import android.app.Activity;
+import android.app.Notification;
+import android.app.PendingIntent;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.graphics.BitmapFactory;
+import android.os.Bundle;
+import android.support.v4.content.LocalBroadcastManager;
+import android.text.TextUtils;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.widget.TextView;
+
+public class MainActivity extends Activity {
+
+ @SuppressWarnings("unused")
+ private static final String TAG = "MainActivity";
+
+ public static final String EXTRA_MESSAGE = "message";
+
+ public static final String ACTION_NOTIFY = "com.example.android.wearable.elizachat.NOTIFY";
+
+ public static final String ACTION_GET_CONVERSATION
+ = "com.example.android.wearable.elizachat.CONVERSATION";
+
+ private BroadcastReceiver mReceiver;
+
+ private TextView mHistoryView;
+
+ @Override
+ protected void onCreate(Bundle saved) {
+ super.onCreate(saved);
+ setContentView(R.layout.activity_main);
+ mReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ processMessage(intent);
+ }
+ };
+ mHistoryView = (TextView) findViewById(R.id.history);
+ startResponderService();
+ }
+
+ private void startResponderService() {
+ Intent serviceIntent = new Intent(ResponderService.ACTION_INCOMING);
+ startService(serviceIntent);
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver,
+ new IntentFilter(ACTION_NOTIFY));
+ mHistoryView.setText("");
+ Intent serviceIntent = new Intent(ACTION_GET_CONVERSATION);
+ startService(serviceIntent);
+
+ }
+
+ @Override
+ protected void onPause() {
+ LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver);
+ super.onPause();
+ }
+
+ private void processMessage(Intent intent) {
+ String text = intent.getStringExtra(EXTRA_MESSAGE);
+ if (!TextUtils.isEmpty(text)) {
+ mHistoryView.append("\n" + text);
+ }
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ super.onCreateOptionsMenu(menu);
+ getMenuInflater().inflate(R.menu.main, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.action_stop_service:
+ stopService(new Intent(this, ResponderService.class));
+ finish();
+ break;
+ }
+ return true;
+ }
+}
diff --git a/samples/wearable/ElizaChat/src/main/java/com/example/android/wearable/elizachat/ResponderService.java b/samples/wearable/ElizaChat/src/main/java/com/example/android/wearable/elizachat/ResponderService.java
new file mode 100644
index 000000000..d776acc1e
--- /dev/null
+++ b/samples/wearable/ElizaChat/src/main/java/com/example/android/wearable/elizachat/ResponderService.java
@@ -0,0 +1,132 @@
+package com.example.android.wearable.elizachat;
+
+import android.app.Notification;
+import android.app.PendingIntent;
+import android.app.Service;
+import android.content.Intent;
+import android.graphics.BitmapFactory;
+import android.os.Bundle;
+import android.os.IBinder;
+import android.support.v4.app.NotificationCompat;
+import android.support.v4.app.RemoteInput;
+import android.support.v4.content.LocalBroadcastManager;
+import android.support.v4.app.NotificationManagerCompat;
+import android.text.TextUtils;
+import android.util.Log;
+
+/**
+ * A service that runs in the background and provides responses to the incoming messages from the
+ * wearable. It also keeps a record of the chat session history, which it can provide upon request.
+ */
+public class ResponderService extends Service {
+
+ public static final String ACTION_INCOMING = "com.example.android.wearable.elizachat.INCOMING";
+
+ public static final String ACTION_RESPONSE = "com.example.android.wearable.elizachat.REPLY";
+
+ public static final String EXTRA_REPLY = "reply";
+
+ private static final String TAG = "ResponderService";
+
+ private ElizaResponder mResponder;
+
+ private String mLastResponse = null;
+
+ private StringBuffer mCompleteConversation = new StringBuffer();
+
+ private LocalBroadcastManager mBroadcastManager;
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "Chat Service started");
+ }
+ mResponder = new ElizaResponder();
+ mBroadcastManager = LocalBroadcastManager.getInstance(this);
+ processIncoming(null);
+ }
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ return null;
+ }
+
+ @Override
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ if (null == intent || null == intent.getAction()) {
+ return Service.START_STICKY;
+ }
+ String action = intent.getAction();
+ if (action.equals(ACTION_RESPONSE)) {
+ Bundle remoteInputResults = RemoteInput.getResultsFromIntent(intent);
+ CharSequence replyMessage = "";
+ if (remoteInputResults != null) {
+ replyMessage = remoteInputResults.getCharSequence(EXTRA_REPLY);
+ }
+ processIncoming(replyMessage.toString());
+ } else if (action.equals(MainActivity.ACTION_GET_CONVERSATION)) {
+ broadcastMessage(mCompleteConversation.toString());
+ }
+ return Service.START_STICKY;
+ }
+
+ private void showNotification() {
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "Sent: " + mLastResponse);
+ }
+ NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
+ .setContentTitle(getString(R.string.eliza))
+ .setContentText(mLastResponse)
+ .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.bg_eliza))
+ .setSmallIcon(R.drawable.bg_eliza)
+ .setPriority(NotificationCompat.PRIORITY_MIN);
+
+ Intent intent = new Intent(ACTION_RESPONSE);
+ PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent,
+ PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT);
+ Notification notification = builder
+ .extend(new NotificationCompat.WearableExtender()
+ .addAction(new NotificationCompat.Action.Builder(
+ R.drawable.ic_full_reply, getString(R.string.reply), pendingIntent)
+ .addRemoteInput(new RemoteInput.Builder(EXTRA_REPLY)
+ .setLabel(getString(R.string.reply))
+ .build())
+ .build()))
+ .build();
+ NotificationManagerCompat.from(this).notify(0, notification);
+ }
+
+ private void processIncoming(String text) {
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "Received: " + text);
+ }
+ mLastResponse = mResponder.elzTalk(text);
+ String line = TextUtils.isEmpty(text) ? mLastResponse : text + "\n" + mLastResponse;
+
+ // Send a new line of conversation to update the Activity, unless the incoming text was
+ // empty.
+ if (!TextUtils.isEmpty(text)) {
+ broadcastMessage(line);
+ }
+ NotificationManagerCompat.from(this).cancelAll();
+ showNotification();
+ mCompleteConversation.append("\n" + line);
+ }
+
+ private void broadcastMessage(String message) {
+ Intent intent = new Intent(MainActivity.ACTION_NOTIFY);
+ intent.putExtra(MainActivity.EXTRA_MESSAGE, message);
+ mBroadcastManager.sendBroadcast(intent);
+ }
+
+ @Override
+ public void onDestroy() {
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "Chat Service stopped");
+ }
+ NotificationManagerCompat.from(this).cancel(0);
+ mBroadcastManager = null;
+ super.onDestroy();
+ }
+}
diff --git a/samples/wearable/ElizaChat/src/main/res/drawable-hdpi/ic_full_reply.png b/samples/wearable/ElizaChat/src/main/res/drawable-hdpi/ic_full_reply.png
new file mode 100644
index 000000000..66388d5fa
Binary files /dev/null and b/samples/wearable/ElizaChat/src/main/res/drawable-hdpi/ic_full_reply.png differ
diff --git a/samples/wearable/ElizaChat/src/main/res/drawable-mdpi/ic_full_reply.png b/samples/wearable/ElizaChat/src/main/res/drawable-mdpi/ic_full_reply.png
new file mode 100644
index 000000000..60ce9f9c5
Binary files /dev/null and b/samples/wearable/ElizaChat/src/main/res/drawable-mdpi/ic_full_reply.png differ
diff --git a/samples/wearable/ElizaChat/src/main/res/drawable-nodpi/bg_eliza.png b/samples/wearable/ElizaChat/src/main/res/drawable-nodpi/bg_eliza.png
new file mode 100644
index 000000000..3bbdf48a8
Binary files /dev/null and b/samples/wearable/ElizaChat/src/main/res/drawable-nodpi/bg_eliza.png differ
diff --git a/samples/wearable/ElizaChat/src/main/res/drawable-xhdpi/ic_full_reply.png b/samples/wearable/ElizaChat/src/main/res/drawable-xhdpi/ic_full_reply.png
new file mode 100644
index 000000000..dba6fa7b0
Binary files /dev/null and b/samples/wearable/ElizaChat/src/main/res/drawable-xhdpi/ic_full_reply.png differ
diff --git a/samples/wearable/ElizaChat/src/main/res/layout/activity_main.xml b/samples/wearable/ElizaChat/src/main/res/layout/activity_main.xml
new file mode 100644
index 000000000..6ffed8ea2
--- /dev/null
+++ b/samples/wearable/ElizaChat/src/main/res/layout/activity_main.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
diff --git a/samples/wearable/ElizaChat/src/main/res/menu/main.xml b/samples/wearable/ElizaChat/src/main/res/menu/main.xml
new file mode 100644
index 000000000..2ec4cf776
--- /dev/null
+++ b/samples/wearable/ElizaChat/src/main/res/menu/main.xml
@@ -0,0 +1,9 @@
+
+
\ No newline at end of file
diff --git a/samples/wearable/ElizaChat/src/main/res/mipmap-hdpi/ic_app_eliza.png b/samples/wearable/ElizaChat/src/main/res/mipmap-hdpi/ic_app_eliza.png
new file mode 100644
index 000000000..1bdb14751
Binary files /dev/null and b/samples/wearable/ElizaChat/src/main/res/mipmap-hdpi/ic_app_eliza.png differ
diff --git a/samples/wearable/ElizaChat/src/main/res/mipmap-mdpi/ic_app_eliza.png b/samples/wearable/ElizaChat/src/main/res/mipmap-mdpi/ic_app_eliza.png
new file mode 100644
index 000000000..2e0e1980c
Binary files /dev/null and b/samples/wearable/ElizaChat/src/main/res/mipmap-mdpi/ic_app_eliza.png differ
diff --git a/samples/wearable/ElizaChat/src/main/res/mipmap-xhdpi/ic_app_eliza.png b/samples/wearable/ElizaChat/src/main/res/mipmap-xhdpi/ic_app_eliza.png
new file mode 100644
index 000000000..8d0f43642
Binary files /dev/null and b/samples/wearable/ElizaChat/src/main/res/mipmap-xhdpi/ic_app_eliza.png differ
diff --git a/samples/wearable/ElizaChat/src/main/res/mipmap-xxhdpi/ic_app_eliza.png b/samples/wearable/ElizaChat/src/main/res/mipmap-xxhdpi/ic_app_eliza.png
new file mode 100644
index 000000000..e72b96752
Binary files /dev/null and b/samples/wearable/ElizaChat/src/main/res/mipmap-xxhdpi/ic_app_eliza.png differ
diff --git a/samples/wearable/ElizaChat/src/main/res/mipmap-xxxhdpi/ic_app_eliza.png b/samples/wearable/ElizaChat/src/main/res/mipmap-xxxhdpi/ic_app_eliza.png
new file mode 100644
index 000000000..06ea0793c
Binary files /dev/null and b/samples/wearable/ElizaChat/src/main/res/mipmap-xxxhdpi/ic_app_eliza.png differ
diff --git a/samples/wearable/ElizaChat/src/main/res/values/dimens.xml b/samples/wearable/ElizaChat/src/main/res/values/dimens.xml
new file mode 100644
index 000000000..47c822467
--- /dev/null
+++ b/samples/wearable/ElizaChat/src/main/res/values/dimens.xml
@@ -0,0 +1,5 @@
+
+
+ 16dp
+ 16dp
+
diff --git a/samples/wearable/ElizaChat/src/main/res/values/strings.xml b/samples/wearable/ElizaChat/src/main/res/values/strings.xml
new file mode 100644
index 000000000..20a31d660
--- /dev/null
+++ b/samples/wearable/ElizaChat/src/main/res/values/strings.xml
@@ -0,0 +1,11 @@
+
+
+
+ ElizaChat
+ Send notification!
+ Eliza
+ Answer Eliza
+ Reply
+ End Chat Session
+
+
diff --git a/samples/wearable/ElizaChat/src/main/res/values/styles.xml b/samples/wearable/ElizaChat/src/main/res/values/styles.xml
new file mode 100644
index 000000000..ff6c9d2c0
--- /dev/null
+++ b/samples/wearable/ElizaChat/src/main/res/values/styles.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
diff --git a/samples/wearable/FindMyPhone/Application/build.gradle b/samples/wearable/FindMyPhone/Application/build.gradle
new file mode 100644
index 000000000..7de0d36a1
--- /dev/null
+++ b/samples/wearable/FindMyPhone/Application/build.gradle
@@ -0,0 +1,30 @@
+apply plugin: 'android'
+
+android {
+ compileSdkVersion 20
+ buildToolsVersion '20'
+
+ defaultConfig {
+ minSdkVersion 18
+ targetSdkVersion 20
+ versionCode 1
+ versionName "1.0"
+ }
+
+ buildTypes {
+ release {
+ runProguard false
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
+ }
+ }
+
+ aaptOptions {
+ noCompress 'apk'
+ }
+}
+
+dependencies {
+ compile 'com.google.android.gms:play-services:5.0.+@aar'
+ compile "com.android.support:support-v4:20.0.+"
+ wearApp project(':Wearable')
+}
\ No newline at end of file
diff --git a/samples/wearable/FindMyPhone/Application/proguard-rules.txt b/samples/wearable/FindMyPhone/Application/proguard-rules.txt
new file mode 100644
index 000000000..08e5bdc8d
--- /dev/null
+++ b/samples/wearable/FindMyPhone/Application/proguard-rules.txt
@@ -0,0 +1,22 @@
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
+-dontwarn android.support.wearable.view.DelayedConfirmationView
+-dontwarn android.support.wearable.view.CircledImageView
diff --git a/samples/wearable/FindMyPhone/Application/project.properties b/samples/wearable/FindMyPhone/Application/project.properties
new file mode 100644
index 000000000..4ab125693
--- /dev/null
+++ b/samples/wearable/FindMyPhone/Application/project.properties
@@ -0,0 +1,14 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system edit
+# "ant.properties", and override values to adapt the script to your
+# project structure.
+#
+# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
+#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
+
+# Project target.
+target=android-19
diff --git a/samples/wearable/FindMyPhone/Application/src/main/AndroidManifest.xml b/samples/wearable/FindMyPhone/Application/src/main/AndroidManifest.xml
new file mode 100644
index 000000000..97fd35f6f
--- /dev/null
+++ b/samples/wearable/FindMyPhone/Application/src/main/AndroidManifest.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/wearable/FindMyPhone/Application/src/main/java/com/example/android/wearable/findphone/SoundAlarmListenerService.java b/samples/wearable/FindMyPhone/Application/src/main/java/com/example/android/wearable/findphone/SoundAlarmListenerService.java
new file mode 100644
index 000000000..c6dd4605b
--- /dev/null
+++ b/samples/wearable/FindMyPhone/Application/src/main/java/com/example/android/wearable/findphone/SoundAlarmListenerService.java
@@ -0,0 +1,85 @@
+package com.example.android.wearable.findphone;
+
+import android.media.AudioManager;
+import android.media.MediaPlayer;
+import android.media.RingtoneManager;
+import android.net.Uri;
+import android.util.Log;
+
+import com.google.android.gms.wearable.DataEvent;
+import com.google.android.gms.wearable.DataEventBuffer;
+import com.google.android.gms.wearable.DataMap;
+import com.google.android.gms.wearable.WearableListenerService;
+
+import java.io.IOException;
+
+/**
+ * Listens for disconnection from home device.
+ */
+public class SoundAlarmListenerService extends WearableListenerService {
+
+ private static final String TAG = "ExampleFindPhoneApp";
+
+ private static final String FIELD_ALARM_ON = "alarm_on";
+
+ private AudioManager mAudioManager;
+ private static int mOrigVolume;
+ private int mMaxVolume;
+ private Uri mAlarmSound;
+ private MediaPlayer mMediaPlayer;
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
+ mOrigVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_ALARM);
+ mMaxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM);
+ mAlarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
+ mMediaPlayer = new MediaPlayer();
+ }
+
+ @Override
+ public void onDestroy() {
+ // Reset the alarm volume to the user's original setting.
+ mAudioManager.setStreamVolume(AudioManager.STREAM_ALARM, mOrigVolume, 0);
+ mMediaPlayer.release();
+ super.onDestroy();
+ }
+
+ @Override
+ public void onDataChanged(DataEventBuffer dataEvents) {
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "onDataChanged: " + dataEvents + " for " + getPackageName());
+ }
+ for (DataEvent event : dataEvents) {
+ if (event.getType() == DataEvent.TYPE_DELETED) {
+ Log.i(TAG, event + " deleted");
+ } else if (event.getType() == DataEvent.TYPE_CHANGED) {
+ Boolean alarmOn =
+ DataMap.fromByteArray(event.getDataItem().getData()).get(FIELD_ALARM_ON);
+ if (alarmOn) {
+ mOrigVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_ALARM);
+ mMediaPlayer.reset();
+ // Sound alarm at max volume.
+ mAudioManager.setStreamVolume(AudioManager.STREAM_ALARM, mMaxVolume, 0);
+ mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
+ try {
+ mMediaPlayer.setDataSource(getApplicationContext(), mAlarmSound);
+ mMediaPlayer.prepare();
+ } catch (IOException e) {
+ Log.e(TAG, "Failed to prepare media player to play alarm.", e);
+ }
+ mMediaPlayer.start();
+ } else {
+ // Reset the alarm volume to the user's original setting.
+ mAudioManager.setStreamVolume(AudioManager.STREAM_ALARM, mOrigVolume, 0);
+ if (mMediaPlayer.isPlaying()) {
+ mMediaPlayer.stop();
+ }
+ }
+ }
+ }
+ dataEvents.close();
+ }
+
+}
diff --git a/samples/wearable/FindMyPhone/Application/src/main/res/drawable-hdpi/ic_launcher.png b/samples/wearable/FindMyPhone/Application/src/main/res/drawable-hdpi/ic_launcher.png
new file mode 100644
index 000000000..43254bd67
Binary files /dev/null and b/samples/wearable/FindMyPhone/Application/src/main/res/drawable-hdpi/ic_launcher.png differ
diff --git a/samples/wearable/FindMyPhone/Application/src/main/res/drawable-mdpi/ic_launcher.png b/samples/wearable/FindMyPhone/Application/src/main/res/drawable-mdpi/ic_launcher.png
new file mode 100644
index 000000000..de255d6bb
Binary files /dev/null and b/samples/wearable/FindMyPhone/Application/src/main/res/drawable-mdpi/ic_launcher.png differ
diff --git a/samples/wearable/FindMyPhone/Application/src/main/res/drawable-xhdpi/ic_launcher.png b/samples/wearable/FindMyPhone/Application/src/main/res/drawable-xhdpi/ic_launcher.png
new file mode 100644
index 000000000..5a849da2e
Binary files /dev/null and b/samples/wearable/FindMyPhone/Application/src/main/res/drawable-xhdpi/ic_launcher.png differ
diff --git a/samples/wearable/FindMyPhone/Application/src/main/res/drawable-xxhdpi/ic_launcher.png b/samples/wearable/FindMyPhone/Application/src/main/res/drawable-xxhdpi/ic_launcher.png
new file mode 100644
index 000000000..96a7cb8e1
Binary files /dev/null and b/samples/wearable/FindMyPhone/Application/src/main/res/drawable-xxhdpi/ic_launcher.png differ
diff --git a/samples/wearable/FindMyPhone/Application/src/main/res/values/strings.xml b/samples/wearable/FindMyPhone/Application/src/main/res/values/strings.xml
new file mode 100644
index 000000000..faf03effc
--- /dev/null
+++ b/samples/wearable/FindMyPhone/Application/src/main/res/values/strings.xml
@@ -0,0 +1,6 @@
+
+
+
+ Find My Phone
+
+
\ No newline at end of file
diff --git a/samples/wearable/FindMyPhone/Wearable/build.gradle b/samples/wearable/FindMyPhone/Wearable/build.gradle
new file mode 100644
index 000000000..7a813455f
--- /dev/null
+++ b/samples/wearable/FindMyPhone/Wearable/build.gradle
@@ -0,0 +1,26 @@
+apply plugin: 'android'
+
+android {
+ compileSdkVersion 20
+ buildToolsVersion '20'
+
+ defaultConfig {
+ minSdkVersion 20
+ targetSdkVersion 20
+ versionCode 1
+ versionName "1.0"
+ }
+
+ buildTypes {
+ release {
+ runProguard false
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
+ }
+ }
+}
+
+dependencies {
+ compile 'com.google.android.gms:play-services:5.+@aar'
+ compile "com.android.support:support-v13:20.0.+"
+ compile "com.google.android.support:wearable:1.0.+"
+}
\ No newline at end of file
diff --git a/samples/wearable/FindMyPhone/Wearable/proguard-rules.txt b/samples/wearable/FindMyPhone/Wearable/proguard-rules.txt
new file mode 100644
index 000000000..08e5bdc8d
--- /dev/null
+++ b/samples/wearable/FindMyPhone/Wearable/proguard-rules.txt
@@ -0,0 +1,22 @@
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
+-dontwarn android.support.wearable.view.DelayedConfirmationView
+-dontwarn android.support.wearable.view.CircledImageView
diff --git a/samples/wearable/FindMyPhone/Wearable/project.properties b/samples/wearable/FindMyPhone/Wearable/project.properties
new file mode 100644
index 000000000..4ab125693
--- /dev/null
+++ b/samples/wearable/FindMyPhone/Wearable/project.properties
@@ -0,0 +1,14 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system edit
+# "ant.properties", and override values to adapt the script to your
+# project structure.
+#
+# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
+#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
+
+# Project target.
+target=android-19
diff --git a/samples/wearable/FindMyPhone/Wearable/src/main/AndroidManifest.xml b/samples/wearable/FindMyPhone/Wearable/src/main/AndroidManifest.xml
new file mode 100644
index 000000000..4208898a0
--- /dev/null
+++ b/samples/wearable/FindMyPhone/Wearable/src/main/AndroidManifest.xml
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/wearable/FindMyPhone/Wearable/src/main/java/com/example/android/wearable/findphone/DisconnectListenerService.java b/samples/wearable/FindMyPhone/Wearable/src/main/java/com/example/android/wearable/findphone/DisconnectListenerService.java
new file mode 100644
index 000000000..dacd6087e
--- /dev/null
+++ b/samples/wearable/FindMyPhone/Wearable/src/main/java/com/example/android/wearable/findphone/DisconnectListenerService.java
@@ -0,0 +1,39 @@
+package com.example.android.wearable.findphone;
+
+import android.app.Notification;
+import android.app.NotificationManager;
+
+import com.google.android.gms.wearable.WearableListenerService;
+
+/**
+ * Listens for disconnection from home device.
+ */
+public class DisconnectListenerService extends WearableListenerService {
+
+ private static final String TAG = "ExampleFindPhoneApp";
+
+ private static final int FORGOT_PHONE_NOTIFICATION_ID = 1;
+
+ @Override
+ public void onPeerDisconnected(com.google.android.gms.wearable.Node peer) {
+ // Create a "forgot phone" notification when phone connection is broken.
+ Notification.Builder notificationBuilder = new Notification.Builder(this)
+ .setContentTitle(getString(R.string.left_phone_title))
+ .setContentText(getString(R.string.left_phone_content))
+ .setVibrate(new long[] {0, 200}) // Vibrate for 200 milliseconds.
+ .setSmallIcon(R.drawable.ic_launcher)
+ .setLocalOnly(true)
+ .setPriority(Notification.PRIORITY_MAX);
+ Notification card = notificationBuilder.build();
+ ((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
+ .notify(FORGOT_PHONE_NOTIFICATION_ID, card);
+ }
+
+ @Override
+ public void onPeerConnected(com.google.android.gms.wearable.Node peer) {
+ // Remove the "forgot phone" notification when connection is restored.
+ ((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
+ .cancel(FORGOT_PHONE_NOTIFICATION_ID);
+ }
+
+}
diff --git a/samples/wearable/FindMyPhone/Wearable/src/main/java/com/example/android/wearable/findphone/FindPhoneActivity.java b/samples/wearable/FindMyPhone/Wearable/src/main/java/com/example/android/wearable/findphone/FindPhoneActivity.java
new file mode 100644
index 000000000..10e13451c
--- /dev/null
+++ b/samples/wearable/FindMyPhone/Wearable/src/main/java/com/example/android/wearable/findphone/FindPhoneActivity.java
@@ -0,0 +1,71 @@
+package com.example.android.wearable.findphone;
+
+import android.app.Activity;
+import android.app.Notification;
+import android.app.Notification.Action;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.text.Spannable;
+import android.text.SpannableString;
+import android.text.style.RelativeSizeSpan;
+
+
+public class FindPhoneActivity extends Activity {
+
+ private static final int FIND_PHONE_NOTIFICATION_ID = 2;
+ private static Notification.Builder notification;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ // Create a notification with an action to toggle an alarm on the phone.
+ Intent toggleAlarmOperation = new Intent(this, FindPhoneService.class);
+ toggleAlarmOperation.setAction(FindPhoneService.ACTION_TOGGLE_ALARM);
+ PendingIntent toggleAlarmIntent = PendingIntent.getService(this, 0, toggleAlarmOperation,
+ PendingIntent.FLAG_CANCEL_CURRENT);
+ Action alarmAction = new Action(R.drawable.alarm_action_icon, "", toggleAlarmIntent);
+ // This intent turns off the alarm if the user dismisses the card from the wearable.
+ Intent cancelAlarmOperation = new Intent(this, FindPhoneService.class);
+ cancelAlarmOperation.setAction(FindPhoneService.ACTION_CANCEL_ALARM);
+ PendingIntent cancelAlarmIntent = PendingIntent.getService(this, 0, cancelAlarmOperation,
+ PendingIntent.FLAG_CANCEL_CURRENT);
+ // Use a spannable string for the notification title to resize it.
+ SpannableString title = new SpannableString(getString(R.string.app_name));
+ title.setSpan(new RelativeSizeSpan(0.85f), 0, title.length(), Spannable.SPAN_POINT_MARK);
+ notification = new Notification.Builder(this)
+ .setContentTitle(title)
+ .setContentText(getString(R.string.turn_alarm_on))
+ .setSmallIcon(R.drawable.ic_launcher)
+ .setVibrate(new long[] {0, 50}) // Vibrate to bring card to top of stream.
+ .setDeleteIntent(cancelAlarmIntent)
+ .extend(new Notification.WearableExtender()
+ .addAction(alarmAction)
+ .setContentAction(0)
+ .setHintHideIcon(true))
+ .setLocalOnly(true)
+ .setPriority(Notification.PRIORITY_MAX);
+ ((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
+ .notify(FIND_PHONE_NOTIFICATION_ID, notification.build());
+
+ finish();
+ }
+
+ /**
+ * Updates the text on the wearable notification. This is used so the notification reflects the
+ * current state of the alarm on the phone. For instance, if the alarm is turned on, the
+ * notification text indicates that the user can tap it to turn it off, and vice-versa.
+ *
+ * @param context
+ * @param notificationText The new text to display on the wearable notification.
+ */
+ public static void updateNotification(Context context, String notificationText) {
+ notification.setContentText(notificationText);
+ ((NotificationManager) context.getSystemService(NOTIFICATION_SERVICE))
+ .notify(FIND_PHONE_NOTIFICATION_ID, notification.build());
+ }
+
+}
\ No newline at end of file
diff --git a/samples/wearable/FindMyPhone/Wearable/src/main/java/com/example/android/wearable/findphone/FindPhoneService.java b/samples/wearable/FindMyPhone/Wearable/src/main/java/com/example/android/wearable/findphone/FindPhoneService.java
new file mode 100644
index 000000000..df0a724c1
--- /dev/null
+++ b/samples/wearable/FindMyPhone/Wearable/src/main/java/com/example/android/wearable/findphone/FindPhoneService.java
@@ -0,0 +1,105 @@
+package com.example.android.wearable.findphone;
+
+import android.app.IntentService;
+import android.content.Intent;
+import android.os.Bundle;
+import android.util.Log;
+
+import com.google.android.gms.common.ConnectionResult;
+import com.google.android.gms.common.api.GoogleApiClient;
+import com.google.android.gms.wearable.DataItemBuffer;
+import com.google.android.gms.wearable.DataMap;
+import com.google.android.gms.wearable.PutDataMapRequest;
+import com.google.android.gms.wearable.Wearable;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Creates a sound on the paired phone to find it.
+ */
+public class FindPhoneService extends IntentService implements GoogleApiClient.ConnectionCallbacks,
+ GoogleApiClient.OnConnectionFailedListener {
+
+ private static final String TAG = "ExampleFindPhoneApp";
+
+ private static final String FIELD_ALARM_ON = "alarm_on";
+ private static final String PATH_SOUND_ALARM = "/sound_alarm";
+ public static final String ACTION_TOGGLE_ALARM = "action_toggle_alarm";
+ public static final String ACTION_CANCEL_ALARM = "action_alarm_off";
+
+ // Timeout for making a connection to GoogleApiClient (in milliseconds).
+ private static final long CONNECTION_TIME_OUT_MS = 100;
+ private GoogleApiClient mGoogleApiClient;
+
+ public FindPhoneService() {
+ super(FindPhoneService.class.getSimpleName());
+ }
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ mGoogleApiClient = new GoogleApiClient.Builder(this)
+ .addApi(Wearable.API)
+ .addConnectionCallbacks(this)
+ .addOnConnectionFailedListener(this)
+ .build();
+ }
+
+ @Override
+ protected void onHandleIntent(Intent intent) {
+ mGoogleApiClient.blockingConnect(CONNECTION_TIME_OUT_MS, TimeUnit.MILLISECONDS);
+ if (Log.isLoggable(TAG, Log.VERBOSE)) {
+ Log.v(TAG, "FindPhoneService.onHandleIntent");
+ }
+ if (mGoogleApiClient.isConnected()) {
+ // Set the alarm off by default.
+ boolean alarmOn = false;
+ if (intent.getAction().equals(ACTION_TOGGLE_ALARM)) {
+ // Get current state of the alarm.
+ DataItemBuffer result = Wearable.DataApi.getDataItems(mGoogleApiClient).await();
+ if (result.getStatus().isSuccess()) {
+ if (result.getCount() == 1) {
+ alarmOn = DataMap.fromByteArray(result.get(0).getData())
+ .getBoolean(FIELD_ALARM_ON, false);
+ } else {
+ Log.e(TAG, "Unexpected number of DataItems found.\n"
+ + "\tExpected: 1\n"
+ + "\tActual: " + result.getCount());
+ }
+ } else if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "onHandleIntent: failed to get current alarm state");
+ }
+ result.close();
+ // Toggle alarm.
+ alarmOn = !alarmOn;
+ // Change notification text based on new value of alarmOn.
+ String notificationText = alarmOn ? getString(R.string.turn_alarm_off)
+ : getString(R.string.turn_alarm_on);
+ FindPhoneActivity.updateNotification(this, notificationText);
+ }
+ // Use alarmOn boolean to update the DataItem - phone will respond accordingly
+ // when it receives the change.
+ PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(PATH_SOUND_ALARM);
+ putDataMapRequest.getDataMap().putBoolean(FIELD_ALARM_ON, alarmOn);
+ Wearable.DataApi.putDataItem(mGoogleApiClient, putDataMapRequest.asPutDataRequest())
+ .await();
+ } else {
+ Log.e(TAG, "Failed to toggle alarm on phone - Client disconnected from Google Play "
+ + "Services");
+ }
+ mGoogleApiClient.disconnect();
+ }
+
+ @Override
+ public void onConnected(Bundle connectionHint) {
+ }
+
+ @Override
+ public void onConnectionSuspended(int cause) {
+ }
+
+ @Override
+ public void onConnectionFailed(ConnectionResult result) {
+ }
+
+}
diff --git a/samples/wearable/FindMyPhone/Wearable/src/main/res/drawable-hdpi/alarm_action_icon.png b/samples/wearable/FindMyPhone/Wearable/src/main/res/drawable-hdpi/alarm_action_icon.png
new file mode 100644
index 000000000..4331a5121
Binary files /dev/null and b/samples/wearable/FindMyPhone/Wearable/src/main/res/drawable-hdpi/alarm_action_icon.png differ
diff --git a/samples/wearable/FindMyPhone/Wearable/src/main/res/drawable-hdpi/ic_launcher.png b/samples/wearable/FindMyPhone/Wearable/src/main/res/drawable-hdpi/ic_launcher.png
new file mode 100644
index 000000000..43254bd67
Binary files /dev/null and b/samples/wearable/FindMyPhone/Wearable/src/main/res/drawable-hdpi/ic_launcher.png differ
diff --git a/samples/wearable/FindMyPhone/Wearable/src/main/res/drawable-mdpi/ic_launcher.png b/samples/wearable/FindMyPhone/Wearable/src/main/res/drawable-mdpi/ic_launcher.png
new file mode 100644
index 000000000..de255d6bb
Binary files /dev/null and b/samples/wearable/FindMyPhone/Wearable/src/main/res/drawable-mdpi/ic_launcher.png differ
diff --git a/samples/wearable/FindMyPhone/Wearable/src/main/res/drawable-xhdpi/ic_launcher.png b/samples/wearable/FindMyPhone/Wearable/src/main/res/drawable-xhdpi/ic_launcher.png
new file mode 100644
index 000000000..5a849da2e
Binary files /dev/null and b/samples/wearable/FindMyPhone/Wearable/src/main/res/drawable-xhdpi/ic_launcher.png differ
diff --git a/samples/wearable/FindMyPhone/Wearable/src/main/res/drawable-xxhdpi/ic_launcher.png b/samples/wearable/FindMyPhone/Wearable/src/main/res/drawable-xxhdpi/ic_launcher.png
new file mode 100644
index 000000000..96a7cb8e1
Binary files /dev/null and b/samples/wearable/FindMyPhone/Wearable/src/main/res/drawable-xxhdpi/ic_launcher.png differ
diff --git a/samples/wearable/FindMyPhone/Wearable/src/main/res/values/strings.xml b/samples/wearable/FindMyPhone/Wearable/src/main/res/values/strings.xml
new file mode 100644
index 000000000..b72dc82b5
--- /dev/null
+++ b/samples/wearable/FindMyPhone/Wearable/src/main/res/values/strings.xml
@@ -0,0 +1,10 @@
+
+
+
+ Find My Phone
+ Forgetting something?
+ You may have left your phone behind.
+ Tap to sound an alarm on phone.
+ Tap to stop the alarm.
+
+
diff --git a/samples/wearable/FindMyPhone/build.gradle b/samples/wearable/FindMyPhone/build.gradle
new file mode 100644
index 000000000..f9e56eeb4
--- /dev/null
+++ b/samples/wearable/FindMyPhone/build.gradle
@@ -0,0 +1,16 @@
+// Top-level build file where you can add configuration options common to all sub-projects/modules.
+
+buildscript {
+ repositories {
+ mavenCentral()
+ }
+ dependencies {
+ classpath 'com.android.tools.build:gradle:0.11.+'
+ }
+}
+
+allprojects {
+ repositories {
+ mavenCentral()
+ }
+}
\ No newline at end of file
diff --git a/samples/wearable/FindMyPhone/gradle.properties b/samples/wearable/FindMyPhone/gradle.properties
new file mode 100644
index 000000000..5d08ba75b
--- /dev/null
+++ b/samples/wearable/FindMyPhone/gradle.properties
@@ -0,0 +1,18 @@
+# Project-wide Gradle settings.
+
+# IDE (e.g. Android Studio) users:
+# Settings specified in this file will override any Gradle settings
+# configured through the IDE.
+
+# For more details on how to configure your build environment visit
+# http://www.gradle.org/docs/current/userguide/build_environment.html
+
+# Specifies the JVM arguments used for the daemon process.
+# The setting is particularly useful for tweaking memory settings.
+# Default value: -Xmx10248m -XX:MaxPermSize=256m
+# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
+
+# When configured, Gradle will run in incubating parallel mode.
+# This option should only be used with decoupled projects. More details, visit
+# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
+# org.gradle.parallel=true
\ No newline at end of file
diff --git a/samples/wearable/FindMyPhone/gradle/wrapper/gradle-wrapper.jar b/samples/wearable/FindMyPhone/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 000000000..583859812
Binary files /dev/null and b/samples/wearable/FindMyPhone/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/samples/wearable/FindMyPhone/gradle/wrapper/gradle-wrapper.properties b/samples/wearable/FindMyPhone/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 000000000..e83e46081
--- /dev/null
+++ b/samples/wearable/FindMyPhone/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Fri Mar 14 14:02:22 PDT 2014
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-all.zip
diff --git a/samples/wearable/FindMyPhone/gradlew b/samples/wearable/FindMyPhone/gradlew
new file mode 100755
index 000000000..91a7e269e
--- /dev/null
+++ b/samples/wearable/FindMyPhone/gradlew
@@ -0,0 +1,164 @@
+#!/usr/bin/env bash
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+ echo "$*"
+}
+
+die ( ) {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+esac
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched.
+if $cygwin ; then
+ [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+fi
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >&-
+APP_HOME="`pwd -P`"
+cd "$SAVED" >&-
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+ JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
diff --git a/samples/wearable/FindMyPhone/gradlew.bat b/samples/wearable/FindMyPhone/gradlew.bat
new file mode 100644
index 000000000..aec99730b
--- /dev/null
+++ b/samples/wearable/FindMyPhone/gradlew.bat
@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windowz variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%@eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/samples/wearable/FindMyPhone/settings.gradle b/samples/wearable/FindMyPhone/settings.gradle
new file mode 100644
index 000000000..f3f25a547
--- /dev/null
+++ b/samples/wearable/FindMyPhone/settings.gradle
@@ -0,0 +1 @@
+include 'Wearable', 'Application'
diff --git a/samples/wearable/Flashlight/Wearable/build.gradle b/samples/wearable/Flashlight/Wearable/build.gradle
new file mode 100644
index 000000000..58ffd2cf4
--- /dev/null
+++ b/samples/wearable/Flashlight/Wearable/build.gradle
@@ -0,0 +1,29 @@
+apply plugin: 'android'
+
+android {
+ compileSdkVersion 20
+ buildToolsVersion '20'
+
+ defaultConfig {
+ minSdkVersion 20
+ targetSdkVersion 20
+ versionCode 1
+ versionName "1.0"
+ }
+
+ buildTypes {
+ release {
+ runProguard false
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
+ }
+ }
+
+ lintOptions {
+ abortOnError false
+ }
+}
+
+dependencies {
+ compile "com.android.support:support-v13:20.0.+"
+ compile "com.google.android.support:wearable:1.0.+"
+}
diff --git a/samples/wearable/Flashlight/Wearable/proguard-rules.txt b/samples/wearable/Flashlight/Wearable/proguard-rules.txt
new file mode 100644
index 000000000..277118ac5
--- /dev/null
+++ b/samples/wearable/Flashlight/Wearable/proguard-rules.txt
@@ -0,0 +1,44 @@
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add classes here when necessary.
+
+-keep class android.support.wearable.view.WearableListView {
+ private void setScrollAnimator(int);
+ private void setScrollVertically(int);
+}
+-keep class android.support.wearable.view.WearableListView.ViewHolder {
+ private void setFocusPaddingTop(int);
+ private void setFocusPaddingBottom(int);
+}
+
+# GmsCore Proguard rules.
+# See: https://developer.android.com/google/play-services/setup.html
+-keep class * extends java.util.ListResourceBundle {
+ protected Object[][] getContents();
+}
+
+# Keep SafeParcelable value, needed for reflection. This is required to support backwards
+# compatibility of some classes.
+-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
+ public static final *** NULL;
+}
+
+# Keep the names of classes/members we need for client functionality.
+-keepnames @com.google.android.gms.common.annotation.KeepName class *
+-keepclassmembernames class * {
+ @com.google.android.gms.common.annotation.KeepName *;
+}
+
+# Needed for Parcelable/SafeParcelable Creators to not get stripped
+-keepnames class * implements android.os.Parcelable {
+ public static final ** CREATOR;
+}
+
+# End GmsCore Proguard rules.
diff --git a/samples/wearable/Flashlight/Wearable/src/main/AndroidManifest.xml b/samples/wearable/Flashlight/Wearable/src/main/AndroidManifest.xml
new file mode 100644
index 000000000..ee05292e4
--- /dev/null
+++ b/samples/wearable/Flashlight/Wearable/src/main/AndroidManifest.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/wearable/Flashlight/Wearable/src/main/java/com/example/android/wearable/flashlight/MainActivity.java b/samples/wearable/Flashlight/Wearable/src/main/java/com/example/android/wearable/flashlight/MainActivity.java
new file mode 100644
index 000000000..f32b993e1
--- /dev/null
+++ b/samples/wearable/Flashlight/Wearable/src/main/java/com/example/android/wearable/flashlight/MainActivity.java
@@ -0,0 +1,109 @@
+package com.example.android.wearable.flashlight;
+
+import android.app.Activity;
+import android.app.Fragment;
+import android.app.FragmentManager;
+import android.os.Bundle;
+import android.support.v13.app.FragmentPagerAdapter;
+import android.support.v4.view.ViewPager;
+import android.support.v4.view.ViewPager.OnPageChangeListener;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import java.util.ArrayList;
+
+/**
+ * Let there be light.
+ */
+public class MainActivity extends Activity {
+
+ private ViewPager mViewPager;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.main);
+ mViewPager = (ViewPager) findViewById(R.id.pager);
+ final LightFragmentAdapter adapter = new LightFragmentAdapter(getFragmentManager());
+ adapter.addFragment(new WhiteLightFragment());
+ final PartyLightFragment partyFragment = new PartyLightFragment();
+ adapter.addFragment(partyFragment);
+ mViewPager.setAdapter(adapter);
+ mViewPager.setOnPageChangeListener(new OnPageChangeListener() {
+
+ @Override
+ public void onPageSelected(int position) {
+ if (position == 1) {
+ partyFragment.startCycling();
+ } else {
+ partyFragment.stopCycling();
+ }
+ }
+
+ @Override
+ public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
+ }
+
+ @Override
+ public void onPageScrollStateChanged(int state) {
+ }
+ });
+ }
+
+ static class LightFragmentAdapter extends FragmentPagerAdapter {
+ private ArrayList mFragments;
+
+ public LightFragmentAdapter(FragmentManager fm) {
+ super(fm);
+ mFragments = new ArrayList();
+ }
+
+ @Override
+ public Fragment getItem(int position) {
+ return mFragments.get(position);
+ }
+
+ @Override
+ public int getCount() {
+ return mFragments.size();
+ }
+
+ public void addFragment(Fragment fragment) {
+ mFragments.add(fragment);
+ // Update the pager when adding a fragment.
+ notifyDataSetChanged();
+ }
+ }
+
+ static class WhiteLightFragment extends Fragment {
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ return inflater.inflate(R.layout.white_light, container, false);
+ }
+ }
+
+ static class PartyLightFragment extends Fragment {
+
+ private PartyLightView mView;
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ mView = (PartyLightView) inflater.inflate(R.layout.party_light, container, false);
+ return mView;
+ }
+
+ public void startCycling() {
+ mView.startCycling();
+ }
+
+ public void stopCycling() {
+ mView.stopCycling();
+ }
+
+ }
+}
diff --git a/samples/wearable/Flashlight/Wearable/src/main/java/com/example/android/wearable/flashlight/PartyLightView.java b/samples/wearable/Flashlight/Wearable/src/main/java/com/example/android/wearable/flashlight/PartyLightView.java
new file mode 100644
index 000000000..7de13096c
--- /dev/null
+++ b/samples/wearable/Flashlight/Wearable/src/main/java/com/example/android/wearable/flashlight/PartyLightView.java
@@ -0,0 +1,104 @@
+package com.example.android.wearable.flashlight;
+
+import android.animation.ArgbEvaluator;
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.os.Handler;
+import android.os.Message;
+import android.util.AttributeSet;
+import android.view.View;
+
+/**
+ * Flashing party lights!
+ */
+public class PartyLightView extends View {
+
+ private int[] mColors = new int[] {
+ Color.RED,
+ Color.GREEN,
+ Color.BLUE,
+ Color.CYAN,
+ Color.MAGENTA
+ };
+
+ private int mFromColorIndex;
+ private int mToColorIndex;
+
+ /**
+ * Value b/t 0 and 1.
+ */
+ private float mProgress;
+
+ private ArgbEvaluator mEvaluator;
+
+ private int mCurrentColor;
+
+ private Handler mHandler;
+
+ public PartyLightView(Context context) {
+ super(context);
+ init();
+ }
+
+ public PartyLightView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ init();
+ }
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+ canvas.drawColor(mCurrentColor);
+ super.onDraw(canvas);
+ }
+
+ public void startCycling() {
+ mHandler.sendEmptyMessage(0);
+ }
+
+ public void stopCycling() {
+ mHandler.removeMessages(0);
+ }
+
+ private void init() {
+ mEvaluator = new ArgbEvaluator();
+ mHandler = new Handler() {
+
+ @Override
+ public void handleMessage(Message msg) {
+ mCurrentColor = getColor(mProgress, mColors[mFromColorIndex],
+ mColors[mToColorIndex]);
+ postInvalidate();
+ mProgress += 0.1;
+ if (mProgress > 1.0) {
+ mFromColorIndex = mToColorIndex;
+ // Find a new color.
+ mToColorIndex++;
+ if (mToColorIndex >= mColors.length) {
+ mToColorIndex = 0;
+ }
+ }
+ mHandler.sendEmptyMessageDelayed(0, 100);
+ }
+ };
+ }
+
+ private int getColor(float fraction, int colorStart, int colorEnd) {
+ int startInt = colorStart;
+ int startA = (startInt >> 24) & 0xff;
+ int startR = (startInt >> 16) & 0xff;
+ int startG = (startInt >> 8) & 0xff;
+ int startB = startInt & 0xff;
+
+ int endInt = colorEnd;
+ int endA = (endInt >> 24) & 0xff;
+ int endR = (endInt >> 16) & 0xff;
+ int endG = (endInt >> 8) & 0xff;
+ int endB = endInt & 0xff;
+
+ return (startA + (int)(fraction * (endA - startA))) << 24 |
+ (startR + (int)(fraction * (endR - startR))) << 16 |
+ (startG + (int)(fraction * (endG - startG))) << 8 |
+ ((startB + (int)(fraction * (endB - startB))));
+ }
+}
diff --git a/samples/wearable/Flashlight/Wearable/src/main/res/drawable-hdpi/ic_launcher.png b/samples/wearable/Flashlight/Wearable/src/main/res/drawable-hdpi/ic_launcher.png
new file mode 100755
index 000000000..589f229d1
Binary files /dev/null and b/samples/wearable/Flashlight/Wearable/src/main/res/drawable-hdpi/ic_launcher.png differ
diff --git a/samples/wearable/Flashlight/Wearable/src/main/res/drawable-mdpi/ic_launcher.png b/samples/wearable/Flashlight/Wearable/src/main/res/drawable-mdpi/ic_launcher.png
new file mode 100755
index 000000000..77dd57139
Binary files /dev/null and b/samples/wearable/Flashlight/Wearable/src/main/res/drawable-mdpi/ic_launcher.png differ
diff --git a/samples/wearable/Flashlight/Wearable/src/main/res/drawable-xhdpi/ic_launcher.png b/samples/wearable/Flashlight/Wearable/src/main/res/drawable-xhdpi/ic_launcher.png
new file mode 100755
index 000000000..fe34ebe13
Binary files /dev/null and b/samples/wearable/Flashlight/Wearable/src/main/res/drawable-xhdpi/ic_launcher.png differ
diff --git a/samples/wearable/Flashlight/Wearable/src/main/res/drawable-xxhdpi/ic_launcher.png b/samples/wearable/Flashlight/Wearable/src/main/res/drawable-xxhdpi/ic_launcher.png
new file mode 100755
index 000000000..ab80bcd13
Binary files /dev/null and b/samples/wearable/Flashlight/Wearable/src/main/res/drawable-xxhdpi/ic_launcher.png differ
diff --git a/samples/wearable/Flashlight/Wearable/src/main/res/layout/main.xml b/samples/wearable/Flashlight/Wearable/src/main/res/layout/main.xml
new file mode 100644
index 000000000..934a92203
--- /dev/null
+++ b/samples/wearable/Flashlight/Wearable/src/main/res/layout/main.xml
@@ -0,0 +1,9 @@
+
+
diff --git a/samples/wearable/Flashlight/Wearable/src/main/res/layout/party_light.xml b/samples/wearable/Flashlight/Wearable/src/main/res/layout/party_light.xml
new file mode 100644
index 000000000..26d333b99
--- /dev/null
+++ b/samples/wearable/Flashlight/Wearable/src/main/res/layout/party_light.xml
@@ -0,0 +1,6 @@
+
+
diff --git a/samples/wearable/Flashlight/Wearable/src/main/res/layout/white_light.xml b/samples/wearable/Flashlight/Wearable/src/main/res/layout/white_light.xml
new file mode 100644
index 000000000..de3ad9fbc
--- /dev/null
+++ b/samples/wearable/Flashlight/Wearable/src/main/res/layout/white_light.xml
@@ -0,0 +1,6 @@
+
+
diff --git a/samples/wearable/Flashlight/Wearable/src/main/res/values/strings.xml b/samples/wearable/Flashlight/Wearable/src/main/res/values/strings.xml
new file mode 100644
index 000000000..06f24538b
--- /dev/null
+++ b/samples/wearable/Flashlight/Wearable/src/main/res/values/strings.xml
@@ -0,0 +1,5 @@
+
+
+ Flashlight
+
+
diff --git a/samples/wearable/Flashlight/build.gradle b/samples/wearable/Flashlight/build.gradle
new file mode 100644
index 000000000..4c8f6d8b9
--- /dev/null
+++ b/samples/wearable/Flashlight/build.gradle
@@ -0,0 +1,16 @@
+// Top-level build file where you can add configuration options common to all sub-projects/modules.
+
+buildscript {
+ repositories {
+ mavenCentral()
+ }
+ dependencies {
+ classpath 'com.android.tools.build:gradle:0.11.+'
+ }
+}
+
+allprojects {
+ repositories {
+ mavenCentral()
+ }
+}
diff --git a/samples/wearable/Flashlight/gradle/wrapper/gradle-wrapper.jar b/samples/wearable/Flashlight/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 000000000..583859812
Binary files /dev/null and b/samples/wearable/Flashlight/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/samples/wearable/Flashlight/gradle/wrapper/gradle-wrapper.properties b/samples/wearable/Flashlight/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 000000000..e83e46081
--- /dev/null
+++ b/samples/wearable/Flashlight/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Fri Mar 14 14:02:22 PDT 2014
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-all.zip
diff --git a/samples/wearable/Flashlight/gradlew b/samples/wearable/Flashlight/gradlew
new file mode 100755
index 000000000..91a7e269e
--- /dev/null
+++ b/samples/wearable/Flashlight/gradlew
@@ -0,0 +1,164 @@
+#!/usr/bin/env bash
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+ echo "$*"
+}
+
+die ( ) {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+esac
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched.
+if $cygwin ; then
+ [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+fi
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >&-
+APP_HOME="`pwd -P`"
+cd "$SAVED" >&-
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+ JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
diff --git a/samples/wearable/Flashlight/gradlew.bat b/samples/wearable/Flashlight/gradlew.bat
new file mode 100755
index 000000000..aec99730b
--- /dev/null
+++ b/samples/wearable/Flashlight/gradlew.bat
@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windowz variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%@eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/samples/wearable/Flashlight/settings.gradle b/samples/wearable/Flashlight/settings.gradle
new file mode 100644
index 000000000..1d97d30e1
--- /dev/null
+++ b/samples/wearable/Flashlight/settings.gradle
@@ -0,0 +1 @@
+include ':Wearable'
diff --git a/samples/wearable/Geofencing/Application/build.gradle b/samples/wearable/Geofencing/Application/build.gradle
new file mode 100644
index 000000000..7de0d36a1
--- /dev/null
+++ b/samples/wearable/Geofencing/Application/build.gradle
@@ -0,0 +1,30 @@
+apply plugin: 'android'
+
+android {
+ compileSdkVersion 20
+ buildToolsVersion '20'
+
+ defaultConfig {
+ minSdkVersion 18
+ targetSdkVersion 20
+ versionCode 1
+ versionName "1.0"
+ }
+
+ buildTypes {
+ release {
+ runProguard false
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
+ }
+ }
+
+ aaptOptions {
+ noCompress 'apk'
+ }
+}
+
+dependencies {
+ compile 'com.google.android.gms:play-services:5.0.+@aar'
+ compile "com.android.support:support-v4:20.0.+"
+ wearApp project(':Wearable')
+}
\ No newline at end of file
diff --git a/samples/wearable/Geofencing/Application/proguard-rules.txt b/samples/wearable/Geofencing/Application/proguard-rules.txt
new file mode 100644
index 000000000..5b89420db
--- /dev/null
+++ b/samples/wearable/Geofencing/Application/proguard-rules.txt
@@ -0,0 +1,20 @@
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
\ No newline at end of file
diff --git a/samples/wearable/Geofencing/Application/project.properties b/samples/wearable/Geofencing/Application/project.properties
new file mode 100644
index 000000000..4ab125693
--- /dev/null
+++ b/samples/wearable/Geofencing/Application/project.properties
@@ -0,0 +1,14 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system edit
+# "ant.properties", and override values to adapt the script to your
+# project structure.
+#
+# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
+#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
+
+# Project target.
+target=android-19
diff --git a/samples/wearable/Geofencing/Application/src/main/AndroidManifest.xml b/samples/wearable/Geofencing/Application/src/main/AndroidManifest.xml
new file mode 100644
index 000000000..d56f37d3e
--- /dev/null
+++ b/samples/wearable/Geofencing/Application/src/main/AndroidManifest.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/wearable/Geofencing/Application/src/main/java/com/example/android/wearable/geofencing/Constants.java b/samples/wearable/Geofencing/Application/src/main/java/com/example/android/wearable/geofencing/Constants.java
new file mode 100644
index 000000000..628acf26c
--- /dev/null
+++ b/samples/wearable/Geofencing/Application/src/main/java/com/example/android/wearable/geofencing/Constants.java
@@ -0,0 +1,61 @@
+package com.example.android.wearable.geofencing;
+
+import android.net.Uri;
+
+import com.google.android.gms.location.Geofence;
+
+/** Constants used in companion app. */
+public final class Constants {
+
+ private Constants() {
+ }
+
+ public static final String TAG = "ExampleGeofencingApp";
+
+ // Request code to attempt to resolve Google Play services connection failures.
+ public final static int CONNECTION_FAILURE_RESOLUTION_REQUEST = 9000;
+ // Timeout for making a connection to GoogleApiClient (in milliseconds).
+ public static final long CONNECTION_TIME_OUT_MS = 100;
+
+ // For the purposes of this demo, the geofences are hard-coded and should not expire.
+ // An app with dynamically-created geofences would want to include a reasonable expiration time.
+ public static final long GEOFENCE_EXPIRATION_TIME = Geofence.NEVER_EXPIRE;
+
+ // Geofence parameters for the Android building on Google's main campus in Mountain View.
+ public static final String ANDROID_BUILDING_ID = "1";
+ public static final double ANDROID_BUILDING_LATITUDE = 37.420092;
+ public static final double ANDROID_BUILDING_LONGITUDE = -122.083648;
+ public static final float ANDROID_BUILDING_RADIUS_METERS = 60.0f;
+
+ // Geofence parameters for the Yerba Buena Gardens near the Moscone Center in San Francisco.
+ public static final String YERBA_BUENA_ID = "2";
+ public static final double YERBA_BUENA_LATITUDE = 37.784886;
+ public static final double YERBA_BUENA_LONGITUDE = -122.402671;
+ public static final float YERBA_BUENA_RADIUS_METERS = 72.0f;
+
+
+ // The constants below are less interesting than those above.
+
+ // Path for the DataItem containing the last geofence id entered.
+ public static final String GEOFENCE_DATA_ITEM_PATH = "/geofenceid";
+ public static final Uri GEOFENCE_DATA_ITEM_URI =
+ new Uri.Builder().scheme("wear").path(GEOFENCE_DATA_ITEM_PATH).build();
+ public static final String KEY_GEOFENCE_ID = "geofence_id";
+
+ // Keys for flattened geofences stored in SharedPreferences.
+ public static final String KEY_LATITUDE = "com.example.wearable.geofencing.KEY_LATITUDE";
+ public static final String KEY_LONGITUDE = "com.example.wearable.geofencing.KEY_LONGITUDE";
+ public static final String KEY_RADIUS = "com.example.wearable.geofencing.KEY_RADIUS";
+ public static final String KEY_EXPIRATION_DURATION =
+ "com.example.wearable.geofencing.KEY_EXPIRATION_DURATION";
+ public static final String KEY_TRANSITION_TYPE =
+ "com.example.wearable.geofencing.KEY_TRANSITION_TYPE";
+ // The prefix for flattened geofence keys.
+ public static final String KEY_PREFIX = "com.example.wearable.geofencing.KEY";
+
+ // Invalid values, used to test geofence storage when retrieving geofences.
+ public static final long INVALID_LONG_VALUE = -999l;
+ public static final float INVALID_FLOAT_VALUE = -999.0f;
+ public static final int INVALID_INT_VALUE = -999;
+
+}
diff --git a/samples/wearable/Geofencing/Application/src/main/java/com/example/android/wearable/geofencing/GeofenceTransitionsIntentService.java b/samples/wearable/Geofencing/Application/src/main/java/com/example/android/wearable/geofencing/GeofenceTransitionsIntentService.java
new file mode 100644
index 000000000..d60b15da7
--- /dev/null
+++ b/samples/wearable/Geofencing/Application/src/main/java/com/example/android/wearable/geofencing/GeofenceTransitionsIntentService.java
@@ -0,0 +1,103 @@
+package com.example.android.wearable.geofencing;
+
+import static com.example.android.wearable.geofencing.Constants.CONNECTION_TIME_OUT_MS;
+import static com.example.android.wearable.geofencing.Constants.GEOFENCE_DATA_ITEM_PATH;
+import static com.example.android.wearable.geofencing.Constants.GEOFENCE_DATA_ITEM_URI;
+import static com.example.android.wearable.geofencing.Constants.KEY_GEOFENCE_ID;
+import static com.example.android.wearable.geofencing.Constants.TAG;
+
+import android.app.IntentService;
+import android.content.Intent;
+import android.os.Bundle;
+import android.util.Log;
+
+import com.google.android.gms.common.ConnectionResult;
+import com.google.android.gms.common.api.GoogleApiClient;
+import com.google.android.gms.location.Geofence;
+import com.google.android.gms.location.LocationClient;
+import com.google.android.gms.wearable.PutDataMapRequest;
+import com.google.android.gms.wearable.Wearable;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Listens for geofence transition changes.
+ */
+public class GeofenceTransitionsIntentService extends IntentService
+ implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
+
+ private GoogleApiClient mGoogleApiClient;
+
+ public GeofenceTransitionsIntentService() {
+ super(GeofenceTransitionsIntentService.class.getSimpleName());
+ }
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ mGoogleApiClient = new GoogleApiClient.Builder(this)
+ .addApi(Wearable.API)
+ .addConnectionCallbacks(this)
+ .addOnConnectionFailedListener(this)
+ .build();
+ }
+
+ /**
+ * Handles incoming intents.
+ * @param intent The Intent sent by Location Services. This Intent is provided to Location
+ * Services (inside a PendingIntent) when addGeofences() is called.
+ */
+ @Override
+ protected void onHandleIntent(Intent intent) {
+ // First check for errors.
+ if (LocationClient.hasError(intent)) {
+ int errorCode = LocationClient.getErrorCode(intent);
+ Log.e(TAG, "Location Services error: " + errorCode);
+ } else {
+ // Get the type of geofence transition (i.e. enter or exit in this sample).
+ int transitionType = LocationClient.getGeofenceTransition(intent);
+ // Create a DataItem when a user enters one of the geofences. The wearable app will
+ // receive this and create a notification to prompt him/her to check in.
+ if (Geofence.GEOFENCE_TRANSITION_ENTER == transitionType) {
+ // Connect to the Google Api service in preparation for sending a DataItem.
+ mGoogleApiClient.blockingConnect(CONNECTION_TIME_OUT_MS, TimeUnit.MILLISECONDS);
+ // Get the geofence id triggered. Note that only one geofence can be triggered at a
+ // time in this example, but in some cases you might want to consider the full list
+ // of geofences triggered.
+ String triggeredGeofenceId = LocationClient.getTriggeringGeofences(intent).get(0)
+ .getRequestId();
+ // Create a DataItem with this geofence's id. The wearable can use this to create
+ // a notification.
+ final PutDataMapRequest putDataMapRequest =
+ PutDataMapRequest.create(GEOFENCE_DATA_ITEM_PATH);
+ putDataMapRequest.getDataMap().putString(KEY_GEOFENCE_ID, triggeredGeofenceId);
+ if (mGoogleApiClient.isConnected()) {
+ Wearable.DataApi.putDataItem(
+ mGoogleApiClient, putDataMapRequest.asPutDataRequest()).await();
+ } else {
+ Log.e(TAG, "Failed to send data item: " + putDataMapRequest
+ + " - Client disconnected from Google Play Services");
+ }
+ mGoogleApiClient.disconnect();
+ } else if (Geofence.GEOFENCE_TRANSITION_EXIT == transitionType) {
+ // Delete the data item when leaving a geofence region.
+ mGoogleApiClient.blockingConnect(CONNECTION_TIME_OUT_MS, TimeUnit.MILLISECONDS);
+ Wearable.DataApi.deleteDataItems(mGoogleApiClient, GEOFENCE_DATA_ITEM_URI).await();
+ mGoogleApiClient.disconnect();
+ }
+ }
+ }
+
+ @Override
+ public void onConnected(Bundle connectionHint) {
+ }
+
+ @Override
+ public void onConnectionSuspended(int cause) {
+ }
+
+ @Override
+ public void onConnectionFailed(ConnectionResult result) {
+ }
+
+}
diff --git a/samples/wearable/Geofencing/Application/src/main/java/com/example/android/wearable/geofencing/MainActivity.java b/samples/wearable/Geofencing/Application/src/main/java/com/example/android/wearable/geofencing/MainActivity.java
new file mode 100644
index 000000000..c8bf1ffe6
--- /dev/null
+++ b/samples/wearable/Geofencing/Application/src/main/java/com/example/android/wearable/geofencing/MainActivity.java
@@ -0,0 +1,224 @@
+package com.example.android.wearable.geofencing;
+
+import static com.example.android.wearable.geofencing.Constants.ANDROID_BUILDING_ID;
+import static com.example.android.wearable.geofencing.Constants.ANDROID_BUILDING_LATITUDE;
+import static com.example.android.wearable.geofencing.Constants.ANDROID_BUILDING_LONGITUDE;
+import static com.example.android.wearable.geofencing.Constants.ANDROID_BUILDING_RADIUS_METERS;
+import static com.example.android.wearable.geofencing.Constants.CONNECTION_FAILURE_RESOLUTION_REQUEST;
+import static com.example.android.wearable.geofencing.Constants.GEOFENCE_EXPIRATION_TIME;
+import static com.example.android.wearable.geofencing.Constants.TAG;
+import static com.example.android.wearable.geofencing.Constants.YERBA_BUENA_ID;
+import static com.example.android.wearable.geofencing.Constants.YERBA_BUENA_LATITUDE;
+import static com.example.android.wearable.geofencing.Constants.YERBA_BUENA_LONGITUDE;
+import static com.example.android.wearable.geofencing.Constants.YERBA_BUENA_RADIUS_METERS;
+
+import android.app.Activity;
+import android.app.PendingIntent;
+import android.content.Intent;
+import android.content.IntentSender;
+import android.os.Bundle;
+import android.util.Log;
+import android.widget.Toast;
+
+import com.google.android.gms.common.ConnectionResult;
+import com.google.android.gms.common.GooglePlayServicesClient.ConnectionCallbacks;
+import com.google.android.gms.common.GooglePlayServicesUtil;
+import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
+import com.google.android.gms.location.Geofence;
+import com.google.android.gms.location.LocationClient;
+import com.google.android.gms.location.LocationClient.OnAddGeofencesResultListener;
+import com.google.android.gms.location.LocationStatusCodes;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class MainActivity extends Activity implements ConnectionCallbacks,
+ OnConnectionFailedListener, OnAddGeofencesResultListener {
+
+ // Internal List of Geofence objects. In a real app, these might be provided by an API based on
+ // locations within the user's proximity.
+ List mGeofenceList;
+
+ // These will store hard-coded geofences in this sample app.
+ private SimpleGeofence mAndroidBuildingGeofence;
+ private SimpleGeofence mYerbaBuenaGeofence;
+
+ // Persistent storage for geofences.
+ private SimpleGeofenceStore mGeofenceStorage;
+
+ private LocationClient mLocationClient;
+ // Stores the PendingIntent used to request geofence monitoring.
+ private PendingIntent mGeofenceRequestIntent;
+
+ // Defines the allowable request types (in this example, we only add geofences).
+ private enum REQUEST_TYPE {ADD}
+ private REQUEST_TYPE mRequestType;
+ // Flag that indicates if a request is underway.
+ private boolean mInProgress;
+
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ // Rather than displayng this activity, simply display a toast indicating that the geofence
+ // service is being created. This should happen in less than a second.
+ Toast.makeText(this, getString(R.string.start_geofence_service), Toast.LENGTH_SHORT).show();
+
+ // Instantiate a new geofence storage area.
+ mGeofenceStorage = new SimpleGeofenceStore(this);
+ // Instantiate the current List of geofences.
+ mGeofenceList = new ArrayList();
+ // Start with the request flag set to false.
+ mInProgress = false;
+
+ createGeofences();
+ addGeofences();
+
+ finish();
+ }
+
+ /**
+ * In this sample, the geofences are predetermined and are hard-coded here. A real app might
+ * dynamically create geofences based on the user's location.
+ */
+ public void createGeofences() {
+ // Create internal "flattened" objects containing the geofence data.
+ mAndroidBuildingGeofence = new SimpleGeofence(
+ ANDROID_BUILDING_ID, // geofenceId.
+ ANDROID_BUILDING_LATITUDE,
+ ANDROID_BUILDING_LONGITUDE,
+ ANDROID_BUILDING_RADIUS_METERS,
+ GEOFENCE_EXPIRATION_TIME,
+ Geofence.GEOFENCE_TRANSITION_ENTER | Geofence.GEOFENCE_TRANSITION_EXIT
+ );
+ mYerbaBuenaGeofence = new SimpleGeofence(
+ YERBA_BUENA_ID, // geofenceId.
+ YERBA_BUENA_LATITUDE,
+ YERBA_BUENA_LONGITUDE,
+ YERBA_BUENA_RADIUS_METERS,
+ GEOFENCE_EXPIRATION_TIME,
+ Geofence.GEOFENCE_TRANSITION_ENTER | Geofence.GEOFENCE_TRANSITION_EXIT
+ );
+
+ // Store these flat versions in SharedPreferences and add them to the geofence list.
+ mGeofenceStorage.setGeofence(ANDROID_BUILDING_ID, mAndroidBuildingGeofence);
+ mGeofenceStorage.setGeofence(YERBA_BUENA_ID, mYerbaBuenaGeofence);
+ mGeofenceList.add(mAndroidBuildingGeofence.toGeofence());
+ mGeofenceList.add(mYerbaBuenaGeofence.toGeofence());
+ }
+
+ /**
+ * Start a request for geofence monitoring by calling LocationClient.connect().
+ */
+ public void addGeofences() {
+ // Start a request to add geofences.
+ mRequestType = REQUEST_TYPE.ADD;
+ // Test for Google Play services after setting the request type.
+ if (!isGooglePlayServicesAvailable()) {
+ Log.e(TAG, "Unable to add geofences - Google Play services unavailable.");
+ return;
+ }
+ // Create a new location client object. Since this activity class implements
+ // ConnectionCallbacks and OnConnectionFailedListener, it can be used as the listener for
+ // both parameters.
+ mLocationClient = new LocationClient(this, this, this);
+ // If a request is not already underway.
+ if (!mInProgress) {
+ // Indicate that a request is underway.
+ mInProgress = true;
+ // Request a connection from the client to Location Services.
+ mLocationClient.connect();
+ // A request is already underway, so disconnect the client and retry the request.
+ } else {
+ mLocationClient.disconnect();
+ mLocationClient.connect();
+ }
+ }
+
+ @Override
+ public void onConnectionFailed(ConnectionResult connectionResult) {
+ mInProgress = false;
+ // If the error has a resolution, start a Google Play services activity to resolve it.
+ if (connectionResult.hasResolution()) {
+ try {
+ connectionResult.startResolutionForResult(this,
+ CONNECTION_FAILURE_RESOLUTION_REQUEST);
+ } catch (IntentSender.SendIntentException e) {
+ Log.e(TAG, "Exception while resolving connection error.", e);
+ }
+ } else {
+ int errorCode = connectionResult.getErrorCode();
+ Log.e(TAG, "Connection to Google Play services failed with error code " + errorCode);
+ }
+ }
+
+ /**
+ * Called by Location Services if the location client disconnects.
+ */
+ @Override
+ public void onDisconnected() {
+ // Turn off the request flag.
+ mInProgress = false;
+ // Destroy the current location client.
+ mLocationClient = null;
+ }
+
+ /**
+ * Once the connection is available, send a request to add the Geofences.
+ */
+ @Override
+ public void onConnected(Bundle connectionHint) {
+ // Use mRequestType to determine what action to take. Only ADD is used in this sample.
+ if (REQUEST_TYPE.ADD == mRequestType) {
+ // Get the PendingIntent for the geofence monitoring request.
+ mGeofenceRequestIntent = getGeofenceTransitionPendingIntent();
+ // Send a request to add the current geofences.
+ mLocationClient.addGeofences(mGeofenceList, mGeofenceRequestIntent, this);
+ }
+ }
+
+ /**
+ * Called when request to add geofences is complete, with a result status code.
+ */
+ @Override
+ public void onAddGeofencesResult(int statusCode, String[] geofenceRequestIds) {
+ // Log if adding the geofences was successful.
+ if (LocationStatusCodes.SUCCESS == statusCode) {
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "Added geofences successfully.");
+ }
+ } else {
+ Log.e(TAG, "Failed to add geofences. Status code: " + statusCode);
+ }
+ // Turn off the in progress flag and disconnect the client.
+ mInProgress = false;
+ mLocationClient.disconnect();
+ }
+
+ /**
+ * Checks if Google Play services is available.
+ * @return true if it is.
+ */
+ private boolean isGooglePlayServicesAvailable() {
+ int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
+ if (ConnectionResult.SUCCESS == resultCode) {
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "Google Play services is available.");
+ }
+ return true;
+ } else {
+ Log.e(TAG, "Google Play services is unavailable.");
+ return false;
+ }
+ }
+
+ /**
+ * Create a PendingIntent that triggers GeofenceTransitionIntentService when a geofence
+ * transition occurs.
+ */
+ private PendingIntent getGeofenceTransitionPendingIntent() {
+ Intent intent = new Intent(this, GeofenceTransitionsIntentService.class);
+ return PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
+ }
+
+}
diff --git a/samples/wearable/Geofencing/Application/src/main/java/com/example/android/wearable/geofencing/SimpleGeofence.java b/samples/wearable/Geofencing/Application/src/main/java/com/example/android/wearable/geofencing/SimpleGeofence.java
new file mode 100644
index 000000000..be7e6bd61
--- /dev/null
+++ b/samples/wearable/Geofencing/Application/src/main/java/com/example/android/wearable/geofencing/SimpleGeofence.java
@@ -0,0 +1,71 @@
+package com.example.android.wearable.geofencing;
+
+import com.google.android.gms.location.Geofence;
+
+/**
+ * A single Geofence object, defined by its center and radius.
+ */
+public class SimpleGeofence {
+
+ // Instance variables
+ private final String mId;
+ private final double mLatitude;
+ private final double mLongitude;
+ private final float mRadius;
+ private long mExpirationDuration;
+ private int mTransitionType;
+
+ /**
+ * @param geofenceId The Geofence's request ID.
+ * @param latitude Latitude of the Geofence's center in degrees.
+ * @param longitude Longitude of the Geofence's center in degrees.
+ * @param radius Radius of the geofence circle in meters.
+ * @param expiration Geofence expiration duration.
+ * @param transition Type of Geofence transition.
+ */
+ public SimpleGeofence(String geofenceId, double latitude, double longitude, float radius,
+ long expiration, int transition) {
+ // Set the instance fields from the constructor.
+ this.mId = geofenceId;
+ this.mLatitude = latitude;
+ this.mLongitude = longitude;
+ this.mRadius = radius;
+ this.mExpirationDuration = expiration;
+ this.mTransitionType = transition;
+ }
+
+ // Instance field getters.
+ public String getId() {
+ return mId;
+ }
+ public double getLatitude() {
+ return mLatitude;
+ }
+ public double getLongitude() {
+ return mLongitude;
+ }
+ public float getRadius() {
+ return mRadius;
+ }
+ public long getExpirationDuration() {
+ return mExpirationDuration;
+ }
+ public int getTransitionType() {
+ return mTransitionType;
+ }
+
+ /**
+ * Creates a Location Services Geofence object from a SimpleGeofence.
+ * @return A Geofence object.
+ */
+ public Geofence toGeofence() {
+ // Build a new Geofence object.
+ return new Geofence.Builder()
+ .setRequestId(mId)
+ .setTransitionTypes(mTransitionType)
+ .setCircularRegion(mLatitude, mLongitude, mRadius)
+ .setExpirationDuration(mExpirationDuration)
+ .build();
+ }
+
+}
diff --git a/samples/wearable/Geofencing/Application/src/main/java/com/example/android/wearable/geofencing/SimpleGeofenceStore.java b/samples/wearable/Geofencing/Application/src/main/java/com/example/android/wearable/geofencing/SimpleGeofenceStore.java
new file mode 100644
index 000000000..db93a8064
--- /dev/null
+++ b/samples/wearable/Geofencing/Application/src/main/java/com/example/android/wearable/geofencing/SimpleGeofenceStore.java
@@ -0,0 +1,108 @@
+package com.example.android.wearable.geofencing;
+
+import static com.example.android.wearable.geofencing.Constants.INVALID_FLOAT_VALUE;
+import static com.example.android.wearable.geofencing.Constants.INVALID_INT_VALUE;
+import static com.example.android.wearable.geofencing.Constants.INVALID_LONG_VALUE;
+import static com.example.android.wearable.geofencing.Constants.KEY_EXPIRATION_DURATION;
+import static com.example.android.wearable.geofencing.Constants.KEY_LATITUDE;
+import static com.example.android.wearable.geofencing.Constants.KEY_LONGITUDE;
+import static com.example.android.wearable.geofencing.Constants.KEY_PREFIX;
+import static com.example.android.wearable.geofencing.Constants.KEY_RADIUS;
+import static com.example.android.wearable.geofencing.Constants.KEY_TRANSITION_TYPE;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+
+/**
+ * Storage for geofence values, implemented in SharedPreferences.
+ */
+public class SimpleGeofenceStore {
+
+ // The SharedPreferences object in which geofences are stored.
+ private final SharedPreferences mPrefs;
+ // The name of the SharedPreferences.
+ private static final String SHARED_PREFERENCES = "SharedPreferences";
+
+ /**
+ * Create the SharedPreferences storage with private access only.
+ */
+ public SimpleGeofenceStore(Context context) {
+ mPrefs = context.getSharedPreferences(SHARED_PREFERENCES, Context.MODE_PRIVATE);
+ }
+
+ /**
+ * Returns a stored geofence by its id, or returns null if it's not found.
+ * @param id The ID of a stored geofence.
+ * @return A SimpleGeofence defined by its center and radius, or null if the ID is invalid.
+ */
+ public SimpleGeofence getGeofence(String id) {
+ // Get the latitude for the geofence identified by id, or INVALID_FLOAT_VALUE if it doesn't
+ // exist (similarly for the other values that follow).
+ double lat = mPrefs.getFloat(getGeofenceFieldKey(id, KEY_LATITUDE),
+ INVALID_FLOAT_VALUE);
+ double lng = mPrefs.getFloat(getGeofenceFieldKey(id, KEY_LONGITUDE),
+ INVALID_FLOAT_VALUE);
+ float radius = mPrefs.getFloat(getGeofenceFieldKey(id, KEY_RADIUS),
+ INVALID_FLOAT_VALUE);
+ long expirationDuration =
+ mPrefs.getLong(getGeofenceFieldKey(id, KEY_EXPIRATION_DURATION),
+ INVALID_LONG_VALUE);
+ int transitionType = mPrefs.getInt(getGeofenceFieldKey(id, KEY_TRANSITION_TYPE),
+ INVALID_INT_VALUE);
+ // If none of the values is incorrect, return the object.
+ if (lat != INVALID_FLOAT_VALUE
+ && lng != INVALID_FLOAT_VALUE
+ && radius != INVALID_FLOAT_VALUE
+ && expirationDuration != INVALID_LONG_VALUE
+ && transitionType != INVALID_INT_VALUE) {
+ return new SimpleGeofence(id, lat, lng, radius, expirationDuration, transitionType);
+ }
+ // Otherwise, return null.
+ return null;
+ }
+
+ /**
+ * Save a geofence.
+ * @param geofence The SimpleGeofence with the values you want to save in SharedPreferences.
+ */
+ public void setGeofence(String id, SimpleGeofence geofence) {
+ // Get a SharedPreferences editor instance. Among other things, SharedPreferences
+ // ensures that updates are atomic and non-concurrent.
+ SharedPreferences.Editor prefs = mPrefs.edit();
+ // Write the Geofence values to SharedPreferences.
+ prefs.putFloat(getGeofenceFieldKey(id, KEY_LATITUDE), (float) geofence.getLatitude());
+ prefs.putFloat(getGeofenceFieldKey(id, KEY_LONGITUDE), (float) geofence.getLongitude());
+ prefs.putFloat(getGeofenceFieldKey(id, KEY_RADIUS), geofence.getRadius());
+ prefs.putLong(getGeofenceFieldKey(id, KEY_EXPIRATION_DURATION),
+ geofence.getExpirationDuration());
+ prefs.putInt(getGeofenceFieldKey(id, KEY_TRANSITION_TYPE),
+ geofence.getTransitionType());
+ // Commit the changes.
+ prefs.commit();
+ }
+
+ /**
+ * Remove a flattened geofence object from storage by removing all of its keys.
+ */
+ public void clearGeofence(String id) {
+ SharedPreferences.Editor prefs = mPrefs.edit();
+ prefs.remove(getGeofenceFieldKey(id, KEY_LATITUDE));
+ prefs.remove(getGeofenceFieldKey(id, KEY_LONGITUDE));
+ prefs.remove(getGeofenceFieldKey(id, KEY_RADIUS));
+ prefs.remove(getGeofenceFieldKey(id, KEY_EXPIRATION_DURATION));
+ prefs.remove(getGeofenceFieldKey(id, KEY_TRANSITION_TYPE));
+ prefs.commit();
+ }
+
+ /**
+ * Given a Geofence object's ID and the name of a field (for example, KEY_LATITUDE), return
+ * the key name of the object's values in SharedPreferences.
+ * @param id The ID of a Geofence object.
+ * @param fieldName The field represented by the key.
+ * @return The full key name of a value in SharedPreferences.
+ */
+ private String getGeofenceFieldKey(String id, String fieldName) {
+ return KEY_PREFIX + "_" + id + "_" + fieldName;
+ }
+
+}
\ No newline at end of file
diff --git a/samples/wearable/Geofencing/Application/src/main/res/drawable-hdpi/ic_launcher.png b/samples/wearable/Geofencing/Application/src/main/res/drawable-hdpi/ic_launcher.png
new file mode 100644
index 000000000..4e3e000b0
Binary files /dev/null and b/samples/wearable/Geofencing/Application/src/main/res/drawable-hdpi/ic_launcher.png differ
diff --git a/samples/wearable/Geofencing/Application/src/main/res/drawable-mdpi/ic_launcher.png b/samples/wearable/Geofencing/Application/src/main/res/drawable-mdpi/ic_launcher.png
new file mode 100644
index 000000000..b405cb2e8
Binary files /dev/null and b/samples/wearable/Geofencing/Application/src/main/res/drawable-mdpi/ic_launcher.png differ
diff --git a/samples/wearable/Geofencing/Application/src/main/res/drawable-xhdpi/ic_launcher.png b/samples/wearable/Geofencing/Application/src/main/res/drawable-xhdpi/ic_launcher.png
new file mode 100644
index 000000000..61f9d889c
Binary files /dev/null and b/samples/wearable/Geofencing/Application/src/main/res/drawable-xhdpi/ic_launcher.png differ
diff --git a/samples/wearable/Geofencing/Application/src/main/res/drawable-xxhdpi/ic_launcher.png b/samples/wearable/Geofencing/Application/src/main/res/drawable-xxhdpi/ic_launcher.png
new file mode 100644
index 000000000..81c10085a
Binary files /dev/null and b/samples/wearable/Geofencing/Application/src/main/res/drawable-xxhdpi/ic_launcher.png differ
diff --git a/samples/wearable/Geofencing/Application/src/main/res/values/strings.xml b/samples/wearable/Geofencing/Application/src/main/res/values/strings.xml
new file mode 100644
index 000000000..57539b903
--- /dev/null
+++ b/samples/wearable/Geofencing/Application/src/main/res/values/strings.xml
@@ -0,0 +1,5 @@
+
+
+ Android Wear Geofencing Example Application
+ Starting geofence transition service
+
diff --git a/samples/wearable/Geofencing/Wearable/build.gradle b/samples/wearable/Geofencing/Wearable/build.gradle
new file mode 100644
index 000000000..a1921f0d5
--- /dev/null
+++ b/samples/wearable/Geofencing/Wearable/build.gradle
@@ -0,0 +1,26 @@
+apply plugin: 'android'
+
+android {
+ compileSdkVersion 20
+ buildToolsVersion '20'
+
+ defaultConfig {
+ minSdkVersion 20
+ targetSdkVersion 20
+ versionCode 1
+ versionName "1.0"
+ }
+
+ buildTypes {
+ release {
+ runProguard false
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
+ }
+ }
+}
+
+dependencies {
+ compile 'com.google.android.gms:play-services:5.+@aar'
+ compile "com.android.support:support-v4:20.0.+"
+ compile "com.google.android.support:wearable:1.0.+"
+}
\ No newline at end of file
diff --git a/samples/wearable/Geofencing/Wearable/proguard-rules.txt b/samples/wearable/Geofencing/Wearable/proguard-rules.txt
new file mode 100644
index 000000000..f2fe1559a
--- /dev/null
+++ b/samples/wearable/Geofencing/Wearable/proguard-rules.txt
@@ -0,0 +1,20 @@
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
diff --git a/samples/wearable/Geofencing/Wearable/project.properties b/samples/wearable/Geofencing/Wearable/project.properties
new file mode 100644
index 000000000..4ab125693
--- /dev/null
+++ b/samples/wearable/Geofencing/Wearable/project.properties
@@ -0,0 +1,14 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system edit
+# "ant.properties", and override values to adapt the script to your
+# project structure.
+#
+# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
+#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
+
+# Project target.
+target=android-19
diff --git a/samples/wearable/Geofencing/Wearable/src/main/AndroidManifest.xml b/samples/wearable/Geofencing/Wearable/src/main/AndroidManifest.xml
new file mode 100644
index 000000000..79145cd13
--- /dev/null
+++ b/samples/wearable/Geofencing/Wearable/src/main/AndroidManifest.xml
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/wearable/Geofencing/Wearable/src/main/java/com/example/android/wearable/geofencing/CheckInAndDeleteDataItemsService.java b/samples/wearable/Geofencing/Wearable/src/main/java/com/example/android/wearable/geofencing/CheckInAndDeleteDataItemsService.java
new file mode 100644
index 000000000..ad6929361
--- /dev/null
+++ b/samples/wearable/Geofencing/Wearable/src/main/java/com/example/android/wearable/geofencing/CheckInAndDeleteDataItemsService.java
@@ -0,0 +1,108 @@
+package com.example.android.wearable.geofencing;
+
+import com.google.android.gms.common.ConnectionResult;
+import com.google.android.gms.common.api.GoogleApiClient;
+import com.google.android.gms.wearable.DataApi;
+import com.google.android.gms.wearable.Wearable;
+
+import android.app.IntentService;
+import android.app.NotificationManager;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Bundle;
+import android.support.wearable.activity.ConfirmationActivity;
+import android.util.Log;
+
+import java.util.concurrent.TimeUnit;
+
+import static com.example.android.wearable.geofencing.Constants.ACTION_CHECK_IN;
+import static com.example.android.wearable.geofencing.Constants.ACTION_DELETE_DATA_ITEM;
+import static com.example.android.wearable.geofencing.Constants.CONNECTION_TIME_OUT_MS;
+import static com.example.android.wearable.geofencing.Constants.NOTIFICATION_ID;
+import static com.example.android.wearable.geofencing.Constants.TAG;
+
+/**
+ * Handles "Check In" action on the location-based notification. Also deletes orphan DataItems
+ * when a notification is dismissed from the wearable.
+ */
+public class CheckInAndDeleteDataItemsService extends IntentService
+ implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
+
+ private GoogleApiClient mGoogleApiClient;
+
+ public CheckInAndDeleteDataItemsService() {
+ super(CheckInAndDeleteDataItemsService.class.getSimpleName());
+ }
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ mGoogleApiClient = new GoogleApiClient.Builder(this)
+ .addApi(Wearable.API)
+ .addConnectionCallbacks(this)
+ .addOnConnectionFailedListener(this)
+ .build();
+ }
+
+ @Override
+ protected void onHandleIntent(Intent intent) {
+ if (ACTION_CHECK_IN.equals(intent.getAction())) {
+ // In a real app, code for checking in would go here. For this sample, we will simply
+ // display a success animation.
+ startConfirmationActivity(ConfirmationActivity.SUCCESS_ANIMATION,
+ getString(R.string.check_in_success));
+ // Dismiss the check-in notification.
+ ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).cancel(NOTIFICATION_ID);
+ } else if (!ACTION_DELETE_DATA_ITEM.equals(intent.getAction())) {
+ // The only possible actions should be checking in or dismissing the notification
+ // (which causes an intent with ACTION_DELETE_DATA_ITEM).
+ Log.e(TAG, "Unrecognized action: " + intent.getAction());
+ return;
+ }
+ // Regardless of the action, delete the DataItem (we are only be handling intents
+ // if the notification is dismissed or if the user has chosen to check in, either of which
+ // would be completed at this point).
+ mGoogleApiClient.blockingConnect(CONNECTION_TIME_OUT_MS, TimeUnit.MILLISECONDS);
+ Uri dataItemUri = intent.getData();
+ if (mGoogleApiClient.isConnected()) {
+ DataApi.DeleteDataItemsResult result = Wearable.DataApi
+ .deleteDataItems(mGoogleApiClient, dataItemUri).await();
+ if (!result.getStatus().isSuccess()) {
+ Log.e(TAG, "CheckInAndDeleteDataItemsService.onHandleIntent: "
+ + "Failed to delete dataItem: " + dataItemUri);
+ } else if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "Successfully deleted data item: " + dataItemUri);
+ }
+ } else {
+ Log.e(TAG, "Failed to delete data item: " + dataItemUri
+ + " - Client disconnected from Google Play Services");
+ }
+ mGoogleApiClient.disconnect();
+ }
+
+ /**
+ * Helper method to create confirmation animations on the wearable.
+ * @param animationType Defined by constants in ConfirmationActivity.
+ * @param message The message to display with the animation.
+ */
+ private void startConfirmationActivity(int animationType, String message) {
+ Intent confirmationActivity = new Intent(this, ConfirmationActivity.class)
+ .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION)
+ .putExtra(ConfirmationActivity.EXTRA_ANIMATION_TYPE, animationType)
+ .putExtra(ConfirmationActivity.EXTRA_MESSAGE, message);
+ startActivity(confirmationActivity);
+ }
+
+ @Override
+ public void onConnected(Bundle connectionHint) {
+ }
+
+ @Override
+ public void onConnectionSuspended(int cause) {
+ }
+
+ @Override
+ public void onConnectionFailed(ConnectionResult result) {
+ }
+
+}
\ No newline at end of file
diff --git a/samples/wearable/Geofencing/Wearable/src/main/java/com/example/android/wearable/geofencing/Constants.java b/samples/wearable/Geofencing/Wearable/src/main/java/com/example/android/wearable/geofencing/Constants.java
new file mode 100644
index 000000000..7103a4e91
--- /dev/null
+++ b/samples/wearable/Geofencing/Wearable/src/main/java/com/example/android/wearable/geofencing/Constants.java
@@ -0,0 +1,22 @@
+package com.example.android.wearable.geofencing;
+
+/** Constants used in wearable app. */
+public final class Constants {
+
+ private Constants() {
+ }
+
+ public static final String TAG = "ExampleGeofencingApp";
+
+ // Timeout for making a connection to GoogleApiClient (in milliseconds).
+ public static final long CONNECTION_TIME_OUT_MS = 100;
+
+ public static final int NOTIFICATION_ID = 1;
+ public static final String ANDROID_BUILDING_ID = "1";
+ public static final String YERBA_BUENA_ID = "2";
+
+ public static final String ACTION_CHECK_IN = "check_in";
+ public static final String ACTION_DELETE_DATA_ITEM = "delete_data_item";
+ public static final String KEY_GEOFENCE_ID = "geofence_id";
+
+}
diff --git a/samples/wearable/Geofencing/Wearable/src/main/java/com/example/android/wearable/geofencing/HomeListenerService.java b/samples/wearable/Geofencing/Wearable/src/main/java/com/example/android/wearable/geofencing/HomeListenerService.java
new file mode 100644
index 000000000..5ecc8a6e6
--- /dev/null
+++ b/samples/wearable/Geofencing/Wearable/src/main/java/com/example/android/wearable/geofencing/HomeListenerService.java
@@ -0,0 +1,136 @@
+package com.example.android.wearable.geofencing;
+
+import static com.example.android.wearable.geofencing.Constants.ACTION_CHECK_IN;
+import static com.example.android.wearable.geofencing.Constants.ACTION_DELETE_DATA_ITEM;
+import static com.example.android.wearable.geofencing.Constants.ANDROID_BUILDING_ID;
+import static com.example.android.wearable.geofencing.Constants.KEY_GEOFENCE_ID;
+import static com.example.android.wearable.geofencing.Constants.NOTIFICATION_ID;
+import static com.example.android.wearable.geofencing.Constants.TAG;
+import static com.example.android.wearable.geofencing.Constants.YERBA_BUENA_ID;
+
+import android.app.Notification;
+import android.app.Notification.Action;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.content.Intent;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.net.Uri;
+import android.text.Spannable;
+import android.text.SpannableString;
+import android.text.style.RelativeSizeSpan;
+import android.util.Log;
+
+import com.google.android.gms.common.api.GoogleApiClient;
+import com.google.android.gms.wearable.DataEvent;
+import com.google.android.gms.wearable.DataEventBuffer;
+import com.google.android.gms.wearable.DataItem;
+import com.google.android.gms.wearable.DataMap;
+import com.google.android.gms.wearable.Wearable;
+import com.google.android.gms.wearable.WearableListenerService;
+
+/**
+ * Listens to DataItem events on the wearable device.
+ */
+public class HomeListenerService extends WearableListenerService {
+
+ private GoogleApiClient mGoogleApiClient;
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ mGoogleApiClient = new GoogleApiClient.Builder(this.getApplicationContext())
+ .addApi(Wearable.API)
+ .build();
+ mGoogleApiClient.connect();
+ }
+
+ /**
+ * Listen for DataItems added/deleted from the geofence service running on the companion.
+ */
+ @Override
+ public void onDataChanged(DataEventBuffer dataEvents) {
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "onDataChanged: " + dataEvents + " for " + getPackageName());
+ }
+ for (DataEvent event : dataEvents) {
+ if (event.getType() == DataEvent.TYPE_DELETED) {
+ cancelNotificationForDataItem(event.getDataItem());
+ } else if (event.getType() == DataEvent.TYPE_CHANGED) {
+ // The user has entered a geofence - post a notification!
+ String geofenceId = DataMap.fromByteArray(event.getDataItem().getData())
+ .getString(KEY_GEOFENCE_ID);
+ postNotificationForGeofenceId(geofenceId, event.getDataItem().getUri());
+ }
+ }
+ dataEvents.close();
+ }
+
+ /**
+ * Deletes the check-in notification when the DataItem is deleted.
+ * @param dataItem Used only for logging in this sample, but could be used to identify which
+ * notification to cancel (in this case, there is at most 1 notification).
+ */
+ private void cancelNotificationForDataItem(DataItem dataItem) {
+ if (Log.isLoggable(TAG, Log.VERBOSE)) {
+ Log.v(TAG, "onDataItemDeleted:DataItem=" + dataItem.getUri());
+ }
+ ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).cancel(NOTIFICATION_ID);
+ }
+
+ /**
+ * Posts a local notification for the given geofence id, with an option to check in.
+ * @param geofenceId The geofence id that the user has triggered.
+ * @param dataItemUri The Uri for the DataItem that triggered this notification. Used to delete
+ * this DataItem when the notification is dismissed.
+ */
+ private void postNotificationForGeofenceId(String geofenceId, Uri dataItemUri) {
+ // Use the geofenceId to determine the title and background of the check-in notification.
+ // A SpannableString is used for the notification title for resizing capabilities.
+ SpannableString checkInTitle;
+ Bitmap notificationBackground;
+ if (ANDROID_BUILDING_ID.equals(geofenceId)) {
+ checkInTitle = new SpannableString(getText(R.string.android_building_title));
+ notificationBackground =
+ BitmapFactory.decodeResource(getResources(), R.drawable.android_building);
+ } else if (YERBA_BUENA_ID.equals(geofenceId)) {
+ checkInTitle = new SpannableString(getText(R.string.yerba_buena_title));
+ notificationBackground =
+ BitmapFactory.decodeResource(getResources(), R.drawable.yerba_buena);
+ } else {
+ Log.e(TAG, "Unrecognized geofence id: " + geofenceId);
+ return;
+ }
+ // Resize the title to avoid truncation.
+ checkInTitle.setSpan(new RelativeSizeSpan(0.8f), 0, checkInTitle.length(),
+ Spannable.SPAN_POINT_MARK);
+
+ Intent checkInOperation =
+ new Intent(this, CheckInAndDeleteDataItemsService.class).setData(dataItemUri);
+ PendingIntent checkInIntent = PendingIntent.getService(this, 0,
+ checkInOperation.setAction(ACTION_CHECK_IN), PendingIntent.FLAG_CANCEL_CURRENT);
+ PendingIntent deleteDataItemIntent = PendingIntent.getService(this, 1,
+ checkInOperation.setAction(ACTION_DELETE_DATA_ITEM),
+ PendingIntent.FLAG_CANCEL_CURRENT);
+ // This action will be embedded into the notification.
+ Action checkInAction = new Action(R.drawable.ic_action_check_in,
+ getText(R.string.check_in_prompt), checkInIntent);
+
+ Notification notification = new Notification.Builder(this)
+ .setContentTitle(checkInTitle)
+ .setContentText(getText(R.string.check_in_prompt))
+ .setSmallIcon(R.drawable.ic_launcher)
+ .setDeleteIntent(deleteDataItemIntent)
+ .extend(new Notification.WearableExtender()
+ .setBackground(notificationBackground)
+ .addAction(checkInAction)
+ .setContentAction(0)
+ .setHintHideIcon(true))
+ .setLocalOnly(true)
+ .build();
+
+ ((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
+ .notify(NOTIFICATION_ID, notification);
+ }
+
+}
diff --git a/samples/wearable/Geofencing/Wearable/src/main/res/drawable-hdpi/ic_action_check_in.png b/samples/wearable/Geofencing/Wearable/src/main/res/drawable-hdpi/ic_action_check_in.png
new file mode 100644
index 000000000..f94a1c4c9
Binary files /dev/null and b/samples/wearable/Geofencing/Wearable/src/main/res/drawable-hdpi/ic_action_check_in.png differ
diff --git a/samples/wearable/Geofencing/Wearable/src/main/res/drawable-hdpi/ic_launcher.png b/samples/wearable/Geofencing/Wearable/src/main/res/drawable-hdpi/ic_launcher.png
new file mode 100644
index 000000000..4e3e000b0
Binary files /dev/null and b/samples/wearable/Geofencing/Wearable/src/main/res/drawable-hdpi/ic_launcher.png differ
diff --git a/samples/wearable/Geofencing/Wearable/src/main/res/drawable-mdpi/ic_launcher.png b/samples/wearable/Geofencing/Wearable/src/main/res/drawable-mdpi/ic_launcher.png
new file mode 100644
index 000000000..b405cb2e8
Binary files /dev/null and b/samples/wearable/Geofencing/Wearable/src/main/res/drawable-mdpi/ic_launcher.png differ
diff --git a/samples/wearable/Geofencing/Wearable/src/main/res/drawable-nodpi/android_building.png b/samples/wearable/Geofencing/Wearable/src/main/res/drawable-nodpi/android_building.png
new file mode 100644
index 000000000..2a28bd425
Binary files /dev/null and b/samples/wearable/Geofencing/Wearable/src/main/res/drawable-nodpi/android_building.png differ
diff --git a/samples/wearable/Geofencing/Wearable/src/main/res/drawable-nodpi/yerba_buena.png b/samples/wearable/Geofencing/Wearable/src/main/res/drawable-nodpi/yerba_buena.png
new file mode 100644
index 000000000..04f39f87f
Binary files /dev/null and b/samples/wearable/Geofencing/Wearable/src/main/res/drawable-nodpi/yerba_buena.png differ
diff --git a/samples/wearable/Geofencing/Wearable/src/main/res/drawable-xhdpi/ic_launcher.png b/samples/wearable/Geofencing/Wearable/src/main/res/drawable-xhdpi/ic_launcher.png
new file mode 100644
index 000000000..61f9d889c
Binary files /dev/null and b/samples/wearable/Geofencing/Wearable/src/main/res/drawable-xhdpi/ic_launcher.png differ
diff --git a/samples/wearable/Geofencing/Wearable/src/main/res/drawable-xxhdpi/ic_launcher.png b/samples/wearable/Geofencing/Wearable/src/main/res/drawable-xxhdpi/ic_launcher.png
new file mode 100644
index 000000000..81c10085a
Binary files /dev/null and b/samples/wearable/Geofencing/Wearable/src/main/res/drawable-xxhdpi/ic_launcher.png differ
diff --git a/samples/wearable/Geofencing/Wearable/src/main/res/values/strings.xml b/samples/wearable/Geofencing/Wearable/src/main/res/values/strings.xml
new file mode 100644
index 000000000..348b4b69b
--- /dev/null
+++ b/samples/wearable/Geofencing/Wearable/src/main/res/values/strings.xml
@@ -0,0 +1,8 @@
+
+
+ Android Wear Geofencing Example Application
+ Android Building
+ Yerba Buena Gardens
+ Check in here?
+ Checked In
+
diff --git a/samples/wearable/Geofencing/build.gradle b/samples/wearable/Geofencing/build.gradle
new file mode 100644
index 000000000..07be865b5
--- /dev/null
+++ b/samples/wearable/Geofencing/build.gradle
@@ -0,0 +1,14 @@
+buildscript {
+ repositories {
+ mavenCentral()
+ }
+ dependencies {
+ classpath 'com.android.tools.build:gradle:0.11.+'
+ }
+}
+
+allprojects {
+ repositories {
+ mavenCentral()
+ }
+}
\ No newline at end of file
diff --git a/samples/wearable/Geofencing/gradle/wrapper/gradle-wrapper.jar b/samples/wearable/Geofencing/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 000000000..583859812
Binary files /dev/null and b/samples/wearable/Geofencing/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/samples/wearable/Geofencing/gradle/wrapper/gradle-wrapper.properties b/samples/wearable/Geofencing/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 000000000..e83e46081
--- /dev/null
+++ b/samples/wearable/Geofencing/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Fri Mar 14 14:02:22 PDT 2014
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-all.zip
diff --git a/samples/wearable/Geofencing/gradlew b/samples/wearable/Geofencing/gradlew
new file mode 100755
index 000000000..91a7e269e
--- /dev/null
+++ b/samples/wearable/Geofencing/gradlew
@@ -0,0 +1,164 @@
+#!/usr/bin/env bash
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+ echo "$*"
+}
+
+die ( ) {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+esac
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched.
+if $cygwin ; then
+ [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+fi
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >&-
+APP_HOME="`pwd -P`"
+cd "$SAVED" >&-
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+ JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
diff --git a/samples/wearable/Geofencing/gradlew.bat b/samples/wearable/Geofencing/gradlew.bat
new file mode 100644
index 000000000..aec99730b
--- /dev/null
+++ b/samples/wearable/Geofencing/gradlew.bat
@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windowz variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%@eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/samples/wearable/Geofencing/settings.gradle b/samples/wearable/Geofencing/settings.gradle
new file mode 100644
index 000000000..f3f25a547
--- /dev/null
+++ b/samples/wearable/Geofencing/settings.gradle
@@ -0,0 +1 @@
+include 'Wearable', 'Application'
diff --git a/samples/wearable/JumpingJack/Wearable/build.gradle b/samples/wearable/JumpingJack/Wearable/build.gradle
new file mode 100644
index 000000000..c07ae51b7
--- /dev/null
+++ b/samples/wearable/JumpingJack/Wearable/build.gradle
@@ -0,0 +1,34 @@
+apply plugin: 'android'
+
+repositories {
+ mavenCentral()
+}
+
+android {
+ compileSdkVersion 20
+ buildToolsVersion '20'
+
+ defaultConfig {
+ minSdkVersion 20
+ targetSdkVersion 20
+ versionCode 1
+ versionName "1.0"
+ }
+ buildTypes {
+ release {
+ runProguard false
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
+ }
+ }
+
+ lintOptions {
+ abortOnError false
+ }
+
+}
+
+dependencies {
+ compile 'com.google.android.gms:play-services:5.0.+@aar'
+ compile "com.android.support:support-v13:20.0.+"
+ compile "com.google.android.support:wearable:1.0.+"
+}
diff --git a/samples/wearable/JumpingJack/Wearable/proguard-rules.txt b/samples/wearable/JumpingJack/Wearable/proguard-rules.txt
new file mode 100644
index 000000000..0cc65eeb3
--- /dev/null
+++ b/samples/wearable/JumpingJack/Wearable/proguard-rules.txt
@@ -0,0 +1,17 @@
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
\ No newline at end of file
diff --git a/samples/wearable/JumpingJack/Wearable/src/main/AndroidManifest.xml b/samples/wearable/JumpingJack/Wearable/src/main/AndroidManifest.xml
new file mode 100644
index 000000000..0be9b0614
--- /dev/null
+++ b/samples/wearable/JumpingJack/Wearable/src/main/AndroidManifest.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/wearable/JumpingJack/Wearable/src/main/java/com/example/android/wearable/jumpingjack/MainActivity.java b/samples/wearable/JumpingJack/Wearable/src/main/java/com/example/android/wearable/jumpingjack/MainActivity.java
new file mode 100644
index 000000000..cdaaf6ec7
--- /dev/null
+++ b/samples/wearable/JumpingJack/Wearable/src/main/java/com/example/android/wearable/jumpingjack/MainActivity.java
@@ -0,0 +1,257 @@
+/*
+ * Copyright (C) 2014 Google Inc. All Rights Reserved.
+ *
+ * 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.
+ */
+
+package com.example.android.wearable.jumpingjack;
+
+import com.example.android.wearable.jumpingjack.fragments.CounterFragment;
+import com.example.android.wearable.jumpingjack.fragments.SettingsFragment;
+
+import android.app.Activity;
+import android.content.Context;
+import android.hardware.Sensor;
+import android.hardware.SensorEvent;
+import android.hardware.SensorEventListener;
+import android.hardware.SensorManager;
+import android.os.Bundle;
+import android.os.Handler;
+import android.support.v4.view.ViewPager;
+import android.util.Log;
+import android.view.WindowManager;
+import android.widget.ImageView;
+
+import java.util.Timer;
+import java.util.TimerTask;
+
+/**
+ * The main activity for the Jumping Jack application. This activity registers itself to receive
+ * sensor values. Since on wearable devices a full screen activity is very short-lived, we set the
+ * FLAG_KEEP_SCREEN_ON to give user adequate time for taking actions but since we don't want to
+ * keep screen on for an extended period of time, there is a SCREEN_ON_TIMEOUT_MS that is enforced
+ * if no interaction is discovered.
+ *
+ * This activity includes a {@link android.support.v4.view.ViewPager} with two pages, one that
+ * shows the current count and one that allows user to reset the counter. the current value of the
+ * counter is persisted so that upon re-launch, the counter picks up from the last value. At any
+ * stage, user can set this counter to 0.
+ */
+public class MainActivity extends Activity
+ implements SensorEventListener {
+
+ private static final String TAG = "JJMainActivity";
+
+ /** How long to keep the screen on when no activity is happening **/
+ private static final long SCREEN_ON_TIMEOUT_MS = 20000; // in milliseconds
+
+ /** an up-down movement that takes more than this will not be registered as such **/
+ private static final long TIME_THRESHOLD_NS = 2000000000; // in nanoseconds (= 2sec)
+
+ /**
+ * Earth gravity is around 9.8 m/s^2 but user may not completely direct his/her hand vertical
+ * during the exercise so we leave some room. Basically if the x-component of gravity, as
+ * measured by the Gravity sensor, changes with a variation (delta) > GRAVITY_THRESHOLD,
+ * we consider that a successful count.
+ */
+ private static final float GRAVITY_THRESHOLD = 7.0f;
+
+ private SensorManager mSensorManager;
+ private Sensor mSensor;
+ private long mLastTime = 0;
+ private boolean mUp = false;
+ private int mJumpCounter = 0;
+ private ViewPager mPager;
+ private CounterFragment mCounterPage;
+ private SettingsFragment mSettingPage;
+ private ImageView mSecondIndicator;
+ private ImageView mFirstIndicator;
+ private Timer mTimer;
+ private TimerTask mTimerTask;
+ private Handler mHandler;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.jj_layout);
+ setupViews();
+ mHandler = new Handler();
+ mJumpCounter = Utils.getCounterFromPreference(this);
+ getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
+ renewTimer();
+ mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
+ mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GRAVITY);
+ }
+
+ private void setupViews() {
+ mPager = (ViewPager) findViewById(R.id.pager);
+ mFirstIndicator = (ImageView) findViewById(R.id.indicator_0);
+ mSecondIndicator = (ImageView) findViewById(R.id.indicator_1);
+ final PagerAdapter adapter = new PagerAdapter(getFragmentManager());
+ mCounterPage = new CounterFragment();
+ mSettingPage = new SettingsFragment(this);
+ adapter.addFragment(mCounterPage);
+ adapter.addFragment(mSettingPage);
+ setIndicator(0);
+ mPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
+ @Override
+ public void onPageScrolled(int i, float v, int i2) {
+ }
+
+ @Override
+ public void onPageSelected(int i) {
+ setIndicator(i);
+ renewTimer();
+ }
+
+ @Override
+ public void onPageScrollStateChanged(int i) {
+ }
+ });
+
+ mPager.setAdapter(adapter);
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ if (mSensorManager.registerListener(this, mSensor,
+ SensorManager.SENSOR_DELAY_NORMAL)) {
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "Successfully registered for the sensor updates");
+ }
+ }
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ mSensorManager.unregisterListener(this);
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "Unregistered for sensor events");
+ }
+ }
+
+ @Override
+ public void onSensorChanged(SensorEvent event) {
+ detectJump(event.values[0], event.timestamp);
+ }
+
+ @Override
+ public void onAccuracyChanged(Sensor sensor, int accuracy) {
+ }
+
+ /**
+ * A simple algorithm to detect a successful up-down movement of hand(s). The algorithm is
+ * based on the assumption that when a person is wearing the watch, the x-component of gravity
+ * as measured by the Gravity Sensor is +9.8 when the hand is downward and -9.8 when the hand
+ * is upward (signs are reversed if the watch is worn on the right hand). Since the upward or
+ * downward may not be completely accurate, we leave some room and instead of 9.8, we use
+ * GRAVITY_THRESHOLD. We also consider the up <-> down movement successful if it takes less than
+ * TIME_THRESHOLD_NS.
+ */
+ private void detectJump(float xValue, long timestamp) {
+ if ((Math.abs(xValue) > GRAVITY_THRESHOLD)) {
+ if(timestamp - mLastTime < TIME_THRESHOLD_NS && mUp != (xValue > 0)) {
+ onJumpDetected(!mUp);
+ }
+ mUp = xValue > 0;
+ mLastTime = timestamp;
+ }
+ }
+
+ /**
+ * Called on detection of a successful down -> up or up -> down movement of hand.
+ */
+ private void onJumpDetected(boolean up) {
+ // we only count a pair of up and down as one successful movement
+ if (up) {
+ return;
+ }
+ mJumpCounter++;
+ setCounter(mJumpCounter);
+ renewTimer();
+ }
+
+ /**
+ * Updates the counter on UI, saves it to preferences and vibrates the watch when counter
+ * reaches a multiple of 10.
+ */
+ private void setCounter(int i) {
+ mCounterPage.setCounter(i);
+ Utils.saveCounterToPreference(this, i);
+ if (i > 0 && i % 10 == 0) {
+ Utils.vibrate(this, 0);
+ }
+ }
+
+ public void resetCounter() {
+ setCounter(0);
+ renewTimer();
+ }
+
+ /**
+ * Starts a timer to clear the flag FLAG_KEEP_SCREEN_ON.
+ */
+ private void renewTimer() {
+ if (null != mTimer) {
+ mTimer.cancel();
+ }
+ mTimerTask = new TimerTask() {
+ @Override
+ public void run() {
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG,
+ "Removing the FLAG_KEEP_SCREEN_ON flag to allow going to background");
+ }
+ resetFlag();
+ }
+ };
+ mTimer = new Timer();
+ mTimer.schedule(mTimerTask, SCREEN_ON_TIMEOUT_MS);
+ }
+
+ /**
+ * Resets the FLAG_KEEP_SCREEN_ON flag so activity can go into background.
+ */
+ private void resetFlag() {
+ mHandler.post(new Runnable() {
+ @Override
+ public void run() {
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "Resetting FLAG_KEEP_SCREEN_ON flag to allow going to background");
+ }
+ getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
+ finish();
+ }
+ });
+ }
+
+ /**
+ * Sets the page indicator for the ViewPager.
+ */
+ private void setIndicator(int i) {
+ switch (i) {
+ case 0:
+ mFirstIndicator.setImageResource(R.drawable.full_10);
+ mSecondIndicator.setImageResource(R.drawable.empty_10);
+ break;
+ case 1:
+ mFirstIndicator.setImageResource(R.drawable.empty_10);
+ mSecondIndicator.setImageResource(R.drawable.full_10);
+ break;
+ }
+ }
+
+
+}
diff --git a/samples/wearable/JumpingJack/Wearable/src/main/java/com/example/android/wearable/jumpingjack/PagerAdapter.java b/samples/wearable/JumpingJack/Wearable/src/main/java/com/example/android/wearable/jumpingjack/PagerAdapter.java
new file mode 100644
index 000000000..f7ac2b010
--- /dev/null
+++ b/samples/wearable/JumpingJack/Wearable/src/main/java/com/example/android/wearable/jumpingjack/PagerAdapter.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2014 Google Inc. All Rights Reserved.
+ *
+ * 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.
+ */
+
+package com.example.android.wearable.jumpingjack;
+
+import android.app.Fragment;
+import android.app.FragmentManager;
+import android.support.v13.app.FragmentPagerAdapter;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A simple adapter for the {@link android.support.v4.view.ViewPager}
+ */
+public class PagerAdapter extends FragmentPagerAdapter {
+
+ List mFragments = null;
+
+ public PagerAdapter(FragmentManager fm) {
+ super(fm);
+ mFragments = new ArrayList();
+ }
+
+ @Override
+ public Fragment getItem(int position) {
+ return mFragments.get(position);
+ }
+
+ @Override
+ public int getCount() {
+ return mFragments.size();
+ }
+
+ public void addFragment(Fragment fragment) {
+ mFragments.add(fragment);
+ notifyDataSetChanged();
+ }
+}
diff --git a/samples/wearable/JumpingJack/Wearable/src/main/java/com/example/android/wearable/jumpingjack/Utils.java b/samples/wearable/JumpingJack/Wearable/src/main/java/com/example/android/wearable/jumpingjack/Utils.java
new file mode 100644
index 000000000..4db66c9a8
--- /dev/null
+++ b/samples/wearable/JumpingJack/Wearable/src/main/java/com/example/android/wearable/jumpingjack/Utils.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2014 Google Inc. All Rights Reserved.
+ *
+ * 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.
+ */
+
+package com.example.android.wearable.jumpingjack;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.os.Vibrator;
+import android.preference.PreferenceManager;
+
+/**
+ * A utility class for some helper methods.
+ */
+public class Utils {
+
+ private static final int DEFAULT_VIBRATION_DURATION_MS = 200; // in millis
+ private static final String PREF_KEY_COUNTER = "counter";
+
+ /**
+ * Causes device to vibrate for the given duration (in millis). If duration is set to 0, then it
+ * will use the DEFAULT_VIBRATION_DURATION_MS.
+ */
+ public final static void vibrate(Context context, int duration) {
+ if (duration == 0) {
+ duration = DEFAULT_VIBRATION_DURATION_MS;
+ }
+ Vibrator v = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
+ v.vibrate(duration);
+ }
+
+ /**
+ * Saves the counter value in the preference storage. If value
+ * is negative, then the value will be removed from the preferences.
+ */
+ public static void saveCounterToPreference(Context context, int value) {
+ SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
+ if (value < 0) {
+ // we want to remove
+ pref.edit().remove(PREF_KEY_COUNTER).apply();
+ } else {
+ pref.edit().putInt(PREF_KEY_COUNTER, value).apply();
+ }
+ }
+
+ /**
+ * Retrieves the value of counter from preference manager. If no value exists, it will return
+ * 0.
+ */
+ public static int getCounterFromPreference(Context context) {
+ SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
+ return pref.getInt(PREF_KEY_COUNTER, 0);
+ }
+
+}
diff --git a/samples/wearable/JumpingJack/Wearable/src/main/java/com/example/android/wearable/jumpingjack/fragments/CounterFragment.java b/samples/wearable/JumpingJack/Wearable/src/main/java/com/example/android/wearable/jumpingjack/fragments/CounterFragment.java
new file mode 100644
index 000000000..c55eb9b04
--- /dev/null
+++ b/samples/wearable/JumpingJack/Wearable/src/main/java/com/example/android/wearable/jumpingjack/fragments/CounterFragment.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2014 Google Inc. All Rights Reserved.
+ *
+ * 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.
+ */
+
+package com.example.android.wearable.jumpingjack.fragments;
+
+import com.example.android.wearable.jumpingjack.R;
+import com.example.android.wearable.jumpingjack.Utils;
+
+import android.app.Fragment;
+import android.graphics.drawable.Drawable;
+import android.os.Bundle;
+import android.os.Handler;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+import java.util.Timer;
+import java.util.TimerTask;
+
+/**
+ * A simple fragment for showing the count
+ */
+public class CounterFragment extends Fragment {
+
+ private static final long ANIMATION_INTERVAL_MS = 500; // in milliseconds
+ private TextView mCounterText;
+ private Timer mAnimationTimer;
+ private Handler mHandler;
+ private TimerTask mAnimationTask;
+ private boolean up = false;
+ private Drawable mDownDrawable;
+ private Drawable mUpDrawable;
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.counter_layout, container, false);
+ mDownDrawable = getResources().getDrawable(R.drawable.jump_down_50);
+ mUpDrawable = getResources().getDrawable(R.drawable.jump_up_50);
+ mCounterText = (TextView) view.findViewById(R.id.counter);
+ mCounterText.setCompoundDrawablesWithIntrinsicBounds(mUpDrawable, null, null, null);
+ setCounter(Utils.getCounterFromPreference(getActivity()));
+ mHandler = new Handler();
+ startAnimation();
+ return view;
+ }
+
+ private void startAnimation() {
+ mAnimationTask = new TimerTask() {
+ @Override
+ public void run() {
+ mHandler.post(new Runnable() {
+ @Override
+ public void run() {
+ mCounterText.setCompoundDrawablesWithIntrinsicBounds(
+ up ? mUpDrawable : mDownDrawable, null, null, null);
+ up = !up;
+ }
+ });
+ }
+ };
+ mAnimationTimer = new Timer();
+ mAnimationTimer.scheduleAtFixedRate(mAnimationTask, ANIMATION_INTERVAL_MS,
+ ANIMATION_INTERVAL_MS);
+ }
+
+ public void setCounter(String text) {
+ mCounterText.setText(text);
+ }
+
+ public void setCounter(int i) {
+ setCounter(i < 0 ? "0" : String.valueOf(i));
+ }
+
+ @Override
+ public void onDetach() {
+ mAnimationTimer.cancel();
+ super.onDetach();
+ }
+}
diff --git a/samples/wearable/JumpingJack/Wearable/src/main/java/com/example/android/wearable/jumpingjack/fragments/SettingsFragment.java b/samples/wearable/JumpingJack/Wearable/src/main/java/com/example/android/wearable/jumpingjack/fragments/SettingsFragment.java
new file mode 100644
index 000000000..fffe8fb71
--- /dev/null
+++ b/samples/wearable/JumpingJack/Wearable/src/main/java/com/example/android/wearable/jumpingjack/fragments/SettingsFragment.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2014 Google Inc. All Rights Reserved.
+ *
+ * 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.
+ */
+
+package com.example.android.wearable.jumpingjack.fragments;
+
+import com.example.android.wearable.jumpingjack.MainActivity;
+import com.example.android.wearable.jumpingjack.R;
+
+import android.app.Fragment;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+
+/**
+ * A simple fragment that shows a button to reset the counter
+ */
+public class SettingsFragment extends Fragment {
+
+ private Button mButton;
+ private MainActivity mMainActivity;
+
+ public SettingsFragment(MainActivity mainActivity) {
+ mMainActivity = mainActivity;
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.setting_layout, container, false);
+ mButton = (Button) view.findViewById(R.id.btn);
+ mButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ mMainActivity.resetCounter();
+ }
+ });
+ return view;
+ }
+
+}
diff --git a/samples/wearable/JumpingJack/Wearable/src/main/res/drawable-hdpi/btn_reset_normal_200.png b/samples/wearable/JumpingJack/Wearable/src/main/res/drawable-hdpi/btn_reset_normal_200.png
new file mode 100644
index 000000000..e58520274
Binary files /dev/null and b/samples/wearable/JumpingJack/Wearable/src/main/res/drawable-hdpi/btn_reset_normal_200.png differ
diff --git a/samples/wearable/JumpingJack/Wearable/src/main/res/drawable-hdpi/btn_reset_pressed_200.png b/samples/wearable/JumpingJack/Wearable/src/main/res/drawable-hdpi/btn_reset_pressed_200.png
new file mode 100644
index 000000000..0b83b6d66
Binary files /dev/null and b/samples/wearable/JumpingJack/Wearable/src/main/res/drawable-hdpi/btn_reset_pressed_200.png differ
diff --git a/samples/wearable/JumpingJack/Wearable/src/main/res/drawable-hdpi/ic_launcher.png b/samples/wearable/JumpingJack/Wearable/src/main/res/drawable-hdpi/ic_launcher.png
new file mode 100644
index 000000000..2d0c37d0e
Binary files /dev/null and b/samples/wearable/JumpingJack/Wearable/src/main/res/drawable-hdpi/ic_launcher.png differ
diff --git a/samples/wearable/JumpingJack/Wearable/src/main/res/drawable-mdpi/ic_launcher.png b/samples/wearable/JumpingJack/Wearable/src/main/res/drawable-mdpi/ic_launcher.png
new file mode 100644
index 000000000..3211c9e8b
Binary files /dev/null and b/samples/wearable/JumpingJack/Wearable/src/main/res/drawable-mdpi/ic_launcher.png differ
diff --git a/samples/wearable/JumpingJack/Wearable/src/main/res/drawable-xhdpi/ic_launcher.png b/samples/wearable/JumpingJack/Wearable/src/main/res/drawable-xhdpi/ic_launcher.png
new file mode 100644
index 000000000..4ead8a29f
Binary files /dev/null and b/samples/wearable/JumpingJack/Wearable/src/main/res/drawable-xhdpi/ic_launcher.png differ
diff --git a/samples/wearable/JumpingJack/Wearable/src/main/res/drawable-xxhdpi/ic_launcher.png b/samples/wearable/JumpingJack/Wearable/src/main/res/drawable-xxhdpi/ic_launcher.png
new file mode 100644
index 000000000..8b357e4d5
Binary files /dev/null and b/samples/wearable/JumpingJack/Wearable/src/main/res/drawable-xxhdpi/ic_launcher.png differ
diff --git a/samples/wearable/JumpingJack/Wearable/src/main/res/drawable-xxxhdpi/ic_launcher.png b/samples/wearable/JumpingJack/Wearable/src/main/res/drawable-xxxhdpi/ic_launcher.png
new file mode 100644
index 000000000..da3c00a9a
Binary files /dev/null and b/samples/wearable/JumpingJack/Wearable/src/main/res/drawable-xxxhdpi/ic_launcher.png differ
diff --git a/samples/wearable/JumpingJack/Wearable/src/main/res/drawable/empty_10.png b/samples/wearable/JumpingJack/Wearable/src/main/res/drawable/empty_10.png
new file mode 100644
index 000000000..78ee76bb1
Binary files /dev/null and b/samples/wearable/JumpingJack/Wearable/src/main/res/drawable/empty_10.png differ
diff --git a/samples/wearable/JumpingJack/Wearable/src/main/res/drawable/full_10.png b/samples/wearable/JumpingJack/Wearable/src/main/res/drawable/full_10.png
new file mode 100644
index 000000000..53b799ebc
Binary files /dev/null and b/samples/wearable/JumpingJack/Wearable/src/main/res/drawable/full_10.png differ
diff --git a/samples/wearable/JumpingJack/Wearable/src/main/res/drawable/jump_down_50.png b/samples/wearable/JumpingJack/Wearable/src/main/res/drawable/jump_down_50.png
new file mode 100644
index 000000000..28980f808
Binary files /dev/null and b/samples/wearable/JumpingJack/Wearable/src/main/res/drawable/jump_down_50.png differ
diff --git a/samples/wearable/JumpingJack/Wearable/src/main/res/drawable/jump_up_50.png b/samples/wearable/JumpingJack/Wearable/src/main/res/drawable/jump_up_50.png
new file mode 100644
index 000000000..86dcef593
Binary files /dev/null and b/samples/wearable/JumpingJack/Wearable/src/main/res/drawable/jump_up_50.png differ
diff --git a/samples/wearable/JumpingJack/Wearable/src/main/res/drawable/submit_button.xml b/samples/wearable/JumpingJack/Wearable/src/main/res/drawable/submit_button.xml
new file mode 100644
index 000000000..e202e9aab
--- /dev/null
+++ b/samples/wearable/JumpingJack/Wearable/src/main/res/drawable/submit_button.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/samples/wearable/JumpingJack/Wearable/src/main/res/layout/counter_layout.xml b/samples/wearable/JumpingJack/Wearable/src/main/res/layout/counter_layout.xml
new file mode 100644
index 000000000..2216d2f69
--- /dev/null
+++ b/samples/wearable/JumpingJack/Wearable/src/main/res/layout/counter_layout.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/samples/wearable/JumpingJack/Wearable/src/main/res/layout/jj_layout.xml b/samples/wearable/JumpingJack/Wearable/src/main/res/layout/jj_layout.xml
new file mode 100644
index 000000000..371cfe880
--- /dev/null
+++ b/samples/wearable/JumpingJack/Wearable/src/main/res/layout/jj_layout.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/wearable/JumpingJack/Wearable/src/main/res/layout/setting_layout.xml b/samples/wearable/JumpingJack/Wearable/src/main/res/layout/setting_layout.xml
new file mode 100644
index 000000000..c012560c2
--- /dev/null
+++ b/samples/wearable/JumpingJack/Wearable/src/main/res/layout/setting_layout.xml
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/samples/wearable/JumpingJack/Wearable/src/main/res/values/colors.xml b/samples/wearable/JumpingJack/Wearable/src/main/res/values/colors.xml
new file mode 100644
index 000000000..3e62ace8e
--- /dev/null
+++ b/samples/wearable/JumpingJack/Wearable/src/main/res/values/colors.xml
@@ -0,0 +1,5 @@
+
+
+ #ffffff
+ #3f51b5
+
\ No newline at end of file
diff --git a/samples/wearable/JumpingJack/Wearable/src/main/res/values/dimens.xml b/samples/wearable/JumpingJack/Wearable/src/main/res/values/dimens.xml
new file mode 100644
index 000000000..47c822467
--- /dev/null
+++ b/samples/wearable/JumpingJack/Wearable/src/main/res/values/dimens.xml
@@ -0,0 +1,5 @@
+
+
+ 16dp
+ 16dp
+
diff --git a/samples/wearable/JumpingJack/Wearable/src/main/res/values/strings.xml b/samples/wearable/JumpingJack/Wearable/src/main/res/values/strings.xml
new file mode 100644
index 000000000..0c762c740
--- /dev/null
+++ b/samples/wearable/JumpingJack/Wearable/src/main/res/values/strings.xml
@@ -0,0 +1,7 @@
+
+
+
+ Jumping Jack
+ Reset Counter
+
+
diff --git a/samples/wearable/JumpingJack/build.gradle b/samples/wearable/JumpingJack/build.gradle
new file mode 100644
index 000000000..ce58a8f6a
--- /dev/null
+++ b/samples/wearable/JumpingJack/build.gradle
@@ -0,0 +1,17 @@
+// Top-level build file where you can add configuration options common to all sub-projects/modules.
+
+buildscript {
+ repositories {
+ mavenCentral()
+ }
+ dependencies {
+ classpath 'com.android.tools.build:gradle:0.11.+'
+ }
+}
+
+allprojects {
+ repositories {
+ mavenCentral()
+ }
+}
+
diff --git a/samples/wearable/JumpingJack/gradle.properties b/samples/wearable/JumpingJack/gradle.properties
new file mode 100644
index 000000000..5d08ba75b
--- /dev/null
+++ b/samples/wearable/JumpingJack/gradle.properties
@@ -0,0 +1,18 @@
+# Project-wide Gradle settings.
+
+# IDE (e.g. Android Studio) users:
+# Settings specified in this file will override any Gradle settings
+# configured through the IDE.
+
+# For more details on how to configure your build environment visit
+# http://www.gradle.org/docs/current/userguide/build_environment.html
+
+# Specifies the JVM arguments used for the daemon process.
+# The setting is particularly useful for tweaking memory settings.
+# Default value: -Xmx10248m -XX:MaxPermSize=256m
+# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
+
+# When configured, Gradle will run in incubating parallel mode.
+# This option should only be used with decoupled projects. More details, visit
+# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
+# org.gradle.parallel=true
\ No newline at end of file
diff --git a/samples/wearable/JumpingJack/gradle/wrapper/gradle-wrapper.jar b/samples/wearable/JumpingJack/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 000000000..583859812
Binary files /dev/null and b/samples/wearable/JumpingJack/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/samples/wearable/JumpingJack/gradle/wrapper/gradle-wrapper.properties b/samples/wearable/JumpingJack/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 000000000..e83e46081
--- /dev/null
+++ b/samples/wearable/JumpingJack/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Fri Mar 14 14:02:22 PDT 2014
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-all.zip
diff --git a/samples/wearable/JumpingJack/gradlew b/samples/wearable/JumpingJack/gradlew
new file mode 100755
index 000000000..91a7e269e
--- /dev/null
+++ b/samples/wearable/JumpingJack/gradlew
@@ -0,0 +1,164 @@
+#!/usr/bin/env bash
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+ echo "$*"
+}
+
+die ( ) {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+esac
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched.
+if $cygwin ; then
+ [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+fi
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >&-
+APP_HOME="`pwd -P`"
+cd "$SAVED" >&-
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+ JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
diff --git a/samples/wearable/JumpingJack/gradlew.bat b/samples/wearable/JumpingJack/gradlew.bat
new file mode 100644
index 000000000..aec99730b
--- /dev/null
+++ b/samples/wearable/JumpingJack/gradlew.bat
@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windowz variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%@eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/samples/wearable/JumpingJack/license.txt b/samples/wearable/JumpingJack/license.txt
new file mode 100644
index 000000000..1555b526f
--- /dev/null
+++ b/samples/wearable/JumpingJack/license.txt
@@ -0,0 +1,5 @@
+The Jumping Jack icons used in this app have been created by Jasper Reyes
+(http://thenounproject.com/term/jumping-jack/26440/) and Co-Effect Creative
+(http://thenounproject.com/term/exercise/15085/) from The Noun Project and are used under the
+Creative Commons (CC By 3.0) license
+
diff --git a/samples/wearable/JumpingJack/proguard-rules.txt b/samples/wearable/JumpingJack/proguard-rules.txt
new file mode 100644
index 000000000..0cc65eeb3
--- /dev/null
+++ b/samples/wearable/JumpingJack/proguard-rules.txt
@@ -0,0 +1,17 @@
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
\ No newline at end of file
diff --git a/samples/wearable/JumpingJack/settings.gradle b/samples/wearable/JumpingJack/settings.gradle
new file mode 100644
index 000000000..1d97d30e1
--- /dev/null
+++ b/samples/wearable/JumpingJack/settings.gradle
@@ -0,0 +1 @@
+include ':Wearable'
diff --git a/samples/wearable/Notifications/Application/build.gradle b/samples/wearable/Notifications/Application/build.gradle
index 5eb4f8b49..32208a32a 100644
--- a/samples/wearable/Notifications/Application/build.gradle
+++ b/samples/wearable/Notifications/Application/build.gradle
@@ -2,7 +2,7 @@ apply plugin: 'android'
android {
compileSdkVersion 19
- buildToolsVersion "19.1"
+ buildToolsVersion '20'
defaultConfig {
minSdkVersion 18
diff --git a/samples/wearable/Notifications/Wearable/build.gradle b/samples/wearable/Notifications/Wearable/build.gradle
index e339c0650..2a520308a 100644
--- a/samples/wearable/Notifications/Wearable/build.gradle
+++ b/samples/wearable/Notifications/Wearable/build.gradle
@@ -2,7 +2,7 @@ apply plugin: 'android'
android {
compileSdkVersion 20
- buildToolsVersion "19.1"
+ buildToolsVersion '20'
defaultConfig {
minSdkVersion 20
diff --git a/samples/wearable/Notifications/Wearable/src/main/java/com/example/android/support/wearable/notifications/MainActivity.java b/samples/wearable/Notifications/Wearable/src/main/java/com/example/android/support/wearable/notifications/MainActivity.java
index c3d16218f..74e5920d0 100644
--- a/samples/wearable/Notifications/Wearable/src/main/java/com/example/android/support/wearable/notifications/MainActivity.java
+++ b/samples/wearable/Notifications/Wearable/src/main/java/com/example/android/support/wearable/notifications/MainActivity.java
@@ -1,11 +1,11 @@
package com.example.android.support.wearable.notifications;
+import android.app.Activity;
import android.app.Notification;
import android.app.RemoteInput;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.NotificationManagerCompat;
-import android.support.wearable.activity.WatchActivity;
import android.support.wearable.view.WearableListView;
import android.text.TextUtils;
import android.view.LayoutInflater;
@@ -13,7 +13,7 @@ import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
-public class MainActivity extends WatchActivity implements WearableListView.ClickListener {
+public class MainActivity extends Activity implements WearableListView.ClickListener {
private static final int SAMPLE_NOTIFICATION_ID = 0;
public static final String KEY_REPLY = "reply";
diff --git a/samples/wearable/Quiz/Application/_index.html b/samples/wearable/Quiz/Application/_index.html
new file mode 100644
index 000000000..39e707562
--- /dev/null
+++ b/samples/wearable/Quiz/Application/_index.html
@@ -0,0 +1,12 @@
+
This sample provides an example of an app that uses Google Play Services Wearable Data APIs to
+communicate between applications on a phone and a paired wearable device. Users can create quiz
+questions on the phone, each of which has a DataItem associated with it. These DataItems are then
+received on the wearable, which then displays them as notifications. Each notification contains the
+question as the first page, followed by answers as actions. When an answer is selected, the
+corresponding question's DataItem is updated, which allows the phone application to update the
+status of the question (i.e. did the user answer it correctly or not) and prompt the next question.
+
+
At the end of the quiz, the sample uses the Google Play Services Wearable Message APIs to create
+an end-of-quiz report notification on the wearable, with an option to reset the quiz (by sending a
+message back to the phone).
+
\ No newline at end of file
diff --git a/samples/wearable/Quiz/Application/build.gradle b/samples/wearable/Quiz/Application/build.gradle
new file mode 100644
index 000000000..8482f3413
--- /dev/null
+++ b/samples/wearable/Quiz/Application/build.gradle
@@ -0,0 +1,30 @@
+apply plugin: 'android'
+
+android {
+ compileSdkVersion 20
+ buildToolsVersion '20'
+
+ defaultConfig {
+ minSdkVersion 18
+ targetSdkVersion 20
+ versionCode 1
+ versionName "1.0"
+ }
+
+ buildTypes {
+ release {
+ runProguard false
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
+ }
+ }
+
+ aaptOptions {
+ noCompress 'apk'
+ }
+}
+
+dependencies {
+ compile 'com.google.android.gms:play-services:5.0.+@aar'
+ compile "com.android.support:support-v13:20.0.+"
+ wearApp project(':Wearable')
+}
diff --git a/samples/wearable/Quiz/Application/proguard-rules.txt b/samples/wearable/Quiz/Application/proguard-rules.txt
new file mode 100644
index 000000000..08e5bdc8d
--- /dev/null
+++ b/samples/wearable/Quiz/Application/proguard-rules.txt
@@ -0,0 +1,22 @@
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
+-dontwarn android.support.wearable.view.DelayedConfirmationView
+-dontwarn android.support.wearable.view.CircledImageView
diff --git a/samples/wearable/Quiz/Application/src/main/AndroidManifest.xml b/samples/wearable/Quiz/Application/src/main/AndroidManifest.xml
new file mode 100644
index 000000000..fff21d0f9
--- /dev/null
+++ b/samples/wearable/Quiz/Application/src/main/AndroidManifest.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/wearable/Quiz/Application/src/main/assets/Quiz.json b/samples/wearable/Quiz/Application/src/main/assets/Quiz.json
new file mode 100644
index 000000000..db2448d9d
--- /dev/null
+++ b/samples/wearable/Quiz/Application/src/main/assets/Quiz.json
@@ -0,0 +1,124 @@
+{
+"questions": [
+{
+"question": "What is the scientific name of a butterfly?",
+"answers": [
+"Apis",
+"Coleoptera",
+"Formicidae",
+"Rhopalocera"
+],
+"correctIndex": 3
+},
+{
+"question": "How hot is the surface of the sun?",
+"answers": [
+"1,233 K",
+"5,778 K",
+"12,130 K",
+"101,300 K"
+],
+"correctIndex": 1
+},
+{
+"question": "Who are the actors in The Internship?",
+"answers": [
+"Ben Stiller, Jonah Hill",
+"Courteney Cox, Matt LeBlanc",
+"Kaley Cuoco, Jim Parsons",
+"Vince Vaughn, Owen Wilson"
+],
+"correctIndex": 3
+},
+{
+"question": "What is the capital of Spain?",
+"answers": [
+"Berlin",
+"Buenos Aires",
+"Madrid",
+"San Juan"
+],
+"correctIndex": 2
+},
+{
+"question": "What are the school colors of the University of Texas at Austin?",
+"answers": [
+"Black, Red",
+"Blue, Orange",
+"White, Burnt Orange",
+"White, Old gold, Gold"
+],
+"correctIndex": 2
+},
+{
+"question": "What is 70 degrees Fahrenheit in Celsius?",
+"answers": [
+"18.8889",
+"20",
+"21.1111",
+"158"
+],
+"correctIndex": 2
+},
+{
+"question": "When was Mahatma Gandhi born?",
+"answers": [
+"October 2, 1869",
+"December 15, 1872",
+"July 18, 1918",
+"January 15, 1929"
+],
+"correctIndex": 0
+},
+{
+"question": "How far is the moon from Earth?",
+"answers": [
+"7,918 miles (12,742 km)",
+"86,881 miles (139,822 km)",
+"238,400 miles (384,400 km)",
+"35,980,000 miles (57,910,000 km)"
+],
+"correctIndex": 2
+},
+{
+"question": "What is 65 times 52?",
+"answers": [
+"117",
+"3120",
+"3380",
+"3520"
+],
+"correctIndex": 2
+},
+{
+"question": "How tall is Mount Everest?",
+"answers": [
+"6,683 ft (2,037 m)",
+"7,918 ft (2,413 m)",
+"19,341 ft (5,895 m)",
+"29,029 ft (8,847 m)"
+],
+"correctIndex": 3
+},
+{
+"question": "When did The Avengers come out?",
+"answers": [
+"May 2, 2008",
+"May 4, 2012",
+"May 3, 2013",
+"April 4, 2014"
+],
+"correctIndex": 1
+},
+{
+"question": "What is 48,879 in hexidecimal?",
+"answers": [
+"0x18C1",
+"0xBEEF",
+"0xDEAD",
+"0x12D591"
+],
+"correctIndex": 1
+}
+]
+}
\ No newline at end of file
diff --git a/samples/wearable/Quiz/Application/src/main/java/com/example/android/wearable/quiz/Constants.java b/samples/wearable/Quiz/Application/src/main/java/com/example/android/wearable/quiz/Constants.java
new file mode 100644
index 000000000..832ddac06
--- /dev/null
+++ b/samples/wearable/Quiz/Application/src/main/java/com/example/android/wearable/quiz/Constants.java
@@ -0,0 +1,23 @@
+package com.example.android.wearable.quiz;
+
+/** Constants used in the companion app. */
+public final class Constants {
+ private Constants() {
+ }
+
+ public static final String ANSWERS = "answers";
+ public static final String CHOSEN_ANSWER_CORRECT = "chosen_answer_correct";
+ public static final String CORRECT_ANSWER_INDEX = "correct_answer_index";
+ public static final String QUESTION = "question";
+ public static final String QUESTION_INDEX = "question_index";
+ public static final String QUESTION_WAS_ANSWERED = "question_was_answered";
+ public static final String QUESTION_WAS_DELETED = "question_was_deleted";
+
+ public static final String NUM_CORRECT = "num_correct";
+ public static final String NUM_INCORRECT = "num_incorrect";
+ public static final String NUM_SKIPPED = "num_skipped";
+
+ public static final String QUIZ_ENDED_PATH = "/quiz_ended";
+ public static final String QUIZ_EXITED_PATH = "/quiz_exited";
+ public static final String RESET_QUIZ_PATH = "/reset_quiz";
+}
diff --git a/samples/wearable/Quiz/Application/src/main/java/com/example/android/wearable/quiz/JsonUtils.java b/samples/wearable/Quiz/Application/src/main/java/com/example/android/wearable/quiz/JsonUtils.java
new file mode 100644
index 000000000..21ac24ac5
--- /dev/null
+++ b/samples/wearable/Quiz/Application/src/main/java/com/example/android/wearable/quiz/JsonUtils.java
@@ -0,0 +1,31 @@
+package com.example.android.wearable.quiz;
+
+import android.content.Context;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+final class JsonUtils {
+ public static final String JSON_FIELD_QUESTIONS = "questions";
+ public static final String JSON_FIELD_QUESTION = "question";
+ public static final String JSON_FIELD_ANSWERS = "answers";
+ public static final String JSON_FIELD_CORRECT_INDEX = "correctIndex";
+ public static final int NUM_ANSWER_CHOICES = 4;
+
+ private JsonUtils() {
+ }
+
+ public static JSONObject loadJsonFile(Context context, String fileName) throws IOException,
+ JSONException {
+ InputStream is = context.getAssets().open(fileName);
+ int size = is.available();
+ byte[] buffer = new byte[size];
+ is.read(buffer);
+ is.close();
+ String jsonString = new String(buffer);
+ return new JSONObject(jsonString);
+ }
+}
diff --git a/samples/wearable/Quiz/Application/src/main/java/com/example/android/wearable/quiz/MainActivity.java b/samples/wearable/Quiz/Application/src/main/java/com/example/android/wearable/quiz/MainActivity.java
new file mode 100644
index 000000000..94b66e998
--- /dev/null
+++ b/samples/wearable/Quiz/Application/src/main/java/com/example/android/wearable/quiz/MainActivity.java
@@ -0,0 +1,569 @@
+package com.example.android.wearable.quiz;
+
+import static com.example.android.wearable.quiz.Constants.ANSWERS;
+import static com.example.android.wearable.quiz.Constants.CHOSEN_ANSWER_CORRECT;
+import static com.example.android.wearable.quiz.Constants.CORRECT_ANSWER_INDEX;
+import static com.example.android.wearable.quiz.Constants.NUM_CORRECT;
+import static com.example.android.wearable.quiz.Constants.NUM_INCORRECT;
+import static com.example.android.wearable.quiz.Constants.NUM_SKIPPED;
+import static com.example.android.wearable.quiz.Constants.QUESTION;
+import static com.example.android.wearable.quiz.Constants.QUESTION_INDEX;
+import static com.example.android.wearable.quiz.Constants.QUESTION_WAS_ANSWERED;
+import static com.example.android.wearable.quiz.Constants.QUESTION_WAS_DELETED;
+import static com.example.android.wearable.quiz.Constants.QUIZ_ENDED_PATH;
+import static com.example.android.wearable.quiz.Constants.QUIZ_EXITED_PATH;
+import static com.example.android.wearable.quiz.Constants.RESET_QUIZ_PATH;
+
+import android.app.Activity;
+import android.graphics.Color;
+import android.net.Uri;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.LinearLayout;
+import android.widget.RadioGroup;
+import android.widget.TextView;
+
+import com.google.android.gms.common.ConnectionResult;
+import com.google.android.gms.common.api.GoogleApiClient;
+import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
+import com.google.android.gms.common.api.ResultCallback;
+import com.google.android.gms.common.data.FreezableUtils;
+import com.google.android.gms.wearable.DataApi;
+import com.google.android.gms.wearable.DataEvent;
+import com.google.android.gms.wearable.DataEventBuffer;
+import com.google.android.gms.wearable.DataItem;
+import com.google.android.gms.wearable.DataItemBuffer;
+import com.google.android.gms.wearable.DataMap;
+import com.google.android.gms.wearable.DataMapItem;
+import com.google.android.gms.wearable.MessageApi;
+import com.google.android.gms.wearable.MessageEvent;
+import com.google.android.gms.wearable.Node;
+import com.google.android.gms.wearable.NodeApi;
+import com.google.android.gms.wearable.PutDataMapRequest;
+import com.google.android.gms.wearable.PutDataRequest;
+import com.google.android.gms.wearable.Wearable;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.PriorityQueue;
+
+/**
+ * Allows the user to create questions, which will be put as notifications on the watch's stream.
+ * The status of questions will be updated on the phone when the user answers them.
+ */
+public class MainActivity extends Activity implements DataApi.DataListener,
+ MessageApi.MessageListener, ConnectionCallbacks,
+ GoogleApiClient.OnConnectionFailedListener {
+
+ private static final String TAG = "ExampleQuizApp";
+ private static final String QUIZ_JSON_FILE = "Quiz.json";
+
+ // Various UI components.
+ private EditText questionEditText;
+ private EditText choiceAEditText;
+ private EditText choiceBEditText;
+ private EditText choiceCEditText;
+ private EditText choiceDEditText;
+ private RadioGroup choicesRadioGroup;
+ private TextView quizStatus;
+ private LinearLayout quizButtons;
+ private LinearLayout questionsContainer;
+ private Button readQuizFromFileButton;
+ private Button resetQuizButton;
+
+ private GoogleApiClient mGoogleApiClient;
+ private PriorityQueue mFutureQuestions;
+ private int mQuestionIndex = 0;
+ private boolean mHasQuestionBeenAsked = false;
+
+ // Data to display in end report.
+ private int mNumCorrect = 0;
+ private int mNumIncorrect = 0;
+ private int mNumSkipped = 0;
+
+ private static final Map radioIdToIndex;
+
+ static {
+ Map temp = new HashMap(4);
+ temp.put(R.id.choice_a_radio, 0);
+ temp.put(R.id.choice_b_radio, 1);
+ temp.put(R.id.choice_c_radio, 2);
+ temp.put(R.id.choice_d_radio, 3);
+ radioIdToIndex = Collections.unmodifiableMap(temp);
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_main);
+
+ mGoogleApiClient = new GoogleApiClient.Builder(this)
+ .addApi(Wearable.API)
+ .addConnectionCallbacks(this)
+ .addOnConnectionFailedListener(this)
+ .build();
+ mFutureQuestions = new PriorityQueue(10);
+
+ // Find UI components to be used later.
+ questionEditText = (EditText) findViewById(R.id.question_text);
+ choiceAEditText = (EditText) findViewById(R.id.choice_a_text);
+ choiceBEditText = (EditText) findViewById(R.id.choice_b_text);
+ choiceCEditText = (EditText) findViewById(R.id.choice_c_text);
+ choiceDEditText = (EditText) findViewById(R.id.choice_d_text);
+ choicesRadioGroup = (RadioGroup) findViewById(R.id.choices_radio_group);
+ quizStatus = (TextView) findViewById(R.id.quiz_status);
+ quizButtons = (LinearLayout) findViewById(R.id.quiz_buttons);
+ questionsContainer = (LinearLayout) findViewById(R.id.questions_container);
+ readQuizFromFileButton = (Button) findViewById(R.id.read_quiz_from_file_button);
+ resetQuizButton = (Button) findViewById(R.id.reset_quiz_button);
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ if (!mGoogleApiClient.isConnected()) {
+ mGoogleApiClient.connect();
+ }
+ }
+
+ @Override
+ protected void onStop() {
+ Wearable.DataApi.removeListener(mGoogleApiClient, this);
+ Wearable.MessageApi.removeListener(mGoogleApiClient, this);
+
+ // Tell the wearable to end the quiz (counting unanswered questions as skipped), and then
+ // disconnect mGoogleApiClient.
+ DataMap dataMap = new DataMap();
+ dataMap.putInt(NUM_CORRECT, mNumCorrect);
+ dataMap.putInt(NUM_INCORRECT, mNumIncorrect);
+ if (mHasQuestionBeenAsked) {
+ mNumSkipped += 1;
+ }
+ mNumSkipped += mFutureQuestions.size();
+ dataMap.putInt(NUM_SKIPPED, mNumSkipped);
+ if (mNumCorrect + mNumIncorrect + mNumSkipped > 0) {
+ sendMessageToWearable(QUIZ_EXITED_PATH, dataMap.toByteArray());
+ }
+
+ clearQuizStatus();
+ super.onStop();
+ }
+
+ @Override
+ public void onConnected(Bundle connectionHint) {
+ Wearable.DataApi.addListener(mGoogleApiClient, this);
+ Wearable.MessageApi.addListener(mGoogleApiClient, this);
+ }
+
+ @Override
+ public void onConnectionSuspended(int cause) {
+ // Ignore
+ }
+
+ @Override
+ public void onConnectionFailed(ConnectionResult result) {
+ Log.e(TAG, "Failed to connect to Google Play Services");
+ }
+
+ @Override
+ public void onMessageReceived(MessageEvent messageEvent) {
+ if (messageEvent.getPath().equals(RESET_QUIZ_PATH)) {
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ resetQuiz(null);
+ }
+ });
+ }
+ }
+
+ /**
+ * Used to ensure questions with smaller indexes come before questions with larger
+ * indexes. For example, question0 should come before question1.
+ */
+ private static class Question implements Comparable {
+ private String question;
+ private int questionIndex;
+ private String[] answers;
+ private int correctAnswerIndex;
+
+ public Question(String question, int questionIndex, String[] answers,
+ int correctAnswerIndex) {
+ this.question = question;
+ this.questionIndex = questionIndex;
+ this.answers = answers;
+ this.correctAnswerIndex = correctAnswerIndex;
+ }
+
+ public static Question fromJson(JSONObject questionObject, int questionIndex)
+ throws JSONException {
+ String question = questionObject.getString(JsonUtils.JSON_FIELD_QUESTION);
+ JSONArray answersJsonArray = questionObject.getJSONArray(JsonUtils.JSON_FIELD_ANSWERS);
+ String[] answers = new String[JsonUtils.NUM_ANSWER_CHOICES];
+ for (int j = 0; j < answersJsonArray.length(); j++) {
+ answers[j] = answersJsonArray.getString(j);
+ }
+ int correctIndex = questionObject.getInt(JsonUtils.JSON_FIELD_CORRECT_INDEX);
+ return new Question(question, questionIndex, answers, correctIndex);
+ }
+
+ @Override
+ public int compareTo(Question that) {
+ return this.questionIndex - that.questionIndex;
+ }
+
+ public PutDataRequest toPutDataRequest() {
+ PutDataMapRequest request = PutDataMapRequest.create("/question/" + questionIndex);
+ DataMap dataMap = request.getDataMap();
+ dataMap.putString(QUESTION, question);
+ dataMap.putInt(QUESTION_INDEX, questionIndex);
+ dataMap.putStringArray(ANSWERS, answers);
+ dataMap.putInt(CORRECT_ANSWER_INDEX, correctAnswerIndex);
+ return request.asPutDataRequest();
+ }
+ }
+
+ /**
+ * Create a quiz, as defined in Quiz.json, when the user clicks on "Read quiz from file."
+ * @throws IOException
+ */
+ public void readQuizFromFile(View view) throws IOException, JSONException {
+ clearQuizStatus();
+ JSONObject jsonObject = JsonUtils.loadJsonFile(this, QUIZ_JSON_FILE);
+ JSONArray jsonArray = jsonObject.getJSONArray(JsonUtils.JSON_FIELD_QUESTIONS);
+ for (int i = 0; i < jsonArray.length(); i++) {
+ JSONObject questionObject = jsonArray.getJSONObject(i);
+ Question question = Question.fromJson(questionObject, mQuestionIndex++);
+ addQuestionDataItem(question);
+ setNewQuestionStatus(question.question);
+ }
+ }
+
+ /**
+ * Adds a question (with answer choices) when user clicks on "Add Question."
+ */
+ public void addQuestion(View view) {
+ // Retrieve the question and answers supplied by the user.
+ String question = questionEditText.getText().toString();
+ String[] answers = new String[4];
+ answers[0] = choiceAEditText.getText().toString();
+ answers[1] = choiceBEditText.getText().toString();
+ answers[2] = choiceCEditText.getText().toString();
+ answers[3] = choiceDEditText.getText().toString();
+ int correctAnswerIndex = radioIdToIndex.get(choicesRadioGroup.getCheckedRadioButtonId());
+
+ addQuestionDataItem(new Question(question, mQuestionIndex++, answers, correctAnswerIndex));
+ setNewQuestionStatus(question);
+
+ // Clear the edit boxes to let the user input a new question.
+ questionEditText.setText("");
+ choiceAEditText.setText("");
+ choiceBEditText.setText("");
+ choiceCEditText.setText("");
+ choiceDEditText.setText("");
+ }
+
+ /**
+ * Adds the questions (and answers) to the wearable's stream by creating a Data Item
+ * that will be received on the wearable, which will create corresponding notifications.
+ */
+ private void addQuestionDataItem(Question question) {
+ if (!mHasQuestionBeenAsked) {
+ // Ask the question now.
+ Wearable.DataApi.putDataItem(mGoogleApiClient, question.toPutDataRequest());
+ setHasQuestionBeenAsked(true);
+ } else {
+ // Enqueue the question to be asked in the future.
+ mFutureQuestions.add(question);
+ }
+ }
+
+ /**
+ * Sets the question's status to be the default "unanswered." This will be updated when the
+ * user chooses an answer for the question on the wearable.
+ */
+ private void setNewQuestionStatus(String question) {
+ quizStatus.setVisibility(View.VISIBLE);
+ quizButtons.setVisibility(View.VISIBLE);
+ LayoutInflater inflater = LayoutInflater.from(this);
+ View questionStatusElem = inflater.inflate(R.layout.question_status_element, null, false);
+ ((TextView) questionStatusElem.findViewById(R.id.question)).setText(question);
+ ((TextView) questionStatusElem.findViewById(R.id.status))
+ .setText(R.string.question_unanswered);
+ questionsContainer.addView(questionStatusElem);
+ }
+
+ @Override
+ public void onDataChanged(DataEventBuffer dataEvents) {
+ final List events = FreezableUtils.freezeIterable(dataEvents);
+ dataEvents.close();
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ for (DataEvent event : events) {
+ if (event.getType() == DataEvent.TYPE_CHANGED) {
+ DataMap dataMap = DataMapItem.fromDataItem(event.getDataItem())
+ .getDataMap();
+ boolean questionWasAnswered = dataMap.getBoolean(QUESTION_WAS_ANSWERED);
+ boolean questionWasDeleted = dataMap.getBoolean(QUESTION_WAS_DELETED);
+ if (questionWasAnswered) {
+ // Update the answered question's status.
+ int questionIndex = dataMap.getInt(QUESTION_INDEX);
+ boolean questionCorrect = dataMap.getBoolean(CHOSEN_ANSWER_CORRECT);
+ updateQuestionStatus(questionIndex, questionCorrect);
+ askNextQuestionIfExists();
+ } else if (questionWasDeleted) {
+ // Update the deleted question's status by marking it as left blank.
+ int questionIndex = dataMap.getInt(QUESTION_INDEX);
+ markQuestionLeftBlank(questionIndex);
+ askNextQuestionIfExists();
+ }
+ }
+ }
+ }
+ });
+ }
+
+ /**
+ * Updates the given question based on whether it was answered correctly or not.
+ * This involves changing the question's text color and changing the status text for it.
+ */
+ public void updateQuestionStatus(int questionIndex, boolean questionCorrect) {
+ LinearLayout questionStatusElement = (LinearLayout)
+ questionsContainer.getChildAt(questionIndex);
+ TextView questionText = (TextView) questionStatusElement.findViewById(R.id.question);
+ TextView questionStatus = (TextView) questionStatusElement.findViewById(R.id.status);
+ if (questionCorrect) {
+ questionText.setTextColor(Color.GREEN);
+ questionStatus.setText(R.string.question_correct);
+ mNumCorrect++;
+ } else {
+ questionText.setTextColor(Color.RED);
+ questionStatus.setText(R.string.question_incorrect);
+ mNumIncorrect++;
+ }
+ }
+
+ /**
+ * Marks a question as "left blank" when its corresponding question notification is deleted.
+ */
+ private void markQuestionLeftBlank(int index) {
+ LinearLayout questionStatusElement = (LinearLayout) questionsContainer.getChildAt(index);
+ if (questionStatusElement != null) {
+ TextView questionText = (TextView) questionStatusElement.findViewById(R.id.question);
+ TextView questionStatus = (TextView) questionStatusElement.findViewById(R.id.status);
+ if (questionStatus.getText().equals(getString(R.string.question_unanswered))) {
+ questionText.setTextColor(Color.YELLOW);
+ questionStatus.setText(R.string.question_left_blank);
+ mNumSkipped++;
+ }
+ }
+ }
+
+ /**
+ * Asks the next enqueued question if it exists, otherwise ends the quiz.
+ */
+ private void askNextQuestionIfExists() {
+ if (mFutureQuestions.isEmpty()) {
+ // Quiz has been completed - send message to wearable to display end report.
+ DataMap dataMap = new DataMap();
+ dataMap.putInt(NUM_CORRECT, mNumCorrect);
+ dataMap.putInt(NUM_INCORRECT, mNumIncorrect);
+ dataMap.putInt(NUM_SKIPPED, mNumSkipped);
+ sendMessageToWearable(QUIZ_ENDED_PATH, dataMap.toByteArray());
+ setHasQuestionBeenAsked(false);
+ } else {
+ // Ask next question by putting a DataItem that will be received on the wearable.
+ Wearable.DataApi.putDataItem(mGoogleApiClient,
+ mFutureQuestions.remove().toPutDataRequest());
+ setHasQuestionBeenAsked(true);
+ }
+ }
+
+ private void sendMessageToWearable(final String path, final byte[] data) {
+ Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).setResultCallback(
+ new ResultCallback() {
+ @Override
+ public void onResult(NodeApi.GetConnectedNodesResult nodes) {
+ for (Node node : nodes.getNodes()) {
+ Wearable.MessageApi.sendMessage(mGoogleApiClient, node.getId(), path, data);
+ }
+
+ if (path.equals(QUIZ_EXITED_PATH) && mGoogleApiClient.isConnected()) {
+ mGoogleApiClient.disconnect();
+ }
+ }
+ });
+ }
+
+ /**
+ * Resets the current quiz when Reset Quiz is pressed.
+ */
+ public void resetQuiz(View view) {
+ // Reset quiz status in phone layout.
+ for(int i = 0; i < questionsContainer.getChildCount(); i++) {
+ LinearLayout questionStatusElement = (LinearLayout) questionsContainer.getChildAt(i);
+ TextView questionText = (TextView) questionStatusElement.findViewById(R.id.question);
+ TextView questionStatus = (TextView) questionStatusElement.findViewById(R.id.status);
+ questionText.setTextColor(Color.WHITE);
+ questionStatus.setText(R.string.question_unanswered);
+ }
+ // Reset data items and notifications on wearable.
+ if (mGoogleApiClient.isConnected()) {
+ Wearable.DataApi.getDataItems(mGoogleApiClient)
+ .setResultCallback(new ResultCallback() {
+ @Override
+ public void onResult(DataItemBuffer result) {
+ if (result.getStatus().isSuccess()) {
+ List dataItemList = FreezableUtils.freezeIterable(result);
+ result.close();
+ resetDataItems(dataItemList);
+ } else {
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "Reset quiz: failed to get Data Items to reset");
+ }
+ }
+ result.close();
+ }
+ });
+ } else {
+ Log.e(TAG, "Failed to reset data items because client is disconnected from "
+ + "Google Play Services");
+ }
+ setHasQuestionBeenAsked(false);
+ mNumCorrect = 0;
+ mNumIncorrect = 0;
+ mNumSkipped = 0;
+ }
+
+ private void resetDataItems(List dataItemList) {
+ if (mGoogleApiClient.isConnected()) {
+ for (final DataItem dataItem : dataItemList) {
+ final Uri dataItemUri = dataItem.getUri();
+ Wearable.DataApi.getDataItem(mGoogleApiClient, dataItemUri)
+ .setResultCallback(new ResetDataItemCallback());
+ }
+ } else {
+ Log.e(TAG, "Failed to reset data items because client is disconnected from "
+ + "Google Play Services");
+ }
+ }
+
+ /**
+ * Callback that marks a DataItem, which represents a question, as unanswered and not deleted.
+ */
+ private class ResetDataItemCallback implements ResultCallback {
+ @Override
+ public void onResult(DataApi.DataItemResult dataItemResult) {
+ if (dataItemResult.getStatus().isSuccess()) {
+ PutDataMapRequest request = PutDataMapRequest.createFromDataMapItem(
+ DataMapItem.fromDataItem(dataItemResult.getDataItem()));
+ DataMap dataMap = request.getDataMap();
+ dataMap.putBoolean(QUESTION_WAS_ANSWERED, false);
+ dataMap.putBoolean(QUESTION_WAS_DELETED, false);
+ if (!mHasQuestionBeenAsked && dataMap.getInt(QUESTION_INDEX) == 0) {
+ // Ask the first question now.
+ Wearable.DataApi.putDataItem(mGoogleApiClient, request.asPutDataRequest());
+ setHasQuestionBeenAsked(true);
+ } else {
+ // Enqueue future questions.
+ mFutureQuestions.add(new Question(dataMap.getString(QUESTION),
+ dataMap.getInt(QUESTION_INDEX), dataMap.getStringArray(ANSWERS),
+ dataMap.getInt(CORRECT_ANSWER_INDEX)));
+ }
+ } else {
+ Log.e(TAG, "Failed to reset data item " + dataItemResult.getDataItem().getUri());
+ }
+ }
+ }
+
+ /**
+ * Clears the current quiz when user clicks on "New Quiz."
+ * On this end, this involves clearing the quiz status layout and deleting all DataItems. The
+ * wearable will then remove any outstanding question notifications upon receiving this change.
+ */
+ public void newQuiz(View view) {
+ clearQuizStatus();
+ if (mGoogleApiClient.isConnected()) {
+ Wearable.DataApi.getDataItems(mGoogleApiClient)
+ .setResultCallback(new ResultCallback() {
+ @Override
+ public void onResult(DataItemBuffer result) {
+ if (result.getStatus().isSuccess()) {
+ List dataItemUriList = new ArrayList();
+ for (final DataItem dataItem : result) {
+ dataItemUriList.add(dataItem.getUri());
+ }
+ result.close();
+ deleteDataItems(dataItemUriList);
+ } else {
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "Clear quiz: failed to get Data Items for deletion");
+ }
+ }
+ result.close();
+ }
+ });
+ } else {
+ Log.e(TAG, "Failed to delete data items because client is disconnected from "
+ + "Google Play Services");
+ }
+ }
+
+ /**
+ * Removes quiz status views (i.e. the views describing the status of each question).
+ */
+ private void clearQuizStatus() {
+ questionsContainer.removeAllViews();
+ quizStatus.setVisibility(View.INVISIBLE);
+ quizButtons.setVisibility(View.INVISIBLE);
+ setHasQuestionBeenAsked(false);
+ mFutureQuestions.clear();
+ mQuestionIndex = 0;
+ mNumCorrect = 0;
+ mNumIncorrect = 0;
+ mNumSkipped = 0;
+ }
+
+ private void deleteDataItems(List dataItemUriList) {
+ if (mGoogleApiClient.isConnected()) {
+ for (final Uri dataItemUri : dataItemUriList) {
+ Wearable.DataApi.deleteDataItems(mGoogleApiClient, dataItemUri)
+ .setResultCallback(new ResultCallback() {
+ @Override
+ public void onResult(DataApi.DeleteDataItemsResult deleteResult) {
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ if (deleteResult.getStatus().isSuccess()) {
+ Log.d(TAG, "Successfully deleted data item " + dataItemUri);
+ } else {
+ Log.d(TAG, "Failed to delete data item " + dataItemUri);
+ }
+ }
+ }
+ });
+ }
+ } else {
+ Log.e(TAG, "Failed to delete data items because client is disconnected from "
+ + "Google Play Services");
+ }
+ }
+
+ private void setHasQuestionBeenAsked(boolean b) {
+ mHasQuestionBeenAsked = b;
+ // Only let user click on Reset or Read from file if they have answered all the questions.
+ readQuizFromFileButton.setEnabled(!mHasQuestionBeenAsked);
+ resetQuizButton.setEnabled(!mHasQuestionBeenAsked);
+ }
+}
diff --git a/samples/wearable/Quiz/Application/src/main/res/drawable-hdpi/ic_choice_a.png b/samples/wearable/Quiz/Application/src/main/res/drawable-hdpi/ic_choice_a.png
new file mode 100644
index 000000000..de18ce11a
Binary files /dev/null and b/samples/wearable/Quiz/Application/src/main/res/drawable-hdpi/ic_choice_a.png differ
diff --git a/samples/wearable/Quiz/Application/src/main/res/drawable-hdpi/ic_choice_b.png b/samples/wearable/Quiz/Application/src/main/res/drawable-hdpi/ic_choice_b.png
new file mode 100644
index 000000000..3cdfe9750
Binary files /dev/null and b/samples/wearable/Quiz/Application/src/main/res/drawable-hdpi/ic_choice_b.png differ
diff --git a/samples/wearable/Quiz/Application/src/main/res/drawable-hdpi/ic_choice_c.png b/samples/wearable/Quiz/Application/src/main/res/drawable-hdpi/ic_choice_c.png
new file mode 100644
index 000000000..f0ed2ef99
Binary files /dev/null and b/samples/wearable/Quiz/Application/src/main/res/drawable-hdpi/ic_choice_c.png differ
diff --git a/samples/wearable/Quiz/Application/src/main/res/drawable-hdpi/ic_choice_d.png b/samples/wearable/Quiz/Application/src/main/res/drawable-hdpi/ic_choice_d.png
new file mode 100644
index 000000000..c158d2953
Binary files /dev/null and b/samples/wearable/Quiz/Application/src/main/res/drawable-hdpi/ic_choice_d.png differ
diff --git a/samples/wearable/Quiz/Application/src/main/res/drawable-hdpi/ic_launcher.png b/samples/wearable/Quiz/Application/src/main/res/drawable-hdpi/ic_launcher.png
new file mode 100755
index 000000000..91a8cff95
Binary files /dev/null and b/samples/wearable/Quiz/Application/src/main/res/drawable-hdpi/ic_launcher.png differ
diff --git a/samples/wearable/Quiz/Application/src/main/res/drawable-hdpi/ic_unknown_choice.png b/samples/wearable/Quiz/Application/src/main/res/drawable-hdpi/ic_unknown_choice.png
new file mode 100644
index 000000000..9aed51728
Binary files /dev/null and b/samples/wearable/Quiz/Application/src/main/res/drawable-hdpi/ic_unknown_choice.png differ
diff --git a/samples/wearable/Quiz/Application/src/main/res/drawable-mdpi/ic_choice_a.png b/samples/wearable/Quiz/Application/src/main/res/drawable-mdpi/ic_choice_a.png
new file mode 100644
index 000000000..57459365c
Binary files /dev/null and b/samples/wearable/Quiz/Application/src/main/res/drawable-mdpi/ic_choice_a.png differ
diff --git a/samples/wearable/Quiz/Application/src/main/res/drawable-mdpi/ic_choice_b.png b/samples/wearable/Quiz/Application/src/main/res/drawable-mdpi/ic_choice_b.png
new file mode 100644
index 000000000..958b92e31
Binary files /dev/null and b/samples/wearable/Quiz/Application/src/main/res/drawable-mdpi/ic_choice_b.png differ
diff --git a/samples/wearable/Quiz/Application/src/main/res/drawable-mdpi/ic_choice_c.png b/samples/wearable/Quiz/Application/src/main/res/drawable-mdpi/ic_choice_c.png
new file mode 100644
index 000000000..9fcfab754
Binary files /dev/null and b/samples/wearable/Quiz/Application/src/main/res/drawable-mdpi/ic_choice_c.png differ
diff --git a/samples/wearable/Quiz/Application/src/main/res/drawable-mdpi/ic_choice_d.png b/samples/wearable/Quiz/Application/src/main/res/drawable-mdpi/ic_choice_d.png
new file mode 100644
index 000000000..821cadb78
Binary files /dev/null and b/samples/wearable/Quiz/Application/src/main/res/drawable-mdpi/ic_choice_d.png differ
diff --git a/samples/wearable/Quiz/Application/src/main/res/drawable-mdpi/ic_launcher.png b/samples/wearable/Quiz/Application/src/main/res/drawable-mdpi/ic_launcher.png
new file mode 100755
index 000000000..728ee6d73
Binary files /dev/null and b/samples/wearable/Quiz/Application/src/main/res/drawable-mdpi/ic_launcher.png differ
diff --git a/samples/wearable/Quiz/Application/src/main/res/drawable-mdpi/ic_unknown_choice.png b/samples/wearable/Quiz/Application/src/main/res/drawable-mdpi/ic_unknown_choice.png
new file mode 100644
index 000000000..b8030ef08
Binary files /dev/null and b/samples/wearable/Quiz/Application/src/main/res/drawable-mdpi/ic_unknown_choice.png differ
diff --git a/samples/wearable/Quiz/Application/src/main/res/drawable-xhdpi/ic_choice_a.png b/samples/wearable/Quiz/Application/src/main/res/drawable-xhdpi/ic_choice_a.png
new file mode 100644
index 000000000..3dba96f32
Binary files /dev/null and b/samples/wearable/Quiz/Application/src/main/res/drawable-xhdpi/ic_choice_a.png differ
diff --git a/samples/wearable/Quiz/Application/src/main/res/drawable-xhdpi/ic_choice_b.png b/samples/wearable/Quiz/Application/src/main/res/drawable-xhdpi/ic_choice_b.png
new file mode 100644
index 000000000..9ca3c85f2
Binary files /dev/null and b/samples/wearable/Quiz/Application/src/main/res/drawable-xhdpi/ic_choice_b.png differ
diff --git a/samples/wearable/Quiz/Application/src/main/res/drawable-xhdpi/ic_choice_c.png b/samples/wearable/Quiz/Application/src/main/res/drawable-xhdpi/ic_choice_c.png
new file mode 100644
index 000000000..b84b3b76d
Binary files /dev/null and b/samples/wearable/Quiz/Application/src/main/res/drawable-xhdpi/ic_choice_c.png differ
diff --git a/samples/wearable/Quiz/Application/src/main/res/drawable-xhdpi/ic_choice_d.png b/samples/wearable/Quiz/Application/src/main/res/drawable-xhdpi/ic_choice_d.png
new file mode 100644
index 000000000..185e91ec8
Binary files /dev/null and b/samples/wearable/Quiz/Application/src/main/res/drawable-xhdpi/ic_choice_d.png differ
diff --git a/samples/wearable/Quiz/Application/src/main/res/drawable-xhdpi/ic_launcher.png b/samples/wearable/Quiz/Application/src/main/res/drawable-xhdpi/ic_launcher.png
new file mode 100755
index 000000000..64a585453
Binary files /dev/null and b/samples/wearable/Quiz/Application/src/main/res/drawable-xhdpi/ic_launcher.png differ
diff --git a/samples/wearable/Quiz/Application/src/main/res/drawable-xxhdpi/ic_launcher.png b/samples/wearable/Quiz/Application/src/main/res/drawable-xxhdpi/ic_launcher.png
new file mode 100755
index 000000000..86a395bb6
Binary files /dev/null and b/samples/wearable/Quiz/Application/src/main/res/drawable-xxhdpi/ic_launcher.png differ
diff --git a/samples/wearable/Quiz/Application/src/main/res/drawable/selected_background.xml b/samples/wearable/Quiz/Application/src/main/res/drawable/selected_background.xml
new file mode 100644
index 000000000..351774a88
--- /dev/null
+++ b/samples/wearable/Quiz/Application/src/main/res/drawable/selected_background.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/samples/wearable/Quiz/Application/src/main/res/drawable/unselected_background.xml b/samples/wearable/Quiz/Application/src/main/res/drawable/unselected_background.xml
new file mode 100644
index 000000000..b9a43d1ef
--- /dev/null
+++ b/samples/wearable/Quiz/Application/src/main/res/drawable/unselected_background.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/samples/wearable/Quiz/Application/src/main/res/layout/activity_main.xml b/samples/wearable/Quiz/Application/src/main/res/layout/activity_main.xml
new file mode 100644
index 000000000..ed684f141
--- /dev/null
+++ b/samples/wearable/Quiz/Application/src/main/res/layout/activity_main.xml
@@ -0,0 +1,152 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/wearable/Quiz/Application/src/main/res/layout/question_status_element.xml b/samples/wearable/Quiz/Application/src/main/res/layout/question_status_element.xml
new file mode 100644
index 000000000..3cf9ec214
--- /dev/null
+++ b/samples/wearable/Quiz/Application/src/main/res/layout/question_status_element.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/samples/wearable/Quiz/Application/src/main/res/values/dimens.xml b/samples/wearable/Quiz/Application/src/main/res/values/dimens.xml
new file mode 100644
index 000000000..8f4947f3a
--- /dev/null
+++ b/samples/wearable/Quiz/Application/src/main/res/values/dimens.xml
@@ -0,0 +1,13 @@
+
+
+ 16dp
+ 16dp
+
+ 12dp
+ 8dp
+ 8dp
+ 50dp
+
+ 48dp
+
+
diff --git a/samples/wearable/Quiz/Application/src/main/res/values/strings.xml b/samples/wearable/Quiz/Application/src/main/res/values/strings.xml
new file mode 100644
index 000000000..5d3a44895
--- /dev/null
+++ b/samples/wearable/Quiz/Application/src/main/res/values/strings.xml
@@ -0,0 +1,25 @@
+
+
+
+ Quiz
+
+ Read quiz from file
+
+ Question
+ Choice A
+ Choice B
+ Choice C
+ Choice D
+ Add Question
+
+ Quiz Status
+ Question
+ This question has not yet been answered.
+ This question has been answered incorrectly.
+ This question has been answered correctly!
+ This question was left blank.
+
+ Reset Quiz
+ New Quiz
+
+
diff --git a/samples/wearable/Quiz/Application/src/main/res/values/styles.xml b/samples/wearable/Quiz/Application/src/main/res/values/styles.xml
new file mode 100644
index 000000000..7247b39b9
--- /dev/null
+++ b/samples/wearable/Quiz/Application/src/main/res/values/styles.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
diff --git a/samples/wearable/Quiz/Wearable/build.gradle b/samples/wearable/Quiz/Wearable/build.gradle
new file mode 100644
index 000000000..35b2f1f3d
--- /dev/null
+++ b/samples/wearable/Quiz/Wearable/build.gradle
@@ -0,0 +1,26 @@
+apply plugin: 'android'
+
+android {
+ compileSdkVersion 20
+ buildToolsVersion '20'
+
+ defaultConfig {
+ minSdkVersion 20
+ targetSdkVersion 20
+ versionCode 1
+ versionName "1.0"
+ }
+
+ buildTypes {
+ release {
+ runProguard false
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
+ }
+ }
+}
+
+dependencies {
+ compile 'com.google.android.gms:play-services:5.0.+@aar'
+ compile "com.android.support:support-v13:20.0.+"
+ compile "com.google.android.support:wearable:1.0.+"
+}
diff --git a/samples/wearable/Quiz/Wearable/proguard-rules.txt b/samples/wearable/Quiz/Wearable/proguard-rules.txt
new file mode 100644
index 000000000..f2fe1559a
--- /dev/null
+++ b/samples/wearable/Quiz/Wearable/proguard-rules.txt
@@ -0,0 +1,20 @@
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
diff --git a/samples/wearable/Quiz/Wearable/src/main/AndroidManifest.xml b/samples/wearable/Quiz/Wearable/src/main/AndroidManifest.xml
new file mode 100644
index 000000000..3427de509
--- /dev/null
+++ b/samples/wearable/Quiz/Wearable/src/main/AndroidManifest.xml
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/wearable/Quiz/Wearable/src/main/java/com/example/android/wearable/quiz/Constants.java b/samples/wearable/Quiz/Wearable/src/main/java/com/example/android/wearable/quiz/Constants.java
new file mode 100644
index 000000000..2038817c9
--- /dev/null
+++ b/samples/wearable/Quiz/Wearable/src/main/java/com/example/android/wearable/quiz/Constants.java
@@ -0,0 +1,25 @@
+package com.example.android.wearable.quiz;
+
+/** Constants used in the wearable app. */
+public final class Constants {
+ private Constants() {
+ }
+
+ public static final String ANSWERS = "answers";
+ public static final String CHOSEN_ANSWER_CORRECT = "chosen_answer_correct";
+ public static final String CORRECT_ANSWER_INDEX = "correct_answer_index";
+ public static final String QUESTION = "question";
+ public static final String QUESTION_INDEX = "question_index";
+ public static final String QUESTION_WAS_ANSWERED = "question_was_answered";
+ public static final String QUESTION_WAS_DELETED = "question_was_deleted";
+
+ public static final String NUM_CORRECT = "num_correct";
+ public static final String NUM_INCORRECT = "num_incorrect";
+ public static final String NUM_SKIPPED = "num_skipped";
+
+ public static final String QUIZ_ENDED_PATH = "/quiz_ended";
+ public static final String QUIZ_EXITED_PATH = "/quiz_exited";
+ public static final String RESET_QUIZ_PATH = "/reset_quiz";
+
+ public static final int CONNECT_TIMEOUT_MS = 100;
+}
diff --git a/samples/wearable/Quiz/Wearable/src/main/java/com/example/android/wearable/quiz/DeleteQuestionService.java b/samples/wearable/Quiz/Wearable/src/main/java/com/example/android/wearable/quiz/DeleteQuestionService.java
new file mode 100644
index 000000000..6c5e09f15
--- /dev/null
+++ b/samples/wearable/Quiz/Wearable/src/main/java/com/example/android/wearable/quiz/DeleteQuestionService.java
@@ -0,0 +1,78 @@
+package com.example.android.wearable.quiz;
+
+import android.app.IntentService;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Bundle;
+import android.util.Log;
+
+import com.google.android.gms.common.ConnectionResult;
+import com.google.android.gms.common.api.GoogleApiClient;
+import com.google.android.gms.wearable.DataApi;
+import com.google.android.gms.wearable.DataMap;
+import com.google.android.gms.wearable.DataMapItem;
+import com.google.android.gms.wearable.PutDataMapRequest;
+import com.google.android.gms.wearable.PutDataRequest;
+import com.google.android.gms.wearable.Wearable;
+
+import java.util.concurrent.TimeUnit;
+
+import static com.example.android.wearable.quiz.Constants.CONNECT_TIMEOUT_MS;
+import static com.example.android.wearable.quiz.Constants.QUESTION_WAS_DELETED;
+
+/**
+ * Used to update quiz status on the phone when user dismisses a question on the watch.
+ */
+public class DeleteQuestionService extends IntentService
+ implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
+
+ private static final String TAG = "DeleteQuestionReceiver";
+
+ private GoogleApiClient mGoogleApiClient;
+
+ public DeleteQuestionService() {
+ super(DeleteQuestionService.class.getSimpleName());
+ }
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ mGoogleApiClient = new GoogleApiClient.Builder(this)
+ .addApi(Wearable.API)
+ .addConnectionCallbacks(this)
+ .addOnConnectionFailedListener(this)
+ .build();
+ }
+
+ @Override
+ public void onHandleIntent(Intent intent) {
+ mGoogleApiClient.blockingConnect(CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
+ Uri dataItemUri = intent.getData();
+ if (!mGoogleApiClient.isConnected()) {
+ Log.e(TAG, "Failed to update data item " + dataItemUri
+ + " because client is disconnected from Google Play Services");
+ return;
+ }
+ DataApi.DataItemResult dataItemResult = Wearable.DataApi.getDataItem(
+ mGoogleApiClient, dataItemUri).await();
+ PutDataMapRequest putDataMapRequest = PutDataMapRequest
+ .createFromDataMapItem(DataMapItem.fromDataItem(dataItemResult.getDataItem()));
+ DataMap dataMap = putDataMapRequest.getDataMap();
+ dataMap.putBoolean(QUESTION_WAS_DELETED, true);
+ PutDataRequest request = putDataMapRequest.asPutDataRequest();
+ Wearable.DataApi.putDataItem(mGoogleApiClient, request).await();
+ mGoogleApiClient.disconnect();
+ }
+
+ @Override
+ public void onConnected(Bundle bundle) {
+ }
+
+ @Override
+ public void onConnectionSuspended(int i) {
+ }
+
+ @Override
+ public void onConnectionFailed(ConnectionResult connectionResult) {
+ }
+}
diff --git a/samples/wearable/Quiz/Wearable/src/main/java/com/example/android/wearable/quiz/QuizListenerService.java b/samples/wearable/Quiz/Wearable/src/main/java/com/example/android/wearable/quiz/QuizListenerService.java
new file mode 100644
index 000000000..f8c5322bb
--- /dev/null
+++ b/samples/wearable/Quiz/Wearable/src/main/java/com/example/android/wearable/quiz/QuizListenerService.java
@@ -0,0 +1,203 @@
+package com.example.android.wearable.quiz;
+
+import static com.example.android.wearable.quiz.Constants.ANSWERS;
+import static com.example.android.wearable.quiz.Constants.CONNECT_TIMEOUT_MS;
+import static com.example.android.wearable.quiz.Constants.CORRECT_ANSWER_INDEX;
+import static com.example.android.wearable.quiz.Constants.NUM_CORRECT;
+import static com.example.android.wearable.quiz.Constants.NUM_INCORRECT;
+import static com.example.android.wearable.quiz.Constants.NUM_SKIPPED;
+import static com.example.android.wearable.quiz.Constants.QUESTION;
+import static com.example.android.wearable.quiz.Constants.QUESTION_INDEX;
+import static com.example.android.wearable.quiz.Constants.QUESTION_WAS_ANSWERED;
+import static com.example.android.wearable.quiz.Constants.QUESTION_WAS_DELETED;
+import static com.example.android.wearable.quiz.Constants.QUIZ_ENDED_PATH;
+import static com.example.android.wearable.quiz.Constants.QUIZ_EXITED_PATH;
+
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.content.Intent;
+import android.net.Uri;
+import android.text.SpannableStringBuilder;
+import android.text.style.ForegroundColorSpan;
+import android.util.Log;
+
+import com.google.android.gms.common.ConnectionResult;
+import com.google.android.gms.common.api.GoogleApiClient;
+import com.google.android.gms.common.data.FreezableUtils;
+import com.google.android.gms.wearable.DataEvent;
+import com.google.android.gms.wearable.DataEventBuffer;
+import com.google.android.gms.wearable.DataItem;
+import com.google.android.gms.wearable.DataMap;
+import com.google.android.gms.wearable.DataMapItem;
+import com.google.android.gms.wearable.MessageEvent;
+import com.google.android.gms.wearable.Wearable;
+import com.google.android.gms.wearable.WearableListenerService;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Listens to changes in DataItems, which represent quiz questions.
+ * If a new question is created, this builds a new notification for it.
+ * Otherwise, if a question is deleted, this cancels the corresponding notification.
+ *
+ * When the quiz ends, this listener receives a message telling it to create an end-of-quiz report.
+ */
+public class QuizListenerService extends WearableListenerService {
+ private static final String TAG = "QuizSample";
+ private static final int QUIZ_REPORT_NOTIF_ID = -1; // Never used by question notifications.
+ private static final Map questionNumToDrawableId;
+
+ static {
+ Map temp = new HashMap(4);
+ temp.put(0, R.drawable.ic_choice_a);
+ temp.put(1, R.drawable.ic_choice_b);
+ temp.put(2, R.drawable.ic_choice_c);
+ temp.put(3, R.drawable.ic_choice_d);
+ questionNumToDrawableId = Collections.unmodifiableMap(temp);
+ }
+
+ @Override
+ public void onDataChanged(DataEventBuffer dataEvents) {
+ final List events = FreezableUtils.freezeIterable(dataEvents);
+ dataEvents.close();
+
+ GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this)
+ .addApi(Wearable.API)
+ .build();
+
+ ConnectionResult connectionResult = googleApiClient.blockingConnect(CONNECT_TIMEOUT_MS,
+ TimeUnit.MILLISECONDS);
+ if (!connectionResult.isSuccess()) {
+ Log.e(TAG, "QuizListenerService failed to connect to GoogleApiClient.");
+ return;
+ }
+
+ for (DataEvent event : events) {
+ if (event.getType() == DataEvent.TYPE_CHANGED) {
+ DataItem dataItem = event.getDataItem();
+ DataMap dataMap = DataMapItem.fromDataItem(dataItem).getDataMap();
+ if (dataMap.getBoolean(QUESTION_WAS_ANSWERED)
+ || dataMap.getBoolean(QUESTION_WAS_DELETED)) {
+ // Ignore the change in data; it is used in MainActivity to update
+ // the question's status (i.e. was the answer right or wrong or left blank).
+ continue;
+ }
+ String question = dataMap.getString(QUESTION);
+ int questionIndex = dataMap.getInt(QUESTION_INDEX);
+ int questionNum = questionIndex + 1;
+ String[] answers = dataMap.getStringArray(ANSWERS);
+ int correctAnswerIndex = dataMap.getInt(CORRECT_ANSWER_INDEX);
+ Intent deleteOperation = new Intent(this, DeleteQuestionService.class);
+ deleteOperation.setData(dataItem.getUri());
+ PendingIntent deleteIntent = PendingIntent.getService(this, 0,
+ deleteOperation, PendingIntent.FLAG_UPDATE_CURRENT);
+ // First page of notification contains question as Big Text.
+ Notification.BigTextStyle bigTextStyle = new Notification.BigTextStyle()
+ .setBigContentTitle(getString(R.string.question, questionNum))
+ .bigText(question);
+ Notification.Builder builder = new Notification.Builder(this)
+ .setStyle(bigTextStyle)
+ .setSmallIcon(R.drawable.ic_launcher)
+ .setLocalOnly(true)
+ .setDeleteIntent(deleteIntent);
+
+ // Add answers as actions.
+ Notification.WearableExtender wearableOptions = new Notification.WearableExtender();
+ for (int i = 0; i < answers.length; i++) {
+ Notification answerPage = new Notification.Builder(this)
+ .setContentTitle(question)
+ .setContentText(answers[i])
+ .extend(new Notification.WearableExtender()
+ .setContentAction(i))
+ .build();
+
+ boolean correct = (i == correctAnswerIndex);
+ Intent updateOperation = new Intent(this, UpdateQuestionService.class);
+ // Give each intent a unique action.
+ updateOperation.setAction("question_" + questionIndex + "_answer_" + i);
+ updateOperation.setData(dataItem.getUri());
+ updateOperation.putExtra(UpdateQuestionService.EXTRA_QUESTION_INDEX,
+ questionIndex);
+ updateOperation.putExtra(UpdateQuestionService.EXTRA_QUESTION_CORRECT, correct);
+ PendingIntent updateIntent = PendingIntent.getService(this, 0, updateOperation,
+ PendingIntent.FLAG_UPDATE_CURRENT);
+ Notification.Action action = new Notification.Action.Builder(
+ questionNumToDrawableId.get(i), null, updateIntent)
+ .build();
+ wearableOptions.addAction(action).addPage(answerPage);
+ }
+ builder.extend(wearableOptions);
+ Notification notification = builder.build();
+ ((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
+ .notify(questionIndex, notification);
+ } else if (event.getType() == DataEvent.TYPE_DELETED) {
+ Uri uri = event.getDataItem().getUri();
+ // URI's are of the form "/question/0", "/question/1" etc.
+ // We use the question index as the notification id.
+ int notificationId = Integer.parseInt(uri.getLastPathSegment());
+ ((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
+ .cancel(notificationId);
+ }
+ // Delete the quiz report, if it exists.
+ ((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
+ .cancel(QUIZ_REPORT_NOTIF_ID);
+ }
+ googleApiClient.disconnect();
+ }
+
+ @Override
+ public void onMessageReceived(MessageEvent messageEvent) {
+ String path = messageEvent.getPath();
+ if (path.equals(QUIZ_EXITED_PATH)) {
+ // Remove any lingering question notifications.
+ ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).cancelAll();
+ }
+ if (path.equals(QUIZ_ENDED_PATH) || path.equals(QUIZ_EXITED_PATH)) {
+ // Quiz ended - display overall results.
+ DataMap dataMap = DataMap.fromByteArray(messageEvent.getData());
+ int numCorrect = dataMap.getInt(NUM_CORRECT);
+ int numIncorrect = dataMap.getInt(NUM_INCORRECT);
+ int numSkipped = dataMap.getInt(NUM_SKIPPED);
+
+ Notification.Builder builder = new Notification.Builder(this)
+ .setContentTitle(getString(R.string.quiz_report))
+ .setSmallIcon(R.drawable.ic_launcher)
+ .setLocalOnly(true);
+ SpannableStringBuilder quizReportText = new SpannableStringBuilder();
+ appendColored(quizReportText, String.valueOf(numCorrect), R.color.dark_green);
+ quizReportText.append(" " + getString(R.string.correct) + "\n");
+ appendColored(quizReportText, String.valueOf(numIncorrect), R.color.dark_red);
+ quizReportText.append(" " + getString(R.string.incorrect) + "\n");
+ appendColored(quizReportText, String.valueOf(numSkipped), R.color.dark_yellow);
+ quizReportText.append(" " + getString(R.string.skipped) + "\n");
+
+ builder.setContentText(quizReportText);
+ if (!path.equals(QUIZ_EXITED_PATH)) {
+ // Don't add reset option if user exited quiz (there might not be a quiz to reset!).
+ builder.addAction(R.drawable.ic_launcher,
+ getString(R.string.reset_quiz), getResetQuizPendingIntent());
+ }
+ ((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
+ .notify(QUIZ_REPORT_NOTIF_ID, builder.build());
+ }
+ }
+
+ private void appendColored(SpannableStringBuilder builder, String text, int colorResId) {
+ builder.append(text).setSpan(new ForegroundColorSpan(getResources().getColor(colorResId)),
+ builder.length() - text.length(), builder.length(), 0);
+ }
+
+ /**
+ * Returns a PendingIntent that will send a message to the phone to reset the quiz when fired.
+ */
+ private PendingIntent getResetQuizPendingIntent() {
+ Intent intent = new Intent(QuizReportActionService.ACTION_RESET_QUIZ)
+ .setClass(this, QuizReportActionService.class);
+ return PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
+ }
+}
diff --git a/samples/wearable/Quiz/Wearable/src/main/java/com/example/android/wearable/quiz/QuizReportActionService.java b/samples/wearable/Quiz/Wearable/src/main/java/com/example/android/wearable/quiz/QuizReportActionService.java
new file mode 100644
index 000000000..4bb5398fc
--- /dev/null
+++ b/samples/wearable/Quiz/Wearable/src/main/java/com/example/android/wearable/quiz/QuizReportActionService.java
@@ -0,0 +1,51 @@
+package com.example.android.wearable.quiz;
+
+import android.app.IntentService;
+import android.content.Intent;
+import android.util.Log;
+
+import com.google.android.gms.common.ConnectionResult;
+import com.google.android.gms.common.api.GoogleApiClient;
+import com.google.android.gms.wearable.Node;
+import com.google.android.gms.wearable.NodeApi;
+import com.google.android.gms.wearable.Wearable;
+
+import java.util.concurrent.TimeUnit;
+
+import static com.example.android.wearable.quiz.Constants.CONNECT_TIMEOUT_MS;
+import static com.example.android.wearable.quiz.Constants.RESET_QUIZ_PATH;
+
+/**
+ * Service to reset the quiz (by sending a message to the phone) when the Reset Quiz
+ * action on the Quiz Report is selected.
+ */
+public class QuizReportActionService extends IntentService {
+ public static final String ACTION_RESET_QUIZ = "com.example.android.wearable.quiz.RESET_QUIZ";
+
+ private static final String TAG = "QuizReportActionReceiver";
+
+ public QuizReportActionService() {
+ super(QuizReportActionService.class.getSimpleName());
+ }
+
+ @Override
+ public void onHandleIntent(Intent intent) {
+ if (intent.getAction().equals(ACTION_RESET_QUIZ)) {
+ GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this)
+ .addApi(Wearable.API)
+ .build();
+ ConnectionResult result = googleApiClient.blockingConnect(CONNECT_TIMEOUT_MS,
+ TimeUnit.MILLISECONDS);
+ if (!result.isSuccess()) {
+ Log.e(TAG, "QuizListenerService failed to connect to GoogleApiClient.");
+ return;
+ }
+ NodeApi.GetConnectedNodesResult nodes =
+ Wearable.NodeApi.getConnectedNodes(googleApiClient).await();
+ for (Node node : nodes.getNodes()) {
+ Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), RESET_QUIZ_PATH,
+ new byte[0]);
+ }
+ }
+ }
+}
diff --git a/samples/wearable/Quiz/Wearable/src/main/java/com/example/android/wearable/quiz/UpdateQuestionService.java b/samples/wearable/Quiz/Wearable/src/main/java/com/example/android/wearable/quiz/UpdateQuestionService.java
new file mode 100644
index 000000000..0668c97e0
--- /dev/null
+++ b/samples/wearable/Quiz/Wearable/src/main/java/com/example/android/wearable/quiz/UpdateQuestionService.java
@@ -0,0 +1,92 @@
+package com.example.android.wearable.quiz;
+
+import android.app.IntentService;
+import android.app.NotificationManager;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Bundle;
+import android.util.Log;
+
+import com.google.android.gms.common.ConnectionResult;
+import com.google.android.gms.common.api.GoogleApiClient;
+import com.google.android.gms.wearable.DataApi;
+import com.google.android.gms.wearable.DataMap;
+import com.google.android.gms.wearable.DataMapItem;
+import com.google.android.gms.wearable.PutDataMapRequest;
+import com.google.android.gms.wearable.PutDataRequest;
+import com.google.android.gms.wearable.Wearable;
+
+import java.util.concurrent.TimeUnit;
+
+import static com.example.android.wearable.quiz.Constants.CHOSEN_ANSWER_CORRECT;
+import static com.example.android.wearable.quiz.Constants.QUESTION_INDEX;
+import static com.example.android.wearable.quiz.Constants.QUESTION_WAS_ANSWERED;
+
+/**
+ * Updates quiz status on the phone when user selects an answer to a question on the watch.
+ */
+public class UpdateQuestionService extends IntentService
+ implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
+ public static final String EXTRA_QUESTION_CORRECT = "extra_question_correct";
+ public static final String EXTRA_QUESTION_INDEX = "extra_question_index";
+
+ private static final long TIME_OUT_MS = 100;
+ private static final String TAG = "UpdateQuestionService";
+
+ private GoogleApiClient mGoogleApiClient;
+
+ public UpdateQuestionService() {
+ super(UpdateQuestionService.class.getSimpleName());
+ }
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ mGoogleApiClient = new GoogleApiClient.Builder(this)
+ .addApi(Wearable.API)
+ .addConnectionCallbacks(this)
+ .addOnConnectionFailedListener(this)
+ .build();
+ }
+
+ @Override
+ protected void onHandleIntent(Intent intent) {
+ mGoogleApiClient.blockingConnect(TIME_OUT_MS, TimeUnit.MILLISECONDS);
+ Uri dataItemUri = intent.getData();
+ if (!mGoogleApiClient.isConnected()) {
+ Log.e(TAG, "Failed to update data item " + dataItemUri
+ + " because client is disconnected from Google Play Services");
+ return;
+ }
+ DataApi.DataItemResult dataItemResult = Wearable.DataApi.getDataItem(
+ mGoogleApiClient, dataItemUri).await();
+ PutDataMapRequest putDataMapRequest = PutDataMapRequest
+ .createFromDataMapItem(DataMapItem.fromDataItem(dataItemResult.getDataItem()));
+ DataMap dataMap = putDataMapRequest.getDataMap();
+
+ // Update quiz status variables, which will be reflected on the phone.
+ int questionIndex = intent.getIntExtra(EXTRA_QUESTION_INDEX, -1);
+ boolean chosenAnswerCorrect = intent.getBooleanExtra(EXTRA_QUESTION_CORRECT, false);
+ dataMap.putInt(QUESTION_INDEX, questionIndex);
+ dataMap.putBoolean(CHOSEN_ANSWER_CORRECT, chosenAnswerCorrect);
+ dataMap.putBoolean(QUESTION_WAS_ANSWERED, true);
+ PutDataRequest request = putDataMapRequest.asPutDataRequest();
+ Wearable.DataApi.putDataItem(mGoogleApiClient, request).await();
+
+ // Remove this question notification.
+ ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).cancel(questionIndex);
+ mGoogleApiClient.disconnect();
+ }
+
+ @Override
+ public void onConnected(Bundle connectionHint) {
+ }
+
+ @Override
+ public void onConnectionSuspended(int cause) {
+ }
+
+ @Override
+ public void onConnectionFailed(ConnectionResult result) {
+ }
+}
diff --git a/samples/wearable/Quiz/Wearable/src/main/res/drawable-hdpi/ic_choice_a.png b/samples/wearable/Quiz/Wearable/src/main/res/drawable-hdpi/ic_choice_a.png
new file mode 100644
index 000000000..de18ce11a
Binary files /dev/null and b/samples/wearable/Quiz/Wearable/src/main/res/drawable-hdpi/ic_choice_a.png differ
diff --git a/samples/wearable/Quiz/Wearable/src/main/res/drawable-hdpi/ic_choice_b.png b/samples/wearable/Quiz/Wearable/src/main/res/drawable-hdpi/ic_choice_b.png
new file mode 100644
index 000000000..3cdfe9750
Binary files /dev/null and b/samples/wearable/Quiz/Wearable/src/main/res/drawable-hdpi/ic_choice_b.png differ
diff --git a/samples/wearable/Quiz/Wearable/src/main/res/drawable-hdpi/ic_choice_c.png b/samples/wearable/Quiz/Wearable/src/main/res/drawable-hdpi/ic_choice_c.png
new file mode 100644
index 000000000..f0ed2ef99
Binary files /dev/null and b/samples/wearable/Quiz/Wearable/src/main/res/drawable-hdpi/ic_choice_c.png differ
diff --git a/samples/wearable/Quiz/Wearable/src/main/res/drawable-hdpi/ic_choice_d.png b/samples/wearable/Quiz/Wearable/src/main/res/drawable-hdpi/ic_choice_d.png
new file mode 100644
index 000000000..c158d2953
Binary files /dev/null and b/samples/wearable/Quiz/Wearable/src/main/res/drawable-hdpi/ic_choice_d.png differ
diff --git a/samples/wearable/Quiz/Wearable/src/main/res/drawable-hdpi/ic_launcher.png b/samples/wearable/Quiz/Wearable/src/main/res/drawable-hdpi/ic_launcher.png
new file mode 100755
index 000000000..91a8cff95
Binary files /dev/null and b/samples/wearable/Quiz/Wearable/src/main/res/drawable-hdpi/ic_launcher.png differ
diff --git a/samples/wearable/Quiz/Wearable/src/main/res/drawable-hdpi/ic_unknown_choice.png b/samples/wearable/Quiz/Wearable/src/main/res/drawable-hdpi/ic_unknown_choice.png
new file mode 100644
index 000000000..9aed51728
Binary files /dev/null and b/samples/wearable/Quiz/Wearable/src/main/res/drawable-hdpi/ic_unknown_choice.png differ
diff --git a/samples/wearable/Quiz/Wearable/src/main/res/drawable-mdpi/ic_choice_a.png b/samples/wearable/Quiz/Wearable/src/main/res/drawable-mdpi/ic_choice_a.png
new file mode 100644
index 000000000..57459365c
Binary files /dev/null and b/samples/wearable/Quiz/Wearable/src/main/res/drawable-mdpi/ic_choice_a.png differ
diff --git a/samples/wearable/Quiz/Wearable/src/main/res/drawable-mdpi/ic_choice_b.png b/samples/wearable/Quiz/Wearable/src/main/res/drawable-mdpi/ic_choice_b.png
new file mode 100644
index 000000000..958b92e31
Binary files /dev/null and b/samples/wearable/Quiz/Wearable/src/main/res/drawable-mdpi/ic_choice_b.png differ
diff --git a/samples/wearable/Quiz/Wearable/src/main/res/drawable-mdpi/ic_choice_c.png b/samples/wearable/Quiz/Wearable/src/main/res/drawable-mdpi/ic_choice_c.png
new file mode 100644
index 000000000..9fcfab754
Binary files /dev/null and b/samples/wearable/Quiz/Wearable/src/main/res/drawable-mdpi/ic_choice_c.png differ
diff --git a/samples/wearable/Quiz/Wearable/src/main/res/drawable-mdpi/ic_choice_d.png b/samples/wearable/Quiz/Wearable/src/main/res/drawable-mdpi/ic_choice_d.png
new file mode 100644
index 000000000..821cadb78
Binary files /dev/null and b/samples/wearable/Quiz/Wearable/src/main/res/drawable-mdpi/ic_choice_d.png differ
diff --git a/samples/wearable/Quiz/Wearable/src/main/res/drawable-mdpi/ic_launcher.png b/samples/wearable/Quiz/Wearable/src/main/res/drawable-mdpi/ic_launcher.png
new file mode 100755
index 000000000..728ee6d73
Binary files /dev/null and b/samples/wearable/Quiz/Wearable/src/main/res/drawable-mdpi/ic_launcher.png differ
diff --git a/samples/wearable/Quiz/Wearable/src/main/res/drawable-mdpi/ic_unknown_choice.png b/samples/wearable/Quiz/Wearable/src/main/res/drawable-mdpi/ic_unknown_choice.png
new file mode 100644
index 000000000..b8030ef08
Binary files /dev/null and b/samples/wearable/Quiz/Wearable/src/main/res/drawable-mdpi/ic_unknown_choice.png differ
diff --git a/samples/wearable/Quiz/Wearable/src/main/res/drawable-xhdpi/ic_choice_a.png b/samples/wearable/Quiz/Wearable/src/main/res/drawable-xhdpi/ic_choice_a.png
new file mode 100644
index 000000000..3dba96f32
Binary files /dev/null and b/samples/wearable/Quiz/Wearable/src/main/res/drawable-xhdpi/ic_choice_a.png differ
diff --git a/samples/wearable/Quiz/Wearable/src/main/res/drawable-xhdpi/ic_choice_b.png b/samples/wearable/Quiz/Wearable/src/main/res/drawable-xhdpi/ic_choice_b.png
new file mode 100644
index 000000000..9ca3c85f2
Binary files /dev/null and b/samples/wearable/Quiz/Wearable/src/main/res/drawable-xhdpi/ic_choice_b.png differ
diff --git a/samples/wearable/Quiz/Wearable/src/main/res/drawable-xhdpi/ic_choice_c.png b/samples/wearable/Quiz/Wearable/src/main/res/drawable-xhdpi/ic_choice_c.png
new file mode 100644
index 000000000..b84b3b76d
Binary files /dev/null and b/samples/wearable/Quiz/Wearable/src/main/res/drawable-xhdpi/ic_choice_c.png differ
diff --git a/samples/wearable/Quiz/Wearable/src/main/res/drawable-xhdpi/ic_choice_d.png b/samples/wearable/Quiz/Wearable/src/main/res/drawable-xhdpi/ic_choice_d.png
new file mode 100644
index 000000000..185e91ec8
Binary files /dev/null and b/samples/wearable/Quiz/Wearable/src/main/res/drawable-xhdpi/ic_choice_d.png differ
diff --git a/samples/wearable/Quiz/Wearable/src/main/res/drawable-xhdpi/ic_launcher.png b/samples/wearable/Quiz/Wearable/src/main/res/drawable-xhdpi/ic_launcher.png
new file mode 100755
index 000000000..64a585453
Binary files /dev/null and b/samples/wearable/Quiz/Wearable/src/main/res/drawable-xhdpi/ic_launcher.png differ
diff --git a/samples/wearable/Quiz/Wearable/src/main/res/drawable-xhdpi/ic_unknown_choice.png b/samples/wearable/Quiz/Wearable/src/main/res/drawable-xhdpi/ic_unknown_choice.png
new file mode 100644
index 000000000..57838d152
Binary files /dev/null and b/samples/wearable/Quiz/Wearable/src/main/res/drawable-xhdpi/ic_unknown_choice.png differ
diff --git a/samples/wearable/Quiz/Wearable/src/main/res/drawable-xxhdpi/ic_launcher.png b/samples/wearable/Quiz/Wearable/src/main/res/drawable-xxhdpi/ic_launcher.png
new file mode 100755
index 000000000..86a395bb6
Binary files /dev/null and b/samples/wearable/Quiz/Wearable/src/main/res/drawable-xxhdpi/ic_launcher.png differ
diff --git a/samples/wearable/Quiz/Wearable/src/main/res/values/colors.xml b/samples/wearable/Quiz/Wearable/src/main/res/values/colors.xml
new file mode 100644
index 000000000..e19c9e7d7
--- /dev/null
+++ b/samples/wearable/Quiz/Wearable/src/main/res/values/colors.xml
@@ -0,0 +1,6 @@
+
+
+ #009900
+ #800000
+ #FF9900
+
\ No newline at end of file
diff --git a/samples/wearable/Quiz/Wearable/src/main/res/values/strings.xml b/samples/wearable/Quiz/Wearable/src/main/res/values/strings.xml
new file mode 100644
index 000000000..2136073cc
--- /dev/null
+++ b/samples/wearable/Quiz/Wearable/src/main/res/values/strings.xml
@@ -0,0 +1,14 @@
+
+
+
+ Quiz Sample Wearable App
+
+ Question %d
+
+ Quiz Report
+ correct
+ incorrect
+ skipped
+ Reset Quiz
+
+
diff --git a/samples/wearable/Quiz/build.gradle b/samples/wearable/Quiz/build.gradle
new file mode 100644
index 000000000..4c8f6d8b9
--- /dev/null
+++ b/samples/wearable/Quiz/build.gradle
@@ -0,0 +1,16 @@
+// Top-level build file where you can add configuration options common to all sub-projects/modules.
+
+buildscript {
+ repositories {
+ mavenCentral()
+ }
+ dependencies {
+ classpath 'com.android.tools.build:gradle:0.11.+'
+ }
+}
+
+allprojects {
+ repositories {
+ mavenCentral()
+ }
+}
diff --git a/samples/wearable/Quiz/gradle.properties b/samples/wearable/Quiz/gradle.properties
new file mode 100644
index 000000000..5d08ba75b
--- /dev/null
+++ b/samples/wearable/Quiz/gradle.properties
@@ -0,0 +1,18 @@
+# Project-wide Gradle settings.
+
+# IDE (e.g. Android Studio) users:
+# Settings specified in this file will override any Gradle settings
+# configured through the IDE.
+
+# For more details on how to configure your build environment visit
+# http://www.gradle.org/docs/current/userguide/build_environment.html
+
+# Specifies the JVM arguments used for the daemon process.
+# The setting is particularly useful for tweaking memory settings.
+# Default value: -Xmx10248m -XX:MaxPermSize=256m
+# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
+
+# When configured, Gradle will run in incubating parallel mode.
+# This option should only be used with decoupled projects. More details, visit
+# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
+# org.gradle.parallel=true
\ No newline at end of file
diff --git a/samples/wearable/Quiz/gradle/wrapper/gradle-wrapper.jar b/samples/wearable/Quiz/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 000000000..583859812
Binary files /dev/null and b/samples/wearable/Quiz/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/samples/wearable/Quiz/gradle/wrapper/gradle-wrapper.properties b/samples/wearable/Quiz/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 000000000..e83e46081
--- /dev/null
+++ b/samples/wearable/Quiz/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Fri Mar 14 14:02:22 PDT 2014
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-all.zip
diff --git a/samples/wearable/Quiz/gradlew b/samples/wearable/Quiz/gradlew
new file mode 100755
index 000000000..91a7e269e
--- /dev/null
+++ b/samples/wearable/Quiz/gradlew
@@ -0,0 +1,164 @@
+#!/usr/bin/env bash
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+ echo "$*"
+}
+
+die ( ) {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+esac
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched.
+if $cygwin ; then
+ [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+fi
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >&-
+APP_HOME="`pwd -P`"
+cd "$SAVED" >&-
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+ JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
diff --git a/samples/wearable/Quiz/gradlew.bat b/samples/wearable/Quiz/gradlew.bat
new file mode 100755
index 000000000..aec99730b
--- /dev/null
+++ b/samples/wearable/Quiz/gradlew.bat
@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windowz variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%@eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/samples/wearable/Quiz/settings.gradle b/samples/wearable/Quiz/settings.gradle
new file mode 100644
index 000000000..d6b72d158
--- /dev/null
+++ b/samples/wearable/Quiz/settings.gradle
@@ -0,0 +1 @@
+include 'Application', 'Wearable'
diff --git a/samples/wearable/RecipeAssistant/Application/build.gradle b/samples/wearable/RecipeAssistant/Application/build.gradle
new file mode 100644
index 000000000..03f9be847
--- /dev/null
+++ b/samples/wearable/RecipeAssistant/Application/build.gradle
@@ -0,0 +1,24 @@
+apply plugin: 'android'
+
+android {
+ compileSdkVersion 19
+ buildToolsVersion '20'
+
+ defaultConfig {
+ minSdkVersion 18
+ targetSdkVersion 19
+ versionCode 1
+ versionName "1.0"
+ }
+
+ buildTypes {
+ release {
+ runProguard false
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
+ }
+ }
+}
+
+dependencies {
+ compile "com.android.support:support-v4:20.0.+"
+}
diff --git a/samples/wearable/RecipeAssistant/Application/proguard-rules.txt b/samples/wearable/RecipeAssistant/Application/proguard-rules.txt
new file mode 100644
index 000000000..08e5bdc8d
--- /dev/null
+++ b/samples/wearable/RecipeAssistant/Application/proguard-rules.txt
@@ -0,0 +1,22 @@
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
+-dontwarn android.support.wearable.view.DelayedConfirmationView
+-dontwarn android.support.wearable.view.CircledImageView
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/AndroidManifest.xml b/samples/wearable/RecipeAssistant/Application/src/main/AndroidManifest.xml
new file mode 100644
index 000000000..7a1a04a3f
--- /dev/null
+++ b/samples/wearable/RecipeAssistant/Application/src/main/AndroidManifest.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/assets/beef-brisket-chili.json b/samples/wearable/RecipeAssistant/Application/src/main/assets/beef-brisket-chili.json
new file mode 100644
index 000000000..19598f9e5
--- /dev/null
+++ b/samples/wearable/RecipeAssistant/Application/src/main/assets/beef-brisket-chili.json
@@ -0,0 +1,91 @@
+{
+name: "beef-brisket-chili.json",
+steps: [
+{
+text: "Place the cinnamon stick, cumin, paprika and oregano in a pestle and mortar. Bash and grind until the cinnamon is in very small flakes. ",
+img: "step-1-grind-spices.jpg"
+},
+{
+text: "Score the beef and rub the spice mix into the cuts. ",
+img: "step-2-score-beef.jpg"
+},
+{
+text: "Season the beef and drizzle with olive oil. Brown in a hot pan. ",
+img: "step-3-brown-beef.jpg"
+},
+{
+text: "Finely slice the onion and fry in a little olive oil together with the chillies, finely sliced. You can control the heat of your chili by deseeding some of the chillies. ",
+img: "step-4-fry-onion.jpg"
+},
+{
+text: "Add the browned brisket to the pan with the onions and chillies and fry on a low heat."
+},
+{
+text: "Place the bell peppers, roughly sliced, the bay leaves and chopped tomatoes in a large covered pot. Bring to the boil and then add the beef, onions and chillies. ",
+img: "step-6-combine.jpg"
+},
+{
+text: "Bring back to the boil, cover and allow to simmer on a low heat for 4 hours."
+},
+{
+text: "Remove the brisket from the pot, place on a large plate and use two forks to pull the beef apart into individual pieces. ",
+img: "step-8-pull.jpg"
+},
+{
+text: "Remove the bay leaves and add the pulled beef and coriander back to the pot, together with the kidney beans."
+},
+{
+text: "Bring back to the boil and simmer gently for a further 15 - 20 mins."
+}
+],
+summary: "",
+title: "Beef brisket chili",
+img: "chili.jpg",
+serving: [
+"Serve with rice, yoghurt and fresh guacamole. Garnish with the remaining coriander."
+],
+ingredients: [
+{
+text: "3 lbs beef brisket"
+},
+{
+text: "2 red onions"
+},
+{
+text: "4 jalapeno chillies"
+},
+{
+text: "1 large cinnamon stick"
+},
+{
+text: "1 tbsp ground cumin"
+},
+{
+text: "1 tbsp paprika"
+},
+{
+text: "1 heaped tbsp dried oregano"
+},
+{
+text: "2 fresh bay leaves"
+},
+{
+text: "2 red bell peppers"
+},
+{
+text: "2 green bell peppers"
+},
+{
+text: "800g tin chopped tomatoes"
+},
+{
+text: "400g tin kidney beans"
+},
+{
+text: "400ml beef stock"
+},
+{
+text: "1/2 bunch coriander"
+}
+]
+}
\ No newline at end of file
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/assets/chili.jpg b/samples/wearable/RecipeAssistant/Application/src/main/assets/chili.jpg
new file mode 100644
index 000000000..ca5f7510f
Binary files /dev/null and b/samples/wearable/RecipeAssistant/Application/src/main/assets/chili.jpg differ
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/assets/guacamole.jpg b/samples/wearable/RecipeAssistant/Application/src/main/assets/guacamole.jpg
new file mode 100644
index 000000000..77175eb88
Binary files /dev/null and b/samples/wearable/RecipeAssistant/Application/src/main/assets/guacamole.jpg differ
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/assets/guacamole.json b/samples/wearable/RecipeAssistant/Application/src/main/assets/guacamole.json
new file mode 100644
index 000000000..5fae53fe1
--- /dev/null
+++ b/samples/wearable/RecipeAssistant/Application/src/main/assets/guacamole.json
@@ -0,0 +1,36 @@
+{
+name: "guacamole.json",
+steps: [
+{
+text: "Use a spoon to scoop the flesh of the avocados into a bowl."
+},
+{
+text: "Mash with a fork until fairly smooth and creamy. Preserve some small solid chunks to add texture."
+},
+{
+text: "Add the juice of the lime. ",
+img: "step-3-lime.jpg"
+},
+{
+text: "Add the cilantro."
+},
+{
+text: "Mix thoroughly."
+}
+],
+summary: "Some guacamole recipes call for many ingredients and can be a pain to prepare. This super simple guac can be thrown together in a couple of minutes and tastes great.",
+title: "Super simple guacamole",
+img: "guacamole.jpg",
+serving: "",
+ingredients: [
+{
+text: "2 ripe avocados"
+},
+{
+text: "1 lime"
+},
+{
+text: "2 tbsp cilantro"
+}
+]
+}
\ No newline at end of file
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/assets/irish-stew.jpg b/samples/wearable/RecipeAssistant/Application/src/main/assets/irish-stew.jpg
new file mode 100644
index 000000000..0c20766fd
Binary files /dev/null and b/samples/wearable/RecipeAssistant/Application/src/main/assets/irish-stew.jpg differ
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/assets/northern-irish-vegetable-soup.json b/samples/wearable/RecipeAssistant/Application/src/main/assets/northern-irish-vegetable-soup.json
new file mode 100644
index 000000000..55d259190
--- /dev/null
+++ b/samples/wearable/RecipeAssistant/Application/src/main/assets/northern-irish-vegetable-soup.json
@@ -0,0 +1,46 @@
+{
+name: "northern-irish-vegetable-soup.json",
+steps: [
+{
+text: "Place the beef in a large stock pot, cover with water and stew for 1 - 2 hours."
+},
+{
+text: "Allow the stock to cool, skim off any fat."
+},
+{
+text: "Add the soup mix to the stock, bring to the boil and simmer for 1 hour."
+},
+{
+text: "Roughly chop the leeks (green and white parts), onion, carrots, celery and parsley. Add to the soup. Season well and simmer until the vegetables are soft."
+}
+],
+summary: "This recipe is apparently unique to Northern Ireland and uses soup/herb celery which is hard to find outside the area, but regular table celery can be substituted (including the leaves).",
+title: "Northern irish vegetable soup",
+img: "irish-stew.jpg",
+serving: [
+"Whole boiled potatoes are traditionally placed in the soup at time of serving."
+],
+ingredients: [
+{
+text: "2 lbs beef shin or similar beef on bone"
+},
+{
+text: "60g soup mix (30g barley, 15g red lentils, 15g split peas)"
+},
+{
+text: "3 carrots"
+},
+{
+text: "1 white onion"
+},
+{
+text: "field celery or 1 stalk celery, plus any leaves on the bunch"
+},
+{
+text: "2 leeks"
+},
+{
+text: "1 bunch parsley"
+}
+]
+}
\ No newline at end of file
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/assets/recipelist.json b/samples/wearable/RecipeAssistant/Application/src/main/assets/recipelist.json
new file mode 100644
index 000000000..efd787d35
--- /dev/null
+++ b/samples/wearable/RecipeAssistant/Application/src/main/assets/recipelist.json
@@ -0,0 +1,23 @@
+{
+recipe_list:
+[
+{
+name: "guacamole.json",
+summary: "Some guacamole recipes call for many ingredients and can be a pain to prepare. This super simple guac can be thrown together in a couple of minutes and tastes great.",
+title: "Super simple guacamole",
+img: "guacamole.jpg"
+},
+{
+name: "northern-irish-vegetable-soup.json",
+summary: "This recipe is apparently unique to Northern Ireland and uses soup/herb celery which is hard to find outside the area, but regular table celery can be substituted (including the leaves).",
+title: "Northern irish vegetable soup",
+img: "irish-stew.jpg"
+},
+{
+name: "beef-brisket-chili.json",
+summary: "",
+title: "Beef brisket chili",
+img: "chili.jpg"
+}
+]
+}
\ No newline at end of file
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/assets/step-1-grind-spices.jpg b/samples/wearable/RecipeAssistant/Application/src/main/assets/step-1-grind-spices.jpg
new file mode 100644
index 000000000..9b5f2b978
Binary files /dev/null and b/samples/wearable/RecipeAssistant/Application/src/main/assets/step-1-grind-spices.jpg differ
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/assets/step-2-score-beef.jpg b/samples/wearable/RecipeAssistant/Application/src/main/assets/step-2-score-beef.jpg
new file mode 100644
index 000000000..66c549dfa
Binary files /dev/null and b/samples/wearable/RecipeAssistant/Application/src/main/assets/step-2-score-beef.jpg differ
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/assets/step-3-brown-beef.jpg b/samples/wearable/RecipeAssistant/Application/src/main/assets/step-3-brown-beef.jpg
new file mode 100644
index 000000000..1bb801e6e
Binary files /dev/null and b/samples/wearable/RecipeAssistant/Application/src/main/assets/step-3-brown-beef.jpg differ
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/assets/step-3-lime.jpg b/samples/wearable/RecipeAssistant/Application/src/main/assets/step-3-lime.jpg
new file mode 100644
index 000000000..b615d5587
Binary files /dev/null and b/samples/wearable/RecipeAssistant/Application/src/main/assets/step-3-lime.jpg differ
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/assets/step-4-fry-onion.jpg b/samples/wearable/RecipeAssistant/Application/src/main/assets/step-4-fry-onion.jpg
new file mode 100644
index 000000000..b5d2a1875
Binary files /dev/null and b/samples/wearable/RecipeAssistant/Application/src/main/assets/step-4-fry-onion.jpg differ
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/assets/step-6-combine.jpg b/samples/wearable/RecipeAssistant/Application/src/main/assets/step-6-combine.jpg
new file mode 100644
index 000000000..fe2940578
Binary files /dev/null and b/samples/wearable/RecipeAssistant/Application/src/main/assets/step-6-combine.jpg differ
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/assets/step-8-pull.jpg b/samples/wearable/RecipeAssistant/Application/src/main/assets/step-8-pull.jpg
new file mode 100644
index 000000000..f8288a849
Binary files /dev/null and b/samples/wearable/RecipeAssistant/Application/src/main/assets/step-8-pull.jpg differ
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/java/com/example/android/wearable/recipeassistant/AssetUtils.java b/samples/wearable/RecipeAssistant/Application/src/main/java/com/example/android/wearable/recipeassistant/AssetUtils.java
new file mode 100644
index 000000000..c7991bbb0
--- /dev/null
+++ b/samples/wearable/RecipeAssistant/Application/src/main/java/com/example/android/wearable/recipeassistant/AssetUtils.java
@@ -0,0 +1,64 @@
+package com.example.android.wearable.recipeassistant;
+
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.util.Log;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+final class AssetUtils {
+ private static final String TAG = "RecipeAssistant";
+
+ public static byte[] loadAsset(Context context, String asset) {
+ byte[] buffer = null;
+ try {
+ InputStream is = context.getAssets().open(asset);
+ int size = is.available();
+ buffer = new byte[size];
+ is.read(buffer);
+ is.close();
+ } catch (IOException e) {
+ Log.e(TAG, "Failed to load asset " + asset + ": " + e);
+ }
+ return buffer;
+ }
+
+ public static JSONObject loadJSONAsset(Context context, String asset) {
+ String jsonString = new String(loadAsset(context, asset));
+ JSONObject jsonObject = null;
+ try {
+ jsonObject = new JSONObject(jsonString);
+ } catch (JSONException e) {
+ Log.e(TAG, "Failed to parse JSON asset " + asset + ": " + e);
+ }
+ return jsonObject;
+ }
+
+ public static Bitmap loadBitmapAsset(Context context, String asset) {
+ InputStream is = null;
+ Bitmap bitmap = null;
+ try {
+ is = context.getAssets().open(asset);
+ if (is != null) {
+ bitmap = BitmapFactory.decodeStream(is);
+ }
+ } catch (IOException e) {
+ Log.e(TAG, e.toString());
+ } finally {
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ Log.e(TAG, "Cannot close InputStream: ", e);
+ }
+ }
+ }
+ return bitmap;
+ }
+}
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/java/com/example/android/wearable/recipeassistant/Constants.java b/samples/wearable/RecipeAssistant/Application/src/main/java/com/example/android/wearable/recipeassistant/Constants.java
new file mode 100644
index 000000000..375444efb
--- /dev/null
+++ b/samples/wearable/RecipeAssistant/Application/src/main/java/com/example/android/wearable/recipeassistant/Constants.java
@@ -0,0 +1,27 @@
+package com.example.android.wearable.recipeassistant;
+
+public final class Constants {
+ private Constants() {
+ }
+ public static final String RECIPE_LIST_FILE = "recipelist.json";
+ public static final String RECIPE_NAME_TO_LOAD = "recipe_name";
+
+ public static final String RECIPE_FIELD_LIST = "recipe_list";
+ public static final String RECIPE_FIELD_IMAGE = "img";
+ public static final String RECIPE_FIELD_INGREDIENTS = "ingredients";
+ public static final String RECIPE_FIELD_NAME = "name";
+ public static final String RECIPE_FIELD_SUMMARY = "summary";
+ public static final String RECIPE_FIELD_STEPS = "steps";
+ public static final String RECIPE_FIELD_TEXT = "text";
+ public static final String RECIPE_FIELD_TITLE = "title";
+ public static final String RECIPE_FIELD_STEP_TEXT = "step_text";
+ public static final String RECIPE_FIELD_STEP_IMAGE = "step_image";
+
+ static final String ACTION_START_COOKING =
+ "com.example.android.wearable.recipeassistant.START_COOKING";
+ public static final String EXTRA_RECIPE = "recipe";
+
+ public static final int NOTIFICATION_ID = 0;
+ public static final int NOTIFICATION_IMAGE_WIDTH = 280;
+ public static final int NOTIFICATION_IMAGE_HEIGHT = 280;
+}
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/java/com/example/android/wearable/recipeassistant/MainActivity.java b/samples/wearable/RecipeAssistant/Application/src/main/java/com/example/android/wearable/recipeassistant/MainActivity.java
new file mode 100644
index 000000000..a456190f2
--- /dev/null
+++ b/samples/wearable/RecipeAssistant/Application/src/main/java/com/example/android/wearable/recipeassistant/MainActivity.java
@@ -0,0 +1,35 @@
+
+package com.example.android.wearable.recipeassistant;
+
+import android.app.ListActivity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.widget.ListView;
+
+public class MainActivity extends ListActivity {
+
+ private static final String TAG = "RecipeAssistant";
+ private RecipeListAdapter mAdapter;
+
+ @Override
+ protected void onListItemClick(ListView l, View v, int position, long id) {
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG , "onListItemClick " + position);
+ }
+ String itemName = mAdapter.getItemName(position);
+ Intent intent = new Intent(getApplicationContext(), RecipeActivity.class);
+ intent.putExtra(Constants.RECIPE_NAME_TO_LOAD, itemName);
+ startActivity(intent);
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(android.R.layout.list_content);
+
+ mAdapter = new RecipeListAdapter(this);
+ setListAdapter(mAdapter);
+ }
+}
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/java/com/example/android/wearable/recipeassistant/Recipe.java b/samples/wearable/RecipeAssistant/Application/src/main/java/com/example/android/wearable/recipeassistant/Recipe.java
new file mode 100644
index 000000000..24356b61e
--- /dev/null
+++ b/samples/wearable/RecipeAssistant/Application/src/main/java/com/example/android/wearable/recipeassistant/Recipe.java
@@ -0,0 +1,110 @@
+package com.example.android.wearable.recipeassistant;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.os.Parcelable;
+import android.util.Log;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.util.ArrayList;
+
+public class Recipe {
+ private static final String TAG = "RecipeAssistant";
+
+ public String titleText;
+ public String summaryText;
+ public String recipeImage;
+ public String ingredientsText;
+
+ public static class RecipeStep {
+ RecipeStep() { }
+ public String stepImage;
+ public String stepText;
+
+ public Bundle toBundle() {
+ Bundle bundle = new Bundle();
+ bundle.putString(Constants.RECIPE_FIELD_STEP_TEXT, stepText);
+ bundle.putString(Constants.RECIPE_FIELD_STEP_IMAGE, stepImage);
+ return bundle;
+ }
+
+ public static RecipeStep fromBundle(Bundle bundle) {
+ RecipeStep recipeStep = new RecipeStep();
+ recipeStep.stepText = bundle.getString(Constants.RECIPE_FIELD_STEP_TEXT);
+ recipeStep.stepImage = bundle.getString(Constants.RECIPE_FIELD_STEP_IMAGE);
+ return recipeStep;
+ }
+ }
+ ArrayList recipeSteps;
+
+ public Recipe() {
+ recipeSteps = new ArrayList();
+ }
+
+ public static Recipe fromJson(Context context, JSONObject json) {
+ Recipe recipe = new Recipe();
+ try {
+ recipe.titleText = json.getString(Constants.RECIPE_FIELD_TITLE);
+ recipe.summaryText = json.getString(Constants.RECIPE_FIELD_SUMMARY);
+ if (json.has(Constants.RECIPE_FIELD_IMAGE)) {
+ recipe.recipeImage = json.getString(Constants.RECIPE_FIELD_IMAGE);
+ }
+ JSONArray ingredients = json.getJSONArray(Constants.RECIPE_FIELD_INGREDIENTS);
+ recipe.ingredientsText = "";
+ for (int i = 0; i < ingredients.length(); i++) {
+ recipe.ingredientsText += " - "
+ + ingredients.getJSONObject(i).getString(Constants.RECIPE_FIELD_TEXT) + "\n";
+ }
+
+ JSONArray steps = json.getJSONArray(Constants.RECIPE_FIELD_STEPS);
+ for (int i = 0; i < steps.length(); i++) {
+ JSONObject step = steps.getJSONObject(i);
+ RecipeStep recipeStep = new RecipeStep();
+ recipeStep.stepText = step.getString(Constants.RECIPE_FIELD_TEXT);
+ if (step.has(Constants.RECIPE_FIELD_IMAGE)) {
+ recipeStep.stepImage = step.getString(Constants.RECIPE_FIELD_IMAGE);
+ }
+ recipe.recipeSteps.add(recipeStep);
+ }
+ } catch (JSONException e) {
+ Log.e(TAG, "Error loading recipe: " + e);
+ return null;
+ }
+ return recipe;
+ }
+
+ public Bundle toBundle() {
+ Bundle bundle = new Bundle();
+ bundle.putString(Constants.RECIPE_FIELD_TITLE, titleText);
+ bundle.putString(Constants.RECIPE_FIELD_SUMMARY, summaryText);
+ bundle.putString(Constants.RECIPE_FIELD_IMAGE, recipeImage);
+ bundle.putString(Constants.RECIPE_FIELD_INGREDIENTS, ingredientsText);
+ if (recipeSteps != null) {
+ ArrayList stepBundles = new ArrayList(recipeSteps.size());
+ for (RecipeStep recipeStep : recipeSteps) {
+ stepBundles.add(recipeStep.toBundle());
+ }
+ bundle.putParcelableArrayList(Constants.RECIPE_FIELD_STEPS, stepBundles);
+ }
+ return bundle;
+ }
+
+ public static Recipe fromBundle(Bundle bundle) {
+ Recipe recipe = new Recipe();
+ recipe.titleText = bundle.getString(Constants.RECIPE_FIELD_TITLE);
+ recipe.summaryText = bundle.getString(Constants.RECIPE_FIELD_SUMMARY);
+ recipe.recipeImage = bundle.getString(Constants.RECIPE_FIELD_IMAGE);
+ recipe.ingredientsText = bundle.getString(Constants.RECIPE_FIELD_INGREDIENTS);
+ ArrayList stepBundles =
+ bundle.getParcelableArrayList(Constants.RECIPE_FIELD_STEPS);
+ if (stepBundles != null) {
+ for (Parcelable stepBundle : stepBundles) {
+ recipe.recipeSteps.add(RecipeStep.fromBundle((Bundle) stepBundle));
+ }
+ }
+ return recipe;
+ }
+}
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/java/com/example/android/wearable/recipeassistant/RecipeActivity.java b/samples/wearable/RecipeAssistant/Application/src/main/java/com/example/android/wearable/recipeassistant/RecipeActivity.java
new file mode 100644
index 000000000..1637745ab
--- /dev/null
+++ b/samples/wearable/RecipeAssistant/Application/src/main/java/com/example/android/wearable/recipeassistant/RecipeActivity.java
@@ -0,0 +1,122 @@
+package com.example.android.wearable.recipeassistant;
+
+import android.app.Activity;
+import android.app.PendingIntent;
+import android.content.Intent;
+import android.graphics.Bitmap;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.animation.Animation;
+import android.view.animation.AnimationUtils;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import org.json.JSONObject;
+
+public class RecipeActivity extends Activity {
+ private static final String TAG = "RecipeAssistant";
+ private String mRecipeName;
+ private Recipe mRecipe;
+ private ImageView mImageView;
+ private TextView mTitleTextView;
+ private TextView mSummaryTextView;
+ private TextView mIngredientsTextView;
+ private LinearLayout mStepsLayout;
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ Intent intent = getIntent();
+ mRecipeName = intent.getStringExtra(Constants.RECIPE_NAME_TO_LOAD);
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "Intent: " + intent.toString() + " " + mRecipeName);
+ }
+ loadRecipe();
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.recipe);
+ mTitleTextView = (TextView) findViewById(R.id.recipeTextTitle);
+ mSummaryTextView = (TextView) findViewById(R.id.recipeTextSummary);
+ mImageView = (ImageView) findViewById(R.id.recipeImageView);
+ mIngredientsTextView = (TextView) findViewById(R.id.textIngredients);
+ mStepsLayout = (LinearLayout) findViewById(R.id.layoutSteps);
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ // Inflate the menu; this adds items to the action bar if it is present.
+ getMenuInflater().inflate(R.menu.main, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch(item.getItemId()) {
+ case R.id.action_cook:
+ startCooking();
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+
+ private void loadRecipe() {
+ JSONObject jsonObject = AssetUtils.loadJSONAsset(this, mRecipeName);
+ if (jsonObject != null) {
+ mRecipe = Recipe.fromJson(this, jsonObject);
+ if (mRecipe != null) {
+ displayRecipe(mRecipe);
+ }
+ }
+ }
+
+ private void displayRecipe(Recipe recipe) {
+ Animation fadeIn = AnimationUtils.loadAnimation(this, android.R.anim.fade_in);
+ mTitleTextView.setAnimation(fadeIn);
+ mTitleTextView.setText(recipe.titleText);
+ mSummaryTextView.setText(recipe.summaryText);
+ if (recipe.recipeImage != null) {
+ mImageView.setAnimation(fadeIn);
+ Bitmap recipeImage = AssetUtils.loadBitmapAsset(this, recipe.recipeImage);
+ mImageView.setImageBitmap(recipeImage);
+ }
+ mIngredientsTextView.setText(recipe.ingredientsText);
+
+ findViewById(R.id.ingredientsHeader).setAnimation(fadeIn);
+ findViewById(R.id.ingredientsHeader).setVisibility(View.VISIBLE);
+ findViewById(R.id.stepsHeader).setAnimation(fadeIn);
+
+ findViewById(R.id.stepsHeader).setVisibility(View.VISIBLE);
+
+ LayoutInflater inf = LayoutInflater.from(this);
+ mStepsLayout.removeAllViews();
+ int stepNumber = 1;
+ for (Recipe.RecipeStep step : recipe.recipeSteps) {
+ View view = inf.inflate(R.layout.step_item, null);
+ ImageView iv = (ImageView) view.findViewById(R.id.stepImageView);
+ if (step.stepImage == null) {
+ iv.setVisibility(View.GONE);
+ } else {
+ Bitmap stepImage = AssetUtils.loadBitmapAsset(this, step.stepImage);
+ iv.setImageBitmap(stepImage);
+ }
+ ((TextView) view.findViewById(R.id.textStep)).setText(
+ (stepNumber++) + ". " + step.stepText);
+ mStepsLayout.addView(view);
+ }
+ }
+
+ private void startCooking() {
+ Intent intent = new Intent(this, RecipeService.class);
+ intent.setAction(Constants.ACTION_START_COOKING);
+ intent.putExtra(Constants.EXTRA_RECIPE, mRecipe.toBundle());
+ startService(intent);
+ }
+}
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/java/com/example/android/wearable/recipeassistant/RecipeListAdapter.java b/samples/wearable/RecipeAssistant/Application/src/main/java/com/example/android/wearable/recipeassistant/RecipeListAdapter.java
new file mode 100644
index 000000000..9602bc6ed
--- /dev/null
+++ b/samples/wearable/RecipeAssistant/Application/src/main/java/com/example/android/wearable/recipeassistant/RecipeListAdapter.java
@@ -0,0 +1,157 @@
+package com.example.android.wearable.recipeassistant;
+
+import android.content.Context;
+import android.database.DataSetObserver;
+import android.graphics.Bitmap;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+import android.widget.ListAdapter;
+import android.widget.TextView;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class RecipeListAdapter implements ListAdapter {
+ private String TAG = "RecipeListAdapter";
+
+ private class Item {
+ String title;
+ String name;
+ String summary;
+ Bitmap image;
+ }
+
+ private List mItems = new ArrayList();
+ private Context mContext;
+ private DataSetObserver mObserver;
+
+ public RecipeListAdapter(Context context) {
+ mContext = context;
+ loadRecipeList();
+ }
+
+ private void loadRecipeList() {
+ JSONObject jsonObject = AssetUtils.loadJSONAsset(mContext, Constants.RECIPE_LIST_FILE);
+ if (jsonObject != null) {
+ List items = parseJson(jsonObject);
+ appendItemsToList(items);
+ }
+ }
+
+ private List parseJson(JSONObject json) {
+ List result = new ArrayList();
+ try {
+ JSONArray items = json.getJSONArray(Constants.RECIPE_FIELD_LIST);
+ for (int i = 0; i < items.length(); i++) {
+ JSONObject item = items.getJSONObject(i);
+ Item parsed = new Item();
+ parsed.name = item.getString(Constants.RECIPE_FIELD_NAME);
+ parsed.title = item.getString(Constants.RECIPE_FIELD_TITLE);
+ if (item.has(Constants.RECIPE_FIELD_IMAGE)) {
+ String imageFile = item.getString(Constants.RECIPE_FIELD_IMAGE);
+ parsed.image = AssetUtils.loadBitmapAsset(mContext, imageFile);
+ }
+ parsed.summary = item.getString(Constants.RECIPE_FIELD_SUMMARY);
+ result.add(parsed);
+ }
+ } catch (JSONException e) {
+ Log.e(TAG, "Failed to parse recipe list: " + e);
+ }
+ return result;
+ }
+
+ private void appendItemsToList(List items) {
+ mItems.addAll(items);
+ if (mObserver != null) {
+ mObserver.onChanged();
+ }
+ }
+
+ @Override
+ public int getCount() {
+ return mItems.size();
+ }
+
+ @Override
+ public Object getItem(int position) {
+ return mItems.get(position);
+ }
+
+ @Override
+ public long getItemId(int position) {
+ return 0;
+ }
+
+ @Override
+ public int getItemViewType(int position) {
+ return 0;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ View view = convertView;
+ if (view == null) {
+ LayoutInflater inf = LayoutInflater.from(mContext);
+ view = inf.inflate(R.layout.list_item, null);
+ }
+ Item item = (Item) getItem(position);
+ TextView titleView = (TextView) view.findViewById(R.id.textTitle);
+ TextView summaryView = (TextView) view.findViewById(R.id.textSummary);
+ ImageView iv = (ImageView) view.findViewById(R.id.imageView);
+
+ titleView.setText(item.title);
+ summaryView.setText(item.summary);
+ if (item.image != null) {
+ iv.setImageBitmap(item.image);
+ } else {
+ iv.setImageDrawable(mContext.getResources().getDrawable(R.drawable.ic_noimage));
+ }
+ return view;
+ }
+
+ @Override
+ public int getViewTypeCount() {
+ return 1;
+ }
+
+ @Override
+ public boolean hasStableIds() {
+ return false;
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return mItems.isEmpty();
+ }
+
+ @Override
+ public void registerDataSetObserver(DataSetObserver observer) {
+ mObserver = observer;
+ }
+
+ @Override
+ public void unregisterDataSetObserver(DataSetObserver observer) {
+ mObserver = null;
+ }
+
+ @Override
+ public boolean areAllItemsEnabled() {
+ return true;
+ }
+
+ @Override
+ public boolean isEnabled(int position) {
+ return true;
+ }
+
+ public String getItemName(int position) {
+ return mItems.get(position).name;
+ }
+}
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/java/com/example/android/wearable/recipeassistant/RecipeService.java b/samples/wearable/RecipeAssistant/Application/src/main/java/com/example/android/wearable/recipeassistant/RecipeService.java
new file mode 100644
index 000000000..607dd2818
--- /dev/null
+++ b/samples/wearable/RecipeAssistant/Application/src/main/java/com/example/android/wearable/recipeassistant/RecipeService.java
@@ -0,0 +1,80 @@
+package com.example.android.wearable.recipeassistant;
+
+import android.app.Notification;
+import android.app.Service;
+import android.content.Intent;
+import android.graphics.Bitmap;
+import android.os.Binder;
+import android.os.IBinder;
+import android.support.v4.app.NotificationManagerCompat;
+import android.support.v4.app.NotificationCompat;
+
+import java.util.ArrayList;
+
+public class RecipeService extends Service {
+ private NotificationManagerCompat mNotificationManager;
+ private Binder mBinder = new LocalBinder();
+ private Recipe mRecipe;
+
+ public class LocalBinder extends Binder {
+ RecipeService getService() {
+ return RecipeService.this;
+ }
+ }
+
+ @Override
+ public void onCreate() {
+ mNotificationManager = NotificationManagerCompat.from(this);
+ }
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ return mBinder;
+ }
+
+ @Override
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ if (intent.getAction().equals(Constants.ACTION_START_COOKING)) {
+ createNotification(intent);
+ return START_STICKY;
+ }
+ return START_NOT_STICKY;
+ }
+
+ private void createNotification(Intent intent) {
+ mRecipe = Recipe.fromBundle(intent.getBundleExtra(Constants.EXTRA_RECIPE));
+ ArrayList notificationPages = new ArrayList();
+
+ int stepCount = mRecipe.recipeSteps.size();
+
+ for (int i = 0; i < stepCount; ++i) {
+ Recipe.RecipeStep recipeStep = mRecipe.recipeSteps.get(i);
+ NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle();
+ style.bigText(recipeStep.stepText);
+ style.setBigContentTitle(String.format(
+ getResources().getString(R.string.step_count), i + 1, stepCount));
+ style.setSummaryText("");
+ NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
+ builder.setStyle(style);
+ notificationPages.add(builder.build());
+ }
+
+ NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
+
+ if (mRecipe.recipeImage != null) {
+ Bitmap recipeImage = Bitmap.createScaledBitmap(
+ AssetUtils.loadBitmapAsset(this, mRecipe.recipeImage),
+ Constants.NOTIFICATION_IMAGE_WIDTH, Constants.NOTIFICATION_IMAGE_HEIGHT, false);
+ builder.setLargeIcon(recipeImage);
+ }
+ builder.setContentTitle(mRecipe.titleText);
+ builder.setContentText(mRecipe.summaryText);
+ builder.setSmallIcon(R.mipmap.ic_notification_recipe);
+
+ Notification notification = builder
+ .extend(new NotificationCompat.WearableExtender()
+ .addPages(notificationPages))
+ .build();
+ mNotificationManager.notify(Constants.NOTIFICATION_ID, notification);
+ }
+}
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/res/drawable-hdpi/ic_noimage.png b/samples/wearable/RecipeAssistant/Application/src/main/res/drawable-hdpi/ic_noimage.png
new file mode 100644
index 000000000..7bba7ab76
Binary files /dev/null and b/samples/wearable/RecipeAssistant/Application/src/main/res/drawable-hdpi/ic_noimage.png differ
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/res/drawable-mdpi/ic_noimage.png b/samples/wearable/RecipeAssistant/Application/src/main/res/drawable-mdpi/ic_noimage.png
new file mode 100644
index 000000000..a5ad26f64
Binary files /dev/null and b/samples/wearable/RecipeAssistant/Application/src/main/res/drawable-mdpi/ic_noimage.png differ
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/res/drawable-xhdpi/ic_noimage.png b/samples/wearable/RecipeAssistant/Application/src/main/res/drawable-xhdpi/ic_noimage.png
new file mode 100644
index 000000000..8b631d121
Binary files /dev/null and b/samples/wearable/RecipeAssistant/Application/src/main/res/drawable-xhdpi/ic_noimage.png differ
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/res/layout/list_item.xml b/samples/wearable/RecipeAssistant/Application/src/main/res/layout/list_item.xml
new file mode 100644
index 000000000..421d057d0
--- /dev/null
+++ b/samples/wearable/RecipeAssistant/Application/src/main/res/layout/list_item.xml
@@ -0,0 +1,43 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/res/layout/recipe.xml b/samples/wearable/RecipeAssistant/Application/src/main/res/layout/recipe.xml
new file mode 100644
index 000000000..220aac2d8
--- /dev/null
+++ b/samples/wearable/RecipeAssistant/Application/src/main/res/layout/recipe.xml
@@ -0,0 +1,80 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/res/layout/step_item.xml b/samples/wearable/RecipeAssistant/Application/src/main/res/layout/step_item.xml
new file mode 100644
index 000000000..2eee9192b
--- /dev/null
+++ b/samples/wearable/RecipeAssistant/Application/src/main/res/layout/step_item.xml
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/res/menu/main.xml b/samples/wearable/RecipeAssistant/Application/src/main/res/menu/main.xml
new file mode 100644
index 000000000..fd1ead7f8
--- /dev/null
+++ b/samples/wearable/RecipeAssistant/Application/src/main/res/menu/main.xml
@@ -0,0 +1,8 @@
+
+
\ No newline at end of file
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/res/mipmap-hdpi/ic_app_recipe.png b/samples/wearable/RecipeAssistant/Application/src/main/res/mipmap-hdpi/ic_app_recipe.png
new file mode 100644
index 000000000..8ceb8696d
Binary files /dev/null and b/samples/wearable/RecipeAssistant/Application/src/main/res/mipmap-hdpi/ic_app_recipe.png differ
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/res/mipmap-hdpi/ic_notification_recipe.png b/samples/wearable/RecipeAssistant/Application/src/main/res/mipmap-hdpi/ic_notification_recipe.png
new file mode 100644
index 000000000..844d8ede8
Binary files /dev/null and b/samples/wearable/RecipeAssistant/Application/src/main/res/mipmap-hdpi/ic_notification_recipe.png differ
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/res/mipmap-mdpi/ic_app_recipe.png b/samples/wearable/RecipeAssistant/Application/src/main/res/mipmap-mdpi/ic_app_recipe.png
new file mode 100644
index 000000000..b884789c5
Binary files /dev/null and b/samples/wearable/RecipeAssistant/Application/src/main/res/mipmap-mdpi/ic_app_recipe.png differ
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/res/mipmap-mdpi/ic_notification_recipe.png b/samples/wearable/RecipeAssistant/Application/src/main/res/mipmap-mdpi/ic_notification_recipe.png
new file mode 100644
index 000000000..3f3f58cde
Binary files /dev/null and b/samples/wearable/RecipeAssistant/Application/src/main/res/mipmap-mdpi/ic_notification_recipe.png differ
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/res/mipmap-xhdpi/ic_app_recipe.png b/samples/wearable/RecipeAssistant/Application/src/main/res/mipmap-xhdpi/ic_app_recipe.png
new file mode 100644
index 000000000..2a27c3283
Binary files /dev/null and b/samples/wearable/RecipeAssistant/Application/src/main/res/mipmap-xhdpi/ic_app_recipe.png differ
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/res/mipmap-xhdpi/ic_notification_recipe.png b/samples/wearable/RecipeAssistant/Application/src/main/res/mipmap-xhdpi/ic_notification_recipe.png
new file mode 100644
index 000000000..5a99b7c71
Binary files /dev/null and b/samples/wearable/RecipeAssistant/Application/src/main/res/mipmap-xhdpi/ic_notification_recipe.png differ
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/res/mipmap-xxhdpi/ic_app_recipe.png b/samples/wearable/RecipeAssistant/Application/src/main/res/mipmap-xxhdpi/ic_app_recipe.png
new file mode 100644
index 000000000..b10c77068
Binary files /dev/null and b/samples/wearable/RecipeAssistant/Application/src/main/res/mipmap-xxhdpi/ic_app_recipe.png differ
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/res/mipmap-xxhdpi/ic_notification_recipe.png b/samples/wearable/RecipeAssistant/Application/src/main/res/mipmap-xxhdpi/ic_notification_recipe.png
new file mode 100644
index 000000000..799726d05
Binary files /dev/null and b/samples/wearable/RecipeAssistant/Application/src/main/res/mipmap-xxhdpi/ic_notification_recipe.png differ
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/res/mipmap-xxxhdpi/ic_app_recipe.png b/samples/wearable/RecipeAssistant/Application/src/main/res/mipmap-xxxhdpi/ic_app_recipe.png
new file mode 100644
index 000000000..606f07f77
Binary files /dev/null and b/samples/wearable/RecipeAssistant/Application/src/main/res/mipmap-xxxhdpi/ic_app_recipe.png differ
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/res/mipmap-xxxhdpi/ic_notification_recipe.png b/samples/wearable/RecipeAssistant/Application/src/main/res/mipmap-xxxhdpi/ic_notification_recipe.png
new file mode 100644
index 000000000..30e28a884
Binary files /dev/null and b/samples/wearable/RecipeAssistant/Application/src/main/res/mipmap-xxxhdpi/ic_notification_recipe.png differ
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/res/values/colors.xml b/samples/wearable/RecipeAssistant/Application/src/main/res/values/colors.xml
new file mode 100644
index 000000000..6e4689ae1
--- /dev/null
+++ b/samples/wearable/RecipeAssistant/Application/src/main/res/values/colors.xml
@@ -0,0 +1,5 @@
+
+
+ #dfff
+ #6aaa
+
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/res/values/strings.xml b/samples/wearable/RecipeAssistant/Application/src/main/res/values/strings.xml
new file mode 100644
index 000000000..e99a61202
--- /dev/null
+++ b/samples/wearable/RecipeAssistant/Application/src/main/res/values/strings.xml
@@ -0,0 +1,9 @@
+
+
+ Recipe Assistant
+ Settings
+ Start
+ Steps
+ Ingredients
+ Step %1$d of %2$d
+
diff --git a/samples/wearable/RecipeAssistant/Application/src/main/res/values/styles.xml b/samples/wearable/RecipeAssistant/Application/src/main/res/values/styles.xml
new file mode 100644
index 000000000..93071e24e
--- /dev/null
+++ b/samples/wearable/RecipeAssistant/Application/src/main/res/values/styles.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/samples/wearable/RecipeAssistant/_index.html b/samples/wearable/RecipeAssistant/_index.html
new file mode 100644
index 000000000..3dce7d3df
--- /dev/null
+++ b/samples/wearable/RecipeAssistant/_index.html
@@ -0,0 +1,8 @@
+
This phone application uses the enhanced notifications API to display
+recipe instructions using paged notifications. After starting the application
+on your phone, you can browse from a short list of recipes and select one to
+view. Each recipe is broken down into a number of steps; when ready, you can
+click on the START action in the action bar to send the steps to the wearable.
+On the wearable device, the steps are displayed as a multi-page notification,
+with one page for each step in the recipe.
+
diff --git a/samples/wearable/RecipeAssistant/build.gradle b/samples/wearable/RecipeAssistant/build.gradle
new file mode 100644
index 000000000..4c8f6d8b9
--- /dev/null
+++ b/samples/wearable/RecipeAssistant/build.gradle
@@ -0,0 +1,16 @@
+// Top-level build file where you can add configuration options common to all sub-projects/modules.
+
+buildscript {
+ repositories {
+ mavenCentral()
+ }
+ dependencies {
+ classpath 'com.android.tools.build:gradle:0.11.+'
+ }
+}
+
+allprojects {
+ repositories {
+ mavenCentral()
+ }
+}
diff --git a/samples/wearable/RecipeAssistant/gradle/wrapper/gradle-wrapper.jar b/samples/wearable/RecipeAssistant/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 000000000..583859812
Binary files /dev/null and b/samples/wearable/RecipeAssistant/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/samples/wearable/RecipeAssistant/gradle/wrapper/gradle-wrapper.properties b/samples/wearable/RecipeAssistant/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 000000000..e83e46081
--- /dev/null
+++ b/samples/wearable/RecipeAssistant/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Fri Mar 14 14:02:22 PDT 2014
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-all.zip
diff --git a/samples/wearable/RecipeAssistant/gradlew b/samples/wearable/RecipeAssistant/gradlew
new file mode 100755
index 000000000..91a7e269e
--- /dev/null
+++ b/samples/wearable/RecipeAssistant/gradlew
@@ -0,0 +1,164 @@
+#!/usr/bin/env bash
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+ echo "$*"
+}
+
+die ( ) {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+esac
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched.
+if $cygwin ; then
+ [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+fi
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >&-
+APP_HOME="`pwd -P`"
+cd "$SAVED" >&-
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+ JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
diff --git a/samples/wearable/RecipeAssistant/gradlew.bat b/samples/wearable/RecipeAssistant/gradlew.bat
new file mode 100644
index 000000000..aec99730b
--- /dev/null
+++ b/samples/wearable/RecipeAssistant/gradlew.bat
@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windowz variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%@eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/samples/wearable/RecipeAssistant/settings.gradle b/samples/wearable/RecipeAssistant/settings.gradle
new file mode 100644
index 000000000..aa94981a3
--- /dev/null
+++ b/samples/wearable/RecipeAssistant/settings.gradle
@@ -0,0 +1 @@
+include 'Application'
\ No newline at end of file
diff --git a/samples/wearable/SkeletonWearableApp/Wearable/build.gradle b/samples/wearable/SkeletonWearableApp/Wearable/build.gradle
new file mode 100644
index 000000000..2a520308a
--- /dev/null
+++ b/samples/wearable/SkeletonWearableApp/Wearable/build.gradle
@@ -0,0 +1,25 @@
+apply plugin: 'android'
+
+android {
+ compileSdkVersion 20
+ buildToolsVersion '20'
+
+ defaultConfig {
+ minSdkVersion 20
+ targetSdkVersion 20
+ versionCode 1
+ versionName "1.0"
+ }
+
+ buildTypes {
+ release {
+ runProguard false
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
+ }
+ }
+}
+
+dependencies {
+ compile "com.android.support:support-v13:20.0.+"
+ compile "com.google.android.support:wearable:1.0.+"
+}
diff --git a/samples/wearable/SkeletonWearableApp/Wearable/proguard-rules.txt b/samples/wearable/SkeletonWearableApp/Wearable/proguard-rules.txt
new file mode 100644
index 000000000..2ddbcfcdd
--- /dev/null
+++ b/samples/wearable/SkeletonWearableApp/Wearable/proguard-rules.txt
@@ -0,0 +1,21 @@
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
+-dontwarn android.support.wearable.view.DelayedConfirmationView
diff --git a/samples/wearable/SkeletonWearableApp/Wearable/src/main/AndroidManifest.xml b/samples/wearable/SkeletonWearableApp/Wearable/src/main/AndroidManifest.xml
new file mode 100644
index 000000000..cd684061a
--- /dev/null
+++ b/samples/wearable/SkeletonWearableApp/Wearable/src/main/AndroidManifest.xml
@@ -0,0 +1,33 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/wearable/SkeletonWearableApp/Wearable/src/main/java/com/example/android/google/wearable/app/GridExampleActivity.java b/samples/wearable/SkeletonWearableApp/Wearable/src/main/java/com/example/android/google/wearable/app/GridExampleActivity.java
new file mode 100644
index 000000000..0a88c04d0
--- /dev/null
+++ b/samples/wearable/SkeletonWearableApp/Wearable/src/main/java/com/example/android/google/wearable/app/GridExampleActivity.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * 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.
+ */
+
+package com.example.android.google.wearable.app;
+
+import android.app.Activity;
+import android.app.Fragment;
+import android.app.FragmentManager;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.graphics.Point;
+import android.graphics.Typeface;
+import android.os.Bundle;
+import android.support.wearable.view.CardFragment;
+import android.support.wearable.view.FragmentGridPagerAdapter;
+import android.support.wearable.view.GridViewPager;
+import android.support.wearable.view.ImageReference;
+import java.util.HashMap;
+import java.util.Map;
+
+public class GridExampleActivity extends Activity {
+ private static final int NUM_ROWS = 10;
+ private static final int NUM_COLS = 3;
+
+ MainAdapter mAdapter;
+ GridViewPager mPager;
+
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.grid_activity);
+ mPager = (GridViewPager) findViewById(R.id.fragment_container);
+ mAdapter = new MainAdapter(getFragmentManager());
+ mPager.setAdapter(mAdapter);
+
+ }
+
+ private static class MainAdapter extends FragmentGridPagerAdapter{
+ Map mBackgrounds = new HashMap();
+
+ public MainAdapter(FragmentManager fm) {
+ super(fm);
+ }
+
+ @Override
+ public int getRowCount() {
+ return NUM_ROWS;
+ }
+
+ @Override
+ public int getColumnCount(int rowNum) {
+ return NUM_COLS;
+ }
+
+ @Override
+ public Fragment getFragment(int rowNum, int colNum) {
+ return MainFragment.newInstance(rowNum, colNum);
+ }
+
+ @Override
+ public ImageReference getBackground(int row, int column) {
+ Point pt = new Point(column, row);
+ ImageReference ref = mBackgrounds.get(pt);
+ if (ref == null) {
+ Bitmap bm = Bitmap.createBitmap(200, 200, Bitmap.Config.ARGB_8888);
+ Canvas c = new Canvas(bm);
+ Paint p = new Paint();
+ // Clear previous image.
+ c.drawRect(0, 0, 200, 200, p);
+ p.setAntiAlias(true);
+ p.setTypeface(Typeface.DEFAULT);
+ p.setTextSize(64);
+ p.setColor(Color.LTGRAY);
+ c.drawText(column+ "-" + row, 20, 100, p);
+ ref = ImageReference.forBitmap(bm);
+ mBackgrounds.put(pt, ref);
+ }
+ return ref;
+ }
+ }
+
+ public static class MainFragment extends CardFragment {
+ private static MainFragment newInstance(int rowNum, int colNum) {
+ Bundle args = new Bundle();
+ args.putString(CardFragment.KEY_TITLE, "Row:" + rowNum);
+ args.putString(CardFragment.KEY_TEXT, "Col:" + colNum);
+ MainFragment f = new MainFragment();
+ f.setArguments(args);
+ return f;
+ }
+ }
+}
diff --git a/samples/wearable/SkeletonWearableApp/Wearable/src/main/java/com/example/android/google/wearable/app/MainActivity.java b/samples/wearable/SkeletonWearableApp/Wearable/src/main/java/com/example/android/google/wearable/app/MainActivity.java
new file mode 100644
index 000000000..11bcee752
--- /dev/null
+++ b/samples/wearable/SkeletonWearableApp/Wearable/src/main/java/com/example/android/google/wearable/app/MainActivity.java
@@ -0,0 +1,114 @@
+package com.example.android.google.wearable.app;
+
+import android.app.Activity;
+import android.app.Notification;
+import android.app.PendingIntent;
+import android.content.Intent;
+import android.os.Bundle;
+import android.support.v4.app.NotificationCompat;
+import android.support.v4.app.NotificationManagerCompat;
+import android.support.v4.view.GestureDetectorCompat;
+import android.support.wearable.view.DelayedConfirmationView;
+import android.support.wearable.view.DismissOverlayView;
+import android.util.Log;
+import android.view.GestureDetector;
+import android.view.MotionEvent;
+import android.view.View;
+import android.widget.ScrollView;
+
+
+public class MainActivity extends Activity
+ implements DelayedConfirmationView.DelayedConfirmationListener {
+ private static final String TAG = "MainActivity";
+
+ private static final int NOTIFICATION_ID = 1;
+ private static final int NOTIFICATION_REQUEST_CODE = 1;
+ private static final int NUM_SECONDS = 5;
+
+ private GestureDetectorCompat mGestureDetector;
+ private DismissOverlayView mDismissOverlayView;
+
+ @Override
+ public void onCreate(Bundle b) {
+ super.onCreate(b);
+ setContentView(R.layout.main_activity);
+
+ mDismissOverlayView = (DismissOverlayView) findViewById(R.id.dismiss_overlay);
+ mDismissOverlayView.setIntroText(R.string.intro_text);
+ mDismissOverlayView.showIntroIfNecessary();
+ mGestureDetector = new GestureDetectorCompat(this, new LongPressListener());
+ }
+
+ @Override
+ public boolean dispatchTouchEvent(MotionEvent event) {
+ return mGestureDetector.onTouchEvent(event) || super.dispatchTouchEvent(event);
+ }
+
+ private class LongPressListener extends GestureDetector.SimpleOnGestureListener {
+ @Override
+ public void onLongPress(MotionEvent event) {
+ mDismissOverlayView.show();
+ }
+ }
+
+ /**
+ * Handles the button to launch a notification.
+ */
+ public void showNotification(View view) {
+ Notification notification = new NotificationCompat.Builder(this)
+ .setContentTitle(getString(R.string.notification_title))
+ .setContentText(getString(R.string.notification_title))
+ .setSmallIcon(R.drawable.ic_launcher)
+ .addAction(R.drawable.ic_launcher,
+ getText(R.string.action_launch_activity),
+ PendingIntent.getActivity(this, NOTIFICATION_REQUEST_CODE,
+ new Intent(this, GridExampleActivity.class),
+ PendingIntent.FLAG_UPDATE_CURRENT))
+ .build();
+ NotificationManagerCompat.from(this).notify(NOTIFICATION_ID, notification);
+ finish();
+ }
+
+
+ /**
+ * Handles the button press to finish this activity and take the user back to the Home.
+ */
+ public void onFinishActivity(View view) {
+ setResult(RESULT_OK);
+ finish();
+ }
+
+ /**
+ * Handles the button to start a DelayedConfirmationView timer.
+ */
+ public void onStartTimer(View view) {
+ DelayedConfirmationView delayedConfirmationView = (DelayedConfirmationView)
+ findViewById(R.id.timer);
+ delayedConfirmationView.setTotalTimeMs(NUM_SECONDS * 1000);
+ delayedConfirmationView.setListener(this);
+ delayedConfirmationView.start();
+ scroll(View.FOCUS_DOWN);
+ }
+
+ @Override
+ public void onTimerFinished(View v) {
+ Log.d(TAG, "onTimerFinished is called.");
+ scroll(View.FOCUS_UP);
+ }
+
+ @Override
+ public void onTimerSelected(View v) {
+ Log.d(TAG, "onTimerSelected is called.");
+ scroll(View.FOCUS_UP);
+ }
+
+ private void scroll(final int scrollDirection) {
+ final ScrollView scrollView = (ScrollView) findViewById(R.id.scroll);
+ scrollView.post(new Runnable() {
+ @Override
+ public void run() {
+ scrollView.fullScroll(scrollDirection);
+ }
+ });
+ }
+}
\ No newline at end of file
diff --git a/samples/wearable/SkeletonWearableApp/Wearable/src/main/res/drawable-hdpi/ic_launcher.png b/samples/wearable/SkeletonWearableApp/Wearable/src/main/res/drawable-hdpi/ic_launcher.png
new file mode 100755
index 000000000..589f229d1
Binary files /dev/null and b/samples/wearable/SkeletonWearableApp/Wearable/src/main/res/drawable-hdpi/ic_launcher.png differ
diff --git a/samples/wearable/SkeletonWearableApp/Wearable/src/main/res/drawable-mdpi/ic_launcher.png b/samples/wearable/SkeletonWearableApp/Wearable/src/main/res/drawable-mdpi/ic_launcher.png
new file mode 100755
index 000000000..77dd57139
Binary files /dev/null and b/samples/wearable/SkeletonWearableApp/Wearable/src/main/res/drawable-mdpi/ic_launcher.png differ
diff --git a/samples/wearable/SkeletonWearableApp/Wearable/src/main/res/drawable-xhdpi/ic_launcher.png b/samples/wearable/SkeletonWearableApp/Wearable/src/main/res/drawable-xhdpi/ic_launcher.png
new file mode 100755
index 000000000..fe34ebe13
Binary files /dev/null and b/samples/wearable/SkeletonWearableApp/Wearable/src/main/res/drawable-xhdpi/ic_launcher.png differ
diff --git a/samples/wearable/SkeletonWearableApp/Wearable/src/main/res/drawable-xxhdpi/ic_launcher.png b/samples/wearable/SkeletonWearableApp/Wearable/src/main/res/drawable-xxhdpi/ic_launcher.png
new file mode 100755
index 000000000..ab80bcd13
Binary files /dev/null and b/samples/wearable/SkeletonWearableApp/Wearable/src/main/res/drawable-xxhdpi/ic_launcher.png differ
diff --git a/samples/wearable/SkeletonWearableApp/Wearable/src/main/res/layout/grid_activity.xml b/samples/wearable/SkeletonWearableApp/Wearable/src/main/res/layout/grid_activity.xml
new file mode 100644
index 000000000..3ee687c73
--- /dev/null
+++ b/samples/wearable/SkeletonWearableApp/Wearable/src/main/res/layout/grid_activity.xml
@@ -0,0 +1,6 @@
+
+
diff --git a/samples/wearable/SkeletonWearableApp/Wearable/src/main/res/layout/main_activity.xml b/samples/wearable/SkeletonWearableApp/Wearable/src/main/res/layout/main_activity.xml
new file mode 100644
index 000000000..7b92da27c
--- /dev/null
+++ b/samples/wearable/SkeletonWearableApp/Wearable/src/main/res/layout/main_activity.xml
@@ -0,0 +1,70 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/wearable/SkeletonWearableApp/Wearable/src/main/res/values/dimens.xml b/samples/wearable/SkeletonWearableApp/Wearable/src/main/res/values/dimens.xml
new file mode 100644
index 000000000..ea938863f
--- /dev/null
+++ b/samples/wearable/SkeletonWearableApp/Wearable/src/main/res/values/dimens.xml
@@ -0,0 +1,5 @@
+
+ 10dp
+ 5dp
+ 50dp
+
diff --git a/samples/wearable/SkeletonWearableApp/Wearable/src/main/res/values/strings.xml b/samples/wearable/SkeletonWearableApp/Wearable/src/main/res/values/strings.xml
new file mode 100644
index 000000000..6046af04f
--- /dev/null
+++ b/samples/wearable/SkeletonWearableApp/Wearable/src/main/res/values/strings.xml
@@ -0,0 +1,13 @@
+
+
+
+ Skeleton Wearable App
+ Long press to go back home.
+ Main Activity
+ Grid Activity
+ Finish Activity
+ Start Timer (5 sec)
+ Show Notification
+ Skeleton App Notification
+ Launch Activity
+
diff --git a/samples/wearable/SkeletonWearableApp/build.gradle b/samples/wearable/SkeletonWearableApp/build.gradle
new file mode 100644
index 000000000..d9bdcb344
--- /dev/null
+++ b/samples/wearable/SkeletonWearableApp/build.gradle
@@ -0,0 +1,15 @@
+buildscript {
+ repositories {
+ mavenCentral()
+ }
+ dependencies {
+ classpath 'com.android.tools.build:gradle:0.11.+'
+ }
+}
+
+allprojects {
+ repositories {
+ mavenCentral()
+ }
+}
+
diff --git a/samples/wearable/SkeletonWearableApp/gradle.properties b/samples/wearable/SkeletonWearableApp/gradle.properties
new file mode 100644
index 000000000..5d08ba75b
--- /dev/null
+++ b/samples/wearable/SkeletonWearableApp/gradle.properties
@@ -0,0 +1,18 @@
+# Project-wide Gradle settings.
+
+# IDE (e.g. Android Studio) users:
+# Settings specified in this file will override any Gradle settings
+# configured through the IDE.
+
+# For more details on how to configure your build environment visit
+# http://www.gradle.org/docs/current/userguide/build_environment.html
+
+# Specifies the JVM arguments used for the daemon process.
+# The setting is particularly useful for tweaking memory settings.
+# Default value: -Xmx10248m -XX:MaxPermSize=256m
+# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
+
+# When configured, Gradle will run in incubating parallel mode.
+# This option should only be used with decoupled projects. More details, visit
+# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
+# org.gradle.parallel=true
\ No newline at end of file
diff --git a/samples/wearable/SkeletonWearableApp/gradle/wrapper/gradle-wrapper.jar b/samples/wearable/SkeletonWearableApp/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 000000000..583859812
Binary files /dev/null and b/samples/wearable/SkeletonWearableApp/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/samples/wearable/SkeletonWearableApp/gradle/wrapper/gradle-wrapper.properties b/samples/wearable/SkeletonWearableApp/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 000000000..e83e46081
--- /dev/null
+++ b/samples/wearable/SkeletonWearableApp/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Fri Mar 14 14:02:22 PDT 2014
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-all.zip
diff --git a/samples/wearable/SkeletonWearableApp/gradlew b/samples/wearable/SkeletonWearableApp/gradlew
new file mode 100755
index 000000000..91a7e269e
--- /dev/null
+++ b/samples/wearable/SkeletonWearableApp/gradlew
@@ -0,0 +1,164 @@
+#!/usr/bin/env bash
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+ echo "$*"
+}
+
+die ( ) {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+esac
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched.
+if $cygwin ; then
+ [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+fi
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >&-
+APP_HOME="`pwd -P`"
+cd "$SAVED" >&-
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+ JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
diff --git a/samples/wearable/SkeletonWearableApp/gradlew.bat b/samples/wearable/SkeletonWearableApp/gradlew.bat
new file mode 100755
index 000000000..aec99730b
--- /dev/null
+++ b/samples/wearable/SkeletonWearableApp/gradlew.bat
@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windowz variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%@eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/samples/wearable/SkeletonWearableApp/settings.gradle b/samples/wearable/SkeletonWearableApp/settings.gradle
new file mode 100644
index 000000000..1d97d30e1
--- /dev/null
+++ b/samples/wearable/SkeletonWearableApp/settings.gradle
@@ -0,0 +1 @@
+include ':Wearable'
diff --git a/samples/wearable/Timer/Wearable/build.gradle b/samples/wearable/Timer/Wearable/build.gradle
new file mode 100644
index 000000000..4c5f5e9cb
--- /dev/null
+++ b/samples/wearable/Timer/Wearable/build.gradle
@@ -0,0 +1,26 @@
+apply plugin: 'android'
+
+android {
+ compileSdkVersion 20
+ buildToolsVersion '20'
+
+ defaultConfig {
+ minSdkVersion 20
+ targetSdkVersion 20
+ versionCode 1
+ versionName "1.0"
+ }
+
+ buildTypes {
+ release {
+ runProguard false
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
+ }
+ }
+}
+
+dependencies {
+ compile 'com.google.android.gms:play-services:5.+@aar'
+ compile "com.android.support:support-v4:20.0.+"
+ compile "com.google.android.support:wearable:1.0.+"
+}
diff --git a/samples/wearable/Timer/Wearable/proguard-rules.txt b/samples/wearable/Timer/Wearable/proguard-rules.txt
new file mode 100644
index 000000000..08e5bdc8d
--- /dev/null
+++ b/samples/wearable/Timer/Wearable/proguard-rules.txt
@@ -0,0 +1,22 @@
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
+-dontwarn android.support.wearable.view.DelayedConfirmationView
+-dontwarn android.support.wearable.view.CircledImageView
diff --git a/samples/wearable/Timer/Wearable/src/main/AndroidManifest.xml b/samples/wearable/Timer/Wearable/src/main/AndroidManifest.xml
new file mode 100644
index 000000000..58f61e32c
--- /dev/null
+++ b/samples/wearable/Timer/Wearable/src/main/AndroidManifest.xml
@@ -0,0 +1,47 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/wearable/Timer/Wearable/src/main/java/com/example/android/wearable/timer/SetTimerActivity.java b/samples/wearable/Timer/Wearable/src/main/java/com/example/android/wearable/timer/SetTimerActivity.java
new file mode 100644
index 000000000..92dbfc043
--- /dev/null
+++ b/samples/wearable/Timer/Wearable/src/main/java/com/example/android/wearable/timer/SetTimerActivity.java
@@ -0,0 +1,222 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * 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.
+ */
+
+package com.example.android.wearable.timer;
+
+import android.app.Activity;
+import android.app.AlarmManager;
+import android.app.Notification;
+import android.app.PendingIntent;
+import android.content.Context;
+import android.content.Intent;
+import android.content.res.Resources;
+import android.os.Bundle;
+import android.provider.AlarmClock;
+import android.support.v4.app.NotificationCompat;
+import android.support.v4.app.NotificationManagerCompat;
+import android.util.Log;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.ListView;
+
+import com.example.android.wearable.timer.util.Constants;
+import com.example.android.wearable.timer.util.TimerFormat;
+import com.google.android.gms.common.ConnectionResult;
+import com.google.android.gms.common.api.GoogleApiClient;
+import com.google.android.gms.wearable.Wearable;
+
+/** This class sets a timer. */
+public class SetTimerActivity extends Activity
+ implements AdapterView.OnItemClickListener, GoogleApiClient.ConnectionCallbacks,
+ GoogleApiClient.OnConnectionFailedListener {
+
+ public static final int NUMBER_OF_TIMES = 10;
+ public static final String TAG = "SetTimerActivity";
+
+ private ListViewItem[] mTimeOptions = new ListViewItem[NUMBER_OF_TIMES];
+ private ListView mListView;
+ private GoogleApiClient mGoogleApiClient;
+
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ int paramLength = getIntent().getIntExtra(AlarmClock.EXTRA_LENGTH, 0);
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "SetTimerActivity:onCreate=" + paramLength);
+ }
+ if (paramLength > 0 && paramLength <= 86400) {
+ long durationMillis = paramLength * 1000;
+ setupTimer(durationMillis);
+ finish();
+ return;
+ }
+
+ Resources res = getResources();
+ for (int i = 0; i < NUMBER_OF_TIMES; i++) {
+ mTimeOptions[i] = new ListViewItem(
+ res.getQuantityString(R.plurals.timer_minutes, i + 1, i + 1),
+ (i + 1) * 60 * 1000);
+ }
+
+ setContentView(R.layout.timer_set_timer);
+
+ // Initialize a simple list of countdown time options.
+ mListView = (ListView) findViewById(R.id.times_list_view);
+ ArrayAdapter arrayAdapter = new ArrayAdapter(this,
+ android.R.layout.simple_list_item_1, mTimeOptions);
+ mListView.setAdapter(arrayAdapter);
+ mListView.setOnItemClickListener(this);
+
+ mGoogleApiClient = new GoogleApiClient.Builder(this)
+ .addApi(Wearable.API)
+ .addConnectionCallbacks(this)
+ .addOnConnectionFailedListener(this)
+ .build();
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ mGoogleApiClient.connect();
+ }
+
+ @Override
+ protected void onStop() {
+ super.onStop();
+ mGoogleApiClient.disconnect();
+ }
+
+ /**
+ * Sets up an alarm (and an associated notification) to go off after duration
+ * milliseconds.
+ */
+ private void setupTimer(long duration) {
+ NotificationManagerCompat notifyMgr = NotificationManagerCompat.from(this);
+
+ // Delete dataItem and cancel a potential old countdown.
+ cancelCountdown(notifyMgr);
+
+ // Build notification and set it.
+ notifyMgr.notify(Constants.NOTIFICATION_TIMER_COUNTDOWN, buildNotification(duration));
+
+ // Register with the alarm manager to display a notification when the timer is done.
+ registerWithAlarmManager(duration);
+
+ finish();
+ }
+
+ @Override
+ public void onItemClick(AdapterView> parent, View view, int position, long id) {
+ long duration = mTimeOptions[position].duration;
+ setupTimer(duration);
+ }
+
+ private void registerWithAlarmManager(long duration) {
+ // Get the alarm manager.
+ AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
+
+ // Create intent that gets fired when timer expires.
+ Intent intent = new Intent(Constants.ACTION_SHOW_ALARM, null, this,
+ TimerNotificationService.class);
+ PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent,
+ PendingIntent.FLAG_UPDATE_CURRENT);
+
+ // Calculate the time when it expires.
+ long wakeupTime = System.currentTimeMillis() + duration;
+
+ // Schedule an alarm.
+ alarm.setExact(AlarmManager.RTC_WAKEUP, wakeupTime, pendingIntent);
+ }
+
+ /**
+ * Build a notification including different actions and other various setup and return it.
+ *
+ * @param duration the duration of the timer.
+ * @return the notification to display.
+ */
+
+ private Notification buildNotification(long duration) {
+ // Intent to restart a timer.
+ Intent restartIntent = new Intent(Constants.ACTION_RESTART_ALARM, null, this,
+ TimerNotificationService.class);
+ PendingIntent pendingIntentRestart = PendingIntent
+ .getService(this, 0, restartIntent, PendingIntent.FLAG_UPDATE_CURRENT);
+
+ // Intent to delete a timer.
+ Intent deleteIntent = new Intent(Constants.ACTION_DELETE_ALARM, null, this,
+ TimerNotificationService.class);
+ PendingIntent pendingIntentDelete = PendingIntent
+ .getService(this, 0, deleteIntent, PendingIntent.FLAG_UPDATE_CURRENT);
+
+ // Create countdown notification using a chronometer style.
+ return new NotificationCompat.Builder(this)
+ .setSmallIcon(R.drawable.ic_cc_alarm)
+ .setContentTitle(getString(R.string.timer_time_left))
+ .setContentText(TimerFormat.getTimeString(duration))
+ .setUsesChronometer(true)
+ .setWhen(System.currentTimeMillis() + duration)
+ .addAction(R.drawable.ic_cc_alarm, getString(R.string.timer_restart),
+ pendingIntentRestart)
+ .addAction(R.drawable.ic_cc_alarm, getString(R.string.timer_delete),
+ pendingIntentDelete)
+ .setDeleteIntent(pendingIntentDelete)
+ .setLocalOnly(true)
+ .build();
+ }
+
+ /**
+ * Cancels an old countdown and deletes the dataItem.
+ *
+ * @param notifyMgr the notification manager.
+ */
+ private void cancelCountdown(NotificationManagerCompat notifyMgr) {
+ notifyMgr.cancel(Constants.NOTIFICATION_TIMER_EXPIRED);
+ }
+
+ /** Model class for the listview. */
+ private static class ListViewItem {
+
+ // Duration in milliseconds.
+ long duration;
+ // Label to display.
+ private String label;
+
+ public ListViewItem(String label, long duration) {
+ this.label = label;
+ this.duration = duration;
+ }
+
+ @Override
+ public String toString() {
+ return label;
+ }
+ }
+
+ @Override
+ public void onConnected(Bundle connectionHint) {
+ }
+
+ @Override
+ public void onConnectionSuspended(int cause) {
+ }
+
+ @Override
+ public void onConnectionFailed(ConnectionResult result) {
+ }
+}
diff --git a/samples/wearable/Timer/Wearable/src/main/java/com/example/android/wearable/timer/TimerNotificationService.java b/samples/wearable/Timer/Wearable/src/main/java/com/example/android/wearable/timer/TimerNotificationService.java
new file mode 100644
index 000000000..344d84c0c
--- /dev/null
+++ b/samples/wearable/Timer/Wearable/src/main/java/com/example/android/wearable/timer/TimerNotificationService.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * 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.
+ */
+
+package com.example.android.wearable.timer;
+
+import android.app.AlarmManager;
+import android.app.IntentService;
+import android.app.Notification;
+import android.app.PendingIntent;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.support.v4.app.NotificationCompat;
+import android.support.v4.app.NotificationManagerCompat;
+import android.util.Log;
+
+import com.example.android.wearable.timer.util.Constants;
+import com.google.android.gms.common.ConnectionResult;
+import com.google.android.gms.common.api.GoogleApiClient;
+import com.google.android.gms.wearable.Wearable;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Service class that manages notifications of the timer.
+ */
+public class TimerNotificationService extends IntentService
+ implements GoogleApiClient.ConnectionCallbacks,
+ GoogleApiClient.OnConnectionFailedListener {
+
+ public static final String TAG = "TimerNotificationSvc";
+
+ public TimerNotificationService() {
+ super(TAG);
+ }
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ }
+
+ @Override
+ protected void onHandleIntent(Intent intent) {
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "onHandleIntent called with intent: " + intent);
+ }
+ String action = intent.getAction();
+ if (Constants.ACTION_SHOW_ALARM.equals(action)) {
+ showTimerDoneNotification();
+ } else if (Constants.ACTION_DELETE_ALARM.equals(action)) {
+ deleteTimer();
+ } else if (Constants.ACTION_RESTART_ALARM.equals(action)) {
+ restartAlarm();
+ } else {
+ throw new IllegalStateException("Undefined constant used: " + action);
+ }
+ }
+
+ private void restartAlarm() {
+ Intent dialogIntent = new Intent(this, SetTimerActivity.class);
+ dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ startActivity(dialogIntent);
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "Timer restarted.");
+ }
+ }
+
+ private void deleteTimer() {
+ cancelCountdownNotification();
+
+ AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
+ Intent intent = new Intent(Constants.ACTION_SHOW_ALARM, null, this,
+ TimerNotificationService.class);
+ PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent,
+ PendingIntent.FLAG_UPDATE_CURRENT);
+ alarm.cancel(pendingIntent);
+
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "Timer deleted.");
+ }
+ }
+
+ private void cancelCountdownNotification() {
+ NotificationManagerCompat notifyMgr = NotificationManagerCompat.from(this);
+ notifyMgr.cancel(Constants.NOTIFICATION_TIMER_COUNTDOWN);
+ }
+
+ private void showTimerDoneNotification() {
+ // Cancel the countdown notification to show the "timer done" notification.
+ cancelCountdownNotification();
+
+ // Create an intent to restart a timer.
+ Intent restartIntent = new Intent(Constants.ACTION_RESTART_ALARM, null, this,
+ TimerNotificationService.class);
+ PendingIntent pendingIntentRestart = PendingIntent
+ .getService(this, 0, restartIntent, PendingIntent.FLAG_UPDATE_CURRENT);
+
+ // Create notification that timer has expired.
+ NotificationManagerCompat notifyMgr = NotificationManagerCompat.from(this);
+ Notification notif = new NotificationCompat.Builder(this)
+ .setSmallIcon(R.drawable.ic_cc_alarm)
+ .setContentTitle(getString(R.string.timer_done))
+ .setContentText(getString(R.string.timer_done))
+ .setUsesChronometer(true)
+ .setWhen(System.currentTimeMillis())
+ .addAction(R.drawable.ic_cc_alarm, getString(R.string.timer_restart),
+ pendingIntentRestart)
+ .setLocalOnly(true)
+ .build();
+ notifyMgr.notify(Constants.NOTIFICATION_TIMER_EXPIRED, notif);
+ }
+
+ @Override
+ public void onConnected(Bundle connectionHint) {
+ }
+
+ @Override
+ public void onConnectionSuspended(int cause) {
+ }
+
+ @Override
+ public void onConnectionFailed(ConnectionResult result) {
+ }
+}
diff --git a/samples/wearable/Timer/Wearable/src/main/java/com/example/android/wearable/timer/util/Constants.java b/samples/wearable/Timer/Wearable/src/main/java/com/example/android/wearable/timer/util/Constants.java
new file mode 100644
index 000000000..b5f58fb8f
--- /dev/null
+++ b/samples/wearable/Timer/Wearable/src/main/java/com/example/android/wearable/timer/util/Constants.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * 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.
+ */
+
+package com.example.android.wearable.timer.util;
+
+import android.net.Uri;
+
+/** Used to hold constants. */
+public final class Constants {
+
+ public static final String START_TIME = "timer_start_time";
+ public static final String ORIGINAL_TIME = "timer_original_time";
+ public static final String DATA_ITEM_PATH = "/timer";
+ public static final Uri URI_PATTERN_DATA_ITEMS =
+ Uri.fromParts("wear", DATA_ITEM_PATH, null);
+
+ public static final int NOTIFICATION_TIMER_COUNTDOWN = 1;
+ public static final int NOTIFICATION_TIMER_EXPIRED = 2;
+
+ public static final String ACTION_SHOW_ALARM
+ = "com.android.example.clockwork.timer.ACTION_SHOW";
+ public static final String ACTION_DELETE_ALARM
+ = "com.android.example.clockwork.timer.ACTION_DELETE";
+ public static final String ACTION_RESTART_ALARM
+ = "com.android.example.clockwork.timer.ACTION_RESTART";
+
+ private Constants() {
+ }
+
+}
diff --git a/samples/wearable/Timer/Wearable/src/main/java/com/example/android/wearable/timer/util/TimerFormat.java b/samples/wearable/Timer/Wearable/src/main/java/com/example/android/wearable/timer/util/TimerFormat.java
new file mode 100644
index 000000000..ca84394a8
--- /dev/null
+++ b/samples/wearable/Timer/Wearable/src/main/java/com/example/android/wearable/timer/util/TimerFormat.java
@@ -0,0 +1,121 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * 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.
+ */
+
+package com.example.android.wearable.timer.util;
+
+/** Helper class to format the timer. Based on com.android.deskclock.timer.CountingTimerView. */
+public final class TimerFormat {
+
+ private static final String TWO_DIGITS = "%02d";
+
+ private static final String ONE_DIGIT = "%01d";
+
+ private static final String NEG_TWO_DIGITS = "-%02d";
+
+ private static final String NEG_ONE_DIGIT = "-%01d";
+
+ private static String mHours;
+
+ private static String mMinutes;
+
+ private static String mSeconds;
+
+ private TimerFormat() {
+
+ }
+
+ /**
+ * Update the time to display. Separates that time into the hours, minutes, seconds.
+ * Copied and shortened from com.android.deskclock.timer.CountingTimerView.
+ *
+ * @param time new time to display - in milliseconds
+ */
+ private static void setTime(long time) {
+ boolean neg = false;
+ boolean showNeg = false;
+ String format;
+ if (time < 0) {
+ time = -time;
+ neg = showNeg = true;
+ }
+ long seconds = time / 1000;
+ long hundreds = (time - seconds * 1000) / 10;
+ long minutes = seconds / 60;
+ seconds = seconds - minutes * 60;
+ long hours = minutes / 60;
+ minutes = minutes - hours * 60;
+ if (hours > 999) {
+ hours = 0;
+ }
+ // The time can be between 0 and -1 seconds, but the "truncated" equivalent time of hours
+ // and minutes and seconds could be zero, so since we do not show fractions of seconds
+ // when counting down, do not show the minus sign.
+ if (hours == 0 && minutes == 0 && seconds == 0) {
+ showNeg = false;
+ }
+
+ // Normalize and check if it is 'time' to invalidate
+ if (!neg && hundreds != 0) {
+ seconds++;
+ if (seconds == 60) {
+ seconds = 0;
+ minutes++;
+ if (minutes == 60) {
+ minutes = 0;
+ hours++;
+ }
+ }
+ }
+
+ // Hours may be empty
+ if (hours >= 10) {
+ format = showNeg ? NEG_TWO_DIGITS : TWO_DIGITS;
+ mHours = String.format(format, hours);
+ } else if (hours > 0) {
+ format = showNeg ? NEG_ONE_DIGIT : ONE_DIGIT;
+ mHours = String.format(format, hours);
+ } else {
+ mHours = null;
+ }
+
+ // Minutes are never empty and when hours are non-empty, must be two digits
+ if (minutes >= 10 || hours > 0) {
+ format = (showNeg && hours == 0) ? NEG_TWO_DIGITS : TWO_DIGITS;
+ mMinutes = String.format(format, minutes);
+ } else {
+ format = (showNeg && hours == 0) ? NEG_ONE_DIGIT : ONE_DIGIT;
+ mMinutes = String.format(format, minutes);
+ }
+
+ // Seconds are always two digits
+ mSeconds = String.format(TWO_DIGITS, seconds);
+ }
+
+ /**
+ * Based on com.android.deskclock.timer.CountingTimerView.
+ *
+ * @param time the time to format.
+ * @return nicely formatted time.
+ */
+ public static String getTimeString(long time) {
+ setTime(time);
+ if (mHours == null) {
+ return String.format("%s:%s", mMinutes, mSeconds);
+ }
+ return String.format("%s:%s:%s", mHours, mMinutes, mSeconds);
+
+ }
+}
diff --git a/samples/wearable/Timer/Wearable/src/main/java/com/example/android/wearable/timer/util/TimerObj.java b/samples/wearable/Timer/Wearable/src/main/java/com/example/android/wearable/timer/util/TimerObj.java
new file mode 100644
index 000000000..2c3373498
--- /dev/null
+++ b/samples/wearable/Timer/Wearable/src/main/java/com/example/android/wearable/timer/util/TimerObj.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * 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.
+ */
+
+package com.example.android.wearable.timer.util;
+
+import android.os.SystemClock;
+
+
+/** This class represents a timer. */
+public class TimerObj {
+
+ // Start time in milliseconds.
+ public long startTime;
+
+ // Length of the timer in milliseconds.
+ public long originalLength;
+
+ /**
+ * Construct a timer with a specific start time and length.
+ *
+ * @param startTime the start time of the timer.
+ * @param timerLength the length of the timer.
+ */
+ public TimerObj(long startTime, long timerLength) {
+ this.startTime = startTime;
+ this.originalLength = timerLength;
+ }
+
+ /**
+ * Calculate the time left of this timer.
+ * @return the time left for this timer.
+ */
+ public long timeLeft() {
+ long millis = SystemClock.elapsedRealtime();
+ return originalLength - (millis - startTime);
+ }
+}
diff --git a/samples/wearable/Timer/Wearable/src/main/res/drawable/ic_cc_alarm.png b/samples/wearable/Timer/Wearable/src/main/res/drawable/ic_cc_alarm.png
new file mode 100644
index 000000000..ad51ddf4d
Binary files /dev/null and b/samples/wearable/Timer/Wearable/src/main/res/drawable/ic_cc_alarm.png differ
diff --git a/samples/wearable/Timer/Wearable/src/main/res/layout/timer_set_timer.xml b/samples/wearable/Timer/Wearable/src/main/res/layout/timer_set_timer.xml
new file mode 100644
index 000000000..190b73c9b
--- /dev/null
+++ b/samples/wearable/Timer/Wearable/src/main/res/layout/timer_set_timer.xml
@@ -0,0 +1,20 @@
+
+
+
+
diff --git a/samples/wearable/Timer/Wearable/src/main/res/mipmap-hdpi/ic_launcher.png b/samples/wearable/Timer/Wearable/src/main/res/mipmap-hdpi/ic_launcher.png
new file mode 100644
index 000000000..56f7fc168
Binary files /dev/null and b/samples/wearable/Timer/Wearable/src/main/res/mipmap-hdpi/ic_launcher.png differ
diff --git a/samples/wearable/Timer/Wearable/src/main/res/mipmap-mdpi/ic_launcher.png b/samples/wearable/Timer/Wearable/src/main/res/mipmap-mdpi/ic_launcher.png
new file mode 100644
index 000000000..dec99cdfe
Binary files /dev/null and b/samples/wearable/Timer/Wearable/src/main/res/mipmap-mdpi/ic_launcher.png differ
diff --git a/samples/wearable/Timer/Wearable/src/main/res/mipmap-xhdpi/ic_launcher.png b/samples/wearable/Timer/Wearable/src/main/res/mipmap-xhdpi/ic_launcher.png
new file mode 100644
index 000000000..48fa0abf7
Binary files /dev/null and b/samples/wearable/Timer/Wearable/src/main/res/mipmap-xhdpi/ic_launcher.png differ
diff --git a/samples/wearable/Timer/Wearable/src/main/res/mipmap-xxhdpi/ic_launcher.png b/samples/wearable/Timer/Wearable/src/main/res/mipmap-xxhdpi/ic_launcher.png
new file mode 100644
index 000000000..817392194
Binary files /dev/null and b/samples/wearable/Timer/Wearable/src/main/res/mipmap-xxhdpi/ic_launcher.png differ
diff --git a/samples/wearable/Timer/Wearable/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/samples/wearable/Timer/Wearable/src/main/res/mipmap-xxxhdpi/ic_launcher.png
new file mode 100644
index 000000000..0dce80932
Binary files /dev/null and b/samples/wearable/Timer/Wearable/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ
diff --git a/samples/wearable/Timer/Wearable/src/main/res/values/strings.xml b/samples/wearable/Timer/Wearable/src/main/res/values/strings.xml
new file mode 100644
index 000000000..8cd0259ab
--- /dev/null
+++ b/samples/wearable/Timer/Wearable/src/main/res/values/strings.xml
@@ -0,0 +1,27 @@
+
+
+
+
+ Timer Example Wearable App
+ Timer done
+ Time remaining
+ Delete
+ Restart
+
+ 1 minute
+ %d minutes
+
+
diff --git a/samples/wearable/Timer/build.gradle b/samples/wearable/Timer/build.gradle
new file mode 100644
index 000000000..4c8f6d8b9
--- /dev/null
+++ b/samples/wearable/Timer/build.gradle
@@ -0,0 +1,16 @@
+// Top-level build file where you can add configuration options common to all sub-projects/modules.
+
+buildscript {
+ repositories {
+ mavenCentral()
+ }
+ dependencies {
+ classpath 'com.android.tools.build:gradle:0.11.+'
+ }
+}
+
+allprojects {
+ repositories {
+ mavenCentral()
+ }
+}
diff --git a/samples/wearable/Timer/gradle/wrapper/gradle-wrapper.jar b/samples/wearable/Timer/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 000000000..583859812
Binary files /dev/null and b/samples/wearable/Timer/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/samples/wearable/Timer/gradle/wrapper/gradle-wrapper.properties b/samples/wearable/Timer/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 000000000..e83e46081
--- /dev/null
+++ b/samples/wearable/Timer/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Fri Mar 14 14:02:22 PDT 2014
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-all.zip
diff --git a/samples/wearable/Timer/gradlew b/samples/wearable/Timer/gradlew
new file mode 100755
index 000000000..91a7e269e
--- /dev/null
+++ b/samples/wearable/Timer/gradlew
@@ -0,0 +1,164 @@
+#!/usr/bin/env bash
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+ echo "$*"
+}
+
+die ( ) {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+esac
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched.
+if $cygwin ; then
+ [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+fi
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >&-
+APP_HOME="`pwd -P`"
+cd "$SAVED" >&-
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+ JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
diff --git a/samples/wearable/Timer/gradlew.bat b/samples/wearable/Timer/gradlew.bat
new file mode 100644
index 000000000..aec99730b
--- /dev/null
+++ b/samples/wearable/Timer/gradlew.bat
@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windowz variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%@eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/samples/wearable/Timer/settings.gradle b/samples/wearable/Timer/settings.gradle
new file mode 100644
index 000000000..1d97d30e1
--- /dev/null
+++ b/samples/wearable/Timer/settings.gradle
@@ -0,0 +1 @@
+include ':Wearable'
diff --git a/samples/wearable/WatchViewStub/Wearable/_index.html b/samples/wearable/WatchViewStub/Wearable/_index.html
new file mode 100644
index 000000000..b46a3ece5
--- /dev/null
+++ b/samples/wearable/WatchViewStub/Wearable/_index.html
@@ -0,0 +1,13 @@
+
This sample demonstrates how to specify different layouts for round and rectangular screens.
+The layouts used in this sample are as follows:
+
+
Round: The background is a blue/green ring surrounding red text.
+
Rect: The background is a blue/breen rounded rectangle with red text on top.
+
+Additionally, a unique animation is played when the user clicks on the layout, depending on whether
+the screen is round or rectangular:
+
+
Round: The layout rotates 360 degrees.
+
Rect: The layout shrinks to 70% and then grows back to 100%.
+
+
\ No newline at end of file
diff --git a/samples/wearable/WatchViewStub/Wearable/build.gradle b/samples/wearable/WatchViewStub/Wearable/build.gradle
new file mode 100644
index 000000000..2a520308a
--- /dev/null
+++ b/samples/wearable/WatchViewStub/Wearable/build.gradle
@@ -0,0 +1,25 @@
+apply plugin: 'android'
+
+android {
+ compileSdkVersion 20
+ buildToolsVersion '20'
+
+ defaultConfig {
+ minSdkVersion 20
+ targetSdkVersion 20
+ versionCode 1
+ versionName "1.0"
+ }
+
+ buildTypes {
+ release {
+ runProguard false
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
+ }
+ }
+}
+
+dependencies {
+ compile "com.android.support:support-v13:20.0.+"
+ compile "com.google.android.support:wearable:1.0.+"
+}
diff --git a/samples/wearable/WatchViewStub/Wearable/proguard-rules.txt b/samples/wearable/WatchViewStub/Wearable/proguard-rules.txt
new file mode 100644
index 000000000..f2fe1559a
--- /dev/null
+++ b/samples/wearable/WatchViewStub/Wearable/proguard-rules.txt
@@ -0,0 +1,20 @@
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
diff --git a/samples/wearable/WatchViewStub/Wearable/src/main/AndroidManifest.xml b/samples/wearable/WatchViewStub/Wearable/src/main/AndroidManifest.xml
new file mode 100644
index 000000000..21925469e
--- /dev/null
+++ b/samples/wearable/WatchViewStub/Wearable/src/main/AndroidManifest.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/wearable/WatchViewStub/Wearable/src/main/java/com/example/android/google/wearable/watchviewstub/MainActivity.java b/samples/wearable/WatchViewStub/Wearable/src/main/java/com/example/android/google/wearable/watchviewstub/MainActivity.java
new file mode 100644
index 000000000..b8d14f598
--- /dev/null
+++ b/samples/wearable/WatchViewStub/Wearable/src/main/java/com/example/android/google/wearable/watchviewstub/MainActivity.java
@@ -0,0 +1,70 @@
+package com.example.android.google.wearable.watchviewstub;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.support.v4.view.GestureDetectorCompat;
+import android.support.wearable.view.DismissOverlayView;
+import android.support.wearable.view.WatchViewStub;
+import android.view.GestureDetector;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.animation.Animation;
+import android.view.animation.ScaleAnimation;
+import android.widget.RelativeLayout;
+
+
+public class MainActivity extends Activity {
+ private RelativeLayout mRectBackground;
+ private RelativeLayout mRoundBackground;
+
+ private GestureDetectorCompat mGestureDetector;
+ private DismissOverlayView mDismissOverlayView;
+
+ @Override
+ public void onCreate(Bundle b) {
+ super.onCreate(b);
+ setContentView(R.layout.main_activity);
+
+ WatchViewStub stub = (WatchViewStub) findViewById(R.id.stub);
+ stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
+ @Override
+ public void onLayoutInflated(WatchViewStub stub) {
+ mRectBackground = (RelativeLayout) findViewById(R.id.rect_layout);
+ mRoundBackground = (RelativeLayout) findViewById(R.id.round_layout);
+ }
+ });
+
+ mDismissOverlayView = (DismissOverlayView) findViewById(R.id.dismiss_overlay);
+ mGestureDetector = new GestureDetectorCompat(this, new LongPressListener());
+ }
+
+ /**
+ * Animates the layout when clicked. The animation used depends on whether the
+ * device is round or rectangular.
+ */
+ public void onLayoutClicked(View view) {
+ if (mRectBackground != null) {
+ ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f, 0.7f, 1.0f, 0.7f,
+ Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
+ scaleAnimation.setDuration(300);
+ scaleAnimation.setRepeatCount(1);
+ scaleAnimation.setRepeatMode(Animation.REVERSE);
+ mRectBackground.startAnimation(scaleAnimation);
+ }
+ if (mRoundBackground != null) {
+ mRoundBackground.animate().rotationBy(360).setDuration(300).start();
+ }
+ }
+
+ @Override
+ public boolean dispatchTouchEvent(MotionEvent event) {
+ return mGestureDetector.onTouchEvent(event) || super.dispatchTouchEvent(event);
+ }
+
+ private class LongPressListener extends GestureDetector.SimpleOnGestureListener {
+ @Override
+ public void onLongPress(MotionEvent event) {
+ mDismissOverlayView.show();
+ }
+ }
+}
\ No newline at end of file
diff --git a/samples/wearable/WatchViewStub/Wearable/src/main/res/drawable-hdpi/ic_launcher.png b/samples/wearable/WatchViewStub/Wearable/src/main/res/drawable-hdpi/ic_launcher.png
new file mode 100755
index 000000000..589f229d1
Binary files /dev/null and b/samples/wearable/WatchViewStub/Wearable/src/main/res/drawable-hdpi/ic_launcher.png differ
diff --git a/samples/wearable/WatchViewStub/Wearable/src/main/res/drawable-mdpi/ic_launcher.png b/samples/wearable/WatchViewStub/Wearable/src/main/res/drawable-mdpi/ic_launcher.png
new file mode 100755
index 000000000..77dd57139
Binary files /dev/null and b/samples/wearable/WatchViewStub/Wearable/src/main/res/drawable-mdpi/ic_launcher.png differ
diff --git a/samples/wearable/WatchViewStub/Wearable/src/main/res/drawable-xhdpi/ic_launcher.png b/samples/wearable/WatchViewStub/Wearable/src/main/res/drawable-xhdpi/ic_launcher.png
new file mode 100755
index 000000000..fe34ebe13
Binary files /dev/null and b/samples/wearable/WatchViewStub/Wearable/src/main/res/drawable-xhdpi/ic_launcher.png differ
diff --git a/samples/wearable/WatchViewStub/Wearable/src/main/res/drawable-xxhdpi/ic_launcher.png b/samples/wearable/WatchViewStub/Wearable/src/main/res/drawable-xxhdpi/ic_launcher.png
new file mode 100755
index 000000000..ab80bcd13
Binary files /dev/null and b/samples/wearable/WatchViewStub/Wearable/src/main/res/drawable-xxhdpi/ic_launcher.png differ
diff --git a/samples/wearable/WatchViewStub/Wearable/src/main/res/drawable/rect_background.xml b/samples/wearable/WatchViewStub/Wearable/src/main/res/drawable/rect_background.xml
new file mode 100644
index 000000000..f370bcb52
--- /dev/null
+++ b/samples/wearable/WatchViewStub/Wearable/src/main/res/drawable/rect_background.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/samples/wearable/WatchViewStub/Wearable/src/main/res/drawable/round_background.xml b/samples/wearable/WatchViewStub/Wearable/src/main/res/drawable/round_background.xml
new file mode 100644
index 000000000..d9e822e82
--- /dev/null
+++ b/samples/wearable/WatchViewStub/Wearable/src/main/res/drawable/round_background.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/samples/wearable/WatchViewStub/Wearable/src/main/res/layout/main_activity.xml b/samples/wearable/WatchViewStub/Wearable/src/main/res/layout/main_activity.xml
new file mode 100644
index 000000000..4d48650b6
--- /dev/null
+++ b/samples/wearable/WatchViewStub/Wearable/src/main/res/layout/main_activity.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/wearable/WatchViewStub/Wearable/src/main/res/layout/rect_layout.xml b/samples/wearable/WatchViewStub/Wearable/src/main/res/layout/rect_layout.xml
new file mode 100644
index 000000000..da9eb39e7
--- /dev/null
+++ b/samples/wearable/WatchViewStub/Wearable/src/main/res/layout/rect_layout.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/samples/wearable/WatchViewStub/Wearable/src/main/res/layout/round_layout.xml b/samples/wearable/WatchViewStub/Wearable/src/main/res/layout/round_layout.xml
new file mode 100644
index 000000000..9cbb4daa9
--- /dev/null
+++ b/samples/wearable/WatchViewStub/Wearable/src/main/res/layout/round_layout.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/samples/wearable/WatchViewStub/Wearable/src/main/res/values/dimens.xml b/samples/wearable/WatchViewStub/Wearable/src/main/res/values/dimens.xml
new file mode 100644
index 000000000..dc1f1c46a
--- /dev/null
+++ b/samples/wearable/WatchViewStub/Wearable/src/main/res/values/dimens.xml
@@ -0,0 +1,5 @@
+
+ 20dp
+ 150dp
+ 24sp
+
diff --git a/samples/wearable/WatchViewStub/Wearable/src/main/res/values/strings.xml b/samples/wearable/WatchViewStub/Wearable/src/main/res/values/strings.xml
new file mode 100644
index 000000000..71a51c6a1
--- /dev/null
+++ b/samples/wearable/WatchViewStub/Wearable/src/main/res/values/strings.xml
@@ -0,0 +1,8 @@
+
+
+
+ WatchViewStub Sample
+ Your screen is round!
+ Your screen is rectangular!
+
+
diff --git a/samples/wearable/WatchViewStub/build.gradle b/samples/wearable/WatchViewStub/build.gradle
new file mode 100644
index 000000000..d9bdcb344
--- /dev/null
+++ b/samples/wearable/WatchViewStub/build.gradle
@@ -0,0 +1,15 @@
+buildscript {
+ repositories {
+ mavenCentral()
+ }
+ dependencies {
+ classpath 'com.android.tools.build:gradle:0.11.+'
+ }
+}
+
+allprojects {
+ repositories {
+ mavenCentral()
+ }
+}
+
diff --git a/samples/wearable/WatchViewStub/gradle.properties b/samples/wearable/WatchViewStub/gradle.properties
new file mode 100644
index 000000000..5d08ba75b
--- /dev/null
+++ b/samples/wearable/WatchViewStub/gradle.properties
@@ -0,0 +1,18 @@
+# Project-wide Gradle settings.
+
+# IDE (e.g. Android Studio) users:
+# Settings specified in this file will override any Gradle settings
+# configured through the IDE.
+
+# For more details on how to configure your build environment visit
+# http://www.gradle.org/docs/current/userguide/build_environment.html
+
+# Specifies the JVM arguments used for the daemon process.
+# The setting is particularly useful for tweaking memory settings.
+# Default value: -Xmx10248m -XX:MaxPermSize=256m
+# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
+
+# When configured, Gradle will run in incubating parallel mode.
+# This option should only be used with decoupled projects. More details, visit
+# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
+# org.gradle.parallel=true
\ No newline at end of file
diff --git a/samples/wearable/WatchViewStub/gradle/wrapper/gradle-wrapper.jar b/samples/wearable/WatchViewStub/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 000000000..583859812
Binary files /dev/null and b/samples/wearable/WatchViewStub/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/samples/wearable/WatchViewStub/gradle/wrapper/gradle-wrapper.properties b/samples/wearable/WatchViewStub/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 000000000..e83e46081
--- /dev/null
+++ b/samples/wearable/WatchViewStub/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Fri Mar 14 14:02:22 PDT 2014
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-all.zip
diff --git a/samples/wearable/WatchViewStub/gradlew b/samples/wearable/WatchViewStub/gradlew
new file mode 100755
index 000000000..91a7e269e
--- /dev/null
+++ b/samples/wearable/WatchViewStub/gradlew
@@ -0,0 +1,164 @@
+#!/usr/bin/env bash
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+ echo "$*"
+}
+
+die ( ) {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+esac
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched.
+if $cygwin ; then
+ [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+fi
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >&-
+APP_HOME="`pwd -P`"
+cd "$SAVED" >&-
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+ JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
diff --git a/samples/wearable/WatchViewStub/gradlew.bat b/samples/wearable/WatchViewStub/gradlew.bat
new file mode 100755
index 000000000..aec99730b
--- /dev/null
+++ b/samples/wearable/WatchViewStub/gradlew.bat
@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windowz variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%@eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/samples/wearable/WatchViewStub/settings.gradle b/samples/wearable/WatchViewStub/settings.gradle
new file mode 100644
index 000000000..1d97d30e1
--- /dev/null
+++ b/samples/wearable/WatchViewStub/settings.gradle
@@ -0,0 +1 @@
+include ':Wearable'
diff --git a/samples/wearable/build.gradle b/samples/wearable/build.gradle
index 19c1596dd..f6230dcf9 100644
--- a/samples/wearable/build.gradle
+++ b/samples/wearable/build.gradle
@@ -9,7 +9,20 @@ buildscript {
}
List samples = [
- "Notifications"
+ "AgendaData",
+ "DataLayer",
+ "DelayedConfirmation",
+ "ElizaChat",
+ "FindMyPhone",
+ "Flashlight",
+ "Geofencing",
+ "JumpingJack",
+ "Notifications",
+ "Quiz",
+ "RecipeAssistant",
+ "SkeletonWearableApp",
+ "Timer",
+ "WatchViewStub",
]
List taskNames = [
diff --git a/samples/wearable/gradle.properties b/samples/wearable/gradle.properties
new file mode 100644
index 000000000..3372dc3fe
--- /dev/null
+++ b/samples/wearable/gradle.properties
@@ -0,0 +1 @@
+org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=1024m
diff --git a/samples/wearable/gradlew b/samples/wearable/gradlew
index 871802d5f..d8910a5b8 100755
--- a/samples/wearable/gradlew
+++ b/samples/wearable/gradlew
@@ -162,7 +162,7 @@ eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
# Change the project's .gradle to the android out dir.
-ANDROID_GRADLE_ROOT="$APP_HOME/../../../../out/host/gradle/tools/updater"
+ANDROID_GRADLE_ROOT="$APP_HOME/../../../out/host/gradle/tools/updater"
if [[ -z "$ANDROID_CACHE_DIR" ]]; then
ANDROID_CACHE_DIR="$ANDROID_GRADLE_ROOT/.gradle"
fi