• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package com.android.settings.accessibility
17 
18 import android.content.Context
19 import android.os.Bundle
20 import android.os.Parcelable
21 import android.util.AttributeSet
22 import com.android.settings.widget.LabeledSeekBarPreference
23 
24 /**
25  * Add a custom AccessibilitySeekBarPreference with tool tip window for font size and display size.
26  */
27 open class AccessibilitySeekBarPreference(context: Context, attrs: AttributeSet?) :
28     LabeledSeekBarPreference(context, attrs) {
29 
30     var needsQSTooltipReshow = false
31     private var tooltipWindow: AccessibilityQuickSettingsTooltipWindow? = null
32 
onSaveInstanceStatenull33     override fun onSaveInstanceState(): Parcelable {
34         val state = Bundle()
35         state.putParcelable(null, super.onSaveInstanceState())
36         if (needsQSTooltipReshow || tooltipWindow?.isShowing == true) {
37             state.putBoolean(KEY_SAVED_QS_TOOLTIP_RESHOW, /* value= */ true)
38         }
39         return state
40     }
41 
onRestoreInstanceStatenull42     override fun onRestoreInstanceState(state: Parcelable?) {
43         val bundle = state as Bundle
44         super.onRestoreInstanceState(bundle.getParcelable(null, Parcelable::class.java))
45         if (bundle.containsKey(KEY_SAVED_QS_TOOLTIP_RESHOW)) {
46             needsQSTooltipReshow = bundle.getBoolean(KEY_SAVED_QS_TOOLTIP_RESHOW)
47         }
48     }
49 
50     /** To generate a tooltip window and return it. */
createTooltipWindownull51     fun createTooltipWindow(): AccessibilityQuickSettingsTooltipWindow =
52         AccessibilityQuickSettingsTooltipWindow(context).also { tooltipWindow = it }
53 
54     /** To dismiss the tooltip window. */
dismissTooltipnull55     fun dismissTooltip() {
56         val tooltip = tooltipWindow
57         if (tooltip?.isShowing == true) {
58             tooltip.dismiss()
59             tooltipWindow = null
60         }
61     }
62 
63     companion object {
64         private const val KEY_SAVED_QS_TOOLTIP_RESHOW = "qs_tooltip_reshow"
65     }
66 }
67