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

@@ -37,26 +37,18 @@ public class AdaptiveSleepPermissionPreferenceController {
@VisibleForTesting
BannerMessagePreference mPreference;
private final PackageManager mPackageManager;
private final Context mContext;
public AdaptiveSleepPermissionPreferenceController(Context context) {
final String packageName = context.getPackageManager().getAttentionServicePackageName();
mPackageManager = context.getPackageManager();
final Intent intent = new Intent(
android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setData(Uri.parse("package:" + packageName));
mPreference = new BannerMessagePreference(context);
mPreference.setTitle(R.string.adaptive_sleep_title_no_permission);
mPreference.setSummary(R.string.adaptive_sleep_summary_no_permission);
mPreference.setPositiveButtonText(R.string.adaptive_sleep_manage_permission_button);
mPreference.setPositiveButtonOnClickListener(p -> {
context.startActivity(intent);
});
mContext = context;
}
/**
* Adds the controlled preference to the provided preference screen.
*/
public void addToScreen(PreferenceScreen screen) {
initializePreference();
if (!hasSufficientPermission(mPackageManager)) {
screen.addPreference(mPreference);
}
@@ -68,4 +60,19 @@ public class AdaptiveSleepPermissionPreferenceController {
public void updateVisibility() {
mPreference.setVisible(!hasSufficientPermission(mPackageManager));
}
private void initializePreference() {
final String packageName = mContext.getPackageManager().getAttentionServicePackageName();
final Intent intent = new Intent(
android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setData(Uri.parse("package:" + packageName));
mPreference = new BannerMessagePreference(mContext);
mPreference.setTitle(R.string.adaptive_sleep_title_no_permission);
mPreference.setSummary(R.string.adaptive_sleep_summary_no_permission);
mPreference.setPositiveButtonText(R.string.adaptive_sleep_manage_permission_button);
mPreference.setPositiveButtonOnClickListener(p -> {
mContext.startActivity(intent);
});
}
}