blob: 170fb891f97d2569a37101a298c1241e3c811345 [file] [log] [blame]
Jeff Sharkeye8d13ea2014-08-08 15:10:03 -07001/*
2 * Copyright (C) 2013 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.documentsui;
18
Steve McKay7776aa52016-01-25 19:00:22 -080019import static com.android.documentsui.State.MODE_UNKNOWN;
Steve McKay7776aa52016-01-25 19:00:22 -080020
Jeff Sharkeye8d13ea2014-08-08 15:10:03 -070021import android.content.Context;
22import android.preference.PreferenceManager;
23
Steve McKay7776aa52016-01-25 19:00:22 -080024import com.android.documentsui.State.ViewMode;
25import com.android.documentsui.model.RootInfo;
26
Jeff Sharkeye8d13ea2014-08-08 15:10:03 -070027public class LocalPreferences {
28 private static final String KEY_ADVANCED_DEVICES = "advancedDevices";
29 private static final String KEY_FILE_SIZE = "fileSize";
Steve McKay7776aa52016-01-25 19:00:22 -080030 private static final String ROOT_VIEW_MODE_PREFIX = "rootViewMode-";
Jeff Sharkeye8d13ea2014-08-08 15:10:03 -070031
32 public static boolean getDisplayAdvancedDevices(Context context) {
Jeff Sharkeyff7ab972015-12-03 20:12:45 -070033 boolean defaultAdvanced = context.getResources()
34 .getBoolean(R.bool.config_defaultAdvancedDevices);
Jeff Sharkeye8d13ea2014-08-08 15:10:03 -070035 return PreferenceManager.getDefaultSharedPreferences(context)
Jeff Sharkeyff7ab972015-12-03 20:12:45 -070036 .getBoolean(KEY_ADVANCED_DEVICES, defaultAdvanced);
Jeff Sharkeye8d13ea2014-08-08 15:10:03 -070037 }
38
39 public static boolean getDisplayFileSize(Context context) {
40 return PreferenceManager.getDefaultSharedPreferences(context)
41 .getBoolean(KEY_FILE_SIZE, false);
42 }
43
Steve McKay7776aa52016-01-25 19:00:22 -080044 public static @ViewMode int getViewMode(
45 Context context, RootInfo root, @ViewMode int fallback) {
46 return PreferenceManager.getDefaultSharedPreferences(context)
47 .getInt(createKey(root), fallback);
48 }
49
Jeff Sharkeye8d13ea2014-08-08 15:10:03 -070050 public static void setDisplayAdvancedDevices(Context context, boolean display) {
51 PreferenceManager.getDefaultSharedPreferences(context).edit()
52 .putBoolean(KEY_ADVANCED_DEVICES, display).apply();
53 }
54
55 public static void setDisplayFileSize(Context context, boolean display) {
56 PreferenceManager.getDefaultSharedPreferences(context).edit()
57 .putBoolean(KEY_FILE_SIZE, display).apply();
58 }
Steve McKay7776aa52016-01-25 19:00:22 -080059
60 public static void setViewMode(Context context, RootInfo root, @ViewMode int viewMode) {
Steve McKay0af8afd2016-02-25 13:34:03 -080061 assert(viewMode != MODE_UNKNOWN);
62
Steve McKay7776aa52016-01-25 19:00:22 -080063 PreferenceManager.getDefaultSharedPreferences(context).edit()
64 .putInt(createKey(root), viewMode).apply();
65 }
66
67 private static String createKey(RootInfo root) {
68 return ROOT_VIEW_MODE_PREFIX + root.authority + root.rootId;
69 }
Jeff Sharkeye8d13ea2014-08-08 15:10:03 -070070}