Fixes 'no ripple effect' issue for screen attention setting

Preferences shouldn't be initialized at onAttach() because the settings
style hasn't been loaded yet. This change defers the preferences
initialization so that they comply with the settings style.

Test: manually
Test: make RunSettingsRoboTests ROBOTEST_FILTER=com.android.settings.display
Bug: 183909540

Change-Id: I4dc4503924a1dcd5b8d41f7d27e576befb11f976
This commit is contained in:
Yi Jiang
2021-04-02 11:46:53 -07:00
parent 9246f6f8b0
commit 20d1da2b62
5 changed files with 55 additions and 36 deletions

View File

@@ -71,11 +71,15 @@ public class ScreenTimeoutSettings extends RadioButtonPickerFragment implements
private CharSequence[] mInitialEntries;
private CharSequence[] mInitialValues;
private FooterPreference mPrivacyPreference;
private MetricsFeatureProvider mMetricsFeatureProvider;
private final MetricsFeatureProvider mMetricsFeatureProvider;
private SensorPrivacyManager mPrivacyManager;
@VisibleForTesting
Context mContext;
@VisibleForTesting
RestrictedLockUtils.EnforcedAdmin mAdmin;
@VisibleForTesting
Preference mDisableOptionsPreference;
@@ -97,6 +101,7 @@ public class ScreenTimeoutSettings extends RadioButtonPickerFragment implements
@Override
public void onAttach(Context context) {
super.onAttach(context);
mContext = context;
mInitialEntries = getResources().getStringArray(R.array.screen_timeout_entries);
mInitialValues = getResources().getStringArray(R.array.screen_timeout_values);
mAdaptiveSleepController = new AdaptiveSleepPreferenceController(context);
@@ -104,11 +109,6 @@ public class ScreenTimeoutSettings extends RadioButtonPickerFragment implements
context);
mAdaptiveSleepCameraStatePreferenceController =
new AdaptiveSleepCameraStatePreferenceController(context);
mPrivacyPreference = new FooterPreference(context);
mPrivacyPreference.setIcon(R.drawable.ic_privacy_shield_24dp);
mPrivacyPreference.setTitle(R.string.adaptive_sleep_privacy);
mPrivacyPreference.setSelectable(false);
mPrivacyPreference.setLayoutResource(R.layout.preference_footer);
mPrivacyManager = SensorPrivacyManager.getInstance(context);
mPrivacyManager.addSensorPrivacyListener(CAMERA,
(sensor, enabled) -> mAdaptiveSleepController.updatePreference());
@@ -167,6 +167,12 @@ public class ScreenTimeoutSettings extends RadioButtonPickerFragment implements
preferenceWithLargestTimeout.setChecked(true);
}
mPrivacyPreference = new FooterPreference(mContext);
mPrivacyPreference.setIcon(R.drawable.ic_privacy_shield_24dp);
mPrivacyPreference.setTitle(R.string.adaptive_sleep_privacy);
mPrivacyPreference.setSelectable(false);
mPrivacyPreference.setLayoutResource(R.layout.preference_footer);
if (isScreenAttentionAvailable(getContext())) {
mAdaptiveSleepPermissionController.addToScreen(screen);
mAdaptiveSleepCameraStatePreferenceController.addToScreen(screen);