Use list+ toggle on devices without face detection

Test: verified intended behavior on crosshatch and no regression on flame, make RunSettingsRoboTests -j$(nproc) ROBOTEST_FILTER=SmartAutoRotatePreferenceFragmentTest

Bug: 181299673
Change-Id: Ic9f44091e95915bc78bc70b86d7f132ba6e159ed
This commit is contained in:
Abel Tesfaye
2021-03-30 22:05:36 +00:00
parent a8e4d51c24
commit faaf8d5af1
4 changed files with 147 additions and 8 deletions

View File

@@ -25,6 +25,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import com.android.internal.view.RotationPolicy;
@@ -48,6 +49,7 @@ public class SmartAutoRotatePreferenceFragment extends DashboardFragment {
private RotationPolicy.RotationPolicyListener mRotationPolicyListener;
private AutoRotateSwitchBarController mSwitchBarController;
@VisibleForTesting static final String AUTO_ROTATE_SWITCH_PREFERENCE_ID = "auto_rotate_switch";
@Override
protected int getPreferenceScreenResId() {
@@ -65,12 +67,7 @@ public class SmartAutoRotatePreferenceFragment extends DashboardFragment {
Bundle savedInstanceState) {
final View view = super.onCreateView(inflater, container, savedInstanceState);
final SettingsActivity activity = (SettingsActivity) getActivity();
final SettingsMainSwitchBar switchBar = activity.getSwitchBar();
switchBar.setTitle(
getContext().getString(R.string.auto_rotate_settings_primary_switch_title));
switchBar.show();
mSwitchBarController = new AutoRotateSwitchBarController(activity, switchBar,
getSettingsLifecycle());
createHeader(activity);
final Preference footerPreference = findPreference(FooterPreference.KEY_FOOTER);
if (footerPreference != null) {
footerPreference.setTitle(Html.fromHtml(getString(R.string.smart_rotate_text_headline),
@@ -80,6 +77,19 @@ public class SmartAutoRotatePreferenceFragment extends DashboardFragment {
return view;
}
@VisibleForTesting
void createHeader(SettingsActivity activity) {
if (isRotationResolverServiceAvailable(activity)) {
final SettingsMainSwitchBar switchBar = activity.getSwitchBar();
switchBar.setTitle(
getContext().getString(R.string.auto_rotate_settings_primary_switch_title));
switchBar.show();
mSwitchBarController = new AutoRotateSwitchBarController(activity, switchBar,
getSettingsLifecycle());
findPreference(AUTO_ROTATE_SWITCH_PREFERENCE_ID).setVisible(false);
}
}
@Override
public void onResume() {
super.onResume();
@@ -87,7 +97,9 @@ public class SmartAutoRotatePreferenceFragment extends DashboardFragment {
mRotationPolicyListener = new RotationPolicy.RotationPolicyListener() {
@Override
public void onChange() {
mSwitchBarController.onChange();
if (mSwitchBarController != null) {
mSwitchBarController.onChange();
}
}
};
}