Jeff Sharkey | e8d13ea | 2014-08-08 15:10:03 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.documentsui; |
| 18 | |
Steve McKay | 7776aa5 | 2016-01-25 19:00:22 -0800 | [diff] [blame] | 19 | import static com.android.documentsui.State.MODE_UNKNOWN; |
Steve McKay | 7776aa5 | 2016-01-25 19:00:22 -0800 | [diff] [blame] | 20 | |
Jeff Sharkey | e8d13ea | 2014-08-08 15:10:03 -0700 | [diff] [blame] | 21 | import android.content.Context; |
| 22 | import android.preference.PreferenceManager; |
| 23 | |
Steve McKay | 7776aa5 | 2016-01-25 19:00:22 -0800 | [diff] [blame] | 24 | import com.android.documentsui.State.ViewMode; |
| 25 | import com.android.documentsui.model.RootInfo; |
| 26 | |
Jeff Sharkey | e8d13ea | 2014-08-08 15:10:03 -0700 | [diff] [blame] | 27 | public class LocalPreferences { |
| 28 | private static final String KEY_ADVANCED_DEVICES = "advancedDevices"; |
| 29 | private static final String KEY_FILE_SIZE = "fileSize"; |
Steve McKay | 7776aa5 | 2016-01-25 19:00:22 -0800 | [diff] [blame] | 30 | private static final String ROOT_VIEW_MODE_PREFIX = "rootViewMode-"; |
Jeff Sharkey | e8d13ea | 2014-08-08 15:10:03 -0700 | [diff] [blame] | 31 | |
| 32 | public static boolean getDisplayAdvancedDevices(Context context) { |
Jeff Sharkey | ff7ab97 | 2015-12-03 20:12:45 -0700 | [diff] [blame] | 33 | boolean defaultAdvanced = context.getResources() |
| 34 | .getBoolean(R.bool.config_defaultAdvancedDevices); |
Jeff Sharkey | e8d13ea | 2014-08-08 15:10:03 -0700 | [diff] [blame] | 35 | return PreferenceManager.getDefaultSharedPreferences(context) |
Jeff Sharkey | ff7ab97 | 2015-12-03 20:12:45 -0700 | [diff] [blame] | 36 | .getBoolean(KEY_ADVANCED_DEVICES, defaultAdvanced); |
Jeff Sharkey | e8d13ea | 2014-08-08 15:10:03 -0700 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | public static boolean getDisplayFileSize(Context context) { |
| 40 | return PreferenceManager.getDefaultSharedPreferences(context) |
| 41 | .getBoolean(KEY_FILE_SIZE, false); |
| 42 | } |
| 43 | |
Steve McKay | 7776aa5 | 2016-01-25 19:00:22 -0800 | [diff] [blame] | 44 | 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 Sharkey | e8d13ea | 2014-08-08 15:10:03 -0700 | [diff] [blame] | 50 | 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 McKay | 7776aa5 | 2016-01-25 19:00:22 -0800 | [diff] [blame] | 59 | |
| 60 | public static void setViewMode(Context context, RootInfo root, @ViewMode int viewMode) { |
Steve McKay | 0af8afd | 2016-02-25 13:34:03 -0800 | [diff] [blame] | 61 | assert(viewMode != MODE_UNKNOWN); |
| 62 | |
Steve McKay | 7776aa5 | 2016-01-25 19:00:22 -0800 | [diff] [blame] | 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 Sharkey | e8d13ea | 2014-08-08 15:10:03 -0700 | [diff] [blame] | 70 | } |