Java 类com.google.android.gms.wearable.Wearable 实例源码

项目:Android-DFU-App    文件:UARTConfigurationSynchronizer.java   
/**
 * Synchronizes the UART configurations between handheld and wearables.
 * Call this when configuration has been created or altered.
 * @return pending result
 */
public PendingResult<DataApi.DataItemResult> onConfigurationAddedOrEdited(final long id, final UartConfiguration configuration) {
    if (mGoogleApiClient == null || !mGoogleApiClient.isConnected())
        return null;

    final PutDataMapRequest mapRequest = PutDataMapRequest.create(Constants.UART.CONFIGURATIONS + "/" + id);
    final DataMap map = mapRequest.getDataMap();
    map.putString(Constants.UART.Configuration.NAME, configuration.getName());
    final ArrayList<DataMap> commands = new ArrayList<>(UartConfiguration.COMMANDS_COUNT);
    for (Command command : configuration.getCommands()) {
        if (command != null && command.isActive()) {
            final DataMap item = new DataMap();
            item.putInt(Constants.UART.Configuration.Command.ICON_ID, command.getIconIndex());
            item.putString(Constants.UART.Configuration.Command.MESSAGE, command.getCommand());
            item.putInt(Constants.UART.Configuration.Command.EOL, command.getEolIndex());
            commands.add(item);
        }
    }
    map.putDataMapArrayList(Constants.UART.Configuration.COMMANDS, commands);
    final PutDataRequest request = mapRequest.asPutDataRequest();
    return Wearable.DataApi.putDataItem(mGoogleApiClient, request);
}
项目:ubiquitous    文件:SunshineSyncIntentService.java   
private void updateWearWeather(int weather_id, double high_temp, double low_temp){
    PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(WEATHER_PATH).setUrgent();
    putDataMapRequest.getDataMap().putInt(WEATHER_ID, weather_id);
    Log.d(LOG_TAG, "value of weather put : "+weather_id);
    putDataMapRequest.getDataMap().putDouble(HIGH_TEMP, high_temp);
    putDataMapRequest.getDataMap().putDouble(LOW_TEMP, low_temp);
    PutDataRequest putDataRequest = putDataMapRequest.asPutDataRequest().setUrgent();
    PendingResult<DataApi.DataItemResult> pendingResult = Wearable.DataApi.putDataItem(mWearClient, putDataRequest);

    pendingResult.setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
        @Override
        public void onResult(@NonNull DataApi.DataItemResult dataItemResult) {
            if (dataItemResult.getStatus().isSuccess()) {
                Log.d(LOG_TAG, "Data item set: " + dataItemResult.getDataItem().getUri());

            } else {
                Log.d(LOG_TAG, "Error in sending data to watch");
            }
        }

    });
}
项目:wear-dnd-sync    文件:LGHackService.java   
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.d(TAG, "Service is started");

    if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
        return Service.START_NOT_STICKY;
    if (android.os.Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1)
        return Service.START_NOT_STICKY;

    IntentFilter filter = new IntentFilter();
    filter.addAction(ACTION_SET_STATE);
    registerReceiver(settingsReceiver, filter);

    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addApi(Wearable.API)
            .build();

    mGoogleApiClient.connect();

    int interruptionFilter = getCurrentInterruptionFilter();
    SettingsService.sendState(mGoogleApiClient, interruptionFilter, mStateTime);

    return Service.START_STICKY;
}
项目:react-native-android-wear-demo    文件:MainActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  btnIncreaseCounter = (Button) findViewById(R.id.btnWearIncreaseCounter);
  btnIncreaseCounter.getBackground().setColorFilter(0xFF1194F7, PorterDuff.Mode.MULTIPLY);
  tvCounter = (TextView) findViewById(R.id.tvCounter);
  tvCounter.setText(Integer.toString(count));

  client = new GoogleApiClient.Builder(this).addApi(Wearable.API)
    .addConnectionCallbacks(this)
    .addOnConnectionFailedListener(this)
    .build();

  btnIncreaseCounter.setOnClickListener(clickListener);
}
项目:WearVibrationCenter    文件:PhoneCommandListener.java   
@Nullable
private byte[] getByteArrayAsset(@Nullable DataItemAsset asset, GoogleApiClient connectedApiClient) {
    if (asset == null) {
        return null;
    }

    InputStream inputStream = Wearable.DataApi.getFdForAsset(connectedApiClient, asset).await().getInputStream();
    byte[] data = readFully(inputStream);
    if (data != null) {
        try {
            inputStream.close();
        } catch (IOException ignored) {
        }
    }

    return data;
}
项目:WearVibrationCenter    文件:AppMuteActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_app_mute);

    googleApiClient = new GoogleApiClient.Builder(this)
            .addApi(Wearable.API)
            .addConnectionCallbacks(this)
            .build();

    recycler = (WearableRecyclerView) findViewById(R.id.recycler);
    progressBar = (ProgressBar) findViewById(R.id.progress);
    emptyNotice = (TextView) findViewById(R.id.empty_notice);

    adapter = new ListAdapter();
    recycler.setOffsettingHelper(new ListOffsettingHelper());
    recycler.setItemAnimator(new DefaultItemAnimatorNoChange());
    recycler.setCenterEdgeItems(true);
    recycler.setAdapter(adapter);

    preferences = PreferenceManager.getDefaultSharedPreferences(this);
}
项目:WearVibrationCenter    文件:AppMuteManager.java   
public AppMuteManager(NotificationService service) {
    this.service = service;

    googleApiClient = new GoogleApiClient.Builder(service)
            .addApi(Wearable.API)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();
    googleApiClient.connect();

    final int maxMemory = (int) (Runtime.getRuntime().maxMemory());
    iconCache = new LruCache<String, Bitmap>(maxMemory / 32) // 1/16th of device's RAM should be far enough for all icons
    {
        @Override
        protected int sizeOf(String key, Bitmap value) {
            return value.getByteCount();
        }
    };

}
项目:WearVibrationCenter    文件:WatchCommander.java   
private void alarmCommand(Intent intent) {
    AlarmCommand commandData = intent.getParcelableExtra(KEY_COMMAND_DATA);

    LiteAlarmCommand liteAlarmCommand = new LiteAlarmCommand(commandData);

    PutDataRequest putDataRequest = PutDataRequest.create(CommPaths.COMMAND_ALARM);
    putDataRequest.setData(ParcelPacker.getData(liteAlarmCommand));

    if (commandData.getIcon() != null) {
        putDataRequest.putAsset(CommPaths.ASSET_ICON, Asset.createFromBytes(commandData.getIcon()));
    }
    if (commandData.getBackgroundBitmap() != null) {
        putDataRequest.putAsset(CommPaths.ASSET_BACKGROUND, Asset.createFromBytes(commandData.getBackgroundBitmap()));
    }

    putDataRequest.setUrgent();

    Wearable.DataApi.putDataItem(googleApiClient, putDataRequest).await();
}
项目:DoNotDisturbSync    文件:WearMessageSenderService.java   
/**
 * Handle the message sending action in the provided background thread.
 */
private void handleActionSendMessage(String mode) {
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addApi(Wearable.API)
            .build();

    if (!(mGoogleApiClient.isConnected() || mGoogleApiClient.isConnecting())) {
        mGoogleApiClient.blockingConnect(CONNECTION_TIME_OUT, TimeUnit.SECONDS);
    }

    NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).await();

    // Send the Do Not Disturb mode message to all devices (nodes)
    for (Node node : nodes.getNodes()) {
        MessageApi.SendMessageResult result = Wearable.MessageApi.sendMessage(mGoogleApiClient, node.getId(), DND_SYNC_PREFIX, mode.getBytes()).await();

        if (!result.getStatus().isSuccess()){
            Log.e(TAG, "Failed to send message to " + node.getDisplayName());
        } else {
            Log.i(TAG, "Successfully sent message " + mode + " to " + node.getDisplayName());
        }
    }
}
项目:DoNotDisturbSync    文件:WearMessageSenderService.java   
/**
 * Handle the message sending action in the provided background thread.
 */
private void handleActionSendMessage(String mode) {
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addApi(Wearable.API)
            .build();

    if (!(mGoogleApiClient.isConnected() || mGoogleApiClient.isConnecting())) {
        mGoogleApiClient.blockingConnect(CONNECTION_TIME_OUT, TimeUnit.SECONDS);
    }

    NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).await();

    // Send the Do Not Disturb mode message to all devices (nodes)
    for (Node node : nodes.getNodes()) {
        MessageApi.SendMessageResult result = Wearable.MessageApi.sendMessage(mGoogleApiClient, node.getId(), DND_SYNC_PREFIX, mode.getBytes()).await();

        if (!result.getStatus().isSuccess()){
            Log.e(TAG, "Failed to send message to " + node.getDisplayName());
        } else {
            Log.i(TAG, "Successfully sent message " + mode + " to " + node.getDisplayName());
        }
    }

    //mGoogleApiClient.disconnect();
}
项目:Android-Wear-Projects    文件:MainActivity.java   
private void sendMessage(String message) {
    if (mNode != null && mGoogleApiClient != null) {
        Wearable.MessageApi.sendMessage(mGoogleApiClient, mNode.getId(), WEAR_PATH, message.getBytes())
                .setResultCallback(new ResultCallback<MessageApi.SendMessageResult>() {
                    @Override
                    public void onResult(MessageApi.SendMessageResult sendMessageResult) {
                        if (!sendMessageResult.getStatus().isSuccess()) {
                            Log.d("packtchat", "Failed message: " +
                                    sendMessageResult.getStatus().getStatusCode());
                        } else {
                            Log.d("packtchat", "Message succeeded");
                        }
                    }
                });
    }
}
项目:Android-Wear-Projects    文件:MainActivity.java   
private void sendMessage(String city) {
    if (mNode != null && mGoogleApiClient != null) {
        Wearable.MessageApi.sendMessage(mGoogleApiClient, mNode.getId(), WEAR_PATH, city.getBytes())
                .setResultCallback(new ResultCallback<MessageApi.SendMessageResult>() {
                    @Override
                    public void onResult(MessageApi.SendMessageResult sendMessageResult) {
                        if (!sendMessageResult.getStatus().isSuccess()) {
                            Log.d("packtchat", "Failed message: " +
                                    sendMessageResult.getStatus().getStatusCode());
                        } else {
                            Log.d("packtchat", "Message succeeded");
                        }
                    }
                });
    }
}
项目:Android-Wear-Projects    文件:MainActivity.java   
@Override
public void onConnected(@Nullable Bundle bundle) {
    Wearable.NodeApi.getConnectedNodes(mGoogleApiClient)
            .setResultCallback(new ResultCallback<NodeApi.GetConnectedNodesResult>() {
                @Override
                public void onResult(NodeApi.GetConnectedNodesResult nodes) {
                    for (Node node : nodes.getNodes()) {
                        if (node != null && node.isNearby()) {
                            mNode = node;
                            Log.d("packtchat", "Connected to " + mNode.getDisplayName());
                        }
                    }
                    if (mNode == null) {
                        Log.d("packtchat", "Not connected!");
                    }
                }
            });
}
项目:Android-DFU-App    文件:ActionReceiver.java   
/**
 * Sends the given message to the handheld.
 * @param path message path
 * @param message the message
 */
private void sendMessageToHandheld(final @NonNull Context context, final @NonNull String path, final @NonNull String message) {
    new Thread(new Runnable() {
        @Override
        public void run() {
            final GoogleApiClient client = new GoogleApiClient.Builder(context)
                    .addApi(Wearable.API)
                    .build();
            client.blockingConnect();

            final NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(client).await();
            for(Node node : nodes.getNodes()) {
                final MessageApi.SendMessageResult result = Wearable.MessageApi.sendMessage(client, node.getId(), path, message.getBytes()).await();
                if (!result.getStatus().isSuccess()){
                    Log.w(TAG, "Failed to send " + path + " to " + node.getDisplayName());
                }
            }
            client.disconnect();
        }
    }).start();
}
项目:Android-DFU-App    文件:UARTCommandsActivity.java   
/**
 * Sends the given command to the handheld.
 *
 * @param command the message
 */
private void sendMessageToHandheld(final @NonNull Context context, final @NonNull String command) {
    new Thread(new Runnable() {
        @Override
        public void run() {
            final GoogleApiClient client = new GoogleApiClient.Builder(context)
                    .addApi(Wearable.API)
                    .build();
            client.blockingConnect();

            final NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(client).await();
            for (Node node : nodes.getNodes()) {
                final MessageApi.SendMessageResult result = Wearable.MessageApi.sendMessage(client, node.getId(), Constants.UART.COMMAND, command.getBytes()).await();
                if (!result.getStatus().isSuccess()) {
                    Log.w(TAG, "Failed to send " + Constants.UART.COMMAND + " to " + node.getDisplayName());
                }
            }
            client.disconnect();
        }
    }).start();
}
项目:Android-DFU-App    文件:UARTConfigurationsActivity.java   
/**
 * This method read the UART configurations from the DataApi and populates the adapter with them.
 */
private void populateConfigurations() {
    if (mGoogleApiClient.isConnected()) {
        final PendingResult<DataItemBuffer> results = Wearable.DataApi.getDataItems(mGoogleApiClient, Uri.parse("wear:" + Constants.UART.CONFIGURATIONS), DataApi.FILTER_PREFIX);
        results.setResultCallback(new ResultCallback<DataItemBuffer>() {
            @Override
            public void onResult(final DataItemBuffer dataItems) {
                final List<UartConfiguration> configurations = new ArrayList<>(dataItems.getCount());
                for (int i = 0; i < dataItems.getCount(); ++i) {
                    final DataItem item = dataItems.get(i);
                    final long id = ContentUris.parseId(item.getUri());
                    final DataMap dataMap = DataMapItem.fromDataItem(item).getDataMap();
                    final UartConfiguration configuration = new UartConfiguration(dataMap, id);
                    configurations.add(configuration);
                }
                mAdapter.setConfigurations(configurations);
                dataItems.release();
            }
        });
    }
}
项目:Android-DFU-App    文件:UARTService.java   
/**
 * Sends the given message to all connected wearables. If the path is equal to {@link Constants.UART#DEVICE_DISCONNECTED} the service will be stopped afterwards.
 * @param path message path
 * @param message the message
 */
private void sendMessageToWearables(final @NonNull String path, final @NonNull String message) {
    if(mGoogleApiClient.isConnected()) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).await();
                for(Node node : nodes.getNodes()) {
                    Logger.v(getLogSession(), "[WEAR] Sending message '" + path + "' to " + node.getDisplayName());
                    final MessageApi.SendMessageResult result = Wearable.MessageApi.sendMessage(mGoogleApiClient, node.getId(), path, message.getBytes()).await();
                    if(result.getStatus().isSuccess()){
                        Logger.i(getLogSession(), "[WEAR] Message sent");
                    } else {
                        Logger.w(getLogSession(), "[WEAR] Sending message failed: " + result.getStatus().getStatusMessage());
                        Log.w(TAG, "Failed to send " + path + " to " + node.getDisplayName());
                    }
                }
                if (Constants.UART.DEVICE_DISCONNECTED.equals(path))
                    stopService();
            }
        }).start();
    } else {
        if (Constants.UART.DEVICE_DISCONNECTED.equals(path))
            stopService();
    }
}
项目:Android_watch_magpie    文件:Home_activity.java   
private void initView()
{
    fragmentAlert =new Fragment_display_alertes();
    fragmentMeasures=new Fragment_display_measures();
    fragmentSettings =new Fragment_display_settings();


    //add the fragment to the fragment manager
    getSupportFragmentManager().beginTransaction().add(R.id.main_container,fragmentAlert,"alertFrag").commit();
    getSupportFragmentManager().beginTransaction().add(R.id.main_container,fragmentMeasures,"measureFrag").commit();
    getSupportFragmentManager().beginTransaction().add(R.id.main_container,fragmentSettings,"settingsFrag").commit();


    //INIT the googe client
    googleClient = new GoogleApiClient.Builder(this)
            .addApi(Wearable.API)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();

}
项目:Excuser    文件:MainWearActivity.java   
private void checkIfPhoneHasApp() {
    Log.d(TAG, "checkIfPhoneHasApp()");

    PendingResult<CapabilityApi.GetCapabilityResult> pendingResult =
            Wearable.CapabilityApi.getCapability(
                    mGoogleApiClient,
                    CAPABILITY_PHONE_APP,
                    CapabilityApi.FILTER_ALL);

    pendingResult.setResultCallback(new ResultCallback<CapabilityApi.GetCapabilityResult>() {

        @Override
        public void onResult(@NonNull CapabilityApi.GetCapabilityResult getCapabilityResult) {
            Log.d(TAG, "onResult(): " + getCapabilityResult);

            if (getCapabilityResult.getStatus().isSuccess()) {
                CapabilityInfo capabilityInfo = getCapabilityResult.getCapability();
                mAndroidPhoneNodeWithApp = pickBestNodeId(capabilityInfo.getNodes());
                verifyNodeAndUpdateUI();

            } else {
                Log.d(TAG, "Failed CapabilityApi: " + getCapabilityResult.getStatus());
            }
        }
    });
}
项目:Excuser    文件:DeviceWearConnectionFragment.java   
@SuppressLint("LongLogTag")
@Override
public void onConnected(@Nullable Bundle bundle) {
    Log.d(TAG, "onConnected()");

    // Set up listeners for capability changes (install/uninstall of remote app).
    Wearable.CapabilityApi.addCapabilityListener(
            mGoogleApiClient,
            this,
            CAPABILITY_WEAR_APP);

    // Initial request for devices with our capability, aka, our Wear app installed.
    findWearDevicesWithApp();

    // Initial request for all Wear devices connected (with or without our capability).
    // Additional Note: Because there isn't a listener for ALL Nodes added/removed from network
    // that isn't deprecated, we simply update the full list when the Google API Client is
    // connected and when capability changes come through in the onCapabilityChanged() method.
    findAllWearDevices();
}
项目:Excuser    文件:DeviceWearConnectionFragment.java   
@SuppressLint("LongLogTag")
private void findAllWearDevices() {
    Log.d(TAG, "findAllWearDevices()");

    PendingResult<NodeApi.GetConnectedNodesResult> pendingResult =
            Wearable.NodeApi.getConnectedNodes(mGoogleApiClient);

    pendingResult.setResultCallback(new ResultCallback<NodeApi.GetConnectedNodesResult>() {
        @Override
        public void onResult(@NonNull NodeApi.GetConnectedNodesResult getConnectedNodesResult) {

            if (getConnectedNodesResult.getStatus().isSuccess()) {
                mAllConnectedNodes = getConnectedNodesResult.getNodes();
                verifyNodeAndUpdateUI();
                Log.e("Connected Nodes", "->"+mAllConnectedNodes.toString());
                findWearDevicesWithApp();

            } else {
                Log.d(TAG, "Failed NodeApi: " + getConnectedNodesResult.getStatus());
            }
        }
    });
}
项目:ubiquitous    文件:SunshineSyncIntentService.java   
@Override
public void onCreate() {
    super.onCreate();
    mWearClient = new GoogleApiClient.Builder(this)
            .addApi(Wearable.API)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();
    mWearClient.connect();
    Log.d(LOG_TAG, "google api client connected");
}
项目:wear-dnd-sync    文件:SettingsService.java   
@Override
public void onCreate() {
    super.onCreate();

    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addApi(Wearable.API)
            .build();

    mGoogleApiClient.connect();
}
项目:wear-dnd-sync    文件:MainActivity.java   
@Override
public void onConnected(@Nullable Bundle bundle) {
    Log.d(TAG, "Connected");

    Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).setResultCallback(
        new ResultCallback<NodeApi.GetConnectedNodesResult>() {
            @Override
            public void onResult(@NonNull NodeApi.GetConnectedNodesResult getConnectedNodesResult) {
                List<Node> nodes = getConnectedNodesResult.getNodes();

                if (nodes.isEmpty()) {
                    watchStatus.setText("No watches connected.");
                    return;
                }

                Wearable.MessageApi.sendMessage(mGoogleApiClient, nodes.get(0).getId(), SettingsService.PATH_DND_REGISTER, null).setResultCallback(new ResultCallback<MessageApi.SendMessageResult>() {
                    @Override
                    public void onResult(@NonNull MessageApi.SendMessageResult sendMessageResult) {
                        if(sendMessageResult.getStatus().isSuccess())
                            watchStatus.setText("Watch connected.");
                        else
                            watchStatus.setText("Watch connection failed.");
                    }
                });
            }
        }
    );
}
项目:wear-dnd-sync    文件:SettingsService.java   
@Override
public void onCreate() {
    super.onCreate();

    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addApi(Wearable.API)
            .build();

    mGoogleApiClient.connect();
}
项目:react-native-android-wear-demo    文件:MainActivity.java   
@Override
protected String doInBackground(GoogleApiClient... params) {
  final List<Node> connectedNodes = Wearable.NodeApi.getConnectedNodes(client).await().getNodes();
  for (Node connectedNode : connectedNodes) {
    if (connectedNode.isNearby()) {
      return connectedNode.getId();
    }
  }
  return null;
}
项目:react-native-android-wear-demo    文件:MainActivity.java   
/**
 * Used to disconnect the {@link MainActivity#client} and reset the other fields like the
 * {@link MainActivity#node} and disable the {@link MainActivity#btnIncreaseCounter}.
 */
private void disconnectGoogleApiClient() {
  if (client != null && client.isConnected()) {
    Wearable.MessageApi.removeListener(client, this);
    client.disconnect();
  }
  btnIncreaseCounter.setEnabled(false);
  node = null;
}
项目:react-native-android-wear-demo    文件:WearCommunicationModule.java   
public WearCommunicationModule(ReactApplicationContext reactContext) {
  super(reactContext);
  reactContext.addLifecycleEventListener(this);
  googleApiClient = new GoogleApiClient.Builder(getReactApplicationContext()).addApi(Wearable.API)
    .addConnectionCallbacks(this)
    .build();
}
项目:react-native-android-wear-demo    文件:WearCommunicationModule.java   
/** Increase the wear counter on every node that is connected to this device. */
@ReactMethod
public void increaseWearCounter() {
  final List<Node> nodes = Wearable.NodeApi.getConnectedNodes(googleApiClient).await().getNodes();
  if (nodes.size() > 0) {
    for (Node node : nodes) {
      Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), "/increase_wear_counter", null);
    }
  } else {
    Toast.makeText(getReactApplicationContext(), "No connected nodes found", Toast.LENGTH_LONG).show();
  }
}
项目:WearVibrationCenter    文件:PhoneCommandListener.java   
@Override
public void onDataChanged(DataEventBuffer dataEventBuffer) {
    GoogleApiClient googleApiClient = null;

    for (DataEvent event : dataEventBuffer) {
        if (event.getType() != DataEvent.TYPE_CHANGED) {
            continue;
        }

        DataItem dataItem = event.getDataItem();

        if (CommPaths.COMMAND_ALARM.equals(dataItem.getUri().getPath())) {
            LiteAlarmCommand liteAlarmCommand = ParcelPacker.getParcelable(dataItem.getData(), LiteAlarmCommand.CREATOR);

            if (googleApiClient == null) {
                googleApiClient = new GoogleApiClient.Builder(this)
                        .addApi(Wearable.API)
                        .build();

                googleApiClient.blockingConnect();
            }

            byte[] iconData = getByteArrayAsset(dataItem.getAssets().get(CommPaths.ASSET_ICON), googleApiClient);
            byte[] backgroundData = getByteArrayAsset(dataItem.getAssets().get(CommPaths.ASSET_BACKGROUND), googleApiClient);

            AlarmCommand alarmCommand = new AlarmCommand(liteAlarmCommand, backgroundData, iconData);
            alarm(alarmCommand);

            Wearable.DataApi.deleteDataItems(googleApiClient, dataItem.getUri()).await();
        }
    }

    if (googleApiClient != null) {
        googleApiClient.disconnect();
    }
}
项目:WearVibrationCenter    文件:TimedMuteManager.java   
public TimedMuteManager(NotificationService service) {
    this.service = service;

    googleApiClient = new GoogleApiClient.Builder(service)
            .addApi(Wearable.API)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();
    googleApiClient.connect();

    unmuteReceiver = new UnmuteReceiver();
    service.registerReceiver(unmuteReceiver, new IntentFilter(ACTON_UNMUTE));
}
项目:WearVibrationCenter    文件:TimedMuteManager.java   
public void onDestroy() {
    unmute();

    if (googleApiClient.isConnected()) {
        Wearable.MessageApi.removeListener(googleApiClient, this);
        googleApiClient.disconnect();
    }

    service.unregisterReceiver(unmuteReceiver);
    handler.removeCallbacksAndMessages(null);
}
项目:WearVibrationCenter    文件:TimedMuteManager.java   
@Override
public void onMessageReceived(MessageEvent messageEvent) {
    if (messageEvent.getPath().equals(CommPaths.COMMAND_TIMED_MUTE)) {
        TimedMuteCommand timedMuteCommand = ParcelPacker.getParcelable(messageEvent.getData(), TimedMuteCommand.CREATOR);

        Wearable.MessageApi.sendMessage(googleApiClient, messageEvent.getSourceNodeId(), CommPaths.COMMAND_RECEIVAL_ACKNOWLEDGMENT, null);

        mute(timedMuteCommand);
    }
}
项目:WearVibrationCenter    文件:AppMuteManager.java   
public void onDestroy() {
    if (googleApiClient.isConnected()) {
        listTransmitter.disconnect();
        Wearable.MessageApi.removeListener(googleApiClient, this);

        googleApiClient.disconnect();
    }

}
项目:WearVibrationCenter    文件:AppMuteManager.java   
@Override
public void onConnected(@Nullable Bundle bundle) {
    listTransmitter = new PlayServicesConnectionToReceiver(googleApiClient, true);
    listTransmitter.setProvider(this);

    Wearable.MessageApi.addListener(googleApiClient, this, Uri.parse("wear://*" + CommPaths.COMMAND_APP_MUTE), MessageApi.FILTER_LITERAL);
}
项目:WearVibrationCenter    文件:AppMuteManager.java   
@Override
public void onMessageReceived(MessageEvent messageEvent) {
    if (messageEvent.getPath().equals(CommPaths.COMMAND_APP_MUTE)) {
        AppMuteCommand appMuteCommand = ParcelPacker.getParcelable(messageEvent.getData(), AppMuteCommand.CREATOR);

        String mutedAppPackage = appList.get(appMuteCommand.getAppIndex()).packageName;
        mute(mutedAppPackage);

        Wearable.MessageApi.sendMessage(googleApiClient, messageEvent.getSourceNodeId(), CommPaths.COMMAND_RECEIVAL_ACKNOWLEDGMENT, null);
    }
}
项目:WearVibrationCenter    文件:WatchCommander.java   
@Override
public void onCreate() {
    super.onCreate();

    googleApiClient = new GoogleApiClient.Builder(this)
            .addApi(Wearable.API)
            .build();

    googleApiClient.connect();
}
项目:Android_Sunshine_Watch    文件:MyWatchFace.java   
@Override
public void onCreate(SurfaceHolder holder) {
    super.onCreate(holder);

    setWatchFaceStyle(new WatchFaceStyle.Builder(MyWatchFace.this)
            .setCardPeekMode(WatchFaceStyle.PEEK_MODE_VARIABLE)
            .setBackgroundVisibility(WatchFaceStyle.BACKGROUND_VISIBILITY_INTERRUPTIVE)
            .setShowSystemUiTime(false)
            .build());
    Resources resources = MyWatchFace.this.getResources();

    googleApiClient = new GoogleApiClient.Builder(MyWatchFace.this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Wearable.API)
            .build();
    googleApiClient.connect();

    // Colors
    mBackgroundPaint = new Paint();
    mBackgroundPaint.setColor(resources.getColor(R.color.orange));
    hourPaint = createTextPaint(resources.getColor(R.color.white));
    minutePaint = createTextPaint(resources.getColor(R.color.white));
    colonPaint = createTextPaint(resources.getColor(R.color.white));
    highPaint = createTextPaint(resources.getColor(R.color.white));
    lowPaint = createTextPaint(resources.getColor(R.color.white));

    // Initialize member variables
    mCalendar = Calendar.getInstance();
    date = new Date();
    dayOfWeekFormat = new SimpleDateFormat("EEEE", Locale.getDefault());
    dayOfWeekFormat.setCalendar(mCalendar);
    dateFormat = DateFormat.getDateFormat(MyWatchFace.this);
    dateFormat.setCalendar(mCalendar);
}
项目:Android_Sunshine_Watch    文件:MainActivity.java   
private void sendWeatherDataToWatch() {

        PutDataMapRequest putDataMapRequest = PutDataMapRequest.create("/weather");

        if (hightempforwatch != 0) {
            putDataMapRequest.getDataMap().putInt("highTemp", hightempforwatch);
            Log.d("Test","High Temp :"+String.valueOf(putDataMapRequest.getDataMap().getInt("highTemp")));
        }
        if (lowtempforWatch != 0) {
            putDataMapRequest.getDataMap().putInt("lowTemp", lowtempforWatch);
            Log.d("Test","Low Temp :"+ String.valueOf(putDataMapRequest.getDataMap().getInt("lowTemp")));
        }
        if (weatherIdforWatch != 0) {
            putDataMapRequest.getDataMap().putInt("weatherId", weatherIdforWatch);
            Log.d("Test", "Weather ID: "+String.valueOf(putDataMapRequest.getDataMap().getInt("weatherId")));
        }

        putDataMapRequest.setUrgent();

        PutDataRequest putDataRequest = putDataMapRequest.asPutDataRequest();

        Wearable.DataApi.putDataItem(MainActivity.googleApiClient, putDataRequest)
                .setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
                    @Override
                    public void onResult(DataApi.DataItemResult result) {
                        if (!result.getStatus().isSuccess()) {
                            System.out.println("Failure with code: " + result.getStatus().getStatusCode());
                        } else {
                            System.out.println("Success: " + result.getDataItem().getUri());
                        }
                    }
                });
    }
项目:Android-Wear-Projects    文件:MapsActivity.java   
private void addGoogleAPIClient() {
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Wearable.API)  // used for data layer API
            .addApi(LocationServices.API)
            .build();
}