Example usage for android.content SharedPreferences getLong

List of usage examples for android.content SharedPreferences getLong

Introduction

In this page you can find the example usage for android.content SharedPreferences getLong.

Prototype

long getLong(String key, long defValue);

Source Link

Document

Retrieve a long value from the preferences.

Usage

From source file:com.tlongdev.bktf.util.Utility.java

/**
 * Convenient method for getting double values from shared preferences.
 *
 * @param prefs        shared preferences
 * @param key          preference key//  w w  w  .  j  a  va2  s. co  m
 * @param defaultValue default preference value
 * @return the stored double value
 */
public static double getDouble(final SharedPreferences prefs, final String key, final double defaultValue) {
    return Double.longBitsToDouble(prefs.getLong(key, Double.doubleToLongBits(defaultValue)));
}

From source file:Main.java

public static Object getParam(Context context, String key, Object defaultObject) {
    String type = defaultObject.getClass().getSimpleName();
    SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);

    if ("String".equals(type)) {
        return sp.getString(key, (String) defaultObject);
    } else if ("Integer".equals(type)) {
        return sp.getInt(key, (Integer) defaultObject);
    } else if ("Boolean".equals(type)) {
        return sp.getBoolean(key, (Boolean) defaultObject);
    } else if ("Float".equals(type)) {
        return sp.getFloat(key, (Float) defaultObject);
    } else if ("Long".equals(type)) {
        return sp.getLong(key, (Long) defaultObject);
    }/*w w  w.  ja  v  a  2  s .  c  o  m*/
    return null;
}

From source file:org.ohmage.reminders.notif.NotifSurveyAdaptor.java

private static boolean IsSurveyTakenOrIgnored(Context context, String survey, long since) {

    SharedPreferences pref = context.getSharedPreferences(NotifSurveyAdaptor.class.getName(),
            Context.MODE_PRIVATE);

    return (pref.contains(survey) && pref.getLong(survey, 0) > since)
            || (pref.contains(survey + "_ignored") && pref.getLong(survey + "_ignored", 0) > since);
}

From source file:Main.java

public static Object getSp(Context context, String key, Object defaultObject) {
    String type = defaultObject.getClass().getSimpleName();
    String packageName = context.getPackageName();
    SharedPreferences sp = context.getSharedPreferences(packageName, Context.MODE_PRIVATE);
    if ("String".equals(type)) {
        return sp.getString(key, (String) defaultObject);
    } else if ("Integer".equals(type)) {
        return sp.getInt(key, (Integer) defaultObject);
    } else if ("Boolean".equals(type)) {
        return sp.getBoolean(key, (Boolean) defaultObject);
    } else if ("Float".equals(type)) {
        return sp.getFloat(key, (Float) defaultObject);
    } else if ("Long".equals(type)) {
        return sp.getLong(key, (Long) defaultObject);
    }// w  ww .ja  v  a2  s. c  o  m
    return null;
}

From source file:Main.java

public static <T> T getData(Context context, String fileName, String key, Class T) {
    SharedPreferences sharedPreferences = context.getSharedPreferences(fileName, Context.MODE_PRIVATE);
    T result;//  w w w . j a v  a2 s  . c  o m
    if (String.class.isAssignableFrom(T)) {
        result = (T) sharedPreferences.getString(key, "");
    } else if (Integer.class.isAssignableFrom(T)) {
        result = (T) Integer.valueOf(sharedPreferences.getInt(key, 0));
    } else if (Float.class.isAssignableFrom(T)) {
        result = (T) Float.valueOf(sharedPreferences.getFloat(key, 0));
    } else if (Long.class.isAssignableFrom(T)) {
        result = (T) Long.valueOf(sharedPreferences.getLong(key, 0));
    } else {
        result = (T) Boolean.valueOf(sharedPreferences.getBoolean(key, false));
    }
    return result;
}

From source file:org.ohmage.triggers.notif.NotifSurveyAdaptor.java

private static boolean IsSurveyTaken(Context context, String campaignUrn, String survey, long since) {

    SharedPreferences pref = context
            .getSharedPreferences(NotifSurveyAdaptor.class.getName() + "_" + campaignUrn, Context.MODE_PRIVATE);

    if (!pref.contains(survey)) {
        return false;
    }/*from   ww  w .jav a2  s  .c  o m*/

    if (pref.getLong(survey, 0) <= since) {
        return false;
    }

    return true;
}

From source file:Main.java

public static Object get(Context context, String key, Object defaultObject) {
    SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
    if (defaultObject instanceof String) {
        return sp.getString(key, (String) defaultObject);
    } else if (defaultObject instanceof Integer) {
        return sp.getInt(key, (Integer) defaultObject);
    } else if (defaultObject instanceof Boolean) {
        return sp.getBoolean(key, (Boolean) defaultObject);
    } else if (defaultObject instanceof Float) {
        return sp.getFloat(key, (Float) defaultObject);
    } else if (defaultObject instanceof Long) {
        return sp.getLong(key, (Long) defaultObject);
    }/* w  w w.j a  v  a 2  s .c o m*/
    return null;
}

From source file:Main.java

public static Object get(Context context, String key, Object defaultObject) {
    SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);

    if (defaultObject instanceof String) {
        return sp.getString(key, (String) defaultObject);
    } else if (defaultObject instanceof Integer) {
        return sp.getInt(key, (Integer) defaultObject);
    } else if (defaultObject instanceof Boolean) {
        return sp.getBoolean(key, (Boolean) defaultObject);
    } else if (defaultObject instanceof Float) {
        return sp.getFloat(key, (Float) defaultObject);
    } else if (defaultObject instanceof Long) {
        return sp.getLong(key, (Long) defaultObject);
    }//from  w w  w .  j  a va 2  s.  c o  m

    return null;
}

From source file:com.smarthome.deskclock.Alarms.java

private static void clearSnoozeIfNeeded(Context context, long alarmTime) {
    // If this alarm fires before the next snooze, clear the snooze to
    // enable this alarm.
    SharedPreferences prefs = context.getSharedPreferences(AlarmClock.PREFERENCES, 0);
    long snoozeTime = prefs.getLong(PREF_SNOOZE_TIME, 0);
    if (alarmTime < snoozeTime) {
        clearSnoozePreference(context, prefs);
    }/*from   w  w  w . java2  s.co  m*/
}

From source file:org.alfresco.mobile.android.application.fragments.preferences.PasscodePreferences.java

/**
 * Determines if the application has passcode feature enable
 *
 * @param context/*  w  ww. j av a2  s  . c o  m*/
 * @return true if the passcode must be prompt.
 */
public static boolean hasPasscodeEnable(Context context) {
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
    boolean passcodeActivated = sharedPref.getBoolean(KEY_PASSCODE_ENABLE, false);
    if (!passcodeActivated) {
        return false;
    }

    long activationTime = sharedPref.getLong(KEY_PASSCODE_ACTIVATED_AT, DEFAULT_ACTIVATION_TIME);
    if (activationTime == DEFAULT_ACTIVATION_TIME) {
        return false;
    }

    long durationTime = Long.parseLong(sharedPref.getString(KEY_PASSCODE_TIMEOUT, DEFAULT_TIMEOUT));
    long now = new Date().getTime();

    boolean isTimeOut = (now - activationTime) > durationTime;
    if (!isTimeOut) {
        updateLastActivity(context);
    }

    return isTimeOut;
}