diff options
Diffstat (limited to 'app/src/main')
7 files changed, 55 insertions, 193 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 56d076441..6be5bd1b3 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -97,15 +97,6 @@ android:launchMode="singleInstance"/> <activity - android:name=".activity.PreferenceActivityGingerbread" - android:configChanges="keyboardHidden|orientation|screenSize" - android:label="@string/settings_label"> - <meta-data - android:name="android.support.PARENT_ACTIVITY" - android:value="de.danoeh.antennapod.activity.MainActivity"/> - </activity> - - <activity android:name=".activity.PreferenceActivity" android:configChanges="keyboardHidden|orientation|screenSize" android:label="@string/settings_label"> diff --git a/app/src/main/java/de/danoeh/antennapod/activity/FlattrAuthActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/FlattrAuthActivity.java index be1c9f9e6..d9c250b38 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/FlattrAuthActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/FlattrAuthActivity.java @@ -18,7 +18,6 @@ import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.util.flattr.FlattrUtils; -import de.danoeh.antennapod.preferences.PreferenceController; /** Guides the user through the authentication process */ @@ -104,7 +103,7 @@ public class FlattrAuthActivity extends ActionBarActivity { switch (item.getItemId()) { case android.R.id.home: if (authSuccessful) { - Intent intent = new Intent(this, PreferenceController.getPreferenceActivity()); + Intent intent = new Intent(this, PreferenceActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } else { diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java index f0fcdca90..9949c01a0 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java @@ -64,7 +64,6 @@ import de.danoeh.antennapod.fragment.PlaybackHistoryFragment; import de.danoeh.antennapod.fragment.QueueFragment; import de.danoeh.antennapod.fragment.SubscriptionFragment; import de.danoeh.antennapod.menuhandler.NavDrawerActivity; -import de.danoeh.antennapod.preferences.PreferenceController; import de.greenrobot.event.EventBus; import rx.Observable; import rx.Subscription; @@ -173,7 +172,7 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi findViewById(R.id.nav_settings).setOnClickListener(v -> { drawerLayout.closeDrawer(navDrawer); - startActivity(new Intent(MainActivity.this, PreferenceController.getPreferenceActivity())); + startActivity(new Intent(MainActivity.this, PreferenceActivity.class)); }); FragmentTransaction transaction = fm.beginTransaction(); diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerInfoActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerInfoActivity.java index cc7d83e0c..3b1427f1b 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerInfoActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerInfoActivity.java @@ -61,7 +61,6 @@ import de.danoeh.antennapod.fragment.PlaybackHistoryFragment; import de.danoeh.antennapod.fragment.QueueFragment; import de.danoeh.antennapod.fragment.SubscriptionFragment; import de.danoeh.antennapod.menuhandler.NavDrawerActivity; -import de.danoeh.antennapod.preferences.PreferenceController; import de.greenrobot.event.EventBus; import rx.Observable; import rx.Subscription; @@ -270,7 +269,7 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem findViewById(R.id.nav_settings).setOnClickListener(v -> { drawerLayout.closeDrawer(navDrawer); - startActivity(new Intent(MediaplayerInfoActivity.this, PreferenceController.getPreferenceActivity())); + startActivity(new Intent(MediaplayerInfoActivity.this, PreferenceActivity.class)); }); butPlaybackSpeed = (Button) findViewById(R.id.butPlaybackSpeed); diff --git a/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivity.java index dd932814f..12d918a76 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivity.java @@ -1,9 +1,7 @@ package de.danoeh.antennapod.activity; -import android.annotation.TargetApi; import android.app.Activity; import android.content.Intent; -import android.os.Build; import android.os.Bundle; import android.preference.Preference; import android.preference.PreferenceFragment; @@ -30,7 +28,6 @@ public class PreferenceActivity extends AppCompatActivity { private PreferenceController preferenceController; private MainFragment prefFragment; private final PreferenceController.PreferenceUI preferenceUI = new PreferenceController.PreferenceUI() { - @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override public Preference findPreference(CharSequence key) { return prefFragment.findPreference(key); @@ -42,7 +39,6 @@ public class PreferenceActivity extends AppCompatActivity { } }; - @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override protected void onCreate(Bundle savedInstanceState) { // This must be the FIRST thing we do, otherwise other code may not have the @@ -95,7 +91,6 @@ public class PreferenceActivity extends AppCompatActivity { } } - @TargetApi(Build.VERSION_CODES.HONEYCOMB) public static class MainFragment extends PreferenceFragment { @Override diff --git a/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivityGingerbread.java b/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivityGingerbread.java deleted file mode 100644 index 390bec15c..000000000 --- a/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivityGingerbread.java +++ /dev/null @@ -1,97 +0,0 @@ -package de.danoeh.antennapod.activity; - -import android.annotation.SuppressLint; -import android.app.Activity; -import android.content.Intent; -import android.content.res.Resources.Theme; -import android.os.Bundle; -import android.preference.Preference; -import android.preference.PreferenceScreen; - -import de.danoeh.antennapod.R; -import de.danoeh.antennapod.core.preferences.UserPreferences; -import de.danoeh.antennapod.preferences.PreferenceController; - -/** - * PreferenceActivity for API 10. In order to change the behavior of the preference UI, see - * PreferenceController. - */ -public class PreferenceActivityGingerbread extends android.preference.PreferenceActivity { - private static final String TAG = "PreferenceActivity"; - private final PreferenceController.PreferenceUI preferenceUI = new PreferenceController.PreferenceUI() { - - @SuppressWarnings("deprecation") - @Override - public Preference findPreference(CharSequence key) { - return PreferenceActivityGingerbread.this.findPreference(key); - } - - @Override - public Activity getActivity() { - return PreferenceActivityGingerbread.this; - } - }; - private PreferenceController preferenceController; - - @SuppressLint("NewApi") - @SuppressWarnings("deprecation") - @Override - public void onCreate(Bundle savedInstanceState) { - setTheme(UserPreferences.getTheme()); - super.onCreate(savedInstanceState); - - addPreferencesFromResource(R.xml.preferences); - preferenceController = new PreferenceController(preferenceUI); - preferenceController.onCreate(); - } - - - @Override - protected void onResume() { - super.onResume(); - preferenceController.onResume(); - } - - @Override - protected void onPause() { - preferenceController.onPause(); - super.onPause(); - } - - @Override - protected void onStop() { - preferenceController.onStop(); - super.onStop(); - } - - @Override - protected void onApplyThemeResource(Theme theme, int resid, boolean first) { - theme.applyStyle(UserPreferences.getTheme(), true); - } - - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - preferenceController.onActivityResult(requestCode, resultCode, data); - } - - @SuppressWarnings("deprecation") - @Override - public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, - Preference preference) { - super.onPreferenceTreeClick(preferenceScreen, preference); - if (preference != null) - if (preference instanceof PreferenceScreen) - if (((PreferenceScreen) preference).getDialog() != null) - ((PreferenceScreen) preference) - .getDialog() - .getWindow() - .getDecorView() - .setBackgroundDrawable( - this.getWindow().getDecorView() - .getBackground().getConstantState() - .newDrawable() - ); - return false; - } -} diff --git a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java index 3b5a68f7f..58c7f39a1 100644 --- a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java +++ b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java @@ -56,8 +56,6 @@ import de.danoeh.antennapod.activity.AboutActivity; import de.danoeh.antennapod.activity.DirectoryChooserActivity; import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.activity.MediaplayerActivity; -import de.danoeh.antennapod.activity.PreferenceActivity; -import de.danoeh.antennapod.activity.PreferenceActivityGingerbread; import de.danoeh.antennapod.activity.StatisticsActivity; import de.danoeh.antennapod.asynctask.ExportWorker; import de.danoeh.antennapod.core.export.ExportWriter; @@ -97,8 +95,8 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc private static final String PREF_CHOOSE_DATA_DIR = "prefChooseDataDir"; private static final String AUTO_DL_PREF_SCREEN = "prefAutoDownloadSettings"; private static final String PREF_PLAYBACK_SPEED_LAUNCHER = "prefPlaybackSpeedLauncher"; - public static final String PREF_PLAYBACK_REWIND_DELTA_LAUNCHER = "prefPlaybackRewindDeltaLauncher"; - public static final String PREF_PLAYBACK_FAST_FORWARD_DELTA_LAUNCHER = "prefPlaybackFastForwardDeltaLauncher"; + private static final String PREF_PLAYBACK_REWIND_DELTA_LAUNCHER = "prefPlaybackRewindDeltaLauncher"; + private static final String PREF_PLAYBACK_FAST_FORWARD_DELTA_LAUNCHER = "prefPlaybackFastForwardDeltaLauncher"; private static final String PREF_GPODNET_LOGIN = "pref_gpodnet_authenticate"; private static final String PREF_GPODNET_SETLOGIN_INFORMATION = "pref_gpodnet_setlogin_information"; private static final String PREF_GPODNET_SYNC = "pref_gpodnet_sync"; @@ -132,19 +130,6 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc .registerOnSharedPreferenceChangeListener(this); } - /** - * Returns the preference activity that should be used on this device. - * - * @return PreferenceActivity if the API level is greater than 10, PreferenceActivityGingerbread otherwise. - */ - public static Class<? extends Activity> getPreferenceActivity() { - if (Build.VERSION.SDK_INT > 10) { - return PreferenceActivity.class; - } else { - return PreferenceActivityGingerbread.class; - } - } - @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if(key.equals(UserPreferences.PREF_SONIC)) { @@ -230,12 +215,8 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc .setOnPreferenceChangeListener( (preference, newValue) -> { Intent i = new Intent(activity, MainActivity.class); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { - i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK - | Intent.FLAG_ACTIVITY_NEW_TASK); - } else { - i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - } + i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK + | Intent.FLAG_ACTIVITY_NEW_TASK); activity.finish(); activity.startActivity(i); return true; @@ -513,7 +494,7 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc alert.setTitle(R.string.export_error_label); alert.setMessage(error.getMessage()); alert.show(); - }, () -> progressDialog.dismiss()); + }, progressDialog::dismiss); return true; } @@ -786,61 +767,56 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc WifiManager wifiservice = (WifiManager) activity.getApplicationContext().getSystemService(Context.WIFI_SERVICE); List<WifiConfiguration> networks = wifiservice.getConfiguredNetworks(); - if (networks != null) { - Collections.sort(networks, new Comparator<WifiConfiguration>() { - @Override - public int compare(WifiConfiguration x, WifiConfiguration y) { - return x.SSID.compareTo(y.SSID); + if (networks == null) { + Log.e(TAG, "Couldn't get list of configure Wi-Fi networks"); + return; + } + Collections.sort(networks, (x, y) -> x.SSID.compareTo(y.SSID)); + selectedNetworks = new CheckBoxPreference[networks.size()]; + List<String> prefValues = Arrays.asList(UserPreferences + .getAutodownloadSelectedNetworks()); + PreferenceScreen prefScreen = (PreferenceScreen) ui.findPreference(PreferenceController.AUTO_DL_PREF_SCREEN); + Preference.OnPreferenceClickListener clickListener = preference -> { + if (preference instanceof CheckBoxPreference) { + String key = preference.getKey(); + List<String> prefValuesList = new ArrayList<>( + Arrays.asList(UserPreferences + .getAutodownloadSelectedNetworks()) + ); + boolean newValue = ((CheckBoxPreference) preference) + .isChecked(); + Log.d(TAG, "Selected network " + key + ". New state: " + newValue); + + int index = prefValuesList.indexOf(key); + if (index >= 0 && !newValue) { + // remove network + prefValuesList.remove(index); + } else if (index < 0 && newValue) { + prefValuesList.add(key); } - }); - selectedNetworks = new CheckBoxPreference[networks.size()]; - List<String> prefValues = Arrays.asList(UserPreferences - .getAutodownloadSelectedNetworks()); - PreferenceScreen prefScreen = (PreferenceScreen) ui.findPreference(PreferenceController.AUTO_DL_PREF_SCREEN); - Preference.OnPreferenceClickListener clickListener = preference -> { - if (preference instanceof CheckBoxPreference) { - String key = preference.getKey(); - List<String> prefValuesList = new ArrayList<>( - Arrays.asList(UserPreferences - .getAutodownloadSelectedNetworks()) - ); - boolean newValue = ((CheckBoxPreference) preference) - .isChecked(); - Log.d(TAG, "Selected network " + key + ". New state: " + newValue); - - int index = prefValuesList.indexOf(key); - if (index >= 0 && !newValue) { - // remove network - prefValuesList.remove(index); - } else if (index < 0 && newValue) { - prefValuesList.add(key); - } - UserPreferences.setAutodownloadSelectedNetworks( - prefValuesList.toArray(new String[prefValuesList.size()]) - ); - return true; - } else { - return false; - } - }; - // create preference for each known network. attach listener and set - // value - for (int i = 0; i < networks.size(); i++) { - WifiConfiguration config = networks.get(i); - - CheckBoxPreference pref = new CheckBoxPreference(activity); - String key = Integer.toString(config.networkId); - pref.setTitle(config.SSID); - pref.setKey(key); - pref.setOnPreferenceClickListener(clickListener); - pref.setPersistent(false); - pref.setChecked(prefValues.contains(key)); - selectedNetworks[i] = pref; - prefScreen.addPreference(pref); + UserPreferences.setAutodownloadSelectedNetworks( + prefValuesList.toArray(new String[prefValuesList.size()]) + ); + return true; + } else { + return false; } - } else { - Log.e(TAG, "Couldn't get list of configure Wi-Fi networks"); + }; + // create preference for each known network. attach listener and set + // value + for (int i = 0; i < networks.size(); i++) { + WifiConfiguration config = networks.get(i); + + CheckBoxPreference pref = new CheckBoxPreference(activity); + String key = Integer.toString(config.networkId); + pref.setTitle(config.SSID); + pref.setKey(key); + pref.setOnPreferenceClickListener(clickListener); + pref.setPersistent(false); + pref.setChecked(prefValues.contains(key)); + selectedNetworks[i] = pref; + prefScreen.addPreference(pref); } } |