Java Code Examples for com.google.android.gms.wearable.Node#getDisplayName()

The following examples show how to use com.google.android.gms.wearable.Node#getDisplayName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ListenerService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onPeerConnected(Node peer) {//Deprecated with BIND_LISTENER
    super.onPeerConnected(peer);
    String id = peer.getId();
    String name = peer.getDisplayName();
    Log.d(TAG, "onPeerConnected peer name & ID: " + name + "|" + id);
    mPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    sendPrefSettings();
    if (mPrefs.getBoolean("enable_wearG5", false) && !mPrefs.getBoolean("force_wearG5", false)) {
        stopBtService();
        ListenerService.requestData(this);
    }
}
 
Example 2
Source File: ListenerService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onPeerDisconnected(Node peer) {//Deprecated with BIND_LISTENER
    super.onPeerDisconnected(peer);
    String id = peer.getId();
    String name = peer.getDisplayName();
    Log.d(TAG, "onPeerDisconnected peer name & ID: " + name + "|" + id);
    mPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    if (mPrefs.getBoolean("enable_wearG5", false)) {
        startBtService();
    }
}
 
Example 3
Source File: WatchUpdaterService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private void setLocalNodeName() {
    forceGoogleApiConnect();
    NodeApi.GetLocalNodeResult localnodes = Wearable.NodeApi.getLocalNode(googleApiClient).await(60, TimeUnit.SECONDS);
    Node getnode = localnodes.getNode();
    localnode = getnode != null ? getnode.getDisplayName() + "|" + getnode.getId() : "";
    UserError.Log.d(TAG, "setLocalNodeName.  localnode=" + localnode);
}
 
Example 4
Source File: ListenerService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onPeerConnected(Node peer) {//Deprecated with BIND_LISTENER
    super.onPeerConnected(peer);
    String id = peer.getId();
    String name = peer.getDisplayName();
    Log.d(TAG, "onPeerConnected peer name & ID: " + name + "|" + id);
    mPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    sendPrefSettings();
    if (mPrefs.getBoolean("enable_wearG5", false) && !mPrefs.getBoolean("force_wearG5", false)) {
        stopBtService();
        ListenerService.requestData(this);
    }
}
 
Example 5
Source File: ListenerService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onPeerDisconnected(Node peer) {//Deprecated with BIND_LISTENER
    super.onPeerDisconnected(peer);
    String id = peer.getId();
    String name = peer.getDisplayName();
    Log.d(TAG, "onPeerDisconnected peer name & ID: " + name + "|" + id);
    mPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    if (mPrefs.getBoolean("enable_wearG5", false)) {
        startBtService();
    }
}
 
Example 6
Source File: WatchUpdaterService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private void setLocalNodeName() {
    forceGoogleApiConnect();
    NodeApi.GetLocalNodeResult localnodes = Wearable.NodeApi.getLocalNode(googleApiClient).await(60, TimeUnit.SECONDS);
    Node getnode = localnodes.getNode();
    localnode = getnode != null ? getnode.getDisplayName() + "|" + getnode.getId() : "";
    UserError.Log.d(TAG, "setLocalNodeName.  localnode=" + localnode);
}
 
Example 7
Source File: GoogleApiMessenger.java    From Sensor-Data-Logger with Apache License 2.0 5 votes vote down vote up
public String getNodeName(String id) {
    Node node = getLastConnectedNodeById(id);
    if (node != null) {
        return node.getDisplayName();
    } else {
        if (id == null || id.equals(DEFAULT_NODE_ID)) {
            return Build.MODEL;
        } else {
            return id;
        }
    }
}
 
Example 8
Source File: WatchUpdaterService.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected Void doInBackground(Void... voids) {
    if (googleApiClient.isConnected()) {
        if (System.currentTimeMillis() - lastRequest > 20 * 1000) { // enforce 20-second debounce period
            lastRequest = System.currentTimeMillis();
            //NodeApi.GetConnectedNodesResult nodes =
            //        Wearable.NodeApi.getConnectedNodes(googleApiClient).await();
            if (localnode == null || (localnode != null && localnode.isEmpty()))
                setLocalNodeName();
            CapabilityApi.GetCapabilityResult capabilityResult =
                    Wearable.CapabilityApi.getCapability(
                            googleApiClient, CAPABILITY_WEAR_APP,
                            CapabilityApi.FILTER_REACHABLE).await(GET_CAPABILITIES_TIMEOUT_MS, TimeUnit.MILLISECONDS);
            CapabilityInfo nodes;
            if (!capabilityResult.getStatus().isSuccess()) {
                Log.e(TAG, "doInBackground Failed to get capabilities, status: " + capabilityResult.getStatus().getStatusMessage());
                nodes = null;
            } else {
                nodes = capabilityResult.getCapability();
            }
            SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
            SharedPreferences.Editor prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit();
            boolean enable_wearG5 = sharedPrefs.getBoolean("enable_wearG5", false);
            boolean force_wearG5 = sharedPrefs.getBoolean("force_wearG5", false);
            String node_wearG5 = mPrefs.getString("node_wearG5", "");

            if (nodes != null && nodes.getNodes().size() > 0) {
                updateWearSyncBgsCapability(nodes);
                int count = nodes.getNodes().size();
                Log.d(TAG, "doInBackground connected.  CapabilityApi.GetCapabilityResult mWearNodeID=" + (mWearNodeId != null ? mWearNodeId : "") + " count=" + count);//KS
                boolean isConnectedToWearable = false;
                for (Node peer : nodes.getNodes()) {

                    //onPeerConnected
                    String wearNode = peer.getDisplayName() + "|" + peer.getId();
                    Log.d(TAG, "CheckWearableConnected onPeerConnected peer name & ID: " + wearNode);
                    if (wearNode.equals(node_wearG5)) {
                        isConnectedToWearable = true;
                        sendPrefSettings();
                        break;
                    } else if (node_wearG5.equals("")) {
                        isConnectedToWearable = true;
                        prefs.putString("node_wearG5", wearNode);
                        prefs.apply();
                        break;
                    }

                }
                sendPrefSettings();
                initWearData();
                if (enable_wearG5) {
                    //Only stop service if Phone will rely on Wear Collection Service
                    if (force_wearG5 && isConnectedToWearable) {
                        Log.d(TAG, "CheckWearableConnected onPeerConnected force_wearG5=true Phone stopBtService and continue to use Wear BT Collector");
                        stopBtService();
                    } else {
                        Log.d(TAG, "CheckWearableConnected onPeerConnected force_wearG5=false Phone startBtService");
                        startBtService();
                    }
                }
            } else {
                //onPeerDisconnected
                Log.d(TAG, "CheckWearableConnected onPeerDisconnected");
                if (sharedPrefs.getBoolean("wear_sync", false)) {
                    Log.d(TAG, "CheckWearableConnected onPeerDisconnected wear_sync=true Phone startBtService");
                    startBtService();
                }
            }
        } else {
            Log.d(TAG, "Debounce limit hit - not sending");
        }
    } else {
        Log.d(TAG, "Not connected for sending");
        googleApiClient.connect();
    }
    return null;
}
 
Example 9
Source File: WatchUpdaterService.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected Void doInBackground(Void... voids) {
    if (googleApiClient.isConnected()) {
        if (System.currentTimeMillis() - lastRequest > 20 * 1000) { // enforce 20-second debounce period
            lastRequest = System.currentTimeMillis();
            //NodeApi.GetConnectedNodesResult nodes =
            //        Wearable.NodeApi.getConnectedNodes(googleApiClient).await();
            if (localnode == null || (localnode != null && localnode.isEmpty()))
                setLocalNodeName();
            CapabilityApi.GetCapabilityResult capabilityResult =
                    Wearable.CapabilityApi.getCapability(
                            googleApiClient, CAPABILITY_WEAR_APP,
                            CapabilityApi.FILTER_REACHABLE).await(GET_CAPABILITIES_TIMEOUT_MS, TimeUnit.MILLISECONDS);
            CapabilityInfo nodes;
            if (!capabilityResult.getStatus().isSuccess()) {
                Log.e(TAG, "doInBackground Failed to get capabilities, status: " + capabilityResult.getStatus().getStatusMessage());
                nodes = null;
            } else {
                nodes = capabilityResult.getCapability();
            }
            SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
            SharedPreferences.Editor prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit();
            boolean enable_wearG5 = sharedPrefs.getBoolean("enable_wearG5", false);
            boolean force_wearG5 = sharedPrefs.getBoolean("force_wearG5", false);
            String node_wearG5 = mPrefs.getString("node_wearG5", "");

            if (nodes != null && nodes.getNodes().size() > 0) {
                updateWearSyncBgsCapability(nodes);
                int count = nodes.getNodes().size();
                Log.d(TAG, "doInBackground connected.  CapabilityApi.GetCapabilityResult mWearNodeID=" + (mWearNodeId != null ? mWearNodeId : "") + " count=" + count);//KS
                boolean isConnectedToWearable = false;
                for (Node peer : nodes.getNodes()) {

                    //onPeerConnected
                    String wearNode = peer.getDisplayName() + "|" + peer.getId();
                    Log.d(TAG, "CheckWearableConnected onPeerConnected peer name & ID: " + wearNode);
                    if (wearNode.equals(node_wearG5)) {
                        isConnectedToWearable = true;
                        sendPrefSettings();
                        break;
                    } else if (node_wearG5.equals("")) {
                        isConnectedToWearable = true;
                        prefs.putString("node_wearG5", wearNode);
                        prefs.apply();
                        break;
                    }

                }
                sendPrefSettings();
                initWearData();
                if (enable_wearG5) {
                    //Only stop service if Phone will rely on Wear Collection Service
                    if (force_wearG5 && isConnectedToWearable) {
                        Log.d(TAG, "CheckWearableConnected onPeerConnected force_wearG5=true Phone stopBtService and continue to use Wear BT Collector");
                        stopBtService();
                    } else {
                        Log.d(TAG, "CheckWearableConnected onPeerConnected force_wearG5=false Phone startBtService");
                        startBtService();
                    }
                }
            } else {
                //onPeerDisconnected
                Log.d(TAG, "CheckWearableConnected onPeerDisconnected");
                if (sharedPrefs.getBoolean("wear_sync", false)) {
                    Log.d(TAG, "CheckWearableConnected onPeerDisconnected wear_sync=true Phone startBtService");
                    startBtService();
                }
            }
        } else {
            Log.d(TAG, "Debounce limit hit - not sending");
        }
    } else {
        Log.d(TAG, "Not connected for sending");
        googleApiClient.connect();
    }
    return null;
}