blob: e933ad05caa0b4584d7168d32d222b20c725095f [file] [log] [blame]
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.documentsui.base;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
public interface ScopedPreferences {
boolean getShowDeviceRoot();
void setShowDeviceRoot(boolean display);
public static ScopedPreferences create(Context context, String scope) {
return new RuntimeScopedPreferences(
PreferenceManager.getDefaultSharedPreferences(context), scope);
}
static final class RuntimeScopedPreferences implements ScopedPreferences {
private static final String INCLUDE_DEVICE_ROOT = "includeDeviceRoot-";
private SharedPreferences mSharedPrefs;
private String mScope;
private RuntimeScopedPreferences(SharedPreferences sharedPrefs, String scope) {
mSharedPrefs = sharedPrefs;
mScope = scope;
}
@Override
public boolean getShowDeviceRoot() {
return mSharedPrefs.getBoolean(INCLUDE_DEVICE_ROOT + mScope, false);
}
@Override
public void setShowDeviceRoot(boolean display) {
mSharedPrefs.edit().putBoolean(INCLUDE_DEVICE_ROOT + mScope, display).apply();
}
}
}