summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSara Ting <sarating@google.com>2012-04-19 13:27:11 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-04-19 13:27:11 -0700
commit76c01c89ae31408836148f3930f980910b08c18a (patch)
treedc76de8228366e998d009f30e393e7c8d7d4704f
parent0f3856a3415732ff547fa2f19ede603da4c2d94e (diff)
parent4e92627c5eb10de50c49c57e116b080d48360c70 (diff)
downloadandroid_packages_apps_Calendar-76c01c89ae31408836148f3930f980910b08c18a.tar.gz
android_packages_apps_Calendar-76c01c89ae31408836148f3930f980910b08c18a.tar.bz2
android_packages_apps_Calendar-76c01c89ae31408836148f3930f980910b08c18a.zip
Merge "Fixed missing event name from the event info details, and changed datetime description to display "Today at <time>" or "Tomorrow at <time>"."
-rw-r--r--res/values/strings.xml9
-rw-r--r--src/com/android/calendar/EventInfoFragment.java5
-rw-r--r--src/com/android/calendar/Utils.java60
-rw-r--r--tests/src/com/android/calendar/UtilsTests.java23
4 files changed, 75 insertions, 22 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 9d4e3688..dbb1bad9 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -33,6 +33,15 @@
<string name="today">Today</string>
<!-- Text to show when an event starts on the next day -->
<string name="tomorrow">Tomorrow</string>
+ <!-- Text for an event starting on the current day with a start and end time.
+ For ex, "Today at 5:00pm-6:00pm" [CHAR LIMIT=NONE] -->
+ <string name="today_at_time_fmt">"Today at <xliff:g id="time_interval">%s</xliff:g>"</string>
+ <!-- Text for an event starting on the next day with a start and end time.
+ For ex, "Tomorrow at 5:00pm-6:00pm" [CHAR LIMIT=NONE] -->
+ <string name="tomorrow_at_time_fmt">"Tomorrow at <xliff:g id="time_interval">%s</xliff:g>"</string>
+ <!-- Format string for a date and time description. For ex:
+ "April 19, 2012, 3:00pm - 4:00pm" [CHAR LIMIT=NONE] -->
+ <string name="date_time_fmt">"<xliff:g id="date">%s</xliff:g>, <xliff:g id="time_interval">%s</xliff:g>"</string>
<!-- Some events repeat daily, weekly, monthly, or yearly. This is the label
for all the choices about how often an event repeats (including the choice
diff --git a/src/com/android/calendar/EventInfoFragment.java b/src/com/android/calendar/EventInfoFragment.java
index 99450243..e385efcb 100644
--- a/src/com/android/calendar/EventInfoFragment.java
+++ b/src/com/android/calendar/EventInfoFragment.java
@@ -1103,6 +1103,11 @@ public class EventInfoFragment extends DialogFragment implements OnCheckedChange
mColor = Utils.getDisplayColorFromColor(mEventCursor.getInt(EVENT_INDEX_COLOR));
mHeadlines.setBackgroundColor(mColor);
+ // What
+ if (eventName != null) {
+ setTextCommon(view, R.id.title, eventName);
+ }
+
// When
// Set the date and repeats (if any)
String localTimezone = Utils.getTimeZone(mActivity, mTZUpdater);
diff --git a/src/com/android/calendar/Utils.java b/src/com/android/calendar/Utils.java
index bc2ba2d3..ca08f230 100644
--- a/src/com/android/calendar/Utils.java
+++ b/src/com/android/calendar/Utils.java
@@ -1156,6 +1156,7 @@ public class Utils {
Time currentTime = new Time(localTimezone);
currentTime.set(currentMillis);
+ Resources resources = context.getResources();
String datetimeString = null;
if (allDay) {
// All day events require special timezone adjustment.
@@ -1163,26 +1164,42 @@ public class Utils {
long localEndMillis = convertAlldayUtcToLocal(null, endMillis, localTimezone);
if (singleDayEvent(localStartMillis, localEndMillis, currentTime.gmtoff)) {
// If possible, use "Today" or "Tomorrow" instead of a full date string.
- datetimeString = getRelativeDayStringOrNull(context.getResources(),
+ int todayOrTomorrow = isTodayOrTomorrow(context.getResources(),
localStartMillis, currentMillis, currentTime.gmtoff);
- }
- if (datetimeString == null) {
- Formatter f = new Formatter(new StringBuilder(50), Locale.getDefault());
- datetimeString = DateUtils.formatDateRange(context, f, startMillis,
- endMillis, flagsDate, Time.TIMEZONE_UTC).toString();
+ if (TODAY == todayOrTomorrow) {
+ datetimeString = resources.getString(R.string.today);
+ } else if (TOMORROW == todayOrTomorrow) {
+ datetimeString = resources.getString(R.string.tomorrow);
+ } else {
+ Formatter f = new Formatter(new StringBuilder(50), Locale.getDefault());
+ datetimeString = DateUtils.formatDateRange(context, f, startMillis,
+ endMillis, flagsDate, Time.TIMEZONE_UTC).toString();
+ }
}
} else {
if (singleDayEvent(startMillis, endMillis, currentTime.gmtoff)) {
- // If possible, use "Today" or "Tomorrow" instead of a full date string.
- String dateString = getRelativeDayStringOrNull(context.getResources(), startMillis,
- currentTime.toMillis(false), currentTime.gmtoff);
- if (dateString == null) {
- dateString = Utils.formatDateRange(context, startMillis, endMillis, flagsDate);
- }
- // Example: "Today, 1:00pm - 2:00pm" or "Thursday, April 12, 1:00pm - 2:00pm"
+ // Format the time.
String timeString = Utils.formatDateRange(context, startMillis, endMillis,
flagsTime);
- datetimeString = dateString + ", " + timeString;
+
+ // If possible, use "Today" or "Tomorrow" instead of a full date string.
+ int todayOrTomorrow = isTodayOrTomorrow(context.getResources(), startMillis,
+ currentMillis, currentTime.gmtoff);
+ if (TODAY == todayOrTomorrow) {
+ // Example: "Today at 1:00pm - 2:00 pm"
+ datetimeString = resources.getString(R.string.today_at_time_fmt,
+ timeString);
+ } else if (TOMORROW == todayOrTomorrow) {
+ // Example: "Tomorrow at 1:00pm - 2:00 pm"
+ datetimeString = resources.getString(R.string.tomorrow_at_time_fmt,
+ timeString);
+ } else {
+ // Format the full date. Example: "Thursday, April 12, 1:00pm - 2:00pm"
+ String dateString = Utils.formatDateRange(context, startMillis, endMillis,
+ flagsDate);
+ datetimeString = resources.getString(R.string.date_time_fmt, dateString,
+ timeString);
+ }
} else {
// For multiday events, shorten day/month names.
// Example format: "Fri Apr 6, 5:00pm - Sun, Apr 8, 6:00pm"
@@ -1225,21 +1242,26 @@ public class Utils {
return startDay == endDay;
}
+ // Using int constants as a return value instead of an enum to minimize resources.
+ private static final int TODAY = 1;
+ private static final int TOMORROW = 2;
+ private static final int NONE = 0;
+
/**
- * Returns "Today" or "Tomorrow" if applicable. Otherwise returns null.
+ * Returns TODAY or TOMORROW if applicable. Otherwise returns NONE.
*/
- private static String getRelativeDayStringOrNull(Resources r, long dayMillis,
+ private static int isTodayOrTomorrow(Resources r, long dayMillis,
long currentMillis, long localGmtOffset) {
int startDay = Time.getJulianDay(dayMillis, localGmtOffset);
int currentDay = Time.getJulianDay(currentMillis, localGmtOffset);
int days = startDay - currentDay;
if (days == 1) {
- return r.getString(R.string.tomorrow);
+ return TOMORROW;
} else if (days == 0) {
- return r.getString(R.string.today);
+ return TODAY;
} else {
- return null;
+ return NONE;
}
}
}
diff --git a/tests/src/com/android/calendar/UtilsTests.java b/tests/src/com/android/calendar/UtilsTests.java
index 11181b60..60e63c8a 100644
--- a/tests/src/com/android/calendar/UtilsTests.java
+++ b/tests/src/com/android/calendar/UtilsTests.java
@@ -19,6 +19,7 @@ package com.android.calendar;
import com.android.calendar.CalendarUtils.TimeZoneUtils;
import android.content.res.Configuration;
+import android.content.res.Resources.NotFoundException;
import android.database.MatrixCursor;
import android.provider.CalendarContract.CalendarCache;
import android.test.mock.MockResources;
@@ -92,6 +93,20 @@ public class UtilsTests extends TestCase {
}
@Override
+ public String getString(int id, Object... formatArgs) {
+ if (id == R.string.today_at_time_fmt) {
+ return String.format("Today at %s", formatArgs);
+ }
+ if (id == R.string.tomorrow_at_time_fmt) {
+ return String.format("Tomorrow at %s", formatArgs);
+ }
+ if (id == R.string.date_time_fmt) {
+ return String.format("%s, %s", formatArgs);
+ }
+ throw new IllegalArgumentException("unexpected resource ID: " + id);
+ }
+
+ @Override
public Configuration getConfiguration() {
Configuration config = new Configuration();
config.locale = Locale.getDefault();
@@ -397,7 +412,7 @@ public class UtilsTests extends TestCase {
long end = createTimeInMillis(0, 0, 18, NOW_DAY, NOW_MONTH, NOW_YEAR);
String result = Utils.getDisplayedDatetime(start, end, NOW_TIME, DEFAULT_TIMEZONE,
DEFAULT_TIMEZONE, false, dbUtils.getContext());
- assertEquals("Today, 5:00pm \u2013 6:00pm", result);
+ assertEquals("Today at 5:00pm \u2013 6:00pm", result);
}
@SmallTest
@@ -407,7 +422,7 @@ public class UtilsTests extends TestCase {
long end = createTimeInMillis(0, 0, 0, NOW_DAY + 1, NOW_MONTH, NOW_YEAR);
String result = Utils.getDisplayedDatetime(start, end, NOW_TIME, DEFAULT_TIMEZONE,
DEFAULT_TIMEZONE, false, dbUtils.getContext());
- assertEquals("Today, 5:00pm \u2013 midnight", result);
+ assertEquals("Today at 5:00pm \u2013 midnight", result);
}
@SmallTest
@@ -417,7 +432,7 @@ public class UtilsTests extends TestCase {
long end = createTimeInMillis(0, 59, 23, NOW_DAY + 1, NOW_MONTH, NOW_YEAR);
String result = Utils.getDisplayedDatetime(start, end, NOW_TIME, DEFAULT_TIMEZONE,
DEFAULT_TIMEZONE, false, dbUtils.getContext());
- assertEquals("Tomorrow, 12:01am \u2013 11:59pm", result);
+ assertEquals("Tomorrow at 12:01am \u2013 11:59pm", result);
}
@SmallTest
@@ -501,4 +516,6 @@ public class UtilsTests extends TestCase {
Time.TIMEZONE_UTC, true, dbUtils.getContext());
assertEquals("Tomorrow", result);
}
+
+ // TODO: add tests for army time.
}