blob: 9f2745b9ac24e135ed1793af682afdf37ef4caac [file] [log] [blame]
Andrew Flynn82862572015-04-01 14:22:37 -04001/*
2 * Copyright (C) 2015 The Android Open Source 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
17package com.android.systemui;
18
19import android.annotation.StringDef;
20import android.content.Context;
21import android.content.SharedPreferences;
22import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
23
24import java.lang.annotation.Retention;
25import java.lang.annotation.RetentionPolicy;
26import java.util.Map;
27
28public final class Prefs {
29 private Prefs() {} // no instantation
30
31 @Retention(RetentionPolicy.SOURCE)
32 @StringDef({
Winsonc742f972015-11-12 11:32:21 -080033 Key.OVERVIEW_SEARCH_APP_WIDGET_ID,
34 Key.OVERVIEW_SEARCH_APP_WIDGET_PACKAGE,
Winson250608a2015-11-24 15:00:31 -080035 Key.OVERVIEW_LAST_STACK_TASK_ACTIVE_TIME,
Andrew Flynn82862572015-04-01 14:22:37 -040036 Key.DEBUG_MODE_ENABLED,
37 Key.HOTSPOT_TILE_LAST_USED,
38 Key.COLOR_INVERSION_TILE_LAST_USED,
39 Key.DND_TILE_VISIBLE,
John Spurlockf55b7f22015-04-13 19:21:26 -040040 Key.DND_TILE_COMBINED_ICON,
41 Key.DND_CONFIRMED_PRIORITY_INTRODUCTION,
John Spurlockd9c75db2015-04-28 11:19:13 -040042 Key.DND_CONFIRMED_SILENCE_INTRODUCTION,
John Spurlockf55b7f22015-04-13 19:21:26 -040043 Key.DND_FAVORITE_BUCKET_INDEX,
44 Key.DND_NONE_SELECTED,
John Spurlockd9c75db2015-04-28 11:19:13 -040045 Key.DND_FAVORITE_ZEN,
Jaewan Kim977dcdc2016-01-20 19:21:08 +090046 Key.TV_PICTURE_IN_PICTURE_ONBOARDING_SHOWN,
Jason Monkc3f42c12016-02-05 12:33:13 -050047 Key.QS_HOTSPOT_ADDED,
48 Key.QS_DATA_SAVER_ADDED,
49 Key.QS_INVERT_COLORS_ADDED,
50 Key.QS_WORK_ADDED,
Jason Monkcb654cb2016-02-25 15:43:07 -050051 Key.QS_NIGHT_ADDED,
Andrew Flynn82862572015-04-01 14:22:37 -040052 })
53 public @interface Key {
Winsonc742f972015-11-12 11:32:21 -080054 String OVERVIEW_SEARCH_APP_WIDGET_ID = "searchAppWidgetId";
55 String OVERVIEW_SEARCH_APP_WIDGET_PACKAGE = "searchAppWidgetPackage";
Winson250608a2015-11-24 15:00:31 -080056 String OVERVIEW_LAST_STACK_TASK_ACTIVE_TIME = "OverviewLastStackTaskActiveTime";
Andrew Flynn82862572015-04-01 14:22:37 -040057 String DEBUG_MODE_ENABLED = "debugModeEnabled";
58 String HOTSPOT_TILE_LAST_USED = "HotspotTileLastUsed";
59 String COLOR_INVERSION_TILE_LAST_USED = "ColorInversionTileLastUsed";
60 String DND_TILE_VISIBLE = "DndTileVisible";
61 String DND_TILE_COMBINED_ICON = "DndTileCombinedIcon";
John Spurlockf55b7f22015-04-13 19:21:26 -040062 String DND_CONFIRMED_PRIORITY_INTRODUCTION = "DndConfirmedPriorityIntroduction";
John Spurlockd9c75db2015-04-28 11:19:13 -040063 String DND_CONFIRMED_SILENCE_INTRODUCTION = "DndConfirmedSilenceIntroduction";
John Spurlockf55b7f22015-04-13 19:21:26 -040064 String DND_FAVORITE_BUCKET_INDEX = "DndCountdownMinuteIndex";
65 String DND_NONE_SELECTED = "DndNoneSelected";
John Spurlockd9c75db2015-04-28 11:19:13 -040066 String DND_FAVORITE_ZEN = "DndFavoriteZen";
Jaewan Kim977dcdc2016-01-20 19:21:08 +090067 String TV_PICTURE_IN_PICTURE_ONBOARDING_SHOWN = "TvPictureInPictureOnboardingShown";
Jason Monkc3f42c12016-02-05 12:33:13 -050068 String QS_HOTSPOT_ADDED = "QsHotspotAdded";
69 String QS_DATA_SAVER_ADDED = "QsDataSaverAdded";
70 String QS_INVERT_COLORS_ADDED = "QsInvertColorsAdded";
71 String QS_WORK_ADDED = "QsWorkAdded";
Jason Monkcb654cb2016-02-25 15:43:07 -050072 String QS_NIGHT_ADDED = "QsNightAdded";
Andrew Flynn82862572015-04-01 14:22:37 -040073 }
74
75 public static boolean getBoolean(Context context, @Key String key, boolean defaultValue) {
76 return get(context).getBoolean(key, defaultValue);
77 }
78
79 public static void putBoolean(Context context, @Key String key, boolean value) {
80 get(context).edit().putBoolean(key, value).apply();
81 }
82
83 public static int getInt(Context context, @Key String key, int defaultValue) {
84 return get(context).getInt(key, defaultValue);
85 }
86
87 public static void putInt(Context context, @Key String key, int value) {
88 get(context).edit().putInt(key, value).apply();
89 }
90
91 public static long getLong(Context context, @Key String key, long defaultValue) {
92 return get(context).getLong(key, defaultValue);
93 }
94
95 public static void putLong(Context context, @Key String key, long value) {
96 get(context).edit().putLong(key, value).apply();
97 }
98
Winson Chungaf3bb692015-06-03 17:31:39 -070099 public static String getString(Context context, @Key String key, String defaultValue) {
100 return get(context).getString(key, defaultValue);
101 }
102
103 public static void putString(Context context, @Key String key, String value) {
104 get(context).edit().putString(key, value).apply();
105 }
106
Andrew Flynn82862572015-04-01 14:22:37 -0400107 public static Map<String, ?> getAll(Context context) {
108 return get(context).getAll();
109 }
110
111 public static void remove(Context context, @Key String key) {
112 get(context).edit().remove(key).apply();
113 }
114
115 public static void registerListener(Context context,
116 OnSharedPreferenceChangeListener listener) {
117 get(context).registerOnSharedPreferenceChangeListener(listener);
118 }
119
120 public static void unregisterListener(Context context,
121 OnSharedPreferenceChangeListener listener) {
122 get(context).unregisterOnSharedPreferenceChangeListener(listener);
123 }
124
125 private static SharedPreferences get(Context context) {
126 return context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
127 }
128}