Fix accessibility button footer preference did not announced correct by TalkBack
Root Cause: Description would be altered after displayPreference(), but getSummary() would be called after it. Solution: Update title before displayPreference(), then it could be set correctly. Fix: 192738520 Test: atest AccessibilityButtonFooterPreferenceControllerTest Change-Id: I068994fca8202b166fedf43f9d9657b0c1a64c4e
This commit is contained in:
@@ -61,6 +61,7 @@
|
|||||||
|
|
||||||
<com.android.settings.accessibility.AccessibilityFooterPreference
|
<com.android.settings.accessibility.AccessibilityFooterPreference
|
||||||
android:key="accessibility_button_footer"
|
android:key="accessibility_button_footer"
|
||||||
|
android:title="@string/accessibility_button_description"
|
||||||
android:persistent="false"
|
android:persistent="false"
|
||||||
android:selectable="false"
|
android:selectable="false"
|
||||||
settings:searchable="false"
|
settings:searchable="false"
|
||||||
|
@@ -18,6 +18,8 @@ package com.android.settings.accessibility;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -36,9 +38,16 @@ public class AccessibilityButtonFooterPreferenceController extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharSequence getSummary() {
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
return AccessibilityUtil.isGestureNavigateEnabled(mContext)
|
// Need to update footerPreference's data before super.displayPreference(), then it will use
|
||||||
? mContext.getString(R.string.accessibility_button_gesture_description)
|
// data to update related property of footerPreference.
|
||||||
: mContext.getString(R.string.accessibility_button_description);
|
if (AccessibilityUtil.isGestureNavigateEnabled(mContext)) {
|
||||||
|
final AccessibilityFooterPreference footerPreference =
|
||||||
|
screen.findPreference(getPreferenceKey());
|
||||||
|
footerPreference.setTitle(
|
||||||
|
mContext.getString(R.string.accessibility_button_gesture_description));
|
||||||
|
}
|
||||||
|
|
||||||
|
super.displayPreference(screen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.android.settings.accessibility;
|
package com.android.settings.accessibility;
|
||||||
|
|
||||||
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_2BUTTON;
|
|
||||||
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL;
|
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
@@ -26,6 +25,7 @@ import static org.mockito.Mockito.when;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
@@ -34,6 +34,7 @@ import org.junit.Before;
|
|||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
import org.mockito.Spy;
|
import org.mockito.Spy;
|
||||||
import org.mockito.junit.MockitoJUnit;
|
import org.mockito.junit.MockitoJUnit;
|
||||||
import org.mockito.junit.MockitoRule;
|
import org.mockito.junit.MockitoRule;
|
||||||
@@ -50,30 +51,29 @@ public class AccessibilityButtonFooterPreferenceControllerTest {
|
|||||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||||
@Spy
|
@Spy
|
||||||
private final Resources mResources = mContext.getResources();
|
private final Resources mResources = mContext.getResources();
|
||||||
|
@Mock
|
||||||
|
private PreferenceScreen mScreen;
|
||||||
private AccessibilityButtonFooterPreferenceController mController;
|
private AccessibilityButtonFooterPreferenceController mController;
|
||||||
|
private AccessibilityFooterPreference mPreference;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
mController = new AccessibilityButtonFooterPreferenceController(mContext,
|
mController = new AccessibilityButtonFooterPreferenceController(mContext, "test_key");
|
||||||
"test_key");
|
mPreference = new AccessibilityFooterPreference(mContext);
|
||||||
|
mPreference.setKey("test_key");
|
||||||
|
|
||||||
|
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||||
when(mContext.getResources()).thenReturn(mResources);
|
when(mContext.getResources()).thenReturn(mResources);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getSummary_navigationGestureEnabled_shouldReturnButtonAndGestureSummary() {
|
public void displayPreference_navigationGestureEnabled_setCorrectTitle() {
|
||||||
when(mResources.getInteger(com.android.internal.R.integer.config_navBarInteractionMode))
|
when(mResources.getInteger(com.android.internal.R.integer.config_navBarInteractionMode))
|
||||||
.thenReturn(NAV_BAR_MODE_GESTURAL);
|
.thenReturn(NAV_BAR_MODE_GESTURAL);
|
||||||
|
|
||||||
assertThat(mController.getSummary()).isEqualTo(
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
|
assertThat(mPreference.getTitle()).isEqualTo(
|
||||||
mContext.getText(R.string.accessibility_button_gesture_description));
|
mContext.getText(R.string.accessibility_button_gesture_description));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getSummary_navigationGestureDisabled_shouldReturnButtonSummary() {
|
|
||||||
when(mResources.getInteger(com.android.internal.R.integer.config_navBarInteractionMode))
|
|
||||||
.thenReturn(NAV_BAR_MODE_2BUTTON);
|
|
||||||
|
|
||||||
assertThat(mController.getSummary()).isEqualTo(
|
|
||||||
mContext.getText(R.string.accessibility_button_description));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user