Pebble: add option for PebbleKit support (default is disabled)

Also fix an endless loop when number of reconnects is set to 0
live-activity-data
Andreas Shimokawa 2015-09-19 12:49:34 +02:00
parent 8bef384855
commit e1b02e1be4
3 changed files with 25 additions and 12 deletions

View File

@ -61,6 +61,8 @@ public class PebbleIoThread extends GBDeviceIoThread {
private final PebbleProtocol mPebbleProtocol;
private final PebbleSupport mPebbleSupport;
private final boolean mEnablePebblekit;
private boolean mIsTCP = false;
private BluetoothAdapter mBtAdapter = null;
private BluetoothSocket mBtSocket = null;
@ -152,6 +154,7 @@ public class PebbleIoThread extends GBDeviceIoThread {
mPebbleProtocol = (PebbleProtocol) gbDeviceProtocol;
mBtAdapter = btAdapter;
mPebbleSupport = pebbleSupport;
mEnablePebblekit = sharedPrefs.getBoolean("pebble_enable_pebblekit", false);
}
@ -346,7 +349,7 @@ public class PebbleIoThread extends GBDeviceIoThread {
LOG.info(e.getMessage());
gbDevice.setState(GBDevice.State.CONNECTING);
gbDevice.sendDeviceUpdateIntent(getContext());
mIsConnected = false;
int reconnectAttempts = Integer.valueOf(sharedPrefs.getString("pebble_reconnect_attempts", "10"));
while (reconnectAttempts-- > 0 && !mQuit) {
LOG.info("Trying to reconnect (attempts left " + reconnectAttempts + ")");
@ -377,9 +380,8 @@ public class PebbleIoThread extends GBDeviceIoThread {
}
private void enablePebbleKitReceiver(boolean enable) {
boolean force_untested = sharedPrefs.getBoolean("pebble_force_untested", false);
if (enable && force_untested) {
if (enable && mEnablePebblekit) {
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(PEBBLEKIT_ACTION_APP_ACK);
intentFilter.addAction(PEBBLEKIT_ACTION_APP_NACK);
@ -507,7 +509,7 @@ public class PebbleIoThread extends GBDeviceIoThread {
setInstallSlot(appInfoEvent.freeSlot);
return false;
} else if (deviceEvent instanceof GBDeviceEventAppMessage) {
if (sharedPrefs.getBoolean("pebble_force_untested", false)) {
if (mEnablePebblekit) {
LOG.info("Got AppMessage event");
sendAppMessageIntent((GBDeviceEventAppMessage) deviceEvent);
}

View File

@ -33,7 +33,7 @@
<string name="pref_header_general">General Settings</string>
<string name="pref_title_general_autoconnectonbluetooth">Connect to device when Bluetooth turned on</string>
<string name="pref_title_audo_player">Preferred audio player</string>
<string name="pref_title_audo_player">Preferred Audioplayer</string>
<string name="pref_default">Default</string>
<string name="pref_header_datetime">Date and Time</string>
<string name="pref_title_datetime_syctimeonconnect">Sync time</string>
@ -59,6 +59,8 @@
<string name="pref_title_development_miaddr">Mi Band address</string>
<string name="pref_title_pebble_settings">Pebble Settings</string>
<string name="pref_title_enable_pebblekit">Allow 3rd Party Android App Access</string>
<string name="pref_summary_enable_pebblekit">Enable experimental support for Android Apps using PebbleKit</string>
<string name="pref_title_pebble_forceprotocol">Force Notification Protocol</string>
<string name="pref_summary_pebble_forceprotocol">This option forces using the latest notification protocol depending on the firmware version. ENABLE ONLY IF YOU KNOW WHAT YOU ARE DOING!</string>
<string name="pref_title_pebble_forceuntested">Enable untested features</string>

View File

@ -9,7 +9,7 @@
android:title="@string/pref_title_general_autoconnectonbluetooth" />
<ListPreference
android:defaultValue="default"
android:key="audio_player"
android:key="audio_player"
android:title="@string/pref_title_audo_player" />
</PreferenceCategory>
<PreferenceCategory
@ -71,6 +71,21 @@
android:icon="@drawable/ic_device_pebble"
android:key="pref_key_pebble"
android:title="@string/pref_title_pebble_settings">
<PreferenceCategory
android:key="pref_key_general"
android:title="@string/pref_header_general">
<CheckBoxPreference
android:defaultValue="false"
android:key="pebble_enable_pebblekit"
android:summary="@string/pref_summary_enable_pebblekit"
android:title="@string/pref_title_enable_pebblekit" />
<EditTextPreference
android:defaultValue="12"
android:inputType="number"
android:key="pebble_reconnect_attempts"
android:maxLength="4"
android:title="@string/pref_title_pebble_reconnect_attempts" />
</PreferenceCategory>
<PreferenceCategory
android:key="pref_key_development"
android:title="@string/pref_header_development">
@ -84,12 +99,6 @@
android:key="pebble_force_untested"
android:summary="@string/pref_summary_pebble_forceuntested"
android:title="@string/pref_title_pebble_forceuntested" />
<EditTextPreference
android:inputType="number"
android:key="pebble_reconnect_attempts"
android:defaultValue="12"
android:maxLength="4"
android:title="@string/pref_title_pebble_reconnect_attempts" />
<EditTextPreference
android:digits="0123456789."
android:key="pebble_emu_addr"