From eb6831ea1284b15948398dfce80759c64a607b91 Mon Sep 17 00:00:00 2001 From: Eric House Date: Fri, 23 Nov 2018 09:47:18 -0800 Subject: [PATCH] add bt-in-background preference And clear it from a button in the alert that's posted when the foreground service notification is selected. --- .../main/java/org/eehouse/android/xw4/BTService.java | 4 +++- .../main/java/org/eehouse/android/xw4/DlgDelegate.java | 1 + .../org/eehouse/android/xw4/GamesListDelegate.java | 10 ++++++++-- .../src/main/java/org/eehouse/android/xw4/XWPrefs.java | 10 ++++++++++ .../android/app/src/main/res/values/common_rsrc.xml | 1 + xwords4/android/app/src/main/res/values/strings.xml | 5 +++++ xwords4/android/app/src/main/res/xml/xwprefs.xml | 5 +++++ 7 files changed, 33 insertions(+), 3 deletions(-) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java index 8b1f3a9b1..e969812f0 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTService.java @@ -351,7 +351,9 @@ public class BTService extends XWService { Log.d( TAG, "startService(%s)", intent ); if ( ! sInForeground && canRunForegroundService() ) { - context.startForegroundService( intent ); + if ( XWPrefs.getBTBackgroundEnabled( context ) ) { + context.startForegroundService( intent ); + } } else if ( sInForeground || Build.VERSION.SDK_INT < Build.VERSION_CODES.O ) { context.startService( intent ); } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DlgDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DlgDelegate.java index 8b13e3b91..c805f4999 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DlgDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DlgDelegate.java @@ -57,6 +57,7 @@ public class DlgDelegate { SET_HIDE_NEWGAME_BUTTONS, DWNLD_LOC_DICT, NEW_GAME_DFLT_NAME, + DISABLE_BT_BACK, // BoardDelegate UNDO_LAST_ACTION, diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java index 1f14fe7f2..73a6e9395 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java @@ -1360,6 +1360,10 @@ public class GamesListDelegate extends ListDelegateBase true ); break; + case DISABLE_BT_BACK: + XWPrefs.setBTBackgroundEnabled( m_activity, false ); + break; + default: handled = super.onPosButton( action, params ); } @@ -2271,9 +2275,11 @@ public class GamesListDelegate extends ListDelegateBase private void tryBackgroundIntent( Intent intent ) { if ( intent.getBooleanExtra( BACKGROUND_EXTRA, false ) ) { + ActionPair pair = new ActionPair( Action.DISABLE_BT_BACK, + R.string.disable_bt_back ); makeNotAgainBuilder( R.string.not_again_btservice, - R.string.key_notagain_btservice, - Action.OPEN_GAME ) + R.string.key_notagain_btservice ) + .setActionPair( pair ) .show(); } } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWPrefs.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWPrefs.java index 4de7cb416..fafe5208e 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWPrefs.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWPrefs.java @@ -52,6 +52,16 @@ public class XWPrefs { setPrefsBoolean( context, R.string.key_enable_sms, enabled ); } + public static void setBTBackgroundEnabled( Context context, boolean enabled ) + { + setPrefsBoolean( context, R.string.key_btback_enabled, enabled ); + } + + public static boolean getBTBackgroundEnabled( Context context ) + { + return getPrefsBoolean( context, R.string.key_btback_enabled, true ); + } + public static boolean getDebugEnabled( Context context ) { return getPrefsBoolean( context, R.string.key_enable_debug, false ); diff --git a/xwords4/android/app/src/main/res/values/common_rsrc.xml b/xwords4/android/app/src/main/res/values/common_rsrc.xml index 389e79ddb..5d8eef505 100644 --- a/xwords4/android/app/src/main/res/values/common_rsrc.xml +++ b/xwords4/android/app/src/main/res/values/common_rsrc.xml @@ -61,6 +61,7 @@ key_notify_sound key_disable_relay key_notify_vibrate + key_btback_enabled key_enable_sms key_enable_p2p key_network_behavior diff --git a/xwords4/android/app/src/main/res/values/strings.xml b/xwords4/android/app/src/main/res/values/strings.xml index d330d7eda..6ab747561 100644 --- a/xwords4/android/app/src/main/res/values/strings.xml +++ b/xwords4/android/app/src/main/res/values/strings.xml @@ -2026,6 +2026,9 @@ Enable WiFi Direct Experimental, uses lots of battery + Enable background Bluetooth + Always listen for Bluetooth messages + Confirm your SMS plan @@ -2649,6 +2652,8 @@ Bluetooth moves and invitations while in the foreground, but any sent while it\'s in the background will be lost. + Disable Background + This game has sent no invitations Disable side-by-side diff --git a/xwords4/android/app/src/main/res/xml/xwprefs.xml b/xwords4/android/app/src/main/res/xml/xwprefs.xml index 8d6204d6d..fdb679770 100644 --- a/xwords4/android/app/src/main/res/xml/xwprefs.xml +++ b/xwords4/android/app/src/main/res/xml/xwprefs.xml @@ -335,6 +335,11 @@ android:summary="@string/notify_other_summary" android:defaultValue="false" /> +