aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Walker <jewalker@google.com>2016-04-13 17:45:13 -0700
committerJeremy Walker <jewalker@google.com>2016-04-14 09:43:21 -0700
commit603b4572af85cf4fe40c7dfe53fb0938dcc4516c (patch)
tree66cf9d982d2c52e19516271b0f035a26d4f1f09f
parent95207a700ac94fe94f2dce1be96c785c89054f5a (diff)
downloadandroid-603b4572af85cf4fe40c7dfe53fb0938dcc4516c.tar.gz
Removes use of NodeAPI and BIND_LISTENER.
Change-Id: Icca739e40474d8c18ddd98594bf2c314b3e24433
-rw-r--r--wearable/wear/AgendaData/Application/src/main/java/com/example/android/wearable/agendadata/MainActivity.java44
-rw-r--r--wearable/wear/AgendaData/Wearable/src/main/AndroidManifest.xml5
-rw-r--r--wearable/wear/AgendaData/Wearable/src/main/java/com/example/android/wearable/agendadata/Constants.java2
-rw-r--r--wearable/wear/AgendaData/Wearable/src/main/java/com/example/android/wearable/agendadata/DeleteService.java15
-rw-r--r--wearable/wear/AgendaData/Wearable/src/main/java/com/example/android/wearable/agendadata/HomeListenerService.java70
-rw-r--r--wearable/wear/AgendaData/gradle/wrapper/gradle-wrapper.properties4
-rw-r--r--wearable/wear/AgendaData/template-params.xml2
7 files changed, 63 insertions, 79 deletions
diff --git a/wearable/wear/AgendaData/Application/src/main/java/com/example/android/wearable/agendadata/MainActivity.java b/wearable/wear/AgendaData/Application/src/main/java/com/example/android/wearable/agendadata/MainActivity.java
index 6a9678a6..1492c813 100644
--- a/wearable/wear/AgendaData/Application/src/main/java/com/example/android/wearable/agendadata/MainActivity.java
+++ b/wearable/wear/AgendaData/Application/src/main/java/com/example/android/wearable/agendadata/MainActivity.java
@@ -41,8 +41,6 @@ import com.google.android.gms.common.api.ResultCallback;
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;
/**
@@ -51,7 +49,6 @@ import com.google.android.gms.wearable.Wearable;
* permissions as well.
*/
public class MainActivity extends AppCompatActivity implements
- NodeApi.NodeListener,
ConnectionCallbacks,
OnConnectionFailedListener,
ActivityCompat.OnRequestPermissionsResultCallback {
@@ -66,11 +63,11 @@ public class MainActivity extends AppCompatActivity implements
private GoogleApiClient mGoogleApiClient;
private boolean mResolvingError = false;
- private TextView mLogTextView;
- ScrollView mScroller;
-
private View mLayout;
+ private TextView mLogTextView;
+ private ScrollView mScroller;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -98,10 +95,10 @@ public class MainActivity extends AppCompatActivity implements
@Override
protected void onStop() {
- if (mGoogleApiClient.isConnected()) {
- Wearable.NodeApi.removeListener(mGoogleApiClient, this);
+ if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) {
+ mGoogleApiClient.disconnect();
}
- mGoogleApiClient.disconnect();
+
super.onStop();
}
@@ -132,10 +129,6 @@ public class MainActivity extends AppCompatActivity implements
}
- private void pushCalendarToWear() {
- startService(new Intent(this, CalendarQueryService.class));
- }
-
/*
* Requests Calendar and Contact permissions.
* If the permission has been denied previously, a SnackBar will prompt the user to grant the
@@ -190,7 +183,9 @@ public class MainActivity extends AppCompatActivity implements
// END_INCLUDE(calendar_and_contact_permissions_request)
}
-
+ private void pushCalendarToWear() {
+ startService(new Intent(this, CalendarQueryService.class));
+ }
public void onDeleteEventsClicked(View view) {
if (mGoogleApiClient.isConnected()) {
@@ -246,27 +241,18 @@ public class MainActivity extends AppCompatActivity implements
}
@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
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "onConnectionSuspended(): Cause id: " + cause);
+ }
}
@Override
@@ -274,9 +260,7 @@ public class MainActivity extends AppCompatActivity implements
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;
@@ -359,4 +343,4 @@ public class MainActivity extends AppCompatActivity implements
}
});
}
-}
+} \ No newline at end of file
diff --git a/wearable/wear/AgendaData/Wearable/src/main/AndroidManifest.xml b/wearable/wear/AgendaData/Wearable/src/main/AndroidManifest.xml
index e6dbab70..336fbe65 100644
--- a/wearable/wear/AgendaData/Wearable/src/main/AndroidManifest.xml
+++ b/wearable/wear/AgendaData/Wearable/src/main/AndroidManifest.xml
@@ -18,7 +18,7 @@
package="com.example.android.wearable.agendadata" >
<uses-sdk android:minSdkVersion="20"
- android:targetSdkVersion="22" />
+ android:targetSdkVersion="23" />
<uses-feature android:name="android.hardware.type.watch" />
@@ -34,7 +34,8 @@
<service
android:name="com.example.android.wearable.agendadata.HomeListenerService" >
<intent-filter>
- <action android:name="com.google.android.gms.wearable.BIND_LISTENER" />
+ <action android:name="com.google.android.gms.wearable.DATA_CHANGED" />
+ <data android:scheme="wear" android:host="*"/>
</intent-filter>
</service>
diff --git a/wearable/wear/AgendaData/Wearable/src/main/java/com/example/android/wearable/agendadata/Constants.java b/wearable/wear/AgendaData/Wearable/src/main/java/com/example/android/wearable/agendadata/Constants.java
index 176a21eb..aa15b6a8 100644
--- a/wearable/wear/AgendaData/Wearable/src/main/java/com/example/android/wearable/agendadata/Constants.java
+++ b/wearable/wear/AgendaData/Wearable/src/main/java/com/example/android/wearable/agendadata/Constants.java
@@ -32,4 +32,4 @@ public final class Constants {
public static final String PROFILE_PIC = "profile_pic";
public static final String EXTRA_SILENT = "silent";
-}
+} \ No newline at end of file
diff --git a/wearable/wear/AgendaData/Wearable/src/main/java/com/example/android/wearable/agendadata/DeleteService.java b/wearable/wear/AgendaData/Wearable/src/main/java/com/example/android/wearable/agendadata/DeleteService.java
index 86aafe03..bc4180e9 100644
--- a/wearable/wear/AgendaData/Wearable/src/main/java/com/example/android/wearable/agendadata/DeleteService.java
+++ b/wearable/wear/AgendaData/Wearable/src/main/java/com/example/android/wearable/agendadata/DeleteService.java
@@ -16,9 +16,6 @@
package com.example.android.wearable.agendadata;
-import static com.example.android.wearable.agendadata.Constants.TAG;
-import static com.example.android.wearable.agendadata.Constants.EXTRA_SILENT;
-
import android.app.IntentService;
import android.content.Intent;
import android.net.Uri;
@@ -26,6 +23,9 @@ import android.os.Bundle;
import android.support.wearable.activity.ConfirmationActivity;
import android.util.Log;
+import static com.example.android.wearable.agendadata.Constants.TAG;
+import static com.example.android.wearable.agendadata.Constants.EXTRA_SILENT;
+
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.wearable.DataApi;
@@ -105,14 +105,23 @@ public class DeleteService extends IntentService implements GoogleApiClient.Conn
@Override
public void onConnected(Bundle connectionHint) {
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "onConnected: " + connectionHint);
+ }
}
@Override
public void onConnectionSuspended(int cause) {
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "onConnectionSuspended: " + cause);
+ }
}
@Override
public void onConnectionFailed(ConnectionResult result) {
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "onConnectionFailed: " + result);
+ }
}
}
diff --git a/wearable/wear/AgendaData/Wearable/src/main/java/com/example/android/wearable/agendadata/HomeListenerService.java b/wearable/wear/AgendaData/Wearable/src/main/java/com/example/android/wearable/agendadata/HomeListenerService.java
index 02a38611..909c27d9 100644
--- a/wearable/wear/AgendaData/Wearable/src/main/java/com/example/android/wearable/agendadata/HomeListenerService.java
+++ b/wearable/wear/AgendaData/Wearable/src/main/java/com/example/android/wearable/agendadata/HomeListenerService.java
@@ -16,16 +16,6 @@
package com.example.android.wearable.agendadata;
-import static com.example.android.wearable.agendadata.Constants.TAG;
-import static com.example.android.wearable.agendadata.Constants.EXTRA_SILENT;
-
-import static com.example.android.wearable.agendadata.Constants.ALL_DAY;
-import static com.example.android.wearable.agendadata.Constants.BEGIN;
-import static com.example.android.wearable.agendadata.Constants.DESCRIPTION;
-import static com.example.android.wearable.agendadata.Constants.END;
-import static com.example.android.wearable.agendadata.Constants.PROFILE_PIC;
-import static com.example.android.wearable.agendadata.Constants.TITLE;
-
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
@@ -37,6 +27,15 @@ import android.text.TextUtils;
import android.text.format.DateFormat;
import android.util.Log;
+import static com.example.android.wearable.agendadata.Constants.ALL_DAY;
+import static com.example.android.wearable.agendadata.Constants.BEGIN;
+import static com.example.android.wearable.agendadata.Constants.DESCRIPTION;
+import static com.example.android.wearable.agendadata.Constants.EXTRA_SILENT;
+import static com.example.android.wearable.agendadata.Constants.END;
+import static com.example.android.wearable.agendadata.Constants.PROFILE_PIC;
+import static com.example.android.wearable.agendadata.Constants.TAG;
+import static com.example.android.wearable.agendadata.Constants.TITLE;
+
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.wearable.Asset;
import com.google.android.gms.wearable.DataApi;
@@ -45,7 +44,6 @@ 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;
@@ -64,11 +62,21 @@ 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();
+ }
+
+ @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) {
@@ -77,13 +85,17 @@ public class HomeListenerService extends WearableListenerService {
}
}
- @Override
- public void onCreate() {
- super.onCreate();
- mGoogleApiClient = new GoogleApiClient.Builder(this.getApplicationContext())
- .addApi(Wearable.API)
- .build();
- mGoogleApiClient.connect();
+ /**
+ * 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);
+ }
}
/**
@@ -154,26 +166,4 @@ public class HomeListenerService extends WearableListenerService {
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/wearable/wear/AgendaData/gradle/wrapper/gradle-wrapper.properties b/wearable/wear/AgendaData/gradle/wrapper/gradle-wrapper.properties
index 07fc193f..f16d65df 100644
--- a/wearable/wear/AgendaData/gradle/wrapper/gradle-wrapper.properties
+++ b/wearable/wear/AgendaData/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Wed Apr 10 15:27:10 PDT 2013
+#Wed Apr 13 15:08:49 PDT 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
diff --git a/wearable/wear/AgendaData/template-params.xml b/wearable/wear/AgendaData/template-params.xml
index a6b48821..a6082e41 100644
--- a/wearable/wear/AgendaData/template-params.xml
+++ b/wearable/wear/AgendaData/template-params.xml
@@ -24,7 +24,7 @@
<minSdk>18</minSdk>
<targetSdkVersion>23</targetSdkVersion>
- <targetSdkVersionWear>22</targetSdkVersionWear>
+ <targetSdkVersionWear>23</targetSdkVersionWear>
<dependency>com.android.support:design:23.1.1</dependency>