本文整理汇总了Java中com.google.android.gms.wearable.Wearable类的典型用法代码示例。如果您正苦于以下问题:Java Wearable类的具体用法?Java Wearable怎么用?Java Wearable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Wearable类属于com.google.android.gms.wearable包,在下文中一共展示了Wearable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onConfigurationAddedOrEdited
import com.google.android.gms.wearable.Wearable; //导入依赖的package包/类
/**
* 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);
}
示例2: updateWearWeather
import com.google.android.gms.wearable.Wearable; //导入依赖的package包/类
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");
}
}
});
}
示例3: onStartCommand
import com.google.android.gms.wearable.Wearable; //导入依赖的package包/类
@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;
}
示例4: onCreate
import com.google.android.gms.wearable.Wearable; //导入依赖的package包/类
@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);
}
示例5: getByteArrayAsset
import com.google.android.gms.wearable.Wearable; //导入依赖的package包/类
@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;
}
示例6: onCreate
import com.google.android.gms.wearable.Wearable; //导入依赖的package包/类
@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);
}
示例7: AppMuteManager
import com.google.android.gms.wearable.Wearable; //导入依赖的package包/类
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();
}
};
}
示例8: alarmCommand
import com.google.android.gms.wearable.Wearable; //导入依赖的package包/类
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();
}
示例9: handleActionSendMessage
import com.google.android.gms.wearable.Wearable; //导入依赖的package包/类
/**
* 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());
}
}
}
示例10: handleActionSendMessage
import com.google.android.gms.wearable.Wearable; //导入依赖的package包/类
/**
* 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();
}
示例11: sendMessage
import com.google.android.gms.wearable.Wearable; //导入依赖的package包/类
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");
}
}
});
}
}
示例12: sendMessage
import com.google.android.gms.wearable.Wearable; //导入依赖的package包/类
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");
}
}
});
}
}
示例13: onConnected
import com.google.android.gms.wearable.Wearable; //导入依赖的package包/类
@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!");
}
}
});
}
示例14: sendMessageToHandheld
import com.google.android.gms.wearable.Wearable; //导入依赖的package包/类
/**
* 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();
}
示例15: sendMessageToHandheld
import com.google.android.gms.wearable.Wearable; //导入依赖的package包/类
/**
* 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();
}