Java Code Examples for com.google.android.gms.wearable.MessageEvent#getPath()

The following examples show how to use com.google.android.gms.wearable.MessageEvent#getPath() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IncomingRequestPhoneService.java    From wear-os-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void onMessageReceived(MessageEvent messageEvent) {
    super.onMessageReceived(messageEvent);
    Log.d(TAG, "onMessageReceived(): " + messageEvent);

    String messagePath = messageEvent.getPath();

    if (messagePath.equals(Constants.MESSAGE_PATH_PHONE)) {

        DataMap dataMap = DataMap.fromByteArray(messageEvent.getData());
        int requestType = dataMap.getInt(Constants.KEY_COMM_TYPE, 0);

        if (requestType == Constants.COMM_TYPE_REQUEST_PROMPT_PERMISSION) {
            promptUserForStoragePermission(messageEvent.getSourceNodeId());

        } else if (requestType == Constants.COMM_TYPE_REQUEST_DATA) {
            respondWithStorageInformation(messageEvent.getSourceNodeId());
        }
    }
}
 
Example 2
Source File: IncomingRequestWearService.java    From wear-os-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void onMessageReceived(MessageEvent messageEvent) {
    Log.d(TAG, "onMessageReceived(): " + messageEvent);

    String messagePath = messageEvent.getPath();

    if (messagePath.equals(Constants.MESSAGE_PATH_WEAR)) {
        DataMap dataMap = DataMap.fromByteArray(messageEvent.getData());

        int requestType = dataMap.getInt(Constants.KEY_COMM_TYPE);

        if (requestType == Constants.COMM_TYPE_REQUEST_PROMPT_PERMISSION) {
            promptUserForSensorPermission();

        } else if (requestType == Constants.COMM_TYPE_REQUEST_DATA) {
            respondWithSensorInformation();
        }
    }
}
 
Example 3
Source File: WearMessageListener.java    From watchpresenter with Apache License 2.0 6 votes vote down vote up
@Override
public void onMessageReceived(MessageEvent messageEvent) {
    if (Log.isLoggable(Constants.LOG_TAG, Log.DEBUG)) {
        Log.d(Constants.LOG_TAG, "onDataChanged: " + messageEvent);
    }

    final String messagePath = messageEvent.getPath();
    if(messagePath != null){
        if(messagePath.equals(Constants.NEXT_SLIDE_GESTURE_DETECTED_PATH)) {
            Log.d(Constants.LOG_TAG, "Next slide message received from Wear device...");
            Intent intent = new Intent(SendMessageReceiver.INTENT);
            intent.putExtra(Constants.EXTRA_MESSAGE, Constants.NEXT_SLIDE_MESSAGE);
            sendBroadcast(intent);
        }
        else{
            Log.i(Constants.LOG_TAG, "Received message with unknown path: " + messagePath);
        }
    }
    else{
        Log.e(Constants.LOG_TAG, "Message with null path: " + messageEvent);
    }
}
 
Example 4
Source File: QuizListenerService.java    From AndroidWearable-Samples with Apache License 2.0 5 votes vote down vote up
@Override
public void onMessageReceived(MessageEvent messageEvent) {
    String path = messageEvent.getPath();
    if (path.equals(QUIZ_EXITED_PATH)) {
        // Remove any lingering question notifications.
        ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).cancelAll();
    }
    if (path.equals(QUIZ_ENDED_PATH) || path.equals(QUIZ_EXITED_PATH)) {
        // Quiz ended - display overall results.
        DataMap dataMap = DataMap.fromByteArray(messageEvent.getData());
        int numCorrect = dataMap.getInt(NUM_CORRECT);
        int numIncorrect = dataMap.getInt(NUM_INCORRECT);
        int numSkipped = dataMap.getInt(NUM_SKIPPED);

        Notification.Builder builder = new Notification.Builder(this)
                .setContentTitle(getString(R.string.quiz_report))
                .setSmallIcon(R.drawable.ic_launcher)
                .setLocalOnly(true);
        SpannableStringBuilder quizReportText = new SpannableStringBuilder();
        appendColored(quizReportText, String.valueOf(numCorrect), R.color.dark_green);
        quizReportText.append(" " + getString(R.string.correct) + "\n");
        appendColored(quizReportText, String.valueOf(numIncorrect), R.color.dark_red);
        quizReportText.append(" " + getString(R.string.incorrect) + "\n");
        appendColored(quizReportText, String.valueOf(numSkipped), R.color.dark_yellow);
        quizReportText.append(" " + getString(R.string.skipped) + "\n");

        builder.setContentText(quizReportText);
        if (!path.equals(QUIZ_EXITED_PATH)) {
            // Don't add reset option if user exited quiz (there might not be a quiz to reset!).
            builder.addAction(R.drawable.ic_launcher,
                    getString(R.string.reset_quiz), getResetQuizPendingIntent());
        }
        ((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
                .notify(QUIZ_REPORT_NOTIF_ID, builder.build());
    }
}
 
Example 5
Source File: QuizListenerService.java    From android-Quiz with Apache License 2.0 5 votes vote down vote up
@Override
public void onMessageReceived(MessageEvent messageEvent) {
    String path = messageEvent.getPath();
    if (path.equals(QUIZ_EXITED_PATH)) {
        // Remove any lingering question notifications.
        ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).cancelAll();
    }
    if (path.equals(QUIZ_ENDED_PATH) || path.equals(QUIZ_EXITED_PATH)) {
        // Quiz ended - display overall results.
        DataMap dataMap = DataMap.fromByteArray(messageEvent.getData());
        int numCorrect = dataMap.getInt(NUM_CORRECT);
        int numIncorrect = dataMap.getInt(NUM_INCORRECT);
        int numSkipped = dataMap.getInt(NUM_SKIPPED);

        Notification.Builder builder = new Notification.Builder(this)
                .setContentTitle(getString(R.string.quiz_report))
                .setSmallIcon(R.drawable.ic_launcher)
                .setLocalOnly(true);
        SpannableStringBuilder quizReportText = new SpannableStringBuilder();
        appendColored(quizReportText, String.valueOf(numCorrect), R.color.dark_green);
        quizReportText.append(" " + getString(R.string.correct) + "\n");
        appendColored(quizReportText, String.valueOf(numIncorrect), R.color.dark_red);
        quizReportText.append(" " + getString(R.string.incorrect) + "\n");
        appendColored(quizReportText, String.valueOf(numSkipped), R.color.dark_yellow);
        quizReportText.append(" " + getString(R.string.skipped) + "\n");

        builder.setContentText(quizReportText);
        if (!path.equals(QUIZ_EXITED_PATH)) {
            // Don't add reset option if user exited quiz (there might not be a quiz to reset!).
            builder.addAction(R.drawable.ic_launcher,
                    getString(R.string.reset_quiz), getResetQuizPendingIntent());
        }
        ((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
                .notify(QUIZ_REPORT_NOTIF_ID, builder.build());
    }
}
 
Example 6
Source File: WearService.java    From DaVinci with Apache License 2.0 5 votes vote down vote up
@Override
public void onMessageReceived(MessageEvent messageEvent) {
    super.onMessageReceived(messageEvent);
    DaVinciDaemon.with(getApplicationContext()).handleMessage(messageEvent);

    ConnectionResult connectionResult = mApiClient.blockingConnect(30, TimeUnit.SECONDS);

    if (!connectionResult.isSuccess()) {
        Log.e(TAG, "Failed to connect to GoogleApiClient.");
        return;
    }


    final String path = messageEvent.getPath();

    if (path.equals("hello")) {

        //DaVinciDaemon.with(getApplicationContext()).load("http://lorempixel.com/400/200/").into("/image/0");

        AndroidService androidService = new RestAdapter.Builder()
                .setEndpoint(AndroidService.ENDPOINT)
                .build().create(AndroidService.class);

        androidService.getElements(new Callback<List<Element>>() {
            @Override
            public void success(List<Element> elements, Response response) {
                sendListElements(elements);
            }

            @Override
            public void failure(RetrofitError error) {
            }
        });

    }
}
 
Example 7
Source File: WatchService.java    From WearPay with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onMessageReceived(MessageEvent messageEvent) {
    String path = messageEvent.getPath();
    if (path.equals(PATH_CODE)) {
        String code = new String(messageEvent.getData());
    } else if (path.equals(PATH_PAY_SUCCESS)) {
        wearPayBinder.onPaySuccess();
    }
}
 
Example 8
Source File: DaVinciDaemon.java    From DaVinci with Apache License 2.0 5 votes vote down vote up
public void handleMessage(MessageEvent messageEvent) {
    final String path = messageEvent.getPath();

    if (path.equals(MESSAGE_DAVINCI)) {
        String message = new String(messageEvent.getData());
        if (message.startsWith("http") || message.startsWith("www")) {
            String sendPath = message.hashCode() + "";

            load(message).into(DAVINCI_PATH + sendPath);
        }
    }
}
 
Example 9
Source File: MainActivity.java    From TutosAndroidFrance with MIT License 5 votes vote down vote up
/**
 * Appellé à la réception d'un message envoyé depuis le smartphone
 *
 * @param messageEvent message reçu
 */
@Override
public void onMessageReceived(MessageEvent messageEvent) {
    //traite le message reçu
    final String path = messageEvent.getPath();
    //récupère le contenu du message
    final String message = new String(messageEvent.getData());

    if (path.equals("bonjour")) {
        elementList = new ArrayList<>();
        elementList.add(new Element("Message reçu", message, Color.parseColor("#F44336")));
        startMainScreen();
    }
}
 
Example 10
Source File: WearMessageService.java    From CrossBow with Apache License 2.0 5 votes vote down vote up
@Override
public void onMessageReceived(MessageEvent messageEvent) {
    super.onMessageReceived(messageEvent);
    if(!isCrossBowMessage(messageEvent)) {
        String path = messageEvent.getPath();
        String data = new String(messageEvent.getData());

        Toast.makeText(this, "Message Received from Path - " + path + ", data = " + data, Toast.LENGTH_SHORT).show();
    }
}
 
Example 11
Source File: RequestListenerService.java    From arcgis-runtime-demos-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onMessageReceived(final MessageEvent event) {
  Log.i("Test", "Received message!");
  // When a message is received, build a Google API client and connect it
  // The Wearable API is used for communicating with the Wear device, and the
  // Location API is used when collecting a new feature
  final GoogleApiClient client = new GoogleApiClient.Builder(this)
          .addApi(Wearable.API)
          .addApi(LocationServices.API)
          .build();
  ConnectionResult connectionResult = client.blockingConnect(30, TimeUnit.SECONDS);
  if (!connectionResult.isSuccess()) {
    Log.e("Test", "Failed to connect to GoogleApiClient");
  }
  Log.i("Test", "Successfully connected to Google Api Service");
  // Get the path of the message and handle it appropriately
  String path = event.getPath();
  switch(path) {
    case LAYER_REQUEST:
      handleLayerRequest(event, client);
      break;
    case FEATURE_TYPE_REQUEST:
      handleFeatureTypeRequest(event, client);
      break;
    case FEATURE_TYPE_RESPONSE:
      handleFeatureTypeResponse(event, client);
      break;
  }
}
 
Example 12
Source File: NotificationListenerService.java    From wear-notify-for-reddit with Apache License 2.0 5 votes vote down vote up
@Override public void onMessageReceived(MessageEvent messageEvent) {
    final String path = messageEvent.getPath();
    boolean finishActivity = false;
    String message = "";

    Logger.log("onMessageReceived, path: " + path);

    if (path.equals(Constants.PATH_POST_REPLY_RESULT_SUCCESS)) {
        message = getString(R.string.reply_successful);
    } else if (path.equals(Constants.PATH_POST_REPLY_RESULT_FAILURE)) {
        message = getString(R.string.reply_failed_sad_face);
    } else if (path.equals(Constants.PATH_SAVE_TO_POCKET_RESULT_SUCCESS)) {
        message = getString(R.string.saving_to_pocket_succeeded);
    } else if (path.equals(Constants.PATH_SAVE_TO_POCKET_RESULT_FAILED)) {
        message = getString(R.string.saving_to_pocket_failed_sad_face);
    } else if (path.equals(Constants.PATH_VOTE_RESULT_FAILED)) {
        message = getString(R.string.voting_failed);
    } else if (path.equals(Constants.PATH_VOTE_RESULT_SUCCESS)) {
        message = getString(R.string.voting_succeded);
    } else if (path.equals(Constants.PATH_GET_COMMENTS_RESULT_FAILED)) {
        message = getString(R.string.retrieving_comments_failed);
    } else if (path.equals(Constants.PATH_NO_NEW_POSTS)) {
        message = getString(R.string.no_posts_to_retrieve);
        finishActivity = true;
    }

    logToPhone("Message received, path: " + path + " message: " + message + " finishActivity: " + finishActivity);
    updateUser(message, finishActivity);
}
 
Example 13
Source File: UARTCommandsActivity.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void onMessageReceived(final MessageEvent messageEvent) {
	// If the activity is bound to service it means that it has connected directly to the device. We ignore messages from the handheld.
	if (profile != null)
		return;

	switch (messageEvent.getPath()) {
		case Constants.UART.DEVICE_LINKLOSS:
		case Constants.UART.DEVICE_DISCONNECTED: {
			finish();
			break;
		}
	}
}
 
Example 14
Source File: UARTConfigurationsActivity.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void onMessageReceived(final MessageEvent messageEvent) {
	// If the activity is bound to service it means that it has connected directly to the device. We ignore messages from the handheld.
	if (binder != null)
		return;

	switch (messageEvent.getPath()) {
		case Constants.UART.DEVICE_LINKLOSS:
		case Constants.UART.DEVICE_DISCONNECTED: {
			finish();
			break;
		}
	}
}
 
Example 15
Source File: ListenerService.java    From sensordatacollector with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onMessageReceived(MessageEvent messageEvent)
{
    String path = messageEvent.getPath();

    if(path.equalsIgnoreCase("/activity/started")) {
        Tasks.informThatWearableHasStarted(messageEvent.getData(), this);
        return;
    }

    if(path.equalsIgnoreCase("/activity/destroyed")) {
        Tasks.informThatWearableHasDestroyed(messageEvent.getData());
        return;
    }

    if(path.equalsIgnoreCase("/posture/update")) {
        Tasks.updatePostureValue(messageEvent.getData());
        return;
    }

    if(path.equalsIgnoreCase("/position/update")) {
        Tasks.updatePositionValue(messageEvent.getData());
        return;
    }

    if(path.equalsIgnoreCase("/activity/update")) {
        Tasks.updateActivityValue(messageEvent.getData());
        return;
    }

    if(path.equalsIgnoreCase("/activity/delete")) {
        Tasks.deleteActivityValue(messageEvent.getData());
        return;
    }

    if(path.startsWith("/database/request")) {
        Tasks.processDatabaseRequest(path, messageEvent.getData());
        return;
    }

    if(path.startsWith("/sensor/data")) {
        Tasks.processIncomingSensorData(path, messageEvent.getData());
        return;
    }

    if(path.startsWith("/sensor/blob")) {
        Tasks.processIncomingSensorBlob(path, messageEvent.getData());
        return;
    }

    super.onMessageReceived(messageEvent);
}
 
Example 16
Source File: ListenerService.java    From sensordatacollector with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onMessageReceived(MessageEvent messageEvent)
{
    String path = messageEvent.getPath();

    if(path.equalsIgnoreCase("/activity/start")) {
        Tasks.startWearableApp(this);
        return;
    }

    if(path.equalsIgnoreCase("/activity/destroy")) {
        Tasks.destroyWearableApp(messageEvent.getData());
        return;
    }

    if(path.startsWith("/database/response")) {
        Tasks.processDatabaseResponse(path, messageEvent.getData());
        return;
    }

    if(path.equalsIgnoreCase("/database/delete")) {
        Tasks.deleteDatabase(this.getBaseContext());
        return;
    }

    if(path.equalsIgnoreCase("/sensor/register")) {
        Tasks.registerSensor(messageEvent.getData());
        return;
    }

    if(path.startsWith("/sensor/unregister")) {
        Tasks.unregisterSensor(messageEvent.getData());
        return;
    }

    if(path.startsWith("/sensor/blob/confirm")) {
        Tasks.confirmBlob(path);
        return;
    }

    if(path.equalsIgnoreCase("/settings")) {
        Tasks.updateSettings(this.getBaseContext(), messageEvent.getData());
        return;
    }

    super.onMessageReceived(messageEvent);
}
 
Example 17
Source File: DataLayerListenerService.java    From DeviceConnect-Android with MIT License 4 votes vote down vote up
@Override
public void onMessageReceived(final MessageEvent messageEvent) {
    // get id of wear device
    String id = messageEvent.getSourceNodeId();
    String action = messageEvent.getPath();
    if (action.equals(WearConst.DEVICE_TO_WEAR_VIBRATION_RUN)) {
        startVibration(messageEvent);
    } else if (action.equals(WearConst.DEVICE_TO_WEAR_VIBRATION_DEL)) {
        stopVibration();
    } else if (action.equals(WearConst.DEVICE_TO_WEAR_CANCAS_DELETE_IMAGE)) {
        deleteCanvas();
    } else if (action.equals(WearConst.DEVICE_TO_WEAR_DEIVCEORIENTATION_REGISTER)) {
        startSensorService(id);
    } else if (action.equals(WearConst.DEVICE_TO_WEAR_DEIVCEORIENTATION_UNREGISTER)) {
        stopSensorService(id);
    } else if (action.equals(WearConst.DEVICE_TO_WEAR_KEYEVENT_ONDOWN_REGISTER)) {
        startKeyEventActivity(WearConst.DEVICE_TO_WEAR_KEYEVENT_ONDOWN_REGISTER, id);
    } else if (action.equals(WearConst.DEVICE_TO_WEAR_KEYEVENT_ONDOWN_UNREGISTER)) {
        startKeyEventActivity(WearConst.DEVICE_TO_WEAR_KEYEVENT_ONDOWN_UNREGISTER, id);
    } else if (action.equals(WearConst.DEVICE_TO_WEAR_KEYEVENT_ONUP_REGISTER)) {
        startKeyEventActivity(WearConst.DEVICE_TO_WEAR_KEYEVENT_ONUP_REGISTER, id);
    } else if (action.equals(WearConst.DEVICE_TO_WEAR_KEYEVENT_ONUP_UNREGISTER)) {
        startKeyEventActivity(WearConst.DEVICE_TO_WEAR_KEYEVENT_ONUP_UNREGISTER, id);
    } else if (action.equals(WearConst.DEVICE_TO_WEAR_KEYEVENT_ONKEYCHANGE_REGISTER)) {
        startKeyEventActivity(WearConst.DEVICE_TO_WEAR_KEYEVENT_ONKEYCHANGE_REGISTER, id);
    } else if (action.equals(WearConst.DEVICE_TO_WEAR_KEYEVENT_ONKEYCHANGE_UNREGISTER)) {
        startKeyEventActivity(WearConst.DEVICE_TO_WEAR_KEYEVENT_ONKEYCHANGE_UNREGISTER, id);
    } else if (action.equals(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCH_REGISTER)) {
        startTouchActivity(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCH_REGISTER, id);
    } else if (action.equals(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHSTART_REGISTER)) {
        startTouchActivity(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHSTART_REGISTER, id);
    } else if (action.equals(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHEND_REGISTER)) {
        startTouchActivity(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHEND_REGISTER, id);
    } else if (action.equals(WearConst.DEVICE_TO_WEAR_TOUCH_ONDOUBLETAP_REGISTER)) {
        startTouchActivity(WearConst.DEVICE_TO_WEAR_TOUCH_ONDOUBLETAP_REGISTER, id);
    } else if (action.equals(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHMOVE_REGISTER)) {
        startTouchActivity(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHMOVE_REGISTER, id);
    } else if (action.equals(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHCANCEL_REGISTER)) {
        startTouchActivity(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHCANCEL_REGISTER, id);
    } else if (action.equals(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHCHANGE_REGISTER)) {
        startTouchActivity(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHCHANGE_REGISTER, id);
    } else if (action.equals(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCH_UNREGISTER)) {
        startTouchActivity(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCH_UNREGISTER, id);
    } else if (action.equals(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHSTART_UNREGISTER)) {
        startTouchActivity(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHSTART_UNREGISTER, id);
    } else if (action.equals(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHEND_UNREGISTER)) {
        startTouchActivity(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHEND_UNREGISTER, id);
    } else if (action.equals(WearConst.DEVICE_TO_WEAR_TOUCH_ONDOUBLETAP_UNREGISTER)) {
        startTouchActivity(WearConst.DEVICE_TO_WEAR_TOUCH_ONDOUBLETAP_UNREGISTER, id);
    } else if (action.equals(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHMOVE_UNREGISTER)) {
        startTouchActivity(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHMOVE_UNREGISTER, id);
    } else if (action.equals(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHCANCEL_UNREGISTER)) {
        startTouchActivity(WearConst.DEVICE_TO_WEAR_TOUCH_ONTOUCHCANCEL_UNREGISTER, id);
    } else if (action.equals(WearConst.DEVICE_TO_WEAR_SET_ID)) {
        String wearId = new String(messageEvent.getData());
        ((WearApplication) getApplication()).setSelfId(wearId);
    } else {
        if (BuildConfig.DEBUG) {
            Log.e("Wear", "unknown event:" + action);
        }
    }
}
 
Example 18
Source File: WearService.java    From LibreAlarm with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onMessageReceived(MessageEvent messageEvent) {
    String data = new String(messageEvent.getData(), Charset.forName("UTF-8"));
    Log.i(TAG, "Message receiver: " + messageEvent.getPath() + ", " + data);
    switch (messageEvent.getPath()) {
        case WearableApi.CANCEL_ALARM:
            stopAlarm();
            break;
        case WearableApi.SETTINGS:
            Toast.makeText(this, R.string.settings_updated_on_watch, Toast.LENGTH_LONG).show();
            HashMap<String, String> prefs = PreferencesUtil.toMap(data);
            for (String key : prefs.keySet()) {
                PreferencesUtil.putString(this, key + QuickSettingsItem.WATCH_VALUE, prefs.get(key));
            }

            if (mListener != null) mListener.onWatchSettingsUpdated();
            break;
        case WearableApi.STATUS:
            mReadingStatus = new Gson().fromJson(data, Status.class);
            Status.Type type = mReadingStatus.status;
            if (type == Status.Type.ALARM_HIGH || type == Status.Type.ALARM_LOW) {
                startAlarm(mReadingStatus);
            } else {
                stopAlarm();
            }
            updateAlarmReceiver(type != Status.Type.NOT_RUNNING);
            updateNotification(type != Status.Type.NOT_RUNNING);
            if (mListener != null) mListener.onDataUpdated();
            break;
        case WearableApi.GLUCOSE:
            ReadingData.TransferObject object =
                    new Gson().fromJson(data, ReadingData.TransferObject.class);
            if (mLastReading == null || mLastReading.realDate < object.data.prediction.realDate) {
                mLastReading = object.data.prediction;
                if (mAlarmReceiverIsRunning) AlarmReceiver.post(this);
                updateNotification((mReadingStatus.status == null ? null : mReadingStatus.status != Status.Type.NOT_RUNNING));
            }

            mDatabase.storeReading(object.data);
            WearableApi.sendMessage(mGoogleApiClient, WearableApi.GLUCOSE, String.valueOf(object.id), null);
            if (mListener != null) mListener.onDataUpdated();
            if (PreferencesUtil.isXdripPlusEnabled(this)) XdripPlusBroadcast.syncXdripPlus(getApplicationContext(),data,object,getBatteryLevel());
            if (PreferencesUtil.isNsRestEnabled(this)) syncNightscout();
            runTextToSpeech(object.data.prediction);
            break;
    }
}
 
Example 19
Source File: MainPhoneActivity.java    From wear-os-samples with Apache License 2.0 4 votes vote down vote up
public void onMessageReceived(MessageEvent messageEvent) {
    Log.d(TAG, "onMessageReceived(): " + messageEvent);

    String messagePath = messageEvent.getPath();

    if (messagePath.equals(Constants.MESSAGE_PATH_PHONE)) {
        DataMap dataMap = DataMap.fromByteArray(messageEvent.getData());

        int commType = dataMap.getInt(Constants.KEY_COMM_TYPE, 0);

        if (commType == Constants.COMM_TYPE_RESPONSE_PERMISSION_REQUIRED) {
            mWearBodySensorsPermissionApproved = false;
            updateWearButtonOnUiThread();

            /* Because our request for remote data requires a remote permission, we now launch
             * a splash activity informing the user we need those permissions (along with
             * other helpful information to approve).
             */
            Intent wearPermissionRationale =
                    new Intent(this, WearPermissionRequestActivity.class);
            startActivityForResult(wearPermissionRationale, REQUEST_WEAR_PERMISSION_RATIONALE);

        } else if (commType == Constants.COMM_TYPE_RESPONSE_USER_APPROVED_PERMISSION) {
            mWearBodySensorsPermissionApproved = true;
            updateWearButtonOnUiThread();
            logToUi("User approved permission on remote device, requesting data again.");
            DataMap outgoingDataRequestDataMap = new DataMap();
            outgoingDataRequestDataMap.putInt(Constants.KEY_COMM_TYPE,
                    Constants.COMM_TYPE_REQUEST_DATA);
            sendMessage(outgoingDataRequestDataMap);

        } else if (commType == Constants.COMM_TYPE_RESPONSE_USER_DENIED_PERMISSION) {
            mWearBodySensorsPermissionApproved = false;
            updateWearButtonOnUiThread();
            logToUi("User denied permission on remote device.");

        } else if (commType == Constants.COMM_TYPE_RESPONSE_DATA) {
            mWearBodySensorsPermissionApproved = true;
            String storageDetails = dataMap.getString(Constants.KEY_PAYLOAD);
            updateWearButtonOnUiThread();
            logToUi(storageDetails);

        } else {
            Log.d(TAG, "Unrecognized communication type received.");
        }
    }
}
 
Example 20
Source File: MainWearActivity.java    From wear-os-samples with Apache License 2.0 4 votes vote down vote up
public void onMessageReceived(MessageEvent messageEvent) {
    Log.d(TAG, "onMessageReceived(): " + messageEvent);

    String messagePath = messageEvent.getPath();

    if (messagePath.equals(Constants.MESSAGE_PATH_WEAR)) {

        DataMap dataMap = DataMap.fromByteArray(messageEvent.getData());
        int commType = dataMap.getInt(Constants.KEY_COMM_TYPE, 0);

        if (commType == Constants.COMM_TYPE_RESPONSE_PERMISSION_REQUIRED) {
            mPhoneStoragePermissionApproved = false;
            updatePhoneButtonOnUiThread();

            /* Because our request for remote data requires a remote permission, we now launch
             * a splash activity informing the user we need those permissions (along with
             * other helpful information to approve).
             */
            Intent phonePermissionRationaleIntent =
                    new Intent(this, RequestPermissionOnPhoneActivity.class);
            startActivityForResult(phonePermissionRationaleIntent, REQUEST_PHONE_PERMISSION);

        } else if (commType == Constants.COMM_TYPE_RESPONSE_USER_APPROVED_PERMISSION) {
            mPhoneStoragePermissionApproved = true;
            updatePhoneButtonOnUiThread();
            logToUi("User approved permission on remote device, requesting data again.");
            DataMap outgoingDataRequestDataMap = new DataMap();
            outgoingDataRequestDataMap.putInt(Constants.KEY_COMM_TYPE,
                    Constants.COMM_TYPE_REQUEST_DATA);
            sendMessage(outgoingDataRequestDataMap);

        } else if (commType == Constants.COMM_TYPE_RESPONSE_USER_DENIED_PERMISSION) {
            mPhoneStoragePermissionApproved = false;
            updatePhoneButtonOnUiThread();
            logToUi("User denied permission on remote device.");

        } else if (commType == Constants.COMM_TYPE_RESPONSE_DATA) {
            mPhoneStoragePermissionApproved = true;
            String storageDetails = dataMap.getString(Constants.KEY_PAYLOAD);
            updatePhoneButtonOnUiThread();
            logToUi(storageDetails);
        }
    }
}