com.getpebble.android.kit.util.PebbleDictionary Java Examples

The following examples show how to use com.getpebble.android.kit.util.PebbleDictionary. 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: PebbleKit.java    From BetterWeather with Apache License 2.0 6 votes vote down vote up
/**
 * Send one-or-more key-value pairs to the watch-app identified by the provided UUID.
 * <p/>
 * The watch-app and phone-app must agree of the set and type of key-value pairs being exchanged. Type mismatches or
 * missing keys will cause errors on the receiver's end.
 *
 * @param context
 *         The context used to send the broadcast.
 * @param watchappUuid
 *         A UUID uniquely identifying the target application. UUIDs for the stock kit applications are available in
 *         {@link Constants}.
 * @param data
 *         A dictionary containing one-or-more key-value pairs. For more information about the types of data that
 *         can be stored, see {@link PebbleDictionary}.
 * @param transactionId
 *         An integer uniquely identifying the transaction. This can be used to correlate messages sent to the
 *         Pebble and ACK/NACKs received from the Pebble.
 *
 * @throws IllegalArgumentException
 *         Thrown in the specified PebbleDictionary or UUID is invalid.
 */
public static void sendDataToPebbleWithTransactionId(final Context context,
                                                     final UUID watchappUuid, final PebbleDictionary data, final int transactionId)
        throws IllegalArgumentException {

    if (watchappUuid == null) {
        throw new IllegalArgumentException("uuid cannot be null");
    }

    if (data == null) {
        throw new IllegalArgumentException("data cannot be null");
    }

    if (data.size() == 0) {
        return;
    }

    final Intent sendDataIntent = new Intent(INTENT_APP_SEND);
    sendDataIntent.putExtra(APP_UUID, watchappUuid);
    sendDataIntent.putExtra(TRANSACTION_ID, transactionId);
    sendDataIntent.putExtra(MSG_DATA, data.toJsonString());
    context.sendBroadcast(sendDataIntent);
}
 
Example #2
Source File: PebbleDisplayTrend.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private void evaluateDataFromPebble(PebbleDictionary data) {

        try {
        if (data.size() > 0) {
            pebble_sync_value = data.getUnsignedIntegerAsLong(SYNC_KEY);
            pebble_platform = data.getUnsignedIntegerAsLong(PLATFORM_KEY);
            pebble_app_version = data.getString(VERSION_KEY);
            Log.d(TAG, "receiveData: pebble_sync_value=" + pebble_sync_value + ", pebble_platform=" + pebble_platform + ", pebble_app_version=" + pebble_app_version);

                switch ((int) pebble_platform) {
                    case 0:
                        if (PebbleUtil.pebbleDisplayType != PebbleDisplayType.TrendClassic) {
                            PebbleUtil.pebbleDisplayType = PebbleDisplayType.TrendClassic;
                            //JoH.static_toast_short("Switching to Pebble Classic Trend");
                            Log.d(TAG, "Changing to Classic Trend due to platform id");
                        }
                        break;
                }

        } else {
            Log.d(TAG, "receiveData: pebble_app_version not known");
        }
        } catch (NullPointerException e) {
            Log.e(TAG, "Got exception trying to parse data from pebble: " + e);
    }
    }
 
Example #3
Source File: PebbleServiceCommandTest.java    From JayPS-AndroidApp with MIT License 6 votes vote down vote up
@SmallTest
public void testSendsLocationToPebbleWhenNotCanvasOnly() throws InterruptedException {
    when(_mockPreferences.getString("CANVAS_MODE", "disable")).thenReturn("stuff");

    _command.execute(_app);

    ArgumentCaptor<PebbleDictionary> captor = new ArgumentCaptor<PebbleDictionary>();

    NewLocation event = new NewLocation();
    event.setUnits(0);
    event.setSpeed(45.4f);
    event.setTime(1420988759);

    _bus.post(event);

    verify(_mockMessageManager, timeout(2000).times(1)).offerIfLow(any(PebbleDictionary.class), anyInt());
}
 
Example #4
Source File: PebbleServiceCommandTest.java    From JayPS-AndroidApp with MIT License 6 votes vote down vote up
@SmallTest
public void testDoesNotSendsLocationToPebbleWhenCanvasOnly() throws InterruptedException {
    when(_mockPreferences.getString("CANVAS_MODE", "disable")).thenReturn("canvas_only");

    _command.execute(_app);

    ArgumentCaptor<PebbleDictionary> captor = new ArgumentCaptor<PebbleDictionary>();

    NewLocation event = new NewLocation();
    event.setUnits(0);
    event.setSpeed(45.4f);
    event.setTime(1420988759);

    _bus.post(event);

    verify(_mockMessageManager, timeout(2000).times(0)).offer(any(PebbleDictionary.class));
}
 
Example #5
Source File: PebbleDisplayAbstract.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public void addBatteryStatusToDictionary(PebbleDictionary dictionary) {
    if (doWeDisplayWixelBatteryStatus()) {

        if (isDexBridgeWixel()) {
            dictionary.addString(UPLOADER_BATTERY_KEY, getBatteryString("bridge_battery"));
            dictionary.addString(NAME_KEY, "Bridge");
        } else {
            dictionary.addString(UPLOADER_BATTERY_KEY, getBatteryString("parakeet_battery"));
            dictionary.addString(NAME_KEY, "Phone");
        }

    } else {
        dictionary.addString(UPLOADER_BATTERY_KEY, getPhoneBatteryStatus());
        dictionary.addString(NAME_KEY, "Phone");
    }

}
 
Example #6
Source File: PebbleServiceCommandTest.java    From JayPS-AndroidApp with MIT License 6 votes vote down vote up
@SmallTest
public void testSendsLocationToCanvasWhenNotCanvasDisabled() throws InterruptedException {
    when(_mockPreferences.getString("CANVAS_MODE", "disable")).thenReturn("stuff");

    _command.execute(_app);

    ArgumentCaptor<PebbleDictionary> captor = new ArgumentCaptor<PebbleDictionary>();

    NewLocation event = new NewLocation();
    event.setUnits(0);
    event.setSpeed(45.4f);
    event.setTime(1420988759);

    _bus.post(event);

    verify(_mockCanvasWrapper, timeout(2000).times(1)).set_gpsdata_details(any(GPSData.class), any(Context.class));
}
 
Example #7
Source File: PebbleServiceCommandTest.java    From JayPS-AndroidApp with MIT License 6 votes vote down vote up
@SmallTest
public void testDoesNotSendsLocationToCanvasWhenCanvasDisable() throws InterruptedException {
    when(_mockPreferences.getString("CANVAS_MODE", "disable")).thenReturn("disable");

    _command.execute(_app);

    ArgumentCaptor<PebbleDictionary> captor = new ArgumentCaptor<PebbleDictionary>();

    NewLocation event = new NewLocation();
    event.setUnits(0);
    event.setSpeed(45.4f);
    event.setTime(1420988759);

    _bus.post(event);

    verify(_mockCanvasWrapper, timeout(2000).times(0)).set_gpsdata_details(any(GPSData.class), any(Context.class));
}
 
Example #8
Source File: Pebble.java    From BetterWeather with Apache License 2.0 6 votes vote down vote up
public static void sendWeather(Context appContext, BetterWeatherData weatherData, boolean showFeelsLike) {

        if (PebbleKit.isWatchConnected(appContext)) {
            if (PebbleKit.areAppMessagesSupported(appContext)) {
                try {
                    LogUtils.LOGD(TAG, "Pebble is connected!");

                    PebbleDictionary pebbleData = new PebbleDictionary();
                    pebbleData.addInt8(0, (byte) getWeatherIconId(weatherData.conditionCode));
                    pebbleData.addString(1, getDisplayTemperature(weatherData, showFeelsLike));

                    PebbleKit.sendDataToPebble(appContext, APP_UUID, pebbleData);
                    LogUtils.LOGD(TAG, "Data sent to Pebble.");
                } catch (NullPointerException npe) {
                    npe.printStackTrace();
                }
            } else {
                LogUtils.LOGD(TAG, "Pebble doesn't support AppMessage.");
            }
        } else {
            LogUtils.LOGD(TAG, "Pebble not connected.");
        }

    }
 
Example #9
Source File: PebbleDisplayTrendOld.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private void evaluateDataFromPebble(PebbleDictionary data) {

        try {
            if (data.size() > 0) {
                pebble_sync_value = data.getUnsignedIntegerAsLong(SYNC_KEY);
                pebble_platform = data.getUnsignedIntegerAsLong(PLATFORM_KEY);
                pebble_app_version = data.getString(VERSION_KEY);
                Log.d(TAG, "receiveData: pebble_sync_value=" + pebble_sync_value + ", pebble_platform=" + pebble_platform + ", pebble_app_version=" + pebble_app_version);

                switch ((int) pebble_platform) {
                    case 0:
                        if (PebbleUtil.pebbleDisplayType != PebbleDisplayType.TrendClassic) {
                            PebbleUtil.pebbleDisplayType = PebbleDisplayType.TrendClassic;
                            //JoH.static_toast_short("Switching to Pebble Classic Trend");
                            Log.d(TAG, "Changing to Classic Trend due to platform id");
                        }
                        break;
                }

            } else {
                Log.d(TAG, "receiveData: pebble_app_version not known");
            }
        } catch (NullPointerException e) {
            Log.e(TAG, "Got exception trying to parse data from pebble: " + e);
        }
    }
 
Example #10
Source File: PebbleDataReceiver.java    From JayPS-AndroidApp with MIT License 6 votes vote down vote up
private void handleButtonData(Context context, PebbleDictionary data) {
    int button = data.getUnsignedIntegerAsLong(Constants.CMD_BUTTON_PRESS).intValue();
    Log.i(TAG, "handleButtonData:" + button);

    if (button == Constants.ORUXMAPS_START_RECORD_CONTINUE_PRESS) {
        _oruxMaps.startRecordNewSegment();
    } else if (button == Constants.ORUXMAPS_STOP_RECORD_PRESS) {
        _oruxMaps.stopRecord();
    } else if (button == Constants.ORUXMAPS_NEW_WAYPOINT_PRESS) {
        _oruxMaps.newWaypoint();
    } else if (button == Constants.STOP_PRESS) {
        _serviceStarter.stopLocationServices();
    } else if (button == Constants.PLAY_PRESS) {
        _serviceStarter.startLocationServices();
    } else if (button == Constants.REFRESH_PRESS) {
        resetSavedData(context);
        _bus.post(new ResetGPSState());
    }
}
 
Example #11
Source File: PebbleDisplayTrend.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private void evaluateDataFromPebble(PebbleDictionary data) {

        try {
        if (data.size() > 0) {
            pebble_sync_value = data.getUnsignedIntegerAsLong(SYNC_KEY);
            pebble_platform = data.getUnsignedIntegerAsLong(PLATFORM_KEY);
            pebble_app_version = data.getString(VERSION_KEY);
            Log.d(TAG, "receiveData: pebble_sync_value=" + pebble_sync_value + ", pebble_platform=" + pebble_platform + ", pebble_app_version=" + pebble_app_version);

                switch ((int) pebble_platform) {
                    case 0:
                        if (PebbleUtil.pebbleDisplayType != PebbleDisplayType.TrendClassic) {
                            PebbleUtil.pebbleDisplayType = PebbleDisplayType.TrendClassic;
                            //JoH.static_toast_short("Switching to Pebble Classic Trend");
                            Log.d(TAG, "Changing to Classic Trend due to platform id");
                        }
                        break;
                }

        } else {
            Log.d(TAG, "receiveData: pebble_app_version not known");
        }
        } catch (NullPointerException e) {
            Log.e(TAG, "Got exception trying to parse data from pebble: " + e);
    }
    }
 
Example #12
Source File: PebbleSync.java    From NightWatch with GNU General Public License v3.0 6 votes vote down vote up
private void init() {
    Log.i(TAG, "Initialising...");
    Log.i(TAG, "configuring PebbleDataReceiver");

    PebbleKit.registerReceivedDataHandler(mContext, new PebbleKit.PebbleDataReceiver(PEBBLEAPP_UUID) {
        @Override
        public void receiveData(final Context context, final int transactionId, final PebbleDictionary data) {
            Log.d(TAG, "receiveData: transactionId is " + String.valueOf(transactionId));
            if (lastTransactionId == 0 || transactionId != lastTransactionId) {
                lastTransactionId = transactionId;
                Log.d(TAG, "Received Query. data: " + data.size() + ". sending ACK and data");
                PebbleKit.sendAckToPebble(context, transactionId);
                sendData();
            } else {
                Log.d(TAG, "receiveData: lastTransactionId is "+ String.valueOf(lastTransactionId)+ ", sending NACK");
                PebbleKit.sendNackToPebble(context,transactionId);
            }
        }
    });
}
 
Example #13
Source File: PebbleKit.java    From BetterWeather with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void onReceive(final Context context, final Intent intent) {
    final UUID receivedUuid = (UUID) intent.getSerializableExtra(APP_UUID);

    // Pebble-enabled apps are expected to be good citizens and only inspect broadcasts
    // containing their UUID
    if (!subscribedUuid.equals(receivedUuid)) {
        return;
    }

    final int transactionId = intent.getIntExtra(TRANSACTION_ID, -1);
    final String jsonData = intent.getStringExtra(MSG_DATA);
    if (jsonData == null || jsonData.isEmpty()) {
        return;
    }

    try {
        final PebbleDictionary data = PebbleDictionary.fromJson(jsonData);
        receiveData(context, transactionId, data);
    } catch (JSONException e) {
        e.printStackTrace();
        return;
    }
}
 
Example #14
Source File: PebbleDataReceiver.java    From JayPS-AndroidApp with MIT License 6 votes vote down vote up
@Override
public void receiveData(final Context context, final int transactionId, final PebbleDictionary data) {
    Log.i(TAG, "receiveData" + transactionId);
    ((PebbleBikeApplication)context.getApplicationContext()).inject(this);

    _messageManager.sendAckToPebble(transactionId);

    if (data.contains(Constants.CMD_BUTTON_PRESS)) {
        handleButtonData(context,data);
    }

    if (data.contains(Constants.MSG_VERSION_PEBBLE)) {
        handleVersion(context,data);
    }
    if (data.contains(Constants.MSG_CONFIG)) {
        handleConfig(context, data);
    }
    /*if (data.contains(Constants.MSG_LIVE_ASK_NAMES)) {
        live_max_name = data.getInteger(Constants.MSG_LIVE_ASK_NAMES).intValue();
        Log.d(TAG, "Constants.MSG_LIVE_ASK_NAMES, live_max_name: " + live_max_name);
        start = true;
    }*/

}
 
Example #15
Source File: PebbleDisplayAbstract.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public void addBatteryStatusToDictionary(PebbleDictionary dictionary) {
    if (doWeDisplayWixelBatteryStatus()) {

        if (isDexBridgeWixel()) {
            dictionary.addString(UPLOADER_BATTERY_KEY, getBatteryString("bridge_battery"));
            dictionary.addString(NAME_KEY, "Bridge");
        } else {
            dictionary.addString(UPLOADER_BATTERY_KEY, getBatteryString("parakeet_battery"));
            dictionary.addString(NAME_KEY, "Phone");
        }

    } else {
        dictionary.addString(UPLOADER_BATTERY_KEY, getPhoneBatteryStatus());
        dictionary.addString(NAME_KEY, "Phone");
    }

}
 
Example #16
Source File: PebbleKit.java    From pebble-android-sdk with MIT License 6 votes vote down vote up
/**
 * Send one-or-more key-value pairs to the watch-app identified by the provided UUID.
 *
 * The watch-app and phone-app must agree of the set and type of key-value pairs being exchanged. Type mismatches or
 * missing keys will cause errors on the receiver's end.
 *
 * @param context
 *         The context used to send the broadcast.
 * @param watchappUuid
 *         A UUID uniquely identifying the target application. UUIDs for the stock kit applications are available in
 *         {@link Constants}.
 * @param data
 *         A dictionary containing one-or-more key-value pairs. For more information about the types of data that
 *         can be stored, see {@link PebbleDictionary}.
 * @param transactionId
 *         An integer uniquely identifying the transaction. This can be used to correlate messages sent to the
 *         Pebble and ACK/NACKs received from the Pebble.
 *
 * @throws IllegalArgumentException
 *         Thrown in the specified PebbleDictionary or UUID is invalid.
 */
public static void sendDataToPebbleWithTransactionId(final Context context,
                                                     final UUID watchappUuid, final PebbleDictionary data, final int transactionId)
        throws IllegalArgumentException {

    if (watchappUuid == null) {
        throw new IllegalArgumentException("uuid cannot be null");
    }

    if (data == null) {
        throw new IllegalArgumentException("data cannot be null");
    }

    if (data.size() == 0) {
        return;
    }

    final Intent sendDataIntent = new Intent(INTENT_APP_SEND);
    sendDataIntent.putExtra(APP_UUID, watchappUuid);
    sendDataIntent.putExtra(TRANSACTION_ID, transactionId);
    sendDataIntent.putExtra(MSG_DATA, data.toJsonString());
    context.sendBroadcast(sendDataIntent);
}
 
Example #17
Source File: PebbleDataReceiverTest.java    From JayPS-AndroidApp with MIT License 5 votes vote down vote up
@SmallTest
public void testReceiveDataWithREFRESH_PRESSResetsSavedData() throws InterruptedException {
    PebbleDictionary dic = new PebbleDictionary();
    dic.addUint32(Constants.CMD_BUTTON_PRESS, Constants.REFRESH_PRESS);

    _pebbleDataReceiver.receiveData(_mockContext,12345,dic);

    _stateLatch.await(1000, TimeUnit.MILLISECONDS);
    verify(_mockDataStore,times(1)).resetAllValues();
    verify(_mockDataStore,times(1)).commit();
}
 
Example #18
Source File: LiveMessageToPebbleDictionaryTest.java    From JayPS-AndroidApp with MIT License 5 votes vote down vote up
public void testSetsName3() {
    LiveMessage message = new LiveMessage();
    byte[] data = new byte[1 + LiveTracking.maxNumberOfFriend * LiveTracking.sizeOfAFriend];
    data[0] = 5; // numberOfFriends
    message.setLive(data);
    message.setName3("three");
    PebbleDictionary dic = new LiveMessageToPebbleDictionary(message);

    assertEquals("three", dic.getString(Constants.MSG_LIVE_NAME3));
}
 
Example #19
Source File: PebbleDataReceiverTest.java    From JayPS-AndroidApp with MIT License 5 votes vote down vote up
@SmallTest
public void testReceiveDataWithREFRESH_PRESSRefreshLocationServices() throws InterruptedException {
    PebbleDictionary dic = new PebbleDictionary();
    dic.addUint32(Constants.CMD_BUTTON_PRESS, Constants.REFRESH_PRESS);

    _pebbleDataReceiver.receiveData(_mockContext,12345,dic);

    _stateLatch.await(1000, TimeUnit.MILLISECONDS);
    assertNotNull(_refreshEvent);
}
 
Example #20
Source File: LiveMessageToPebbleDictionaryTest.java    From JayPS-AndroidApp with MIT License 5 votes vote down vote up
public void testSetsName0() {
    LiveMessage message = new LiveMessage();
    byte[] data = new byte[1 + LiveTracking.maxNumberOfFriend * LiveTracking.sizeOfAFriend];
    data[0] = 5; // numberOfFriends
    message.setLive(data);
    message.setName0("zero");
    PebbleDictionary dic = new LiveMessageToPebbleDictionary(message);

    assertEquals("zero", dic.getString(Constants.MSG_LIVE_NAME0));
}
 
Example #21
Source File: PebbleDataReceiverTest.java    From JayPS-AndroidApp with MIT License 5 votes vote down vote up
@SmallTest
public void testReceiveDataWithMSG_VERSION_PEBBLEAndVersionGreaterOrEqualThanCurrentDoesNotSendMessage() throws InterruptedException {
    PebbleDictionary dic = new PebbleDictionary();
    dic.addInt32(Constants.MSG_VERSION_PEBBLE, Constants.LAST_VERSION_PEBBLE);

    _pebbleDataReceiver.receiveData(_mockContext,12345,dic);

    verify(_mockMessageManager, timeout(1000).times(0)).sendMessageToPebble(any(String.class), any(String.class));    }
 
Example #22
Source File: LiveMessageToPebbleDictionaryTest.java    From JayPS-AndroidApp with MIT License 5 votes vote down vote up
public void testSetsName2() {
    LiveMessage message = new LiveMessage();
    byte[] data = new byte[1 + LiveTracking.maxNumberOfFriend * LiveTracking.sizeOfAFriend];
    data[0] = 5; // numberOfFriends
    message.setLive(data);
    message.setName2("two");
    PebbleDictionary dic = new LiveMessageToPebbleDictionary(message);

    assertEquals("two", dic.getString(Constants.MSG_LIVE_NAME2));
}
 
Example #23
Source File: PebbleSync.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public void sendDownload(PebbleDictionary dictionary) {
    if (PebbleKit.isWatchConnected(mContext)) {
        if (dictionary != null && mContext != null) {
            Log.d("PEBBLE PUSHER", "Sending data to pebble");
            PebbleKit.sendDataToPebble(mContext, PEBBLEAPP_UUID, dictionary);
        }
    }
}
 
Example #24
Source File: MessageManager.java    From JayPS-AndroidApp with MIT License 5 votes vote down vote up
public boolean offerIfLow(final PebbleDictionary data, int sizeMax) {
    boolean success = false;
    synchronized (messageQueue) {
        int s = messageQueue.size();
        if (s > sizeMax) {
            if (debug) Log.i(TAG, "offerIfLow s:" + s + ">" + sizeMax);
            if (_isConnected) {
                _skipped++;
                if (_skipped == 50) {
                    // only track 50th message
                    _parseAnalytics.trackSkippedMessage();
                }
                if (_skipped % 20 == 19) {
                    // once every 20 messages, try to send next message in the queue
                    // avoid blocking situation if ack/nack are lost
                    removeMessageASync();
                    consumeAsync();
                }
            }
            return false;
        }
        // reset counter if we can queue the message
        _skipped = 0;
        success = messageQueue.offer(data);
        if (debug) {
            if (s > 1) Log.i(TAG, "offerIfLow s:" + s + "<=" + sizeMax);
        }
    }

    if (success) {
        consumeAsync();
    }

    return success;
}
 
Example #25
Source File: MessageManager.java    From JayPS-AndroidApp with MIT License 5 votes vote down vote up
public boolean offer(final PebbleDictionary data) {
    final boolean success = messageQueue.offer(data);
    if (debug) {
        int s = messageQueue.size();
        if (s > 1) Log.i(TAG, "offer s:" + s);
    }

    if (success) {
        consumeAsync();
    }

    return success;
}
 
Example #26
Source File: MessageManager.java    From JayPS-AndroidApp with MIT License 5 votes vote down vote up
private void consumeAsync() {
    if (debug) Log.v(TAG, "consumeAsync");
    boolean needToWait = false;
    synchronized (_hasStarted) {
        if (_hasStarted.booleanValue() == false) {
            needToWait = true;
        }
    }
    if (needToWait) {
        Log.d(TAG, "Race condition, wait for run()");
        SystemClock.sleep(2000);
    }
    synchronized (_hasStarted) {
        messageHandler.post(new Runnable() {
            @Override
            public void run() {
                synchronized (isMessagePending) {
                    if (isMessagePending.booleanValue()) {
                        return;
                    }

                    synchronized (messageQueue) {
                        if (messageQueue.size() == 0) {
                            return;
                        }
                        transID = (transID + 1) % 256;
                        PebbleDictionary data = messageQueue.peek();
                        if (debug) Log.i(TAG, "sendDataToPebble s:" + messageQueue.size() + " transID:" + transID + " " + data.toJsonString());
                        PebbleKit.sendDataToPebbleWithTransactionId(_applicationContext, Constants.WATCH_UUID, data, transID);
                    }

                    isMessagePending = Boolean.valueOf(true);
                }
            }
        });
    }
}
 
Example #27
Source File: PebbleDataReceiver.java    From JayPS-AndroidApp with MIT License 5 votes vote down vote up
private void handleConfig(Context context, PebbleDictionary data) {
    byte[] config = data.getBytes(Constants.MSG_CONFIG);
    String configString = "";
    for(int i=0; i<config.length; i++) {
        configString += String.format("%02X", config[i]);
    }
    //Log.i(TAG, "config=" + configString);
    SharedPreferences.Editor editor = _sharedPreferences.edit();
    editor.putString("WATCHFACE_CONFIG", configString);
    editor.commit();
}
 
Example #28
Source File: PebbleServiceCommand.java    From JayPS-AndroidApp with MIT License 5 votes vote down vote up
private void sendDataToPebble(PebbleDictionary data, boolean forceSend) {
    if (forceSend) {
        sendDataToPebble(data);
    } else {
        sendDataToPebbleIfPossible(data);
    }
}
 
Example #29
Source File: PebbleServiceCommand.java    From JayPS-AndroidApp with MIT License 5 votes vote down vote up
private void sendLocationToPebble(NewLocation newLocation) {
    PebbleDictionary dictionary = new NewLocationToPebbleDictionary(
            newLocation,
            _navigator,
            true, // forced to true, we're receiving location (can a location arrive after stop event?)
            _sharedPreferences.getBoolean("PREF_DEBUG", false),
            _sharedPreferences.getBoolean("LIVE_TRACKING", false),
            Integer.valueOf(_sharedPreferences.getString("REFRESH_INTERVAL", String.valueOf(Constants.REFRESH_INTERVAL_DEFAULT))),
            _sharedPreferences.getInt("WATCHFACE_VERSION", 0),
            _sharedPreferences.getBoolean("NAV_NOTIFICATION", false)
    );
    sendDataToPebbleIfPossible(dictionary);
}
 
Example #30
Source File: UrchinService.java    From 600SeriesAndroidUploader with MIT License 5 votes vote down vote up
private synchronized void refresh() {
    Log.d(TAG, "sending data to Pebble");

    timeNow = System.currentTimeMillis();
    ignoreACK = timeNow + 2000L;

    PebbleDictionary out = new PebbleDictionary();

    int recency = (int) (timeNow - eventTime) / 1000;

    out.addInt32(KEY.msgType.ordinal(), MSG_TYPE.DATA.ordinal());
    out.addInt32(KEY.recency.ordinal(), recency);
    out.addInt32(KEY.sgvCount.ordinal(), GRAPH_MAX_SGV_COUNT);
    out.addBytes(KEY.sgvs.ordinal(), sgvs);
    out.addInt32(KEY.lastSgv.ordinal(), sgv);
    out.addInt32(KEY.trend.ordinal(), trend);
    out.addInt32(KEY.delta.ordinal(), delta);
    out.addString(KEY.statusText.ordinal(), text);
    out.addBytes(KEY.graphExtra.ordinal(), extra);

    updateID += 13; // odd offset used to stop us syncing to urchin pebble JS ack
    updateID &= 0xFF;
    Log.d(TAG, "refresh: updateID = " + updateID);

    PebbleKit.sendDataToPebbleWithTransactionId(mContext, URCHIN_UUID, out, updateID);

    messageReceiver();
}