Follow O patterns for a11y settings
Move the summary for the toggled features to a footer. Make the settings appear as a preference. Bug: 36780887 Test: Start settings and observe the new UI looks a lot like the mocks referenced in the bug. Also added unit test to verify that summary text shows up. Change-Id: I1d002b194991d0901ecb27198ba5de73bd23a5a9
This commit is contained in:
@@ -17,12 +17,6 @@
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:title="@string/accessibility_display_daltonizer_preference_title" >
|
||||
|
||||
<Preference
|
||||
android:summary="@string/accessibility_display_daltonizer_preference_subtitle"
|
||||
android:layout="@layout/text_description_preference"
|
||||
android:persistent="false"
|
||||
android:selectable="false" />
|
||||
|
||||
<ListPreference
|
||||
android:entries="@array/daltonizer_type_entries"
|
||||
android:entryValues="@array/daltonizer_type_values"
|
||||
|
@@ -211,6 +211,18 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
||||
|
||||
private DevicePolicyManager mDpm;
|
||||
|
||||
/**
|
||||
* Check if the color transforms are color accelerated. Some transforms are experimental only
|
||||
* on non-accelerated platforms due to the performance implications.
|
||||
*
|
||||
* @param context The current context
|
||||
* @return
|
||||
*/
|
||||
public static boolean isColorTransformAccelerated(Context context) {
|
||||
return context.getResources()
|
||||
.getBoolean(com.android.internal.R.bool.config_setColorTransformAccelerated);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.ACCESSIBILITY;
|
||||
@@ -618,11 +630,6 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
||||
updateAccessibilityShortcut(mAccessibilityShortcutPreferenceScreen);
|
||||
}
|
||||
|
||||
private boolean isColorTransformAccelerated(Context context) {
|
||||
return context.getResources()
|
||||
.getBoolean(com.android.internal.R.bool.config_setColorTransformAccelerated);
|
||||
}
|
||||
|
||||
private void updateMagnificationSummary(Preference pref) {
|
||||
final boolean tripleTapEnabled = Settings.Secure.getInt(getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, 0) == 1;
|
||||
|
@@ -34,7 +34,6 @@ import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.accessibility.AccessibilityManager;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
@@ -79,14 +78,6 @@ public class ToggleAccessibilityServicePreferenceFragment
|
||||
// Do not call super. We don't want to see the "Help & feedback" option on this page so as
|
||||
// not to confuse users who think they might be able to send feedback about a specific
|
||||
// accessibility service from this page.
|
||||
|
||||
// We still want to show the "Settings" menu.
|
||||
if (mSettingsTitle != null && mSettingsIntent != null) {
|
||||
MenuItem menuItem = menu.add(mSettingsTitle);
|
||||
menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||
menuItem.setIntent(mSettingsIntent);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -49,6 +49,10 @@ public class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePreferenceF
|
||||
|
||||
mType = (ListPreference) findPreference("type");
|
||||
|
||||
if (!AccessibilitySettings.isColorTransformAccelerated(getActivity())) {
|
||||
mFooterPreferenceMixin.createFooterPreference().setTitle(
|
||||
R.string.accessibility_display_daltonizer_preference_subtitle);
|
||||
}
|
||||
initPreferences();
|
||||
}
|
||||
|
||||
|
@@ -42,7 +42,6 @@ public abstract class ToggleFeaturePreferenceFragment
|
||||
protected ToggleSwitch mToggleSwitch;
|
||||
|
||||
protected String mPreferenceKey;
|
||||
protected Preference mSummaryPreference;
|
||||
|
||||
protected CharSequence mSettingsTitle;
|
||||
protected Intent mSettingsIntent;
|
||||
@@ -53,36 +52,6 @@ public abstract class ToggleFeaturePreferenceFragment
|
||||
PreferenceScreen preferenceScreen = getPreferenceManager().createPreferenceScreen(
|
||||
getActivity());
|
||||
setPreferenceScreen(preferenceScreen);
|
||||
mSummaryPreference = new Preference(getPrefContext()) {
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder view) {
|
||||
super.onBindViewHolder(view);
|
||||
view.setDividerAllowedAbove(false);
|
||||
view.setDividerAllowedBelow(false);
|
||||
final TextView summaryView = (TextView) view.findViewById(android.R.id.summary);
|
||||
summaryView.setText(getSummary());
|
||||
sendAccessibilityEvent(summaryView);
|
||||
}
|
||||
|
||||
private void sendAccessibilityEvent(View view) {
|
||||
// Since the view is still not attached we create, populate,
|
||||
// and send the event directly since we do not know when it
|
||||
// will be attached and posting commands is not as clean.
|
||||
AccessibilityManager accessibilityManager =
|
||||
AccessibilityManager.getInstance(getActivity());
|
||||
if (accessibilityManager.isEnabled()) {
|
||||
AccessibilityEvent event = AccessibilityEvent.obtain();
|
||||
event.setEventType(AccessibilityEvent.TYPE_VIEW_FOCUSED);
|
||||
view.onInitializeAccessibilityEvent(event);
|
||||
view.dispatchPopulateAccessibilityEvent(event);
|
||||
accessibilityManager.sendAccessibilityEvent(event);
|
||||
}
|
||||
}
|
||||
};
|
||||
mSummaryPreference.setSelectable(false);
|
||||
mSummaryPreference.setPersistent(false);
|
||||
mSummaryPreference.setLayoutResource(R.layout.text_description_preference);
|
||||
preferenceScreen.addPreference(mSummaryPreference);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -94,6 +63,16 @@ public abstract class ToggleFeaturePreferenceFragment
|
||||
mToggleSwitch = mSwitchBar.getSwitch();
|
||||
|
||||
onProcessArguments(getArguments());
|
||||
|
||||
// Show the "Settings" menu as if it were a preference screen
|
||||
if (mSettingsTitle != null && mSettingsIntent != null) {
|
||||
PreferenceScreen preferenceScreen = getPreferenceScreen();
|
||||
Preference settingsPref = new Preference(preferenceScreen.getContext());
|
||||
settingsPref.setTitle(mSettingsTitle);
|
||||
settingsPref.setIconSpaceReserved(true);
|
||||
settingsPref.setIntent(mSettingsIntent);
|
||||
preferenceScreen.addPreference(settingsPref);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -111,16 +90,6 @@ public abstract class ToggleFeaturePreferenceFragment
|
||||
|
||||
protected abstract void onPreferenceToggled(String preferenceKey, boolean enabled);
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
if (mSettingsTitle != null && mSettingsIntent != null) {
|
||||
MenuItem menuItem = menu.add(mSettingsTitle);
|
||||
menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||
menuItem.setIntent(mSettingsIntent);
|
||||
}
|
||||
}
|
||||
|
||||
protected void onInstallSwitchBarToggleSwitch() {
|
||||
// Implement this to set a checked listener.
|
||||
}
|
||||
@@ -145,11 +114,6 @@ public abstract class ToggleFeaturePreferenceFragment
|
||||
}
|
||||
|
||||
protected void onProcessArguments(Bundle arguments) {
|
||||
if (arguments == null) {
|
||||
getPreferenceScreen().removePreference(mSummaryPreference);
|
||||
return;
|
||||
}
|
||||
|
||||
// Key.
|
||||
mPreferenceKey = arguments.getString(AccessibilitySettings.EXTRA_PREFERENCE_KEY);
|
||||
|
||||
@@ -168,9 +132,7 @@ public abstract class ToggleFeaturePreferenceFragment
|
||||
if (arguments.containsKey(AccessibilitySettings.EXTRA_SUMMARY)) {
|
||||
final CharSequence summary = arguments.getCharSequence(
|
||||
AccessibilitySettings.EXTRA_SUMMARY);
|
||||
mSummaryPreference.setSummary(summary);
|
||||
} else {
|
||||
getPreferenceScreen().removePreference(mSummaryPreference);
|
||||
mFooterPreferenceMixin.createFooterPreference().setTitle(summary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -144,7 +144,6 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
||||
final PreferenceScreen preferenceScreen = getPreferenceManager().getPreferenceScreen();
|
||||
preferenceScreen.setOrderingAsAdded(false);
|
||||
mVideoPreference.setOrder(0);
|
||||
mSummaryPreference.setOrder(1);
|
||||
mConfigWarningPreference.setOrder(2);
|
||||
preferenceScreen.addPreference(mVideoPreference);
|
||||
preferenceScreen.addPreference(mConfigWarningPreference);
|
||||
|
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.settings.accessibility;
|
||||
|
||||
import static android.support.test.espresso.Espresso.onView;
|
||||
import static android.support.test.espresso.assertion.ViewAssertions.matches;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.withText;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
import android.os.Bundle;
|
||||
import android.os.Looper;
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
import android.support.test.rule.ActivityTestRule;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.Settings.AccessibilitySettingsActivity;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ToggleFeaturePreferenceFragmentTest {
|
||||
private static final String SUMMARY_TEXT = "Here's some summary text";
|
||||
|
||||
@Rule
|
||||
public final ActivityTestRule<AccessibilitySettingsActivity> mActivityRule =
|
||||
new ActivityTestRule<>(AccessibilitySettingsActivity.class, true);
|
||||
|
||||
private final Instrumentation mInstrumentation = InstrumentationRegistry.getInstrumentation();
|
||||
|
||||
@BeforeClass
|
||||
public static void oneTimeSetup() {
|
||||
if (Looper.myLooper() == null) {
|
||||
Looper.prepare();
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mInstrumentation.runOnMainSync(() -> {
|
||||
MyToggleFeaturePreferenceFragment fragment = new MyToggleFeaturePreferenceFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putString(AccessibilitySettings.EXTRA_SUMMARY, SUMMARY_TEXT);
|
||||
fragment.setArguments(args);
|
||||
mActivityRule.getActivity().startPreferenceFragment(fragment, false);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSummaryTestDisplayed() {
|
||||
onView(withText(SUMMARY_TEXT)).check(matches(isDisplayed()));
|
||||
}
|
||||
|
||||
public static class MyToggleFeaturePreferenceFragment extends ToggleFeaturePreferenceFragment {
|
||||
@Override
|
||||
protected void onPreferenceToggled(String preferenceKey, boolean enabled) {}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user