Android Open Source - EnklawaPlayer Settings Manager






From Project

Back to project page EnklawaPlayer.

License

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.app.AlarmManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.net.Uri;
import android.preference.PreferenceManager;
import android.util.Log;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
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     = "127.0.0.1";


  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() {
    updateION();
    App.current().alarms.setup();
  }

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

    ionConfig.setGson(gson);
  }

  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

macbury.pod.ApplicationTest.java
macbury.pod.activities.DonateActivity.java
macbury.pod.activities.ProgramEpisodesActivity.java
macbury.pod.activities.SettingsActivity.java
macbury.pod.activities.ext.AccentFragmentActivity.java
macbury.pod.activities.main.MainActivityActionBarToggle.java
macbury.pod.activities.main.MainActivity.java
macbury.pod.activities.main.NavigationController.java
macbury.pod.activities.main.NavigationListener.java
macbury.pod.activities.player.PlayerActivity.java
macbury.pod.activities.player.RadioActivity.java
macbury.pod.adapters.EpisodesAdapterListener.java
macbury.pod.adapters.EpisodesAdapter.java
macbury.pod.adapters.ProgramsAdapter.java
macbury.pod.api.APICategory.java
macbury.pod.api.APIEpisode.java
macbury.pod.api.APIProgram.java
macbury.pod.api.APIResponse.java
macbury.pod.api.APIThread.java
macbury.pod.db.DatabaseCRUDListener.java
macbury.pod.db.models.EnqueueEpisode.java
macbury.pod.db.models.EpisodeFile.java
macbury.pod.db.models.Episode.java
macbury.pod.db.models.ForumThread.java
macbury.pod.db.models.Program.java
macbury.pod.db.scopes.AbstractScope.java
macbury.pod.db.scopes.EnqueueEpisodeScope.java
macbury.pod.db.scopes.EpisodeFilesScope.java
macbury.pod.db.scopes.EpisodesScope.java
macbury.pod.db.scopes.ProgramsScope.java
macbury.pod.db.scopes.ThreadScope.java
macbury.pod.dialogs.EpisodeAboutDialog.java
macbury.pod.dialogs.ProgramAboutDialog.java
macbury.pod.extensions.Converter.java
macbury.pod.extensions.DateDeserializer.java
macbury.pod.extensions.SleepTimer.java
macbury.pod.fragments.SettingsFragment.java
macbury.pod.fragments.main.AbstractEpisodesFragment.java
macbury.pod.fragments.main.AllProgramsFragment.java
macbury.pod.fragments.main.EnklawaBaseAbstractListFragment.java
macbury.pod.fragments.main.episodes.DownloadedEpisodesFragment.java
macbury.pod.fragments.main.episodes.NewestEpisodesFragment.java
macbury.pod.fragments.main.episodes.PlaylistFragment.java
macbury.pod.fragments.main.episodes.ProgramEpisodesFragment.java
macbury.pod.fragments.player.ExternalPlayerFragment.java
macbury.pod.fragments.player.PlayerArtworkAndInfoFragment.java
macbury.pod.fragments.player.PlayerControllerFragment.java
macbury.pod.managers.AlarmsManager.java
macbury.pod.managers.App.java
macbury.pod.managers.BroadcastsManager.java
macbury.pod.managers.DatabaseManager.java
macbury.pod.managers.IntentManager.java
macbury.pod.managers.NotificationsManager.java
macbury.pod.managers.ServiceManager.java
macbury.pod.managers.SettingsManager.java
macbury.pod.managers.StorageManager.java
macbury.pod.managers.download.DownloadEpisode.java
macbury.pod.managers.download.DownloadManagerListener.java
macbury.pod.managers.download.DownloadManager.java
macbury.pod.managers.player.PlaybackStatus.java
macbury.pod.managers.player.PlayerManagerListener.java
macbury.pod.managers.player.PlayerManager.java
macbury.pod.managers.player.sources.AbstractMediaSource.java
macbury.pod.managers.player.sources.EpisodeMediaSource.java
macbury.pod.managers.player.sources.RadioMediaSource.java
macbury.pod.navigation_drawer.NavAdapter.java
macbury.pod.navigation_drawer.NavBaseItem.java
macbury.pod.navigation_drawer.NavDivider.java
macbury.pod.navigation_drawer.items.AllProgramsNavItem.java
macbury.pod.navigation_drawer.items.DownloadedEpisodesNavItem.java
macbury.pod.navigation_drawer.items.FavoriteProgramNavItem.java
macbury.pod.navigation_drawer.items.ForumNavItem.java
macbury.pod.navigation_drawer.items.NavItemFragment.java
macbury.pod.navigation_drawer.items.NewestEpisodesNavItem.java
macbury.pod.navigation_drawer.items.PlayQueueNavItem.java
macbury.pod.receivers.BootReceiver.java
macbury.pod.receivers.MediaButtonReceiver.java
macbury.pod.services.DownloadService.java
macbury.pod.services.PlayerService.java
macbury.pod.services.SyncPodService.java
macbury.pod.tutorial.MainActivityTutorial.java
macbury.pod.views.TappableFrameLayout.java