android 设置设置中Region & Time Zone

31 篇文章 1 订阅

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


    <PreferenceCategory
        android:key="time_zone_region_preference_category">
        <com.android.settingslib.RestrictedPreference
            android:key="region"
            android:title="@string/date_time_select_region"
            android:summary="@string/summary_placeholder" />
        <com.android.settingslib.RestrictedPreference
            android:key="region_zone"
            android:title="@string/date_time_set_timezone_title"
            android:summary="@string/summary_placeholder" />
        <com.android.settingslib.widget.FooterPreference
            android:key="footer_preference"
            settings:controller="com.android.settings.datetime.timezone.TimeZoneInfoPreferenceController" />
    </PreferenceCategory>

 

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;
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值