1 /* 2 * Copyright (C) 2024 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.settingslib.metadata 18 19 import android.content.Context 20 import androidx.annotation.StringRes 21 22 /** A persistent preference that has a boolean value. */ 23 interface BooleanValuePreference : PersistentPreference<Boolean> { 24 override val valueType: Class<Boolean> 25 get() = Boolean::class.javaObjectType 26 } 27 28 /** A persistent preference that has a float value. */ 29 interface FloatValuePreference : PersistentPreference<Float> { 30 override val valueType: Class<Float> 31 get() = Float::class.javaObjectType 32 } 33 34 /** A persistent preference that has a int value between a range. */ 35 interface IntRangeValuePreference : PersistentPreference<Int>, ValueDescriptor { 36 override val valueType: Class<Int> 37 get() = Int::class.javaObjectType 38 39 /** The lower bound (inclusive) of the range. */ getMinValuenull40 fun getMinValue(context: Context): Int 41 42 /** The upper bound (inclusive) of the range. */ 43 fun getMaxValue(context: Context): Int 44 45 /** The increment step within the range. 0 means unset, which implies step size is 1. */ 46 fun getIncrementStep(context: Context) = 0 47 48 override fun isValidValue(context: Context, index: Int) = 49 index in getMinValue(context)..getMaxValue(context) 50 } 51 52 /** A preference that provides a two-state toggleable option. */ 53 open class SwitchPreference 54 @JvmOverloads 55 constructor( 56 override val key: String, 57 @StringRes override val title: Int = 0, 58 @StringRes override val summary: Int = 0, 59 ) : BooleanValuePreference 60 61 /** A preference that provides a two-state toggleable option that can be used as a main switch. */ 62 open class MainSwitchPreference 63 @JvmOverloads 64 constructor(override val key: String, @StringRes override val title: Int = 0) : 65 BooleanValuePreference 66