blob: 9319bc60f9ef4731affac946381acc38b728f21d [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({
Winson250608a2015-11-24 15:00:31 -080033 Key.OVERVIEW_LAST_STACK_TASK_ACTIVE_TIME,
Andrew Flynn82862572015-04-01 14:22:37 -040034 Key.DEBUG_MODE_ENABLED,
35 Key.HOTSPOT_TILE_LAST_USED,
36 Key.COLOR_INVERSION_TILE_LAST_USED,
37 Key.DND_TILE_VISIBLE,
John Spurlockf55b7f22015-04-13 19:21:26 -040038 Key.DND_TILE_COMBINED_ICON,
39 Key.DND_CONFIRMED_PRIORITY_INTRODUCTION,
John Spurlockd9c75db2015-04-28 11:19:13 -040040 Key.DND_CONFIRMED_SILENCE_INTRODUCTION,
John Spurlockf55b7f22015-04-13 19:21:26 -040041 Key.DND_FAVORITE_BUCKET_INDEX,
42 Key.DND_NONE_SELECTED,
John Spurlockd9c75db2015-04-28 11:19:13 -040043 Key.DND_FAVORITE_ZEN,
Jason Monkc3f42c12016-02-05 12:33:13 -050044 Key.QS_HOTSPOT_ADDED,
45 Key.QS_DATA_SAVER_ADDED,
Felipe Leme0281a992016-04-27 10:22:32 -070046 Key.QS_DATA_SAVER_DIALOG_SHOWN,
Jason Monkc3f42c12016-02-05 12:33:13 -050047 Key.QS_INVERT_COLORS_ADDED,
48 Key.QS_WORK_ADDED,
Christine Franks69c2d1d2017-01-23 14:45:29 -080049 Key.QS_NIGHTDISPLAY_ADDED,
Jason Monk24f8a752017-06-30 11:31:03 -040050 Key.SEEN_MULTI_USER,
Tony Wickhamfb63fe82018-01-16 12:14:06 -080051 Key.NUM_APPS_LAUNCHED,
52 Key.HAS_SWIPED_UP_FOR_RECENTS,
Andrew Flynn82862572015-04-01 14:22:37 -040053 })
54 public @interface Key {
Winson Chung28217a42017-02-15 13:46:52 -080055 @Deprecated
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";
Julia Reynoldsd7a00aa2017-02-16 15:01:36 -050064 String DND_CONFIRMED_ALARM_INTRODUCTION = "DndConfirmedAlarmIntroduction";
John Spurlockf55b7f22015-04-13 19:21:26 -040065 String DND_FAVORITE_BUCKET_INDEX = "DndCountdownMinuteIndex";
66 String DND_NONE_SELECTED = "DndNoneSelected";
John Spurlockd9c75db2015-04-28 11:19:13 -040067 String DND_FAVORITE_ZEN = "DndFavoriteZen";
Felipe Leme0281a992016-04-27 10:22:32 -070068 String QS_DATA_SAVER_DIALOG_SHOWN = "QsDataSaverDialogShown";
Jason Monkcb5296a2017-06-30 10:28:18 -040069 @Deprecated
70 String QS_HOTSPOT_ADDED = "QsHotspotAdded";
71 @Deprecated
72 String QS_DATA_SAVER_ADDED = "QsDataSaverAdded";
73 @Deprecated
Jason Monkc3f42c12016-02-05 12:33:13 -050074 String QS_INVERT_COLORS_ADDED = "QsInvertColorsAdded";
Jason Monkcb5296a2017-06-30 10:28:18 -040075 @Deprecated
Jason Monkc3f42c12016-02-05 12:33:13 -050076 String QS_WORK_ADDED = "QsWorkAdded";
Jason Monkcb5296a2017-06-30 10:28:18 -040077 @Deprecated
Christine Franks69c2d1d2017-01-23 14:45:29 -080078 String QS_NIGHTDISPLAY_ADDED = "QsNightDisplayAdded";
Jason Monk24f8a752017-06-30 11:31:03 -040079 String SEEN_MULTI_USER = "HasSeenMultiUser";
Tony Wickhamfb63fe82018-01-16 12:14:06 -080080 String NUM_APPS_LAUNCHED = "NumAppsLaunched";
81 String HAS_SWIPED_UP_FOR_RECENTS = "HasSwipedUpForRecents";
Andrew Flynn82862572015-04-01 14:22:37 -040082 }
83
84 public static boolean getBoolean(Context context, @Key String key, boolean defaultValue) {
85 return get(context).getBoolean(key, defaultValue);
86 }
87
88 public static void putBoolean(Context context, @Key String key, boolean value) {
89 get(context).edit().putBoolean(key, value).apply();
90 }
91
92 public static int getInt(Context context, @Key String key, int defaultValue) {
93 return get(context).getInt(key, defaultValue);
94 }
95
96 public static void putInt(Context context, @Key String key, int value) {
97 get(context).edit().putInt(key, value).apply();
98 }
99
100 public static long getLong(Context context, @Key String key, long defaultValue) {
101 return get(context).getLong(key, defaultValue);
102 }
103
104 public static void putLong(Context context, @Key String key, long value) {
105 get(context).edit().putLong(key, value).apply();
106 }
107
Winson Chungaf3bb692015-06-03 17:31:39 -0700108 public static String getString(Context context, @Key String key, String defaultValue) {
109 return get(context).getString(key, defaultValue);
110 }
111
112 public static void putString(Context context, @Key String key, String value) {
113 get(context).edit().putString(key, value).apply();
114 }
115
Andrew Flynn82862572015-04-01 14:22:37 -0400116 public static Map<String, ?> getAll(Context context) {
117 return get(context).getAll();
118 }
119
120 public static void remove(Context context, @Key String key) {
121 get(context).edit().remove(key).apply();
122 }
123
124 public static void registerListener(Context context,
125 OnSharedPreferenceChangeListener listener) {
126 get(context).registerOnSharedPreferenceChangeListener(listener);
127 }
128
129 public static void unregisterListener(Context context,
130 OnSharedPreferenceChangeListener listener) {
131 get(context).unregisterOnSharedPreferenceChangeListener(listener);
132 }
133
134 private static SharedPreferences get(Context context) {
135 return context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
136 }
137}