Merge remote-tracking branch 'origin/master' into db-refactoring

This commit is contained in:
cpfeiffer 2016-06-19 00:12:02 +02:00
commit 04c8a17d6e
7 changed files with 122 additions and 50 deletions

View File

@ -1,4 +1,10 @@
###Changelog ###Changelog
####Version 0.10.2
* Pebble: allow to manually paste configuration data for legacy configuration pages
* Pebble: various improvements to the configuration page
####Version 0.10.1 ####Version 0.10.1
* Pebble: set extended music info by dissecting notifications on Android 5.0+ * Pebble: set extended music info by dissecting notifications on Android 5.0+
* Pebble: various other improvemnts to music playback * Pebble: various other improvemnts to music playback

View File

@ -261,6 +261,9 @@
</receiver> </receiver>
<activity <activity
android:launchMode="singleTask"
android:allowTaskReparenting="true"
android:clearTaskOnLaunch="true"
android:name=".activities.ExternalPebbleJSActivity" android:name=".activities.ExternalPebbleJSActivity"
android:label="@string/app_configure" android:label="@string/app_configure"
android:parentActivityName=".activities.AppManagerActivity"> android:parentActivityName=".activities.AppManagerActivity">

View File

@ -1,6 +1,6 @@
<!DOCTYPE html> <!DOCTYPE html>
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8"/>
<meta name='viewport' content='initial-scale=1.0, maximum-scale=1.0'> <meta name='viewport' content='initial-scale=1.0, maximum-scale=1.0'>
<script type="text/javascript" src="js/Uri.js"> <script type="text/javascript" src="js/Uri.js">
</script> </script>
@ -52,24 +52,28 @@
<!-- TODO --> <!-- TODO -->
</style> </style>
</head> </head>
<body onload="" style="width: 100%;"> <body>
<div id="step1"> <div id="step1" class="step">
<h2>Url of the configuration:</h2> <h2>Url of the configuration:</h2>
<div id="config_url"></div> <div id="config_url"></div>
<!--<button class="btn" name="show config" value="show config" onclick="Pebble.showConfiguration()" >Show config / URL</button>--> <!--<button class="btn" name="show config" value="show config" onclick="Pebble.showConfiguration()" >Show config / URL</button>-->
<button class="btn" name="open config" value="open config" onclick="Pebble.actuallyOpenURL()" >Open configuration website</button> <button class="btn" name="open config" value="open config" onclick="Pebble.actuallyOpenURL()">
Open configuration website
</button>
</div> </div>
<div id="step1compat"> <div id="step1compat" class="step">
<p>In case of "network error" after saving settings in the wathchapp, copy the "network error" <p>In case of "network error" after saving settings in the watchhapp, copy the "network error"
URL and paste it here:</p> URL and paste it here:</p>
<textarea id="pastereturn"></textarea><br/> <textarea id="pastereturn"></textarea><br/>
<button class="btn" name="parse" onclick="Pebble.parseReturnedPebbleJS()">Parse legacy app <button class="btn" name="parse" onclick="Pebble.parseReturnedPebbleJS()">Parse legacy app
configuration configuration
</button> </button>
</div> </div>
<div id="step2"> <div id="step2" class="step">
<h2>Incoming configuration data:</h2> <h2>Incoming configuration data:</h2>
<div id="jsondata"></div> <div id="jsondata"></div>
<button class="btn" name="send config" value="send config" onclick="Pebble.actuallySendData()" >Send data to pebble</button> <button class="btn" name="send config" value="send config" onclick="Pebble.actuallySendData()">
Send data to pebble
</button>
</div> </div>
</body> </body>

View File

@ -1,3 +1,6 @@
//clay stores the values in the localStorage
localStorage.clear();
function loadScript(url, callback) { function loadScript(url, callback) {
// Adding the script tag to the head as suggested before // Adding the script tag to the head as suggested before
var head = document.getElementsByTagName('head')[0]; var head = document.getElementsByTagName('head')[0];
@ -29,46 +32,63 @@ function getURLVariable(variable, defaultValue) {
return defaultValue || false; return defaultValue || false;
} }
function showStep(desiredStep) {
var steps = document.getElementsByClassName("step");
var testStep = null;
for (var i = 0; i < steps.length; i ++) {
if (steps[i].id == desiredStep)
testStep = steps[i].id;
}
if (testStep !== null) {
for (var i = 0; i < steps.length; i ++) {
steps[i].style.display = 'none';
}
document.getElementById(desiredStep).style.display="block";
}
}
function gbPebble() { function gbPebble() {
this.configurationURL = null; this.configurationURL = null;
this.configurationValues = null; this.configurationValues = null;
var self = this;
this.addEventListener = function(e, f) { this.addEventListener = function(e, f) {
if(e == 'ready') { if(e == 'ready') {
this.ready = f; self.ready = f;
} }
if(e == 'showConfiguration') { if(e == 'showConfiguration') {
this.showConfiguration = f; self.showConfiguration = f;
} }
if(e == 'webviewclosed') { if(e == 'webviewclosed') {
this.parseconfig = f; self.parseconfig = f;
} }
if(e == 'appmessage') { if(e == 'appmessage') {
this.appmessage = f; self.appmessage = f;
} }
} }
this.removeEventListener = function(e, f) { this.removeEventListener = function(e, f) {
if(e == 'ready') { if(e == 'ready') {
this.ready = null; self.ready = null;
} }
if(e == 'showConfiguration') { if(e == 'showConfiguration') {
this.showConfiguration = null; self.showConfiguration = null;
} }
if(e == 'webviewclosed') { if(e == 'webviewclosed') {
this.parseconfig = null; self.parseconfig = null;
} }
if(e == 'appmessage') { if(e == 'appmessage') {
this.appmessage = null; self.appmessage = null;
} }
} }
this.actuallyOpenURL = function() { this.actuallyOpenURL = function() {
document.getElementById('step1compat').style.display="block"; showStep("step1compat");
window.open(this.configurationURL.toString(), "config"); window.open(self.configurationURL.toString(), "config");
} }
this.actuallySendData = function() { this.actuallySendData = function() {
GBjs.sendAppMessage(this.configurationValues); GBjs.sendAppMessage(self.configurationValues);
GBjs.closeActivity();
} }
//needs to be called like this because of original Pebble function name //needs to be called like this because of original Pebble function name
@ -76,7 +96,7 @@ function gbPebble() {
if (url.lastIndexOf("http", 0) === 0) { if (url.lastIndexOf("http", 0) === 0) {
document.getElementById("config_url").innerHTML=url; document.getElementById("config_url").innerHTML=url;
var UUID = GBjs.getAppUUID(); var UUID = GBjs.getAppUUID();
this.configurationURL = new Uri(url).addQueryParam("return_to", "gadgetbridge://"+UUID+"?config=true&json="); self.configurationURL = new Uri(url).addQueryParam("return_to", "gadgetbridge://"+UUID+"?config=true&json=");
} else { } else {
//TODO: add custom return_to //TODO: add custom return_to
location.href = url; location.href = url;
@ -90,7 +110,7 @@ function gbPebble() {
this.sendAppMessage = function (dict, callbackAck, callbackNack){ this.sendAppMessage = function (dict, callbackAck, callbackNack){
try { try {
this.configurationValues = JSON.stringify(dict); self.configurationValues = JSON.stringify(dict);
document.getElementById("jsondata").innerHTML=this.configurationValues; document.getElementById("jsondata").innerHTML=this.configurationValues;
return callbackAck; return callbackAck;
} }
@ -108,6 +128,10 @@ function gbPebble() {
return GBjs.getWatchToken(); return GBjs.getWatchToken();
} }
this.getTimelineToken = function() {
return '';
}
this.showSimpleNotificationOnPebble = function(title, body) { this.showSimpleNotificationOnPebble = function(title, body) {
GBjs.gbLog("app wanted to show: " + title + " body: "+ body); GBjs.gbLog("app wanted to show: " + title + " body: "+ body);
} }
@ -115,18 +139,20 @@ function gbPebble() {
this.ready = function() { this.ready = function() {
} }
this.parseReturnedPebbleJS = function() { this.showConfiguration = function() {
console.error("This watchapp doesn't support configuration");
GBjs.closeActivity();
}
this.parseReturnedPebbleJS = function() {
var str = document.getElementById('pastereturn').value; var str = document.getElementById('pastereturn').value;
var needle = "pebblejs://close#"; var needle = "pebblejs://close#";
if (str.split(needle)[1] !== undefined) { if (str.split(needle)[1] !== undefined) {
var t = new Object(); var t = new Object();
t.response = unescape(str.split(needle)[1]); t.response = unescape(str.split(needle)[1]);
this.parseconfig(t); self.parseconfig(t);
document.getElementById('step1').style.display="none"; showStep("step2");
document.getElementById('step1compat').style.display="none";
document.getElementById('step2').style.display="block";
} else { } else {
console.error("No valid configuration found in the entered string."); console.error("No valid configuration found in the entered string.");
} }
@ -136,13 +162,11 @@ function gbPebble() {
var Pebble = new gbPebble(); var Pebble = new gbPebble();
var jsConfigFile = GBjs.getAppConfigurationFile(); var jsConfigFile = GBjs.getAppConfigurationFile();
document.addEventListener('DOMContentLoaded', function(){
if (jsConfigFile != null) { if (jsConfigFile != null) {
loadScript(jsConfigFile, function() { loadScript(jsConfigFile, function() {
if (getURLVariable('config') == 'true') { if (getURLVariable('config') == 'true') {
document.getElementById('step1').style.display="none"; showStep("step2");
document.getElementById('step1compat').style.display="none";
document.getElementById('step2').style.display="block";
var json_string = unescape(getURLVariable('json')); var json_string = unescape(getURLVariable('json'));
var t = new Object(); var t = new Object();
t.response = json_string; t.response = json_string;
@ -154,3 +178,4 @@ if (jsConfigFile != null) {
} }
}); });
} }
}, false);

View File

@ -30,6 +30,7 @@ import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.adapter.GBDeviceAppAdapter; import nodomain.freeyourgadget.gadgetbridge.adapter.GBDeviceAppAdapter;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceApp; import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceApp;
import nodomain.freeyourgadget.gadgetbridge.model.DeviceService;
import nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol; import nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol;
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils; import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
import nodomain.freeyourgadget.gadgetbridge.util.PebbleUtils; import nodomain.freeyourgadget.gadgetbridge.util.PebbleUtils;
@ -255,7 +256,7 @@ public class AppManagerActivity extends GBActivity {
GBApplication.deviceService().onAppStart(selectedApp.getUUID(), true); GBApplication.deviceService().onAppStart(selectedApp.getUUID(), true);
Intent startIntent = new Intent(getApplicationContext(), ExternalPebbleJSActivity.class); Intent startIntent = new Intent(getApplicationContext(), ExternalPebbleJSActivity.class);
startIntent.putExtra("app_uuid", selectedApp.getUUID()); startIntent.putExtra(DeviceService.EXTRA_APP_UUID, selectedApp.getUUID());
startIntent.putExtra(GBDevice.EXTRA_DEVICE, mGBDevice); startIntent.putExtra(GBDevice.EXTRA_DEVICE, mGBDevice);
startActivity(startIntent); startActivity(startIntent);
return true; return true;

View File

@ -1,5 +1,6 @@
package nodomain.freeyourgadget.gadgetbridge.activities; package nodomain.freeyourgadget.gadgetbridge.activities;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
@ -28,6 +29,7 @@ import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.GBApplication; 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.model.DeviceService;
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils; import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
import nodomain.freeyourgadget.gadgetbridge.util.GB; import nodomain.freeyourgadget.gadgetbridge.util.GB;
import nodomain.freeyourgadget.gadgetbridge.util.PebbleUtils; import nodomain.freeyourgadget.gadgetbridge.util.PebbleUtils;
@ -37,7 +39,9 @@ public class ExternalPebbleJSActivity extends GBActivity {
private static final Logger LOG = LoggerFactory.getLogger(ExternalPebbleJSActivity.class); private static final Logger LOG = LoggerFactory.getLogger(ExternalPebbleJSActivity.class);
private UUID appUuid; private UUID appUuid;
private Uri confUri;
private GBDevice mGBDevice = null; private GBDevice mGBDevice = null;
private WebView myWebView;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -46,27 +50,15 @@ public class ExternalPebbleJSActivity extends GBActivity {
Bundle extras = getIntent().getExtras(); Bundle extras = getIntent().getExtras();
if (extras != null) { if (extras != null) {
mGBDevice = extras.getParcelable(GBDevice.EXTRA_DEVICE); mGBDevice = extras.getParcelable(GBDevice.EXTRA_DEVICE);
appUuid = (UUID) extras.getSerializable(DeviceService.EXTRA_APP_UUID);
} else { } else {
throw new IllegalArgumentException("Must provide a device when invoking this activity"); throw new IllegalArgumentException("Must provide a device when invoking this activity");
} }
String queryString = "";
Uri uri = getIntent().getData();
if (uri != null) {
//getting back with configuration data
try {
appUuid = UUID.fromString(uri.getHost());
queryString = uri.getEncodedQuery();
} catch (IllegalArgumentException e) {
Log.d("returned uri: ", uri.toString());
}
} else {
appUuid = (UUID) getIntent().getSerializableExtra("app_uuid");
}
setContentView(R.layout.activity_external_pebble_js); setContentView(R.layout.activity_external_pebble_js);
WebView myWebView = (WebView) findViewById(R.id.configureWebview); myWebView = (WebView) findViewById(R.id.configureWebview);
myWebView.clearCache(true); myWebView.clearCache(true);
myWebView.setWebViewClient(new GBWebClient()); myWebView.setWebViewClient(new GBWebClient());
myWebView.setWebChromeClient(new GBChromeClient()); myWebView.setWebChromeClient(new GBChromeClient());
@ -75,10 +67,36 @@ public class ExternalPebbleJSActivity extends GBActivity {
//needed to access the DOM //needed to access the DOM
webSettings.setDomStorageEnabled(true); webSettings.setDomStorageEnabled(true);
JSInterface gbJSInterface = new JSInterface(); JSInterface gbJSInterface = new JSInterface(this);
myWebView.addJavascriptInterface(gbJSInterface, "GBjs"); myWebView.addJavascriptInterface(gbJSInterface, "GBjs");
myWebView.loadUrl("file:///android_asset/app_config/configure.html?" + queryString); myWebView.loadUrl("file:///android_asset/app_config/configure.html");
}
@Override
protected void onNewIntent(Intent incoming) {
incoming.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
super.onNewIntent(incoming);
confUri = incoming.getData();
}
@Override
protected void onResume() {
super.onResume();
String queryString = "";
if (confUri != null) {
//getting back with configuration data
try {
appUuid = UUID.fromString(confUri.getHost());
queryString = confUri.getEncodedQuery();
} catch (IllegalArgumentException e) {
GB.toast("returned uri: " + confUri.toString(), Toast.LENGTH_LONG, GB.ERROR);
}
myWebView.loadUrl("file:///android_asset/app_config/configure.html?" + queryString);
}
} }
private JSONObject getAppConfigurationKeys() { private JSONObject getAppConfigurationKeys() {
@ -112,8 +130,8 @@ public class ExternalPebbleJSActivity extends GBActivity {
@Override @Override
public boolean shouldOverrideUrlLoading(WebView view, String url) { public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith("http://") || url.startsWith("https://")) { if (url.startsWith("http://") || url.startsWith("https://")) {
Intent i = new Intent(Intent.ACTION_VIEW, Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
Uri.parse(url)); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i); startActivity(i);
} else { } else {
url = url.replaceFirst("^pebblejs://close#", "file:///android_asset/app_config/configure.html?config=true&json="); url = url.replaceFirst("^pebblejs://close#", "file:///android_asset/app_config/configure.html?config=true&json=");
@ -127,7 +145,10 @@ public class ExternalPebbleJSActivity extends GBActivity {
private class JSInterface { private class JSInterface {
public JSInterface() { Context mContext;
public JSInterface(Context c) {
mContext = c;
} }
@JavascriptInterface @JavascriptInterface
@ -222,6 +243,11 @@ public class ExternalPebbleJSActivity extends GBActivity {
//specification says: A string that is is guaranteed to be identical for each Pebble device for the same app across different mobile devices. The token is unique to your app and cannot be used to track Pebble devices across applications. see https://developer.pebble.com/docs/js/Pebble/ //specification says: A string that is is guaranteed to be identical for each Pebble device for the same app across different mobile devices. The token is unique to your app and cannot be used to track Pebble devices across applications. see https://developer.pebble.com/docs/js/Pebble/
return "gb" + appUuid.toString(); return "gb" + appUuid.toString();
} }
@JavascriptInterface
public void closeActivity() {
NavUtils.navigateUpFromSameTask((ExternalPebbleJSActivity) mContext);
}
} }
@Override @Override

View File

@ -1,5 +1,12 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<changelog> <changelog>
<release
version="0.10.2"
versioncode="55">
<change>Pebble: allow to manually paste configuration data for legacy configuration pages
</change>
<change>Pebble: various improvements to the configuration page</change>
</release>
<release version="0.10.1" versioncode="54"> <release version="0.10.1" versioncode="54">
<change>Pebble: set extended music info by dissecting notifications on Android 5.0+</change> <change>Pebble: set extended music info by dissecting notifications on Android 5.0+</change>
<change>Pebble: various other improvemnts to music playback</change> <change>Pebble: various other improvemnts to music playback</change>