Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ed5f0951 authored by Phil Weaver's avatar Phil Weaver
Browse files

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
parent 8e0754e8
Loading
Loading
Loading
Loading
+0 −6
Original line number Diff line number Diff line
@@ -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"
+12 −5
Original line number Diff line number Diff line
@@ -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;
+0 −9
Original line number Diff line number Diff line
@@ -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
+4 −0
Original line number Diff line number Diff line
@@ -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();
    }

+11 −49
Original line number Diff line number Diff line
@@ -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);
        }
    }
}
Loading