From 28bc1c04b98ad901462ae865e347f64c35d010d9 Mon Sep 17 00:00:00 2001 From: Mill Chen Date: Thu, 18 Nov 2021 15:45:44 +0800 Subject: [PATCH] Fix the background color of CollapsingToolbarLayout The wrong background color of CollapsingToolbarLayout appears in some pages like "All apps" page or "Password and accounts" page. This symptom can be observed in these pages when the work profile is enabled and the line count of title is 1. This issue is caused by updating the title of the page many times. In these pages that have the tab view, the structure of the page differs from a general setting page. The title of the page is coming from BaseActivity, ProfileSelectFragment, PersonalFragment and WorkFragment, in which the page that has the issue has an empty string from ProfileSelectFragment. That is causing the CollapsingTollbarLayout has the different line count during the process of setting the title. Since the pages that have the tab view are different from the general pages in Settings, the title should be set separately for those pages. Adding a method to get the title resource ID so the page extending from ProfileSelectFragment can set its title. Bug: 192914660 Test: visual test and manual test 1) Enable work profile 2) Navigate to All apps page 3) The page should have the correct background color in the CollapsingToolbarLayout Change-Id: I52ef9729f3cad56161ea3d87ba25429dfcdb26ef --- .../accounts_dashboard_settings_header.xml | 22 ++++++++ res/xml/location_recent_requests_header.xml | 22 ++++++++ res/xml/location_services_header.xml | 22 ++++++++ res/xml/location_settings_header.xml | 22 ++++++++ .../ManageApplications.java | 56 ++++++++++++++----- .../ProfileSelectAccountFragment.java | 6 ++ .../ProfileSelectFragment.java | 12 ++++ .../ProfileSelectLocationFragment.java | 5 ++ ...ProfileSelectLocationServicesFragment.java | 6 ++ .../ProfileSelectManageApplications.java | 10 ++++ ...leSelectRecentLocationRequestFragment.java | 6 ++ 11 files changed, 174 insertions(+), 15 deletions(-) create mode 100644 res/xml/accounts_dashboard_settings_header.xml create mode 100644 res/xml/location_recent_requests_header.xml create mode 100644 res/xml/location_services_header.xml create mode 100644 res/xml/location_settings_header.xml diff --git a/res/xml/accounts_dashboard_settings_header.xml b/res/xml/accounts_dashboard_settings_header.xml new file mode 100644 index 00000000000..99f07360f48 --- /dev/null +++ b/res/xml/accounts_dashboard_settings_header.xml @@ -0,0 +1,22 @@ + + + + + diff --git a/res/xml/location_recent_requests_header.xml b/res/xml/location_recent_requests_header.xml new file mode 100644 index 00000000000..0e252a5db85 --- /dev/null +++ b/res/xml/location_recent_requests_header.xml @@ -0,0 +1,22 @@ + + + + + diff --git a/res/xml/location_services_header.xml b/res/xml/location_services_header.xml new file mode 100644 index 00000000000..4eaf2c5bc00 --- /dev/null +++ b/res/xml/location_services_header.xml @@ -0,0 +1,22 @@ + + + + + diff --git a/res/xml/location_settings_header.xml b/res/xml/location_settings_header.xml new file mode 100644 index 00000000000..4749a2e3a6a --- /dev/null +++ b/res/xml/location_settings_header.xml @@ -0,0 +1,22 @@ + + + + + diff --git a/src/com/android/settings/applications/manageapplications/ManageApplications.java b/src/com/android/settings/applications/manageapplications/ManageApplications.java index c1f45746599..7b5c2218f7d 100644 --- a/src/com/android/settings/applications/manageapplications/ManageApplications.java +++ b/src/com/android/settings/applications/manageapplications/ManageApplications.java @@ -272,8 +272,7 @@ public class ManageApplications extends InstrumentedFragment Intent intent = activity.getIntent(); Bundle args = getArguments(); - int screenTitle = intent.getIntExtra( - SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RESID, R.string.all_apps); + final int screenTitle = getTitleResId(intent, args); String className = args != null ? args.getString(EXTRA_CLASSNAME) : null; if (className == null) { className = intent.getComponent().getClassName(); @@ -290,49 +289,36 @@ public class ManageApplications extends InstrumentedFragment mSortOrder = R.id.sort_order_size; } else if (className.equals(UsageAccessSettingsActivity.class.getName())) { mListType = LIST_TYPE_USAGE_ACCESS; - screenTitle = R.string.usage_access; } else if (className.equals(HighPowerApplicationsActivity.class.getName())) { mListType = LIST_TYPE_HIGH_POWER; // Default to showing system. mShowSystem = true; - screenTitle = R.string.high_power_apps; } else if (className.equals(OverlaySettingsActivity.class.getName())) { mListType = LIST_TYPE_OVERLAY; - screenTitle = R.string.system_alert_window_settings; reportIfRestrictedSawIntent(intent); } else if (className.equals(WriteSettingsActivity.class.getName())) { mListType = LIST_TYPE_WRITE_SETTINGS; - screenTitle = R.string.write_settings; } else if (className.equals(ManageExternalSourcesActivity.class.getName())) { mListType = LIST_TYPE_MANAGE_SOURCES; - screenTitle = R.string.install_other_apps; } else if (className.equals(GamesStorageActivity.class.getName())) { mListType = LIST_TYPE_GAMES; mSortOrder = R.id.sort_order_size; } else if (className.equals(Settings.ChangeWifiStateActivity.class.getName())) { mListType = LIST_TYPE_WIFI_ACCESS; - screenTitle = R.string.change_wifi_state_title; } else if (className.equals(Settings.ManageExternalStorageActivity.class.getName())) { mListType = LIST_MANAGE_EXTERNAL_STORAGE; - screenTitle = R.string.manage_external_storage_title; } else if (className.equals(Settings.MediaManagementAppsActivity.class.getName())) { mListType = LIST_TYPE_MEDIA_MANAGEMENT_APPS; - screenTitle = R.string.media_management_apps_title; } else if (className.equals(Settings.AlarmsAndRemindersActivity.class.getName())) { mListType = LIST_TYPE_ALARMS_AND_REMINDERS; - screenTitle = R.string.alarms_and_reminders_title; } else if (className.equals(Settings.NotificationAppListActivity.class.getName())) { mListType = LIST_TYPE_NOTIFICATION; mUsageStatsManager = IUsageStatsManager.Stub.asInterface( ServiceManager.getService(Context.USAGE_STATS_SERVICE)); mNotificationBackend = new NotificationBackend(); mSortOrder = R.id.sort_order_recent_notification; - screenTitle = R.string.app_notifications_title; } else { - if (screenTitle == -1) { - screenTitle = R.string.all_apps; - } mListType = LIST_TYPE_MAIN; } final AppFilterRegistry appFilterRegistry = AppFilterRegistry.getInstance(); @@ -881,6 +867,46 @@ public class ManageApplications extends InstrumentedFragment params.setBehavior(behavior); } + /** + * Returns a resource ID of title based on what type of app list is + * @param intent the intent of the activity that might include a specified title + * @param args the args that includes a class name of app list + */ + public static int getTitleResId(@NonNull Intent intent, Bundle args) { + int screenTitle = intent.getIntExtra( + SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RESID, R.string.all_apps); + String className = args != null ? args.getString(EXTRA_CLASSNAME) : null; + if (className == null) { + className = intent.getComponent().getClassName(); + } + if (className.equals(Settings.UsageAccessSettingsActivity.class.getName())) { + screenTitle = R.string.usage_access; + } else if (className.equals(Settings.HighPowerApplicationsActivity.class.getName())) { + screenTitle = R.string.high_power_apps; + } else if (className.equals(Settings.OverlaySettingsActivity.class.getName())) { + screenTitle = R.string.system_alert_window_settings; + } else if (className.equals(Settings.WriteSettingsActivity.class.getName())) { + screenTitle = R.string.write_settings; + } else if (className.equals(Settings.ManageExternalSourcesActivity.class.getName())) { + screenTitle = R.string.install_other_apps; + } else if (className.equals(Settings.ChangeWifiStateActivity.class.getName())) { + screenTitle = R.string.change_wifi_state_title; + } else if (className.equals(Settings.ManageExternalStorageActivity.class.getName())) { + screenTitle = R.string.manage_external_storage_title; + } else if (className.equals(Settings.MediaManagementAppsActivity.class.getName())) { + screenTitle = R.string.media_management_apps_title; + } else if (className.equals(Settings.AlarmsAndRemindersActivity.class.getName())) { + screenTitle = R.string.alarms_and_reminders_title; + } else if (className.equals(Settings.NotificationAppListActivity.class.getName())) { + screenTitle = R.string.app_notifications_title; + } else { + if (screenTitle == -1) { + screenTitle = R.string.all_apps; + } + } + return screenTitle; + } + static class FilterSpinnerAdapter extends SettingsSpinnerAdapter { private final ManageApplications mManageApplications; diff --git a/src/com/android/settings/dashboard/profileselector/ProfileSelectAccountFragment.java b/src/com/android/settings/dashboard/profileselector/ProfileSelectAccountFragment.java index ac67b586fa3..cf91031933a 100644 --- a/src/com/android/settings/dashboard/profileselector/ProfileSelectAccountFragment.java +++ b/src/com/android/settings/dashboard/profileselector/ProfileSelectAccountFragment.java @@ -17,6 +17,7 @@ package com.android.settings.dashboard.profileselector; import androidx.fragment.app.Fragment; +import com.android.settings.R; import com.android.settings.accounts.AccountPersonalDashboardFragment; import com.android.settings.accounts.AccountWorkProfileDashboardFragment; @@ -32,4 +33,9 @@ public class ProfileSelectAccountFragment extends ProfileSelectFragment { new AccountWorkProfileDashboardFragment() }; } + + @Override + protected int getPreferenceScreenResId() { + return R.xml.accounts_dashboard_settings_header; + } } diff --git a/src/com/android/settings/dashboard/profileselector/ProfileSelectFragment.java b/src/com/android/settings/dashboard/profileselector/ProfileSelectFragment.java index 82d524d9f06..3b64d3d0c77 100644 --- a/src/com/android/settings/dashboard/profileselector/ProfileSelectFragment.java +++ b/src/com/android/settings/dashboard/profileselector/ProfileSelectFragment.java @@ -107,6 +107,10 @@ public abstract class ProfileSelectFragment extends DashboardFragment { Bundle savedInstanceState) { mContentView = (ViewGroup) super.onCreateView(inflater, container, savedInstanceState); final Activity activity = getActivity(); + final int titleResId = getTitleResId(); + if (titleResId > 0) { + activity.setTitle(titleResId); + } final int selectedTab = convertPosition(getTabId(activity, getArguments())); final View tabContainer = mContentView.findViewById(R.id.tab_container); @@ -166,6 +170,14 @@ public abstract class ProfileSelectFragment extends DashboardFragment { */ public abstract Fragment[] getFragments(); + /** + * Returns a resource ID of the title + * Override this if the title needs to be updated dynamically. + */ + public int getTitleResId() { + return 0; + } + @Override protected int getPreferenceScreenResId() { return R.xml.placeholder_preference_screen; diff --git a/src/com/android/settings/dashboard/profileselector/ProfileSelectLocationFragment.java b/src/com/android/settings/dashboard/profileselector/ProfileSelectLocationFragment.java index e4cde8e1590..28fb97bb42f 100644 --- a/src/com/android/settings/dashboard/profileselector/ProfileSelectLocationFragment.java +++ b/src/com/android/settings/dashboard/profileselector/ProfileSelectLocationFragment.java @@ -60,4 +60,9 @@ public class ProfileSelectLocationFragment extends ProfileSelectFragment { workFragment }; } + + @Override + protected int getPreferenceScreenResId() { + return R.xml.location_settings_header; + } } diff --git a/src/com/android/settings/dashboard/profileselector/ProfileSelectLocationServicesFragment.java b/src/com/android/settings/dashboard/profileselector/ProfileSelectLocationServicesFragment.java index b6f03d6b820..5f25f599988 100644 --- a/src/com/android/settings/dashboard/profileselector/ProfileSelectLocationServicesFragment.java +++ b/src/com/android/settings/dashboard/profileselector/ProfileSelectLocationServicesFragment.java @@ -20,6 +20,7 @@ import android.os.Bundle; import androidx.fragment.app.Fragment; +import com.android.settings.R; import com.android.settings.location.LocationServices; import com.android.settings.location.LocationServicesForWork; @@ -44,4 +45,9 @@ public class ProfileSelectLocationServicesFragment extends ProfileSelectFragment workFragment }; } + + @Override + protected int getPreferenceScreenResId() { + return R.xml.location_services_header; + } } diff --git a/src/com/android/settings/dashboard/profileselector/ProfileSelectManageApplications.java b/src/com/android/settings/dashboard/profileselector/ProfileSelectManageApplications.java index 17fed11b44b..36aa9c53358 100644 --- a/src/com/android/settings/dashboard/profileselector/ProfileSelectManageApplications.java +++ b/src/com/android/settings/dashboard/profileselector/ProfileSelectManageApplications.java @@ -16,6 +16,8 @@ package com.android.settings.dashboard.profileselector; +import android.app.Activity; +import android.content.Intent; import android.os.Bundle; import androidx.fragment.app.Fragment; @@ -43,4 +45,12 @@ public class ProfileSelectManageApplications extends ProfileSelectFragment { workFragment }; } + + @Override + public int getTitleResId() { + final Activity activity = getActivity(); + final Intent intent = activity.getIntent(); + final Bundle args = getArguments(); + return ManageApplications.getTitleResId(intent, args); + } } diff --git a/src/com/android/settings/dashboard/profileselector/ProfileSelectRecentLocationRequestFragment.java b/src/com/android/settings/dashboard/profileselector/ProfileSelectRecentLocationRequestFragment.java index 058ffe4dfd2..16cb43cc432 100644 --- a/src/com/android/settings/dashboard/profileselector/ProfileSelectRecentLocationRequestFragment.java +++ b/src/com/android/settings/dashboard/profileselector/ProfileSelectRecentLocationRequestFragment.java @@ -20,6 +20,7 @@ import android.os.Bundle; import androidx.fragment.app.Fragment; +import com.android.settings.R; import com.android.settings.location.RecentLocationRequestSeeAllFragment; /** @@ -43,4 +44,9 @@ public class ProfileSelectRecentLocationRequestFragment extends ProfileSelectFra workFragment }; } + + @Override + protected int getPreferenceScreenResId() { + return R.xml.location_recent_requests_header; + } }