1 /* 2 * Copyright (C) 2025 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.settings.connecteddevice.display 18 19 import android.content.Context 20 import android.provider.Settings 21 22 import androidx.preference.SwitchPreferenceCompat 23 24 import com.android.settings.R 25 26 const val MIRROR_SETTING = Settings.Secure.MIRROR_BUILT_IN_DISPLAY 27 28 /** 29 * A switch preference which is backed by the MIRROR_BUILT_IN_DISPLAY global setting. 30 */ 31 class MirrorPreference(context: Context, val contentModeEnabled: Boolean): 32 SwitchPreferenceCompat(context) { onAttachednull33 override fun onAttached() { 34 super.onAttached() 35 36 isEnabled = contentModeEnabled 37 if (contentModeEnabled) { 38 setChecked(0 != Settings.Secure.getInt(context.contentResolver, MIRROR_SETTING, 0)) 39 } else { 40 setChecked(0 == Settings.Global.getInt( 41 context.contentResolver, 42 Settings.Global.DEVELOPMENT_FORCE_DESKTOP_MODE_ON_EXTERNAL_DISPLAYS, 0)) 43 } 44 } 45 onClicknull46 override fun onClick() { 47 super.onClick() 48 49 if (contentModeEnabled) { 50 Settings.Secure.putInt( 51 context.contentResolver, MIRROR_SETTING, if (isChecked()) 1 else 0) 52 } 53 } 54 } 55