48 lines
1.4 KiB
Java
48 lines
1.4 KiB
Java
/*
|
|
* SPDX-FileCopyrightText: 2021 The LineageOS Project
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
package lineageos.preference;
|
|
|
|
import android.content.Context;
|
|
import android.util.AttributeSet;
|
|
|
|
import androidx.preference.PreferenceDataStore;
|
|
|
|
import com.android.settingslib.widget.MainSwitchPreference;
|
|
|
|
import lineageos.providers.LineageSettings;
|
|
|
|
public class LineageGlobalSettingMainSwitchPreference extends MainSwitchPreference {
|
|
|
|
public LineageGlobalSettingMainSwitchPreference(Context context, AttributeSet attrs,
|
|
int defStyle) {
|
|
super(context, attrs, defStyle);
|
|
setPreferenceDataStore(new DataStore());
|
|
}
|
|
|
|
public LineageGlobalSettingMainSwitchPreference(Context context, AttributeSet attrs) {
|
|
super(context, attrs);
|
|
setPreferenceDataStore(new DataStore());
|
|
}
|
|
|
|
public LineageGlobalSettingMainSwitchPreference(Context context) {
|
|
super(context);
|
|
setPreferenceDataStore(new DataStore());
|
|
}
|
|
|
|
private class DataStore extends PreferenceDataStore {
|
|
@Override
|
|
public void putBoolean(String key, boolean value) {
|
|
LineageSettings.Global.putInt(getContext().getContentResolver(), key, value ? 1 : 0);
|
|
}
|
|
|
|
@Override
|
|
public boolean getBoolean(String key, boolean defaultValue) {
|
|
return LineageSettings.Global.getInt(getContext().getContentResolver(), key,
|
|
defaultValue ? 1 : 0) != 0;
|
|
}
|
|
}
|
|
}
|