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:
@@ -25,6 +25,7 @@ import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.icu.util.TimeZone;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
@@ -123,9 +124,9 @@ public class TimeZoneSettings extends DashboardFragment {
|
||||
super.onCreate(icicle);
|
||||
// Hide all interactive preferences
|
||||
setPreferenceCategoryVisible((PreferenceCategory) findPreference(
|
||||
PREF_KEY_REGION_CATEGORY), false);
|
||||
PREF_KEY_REGION_CATEGORY), false);
|
||||
setPreferenceCategoryVisible((PreferenceCategory) findPreference(
|
||||
PREF_KEY_FIXED_OFFSET_CATEGORY), false);
|
||||
PREF_KEY_FIXED_OFFSET_CATEGORY), false);
|
||||
|
||||
// Start loading TimeZoneData
|
||||
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);
|
||||
// Ignore the result if user didn't change the region or time zone.
|
||||
if (Objects.equals(regionId, use(RegionPreferenceController.class).getRegionId())
|
||||
&& Objects.equals(tzId, mSelectedTimeZoneId)) {
|
||||
&& Objects.equals(tzId, mSelectedTimeZoneId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -327,9 +328,9 @@ public class TimeZoneSettings extends DashboardFragment {
|
||||
private void setSelectByRegion(boolean selectByRegion) {
|
||||
mSelectByRegion = selectByRegion;
|
||||
setPreferenceCategoryVisible((PreferenceCategory) findPreference(
|
||||
PREF_KEY_REGION_CATEGORY), selectByRegion);
|
||||
PREF_KEY_REGION_CATEGORY), selectByRegion);
|
||||
setPreferenceCategoryVisible((PreferenceCategory) findPreference(
|
||||
PREF_KEY_FIXED_OFFSET_CATEGORY), !selectByRegion);
|
||||
PREF_KEY_FIXED_OFFSET_CATEGORY), !selectByRegion);
|
||||
final String localeRegionId = getLocaleRegionId();
|
||||
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.
|
||||
* 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.
|
||||
*
|
||||
* @return null if no region associated with the time zone
|
||||
*/
|
||||
private String findRegionIdForTzId(String tzId) {
|
||||
@@ -378,7 +380,7 @@ public class TimeZoneSettings extends DashboardFragment {
|
||||
}
|
||||
|
||||
private void setPreferenceCategoryVisible(PreferenceCategory category,
|
||||
boolean isVisible) {
|
||||
boolean isVisible) {
|
||||
// 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.
|
||||
category.setVisible(isVisible);
|
||||
@@ -392,5 +394,13 @@ public class TimeZoneSettings extends DashboardFragment {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user