Merge "Disabling the Done button when system applying new font size" into udc-qpr-dev

This commit is contained in:
Candice Lo
2023-07-24 03:34:21 +00:00
committed by Android (Google) Code Review
6 changed files with 87 additions and 9 deletions

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ 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.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:androidprv="http://schemas.android.com/apk/prv/res/android">
<item android:state_enabled="false"
android:color="?androidprv:attr/materialColorPrimary"
android:alpha="0.30"/>
<item android:color="?androidprv:attr/materialColorPrimary"/>
</selector>

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ 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.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:androidprv="http://schemas.android.com/apk/prv/res/android">
<item android:state_enabled="false"
android:color="?androidprv:attr/materialColorOnPrimary"
android:alpha="0.30"/>
<item android:color="?androidprv:attr/materialColorOnPrimary"/>
</selector>

View File

@@ -15,7 +15,6 @@
~ limitations under the License.
-->
<inset xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
android:insetTop="@dimen/dialog_button_vertical_inset"
android:insetBottom="@dimen/dialog_button_vertical_inset">
<ripple android:color="?android:attr/colorControlHighlight">
@@ -28,7 +27,7 @@
<item>
<shape android:shape="rectangle">
<corners android:radius="?android:attr/buttonCornerRadius"/>
<solid android:color="?androidprv:attr/materialColorPrimary"/>
<solid android:color="@color/qs_dialog_btn_filled_background"/>
<padding android:left="@dimen/dialog_button_horizontal_padding"
android:top="@dimen/dialog_button_vertical_padding"
android:right="@dimen/dialog_button_horizontal_padding"

View File

@@ -1116,7 +1116,7 @@
<style name="Widget.Dialog.Button">
<item name="android:buttonCornerRadius">28dp</item>
<item name="android:background">@drawable/qs_dialog_btn_filled</item>
<item name="android:textColor">?androidprv:attr/materialColorOnPrimary</item>
<item name="android:textColor">@color/qs_dialog_btn_filled_text_color</item>
<item name="android:textSize">14sp</item>
<item name="android:lineHeight">20sp</item>
<item name="android:fontFamily">@*android:string/config_bodyFontFamilyMedium</item>

View File

@@ -145,6 +145,8 @@ class FontScalingDialog(
*/
@MainThread
fun updateFontScaleDelayed(delayMsFromSource: Long) {
doneButton.isEnabled = false
var delayMs = delayMsFromSource
if (systemClock.elapsedRealtime() - lastUpdateTime < MIN_UPDATE_INTERVAL_MS) {
delayMs += MIN_UPDATE_INTERVAL_MS
@@ -197,17 +199,22 @@ class FontScalingDialog(
title.post {
title.setTextAppearance(R.style.TextAppearance_Dialog_Title)
doneButton.setTextAppearance(R.style.Widget_Dialog_Button)
doneButton.isEnabled = true
}
}
}
@WorkerThread
fun updateFontScale() {
systemSettings.putStringForUser(
Settings.System.FONT_SCALE,
strEntryValues[lastProgress.get()],
userTracker.userId
)
if (
!systemSettings.putStringForUser(
Settings.System.FONT_SCALE,
strEntryValues[lastProgress.get()],
userTracker.userId
)
) {
title.post { doneButton.isEnabled = true }
}
}
@WorkerThread

View File

@@ -15,11 +15,13 @@
*/
package com.android.systemui.accessibility.fontscaling
import android.content.res.Configuration
import android.os.Handler
import android.provider.Settings
import android.testing.AndroidTestingRunner
import android.testing.TestableLooper
import android.view.ViewGroup
import android.widget.Button
import android.widget.SeekBar
import androidx.test.filters.SmallTest
import com.android.systemui.R
@@ -61,6 +63,7 @@ class FontScalingDialogTest : SysuiTestCase() {
private lateinit var secureSettings: SecureSettings
private lateinit var systemClock: FakeSystemClock
private lateinit var backgroundDelayableExecutor: FakeExecutor
private lateinit var testableLooper: TestableLooper
private val fontSizeValueArray: Array<String> =
mContext
.getResources()
@@ -73,7 +76,8 @@ class FontScalingDialogTest : SysuiTestCase() {
@Before
fun setUp() {
MockitoAnnotations.initMocks(this)
val mainHandler = Handler(TestableLooper.get(this).getLooper())
testableLooper = TestableLooper.get(this)
val mainHandler = Handler(testableLooper.looper)
systemSettings = FakeSettings()
// Guarantee that the systemSettings always starts with the default font scale.
systemSettings.putFloatForUser(Settings.System.FONT_SCALE, 1.0f, userTracker.userId)
@@ -286,4 +290,26 @@ class FontScalingDialogTest : SysuiTestCase() {
verify(fontScalingDialog).createTextPreview(/* index= */ 0)
fontScalingDialog.dismiss()
}
@Test
fun changeFontSize_buttonIsDisabledBeforeFontSizeChangeFinishes() {
fontScalingDialog.show()
val iconEndFrame: ViewGroup = fontScalingDialog.findViewById(R.id.icon_end_frame)!!
val doneButton: Button = fontScalingDialog.findViewById(com.android.internal.R.id.button1)!!
iconEndFrame.performClick()
backgroundDelayableExecutor.runAllReady()
backgroundDelayableExecutor.advanceClockToNext()
backgroundDelayableExecutor.runAllReady()
// Verify that the button is disabled before receiving onConfigurationChanged
assertThat(doneButton.isEnabled).isFalse()
val config = Configuration()
config.fontScale = 1.15f
fontScalingDialog.onConfigurationChanged(config)
testableLooper.processAllMessages()
assertThat(doneButton.isEnabled).isTrue()
}
}