/* * Copyright 2016 Hippo Seven * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hippo.ehviewer; import android.content.Context; import android.content.SharedPreferences; import android.preference.PreferenceManager; import com.hippo.yorozuya.NumberUtils; public class Settings { private static Context sContext; private static SharedPreferences sSettingsPre; public static void initialize(Context context) { sContext = context.getApplicationContext(); sSettingsPre = PreferenceManager.getDefaultSharedPreferences(sContext); } public static boolean getBoolean(String key, boolean defValue) { return sSettingsPre.getBoolean(key, defValue); } public static void putBoolean(String key, boolean value) { sSettingsPre.edit().putBoolean(key, value).apply(); } public static int getInt(String key, int defValue) { return sSettingsPre.getInt(key, defValue); } public static void putInt(String key, int value) { sSettingsPre.edit().putInt(key, value).apply(); } public static long getLong(String key, long defValue) { return sSettingsPre.getLong(key, defValue); } public static void putLong(String key, long value) { sSettingsPre.edit().putLong(key, value).apply(); } public static float getFloat(String key, float defValue) { return sSettingsPre.getFloat(key, defValue); } public static void putFloat(String key, float value) { sSettingsPre.edit().putFloat(key, value).apply(); } public static String getString(String key, String defValue) { return sSettingsPre.getString(key, defValue); } public static void putString(String key, String value) { sSettingsPre.edit().putString(key, value).apply(); } public static int getIntFromStr(String key, int defValue) { return NumberUtils.parseIntSafely(sSettingsPre.getString(key, Integer.toString(defValue)), defValue); } public static void putIntToStr(String key, int value) { sSettingsPre.edit().putString(key, Integer.toString(value)).apply(); } private static final String KEY_DISPLAY_NAME = "display_name"; private static final String DEFAULT_DISPLAY_NAME = null; public static String getDisplayName() { return getString(KEY_DISPLAY_NAME, DEFAULT_DISPLAY_NAME); } public static void putDisplayName(String value) { putString(KEY_DISPLAY_NAME, value); } private static final String KEY_SHOW_WARNING = "show_warning"; private static final boolean DEFAULT_SHOW_WARNING = true; public static boolean getShowWarning() { return getBoolean(KEY_SHOW_WARNING, DEFAULT_SHOW_WARNING); } public static void putShowWarning(boolean value) { putBoolean(KEY_SHOW_WARNING, value); } }