Android Open Source - jpstrack.android Settings Activity






From Project

Back to project page jpstrack.android.

License

The source code is released under:

/* * Copyright (c) 2006-2014 Ian F. Darwin, http://darwinsys.com * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following co...

If you think the Android project jpstrack.android 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 jpstrack.android;
//ww  w. ja v a 2 s.  c o  m
import android.content.Context;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;

/**
 * The Settings or Preferences activity.
 * This will be SOOO cleanable-uppable when Android catches up to Java 8
 * @author Ian Darwin
 */
public class SettingsActivity extends PreferenceActivity {

  static final String DIRECTORY_NAME = "jpstrack";
  
  // Keys MUST agree with keys defined in settings.xml!
  
  static final String OPTION_DIR = "dir";
  static final String OPTION_SEEN_EULA = "accepted_eula";  // NOT IN GUI FOR OBVIOUS REASONS
  static final String OPTION_SEEN_WELCOME = "seen_welcome"; // Ditto
  //static final String OPTION_FORMAT = "format";
  static final String OPTION_OSM_USER = "osm_username";
  //static final String OPTION_OSM_PASS = "osm_password";
  private static String OPTION_ALWAYS_UPLOAD = "osm_alwaysUpload";
  private static String OPTION_USE_SANDBOX = "osm_useSandbox";
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.layout.settings);
  }
  
  /** No set method, it is set by our PreferencesActivity subclass */
  public static String getDirectory(Context context) {
    return PreferenceManager.getDefaultSharedPreferences(context).getString(OPTION_DIR, null);
  }
  
  /** No set method, it is set by our PreferencesActivity subclass */
  public static String getOSMUserName(Context context) {
    return PreferenceManager.getDefaultSharedPreferences(context).getString(OPTION_OSM_USER, null);
  }
  
  /** No set method, it is set by our PreferencesActivity subclass */
  public static boolean isAlwaysUpload(Context context) {
    Getter t = new Getter(context, OPTION_ALWAYS_UPLOAD);
    ThreadUtils.executeAndWait(t);
    return t.getSeen();
  }

  public static void setSeenEula(final Context context, final boolean seenValue) {
    ThreadUtils.execute(new Setter(context, OPTION_SEEN_EULA, seenValue));
  }
  
  public static boolean hasSeenEula(final Context context) {    
    Getter t = new Getter(context, OPTION_SEEN_EULA);
    ThreadUtils.executeAndWait(t);
    return t.getSeen();
  }
  
  public static void setSeenWelcome(final Context context, final boolean seenValue) {
    ThreadUtils.execute(new Setter(context, OPTION_SEEN_WELCOME, seenValue));
  }
  
  public static boolean hasSeenWelcome(final Context context) {    
    Getter t = new Getter(context, OPTION_SEEN_WELCOME);
    ThreadUtils.executeAndWait(t);
    return t.getSeen();
  }
  
  public static boolean useSandbox(final Context context) {    
    Getter t = new Getter(context, OPTION_USE_SANDBOX);
    ThreadUtils.executeAndWait(t);
    return t.getSeen();
  }
  
  /** Q&D way to do gets on a background thread. */
  private static class Getter extends Thread {
    public Getter(Context context, String optionName) {
      super();
      this.context = context;
      this.optionName = optionName;
    }
    Context context;
    String optionName;
    boolean seen;
    
    @Override
    public void run() {
      seen = PreferenceManager.getDefaultSharedPreferences(context).
          getBoolean(optionName, false);
    }
    public boolean getSeen() {
      return seen;
    }
  }
  
  /** Q&D way to do sets on a background thread. */
  private static class Setter extends Thread {
    public Setter(Context context, String optionName, boolean seenValue) {
      super();
      this.context = context;
      this.optionName = optionName;
      this.seenValue = seenValue;
    }
    Context context;
    String optionName;
    boolean seenValue;
    @Override
    public void run() {
      PreferenceManager.getDefaultSharedPreferences(context).
      edit().putBoolean(optionName, seenValue).commit();
    }
  }


  


}




Java Source Code List

jpstrack.android.ActionBarActivity.java
jpstrack.android.ActionBarHelperBase.java
jpstrack.android.ActionBarHelperHoneycomb.java
jpstrack.android.ActionBarHelperICS.java
jpstrack.android.ActionBarHelper.java
jpstrack.android.AndroidApplication.java
jpstrack.android.ButtonSnazzler.java
jpstrack.android.MainActivity.java
jpstrack.android.OnboardingActivity.java
jpstrack.android.SettingsActivity.java
jpstrack.android.ShowWelcomePage.java
jpstrack.android.SimpleMenuItem.java
jpstrack.android.SimpleMenu.java
jpstrack.android.TextNoteActivity.java
jpstrack.android.ThreadUtils.java
jpstrack.android.TrackerName.java
jpstrack.android.VoiceNoteActivity.java