From c4317782e413df6c339ebbf7b5b5ce227397563b Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 1 May 2014 21:49:03 +0200 Subject: [PATCH] Added option to auto-enable wifi on start. --- res/layout/dialog_wifi_disabled.xml | 13 ----- res/values/arrays.xml | 8 ++++ res/values/strings.xml | 15 ++++-- res/xml/preferences.xml | 7 +++ .../nutomic/controldlna/gui/MainActivity.java | 47 ++++++++++--------- .../controldlna/gui/PreferencesActivity.java | 32 ++++++++++++- .../controldlna/utility/RouteAdapter.java | 3 +- 7 files changed, 84 insertions(+), 41 deletions(-) delete mode 100644 res/layout/dialog_wifi_disabled.xml create mode 100644 res/values/arrays.xml diff --git a/res/layout/dialog_wifi_disabled.xml b/res/layout/dialog_wifi_disabled.xml deleted file mode 100644 index 8d67d52..0000000 --- a/res/layout/dialog_wifi_disabled.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - diff --git a/res/values/arrays.xml b/res/values/arrays.xml new file mode 100644 index 0000000..47bfef4 --- /dev/null +++ b/res/values/arrays.xml @@ -0,0 +1,8 @@ + + + + yes + no + ask + + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index f5cbf32..ecfdd95 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -27,9 +27,8 @@ Do you really want to exit the renderer? Playback will be stopped. Please select a route - Wifi needs to be connected for playback - "Do not show this dialog again" - Warning + Wifi needs to be connected for playback. + Do you want to enable it now? Album Art @@ -43,6 +42,16 @@ Preferences + + Automatically enable Wifi on start + + + + yes + no + ask + + Pause playback on incoming phone call diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml index cfeb06c..9cf4091 100644 --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@ -1,6 +1,13 @@ + + = Build.VERSION_CODES.HONEYCOMB) { - getActionBar().setDisplayHomeAsUpEnabled(true); + getActionBar().setDisplayHomeAsUpEnabled(true); } + PreferenceManager.getDefaultSharedPreferences(this) + .registerOnSharedPreferenceChangeListener(this); addPreferencesFromResource(R.xml.preferences); final PreferenceScreen screen = getPreferenceScreen(); + mEnableWifiOnStart = (ListPreference) screen.findPreference(KEY_ENABLE_WIFI_ON_START); + mEnableWifiOnStart.setSummary(mEnableWifiOnStart.getEntry()); mContactDev = screen.findPreference(KEY_CONTACT_DEV); } + /** + * Navigates up from activity on ActionBar back click. + */ @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { @@ -72,6 +88,9 @@ public class PreferencesActivity extends PreferenceActivity { } } + /** + * Sends mail intent on contact dev preference click. + */ @Override public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { @@ -83,5 +102,14 @@ public class PreferencesActivity extends PreferenceActivity { } return super.onPreferenceTreeClick(preferenceScreen, preference); } + + /** + * Updates summary of list preference (from current item). + */ + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { + if (key.equals(KEY_ENABLE_WIFI_ON_START)) { + mEnableWifiOnStart.setSummary(mEnableWifiOnStart.getEntry()); + } + } } diff --git a/src/com/github/nutomic/controldlna/utility/RouteAdapter.java b/src/com/github/nutomic/controldlna/utility/RouteAdapter.java index 26125e3..b84cbcd 100644 --- a/src/com/github/nutomic/controldlna/utility/RouteAdapter.java +++ b/src/com/github/nutomic/controldlna/utility/RouteAdapter.java @@ -39,8 +39,9 @@ public class RouteAdapter extends ArrayAdapter { * Replacement for addAll, which is not implemented on lower API levels. */ public void add(List routes) { - for (RouteInfo r : routes) + for (RouteInfo r : routes) { add(r); + } } }