1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-08-13 17:03:48 -04:00

Remove 100loc of custom date formatting code which worked around a deficiency in the android 1.0 API

This commit is contained in:
Jesse Vincent 2009-11-27 21:52:48 +00:00
parent 5727cb3c3b
commit 7707270b31
3 changed files with 39 additions and 138 deletions

View File

@ -1,6 +1,5 @@
package com.android.email.activity;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
@ -18,6 +17,7 @@ import android.os.Bundle;
import android.os.Handler;
import android.util.Config;
import android.util.Log;
import android.text.format.DateFormat;
import android.view.ContextMenu;
import android.view.KeyEvent;
import android.view.LayoutInflater;
@ -83,51 +83,12 @@ public class FolderList extends K9ListActivity
private FolderListHandler mHandler = new FolderListHandler();
private DateFormat dateFormat = null;
private DateFormat timeFormat = null;
private boolean mStartup = false;
private DateFormat getDateFormat()
{
if (dateFormat == null)
{
String dateFormatS = android.provider.Settings.System.getString(getContentResolver(),
android.provider.Settings.System.DATE_FORMAT);
private java.text.DateFormat mDateFormat;
if (dateFormatS != null)
{
dateFormat = new java.text.SimpleDateFormat(dateFormatS);
}
else
{
dateFormat = new java.text.SimpleDateFormat(Email.BACKUP_DATE_FORMAT);
}
}
private java.text.DateFormat mTimeFormat;
return dateFormat;
}
private DateFormat getTimeFormat()
{
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()
{
dateFormat = null;
timeFormat = null;
}
class FolderListHandler extends Handler
{
@ -393,6 +354,10 @@ public class FolderList extends K9ListActivity
Intent intent = getIntent();
mAccount = (Account)intent.getSerializableExtra(EXTRA_ACCOUNT);
Log.v(Email.LOG_TAG, "savedInstanceState: " + (savedInstanceState==null));
mDateFormat = android.text.format.DateFormat.getDateFormat(this); // short format
mTimeFormat = android.text.format.DateFormat.getTimeFormat(this); // 12/24 date format
if (savedInstanceState == null)
{
initialFolder = intent.getStringExtra(EXTRA_INITIAL_FOLDER);
@ -486,7 +451,6 @@ public class FolderList extends K9ListActivity
@Override public void onResume()
{
super.onResume();
clearFormats();
MessagingController.getInstance(getApplication()).addListener(mAdapter.mListener);
mAccount.refresh(Preferences.getPreferences(this));
@ -1233,8 +1197,8 @@ public class FolderList extends K9ListActivity
{
Date lastCheckedDate = new Date(folder.lastChecked);
statusText = (getDateFormat().format(lastCheckedDate) + " " + getTimeFormat()
.format(lastCheckedDate));
statusText = mTimeFormat.format(lastCheckedDate) + " "+
mDateFormat.format(lastCheckedDate);
}
if (folder.pushActive)

View File

@ -1,6 +1,5 @@
package com.android.email.activity;
//import android.os.Debug;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
@ -17,6 +16,7 @@ import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.text.format.DateFormat;
import android.util.Config;
import android.util.Log;
import android.view.ContextMenu;
@ -135,6 +135,10 @@ public class MessageList
private Account mAccount;
private java.text.DateFormat mDateFormat;
private java.text.DateFormat mTimeFormat;
/**
* Stores the name of the folder that we want to open as soon as possible
@ -144,10 +148,6 @@ public class MessageList
private MessageListHandler mHandler = new MessageListHandler();
private DateFormat dateFormat = null;
private DateFormat timeFormat = null;
private SORT_TYPE sortType = SORT_TYPE.SORT_DATE;
private boolean sortAscending = true;
@ -163,48 +163,6 @@ public class MessageList
private Button mBatchDeleteButton;
private Button mBatchFlagButton;
private DateFormat getDateFormat()
{
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)
{
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()
{
dateFormat = null;
timeFormat = null;
}
class MessageListHandler extends Handler
{
@ -401,10 +359,12 @@ public class MessageList
mAdapter.mListener);
return;
}
else if (mSelectedWidget == WIDGET_MULTISELECT) {
else if (mSelectedWidget == WIDGET_MULTISELECT)
{
CheckBox selected = (CheckBox) v.findViewById(R.id.selected_checkbox);
selected.setChecked(!selected.isChecked());
} else
}
else
{
MessageInfoHolder message = (MessageInfoHolder) mAdapter.getItem(position);
onOpenMessage(message);
@ -428,6 +388,11 @@ public class MessageList
mListView.setScrollingCacheEnabled(true);
mListView.setOnItemClickListener(this);
mDateFormat = android.text.format.DateFormat.getDateFormat(this); // short format
mTimeFormat = android.text.format.DateFormat.getTimeFormat(this); // 12/24 date format
registerForContextMenu(mListView);
/*
@ -536,7 +501,6 @@ public class MessageList
public void onResume()
{
super.onResume();
clearFormats();
sortType = MessagingController.getInstance(getApplication()).getSortType();
sortAscending = MessagingController.getInstance(getApplication()).isSortAscending(sortType);
sortDateAscending = MessagingController.getInstance(getApplication()).isSortAscending(SORT_TYPE.SORT_DATE);
@ -626,7 +590,7 @@ public class MessageList
{
if (position >= 0)
{
MessageInfoHolder message = (MessageInfoHolder) mAdapter.getItem(position);
MessageInfoHolder message = (MessageInfoHolder) mAdapter.getItem(position);
if (message != null)
@ -2013,13 +1977,14 @@ public class MessageList
if (Utility.isDateToday(date))
{
this.date = getTimeFormat().format(date);
this.date = mTimeFormat.format(date);
}
else
{
this.date = getDateFormat().format(date);
this.date = mDateFormat.format(date);
}
this.hasAttachments = message.getAttachmentCount() > 0;
this.read = message.isSet(Flag.SEEN);

View File

@ -96,6 +96,11 @@ public class MessageView extends K9Activity
private static final int ACTIVITY_CHOOSE_FOLDER_COPY = 2;
private java.text.DateFormat mDateFormat;
private java.text.DateFormat mTimeFormat;
private TextView mFromView;
private TextView mDateView;
private TextView mTimeView;
@ -129,45 +134,8 @@ public class MessageView extends K9Activity
private GestureDetector gestureDetector;
private DateFormat dateFormat = null;
private DateFormat timeFormat = null;
private Menu optionsMenu = null;
private DateFormat getDateFormat()
{
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)
{
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()
{
dateFormat = null;
timeFormat = null;
}
private Listener mListener = new Listener();
private MessageViewHandler mHandler = new MessageViewHandler();
@ -520,6 +488,11 @@ public class MessageView extends K9Activity
setContentView(R.layout.message_view);
mDateFormat = android.text.format.DateFormat.getDateFormat(this); // short format
mTimeFormat = android.text.format.DateFormat.getTimeFormat(this); // 12/24 date format
mFromView = (TextView)findViewById(R.id.from);
mToView = (TextView)findViewById(R.id.to);
mCcView = (TextView)findViewById(R.id.cc);
@ -770,7 +743,6 @@ public class MessageView extends K9Activity
public void onResume()
{
super.onResume();
clearFormats();
}
private void onDelete()
@ -1410,8 +1382,8 @@ public class MessageView extends K9Activity
String fromText = Address.toFriendly(message.getFrom());
String dateText = Utility.isDateToday(message.getSentDate()) ?
null :
getDateFormat().format(message.getSentDate());
String timeText = getTimeFormat().format(message.getSentDate());
mDateFormat.format(message.getSentDate());
String timeText = mTimeFormat.format(message.getSentDate());
String toText = Address.toFriendly(message.getRecipients(RecipientType.TO));
String ccText = Address.toFriendly(message.getRecipients(RecipientType.CC));
Log.d(Email.LOG_TAG, ccText);