diff options
Diffstat (limited to 'src/de')
4 files changed, 115 insertions, 5 deletions
diff --git a/src/de/danoeh/antennapod/activity/PreferenceActivity.java b/src/de/danoeh/antennapod/activity/PreferenceActivity.java index 9fcf57ac2..21998ea73 100644 --- a/src/de/danoeh/antennapod/activity/PreferenceActivity.java +++ b/src/de/danoeh/antennapod/activity/PreferenceActivity.java @@ -5,7 +5,9 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import android.app.AlertDialog; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.res.Resources.Theme; import android.net.wifi.WifiConfiguration; @@ -27,6 +29,7 @@ import de.danoeh.antennapod.AppConfig; import de.danoeh.antennapod.R; import de.danoeh.antennapod.asynctask.FlattrClickWorker; import de.danoeh.antennapod.asynctask.OpmlExportWorker; +import de.danoeh.antennapod.dialog.GetSpeedPlaybackPlugin; import de.danoeh.antennapod.feed.FeedManager; import de.danoeh.antennapod.preferences.UserPreferences; import de.danoeh.antennapod.util.flattr.FlattrUtils; @@ -42,6 +45,7 @@ public class PreferenceActivity extends SherlockPreferenceActivity { private static final String PREF_ABOUT = "prefAbout"; 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"; private CheckBoxPreference[] selectedNetworks; @@ -167,6 +171,14 @@ public class PreferenceActivity extends SherlockPreferenceActivity { return true; } }); + findPreference(PREF_PLAYBACK_SPEED_LAUNCHER) + .setOnPreferenceClickListener(new OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + setPlaybackSpeed(); + return true; + } + }); buildUpdateIntervalPreference(); buildAutodownloadSelectedNetworsPreference(); setSelectedNetworksEnabled(UserPreferences @@ -252,6 +264,40 @@ public class PreferenceActivity extends SherlockPreferenceActivity { } } + private void setPlaybackSpeed() { + if (com.aocate.media.MediaPlayer + .isPrestoLibraryInstalled(PreferenceActivity.this)) { + int currentIndex = 0; + final String[] speedValues = getResources().getStringArray( + R.array.playback_speed_values); + for (int i = 0; i < speedValues.length; i++) { + // Probably shouldn't float compare here... + if (Float.parseFloat(speedValues[i]) == UserPreferences + .getPlaybackSpeed()) { + currentIndex = i; + } + } + AlertDialog.Builder builder = new AlertDialog.Builder( + PreferenceActivity.this); + builder.setTitle(R.string.set_playback_speed_label); + builder.setSingleChoiceItems(R.array.playback_speed_values, + currentIndex, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + UserPreferences.setPlaybackSpeed( + PreferenceActivity.this, + Float.valueOf(speedValues[which])); + dialog.dismiss(); + + } + }); + builder.create().show(); + + } else { + GetSpeedPlaybackPlugin.showDialog(this); + } + } + @Override public boolean onCreateOptionsMenu(Menu menu) { return true; diff --git a/src/de/danoeh/antennapod/dialog/GetSpeedPlaybackPlugin.java b/src/de/danoeh/antennapod/dialog/GetSpeedPlaybackPlugin.java new file mode 100644 index 000000000..f4aabfdeb --- /dev/null +++ b/src/de/danoeh/antennapod/dialog/GetSpeedPlaybackPlugin.java @@ -0,0 +1,31 @@ +package de.danoeh.antennapod.dialog; + +import android.app.AlertDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.net.Uri; +import de.danoeh.antennapod.R; + +public class GetSpeedPlaybackPlugin { + private GetSpeedPlaybackPlugin() { + } + + public static void showDialog(final Context context) { + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle(R.string.no_playback_plugin_title); + builder.setMessage(R.string.no_playback_plugin_msg); + builder.setNegativeButton(R.string.close_label, null); + builder.setPositiveButton(R.string.download_plugin_label, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + Intent playStoreIntent = new Intent( + Intent.ACTION_VIEW, + Uri.parse("market://details?id=com.falconware.prestissimo")); + context.startActivity(playStoreIntent); + } + }); + builder.create().show(); + } +} diff --git a/src/de/danoeh/antennapod/preferences/UserPreferences.java b/src/de/danoeh/antennapod/preferences/UserPreferences.java index f2f35f41d..0674849db 100644 --- a/src/de/danoeh/antennapod/preferences/UserPreferences.java +++ b/src/de/danoeh/antennapod/preferences/UserPreferences.java @@ -17,6 +17,7 @@ import de.danoeh.antennapod.AppConfig; import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.OpmlImportFromPathActivity; import de.danoeh.antennapod.receiver.FeedUpdateReceiver; +import de.danoeh.antennapod.service.PlaybackService; /** * Provides access to preferences set by the user in the settings screen. A @@ -41,11 +42,12 @@ public class UserPreferences implements public static final String PREF_ENABLE_AUTODL_WIFI_FILTER = "prefEnableAutoDownloadWifiFilter"; private static final String PREF_AUTODL_SELECTED_NETWORKS = "prefAutodownloadSelectedNetworks"; public static final String PREF_EPISODE_CACHE_SIZE = "prefEpisodeCacheSize"; + private static final String PREF_PLAYBACK_SPEED = "prefPlaybackSpeed"; private static int EPISODE_CACHE_SIZE_UNLIMITED = -1; private static UserPreferences instance; - private Context context; + private final Context context; // Preferences private boolean pauseOnHeadsetDisconnect; @@ -60,6 +62,7 @@ public class UserPreferences implements private boolean enableAutodownloadWifiFilter; private String[] autodownloadSelectedNetworks; private int episodeCacheSize; + private float playbackSpeed; private UserPreferences(Context context) { this.context = context; @@ -108,6 +111,7 @@ public class UserPreferences implements episodeCacheSize = readEpisodeCacheSize(sp.getString( PREF_EPISODE_CACHE_SIZE, "20")); enableAutodownload = sp.getBoolean(PREF_ENABLE_AUTODL, false); + playbackSpeed = sp.getFloat(PREF_PLAYBACK_SPEED, (float) 1.0); } private int readThemeValue(String valueFromPrefs) { @@ -196,6 +200,11 @@ public class UserPreferences implements return EPISODE_CACHE_SIZE_UNLIMITED; } + public static float getPlaybackSpeed() { + instanceAvailable(); + return instance.playbackSpeed; + } + /** * Returns the capacity of the episode cache. This method will return the * negative integer EPISODE_CACHE_SIZE_UNLIMITED if the cache size is set to @@ -250,9 +259,23 @@ public class UserPreferences implements PREF_EPISODE_CACHE_SIZE, "20")); } else if (key.equals(PREF_ENABLE_AUTODL)) { enableAutodownload = sp.getBoolean(PREF_ENABLE_AUTODL, false); + } else if (key.equals(PREF_PLAYBACK_SPEED)) { + playbackSpeed = sp.getFloat(PREF_PLAYBACK_SPEED, (float) 1.0); } } + public static void setPlaybackSpeed(Context context, float speed) { + SharedPreferences prefs = PreferenceManager + .getDefaultSharedPreferences(context.getApplicationContext()); + SharedPreferences.Editor editor = prefs.edit(); + editor.putFloat(PREF_PLAYBACK_SPEED, speed); + editor.apply(); + + Intent intent = new Intent(context, PlaybackService.class); + intent.putExtra(PlaybackService.EXTRA_PLAYBACK_SPEED, speed); + context.startService(intent); + } + public static void setAutodownloadSelectedNetworks(Context context, String[] value) { SharedPreferences.Editor editor = PreferenceManager diff --git a/src/de/danoeh/antennapod/service/PlaybackService.java b/src/de/danoeh/antennapod/service/PlaybackService.java index 6c7619476..afd8de68f 100644 --- a/src/de/danoeh/antennapod/service/PlaybackService.java +++ b/src/de/danoeh/antennapod/service/PlaybackService.java @@ -82,6 +82,7 @@ public class PlaybackService extends Service { public static final String ACTION_PLAYER_NOTIFICATION = "action.de.danoeh.antennapod.service.playerNotification"; public static final String EXTRA_NOTIFICATION_CODE = "extra.de.danoeh.antennapod.service.notificationCode"; public static final String EXTRA_NOTIFICATION_TYPE = "extra.de.danoeh.antennapod.service.notificationType"; + public static final String EXTRA_PLAYBACK_SPEED = "extra.de.danoeh.antennapod.service.playbackSpeed"; /** * If the PlaybackService receives this action, it will stop playback and @@ -372,10 +373,17 @@ public class PlaybackService extends Service { if (AppConfig.DEBUG) Log.d(TAG, "OnStartCommand called"); int keycode = intent.getIntExtra(MediaButtonReceiver.EXTRA_KEYCODE, -1); + float playbackSpeed = intent.getFloatExtra(EXTRA_PLAYBACK_SPEED, -1); if (keycode != -1) { if (AppConfig.DEBUG) Log.d(TAG, "Received media button event"); handleKeycode(keycode); + } else if (playbackSpeed > 0) { + if (media == null) { + stopSelf(); + } else { + setSpeed(playbackSpeed); + } } else { Playable playable = intent.getParcelableExtra(EXTRA_PLAYABLE); @@ -422,6 +430,7 @@ public class PlaybackService extends Service { stopSelf(); } } + return Service.START_NOT_STICKY; } @@ -979,6 +988,7 @@ public class PlaybackService extends Service { Log.d(TAG, "Resuming/Starting playback"); writePlaybackPreferences(); + setSpeed(UserPreferences.getPlaybackSpeed()); player.start(); if (status != PlayerStatus.PAUSED) { player.seekTo(media.getPosition()); @@ -1537,11 +1547,11 @@ public class PlaybackService extends Service { return false; } - public void setSpeed(double speed) { + public void setSpeed(float speed) { if (media != null && media.getMediaType() == MediaType.AUDIO) { AudioPlayer audioPlayer = (AudioPlayer) player; if (audioPlayer.canSetSpeed()) { - audioPlayer.setPlaybackSpeed((float) speed); + audioPlayer.setPlaybackSpeed(speed); if (AppConfig.DEBUG) Log.d(TAG, "Playback speed was set to " + speed); sendNotificationBroadcast( @@ -1550,11 +1560,11 @@ public class PlaybackService extends Service { } } - public void setPitch(double pitch) { + public void setPitch(float pitch) { if (media != null && media.getMediaType() == MediaType.AUDIO) { AudioPlayer audioPlayer = (AudioPlayer) player; if (audioPlayer.canSetPitch()) { - audioPlayer.setPlaybackPitch((float) pitch); + audioPlayer.setPlaybackPitch(pitch); } } } |