本文整理汇总了Java中com.getpebble.android.kit.util.PebbleDictionary类的典型用法代码示例。如果您正苦于以下问题:Java PebbleDictionary类的具体用法?Java PebbleDictionary怎么用?Java PebbleDictionary使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PebbleDictionary类属于com.getpebble.android.kit.util包,在下文中一共展示了PebbleDictionary类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendForecast
import com.getpebble.android.kit.util.PebbleDictionary; //导入依赖的package包/类
private void sendForecast()
{
Collections.sort(m_forecast);
int utcOffset = TimeZone.getDefault().getRawOffset();
long startOfToday = getStartOfDay().getTime();
long minutesSinceStartOfToday = (Calendar.getInstance().getTime().getTime() - startOfToday) / 60000;
for (Forecast f : m_forecast) {
if (m_nackCount > 5)
return;
long minInFuture = (f.getTimeFrom().getTime() - startOfToday + utcOffset) / 60000;
// 172px, 1 px per half-hour period = 5160 minutes; but
// minInFuture is from startOfToday so we usually need to go higher than 5160
if (minInFuture - minutesSinceStartOfToday < 5200 && f.getTemperature() != null) {
PebbleDictionary out = new PebbleDictionary();
out.addInt16(KEY_FORECAST_MINUTES, (short)minInFuture);
out.addInt16(KEY_FORECAST_TEMPERATURE, (short)Math.round(f.getTemperature().getTemperatureDouble() * 10));
// TODO add wind speed? what else?
PebbleKit.sendDataToPebble(m_weatherService, WATCHAPP_UUID, out);
try {
Thread.sleep(SLEEP_BETWEEN_PACKETS);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
示例2: addBatteryStatusToDictionary
import com.getpebble.android.kit.util.PebbleDictionary; //导入依赖的package包/类
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");
}
}
示例3: receiveData
import com.getpebble.android.kit.util.PebbleDictionary; //导入依赖的package包/类
@Override
public void receiveData(int transactionId, PebbleDictionary data) {
Log.d(TAG, "receiveData: transactionId is " + String.valueOf(transactionId));
lastTransactionId = transactionId;
Log.d(TAG, "Received Query. data: " + data.size() + ".");
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);
} else {
Log.d(TAG, "receiveData: pebble_app_version not known");
}
PebbleKit.sendAckToPebble(context, transactionId);
transactionFailed = false;
transactionOk = false;
messageInTransit = false;
sendStep = 5;
sendData();
}
示例4: evaluateDataFromPebble
import com.getpebble.android.kit.util.PebbleDictionary; //导入依赖的package包/类
private void evaluateDataFromPebble(PebbleDictionary data) {
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");
}
}
示例5: sendDataToPebbleWithTransactionId
import com.getpebble.android.kit.util.PebbleDictionary; //导入依赖的package包/类
/**
* 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);
}
示例6: onReceive
import com.getpebble.android.kit.util.PebbleDictionary; //导入依赖的package包/类
/**
* {@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();
}
}
示例7: onRequest
import com.getpebble.android.kit.util.PebbleDictionary; //导入依赖的package包/类
@Override
public boolean onRequest(final Intent request, final Intent response) {
startSensor(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);
}
}
sendResponse(response);
}
});
// レスポンスを非同期で返却するので、falseを返す
return false;
}
示例8: createOrientation
import com.getpebble.android.kit.util.PebbleDictionary; //导入依赖的package包/类
/**
* Pebbleから送られてきたデータからOrientationデータを作成する.
* @param dic 受信したデータ
* @return Orientationデータ
*/
private Bundle createOrientation(final PebbleDictionary dic) {
Long x = dic.getInteger(PebbleManager.KEY_PARAM_DEVICE_ORIENTATION_X);
Long y = dic.getInteger(PebbleManager.KEY_PARAM_DEVICE_ORIENTATION_Y);
Long z = dic.getInteger(PebbleManager.KEY_PARAM_DEVICE_ORIENTATION_Z);
Long interval = dic.getInteger(PebbleManager.KEY_PARAM_DEVICE_ORIENTATION_INTERVAL);
// Pebbleからの加速度をdConnectの単位に正規化してdConnect用のデータを作成
Bundle orientation = new Bundle();
Bundle accelerationIncludingGravity = new Bundle();
setX(accelerationIncludingGravity, x.intValue() * G_TO_MS2_COEFFICIENT);
setY(accelerationIncludingGravity, y.intValue() * G_TO_MS2_COEFFICIENT);
setZ(accelerationIncludingGravity, z.intValue() * G_TO_MS2_COEFFICIENT);
setAccelerationIncludingGravity(orientation, accelerationIncludingGravity);
setInterval(orientation, interval.longValue());
return orientation;
}
示例9: sendOnBatteryChange
import com.getpebble.android.kit.util.PebbleDictionary; //导入依赖的package包/类
/**
* バッテリーの状態変更イベントを送信する.
*
* @param dic バッテリー状態変更イベント
*/
private void sendOnBatteryChange(final PebbleDictionary dic) {
PebbleDeviceService service = (PebbleDeviceService) getContext();
Long level = dic.getInteger(PebbleManager.KEY_PARAM_BATTERY_LEVEL);
if (level == null) {
return;
}
Bundle battery = new Bundle();
setLevel(battery, level.intValue() / TO_PERCENT);
List<Event> evts = EventManager.INSTANCE.getEventList(service.getServiceId(),
PROFILE_NAME, null, ATTRIBUTE_ON_BATTERY_CHANGE);
for (Event evt : evts) {
Intent intent = EventManager.createEventMessage(evt);
setBattery(intent, battery);
sendEvent(intent, evt.getAccessToken());
}
}
示例10: sendOnChargingChange
import com.getpebble.android.kit.util.PebbleDictionary; //导入依赖的package包/类
/**
* バッテリーチャージングイベントを返却する.
*
* @param dic チャージングイベント
*/
private void sendOnChargingChange(final PebbleDictionary dic) {
PebbleDeviceService service = (PebbleDeviceService) getContext();
Long charging = dic.getInteger(PebbleManager.KEY_PARAM_BATTERY_CHARGING);
if (charging == null) {
return;
}
boolean isCharging = (charging.intValue() == PebbleManager.BATTERY_CHARGING_ON);
Bundle battery = new Bundle();
setCharging(battery, isCharging);
List<Event> evts = EventManager.INSTANCE.getEventList(service.getServiceId(),
PROFILE_NAME, null, ATTRIBUTE_ON_CHARGING_CHANGE);
for (Event evt : evts) {
Intent intent = EventManager.createEventMessage(evt);
setBattery(intent, battery);
sendEvent(intent, evt.getAccessToken());
}
}
示例11: onReceive
import com.getpebble.android.kit.util.PebbleDictionary; //导入依赖的package包/类
/**
* {@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;
}
}
示例12: testGetBytesLeft
import com.getpebble.android.kit.util.PebbleDictionary; //导入依赖的package包/类
@Test
public void testGetBytesLeft() throws Exception
{
PebbleCapabilities testCapabilities = new PebbleCapabilities(false, false, false, false, false, 100);
PebbleDictionary testDictionary = new PebbleDictionary();
assertEquals(92, PebbleUtil.getBytesLeft(testDictionary, testCapabilities));
testDictionary.addInt8(1, (byte) 20);
assertEquals(84, PebbleUtil.getBytesLeft(testDictionary, testCapabilities));
testDictionary.addInt32(2, 20);
assertEquals(73, PebbleUtil.getBytesLeft(testDictionary, testCapabilities));
testDictionary.addBytes(3, new byte[]{1, 2, 3, 4});
assertEquals(62, PebbleUtil.getBytesLeft(testDictionary, testCapabilities));
testDictionary.addString(4, "abcde");
assertEquals(50, PebbleUtil.getBytesLeft(testDictionary, testCapabilities));
testDictionary.addUint32(1, 20);
assertEquals(47, PebbleUtil.getBytesLeft(testDictionary, testCapabilities));
}
示例13: init
import com.getpebble.android.kit.util.PebbleDictionary; //导入依赖的package包/类
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);
}
}
});
}
示例14: onStartCommand
import com.getpebble.android.kit.util.PebbleDictionary; //导入依赖的package包/类
public int onStartCommand(Intent intent, int flags, int startId) {
PebbleKit.registerReceivedDataHandler(this, new PebbleKit.PebbleDataReceiver(PEBBLE_APP_UUID) {
@Override
public void receiveData(final Context context, final int transactionId, final PebbleDictionary data) {
Log.i("PebbLIFXService", "Received value = " + data.getUnsignedInteger(0) + " for key: 0");
if (data.getUnsignedInteger(0) == 1 && LFXClient.getSharedInstance(getApplicationContext()).getLocalNetworkContext().isConnected() == false) {
// do nothing
} else {
receiveMessage(data, transactionId);
}
}
});
boolean connected = PebbleKit.isWatchConnected(getApplicationContext());
String pebbleStatus = (connected ? "connected" : "not connected");
Toast.makeText(getApplicationContext(), "PebbLIFXService started, Pebble " + pebbleStatus , Toast.LENGTH_SHORT).show();
Log.i("PebbLIFXService", "Pebble is " + (connected ? "connected" : "not connected"));
// http://stackoverflow.com/questions/15758980/android-service-need-to-run-alwaysnever-pause-or-stop
return START_STICKY;
}
示例15: nackReceived
import com.getpebble.android.kit.util.PebbleDictionary; //导入依赖的package包/类
/**
* Handle nacks: resend if necessary
*
* @param transactionId
*/
private void nackReceived(int transactionId) {
if (transactionId == transactionFlying) {
Log.d("PebbleCommunication", "Received Nack in state " + state + " resend counter: " + numRetries);
final PebbleDictionary dictToResend = lastSentDict;
handler.postDelayed(new Runnable() {
public void run() {
if (dictToResend == lastSentDict && !sendMessage(dictToResend, true)) {
Log.d("PebbleCommunication", "Retries exhausted. Resetting state to begin again");
state = STATE_WAIT_FOR_WATCH_REQUEST;
}
}
}, 3000);
} else {
Log.d("PebbleCommunication", "Received Nack for \"foreign\" transaction");
}
}