Esempio n. 1
0
 private boolean processDataItem(GoogleApiClient googleApiClient, DataItem dataItem) {
   if (!dataItem.getUri().getPath().equals("/artwork")) {
     Log.w(TAG, "Ignoring data item " + dataItem.getUri().getPath());
     return false;
   }
   DataMapItem dataMapItem = DataMapItem.fromDataItem(dataItem);
   DataMap artworkDataMap = dataMapItem.getDataMap().getDataMap("artwork");
   if (artworkDataMap == null) {
     Log.w(TAG, "No artwork in datamap.");
     return false;
   }
   final Artwork artwork = Artwork.fromBundle(artworkDataMap.toBundle());
   final Asset asset = dataMapItem.getDataMap().getAsset("image");
   if (asset == null) {
     Log.w(TAG, "No image asset in datamap.");
     return false;
   }
   // Convert asset into a file descriptor and block until it's ready
   final DataApi.GetFdForAssetResult getFdForAssetResult =
       Wearable.DataApi.getFdForAsset(googleApiClient, asset).await();
   InputStream assetInputStream = getFdForAssetResult.getInputStream();
   if (assetInputStream == null) {
     Log.w(TAG, "Empty asset input stream (probably an unknown asset).");
     return false;
   }
   Bitmap image = BitmapFactory.decodeStream(assetInputStream);
   if (image == null) {
     Log.w(TAG, "Couldn't decode a bitmap from the stream.");
     return false;
   }
   File localCache = new File(getCacheDir(), "cache.png");
   FileOutputStream out = null;
   try {
     out = new FileOutputStream(localCache);
     image.compress(Bitmap.CompressFormat.PNG, 100, out);
   } catch (IOException e) {
     Log.e(TAG, "Error writing local cache", e);
   } finally {
     try {
       if (out != null) {
         out.close();
       }
     } catch (IOException e) {
       Log.e(TAG, "Error closing local cache file", e);
     }
   }
   enableComponents(FullScreenActivity.class);
   if (MuzeiProvider.saveCurrentArtworkLocation(this, localCache)) {
     getContentResolver().insert(MuzeiContract.Artwork.CONTENT_URI, artwork.toContentValues());
   }
   return true;
 }
 @Override
 public void onResult(DataApi.DataItemResult dataItemResult) {
   if (dataItemResult.getStatus().isSuccess()) {
     if (dataItemResult.getDataItem() != null) {
       DataItem configDataItem = dataItemResult.getDataItem();
       DataMapItem dataMapItem = DataMapItem.fromDataItem(configDataItem);
       DataMap config = dataMapItem.getDataMap();
       mCallback.onConfigDataMapFetched(config);
     } else {
       mCallback.onConfigDataMapFetched(new DataMap());
     }
   }
 }
 @Override
 public void onDataChanged(DataEventBuffer dataEvents) {
   for (DataEvent dataEvent : dataEvents) {
     if (dataEvent.getType() == DataEvent.TYPE_CHANGED) {
       if (Constants.NOTIFICATION_PATH.equals(dataEvent.getDataItem().getUri().getPath())) {
         DataMapItem dataMapItem = DataMapItem.fromDataItem(dataEvent.getDataItem());
         String title = dataMapItem.getDataMap().getString(Constants.NOTIFICATION_TITLE);
         String content = dataMapItem.getDataMap().getString(Constants.NOTIFICATION_CONTENT);
         sendNotification(title, content);
       }
     }
   }
 }
Esempio n. 4
0
 @Override
 public void onDataChanged(DataEventBuffer dataEventBuffer) {
   for (DataEvent event : dataEventBuffer) {
     if (event.getType() == DataEvent.TYPE_CHANGED) {
       DataItem item = event.getDataItem();
       DataMap dataMap = DataMapItem.fromDataItem(item).getDataMap();
       if (item.getUri().getPath().compareTo("/headReq") == 0) {
         if (dataMap.getInt("head") == 1 && gameStatus == true) {
           sendHeadVector();
         }
       } else if (item.getUri().getPath().compareTo("/" + RESUME) == 0) {
         if (dataMap.getInt(RESUME) == 1) {
           gameStatus = true;
         }
       } else if (item.getUri().getPath().compareTo("/" + PAUSE) == 0) {
         if (dataMap.getInt(PAUSE) == 1) {
           gameStatus = false;
         }
       } else if (item.getUri().getPath().compareTo("/" + RESTART) == 0) {
         if (dataMap.getInt(RESTART) == 1) {
           gameStatus = true;
         }
       }
     }
   }
 }
Esempio n. 5
0
    @Override
    public void onDataChanged(DataEventBuffer dataEventBuffer) {
      for (DataEvent dataEvent : dataEventBuffer) {
        if (dataEvent.getType() == DataEvent.TYPE_CHANGED) {
          DataMap dataMap = DataMapItem.fromDataItem(dataEvent.getDataItem()).getDataMap();
          String path = dataEvent.getDataItem().getUri().getPath();

          Log.v("BuntinLog", "onDataChanged hit");
          final String WEAR_PATH = "/sunshinewear";
          final String WEAR_HIGH = "high";
          final String WEAR_LOW = "low";
          final String WEAR_WEATHER_ID = "weatherId";

          if (path.equals(WEAR_PATH)) {
            if (dataMap.containsKey(WEAR_HIGH)) {
              mHigh = dataMap.getString(WEAR_HIGH);
            }
            if (dataMap.containsKey(WEAR_LOW)) {
              mLow = dataMap.getString(WEAR_LOW);
            }
            if (dataMap.containsKey(WEAR_WEATHER_ID)) {
              int weatherId = dataMap.getInt(WEAR_WEATHER_ID);
              mWeatherImage = Utility.getImages(weatherId);
            }
          }

          invalidate();
        }
      }
    }
  @Override
  public void onDataChanged(DataEventBuffer dataEvents) {
    for (DataEvent event : dataEvents) {
      if (event.getType() == DataEvent.TYPE_CHANGED) {

        DataMap map = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();

        String path = event.getDataItem().getUri().getPath();

        if ("/sunshine".equals(path)) {
          high = map.getDouble("temp-high");
          low = map.getDouble("temp-low");
          weatherId = map.getInt("weather-id");

          Log.d(LOG_TAG, high + "-" + low + "-" + weatherId);

          Intent intent = new Intent("weather-data");

          intent.putExtra("temp-high", high);
          intent.putExtra("temp-low", low);
          intent.putExtra("weather-id", weatherId);

          LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(intent);
        }
      }
    }
  }
Esempio n. 7
0
  @Override
  public void onDataChanged(DataEventBuffer dataEvents) {
    DataMap dataMap;
    for (DataEvent event : dataEvents) {
      if (event.getType() == DataEvent.TYPE_CHANGED) {
        String path = event.getDataItem().getUri().getPath();

        if (path.equals(PATH_WEATHER_INFO)) {}
        dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();

        Intent messageIntent = new Intent();
        messageIntent.setAction(Intent.ACTION_SEND);
        messageIntent.putExtras(dataMap.toBundle());
        LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent);
      }
    }
  }
  @Override
  public void onDataChanged(DataEventBuffer dataEvents) {
    DataMap dataMap;
    for (DataEvent event : dataEvents) {

      // Check the data type
      if (event.getType() == DataEvent.TYPE_CHANGED) {
        // Check the data path
        dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
        String path = event.getDataItem().getUri().getPath();

        if (path.equals(WEARABLE_TO_PHONE_DATA_PATH) && dataMap.containsKey(ACTION_KEY)) {
          doAction(dataMap.getString(ACTION_KEY), dataMap);
        }
      }
    }
  }
  @Override
  public void onDataChanged(DataEventBuffer dataEvents) {
    for (DataEvent dataEvent : dataEvents) {
      if (dataEvent.getType() == DataEvent.TYPE_CHANGED) {
        DataMap dataMap = DataMapItem.fromDataItem(dataEvent.getDataItem()).getDataMap();
        String message = dataMap.getString(Constants.KEY_TEXT_FROM_SERVER);
        String type = dataMap.getString(Constants.KEY_MESSAGE_TYPE);
        String path = dataEvent.getDataItem().getUri().getPath();

        if (Constants.MESSAGE_WEARABLE_TO_MOBILE_PATH.equals(path)) {
          sendMessageToActivity(message, type);
        }
      } else if (dataEvent.getType() == DataEvent.TYPE_DELETED) {
        Log.d(TAG, "Message deleted");
        if (Log.isLoggable(TAG, Log.DEBUG)) {
          Log.d(TAG, "DataItem deleted: " + dataEvent.getDataItem().getUri().getPath());
        }
        if (Constants.MESSAGE_WEARABLE_TO_MOBILE_PATH.equals(
            dataEvent.getDataItem().getUri().getPath())) {}
      }
    }
  }
 @Override
 public void onDataChanged(DataEventBuffer dataEvents) {
   Log.d("onDataChanged", "Received a data change");
   for (DataEvent event : dataEvents) {
     DataItem item = event.getDataItem();
     if (item.getUri().getPath().compareTo(PATH) == 0) {
       DataMap dataMap = DataMapItem.fromDataItem(item).getDataMap();
       String key = dataMap.getString(ACTION_KEY);
       String checkString, dateString, newGroupName, newItemName;
       switch (key) {
         case MAKE_GROUP_KEY:
           Log.d("DATA", "MAKE_GROUP_KEY RECEIVED");
           groupName = dataMap.getString(GROUP_NAME_KEY);
           groupReaderDbHelper.insertGroup(groupName);
           updateGroupList();
           break;
         case DELETE_GROUP_KEY:
           Log.d("DATA", "DELETE_GROUP_KEY RECEIVED");
           groupName = dataMap.getString(GROUP_NAME_KEY);
           groupReaderDbHelper.deleteGroup(groupName);
           itemReaderDbHelper.deleteItemsInGroup(groupName);
           updateGroupList();
           break;
         case DELETE_ALL_GROUPS_KEY:
           Log.d("DATA", "DELETE_ALL_GROUPS_KEY RECEIVED");
           groupReaderDbHelper.deleteAllGroups();
           itemReaderDbHelper.deleteAllItems();
           updateGroupList();
           break;
         case MAKE_ITEM_KEY:
           Log.d("DATA", "MAKE_ITEM_KEY RECEIVED");
           groupName = dataMap.getString(GROUP_NAME_KEY);
           itemName = dataMap.getString(ITEM_NAME_KEY);
           itemReaderDbHelper.insertItem(groupName, itemName);
           updateItemList();
           break;
         case DELETE_ITEM_KEY:
           Log.d("DATA", "DELETE_ITEM_KEY RECEIVED");
           groupName = dataMap.getString(GROUP_NAME_KEY);
           itemName = dataMap.getString(ITEM_NAME_KEY);
           itemReaderDbHelper.deleteItem(groupName, itemName);
           updateItemList();
           break;
         case DELETE_ALL_ITEMS_IN_GROUP_KEY:
           Log.d("DATA", "DELETE_ALL_ITEMS_IN_GROUP_KEY RECEIVED");
           groupName = dataMap.getString(GROUP_NAME_KEY);
           itemReaderDbHelper.deleteItemsInGroup(groupName);
           updateItemList();
           break;
         case CHECK_KEY:
           Log.d("DATA", "CHECK_KEY RECEIVED");
           groupName = dataMap.getString(GROUP_NAME_KEY);
           itemName = dataMap.getString(ITEM_NAME_KEY);
           checkString = dataMap.getString(CHECK_KEY);
           switch (checkString) {
             case "0":
               itemReaderDbHelper.uncheckItem(groupName, itemName);
               uncheckItem(itemName);
               break;
             case "1":
               // TODOs : change to using broadcast receiver instead
               itemReaderDbHelper.checkItem(groupName, itemName);
               checkItem(itemName);
               break;
           }
           break;
         case DATE_KEY:
           Log.d("DATA", "DATE_KEY RECEIVED");
           groupName = dataMap.getString(GROUP_NAME_KEY);
           itemName = dataMap.getString(ITEM_NAME_KEY);
           dateString = dataMap.getString(DATE_KEY);
           SimpleDateFormat sdf = new SimpleDateFormat("yyy-MM-dd");
           try {
             Date date = sdf.parse(dateString);
             itemReaderDbHelper.updateDateCheckedItem(groupName, itemName, date);
             updateItemList();
           } catch (Exception e) {
             System.out.println(e);
           }
           break;
         case COPY_KEY:
           Log.d("DATA", "COPY_KEY RECEIVED");
           groupName = dataMap.getString(GROUP_NAME_KEY);
           itemName = dataMap.getString(ITEM_NAME_KEY);
           newGroupName = dataMap.getString(NEW_GROUP_NAME_KEY);
           itemReaderDbHelper.copyItem(groupName, newGroupName, itemName);
           updateItemList();
           break;
         case RENAME_ITEM_KEY:
           Log.d("DATA", "RENAME_ITEM_KEY RECEIVED");
           groupName = dataMap.getString(GROUP_NAME_KEY);
           itemName = dataMap.getString(ITEM_NAME_KEY);
           newItemName = dataMap.getString(NEW_ITEM_NAME_KEY);
           itemReaderDbHelper.renameItem(groupName, itemName, newItemName);
           updateItemList();
           break;
         case RENAME_GROUP_KEY:
           Log.d("DATA", "RENAME_GROUP_KEY RECEIVED");
           groupName = dataMap.getString(GROUP_NAME_KEY);
           newGroupName = dataMap.getString(NEW_GROUP_NAME_KEY);
           groupReaderDbHelper.renameGroup(groupName, newGroupName);
           itemReaderDbHelper.renameGroup(groupName, newGroupName);
           updateGroupList();
           break;
         case DONE_KEY:
           groupName = dataMap.getString(GROUP_NAME_KEY);
           doneScanning(groupName);
           break;
       }
     }
   }
 }