Skip to content

Commit b11a0c5

Browse files
committed
No returns error when it can't connect
1 parent 408a97c commit b11a0c5

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

wear-socket/src/main/java/com/github/jrejaud/wear_socket/WearSocket.java

+14-9
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public class WearSocket implements MessageApi.MessageListener, DataApi.DataListe
5151

5252
private MessageListener messageReceived;
5353
private DataListener dataChanged;
54+
private onErrorListener errorListener;
5455

5556
public static WearSocket getInstance() {
5657
return ourInstance;
@@ -63,8 +64,9 @@ private WearSocket() {
6364
//Setup and State Handling
6465
//********************************************************************
6566

66-
public void setupAndConnect(final Context context, final String capability) {
67+
public void setupAndConnect(final Context context, final String capability, onErrorListener errorListener) {
6768
this.context = context;
69+
this.errorListener = errorListener;
6870
this.capability = capability;
6971
Log.d(TAG, "Starting up Google Api Client");
7072
googleApiClient = new GoogleApiClient.Builder(context)
@@ -103,14 +105,9 @@ public void run() {
103105
String nodeID = findBestNodeId(nodes);
104106
Log.d(TAG,"Node found: "+nodeID);
105107
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;
114111
}
115112
WearSocket.this.nodeID = nodeID;
116113
nodeFound.release();
@@ -330,4 +327,12 @@ public void onDataChanged(final DataEventBuffer dataEventBuffer) {
330327
public void setKeyDataType(String key, Type type) {
331328
keyTypes.put(key, type);
332329
}
330+
331+
//********************************************************************
332+
//Error Listener
333+
//********************************************************************
334+
335+
public interface onErrorListener {
336+
void onError(Throwable throwable);
337+
}
333338
}

0 commit comments

Comments
 (0)