Andrew Flynn | 8286257 | 2015-04-01 14:22:37 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.systemui; |
| 18 | |
| 19 | import android.annotation.StringDef; |
| 20 | import android.content.Context; |
| 21 | import android.content.SharedPreferences; |
| 22 | import android.content.SharedPreferences.OnSharedPreferenceChangeListener; |
| 23 | |
| 24 | import java.lang.annotation.Retention; |
| 25 | import java.lang.annotation.RetentionPolicy; |
| 26 | import java.util.Map; |
| 27 | |
| 28 | public final class Prefs { |
| 29 | private Prefs() {} // no instantation |
| 30 | |
| 31 | @Retention(RetentionPolicy.SOURCE) |
| 32 | @StringDef({ |
Winson | 250608a | 2015-11-24 15:00:31 -0800 | [diff] [blame] | 33 | Key.OVERVIEW_LAST_STACK_TASK_ACTIVE_TIME, |
Andrew Flynn | 8286257 | 2015-04-01 14:22:37 -0400 | [diff] [blame] | 34 | Key.DEBUG_MODE_ENABLED, |
| 35 | Key.HOTSPOT_TILE_LAST_USED, |
| 36 | Key.COLOR_INVERSION_TILE_LAST_USED, |
| 37 | Key.DND_TILE_VISIBLE, |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 38 | Key.DND_TILE_COMBINED_ICON, |
| 39 | Key.DND_CONFIRMED_PRIORITY_INTRODUCTION, |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 40 | Key.DND_CONFIRMED_SILENCE_INTRODUCTION, |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 41 | Key.DND_FAVORITE_BUCKET_INDEX, |
| 42 | Key.DND_NONE_SELECTED, |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 43 | Key.DND_FAVORITE_ZEN, |
Jason Monk | c3f42c1 | 2016-02-05 12:33:13 -0500 | [diff] [blame] | 44 | Key.QS_HOTSPOT_ADDED, |
| 45 | Key.QS_DATA_SAVER_ADDED, |
Felipe Leme | 0281a99 | 2016-04-27 10:22:32 -0700 | [diff] [blame] | 46 | Key.QS_DATA_SAVER_DIALOG_SHOWN, |
Jason Monk | c3f42c1 | 2016-02-05 12:33:13 -0500 | [diff] [blame] | 47 | Key.QS_INVERT_COLORS_ADDED, |
| 48 | Key.QS_WORK_ADDED, |
Christine Franks | 69c2d1d | 2017-01-23 14:45:29 -0800 | [diff] [blame] | 49 | Key.QS_NIGHTDISPLAY_ADDED, |
Andrew Flynn | 8286257 | 2015-04-01 14:22:37 -0400 | [diff] [blame] | 50 | }) |
| 51 | public @interface Key { |
Winson Chung | 28217a4 | 2017-02-15 13:46:52 -0800 | [diff] [blame] | 52 | @Deprecated |
Winson | 250608a | 2015-11-24 15:00:31 -0800 | [diff] [blame] | 53 | String OVERVIEW_LAST_STACK_TASK_ACTIVE_TIME = "OverviewLastStackTaskActiveTime"; |
Andrew Flynn | 8286257 | 2015-04-01 14:22:37 -0400 | [diff] [blame] | 54 | String DEBUG_MODE_ENABLED = "debugModeEnabled"; |
| 55 | String HOTSPOT_TILE_LAST_USED = "HotspotTileLastUsed"; |
| 56 | String COLOR_INVERSION_TILE_LAST_USED = "ColorInversionTileLastUsed"; |
| 57 | String DND_TILE_VISIBLE = "DndTileVisible"; |
| 58 | String DND_TILE_COMBINED_ICON = "DndTileCombinedIcon"; |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 59 | String DND_CONFIRMED_PRIORITY_INTRODUCTION = "DndConfirmedPriorityIntroduction"; |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 60 | String DND_CONFIRMED_SILENCE_INTRODUCTION = "DndConfirmedSilenceIntroduction"; |
Julia Reynolds | d7a00aa | 2017-02-16 15:01:36 -0500 | [diff] [blame] | 61 | String DND_CONFIRMED_ALARM_INTRODUCTION = "DndConfirmedAlarmIntroduction"; |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 62 | String DND_FAVORITE_BUCKET_INDEX = "DndCountdownMinuteIndex"; |
| 63 | String DND_NONE_SELECTED = "DndNoneSelected"; |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 64 | String DND_FAVORITE_ZEN = "DndFavoriteZen"; |
Felipe Leme | 0281a99 | 2016-04-27 10:22:32 -0700 | [diff] [blame] | 65 | String QS_DATA_SAVER_DIALOG_SHOWN = "QsDataSaverDialogShown"; |
Jason Monk | cb5296a | 2017-06-30 10:28:18 -0400 | [diff] [blame^] | 66 | @Deprecated |
| 67 | String QS_HOTSPOT_ADDED = "QsHotspotAdded"; |
| 68 | @Deprecated |
| 69 | String QS_DATA_SAVER_ADDED = "QsDataSaverAdded"; |
| 70 | @Deprecated |
Jason Monk | c3f42c1 | 2016-02-05 12:33:13 -0500 | [diff] [blame] | 71 | String QS_INVERT_COLORS_ADDED = "QsInvertColorsAdded"; |
Jason Monk | cb5296a | 2017-06-30 10:28:18 -0400 | [diff] [blame^] | 72 | @Deprecated |
Jason Monk | c3f42c1 | 2016-02-05 12:33:13 -0500 | [diff] [blame] | 73 | String QS_WORK_ADDED = "QsWorkAdded"; |
Jason Monk | cb5296a | 2017-06-30 10:28:18 -0400 | [diff] [blame^] | 74 | @Deprecated |
Christine Franks | 69c2d1d | 2017-01-23 14:45:29 -0800 | [diff] [blame] | 75 | String QS_NIGHTDISPLAY_ADDED = "QsNightDisplayAdded"; |
Andrew Flynn | 8286257 | 2015-04-01 14:22:37 -0400 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | public static boolean getBoolean(Context context, @Key String key, boolean defaultValue) { |
| 79 | return get(context).getBoolean(key, defaultValue); |
| 80 | } |
| 81 | |
| 82 | public static void putBoolean(Context context, @Key String key, boolean value) { |
| 83 | get(context).edit().putBoolean(key, value).apply(); |
| 84 | } |
| 85 | |
| 86 | public static int getInt(Context context, @Key String key, int defaultValue) { |
| 87 | return get(context).getInt(key, defaultValue); |
| 88 | } |
| 89 | |
| 90 | public static void putInt(Context context, @Key String key, int value) { |
| 91 | get(context).edit().putInt(key, value).apply(); |
| 92 | } |
| 93 | |
| 94 | public static long getLong(Context context, @Key String key, long defaultValue) { |
| 95 | return get(context).getLong(key, defaultValue); |
| 96 | } |
| 97 | |
| 98 | public static void putLong(Context context, @Key String key, long value) { |
| 99 | get(context).edit().putLong(key, value).apply(); |
| 100 | } |
| 101 | |
Winson Chung | af3bb69 | 2015-06-03 17:31:39 -0700 | [diff] [blame] | 102 | public static String getString(Context context, @Key String key, String defaultValue) { |
| 103 | return get(context).getString(key, defaultValue); |
| 104 | } |
| 105 | |
| 106 | public static void putString(Context context, @Key String key, String value) { |
| 107 | get(context).edit().putString(key, value).apply(); |
| 108 | } |
| 109 | |
Andrew Flynn | 8286257 | 2015-04-01 14:22:37 -0400 | [diff] [blame] | 110 | public static Map<String, ?> getAll(Context context) { |
| 111 | return get(context).getAll(); |
| 112 | } |
| 113 | |
| 114 | public static void remove(Context context, @Key String key) { |
| 115 | get(context).edit().remove(key).apply(); |
| 116 | } |
| 117 | |
| 118 | public static void registerListener(Context context, |
| 119 | OnSharedPreferenceChangeListener listener) { |
| 120 | get(context).registerOnSharedPreferenceChangeListener(listener); |
| 121 | } |
| 122 | |
| 123 | public static void unregisterListener(Context context, |
| 124 | OnSharedPreferenceChangeListener listener) { |
| 125 | get(context).unregisterOnSharedPreferenceChangeListener(listener); |
| 126 | } |
| 127 | |
| 128 | private static SharedPreferences get(Context context) { |
| 129 | return context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE); |
| 130 | } |
| 131 | } |