diff options
| -rw-r--r-- | core/java/android/service/notification/SystemZenRules.java | 15 | ||||
| -rw-r--r-- | services/tests/uiservicestests/src/com/android/server/notification/SystemZenRulesTest.java | 24 | 
2 files changed, 34 insertions, 5 deletions
| diff --git a/core/java/android/service/notification/SystemZenRules.java b/core/java/android/service/notification/SystemZenRules.java index 22234a95eef8..1d18643c4ac1 100644 --- a/core/java/android/service/notification/SystemZenRules.java +++ b/core/java/android/service/notification/SystemZenRules.java @@ -129,10 +129,7 @@ public final class SystemZenRules {          }          sb.append(daysSummary);          sb.append(context.getString(R.string.zen_mode_trigger_summary_divider_text)); -        sb.append(context.getString( -                R.string.zen_mode_trigger_summary_range_symbol_combination, -                timeString(context, schedule.startHour, schedule.startMinute), -                timeString(context, schedule.endHour, schedule.endMinute))); +        sb.append(getTimeSummary(context, schedule));          return sb.toString();      } @@ -142,7 +139,7 @@ public final class SystemZenRules {       * adjacent days grouped together ("Sun-Wed" instead of "Sun,Mon,Tue,Wed").       */      @Nullable -    private static String getShortDaysSummary(Context context, @NonNull ScheduleInfo schedule) { +    public static String getShortDaysSummary(Context context, @NonNull ScheduleInfo schedule) {          // Compute a list of days with contiguous days grouped together, for example: "Sun-Thu" or          // "Sun-Mon,Wed,Fri"          final int[] days = schedule.days; @@ -224,6 +221,14 @@ public final class SystemZenRules {          return null;      } +    /** Returns the time part of a {@link ScheduleInfo}, e.g. {@code 9:00-17:00}. */ +    public static String getTimeSummary(Context context, @NonNull ScheduleInfo schedule) { +        return context.getString( +                R.string.zen_mode_trigger_summary_range_symbol_combination, +                timeString(context, schedule.startHour, schedule.startMinute), +                timeString(context, schedule.endHour, schedule.endMinute)); +    } +      /**       * Convenience method for representing the specified time in string format.       */ diff --git a/services/tests/uiservicestests/src/com/android/server/notification/SystemZenRulesTest.java b/services/tests/uiservicestests/src/com/android/server/notification/SystemZenRulesTest.java index 7aa208bd04c9..5de323bc819c 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/SystemZenRulesTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/SystemZenRulesTest.java @@ -207,4 +207,28 @@ public class SystemZenRulesTest extends UiServiceTestCase {          assertThat(getTriggerDescriptionForScheduleTime(mContext, scheduleInfo))                  .isEqualTo("Mon,Wed,Fri-Sat,10:00 AM-4:00 PM");      } + +    @Test +    public void getShortDaysSummary_onlyDays() { +        ScheduleInfo scheduleInfo = new ScheduleInfo(); +        scheduleInfo.startHour = 10; +        scheduleInfo.endHour = 16; +        scheduleInfo.days = new int[] {Calendar.MONDAY, Calendar.TUESDAY, +                Calendar.WEDNESDAY, Calendar.THURSDAY, Calendar.FRIDAY}; + +        assertThat(SystemZenRules.getShortDaysSummary(mContext, scheduleInfo)) +                .isEqualTo("Mon-Fri"); +    } + +    @Test +    public void getTimeSummary_onlyTime() { +        ScheduleInfo scheduleInfo = new ScheduleInfo(); +        scheduleInfo.startHour = 11; +        scheduleInfo.endHour = 15; +        scheduleInfo.days = new int[] {Calendar.MONDAY, Calendar.TUESDAY, +                Calendar.WEDNESDAY, Calendar.THURSDAY, Calendar.FRIDAY}; + +        assertThat(SystemZenRules.getTimeSummary(mContext, scheduleInfo)) +                .isEqualTo("11:00 AM-3:00 PM"); +    }  } |