Enable auto-add for the font scaling tile
1. Add the setting name and spec for font scaling tile to the list of auto-add items 2. Change settings key when the font size is modified for the first time Bug: 269679768 Test: manually - verifying the value of key through adb commands Test: atest FontScalingDialogTest Test: atest FontScalingTileTest Change-Id: I65a1a424a181aaa2b9ab9f3538bd6a594dfde9f2
This commit is contained in:
@@ -99,6 +99,7 @@
|
||||
<item>accessibility_display_daltonizer_enabled:color_correction</item>
|
||||
<item>accessibility_display_inversion_enabled:inversion</item>
|
||||
<item>one_handed_mode_enabled:onehanded</item>
|
||||
<item>accessibility_font_scaling_has_been_changed:font_scaling</item>
|
||||
</string-array>
|
||||
|
||||
<!-- Use collapsed layout for media player in landscape QQS -->
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.android.systemui.accessibility.fontscaling
|
||||
|
||||
import android.annotation.WorkerThread
|
||||
import android.content.Context
|
||||
import android.content.pm.ActivityInfo
|
||||
import android.content.res.Configuration
|
||||
@@ -27,18 +28,26 @@ 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.dagger.qualifiers.Background
|
||||
import com.android.systemui.statusbar.phone.SystemUIDialog
|
||||
import com.android.systemui.util.settings.SecureSettings
|
||||
import com.android.systemui.util.settings.SystemSettings
|
||||
import java.util.concurrent.Executor
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/** The Dialog that contains a seekbar for changing the font size. */
|
||||
class FontScalingDialog(context: Context, private val systemSettings: SystemSettings) :
|
||||
SystemUIDialog(context) {
|
||||
class FontScalingDialog(
|
||||
context: Context,
|
||||
private val systemSettings: SystemSettings,
|
||||
private val secureSettings: SecureSettings,
|
||||
@Background private val backgroundExecutor: Executor
|
||||
) : 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 var lastProgress: Int = -1
|
||||
|
||||
private val configuration: Configuration =
|
||||
Configuration(context.getResources().getConfiguration())
|
||||
@@ -70,12 +79,22 @@ class FontScalingDialog(context: Context, private val systemSettings: SystemSett
|
||||
seekBarWithIconButtonsView.setMax((strEntryValues).size - 1)
|
||||
|
||||
val currentScale = systemSettings.getFloat(Settings.System.FONT_SCALE, 1.0f)
|
||||
seekBarWithIconButtonsView.setProgress(fontSizeValueToIndex(currentScale))
|
||||
lastProgress = fontSizeValueToIndex(currentScale)
|
||||
seekBarWithIconButtonsView.setProgress(lastProgress)
|
||||
|
||||
seekBarWithIconButtonsView.setOnSeekBarChangeListener(
|
||||
object : OnSeekBarChangeListener {
|
||||
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
|
||||
systemSettings.putString(Settings.System.FONT_SCALE, strEntryValues[progress])
|
||||
if (progress != lastProgress) {
|
||||
if (!fontSizeHasBeenChangedFromTile) {
|
||||
backgroundExecutor.execute { updateSecureSettingsIfNeeded() }
|
||||
fontSizeHasBeenChangedFromTile = true
|
||||
}
|
||||
|
||||
backgroundExecutor.execute { updateFontScale(strEntryValues[progress]) }
|
||||
|
||||
lastProgress = progress
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStartTrackingTouch(seekBar: SeekBar) {
|
||||
@@ -115,4 +134,28 @@ class FontScalingDialog(context: Context, private val systemSettings: SystemSett
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
fun updateFontScale(newScale: String) {
|
||||
systemSettings.putString(Settings.System.FONT_SCALE, newScale)
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
fun updateSecureSettingsIfNeeded() {
|
||||
if (
|
||||
secureSettings.getString(Settings.Secure.ACCESSIBILITY_FONT_SCALING_HAS_BEEN_CHANGED) !=
|
||||
ON
|
||||
) {
|
||||
secureSettings.putString(
|
||||
Settings.Secure.ACCESSIBILITY_FONT_SCALING_HAS_BEEN_CHANGED,
|
||||
ON
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val ON = "1"
|
||||
private const val OFF = "0"
|
||||
private var fontSizeHasBeenChangedFromTile = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.android.systemui.qs.tiles
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Handler
|
||||
import android.os.HandlerExecutor
|
||||
import android.os.Looper
|
||||
import android.provider.Settings
|
||||
import android.view.View
|
||||
@@ -38,6 +39,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.SecureSettings
|
||||
import com.android.systemui.util.settings.SystemSettings
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -54,6 +56,7 @@ constructor(
|
||||
qsLogger: QSLogger,
|
||||
private val dialogLaunchAnimator: DialogLaunchAnimator,
|
||||
private val systemSettings: SystemSettings,
|
||||
private val secureSettings: SecureSettings,
|
||||
private val featureFlags: FeatureFlags
|
||||
) :
|
||||
QSTileImpl<QSTile.State?>(
|
||||
@@ -78,7 +81,13 @@ constructor(
|
||||
|
||||
override fun handleClick(view: View?) {
|
||||
mUiHandler.post {
|
||||
val dialog: SystemUIDialog = FontScalingDialog(mContext, systemSettings)
|
||||
val dialog: SystemUIDialog =
|
||||
FontScalingDialog(
|
||||
mContext,
|
||||
systemSettings,
|
||||
secureSettings,
|
||||
HandlerExecutor(mHandler)
|
||||
)
|
||||
if (view != null) {
|
||||
dialogLaunchAnimator.showFromView(
|
||||
dialog,
|
||||
|
||||
@@ -25,12 +25,19 @@ 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.concurrency.FakeExecutor
|
||||
import com.android.systemui.util.settings.FakeSettings
|
||||
import com.android.systemui.util.settings.SecureSettings
|
||||
import com.android.systemui.util.settings.SystemSettings
|
||||
import com.android.systemui.util.time.FakeSystemClock
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.MockitoAnnotations
|
||||
|
||||
private const val ON: Int = 1
|
||||
private const val OFF: Int = 0
|
||||
|
||||
/** Tests for [FontScalingDialog]. */
|
||||
@SmallTest
|
||||
@@ -39,6 +46,8 @@ import org.junit.runner.RunWith
|
||||
class FontScalingDialogTest : SysuiTestCase() {
|
||||
private lateinit var fontScalingDialog: FontScalingDialog
|
||||
private lateinit var systemSettings: SystemSettings
|
||||
private lateinit var secureSettings: SecureSettings
|
||||
private lateinit var backgroundExecutor: FakeExecutor
|
||||
private val fontSizeValueArray: Array<String> =
|
||||
mContext
|
||||
.getResources()
|
||||
@@ -46,9 +55,13 @@ class FontScalingDialogTest : SysuiTestCase() {
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
val mainHandler = Handler(TestableLooper.get(this).getLooper())
|
||||
systemSettings = FakeSettings()
|
||||
fontScalingDialog = FontScalingDialog(mContext, systemSettings as FakeSettings)
|
||||
secureSettings = FakeSettings()
|
||||
backgroundExecutor = FakeExecutor(FakeSystemClock())
|
||||
fontScalingDialog =
|
||||
FontScalingDialog(mContext, systemSettings, secureSettings, backgroundExecutor)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -76,6 +89,7 @@ class FontScalingDialogTest : SysuiTestCase() {
|
||||
seekBarWithIconButtonsView.setProgress(0)
|
||||
|
||||
iconEndFrame.performClick()
|
||||
backgroundExecutor.runAllReady()
|
||||
|
||||
val currentScale = systemSettings.getFloat(Settings.System.FONT_SCALE, /* def = */ 1.0f)
|
||||
assertThat(seekBar.getProgress()).isEqualTo(1)
|
||||
@@ -96,6 +110,7 @@ class FontScalingDialogTest : SysuiTestCase() {
|
||||
seekBarWithIconButtonsView.setProgress(fontSizeValueArray.size - 1)
|
||||
|
||||
iconStartFrame.performClick()
|
||||
backgroundExecutor.runAllReady()
|
||||
|
||||
val currentScale = systemSettings.getFloat(Settings.System.FONT_SCALE, /* def = */ 1.0f)
|
||||
assertThat(seekBar.getProgress()).isEqualTo(fontSizeValueArray.size - 2)
|
||||
@@ -104,4 +119,26 @@ class FontScalingDialogTest : SysuiTestCase() {
|
||||
|
||||
fontScalingDialog.dismiss()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun progressChanged_keyWasNotSetBefore_fontScalingHasBeenChangedIsOn() {
|
||||
fontScalingDialog.show()
|
||||
|
||||
val seekBarWithIconButtonsView: SeekBarWithIconButtonsView =
|
||||
fontScalingDialog.findViewById(R.id.font_scaling_slider)!!
|
||||
secureSettings.putInt(Settings.Secure.ACCESSIBILITY_FONT_SCALING_HAS_BEEN_CHANGED, OFF)
|
||||
|
||||
// Default seekbar progress for font size is 1, set it to another progress 0
|
||||
seekBarWithIconButtonsView.setProgress(0)
|
||||
backgroundExecutor.runAllReady()
|
||||
|
||||
val currentSettings =
|
||||
secureSettings.getInt(
|
||||
Settings.Secure.ACCESSIBILITY_FONT_SCALING_HAS_BEEN_CHANGED,
|
||||
/* def = */ OFF
|
||||
)
|
||||
assertThat(currentSettings).isEqualTo(ON)
|
||||
|
||||
fontScalingDialog.dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,6 +84,7 @@ class FontScalingTileTest : SysuiTestCase() {
|
||||
qsLogger,
|
||||
dialogLaunchAnimator,
|
||||
FakeSettings(),
|
||||
FakeSettings(),
|
||||
featureFlags
|
||||
)
|
||||
fontScalingTile.initialize()
|
||||
|
||||
Reference in New Issue
Block a user