OSDN Git Service

4357a451c54d2c84607717fe9372a6b7017d777a
[android-x86/packages-apps-Trebuchet.git] / src / com / android / launcher3 / settings / SettingsProvider.java
1 /*
2  * Copyright (C) 2013 The CyanogenMod Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package com.android.launcher3.settings;
18
19 import android.content.Context;
20 import android.content.SharedPreferences;
21
22 public final class SettingsProvider {
23     public static final String SETTINGS_KEY = "trebuchet_preferences";
24     public static final String SETTINGS_CHANGED = "settings_changed";
25
26     public static final String SETTINGS_UI_HOMESCREEN_DEFAULT_SCREEN_ID = "ui_homescreen_default_screen_id";
27     public static final String SETTINGS_UI_HOMESCREEN_SEARCH = "ui_homescreen_search";
28     public static final String SETTINGS_UI_HOMESCREEN_HIDE_ICON_LABELS = "ui_homescreen_general_hide_icon_labels";
29     public static final String SETTINGS_UI_HOMESCREEN_SCROLLING_WALLPAPER_SCROLL = "ui_homescreen_scrolling_wallpaper_scroll";
30     public static final String SETTINGS_UI_DYNAMIC_GRID_SIZE = "ui_dynamic_grid_size";
31     public static final String SETTINGS_UI_HOMESCREEN_ROWS = "ui_homescreen_rows";
32     public static final String SETTINGS_UI_HOMESCREEN_COLUMNS = "ui_homescreen_columns";
33     public static final String SETTINGS_UI_DRAWER_HIDE_ICON_LABELS = "ui_drawer_hide_icon_labels";
34     public static final String SETTINGS_UI_DRAWER_STYLE_USE_COMPACT = "ui_drawer_style_compact";
35     public static final String SETTINGS_UI_DRAWER_DARK = "ui_drawer_dark";
36     public static final String SETTINGS_UI_USE_SCROLLER = "ui_scroller";
37     public static final String SETTINGS_UI_USE_HORIZONTAL_SCRUBBER = "ui_horizontal_scrubber";
38     public static final String SETTINGS_UI_DRAWER_SEARCH = "ui_drawer_search";
39     public static final String SETTINGS_UI_GENERAL_ICONS_LARGE = "ui_general_icons_large";
40     public static final String SETTINGS_UI_ALLOW_ROTATION = "ui_allow_rotation";
41
42     public static SharedPreferences get(Context context) {
43         return context.getSharedPreferences(SETTINGS_KEY, Context.MODE_PRIVATE);
44     }
45
46     public static int getIntCustomDefault(Context context, String key, int def) {
47         return get(context).getInt(key, def);
48     }
49
50     public static int getInt(Context context, String key, int resource) {
51         return getIntCustomDefault(context, key, context.getResources().getInteger(resource));
52     }
53
54     public static long getLongCustomDefault(Context context, String key, long def) {
55         return get(context).getLong(key, def);
56     }
57
58     public static long getLong(Context context, String key, int resource) {
59         return getLongCustomDefault(context, key, context.getResources().getInteger(resource));
60     }
61
62     public static boolean getBooleanCustomDefault(Context context, String key, boolean def) {
63         return get(context).getBoolean(key, def);
64     }
65
66     public static boolean getBoolean(Context context, String key, int resource) {
67         return getBooleanCustomDefault(context, key, context.getResources().getBoolean(resource));
68     }
69
70     public static String getStringCustomDefault(Context context, String key, String def) {
71         return get(context).getString(key, def);
72     }
73
74     public static String getString(Context context, String key, int resource) {
75         return getStringCustomDefault(context, key, context.getResources().getString(resource));
76     }
77
78     public static void putString(Context context, String key, String value) {
79         get(context).edit().putString(key, value).commit();
80     }
81
82     public static void putInt(Context context, String key, int value) {
83         get(context).edit().putInt(key, value).commit();
84     }
85
86     public static void putBoolean(Context context, String key, boolean value) {
87         get(context).edit().putBoolean(key, value).commit();
88     }
89 }