Merge "Follow O patterns for a11y settings"

This commit is contained in:
Phil Weaver
2017-05-24 19:37:38 +00:00
committed by Android (Google) Code Review
7 changed files with 107 additions and 70 deletions

View File

@@ -17,12 +17,6 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/accessibility_display_daltonizer_preference_title" > 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 <ListPreference
android:entries="@array/daltonizer_type_entries" android:entries="@array/daltonizer_type_entries"
android:entryValues="@array/daltonizer_type_values" android:entryValues="@array/daltonizer_type_values"

View File

@@ -211,6 +211,18 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
private DevicePolicyManager mDpm; 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 @Override
public int getMetricsCategory() { public int getMetricsCategory() {
return MetricsEvent.ACCESSIBILITY; return MetricsEvent.ACCESSIBILITY;
@@ -618,11 +630,6 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
updateAccessibilityShortcut(mAccessibilityShortcutPreferenceScreen); updateAccessibilityShortcut(mAccessibilityShortcutPreferenceScreen);
} }
private boolean isColorTransformAccelerated(Context context) {
return context.getResources()
.getBoolean(com.android.internal.R.bool.config_setColorTransformAccelerated);
}
private void updateMagnificationSummary(Preference pref) { private void updateMagnificationSummary(Preference pref) {
final boolean tripleTapEnabled = Settings.Secure.getInt(getContentResolver(), final boolean tripleTapEnabled = Settings.Secure.getInt(getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, 0) == 1; Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, 0) == 1;

View File

@@ -34,7 +34,6 @@ import android.provider.Settings;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.accessibility.AccessibilityManager; import android.view.accessibility.AccessibilityManager;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent; 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 // 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 // not to confuse users who think they might be able to send feedback about a specific
// accessibility service from this page. // 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 @Override

View File

@@ -49,6 +49,10 @@ public class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePreferenceF
mType = (ListPreference) findPreference("type"); mType = (ListPreference) findPreference("type");
if (!AccessibilitySettings.isColorTransformAccelerated(getActivity())) {
mFooterPreferenceMixin.createFooterPreference().setTitle(
R.string.accessibility_display_daltonizer_preference_subtitle);
}
initPreferences(); initPreferences();
} }

View File

@@ -42,7 +42,6 @@ public abstract class ToggleFeaturePreferenceFragment
protected ToggleSwitch mToggleSwitch; protected ToggleSwitch mToggleSwitch;
protected String mPreferenceKey; protected String mPreferenceKey;
protected Preference mSummaryPreference;
protected CharSequence mSettingsTitle; protected CharSequence mSettingsTitle;
protected Intent mSettingsIntent; protected Intent mSettingsIntent;
@@ -53,36 +52,6 @@ public abstract class ToggleFeaturePreferenceFragment
PreferenceScreen preferenceScreen = getPreferenceManager().createPreferenceScreen( PreferenceScreen preferenceScreen = getPreferenceManager().createPreferenceScreen(
getActivity()); getActivity());
setPreferenceScreen(preferenceScreen); 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 @Override
@@ -94,6 +63,16 @@ public abstract class ToggleFeaturePreferenceFragment
mToggleSwitch = mSwitchBar.getSwitch(); mToggleSwitch = mSwitchBar.getSwitch();
onProcessArguments(getArguments()); 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 @Override
@@ -111,16 +90,6 @@ public abstract class ToggleFeaturePreferenceFragment
protected abstract void onPreferenceToggled(String preferenceKey, boolean enabled); 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() { protected void onInstallSwitchBarToggleSwitch() {
// Implement this to set a checked listener. // Implement this to set a checked listener.
} }
@@ -145,11 +114,6 @@ public abstract class ToggleFeaturePreferenceFragment
} }
protected void onProcessArguments(Bundle arguments) { protected void onProcessArguments(Bundle arguments) {
if (arguments == null) {
getPreferenceScreen().removePreference(mSummaryPreference);
return;
}
// Key. // Key.
mPreferenceKey = arguments.getString(AccessibilitySettings.EXTRA_PREFERENCE_KEY); mPreferenceKey = arguments.getString(AccessibilitySettings.EXTRA_PREFERENCE_KEY);
@@ -168,9 +132,7 @@ public abstract class ToggleFeaturePreferenceFragment
if (arguments.containsKey(AccessibilitySettings.EXTRA_SUMMARY)) { if (arguments.containsKey(AccessibilitySettings.EXTRA_SUMMARY)) {
final CharSequence summary = arguments.getCharSequence( final CharSequence summary = arguments.getCharSequence(
AccessibilitySettings.EXTRA_SUMMARY); AccessibilitySettings.EXTRA_SUMMARY);
mSummaryPreference.setSummary(summary); mFooterPreferenceMixin.createFooterPreference().setTitle(summary);
} else {
getPreferenceScreen().removePreference(mSummaryPreference);
} }
} }
} }

View File

@@ -144,7 +144,6 @@ public class ToggleScreenMagnificationPreferenceFragment extends
final PreferenceScreen preferenceScreen = getPreferenceManager().getPreferenceScreen(); final PreferenceScreen preferenceScreen = getPreferenceManager().getPreferenceScreen();
preferenceScreen.setOrderingAsAdded(false); preferenceScreen.setOrderingAsAdded(false);
mVideoPreference.setOrder(0); mVideoPreference.setOrder(0);
mSummaryPreference.setOrder(1);
mConfigWarningPreference.setOrder(2); mConfigWarningPreference.setOrder(2);
preferenceScreen.addPreference(mVideoPreference); preferenceScreen.addPreference(mVideoPreference);
preferenceScreen.addPreference(mConfigWarningPreference); preferenceScreen.addPreference(mConfigWarningPreference);

View File

@@ -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;
}
}
}