Merge "Implement Font Scaling Quick Settings Tile (4/n)" into tm-qpr-dev am: c0e6f4e8d7

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/21336878

Change-Id: Ia93ce282085bf45db533a8014c7309b488e74a89
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Candice Lo
2023-02-14 09:26:42 +00:00
committed by Automerger Merge Worker
5 changed files with 193 additions and 4 deletions

View File

@@ -16,13 +16,32 @@
package com.android.systemui.accessibility.fontscaling
import android.content.Context
import android.content.pm.ActivityInfo
import android.content.res.Configuration
import android.os.Bundle
import android.provider.Settings
import android.view.LayoutInflater
import android.widget.Button
import android.widget.SeekBar
import android.widget.SeekBar.OnSeekBarChangeListener
import android.widget.TextView
import com.android.systemui.R
import com.android.systemui.common.ui.view.SeekBarWithIconButtonsView
import com.android.systemui.statusbar.phone.SystemUIDialog
import com.android.systemui.util.settings.SystemSettings
/** The Dialog that contains a seekbar for changing the font size. */
class FontScalingDialog(context: Context) : SystemUIDialog(context) {
class FontScalingDialog(context: Context, private val systemSettings: SystemSettings) :
SystemUIDialog(context) {
private val strEntryValues: Array<String> =
context.resources.getStringArray(com.android.settingslib.R.array.entryvalues_font_size)
private lateinit var title: TextView
private lateinit var doneButton: Button
private lateinit var seekBarWithIconButtonsView: SeekBarWithIconButtonsView
private val configuration: Configuration =
Configuration(context.getResources().getConfiguration())
override fun onCreate(savedInstanceState: Bundle?) {
setTitle(R.string.font_scaling_dialog_title)
setView(LayoutInflater.from(context).inflate(R.layout.font_scaling_dialog, null))
@@ -32,5 +51,57 @@ class FontScalingDialog(context: Context) : SystemUIDialog(context) {
/* dismissOnClick = */ true
)
super.onCreate(savedInstanceState)
title = requireViewById(com.android.internal.R.id.alertTitle)
doneButton = requireViewById(com.android.internal.R.id.button1)
seekBarWithIconButtonsView = requireViewById(R.id.font_scaling_slider)
seekBarWithIconButtonsView.setMax((strEntryValues).size - 1)
val currentScale = systemSettings.getFloat(Settings.System.FONT_SCALE, 1.0f)
seekBarWithIconButtonsView.setProgress(fontSizeValueToIndex(currentScale))
seekBarWithIconButtonsView.setOnSeekBarChangeListener(
object : OnSeekBarChangeListener {
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
systemSettings.putString(Settings.System.FONT_SCALE, strEntryValues[progress])
}
override fun onStartTrackingTouch(seekBar: SeekBar) {
// Do nothing
}
override fun onStopTrackingTouch(seekBar: SeekBar) {
// Do nothing
}
}
)
doneButton.setOnClickListener { dismiss() }
}
private fun fontSizeValueToIndex(value: Float): Int {
var lastValue = strEntryValues[0].toFloat()
for (i in 1 until strEntryValues.size) {
val thisValue = strEntryValues[i].toFloat()
if (value < lastValue + (thisValue - lastValue) * .5f) {
return i - 1
}
lastValue = thisValue
}
return strEntryValues.size - 1
}
override fun onConfigurationChanged(configuration: Configuration) {
super.onConfigurationChanged(configuration)
val configDiff = configuration.diff(this.configuration)
this.configuration.setTo(configuration)
if (configDiff and ActivityInfo.CONFIG_FONT_SCALE != 0) {
title.post {
title.setTextAppearance(R.style.TextAppearance_Dialog_Title)
doneButton.setTextAppearance(R.style.Widget_Dialog_Button)
}
}
}
}

View File

@@ -152,6 +152,13 @@ public class SeekBarWithIconButtonsView extends LinearLayout {
setIconViewAndFrameEnabled(mIconEnd, progress < mSeekbar.getMax());
}
/**
* Sets max to the seekbar in the layout.
*/
public void setMax(int max) {
mSeekbar.setMax(max);
}
/**
* Sets progress to the seekbar in the layout.
* If the progress is smaller than or equals to 0, the IconStart will be disabled. If the

View File

@@ -35,6 +35,7 @@ import com.android.systemui.qs.QSHost
import com.android.systemui.qs.logging.QSLogger
import com.android.systemui.qs.tileimpl.QSTileImpl
import com.android.systemui.statusbar.phone.SystemUIDialog
import com.android.systemui.util.settings.SystemSettings
import javax.inject.Inject
class FontScalingTile
@@ -48,7 +49,8 @@ constructor(
statusBarStateController: StatusBarStateController,
activityStarter: ActivityStarter,
qsLogger: QSLogger,
private val dialogLaunchAnimator: DialogLaunchAnimator
private val dialogLaunchAnimator: DialogLaunchAnimator,
private val systemSettings: SystemSettings
) :
QSTileImpl<QSTile.State?>(
host,
@@ -74,7 +76,7 @@ constructor(
override fun handleClick(view: View?) {
mUiHandler.post {
val dialog: SystemUIDialog = FontScalingDialog(mContext)
val dialog: SystemUIDialog = FontScalingDialog(mContext, systemSettings)
if (view != null) {
dialogLaunchAnimator.showFromView(
dialog,

View File

@@ -0,0 +1,107 @@
/*
* 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.accessibility.fontscaling
import android.os.Handler
import android.provider.Settings
import android.testing.AndroidTestingRunner
import android.testing.TestableLooper
import android.widget.ImageView
import android.widget.SeekBar
import androidx.test.filters.SmallTest
import com.android.systemui.R
import com.android.systemui.SysuiTestCase
import com.android.systemui.common.ui.view.SeekBarWithIconButtonsView
import com.android.systemui.util.settings.FakeSettings
import com.android.systemui.util.settings.SystemSettings
import com.google.common.truth.Truth.assertThat
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
/** Tests for [FontScalingDialog]. */
@SmallTest
@RunWith(AndroidTestingRunner::class)
@TestableLooper.RunWithLooper(setAsMainLooper = true)
class FontScalingDialogTest : SysuiTestCase() {
private lateinit var fontScalingDialog: FontScalingDialog
private lateinit var systemSettings: SystemSettings
private val fontSizeValueArray: Array<String> =
mContext
.getResources()
.getStringArray(com.android.settingslib.R.array.entryvalues_font_size)
@Before
fun setUp() {
val mainHandler = Handler(TestableLooper.get(this).getLooper())
systemSettings = FakeSettings()
fontScalingDialog = FontScalingDialog(mContext, systemSettings as FakeSettings)
}
@Test
fun showTheDialog_seekbarIsShowingCorrectProgress() {
fontScalingDialog.show()
val seekBar: SeekBar = fontScalingDialog.findViewById<SeekBar>(R.id.seekbar)!!
val progress: Int = seekBar.getProgress()
val currentScale = systemSettings.getFloat(Settings.System.FONT_SCALE, /* def = */ 1.0f)
assertThat(currentScale).isEqualTo(fontSizeValueArray[progress].toFloat())
fontScalingDialog.dismiss()
}
@Test
fun progressIsZero_clickIconEnd_seekBarProgressIncreaseOne_fontSizeScaled() {
fontScalingDialog.show()
val iconEnd: ImageView = fontScalingDialog.findViewById(R.id.icon_end)!!
val seekBarWithIconButtonsView: SeekBarWithIconButtonsView =
fontScalingDialog.findViewById(R.id.font_scaling_slider)!!
val seekBar: SeekBar = fontScalingDialog.findViewById(R.id.seekbar)!!
seekBarWithIconButtonsView.setProgress(0)
iconEnd.performClick()
val currentScale = systemSettings.getFloat(Settings.System.FONT_SCALE, /* def = */ 1.0f)
assertThat(seekBar.getProgress()).isEqualTo(1)
assertThat(currentScale).isEqualTo(fontSizeValueArray[1].toFloat())
fontScalingDialog.dismiss()
}
@Test
fun progressIsMax_clickIconStart_seekBarProgressDecreaseOne_fontSizeScaled() {
fontScalingDialog.show()
val iconStart: ImageView = fontScalingDialog.findViewById(R.id.icon_start)!!
val seekBarWithIconButtonsView: SeekBarWithIconButtonsView =
fontScalingDialog.findViewById(R.id.font_scaling_slider)!!
val seekBar: SeekBar = fontScalingDialog.findViewById(R.id.seekbar)!!
seekBarWithIconButtonsView.setProgress(fontSizeValueArray.size - 1)
iconStart.performClick()
val currentScale = systemSettings.getFloat(Settings.System.FONT_SCALE, /* def = */ 1.0f)
assertThat(seekBar.getProgress()).isEqualTo(fontSizeValueArray.size - 2)
assertThat(currentScale)
.isEqualTo(fontSizeValueArray[fontSizeValueArray.size - 2].toFloat())
fontScalingDialog.dismiss()
}
}

View File

@@ -28,6 +28,7 @@ import com.android.systemui.plugins.statusbar.StatusBarStateController
import com.android.systemui.qs.QSTileHost
import com.android.systemui.qs.logging.QSLogger
import com.android.systemui.qs.tiles.FontScalingTile
import com.android.systemui.util.settings.FakeSettings
import com.google.common.truth.Truth.assertThat
import org.junit.Before
import org.junit.Test
@@ -65,7 +66,8 @@ class FontScalingTileTest : SysuiTestCase() {
statusBarStateController,
activityStarter,
qsLogger,
dialogLaunchAnimator
dialogLaunchAnimator,
FakeSettings()
)
fontScalingTile.initialize()
}