From a5de5ceb0e3d86c5efa9be22051cb45bae35114e Mon Sep 17 00:00:00 2001 From: Daniel Applebaum Date: Sun, 18 Jan 2009 16:46:08 +0000 Subject: [PATCH] Eliminate use of Android-private APIs for getting user-selected date/time formats. With this change, K-9 can run on original master or cupcake versions for the platform. This seems like an excessive amount of code. Perhaps there is a public API that accomplishes this work. Alternatively, the code in MessageView.java and FolderMessageList.java should be consolidated into a utility class used by both of the classes needing this functionality. --- src/com/android/email/Email.java | 5 ++++ .../email/activity/FolderMessageList.java | 17 +++++++++--- .../android/email/activity/MessageView.java | 27 +++++++++++++------ 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/src/com/android/email/Email.java b/src/com/android/email/Email.java index ad06daeb5..08efba737 100644 --- a/src/com/android/email/Email.java +++ b/src/com/android/email/Email.java @@ -143,6 +143,11 @@ public class Email extends Application { public static final int FETCHING_EMAIL_NOTIFICATION_ID = -4; public static final int FETCHING_EMAIL_NOTIFICATION_MULTI_ACCOUNT_ID = -1; public static final int FETCHING_EMAIL_NOTIFICATION_NO_ACCOUNT = -2; + + // Backup formats in case they can't be fetched from the system + public static final String BACKUP_DATE_FORMAT = "MM-dd-yyyy"; + public static final String TIME_FORMAT_12 = "h:mm a"; + public static final String TIME_FORMAT_24 = "H:mm"; /** * Called throughout the application when the number of accounts has changed. This method diff --git a/src/com/android/email/activity/FolderMessageList.java b/src/com/android/email/activity/FolderMessageList.java index e702610d6..c38ca73bb 100644 --- a/src/com/android/email/activity/FolderMessageList.java +++ b/src/com/android/email/activity/FolderMessageList.java @@ -148,7 +148,15 @@ public class FolderMessageList extends ExpandableListActivity { if (dateFormat == null) { - dateFormat = android.pim.DateFormat.getDateFormat(getApplication()); + String dateFormatS = android.provider.Settings.System.getString(getContentResolver(), + android.provider.Settings.System.DATE_FORMAT); + if (dateFormatS != null) { + dateFormat = new java.text.SimpleDateFormat(dateFormatS); + } + else + { + dateFormat = new java.text.SimpleDateFormat(Email.BACKUP_DATE_FORMAT); + } } return dateFormat; } @@ -156,8 +164,11 @@ public class FolderMessageList extends ExpandableListActivity private DateFormat getTimeFormat() { if (timeFormat == null) - { - timeFormat = android.pim.DateFormat.getTimeFormat(getApplication()); + { + String timeFormatS = android.provider.Settings.System.getString(getContentResolver(), + android.provider.Settings.System.TIME_12_24); + boolean b24 = !(timeFormatS == null || timeFormatS.equals("12")); + timeFormat = new java.text.SimpleDateFormat(b24 ? Email.TIME_FORMAT_24 : Email.TIME_FORMAT_12); } return timeFormat; } diff --git a/src/com/android/email/activity/MessageView.java b/src/com/android/email/activity/MessageView.java index 4ed91553c..3c55aecbb 100644 --- a/src/com/android/email/activity/MessageView.java +++ b/src/com/android/email/activity/MessageView.java @@ -100,18 +100,29 @@ public class MessageView extends Activity private DateFormat getDateFormat() { - if (dateFormat == null) - { - dateFormat = android.pim.DateFormat.getDateFormat(getApplication()); - } + if (dateFormat == null) + { + String dateFormatS = android.provider.Settings.System.getString(getContentResolver(), + android.provider.Settings.System.DATE_FORMAT); + if (dateFormatS != null) { + dateFormat = new java.text.SimpleDateFormat(dateFormatS); + } + else + { + dateFormat = new java.text.SimpleDateFormat(Email.BACKUP_DATE_FORMAT); + } + } return dateFormat; } private DateFormat getTimeFormat() { - if (timeFormat == null) - { - timeFormat = android.pim.DateFormat.getTimeFormat(getApplication()); - } + if (timeFormat == null) + { + String timeFormatS = android.provider.Settings.System.getString(getContentResolver(), + android.provider.Settings.System.TIME_12_24); + boolean b24 = !(timeFormatS == null || timeFormatS.equals("12")); + timeFormat = new java.text.SimpleDateFormat(b24 ? Email.TIME_FORMAT_24 : Email.TIME_FORMAT_12); + } return timeFormat; } private void clearFormats()