|
import android.content.Context; |
|
import android.content.SharedPreferences; |
|
import android.content.SharedPreferences.Editor; |
|
import android.preference.PreferenceManager; |
|
|
|
public class GlobalSetting { |
|
|
|
public static int deviceWidth; |
|
public static int deviceHeight; |
|
|
|
public static final String FILL_COLUMN = "fillColumn"; |
|
public static final String TAB_WIDTH = "tabWidth"; |
|
|
|
public static int tabWidth; |
|
public static int fillColumn; |
|
|
|
|
|
public static void savePreference(Context context, String key, Object value){ |
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); |
|
Editor editor = prefs.edit(); |
|
if (value instanceof Boolean){ |
|
editor.putBoolean(key, (Boolean)value); |
|
}else if (value instanceof String){ |
|
editor.putString(key, (String)value); |
|
}else if (value instanceof Integer){ |
|
editor.putInt(key, (Integer)value); |
|
}else if (value instanceof Float){ |
|
editor.putFloat(key, (Float)value); |
|
}else if (value instanceof Long){ |
|
editor.putLong(key, (Long)value); |
|
} |
|
editor.commit(); |
|
} |
|
|
|
/** |
|
Load default preferences |
|
it should be called from onResume(). |
|
*/ |
|
public static void loadPreferences(Context context){ |
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); |
|
tabWidth = prefs.getInt(TAB_WIDTH, 8); |
|
fillColumn = prefs.getInt(FILL_COLUMN, 72); |
|
} |
|
} |