1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-29 05:16:51 +01:00

Make app loader page more reliable, and allow a custom app loader URL to be specified

This commit is contained in:
Gordon Williams 2022-05-23 17:08:10 +01:00
parent 57b53f28be
commit 961cdd437f
5 changed files with 30 additions and 4 deletions

View File

@ -45,6 +45,7 @@ public class DeviceSettingsPreferenceConst {
public static final String PREF_DEVICE_INTENTS = "device_intents"; public static final String PREF_DEVICE_INTENTS = "device_intents";
public static final String PREF_BANGLEJS_TEXT_BITMAP = "banglejs_text_bitmap"; public static final String PREF_BANGLEJS_TEXT_BITMAP = "banglejs_text_bitmap";
public static final String PREF_BANGLEJS_WEBVIEW_URL = "banglejs_webview_url";
public static final String PREF_DISCONNECT_NOTIFICATION = "disconnect_notification"; public static final String PREF_DISCONNECT_NOTIFICATION = "disconnect_notification";
public static final String PREF_DISCONNECT_NOTIFICATION_START = "disconnect_notification_start"; public static final String PREF_DISCONNECT_NOTIFICATION_START = "disconnect_notification_start";

View File

@ -1,5 +1,7 @@
package nodomain.freeyourgadget.gadgetbridge.devices.banglejs; package nodomain.freeyourgadget.gadgetbridge.devices.banglejs;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_DEVICE_INTERNET_ACCESS;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@ -42,6 +44,8 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.banglejs.BangleJSDev
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.QHybridSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.QHybridSupport;
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 nodomain.freeyourgadget.gadgetbridge.util.Prefs;
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_BANGLEJS_WEBVIEW_URL;
public class AppsManagementActivity extends AbstractGBActivity { public class AppsManagementActivity extends AbstractGBActivity {
private static final Logger LOG = LoggerFactory.getLogger(AppsManagementActivity.class); private static final Logger LOG = LoggerFactory.getLogger(AppsManagementActivity.class);
@ -49,6 +53,8 @@ public class AppsManagementActivity extends AbstractGBActivity {
private WebView webView; private WebView webView;
private GBDevice mGBDevice; private GBDevice mGBDevice;
private DeviceCoordinator mCoordinator; private DeviceCoordinator mCoordinator;
/// It seems we can get duplicate broadcasts sometimes - so this helps to avoid that
private int deviceRxSeq = -1;
public AppsManagementActivity() { public AppsManagementActivity() {
} }
@ -88,7 +94,6 @@ public class AppsManagementActivity extends AbstractGBActivity {
commandFilter.addAction(GBDevice.ACTION_DEVICE_CHANGED); commandFilter.addAction(GBDevice.ACTION_DEVICE_CHANGED);
commandFilter.addAction(BangleJSDeviceSupport.BANGLEJS_COMMAND_RX); commandFilter.addAction(BangleJSDeviceSupport.BANGLEJS_COMMAND_RX);
LocalBroadcastManager.getInstance(this).registerReceiver(deviceUpdateReceiver, commandFilter); LocalBroadcastManager.getInstance(this).registerReceiver(deviceUpdateReceiver, commandFilter);
initViews(); initViews();
} }
@ -98,8 +103,14 @@ public class AppsManagementActivity extends AbstractGBActivity {
switch (intent.getAction()) { switch (intent.getAction()) {
case BangleJSDeviceSupport.BANGLEJS_COMMAND_RX: { case BangleJSDeviceSupport.BANGLEJS_COMMAND_RX: {
String data = String.valueOf(intent.getExtras().get("DATA")); String data = String.valueOf(intent.getExtras().get("DATA"));
LOG.info("WebView TX: " + data); int seq = intent.getIntExtra("SEQ",0);
bangleRxData(data); LOG.info("WebView TX: " + data + "("+seq+")");
if (seq==deviceRxSeq) {
LOG.info("WebView TX DUPLICATE AND IGNORED");
} else {
deviceRxSeq = seq;
bangleRxData(data);
}
break; break;
} }
} }
@ -162,7 +173,11 @@ public class AppsManagementActivity extends AbstractGBActivity {
settings.setDatabasePath(databasePath); settings.setDatabasePath(databasePath);
webView.addJavascriptInterface(new WebViewInterface(this), "Android"); webView.addJavascriptInterface(new WebViewInterface(this), "Android");
webView.setWebContentsDebuggingEnabled(true); // FIXME webView.setWebContentsDebuggingEnabled(true); // FIXME
webView.loadUrl("https://banglejs.com/apps/android.html");
Prefs devicePrefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(mGBDevice.getAddress()));
String url = devicePrefs.getString(PREF_BANGLEJS_WEBVIEW_URL, "").trim();
if (url.isEmpty()) url = "https://banglejs.com/apps/android.html";
webView.loadUrl(url);
webView.setWebViewClient(new WebViewClient(){ webView.setWebViewClient(new WebViewClient(){
public void onPageFinished(WebView view, String weburl){ public void onPageFinished(WebView view, String weburl){

View File

@ -119,6 +119,7 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
// Local Intents - for app manager communication // Local Intents - for app manager communication
public static final String BANGLEJS_COMMAND_TX = "banglejs_command_tx"; public static final String BANGLEJS_COMMAND_TX = "banglejs_command_tx";
public static final String BANGLEJS_COMMAND_RX = "banglejs_command_rx"; public static final String BANGLEJS_COMMAND_RX = "banglejs_command_rx";
int bangleCommandSeq = 0; // to attempt to stop duplicate packets
// Global Intents // Global Intents
private static final String BANGLE_ACTION_UART_TX = "com.banglejs.uart.tx"; private static final String BANGLE_ACTION_UART_TX = "com.banglejs.uart.tx";
@ -553,6 +554,7 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
// Send an intent with new data // Send an intent with new data
Intent intent = new Intent(BangleJSDeviceSupport.BANGLEJS_COMMAND_RX); Intent intent = new Intent(BangleJSDeviceSupport.BANGLEJS_COMMAND_RX);
intent.putExtra("DATA", packetStr); intent.putExtra("DATA", packetStr);
intent.putExtra("SEQ", bangleCommandSeq++);
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent); LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
} }
return false; return false;

View File

@ -182,6 +182,8 @@
<string name="pref_summary_transliteration">Enable this if your device has no support for your language\'s font</string> <string name="pref_summary_transliteration">Enable this if your device has no support for your language\'s font</string>
<string name="pref_title_banglejs_text_bitmap">Text as Bitmaps</string> <string name="pref_title_banglejs_text_bitmap">Text as Bitmaps</string>
<string name="pref_summary_banglejs_text_bitmap">If a word cannot be rendered with the watch\'s font, render it to a bitmap in Gadgetbridge and display the bitmap on the watch</string> <string name="pref_summary_banglejs_text_bitmap">If a word cannot be rendered with the watch\'s font, render it to a bitmap in Gadgetbridge and display the bitmap on the watch</string>
<string name="pref_title_banglejs_webview_url">App loader URL</string>
<string name="pref_summary_banglejs_webview_url">If you want a custom app loader put your https://…/android.html URL here. Otherwise leave blank for https://banglejs.com/apps</string>
<string name="pref_title_rtl">Right-To-Left</string> <string name="pref_title_rtl">Right-To-Left</string>
<string name="pref_summary_rtl">Enable this if your device can not show right-to-left languages</string> <string name="pref_summary_rtl">Enable this if your device can not show right-to-left languages</string>
<string name="pref_rtl_max_line_length">Right-To-Left Max Line Length</string> <string name="pref_rtl_max_line_length">Right-To-Left Max Line Length</string>

View File

@ -6,4 +6,10 @@
android:key="banglejs_text_bitmap" android:key="banglejs_text_bitmap"
android:summary="@string/pref_summary_banglejs_text_bitmap" android:summary="@string/pref_summary_banglejs_text_bitmap"
android:title="@string/pref_title_banglejs_text_bitmap" /> android:title="@string/pref_title_banglejs_text_bitmap" />
<EditTextPreference
android:defaultValue=""
android:icon="@drawable/ic_engineering"
android:key="banglejs_webview_url"
android:summary="@string/pref_summary_banglejs_webview_url"
android:title="@string/pref_title_banglejs_webview_url" />
</androidx.preference.PreferenceScreen> </androidx.preference.PreferenceScreen>