From c336f2d46e7318e00d25ebd26d13dfec3026fd67 Mon Sep 17 00:00:00 2001 From: Candice Lo Date: Sat, 4 Feb 2023 08:53:00 +0000 Subject: [PATCH] Implement Font Scaling Quick Settings Tile (2/n) Font scaling quick settings tile provides a quick access for users to change the Font Size in quick settings panel. In this modification, we create the FontScalingTile and set the icon and title for the tile. Only the appearance of the tile is set. Disabling the tile with setting isAvailable to false. Bug: 242326166 Test: Attach a video to the bug Test: atest TilesStatesTextTest QSTileViewImplTest QSFactoryImplTest Change-Id: I5d4d3ddc97eb1db90db48f23e362136b002d4b2d --- .../res/drawable/ic_qs_font_scaling.xml | 25 ++++++ packages/SystemUI/res/values/config.xml | 2 +- packages/SystemUI/res/values/strings.xml | 2 + .../res/values/tiles_states_strings.xml | 10 +++ .../systemui/qs/tileimpl/QSFactoryImpl.java | 8 +- .../systemui/qs/tileimpl/QSTileViewImpl.kt | 3 +- .../systemui/qs/tiles/FontScalingTile.kt | 83 +++++++++++++++++++ .../systemui/qs/tileimpl/QSFactoryImplTest.kt | 8 +- 8 files changed, 136 insertions(+), 5 deletions(-) create mode 100644 packages/SystemUI/res/drawable/ic_qs_font_scaling.xml create mode 100644 packages/SystemUI/src/com/android/systemui/qs/tiles/FontScalingTile.kt diff --git a/packages/SystemUI/res/drawable/ic_qs_font_scaling.xml b/packages/SystemUI/res/drawable/ic_qs_font_scaling.xml new file mode 100644 index 0000000000000..d5b4c9ed5a87a --- /dev/null +++ b/packages/SystemUI/res/drawable/ic_qs_font_scaling.xml @@ -0,0 +1,25 @@ + + + + + \ No newline at end of file diff --git a/packages/SystemUI/res/values/config.xml b/packages/SystemUI/res/values/config.xml index 371f00189ad61..7eb98dc261a45 100644 --- a/packages/SystemUI/res/values/config.xml +++ b/packages/SystemUI/res/values/config.xml @@ -81,7 +81,7 @@ - internet,bt,flashlight,dnd,alarm,airplane,controls,wallet,rotation,battery,cast,screenrecord,mictoggle,cameratoggle,location,hotspot,inversion,saver,dark,work,night,reverse,reduce_brightness,qr_code_scanner,onehanded,color_correction,dream + internet,bt,flashlight,dnd,alarm,airplane,controls,wallet,rotation,battery,cast,screenrecord,mictoggle,cameratoggle,location,hotspot,inversion,saver,dark,work,night,reverse,reduce_brightness,qr_code_scanner,onehanded,color_correction,dream,font_scaling diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml index 7d5b66e9cbab9..61a46f7bdfbdc 100644 --- a/packages/SystemUI/res/values/strings.xml +++ b/packages/SystemUI/res/values/strings.xml @@ -660,6 +660,8 @@ Color inversion Color correction + + Font size Manage users diff --git a/packages/SystemUI/res/values/tiles_states_strings.xml b/packages/SystemUI/res/values/tiles_states_strings.xml index c8095510e2c2a..7020d548f6b07 100644 --- a/packages/SystemUI/res/values/tiles_states_strings.xml +++ b/packages/SystemUI/res/values/tiles_states_strings.xml @@ -318,4 +318,14 @@ Off On + + + + Unavailable + Off + On + \ No newline at end of file diff --git a/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSFactoryImpl.java b/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSFactoryImpl.java index 24a4f60b7c007..dec6e7d93fa25 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSFactoryImpl.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSFactoryImpl.java @@ -40,6 +40,7 @@ import com.android.systemui.qs.tiles.DeviceControlsTile; import com.android.systemui.qs.tiles.DndTile; import com.android.systemui.qs.tiles.DreamTile; import com.android.systemui.qs.tiles.FlashlightTile; +import com.android.systemui.qs.tiles.FontScalingTile; import com.android.systemui.qs.tiles.HotspotTile; import com.android.systemui.qs.tiles.InternetTile; import com.android.systemui.qs.tiles.LocationTile; @@ -94,6 +95,7 @@ public class QSFactoryImpl implements QSFactory { private final Provider mQRCodeScannerTileProvider; private final Provider mOneHandedModeTileProvider; private final Provider mDreamTileProvider; + private final Provider mFontScalingTileProvider; private final Lazy mQsHostLazy; private final Provider mCustomTileBuilderProvider; @@ -129,7 +131,8 @@ public class QSFactoryImpl implements QSFactory { Provider qrCodeScannerTileProvider, Provider oneHandedModeTileProvider, Provider colorCorrectionTileProvider, - Provider dreamTileProvider) { + Provider dreamTileProvider, + Provider fontScalingTileProvider) { mQsHostLazy = qsHostLazy; mCustomTileBuilderProvider = customTileBuilderProvider; @@ -161,6 +164,7 @@ public class QSFactoryImpl implements QSFactory { mOneHandedModeTileProvider = oneHandedModeTileProvider; mColorCorrectionTileProvider = colorCorrectionTileProvider; mDreamTileProvider = dreamTileProvider; + mFontScalingTileProvider = fontScalingTileProvider; } /** Creates a tile with a type based on {@code tileSpec} */ @@ -232,6 +236,8 @@ public class QSFactoryImpl implements QSFactory { return mColorCorrectionTileProvider.get(); case "dream": return mDreamTileProvider.get(); + case "font_scaling": + return mFontScalingTileProvider.get(); } // Custom tiles diff --git a/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileViewImpl.kt b/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileViewImpl.kt index 29d7fb02e6139..d0b04c93bba0b 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileViewImpl.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileViewImpl.kt @@ -694,7 +694,8 @@ internal object SubtitleArrayMapping { "alarm" to R.array.tile_states_alarm, "onehanded" to R.array.tile_states_onehanded, "color_correction" to R.array.tile_states_color_correction, - "dream" to R.array.tile_states_dream + "dream" to R.array.tile_states_dream, + "font_scaling" to R.array.tile_states_font_scaling ) fun getSubtitleId(spec: String?): Int { diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/FontScalingTile.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/FontScalingTile.kt new file mode 100644 index 0000000000000..4d8f89edd969e --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/FontScalingTile.kt @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.systemui.qs.tiles + +import android.content.Intent +import android.os.Handler +import android.os.Looper +import android.view.View +import com.android.internal.logging.MetricsLogger +import com.android.systemui.R +import com.android.systemui.dagger.qualifiers.Background +import com.android.systemui.dagger.qualifiers.Main +import com.android.systemui.plugins.ActivityStarter +import com.android.systemui.plugins.FalsingManager +import com.android.systemui.plugins.qs.QSTile +import com.android.systemui.plugins.statusbar.StatusBarStateController +import com.android.systemui.qs.QSHost +import com.android.systemui.qs.logging.QSLogger +import com.android.systemui.qs.tileimpl.QSTileImpl +import javax.inject.Inject + +class FontScalingTile +@Inject +constructor( + host: QSHost, + @Background backgroundLooper: Looper, + @Main mainHandler: Handler, + falsingManager: FalsingManager, + metricsLogger: MetricsLogger, + statusBarStateController: StatusBarStateController, + activityStarter: ActivityStarter, + qsLogger: QSLogger +) : + QSTileImpl( + host, + backgroundLooper, + mainHandler, + falsingManager, + metricsLogger, + statusBarStateController, + activityStarter, + qsLogger + ) { + private val mIcon = ResourceIcon.get(R.drawable.ic_qs_font_scaling) + + override fun isAvailable(): Boolean { + return false + } + + override fun newTileState(): QSTile.State { + val state = QSTile.State() + state.handlesLongClick = false + return state + } + + override fun handleClick(view: View?) {} + + override fun handleUpdateState(state: QSTile.State?, arg: Any?) { + state?.label = mContext.getString(R.string.quick_settings_font_scaling_label) + state?.icon = mIcon + } + + override fun getLongClickIntent(): Intent? { + return null + } + + override fun getTileLabel(): CharSequence { + return mContext.getString(R.string.quick_settings_font_scaling_label) + } +} diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/tileimpl/QSFactoryImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/qs/tileimpl/QSFactoryImplTest.kt index 3281fa9bd8a41..4635b4843a913 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/qs/tileimpl/QSFactoryImplTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/qs/tileimpl/QSFactoryImplTest.kt @@ -35,6 +35,7 @@ import com.android.systemui.qs.tiles.DeviceControlsTile import com.android.systemui.qs.tiles.DndTile import com.android.systemui.qs.tiles.DreamTile import com.android.systemui.qs.tiles.FlashlightTile +import com.android.systemui.qs.tiles.FontScalingTile import com.android.systemui.qs.tiles.HotspotTile import com.android.systemui.qs.tiles.InternetTile import com.android.systemui.qs.tiles.LocationTile @@ -87,7 +88,8 @@ private val specMap = mapOf( "qr_code_scanner" to QRCodeScannerTile::class.java, "onehanded" to OneHandedModeTile::class.java, "color_correction" to ColorCorrectionTile::class.java, - "dream" to DreamTile::class.java + "dream" to DreamTile::class.java, + "font_scaling" to FontScalingTile::class.java ) @RunWith(AndroidTestingRunner::class) @@ -126,6 +128,7 @@ class QSFactoryImplTest : SysuiTestCase() { @Mock private lateinit var oneHandedModeTile: OneHandedModeTile @Mock private lateinit var colorCorrectionTile: ColorCorrectionTile @Mock private lateinit var dreamTile: DreamTile + @Mock private lateinit var fontScalingTile: FontScalingTile private lateinit var factory: QSFactoryImpl @@ -167,7 +170,8 @@ class QSFactoryImplTest : SysuiTestCase() { { qrCodeScannerTile }, { oneHandedModeTile }, { colorCorrectionTile }, - { dreamTile } + { dreamTile }, + { fontScalingTile } ) // When adding/removing tiles, fix also [specMap] }