Android Open Source - oidarSample Preference Util






From Project

Back to project page oidarSample.

License

The source code is released under:

GNU General Public License

If you think the Android project oidarSample 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 com.oidar.util;
/*w ww  .  j a va  2 s . c o m*/
import android.content.Context;
import android.preference.PreferenceManager;

/**
 * Utility class for handling preferences.
 */
public class PreferenceUtil {

    public static final String KEY_HAS_SEEN_FIRST_TIME_DIALOG = "key_has_seen_first_time_dialog";
    public static final String KEY_SHOW_WARM_UP = "key_show_warm_up";
    public static final String KEY_WARM_UP_SETS = "key_warm_up_sets";
    public static final String KEY_WARM_UP_REPS = "key_warm_up_reps";
    public static final String KEY_ROUND_TO = "key_round";
    public static final String KEY_CUSTOM_ROUND_TO = "key_custom_round_to";
    public static final String KEY_ROUND_TO_VALUE = "key_round_to_value";
    public static final String KEY_DELOAD_REPS = "key_deload_reps";
    public static final String KEY_USE_VOLUME_BUTTONS = "key_use_volume_button";
    public static final String KEY_KEEP_SCREEN_ON_STOPWATCH = "key_keep_screen_on_stopwatch";
    public static final String KEY_HAS_SEEN_SHOWCASE_WORKOUTS = "key_has_seen_showcase_workouts";
    public static final String KEY_HAS_SEEN_SHOWCASE_FINISH_WORKOUTS =
            "key_has_seen_showcase_workout";
    public static final String KEY_HAS_SEEN_SHOWCASE_OLD_WORKOUTS =
            "key_has_seen_showcase_old_workouts";
    public static final String KEY_VERSION = "key_version";

    public static final String KEY_HAS_PURGED = "key_has_purged";
    public static final String KEY_HAS_CYCLE_NAME = "key_has_updated_cycle_name";
    public static final String KEY_AUTO_DELOAD = "key_auto_deload";
    public static final String KEY_RESET_CYCLE_DELOAD = "key_reset_cycle_deload";
    public static final String KEY_WEIGHT_TYPE_DELOAD = "key_weight_type_deload";
    public static final String KEY_DELOAD_TYPE = "key_deload_type";
    public static final String KEY_CUSTOM_DELOAD_TYPE = "key_custom_deload_type";
    public static final String KEY_CUSTOM_DELOAD_TYPE_VALUE = "key_custom_deload_type_value";
    public static final String KEY_CLEAR_DATA = "key_clear_data";
    public static final String KEY_TIME_OF_LAST_BACKUP = "key_time_of_last_backup";
    public static final String KEY_UPDATE_TO_TM = "key_update_to_tm";

    /**
     * Get a boolean stored in preferences. Default value is false.
     */
    public static boolean getBoolean(Context context, String tag) {
        return getBoolean(context, tag, false);
    }

    /**
     * Get a boolean stored in preferences with a default value provided.
     */
    public static boolean getBoolean(Context context, String tag, boolean defaultValue) {
        boolean bool = PreferenceManager
                .getDefaultSharedPreferences(context).getBoolean(tag, defaultValue);
        MyLog.i("Load value: " + bool + " for " + tag);
        return bool;
    }

    /**
     * Write a boolean value to preferences.
     */
    public static void putBoolean(Context context, String tag, boolean value) {
        MyLog.i("Store " + value + " for " + tag);
        PreferenceManager
                .getDefaultSharedPreferences(context)
                .edit()
                .putBoolean(tag, value)
                .apply();
    }

    /**
     * Get a String stored in preferences with a default value provided.
     */
    public static String getString(Context context, String tag, String defaultValue) {
        String string = PreferenceManager.getDefaultSharedPreferences(context).getString(tag,
                defaultValue);
        MyLog.i("Load value: " + string + " for " + tag);
        return string;
    }

    /**
     * Write a String value to preferences.
     */
    public static void putString(Context context, String tag, String value) {
        MyLog.i("Store " + value + " for " + tag);
        PreferenceManager
                .getDefaultSharedPreferences(context)
                .edit()
                .putString(tag, value)
                .apply();
    }

    /**
     * Get a float stored in preferences with a default value provided
     */
    public static float getFloat(Context context, String tag, float defaultValue) {
        Float value = Float.parseFloat(PreferenceManager
                .getDefaultSharedPreferences(context)
                .getString(tag, String.valueOf(defaultValue)));

        MyLog.i("Load value: " + value + " for " + tag);
        return value;
    }

    public static long getLong(Context context, String tag) {
        return getLong(context, tag, 0);
    }

    public static long getLong(Context context, String tag, long defaultValue) {
        long value = Long.parseLong(PreferenceManager
                .getDefaultSharedPreferences(context)
                .getString(tag, String.valueOf(defaultValue)));
        MyLog.i("Load value: " + value + " for " + tag);
        return value;
    }

    /**
     * Write a float value to preferences.
     */
    public static void putLong(Context context, String tag, long value) {
        MyLog.i("Store " + value + " for " + tag);
        PreferenceManager
                .getDefaultSharedPreferences(context)
                .edit()
                .putString(tag, String.valueOf(value))
                .apply();
    }

    /**
     * Store a float value.
     */
    public static void putFloat(Context context, String tag, float value) {
        MyLog.i("Store " + value + " for " + tag);
        PreferenceManager
                .getDefaultSharedPreferences(context)
                .edit()
                .putString(tag, String.valueOf(value))
                .apply();
    }
}




Java Source Code List

com.oidar.ApplicationTest.java
com.oidar.activity.MainActivity.java
com.oidar.activity.SettingsActivity.java
com.oidar.activity.base.BaseActivity.java
com.oidar.adapter.DrawerAdapter.java
com.oidar.adapter.DrawerLiveNewsAdapter.java
com.oidar.adapter.DrawerTalkRadioAdapter.java
com.oidar.animation.CustomObjectAnimator.java
com.oidar.animation.DepthPageTransformer.java
com.oidar.animation.ZoomOutPageTransformer.java
com.oidar.fragment.AboutFragment.java
com.oidar.fragment.DrawerLiveNewsFragment.java
com.oidar.fragment.DrawerTalkRadioFragment.java
com.oidar.fragment.FeedbackFragment.java
com.oidar.fragment.LiveNewsFragment.java
com.oidar.fragment.SettingsFragment.java
com.oidar.fragment.TalkRadioFragment.java
com.oidar.fragment.base.DrawerFragment.java
com.oidar.fragment.base.RadioFragment.java
com.oidar.model.DrawerListItem.java
com.oidar.model.ListItemType.java
com.oidar.model.Radio.java
com.oidar.sql.SqlHandler.java
com.oidar.util.Constants.java
com.oidar.util.MathHelper.java
com.oidar.util.MyLog.java
com.oidar.util.OIDARConstants.java
com.oidar.util.PreferenceUtil.java
com.oidar.util.StringHelper.java
com.oidar.util.Util.java
com.oidar.view.CustomDrawerLayout.java