Merge "Update auto-rotate strings/toggles for better accessibility" into tm-dev

This commit is contained in:
TreeHugger Robot
2022-04-19 23:44:38 +00:00
committed by Android (Google) Code Review
5 changed files with 124 additions and 104 deletions

View File

@@ -98,10 +98,10 @@
<string name="font_size_make_larger_desc">Make larger</string> <string name="font_size_make_larger_desc">Make larger</string>
<!-- Auto rotate switchbar title. [CHAR_LIMIT=NONE] --> <!-- Auto rotate switchbar title. [CHAR_LIMIT=NONE] -->
<string name="auto_rotate_settings_primary_switch_title">Use Auto-rotate</string> <string name="auto_rotate_settings_primary_switch_title">Use auto-rotate</string>
<!-- Disclaimer for camera based rotate [CHAR_LIMIT=NONE] --> <!-- Disclaimer for camera based rotate [CHAR_LIMIT=NONE] -->
<string name="smart_rotate_text_headline">Face Detection uses the front-facing camera to improve Auto-rotate accuracy. Images are never stored or sent to Google.</string> <string name="smart_rotate_text_headline">Face Detection uses the front-facing camera to improve auto-rotate accuracy. Images are never stored or sent to Google.</string>
<string name="font_size_preview_text_headline">Sample text</string> <string name="font_size_preview_text_headline">Sample text</string>
<string name="font_size_preview_text_title" <string name="font_size_preview_text_title"
translation_description="Title text in sample text used to illustrate how the currently selected font size will appear to the user. NOTE: Translate manually. No not adopt any copyrighted material for translation."> translation_description="Title text in sample text used to illustrate how the currently selected font size will appear to the user. NOTE: Translate manually. No not adopt any copyrighted material for translation.">
@@ -2926,7 +2926,11 @@
<!-- Sound & display settings screen, face-based rotation check box label [CHAR LIMIT=30] --> <!-- Sound & display settings screen, face-based rotation check box label [CHAR LIMIT=30] -->
<string name="auto_rotate_option_face_based">On - Face-based</string> <string name="auto_rotate_option_face_based">On - Face-based</string>
<!-- SmartAutoRotatePreferenceFragment settings screen, face-based rotation switch label [CHAR LIMIT=30] --> <!-- SmartAutoRotatePreferenceFragment settings screen, face-based rotation switch label [CHAR LIMIT=30] -->
<string name="auto_rotate_switch_face_based">Enable Face Detection</string> <string name="auto_rotate_switch_face_based">Face Detection</string>
<!-- Preference summary to enable auto rotate[CHAR_LIMIT=NONE]-->
<string name="auto_rotate_screen_summary">Automatically adjust the screen orientation when you move your phone between portrait and landscape</string>
<!-- Accessibility description for auto rotate learn more link [CHAR LIMIT=NONE] -->
<string name="auto_rotate_link_a11y">Learn more about auto-rotate</string>
<!-- Display settings screen, screen resolution settings title [CHAR LIMIT=30] --> <!-- Display settings screen, screen resolution settings title [CHAR LIMIT=30] -->
<string name="screen_resolution_title">Screen resolution</string> <string name="screen_resolution_title">Screen resolution</string>
@@ -12453,6 +12457,9 @@
<!-- Help URI, battery saver page [DO NOT TRANSLATE] --> <!-- Help URI, battery saver page [DO NOT TRANSLATE] -->
<string name="help_url_battery_saver_settings" translatable="false"></string> <string name="help_url_battery_saver_settings" translatable="false"></string>
<!-- Help URI, auto rotate page [DO NOT TRANSLATE] -->
<string name="help_url_auto_rotate_settings" translatable="false"></string>
<!-- Help URI, app usage page [DO NOT TRANSLATE] --> <!-- Help URI, app usage page [DO NOT TRANSLATE] -->
<string name="help_url_app_usage_settings" translatable="false"></string> <string name="help_url_app_usage_settings" translatable="false"></string>

View File

@@ -20,6 +20,14 @@
xmlns:settings="http://schemas.android.com/apk/res-auto" xmlns:settings="http://schemas.android.com/apk/res-auto"
android:title="@string/accelerometer_title" > android:title="@string/accelerometer_title" >
<com.android.settingslib.widget.TopIntroPreference
android:title="@string/auto_rotate_screen_summary"/>
<com.android.settingslib.widget.MainSwitchPreference
android:key="auto_rotate_main_switch"
android:title="@string/auto_rotate_settings_primary_switch_title"
settings:controller="com.android.settings.display.AutoRotateSwitchBarController"/>
<SwitchPreference <SwitchPreference
android:key="auto_rotate_switch" android:key="auto_rotate_switch"
android:title="@string/auto_rotate_settings_primary_switch_title" android:title="@string/auto_rotate_settings_primary_switch_title"
@@ -48,8 +56,9 @@
settings:controller="com.android.settings.display.SmartAutoRotateController" /> settings:controller="com.android.settings.display.SmartAutoRotateController" />
<com.android.settingslib.widget.FooterPreference <com.android.settingslib.widget.FooterPreference
android:icon="@drawable/ic_privacy_shield_24dp" android:key="auto_rotate_footer_preference"
android:title="@string/smart_rotate_text_headline"
android:selectable="false" android:selectable="false"
settings:searchable="false" /> settings:searchable="false"/>
</PreferenceScreen> </PreferenceScreen>

View File

@@ -18,86 +18,78 @@ package com.android.settings.display;
import android.app.settings.SettingsEnums; import android.app.settings.SettingsEnums;
import android.content.Context; import android.content.Context;
import android.widget.Switch;
import com.android.internal.view.RotationPolicy; import com.android.internal.view.RotationPolicy;
import com.android.settings.R;
import com.android.settings.overlay.FeatureFactory; import com.android.settings.overlay.FeatureFactory;
import com.android.settings.widget.SettingsMainSwitchBar; import com.android.settings.widget.SettingsMainSwitchPreferenceController;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.core.lifecycle.LifecycleObserver; import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart; import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop; import com.android.settingslib.core.lifecycle.events.OnStop;
import com.android.settingslib.widget.OnMainSwitchChangeListener;
/** /**
* The switch controller for auto-rotate. * The main switch controller for auto-rotate.
*/ */
public class AutoRotateSwitchBarController implements OnMainSwitchChangeListener, public class AutoRotateSwitchBarController extends SettingsMainSwitchPreferenceController implements
LifecycleObserver, OnStart, OnStop { LifecycleObserver, OnStart, OnStop {
private final SettingsMainSwitchBar mSwitchBar;
private final Context mContext;
private boolean mValidListener;
private final MetricsFeatureProvider mMetricsFeatureProvider; private final MetricsFeatureProvider mMetricsFeatureProvider;
private RotationPolicy.RotationPolicyListener mRotationPolicyListener;
public AutoRotateSwitchBarController(Context context, SettingsMainSwitchBar switchBar, public AutoRotateSwitchBarController(Context context, String key) {
Lifecycle lifecycle) { super(context, key);
mSwitchBar = switchBar;
mContext = context;
mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider(); mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
if (lifecycle != null) {
lifecycle.addObserver(this);
} }
@Override
public int getAvailabilityStatus() {
return RotationPolicy.isRotationLockToggleVisible(mContext)
&& !DeviceStateAutoRotationHelper.isDeviceStateRotationEnabled(mContext)
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
} }
@Override @Override
public void onStart() { public void onStart() {
if (!mValidListener) { if (mRotationPolicyListener == null) {
mSwitchBar.addOnSwitchChangeListener(this); mRotationPolicyListener = new RotationPolicy.RotationPolicyListener() {
mValidListener = true; @Override
public void onChange() {
if (mSwitchPreference != null) {
updateState(mSwitchPreference);
} }
onChange(); }
};
}
RotationPolicy.registerRotationPolicyListener(mContext,
mRotationPolicyListener);
} }
@Override @Override
public void onStop() { public void onStop() {
if (mValidListener) { if (mRotationPolicyListener != null) {
mSwitchBar.removeOnSwitchChangeListener(this); RotationPolicy.unregisterRotationPolicyListener(mContext, mRotationPolicyListener);
mValidListener = false;
} }
} }
/**
* Listens to the state change of the rotation primary switch.
*/
@Override @Override
public void onSwitchChanged(Switch switchView, boolean isChecked) { public boolean isChecked() {
setRotationLock(isChecked); return !RotationPolicy.isRotationLocked(mContext);
} }
@Override
protected void onChange() { public boolean setChecked(boolean isChecked) {
final boolean isEnabled = !RotationPolicy.isRotationLocked(mContext);
if (isEnabled != mSwitchBar.isChecked()) {
// set listener to null so that that code below doesn't trigger onCheckedChanged()
if (mValidListener) {
mSwitchBar.removeOnSwitchChangeListener(this);
}
mSwitchBar.setChecked(isEnabled);
if (mValidListener) {
mSwitchBar.addOnSwitchChangeListener(this);
}
}
}
private boolean setRotationLock(boolean isChecked) {
final boolean isLocked = !isChecked; final boolean isLocked = !isChecked;
mMetricsFeatureProvider.action(mContext, SettingsEnums.ACTION_ROTATE_ROTATE_MASTER_TOGGLE, mMetricsFeatureProvider.action(mContext, SettingsEnums.ACTION_ROTATE_ROTATE_MASTER_TOGGLE,
isChecked); isLocked);
RotationPolicy.setRotationLock(mContext, isLocked); RotationPolicy.setRotationLock(mContext, isLocked);
return true; return true;
} }
@Override
public int getSliceHighlightMenuRes() {
return R.string.menu_key_display;
}
} }

View File

@@ -20,7 +20,7 @@ import static com.android.settings.display.SmartAutoRotateController.isRotationR
import android.app.settings.SettingsEnums; import android.app.settings.SettingsEnums;
import android.content.Context; import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.text.Html; import android.text.TextUtils;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@@ -28,12 +28,11 @@ import android.view.ViewGroup;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference; import androidx.preference.Preference;
import com.android.internal.view.RotationPolicy;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.SettingsActivity; import com.android.settings.SettingsActivity;
import com.android.settings.dashboard.DashboardFragment; import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.widget.SettingsMainSwitchBar; import com.android.settingslib.HelpUtils;
import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.search.Indexable; import com.android.settingslib.search.Indexable;
import com.android.settingslib.search.SearchIndexable; import com.android.settingslib.search.SearchIndexable;
@@ -51,9 +50,11 @@ public class SmartAutoRotatePreferenceFragment extends DashboardFragment {
private static final String TAG = "SmartAutoRotatePreferenceFragment"; private static final String TAG = "SmartAutoRotatePreferenceFragment";
private RotationPolicy.RotationPolicyListener mRotationPolicyListener; @VisibleForTesting
private AutoRotateSwitchBarController mSwitchBarController; static final String AUTO_ROTATE_MAIN_SWITCH_PREFERENCE_KEY = "auto_rotate_main_switch";
@VisibleForTesting static final String AUTO_ROTATE_SWITCH_PREFERENCE_ID = "auto_rotate_switch"; @VisibleForTesting
static final String AUTO_ROTATE_SWITCH_PREFERENCE_KEY = "auto_rotate_switch";
private static final String KEY_FOOTER_PREFERENCE = "auto_rotate_footer_preference";
@Override @Override
protected int getPreferenceScreenResId() { protected int getPreferenceScreenResId() {
@@ -81,11 +82,10 @@ public class SmartAutoRotatePreferenceFragment extends DashboardFragment {
final View view = super.onCreateView(inflater, container, savedInstanceState); final View view = super.onCreateView(inflater, container, savedInstanceState);
final SettingsActivity activity = (SettingsActivity) getActivity(); final SettingsActivity activity = (SettingsActivity) getActivity();
createHeader(activity); createHeader(activity);
final Preference footerPreference = findPreference(FooterPreference.KEY_FOOTER); final Preference footerPreference = findPreference(KEY_FOOTER_PREFERENCE);
if (footerPreference != null) { if (footerPreference != null) {
footerPreference.setTitle(Html.fromHtml(getString(R.string.smart_rotate_text_headline),
Html.FROM_HTML_MODE_COMPACT));
footerPreference.setVisible(isRotationResolverServiceAvailable(activity)); footerPreference.setVisible(isRotationResolverServiceAvailable(activity));
setupFooter();
} }
return view; return view;
} }
@@ -95,39 +95,9 @@ public class SmartAutoRotatePreferenceFragment extends DashboardFragment {
boolean deviceStateRotationEnabled = boolean deviceStateRotationEnabled =
DeviceStateAutoRotationHelper.isDeviceStateRotationEnabled(activity); DeviceStateAutoRotationHelper.isDeviceStateRotationEnabled(activity);
if (isRotationResolverServiceAvailable(activity) && !deviceStateRotationEnabled) { if (isRotationResolverServiceAvailable(activity) && !deviceStateRotationEnabled) {
final SettingsMainSwitchBar switchBar = activity.getSwitchBar(); findPreference(AUTO_ROTATE_SWITCH_PREFERENCE_KEY).setVisible(false);
switchBar.setTitle( } else {
getContext().getString(R.string.auto_rotate_settings_primary_switch_title)); findPreference(AUTO_ROTATE_MAIN_SWITCH_PREFERENCE_KEY).setVisible(false);
switchBar.show();
mSwitchBarController = new AutoRotateSwitchBarController(activity, switchBar,
getSettingsLifecycle());
findPreference(AUTO_ROTATE_SWITCH_PREFERENCE_ID).setVisible(false);
}
}
@Override
public void onResume() {
super.onResume();
if (mRotationPolicyListener == null) {
mRotationPolicyListener = new RotationPolicy.RotationPolicyListener() {
@Override
public void onChange() {
if (mSwitchBarController != null) {
mSwitchBarController.onChange();
}
}
};
}
RotationPolicy.registerRotationPolicyListener(getPrefContext(),
mRotationPolicyListener);
}
@Override
public void onPause() {
super.onPause();
if (mRotationPolicyListener != null) {
RotationPolicy.unregisterRotationPolicyListener(getPrefContext(),
mRotationPolicyListener);
} }
} }
@@ -141,6 +111,34 @@ public class SmartAutoRotatePreferenceFragment extends DashboardFragment {
return TAG; return TAG;
} }
@Override
public int getHelpResource() {
return R.string.help_url_auto_rotate_settings;
}
// Updates the footer for this page.
@VisibleForTesting
void setupFooter() {
final String mHelpUri = getString(getHelpResource());
if (!TextUtils.isEmpty(mHelpUri)) {
addHelpLink();
}
}
// Changes the text to include a learn more link if the link is defined.
@VisibleForTesting
void addHelpLink() {
final FooterPreference pref = findPreference(KEY_FOOTER_PREFERENCE);
if (pref != null) {
pref.setLearnMoreAction(v -> {
startActivityForResult(HelpUtils.getHelpIntent(getContext(),
getString(getHelpResource()),
/*backupContext=*/ ""), /*requestCode=*/ 0);
});
pref.setLearnMoreContentDescription(getString(R.string.auto_rotate_link_a11y));
}
}
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider(R.xml.auto_rotate_settings) { new BaseSearchIndexProvider(R.xml.auto_rotate_settings) {

View File

@@ -16,7 +16,8 @@
package com.android.settings.display; package com.android.settings.display;
import static com.android.settings.display.SmartAutoRotatePreferenceFragment.AUTO_ROTATE_SWITCH_PREFERENCE_ID; import static com.android.settings.display.SmartAutoRotatePreferenceFragment.AUTO_ROTATE_MAIN_SWITCH_PREFERENCE_KEY;
import static com.android.settings.display.SmartAutoRotatePreferenceFragment.AUTO_ROTATE_SWITCH_PREFERENCE_KEY;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
@@ -45,7 +46,6 @@ import com.android.settings.SettingsActivity;
import com.android.settings.testutils.ResolveInfoBuilder; import com.android.settings.testutils.ResolveInfoBuilder;
import com.android.settings.testutils.shadow.ShadowDeviceStateRotationLockSettingsManager; import com.android.settings.testutils.shadow.ShadowDeviceStateRotationLockSettingsManager;
import com.android.settings.testutils.shadow.ShadowRotationPolicy; import com.android.settings.testutils.shadow.ShadowRotationPolicy;
import com.android.settings.widget.SettingsMainSwitchBar;
import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager; import com.android.settingslib.devicestate.DeviceStateRotationLockSettingsManager;
@@ -71,8 +71,6 @@ public class SmartAutoRotatePreferenceFragmentTest {
private SmartAutoRotatePreferenceFragment mFragment; private SmartAutoRotatePreferenceFragment mFragment;
private SettingsMainSwitchBar mSwitchBar;
@Mock @Mock
private PackageManager mPackageManager; private PackageManager mPackageManager;
@@ -87,6 +85,9 @@ public class SmartAutoRotatePreferenceFragmentTest {
private Resources mResources; private Resources mResources;
private Context mContext; private Context mContext;
@Mock
private Preference mRotateMainSwitchPreference;
@Before @Before
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
@@ -112,21 +113,21 @@ public class SmartAutoRotatePreferenceFragmentTest {
when(mFragment.getContext()).thenReturn(mContext); when(mFragment.getContext()).thenReturn(mContext);
doReturn(mView).when(mFragment).getView(); doReturn(mView).when(mFragment).getView();
when(mFragment.findPreference(AUTO_ROTATE_SWITCH_PREFERENCE_ID)).thenReturn( when(mFragment.findPreference(AUTO_ROTATE_SWITCH_PREFERENCE_KEY)).thenReturn(
mRotateSwitchPreference); mRotateSwitchPreference);
mSwitchBar = spy(new SettingsMainSwitchBar(mContext));
when(mActivity.getSwitchBar()).thenReturn(mSwitchBar); when(mFragment.findPreference(AUTO_ROTATE_MAIN_SWITCH_PREFERENCE_KEY)).thenReturn(
doReturn(mSwitchBar).when(mView).findViewById(R.id.switch_bar); mRotateMainSwitchPreference);
ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(false);
} }
@Test @Test
public void createHeader_faceDetectionSupported_switchBarIsEnabled() { public void createHeader_faceDetectionSupported_switchBarIsEnabled() {
ShadowDeviceStateRotationLockSettingsManager.setDeviceStateRotationLockEnabled(false);
mFragment.createHeader(mActivity); mFragment.createHeader(mActivity);
verify(mSwitchBar, times(1)).show(); verify(mRotateMainSwitchPreference, never()).setVisible(false);
verify(mRotateSwitchPreference, times(1)).setVisible(false); verify(mRotateSwitchPreference, times(1)).setVisible(false);
} }
@@ -137,7 +138,7 @@ public class SmartAutoRotatePreferenceFragmentTest {
mFragment.createHeader(mActivity); mFragment.createHeader(mActivity);
verify(mSwitchBar, never()).show(); verify(mRotateMainSwitchPreference, times(1)).setVisible(false);
verify(mRotateSwitchPreference, never()).setVisible(false); verify(mRotateSwitchPreference, never()).setVisible(false);
} }
@@ -147,7 +148,7 @@ public class SmartAutoRotatePreferenceFragmentTest {
mFragment.createHeader(mActivity); mFragment.createHeader(mActivity);
verify(mSwitchBar, never()).show(); verify(mRotateMainSwitchPreference, times(1)).setVisible(false);
verify(mRotateSwitchPreference, never()).setVisible(false); verify(mRotateSwitchPreference, never()).setVisible(false);
} }
@@ -176,6 +177,19 @@ public class SmartAutoRotatePreferenceFragmentTest {
DeviceStateAutoRotateSettingController.class); DeviceStateAutoRotateSettingController.class);
} }
@Test
public void setupFooter_linkAddedWhenAppropriate() {
doReturn("").when(mFragment).getText(anyInt());
doReturn("").when(mFragment).getString(anyInt());
mFragment.setupFooter();
verify(mFragment, never()).addHelpLink();
doReturn("testString").when(mFragment).getText(anyInt());
doReturn("testString").when(mFragment).getString(anyInt());
mFragment.setupFooter();
verify(mFragment, times(1)).addHelpLink();
}
private void enableDeviceStateSettableRotationStates(String[] settableStates, private void enableDeviceStateSettableRotationStates(String[] settableStates,
String[] settableStatesDescriptions) { String[] settableStatesDescriptions) {
when(mResources.getStringArray( when(mResources.getStringArray(