本文整理匯總了Java中com.google.android.gms.wearable.DataItem類的典型用法代碼示例。如果您正苦於以下問題:Java DataItem類的具體用法?Java DataItem怎麽用?Java DataItem使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DataItem類屬於com.google.android.gms.wearable包,在下文中一共展示了DataItem類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onDataChanged
import com.google.android.gms.wearable.DataItem; //導入依賴的package包/類
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
Log.d(LOG_TAG, " in data changed");
for (DataEvent event : dataEvents) {
if (event.getType() == DataEvent.TYPE_CHANGED) {
// DataItem changed
DataItem item = event.getDataItem();
if (item.getUri().getPath().compareTo(WEATHER_PATH) == 0) {
DataMap dataMap = DataMapItem.fromDataItem(item).getDataMap();
weather_id = dataMap.getInt(WEATHER_ID);
high_temp = dataMap.getDouble(HIGH_TEMP);
low_temp = dataMap.getDouble(LOW_TEMP);
}
} else if (event.getType() == DataEvent.TYPE_DELETED) {
// DataItem deleted
}
}
invalidate();
}
示例2: populateConfigurations
import com.google.android.gms.wearable.DataItem; //導入依賴的package包/類
/**
* 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();
}
});
}
}
示例3: onDataChanged
import com.google.android.gms.wearable.DataItem; //導入依賴的package包/類
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
super.onDataChanged(dataEvents);
for (DataEvent event : dataEvents) {
if (event.getType() == DataEvent.TYPE_CHANGED) {
// DataItem changed
DataItem item = event.getDataItem();
if (item.getUri().getPath().compareTo("/SHAKEINTENSITY") == 0) {
DataMap dataMap = DataMapItem.fromDataItem(item).getDataMap();
Log.e("Data Event", "value->"+dataMap.getString(SHAKE_INTENSITY_KEY));
LocalStoreUtils.setShakeIntensity(dataMap.getString(SHAKE_INTENSITY_KEY), this);
}
}
}
}
示例4: onDataChanged
import com.google.android.gms.wearable.DataItem; //導入依賴的package包/類
@Override // DataApi.DataListener
public void onDataChanged(DataEventBuffer dataEvents) {
Log.d(TAG, "Data changed");
for (DataEvent dataEvent : dataEvents) {
if (dataEvent.getType() != DataEvent.TYPE_CHANGED) {
continue;
}
DataItem dataItem = dataEvent.getDataItem();
if (!dataItem.getUri().getPath().equals(
ConfigurationHelper.PATH_WITH_FEATURE)) {
continue;
}
DataMapItem dataMapItem = DataMapItem.fromDataItem(dataItem);
DataMap config = dataMapItem.getDataMap();
Log.d(TAG, "Config DataItem updated:" + config);
// This can happen from this method more often when phone changes
updateUiForConfigDataMap(config);
}
}
示例5: processData
import com.google.android.gms.wearable.DataItem; //導入依賴的package包/類
private void processData(DataItem item) {
if (START_ACTIVITY_PATH.equals(item.getUri().getPath())) {
DataMap dataMap = DataMapItem.fromDataItem(item).getDataMap();
if (dataMap.containsKey("max")) {
mWatchMaxTemp = dataMap.getString("max");
}
if (dataMap.containsKey("min")) {
mWatchMinTemp = dataMap.getString("min");
}
if (dataMap.containsKey("id")) {
int resid=getArtResourceForWeatherCondition(dataMap.getInt("id"));
mWatchBitmap= BitmapFactory.decodeResource(getResources(), resid);
mWatchBitmap=Bitmap.createScaledBitmap(mWatchBitmap, (int) mTextPaint.getTextSize(), (int)mTextPaint.getTextSize(), false);
}
mWatchTemp=mWatchMaxTemp+" "+mWatchMinTemp;
}
}
示例6: onDataChanged
import com.google.android.gms.wearable.DataItem; //導入依賴的package包/類
@Override // DataApi.DataListener
public void onDataChanged(DataEventBuffer dataEvents) {
for (DataEvent dataEvent : dataEvents) {
if (dataEvent.getType() != DataEvent.TYPE_CHANGED) {
continue;
}
DataItem dataItem = dataEvent.getDataItem();
if (!dataItem.getUri().getPath().equals(
WatchFaceUtil.PATH_WITH_FEATURE)) {
continue;
}
DataMapItem dataMapItem = DataMapItem.fromDataItem(dataItem);
DataMap config = dataMapItem.getDataMap();
Log.d(TAG, "Config DataItem updated:" + config);
updateUiForConfigDataMap(config);
}
}
示例7: onDataChanged
import com.google.android.gms.wearable.DataItem; //導入依賴的package包/類
@Override // DataApi.DataListener
public void onDataChanged(DataEventBuffer dataEvents) {
Log.d(TAG,"onDataChanged "+dataEvents);
for (DataEvent dataEvent : dataEvents) {
if (dataEvent.getType() != DataEvent.TYPE_CHANGED) {
continue;
}
DataItem dataItem = dataEvent.getDataItem();
if (!dataItem.getUri().getPath().equals(WatchFaceUtil.PATH_WITH_FEATURE)) {
continue;
}
DataMapItem dataMapItem = DataMapItem.fromDataItem(dataItem);
DataMap config = dataMapItem.getDataMap();
Log.d(TAG, "Config DataItem updated:" + config);
updateUiForConfigDataMap(config);
}
}
示例8: onDataChanged
import com.google.android.gms.wearable.DataItem; //導入依賴的package包/類
@Override
public void onDataChanged(DataEventBuffer dataEventBuffer) {
Log.d(LOG_TAG, "Weather data has been changed!");
for (DataEvent event : dataEventBuffer) {
DataItem item = event.getDataItem();
if (WEATHER_DATA_PATH.equals(item.getUri().getPath())) {
DataMap dataMap = DataMapItem.fromDataItem(item).getDataMap();
double high = dataMap.getDouble(WEATHER_DATA_HIGH);
double low = dataMap.getDouble(WEATHER_DATA_LOW);
long id = dataMap.getLong(WEATHER_DATA_ID);
mWeather = (int) Math.round(high) + "/" + (int) Math.round(low);
mWeatherId = (int) id;
loadIconForWeatherId();
SharedPreferences preferences = getSharedPreferences(PREFERENCES, MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putString(KEY_WEATHER, mWeather);
editor.putInt(KEY_WEATHER_ID, mWeatherId);
editor.apply();
}
}
}
示例9: onDataChanged
import com.google.android.gms.wearable.DataItem; //導入依賴的package包/類
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
Log.d(LOG_TAG, "onDataChanged" );
for (DataEvent dataEvent : dataEvents) {
if (DataEvent.TYPE_CHANGED == dataEvent.getType()) {
DataItem dataItem = dataEvent.getDataItem();
DataMap dataMap = DataMapItem.fromDataItem(dataItem).getDataMap();
String path = dataEvent.getDataItem().getUri().getPath();
if (path.equals(WEATHER_PATH)) {
Log.d(LOG_TAG, "/weather id=" + dataMap.getString(KEY_UUID));
SunshineSyncAdapter.syncImmediately(this);
}
}
}
}
示例10: onDataChanged
import com.google.android.gms.wearable.DataItem; //導入依賴的package包/類
/**
* Called whenever a new message sent by the Wearable.
*
* @param dataEvents buffer with transmitted data
*/
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
Log.i(TAG, "onDataChanged()");
for (DataEvent dataEvent : dataEvents) {
if (dataEvent.getType() == DataEvent.TYPE_CHANGED) {
DataItem dataItem = dataEvent.getDataItem();
Uri uri = dataItem.getUri();
String path = uri.getPath();
if (path.startsWith("/sensors/")) {
if (SmartWatch.getInstance() != null) {
SmartWatch.getInstance().unpackSensorData(DataMapItem.fromDataItem(dataItem).getDataMap());
}
}
}
}
}
示例11: onDataChanged
import com.google.android.gms.wearable.DataItem; //導入依賴的package包/類
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
Log.i("DEV", "Wear: MainActivity.onDataChangeListener");
for (DataEvent event : dataEvents) {
if (event.getType() == DataEvent.TYPE_CHANGED) {
// DataItem changed
DataItem item = event.getDataItem();
if (item.getUri().getPath().compareTo("/stayawhile/queue") == 0) {
DataMap dataMap = DataMapItem.fromDataItem(item).getDataMap();
queueUpdated(dataMap.getString(QUEUE_KEY));
}
} else if (event.getType() == DataEvent.TYPE_DELETED) {
// DataItem deleted
}
}
}
示例12: deleteSingleIgcFile
import com.google.android.gms.wearable.DataItem; //導入依賴的package包/類
private void deleteSingleIgcFile(DataItem item) {
item.freeze();
DataMapItem dataMapItem = DataMapItem.fromDataItem(item);
String filename = dataMapItem.getDataMap().getString(Statics.DATADELETE);
File dir = getFilesDir();
File[] subFiles = dir.listFiles();
if (subFiles != null) {
for (File file : subFiles) {
if (filename.contains(Statics.getUTCdateReverse())) return;
if (file.getName().equals(filename)) {
if (file.delete()) {
if (debugMode) Log.d(TAG, "File " + filename + " is deleted.");
Wearable.DataApi.deleteDataItems(mGoogleApiClient, item.getUri());
} else {
if (debugMode) Log.d(TAG, "File " + filename + " delete error.");
}
}
}
}
}
示例13: getExceptionFromWear
import com.google.android.gms.wearable.DataItem; //導入依賴的package包/類
private void getExceptionFromWear(DataItem dataItem) {
if (debugMode) Log.d(TAG, "Exception from wear!!!");
dataItem.freeze();
DataMapItem dataMapItem = DataMapItem.fromDataItem(dataItem);
ByteArrayInputStream bis = new ByteArrayInputStream(dataMapItem.getDataMap().getByteArray("exception"));
Wearable.DataApi.deleteDataItems(mGoogleApiClient, dataItem.getUri());
try {
ObjectInputStream ois = new ObjectInputStream(bis);
Throwable ex = (Throwable) ois.readObject();
FirebaseCrash.log("board: " + dataMapItem.getDataMap().getString("board"));
FirebaseCrash.log("fingerprint: " + dataMapItem.getDataMap().getString("fingerprint"));
FirebaseCrash.log("model: " + dataMapItem.getDataMap().getString("model"));
FirebaseCrash.log("manufacturer: " + dataMapItem.getDataMap().getString("manufacturer"));
FirebaseCrash.log("product: " + dataMapItem.getDataMap().getString("product"));
FirebaseCrash.report(ex);
} catch (IOException | ClassNotFoundException e) {
FirebaseCrash.report(e);
if (debugMode) Log.e(TAG, Log.getStackTraceString(e));
}
}
示例14: getAllAvailableDataItems
import com.google.android.gms.wearable.DataItem; //導入依賴的package包/類
private void getAllAvailableDataItems() {
PendingResult<DataItemBuffer> results = Wearable.DataApi.getDataItems(mGoogleApiClient);
results.setResultCallback(new ResultCallback<DataItemBuffer>() {
@Override
public void onResult(@NonNull DataItemBuffer dataItems) {
if (dataItems.getCount() != 0) {
for (DataItem item : dataItems) {
if (item.getUri().getPath().contains(Statics.DATAIGC)) {
getStringFromAsset(item);
}
if (item.getUri().getPath().contains(Statics.DATATHROWABLE)) {
getExceptionFromWear(item);
}
if (item.getUri().getPath().contains(Statics.DATABTFAILED)) {
getBTFailed(item);
}
}
}
dataItems.release();
}
});
}
示例15: getBTFailed
import com.google.android.gms.wearable.DataItem; //導入依賴的package包/類
private void getBTFailed(DataItem dataItem) {
dataItem.freeze();
final Uri dataItemUri = dataItem.getUri();
DataMapItem dataMapItem = DataMapItem.fromDataItem(dataItem);
final int reason = dataMapItem.getDataMap().getInt("reason");
if (debugMode) Log.d(TAG, "BT failed on wear, reason: " + reason);
switch (reason) {
case Statics.MY_BT_FAILED_NO_BT:
Toast.makeText(getApplicationContext(), R.string.bt_failed_no_bt, Toast.LENGTH_LONG).show();
break;
case Statics.MY_BT_FAILED_NO_DEVICE:
Toast.makeText(getApplicationContext(), R.string.bt_failed_no_device, Toast.LENGTH_LONG).show();
break;
case Statics.MY_BT_FAILED_USER:
Toast.makeText(getApplicationContext(), R.string.bt_failed_user, Toast.LENGTH_LONG).show();
break;
}
Wearable.DataApi.deleteDataItems(mGoogleApiClient, dataItemUri);
prefs.edit().putBoolean(Statics.PREFUSEBTVARIO, false).apply();
checkBoxBT.setChecked(false);
}