android 设置设置中Region & Time Zone
packages\apps\Settings\res\xml\time_zone_prefs.xml
android:title="@string/date_time_select_region"
android:summary="@string/summary_placeholder" />
android:title="@string/date_time_set_timezone_title"
android:summary="@string/summary_placeholder" />
settings:controller="com.android.settings.datetime.timezone.TimeZoneInfoPreferenceController" />
packages\apps\Settings\src\com\android\settings\datetime\timezone\TimeZoneSettings.java
protected int getPreferenceScreenResId() {
return R.xml.time_zone_prefs;
}
packages\apps\Settings\src\com\android\settings\datetime\timezone\RegionSearchPicker.java
//创建Region list view ,并添加item 点击事件
protected BaseTimeZoneAdapter createAdapter(TimeZoneData timeZoneData) { mTimeZoneData = timeZoneData; mAdapter = new BaseTimeZoneAdapter<>(createAdapterItem(timeZoneData.getRegionIds()), this::onListItemClick, getLocale(), false /* showItemSummary */, null /* headerText */); return mAdapter;}
用户点击,保存Region 和Zone
packages\apps\Settings\src\com\android\settings\datetime\timezone\TimeZoneSettings.java
private void saveTimeZone(String regionId, String tzId) { SharedPreferences.Editor editor = getPreferenceManager().getSharedPreferences().edit(); if (regionId == null) { editor.remove(PREF_KEY_REGION); } else { editor.putString(PREF_KEY_REGION, regionId); } editor.apply(); getActivity().getSystemService(AlarmManager.class).setTimeZone(tzId);}
libcore/luni/src/main/java/libcore/util/import libcore.util.CountryTimeZones;
CountryZonesFinder.java表示所有的区域(Region)TimeZoneFinder.java 这里通过 getCountryZonesFinder 来创建 CountryZonesFinder
getCountryZonesFinder 处理 /system/usr/share/zoneinfo/tzlookup.xml 这个文件
public CountryZonesFinder getCountryZonesFinder() { CountryZonesLookupExtractor extractor = new CountryZonesLookupExtractor(); try { processXml(extractor); return extractor.getCountryZonesLookup(); } catch (XmlPullParserException | IOException e) { System.logW("Error reading country zones ", e); return null; }}
/system/usr/share/zoneinfo/tzdata
/system/usr/share/zoneinfo/tzlookup.xml 这个文件记录了区域的code 并对应的时区
/** * @return the country from the system's locale. */protected Country getLocaleCountry() { Locale defaultLocale = Locale.getDefault(); if (defaultLocale != null) { return new Country(defaultLocale.getCountry(), Country.COUNTRY_SOURCE_LOCALE); } else { return null; }}
更多相关文章
- android中使用HTTP协议和TCP协议实现上传文件
- Android 读取TXT 文件中文乱码 解决方案
- android:获取网络时间、文件路径,修改包名,发布release版本
- [GeoWay]android用于打开各种文件的intent
- Android Studio设置apk文件名
- Android文件列表RecyclerView中点击视频播放
- Android Dex文件结构
- android 文件存储注意点