Android Open Source - EnklawaPlayer Settings Manager

From Project

Back to project page EnklawaPlayer.


The source code is released under:

GNU General Public License

If you think the Android project EnklawaPlayer listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package macbury.pod.managers;
/*ww  w  .  jav a 2 s . co m*/
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;

import com.koushikdutta.ion.Ion;

import java.util.Date;

import macbury.pod.R;
import macbury.pod.extensions.DateDeserializer;

 * Created by macbury on 09.09.14.
public class SettingsManager {
  public static final String KEY_API_RADIO_URI      = "KEY_API_RADIO_URI";
  public static final String KEY_API_ENDPOINT       = "pref_key_api_endpoint";
  public static final String KEY_SYNC_FREQ          = "pref_key_sync_frequency";
  public static final String KEY_PROXY_ENABLED      = "pref_key_proxy_enabled";
  public static final String KEY_PROXY_HOST         = "pref_key_proxy_host";
  public static final String KEY_PROXY_PORT         = "pref_key_proxy_port";
  public static final String KEY_LAST_UPDATE        = "pref_key_last_update";
  public static final int DEFAULT_SYNC_FREQ         = 360;
  public static final int DEFAULT_PROXY_PORT        = 9050;
  public static final String DEFAULT_PROXY_HOST     = "";

  private final SharedPreferences settings;
  private final Context context;

  public SettingsManager(Context context) {
    this.context = context;
    settings     = PreferenceManager.getDefaultSharedPreferences(context);
    PreferenceManager.setDefaultValues(context, R.xml.settings, false);

  public void update() {

  private void updateION() {
    Gson gson = new GsonBuilder()
            .registerTypeAdapter(Date.class, new DateDeserializer())
    Ion.Config ionConfig = Ion.getDefault(context).configure();
    ionConfig.setLogging("ION", Log.ERROR);
    ionConfig.userAgent("Enklawa Pod");
    if (useProxy()) {
      ionConfig.proxy(getProxyHost(), getProxyPort());
    } else {


  public String getApiEndpoint() {
    return settings.getString(KEY_API_ENDPOINT, App.current().getString(R.string.default_pod_url));

  public long getSyncFreq() {
    return Long.parseLong(settings.getString(KEY_SYNC_FREQ, String.valueOf(AlarmManager.INTERVAL_HOUR)));
  public boolean useProxy() {
    return settings.getBoolean(KEY_PROXY_ENABLED, false);

  public String getProxyHost() {
    return settings.getString(KEY_PROXY_HOST, DEFAULT_PROXY_HOST);

  public int getProxyPort() {
    return Integer.parseInt(settings.getString(KEY_PROXY_PORT, ""));

  public void setRadioURI(String radioURL) {
    settings.edit().putString(KEY_API_RADIO_URI, radioURL).commit();

  public Uri getRadioURI() {
    return Uri.parse(settings.getString(KEY_API_RADIO_URI, null));

Java Source Code List