com.getpebble.android.kit.PebbleKit Java Examples
The following examples show how to use
com.getpebble.android.kit.PebbleKit.
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: PebbleService.java From WheelLogAndroid with GNU General Public License v3.0 | 6 votes |
@Override public int onStartCommand(Intent intent, int flags, int startId) { instance = this; PebbleKit.registerReceivedAckHandler(this, ackReceiver); PebbleKit.registerReceivedNackHandler(this, nackReceiver); PebbleKit.startAppOnPebble(this, APP_UUID); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(Constants.ACTION_BLUETOOTH_CONNECTION_STATE); intentFilter.addAction(Constants.ACTION_WHEEL_DATA_AVAILABLE); intentFilter.addAction(Constants.ACTION_ALARM_TRIGGERED); intentFilter.addAction(Constants.ACTION_PEBBLE_APP_READY); intentFilter.addAction(Constants.ACTION_PEBBLE_APP_SCREEN); intentFilter.addAction(Constants.ACTION_PEBBLE_AFFECTING_PREFERENCE_CHANGED); registerReceiver(mBroadcastReceiver, intentFilter); Intent serviceStartedIntent = new Intent(Constants.ACTION_PEBBLE_SERVICE_TOGGLED) .putExtra(Constants.INTENT_EXTRA_IS_RUNNING, true); sendBroadcast(serviceStartedIntent); mHandler.post(mSendPebbleData); Timber.d("PebbleConnectivity Started"); return START_STICKY; }
Example #2
Source File: Pebble.java From BetterWeather with Apache License 2.0 | 6 votes |
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 #3
Source File: PebbleSync.java From NightWatch with GNU General Public License v3.0 | 6 votes |
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 #4
Source File: ExternalNotificationManager.java From trackworktime with GNU General Public License v3.0 | 6 votes |
public void notifyPebble(String message) { if (PebbleKit.isWatchConnected(context)) { final Intent i = new Intent("com.getpebble.action.SEND_NOTIFICATION"); final Map<String, String> data = new HashMap<>(); data.put("title", "Track Work Time"); data.put("body", message); final JSONObject jsonData = new JSONObject(data); final String notificationData = new JSONArray().put(jsonData).toString(); i.putExtra("messageType", "PEBBLE_ALERT"); i.putExtra("sender", "PebbleKit Android"); i.putExtra("notificationData", notificationData); context.sendBroadcast(i); } }
Example #5
Source File: PebbleSync.java From NightWatch with GNU General Public License v3.0 | 6 votes |
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 #6
Source File: PebbleService.java From WheelLogAndroid with GNU General Public License v3.0 | 6 votes |
@Override public void onDestroy() { unregisterReceiver(mBroadcastReceiver); unregisterReceiver(ackReceiver); unregisterReceiver(nackReceiver); mHandler.removeCallbacksAndMessages(null); instance = null; PebbleKit.closeAppOnPebble(this, APP_UUID); Intent serviceStartedIntent = new Intent(Constants.ACTION_PEBBLE_SERVICE_TOGGLED); serviceStartedIntent.putExtra(Constants.INTENT_EXTRA_IS_RUNNING, false); sendBroadcast(serviceStartedIntent); Timber.i("PebbleConnectivity Stopped"); }
Example #7
Source File: UrchinService.java From 600SeriesAndroidUploader with MIT License | 6 votes |
private void messageReceiver() { if (pebbleAckReceiver == null) { pebbleAckReceiver = new PebbleAckReceiver(URCHIN_UUID) { @Override public void receiveAck(Context context, int transactionId) { Log.d(TAG, "received ACK id=" + transactionId); // an ack from pebble urchin watchface that does not equal the last update id // means a data refresh is needed (workaround for lack of a direct message) // a short ignore period after update/refresh is used to stop a refresh race condition if (transactionId != updateID && System.currentTimeMillis() > ignoreACK) refresh(); else received(); } }; PebbleKit.registerReceivedAckHandler(mContext, pebbleAckReceiver); } }
Example #8
Source File: PebbleDisplayTrend.java From xDrip with GNU General Public License v3.0 | 5 votes |
@Override public void receiveData(int transactionId, PebbleDictionary data) { Log.d(TAG, "receiveData: transactionId is " + String.valueOf(transactionId)); this.pebbleWatchSync.lastTransactionId = transactionId; Log.d(TAG, "Received Query. data: " + data.size() + "."); PebbleKit.sendAckToPebble(this.context, transactionId); evaluateDataFromPebble(data); transactionFailed = false; transactionOk = false; messageInTransit = false; sendStep = 5; sendData(); }
Example #9
Source File: Pebble.java From BetterWeather with Apache License 2.0 | 5 votes |
private static PebbleKit.PebbleDataReceiver getDataReceiver() { if (dataReceiver == null) { dataReceiver = new PebbleKit.PebbleDataReceiver(APP_UUID) { @Override public void receiveData(Context context, int transactionId, PebbleDictionary data) { PebbleKit.sendAckToPebble(context, transactionId); if (data.getInteger(0) == 1) { requestWeatherUpdate(context); } } }; } return dataReceiver; }
Example #10
Source File: MessageManager.java From JayPS-AndroidApp with MIT License | 5 votes |
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 #11
Source File: PebbleSync.java From xDrip with GNU General Public License v3.0 | 5 votes |
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 #12
Source File: PebbleSync.java From NightWatch with GNU General Public License v3.0 | 5 votes |
public void sendDownload(PebbleDictionary dictionary) { if (PebbleKit.isWatchConnected(mContext)) { if (dictionary != null && mContext != null) { Log.d(TAG, "sendDownload: Sending data to pebble"); PebbleKit.sendDataToPebble(mContext, PEBBLEAPP_UUID, dictionary); } } }
Example #13
Source File: UrchinService.java From 600SeriesAndroidUploader with MIT License | 5 votes |
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(); }
Example #14
Source File: PebbleSync.java From NightWatch with GNU General Public License v3.0 | 5 votes |
public void sendDownload(PebbleDictionary dictionary) { if (PebbleKit.isWatchConnected(mContext)) { if (dictionary != null && mContext != null) { Log.d(TAG, "sendDownload: Sending data to pebble"); PebbleKit.sendDataToPebble(mContext, PEBBLEAPP_UUID, dictionary); } } }
Example #15
Source File: PebbleSync.java From xDrip-Experimental with GNU General Public License v3.0 | 5 votes |
public void sendDownload() { if (dictionary != null && mContext != null) { Log.d(TAG, "sendDownload: Sending data to pebble"); messageInTransit = true; transactionFailed = false; transactionOk = false; PebbleKit.sendDataToPebble(mContext, PEBBLEAPP_UUID, dictionary); } }
Example #16
Source File: PebbleSync.java From xDrip-Experimental with GNU General Public License v3.0 | 5 votes |
@Override public int onStartCommand(Intent intent, int flags, int startId) { if(!PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean("broadcast_to_pebble", false)) { stopSelf(); return START_NOT_STICKY; } bgGraphBuilder = new BgGraphBuilder(mContext); if(PebbleKit.isWatchConnected(mContext)) { Log.i(TAG, "onStartCommand called. Sending Sync Request"); transactionFailed = false; transactionOk = false; sendStep = 5; messageInTransit = false; done = true; sendingData = false; dictionary.addInt32(SYNC_KEY, 0); PebbleKit.sendDataToPebble(mContext, PEBBLEAPP_UUID, dictionary); dictionary.remove(SYNC_KEY); if(pebble_app_version.isEmpty() && sentInitialSync){ Log.d(TAG,"onStartCommand: No watch app version, sideloading"); sideloadInstall(mContext, WATCHAPP_FILENAME); } if(!pebble_app_version.contentEquals("xDrip-Pebble2") && sentInitialSync){ Log.d(TAG,"onStartCommand: Wrong watch app version, sideloading"); sideloadInstall(mContext, WATCHAPP_FILENAME); } sentInitialSync = true; } else { Log.d(TAG,"onStartCommand; No watch connected."); } return START_STICKY; }
Example #17
Source File: PebbleDisplayTrendOld.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
@Override public void receiveData(int transactionId, PebbleDictionary data) { Log.d(TAG, "receiveData: transactionId is " + String.valueOf(transactionId)); this.pebbleWatchSync.lastTransactionId = transactionId; Log.d(TAG, "Received Query. data: " + data.size() + "."); PebbleKit.sendAckToPebble(this.context, transactionId); evaluateDataFromPebble(data); transactionFailed = false; transactionOk = false; messageInTransit = false; sendStep = 5; sendData(); }
Example #18
Source File: PebbleWatchSync.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
public static void receiveAppData(int transactionId, PebbleDictionary data) { Log.d(TAG, "receiveAppData: transactionId is " + String.valueOf(transactionId)); AlertPlayer.getPlayer().Snooze(xdrip.getAppContext(), -1); PebbleKit.sendAckToPebble(xdrip.getAppContext(), transactionId); BroadcastSnooze.send(); JoH.static_toast_long("Alarm snoozed by pebble"); }
Example #19
Source File: PebbleDisplayStandard.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
public void receiveData(int transactionId, PebbleDictionary data) { Log.d(TAG, "receiveData: transactionId is " + String.valueOf(transactionId)); if (PebbleWatchSync.lastTransactionId == 0 || transactionId != PebbleWatchSync.lastTransactionId) { PebbleWatchSync.lastTransactionId = transactionId; Log.d(TAG, "Received Query. data: " + data.size() + ". sending ACK and data"); PebbleKit.sendAckToPebble(this.context, transactionId); sendData(); } else { Log.d(TAG, "receiveData: lastTransactionId is " + String.valueOf(PebbleWatchSync.lastTransactionId) + ", sending NACK"); PebbleKit.sendNackToPebble(this.context, transactionId); } }
Example #20
Source File: PebbleDisplayStandard.java From xDrip with GNU General Public License v3.0 | 5 votes |
public void receiveData(int transactionId, PebbleDictionary data) { Log.d(TAG, "receiveData: transactionId is " + String.valueOf(transactionId)); if (PebbleWatchSync.lastTransactionId == 0 || transactionId != PebbleWatchSync.lastTransactionId) { PebbleWatchSync.lastTransactionId = transactionId; Log.d(TAG, "Received Query. data: " + data.size() + ". sending ACK and data"); PebbleKit.sendAckToPebble(this.context, transactionId); sendData(); } else { Log.d(TAG, "receiveData: lastTransactionId is " + String.valueOf(PebbleWatchSync.lastTransactionId) + ", sending NACK"); PebbleKit.sendNackToPebble(this.context, transactionId); } }
Example #21
Source File: PebbleDisplayStandard.java From xDrip with GNU General Public License v3.0 | 5 votes |
public void sendDownload() { if (PebbleKit.isWatchConnected(this.context)) { PebbleDictionary dictionary = buildDictionary(); if (dictionary != null && this.context != null) { Log.d(TAG, "sendDownload: Sending data to pebble"); sendDataToPebble(dictionary); last_time_seen = JoH.ts(); } } else { watchdog(); } }
Example #22
Source File: PebbleWatchSync.java From xDrip with GNU General Public License v3.0 | 5 votes |
public static void receiveAppData(int transactionId, PebbleDictionary data) { Log.d(TAG, "receiveAppData: transactionId is " + String.valueOf(transactionId)); AlertPlayer.getPlayer().Snooze(xdrip.getAppContext(), -1); PebbleKit.sendAckToPebble(xdrip.getAppContext(), transactionId); BroadcastSnooze.send(); JoH.static_toast_long("Alarm snoozed by pebble"); }
Example #23
Source File: PebbleDisplayTrendOld.java From xDrip with GNU General Public License v3.0 | 5 votes |
@Override public void receiveData(int transactionId, PebbleDictionary data) { Log.d(TAG, "receiveData: transactionId is " + String.valueOf(transactionId)); this.pebbleWatchSync.lastTransactionId = transactionId; Log.d(TAG, "Received Query. data: " + data.size() + "."); PebbleKit.sendAckToPebble(this.context, transactionId); evaluateDataFromPebble(data); transactionFailed = false; transactionOk = false; messageInTransit = false; sendStep = 5; sendData(); }
Example #24
Source File: PebbleDisplayTrend.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
@Override public void receiveData(int transactionId, PebbleDictionary data) { Log.d(TAG, "receiveData: transactionId is " + String.valueOf(transactionId)); this.pebbleWatchSync.lastTransactionId = transactionId; Log.d(TAG, "Received Query. data: " + data.size() + "."); PebbleKit.sendAckToPebble(this.context, transactionId); evaluateDataFromPebble(data); transactionFailed = false; transactionOk = false; messageInTransit = false; sendStep = 5; sendData(); }
Example #25
Source File: PebbleDisplayStandard.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
public void sendDownload() { if (PebbleKit.isWatchConnected(this.context)) { PebbleDictionary dictionary = buildDictionary(); if (dictionary != null && this.context != null) { Log.d(TAG, "sendDownload: Sending data to pebble"); sendDataToPebble(dictionary); last_time_seen = JoH.ts(); } } else { watchdog(); } }
Example #26
Source File: PebbleDisplayAbstract.java From xDrip-plus with GNU General Public License v3.0 | 4 votes |
public void sendDataToPebble(final PebbleDictionary data) { synchronized (data) { PebbleKit.sendDataToPebble(this.context, watchfaceUUID(), data); } }
Example #27
Source File: PebbleDisplayTrendOld.java From xDrip with GNU General Public License v3.0 | 4 votes |
public synchronized void sendData() { PowerManager.WakeLock wl = JoH.getWakeLock("pebble-trend-sendData",60000); try { if (lock.tryLock(60, TimeUnit.SECONDS)) { try { if (PebbleKit.isWatchConnected(this.context)) { if (d) Log.d(TAG, "Sendstep: " + sendStep); if (sendStep == 5) { sendStep = 0; done = false; clearDictionary(); } if (d) Log.i(TAG, "sendData: messageInTransit= " + messageInTransit + ", transactionFailed= " + transactionFailed + ", sendStep= " + sendStep); if (sendStep == 0 && !messageInTransit && !transactionOk && !transactionFailed) { if (use_best_glucose) { this.dg = BestGlucose.getDisplayGlucose(); } else { this.bgReading = BgReading.last(); } sendingData = true; buildDictionary(); sendDownload(); } if (sendStep == 0 && !messageInTransit && transactionOk && !transactionFailed) { if (d) Log.i(TAG, "sendData: sendStep 0 complete, clearing dictionary"); clearDictionary(); transactionOk = false; sendStep = 1; } if (sendStep > 0 && sendStep < 5) { if (!doWeDisplayTrendData()) { if (didTrend) { sendTrendToPebble(true); // clear trend image } else { sendStep = 5; } } else { sendTrendToPebble(false); } } if (sendStep == 5) { if (d) Log.i(TAG, "sendData: finished sending. sendStep = " + sendStep); done = true; transactionFailed = false; transactionOk = false; messageInTransit = false; sendingData = false; } } } finally { lock.unlock(); } } else { Log.w(TAG, "Could not acquire lock within timeout!"); } } catch (InterruptedException e) { Log.w(TAG,"Got interrupted while waiting to acquire lock!"); } finally { JoH.releaseWakeLock(wl); } }
Example #28
Source File: PebbleSync.java From xDrip-Experimental with GNU General Public License v3.0 | 4 votes |
public void sendData(){ if (PebbleKit.isWatchConnected(mContext)) { if(sendStep == 5) { sendStep = 0; done=false; dictionary.remove(ICON_KEY); dictionary.remove(BG_KEY); dictionary.remove(NAME_KEY); dictionary.remove(BG_DELTA_KEY); dictionary.remove(PHONE_TIME_KEY); dictionary.remove(RECORD_TIME_KEY); dictionary.remove(UPLOADER_BATTERY_KEY); dictionary.remove(VIBE_KEY); } Log.i(TAG, "sendData: messageInTransit= " + messageInTransit + ", transactionFailed= " + transactionFailed + ", sendStep= " + sendStep); if (sendStep == 0 && !messageInTransit && !transactionOk && !transactionFailed) { mBgReading = BgReading.last(); sendingData = true; buildDictionary(); sendDownload(); } if (sendStep == 0 && !messageInTransit && transactionOk && !transactionFailed) { Log.i(TAG, "sendData: sendStep 0 complete, clearing dictionary"); dictionary.remove(ICON_KEY); dictionary.remove(BG_KEY); dictionary.remove(NAME_KEY); dictionary.remove(BG_DELTA_KEY); dictionary.remove(PHONE_TIME_KEY); dictionary.remove(RECORD_TIME_KEY); dictionary.remove(UPLOADER_BATTERY_KEY); dictionary.remove(VIBE_KEY); transactionOk = false; sendStep = 1; } if (sendStep > 0 && sendStep < 5) { if(!PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean("pebble_display_trend",false)){ sendStep = 5; } else { sendTrendToPebble(); } } if(sendStep == 5) { sendStep = 5; Log.i(TAG, "sendData: finished sending. sendStep = " +sendStep); done = true; transactionFailed = false; transactionOk = false; messageInTransit = false; sendingData = false; } } }
Example #29
Source File: PebbleDisplayTrend.java From xDrip-plus with GNU General Public License v3.0 | 4 votes |
public synchronized void sendData() { PowerManager.WakeLock wl = JoH.getWakeLock("pebble-trend-sendData",60000); try { if (lock.tryLock(60, TimeUnit.SECONDS)) { try { if (PebbleKit.isWatchConnected(this.context)) { if (d) Log.d(TAG, "Sendstep: " + sendStep); if (sendStep == 5) { sendStep = 0; done = false; clearDictionary(); } if (d) Log.i(TAG, "sendData: messageInTransit= " + messageInTransit + ", transactionFailed= " + transactionFailed + ", sendStep= " + sendStep); if (sendStep == 0 && !messageInTransit && !transactionOk && !transactionFailed) { if (use_best_glucose) { this.dg = BestGlucose.getDisplayGlucose(); } else { this.bgReading = BgReading.last(); } sendingData = true; buildDictionary(); sendDownload(); } if (sendStep == 0 && !messageInTransit && transactionOk && !transactionFailed) { if (d) Log.i(TAG, "sendData: sendStep 0 complete, clearing dictionary"); clearDictionary(); transactionOk = false; sendStep = 1; } if (sendStep > 0 && sendStep < 5) { if (!doWeDisplayTrendData()) { if (didTrend) { sendTrendToPebble(true); // clear trend image } else { sendStep = 5; } } else { sendTrendToPebble(false); } } if (sendStep == 5) { if (d) Log.i(TAG, "sendData: finished sending. sendStep = " + sendStep); done = true; transactionFailed = false; transactionOk = false; messageInTransit = false; sendingData = false; } } } finally { lock.unlock(); } } else { Log.w(TAG, "Could not acquire lock within timeout!"); } } catch (InterruptedException e) { Log.w(TAG,"Got interrupted while waiting to acquire lock!"); } finally { JoH.releaseWakeLock(wl); } }
Example #30
Source File: PebbleDisplayTrendOld.java From xDrip-plus with GNU General Public License v3.0 | 4 votes |
public synchronized void sendData() { PowerManager.WakeLock wl = JoH.getWakeLock("pebble-trend-sendData",60000); try { if (lock.tryLock(60, TimeUnit.SECONDS)) { try { if (PebbleKit.isWatchConnected(this.context)) { if (d) Log.d(TAG, "Sendstep: " + sendStep); if (sendStep == 5) { sendStep = 0; done = false; clearDictionary(); } if (d) Log.i(TAG, "sendData: messageInTransit= " + messageInTransit + ", transactionFailed= " + transactionFailed + ", sendStep= " + sendStep); if (sendStep == 0 && !messageInTransit && !transactionOk && !transactionFailed) { if (use_best_glucose) { this.dg = BestGlucose.getDisplayGlucose(); } else { this.bgReading = BgReading.last(); } sendingData = true; buildDictionary(); sendDownload(); } if (sendStep == 0 && !messageInTransit && transactionOk && !transactionFailed) { if (d) Log.i(TAG, "sendData: sendStep 0 complete, clearing dictionary"); clearDictionary(); transactionOk = false; sendStep = 1; } if (sendStep > 0 && sendStep < 5) { if (!doWeDisplayTrendData()) { if (didTrend) { sendTrendToPebble(true); // clear trend image } else { sendStep = 5; } } else { sendTrendToPebble(false); } } if (sendStep == 5) { if (d) Log.i(TAG, "sendData: finished sending. sendStep = " + sendStep); done = true; transactionFailed = false; transactionOk = false; messageInTransit = false; sendingData = false; } } } finally { lock.unlock(); } } else { Log.w(TAG, "Could not acquire lock within timeout!"); } } catch (InterruptedException e) { Log.w(TAG,"Got interrupted while waiting to acquire lock!"); } finally { JoH.releaseWakeLock(wl); } }