Jeff Sharkey | 669f8e7 | 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 | 3eb2d07 | 2016-01-25 19:00:22 -0800 | [diff] [blame] | 19 | import static com.android.documentsui.State.MODE_UNKNOWN; |
| 20 | import static com.android.internal.util.Preconditions.checkArgument; |
| 21 | |
Jeff Sharkey | 669f8e7 | 2014-08-08 15:10:03 -0700 | [diff] [blame] | 22 | import android.content.Context; |
| 23 | import android.preference.PreferenceManager; |
| 24 | |
Steve McKay | 3eb2d07 | 2016-01-25 19:00:22 -0800 | [diff] [blame] | 25 | import com.android.documentsui.State.ViewMode; |
| 26 | import com.android.documentsui.model.RootInfo; |
| 27 | |
Jeff Sharkey | 669f8e7 | 2014-08-08 15:10:03 -0700 | [diff] [blame] | 28 | public class LocalPreferences { |
| 29 | private static final String KEY_ADVANCED_DEVICES = "advancedDevices"; |
| 30 | private static final String KEY_FILE_SIZE = "fileSize"; |
Steve McKay | 3eb2d07 | 2016-01-25 19:00:22 -0800 | [diff] [blame] | 31 | private static final String ROOT_VIEW_MODE_PREFIX = "rootViewMode-"; |
Jeff Sharkey | 669f8e7 | 2014-08-08 15:10:03 -0700 | [diff] [blame] | 32 | |
| 33 | public static boolean getDisplayAdvancedDevices(Context context) { |
Jeff Sharkey | a1fbe28 | 2015-12-03 20:12:45 -0700 | [diff] [blame] | 34 | boolean defaultAdvanced = context.getResources() |
| 35 | .getBoolean(R.bool.config_defaultAdvancedDevices); |
Jeff Sharkey | 669f8e7 | 2014-08-08 15:10:03 -0700 | [diff] [blame] | 36 | return PreferenceManager.getDefaultSharedPreferences(context) |
Jeff Sharkey | a1fbe28 | 2015-12-03 20:12:45 -0700 | [diff] [blame] | 37 | .getBoolean(KEY_ADVANCED_DEVICES, defaultAdvanced); |
Jeff Sharkey | 669f8e7 | 2014-08-08 15:10:03 -0700 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | public static boolean getDisplayFileSize(Context context) { |
| 41 | return PreferenceManager.getDefaultSharedPreferences(context) |
| 42 | .getBoolean(KEY_FILE_SIZE, false); |
| 43 | } |
| 44 | |
Steve McKay | 3eb2d07 | 2016-01-25 19:00:22 -0800 | [diff] [blame] | 45 | 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 Sharkey | 669f8e7 | 2014-08-08 15:10:03 -0700 | [diff] [blame] | 51 | 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 McKay | 3eb2d07 | 2016-01-25 19:00:22 -0800 | [diff] [blame] | 60 | |
| 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 Sharkey | 669f8e7 | 2014-08-08 15:10:03 -0700 | [diff] [blame] | 70 | } |