blob: 4bffc49e5ac0110ad7322947851a8c1bb7e8de40 [file] [log] [blame]
Jeff Sharkey669f8e72014-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 McKay3eb2d072016-01-25 19:00:22 -080019import static com.android.documentsui.State.MODE_UNKNOWN;
20import static com.android.internal.util.Preconditions.checkArgument;
21
Jeff Sharkey669f8e72014-08-08 15:10:03 -070022import android.content.Context;
23import android.preference.PreferenceManager;
24
Steve McKay3eb2d072016-01-25 19:00:22 -080025import com.android.documentsui.State.ViewMode;
26import com.android.documentsui.model.RootInfo;
27
Jeff Sharkey669f8e72014-08-08 15:10:03 -070028public class LocalPreferences {
29 private static final String KEY_ADVANCED_DEVICES = "advancedDevices";
30 private static final String KEY_FILE_SIZE = "fileSize";
Steve McKay3eb2d072016-01-25 19:00:22 -080031 private static final String ROOT_VIEW_MODE_PREFIX = "rootViewMode-";
Jeff Sharkey669f8e72014-08-08 15:10:03 -070032
33 public static boolean getDisplayAdvancedDevices(Context context) {
Jeff Sharkeya1fbe282015-12-03 20:12:45 -070034 boolean defaultAdvanced = context.getResources()
35 .getBoolean(R.bool.config_defaultAdvancedDevices);
Jeff Sharkey669f8e72014-08-08 15:10:03 -070036 return PreferenceManager.getDefaultSharedPreferences(context)
Jeff Sharkeya1fbe282015-12-03 20:12:45 -070037 .getBoolean(KEY_ADVANCED_DEVICES, defaultAdvanced);
Jeff Sharkey669f8e72014-08-08 15:10:03 -070038 }
39
40 public static boolean getDisplayFileSize(Context context) {
41 return PreferenceManager.getDefaultSharedPreferences(context)
42 .getBoolean(KEY_FILE_SIZE, false);
43 }
44
Steve McKay3eb2d072016-01-25 19:00:22 -080045 public static @ViewMode int getViewMode(
46 Context context, RootInfo root, @ViewMode int fallback) {
47 return PreferenceManager.getDefaultSharedPreferences(context)
48 .getInt(createKey(root), fallback);
49 }
50
Jeff Sharkey669f8e72014-08-08 15:10:03 -070051 public static void setDisplayAdvancedDevices(Context context, boolean display) {
52 PreferenceManager.getDefaultSharedPreferences(context).edit()
53 .putBoolean(KEY_ADVANCED_DEVICES, display).apply();
54 }
55
56 public static void setDisplayFileSize(Context context, boolean display) {
57 PreferenceManager.getDefaultSharedPreferences(context).edit()
58 .putBoolean(KEY_FILE_SIZE, display).apply();
59 }
Steve McKay3eb2d072016-01-25 19:00:22 -080060
61 public static void setViewMode(Context context, RootInfo root, @ViewMode int viewMode) {
62 checkArgument(viewMode != MODE_UNKNOWN);
63 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 Sharkey669f8e72014-08-08 15:10:03 -070070}