The dynamic index implementation for time zone preferences.

Disable the region settings page if auto time zone is enabled.

Fixes: 146849126
Test: manual
Change-Id: Icce1e5aca14539d6c9149e05a3321429bd337f17
This commit is contained in:
Stanley Wang
2019-12-25 16:53:17 +08:00
parent 4e7229c440
commit f0cd9742b5

View File

@@ -25,6 +25,7 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.icu.util.TimeZone; import android.icu.util.TimeZone;
import android.os.Bundle; import android.os.Bundle;
import android.provider.Settings;
import android.util.Log; import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
@@ -123,9 +124,9 @@ public class TimeZoneSettings extends DashboardFragment {
super.onCreate(icicle); super.onCreate(icicle);
// Hide all interactive preferences // Hide all interactive preferences
setPreferenceCategoryVisible((PreferenceCategory) findPreference( setPreferenceCategoryVisible((PreferenceCategory) findPreference(
PREF_KEY_REGION_CATEGORY), false); PREF_KEY_REGION_CATEGORY), false);
setPreferenceCategoryVisible((PreferenceCategory) findPreference( setPreferenceCategoryVisible((PreferenceCategory) findPreference(
PREF_KEY_FIXED_OFFSET_CATEGORY), false); PREF_KEY_FIXED_OFFSET_CATEGORY), false);
// Start loading TimeZoneData // Start loading TimeZoneData
getLoaderManager().initLoader(0, null, new TimeZoneDataLoader.LoaderCreator( getLoaderManager().initLoader(0, null, new TimeZoneDataLoader.LoaderCreator(
@@ -237,7 +238,7 @@ public class TimeZoneSettings extends DashboardFragment {
String tzId = data.getStringExtra(RegionZonePicker.EXTRA_RESULT_TIME_ZONE_ID); String tzId = data.getStringExtra(RegionZonePicker.EXTRA_RESULT_TIME_ZONE_ID);
// Ignore the result if user didn't change the region or time zone. // Ignore the result if user didn't change the region or time zone.
if (Objects.equals(regionId, use(RegionPreferenceController.class).getRegionId()) if (Objects.equals(regionId, use(RegionPreferenceController.class).getRegionId())
&& Objects.equals(tzId, mSelectedTimeZoneId)) { && Objects.equals(tzId, mSelectedTimeZoneId)) {
return; return;
} }
@@ -327,9 +328,9 @@ public class TimeZoneSettings extends DashboardFragment {
private void setSelectByRegion(boolean selectByRegion) { private void setSelectByRegion(boolean selectByRegion) {
mSelectByRegion = selectByRegion; mSelectByRegion = selectByRegion;
setPreferenceCategoryVisible((PreferenceCategory) findPreference( setPreferenceCategoryVisible((PreferenceCategory) findPreference(
PREF_KEY_REGION_CATEGORY), selectByRegion); PREF_KEY_REGION_CATEGORY), selectByRegion);
setPreferenceCategoryVisible((PreferenceCategory) findPreference( setPreferenceCategoryVisible((PreferenceCategory) findPreference(
PREF_KEY_FIXED_OFFSET_CATEGORY), !selectByRegion); PREF_KEY_FIXED_OFFSET_CATEGORY), !selectByRegion);
final String localeRegionId = getLocaleRegionId(); final String localeRegionId = getLocaleRegionId();
final Set<String> allCountryIsoCodes = mTimeZoneData.getRegionIds(); final Set<String> allCountryIsoCodes = mTimeZoneData.getRegionIds();
@@ -353,6 +354,7 @@ public class TimeZoneSettings extends DashboardFragment {
* Find the a region associated with the specified time zone, based on the time zone data. * Find the a region associated with the specified time zone, based on the time zone data.
* If there are multiple regions associated with the given time zone, the priority will be given * If there are multiple regions associated with the given time zone, the priority will be given
* to the region the user last picked and the country in user's locale. * to the region the user last picked and the country in user's locale.
*
* @return null if no region associated with the time zone * @return null if no region associated with the time zone
*/ */
private String findRegionIdForTzId(String tzId) { private String findRegionIdForTzId(String tzId) {
@@ -378,7 +380,7 @@ public class TimeZoneSettings extends DashboardFragment {
} }
private void setPreferenceCategoryVisible(PreferenceCategory category, private void setPreferenceCategoryVisible(PreferenceCategory category,
boolean isVisible) { boolean isVisible) {
// Hiding category doesn't hide all the children preference. Set visibility of its children. // Hiding category doesn't hide all the children preference. Set visibility of its children.
// Do not care grandchildren as time_zone_pref.xml has only 2 levels. // Do not care grandchildren as time_zone_pref.xml has only 2 levels.
category.setVisible(isVisible); category.setVisible(isVisible);
@@ -392,5 +394,13 @@ public class TimeZoneSettings extends DashboardFragment {
} }
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider(R.xml.time_zone_prefs); new BaseSearchIndexProvider(R.xml.time_zone_prefs) {
@Override
protected boolean isPageSearchEnabled(Context context) {
// We can't enter this page if the auto time zone is enabled.
final int autoTimeZone = Settings.Global.getInt(context.getContentResolver(),
Settings.Global.AUTO_TIME_ZONE, 1);
return autoTimeZone == 1 ? false : true;
}
};
} }