1 /* 2 * Copyright (C) 2020 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.settings.accessibility; 18 19 import android.content.Context; 20 import android.content.SharedPreferences; 21 22 import com.google.common.collect.ImmutableSet; 23 24 import java.util.Set; 25 26 /** Utility class for SharedPreferences. */ 27 public final class SharedPreferenceUtils { 28 29 private static final String ACCESSIBILITY_PERF = "accessibility_prefs"; 30 private static final String USER_SHORTCUT_TYPE = "user_shortcut_type"; SharedPreferenceUtils()31 private SharedPreferenceUtils() { } 32 getSharedPreferences(Context context, String fileName)33 private static SharedPreferences getSharedPreferences(Context context, String fileName) { 34 return context.getSharedPreferences(fileName, Context.MODE_PRIVATE); 35 } 36 37 /** Returns a set of user shortcuts list to determine user preferred service shortcut. */ getUserShortcutTypes(Context context)38 public static Set<String> getUserShortcutTypes(Context context) { 39 return getSharedPreferences(context, ACCESSIBILITY_PERF) 40 .getStringSet(USER_SHORTCUT_TYPE, ImmutableSet.of()); 41 } 42 43 /** Sets a set of user shortcuts list to determine user preferred service shortcut. */ setUserShortcutType(Context context, Set<String> data)44 public static void setUserShortcutType(Context context, Set<String> data) { 45 SharedPreferences.Editor editor = getSharedPreferences(context, ACCESSIBILITY_PERF).edit(); 46 editor.remove(USER_SHORTCUT_TYPE).apply(); 47 editor.putStringSet(USER_SHORTCUT_TYPE, data).apply(); 48 } 49 } 50