summaryrefslogtreecommitdiff
path: root/InCallUI/src/com/android/incallui
diff options
context:
space:
mode:
authorNancy Chen <nancychen@google.com>2015-11-11 16:24:15 -0800
committerNancy Chen <nancychen@google.com>2015-11-12 12:03:56 -0800
commitc2087df5fac6bc8760395ebf8c8366c569fa2f9d (patch)
treea68fe916a3266141ea595b88a3dd60ec35597167 /InCallUI/src/com/android/incallui
parent3c4f8067c0ce904fb05c8ef427cf8ff083ba334e (diff)
Modify the hours of operation display text for multiple intervals.
In order to not overflow the business hours display, we only want to display two intervals at most. Other logic will be used for determining what to display if there are more than 2 intervals, it is currently closed between intervals, and it is closed after all open hours. Bug: 25488385 Change-Id: I9a3ee2967dfd0acc9a9cdc653b27e45c358255e8
Diffstat (limited to 'InCallUI/src/com/android/incallui')
-rw-r--r--InCallUI/src/com/android/incallui/InCallContactInteractions.java71
1 files changed, 60 insertions, 11 deletions
diff --git a/InCallUI/src/com/android/incallui/InCallContactInteractions.java b/InCallUI/src/com/android/incallui/InCallContactInteractions.java
index 275243e4d..6fade9bdf 100644
--- a/InCallUI/src/com/android/incallui/InCallContactInteractions.java
+++ b/InCallUI/src/com/android/incallui/InCallContactInteractions.java
@@ -142,33 +142,82 @@ public class InCallContactInteractions {
BusinessContextInfo hoursInfo = new BusinessContextInfo();
hoursInfo.iconId = R.drawable.ic_schedule_white_24dp;
- boolean isOpen = false;
+ boolean isOpenNow = false;
+ // This variable records which interval the current time is after. 0 denotes none of the
+ // intervals, 1 after the first interval, etc.
+ int afterInterval = 0;
+ // This variable records counts the number of time intervals in today's opening hours.
+ int todaysIntervalCount = 0;
for (Pair<Calendar, Calendar> hours : openingHours) {
if (hours.first.compareTo(currentTime) <= 0
&& currentTime.compareTo(hours.second) < 0) {
// If the current time is on or after the opening time and strictly before the
// closing time, then this business is open.
- isOpen = true;
+ isOpenNow = true;
}
- String openTimeSpan = mContext.getString(R.string.open_time_span,
- DateFormat.getTimeFormat(mContext).format(hours.first.getTime()),
- DateFormat.getTimeFormat(mContext).format(hours.second.getTime()));
+ if (currentTime.get(Calendar.DAY_OF_YEAR) == hours.first.get(Calendar.DAY_OF_YEAR)) {
+ todaysIntervalCount += 1;
+ }
- if (TextUtils.isEmpty(hoursInfo.detail)) {
- hoursInfo.detail = openTimeSpan;
- } else {
- hoursInfo.detail = mContext.getString(R.string.opening_hours, hoursInfo.detail,
- openTimeSpan);
+ if (currentTime.compareTo(hours.second) > 0) {
+ // This assumes that the list of intervals is sorted by time.
+ afterInterval += 1;
}
}
- hoursInfo.heading = isOpen ? mContext.getString(R.string.open_now)
+ hoursInfo.heading = isOpenNow ? mContext.getString(R.string.open_now)
: mContext.getString(R.string.closed_now);
+ /*
+ * The following logic determines what to display in various cases for hours of operation.
+ *
+ * - Display all intervals if open now and number of intervals is <=2.
+ * - Display next closing time if open now and number of intervals is >2.
+ * - Display next opening time if currently closed but opens later today.
+ * - Display last time it closed today if closed now and tomorrow's hours are unknown.
+ * - Display tomorrow's first open time if closed today and tomorrow's hours are known.
+ */
+ if (isOpenNow) {
+ if (todaysIntervalCount == 1) {
+ hoursInfo.detail = getTimeSpanStringForHours(openingHours.get(0));
+ } else if (todaysIntervalCount == 2) {
+ hoursInfo.detail = mContext.getString(R.string.opening_hours,
+ getTimeSpanStringForHours(openingHours.get(0)),
+ getTimeSpanStringForHours(openingHours.get(1)));
+ } else {
+ hoursInfo.detail = mContext.getString(R.string.closes_today_at,
+ getFormattedTimeForCalendar(openingHours.get(afterInterval).second));
+ }
+ } else {
+ // Currently closed
+ final int lastIntervalToday = todaysIntervalCount - 1;
+ if (currentTime.before(openingHours.get(lastIntervalToday).first)) {
+ hoursInfo.detail = mContext.getString(R.string.opens_today_at,
+ getFormattedTimeForCalendar(openingHours.get(afterInterval).first));
+ } else if (todaysIntervalCount < openingHours.size()){
+ // Assuming all intervals after today's intervals are exhausted are tomorrow's.
+ hoursInfo.detail = mContext.getString(R.string.opens_tomorrow_at,
+ getFormattedTimeForCalendar(openingHours.get(todaysIntervalCount).first));
+ } else {
+ hoursInfo.detail = mContext.getString(R.string.closed_today_at,
+ getFormattedTimeForCalendar(openingHours.get(lastIntervalToday).second));
+ }
+ }
+
return hoursInfo;
}
+ String getFormattedTimeForCalendar(Calendar calendar) {
+ return DateFormat.getTimeFormat(mContext).format(calendar.getTime());
+ }
+
+ String getTimeSpanStringForHours(Pair<Calendar, Calendar> hours) {
+ return mContext.getString(R.string.open_time_span,
+ getFormattedTimeForCalendar(hours.first),
+ getFormattedTimeForCalendar(hours.second));
+ }
+
/**
* Construct a BusinessContextInfo object with the location information of the business.
* The format is: