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.provider.Settings 22 import com.android.internal.jank.InteractionJankMonitor 23 import com.android.internal.logging.MetricsLogger 24 import com.android.systemui.accessibility.fontscaling.FontScalingDialogDelegate 25 import com.android.systemui.animation.DialogCuj 26 import com.android.systemui.animation.DialogTransitionAnimator 27 import com.android.systemui.animation.Expandable 28 import com.android.systemui.dagger.qualifiers.Background 29 import com.android.systemui.dagger.qualifiers.Main 30 import com.android.systemui.plugins.ActivityStarter 31 import com.android.systemui.plugins.FalsingManager 32 import com.android.systemui.plugins.qs.QSTile 33 import com.android.systemui.plugins.statusbar.StatusBarStateController 34 import com.android.systemui.qs.QSHost 35 import com.android.systemui.qs.QsEventLogger 36 import com.android.systemui.qs.logging.QSLogger 37 import com.android.systemui.qs.tileimpl.QSTileImpl 38 import com.android.systemui.res.R 39 import com.android.systemui.statusbar.phone.SystemUIDialog 40 import com.android.systemui.statusbar.policy.KeyguardStateController 41 import javax.inject.Inject 42 import javax.inject.Provider 43 44 class FontScalingTile 45 @Inject 46 constructor( 47 host: QSHost, 48 uiEventLogger: QsEventLogger, 49 @Background backgroundLooper: Looper, 50 @Main private val mainHandler: Handler, 51 falsingManager: FalsingManager, 52 metricsLogger: MetricsLogger, 53 statusBarStateController: StatusBarStateController, 54 activityStarter: ActivityStarter, 55 qsLogger: QSLogger, 56 private val keyguardStateController: KeyguardStateController, 57 private val dialogTransitionAnimator: DialogTransitionAnimator, 58 private val fontScalingDialogDelegateProvider: Provider<FontScalingDialogDelegate> 59 ) : 60 QSTileImpl<QSTile.State?>( 61 host, 62 uiEventLogger, 63 backgroundLooper, 64 mainHandler, 65 falsingManager, 66 metricsLogger, 67 statusBarStateController, 68 activityStarter, 69 qsLogger 70 ) { 71 private val icon = ResourceIcon.get(R.drawable.ic_qs_font_scaling) 72 newTileStatenull73 override fun newTileState(): QSTile.State { 74 return QSTile.State() 75 } 76 handleClicknull77 override fun handleClick(expandable: Expandable?) { 78 // We animate from the touched view only if we are not on the keyguard 79 val animateFromExpandable: Boolean = 80 expandable != null && !keyguardStateController.isShowing 81 82 val runnable = Runnable { 83 val dialog: SystemUIDialog = fontScalingDialogDelegateProvider.get().createDialog() 84 if (animateFromExpandable) { 85 val controller = 86 expandable?.dialogTransitionController( 87 DialogCuj( 88 InteractionJankMonitor.CUJ_SHADE_DIALOG_OPEN, 89 INTERACTION_JANK_TAG 90 ) 91 ) 92 controller?.let { dialogTransitionAnimator.show(dialog, controller) } 93 ?: dialog.show() 94 } else { 95 dialog.show() 96 } 97 } 98 99 mainHandler.post { 100 mActivityStarter.executeRunnableDismissingKeyguard( 101 runnable, 102 /* cancelAction= */ null, 103 /* dismissShade= */ true, 104 /* afterKeyguardGone= */ true, 105 /* deferred= */ false 106 ) 107 } 108 } 109 handleUpdateStatenull110 override fun handleUpdateState(state: QSTile.State?, arg: Any?) { 111 state?.label = mContext.getString(R.string.quick_settings_font_scaling_label) 112 state?.icon = icon 113 } 114 getLongClickIntentnull115 override fun getLongClickIntent(): Intent? { 116 return Intent(Settings.ACTION_TEXT_READING_SETTINGS) 117 } 118 getTileLabelnull119 override fun getTileLabel(): CharSequence { 120 return mContext.getString(R.string.quick_settings_font_scaling_label) 121 } 122 123 companion object { 124 const val TILE_SPEC = "font_scaling" 125 private const val INTERACTION_JANK_TAG = "font_scaling" 126 } 127 } 128