Reduce default speeds to every .1 instead of every .05 so user doesn't have to do a lot of unchecking. Also, be consistant about where float or double is used and be consistent about which context is used for UserPreferences.

This commit is contained in:
James Falcon 2013-05-13 21:53:44 -05:00
parent ad3e8d8bfe
commit 0a607117d6
4 changed files with 47 additions and 23 deletions

View File

@ -59,7 +59,27 @@
<item>1.85</item>
<item>1.90</item>
<item>1.95</item>
<item>2.0</item>
<item>2.00</item>
<item>2.10</item>
<item>2.20</item>
<item>2.30</item>
<item>2.40</item>
<item>2.50</item>
<item>2.60</item>
<item>2.70</item>
<item>2.80</item>
<item>2.90</item>
<item>3.00</item>
<item>3.10</item>
<item>3.20</item>
<item>3.30</item>
<item>3.40</item>
<item>3.50</item>
<item>3.60</item>
<item>3.70</item>
<item>3.80</item>
<item>3.90</item>
<item>4.00</item>
</string-array>
<string-array name="autodl_select_networks_default_entries">

View File

@ -428,8 +428,7 @@ public class AudioplayerActivity extends MediaplayerActivity {
break;
}
}
UserPreferences.setPlaybackSpeed(AudioplayerActivity.this,
newSpeed);
UserPreferences.setPlaybackSpeed(newSpeed);
controller.setPlaybackSpeed(Float.parseFloat(newSpeed));
}
}

View File

@ -85,8 +85,7 @@ public class VariableSpeedDialog {
}
}
UserPreferences.setPlaybackSpeedArray(context,
newSpeedValues);
UserPreferences.setPlaybackSpeedArray(newSpeedValues);
}
});

View File

@ -2,6 +2,8 @@ package de.danoeh.antennapod.preferences;
import java.io.File;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.apache.commons.lang3.StringUtils;
@ -89,6 +91,7 @@ public class UserPreferences implements
createNoMediaFile();
PreferenceManager.getDefaultSharedPreferences(context)
.registerOnSharedPreferenceChangeListener(instance);
}
private void loadPreferences() {
@ -145,17 +148,25 @@ public class UserPreferences implements
}
private String[] readPlaybackSpeedArray(String valueFromPrefs) {
String[] playbackSpeeds = null;
// If this preference hasn't been set yet, return all options
String[] selectedSpeeds = null;
// If this preference hasn't been set yet, return the default options
if (valueFromPrefs == null) {
playbackSpeeds = context.getResources().getStringArray(
String[] allSpeeds = context.getResources().getStringArray(
R.array.playback_speed_values);
List<String> speedList = new LinkedList<String>();
for (String speedStr : allSpeeds) {
float speed = Float.parseFloat(speedStr);
if (speed < 2.0001 && speed * 10 % 1 == 0) {
speedList.add(speedStr);
}
}
selectedSpeeds = speedList.toArray(new String[speedList.size()]);
} else {
try {
JSONArray jsonArray = new JSONArray(valueFromPrefs);
playbackSpeeds = new String[jsonArray.length()];
selectedSpeeds = new String[jsonArray.length()];
for (int i = 0; i < jsonArray.length(); i++) {
playbackSpeeds[i] = jsonArray.getString(i);
selectedSpeeds[i] = jsonArray.getString(i);
}
} catch (JSONException e) {
Log.e(TAG,
@ -163,7 +174,7 @@ public class UserPreferences implements
e.printStackTrace();
}
}
return playbackSpeeds;
return selectedSpeeds;
}
private static void instanceAvailable() {
@ -299,24 +310,19 @@ public class UserPreferences implements
}
}
public static void setPlaybackSpeed(Context context, String speed) {
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(context.getApplicationContext());
SharedPreferences.Editor editor = prefs.edit();
editor.putString(PREF_PLAYBACK_SPEED, speed);
editor.apply();
public static void setPlaybackSpeed(String speed) {
PreferenceManager.getDefaultSharedPreferences(instance.context).edit()
.putString(PREF_PLAYBACK_SPEED, speed).apply();
}
public static void setPlaybackSpeedArray(Context context, String[] speeds) {
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(context.getApplicationContext());
SharedPreferences.Editor editor = prefs.edit();
public static void setPlaybackSpeedArray(String[] speeds) {
JSONArray jsonArray = new JSONArray();
for (String speed : speeds) {
jsonArray.put(speed);
}
editor.putString(PREF_PLAYBACK_SPEED_ARRAY, jsonArray.toString());
editor.apply();
PreferenceManager.getDefaultSharedPreferences(instance.context).edit()
.putString(PREF_PLAYBACK_SPEED_ARRAY, jsonArray.toString())
.apply();
}
public static void setAutodownloadSelectedNetworks(Context context,