Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4f5a113d authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Show time zone standard name in FixedOffsetPreferenceController" into pi-dev

parents ec9606ad d251a10c
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -17,7 +17,8 @@
package com.android.settings.datetime.timezone;

import android.content.Context;
import android.support.v7.preference.Preference;

import com.android.settings.R;

public class FixedOffsetPreferenceController extends BaseTimeZonePreferenceController {

@@ -31,8 +32,18 @@ public class FixedOffsetPreferenceController extends BaseTimeZonePreferenceContr

    @Override
    public CharSequence getSummary() {
        // This is a Spannable object, which contains TTS span. It shouldn't be converted to String.
        return mTimeZoneInfo == null ? "" : mTimeZoneInfo.getGmtOffset();
        if (mTimeZoneInfo == null) {
            return "";
        }

        String standardName = mTimeZoneInfo.getStandardName();
        if (standardName == null) {
            return mTimeZoneInfo.getGmtOffset();
        } else {
            // GmtOffset is Spannable, which contains TTS span. It shouldn't be converted to String.
            return SpannableUtil.getResourcesText(mContext.getResources(),
                    R.string.zone_info_offset_and_name, mTimeZoneInfo.getGmtOffset(), standardName);
        }
    }

    public void setTimeZoneInfo(TimeZoneInfo timeZoneInfo) {
+16 −2
Original line number Diff line number Diff line
@@ -40,10 +40,9 @@ public class FixedOffsetPreferenceControllerTest {
    }

    @Test
    public void updateState_matchTimeZoneSummary() {
    public void updateState_GmtMinus8_matchTimeZoneSummary() {
        TimeZoneInfo fixedOffsetZone = new TimeZoneInfo.Builder(
                    TimeZone.getFrozenTimeZone("Etc/GMT-8"))
                    .setExemplarLocation("Los Angeles")
                    .setGmtOffset("GMT-08:00")
                    .setItemId(0)
                    .build();
@@ -52,6 +51,21 @@ public class FixedOffsetPreferenceControllerTest {
        controller.setTimeZoneInfo(fixedOffsetZone);
        controller.updateState(preference);
        assertThat(preference.getSummary()).isEqualTo("GMT-08:00");
    }

    @Test
    public void updateState_Utc_matchTimeZoneSummary() {
        TimeZoneInfo fixedOffsetZone = new TimeZoneInfo.Builder(
                    TimeZone.getFrozenTimeZone("Etc/UTC"))
                    .setStandardName("Coordinated Universal Time")
                    .setGmtOffset("GMT+00:00")
                    .setItemId(0)
                    .build();
        Preference preference = new Preference(mActivity);
        FixedOffsetPreferenceController controller = new FixedOffsetPreferenceController(mActivity);
        controller.setTimeZoneInfo(fixedOffsetZone);
        controller.updateState(preference);
        assertThat(preference.getSummary().toString())
                .isEqualTo("Coordinated Universal Time (GMT+00:00)");
    }
}