/** * 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; } }