完善SDK
This commit is contained in:
@@ -2,8 +2,6 @@ package com.mogo.utils.storage;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@@ -13,11 +11,11 @@ public class SharedPrefsMgr {
|
||||
private static SharedPrefsMgr sInstance;
|
||||
private static SharedPreferences sSharedPrefs;
|
||||
|
||||
public synchronized static SharedPrefsMgr getInstance(@NonNull Context context ) {
|
||||
if ( sInstance == null ) {
|
||||
public synchronized static SharedPrefsMgr getInstance(Context context) {
|
||||
if (sInstance == null) {
|
||||
try {
|
||||
sInstance = new SharedPrefsMgr( context.getApplicationContext() );
|
||||
} catch ( Exception e ) {
|
||||
sInstance = new SharedPrefsMgr(context.getApplicationContext());
|
||||
} catch (Exception e) {
|
||||
sInstance = new SharedPrefsMgr();
|
||||
}
|
||||
}
|
||||
@@ -28,127 +26,127 @@ public class SharedPrefsMgr {
|
||||
|
||||
}
|
||||
|
||||
private SharedPrefsMgr( Context context ) {
|
||||
private SharedPrefsMgr(Context context) {
|
||||
try {
|
||||
sSharedPrefs = context.getSharedPreferences( File_Name, Context.MODE_PRIVATE );
|
||||
} catch ( Exception e ) {
|
||||
sSharedPrefs = context.getSharedPreferences(File_Name, Context.MODE_PRIVATE);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void putString( String key, String value ) {
|
||||
public void putString(String key, String value) {
|
||||
try {
|
||||
SharedPreferences.Editor editor = sSharedPrefs.edit();
|
||||
editor.putString( key, value );
|
||||
editor.putString(key, value);
|
||||
editor.apply();
|
||||
} catch ( Exception e ) {
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
public String getString( String tag ) {
|
||||
public String getString(String tag) {
|
||||
try {
|
||||
return sSharedPrefs.getString( tag, "" );
|
||||
} catch ( Exception e ) {
|
||||
return sSharedPrefs.getString(tag, "");
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public String getString( String tag, String defVal ) {
|
||||
public String getString(String tag, String defVal) {
|
||||
try {
|
||||
return sSharedPrefs.getString( tag, defVal );
|
||||
} catch ( Exception e ) {
|
||||
return sSharedPrefs.getString(tag, defVal);
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public boolean getBoolean( String key, boolean defaultValue ) {
|
||||
public boolean getBoolean(String key, boolean defaultValue) {
|
||||
try {
|
||||
return sSharedPrefs.getBoolean( key, defaultValue );
|
||||
} catch ( Exception e ) {
|
||||
return sSharedPrefs.getBoolean(key, defaultValue);
|
||||
} catch (Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public long getLong( String key, long defaultValue ) {
|
||||
public long getLong(String key, long defaultValue) {
|
||||
try {
|
||||
return sSharedPrefs.getLong( key, defaultValue );
|
||||
} catch ( Exception e ) {
|
||||
return sSharedPrefs.getLong(key, defaultValue);
|
||||
} catch (Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public float getFloat( String key, float defaultValue ) {
|
||||
public float getFloat(String key, float defaultValue) {
|
||||
try {
|
||||
return sSharedPrefs.getFloat( key, defaultValue );
|
||||
} catch ( Exception e ) {
|
||||
return sSharedPrefs.getFloat(key, defaultValue);
|
||||
} catch (Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public int getInt( String key, int value ) {
|
||||
public int getInt(String key, int value) {
|
||||
try {
|
||||
return sSharedPrefs.getInt( key, value );
|
||||
} catch ( Exception e ) {
|
||||
return sSharedPrefs.getInt(key, value);
|
||||
} catch (Exception e) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
public void putBoolean( String key, boolean value ) {
|
||||
public void putBoolean(String key, boolean value) {
|
||||
try {
|
||||
SharedPreferences.Editor editor = sSharedPrefs.edit();
|
||||
editor.putBoolean( key, value );
|
||||
editor.putBoolean(key, value);
|
||||
editor.apply();
|
||||
} catch ( Exception e ) {
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
public void putLong( String key, long value ) {
|
||||
public void putLong(String key, long value) {
|
||||
try {
|
||||
SharedPreferences.Editor editor = sSharedPrefs.edit();
|
||||
editor.putLong( key, value );
|
||||
editor.putLong(key, value);
|
||||
editor.apply();
|
||||
} catch ( Exception e ) {
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
public void putInt( String key, int value ) {
|
||||
public void putInt(String key, int value) {
|
||||
try {
|
||||
SharedPreferences.Editor editor = sSharedPrefs.edit();
|
||||
editor.putInt( key, value );
|
||||
editor.putInt(key, value);
|
||||
editor.apply();
|
||||
} catch ( Exception e ) {
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
public void putFloat( String key, float value ) {
|
||||
public void putFloat(String key, float value) {
|
||||
try {
|
||||
SharedPreferences.Editor editor = sSharedPrefs.edit();
|
||||
editor.putFloat( key, value );
|
||||
editor.putFloat(key, value);
|
||||
editor.apply();
|
||||
} catch ( Exception e ) {
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
public void remove( String key ) {
|
||||
public void remove(String key) {
|
||||
try {
|
||||
SharedPreferences.Editor editor = sSharedPrefs.edit();
|
||||
editor.remove( key );
|
||||
editor.remove(key);
|
||||
editor.apply();
|
||||
} catch ( Exception e ) {
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
public void putStringSet( String key, Set< String > values ) {
|
||||
public void putStringSet(String key, Set<String> values) {
|
||||
try {
|
||||
SharedPreferences.Editor editor = sSharedPrefs.edit();
|
||||
editor.putStringSet( key, values );
|
||||
editor.putStringSet(key, values);
|
||||
editor.apply();
|
||||
} catch ( Exception e ) {
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
public Set<String> getStringSet( String key ) {
|
||||
return sSharedPrefs.getStringSet( key, null );
|
||||
public Set<String> getStringSet(String key) {
|
||||
return sSharedPrefs.getStringSet(key, null);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user