• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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.systemui.qs.tiles
17 
18 import android.content.Intent
19 import android.os.Handler
20 import android.os.Looper
21 import android.view.View
22 import com.android.internal.jank.InteractionJankMonitor
23 import com.android.internal.logging.MetricsLogger
24 import com.android.systemui.R
25 import com.android.systemui.accessibility.fontscaling.FontScalingDialog
26 import com.android.systemui.animation.DialogCuj
27 import com.android.systemui.animation.DialogLaunchAnimator
28 import com.android.systemui.dagger.qualifiers.Background
29 import com.android.systemui.dagger.qualifiers.Main
30 import com.android.systemui.flags.FeatureFlags
31 import com.android.systemui.flags.Flags
32 import com.android.systemui.plugins.ActivityStarter
33 import com.android.systemui.plugins.FalsingManager
34 import com.android.systemui.plugins.qs.QSTile
35 import com.android.systemui.plugins.statusbar.StatusBarStateController
36 import com.android.systemui.qs.QSHost
37 import com.android.systemui.qs.logging.QSLogger
38 import com.android.systemui.qs.tileimpl.QSTileImpl
39 import com.android.systemui.statusbar.phone.SystemUIDialog
40 import com.android.systemui.util.settings.SystemSettings
41 import javax.inject.Inject
42 
43 class FontScalingTile
44 @Inject
45 constructor(
46     host: QSHost,
47     @Background backgroundLooper: Looper,
48     @Main mainHandler: Handler,
49     falsingManager: FalsingManager,
50     metricsLogger: MetricsLogger,
51     statusBarStateController: StatusBarStateController,
52     activityStarter: ActivityStarter,
53     qsLogger: QSLogger,
54     private val dialogLaunchAnimator: DialogLaunchAnimator,
55     private val systemSettings: SystemSettings,
56     private val featureFlags: FeatureFlags
57 ) :
58     QSTileImpl<QSTile.State?>(
59         host,
60         backgroundLooper,
61         mainHandler,
62         falsingManager,
63         metricsLogger,
64         statusBarStateController,
65         activityStarter,
66         qsLogger
67     ) {
68     private val icon = ResourceIcon.get(R.drawable.ic_qs_font_scaling)
69 
isAvailablenull70     override fun isAvailable(): Boolean {
71         return featureFlags.isEnabled(Flags.ENABLE_FONT_SCALING_TILE)
72     }
73 
newTileStatenull74     override fun newTileState(): QSTile.State {
75         val state = QSTile.State()
76         state.handlesLongClick = false
77         return state
78     }
79 
handleClicknull80     override fun handleClick(view: View?) {
81         mUiHandler.post {
82             val dialog: SystemUIDialog = FontScalingDialog(mContext, systemSettings)
83             if (view != null) {
84                 dialogLaunchAnimator.showFromView(
85                     dialog,
86                     view,
87                     DialogCuj(InteractionJankMonitor.CUJ_SHADE_DIALOG_OPEN, INTERACTION_JANK_TAG)
88                 )
89             } else {
90                 dialog.show()
91             }
92         }
93     }
94 
handleUpdateStatenull95     override fun handleUpdateState(state: QSTile.State?, arg: Any?) {
96         state?.label = mContext.getString(R.string.quick_settings_font_scaling_label)
97         state?.icon = icon
98     }
99 
getLongClickIntentnull100     override fun getLongClickIntent(): Intent? {
101         return null
102     }
103 
getTileLabelnull104     override fun getTileLabel(): CharSequence {
105         return mContext.getString(R.string.quick_settings_font_scaling_label)
106     }
107 
108     companion object {
109         const val TILE_SPEC = "font_scaling"
110         private const val INTERACTION_JANK_TAG = "font_scaling"
111     }
112 }
113