Use a cached SharedPreferences instance
Reduces allocations a bit
This commit is contained in:
parent
221e3857f3
commit
6da2526648
@ -27,7 +27,6 @@ import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
@ -75,7 +74,7 @@ public class FullPlaybackActivity extends PlaybackActivity implements SeekBar.On
|
||||
{
|
||||
super.onCreate(icicle);
|
||||
|
||||
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
SharedPreferences settings = PlaybackService.getSettings(this);
|
||||
int displayMode = Integer.parseInt(settings.getString("display_mode", "0"));
|
||||
boolean hiddenControls = settings.getBoolean("hidden_controls", false);
|
||||
|
||||
@ -369,7 +368,7 @@ public class FullPlaybackActivity extends PlaybackActivity implements SeekBar.On
|
||||
{
|
||||
switch (message.what) {
|
||||
case MSG_SAVE_CONTROLS: {
|
||||
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
SharedPreferences settings = PlaybackService.getSettings(this);
|
||||
SharedPreferences.Editor editor = settings.edit();
|
||||
editor.putBoolean("hidden_controls", message.arg1 == 1);
|
||||
editor.commit();
|
||||
|
@ -26,7 +26,6 @@ import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
/**
|
||||
* Very simple activity that simply launches the appropriate Activity based on
|
||||
@ -42,7 +41,7 @@ public class LaunchActivity extends Activity {
|
||||
{
|
||||
super.onCreate(state);
|
||||
|
||||
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
SharedPreferences settings = PlaybackService.getSettings(this);
|
||||
boolean selector = settings.getBoolean("selector_on_startup", false);
|
||||
startActivity(new Intent(this, selector ? LibraryActivity.class : FullPlaybackActivity.class));
|
||||
finish();
|
||||
|
@ -34,7 +34,6 @@ import android.graphics.drawable.PaintDrawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.provider.MediaStore;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
@ -113,7 +112,7 @@ public class LibraryActivity extends PlaybackActivity implements AdapterView.OnI
|
||||
|
||||
MediaView.init(this);
|
||||
|
||||
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
SharedPreferences settings = PlaybackService.getSettings(this);
|
||||
if (settings.getBoolean("controls_in_selector", false)) {
|
||||
setContentView(R.layout.library_withcontrols);
|
||||
|
||||
@ -185,7 +184,7 @@ public class LibraryActivity extends PlaybackActivity implements AdapterView.OnI
|
||||
{
|
||||
super.onStart();
|
||||
|
||||
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
SharedPreferences settings = PlaybackService.getSettings(this);
|
||||
mDefaultAction = Integer.parseInt(settings.getString("default_action_int", "0"));
|
||||
mLastActedId = -2;
|
||||
updateHeaders();
|
||||
|
@ -31,7 +31,6 @@ import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.media.AudioManager;
|
||||
import android.os.SystemClock;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
@ -127,7 +126,7 @@ public class MediaButtonHandler {
|
||||
public static boolean useHeadsetControls(Context context)
|
||||
{
|
||||
if (mUseControls == -1) {
|
||||
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
SharedPreferences settings = PlaybackService.getSettings(context);
|
||||
mUseControls = settings.getBoolean("media_button", true) ? 1 : 0;
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,6 @@ import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
/**
|
||||
@ -89,7 +88,7 @@ public class OneCellWidget extends AppWidgetProvider {
|
||||
if (!sEnabled)
|
||||
return;
|
||||
|
||||
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
SharedPreferences settings = PlaybackService.getSettings(context);
|
||||
boolean doubleTap = settings.getBoolean("double_tap", false);
|
||||
|
||||
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.one_cell_widget);
|
||||
|
@ -32,7 +32,6 @@ import android.os.HandlerThread;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.os.SystemClock;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
@ -109,7 +108,7 @@ public class PlaybackActivity extends Activity
|
||||
else
|
||||
startService(new Intent(this, PlaybackService.class));
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
SharedPreferences prefs = PlaybackService.getSettings(this);
|
||||
mUpAction = Integer.parseInt(prefs.getString("swipe_up_action", "0"));
|
||||
mDownAction = Integer.parseInt(prefs.getString("swipe_down_action", "0"));
|
||||
mCoverPressAction = Integer.parseInt(prefs.getString("cover_press_action", "12"));
|
||||
|
@ -157,6 +157,10 @@ public final class PlaybackService extends Service implements Handler.Callback,
|
||||
private static Object sWait = new Object();
|
||||
private static PlaybackService sInstance;
|
||||
private static ArrayList<PlaybackActivity> sActivities = new ArrayList<PlaybackActivity>();
|
||||
/**
|
||||
* Cached app-wide SharedPreferences instance.
|
||||
*/
|
||||
private static SharedPreferences sSettings;
|
||||
|
||||
boolean mHeadsetPause;
|
||||
private boolean mScrobble;
|
||||
@ -175,7 +179,6 @@ public final class PlaybackService extends Service implements Handler.Callback,
|
||||
MediaPlayer mMediaPlayer;
|
||||
private boolean mMediaPlayerInitialized;
|
||||
private PowerManager.WakeLock mWakeLock;
|
||||
private SharedPreferences mSettings;
|
||||
private NotificationManager mNotificationManager;
|
||||
private AudioManager mAudioManager;
|
||||
|
||||
@ -217,7 +220,7 @@ public final class PlaybackService extends Service implements Handler.Callback,
|
||||
mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
|
||||
mAudioManager = (AudioManager)getSystemService(AUDIO_SERVICE);
|
||||
|
||||
SharedPreferences settings = getSettings();
|
||||
SharedPreferences settings = getSettings(this);
|
||||
settings.registerOnSharedPreferenceChangeListener(this);
|
||||
mNotificationMode = Integer.parseInt(settings.getString("notification_mode", "1"));
|
||||
mScrobble = settings.getBoolean("scrobble", false);
|
||||
@ -321,16 +324,16 @@ public final class PlaybackService extends Service implements Handler.Callback,
|
||||
* Return the SharedPreferences instance containing the PlaybackService
|
||||
* settings, creating it if necessary.
|
||||
*/
|
||||
private SharedPreferences getSettings()
|
||||
public static SharedPreferences getSettings(Context context)
|
||||
{
|
||||
if (mSettings == null)
|
||||
mSettings = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
return mSettings;
|
||||
if (sSettings == null)
|
||||
sSettings = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
return sSettings;
|
||||
}
|
||||
|
||||
private void loadPreference(String key)
|
||||
{
|
||||
SharedPreferences settings = getSettings();
|
||||
SharedPreferences settings = getSettings(this);
|
||||
if ("headset_pause".equals(key)) {
|
||||
mHeadsetPause = settings.getBoolean("headset_pause", true);
|
||||
} else if ("remote_player".equals(key)) {
|
||||
@ -854,7 +857,7 @@ public final class PlaybackService extends Service implements Handler.Callback,
|
||||
runQuery(message.arg1, (QueryTask)message.obj);
|
||||
break;
|
||||
case POST_CREATE:
|
||||
mHeadsetPause = mSettings.getBoolean("headset_pause", true);
|
||||
mHeadsetPause = getSettings(this).getBoolean("headset_pause", true);
|
||||
setupReceiver();
|
||||
|
||||
mCallListener = new InCallListener();
|
||||
|
@ -28,7 +28,6 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.TypedArray;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
@ -64,7 +63,7 @@ public class SongNotification extends Notification {
|
||||
*/
|
||||
public SongNotification(Context context, Song song, boolean playing)
|
||||
{
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
SharedPreferences prefs = PlaybackService.getSettings(context);
|
||||
int action = Integer.parseInt(prefs.getString("notification_action", "0"));
|
||||
int statusIcon = playing ? R.drawable.status_icon : R.drawable.status_icon_paused;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user