diff options
author | James Falcon <therealfalcon@gmail.com> | 2013-05-09 16:02:15 -0500 |
---|---|---|
committer | James Falcon <therealfalcon@gmail.com> | 2013-05-09 16:02:15 -0500 |
commit | 916074957ff66b08934cf262197b337c00bdbd67 (patch) | |
tree | abdfd7ae7c09440599f502010219e8940b037928 /src/de/danoeh/antennapod/activity | |
parent | b48c3807fd23df0a6d953ebdabaaf2330bc4f3d3 (diff) | |
download | AntennaPod-916074957ff66b08934cf262197b337c00bdbd67.zip |
Variable speed playback as user preferences and customization of playback speed.
Diffstat (limited to 'src/de/danoeh/antennapod/activity')
-rw-r--r-- | src/de/danoeh/antennapod/activity/AudioplayerActivity.java | 55 | ||||
-rw-r--r-- | src/de/danoeh/antennapod/activity/PreferenceActivity.java | 40 |
2 files changed, 39 insertions, 56 deletions
diff --git a/src/de/danoeh/antennapod/activity/AudioplayerActivity.java b/src/de/danoeh/antennapod/activity/AudioplayerActivity.java index f43f29db3..a84e5b8f2 100644 --- a/src/de/danoeh/antennapod/activity/AudioplayerActivity.java +++ b/src/de/danoeh/antennapod/activity/AudioplayerActivity.java @@ -10,6 +10,7 @@ import android.support.v4.app.FragmentTransaction; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; +import android.view.View.OnLongClickListener; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ImageButton; @@ -24,11 +25,13 @@ import de.danoeh.antennapod.AppConfig; import de.danoeh.antennapod.R; import de.danoeh.antennapod.adapter.ChapterListAdapter; import de.danoeh.antennapod.asynctask.ImageLoader; +import de.danoeh.antennapod.dialog.VariableSpeedDialog; import de.danoeh.antennapod.feed.Chapter; import de.danoeh.antennapod.feed.MediaType; import de.danoeh.antennapod.feed.SimpleChapter; import de.danoeh.antennapod.fragment.CoverFragment; import de.danoeh.antennapod.fragment.ItemDescriptionFragment; +import de.danoeh.antennapod.preferences.UserPreferences; import de.danoeh.antennapod.service.PlaybackService; import de.danoeh.antennapod.util.playback.ExternalMedia; import de.danoeh.antennapod.util.playback.Playable; @@ -400,27 +403,45 @@ public class AudioplayerActivity extends MediaplayerActivity { @Override public void onClick(View v) { - final double PLAYBACK_SPEED_STEP = 0.5; - final double PLAYBACK_SPEED_MAX = 2.0; - final double PLAYBACK_SPEED_DEFAULT = 1.0; - if (controller != null && controller.canSetPlaybackSpeed()) { - double currentPlaybackSpeed = controller - .getCurrentPlaybackSpeedMultiplier(); - if (currentPlaybackSpeed != -1) { - if (currentPlaybackSpeed >= PLAYBACK_SPEED_MAX) { - controller.setPlaybackSpeed(PLAYBACK_SPEED_DEFAULT); - } else { - controller.setPlaybackSpeed(currentPlaybackSpeed - + PLAYBACK_SPEED_STEP); - } + String[] availableSpeeds = UserPreferences + .getPlaybackSpeedArray(); + String currentSpeed = UserPreferences.getPlaybackSpeed(); + + // Provide initial value in case the speed list has changed + // out from under us + // and our current speed isn't in the new list + String newSpeed; + if (availableSpeeds.length > 0) { + newSpeed = availableSpeeds[0]; } else { - controller.setPlaybackSpeed(PLAYBACK_SPEED_DEFAULT); + newSpeed = "1.0"; } + for (int i = 0; i < availableSpeeds.length; i++) { + if (availableSpeeds[i].equals(currentSpeed)) { + if (i == availableSpeeds.length - 1) { + newSpeed = availableSpeeds[0]; + } else { + newSpeed = availableSpeeds[i + 1]; + } + break; + } + } + UserPreferences.setPlaybackSpeed(AudioplayerActivity.this, + newSpeed); + controller.setPlaybackSpeed(Float.parseFloat(newSpeed)); } } }); + + butPlaybackSpeed.setOnLongClickListener(new OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + VariableSpeedDialog.showDialog(AudioplayerActivity.this); + return true; + } + }); } @Override @@ -430,14 +451,12 @@ public class AudioplayerActivity extends MediaplayerActivity { } private void updateButPlaybackSpeed() { - double playbackSpeed; if (controller == null - || (playbackSpeed = controller - .getCurrentPlaybackSpeedMultiplier()) == -1) { + || (controller.getCurrentPlaybackSpeedMultiplier() == -1)) { butPlaybackSpeed.setVisibility(View.GONE); } else { butPlaybackSpeed.setVisibility(View.VISIBLE); - butPlaybackSpeed.setText(String.format("%.1fx", playbackSpeed)); + butPlaybackSpeed.setText(UserPreferences.getPlaybackSpeed()); } } diff --git a/src/de/danoeh/antennapod/activity/PreferenceActivity.java b/src/de/danoeh/antennapod/activity/PreferenceActivity.java index 21998ea73..373fbdf99 100644 --- a/src/de/danoeh/antennapod/activity/PreferenceActivity.java +++ b/src/de/danoeh/antennapod/activity/PreferenceActivity.java @@ -5,9 +5,7 @@ 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; @@ -29,7 +27,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.dialog.VariableSpeedDialog; import de.danoeh.antennapod.feed.FeedManager; import de.danoeh.antennapod.preferences.UserPreferences; import de.danoeh.antennapod.util.flattr.FlattrUtils; @@ -175,7 +173,7 @@ public class PreferenceActivity extends SherlockPreferenceActivity { .setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { - setPlaybackSpeed(); + VariableSpeedDialog.showDialog(PreferenceActivity.this); return true; } }); @@ -264,40 +262,6 @@ 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; |