Android Open Source - CommonLibs Pref Utils






From Project

Back to project page CommonLibs.

License

The source code is released under:

Apache License

If you think the Android project CommonLibs 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.alex.common.utils;
/*from  w w w .j  av  a 2  s  . c om*/
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

/**
 * SharedPreferences?????
 * @author caisenchuan
 */
public class PrefUtils {
    /*--------------------------
     * ???
     *-------------------------*/

    /*--------------------------
     * ?????
     *-------------------------*/

    /*--------------------------
     * ????????
     *-------------------------*/

    /*--------------------------
     * public??
     *-------------------------*/
    /**
     * ???????pref?
     * @param context ???
     * @param pref_name share pref????
     * @param tag ?????
     * @param value ???
     */
    public static void keep(Context context, String pref_name, String tag, String value) {
        SharedPreferences pref = context.getSharedPreferences(pref_name, Context.MODE_APPEND);
        Editor editor = pref.edit();
        editor.putString(tag, value);
        editor.commit();
    }
    
    /**
     * ???boolean?pref?
     * @param context ???
     * @param pref_name share pref????
     * @param tag ?????
     * @param value ???
     */
    public static void keep(Context context, String pref_name, String tag, boolean value) {
        SharedPreferences pref = context.getSharedPreferences(pref_name, Context.MODE_APPEND);
        Editor editor = pref.edit();
        editor.putBoolean(tag, value);
        editor.commit();
    }

    /**
     * ?pref????????
     * @param context ???
     * @param pref_name share pref????
     * @param tag ?????
     */
    public static String readString(Context context, String pref_name, String tag) {
        SharedPreferences pref = context.getSharedPreferences(pref_name, Context.MODE_APPEND);
        String ret = pref.getString(tag, "");
        return ret;
    }
    
    /**
     * ?pref?????boolean
     * @param context ???
     * @param pref_name share pref????
     * @param tag ?????
     */
    public static boolean readBoolean(Context context, String pref_name, String tag) {
        SharedPreferences pref = context.getSharedPreferences(pref_name, Context.MODE_APPEND);
        boolean ret = pref.getBoolean(tag, false);
        return ret;
    }

    /**
     * ??????
     * @param context
     * @param pref_name share pref????
     */
    public static void clear(Context context, String pref_name) {
        SharedPreferences pref = context.getSharedPreferences(pref_name, Context.MODE_APPEND);
        Editor editor = pref.edit();
        editor.clear();
        editor.commit();
    }
    /*--------------------------
     * protected??packet??
     *-------------------------*/

    /*--------------------------
     * private??
     *-------------------------*/

}




Java Source Code List

com.alex.common.AppConfig.java
com.alex.common.AppControl.java
com.alex.common.Err.java
com.alex.common.OnHttpRequestReturnListener.java
com.alex.common.activities.BaseActivity.java
com.alex.common.activities.ImageLoadActivity.java
com.alex.common.activities.WebViewActivity.java
com.alex.common.apis.HttpApi.java
com.alex.common.exception.RetErrorException.java
com.alex.common.utils.BackgroundHandler.java
com.alex.common.utils.BaiduMapUtils.java
com.alex.common.utils.DateTimeUtils.java
com.alex.common.utils.DeviceUtils.java
com.alex.common.utils.DialogUtils.java
com.alex.common.utils.FileUtils.java
com.alex.common.utils.ImageUtils.java
com.alex.common.utils.KLog.java
com.alex.common.utils.Misc.java
com.alex.common.utils.NetworkUtils.java
com.alex.common.utils.PrefUtils.java
com.alex.common.utils.ShareUtils.java
com.alex.common.utils.StringUtils.java
com.alex.common.utils.ThreadUtils.java
com.alex.common.utils.ToastUtils.java
com.alex.common.views.ZoomImageView.java