packages\apps\Settings\res\xml\time_zone_prefs.xml


            android:key="time_zone_region_preference_category">
                    android:key="region"
            android:title="@string/date_time_select_region"
            android:summary="@string/summary_placeholder" />
                    android:key="region_zone"
            android:title="@string/date_time_set_timezone_title"
            android:summary="@string/summary_placeholder" />
                    android:key="footer_preference"
            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;    }}

 

更多相关文章

  1. android中使用HTTP协议和TCP协议实现上传文件
  2. Android 读取TXT 文件中文乱码 解决方案
  3. android:获取网络时间、文件路径,修改包名,发布release版本
  4. [GeoWay]android用于打开各种文件的intent
  5. Android Studio设置apk文件名
  6. Android文件列表RecyclerView中点击视频播放
  7. Android Dex文件结构
  8. android 文件存储注意点

随机推荐

  1. 练习2-12 输出华氏-摄氏温度转换表 (15分
  2. 介绍几种常见的作图软件
  3. flex布局理解
  4. 遇到位置不可用怎样解决?
  5. 报培训班和自学的差别到底在哪
  6. Linux主流的发行版本!初学者的首选
  7. 论学习资源的重要性
  8. Python和Java哪个好?分析!
  9. EGG Network阿凡提的模式是怎么样的?早点
  10. 买房,程序员的高考。