Example usage for android.app Activity getPreferences

List of usage examples for android.app Activity getPreferences

Introduction

In this page you can find the example usage for android.app Activity getPreferences.

Prototype

public SharedPreferences getPreferences(@Context.PreferencesMode int mode) 

Source Link

Document

Retrieve a SharedPreferences object for accessing preferences that are private to this activity.

Usage

From source file:Main.java

public static void setupSharedPrefsMethods(Activity a) {
    prefs = a.getPreferences(Context.MODE_PRIVATE);
}

From source file:Main.java

/**
 * Tests if the json has been cached locally
 *
 * @return True if the file has been cached
 *//*from ww w . j  a  v  a2s.  c om*/
public static boolean wasJsonCached(Activity activity) {
    SharedPreferences sharedPreferences = activity.getPreferences(Context.MODE_PRIVATE);
    return sharedPreferences.contains(SHARED_PREF_CACHED_KEY);
}

From source file:Main.java

/**
 * Saves the name of the cache file in the SharePreferences when cached;
 * used to check later if there is cache
 *///from w  w w  .j av  a  2 s.co  m
public static void markJsonWasCached(Activity activity) {
    SharedPreferences.Editor sharedPrefEditor = activity.getPreferences(Context.MODE_PRIVATE).edit();
    sharedPrefEditor.putString(SHARED_PREF_CACHED_KEY, CACHE_FILENAME);
    sharedPrefEditor.apply();
}

From source file:Main.java

/**
 * Forget the account name and authToken. With no account name the app will
 * prompt the user to select a new account. This method is mostly used for
 * testing purposes./*from www.j  av  a2 s .c  o m*/
 * 
 * @param activity
 */
public static void resetAccountCredential(Activity activity) {
    Log.i(TAG, "Reset credentials");
    SharedPreferences settings = activity.getPreferences(Activity.MODE_PRIVATE);
    SharedPreferences.Editor editor2 = settings.edit();
    editor2.remove(PREF_AUTH_TOKEN);
    editor2.remove(PREF_ACCOUNT_NAME);
    editor2.commit();
}

From source file:me.qisthi.cuit.helper.StorageHelper.java

public static String getPreferenceStringValue(Activity activity, String key) {
    SharedPreferences sharedPreferences = activity.getPreferences(Context.MODE_PRIVATE);
    return sharedPreferences.getString(key, "");
}

From source file:me.qisthi.cuit.helper.StorageHelper.java

public static Long getPreferenceLongValue(Activity activity, String key) {
    SharedPreferences sharedPreferences = activity.getPreferences(Context.MODE_PRIVATE);
    return sharedPreferences.getLong(key, 0);
}

From source file:me.qisthi.cuit.helper.StorageHelper.java

public static void writePreferenceLongValue(Activity activity, String key, Long value) {
    SharedPreferences sharedPreferences = activity.getPreferences(Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putLong(key, value);/*from  w  w  w. j av a2 s  .co  m*/
    editor.apply();
}

From source file:me.qisthi.cuit.helper.StorageHelper.java

public static void writePreferenceStringValue(Activity activity, String key, String value) {
    SharedPreferences sharedPreferences = activity.getPreferences(Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putString(key, value);/*  w w w. j av  a 2 s .  c o m*/
    editor.apply();
}

From source file:me.qisthi.cuit.helper.StorageHelper.java

public static List<String[]> readPreferenceStatusValue(Activity activity, String key) throws Exception {
    SharedPreferences sharedPreferences = activity.getPreferences(Context.MODE_PRIVATE);
    String jsonValue = sharedPreferences.getString(key, null);

    List<String[]> statuses;

    if (jsonValue != null) {
        ObjectMapper mapper = new ObjectMapper();
        statuses = mapper.readValue(jsonValue, new TypeReference<List<String[]>>() {
        });//from   w  ww .jav  a  2  s .  c  om

        return statuses;
    }
    return null;
}

From source file:edu.cmu.cylab.starslinger.demo.MainActivity.java

private static void updateNfcState(Activity act) {
    final SharedPreferences sharedPref = act.getPreferences(Context.MODE_PRIVATE);
    Boolean nfc = getNfcState(act);
    if (nfc == null) { // no system nfc
        toggleButtonUseNfc.setVisibility(View.GONE);
        toggleButtonUseNfc.setEnabled(false);
        toggleButtonUseNfc.setChecked(false);
    } else if (!nfc) { // system nfc is off
        toggleButtonUseNfc.setVisibility(View.VISIBLE);
        toggleButtonUseNfc.setEnabled(false);
        toggleButtonUseNfc.setChecked(false);
    } else { // system nfc is on
        toggleButtonUseNfc.setVisibility(View.VISIBLE);
        toggleButtonUseNfc.setEnabled(true);
        toggleButtonUseNfc.setChecked(sharedPref.getBoolean(PREF_USENFC, false));
    }/*from   w  w w  .j a v a  2s  . c  o  m*/
}