/**
  * delete event を送る.
  *
  * @param profile profile.
  * @param attribute attribute.
  * @param mgr PebbleManager
  */
 private void sendDeleteEvent(final int profile, final int attribute, final PebbleManager mgr) {
   PebbleDictionary dic = new PebbleDictionary();
   dic.addInt8(PebbleManager.KEY_PROFILE, (byte) profile);
   dic.addInt8(PebbleManager.KEY_ATTRIBUTE, (byte) attribute);
   dic.addInt8(PebbleManager.KEY_ACTION, (byte) PebbleManager.ACTION_DELETE);
   mgr.sendCommandToPebble(dic, null);
 }
 @Override
 protected boolean onPutOnDeviceOrientation(
     final Intent request, final Intent response, final String deviceId, final String sessionKey) {
   if (deviceId == null) {
     MessageUtils.setEmptyDeviceIdError(response);
     return true;
   } else if (!PebbleUtil.checkDeviceId(deviceId)) {
     MessageUtils.setNotFoundDeviceError(response);
     return true;
   } else if (sessionKey == null) {
     MessageUtils.setInvalidRequestParameterError(response, ERROR_MESSAGE);
     return true;
   } else {
     PebbleManager mgr = ((PebbleDeviceService) getContext()).getPebbleManager();
     // Pebbleで加速度センサーの登録依頼を送る
     PebbleDictionary dic = new PebbleDictionary();
     dic.addInt8(PebbleManager.KEY_PROFILE, (byte) PebbleManager.PROFILE_DEVICE_ORIENTATION);
     dic.addInt8(
         PebbleManager.KEY_ATTRIBUTE,
         (byte) PebbleManager.DEVICE_ORIENTATION_ATTRIBUTE_ON_DEVICE_ORIENTATION);
     dic.addInt8(PebbleManager.KEY_ACTION, (byte) PebbleManager.ACTION_PUT);
     mgr.sendCommandToPebble(
         dic,
         new OnSendCommandListener() {
           @Override
           public void onReceivedData(final PebbleDictionary dic) {
             if (dic == null) {
               MessageUtils.setUnknownError(response);
             } else {
               // イベントリスナーを登録
               EventError error = EventManager.INSTANCE.addEvent(request);
               if (error == EventError.NONE) {
                 setResult(response, DConnectMessage.RESULT_OK);
               } else if (error == EventError.INVALID_PARAMETER) {
                 MessageUtils.setInvalidRequestParameterError(response);
               } else {
                 MessageUtils.setUnknownError(response);
               }
             }
             getContext().sendBroadcast(response);
           }
         });
     // レスポンスを非同期で返却するので、falseを返す
     return false;
   }
 }
Esempio n. 3
0
  /**
   * Sends an event to the app, and tells whether it's been added or removed
   *
   * @param e
   * @param added
   */
  public void sendEvent(Event e, boolean added) {
    byte b_false = 0;
    byte b_true = 1;
    PebbleDictionary data = new PebbleDictionary();
    //		data.addInt32(0,e.hashCode); //The batch number of this transaction
    data.addInt8(1, added ? b_true : b_false); // I have no idea what I'm doing
    data.addInt32(2, e.startDay);
    data.addInt32(3, e.endDay);
    data.addInt32(4, e.startTime);
    data.addInt32(5, e.endTime);
    data.addString(6, e.title);
    pending_events.put(COUNTER, data);
    Log.i(MainActivity.TAG, "start time:" + e.startTime);
    Log.i(MainActivity.TAG, "start day:" + e.startDay);

    pending_events.put(COUNTER, data);
    PebbleKit.sendDataToPebbleWithTransactionId(
        ctx, PEBBLE_APP_UUID, data, COUNTER); // counter is also transaction ID
    COUNTER++;
  }