Fixes Issue 835
This commit is contained in:
parent
d871d2d2ee
commit
61319d8c21
9 changed files with 177 additions and 30 deletions
|
@ -205,5 +205,12 @@
|
|||
<item>ALWAYS</item>
|
||||
<item>NEVER</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="date_formats">
|
||||
<item>@string/date_format_short</item>
|
||||
<item>@string/date_format_medium</item>
|
||||
<item>@string/date_format_common</item>
|
||||
<item>@string/date_format_iso8601</item>
|
||||
</string-array>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -564,4 +564,12 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin
|
|||
<string name="background_ops_enabled">When \'Background data\' is checked</string>
|
||||
|
||||
<string name="no_message_seletected_toast">No message selected</string>
|
||||
|
||||
<string name="date_format_label">Date format</string>
|
||||
<string name="date_format_short">SHORT</string>
|
||||
<string name="date_format_medium">MEDIUM</string>
|
||||
<string name="date_format_common">dd-MMM-yyyy</string>
|
||||
<string name="date_format_iso8601">yyyy-MM-dd</string>
|
||||
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -24,6 +24,13 @@
|
|||
android:entries="@array/settings_theme_entries"
|
||||
android:entryValues="@array/settings_theme_values"
|
||||
android:dialogTitle="@string/settings_theme_label" />
|
||||
|
||||
<ListPreference
|
||||
android:key="dateFormat"
|
||||
android:title="@string/date_format_label"
|
||||
android:entries="@array/date_formats"
|
||||
android:entryValues="@array/date_formats"
|
||||
android:dialogTitle="@string/date_format_label" />
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory android:title="@string/operational_preferences" android:key="operational_preferences">
|
||||
|
|
|
@ -463,14 +463,12 @@ public class Email extends Application
|
|||
|
||||
}
|
||||
|
||||
public static void save(SharedPreferences preferences)
|
||||
public static void save(SharedPreferences.Editor editor)
|
||||
{
|
||||
SharedPreferences.Editor editor = preferences.edit();
|
||||
editor.putBoolean("enableDebugLogging", Email.DEBUG);
|
||||
editor.putBoolean("enableSensitiveLogging", Email.DEBUG_SENSITIVE);
|
||||
editor.putString("backgroundOperations", Email.backgroundOps.toString());
|
||||
editor.putInt("theme", theme);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
103
src/com/android/email/activity/DateFormatter.java
Normal file
103
src/com/android/email/activity/DateFormatter.java
Normal file
|
@ -0,0 +1,103 @@
|
|||
package com.android.email.activity;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
|
||||
import com.android.email.Preferences;
|
||||
import com.android.email.R;
|
||||
|
||||
public class DateFormatter
|
||||
{
|
||||
private DateFormatter()
|
||||
{
|
||||
}
|
||||
private final static Calendar SAMPLE_DATE = Calendar.getInstance();
|
||||
static
|
||||
{
|
||||
SAMPLE_DATE.set(SAMPLE_DATE.get(Calendar.YEAR), SAMPLE_DATE.getActualMaximum(Calendar.MONTH), SAMPLE_DATE.getActualMaximum(Calendar.DAY_OF_MONTH));
|
||||
}
|
||||
|
||||
public static final String SHORT_FORMAT = "SHORT";
|
||||
public static final String MEDIUM_FORMAT = "MEDIUM";
|
||||
public static final String DEFAULT_FORMAT = SHORT_FORMAT;
|
||||
|
||||
public static final String PREF_KEY = "dateFormat";
|
||||
|
||||
private static volatile String sChosenFormat = null;
|
||||
|
||||
public static String getSampleDate(Context context, String formatString)
|
||||
{
|
||||
java.text.DateFormat formatter = getDateFormat(context, formatString);
|
||||
return formatter.format(SAMPLE_DATE.getTime());
|
||||
}
|
||||
|
||||
public static String[] getFormats(Context context)
|
||||
{
|
||||
return context.getResources().getStringArray(R.array.date_formats);
|
||||
}
|
||||
|
||||
private static ThreadLocal<Map<String, DateFormat>> storedFormats = new ThreadLocal<Map<String, DateFormat>>()
|
||||
{
|
||||
@Override
|
||||
public synchronized Map<String, DateFormat> initialValue()
|
||||
{
|
||||
return new HashMap<String, DateFormat>();
|
||||
}
|
||||
};
|
||||
|
||||
public static DateFormat getDateFormat(Context context, String formatString)
|
||||
{
|
||||
java.text.DateFormat dateFormat;
|
||||
|
||||
if (SHORT_FORMAT.equals(formatString))
|
||||
{
|
||||
dateFormat = android.text.format.DateFormat.getDateFormat(context);
|
||||
}
|
||||
else if (MEDIUM_FORMAT.equals(formatString))
|
||||
{
|
||||
dateFormat = android.text.format.DateFormat.getMediumDateFormat(context);
|
||||
}
|
||||
else
|
||||
{
|
||||
Map<String, DateFormat> formatMap = storedFormats.get();
|
||||
dateFormat = formatMap.get(formatString);
|
||||
|
||||
if (dateFormat == null)
|
||||
{
|
||||
dateFormat = new SimpleDateFormat(formatString);
|
||||
formatMap.put(formatString, dateFormat);
|
||||
}
|
||||
}
|
||||
return dateFormat;
|
||||
}
|
||||
|
||||
public static void setDateFormat(Editor editor, String formatString)
|
||||
{
|
||||
sChosenFormat = formatString;
|
||||
editor.putString(PREF_KEY, formatString);
|
||||
}
|
||||
|
||||
public static String getFormat(Context context)
|
||||
{
|
||||
if (sChosenFormat == null)
|
||||
{
|
||||
Preferences prefs = Preferences.getPreferences(context);
|
||||
String chosenFormat = prefs.getPreferences().getString(PREF_KEY, DEFAULT_FORMAT);
|
||||
|
||||
sChosenFormat = chosenFormat;
|
||||
}
|
||||
return sChosenFormat;
|
||||
}
|
||||
|
||||
public static DateFormat getDateFormat(Context context)
|
||||
{
|
||||
String formatString = getFormat(context);
|
||||
return getDateFormat(context, formatString);
|
||||
}
|
||||
}
|
|
@ -17,7 +17,6 @@ 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;
|
||||
|
@ -355,9 +354,6 @@ public class FolderList extends K9ListActivity
|
|||
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);
|
||||
|
@ -452,6 +448,9 @@ public class FolderList extends K9ListActivity
|
|||
{
|
||||
super.onResume();
|
||||
|
||||
mDateFormat = DateFormatter.getDateFormat(this);
|
||||
mTimeFormat = android.text.format.DateFormat.getTimeFormat(this); // 12/24 date format
|
||||
|
||||
MessagingController.getInstance(getApplication()).addListener(mAdapter.mListener);
|
||||
mAccount.refresh(Preferences.getPreferences(this));
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ 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;
|
||||
|
@ -387,9 +386,6 @@ public class MessageList
|
|||
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);
|
||||
|
||||
|
@ -499,6 +495,10 @@ public class MessageList
|
|||
public void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
|
||||
mDateFormat = DateFormatter.getDateFormat(this);
|
||||
mTimeFormat = android.text.format.DateFormat.getTimeFormat(this); // 12/24 date format
|
||||
|
||||
sortType = MessagingController.getInstance(getApplication()).getSortType();
|
||||
sortAscending = MessagingController.getInstance(getApplication()).isSortAscending(sortType);
|
||||
sortDateAscending = MessagingController.getInstance(getApplication()).isSortAscending(SORT_TYPE.SORT_DATE);
|
||||
|
@ -2103,6 +2103,7 @@ public class MessageList
|
|||
public TextView subject;
|
||||
public TextView preview;
|
||||
public TextView from;
|
||||
public TextView time;
|
||||
public TextView date;
|
||||
public CheckBox flagged;
|
||||
public View chip;
|
||||
|
|
|
@ -6,7 +6,6 @@ import java.io.FileOutputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.text.DateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -488,10 +487,6 @@ 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);
|
||||
|
@ -743,6 +738,11 @@ public class MessageView extends K9Activity
|
|||
public void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
|
||||
mDateFormat = DateFormatter.getDateFormat(this);
|
||||
mTimeFormat = android.text.format.DateFormat.getTimeFormat(this); // 12/24 date format
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void onDelete()
|
||||
|
|
|
@ -3,37 +3,31 @@ package com.android.email.activity.setup;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.os.Bundle;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.preference.EditTextPreference;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.preference.RingtonePreference;
|
||||
import android.preference.Preference.OnPreferenceClickListener;
|
||||
import android.view.KeyEvent;
|
||||
|
||||
import com.android.email.K9PreferenceActivity;
|
||||
import com.android.email.Account;
|
||||
import com.android.email.Email;
|
||||
import com.android.email.K9PreferenceActivity;
|
||||
import com.android.email.Preferences;
|
||||
import com.android.email.R;
|
||||
import com.android.email.activity.DateFormatter;
|
||||
import com.android.email.service.MailService;
|
||||
|
||||
public class Prefs extends K9PreferenceActivity
|
||||
{
|
||||
|
||||
private static final String PREFERENCE_TOP_CATERGORY = "preferences";
|
||||
private static final String PREFERENCE_THEME = "theme";
|
||||
private static final String PREFERENCE_DATE_FORMAT = "dateFormat";
|
||||
private static final String PREFERENCE_BACKGROUND_OPS = "background_ops";
|
||||
private static final String PREFERENCE_DEBUG_LOGGING = "debug_logging";
|
||||
private static final String PREFERENCE_SENSITIVE_LOGGING = "sensitive_logging";
|
||||
|
||||
private ListPreference mTheme;
|
||||
private ListPreference mDateFormat;
|
||||
private ListPreference mBackgroundOps;
|
||||
private CheckBoxPreference mDebugLogging;
|
||||
private CheckBoxPreference mSensitiveLogging;
|
||||
|
@ -69,6 +63,33 @@ public class Prefs extends K9PreferenceActivity
|
|||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
mDateFormat = (ListPreference) findPreference(PREFERENCE_DATE_FORMAT);
|
||||
String[] formats = DateFormatter.getFormats(this);
|
||||
CharSequence[] entries = new CharSequence[formats.length];
|
||||
CharSequence[] values = new CharSequence[formats.length];
|
||||
for (int i = 0 ; i < formats.length; i++)
|
||||
{
|
||||
String format = formats[i];
|
||||
entries[i] = DateFormatter.getSampleDate(this, format);;
|
||||
values[i] = format;
|
||||
}
|
||||
mDateFormat.setEntries(entries);
|
||||
mDateFormat.setEntryValues(values);
|
||||
|
||||
mDateFormat.setValue(DateFormatter.getFormat(this));
|
||||
mDateFormat.setSummary(mDateFormat.getEntry());
|
||||
mDateFormat.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
|
||||
{
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue)
|
||||
{
|
||||
final String summary = newValue.toString();
|
||||
int index = mDateFormat.findIndexOfValue(summary);
|
||||
mDateFormat.setSummary(mDateFormat.getEntries()[index]);
|
||||
mDateFormat.setValue(summary);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
mBackgroundOps = (ListPreference) findPreference(PREFERENCE_BACKGROUND_OPS);
|
||||
initBackgroundOps = Email.getBackgroundOps().toString();
|
||||
|
@ -108,7 +129,10 @@ public class Prefs extends K9PreferenceActivity
|
|||
Email.DEBUG_SENSITIVE = mSensitiveLogging.isChecked();
|
||||
String newBackgroundOps = mBackgroundOps.getValue();
|
||||
Email.setBackgroundOps(newBackgroundOps);
|
||||
Email.save(preferences);
|
||||
Editor editor = preferences.edit();
|
||||
Email.save(editor);
|
||||
DateFormatter.setDateFormat(editor, mDateFormat.getValue());
|
||||
editor.commit();
|
||||
if (newBackgroundOps.equals(initBackgroundOps) == false)
|
||||
{
|
||||
MailService.backgroundDataChanged(this, null);
|
||||
|
|
Loading…
Reference in a new issue