@@ -51,6 +51,7 @@ public class WearSocket implements MessageApi.MessageListener, DataApi.DataListe
51
51
52
52
private MessageListener messageReceived ;
53
53
private DataListener dataChanged ;
54
+ private onErrorListener errorListener ;
54
55
55
56
public static WearSocket getInstance () {
56
57
return ourInstance ;
@@ -63,8 +64,9 @@ private WearSocket() {
63
64
//Setup and State Handling
64
65
//********************************************************************
65
66
66
- public void setupAndConnect (final Context context , final String capability ) {
67
+ public void setupAndConnect (final Context context , final String capability , onErrorListener errorListener ) {
67
68
this .context = context ;
69
+ this .errorListener = errorListener ;
68
70
this .capability = capability ;
69
71
Log .d (TAG , "Starting up Google Api Client" );
70
72
googleApiClient = new GoogleApiClient .Builder (context )
@@ -103,14 +105,9 @@ public void run() {
103
105
String nodeID = findBestNodeId (nodes );
104
106
Log .d (TAG ,"Node found: " +nodeID );
105
107
if (nodeID ==null ) {
106
- final String message = "Error, cannot find a connected device" ;
107
- ((Activity )context ).runOnUiThread (new Runnable () {
108
- @ Override
109
- public void run () {
110
- Toast .makeText (context , message , Toast .LENGTH_LONG ).show ();
111
- }
112
- });
113
- throw new RuntimeException (message );
108
+ //This might be cause by there not being a watch paired to the device
109
+ errorListener .onError (new Throwable ("Error, cannot find a connected device" ));
110
+ return ;
114
111
}
115
112
WearSocket .this .nodeID = nodeID ;
116
113
nodeFound .release ();
@@ -330,4 +327,12 @@ public void onDataChanged(final DataEventBuffer dataEventBuffer) {
330
327
public void setKeyDataType (String key , Type type ) {
331
328
keyTypes .put (key , type );
332
329
}
330
+
331
+ //********************************************************************
332
+ //Error Listener
333
+ //********************************************************************
334
+
335
+ public interface onErrorListener {
336
+ void onError (Throwable throwable );
337
+ }
333
338
}
0 commit comments