Add browseable samples for Clockwork Beryl
Bug: 17473824
Change-Id: Id4c637733c491ac71bb6e269f55939c082fb0994
diff --git a/samples/browseable/AgendaData/Application/AndroidManifest.xml b/samples/browseable/AgendaData/Application/AndroidManifest.xml
new file mode 100644
index 0000000..b5bebc3
--- /dev/null
+++ b/samples/browseable/AgendaData/Application/AndroidManifest.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.agendadata">
+
+ <uses-sdk android:minSdkVersion="19"
+ android:targetSdkVersion="19" />
+
+ <uses-permission android:name="android.permission.READ_CALENDAR" />
+ <uses-permission android:name="android.permission.READ_CONTACTS" />
+
+ <application
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name"
+ android:theme="@android:style/Theme.Holo.Light"
+ >
+
+ <meta-data
+ android:name="com.google.android.gms.version"
+ android:value="@integer/google_play_services_version" />
+
+ <activity
+ android:name="com.example.android.agendadata.MainActivity"
+ android:label="@string/app_name"
+ android:configChanges="keyboardHidden|orientation|screenSize">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ </activity>
+
+ <service android:name="com.example.android.agendadata.CalendarQueryService"/>
+ </application>
+</manifest>
diff --git a/samples/browseable/AgendaData/Application/res/drawable-hdpi/ic_launcher.png b/samples/browseable/AgendaData/Application/res/drawable-hdpi/ic_launcher.png
new file mode 100644
index 0000000..0564717
--- /dev/null
+++ b/samples/browseable/AgendaData/Application/res/drawable-hdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/AgendaData/Application/res/drawable-hdpi/tile.9.png b/samples/browseable/AgendaData/Application/res/drawable-hdpi/tile.9.png
new file mode 100644
index 0000000..1358628
--- /dev/null
+++ b/samples/browseable/AgendaData/Application/res/drawable-hdpi/tile.9.png
Binary files differ
diff --git a/samples/browseable/AgendaData/Application/res/drawable-mdpi/ic_launcher.png b/samples/browseable/AgendaData/Application/res/drawable-mdpi/ic_launcher.png
new file mode 100644
index 0000000..0f40347
--- /dev/null
+++ b/samples/browseable/AgendaData/Application/res/drawable-mdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/AgendaData/Application/res/drawable-nodpi/nobody.png b/samples/browseable/AgendaData/Application/res/drawable-nodpi/nobody.png
new file mode 100644
index 0000000..5a33d60
--- /dev/null
+++ b/samples/browseable/AgendaData/Application/res/drawable-nodpi/nobody.png
Binary files differ
diff --git a/samples/browseable/AgendaData/Application/res/drawable-xhdpi/ic_launcher.png b/samples/browseable/AgendaData/Application/res/drawable-xhdpi/ic_launcher.png
new file mode 100644
index 0000000..d7705cf
--- /dev/null
+++ b/samples/browseable/AgendaData/Application/res/drawable-xhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/AgendaData/Application/res/drawable-xxhdpi/ic_launcher.png b/samples/browseable/AgendaData/Application/res/drawable-xxhdpi/ic_launcher.png
new file mode 100644
index 0000000..f07299f
--- /dev/null
+++ b/samples/browseable/AgendaData/Application/res/drawable-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/AgendaData/Application/res/layout/activity_main.xml b/samples/browseable/AgendaData/Application/res/layout/activity_main.xml
new file mode 100755
index 0000000..be1aa49
--- /dev/null
+++ b/samples/browseable/AgendaData/Application/res/layout/activity_main.xml
@@ -0,0 +1,36 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <LinearLayout style="@style/Widget.SampleMessageTile"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+
+ <TextView style="@style/Widget.SampleMessage"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="@dimen/horizontal_page_margin"
+ android:layout_marginRight="@dimen/horizontal_page_margin"
+ android:layout_marginTop="@dimen/vertical_page_margin"
+ android:layout_marginBottom="@dimen/vertical_page_margin"
+ android:text="@string/intro_message" />
+ </LinearLayout>
+</LinearLayout>
diff --git a/samples/browseable/AgendaData/Application/res/layout/main.xml b/samples/browseable/AgendaData/Application/res/layout/main.xml
new file mode 100644
index 0000000..8e82cdd
--- /dev/null
+++ b/samples/browseable/AgendaData/Application/res/layout/main.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <Button
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:text="@string/get_events"
+ android:onClick="onGetEventsClicked"/>
+ <Button
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:text="@string/delete_events"
+ android:onClick="onDeleteEventsClicked"/>
+
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:textAppearanceLarge"
+ android:layout_marginTop="6dp"
+ android:padding="6dp"
+ android:text="@string/log"
+ android:textAllCaps="true"
+ android:textColor="@android:color/white"
+ android:background="@android:color/black"/>
+
+ <ScrollView
+ android:id="@+id/scroller"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+
+ <TextView
+ android:id="@+id/log"
+ android:fontFamily="courier"
+ android:textColor="@android:color/white"
+ android:background="@android:color/black"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"/>
+ </ScrollView>
+</LinearLayout>
diff --git a/samples/browseable/AgendaData/Application/res/values-sw600dp/template-dimens.xml b/samples/browseable/AgendaData/Application/res/values-sw600dp/template-dimens.xml
new file mode 100644
index 0000000..22074a2
--- /dev/null
+++ b/samples/browseable/AgendaData/Application/res/values-sw600dp/template-dimens.xml
@@ -0,0 +1,24 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Semantic definitions -->
+
+ <dimen name="horizontal_page_margin">@dimen/margin_huge</dimen>
+ <dimen name="vertical_page_margin">@dimen/margin_medium</dimen>
+
+</resources>
diff --git a/samples/browseable/AgendaData/Application/res/values-sw600dp/template-styles.xml b/samples/browseable/AgendaData/Application/res/values-sw600dp/template-styles.xml
new file mode 100644
index 0000000..03d1974
--- /dev/null
+++ b/samples/browseable/AgendaData/Application/res/values-sw600dp/template-styles.xml
@@ -0,0 +1,25 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <style name="Widget.SampleMessage">
+ <item name="android:textAppearance">?android:textAppearanceLarge</item>
+ <item name="android:lineSpacingMultiplier">1.2</item>
+ <item name="android:shadowDy">-6.5</item>
+ </style>
+
+</resources>
diff --git a/samples/browseable/AgendaData/Application/res/values-v11/template-styles.xml b/samples/browseable/AgendaData/Application/res/values-v11/template-styles.xml
new file mode 100644
index 0000000..8c1ea66
--- /dev/null
+++ b/samples/browseable/AgendaData/Application/res/values-v11/template-styles.xml
@@ -0,0 +1,22 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Activity themes -->
+ <style name="Theme.Base" parent="android:Theme.Holo.Light" />
+
+</resources>
diff --git a/samples/browseable/AgendaData/Application/res/values/base-strings.xml b/samples/browseable/AgendaData/Application/res/values/base-strings.xml
new file mode 100644
index 0000000..7f057a0
--- /dev/null
+++ b/samples/browseable/AgendaData/Application/res/values/base-strings.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 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.
+-->
+<resources>
+ <string name="app_name">AgendaData</string>
+ <string name="intro_message">
+ <![CDATA[
+
+
+ Syncs calendar events to your wearable at the press of a button, using the Wearable
+ DataApi to transmit data such as event time, description, and background image. The DataItems can be
+ deleted individually via an action on the event notifications, or all at once via a button on the
+ companion. When deleted using the notification action, a ConfirmationActivity is used to indicate
+ success or failure.
+
+
+ ]]>
+ </string>
+</resources>
diff --git a/samples/browseable/AgendaData/Application/res/values/strings.xml b/samples/browseable/AgendaData/Application/res/values/strings.xml
new file mode 100644
index 0000000..9969f4f
--- /dev/null
+++ b/samples/browseable/AgendaData/Application/res/values/strings.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <string name="get_events">Sync calendar events to wearable</string>
+ <string name="delete_events">Delete calendar events from wearable</string>
+ <string name="log">Log</string>
+</resources>
diff --git a/samples/browseable/AgendaData/Application/res/values/template-dimens.xml b/samples/browseable/AgendaData/Application/res/values/template-dimens.xml
new file mode 100644
index 0000000..39e710b
--- /dev/null
+++ b/samples/browseable/AgendaData/Application/res/values/template-dimens.xml
@@ -0,0 +1,32 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Define standard dimensions to comply with Holo-style grids and rhythm. -->
+
+ <dimen name="margin_tiny">4dp</dimen>
+ <dimen name="margin_small">8dp</dimen>
+ <dimen name="margin_medium">16dp</dimen>
+ <dimen name="margin_large">32dp</dimen>
+ <dimen name="margin_huge">64dp</dimen>
+
+ <!-- Semantic definitions -->
+
+ <dimen name="horizontal_page_margin">@dimen/margin_medium</dimen>
+ <dimen name="vertical_page_margin">@dimen/margin_medium</dimen>
+
+</resources>
diff --git a/samples/browseable/AgendaData/Application/res/values/template-styles.xml b/samples/browseable/AgendaData/Application/res/values/template-styles.xml
new file mode 100644
index 0000000..6e7d593
--- /dev/null
+++ b/samples/browseable/AgendaData/Application/res/values/template-styles.xml
@@ -0,0 +1,42 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Activity themes -->
+
+ <style name="Theme.Base" parent="android:Theme.Light" />
+
+ <style name="Theme.Sample" parent="Theme.Base" />
+
+ <style name="AppTheme" parent="Theme.Sample" />
+ <!-- Widget styling -->
+
+ <style name="Widget" />
+
+ <style name="Widget.SampleMessage">
+ <item name="android:textAppearance">?android:textAppearanceMedium</item>
+ <item name="android:lineSpacingMultiplier">1.1</item>
+ </style>
+
+ <style name="Widget.SampleMessageTile">
+ <item name="android:background">@drawable/tile</item>
+ <item name="android:shadowColor">#7F000000</item>
+ <item name="android:shadowDy">-3.5</item>
+ <item name="android:shadowRadius">2</item>
+ </style>
+
+</resources>
diff --git a/samples/browseable/AgendaData/Application/src/com.example.android.agendadata/CalendarQueryService.java b/samples/browseable/AgendaData/Application/src/com.example.android.agendadata/CalendarQueryService.java
new file mode 100644
index 0000000..fe7fa27
--- /dev/null
+++ b/samples/browseable/AgendaData/Application/src/com.example.android.agendadata/CalendarQueryService.java
@@ -0,0 +1,267 @@
+/*
+ * 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.agendadata;
+
+
+import static com.example.android.agendadata.Constants.TAG;
+import static com.example.android.agendadata.Constants.CONNECTION_TIME_OUT_MS;
+import static com.example.android.agendadata.Constants.CAL_DATA_ITEM_PATH_PREFIX;
+import static com.example.android.agendadata.Constants.ALL_DAY;
+import static com.example.android.agendadata.Constants.BEGIN;
+import static com.example.android.agendadata.Constants.DATA_ITEM_URI;
+import static com.example.android.agendadata.Constants.DESCRIPTION;
+import static com.example.android.agendadata.Constants.END;
+import static com.example.android.agendadata.Constants.EVENT_ID;
+import static com.example.android.agendadata.Constants.ID;
+import static com.example.android.agendadata.Constants.PROFILE_PIC;
+import static com.example.android.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<Event> 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<Event> 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<Event> events = new ArrayList<Event>(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/browseable/AgendaData/Application/src/com.example.android.agendadata/Constants.java b/samples/browseable/AgendaData/Application/src/com.example.android.agendadata/Constants.java
new file mode 100644
index 0000000..d66e7ca
--- /dev/null
+++ b/samples/browseable/AgendaData/Application/src/com.example.android.agendadata/Constants.java
@@ -0,0 +1,39 @@
+/*
+ * 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.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/browseable/AgendaData/Application/src/com.example.android.agendadata/MainActivity.java b/samples/browseable/AgendaData/Application/src/com.example.android.agendadata/MainActivity.java
new file mode 100644
index 0000000..e999fde
--- /dev/null
+++ b/samples/browseable/AgendaData/Application/src/com.example.android.agendadata/MainActivity.java
@@ -0,0 +1,202 @@
+/*
+ * 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.agendadata;
+
+import static com.example.android.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<DataItemBuffer>() {
+ @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<DataItem> 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<DataApi.DeleteDataItemsResult>() {
+ @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/browseable/AgendaData/Application/src/com.example.android.common/activities/SampleActivityBase.java b/samples/browseable/AgendaData/Application/src/com.example.android.common/activities/SampleActivityBase.java
new file mode 100644
index 0000000..3228927
--- /dev/null
+++ b/samples/browseable/AgendaData/Application/src/com.example.android.common/activities/SampleActivityBase.java
@@ -0,0 +1,52 @@
+/*
+* Copyright 2013 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.common.activities;
+
+import android.os.Bundle;
+import android.support.v4.app.FragmentActivity;
+
+import com.example.android.common.logger.Log;
+import com.example.android.common.logger.LogWrapper;
+
+/**
+ * Base launcher activity, to handle most of the common plumbing for samples.
+ */
+public class SampleActivityBase extends FragmentActivity {
+
+ public static final String TAG = "SampleActivityBase";
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ initializeLogging();
+ }
+
+ /** Set up targets to receive log data */
+ public void initializeLogging() {
+ // Using Log, front-end to the logging chain, emulates android.util.log method signatures.
+ // Wraps Android's native log framework
+ LogWrapper logWrapper = new LogWrapper();
+ Log.setLogNode(logWrapper);
+
+ Log.i(TAG, "Ready");
+ }
+}
diff --git a/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/Log.java b/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/Log.java
new file mode 100644
index 0000000..17503c5
--- /dev/null
+++ b/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/Log.java
@@ -0,0 +1,236 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+/**
+ * Helper class for a list (or tree) of LoggerNodes.
+ *
+ * <p>When this is set as the head of the list,
+ * an instance of it can function as a drop-in replacement for {@link android.util.Log}.
+ * Most of the methods in this class server only to map a method call in Log to its equivalent
+ * in LogNode.</p>
+ */
+public class Log {
+ // Grabbing the native values from Android's native logging facilities,
+ // to make for easy migration and interop.
+ public static final int NONE = -1;
+ public static final int VERBOSE = android.util.Log.VERBOSE;
+ public static final int DEBUG = android.util.Log.DEBUG;
+ public static final int INFO = android.util.Log.INFO;
+ public static final int WARN = android.util.Log.WARN;
+ public static final int ERROR = android.util.Log.ERROR;
+ public static final int ASSERT = android.util.Log.ASSERT;
+
+ // Stores the beginning of the LogNode topology.
+ private static LogNode mLogNode;
+
+ /**
+ * Returns the next LogNode in the linked list.
+ */
+ public static LogNode getLogNode() {
+ return mLogNode;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to.
+ */
+ public static void setLogNode(LogNode node) {
+ mLogNode = node;
+ }
+
+ /**
+ * Instructs the LogNode to print the log data provided. Other LogNodes can
+ * be chained to the end of the LogNode as desired.
+ *
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void println(int priority, String tag, String msg, Throwable tr) {
+ if (mLogNode != null) {
+ mLogNode.println(priority, tag, msg, tr);
+ }
+ }
+
+ /**
+ * Instructs the LogNode to print the log data provided. Other LogNodes can
+ * be chained to the end of the LogNode as desired.
+ *
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ */
+ public static void println(int priority, String tag, String msg) {
+ println(priority, tag, msg, null);
+ }
+
+ /**
+ * Prints a message at VERBOSE priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void v(String tag, String msg, Throwable tr) {
+ println(VERBOSE, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at VERBOSE priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void v(String tag, String msg) {
+ v(tag, msg, null);
+ }
+
+
+ /**
+ * Prints a message at DEBUG priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void d(String tag, String msg, Throwable tr) {
+ println(DEBUG, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at DEBUG priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void d(String tag, String msg) {
+ d(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at INFO priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void i(String tag, String msg, Throwable tr) {
+ println(INFO, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at INFO priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void i(String tag, String msg) {
+ i(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void w(String tag, String msg, Throwable tr) {
+ println(WARN, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void w(String tag, String msg) {
+ w(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void w(String tag, Throwable tr) {
+ w(tag, null, tr);
+ }
+
+ /**
+ * Prints a message at ERROR priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void e(String tag, String msg, Throwable tr) {
+ println(ERROR, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at ERROR priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void e(String tag, String msg) {
+ e(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void wtf(String tag, String msg, Throwable tr) {
+ println(ASSERT, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void wtf(String tag, String msg) {
+ wtf(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void wtf(String tag, Throwable tr) {
+ wtf(tag, null, tr);
+ }
+}
diff --git a/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/LogFragment.java
new file mode 100644
index 0000000..b302acd
--- /dev/null
+++ b/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/LogFragment.java
@@ -0,0 +1,109 @@
+/*
+* Copyright 2013 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.
+*/
+/*
+ * Copyright 2013 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.common.logger;
+
+import android.graphics.Typeface;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ScrollView;
+
+/**
+ * Simple fraggment which contains a LogView and uses is to output log data it receives
+ * through the LogNode interface.
+ */
+public class LogFragment extends Fragment {
+
+ private LogView mLogView;
+ private ScrollView mScrollView;
+
+ public LogFragment() {}
+
+ public View inflateViews() {
+ mScrollView = new ScrollView(getActivity());
+ ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT);
+ mScrollView.setLayoutParams(scrollParams);
+
+ mLogView = new LogView(getActivity());
+ ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams);
+ logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
+ mLogView.setLayoutParams(logParams);
+ mLogView.setClickable(true);
+ mLogView.setFocusable(true);
+ mLogView.setTypeface(Typeface.MONOSPACE);
+
+ // Want to set padding as 16 dips, setPadding takes pixels. Hooray math!
+ int paddingDips = 16;
+ double scale = getResources().getDisplayMetrics().density;
+ int paddingPixels = (int) ((paddingDips * (scale)) + .5);
+ mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels);
+ mLogView.setCompoundDrawablePadding(paddingPixels);
+
+ mLogView.setGravity(Gravity.BOTTOM);
+ mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium);
+
+ mScrollView.addView(mLogView);
+ return mScrollView;
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+
+ View result = inflateViews();
+
+ mLogView.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {}
+
+ @Override
+ public void afterTextChanged(Editable s) {
+ mScrollView.fullScroll(ScrollView.FOCUS_DOWN);
+ }
+ });
+ return result;
+ }
+
+ public LogView getLogView() {
+ return mLogView;
+ }
+}
\ No newline at end of file
diff --git a/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/LogNode.java
new file mode 100644
index 0000000..bc37cab
--- /dev/null
+++ b/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/LogNode.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2012 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.common.logger;
+
+/**
+ * Basic interface for a logging system that can output to one or more targets.
+ * Note that in addition to classes that will output these logs in some format,
+ * one can also implement this interface over a filter and insert that in the chain,
+ * such that no targets further down see certain data, or see manipulated forms of the data.
+ * You could, for instance, write a "ToHtmlLoggerNode" that just converted all the log data
+ * it received to HTML and sent it along to the next node in the chain, without printing it
+ * anywhere.
+ */
+public interface LogNode {
+
+ /**
+ * Instructs first LogNode in the list to print the log data provided.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public void println(int priority, String tag, String msg, Throwable tr);
+
+}
diff --git a/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/LogView.java
new file mode 100644
index 0000000..c01542b
--- /dev/null
+++ b/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/LogView.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+import android.app.Activity;
+import android.content.Context;
+import android.util.*;
+import android.widget.TextView;
+
+/** Simple TextView which is used to output log data received through the LogNode interface.
+*/
+public class LogView extends TextView implements LogNode {
+
+ public LogView(Context context) {
+ super(context);
+ }
+
+ public LogView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public LogView(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ /**
+ * Formats the log data and prints it out to the LogView.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+
+
+ String priorityStr = null;
+
+ // For the purposes of this View, we want to print the priority as readable text.
+ switch(priority) {
+ case android.util.Log.VERBOSE:
+ priorityStr = "VERBOSE";
+ break;
+ case android.util.Log.DEBUG:
+ priorityStr = "DEBUG";
+ break;
+ case android.util.Log.INFO:
+ priorityStr = "INFO";
+ break;
+ case android.util.Log.WARN:
+ priorityStr = "WARN";
+ break;
+ case android.util.Log.ERROR:
+ priorityStr = "ERROR";
+ break;
+ case android.util.Log.ASSERT:
+ priorityStr = "ASSERT";
+ break;
+ default:
+ break;
+ }
+
+ // Handily, the Log class has a facility for converting a stack trace into a usable string.
+ String exceptionStr = null;
+ if (tr != null) {
+ exceptionStr = android.util.Log.getStackTraceString(tr);
+ }
+
+ // Take the priority, tag, message, and exception, and concatenate as necessary
+ // into one usable line of text.
+ final StringBuilder outputBuilder = new StringBuilder();
+
+ String delimiter = "\t";
+ appendIfNotNull(outputBuilder, priorityStr, delimiter);
+ appendIfNotNull(outputBuilder, tag, delimiter);
+ appendIfNotNull(outputBuilder, msg, delimiter);
+ appendIfNotNull(outputBuilder, exceptionStr, delimiter);
+
+ // In case this was originally called from an AsyncTask or some other off-UI thread,
+ // make sure the update occurs within the UI thread.
+ ((Activity) getContext()).runOnUiThread( (new Thread(new Runnable() {
+ @Override
+ public void run() {
+ // Display the text we just generated within the LogView.
+ appendToLog(outputBuilder.toString());
+ }
+ })));
+
+ if (mNext != null) {
+ mNext.println(priority, tag, msg, tr);
+ }
+ }
+
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+ /** Takes a string and adds to it, with a separator, if the bit to be added isn't null. Since
+ * the logger takes so many arguments that might be null, this method helps cut out some of the
+ * agonizing tedium of writing the same 3 lines over and over.
+ * @param source StringBuilder containing the text to append to.
+ * @param addStr The String to append
+ * @param delimiter The String to separate the source and appended strings. A tab or comma,
+ * for instance.
+ * @return The fully concatenated String as a StringBuilder
+ */
+ private StringBuilder appendIfNotNull(StringBuilder source, String addStr, String delimiter) {
+ if (addStr != null) {
+ if (addStr.length() == 0) {
+ delimiter = "";
+ }
+
+ return source.append(addStr).append(delimiter);
+ }
+ return source;
+ }
+
+ // The next LogNode in the chain.
+ LogNode mNext;
+
+ /** Outputs the string as a new line of log data in the LogView. */
+ public void appendToLog(String s) {
+ append("\n" + s);
+ }
+
+
+}
diff --git a/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/LogWrapper.java
new file mode 100644
index 0000000..16a9e7b
--- /dev/null
+++ b/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/LogWrapper.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2012 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.common.logger;
+
+import android.util.Log;
+
+/**
+ * Helper class which wraps Android's native Log utility in the Logger interface. This way
+ * normal DDMS output can be one of the many targets receiving and outputting logs simultaneously.
+ */
+public class LogWrapper implements LogNode {
+
+ // For piping: The next node to receive Log data after this one has done its work.
+ private LogNode mNext;
+
+ /**
+ * Returns the next LogNode in the linked list.
+ */
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to..
+ */
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+ /**
+ * Prints data out to the console using Android's native log mechanism.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+ // There actually are log methods that don't take a msg parameter. For now,
+ // if that's the case, just convert null to the empty string and move on.
+ String useMsg = msg;
+ if (useMsg == null) {
+ useMsg = "";
+ }
+
+ // If an exeption was provided, convert that exception to a usable string and attach
+ // it to the end of the msg method.
+ if (tr != null) {
+ msg += "\n" + Log.getStackTraceString(tr);
+ }
+
+ // This is functionally identical to Log.x(tag, useMsg);
+ // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg)
+ Log.println(priority, tag, useMsg);
+
+ // If this isn't the last node in the chain, move things along.
+ if (mNext != null) {
+ mNext.println(priority, tag, msg, tr);
+ }
+ }
+}
diff --git a/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java
new file mode 100644
index 0000000..19967dc
--- /dev/null
+++ b/samples/browseable/AgendaData/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+/**
+ * Simple {@link LogNode} filter, removes everything except the message.
+ * Useful for situations like on-screen log output where you don't want a lot of metadata displayed,
+ * just easy-to-read message updates as they're happening.
+ */
+public class MessageOnlyLogFilter implements LogNode {
+
+ LogNode mNext;
+
+ /**
+ * Takes the "next" LogNode as a parameter, to simplify chaining.
+ *
+ * @param next The next LogNode in the pipeline.
+ */
+ public MessageOnlyLogFilter(LogNode next) {
+ mNext = next;
+ }
+
+ public MessageOnlyLogFilter() {
+ }
+
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+ if (mNext != null) {
+ getNext().println(Log.NONE, null, msg, null);
+ }
+ }
+
+ /**
+ * Returns the next LogNode in the chain.
+ */
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to..
+ */
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+}
diff --git a/samples/browseable/AgendaData/Shared/AndroidManifest.xml b/samples/browseable/AgendaData/Shared/AndroidManifest.xml
new file mode 100644
index 0000000..07bc153
--- /dev/null
+++ b/samples/browseable/AgendaData/Shared/AndroidManifest.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.agendadata.common">
+
+ <application android:allowBackup="true"
+ android:label="@string/app_name">
+ </application>
+
+</manifest>
diff --git a/samples/browseable/AgendaData/Shared/res/values/strings.xml b/samples/browseable/AgendaData/Shared/res/values/strings.xml
new file mode 100644
index 0000000..0f2bb90
--- /dev/null
+++ b/samples/browseable/AgendaData/Shared/res/values/strings.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<resources>
+ <string name="app_name">Shared</string>
+</resources>
diff --git a/samples/browseable/AgendaData/Wearable/AndroidManifest.xml b/samples/browseable/AgendaData/Wearable/AndroidManifest.xml
new file mode 100644
index 0000000..c91f09c
--- /dev/null
+++ b/samples/browseable/AgendaData/Wearable/AndroidManifest.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.agendadata" >
+
+ <uses-sdk android:minSdkVersion="20"
+ android:targetSdkVersion="20" />
+
+ <uses-feature android:name="android.hardware.type.watch" />
+
+ <application
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name"
+ >
+
+ <meta-data
+ android:name="com.google.android.gms.version"
+ android:value="@integer/google_play_services_version" />
+
+ <service
+ android:name="com.example.android.agendadata.HomeListenerService" >
+ <intent-filter>
+ <action android:name="com.google.android.gms.wearable.BIND_LISTENER" />
+ </intent-filter>
+ </service>
+
+ <service android:name="com.example.android.agendadata.DeleteService"/>
+
+ <activity android:name="android.support.wearable.activity.ConfirmationActivity"/>
+
+ </application>
+</manifest>
diff --git a/samples/browseable/AgendaData/Wearable/res/drawable-hdpi/ic_launcher.png b/samples/browseable/AgendaData/Wearable/res/drawable-hdpi/ic_launcher.png
new file mode 100644
index 0000000..0564717
--- /dev/null
+++ b/samples/browseable/AgendaData/Wearable/res/drawable-hdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/AgendaData/Wearable/res/drawable-hdpi/ic_menu_delete.png b/samples/browseable/AgendaData/Wearable/res/drawable-hdpi/ic_menu_delete.png
new file mode 100644
index 0000000..24d8f6a
--- /dev/null
+++ b/samples/browseable/AgendaData/Wearable/res/drawable-hdpi/ic_menu_delete.png
Binary files differ
diff --git a/samples/browseable/AgendaData/Wearable/res/drawable-mdpi/ic_launcher.png b/samples/browseable/AgendaData/Wearable/res/drawable-mdpi/ic_launcher.png
new file mode 100644
index 0000000..0f40347
--- /dev/null
+++ b/samples/browseable/AgendaData/Wearable/res/drawable-mdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/AgendaData/Wearable/res/drawable-mdpi/ic_menu_delete.png b/samples/browseable/AgendaData/Wearable/res/drawable-mdpi/ic_menu_delete.png
new file mode 100644
index 0000000..e2c8700
--- /dev/null
+++ b/samples/browseable/AgendaData/Wearable/res/drawable-mdpi/ic_menu_delete.png
Binary files differ
diff --git a/samples/browseable/AgendaData/Wearable/res/drawable-xhdpi/ic_launcher.png b/samples/browseable/AgendaData/Wearable/res/drawable-xhdpi/ic_launcher.png
new file mode 100644
index 0000000..d7705cf
--- /dev/null
+++ b/samples/browseable/AgendaData/Wearable/res/drawable-xhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/AgendaData/Wearable/res/drawable-xhdpi/ic_menu_delete.png b/samples/browseable/AgendaData/Wearable/res/drawable-xhdpi/ic_menu_delete.png
new file mode 100644
index 0000000..65b9cae
--- /dev/null
+++ b/samples/browseable/AgendaData/Wearable/res/drawable-xhdpi/ic_menu_delete.png
Binary files differ
diff --git a/samples/browseable/AgendaData/Wearable/res/drawable-xxhdpi/ic_launcher.png b/samples/browseable/AgendaData/Wearable/res/drawable-xxhdpi/ic_launcher.png
new file mode 100644
index 0000000..f07299f
--- /dev/null
+++ b/samples/browseable/AgendaData/Wearable/res/drawable-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/AgendaData/Wearable/res/drawable-xxhdpi/ic_menu_delete.png b/samples/browseable/AgendaData/Wearable/res/drawable-xxhdpi/ic_menu_delete.png
new file mode 100644
index 0000000..8e9e78d
--- /dev/null
+++ b/samples/browseable/AgendaData/Wearable/res/drawable-xxhdpi/ic_menu_delete.png
Binary files differ
diff --git a/samples/browseable/AgendaData/Wearable/res/values/strings.xml b/samples/browseable/AgendaData/Wearable/res/values/strings.xml
new file mode 100644
index 0000000..10ef53c
--- /dev/null
+++ b/samples/browseable/AgendaData/Wearable/res/values/strings.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <string name="app_name">Android Wear AgendaData Example Application</string>
+ <string name="delete">Delete</string>
+ <string name="desc_all_day">%s(All day)</string>
+ <string name="desc_time_period">%1$s(%2$s - %3$s)</string>
+ <string name="delete_successful">Event deleted</string>
+ <string name="delete_unsuccessful">Unable to delete event</string>
+</resources>
diff --git a/samples/browseable/AgendaData/Wearable/src/com.example.android.agendadata/Constants.java b/samples/browseable/AgendaData/Wearable/src/com.example.android.agendadata/Constants.java
new file mode 100644
index 0000000..5b51751
--- /dev/null
+++ b/samples/browseable/AgendaData/Wearable/src/com.example.android.agendadata/Constants.java
@@ -0,0 +1,35 @@
+/*
+ * 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.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/browseable/AgendaData/Wearable/src/com.example.android.agendadata/DeleteService.java b/samples/browseable/AgendaData/Wearable/src/com.example.android.agendadata/DeleteService.java
new file mode 100644
index 0000000..7c6bb9b
--- /dev/null
+++ b/samples/browseable/AgendaData/Wearable/src/com.example.android.agendadata/DeleteService.java
@@ -0,0 +1,118 @@
+/*
+ * 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.agendadata;
+
+import static com.example.android.agendadata.Constants.TAG;
+import static com.example.android.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) {
+ }
+
+}
diff --git a/samples/browseable/AgendaData/Wearable/src/com.example.android.agendadata/HomeListenerService.java b/samples/browseable/AgendaData/Wearable/src/com.example.android.agendadata/HomeListenerService.java
new file mode 100644
index 0000000..7a46911
--- /dev/null
+++ b/samples/browseable/AgendaData/Wearable/src/com.example.android.agendadata/HomeListenerService.java
@@ -0,0 +1,180 @@
+/*
+ * 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.agendadata;
+
+import static com.example.android.agendadata.Constants.TAG;
+import static com.example.android.agendadata.Constants.EXTRA_SILENT;
+
+import static com.example.android.agendadata.Constants.ALL_DAY;
+import static com.example.android.agendadata.Constants.BEGIN;
+import static com.example.android.agendadata.Constants.DESCRIPTION;
+import static com.example.android.agendadata.Constants.END;
+import static com.example.android.agendadata.Constants.PROFILE_PIC;
+import static com.example.android.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<Uri, Integer> sNotificationIdByDataItemUri =
+ new HashMap<Uri, Integer>();
+ 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/browseable/AgendaData/_index.jd b/samples/browseable/AgendaData/_index.jd
new file mode 100644
index 0000000..7586b50
--- /dev/null
+++ b/samples/browseable/AgendaData/_index.jd
@@ -0,0 +1,13 @@
+page.tags="AgendaData"
+sample.group=Wearable
+@jd:body
+
+<p>
+
+ Syncs calendar events to your wearable at the press of a button, using the Wearable
+ DataApi to transmit data such as event time, description, and background image. The DataItems can be
+ deleted individually via an action on the event notifications, or all at once via a button on the
+ companion. When deleted using the notification action, a ConfirmationActivity is used to indicate
+ success or failure.
+
+ </p>
diff --git a/samples/browseable/DataLayer/Application/AndroidManifest.xml b/samples/browseable/DataLayer/Application/AndroidManifest.xml
new file mode 100644
index 0000000..f382b25
--- /dev/null
+++ b/samples/browseable/DataLayer/Application/AndroidManifest.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.datalayer" >
+
+ <uses-sdk android:minSdkVersion="19"
+ android:targetSdkVersion="19" />
+
+ <uses-feature android:name="android.hardware.camera" android:required="false" />
+
+ <application
+ android:allowBackup="true"
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name">
+
+ <meta-data
+ android:name="com.google.android.gms.version"
+ android:value="@integer/google_play_services_version" />
+
+ <activity
+ android:name=".MainActivity"
+ android:label="@string/app_name"
+ android:launchMode="singleTask" >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+</manifest>
diff --git a/samples/browseable/DataLayer/Application/res/drawable-hdpi/ic_content_picture.png b/samples/browseable/DataLayer/Application/res/drawable-hdpi/ic_content_picture.png
new file mode 100644
index 0000000..597997c
--- /dev/null
+++ b/samples/browseable/DataLayer/Application/res/drawable-hdpi/ic_content_picture.png
Binary files differ
diff --git a/samples/browseable/DataLayer/Application/res/drawable-hdpi/ic_launcher.png b/samples/browseable/DataLayer/Application/res/drawable-hdpi/ic_launcher.png
new file mode 100755
index 0000000..589f229
--- /dev/null
+++ b/samples/browseable/DataLayer/Application/res/drawable-hdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/DataLayer/Application/res/drawable-hdpi/tile.9.png b/samples/browseable/DataLayer/Application/res/drawable-hdpi/tile.9.png
new file mode 100644
index 0000000..1358628
--- /dev/null
+++ b/samples/browseable/DataLayer/Application/res/drawable-hdpi/tile.9.png
Binary files differ
diff --git a/samples/browseable/DataLayer/Application/res/drawable-mdpi/ic_content_picture.png b/samples/browseable/DataLayer/Application/res/drawable-mdpi/ic_content_picture.png
new file mode 100644
index 0000000..c23f4c0
--- /dev/null
+++ b/samples/browseable/DataLayer/Application/res/drawable-mdpi/ic_content_picture.png
Binary files differ
diff --git a/samples/browseable/DataLayer/Application/res/drawable-mdpi/ic_launcher.png b/samples/browseable/DataLayer/Application/res/drawable-mdpi/ic_launcher.png
new file mode 100755
index 0000000..77dd571
--- /dev/null
+++ b/samples/browseable/DataLayer/Application/res/drawable-mdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/DataLayer/Application/res/drawable-xhdpi/ic_content_picture.png b/samples/browseable/DataLayer/Application/res/drawable-xhdpi/ic_content_picture.png
new file mode 100644
index 0000000..289adf1
--- /dev/null
+++ b/samples/browseable/DataLayer/Application/res/drawable-xhdpi/ic_content_picture.png
Binary files differ
diff --git a/samples/browseable/DataLayer/Application/res/drawable-xhdpi/ic_launcher.png b/samples/browseable/DataLayer/Application/res/drawable-xhdpi/ic_launcher.png
new file mode 100755
index 0000000..fe34ebe
--- /dev/null
+++ b/samples/browseable/DataLayer/Application/res/drawable-xhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/DataLayer/Application/res/drawable-xxhdpi/ic_content_picture.png b/samples/browseable/DataLayer/Application/res/drawable-xxhdpi/ic_content_picture.png
new file mode 100644
index 0000000..073ad55
--- /dev/null
+++ b/samples/browseable/DataLayer/Application/res/drawable-xxhdpi/ic_content_picture.png
Binary files differ
diff --git a/samples/browseable/DataLayer/Application/res/drawable-xxhdpi/ic_launcher.png b/samples/browseable/DataLayer/Application/res/drawable-xxhdpi/ic_launcher.png
new file mode 100755
index 0000000..ab80bcd
--- /dev/null
+++ b/samples/browseable/DataLayer/Application/res/drawable-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/DataLayer/Application/res/drawable/divider.xml b/samples/browseable/DataLayer/Application/res/drawable/divider.xml
new file mode 100644
index 0000000..95c4d33
--- /dev/null
+++ b/samples/browseable/DataLayer/Application/res/drawable/divider.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<shape xmlns:android="http://schemas.android.com/apk/res/android">
+ <size android:height="2dip"/>
+ <solid android:color="#ffffffff"/>
+</shape>
diff --git a/samples/browseable/DataLayer/Application/res/layout/activity_main.xml b/samples/browseable/DataLayer/Application/res/layout/activity_main.xml
new file mode 100755
index 0000000..be1aa49
--- /dev/null
+++ b/samples/browseable/DataLayer/Application/res/layout/activity_main.xml
@@ -0,0 +1,36 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <LinearLayout style="@style/Widget.SampleMessageTile"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+
+ <TextView style="@style/Widget.SampleMessage"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="@dimen/horizontal_page_margin"
+ android:layout_marginRight="@dimen/horizontal_page_margin"
+ android:layout_marginTop="@dimen/vertical_page_margin"
+ android:layout_marginBottom="@dimen/vertical_page_margin"
+ android:text="@string/intro_message" />
+ </LinearLayout>
+</LinearLayout>
diff --git a/samples/browseable/DataLayer/Application/res/layout/main_activity.xml b/samples/browseable/DataLayer/Application/res/layout/main_activity.xml
new file mode 100644
index 0000000..0412023
--- /dev/null
+++ b/samples/browseable/DataLayer/Application/res/layout/main_activity.xml
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <RelativeLayout
+ android:id="@+id/top"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_alignParentTop="true"
+ android:layout_marginTop="10dp">
+
+ <Button
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/take_photo"
+ android:id="@+id/takePhoto"
+ android:onClick="onTakePhotoClick"
+ android:layout_marginLeft="39dp"
+ android:layout_alignParentStart="true"
+ android:layout_alignParentTop="true" />
+
+ <Button
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/send_photo"
+ android:id="@+id/sendPhoto"
+ android:layout_alignRight="@+id/takePhoto"
+ android:layout_marginLeft="39dp"
+ android:enabled="false"
+ android:onClick="onSendPhotoClick"
+ android:layout_alignParentStart="true"
+ android:layout_below="@+id/takePhoto" />
+
+ <ImageView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:id="@+id/imageView"
+ android:layout_marginLeft="29dp"
+ android:layout_centerVertical="true"
+ android:layout_alignParentRight="true"
+ android:src="@drawable/ic_content_picture" />
+ </RelativeLayout>
+
+ <View
+ style="@style/Divider"
+ android:id="@+id/divider"
+ android:layout_below="@+id/top"
+ android:layout_marginTop="5dp"
+ android:layout_marginLeft="20dp"
+ android:layout_marginRight="20dp" />
+
+ <Button
+ android:id="@+id/start_wearable_activity"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginRight="10dp"
+ android:onClick="onStartWearableActivityClick"
+ android:text="@string/start_wearable_activity"
+ android:enabled="false"
+ android:layout_below="@+id/divider"
+ android:layout_centerHorizontal="true"
+ android:layout_marginTop="10dp" />
+
+ <ListView
+ android:id="@+id/data_item_list"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_below="@+id/start_wearable_activity"
+ android:transcriptMode="alwaysScroll" />
+</RelativeLayout>
diff --git a/samples/browseable/DataLayer/Application/res/values-sw600dp/template-dimens.xml b/samples/browseable/DataLayer/Application/res/values-sw600dp/template-dimens.xml
new file mode 100644
index 0000000..22074a2
--- /dev/null
+++ b/samples/browseable/DataLayer/Application/res/values-sw600dp/template-dimens.xml
@@ -0,0 +1,24 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Semantic definitions -->
+
+ <dimen name="horizontal_page_margin">@dimen/margin_huge</dimen>
+ <dimen name="vertical_page_margin">@dimen/margin_medium</dimen>
+
+</resources>
diff --git a/samples/browseable/DataLayer/Application/res/values-sw600dp/template-styles.xml b/samples/browseable/DataLayer/Application/res/values-sw600dp/template-styles.xml
new file mode 100644
index 0000000..03d1974
--- /dev/null
+++ b/samples/browseable/DataLayer/Application/res/values-sw600dp/template-styles.xml
@@ -0,0 +1,25 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <style name="Widget.SampleMessage">
+ <item name="android:textAppearance">?android:textAppearanceLarge</item>
+ <item name="android:lineSpacingMultiplier">1.2</item>
+ <item name="android:shadowDy">-6.5</item>
+ </style>
+
+</resources>
diff --git a/samples/browseable/DataLayer/Application/res/values-v11/template-styles.xml b/samples/browseable/DataLayer/Application/res/values-v11/template-styles.xml
new file mode 100644
index 0000000..8c1ea66
--- /dev/null
+++ b/samples/browseable/DataLayer/Application/res/values-v11/template-styles.xml
@@ -0,0 +1,22 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Activity themes -->
+ <style name="Theme.Base" parent="android:Theme.Holo.Light" />
+
+</resources>
diff --git a/samples/browseable/DataLayer/Application/res/values/base-strings.xml b/samples/browseable/DataLayer/Application/res/values/base-strings.xml
new file mode 100644
index 0000000..b335734
--- /dev/null
+++ b/samples/browseable/DataLayer/Application/res/values/base-strings.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 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.
+-->
+<resources>
+ <string name="app_name">DataLayer</string>
+ <string name="intro_message">
+ <![CDATA[
+
+
+ You can cause the wearable to start an activity by pressing a button in the
+ companion app UI. You can also take a picture on the companion device, which will be transmitted as
+ an Asset for display on the wearable.
+
+
+ ]]>
+ </string>
+</resources>
diff --git a/samples/browseable/DataLayer/Application/res/values/strings.xml b/samples/browseable/DataLayer/Application/res/values/strings.xml
new file mode 100644
index 0000000..9eba46c
--- /dev/null
+++ b/samples/browseable/DataLayer/Application/res/values/strings.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <string name="start_wearable_activity">Start Wearable Activity</string>
+ <string name="start">Start</string>
+ <string name="take_photo">Take a Photo</string>
+ <string name="send_photo">Send Photo</string>
+</resources>
diff --git a/samples/browseable/DataLayer/Application/res/values/style.xml b/samples/browseable/DataLayer/Application/res/values/style.xml
new file mode 100644
index 0000000..81d6799
--- /dev/null
+++ b/samples/browseable/DataLayer/Application/res/values/style.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+ <style name="Divider">
+ <item name="android:layout_width">match_parent</item>
+ <item name="android:layout_height">3dp</item>
+ <item name="android:background">?android:attr/listDivider</item>
+ </style>
+</resources>
diff --git a/samples/browseable/DataLayer/Application/res/values/template-dimens.xml b/samples/browseable/DataLayer/Application/res/values/template-dimens.xml
new file mode 100644
index 0000000..39e710b
--- /dev/null
+++ b/samples/browseable/DataLayer/Application/res/values/template-dimens.xml
@@ -0,0 +1,32 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Define standard dimensions to comply with Holo-style grids and rhythm. -->
+
+ <dimen name="margin_tiny">4dp</dimen>
+ <dimen name="margin_small">8dp</dimen>
+ <dimen name="margin_medium">16dp</dimen>
+ <dimen name="margin_large">32dp</dimen>
+ <dimen name="margin_huge">64dp</dimen>
+
+ <!-- Semantic definitions -->
+
+ <dimen name="horizontal_page_margin">@dimen/margin_medium</dimen>
+ <dimen name="vertical_page_margin">@dimen/margin_medium</dimen>
+
+</resources>
diff --git a/samples/browseable/DataLayer/Application/res/values/template-styles.xml b/samples/browseable/DataLayer/Application/res/values/template-styles.xml
new file mode 100644
index 0000000..6e7d593
--- /dev/null
+++ b/samples/browseable/DataLayer/Application/res/values/template-styles.xml
@@ -0,0 +1,42 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Activity themes -->
+
+ <style name="Theme.Base" parent="android:Theme.Light" />
+
+ <style name="Theme.Sample" parent="Theme.Base" />
+
+ <style name="AppTheme" parent="Theme.Sample" />
+ <!-- Widget styling -->
+
+ <style name="Widget" />
+
+ <style name="Widget.SampleMessage">
+ <item name="android:textAppearance">?android:textAppearanceMedium</item>
+ <item name="android:lineSpacingMultiplier">1.1</item>
+ </style>
+
+ <style name="Widget.SampleMessageTile">
+ <item name="android:background">@drawable/tile</item>
+ <item name="android:shadowColor">#7F000000</item>
+ <item name="android:shadowDy">-3.5</item>
+ <item name="android:shadowRadius">2</item>
+ </style>
+
+</resources>
diff --git a/samples/browseable/DataLayer/Application/src/com.example.android.common/activities/SampleActivityBase.java b/samples/browseable/DataLayer/Application/src/com.example.android.common/activities/SampleActivityBase.java
new file mode 100644
index 0000000..3228927
--- /dev/null
+++ b/samples/browseable/DataLayer/Application/src/com.example.android.common/activities/SampleActivityBase.java
@@ -0,0 +1,52 @@
+/*
+* Copyright 2013 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.common.activities;
+
+import android.os.Bundle;
+import android.support.v4.app.FragmentActivity;
+
+import com.example.android.common.logger.Log;
+import com.example.android.common.logger.LogWrapper;
+
+/**
+ * Base launcher activity, to handle most of the common plumbing for samples.
+ */
+public class SampleActivityBase extends FragmentActivity {
+
+ public static final String TAG = "SampleActivityBase";
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ initializeLogging();
+ }
+
+ /** Set up targets to receive log data */
+ public void initializeLogging() {
+ // Using Log, front-end to the logging chain, emulates android.util.log method signatures.
+ // Wraps Android's native log framework
+ LogWrapper logWrapper = new LogWrapper();
+ Log.setLogNode(logWrapper);
+
+ Log.i(TAG, "Ready");
+ }
+}
diff --git a/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/Log.java b/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/Log.java
new file mode 100644
index 0000000..17503c5
--- /dev/null
+++ b/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/Log.java
@@ -0,0 +1,236 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+/**
+ * Helper class for a list (or tree) of LoggerNodes.
+ *
+ * <p>When this is set as the head of the list,
+ * an instance of it can function as a drop-in replacement for {@link android.util.Log}.
+ * Most of the methods in this class server only to map a method call in Log to its equivalent
+ * in LogNode.</p>
+ */
+public class Log {
+ // Grabbing the native values from Android's native logging facilities,
+ // to make for easy migration and interop.
+ public static final int NONE = -1;
+ public static final int VERBOSE = android.util.Log.VERBOSE;
+ public static final int DEBUG = android.util.Log.DEBUG;
+ public static final int INFO = android.util.Log.INFO;
+ public static final int WARN = android.util.Log.WARN;
+ public static final int ERROR = android.util.Log.ERROR;
+ public static final int ASSERT = android.util.Log.ASSERT;
+
+ // Stores the beginning of the LogNode topology.
+ private static LogNode mLogNode;
+
+ /**
+ * Returns the next LogNode in the linked list.
+ */
+ public static LogNode getLogNode() {
+ return mLogNode;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to.
+ */
+ public static void setLogNode(LogNode node) {
+ mLogNode = node;
+ }
+
+ /**
+ * Instructs the LogNode to print the log data provided. Other LogNodes can
+ * be chained to the end of the LogNode as desired.
+ *
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void println(int priority, String tag, String msg, Throwable tr) {
+ if (mLogNode != null) {
+ mLogNode.println(priority, tag, msg, tr);
+ }
+ }
+
+ /**
+ * Instructs the LogNode to print the log data provided. Other LogNodes can
+ * be chained to the end of the LogNode as desired.
+ *
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ */
+ public static void println(int priority, String tag, String msg) {
+ println(priority, tag, msg, null);
+ }
+
+ /**
+ * Prints a message at VERBOSE priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void v(String tag, String msg, Throwable tr) {
+ println(VERBOSE, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at VERBOSE priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void v(String tag, String msg) {
+ v(tag, msg, null);
+ }
+
+
+ /**
+ * Prints a message at DEBUG priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void d(String tag, String msg, Throwable tr) {
+ println(DEBUG, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at DEBUG priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void d(String tag, String msg) {
+ d(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at INFO priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void i(String tag, String msg, Throwable tr) {
+ println(INFO, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at INFO priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void i(String tag, String msg) {
+ i(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void w(String tag, String msg, Throwable tr) {
+ println(WARN, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void w(String tag, String msg) {
+ w(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void w(String tag, Throwable tr) {
+ w(tag, null, tr);
+ }
+
+ /**
+ * Prints a message at ERROR priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void e(String tag, String msg, Throwable tr) {
+ println(ERROR, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at ERROR priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void e(String tag, String msg) {
+ e(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void wtf(String tag, String msg, Throwable tr) {
+ println(ASSERT, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void wtf(String tag, String msg) {
+ wtf(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void wtf(String tag, Throwable tr) {
+ wtf(tag, null, tr);
+ }
+}
diff --git a/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/LogFragment.java
new file mode 100644
index 0000000..b302acd
--- /dev/null
+++ b/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/LogFragment.java
@@ -0,0 +1,109 @@
+/*
+* Copyright 2013 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.
+*/
+/*
+ * Copyright 2013 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.common.logger;
+
+import android.graphics.Typeface;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ScrollView;
+
+/**
+ * Simple fraggment which contains a LogView and uses is to output log data it receives
+ * through the LogNode interface.
+ */
+public class LogFragment extends Fragment {
+
+ private LogView mLogView;
+ private ScrollView mScrollView;
+
+ public LogFragment() {}
+
+ public View inflateViews() {
+ mScrollView = new ScrollView(getActivity());
+ ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT);
+ mScrollView.setLayoutParams(scrollParams);
+
+ mLogView = new LogView(getActivity());
+ ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams);
+ logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
+ mLogView.setLayoutParams(logParams);
+ mLogView.setClickable(true);
+ mLogView.setFocusable(true);
+ mLogView.setTypeface(Typeface.MONOSPACE);
+
+ // Want to set padding as 16 dips, setPadding takes pixels. Hooray math!
+ int paddingDips = 16;
+ double scale = getResources().getDisplayMetrics().density;
+ int paddingPixels = (int) ((paddingDips * (scale)) + .5);
+ mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels);
+ mLogView.setCompoundDrawablePadding(paddingPixels);
+
+ mLogView.setGravity(Gravity.BOTTOM);
+ mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium);
+
+ mScrollView.addView(mLogView);
+ return mScrollView;
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+
+ View result = inflateViews();
+
+ mLogView.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {}
+
+ @Override
+ public void afterTextChanged(Editable s) {
+ mScrollView.fullScroll(ScrollView.FOCUS_DOWN);
+ }
+ });
+ return result;
+ }
+
+ public LogView getLogView() {
+ return mLogView;
+ }
+}
\ No newline at end of file
diff --git a/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/LogNode.java
new file mode 100644
index 0000000..bc37cab
--- /dev/null
+++ b/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/LogNode.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2012 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.common.logger;
+
+/**
+ * Basic interface for a logging system that can output to one or more targets.
+ * Note that in addition to classes that will output these logs in some format,
+ * one can also implement this interface over a filter and insert that in the chain,
+ * such that no targets further down see certain data, or see manipulated forms of the data.
+ * You could, for instance, write a "ToHtmlLoggerNode" that just converted all the log data
+ * it received to HTML and sent it along to the next node in the chain, without printing it
+ * anywhere.
+ */
+public interface LogNode {
+
+ /**
+ * Instructs first LogNode in the list to print the log data provided.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public void println(int priority, String tag, String msg, Throwable tr);
+
+}
diff --git a/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/LogView.java
new file mode 100644
index 0000000..c01542b
--- /dev/null
+++ b/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/LogView.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+import android.app.Activity;
+import android.content.Context;
+import android.util.*;
+import android.widget.TextView;
+
+/** Simple TextView which is used to output log data received through the LogNode interface.
+*/
+public class LogView extends TextView implements LogNode {
+
+ public LogView(Context context) {
+ super(context);
+ }
+
+ public LogView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public LogView(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ /**
+ * Formats the log data and prints it out to the LogView.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+
+
+ String priorityStr = null;
+
+ // For the purposes of this View, we want to print the priority as readable text.
+ switch(priority) {
+ case android.util.Log.VERBOSE:
+ priorityStr = "VERBOSE";
+ break;
+ case android.util.Log.DEBUG:
+ priorityStr = "DEBUG";
+ break;
+ case android.util.Log.INFO:
+ priorityStr = "INFO";
+ break;
+ case android.util.Log.WARN:
+ priorityStr = "WARN";
+ break;
+ case android.util.Log.ERROR:
+ priorityStr = "ERROR";
+ break;
+ case android.util.Log.ASSERT:
+ priorityStr = "ASSERT";
+ break;
+ default:
+ break;
+ }
+
+ // Handily, the Log class has a facility for converting a stack trace into a usable string.
+ String exceptionStr = null;
+ if (tr != null) {
+ exceptionStr = android.util.Log.getStackTraceString(tr);
+ }
+
+ // Take the priority, tag, message, and exception, and concatenate as necessary
+ // into one usable line of text.
+ final StringBuilder outputBuilder = new StringBuilder();
+
+ String delimiter = "\t";
+ appendIfNotNull(outputBuilder, priorityStr, delimiter);
+ appendIfNotNull(outputBuilder, tag, delimiter);
+ appendIfNotNull(outputBuilder, msg, delimiter);
+ appendIfNotNull(outputBuilder, exceptionStr, delimiter);
+
+ // In case this was originally called from an AsyncTask or some other off-UI thread,
+ // make sure the update occurs within the UI thread.
+ ((Activity) getContext()).runOnUiThread( (new Thread(new Runnable() {
+ @Override
+ public void run() {
+ // Display the text we just generated within the LogView.
+ appendToLog(outputBuilder.toString());
+ }
+ })));
+
+ if (mNext != null) {
+ mNext.println(priority, tag, msg, tr);
+ }
+ }
+
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+ /** Takes a string and adds to it, with a separator, if the bit to be added isn't null. Since
+ * the logger takes so many arguments that might be null, this method helps cut out some of the
+ * agonizing tedium of writing the same 3 lines over and over.
+ * @param source StringBuilder containing the text to append to.
+ * @param addStr The String to append
+ * @param delimiter The String to separate the source and appended strings. A tab or comma,
+ * for instance.
+ * @return The fully concatenated String as a StringBuilder
+ */
+ private StringBuilder appendIfNotNull(StringBuilder source, String addStr, String delimiter) {
+ if (addStr != null) {
+ if (addStr.length() == 0) {
+ delimiter = "";
+ }
+
+ return source.append(addStr).append(delimiter);
+ }
+ return source;
+ }
+
+ // The next LogNode in the chain.
+ LogNode mNext;
+
+ /** Outputs the string as a new line of log data in the LogView. */
+ public void appendToLog(String s) {
+ append("\n" + s);
+ }
+
+
+}
diff --git a/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/LogWrapper.java
new file mode 100644
index 0000000..16a9e7b
--- /dev/null
+++ b/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/LogWrapper.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2012 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.common.logger;
+
+import android.util.Log;
+
+/**
+ * Helper class which wraps Android's native Log utility in the Logger interface. This way
+ * normal DDMS output can be one of the many targets receiving and outputting logs simultaneously.
+ */
+public class LogWrapper implements LogNode {
+
+ // For piping: The next node to receive Log data after this one has done its work.
+ private LogNode mNext;
+
+ /**
+ * Returns the next LogNode in the linked list.
+ */
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to..
+ */
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+ /**
+ * Prints data out to the console using Android's native log mechanism.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+ // There actually are log methods that don't take a msg parameter. For now,
+ // if that's the case, just convert null to the empty string and move on.
+ String useMsg = msg;
+ if (useMsg == null) {
+ useMsg = "";
+ }
+
+ // If an exeption was provided, convert that exception to a usable string and attach
+ // it to the end of the msg method.
+ if (tr != null) {
+ msg += "\n" + Log.getStackTraceString(tr);
+ }
+
+ // This is functionally identical to Log.x(tag, useMsg);
+ // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg)
+ Log.println(priority, tag, useMsg);
+
+ // If this isn't the last node in the chain, move things along.
+ if (mNext != null) {
+ mNext.println(priority, tag, msg, tr);
+ }
+ }
+}
diff --git a/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java
new file mode 100644
index 0000000..19967dc
--- /dev/null
+++ b/samples/browseable/DataLayer/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+/**
+ * Simple {@link LogNode} filter, removes everything except the message.
+ * Useful for situations like on-screen log output where you don't want a lot of metadata displayed,
+ * just easy-to-read message updates as they're happening.
+ */
+public class MessageOnlyLogFilter implements LogNode {
+
+ LogNode mNext;
+
+ /**
+ * Takes the "next" LogNode as a parameter, to simplify chaining.
+ *
+ * @param next The next LogNode in the pipeline.
+ */
+ public MessageOnlyLogFilter(LogNode next) {
+ mNext = next;
+ }
+
+ public MessageOnlyLogFilter() {
+ }
+
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+ if (mNext != null) {
+ getNext().println(Log.NONE, null, msg, null);
+ }
+ }
+
+ /**
+ * Returns the next LogNode in the chain.
+ */
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to..
+ */
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+}
diff --git a/samples/browseable/DataLayer/Application/src/com.example.android.datalayer/MainActivity.java b/samples/browseable/DataLayer/Application/src/com.example.android.datalayer/MainActivity.java
new file mode 100644
index 0000000..d94261d
--- /dev/null
+++ b/samples/browseable/DataLayer/Application/src/com.example.android.datalayer/MainActivity.java
@@ -0,0 +1,484 @@
+/*
+ * 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.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<DataEvent> 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<Event> {
+
+ 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<String> getNodes() {
+ HashSet<String> results = new HashSet<String>();
+ 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<SendMessageResult>() {
+ @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<Void, Void, Void> {
+
+ @Override
+ protected Void doInBackground(Void... args) {
+ Collection<String> 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<DataItemResult>() {
+ @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<DataItemResult>() {
+ @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/browseable/DataLayer/Shared/AndroidManifest.xml b/samples/browseable/DataLayer/Shared/AndroidManifest.xml
new file mode 100644
index 0000000..b7d03bf
--- /dev/null
+++ b/samples/browseable/DataLayer/Shared/AndroidManifest.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.datalayer.common">
+
+ <application android:allowBackup="true"
+ android:label="@string/app_name">
+ </application>
+
+</manifest>
diff --git a/samples/browseable/DataLayer/Shared/res/values/strings.xml b/samples/browseable/DataLayer/Shared/res/values/strings.xml
new file mode 100644
index 0000000..0f2bb90
--- /dev/null
+++ b/samples/browseable/DataLayer/Shared/res/values/strings.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<resources>
+ <string name="app_name">Shared</string>
+</resources>
diff --git a/samples/browseable/DataLayer/Wearable/AndroidManifest.xml b/samples/browseable/DataLayer/Wearable/AndroidManifest.xml
new file mode 100644
index 0000000..7bde39a
--- /dev/null
+++ b/samples/browseable/DataLayer/Wearable/AndroidManifest.xml
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.datalayer" >
+
+ <uses-sdk android:minSdkVersion="20"
+ android:targetSdkVersion="20" />
+
+ <uses-feature android:name="android.hardware.type.watch" />
+
+ <application
+ android:allowBackup="true"
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name"
+ android:theme="@android:style/Theme.DeviceDefault">
+
+ <meta-data
+ android:name="com.google.android.gms.version"
+ android:value="@integer/google_play_services_version" />
+
+ <service
+ android:name=".DataLayerListenerService" >
+ <intent-filter>
+ <action android:name="com.google.android.gms.wearable.BIND_LISTENER" />
+ </intent-filter>
+ </service>
+
+ <activity
+ android:name=".MainActivity"
+ android:label="@string/app_name">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ <intent-filter>
+ <action android:name="com.example.android.datalayer.EXAMPLE"/>
+ <category android:name="android.intent.category.DEFAULT"/>
+ </intent-filter>
+ </activity>
+ </application>
+</manifest>
diff --git a/samples/browseable/DataLayer/Wearable/res/drawable-hdpi/ic_launcher.png b/samples/browseable/DataLayer/Wearable/res/drawable-hdpi/ic_launcher.png
new file mode 100755
index 0000000..589f229
--- /dev/null
+++ b/samples/browseable/DataLayer/Wearable/res/drawable-hdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/DataLayer/Wearable/res/drawable-mdpi/ic_launcher.png b/samples/browseable/DataLayer/Wearable/res/drawable-mdpi/ic_launcher.png
new file mode 100755
index 0000000..77dd571
--- /dev/null
+++ b/samples/browseable/DataLayer/Wearable/res/drawable-mdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/DataLayer/Wearable/res/drawable-xhdpi/ic_launcher.png b/samples/browseable/DataLayer/Wearable/res/drawable-xhdpi/ic_launcher.png
new file mode 100755
index 0000000..fe34ebe
--- /dev/null
+++ b/samples/browseable/DataLayer/Wearable/res/drawable-xhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/DataLayer/Wearable/res/drawable-xxhdpi/ic_launcher.png b/samples/browseable/DataLayer/Wearable/res/drawable-xxhdpi/ic_launcher.png
new file mode 100755
index 0000000..ab80bcd
--- /dev/null
+++ b/samples/browseable/DataLayer/Wearable/res/drawable-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/DataLayer/Wearable/res/layout/main_activity.xml b/samples/browseable/DataLayer/Wearable/res/layout/main_activity.xml
new file mode 100644
index 0000000..f98e667
--- /dev/null
+++ b/samples/browseable/DataLayer/Wearable/res/layout/main_activity.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/layout"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+
+ <ListView
+ android:id="@+id/dataItem_list"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:transcriptMode="alwaysScroll"/>
+
+ <TextView
+ android:id="@+id/intro"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_centerInParent="true"
+ android:textSize="20sp"
+ android:layout_marginLeft="16dp"
+ android:layout_marginRight="16dp"
+ android:gravity="center"
+ android:fontFamily="sans-serif-condensed-light"
+ android:text="@string/intro" />
+</RelativeLayout>
diff --git a/samples/browseable/DataLayer/Wearable/res/values/strings.xml b/samples/browseable/DataLayer/Wearable/res/values/strings.xml
new file mode 100644
index 0000000..331e736
--- /dev/null
+++ b/samples/browseable/DataLayer/Wearable/res/values/strings.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <string name="app_name">Data Layer Sample Wearable App</string>
+ <string name="intro">Waiting for data to arrive\u2026</string>
+</resources>
diff --git a/samples/browseable/DataLayer/Wearable/src/com.example.android.datalayer/DataLayerListenerService.java b/samples/browseable/DataLayer/Wearable/src/com.example.android.datalayer/DataLayerListenerService.java
new file mode 100644
index 0000000..9356f39
--- /dev/null
+++ b/samples/browseable/DataLayer/Wearable/src/com.example.android.datalayer/DataLayerListenerService.java
@@ -0,0 +1,120 @@
+/*
+ * 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.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<DataEvent> 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/browseable/DataLayer/Wearable/src/com.example.android.datalayer/MainActivity.java b/samples/browseable/DataLayer/Wearable/src/com.example.android.datalayer/MainActivity.java
new file mode 100644
index 0000000..5f763b8
--- /dev/null
+++ b/samples/browseable/DataLayer/Wearable/src/com.example.android.datalayer/MainActivity.java
@@ -0,0 +1,255 @@
+/*
+ * 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.datalayer;
+
+import static com.example.android.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<DataEvent> 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<Event> {
+
+ 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/browseable/DataLayer/_index.jd b/samples/browseable/DataLayer/_index.jd
new file mode 100644
index 0000000..bab98d6
--- /dev/null
+++ b/samples/browseable/DataLayer/_index.jd
@@ -0,0 +1,11 @@
+page.tags="DataLayer"
+sample.group=Wearable
+@jd:body
+
+<p>
+
+ You can cause the wearable to start an activity by pressing a button in the
+ companion app UI. You can also take a picture on the companion device, which will be transmitted as
+ an Asset for display on the wearable.
+
+ </p>
diff --git a/samples/browseable/DelayedConfirmation/Application/AndroidManifest.xml b/samples/browseable/DelayedConfirmation/Application/AndroidManifest.xml
new file mode 100644
index 0000000..115ebec
--- /dev/null
+++ b/samples/browseable/DelayedConfirmation/Application/AndroidManifest.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.delayedconfirmation" >
+
+ <uses-sdk android:minSdkVersion="19"
+ android:targetSdkVersion="19" />
+
+ <application
+ android:allowBackup="true"
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name">
+
+ <meta-data
+ android:name="com.google.android.gms.version"
+ android:value="@integer/google_play_services_version" />
+
+ <activity
+ android:name=".MainActivity"
+ android:label="@string/app_name"
+ android:launchMode="singleTask" >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+</manifest>
diff --git a/samples/browseable/DelayedConfirmation/Application/res/drawable-hdpi/ic_launcher.png b/samples/browseable/DelayedConfirmation/Application/res/drawable-hdpi/ic_launcher.png
new file mode 100755
index 0000000..589f229
--- /dev/null
+++ b/samples/browseable/DelayedConfirmation/Application/res/drawable-hdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/DelayedConfirmation/Application/res/drawable-hdpi/tile.9.png b/samples/browseable/DelayedConfirmation/Application/res/drawable-hdpi/tile.9.png
new file mode 100644
index 0000000..1358628
--- /dev/null
+++ b/samples/browseable/DelayedConfirmation/Application/res/drawable-hdpi/tile.9.png
Binary files differ
diff --git a/samples/browseable/DelayedConfirmation/Application/res/drawable-mdpi/ic_launcher.png b/samples/browseable/DelayedConfirmation/Application/res/drawable-mdpi/ic_launcher.png
new file mode 100755
index 0000000..77dd571
--- /dev/null
+++ b/samples/browseable/DelayedConfirmation/Application/res/drawable-mdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/DelayedConfirmation/Application/res/drawable-xhdpi/ic_launcher.png b/samples/browseable/DelayedConfirmation/Application/res/drawable-xhdpi/ic_launcher.png
new file mode 100755
index 0000000..fe34ebe
--- /dev/null
+++ b/samples/browseable/DelayedConfirmation/Application/res/drawable-xhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/DelayedConfirmation/Application/res/drawable-xxhdpi/ic_launcher.png b/samples/browseable/DelayedConfirmation/Application/res/drawable-xxhdpi/ic_launcher.png
new file mode 100755
index 0000000..ab80bcd
--- /dev/null
+++ b/samples/browseable/DelayedConfirmation/Application/res/drawable-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/DelayedConfirmation/Application/res/layout/activity_main.xml b/samples/browseable/DelayedConfirmation/Application/res/layout/activity_main.xml
new file mode 100755
index 0000000..be1aa49
--- /dev/null
+++ b/samples/browseable/DelayedConfirmation/Application/res/layout/activity_main.xml
@@ -0,0 +1,36 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <LinearLayout style="@style/Widget.SampleMessageTile"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+
+ <TextView style="@style/Widget.SampleMessage"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="@dimen/horizontal_page_margin"
+ android:layout_marginRight="@dimen/horizontal_page_margin"
+ android:layout_marginTop="@dimen/vertical_page_margin"
+ android:layout_marginBottom="@dimen/vertical_page_margin"
+ android:text="@string/intro_message" />
+ </LinearLayout>
+</LinearLayout>
diff --git a/samples/browseable/DelayedConfirmation/Application/res/layout/main_activity.xml b/samples/browseable/DelayedConfirmation/Application/res/layout/main_activity.xml
new file mode 100644
index 0000000..cbc1874
--- /dev/null
+++ b/samples/browseable/DelayedConfirmation/Application/res/layout/main_activity.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="horizontal">
+ <TextView
+ android:id="@+id/text_start_wearable_activity"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textSize="20sp"
+ android:text="@string/start_wearable_activity" />
+ <Button
+ android:id="@+id/start_wearable_activity"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:minWidth="150dp"
+ android:onClick="onStartWearableActivityClick"
+ android:text="@string/start"/>
+</LinearLayout>
diff --git a/samples/browseable/DelayedConfirmation/Application/res/values-sw600dp/template-dimens.xml b/samples/browseable/DelayedConfirmation/Application/res/values-sw600dp/template-dimens.xml
new file mode 100644
index 0000000..22074a2
--- /dev/null
+++ b/samples/browseable/DelayedConfirmation/Application/res/values-sw600dp/template-dimens.xml
@@ -0,0 +1,24 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Semantic definitions -->
+
+ <dimen name="horizontal_page_margin">@dimen/margin_huge</dimen>
+ <dimen name="vertical_page_margin">@dimen/margin_medium</dimen>
+
+</resources>
diff --git a/samples/browseable/DelayedConfirmation/Application/res/values-sw600dp/template-styles.xml b/samples/browseable/DelayedConfirmation/Application/res/values-sw600dp/template-styles.xml
new file mode 100644
index 0000000..03d1974
--- /dev/null
+++ b/samples/browseable/DelayedConfirmation/Application/res/values-sw600dp/template-styles.xml
@@ -0,0 +1,25 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <style name="Widget.SampleMessage">
+ <item name="android:textAppearance">?android:textAppearanceLarge</item>
+ <item name="android:lineSpacingMultiplier">1.2</item>
+ <item name="android:shadowDy">-6.5</item>
+ </style>
+
+</resources>
diff --git a/samples/browseable/DelayedConfirmation/Application/res/values-v11/template-styles.xml b/samples/browseable/DelayedConfirmation/Application/res/values-v11/template-styles.xml
new file mode 100644
index 0000000..8c1ea66
--- /dev/null
+++ b/samples/browseable/DelayedConfirmation/Application/res/values-v11/template-styles.xml
@@ -0,0 +1,22 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Activity themes -->
+ <style name="Theme.Base" parent="android:Theme.Holo.Light" />
+
+</resources>
diff --git a/samples/browseable/DelayedConfirmation/Application/res/values/base-strings.xml b/samples/browseable/DelayedConfirmation/Application/res/values/base-strings.xml
new file mode 100644
index 0000000..b4e1a2e
--- /dev/null
+++ b/samples/browseable/DelayedConfirmation/Application/res/values/base-strings.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 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.
+-->
+<resources>
+ <string name="app_name">DelayedConfirmation</string>
+ <string name="intro_message">
+ <![CDATA[
+
+
+ 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. The activity on the wearable uses BoxInsetLayout to automatically apply
+ appropriate margins based on whether the display is square or circular.
+
+
+ ]]>
+ </string>
+</resources>
diff --git a/samples/browseable/DelayedConfirmation/Application/res/values/strings.xml b/samples/browseable/DelayedConfirmation/Application/res/values/strings.xml
new file mode 100644
index 0000000..1708705
--- /dev/null
+++ b/samples/browseable/DelayedConfirmation/Application/res/values/strings.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <string name="start_wearable_activity">Start Wearable Activity</string>
+ <string name="start">Start</string>
+
+ <string name="toast_timer_selected">Timer Selected</string>
+ <string name="toast_timer_finished">Timer Finished</string>
+</resources>
diff --git a/samples/browseable/DelayedConfirmation/Application/res/values/template-dimens.xml b/samples/browseable/DelayedConfirmation/Application/res/values/template-dimens.xml
new file mode 100644
index 0000000..39e710b
--- /dev/null
+++ b/samples/browseable/DelayedConfirmation/Application/res/values/template-dimens.xml
@@ -0,0 +1,32 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Define standard dimensions to comply with Holo-style grids and rhythm. -->
+
+ <dimen name="margin_tiny">4dp</dimen>
+ <dimen name="margin_small">8dp</dimen>
+ <dimen name="margin_medium">16dp</dimen>
+ <dimen name="margin_large">32dp</dimen>
+ <dimen name="margin_huge">64dp</dimen>
+
+ <!-- Semantic definitions -->
+
+ <dimen name="horizontal_page_margin">@dimen/margin_medium</dimen>
+ <dimen name="vertical_page_margin">@dimen/margin_medium</dimen>
+
+</resources>
diff --git a/samples/browseable/DelayedConfirmation/Application/res/values/template-styles.xml b/samples/browseable/DelayedConfirmation/Application/res/values/template-styles.xml
new file mode 100644
index 0000000..6e7d593
--- /dev/null
+++ b/samples/browseable/DelayedConfirmation/Application/res/values/template-styles.xml
@@ -0,0 +1,42 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Activity themes -->
+
+ <style name="Theme.Base" parent="android:Theme.Light" />
+
+ <style name="Theme.Sample" parent="Theme.Base" />
+
+ <style name="AppTheme" parent="Theme.Sample" />
+ <!-- Widget styling -->
+
+ <style name="Widget" />
+
+ <style name="Widget.SampleMessage">
+ <item name="android:textAppearance">?android:textAppearanceMedium</item>
+ <item name="android:lineSpacingMultiplier">1.1</item>
+ </style>
+
+ <style name="Widget.SampleMessageTile">
+ <item name="android:background">@drawable/tile</item>
+ <item name="android:shadowColor">#7F000000</item>
+ <item name="android:shadowDy">-3.5</item>
+ <item name="android:shadowRadius">2</item>
+ </style>
+
+</resources>
diff --git a/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/activities/SampleActivityBase.java b/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/activities/SampleActivityBase.java
new file mode 100644
index 0000000..3228927
--- /dev/null
+++ b/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/activities/SampleActivityBase.java
@@ -0,0 +1,52 @@
+/*
+* Copyright 2013 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.common.activities;
+
+import android.os.Bundle;
+import android.support.v4.app.FragmentActivity;
+
+import com.example.android.common.logger.Log;
+import com.example.android.common.logger.LogWrapper;
+
+/**
+ * Base launcher activity, to handle most of the common plumbing for samples.
+ */
+public class SampleActivityBase extends FragmentActivity {
+
+ public static final String TAG = "SampleActivityBase";
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ initializeLogging();
+ }
+
+ /** Set up targets to receive log data */
+ public void initializeLogging() {
+ // Using Log, front-end to the logging chain, emulates android.util.log method signatures.
+ // Wraps Android's native log framework
+ LogWrapper logWrapper = new LogWrapper();
+ Log.setLogNode(logWrapper);
+
+ Log.i(TAG, "Ready");
+ }
+}
diff --git a/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/Log.java b/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/Log.java
new file mode 100644
index 0000000..17503c5
--- /dev/null
+++ b/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/Log.java
@@ -0,0 +1,236 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+/**
+ * Helper class for a list (or tree) of LoggerNodes.
+ *
+ * <p>When this is set as the head of the list,
+ * an instance of it can function as a drop-in replacement for {@link android.util.Log}.
+ * Most of the methods in this class server only to map a method call in Log to its equivalent
+ * in LogNode.</p>
+ */
+public class Log {
+ // Grabbing the native values from Android's native logging facilities,
+ // to make for easy migration and interop.
+ public static final int NONE = -1;
+ public static final int VERBOSE = android.util.Log.VERBOSE;
+ public static final int DEBUG = android.util.Log.DEBUG;
+ public static final int INFO = android.util.Log.INFO;
+ public static final int WARN = android.util.Log.WARN;
+ public static final int ERROR = android.util.Log.ERROR;
+ public static final int ASSERT = android.util.Log.ASSERT;
+
+ // Stores the beginning of the LogNode topology.
+ private static LogNode mLogNode;
+
+ /**
+ * Returns the next LogNode in the linked list.
+ */
+ public static LogNode getLogNode() {
+ return mLogNode;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to.
+ */
+ public static void setLogNode(LogNode node) {
+ mLogNode = node;
+ }
+
+ /**
+ * Instructs the LogNode to print the log data provided. Other LogNodes can
+ * be chained to the end of the LogNode as desired.
+ *
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void println(int priority, String tag, String msg, Throwable tr) {
+ if (mLogNode != null) {
+ mLogNode.println(priority, tag, msg, tr);
+ }
+ }
+
+ /**
+ * Instructs the LogNode to print the log data provided. Other LogNodes can
+ * be chained to the end of the LogNode as desired.
+ *
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ */
+ public static void println(int priority, String tag, String msg) {
+ println(priority, tag, msg, null);
+ }
+
+ /**
+ * Prints a message at VERBOSE priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void v(String tag, String msg, Throwable tr) {
+ println(VERBOSE, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at VERBOSE priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void v(String tag, String msg) {
+ v(tag, msg, null);
+ }
+
+
+ /**
+ * Prints a message at DEBUG priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void d(String tag, String msg, Throwable tr) {
+ println(DEBUG, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at DEBUG priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void d(String tag, String msg) {
+ d(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at INFO priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void i(String tag, String msg, Throwable tr) {
+ println(INFO, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at INFO priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void i(String tag, String msg) {
+ i(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void w(String tag, String msg, Throwable tr) {
+ println(WARN, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void w(String tag, String msg) {
+ w(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void w(String tag, Throwable tr) {
+ w(tag, null, tr);
+ }
+
+ /**
+ * Prints a message at ERROR priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void e(String tag, String msg, Throwable tr) {
+ println(ERROR, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at ERROR priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void e(String tag, String msg) {
+ e(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void wtf(String tag, String msg, Throwable tr) {
+ println(ASSERT, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void wtf(String tag, String msg) {
+ wtf(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void wtf(String tag, Throwable tr) {
+ wtf(tag, null, tr);
+ }
+}
diff --git a/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/LogFragment.java
new file mode 100644
index 0000000..b302acd
--- /dev/null
+++ b/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/LogFragment.java
@@ -0,0 +1,109 @@
+/*
+* Copyright 2013 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.
+*/
+/*
+ * Copyright 2013 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.common.logger;
+
+import android.graphics.Typeface;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ScrollView;
+
+/**
+ * Simple fraggment which contains a LogView and uses is to output log data it receives
+ * through the LogNode interface.
+ */
+public class LogFragment extends Fragment {
+
+ private LogView mLogView;
+ private ScrollView mScrollView;
+
+ public LogFragment() {}
+
+ public View inflateViews() {
+ mScrollView = new ScrollView(getActivity());
+ ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT);
+ mScrollView.setLayoutParams(scrollParams);
+
+ mLogView = new LogView(getActivity());
+ ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams);
+ logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
+ mLogView.setLayoutParams(logParams);
+ mLogView.setClickable(true);
+ mLogView.setFocusable(true);
+ mLogView.setTypeface(Typeface.MONOSPACE);
+
+ // Want to set padding as 16 dips, setPadding takes pixels. Hooray math!
+ int paddingDips = 16;
+ double scale = getResources().getDisplayMetrics().density;
+ int paddingPixels = (int) ((paddingDips * (scale)) + .5);
+ mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels);
+ mLogView.setCompoundDrawablePadding(paddingPixels);
+
+ mLogView.setGravity(Gravity.BOTTOM);
+ mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium);
+
+ mScrollView.addView(mLogView);
+ return mScrollView;
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+
+ View result = inflateViews();
+
+ mLogView.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {}
+
+ @Override
+ public void afterTextChanged(Editable s) {
+ mScrollView.fullScroll(ScrollView.FOCUS_DOWN);
+ }
+ });
+ return result;
+ }
+
+ public LogView getLogView() {
+ return mLogView;
+ }
+}
\ No newline at end of file
diff --git a/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/LogNode.java
new file mode 100644
index 0000000..bc37cab
--- /dev/null
+++ b/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/LogNode.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2012 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.common.logger;
+
+/**
+ * Basic interface for a logging system that can output to one or more targets.
+ * Note that in addition to classes that will output these logs in some format,
+ * one can also implement this interface over a filter and insert that in the chain,
+ * such that no targets further down see certain data, or see manipulated forms of the data.
+ * You could, for instance, write a "ToHtmlLoggerNode" that just converted all the log data
+ * it received to HTML and sent it along to the next node in the chain, without printing it
+ * anywhere.
+ */
+public interface LogNode {
+
+ /**
+ * Instructs first LogNode in the list to print the log data provided.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public void println(int priority, String tag, String msg, Throwable tr);
+
+}
diff --git a/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/LogView.java
new file mode 100644
index 0000000..c01542b
--- /dev/null
+++ b/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/LogView.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+import android.app.Activity;
+import android.content.Context;
+import android.util.*;
+import android.widget.TextView;
+
+/** Simple TextView which is used to output log data received through the LogNode interface.
+*/
+public class LogView extends TextView implements LogNode {
+
+ public LogView(Context context) {
+ super(context);
+ }
+
+ public LogView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public LogView(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ /**
+ * Formats the log data and prints it out to the LogView.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+
+
+ String priorityStr = null;
+
+ // For the purposes of this View, we want to print the priority as readable text.
+ switch(priority) {
+ case android.util.Log.VERBOSE:
+ priorityStr = "VERBOSE";
+ break;
+ case android.util.Log.DEBUG:
+ priorityStr = "DEBUG";
+ break;
+ case android.util.Log.INFO:
+ priorityStr = "INFO";
+ break;
+ case android.util.Log.WARN:
+ priorityStr = "WARN";
+ break;
+ case android.util.Log.ERROR:
+ priorityStr = "ERROR";
+ break;
+ case android.util.Log.ASSERT:
+ priorityStr = "ASSERT";
+ break;
+ default:
+ break;
+ }
+
+ // Handily, the Log class has a facility for converting a stack trace into a usable string.
+ String exceptionStr = null;
+ if (tr != null) {
+ exceptionStr = android.util.Log.getStackTraceString(tr);
+ }
+
+ // Take the priority, tag, message, and exception, and concatenate as necessary
+ // into one usable line of text.
+ final StringBuilder outputBuilder = new StringBuilder();
+
+ String delimiter = "\t";
+ appendIfNotNull(outputBuilder, priorityStr, delimiter);
+ appendIfNotNull(outputBuilder, tag, delimiter);
+ appendIfNotNull(outputBuilder, msg, delimiter);
+ appendIfNotNull(outputBuilder, exceptionStr, delimiter);
+
+ // In case this was originally called from an AsyncTask or some other off-UI thread,
+ // make sure the update occurs within the UI thread.
+ ((Activity) getContext()).runOnUiThread( (new Thread(new Runnable() {
+ @Override
+ public void run() {
+ // Display the text we just generated within the LogView.
+ appendToLog(outputBuilder.toString());
+ }
+ })));
+
+ if (mNext != null) {
+ mNext.println(priority, tag, msg, tr);
+ }
+ }
+
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+ /** Takes a string and adds to it, with a separator, if the bit to be added isn't null. Since
+ * the logger takes so many arguments that might be null, this method helps cut out some of the
+ * agonizing tedium of writing the same 3 lines over and over.
+ * @param source StringBuilder containing the text to append to.
+ * @param addStr The String to append
+ * @param delimiter The String to separate the source and appended strings. A tab or comma,
+ * for instance.
+ * @return The fully concatenated String as a StringBuilder
+ */
+ private StringBuilder appendIfNotNull(StringBuilder source, String addStr, String delimiter) {
+ if (addStr != null) {
+ if (addStr.length() == 0) {
+ delimiter = "";
+ }
+
+ return source.append(addStr).append(delimiter);
+ }
+ return source;
+ }
+
+ // The next LogNode in the chain.
+ LogNode mNext;
+
+ /** Outputs the string as a new line of log data in the LogView. */
+ public void appendToLog(String s) {
+ append("\n" + s);
+ }
+
+
+}
diff --git a/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/LogWrapper.java
new file mode 100644
index 0000000..16a9e7b
--- /dev/null
+++ b/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/LogWrapper.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2012 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.common.logger;
+
+import android.util.Log;
+
+/**
+ * Helper class which wraps Android's native Log utility in the Logger interface. This way
+ * normal DDMS output can be one of the many targets receiving and outputting logs simultaneously.
+ */
+public class LogWrapper implements LogNode {
+
+ // For piping: The next node to receive Log data after this one has done its work.
+ private LogNode mNext;
+
+ /**
+ * Returns the next LogNode in the linked list.
+ */
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to..
+ */
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+ /**
+ * Prints data out to the console using Android's native log mechanism.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+ // There actually are log methods that don't take a msg parameter. For now,
+ // if that's the case, just convert null to the empty string and move on.
+ String useMsg = msg;
+ if (useMsg == null) {
+ useMsg = "";
+ }
+
+ // If an exeption was provided, convert that exception to a usable string and attach
+ // it to the end of the msg method.
+ if (tr != null) {
+ msg += "\n" + Log.getStackTraceString(tr);
+ }
+
+ // This is functionally identical to Log.x(tag, useMsg);
+ // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg)
+ Log.println(priority, tag, useMsg);
+
+ // If this isn't the last node in the chain, move things along.
+ if (mNext != null) {
+ mNext.println(priority, tag, msg, tr);
+ }
+ }
+}
diff --git a/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java
new file mode 100644
index 0000000..19967dc
--- /dev/null
+++ b/samples/browseable/DelayedConfirmation/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+/**
+ * Simple {@link LogNode} filter, removes everything except the message.
+ * Useful for situations like on-screen log output where you don't want a lot of metadata displayed,
+ * just easy-to-read message updates as they're happening.
+ */
+public class MessageOnlyLogFilter implements LogNode {
+
+ LogNode mNext;
+
+ /**
+ * Takes the "next" LogNode as a parameter, to simplify chaining.
+ *
+ * @param next The next LogNode in the pipeline.
+ */
+ public MessageOnlyLogFilter(LogNode next) {
+ mNext = next;
+ }
+
+ public MessageOnlyLogFilter() {
+ }
+
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+ if (mNext != null) {
+ getNext().println(Log.NONE, null, msg, null);
+ }
+ }
+
+ /**
+ * Returns the next LogNode in the chain.
+ */
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to..
+ */
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+}
diff --git a/samples/browseable/DelayedConfirmation/Application/src/com.example.android.delayedconfirmation/MainActivity.java b/samples/browseable/DelayedConfirmation/Application/src/com.example.android.delayedconfirmation/MainActivity.java
new file mode 100644
index 0000000..6fe681f
--- /dev/null
+++ b/samples/browseable/DelayedConfirmation/Application/src/com.example.android.delayedconfirmation/MainActivity.java
@@ -0,0 +1,134 @@
+/*
+ * 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.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<NodeApi.GetConnectedNodesResult>() {
+ @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<MessageApi.SendMessageResult> getSendMessageResultCallback() {
+ return new ResultCallback<MessageApi.SendMessageResult>() {
+ @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/browseable/DelayedConfirmation/Shared/AndroidManifest.xml b/samples/browseable/DelayedConfirmation/Shared/AndroidManifest.xml
new file mode 100644
index 0000000..2c9b669
--- /dev/null
+++ b/samples/browseable/DelayedConfirmation/Shared/AndroidManifest.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.delayedconfirmation.common">
+
+ <application android:allowBackup="true"
+ android:label="@string/app_name">
+ </application>
+
+</manifest>
diff --git a/samples/browseable/DelayedConfirmation/Shared/res/values/strings.xml b/samples/browseable/DelayedConfirmation/Shared/res/values/strings.xml
new file mode 100644
index 0000000..0f2bb90
--- /dev/null
+++ b/samples/browseable/DelayedConfirmation/Shared/res/values/strings.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<resources>
+ <string name="app_name">Shared</string>
+</resources>
diff --git a/samples/browseable/DelayedConfirmation/Wearable/AndroidManifest.xml b/samples/browseable/DelayedConfirmation/Wearable/AndroidManifest.xml
new file mode 100644
index 0000000..a220008
--- /dev/null
+++ b/samples/browseable/DelayedConfirmation/Wearable/AndroidManifest.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.delayedconfirmation" >
+
+ <uses-sdk android:minSdkVersion="20"
+ android:targetSdkVersion="20" />
+
+ <uses-feature android:name="android.hardware.type.watch" />
+
+ <application
+ android:allowBackup="true"
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name"
+ android:theme="@android:style/Theme.DeviceDefault">
+
+ <meta-data
+ android:name="com.google.android.gms.version"
+ android:value="@integer/google_play_services_version" />
+
+ <service
+ android:name=".WearableMessageListenerService" >
+ <intent-filter>
+ <action android:name="com.google.android.gms.wearable.BIND_LISTENER" />
+ </intent-filter>
+ </service>
+
+ <activity
+ android:name=".MainActivity"
+ android:label="@string/app_name">
+ </activity>
+ </application>
+</manifest>
diff --git a/samples/browseable/DelayedConfirmation/Wearable/res/drawable-hdpi/ic_launcher.png b/samples/browseable/DelayedConfirmation/Wearable/res/drawable-hdpi/ic_launcher.png
new file mode 100755
index 0000000..589f229
--- /dev/null
+++ b/samples/browseable/DelayedConfirmation/Wearable/res/drawable-hdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/DelayedConfirmation/Wearable/res/drawable-mdpi/ic_launcher.png b/samples/browseable/DelayedConfirmation/Wearable/res/drawable-mdpi/ic_launcher.png
new file mode 100755
index 0000000..77dd571
--- /dev/null
+++ b/samples/browseable/DelayedConfirmation/Wearable/res/drawable-mdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/DelayedConfirmation/Wearable/res/drawable-xhdpi/ic_launcher.png b/samples/browseable/DelayedConfirmation/Wearable/res/drawable-xhdpi/ic_launcher.png
new file mode 100755
index 0000000..fe34ebe
--- /dev/null
+++ b/samples/browseable/DelayedConfirmation/Wearable/res/drawable-xhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/DelayedConfirmation/Wearable/res/drawable-xxhdpi/ic_launcher.png b/samples/browseable/DelayedConfirmation/Wearable/res/drawable-xxhdpi/ic_launcher.png
new file mode 100755
index 0000000..ab80bcd
--- /dev/null
+++ b/samples/browseable/DelayedConfirmation/Wearable/res/drawable-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/DelayedConfirmation/Wearable/res/layout/main_activity.xml b/samples/browseable/DelayedConfirmation/Wearable/res/layout/main_activity.xml
new file mode 100644
index 0000000..1b9bcb3
--- /dev/null
+++ b/samples/browseable/DelayedConfirmation/Wearable/res/layout/main_activity.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<android.support.wearable.view.BoxInsetLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ android:layout_height="match_parent"
+ android:layout_width="match_parent">
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical"
+ android:background="@color/grey"
+ app:layout_box="top">
+
+ <Button
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:onClick="onStartTimer"
+ android:text="@string/start_timer"/>
+
+ <android.support.wearable.view.DelayedConfirmationView
+ android:id="@+id/delayed_confirmation"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:src="@drawable/ic_launcher"
+ app:circle_color="@color/blue"
+ app:circle_radius="@dimen/circle_radius"
+ app:circle_radius_pressed="@dimen/circle_radius_pressed"
+ app:circle_padding="@dimen/circle_padding"
+ app:circle_border_width="@dimen/circle_border_normal_width"
+ app:circle_border_color="@color/white"/>
+
+ </LinearLayout>
+</android.support.wearable.view.BoxInsetLayout>
diff --git a/samples/browseable/DelayedConfirmation/Wearable/res/values/dimens.xml b/samples/browseable/DelayedConfirmation/Wearable/res/values/dimens.xml
new file mode 100644
index 0000000..677a0f1
--- /dev/null
+++ b/samples/browseable/DelayedConfirmation/Wearable/res/values/dimens.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+ <dimen name="circle_border_normal_width">10dp</dimen>
+ <dimen name="circle_padding">5dp</dimen>
+ <dimen name="circle_radius">60dp</dimen>
+ <dimen name="circle_radius_pressed">55dp</dimen>
+</resources>
diff --git a/samples/browseable/DelayedConfirmation/Wearable/res/values/strings.xml b/samples/browseable/DelayedConfirmation/Wearable/res/values/strings.xml
new file mode 100644
index 0000000..46f5326
--- /dev/null
+++ b/samples/browseable/DelayedConfirmation/Wearable/res/values/strings.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+
+ <string name="app_name">Delayed Confirmation</string>
+ <string name="start_timer">Start Timer (5 seconds)</string>
+
+ <string name="notification_title">DelayedConfirmation</string>
+ <string name="notification_timer_selected">Timer Selected</string>
+ <string name="notification_timer_finished">Timer Finished</string>
+</resources>
diff --git a/samples/browseable/DelayedConfirmation/Wearable/src/com.example.android.delayedconfirmation/MainActivity.java b/samples/browseable/DelayedConfirmation/Wearable/src/com.example.android.delayedconfirmation/MainActivity.java
new file mode 100644
index 0000000..2e169c7
--- /dev/null
+++ b/samples/browseable/DelayedConfirmation/Wearable/src/com.example.android.delayedconfirmation/MainActivity.java
@@ -0,0 +1,143 @@
+/*
+ * 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.delayedconfirmation;
+
+import android.app.Activity;
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.os.Bundle;
+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 Notification.Builder(this)
+ .setSmallIcon(R.drawable.ic_launcher)
+ .setContentTitle(getString(R.string.notification_title))
+ .setContentText(getString(R.string.notification_timer_selected))
+ .build();
+ ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).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 Notification.Builder(this)
+ .setSmallIcon(R.drawable.ic_launcher)
+ .setContentTitle(getString(R.string.notification_title))
+ .setContentText(getString(R.string.notification_timer_finished))
+ .build();
+ ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).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<NodeApi.GetConnectedNodesResult>() {
+ @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<MessageApi.SendMessageResult> getSendMessageResultCallback() {
+ return new ResultCallback<MessageApi.SendMessageResult>() {
+ @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/browseable/DelayedConfirmation/Wearable/src/com.example.android.delayedconfirmation/WearableMessageListenerService.java b/samples/browseable/DelayedConfirmation/Wearable/src/com.example.android.delayedconfirmation/WearableMessageListenerService.java
new file mode 100644
index 0000000..0032fda
--- /dev/null
+++ b/samples/browseable/DelayedConfirmation/Wearable/src/com.example.android.delayedconfirmation/WearableMessageListenerService.java
@@ -0,0 +1,38 @@
+/*
+ * 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.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/browseable/DelayedConfirmation/_index.jd b/samples/browseable/DelayedConfirmation/_index.jd
new file mode 100644
index 0000000..28db25a
--- /dev/null
+++ b/samples/browseable/DelayedConfirmation/_index.jd
@@ -0,0 +1,14 @@
+page.tags="DelayedConfirmation"
+sample.group=Wearable
+@jd:body
+
+<p>
+
+ 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. The activity on the wearable uses BoxInsetLayout to automatically apply
+ appropriate margins based on whether the display is square or circular.
+
+ </p>
diff --git a/samples/browseable/ElizaChat/Application/AndroidManifest.xml b/samples/browseable/ElizaChat/Application/AndroidManifest.xml
new file mode 100644
index 0000000..e653fa9
--- /dev/null
+++ b/samples/browseable/ElizaChat/Application/AndroidManifest.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.elizachat" >
+
+ <uses-sdk android:minSdkVersion="19"
+ android:targetSdkVersion="19" />
+
+ <application
+ android:allowBackup="true"
+ android:icon="@mipmap/ic_app_eliza"
+ android:label="@string/app_name"
+ android:theme="@style/AppTheme" >
+ <activity
+ android:name=".MainActivity"
+ android:label="@string/app_name" >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ <service
+ android:name=".ResponderService">
+ <intent-filter>
+ <action android:name="com.example.android.elizachat.REPLY" />
+ <action android:name="com.example.android.elizachat.CONVERSATION" />
+ </intent-filter>
+ </service>
+ </application>
+
+</manifest>
diff --git a/samples/browseable/ElizaChat/Application/res/drawable-hdpi/ic_full_reply.png b/samples/browseable/ElizaChat/Application/res/drawable-hdpi/ic_full_reply.png
new file mode 100644
index 0000000..66388d5
--- /dev/null
+++ b/samples/browseable/ElizaChat/Application/res/drawable-hdpi/ic_full_reply.png
Binary files differ
diff --git a/samples/browseable/ElizaChat/Application/res/drawable-hdpi/tile.9.png b/samples/browseable/ElizaChat/Application/res/drawable-hdpi/tile.9.png
new file mode 100644
index 0000000..1358628
--- /dev/null
+++ b/samples/browseable/ElizaChat/Application/res/drawable-hdpi/tile.9.png
Binary files differ
diff --git a/samples/browseable/ElizaChat/Application/res/drawable-mdpi/ic_full_reply.png b/samples/browseable/ElizaChat/Application/res/drawable-mdpi/ic_full_reply.png
new file mode 100644
index 0000000..60ce9f9
--- /dev/null
+++ b/samples/browseable/ElizaChat/Application/res/drawable-mdpi/ic_full_reply.png
Binary files differ
diff --git a/samples/browseable/ElizaChat/Application/res/drawable-nodpi/bg_eliza.png b/samples/browseable/ElizaChat/Application/res/drawable-nodpi/bg_eliza.png
new file mode 100644
index 0000000..3bbdf48
--- /dev/null
+++ b/samples/browseable/ElizaChat/Application/res/drawable-nodpi/bg_eliza.png
Binary files differ
diff --git a/samples/browseable/ElizaChat/Application/res/drawable-xhdpi/ic_full_reply.png b/samples/browseable/ElizaChat/Application/res/drawable-xhdpi/ic_full_reply.png
new file mode 100644
index 0000000..dba6fa7
--- /dev/null
+++ b/samples/browseable/ElizaChat/Application/res/drawable-xhdpi/ic_full_reply.png
Binary files differ
diff --git a/samples/browseable/ElizaChat/Application/res/layout/activity_main.xml b/samples/browseable/ElizaChat/Application/res/layout/activity_main.xml
new file mode 100755
index 0000000..be1aa49
--- /dev/null
+++ b/samples/browseable/ElizaChat/Application/res/layout/activity_main.xml
@@ -0,0 +1,36 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <LinearLayout style="@style/Widget.SampleMessageTile"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+
+ <TextView style="@style/Widget.SampleMessage"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="@dimen/horizontal_page_margin"
+ android:layout_marginRight="@dimen/horizontal_page_margin"
+ android:layout_marginTop="@dimen/vertical_page_margin"
+ android:layout_marginBottom="@dimen/vertical_page_margin"
+ android:text="@string/intro_message" />
+ </LinearLayout>
+</LinearLayout>
diff --git a/samples/browseable/ElizaChat/Application/res/layout/main.xml b/samples/browseable/ElizaChat/Application/res/layout/main.xml
new file mode 100644
index 0000000..6ffed8e
--- /dev/null
+++ b/samples/browseable/ElizaChat/Application/res/layout/main.xml
@@ -0,0 +1,17 @@
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:paddingLeft="@dimen/activity_horizontal_margin"
+ android:paddingRight="@dimen/activity_horizontal_margin"
+ android:paddingTop="@dimen/activity_vertical_margin"
+ android:paddingBottom="@dimen/activity_vertical_margin"
+ tools:context="com.example.android.wearable.elizachat.MainActivity$PlaceholderFragment"
+ android:orientation="vertical" >
+
+ <TextView
+ android:id="@+id/history"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"/>
+
+</ScrollView>
diff --git a/samples/browseable/ElizaChat/Application/res/menu/main.xml b/samples/browseable/ElizaChat/Application/res/menu/main.xml
new file mode 100644
index 0000000..b8e1ef2
--- /dev/null
+++ b/samples/browseable/ElizaChat/Application/res/menu/main.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+ <item
+ android:id="@+id/action_stop_service"
+ android:orderInCategory="100"
+ android:showAsAction="always|withText"
+ android:title="@string/stop_service" />
+
+</menu>
diff --git a/samples/browseable/ElizaChat/Application/res/mipmap-hdpi/ic_app_eliza.png b/samples/browseable/ElizaChat/Application/res/mipmap-hdpi/ic_app_eliza.png
new file mode 100644
index 0000000..1bdb147
--- /dev/null
+++ b/samples/browseable/ElizaChat/Application/res/mipmap-hdpi/ic_app_eliza.png
Binary files differ
diff --git a/samples/browseable/ElizaChat/Application/res/mipmap-mdpi/ic_app_eliza.png b/samples/browseable/ElizaChat/Application/res/mipmap-mdpi/ic_app_eliza.png
new file mode 100644
index 0000000..2e0e198
--- /dev/null
+++ b/samples/browseable/ElizaChat/Application/res/mipmap-mdpi/ic_app_eliza.png
Binary files differ
diff --git a/samples/browseable/ElizaChat/Application/res/mipmap-xhdpi/ic_app_eliza.png b/samples/browseable/ElizaChat/Application/res/mipmap-xhdpi/ic_app_eliza.png
new file mode 100644
index 0000000..8d0f436
--- /dev/null
+++ b/samples/browseable/ElizaChat/Application/res/mipmap-xhdpi/ic_app_eliza.png
Binary files differ
diff --git a/samples/browseable/ElizaChat/Application/res/mipmap-xxhdpi/ic_app_eliza.png b/samples/browseable/ElizaChat/Application/res/mipmap-xxhdpi/ic_app_eliza.png
new file mode 100644
index 0000000..e72b967
--- /dev/null
+++ b/samples/browseable/ElizaChat/Application/res/mipmap-xxhdpi/ic_app_eliza.png
Binary files differ
diff --git a/samples/browseable/ElizaChat/Application/res/mipmap-xxxhdpi/ic_app_eliza.png b/samples/browseable/ElizaChat/Application/res/mipmap-xxxhdpi/ic_app_eliza.png
new file mode 100644
index 0000000..06ea079
--- /dev/null
+++ b/samples/browseable/ElizaChat/Application/res/mipmap-xxxhdpi/ic_app_eliza.png
Binary files differ
diff --git a/samples/browseable/ElizaChat/Application/res/values-sw600dp/template-dimens.xml b/samples/browseable/ElizaChat/Application/res/values-sw600dp/template-dimens.xml
new file mode 100644
index 0000000..22074a2
--- /dev/null
+++ b/samples/browseable/ElizaChat/Application/res/values-sw600dp/template-dimens.xml
@@ -0,0 +1,24 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Semantic definitions -->
+
+ <dimen name="horizontal_page_margin">@dimen/margin_huge</dimen>
+ <dimen name="vertical_page_margin">@dimen/margin_medium</dimen>
+
+</resources>
diff --git a/samples/browseable/ElizaChat/Application/res/values-sw600dp/template-styles.xml b/samples/browseable/ElizaChat/Application/res/values-sw600dp/template-styles.xml
new file mode 100644
index 0000000..03d1974
--- /dev/null
+++ b/samples/browseable/ElizaChat/Application/res/values-sw600dp/template-styles.xml
@@ -0,0 +1,25 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <style name="Widget.SampleMessage">
+ <item name="android:textAppearance">?android:textAppearanceLarge</item>
+ <item name="android:lineSpacingMultiplier">1.2</item>
+ <item name="android:shadowDy">-6.5</item>
+ </style>
+
+</resources>
diff --git a/samples/browseable/ElizaChat/Application/res/values-v11/template-styles.xml b/samples/browseable/ElizaChat/Application/res/values-v11/template-styles.xml
new file mode 100644
index 0000000..8c1ea66
--- /dev/null
+++ b/samples/browseable/ElizaChat/Application/res/values-v11/template-styles.xml
@@ -0,0 +1,22 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Activity themes -->
+ <style name="Theme.Base" parent="android:Theme.Holo.Light" />
+
+</resources>
diff --git a/samples/browseable/ElizaChat/Application/res/values/base-strings.xml b/samples/browseable/ElizaChat/Application/res/values/base-strings.xml
new file mode 100644
index 0000000..be29a5b
--- /dev/null
+++ b/samples/browseable/ElizaChat/Application/res/values/base-strings.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 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.
+-->
+<resources>
+ <string name="app_name">ElizaChat</string>
+ <string name="intro_message">
+ <![CDATA[
+
+
+ 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.
+
+
+ ]]>
+ </string>
+</resources>
diff --git a/samples/browseable/ElizaChat/Application/res/values/dimens.xml b/samples/browseable/ElizaChat/Application/res/values/dimens.xml
new file mode 100644
index 0000000..a1e9cfe
--- /dev/null
+++ b/samples/browseable/ElizaChat/Application/res/values/dimens.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+ <!-- Default screen margins, per the Android Design guidelines. -->
+ <dimen name="activity_horizontal_margin">16dp</dimen>
+ <dimen name="activity_vertical_margin">16dp</dimen>
+</resources>
diff --git a/samples/browseable/ElizaChat/Application/res/values/strings.xml b/samples/browseable/ElizaChat/Application/res/values/strings.xml
new file mode 100644
index 0000000..9a5c9d7
--- /dev/null
+++ b/samples/browseable/ElizaChat/Application/res/values/strings.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+
+ <string name="send_notification">Send notification!</string>
+ <string name="eliza">Eliza</string>
+ <string name="answer_eliza">Answer Eliza</string>
+ <string name="reply">Reply</string>
+ <string name="stop_service">End Chat Session</string>
+
+</resources>
diff --git a/samples/browseable/ElizaChat/Application/res/values/template-dimens.xml b/samples/browseable/ElizaChat/Application/res/values/template-dimens.xml
new file mode 100644
index 0000000..39e710b
--- /dev/null
+++ b/samples/browseable/ElizaChat/Application/res/values/template-dimens.xml
@@ -0,0 +1,32 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Define standard dimensions to comply with Holo-style grids and rhythm. -->
+
+ <dimen name="margin_tiny">4dp</dimen>
+ <dimen name="margin_small">8dp</dimen>
+ <dimen name="margin_medium">16dp</dimen>
+ <dimen name="margin_large">32dp</dimen>
+ <dimen name="margin_huge">64dp</dimen>
+
+ <!-- Semantic definitions -->
+
+ <dimen name="horizontal_page_margin">@dimen/margin_medium</dimen>
+ <dimen name="vertical_page_margin">@dimen/margin_medium</dimen>
+
+</resources>
diff --git a/samples/browseable/ElizaChat/Application/res/values/template-styles.xml b/samples/browseable/ElizaChat/Application/res/values/template-styles.xml
new file mode 100644
index 0000000..6e7d593
--- /dev/null
+++ b/samples/browseable/ElizaChat/Application/res/values/template-styles.xml
@@ -0,0 +1,42 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Activity themes -->
+
+ <style name="Theme.Base" parent="android:Theme.Light" />
+
+ <style name="Theme.Sample" parent="Theme.Base" />
+
+ <style name="AppTheme" parent="Theme.Sample" />
+ <!-- Widget styling -->
+
+ <style name="Widget" />
+
+ <style name="Widget.SampleMessage">
+ <item name="android:textAppearance">?android:textAppearanceMedium</item>
+ <item name="android:lineSpacingMultiplier">1.1</item>
+ </style>
+
+ <style name="Widget.SampleMessageTile">
+ <item name="android:background">@drawable/tile</item>
+ <item name="android:shadowColor">#7F000000</item>
+ <item name="android:shadowDy">-3.5</item>
+ <item name="android:shadowRadius">2</item>
+ </style>
+
+</resources>
diff --git a/samples/browseable/ElizaChat/Application/src/com.example.android.common/activities/SampleActivityBase.java b/samples/browseable/ElizaChat/Application/src/com.example.android.common/activities/SampleActivityBase.java
new file mode 100644
index 0000000..3228927
--- /dev/null
+++ b/samples/browseable/ElizaChat/Application/src/com.example.android.common/activities/SampleActivityBase.java
@@ -0,0 +1,52 @@
+/*
+* Copyright 2013 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.common.activities;
+
+import android.os.Bundle;
+import android.support.v4.app.FragmentActivity;
+
+import com.example.android.common.logger.Log;
+import com.example.android.common.logger.LogWrapper;
+
+/**
+ * Base launcher activity, to handle most of the common plumbing for samples.
+ */
+public class SampleActivityBase extends FragmentActivity {
+
+ public static final String TAG = "SampleActivityBase";
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ initializeLogging();
+ }
+
+ /** Set up targets to receive log data */
+ public void initializeLogging() {
+ // Using Log, front-end to the logging chain, emulates android.util.log method signatures.
+ // Wraps Android's native log framework
+ LogWrapper logWrapper = new LogWrapper();
+ Log.setLogNode(logWrapper);
+
+ Log.i(TAG, "Ready");
+ }
+}
diff --git a/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/Log.java b/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/Log.java
new file mode 100644
index 0000000..17503c5
--- /dev/null
+++ b/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/Log.java
@@ -0,0 +1,236 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+/**
+ * Helper class for a list (or tree) of LoggerNodes.
+ *
+ * <p>When this is set as the head of the list,
+ * an instance of it can function as a drop-in replacement for {@link android.util.Log}.
+ * Most of the methods in this class server only to map a method call in Log to its equivalent
+ * in LogNode.</p>
+ */
+public class Log {
+ // Grabbing the native values from Android's native logging facilities,
+ // to make for easy migration and interop.
+ public static final int NONE = -1;
+ public static final int VERBOSE = android.util.Log.VERBOSE;
+ public static final int DEBUG = android.util.Log.DEBUG;
+ public static final int INFO = android.util.Log.INFO;
+ public static final int WARN = android.util.Log.WARN;
+ public static final int ERROR = android.util.Log.ERROR;
+ public static final int ASSERT = android.util.Log.ASSERT;
+
+ // Stores the beginning of the LogNode topology.
+ private static LogNode mLogNode;
+
+ /**
+ * Returns the next LogNode in the linked list.
+ */
+ public static LogNode getLogNode() {
+ return mLogNode;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to.
+ */
+ public static void setLogNode(LogNode node) {
+ mLogNode = node;
+ }
+
+ /**
+ * Instructs the LogNode to print the log data provided. Other LogNodes can
+ * be chained to the end of the LogNode as desired.
+ *
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void println(int priority, String tag, String msg, Throwable tr) {
+ if (mLogNode != null) {
+ mLogNode.println(priority, tag, msg, tr);
+ }
+ }
+
+ /**
+ * Instructs the LogNode to print the log data provided. Other LogNodes can
+ * be chained to the end of the LogNode as desired.
+ *
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ */
+ public static void println(int priority, String tag, String msg) {
+ println(priority, tag, msg, null);
+ }
+
+ /**
+ * Prints a message at VERBOSE priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void v(String tag, String msg, Throwable tr) {
+ println(VERBOSE, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at VERBOSE priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void v(String tag, String msg) {
+ v(tag, msg, null);
+ }
+
+
+ /**
+ * Prints a message at DEBUG priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void d(String tag, String msg, Throwable tr) {
+ println(DEBUG, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at DEBUG priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void d(String tag, String msg) {
+ d(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at INFO priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void i(String tag, String msg, Throwable tr) {
+ println(INFO, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at INFO priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void i(String tag, String msg) {
+ i(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void w(String tag, String msg, Throwable tr) {
+ println(WARN, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void w(String tag, String msg) {
+ w(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void w(String tag, Throwable tr) {
+ w(tag, null, tr);
+ }
+
+ /**
+ * Prints a message at ERROR priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void e(String tag, String msg, Throwable tr) {
+ println(ERROR, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at ERROR priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void e(String tag, String msg) {
+ e(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void wtf(String tag, String msg, Throwable tr) {
+ println(ASSERT, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void wtf(String tag, String msg) {
+ wtf(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void wtf(String tag, Throwable tr) {
+ wtf(tag, null, tr);
+ }
+}
diff --git a/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/LogFragment.java
new file mode 100644
index 0000000..b302acd
--- /dev/null
+++ b/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/LogFragment.java
@@ -0,0 +1,109 @@
+/*
+* Copyright 2013 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.
+*/
+/*
+ * Copyright 2013 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.common.logger;
+
+import android.graphics.Typeface;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ScrollView;
+
+/**
+ * Simple fraggment which contains a LogView and uses is to output log data it receives
+ * through the LogNode interface.
+ */
+public class LogFragment extends Fragment {
+
+ private LogView mLogView;
+ private ScrollView mScrollView;
+
+ public LogFragment() {}
+
+ public View inflateViews() {
+ mScrollView = new ScrollView(getActivity());
+ ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT);
+ mScrollView.setLayoutParams(scrollParams);
+
+ mLogView = new LogView(getActivity());
+ ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams);
+ logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
+ mLogView.setLayoutParams(logParams);
+ mLogView.setClickable(true);
+ mLogView.setFocusable(true);
+ mLogView.setTypeface(Typeface.MONOSPACE);
+
+ // Want to set padding as 16 dips, setPadding takes pixels. Hooray math!
+ int paddingDips = 16;
+ double scale = getResources().getDisplayMetrics().density;
+ int paddingPixels = (int) ((paddingDips * (scale)) + .5);
+ mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels);
+ mLogView.setCompoundDrawablePadding(paddingPixels);
+
+ mLogView.setGravity(Gravity.BOTTOM);
+ mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium);
+
+ mScrollView.addView(mLogView);
+ return mScrollView;
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+
+ View result = inflateViews();
+
+ mLogView.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {}
+
+ @Override
+ public void afterTextChanged(Editable s) {
+ mScrollView.fullScroll(ScrollView.FOCUS_DOWN);
+ }
+ });
+ return result;
+ }
+
+ public LogView getLogView() {
+ return mLogView;
+ }
+}
\ No newline at end of file
diff --git a/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/LogNode.java
new file mode 100644
index 0000000..bc37cab
--- /dev/null
+++ b/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/LogNode.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2012 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.common.logger;
+
+/**
+ * Basic interface for a logging system that can output to one or more targets.
+ * Note that in addition to classes that will output these logs in some format,
+ * one can also implement this interface over a filter and insert that in the chain,
+ * such that no targets further down see certain data, or see manipulated forms of the data.
+ * You could, for instance, write a "ToHtmlLoggerNode" that just converted all the log data
+ * it received to HTML and sent it along to the next node in the chain, without printing it
+ * anywhere.
+ */
+public interface LogNode {
+
+ /**
+ * Instructs first LogNode in the list to print the log data provided.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public void println(int priority, String tag, String msg, Throwable tr);
+
+}
diff --git a/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/LogView.java
new file mode 100644
index 0000000..c01542b
--- /dev/null
+++ b/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/LogView.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+import android.app.Activity;
+import android.content.Context;
+import android.util.*;
+import android.widget.TextView;
+
+/** Simple TextView which is used to output log data received through the LogNode interface.
+*/
+public class LogView extends TextView implements LogNode {
+
+ public LogView(Context context) {
+ super(context);
+ }
+
+ public LogView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public LogView(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ /**
+ * Formats the log data and prints it out to the LogView.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+
+
+ String priorityStr = null;
+
+ // For the purposes of this View, we want to print the priority as readable text.
+ switch(priority) {
+ case android.util.Log.VERBOSE:
+ priorityStr = "VERBOSE";
+ break;
+ case android.util.Log.DEBUG:
+ priorityStr = "DEBUG";
+ break;
+ case android.util.Log.INFO:
+ priorityStr = "INFO";
+ break;
+ case android.util.Log.WARN:
+ priorityStr = "WARN";
+ break;
+ case android.util.Log.ERROR:
+ priorityStr = "ERROR";
+ break;
+ case android.util.Log.ASSERT:
+ priorityStr = "ASSERT";
+ break;
+ default:
+ break;
+ }
+
+ // Handily, the Log class has a facility for converting a stack trace into a usable string.
+ String exceptionStr = null;
+ if (tr != null) {
+ exceptionStr = android.util.Log.getStackTraceString(tr);
+ }
+
+ // Take the priority, tag, message, and exception, and concatenate as necessary
+ // into one usable line of text.
+ final StringBuilder outputBuilder = new StringBuilder();
+
+ String delimiter = "\t";
+ appendIfNotNull(outputBuilder, priorityStr, delimiter);
+ appendIfNotNull(outputBuilder, tag, delimiter);
+ appendIfNotNull(outputBuilder, msg, delimiter);
+ appendIfNotNull(outputBuilder, exceptionStr, delimiter);
+
+ // In case this was originally called from an AsyncTask or some other off-UI thread,
+ // make sure the update occurs within the UI thread.
+ ((Activity) getContext()).runOnUiThread( (new Thread(new Runnable() {
+ @Override
+ public void run() {
+ // Display the text we just generated within the LogView.
+ appendToLog(outputBuilder.toString());
+ }
+ })));
+
+ if (mNext != null) {
+ mNext.println(priority, tag, msg, tr);
+ }
+ }
+
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+ /** Takes a string and adds to it, with a separator, if the bit to be added isn't null. Since
+ * the logger takes so many arguments that might be null, this method helps cut out some of the
+ * agonizing tedium of writing the same 3 lines over and over.
+ * @param source StringBuilder containing the text to append to.
+ * @param addStr The String to append
+ * @param delimiter The String to separate the source and appended strings. A tab or comma,
+ * for instance.
+ * @return The fully concatenated String as a StringBuilder
+ */
+ private StringBuilder appendIfNotNull(StringBuilder source, String addStr, String delimiter) {
+ if (addStr != null) {
+ if (addStr.length() == 0) {
+ delimiter = "";
+ }
+
+ return source.append(addStr).append(delimiter);
+ }
+ return source;
+ }
+
+ // The next LogNode in the chain.
+ LogNode mNext;
+
+ /** Outputs the string as a new line of log data in the LogView. */
+ public void appendToLog(String s) {
+ append("\n" + s);
+ }
+
+
+}
diff --git a/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/LogWrapper.java
new file mode 100644
index 0000000..16a9e7b
--- /dev/null
+++ b/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/LogWrapper.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2012 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.common.logger;
+
+import android.util.Log;
+
+/**
+ * Helper class which wraps Android's native Log utility in the Logger interface. This way
+ * normal DDMS output can be one of the many targets receiving and outputting logs simultaneously.
+ */
+public class LogWrapper implements LogNode {
+
+ // For piping: The next node to receive Log data after this one has done its work.
+ private LogNode mNext;
+
+ /**
+ * Returns the next LogNode in the linked list.
+ */
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to..
+ */
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+ /**
+ * Prints data out to the console using Android's native log mechanism.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+ // There actually are log methods that don't take a msg parameter. For now,
+ // if that's the case, just convert null to the empty string and move on.
+ String useMsg = msg;
+ if (useMsg == null) {
+ useMsg = "";
+ }
+
+ // If an exeption was provided, convert that exception to a usable string and attach
+ // it to the end of the msg method.
+ if (tr != null) {
+ msg += "\n" + Log.getStackTraceString(tr);
+ }
+
+ // This is functionally identical to Log.x(tag, useMsg);
+ // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg)
+ Log.println(priority, tag, useMsg);
+
+ // If this isn't the last node in the chain, move things along.
+ if (mNext != null) {
+ mNext.println(priority, tag, msg, tr);
+ }
+ }
+}
diff --git a/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java
new file mode 100644
index 0000000..19967dc
--- /dev/null
+++ b/samples/browseable/ElizaChat/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+/**
+ * Simple {@link LogNode} filter, removes everything except the message.
+ * Useful for situations like on-screen log output where you don't want a lot of metadata displayed,
+ * just easy-to-read message updates as they're happening.
+ */
+public class MessageOnlyLogFilter implements LogNode {
+
+ LogNode mNext;
+
+ /**
+ * Takes the "next" LogNode as a parameter, to simplify chaining.
+ *
+ * @param next The next LogNode in the pipeline.
+ */
+ public MessageOnlyLogFilter(LogNode next) {
+ mNext = next;
+ }
+
+ public MessageOnlyLogFilter() {
+ }
+
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+ if (mNext != null) {
+ getNext().println(Log.NONE, null, msg, null);
+ }
+ }
+
+ /**
+ * Returns the next LogNode in the chain.
+ */
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to..
+ */
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+}
diff --git a/samples/browseable/ElizaChat/Application/src/com.example.android.elizachat/ElizaResponder.java b/samples/browseable/ElizaChat/Application/src/com.example.android.elizachat/ElizaResponder.java
new file mode 100644
index 0000000..e87f6de
--- /dev/null
+++ b/samples/browseable/ElizaChat/Application/src/com.example.android.elizachat/ElizaResponder.java
@@ -0,0 +1,168 @@
+/*
+ * 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.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/browseable/ElizaChat/Application/src/com.example.android.elizachat/MainActivity.java b/samples/browseable/ElizaChat/Application/src/com.example.android.elizachat/MainActivity.java
new file mode 100644
index 0000000..421dcb8
--- /dev/null
+++ b/samples/browseable/ElizaChat/Application/src/com.example.android.elizachat/MainActivity.java
@@ -0,0 +1,107 @@
+/*
+ * 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.elizachat;
+
+import android.app.Activity;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+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.elizachat.NOTIFY";
+
+ public static final String ACTION_GET_CONVERSATION
+ = "com.example.android.elizachat.CONVERSATION";
+
+ private BroadcastReceiver mReceiver;
+
+ private TextView mHistoryView;
+
+ @Override
+ protected void onCreate(Bundle saved) {
+ super.onCreate(saved);
+ setContentView(R.layout.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/browseable/ElizaChat/Application/src/com.example.android.elizachat/ResponderService.java b/samples/browseable/ElizaChat/Application/src/com.example.android.elizachat/ResponderService.java
new file mode 100644
index 0000000..6d6cd9a
--- /dev/null
+++ b/samples/browseable/ElizaChat/Application/src/com.example.android.elizachat/ResponderService.java
@@ -0,0 +1,148 @@
+/*
+ * 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.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.elizachat.INCOMING";
+
+ public static final String ACTION_RESPONSE = "com.example.android.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/browseable/ElizaChat/Shared/AndroidManifest.xml b/samples/browseable/ElizaChat/Shared/AndroidManifest.xml
new file mode 100644
index 0000000..9c02d59
--- /dev/null
+++ b/samples/browseable/ElizaChat/Shared/AndroidManifest.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.elizachat.common">
+
+ <application android:allowBackup="true"
+ android:label="@string/app_name">
+ </application>
+
+</manifest>
diff --git a/samples/browseable/ElizaChat/Shared/res/values/strings.xml b/samples/browseable/ElizaChat/Shared/res/values/strings.xml
new file mode 100644
index 0000000..0f2bb90
--- /dev/null
+++ b/samples/browseable/ElizaChat/Shared/res/values/strings.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<resources>
+ <string name="app_name">Shared</string>
+</resources>
diff --git a/samples/browseable/ElizaChat/_index.jd b/samples/browseable/ElizaChat/_index.jd
new file mode 100644
index 0000000..a88371c
--- /dev/null
+++ b/samples/browseable/ElizaChat/_index.jd
@@ -0,0 +1,12 @@
+page.tags="ElizaChat"
+sample.group=Wearable
+@jd:body
+
+<p>
+
+ 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.
+
+ </p>
diff --git a/samples/browseable/EmbeddedApp/Application/AndroidManifest.xml b/samples/browseable/EmbeddedApp/Application/AndroidManifest.xml
new file mode 100644
index 0000000..2d266f2
--- /dev/null
+++ b/samples/browseable/EmbeddedApp/Application/AndroidManifest.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.embeddedapp" >
+ <uses-sdk android:minSdkVersion="18" android:targetSdkVersion="19" />
+ <application
+ android:allowBackup="true"
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name"
+ android:theme="@android:style/Theme.DeviceDefault.Light" >
+ <activity
+ android:name=".PhoneActivity"
+ android:label="@string/app_name" >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+
+</manifest>
diff --git a/samples/browseable/EmbeddedApp/Application/res/drawable-hdpi/ic_launcher.png b/samples/browseable/EmbeddedApp/Application/res/drawable-hdpi/ic_launcher.png
new file mode 100755
index 0000000..589f229
--- /dev/null
+++ b/samples/browseable/EmbeddedApp/Application/res/drawable-hdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/EmbeddedApp/Application/res/drawable-hdpi/tile.9.png b/samples/browseable/EmbeddedApp/Application/res/drawable-hdpi/tile.9.png
new file mode 100644
index 0000000..1358628
--- /dev/null
+++ b/samples/browseable/EmbeddedApp/Application/res/drawable-hdpi/tile.9.png
Binary files differ
diff --git a/samples/browseable/EmbeddedApp/Application/res/drawable-mdpi/ic_launcher.png b/samples/browseable/EmbeddedApp/Application/res/drawable-mdpi/ic_launcher.png
new file mode 100755
index 0000000..77dd571
--- /dev/null
+++ b/samples/browseable/EmbeddedApp/Application/res/drawable-mdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/EmbeddedApp/Application/res/drawable-xhdpi/ic_launcher.png b/samples/browseable/EmbeddedApp/Application/res/drawable-xhdpi/ic_launcher.png
new file mode 100755
index 0000000..fe34ebe
--- /dev/null
+++ b/samples/browseable/EmbeddedApp/Application/res/drawable-xhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/EmbeddedApp/Application/res/drawable-xxhdpi/ic_launcher.png b/samples/browseable/EmbeddedApp/Application/res/drawable-xxhdpi/ic_launcher.png
new file mode 100755
index 0000000..ab80bcd
--- /dev/null
+++ b/samples/browseable/EmbeddedApp/Application/res/drawable-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/EmbeddedApp/Application/res/layout/activity_main.xml b/samples/browseable/EmbeddedApp/Application/res/layout/activity_main.xml
new file mode 100755
index 0000000..be1aa49
--- /dev/null
+++ b/samples/browseable/EmbeddedApp/Application/res/layout/activity_main.xml
@@ -0,0 +1,36 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <LinearLayout style="@style/Widget.SampleMessageTile"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+
+ <TextView style="@style/Widget.SampleMessage"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="@dimen/horizontal_page_margin"
+ android:layout_marginRight="@dimen/horizontal_page_margin"
+ android:layout_marginTop="@dimen/vertical_page_margin"
+ android:layout_marginBottom="@dimen/vertical_page_margin"
+ android:text="@string/intro_message" />
+ </LinearLayout>
+</LinearLayout>
diff --git a/samples/browseable/EmbeddedApp/Application/res/layout/activity_phone.xml b/samples/browseable/EmbeddedApp/Application/res/layout/activity_phone.xml
new file mode 100644
index 0000000..54ca57e
--- /dev/null
+++ b/samples/browseable/EmbeddedApp/Application/res/layout/activity_phone.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:paddingLeft="@dimen/activity_horizontal_margin"
+ android:paddingRight="@dimen/activity_horizontal_margin"
+ android:paddingTop="@dimen/activity_vertical_margin"
+ android:paddingBottom="@dimen/activity_vertical_margin"
+ tools:context=".PhoneActivity">
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceLarge"
+ android:text="@string/welcome_message"
+ android:layout_alignParentTop="true"
+ android:layout_alignParentStart="true" />
+</RelativeLayout>
diff --git a/samples/browseable/EmbeddedApp/Application/res/values-sw600dp/template-dimens.xml b/samples/browseable/EmbeddedApp/Application/res/values-sw600dp/template-dimens.xml
new file mode 100644
index 0000000..22074a2
--- /dev/null
+++ b/samples/browseable/EmbeddedApp/Application/res/values-sw600dp/template-dimens.xml
@@ -0,0 +1,24 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Semantic definitions -->
+
+ <dimen name="horizontal_page_margin">@dimen/margin_huge</dimen>
+ <dimen name="vertical_page_margin">@dimen/margin_medium</dimen>
+
+</resources>
diff --git a/samples/browseable/EmbeddedApp/Application/res/values-sw600dp/template-styles.xml b/samples/browseable/EmbeddedApp/Application/res/values-sw600dp/template-styles.xml
new file mode 100644
index 0000000..03d1974
--- /dev/null
+++ b/samples/browseable/EmbeddedApp/Application/res/values-sw600dp/template-styles.xml
@@ -0,0 +1,25 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <style name="Widget.SampleMessage">
+ <item name="android:textAppearance">?android:textAppearanceLarge</item>
+ <item name="android:lineSpacingMultiplier">1.2</item>
+ <item name="android:shadowDy">-6.5</item>
+ </style>
+
+</resources>
diff --git a/samples/browseable/EmbeddedApp/Application/res/values-v11/template-styles.xml b/samples/browseable/EmbeddedApp/Application/res/values-v11/template-styles.xml
new file mode 100644
index 0000000..8c1ea66
--- /dev/null
+++ b/samples/browseable/EmbeddedApp/Application/res/values-v11/template-styles.xml
@@ -0,0 +1,22 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Activity themes -->
+ <style name="Theme.Base" parent="android:Theme.Holo.Light" />
+
+</resources>
diff --git a/samples/browseable/EmbeddedApp/Application/res/values/base-strings.xml b/samples/browseable/EmbeddedApp/Application/res/values/base-strings.xml
new file mode 100644
index 0000000..46059ed
--- /dev/null
+++ b/samples/browseable/EmbeddedApp/Application/res/values/base-strings.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 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.
+-->
+<resources>
+ <string name="app_name">EmbeddedApp</string>
+ <string name="intro_message">
+ <![CDATA[
+
+
+ This simple app demonstrates how to embed a wearable app into a phone app.
+
+
+ ]]>
+ </string>
+</resources>
diff --git a/samples/browseable/EmbeddedApp/Application/res/values/dimens.xml b/samples/browseable/EmbeddedApp/Application/res/values/dimens.xml
new file mode 100644
index 0000000..a1e9cfe
--- /dev/null
+++ b/samples/browseable/EmbeddedApp/Application/res/values/dimens.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+ <!-- Default screen margins, per the Android Design guidelines. -->
+ <dimen name="activity_horizontal_margin">16dp</dimen>
+ <dimen name="activity_vertical_margin">16dp</dimen>
+</resources>
diff --git a/samples/browseable/EmbeddedApp/Application/res/values/strings.xml b/samples/browseable/EmbeddedApp/Application/res/values/strings.xml
new file mode 100644
index 0000000..05b6f12
--- /dev/null
+++ b/samples/browseable/EmbeddedApp/Application/res/values/strings.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+
+ <string name="welcome_message">
+ By installing the release build of this application, the corresponding wearable app should
+ automatically be installed on any connected wearable devices.
+ </string>
+
+</resources>
diff --git a/samples/browseable/EmbeddedApp/Application/res/values/template-dimens.xml b/samples/browseable/EmbeddedApp/Application/res/values/template-dimens.xml
new file mode 100644
index 0000000..39e710b
--- /dev/null
+++ b/samples/browseable/EmbeddedApp/Application/res/values/template-dimens.xml
@@ -0,0 +1,32 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Define standard dimensions to comply with Holo-style grids and rhythm. -->
+
+ <dimen name="margin_tiny">4dp</dimen>
+ <dimen name="margin_small">8dp</dimen>
+ <dimen name="margin_medium">16dp</dimen>
+ <dimen name="margin_large">32dp</dimen>
+ <dimen name="margin_huge">64dp</dimen>
+
+ <!-- Semantic definitions -->
+
+ <dimen name="horizontal_page_margin">@dimen/margin_medium</dimen>
+ <dimen name="vertical_page_margin">@dimen/margin_medium</dimen>
+
+</resources>
diff --git a/samples/browseable/EmbeddedApp/Application/res/values/template-styles.xml b/samples/browseable/EmbeddedApp/Application/res/values/template-styles.xml
new file mode 100644
index 0000000..6e7d593
--- /dev/null
+++ b/samples/browseable/EmbeddedApp/Application/res/values/template-styles.xml
@@ -0,0 +1,42 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Activity themes -->
+
+ <style name="Theme.Base" parent="android:Theme.Light" />
+
+ <style name="Theme.Sample" parent="Theme.Base" />
+
+ <style name="AppTheme" parent="Theme.Sample" />
+ <!-- Widget styling -->
+
+ <style name="Widget" />
+
+ <style name="Widget.SampleMessage">
+ <item name="android:textAppearance">?android:textAppearanceMedium</item>
+ <item name="android:lineSpacingMultiplier">1.1</item>
+ </style>
+
+ <style name="Widget.SampleMessageTile">
+ <item name="android:background">@drawable/tile</item>
+ <item name="android:shadowColor">#7F000000</item>
+ <item name="android:shadowDy">-3.5</item>
+ <item name="android:shadowRadius">2</item>
+ </style>
+
+</resources>
diff --git a/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/activities/SampleActivityBase.java b/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/activities/SampleActivityBase.java
new file mode 100644
index 0000000..3228927
--- /dev/null
+++ b/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/activities/SampleActivityBase.java
@@ -0,0 +1,52 @@
+/*
+* Copyright 2013 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.common.activities;
+
+import android.os.Bundle;
+import android.support.v4.app.FragmentActivity;
+
+import com.example.android.common.logger.Log;
+import com.example.android.common.logger.LogWrapper;
+
+/**
+ * Base launcher activity, to handle most of the common plumbing for samples.
+ */
+public class SampleActivityBase extends FragmentActivity {
+
+ public static final String TAG = "SampleActivityBase";
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ initializeLogging();
+ }
+
+ /** Set up targets to receive log data */
+ public void initializeLogging() {
+ // Using Log, front-end to the logging chain, emulates android.util.log method signatures.
+ // Wraps Android's native log framework
+ LogWrapper logWrapper = new LogWrapper();
+ Log.setLogNode(logWrapper);
+
+ Log.i(TAG, "Ready");
+ }
+}
diff --git a/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/Log.java b/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/Log.java
new file mode 100644
index 0000000..17503c5
--- /dev/null
+++ b/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/Log.java
@@ -0,0 +1,236 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+/**
+ * Helper class for a list (or tree) of LoggerNodes.
+ *
+ * <p>When this is set as the head of the list,
+ * an instance of it can function as a drop-in replacement for {@link android.util.Log}.
+ * Most of the methods in this class server only to map a method call in Log to its equivalent
+ * in LogNode.</p>
+ */
+public class Log {
+ // Grabbing the native values from Android's native logging facilities,
+ // to make for easy migration and interop.
+ public static final int NONE = -1;
+ public static final int VERBOSE = android.util.Log.VERBOSE;
+ public static final int DEBUG = android.util.Log.DEBUG;
+ public static final int INFO = android.util.Log.INFO;
+ public static final int WARN = android.util.Log.WARN;
+ public static final int ERROR = android.util.Log.ERROR;
+ public static final int ASSERT = android.util.Log.ASSERT;
+
+ // Stores the beginning of the LogNode topology.
+ private static LogNode mLogNode;
+
+ /**
+ * Returns the next LogNode in the linked list.
+ */
+ public static LogNode getLogNode() {
+ return mLogNode;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to.
+ */
+ public static void setLogNode(LogNode node) {
+ mLogNode = node;
+ }
+
+ /**
+ * Instructs the LogNode to print the log data provided. Other LogNodes can
+ * be chained to the end of the LogNode as desired.
+ *
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void println(int priority, String tag, String msg, Throwable tr) {
+ if (mLogNode != null) {
+ mLogNode.println(priority, tag, msg, tr);
+ }
+ }
+
+ /**
+ * Instructs the LogNode to print the log data provided. Other LogNodes can
+ * be chained to the end of the LogNode as desired.
+ *
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ */
+ public static void println(int priority, String tag, String msg) {
+ println(priority, tag, msg, null);
+ }
+
+ /**
+ * Prints a message at VERBOSE priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void v(String tag, String msg, Throwable tr) {
+ println(VERBOSE, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at VERBOSE priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void v(String tag, String msg) {
+ v(tag, msg, null);
+ }
+
+
+ /**
+ * Prints a message at DEBUG priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void d(String tag, String msg, Throwable tr) {
+ println(DEBUG, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at DEBUG priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void d(String tag, String msg) {
+ d(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at INFO priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void i(String tag, String msg, Throwable tr) {
+ println(INFO, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at INFO priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void i(String tag, String msg) {
+ i(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void w(String tag, String msg, Throwable tr) {
+ println(WARN, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void w(String tag, String msg) {
+ w(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void w(String tag, Throwable tr) {
+ w(tag, null, tr);
+ }
+
+ /**
+ * Prints a message at ERROR priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void e(String tag, String msg, Throwable tr) {
+ println(ERROR, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at ERROR priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void e(String tag, String msg) {
+ e(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void wtf(String tag, String msg, Throwable tr) {
+ println(ASSERT, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void wtf(String tag, String msg) {
+ wtf(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void wtf(String tag, Throwable tr) {
+ wtf(tag, null, tr);
+ }
+}
diff --git a/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/LogFragment.java
new file mode 100644
index 0000000..b302acd
--- /dev/null
+++ b/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/LogFragment.java
@@ -0,0 +1,109 @@
+/*
+* Copyright 2013 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.
+*/
+/*
+ * Copyright 2013 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.common.logger;
+
+import android.graphics.Typeface;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ScrollView;
+
+/**
+ * Simple fraggment which contains a LogView and uses is to output log data it receives
+ * through the LogNode interface.
+ */
+public class LogFragment extends Fragment {
+
+ private LogView mLogView;
+ private ScrollView mScrollView;
+
+ public LogFragment() {}
+
+ public View inflateViews() {
+ mScrollView = new ScrollView(getActivity());
+ ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT);
+ mScrollView.setLayoutParams(scrollParams);
+
+ mLogView = new LogView(getActivity());
+ ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams);
+ logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
+ mLogView.setLayoutParams(logParams);
+ mLogView.setClickable(true);
+ mLogView.setFocusable(true);
+ mLogView.setTypeface(Typeface.MONOSPACE);
+
+ // Want to set padding as 16 dips, setPadding takes pixels. Hooray math!
+ int paddingDips = 16;
+ double scale = getResources().getDisplayMetrics().density;
+ int paddingPixels = (int) ((paddingDips * (scale)) + .5);
+ mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels);
+ mLogView.setCompoundDrawablePadding(paddingPixels);
+
+ mLogView.setGravity(Gravity.BOTTOM);
+ mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium);
+
+ mScrollView.addView(mLogView);
+ return mScrollView;
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+
+ View result = inflateViews();
+
+ mLogView.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {}
+
+ @Override
+ public void afterTextChanged(Editable s) {
+ mScrollView.fullScroll(ScrollView.FOCUS_DOWN);
+ }
+ });
+ return result;
+ }
+
+ public LogView getLogView() {
+ return mLogView;
+ }
+}
\ No newline at end of file
diff --git a/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/LogNode.java
new file mode 100644
index 0000000..bc37cab
--- /dev/null
+++ b/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/LogNode.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2012 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.common.logger;
+
+/**
+ * Basic interface for a logging system that can output to one or more targets.
+ * Note that in addition to classes that will output these logs in some format,
+ * one can also implement this interface over a filter and insert that in the chain,
+ * such that no targets further down see certain data, or see manipulated forms of the data.
+ * You could, for instance, write a "ToHtmlLoggerNode" that just converted all the log data
+ * it received to HTML and sent it along to the next node in the chain, without printing it
+ * anywhere.
+ */
+public interface LogNode {
+
+ /**
+ * Instructs first LogNode in the list to print the log data provided.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public void println(int priority, String tag, String msg, Throwable tr);
+
+}
diff --git a/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/LogView.java
new file mode 100644
index 0000000..c01542b
--- /dev/null
+++ b/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/LogView.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+import android.app.Activity;
+import android.content.Context;
+import android.util.*;
+import android.widget.TextView;
+
+/** Simple TextView which is used to output log data received through the LogNode interface.
+*/
+public class LogView extends TextView implements LogNode {
+
+ public LogView(Context context) {
+ super(context);
+ }
+
+ public LogView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public LogView(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ /**
+ * Formats the log data and prints it out to the LogView.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+
+
+ String priorityStr = null;
+
+ // For the purposes of this View, we want to print the priority as readable text.
+ switch(priority) {
+ case android.util.Log.VERBOSE:
+ priorityStr = "VERBOSE";
+ break;
+ case android.util.Log.DEBUG:
+ priorityStr = "DEBUG";
+ break;
+ case android.util.Log.INFO:
+ priorityStr = "INFO";
+ break;
+ case android.util.Log.WARN:
+ priorityStr = "WARN";
+ break;
+ case android.util.Log.ERROR:
+ priorityStr = "ERROR";
+ break;
+ case android.util.Log.ASSERT:
+ priorityStr = "ASSERT";
+ break;
+ default:
+ break;
+ }
+
+ // Handily, the Log class has a facility for converting a stack trace into a usable string.
+ String exceptionStr = null;
+ if (tr != null) {
+ exceptionStr = android.util.Log.getStackTraceString(tr);
+ }
+
+ // Take the priority, tag, message, and exception, and concatenate as necessary
+ // into one usable line of text.
+ final StringBuilder outputBuilder = new StringBuilder();
+
+ String delimiter = "\t";
+ appendIfNotNull(outputBuilder, priorityStr, delimiter);
+ appendIfNotNull(outputBuilder, tag, delimiter);
+ appendIfNotNull(outputBuilder, msg, delimiter);
+ appendIfNotNull(outputBuilder, exceptionStr, delimiter);
+
+ // In case this was originally called from an AsyncTask or some other off-UI thread,
+ // make sure the update occurs within the UI thread.
+ ((Activity) getContext()).runOnUiThread( (new Thread(new Runnable() {
+ @Override
+ public void run() {
+ // Display the text we just generated within the LogView.
+ appendToLog(outputBuilder.toString());
+ }
+ })));
+
+ if (mNext != null) {
+ mNext.println(priority, tag, msg, tr);
+ }
+ }
+
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+ /** Takes a string and adds to it, with a separator, if the bit to be added isn't null. Since
+ * the logger takes so many arguments that might be null, this method helps cut out some of the
+ * agonizing tedium of writing the same 3 lines over and over.
+ * @param source StringBuilder containing the text to append to.
+ * @param addStr The String to append
+ * @param delimiter The String to separate the source and appended strings. A tab or comma,
+ * for instance.
+ * @return The fully concatenated String as a StringBuilder
+ */
+ private StringBuilder appendIfNotNull(StringBuilder source, String addStr, String delimiter) {
+ if (addStr != null) {
+ if (addStr.length() == 0) {
+ delimiter = "";
+ }
+
+ return source.append(addStr).append(delimiter);
+ }
+ return source;
+ }
+
+ // The next LogNode in the chain.
+ LogNode mNext;
+
+ /** Outputs the string as a new line of log data in the LogView. */
+ public void appendToLog(String s) {
+ append("\n" + s);
+ }
+
+
+}
diff --git a/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/LogWrapper.java
new file mode 100644
index 0000000..16a9e7b
--- /dev/null
+++ b/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/LogWrapper.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2012 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.common.logger;
+
+import android.util.Log;
+
+/**
+ * Helper class which wraps Android's native Log utility in the Logger interface. This way
+ * normal DDMS output can be one of the many targets receiving and outputting logs simultaneously.
+ */
+public class LogWrapper implements LogNode {
+
+ // For piping: The next node to receive Log data after this one has done its work.
+ private LogNode mNext;
+
+ /**
+ * Returns the next LogNode in the linked list.
+ */
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to..
+ */
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+ /**
+ * Prints data out to the console using Android's native log mechanism.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+ // There actually are log methods that don't take a msg parameter. For now,
+ // if that's the case, just convert null to the empty string and move on.
+ String useMsg = msg;
+ if (useMsg == null) {
+ useMsg = "";
+ }
+
+ // If an exeption was provided, convert that exception to a usable string and attach
+ // it to the end of the msg method.
+ if (tr != null) {
+ msg += "\n" + Log.getStackTraceString(tr);
+ }
+
+ // This is functionally identical to Log.x(tag, useMsg);
+ // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg)
+ Log.println(priority, tag, useMsg);
+
+ // If this isn't the last node in the chain, move things along.
+ if (mNext != null) {
+ mNext.println(priority, tag, msg, tr);
+ }
+ }
+}
diff --git a/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java
new file mode 100644
index 0000000..19967dc
--- /dev/null
+++ b/samples/browseable/EmbeddedApp/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+/**
+ * Simple {@link LogNode} filter, removes everything except the message.
+ * Useful for situations like on-screen log output where you don't want a lot of metadata displayed,
+ * just easy-to-read message updates as they're happening.
+ */
+public class MessageOnlyLogFilter implements LogNode {
+
+ LogNode mNext;
+
+ /**
+ * Takes the "next" LogNode as a parameter, to simplify chaining.
+ *
+ * @param next The next LogNode in the pipeline.
+ */
+ public MessageOnlyLogFilter(LogNode next) {
+ mNext = next;
+ }
+
+ public MessageOnlyLogFilter() {
+ }
+
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+ if (mNext != null) {
+ getNext().println(Log.NONE, null, msg, null);
+ }
+ }
+
+ /**
+ * Returns the next LogNode in the chain.
+ */
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to..
+ */
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+}
diff --git a/samples/browseable/EmbeddedApp/Application/src/com.example.android.embeddedapp/PhoneActivity.java b/samples/browseable/EmbeddedApp/Application/src/com.example.android.embeddedapp/PhoneActivity.java
new file mode 100644
index 0000000..de95938
--- /dev/null
+++ b/samples/browseable/EmbeddedApp/Application/src/com.example.android.embeddedapp/PhoneActivity.java
@@ -0,0 +1,29 @@
+/*
+ * 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.embeddedapp;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+public class PhoneActivity extends Activity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_phone);
+ }
+}
diff --git a/samples/browseable/EmbeddedApp/Shared/AndroidManifest.xml b/samples/browseable/EmbeddedApp/Shared/AndroidManifest.xml
new file mode 100644
index 0000000..f026bc5
--- /dev/null
+++ b/samples/browseable/EmbeddedApp/Shared/AndroidManifest.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.embeddedapp.common">
+
+ <application android:allowBackup="true"
+ android:label="@string/app_name">
+ </application>
+
+</manifest>
diff --git a/samples/browseable/EmbeddedApp/Shared/res/values/strings.xml b/samples/browseable/EmbeddedApp/Shared/res/values/strings.xml
new file mode 100644
index 0000000..0f2bb90
--- /dev/null
+++ b/samples/browseable/EmbeddedApp/Shared/res/values/strings.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<resources>
+ <string name="app_name">Shared</string>
+</resources>
diff --git a/samples/browseable/EmbeddedApp/Wearable/AndroidManifest.xml b/samples/browseable/EmbeddedApp/Wearable/AndroidManifest.xml
new file mode 100644
index 0000000..fd07d3c
--- /dev/null
+++ b/samples/browseable/EmbeddedApp/Wearable/AndroidManifest.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.embeddedapp" >
+
+ <uses-sdk android:minSdkVersion="20"
+ android:targetSdkVersion="20" />
+
+ <uses-feature android:name="android.hardware.type.watch" />
+
+ <application
+ android:allowBackup="true"
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name"
+ android:theme="@android:style/Theme.DeviceDefault.Light" >
+ <activity
+ android:name=".WearableActivity"
+ android:label="@string/app_name" >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+
+</manifest>
diff --git a/samples/browseable/EmbeddedApp/Wearable/res/drawable-hdpi/ic_launcher.png b/samples/browseable/EmbeddedApp/Wearable/res/drawable-hdpi/ic_launcher.png
new file mode 100755
index 0000000..589f229
--- /dev/null
+++ b/samples/browseable/EmbeddedApp/Wearable/res/drawable-hdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/EmbeddedApp/Wearable/res/drawable-mdpi/ic_launcher.png b/samples/browseable/EmbeddedApp/Wearable/res/drawable-mdpi/ic_launcher.png
new file mode 100755
index 0000000..77dd571
--- /dev/null
+++ b/samples/browseable/EmbeddedApp/Wearable/res/drawable-mdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/EmbeddedApp/Wearable/res/drawable-xhdpi/ic_launcher.png b/samples/browseable/EmbeddedApp/Wearable/res/drawable-xhdpi/ic_launcher.png
new file mode 100755
index 0000000..fe34ebe
--- /dev/null
+++ b/samples/browseable/EmbeddedApp/Wearable/res/drawable-xhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/EmbeddedApp/Wearable/res/drawable-xxhdpi/ic_launcher.png b/samples/browseable/EmbeddedApp/Wearable/res/drawable-xxhdpi/ic_launcher.png
new file mode 100755
index 0000000..ab80bcd
--- /dev/null
+++ b/samples/browseable/EmbeddedApp/Wearable/res/drawable-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/EmbeddedApp/Wearable/res/layout/activity_wearable.xml b/samples/browseable/EmbeddedApp/Wearable/res/layout/activity_wearable.xml
new file mode 100644
index 0000000..1f6a78a
--- /dev/null
+++ b/samples/browseable/EmbeddedApp/Wearable/res/layout/activity_wearable.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ tools:context=".WearableActivity">
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:text="@string/welcome_message"
+ android:layout_centerVertical="true"
+ android:layout_centerHorizontal="true" />
+</RelativeLayout>
diff --git a/samples/browseable/EmbeddedApp/Wearable/res/values/strings.xml b/samples/browseable/EmbeddedApp/Wearable/res/values/strings.xml
new file mode 100644
index 0000000..1823c57
--- /dev/null
+++ b/samples/browseable/EmbeddedApp/Wearable/res/values/strings.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+
+ <string name="app_name">EmbeddedApp Sample</string>
+ <string name="welcome_message">
+ This wearable app should be automatically installed on wearable devices whenever the
+ release build of the corresponding phone app is installed.
+ </string>
+
+</resources>
diff --git a/samples/browseable/EmbeddedApp/Wearable/src/com.example.android.embeddedapp/WearableActivity.java b/samples/browseable/EmbeddedApp/Wearable/src/com.example.android.embeddedapp/WearableActivity.java
new file mode 100644
index 0000000..1ae0c1f
--- /dev/null
+++ b/samples/browseable/EmbeddedApp/Wearable/src/com.example.android.embeddedapp/WearableActivity.java
@@ -0,0 +1,29 @@
+/*
+ * 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.embeddedapp;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+public class WearableActivity extends Activity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_wearable);
+ }
+}
diff --git a/samples/browseable/EmbeddedApp/_index.jd b/samples/browseable/EmbeddedApp/_index.jd
new file mode 100644
index 0000000..b8d047f
--- /dev/null
+++ b/samples/browseable/EmbeddedApp/_index.jd
@@ -0,0 +1,9 @@
+page.tags="EmbeddedApp"
+sample.group=Wearable
+@jd:body
+
+<p>
+
+ This simple app demonstrates how to embed a wearable app into a phone app.
+
+ </p>
diff --git a/samples/browseable/FindMyPhone/Application/AndroidManifest.xml b/samples/browseable/FindMyPhone/Application/AndroidManifest.xml
new file mode 100644
index 0000000..5ca8c8a
--- /dev/null
+++ b/samples/browseable/FindMyPhone/Application/AndroidManifest.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.findphone">
+
+ <uses-sdk android:minSdkVersion="19"
+ android:targetSdkVersion="19" />
+
+ <uses-permission android:name="android.permission.VIBRATE" />
+ <application
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name"
+ android:theme="@android:style/Theme.Holo.Light"
+ android:allowBackup="true">
+
+ <meta-data
+ android:name="com.google.android.gms.version"
+ android:value="@integer/google_play_services_version" />
+
+ <service
+ android:name="com.example.android.findphone.SoundAlarmListenerService" >
+ <intent-filter>
+ <action android:name="com.google.android.gms.wearable.BIND_LISTENER" />
+ </intent-filter>
+ </service>
+
+ </application>
+</manifest>
diff --git a/samples/browseable/FindMyPhone/Application/res/drawable-hdpi/ic_launcher.png b/samples/browseable/FindMyPhone/Application/res/drawable-hdpi/ic_launcher.png
new file mode 100644
index 0000000..43254bd
--- /dev/null
+++ b/samples/browseable/FindMyPhone/Application/res/drawable-hdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/FindMyPhone/Application/res/drawable-hdpi/tile.9.png b/samples/browseable/FindMyPhone/Application/res/drawable-hdpi/tile.9.png
new file mode 100644
index 0000000..1358628
--- /dev/null
+++ b/samples/browseable/FindMyPhone/Application/res/drawable-hdpi/tile.9.png
Binary files differ
diff --git a/samples/browseable/FindMyPhone/Application/res/drawable-mdpi/ic_launcher.png b/samples/browseable/FindMyPhone/Application/res/drawable-mdpi/ic_launcher.png
new file mode 100644
index 0000000..de255d6
--- /dev/null
+++ b/samples/browseable/FindMyPhone/Application/res/drawable-mdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/FindMyPhone/Application/res/drawable-xhdpi/ic_launcher.png b/samples/browseable/FindMyPhone/Application/res/drawable-xhdpi/ic_launcher.png
new file mode 100644
index 0000000..5a849da
--- /dev/null
+++ b/samples/browseable/FindMyPhone/Application/res/drawable-xhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/FindMyPhone/Application/res/drawable-xxhdpi/ic_launcher.png b/samples/browseable/FindMyPhone/Application/res/drawable-xxhdpi/ic_launcher.png
new file mode 100644
index 0000000..96a7cb8
--- /dev/null
+++ b/samples/browseable/FindMyPhone/Application/res/drawable-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/FindMyPhone/Application/res/layout/activity_main.xml b/samples/browseable/FindMyPhone/Application/res/layout/activity_main.xml
new file mode 100755
index 0000000..be1aa49
--- /dev/null
+++ b/samples/browseable/FindMyPhone/Application/res/layout/activity_main.xml
@@ -0,0 +1,36 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <LinearLayout style="@style/Widget.SampleMessageTile"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+
+ <TextView style="@style/Widget.SampleMessage"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="@dimen/horizontal_page_margin"
+ android:layout_marginRight="@dimen/horizontal_page_margin"
+ android:layout_marginTop="@dimen/vertical_page_margin"
+ android:layout_marginBottom="@dimen/vertical_page_margin"
+ android:text="@string/intro_message" />
+ </LinearLayout>
+</LinearLayout>
diff --git a/samples/browseable/FindMyPhone/Application/res/values-sw600dp/template-dimens.xml b/samples/browseable/FindMyPhone/Application/res/values-sw600dp/template-dimens.xml
new file mode 100644
index 0000000..22074a2
--- /dev/null
+++ b/samples/browseable/FindMyPhone/Application/res/values-sw600dp/template-dimens.xml
@@ -0,0 +1,24 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Semantic definitions -->
+
+ <dimen name="horizontal_page_margin">@dimen/margin_huge</dimen>
+ <dimen name="vertical_page_margin">@dimen/margin_medium</dimen>
+
+</resources>
diff --git a/samples/browseable/FindMyPhone/Application/res/values-sw600dp/template-styles.xml b/samples/browseable/FindMyPhone/Application/res/values-sw600dp/template-styles.xml
new file mode 100644
index 0000000..03d1974
--- /dev/null
+++ b/samples/browseable/FindMyPhone/Application/res/values-sw600dp/template-styles.xml
@@ -0,0 +1,25 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <style name="Widget.SampleMessage">
+ <item name="android:textAppearance">?android:textAppearanceLarge</item>
+ <item name="android:lineSpacingMultiplier">1.2</item>
+ <item name="android:shadowDy">-6.5</item>
+ </style>
+
+</resources>
diff --git a/samples/browseable/FindMyPhone/Application/res/values-v11/template-styles.xml b/samples/browseable/FindMyPhone/Application/res/values-v11/template-styles.xml
new file mode 100644
index 0000000..8c1ea66
--- /dev/null
+++ b/samples/browseable/FindMyPhone/Application/res/values-v11/template-styles.xml
@@ -0,0 +1,22 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Activity themes -->
+ <style name="Theme.Base" parent="android:Theme.Holo.Light" />
+
+</resources>
diff --git a/samples/browseable/FindMyPhone/Application/res/values/base-strings.xml b/samples/browseable/FindMyPhone/Application/res/values/base-strings.xml
new file mode 100644
index 0000000..e2e3722
--- /dev/null
+++ b/samples/browseable/FindMyPhone/Application/res/values/base-strings.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 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.
+-->
+<resources>
+ <string name="app_name">FindMyPhone</string>
+ <string name="intro_message">
+ <![CDATA[
+
+
+ This sample application notifies you when you may have left your phone behind
+ (specifically, when your companion and wearable disconnect). If you have misplaced your phone, but
+ it is still connected to your wearable, you can also start an activity on the wearable to sound an
+ alarm on your phone.
+
+
+ ]]>
+ </string>
+</resources>
diff --git a/samples/browseable/FindMyPhone/Application/res/values/strings.xml b/samples/browseable/FindMyPhone/Application/res/values/strings.xml
new file mode 100644
index 0000000..64163c2
--- /dev/null
+++ b/samples/browseable/FindMyPhone/Application/res/values/strings.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+</resources>
diff --git a/samples/browseable/FindMyPhone/Application/res/values/template-dimens.xml b/samples/browseable/FindMyPhone/Application/res/values/template-dimens.xml
new file mode 100644
index 0000000..39e710b
--- /dev/null
+++ b/samples/browseable/FindMyPhone/Application/res/values/template-dimens.xml
@@ -0,0 +1,32 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Define standard dimensions to comply with Holo-style grids and rhythm. -->
+
+ <dimen name="margin_tiny">4dp</dimen>
+ <dimen name="margin_small">8dp</dimen>
+ <dimen name="margin_medium">16dp</dimen>
+ <dimen name="margin_large">32dp</dimen>
+ <dimen name="margin_huge">64dp</dimen>
+
+ <!-- Semantic definitions -->
+
+ <dimen name="horizontal_page_margin">@dimen/margin_medium</dimen>
+ <dimen name="vertical_page_margin">@dimen/margin_medium</dimen>
+
+</resources>
diff --git a/samples/browseable/FindMyPhone/Application/res/values/template-styles.xml b/samples/browseable/FindMyPhone/Application/res/values/template-styles.xml
new file mode 100644
index 0000000..6e7d593
--- /dev/null
+++ b/samples/browseable/FindMyPhone/Application/res/values/template-styles.xml
@@ -0,0 +1,42 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Activity themes -->
+
+ <style name="Theme.Base" parent="android:Theme.Light" />
+
+ <style name="Theme.Sample" parent="Theme.Base" />
+
+ <style name="AppTheme" parent="Theme.Sample" />
+ <!-- Widget styling -->
+
+ <style name="Widget" />
+
+ <style name="Widget.SampleMessage">
+ <item name="android:textAppearance">?android:textAppearanceMedium</item>
+ <item name="android:lineSpacingMultiplier">1.1</item>
+ </style>
+
+ <style name="Widget.SampleMessageTile">
+ <item name="android:background">@drawable/tile</item>
+ <item name="android:shadowColor">#7F000000</item>
+ <item name="android:shadowDy">-3.5</item>
+ <item name="android:shadowRadius">2</item>
+ </style>
+
+</resources>
diff --git a/samples/browseable/FindMyPhone/Application/src/com.example.android.common/activities/SampleActivityBase.java b/samples/browseable/FindMyPhone/Application/src/com.example.android.common/activities/SampleActivityBase.java
new file mode 100644
index 0000000..3228927
--- /dev/null
+++ b/samples/browseable/FindMyPhone/Application/src/com.example.android.common/activities/SampleActivityBase.java
@@ -0,0 +1,52 @@
+/*
+* Copyright 2013 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.common.activities;
+
+import android.os.Bundle;
+import android.support.v4.app.FragmentActivity;
+
+import com.example.android.common.logger.Log;
+import com.example.android.common.logger.LogWrapper;
+
+/**
+ * Base launcher activity, to handle most of the common plumbing for samples.
+ */
+public class SampleActivityBase extends FragmentActivity {
+
+ public static final String TAG = "SampleActivityBase";
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ initializeLogging();
+ }
+
+ /** Set up targets to receive log data */
+ public void initializeLogging() {
+ // Using Log, front-end to the logging chain, emulates android.util.log method signatures.
+ // Wraps Android's native log framework
+ LogWrapper logWrapper = new LogWrapper();
+ Log.setLogNode(logWrapper);
+
+ Log.i(TAG, "Ready");
+ }
+}
diff --git a/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/Log.java b/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/Log.java
new file mode 100644
index 0000000..17503c5
--- /dev/null
+++ b/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/Log.java
@@ -0,0 +1,236 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+/**
+ * Helper class for a list (or tree) of LoggerNodes.
+ *
+ * <p>When this is set as the head of the list,
+ * an instance of it can function as a drop-in replacement for {@link android.util.Log}.
+ * Most of the methods in this class server only to map a method call in Log to its equivalent
+ * in LogNode.</p>
+ */
+public class Log {
+ // Grabbing the native values from Android's native logging facilities,
+ // to make for easy migration and interop.
+ public static final int NONE = -1;
+ public static final int VERBOSE = android.util.Log.VERBOSE;
+ public static final int DEBUG = android.util.Log.DEBUG;
+ public static final int INFO = android.util.Log.INFO;
+ public static final int WARN = android.util.Log.WARN;
+ public static final int ERROR = android.util.Log.ERROR;
+ public static final int ASSERT = android.util.Log.ASSERT;
+
+ // Stores the beginning of the LogNode topology.
+ private static LogNode mLogNode;
+
+ /**
+ * Returns the next LogNode in the linked list.
+ */
+ public static LogNode getLogNode() {
+ return mLogNode;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to.
+ */
+ public static void setLogNode(LogNode node) {
+ mLogNode = node;
+ }
+
+ /**
+ * Instructs the LogNode to print the log data provided. Other LogNodes can
+ * be chained to the end of the LogNode as desired.
+ *
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void println(int priority, String tag, String msg, Throwable tr) {
+ if (mLogNode != null) {
+ mLogNode.println(priority, tag, msg, tr);
+ }
+ }
+
+ /**
+ * Instructs the LogNode to print the log data provided. Other LogNodes can
+ * be chained to the end of the LogNode as desired.
+ *
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ */
+ public static void println(int priority, String tag, String msg) {
+ println(priority, tag, msg, null);
+ }
+
+ /**
+ * Prints a message at VERBOSE priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void v(String tag, String msg, Throwable tr) {
+ println(VERBOSE, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at VERBOSE priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void v(String tag, String msg) {
+ v(tag, msg, null);
+ }
+
+
+ /**
+ * Prints a message at DEBUG priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void d(String tag, String msg, Throwable tr) {
+ println(DEBUG, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at DEBUG priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void d(String tag, String msg) {
+ d(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at INFO priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void i(String tag, String msg, Throwable tr) {
+ println(INFO, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at INFO priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void i(String tag, String msg) {
+ i(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void w(String tag, String msg, Throwable tr) {
+ println(WARN, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void w(String tag, String msg) {
+ w(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void w(String tag, Throwable tr) {
+ w(tag, null, tr);
+ }
+
+ /**
+ * Prints a message at ERROR priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void e(String tag, String msg, Throwable tr) {
+ println(ERROR, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at ERROR priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void e(String tag, String msg) {
+ e(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void wtf(String tag, String msg, Throwable tr) {
+ println(ASSERT, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void wtf(String tag, String msg) {
+ wtf(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void wtf(String tag, Throwable tr) {
+ wtf(tag, null, tr);
+ }
+}
diff --git a/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/LogFragment.java
new file mode 100644
index 0000000..b302acd
--- /dev/null
+++ b/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/LogFragment.java
@@ -0,0 +1,109 @@
+/*
+* Copyright 2013 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.
+*/
+/*
+ * Copyright 2013 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.common.logger;
+
+import android.graphics.Typeface;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ScrollView;
+
+/**
+ * Simple fraggment which contains a LogView and uses is to output log data it receives
+ * through the LogNode interface.
+ */
+public class LogFragment extends Fragment {
+
+ private LogView mLogView;
+ private ScrollView mScrollView;
+
+ public LogFragment() {}
+
+ public View inflateViews() {
+ mScrollView = new ScrollView(getActivity());
+ ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT);
+ mScrollView.setLayoutParams(scrollParams);
+
+ mLogView = new LogView(getActivity());
+ ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams);
+ logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
+ mLogView.setLayoutParams(logParams);
+ mLogView.setClickable(true);
+ mLogView.setFocusable(true);
+ mLogView.setTypeface(Typeface.MONOSPACE);
+
+ // Want to set padding as 16 dips, setPadding takes pixels. Hooray math!
+ int paddingDips = 16;
+ double scale = getResources().getDisplayMetrics().density;
+ int paddingPixels = (int) ((paddingDips * (scale)) + .5);
+ mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels);
+ mLogView.setCompoundDrawablePadding(paddingPixels);
+
+ mLogView.setGravity(Gravity.BOTTOM);
+ mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium);
+
+ mScrollView.addView(mLogView);
+ return mScrollView;
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+
+ View result = inflateViews();
+
+ mLogView.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {}
+
+ @Override
+ public void afterTextChanged(Editable s) {
+ mScrollView.fullScroll(ScrollView.FOCUS_DOWN);
+ }
+ });
+ return result;
+ }
+
+ public LogView getLogView() {
+ return mLogView;
+ }
+}
\ No newline at end of file
diff --git a/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/LogNode.java
new file mode 100644
index 0000000..bc37cab
--- /dev/null
+++ b/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/LogNode.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2012 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.common.logger;
+
+/**
+ * Basic interface for a logging system that can output to one or more targets.
+ * Note that in addition to classes that will output these logs in some format,
+ * one can also implement this interface over a filter and insert that in the chain,
+ * such that no targets further down see certain data, or see manipulated forms of the data.
+ * You could, for instance, write a "ToHtmlLoggerNode" that just converted all the log data
+ * it received to HTML and sent it along to the next node in the chain, without printing it
+ * anywhere.
+ */
+public interface LogNode {
+
+ /**
+ * Instructs first LogNode in the list to print the log data provided.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public void println(int priority, String tag, String msg, Throwable tr);
+
+}
diff --git a/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/LogView.java
new file mode 100644
index 0000000..c01542b
--- /dev/null
+++ b/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/LogView.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+import android.app.Activity;
+import android.content.Context;
+import android.util.*;
+import android.widget.TextView;
+
+/** Simple TextView which is used to output log data received through the LogNode interface.
+*/
+public class LogView extends TextView implements LogNode {
+
+ public LogView(Context context) {
+ super(context);
+ }
+
+ public LogView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public LogView(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ /**
+ * Formats the log data and prints it out to the LogView.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+
+
+ String priorityStr = null;
+
+ // For the purposes of this View, we want to print the priority as readable text.
+ switch(priority) {
+ case android.util.Log.VERBOSE:
+ priorityStr = "VERBOSE";
+ break;
+ case android.util.Log.DEBUG:
+ priorityStr = "DEBUG";
+ break;
+ case android.util.Log.INFO:
+ priorityStr = "INFO";
+ break;
+ case android.util.Log.WARN:
+ priorityStr = "WARN";
+ break;
+ case android.util.Log.ERROR:
+ priorityStr = "ERROR";
+ break;
+ case android.util.Log.ASSERT:
+ priorityStr = "ASSERT";
+ break;
+ default:
+ break;
+ }
+
+ // Handily, the Log class has a facility for converting a stack trace into a usable string.
+ String exceptionStr = null;
+ if (tr != null) {
+ exceptionStr = android.util.Log.getStackTraceString(tr);
+ }
+
+ // Take the priority, tag, message, and exception, and concatenate as necessary
+ // into one usable line of text.
+ final StringBuilder outputBuilder = new StringBuilder();
+
+ String delimiter = "\t";
+ appendIfNotNull(outputBuilder, priorityStr, delimiter);
+ appendIfNotNull(outputBuilder, tag, delimiter);
+ appendIfNotNull(outputBuilder, msg, delimiter);
+ appendIfNotNull(outputBuilder, exceptionStr, delimiter);
+
+ // In case this was originally called from an AsyncTask or some other off-UI thread,
+ // make sure the update occurs within the UI thread.
+ ((Activity) getContext()).runOnUiThread( (new Thread(new Runnable() {
+ @Override
+ public void run() {
+ // Display the text we just generated within the LogView.
+ appendToLog(outputBuilder.toString());
+ }
+ })));
+
+ if (mNext != null) {
+ mNext.println(priority, tag, msg, tr);
+ }
+ }
+
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+ /** Takes a string and adds to it, with a separator, if the bit to be added isn't null. Since
+ * the logger takes so many arguments that might be null, this method helps cut out some of the
+ * agonizing tedium of writing the same 3 lines over and over.
+ * @param source StringBuilder containing the text to append to.
+ * @param addStr The String to append
+ * @param delimiter The String to separate the source and appended strings. A tab or comma,
+ * for instance.
+ * @return The fully concatenated String as a StringBuilder
+ */
+ private StringBuilder appendIfNotNull(StringBuilder source, String addStr, String delimiter) {
+ if (addStr != null) {
+ if (addStr.length() == 0) {
+ delimiter = "";
+ }
+
+ return source.append(addStr).append(delimiter);
+ }
+ return source;
+ }
+
+ // The next LogNode in the chain.
+ LogNode mNext;
+
+ /** Outputs the string as a new line of log data in the LogView. */
+ public void appendToLog(String s) {
+ append("\n" + s);
+ }
+
+
+}
diff --git a/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/LogWrapper.java
new file mode 100644
index 0000000..16a9e7b
--- /dev/null
+++ b/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/LogWrapper.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2012 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.common.logger;
+
+import android.util.Log;
+
+/**
+ * Helper class which wraps Android's native Log utility in the Logger interface. This way
+ * normal DDMS output can be one of the many targets receiving and outputting logs simultaneously.
+ */
+public class LogWrapper implements LogNode {
+
+ // For piping: The next node to receive Log data after this one has done its work.
+ private LogNode mNext;
+
+ /**
+ * Returns the next LogNode in the linked list.
+ */
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to..
+ */
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+ /**
+ * Prints data out to the console using Android's native log mechanism.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+ // There actually are log methods that don't take a msg parameter. For now,
+ // if that's the case, just convert null to the empty string and move on.
+ String useMsg = msg;
+ if (useMsg == null) {
+ useMsg = "";
+ }
+
+ // If an exeption was provided, convert that exception to a usable string and attach
+ // it to the end of the msg method.
+ if (tr != null) {
+ msg += "\n" + Log.getStackTraceString(tr);
+ }
+
+ // This is functionally identical to Log.x(tag, useMsg);
+ // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg)
+ Log.println(priority, tag, useMsg);
+
+ // If this isn't the last node in the chain, move things along.
+ if (mNext != null) {
+ mNext.println(priority, tag, msg, tr);
+ }
+ }
+}
diff --git a/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java
new file mode 100644
index 0000000..19967dc
--- /dev/null
+++ b/samples/browseable/FindMyPhone/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+/**
+ * Simple {@link LogNode} filter, removes everything except the message.
+ * Useful for situations like on-screen log output where you don't want a lot of metadata displayed,
+ * just easy-to-read message updates as they're happening.
+ */
+public class MessageOnlyLogFilter implements LogNode {
+
+ LogNode mNext;
+
+ /**
+ * Takes the "next" LogNode as a parameter, to simplify chaining.
+ *
+ * @param next The next LogNode in the pipeline.
+ */
+ public MessageOnlyLogFilter(LogNode next) {
+ mNext = next;
+ }
+
+ public MessageOnlyLogFilter() {
+ }
+
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+ if (mNext != null) {
+ getNext().println(Log.NONE, null, msg, null);
+ }
+ }
+
+ /**
+ * Returns the next LogNode in the chain.
+ */
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to..
+ */
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+}
diff --git a/samples/browseable/FindMyPhone/Application/src/com.example.android.findphone/SoundAlarmListenerService.java b/samples/browseable/FindMyPhone/Application/src/com.example.android.findphone/SoundAlarmListenerService.java
new file mode 100644
index 0000000..106a47a
--- /dev/null
+++ b/samples/browseable/FindMyPhone/Application/src/com.example.android.findphone/SoundAlarmListenerService.java
@@ -0,0 +1,101 @@
+/*
+ * 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.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/browseable/FindMyPhone/Shared/AndroidManifest.xml b/samples/browseable/FindMyPhone/Shared/AndroidManifest.xml
new file mode 100644
index 0000000..80efe2e
--- /dev/null
+++ b/samples/browseable/FindMyPhone/Shared/AndroidManifest.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.findphone.common">
+
+ <application android:allowBackup="true"
+ android:label="@string/app_name">
+ </application>
+
+</manifest>
diff --git a/samples/browseable/FindMyPhone/Shared/res/values/strings.xml b/samples/browseable/FindMyPhone/Shared/res/values/strings.xml
new file mode 100644
index 0000000..0f2bb90
--- /dev/null
+++ b/samples/browseable/FindMyPhone/Shared/res/values/strings.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<resources>
+ <string name="app_name">Shared</string>
+</resources>
diff --git a/samples/browseable/FindMyPhone/Wearable/AndroidManifest.xml b/samples/browseable/FindMyPhone/Wearable/AndroidManifest.xml
new file mode 100644
index 0000000..b81dd33
--- /dev/null
+++ b/samples/browseable/FindMyPhone/Wearable/AndroidManifest.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.findphone" >
+
+ <uses-sdk android:minSdkVersion="20"
+ android:targetSdkVersion="20" />
+
+ <uses-permission android:name="android.permission.VIBRATE" />
+ <uses-feature android:name="android.hardware.type.watch" />
+
+ <application
+ android:allowBackup="true"
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name"
+ android:theme="@android:style/Theme.DeviceDefault" >
+
+ <meta-data
+ android:name="com.google.android.gms.version"
+ android:value="@integer/google_play_services_version" />
+
+ <service android:name=".DisconnectListenerService" >
+ <intent-filter>
+ <action android:name="com.google.android.gms.wearable.BIND_LISTENER" />
+ </intent-filter>
+ </service>
+
+ <service android:name="com.example.android.findphone.FindPhoneService"/>
+
+ <activity
+ android:name=".FindPhoneActivity"
+ android:label="@string/app_name" >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ </activity>
+ </application>
+
+</manifest>
diff --git a/samples/browseable/FindMyPhone/Wearable/res/drawable-hdpi/alarm_action_icon.png b/samples/browseable/FindMyPhone/Wearable/res/drawable-hdpi/alarm_action_icon.png
new file mode 100644
index 0000000..4331a51
--- /dev/null
+++ b/samples/browseable/FindMyPhone/Wearable/res/drawable-hdpi/alarm_action_icon.png
Binary files differ
diff --git a/samples/browseable/FindMyPhone/Wearable/res/drawable-hdpi/ic_launcher.png b/samples/browseable/FindMyPhone/Wearable/res/drawable-hdpi/ic_launcher.png
new file mode 100644
index 0000000..43254bd
--- /dev/null
+++ b/samples/browseable/FindMyPhone/Wearable/res/drawable-hdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/FindMyPhone/Wearable/res/drawable-mdpi/ic_launcher.png b/samples/browseable/FindMyPhone/Wearable/res/drawable-mdpi/ic_launcher.png
new file mode 100644
index 0000000..de255d6
--- /dev/null
+++ b/samples/browseable/FindMyPhone/Wearable/res/drawable-mdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/FindMyPhone/Wearable/res/drawable-xhdpi/ic_launcher.png b/samples/browseable/FindMyPhone/Wearable/res/drawable-xhdpi/ic_launcher.png
new file mode 100644
index 0000000..5a849da
--- /dev/null
+++ b/samples/browseable/FindMyPhone/Wearable/res/drawable-xhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/FindMyPhone/Wearable/res/drawable-xxhdpi/ic_launcher.png b/samples/browseable/FindMyPhone/Wearable/res/drawable-xxhdpi/ic_launcher.png
new file mode 100644
index 0000000..96a7cb8
--- /dev/null
+++ b/samples/browseable/FindMyPhone/Wearable/res/drawable-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/FindMyPhone/Wearable/res/values/strings.xml b/samples/browseable/FindMyPhone/Wearable/res/values/strings.xml
new file mode 100644
index 0000000..5c6debe
--- /dev/null
+++ b/samples/browseable/FindMyPhone/Wearable/res/values/strings.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+
+ <string name="app_name">Find My Phone</string>
+ <string name="left_phone_title">Forgetting something?</string>
+ <string name="left_phone_content">You may have left your phone behind.</string>
+ <string name="turn_alarm_on">Tap to sound an alarm on phone.</string>
+ <string name="turn_alarm_off">Tap to stop the alarm.</string>
+
+</resources>
diff --git a/samples/browseable/FindMyPhone/Wearable/src/com.example.android.findphone/DisconnectListenerService.java b/samples/browseable/FindMyPhone/Wearable/src/com.example.android.findphone/DisconnectListenerService.java
new file mode 100644
index 0000000..749a38d
--- /dev/null
+++ b/samples/browseable/FindMyPhone/Wearable/src/com.example.android.findphone/DisconnectListenerService.java
@@ -0,0 +1,55 @@
+/*
+ * 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.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/browseable/FindMyPhone/Wearable/src/com.example.android.findphone/FindPhoneActivity.java b/samples/browseable/FindMyPhone/Wearable/src/com.example.android.findphone/FindPhoneActivity.java
new file mode 100644
index 0000000..8251bab
--- /dev/null
+++ b/samples/browseable/FindMyPhone/Wearable/src/com.example.android.findphone/FindPhoneActivity.java
@@ -0,0 +1,87 @@
+/*
+ * 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.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());
+ }
+
+}
diff --git a/samples/browseable/FindMyPhone/Wearable/src/com.example.android.findphone/FindPhoneService.java b/samples/browseable/FindMyPhone/Wearable/src/com.example.android.findphone/FindPhoneService.java
new file mode 100644
index 0000000..cb9f961
--- /dev/null
+++ b/samples/browseable/FindMyPhone/Wearable/src/com.example.android.findphone/FindPhoneService.java
@@ -0,0 +1,121 @@
+/*
+ * 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.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/browseable/FindMyPhone/_index.jd b/samples/browseable/FindMyPhone/_index.jd
new file mode 100644
index 0000000..ed504c9
--- /dev/null
+++ b/samples/browseable/FindMyPhone/_index.jd
@@ -0,0 +1,12 @@
+page.tags="FindMyPhone"
+sample.group=Wearable
+@jd:body
+
+<p>
+
+ This sample application notifies you when you may have left your phone behind
+ (specifically, when your companion and wearable disconnect). If you have misplaced your phone, but
+ it is still connected to your wearable, you can also start an activity on the wearable to sound an
+ alarm on your phone.
+
+ </p>
diff --git a/samples/browseable/Flashlight/Application/AndroidManifest.xml b/samples/browseable/Flashlight/Application/AndroidManifest.xml
new file mode 100644
index 0000000..2710313
--- /dev/null
+++ b/samples/browseable/Flashlight/Application/AndroidManifest.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.flashlight">
+
+ <uses-sdk android:minSdkVersion="19"
+ android:targetSdkVersion="19" />
+
+ <application android:allowBackup="true"
+ android:label="@string/app_name">
+ </application>
+
+</manifest>
+
diff --git a/samples/browseable/Flashlight/Application/res/drawable-hdpi/tile.9.png b/samples/browseable/Flashlight/Application/res/drawable-hdpi/tile.9.png
new file mode 100644
index 0000000..1358628
--- /dev/null
+++ b/samples/browseable/Flashlight/Application/res/drawable-hdpi/tile.9.png
Binary files differ
diff --git a/samples/browseable/Flashlight/Application/res/layout/activity_main.xml b/samples/browseable/Flashlight/Application/res/layout/activity_main.xml
new file mode 100755
index 0000000..be1aa49
--- /dev/null
+++ b/samples/browseable/Flashlight/Application/res/layout/activity_main.xml
@@ -0,0 +1,36 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <LinearLayout style="@style/Widget.SampleMessageTile"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+
+ <TextView style="@style/Widget.SampleMessage"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="@dimen/horizontal_page_margin"
+ android:layout_marginRight="@dimen/horizontal_page_margin"
+ android:layout_marginTop="@dimen/vertical_page_margin"
+ android:layout_marginBottom="@dimen/vertical_page_margin"
+ android:text="@string/intro_message" />
+ </LinearLayout>
+</LinearLayout>
diff --git a/samples/browseable/Flashlight/Application/res/values-sw600dp/template-dimens.xml b/samples/browseable/Flashlight/Application/res/values-sw600dp/template-dimens.xml
new file mode 100644
index 0000000..22074a2
--- /dev/null
+++ b/samples/browseable/Flashlight/Application/res/values-sw600dp/template-dimens.xml
@@ -0,0 +1,24 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Semantic definitions -->
+
+ <dimen name="horizontal_page_margin">@dimen/margin_huge</dimen>
+ <dimen name="vertical_page_margin">@dimen/margin_medium</dimen>
+
+</resources>
diff --git a/samples/browseable/Flashlight/Application/res/values-sw600dp/template-styles.xml b/samples/browseable/Flashlight/Application/res/values-sw600dp/template-styles.xml
new file mode 100644
index 0000000..03d1974
--- /dev/null
+++ b/samples/browseable/Flashlight/Application/res/values-sw600dp/template-styles.xml
@@ -0,0 +1,25 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <style name="Widget.SampleMessage">
+ <item name="android:textAppearance">?android:textAppearanceLarge</item>
+ <item name="android:lineSpacingMultiplier">1.2</item>
+ <item name="android:shadowDy">-6.5</item>
+ </style>
+
+</resources>
diff --git a/samples/browseable/Flashlight/Application/res/values-v11/template-styles.xml b/samples/browseable/Flashlight/Application/res/values-v11/template-styles.xml
new file mode 100644
index 0000000..8c1ea66
--- /dev/null
+++ b/samples/browseable/Flashlight/Application/res/values-v11/template-styles.xml
@@ -0,0 +1,22 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Activity themes -->
+ <style name="Theme.Base" parent="android:Theme.Holo.Light" />
+
+</resources>
diff --git a/samples/browseable/Flashlight/Application/res/values/base-strings.xml b/samples/browseable/Flashlight/Application/res/values/base-strings.xml
new file mode 100644
index 0000000..f0f3d9d
--- /dev/null
+++ b/samples/browseable/Flashlight/Application/res/values/base-strings.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 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.
+-->
+<resources>
+ <string name="app_name">Flashlight</string>
+ <string name="intro_message">
+ <![CDATA[
+
+
+ Wearable activity that uses your wearable screen as a flashlight. There is also
+ a party-mode option, if you want to make things interesting.
+
+
+ ]]>
+ </string>
+</resources>
diff --git a/samples/browseable/Flashlight/Application/res/values/template-dimens.xml b/samples/browseable/Flashlight/Application/res/values/template-dimens.xml
new file mode 100644
index 0000000..39e710b
--- /dev/null
+++ b/samples/browseable/Flashlight/Application/res/values/template-dimens.xml
@@ -0,0 +1,32 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Define standard dimensions to comply with Holo-style grids and rhythm. -->
+
+ <dimen name="margin_tiny">4dp</dimen>
+ <dimen name="margin_small">8dp</dimen>
+ <dimen name="margin_medium">16dp</dimen>
+ <dimen name="margin_large">32dp</dimen>
+ <dimen name="margin_huge">64dp</dimen>
+
+ <!-- Semantic definitions -->
+
+ <dimen name="horizontal_page_margin">@dimen/margin_medium</dimen>
+ <dimen name="vertical_page_margin">@dimen/margin_medium</dimen>
+
+</resources>
diff --git a/samples/browseable/Flashlight/Application/res/values/template-styles.xml b/samples/browseable/Flashlight/Application/res/values/template-styles.xml
new file mode 100644
index 0000000..6e7d593
--- /dev/null
+++ b/samples/browseable/Flashlight/Application/res/values/template-styles.xml
@@ -0,0 +1,42 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Activity themes -->
+
+ <style name="Theme.Base" parent="android:Theme.Light" />
+
+ <style name="Theme.Sample" parent="Theme.Base" />
+
+ <style name="AppTheme" parent="Theme.Sample" />
+ <!-- Widget styling -->
+
+ <style name="Widget" />
+
+ <style name="Widget.SampleMessage">
+ <item name="android:textAppearance">?android:textAppearanceMedium</item>
+ <item name="android:lineSpacingMultiplier">1.1</item>
+ </style>
+
+ <style name="Widget.SampleMessageTile">
+ <item name="android:background">@drawable/tile</item>
+ <item name="android:shadowColor">#7F000000</item>
+ <item name="android:shadowDy">-3.5</item>
+ <item name="android:shadowRadius">2</item>
+ </style>
+
+</resources>
diff --git a/samples/browseable/Flashlight/Application/src/com.example.android.common/activities/SampleActivityBase.java b/samples/browseable/Flashlight/Application/src/com.example.android.common/activities/SampleActivityBase.java
new file mode 100644
index 0000000..3228927
--- /dev/null
+++ b/samples/browseable/Flashlight/Application/src/com.example.android.common/activities/SampleActivityBase.java
@@ -0,0 +1,52 @@
+/*
+* Copyright 2013 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.common.activities;
+
+import android.os.Bundle;
+import android.support.v4.app.FragmentActivity;
+
+import com.example.android.common.logger.Log;
+import com.example.android.common.logger.LogWrapper;
+
+/**
+ * Base launcher activity, to handle most of the common plumbing for samples.
+ */
+public class SampleActivityBase extends FragmentActivity {
+
+ public static final String TAG = "SampleActivityBase";
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ initializeLogging();
+ }
+
+ /** Set up targets to receive log data */
+ public void initializeLogging() {
+ // Using Log, front-end to the logging chain, emulates android.util.log method signatures.
+ // Wraps Android's native log framework
+ LogWrapper logWrapper = new LogWrapper();
+ Log.setLogNode(logWrapper);
+
+ Log.i(TAG, "Ready");
+ }
+}
diff --git a/samples/browseable/Flashlight/Application/src/com.example.android.common/logger/Log.java b/samples/browseable/Flashlight/Application/src/com.example.android.common/logger/Log.java
new file mode 100644
index 0000000..17503c5
--- /dev/null
+++ b/samples/browseable/Flashlight/Application/src/com.example.android.common/logger/Log.java
@@ -0,0 +1,236 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+/**
+ * Helper class for a list (or tree) of LoggerNodes.
+ *
+ * <p>When this is set as the head of the list,
+ * an instance of it can function as a drop-in replacement for {@link android.util.Log}.
+ * Most of the methods in this class server only to map a method call in Log to its equivalent
+ * in LogNode.</p>
+ */
+public class Log {
+ // Grabbing the native values from Android's native logging facilities,
+ // to make for easy migration and interop.
+ public static final int NONE = -1;
+ public static final int VERBOSE = android.util.Log.VERBOSE;
+ public static final int DEBUG = android.util.Log.DEBUG;
+ public static final int INFO = android.util.Log.INFO;
+ public static final int WARN = android.util.Log.WARN;
+ public static final int ERROR = android.util.Log.ERROR;
+ public static final int ASSERT = android.util.Log.ASSERT;
+
+ // Stores the beginning of the LogNode topology.
+ private static LogNode mLogNode;
+
+ /**
+ * Returns the next LogNode in the linked list.
+ */
+ public static LogNode getLogNode() {
+ return mLogNode;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to.
+ */
+ public static void setLogNode(LogNode node) {
+ mLogNode = node;
+ }
+
+ /**
+ * Instructs the LogNode to print the log data provided. Other LogNodes can
+ * be chained to the end of the LogNode as desired.
+ *
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void println(int priority, String tag, String msg, Throwable tr) {
+ if (mLogNode != null) {
+ mLogNode.println(priority, tag, msg, tr);
+ }
+ }
+
+ /**
+ * Instructs the LogNode to print the log data provided. Other LogNodes can
+ * be chained to the end of the LogNode as desired.
+ *
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ */
+ public static void println(int priority, String tag, String msg) {
+ println(priority, tag, msg, null);
+ }
+
+ /**
+ * Prints a message at VERBOSE priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void v(String tag, String msg, Throwable tr) {
+ println(VERBOSE, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at VERBOSE priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void v(String tag, String msg) {
+ v(tag, msg, null);
+ }
+
+
+ /**
+ * Prints a message at DEBUG priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void d(String tag, String msg, Throwable tr) {
+ println(DEBUG, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at DEBUG priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void d(String tag, String msg) {
+ d(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at INFO priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void i(String tag, String msg, Throwable tr) {
+ println(INFO, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at INFO priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void i(String tag, String msg) {
+ i(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void w(String tag, String msg, Throwable tr) {
+ println(WARN, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void w(String tag, String msg) {
+ w(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void w(String tag, Throwable tr) {
+ w(tag, null, tr);
+ }
+
+ /**
+ * Prints a message at ERROR priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void e(String tag, String msg, Throwable tr) {
+ println(ERROR, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at ERROR priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void e(String tag, String msg) {
+ e(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void wtf(String tag, String msg, Throwable tr) {
+ println(ASSERT, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void wtf(String tag, String msg) {
+ wtf(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void wtf(String tag, Throwable tr) {
+ wtf(tag, null, tr);
+ }
+}
diff --git a/samples/browseable/Flashlight/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/Flashlight/Application/src/com.example.android.common/logger/LogFragment.java
new file mode 100644
index 0000000..b302acd
--- /dev/null
+++ b/samples/browseable/Flashlight/Application/src/com.example.android.common/logger/LogFragment.java
@@ -0,0 +1,109 @@
+/*
+* Copyright 2013 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.
+*/
+/*
+ * Copyright 2013 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.common.logger;
+
+import android.graphics.Typeface;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ScrollView;
+
+/**
+ * Simple fraggment which contains a LogView and uses is to output log data it receives
+ * through the LogNode interface.
+ */
+public class LogFragment extends Fragment {
+
+ private LogView mLogView;
+ private ScrollView mScrollView;
+
+ public LogFragment() {}
+
+ public View inflateViews() {
+ mScrollView = new ScrollView(getActivity());
+ ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT);
+ mScrollView.setLayoutParams(scrollParams);
+
+ mLogView = new LogView(getActivity());
+ ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams);
+ logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
+ mLogView.setLayoutParams(logParams);
+ mLogView.setClickable(true);
+ mLogView.setFocusable(true);
+ mLogView.setTypeface(Typeface.MONOSPACE);
+
+ // Want to set padding as 16 dips, setPadding takes pixels. Hooray math!
+ int paddingDips = 16;
+ double scale = getResources().getDisplayMetrics().density;
+ int paddingPixels = (int) ((paddingDips * (scale)) + .5);
+ mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels);
+ mLogView.setCompoundDrawablePadding(paddingPixels);
+
+ mLogView.setGravity(Gravity.BOTTOM);
+ mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium);
+
+ mScrollView.addView(mLogView);
+ return mScrollView;
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+
+ View result = inflateViews();
+
+ mLogView.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {}
+
+ @Override
+ public void afterTextChanged(Editable s) {
+ mScrollView.fullScroll(ScrollView.FOCUS_DOWN);
+ }
+ });
+ return result;
+ }
+
+ public LogView getLogView() {
+ return mLogView;
+ }
+}
\ No newline at end of file
diff --git a/samples/browseable/Flashlight/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/Flashlight/Application/src/com.example.android.common/logger/LogNode.java
new file mode 100644
index 0000000..bc37cab
--- /dev/null
+++ b/samples/browseable/Flashlight/Application/src/com.example.android.common/logger/LogNode.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2012 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.common.logger;
+
+/**
+ * Basic interface for a logging system that can output to one or more targets.
+ * Note that in addition to classes that will output these logs in some format,
+ * one can also implement this interface over a filter and insert that in the chain,
+ * such that no targets further down see certain data, or see manipulated forms of the data.
+ * You could, for instance, write a "ToHtmlLoggerNode" that just converted all the log data
+ * it received to HTML and sent it along to the next node in the chain, without printing it
+ * anywhere.
+ */
+public interface LogNode {
+
+ /**
+ * Instructs first LogNode in the list to print the log data provided.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public void println(int priority, String tag, String msg, Throwable tr);
+
+}
diff --git a/samples/browseable/Flashlight/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/Flashlight/Application/src/com.example.android.common/logger/LogView.java
new file mode 100644
index 0000000..c01542b
--- /dev/null
+++ b/samples/browseable/Flashlight/Application/src/com.example.android.common/logger/LogView.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+import android.app.Activity;
+import android.content.Context;
+import android.util.*;
+import android.widget.TextView;
+
+/** Simple TextView which is used to output log data received through the LogNode interface.
+*/
+public class LogView extends TextView implements LogNode {
+
+ public LogView(Context context) {
+ super(context);
+ }
+
+ public LogView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public LogView(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ /**
+ * Formats the log data and prints it out to the LogView.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+
+
+ String priorityStr = null;
+
+ // For the purposes of this View, we want to print the priority as readable text.
+ switch(priority) {
+ case android.util.Log.VERBOSE:
+ priorityStr = "VERBOSE";
+ break;
+ case android.util.Log.DEBUG:
+ priorityStr = "DEBUG";
+ break;
+ case android.util.Log.INFO:
+ priorityStr = "INFO";
+ break;
+ case android.util.Log.WARN:
+ priorityStr = "WARN";
+ break;
+ case android.util.Log.ERROR:
+ priorityStr = "ERROR";
+ break;
+ case android.util.Log.ASSERT:
+ priorityStr = "ASSERT";
+ break;
+ default:
+ break;
+ }
+
+ // Handily, the Log class has a facility for converting a stack trace into a usable string.
+ String exceptionStr = null;
+ if (tr != null) {
+ exceptionStr = android.util.Log.getStackTraceString(tr);
+ }
+
+ // Take the priority, tag, message, and exception, and concatenate as necessary
+ // into one usable line of text.
+ final StringBuilder outputBuilder = new StringBuilder();
+
+ String delimiter = "\t";
+ appendIfNotNull(outputBuilder, priorityStr, delimiter);
+ appendIfNotNull(outputBuilder, tag, delimiter);
+ appendIfNotNull(outputBuilder, msg, delimiter);
+ appendIfNotNull(outputBuilder, exceptionStr, delimiter);
+
+ // In case this was originally called from an AsyncTask or some other off-UI thread,
+ // make sure the update occurs within the UI thread.
+ ((Activity) getContext()).runOnUiThread( (new Thread(new Runnable() {
+ @Override
+ public void run() {
+ // Display the text we just generated within the LogView.
+ appendToLog(outputBuilder.toString());
+ }
+ })));
+
+ if (mNext != null) {
+ mNext.println(priority, tag, msg, tr);
+ }
+ }
+
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+ /** Takes a string and adds to it, with a separator, if the bit to be added isn't null. Since
+ * the logger takes so many arguments that might be null, this method helps cut out some of the
+ * agonizing tedium of writing the same 3 lines over and over.
+ * @param source StringBuilder containing the text to append to.
+ * @param addStr The String to append
+ * @param delimiter The String to separate the source and appended strings. A tab or comma,
+ * for instance.
+ * @return The fully concatenated String as a StringBuilder
+ */
+ private StringBuilder appendIfNotNull(StringBuilder source, String addStr, String delimiter) {
+ if (addStr != null) {
+ if (addStr.length() == 0) {
+ delimiter = "";
+ }
+
+ return source.append(addStr).append(delimiter);
+ }
+ return source;
+ }
+
+ // The next LogNode in the chain.
+ LogNode mNext;
+
+ /** Outputs the string as a new line of log data in the LogView. */
+ public void appendToLog(String s) {
+ append("\n" + s);
+ }
+
+
+}
diff --git a/samples/browseable/Flashlight/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/Flashlight/Application/src/com.example.android.common/logger/LogWrapper.java
new file mode 100644
index 0000000..16a9e7b
--- /dev/null
+++ b/samples/browseable/Flashlight/Application/src/com.example.android.common/logger/LogWrapper.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2012 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.common.logger;
+
+import android.util.Log;
+
+/**
+ * Helper class which wraps Android's native Log utility in the Logger interface. This way
+ * normal DDMS output can be one of the many targets receiving and outputting logs simultaneously.
+ */
+public class LogWrapper implements LogNode {
+
+ // For piping: The next node to receive Log data after this one has done its work.
+ private LogNode mNext;
+
+ /**
+ * Returns the next LogNode in the linked list.
+ */
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to..
+ */
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+ /**
+ * Prints data out to the console using Android's native log mechanism.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+ // There actually are log methods that don't take a msg parameter. For now,
+ // if that's the case, just convert null to the empty string and move on.
+ String useMsg = msg;
+ if (useMsg == null) {
+ useMsg = "";
+ }
+
+ // If an exeption was provided, convert that exception to a usable string and attach
+ // it to the end of the msg method.
+ if (tr != null) {
+ msg += "\n" + Log.getStackTraceString(tr);
+ }
+
+ // This is functionally identical to Log.x(tag, useMsg);
+ // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg)
+ Log.println(priority, tag, useMsg);
+
+ // If this isn't the last node in the chain, move things along.
+ if (mNext != null) {
+ mNext.println(priority, tag, msg, tr);
+ }
+ }
+}
diff --git a/samples/browseable/Flashlight/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/Flashlight/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java
new file mode 100644
index 0000000..19967dc
--- /dev/null
+++ b/samples/browseable/Flashlight/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+/**
+ * Simple {@link LogNode} filter, removes everything except the message.
+ * Useful for situations like on-screen log output where you don't want a lot of metadata displayed,
+ * just easy-to-read message updates as they're happening.
+ */
+public class MessageOnlyLogFilter implements LogNode {
+
+ LogNode mNext;
+
+ /**
+ * Takes the "next" LogNode as a parameter, to simplify chaining.
+ *
+ * @param next The next LogNode in the pipeline.
+ */
+ public MessageOnlyLogFilter(LogNode next) {
+ mNext = next;
+ }
+
+ public MessageOnlyLogFilter() {
+ }
+
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+ if (mNext != null) {
+ getNext().println(Log.NONE, null, msg, null);
+ }
+ }
+
+ /**
+ * Returns the next LogNode in the chain.
+ */
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to..
+ */
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+}
diff --git a/samples/browseable/Flashlight/Shared/AndroidManifest.xml b/samples/browseable/Flashlight/Shared/AndroidManifest.xml
new file mode 100644
index 0000000..c7893c7
--- /dev/null
+++ b/samples/browseable/Flashlight/Shared/AndroidManifest.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.flashlight.common">
+
+ <application android:allowBackup="true"
+ android:label="@string/app_name">
+ </application>
+
+</manifest>
diff --git a/samples/browseable/Flashlight/Shared/res/values/strings.xml b/samples/browseable/Flashlight/Shared/res/values/strings.xml
new file mode 100644
index 0000000..0f2bb90
--- /dev/null
+++ b/samples/browseable/Flashlight/Shared/res/values/strings.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<resources>
+ <string name="app_name">Shared</string>
+</resources>
diff --git a/samples/browseable/Flashlight/Wearable/AndroidManifest.xml b/samples/browseable/Flashlight/Wearable/AndroidManifest.xml
new file mode 100644
index 0000000..f22e1ab
--- /dev/null
+++ b/samples/browseable/Flashlight/Wearable/AndroidManifest.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.flashlight" >
+
+ <uses-sdk android:minSdkVersion="20"
+ android:targetSdkVersion="20" />
+
+ <uses-feature android:name="android.hardware.type.watch" />
+
+ <application
+ android:label="@string/app_name"
+ android:icon="@drawable/ic_launcher"
+ android:theme="@android:style/Theme.DeviceDefault" >
+ <activity android:name=".MainActivity"
+ android:label="@string/app_name"
+ android:launchMode="singleTop"
+ android:configChanges="orientation|keyboardHidden">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ </activity>
+ </application>
+</manifest>
diff --git a/samples/browseable/Flashlight/Wearable/res/drawable-hdpi/ic_launcher.png b/samples/browseable/Flashlight/Wearable/res/drawable-hdpi/ic_launcher.png
new file mode 100755
index 0000000..589f229
--- /dev/null
+++ b/samples/browseable/Flashlight/Wearable/res/drawable-hdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/Flashlight/Wearable/res/drawable-mdpi/ic_launcher.png b/samples/browseable/Flashlight/Wearable/res/drawable-mdpi/ic_launcher.png
new file mode 100755
index 0000000..77dd571
--- /dev/null
+++ b/samples/browseable/Flashlight/Wearable/res/drawable-mdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/Flashlight/Wearable/res/drawable-xhdpi/ic_launcher.png b/samples/browseable/Flashlight/Wearable/res/drawable-xhdpi/ic_launcher.png
new file mode 100755
index 0000000..fe34ebe
--- /dev/null
+++ b/samples/browseable/Flashlight/Wearable/res/drawable-xhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/Flashlight/Wearable/res/drawable-xxhdpi/ic_launcher.png b/samples/browseable/Flashlight/Wearable/res/drawable-xxhdpi/ic_launcher.png
new file mode 100755
index 0000000..ab80bcd
--- /dev/null
+++ b/samples/browseable/Flashlight/Wearable/res/drawable-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/Flashlight/Wearable/res/layout/main.xml b/samples/browseable/Flashlight/Wearable/res/layout/main.xml
new file mode 100644
index 0000000..1e10f5a
--- /dev/null
+++ b/samples/browseable/Flashlight/Wearable/res/layout/main.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<android.support.v4.view.ViewPager
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/pager"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="#000"
+ android:keepScreenOn="true"
+ />
diff --git a/samples/browseable/Flashlight/Wearable/res/layout/party_light.xml b/samples/browseable/Flashlight/Wearable/res/layout/party_light.xml
new file mode 100644
index 0000000..b29ef94
--- /dev/null
+++ b/samples/browseable/Flashlight/Wearable/res/layout/party_light.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<com.example.android.wearable.flashlight.PartyLightView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ />
diff --git a/samples/browseable/Flashlight/Wearable/res/layout/white_light.xml b/samples/browseable/Flashlight/Wearable/res/layout/white_light.xml
new file mode 100644
index 0000000..94353a2
--- /dev/null
+++ b/samples/browseable/Flashlight/Wearable/res/layout/white_light.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<View xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="#fff"
+ />
diff --git a/samples/browseable/Flashlight/Wearable/res/values/strings.xml b/samples/browseable/Flashlight/Wearable/res/values/strings.xml
new file mode 100644
index 0000000..6790e2d
--- /dev/null
+++ b/samples/browseable/Flashlight/Wearable/res/values/strings.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <!-- Name of the wearable app [CHAR LIMIT=NONE] -->
+ <string name="app_name">Flashlight</string>
+
+</resources>
diff --git a/samples/browseable/Flashlight/Wearable/src/com.example.android.flashlight/MainActivity.java b/samples/browseable/Flashlight/Wearable/src/com.example.android.flashlight/MainActivity.java
new file mode 100644
index 0000000..9e4bae5
--- /dev/null
+++ b/samples/browseable/Flashlight/Wearable/src/com.example.android.flashlight/MainActivity.java
@@ -0,0 +1,125 @@
+/*
+ * 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.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<Fragment> mFragments;
+
+ public LightFragmentAdapter(FragmentManager fm) {
+ super(fm);
+ mFragments = new ArrayList<Fragment>();
+ }
+
+ @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();
+ }
+ }
+
+ public static class WhiteLightFragment extends Fragment {
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ return inflater.inflate(R.layout.white_light, container, false);
+ }
+ }
+
+ public 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/browseable/Flashlight/Wearable/src/com.example.android.flashlight/PartyLightView.java b/samples/browseable/Flashlight/Wearable/src/com.example.android.flashlight/PartyLightView.java
new file mode 100644
index 0000000..02247d6
--- /dev/null
+++ b/samples/browseable/Flashlight/Wearable/src/com.example.android.flashlight/PartyLightView.java
@@ -0,0 +1,120 @@
+/*
+ * 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.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/browseable/Flashlight/_index.jd b/samples/browseable/Flashlight/_index.jd
new file mode 100644
index 0000000..d691b73
--- /dev/null
+++ b/samples/browseable/Flashlight/_index.jd
@@ -0,0 +1,10 @@
+page.tags="Flashlight"
+sample.group=Wearable
+@jd:body
+
+<p>
+
+ Wearable activity that uses your wearable screen as a flashlight. There is also
+ a party-mode option, if you want to make things interesting.
+
+ </p>
diff --git a/samples/browseable/Geofencing/Application/AndroidManifest.xml b/samples/browseable/Geofencing/Application/AndroidManifest.xml
new file mode 100644
index 0000000..519aa14
--- /dev/null
+++ b/samples/browseable/Geofencing/Application/AndroidManifest.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.geofencing">
+
+ <uses-sdk android:minSdkVersion="19"
+ android:targetSdkVersion="19" />
+
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
+
+ <application
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name"
+ android:theme="@android:style/Theme.Holo.Light"
+ android:allowBackup="true">
+
+ <meta-data
+ android:name="com.google.android.gms.version"
+ android:value="@integer/google_play_services_version"/>
+
+ <activity
+ android:name=".MainActivity"
+ android:label="@string/app_name"
+ android:theme="@android:style/Theme.Translucent.NoTitleBar"
+ android:excludeFromRecents="true">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ </activity>
+
+ <service
+ android:name=".GeofenceTransitionsIntentService"
+ android:exported="false">
+ </service>
+ </application>
+</manifest>
diff --git a/samples/browseable/Geofencing/Application/res/drawable-hdpi/ic_launcher.png b/samples/browseable/Geofencing/Application/res/drawable-hdpi/ic_launcher.png
new file mode 100644
index 0000000..4e3e000
--- /dev/null
+++ b/samples/browseable/Geofencing/Application/res/drawable-hdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/Geofencing/Application/res/drawable-hdpi/tile.9.png b/samples/browseable/Geofencing/Application/res/drawable-hdpi/tile.9.png
new file mode 100644
index 0000000..1358628
--- /dev/null
+++ b/samples/browseable/Geofencing/Application/res/drawable-hdpi/tile.9.png
Binary files differ
diff --git a/samples/browseable/Geofencing/Application/res/drawable-mdpi/ic_launcher.png b/samples/browseable/Geofencing/Application/res/drawable-mdpi/ic_launcher.png
new file mode 100644
index 0000000..b405cb2
--- /dev/null
+++ b/samples/browseable/Geofencing/Application/res/drawable-mdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/Geofencing/Application/res/drawable-xhdpi/ic_launcher.png b/samples/browseable/Geofencing/Application/res/drawable-xhdpi/ic_launcher.png
new file mode 100644
index 0000000..61f9d88
--- /dev/null
+++ b/samples/browseable/Geofencing/Application/res/drawable-xhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/Geofencing/Application/res/drawable-xxhdpi/ic_launcher.png b/samples/browseable/Geofencing/Application/res/drawable-xxhdpi/ic_launcher.png
new file mode 100644
index 0000000..81c1008
--- /dev/null
+++ b/samples/browseable/Geofencing/Application/res/drawable-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/Geofencing/Application/res/layout/activity_main.xml b/samples/browseable/Geofencing/Application/res/layout/activity_main.xml
new file mode 100755
index 0000000..be1aa49
--- /dev/null
+++ b/samples/browseable/Geofencing/Application/res/layout/activity_main.xml
@@ -0,0 +1,36 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <LinearLayout style="@style/Widget.SampleMessageTile"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+
+ <TextView style="@style/Widget.SampleMessage"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="@dimen/horizontal_page_margin"
+ android:layout_marginRight="@dimen/horizontal_page_margin"
+ android:layout_marginTop="@dimen/vertical_page_margin"
+ android:layout_marginBottom="@dimen/vertical_page_margin"
+ android:text="@string/intro_message" />
+ </LinearLayout>
+</LinearLayout>
diff --git a/samples/browseable/Geofencing/Application/res/values-sw600dp/template-dimens.xml b/samples/browseable/Geofencing/Application/res/values-sw600dp/template-dimens.xml
new file mode 100644
index 0000000..22074a2
--- /dev/null
+++ b/samples/browseable/Geofencing/Application/res/values-sw600dp/template-dimens.xml
@@ -0,0 +1,24 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Semantic definitions -->
+
+ <dimen name="horizontal_page_margin">@dimen/margin_huge</dimen>
+ <dimen name="vertical_page_margin">@dimen/margin_medium</dimen>
+
+</resources>
diff --git a/samples/browseable/Geofencing/Application/res/values-sw600dp/template-styles.xml b/samples/browseable/Geofencing/Application/res/values-sw600dp/template-styles.xml
new file mode 100644
index 0000000..03d1974
--- /dev/null
+++ b/samples/browseable/Geofencing/Application/res/values-sw600dp/template-styles.xml
@@ -0,0 +1,25 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <style name="Widget.SampleMessage">
+ <item name="android:textAppearance">?android:textAppearanceLarge</item>
+ <item name="android:lineSpacingMultiplier">1.2</item>
+ <item name="android:shadowDy">-6.5</item>
+ </style>
+
+</resources>
diff --git a/samples/browseable/Geofencing/Application/res/values-v11/template-styles.xml b/samples/browseable/Geofencing/Application/res/values-v11/template-styles.xml
new file mode 100644
index 0000000..8c1ea66
--- /dev/null
+++ b/samples/browseable/Geofencing/Application/res/values-v11/template-styles.xml
@@ -0,0 +1,22 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Activity themes -->
+ <style name="Theme.Base" parent="android:Theme.Holo.Light" />
+
+</resources>
diff --git a/samples/browseable/Geofencing/Application/res/values/base-strings.xml b/samples/browseable/Geofencing/Application/res/values/base-strings.xml
new file mode 100644
index 0000000..5a66931
--- /dev/null
+++ b/samples/browseable/Geofencing/Application/res/values/base-strings.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 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.
+-->
+<resources>
+ <string name="app_name">Geofencing</string>
+ <string name="intro_message">
+ <![CDATA[
+
+
+ When a user enters the vicinity of the Android building (B44) or the Yerba Buena
+ Gardens near the Moscone center in San Francisco, a notification silently appears on his/her
+ wearable with an option to check in. This notification automatically disappears when he/she leaves
+ the area, and reappears the next time he/she is at one of these locations.
+
+
+ ]]>
+ </string>
+</resources>
diff --git a/samples/browseable/Geofencing/Application/res/values/strings.xml b/samples/browseable/Geofencing/Application/res/values/strings.xml
new file mode 100644
index 0000000..ad9717b
--- /dev/null
+++ b/samples/browseable/Geofencing/Application/res/values/strings.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <string name="start_geofence_service">Starting geofence transition service</string>
+</resources>
diff --git a/samples/browseable/Geofencing/Application/res/values/template-dimens.xml b/samples/browseable/Geofencing/Application/res/values/template-dimens.xml
new file mode 100644
index 0000000..39e710b
--- /dev/null
+++ b/samples/browseable/Geofencing/Application/res/values/template-dimens.xml
@@ -0,0 +1,32 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Define standard dimensions to comply with Holo-style grids and rhythm. -->
+
+ <dimen name="margin_tiny">4dp</dimen>
+ <dimen name="margin_small">8dp</dimen>
+ <dimen name="margin_medium">16dp</dimen>
+ <dimen name="margin_large">32dp</dimen>
+ <dimen name="margin_huge">64dp</dimen>
+
+ <!-- Semantic definitions -->
+
+ <dimen name="horizontal_page_margin">@dimen/margin_medium</dimen>
+ <dimen name="vertical_page_margin">@dimen/margin_medium</dimen>
+
+</resources>
diff --git a/samples/browseable/Geofencing/Application/res/values/template-styles.xml b/samples/browseable/Geofencing/Application/res/values/template-styles.xml
new file mode 100644
index 0000000..6e7d593
--- /dev/null
+++ b/samples/browseable/Geofencing/Application/res/values/template-styles.xml
@@ -0,0 +1,42 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Activity themes -->
+
+ <style name="Theme.Base" parent="android:Theme.Light" />
+
+ <style name="Theme.Sample" parent="Theme.Base" />
+
+ <style name="AppTheme" parent="Theme.Sample" />
+ <!-- Widget styling -->
+
+ <style name="Widget" />
+
+ <style name="Widget.SampleMessage">
+ <item name="android:textAppearance">?android:textAppearanceMedium</item>
+ <item name="android:lineSpacingMultiplier">1.1</item>
+ </style>
+
+ <style name="Widget.SampleMessageTile">
+ <item name="android:background">@drawable/tile</item>
+ <item name="android:shadowColor">#7F000000</item>
+ <item name="android:shadowDy">-3.5</item>
+ <item name="android:shadowRadius">2</item>
+ </style>
+
+</resources>
diff --git a/samples/browseable/Geofencing/Application/src/com.example.android.common/activities/SampleActivityBase.java b/samples/browseable/Geofencing/Application/src/com.example.android.common/activities/SampleActivityBase.java
new file mode 100644
index 0000000..3228927
--- /dev/null
+++ b/samples/browseable/Geofencing/Application/src/com.example.android.common/activities/SampleActivityBase.java
@@ -0,0 +1,52 @@
+/*
+* Copyright 2013 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.common.activities;
+
+import android.os.Bundle;
+import android.support.v4.app.FragmentActivity;
+
+import com.example.android.common.logger.Log;
+import com.example.android.common.logger.LogWrapper;
+
+/**
+ * Base launcher activity, to handle most of the common plumbing for samples.
+ */
+public class SampleActivityBase extends FragmentActivity {
+
+ public static final String TAG = "SampleActivityBase";
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ initializeLogging();
+ }
+
+ /** Set up targets to receive log data */
+ public void initializeLogging() {
+ // Using Log, front-end to the logging chain, emulates android.util.log method signatures.
+ // Wraps Android's native log framework
+ LogWrapper logWrapper = new LogWrapper();
+ Log.setLogNode(logWrapper);
+
+ Log.i(TAG, "Ready");
+ }
+}
diff --git a/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/Log.java b/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/Log.java
new file mode 100644
index 0000000..17503c5
--- /dev/null
+++ b/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/Log.java
@@ -0,0 +1,236 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+/**
+ * Helper class for a list (or tree) of LoggerNodes.
+ *
+ * <p>When this is set as the head of the list,
+ * an instance of it can function as a drop-in replacement for {@link android.util.Log}.
+ * Most of the methods in this class server only to map a method call in Log to its equivalent
+ * in LogNode.</p>
+ */
+public class Log {
+ // Grabbing the native values from Android's native logging facilities,
+ // to make for easy migration and interop.
+ public static final int NONE = -1;
+ public static final int VERBOSE = android.util.Log.VERBOSE;
+ public static final int DEBUG = android.util.Log.DEBUG;
+ public static final int INFO = android.util.Log.INFO;
+ public static final int WARN = android.util.Log.WARN;
+ public static final int ERROR = android.util.Log.ERROR;
+ public static final int ASSERT = android.util.Log.ASSERT;
+
+ // Stores the beginning of the LogNode topology.
+ private static LogNode mLogNode;
+
+ /**
+ * Returns the next LogNode in the linked list.
+ */
+ public static LogNode getLogNode() {
+ return mLogNode;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to.
+ */
+ public static void setLogNode(LogNode node) {
+ mLogNode = node;
+ }
+
+ /**
+ * Instructs the LogNode to print the log data provided. Other LogNodes can
+ * be chained to the end of the LogNode as desired.
+ *
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void println(int priority, String tag, String msg, Throwable tr) {
+ if (mLogNode != null) {
+ mLogNode.println(priority, tag, msg, tr);
+ }
+ }
+
+ /**
+ * Instructs the LogNode to print the log data provided. Other LogNodes can
+ * be chained to the end of the LogNode as desired.
+ *
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ */
+ public static void println(int priority, String tag, String msg) {
+ println(priority, tag, msg, null);
+ }
+
+ /**
+ * Prints a message at VERBOSE priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void v(String tag, String msg, Throwable tr) {
+ println(VERBOSE, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at VERBOSE priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void v(String tag, String msg) {
+ v(tag, msg, null);
+ }
+
+
+ /**
+ * Prints a message at DEBUG priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void d(String tag, String msg, Throwable tr) {
+ println(DEBUG, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at DEBUG priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void d(String tag, String msg) {
+ d(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at INFO priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void i(String tag, String msg, Throwable tr) {
+ println(INFO, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at INFO priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void i(String tag, String msg) {
+ i(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void w(String tag, String msg, Throwable tr) {
+ println(WARN, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void w(String tag, String msg) {
+ w(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void w(String tag, Throwable tr) {
+ w(tag, null, tr);
+ }
+
+ /**
+ * Prints a message at ERROR priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void e(String tag, String msg, Throwable tr) {
+ println(ERROR, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at ERROR priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void e(String tag, String msg) {
+ e(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void wtf(String tag, String msg, Throwable tr) {
+ println(ASSERT, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void wtf(String tag, String msg) {
+ wtf(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void wtf(String tag, Throwable tr) {
+ wtf(tag, null, tr);
+ }
+}
diff --git a/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/LogFragment.java
new file mode 100644
index 0000000..b302acd
--- /dev/null
+++ b/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/LogFragment.java
@@ -0,0 +1,109 @@
+/*
+* Copyright 2013 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.
+*/
+/*
+ * Copyright 2013 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.common.logger;
+
+import android.graphics.Typeface;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ScrollView;
+
+/**
+ * Simple fraggment which contains a LogView and uses is to output log data it receives
+ * through the LogNode interface.
+ */
+public class LogFragment extends Fragment {
+
+ private LogView mLogView;
+ private ScrollView mScrollView;
+
+ public LogFragment() {}
+
+ public View inflateViews() {
+ mScrollView = new ScrollView(getActivity());
+ ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT);
+ mScrollView.setLayoutParams(scrollParams);
+
+ mLogView = new LogView(getActivity());
+ ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams);
+ logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
+ mLogView.setLayoutParams(logParams);
+ mLogView.setClickable(true);
+ mLogView.setFocusable(true);
+ mLogView.setTypeface(Typeface.MONOSPACE);
+
+ // Want to set padding as 16 dips, setPadding takes pixels. Hooray math!
+ int paddingDips = 16;
+ double scale = getResources().getDisplayMetrics().density;
+ int paddingPixels = (int) ((paddingDips * (scale)) + .5);
+ mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels);
+ mLogView.setCompoundDrawablePadding(paddingPixels);
+
+ mLogView.setGravity(Gravity.BOTTOM);
+ mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium);
+
+ mScrollView.addView(mLogView);
+ return mScrollView;
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+
+ View result = inflateViews();
+
+ mLogView.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {}
+
+ @Override
+ public void afterTextChanged(Editable s) {
+ mScrollView.fullScroll(ScrollView.FOCUS_DOWN);
+ }
+ });
+ return result;
+ }
+
+ public LogView getLogView() {
+ return mLogView;
+ }
+}
\ No newline at end of file
diff --git a/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/LogNode.java
new file mode 100644
index 0000000..bc37cab
--- /dev/null
+++ b/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/LogNode.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2012 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.common.logger;
+
+/**
+ * Basic interface for a logging system that can output to one or more targets.
+ * Note that in addition to classes that will output these logs in some format,
+ * one can also implement this interface over a filter and insert that in the chain,
+ * such that no targets further down see certain data, or see manipulated forms of the data.
+ * You could, for instance, write a "ToHtmlLoggerNode" that just converted all the log data
+ * it received to HTML and sent it along to the next node in the chain, without printing it
+ * anywhere.
+ */
+public interface LogNode {
+
+ /**
+ * Instructs first LogNode in the list to print the log data provided.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public void println(int priority, String tag, String msg, Throwable tr);
+
+}
diff --git a/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/LogView.java
new file mode 100644
index 0000000..c01542b
--- /dev/null
+++ b/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/LogView.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+import android.app.Activity;
+import android.content.Context;
+import android.util.*;
+import android.widget.TextView;
+
+/** Simple TextView which is used to output log data received through the LogNode interface.
+*/
+public class LogView extends TextView implements LogNode {
+
+ public LogView(Context context) {
+ super(context);
+ }
+
+ public LogView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public LogView(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ /**
+ * Formats the log data and prints it out to the LogView.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+
+
+ String priorityStr = null;
+
+ // For the purposes of this View, we want to print the priority as readable text.
+ switch(priority) {
+ case android.util.Log.VERBOSE:
+ priorityStr = "VERBOSE";
+ break;
+ case android.util.Log.DEBUG:
+ priorityStr = "DEBUG";
+ break;
+ case android.util.Log.INFO:
+ priorityStr = "INFO";
+ break;
+ case android.util.Log.WARN:
+ priorityStr = "WARN";
+ break;
+ case android.util.Log.ERROR:
+ priorityStr = "ERROR";
+ break;
+ case android.util.Log.ASSERT:
+ priorityStr = "ASSERT";
+ break;
+ default:
+ break;
+ }
+
+ // Handily, the Log class has a facility for converting a stack trace into a usable string.
+ String exceptionStr = null;
+ if (tr != null) {
+ exceptionStr = android.util.Log.getStackTraceString(tr);
+ }
+
+ // Take the priority, tag, message, and exception, and concatenate as necessary
+ // into one usable line of text.
+ final StringBuilder outputBuilder = new StringBuilder();
+
+ String delimiter = "\t";
+ appendIfNotNull(outputBuilder, priorityStr, delimiter);
+ appendIfNotNull(outputBuilder, tag, delimiter);
+ appendIfNotNull(outputBuilder, msg, delimiter);
+ appendIfNotNull(outputBuilder, exceptionStr, delimiter);
+
+ // In case this was originally called from an AsyncTask or some other off-UI thread,
+ // make sure the update occurs within the UI thread.
+ ((Activity) getContext()).runOnUiThread( (new Thread(new Runnable() {
+ @Override
+ public void run() {
+ // Display the text we just generated within the LogView.
+ appendToLog(outputBuilder.toString());
+ }
+ })));
+
+ if (mNext != null) {
+ mNext.println(priority, tag, msg, tr);
+ }
+ }
+
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+ /** Takes a string and adds to it, with a separator, if the bit to be added isn't null. Since
+ * the logger takes so many arguments that might be null, this method helps cut out some of the
+ * agonizing tedium of writing the same 3 lines over and over.
+ * @param source StringBuilder containing the text to append to.
+ * @param addStr The String to append
+ * @param delimiter The String to separate the source and appended strings. A tab or comma,
+ * for instance.
+ * @return The fully concatenated String as a StringBuilder
+ */
+ private StringBuilder appendIfNotNull(StringBuilder source, String addStr, String delimiter) {
+ if (addStr != null) {
+ if (addStr.length() == 0) {
+ delimiter = "";
+ }
+
+ return source.append(addStr).append(delimiter);
+ }
+ return source;
+ }
+
+ // The next LogNode in the chain.
+ LogNode mNext;
+
+ /** Outputs the string as a new line of log data in the LogView. */
+ public void appendToLog(String s) {
+ append("\n" + s);
+ }
+
+
+}
diff --git a/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/LogWrapper.java
new file mode 100644
index 0000000..16a9e7b
--- /dev/null
+++ b/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/LogWrapper.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2012 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.common.logger;
+
+import android.util.Log;
+
+/**
+ * Helper class which wraps Android's native Log utility in the Logger interface. This way
+ * normal DDMS output can be one of the many targets receiving and outputting logs simultaneously.
+ */
+public class LogWrapper implements LogNode {
+
+ // For piping: The next node to receive Log data after this one has done its work.
+ private LogNode mNext;
+
+ /**
+ * Returns the next LogNode in the linked list.
+ */
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to..
+ */
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+ /**
+ * Prints data out to the console using Android's native log mechanism.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+ // There actually are log methods that don't take a msg parameter. For now,
+ // if that's the case, just convert null to the empty string and move on.
+ String useMsg = msg;
+ if (useMsg == null) {
+ useMsg = "";
+ }
+
+ // If an exeption was provided, convert that exception to a usable string and attach
+ // it to the end of the msg method.
+ if (tr != null) {
+ msg += "\n" + Log.getStackTraceString(tr);
+ }
+
+ // This is functionally identical to Log.x(tag, useMsg);
+ // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg)
+ Log.println(priority, tag, useMsg);
+
+ // If this isn't the last node in the chain, move things along.
+ if (mNext != null) {
+ mNext.println(priority, tag, msg, tr);
+ }
+ }
+}
diff --git a/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java
new file mode 100644
index 0000000..19967dc
--- /dev/null
+++ b/samples/browseable/Geofencing/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+/**
+ * Simple {@link LogNode} filter, removes everything except the message.
+ * Useful for situations like on-screen log output where you don't want a lot of metadata displayed,
+ * just easy-to-read message updates as they're happening.
+ */
+public class MessageOnlyLogFilter implements LogNode {
+
+ LogNode mNext;
+
+ /**
+ * Takes the "next" LogNode as a parameter, to simplify chaining.
+ *
+ * @param next The next LogNode in the pipeline.
+ */
+ public MessageOnlyLogFilter(LogNode next) {
+ mNext = next;
+ }
+
+ public MessageOnlyLogFilter() {
+ }
+
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+ if (mNext != null) {
+ getNext().println(Log.NONE, null, msg, null);
+ }
+ }
+
+ /**
+ * Returns the next LogNode in the chain.
+ */
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to..
+ */
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+}
diff --git a/samples/browseable/Geofencing/Application/src/com.example.android.geofencing/Constants.java b/samples/browseable/Geofencing/Application/src/com.example.android.geofencing/Constants.java
new file mode 100644
index 0000000..b90aa3b
--- /dev/null
+++ b/samples/browseable/Geofencing/Application/src/com.example.android.geofencing/Constants.java
@@ -0,0 +1,77 @@
+/*
+ * 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.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/browseable/Geofencing/Application/src/com.example.android.geofencing/GeofenceTransitionsIntentService.java b/samples/browseable/Geofencing/Application/src/com.example.android.geofencing/GeofenceTransitionsIntentService.java
new file mode 100644
index 0000000..1af7bc6
--- /dev/null
+++ b/samples/browseable/Geofencing/Application/src/com.example.android.geofencing/GeofenceTransitionsIntentService.java
@@ -0,0 +1,119 @@
+/*
+ * 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.geofencing;
+
+import static com.example.android.geofencing.Constants.CONNECTION_TIME_OUT_MS;
+import static com.example.android.geofencing.Constants.GEOFENCE_DATA_ITEM_PATH;
+import static com.example.android.geofencing.Constants.GEOFENCE_DATA_ITEM_URI;
+import static com.example.android.geofencing.Constants.KEY_GEOFENCE_ID;
+import static com.example.android.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/browseable/Geofencing/Application/src/com.example.android.geofencing/MainActivity.java b/samples/browseable/Geofencing/Application/src/com.example.android.geofencing/MainActivity.java
new file mode 100644
index 0000000..67dcd07
--- /dev/null
+++ b/samples/browseable/Geofencing/Application/src/com.example.android.geofencing/MainActivity.java
@@ -0,0 +1,240 @@
+/*
+ * 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.geofencing;
+
+import static com.example.android.geofencing.Constants.ANDROID_BUILDING_ID;
+import static com.example.android.geofencing.Constants.ANDROID_BUILDING_LATITUDE;
+import static com.example.android.geofencing.Constants.ANDROID_BUILDING_LONGITUDE;
+import static com.example.android.geofencing.Constants.ANDROID_BUILDING_RADIUS_METERS;
+import static com.example.android.geofencing.Constants.CONNECTION_FAILURE_RESOLUTION_REQUEST;
+import static com.example.android.geofencing.Constants.GEOFENCE_EXPIRATION_TIME;
+import static com.example.android.geofencing.Constants.TAG;
+import static com.example.android.geofencing.Constants.YERBA_BUENA_ID;
+import static com.example.android.geofencing.Constants.YERBA_BUENA_LATITUDE;
+import static com.example.android.geofencing.Constants.YERBA_BUENA_LONGITUDE;
+import static com.example.android.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<Geofence> 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<Geofence>();
+ // 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/browseable/Geofencing/Application/src/com.example.android.geofencing/SimpleGeofence.java b/samples/browseable/Geofencing/Application/src/com.example.android.geofencing/SimpleGeofence.java
new file mode 100644
index 0000000..8e17526
--- /dev/null
+++ b/samples/browseable/Geofencing/Application/src/com.example.android.geofencing/SimpleGeofence.java
@@ -0,0 +1,87 @@
+/*
+ * 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.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/browseable/Geofencing/Application/src/com.example.android.geofencing/SimpleGeofenceStore.java b/samples/browseable/Geofencing/Application/src/com.example.android.geofencing/SimpleGeofenceStore.java
new file mode 100644
index 0000000..fcdf8f8
--- /dev/null
+++ b/samples/browseable/Geofencing/Application/src/com.example.android.geofencing/SimpleGeofenceStore.java
@@ -0,0 +1,124 @@
+/*
+ * 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.geofencing;
+
+import static com.example.android.geofencing.Constants.INVALID_FLOAT_VALUE;
+import static com.example.android.geofencing.Constants.INVALID_INT_VALUE;
+import static com.example.android.geofencing.Constants.INVALID_LONG_VALUE;
+import static com.example.android.geofencing.Constants.KEY_EXPIRATION_DURATION;
+import static com.example.android.geofencing.Constants.KEY_LATITUDE;
+import static com.example.android.geofencing.Constants.KEY_LONGITUDE;
+import static com.example.android.geofencing.Constants.KEY_PREFIX;
+import static com.example.android.geofencing.Constants.KEY_RADIUS;
+import static com.example.android.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;
+ }
+
+}
diff --git a/samples/browseable/Geofencing/Shared/AndroidManifest.xml b/samples/browseable/Geofencing/Shared/AndroidManifest.xml
new file mode 100644
index 0000000..2b60180
--- /dev/null
+++ b/samples/browseable/Geofencing/Shared/AndroidManifest.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.geofencing.common">
+
+ <application android:allowBackup="true"
+ android:label="@string/app_name">
+ </application>
+
+</manifest>
diff --git a/samples/browseable/Geofencing/Shared/res/values/strings.xml b/samples/browseable/Geofencing/Shared/res/values/strings.xml
new file mode 100644
index 0000000..0f2bb90
--- /dev/null
+++ b/samples/browseable/Geofencing/Shared/res/values/strings.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<resources>
+ <string name="app_name">Shared</string>
+</resources>
diff --git a/samples/browseable/Geofencing/Wearable/AndroidManifest.xml b/samples/browseable/Geofencing/Wearable/AndroidManifest.xml
new file mode 100644
index 0000000..85c41cd
--- /dev/null
+++ b/samples/browseable/Geofencing/Wearable/AndroidManifest.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.geofencing" >
+
+ <uses-sdk android:minSdkVersion="20"
+ android:targetSdkVersion="20" />
+
+ <uses-feature android:name="android.hardware.type.watch" />
+
+ <application
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name"
+ android:allowBackup="true">
+
+ <meta-data
+ android:name="com.google.android.gms.version"
+ android:value="@integer/google_play_services_version" />
+
+ <service
+ android:name="com.example.android.geofencing.HomeListenerService" >
+ <intent-filter>
+ <action android:name="com.google.android.gms.wearable.BIND_LISTENER" />
+ </intent-filter>
+ </service>
+ <service android:name=".CheckInAndDeleteDataItemsService"/>
+
+ <activity android:name="android.support.wearable.activity.ConfirmationActivity"/>
+ </application>
+</manifest>
diff --git a/samples/browseable/Geofencing/Wearable/res/drawable-hdpi/ic_action_check_in.png b/samples/browseable/Geofencing/Wearable/res/drawable-hdpi/ic_action_check_in.png
new file mode 100644
index 0000000..f94a1c4
--- /dev/null
+++ b/samples/browseable/Geofencing/Wearable/res/drawable-hdpi/ic_action_check_in.png
Binary files differ
diff --git a/samples/browseable/Geofencing/Wearable/res/drawable-hdpi/ic_launcher.png b/samples/browseable/Geofencing/Wearable/res/drawable-hdpi/ic_launcher.png
new file mode 100644
index 0000000..4e3e000
--- /dev/null
+++ b/samples/browseable/Geofencing/Wearable/res/drawable-hdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/Geofencing/Wearable/res/drawable-mdpi/ic_launcher.png b/samples/browseable/Geofencing/Wearable/res/drawable-mdpi/ic_launcher.png
new file mode 100644
index 0000000..b405cb2
--- /dev/null
+++ b/samples/browseable/Geofencing/Wearable/res/drawable-mdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/Geofencing/Wearable/res/drawable-nodpi/android_building.png b/samples/browseable/Geofencing/Wearable/res/drawable-nodpi/android_building.png
new file mode 100644
index 0000000..2a28bd4
--- /dev/null
+++ b/samples/browseable/Geofencing/Wearable/res/drawable-nodpi/android_building.png
Binary files differ
diff --git a/samples/browseable/Geofencing/Wearable/res/drawable-nodpi/yerba_buena.png b/samples/browseable/Geofencing/Wearable/res/drawable-nodpi/yerba_buena.png
new file mode 100644
index 0000000..04f39f8
--- /dev/null
+++ b/samples/browseable/Geofencing/Wearable/res/drawable-nodpi/yerba_buena.png
Binary files differ
diff --git a/samples/browseable/Geofencing/Wearable/res/drawable-xhdpi/ic_launcher.png b/samples/browseable/Geofencing/Wearable/res/drawable-xhdpi/ic_launcher.png
new file mode 100644
index 0000000..61f9d88
--- /dev/null
+++ b/samples/browseable/Geofencing/Wearable/res/drawable-xhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/Geofencing/Wearable/res/drawable-xxhdpi/ic_launcher.png b/samples/browseable/Geofencing/Wearable/res/drawable-xxhdpi/ic_launcher.png
new file mode 100644
index 0000000..81c1008
--- /dev/null
+++ b/samples/browseable/Geofencing/Wearable/res/drawable-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/Geofencing/Wearable/res/values/strings.xml b/samples/browseable/Geofencing/Wearable/res/values/strings.xml
new file mode 100644
index 0000000..49fb2b3
--- /dev/null
+++ b/samples/browseable/Geofencing/Wearable/res/values/strings.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <string name="app_name">Android Wear Geofencing Example Application</string>
+ <string name="android_building_title">Android Building</string>
+ <string name="yerba_buena_title">Yerba Buena Gardens</string>
+ <string name="check_in_prompt">Check in here?</string>
+ <string name="check_in_success">Checked In</string>
+</resources>
diff --git a/samples/browseable/Geofencing/Wearable/src/com.example.android.geofencing/CheckInAndDeleteDataItemsService.java b/samples/browseable/Geofencing/Wearable/src/com.example.android.geofencing/CheckInAndDeleteDataItemsService.java
new file mode 100644
index 0000000..1cc9baf
--- /dev/null
+++ b/samples/browseable/Geofencing/Wearable/src/com.example.android.geofencing/CheckInAndDeleteDataItemsService.java
@@ -0,0 +1,124 @@
+/*
+ * 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.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.geofencing.Constants.ACTION_CHECK_IN;
+import static com.example.android.geofencing.Constants.ACTION_DELETE_DATA_ITEM;
+import static com.example.android.geofencing.Constants.CONNECTION_TIME_OUT_MS;
+import static com.example.android.geofencing.Constants.NOTIFICATION_ID;
+import static com.example.android.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) {
+ }
+
+}
diff --git a/samples/browseable/Geofencing/Wearable/src/com.example.android.geofencing/Constants.java b/samples/browseable/Geofencing/Wearable/src/com.example.android.geofencing/Constants.java
new file mode 100644
index 0000000..23ee99e
--- /dev/null
+++ b/samples/browseable/Geofencing/Wearable/src/com.example.android.geofencing/Constants.java
@@ -0,0 +1,38 @@
+/*
+ * 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.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/browseable/Geofencing/Wearable/src/com.example.android.geofencing/HomeListenerService.java b/samples/browseable/Geofencing/Wearable/src/com.example.android.geofencing/HomeListenerService.java
new file mode 100644
index 0000000..b0b1b13
--- /dev/null
+++ b/samples/browseable/Geofencing/Wearable/src/com.example.android.geofencing/HomeListenerService.java
@@ -0,0 +1,152 @@
+/*
+ * 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.geofencing;
+
+import static com.example.android.geofencing.Constants.ACTION_CHECK_IN;
+import static com.example.android.geofencing.Constants.ACTION_DELETE_DATA_ITEM;
+import static com.example.android.geofencing.Constants.ANDROID_BUILDING_ID;
+import static com.example.android.geofencing.Constants.KEY_GEOFENCE_ID;
+import static com.example.android.geofencing.Constants.NOTIFICATION_ID;
+import static com.example.android.geofencing.Constants.TAG;
+import static com.example.android.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/browseable/Geofencing/_index.jd b/samples/browseable/Geofencing/_index.jd
new file mode 100644
index 0000000..497a5b1
--- /dev/null
+++ b/samples/browseable/Geofencing/_index.jd
@@ -0,0 +1,12 @@
+page.tags="Geofencing"
+sample.group=Wearable
+@jd:body
+
+<p>
+
+ When a user enters the vicinity of the Android building (B44) or the Yerba Buena
+ Gardens near the Moscone center in San Francisco, a notification silently appears on his/her
+ wearable with an option to check in. This notification automatically disappears when he/she leaves
+ the area, and reappears the next time he/she is at one of these locations.
+
+ </p>
diff --git a/samples/browseable/GridViewPager/Application/AndroidManifest.xml b/samples/browseable/GridViewPager/Application/AndroidManifest.xml
new file mode 100644
index 0000000..eaa91d7
--- /dev/null
+++ b/samples/browseable/GridViewPager/Application/AndroidManifest.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.gridviewpager">
+
+ <uses-sdk android:minSdkVersion="19"
+ android:targetSdkVersion="19" />
+
+ <application android:allowBackup="true"
+ android:label="@string/app_name">
+ </application>
+
+</manifest>
+
diff --git a/samples/browseable/GridViewPager/Application/res/drawable-hdpi/tile.9.png b/samples/browseable/GridViewPager/Application/res/drawable-hdpi/tile.9.png
new file mode 100644
index 0000000..1358628
--- /dev/null
+++ b/samples/browseable/GridViewPager/Application/res/drawable-hdpi/tile.9.png
Binary files differ
diff --git a/samples/browseable/GridViewPager/Application/res/layout/activity_main.xml b/samples/browseable/GridViewPager/Application/res/layout/activity_main.xml
new file mode 100755
index 0000000..be1aa49
--- /dev/null
+++ b/samples/browseable/GridViewPager/Application/res/layout/activity_main.xml
@@ -0,0 +1,36 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <LinearLayout style="@style/Widget.SampleMessageTile"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+
+ <TextView style="@style/Widget.SampleMessage"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="@dimen/horizontal_page_margin"
+ android:layout_marginRight="@dimen/horizontal_page_margin"
+ android:layout_marginTop="@dimen/vertical_page_margin"
+ android:layout_marginBottom="@dimen/vertical_page_margin"
+ android:text="@string/intro_message" />
+ </LinearLayout>
+</LinearLayout>
diff --git a/samples/browseable/GridViewPager/Application/res/values-sw600dp/template-dimens.xml b/samples/browseable/GridViewPager/Application/res/values-sw600dp/template-dimens.xml
new file mode 100644
index 0000000..22074a2
--- /dev/null
+++ b/samples/browseable/GridViewPager/Application/res/values-sw600dp/template-dimens.xml
@@ -0,0 +1,24 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Semantic definitions -->
+
+ <dimen name="horizontal_page_margin">@dimen/margin_huge</dimen>
+ <dimen name="vertical_page_margin">@dimen/margin_medium</dimen>
+
+</resources>
diff --git a/samples/browseable/GridViewPager/Application/res/values-sw600dp/template-styles.xml b/samples/browseable/GridViewPager/Application/res/values-sw600dp/template-styles.xml
new file mode 100644
index 0000000..03d1974
--- /dev/null
+++ b/samples/browseable/GridViewPager/Application/res/values-sw600dp/template-styles.xml
@@ -0,0 +1,25 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <style name="Widget.SampleMessage">
+ <item name="android:textAppearance">?android:textAppearanceLarge</item>
+ <item name="android:lineSpacingMultiplier">1.2</item>
+ <item name="android:shadowDy">-6.5</item>
+ </style>
+
+</resources>
diff --git a/samples/browseable/GridViewPager/Application/res/values-v11/template-styles.xml b/samples/browseable/GridViewPager/Application/res/values-v11/template-styles.xml
new file mode 100644
index 0000000..8c1ea66
--- /dev/null
+++ b/samples/browseable/GridViewPager/Application/res/values-v11/template-styles.xml
@@ -0,0 +1,22 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Activity themes -->
+ <style name="Theme.Base" parent="android:Theme.Holo.Light" />
+
+</resources>
diff --git a/samples/browseable/GridViewPager/Application/res/values/base-strings.xml b/samples/browseable/GridViewPager/Application/res/values/base-strings.xml
new file mode 100644
index 0000000..c5f9122
--- /dev/null
+++ b/samples/browseable/GridViewPager/Application/res/values/base-strings.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 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.
+-->
+<resources>
+ <string name="app_name">GridViewPager</string>
+ <string name="intro_message">
+ <![CDATA[
+
+
+ Demonstrates how to implement a GridViewPager in your wearable app.
+
+
+ ]]>
+ </string>
+</resources>
diff --git a/samples/browseable/GridViewPager/Application/res/values/template-dimens.xml b/samples/browseable/GridViewPager/Application/res/values/template-dimens.xml
new file mode 100644
index 0000000..39e710b
--- /dev/null
+++ b/samples/browseable/GridViewPager/Application/res/values/template-dimens.xml
@@ -0,0 +1,32 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Define standard dimensions to comply with Holo-style grids and rhythm. -->
+
+ <dimen name="margin_tiny">4dp</dimen>
+ <dimen name="margin_small">8dp</dimen>
+ <dimen name="margin_medium">16dp</dimen>
+ <dimen name="margin_large">32dp</dimen>
+ <dimen name="margin_huge">64dp</dimen>
+
+ <!-- Semantic definitions -->
+
+ <dimen name="horizontal_page_margin">@dimen/margin_medium</dimen>
+ <dimen name="vertical_page_margin">@dimen/margin_medium</dimen>
+
+</resources>
diff --git a/samples/browseable/GridViewPager/Application/res/values/template-styles.xml b/samples/browseable/GridViewPager/Application/res/values/template-styles.xml
new file mode 100644
index 0000000..6e7d593
--- /dev/null
+++ b/samples/browseable/GridViewPager/Application/res/values/template-styles.xml
@@ -0,0 +1,42 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Activity themes -->
+
+ <style name="Theme.Base" parent="android:Theme.Light" />
+
+ <style name="Theme.Sample" parent="Theme.Base" />
+
+ <style name="AppTheme" parent="Theme.Sample" />
+ <!-- Widget styling -->
+
+ <style name="Widget" />
+
+ <style name="Widget.SampleMessage">
+ <item name="android:textAppearance">?android:textAppearanceMedium</item>
+ <item name="android:lineSpacingMultiplier">1.1</item>
+ </style>
+
+ <style name="Widget.SampleMessageTile">
+ <item name="android:background">@drawable/tile</item>
+ <item name="android:shadowColor">#7F000000</item>
+ <item name="android:shadowDy">-3.5</item>
+ <item name="android:shadowRadius">2</item>
+ </style>
+
+</resources>
diff --git a/samples/browseable/GridViewPager/Application/src/com.example.android.common/activities/SampleActivityBase.java b/samples/browseable/GridViewPager/Application/src/com.example.android.common/activities/SampleActivityBase.java
new file mode 100644
index 0000000..3228927
--- /dev/null
+++ b/samples/browseable/GridViewPager/Application/src/com.example.android.common/activities/SampleActivityBase.java
@@ -0,0 +1,52 @@
+/*
+* Copyright 2013 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.common.activities;
+
+import android.os.Bundle;
+import android.support.v4.app.FragmentActivity;
+
+import com.example.android.common.logger.Log;
+import com.example.android.common.logger.LogWrapper;
+
+/**
+ * Base launcher activity, to handle most of the common plumbing for samples.
+ */
+public class SampleActivityBase extends FragmentActivity {
+
+ public static final String TAG = "SampleActivityBase";
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ initializeLogging();
+ }
+
+ /** Set up targets to receive log data */
+ public void initializeLogging() {
+ // Using Log, front-end to the logging chain, emulates android.util.log method signatures.
+ // Wraps Android's native log framework
+ LogWrapper logWrapper = new LogWrapper();
+ Log.setLogNode(logWrapper);
+
+ Log.i(TAG, "Ready");
+ }
+}
diff --git a/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/Log.java b/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/Log.java
new file mode 100644
index 0000000..17503c5
--- /dev/null
+++ b/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/Log.java
@@ -0,0 +1,236 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+/**
+ * Helper class for a list (or tree) of LoggerNodes.
+ *
+ * <p>When this is set as the head of the list,
+ * an instance of it can function as a drop-in replacement for {@link android.util.Log}.
+ * Most of the methods in this class server only to map a method call in Log to its equivalent
+ * in LogNode.</p>
+ */
+public class Log {
+ // Grabbing the native values from Android's native logging facilities,
+ // to make for easy migration and interop.
+ public static final int NONE = -1;
+ public static final int VERBOSE = android.util.Log.VERBOSE;
+ public static final int DEBUG = android.util.Log.DEBUG;
+ public static final int INFO = android.util.Log.INFO;
+ public static final int WARN = android.util.Log.WARN;
+ public static final int ERROR = android.util.Log.ERROR;
+ public static final int ASSERT = android.util.Log.ASSERT;
+
+ // Stores the beginning of the LogNode topology.
+ private static LogNode mLogNode;
+
+ /**
+ * Returns the next LogNode in the linked list.
+ */
+ public static LogNode getLogNode() {
+ return mLogNode;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to.
+ */
+ public static void setLogNode(LogNode node) {
+ mLogNode = node;
+ }
+
+ /**
+ * Instructs the LogNode to print the log data provided. Other LogNodes can
+ * be chained to the end of the LogNode as desired.
+ *
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void println(int priority, String tag, String msg, Throwable tr) {
+ if (mLogNode != null) {
+ mLogNode.println(priority, tag, msg, tr);
+ }
+ }
+
+ /**
+ * Instructs the LogNode to print the log data provided. Other LogNodes can
+ * be chained to the end of the LogNode as desired.
+ *
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ */
+ public static void println(int priority, String tag, String msg) {
+ println(priority, tag, msg, null);
+ }
+
+ /**
+ * Prints a message at VERBOSE priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void v(String tag, String msg, Throwable tr) {
+ println(VERBOSE, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at VERBOSE priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void v(String tag, String msg) {
+ v(tag, msg, null);
+ }
+
+
+ /**
+ * Prints a message at DEBUG priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void d(String tag, String msg, Throwable tr) {
+ println(DEBUG, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at DEBUG priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void d(String tag, String msg) {
+ d(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at INFO priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void i(String tag, String msg, Throwable tr) {
+ println(INFO, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at INFO priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void i(String tag, String msg) {
+ i(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void w(String tag, String msg, Throwable tr) {
+ println(WARN, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void w(String tag, String msg) {
+ w(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void w(String tag, Throwable tr) {
+ w(tag, null, tr);
+ }
+
+ /**
+ * Prints a message at ERROR priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void e(String tag, String msg, Throwable tr) {
+ println(ERROR, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at ERROR priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void e(String tag, String msg) {
+ e(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void wtf(String tag, String msg, Throwable tr) {
+ println(ASSERT, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void wtf(String tag, String msg) {
+ wtf(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void wtf(String tag, Throwable tr) {
+ wtf(tag, null, tr);
+ }
+}
diff --git a/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/LogFragment.java
new file mode 100644
index 0000000..b302acd
--- /dev/null
+++ b/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/LogFragment.java
@@ -0,0 +1,109 @@
+/*
+* Copyright 2013 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.
+*/
+/*
+ * Copyright 2013 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.common.logger;
+
+import android.graphics.Typeface;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ScrollView;
+
+/**
+ * Simple fraggment which contains a LogView and uses is to output log data it receives
+ * through the LogNode interface.
+ */
+public class LogFragment extends Fragment {
+
+ private LogView mLogView;
+ private ScrollView mScrollView;
+
+ public LogFragment() {}
+
+ public View inflateViews() {
+ mScrollView = new ScrollView(getActivity());
+ ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT);
+ mScrollView.setLayoutParams(scrollParams);
+
+ mLogView = new LogView(getActivity());
+ ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams);
+ logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
+ mLogView.setLayoutParams(logParams);
+ mLogView.setClickable(true);
+ mLogView.setFocusable(true);
+ mLogView.setTypeface(Typeface.MONOSPACE);
+
+ // Want to set padding as 16 dips, setPadding takes pixels. Hooray math!
+ int paddingDips = 16;
+ double scale = getResources().getDisplayMetrics().density;
+ int paddingPixels = (int) ((paddingDips * (scale)) + .5);
+ mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels);
+ mLogView.setCompoundDrawablePadding(paddingPixels);
+
+ mLogView.setGravity(Gravity.BOTTOM);
+ mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium);
+
+ mScrollView.addView(mLogView);
+ return mScrollView;
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+
+ View result = inflateViews();
+
+ mLogView.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {}
+
+ @Override
+ public void afterTextChanged(Editable s) {
+ mScrollView.fullScroll(ScrollView.FOCUS_DOWN);
+ }
+ });
+ return result;
+ }
+
+ public LogView getLogView() {
+ return mLogView;
+ }
+}
\ No newline at end of file
diff --git a/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/LogNode.java
new file mode 100644
index 0000000..bc37cab
--- /dev/null
+++ b/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/LogNode.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2012 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.common.logger;
+
+/**
+ * Basic interface for a logging system that can output to one or more targets.
+ * Note that in addition to classes that will output these logs in some format,
+ * one can also implement this interface over a filter and insert that in the chain,
+ * such that no targets further down see certain data, or see manipulated forms of the data.
+ * You could, for instance, write a "ToHtmlLoggerNode" that just converted all the log data
+ * it received to HTML and sent it along to the next node in the chain, without printing it
+ * anywhere.
+ */
+public interface LogNode {
+
+ /**
+ * Instructs first LogNode in the list to print the log data provided.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public void println(int priority, String tag, String msg, Throwable tr);
+
+}
diff --git a/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/LogView.java
new file mode 100644
index 0000000..c01542b
--- /dev/null
+++ b/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/LogView.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+import android.app.Activity;
+import android.content.Context;
+import android.util.*;
+import android.widget.TextView;
+
+/** Simple TextView which is used to output log data received through the LogNode interface.
+*/
+public class LogView extends TextView implements LogNode {
+
+ public LogView(Context context) {
+ super(context);
+ }
+
+ public LogView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public LogView(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ /**
+ * Formats the log data and prints it out to the LogView.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+
+
+ String priorityStr = null;
+
+ // For the purposes of this View, we want to print the priority as readable text.
+ switch(priority) {
+ case android.util.Log.VERBOSE:
+ priorityStr = "VERBOSE";
+ break;
+ case android.util.Log.DEBUG:
+ priorityStr = "DEBUG";
+ break;
+ case android.util.Log.INFO:
+ priorityStr = "INFO";
+ break;
+ case android.util.Log.WARN:
+ priorityStr = "WARN";
+ break;
+ case android.util.Log.ERROR:
+ priorityStr = "ERROR";
+ break;
+ case android.util.Log.ASSERT:
+ priorityStr = "ASSERT";
+ break;
+ default:
+ break;
+ }
+
+ // Handily, the Log class has a facility for converting a stack trace into a usable string.
+ String exceptionStr = null;
+ if (tr != null) {
+ exceptionStr = android.util.Log.getStackTraceString(tr);
+ }
+
+ // Take the priority, tag, message, and exception, and concatenate as necessary
+ // into one usable line of text.
+ final StringBuilder outputBuilder = new StringBuilder();
+
+ String delimiter = "\t";
+ appendIfNotNull(outputBuilder, priorityStr, delimiter);
+ appendIfNotNull(outputBuilder, tag, delimiter);
+ appendIfNotNull(outputBuilder, msg, delimiter);
+ appendIfNotNull(outputBuilder, exceptionStr, delimiter);
+
+ // In case this was originally called from an AsyncTask or some other off-UI thread,
+ // make sure the update occurs within the UI thread.
+ ((Activity) getContext()).runOnUiThread( (new Thread(new Runnable() {
+ @Override
+ public void run() {
+ // Display the text we just generated within the LogView.
+ appendToLog(outputBuilder.toString());
+ }
+ })));
+
+ if (mNext != null) {
+ mNext.println(priority, tag, msg, tr);
+ }
+ }
+
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+ /** Takes a string and adds to it, with a separator, if the bit to be added isn't null. Since
+ * the logger takes so many arguments that might be null, this method helps cut out some of the
+ * agonizing tedium of writing the same 3 lines over and over.
+ * @param source StringBuilder containing the text to append to.
+ * @param addStr The String to append
+ * @param delimiter The String to separate the source and appended strings. A tab or comma,
+ * for instance.
+ * @return The fully concatenated String as a StringBuilder
+ */
+ private StringBuilder appendIfNotNull(StringBuilder source, String addStr, String delimiter) {
+ if (addStr != null) {
+ if (addStr.length() == 0) {
+ delimiter = "";
+ }
+
+ return source.append(addStr).append(delimiter);
+ }
+ return source;
+ }
+
+ // The next LogNode in the chain.
+ LogNode mNext;
+
+ /** Outputs the string as a new line of log data in the LogView. */
+ public void appendToLog(String s) {
+ append("\n" + s);
+ }
+
+
+}
diff --git a/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/LogWrapper.java
new file mode 100644
index 0000000..16a9e7b
--- /dev/null
+++ b/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/LogWrapper.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2012 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.common.logger;
+
+import android.util.Log;
+
+/**
+ * Helper class which wraps Android's native Log utility in the Logger interface. This way
+ * normal DDMS output can be one of the many targets receiving and outputting logs simultaneously.
+ */
+public class LogWrapper implements LogNode {
+
+ // For piping: The next node to receive Log data after this one has done its work.
+ private LogNode mNext;
+
+ /**
+ * Returns the next LogNode in the linked list.
+ */
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to..
+ */
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+ /**
+ * Prints data out to the console using Android's native log mechanism.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+ // There actually are log methods that don't take a msg parameter. For now,
+ // if that's the case, just convert null to the empty string and move on.
+ String useMsg = msg;
+ if (useMsg == null) {
+ useMsg = "";
+ }
+
+ // If an exeption was provided, convert that exception to a usable string and attach
+ // it to the end of the msg method.
+ if (tr != null) {
+ msg += "\n" + Log.getStackTraceString(tr);
+ }
+
+ // This is functionally identical to Log.x(tag, useMsg);
+ // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg)
+ Log.println(priority, tag, useMsg);
+
+ // If this isn't the last node in the chain, move things along.
+ if (mNext != null) {
+ mNext.println(priority, tag, msg, tr);
+ }
+ }
+}
diff --git a/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java
new file mode 100644
index 0000000..19967dc
--- /dev/null
+++ b/samples/browseable/GridViewPager/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+/**
+ * Simple {@link LogNode} filter, removes everything except the message.
+ * Useful for situations like on-screen log output where you don't want a lot of metadata displayed,
+ * just easy-to-read message updates as they're happening.
+ */
+public class MessageOnlyLogFilter implements LogNode {
+
+ LogNode mNext;
+
+ /**
+ * Takes the "next" LogNode as a parameter, to simplify chaining.
+ *
+ * @param next The next LogNode in the pipeline.
+ */
+ public MessageOnlyLogFilter(LogNode next) {
+ mNext = next;
+ }
+
+ public MessageOnlyLogFilter() {
+ }
+
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+ if (mNext != null) {
+ getNext().println(Log.NONE, null, msg, null);
+ }
+ }
+
+ /**
+ * Returns the next LogNode in the chain.
+ */
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to..
+ */
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+}
diff --git a/samples/browseable/GridViewPager/Shared/AndroidManifest.xml b/samples/browseable/GridViewPager/Shared/AndroidManifest.xml
new file mode 100644
index 0000000..1be08aa
--- /dev/null
+++ b/samples/browseable/GridViewPager/Shared/AndroidManifest.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.gridviewpager.common">
+
+ <application android:allowBackup="true"
+ android:label="@string/app_name">
+ </application>
+
+</manifest>
diff --git a/samples/browseable/GridViewPager/Shared/res/values/strings.xml b/samples/browseable/GridViewPager/Shared/res/values/strings.xml
new file mode 100644
index 0000000..0f2bb90
--- /dev/null
+++ b/samples/browseable/GridViewPager/Shared/res/values/strings.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<resources>
+ <string name="app_name">Shared</string>
+</resources>
diff --git a/samples/browseable/GridViewPager/Wearable/AndroidManifest.xml b/samples/browseable/GridViewPager/Wearable/AndroidManifest.xml
new file mode 100644
index 0000000..baadee2
--- /dev/null
+++ b/samples/browseable/GridViewPager/Wearable/AndroidManifest.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.gridviewpager" >
+
+ <uses-sdk android:minSdkVersion="20"
+ android:targetSdkVersion="20" />
+
+ <uses-feature android:name="android.hardware.type.watch" />
+
+ <application
+ android:allowBackup="true"
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name"
+ android:theme="@android:style/Theme.DeviceDefault.Light" >
+ <activity
+ android:name="com.example.android.gridviewpager.MainActivity"
+ android:label="@string/app_name" >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+
+</manifest>
diff --git a/samples/browseable/GridViewPager/Wearable/res/drawable-hdpi/bugdroid.png b/samples/browseable/GridViewPager/Wearable/res/drawable-hdpi/bugdroid.png
new file mode 100644
index 0000000..7cbe661
--- /dev/null
+++ b/samples/browseable/GridViewPager/Wearable/res/drawable-hdpi/bugdroid.png
Binary files differ
diff --git a/samples/browseable/GridViewPager/Wearable/res/drawable-hdpi/ic_launcher.png b/samples/browseable/GridViewPager/Wearable/res/drawable-hdpi/ic_launcher.png
new file mode 100644
index 0000000..589f229
--- /dev/null
+++ b/samples/browseable/GridViewPager/Wearable/res/drawable-hdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/GridViewPager/Wearable/res/drawable-hdpi/ic_swipe_arrow_left.png b/samples/browseable/GridViewPager/Wearable/res/drawable-hdpi/ic_swipe_arrow_left.png
new file mode 100644
index 0000000..88a497f
--- /dev/null
+++ b/samples/browseable/GridViewPager/Wearable/res/drawable-hdpi/ic_swipe_arrow_left.png
Binary files differ
diff --git a/samples/browseable/GridViewPager/Wearable/res/drawable-hdpi/ic_swipe_arrow_right.png b/samples/browseable/GridViewPager/Wearable/res/drawable-hdpi/ic_swipe_arrow_right.png
new file mode 100644
index 0000000..5bf0e47
--- /dev/null
+++ b/samples/browseable/GridViewPager/Wearable/res/drawable-hdpi/ic_swipe_arrow_right.png
Binary files differ
diff --git a/samples/browseable/GridViewPager/Wearable/res/drawable-hdpi/ic_swipe_arrow_up.png b/samples/browseable/GridViewPager/Wearable/res/drawable-hdpi/ic_swipe_arrow_up.png
new file mode 100644
index 0000000..9a3256a
--- /dev/null
+++ b/samples/browseable/GridViewPager/Wearable/res/drawable-hdpi/ic_swipe_arrow_up.png
Binary files differ
diff --git a/samples/browseable/GridViewPager/Wearable/res/drawable-mdpi/bugdroid.png b/samples/browseable/GridViewPager/Wearable/res/drawable-mdpi/bugdroid.png
new file mode 100644
index 0000000..8bf7596
--- /dev/null
+++ b/samples/browseable/GridViewPager/Wearable/res/drawable-mdpi/bugdroid.png
Binary files differ
diff --git a/samples/browseable/GridViewPager/Wearable/res/drawable-mdpi/ic_launcher.png b/samples/browseable/GridViewPager/Wearable/res/drawable-mdpi/ic_launcher.png
new file mode 100644
index 0000000..77dd571
--- /dev/null
+++ b/samples/browseable/GridViewPager/Wearable/res/drawable-mdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/GridViewPager/Wearable/res/drawable-mdpi/ic_swipe_arrow_left.png b/samples/browseable/GridViewPager/Wearable/res/drawable-mdpi/ic_swipe_arrow_left.png
new file mode 100644
index 0000000..ba36d9d
--- /dev/null
+++ b/samples/browseable/GridViewPager/Wearable/res/drawable-mdpi/ic_swipe_arrow_left.png
Binary files differ
diff --git a/samples/browseable/GridViewPager/Wearable/res/drawable-mdpi/ic_swipe_arrow_right.png b/samples/browseable/GridViewPager/Wearable/res/drawable-mdpi/ic_swipe_arrow_right.png
new file mode 100644
index 0000000..e5930ac
--- /dev/null
+++ b/samples/browseable/GridViewPager/Wearable/res/drawable-mdpi/ic_swipe_arrow_right.png
Binary files differ
diff --git a/samples/browseable/GridViewPager/Wearable/res/drawable-mdpi/ic_swipe_arrow_up.png b/samples/browseable/GridViewPager/Wearable/res/drawable-mdpi/ic_swipe_arrow_up.png
new file mode 100644
index 0000000..5ded1c3
--- /dev/null
+++ b/samples/browseable/GridViewPager/Wearable/res/drawable-mdpi/ic_swipe_arrow_up.png
Binary files differ
diff --git a/samples/browseable/GridViewPager/Wearable/res/drawable-xhdpi/ic_launcher.png b/samples/browseable/GridViewPager/Wearable/res/drawable-xhdpi/ic_launcher.png
new file mode 100644
index 0000000..fe34ebe
--- /dev/null
+++ b/samples/browseable/GridViewPager/Wearable/res/drawable-xhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/GridViewPager/Wearable/res/drawable-xhdpi/ic_swipe_arrow_left.png b/samples/browseable/GridViewPager/Wearable/res/drawable-xhdpi/ic_swipe_arrow_left.png
new file mode 100644
index 0000000..f02901b
--- /dev/null
+++ b/samples/browseable/GridViewPager/Wearable/res/drawable-xhdpi/ic_swipe_arrow_left.png
Binary files differ
diff --git a/samples/browseable/GridViewPager/Wearable/res/drawable-xhdpi/ic_swipe_arrow_right.png b/samples/browseable/GridViewPager/Wearable/res/drawable-xhdpi/ic_swipe_arrow_right.png
new file mode 100644
index 0000000..154a87e
--- /dev/null
+++ b/samples/browseable/GridViewPager/Wearable/res/drawable-xhdpi/ic_swipe_arrow_right.png
Binary files differ
diff --git a/samples/browseable/GridViewPager/Wearable/res/drawable-xhdpi/ic_swipe_arrow_up.png b/samples/browseable/GridViewPager/Wearable/res/drawable-xhdpi/ic_swipe_arrow_up.png
new file mode 100644
index 0000000..e99d982
--- /dev/null
+++ b/samples/browseable/GridViewPager/Wearable/res/drawable-xhdpi/ic_swipe_arrow_up.png
Binary files differ
diff --git a/samples/browseable/GridViewPager/Wearable/res/drawable-xxhdpi/ic_launcher.png b/samples/browseable/GridViewPager/Wearable/res/drawable-xxhdpi/ic_launcher.png
new file mode 100755
index 0000000..ab80bcd
--- /dev/null
+++ b/samples/browseable/GridViewPager/Wearable/res/drawable-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/GridViewPager/Wearable/res/drawable/debug_background_1.png b/samples/browseable/GridViewPager/Wearable/res/drawable/debug_background_1.png
new file mode 100644
index 0000000..7e6437b
--- /dev/null
+++ b/samples/browseable/GridViewPager/Wearable/res/drawable/debug_background_1.png
Binary files differ
diff --git a/samples/browseable/GridViewPager/Wearable/res/drawable/debug_background_2.png b/samples/browseable/GridViewPager/Wearable/res/drawable/debug_background_2.png
new file mode 100644
index 0000000..4fdc5c9
--- /dev/null
+++ b/samples/browseable/GridViewPager/Wearable/res/drawable/debug_background_2.png
Binary files differ
diff --git a/samples/browseable/GridViewPager/Wearable/res/drawable/debug_background_3.png b/samples/browseable/GridViewPager/Wearable/res/drawable/debug_background_3.png
new file mode 100644
index 0000000..20faf46
--- /dev/null
+++ b/samples/browseable/GridViewPager/Wearable/res/drawable/debug_background_3.png
Binary files differ
diff --git a/samples/browseable/GridViewPager/Wearable/res/drawable/debug_background_4.png b/samples/browseable/GridViewPager/Wearable/res/drawable/debug_background_4.png
new file mode 100644
index 0000000..1fd25c6
--- /dev/null
+++ b/samples/browseable/GridViewPager/Wearable/res/drawable/debug_background_4.png
Binary files differ
diff --git a/samples/browseable/GridViewPager/Wearable/res/drawable/debug_background_5.png b/samples/browseable/GridViewPager/Wearable/res/drawable/debug_background_5.png
new file mode 100644
index 0000000..eecdb2c
--- /dev/null
+++ b/samples/browseable/GridViewPager/Wearable/res/drawable/debug_background_5.png
Binary files differ
diff --git a/samples/browseable/GridViewPager/Wearable/res/layout/activity_main.xml b/samples/browseable/GridViewPager/Wearable/res/layout/activity_main.xml
new file mode 100644
index 0000000..abc3b30
--- /dev/null
+++ b/samples/browseable/GridViewPager/Wearable/res/layout/activity_main.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<android.support.wearable.view.GridViewPager
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/pager"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:keepScreenOn="true" />
diff --git a/samples/browseable/GridViewPager/Wearable/res/values/dimens.xml b/samples/browseable/GridViewPager/Wearable/res/values/dimens.xml
new file mode 100644
index 0000000..47ab217
--- /dev/null
+++ b/samples/browseable/GridViewPager/Wearable/res/values/dimens.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+ <dimen name="page_row_margin">100dp</dimen>
+ <dimen name="page_column_margin">10dp</dimen>
+ <dimen name="page_column_margin_round">50dp</dimen>
+</resources>
diff --git a/samples/browseable/GridViewPager/Wearable/res/values/strings.xml b/samples/browseable/GridViewPager/Wearable/res/values/strings.xml
new file mode 100644
index 0000000..404119b
--- /dev/null
+++ b/samples/browseable/GridViewPager/Wearable/res/values/strings.xml
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+
+ <string name="app_name">GridViewPager Sample</string>
+ <string name="welcome_title">GridViewPager</string>
+ <string name="welcome_text">Welcome!</string>
+
+ <string name="about_title">About</string>
+ <string name="about_text">Content is organized into multiple pages. Swipe
+ between cards to view other content.</string>
+
+ <string name="cards_title">Cards</string>
+ <string name="cards_text">Each page is created using a CardFragment. A
+ layout is placed inside the card and the rest is handled
+ automatically.</string>
+
+ <string name="expansion_title">Expansion</string>
+ <string name="expansion_text">By default, each card will grow taller to
+ accommodate extra content. Tall cards can be scrolled through
+ like any scrollable view. The maximum height is controlled by
+ setExpansionFactor() with a default of 10 pages. After that
+ you\'ll notice a faded edge to indicate there is more. Expansion
+ can be disabled completely using setExpansionEnabled(false).
+ With this, the content will be clipped if it\'s taller than one
+ page.</string>
+
+ <string name="backgrounds_title">Backgrounds</string>
+ <string name="backgrounds_text">Backgrounds are supplied by the adapter\'s
+ getBackground method. Parallax and crossfade effects are applied
+ automatically.</string>
+
+ <string name="columns_title">Columns</string>
+ <string name="columns_text">When moving between rows, the pager always
+ returns to column 0. This is adjustable in the adapter. See
+ method getCurrentColumnForRow().</string>
+
+ <string name="dismiss_title">Dismiss</string>
+ <string name="dismiss_text">To exit the application, swipe from left to
+ right.</string>
+
+</resources>
diff --git a/samples/browseable/GridViewPager/Wearable/src/com.example.android.gridviewpager/MainActivity.java b/samples/browseable/GridViewPager/Wearable/src/com.example.android.gridviewpager/MainActivity.java
new file mode 100644
index 0000000..0ca304e
--- /dev/null
+++ b/samples/browseable/GridViewPager/Wearable/src/com.example.android.gridviewpager/MainActivity.java
@@ -0,0 +1,56 @@
+/*
+ * 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.gridviewpager;
+
+import android.app.Activity;
+import android.content.res.Resources;
+import android.os.Bundle;
+import android.support.wearable.view.GridViewPager;
+import android.view.View;
+import android.view.View.OnApplyWindowInsetsListener;
+import android.view.WindowInsets;
+
+public class MainActivity extends Activity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_main);
+ final Resources res = getResources();
+ final GridViewPager pager = (GridViewPager) findViewById(R.id.pager);
+ pager.setOnApplyWindowInsetsListener(new OnApplyWindowInsetsListener() {
+ @Override
+ public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
+ // Adjust page margins:
+ // A little extra horizontal spacing between pages looks a bit
+ // less crowded on a round display.
+ final boolean round = insets.isRound();
+ int rowMargin = res.getDimensionPixelOffset(R.dimen.page_row_margin);
+ int colMargin = res.getDimensionPixelOffset(round ?
+ R.dimen.page_column_margin_round : R.dimen.page_column_margin);
+ pager.setPageMargins(rowMargin, colMargin);
+
+ // GridViewPager relies on insets to properly handle
+ // layout for round displays. They must be explicitly
+ // applied since this listener has taken them over.
+ pager.onApplyWindowInsets(insets);
+ return insets;
+ }
+ });
+ pager.setAdapter(new SampleGridPagerAdapter(this, getFragmentManager()));
+ }
+}
diff --git a/samples/browseable/GridViewPager/Wearable/src/com.example.android.gridviewpager/SampleGridPagerAdapter.java b/samples/browseable/GridViewPager/Wearable/src/com.example.android.gridviewpager/SampleGridPagerAdapter.java
new file mode 100644
index 0000000..c9dde07
--- /dev/null
+++ b/samples/browseable/GridViewPager/Wearable/src/com.example.android.gridviewpager/SampleGridPagerAdapter.java
@@ -0,0 +1,134 @@
+/*
+ * 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.gridviewpager;
+
+import android.app.Fragment;
+import android.app.FragmentManager;
+import android.content.Context;
+import android.support.wearable.view.CardFragment;
+import android.support.wearable.view.FragmentGridPagerAdapter;
+import android.support.wearable.view.ImageReference;
+import android.view.Gravity;
+
+/**
+ * Constructs fragments as requested by the GridViewPager. For each row a
+ * different background is provided.
+ */
+public class SampleGridPagerAdapter extends FragmentGridPagerAdapter {
+
+ private final Context mContext;
+
+ public SampleGridPagerAdapter(Context ctx, FragmentManager fm) {
+ super(fm);
+ mContext = ctx;
+ }
+
+ static final int[] BG_IMAGES = new int[] {
+ R.drawable.debug_background_1,
+ R.drawable.debug_background_2,
+ R.drawable.debug_background_3,
+ R.drawable.debug_background_4,
+ R.drawable.debug_background_5
+ };
+
+ /** A simple container for static data in each page */
+ private static class Page {
+ int titleRes;
+ int textRes;
+ int iconRes;
+ int cardGravity = Gravity.BOTTOM;
+ boolean expansionEnabled = true;
+ float expansionFactor = 1.0f;
+ int expansionDirection = CardFragment.EXPAND_DOWN;
+
+ public Page(int titleRes, int textRes, boolean expansion) {
+ this(titleRes, textRes, 0);
+ this.expansionEnabled = expansion;
+ }
+
+ public Page(int titleRes, int textRes, boolean expansion, float expansionFactor) {
+ this(titleRes, textRes, 0);
+ this.expansionEnabled = expansion;
+ this.expansionFactor = expansionFactor;
+ }
+
+ public Page(int titleRes, int textRes, int iconRes) {
+ this.titleRes = titleRes;
+ this.textRes = textRes;
+ this.iconRes = iconRes;
+ }
+
+ public Page(int titleRes, int textRes, int iconRes, int gravity) {
+ this.titleRes = titleRes;
+ this.textRes = textRes;
+ this.iconRes = iconRes;
+ this.cardGravity = gravity;
+ }
+ }
+
+ private final Page[][] PAGES = {
+ {
+ new Page(R.string.welcome_title, R.string.welcome_text, R.drawable.bugdroid,
+ Gravity.CENTER_VERTICAL),
+ },
+ {
+ new Page(R.string.about_title, R.string.about_text, false),
+ },
+ {
+ new Page(R.string.cards_title, R.string.cards_text, true, 2),
+ new Page(R.string.expansion_title, R.string.expansion_text, true, 10),
+ },
+ {
+ new Page(R.string.backgrounds_title, R.string.backgrounds_text, true, 2),
+ new Page(R.string.columns_title, R.string.columns_text, true, 2)
+ },
+ {
+ new Page(R.string.dismiss_title, R.string.dismiss_text, R.drawable.bugdroid,
+ Gravity.CENTER_VERTICAL),
+ },
+
+ };
+
+ @Override
+ public Fragment getFragment(int row, int col) {
+ Page page = PAGES[row][col];
+ String title = page.titleRes != 0 ? mContext.getString(page.titleRes) : null;
+ String text = page.textRes != 0 ? mContext.getString(page.textRes) : null;
+ CardFragment fragment = CardFragment.create(title, text, page.iconRes);
+ // Advanced settings
+ fragment.setCardGravity(page.cardGravity);
+ fragment.setExpansionEnabled(page.expansionEnabled);
+ fragment.setExpansionDirection(page.expansionDirection);
+ fragment.setExpansionFactor(page.expansionFactor);
+ return fragment;
+ }
+
+ @Override
+ public ImageReference getBackground(int row, int column) {
+ return ImageReference.forDrawable(BG_IMAGES[row % BG_IMAGES.length]);
+ }
+
+ @Override
+ public int getRowCount() {
+ return PAGES.length;
+ }
+
+ @Override
+ public int getColumnCount(int rowNum) {
+ return PAGES[rowNum].length;
+ }
+}
diff --git a/samples/browseable/GridViewPager/_index.jd b/samples/browseable/GridViewPager/_index.jd
new file mode 100644
index 0000000..0abe754
--- /dev/null
+++ b/samples/browseable/GridViewPager/_index.jd
@@ -0,0 +1,9 @@
+page.tags="GridViewPager"
+sample.group=Wearable
+@jd:body
+
+<p>
+
+ Demonstrates how to implement a GridViewPager in your wearable app.
+
+ </p>
diff --git a/samples/browseable/JumpingJack/Application/AndroidManifest.xml b/samples/browseable/JumpingJack/Application/AndroidManifest.xml
new file mode 100644
index 0000000..652f895
--- /dev/null
+++ b/samples/browseable/JumpingJack/Application/AndroidManifest.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.jumpingjack">
+
+ <uses-sdk android:minSdkVersion="19"
+ android:targetSdkVersion="19" />
+
+ <application android:allowBackup="true"
+ android:label="@string/app_name">
+ </application>
+
+</manifest>
+
diff --git a/samples/browseable/JumpingJack/Application/res/drawable-hdpi/tile.9.png b/samples/browseable/JumpingJack/Application/res/drawable-hdpi/tile.9.png
new file mode 100644
index 0000000..1358628
--- /dev/null
+++ b/samples/browseable/JumpingJack/Application/res/drawable-hdpi/tile.9.png
Binary files differ
diff --git a/samples/browseable/JumpingJack/Application/res/layout/activity_main.xml b/samples/browseable/JumpingJack/Application/res/layout/activity_main.xml
new file mode 100755
index 0000000..be1aa49
--- /dev/null
+++ b/samples/browseable/JumpingJack/Application/res/layout/activity_main.xml
@@ -0,0 +1,36 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <LinearLayout style="@style/Widget.SampleMessageTile"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+
+ <TextView style="@style/Widget.SampleMessage"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="@dimen/horizontal_page_margin"
+ android:layout_marginRight="@dimen/horizontal_page_margin"
+ android:layout_marginTop="@dimen/vertical_page_margin"
+ android:layout_marginBottom="@dimen/vertical_page_margin"
+ android:text="@string/intro_message" />
+ </LinearLayout>
+</LinearLayout>
diff --git a/samples/browseable/JumpingJack/Application/res/values-sw600dp/template-dimens.xml b/samples/browseable/JumpingJack/Application/res/values-sw600dp/template-dimens.xml
new file mode 100644
index 0000000..22074a2
--- /dev/null
+++ b/samples/browseable/JumpingJack/Application/res/values-sw600dp/template-dimens.xml
@@ -0,0 +1,24 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Semantic definitions -->
+
+ <dimen name="horizontal_page_margin">@dimen/margin_huge</dimen>
+ <dimen name="vertical_page_margin">@dimen/margin_medium</dimen>
+
+</resources>
diff --git a/samples/browseable/JumpingJack/Application/res/values-sw600dp/template-styles.xml b/samples/browseable/JumpingJack/Application/res/values-sw600dp/template-styles.xml
new file mode 100644
index 0000000..03d1974
--- /dev/null
+++ b/samples/browseable/JumpingJack/Application/res/values-sw600dp/template-styles.xml
@@ -0,0 +1,25 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <style name="Widget.SampleMessage">
+ <item name="android:textAppearance">?android:textAppearanceLarge</item>
+ <item name="android:lineSpacingMultiplier">1.2</item>
+ <item name="android:shadowDy">-6.5</item>
+ </style>
+
+</resources>
diff --git a/samples/browseable/JumpingJack/Application/res/values-v11/template-styles.xml b/samples/browseable/JumpingJack/Application/res/values-v11/template-styles.xml
new file mode 100644
index 0000000..8c1ea66
--- /dev/null
+++ b/samples/browseable/JumpingJack/Application/res/values-v11/template-styles.xml
@@ -0,0 +1,22 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Activity themes -->
+ <style name="Theme.Base" parent="android:Theme.Holo.Light" />
+
+</resources>
diff --git a/samples/browseable/JumpingJack/Application/res/values/base-strings.xml b/samples/browseable/JumpingJack/Application/res/values/base-strings.xml
new file mode 100644
index 0000000..7553d3e
--- /dev/null
+++ b/samples/browseable/JumpingJack/Application/res/values/base-strings.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 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.
+-->
+<resources>
+ <string name="app_name">JumpingJack</string>
+ <string name="intro_message">
+ <![CDATA[
+
+
+ Uses the Gravity sensor to count how many jumping jacks you have performed.
+
+
+ ]]>
+ </string>
+</resources>
diff --git a/samples/browseable/JumpingJack/Application/res/values/template-dimens.xml b/samples/browseable/JumpingJack/Application/res/values/template-dimens.xml
new file mode 100644
index 0000000..39e710b
--- /dev/null
+++ b/samples/browseable/JumpingJack/Application/res/values/template-dimens.xml
@@ -0,0 +1,32 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Define standard dimensions to comply with Holo-style grids and rhythm. -->
+
+ <dimen name="margin_tiny">4dp</dimen>
+ <dimen name="margin_small">8dp</dimen>
+ <dimen name="margin_medium">16dp</dimen>
+ <dimen name="margin_large">32dp</dimen>
+ <dimen name="margin_huge">64dp</dimen>
+
+ <!-- Semantic definitions -->
+
+ <dimen name="horizontal_page_margin">@dimen/margin_medium</dimen>
+ <dimen name="vertical_page_margin">@dimen/margin_medium</dimen>
+
+</resources>
diff --git a/samples/browseable/JumpingJack/Application/res/values/template-styles.xml b/samples/browseable/JumpingJack/Application/res/values/template-styles.xml
new file mode 100644
index 0000000..6e7d593
--- /dev/null
+++ b/samples/browseable/JumpingJack/Application/res/values/template-styles.xml
@@ -0,0 +1,42 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Activity themes -->
+
+ <style name="Theme.Base" parent="android:Theme.Light" />
+
+ <style name="Theme.Sample" parent="Theme.Base" />
+
+ <style name="AppTheme" parent="Theme.Sample" />
+ <!-- Widget styling -->
+
+ <style name="Widget" />
+
+ <style name="Widget.SampleMessage">
+ <item name="android:textAppearance">?android:textAppearanceMedium</item>
+ <item name="android:lineSpacingMultiplier">1.1</item>
+ </style>
+
+ <style name="Widget.SampleMessageTile">
+ <item name="android:background">@drawable/tile</item>
+ <item name="android:shadowColor">#7F000000</item>
+ <item name="android:shadowDy">-3.5</item>
+ <item name="android:shadowRadius">2</item>
+ </style>
+
+</resources>
diff --git a/samples/browseable/JumpingJack/Application/src/com.example.android.common/activities/SampleActivityBase.java b/samples/browseable/JumpingJack/Application/src/com.example.android.common/activities/SampleActivityBase.java
new file mode 100644
index 0000000..3228927
--- /dev/null
+++ b/samples/browseable/JumpingJack/Application/src/com.example.android.common/activities/SampleActivityBase.java
@@ -0,0 +1,52 @@
+/*
+* Copyright 2013 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.common.activities;
+
+import android.os.Bundle;
+import android.support.v4.app.FragmentActivity;
+
+import com.example.android.common.logger.Log;
+import com.example.android.common.logger.LogWrapper;
+
+/**
+ * Base launcher activity, to handle most of the common plumbing for samples.
+ */
+public class SampleActivityBase extends FragmentActivity {
+
+ public static final String TAG = "SampleActivityBase";
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ initializeLogging();
+ }
+
+ /** Set up targets to receive log data */
+ public void initializeLogging() {
+ // Using Log, front-end to the logging chain, emulates android.util.log method signatures.
+ // Wraps Android's native log framework
+ LogWrapper logWrapper = new LogWrapper();
+ Log.setLogNode(logWrapper);
+
+ Log.i(TAG, "Ready");
+ }
+}
diff --git a/samples/browseable/JumpingJack/Application/src/com.example.android.common/logger/Log.java b/samples/browseable/JumpingJack/Application/src/com.example.android.common/logger/Log.java
new file mode 100644
index 0000000..17503c5
--- /dev/null
+++ b/samples/browseable/JumpingJack/Application/src/com.example.android.common/logger/Log.java
@@ -0,0 +1,236 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+/**
+ * Helper class for a list (or tree) of LoggerNodes.
+ *
+ * <p>When this is set as the head of the list,
+ * an instance of it can function as a drop-in replacement for {@link android.util.Log}.
+ * Most of the methods in this class server only to map a method call in Log to its equivalent
+ * in LogNode.</p>
+ */
+public class Log {
+ // Grabbing the native values from Android's native logging facilities,
+ // to make for easy migration and interop.
+ public static final int NONE = -1;
+ public static final int VERBOSE = android.util.Log.VERBOSE;
+ public static final int DEBUG = android.util.Log.DEBUG;
+ public static final int INFO = android.util.Log.INFO;
+ public static final int WARN = android.util.Log.WARN;
+ public static final int ERROR = android.util.Log.ERROR;
+ public static final int ASSERT = android.util.Log.ASSERT;
+
+ // Stores the beginning of the LogNode topology.
+ private static LogNode mLogNode;
+
+ /**
+ * Returns the next LogNode in the linked list.
+ */
+ public static LogNode getLogNode() {
+ return mLogNode;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to.
+ */
+ public static void setLogNode(LogNode node) {
+ mLogNode = node;
+ }
+
+ /**
+ * Instructs the LogNode to print the log data provided. Other LogNodes can
+ * be chained to the end of the LogNode as desired.
+ *
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void println(int priority, String tag, String msg, Throwable tr) {
+ if (mLogNode != null) {
+ mLogNode.println(priority, tag, msg, tr);
+ }
+ }
+
+ /**
+ * Instructs the LogNode to print the log data provided. Other LogNodes can
+ * be chained to the end of the LogNode as desired.
+ *
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ */
+ public static void println(int priority, String tag, String msg) {
+ println(priority, tag, msg, null);
+ }
+
+ /**
+ * Prints a message at VERBOSE priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void v(String tag, String msg, Throwable tr) {
+ println(VERBOSE, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at VERBOSE priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void v(String tag, String msg) {
+ v(tag, msg, null);
+ }
+
+
+ /**
+ * Prints a message at DEBUG priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void d(String tag, String msg, Throwable tr) {
+ println(DEBUG, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at DEBUG priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void d(String tag, String msg) {
+ d(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at INFO priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void i(String tag, String msg, Throwable tr) {
+ println(INFO, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at INFO priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void i(String tag, String msg) {
+ i(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void w(String tag, String msg, Throwable tr) {
+ println(WARN, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void w(String tag, String msg) {
+ w(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void w(String tag, Throwable tr) {
+ w(tag, null, tr);
+ }
+
+ /**
+ * Prints a message at ERROR priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void e(String tag, String msg, Throwable tr) {
+ println(ERROR, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at ERROR priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void e(String tag, String msg) {
+ e(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void wtf(String tag, String msg, Throwable tr) {
+ println(ASSERT, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void wtf(String tag, String msg) {
+ wtf(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void wtf(String tag, Throwable tr) {
+ wtf(tag, null, tr);
+ }
+}
diff --git a/samples/browseable/JumpingJack/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/JumpingJack/Application/src/com.example.android.common/logger/LogFragment.java
new file mode 100644
index 0000000..b302acd
--- /dev/null
+++ b/samples/browseable/JumpingJack/Application/src/com.example.android.common/logger/LogFragment.java
@@ -0,0 +1,109 @@
+/*
+* Copyright 2013 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.
+*/
+/*
+ * Copyright 2013 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.common.logger;
+
+import android.graphics.Typeface;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ScrollView;
+
+/**
+ * Simple fraggment which contains a LogView and uses is to output log data it receives
+ * through the LogNode interface.
+ */
+public class LogFragment extends Fragment {
+
+ private LogView mLogView;
+ private ScrollView mScrollView;
+
+ public LogFragment() {}
+
+ public View inflateViews() {
+ mScrollView = new ScrollView(getActivity());
+ ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT);
+ mScrollView.setLayoutParams(scrollParams);
+
+ mLogView = new LogView(getActivity());
+ ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams);
+ logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
+ mLogView.setLayoutParams(logParams);
+ mLogView.setClickable(true);
+ mLogView.setFocusable(true);
+ mLogView.setTypeface(Typeface.MONOSPACE);
+
+ // Want to set padding as 16 dips, setPadding takes pixels. Hooray math!
+ int paddingDips = 16;
+ double scale = getResources().getDisplayMetrics().density;
+ int paddingPixels = (int) ((paddingDips * (scale)) + .5);
+ mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels);
+ mLogView.setCompoundDrawablePadding(paddingPixels);
+
+ mLogView.setGravity(Gravity.BOTTOM);
+ mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium);
+
+ mScrollView.addView(mLogView);
+ return mScrollView;
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+
+ View result = inflateViews();
+
+ mLogView.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {}
+
+ @Override
+ public void afterTextChanged(Editable s) {
+ mScrollView.fullScroll(ScrollView.FOCUS_DOWN);
+ }
+ });
+ return result;
+ }
+
+ public LogView getLogView() {
+ return mLogView;
+ }
+}
\ No newline at end of file
diff --git a/samples/browseable/JumpingJack/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/JumpingJack/Application/src/com.example.android.common/logger/LogNode.java
new file mode 100644
index 0000000..bc37cab
--- /dev/null
+++ b/samples/browseable/JumpingJack/Application/src/com.example.android.common/logger/LogNode.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2012 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.common.logger;
+
+/**
+ * Basic interface for a logging system that can output to one or more targets.
+ * Note that in addition to classes that will output these logs in some format,
+ * one can also implement this interface over a filter and insert that in the chain,
+ * such that no targets further down see certain data, or see manipulated forms of the data.
+ * You could, for instance, write a "ToHtmlLoggerNode" that just converted all the log data
+ * it received to HTML and sent it along to the next node in the chain, without printing it
+ * anywhere.
+ */
+public interface LogNode {
+
+ /**
+ * Instructs first LogNode in the list to print the log data provided.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public void println(int priority, String tag, String msg, Throwable tr);
+
+}
diff --git a/samples/browseable/JumpingJack/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/JumpingJack/Application/src/com.example.android.common/logger/LogView.java
new file mode 100644
index 0000000..c01542b
--- /dev/null
+++ b/samples/browseable/JumpingJack/Application/src/com.example.android.common/logger/LogView.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+import android.app.Activity;
+import android.content.Context;
+import android.util.*;
+import android.widget.TextView;
+
+/** Simple TextView which is used to output log data received through the LogNode interface.
+*/
+public class LogView extends TextView implements LogNode {
+
+ public LogView(Context context) {
+ super(context);
+ }
+
+ public LogView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public LogView(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ /**
+ * Formats the log data and prints it out to the LogView.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+
+
+ String priorityStr = null;
+
+ // For the purposes of this View, we want to print the priority as readable text.
+ switch(priority) {
+ case android.util.Log.VERBOSE:
+ priorityStr = "VERBOSE";
+ break;
+ case android.util.Log.DEBUG:
+ priorityStr = "DEBUG";
+ break;
+ case android.util.Log.INFO:
+ priorityStr = "INFO";
+ break;
+ case android.util.Log.WARN:
+ priorityStr = "WARN";
+ break;
+ case android.util.Log.ERROR:
+ priorityStr = "ERROR";
+ break;
+ case android.util.Log.ASSERT:
+ priorityStr = "ASSERT";
+ break;
+ default:
+ break;
+ }
+
+ // Handily, the Log class has a facility for converting a stack trace into a usable string.
+ String exceptionStr = null;
+ if (tr != null) {
+ exceptionStr = android.util.Log.getStackTraceString(tr);
+ }
+
+ // Take the priority, tag, message, and exception, and concatenate as necessary
+ // into one usable line of text.
+ final StringBuilder outputBuilder = new StringBuilder();
+
+ String delimiter = "\t";
+ appendIfNotNull(outputBuilder, priorityStr, delimiter);
+ appendIfNotNull(outputBuilder, tag, delimiter);
+ appendIfNotNull(outputBuilder, msg, delimiter);
+ appendIfNotNull(outputBuilder, exceptionStr, delimiter);
+
+ // In case this was originally called from an AsyncTask or some other off-UI thread,
+ // make sure the update occurs within the UI thread.
+ ((Activity) getContext()).runOnUiThread( (new Thread(new Runnable() {
+ @Override
+ public void run() {
+ // Display the text we just generated within the LogView.
+ appendToLog(outputBuilder.toString());
+ }
+ })));
+
+ if (mNext != null) {
+ mNext.println(priority, tag, msg, tr);
+ }
+ }
+
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+ /** Takes a string and adds to it, with a separator, if the bit to be added isn't null. Since
+ * the logger takes so many arguments that might be null, this method helps cut out some of the
+ * agonizing tedium of writing the same 3 lines over and over.
+ * @param source StringBuilder containing the text to append to.
+ * @param addStr The String to append
+ * @param delimiter The String to separate the source and appended strings. A tab or comma,
+ * for instance.
+ * @return The fully concatenated String as a StringBuilder
+ */
+ private StringBuilder appendIfNotNull(StringBuilder source, String addStr, String delimiter) {
+ if (addStr != null) {
+ if (addStr.length() == 0) {
+ delimiter = "";
+ }
+
+ return source.append(addStr).append(delimiter);
+ }
+ return source;
+ }
+
+ // The next LogNode in the chain.
+ LogNode mNext;
+
+ /** Outputs the string as a new line of log data in the LogView. */
+ public void appendToLog(String s) {
+ append("\n" + s);
+ }
+
+
+}
diff --git a/samples/browseable/JumpingJack/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/JumpingJack/Application/src/com.example.android.common/logger/LogWrapper.java
new file mode 100644
index 0000000..16a9e7b
--- /dev/null
+++ b/samples/browseable/JumpingJack/Application/src/com.example.android.common/logger/LogWrapper.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2012 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.common.logger;
+
+import android.util.Log;
+
+/**
+ * Helper class which wraps Android's native Log utility in the Logger interface. This way
+ * normal DDMS output can be one of the many targets receiving and outputting logs simultaneously.
+ */
+public class LogWrapper implements LogNode {
+
+ // For piping: The next node to receive Log data after this one has done its work.
+ private LogNode mNext;
+
+ /**
+ * Returns the next LogNode in the linked list.
+ */
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to..
+ */
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+ /**
+ * Prints data out to the console using Android's native log mechanism.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+ // There actually are log methods that don't take a msg parameter. For now,
+ // if that's the case, just convert null to the empty string and move on.
+ String useMsg = msg;
+ if (useMsg == null) {
+ useMsg = "";
+ }
+
+ // If an exeption was provided, convert that exception to a usable string and attach
+ // it to the end of the msg method.
+ if (tr != null) {
+ msg += "\n" + Log.getStackTraceString(tr);
+ }
+
+ // This is functionally identical to Log.x(tag, useMsg);
+ // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg)
+ Log.println(priority, tag, useMsg);
+
+ // If this isn't the last node in the chain, move things along.
+ if (mNext != null) {
+ mNext.println(priority, tag, msg, tr);
+ }
+ }
+}
diff --git a/samples/browseable/JumpingJack/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/JumpingJack/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java
new file mode 100644
index 0000000..19967dc
--- /dev/null
+++ b/samples/browseable/JumpingJack/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+/**
+ * Simple {@link LogNode} filter, removes everything except the message.
+ * Useful for situations like on-screen log output where you don't want a lot of metadata displayed,
+ * just easy-to-read message updates as they're happening.
+ */
+public class MessageOnlyLogFilter implements LogNode {
+
+ LogNode mNext;
+
+ /**
+ * Takes the "next" LogNode as a parameter, to simplify chaining.
+ *
+ * @param next The next LogNode in the pipeline.
+ */
+ public MessageOnlyLogFilter(LogNode next) {
+ mNext = next;
+ }
+
+ public MessageOnlyLogFilter() {
+ }
+
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+ if (mNext != null) {
+ getNext().println(Log.NONE, null, msg, null);
+ }
+ }
+
+ /**
+ * Returns the next LogNode in the chain.
+ */
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to..
+ */
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+}
diff --git a/samples/browseable/JumpingJack/Shared/AndroidManifest.xml b/samples/browseable/JumpingJack/Shared/AndroidManifest.xml
new file mode 100644
index 0000000..7ba3326
--- /dev/null
+++ b/samples/browseable/JumpingJack/Shared/AndroidManifest.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.jumpingjack.common">
+
+ <application android:allowBackup="true"
+ android:label="@string/app_name">
+ </application>
+
+</manifest>
diff --git a/samples/browseable/JumpingJack/Shared/res/values/strings.xml b/samples/browseable/JumpingJack/Shared/res/values/strings.xml
new file mode 100644
index 0000000..0f2bb90
--- /dev/null
+++ b/samples/browseable/JumpingJack/Shared/res/values/strings.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<resources>
+ <string name="app_name">Shared</string>
+</resources>
diff --git a/samples/browseable/JumpingJack/Wearable/AndroidManifest.xml b/samples/browseable/JumpingJack/Wearable/AndroidManifest.xml
new file mode 100644
index 0000000..e0448d9
--- /dev/null
+++ b/samples/browseable/JumpingJack/Wearable/AndroidManifest.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.jumpingjack">
+
+ <uses-sdk android:minSdkVersion="20"
+ android:targetSdkVersion="20" />
+
+ <uses-feature android:name="android.hardware.type.watch" />
+
+ <uses-permission android:name="android.permission.VIBRATE"/>
+
+ <application
+ android:allowBackup="true"
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name"
+ android:theme="@android:style/Theme.DeviceDefault.Light">
+ <activity
+ android:name=".MainActivity"
+ android:label="@string/app_name">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ </activity>
+ </application>
+
+</manifest>
diff --git a/samples/browseable/JumpingJack/Wearable/res/drawable-hdpi/btn_reset_normal_200.png b/samples/browseable/JumpingJack/Wearable/res/drawable-hdpi/btn_reset_normal_200.png
new file mode 100644
index 0000000..e585202
--- /dev/null
+++ b/samples/browseable/JumpingJack/Wearable/res/drawable-hdpi/btn_reset_normal_200.png
Binary files differ
diff --git a/samples/browseable/JumpingJack/Wearable/res/drawable-hdpi/btn_reset_pressed_200.png b/samples/browseable/JumpingJack/Wearable/res/drawable-hdpi/btn_reset_pressed_200.png
new file mode 100644
index 0000000..0b83b6d
--- /dev/null
+++ b/samples/browseable/JumpingJack/Wearable/res/drawable-hdpi/btn_reset_pressed_200.png
Binary files differ
diff --git a/samples/browseable/JumpingJack/Wearable/res/drawable-hdpi/ic_launcher.png b/samples/browseable/JumpingJack/Wearable/res/drawable-hdpi/ic_launcher.png
new file mode 100644
index 0000000..2d0c37d
--- /dev/null
+++ b/samples/browseable/JumpingJack/Wearable/res/drawable-hdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/JumpingJack/Wearable/res/drawable-mdpi/ic_launcher.png b/samples/browseable/JumpingJack/Wearable/res/drawable-mdpi/ic_launcher.png
new file mode 100644
index 0000000..3211c9e
--- /dev/null
+++ b/samples/browseable/JumpingJack/Wearable/res/drawable-mdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/JumpingJack/Wearable/res/drawable-xhdpi/ic_launcher.png b/samples/browseable/JumpingJack/Wearable/res/drawable-xhdpi/ic_launcher.png
new file mode 100644
index 0000000..4ead8a2
--- /dev/null
+++ b/samples/browseable/JumpingJack/Wearable/res/drawable-xhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/JumpingJack/Wearable/res/drawable-xxhdpi/ic_launcher.png b/samples/browseable/JumpingJack/Wearable/res/drawable-xxhdpi/ic_launcher.png
new file mode 100644
index 0000000..8b357e4
--- /dev/null
+++ b/samples/browseable/JumpingJack/Wearable/res/drawable-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/JumpingJack/Wearable/res/drawable-xxxhdpi/ic_launcher.png b/samples/browseable/JumpingJack/Wearable/res/drawable-xxxhdpi/ic_launcher.png
new file mode 100644
index 0000000..da3c00a
--- /dev/null
+++ b/samples/browseable/JumpingJack/Wearable/res/drawable-xxxhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/JumpingJack/Wearable/res/drawable/empty_10.png b/samples/browseable/JumpingJack/Wearable/res/drawable/empty_10.png
new file mode 100644
index 0000000..78ee76b
--- /dev/null
+++ b/samples/browseable/JumpingJack/Wearable/res/drawable/empty_10.png
Binary files differ
diff --git a/samples/browseable/JumpingJack/Wearable/res/drawable/full_10.png b/samples/browseable/JumpingJack/Wearable/res/drawable/full_10.png
new file mode 100644
index 0000000..53b799e
--- /dev/null
+++ b/samples/browseable/JumpingJack/Wearable/res/drawable/full_10.png
Binary files differ
diff --git a/samples/browseable/JumpingJack/Wearable/res/drawable/jump_down_50.png b/samples/browseable/JumpingJack/Wearable/res/drawable/jump_down_50.png
new file mode 100644
index 0000000..28980f8
--- /dev/null
+++ b/samples/browseable/JumpingJack/Wearable/res/drawable/jump_down_50.png
Binary files differ
diff --git a/samples/browseable/JumpingJack/Wearable/res/drawable/jump_up_50.png b/samples/browseable/JumpingJack/Wearable/res/drawable/jump_up_50.png
new file mode 100644
index 0000000..86dcef5
--- /dev/null
+++ b/samples/browseable/JumpingJack/Wearable/res/drawable/jump_up_50.png
Binary files differ
diff --git a/samples/browseable/JumpingJack/Wearable/res/drawable/submit_button.xml b/samples/browseable/JumpingJack/Wearable/res/drawable/submit_button.xml
new file mode 100644
index 0000000..2ab9ba5
--- /dev/null
+++ b/samples/browseable/JumpingJack/Wearable/res/drawable/submit_button.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:drawable="@drawable/btn_reset_pressed_200"
+ android:state_pressed="true" />
+ <item android:drawable="@drawable/btn_reset_pressed_200"
+ android:state_focused="true" />
+ <item android:drawable="@drawable/btn_reset_normal_200" />
+</selector>
diff --git a/samples/browseable/JumpingJack/Wearable/res/layout/counter_layout.xml b/samples/browseable/JumpingJack/Wearable/res/layout/counter_layout.xml
new file mode 100644
index 0000000..e443e34
--- /dev/null
+++ b/samples/browseable/JumpingJack/Wearable/res/layout/counter_layout.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="@color/white">
+
+ <TextView
+ android:id="@+id/counter"
+ android:layout_centerInParent="true"
+ android:textSize="50sp"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content" />
+
+</RelativeLayout>
diff --git a/samples/browseable/JumpingJack/Wearable/res/layout/jj_layout.xml b/samples/browseable/JumpingJack/Wearable/res/layout/jj_layout.xml
new file mode 100644
index 0000000..73af6e3
--- /dev/null
+++ b/samples/browseable/JumpingJack/Wearable/res/layout/jj_layout.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="@color/white">
+
+ <android.support.v4.view.ViewPager
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/pager"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="#000"
+ />
+
+ <LinearLayout
+ android:layout_alignParentBottom="true"
+ android:layout_centerHorizontal="true"
+ android:layout_marginBottom="10dp"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content">
+ <ImageView
+ android:id="@+id/indicator_0"
+ android:layout_marginRight="5dp"
+ android:src="@drawable/full_10"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content" />
+ <ImageView
+ android:id="@+id/indicator_1"
+ android:src="@drawable/empty_10"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content" />
+ </LinearLayout>
+
+</RelativeLayout>
diff --git a/samples/browseable/JumpingJack/Wearable/res/layout/setting_layout.xml b/samples/browseable/JumpingJack/Wearable/res/layout/setting_layout.xml
new file mode 100644
index 0000000..1298409
--- /dev/null
+++ b/samples/browseable/JumpingJack/Wearable/res/layout/setting_layout.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="@color/white">
+
+ <Button
+ android:id="@+id/btn"
+ android:layout_alignParentTop="true"
+ android:layout_centerHorizontal="true"
+ android:layout_marginTop="40dp"
+ android:layout_width="75dp"
+ android:layout_height="75dp"
+ android:background="@drawable/submit_button"/>
+
+ <TextView
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_below="@+id/btn"
+ android:layout_marginTop="5dp"
+ android:gravity="center"
+ android:textColor="@color/blue"
+ android:text="@string/reset_counter"/>
+
+</RelativeLayout>
diff --git a/samples/browseable/JumpingJack/Wearable/res/values/colors.xml b/samples/browseable/JumpingJack/Wearable/res/values/colors.xml
new file mode 100644
index 0000000..eccbe6d
--- /dev/null
+++ b/samples/browseable/JumpingJack/Wearable/res/values/colors.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+ <color name="white">#ffffff</color>
+ <color name="blue">#3f51b5</color>
+</resources>
diff --git a/samples/browseable/JumpingJack/Wearable/res/values/dimens.xml b/samples/browseable/JumpingJack/Wearable/res/values/dimens.xml
new file mode 100644
index 0000000..a1e9cfe
--- /dev/null
+++ b/samples/browseable/JumpingJack/Wearable/res/values/dimens.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+ <!-- Default screen margins, per the Android Design guidelines. -->
+ <dimen name="activity_horizontal_margin">16dp</dimen>
+ <dimen name="activity_vertical_margin">16dp</dimen>
+</resources>
diff --git a/samples/browseable/JumpingJack/Wearable/res/values/strings.xml b/samples/browseable/JumpingJack/Wearable/res/values/strings.xml
new file mode 100644
index 0000000..8ab0f86
--- /dev/null
+++ b/samples/browseable/JumpingJack/Wearable/res/values/strings.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+
+ <string name="app_name">Jumping Jack</string>
+ <string name="reset_counter">Reset Counter</string>
+
+</resources>
diff --git a/samples/browseable/JumpingJack/Wearable/src/com.example.android.jumpingjack/MainActivity.java b/samples/browseable/JumpingJack/Wearable/src/com.example.android.jumpingjack/MainActivity.java
new file mode 100644
index 0000000..4fe2e79
--- /dev/null
+++ b/samples/browseable/JumpingJack/Wearable/src/com.example.android.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.jumpingjack;
+
+import com.example.android.jumpingjack.fragments.CounterFragment;
+import com.example.android.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/browseable/JumpingJack/Wearable/src/com.example.android.jumpingjack/PagerAdapter.java b/samples/browseable/JumpingJack/Wearable/src/com.example.android.jumpingjack/PagerAdapter.java
new file mode 100644
index 0000000..47fe86c
--- /dev/null
+++ b/samples/browseable/JumpingJack/Wearable/src/com.example.android.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.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<Fragment> mFragments = null;
+
+ public PagerAdapter(FragmentManager fm) {
+ super(fm);
+ mFragments = new ArrayList<Fragment>();
+ }
+
+ @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/browseable/JumpingJack/Wearable/src/com.example.android.jumpingjack/Utils.java b/samples/browseable/JumpingJack/Wearable/src/com.example.android.jumpingjack/Utils.java
new file mode 100644
index 0000000..90fc296
--- /dev/null
+++ b/samples/browseable/JumpingJack/Wearable/src/com.example.android.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.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 <code>DEFAULT_VIBRATION_DURATION_MS</code>.
+ */
+ 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 <code>value</code>
+ * 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
+ * <code>0</code>.
+ */
+ public static int getCounterFromPreference(Context context) {
+ SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
+ return pref.getInt(PREF_KEY_COUNTER, 0);
+ }
+
+}
diff --git a/samples/browseable/JumpingJack/Wearable/src/com.example.android.jumpingjack/fragments/CounterFragment.java b/samples/browseable/JumpingJack/Wearable/src/com.example.android.jumpingjack/fragments/CounterFragment.java
new file mode 100644
index 0000000..aa6fa53
--- /dev/null
+++ b/samples/browseable/JumpingJack/Wearable/src/com.example.android.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.jumpingjack.fragments;
+
+import com.example.android.jumpingjack.R;
+import com.example.android.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/browseable/JumpingJack/Wearable/src/com.example.android.jumpingjack/fragments/SettingsFragment.java b/samples/browseable/JumpingJack/Wearable/src/com.example.android.jumpingjack/fragments/SettingsFragment.java
new file mode 100644
index 0000000..0ef7a43
--- /dev/null
+++ b/samples/browseable/JumpingJack/Wearable/src/com.example.android.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.jumpingjack.fragments;
+
+import com.example.android.jumpingjack.MainActivity;
+import com.example.android.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/browseable/JumpingJack/_index.jd b/samples/browseable/JumpingJack/_index.jd
new file mode 100644
index 0000000..d742e9e
--- /dev/null
+++ b/samples/browseable/JumpingJack/_index.jd
@@ -0,0 +1,9 @@
+page.tags="JumpingJack"
+sample.group=Wearable
+@jd:body
+
+<p>
+
+ Uses the Gravity sensor to count how many jumping jacks you have performed.
+
+ </p>
diff --git a/samples/browseable/Notifications/Application/AndroidManifest.xml b/samples/browseable/Notifications/Application/AndroidManifest.xml
new file mode 100644
index 0000000..005d745
--- /dev/null
+++ b/samples/browseable/Notifications/Application/AndroidManifest.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.notifications" >
+
+
+ <uses-sdk android:minSdkVersion="19"
+ android:targetSdkVersion="19" />
+
+ <application
+ android:allowBackup="true"
+ android:icon="@mipmap/ic_launcher"
+ android:label="@string/app_name"
+ android:theme="@style/AppTheme" >
+
+ <activity
+ android:name=".MainActivity"
+ android:label="@string/app_name"
+ android:windowSoftInputMode="stateHidden" >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+
+ <receiver android:name=".NotificationIntentReceiver"
+ android:exported="false">
+ <intent-filter>
+ <action android:name="com.example.android.notifications.ACTION_EXAMPLE" />
+ <action android:name="com.example.android.notifications.ACTION_ENABLE_MESSAGES" />
+ <action android:name="com.example.android.notifications.ACTION_DISABLE_MESSAGES" />
+ </intent-filter>
+ </receiver>
+
+ </application>
+
+</manifest>
diff --git a/samples/browseable/Notifications/Application/res/drawable-hdpi/example_large_icon.png b/samples/browseable/Notifications/Application/res/drawable-hdpi/example_large_icon.png
new file mode 100644
index 0000000..545f8ce
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/drawable-hdpi/example_large_icon.png
Binary files differ
diff --git a/samples/browseable/Notifications/Application/res/drawable-hdpi/ic_full_action.png b/samples/browseable/Notifications/Application/res/drawable-hdpi/ic_full_action.png
new file mode 100644
index 0000000..1f27499
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/drawable-hdpi/ic_full_action.png
Binary files differ
diff --git a/samples/browseable/Notifications/Application/res/drawable-hdpi/ic_full_reply.png b/samples/browseable/Notifications/Application/res/drawable-hdpi/ic_full_reply.png
new file mode 100644
index 0000000..66388d5
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/drawable-hdpi/ic_full_reply.png
Binary files differ
diff --git a/samples/browseable/Notifications/Application/res/drawable-hdpi/ic_result_open.png b/samples/browseable/Notifications/Application/res/drawable-hdpi/ic_result_open.png
new file mode 100644
index 0000000..db8af57
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/drawable-hdpi/ic_result_open.png
Binary files differ
diff --git a/samples/browseable/Notifications/Application/res/drawable-hdpi/tile.9.png b/samples/browseable/Notifications/Application/res/drawable-hdpi/tile.9.png
new file mode 100644
index 0000000..1358628
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/drawable-hdpi/tile.9.png
Binary files differ
diff --git a/samples/browseable/Notifications/Application/res/drawable-mdpi/ic_full_action.png b/samples/browseable/Notifications/Application/res/drawable-mdpi/ic_full_action.png
new file mode 100644
index 0000000..b70b74f
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/drawable-mdpi/ic_full_action.png
Binary files differ
diff --git a/samples/browseable/Notifications/Application/res/drawable-mdpi/ic_full_reply.png b/samples/browseable/Notifications/Application/res/drawable-mdpi/ic_full_reply.png
new file mode 100644
index 0000000..60ce9f9
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/drawable-mdpi/ic_full_reply.png
Binary files differ
diff --git a/samples/browseable/Notifications/Application/res/drawable-mdpi/ic_result_open.png b/samples/browseable/Notifications/Application/res/drawable-mdpi/ic_result_open.png
new file mode 100644
index 0000000..860d7de
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/drawable-mdpi/ic_result_open.png
Binary files differ
diff --git a/samples/browseable/Notifications/Application/res/drawable-nodpi/bg_1.png b/samples/browseable/Notifications/Application/res/drawable-nodpi/bg_1.png
new file mode 100644
index 0000000..9c80794
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/drawable-nodpi/bg_1.png
Binary files differ
diff --git a/samples/browseable/Notifications/Application/res/drawable-nodpi/bg_2.png b/samples/browseable/Notifications/Application/res/drawable-nodpi/bg_2.png
new file mode 100644
index 0000000..23d7062
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/drawable-nodpi/bg_2.png
Binary files differ
diff --git a/samples/browseable/Notifications/Application/res/drawable-nodpi/bg_3.png b/samples/browseable/Notifications/Application/res/drawable-nodpi/bg_3.png
new file mode 100644
index 0000000..588318d
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/drawable-nodpi/bg_3.png
Binary files differ
diff --git a/samples/browseable/Notifications/Application/res/drawable-nodpi/bg_4.png b/samples/browseable/Notifications/Application/res/drawable-nodpi/bg_4.png
new file mode 100644
index 0000000..bd1dfee
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/drawable-nodpi/bg_4.png
Binary files differ
diff --git a/samples/browseable/Notifications/Application/res/drawable-nodpi/bg_5.png b/samples/browseable/Notifications/Application/res/drawable-nodpi/bg_5.png
new file mode 100644
index 0000000..aa1ad23
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/drawable-nodpi/bg_5.png
Binary files differ
diff --git a/samples/browseable/Notifications/Application/res/drawable-nodpi/content_icon_large.png b/samples/browseable/Notifications/Application/res/drawable-nodpi/content_icon_large.png
new file mode 100644
index 0000000..0eab3b1
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/drawable-nodpi/content_icon_large.png
Binary files differ
diff --git a/samples/browseable/Notifications/Application/res/drawable-nodpi/content_icon_small.png b/samples/browseable/Notifications/Application/res/drawable-nodpi/content_icon_small.png
new file mode 100644
index 0000000..9a9f4b4
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/drawable-nodpi/content_icon_small.png
Binary files differ
diff --git a/samples/browseable/Notifications/Application/res/drawable-nodpi/example_big_picture.jpg b/samples/browseable/Notifications/Application/res/drawable-nodpi/example_big_picture.jpg
new file mode 100644
index 0000000..68473ba
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/drawable-nodpi/example_big_picture.jpg
Binary files differ
diff --git a/samples/browseable/Notifications/Application/res/drawable-xhdpi/ic_full_action.png b/samples/browseable/Notifications/Application/res/drawable-xhdpi/ic_full_action.png
new file mode 100644
index 0000000..6a76952
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/drawable-xhdpi/ic_full_action.png
Binary files differ
diff --git a/samples/browseable/Notifications/Application/res/drawable-xhdpi/ic_full_reply.png b/samples/browseable/Notifications/Application/res/drawable-xhdpi/ic_full_reply.png
new file mode 100644
index 0000000..dba6fa7
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/drawable-xhdpi/ic_full_reply.png
Binary files differ
diff --git a/samples/browseable/Notifications/Application/res/drawable-xhdpi/ic_result_open.png b/samples/browseable/Notifications/Application/res/drawable-xhdpi/ic_result_open.png
new file mode 100644
index 0000000..7d3c785
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/drawable-xhdpi/ic_result_open.png
Binary files differ
diff --git a/samples/browseable/Notifications/Application/res/drawable/selected_background.xml b/samples/browseable/Notifications/Application/res/drawable/selected_background.xml
new file mode 100644
index 0000000..5852dd8
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/drawable/selected_background.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="rectangle">
+ <padding
+ android:top="4dp"
+ android:bottom="4dp"
+ android:left="4dp"
+ android:right="4dp"/>
+ <stroke
+ android:width="4dp"
+ android:color="@android:color/holo_blue_bright" />
+</shape>
diff --git a/samples/browseable/Notifications/Application/res/drawable/unselected_background.xml b/samples/browseable/Notifications/Application/res/drawable/unselected_background.xml
new file mode 100644
index 0000000..1613167
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/drawable/unselected_background.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="rectangle">
+ <padding
+ android:top="4dp"
+ android:bottom="4dp"
+ android:left="4dp"
+ android:right="4dp"/>
+ <stroke
+ android:width="4dp"
+ android:color="#ff000000" />
+</shape>
diff --git a/samples/browseable/Notifications/Application/res/layout/activity_main.xml b/samples/browseable/Notifications/Application/res/layout/activity_main.xml
new file mode 100755
index 0000000..be1aa49
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/layout/activity_main.xml
@@ -0,0 +1,36 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <LinearLayout style="@style/Widget.SampleMessageTile"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+
+ <TextView style="@style/Widget.SampleMessage"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="@dimen/horizontal_page_margin"
+ android:layout_marginRight="@dimen/horizontal_page_margin"
+ android:layout_marginTop="@dimen/vertical_page_margin"
+ android:layout_marginBottom="@dimen/vertical_page_margin"
+ android:text="@string/intro_message" />
+ </LinearLayout>
+</LinearLayout>
diff --git a/samples/browseable/Notifications/Application/res/layout/background_picker.xml b/samples/browseable/Notifications/Application/res/layout/background_picker.xml
new file mode 100644
index 0000000..03f77f1
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/layout/background_picker.xml
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <TextView
+ android:id="@+id/bg_picker_label"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="@dimen/editor_item_padding_top"
+ android:paddingTop="@dimen/editor_item_padding_top"
+ android:paddingBottom="@dimen/editor_item_padding_top"
+ android:text="@string/bg_picker_label"/>
+
+ <HorizontalScrollView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+ <LinearLayout
+ android:id="@+id/bg_picker_container"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+ <ImageView
+ android:id="@+id/bg_none"
+ android:background="@drawable/selected_background"
+ style="@style/bg_picker"
+ android:layout_width="@dimen/image_picker_item_side"
+ android:layout_height="@dimen/image_picker_item_side"
+ android:src="@android:color/background_light"/>
+ <ImageView
+ android:id="@+id/bg1"
+ style="@style/bg_picker"
+ android:layout_width="@dimen/image_picker_item_side"
+ android:layout_height="@dimen/image_picker_item_side"
+ android:tag="bg_1"
+ android:src="@drawable/bg_1"/>
+ <ImageView
+ android:id="@+id/bg2"
+ style="@style/bg_picker"
+ android:layout_width="@dimen/image_picker_item_side"
+ android:layout_height="@dimen/image_picker_item_side"
+ android:tag="bg_2"
+ android:src="@drawable/bg_2"/>
+ <ImageView
+ android:id="@+id/bg3"
+ style="@style/bg_picker"
+ android:layout_width="@dimen/image_picker_item_side"
+ android:layout_height="@dimen/image_picker_item_side"
+ android:tag="bg_3"
+ android:src="@drawable/bg_3"/>
+ <ImageView
+ android:id="@+id/bg4"
+ style="@style/bg_picker"
+ android:layout_width="@dimen/image_picker_item_side"
+ android:layout_height="@dimen/image_picker_item_side"
+ android:tag="bg_4"
+ android:src="@drawable/bg_4"/>
+ <ImageView
+ android:id="@+id/bg5"
+ style="@style/bg_picker"
+ android:layout_width="@dimen/image_picker_item_side"
+ android:layout_height="@dimen/image_picker_item_side"
+ android:tag="bg_5"
+ android:src="@drawable/bg_5"/>
+ </LinearLayout>
+
+ </HorizontalScrollView>
+
+</LinearLayout>
diff --git a/samples/browseable/Notifications/Application/res/layout/layout_divider.xml b/samples/browseable/Notifications/Application/res/layout/layout_divider.xml
new file mode 100644
index 0000000..82142b7
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/layout/layout_divider.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<!--
+ Copyright 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.
+ -->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical" >
+
+ <TextView
+ android:id="@+id/divider_text"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="3dp"
+ android:textAllCaps="true"
+ android:textColor="@color/divider_text"
+ android:textSize="@dimen/editor_text_size"
+ android:text="@string/properties"/>
+
+ <View
+ android:layout_width="match_parent"
+ android:layout_height="1dp"
+ android:layout_marginTop="3dp"
+ android:background="@color/divider_text" />
+
+</LinearLayout>
diff --git a/samples/browseable/Notifications/Application/res/layout/main.xml b/samples/browseable/Notifications/Application/res/layout/main.xml
new file mode 100644
index 0000000..3068ddc
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/layout/main.xml
@@ -0,0 +1,173 @@
+
+<!-- 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.
+-->
+
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:paddingBottom="@dimen/activity_vertical_margin"
+ android:paddingLeft="@dimen/activity_horizontal_margin"
+ android:paddingRight="@dimen/activity_horizontal_margin"
+ android:paddingTop="@dimen/activity_vertical_margin"
+ tools:context="com.example.android.support.wearable.notifications.MainActivity"
+ tools:ignore="MergeRootFrame">
+
+ <LinearLayout android:id="@+id/container"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+
+ <include layout="@layout/layout_divider" />
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal">
+
+ <TextView
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:minWidth="@dimen/editor_spinner_caption_min_width"
+ android:minHeight="?android:attr/listPreferredItemHeightSmall"
+ android:gravity="center_vertical"
+ android:text="@string/preset" />
+
+ <Spinner android:id="@+id/preset_spinner"
+ android:layout_marginLeft="10dp"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" />
+
+ </LinearLayout>
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal">
+
+ <TextView
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:minWidth="@dimen/editor_spinner_caption_min_width"
+ android:minHeight="?android:attr/listPreferredItemHeightSmall"
+ android:gravity="center_vertical"
+ android:text="@string/priority" />
+
+ <Spinner android:id="@+id/priority_spinner"
+ android:layout_marginLeft="10dp"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" />
+
+ </LinearLayout>
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal">
+
+ <TextView
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:minWidth="@dimen/editor_spinner_caption_min_width"
+ android:minHeight="?android:attr/listPreferredItemHeightSmall"
+ android:gravity="center_vertical"
+ android:text="@string/actions" />
+
+ <Spinner android:id="@+id/actions_spinner"
+ android:layout_marginLeft="10dp"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" />
+
+ </LinearLayout>
+
+ <LinearLayout
+ android:id="@+id/title_edit_field"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal">
+
+ <TextView
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:minWidth="@dimen/editor_spinner_caption_min_width"
+ android:minHeight="?android:attr/listPreferredItemHeightSmall"
+ android:gravity="center_vertical"
+ android:text="@string/title" />
+
+ <EditText android:id="@+id/title_editor"
+ android:layout_marginLeft="10dp"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" />
+
+ </LinearLayout>
+
+ <LinearLayout
+ android:id="@+id/text_edit_field"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal">
+
+ <TextView
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:minWidth="@dimen/editor_spinner_caption_min_width"
+ android:minHeight="?android:attr/listPreferredItemHeightSmall"
+ android:gravity="center_vertical"
+ android:text="@string/text" />
+
+ <EditText android:id="@+id/text_editor"
+ android:layout_marginLeft="10dp"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" />
+
+ </LinearLayout>
+
+ <CheckBox android:id="@+id/include_large_icon_checkbox"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:paddingTop="@dimen/editor_item_padding_top"
+ android:paddingBottom="@dimen/editor_item_padding_bottom"
+ android:text="@string/include_large_icon" />
+
+ <CheckBox android:id="@+id/local_only_checkbox"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:paddingTop="@dimen/editor_item_padding_top"
+ android:paddingBottom="@dimen/editor_item_padding_bottom"
+ android:text="@string/local_only" />
+
+ <CheckBox android:id="@+id/include_content_intent_checkbox"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:paddingTop="@dimen/editor_item_padding_top"
+ android:paddingBottom="@dimen/editor_item_padding_bottom"
+ android:text="@string/include_content_intent" />
+
+ <CheckBox android:id="@+id/vibrate_checkbox"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:paddingTop="@dimen/editor_item_padding_top"
+ android:paddingBottom="@dimen/editor_item_padding_bottom"
+ android:text="@string/vibrate" />
+
+ <LinearLayout android:id="@+id/background_pickers"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+ </LinearLayout>
+
+ </LinearLayout>
+
+</ScrollView>
diff --git a/samples/browseable/Notifications/Application/res/layout/simple_spinner_item.xml b/samples/browseable/Notifications/Application/res/layout/simple_spinner_item.xml
new file mode 100644
index 0000000..342a130
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/layout/simple_spinner_item.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<TextView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceListItemSmall"
+ android:gravity="center_vertical"
+ android:paddingStart="?android:attr/listPreferredItemPaddingStart"
+ android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
+ android:background="?android:attr/activatedBackgroundIndicator"
+ android:minHeight="?android:attr/listPreferredItemHeightSmall" />
diff --git a/samples/browseable/Notifications/Application/res/mipmap-hdpi/ic_launcher.png b/samples/browseable/Notifications/Application/res/mipmap-hdpi/ic_launcher.png
new file mode 100644
index 0000000..41479de
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/mipmap-hdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/Notifications/Application/res/mipmap-mdpi/ic_launcher.png b/samples/browseable/Notifications/Application/res/mipmap-mdpi/ic_launcher.png
new file mode 100644
index 0000000..380b02f
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/mipmap-mdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/Notifications/Application/res/mipmap-xhdpi/ic_launcher.png b/samples/browseable/Notifications/Application/res/mipmap-xhdpi/ic_launcher.png
new file mode 100644
index 0000000..b3e251e
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/mipmap-xhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/Notifications/Application/res/mipmap-xxhdpi/ic_launcher.png b/samples/browseable/Notifications/Application/res/mipmap-xxhdpi/ic_launcher.png
new file mode 100644
index 0000000..1962289
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/mipmap-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/Notifications/Application/res/mipmap-xxxhdpi/ic_launcher.png b/samples/browseable/Notifications/Application/res/mipmap-xxxhdpi/ic_launcher.png
new file mode 100644
index 0000000..163f1f0
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/mipmap-xxxhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/Notifications/Application/res/values-sw600dp/template-dimens.xml b/samples/browseable/Notifications/Application/res/values-sw600dp/template-dimens.xml
new file mode 100644
index 0000000..22074a2
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/values-sw600dp/template-dimens.xml
@@ -0,0 +1,24 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Semantic definitions -->
+
+ <dimen name="horizontal_page_margin">@dimen/margin_huge</dimen>
+ <dimen name="vertical_page_margin">@dimen/margin_medium</dimen>
+
+</resources>
diff --git a/samples/browseable/Notifications/Application/res/values-sw600dp/template-styles.xml b/samples/browseable/Notifications/Application/res/values-sw600dp/template-styles.xml
new file mode 100644
index 0000000..03d1974
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/values-sw600dp/template-styles.xml
@@ -0,0 +1,25 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <style name="Widget.SampleMessage">
+ <item name="android:textAppearance">?android:textAppearanceLarge</item>
+ <item name="android:lineSpacingMultiplier">1.2</item>
+ <item name="android:shadowDy">-6.5</item>
+ </style>
+
+</resources>
diff --git a/samples/browseable/Notifications/Application/res/values-v11/template-styles.xml b/samples/browseable/Notifications/Application/res/values-v11/template-styles.xml
new file mode 100644
index 0000000..8c1ea66
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/values-v11/template-styles.xml
@@ -0,0 +1,22 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Activity themes -->
+ <style name="Theme.Base" parent="android:Theme.Holo.Light" />
+
+</resources>
diff --git a/samples/browseable/Notifications/Application/res/values/base-strings.xml b/samples/browseable/Notifications/Application/res/values/base-strings.xml
new file mode 100644
index 0000000..9abe486
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/values/base-strings.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 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.
+-->
+<resources>
+ <string name="app_name">Notifications</string>
+ <string name="intro_message">
+ <![CDATA[
+
+
+This sample application provides a showcase of available notification styles and
+demonstrates various features of the Android Wear notifications API. Running the sample on your
+companion allows you to select between various notification styles and to see how these
+notifications are displayed, both in a phone\'s notification shade and on the wearable.
+
+
+ ]]>
+ </string>
+</resources>
diff --git a/samples/browseable/Notifications/Application/res/values/colors.xml b/samples/browseable/Notifications/Application/res/values/colors.xml
new file mode 100644
index 0000000..9464085
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/values/colors.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+ <color name="divider_text">@android:color/holo_blue_bright</color>
+</resources>
diff --git a/samples/browseable/Notifications/Application/res/values/dimens.xml b/samples/browseable/Notifications/Application/res/values/dimens.xml
new file mode 100644
index 0000000..fd97910
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/values/dimens.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+ <!-- Default screen margins, per the Android Design guidelines. -->
+ <dimen name="activity_horizontal_margin">16dp</dimen>
+ <dimen name="activity_vertical_margin">16dp</dimen>
+
+ <dimen name="editor_text_size">12dp</dimen>
+ <dimen name="editor_item_padding_top">8dp</dimen>
+ <dimen name="editor_item_padding_bottom">8dp</dimen>
+ <dimen name="editor_spinner_caption_min_width">50dp</dimen>
+
+ <dimen name="image_picker_item_side">48dp</dimen>
+
+</resources>
diff --git a/samples/browseable/Notifications/Application/res/values/strings.xml b/samples/browseable/Notifications/Application/res/values/strings.xml
new file mode 100644
index 0000000..52f0f10
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/values/strings.xml
@@ -0,0 +1,192 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+
+ <string name="properties">Properties</string>
+ <string name="preset">Preset</string>
+ <string name="text">Text</string>
+ <string name="title">Title</string>
+ <string name="priority">Priority</string>
+ <string name="actions">Actions</string>
+ <string name="include_large_icon">Include large icon</string>
+ <string name="local_only">Local only</string>
+ <string name="include_content_intent">Include content intent</string>
+ <string name="vibrate">Vibrate</string>
+
+ <string name="basic_example">Basic example</string>
+ <string name="stylized_text_example">Stylized text example</string>
+ <string name="inbox_example">Inbox example</string>
+ <string name="big_picture_example">Big picture example</string>
+ <string name="big_text_example">Big text example</string>
+ <string name="bottom_aligned_example">Bottom-aligned example</string>
+ <string name="gravity_example">Gravity example</string>
+ <string name="content_action_example">Content action example</string>
+ <string name="content_icon_example">Content icon example</string>
+ <string name="multiple_page_example">Multiple page example</string>
+ <string name="bundle_example">Bundle example</string>
+
+ <string name="min_priority">Min priority</string>
+ <string name="low_priority">Low priority</string>
+ <string name="default_priority">Default priority</string>
+ <string name="high_priority">High priority</string>
+ <string name="max_priority">Max priority</string>
+
+ <string name="no_actions">No actions</string>
+ <string name="single_action">Single action</string>
+ <string name="long_title_action">Single action with a long title</string>
+ <string name="reply_action">Reply action</string>
+ <string name="reply_action_with_choices">Reply action with choices</string>
+ <string name="different_actions_on_phone_and_wearable">Different on phone and wearable</string>
+
+ <string name="example_action">Example action</string>
+ <string name="example_action_long_title">Example action with a long title which wraps</string>
+ <string name="example_reply_action">Example reply action</string>
+ <string name="phone_action">Phone action</string>
+ <string name="wearable_action">Wearable action</string>
+
+ <string name="example_action_clicked">Example action clicked</string>
+ <string name="example_reply_action_clicked">Example reply action clicked</string>
+ <string name="phone_action_clicked">Phone action clicked</string>
+ <string name="wearable_action_clicked">Wearable action clicked</string>
+ <string name="second_child_action_clicked">Second child action clicked</string>
+ <string name="content_intent_clicked">Content intent clicked</string>
+ <string name="example_content_action_clicked">Example content action clicked</string>
+ <string name="example_content_action2_clicked">Example content action 2 clicked</string>
+ <string name="example_notification_deleted">Example notification deleted</string>
+
+ <string name="example_content_title">Basic example title</string>
+ <string name="example_content_text">Basic example text</string>
+
+ <string name="big_text_example_title">Big text example title</string>
+ <string name="big_text_example_summary_text">Big text example summary</string>
+ <string name="big_text_example_big_text">
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
+ incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
+ exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
+ dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
+ Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit
+ anim id est laborum.
+
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
+ incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
+ exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
+ dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
+ Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit
+ anim id est laborum.
+
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
+ incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
+ exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
+ dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
+ Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit
+ anim id est laborum.
+
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
+ incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
+ exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
+ dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
+ Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit
+ anim id est laborum.
+
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
+ incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
+ exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
+ dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
+ Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit
+ anim id est laborum.
+
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
+ incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
+ exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
+ dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
+ Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit
+ anim id est laborum.
+
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
+ incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
+ exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
+ dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
+ Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit
+ anim id est laborum.
+
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
+ incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
+ exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
+ dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
+ Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit
+ anim id est laborum.
+
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
+ incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
+ exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
+ dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
+ Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit
+ anim id est laborum.
+
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
+ incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
+ exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
+ dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
+ Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit
+ anim id est laborum.
+
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
+ incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
+ exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
+ dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
+ Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit
+ anim id est laborum.
+ </string>
+
+ <string name="inbox_style_example_title">Inbox style example title</string>
+ <string name="inbox_style_example_summary_text">Inbox style example summary</string>
+ <string name="inbox_style_example_line1">Inbox style example line 1</string>
+ <string name="inbox_style_example_line2">Inbox style example line 2</string>
+ <string name="inbox_style_example_line3">Inbox style example line 3</string>
+
+ <string name="big_picture_style_example_title">Big picture style example title</string>
+ <string name="big_picture_style_example_summary_text">Big picture style example summary</string>
+
+ <string name="second_page_content_title">Second page title</string>
+ <string name="second_page_content_text">Second page text</string>
+
+ <string name="third_page_content_title">Third page title</string>
+ <string name="third_page_content_text">Third page text</string>
+
+ <string name="fourth_page_content_title">Fourth page title</string>
+ <string name="fourth_page_content_text">Fourth page text</string>
+
+ <string name="first_child_content_title">First child title</string>
+ <string name="first_child_content_text">
+ First child text. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
+ tempor incididunt ut labore et dolore magna aliqua.</string>
+ <string name="second_child_content_title">Second child title</string>
+ <string name="second_child_content_text">
+ Second child text. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
+ tempor incididunt ut labore et dolore magna aliqua.</string>
+ <string name="second_child_action">Second child action</string>
+
+ <string name="example_reply_label">Message?</string>
+
+ <string name="example_reply_answer_label">Answer?</string>
+ <string name="yes">Yes</string>
+ <string name="no">No</string>
+ <string name="maybe">Maybe</string>
+
+ <string name="bg_picker_label">Page %s background: </string>
+
+</resources>
diff --git a/samples/browseable/Notifications/Application/res/values/styles.xml b/samples/browseable/Notifications/Application/res/values/styles.xml
new file mode 100644
index 0000000..69f8dfa
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/values/styles.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+
+ <style name="bg_picker">
+ <item name="android:layout_marginLeft">16dp</item>
+ <item name="android:background">@drawable/unselected_background</item>
+ </style>
+
+</resources>
diff --git a/samples/browseable/Notifications/Application/res/values/template-dimens.xml b/samples/browseable/Notifications/Application/res/values/template-dimens.xml
new file mode 100644
index 0000000..39e710b
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/values/template-dimens.xml
@@ -0,0 +1,32 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Define standard dimensions to comply with Holo-style grids and rhythm. -->
+
+ <dimen name="margin_tiny">4dp</dimen>
+ <dimen name="margin_small">8dp</dimen>
+ <dimen name="margin_medium">16dp</dimen>
+ <dimen name="margin_large">32dp</dimen>
+ <dimen name="margin_huge">64dp</dimen>
+
+ <!-- Semantic definitions -->
+
+ <dimen name="horizontal_page_margin">@dimen/margin_medium</dimen>
+ <dimen name="vertical_page_margin">@dimen/margin_medium</dimen>
+
+</resources>
diff --git a/samples/browseable/Notifications/Application/res/values/template-styles.xml b/samples/browseable/Notifications/Application/res/values/template-styles.xml
new file mode 100644
index 0000000..6e7d593
--- /dev/null
+++ b/samples/browseable/Notifications/Application/res/values/template-styles.xml
@@ -0,0 +1,42 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Activity themes -->
+
+ <style name="Theme.Base" parent="android:Theme.Light" />
+
+ <style name="Theme.Sample" parent="Theme.Base" />
+
+ <style name="AppTheme" parent="Theme.Sample" />
+ <!-- Widget styling -->
+
+ <style name="Widget" />
+
+ <style name="Widget.SampleMessage">
+ <item name="android:textAppearance">?android:textAppearanceMedium</item>
+ <item name="android:lineSpacingMultiplier">1.1</item>
+ </style>
+
+ <style name="Widget.SampleMessageTile">
+ <item name="android:background">@drawable/tile</item>
+ <item name="android:shadowColor">#7F000000</item>
+ <item name="android:shadowDy">-3.5</item>
+ <item name="android:shadowRadius">2</item>
+ </style>
+
+</resources>
diff --git a/samples/browseable/Notifications/Application/src/com.example.android.common/activities/SampleActivityBase.java b/samples/browseable/Notifications/Application/src/com.example.android.common/activities/SampleActivityBase.java
new file mode 100644
index 0000000..3228927
--- /dev/null
+++ b/samples/browseable/Notifications/Application/src/com.example.android.common/activities/SampleActivityBase.java
@@ -0,0 +1,52 @@
+/*
+* Copyright 2013 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.common.activities;
+
+import android.os.Bundle;
+import android.support.v4.app.FragmentActivity;
+
+import com.example.android.common.logger.Log;
+import com.example.android.common.logger.LogWrapper;
+
+/**
+ * Base launcher activity, to handle most of the common plumbing for samples.
+ */
+public class SampleActivityBase extends FragmentActivity {
+
+ public static final String TAG = "SampleActivityBase";
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ initializeLogging();
+ }
+
+ /** Set up targets to receive log data */
+ public void initializeLogging() {
+ // Using Log, front-end to the logging chain, emulates android.util.log method signatures.
+ // Wraps Android's native log framework
+ LogWrapper logWrapper = new LogWrapper();
+ Log.setLogNode(logWrapper);
+
+ Log.i(TAG, "Ready");
+ }
+}
diff --git a/samples/browseable/Notifications/Application/src/com.example.android.common/logger/Log.java b/samples/browseable/Notifications/Application/src/com.example.android.common/logger/Log.java
new file mode 100644
index 0000000..17503c5
--- /dev/null
+++ b/samples/browseable/Notifications/Application/src/com.example.android.common/logger/Log.java
@@ -0,0 +1,236 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+/**
+ * Helper class for a list (or tree) of LoggerNodes.
+ *
+ * <p>When this is set as the head of the list,
+ * an instance of it can function as a drop-in replacement for {@link android.util.Log}.
+ * Most of the methods in this class server only to map a method call in Log to its equivalent
+ * in LogNode.</p>
+ */
+public class Log {
+ // Grabbing the native values from Android's native logging facilities,
+ // to make for easy migration and interop.
+ public static final int NONE = -1;
+ public static final int VERBOSE = android.util.Log.VERBOSE;
+ public static final int DEBUG = android.util.Log.DEBUG;
+ public static final int INFO = android.util.Log.INFO;
+ public static final int WARN = android.util.Log.WARN;
+ public static final int ERROR = android.util.Log.ERROR;
+ public static final int ASSERT = android.util.Log.ASSERT;
+
+ // Stores the beginning of the LogNode topology.
+ private static LogNode mLogNode;
+
+ /**
+ * Returns the next LogNode in the linked list.
+ */
+ public static LogNode getLogNode() {
+ return mLogNode;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to.
+ */
+ public static void setLogNode(LogNode node) {
+ mLogNode = node;
+ }
+
+ /**
+ * Instructs the LogNode to print the log data provided. Other LogNodes can
+ * be chained to the end of the LogNode as desired.
+ *
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void println(int priority, String tag, String msg, Throwable tr) {
+ if (mLogNode != null) {
+ mLogNode.println(priority, tag, msg, tr);
+ }
+ }
+
+ /**
+ * Instructs the LogNode to print the log data provided. Other LogNodes can
+ * be chained to the end of the LogNode as desired.
+ *
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ */
+ public static void println(int priority, String tag, String msg) {
+ println(priority, tag, msg, null);
+ }
+
+ /**
+ * Prints a message at VERBOSE priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void v(String tag, String msg, Throwable tr) {
+ println(VERBOSE, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at VERBOSE priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void v(String tag, String msg) {
+ v(tag, msg, null);
+ }
+
+
+ /**
+ * Prints a message at DEBUG priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void d(String tag, String msg, Throwable tr) {
+ println(DEBUG, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at DEBUG priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void d(String tag, String msg) {
+ d(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at INFO priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void i(String tag, String msg, Throwable tr) {
+ println(INFO, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at INFO priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void i(String tag, String msg) {
+ i(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void w(String tag, String msg, Throwable tr) {
+ println(WARN, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void w(String tag, String msg) {
+ w(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void w(String tag, Throwable tr) {
+ w(tag, null, tr);
+ }
+
+ /**
+ * Prints a message at ERROR priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void e(String tag, String msg, Throwable tr) {
+ println(ERROR, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at ERROR priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void e(String tag, String msg) {
+ e(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void wtf(String tag, String msg, Throwable tr) {
+ println(ASSERT, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void wtf(String tag, String msg) {
+ wtf(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void wtf(String tag, Throwable tr) {
+ wtf(tag, null, tr);
+ }
+}
diff --git a/samples/browseable/Notifications/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/Notifications/Application/src/com.example.android.common/logger/LogFragment.java
new file mode 100644
index 0000000..b302acd
--- /dev/null
+++ b/samples/browseable/Notifications/Application/src/com.example.android.common/logger/LogFragment.java
@@ -0,0 +1,109 @@
+/*
+* Copyright 2013 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.
+*/
+/*
+ * Copyright 2013 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.common.logger;
+
+import android.graphics.Typeface;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ScrollView;
+
+/**
+ * Simple fraggment which contains a LogView and uses is to output log data it receives
+ * through the LogNode interface.
+ */
+public class LogFragment extends Fragment {
+
+ private LogView mLogView;
+ private ScrollView mScrollView;
+
+ public LogFragment() {}
+
+ public View inflateViews() {
+ mScrollView = new ScrollView(getActivity());
+ ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT);
+ mScrollView.setLayoutParams(scrollParams);
+
+ mLogView = new LogView(getActivity());
+ ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams);
+ logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
+ mLogView.setLayoutParams(logParams);
+ mLogView.setClickable(true);
+ mLogView.setFocusable(true);
+ mLogView.setTypeface(Typeface.MONOSPACE);
+
+ // Want to set padding as 16 dips, setPadding takes pixels. Hooray math!
+ int paddingDips = 16;
+ double scale = getResources().getDisplayMetrics().density;
+ int paddingPixels = (int) ((paddingDips * (scale)) + .5);
+ mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels);
+ mLogView.setCompoundDrawablePadding(paddingPixels);
+
+ mLogView.setGravity(Gravity.BOTTOM);
+ mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium);
+
+ mScrollView.addView(mLogView);
+ return mScrollView;
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+
+ View result = inflateViews();
+
+ mLogView.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {}
+
+ @Override
+ public void afterTextChanged(Editable s) {
+ mScrollView.fullScroll(ScrollView.FOCUS_DOWN);
+ }
+ });
+ return result;
+ }
+
+ public LogView getLogView() {
+ return mLogView;
+ }
+}
\ No newline at end of file
diff --git a/samples/browseable/Notifications/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/Notifications/Application/src/com.example.android.common/logger/LogNode.java
new file mode 100644
index 0000000..bc37cab
--- /dev/null
+++ b/samples/browseable/Notifications/Application/src/com.example.android.common/logger/LogNode.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2012 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.common.logger;
+
+/**
+ * Basic interface for a logging system that can output to one or more targets.
+ * Note that in addition to classes that will output these logs in some format,
+ * one can also implement this interface over a filter and insert that in the chain,
+ * such that no targets further down see certain data, or see manipulated forms of the data.
+ * You could, for instance, write a "ToHtmlLoggerNode" that just converted all the log data
+ * it received to HTML and sent it along to the next node in the chain, without printing it
+ * anywhere.
+ */
+public interface LogNode {
+
+ /**
+ * Instructs first LogNode in the list to print the log data provided.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public void println(int priority, String tag, String msg, Throwable tr);
+
+}
diff --git a/samples/browseable/Notifications/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/Notifications/Application/src/com.example.android.common/logger/LogView.java
new file mode 100644
index 0000000..c01542b
--- /dev/null
+++ b/samples/browseable/Notifications/Application/src/com.example.android.common/logger/LogView.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+import android.app.Activity;
+import android.content.Context;
+import android.util.*;
+import android.widget.TextView;
+
+/** Simple TextView which is used to output log data received through the LogNode interface.
+*/
+public class LogView extends TextView implements LogNode {
+
+ public LogView(Context context) {
+ super(context);
+ }
+
+ public LogView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public LogView(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ /**
+ * Formats the log data and prints it out to the LogView.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+
+
+ String priorityStr = null;
+
+ // For the purposes of this View, we want to print the priority as readable text.
+ switch(priority) {
+ case android.util.Log.VERBOSE:
+ priorityStr = "VERBOSE";
+ break;
+ case android.util.Log.DEBUG:
+ priorityStr = "DEBUG";
+ break;
+ case android.util.Log.INFO:
+ priorityStr = "INFO";
+ break;
+ case android.util.Log.WARN:
+ priorityStr = "WARN";
+ break;
+ case android.util.Log.ERROR:
+ priorityStr = "ERROR";
+ break;
+ case android.util.Log.ASSERT:
+ priorityStr = "ASSERT";
+ break;
+ default:
+ break;
+ }
+
+ // Handily, the Log class has a facility for converting a stack trace into a usable string.
+ String exceptionStr = null;
+ if (tr != null) {
+ exceptionStr = android.util.Log.getStackTraceString(tr);
+ }
+
+ // Take the priority, tag, message, and exception, and concatenate as necessary
+ // into one usable line of text.
+ final StringBuilder outputBuilder = new StringBuilder();
+
+ String delimiter = "\t";
+ appendIfNotNull(outputBuilder, priorityStr, delimiter);
+ appendIfNotNull(outputBuilder, tag, delimiter);
+ appendIfNotNull(outputBuilder, msg, delimiter);
+ appendIfNotNull(outputBuilder, exceptionStr, delimiter);
+
+ // In case this was originally called from an AsyncTask or some other off-UI thread,
+ // make sure the update occurs within the UI thread.
+ ((Activity) getContext()).runOnUiThread( (new Thread(new Runnable() {
+ @Override
+ public void run() {
+ // Display the text we just generated within the LogView.
+ appendToLog(outputBuilder.toString());
+ }
+ })));
+
+ if (mNext != null) {
+ mNext.println(priority, tag, msg, tr);
+ }
+ }
+
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+ /** Takes a string and adds to it, with a separator, if the bit to be added isn't null. Since
+ * the logger takes so many arguments that might be null, this method helps cut out some of the
+ * agonizing tedium of writing the same 3 lines over and over.
+ * @param source StringBuilder containing the text to append to.
+ * @param addStr The String to append
+ * @param delimiter The String to separate the source and appended strings. A tab or comma,
+ * for instance.
+ * @return The fully concatenated String as a StringBuilder
+ */
+ private StringBuilder appendIfNotNull(StringBuilder source, String addStr, String delimiter) {
+ if (addStr != null) {
+ if (addStr.length() == 0) {
+ delimiter = "";
+ }
+
+ return source.append(addStr).append(delimiter);
+ }
+ return source;
+ }
+
+ // The next LogNode in the chain.
+ LogNode mNext;
+
+ /** Outputs the string as a new line of log data in the LogView. */
+ public void appendToLog(String s) {
+ append("\n" + s);
+ }
+
+
+}
diff --git a/samples/browseable/Notifications/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/Notifications/Application/src/com.example.android.common/logger/LogWrapper.java
new file mode 100644
index 0000000..16a9e7b
--- /dev/null
+++ b/samples/browseable/Notifications/Application/src/com.example.android.common/logger/LogWrapper.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2012 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.common.logger;
+
+import android.util.Log;
+
+/**
+ * Helper class which wraps Android's native Log utility in the Logger interface. This way
+ * normal DDMS output can be one of the many targets receiving and outputting logs simultaneously.
+ */
+public class LogWrapper implements LogNode {
+
+ // For piping: The next node to receive Log data after this one has done its work.
+ private LogNode mNext;
+
+ /**
+ * Returns the next LogNode in the linked list.
+ */
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to..
+ */
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+ /**
+ * Prints data out to the console using Android's native log mechanism.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+ // There actually are log methods that don't take a msg parameter. For now,
+ // if that's the case, just convert null to the empty string and move on.
+ String useMsg = msg;
+ if (useMsg == null) {
+ useMsg = "";
+ }
+
+ // If an exeption was provided, convert that exception to a usable string and attach
+ // it to the end of the msg method.
+ if (tr != null) {
+ msg += "\n" + Log.getStackTraceString(tr);
+ }
+
+ // This is functionally identical to Log.x(tag, useMsg);
+ // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg)
+ Log.println(priority, tag, useMsg);
+
+ // If this isn't the last node in the chain, move things along.
+ if (mNext != null) {
+ mNext.println(priority, tag, msg, tr);
+ }
+ }
+}
diff --git a/samples/browseable/Notifications/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/Notifications/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java
new file mode 100644
index 0000000..19967dc
--- /dev/null
+++ b/samples/browseable/Notifications/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+/**
+ * Simple {@link LogNode} filter, removes everything except the message.
+ * Useful for situations like on-screen log output where you don't want a lot of metadata displayed,
+ * just easy-to-read message updates as they're happening.
+ */
+public class MessageOnlyLogFilter implements LogNode {
+
+ LogNode mNext;
+
+ /**
+ * Takes the "next" LogNode as a parameter, to simplify chaining.
+ *
+ * @param next The next LogNode in the pipeline.
+ */
+ public MessageOnlyLogFilter(LogNode next) {
+ mNext = next;
+ }
+
+ public MessageOnlyLogFilter() {
+ }
+
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+ if (mNext != null) {
+ getNext().println(Log.NONE, null, msg, null);
+ }
+ }
+
+ /**
+ * Returns the next LogNode in the chain.
+ */
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to..
+ */
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+}
diff --git a/samples/browseable/Notifications/Application/src/com.example.android.notifications/ActionsPreset.java b/samples/browseable/Notifications/Application/src/com.example.android.notifications/ActionsPreset.java
new file mode 100644
index 0000000..32be1a6
--- /dev/null
+++ b/samples/browseable/Notifications/Application/src/com.example.android.notifications/ActionsPreset.java
@@ -0,0 +1,33 @@
+/*
+ * 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.notifications;
+
+import android.content.Context;
+import android.support.v4.app.NotificationCompat;
+
+/**
+ * Base class for notification actions presets.
+ */
+public abstract class ActionsPreset extends NamedPreset {
+ public ActionsPreset(int nameResId) {
+ super(nameResId);
+ }
+
+ /** Apply the priority to a notification builder */
+ public abstract void apply(Context context, NotificationCompat.Builder builder,
+ NotificationCompat.WearableExtender wearableOptions);
+}
diff --git a/samples/browseable/Notifications/Application/src/com.example.android.notifications/ActionsPresets.java b/samples/browseable/Notifications/Application/src/com.example.android.notifications/ActionsPresets.java
new file mode 100644
index 0000000..2481ac8
--- /dev/null
+++ b/samples/browseable/Notifications/Application/src/com.example.android.notifications/ActionsPresets.java
@@ -0,0 +1,158 @@
+/*
+ * 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.notifications;
+
+import android.content.Context;
+import android.support.v4.app.NotificationCompat;
+import android.support.v4.app.RemoteInput;
+
+/**
+ * Collection of notification actions presets.
+ */
+public class ActionsPresets {
+ public static final ActionsPreset NO_ACTIONS_PRESET = new NoActionsPreset();
+ public static final ActionsPreset SINGLE_ACTION_PRESET = new SingleActionPreset();
+
+ public static final ActionsPreset[] PRESETS = new ActionsPreset[] {
+ NO_ACTIONS_PRESET,
+ SINGLE_ACTION_PRESET,
+ new ReplyActionPreset(),
+ new ReplyWithChoicesActionPreset(),
+ new DifferentActionsOnPhoneAndWearable(),
+ new LongTitleActionPreset()
+ };
+
+ private static class NoActionsPreset extends ActionsPreset {
+ public NoActionsPreset() {
+ super(R.string.no_actions);
+ }
+
+ @Override
+ public void apply(Context context, NotificationCompat.Builder builder,
+ NotificationCompat.WearableExtender wearableOptions) {
+ }
+ }
+
+ private static class SingleActionPreset extends ActionsPreset {
+ public SingleActionPreset() {
+ super(R.string.single_action);
+ }
+
+ @Override
+ public void apply(Context context, NotificationCompat.Builder builder,
+ NotificationCompat.WearableExtender wearableOptions) {
+ builder.addAction(R.drawable.ic_full_action,
+ context.getString(R.string.example_action),
+ NotificationUtil.getExamplePendingIntent(context,
+ R.string.example_action_clicked))
+ .build();
+ }
+ }
+
+ private static class LongTitleActionPreset extends ActionsPreset {
+ public LongTitleActionPreset() {
+ super(R.string.long_title_action);
+ }
+
+ @Override
+ public void apply(Context context, NotificationCompat.Builder builder,
+ NotificationCompat.WearableExtender wearableOptions) {
+ builder.addAction(R.drawable.ic_full_action,
+ context.getString(R.string.example_action_long_title),
+ NotificationUtil.getExamplePendingIntent(context,
+ R.string.example_action_clicked))
+ .build();
+ }
+ }
+
+ private static class ReplyActionPreset extends ActionsPreset {
+ public ReplyActionPreset() {
+ super(R.string.reply_action);
+ }
+
+ @Override
+ public void apply(Context context, NotificationCompat.Builder builder,
+ NotificationCompat.WearableExtender wearableOptions) {
+ RemoteInput remoteInput = new RemoteInput.Builder(NotificationUtil.EXTRA_REPLY)
+ .setLabel(context.getString(R.string.example_reply_label))
+ .build();
+ NotificationCompat.Action action = new NotificationCompat.Action.Builder(
+ R.drawable.ic_full_reply,
+ context.getString(R.string.example_reply_action),
+ NotificationUtil.getExamplePendingIntent(context,
+ R.string.example_reply_action_clicked))
+ .addRemoteInput(remoteInput)
+ .build();
+ builder.addAction(action);
+ }
+ }
+
+ private static class ReplyWithChoicesActionPreset extends ActionsPreset {
+ public ReplyWithChoicesActionPreset() {
+ super(R.string.reply_action_with_choices);
+ }
+
+ @Override
+ public void apply(Context context, NotificationCompat.Builder builder,
+ NotificationCompat.WearableExtender wearableOptions) {
+ RemoteInput remoteInput = new RemoteInput.Builder(NotificationUtil.EXTRA_REPLY)
+ .setLabel(context.getString(R.string.example_reply_answer_label))
+ .setChoices(new String[] { context.getString(R.string.yes),
+ context.getString(R.string.no), context.getString(R.string.maybe) })
+ .build();
+ NotificationCompat.Action action = new NotificationCompat.Action.Builder(
+ R.drawable.ic_full_reply,
+ context.getString(R.string.example_reply_action),
+ NotificationUtil.getExamplePendingIntent(context,
+ R.string.example_reply_action_clicked))
+ .addRemoteInput(remoteInput)
+ .build();
+ wearableOptions.addAction(action);
+ }
+ }
+
+ private static class DifferentActionsOnPhoneAndWearable extends ActionsPreset {
+ public DifferentActionsOnPhoneAndWearable() {
+ super(R.string.different_actions_on_phone_and_wearable);
+ }
+
+ @Override
+ public void apply(Context context, NotificationCompat.Builder builder,
+ NotificationCompat.WearableExtender wearableOptions) {
+ NotificationCompat.Action phoneAction = new NotificationCompat.Action.Builder(
+ R.drawable.ic_full_action,
+ context.getString(R.string.phone_action),
+ NotificationUtil.getExamplePendingIntent(context,
+ R.string.phone_action_clicked))
+ .build();
+ builder.addAction(phoneAction);
+
+ RemoteInput remoteInput = new RemoteInput.Builder(NotificationUtil.EXTRA_REPLY)
+ .setLabel(context.getString(R.string.example_reply_label))
+ .build();
+
+ NotificationCompat.Action wearableAction = new NotificationCompat.Action.Builder(
+ R.drawable.ic_full_reply,
+ context.getString(R.string.wearable_action),
+ NotificationUtil.getExamplePendingIntent(context,
+ R.string.wearable_action_clicked))
+ .addRemoteInput(remoteInput)
+ .build();
+ wearableOptions.addAction(wearableAction);
+ }
+ }
+}
diff --git a/samples/browseable/Notifications/Application/src/com.example.android.notifications/BackgroundPickers.java b/samples/browseable/Notifications/Application/src/com.example.android.notifications/BackgroundPickers.java
new file mode 100644
index 0000000..69263b2
--- /dev/null
+++ b/samples/browseable/Notifications/Application/src/com.example.android.notifications/BackgroundPickers.java
@@ -0,0 +1,140 @@
+/*
+ * 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.notifications;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Manages the background image pickers.
+ */
+public class BackgroundPickers {
+
+ public interface OnBackgroundPickersChangedListener {
+ public void onBackgroundPickersChanged(BackgroundPickers pickers);
+ }
+
+ private final ViewGroup mContainer;
+ private final OnPickedListener mOnPickedListener;
+ private final List<ViewGroup> mPickers;
+ private final OnBackgroundPickersChangedListener listener;
+
+ public BackgroundPickers(ViewGroup container, OnBackgroundPickersChangedListener listener) {
+ this.mContainer = container;
+ this.mOnPickedListener = new OnPickedListener();
+ this.mPickers = new ArrayList<ViewGroup>();
+ this.listener = listener;
+ }
+
+ /**
+ * Generates the pickers as necessary.
+ */
+ public void generatePickers(int count) {
+ // Clear existing containers.
+ clear();
+
+ // Fill in new pickers.
+ LayoutInflater inflater = LayoutInflater.from(mContainer.getContext());
+ Resources res = mContainer.getResources();
+ for (int i = 0; i < count; i++) {
+ View picker = inflater.inflate(R.layout.background_picker, mContainer, false);
+ TextView label = (TextView) picker.findViewById(R.id.bg_picker_label);
+ label.setText(String.format(res.getString(R.string.bg_picker_label), i+1));
+ ViewGroup pickerBox = (ViewGroup) picker.findViewById(R.id.bg_picker_container);
+ mPickers.add(pickerBox);
+ for (int j = 0; j < pickerBox.getChildCount(); j++) {
+ ImageView img = (ImageView) pickerBox.getChildAt(j);
+ img.setOnClickListener(mOnPickedListener);
+ }
+ mContainer.addView(picker);
+ }
+ }
+
+ /**
+ * Returns the background resource for the picker at the given index.
+ * @param position Index of the background picker.
+ * @return Id of the background image resource. null if no image is picked.
+ */
+ public Integer getRes(int position) {
+ String tag = (String) mPickers.get(position).getTag();
+ if (tag == null) {
+ return null;
+ }
+
+ Context context = mContainer.getContext();
+ return context.getResources().getIdentifier(tag, "drawable", context.getPackageName());
+ }
+
+ /**
+ * Returns the all the background resources for the pickers managed by this object. Returns null
+ * if no pickers exist.
+ */
+ public Integer[] getRes() {
+ if (mPickers.size() == 0) {
+ return null;
+ }
+
+ Integer[] res = new Integer[mPickers.size()];
+ for (int i = 0; i < mPickers.size(); i++) {
+ res[i] = getRes(i);
+ }
+ return res;
+ }
+
+ /**
+ * Clears the pickers.
+ */
+ public void clear() {
+ mContainer.removeAllViews();
+ mPickers.clear();
+ }
+
+ public int getCount() {
+ return mPickers.size();
+ }
+
+ private class OnPickedListener implements View.OnClickListener {
+
+ @Override
+ public void onClick(View view) {
+ ImageView pickedView = (ImageView) view;
+ ViewGroup pickerBox = (ViewGroup) view.getParent();
+
+ // Clear old selection.
+ for (int i = 0; i < pickerBox.getChildCount(); i++) {
+ ImageView childView = (ImageView) pickerBox.getChildAt(i);
+ childView.setBackgroundResource(R.drawable.unselected_background);
+ }
+
+ // Set new selection.
+ pickedView.setBackgroundResource(R.drawable.selected_background);
+ pickerBox.setTag(pickedView.getTag());
+
+ if (listener != null) {
+ listener.onBackgroundPickersChanged(BackgroundPickers.this);
+ }
+ }
+ }
+}
diff --git a/samples/browseable/Notifications/Application/src/com.example.android.notifications/MainActivity.java b/samples/browseable/Notifications/Application/src/com.example.android.notifications/MainActivity.java
new file mode 100644
index 0000000..22b1059
--- /dev/null
+++ b/samples/browseable/Notifications/Application/src/com.example.android.notifications/MainActivity.java
@@ -0,0 +1,352 @@
+/*
+ * 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.notifications;
+
+import android.app.Activity;
+import android.app.Notification;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.support.v4.app.NotificationManagerCompat;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.CheckBox;
+import android.widget.CompoundButton;
+import android.widget.EditText;
+import android.widget.Spinner;
+import android.widget.TextView;
+
+import java.util.Arrays;
+
+/**
+ * Main activity which posts a notification when resumed, and allows customization
+ * of that notification via controls.
+ */
+public class MainActivity extends Activity implements Handler.Callback {
+ private static final int MSG_POST_NOTIFICATIONS = 0;
+ private static final long POST_NOTIFICATIONS_DELAY_MS = 200;
+
+ private Handler mHandler;
+ private Spinner mPresetSpinner;
+ private EditText mTitleEditText;
+ private EditText mTextEditText;
+ private TextWatcher mTextChangedListener;
+ private Spinner mPrioritySpinner;
+ private Spinner mActionsSpinner;
+ private CheckBox mIncludeLargeIconCheckbox;
+ private CheckBox mLocalOnlyCheckbox;
+ private CheckBox mIncludeContentIntentCheckbox;
+ private CheckBox mVibrateCheckbox;
+ private BackgroundPickers mBackgroundPickers;
+ private int postedNotificationCount = 0;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.main);
+
+ mHandler = new Handler(this);
+ mTextChangedListener = new UpdateNotificationsOnTextChangeListener();
+
+ initPresetSpinner();
+ initTitleEditText();
+ initTextEditText();
+ initPrioritySpinner();
+ initActionsSpinner();
+ initIncludeLargeIconCheckbox();
+ initLocalOnlyCheckbox();
+ initIncludeContentIntentCheckbox();
+ initVibrateCheckbox();
+ initBackgroundPickers();
+
+ NotificationPreset preset = NotificationPresets.PRESETS[
+ mPresetSpinner.getSelectedItemPosition()];
+ updateTextEditors(preset);
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ updateNotifications(false /* cancelExisting */);
+ }
+
+ private void initPresetSpinner() {
+ mPresetSpinner = (Spinner) findViewById(R.id.preset_spinner);
+ mPresetSpinner.setAdapter(new NamedPresetSpinnerArrayAdapter(this,
+ NotificationPresets.PRESETS));
+ mPresetSpinner.post(new Runnable() {
+ @Override
+ public void run() {
+ mPresetSpinner.setOnItemSelectedListener(new PresetSpinnerListener());
+ }
+ });
+ }
+
+ private void initTitleEditText() {
+ mTitleEditText = (EditText) findViewById(R.id.title_editor);
+ }
+
+ private void initTextEditText() {
+ mTextEditText = (EditText) findViewById(R.id.text_editor);
+ }
+
+ private void initPrioritySpinner() {
+ mPrioritySpinner = (Spinner) findViewById(R.id.priority_spinner);
+ mPrioritySpinner.setAdapter(new NamedPresetSpinnerArrayAdapter(this,
+ PriorityPresets.PRESETS));
+ mPrioritySpinner.setSelection(Arrays.asList(PriorityPresets.PRESETS)
+ .indexOf(PriorityPresets.DEFAULT));
+ mPrioritySpinner.post(new Runnable() {
+ @Override
+ public void run() {
+ mPrioritySpinner.setOnItemSelectedListener(
+ new UpdateNotificationsOnItemSelectedListener(true /* cancelExisting */));
+ }
+ });
+ }
+
+ private void initActionsSpinner() {
+ mActionsSpinner = (Spinner) findViewById(R.id.actions_spinner);
+ mActionsSpinner.setAdapter(new NamedPresetSpinnerArrayAdapter(this,
+ ActionsPresets.PRESETS));
+ mActionsSpinner.post(new Runnable() {
+ @Override
+ public void run() {
+ mActionsSpinner.setOnItemSelectedListener(
+ new UpdateNotificationsOnItemSelectedListener(false /* cancelExisting */));
+ }
+ });
+ }
+
+ private void initIncludeLargeIconCheckbox() {
+ mIncludeLargeIconCheckbox = (CheckBox) findViewById(R.id.include_large_icon_checkbox);
+ mIncludeLargeIconCheckbox.setOnCheckedChangeListener(
+ new UpdateNotificationsOnCheckedChangeListener(false /* cancelExisting */));
+ }
+
+ private void initLocalOnlyCheckbox() {
+ mLocalOnlyCheckbox = (CheckBox) findViewById(R.id.local_only_checkbox);
+ mLocalOnlyCheckbox.setOnCheckedChangeListener(
+ new UpdateNotificationsOnCheckedChangeListener(false /* cancelExisting */));
+ }
+
+ private void initIncludeContentIntentCheckbox() {
+ mIncludeContentIntentCheckbox = (CheckBox) findViewById(
+ R.id.include_content_intent_checkbox);
+ mIncludeContentIntentCheckbox.setOnCheckedChangeListener(
+ new UpdateNotificationsOnCheckedChangeListener(false /* cancelExisting */));
+ }
+
+ private void initVibrateCheckbox() {
+ mVibrateCheckbox = (CheckBox) findViewById(R.id.vibrate_checkbox);
+ mVibrateCheckbox.setOnCheckedChangeListener(
+ new UpdateNotificationsOnCheckedChangeListener(false /* cancelExisting */));
+ }
+
+ private void initBackgroundPickers() {
+ mBackgroundPickers = new BackgroundPickers(
+ (ViewGroup) findViewById(R.id.background_pickers),
+ new BackgroundPickerListener());
+ }
+
+ private void updateTextEditors(NotificationPreset preset) {
+ if (preset == NotificationPresets.BASIC) {
+ findViewById(R.id.title_edit_field).setVisibility(View.VISIBLE);
+ mTitleEditText.setText(getString(preset.titleResId));
+ mTitleEditText.addTextChangedListener(mTextChangedListener);
+ findViewById(R.id.text_edit_field).setVisibility(View.VISIBLE);
+ mTextEditText.setText(getString(preset.textResId));
+ mTextEditText.addTextChangedListener(mTextChangedListener);
+ } else {
+ findViewById(R.id.title_edit_field).setVisibility(View.GONE);
+ mTitleEditText.removeTextChangedListener(mTextChangedListener);
+ findViewById(R.id.text_edit_field).setVisibility(View.GONE);
+ mTextEditText.removeTextChangedListener(mTextChangedListener);
+ }
+ }
+
+ /**
+ * Begin to re-post the sample notification(s).
+ */
+ private void updateNotifications(boolean cancelExisting) {
+ // Disable messages to skip notification deleted messages during cancel.
+ sendBroadcast(new Intent(NotificationIntentReceiver.ACTION_DISABLE_MESSAGES)
+ .setClass(this, NotificationIntentReceiver.class));
+
+ if (cancelExisting) {
+ // Cancel all existing notifications to trigger fresh-posting behavior: For example,
+ // switching from HIGH to LOW priority does not cause a reordering in Notification Shade.
+ NotificationManagerCompat.from(this).cancelAll();
+ postedNotificationCount = 0;
+
+ // Post the updated notifications on a delay to avoid a cancel+post race condition
+ // with notification manager.
+ mHandler.removeMessages(MSG_POST_NOTIFICATIONS);
+ mHandler.sendEmptyMessageDelayed(MSG_POST_NOTIFICATIONS, POST_NOTIFICATIONS_DELAY_MS);
+ } else {
+ postNotifications();
+ }
+ }
+
+ /**
+ * Post the sample notification(s) using current options.
+ */
+ private void postNotifications() {
+ sendBroadcast(new Intent(NotificationIntentReceiver.ACTION_ENABLE_MESSAGES)
+ .setClass(this, NotificationIntentReceiver.class));
+
+ NotificationPreset preset = NotificationPresets.PRESETS[
+ mPresetSpinner.getSelectedItemPosition()];
+ CharSequence titlePreset = mTitleEditText.getText();
+ CharSequence textPreset = mTextEditText.getText();
+ PriorityPreset priorityPreset = PriorityPresets.PRESETS[
+ mPrioritySpinner.getSelectedItemPosition()];
+ ActionsPreset actionsPreset = ActionsPresets.PRESETS[
+ mActionsSpinner.getSelectedItemPosition()];
+ if (preset.actionsRequired() && actionsPreset == ActionsPresets.NO_ACTIONS_PRESET) {
+ // If actions are required, but the no-actions preset was selected, change presets.
+ actionsPreset = ActionsPresets.SINGLE_ACTION_PRESET;
+ mActionsSpinner.setSelection(Arrays.asList(ActionsPresets.PRESETS).indexOf(
+ actionsPreset), true);
+ }
+ NotificationPreset.BuildOptions options = new NotificationPreset.BuildOptions(
+ titlePreset,
+ textPreset,
+ priorityPreset,
+ actionsPreset,
+ mIncludeLargeIconCheckbox.isChecked(),
+ mLocalOnlyCheckbox.isChecked(),
+ mIncludeContentIntentCheckbox.isChecked(),
+ mVibrateCheckbox.isChecked(),
+ mBackgroundPickers.getRes());
+ Notification[] notifications = preset.buildNotifications(this, options);
+
+ // Post new notifications
+ for (int i = 0; i < notifications.length; i++) {
+ NotificationManagerCompat.from(this).notify(i, notifications[i]);
+ }
+ // Cancel any that are beyond the current count.
+ for (int i = notifications.length; i < postedNotificationCount; i++) {
+ NotificationManagerCompat.from(this).cancel(i);
+ }
+ postedNotificationCount = notifications.length;
+ }
+
+ @Override
+ public boolean handleMessage(Message message) {
+ switch (message.what) {
+ case MSG_POST_NOTIFICATIONS:
+ postNotifications();
+ return true;
+ }
+ return false;
+ }
+
+ private class PresetSpinnerListener implements AdapterView.OnItemSelectedListener {
+ @Override
+ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
+ NotificationPreset preset = NotificationPresets.PRESETS[position];
+ mBackgroundPickers.generatePickers(preset.countBackgroundPickersRequired());
+ updateTextEditors(preset);
+ updateNotifications(false /* cancelExisting */);
+ }
+
+ @Override
+ public void onNothingSelected(AdapterView<?> adapterView) {
+ }
+ }
+
+ private class UpdateNotificationsOnTextChangeListener implements TextWatcher {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+ }
+
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
+ }
+
+ @Override
+ public void afterTextChanged(Editable s) {
+ updateNotifications(false /* cancelExisting */);
+ }
+ }
+
+ private class UpdateNotificationsOnItemSelectedListener
+ implements AdapterView.OnItemSelectedListener {
+ private final boolean mCancelExisting;
+
+ public UpdateNotificationsOnItemSelectedListener(boolean cancelExisting) {
+ mCancelExisting = cancelExisting;
+ }
+ @Override
+ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
+ updateNotifications(mCancelExisting);
+ }
+
+ @Override
+ public void onNothingSelected(AdapterView<?> adapterView) {
+ }
+ }
+
+ private class UpdateNotificationsOnCheckedChangeListener
+ implements CompoundButton.OnCheckedChangeListener {
+ private final boolean mCancelExisting;
+
+ public UpdateNotificationsOnCheckedChangeListener(boolean cancelExisting) {
+ mCancelExisting = cancelExisting;
+ }
+
+ @Override
+ public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
+ updateNotifications(mCancelExisting);
+ }
+ }
+
+ private class BackgroundPickerListener
+ implements BackgroundPickers.OnBackgroundPickersChangedListener {
+ @Override
+ public void onBackgroundPickersChanged(BackgroundPickers pickers) {
+ updateNotifications(false /* cancelExisting */);
+ }
+ }
+
+ private class NamedPresetSpinnerArrayAdapter extends ArrayAdapter<NamedPreset> {
+ public NamedPresetSpinnerArrayAdapter(Context context, NamedPreset[] presets) {
+ super(context, R.layout.simple_spinner_item, presets);
+ }
+
+ @Override
+ public View getDropDownView(int position, View convertView, ViewGroup parent) {
+ TextView view = (TextView) super.getDropDownView(position, convertView, parent);
+ view.setText(getString(getItem(position).nameResId));
+ return view;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ TextView view = (TextView) getLayoutInflater().inflate(
+ android.R.layout.simple_spinner_item, parent, false);
+ view.setText(getString(getItem(position).nameResId));
+ return view;
+ }
+ }
+}
diff --git a/samples/browseable/Notifications/Application/src/com.example.android.notifications/NamedPreset.java b/samples/browseable/Notifications/Application/src/com.example.android.notifications/NamedPreset.java
new file mode 100644
index 0000000..b97bcb9
--- /dev/null
+++ b/samples/browseable/Notifications/Application/src/com.example.android.notifications/NamedPreset.java
@@ -0,0 +1,28 @@
+/*
+ * 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.notifications;
+
+/**
+ * Base class for presets that have a simple name to display.
+ */
+public abstract class NamedPreset {
+ public final int nameResId;
+
+ public NamedPreset(int nameResId) {
+ this.nameResId = nameResId;
+ }
+}
diff --git a/samples/browseable/Notifications/Application/src/com.example.android.notifications/NotificationIntentReceiver.java b/samples/browseable/Notifications/Application/src/com.example.android.notifications/NotificationIntentReceiver.java
new file mode 100644
index 0000000..8dabb34
--- /dev/null
+++ b/samples/browseable/Notifications/Application/src/com.example.android.notifications/NotificationIntentReceiver.java
@@ -0,0 +1,60 @@
+/*
+ * 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.notifications;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.support.v4.app.RemoteInput;
+import android.widget.Toast;
+
+/**
+ * Broadcast receiver to post toast messages in response to notification intents firing.
+ */
+public class NotificationIntentReceiver extends BroadcastReceiver {
+ public static final String ACTION_EXAMPLE =
+ "com.example.android.notifications.ACTION_EXAMPLE";
+ public static final String ACTION_ENABLE_MESSAGES =
+ "com.example.android.notifications.ACTION_ENABLE_MESSAGES";
+ public static final String ACTION_DISABLE_MESSAGES =
+ "com.example.android.notifications.ACTION_DISABLE_MESSAGES";
+
+ private boolean mEnableMessages = true;
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (intent.getAction().equals(ACTION_EXAMPLE)) {
+ if (mEnableMessages) {
+ String message = intent.getStringExtra(NotificationUtil.EXTRA_MESSAGE);
+ Bundle remoteInputResults = RemoteInput.getResultsFromIntent(intent);
+ CharSequence replyMessage = null;
+ if (remoteInputResults != null) {
+ replyMessage = remoteInputResults.getCharSequence(NotificationUtil.EXTRA_REPLY);
+ }
+ if (replyMessage != null) {
+ message = message + ": \"" + replyMessage + "\"";
+ }
+ Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
+ }
+ } else if (intent.getAction().equals(ACTION_ENABLE_MESSAGES)) {
+ mEnableMessages = true;
+ } else if (intent.getAction().equals(ACTION_DISABLE_MESSAGES)) {
+ mEnableMessages = false;
+ }
+ }
+}
diff --git a/samples/browseable/Notifications/Application/src/com.example.android.notifications/NotificationPreset.java b/samples/browseable/Notifications/Application/src/com.example.android.notifications/NotificationPreset.java
new file mode 100644
index 0000000..3ab792b
--- /dev/null
+++ b/samples/browseable/Notifications/Application/src/com.example.android.notifications/NotificationPreset.java
@@ -0,0 +1,74 @@
+/*
+ * 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.notifications;
+
+import android.app.Notification;
+import android.content.Context;
+
+/**
+ * Base class for notification preset generators.
+ */
+public abstract class NotificationPreset extends NamedPreset {
+ public final int titleResId;
+ public final int textResId;
+
+ public NotificationPreset(int nameResId, int titleResId, int textResId) {
+ super(nameResId);
+ this.titleResId = titleResId;
+ this.textResId = textResId;
+ }
+
+ public static class BuildOptions {
+ public final CharSequence titlePreset;
+ public final CharSequence textPreset;
+ public final PriorityPreset priorityPreset;
+ public final ActionsPreset actionsPreset;
+ public final boolean includeLargeIcon;
+ public final boolean isLocalOnly;
+ public final boolean hasContentIntent;
+ public final boolean vibrate;
+ public final Integer[] backgroundIds;
+
+ public BuildOptions(CharSequence titlePreset, CharSequence textPreset,
+ PriorityPreset priorityPreset, ActionsPreset actionsPreset,
+ boolean includeLargeIcon, boolean isLocalOnly, boolean hasContentIntent,
+ boolean vibrate, Integer[] backgroundIds) {
+ this.titlePreset = titlePreset;
+ this.textPreset = textPreset;
+ this.priorityPreset = priorityPreset;
+ this.actionsPreset = actionsPreset;
+ this.includeLargeIcon = includeLargeIcon;
+ this.isLocalOnly = isLocalOnly;
+ this.hasContentIntent = hasContentIntent;
+ this.vibrate = vibrate;
+ this.backgroundIds = backgroundIds;
+ }
+ }
+
+ /** Build a notification with this preset and the provided options */
+ public abstract Notification[] buildNotifications(Context context, BuildOptions options);
+
+ /** Whether actions are required to use this preset. */
+ public boolean actionsRequired() {
+ return false;
+ }
+
+ /** Number of background pickers required */
+ public int countBackgroundPickersRequired() {
+ return 0;
+ }
+}
diff --git a/samples/browseable/Notifications/Application/src/com.example.android.notifications/NotificationPresets.java b/samples/browseable/Notifications/Application/src/com.example.android.notifications/NotificationPresets.java
new file mode 100644
index 0000000..b6fe24a
--- /dev/null
+++ b/samples/browseable/Notifications/Application/src/com.example.android.notifications/NotificationPresets.java
@@ -0,0 +1,479 @@
+/*
+ * 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.notifications;
+
+import android.app.Notification;
+import android.content.Context;
+import android.graphics.BitmapFactory;
+import android.graphics.Color;
+import android.graphics.Typeface;
+import android.support.v4.app.NotificationCompat;
+import android.text.SpannableStringBuilder;
+import android.text.style.ForegroundColorSpan;
+import android.text.style.RelativeSizeSpan;
+import android.text.style.StrikethroughSpan;
+import android.text.style.StyleSpan;
+import android.text.style.SubscriptSpan;
+import android.text.style.SuperscriptSpan;
+import android.text.style.TypefaceSpan;
+import android.text.style.UnderlineSpan;
+import android.view.Gravity;
+
+/**
+ * Collection of notification builder presets.
+ */
+public class NotificationPresets {
+ private static final String EXAMPLE_GROUP_KEY = "example";
+
+ public static final NotificationPreset BASIC = new BasicNotificationPreset();
+ public static final NotificationPreset STYLIZED_TEXT = new StylizedTextNotificationPreset();
+ public static final NotificationPreset INBOX = new InboxNotificationPreset();
+ public static final NotificationPreset BIG_PICTURE = new BigPictureNotificationPreset();
+ public static final NotificationPreset BIG_TEXT = new BigTextNotificationPreset();
+ public static final NotificationPreset BOTTOM_ALIGNED = new BottomAlignedNotificationPreset();
+ public static final NotificationPreset GRAVITY = new GravityNotificationPreset();
+ public static final NotificationPreset CONTENT_ACTION = new ContentActionNotificationPreset();
+ public static final NotificationPreset CONTENT_ICON = new ContentIconNotificationPreset();
+ public static final NotificationPreset MULTIPLE_PAGE = new MultiplePageNotificationPreset();
+ public static final NotificationPreset BUNDLE = new NotificationBundlePreset();
+
+ public static final NotificationPreset[] PRESETS = new NotificationPreset[] {
+ BASIC,
+ STYLIZED_TEXT,
+ INBOX,
+ BIG_PICTURE,
+ BIG_TEXT,
+ BOTTOM_ALIGNED,
+ GRAVITY,
+ CONTENT_ACTION,
+ CONTENT_ICON,
+ MULTIPLE_PAGE,
+ BUNDLE
+ };
+
+ private static NotificationCompat.Builder applyBasicOptions(Context context,
+ NotificationCompat.Builder builder, NotificationCompat.WearableExtender wearableOptions,
+ NotificationPreset.BuildOptions options) {
+ builder.setContentTitle(options.titlePreset)
+ .setContentText(options.textPreset)
+ .setSmallIcon(R.mipmap.ic_launcher)
+ .setDeleteIntent(NotificationUtil.getExamplePendingIntent(
+ context, R.string.example_notification_deleted));
+ options.actionsPreset.apply(context, builder, wearableOptions);
+ options.priorityPreset.apply(builder, wearableOptions);
+ if (options.includeLargeIcon) {
+ builder.setLargeIcon(BitmapFactory.decodeResource(
+ context.getResources(), R.drawable.example_large_icon));
+ }
+ if (options.isLocalOnly) {
+ builder.setLocalOnly(true);
+ }
+ if (options.hasContentIntent) {
+ builder.setContentIntent(NotificationUtil.getExamplePendingIntent(context,
+ R.string.content_intent_clicked));
+ }
+ if (options.vibrate) {
+ builder.setVibrate(new long[] {0, 100, 50, 100} );
+ }
+ return builder;
+ }
+
+ private static class BasicNotificationPreset extends NotificationPreset {
+ public BasicNotificationPreset() {
+ super(R.string.basic_example, R.string.example_content_title,
+ R.string.example_content_text);
+ }
+
+ @Override
+ public Notification[] buildNotifications(Context context, BuildOptions options) {
+ NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
+ NotificationCompat.WearableExtender wearableOptions =
+ new NotificationCompat.WearableExtender();
+ applyBasicOptions(context, builder, wearableOptions, options);
+ builder.extend(wearableOptions);
+ return new Notification[] { builder.build() };
+ }
+ }
+
+ private static class StylizedTextNotificationPreset extends NotificationPreset {
+ public StylizedTextNotificationPreset() {
+ super(R.string.stylized_text_example, R.string.example_content_title,
+ R.string.example_content_text);
+ }
+
+ @Override
+ public Notification[] buildNotifications(Context context, BuildOptions options) {
+ NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle();
+
+ SpannableStringBuilder title = new SpannableStringBuilder();
+ appendStyled(title, "Stylized", new StyleSpan(Typeface.BOLD_ITALIC));
+ title.append(" title");
+ SpannableStringBuilder text = new SpannableStringBuilder("Stylized text: ");
+ appendStyled(text, "C", new ForegroundColorSpan(Color.RED));
+ appendStyled(text, "O", new ForegroundColorSpan(Color.GREEN));
+ appendStyled(text, "L", new ForegroundColorSpan(Color.BLUE));
+ appendStyled(text, "O", new ForegroundColorSpan(Color.YELLOW));
+ appendStyled(text, "R", new ForegroundColorSpan(Color.MAGENTA));
+ appendStyled(text, "S", new ForegroundColorSpan(Color.CYAN));
+ text.append("; ");
+ appendStyled(text, "1.25x size", new RelativeSizeSpan(1.25f));
+ text.append("; ");
+ appendStyled(text, "0.75x size", new RelativeSizeSpan(0.75f));
+ text.append("; ");
+ appendStyled(text, "underline", new UnderlineSpan());
+ text.append("; ");
+ appendStyled(text, "strikethrough", new StrikethroughSpan());
+ text.append("; ");
+ appendStyled(text, "bold", new StyleSpan(Typeface.BOLD));
+ text.append("; ");
+ appendStyled(text, "italic", new StyleSpan(Typeface.ITALIC));
+ text.append("; ");
+ appendStyled(text, "sans-serif-thin", new TypefaceSpan("sans-serif-thin"));
+ text.append("; ");
+ appendStyled(text, "monospace", new TypefaceSpan("monospace"));
+ text.append("; ");
+ appendStyled(text, "sub", new SubscriptSpan());
+ text.append("script");
+ appendStyled(text, "super", new SuperscriptSpan());
+
+ style.setBigContentTitle(title);
+ style.bigText(text);
+
+ NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
+ .setStyle(style);
+ NotificationCompat.WearableExtender wearableOptions =
+ new NotificationCompat.WearableExtender();
+ applyBasicOptions(context, builder, wearableOptions, options);
+ builder.extend(wearableOptions);
+ return new Notification[] { builder.build() };
+ }
+
+ private void appendStyled(SpannableStringBuilder builder, String str, Object... spans) {
+ builder.append(str);
+ for (Object span : spans) {
+ builder.setSpan(span, builder.length() - str.length(), builder.length(), 0);
+ }
+ }
+ }
+
+ private static class InboxNotificationPreset extends NotificationPreset {
+ public InboxNotificationPreset() {
+ super(R.string.inbox_example, R.string.example_content_title,
+ R.string.example_content_text);
+ }
+
+ @Override
+ public Notification[] buildNotifications(Context context, BuildOptions options) {
+ NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
+ style.addLine(context.getString(R.string.inbox_style_example_line1));
+ style.addLine(context.getString(R.string.inbox_style_example_line2));
+ style.addLine(context.getString(R.string.inbox_style_example_line3));
+ style.setBigContentTitle(context.getString(R.string.inbox_style_example_title));
+ style.setSummaryText(context.getString(R.string.inbox_style_example_summary_text));
+
+ NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
+ .setStyle(style);
+ NotificationCompat.WearableExtender wearableOptions =
+ new NotificationCompat.WearableExtender();
+ applyBasicOptions(context, builder, wearableOptions, options);
+ builder.extend(wearableOptions);
+ return new Notification[] { builder.build() };
+ }
+ }
+
+ private static class BigPictureNotificationPreset extends NotificationPreset {
+ public BigPictureNotificationPreset() {
+ super(R.string.big_picture_example, R.string.example_content_title,
+ R.string.example_content_text);
+ }
+
+ @Override
+ public Notification[] buildNotifications(Context context, BuildOptions options) {
+ NotificationCompat.BigPictureStyle style = new NotificationCompat.BigPictureStyle();
+ style.bigPicture(BitmapFactory.decodeResource(context.getResources(),
+ R.drawable.example_big_picture));
+ style.setBigContentTitle(context.getString(R.string.big_picture_style_example_title));
+ style.setSummaryText(context.getString(
+ R.string.big_picture_style_example_summary_text));
+
+ NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
+ .setStyle(style);
+ NotificationCompat.WearableExtender wearableOptions =
+ new NotificationCompat.WearableExtender();
+ applyBasicOptions(context, builder, wearableOptions, options);
+ builder.extend(wearableOptions);
+ return new Notification[] { builder.build() };
+ }
+ }
+
+ private static class BigTextNotificationPreset extends NotificationPreset {
+ public BigTextNotificationPreset() {
+ super(R.string.big_text_example, R.string.example_content_title,
+ R.string.example_content_text);
+ }
+
+ @Override
+ public Notification[] buildNotifications(Context context, BuildOptions options) {
+ NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle();
+ style.bigText(context.getString(R.string.big_text_example_big_text));
+ style.setBigContentTitle(context.getString(R.string.big_text_example_title));
+ style.setSummaryText(context.getString(R.string.big_text_example_summary_text));
+
+ NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
+ .setStyle(style);
+ NotificationCompat.WearableExtender wearableOptions =
+ new NotificationCompat.WearableExtender();
+ applyBasicOptions(context, builder, wearableOptions, options);
+ builder.extend(wearableOptions);
+ return new Notification[] { builder.build() };
+ }
+ }
+
+ private static class BottomAlignedNotificationPreset extends NotificationPreset {
+ public BottomAlignedNotificationPreset() {
+ super(R.string.bottom_aligned_example, R.string.example_content_title,
+ R.string.example_content_text);
+ }
+
+ @Override
+ public Notification[] buildNotifications(Context context, BuildOptions options) {
+ NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
+ NotificationCompat.WearableExtender wearableOptions =
+ new NotificationCompat.WearableExtender();
+ applyBasicOptions(context, builder, wearableOptions, options);
+
+ NotificationCompat.Builder secondPageBuilder = new NotificationCompat.Builder(context);
+ secondPageBuilder.setContentTitle(
+ context.getString(R.string.second_page_content_title));
+ secondPageBuilder.setContentText(context.getString(R.string.big_text_example_big_text));
+ secondPageBuilder.extend(new NotificationCompat.WearableExtender()
+ .setStartScrollBottom(true));
+
+ wearableOptions.addPage(secondPageBuilder.build());
+ builder.extend(wearableOptions);
+ return new Notification[] { builder.build() };
+ }
+ }
+
+ private static class GravityNotificationPreset extends NotificationPreset {
+ public GravityNotificationPreset() {
+ super(R.string.gravity_example, R.string.example_content_title,
+ R.string.example_content_text);
+ }
+
+ @Override
+ public Notification[] buildNotifications(Context context, BuildOptions options) {
+ NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
+ NotificationCompat.WearableExtender wearableOptions =
+ new NotificationCompat.WearableExtender();
+ applyBasicOptions(context, builder, wearableOptions, options);
+
+ NotificationCompat.Builder secondPageBuilder = new NotificationCompat.Builder(context)
+ .setContentTitle(options.titlePreset)
+ .setContentText(options.textPreset)
+ .extend(new NotificationCompat.WearableExtender()
+ .setGravity(Gravity.CENTER_VERTICAL));
+ wearableOptions.addPage(secondPageBuilder.build());
+
+ NotificationCompat.Builder thirdPageBuilder = new NotificationCompat.Builder(context)
+ .setContentTitle(options.titlePreset)
+ .setContentText(options.textPreset)
+ .extend(new NotificationCompat.WearableExtender()
+ .setGravity(Gravity.TOP));
+ wearableOptions.addPage(thirdPageBuilder.build());
+
+ wearableOptions.setGravity(Gravity.BOTTOM);
+ builder.extend(wearableOptions);
+ return new Notification[] { builder.build() };
+ }
+ }
+
+ private static class ContentActionNotificationPreset extends NotificationPreset {
+ public ContentActionNotificationPreset() {
+ super(R.string.content_action_example, R.string.example_content_title,
+ R.string.example_content_text);
+ }
+
+ @Override
+ public Notification[] buildNotifications(Context context, BuildOptions options) {
+ Notification secondPage = new NotificationCompat.Builder(context)
+ .setContentTitle(context.getString(R.string.second_page_content_title))
+ .setContentText(context.getString(R.string.second_page_content_text))
+ .extend(new NotificationCompat.WearableExtender()
+ .setContentAction(1))
+ .build();
+
+ NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
+ NotificationCompat.Action action = new NotificationCompat.Action.Builder(
+ R.drawable.ic_result_open, null, NotificationUtil.getExamplePendingIntent(
+ context, R.string.example_content_action_clicked)).build();
+ NotificationCompat.Action action2 = new NotificationCompat.Action.Builder(
+ R.drawable.ic_result_open, null, NotificationUtil.getExamplePendingIntent(
+ context, R.string.example_content_action2_clicked)).build();
+ NotificationCompat.WearableExtender wearableOptions =
+ new NotificationCompat.WearableExtender()
+ .addAction(action)
+ .addAction(action2)
+ .addPage(secondPage)
+ .setContentAction(0)
+ .setHintHideIcon(true);
+ applyBasicOptions(context, builder, wearableOptions, options);
+ builder.extend(wearableOptions);
+ return new Notification[] { builder.build() };
+ }
+
+ @Override
+ public boolean actionsRequired() {
+ return true;
+ }
+ }
+
+ private static class ContentIconNotificationPreset extends NotificationPreset {
+ public ContentIconNotificationPreset() {
+ super(R.string.content_icon_example, R.string.example_content_title,
+ R.string.example_content_text);
+ }
+
+ @Override
+ public Notification[] buildNotifications(Context context, BuildOptions options) {
+ Notification secondPage = new NotificationCompat.Builder(context)
+ .setContentTitle(context.getString(R.string.second_page_content_title))
+ .setContentText(context.getString(R.string.second_page_content_text))
+ .extend(new NotificationCompat.WearableExtender()
+ .setContentIcon(R.drawable.content_icon_small)
+ .setContentIconGravity(Gravity.START))
+ .build();
+
+ Notification thirdPage = new NotificationCompat.Builder(context)
+ .setContentTitle(context.getString(R.string.third_page_content_title))
+ .setContentText(context.getString(R.string.third_page_content_text))
+ .extend(new NotificationCompat.WearableExtender()
+ .setContentIcon(R.drawable.content_icon_large))
+ .build();
+
+ Notification fourthPage = new NotificationCompat.Builder(context)
+ .setContentTitle(context.getString(R.string.fourth_page_content_title))
+ .setContentText(context.getString(R.string.fourth_page_content_text))
+ .extend(new NotificationCompat.WearableExtender()
+ .setContentIcon(R.drawable.content_icon_large)
+ .setContentIconGravity(Gravity.START))
+ .build();
+
+ NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
+ NotificationCompat.WearableExtender wearableOptions =
+ new NotificationCompat.WearableExtender()
+ .setHintHideIcon(true)
+ .setContentIcon(R.drawable.content_icon_small)
+ .addPage(secondPage)
+ .addPage(thirdPage)
+ .addPage(fourthPage);
+ applyBasicOptions(context, builder, wearableOptions, options);
+ builder.extend(wearableOptions);
+ return new Notification[] { builder.build() };
+ }
+ }
+
+ private static class MultiplePageNotificationPreset extends NotificationPreset {
+ public MultiplePageNotificationPreset() {
+ super(R.string.multiple_page_example, R.string.example_content_title,
+ R.string.example_content_text);
+ }
+
+ @Override
+ public Notification[] buildNotifications(Context context, BuildOptions options) {
+ NotificationCompat.Builder secondPageBuilder = new NotificationCompat.Builder(context)
+ .setContentTitle(context.getString(R.string.second_page_content_title))
+ .setContentText(context.getString(R.string.second_page_content_text));
+
+ NotificationCompat.Builder firstPageBuilder = new NotificationCompat.Builder(context);
+ NotificationCompat.WearableExtender firstPageWearableOptions =
+ new NotificationCompat.WearableExtender();
+ applyBasicOptions(context, firstPageBuilder, firstPageWearableOptions, options);
+
+ Integer firstBackground = options.backgroundIds == null
+ ? null : options.backgroundIds[0];
+ if (firstBackground != null) {
+ NotificationCompat.BigPictureStyle style =
+ new NotificationCompat.BigPictureStyle();
+ style.bigPicture(BitmapFactory.decodeResource(context.getResources(),
+ firstBackground));
+ firstPageBuilder.setStyle(style);
+ }
+
+ Integer secondBackground = options.backgroundIds == null
+ ? null : options.backgroundIds[1];
+ if (secondBackground != null) {
+ NotificationCompat.BigPictureStyle style = new NotificationCompat.BigPictureStyle();
+ style.bigPicture(BitmapFactory.decodeResource(context.getResources(),
+ secondBackground));
+ secondPageBuilder.setStyle(style);
+ }
+
+ firstPageBuilder.extend(
+ firstPageWearableOptions.addPage(secondPageBuilder.build()));
+
+ return new Notification[]{ firstPageBuilder.build() };
+ }
+
+ @Override
+ public int countBackgroundPickersRequired() {
+ return 2; // This sample does 2 pages notifications.
+ }
+ }
+
+ private static class NotificationBundlePreset extends NotificationPreset {
+ public NotificationBundlePreset() {
+ super(R.string.bundle_example, R.string.example_content_title,
+ R.string.example_content_text);
+ }
+
+ @Override
+ public Notification[] buildNotifications(Context context, BuildOptions options) {
+ NotificationCompat.Builder childBuilder1 = new NotificationCompat.Builder(context)
+ .setContentTitle(context.getString(R.string.first_child_content_title))
+ .setContentText(context.getString(R.string.first_child_content_text))
+ .setSmallIcon(R.mipmap.ic_launcher)
+ .setLocalOnly(options.isLocalOnly)
+ .setGroup(EXAMPLE_GROUP_KEY)
+ .setSortKey("0");
+
+ NotificationCompat.Builder childBuilder2 = new NotificationCompat.Builder(context)
+ .setContentTitle(context.getString(R.string.second_child_content_title))
+ .setContentText(context.getString(R.string.second_child_content_text))
+ .setSmallIcon(R.mipmap.ic_launcher)
+ .addAction(R.mipmap.ic_launcher,
+ context.getString(R.string.second_child_action),
+ NotificationUtil.getExamplePendingIntent(
+ context, R.string.second_child_action_clicked))
+ .setLocalOnly(options.isLocalOnly)
+ .setGroup(EXAMPLE_GROUP_KEY)
+ .setSortKey("1");
+
+ NotificationCompat.Builder summaryBuilder = new NotificationCompat.Builder(context)
+ .setGroup(EXAMPLE_GROUP_KEY)
+ .setGroupSummary(true);
+
+ NotificationCompat.WearableExtender summaryWearableOptions =
+ new NotificationCompat.WearableExtender();
+ applyBasicOptions(context, summaryBuilder, summaryWearableOptions, options);
+ summaryBuilder.extend(summaryWearableOptions);
+
+ return new Notification[] { summaryBuilder.build(), childBuilder1.build(),
+ childBuilder2.build() };
+ }
+ }
+}
diff --git a/samples/browseable/Notifications/Application/src/com.example.android.notifications/NotificationUtil.java b/samples/browseable/Notifications/Application/src/com.example.android.notifications/NotificationUtil.java
new file mode 100644
index 0000000..b5c43e5
--- /dev/null
+++ b/samples/browseable/Notifications/Application/src/com.example.android.notifications/NotificationUtil.java
@@ -0,0 +1,36 @@
+/*
+ * 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.notifications;
+
+import android.app.PendingIntent;
+import android.content.Context;
+import android.content.Intent;
+
+public class NotificationUtil {
+ public static final String EXTRA_MESSAGE =
+ "com.example.android.notifications.MESSAGE";
+ public static final String EXTRA_REPLY =
+ "com.example.android.notifications.REPLY";
+
+ public static PendingIntent getExamplePendingIntent(Context context, int messageResId) {
+ Intent intent = new Intent(NotificationIntentReceiver.ACTION_EXAMPLE)
+ .setClass(context, NotificationIntentReceiver.class);
+ intent.putExtra(EXTRA_MESSAGE, context.getString(messageResId));
+ return PendingIntent.getBroadcast(context, messageResId /* requestCode */, intent,
+ PendingIntent.FLAG_UPDATE_CURRENT);
+ }
+}
diff --git a/samples/browseable/Notifications/Application/src/com.example.android.notifications/PriorityPreset.java b/samples/browseable/Notifications/Application/src/com.example.android.notifications/PriorityPreset.java
new file mode 100644
index 0000000..eaddb83
--- /dev/null
+++ b/samples/browseable/Notifications/Application/src/com.example.android.notifications/PriorityPreset.java
@@ -0,0 +1,32 @@
+/*
+ * 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.notifications;
+
+import android.support.v4.app.NotificationCompat;
+
+/**
+ * Base class for notification priority presets.
+ */
+public abstract class PriorityPreset extends NamedPreset {
+ public PriorityPreset(int nameResId) {
+ super(nameResId);
+ }
+
+ /** Apply the priority to a notification builder */
+ public abstract void apply(NotificationCompat.Builder builder,
+ NotificationCompat.WearableExtender wearableOptions);
+}
diff --git a/samples/browseable/Notifications/Application/src/com.example.android.notifications/PriorityPresets.java b/samples/browseable/Notifications/Application/src/com.example.android.notifications/PriorityPresets.java
new file mode 100644
index 0000000..7d1ed7c
--- /dev/null
+++ b/samples/browseable/Notifications/Application/src/com.example.android.notifications/PriorityPresets.java
@@ -0,0 +1,55 @@
+/*
+ * 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.notifications;
+
+import android.app.Notification;
+import android.support.v4.app.NotificationCompat;
+
+/**
+ * Collection of notification priority presets.
+ */
+public class PriorityPresets {
+ public static final PriorityPreset DEFAULT = new SimplePriorityPreset(
+ R.string.default_priority, Notification.PRIORITY_DEFAULT);
+
+ public static final PriorityPreset[] PRESETS = new PriorityPreset[] {
+ new SimplePriorityPreset(R.string.min_priority, Notification.PRIORITY_MIN),
+ new SimplePriorityPreset(R.string.low_priority, Notification.PRIORITY_LOW),
+ DEFAULT,
+ new SimplePriorityPreset(R.string.high_priority, Notification.PRIORITY_HIGH),
+ new SimplePriorityPreset(R.string.max_priority, Notification.PRIORITY_MAX)
+ };
+
+ /**
+ * Simple notification priority preset that sets a priority using
+ * {@link android.support.v4.app.NotificationCompat.Builder#setPriority}
+ */
+ private static class SimplePriorityPreset extends PriorityPreset {
+ private final int mPriority;
+
+ public SimplePriorityPreset(int nameResId, int priority) {
+ super(nameResId);
+ mPriority = priority;
+ }
+
+ @Override
+ public void apply(NotificationCompat.Builder builder,
+ NotificationCompat.WearableExtender wearableOptions) {
+ builder.setPriority(mPriority);
+ }
+ }
+}
diff --git a/samples/browseable/Notifications/Shared/AndroidManifest.xml b/samples/browseable/Notifications/Shared/AndroidManifest.xml
new file mode 100644
index 0000000..0054143
--- /dev/null
+++ b/samples/browseable/Notifications/Shared/AndroidManifest.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.notifications.common">
+
+ <application android:allowBackup="true"
+ android:label="@string/app_name">
+ </application>
+
+</manifest>
diff --git a/samples/browseable/Notifications/Shared/res/values/strings.xml b/samples/browseable/Notifications/Shared/res/values/strings.xml
new file mode 100644
index 0000000..0f2bb90
--- /dev/null
+++ b/samples/browseable/Notifications/Shared/res/values/strings.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<resources>
+ <string name="app_name">Shared</string>
+</resources>
diff --git a/samples/browseable/Notifications/Wearable/AndroidManifest.xml b/samples/browseable/Notifications/Wearable/AndroidManifest.xml
new file mode 100644
index 0000000..99640f5
--- /dev/null
+++ b/samples/browseable/Notifications/Wearable/AndroidManifest.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.notifications" >
+
+ <uses-sdk android:minSdkVersion="20"
+ android:targetSdkVersion="20" />
+
+ <uses-feature android:name="android.hardware.type.watch" />
+
+ <application
+ android:allowBackup="true"
+ android:icon="@mipmap/ic_launcher"
+ android:label="@string/app_name"
+ android:theme="@android:style/Theme.DeviceDefault.Light" >
+
+ <activity
+ android:name=".MainActivity"
+ android:label="@string/app_name" >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ <activity
+ android:name=".BasicNotificationDisplayActivity"
+ android:exported="true"
+ android:allowEmbedded="true"
+ android:label="@string/app_name"
+ android:taskAffinity="" />
+ <activity
+ android:name=".AnimatedNotificationDisplayActivity"
+ android:exported="true"
+ android:allowEmbedded="true"
+ android:label="@string/app_name"
+ android:taskAffinity="" />
+ </application>
+
+</manifest>
diff --git a/samples/browseable/Notifications/Wearable/res/drawable-nodpi/content_icon_large.png b/samples/browseable/Notifications/Wearable/res/drawable-nodpi/content_icon_large.png
new file mode 100644
index 0000000..0eab3b1
--- /dev/null
+++ b/samples/browseable/Notifications/Wearable/res/drawable-nodpi/content_icon_large.png
Binary files differ
diff --git a/samples/browseable/Notifications/Wearable/res/drawable-nodpi/content_icon_small.png b/samples/browseable/Notifications/Wearable/res/drawable-nodpi/content_icon_small.png
new file mode 100644
index 0000000..9a9f4b4
--- /dev/null
+++ b/samples/browseable/Notifications/Wearable/res/drawable-nodpi/content_icon_small.png
Binary files differ
diff --git a/samples/browseable/Notifications/Wearable/res/drawable-nodpi/example_big_picture.jpg b/samples/browseable/Notifications/Wearable/res/drawable-nodpi/example_big_picture.jpg
new file mode 100644
index 0000000..68473ba
--- /dev/null
+++ b/samples/browseable/Notifications/Wearable/res/drawable-nodpi/example_big_picture.jpg
Binary files differ
diff --git a/samples/browseable/Notifications/Wearable/res/drawable/wl_circle.xml b/samples/browseable/Notifications/Wearable/res/drawable/wl_circle.xml
new file mode 100644
index 0000000..7c9708e
--- /dev/null
+++ b/samples/browseable/Notifications/Wearable/res/drawable/wl_circle.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<shape
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="oval">
+ <solid android:color="@color/wl_gray"/>
+</shape>
diff --git a/samples/browseable/Notifications/Wearable/res/layout/activity_animated_notification_display.xml b/samples/browseable/Notifications/Wearable/res/layout/activity_animated_notification_display.xml
new file mode 100644
index 0000000..be70b2b
--- /dev/null
+++ b/samples/browseable/Notifications/Wearable/res/layout/activity_animated_notification_display.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/container"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" >
+
+ <TextView android:id="@+id/title"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:textSize="16sp"
+ android:padding="8dp"
+ android:gravity="center_vertical|center_horizontal"
+ android:textColor="#FF3333"
+ android:shadowColor="#992222"
+ android:shadowRadius="2"
+ android:shadowDx="1"
+ android:shadowDy="1" />
+
+</FrameLayout>
diff --git a/samples/browseable/Notifications/Wearable/res/layout/activity_main.xml b/samples/browseable/Notifications/Wearable/res/layout/activity_main.xml
new file mode 100644
index 0000000..9ae6026
--- /dev/null
+++ b/samples/browseable/Notifications/Wearable/res/layout/activity_main.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<android.support.wearable.view.WearableListView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/list"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:scrollbars="none"
+ android:dividerHeight="0dp"/>
diff --git a/samples/browseable/Notifications/Wearable/res/layout/activity_notification_display.xml b/samples/browseable/Notifications/Wearable/res/layout/activity_notification_display.xml
new file mode 100644
index 0000000..7a329d2
--- /dev/null
+++ b/samples/browseable/Notifications/Wearable/res/layout/activity_notification_display.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" >
+
+ <TextView android:id="@+id/title"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:textSize="16sp"
+ android:padding="8dp"
+ android:gravity="center_vertical|center_horizontal"
+ android:textColor="#7777FF"
+ android:shadowColor="#222299"
+ android:shadowRadius="2"
+ android:shadowDx="1"
+ android:shadowDy="1"
+ />
+
+</LinearLayout>
diff --git a/samples/browseable/Notifications/Wearable/res/layout/notif_preset_list_item.xml b/samples/browseable/Notifications/Wearable/res/layout/notif_preset_list_item.xml
new file mode 100644
index 0000000..9e3cd45
--- /dev/null
+++ b/samples/browseable/Notifications/Wearable/res/layout/notif_preset_list_item.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<com.example.android.support.wearable.notifications.WearableListItemLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:gravity="center_vertical"
+ android:layout_width="match_parent"
+ android:layout_height="80dp">
+ <ImageView
+ android:id="@+id/circle"
+ android:layout_height="20dp"
+ android:layout_margin="16dp"
+ android:layout_width="20dp"
+ android:src="@drawable/wl_circle"/>
+ <TextView
+ android:id="@+id/name"
+ android:gravity="center_vertical|left"
+ android:layout_width="wrap_content"
+ android:layout_marginRight="16dp"
+ android:layout_height="match_parent"
+ android:fontFamily="sans-serif-condensed-light"
+ android:lineSpacingExtra="-4sp"
+ android:textColor="@color/text_color"
+ android:textSize="16sp"/>
+</com.example.android.support.wearable.notifications.WearableListItemLayout>
diff --git a/samples/browseable/Notifications/Wearable/res/mipmap-hdpi/ic_launcher.png b/samples/browseable/Notifications/Wearable/res/mipmap-hdpi/ic_launcher.png
new file mode 100644
index 0000000..41479de
--- /dev/null
+++ b/samples/browseable/Notifications/Wearable/res/mipmap-hdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/Notifications/Wearable/res/mipmap-mdpi/ic_launcher.png b/samples/browseable/Notifications/Wearable/res/mipmap-mdpi/ic_launcher.png
new file mode 100644
index 0000000..380b02f
--- /dev/null
+++ b/samples/browseable/Notifications/Wearable/res/mipmap-mdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/Notifications/Wearable/res/mipmap-xhdpi/ic_launcher.png b/samples/browseable/Notifications/Wearable/res/mipmap-xhdpi/ic_launcher.png
new file mode 100644
index 0000000..b3e251e
--- /dev/null
+++ b/samples/browseable/Notifications/Wearable/res/mipmap-xhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/Notifications/Wearable/res/mipmap-xxhdpi/ic_launcher.png b/samples/browseable/Notifications/Wearable/res/mipmap-xxhdpi/ic_launcher.png
new file mode 100644
index 0000000..1962289
--- /dev/null
+++ b/samples/browseable/Notifications/Wearable/res/mipmap-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/Notifications/Wearable/res/mipmap-xxxhdpi/ic_launcher.png b/samples/browseable/Notifications/Wearable/res/mipmap-xxxhdpi/ic_launcher.png
new file mode 100644
index 0000000..163f1f0
--- /dev/null
+++ b/samples/browseable/Notifications/Wearable/res/mipmap-xxxhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/Notifications/Wearable/res/values/colors.xml b/samples/browseable/Notifications/Wearable/res/values/colors.xml
new file mode 100644
index 0000000..10fad66
--- /dev/null
+++ b/samples/browseable/Notifications/Wearable/res/values/colors.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+ <color name="wl_blue">#2878ff</color>
+ <color name="wl_gray">#c1c1c1</color>
+ <color name="text_color">#434343</color>
+</resources>
diff --git a/samples/browseable/Notifications/Wearable/res/values/dimens.xml b/samples/browseable/Notifications/Wearable/res/values/dimens.xml
new file mode 100644
index 0000000..50214e6
--- /dev/null
+++ b/samples/browseable/Notifications/Wearable/res/values/dimens.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+ <!-- Default screen margins, per the Android Design guidelines. -->
+ <dimen name="activity_horizontal_margin">16dp</dimen>
+ <dimen name="activity_vertical_margin">16dp</dimen>
+ <dimen name="animation_range">60dp</dimen>
+
+</resources>
diff --git a/samples/browseable/Notifications/Wearable/res/values/integers.xml b/samples/browseable/Notifications/Wearable/res/values/integers.xml
new file mode 100644
index 0000000..1dfb011
--- /dev/null
+++ b/samples/browseable/Notifications/Wearable/res/values/integers.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+ <integer name="action_text_faded_alpha">40</integer>
+</resources>
diff --git a/samples/browseable/Notifications/Wearable/res/values/strings.xml b/samples/browseable/Notifications/Wearable/res/values/strings.xml
new file mode 100644
index 0000000..ff7023b
--- /dev/null
+++ b/samples/browseable/Notifications/Wearable/res/values/strings.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+
+ <string name="app_name">Wearable Notifications</string>
+ <string name="basic_example">Basic example</string>
+ <string name="stylized_text_example">Stylized text example</string>
+ <string name="display_intent_example">Display intent example</string>
+ <string name="multisize_display_intent_example">Multiple-sized display intent example</string>
+ <string name="animated_display_intent_example">Animated display intent example</string>
+ <string name="content_icon_example">Content icon example</string>
+
+ <string name="example_content_title">Example content title</string>
+ <string name="example_content_text">Example content text</string>
+
+ <string name="xsmall_sized_display">X-Small sized display</string>
+ <string name="small_sized_display">Small sized display</string>
+ <string name="medium_sized_display">Medium sized display</string>
+ <string name="large_sized_display">Large sized display</string>
+ <string name="full_screen_display">Full-Screen display</string>
+ <string name="dp256_height_display">256dp height display</string>
+ <string name="dp512_height_display">512dp height display</string>
+
+ <string name="action_a">Action A</string>
+ <string name="action_b">Action B</string>
+ <string name="action_c">Action C</string>
+ <string name="action_d">Action D</string>
+ <string name="reply">Reply</string>
+ <string name="reply_was">Reply was: </string>
+ <string name="third_page">Third page</string>
+ <string name="choice_1">Choice #1</string>
+</resources>
diff --git a/samples/browseable/Notifications/Wearable/src/com.example.android.notifications/AnimatedNotificationDisplayActivity.java b/samples/browseable/Notifications/Wearable/src/com.example.android.notifications/AnimatedNotificationDisplayActivity.java
new file mode 100644
index 0000000..f14acef
--- /dev/null
+++ b/samples/browseable/Notifications/Wearable/src/com.example.android.notifications/AnimatedNotificationDisplayActivity.java
@@ -0,0 +1,138 @@
+/*
+ * 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.notifications;
+
+import android.animation.Animator;
+import android.animation.AnimatorListenerAdapter;
+import android.animation.ObjectAnimator;
+import android.animation.PropertyValuesHolder;
+import android.app.Activity;
+import android.content.Context;
+import android.os.Bundle;
+import android.view.ViewGroup;
+import android.view.animation.AccelerateDecelerateInterpolator;
+import android.widget.FrameLayout;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import java.util.Random;
+
+/**
+ * Custom display activity for an animated sample notification.
+ */
+public class AnimatedNotificationDisplayActivity extends Activity {
+ public static final String EXTRA_TITLE = "title";
+
+ private static final int BASE_ANIMATION_DURATION_MS = 2000;
+
+ private Random mRandom;
+ private int mAnimationRange;
+ private ImageView mImageView;
+ private Animator mAnimation;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_animated_notification_display);
+
+ mRandom = new Random(System.currentTimeMillis());
+ mAnimationRange = getResources().getDimensionPixelSize(R.dimen.animation_range);
+
+ String title = getIntent().getStringExtra(EXTRA_TITLE);
+ ((TextView) findViewById(R.id.title)).setText(title);
+
+ mImageView = new ImageView(this);
+ mImageView.setImageResource(R.drawable.example_big_picture);
+
+ ImageZoomView zoomView = new ImageZoomView(this, mImageView, mAnimationRange);
+ zoomView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT));
+
+ ((FrameLayout) findViewById(R.id.container)).addView(zoomView, 0);
+
+ createNextAnimation(false);
+ }
+
+ private void createNextAnimation(boolean start) {
+ float startX = mImageView.getTranslationX();
+ float startY = mImageView.getTranslationY();
+ float endX = -mRandom.nextInt(mAnimationRange);
+ float endY = -mRandom.nextInt(mAnimationRange);
+ float distance = (float) Math.sqrt(Math.pow(endX - startX, 2) + Math.pow(endY - startY, 2));
+
+ mAnimation = ObjectAnimator.ofPropertyValuesHolder(mImageView,
+ PropertyValuesHolder.ofFloat("translationX", startX, endX),
+ PropertyValuesHolder.ofFloat("translationY", startY, endY));
+ mAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
+
+ mAnimation.setDuration(Math.max(BASE_ANIMATION_DURATION_MS / 10,
+ (int) (distance * BASE_ANIMATION_DURATION_MS / mAnimationRange)));
+
+ mAnimation.addListener(new AnimatorListenerAdapter() {
+ @Override
+ public void onAnimationEnd(Animator animation) {
+ super.onAnimationEnd(animation);
+ createNextAnimation(true);
+ }
+ });
+ if (start) {
+ mAnimation.start();
+ }
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ mAnimation.start();
+ }
+
+ @Override
+ protected void onPause() {
+ mAnimation.pause();
+ super.onPause();
+ }
+
+ /** Helper view that zooms in on a child image view */
+ private static class ImageZoomView extends ViewGroup {
+ private final int mZoomLength;
+
+ public ImageZoomView(Context context, ImageView imageView, int zoomLength) {
+ super(context);
+ addView(imageView);
+ mZoomLength = zoomLength;
+ }
+
+ @Override
+ protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
+ ImageView imageView = (ImageView) getChildAt(0);
+
+ // Resize the image view to be at least mZoomLength pixels larger in both
+ // dimensions than the containing view.
+ int imageWidth = imageView.getDrawable().getIntrinsicWidth();
+ int imageHeight = imageView.getDrawable().getIntrinsicHeight();
+ int minSize = Math.max(right - left, bottom - top) + mZoomLength;
+ if (imageWidth > imageHeight) {
+ imageWidth = minSize * imageWidth / imageHeight;
+ imageHeight = minSize;
+ } else {
+ imageHeight = minSize * imageHeight / imageWidth;
+ imageWidth = minSize;
+ }
+ imageView.layout(left, top, left + imageWidth, top + imageHeight);
+ }
+ }
+}
diff --git a/samples/browseable/Notifications/Wearable/src/com.example.android.notifications/BasicNotificationDisplayActivity.java b/samples/browseable/Notifications/Wearable/src/com.example.android.notifications/BasicNotificationDisplayActivity.java
new file mode 100644
index 0000000..a6cc5fb
--- /dev/null
+++ b/samples/browseable/Notifications/Wearable/src/com.example.android.notifications/BasicNotificationDisplayActivity.java
@@ -0,0 +1,38 @@
+/*
+ * 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.notifications;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.widget.TextView;
+
+/**
+ * Custom display activity for a sample notification.
+ */
+public class BasicNotificationDisplayActivity extends Activity {
+ public static final String EXTRA_TITLE = "title";
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_notification_display);
+
+ String title = getIntent().getStringExtra(EXTRA_TITLE);
+
+ ((TextView) findViewById(R.id.title)).setText(title);
+ }
+}
diff --git a/samples/browseable/Notifications/Wearable/src/com.example.android.notifications/MainActivity.java b/samples/browseable/Notifications/Wearable/src/com.example.android.notifications/MainActivity.java
new file mode 100644
index 0000000..fe7e134
--- /dev/null
+++ b/samples/browseable/Notifications/Wearable/src/com.example.android.notifications/MainActivity.java
@@ -0,0 +1,106 @@
+/*
+ * 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.notifications;
+
+import android.app.Activity;
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.RemoteInput;
+import android.content.Context;
+import android.os.Bundle;
+import android.support.wearable.view.WearableListView;
+import android.text.TextUtils;
+import android.view.LayoutInflater;
+import android.view.ViewGroup;
+import android.widget.TextView;
+import android.widget.Toast;
+
+public class MainActivity extends Activity implements WearableListView.ClickListener {
+ private static final int SAMPLE_NOTIFICATION_ID = 0;
+ public static final String KEY_REPLY = "reply";
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_main);
+
+ WearableListView listView = (WearableListView) findViewById(R.id.list);
+ listView.setAdapter(new Adapter(this));
+ listView.setClickListener(this);
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ if (getIntent() != null) {
+ Bundle inputResults = RemoteInput.getResultsFromIntent(getIntent());
+ if (inputResults != null) {
+ CharSequence replyText = inputResults.getCharSequence(KEY_REPLY);
+ if (replyText != null) {
+ Toast.makeText(this, TextUtils.concat(getString(R.string.reply_was), replyText),
+ Toast.LENGTH_LONG).show();
+ }
+ }
+ }
+ }
+
+ /** Post a new or updated notification using the selected notification options. */
+ private void updateNotification(int presetIndex) {
+ NotificationPreset preset = NotificationPresets.PRESETS[presetIndex];
+ Notification notif = preset.buildNotification(this);
+ ((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
+ .notify(SAMPLE_NOTIFICATION_ID, notif);
+ finish();
+ }
+
+ @Override
+ public void onClick(WearableListView.ViewHolder v) {
+ updateNotification((Integer) v.itemView.getTag());
+ }
+
+ @Override
+ public void onTopEmptyRegionClick() {
+ }
+
+ private static final class Adapter extends WearableListView.Adapter {
+ private final Context mContext;
+ private final LayoutInflater mInflater;
+
+ private Adapter(Context context) {
+ mContext = context;
+ mInflater = LayoutInflater.from(context);
+ }
+
+ @Override
+ public WearableListView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
+ return new WearableListView.ViewHolder(
+ mInflater.inflate(R.layout.notif_preset_list_item, null));
+ }
+
+ @Override
+ public void onBindViewHolder(WearableListView.ViewHolder holder, int position) {
+ TextView view = (TextView) holder.itemView.findViewById(R.id.name);
+ view.setText(mContext.getString(NotificationPresets.PRESETS[position].nameResId));
+ holder.itemView.setTag(position);
+ }
+
+ @Override
+ public int getItemCount() {
+ return NotificationPresets.PRESETS.length;
+ }
+ }
+}
diff --git a/samples/browseable/Notifications/Wearable/src/com.example.android.notifications/NotificationPreset.java b/samples/browseable/Notifications/Wearable/src/com.example.android.notifications/NotificationPreset.java
new file mode 100644
index 0000000..db15467
--- /dev/null
+++ b/samples/browseable/Notifications/Wearable/src/com.example.android.notifications/NotificationPreset.java
@@ -0,0 +1,34 @@
+/*
+ * 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.notifications;
+
+import android.app.Notification;
+import android.content.Context;
+
+/**
+ * Base class for notification preset generators.
+ */
+public abstract class NotificationPreset {
+ public final int nameResId;
+
+ public NotificationPreset(int nameResId) {
+ this.nameResId = nameResId;
+ }
+
+ /** Start building a notification with this preset */
+ public abstract Notification buildNotification(Context context);
+}
diff --git a/samples/browseable/Notifications/Wearable/src/com.example.android.notifications/NotificationPresets.java b/samples/browseable/Notifications/Wearable/src/com.example.android.notifications/NotificationPresets.java
new file mode 100644
index 0000000..04a4d15
--- /dev/null
+++ b/samples/browseable/Notifications/Wearable/src/com.example.android.notifications/NotificationPresets.java
@@ -0,0 +1,314 @@
+/*
+ * 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.notifications;
+
+import android.app.Notification;
+import android.app.PendingIntent;
+import android.app.RemoteInput;
+import android.content.Context;
+import android.content.Intent;
+import android.graphics.BitmapFactory;
+import android.graphics.Color;
+import android.graphics.Typeface;
+import android.net.Uri;
+import android.text.SpannableStringBuilder;
+import android.text.style.ForegroundColorSpan;
+import android.text.style.RelativeSizeSpan;
+import android.text.style.StrikethroughSpan;
+import android.text.style.StyleSpan;
+import android.text.style.SubscriptSpan;
+import android.text.style.SuperscriptSpan;
+import android.text.style.TypefaceSpan;
+import android.text.style.UnderlineSpan;
+import android.util.TypedValue;
+import android.view.Gravity;
+
+/**
+ * Collection of notification builder presets.
+ */
+public class NotificationPresets {
+ public static final NotificationPreset[] PRESETS = new NotificationPreset[] {
+ new BasicPreset(),
+ new StylizedTextPreset(),
+ new DisplayIntentPreset(),
+ new MultiSizeDisplayIntentPreset(),
+ new AnimatedDisplayIntentPreset(),
+ new ContentIconPreset()
+ };
+
+ private static Notification.Builder buildBasicNotification(Context context) {
+ return new Notification.Builder(context)
+ .setContentTitle(context.getString(R.string.example_content_title))
+ .setContentText(context.getString(R.string.example_content_text))
+ // Set a content intent to return to this sample
+ .setContentIntent(PendingIntent.getActivity(context, 0,
+ new Intent(context, MainActivity.class), 0))
+ .setSmallIcon(R.mipmap.ic_launcher);
+ }
+
+ private static class BasicPreset extends NotificationPreset {
+ public BasicPreset() {
+ super(R.string.basic_example);
+ }
+
+ @Override
+ public Notification buildNotification(Context context) {
+ PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
+ new Intent(context, MainActivity.class), 0);
+
+ Notification page2 = buildBasicNotification(context)
+ .extend(new Notification.WearableExtender()
+ .setHintShowBackgroundOnly(true)
+ .setBackground(BitmapFactory.decodeResource(context.getResources(),
+ R.drawable.example_big_picture)))
+ .build();
+
+ Notification page3 = buildBasicNotification(context)
+ .setContentTitle(context.getString(R.string.third_page))
+ .setContentText(null)
+ .extend(new Notification.WearableExtender()
+ .setContentAction(0 /* action A */))
+ .build();
+
+ SpannableStringBuilder choice2 = new SpannableStringBuilder(
+ "This choice is best");
+ choice2.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), 5, 11, 0);
+
+ return buildBasicNotification(context)
+ .extend(new Notification.WearableExtender()
+ .addAction(new Notification.Action(R.mipmap.ic_launcher,
+ context.getString(R.string.action_a), pendingIntent))
+ .addAction(new Notification.Action.Builder(R.mipmap.ic_launcher,
+ context.getString(R.string.reply), pendingIntent)
+ .addRemoteInput(new RemoteInput.Builder(MainActivity.KEY_REPLY)
+ .setChoices(new CharSequence[] {
+ context.getString(R.string.choice_1),
+ choice2 })
+ .build())
+ .build())
+ .addPage(page2)
+ .addPage(page3))
+ .build();
+ }
+ }
+
+ private static class StylizedTextPreset extends NotificationPreset {
+ public StylizedTextPreset() {
+ super(R.string.stylized_text_example);
+ }
+
+ @Override
+ public Notification buildNotification(Context context) {
+ Notification.Builder builder = buildBasicNotification(context);
+
+ Notification.BigTextStyle style = new Notification.BigTextStyle();
+
+ SpannableStringBuilder title = new SpannableStringBuilder();
+ appendStyled(title, "Stylized", new StyleSpan(Typeface.BOLD_ITALIC));
+ title.append(" title");
+ SpannableStringBuilder text = new SpannableStringBuilder("Stylized text: ");
+ appendStyled(text, "C", new ForegroundColorSpan(Color.RED));
+ appendStyled(text, "O", new ForegroundColorSpan(Color.GREEN));
+ appendStyled(text, "L", new ForegroundColorSpan(Color.BLUE));
+ appendStyled(text, "O", new ForegroundColorSpan(Color.YELLOW));
+ appendStyled(text, "R", new ForegroundColorSpan(Color.MAGENTA));
+ appendStyled(text, "S", new ForegroundColorSpan(Color.CYAN));
+ text.append("; ");
+ appendStyled(text, "1.25x size", new RelativeSizeSpan(1.25f));
+ text.append("; ");
+ appendStyled(text, "0.75x size", new RelativeSizeSpan(0.75f));
+ text.append("; ");
+ appendStyled(text, "underline", new UnderlineSpan());
+ text.append("; ");
+ appendStyled(text, "strikethrough", new StrikethroughSpan());
+ text.append("; ");
+ appendStyled(text, "bold", new StyleSpan(Typeface.BOLD));
+ text.append("; ");
+ appendStyled(text, "italic", new StyleSpan(Typeface.ITALIC));
+ text.append("; ");
+ appendStyled(text, "sans-serif-thin", new TypefaceSpan("sans-serif-thin"));
+ text.append("; ");
+ appendStyled(text, "monospace", new TypefaceSpan("monospace"));
+ text.append("; ");
+ appendStyled(text, "sub", new SubscriptSpan());
+ text.append("script");
+ appendStyled(text, "super", new SuperscriptSpan());
+
+ style.setBigContentTitle(title);
+ style.bigText(text);
+
+ builder.setStyle(style);
+ return builder.build();
+ }
+
+ private void appendStyled(SpannableStringBuilder builder, String str, Object... spans) {
+ builder.append(str);
+ for (Object span : spans) {
+ builder.setSpan(span, builder.length() - str.length(), builder.length(), 0);
+ }
+ }
+ }
+
+ private static class DisplayIntentPreset extends NotificationPreset {
+ public DisplayIntentPreset() {
+ super(R.string.display_intent_example);
+ }
+
+ @Override
+ public Notification buildNotification(Context context) {
+ Intent displayIntent = new Intent(context, BasicNotificationDisplayActivity.class);
+ displayIntent.putExtra(BasicNotificationDisplayActivity.EXTRA_TITLE,
+ context.getString(nameResId));
+ PendingIntent displayPendingIntent = PendingIntent.getActivity(context,
+ 0, displayIntent, PendingIntent.FLAG_UPDATE_CURRENT);
+ return buildBasicNotification(context)
+ .extend(new Notification.WearableExtender()
+ .setDisplayIntent(displayPendingIntent))
+ .build();
+ }
+ }
+
+ private static class MultiSizeDisplayIntentPreset extends NotificationPreset {
+ public MultiSizeDisplayIntentPreset() {
+ super(R.string.multisize_display_intent_example);
+ }
+
+ @Override
+ public Notification buildNotification(Context context) {
+ PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
+ new Intent(context, MainActivity.class), 0);
+ Intent displayIntent = new Intent(context, BasicNotificationDisplayActivity.class)
+ .putExtra(BasicNotificationDisplayActivity.EXTRA_TITLE,
+ context.getString(R.string.xsmall_sized_display));
+ return buildBasicNotification(context)
+ .extend(new Notification.WearableExtender()
+ .setDisplayIntent(PendingIntent.getActivity(context, 0, displayIntent,
+ PendingIntent.FLAG_UPDATE_CURRENT))
+ .addPage(createPageForSizePreset(context,
+ Notification.WearableExtender.SIZE_SMALL,
+ R.string.small_sized_display, 0))
+ .addPage(createPageForSizePreset(context,
+ Notification.WearableExtender.SIZE_MEDIUM,
+ R.string.medium_sized_display, 1))
+ .addPage(createPageForSizePreset(context,
+ Notification.WearableExtender.SIZE_LARGE,
+ R.string.large_sized_display, 2))
+ .addPage(createPageForSizePreset(context,
+ Notification.WearableExtender.SIZE_FULL_SCREEN,
+ R.string.full_screen_display, 3))
+ .addPage(createPageForCustomHeight(context, 256,
+ R.string.dp256_height_display))
+ .addPage(createPageForCustomHeight(context, 512,
+ R.string.dp512_height_display))
+ .addAction(new Notification.Action(R.mipmap.ic_launcher,
+ context.getString(R.string.action_a), pendingIntent))
+ .addAction(new Notification.Action(R.mipmap.ic_launcher,
+ context.getString(R.string.action_b), pendingIntent))
+ .addAction(new Notification.Action(R.mipmap.ic_launcher,
+ context.getString(R.string.action_c), pendingIntent))
+ .addAction(new Notification.Action(R.mipmap.ic_launcher,
+ context.getString(R.string.action_d), pendingIntent))
+ .setCustomSizePreset(Notification.WearableExtender.SIZE_XSMALL))
+ .build();
+ }
+
+ private Notification createPageForCustomHeight(Context context, int heightDisplayDp,
+ int pageNameResId) {
+ int contentHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
+ heightDisplayDp, context.getResources().getDisplayMetrics());
+ Intent displayIntent = new Intent(context, BasicNotificationDisplayActivity.class)
+ .setData(Uri.fromParts("example", "height/" + heightDisplayDp, null))
+ .putExtra(BasicNotificationDisplayActivity.EXTRA_TITLE,
+ context.getString(pageNameResId));
+ return buildBasicNotification(context)
+ .extend(new Notification.WearableExtender()
+ .setDisplayIntent(PendingIntent.getActivity(context, 0, displayIntent,
+ PendingIntent.FLAG_UPDATE_CURRENT))
+ .setCustomContentHeight(contentHeight))
+ .build();
+ }
+
+ private Notification createPageForSizePreset(Context context, int sizePreset,
+ int pageNameResId, int contentAction) {
+ Intent displayIntent = new Intent(context, BasicNotificationDisplayActivity.class)
+ .setData(Uri.fromParts("example", "size/" + sizePreset, null))
+ .putExtra(BasicNotificationDisplayActivity.EXTRA_TITLE,
+ context.getString(pageNameResId));
+ return buildBasicNotification(context)
+ .extend(new Notification.WearableExtender()
+ .setDisplayIntent(PendingIntent.getActivity(context, 0, displayIntent,
+ PendingIntent.FLAG_UPDATE_CURRENT))
+ .setCustomSizePreset(sizePreset)
+ .setContentAction(contentAction))
+ .build();
+ }
+ }
+
+ private static class AnimatedDisplayIntentPreset extends NotificationPreset {
+ public AnimatedDisplayIntentPreset() {
+ super(R.string.animated_display_intent_example);
+ }
+
+ @Override
+ public Notification buildNotification(Context context) {
+ Intent displayIntent = new Intent(context, AnimatedNotificationDisplayActivity.class);
+ displayIntent.putExtra(BasicNotificationDisplayActivity.EXTRA_TITLE,
+ context.getString(nameResId));
+ PendingIntent displayPendingIntent = PendingIntent.getActivity(context,
+ 0, displayIntent, 0);
+ return buildBasicNotification(context)
+ .extend(new Notification.WearableExtender()
+ .setDisplayIntent(displayPendingIntent))
+ .build();
+ }
+ }
+
+ private static class ContentIconPreset extends NotificationPreset {
+ public ContentIconPreset() {
+ super(R.string.content_icon_example);
+ }
+
+ @Override
+ public Notification buildNotification(Context context) {
+ Notification page2 = buildBasicNotification(context)
+ .extend(new Notification.WearableExtender()
+ .setContentIcon(R.drawable.content_icon_small)
+ .setContentIconGravity(Gravity.START))
+ .build();
+
+ Notification page3 = buildBasicNotification(context)
+ .extend(new Notification.WearableExtender()
+ .setContentIcon(R.drawable.content_icon_large))
+ .build();
+
+ Notification page4 = buildBasicNotification(context)
+ .extend(new Notification.WearableExtender()
+ .setContentIcon(R.drawable.content_icon_large)
+ .setContentIconGravity(Gravity.START))
+ .build();
+
+ return buildBasicNotification(context)
+ .extend(new Notification.WearableExtender()
+ .setHintHideIcon(true)
+ .setContentIcon(R.drawable.content_icon_small)
+ .addPage(page2)
+ .addPage(page3)
+ .addPage(page4))
+ .build();
+ }
+ }
+}
diff --git a/samples/browseable/Notifications/Wearable/src/com.example.android.notifications/WearableListItemLayout.java b/samples/browseable/Notifications/Wearable/src/com.example.android.notifications/WearableListItemLayout.java
new file mode 100644
index 0000000..cb08a9c
--- /dev/null
+++ b/samples/browseable/Notifications/Wearable/src/com.example.android.notifications/WearableListItemLayout.java
@@ -0,0 +1,91 @@
+/*
+ * 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.notifications;
+
+import android.content.Context;
+import android.graphics.drawable.GradientDrawable;
+import android.support.wearable.view.WearableListView;
+import android.util.AttributeSet;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+public class WearableListItemLayout extends LinearLayout implements WearableListView.Item {
+
+ private final float mFadedTextAlpha;
+ private final int mFadedCircleColor;
+ private final int mChosenCircleColor;
+ private ImageView mCircle;
+ private float mScale;
+ private TextView mName;
+
+ public WearableListItemLayout(Context context) {
+ this(context, null);
+ }
+
+ public WearableListItemLayout(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public WearableListItemLayout(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ mFadedTextAlpha = getResources().getInteger(R.integer.action_text_faded_alpha) / 100f;
+ mFadedCircleColor = getResources().getColor(R.color.wl_gray);
+ mChosenCircleColor = getResources().getColor(R.color.wl_blue);
+ }
+
+ @Override
+ protected void onFinishInflate() {
+ super.onFinishInflate();
+ mCircle = (ImageView) findViewById(R.id.circle);
+ mName = (TextView) findViewById(R.id.name);
+ }
+
+ @Override
+ public float getProximityMinValue() {
+ return 1f;
+ }
+
+ @Override
+ public float getProximityMaxValue() {
+ return 1.6f;
+ }
+
+ @Override
+ public float getCurrentProximityValue() {
+ return mScale;
+ }
+
+ @Override
+ public void setScalingAnimatorValue(float scale) {
+ mScale = scale;
+ mCircle.setScaleX(scale);
+ mCircle.setScaleY(scale);
+ }
+
+ @Override
+ public void onScaleUpStart() {
+ mName.setAlpha(1f);
+ ((GradientDrawable) mCircle.getDrawable()).setColor(mChosenCircleColor);
+ }
+
+ @Override
+ public void onScaleDownStart() {
+ ((GradientDrawable) mCircle.getDrawable()).setColor(mFadedCircleColor);
+ mName.setAlpha(mFadedTextAlpha);
+ }
+}
diff --git a/samples/browseable/Notifications/_index.jd b/samples/browseable/Notifications/_index.jd
new file mode 100644
index 0000000..7fa5d23
--- /dev/null
+++ b/samples/browseable/Notifications/_index.jd
@@ -0,0 +1,12 @@
+page.tags="Notifications"
+sample.group=Wearable
+@jd:body
+
+<p>
+
+This sample application provides a showcase of available notification styles and
+demonstrates various features of the Android Wear notifications API. Running the sample on your
+companion allows you to select between various notification styles and to see how these
+notifications are displayed, both in a phone\'s notification shade and on the wearable.
+
+ </p>
diff --git a/samples/browseable/Quiz/Application/AndroidManifest.xml b/samples/browseable/Quiz/Application/AndroidManifest.xml
new file mode 100644
index 0000000..40e3602
--- /dev/null
+++ b/samples/browseable/Quiz/Application/AndroidManifest.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.quiz" >
+
+ <uses-sdk android:minSdkVersion="19"
+ android:targetSdkVersion="19" />
+
+ <application
+ android:allowBackup="true"
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name"
+ android:theme="@style/AppTheme">
+ <meta-data android:name="com.google.android.gms.version"
+ android:value="@integer/google_play_services_version" />
+
+ <activity
+ android:name="com.example.android.quiz.MainActivity"
+ android:label="@string/app_name"
+ android:windowSoftInputMode="stateHidden"
+ android:configChanges="keyboardHidden|orientation|screenSize" >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+
+ </application>
+
+</manifest>
diff --git a/samples/browseable/Quiz/Application/res/drawable-hdpi/ic_choice_a.png b/samples/browseable/Quiz/Application/res/drawable-hdpi/ic_choice_a.png
new file mode 100644
index 0000000..de18ce1
--- /dev/null
+++ b/samples/browseable/Quiz/Application/res/drawable-hdpi/ic_choice_a.png
Binary files differ
diff --git a/samples/browseable/Quiz/Application/res/drawable-hdpi/ic_choice_b.png b/samples/browseable/Quiz/Application/res/drawable-hdpi/ic_choice_b.png
new file mode 100644
index 0000000..3cdfe97
--- /dev/null
+++ b/samples/browseable/Quiz/Application/res/drawable-hdpi/ic_choice_b.png
Binary files differ
diff --git a/samples/browseable/Quiz/Application/res/drawable-hdpi/ic_choice_c.png b/samples/browseable/Quiz/Application/res/drawable-hdpi/ic_choice_c.png
new file mode 100644
index 0000000..f0ed2ef
--- /dev/null
+++ b/samples/browseable/Quiz/Application/res/drawable-hdpi/ic_choice_c.png
Binary files differ
diff --git a/samples/browseable/Quiz/Application/res/drawable-hdpi/ic_choice_d.png b/samples/browseable/Quiz/Application/res/drawable-hdpi/ic_choice_d.png
new file mode 100644
index 0000000..c158d29
--- /dev/null
+++ b/samples/browseable/Quiz/Application/res/drawable-hdpi/ic_choice_d.png
Binary files differ
diff --git a/samples/browseable/Quiz/Application/res/drawable-hdpi/ic_launcher.png b/samples/browseable/Quiz/Application/res/drawable-hdpi/ic_launcher.png
new file mode 100755
index 0000000..91a8cff
--- /dev/null
+++ b/samples/browseable/Quiz/Application/res/drawable-hdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/Quiz/Application/res/drawable-hdpi/ic_unknown_choice.png b/samples/browseable/Quiz/Application/res/drawable-hdpi/ic_unknown_choice.png
new file mode 100644
index 0000000..9aed517
--- /dev/null
+++ b/samples/browseable/Quiz/Application/res/drawable-hdpi/ic_unknown_choice.png
Binary files differ
diff --git a/samples/browseable/Quiz/Application/res/drawable-hdpi/tile.9.png b/samples/browseable/Quiz/Application/res/drawable-hdpi/tile.9.png
new file mode 100644
index 0000000..1358628
--- /dev/null
+++ b/samples/browseable/Quiz/Application/res/drawable-hdpi/tile.9.png
Binary files differ
diff --git a/samples/browseable/Quiz/Application/res/drawable-mdpi/ic_choice_a.png b/samples/browseable/Quiz/Application/res/drawable-mdpi/ic_choice_a.png
new file mode 100644
index 0000000..5745936
--- /dev/null
+++ b/samples/browseable/Quiz/Application/res/drawable-mdpi/ic_choice_a.png
Binary files differ
diff --git a/samples/browseable/Quiz/Application/res/drawable-mdpi/ic_choice_b.png b/samples/browseable/Quiz/Application/res/drawable-mdpi/ic_choice_b.png
new file mode 100644
index 0000000..958b92e
--- /dev/null
+++ b/samples/browseable/Quiz/Application/res/drawable-mdpi/ic_choice_b.png
Binary files differ
diff --git a/samples/browseable/Quiz/Application/res/drawable-mdpi/ic_choice_c.png b/samples/browseable/Quiz/Application/res/drawable-mdpi/ic_choice_c.png
new file mode 100644
index 0000000..9fcfab7
--- /dev/null
+++ b/samples/browseable/Quiz/Application/res/drawable-mdpi/ic_choice_c.png
Binary files differ
diff --git a/samples/browseable/Quiz/Application/res/drawable-mdpi/ic_choice_d.png b/samples/browseable/Quiz/Application/res/drawable-mdpi/ic_choice_d.png
new file mode 100644
index 0000000..821cadb
--- /dev/null
+++ b/samples/browseable/Quiz/Application/res/drawable-mdpi/ic_choice_d.png
Binary files differ
diff --git a/samples/browseable/Quiz/Application/res/drawable-mdpi/ic_launcher.png b/samples/browseable/Quiz/Application/res/drawable-mdpi/ic_launcher.png
new file mode 100755
index 0000000..728ee6d
--- /dev/null
+++ b/samples/browseable/Quiz/Application/res/drawable-mdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/Quiz/Application/res/drawable-mdpi/ic_unknown_choice.png b/samples/browseable/Quiz/Application/res/drawable-mdpi/ic_unknown_choice.png
new file mode 100644
index 0000000..b8030ef
--- /dev/null
+++ b/samples/browseable/Quiz/Application/res/drawable-mdpi/ic_unknown_choice.png
Binary files differ
diff --git a/samples/browseable/Quiz/Application/res/drawable-xhdpi/ic_choice_a.png b/samples/browseable/Quiz/Application/res/drawable-xhdpi/ic_choice_a.png
new file mode 100644
index 0000000..3dba96f
--- /dev/null
+++ b/samples/browseable/Quiz/Application/res/drawable-xhdpi/ic_choice_a.png
Binary files differ
diff --git a/samples/browseable/Quiz/Application/res/drawable-xhdpi/ic_choice_b.png b/samples/browseable/Quiz/Application/res/drawable-xhdpi/ic_choice_b.png
new file mode 100644
index 0000000..9ca3c85
--- /dev/null
+++ b/samples/browseable/Quiz/Application/res/drawable-xhdpi/ic_choice_b.png
Binary files differ
diff --git a/samples/browseable/Quiz/Application/res/drawable-xhdpi/ic_choice_c.png b/samples/browseable/Quiz/Application/res/drawable-xhdpi/ic_choice_c.png
new file mode 100644
index 0000000..b84b3b7
--- /dev/null
+++ b/samples/browseable/Quiz/Application/res/drawable-xhdpi/ic_choice_c.png
Binary files differ
diff --git a/samples/browseable/Quiz/Application/res/drawable-xhdpi/ic_choice_d.png b/samples/browseable/Quiz/Application/res/drawable-xhdpi/ic_choice_d.png
new file mode 100644
index 0000000..185e91e
--- /dev/null
+++ b/samples/browseable/Quiz/Application/res/drawable-xhdpi/ic_choice_d.png
Binary files differ
diff --git a/samples/browseable/Quiz/Application/res/drawable-xhdpi/ic_launcher.png b/samples/browseable/Quiz/Application/res/drawable-xhdpi/ic_launcher.png
new file mode 100755
index 0000000..64a5854
--- /dev/null
+++ b/samples/browseable/Quiz/Application/res/drawable-xhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/Quiz/Application/res/drawable-xxhdpi/ic_launcher.png b/samples/browseable/Quiz/Application/res/drawable-xxhdpi/ic_launcher.png
new file mode 100755
index 0000000..86a395b
--- /dev/null
+++ b/samples/browseable/Quiz/Application/res/drawable-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/Quiz/Application/res/drawable/selected_background.xml b/samples/browseable/Quiz/Application/res/drawable/selected_background.xml
new file mode 100644
index 0000000..5852dd8
--- /dev/null
+++ b/samples/browseable/Quiz/Application/res/drawable/selected_background.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="rectangle">
+ <padding
+ android:top="4dp"
+ android:bottom="4dp"
+ android:left="4dp"
+ android:right="4dp"/>
+ <stroke
+ android:width="4dp"
+ android:color="@android:color/holo_blue_bright" />
+</shape>
diff --git a/samples/browseable/Quiz/Application/res/drawable/unselected_background.xml b/samples/browseable/Quiz/Application/res/drawable/unselected_background.xml
new file mode 100644
index 0000000..1613167
--- /dev/null
+++ b/samples/browseable/Quiz/Application/res/drawable/unselected_background.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="rectangle">
+ <padding
+ android:top="4dp"
+ android:bottom="4dp"
+ android:left="4dp"
+ android:right="4dp"/>
+ <stroke
+ android:width="4dp"
+ android:color="#ff000000" />
+</shape>
diff --git a/samples/browseable/Quiz/Application/res/layout/activity_main.xml b/samples/browseable/Quiz/Application/res/layout/activity_main.xml
new file mode 100755
index 0000000..be1aa49
--- /dev/null
+++ b/samples/browseable/Quiz/Application/res/layout/activity_main.xml
@@ -0,0 +1,36 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <LinearLayout style="@style/Widget.SampleMessageTile"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+
+ <TextView style="@style/Widget.SampleMessage"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="@dimen/horizontal_page_margin"
+ android:layout_marginRight="@dimen/horizontal_page_margin"
+ android:layout_marginTop="@dimen/vertical_page_margin"
+ android:layout_marginBottom="@dimen/vertical_page_margin"
+ android:text="@string/intro_message" />
+ </LinearLayout>
+</LinearLayout>
diff --git a/samples/browseable/Quiz/Application/res/layout/main.xml b/samples/browseable/Quiz/Application/res/layout/main.xml
new file mode 100644
index 0000000..3eb19f9
--- /dev/null
+++ b/samples/browseable/Quiz/Application/res/layout/main.xml
@@ -0,0 +1,168 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:paddingBottom="@dimen/activity_vertical_margin"
+ android:paddingLeft="@dimen/activity_horizontal_margin"
+ android:paddingRight="@dimen/activity_horizontal_margin"
+ android:paddingTop="@dimen/activity_vertical_margin"
+ tools:context="com.example.android.support.wearable.quiz.MainActivity"
+ tools:ignore="MergeRootFrame">
+
+ <LinearLayout android:id="@+id/container"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+
+ <Button
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:id="@+id/read_quiz_from_file_button"
+ android:text="@string/read_from_file_button"
+ android:onClick="readQuizFromFile"
+ android:layout_gravity="center"/>
+
+ <LinearLayout
+ android:orientation="horizontal"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceLarge"
+ android:text="@string/edit_question"
+ android:id="@+id/textView2" />
+
+ <EditText
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:id="@+id/question_text" />
+ </LinearLayout>
+
+ <LinearLayout
+ android:orientation="horizontal"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+
+ <RadioGroup
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:id="@+id/choices_radio_group">
+ <RadioButton
+ android:layout_width="wrap_content"
+ android:layout_height="50dp"
+ android:text="@string/edit_choice_a"
+ android:id="@+id/choice_a_radio"
+ android:checked="true" />
+ <RadioButton
+ android:layout_width="wrap_content"
+ android:layout_height="50dp"
+ android:text="@string/edit_choice_b"
+ android:id="@+id/choice_b_radio"
+ android:checked="false" />
+ <RadioButton
+ android:layout_width="wrap_content"
+ android:layout_height="50dp"
+ android:text="@string/edit_choice_c"
+ android:id="@+id/choice_c_radio" />
+ <RadioButton
+ android:layout_width="wrap_content"
+ android:layout_height="50dp"
+ android:text="@string/edit_choice_d"
+ android:id="@+id/choice_d_radio" />
+ </RadioGroup>
+
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+ <EditText
+ android:layout_width="match_parent"
+ android:layout_height="50dp"
+ android:id="@+id/choice_a_text" />
+ <EditText
+ android:layout_width="match_parent"
+ android:layout_height="50dp"
+ android:id="@+id/choice_b_text" />
+ <EditText
+ android:layout_width="match_parent"
+ android:layout_height="50dp"
+ android:id="@+id/choice_c_text" />
+ <EditText
+ android:layout_width="match_parent"
+ android:layout_height="50dp"
+ android:id="@+id/choice_d_text" />
+ </LinearLayout>
+
+
+ </LinearLayout>
+
+ <Button android:id="@+id/add_question"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:text="@string/add_question"
+ android:onClick="addQuestion"
+ android:layout_gravity="center">
+ </Button>
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceLarge"
+ android:text="@string/quiz_status"
+ android:id="@+id/quiz_status"
+ android:paddingTop="30dp"
+ android:paddingBottom="10dp"
+ android:visibility="invisible"/>
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:id="@+id/questions_container"
+ android:orientation="vertical"
+ android:paddingBottom="10dp">
+ </LinearLayout>
+
+ <LinearLayout
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:id="@+id/quiz_buttons"
+ android:layout_gravity="center"
+ android:visibility="invisible">
+ <Button android:id="@+id/reset_quiz_button"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:text="@string/reset_quiz"
+ android:onClick="resetQuiz">
+ </Button>
+ <Button android:id="@+id/new_quiz_button"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:text="@string/new_quiz"
+ android:onClick="newQuiz">
+ </Button>
+ </LinearLayout>
+
+
+ </LinearLayout>
+
+</ScrollView>
diff --git a/samples/browseable/Quiz/Application/res/layout/question_status_element.xml b/samples/browseable/Quiz/Application/res/layout/question_status_element.xml
new file mode 100644
index 0000000..280f44a
--- /dev/null
+++ b/samples/browseable/Quiz/Application/res/layout/question_status_element.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical" android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:text="@string/question_placeholder"
+ android:id="@+id/question" />
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:text="@string/question_unanswered"
+ android:id="@+id/status" />
+</LinearLayout>
diff --git a/samples/browseable/Quiz/Application/res/values-sw600dp/template-dimens.xml b/samples/browseable/Quiz/Application/res/values-sw600dp/template-dimens.xml
new file mode 100644
index 0000000..22074a2
--- /dev/null
+++ b/samples/browseable/Quiz/Application/res/values-sw600dp/template-dimens.xml
@@ -0,0 +1,24 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Semantic definitions -->
+
+ <dimen name="horizontal_page_margin">@dimen/margin_huge</dimen>
+ <dimen name="vertical_page_margin">@dimen/margin_medium</dimen>
+
+</resources>
diff --git a/samples/browseable/Quiz/Application/res/values-sw600dp/template-styles.xml b/samples/browseable/Quiz/Application/res/values-sw600dp/template-styles.xml
new file mode 100644
index 0000000..03d1974
--- /dev/null
+++ b/samples/browseable/Quiz/Application/res/values-sw600dp/template-styles.xml
@@ -0,0 +1,25 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <style name="Widget.SampleMessage">
+ <item name="android:textAppearance">?android:textAppearanceLarge</item>
+ <item name="android:lineSpacingMultiplier">1.2</item>
+ <item name="android:shadowDy">-6.5</item>
+ </style>
+
+</resources>
diff --git a/samples/browseable/Quiz/Application/res/values-v11/template-styles.xml b/samples/browseable/Quiz/Application/res/values-v11/template-styles.xml
new file mode 100644
index 0000000..8c1ea66
--- /dev/null
+++ b/samples/browseable/Quiz/Application/res/values-v11/template-styles.xml
@@ -0,0 +1,22 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Activity themes -->
+ <style name="Theme.Base" parent="android:Theme.Holo.Light" />
+
+</resources>
diff --git a/samples/browseable/Quiz/Application/res/values/base-strings.xml b/samples/browseable/Quiz/Application/res/values/base-strings.xml
new file mode 100644
index 0000000..527d038
--- /dev/null
+++ b/samples/browseable/Quiz/Application/res/values/base-strings.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 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.
+-->
+<resources>
+ <string name="app_name">Quiz</string>
+ <string name="intro_message">
+ <![CDATA[
+
+
+ This sample 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 an associated DataItem. These DataItems are then received on the wearable, which
+ 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.
+
+
+ ]]>
+ </string>
+</resources>
diff --git a/samples/browseable/Quiz/Application/res/values/dimens.xml b/samples/browseable/Quiz/Application/res/values/dimens.xml
new file mode 100644
index 0000000..fd97910
--- /dev/null
+++ b/samples/browseable/Quiz/Application/res/values/dimens.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+ <!-- Default screen margins, per the Android Design guidelines. -->
+ <dimen name="activity_horizontal_margin">16dp</dimen>
+ <dimen name="activity_vertical_margin">16dp</dimen>
+
+ <dimen name="editor_text_size">12dp</dimen>
+ <dimen name="editor_item_padding_top">8dp</dimen>
+ <dimen name="editor_item_padding_bottom">8dp</dimen>
+ <dimen name="editor_spinner_caption_min_width">50dp</dimen>
+
+ <dimen name="image_picker_item_side">48dp</dimen>
+
+</resources>
diff --git a/samples/browseable/Quiz/Application/res/values/strings.xml b/samples/browseable/Quiz/Application/res/values/strings.xml
new file mode 100644
index 0000000..e2fa3b1
--- /dev/null
+++ b/samples/browseable/Quiz/Application/res/values/strings.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+
+ <string name="read_from_file_button">Read quiz from file</string>
+
+ <string name="edit_question">Question</string>
+ <string name="edit_choice_a">Choice A</string>
+ <string name="edit_choice_b">Choice B</string>
+ <string name="edit_choice_c">Choice C</string>
+ <string name="edit_choice_d">Choice D</string>
+ <string name="add_question">Add Question</string>
+
+ <string name="quiz_status">Quiz Status</string>
+ <string name="question_placeholder">Question</string>
+ <string name="question_unanswered">This question has not yet been answered.</string>
+ <string name="question_incorrect">This question has been answered incorrectly.</string>
+ <string name="question_correct">This question has been answered correctly!</string>
+ <string name="question_left_blank">This question was left blank.</string>
+
+ <string name="reset_quiz">Reset Quiz</string>
+ <string name="new_quiz">New Quiz</string>
+
+</resources>
diff --git a/samples/browseable/Quiz/Application/res/values/styles.xml b/samples/browseable/Quiz/Application/res/values/styles.xml
new file mode 100644
index 0000000..69f8dfa
--- /dev/null
+++ b/samples/browseable/Quiz/Application/res/values/styles.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+
+ <style name="bg_picker">
+ <item name="android:layout_marginLeft">16dp</item>
+ <item name="android:background">@drawable/unselected_background</item>
+ </style>
+
+</resources>
diff --git a/samples/browseable/Quiz/Application/res/values/template-dimens.xml b/samples/browseable/Quiz/Application/res/values/template-dimens.xml
new file mode 100644
index 0000000..39e710b
--- /dev/null
+++ b/samples/browseable/Quiz/Application/res/values/template-dimens.xml
@@ -0,0 +1,32 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Define standard dimensions to comply with Holo-style grids and rhythm. -->
+
+ <dimen name="margin_tiny">4dp</dimen>
+ <dimen name="margin_small">8dp</dimen>
+ <dimen name="margin_medium">16dp</dimen>
+ <dimen name="margin_large">32dp</dimen>
+ <dimen name="margin_huge">64dp</dimen>
+
+ <!-- Semantic definitions -->
+
+ <dimen name="horizontal_page_margin">@dimen/margin_medium</dimen>
+ <dimen name="vertical_page_margin">@dimen/margin_medium</dimen>
+
+</resources>
diff --git a/samples/browseable/Quiz/Application/res/values/template-styles.xml b/samples/browseable/Quiz/Application/res/values/template-styles.xml
new file mode 100644
index 0000000..6e7d593
--- /dev/null
+++ b/samples/browseable/Quiz/Application/res/values/template-styles.xml
@@ -0,0 +1,42 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Activity themes -->
+
+ <style name="Theme.Base" parent="android:Theme.Light" />
+
+ <style name="Theme.Sample" parent="Theme.Base" />
+
+ <style name="AppTheme" parent="Theme.Sample" />
+ <!-- Widget styling -->
+
+ <style name="Widget" />
+
+ <style name="Widget.SampleMessage">
+ <item name="android:textAppearance">?android:textAppearanceMedium</item>
+ <item name="android:lineSpacingMultiplier">1.1</item>
+ </style>
+
+ <style name="Widget.SampleMessageTile">
+ <item name="android:background">@drawable/tile</item>
+ <item name="android:shadowColor">#7F000000</item>
+ <item name="android:shadowDy">-3.5</item>
+ <item name="android:shadowRadius">2</item>
+ </style>
+
+</resources>
diff --git a/samples/browseable/Quiz/Application/src/com.example.android.common/activities/SampleActivityBase.java b/samples/browseable/Quiz/Application/src/com.example.android.common/activities/SampleActivityBase.java
new file mode 100644
index 0000000..3228927
--- /dev/null
+++ b/samples/browseable/Quiz/Application/src/com.example.android.common/activities/SampleActivityBase.java
@@ -0,0 +1,52 @@
+/*
+* Copyright 2013 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.common.activities;
+
+import android.os.Bundle;
+import android.support.v4.app.FragmentActivity;
+
+import com.example.android.common.logger.Log;
+import com.example.android.common.logger.LogWrapper;
+
+/**
+ * Base launcher activity, to handle most of the common plumbing for samples.
+ */
+public class SampleActivityBase extends FragmentActivity {
+
+ public static final String TAG = "SampleActivityBase";
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ initializeLogging();
+ }
+
+ /** Set up targets to receive log data */
+ public void initializeLogging() {
+ // Using Log, front-end to the logging chain, emulates android.util.log method signatures.
+ // Wraps Android's native log framework
+ LogWrapper logWrapper = new LogWrapper();
+ Log.setLogNode(logWrapper);
+
+ Log.i(TAG, "Ready");
+ }
+}
diff --git a/samples/browseable/Quiz/Application/src/com.example.android.common/logger/Log.java b/samples/browseable/Quiz/Application/src/com.example.android.common/logger/Log.java
new file mode 100644
index 0000000..17503c5
--- /dev/null
+++ b/samples/browseable/Quiz/Application/src/com.example.android.common/logger/Log.java
@@ -0,0 +1,236 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+/**
+ * Helper class for a list (or tree) of LoggerNodes.
+ *
+ * <p>When this is set as the head of the list,
+ * an instance of it can function as a drop-in replacement for {@link android.util.Log}.
+ * Most of the methods in this class server only to map a method call in Log to its equivalent
+ * in LogNode.</p>
+ */
+public class Log {
+ // Grabbing the native values from Android's native logging facilities,
+ // to make for easy migration and interop.
+ public static final int NONE = -1;
+ public static final int VERBOSE = android.util.Log.VERBOSE;
+ public static final int DEBUG = android.util.Log.DEBUG;
+ public static final int INFO = android.util.Log.INFO;
+ public static final int WARN = android.util.Log.WARN;
+ public static final int ERROR = android.util.Log.ERROR;
+ public static final int ASSERT = android.util.Log.ASSERT;
+
+ // Stores the beginning of the LogNode topology.
+ private static LogNode mLogNode;
+
+ /**
+ * Returns the next LogNode in the linked list.
+ */
+ public static LogNode getLogNode() {
+ return mLogNode;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to.
+ */
+ public static void setLogNode(LogNode node) {
+ mLogNode = node;
+ }
+
+ /**
+ * Instructs the LogNode to print the log data provided. Other LogNodes can
+ * be chained to the end of the LogNode as desired.
+ *
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void println(int priority, String tag, String msg, Throwable tr) {
+ if (mLogNode != null) {
+ mLogNode.println(priority, tag, msg, tr);
+ }
+ }
+
+ /**
+ * Instructs the LogNode to print the log data provided. Other LogNodes can
+ * be chained to the end of the LogNode as desired.
+ *
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ */
+ public static void println(int priority, String tag, String msg) {
+ println(priority, tag, msg, null);
+ }
+
+ /**
+ * Prints a message at VERBOSE priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void v(String tag, String msg, Throwable tr) {
+ println(VERBOSE, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at VERBOSE priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void v(String tag, String msg) {
+ v(tag, msg, null);
+ }
+
+
+ /**
+ * Prints a message at DEBUG priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void d(String tag, String msg, Throwable tr) {
+ println(DEBUG, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at DEBUG priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void d(String tag, String msg) {
+ d(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at INFO priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void i(String tag, String msg, Throwable tr) {
+ println(INFO, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at INFO priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void i(String tag, String msg) {
+ i(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void w(String tag, String msg, Throwable tr) {
+ println(WARN, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void w(String tag, String msg) {
+ w(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void w(String tag, Throwable tr) {
+ w(tag, null, tr);
+ }
+
+ /**
+ * Prints a message at ERROR priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void e(String tag, String msg, Throwable tr) {
+ println(ERROR, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at ERROR priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void e(String tag, String msg) {
+ e(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void wtf(String tag, String msg, Throwable tr) {
+ println(ASSERT, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void wtf(String tag, String msg) {
+ wtf(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void wtf(String tag, Throwable tr) {
+ wtf(tag, null, tr);
+ }
+}
diff --git a/samples/browseable/Quiz/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/Quiz/Application/src/com.example.android.common/logger/LogFragment.java
new file mode 100644
index 0000000..b302acd
--- /dev/null
+++ b/samples/browseable/Quiz/Application/src/com.example.android.common/logger/LogFragment.java
@@ -0,0 +1,109 @@
+/*
+* Copyright 2013 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.
+*/
+/*
+ * Copyright 2013 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.common.logger;
+
+import android.graphics.Typeface;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ScrollView;
+
+/**
+ * Simple fraggment which contains a LogView and uses is to output log data it receives
+ * through the LogNode interface.
+ */
+public class LogFragment extends Fragment {
+
+ private LogView mLogView;
+ private ScrollView mScrollView;
+
+ public LogFragment() {}
+
+ public View inflateViews() {
+ mScrollView = new ScrollView(getActivity());
+ ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT);
+ mScrollView.setLayoutParams(scrollParams);
+
+ mLogView = new LogView(getActivity());
+ ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams);
+ logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
+ mLogView.setLayoutParams(logParams);
+ mLogView.setClickable(true);
+ mLogView.setFocusable(true);
+ mLogView.setTypeface(Typeface.MONOSPACE);
+
+ // Want to set padding as 16 dips, setPadding takes pixels. Hooray math!
+ int paddingDips = 16;
+ double scale = getResources().getDisplayMetrics().density;
+ int paddingPixels = (int) ((paddingDips * (scale)) + .5);
+ mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels);
+ mLogView.setCompoundDrawablePadding(paddingPixels);
+
+ mLogView.setGravity(Gravity.BOTTOM);
+ mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium);
+
+ mScrollView.addView(mLogView);
+ return mScrollView;
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+
+ View result = inflateViews();
+
+ mLogView.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {}
+
+ @Override
+ public void afterTextChanged(Editable s) {
+ mScrollView.fullScroll(ScrollView.FOCUS_DOWN);
+ }
+ });
+ return result;
+ }
+
+ public LogView getLogView() {
+ return mLogView;
+ }
+}
\ No newline at end of file
diff --git a/samples/browseable/Quiz/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/Quiz/Application/src/com.example.android.common/logger/LogNode.java
new file mode 100644
index 0000000..bc37cab
--- /dev/null
+++ b/samples/browseable/Quiz/Application/src/com.example.android.common/logger/LogNode.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2012 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.common.logger;
+
+/**
+ * Basic interface for a logging system that can output to one or more targets.
+ * Note that in addition to classes that will output these logs in some format,
+ * one can also implement this interface over a filter and insert that in the chain,
+ * such that no targets further down see certain data, or see manipulated forms of the data.
+ * You could, for instance, write a "ToHtmlLoggerNode" that just converted all the log data
+ * it received to HTML and sent it along to the next node in the chain, without printing it
+ * anywhere.
+ */
+public interface LogNode {
+
+ /**
+ * Instructs first LogNode in the list to print the log data provided.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public void println(int priority, String tag, String msg, Throwable tr);
+
+}
diff --git a/samples/browseable/Quiz/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/Quiz/Application/src/com.example.android.common/logger/LogView.java
new file mode 100644
index 0000000..c01542b
--- /dev/null
+++ b/samples/browseable/Quiz/Application/src/com.example.android.common/logger/LogView.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+import android.app.Activity;
+import android.content.Context;
+import android.util.*;
+import android.widget.TextView;
+
+/** Simple TextView which is used to output log data received through the LogNode interface.
+*/
+public class LogView extends TextView implements LogNode {
+
+ public LogView(Context context) {
+ super(context);
+ }
+
+ public LogView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public LogView(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ /**
+ * Formats the log data and prints it out to the LogView.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+
+
+ String priorityStr = null;
+
+ // For the purposes of this View, we want to print the priority as readable text.
+ switch(priority) {
+ case android.util.Log.VERBOSE:
+ priorityStr = "VERBOSE";
+ break;
+ case android.util.Log.DEBUG:
+ priorityStr = "DEBUG";
+ break;
+ case android.util.Log.INFO:
+ priorityStr = "INFO";
+ break;
+ case android.util.Log.WARN:
+ priorityStr = "WARN";
+ break;
+ case android.util.Log.ERROR:
+ priorityStr = "ERROR";
+ break;
+ case android.util.Log.ASSERT:
+ priorityStr = "ASSERT";
+ break;
+ default:
+ break;
+ }
+
+ // Handily, the Log class has a facility for converting a stack trace into a usable string.
+ String exceptionStr = null;
+ if (tr != null) {
+ exceptionStr = android.util.Log.getStackTraceString(tr);
+ }
+
+ // Take the priority, tag, message, and exception, and concatenate as necessary
+ // into one usable line of text.
+ final StringBuilder outputBuilder = new StringBuilder();
+
+ String delimiter = "\t";
+ appendIfNotNull(outputBuilder, priorityStr, delimiter);
+ appendIfNotNull(outputBuilder, tag, delimiter);
+ appendIfNotNull(outputBuilder, msg, delimiter);
+ appendIfNotNull(outputBuilder, exceptionStr, delimiter);
+
+ // In case this was originally called from an AsyncTask or some other off-UI thread,
+ // make sure the update occurs within the UI thread.
+ ((Activity) getContext()).runOnUiThread( (new Thread(new Runnable() {
+ @Override
+ public void run() {
+ // Display the text we just generated within the LogView.
+ appendToLog(outputBuilder.toString());
+ }
+ })));
+
+ if (mNext != null) {
+ mNext.println(priority, tag, msg, tr);
+ }
+ }
+
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+ /** Takes a string and adds to it, with a separator, if the bit to be added isn't null. Since
+ * the logger takes so many arguments that might be null, this method helps cut out some of the
+ * agonizing tedium of writing the same 3 lines over and over.
+ * @param source StringBuilder containing the text to append to.
+ * @param addStr The String to append
+ * @param delimiter The String to separate the source and appended strings. A tab or comma,
+ * for instance.
+ * @return The fully concatenated String as a StringBuilder
+ */
+ private StringBuilder appendIfNotNull(StringBuilder source, String addStr, String delimiter) {
+ if (addStr != null) {
+ if (addStr.length() == 0) {
+ delimiter = "";
+ }
+
+ return source.append(addStr).append(delimiter);
+ }
+ return source;
+ }
+
+ // The next LogNode in the chain.
+ LogNode mNext;
+
+ /** Outputs the string as a new line of log data in the LogView. */
+ public void appendToLog(String s) {
+ append("\n" + s);
+ }
+
+
+}
diff --git a/samples/browseable/Quiz/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/Quiz/Application/src/com.example.android.common/logger/LogWrapper.java
new file mode 100644
index 0000000..16a9e7b
--- /dev/null
+++ b/samples/browseable/Quiz/Application/src/com.example.android.common/logger/LogWrapper.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2012 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.common.logger;
+
+import android.util.Log;
+
+/**
+ * Helper class which wraps Android's native Log utility in the Logger interface. This way
+ * normal DDMS output can be one of the many targets receiving and outputting logs simultaneously.
+ */
+public class LogWrapper implements LogNode {
+
+ // For piping: The next node to receive Log data after this one has done its work.
+ private LogNode mNext;
+
+ /**
+ * Returns the next LogNode in the linked list.
+ */
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to..
+ */
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+ /**
+ * Prints data out to the console using Android's native log mechanism.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+ // There actually are log methods that don't take a msg parameter. For now,
+ // if that's the case, just convert null to the empty string and move on.
+ String useMsg = msg;
+ if (useMsg == null) {
+ useMsg = "";
+ }
+
+ // If an exeption was provided, convert that exception to a usable string and attach
+ // it to the end of the msg method.
+ if (tr != null) {
+ msg += "\n" + Log.getStackTraceString(tr);
+ }
+
+ // This is functionally identical to Log.x(tag, useMsg);
+ // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg)
+ Log.println(priority, tag, useMsg);
+
+ // If this isn't the last node in the chain, move things along.
+ if (mNext != null) {
+ mNext.println(priority, tag, msg, tr);
+ }
+ }
+}
diff --git a/samples/browseable/Quiz/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/Quiz/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java
new file mode 100644
index 0000000..19967dc
--- /dev/null
+++ b/samples/browseable/Quiz/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+/**
+ * Simple {@link LogNode} filter, removes everything except the message.
+ * Useful for situations like on-screen log output where you don't want a lot of metadata displayed,
+ * just easy-to-read message updates as they're happening.
+ */
+public class MessageOnlyLogFilter implements LogNode {
+
+ LogNode mNext;
+
+ /**
+ * Takes the "next" LogNode as a parameter, to simplify chaining.
+ *
+ * @param next The next LogNode in the pipeline.
+ */
+ public MessageOnlyLogFilter(LogNode next) {
+ mNext = next;
+ }
+
+ public MessageOnlyLogFilter() {
+ }
+
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+ if (mNext != null) {
+ getNext().println(Log.NONE, null, msg, null);
+ }
+ }
+
+ /**
+ * Returns the next LogNode in the chain.
+ */
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to..
+ */
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+}
diff --git a/samples/browseable/Quiz/Application/src/com.example.android.quiz/Constants.java b/samples/browseable/Quiz/Application/src/com.example.android.quiz/Constants.java
new file mode 100644
index 0000000..ea5c56b
--- /dev/null
+++ b/samples/browseable/Quiz/Application/src/com.example.android.quiz/Constants.java
@@ -0,0 +1,39 @@
+/*
+ * 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.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/browseable/Quiz/Application/src/com.example.android.quiz/JsonUtils.java b/samples/browseable/Quiz/Application/src/com.example.android.quiz/JsonUtils.java
new file mode 100644
index 0000000..a0f98c1
--- /dev/null
+++ b/samples/browseable/Quiz/Application/src/com.example.android.quiz/JsonUtils.java
@@ -0,0 +1,47 @@
+/*
+ * 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.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/browseable/Quiz/Application/src/com.example.android.quiz/MainActivity.java b/samples/browseable/Quiz/Application/src/com.example.android.quiz/MainActivity.java
new file mode 100644
index 0000000..ab8e3b4
--- /dev/null
+++ b/samples/browseable/Quiz/Application/src/com.example.android.quiz/MainActivity.java
@@ -0,0 +1,585 @@
+/*
+ * 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.quiz;
+
+import static com.example.android.quiz.Constants.ANSWERS;
+import static com.example.android.quiz.Constants.CHOSEN_ANSWER_CORRECT;
+import static com.example.android.quiz.Constants.CORRECT_ANSWER_INDEX;
+import static com.example.android.quiz.Constants.NUM_CORRECT;
+import static com.example.android.quiz.Constants.NUM_INCORRECT;
+import static com.example.android.quiz.Constants.NUM_SKIPPED;
+import static com.example.android.quiz.Constants.QUESTION;
+import static com.example.android.quiz.Constants.QUESTION_INDEX;
+import static com.example.android.quiz.Constants.QUESTION_WAS_ANSWERED;
+import static com.example.android.quiz.Constants.QUESTION_WAS_DELETED;
+import static com.example.android.quiz.Constants.QUIZ_ENDED_PATH;
+import static com.example.android.quiz.Constants.QUIZ_EXITED_PATH;
+import static com.example.android.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<Question> 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<Integer, Integer> radioIdToIndex;
+
+ static {
+ Map<Integer, Integer> temp = new HashMap<Integer, Integer>(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.main);
+
+ mGoogleApiClient = new GoogleApiClient.Builder(this)
+ .addApi(Wearable.API)
+ .addConnectionCallbacks(this)
+ .addOnConnectionFailedListener(this)
+ .build();
+ mFutureQuestions = new PriorityQueue<Question>(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<Question> {
+ 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<DataEvent> 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<NodeApi.GetConnectedNodesResult>() {
+ @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<DataItemBuffer>() {
+ @Override
+ public void onResult(DataItemBuffer result) {
+ if (result.getStatus().isSuccess()) {
+ List<DataItem> 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<DataItem> 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<DataApi.DataItemResult> {
+ @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<DataItemBuffer>() {
+ @Override
+ public void onResult(DataItemBuffer result) {
+ if (result.getStatus().isSuccess()) {
+ List<Uri> dataItemUriList = new ArrayList<Uri>();
+ 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<Uri> dataItemUriList) {
+ if (mGoogleApiClient.isConnected()) {
+ for (final Uri dataItemUri : dataItemUriList) {
+ Wearable.DataApi.deleteDataItems(mGoogleApiClient, dataItemUri)
+ .setResultCallback(new ResultCallback<DataApi.DeleteDataItemsResult>() {
+ @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/browseable/Quiz/Shared/AndroidManifest.xml b/samples/browseable/Quiz/Shared/AndroidManifest.xml
new file mode 100644
index 0000000..0d7b8a6
--- /dev/null
+++ b/samples/browseable/Quiz/Shared/AndroidManifest.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.quiz.common">
+
+ <application android:allowBackup="true"
+ android:label="@string/app_name">
+ </application>
+
+</manifest>
diff --git a/samples/browseable/Quiz/Shared/res/values/strings.xml b/samples/browseable/Quiz/Shared/res/values/strings.xml
new file mode 100644
index 0000000..0f2bb90
--- /dev/null
+++ b/samples/browseable/Quiz/Shared/res/values/strings.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<resources>
+ <string name="app_name">Shared</string>
+</resources>
diff --git a/samples/browseable/Quiz/Wearable/AndroidManifest.xml b/samples/browseable/Quiz/Wearable/AndroidManifest.xml
new file mode 100644
index 0000000..7954e32
--- /dev/null
+++ b/samples/browseable/Quiz/Wearable/AndroidManifest.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.quiz" >
+
+
+ <uses-sdk android:minSdkVersion="20"
+ android:targetSdkVersion="20" />
+
+ <uses-feature android:name="android.hardware.type.watch" />
+
+ <application
+ android:allowBackup="true"
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name"
+ android:theme="@android:style/Theme.DeviceDefault" >
+ <meta-data
+ android:name="com.google.android.gms.version"
+ android:value="@integer/google_play_services_version" />
+
+ <service android:name=".QuizListenerService" >
+ <intent-filter>
+ <action android:name="com.google.android.gms.wearable.BIND_LISTENER" />
+ </intent-filter>
+ </service>
+ <service android:name=".UpdateQuestionService" />
+ <service android:name=".DeleteQuestionService" />
+ <service android:name=".QuizReportActionService" />
+
+ </application>
+
+</manifest>
diff --git a/samples/browseable/Quiz/Wearable/res/drawable-hdpi/ic_choice_a.png b/samples/browseable/Quiz/Wearable/res/drawable-hdpi/ic_choice_a.png
new file mode 100644
index 0000000..de18ce1
--- /dev/null
+++ b/samples/browseable/Quiz/Wearable/res/drawable-hdpi/ic_choice_a.png
Binary files differ
diff --git a/samples/browseable/Quiz/Wearable/res/drawable-hdpi/ic_choice_b.png b/samples/browseable/Quiz/Wearable/res/drawable-hdpi/ic_choice_b.png
new file mode 100644
index 0000000..3cdfe97
--- /dev/null
+++ b/samples/browseable/Quiz/Wearable/res/drawable-hdpi/ic_choice_b.png
Binary files differ
diff --git a/samples/browseable/Quiz/Wearable/res/drawable-hdpi/ic_choice_c.png b/samples/browseable/Quiz/Wearable/res/drawable-hdpi/ic_choice_c.png
new file mode 100644
index 0000000..f0ed2ef
--- /dev/null
+++ b/samples/browseable/Quiz/Wearable/res/drawable-hdpi/ic_choice_c.png
Binary files differ
diff --git a/samples/browseable/Quiz/Wearable/res/drawable-hdpi/ic_choice_d.png b/samples/browseable/Quiz/Wearable/res/drawable-hdpi/ic_choice_d.png
new file mode 100644
index 0000000..c158d29
--- /dev/null
+++ b/samples/browseable/Quiz/Wearable/res/drawable-hdpi/ic_choice_d.png
Binary files differ
diff --git a/samples/browseable/Quiz/Wearable/res/drawable-hdpi/ic_launcher.png b/samples/browseable/Quiz/Wearable/res/drawable-hdpi/ic_launcher.png
new file mode 100755
index 0000000..91a8cff
--- /dev/null
+++ b/samples/browseable/Quiz/Wearable/res/drawable-hdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/Quiz/Wearable/res/drawable-hdpi/ic_unknown_choice.png b/samples/browseable/Quiz/Wearable/res/drawable-hdpi/ic_unknown_choice.png
new file mode 100644
index 0000000..9aed517
--- /dev/null
+++ b/samples/browseable/Quiz/Wearable/res/drawable-hdpi/ic_unknown_choice.png
Binary files differ
diff --git a/samples/browseable/Quiz/Wearable/res/drawable-mdpi/ic_choice_a.png b/samples/browseable/Quiz/Wearable/res/drawable-mdpi/ic_choice_a.png
new file mode 100644
index 0000000..5745936
--- /dev/null
+++ b/samples/browseable/Quiz/Wearable/res/drawable-mdpi/ic_choice_a.png
Binary files differ
diff --git a/samples/browseable/Quiz/Wearable/res/drawable-mdpi/ic_choice_b.png b/samples/browseable/Quiz/Wearable/res/drawable-mdpi/ic_choice_b.png
new file mode 100644
index 0000000..958b92e
--- /dev/null
+++ b/samples/browseable/Quiz/Wearable/res/drawable-mdpi/ic_choice_b.png
Binary files differ
diff --git a/samples/browseable/Quiz/Wearable/res/drawable-mdpi/ic_choice_c.png b/samples/browseable/Quiz/Wearable/res/drawable-mdpi/ic_choice_c.png
new file mode 100644
index 0000000..9fcfab7
--- /dev/null
+++ b/samples/browseable/Quiz/Wearable/res/drawable-mdpi/ic_choice_c.png
Binary files differ
diff --git a/samples/browseable/Quiz/Wearable/res/drawable-mdpi/ic_choice_d.png b/samples/browseable/Quiz/Wearable/res/drawable-mdpi/ic_choice_d.png
new file mode 100644
index 0000000..821cadb
--- /dev/null
+++ b/samples/browseable/Quiz/Wearable/res/drawable-mdpi/ic_choice_d.png
Binary files differ
diff --git a/samples/browseable/Quiz/Wearable/res/drawable-mdpi/ic_launcher.png b/samples/browseable/Quiz/Wearable/res/drawable-mdpi/ic_launcher.png
new file mode 100755
index 0000000..728ee6d
--- /dev/null
+++ b/samples/browseable/Quiz/Wearable/res/drawable-mdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/Quiz/Wearable/res/drawable-mdpi/ic_unknown_choice.png b/samples/browseable/Quiz/Wearable/res/drawable-mdpi/ic_unknown_choice.png
new file mode 100644
index 0000000..b8030ef
--- /dev/null
+++ b/samples/browseable/Quiz/Wearable/res/drawable-mdpi/ic_unknown_choice.png
Binary files differ
diff --git a/samples/browseable/Quiz/Wearable/res/drawable-xhdpi/ic_choice_a.png b/samples/browseable/Quiz/Wearable/res/drawable-xhdpi/ic_choice_a.png
new file mode 100644
index 0000000..3dba96f
--- /dev/null
+++ b/samples/browseable/Quiz/Wearable/res/drawable-xhdpi/ic_choice_a.png
Binary files differ
diff --git a/samples/browseable/Quiz/Wearable/res/drawable-xhdpi/ic_choice_b.png b/samples/browseable/Quiz/Wearable/res/drawable-xhdpi/ic_choice_b.png
new file mode 100644
index 0000000..9ca3c85
--- /dev/null
+++ b/samples/browseable/Quiz/Wearable/res/drawable-xhdpi/ic_choice_b.png
Binary files differ
diff --git a/samples/browseable/Quiz/Wearable/res/drawable-xhdpi/ic_choice_c.png b/samples/browseable/Quiz/Wearable/res/drawable-xhdpi/ic_choice_c.png
new file mode 100644
index 0000000..b84b3b7
--- /dev/null
+++ b/samples/browseable/Quiz/Wearable/res/drawable-xhdpi/ic_choice_c.png
Binary files differ
diff --git a/samples/browseable/Quiz/Wearable/res/drawable-xhdpi/ic_choice_d.png b/samples/browseable/Quiz/Wearable/res/drawable-xhdpi/ic_choice_d.png
new file mode 100644
index 0000000..185e91e
--- /dev/null
+++ b/samples/browseable/Quiz/Wearable/res/drawable-xhdpi/ic_choice_d.png
Binary files differ
diff --git a/samples/browseable/Quiz/Wearable/res/drawable-xhdpi/ic_launcher.png b/samples/browseable/Quiz/Wearable/res/drawable-xhdpi/ic_launcher.png
new file mode 100755
index 0000000..64a5854
--- /dev/null
+++ b/samples/browseable/Quiz/Wearable/res/drawable-xhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/Quiz/Wearable/res/drawable-xhdpi/ic_unknown_choice.png b/samples/browseable/Quiz/Wearable/res/drawable-xhdpi/ic_unknown_choice.png
new file mode 100644
index 0000000..57838d1
--- /dev/null
+++ b/samples/browseable/Quiz/Wearable/res/drawable-xhdpi/ic_unknown_choice.png
Binary files differ
diff --git a/samples/browseable/Quiz/Wearable/res/drawable-xxhdpi/ic_launcher.png b/samples/browseable/Quiz/Wearable/res/drawable-xxhdpi/ic_launcher.png
new file mode 100755
index 0000000..86a395b
--- /dev/null
+++ b/samples/browseable/Quiz/Wearable/res/drawable-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/Quiz/Wearable/res/values/colors.xml b/samples/browseable/Quiz/Wearable/res/values/colors.xml
new file mode 100644
index 0000000..b10adaf
--- /dev/null
+++ b/samples/browseable/Quiz/Wearable/res/values/colors.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+ <color name="dark_green">#009900</color>
+ <color name="dark_red">#800000</color>
+ <color name="dark_yellow">#FF9900</color>
+</resources>
diff --git a/samples/browseable/Quiz/Wearable/res/values/strings.xml b/samples/browseable/Quiz/Wearable/res/values/strings.xml
new file mode 100644
index 0000000..313ee4c
--- /dev/null
+++ b/samples/browseable/Quiz/Wearable/res/values/strings.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+
+ <string name="app_name">Quiz Sample Wearable App</string>
+
+ <string name="question">Question %d</string>
+
+ <string name="quiz_report">Quiz Report</string>
+ <string name="correct">correct</string>
+ <string name="incorrect">incorrect</string>
+ <string name="skipped">skipped</string>
+ <string name="reset_quiz">Reset Quiz</string>
+
+</resources>
diff --git a/samples/browseable/Quiz/Wearable/src/com.example.android.quiz/Constants.java b/samples/browseable/Quiz/Wearable/src/com.example.android.quiz/Constants.java
new file mode 100644
index 0000000..8218ad9
--- /dev/null
+++ b/samples/browseable/Quiz/Wearable/src/com.example.android.quiz/Constants.java
@@ -0,0 +1,41 @@
+/*
+ * 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.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/browseable/Quiz/Wearable/src/com.example.android.quiz/DeleteQuestionService.java b/samples/browseable/Quiz/Wearable/src/com.example.android.quiz/DeleteQuestionService.java
new file mode 100644
index 0000000..38b5e4a
--- /dev/null
+++ b/samples/browseable/Quiz/Wearable/src/com.example.android.quiz/DeleteQuestionService.java
@@ -0,0 +1,94 @@
+/*
+ * 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.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.quiz.Constants.CONNECT_TIMEOUT_MS;
+import static com.example.android.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/browseable/Quiz/Wearable/src/com.example.android.quiz/QuizListenerService.java b/samples/browseable/Quiz/Wearable/src/com.example.android.quiz/QuizListenerService.java
new file mode 100644
index 0000000..3226f9b
--- /dev/null
+++ b/samples/browseable/Quiz/Wearable/src/com.example.android.quiz/QuizListenerService.java
@@ -0,0 +1,219 @@
+/*
+ * 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.quiz;
+
+import static com.example.android.quiz.Constants.ANSWERS;
+import static com.example.android.quiz.Constants.CONNECT_TIMEOUT_MS;
+import static com.example.android.quiz.Constants.CORRECT_ANSWER_INDEX;
+import static com.example.android.quiz.Constants.NUM_CORRECT;
+import static com.example.android.quiz.Constants.NUM_INCORRECT;
+import static com.example.android.quiz.Constants.NUM_SKIPPED;
+import static com.example.android.quiz.Constants.QUESTION;
+import static com.example.android.quiz.Constants.QUESTION_INDEX;
+import static com.example.android.quiz.Constants.QUESTION_WAS_ANSWERED;
+import static com.example.android.quiz.Constants.QUESTION_WAS_DELETED;
+import static com.example.android.quiz.Constants.QUIZ_ENDED_PATH;
+import static com.example.android.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<Integer, Integer> questionNumToDrawableId;
+
+ static {
+ Map<Integer, Integer> temp = new HashMap<Integer, Integer>(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<DataEvent> 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/browseable/Quiz/Wearable/src/com.example.android.quiz/QuizReportActionService.java b/samples/browseable/Quiz/Wearable/src/com.example.android.quiz/QuizReportActionService.java
new file mode 100644
index 0000000..4ca55be
--- /dev/null
+++ b/samples/browseable/Quiz/Wearable/src/com.example.android.quiz/QuizReportActionService.java
@@ -0,0 +1,67 @@
+/*
+ * 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.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.quiz.Constants.CONNECT_TIMEOUT_MS;
+import static com.example.android.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.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/browseable/Quiz/Wearable/src/com.example.android.quiz/UpdateQuestionService.java b/samples/browseable/Quiz/Wearable/src/com.example.android.quiz/UpdateQuestionService.java
new file mode 100644
index 0000000..671ecad
--- /dev/null
+++ b/samples/browseable/Quiz/Wearable/src/com.example.android.quiz/UpdateQuestionService.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.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.quiz.Constants.CHOSEN_ANSWER_CORRECT;
+import static com.example.android.quiz.Constants.QUESTION_INDEX;
+import static com.example.android.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/browseable/Quiz/_index.jd b/samples/browseable/Quiz/_index.jd
new file mode 100644
index 0000000..3c1a1da
--- /dev/null
+++ b/samples/browseable/Quiz/_index.jd
@@ -0,0 +1,15 @@
+page.tags="Quiz"
+sample.group=Wearable
+@jd:body
+
+<p>
+
+ This sample 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 an associated DataItem. These DataItems are then received on the wearable, which
+ 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.
+
+ </p>
diff --git a/samples/browseable/RecipeAssistant/Application/AndroidManifest.xml b/samples/browseable/RecipeAssistant/Application/AndroidManifest.xml
new file mode 100644
index 0000000..db13ed9
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/AndroidManifest.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.recipeassistant" >
+
+ <uses-sdk android:minSdkVersion="19"
+ android:targetSdkVersion="19" />
+
+ <application
+ android:allowBackup="true"
+ android:icon="@mipmap/ic_app_recipe"
+ android:label="@string/app_name"
+ android:theme="@android:style/Theme.Holo.Light" >
+ <activity
+ android:name=".MainActivity"
+ android:label="@string/app_name" >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ <activity
+ android:name=".RecipeActivity"
+ android:label="@string/app_name" >
+ </activity>
+ <service
+ android:name=".RecipeService" />
+ </application>
+
+</manifest>
diff --git a/samples/browseable/RecipeAssistant/Application/res/drawable-hdpi/ic_noimage.png b/samples/browseable/RecipeAssistant/Application/res/drawable-hdpi/ic_noimage.png
new file mode 100644
index 0000000..7bba7ab
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/res/drawable-hdpi/ic_noimage.png
Binary files differ
diff --git a/samples/browseable/RecipeAssistant/Application/res/drawable-hdpi/tile.9.png b/samples/browseable/RecipeAssistant/Application/res/drawable-hdpi/tile.9.png
new file mode 100644
index 0000000..1358628
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/res/drawable-hdpi/tile.9.png
Binary files differ
diff --git a/samples/browseable/RecipeAssistant/Application/res/drawable-mdpi/ic_noimage.png b/samples/browseable/RecipeAssistant/Application/res/drawable-mdpi/ic_noimage.png
new file mode 100644
index 0000000..a5ad26f
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/res/drawable-mdpi/ic_noimage.png
Binary files differ
diff --git a/samples/browseable/RecipeAssistant/Application/res/drawable-xhdpi/ic_noimage.png b/samples/browseable/RecipeAssistant/Application/res/drawable-xhdpi/ic_noimage.png
new file mode 100644
index 0000000..8b631d1
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/res/drawable-xhdpi/ic_noimage.png
Binary files differ
diff --git a/samples/browseable/RecipeAssistant/Application/res/layout/activity_main.xml b/samples/browseable/RecipeAssistant/Application/res/layout/activity_main.xml
new file mode 100755
index 0000000..be1aa49
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/res/layout/activity_main.xml
@@ -0,0 +1,36 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <LinearLayout style="@style/Widget.SampleMessageTile"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+
+ <TextView style="@style/Widget.SampleMessage"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="@dimen/horizontal_page_margin"
+ android:layout_marginRight="@dimen/horizontal_page_margin"
+ android:layout_marginTop="@dimen/vertical_page_margin"
+ android:layout_marginBottom="@dimen/vertical_page_margin"
+ android:text="@string/intro_message" />
+ </LinearLayout>
+</LinearLayout>
diff --git a/samples/browseable/RecipeAssistant/Application/res/layout/list_item.xml b/samples/browseable/RecipeAssistant/Application/res/layout/list_item.xml
new file mode 100644
index 0000000..756880c
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/res/layout/list_item.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_marginBottom="16dp"
+ android:orientation="vertical" >
+
+ <ImageView
+ android:id="@+id/imageView"
+ android:layout_width="fill_parent"
+ android:layout_height="300dp"
+ android:layout_alignParentLeft="true"
+ android:layout_alignParentTop="true"
+ android:layout_marginBottom="16dp"
+ android:background="@color/list_image_bg_color"
+ android:src="@drawable/ic_noimage" />
+
+ <LinearLayout
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_alignBottom="@+id/imageView"
+ android:layout_alignParentLeft="true"
+ android:background="@color/list_text_bg_color"
+ android:orientation="vertical" >
+
+ <TextView
+ android:id="@+id/textTitle"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginBottom="8dp"
+ android:layout_marginLeft="8dp"
+ android:textAppearance="@style/RecipeTitleFont" />
+
+ <TextView
+ android:id="@+id/textSummary"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginBottom="16dp"
+ android:layout_marginLeft="16dp"
+ android:textAppearance="@style/RecipeSummaryFont" />
+ </LinearLayout>
+
+</RelativeLayout>
diff --git a/samples/browseable/RecipeAssistant/Application/res/layout/recipe.xml b/samples/browseable/RecipeAssistant/Application/res/layout/recipe.xml
new file mode 100644
index 0000000..3bb20b8
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/res/layout/recipe.xml
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" >
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical" >
+
+ <ImageView
+ android:id="@+id/recipeImageView"
+ android:layout_width="fill_parent"
+ android:layout_height="300dp"
+ android:layout_marginBottom="16dp"
+ android:background="@color/list_image_bg_color"
+ android:src="@drawable/ic_noimage" />
+
+ <LinearLayout
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:background="@color/list_text_bg_color"
+ android:orientation="vertical" >
+
+ <TextView
+ android:id="@+id/recipeTextTitle"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginBottom="8dp"
+ android:layout_marginLeft="8dp"
+ android:textAppearance="@style/RecipeHugeFont" />
+
+ <TextView
+ android:id="@+id/recipeTextSummary"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginBottom="16dp"
+ android:layout_marginLeft="16dp"
+ android:textAppearance="@style/RecipeSummaryFont" />
+ </LinearLayout>
+
+ <TextView
+ android:id="@+id/ingredientsHeader"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginBottom="8dp"
+ android:layout_marginLeft="8dp"
+ android:text="@string/ingredients"
+ android:textAppearance="@style/RecipeTitleFont"
+ android:visibility="gone" />
+
+ <TextView
+ android:id="@+id/textIngredients"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginBottom="8dp"
+ android:layout_marginLeft="8dp"
+ android:textAppearance="@style/RecipeSummaryFont" />
+
+ <TextView
+ android:id="@+id/stepsHeader"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginBottom="8dp"
+ android:layout_marginLeft="8dp"
+ android:text="@string/steps"
+ android:textAppearance="@style/RecipeTitleFont"
+ android:visibility="gone" />
+
+ <LinearLayout
+ android:id="@+id/layoutSteps"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_margin="8dp"
+ android:orientation="vertical"
+ android:textAppearance="@style/RecipeSummaryFont" >
+ </LinearLayout>
+ </LinearLayout>
+
+</ScrollView>
diff --git a/samples/browseable/RecipeAssistant/Application/res/layout/step_item.xml b/samples/browseable/RecipeAssistant/Application/res/layout/step_item.xml
new file mode 100644
index 0000000..faa5ac5
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/res/layout/step_item.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_marginBottom="32dp"
+ android:orientation="vertical" >
+
+ <ImageView
+ android:id="@+id/stepImageView"
+ android:layout_width="fill_parent"
+ android:layout_height="300dp"
+ android:layout_alignParentLeft="true"
+ android:layout_alignParentTop="true"
+ android:layout_marginBottom="16dp"
+ android:background="@color/list_image_bg_color"
+ android:src="@drawable/ic_noimage" />
+
+ <LinearLayout
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_alignBottom="@+id/stepImageView"
+ android:layout_alignParentLeft="true"
+ android:background="@color/list_text_bg_color"
+ android:orientation="vertical" >
+
+ <TextView
+ android:id="@+id/textStep"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginBottom="8dp"
+ android:layout_marginLeft="8dp"
+ android:layout_marginRight="8dp"
+ android:textAppearance="@style/RecipeTitleFont" />
+ </LinearLayout>
+
+</RelativeLayout>
diff --git a/samples/browseable/RecipeAssistant/Application/res/menu/main.xml b/samples/browseable/RecipeAssistant/Application/res/menu/main.xml
new file mode 100644
index 0000000..b392472
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/res/menu/main.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+ <item
+ android:id="@+id/action_cook"
+ android:orderInCategory="100"
+ android:showAsAction="always|withText"
+ android:title="@string/action_cook" />
+</menu>
diff --git a/samples/browseable/RecipeAssistant/Application/res/mipmap-hdpi/ic_app_recipe.png b/samples/browseable/RecipeAssistant/Application/res/mipmap-hdpi/ic_app_recipe.png
new file mode 100644
index 0000000..8ceb869
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/res/mipmap-hdpi/ic_app_recipe.png
Binary files differ
diff --git a/samples/browseable/RecipeAssistant/Application/res/mipmap-hdpi/ic_notification_recipe.png b/samples/browseable/RecipeAssistant/Application/res/mipmap-hdpi/ic_notification_recipe.png
new file mode 100644
index 0000000..844d8ed
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/res/mipmap-hdpi/ic_notification_recipe.png
Binary files differ
diff --git a/samples/browseable/RecipeAssistant/Application/res/mipmap-mdpi/ic_app_recipe.png b/samples/browseable/RecipeAssistant/Application/res/mipmap-mdpi/ic_app_recipe.png
new file mode 100644
index 0000000..b884789
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/res/mipmap-mdpi/ic_app_recipe.png
Binary files differ
diff --git a/samples/browseable/RecipeAssistant/Application/res/mipmap-mdpi/ic_notification_recipe.png b/samples/browseable/RecipeAssistant/Application/res/mipmap-mdpi/ic_notification_recipe.png
new file mode 100644
index 0000000..3f3f58c
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/res/mipmap-mdpi/ic_notification_recipe.png
Binary files differ
diff --git a/samples/browseable/RecipeAssistant/Application/res/mipmap-xhdpi/ic_app_recipe.png b/samples/browseable/RecipeAssistant/Application/res/mipmap-xhdpi/ic_app_recipe.png
new file mode 100644
index 0000000..2a27c32
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/res/mipmap-xhdpi/ic_app_recipe.png
Binary files differ
diff --git a/samples/browseable/RecipeAssistant/Application/res/mipmap-xhdpi/ic_notification_recipe.png b/samples/browseable/RecipeAssistant/Application/res/mipmap-xhdpi/ic_notification_recipe.png
new file mode 100644
index 0000000..5a99b7c
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/res/mipmap-xhdpi/ic_notification_recipe.png
Binary files differ
diff --git a/samples/browseable/RecipeAssistant/Application/res/mipmap-xxhdpi/ic_app_recipe.png b/samples/browseable/RecipeAssistant/Application/res/mipmap-xxhdpi/ic_app_recipe.png
new file mode 100644
index 0000000..b10c770
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/res/mipmap-xxhdpi/ic_app_recipe.png
Binary files differ
diff --git a/samples/browseable/RecipeAssistant/Application/res/mipmap-xxhdpi/ic_notification_recipe.png b/samples/browseable/RecipeAssistant/Application/res/mipmap-xxhdpi/ic_notification_recipe.png
new file mode 100644
index 0000000..799726d
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/res/mipmap-xxhdpi/ic_notification_recipe.png
Binary files differ
diff --git a/samples/browseable/RecipeAssistant/Application/res/mipmap-xxxhdpi/ic_app_recipe.png b/samples/browseable/RecipeAssistant/Application/res/mipmap-xxxhdpi/ic_app_recipe.png
new file mode 100644
index 0000000..606f07f
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/res/mipmap-xxxhdpi/ic_app_recipe.png
Binary files differ
diff --git a/samples/browseable/RecipeAssistant/Application/res/mipmap-xxxhdpi/ic_notification_recipe.png b/samples/browseable/RecipeAssistant/Application/res/mipmap-xxxhdpi/ic_notification_recipe.png
new file mode 100644
index 0000000..30e28a8
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/res/mipmap-xxxhdpi/ic_notification_recipe.png
Binary files differ
diff --git a/samples/browseable/RecipeAssistant/Application/res/values-sw600dp/template-dimens.xml b/samples/browseable/RecipeAssistant/Application/res/values-sw600dp/template-dimens.xml
new file mode 100644
index 0000000..22074a2
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/res/values-sw600dp/template-dimens.xml
@@ -0,0 +1,24 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Semantic definitions -->
+
+ <dimen name="horizontal_page_margin">@dimen/margin_huge</dimen>
+ <dimen name="vertical_page_margin">@dimen/margin_medium</dimen>
+
+</resources>
diff --git a/samples/browseable/RecipeAssistant/Application/res/values-sw600dp/template-styles.xml b/samples/browseable/RecipeAssistant/Application/res/values-sw600dp/template-styles.xml
new file mode 100644
index 0000000..03d1974
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/res/values-sw600dp/template-styles.xml
@@ -0,0 +1,25 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <style name="Widget.SampleMessage">
+ <item name="android:textAppearance">?android:textAppearanceLarge</item>
+ <item name="android:lineSpacingMultiplier">1.2</item>
+ <item name="android:shadowDy">-6.5</item>
+ </style>
+
+</resources>
diff --git a/samples/browseable/RecipeAssistant/Application/res/values-v11/template-styles.xml b/samples/browseable/RecipeAssistant/Application/res/values-v11/template-styles.xml
new file mode 100644
index 0000000..8c1ea66
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/res/values-v11/template-styles.xml
@@ -0,0 +1,22 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Activity themes -->
+ <style name="Theme.Base" parent="android:Theme.Holo.Light" />
+
+</resources>
diff --git a/samples/browseable/RecipeAssistant/Application/res/values/base-strings.xml b/samples/browseable/RecipeAssistant/Application/res/values/base-strings.xml
new file mode 100644
index 0000000..e536fbd
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/res/values/base-strings.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 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.
+-->
+<resources>
+ <string name="app_name">RecipeAssistant</string>
+ <string name="intro_message">
+ <![CDATA[
+
+
+ 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.
+
+
+ ]]>
+ </string>
+</resources>
diff --git a/samples/browseable/RecipeAssistant/Application/res/values/colors.xml b/samples/browseable/RecipeAssistant/Application/res/values/colors.xml
new file mode 100644
index 0000000..0f1430c
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/res/values/colors.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+ <color name="list_text_bg_color">#dfff</color>
+ <color name="list_image_bg_color">#6aaa</color>
+</resources>
diff --git a/samples/browseable/RecipeAssistant/Application/res/values/strings.xml b/samples/browseable/RecipeAssistant/Application/res/values/strings.xml
new file mode 100644
index 0000000..f8ae109
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/res/values/strings.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+ <string name="action_settings">Settings</string>
+ <string name="action_cook">Start</string>
+ <string name="steps">Steps</string>
+ <string name="ingredients">Ingredients</string>
+ <string name="step_count">Step %1$d of %2$d</string>
+</resources>
diff --git a/samples/browseable/RecipeAssistant/Application/res/values/styles.xml b/samples/browseable/RecipeAssistant/Application/res/values/styles.xml
new file mode 100644
index 0000000..8876dd5
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/res/values/styles.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources xmlns:android="http://schemas.android.com/apk/res/android">
+ <style name="RecipeTitleFont" parent="@android:style/TextAppearance.Large">
+ <item name="android:layout_width">fill_parent</item>
+ <item name="android:layout_height">wrap_content</item>
+ <item name="android:textColor">#333333</item>
+ <item name="android:fontFamily">sans-serif</item>
+ </style>
+
+ <style name="RecipeHugeFont" parent="@android:style/TextAppearance.Large">
+ <item name="android:layout_width">fill_parent</item>
+ <item name="android:layout_height">wrap_content</item>
+ <item name="android:textColor">#333333</item>
+ <item name="android:fontFamily">sans-serif</item>
+ <item name="android:textSize">20pt</item>
+ </style>
+
+ <style name="RecipeSummaryFont" parent="@android:style/TextAppearance.Medium">
+ <item name="android:layout_width">fill_parent</item>
+ <item name="android:layout_height">wrap_content</item>
+ <item name="android:textColor">#333333</item>
+ <item name="android:fontFamily">sans-serif</item>
+ </style>
+</resources>
diff --git a/samples/browseable/RecipeAssistant/Application/res/values/template-dimens.xml b/samples/browseable/RecipeAssistant/Application/res/values/template-dimens.xml
new file mode 100644
index 0000000..39e710b
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/res/values/template-dimens.xml
@@ -0,0 +1,32 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Define standard dimensions to comply with Holo-style grids and rhythm. -->
+
+ <dimen name="margin_tiny">4dp</dimen>
+ <dimen name="margin_small">8dp</dimen>
+ <dimen name="margin_medium">16dp</dimen>
+ <dimen name="margin_large">32dp</dimen>
+ <dimen name="margin_huge">64dp</dimen>
+
+ <!-- Semantic definitions -->
+
+ <dimen name="horizontal_page_margin">@dimen/margin_medium</dimen>
+ <dimen name="vertical_page_margin">@dimen/margin_medium</dimen>
+
+</resources>
diff --git a/samples/browseable/RecipeAssistant/Application/res/values/template-styles.xml b/samples/browseable/RecipeAssistant/Application/res/values/template-styles.xml
new file mode 100644
index 0000000..6e7d593
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/res/values/template-styles.xml
@@ -0,0 +1,42 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Activity themes -->
+
+ <style name="Theme.Base" parent="android:Theme.Light" />
+
+ <style name="Theme.Sample" parent="Theme.Base" />
+
+ <style name="AppTheme" parent="Theme.Sample" />
+ <!-- Widget styling -->
+
+ <style name="Widget" />
+
+ <style name="Widget.SampleMessage">
+ <item name="android:textAppearance">?android:textAppearanceMedium</item>
+ <item name="android:lineSpacingMultiplier">1.1</item>
+ </style>
+
+ <style name="Widget.SampleMessageTile">
+ <item name="android:background">@drawable/tile</item>
+ <item name="android:shadowColor">#7F000000</item>
+ <item name="android:shadowDy">-3.5</item>
+ <item name="android:shadowRadius">2</item>
+ </style>
+
+</resources>
diff --git a/samples/browseable/RecipeAssistant/Application/src/com.example.android.common/activities/SampleActivityBase.java b/samples/browseable/RecipeAssistant/Application/src/com.example.android.common/activities/SampleActivityBase.java
new file mode 100644
index 0000000..3228927
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/src/com.example.android.common/activities/SampleActivityBase.java
@@ -0,0 +1,52 @@
+/*
+* Copyright 2013 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.common.activities;
+
+import android.os.Bundle;
+import android.support.v4.app.FragmentActivity;
+
+import com.example.android.common.logger.Log;
+import com.example.android.common.logger.LogWrapper;
+
+/**
+ * Base launcher activity, to handle most of the common plumbing for samples.
+ */
+public class SampleActivityBase extends FragmentActivity {
+
+ public static final String TAG = "SampleActivityBase";
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ initializeLogging();
+ }
+
+ /** Set up targets to receive log data */
+ public void initializeLogging() {
+ // Using Log, front-end to the logging chain, emulates android.util.log method signatures.
+ // Wraps Android's native log framework
+ LogWrapper logWrapper = new LogWrapper();
+ Log.setLogNode(logWrapper);
+
+ Log.i(TAG, "Ready");
+ }
+}
diff --git a/samples/browseable/RecipeAssistant/Application/src/com.example.android.common/logger/Log.java b/samples/browseable/RecipeAssistant/Application/src/com.example.android.common/logger/Log.java
new file mode 100644
index 0000000..17503c5
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/src/com.example.android.common/logger/Log.java
@@ -0,0 +1,236 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+/**
+ * Helper class for a list (or tree) of LoggerNodes.
+ *
+ * <p>When this is set as the head of the list,
+ * an instance of it can function as a drop-in replacement for {@link android.util.Log}.
+ * Most of the methods in this class server only to map a method call in Log to its equivalent
+ * in LogNode.</p>
+ */
+public class Log {
+ // Grabbing the native values from Android's native logging facilities,
+ // to make for easy migration and interop.
+ public static final int NONE = -1;
+ public static final int VERBOSE = android.util.Log.VERBOSE;
+ public static final int DEBUG = android.util.Log.DEBUG;
+ public static final int INFO = android.util.Log.INFO;
+ public static final int WARN = android.util.Log.WARN;
+ public static final int ERROR = android.util.Log.ERROR;
+ public static final int ASSERT = android.util.Log.ASSERT;
+
+ // Stores the beginning of the LogNode topology.
+ private static LogNode mLogNode;
+
+ /**
+ * Returns the next LogNode in the linked list.
+ */
+ public static LogNode getLogNode() {
+ return mLogNode;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to.
+ */
+ public static void setLogNode(LogNode node) {
+ mLogNode = node;
+ }
+
+ /**
+ * Instructs the LogNode to print the log data provided. Other LogNodes can
+ * be chained to the end of the LogNode as desired.
+ *
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void println(int priority, String tag, String msg, Throwable tr) {
+ if (mLogNode != null) {
+ mLogNode.println(priority, tag, msg, tr);
+ }
+ }
+
+ /**
+ * Instructs the LogNode to print the log data provided. Other LogNodes can
+ * be chained to the end of the LogNode as desired.
+ *
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ */
+ public static void println(int priority, String tag, String msg) {
+ println(priority, tag, msg, null);
+ }
+
+ /**
+ * Prints a message at VERBOSE priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void v(String tag, String msg, Throwable tr) {
+ println(VERBOSE, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at VERBOSE priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void v(String tag, String msg) {
+ v(tag, msg, null);
+ }
+
+
+ /**
+ * Prints a message at DEBUG priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void d(String tag, String msg, Throwable tr) {
+ println(DEBUG, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at DEBUG priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void d(String tag, String msg) {
+ d(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at INFO priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void i(String tag, String msg, Throwable tr) {
+ println(INFO, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at INFO priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void i(String tag, String msg) {
+ i(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void w(String tag, String msg, Throwable tr) {
+ println(WARN, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void w(String tag, String msg) {
+ w(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void w(String tag, Throwable tr) {
+ w(tag, null, tr);
+ }
+
+ /**
+ * Prints a message at ERROR priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void e(String tag, String msg, Throwable tr) {
+ println(ERROR, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at ERROR priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void e(String tag, String msg) {
+ e(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void wtf(String tag, String msg, Throwable tr) {
+ println(ASSERT, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void wtf(String tag, String msg) {
+ wtf(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void wtf(String tag, Throwable tr) {
+ wtf(tag, null, tr);
+ }
+}
diff --git a/samples/browseable/RecipeAssistant/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/RecipeAssistant/Application/src/com.example.android.common/logger/LogFragment.java
new file mode 100644
index 0000000..b302acd
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/src/com.example.android.common/logger/LogFragment.java
@@ -0,0 +1,109 @@
+/*
+* Copyright 2013 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.
+*/
+/*
+ * Copyright 2013 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.common.logger;
+
+import android.graphics.Typeface;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ScrollView;
+
+/**
+ * Simple fraggment which contains a LogView and uses is to output log data it receives
+ * through the LogNode interface.
+ */
+public class LogFragment extends Fragment {
+
+ private LogView mLogView;
+ private ScrollView mScrollView;
+
+ public LogFragment() {}
+
+ public View inflateViews() {
+ mScrollView = new ScrollView(getActivity());
+ ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT);
+ mScrollView.setLayoutParams(scrollParams);
+
+ mLogView = new LogView(getActivity());
+ ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams);
+ logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
+ mLogView.setLayoutParams(logParams);
+ mLogView.setClickable(true);
+ mLogView.setFocusable(true);
+ mLogView.setTypeface(Typeface.MONOSPACE);
+
+ // Want to set padding as 16 dips, setPadding takes pixels. Hooray math!
+ int paddingDips = 16;
+ double scale = getResources().getDisplayMetrics().density;
+ int paddingPixels = (int) ((paddingDips * (scale)) + .5);
+ mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels);
+ mLogView.setCompoundDrawablePadding(paddingPixels);
+
+ mLogView.setGravity(Gravity.BOTTOM);
+ mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium);
+
+ mScrollView.addView(mLogView);
+ return mScrollView;
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+
+ View result = inflateViews();
+
+ mLogView.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {}
+
+ @Override
+ public void afterTextChanged(Editable s) {
+ mScrollView.fullScroll(ScrollView.FOCUS_DOWN);
+ }
+ });
+ return result;
+ }
+
+ public LogView getLogView() {
+ return mLogView;
+ }
+}
\ No newline at end of file
diff --git a/samples/browseable/RecipeAssistant/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/RecipeAssistant/Application/src/com.example.android.common/logger/LogNode.java
new file mode 100644
index 0000000..bc37cab
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/src/com.example.android.common/logger/LogNode.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2012 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.common.logger;
+
+/**
+ * Basic interface for a logging system that can output to one or more targets.
+ * Note that in addition to classes that will output these logs in some format,
+ * one can also implement this interface over a filter and insert that in the chain,
+ * such that no targets further down see certain data, or see manipulated forms of the data.
+ * You could, for instance, write a "ToHtmlLoggerNode" that just converted all the log data
+ * it received to HTML and sent it along to the next node in the chain, without printing it
+ * anywhere.
+ */
+public interface LogNode {
+
+ /**
+ * Instructs first LogNode in the list to print the log data provided.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public void println(int priority, String tag, String msg, Throwable tr);
+
+}
diff --git a/samples/browseable/RecipeAssistant/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/RecipeAssistant/Application/src/com.example.android.common/logger/LogView.java
new file mode 100644
index 0000000..c01542b
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/src/com.example.android.common/logger/LogView.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+import android.app.Activity;
+import android.content.Context;
+import android.util.*;
+import android.widget.TextView;
+
+/** Simple TextView which is used to output log data received through the LogNode interface.
+*/
+public class LogView extends TextView implements LogNode {
+
+ public LogView(Context context) {
+ super(context);
+ }
+
+ public LogView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public LogView(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ /**
+ * Formats the log data and prints it out to the LogView.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+
+
+ String priorityStr = null;
+
+ // For the purposes of this View, we want to print the priority as readable text.
+ switch(priority) {
+ case android.util.Log.VERBOSE:
+ priorityStr = "VERBOSE";
+ break;
+ case android.util.Log.DEBUG:
+ priorityStr = "DEBUG";
+ break;
+ case android.util.Log.INFO:
+ priorityStr = "INFO";
+ break;
+ case android.util.Log.WARN:
+ priorityStr = "WARN";
+ break;
+ case android.util.Log.ERROR:
+ priorityStr = "ERROR";
+ break;
+ case android.util.Log.ASSERT:
+ priorityStr = "ASSERT";
+ break;
+ default:
+ break;
+ }
+
+ // Handily, the Log class has a facility for converting a stack trace into a usable string.
+ String exceptionStr = null;
+ if (tr != null) {
+ exceptionStr = android.util.Log.getStackTraceString(tr);
+ }
+
+ // Take the priority, tag, message, and exception, and concatenate as necessary
+ // into one usable line of text.
+ final StringBuilder outputBuilder = new StringBuilder();
+
+ String delimiter = "\t";
+ appendIfNotNull(outputBuilder, priorityStr, delimiter);
+ appendIfNotNull(outputBuilder, tag, delimiter);
+ appendIfNotNull(outputBuilder, msg, delimiter);
+ appendIfNotNull(outputBuilder, exceptionStr, delimiter);
+
+ // In case this was originally called from an AsyncTask or some other off-UI thread,
+ // make sure the update occurs within the UI thread.
+ ((Activity) getContext()).runOnUiThread( (new Thread(new Runnable() {
+ @Override
+ public void run() {
+ // Display the text we just generated within the LogView.
+ appendToLog(outputBuilder.toString());
+ }
+ })));
+
+ if (mNext != null) {
+ mNext.println(priority, tag, msg, tr);
+ }
+ }
+
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+ /** Takes a string and adds to it, with a separator, if the bit to be added isn't null. Since
+ * the logger takes so many arguments that might be null, this method helps cut out some of the
+ * agonizing tedium of writing the same 3 lines over and over.
+ * @param source StringBuilder containing the text to append to.
+ * @param addStr The String to append
+ * @param delimiter The String to separate the source and appended strings. A tab or comma,
+ * for instance.
+ * @return The fully concatenated String as a StringBuilder
+ */
+ private StringBuilder appendIfNotNull(StringBuilder source, String addStr, String delimiter) {
+ if (addStr != null) {
+ if (addStr.length() == 0) {
+ delimiter = "";
+ }
+
+ return source.append(addStr).append(delimiter);
+ }
+ return source;
+ }
+
+ // The next LogNode in the chain.
+ LogNode mNext;
+
+ /** Outputs the string as a new line of log data in the LogView. */
+ public void appendToLog(String s) {
+ append("\n" + s);
+ }
+
+
+}
diff --git a/samples/browseable/RecipeAssistant/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/RecipeAssistant/Application/src/com.example.android.common/logger/LogWrapper.java
new file mode 100644
index 0000000..16a9e7b
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/src/com.example.android.common/logger/LogWrapper.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2012 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.common.logger;
+
+import android.util.Log;
+
+/**
+ * Helper class which wraps Android's native Log utility in the Logger interface. This way
+ * normal DDMS output can be one of the many targets receiving and outputting logs simultaneously.
+ */
+public class LogWrapper implements LogNode {
+
+ // For piping: The next node to receive Log data after this one has done its work.
+ private LogNode mNext;
+
+ /**
+ * Returns the next LogNode in the linked list.
+ */
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to..
+ */
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+ /**
+ * Prints data out to the console using Android's native log mechanism.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+ // There actually are log methods that don't take a msg parameter. For now,
+ // if that's the case, just convert null to the empty string and move on.
+ String useMsg = msg;
+ if (useMsg == null) {
+ useMsg = "";
+ }
+
+ // If an exeption was provided, convert that exception to a usable string and attach
+ // it to the end of the msg method.
+ if (tr != null) {
+ msg += "\n" + Log.getStackTraceString(tr);
+ }
+
+ // This is functionally identical to Log.x(tag, useMsg);
+ // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg)
+ Log.println(priority, tag, useMsg);
+
+ // If this isn't the last node in the chain, move things along.
+ if (mNext != null) {
+ mNext.println(priority, tag, msg, tr);
+ }
+ }
+}
diff --git a/samples/browseable/RecipeAssistant/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/RecipeAssistant/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java
new file mode 100644
index 0000000..19967dc
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+/**
+ * Simple {@link LogNode} filter, removes everything except the message.
+ * Useful for situations like on-screen log output where you don't want a lot of metadata displayed,
+ * just easy-to-read message updates as they're happening.
+ */
+public class MessageOnlyLogFilter implements LogNode {
+
+ LogNode mNext;
+
+ /**
+ * Takes the "next" LogNode as a parameter, to simplify chaining.
+ *
+ * @param next The next LogNode in the pipeline.
+ */
+ public MessageOnlyLogFilter(LogNode next) {
+ mNext = next;
+ }
+
+ public MessageOnlyLogFilter() {
+ }
+
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+ if (mNext != null) {
+ getNext().println(Log.NONE, null, msg, null);
+ }
+ }
+
+ /**
+ * Returns the next LogNode in the chain.
+ */
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to..
+ */
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+}
diff --git a/samples/browseable/RecipeAssistant/Application/src/com.example.android.recipeassistant/AssetUtils.java b/samples/browseable/RecipeAssistant/Application/src/com.example.android.recipeassistant/AssetUtils.java
new file mode 100644
index 0000000..b9ad8d5
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/src/com.example.android.recipeassistant/AssetUtils.java
@@ -0,0 +1,79 @@
+/*
+ * 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.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/browseable/RecipeAssistant/Application/src/com.example.android.recipeassistant/Constants.java b/samples/browseable/RecipeAssistant/Application/src/com.example.android.recipeassistant/Constants.java
new file mode 100644
index 0000000..e6d367d
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/src/com.example.android.recipeassistant/Constants.java
@@ -0,0 +1,43 @@
+/*
+ * 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.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.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/browseable/RecipeAssistant/Application/src/com.example.android.recipeassistant/MainActivity.java b/samples/browseable/RecipeAssistant/Application/src/com.example.android.recipeassistant/MainActivity.java
new file mode 100644
index 0000000..5738e2a
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/src/com.example.android.recipeassistant/MainActivity.java
@@ -0,0 +1,50 @@
+/*
+ * 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.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/browseable/RecipeAssistant/Application/src/com.example.android.recipeassistant/Recipe.java b/samples/browseable/RecipeAssistant/Application/src/com.example.android.recipeassistant/Recipe.java
new file mode 100644
index 0000000..3551907
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/src/com.example.android.recipeassistant/Recipe.java
@@ -0,0 +1,126 @@
+/*
+ * 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.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<RecipeStep> recipeSteps;
+
+ public Recipe() {
+ recipeSteps = new ArrayList<RecipeStep>();
+ }
+
+ 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<Parcelable> stepBundles = new ArrayList<Parcelable>(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<Parcelable> 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/browseable/RecipeAssistant/Application/src/com.example.android.recipeassistant/RecipeActivity.java b/samples/browseable/RecipeAssistant/Application/src/com.example.android.recipeassistant/RecipeActivity.java
new file mode 100644
index 0000000..4b9d72d
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/src/com.example.android.recipeassistant/RecipeActivity.java
@@ -0,0 +1,138 @@
+/*
+ * 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.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/browseable/RecipeAssistant/Application/src/com.example.android.recipeassistant/RecipeListAdapter.java b/samples/browseable/RecipeAssistant/Application/src/com.example.android.recipeassistant/RecipeListAdapter.java
new file mode 100644
index 0000000..bc602a1
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/src/com.example.android.recipeassistant/RecipeListAdapter.java
@@ -0,0 +1,173 @@
+/*
+ * 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.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<Item> mItems = new ArrayList<Item>();
+ 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<Item> items = parseJson(jsonObject);
+ appendItemsToList(items);
+ }
+ }
+
+ private List<Item> parseJson(JSONObject json) {
+ List<Item> result = new ArrayList<Item>();
+ 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<Item> 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/browseable/RecipeAssistant/Application/src/com.example.android.recipeassistant/RecipeService.java b/samples/browseable/RecipeAssistant/Application/src/com.example.android.recipeassistant/RecipeService.java
new file mode 100644
index 0000000..74bbfda
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Application/src/com.example.android.recipeassistant/RecipeService.java
@@ -0,0 +1,96 @@
+/*
+ * 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.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<Notification> notificationPages = new ArrayList<Notification>();
+
+ 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/browseable/RecipeAssistant/Shared/AndroidManifest.xml b/samples/browseable/RecipeAssistant/Shared/AndroidManifest.xml
new file mode 100644
index 0000000..1951e26
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Shared/AndroidManifest.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.recipeassistant.common">
+
+ <application android:allowBackup="true"
+ android:label="@string/app_name">
+ </application>
+
+</manifest>
diff --git a/samples/browseable/RecipeAssistant/Shared/res/values/strings.xml b/samples/browseable/RecipeAssistant/Shared/res/values/strings.xml
new file mode 100644
index 0000000..0f2bb90
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/Shared/res/values/strings.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<resources>
+ <string name="app_name">Shared</string>
+</resources>
diff --git a/samples/browseable/RecipeAssistant/_index.jd b/samples/browseable/RecipeAssistant/_index.jd
new file mode 100644
index 0000000..0860bce
--- /dev/null
+++ b/samples/browseable/RecipeAssistant/_index.jd
@@ -0,0 +1,14 @@
+page.tags="RecipeAssistant"
+sample.group=Wearable
+@jd:body
+
+<p>
+
+ 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.
+
+ </p>
diff --git a/samples/browseable/SkeletonWearableApp/Application/AndroidManifest.xml b/samples/browseable/SkeletonWearableApp/Application/AndroidManifest.xml
new file mode 100644
index 0000000..7e19680
--- /dev/null
+++ b/samples/browseable/SkeletonWearableApp/Application/AndroidManifest.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.skeletonwearableapp">
+
+ <uses-sdk android:minSdkVersion="19"
+ android:targetSdkVersion="19" />
+
+ <application android:allowBackup="true"
+ android:label="@string/app_name">
+ </application>
+
+</manifest>
+
diff --git a/samples/browseable/SkeletonWearableApp/Application/res/drawable-hdpi/tile.9.png b/samples/browseable/SkeletonWearableApp/Application/res/drawable-hdpi/tile.9.png
new file mode 100644
index 0000000..1358628
--- /dev/null
+++ b/samples/browseable/SkeletonWearableApp/Application/res/drawable-hdpi/tile.9.png
Binary files differ
diff --git a/samples/browseable/SkeletonWearableApp/Application/res/layout/activity_main.xml b/samples/browseable/SkeletonWearableApp/Application/res/layout/activity_main.xml
new file mode 100755
index 0000000..be1aa49
--- /dev/null
+++ b/samples/browseable/SkeletonWearableApp/Application/res/layout/activity_main.xml
@@ -0,0 +1,36 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <LinearLayout style="@style/Widget.SampleMessageTile"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+
+ <TextView style="@style/Widget.SampleMessage"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="@dimen/horizontal_page_margin"
+ android:layout_marginRight="@dimen/horizontal_page_margin"
+ android:layout_marginTop="@dimen/vertical_page_margin"
+ android:layout_marginBottom="@dimen/vertical_page_margin"
+ android:text="@string/intro_message" />
+ </LinearLayout>
+</LinearLayout>
diff --git a/samples/browseable/SkeletonWearableApp/Application/res/values-sw600dp/template-dimens.xml b/samples/browseable/SkeletonWearableApp/Application/res/values-sw600dp/template-dimens.xml
new file mode 100644
index 0000000..22074a2
--- /dev/null
+++ b/samples/browseable/SkeletonWearableApp/Application/res/values-sw600dp/template-dimens.xml
@@ -0,0 +1,24 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Semantic definitions -->
+
+ <dimen name="horizontal_page_margin">@dimen/margin_huge</dimen>
+ <dimen name="vertical_page_margin">@dimen/margin_medium</dimen>
+
+</resources>
diff --git a/samples/browseable/SkeletonWearableApp/Application/res/values-sw600dp/template-styles.xml b/samples/browseable/SkeletonWearableApp/Application/res/values-sw600dp/template-styles.xml
new file mode 100644
index 0000000..03d1974
--- /dev/null
+++ b/samples/browseable/SkeletonWearableApp/Application/res/values-sw600dp/template-styles.xml
@@ -0,0 +1,25 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <style name="Widget.SampleMessage">
+ <item name="android:textAppearance">?android:textAppearanceLarge</item>
+ <item name="android:lineSpacingMultiplier">1.2</item>
+ <item name="android:shadowDy">-6.5</item>
+ </style>
+
+</resources>
diff --git a/samples/browseable/SkeletonWearableApp/Application/res/values-v11/template-styles.xml b/samples/browseable/SkeletonWearableApp/Application/res/values-v11/template-styles.xml
new file mode 100644
index 0000000..8c1ea66
--- /dev/null
+++ b/samples/browseable/SkeletonWearableApp/Application/res/values-v11/template-styles.xml
@@ -0,0 +1,22 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Activity themes -->
+ <style name="Theme.Base" parent="android:Theme.Holo.Light" />
+
+</resources>
diff --git a/samples/browseable/SkeletonWearableApp/Application/res/values/base-strings.xml b/samples/browseable/SkeletonWearableApp/Application/res/values/base-strings.xml
new file mode 100644
index 0000000..6bdffc6
--- /dev/null
+++ b/samples/browseable/SkeletonWearableApp/Application/res/values/base-strings.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 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.
+-->
+<resources>
+ <string name="app_name">SkeletonWearableApp</string>
+ <string name="intro_message">
+ <![CDATA[
+
+
+ This sample is a mostly empty wearable app that implements a fullscreen activity
+ conforming to Android Wear best practices. Included in the sample are examples of GridViewPager,
+ DelayedConfirmationView, and DismissOverlayView. Developers who require a fullscreen activity for
+ their wearable app can use this sample as a starting point.
+
+
+ ]]>
+ </string>
+</resources>
diff --git a/samples/browseable/SkeletonWearableApp/Application/res/values/template-dimens.xml b/samples/browseable/SkeletonWearableApp/Application/res/values/template-dimens.xml
new file mode 100644
index 0000000..39e710b
--- /dev/null
+++ b/samples/browseable/SkeletonWearableApp/Application/res/values/template-dimens.xml
@@ -0,0 +1,32 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Define standard dimensions to comply with Holo-style grids and rhythm. -->
+
+ <dimen name="margin_tiny">4dp</dimen>
+ <dimen name="margin_small">8dp</dimen>
+ <dimen name="margin_medium">16dp</dimen>
+ <dimen name="margin_large">32dp</dimen>
+ <dimen name="margin_huge">64dp</dimen>
+
+ <!-- Semantic definitions -->
+
+ <dimen name="horizontal_page_margin">@dimen/margin_medium</dimen>
+ <dimen name="vertical_page_margin">@dimen/margin_medium</dimen>
+
+</resources>
diff --git a/samples/browseable/SkeletonWearableApp/Application/res/values/template-styles.xml b/samples/browseable/SkeletonWearableApp/Application/res/values/template-styles.xml
new file mode 100644
index 0000000..6e7d593
--- /dev/null
+++ b/samples/browseable/SkeletonWearableApp/Application/res/values/template-styles.xml
@@ -0,0 +1,42 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Activity themes -->
+
+ <style name="Theme.Base" parent="android:Theme.Light" />
+
+ <style name="Theme.Sample" parent="Theme.Base" />
+
+ <style name="AppTheme" parent="Theme.Sample" />
+ <!-- Widget styling -->
+
+ <style name="Widget" />
+
+ <style name="Widget.SampleMessage">
+ <item name="android:textAppearance">?android:textAppearanceMedium</item>
+ <item name="android:lineSpacingMultiplier">1.1</item>
+ </style>
+
+ <style name="Widget.SampleMessageTile">
+ <item name="android:background">@drawable/tile</item>
+ <item name="android:shadowColor">#7F000000</item>
+ <item name="android:shadowDy">-3.5</item>
+ <item name="android:shadowRadius">2</item>
+ </style>
+
+</resources>
diff --git a/samples/browseable/SkeletonWearableApp/Application/src/com.example.android.common/activities/SampleActivityBase.java b/samples/browseable/SkeletonWearableApp/Application/src/com.example.android.common/activities/SampleActivityBase.java
new file mode 100644
index 0000000..3228927
--- /dev/null
+++ b/samples/browseable/SkeletonWearableApp/Application/src/com.example.android.common/activities/SampleActivityBase.java
@@ -0,0 +1,52 @@
+/*
+* Copyright 2013 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.common.activities;
+
+import android.os.Bundle;
+import android.support.v4.app.FragmentActivity;
+
+import com.example.android.common.logger.Log;
+import com.example.android.common.logger.LogWrapper;
+
+/**
+ * Base launcher activity, to handle most of the common plumbing for samples.
+ */
+public class SampleActivityBase extends FragmentActivity {
+
+ public static final String TAG = "SampleActivityBase";
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ initializeLogging();
+ }
+
+ /** Set up targets to receive log data */
+ public void initializeLogging() {
+ // Using Log, front-end to the logging chain, emulates android.util.log method signatures.
+ // Wraps Android's native log framework
+ LogWrapper logWrapper = new LogWrapper();
+ Log.setLogNode(logWrapper);
+
+ Log.i(TAG, "Ready");
+ }
+}
diff --git a/samples/browseable/SkeletonWearableApp/Application/src/com.example.android.common/logger/Log.java b/samples/browseable/SkeletonWearableApp/Application/src/com.example.android.common/logger/Log.java
new file mode 100644
index 0000000..17503c5
--- /dev/null
+++ b/samples/browseable/SkeletonWearableApp/Application/src/com.example.android.common/logger/Log.java
@@ -0,0 +1,236 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+/**
+ * Helper class for a list (or tree) of LoggerNodes.
+ *
+ * <p>When this is set as the head of the list,
+ * an instance of it can function as a drop-in replacement for {@link android.util.Log}.
+ * Most of the methods in this class server only to map a method call in Log to its equivalent
+ * in LogNode.</p>
+ */
+public class Log {
+ // Grabbing the native values from Android's native logging facilities,
+ // to make for easy migration and interop.
+ public static final int NONE = -1;
+ public static final int VERBOSE = android.util.Log.VERBOSE;
+ public static final int DEBUG = android.util.Log.DEBUG;
+ public static final int INFO = android.util.Log.INFO;
+ public static final int WARN = android.util.Log.WARN;
+ public static final int ERROR = android.util.Log.ERROR;
+ public static final int ASSERT = android.util.Log.ASSERT;
+
+ // Stores the beginning of the LogNode topology.
+ private static LogNode mLogNode;
+
+ /**
+ * Returns the next LogNode in the linked list.
+ */
+ public static LogNode getLogNode() {
+ return mLogNode;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to.
+ */
+ public static void setLogNode(LogNode node) {
+ mLogNode = node;
+ }
+
+ /**
+ * Instructs the LogNode to print the log data provided. Other LogNodes can
+ * be chained to the end of the LogNode as desired.
+ *
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void println(int priority, String tag, String msg, Throwable tr) {
+ if (mLogNode != null) {
+ mLogNode.println(priority, tag, msg, tr);
+ }
+ }
+
+ /**
+ * Instructs the LogNode to print the log data provided. Other LogNodes can
+ * be chained to the end of the LogNode as desired.
+ *
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ */
+ public static void println(int priority, String tag, String msg) {
+ println(priority, tag, msg, null);
+ }
+
+ /**
+ * Prints a message at VERBOSE priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void v(String tag, String msg, Throwable tr) {
+ println(VERBOSE, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at VERBOSE priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void v(String tag, String msg) {
+ v(tag, msg, null);
+ }
+
+
+ /**
+ * Prints a message at DEBUG priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void d(String tag, String msg, Throwable tr) {
+ println(DEBUG, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at DEBUG priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void d(String tag, String msg) {
+ d(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at INFO priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void i(String tag, String msg, Throwable tr) {
+ println(INFO, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at INFO priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void i(String tag, String msg) {
+ i(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void w(String tag, String msg, Throwable tr) {
+ println(WARN, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void w(String tag, String msg) {
+ w(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void w(String tag, Throwable tr) {
+ w(tag, null, tr);
+ }
+
+ /**
+ * Prints a message at ERROR priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void e(String tag, String msg, Throwable tr) {
+ println(ERROR, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at ERROR priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void e(String tag, String msg) {
+ e(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void wtf(String tag, String msg, Throwable tr) {
+ println(ASSERT, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void wtf(String tag, String msg) {
+ wtf(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void wtf(String tag, Throwable tr) {
+ wtf(tag, null, tr);
+ }
+}
diff --git a/samples/browseable/SkeletonWearableApp/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/SkeletonWearableApp/Application/src/com.example.android.common/logger/LogFragment.java
new file mode 100644
index 0000000..b302acd
--- /dev/null
+++ b/samples/browseable/SkeletonWearableApp/Application/src/com.example.android.common/logger/LogFragment.java
@@ -0,0 +1,109 @@
+/*
+* Copyright 2013 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.
+*/
+/*
+ * Copyright 2013 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.common.logger;
+
+import android.graphics.Typeface;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ScrollView;
+
+/**
+ * Simple fraggment which contains a LogView and uses is to output log data it receives
+ * through the LogNode interface.
+ */
+public class LogFragment extends Fragment {
+
+ private LogView mLogView;
+ private ScrollView mScrollView;
+
+ public LogFragment() {}
+
+ public View inflateViews() {
+ mScrollView = new ScrollView(getActivity());
+ ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT);
+ mScrollView.setLayoutParams(scrollParams);
+
+ mLogView = new LogView(getActivity());
+ ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams);
+ logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
+ mLogView.setLayoutParams(logParams);
+ mLogView.setClickable(true);
+ mLogView.setFocusable(true);
+ mLogView.setTypeface(Typeface.MONOSPACE);
+
+ // Want to set padding as 16 dips, setPadding takes pixels. Hooray math!
+ int paddingDips = 16;
+ double scale = getResources().getDisplayMetrics().density;
+ int paddingPixels = (int) ((paddingDips * (scale)) + .5);
+ mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels);
+ mLogView.setCompoundDrawablePadding(paddingPixels);
+
+ mLogView.setGravity(Gravity.BOTTOM);
+ mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium);
+
+ mScrollView.addView(mLogView);
+ return mScrollView;
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+
+ View result = inflateViews();
+
+ mLogView.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {}
+
+ @Override
+ public void afterTextChanged(Editable s) {
+ mScrollView.fullScroll(ScrollView.FOCUS_DOWN);
+ }
+ });
+ return result;
+ }
+
+ public LogView getLogView() {
+ return mLogView;
+ }
+}
\ No newline at end of file
diff --git a/samples/browseable/SkeletonWearableApp/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/SkeletonWearableApp/Application/src/com.example.android.common/logger/LogNode.java
new file mode 100644
index 0000000..bc37cab
--- /dev/null
+++ b/samples/browseable/SkeletonWearableApp/Application/src/com.example.android.common/logger/LogNode.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2012 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.common.logger;
+
+/**
+ * Basic interface for a logging system that can output to one or more targets.
+ * Note that in addition to classes that will output these logs in some format,
+ * one can also implement this interface over a filter and insert that in the chain,
+ * such that no targets further down see certain data, or see manipulated forms of the data.
+ * You could, for instance, write a "ToHtmlLoggerNode" that just converted all the log data
+ * it received to HTML and sent it along to the next node in the chain, without printing it
+ * anywhere.
+ */
+public interface LogNode {
+
+ /**
+ * Instructs first LogNode in the list to print the log data provided.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public void println(int priority, String tag, String msg, Throwable tr);
+
+}
diff --git a/samples/browseable/SkeletonWearableApp/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/SkeletonWearableApp/Application/src/com.example.android.common/logger/LogView.java
new file mode 100644
index 0000000..c01542b
--- /dev/null
+++ b/samples/browseable/SkeletonWearableApp/Application/src/com.example.android.common/logger/LogView.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+import android.app.Activity;
+import android.content.Context;
+import android.util.*;
+import android.widget.TextView;
+
+/** Simple TextView which is used to output log data received through the LogNode interface.
+*/
+public class LogView extends TextView implements LogNode {
+
+ public LogView(Context context) {
+ super(context);
+ }
+
+ public LogView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public LogView(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ /**
+ * Formats the log data and prints it out to the LogView.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+
+
+ String priorityStr = null;
+
+ // For the purposes of this View, we want to print the priority as readable text.
+ switch(priority) {
+ case android.util.Log.VERBOSE:
+ priorityStr = "VERBOSE";
+ break;
+ case android.util.Log.DEBUG:
+ priorityStr = "DEBUG";
+ break;
+ case android.util.Log.INFO:
+ priorityStr = "INFO";
+ break;
+ case android.util.Log.WARN:
+ priorityStr = "WARN";
+ break;
+ case android.util.Log.ERROR:
+ priorityStr = "ERROR";
+ break;
+ case android.util.Log.ASSERT:
+ priorityStr = "ASSERT";
+ break;
+ default:
+ break;
+ }
+
+ // Handily, the Log class has a facility for converting a stack trace into a usable string.
+ String exceptionStr = null;
+ if (tr != null) {
+ exceptionStr = android.util.Log.getStackTraceString(tr);
+ }
+
+ // Take the priority, tag, message, and exception, and concatenate as necessary
+ // into one usable line of text.
+ final StringBuilder outputBuilder = new StringBuilder();
+
+ String delimiter = "\t";
+ appendIfNotNull(outputBuilder, priorityStr, delimiter);
+ appendIfNotNull(outputBuilder, tag, delimiter);
+ appendIfNotNull(outputBuilder, msg, delimiter);
+ appendIfNotNull(outputBuilder, exceptionStr, delimiter);
+
+ // In case this was originally called from an AsyncTask or some other off-UI thread,
+ // make sure the update occurs within the UI thread.
+ ((Activity) getContext()).runOnUiThread( (new Thread(new Runnable() {
+ @Override
+ public void run() {
+ // Display the text we just generated within the LogView.
+ appendToLog(outputBuilder.toString());
+ }
+ })));
+
+ if (mNext != null) {
+ mNext.println(priority, tag, msg, tr);
+ }
+ }
+
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+ /** Takes a string and adds to it, with a separator, if the bit to be added isn't null. Since
+ * the logger takes so many arguments that might be null, this method helps cut out some of the
+ * agonizing tedium of writing the same 3 lines over and over.
+ * @param source StringBuilder containing the text to append to.
+ * @param addStr The String to append
+ * @param delimiter The String to separate the source and appended strings. A tab or comma,
+ * for instance.
+ * @return The fully concatenated String as a StringBuilder
+ */
+ private StringBuilder appendIfNotNull(StringBuilder source, String addStr, String delimiter) {
+ if (addStr != null) {
+ if (addStr.length() == 0) {
+ delimiter = "";
+ }
+
+ return source.append(addStr).append(delimiter);
+ }
+ return source;
+ }
+
+ // The next LogNode in the chain.
+ LogNode mNext;
+
+ /** Outputs the string as a new line of log data in the LogView. */
+ public void appendToLog(String s) {
+ append("\n" + s);
+ }
+
+
+}
diff --git a/samples/browseable/SkeletonWearableApp/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/SkeletonWearableApp/Application/src/com.example.android.common/logger/LogWrapper.java
new file mode 100644
index 0000000..16a9e7b
--- /dev/null
+++ b/samples/browseable/SkeletonWearableApp/Application/src/com.example.android.common/logger/LogWrapper.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2012 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.common.logger;
+
+import android.util.Log;
+
+/**
+ * Helper class which wraps Android's native Log utility in the Logger interface. This way
+ * normal DDMS output can be one of the many targets receiving and outputting logs simultaneously.
+ */
+public class LogWrapper implements LogNode {
+
+ // For piping: The next node to receive Log data after this one has done its work.
+ private LogNode mNext;
+
+ /**
+ * Returns the next LogNode in the linked list.
+ */
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to..
+ */
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+ /**
+ * Prints data out to the console using Android's native log mechanism.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+ // There actually are log methods that don't take a msg parameter. For now,
+ // if that's the case, just convert null to the empty string and move on.
+ String useMsg = msg;
+ if (useMsg == null) {
+ useMsg = "";
+ }
+
+ // If an exeption was provided, convert that exception to a usable string and attach
+ // it to the end of the msg method.
+ if (tr != null) {
+ msg += "\n" + Log.getStackTraceString(tr);
+ }
+
+ // This is functionally identical to Log.x(tag, useMsg);
+ // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg)
+ Log.println(priority, tag, useMsg);
+
+ // If this isn't the last node in the chain, move things along.
+ if (mNext != null) {
+ mNext.println(priority, tag, msg, tr);
+ }
+ }
+}
diff --git a/samples/browseable/SkeletonWearableApp/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/SkeletonWearableApp/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java
new file mode 100644
index 0000000..19967dc
--- /dev/null
+++ b/samples/browseable/SkeletonWearableApp/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+/**
+ * Simple {@link LogNode} filter, removes everything except the message.
+ * Useful for situations like on-screen log output where you don't want a lot of metadata displayed,
+ * just easy-to-read message updates as they're happening.
+ */
+public class MessageOnlyLogFilter implements LogNode {
+
+ LogNode mNext;
+
+ /**
+ * Takes the "next" LogNode as a parameter, to simplify chaining.
+ *
+ * @param next The next LogNode in the pipeline.
+ */
+ public MessageOnlyLogFilter(LogNode next) {
+ mNext = next;
+ }
+
+ public MessageOnlyLogFilter() {
+ }
+
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+ if (mNext != null) {
+ getNext().println(Log.NONE, null, msg, null);
+ }
+ }
+
+ /**
+ * Returns the next LogNode in the chain.
+ */
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to..
+ */
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+}
diff --git a/samples/browseable/SkeletonWearableApp/Shared/AndroidManifest.xml b/samples/browseable/SkeletonWearableApp/Shared/AndroidManifest.xml
new file mode 100644
index 0000000..5e29d53
--- /dev/null
+++ b/samples/browseable/SkeletonWearableApp/Shared/AndroidManifest.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.skeletonwearableapp.common">
+
+ <application android:allowBackup="true"
+ android:label="@string/app_name">
+ </application>
+
+</manifest>
diff --git a/samples/browseable/SkeletonWearableApp/Shared/res/values/strings.xml b/samples/browseable/SkeletonWearableApp/Shared/res/values/strings.xml
new file mode 100644
index 0000000..0f2bb90
--- /dev/null
+++ b/samples/browseable/SkeletonWearableApp/Shared/res/values/strings.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<resources>
+ <string name="app_name">Shared</string>
+</resources>
diff --git a/samples/browseable/SkeletonWearableApp/Wearable/AndroidManifest.xml b/samples/browseable/SkeletonWearableApp/Wearable/AndroidManifest.xml
new file mode 100644
index 0000000..3e9310e
--- /dev/null
+++ b/samples/browseable/SkeletonWearableApp/Wearable/AndroidManifest.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.skeletonwearableapp" >
+
+ <uses-sdk android:minSdkVersion="20"
+ android:targetSdkVersion="20" />
+
+ <uses-feature android:name="android.hardware.type.watch" />
+
+ <application
+ android:allowBackup="true"
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name"
+ android:theme="@android:style/Theme.DeviceDefault">
+ <activity
+ android:name=".MainActivity"
+ android:label="@string/app_name">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ <intent-filter>
+ <action android:name="com.google.android.clockwork.example.SKELETON"/>
+ <category android:name="android.intent.category.DEFAULT"/>
+ </intent-filter>
+ </activity>
+ <activity
+ android:name=".GridExampleActivity">
+ <intent-filter>
+ <action android:name="com.example.android.skeletonwearableapp.GRID_ACTIVITY"/>
+ <category android:name="android.intent.category.DEFAULT"/>
+ </intent-filter>
+ </activity>
+ </application>
+
+</manifest>
diff --git a/samples/browseable/SkeletonWearableApp/Wearable/res/drawable-hdpi/ic_launcher.png b/samples/browseable/SkeletonWearableApp/Wearable/res/drawable-hdpi/ic_launcher.png
new file mode 100755
index 0000000..589f229
--- /dev/null
+++ b/samples/browseable/SkeletonWearableApp/Wearable/res/drawable-hdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/SkeletonWearableApp/Wearable/res/drawable-mdpi/ic_launcher.png b/samples/browseable/SkeletonWearableApp/Wearable/res/drawable-mdpi/ic_launcher.png
new file mode 100755
index 0000000..77dd571
--- /dev/null
+++ b/samples/browseable/SkeletonWearableApp/Wearable/res/drawable-mdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/SkeletonWearableApp/Wearable/res/drawable-xhdpi/ic_launcher.png b/samples/browseable/SkeletonWearableApp/Wearable/res/drawable-xhdpi/ic_launcher.png
new file mode 100755
index 0000000..fe34ebe
--- /dev/null
+++ b/samples/browseable/SkeletonWearableApp/Wearable/res/drawable-xhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/SkeletonWearableApp/Wearable/res/drawable-xxhdpi/ic_launcher.png b/samples/browseable/SkeletonWearableApp/Wearable/res/drawable-xxhdpi/ic_launcher.png
new file mode 100755
index 0000000..ab80bcd
--- /dev/null
+++ b/samples/browseable/SkeletonWearableApp/Wearable/res/drawable-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/SkeletonWearableApp/Wearable/res/layout/grid_activity.xml b/samples/browseable/SkeletonWearableApp/Wearable/res/layout/grid_activity.xml
new file mode 100644
index 0000000..c867051
--- /dev/null
+++ b/samples/browseable/SkeletonWearableApp/Wearable/res/layout/grid_activity.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<android.support.wearable.view.GridViewPager
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/fragment_container"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" />
diff --git a/samples/browseable/SkeletonWearableApp/Wearable/res/layout/main_activity.xml b/samples/browseable/SkeletonWearableApp/Wearable/res/layout/main_activity.xml
new file mode 100644
index 0000000..c949e5f
--- /dev/null
+++ b/samples/browseable/SkeletonWearableApp/Wearable/res/layout/main_activity.xml
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<FrameLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <ScrollView
+ android:id="@+id/scroll"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:background="#000000"
+ android:fillViewport="true">
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginBottom="2dp"
+ android:text="@string/main_activity_title_text"
+ android:textSize="36sp"
+ android:textColor="#006600"/>
+
+ <Button
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:onClick="showNotification"
+ android:text="@string/show_notification" />
+
+ <Button
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:onClick="onFinishActivity"
+ android:text="@string/finish_activity" />
+
+ <Button
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:id="@+id/start_timer_button"
+ android:onClick="onStartTimer"
+ android:text="@string/start_timer" />
+
+ <android.support.wearable.view.DelayedConfirmationView
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ android:id="@+id/timer"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:src="@drawable/ic_launcher"
+ app:circle_color="@color/blue"
+ app:circle_padding="@dimen/circle_padding"
+ app:circle_border_width="@dimen/circle_border_normal_width"
+ app:circle_border_color="@color/white"
+ app:circle_radius="@dimen/circle_radius"/>
+
+ </LinearLayout>
+
+ </ScrollView>
+
+ <android.support.wearable.view.DismissOverlayView
+ android:id="@+id/dismiss_overlay"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" />
+
+</FrameLayout>
diff --git a/samples/browseable/SkeletonWearableApp/Wearable/res/values/dimens.xml b/samples/browseable/SkeletonWearableApp/Wearable/res/values/dimens.xml
new file mode 100644
index 0000000..67c9677
--- /dev/null
+++ b/samples/browseable/SkeletonWearableApp/Wearable/res/values/dimens.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+ <dimen name="circle_border_normal_width">10dp</dimen>
+ <dimen name="circle_padding">5dp</dimen>
+ <dimen name="circle_radius">50dp</dimen>
+</resources>
diff --git a/samples/browseable/SkeletonWearableApp/Wearable/res/values/strings.xml b/samples/browseable/SkeletonWearableApp/Wearable/res/values/strings.xml
new file mode 100644
index 0000000..3917d07
--- /dev/null
+++ b/samples/browseable/SkeletonWearableApp/Wearable/res/values/strings.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+
+ <string name="app_name">Skeleton Wearable App</string>
+ <string name="intro_text">Long press to go back home.</string>
+ <string name="main_activity_title_text"> Main Activity </string>
+ <string name="grid_activity_title_text"> Grid Activity </string>
+ <string name="finish_activity"> Finish Activity </string>
+ <string name="start_timer"> Start Timer (5 sec) </string>
+ <string name="show_notification"> Show Notification </string>
+ <string name="notification_title"> Skeleton App Notification </string>
+ <string name="action_launch_activity">Launch Activity</string>
+</resources>
diff --git a/samples/browseable/SkeletonWearableApp/Wearable/src/com.example.android.skeletonwearableapp/GridExampleActivity.java b/samples/browseable/SkeletonWearableApp/Wearable/src/com.example.android.skeletonwearableapp/GridExampleActivity.java
new file mode 100644
index 0000000..c0d0b2b
--- /dev/null
+++ b/samples/browseable/SkeletonWearableApp/Wearable/src/com.example.android.skeletonwearableapp/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.skeletonwearableapp;
+
+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<Point, ImageReference> mBackgrounds = new HashMap<Point, ImageReference>();
+
+ 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/browseable/SkeletonWearableApp/Wearable/src/com.example.android.skeletonwearableapp/MainActivity.java b/samples/browseable/SkeletonWearableApp/Wearable/src/com.example.android.skeletonwearableapp/MainActivity.java
new file mode 100644
index 0000000..b7a91e6
--- /dev/null
+++ b/samples/browseable/SkeletonWearableApp/Wearable/src/com.example.android.skeletonwearableapp/MainActivity.java
@@ -0,0 +1,129 @@
+/*
+ * 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.skeletonwearableapp;
+
+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);
+ }
+ });
+ }
+}
diff --git a/samples/browseable/SkeletonWearableApp/_index.jd b/samples/browseable/SkeletonWearableApp/_index.jd
new file mode 100644
index 0000000..f3ab425
--- /dev/null
+++ b/samples/browseable/SkeletonWearableApp/_index.jd
@@ -0,0 +1,12 @@
+page.tags="SkeletonWearableApp"
+sample.group=Wearable
+@jd:body
+
+<p>
+
+ This sample is a mostly empty wearable app that implements a fullscreen activity
+ conforming to Android Wear best practices. Included in the sample are examples of GridViewPager,
+ DelayedConfirmationView, and DismissOverlayView. Developers who require a fullscreen activity for
+ their wearable app can use this sample as a starting point.
+
+ </p>
diff --git a/samples/browseable/SpeedTracker/Application/AndroidManifest.xml b/samples/browseable/SpeedTracker/Application/AndroidManifest.xml
new file mode 100644
index 0000000..3361a44
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Application/AndroidManifest.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.wearable.speedtracker" >
+
+ <uses-permission android:name="android.permission.INTERNET"/>
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
+ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
+
+ <uses-feature
+ android:glEsVersion="0x00020000" android:required="true"/>
+ <uses-sdk
+ android:minSdkVersion="18"
+ android:targetSdkVersion="19" />
+
+ <application
+ android:name=".PhoneApplication"
+ android:allowBackup="true"
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name"
+ android:theme="@style/AppTheme" >
+ <meta-data
+ android:name="com.google.android.maps.v2.API_KEY"
+ android:value="@string/map_v2_api_key"/>
+ <meta-data android:name="com.google.android.gms.version"
+ android:value="@integer/google_play_services_version"/>
+ <activity
+ android:name=".PhoneMainActivity"
+ android:label="@string/app_name"
+ android:screenOrientation="portrait">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ <service android:name=".db.UpdateService">
+ <intent-filter>
+ <action android:name="com.google.android.gms.wearable.BIND_LISTENER" />
+ </intent-filter>
+ </service>
+ </application>
+
+</manifest>
diff --git a/samples/browseable/SpeedTracker/Application/res/drawable-hdpi/ic_launcher.png b/samples/browseable/SpeedTracker/Application/res/drawable-hdpi/ic_launcher.png
new file mode 100644
index 0000000..2275b45
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Application/res/drawable-hdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/SpeedTracker/Application/res/drawable-hdpi/tile.9.png b/samples/browseable/SpeedTracker/Application/res/drawable-hdpi/tile.9.png
new file mode 100644
index 0000000..1358628
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Application/res/drawable-hdpi/tile.9.png
Binary files differ
diff --git a/samples/browseable/SpeedTracker/Application/res/drawable-mdpi/ic_launcher.png b/samples/browseable/SpeedTracker/Application/res/drawable-mdpi/ic_launcher.png
new file mode 100644
index 0000000..25015af
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Application/res/drawable-mdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/SpeedTracker/Application/res/drawable-xhdpi/ic_launcher.png b/samples/browseable/SpeedTracker/Application/res/drawable-xhdpi/ic_launcher.png
new file mode 100644
index 0000000..8aee870
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Application/res/drawable-xhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/SpeedTracker/Application/res/drawable-xxhdpi/ic_launcher.png b/samples/browseable/SpeedTracker/Application/res/drawable-xxhdpi/ic_launcher.png
new file mode 100644
index 0000000..7008a2f
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Application/res/drawable-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/SpeedTracker/Application/res/drawable-xxxhdpi/ic_launcher.png b/samples/browseable/SpeedTracker/Application/res/drawable-xxxhdpi/ic_launcher.png
new file mode 100644
index 0000000..c31ab73
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Application/res/drawable-xxxhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/SpeedTracker/Application/res/layout/activity_main.xml b/samples/browseable/SpeedTracker/Application/res/layout/activity_main.xml
new file mode 100755
index 0000000..be1aa49
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Application/res/layout/activity_main.xml
@@ -0,0 +1,36 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <LinearLayout style="@style/Widget.SampleMessageTile"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+
+ <TextView style="@style/Widget.SampleMessage"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="@dimen/horizontal_page_margin"
+ android:layout_marginRight="@dimen/horizontal_page_margin"
+ android:layout_marginTop="@dimen/vertical_page_margin"
+ android:layout_marginBottom="@dimen/vertical_page_margin"
+ android:text="@string/intro_message" />
+ </LinearLayout>
+</LinearLayout>
diff --git a/samples/browseable/SpeedTracker/Application/res/layout/main_activity.xml b/samples/browseable/SpeedTracker/Application/res/layout/main_activity.xml
new file mode 100644
index 0000000..a18c644
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Application/res/layout/main_activity.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+
+ <RelativeLayout
+ android:id="@+id/top_container"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content">
+ <Button
+ android:id="@+id/date_picker"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:onClick="onClick"
+ android:layout_centerHorizontal="true"
+ android:text="@string/show_my_track"
+ />
+ <TextView
+ android:id="@+id/selected_date"
+ android:layout_below="@+id/date_picker"
+ android:layout_centerHorizontal="true"
+ android:layout_marginBottom="5dp"
+ android:layout_marginTop="5dp"
+ android:textStyle="italic"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content" />
+ </RelativeLayout>
+
+ <fragment
+ android:id="@+id/map"
+ android:layout_below="@+id/top_container"
+ android:layout_width="fill_parent"
+ android:layout_height="match_parent"
+ android:name="com.google.android.gms.maps.MapFragment"/>
+
+</RelativeLayout>
\ No newline at end of file
diff --git a/samples/browseable/SpeedTracker/Application/res/values-sw600dp/template-dimens.xml b/samples/browseable/SpeedTracker/Application/res/values-sw600dp/template-dimens.xml
new file mode 100644
index 0000000..22074a2
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Application/res/values-sw600dp/template-dimens.xml
@@ -0,0 +1,24 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Semantic definitions -->
+
+ <dimen name="horizontal_page_margin">@dimen/margin_huge</dimen>
+ <dimen name="vertical_page_margin">@dimen/margin_medium</dimen>
+
+</resources>
diff --git a/samples/browseable/SpeedTracker/Application/res/values-sw600dp/template-styles.xml b/samples/browseable/SpeedTracker/Application/res/values-sw600dp/template-styles.xml
new file mode 100644
index 0000000..03d1974
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Application/res/values-sw600dp/template-styles.xml
@@ -0,0 +1,25 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <style name="Widget.SampleMessage">
+ <item name="android:textAppearance">?android:textAppearanceLarge</item>
+ <item name="android:lineSpacingMultiplier">1.2</item>
+ <item name="android:shadowDy">-6.5</item>
+ </style>
+
+</resources>
diff --git a/samples/browseable/SpeedTracker/Application/res/values-v11/template-styles.xml b/samples/browseable/SpeedTracker/Application/res/values-v11/template-styles.xml
new file mode 100644
index 0000000..8c1ea66
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Application/res/values-v11/template-styles.xml
@@ -0,0 +1,22 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Activity themes -->
+ <style name="Theme.Base" parent="android:Theme.Holo.Light" />
+
+</resources>
diff --git a/samples/browseable/SpeedTracker/Application/res/values/base-strings.xml b/samples/browseable/SpeedTracker/Application/res/values/base-strings.xml
new file mode 100644
index 0000000..55a45f3
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Application/res/values/base-strings.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 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.
+-->
+<resources>
+ <string name="app_name">Speed Tracker</string>
+ <string name="intro_message">
+ <![CDATA[
+
+
+This sample uses the FusedLocation APIs of GMS on those
+devices that have a hardware GPS built in. In those cases,
+this sample provides a simple screen that shows the current
+speed of the device on the watch. User can set a speed limit
+and if the speed approaches that limit, it changes the color
+to yellow and if it exceeds the limit, it turns red. User
+can also enable recording of coordinates and when it pairs
+back with the phone, this data will be synced with the phone
+component of the app and user can see a track made of those
+coordinates on a map on the phone.
+
+
+ ]]>
+ </string>
+</resources>
diff --git a/samples/browseable/SpeedTracker/Application/res/values/strings.xml b/samples/browseable/SpeedTracker/Application/res/values/strings.xml
new file mode 100644
index 0000000..cdb6f7c
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Application/res/values/strings.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+
+ <string name="map_v2_api_key">YOUR_MAP_V2_API_KEY</string>
+ <string name="action_settings">Settings</string>
+
+ <string name="showing_for_date">Track for %1$s</string>
+ <string name="no_date">No data for the selected date</string>
+ <string name="show_my_track">Show My Track</string>
+
+</resources>
diff --git a/samples/browseable/SpeedTracker/Application/res/values/template-dimens.xml b/samples/browseable/SpeedTracker/Application/res/values/template-dimens.xml
new file mode 100644
index 0000000..39e710b
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Application/res/values/template-dimens.xml
@@ -0,0 +1,32 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Define standard dimensions to comply with Holo-style grids and rhythm. -->
+
+ <dimen name="margin_tiny">4dp</dimen>
+ <dimen name="margin_small">8dp</dimen>
+ <dimen name="margin_medium">16dp</dimen>
+ <dimen name="margin_large">32dp</dimen>
+ <dimen name="margin_huge">64dp</dimen>
+
+ <!-- Semantic definitions -->
+
+ <dimen name="horizontal_page_margin">@dimen/margin_medium</dimen>
+ <dimen name="vertical_page_margin">@dimen/margin_medium</dimen>
+
+</resources>
diff --git a/samples/browseable/SpeedTracker/Application/res/values/template-styles.xml b/samples/browseable/SpeedTracker/Application/res/values/template-styles.xml
new file mode 100644
index 0000000..6e7d593
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Application/res/values/template-styles.xml
@@ -0,0 +1,42 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Activity themes -->
+
+ <style name="Theme.Base" parent="android:Theme.Light" />
+
+ <style name="Theme.Sample" parent="Theme.Base" />
+
+ <style name="AppTheme" parent="Theme.Sample" />
+ <!-- Widget styling -->
+
+ <style name="Widget" />
+
+ <style name="Widget.SampleMessage">
+ <item name="android:textAppearance">?android:textAppearanceMedium</item>
+ <item name="android:lineSpacingMultiplier">1.1</item>
+ </style>
+
+ <style name="Widget.SampleMessageTile">
+ <item name="android:background">@drawable/tile</item>
+ <item name="android:shadowColor">#7F000000</item>
+ <item name="android:shadowDy">-3.5</item>
+ <item name="android:shadowRadius">2</item>
+ </style>
+
+</resources>
diff --git a/samples/browseable/SpeedTracker/Application/src/com.example.android.common/activities/SampleActivityBase.java b/samples/browseable/SpeedTracker/Application/src/com.example.android.common/activities/SampleActivityBase.java
new file mode 100644
index 0000000..3228927
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Application/src/com.example.android.common/activities/SampleActivityBase.java
@@ -0,0 +1,52 @@
+/*
+* Copyright 2013 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.common.activities;
+
+import android.os.Bundle;
+import android.support.v4.app.FragmentActivity;
+
+import com.example.android.common.logger.Log;
+import com.example.android.common.logger.LogWrapper;
+
+/**
+ * Base launcher activity, to handle most of the common plumbing for samples.
+ */
+public class SampleActivityBase extends FragmentActivity {
+
+ public static final String TAG = "SampleActivityBase";
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ initializeLogging();
+ }
+
+ /** Set up targets to receive log data */
+ public void initializeLogging() {
+ // Using Log, front-end to the logging chain, emulates android.util.log method signatures.
+ // Wraps Android's native log framework
+ LogWrapper logWrapper = new LogWrapper();
+ Log.setLogNode(logWrapper);
+
+ Log.i(TAG, "Ready");
+ }
+}
diff --git a/samples/browseable/SpeedTracker/Application/src/com.example.android.common/logger/Log.java b/samples/browseable/SpeedTracker/Application/src/com.example.android.common/logger/Log.java
new file mode 100644
index 0000000..17503c5
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Application/src/com.example.android.common/logger/Log.java
@@ -0,0 +1,236 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+/**
+ * Helper class for a list (or tree) of LoggerNodes.
+ *
+ * <p>When this is set as the head of the list,
+ * an instance of it can function as a drop-in replacement for {@link android.util.Log}.
+ * Most of the methods in this class server only to map a method call in Log to its equivalent
+ * in LogNode.</p>
+ */
+public class Log {
+ // Grabbing the native values from Android's native logging facilities,
+ // to make for easy migration and interop.
+ public static final int NONE = -1;
+ public static final int VERBOSE = android.util.Log.VERBOSE;
+ public static final int DEBUG = android.util.Log.DEBUG;
+ public static final int INFO = android.util.Log.INFO;
+ public static final int WARN = android.util.Log.WARN;
+ public static final int ERROR = android.util.Log.ERROR;
+ public static final int ASSERT = android.util.Log.ASSERT;
+
+ // Stores the beginning of the LogNode topology.
+ private static LogNode mLogNode;
+
+ /**
+ * Returns the next LogNode in the linked list.
+ */
+ public static LogNode getLogNode() {
+ return mLogNode;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to.
+ */
+ public static void setLogNode(LogNode node) {
+ mLogNode = node;
+ }
+
+ /**
+ * Instructs the LogNode to print the log data provided. Other LogNodes can
+ * be chained to the end of the LogNode as desired.
+ *
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void println(int priority, String tag, String msg, Throwable tr) {
+ if (mLogNode != null) {
+ mLogNode.println(priority, tag, msg, tr);
+ }
+ }
+
+ /**
+ * Instructs the LogNode to print the log data provided. Other LogNodes can
+ * be chained to the end of the LogNode as desired.
+ *
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ */
+ public static void println(int priority, String tag, String msg) {
+ println(priority, tag, msg, null);
+ }
+
+ /**
+ * Prints a message at VERBOSE priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void v(String tag, String msg, Throwable tr) {
+ println(VERBOSE, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at VERBOSE priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void v(String tag, String msg) {
+ v(tag, msg, null);
+ }
+
+
+ /**
+ * Prints a message at DEBUG priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void d(String tag, String msg, Throwable tr) {
+ println(DEBUG, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at DEBUG priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void d(String tag, String msg) {
+ d(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at INFO priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void i(String tag, String msg, Throwable tr) {
+ println(INFO, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at INFO priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void i(String tag, String msg) {
+ i(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void w(String tag, String msg, Throwable tr) {
+ println(WARN, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void w(String tag, String msg) {
+ w(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void w(String tag, Throwable tr) {
+ w(tag, null, tr);
+ }
+
+ /**
+ * Prints a message at ERROR priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void e(String tag, String msg, Throwable tr) {
+ println(ERROR, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at ERROR priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void e(String tag, String msg) {
+ e(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void wtf(String tag, String msg, Throwable tr) {
+ println(ASSERT, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void wtf(String tag, String msg) {
+ wtf(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void wtf(String tag, Throwable tr) {
+ wtf(tag, null, tr);
+ }
+}
diff --git a/samples/browseable/SpeedTracker/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/SpeedTracker/Application/src/com.example.android.common/logger/LogFragment.java
new file mode 100644
index 0000000..b302acd
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Application/src/com.example.android.common/logger/LogFragment.java
@@ -0,0 +1,109 @@
+/*
+* Copyright 2013 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.
+*/
+/*
+ * Copyright 2013 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.common.logger;
+
+import android.graphics.Typeface;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ScrollView;
+
+/**
+ * Simple fraggment which contains a LogView and uses is to output log data it receives
+ * through the LogNode interface.
+ */
+public class LogFragment extends Fragment {
+
+ private LogView mLogView;
+ private ScrollView mScrollView;
+
+ public LogFragment() {}
+
+ public View inflateViews() {
+ mScrollView = new ScrollView(getActivity());
+ ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT);
+ mScrollView.setLayoutParams(scrollParams);
+
+ mLogView = new LogView(getActivity());
+ ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams);
+ logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
+ mLogView.setLayoutParams(logParams);
+ mLogView.setClickable(true);
+ mLogView.setFocusable(true);
+ mLogView.setTypeface(Typeface.MONOSPACE);
+
+ // Want to set padding as 16 dips, setPadding takes pixels. Hooray math!
+ int paddingDips = 16;
+ double scale = getResources().getDisplayMetrics().density;
+ int paddingPixels = (int) ((paddingDips * (scale)) + .5);
+ mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels);
+ mLogView.setCompoundDrawablePadding(paddingPixels);
+
+ mLogView.setGravity(Gravity.BOTTOM);
+ mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium);
+
+ mScrollView.addView(mLogView);
+ return mScrollView;
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+
+ View result = inflateViews();
+
+ mLogView.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {}
+
+ @Override
+ public void afterTextChanged(Editable s) {
+ mScrollView.fullScroll(ScrollView.FOCUS_DOWN);
+ }
+ });
+ return result;
+ }
+
+ public LogView getLogView() {
+ return mLogView;
+ }
+}
\ No newline at end of file
diff --git a/samples/browseable/SpeedTracker/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/SpeedTracker/Application/src/com.example.android.common/logger/LogNode.java
new file mode 100644
index 0000000..bc37cab
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Application/src/com.example.android.common/logger/LogNode.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2012 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.common.logger;
+
+/**
+ * Basic interface for a logging system that can output to one or more targets.
+ * Note that in addition to classes that will output these logs in some format,
+ * one can also implement this interface over a filter and insert that in the chain,
+ * such that no targets further down see certain data, or see manipulated forms of the data.
+ * You could, for instance, write a "ToHtmlLoggerNode" that just converted all the log data
+ * it received to HTML and sent it along to the next node in the chain, without printing it
+ * anywhere.
+ */
+public interface LogNode {
+
+ /**
+ * Instructs first LogNode in the list to print the log data provided.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public void println(int priority, String tag, String msg, Throwable tr);
+
+}
diff --git a/samples/browseable/SpeedTracker/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/SpeedTracker/Application/src/com.example.android.common/logger/LogView.java
new file mode 100644
index 0000000..c01542b
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Application/src/com.example.android.common/logger/LogView.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+import android.app.Activity;
+import android.content.Context;
+import android.util.*;
+import android.widget.TextView;
+
+/** Simple TextView which is used to output log data received through the LogNode interface.
+*/
+public class LogView extends TextView implements LogNode {
+
+ public LogView(Context context) {
+ super(context);
+ }
+
+ public LogView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public LogView(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ /**
+ * Formats the log data and prints it out to the LogView.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+
+
+ String priorityStr = null;
+
+ // For the purposes of this View, we want to print the priority as readable text.
+ switch(priority) {
+ case android.util.Log.VERBOSE:
+ priorityStr = "VERBOSE";
+ break;
+ case android.util.Log.DEBUG:
+ priorityStr = "DEBUG";
+ break;
+ case android.util.Log.INFO:
+ priorityStr = "INFO";
+ break;
+ case android.util.Log.WARN:
+ priorityStr = "WARN";
+ break;
+ case android.util.Log.ERROR:
+ priorityStr = "ERROR";
+ break;
+ case android.util.Log.ASSERT:
+ priorityStr = "ASSERT";
+ break;
+ default:
+ break;
+ }
+
+ // Handily, the Log class has a facility for converting a stack trace into a usable string.
+ String exceptionStr = null;
+ if (tr != null) {
+ exceptionStr = android.util.Log.getStackTraceString(tr);
+ }
+
+ // Take the priority, tag, message, and exception, and concatenate as necessary
+ // into one usable line of text.
+ final StringBuilder outputBuilder = new StringBuilder();
+
+ String delimiter = "\t";
+ appendIfNotNull(outputBuilder, priorityStr, delimiter);
+ appendIfNotNull(outputBuilder, tag, delimiter);
+ appendIfNotNull(outputBuilder, msg, delimiter);
+ appendIfNotNull(outputBuilder, exceptionStr, delimiter);
+
+ // In case this was originally called from an AsyncTask or some other off-UI thread,
+ // make sure the update occurs within the UI thread.
+ ((Activity) getContext()).runOnUiThread( (new Thread(new Runnable() {
+ @Override
+ public void run() {
+ // Display the text we just generated within the LogView.
+ appendToLog(outputBuilder.toString());
+ }
+ })));
+
+ if (mNext != null) {
+ mNext.println(priority, tag, msg, tr);
+ }
+ }
+
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+ /** Takes a string and adds to it, with a separator, if the bit to be added isn't null. Since
+ * the logger takes so many arguments that might be null, this method helps cut out some of the
+ * agonizing tedium of writing the same 3 lines over and over.
+ * @param source StringBuilder containing the text to append to.
+ * @param addStr The String to append
+ * @param delimiter The String to separate the source and appended strings. A tab or comma,
+ * for instance.
+ * @return The fully concatenated String as a StringBuilder
+ */
+ private StringBuilder appendIfNotNull(StringBuilder source, String addStr, String delimiter) {
+ if (addStr != null) {
+ if (addStr.length() == 0) {
+ delimiter = "";
+ }
+
+ return source.append(addStr).append(delimiter);
+ }
+ return source;
+ }
+
+ // The next LogNode in the chain.
+ LogNode mNext;
+
+ /** Outputs the string as a new line of log data in the LogView. */
+ public void appendToLog(String s) {
+ append("\n" + s);
+ }
+
+
+}
diff --git a/samples/browseable/SpeedTracker/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/SpeedTracker/Application/src/com.example.android.common/logger/LogWrapper.java
new file mode 100644
index 0000000..16a9e7b
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Application/src/com.example.android.common/logger/LogWrapper.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2012 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.common.logger;
+
+import android.util.Log;
+
+/**
+ * Helper class which wraps Android's native Log utility in the Logger interface. This way
+ * normal DDMS output can be one of the many targets receiving and outputting logs simultaneously.
+ */
+public class LogWrapper implements LogNode {
+
+ // For piping: The next node to receive Log data after this one has done its work.
+ private LogNode mNext;
+
+ /**
+ * Returns the next LogNode in the linked list.
+ */
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to..
+ */
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+ /**
+ * Prints data out to the console using Android's native log mechanism.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+ // There actually are log methods that don't take a msg parameter. For now,
+ // if that's the case, just convert null to the empty string and move on.
+ String useMsg = msg;
+ if (useMsg == null) {
+ useMsg = "";
+ }
+
+ // If an exeption was provided, convert that exception to a usable string and attach
+ // it to the end of the msg method.
+ if (tr != null) {
+ msg += "\n" + Log.getStackTraceString(tr);
+ }
+
+ // This is functionally identical to Log.x(tag, useMsg);
+ // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg)
+ Log.println(priority, tag, useMsg);
+
+ // If this isn't the last node in the chain, move things along.
+ if (mNext != null) {
+ mNext.println(priority, tag, msg, tr);
+ }
+ }
+}
diff --git a/samples/browseable/SpeedTracker/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/SpeedTracker/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java
new file mode 100644
index 0000000..19967dc
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+/**
+ * Simple {@link LogNode} filter, removes everything except the message.
+ * Useful for situations like on-screen log output where you don't want a lot of metadata displayed,
+ * just easy-to-read message updates as they're happening.
+ */
+public class MessageOnlyLogFilter implements LogNode {
+
+ LogNode mNext;
+
+ /**
+ * Takes the "next" LogNode as a parameter, to simplify chaining.
+ *
+ * @param next The next LogNode in the pipeline.
+ */
+ public MessageOnlyLogFilter(LogNode next) {
+ mNext = next;
+ }
+
+ public MessageOnlyLogFilter() {
+ }
+
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+ if (mNext != null) {
+ getNext().println(Log.NONE, null, msg, null);
+ }
+ }
+
+ /**
+ * Returns the next LogNode in the chain.
+ */
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to..
+ */
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+}
diff --git a/samples/browseable/SpeedTracker/Application/src/com.example.android.wearable.speedtracker/LocationDataManager.java b/samples/browseable/SpeedTracker/Application/src/com.example.android.wearable.speedtracker/LocationDataManager.java
new file mode 100644
index 0000000..9a3bf23
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Application/src/com.example.android.wearable.speedtracker/LocationDataManager.java
@@ -0,0 +1,95 @@
+/*
+ * 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.speedtracker;
+
+import com.example.android.wearable.speedtracker.common.LocationEntry;
+import com.example.android.wearable.speedtracker.common.Utils;
+import com.example.android.wearable.speedtracker.db.LocationDbHelper;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A class that wraps database access and provides a cache for various GPS data.
+ */
+public class LocationDataManager {
+
+ private final Map<String, List<LocationEntry>> mPointsMap =
+ new HashMap<String, List<LocationEntry>>();
+
+ private LocationDbHelper mDbHelper;
+
+ public LocationDataManager(LocationDbHelper dbHelper) {
+ mDbHelper = dbHelper;
+ }
+
+ /**
+ * Returns a list of {@link com.example.android.wearable.speedtracker.common.LocationEntry}
+ * objects for the day that the {@link java.util.Calendar} object points at. Internally it uses
+ * a cache to speed up subsequent calls. If there is no cached value, it gets the result from
+ * the database.
+ */
+ public final List<LocationEntry> getPoints(Calendar calendar) {
+ String day = Utils.getHashedDay(calendar);
+ synchronized (mPointsMap) {
+ if (mPointsMap.get(day) == null) {
+ // there is no cache for this day, so lets get it from DB
+ List<LocationEntry> points = mDbHelper.read(calendar);
+ mPointsMap.put(day, points);
+ }
+ }
+ return mPointsMap.get(day);
+ }
+
+ /**
+ * Clears the data for the day that the {@link java.util.Calendar} object falls on. This method
+ * removes the entries from the database and updates the cache accordingly.
+ */
+ public final int clearPoints(Calendar calendar) {
+ synchronized (mPointsMap) {
+ String day = Utils.getHashedDay(calendar);
+ mPointsMap.remove(day);
+ return mDbHelper.delete(day);
+ }
+ }
+
+ /**
+ * Adds a {@link com.example.android.wearable.speedtracker.common.LocationEntry} point to the
+ * database and cache if it is a new point.
+ */
+ public final void addPoint(LocationEntry entry) {
+ synchronized (mPointsMap) {
+ List<LocationEntry> points = getPoints(entry.calendar);
+ if (points == null || points.isEmpty()) {
+ mDbHelper.insert(entry);
+ if (points == null) {
+ points = new ArrayList<LocationEntry>();
+ }
+ points.add(entry);
+ mPointsMap.put(entry.day, points);
+ } else {
+ if (!points.contains(entry)) {
+ mDbHelper.insert(entry);
+ points.add(entry);
+ }
+ }
+ }
+ }
+}
diff --git a/samples/browseable/SpeedTracker/Application/src/com.example.android.wearable.speedtracker/PhoneApplication.java b/samples/browseable/SpeedTracker/Application/src/com.example.android.wearable.speedtracker/PhoneApplication.java
new file mode 100644
index 0000000..d74d81f
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Application/src/com.example.android.wearable.speedtracker/PhoneApplication.java
@@ -0,0 +1,43 @@
+/*
+ * 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.speedtracker;
+
+import android.app.Application;
+
+import com.example.android.wearable.speedtracker.db.LocationDbHelper;
+
+/**
+ * The {@link android.app.Application} class for the handset app.
+ */
+public class PhoneApplication extends Application {
+
+ private LocationDataManager mDataManager;
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ LocationDbHelper dbHelper = new LocationDbHelper(getApplicationContext());
+ mDataManager = new LocationDataManager(dbHelper);
+ }
+
+ /**
+ * Returns an instance of {@link com.example.android.wearable.speedtracker.LocationDataManager}.
+ */
+ public final LocationDataManager getDataManager() {
+ return mDataManager;
+ }
+}
diff --git a/samples/browseable/SpeedTracker/Application/src/com.example.android.wearable.speedtracker/PhoneMainActivity.java b/samples/browseable/SpeedTracker/Application/src/com.example.android.wearable.speedtracker/PhoneMainActivity.java
new file mode 100644
index 0000000..76f609b
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Application/src/com.example.android.wearable.speedtracker/PhoneMainActivity.java
@@ -0,0 +1,134 @@
+/*
+ * 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.speedtracker;
+
+import com.google.android.gms.maps.CameraUpdateFactory;
+import com.google.android.gms.maps.GoogleMap;
+import com.google.android.gms.maps.MapFragment;
+import com.google.android.gms.maps.model.LatLng;
+import com.google.android.gms.maps.model.LatLngBounds;
+import com.google.android.gms.maps.model.PolylineOptions;
+
+import android.app.Activity;
+import android.app.DatePickerDialog;
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.text.format.DateUtils;
+import android.util.Log;
+import android.view.View;
+import android.widget.DatePicker;
+import android.widget.TextView;
+
+import com.example.android.wearable.speedtracker.common.LocationEntry;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.List;
+
+/**
+ * The main activity for the handset application. When a watch device reconnects to the handset
+ * app, the collected GPS data on the watch, if any, is synced up and user can see his/her track on
+ * a map. This data is then saved into an internal database and the corresponding data items are
+ * deleted.
+ */
+public class PhoneMainActivity extends Activity implements DatePickerDialog.OnDateSetListener {
+
+ private static final String TAG = "PhoneMainActivity";
+ private static final int BOUNDING_BOX_PADDING_PX = 50;
+ private TextView mSelectedDateText;
+ private GoogleMap mMap;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.main_activity);
+ mSelectedDateText = (TextView) findViewById(R.id.selected_date);
+ mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
+ }
+
+ public void onClick(View view) {
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTimeInMillis(System.currentTimeMillis());
+ new DatePickerDialog(PhoneMainActivity.this, PhoneMainActivity.this,
+ calendar.get(Calendar.YEAR),
+ calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)).show();
+ }
+
+ @Override
+ public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
+ // the following if-clause is to get around a bug that causes this callback to be called
+ // twice
+ if (view.isShown()) {
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTimeInMillis(System.currentTimeMillis());
+ calendar.set(Calendar.YEAR, year);
+ calendar.set(Calendar.MONTH, monthOfYear);
+ calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
+ String date = DateUtils.formatDateTime(this, calendar.getTimeInMillis(),
+ DateUtils.FORMAT_SHOW_DATE);
+ mSelectedDateText.setText(getString(R.string.showing_for_date, date));
+ showTrack(calendar);
+ }
+ }
+
+ /**
+ * An {@link android.os.AsyncTask} that is responsible for getting a list of {@link
+ * com.example.android.wearable.speedtracker.common.LocationEntry} objects for a given day and
+ * building a track from those points. In addition, it sets the smallest bounding box for the
+ * map that covers all the points on the track.
+ */
+ private void showTrack(Calendar calendar) {
+ new AsyncTask<Calendar, Void, Void>() {
+
+ private List<LatLng> coordinates;
+ private LatLngBounds bounds;
+
+ @Override
+ protected Void doInBackground(Calendar... params) {
+ LocationDataManager dataManager = ((PhoneApplication) getApplicationContext())
+ .getDataManager();
+ List<LocationEntry> entries = dataManager.getPoints(params[0]);
+ if (entries != null && !entries.isEmpty()) {
+ coordinates = new ArrayList<LatLng>();
+ LatLngBounds.Builder builder = new LatLngBounds.Builder();
+ for (LocationEntry entry : entries) {
+ LatLng latLng = new LatLng(entry.latitude, entry.longitude);
+ builder.include(latLng);
+ coordinates.add(latLng);
+ }
+ bounds = builder.build();
+ }
+ return null;
+ }
+
+ @Override
+ protected void onPostExecute(Void aVoid) {
+ mMap.clear();
+ if (coordinates == null || coordinates.isEmpty()) {
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "No Entries found for that date");
+ }
+ } else {
+ mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds,
+ BOUNDING_BOX_PADDING_PX));
+ mMap.addPolyline(new PolylineOptions().geodesic(true).addAll(coordinates));
+ }
+ }
+
+ }.execute(calendar);
+ }
+}
diff --git a/samples/browseable/SpeedTracker/Application/src/com.example.android.wearable.speedtracker/db/LocationDbHelper.java b/samples/browseable/SpeedTracker/Application/src/com.example.android.wearable.speedtracker/db/LocationDbHelper.java
new file mode 100644
index 0000000..3397eaa
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Application/src/com.example.android.wearable.speedtracker/db/LocationDbHelper.java
@@ -0,0 +1,165 @@
+/*
+ * 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.speedtracker.db;
+
+import android.content.ContentValues;
+import android.content.Context;
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteOpenHelper;
+import android.provider.BaseColumns;
+import android.util.Log;
+
+import com.example.android.wearable.speedtracker.common.LocationEntry;
+import com.example.android.wearable.speedtracker.common.Utils;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.List;
+
+/**
+ * A helper class to set up the database that holds the GPS location information
+ */
+public class LocationDbHelper extends SQLiteOpenHelper {
+
+ private static final String TAG = "LocationDbHelper";
+
+ public static final String TABLE_NAME = "location";
+ public static final String COLUMN_NAME_DAY = "day";
+ public static final String COLUMN_NAME_LATITUDE = "lat";
+ public static final String COLUMN_NAME_LONGITUDE = "lon";
+ public static final String COLUMN_NAME_TIME = "time";
+
+ private static final String TEXT_TYPE = " TEXT";
+ private static final String INTEGER_TYPE = " INTEGER";
+ private static final String REAL_TYPE = " REAL";
+ private static final String COMMA_SEP = ",";
+ private static final String SQL_CREATE_ENTRIES =
+ "CREATE TABLE " + TABLE_NAME + " ("
+ + BaseColumns._ID + " INTEGER PRIMARY KEY,"
+ + COLUMN_NAME_DAY + TEXT_TYPE + COMMA_SEP
+ + COLUMN_NAME_LATITUDE + REAL_TYPE + COMMA_SEP
+ + COLUMN_NAME_LONGITUDE + REAL_TYPE + COMMA_SEP
+ + COLUMN_NAME_TIME + INTEGER_TYPE
+ + " )";
+ private static final String SQL_DELETE_ENTRIES = "DROP TABLE IF EXISTS " + TABLE_NAME;
+
+ public static final int DATABASE_VERSION = 1;
+ public static final String DATABASE_NAME = "Location.db";
+
+ public LocationDbHelper(Context context) {
+ super(context, DATABASE_NAME, null, DATABASE_VERSION);
+ }
+
+ @Override
+ public void onCreate(SQLiteDatabase db) {
+ db.execSQL(SQL_CREATE_ENTRIES);
+ }
+
+ @Override
+ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
+ db.execSQL(SQL_DELETE_ENTRIES);
+ onCreate(db);
+ }
+
+ /**
+ * Inserts a {@link com.example.android.wearable.speedtracker.common.LocationEntry} item to the
+ * database.
+ */
+ public final long insert(LocationEntry entry) {
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "Inserting a LocationEntry");
+ }
+ // Gets the data repository in write mode
+ SQLiteDatabase db = getWritableDatabase();
+
+ // Create a new map of values, where column names are the keys
+ ContentValues values = new ContentValues();
+ values.put(COLUMN_NAME_DAY, entry.day);
+ values.put(COLUMN_NAME_LONGITUDE, entry.longitude);
+ values.put(COLUMN_NAME_LATITUDE, entry.latitude);
+ values.put(COLUMN_NAME_TIME, entry.calendar.getTimeInMillis());
+
+ // Insert the new row, returning the primary key value of the new row
+ return db.insert(TABLE_NAME, "null", values);
+ }
+
+ /**
+ * Returns a list of {@link com.example.android.wearable.speedtracker.common.LocationEntry}
+ * objects from the database for a given day. The list can be empty (but not {@code null}) if
+ * there are no such items. This method looks at the day that the calendar argument points at.
+ */
+ public final List<LocationEntry> read(Calendar calendar) {
+ SQLiteDatabase db = getReadableDatabase();
+ String[] projection = {
+ COLUMN_NAME_LONGITUDE,
+ COLUMN_NAME_LATITUDE,
+ COLUMN_NAME_TIME
+ };
+ String day = Utils.getHashedDay(calendar);
+
+ // sort ASC based on the time of the entry
+ String sortOrder = COLUMN_NAME_TIME + " ASC";
+ String selection = COLUMN_NAME_DAY + " LIKE ?";
+
+ Cursor cursor = db.query(
+ TABLE_NAME, // The table to query
+ projection, // The columns to return
+ selection, // The columns for the WHERE clause
+ new String[]{day}, // The values for the WHERE clause
+ null, // don't group the rows
+ null, // don't filter by row groups
+ sortOrder // The sort order
+ );
+
+ List<LocationEntry> result = new ArrayList<LocationEntry>();
+ int count = cursor.getCount();
+ if (count > 0) {
+ cursor.moveToFirst();
+ while (!cursor.isAfterLast()) {
+ Calendar cal = Calendar.getInstance();
+ cal.setTimeInMillis(cursor.getLong(2));
+ LocationEntry entry = new LocationEntry(cal, cursor.getDouble(1),
+ cursor.getDouble(0));
+ result.add(entry);
+ cursor.moveToNext();
+ }
+ }
+ cursor.close();
+ return result;
+ }
+
+ /**
+ * Deletes all the entries in the database for the given day. The argument {@code day} should
+ * match the format provided by {@link getHashedDay()}
+ */
+ public final int delete(String day) {
+ SQLiteDatabase db = getWritableDatabase();
+ // Define 'where' part of the query.
+ String selection = COLUMN_NAME_DAY + " LIKE ?";
+ String[] selectionArgs = {day};
+ return db.delete(TABLE_NAME, selection, selectionArgs);
+ }
+
+ /**
+ * Deletes all the entries in the database for the day that the {@link java.util.Calendar}
+ * argument points at.
+ */
+ public final int delete(Calendar calendar) {
+ return delete(Utils.getHashedDay(calendar));
+ }
+}
diff --git a/samples/browseable/SpeedTracker/Application/src/com.example.android.wearable.speedtracker/db/UpdateService.java b/samples/browseable/SpeedTracker/Application/src/com.example.android.wearable.speedtracker/db/UpdateService.java
new file mode 100644
index 0000000..8fe5951
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Application/src/com.example.android.wearable.speedtracker/db/UpdateService.java
@@ -0,0 +1,135 @@
+/*
+ * 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.speedtracker.db;
+
+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.DataApi;
+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.DataMapItem;
+import com.google.android.gms.wearable.Wearable;
+import com.google.android.gms.wearable.WearableListenerService;
+
+import android.net.Uri;
+import android.os.Bundle;
+import android.util.Log;
+
+import com.example.android.wearable.speedtracker.LocationDataManager;
+import com.example.android.wearable.speedtracker.PhoneApplication;
+import com.example.android.wearable.speedtracker.common.Constants;
+import com.example.android.wearable.speedtracker.common.LocationEntry;
+
+import java.util.Calendar;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * A {@link com.google.android.gms.wearable.WearableListenerService} that is responsible for
+ * reading location data that gets added to the Data Layer storage.
+ */
+public class UpdateService extends WearableListenerService
+ implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener,
+ ResultCallback<DataApi.DeleteDataItemsResult> {
+
+ private static final String TAG = "UpdateService";
+ private LocationDataManager mDataManager;
+ private GoogleApiClient mGoogleApiClient;
+ private final Set<Uri> mToBeDeletedUris = new HashSet<Uri>();
+ public static final String ACTION_NOTIFY = "com.example.android.wearable.speedtracker.Message";
+ public static final String EXTRA_ENTRY = "entry";
+ public static final String EXTRA_LOG = "log";
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ mGoogleApiClient = new GoogleApiClient.Builder(this)
+ .addApi(Wearable.API)
+ .addConnectionCallbacks(this)
+ .addOnConnectionFailedListener(this)
+ .build();
+ mGoogleApiClient.connect();
+ mDataManager = ((PhoneApplication) getApplicationContext()).getDataManager();
+ }
+
+ @Override
+ public void onDataChanged(DataEventBuffer dataEvents) {
+ for (DataEvent dataEvent : dataEvents) {
+ if (dataEvent.getType() == DataEvent.TYPE_CHANGED) {
+ Uri dataItemUri = dataEvent.getDataItem().getUri();
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "Received a data item with uri: " + dataItemUri.getPath());
+ }
+ if (dataItemUri.getPath().startsWith(Constants.PATH)) {
+ DataMap dataMap = DataMapItem.fromDataItem(dataEvent.getDataItem())
+ .getDataMap();
+ double longitude = dataMap.getDouble(Constants.KEY_LONGITUDE);
+ double latitude = dataMap.getDouble(Constants.KEY_LATITUDE);
+ long time = dataMap.getLong(Constants.KEY_TIME);
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTimeInMillis(time);
+ mDataManager.addPoint(
+ new LocationEntry(calendar, latitude, longitude));
+ if (mGoogleApiClient.isConnected()) {
+ Wearable.DataApi.deleteDataItems(
+ mGoogleApiClient, dataItemUri).setResultCallback(this);
+ } else {
+ synchronized (mToBeDeletedUris) {
+ mToBeDeletedUris.add(dataItemUri);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ @Override // ConnectionCallbacks
+ public void onConnected(Bundle bundle) {
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "onConnected(): api client is connected now");
+ }
+ synchronized (mToBeDeletedUris) {
+ if (!mToBeDeletedUris.isEmpty()) {
+ for (Uri dataItemUri : mToBeDeletedUris) {
+ Wearable.DataApi.deleteDataItems(
+ mGoogleApiClient, dataItemUri).setResultCallback(this);
+ }
+ }
+ }
+ }
+
+ @Override // ConnectionCallbacks
+ public void onConnectionSuspended(int i) {
+ }
+
+ @Override // OnConnectionFailedListener
+ public void onConnectionFailed(ConnectionResult connectionResult) {
+ Log.e(TAG, "Failed to connect to the Google API client");
+ }
+
+ @Override // ResultCallback
+ public void onResult(DataApi.DeleteDataItemsResult deleteDataItemsResult) {
+ if (!deleteDataItemsResult.getStatus().isSuccess()) {
+ Log.e(TAG,
+ "Failed to delete a dataItem, status code: " + deleteDataItemsResult.getStatus()
+ .getStatusCode() + deleteDataItemsResult.getStatus()
+ .getStatusMessage());
+ }
+ }
+}
diff --git a/samples/browseable/SpeedTracker/Shared/AndroidManifest.xml b/samples/browseable/SpeedTracker/Shared/AndroidManifest.xml
new file mode 100644
index 0000000..50d0339
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Shared/AndroidManifest.xml
@@ -0,0 +1,6 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.wearable.speedtracker.common">
+
+ <application android:allowBackup="true"/>
+
+</manifest>
diff --git a/samples/browseable/SpeedTracker/Shared/src/com.example.android.wearable.speedtracker.common/Constants.java b/samples/browseable/SpeedTracker/Shared/src/com.example.android.wearable.speedtracker.common/Constants.java
new file mode 100644
index 0000000..ac761eb
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Shared/src/com.example.android.wearable.speedtracker.common/Constants.java
@@ -0,0 +1,30 @@
+/*
+ * 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.speedtracker.common;
+
+/**
+ * A collection of constants that is shared between teh wearable and handset apps.
+ */
+public class Constants {
+
+ public static final String PATH = "/location";
+ public static final String KEY_LONGITUDE = "lng";
+ public static final String KEY_LATITUDE = "lat";
+ public static final String KEY_TIME = "time";
+
+ private Constants() {}
+}
diff --git a/samples/browseable/SpeedTracker/Shared/src/com.example.android.wearable.speedtracker.common/LocationEntry.java b/samples/browseable/SpeedTracker/Shared/src/com.example.android.wearable.speedtracker.common/LocationEntry.java
new file mode 100644
index 0000000..2a8676a
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Shared/src/com.example.android.wearable.speedtracker.common/LocationEntry.java
@@ -0,0 +1,61 @@
+/*
+ * 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.speedtracker.common;
+
+import java.util.Calendar;
+
+/**
+ * A class that models a GPS location point with additional information about the time that the data
+ * was obtained.
+ */
+public class LocationEntry {
+
+ public double latitude;
+ public double longitude;
+ public Calendar calendar;
+ public String day;
+
+ public LocationEntry(Calendar calendar, double latitude, double longitude) {
+ this.calendar = calendar;
+ this.latitude = latitude;
+ this.longitude = longitude;
+ this.day = Utils.getHashedDay(calendar);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ LocationEntry that = (LocationEntry) o;
+
+ if (calendar.getTimeInMillis() != that.calendar.getTimeInMillis()) {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ return calendar.hashCode();
+ }
+}
\ No newline at end of file
diff --git a/samples/browseable/SpeedTracker/Shared/src/com.example.android.wearable.speedtracker.common/Utils.java b/samples/browseable/SpeedTracker/Shared/src/com.example.android.wearable.speedtracker.common/Utils.java
new file mode 100644
index 0000000..a2f300f
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Shared/src/com.example.android.wearable.speedtracker.common/Utils.java
@@ -0,0 +1,37 @@
+/*
+ * 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.speedtracker.common;
+
+import java.util.Calendar;
+
+/**
+ * A utility class that is used in both the handset and wearable apps.
+ */
+public class Utils {
+
+ /**
+ * Builds a simple hash for a day by concatenating year and day of year together. Note that two
+ * {@link java.util.Calendar} inputs that fall on the same day will be hashed to the same
+ * string.
+ */
+ public static String getHashedDay(Calendar day) {
+ return day.get(Calendar.YEAR) + "-" + day.get(Calendar.DAY_OF_YEAR);
+ }
+
+ private Utils() {
+ }
+}
diff --git a/samples/browseable/SpeedTracker/Wearable/AndroidManifest.xml b/samples/browseable/SpeedTracker/Wearable/AndroidManifest.xml
new file mode 100644
index 0000000..750f052
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Wearable/AndroidManifest.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.wearable.speedtracker">
+
+ <uses-feature android:name="android.hardware.type.watch"/>
+ <uses-feature android:name="android.hardware.location.gps" android:required="true" />
+ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>\
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
+
+ <uses-sdk
+ android:minSdkVersion="20"
+ android:targetSdkVersion="20" />
+
+ <application
+ android:allowBackup="true"
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name"
+ android:theme="@android:style/Theme.DeviceDefault">
+ <meta-data android:name="com.google.android.gms.version"
+ android:value="@integer/google_play_services_version"/>
+ <activity
+ android:name=".WearableMainActivity"
+ android:label="@string/app_name">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ </activity>
+ <activity
+ android:name="com.example.android.wearable.speedtracker.SpeedPickerActivity">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ </intent-filter>
+ </activity>
+ <activity
+ android:name=".ui.LocationSettingActivity">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ </intent-filter>
+ </activity>
+ </application>
+
+</manifest>
diff --git a/samples/browseable/SpeedTracker/Wearable/res/drawable-hdpi/ic_launcher.png b/samples/browseable/SpeedTracker/Wearable/res/drawable-hdpi/ic_launcher.png
new file mode 100644
index 0000000..2275b45
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Wearable/res/drawable-hdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/SpeedTracker/Wearable/res/drawable-mdpi/ic_boot_cancel.png b/samples/browseable/SpeedTracker/Wearable/res/drawable-mdpi/ic_boot_cancel.png
new file mode 100644
index 0000000..9b44979
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Wearable/res/drawable-mdpi/ic_boot_cancel.png
Binary files differ
diff --git a/samples/browseable/SpeedTracker/Wearable/res/drawable-mdpi/ic_launcher.png b/samples/browseable/SpeedTracker/Wearable/res/drawable-mdpi/ic_launcher.png
new file mode 100644
index 0000000..25015af
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Wearable/res/drawable-mdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/SpeedTracker/Wearable/res/drawable-nodpi/dot.png b/samples/browseable/SpeedTracker/Wearable/res/drawable-nodpi/dot.png
new file mode 100644
index 0000000..37cfba6
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Wearable/res/drawable-nodpi/dot.png
Binary files differ
diff --git a/samples/browseable/SpeedTracker/Wearable/res/drawable-xhdpi/ic_cancel_80.png b/samples/browseable/SpeedTracker/Wearable/res/drawable-xhdpi/ic_cancel_80.png
new file mode 100644
index 0000000..46de043
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Wearable/res/drawable-xhdpi/ic_cancel_80.png
Binary files differ
diff --git a/samples/browseable/SpeedTracker/Wearable/res/drawable-xhdpi/ic_confirmation.png b/samples/browseable/SpeedTracker/Wearable/res/drawable-xhdpi/ic_confirmation.png
new file mode 100755
index 0000000..aba4b3e
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Wearable/res/drawable-xhdpi/ic_confirmation.png
Binary files differ
diff --git a/samples/browseable/SpeedTracker/Wearable/res/drawable-xhdpi/ic_confirmation_80.png b/samples/browseable/SpeedTracker/Wearable/res/drawable-xhdpi/ic_confirmation_80.png
new file mode 100644
index 0000000..faeb9e4
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Wearable/res/drawable-xhdpi/ic_confirmation_80.png
Binary files differ
diff --git a/samples/browseable/SpeedTracker/Wearable/res/drawable-xhdpi/ic_launcher.png b/samples/browseable/SpeedTracker/Wearable/res/drawable-xhdpi/ic_launcher.png
new file mode 100644
index 0000000..8aee870
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Wearable/res/drawable-xhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/SpeedTracker/Wearable/res/drawable-xxhdpi/ic_file_download_black_24dp.png b/samples/browseable/SpeedTracker/Wearable/res/drawable-xxhdpi/ic_file_download_black_24dp.png
new file mode 100644
index 0000000..0ec94b2
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Wearable/res/drawable-xxhdpi/ic_file_download_black_24dp.png
Binary files differ
diff --git a/samples/browseable/SpeedTracker/Wearable/res/drawable-xxhdpi/ic_file_download_googblue_24dp.png b/samples/browseable/SpeedTracker/Wearable/res/drawable-xxhdpi/ic_file_download_googblue_24dp.png
new file mode 100644
index 0000000..00b3e05
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Wearable/res/drawable-xxhdpi/ic_file_download_googblue_24dp.png
Binary files differ
diff --git a/samples/browseable/SpeedTracker/Wearable/res/drawable-xxhdpi/ic_file_download_grey600_24dp.png b/samples/browseable/SpeedTracker/Wearable/res/drawable-xxhdpi/ic_file_download_grey600_24dp.png
new file mode 100644
index 0000000..c7e86f9
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Wearable/res/drawable-xxhdpi/ic_file_download_grey600_24dp.png
Binary files differ
diff --git a/samples/browseable/SpeedTracker/Wearable/res/drawable-xxhdpi/ic_file_download_white_24dp.png b/samples/browseable/SpeedTracker/Wearable/res/drawable-xxhdpi/ic_file_download_white_24dp.png
new file mode 100644
index 0000000..a57e72f
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Wearable/res/drawable-xxhdpi/ic_file_download_white_24dp.png
Binary files differ
diff --git a/samples/browseable/SpeedTracker/Wearable/res/drawable-xxhdpi/ic_launcher.png b/samples/browseable/SpeedTracker/Wearable/res/drawable-xxhdpi/ic_launcher.png
new file mode 100644
index 0000000..7008a2f
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Wearable/res/drawable-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/SpeedTracker/Wearable/res/drawable-xxhdpi/ic_settings_black_24dp.png b/samples/browseable/SpeedTracker/Wearable/res/drawable-xxhdpi/ic_settings_black_24dp.png
new file mode 100644
index 0000000..bce161d
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Wearable/res/drawable-xxhdpi/ic_settings_black_24dp.png
Binary files differ
diff --git a/samples/browseable/SpeedTracker/Wearable/res/drawable-xxhdpi/ic_settings_googblue_24dp.png b/samples/browseable/SpeedTracker/Wearable/res/drawable-xxhdpi/ic_settings_googblue_24dp.png
new file mode 100644
index 0000000..c1b1725
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Wearable/res/drawable-xxhdpi/ic_settings_googblue_24dp.png
Binary files differ
diff --git a/samples/browseable/SpeedTracker/Wearable/res/drawable-xxhdpi/ic_settings_grey600_24dp.png b/samples/browseable/SpeedTracker/Wearable/res/drawable-xxhdpi/ic_settings_grey600_24dp.png
new file mode 100644
index 0000000..5eba9e8
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Wearable/res/drawable-xxhdpi/ic_settings_grey600_24dp.png
Binary files differ
diff --git a/samples/browseable/SpeedTracker/Wearable/res/drawable-xxhdpi/ic_settings_white_24dp.png b/samples/browseable/SpeedTracker/Wearable/res/drawable-xxhdpi/ic_settings_white_24dp.png
new file mode 100644
index 0000000..97e9ca9
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Wearable/res/drawable-xxhdpi/ic_settings_white_24dp.png
Binary files differ
diff --git a/samples/browseable/SpeedTracker/Wearable/res/drawable-xxxhdpi/ic_launcher.png b/samples/browseable/SpeedTracker/Wearable/res/drawable-xxxhdpi/ic_launcher.png
new file mode 100644
index 0000000..c31ab73
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Wearable/res/drawable-xxxhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/SpeedTracker/Wearable/res/drawable/settings.xml b/samples/browseable/SpeedTracker/Wearable/res/drawable/settings.xml
new file mode 100644
index 0000000..7af58c6
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Wearable/res/drawable/settings.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:drawable="@drawable/ic_settings_googblue_24dp" android:state_pressed="true" />
+ <item android:drawable="@drawable/ic_settings_grey600_24dp" android:state_focused="true" />
+ <item android:drawable="@drawable/ic_settings_grey600_24dp" />
+</selector>
\ No newline at end of file
diff --git a/samples/browseable/SpeedTracker/Wearable/res/drawable/wl_circle.xml b/samples/browseable/SpeedTracker/Wearable/res/drawable/wl_circle.xml
new file mode 100644
index 0000000..a06c53a
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Wearable/res/drawable/wl_circle.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="oval">
+ <solid android:color="@color/wl_gray"/>
+</shape>
diff --git a/samples/browseable/SpeedTracker/Wearable/res/layout/main_activity.xml b/samples/browseable/SpeedTracker/Wearable/res/layout/main_activity.xml
new file mode 100644
index 0000000..21f809e
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Wearable/res/layout/main_activity.xml
@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="#111">
+
+ <View
+ android:id="@+id/center"
+ android:layout_width="1px"
+ android:layout_height="1px"
+ android:layout_centerInParent="true"/>
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_centerInParent="true"
+ android:fontFamily="sans-serif-light"
+ android:textSize="17sp"
+ android:textStyle="italic"
+ android:id="@+id/acquiring_gps"
+ android:text="@string/acquiring_gps"/>
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceLarge"
+ android:textSize="50sp"
+ android:fontFamily="sans-serif-light"
+ android:id="@+id/current_speed_text"
+ android:layout_centerVertical="true"
+ android:layout_toLeftOf="@+id/center"
+ android:textColor="@color/green"
+ android:layout_marginRight="-10dp"/>
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceLarge"
+ android:textSize="18sp"
+ android:text="@string/mph"
+ android:layout_marginLeft="15dp"
+ android:layout_alignBaseline="@+id/current_speed_text"
+ android:id="@+id/current_speed_mph"
+ android:fontFamily="sans-serif-thin"
+ android:layout_toRightOf="@+id/current_speed_text"/>
+
+ <ImageView
+ android:id="@+id/dot"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_toRightOf="@+id/current_speed_mph"
+ android:layout_centerVertical="true"
+ android:layout_marginLeft="5dp"
+ android:visibility="invisible"
+ android:src="@drawable/dot"/>
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:id="@+id/max_speed_text"
+ android:layout_alignParentTop="true"
+ android:layout_centerHorizontal="true"
+ android:fontFamily="sans-serif-thin"
+ android:textSize="17sp"
+ android:layout_marginTop="33dp" />
+
+ <ImageView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:src="@drawable/ic_file_download_grey600_24dp"
+ android:id="@+id/saving"
+ android:layout_alignParentBottom="true"
+ android:layout_alignParentLeft="true"
+ android:layout_marginBottom="20dp"
+ android:layout_marginLeft="60dp" />
+
+ <ImageButton
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:id="@+id/settings"
+ android:background="@drawable/settings"
+ android:layout_alignParentRight="true"
+ android:layout_alignBottom="@+id/saving"
+ android:layout_marginRight="60dp"/>
+</RelativeLayout>
\ No newline at end of file
diff --git a/samples/browseable/SpeedTracker/Wearable/res/layout/saving_activity.xml b/samples/browseable/SpeedTracker/Wearable/res/layout/saving_activity.xml
new file mode 100644
index 0000000..c37d959
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Wearable/res/layout/saving_activity.xml
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ android:layout_width="match_parent" android:layout_height="match_parent">
+ <View
+ android:id="@+id/center"
+ android:layout_width="0dp"
+ android:layout_height="0dp"
+ android:layout_centerInParent="true"/>
+ <TextView
+ android:id="@+id/textView"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_centerHorizontal="true"
+ android:layout_above="@id/center"
+ android:layout_marginBottom="18dp"
+ android:fontFamily="sans-serif-light"
+ android:textSize="18sp"
+ android:text="@string/start_saving_gps"/>
+ <android.support.wearable.view.CircledImageView
+ android:id="@+id/cancelBtn"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:layout_below="@id/center"
+ android:layout_toLeftOf="@id/center"
+ android:layout_marginEnd="10dp"
+ android:src="@drawable/ic_cancel_80"
+ app:circle_color="@color/grey"
+ android:onClick="onClick"
+ app:circle_padding="@dimen/circle_padding"
+ app:circle_radius="@dimen/circle_radius"
+ app:circle_radius_pressed="@dimen/circle_radius_pressed" />
+ <android.support.wearable.view.CircledImageView
+ android:id="@+id/submitBtn"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:layout_below="@id/center"
+ android:layout_toRightOf="@id/center"
+ android:layout_marginStart="10dp"
+ android:src="@drawable/ic_confirmation_80"
+ app:circle_color="@color/blue"
+ android:onClick="onClick"
+ app:circle_padding="@dimen/circle_padding"
+ app:circle_radius="@dimen/circle_radius"
+ app:circle_radius_pressed="@dimen/circle_radius_pressed" />
+</RelativeLayout>
\ No newline at end of file
diff --git a/samples/browseable/SpeedTracker/Wearable/res/layout/speed_picker_activity.xml b/samples/browseable/SpeedTracker/Wearable/res/layout/speed_picker_activity.xml
new file mode 100644
index 0000000..663988f
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Wearable/res/layout/speed_picker_activity.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<android.support.wearable.view.BoxInsetLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ android:background="@android:color/black"
+ android:layout_height="match_parent"
+ android:layout_width="match_parent"
+ >
+
+ <RelativeLayout
+ android:id="@+id/frame_layout"
+ android:layout_height="match_parent"
+ android:layout_width="match_parent"
+ app:layout_box="left|bottom|right">
+
+
+ <android.support.wearable.view.WearableListView
+ android:id="@+id/wearable_list"
+ android:layout_height="match_parent"
+ android:layout_width="match_parent">
+ </android.support.wearable.view.WearableListView>
+ <TextView
+ android:id="@+id/header"
+ android:layout_width="wrap_content"
+ android:layout_height="60dp"
+ android:gravity="bottom"
+ android:textSize="20sp"
+ android:fontFamily="sans-serif-light"
+ android:layout_centerHorizontal="true"
+ android:layout_alignParentTop="true"
+ android:text="@string/speed_limit_header"/>
+ </RelativeLayout>
+</android.support.wearable.view.BoxInsetLayout>
\ No newline at end of file
diff --git a/samples/browseable/SpeedTracker/Wearable/res/layout/speed_picker_item_layout.xml b/samples/browseable/SpeedTracker/Wearable/res/layout/speed_picker_item_layout.xml
new file mode 100644
index 0000000..7b68908
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Wearable/res/layout/speed_picker_item_layout.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<com.example.android.wearable.speedtracker.ui.SpeedPickerLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:gravity="center_vertical"
+ android:layout_width="match_parent"
+ android:layout_height="80dp">
+ <ImageView
+ android:id="@+id/circle"
+ android:layout_height="20dp"
+ android:layout_margin="16dp"
+ android:layout_width="20dp"
+ android:src="@drawable/wl_circle"/>
+ <TextView
+ android:id="@+id/name"
+ android:gravity="center_vertical|left"
+ android:layout_width="wrap_content"
+ android:layout_marginRight="16dp"
+ android:layout_height="match_parent"
+ android:fontFamily="sans-serif-condensed-light"
+ android:lineSpacingExtra="-4sp"
+ android:textColor="@color/text_color"
+ android:textSize="20sp"/>
+</com.example.android.wearable.speedtracker.ui.SpeedPickerLayout>
\ No newline at end of file
diff --git a/samples/browseable/SpeedTracker/Wearable/res/values/colors.xml b/samples/browseable/SpeedTracker/Wearable/res/values/colors.xml
new file mode 100644
index 0000000..a833064
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Wearable/res/values/colors.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+ <color name="wl_blue">#2878ff</color>
+ <color name="wl_gray">#c1c1c1</color>
+ <color name="text_color">#BBB</color>
+ <color name="yellow">#ced020</color>
+ <color name="speed_below">@color/green</color>
+ <color name="speed_close">@color/yellow</color>
+ <color name="speed_above">@color/red</color>
+
+ <color name="cancel">#c1c1c1</color>
+ <color name="cancel_pressed">#838383</color>
+ <color name="lightblue">#2878ff</color>
+</resources>
\ No newline at end of file
diff --git a/samples/browseable/SpeedTracker/Wearable/res/values/dimens.xml b/samples/browseable/SpeedTracker/Wearable/res/values/dimens.xml
new file mode 100644
index 0000000..2f2eb2a
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Wearable/res/values/dimens.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+ <dimen name="pair_button_diameter">40dp</dimen>
+ <dimen name="circle_border_normal_width">10dp</dimen>
+ <dimen name="circle_padding">5dp</dimen>
+ <dimen name="circle_radius">35dp</dimen>
+ <dimen name="circle_radius_pressed">40dp</dimen>
+</resources>
\ No newline at end of file
diff --git a/samples/browseable/SpeedTracker/Wearable/res/values/integers.xml b/samples/browseable/SpeedTracker/Wearable/res/values/integers.xml
new file mode 100644
index 0000000..b58f083
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Wearable/res/values/integers.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+ <integer name="action_text_faded_alpha">50</integer>
+</resources>
\ No newline at end of file
diff --git a/samples/browseable/SpeedTracker/Wearable/res/values/strings.xml b/samples/browseable/SpeedTracker/Wearable/res/values/strings.xml
new file mode 100644
index 0000000..dda3ecd
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Wearable/res/values/strings.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+ <string name="app_name">Speed Tracker</string>
+ <string name="lat_label">Latitude:</string>
+ <string name="not_available">Not Available</string>
+ <string name="lon_label">Longitude:</string>
+ <string name="speed_label">Speed:</string>
+ <string name="activity_label">Activity:</string>
+ <string name="timestamp_label">Time:</string>
+ <string name="speed_limit">Limit: %1$d mph</string>
+ <string name="acquiring_gps">Acquiring GPS Fix ...</string>
+ <string name="speed_for_list">%1$d mph</string>
+ <string name="start_saving_gps">Start Recording GPS?</string>
+ <string name="stop_saving_gps">Stop Recording GPS?</string>
+ <string name="mph">mph</string>
+ <string name="speed_limit_header">Speed Limit</string>
+ <string name="gps_not_available">GPS not available.</string>
+ <string name="ok">OK</string>
+ <string name="speed_format">%.0f</string>
+</resources>
diff --git a/samples/browseable/SpeedTracker/Wearable/src/com.example.android.wearable.speedtracker/SpeedPickerActivity.java b/samples/browseable/SpeedTracker/Wearable/src/com.example.android.wearable.speedtracker/SpeedPickerActivity.java
new file mode 100644
index 0000000..d55d7df
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Wearable/src/com.example.android.wearable.speedtracker/SpeedPickerActivity.java
@@ -0,0 +1,87 @@
+/*
+ * 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.speedtracker;
+
+import android.app.Activity;
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.preference.PreferenceManager;
+import android.support.wearable.view.WearableListView;
+import android.widget.TextView;
+
+import com.example.android.wearable.speedtracker.ui.SpeedPickerListAdapter;
+
+/**
+ * An activity that presents a list of speeds to user and allows user to pick one, to be used as
+ * the current speed limit.
+ */
+public class SpeedPickerActivity extends Activity implements WearableListView.ClickListener {
+
+ /* Speeds, in mph, that will be shown on the list */
+ private int[] speeds = {25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75};
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.speed_picker_activity);
+
+ final TextView header = (TextView) findViewById(R.id.header);
+
+ // Get the list component from the layout of the activity
+ WearableListView listView = (WearableListView) findViewById(R.id.wearable_list);
+
+ // Assign an adapter to the list
+ listView.setAdapter(new SpeedPickerListAdapter(this, speeds));
+
+ // Set a click listener
+ listView.setClickListener(this);
+
+ listView.addOnScrollListener(new WearableListView.OnScrollListener() {
+ @Override
+ public void onScroll(int i) {
+ }
+
+ @Override
+ public void onAbsoluteScrollChange(int i) {
+ // only scroll the header up from the base position, not down...
+ if (i > 0) {
+ header.setY(-i);
+ }
+ }
+
+ @Override
+ public void onScrollStateChanged(int i) {
+ }
+
+ @Override
+ public void onCentralPositionChanged(int i) {
+ }
+ });
+ }
+
+ @Override
+ public void onClick(WearableListView.ViewHolder viewHolder) {
+ SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
+ pref.edit().putInt(WearableMainActivity.PREFS_SPEED_LIMIT_KEY,
+ speeds[viewHolder.getPosition()]).apply();
+ finish();
+ }
+
+ @Override
+ public void onTopEmptyRegionClick() {
+ }
+}
diff --git a/samples/browseable/SpeedTracker/Wearable/src/com.example.android.wearable.speedtracker/WearableMainActivity.java b/samples/browseable/SpeedTracker/Wearable/src/com.example.android.wearable.speedtracker/WearableMainActivity.java
new file mode 100644
index 0000000..9610f22
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Wearable/src/com.example.android.wearable.speedtracker/WearableMainActivity.java
@@ -0,0 +1,349 @@
+/*
+ * 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.speedtracker;
+
+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.common.api.Status;
+import com.google.android.gms.location.LocationListener;
+import com.google.android.gms.location.LocationRequest;
+import com.google.android.gms.location.LocationServices;
+import com.google.android.gms.wearable.DataApi;
+import com.google.android.gms.wearable.PutDataMapRequest;
+import com.google.android.gms.wearable.PutDataRequest;
+import com.google.android.gms.wearable.Wearable;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.content.pm.PackageManager;
+import android.location.Location;
+import android.os.Bundle;
+import android.os.Handler;
+import android.preference.PreferenceManager;
+import android.util.Log;
+import android.view.View;
+import android.view.WindowManager;
+import android.widget.ImageButton;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import com.example.android.wearable.speedtracker.common.Constants;
+import com.example.android.wearable.speedtracker.common.LocationEntry;
+import com.example.android.wearable.speedtracker.ui.LocationSettingActivity;
+
+import java.util.Calendar;
+
+/**
+ * The main activity for the wearable app. User can pick a speed limit, and after this activity
+ * obtains a fix on the GPS, it starts reporting the speed. In addition to showing the current
+ * speed, if user's speed gets close to the selected speed limit, the color of speed turns yellow
+ * and if the user exceeds the speed limit, it will turn red. In order to show the user that GPS
+ * location data is coming in, a small green dot keeps on blinking while GPS data is available.
+ */
+public class WearableMainActivity extends Activity implements GoogleApiClient.ConnectionCallbacks,
+ GoogleApiClient.OnConnectionFailedListener, LocationListener {
+
+ private static final String TAG = "WearableActivity";
+
+ private static final long UPDATE_INTERVAL_MS = 5 * 1000;
+ private static final long FASTEST_INTERVAL_MS = 5 * 1000;
+
+ public static final float MPH_IN_METERS_PER_SECOND = 2.23694f;
+
+ public static final String PREFS_SPEED_LIMIT_KEY = "speed_limit";
+ public static final int SPEED_LIMIT_DEFAULT_MPH = 45;
+ private static final long INDICATOR_DOT_FADE_AWAY_MS = 500L;
+
+ private GoogleApiClient mGoogleApiClient;
+ private TextView mSpeedLimitText;
+ private TextView mCurrentSpeedText;
+ private ImageView mSaveImageView;
+ private TextView mAcquiringGps;
+ private TextView mCurrentSpeedMphText;
+
+ private int mCurrentSpeedLimit;
+ private float mCurrentSpeed;
+ private View mDot;
+ private Handler mHandler = new Handler();
+ private Calendar mCalendar;
+ private boolean mSaveGpsLocation;
+
+ private enum SpeedState {
+ BELOW(R.color.speed_below), CLOSE(R.color.speed_close), ABOVE(R.color.speed_above);
+
+ private int mColor;
+
+ SpeedState(int color) {
+ mColor = color;
+ }
+
+ int getColor() {
+ return mColor;
+ }
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.main_activity);
+ if (!hasGps()) {
+ // If this hardware doesn't support GPS, we prefer to exit.
+ // Note that when such device is connected to a phone with GPS capabilities, the
+ // framework automatically routes the location requests to the phone. For this
+ // application, this would not be desirable so we exit the app but for some other
+ // applications, that might be a valid scenario.
+ Log.w(TAG, "This hardware doesn't have GPS, so we exit");
+ new AlertDialog.Builder(this)
+ .setMessage(getString(R.string.gps_not_available))
+ .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int id) {
+ finish();
+ dialog.cancel();
+ }
+ })
+ .setOnDismissListener(new DialogInterface.OnDismissListener() {
+ @Override
+ public void onDismiss(DialogInterface dialog) {
+ dialog.cancel();
+ finish();
+ }
+ })
+ .setCancelable(false)
+ .create()
+ .show();
+ }
+
+ setupViews();
+ updateSpeedVisibility(false);
+ setSpeedLimit();
+ mGoogleApiClient = new GoogleApiClient.Builder(this)
+ .addApi(LocationServices.API)
+ .addApi(Wearable.API)
+ .addConnectionCallbacks(this)
+ .addOnConnectionFailedListener(this)
+ .build();
+ mGoogleApiClient.connect();
+ }
+
+ private void setupViews() {
+ mSpeedLimitText = (TextView) findViewById(R.id.max_speed_text);
+ mCurrentSpeedText = (TextView) findViewById(R.id.current_speed_text);
+ mSaveImageView = (ImageView) findViewById(R.id.saving);
+ ImageButton settingButton = (ImageButton) findViewById(R.id.settings);
+ mAcquiringGps = (TextView) findViewById(R.id.acquiring_gps);
+ mCurrentSpeedMphText = (TextView) findViewById(R.id.current_speed_mph);
+ mDot = findViewById(R.id.dot);
+
+ settingButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Intent speedIntent = new Intent(WearableMainActivity.this,
+ SpeedPickerActivity.class);
+ startActivity(speedIntent);
+ }
+ });
+
+ mSaveImageView.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Intent savingIntent = new Intent(WearableMainActivity.this,
+ LocationSettingActivity.class);
+ startActivity(savingIntent);
+ }
+ });
+ }
+
+ private void setSpeedLimit(int speedLimit) {
+ mSpeedLimitText.setText(getString(R.string.speed_limit, speedLimit));
+ }
+
+ private void setSpeedLimit() {
+ SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
+ mCurrentSpeedLimit = pref.getInt(PREFS_SPEED_LIMIT_KEY, SPEED_LIMIT_DEFAULT_MPH);
+ setSpeedLimit(mCurrentSpeedLimit);
+ }
+
+ private void setCurrentSpeed(float speed) {
+ mCurrentSpeed = speed;
+ mCurrentSpeedText.setText(String.format(getString(R.string.speed_format), speed));
+ adjustColor();
+ }
+
+ /**
+ * Adjusts the color of the speed based on its value relative to the speed limit.
+ */
+ private void adjustColor() {
+ SpeedState state = SpeedState.ABOVE;
+ if (mCurrentSpeed <= mCurrentSpeedLimit - 5) {
+ state = SpeedState.BELOW;
+ } else if (mCurrentSpeed <= mCurrentSpeedLimit) {
+ state = SpeedState.CLOSE;
+ }
+
+ mCurrentSpeedText.setTextColor(getResources().getColor(state.getColor()));
+ }
+
+ @Override
+ public void onConnected(Bundle bundle) {
+ LocationRequest locationRequest = LocationRequest.create()
+ .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
+ .setInterval(UPDATE_INTERVAL_MS)
+ .setFastestInterval(FASTEST_INTERVAL_MS);
+
+ LocationServices.FusedLocationApi
+ .requestLocationUpdates(mGoogleApiClient, locationRequest, this)
+ .setResultCallback(new ResultCallback<Status>() {
+
+ @Override
+ public void onResult(Status status) {
+ if (status.getStatus().isSuccess()) {
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "Successfully requested location updates");
+ }
+ } else {
+ Log.e(TAG,
+ "Failed in requesting location updates, "
+ + "status code: "
+ + status.getStatusCode() + ", message: " + status
+ .getStatusMessage());
+ }
+ }
+ });
+ }
+
+ @Override
+ public void onConnectionSuspended(int i) {
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "onConnectionSuspended(): connection to location client suspended");
+ }
+ LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
+ }
+
+ @Override
+ public void onConnectionFailed(ConnectionResult connectionResult) {
+ Log.e(TAG, "onConnectionFailed(): connection to location client failed");
+ }
+
+ @Override
+ public void onLocationChanged(Location location) {
+ updateSpeedVisibility(true);
+ setCurrentSpeed(location.getSpeed() * MPH_IN_METERS_PER_SECOND);
+ flashDot();
+ addLocationEntry(location.getLatitude(), location.getLongitude());
+ }
+
+ /**
+ * Causes the (green) dot blinks when new GPS location data is acquired.
+ */
+ private void flashDot() {
+ mHandler.post(new Runnable() {
+ @Override
+ public void run() {
+ mDot.setVisibility(View.VISIBLE);
+ }
+ });
+ mDot.setVisibility(View.VISIBLE);
+ mHandler.postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ mDot.setVisibility(View.INVISIBLE);
+ }
+ }, INDICATOR_DOT_FADE_AWAY_MS);
+ }
+
+ /**
+ * Adjusts the visibility of speed indicator based on the arrival of GPS data.
+ */
+ private void updateSpeedVisibility(boolean speedVisible) {
+ if (speedVisible) {
+ mAcquiringGps.setVisibility(View.GONE);
+ mCurrentSpeedText.setVisibility(View.VISIBLE);
+ mCurrentSpeedMphText.setVisibility(View.VISIBLE);
+ } else {
+ mAcquiringGps.setVisibility(View.VISIBLE);
+ mCurrentSpeedText.setVisibility(View.GONE);
+ mCurrentSpeedMphText.setVisibility(View.GONE);
+ }
+ }
+
+ /**
+ * Adds a data item to the data Layer storage
+ */
+ private void addLocationEntry(double latitude, double longitude) {
+ if (!mSaveGpsLocation || !mGoogleApiClient.isConnected()) {
+ return;
+ }
+ mCalendar.setTimeInMillis(System.currentTimeMillis());
+ LocationEntry entry = new LocationEntry(mCalendar, latitude, longitude);
+ String path = Constants.PATH + "/" + mCalendar.getTimeInMillis();
+ PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(path);
+ putDataMapRequest.getDataMap().putDouble(Constants.KEY_LATITUDE, entry.latitude);
+ putDataMapRequest.getDataMap().putDouble(Constants.KEY_LONGITUDE, entry.longitude);
+ putDataMapRequest.getDataMap()
+ .putLong(Constants.KEY_TIME, entry.calendar.getTimeInMillis());
+ PutDataRequest request = putDataMapRequest.asPutDataRequest();
+ Wearable.DataApi.putDataItem(mGoogleApiClient, request)
+ .setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
+ @Override
+ public void onResult(DataApi.DataItemResult dataItemResult) {
+ if (!dataItemResult.getStatus().isSuccess()) {
+ Log.e(TAG, "AddPoint:onClick(): Failed to set the data, "
+ + "status: " + dataItemResult.getStatus()
+ .getStatusCode());
+ }
+ }
+ });
+ }
+
+ @Override
+ protected void onStop() {
+ super.onStop();
+ if (mGoogleApiClient.isConnected()) {
+ LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
+ }
+ mGoogleApiClient.disconnect();
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
+ mCalendar = Calendar.getInstance();
+ setSpeedLimit();
+ adjustColor();
+ updateRecordingIcon();
+ }
+
+ private void updateRecordingIcon() {
+ mSaveGpsLocation = LocationSettingActivity.getGpsRecordingStatusFromPreferences(this);
+ mSaveImageView.setImageResource(mSaveGpsLocation ? R.drawable.ic_file_download_googblue_24dp
+ : R.drawable.ic_file_download_grey600_24dp);
+ }
+
+ /**
+ * Returns {@code true} if this device has the GPS capabilities.
+ */
+ private boolean hasGps() {
+ return getPackageManager().hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS);
+ }
+}
diff --git a/samples/browseable/SpeedTracker/Wearable/src/com.example.android.wearable.speedtracker/ui/LocationSettingActivity.java b/samples/browseable/SpeedTracker/Wearable/src/com.example.android.wearable.speedtracker/ui/LocationSettingActivity.java
new file mode 100644
index 0000000..1f8be71
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Wearable/src/com.example.android.wearable.speedtracker/ui/LocationSettingActivity.java
@@ -0,0 +1,75 @@
+/*
+ * 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.speedtracker.ui;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.preference.PreferenceManager;
+import android.view.View;
+import android.widget.TextView;
+
+import com.example.android.wearable.speedtracker.R;
+
+/**
+ * A simple activity that allows the user to start or stop recording of GPS location data.
+ */
+public class LocationSettingActivity extends Activity {
+
+ private static final String PREFS_KEY_SAVE_GPS = "save-gps";
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.saving_activity);
+ TextView textView = (TextView) findViewById(R.id.textView);
+ textView.setText(getGpsRecordingStatusFromPreferences(this) ? R.string.stop_saving_gps
+ : R.string.start_saving_gps);
+
+ }
+
+ public void onClick(View view) {
+ switch (view.getId()) {
+ case R.id.submitBtn:
+ saveGpsRecordingStatusToPreferences(LocationSettingActivity.this,
+ !getGpsRecordingStatusFromPreferences(this));
+ break;
+ case R.id.cancelBtn:
+ break;
+ }
+ finish();
+ }
+
+ /**
+ * Get the persisted value for whether the app should record the GPS location data or not. If
+ * there is no prior value persisted, it returns {@code false}.
+ */
+ public static boolean getGpsRecordingStatusFromPreferences(Context context) {
+ SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
+ return pref.getBoolean(PREFS_KEY_SAVE_GPS, false);
+ }
+
+ /**
+ * Persists the user selection to whether save the GPS location data or not.
+ */
+ public static void saveGpsRecordingStatusToPreferences(Context context, boolean value) {
+ SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
+ pref.edit().putBoolean(PREFS_KEY_SAVE_GPS, value).apply();
+
+ }
+}
diff --git a/samples/browseable/SpeedTracker/Wearable/src/com.example.android.wearable.speedtracker/ui/SpeedPickerLayout.java b/samples/browseable/SpeedTracker/Wearable/src/com.example.android.wearable.speedtracker/ui/SpeedPickerLayout.java
new file mode 100644
index 0000000..9fd882d
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Wearable/src/com.example.android.wearable.speedtracker/ui/SpeedPickerLayout.java
@@ -0,0 +1,104 @@
+/*
+ * 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.speedtracker.ui;
+
+import android.content.Context;
+import android.graphics.drawable.GradientDrawable;
+import android.support.wearable.view.WearableListView;
+import android.util.AttributeSet;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import com.example.android.wearable.speedtracker.R;
+
+/**
+ * A simple extension of the {@link android.widget.LinearLayout} to represent a single item in a
+ * {@link android.support.wearable.view.WearableListView}.
+ */
+public class SpeedPickerLayout extends LinearLayout implements WearableListView.Item {
+
+ private final float mFadedTextAlpha;
+ private final int mFadedCircleColor;
+ private final int mChosenCircleColor;
+ private ImageView mCircle;
+ private float mScale;
+ private TextView mName;
+
+ public SpeedPickerLayout(Context context) {
+ this(context, null);
+ }
+
+ public SpeedPickerLayout(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public SpeedPickerLayout(Context context, AttributeSet attrs,
+ int defStyle) {
+ super(context, attrs, defStyle);
+ mFadedTextAlpha = getResources()
+ .getInteger(R.integer.action_text_faded_alpha) / 100f;
+ mFadedCircleColor = getResources().getColor(R.color.grey);
+ mChosenCircleColor = getResources().getColor(R.color.blue);
+ }
+
+ // Get references to the icon and text in the item layout definiton
+ @Override
+ protected void onFinishInflate() {
+ super.onFinishInflate();
+ mCircle = (ImageView) findViewById(R.id.circle);
+ mName = (TextView) findViewById(R.id.name);
+ }
+
+ // Provide scaling values for WearableListView animations
+ @Override
+ public float getProximityMinValue() {
+ return 1f;
+ }
+
+ @Override
+ public float getProximityMaxValue() {
+ return 1.6f;
+ }
+
+ @Override
+ public float getCurrentProximityValue() {
+ return mScale;
+ }
+
+ // Scale the icon for WearableListView animations
+ @Override
+ public void setScalingAnimatorValue(float scale) {
+ mScale = scale;
+ mCircle.setScaleX(scale);
+ mCircle.setScaleY(scale);
+ }
+
+ // Change color of the icon, remove fading from the text
+ @Override
+ public void onScaleUpStart() {
+ mName.setAlpha(1f);
+ ((GradientDrawable) mCircle.getDrawable()).setColor(mChosenCircleColor);
+ }
+
+ // Change the color of the icon, fade the text
+ @Override
+ public void onScaleDownStart() {
+ ((GradientDrawable) mCircle.getDrawable()).setColor(mFadedCircleColor);
+ mName.setAlpha(mFadedTextAlpha);
+ }
+}
diff --git a/samples/browseable/SpeedTracker/Wearable/src/com.example.android.wearable.speedtracker/ui/SpeedPickerListAdapter.java b/samples/browseable/SpeedTracker/Wearable/src/com.example.android.wearable.speedtracker/ui/SpeedPickerListAdapter.java
new file mode 100644
index 0000000..e3b284b
--- /dev/null
+++ b/samples/browseable/SpeedTracker/Wearable/src/com.example.android.wearable.speedtracker/ui/SpeedPickerListAdapter.java
@@ -0,0 +1,89 @@
+/*
+ * 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.speedtracker.ui;
+
+import android.content.Context;
+import android.support.wearable.view.WearableListView;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+import com.example.android.wearable.speedtracker.R;
+
+/**
+ * A {@link android.support.wearable.view.WearableListView.Adapter} that is used to populate the
+ * list of speeds.
+ */
+public class SpeedPickerListAdapter extends WearableListView.Adapter {
+
+ private int[] mDataSet;
+ private final Context mContext;
+ private final LayoutInflater mInflater;
+
+ public SpeedPickerListAdapter(Context context, int[] dataset) {
+ mContext = context;
+ mInflater = LayoutInflater.from(context);
+ mDataSet = dataset;
+ }
+
+ public static class ItemViewHolder extends WearableListView.ViewHolder {
+
+ private TextView mTextView;
+
+ public ItemViewHolder(View itemView) {
+ super(itemView);
+ // find the text view within the custom item's layout
+ mTextView = (TextView) itemView.findViewById(R.id.name);
+ }
+ }
+
+ /**
+ * Create new views for list items (invoked by the WearableListView's layout manager)
+ */
+ @Override
+ public WearableListView.ViewHolder onCreateViewHolder(ViewGroup parent,
+ int viewType) {
+ // Inflate our custom layout for list items
+ return new ItemViewHolder(mInflater.inflate(R.layout.speed_picker_item_layout, null));
+ }
+
+ /**
+ * Replaces the contents of a list item. Instead of creating new views, the list tries to
+ * recycle existing ones. This is invoked by the WearableListView's layout manager.
+ */
+ @Override
+ public void onBindViewHolder(WearableListView.ViewHolder holder,
+ int position) {
+ // retrieve the text view
+ ItemViewHolder itemHolder = (ItemViewHolder) holder;
+ TextView view = itemHolder.mTextView;
+ // replace text contents
+ view.setText(mContext.getString(R.string.speed_for_list, mDataSet[position]));
+ // replace list item's metadata
+ holder.itemView.setTag(position);
+ }
+
+ /**
+ * Return the size of the data set (invoked by the WearableListView's layout manager).
+ */
+ @Override
+ public int getItemCount() {
+ return mDataSet.length;
+ }
+
+}
diff --git a/samples/browseable/SpeedTracker/_index.jd b/samples/browseable/SpeedTracker/_index.jd
new file mode 100644
index 0000000..f16522b
--- /dev/null
+++ b/samples/browseable/SpeedTracker/_index.jd
@@ -0,0 +1,18 @@
+page.tags="Speed Tracker"
+sample.group=Wearable
+@jd:body
+
+<p>
+
+This sample uses the FusedLocation APIs of GMS on those
+devices that have a hardware GPS built in. In those cases,
+this sample provides a simple screen that shows the current
+speed of the device on the watch. User can set a speed limit
+and if the speed approaches that limit, it changes the color
+to yellow and if it exceeds the limit, it turns red. User
+can also enable recording of coordinates and when it pairs
+back with the phone, this data will be synced with the phone
+component of the app and user can see a track made of those
+coordinates on a map on the phone.
+
+ </p>
diff --git a/samples/browseable/SynchronizedNotifications/Application/AndroidManifest.xml b/samples/browseable/SynchronizedNotifications/Application/AndroidManifest.xml
new file mode 100644
index 0000000..c46f772
--- /dev/null
+++ b/samples/browseable/SynchronizedNotifications/Application/AndroidManifest.xml
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 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.
+-->
+
+
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.synchronizednotifications"
+ android:versionCode="1"
+ android:versionName="1.0">
+
+ <uses-sdk android:minSdkVersion="19"
+ android:targetSdkVersion="19" />
+
+ <application android:allowBackup="true"
+ android:label="@string/app_name"
+ android:icon="@drawable/ic_launcher"
+ android:theme="@style/AppTheme">
+
+ <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
+
+ <activity android:name=".MainActivity"
+ android:label="@string/app_name"
+ android:uiOptions="splitActionBarWhenNarrow">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ <service android:name=".DismissListener">
+ <intent-filter>
+ <action
+ android:name="com.google.android.gms.wearable.BIND_LISTENER" />
+ </intent-filter>
+ <intent-filter>
+ <action
+ android:name="com.example.android.wearable.synchronizednotifications.DISMISS" />
+ </intent-filter>
+ </service>
+ </application>
+
+
+</manifest>
diff --git a/samples/browseable/SynchronizedNotifications/Application/res/drawable-hdpi/ic_launcher.png b/samples/browseable/SynchronizedNotifications/Application/res/drawable-hdpi/ic_launcher.png
new file mode 100644
index 0000000..b1efaf4
--- /dev/null
+++ b/samples/browseable/SynchronizedNotifications/Application/res/drawable-hdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/SynchronizedNotifications/Application/res/drawable-hdpi/tile.9.png b/samples/browseable/SynchronizedNotifications/Application/res/drawable-hdpi/tile.9.png
new file mode 100644
index 0000000..1358628
--- /dev/null
+++ b/samples/browseable/SynchronizedNotifications/Application/res/drawable-hdpi/tile.9.png
Binary files differ
diff --git a/samples/browseable/SynchronizedNotifications/Application/res/drawable-mdpi/ic_launcher.png b/samples/browseable/SynchronizedNotifications/Application/res/drawable-mdpi/ic_launcher.png
new file mode 100644
index 0000000..f5f9244
--- /dev/null
+++ b/samples/browseable/SynchronizedNotifications/Application/res/drawable-mdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/SynchronizedNotifications/Application/res/drawable-xhdpi/ic_launcher.png b/samples/browseable/SynchronizedNotifications/Application/res/drawable-xhdpi/ic_launcher.png
new file mode 100644
index 0000000..5d07b3f
--- /dev/null
+++ b/samples/browseable/SynchronizedNotifications/Application/res/drawable-xhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/SynchronizedNotifications/Application/res/drawable-xxhdpi/ic_launcher.png b/samples/browseable/SynchronizedNotifications/Application/res/drawable-xxhdpi/ic_launcher.png
new file mode 100644
index 0000000..6ef21e1
--- /dev/null
+++ b/samples/browseable/SynchronizedNotifications/Application/res/drawable-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/SynchronizedNotifications/Application/res/layout-sw600dp-land/activity_main.xml b/samples/browseable/SynchronizedNotifications/Application/res/layout-sw600dp-land/activity_main.xml
new file mode 100644
index 0000000..653454b
--- /dev/null
+++ b/samples/browseable/SynchronizedNotifications/Application/res/layout-sw600dp-land/activity_main.xml
@@ -0,0 +1,37 @@
+<!--
+ Copyright 2013 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.
+ -->
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:id="@+id/sample_main_layout">
+ <TextView android:id="@+id/sample_output"
+ style="@style/Widget.SampleMessage"
+ android:background="@android:color/white"
+ android:layout_weight="1"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:text="@string/intro_message"
+ android:layout_margin="16dp" />
+ <fragment
+ android:name="com.example.android.common.logger.LogFragment"
+ android:id="@+id/log_fragment"
+ android:layout_weight="1"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_margin="16dp" />
+</LinearLayout>
diff --git a/samples/browseable/SynchronizedNotifications/Application/res/layout-sw600dp/activity_main.xml b/samples/browseable/SynchronizedNotifications/Application/res/layout-sw600dp/activity_main.xml
new file mode 100644
index 0000000..11cd71b
--- /dev/null
+++ b/samples/browseable/SynchronizedNotifications/Application/res/layout-sw600dp/activity_main.xml
@@ -0,0 +1,36 @@
+<!--
+ Copyright 2013 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.
+ -->
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:id="@+id/sample_main_layout">
+ <TextView android:id="@+id/sample_output"
+ style="@style/Widget.SampleMessage"
+ android:background="@android:color/white"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/intro_message"
+ android:padding="16dp"
+ android:layout_margin="16dp"/>
+ <fragment
+ android:name="com.example.android.common.logger.LogFragment"
+ android:id="@+id/log_fragment"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_margin="16dp" />
+</LinearLayout>
diff --git a/samples/browseable/SynchronizedNotifications/Application/res/layout/activity_main.xml b/samples/browseable/SynchronizedNotifications/Application/res/layout/activity_main.xml
new file mode 100644
index 0000000..6f41369
--- /dev/null
+++ b/samples/browseable/SynchronizedNotifications/Application/res/layout/activity_main.xml
@@ -0,0 +1,39 @@
+<!--
+ Copyright 2013 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.
+ -->
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:id="@+id/sample_main_layout">
+ <TextView android:id="@+id/sample_output"
+ style="@style/Widget.SampleMessage"
+ android:layout_weight="1"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:text="@string/intro_message"
+ android:padding="16dp" />
+ <View
+ android:layout_width="fill_parent"
+ android:layout_height="1dp"
+ android:background="@android:color/darker_gray"/>
+ <fragment
+ android:name="com.example.android.common.logger.LogFragment"
+ android:id="@+id/log_fragment"
+ android:layout_weight="1"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" />
+</LinearLayout>
diff --git a/samples/browseable/SynchronizedNotifications/Application/res/menu/main.xml b/samples/browseable/SynchronizedNotifications/Application/res/menu/main.xml
new file mode 100644
index 0000000..165c0a8
--- /dev/null
+++ b/samples/browseable/SynchronizedNotifications/Application/res/menu/main.xml
@@ -0,0 +1,30 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:id="@+id/btn_phone_only"
+ android:showAsAction="always"
+ android:title="@string/phone_only" />
+
+ <item android:id="@+id/btn_wear_only"
+ android:showAsAction="always"
+ android:title="@string/wear_only" />
+
+ <item android:id="@+id/btn_different"
+ android:showAsAction="always"
+ android:title="@string/different_notifications" />
+
+</menu>
diff --git a/samples/browseable/SynchronizedNotifications/Application/res/values-sw600dp/template-dimens.xml b/samples/browseable/SynchronizedNotifications/Application/res/values-sw600dp/template-dimens.xml
new file mode 100644
index 0000000..22074a2
--- /dev/null
+++ b/samples/browseable/SynchronizedNotifications/Application/res/values-sw600dp/template-dimens.xml
@@ -0,0 +1,24 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Semantic definitions -->
+
+ <dimen name="horizontal_page_margin">@dimen/margin_huge</dimen>
+ <dimen name="vertical_page_margin">@dimen/margin_medium</dimen>
+
+</resources>
diff --git a/samples/browseable/SynchronizedNotifications/Application/res/values-sw600dp/template-styles.xml b/samples/browseable/SynchronizedNotifications/Application/res/values-sw600dp/template-styles.xml
new file mode 100644
index 0000000..03d1974
--- /dev/null
+++ b/samples/browseable/SynchronizedNotifications/Application/res/values-sw600dp/template-styles.xml
@@ -0,0 +1,25 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <style name="Widget.SampleMessage">
+ <item name="android:textAppearance">?android:textAppearanceLarge</item>
+ <item name="android:lineSpacingMultiplier">1.2</item>
+ <item name="android:shadowDy">-6.5</item>
+ </style>
+
+</resources>
diff --git a/samples/browseable/SynchronizedNotifications/Application/res/values-v11/template-styles.xml b/samples/browseable/SynchronizedNotifications/Application/res/values-v11/template-styles.xml
new file mode 100644
index 0000000..8c1ea66
--- /dev/null
+++ b/samples/browseable/SynchronizedNotifications/Application/res/values-v11/template-styles.xml
@@ -0,0 +1,22 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Activity themes -->
+ <style name="Theme.Base" parent="android:Theme.Holo.Light" />
+
+</resources>
diff --git a/samples/browseable/SynchronizedNotifications/Application/res/values/base-strings.xml b/samples/browseable/SynchronizedNotifications/Application/res/values/base-strings.xml
new file mode 100644
index 0000000..8b6d8ff
--- /dev/null
+++ b/samples/browseable/SynchronizedNotifications/Application/res/values/base-strings.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 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.
+-->
+<resources>
+ <string name="app_name">SynchronizedNotifications</string>
+ <string name="intro_message">
+ <![CDATA[
+
+
+ This sample creates simple or synchronized notifications on a
+ device and an Android Wear watch.
+
+
+ ]]>
+ </string>
+</resources>
diff --git a/samples/browseable/SynchronizedNotifications/Application/res/values/dimens.xml b/samples/browseable/SynchronizedNotifications/Application/res/values/dimens.xml
new file mode 100644
index 0000000..a1e9cfe
--- /dev/null
+++ b/samples/browseable/SynchronizedNotifications/Application/res/values/dimens.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+ <!-- Default screen margins, per the Android Design guidelines. -->
+ <dimen name="activity_horizontal_margin">16dp</dimen>
+ <dimen name="activity_vertical_margin">16dp</dimen>
+</resources>
diff --git a/samples/browseable/SynchronizedNotifications/Application/res/values/sample-strings.xml b/samples/browseable/SynchronizedNotifications/Application/res/values/sample-strings.xml
new file mode 100644
index 0000000..8ac6bf2
--- /dev/null
+++ b/samples/browseable/SynchronizedNotifications/Application/res/values/sample-strings.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+
+ <string name="wear_only">Watch Only</string>
+ <string name="phone_only">Phone Only</string>
+ <string name="different_notifications">Both</string>
+ <string name="phone_both">Phone Notification</string>
+ <string name="watch_both">Watch Notification</string>
+
+</resources>
diff --git a/samples/browseable/SynchronizedNotifications/Application/res/values/template-dimens.xml b/samples/browseable/SynchronizedNotifications/Application/res/values/template-dimens.xml
new file mode 100644
index 0000000..39e710b
--- /dev/null
+++ b/samples/browseable/SynchronizedNotifications/Application/res/values/template-dimens.xml
@@ -0,0 +1,32 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Define standard dimensions to comply with Holo-style grids and rhythm. -->
+
+ <dimen name="margin_tiny">4dp</dimen>
+ <dimen name="margin_small">8dp</dimen>
+ <dimen name="margin_medium">16dp</dimen>
+ <dimen name="margin_large">32dp</dimen>
+ <dimen name="margin_huge">64dp</dimen>
+
+ <!-- Semantic definitions -->
+
+ <dimen name="horizontal_page_margin">@dimen/margin_medium</dimen>
+ <dimen name="vertical_page_margin">@dimen/margin_medium</dimen>
+
+</resources>
diff --git a/samples/browseable/SynchronizedNotifications/Application/res/values/template-styles.xml b/samples/browseable/SynchronizedNotifications/Application/res/values/template-styles.xml
new file mode 100644
index 0000000..cfffcbd
--- /dev/null
+++ b/samples/browseable/SynchronizedNotifications/Application/res/values/template-styles.xml
@@ -0,0 +1,54 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Activity themes -->
+
+ <style name="Theme.Base" parent="android:Theme.Holo.Light" />
+
+ <style name="AppTheme" parent="Theme.Base" />
+ <!-- Widget styling -->
+
+ <style name="Widget" />
+
+ <style name="Widget.SampleMessage">
+ <item name="android:padding">@dimen/margin_medium</item>
+ <item name="android:textAppearance">?android:textAppearanceMedium</item>
+ <item name="android:lineSpacingMultiplier">1.1</item>
+ <item name="android:layout_margin">16dp</item>
+ <item name="android:shadowDy">-6.5</item>
+ </style>
+
+ <style name="Widget.SampleMessageTile">
+ <item name="android:background">@drawable/tile</item>
+ <item name="android:shadowColor">#7F000000</item>
+ <item name="android:shadowDy">-3.5</item>
+ <item name="android:shadowRadius">2</item>
+ </style>
+
+
+ <style name="Widget.SampleOutput">
+ <item name="android:padding">@dimen/margin_medium</item>
+ <item name="android:textAppearance">?android:textAppearanceMedium</item>
+ <item name="android:lineSpacingMultiplier">1.1</item>
+ </style>
+
+ <style name="Log" parent="Widget.SampleOutput">
+ <item name="android:typeface">monospace</item>
+ </style>
+
+</resources>
diff --git a/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.common/activities/SampleActivityBase.java b/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.common/activities/SampleActivityBase.java
new file mode 100644
index 0000000..3228927
--- /dev/null
+++ b/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.common/activities/SampleActivityBase.java
@@ -0,0 +1,52 @@
+/*
+* Copyright 2013 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.common.activities;
+
+import android.os.Bundle;
+import android.support.v4.app.FragmentActivity;
+
+import com.example.android.common.logger.Log;
+import com.example.android.common.logger.LogWrapper;
+
+/**
+ * Base launcher activity, to handle most of the common plumbing for samples.
+ */
+public class SampleActivityBase extends FragmentActivity {
+
+ public static final String TAG = "SampleActivityBase";
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ initializeLogging();
+ }
+
+ /** Set up targets to receive log data */
+ public void initializeLogging() {
+ // Using Log, front-end to the logging chain, emulates android.util.log method signatures.
+ // Wraps Android's native log framework
+ LogWrapper logWrapper = new LogWrapper();
+ Log.setLogNode(logWrapper);
+
+ Log.i(TAG, "Ready");
+ }
+}
diff --git a/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.common/logger/Log.java b/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.common/logger/Log.java
new file mode 100644
index 0000000..17503c5
--- /dev/null
+++ b/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.common/logger/Log.java
@@ -0,0 +1,236 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+/**
+ * Helper class for a list (or tree) of LoggerNodes.
+ *
+ * <p>When this is set as the head of the list,
+ * an instance of it can function as a drop-in replacement for {@link android.util.Log}.
+ * Most of the methods in this class server only to map a method call in Log to its equivalent
+ * in LogNode.</p>
+ */
+public class Log {
+ // Grabbing the native values from Android's native logging facilities,
+ // to make for easy migration and interop.
+ public static final int NONE = -1;
+ public static final int VERBOSE = android.util.Log.VERBOSE;
+ public static final int DEBUG = android.util.Log.DEBUG;
+ public static final int INFO = android.util.Log.INFO;
+ public static final int WARN = android.util.Log.WARN;
+ public static final int ERROR = android.util.Log.ERROR;
+ public static final int ASSERT = android.util.Log.ASSERT;
+
+ // Stores the beginning of the LogNode topology.
+ private static LogNode mLogNode;
+
+ /**
+ * Returns the next LogNode in the linked list.
+ */
+ public static LogNode getLogNode() {
+ return mLogNode;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to.
+ */
+ public static void setLogNode(LogNode node) {
+ mLogNode = node;
+ }
+
+ /**
+ * Instructs the LogNode to print the log data provided. Other LogNodes can
+ * be chained to the end of the LogNode as desired.
+ *
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void println(int priority, String tag, String msg, Throwable tr) {
+ if (mLogNode != null) {
+ mLogNode.println(priority, tag, msg, tr);
+ }
+ }
+
+ /**
+ * Instructs the LogNode to print the log data provided. Other LogNodes can
+ * be chained to the end of the LogNode as desired.
+ *
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ */
+ public static void println(int priority, String tag, String msg) {
+ println(priority, tag, msg, null);
+ }
+
+ /**
+ * Prints a message at VERBOSE priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void v(String tag, String msg, Throwable tr) {
+ println(VERBOSE, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at VERBOSE priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void v(String tag, String msg) {
+ v(tag, msg, null);
+ }
+
+
+ /**
+ * Prints a message at DEBUG priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void d(String tag, String msg, Throwable tr) {
+ println(DEBUG, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at DEBUG priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void d(String tag, String msg) {
+ d(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at INFO priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void i(String tag, String msg, Throwable tr) {
+ println(INFO, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at INFO priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void i(String tag, String msg) {
+ i(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void w(String tag, String msg, Throwable tr) {
+ println(WARN, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void w(String tag, String msg) {
+ w(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void w(String tag, Throwable tr) {
+ w(tag, null, tr);
+ }
+
+ /**
+ * Prints a message at ERROR priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void e(String tag, String msg, Throwable tr) {
+ println(ERROR, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at ERROR priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void e(String tag, String msg) {
+ e(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void wtf(String tag, String msg, Throwable tr) {
+ println(ASSERT, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void wtf(String tag, String msg) {
+ wtf(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void wtf(String tag, Throwable tr) {
+ wtf(tag, null, tr);
+ }
+}
diff --git a/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.common/logger/LogFragment.java
new file mode 100644
index 0000000..b302acd
--- /dev/null
+++ b/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.common/logger/LogFragment.java
@@ -0,0 +1,109 @@
+/*
+* Copyright 2013 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.
+*/
+/*
+ * Copyright 2013 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.common.logger;
+
+import android.graphics.Typeface;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ScrollView;
+
+/**
+ * Simple fraggment which contains a LogView and uses is to output log data it receives
+ * through the LogNode interface.
+ */
+public class LogFragment extends Fragment {
+
+ private LogView mLogView;
+ private ScrollView mScrollView;
+
+ public LogFragment() {}
+
+ public View inflateViews() {
+ mScrollView = new ScrollView(getActivity());
+ ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT);
+ mScrollView.setLayoutParams(scrollParams);
+
+ mLogView = new LogView(getActivity());
+ ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams);
+ logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
+ mLogView.setLayoutParams(logParams);
+ mLogView.setClickable(true);
+ mLogView.setFocusable(true);
+ mLogView.setTypeface(Typeface.MONOSPACE);
+
+ // Want to set padding as 16 dips, setPadding takes pixels. Hooray math!
+ int paddingDips = 16;
+ double scale = getResources().getDisplayMetrics().density;
+ int paddingPixels = (int) ((paddingDips * (scale)) + .5);
+ mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels);
+ mLogView.setCompoundDrawablePadding(paddingPixels);
+
+ mLogView.setGravity(Gravity.BOTTOM);
+ mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium);
+
+ mScrollView.addView(mLogView);
+ return mScrollView;
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+
+ View result = inflateViews();
+
+ mLogView.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {}
+
+ @Override
+ public void afterTextChanged(Editable s) {
+ mScrollView.fullScroll(ScrollView.FOCUS_DOWN);
+ }
+ });
+ return result;
+ }
+
+ public LogView getLogView() {
+ return mLogView;
+ }
+}
\ No newline at end of file
diff --git a/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.common/logger/LogNode.java
new file mode 100644
index 0000000..bc37cab
--- /dev/null
+++ b/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.common/logger/LogNode.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2012 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.common.logger;
+
+/**
+ * Basic interface for a logging system that can output to one or more targets.
+ * Note that in addition to classes that will output these logs in some format,
+ * one can also implement this interface over a filter and insert that in the chain,
+ * such that no targets further down see certain data, or see manipulated forms of the data.
+ * You could, for instance, write a "ToHtmlLoggerNode" that just converted all the log data
+ * it received to HTML and sent it along to the next node in the chain, without printing it
+ * anywhere.
+ */
+public interface LogNode {
+
+ /**
+ * Instructs first LogNode in the list to print the log data provided.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public void println(int priority, String tag, String msg, Throwable tr);
+
+}
diff --git a/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.common/logger/LogView.java
new file mode 100644
index 0000000..c01542b
--- /dev/null
+++ b/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.common/logger/LogView.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+import android.app.Activity;
+import android.content.Context;
+import android.util.*;
+import android.widget.TextView;
+
+/** Simple TextView which is used to output log data received through the LogNode interface.
+*/
+public class LogView extends TextView implements LogNode {
+
+ public LogView(Context context) {
+ super(context);
+ }
+
+ public LogView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public LogView(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ /**
+ * Formats the log data and prints it out to the LogView.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+
+
+ String priorityStr = null;
+
+ // For the purposes of this View, we want to print the priority as readable text.
+ switch(priority) {
+ case android.util.Log.VERBOSE:
+ priorityStr = "VERBOSE";
+ break;
+ case android.util.Log.DEBUG:
+ priorityStr = "DEBUG";
+ break;
+ case android.util.Log.INFO:
+ priorityStr = "INFO";
+ break;
+ case android.util.Log.WARN:
+ priorityStr = "WARN";
+ break;
+ case android.util.Log.ERROR:
+ priorityStr = "ERROR";
+ break;
+ case android.util.Log.ASSERT:
+ priorityStr = "ASSERT";
+ break;
+ default:
+ break;
+ }
+
+ // Handily, the Log class has a facility for converting a stack trace into a usable string.
+ String exceptionStr = null;
+ if (tr != null) {
+ exceptionStr = android.util.Log.getStackTraceString(tr);
+ }
+
+ // Take the priority, tag, message, and exception, and concatenate as necessary
+ // into one usable line of text.
+ final StringBuilder outputBuilder = new StringBuilder();
+
+ String delimiter = "\t";
+ appendIfNotNull(outputBuilder, priorityStr, delimiter);
+ appendIfNotNull(outputBuilder, tag, delimiter);
+ appendIfNotNull(outputBuilder, msg, delimiter);
+ appendIfNotNull(outputBuilder, exceptionStr, delimiter);
+
+ // In case this was originally called from an AsyncTask or some other off-UI thread,
+ // make sure the update occurs within the UI thread.
+ ((Activity) getContext()).runOnUiThread( (new Thread(new Runnable() {
+ @Override
+ public void run() {
+ // Display the text we just generated within the LogView.
+ appendToLog(outputBuilder.toString());
+ }
+ })));
+
+ if (mNext != null) {
+ mNext.println(priority, tag, msg, tr);
+ }
+ }
+
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+ /** Takes a string and adds to it, with a separator, if the bit to be added isn't null. Since
+ * the logger takes so many arguments that might be null, this method helps cut out some of the
+ * agonizing tedium of writing the same 3 lines over and over.
+ * @param source StringBuilder containing the text to append to.
+ * @param addStr The String to append
+ * @param delimiter The String to separate the source and appended strings. A tab or comma,
+ * for instance.
+ * @return The fully concatenated String as a StringBuilder
+ */
+ private StringBuilder appendIfNotNull(StringBuilder source, String addStr, String delimiter) {
+ if (addStr != null) {
+ if (addStr.length() == 0) {
+ delimiter = "";
+ }
+
+ return source.append(addStr).append(delimiter);
+ }
+ return source;
+ }
+
+ // The next LogNode in the chain.
+ LogNode mNext;
+
+ /** Outputs the string as a new line of log data in the LogView. */
+ public void appendToLog(String s) {
+ append("\n" + s);
+ }
+
+
+}
diff --git a/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.common/logger/LogWrapper.java
new file mode 100644
index 0000000..16a9e7b
--- /dev/null
+++ b/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.common/logger/LogWrapper.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2012 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.common.logger;
+
+import android.util.Log;
+
+/**
+ * Helper class which wraps Android's native Log utility in the Logger interface. This way
+ * normal DDMS output can be one of the many targets receiving and outputting logs simultaneously.
+ */
+public class LogWrapper implements LogNode {
+
+ // For piping: The next node to receive Log data after this one has done its work.
+ private LogNode mNext;
+
+ /**
+ * Returns the next LogNode in the linked list.
+ */
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to..
+ */
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+ /**
+ * Prints data out to the console using Android's native log mechanism.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+ // There actually are log methods that don't take a msg parameter. For now,
+ // if that's the case, just convert null to the empty string and move on.
+ String useMsg = msg;
+ if (useMsg == null) {
+ useMsg = "";
+ }
+
+ // If an exeption was provided, convert that exception to a usable string and attach
+ // it to the end of the msg method.
+ if (tr != null) {
+ msg += "\n" + Log.getStackTraceString(tr);
+ }
+
+ // This is functionally identical to Log.x(tag, useMsg);
+ // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg)
+ Log.println(priority, tag, useMsg);
+
+ // If this isn't the last node in the chain, move things along.
+ if (mNext != null) {
+ mNext.println(priority, tag, msg, tr);
+ }
+ }
+}
diff --git a/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java
new file mode 100644
index 0000000..19967dc
--- /dev/null
+++ b/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+/**
+ * Simple {@link LogNode} filter, removes everything except the message.
+ * Useful for situations like on-screen log output where you don't want a lot of metadata displayed,
+ * just easy-to-read message updates as they're happening.
+ */
+public class MessageOnlyLogFilter implements LogNode {
+
+ LogNode mNext;
+
+ /**
+ * Takes the "next" LogNode as a parameter, to simplify chaining.
+ *
+ * @param next The next LogNode in the pipeline.
+ */
+ public MessageOnlyLogFilter(LogNode next) {
+ mNext = next;
+ }
+
+ public MessageOnlyLogFilter() {
+ }
+
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+ if (mNext != null) {
+ getNext().println(Log.NONE, null, msg, null);
+ }
+ }
+
+ /**
+ * Returns the next LogNode in the chain.
+ */
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to..
+ */
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+}
diff --git a/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.synchronizednotifications/DismissListener.java b/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.synchronizednotifications/DismissListener.java
new file mode 100644
index 0000000..8648148
--- /dev/null
+++ b/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.synchronizednotifications/DismissListener.java
@@ -0,0 +1,128 @@
+/*
+ * 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.synchronizednotifications;
+
+import static com.google.android.gms.wearable.PutDataRequest.WEAR_URI_SCHEME;
+
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Bundle;
+import android.support.v4.app.NotificationManagerCompat;
+import android.util.Log;
+
+import com.example.android.synchronizednotifications.common.Constants;
+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.DataApi;
+import com.google.android.gms.wearable.DataEvent;
+import com.google.android.gms.wearable.DataEventBuffer;
+import com.google.android.gms.wearable.PutDataMapRequest;
+import com.google.android.gms.wearable.Wearable;
+import com.google.android.gms.wearable.WearableListenerService;
+
+/**
+ * A {@link com.google.android.gms.wearable.WearableListenerService} that is invoked when certain
+ * notifications are dismissed from either the phone or watch.
+ */
+public class DismissListener extends WearableListenerService
+ implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener,
+ ResultCallback<DataApi.DeleteDataItemsResult> {
+
+ private static final String TAG = "DismissListener";
+ private GoogleApiClient mGoogleApiClient;
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ mGoogleApiClient = new GoogleApiClient.Builder(this)
+ .addApi(Wearable.API)
+ .addConnectionCallbacks(this)
+ .addOnConnectionFailedListener(this)
+ .build();
+ }
+
+ @Override
+ public void onDataChanged(DataEventBuffer dataEvents) {
+ for (DataEvent dataEvent : dataEvents) {
+ if (dataEvent.getType() == DataEvent.TYPE_DELETED) {
+ if (Constants.BOTH_PATH.equals(dataEvent.getDataItem().getUri().getPath())) {
+ // notification on the phone should be dismissed
+ NotificationManagerCompat.from(this).cancel(Constants.BOTH_ID);
+ }
+ }
+ }
+ }
+
+ @Override
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ if (null != intent) {
+ String action = intent.getAction();
+ if (Constants.ACTION_DISMISS.equals(action)) {
+ // We need to dismiss the wearable notification. We delete the DataItem that
+ // created the notification to inform the wearable.
+ int notificationId = intent.getIntExtra(Constants.KEY_NOTIFICATION_ID, -1);
+ if (notificationId == Constants.BOTH_ID) {
+ dismissWearableNotification(notificationId);
+ }
+ }
+ }
+ return super.onStartCommand(intent, flags, startId);
+ }
+
+ /**
+ * Removes the DataItem that was used to create a notification on the watch. By deleting the
+ * data item, a {@link com.google.android.gms.wearable.WearableListenerService} on the watch
+ * will be notified and the notification on the watch will be removed. To
+ * access the Wearable DataApi, we first need to ensure the GoogleApiClient is ready,
+ * which will then run the onConnected callback were the data removal is
+ * defined.
+ *
+ * @param id The ID of the notification that should be removed
+ */
+ private void dismissWearableNotification(final int id) {
+ mGoogleApiClient.connect();
+ }
+
+ @Override // ConnectionCallbacks
+ public void onConnected(Bundle bundle) {
+ final Uri dataItemUri =
+ new Uri.Builder().scheme(WEAR_URI_SCHEME).path(Constants.BOTH_PATH).build();
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "Deleting Uri: " + dataItemUri.toString());
+ }
+ Wearable.DataApi.deleteDataItems(
+ mGoogleApiClient, dataItemUri).setResultCallback(this);
+ }
+
+ @Override // ConnectionCallbacks
+ public void onConnectionSuspended(int i) {
+ }
+
+ @Override // OnConnectionFailedListener
+ public void onConnectionFailed(ConnectionResult connectionResult) {
+ Log.e(TAG, "Failed to connect to the Google API client");
+ }
+
+ @Override // ResultCallback<DataApi.DeleteDataItemsResult>
+ public void onResult(DataApi.DeleteDataItemsResult deleteDataItemsResult) {
+ if (!deleteDataItemsResult.getStatus().isSuccess()) {
+ Log.e(TAG, "dismissWearableNotification(): failed to delete DataItem");
+ }
+ mGoogleApiClient.disconnect();
+ }
+}
diff --git a/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.synchronizednotifications/MainActivity.java b/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.synchronizednotifications/MainActivity.java
new file mode 100644
index 0000000..44b7ff7
--- /dev/null
+++ b/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.synchronizednotifications/MainActivity.java
@@ -0,0 +1,78 @@
+/*
+* Copyright 2013 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.synchronizednotifications;
+
+import android.graphics.Color;
+import android.os.Bundle;
+import android.support.v4.app.FragmentTransaction;
+import android.view.Menu;
+
+import com.example.android.common.activities.SampleActivityBase;
+import com.example.android.common.logger.Log;
+import com.example.android.common.logger.LogFragment;
+import com.example.android.common.logger.LogWrapper;
+import com.example.android.common.logger.MessageOnlyLogFilter;
+
+/**
+ * A simple launcher activity containing a summary sample description
+ * and a few action bar buttons.
+ */
+public class MainActivity extends SampleActivityBase {
+
+ public static final String TAG = "MainActivity";
+
+ public static final String FRAGTAG = "SynchronizedNotificationsFragment";
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_main);
+
+ FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
+ SynchronizedNotificationsFragment fragment = new SynchronizedNotificationsFragment();
+ transaction.add(fragment, FRAGTAG);
+ transaction.commit();
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.main, menu);
+ return true;
+ }
+
+ /** Create a chain of targets that will receive log data */
+ @Override
+ public void initializeLogging() {
+ // Wraps Android's native log framework.
+ LogWrapper logWrapper = new LogWrapper();
+ // Using Log, front-end to the logging chain, emulates android.util.log method signatures.
+ Log.setLogNode(logWrapper);
+
+ // Filter strips out everything except the message text.
+ MessageOnlyLogFilter msgFilter = new MessageOnlyLogFilter();
+ logWrapper.setNext(msgFilter);
+
+ // On screen logging via a fragment with a TextView.
+ LogFragment logFragment = (LogFragment) getSupportFragmentManager()
+ .findFragmentById(R.id.log_fragment);
+ msgFilter.setNext(logFragment.getLogView());
+ logFragment.getLogView().setTextAppearance(this, R.style.Log);
+ logFragment.getLogView().setBackgroundColor(Color.WHITE);
+
+ Log.i(TAG, "Ready");
+ }
+}
\ No newline at end of file
diff --git a/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.synchronizednotifications/SynchronizedNotificationsFragment.java b/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.synchronizednotifications/SynchronizedNotificationsFragment.java
new file mode 100644
index 0000000..537f816
--- /dev/null
+++ b/samples/browseable/SynchronizedNotifications/Application/src/com.example.android.synchronizednotifications/SynchronizedNotificationsFragment.java
@@ -0,0 +1,198 @@
+/*
+ * 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.synchronizednotifications;
+
+import android.app.PendingIntent;
+import android.content.Intent;
+import android.support.v4.app.Fragment;
+import android.app.Activity;
+import android.net.Uri;
+import android.os.Bundle;
+import android.support.v4.app.NotificationCompat;
+import android.support.v4.app.NotificationManagerCompat;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Toast;
+
+import com.example.android.synchronizednotifications.common.Constants;
+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.DataApi;
+import com.google.android.gms.wearable.PutDataMapRequest;
+import com.google.android.gms.wearable.PutDataRequest;
+import com.google.android.gms.wearable.Wearable;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+
+
+/**
+ * A simple fragment that presents three buttons that would trigger three different combinations of
+ * notifications on the handset and the watch:
+ * <ul>
+ * <li>The first button builds a simple local-only notification on the handset.</li>
+ * <li>The second one creates a wearable-only notification by putting a data item in the shared data
+ * store and having a {@link com.google.android.gms.wearable.WearableListenerService} listen for
+ * that on the wearable</li>
+ * <li>The third one creates a local notification and a wearable notification by combining the above
+ * two. It, however, demonstrates how one can set things up so that the dismissal of one
+ * notification results in the dismissal of the other one.</li>
+ * </ul>
+ */
+public class SynchronizedNotificationsFragment extends Fragment
+ implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
+
+ private static final String TAG = "SynchronizedNotificationsFragment";
+ private GoogleApiClient mGoogleApiClient;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ mGoogleApiClient = new GoogleApiClient.Builder(this.getActivity())
+ .addApi(Wearable.API)
+ .addConnectionCallbacks(this)
+ .addOnConnectionFailedListener(this)
+ .build();
+ setHasOptionsMenu(true);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.btn_phone_only:
+ buildLocalOnlyNotification(getString(R.string.phone_only), now(),
+ Constants.PHONE_ONLY_ID, false);
+ return true;
+ case R.id.btn_wear_only:
+ buildWearableOnlyNotification(getString(R.string.wear_only), now(),
+ Constants.WATCH_ONLY_PATH);
+ return true;
+ case R.id.btn_different:
+ buildMirroredNotifications(getString(R.string.phone_both), getString(R.string.watch_both), now());
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Builds a local-only notification for the handset. This is achieved by using
+ * <code>setLocalOnly(true)</code>. If <code>withDismissal</code> is set to <code>true</code>, a
+ * {@link android.app.PendingIntent} will be added to handle the dismissal of notification to
+ * be able to remove the mirrored notification on the wearable.
+ */
+ private void buildLocalOnlyNotification(String title, String content, int notificationId,
+ boolean withDismissal) {
+ NotificationCompat.Builder builder = new NotificationCompat.Builder(this.getActivity());
+ builder.setContentTitle(title)
+ .setContentText(content)
+ .setLocalOnly(true)
+ .setSmallIcon(R.drawable.ic_launcher);
+
+ if (withDismissal) {
+ Intent dismissIntent = new Intent(Constants.ACTION_DISMISS);
+ dismissIntent.putExtra(Constants.KEY_NOTIFICATION_ID, Constants.BOTH_ID);
+ PendingIntent pendingIntent = PendingIntent
+ .getService(this.getActivity(), 0, dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT);
+ builder.setDeleteIntent(pendingIntent);
+ }
+ NotificationManagerCompat.from(this.getActivity()).notify(notificationId, builder.build());
+ }
+
+ /**
+ * Builds a DataItem that on the wearable will be interpreted as a request to show a
+ * notification. The result will be a notification that only shows up on the wearable.
+ */
+ private void buildWearableOnlyNotification(String title, String content, String path) {
+ if (mGoogleApiClient.isConnected()) {
+ PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(path);
+ putDataMapRequest.getDataMap().putString(Constants.KEY_CONTENT, content);
+ putDataMapRequest.getDataMap().putString(Constants.KEY_TITLE, title);
+ PutDataRequest request = putDataMapRequest.asPutDataRequest();
+ Wearable.DataApi.putDataItem(mGoogleApiClient, request)
+ .setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
+ @Override
+ public void onResult(DataApi.DataItemResult dataItemResult) {
+ if (!dataItemResult.getStatus().isSuccess()) {
+ Log.e(TAG, "buildWatchOnlyNotification(): Failed to set the data, "
+ + "status: " + dataItemResult.getStatus().getStatusCode());
+ }
+ }
+ });
+ } else {
+ Log.e(TAG, "buildWearableOnlyNotification(): no Google API Client connection");
+ }
+ }
+
+ /**
+ * Builds a local notification and sets a DataItem that will be interpreted by the wearable as
+ * a request to build a notification on the wearable as as well. The two notifications show
+ * different messages.
+ * Dismissing either of the notifications will result in dismissal of the other; this is
+ * achieved by creating a {@link android.app.PendingIntent} that results in removal of
+ * the DataItem that created the watch notification. The deletion of the DataItem is observed on
+ * both sides, using WearableListenerService callbacks, and is interpreted on each side as a
+ * request to dismiss the corresponding notification.
+ */
+ private void buildMirroredNotifications(String phoneTitle, String watchTitle, String content) {
+ if (mGoogleApiClient.isConnected()) {
+ // Wearable notification
+ buildWearableOnlyNotification(watchTitle, content, Constants.BOTH_PATH);
+
+ // Local notification, with a pending intent for dismissal
+ buildLocalOnlyNotification(phoneTitle, content, Constants.BOTH_ID, true);
+ }
+ }
+
+ @Override
+ public void onStart() {
+ super.onStart();
+ mGoogleApiClient.connect();
+ }
+
+ @Override
+ public void onStop() {
+ mGoogleApiClient.disconnect();
+ super.onStop();
+ }
+
+ @Override
+ public void onConnected(Bundle bundle) {
+ }
+
+ @Override
+ public void onConnectionSuspended(int i) {
+ }
+
+ @Override
+ public void onConnectionFailed(ConnectionResult connectionResult) {
+ Log.e(TAG, "Failed to connect to Google API Client");
+ }
+
+ /**
+ * Returns a string built from the current time
+ */
+ private String now() {
+ SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
+ return sdf.format(new Date());
+ }
+
+}
diff --git a/samples/browseable/SynchronizedNotifications/Shared/AndroidManifest.xml b/samples/browseable/SynchronizedNotifications/Shared/AndroidManifest.xml
new file mode 100644
index 0000000..7235ace
--- /dev/null
+++ b/samples/browseable/SynchronizedNotifications/Shared/AndroidManifest.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.synchronizednotifications.common">
+
+ <application android:allowBackup="true"
+ android:label="@string/app_name">
+ </application>
+
+</manifest>
diff --git a/samples/browseable/SynchronizedNotifications/Shared/res/values/strings.xml b/samples/browseable/SynchronizedNotifications/Shared/res/values/strings.xml
new file mode 100644
index 0000000..0f2bb90
--- /dev/null
+++ b/samples/browseable/SynchronizedNotifications/Shared/res/values/strings.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<resources>
+ <string name="app_name">Shared</string>
+</resources>
diff --git a/samples/browseable/SynchronizedNotifications/Shared/src/com.example.android.synchronizednotifications.common/Constants.java b/samples/browseable/SynchronizedNotifications/Shared/src/com.example.android.synchronizednotifications.common/Constants.java
new file mode 100644
index 0000000..5a45583
--- /dev/null
+++ b/samples/browseable/SynchronizedNotifications/Shared/src/com.example.android.synchronizednotifications.common/Constants.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2013 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.synchronizednotifications.common;
+
+/**
+ * Constants that are used in both the Application and the Wearable modules.
+ */
+public final class Constants {
+
+ private Constants() {};
+
+ public static final int WATCH_ONLY_ID = 2;
+ public static final int PHONE_ONLY_ID = 3;
+ public static final int BOTH_ID = 4;
+
+ public static final String BOTH_PATH = "/both";
+ public static final String WATCH_ONLY_PATH = "/watch-only";
+ public static final String KEY_NOTIFICATION_ID = "notification-id";
+ public static final String KEY_TITLE = "title";
+ public static final String KEY_CONTENT = "content";
+
+ public static final String ACTION_DISMISS
+ = "com.example.android.synchronizednotifications.DISMISS";
+}
diff --git a/samples/browseable/SynchronizedNotifications/Wearable/AndroidManifest.xml b/samples/browseable/SynchronizedNotifications/Wearable/AndroidManifest.xml
new file mode 100644
index 0000000..97702ce
--- /dev/null
+++ b/samples/browseable/SynchronizedNotifications/Wearable/AndroidManifest.xml
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 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.
+-->
+
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.synchronizednotifications">
+
+ <uses-sdk android:minSdkVersion="20"
+ android:targetSdkVersion="20" />
+
+ <uses-feature android:name="android.hardware.type.watch" />
+
+ <application
+ android:allowBackup="true"
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name"
+ android:theme="@android:style/Theme.DeviceDefault.Light" >
+ <meta-data android:name="com.google.android.gms.version"
+ android:value="@integer/google_play_services_version" />
+ <activity
+ android:name=".WearableActivity"
+ android:label="@string/app_name" >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ <service android:name=".NotificationUpdateService">
+ <intent-filter>
+ <action
+ android:name="com.google.android.gms.wearable.BIND_LISTENER" />
+ </intent-filter>
+ <intent-filter>
+ <action
+ android:name="com.example.android.synchronizednotifications.DISMISS" />
+ </intent-filter>
+ </service>
+
+ </application>
+
+</manifest>
diff --git a/samples/browseable/SynchronizedNotifications/Wearable/res/drawable-hdpi/ic_launcher.png b/samples/browseable/SynchronizedNotifications/Wearable/res/drawable-hdpi/ic_launcher.png
new file mode 100644
index 0000000..f7dd9a0
--- /dev/null
+++ b/samples/browseable/SynchronizedNotifications/Wearable/res/drawable-hdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/SynchronizedNotifications/Wearable/res/drawable-mdpi/ic_launcher.png b/samples/browseable/SynchronizedNotifications/Wearable/res/drawable-mdpi/ic_launcher.png
new file mode 100644
index 0000000..fef2da7
--- /dev/null
+++ b/samples/browseable/SynchronizedNotifications/Wearable/res/drawable-mdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/SynchronizedNotifications/Wearable/res/drawable-xhdpi/ic_launcher.png b/samples/browseable/SynchronizedNotifications/Wearable/res/drawable-xhdpi/ic_launcher.png
new file mode 100644
index 0000000..f2fb03c
--- /dev/null
+++ b/samples/browseable/SynchronizedNotifications/Wearable/res/drawable-xhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/SynchronizedNotifications/Wearable/res/layout/activity_wearable.xml b/samples/browseable/SynchronizedNotifications/Wearable/res/layout/activity_wearable.xml
new file mode 100644
index 0000000..71451ff
--- /dev/null
+++ b/samples/browseable/SynchronizedNotifications/Wearable/res/layout/activity_wearable.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ tools:context=".WearableActivity">
+
+</RelativeLayout>
diff --git a/samples/browseable/SynchronizedNotifications/Wearable/res/values/strings.xml b/samples/browseable/SynchronizedNotifications/Wearable/res/values/strings.xml
new file mode 100644
index 0000000..4240ff5
--- /dev/null
+++ b/samples/browseable/SynchronizedNotifications/Wearable/res/values/strings.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+ <string name="app_name">Sample Wearable app</string>
+</resources>
+
diff --git a/samples/browseable/SynchronizedNotifications/Wearable/src/com.example.android.synchronizednotifications/NotificationUpdateService.java b/samples/browseable/SynchronizedNotifications/Wearable/src/com.example.android.synchronizednotifications/NotificationUpdateService.java
new file mode 100644
index 0000000..b8963cd
--- /dev/null
+++ b/samples/browseable/SynchronizedNotifications/Wearable/src/com.example.android.synchronizednotifications/NotificationUpdateService.java
@@ -0,0 +1,164 @@
+/*
+ * 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.synchronizednotifications;
+
+import static com.google.android.gms.wearable.PutDataRequest.WEAR_URI_SCHEME;
+
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Bundle;
+import android.util.Log;
+
+import com.example.android.synchronizednotifications.common.Constants;
+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.DataApi;
+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.DataMapItem;
+import com.google.android.gms.wearable.PutDataMapRequest;
+import com.google.android.gms.wearable.Wearable;
+import com.google.android.gms.wearable.WearableListenerService;
+
+/**
+ * A {@link com.google.android.gms.wearable.WearableListenerService} that will be invoked when a
+ * DataItem is added or deleted. The creation of a new DataItem will be interpreted as a request to
+ * create a new notification and the removal of that DataItem is interpreted as a request to
+ * dismiss that notification.
+ */
+public class NotificationUpdateService extends WearableListenerService
+ implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener,
+ ResultCallback<DataApi.DeleteDataItemsResult> {
+
+ private static final String TAG = "NotificationUpdate";
+ private GoogleApiClient mGoogleApiClient;
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ mGoogleApiClient = new GoogleApiClient.Builder(this)
+ .addApi(Wearable.API)
+ .addConnectionCallbacks(this)
+ .addOnConnectionFailedListener(this)
+ .build();
+ }
+
+ @Override
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ if (null != intent) {
+ String action = intent.getAction();
+ if (Constants.ACTION_DISMISS.equals(action)) {
+ // We need to dismiss the wearable notification. We delete the data item that
+ // created the notification and that is how we inform the phone
+ int notificationId = intent.getIntExtra(Constants.KEY_NOTIFICATION_ID, -1);
+ if (notificationId == Constants.BOTH_ID) {
+ dismissPhoneNotification(notificationId);
+ }
+ }
+ }
+ return super.onStartCommand(intent, flags, startId);
+ }
+
+ /**
+ * Dismisses the phone notification, via a {@link android.app.PendingIntent} that is triggered
+ * when the user dismisses the local notification. Deleting the corresponding data item notifies
+ * the {@link com.google.android.gms.wearable.WearableListenerService} on the phone that the
+ * matching notification on the phone side should be removed.
+ */
+ private void dismissPhoneNotification(int id) {
+ mGoogleApiClient.connect();
+ }
+
+ @Override
+ public void onDataChanged(DataEventBuffer dataEvents) {
+ for (DataEvent dataEvent : dataEvents) {
+ if (dataEvent.getType() == DataEvent.TYPE_CHANGED) {
+ DataMap dataMap = DataMapItem.fromDataItem(dataEvent.getDataItem()).getDataMap();
+ String content = dataMap.getString(Constants.KEY_CONTENT);
+ String title = dataMap.getString(Constants.KEY_TITLE);
+ if (Constants.WATCH_ONLY_PATH.equals(dataEvent.getDataItem().getUri().getPath())) {
+ buildWearableOnlyNotification(title, content, false);
+ } else if (Constants.BOTH_PATH.equals(dataEvent.getDataItem().getUri().getPath())) {
+ buildWearableOnlyNotification(title, content, true);
+ }
+ } else if (dataEvent.getType() == DataEvent.TYPE_DELETED) {
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "DataItem deleted: " + dataEvent.getDataItem().getUri().getPath());
+ }
+ if (Constants.BOTH_PATH.equals(dataEvent.getDataItem().getUri().getPath())) {
+ // Dismiss the corresponding notification
+ ((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
+ .cancel(Constants.WATCH_ONLY_ID);
+ }
+ }
+ }
+ }
+
+ /**
+ * Builds a simple notification on the wearable.
+ */
+ private void buildWearableOnlyNotification(String title, String content,
+ boolean withDismissal) {
+ Notification.Builder builder = new Notification.Builder(this)
+ .setSmallIcon(R.drawable.ic_launcher)
+ .setContentTitle(title)
+ .setContentText(content);
+
+ if (withDismissal) {
+ Intent dismissIntent = new Intent(Constants.ACTION_DISMISS);
+ dismissIntent.putExtra(Constants.KEY_NOTIFICATION_ID, Constants.BOTH_ID);
+ PendingIntent pendingIntent = PendingIntent
+ .getService(this, 0, dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT);
+ builder.setDeleteIntent(pendingIntent);
+ }
+
+ ((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
+ .notify(Constants.WATCH_ONLY_ID, builder.build());
+ }
+
+ @Override
+ public void onConnected(Bundle bundle) {
+ final Uri dataItemUri =
+ new Uri.Builder().scheme(WEAR_URI_SCHEME).path(Constants.BOTH_PATH).build();
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "Deleting Uri: " + dataItemUri.toString());
+ }
+ Wearable.DataApi.deleteDataItems(
+ mGoogleApiClient, dataItemUri).setResultCallback(this);
+ }
+
+ @Override
+ public void onConnectionSuspended(int i) {
+ }
+
+ @Override
+ public void onConnectionFailed(ConnectionResult connectionResult) {
+ }
+
+ @Override
+ public void onResult(DataApi.DeleteDataItemsResult deleteDataItemsResult) {
+ if (!deleteDataItemsResult.getStatus().isSuccess()) {
+ Log.e(TAG, "dismissWearableNotification(): failed to delete DataItem");
+ }
+ mGoogleApiClient.disconnect();
+ }
+}
diff --git a/samples/browseable/SynchronizedNotifications/Wearable/src/com.example.android.synchronizednotifications/WearableActivity.java b/samples/browseable/SynchronizedNotifications/Wearable/src/com.example.android.synchronizednotifications/WearableActivity.java
new file mode 100644
index 0000000..28736ad
--- /dev/null
+++ b/samples/browseable/SynchronizedNotifications/Wearable/src/com.example.android.synchronizednotifications/WearableActivity.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2013 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.synchronizednotifications;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+public class WearableActivity extends Activity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_wearable);
+ }
+}
diff --git a/samples/browseable/SynchronizedNotifications/_index.jd b/samples/browseable/SynchronizedNotifications/_index.jd
new file mode 100644
index 0000000..fe882ad
--- /dev/null
+++ b/samples/browseable/SynchronizedNotifications/_index.jd
@@ -0,0 +1,10 @@
+page.tags="SynchronizedNotifications"
+sample.group=Wearable
+@jd:body
+
+<p>
+
+ This sample creates simple or synchronized notifications on a
+ device and an Android Wear watch.
+
+ </p>
diff --git a/samples/browseable/Timer/Application/AndroidManifest.xml b/samples/browseable/Timer/Application/AndroidManifest.xml
new file mode 100644
index 0000000..b8ebd74
--- /dev/null
+++ b/samples/browseable/Timer/Application/AndroidManifest.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.timer">
+
+ <uses-sdk android:minSdkVersion="19"
+ android:targetSdkVersion="19" />
+
+ <application android:allowBackup="true"
+ android:label="@string/app_name">
+ </application>
+
+</manifest>
+
diff --git a/samples/browseable/Timer/Application/res/drawable-hdpi/tile.9.png b/samples/browseable/Timer/Application/res/drawable-hdpi/tile.9.png
new file mode 100644
index 0000000..1358628
--- /dev/null
+++ b/samples/browseable/Timer/Application/res/drawable-hdpi/tile.9.png
Binary files differ
diff --git a/samples/browseable/Timer/Application/res/layout/activity_main.xml b/samples/browseable/Timer/Application/res/layout/activity_main.xml
new file mode 100755
index 0000000..be1aa49
--- /dev/null
+++ b/samples/browseable/Timer/Application/res/layout/activity_main.xml
@@ -0,0 +1,36 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <LinearLayout style="@style/Widget.SampleMessageTile"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+
+ <TextView style="@style/Widget.SampleMessage"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="@dimen/horizontal_page_margin"
+ android:layout_marginRight="@dimen/horizontal_page_margin"
+ android:layout_marginTop="@dimen/vertical_page_margin"
+ android:layout_marginBottom="@dimen/vertical_page_margin"
+ android:text="@string/intro_message" />
+ </LinearLayout>
+</LinearLayout>
diff --git a/samples/browseable/Timer/Application/res/values-sw600dp/template-dimens.xml b/samples/browseable/Timer/Application/res/values-sw600dp/template-dimens.xml
new file mode 100644
index 0000000..22074a2
--- /dev/null
+++ b/samples/browseable/Timer/Application/res/values-sw600dp/template-dimens.xml
@@ -0,0 +1,24 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Semantic definitions -->
+
+ <dimen name="horizontal_page_margin">@dimen/margin_huge</dimen>
+ <dimen name="vertical_page_margin">@dimen/margin_medium</dimen>
+
+</resources>
diff --git a/samples/browseable/Timer/Application/res/values-sw600dp/template-styles.xml b/samples/browseable/Timer/Application/res/values-sw600dp/template-styles.xml
new file mode 100644
index 0000000..03d1974
--- /dev/null
+++ b/samples/browseable/Timer/Application/res/values-sw600dp/template-styles.xml
@@ -0,0 +1,25 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <style name="Widget.SampleMessage">
+ <item name="android:textAppearance">?android:textAppearanceLarge</item>
+ <item name="android:lineSpacingMultiplier">1.2</item>
+ <item name="android:shadowDy">-6.5</item>
+ </style>
+
+</resources>
diff --git a/samples/browseable/Timer/Application/res/values-v11/template-styles.xml b/samples/browseable/Timer/Application/res/values-v11/template-styles.xml
new file mode 100644
index 0000000..8c1ea66
--- /dev/null
+++ b/samples/browseable/Timer/Application/res/values-v11/template-styles.xml
@@ -0,0 +1,22 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Activity themes -->
+ <style name="Theme.Base" parent="android:Theme.Holo.Light" />
+
+</resources>
diff --git a/samples/browseable/Timer/Application/res/values/base-strings.xml b/samples/browseable/Timer/Application/res/values/base-strings.xml
new file mode 100644
index 0000000..0ccfd50
--- /dev/null
+++ b/samples/browseable/Timer/Application/res/values/base-strings.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 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.
+-->
+<resources>
+ <string name="app_name">Timer</string>
+ <string name="intro_message">
+ <![CDATA[
+
+
+ This simple wearable app allows the user to set a countdown timer. It runs
+ independently on the wearable with no phone connection.
+
+
+ ]]>
+ </string>
+</resources>
diff --git a/samples/browseable/Timer/Application/res/values/template-dimens.xml b/samples/browseable/Timer/Application/res/values/template-dimens.xml
new file mode 100644
index 0000000..39e710b
--- /dev/null
+++ b/samples/browseable/Timer/Application/res/values/template-dimens.xml
@@ -0,0 +1,32 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Define standard dimensions to comply with Holo-style grids and rhythm. -->
+
+ <dimen name="margin_tiny">4dp</dimen>
+ <dimen name="margin_small">8dp</dimen>
+ <dimen name="margin_medium">16dp</dimen>
+ <dimen name="margin_large">32dp</dimen>
+ <dimen name="margin_huge">64dp</dimen>
+
+ <!-- Semantic definitions -->
+
+ <dimen name="horizontal_page_margin">@dimen/margin_medium</dimen>
+ <dimen name="vertical_page_margin">@dimen/margin_medium</dimen>
+
+</resources>
diff --git a/samples/browseable/Timer/Application/res/values/template-styles.xml b/samples/browseable/Timer/Application/res/values/template-styles.xml
new file mode 100644
index 0000000..6e7d593
--- /dev/null
+++ b/samples/browseable/Timer/Application/res/values/template-styles.xml
@@ -0,0 +1,42 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Activity themes -->
+
+ <style name="Theme.Base" parent="android:Theme.Light" />
+
+ <style name="Theme.Sample" parent="Theme.Base" />
+
+ <style name="AppTheme" parent="Theme.Sample" />
+ <!-- Widget styling -->
+
+ <style name="Widget" />
+
+ <style name="Widget.SampleMessage">
+ <item name="android:textAppearance">?android:textAppearanceMedium</item>
+ <item name="android:lineSpacingMultiplier">1.1</item>
+ </style>
+
+ <style name="Widget.SampleMessageTile">
+ <item name="android:background">@drawable/tile</item>
+ <item name="android:shadowColor">#7F000000</item>
+ <item name="android:shadowDy">-3.5</item>
+ <item name="android:shadowRadius">2</item>
+ </style>
+
+</resources>
diff --git a/samples/browseable/Timer/Application/src/com.example.android.common/activities/SampleActivityBase.java b/samples/browseable/Timer/Application/src/com.example.android.common/activities/SampleActivityBase.java
new file mode 100644
index 0000000..3228927
--- /dev/null
+++ b/samples/browseable/Timer/Application/src/com.example.android.common/activities/SampleActivityBase.java
@@ -0,0 +1,52 @@
+/*
+* Copyright 2013 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.common.activities;
+
+import android.os.Bundle;
+import android.support.v4.app.FragmentActivity;
+
+import com.example.android.common.logger.Log;
+import com.example.android.common.logger.LogWrapper;
+
+/**
+ * Base launcher activity, to handle most of the common plumbing for samples.
+ */
+public class SampleActivityBase extends FragmentActivity {
+
+ public static final String TAG = "SampleActivityBase";
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ initializeLogging();
+ }
+
+ /** Set up targets to receive log data */
+ public void initializeLogging() {
+ // Using Log, front-end to the logging chain, emulates android.util.log method signatures.
+ // Wraps Android's native log framework
+ LogWrapper logWrapper = new LogWrapper();
+ Log.setLogNode(logWrapper);
+
+ Log.i(TAG, "Ready");
+ }
+}
diff --git a/samples/browseable/Timer/Application/src/com.example.android.common/logger/Log.java b/samples/browseable/Timer/Application/src/com.example.android.common/logger/Log.java
new file mode 100644
index 0000000..17503c5
--- /dev/null
+++ b/samples/browseable/Timer/Application/src/com.example.android.common/logger/Log.java
@@ -0,0 +1,236 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+/**
+ * Helper class for a list (or tree) of LoggerNodes.
+ *
+ * <p>When this is set as the head of the list,
+ * an instance of it can function as a drop-in replacement for {@link android.util.Log}.
+ * Most of the methods in this class server only to map a method call in Log to its equivalent
+ * in LogNode.</p>
+ */
+public class Log {
+ // Grabbing the native values from Android's native logging facilities,
+ // to make for easy migration and interop.
+ public static final int NONE = -1;
+ public static final int VERBOSE = android.util.Log.VERBOSE;
+ public static final int DEBUG = android.util.Log.DEBUG;
+ public static final int INFO = android.util.Log.INFO;
+ public static final int WARN = android.util.Log.WARN;
+ public static final int ERROR = android.util.Log.ERROR;
+ public static final int ASSERT = android.util.Log.ASSERT;
+
+ // Stores the beginning of the LogNode topology.
+ private static LogNode mLogNode;
+
+ /**
+ * Returns the next LogNode in the linked list.
+ */
+ public static LogNode getLogNode() {
+ return mLogNode;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to.
+ */
+ public static void setLogNode(LogNode node) {
+ mLogNode = node;
+ }
+
+ /**
+ * Instructs the LogNode to print the log data provided. Other LogNodes can
+ * be chained to the end of the LogNode as desired.
+ *
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void println(int priority, String tag, String msg, Throwable tr) {
+ if (mLogNode != null) {
+ mLogNode.println(priority, tag, msg, tr);
+ }
+ }
+
+ /**
+ * Instructs the LogNode to print the log data provided. Other LogNodes can
+ * be chained to the end of the LogNode as desired.
+ *
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ */
+ public static void println(int priority, String tag, String msg) {
+ println(priority, tag, msg, null);
+ }
+
+ /**
+ * Prints a message at VERBOSE priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void v(String tag, String msg, Throwable tr) {
+ println(VERBOSE, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at VERBOSE priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void v(String tag, String msg) {
+ v(tag, msg, null);
+ }
+
+
+ /**
+ * Prints a message at DEBUG priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void d(String tag, String msg, Throwable tr) {
+ println(DEBUG, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at DEBUG priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void d(String tag, String msg) {
+ d(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at INFO priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void i(String tag, String msg, Throwable tr) {
+ println(INFO, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at INFO priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void i(String tag, String msg) {
+ i(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void w(String tag, String msg, Throwable tr) {
+ println(WARN, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void w(String tag, String msg) {
+ w(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void w(String tag, Throwable tr) {
+ w(tag, null, tr);
+ }
+
+ /**
+ * Prints a message at ERROR priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void e(String tag, String msg, Throwable tr) {
+ println(ERROR, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at ERROR priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void e(String tag, String msg) {
+ e(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void wtf(String tag, String msg, Throwable tr) {
+ println(ASSERT, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void wtf(String tag, String msg) {
+ wtf(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void wtf(String tag, Throwable tr) {
+ wtf(tag, null, tr);
+ }
+}
diff --git a/samples/browseable/Timer/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/Timer/Application/src/com.example.android.common/logger/LogFragment.java
new file mode 100644
index 0000000..b302acd
--- /dev/null
+++ b/samples/browseable/Timer/Application/src/com.example.android.common/logger/LogFragment.java
@@ -0,0 +1,109 @@
+/*
+* Copyright 2013 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.
+*/
+/*
+ * Copyright 2013 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.common.logger;
+
+import android.graphics.Typeface;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ScrollView;
+
+/**
+ * Simple fraggment which contains a LogView and uses is to output log data it receives
+ * through the LogNode interface.
+ */
+public class LogFragment extends Fragment {
+
+ private LogView mLogView;
+ private ScrollView mScrollView;
+
+ public LogFragment() {}
+
+ public View inflateViews() {
+ mScrollView = new ScrollView(getActivity());
+ ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT);
+ mScrollView.setLayoutParams(scrollParams);
+
+ mLogView = new LogView(getActivity());
+ ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams);
+ logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
+ mLogView.setLayoutParams(logParams);
+ mLogView.setClickable(true);
+ mLogView.setFocusable(true);
+ mLogView.setTypeface(Typeface.MONOSPACE);
+
+ // Want to set padding as 16 dips, setPadding takes pixels. Hooray math!
+ int paddingDips = 16;
+ double scale = getResources().getDisplayMetrics().density;
+ int paddingPixels = (int) ((paddingDips * (scale)) + .5);
+ mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels);
+ mLogView.setCompoundDrawablePadding(paddingPixels);
+
+ mLogView.setGravity(Gravity.BOTTOM);
+ mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium);
+
+ mScrollView.addView(mLogView);
+ return mScrollView;
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+
+ View result = inflateViews();
+
+ mLogView.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {}
+
+ @Override
+ public void afterTextChanged(Editable s) {
+ mScrollView.fullScroll(ScrollView.FOCUS_DOWN);
+ }
+ });
+ return result;
+ }
+
+ public LogView getLogView() {
+ return mLogView;
+ }
+}
\ No newline at end of file
diff --git a/samples/browseable/Timer/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/Timer/Application/src/com.example.android.common/logger/LogNode.java
new file mode 100644
index 0000000..bc37cab
--- /dev/null
+++ b/samples/browseable/Timer/Application/src/com.example.android.common/logger/LogNode.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2012 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.common.logger;
+
+/**
+ * Basic interface for a logging system that can output to one or more targets.
+ * Note that in addition to classes that will output these logs in some format,
+ * one can also implement this interface over a filter and insert that in the chain,
+ * such that no targets further down see certain data, or see manipulated forms of the data.
+ * You could, for instance, write a "ToHtmlLoggerNode" that just converted all the log data
+ * it received to HTML and sent it along to the next node in the chain, without printing it
+ * anywhere.
+ */
+public interface LogNode {
+
+ /**
+ * Instructs first LogNode in the list to print the log data provided.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public void println(int priority, String tag, String msg, Throwable tr);
+
+}
diff --git a/samples/browseable/Timer/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/Timer/Application/src/com.example.android.common/logger/LogView.java
new file mode 100644
index 0000000..c01542b
--- /dev/null
+++ b/samples/browseable/Timer/Application/src/com.example.android.common/logger/LogView.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+import android.app.Activity;
+import android.content.Context;
+import android.util.*;
+import android.widget.TextView;
+
+/** Simple TextView which is used to output log data received through the LogNode interface.
+*/
+public class LogView extends TextView implements LogNode {
+
+ public LogView(Context context) {
+ super(context);
+ }
+
+ public LogView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public LogView(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ /**
+ * Formats the log data and prints it out to the LogView.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+
+
+ String priorityStr = null;
+
+ // For the purposes of this View, we want to print the priority as readable text.
+ switch(priority) {
+ case android.util.Log.VERBOSE:
+ priorityStr = "VERBOSE";
+ break;
+ case android.util.Log.DEBUG:
+ priorityStr = "DEBUG";
+ break;
+ case android.util.Log.INFO:
+ priorityStr = "INFO";
+ break;
+ case android.util.Log.WARN:
+ priorityStr = "WARN";
+ break;
+ case android.util.Log.ERROR:
+ priorityStr = "ERROR";
+ break;
+ case android.util.Log.ASSERT:
+ priorityStr = "ASSERT";
+ break;
+ default:
+ break;
+ }
+
+ // Handily, the Log class has a facility for converting a stack trace into a usable string.
+ String exceptionStr = null;
+ if (tr != null) {
+ exceptionStr = android.util.Log.getStackTraceString(tr);
+ }
+
+ // Take the priority, tag, message, and exception, and concatenate as necessary
+ // into one usable line of text.
+ final StringBuilder outputBuilder = new StringBuilder();
+
+ String delimiter = "\t";
+ appendIfNotNull(outputBuilder, priorityStr, delimiter);
+ appendIfNotNull(outputBuilder, tag, delimiter);
+ appendIfNotNull(outputBuilder, msg, delimiter);
+ appendIfNotNull(outputBuilder, exceptionStr, delimiter);
+
+ // In case this was originally called from an AsyncTask or some other off-UI thread,
+ // make sure the update occurs within the UI thread.
+ ((Activity) getContext()).runOnUiThread( (new Thread(new Runnable() {
+ @Override
+ public void run() {
+ // Display the text we just generated within the LogView.
+ appendToLog(outputBuilder.toString());
+ }
+ })));
+
+ if (mNext != null) {
+ mNext.println(priority, tag, msg, tr);
+ }
+ }
+
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+ /** Takes a string and adds to it, with a separator, if the bit to be added isn't null. Since
+ * the logger takes so many arguments that might be null, this method helps cut out some of the
+ * agonizing tedium of writing the same 3 lines over and over.
+ * @param source StringBuilder containing the text to append to.
+ * @param addStr The String to append
+ * @param delimiter The String to separate the source and appended strings. A tab or comma,
+ * for instance.
+ * @return The fully concatenated String as a StringBuilder
+ */
+ private StringBuilder appendIfNotNull(StringBuilder source, String addStr, String delimiter) {
+ if (addStr != null) {
+ if (addStr.length() == 0) {
+ delimiter = "";
+ }
+
+ return source.append(addStr).append(delimiter);
+ }
+ return source;
+ }
+
+ // The next LogNode in the chain.
+ LogNode mNext;
+
+ /** Outputs the string as a new line of log data in the LogView. */
+ public void appendToLog(String s) {
+ append("\n" + s);
+ }
+
+
+}
diff --git a/samples/browseable/Timer/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/Timer/Application/src/com.example.android.common/logger/LogWrapper.java
new file mode 100644
index 0000000..16a9e7b
--- /dev/null
+++ b/samples/browseable/Timer/Application/src/com.example.android.common/logger/LogWrapper.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2012 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.common.logger;
+
+import android.util.Log;
+
+/**
+ * Helper class which wraps Android's native Log utility in the Logger interface. This way
+ * normal DDMS output can be one of the many targets receiving and outputting logs simultaneously.
+ */
+public class LogWrapper implements LogNode {
+
+ // For piping: The next node to receive Log data after this one has done its work.
+ private LogNode mNext;
+
+ /**
+ * Returns the next LogNode in the linked list.
+ */
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to..
+ */
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+ /**
+ * Prints data out to the console using Android's native log mechanism.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+ // There actually are log methods that don't take a msg parameter. For now,
+ // if that's the case, just convert null to the empty string and move on.
+ String useMsg = msg;
+ if (useMsg == null) {
+ useMsg = "";
+ }
+
+ // If an exeption was provided, convert that exception to a usable string and attach
+ // it to the end of the msg method.
+ if (tr != null) {
+ msg += "\n" + Log.getStackTraceString(tr);
+ }
+
+ // This is functionally identical to Log.x(tag, useMsg);
+ // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg)
+ Log.println(priority, tag, useMsg);
+
+ // If this isn't the last node in the chain, move things along.
+ if (mNext != null) {
+ mNext.println(priority, tag, msg, tr);
+ }
+ }
+}
diff --git a/samples/browseable/Timer/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/Timer/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java
new file mode 100644
index 0000000..19967dc
--- /dev/null
+++ b/samples/browseable/Timer/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+/**
+ * Simple {@link LogNode} filter, removes everything except the message.
+ * Useful for situations like on-screen log output where you don't want a lot of metadata displayed,
+ * just easy-to-read message updates as they're happening.
+ */
+public class MessageOnlyLogFilter implements LogNode {
+
+ LogNode mNext;
+
+ /**
+ * Takes the "next" LogNode as a parameter, to simplify chaining.
+ *
+ * @param next The next LogNode in the pipeline.
+ */
+ public MessageOnlyLogFilter(LogNode next) {
+ mNext = next;
+ }
+
+ public MessageOnlyLogFilter() {
+ }
+
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+ if (mNext != null) {
+ getNext().println(Log.NONE, null, msg, null);
+ }
+ }
+
+ /**
+ * Returns the next LogNode in the chain.
+ */
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to..
+ */
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+}
diff --git a/samples/browseable/Timer/Shared/AndroidManifest.xml b/samples/browseable/Timer/Shared/AndroidManifest.xml
new file mode 100644
index 0000000..c332a84
--- /dev/null
+++ b/samples/browseable/Timer/Shared/AndroidManifest.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.timer.common">
+
+ <application android:allowBackup="true"
+ android:label="@string/app_name">
+ </application>
+
+</manifest>
diff --git a/samples/browseable/Timer/Shared/res/values/strings.xml b/samples/browseable/Timer/Shared/res/values/strings.xml
new file mode 100644
index 0000000..0f2bb90
--- /dev/null
+++ b/samples/browseable/Timer/Shared/res/values/strings.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<resources>
+ <string name="app_name">Shared</string>
+</resources>
diff --git a/samples/browseable/Timer/Wearable/AndroidManifest.xml b/samples/browseable/Timer/Wearable/AndroidManifest.xml
new file mode 100644
index 0000000..3dabadc
--- /dev/null
+++ b/samples/browseable/Timer/Wearable/AndroidManifest.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.timer" >
+
+ <uses-sdk android:minSdkVersion="20"
+ android:targetSdkVersion="20" />
+
+ <uses-feature android:name="android.hardware.type.watch" />
+
+ <application
+ android:icon="@mipmap/ic_launcher"
+ android:label="@string/app_name"
+ android:theme="@android:style/Theme.DeviceDefault.Light"
+ android:allowBackup="true">
+
+ <!-- Timer components -->
+ <activity android:name=".SetTimerActivity">
+ <intent-filter>
+ <action android:name="com.android.example.clockwork.timer.TIMER"/>
+ <category android:name="android.intent.category.DEFAULT"/>
+ </intent-filter>
+ <!-- Set a timer voice command -->
+ <intent-filter>
+ <action android:name="android.intent.action.SET_TIMER"/>
+ <category android:name="android.intent.category.DEFAULT"/>
+ </intent-filter>
+ </activity>
+
+ <service android:name=".TimerNotificationService" />
+
+ </application>
+</manifest>
diff --git a/samples/browseable/Timer/Wearable/res/drawable/ic_cc_alarm.png b/samples/browseable/Timer/Wearable/res/drawable/ic_cc_alarm.png
new file mode 100644
index 0000000..ad51ddf
--- /dev/null
+++ b/samples/browseable/Timer/Wearable/res/drawable/ic_cc_alarm.png
Binary files differ
diff --git a/samples/browseable/Timer/Wearable/res/drawable/wl_circle.xml b/samples/browseable/Timer/Wearable/res/drawable/wl_circle.xml
new file mode 100644
index 0000000..a06c53a
--- /dev/null
+++ b/samples/browseable/Timer/Wearable/res/drawable/wl_circle.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="oval">
+ <solid android:color="@color/wl_gray"/>
+</shape>
diff --git a/samples/browseable/Timer/Wearable/res/layout/timer_list_item.xml b/samples/browseable/Timer/Wearable/res/layout/timer_list_item.xml
new file mode 100644
index 0000000..6cef07a
--- /dev/null
+++ b/samples/browseable/Timer/Wearable/res/layout/timer_list_item.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<com.example.android.wearable.timer.WearableListItemLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:gravity="center_vertical"
+ android:layout_width="match_parent"
+ android:layout_height="80dp">
+ <ImageView
+ android:id="@+id/circle"
+ android:layout_height="20dp"
+ android:layout_margin="16dp"
+ android:layout_width="20dp"
+ android:src="@drawable/wl_circle"/>
+ <TextView
+ android:id="@+id/time_text"
+ android:gravity="center_vertical|left"
+ android:layout_width="wrap_content"
+ android:layout_marginRight="16dp"
+ android:layout_height="match_parent"
+ android:fontFamily="sans-serif-condensed-light"
+ android:lineSpacingExtra="-4sp"
+ android:textColor="@color/text_color"
+ android:textSize="16sp"/>
+</com.example.android.wearable.timer.WearableListItemLayout>
\ No newline at end of file
diff --git a/samples/browseable/Timer/Wearable/res/layout/timer_set_timer.xml b/samples/browseable/Timer/Wearable/res/layout/timer_set_timer.xml
new file mode 100644
index 0000000..cdf9e77
--- /dev/null
+++ b/samples/browseable/Timer/Wearable/res/layout/timer_set_timer.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<android.support.wearable.view.WearableListView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/times_list_view"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:scrollbars="none"
+ android:dividerHeight="0dp" />
\ No newline at end of file
diff --git a/samples/browseable/Timer/Wearable/res/mipmap-hdpi/ic_launcher.png b/samples/browseable/Timer/Wearable/res/mipmap-hdpi/ic_launcher.png
new file mode 100644
index 0000000..56f7fc1
--- /dev/null
+++ b/samples/browseable/Timer/Wearable/res/mipmap-hdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/Timer/Wearable/res/mipmap-mdpi/ic_launcher.png b/samples/browseable/Timer/Wearable/res/mipmap-mdpi/ic_launcher.png
new file mode 100644
index 0000000..dec99cd
--- /dev/null
+++ b/samples/browseable/Timer/Wearable/res/mipmap-mdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/Timer/Wearable/res/mipmap-xhdpi/ic_launcher.png b/samples/browseable/Timer/Wearable/res/mipmap-xhdpi/ic_launcher.png
new file mode 100644
index 0000000..48fa0ab
--- /dev/null
+++ b/samples/browseable/Timer/Wearable/res/mipmap-xhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/Timer/Wearable/res/mipmap-xxhdpi/ic_launcher.png b/samples/browseable/Timer/Wearable/res/mipmap-xxhdpi/ic_launcher.png
new file mode 100644
index 0000000..8173921
--- /dev/null
+++ b/samples/browseable/Timer/Wearable/res/mipmap-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/Timer/Wearable/res/mipmap-xxxhdpi/ic_launcher.png b/samples/browseable/Timer/Wearable/res/mipmap-xxxhdpi/ic_launcher.png
new file mode 100644
index 0000000..0dce809
--- /dev/null
+++ b/samples/browseable/Timer/Wearable/res/mipmap-xxxhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/Timer/Wearable/res/values/colors.xml b/samples/browseable/Timer/Wearable/res/values/colors.xml
new file mode 100644
index 0000000..a8bb87b
--- /dev/null
+++ b/samples/browseable/Timer/Wearable/res/values/colors.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <color name="wl_blue">#2878ff</color>
+ <color name="wl_gray">#c1c1c1</color>
+ <color name="text_color">#434343</color>
+</resources>
diff --git a/samples/browseable/Timer/Wearable/res/values/integers.xml b/samples/browseable/Timer/Wearable/res/values/integers.xml
new file mode 100644
index 0000000..c3bc252
--- /dev/null
+++ b/samples/browseable/Timer/Wearable/res/values/integers.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <integer name="action_text_faded_alpha">40</integer>
+</resources>
diff --git a/samples/browseable/Timer/Wearable/res/values/strings.xml b/samples/browseable/Timer/Wearable/res/values/strings.xml
new file mode 100644
index 0000000..f7e05bb
--- /dev/null
+++ b/samples/browseable/Timer/Wearable/res/values/strings.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+ <string name="app_name">Timer Example Wearable App</string>
+ <string name="timer_done">Timer done</string>
+ <string name="timer_time_left">Time remaining</string>
+ <string name="timer_delete">Delete</string>
+ <string name="timer_restart">Restart</string>
+ <plurals name="timer_minutes">
+ <item quantity="one">1 minute</item>
+ <item quantity="other">%d minutes</item>
+ </plurals>
+</resources>
diff --git a/samples/browseable/Timer/Wearable/src/com.example.android.timer/SetTimerActivity.java b/samples/browseable/Timer/Wearable/src/com.example.android.timer/SetTimerActivity.java
new file mode 100644
index 0000000..5285589
--- /dev/null
+++ b/samples/browseable/Timer/Wearable/src/com.example.android.timer/SetTimerActivity.java
@@ -0,0 +1,217 @@
+/*
+ * 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.timer;
+
+import android.app.Activity;
+import android.app.AlarmManager;
+import android.app.Notification;
+import android.app.NotificationManager;
+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.wearable.view.WearableListView;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+import com.example.android.timer.util.Constants;
+import com.example.android.timer.util.TimerFormat;
+
+/** This class sets a timer. */
+public class SetTimerActivity extends Activity implements WearableListView.ClickListener {
+
+ public static final int NUMBER_OF_TIMES = 10;
+ public static final String TAG = "SetTimerActivity";
+
+ private ListViewItem[] mTimeOptions = new ListViewItem[NUMBER_OF_TIMES];
+ private WearableListView mWearableListView;
+
+
+ @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.
+ mWearableListView = (WearableListView) findViewById(R.id.times_list_view);
+ mWearableListView.setAdapter(new TimerWearableListViewAdapter(this));
+ mWearableListView.setClickListener(this);
+ }
+
+ /**
+ * Sets up an alarm (and an associated notification) to go off after <code>duration</code>
+ * milliseconds.
+ */
+ private void setupTimer(long duration) {
+ NotificationManager notifyMgr =
+ ((NotificationManager) getSystemService(NOTIFICATION_SERVICE));
+
+ // 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 onClick(WearableListView.ViewHolder holder) {
+ long duration = mTimeOptions[holder.getPosition()].duration;
+ setupTimer(duration);
+ }
+
+ @Override
+ public void onTopEmptyRegionClick() {
+ }
+
+ 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 Notification.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(NotificationManager 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;
+ }
+ }
+
+ private final class TimerWearableListViewAdapter extends WearableListView.Adapter {
+ private final Context mContext;
+ private final LayoutInflater mInflater;
+
+ private TimerWearableListViewAdapter(Context context) {
+ mContext = context;
+ mInflater = LayoutInflater.from(context);
+ }
+
+ @Override
+ public WearableListView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
+ return new WearableListView.ViewHolder(
+ mInflater.inflate(R.layout.timer_list_item, null));
+ }
+
+ @Override
+ public void onBindViewHolder(WearableListView.ViewHolder holder, int position) {
+ TextView view = (TextView) holder.itemView.findViewById(R.id.time_text);
+ view.setText(mTimeOptions[position].label);
+ holder.itemView.setTag(position);
+ }
+
+ @Override
+ public int getItemCount() {
+ return NUMBER_OF_TIMES;
+ }
+ }
+
+}
diff --git a/samples/browseable/Timer/Wearable/src/com.example.android.timer/TimerNotificationService.java b/samples/browseable/Timer/Wearable/src/com.example.android.timer/TimerNotificationService.java
new file mode 100644
index 0000000..709b949
--- /dev/null
+++ b/samples/browseable/Timer/Wearable/src/com.example.android.timer/TimerNotificationService.java
@@ -0,0 +1,119 @@
+/*
+ * 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.timer;
+
+import android.app.AlarmManager;
+import android.app.IntentService;
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.content.Context;
+import android.content.Intent;
+import android.util.Log;
+
+import com.example.android.timer.util.Constants;
+
+/**
+ * Service class that manages notifications of the timer.
+ */
+public class TimerNotificationService extends IntentService {
+
+ 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() {
+ NotificationManager notifyMgr =
+ ((NotificationManager) getSystemService(NOTIFICATION_SERVICE));
+ 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.
+ NotificationManager notifyMgr =
+ ((NotificationManager) getSystemService(NOTIFICATION_SERVICE));
+ Notification notif = new Notification.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);
+ }
+
+}
diff --git a/samples/browseable/Timer/Wearable/src/com.example.android.timer/WearableListItemLayout.java b/samples/browseable/Timer/Wearable/src/com.example.android.timer/WearableListItemLayout.java
new file mode 100644
index 0000000..739213d
--- /dev/null
+++ b/samples/browseable/Timer/Wearable/src/com.example.android.timer/WearableListItemLayout.java
@@ -0,0 +1,90 @@
+/*
+ * 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.timer;
+
+import android.content.Context;
+import android.graphics.drawable.GradientDrawable;
+import android.support.wearable.view.WearableListView;
+import android.util.AttributeSet;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+public class WearableListItemLayout extends LinearLayout implements WearableListView.Item {
+ private final float mFadedTextAlpha;
+ private final int mFadedCircleColor;
+ private final int mChosenCircleColor;
+ private ImageView mCircle;
+ private float mScale;
+ private TextView mName;
+
+ public WearableListItemLayout(Context context) {
+ this(context, null);
+ }
+
+ public WearableListItemLayout(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public WearableListItemLayout(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ mFadedTextAlpha = getResources().getInteger(R.integer.action_text_faded_alpha) / 100f;
+ mFadedCircleColor = getResources().getColor(R.color.wl_gray);
+ mChosenCircleColor = getResources().getColor(R.color.wl_blue);
+ }
+
+ @Override
+ protected void onFinishInflate() {
+ super.onFinishInflate();
+ mCircle = (ImageView) findViewById(R.id.circle);
+ mName = (TextView) findViewById(R.id.time_text);
+ }
+
+ @Override
+ public float getProximityMinValue() {
+ return 1f;
+ }
+
+ @Override
+ public float getProximityMaxValue() {
+ return 1.6f;
+ }
+
+ @Override
+ public float getCurrentProximityValue() {
+ return mScale;
+ }
+
+ @Override
+ public void setScalingAnimatorValue(float scale) {
+ mScale = scale;
+ mCircle.setScaleX(scale);
+ mCircle.setScaleY(scale);
+ }
+
+ @Override
+ public void onScaleUpStart() {
+ mName.setAlpha(1f);
+ ((GradientDrawable) mCircle.getDrawable()).setColor(mChosenCircleColor);
+ }
+
+ @Override
+ public void onScaleDownStart() {
+ ((GradientDrawable) mCircle.getDrawable()).setColor(mFadedCircleColor);
+ mName.setAlpha(mFadedTextAlpha);
+ }
+}
diff --git a/samples/browseable/Timer/Wearable/src/com.example.android.timer/util/Constants.java b/samples/browseable/Timer/Wearable/src/com.example.android.timer/util/Constants.java
new file mode 100644
index 0000000..18254f1
--- /dev/null
+++ b/samples/browseable/Timer/Wearable/src/com.example.android.timer/util/Constants.java
@@ -0,0 +1,43 @@
+/*
+ * 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.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/browseable/Timer/Wearable/src/com.example.android.timer/util/TimerFormat.java b/samples/browseable/Timer/Wearable/src/com.example.android.timer/util/TimerFormat.java
new file mode 100644
index 0000000..b1c1dab
--- /dev/null
+++ b/samples/browseable/Timer/Wearable/src/com.example.android.timer/util/TimerFormat.java
@@ -0,0 +1,121 @@
+/*
+ * 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.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/browseable/Timer/Wearable/src/com.example.android.timer/util/TimerObj.java b/samples/browseable/Timer/Wearable/src/com.example.android.timer/util/TimerObj.java
new file mode 100644
index 0000000..47f019f
--- /dev/null
+++ b/samples/browseable/Timer/Wearable/src/com.example.android.timer/util/TimerObj.java
@@ -0,0 +1,49 @@
+/*
+ * 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.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/browseable/Timer/_index.jd b/samples/browseable/Timer/_index.jd
new file mode 100644
index 0000000..68941ef
--- /dev/null
+++ b/samples/browseable/Timer/_index.jd
@@ -0,0 +1,10 @@
+page.tags="Timer"
+sample.group=Wearable
+@jd:body
+
+<p>
+
+ This simple wearable app allows the user to set a countdown timer. It runs
+ independently on the wearable with no phone connection.
+
+ </p>
diff --git a/samples/browseable/WatchViewStub/Application/AndroidManifest.xml b/samples/browseable/WatchViewStub/Application/AndroidManifest.xml
new file mode 100644
index 0000000..aa0d790
--- /dev/null
+++ b/samples/browseable/WatchViewStub/Application/AndroidManifest.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.watchviewstub">
+
+ <uses-sdk android:minSdkVersion="19"
+ android:targetSdkVersion="19" />
+
+ <application android:allowBackup="true"
+ android:label="@string/app_name">
+ </application>
+
+</manifest>
+
diff --git a/samples/browseable/WatchViewStub/Application/res/drawable-hdpi/tile.9.png b/samples/browseable/WatchViewStub/Application/res/drawable-hdpi/tile.9.png
new file mode 100644
index 0000000..1358628
--- /dev/null
+++ b/samples/browseable/WatchViewStub/Application/res/drawable-hdpi/tile.9.png
Binary files differ
diff --git a/samples/browseable/WatchViewStub/Application/res/layout/activity_main.xml b/samples/browseable/WatchViewStub/Application/res/layout/activity_main.xml
new file mode 100755
index 0000000..be1aa49
--- /dev/null
+++ b/samples/browseable/WatchViewStub/Application/res/layout/activity_main.xml
@@ -0,0 +1,36 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <LinearLayout style="@style/Widget.SampleMessageTile"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+
+ <TextView style="@style/Widget.SampleMessage"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="@dimen/horizontal_page_margin"
+ android:layout_marginRight="@dimen/horizontal_page_margin"
+ android:layout_marginTop="@dimen/vertical_page_margin"
+ android:layout_marginBottom="@dimen/vertical_page_margin"
+ android:text="@string/intro_message" />
+ </LinearLayout>
+</LinearLayout>
diff --git a/samples/browseable/WatchViewStub/Application/res/values-sw600dp/template-dimens.xml b/samples/browseable/WatchViewStub/Application/res/values-sw600dp/template-dimens.xml
new file mode 100644
index 0000000..22074a2
--- /dev/null
+++ b/samples/browseable/WatchViewStub/Application/res/values-sw600dp/template-dimens.xml
@@ -0,0 +1,24 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Semantic definitions -->
+
+ <dimen name="horizontal_page_margin">@dimen/margin_huge</dimen>
+ <dimen name="vertical_page_margin">@dimen/margin_medium</dimen>
+
+</resources>
diff --git a/samples/browseable/WatchViewStub/Application/res/values-sw600dp/template-styles.xml b/samples/browseable/WatchViewStub/Application/res/values-sw600dp/template-styles.xml
new file mode 100644
index 0000000..03d1974
--- /dev/null
+++ b/samples/browseable/WatchViewStub/Application/res/values-sw600dp/template-styles.xml
@@ -0,0 +1,25 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <style name="Widget.SampleMessage">
+ <item name="android:textAppearance">?android:textAppearanceLarge</item>
+ <item name="android:lineSpacingMultiplier">1.2</item>
+ <item name="android:shadowDy">-6.5</item>
+ </style>
+
+</resources>
diff --git a/samples/browseable/WatchViewStub/Application/res/values-v11/template-styles.xml b/samples/browseable/WatchViewStub/Application/res/values-v11/template-styles.xml
new file mode 100644
index 0000000..8c1ea66
--- /dev/null
+++ b/samples/browseable/WatchViewStub/Application/res/values-v11/template-styles.xml
@@ -0,0 +1,22 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Activity themes -->
+ <style name="Theme.Base" parent="android:Theme.Holo.Light" />
+
+</resources>
diff --git a/samples/browseable/WatchViewStub/Application/res/values/base-strings.xml b/samples/browseable/WatchViewStub/Application/res/values/base-strings.xml
new file mode 100644
index 0000000..d653382
--- /dev/null
+++ b/samples/browseable/WatchViewStub/Application/res/values/base-strings.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 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.
+-->
+<resources>
+ <string name="app_name">WatchViewStub</string>
+ <string name="intro_message">
+ <![CDATA[
+
+
+ This sample demonstrates how to specify different layouts for round and rectangular screens.
+
+
+ ]]>
+ </string>
+</resources>
diff --git a/samples/browseable/WatchViewStub/Application/res/values/template-dimens.xml b/samples/browseable/WatchViewStub/Application/res/values/template-dimens.xml
new file mode 100644
index 0000000..39e710b
--- /dev/null
+++ b/samples/browseable/WatchViewStub/Application/res/values/template-dimens.xml
@@ -0,0 +1,32 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Define standard dimensions to comply with Holo-style grids and rhythm. -->
+
+ <dimen name="margin_tiny">4dp</dimen>
+ <dimen name="margin_small">8dp</dimen>
+ <dimen name="margin_medium">16dp</dimen>
+ <dimen name="margin_large">32dp</dimen>
+ <dimen name="margin_huge">64dp</dimen>
+
+ <!-- Semantic definitions -->
+
+ <dimen name="horizontal_page_margin">@dimen/margin_medium</dimen>
+ <dimen name="vertical_page_margin">@dimen/margin_medium</dimen>
+
+</resources>
diff --git a/samples/browseable/WatchViewStub/Application/res/values/template-styles.xml b/samples/browseable/WatchViewStub/Application/res/values/template-styles.xml
new file mode 100644
index 0000000..6e7d593
--- /dev/null
+++ b/samples/browseable/WatchViewStub/Application/res/values/template-styles.xml
@@ -0,0 +1,42 @@
+<!--
+ Copyright 2013 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.
+ -->
+
+<resources>
+
+ <!-- Activity themes -->
+
+ <style name="Theme.Base" parent="android:Theme.Light" />
+
+ <style name="Theme.Sample" parent="Theme.Base" />
+
+ <style name="AppTheme" parent="Theme.Sample" />
+ <!-- Widget styling -->
+
+ <style name="Widget" />
+
+ <style name="Widget.SampleMessage">
+ <item name="android:textAppearance">?android:textAppearanceMedium</item>
+ <item name="android:lineSpacingMultiplier">1.1</item>
+ </style>
+
+ <style name="Widget.SampleMessageTile">
+ <item name="android:background">@drawable/tile</item>
+ <item name="android:shadowColor">#7F000000</item>
+ <item name="android:shadowDy">-3.5</item>
+ <item name="android:shadowRadius">2</item>
+ </style>
+
+</resources>
diff --git a/samples/browseable/WatchViewStub/Application/src/com.example.android.common/activities/SampleActivityBase.java b/samples/browseable/WatchViewStub/Application/src/com.example.android.common/activities/SampleActivityBase.java
new file mode 100644
index 0000000..3228927
--- /dev/null
+++ b/samples/browseable/WatchViewStub/Application/src/com.example.android.common/activities/SampleActivityBase.java
@@ -0,0 +1,52 @@
+/*
+* Copyright 2013 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.common.activities;
+
+import android.os.Bundle;
+import android.support.v4.app.FragmentActivity;
+
+import com.example.android.common.logger.Log;
+import com.example.android.common.logger.LogWrapper;
+
+/**
+ * Base launcher activity, to handle most of the common plumbing for samples.
+ */
+public class SampleActivityBase extends FragmentActivity {
+
+ public static final String TAG = "SampleActivityBase";
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ initializeLogging();
+ }
+
+ /** Set up targets to receive log data */
+ public void initializeLogging() {
+ // Using Log, front-end to the logging chain, emulates android.util.log method signatures.
+ // Wraps Android's native log framework
+ LogWrapper logWrapper = new LogWrapper();
+ Log.setLogNode(logWrapper);
+
+ Log.i(TAG, "Ready");
+ }
+}
diff --git a/samples/browseable/WatchViewStub/Application/src/com.example.android.common/logger/Log.java b/samples/browseable/WatchViewStub/Application/src/com.example.android.common/logger/Log.java
new file mode 100644
index 0000000..17503c5
--- /dev/null
+++ b/samples/browseable/WatchViewStub/Application/src/com.example.android.common/logger/Log.java
@@ -0,0 +1,236 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+/**
+ * Helper class for a list (or tree) of LoggerNodes.
+ *
+ * <p>When this is set as the head of the list,
+ * an instance of it can function as a drop-in replacement for {@link android.util.Log}.
+ * Most of the methods in this class server only to map a method call in Log to its equivalent
+ * in LogNode.</p>
+ */
+public class Log {
+ // Grabbing the native values from Android's native logging facilities,
+ // to make for easy migration and interop.
+ public static final int NONE = -1;
+ public static final int VERBOSE = android.util.Log.VERBOSE;
+ public static final int DEBUG = android.util.Log.DEBUG;
+ public static final int INFO = android.util.Log.INFO;
+ public static final int WARN = android.util.Log.WARN;
+ public static final int ERROR = android.util.Log.ERROR;
+ public static final int ASSERT = android.util.Log.ASSERT;
+
+ // Stores the beginning of the LogNode topology.
+ private static LogNode mLogNode;
+
+ /**
+ * Returns the next LogNode in the linked list.
+ */
+ public static LogNode getLogNode() {
+ return mLogNode;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to.
+ */
+ public static void setLogNode(LogNode node) {
+ mLogNode = node;
+ }
+
+ /**
+ * Instructs the LogNode to print the log data provided. Other LogNodes can
+ * be chained to the end of the LogNode as desired.
+ *
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void println(int priority, String tag, String msg, Throwable tr) {
+ if (mLogNode != null) {
+ mLogNode.println(priority, tag, msg, tr);
+ }
+ }
+
+ /**
+ * Instructs the LogNode to print the log data provided. Other LogNodes can
+ * be chained to the end of the LogNode as desired.
+ *
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ */
+ public static void println(int priority, String tag, String msg) {
+ println(priority, tag, msg, null);
+ }
+
+ /**
+ * Prints a message at VERBOSE priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void v(String tag, String msg, Throwable tr) {
+ println(VERBOSE, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at VERBOSE priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void v(String tag, String msg) {
+ v(tag, msg, null);
+ }
+
+
+ /**
+ * Prints a message at DEBUG priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void d(String tag, String msg, Throwable tr) {
+ println(DEBUG, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at DEBUG priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void d(String tag, String msg) {
+ d(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at INFO priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void i(String tag, String msg, Throwable tr) {
+ println(INFO, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at INFO priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void i(String tag, String msg) {
+ i(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void w(String tag, String msg, Throwable tr) {
+ println(WARN, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void w(String tag, String msg) {
+ w(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at WARN priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void w(String tag, Throwable tr) {
+ w(tag, null, tr);
+ }
+
+ /**
+ * Prints a message at ERROR priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void e(String tag, String msg, Throwable tr) {
+ println(ERROR, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at ERROR priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void e(String tag, String msg) {
+ e(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void wtf(String tag, String msg, Throwable tr) {
+ println(ASSERT, tag, msg, tr);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged.
+ */
+ public static void wtf(String tag, String msg) {
+ wtf(tag, msg, null);
+ }
+
+ /**
+ * Prints a message at ASSERT priority.
+ *
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public static void wtf(String tag, Throwable tr) {
+ wtf(tag, null, tr);
+ }
+}
diff --git a/samples/browseable/WatchViewStub/Application/src/com.example.android.common/logger/LogFragment.java b/samples/browseable/WatchViewStub/Application/src/com.example.android.common/logger/LogFragment.java
new file mode 100644
index 0000000..b302acd
--- /dev/null
+++ b/samples/browseable/WatchViewStub/Application/src/com.example.android.common/logger/LogFragment.java
@@ -0,0 +1,109 @@
+/*
+* Copyright 2013 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.
+*/
+/*
+ * Copyright 2013 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.common.logger;
+
+import android.graphics.Typeface;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ScrollView;
+
+/**
+ * Simple fraggment which contains a LogView and uses is to output log data it receives
+ * through the LogNode interface.
+ */
+public class LogFragment extends Fragment {
+
+ private LogView mLogView;
+ private ScrollView mScrollView;
+
+ public LogFragment() {}
+
+ public View inflateViews() {
+ mScrollView = new ScrollView(getActivity());
+ ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT);
+ mScrollView.setLayoutParams(scrollParams);
+
+ mLogView = new LogView(getActivity());
+ ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams);
+ logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
+ mLogView.setLayoutParams(logParams);
+ mLogView.setClickable(true);
+ mLogView.setFocusable(true);
+ mLogView.setTypeface(Typeface.MONOSPACE);
+
+ // Want to set padding as 16 dips, setPadding takes pixels. Hooray math!
+ int paddingDips = 16;
+ double scale = getResources().getDisplayMetrics().density;
+ int paddingPixels = (int) ((paddingDips * (scale)) + .5);
+ mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels);
+ mLogView.setCompoundDrawablePadding(paddingPixels);
+
+ mLogView.setGravity(Gravity.BOTTOM);
+ mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium);
+
+ mScrollView.addView(mLogView);
+ return mScrollView;
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+
+ View result = inflateViews();
+
+ mLogView.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {}
+
+ @Override
+ public void afterTextChanged(Editable s) {
+ mScrollView.fullScroll(ScrollView.FOCUS_DOWN);
+ }
+ });
+ return result;
+ }
+
+ public LogView getLogView() {
+ return mLogView;
+ }
+}
\ No newline at end of file
diff --git a/samples/browseable/WatchViewStub/Application/src/com.example.android.common/logger/LogNode.java b/samples/browseable/WatchViewStub/Application/src/com.example.android.common/logger/LogNode.java
new file mode 100644
index 0000000..bc37cab
--- /dev/null
+++ b/samples/browseable/WatchViewStub/Application/src/com.example.android.common/logger/LogNode.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2012 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.common.logger;
+
+/**
+ * Basic interface for a logging system that can output to one or more targets.
+ * Note that in addition to classes that will output these logs in some format,
+ * one can also implement this interface over a filter and insert that in the chain,
+ * such that no targets further down see certain data, or see manipulated forms of the data.
+ * You could, for instance, write a "ToHtmlLoggerNode" that just converted all the log data
+ * it received to HTML and sent it along to the next node in the chain, without printing it
+ * anywhere.
+ */
+public interface LogNode {
+
+ /**
+ * Instructs first LogNode in the list to print the log data provided.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ public void println(int priority, String tag, String msg, Throwable tr);
+
+}
diff --git a/samples/browseable/WatchViewStub/Application/src/com.example.android.common/logger/LogView.java b/samples/browseable/WatchViewStub/Application/src/com.example.android.common/logger/LogView.java
new file mode 100644
index 0000000..c01542b
--- /dev/null
+++ b/samples/browseable/WatchViewStub/Application/src/com.example.android.common/logger/LogView.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+import android.app.Activity;
+import android.content.Context;
+import android.util.*;
+import android.widget.TextView;
+
+/** Simple TextView which is used to output log data received through the LogNode interface.
+*/
+public class LogView extends TextView implements LogNode {
+
+ public LogView(Context context) {
+ super(context);
+ }
+
+ public LogView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public LogView(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ /**
+ * Formats the log data and prints it out to the LogView.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+
+
+ String priorityStr = null;
+
+ // For the purposes of this View, we want to print the priority as readable text.
+ switch(priority) {
+ case android.util.Log.VERBOSE:
+ priorityStr = "VERBOSE";
+ break;
+ case android.util.Log.DEBUG:
+ priorityStr = "DEBUG";
+ break;
+ case android.util.Log.INFO:
+ priorityStr = "INFO";
+ break;
+ case android.util.Log.WARN:
+ priorityStr = "WARN";
+ break;
+ case android.util.Log.ERROR:
+ priorityStr = "ERROR";
+ break;
+ case android.util.Log.ASSERT:
+ priorityStr = "ASSERT";
+ break;
+ default:
+ break;
+ }
+
+ // Handily, the Log class has a facility for converting a stack trace into a usable string.
+ String exceptionStr = null;
+ if (tr != null) {
+ exceptionStr = android.util.Log.getStackTraceString(tr);
+ }
+
+ // Take the priority, tag, message, and exception, and concatenate as necessary
+ // into one usable line of text.
+ final StringBuilder outputBuilder = new StringBuilder();
+
+ String delimiter = "\t";
+ appendIfNotNull(outputBuilder, priorityStr, delimiter);
+ appendIfNotNull(outputBuilder, tag, delimiter);
+ appendIfNotNull(outputBuilder, msg, delimiter);
+ appendIfNotNull(outputBuilder, exceptionStr, delimiter);
+
+ // In case this was originally called from an AsyncTask or some other off-UI thread,
+ // make sure the update occurs within the UI thread.
+ ((Activity) getContext()).runOnUiThread( (new Thread(new Runnable() {
+ @Override
+ public void run() {
+ // Display the text we just generated within the LogView.
+ appendToLog(outputBuilder.toString());
+ }
+ })));
+
+ if (mNext != null) {
+ mNext.println(priority, tag, msg, tr);
+ }
+ }
+
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+ /** Takes a string and adds to it, with a separator, if the bit to be added isn't null. Since
+ * the logger takes so many arguments that might be null, this method helps cut out some of the
+ * agonizing tedium of writing the same 3 lines over and over.
+ * @param source StringBuilder containing the text to append to.
+ * @param addStr The String to append
+ * @param delimiter The String to separate the source and appended strings. A tab or comma,
+ * for instance.
+ * @return The fully concatenated String as a StringBuilder
+ */
+ private StringBuilder appendIfNotNull(StringBuilder source, String addStr, String delimiter) {
+ if (addStr != null) {
+ if (addStr.length() == 0) {
+ delimiter = "";
+ }
+
+ return source.append(addStr).append(delimiter);
+ }
+ return source;
+ }
+
+ // The next LogNode in the chain.
+ LogNode mNext;
+
+ /** Outputs the string as a new line of log data in the LogView. */
+ public void appendToLog(String s) {
+ append("\n" + s);
+ }
+
+
+}
diff --git a/samples/browseable/WatchViewStub/Application/src/com.example.android.common/logger/LogWrapper.java b/samples/browseable/WatchViewStub/Application/src/com.example.android.common/logger/LogWrapper.java
new file mode 100644
index 0000000..16a9e7b
--- /dev/null
+++ b/samples/browseable/WatchViewStub/Application/src/com.example.android.common/logger/LogWrapper.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2012 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.common.logger;
+
+import android.util.Log;
+
+/**
+ * Helper class which wraps Android's native Log utility in the Logger interface. This way
+ * normal DDMS output can be one of the many targets receiving and outputting logs simultaneously.
+ */
+public class LogWrapper implements LogNode {
+
+ // For piping: The next node to receive Log data after this one has done its work.
+ private LogNode mNext;
+
+ /**
+ * Returns the next LogNode in the linked list.
+ */
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to..
+ */
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+ /**
+ * Prints data out to the console using Android's native log mechanism.
+ * @param priority Log level of the data being logged. Verbose, Error, etc.
+ * @param tag Tag for for the log data. Can be used to organize log statements.
+ * @param msg The actual message to be logged. The actual message to be logged.
+ * @param tr If an exception was thrown, this can be sent along for the logging facilities
+ * to extract and print useful information.
+ */
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+ // There actually are log methods that don't take a msg parameter. For now,
+ // if that's the case, just convert null to the empty string and move on.
+ String useMsg = msg;
+ if (useMsg == null) {
+ useMsg = "";
+ }
+
+ // If an exeption was provided, convert that exception to a usable string and attach
+ // it to the end of the msg method.
+ if (tr != null) {
+ msg += "\n" + Log.getStackTraceString(tr);
+ }
+
+ // This is functionally identical to Log.x(tag, useMsg);
+ // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg)
+ Log.println(priority, tag, useMsg);
+
+ // If this isn't the last node in the chain, move things along.
+ if (mNext != null) {
+ mNext.println(priority, tag, msg, tr);
+ }
+ }
+}
diff --git a/samples/browseable/WatchViewStub/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java b/samples/browseable/WatchViewStub/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java
new file mode 100644
index 0000000..19967dc
--- /dev/null
+++ b/samples/browseable/WatchViewStub/Application/src/com.example.android.common/logger/MessageOnlyLogFilter.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2013 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.common.logger;
+
+/**
+ * Simple {@link LogNode} filter, removes everything except the message.
+ * Useful for situations like on-screen log output where you don't want a lot of metadata displayed,
+ * just easy-to-read message updates as they're happening.
+ */
+public class MessageOnlyLogFilter implements LogNode {
+
+ LogNode mNext;
+
+ /**
+ * Takes the "next" LogNode as a parameter, to simplify chaining.
+ *
+ * @param next The next LogNode in the pipeline.
+ */
+ public MessageOnlyLogFilter(LogNode next) {
+ mNext = next;
+ }
+
+ public MessageOnlyLogFilter() {
+ }
+
+ @Override
+ public void println(int priority, String tag, String msg, Throwable tr) {
+ if (mNext != null) {
+ getNext().println(Log.NONE, null, msg, null);
+ }
+ }
+
+ /**
+ * Returns the next LogNode in the chain.
+ */
+ public LogNode getNext() {
+ return mNext;
+ }
+
+ /**
+ * Sets the LogNode data will be sent to..
+ */
+ public void setNext(LogNode node) {
+ mNext = node;
+ }
+
+}
diff --git a/samples/browseable/WatchViewStub/Shared/AndroidManifest.xml b/samples/browseable/WatchViewStub/Shared/AndroidManifest.xml
new file mode 100644
index 0000000..846fa9d
--- /dev/null
+++ b/samples/browseable/WatchViewStub/Shared/AndroidManifest.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2013 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.watchviewstub.common">
+
+ <application android:allowBackup="true"
+ android:label="@string/app_name">
+ </application>
+
+</manifest>
diff --git a/samples/browseable/WatchViewStub/Shared/res/values/strings.xml b/samples/browseable/WatchViewStub/Shared/res/values/strings.xml
new file mode 100644
index 0000000..0f2bb90
--- /dev/null
+++ b/samples/browseable/WatchViewStub/Shared/res/values/strings.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<resources>
+ <string name="app_name">Shared</string>
+</resources>
diff --git a/samples/browseable/WatchViewStub/Wearable/AndroidManifest.xml b/samples/browseable/WatchViewStub/Wearable/AndroidManifest.xml
new file mode 100644
index 0000000..5b33044
--- /dev/null
+++ b/samples/browseable/WatchViewStub/Wearable/AndroidManifest.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.watchviewstub" >
+
+ <uses-sdk android:minSdkVersion="20"
+ android:targetSdkVersion="20" />
+
+ <uses-feature android:name="android.hardware.type.watch" />
+
+ <application
+ android:allowBackup="true"
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name"
+ android:theme="@android:style/Theme.DeviceDefault">
+ <activity
+ android:name="com.example.android.watchviewstub.MainActivity"
+ android:label="@string/app_name">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ </activity>
+ </application>
+
+</manifest>
diff --git a/samples/browseable/WatchViewStub/Wearable/res/drawable-hdpi/ic_launcher.png b/samples/browseable/WatchViewStub/Wearable/res/drawable-hdpi/ic_launcher.png
new file mode 100755
index 0000000..589f229
--- /dev/null
+++ b/samples/browseable/WatchViewStub/Wearable/res/drawable-hdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/WatchViewStub/Wearable/res/drawable-mdpi/ic_launcher.png b/samples/browseable/WatchViewStub/Wearable/res/drawable-mdpi/ic_launcher.png
new file mode 100755
index 0000000..77dd571
--- /dev/null
+++ b/samples/browseable/WatchViewStub/Wearable/res/drawable-mdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/WatchViewStub/Wearable/res/drawable-xhdpi/ic_launcher.png b/samples/browseable/WatchViewStub/Wearable/res/drawable-xhdpi/ic_launcher.png
new file mode 100755
index 0000000..fe34ebe
--- /dev/null
+++ b/samples/browseable/WatchViewStub/Wearable/res/drawable-xhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/WatchViewStub/Wearable/res/drawable-xxhdpi/ic_launcher.png b/samples/browseable/WatchViewStub/Wearable/res/drawable-xxhdpi/ic_launcher.png
new file mode 100755
index 0000000..ab80bcd
--- /dev/null
+++ b/samples/browseable/WatchViewStub/Wearable/res/drawable-xxhdpi/ic_launcher.png
Binary files differ
diff --git a/samples/browseable/WatchViewStub/Wearable/res/drawable/rect_background.xml b/samples/browseable/WatchViewStub/Wearable/res/drawable/rect_background.xml
new file mode 100644
index 0000000..eeda78f
--- /dev/null
+++ b/samples/browseable/WatchViewStub/Wearable/res/drawable/rect_background.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="rectangle">
+ <corners android:radius="@dimen/rect_corner_radius"/>
+ <gradient android:startColor="@color/green"
+ android:endColor="@color/blue"
+ android:angle="45"/>
+</shape>
diff --git a/samples/browseable/WatchViewStub/Wearable/res/drawable/round_background.xml b/samples/browseable/WatchViewStub/Wearable/res/drawable/round_background.xml
new file mode 100644
index 0000000..432b0d2
--- /dev/null
+++ b/samples/browseable/WatchViewStub/Wearable/res/drawable/round_background.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="ring"
+ android:useLevel="false" >
+ <gradient android:startColor="@color/green"
+ android:endColor="@color/blue"/>
+</shape>
diff --git a/samples/browseable/WatchViewStub/Wearable/res/layout/main_activity.xml b/samples/browseable/WatchViewStub/Wearable/res/layout/main_activity.xml
new file mode 100644
index 0000000..e9745bc
--- /dev/null
+++ b/samples/browseable/WatchViewStub/Wearable/res/layout/main_activity.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<FrameLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <android.support.wearable.view.WatchViewStub
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:id="@+id/stub"
+ app:rectLayout="@layout/rect_layout"
+ app:roundLayout="@layout/round_layout"/>
+
+ <android.support.wearable.view.DismissOverlayView
+ android:id="@+id/dismiss_overlay"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" />
+
+</FrameLayout>
+
diff --git a/samples/browseable/WatchViewStub/Wearable/res/layout/rect_layout.xml b/samples/browseable/WatchViewStub/Wearable/res/layout/rect_layout.xml
new file mode 100644
index 0000000..7b0006c
--- /dev/null
+++ b/samples/browseable/WatchViewStub/Wearable/res/layout/rect_layout.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:id="@+id/rect_layout"
+ android:background="@drawable/rect_background"
+ android:onClick="onLayoutClicked">
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/rect_string"
+ android:textColor="@color/red"
+ android:textSize="@dimen/text_size"
+ android:gravity="center"
+ android:layout_centerInParent="true"/>
+</RelativeLayout>
diff --git a/samples/browseable/WatchViewStub/Wearable/res/layout/round_layout.xml b/samples/browseable/WatchViewStub/Wearable/res/layout/round_layout.xml
new file mode 100644
index 0000000..d7a55f6
--- /dev/null
+++ b/samples/browseable/WatchViewStub/Wearable/res/layout/round_layout.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:id="@+id/round_layout"
+ android:background="@drawable/round_background"
+ android:onClick="onLayoutClicked">
+ <TextView
+ android:layout_width="@dimen/round_text_view_width"
+ android:layout_height="wrap_content"
+ android:text="@string/round_string"
+ android:textColor="@color/red"
+ android:textSize="@dimen/text_size"
+ android:gravity="center"
+ android:layout_centerInParent="true"/>
+</RelativeLayout>
diff --git a/samples/browseable/WatchViewStub/Wearable/res/values/dimens.xml b/samples/browseable/WatchViewStub/Wearable/res/values/dimens.xml
new file mode 100644
index 0000000..37148a2
--- /dev/null
+++ b/samples/browseable/WatchViewStub/Wearable/res/values/dimens.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<resources>
+ <dimen name="rect_corner_radius">20dp</dimen>
+ <dimen name="round_text_view_width">150dp</dimen>
+ <dimen name="text_size">24sp</dimen>
+</resources>
diff --git a/samples/browseable/WatchViewStub/Wearable/res/values/strings.xml b/samples/browseable/WatchViewStub/Wearable/res/values/strings.xml
new file mode 100644
index 0000000..00cc6c6
--- /dev/null
+++ b/samples/browseable/WatchViewStub/Wearable/res/values/strings.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources>
+
+ <string name="app_name">WatchViewStub Sample</string>
+ <string name="round_string">Your screen is round!</string>
+ <string name="rect_string">Your screen is rectangular!</string>
+
+</resources>
diff --git a/samples/browseable/WatchViewStub/Wearable/src/com.example.android.watchviewstub/MainActivity.java b/samples/browseable/WatchViewStub/Wearable/src/com.example.android.watchviewstub/MainActivity.java
new file mode 100644
index 0000000..1e931dc
--- /dev/null
+++ b/samples/browseable/WatchViewStub/Wearable/src/com.example.android.watchviewstub/MainActivity.java
@@ -0,0 +1,85 @@
+/*
+ * 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.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();
+ }
+ }
+}
diff --git a/samples/browseable/WatchViewStub/_index.jd b/samples/browseable/WatchViewStub/_index.jd
new file mode 100644
index 0000000..7341f92
--- /dev/null
+++ b/samples/browseable/WatchViewStub/_index.jd
@@ -0,0 +1,9 @@
+page.tags="WatchViewStub"
+sample.group=Wearable
+@jd:body
+
+<p>
+
+ This sample demonstrates how to specify different layouts for round and rectangular screens.
+
+ </p>