Android Open Source - DragonGoApp Pref Utils






From Project

Back to project page DragonGoApp.

License

The source code is released under:

GNU General Public License

If you think the Android project DragonGoApp 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 fr.xtof54.jsgo;
// w  w  w  .j  av  a 2  s  . c om
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

public class PrefUtils {
  public static final String PREFS_LOGIN_USERNAME_KEY = "__USERNAME__" ;
  public static final String PREFS_LOGIN_PASSWORD_KEY = "__PASSWORD__" ;
  public static final String PREFS_LOGIN_USERNAME2_KEY = "__USERNAME2__" ;
  public static final String PREFS_LOGIN_PASSWORD2_KEY = "__PASSWORD2__" ;

  /**
   * Called to save supplied value in shared preferences against given key.
   * @param context Context of caller activity
   * @param key Key of value to save against
   * @param value Value to save
   */
  public static void saveToPrefs(Context context, String key, String value) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    final SharedPreferences.Editor editor = prefs.edit();
    editor.putString(key,value);
    editor.commit();
  }
  public static void saveToPrefs(Context context, String key, int value) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    final SharedPreferences.Editor editor = prefs.edit();
    editor.putInt(key,value);
    editor.commit();
  }

  /**
   * Called to retrieve required value from shared preferences, identified by given key.
   * Default value will be returned of no value found or error occurred.
   * @param context Context of caller activity
   * @param key Key to find value against
   * @param defaultValue Value to return if no data found against given key
   * @return Return the value found against given key, default if not found or any error occurs
   */
  public static String getFromPrefs(Context context, String key, String defaultValue) {
    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
    try {
      return sharedPrefs.getString(key, defaultValue);
    } catch (Exception e) {
      e.printStackTrace();
      return defaultValue;
    }
  }
  public static int getFromPrefs(Context context, String key, int defaultValue) {
    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
    try {
      return sharedPrefs.getInt(key, defaultValue);
    } catch (Exception e) {
      e.printStackTrace();
      return defaultValue;
    }
  }
}




Java Source Code List

fr.xtof54.jsgo.AndroidServerConnection.java
fr.xtof54.jsgo.EventManager.java
fr.xtof54.jsgo.Forums.java
fr.xtof54.jsgo.GUI.java
fr.xtof54.jsgo.Game.java
fr.xtof54.jsgo.GoJsActivity.java
fr.xtof54.jsgo.Ladder.java
fr.xtof54.jsgo.Message.java
fr.xtof54.jsgo.PrefUtils.java
fr.xtof54.jsgo.Reviews.java
fr.xtof54.jsgo.ServerConnection.java
fr.xtof54.jsgo.WebAppInterface.java
org.json.CDL.java
org.json.CookieList.java
org.json.Cookie.java
org.json.HTTPTokener.java
org.json.HTTP.java
org.json.JSONArray.java
org.json.JSONException.java
org.json.JSONML.java
org.json.JSONObject.java
org.json.JSONString.java
org.json.JSONStringer.java
org.json.JSONTokener.java
org.json.JSONWriter.java
org.json.Kim.java
org.json.Property.java
org.json.XMLTokener.java
org.json.XML.java