Accessibility Service & Shortcut Redesign - Primary action - toggle button design

Implements DividerSwitchPreference to replace ToggleSwitch

Bug: 142528112
Test: Manual test

Change-Id: I0d80d16bfa941f7ee333a2c5680a25a26c42809d
This commit is contained in:
menghanli
2020-02-03 22:12:45 +08:00
parent da645144e0
commit 6eb3912f31
17 changed files with 246 additions and 156 deletions

View File

@@ -53,7 +53,7 @@
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory <PreferenceCategory
android:key="daltonizer_footer_category" > android:key="daltonizer_footer_category">
<com.android.settingslib.widget.FooterPreference <com.android.settingslib.widget.FooterPreference
android:key="daltonizer_footer" android:key="daltonizer_footer"

View File

@@ -14,21 +14,22 @@
limitations under the License. limitations under the License.
--> -->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res-auto" xmlns:settings="http://schemas.android.com/apk/res-auto"
android:title="@string/accessibility_global_gesture_preference_title" > android:title="@string/accessibility_global_gesture_preference_title">
<Preference <Preference
android:key="accessibility_shortcut_service" android:fragment="com.android.settings.accessibility.ShortcutServicePickerFragment"
android:title="@string/accessibility_shortcut_service_title" android:key="accessibility_shortcut_service"
android:fragment="com.android.settings.accessibility.ShortcutServicePickerFragment"/> android:title="@string/accessibility_shortcut_service_title" />
<SwitchPreference <SwitchPreference
android:key="accessibility_shortcut_on_lock_screen" android:key="accessibility_shortcut_on_lock_screen"
android:title="@string/accessibility_shortcut_service_on_lock_screen_title"/> android:title="@string/accessibility_shortcut_service_on_lock_screen_title" />
<com.android.settingslib.widget.FooterPreference <com.android.settingslib.widget.FooterPreference
android:key="accessibility_shortcut_footer" android:key="accessibility_shortcut_footer"
android:title="@string/accessibility_shortcut_description"
android:selectable="false" android:selectable="false"
settings:searchable="false"/> android:title="@string/accessibility_shortcut_description"
settings:searchable="false" />
</PreferenceScreen> </PreferenceScreen>

View File

@@ -15,6 +15,9 @@
*/ */
package com.android.settings.accessibility; package com.android.settings.accessibility;
import static com.android.settings.accessibility.AccessibilityUtil.State.OFF;
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
import android.accessibilityservice.AccessibilityServiceInfo; import android.accessibilityservice.AccessibilityServiceInfo;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.app.settings.SettingsEnums; import android.app.settings.SettingsEnums;
@@ -28,15 +31,14 @@ import android.os.UserHandle;
import android.provider.Settings; import android.provider.Settings;
import android.view.View; import android.view.View;
import android.view.accessibility.AccessibilityManager; import android.view.accessibility.AccessibilityManager;
import android.widget.Switch;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference; import androidx.preference.SwitchPreference;
import com.android.internal.accessibility.AccessibilityShortcutController; import com.android.internal.accessibility.AccessibilityShortcutController;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.widget.SwitchBar;
import com.android.settingslib.accessibility.AccessibilityUtils; import com.android.settingslib.accessibility.AccessibilityUtils;
import com.android.settingslib.search.Indexable; import com.android.settingslib.search.Indexable;
import com.android.settingslib.search.SearchIndexable; import com.android.settingslib.search.SearchIndexable;
@@ -79,7 +81,7 @@ public class AccessibilityShortcutPreferenceFragment extends ToggleFeaturePrefer
mOnLockScreenSwitchPreference.setOnPreferenceChangeListener((Preference p, Object o) -> { mOnLockScreenSwitchPreference.setOnPreferenceChangeListener((Preference p, Object o) -> {
Settings.Secure.putInt(getContentResolver(), Settings.Secure.putInt(getContentResolver(),
Settings.Secure.ACCESSIBILITY_SHORTCUT_ON_LOCK_SCREEN, Settings.Secure.ACCESSIBILITY_SHORTCUT_ON_LOCK_SCREEN,
((Boolean) o) ? 1 : 0); ((Boolean) o) ? ON : OFF);
return true; return true;
}); });
} }
@@ -87,7 +89,12 @@ public class AccessibilityShortcutPreferenceFragment extends ToggleFeaturePrefer
@Override @Override
public void onViewCreated(View view, Bundle savedInstanceState) { public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
mShortcutPreference.setVisible(false);
final PreferenceScreen preferenceScreen = getPreferenceScreen();
preferenceScreen.findPreference(KEY_GENERAL_CATEGORY).setVisible(false);
preferenceScreen.setOrderingAsAdded(false);
mToggleServiceDividerSwitchPreference.setOrder(mServicePreference.getOrder() - 1);
} }
@Override @Override
@@ -111,34 +118,42 @@ public class AccessibilityShortcutPreferenceFragment extends ToggleFeaturePrefer
} }
@Override @Override
protected void onInstallSwitchBarToggleSwitch() { protected void onRemoveSwitchPreferenceToggleSwitch() {
super.onInstallSwitchBarToggleSwitch(); super.onRemoveSwitchPreferenceToggleSwitch();
mSwitchBar.addOnSwitchChangeListener((Switch switchView, boolean enabled) -> { mToggleServiceDividerSwitchPreference.setOnPreferenceClickListener(null);
}
@Override
protected void onInstallSwitchPreferenceToggleSwitch() {
super.onInstallSwitchPreferenceToggleSwitch();
mToggleServiceDividerSwitchPreference.setOnPreferenceClickListener((preference) -> {
boolean enabled = ((SwitchPreference) preference).isChecked();
Context context = getContext(); Context context = getContext();
if (enabled && !shortcutFeatureAvailable(context)) { if (enabled && !shortcutFeatureAvailable(context)) {
// If no service is configured, we'll disable the shortcut shortly. Give the // If no service is configured, we'll disable the shortcut shortly. Give the user
// user a chance to select a service. We'll update the preferences when we resume. // a chance to select a service. We'll update the preferences when we resume.
Settings.Secure.putInt( Settings.Secure.putInt(getContentResolver(),
getContentResolver(), Settings.Secure.ACCESSIBILITY_SHORTCUT_ENABLED, 1); Settings.Secure.ACCESSIBILITY_SHORTCUT_ENABLED, ON);
mServicePreference.setEnabled(true); mServicePreference.setEnabled(true);
mServicePreference.performClick(); mServicePreference.performClick();
} else { } else {
onPreferenceToggled(Settings.Secure.ACCESSIBILITY_SHORTCUT_ENABLED, enabled); onPreferenceToggled(Settings.Secure.ACCESSIBILITY_SHORTCUT_ENABLED, enabled);
} }
return true;
}); });
} }
@Override @Override
protected void onPreferenceToggled(String preferenceKey, boolean enabled) { protected void onPreferenceToggled(String preferenceKey, boolean enabled) {
Settings.Secure.putInt(getContentResolver(), preferenceKey, enabled ? 1 : 0); Settings.Secure.putInt(getContentResolver(), preferenceKey, enabled ? ON : OFF);
updatePreferences(); updatePreferences();
} }
@Override @Override
protected void updateSwitchBarText(SwitchBar switchBar) { protected void updateToggleServiceTitle(SwitchPreference switchPreference) {
final String switchBarText = getString(R.string.accessibility_service_master_switch_title, final String switchBarText = getString(R.string.accessibility_service_master_switch_title,
getString(R.string.accessibility_global_gesture_preference_title)); getString(R.string.accessibility_global_gesture_preference_title));
switchBar.setSwitchBarText(switchBarText, switchBarText); switchPreference.setTitle(switchBarText);
} }
private void updatePreferences() { private void updatePreferences() {
@@ -148,21 +163,21 @@ public class AccessibilityShortcutPreferenceFragment extends ToggleFeaturePrefer
if (!shortcutFeatureAvailable(context)) { if (!shortcutFeatureAvailable(context)) {
// If no service is configured, make sure the overall shortcut is turned off // If no service is configured, make sure the overall shortcut is turned off
Settings.Secure.putInt( Settings.Secure.putInt(
getContentResolver(), Settings.Secure.ACCESSIBILITY_SHORTCUT_ENABLED, 0); getContentResolver(), Settings.Secure.ACCESSIBILITY_SHORTCUT_ENABLED, OFF);
} }
boolean isEnabled = Settings.Secure boolean isEnabled = Settings.Secure
.getInt(cr, Settings.Secure.ACCESSIBILITY_SHORTCUT_ENABLED, 1) == 1; .getInt(cr, Settings.Secure.ACCESSIBILITY_SHORTCUT_ENABLED, ON) == ON;
mSwitchBar.setChecked(isEnabled); mToggleServiceDividerSwitchPreference.setChecked(isEnabled);
// The shortcut is enabled by default on the lock screen as long as the user has // The shortcut is enabled by default on the lock screen as long as the user has
// enabled the shortcut with the warning dialog // enabled the shortcut with the warning dialog
final int dialogShown = Settings.Secure.getInt( final int dialogShown = Settings.Secure.getInt(
cr, Settings.Secure.ACCESSIBILITY_SHORTCUT_DIALOG_SHOWN, 0); cr, Settings.Secure.ACCESSIBILITY_SHORTCUT_DIALOG_SHOWN, OFF);
final boolean enabledFromLockScreen = Settings.Secure.getInt( final boolean enabledFromLockScreen = Settings.Secure.getInt(
cr, Settings.Secure.ACCESSIBILITY_SHORTCUT_ON_LOCK_SCREEN, dialogShown) == 1; cr, Settings.Secure.ACCESSIBILITY_SHORTCUT_ON_LOCK_SCREEN, dialogShown) == ON;
mOnLockScreenSwitchPreference.setChecked(enabledFromLockScreen); mOnLockScreenSwitchPreference.setChecked(enabledFromLockScreen);
// Only enable changing the service and lock screen behavior if the shortcut is on // Only enable changing the service and lock screen behavior if the shortcut is on
mServicePreference.setEnabled(mToggleSwitch.isChecked()); mServicePreference.setEnabled(mToggleServiceDividerSwitchPreference.isChecked());
mOnLockScreenSwitchPreference.setEnabled(mToggleSwitch.isChecked()); mOnLockScreenSwitchPreference.setEnabled(mToggleServiceDividerSwitchPreference.isChecked());
} }
/** /**

View File

@@ -0,0 +1,69 @@
/*
* Copyright (C) 2020 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 android.content.Context;
import androidx.preference.PreferenceViewHolder;
import androidx.preference.SwitchPreference;
/**
* A switch preference that has a divider below and above. Used for Accessibility Settings use
* service.
*/
public final class DividerSwitchPreference extends SwitchPreference {
private Boolean mDividerAllowedAbove;
private Boolean mDividerAllowBelow;
public DividerSwitchPreference(Context context) {
super(context);
mDividerAllowedAbove = true;
mDividerAllowBelow = true;
}
/**
* Sets divider whether to show in preference above.
*
* @param allowed true will be drawn on above this item
*/
public void setDividerAllowedAbove(boolean allowed) {
if (mDividerAllowedAbove != allowed) {
mDividerAllowedAbove = allowed;
notifyChanged();
}
}
/**
* Sets divider whether to show in preference below.
*
* @param allowed true will be drawn on below this item
*/
public void setDividerAllowedBelow(boolean allowed) {
if (mDividerAllowedAbove != allowed) {
mDividerAllowBelow = allowed;
notifyChanged();
}
}
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
holder.setDividerAllowedAbove(mDividerAllowedAbove);
holder.setDividerAllowedBelow(mDividerAllowBelow);
}
}

View File

@@ -17,29 +17,27 @@
package com.android.settings.accessibility; package com.android.settings.accessibility;
import android.accessibilityservice.AccessibilityServiceInfo; import android.accessibilityservice.AccessibilityServiceInfo;
import android.os.Bundle;
import android.view.View; import android.view.View;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.widget.SwitchBar;
import com.android.settingslib.accessibility.AccessibilityUtils; import com.android.settingslib.accessibility.AccessibilityUtils;
/** /**
* For accessibility services that target SDK > Q, and * Fragment that does not have toggle bar to turn on service to use.
* {@link AccessibilityServiceInfo#FLAG_REQUEST_ACCESSIBILITY_BUTTON} *
* is set. * <p>The child {@link ToggleAccessibilityServicePreferenceFragment} shows the actual UI for
* providing basic accessibility service setup.
*
* <p>For accessibility services that target SDK > Q, and
* {@link AccessibilityServiceInfo#FLAG_REQUEST_ACCESSIBILITY_BUTTON} is set.
*/ */
public class InvisibleToggleAccessibilityServicePreferenceFragment extends public class InvisibleToggleAccessibilityServicePreferenceFragment extends
ToggleAccessibilityServicePreferenceFragment implements ShortcutPreference.OnClickListener{ ToggleAccessibilityServicePreferenceFragment implements ShortcutPreference.OnClickListener{
@Override @Override
public void onActivityCreated(Bundle savedInstanceState) { protected void onInstallSwitchPreferenceToggleSwitch() {
super.onActivityCreated(savedInstanceState); super.onInstallSwitchPreferenceToggleSwitch();
mToggleServiceDividerSwitchPreference.setVisible(false);
final SettingsActivity activity = (SettingsActivity) getActivity();
final SwitchBar mSwitchBar = activity.getSwitchBar();
mSwitchBar.hide();
} }
/** /**

View File

@@ -25,7 +25,14 @@ import com.android.settings.R;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
/** For accessibility services that target SDK <= Q. */ /**
* Fragment that only allowed hardware {@link UserShortcutType} for shortcut to open.
*
* <p>The child {@link ToggleAccessibilityServicePreferenceFragment} shows the actual UI for
* providing basic accessibility service setup.
*
* <p>For accessibility services that target SDK <= Q.
*/
public class LegacyAccessibilityServicePreferenceFragment extends public class LegacyAccessibilityServicePreferenceFragment extends
ToggleAccessibilityServicePreferenceFragment { ToggleAccessibilityServicePreferenceFragment {
@@ -38,7 +45,6 @@ public class LegacyAccessibilityServicePreferenceFragment extends
mShortcutPreference.setSummary(hardwareTitle); mShortcutPreference.setSummary(hardwareTitle);
mShortcutPreference.setSettingsVisibility(View.GONE); mShortcutPreference.setSettingsVisibility(View.GONE);
// Only allowed hardware PreferredShortcutType in this fragment.
setAllowedPreferredShortcutType(UserShortcutType.HARDWARE); setAllowedPreferredShortcutType(UserShortcutType.HARDWARE);
} }

View File

@@ -28,7 +28,7 @@ public class LegacyToggleScreenReaderPreferenceFragmentForSetupWizard
@Override @Override
protected void onProcessArguments(Bundle arguments) { protected void onProcessArguments(Bundle arguments) {
super.onProcessArguments(arguments); super.onProcessArguments(arguments);
mToggleSwitchWasInitiallyChecked = mToggleSwitch.isChecked(); mToggleSwitchWasInitiallyChecked = mToggleServiceDividerSwitchPreference.isChecked();
} }
@Override @Override
@@ -39,10 +39,10 @@ public class LegacyToggleScreenReaderPreferenceFragmentForSetupWizard
@Override @Override
public void onStop() { public void onStop() {
// Log the final choice in value if it's different from the previous value. // Log the final choice in value if it's different from the previous value.
if (mToggleSwitch.isChecked() != mToggleSwitchWasInitiallyChecked) { if (mToggleServiceDividerSwitchPreference.isChecked() != mToggleSwitchWasInitiallyChecked) {
mMetricsFeatureProvider.action(getContext(), mMetricsFeatureProvider.action(getContext(),
SettingsEnums.SUW_ACCESSIBILITY_TOGGLE_SCREEN_READER, SettingsEnums.SUW_ACCESSIBILITY_TOGGLE_SCREEN_READER,
mToggleSwitch.isChecked()); mToggleServiceDividerSwitchPreference.isChecked());
} }
super.onStop(); super.onStop();

View File

@@ -28,7 +28,7 @@ public class LegacyToggleSelectToSpeakPreferenceFragmentForSetupWizard
@Override @Override
protected void onProcessArguments(Bundle arguments) { protected void onProcessArguments(Bundle arguments) {
super.onProcessArguments(arguments); super.onProcessArguments(arguments);
mToggleSwitchWasInitiallyChecked = mToggleSwitch.isChecked(); mToggleSwitchWasInitiallyChecked = mToggleServiceDividerSwitchPreference.isChecked();
} }
@Override @Override
@@ -39,10 +39,10 @@ public class LegacyToggleSelectToSpeakPreferenceFragmentForSetupWizard
@Override @Override
public void onStop() { public void onStop() {
// Log the final choice in value if it's different from the previous value. // Log the final choice in value if it's different from the previous value.
if (mToggleSwitch.isChecked() != mToggleSwitchWasInitiallyChecked) { if (mToggleServiceDividerSwitchPreference.isChecked() != mToggleSwitchWasInitiallyChecked) {
mMetricsFeatureProvider.action(getContext(), mMetricsFeatureProvider.action(getContext(),
SettingsEnums.SUW_ACCESSIBILITY_TOGGLE_SELECT_TO_SPEAK, SettingsEnums.SUW_ACCESSIBILITY_TOGGLE_SELECT_TO_SPEAK,
mToggleSwitch.isChecked()); mToggleServiceDividerSwitchPreference.isChecked());
} }
super.onStop(); super.onStop();

View File

@@ -39,12 +39,13 @@ import android.view.MenuInflater;
import android.view.View; import android.view.View;
import android.view.accessibility.AccessibilityManager; import android.view.accessibility.AccessibilityManager;
import androidx.preference.Preference;
import androidx.preference.SwitchPreference;
import com.android.internal.widget.LockPatternUtils; import com.android.internal.widget.LockPatternUtils;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.accessibility.AccessibilityUtil.UserShortcutType; import com.android.settings.accessibility.AccessibilityUtil.UserShortcutType;
import com.android.settings.password.ConfirmDeviceCredentialActivity; import com.android.settings.password.ConfirmDeviceCredentialActivity;
import com.android.settings.widget.SwitchBar;
import com.android.settings.widget.ToggleSwitch;
import com.android.settingslib.accessibility.AccessibilityUtils; import com.android.settingslib.accessibility.AccessibilityUtils;
import java.util.List; import java.util.List;
@@ -186,21 +187,21 @@ public class ToggleAccessibilityServicePreferenceFragment extends
} }
@Override @Override
protected void updateSwitchBarText(SwitchBar switchBar) { protected void updateToggleServiceTitle(SwitchPreference switchPreference) {
final AccessibilityServiceInfo info = getAccessibilityServiceInfo(); final AccessibilityServiceInfo info = getAccessibilityServiceInfo();
final String switchBarText = (info == null) ? "" : final String switchBarText = (info == null) ? "" :
getString(R.string.accessibility_service_master_switch_title, getString(R.string.accessibility_service_master_switch_title,
info.getResolveInfo().loadLabel(getPackageManager())); info.getResolveInfo().loadLabel(getPackageManager()));
switchBar.setSwitchBarText(switchBarText, switchBarText); switchPreference.setTitle(switchBarText);
} }
private void updateSwitchBarToggleSwitch() { private void updateSwitchBarToggleSwitch() {
final boolean checked = AccessibilityUtils.getEnabledServicesFromSettings(getPrefContext()) final boolean checked = AccessibilityUtils.getEnabledServicesFromSettings(getPrefContext())
.contains(mComponentName); .contains(mComponentName);
if (mSwitchBar.isChecked() == checked) { if (mToggleServiceDividerSwitchPreference.isChecked() == checked) {
return; return;
} }
mSwitchBar.setCheckedInternal(checked); mToggleServiceDividerSwitchPreference.setChecked(checked);
} }
/** /**
@@ -251,7 +252,7 @@ public class ToggleAccessibilityServicePreferenceFragment extends
} }
private void handleConfirmServiceEnabled(boolean confirmed) { private void handleConfirmServiceEnabled(boolean confirmed) {
mSwitchBar.setCheckedInternal(confirmed); mToggleServiceDividerSwitchPreference.setChecked(confirmed);
getArguments().putBoolean(AccessibilitySettings.EXTRA_CHECKED, confirmed); getArguments().putBoolean(AccessibilitySettings.EXTRA_CHECKED, confirmed);
onPreferenceToggled(mPreferenceKey, confirmed); onPreferenceToggled(mPreferenceKey, confirmed);
} }
@@ -274,9 +275,9 @@ public class ToggleAccessibilityServicePreferenceFragment extends
} }
@Override @Override
protected void onInstallSwitchBarToggleSwitch() { protected void onInstallSwitchPreferenceToggleSwitch() {
super.onInstallSwitchBarToggleSwitch(); super.onInstallSwitchPreferenceToggleSwitch();
mToggleSwitch.setOnBeforeCheckedChangeListener(this::onBeforeCheckedChanged); mToggleServiceDividerSwitchPreference.setOnPreferenceClickListener(this::onPreferenceClick);
} }
@Override @Override
@@ -410,9 +411,10 @@ public class ToggleAccessibilityServicePreferenceFragment extends
mDialog.dismiss(); mDialog.dismiss();
} }
private boolean onBeforeCheckedChanged(ToggleSwitch toggleSwitch, boolean checked) { private boolean onPreferenceClick(Preference preference) {
boolean checked = ((DividerSwitchPreference) preference).isChecked();
if (checked) { if (checked) {
mSwitchBar.setCheckedInternal(false); mToggleServiceDividerSwitchPreference.setChecked(false);
getArguments().putBoolean(AccessibilitySettings.EXTRA_CHECKED, getArguments().putBoolean(AccessibilitySettings.EXTRA_CHECKED,
/* disableService */ false); /* disableService */ false);
if (!mShortcutPreference.getChecked()) { if (!mShortcutPreference.getChecked()) {
@@ -424,7 +426,7 @@ public class ToggleAccessibilityServicePreferenceFragment extends
} }
} }
} else { } else {
mSwitchBar.setCheckedInternal(true); mToggleServiceDividerSwitchPreference.setChecked(true);
getArguments().putBoolean(AccessibilitySettings.EXTRA_CHECKED, getArguments().putBoolean(AccessibilitySettings.EXTRA_CHECKED,
/* enableService */ true); /* enableService */ true);
showDialog(DialogEnums.DISABLE_WARNING_FROM_TOGGLE); showDialog(DialogEnums.DISABLE_WARNING_FROM_TOGGLE);

View File

@@ -31,10 +31,10 @@ import android.view.ViewGroup;
import androidx.preference.PreferenceCategory; import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.widget.SwitchBar;
import com.android.settingslib.search.SearchIndexable; import com.android.settingslib.search.SearchIndexable;
import java.util.ArrayList; import java.util.ArrayList;
@@ -66,22 +66,22 @@ public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePrefere
} }
@Override @Override
protected void onRemoveSwitchBarToggleSwitch() { protected void onRemoveSwitchPreferenceToggleSwitch() {
super.onRemoveSwitchBarToggleSwitch(); super.onRemoveSwitchPreferenceToggleSwitch();
mToggleSwitch.setOnBeforeCheckedChangeListener(null); mToggleServiceDividerSwitchPreference.setOnPreferenceClickListener(null);
} }
@Override @Override
protected void updateSwitchBarText(SwitchBar switchBar) { protected void updateToggleServiceTitle(SwitchPreference switchPreference) {
switchBar.setSwitchBarText(R.string.accessibility_display_inversion_switch_title, switchPreference.setTitle(R.string.accessibility_display_inversion_switch_title);
R.string.accessibility_display_inversion_switch_title);
} }
@Override @Override
protected void onInstallSwitchBarToggleSwitch() { protected void onInstallSwitchPreferenceToggleSwitch() {
super.onInstallSwitchBarToggleSwitch(); super.onInstallSwitchPreferenceToggleSwitch();
updateSwitchBarToggleSwitch(); updateSwitchBarToggleSwitch();
mToggleSwitch.setOnBeforeCheckedChangeListener((toggleSwitch, checked) -> { mToggleServiceDividerSwitchPreference.setOnPreferenceClickListener((preference) -> {
boolean checked = ((SwitchPreference) preference).isChecked();
onPreferenceToggled(mPreferenceKey, checked); onPreferenceToggled(mPreferenceKey, checked);
return false; return false;
}); });
@@ -135,10 +135,10 @@ public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePrefere
private void updateSwitchBarToggleSwitch() { private void updateSwitchBarToggleSwitch() {
final boolean checked = Settings.Secure.getInt(getContentResolver(), ENABLED, OFF) == ON; final boolean checked = Settings.Secure.getInt(getContentResolver(), ENABLED, OFF) == ON;
if (mSwitchBar.isChecked() == checked) { if (mToggleServiceDividerSwitchPreference.isChecked() == checked) {
return; return;
} }
mSwitchBar.setCheckedInternal(checked); mToggleServiceDividerSwitchPreference.setChecked(checked);
} }
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =

View File

@@ -34,10 +34,10 @@ import android.view.ViewGroup;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.PreferenceCategory; import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.widget.SwitchBar;
import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.search.SearchIndexable; import com.android.settingslib.search.SearchIndexable;
@@ -51,6 +51,7 @@ public final class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePrefe
private static final String ENABLED = Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED; private static final String ENABLED = Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED;
private static final String CATEGORY_FOOTER_KEY = "daltonizer_footer_category"; private static final String CATEGORY_FOOTER_KEY = "daltonizer_footer_category";
private static final String CATEGORY_MODE_KEY = "daltonizer_mode_category";
private static final List<AbstractPreferenceController> sControllers = new ArrayList<>(); private static final List<AbstractPreferenceController> sControllers = new ArrayList<>();
private final Handler mHandler = new Handler(); private final Handler mHandler = new Handler();
private SettingsContentObserver mSettingsContentObserver; private SettingsContentObserver mSettingsContentObserver;
@@ -98,6 +99,11 @@ public final class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePrefe
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
final PreferenceScreen preferenceScreen = getPreferenceScreen(); final PreferenceScreen preferenceScreen = getPreferenceScreen();
preferenceScreen.setOrderingAsAdded(false); preferenceScreen.setOrderingAsAdded(false);
final PreferenceCategory modeCategory = preferenceScreen.findPreference(
CATEGORY_MODE_KEY);
modeCategory.setOrder(Integer.MAX_VALUE - 1);
final PreferenceCategory footerCategory = preferenceScreen.findPreference( final PreferenceCategory footerCategory = preferenceScreen.findPreference(
CATEGORY_FOOTER_KEY); CATEGORY_FOOTER_KEY);
footerCategory.setOrder(Integer.MAX_VALUE); footerCategory.setOrder(Integer.MAX_VALUE);
@@ -148,22 +154,22 @@ public final class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePrefe
} }
@Override @Override
protected void onRemoveSwitchBarToggleSwitch() { protected void onRemoveSwitchPreferenceToggleSwitch() {
super.onRemoveSwitchBarToggleSwitch(); super.onRemoveSwitchPreferenceToggleSwitch();
mToggleSwitch.setOnBeforeCheckedChangeListener(null); mToggleServiceDividerSwitchPreference.setOnPreferenceClickListener(null);
} }
@Override @Override
protected void updateSwitchBarText(SwitchBar switchBar) { protected void updateToggleServiceTitle(SwitchPreference switchPreference) {
switchBar.setSwitchBarText(R.string.accessibility_daltonizer_master_switch_title, switchPreference.setTitle(R.string.accessibility_daltonizer_master_switch_title);
R.string.accessibility_daltonizer_master_switch_title);
} }
@Override @Override
protected void onInstallSwitchBarToggleSwitch() { protected void onInstallSwitchPreferenceToggleSwitch() {
super.onInstallSwitchBarToggleSwitch(); super.onInstallSwitchPreferenceToggleSwitch();
updateSwitchBarToggleSwitch(); updateSwitchBarToggleSwitch();
mToggleSwitch.setOnBeforeCheckedChangeListener((toggleSwitch, checked) -> { mToggleServiceDividerSwitchPreference.setOnPreferenceClickListener((preference) -> {
boolean checked = ((SwitchPreference) preference).isChecked();
onPreferenceToggled(mPreferenceKey, checked); onPreferenceToggled(mPreferenceKey, checked);
return false; return false;
}); });
@@ -177,10 +183,10 @@ public final class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePrefe
private void updateSwitchBarToggleSwitch() { private void updateSwitchBarToggleSwitch() {
final boolean checked = Settings.Secure.getInt(getContentResolver(), ENABLED, OFF) == ON; final boolean checked = Settings.Secure.getInt(getContentResolver(), ENABLED, OFF) == ON;
if (mSwitchBar.isChecked() == checked) { if (mToggleServiceDividerSwitchPreference.isChecked() == checked) {
return; return;
} }
mSwitchBar.setCheckedInternal(checked); mToggleServiceDividerSwitchPreference.setChecked(checked);
} }
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =

View File

@@ -40,13 +40,13 @@ import android.widget.ImageView;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.PreferenceCategory; import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.SettingsActivity; import com.android.settings.SettingsActivity;
import com.android.settings.SettingsPreferenceFragment; import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.accessibility.AccessibilityUtil.UserShortcutType; import com.android.settings.accessibility.AccessibilityUtil.UserShortcutType;
import com.android.settings.widget.SwitchBar; import com.android.settings.widget.SwitchBar;
import com.android.settings.widget.ToggleSwitch;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
@@ -64,8 +64,7 @@ import java.util.stream.Collectors;
public abstract class ToggleFeaturePreferenceFragment extends SettingsPreferenceFragment public abstract class ToggleFeaturePreferenceFragment extends SettingsPreferenceFragment
implements ShortcutPreference.OnClickListener { implements ShortcutPreference.OnClickListener {
protected SwitchBar mSwitchBar; protected DividerSwitchPreference mToggleServiceDividerSwitchPreference;
protected ToggleSwitch mToggleSwitch;
protected ShortcutPreference mShortcutPreference; protected ShortcutPreference mShortcutPreference;
protected Preference mSettingsPreference; protected Preference mSettingsPreference;
protected String mPreferenceKey; protected String mPreferenceKey;
@@ -80,7 +79,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
protected CharSequence mHtmlDescription; protected CharSequence mHtmlDescription;
private static final String ANCHOR_TAG = "a"; private static final String ANCHOR_TAG = "a";
private static final String DRAWABLE_FOLDER = "drawable"; private static final String DRAWABLE_FOLDER = "drawable";
protected static final String KEY_GENERAL_CATEGORY = "categories";
private static final String KEY_SHORTCUT_PREFERENCE = "shortcut_preference"; private static final String KEY_SHORTCUT_PREFERENCE = "shortcut_preference";
private static final String EXTRA_SHORTCUT_TYPE = "shortcut_type"; private static final String EXTRA_SHORTCUT_TYPE = "shortcut_type";
private TouchExplorationStateChangeListener mTouchExplorationStateChangeListener; private TouchExplorationStateChangeListener mTouchExplorationStateChangeListener;
@@ -133,12 +132,9 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
public void onViewCreated(View view, Bundle savedInstanceState) { public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
SettingsActivity activity = (SettingsActivity) getActivity(); final SettingsActivity activity = (SettingsActivity) getActivity();
mSwitchBar = activity.getSwitchBar(); final SwitchBar switchBar = activity.getSwitchBar();
mToggleSwitch = mSwitchBar.getSwitch(); switchBar.hide();
onProcessArguments(getArguments());
updateSwitchBarText(mSwitchBar);
PreferenceScreen preferenceScreen = getPreferenceScreen(); PreferenceScreen preferenceScreen = getPreferenceScreen();
if (mImageUri != null) { if (mImageUri != null) {
@@ -149,12 +145,19 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
preferenceScreen.addPreference(animatedImagePreference); preferenceScreen.addPreference(animatedImagePreference);
} }
final PreferenceCategory category = new PreferenceCategory(getPrefContext()); mToggleServiceDividerSwitchPreference = new DividerSwitchPreference(getPrefContext());
category.setTitle(R.string.accessibility_screen_option); preferenceScreen.addPreference(mToggleServiceDividerSwitchPreference);
preferenceScreen.addPreference(category);
onProcessArguments(getArguments());
updateToggleServiceTitle(mToggleServiceDividerSwitchPreference);
final PreferenceCategory groupCategory = new PreferenceCategory(getPrefContext());
groupCategory.setKey(KEY_GENERAL_CATEGORY);
groupCategory.setTitle(R.string.accessibility_screen_option);
preferenceScreen.addPreference(groupCategory);
initShortcutPreference(savedInstanceState); initShortcutPreference(savedInstanceState);
category.addPreference(mShortcutPreference); groupCategory.addPreference(mShortcutPreference);
// Show the "Settings" menu as if it were a preference screen. // Show the "Settings" menu as if it were a preference screen.
if (mSettingsTitle != null && mSettingsIntent != null) { if (mSettingsTitle != null && mSettingsIntent != null) {
@@ -166,7 +169,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
// The downloaded app may not show Settings. The framework app has Settings. // The downloaded app may not show Settings. The framework app has Settings.
if (mSettingsPreference != null) { if (mSettingsPreference != null) {
category.addPreference(mSettingsPreference); groupCategory.addPreference(mSettingsPreference);
} }
if (mStaticDescription != null || mHtmlDescription != null) { if (mStaticDescription != null || mHtmlDescription != null) {
@@ -311,31 +314,27 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
removeActionBarToggleSwitch(); removeActionBarToggleSwitch();
} }
protected void updateSwitchBarText(SwitchBar switchBar) { protected void updateToggleServiceTitle(SwitchPreference switchPreference) {
// Implement this to provide meaningful text in switch bar. switchPreference.setTitle(R.string.accessibility_service_master_switch_title);
switchBar.setSwitchBarText(R.string.accessibility_service_master_switch_title,
R.string.accessibility_service_master_switch_title);
} }
protected abstract void onPreferenceToggled(String preferenceKey, boolean enabled); protected abstract void onPreferenceToggled(String preferenceKey, boolean enabled);
protected void onInstallSwitchBarToggleSwitch() { protected void onInstallSwitchPreferenceToggleSwitch() {
// Implement this to set a checked listener. // Implement this to set a checked listener.
} }
protected void onRemoveSwitchBarToggleSwitch() { protected void onRemoveSwitchPreferenceToggleSwitch() {
// Implement this to reset a checked listener. // Implement this to reset a checked listener.
} }
private void installActionBarToggleSwitch() { private void installActionBarToggleSwitch() {
mSwitchBar.show(); onInstallSwitchPreferenceToggleSwitch();
onInstallSwitchBarToggleSwitch();
} }
private void removeActionBarToggleSwitch() { private void removeActionBarToggleSwitch() {
mToggleSwitch.setOnBeforeCheckedChangeListener(null); mToggleServiceDividerSwitchPreference.setOnPreferenceClickListener(null);
onRemoveSwitchBarToggleSwitch(); onRemoveSwitchPreferenceToggleSwitch();
mSwitchBar.hide();
} }
public void setTitle(String title) { public void setTitle(String title) {
@@ -349,7 +348,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
// Enabled. // Enabled.
if (arguments.containsKey(AccessibilitySettings.EXTRA_CHECKED)) { if (arguments.containsKey(AccessibilitySettings.EXTRA_CHECKED)) {
final boolean enabled = arguments.getBoolean(AccessibilitySettings.EXTRA_CHECKED); final boolean enabled = arguments.getBoolean(AccessibilitySettings.EXTRA_CHECKED);
mSwitchBar.setCheckedInternal(enabled); mToggleServiceDividerSwitchPreference.setChecked(enabled);
} }
// Title. // Title.
@@ -493,8 +492,9 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
if (info.isEmpty()) { if (info.isEmpty()) {
info = new HashSet<>(); info = new HashSet<>();
} else { } else {
final Set<String> filtered = info.stream().filter( final Set<String> filtered = info.stream()
str -> str.contains(componentName)).collect(Collectors.toSet()); .filter(str -> str.contains(componentName))
.collect(Collectors.toSet());
info.removeAll(filtered); info.removeAll(filtered);
} }
final AccessibilityUserShortcutType shortcut = new AccessibilityUserShortcutType( final AccessibilityUserShortcutType shortcut = new AccessibilityUserShortcutType(
@@ -538,9 +538,9 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
final Set<String> info = SharedPreferenceUtils.getUserShortcutType(context); final Set<String> info = SharedPreferenceUtils.getUserShortcutType(context);
final String componentName = mComponentName.flattenToString(); final String componentName = mComponentName.flattenToString();
final Set<String> filtered = info.stream().filter( final Set<String> filtered = info.stream()
str -> str.contains(componentName)).collect( .filter(str -> str.contains(componentName))
Collectors.toSet()); .collect(Collectors.toSet());
if (filtered.isEmpty()) { if (filtered.isEmpty()) {
return defaultValue; return defaultValue;
} }

View File

@@ -60,10 +60,13 @@ import java.util.Set;
import java.util.StringJoiner; import java.util.StringJoiner;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/**
* Fragment that shows the actual UI for providing basic magnification accessibility service setup
* and does not have toggle bar to turn on service to use.
*/
public class ToggleScreenMagnificationPreferenceFragment extends public class ToggleScreenMagnificationPreferenceFragment extends
ToggleFeaturePreferenceFragment { ToggleFeaturePreferenceFragment {
private static final String SETTINGS_KEY = "screen_magnification_settings";
private static final String EXTRA_SHORTCUT_TYPE = "shortcut_type"; private static final String EXTRA_SHORTCUT_TYPE = "shortcut_type";
private static final String KEY_SHORTCUT_PREFERENCE = "shortcut_preference"; private static final String KEY_SHORTCUT_PREFERENCE = "shortcut_preference";
private TouchExplorationStateChangeListener mTouchExplorationStateChangeListener; private TouchExplorationStateChangeListener mTouchExplorationStateChangeListener;
@@ -429,11 +432,9 @@ public class ToggleScreenMagnificationPreferenceFragment extends
} }
@Override @Override
protected void onInstallSwitchBarToggleSwitch() { protected void onInstallSwitchPreferenceToggleSwitch() {
super.onInstallSwitchBarToggleSwitch(); super.onInstallSwitchPreferenceToggleSwitch();
mToggleServiceDividerSwitchPreference.setVisible(false);
// Magnify is temporary-use app which uses shortcut to magnify screen, not by toggle.
mSwitchBar.hide();
} }
@Override @Override

View File

@@ -32,11 +32,12 @@ public class ToggleScreenMagnificationPreferenceFragmentForSetupWizard
// Log the final choice in value if it's different from the previous value. // Log the final choice in value if it's different from the previous value.
Bundle args = getArguments(); Bundle args = getArguments();
if ((args != null) && args.containsKey(AccessibilitySettings.EXTRA_CHECKED)) { if ((args != null) && args.containsKey(AccessibilitySettings.EXTRA_CHECKED)) {
if (mToggleSwitch.isChecked() != args.getBoolean(AccessibilitySettings.EXTRA_CHECKED)) { if (mToggleServiceDividerSwitchPreference.isChecked() != args.getBoolean(
AccessibilitySettings.EXTRA_CHECKED)) {
// TODO: Distinguish between magnification modes // TODO: Distinguish between magnification modes
mMetricsFeatureProvider.action(getContext(), mMetricsFeatureProvider.action(getContext(),
SettingsEnums.SUW_ACCESSIBILITY_TOGGLE_SCREEN_MAGNIFICATION, SettingsEnums.SUW_ACCESSIBILITY_TOGGLE_SCREEN_MAGNIFICATION,
mToggleSwitch.isChecked()); mToggleServiceDividerSwitchPreference.isChecked());
} }
} }
super.onStop(); super.onStop();

View File

@@ -27,7 +27,7 @@ public class ToggleScreenReaderPreferenceFragmentForSetupWizard
@Override @Override
protected void onProcessArguments(Bundle arguments) { protected void onProcessArguments(Bundle arguments) {
super.onProcessArguments(arguments); super.onProcessArguments(arguments);
mToggleSwitchWasInitiallyChecked = mToggleSwitch.isChecked(); mToggleSwitchWasInitiallyChecked = mToggleServiceDividerSwitchPreference.isChecked();
} }
@Override @Override
@@ -38,11 +38,11 @@ public class ToggleScreenReaderPreferenceFragmentForSetupWizard
@Override @Override
public void onStop() { public void onStop() {
// Log the final choice in value if it's different from the previous value. // Log the final choice in value if it's different from the previous value.
if (mToggleSwitch.isChecked() != mToggleSwitchWasInitiallyChecked) { if (mToggleServiceDividerSwitchPreference.isChecked() != mToggleSwitchWasInitiallyChecked) {
mMetricsFeatureProvider.action(getContext(), mMetricsFeatureProvider.action(getContext(),
SettingsEnums.SUW_ACCESSIBILITY_TOGGLE_SCREEN_READER, mToggleSwitch.isChecked()); SettingsEnums.SUW_ACCESSIBILITY_TOGGLE_SCREEN_READER,
mToggleServiceDividerSwitchPreference.isChecked());
} }
super.onStop(); super.onStop();
} }
} }

View File

@@ -27,7 +27,7 @@ public class ToggleSelectToSpeakPreferenceFragmentForSetupWizard
@Override @Override
protected void onProcessArguments(Bundle arguments) { protected void onProcessArguments(Bundle arguments) {
super.onProcessArguments(arguments); super.onProcessArguments(arguments);
mToggleSwitchWasInitiallyChecked = mToggleSwitch.isChecked(); mToggleSwitchWasInitiallyChecked = mToggleServiceDividerSwitchPreference.isChecked();
} }
@Override @Override
@@ -38,10 +38,10 @@ public class ToggleSelectToSpeakPreferenceFragmentForSetupWizard
@Override @Override
public void onStop() { public void onStop() {
// Log the final choice in value if it's different from the previous value. // Log the final choice in value if it's different from the previous value.
if (mToggleSwitch.isChecked() != mToggleSwitchWasInitiallyChecked) { if (mToggleServiceDividerSwitchPreference.isChecked() != mToggleSwitchWasInitiallyChecked) {
mMetricsFeatureProvider.action(getContext(), mMetricsFeatureProvider.action(getContext(),
SettingsEnums.SUW_ACCESSIBILITY_TOGGLE_SELECT_TO_SPEAK, SettingsEnums.SUW_ACCESSIBILITY_TOGGLE_SELECT_TO_SPEAK,
mToggleSwitch.isChecked()); mToggleServiceDividerSwitchPreference.isChecked());
} }
super.onStop(); super.onStop();

View File

@@ -32,7 +32,6 @@ import androidx.fragment.app.FragmentActivity;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.accessibility.ToggleFeaturePreferenceFragment.AccessibilityUserShortcutType; import com.android.settings.accessibility.ToggleFeaturePreferenceFragment.AccessibilityUserShortcutType;
import com.android.settings.widget.SwitchBar;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@@ -82,9 +81,9 @@ public class ToggleFeaturePreferenceFragmentTest {
mySet.add(TEST_SERVICE_KEY_2); mySet.add(TEST_SERVICE_KEY_2);
mySet.add(TEST_SERVICE_KEY_3); mySet.add(TEST_SERVICE_KEY_3);
final Set<String> filtered = mySet.stream().filter( final Set<String> filtered = mySet.stream()
str -> str.contains(TEST_SERVICE_NAME_1)).collect( .filter(str -> str.contains(TEST_SERVICE_NAME_1))
Collectors.toSet()); .collect(Collectors.toSet());
mySet.removeAll(filtered); mySet.removeAll(filtered);
assertThat(mySet).doesNotContain(TEST_SERVICE_KEY_1); assertThat(mySet).doesNotContain(TEST_SERVICE_KEY_1);
@@ -93,28 +92,26 @@ public class ToggleFeaturePreferenceFragmentTest {
@Test @Test
public void stringSet_convertA11yUserShortcutType_shouldReturnPreferredShortcut() { public void stringSet_convertA11yUserShortcutType_shouldReturnPreferredShortcut() {
int type = 0;
Set<String> mySet = new HashSet<>(); Set<String> mySet = new HashSet<>();
mySet.add(TEST_SERVICE_KEY_1); mySet.add(TEST_SERVICE_KEY_1);
mySet.add(TEST_SERVICE_KEY_2); mySet.add(TEST_SERVICE_KEY_2);
mySet.add(TEST_SERVICE_KEY_3); mySet.add(TEST_SERVICE_KEY_3);
final Set<String> filtered = mySet.stream().filter( final Set<String> filtered = mySet.stream()
str -> str.contains(TEST_SERVICE_NAME_1)).collect( .filter(str -> str.contains(TEST_SERVICE_NAME_1))
Collectors.toSet()); .collect(Collectors.toSet());
for (String str : filtered) {
final AccessibilityUserShortcutType shortcut = new AccessibilityUserShortcutType(str);
type = shortcut.getUserShortcutType();
}
final String str = (String) filtered.toArray()[0];
final AccessibilityUserShortcutType shortcut = new AccessibilityUserShortcutType(str);
final int type = shortcut.getUserShortcutType();
assertThat(type).isEqualTo(TEST_SERVICE_VALUE_1); assertThat(type).isEqualTo(TEST_SERVICE_VALUE_1);
} }
@Test @Test
public void createFragment_shouldOnlyAddPreferencesOnce() { public void createFragment_shouldOnlyAddPreferencesOnce() {
mFragment = spy(new ToggleFeaturePreferenceFragmentTestable()); mFragment = spy(new ToggleFeaturePreferenceFragmentTestable());
FragmentController.setupFragment(mFragment, FragmentActivity.class, 0 /* containerViewId*/, FragmentController.setupFragment(mFragment, FragmentActivity.class,
null /* bundle */); /* containerViewId= */ 0, /* bundle= */null);
// execute exactly once // execute exactly once
verify(mFragment).addPreferencesFromResource(R.xml.placeholder_prefs); verify(mFragment).addPreferencesFromResource(R.xml.placeholder_prefs);
@@ -152,11 +149,5 @@ public class ToggleFeaturePreferenceFragmentTest {
public void onViewCreated(View view, Bundle savedInstanceState) { public void onViewCreated(View view, Bundle savedInstanceState) {
// do nothing // do nothing
} }
@Override
public void onActivityCreated(Bundle savedInstanceState) {
mSwitchBar = mock(SwitchBar.class);
super.onActivityCreated(savedInstanceState);
}
} }
} }