mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-24 19:06:53 +01:00
Pebble: send configuration to watch
TODO: handle booleans
This commit is contained in:
parent
fa924ff9d8
commit
2a7f9226a0
@ -5,7 +5,6 @@ import android.net.Uri;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.NavUtils;
|
import android.support.v4.app.NavUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Pair;
|
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.webkit.JavascriptInterface;
|
import android.webkit.JavascriptInterface;
|
||||||
import android.webkit.WebSettings;
|
import android.webkit.WebSettings;
|
||||||
@ -19,10 +18,10 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
||||||
@ -100,28 +99,28 @@ public class ExternalPebbleJSActivity extends Activity {
|
|||||||
|
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
public void sendAppMessage(String msg) {
|
public void sendAppMessage(String msg) {
|
||||||
Log.d("from WEBVIEW", msg);
|
LOG.debug("from WEBVIEW: ", msg);
|
||||||
JSONObject knownKeys = getAppConfigurationKeys();
|
JSONObject knownKeys = getAppConfigurationKeys();
|
||||||
ArrayList<Pair<Integer, Object>> pairs = new ArrayList<>();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
JSONObject in = new JSONObject(msg);
|
JSONObject in = new JSONObject(msg);
|
||||||
|
JSONObject out = new JSONObject();
|
||||||
String cur_key;
|
String cur_key;
|
||||||
for (Iterator<String> key = in.keys(); key.hasNext(); ) {
|
for (Iterator<String> key = in.keys(); key.hasNext(); ) {
|
||||||
cur_key = key.next();
|
cur_key = key.next();
|
||||||
int pebbleAppIndex = knownKeys.optInt(cur_key);
|
int pebbleAppIndex = knownKeys.optInt(cur_key);
|
||||||
if (pebbleAppIndex != 0) {
|
if (pebbleAppIndex != 0) {
|
||||||
//TODO: cast to integer (int32) / String? Is it needed?
|
out.put(String.valueOf(pebbleAppIndex), in.get(cur_key));
|
||||||
pairs.add(new Pair<>(pebbleAppIndex, in.get(cur_key)));
|
|
||||||
LOG.info(in.get(cur_key).getClass().toString());
|
|
||||||
} else {
|
} else {
|
||||||
GB.toast("Discarded key " + cur_key + ", not found in the local configuration.", Toast.LENGTH_SHORT, GB.WARN);
|
GB.toast("Discarded key " + cur_key + ", not found in the local configuration.", Toast.LENGTH_SHORT, GB.WARN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
LOG.info(out.toString());
|
||||||
|
GBApplication.deviceService().onAppConfiguration(appUuid, out.toString());
|
||||||
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
//TODO: send pairs to pebble. (encodeApplicationMessagePush(ENDPOINT_APPLICATIONMESSAGE, uuid, pairs);)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
|
@ -2,6 +2,7 @@ package nodomain.freeyourgadget.gadgetbridge.devices;
|
|||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import android.util.Pair;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -36,6 +37,8 @@ public interface EventHandler {
|
|||||||
|
|
||||||
void onAppDelete(UUID uuid);
|
void onAppDelete(UUID uuid);
|
||||||
|
|
||||||
|
void onAppConfiguration(UUID appUuid, String config);
|
||||||
|
|
||||||
void onFetchActivityData();
|
void onFetchActivityData();
|
||||||
|
|
||||||
void onReboot();
|
void onReboot();
|
||||||
@ -45,4 +48,5 @@ public interface EventHandler {
|
|||||||
void onFindDevice(boolean start);
|
void onFindDevice(boolean start);
|
||||||
|
|
||||||
void onScreenshotReq();
|
void onScreenshotReq();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import android.util.Pair;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -159,6 +160,14 @@ public class GBDeviceService implements DeviceService {
|
|||||||
invokeService(intent);
|
invokeService(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAppConfiguration(UUID uuid, String config) {
|
||||||
|
Intent intent = createIntent().setAction(ACTION_APP_CONFIGURE)
|
||||||
|
.putExtra(EXTRA_APP_UUID, uuid)
|
||||||
|
.putExtra(EXTRA_APP_CONFIG, config);
|
||||||
|
invokeService(intent);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFetchActivityData() {
|
public void onFetchActivityData() {
|
||||||
Intent intent = createIntent().setAction(ACTION_FETCH_ACTIVITY_DATA);
|
Intent intent = createIntent().setAction(ACTION_FETCH_ACTIVITY_DATA);
|
||||||
|
@ -15,7 +15,6 @@ public interface DeviceService extends EventHandler {
|
|||||||
String ACTION_START = PREFIX + ".action.start";
|
String ACTION_START = PREFIX + ".action.start";
|
||||||
String ACTION_CONNECT = PREFIX + ".action.connect";
|
String ACTION_CONNECT = PREFIX + ".action.connect";
|
||||||
String ACTION_NOTIFICATION = PREFIX + ".action.notification";
|
String ACTION_NOTIFICATION = PREFIX + ".action.notification";
|
||||||
String ACTION_NOTIFICATION_SMS = PREFIX + ".action.notification_sms";
|
|
||||||
String ACTION_CALLSTATE = PREFIX + ".action.callstate";
|
String ACTION_CALLSTATE = PREFIX + ".action.callstate";
|
||||||
String ACTION_SETTIME = PREFIX + ".action.settime";
|
String ACTION_SETTIME = PREFIX + ".action.settime";
|
||||||
String ACTION_SETMUSICINFO = PREFIX + ".action.setmusicinfo";
|
String ACTION_SETMUSICINFO = PREFIX + ".action.setmusicinfo";
|
||||||
@ -24,6 +23,7 @@ public interface DeviceService extends EventHandler {
|
|||||||
String ACTION_REQUEST_SCREENSHOT = PREFIX + ".action.request_screenshot";
|
String ACTION_REQUEST_SCREENSHOT = PREFIX + ".action.request_screenshot";
|
||||||
String ACTION_STARTAPP = PREFIX + ".action.startapp";
|
String ACTION_STARTAPP = PREFIX + ".action.startapp";
|
||||||
String ACTION_DELETEAPP = PREFIX + ".action.deleteapp";
|
String ACTION_DELETEAPP = PREFIX + ".action.deleteapp";
|
||||||
|
String ACTION_APP_CONFIGURE = PREFIX + ".action.app_configure";
|
||||||
String ACTION_INSTALL = PREFIX + ".action.install";
|
String ACTION_INSTALL = PREFIX + ".action.install";
|
||||||
String ACTION_REBOOT = PREFIX + ".action.reboot";
|
String ACTION_REBOOT = PREFIX + ".action.reboot";
|
||||||
String ACTION_HEARTRATE_TEST = PREFIX + ".action.heartrate_test";
|
String ACTION_HEARTRATE_TEST = PREFIX + ".action.heartrate_test";
|
||||||
@ -51,6 +51,7 @@ public interface DeviceService extends EventHandler {
|
|||||||
String EXTRA_MUSIC_TRACK = "music_track";
|
String EXTRA_MUSIC_TRACK = "music_track";
|
||||||
String EXTRA_APP_UUID = "app_uuid";
|
String EXTRA_APP_UUID = "app_uuid";
|
||||||
String EXTRA_APP_START = "app_start";
|
String EXTRA_APP_START = "app_start";
|
||||||
|
String EXTRA_APP_CONFIG = "app_configt";
|
||||||
String EXTRA_URI = "uri";
|
String EXTRA_URI = "uri";
|
||||||
String EXTRA_ALARMS = "alarms";
|
String EXTRA_ALARMS = "alarms";
|
||||||
String EXTRA_PERFORM_PAIR = "perform_pair";
|
String EXTRA_PERFORM_PAIR = "perform_pair";
|
||||||
|
@ -40,6 +40,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.ServiceCommand;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
|
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||||
|
|
||||||
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_APP_CONFIGURE;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_CALLSTATE;
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_CALLSTATE;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_CONNECT;
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_CONNECT;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_DELETEAPP;
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_DELETEAPP;
|
||||||
@ -60,6 +61,7 @@ import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_SE
|
|||||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_START;
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_START;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_STARTAPP;
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.ACTION_STARTAPP;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_ALARMS;
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_ALARMS;
|
||||||
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_APP_CONFIG;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_APP_START;
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_APP_START;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_APP_UUID;
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_APP_UUID;
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_CALL_COMMAND;
|
import static nodomain.freeyourgadget.gadgetbridge.model.DeviceService.EXTRA_CALL_COMMAND;
|
||||||
@ -306,6 +308,11 @@ public class DeviceCommunicationService extends Service {
|
|||||||
mDeviceSupport.onAppDelete(uuid);
|
mDeviceSupport.onAppDelete(uuid);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case ACTION_APP_CONFIGURE: {
|
||||||
|
UUID uuid = (UUID) intent.getSerializableExtra(EXTRA_APP_UUID);
|
||||||
|
String config = intent.getStringExtra(EXTRA_APP_CONFIG);
|
||||||
|
mDeviceSupport.onAppConfiguration(uuid, config);
|
||||||
|
}
|
||||||
case ACTION_INSTALL:
|
case ACTION_INSTALL:
|
||||||
Uri uri = intent.getParcelableExtra(EXTRA_URI);
|
Uri uri = intent.getParcelableExtra(EXTRA_URI);
|
||||||
if (uri != null) {
|
if (uri != null) {
|
||||||
|
@ -178,6 +178,14 @@ public class ServiceDeviceSupport implements DeviceSupport {
|
|||||||
delegate.onAppDelete(uuid);
|
delegate.onAppDelete(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAppConfiguration(UUID uuid, String config) {
|
||||||
|
if (checkBusy("app configuration")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
delegate.onAppConfiguration(uuid, config);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFetchActivityData() {
|
public void onFetchActivityData() {
|
||||||
if (checkBusy("fetch activity data")) {
|
if (checkBusy("fetch activity data")) {
|
||||||
|
@ -657,6 +657,11 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
|||||||
// not supported
|
// not supported
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAppConfiguration(UUID uuid, String config) {
|
||||||
|
// not supported
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onScreenshotReq() {
|
public void onScreenshotReq() {
|
||||||
// not supported
|
// not supported
|
||||||
|
@ -1,8 +1,14 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.pebble;
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.pebble;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.util.Pair;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.Alarm;
|
import nodomain.freeyourgadget.gadgetbridge.model.Alarm;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.serial.AbstractSerialDeviceSupport;
|
import nodomain.freeyourgadget.gadgetbridge.service.serial.AbstractSerialDeviceSupport;
|
||||||
@ -37,6 +43,24 @@ public class PebbleSupport extends AbstractSerialDeviceSupport {
|
|||||||
getDeviceIOThread().installApp(uri, 0);
|
getDeviceIOThread().installApp(uri, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAppConfiguration(UUID uuid, String config) {
|
||||||
|
try {
|
||||||
|
ArrayList<Pair<Integer, Object>> pairs = new ArrayList<>();
|
||||||
|
|
||||||
|
JSONObject json = new JSONObject(config);
|
||||||
|
Iterator<String> keysIterator = json.keys();
|
||||||
|
while (keysIterator.hasNext()) {
|
||||||
|
String keyStr = keysIterator.next();
|
||||||
|
Object object = json.get(keyStr);
|
||||||
|
pairs.add(new Pair<>(Integer.parseInt(keyStr), object));
|
||||||
|
}
|
||||||
|
getDeviceIOThread().write(((PebbleProtocol) getDeviceProtocol()).encodeApplicationMessagePush(PebbleProtocol.ENDPOINT_APPLICATIONMESSAGE, uuid, pairs));
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onHeartRateTest() {
|
public void onHeartRateTest() {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user