• sharedPreference工具类


    package com.huawei.pom.alarm.util;
    
    import android.content.Context;
    import android.content.SharedPreferences;
    import android.content.SharedPreferences.Editor;
    import android.preference.PreferenceManager;
     
    public class SPUtil {
            private Context context;
            private SharedPreferences sp = null;
            private Editor edit = null;
     
            /**
             * Create DefaultSharedPreferences
             * 
             * @param context
             */
            public SPUtil(Context context) {
                    this(context, PreferenceManager.getDefaultSharedPreferences(context));
            }
     
            /**
             * Create SharedPreferences by filename
             * 
             * @param context
             * @param filename
             */
            public SPUtil(Context context, String filename) {
                    this(context, context.getSharedPreferences(filename,
                                    Context.MODE_WORLD_WRITEABLE));
            }
     
            /**
             * Create SharedPreferences by SharedPreferences
             * 
             * @param context
             * @param sp
             */
            public SPUtil(Context context, SharedPreferences sp) {
                    this.context = context;
                    this.sp = sp;
                    edit = sp.edit();
            }
     
            // Set
     
            // Boolean
            public void setValue(String key, boolean value) {
                    edit.putBoolean(key, value);
                    edit.commit();
            }
     
            public void setValue(int resKey, boolean value) {
                    setValue(this.context.getString(resKey), value);
            }
     
            // Float
            public void setValue(String key, float value) {
                    edit.putFloat(key, value);
                    edit.commit();
            }
     
            public void setValue(int resKey, float value) {
                    setValue(this.context.getString(resKey), value);
            }
     
            // Integer
            public void setValue(String key, int value) {
                    edit.putInt(key, value);
                    edit.commit();
            }
     
            public void setValue(int resKey, int value) {
                    setValue(this.context.getString(resKey), value);
            }
     
            // Long
            public void setValue(String key, long value) {
                    edit.putLong(key, value);
                    edit.commit();
            }
     
            public void setValue(int resKey, long value) {
                    setValue(this.context.getString(resKey), value);
            }
     
            // String
            public void setValue(String key, String value) {
                    edit.putString(key, value);
                    edit.commit();
            }
     
            public void setValue(int resKey, String value) {
                    setValue(this.context.getString(resKey), value);
            }
     
            // Get
     
            // Boolean
            public boolean getValue(String key, boolean defaultValue) {
                    return sp.getBoolean(key, defaultValue);
            }
     
            public boolean getValue(int resKey, boolean defaultValue) {
                    return getValue(this.context.getString(resKey), defaultValue);
            }
     
            // Float
            public float getValue(String key, float defaultValue) {
                    return sp.getFloat(key, defaultValue);
            }
     
            public float getValue(int resKey, float defaultValue) {
                    return getValue(this.context.getString(resKey), defaultValue);
            }
     
            // Integer
            public int getValue(String key, int defaultValue) {
                    return sp.getInt(key, defaultValue);
            }
     
            public int getValue(int resKey, int defaultValue) {
                    return getValue(this.context.getString(resKey), defaultValue);
            }
     
            // Long
            public long getValue(String key, long defaultValue) {
                    return sp.getLong(key, defaultValue);
            }
     
            public long getValue(int resKey, long defaultValue) {
                    return getValue(this.context.getString(resKey), defaultValue);
            }
     
            // String
            public String getValue(String key, String defaultValue) {
                    return sp.getString(key, defaultValue);
            }
     
            public String getValue(int resKey, String defaultValue) {
                    return getValue(this.context.getString(resKey), defaultValue);
            }
     
            // Delete
            public void remove(String key) {
                    edit.remove(key);
                    edit.commit();
            }
     
            public void clear() {
                    edit.clear();
                    edit.commit();
            }
     
    }
  • 相关阅读:
    python各种类型转换-int,str,char,float,ord,hex,oct等
    pandas快速入门
    python里面,将多个list列表合并成一个list列表
    对字符串进行切分的技巧
    Ubuntu 16.04 安装navicat (tar.gz)
    ubuntu 16.04 如何升级系统的scrapy旧版本(1.0.3)到最新版本
    ubuntu下,敲命令scrapy出现:0: UserWarning: You do not have a working installation of the service_identity module: 'cannot import name 'opentype''. Please install it from <https://pypi.python.org/pypi/servic
    Ubuntu下解压缩zip,tar,tar.gz,tar.bz2格式的文件
    简单的查看进程信息
    python正则表达式
  • 原文地址:https://www.cnblogs.com/leiqun123/p/3196303.html
Copyright © 2020-2023  润新知