diff --git a/src/com/fsck/k9/Account.java b/src/com/fsck/k9/Account.java
index e70af5890..cf8a9be84 100644
--- a/src/com/fsck/k9/Account.java
+++ b/src/com/fsck/k9/Account.java
@@ -32,8 +32,7 @@ import java.util.concurrent.ConcurrentHashMap;
* Account stores all of the settings for a single account defined by the user. It is able to save
* and delete itself given a Preferences to work with. Each account is defined by a UUID.
*/
-public class Account implements BaseAccount
-{
+public class Account implements BaseAccount {
public static final String EXPUNGE_IMMEDIATELY = "EXPUNGE_IMMEDIATELY";
public static final String EXPUNGE_MANUALLY = "EXPUNGE_MANUALLY";
public static final String EXPUNGE_ON_POLL = "EXPUNGE_ON_POLL";
@@ -136,38 +135,31 @@ public class Account implements BaseAccount
private NotificationSetting mNotificationSetting = new NotificationSetting();
- public enum FolderMode
- {
+ public enum FolderMode {
NONE, ALL, FIRST_CLASS, FIRST_AND_SECOND_CLASS, NOT_SECOND_CLASS
}
- public enum ScrollButtons
- {
+ public enum ScrollButtons {
NEVER, ALWAYS, KEYBOARD_AVAILABLE
}
- public enum ShowPictures
- {
+ public enum ShowPictures {
NEVER, ALWAYS, ONLY_FROM_CONTACTS
}
- public enum Searchable
- {
+ public enum Searchable {
ALL, DISPLAYABLE, NONE
}
- public enum QuoteStyle
- {
+ public enum QuoteStyle {
PREFIX, HEADER
}
- public enum MessageFormat
- {
+ public enum MessageFormat {
TEXT, HTML
}
- protected Account(Context context)
- {
+ protected Account(Context context) {
mUuid = UUID.randomUUID().toString();
mLocalStorageProviderId = StorageManager.getInstance(K9.app).getDefaultProviderId();
mAutomaticCheckIntervalMinutes = -1;
@@ -224,8 +216,7 @@ public class Account implements BaseAccount
mNotificationSetting.setLedColor(mChipColor);
}
- protected Account(Preferences preferences, String uuid)
- {
+ protected Account(Preferences preferences, String uuid) {
this.mUuid = uuid;
loadAccount(preferences);
}
@@ -233,8 +224,7 @@ public class Account implements BaseAccount
/**
* Load stored settings for this account.
*/
- private synchronized void loadAccount(Preferences preferences)
- {
+ private synchronized void loadAccount(Preferences preferences) {
SharedPreferences prefs = preferences.getPreferences();
@@ -248,12 +238,11 @@ public class Account implements BaseAccount
mSaveAllHeaders = prefs.getBoolean(mUuid + ".saveAllHeaders", true);
mPushPollOnConnect = prefs.getBoolean(mUuid + ".pushPollOnConnect", true);
mDisplayCount = prefs.getInt(mUuid + ".displayCount", K9.DEFAULT_VISIBLE_LIMIT);
- if (mDisplayCount < 0)
- {
+ if (mDisplayCount < 0) {
mDisplayCount = K9.DEFAULT_VISIBLE_LIMIT;
}
mLastAutomaticCheckTime = prefs.getLong(mUuid + ".lastAutomaticCheckTime", 0);
- mLatestOldMessageSeenTime = prefs.getLong(mUuid +".latestOldMessageSeenTime",0);
+ mLatestOldMessageSeenTime = prefs.getLong(mUuid + ".latestOldMessageSeenTime", 0);
mNotifyNewMail = prefs.getBoolean(mUuid + ".notifyNewMail", false);
mNotifySelfNewMail = prefs.getBoolean(mUuid + ".notifySelfNewMail", true);
mNotifySync = prefs.getBoolean(mUuid + ".notifyMailCheck", false);
@@ -277,8 +266,7 @@ public class Account implements BaseAccount
mQuoteStyle = QuoteStyle.valueOf(prefs.getString(mUuid + ".quoteStyle", DEFAULT_QUOTE_STYLE.name()));
mQuotePrefix = prefs.getString(mUuid + ".quotePrefix", DEFAULT_QUOTE_PREFIX);
mReplyAfterQuote = prefs.getBoolean(mUuid + ".replyAfterQuote", DEFAULT_REPLY_AFTER_QUOTE);
- for (String type : networkTypes)
- {
+ for (String type : networkTypes) {
Boolean useCompression = prefs.getBoolean(mUuid + ".useCompression." + type,
true);
compressionMap.put(type, useCompression);
@@ -289,41 +277,32 @@ public class Account implements BaseAccount
mAccountNumber = prefs.getInt(mUuid + ".accountNumber", 0);
- Random random = new Random((long)mAccountNumber+4);
+ Random random = new Random((long)mAccountNumber + 4);
- mChipColor = prefs.getInt(mUuid+".chipColor",
+ mChipColor = prefs.getInt(mUuid + ".chipColor",
(random.nextInt(0x70)) +
(random.nextInt(0x70) * 0xff) +
(random.nextInt(0x70) * 0xffff) +
0xff000000);
- try
- {
+ try {
mScrollMessageViewButtons = ScrollButtons.valueOf(prefs.getString(mUuid + ".hideButtonsEnum",
ScrollButtons.NEVER.name()));
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
mScrollMessageViewButtons = ScrollButtons.NEVER;
}
- try
- {
+ try {
mScrollMessageViewMoveButtons = ScrollButtons.valueOf(prefs.getString(mUuid + ".hideMoveButtonsEnum",
ScrollButtons.NEVER.name()));
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
mScrollMessageViewMoveButtons = ScrollButtons.NEVER;
}
- try
- {
+ try {
mShowPictures = ShowPictures.valueOf(prefs.getString(mUuid + ".showPicturesEnum",
ShowPictures.NEVER.name()));
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
mShowPictures = ShowPictures.NEVER;
}
@@ -336,55 +315,40 @@ public class Account implements BaseAccount
mNotificationSetting.setRingtone(prefs.getString(mUuid + ".ringtone",
"content://settings/system/notification_sound"));
mNotificationSetting.setLed(prefs.getBoolean(mUuid + ".led", true));
- mNotificationSetting.setLedColor(prefs.getInt(mUuid+".ledColor", mChipColor));
+ mNotificationSetting.setLedColor(prefs.getInt(mUuid + ".ledColor", mChipColor));
- try
- {
+ try {
mFolderDisplayMode = FolderMode.valueOf(prefs.getString(mUuid + ".folderDisplayMode",
FolderMode.NOT_SECOND_CLASS.name()));
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
mFolderDisplayMode = FolderMode.NOT_SECOND_CLASS;
}
- try
- {
+ try {
mFolderSyncMode = FolderMode.valueOf(prefs.getString(mUuid + ".folderSyncMode",
FolderMode.FIRST_CLASS.name()));
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
mFolderSyncMode = FolderMode.FIRST_CLASS;
}
- try
- {
+ try {
mFolderPushMode = FolderMode.valueOf(prefs.getString(mUuid + ".folderPushMode",
FolderMode.FIRST_CLASS.name()));
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
mFolderPushMode = FolderMode.FIRST_CLASS;
}
- try
- {
+ try {
mFolderTargetMode = FolderMode.valueOf(prefs.getString(mUuid + ".folderTargetMode",
FolderMode.NOT_SECOND_CLASS.name()));
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
mFolderTargetMode = FolderMode.NOT_SECOND_CLASS;
}
- try
- {
+ try {
searchableFolders = Searchable.valueOf(prefs.getString(mUuid + ".searchableFolders",
Searchable.ALL.name()));
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
searchableFolders = Searchable.ALL;
}
@@ -396,16 +360,12 @@ public class Account implements BaseAccount
}
- protected synchronized void delete(Preferences preferences)
- {
+ protected synchronized void delete(Preferences preferences) {
String[] uuids = preferences.getPreferences().getString("accountUuids", "").split(",");
StringBuffer sb = new StringBuffer();
- for (int i = 0, length = uuids.length; i < length; i++)
- {
- if (!uuids[i].equals(mUuid))
- {
- if (sb.length() > 0)
- {
+ for (int i = 0, length = uuids.length; i < length; i++) {
+ if (!uuids[i].equals(mUuid)) {
+ if (sb.length() > 0) {
sb.append(',');
}
sb.append(uuids[i]);
@@ -471,20 +431,17 @@ public class Account implements BaseAccount
editor.remove(mUuid + ".cryptoAutoSignature");
editor.remove(mUuid + ".enableMoveButtons");
editor.remove(mUuid + ".hideMoveButtonsEnum");
- for (String type : networkTypes)
- {
+ for (String type : networkTypes) {
editor.remove(mUuid + ".useCompression." + type);
}
deleteIdentities(preferences.getPreferences(), editor);
editor.commit();
}
- public synchronized void save(Preferences preferences)
- {
+ public synchronized void save(Preferences preferences) {
SharedPreferences.Editor editor = preferences.getPreferences().edit();
- if (!preferences.getPreferences().getString("accountUuids", "").contains(mUuid))
- {
+ if (!preferences.getPreferences().getString("accountUuids", "").contains(mUuid)) {
/*
* When the account is first created we assign it a unique account number. The
* account number will be unique to that account for the lifetime of the account.
@@ -498,15 +455,12 @@ public class Account implements BaseAccount
*/
Account[] accounts = preferences.getAccounts();
int[] accountNumbers = new int[accounts.length];
- for (int i = 0; i < accounts.length; i++)
- {
+ for (int i = 0; i < accounts.length; i++) {
accountNumbers[i] = accounts[i].getAccountNumber();
}
Arrays.sort(accountNumbers);
- for (int accountNumber : accountNumbers)
- {
- if (accountNumber > mAccountNumber + 1)
- {
+ for (int accountNumber : accountNumbers) {
+ if (accountNumber > mAccountNumber + 1) {
break;
}
mAccountNumber = accountNumber;
@@ -576,11 +530,9 @@ public class Account implements BaseAccount
editor.putBoolean(mUuid + ".led", mNotificationSetting.isLed());
editor.putInt(mUuid + ".ledColor", mNotificationSetting.getLedColor());
- for (String type : networkTypes)
- {
+ for (String type : networkTypes) {
Boolean useCompression = compressionMap.get(type);
- if (useCompression != null)
- {
+ if (useCompression != null) {
editor.putBoolean(mUuid + ".useCompression." + type, useCompression);
}
}
@@ -590,14 +542,10 @@ public class Account implements BaseAccount
}
- public void resetVisibleLimits()
- {
- try
- {
+ public void resetVisibleLimits() {
+ try {
getLocalStore().resetVisibleLimits(getDisplayCount());
- }
- catch (MessagingException e)
- {
+ } catch (MessagingException e) {
Log.e(K9.LOG_TAG, "Unable to reset visible limits", e);
}
@@ -609,17 +557,14 @@ public class Account implements BaseAccount
* @throws MessagingException
* @see {@link #isAvailable(Context)}
*/
- public AccountStats getStats(Context context) throws MessagingException
- {
- if (!isAvailable(context))
- {
+ public AccountStats getStats(Context context) throws MessagingException {
+ if (!isAvailable(context)) {
return null;
}
long startTime = System.currentTimeMillis();
AccountStats stats = new AccountStats();
LocalStore localStore = getLocalStore();
- if (K9.measureAccounts())
- {
+ if (K9.measureAccounts()) {
stats.size = localStore.getSize();
}
localStore.getMessageCounts(stats);
@@ -630,149 +575,117 @@ public class Account implements BaseAccount
}
- public synchronized void setChipColor(int color)
- {
+ public synchronized void setChipColor(int color) {
mChipColor = color;
}
- public synchronized int getChipColor()
- {
+ public synchronized int getChipColor() {
return mChipColor;
}
- public ColorChip generateColorChip()
- {
- return new ColorChip( mChipColor);
+ public ColorChip generateColorChip() {
+ return new ColorChip(mChipColor);
}
- public String getUuid()
- {
+ public String getUuid() {
return mUuid;
}
- public Uri getContentUri()
- {
+ public Uri getContentUri() {
return Uri.parse("content://accounts/" + getUuid());
}
- public synchronized String getStoreUri()
- {
+ public synchronized String getStoreUri() {
return mStoreUri;
}
- public synchronized void setStoreUri(String storeUri)
- {
+ public synchronized void setStoreUri(String storeUri) {
this.mStoreUri = storeUri;
}
- public synchronized String getTransportUri()
- {
+ public synchronized String getTransportUri() {
return mTransportUri;
}
- public synchronized void setTransportUri(String transportUri)
- {
+ public synchronized void setTransportUri(String transportUri) {
this.mTransportUri = transportUri;
}
- public synchronized String getDescription()
- {
+ public synchronized String getDescription() {
return mDescription;
}
- public synchronized void setDescription(String description)
- {
+ public synchronized void setDescription(String description) {
this.mDescription = description;
}
- public synchronized String getName()
- {
+ public synchronized String getName() {
return identities.get(0).getName();
}
- public synchronized void setName(String name)
- {
+ public synchronized void setName(String name) {
identities.get(0).setName(name);
}
- public synchronized boolean getSignatureUse()
- {
+ public synchronized boolean getSignatureUse() {
return identities.get(0).getSignatureUse();
}
- public synchronized void setSignatureUse(boolean signatureUse)
- {
+ public synchronized void setSignatureUse(boolean signatureUse) {
identities.get(0).setSignatureUse(signatureUse);
}
- public synchronized String getSignature()
- {
+ public synchronized String getSignature() {
return identities.get(0).getSignature();
}
- public synchronized void setSignature(String signature)
- {
+ public synchronized void setSignature(String signature) {
identities.get(0).setSignature(signature);
}
- public synchronized String getEmail()
- {
+ public synchronized String getEmail() {
return identities.get(0).getEmail();
}
- public synchronized void setEmail(String email)
- {
+ public synchronized void setEmail(String email) {
identities.get(0).setEmail(email);
}
- public synchronized String getAlwaysBcc()
- {
+ public synchronized String getAlwaysBcc() {
return mAlwaysBcc;
}
- public synchronized void setAlwaysBcc(String alwaysBcc)
- {
+ public synchronized void setAlwaysBcc(String alwaysBcc) {
this.mAlwaysBcc = alwaysBcc;
}
/* Have we sent a new mail notification on this account */
- public boolean isRingNotified()
- {
+ public boolean isRingNotified() {
return mRingNotified;
}
- public void setRingNotified(boolean ringNotified)
- {
+ public void setRingNotified(boolean ringNotified) {
mRingNotified = ringNotified;
}
- public String getLocalStorageProviderId()
- {
+ public String getLocalStorageProviderId() {
return mLocalStorageProviderId;
}
- public void setLocalStorageProviderId(String id)
- {
+ public void setLocalStorageProviderId(String id) {
- if (!mLocalStorageProviderId.equals(id))
- {
+ if (!mLocalStorageProviderId.equals(id)) {
boolean successful = false;
- try
- {
+ try {
switchLocalStorage(id);
successful = true;
- }
- catch (MessagingException e)
- {
- }
- finally
- {
+ } catch (MessagingException e) {
+ } finally {
// if migration to/from SD-card failed once, it will fail again.
- if (!successful)
- {
+ if (!successful) {
return;
}
}
@@ -790,394 +703,318 @@ public class Account implements BaseAccount
/**
* Returns -1 for never.
*/
- public synchronized int getAutomaticCheckIntervalMinutes()
- {
+ public synchronized int getAutomaticCheckIntervalMinutes() {
return mAutomaticCheckIntervalMinutes;
}
/**
* @param automaticCheckIntervalMinutes or -1 for never.
*/
- public synchronized boolean setAutomaticCheckIntervalMinutes(int automaticCheckIntervalMinutes)
- {
+ public synchronized boolean setAutomaticCheckIntervalMinutes(int automaticCheckIntervalMinutes) {
int oldInterval = this.mAutomaticCheckIntervalMinutes;
this.mAutomaticCheckIntervalMinutes = automaticCheckIntervalMinutes;
return (oldInterval != automaticCheckIntervalMinutes);
}
- public synchronized int getDisplayCount()
- {
+ public synchronized int getDisplayCount() {
return mDisplayCount;
}
- public synchronized void setDisplayCount(int displayCount)
- {
- if (displayCount != -1)
- {
+ public synchronized void setDisplayCount(int displayCount) {
+ if (displayCount != -1) {
this.mDisplayCount = displayCount;
- }
- else
- {
+ } else {
this.mDisplayCount = K9.DEFAULT_VISIBLE_LIMIT;
}
resetVisibleLimits();
}
- public synchronized long getLastAutomaticCheckTime()
- {
+ public synchronized long getLastAutomaticCheckTime() {
return mLastAutomaticCheckTime;
}
- public synchronized void setLastAutomaticCheckTime(long lastAutomaticCheckTime)
- {
+ public synchronized void setLastAutomaticCheckTime(long lastAutomaticCheckTime) {
this.mLastAutomaticCheckTime = lastAutomaticCheckTime;
}
- public synchronized long getLatestOldMessageSeenTime()
- {
+ public synchronized long getLatestOldMessageSeenTime() {
return mLatestOldMessageSeenTime;
}
- public synchronized void setLatestOldMessageSeenTime(long latestOldMessageSeenTime)
- {
+ public synchronized void setLatestOldMessageSeenTime(long latestOldMessageSeenTime) {
this.mLatestOldMessageSeenTime = latestOldMessageSeenTime;
}
- public synchronized boolean isNotifyNewMail()
- {
+ public synchronized boolean isNotifyNewMail() {
return mNotifyNewMail;
}
- public synchronized void setNotifyNewMail(boolean notifyNewMail)
- {
+ public synchronized void setNotifyNewMail(boolean notifyNewMail) {
this.mNotifyNewMail = notifyNewMail;
}
- public synchronized int getDeletePolicy()
- {
+ public synchronized int getDeletePolicy() {
return mDeletePolicy;
}
- public synchronized void setDeletePolicy(int deletePolicy)
- {
+ public synchronized void setDeletePolicy(int deletePolicy) {
this.mDeletePolicy = deletePolicy;
}
- public boolean isSpecialFolder(String folderName)
- {
- if ( folderName != null && (folderName.equalsIgnoreCase(K9.INBOX) ||
- folderName.equals(getTrashFolderName()) ||
- folderName.equals(getDraftsFolderName()) ||
- folderName.equals(getArchiveFolderName()) ||
- folderName.equals(getSpamFolderName()) ||
- folderName.equals(getOutboxFolderName()) ||
- folderName.equals(getSentFolderName()) ||
- folderName.equals(getErrorFolderName())))
- {
+ public boolean isSpecialFolder(String folderName) {
+ if (folderName != null && (folderName.equalsIgnoreCase(K9.INBOX) ||
+ folderName.equals(getTrashFolderName()) ||
+ folderName.equals(getDraftsFolderName()) ||
+ folderName.equals(getArchiveFolderName()) ||
+ folderName.equals(getSpamFolderName()) ||
+ folderName.equals(getOutboxFolderName()) ||
+ folderName.equals(getSentFolderName()) ||
+ folderName.equals(getErrorFolderName()))) {
return true;
- }
- else
- {
+ } else {
return false;
}
}
- public synchronized String getDraftsFolderName()
- {
+ public synchronized String getDraftsFolderName() {
return mDraftsFolderName;
}
- public synchronized void setDraftsFolderName(String draftsFolderName)
- {
+ public synchronized void setDraftsFolderName(String draftsFolderName) {
mDraftsFolderName = draftsFolderName;
}
- public synchronized String getSentFolderName()
- {
+ public synchronized String getSentFolderName() {
return mSentFolderName;
}
- public synchronized String getErrorFolderName()
- {
+ public synchronized String getErrorFolderName() {
return K9.ERROR_FOLDER_NAME;
}
- public synchronized void setSentFolderName(String sentFolderName)
- {
+ public synchronized void setSentFolderName(String sentFolderName) {
mSentFolderName = sentFolderName;
}
- public synchronized String getTrashFolderName()
- {
+ public synchronized String getTrashFolderName() {
return mTrashFolderName;
}
- public synchronized void setTrashFolderName(String trashFolderName)
- {
+ public synchronized void setTrashFolderName(String trashFolderName) {
mTrashFolderName = trashFolderName;
}
- public synchronized String getArchiveFolderName()
- {
+ public synchronized String getArchiveFolderName() {
return mArchiveFolderName;
}
- public synchronized void setArchiveFolderName(String archiveFolderName)
- {
+ public synchronized void setArchiveFolderName(String archiveFolderName) {
mArchiveFolderName = archiveFolderName;
}
- public synchronized String getSpamFolderName()
- {
+ public synchronized String getSpamFolderName() {
return mSpamFolderName;
}
- public synchronized void setSpamFolderName(String spamFolderName)
- {
+ public synchronized void setSpamFolderName(String spamFolderName) {
mSpamFolderName = spamFolderName;
}
- public synchronized String getOutboxFolderName()
- {
+ public synchronized String getOutboxFolderName() {
return mOutboxFolderName;
}
- public synchronized void setOutboxFolderName(String outboxFolderName)
- {
+ public synchronized void setOutboxFolderName(String outboxFolderName) {
mOutboxFolderName = outboxFolderName;
}
- public synchronized String getAutoExpandFolderName()
- {
+ public synchronized String getAutoExpandFolderName() {
return mAutoExpandFolderName;
}
- public synchronized void setAutoExpandFolderName(String autoExpandFolderName)
- {
+ public synchronized void setAutoExpandFolderName(String autoExpandFolderName) {
mAutoExpandFolderName = autoExpandFolderName;
}
- public synchronized int getAccountNumber()
- {
+ public synchronized int getAccountNumber() {
return mAccountNumber;
}
- public synchronized FolderMode getFolderDisplayMode()
- {
+ public synchronized FolderMode getFolderDisplayMode() {
return mFolderDisplayMode;
}
- public synchronized boolean setFolderDisplayMode(FolderMode displayMode)
- {
+ public synchronized boolean setFolderDisplayMode(FolderMode displayMode) {
FolderMode oldDisplayMode = mFolderDisplayMode;
mFolderDisplayMode = displayMode;
return oldDisplayMode != displayMode;
}
- public synchronized FolderMode getFolderSyncMode()
- {
+ public synchronized FolderMode getFolderSyncMode() {
return mFolderSyncMode;
}
- public synchronized boolean setFolderSyncMode(FolderMode syncMode)
- {
+ public synchronized boolean setFolderSyncMode(FolderMode syncMode) {
FolderMode oldSyncMode = mFolderSyncMode;
mFolderSyncMode = syncMode;
- if (syncMode == FolderMode.NONE && oldSyncMode != FolderMode.NONE)
- {
+ if (syncMode == FolderMode.NONE && oldSyncMode != FolderMode.NONE) {
return true;
}
- if (syncMode != FolderMode.NONE && oldSyncMode == FolderMode.NONE)
- {
+ if (syncMode != FolderMode.NONE && oldSyncMode == FolderMode.NONE) {
return true;
}
return false;
}
- public synchronized FolderMode getFolderPushMode()
- {
+ public synchronized FolderMode getFolderPushMode() {
return mFolderPushMode;
}
- public synchronized boolean setFolderPushMode(FolderMode pushMode)
- {
+ public synchronized boolean setFolderPushMode(FolderMode pushMode) {
FolderMode oldPushMode = mFolderPushMode;
mFolderPushMode = pushMode;
return pushMode != oldPushMode;
}
- public synchronized boolean isShowOngoing()
- {
+ public synchronized boolean isShowOngoing() {
return mNotifySync;
}
- public synchronized void setShowOngoing(boolean showOngoing)
- {
+ public synchronized void setShowOngoing(boolean showOngoing) {
this.mNotifySync = showOngoing;
}
- public synchronized ScrollButtons getScrollMessageViewButtons()
- {
+ public synchronized ScrollButtons getScrollMessageViewButtons() {
return mScrollMessageViewButtons;
}
- public synchronized void setScrollMessageViewButtons(ScrollButtons scrollMessageViewButtons)
- {
+ public synchronized void setScrollMessageViewButtons(ScrollButtons scrollMessageViewButtons) {
mScrollMessageViewButtons = scrollMessageViewButtons;
}
- public synchronized ScrollButtons getScrollMessageViewMoveButtons()
- {
+ public synchronized ScrollButtons getScrollMessageViewMoveButtons() {
return mScrollMessageViewMoveButtons;
}
- public synchronized void setScrollMessageViewMoveButtons(ScrollButtons scrollMessageViewButtons)
- {
+ public synchronized void setScrollMessageViewMoveButtons(ScrollButtons scrollMessageViewButtons) {
mScrollMessageViewMoveButtons = scrollMessageViewButtons;
}
- public synchronized ShowPictures getShowPictures()
- {
+ public synchronized ShowPictures getShowPictures() {
return mShowPictures;
}
- public synchronized void setShowPictures(ShowPictures showPictures)
- {
+ public synchronized void setShowPictures(ShowPictures showPictures) {
mShowPictures = showPictures;
}
- public synchronized FolderMode getFolderTargetMode()
- {
+ public synchronized FolderMode getFolderTargetMode() {
return mFolderTargetMode;
}
- public synchronized void setFolderTargetMode(FolderMode folderTargetMode)
- {
+ public synchronized void setFolderTargetMode(FolderMode folderTargetMode) {
mFolderTargetMode = folderTargetMode;
}
- public synchronized boolean isSignatureBeforeQuotedText()
- {
+ public synchronized boolean isSignatureBeforeQuotedText() {
return mIsSignatureBeforeQuotedText;
}
- public synchronized void setSignatureBeforeQuotedText(boolean mIsSignatureBeforeQuotedText)
- {
+ public synchronized void setSignatureBeforeQuotedText(boolean mIsSignatureBeforeQuotedText) {
this.mIsSignatureBeforeQuotedText = mIsSignatureBeforeQuotedText;
}
- public synchronized boolean isNotifySelfNewMail()
- {
+ public synchronized boolean isNotifySelfNewMail() {
return mNotifySelfNewMail;
}
- public synchronized void setNotifySelfNewMail(boolean notifySelfNewMail)
- {
+ public synchronized void setNotifySelfNewMail(boolean notifySelfNewMail) {
mNotifySelfNewMail = notifySelfNewMail;
}
- public synchronized String getExpungePolicy()
- {
+ public synchronized String getExpungePolicy() {
return mExpungePolicy;
}
- public synchronized void setExpungePolicy(String expungePolicy)
- {
+ public synchronized void setExpungePolicy(String expungePolicy) {
mExpungePolicy = expungePolicy;
}
- public synchronized int getMaxPushFolders()
- {
+ public synchronized int getMaxPushFolders() {
return mMaxPushFolders;
}
- public synchronized boolean setMaxPushFolders(int maxPushFolders)
- {
+ public synchronized boolean setMaxPushFolders(int maxPushFolders) {
int oldMaxPushFolders = mMaxPushFolders;
mMaxPushFolders = maxPushFolders;
return oldMaxPushFolders != maxPushFolders;
}
- public LocalStore getLocalStore() throws MessagingException
- {
+ public LocalStore getLocalStore() throws MessagingException {
return Store.getLocalInstance(this, K9.app);
}
- public Store getRemoteStore() throws MessagingException
- {
+ public Store getRemoteStore() throws MessagingException {
return Store.getRemoteInstance(this);
}
@Override
- public synchronized String toString()
- {
+ public synchronized String toString() {
return mDescription;
}
- public synchronized void setCompression(String networkType, boolean useCompression)
- {
+ public synchronized void setCompression(String networkType, boolean useCompression) {
compressionMap.put(networkType, useCompression);
}
- public synchronized boolean useCompression(String networkType)
- {
+ public synchronized boolean useCompression(String networkType) {
Boolean useCompression = compressionMap.get(networkType);
- if (useCompression == null)
- {
+ if (useCompression == null) {
return true;
- }
- else
- {
+ } else {
return useCompression;
}
}
- public boolean useCompression(int type)
- {
+ public boolean useCompression(int type) {
String networkType = TYPE_OTHER;
- switch (type)
- {
- case ConnectivityManager.TYPE_MOBILE:
- networkType = TYPE_MOBILE;
- break;
- case ConnectivityManager.TYPE_WIFI:
- networkType = TYPE_WIFI;
- break;
+ switch (type) {
+ case ConnectivityManager.TYPE_MOBILE:
+ networkType = TYPE_MOBILE;
+ break;
+ case ConnectivityManager.TYPE_WIFI:
+ networkType = TYPE_WIFI;
+ break;
}
return useCompression(networkType);
}
@Override
- public boolean equals(Object o)
- {
- if (o instanceof Account)
- {
+ public boolean equals(Object o) {
+ if (o instanceof Account) {
return ((Account)o).mUuid.equals(mUuid);
}
return super.equals(o);
}
@Override
- public int hashCode()
- {
+ public int hashCode() {
return mUuid.hashCode();
}
- private synchronized List loadIdentities(SharedPreferences prefs)
- {
+ private synchronized List loadIdentities(SharedPreferences prefs) {
List newIdentities = new ArrayList();
int ident = 0;
boolean gotOne = false;
- do
- {
+ do {
gotOne = false;
String name = prefs.getString(mUuid + ".name." + ident, null);
String email = prefs.getString(mUuid + ".email." + ident, null);
@@ -1185,8 +1022,7 @@ public class Account implements BaseAccount
String signature = prefs.getString(mUuid + ".signature." + ident, null);
String description = prefs.getString(mUuid + ".description." + ident, null);
final String replyTo = prefs.getString(mUuid + ".replyTo." + ident, null);
- if (email != null)
- {
+ if (email != null) {
Identity identity = new Identity();
identity.setName(name);
identity.setEmail(email);
@@ -1198,11 +1034,9 @@ public class Account implements BaseAccount
gotOne = true;
}
ident++;
- }
- while (gotOne);
+ } while (gotOne);
- if (newIdentities.size() == 0)
- {
+ if (newIdentities.size() == 0) {
String name = prefs.getString(mUuid + ".name", null);
String email = prefs.getString(mUuid + ".email", null);
boolean signatureUse = prefs.getBoolean(mUuid + ".signatureUse", true);
@@ -1219,16 +1053,13 @@ public class Account implements BaseAccount
return newIdentities;
}
- private synchronized void deleteIdentities(SharedPreferences prefs, SharedPreferences.Editor editor)
- {
+ private synchronized void deleteIdentities(SharedPreferences prefs, SharedPreferences.Editor editor) {
int ident = 0;
boolean gotOne = false;
- do
- {
+ do {
gotOne = false;
String email = prefs.getString(mUuid + ".email." + ident, null);
- if (email != null)
- {
+ if (email != null) {
editor.remove(mUuid + ".name." + ident);
editor.remove(mUuid + ".email." + ident);
editor.remove(mUuid + ".signatureUse." + ident);
@@ -1238,17 +1069,14 @@ public class Account implements BaseAccount
gotOne = true;
}
ident++;
- }
- while (gotOne);
+ } while (gotOne);
}
- private synchronized void saveIdentities(SharedPreferences prefs, SharedPreferences.Editor editor)
- {
+ private synchronized void saveIdentities(SharedPreferences prefs, SharedPreferences.Editor editor) {
deleteIdentities(prefs, editor);
int ident = 0;
- for (Identity identity : identities)
- {
+ for (Identity identity : identities) {
editor.putString(mUuid + ".name." + ident, identity.getName());
editor.putString(mUuid + ".email." + ident, identity.getEmail());
editor.putBoolean(mUuid + ".signatureUse." + ident, identity.getSignatureUse());
@@ -1259,35 +1087,27 @@ public class Account implements BaseAccount
}
}
- public synchronized List getIdentities()
- {
+ public synchronized List getIdentities() {
return identities;
}
- public synchronized void setIdentities(List newIdentities)
- {
+ public synchronized void setIdentities(List newIdentities) {
identities = new ArrayList(newIdentities);
}
- public synchronized Identity getIdentity(int i)
- {
- if (i < identities.size())
- {
+ public synchronized Identity getIdentity(int i) {
+ if (i < identities.size()) {
return identities.get(i);
}
return null;
}
- public boolean isAnIdentity(Address[] addrs)
- {
- if (addrs == null)
- {
+ public boolean isAnIdentity(Address[] addrs) {
+ if (addrs == null) {
return false;
}
- for (Address addr : addrs)
- {
- if (findIdentity(addr) != null)
- {
+ for (Address addr : addrs) {
+ if (findIdentity(addr) != null) {
return true;
}
}
@@ -1295,61 +1115,49 @@ public class Account implements BaseAccount
return false;
}
- public boolean isAnIdentity(Address addr)
- {
+ public boolean isAnIdentity(Address addr) {
return findIdentity(addr) != null;
}
- public synchronized Identity findIdentity(Address addr)
- {
- for (Identity identity : identities)
- {
+ public synchronized Identity findIdentity(Address addr) {
+ for (Identity identity : identities) {
String email = identity.getEmail();
- if (email != null && email.equalsIgnoreCase(addr.getAddress()))
- {
+ if (email != null && email.equalsIgnoreCase(addr.getAddress())) {
return identity;
}
}
return null;
}
- public synchronized Searchable getSearchableFolders()
- {
+ public synchronized Searchable getSearchableFolders() {
return searchableFolders;
}
- public synchronized void setSearchableFolders(Searchable searchableFolders)
- {
+ public synchronized void setSearchableFolders(Searchable searchableFolders) {
this.searchableFolders = searchableFolders;
}
- public synchronized int getIdleRefreshMinutes()
- {
+ public synchronized int getIdleRefreshMinutes() {
return mIdleRefreshMinutes;
}
- public synchronized void setIdleRefreshMinutes(int idleRefreshMinutes)
- {
+ public synchronized void setIdleRefreshMinutes(int idleRefreshMinutes) {
mIdleRefreshMinutes = idleRefreshMinutes;
}
- public synchronized boolean isPushPollOnConnect()
- {
+ public synchronized boolean isPushPollOnConnect() {
return mPushPollOnConnect;
}
- public synchronized void setPushPollOnConnect(boolean pushPollOnConnect)
- {
+ public synchronized void setPushPollOnConnect(boolean pushPollOnConnect) {
mPushPollOnConnect = pushPollOnConnect;
}
- public synchronized boolean saveAllHeaders()
- {
+ public synchronized boolean saveAllHeaders() {
return mSaveAllHeaders;
}
- public synchronized void setSaveAllHeaders(boolean saveAllHeaders)
- {
+ public synchronized void setSaveAllHeaders(boolean saveAllHeaders) {
mSaveAllHeaders = saveAllHeaders;
}
@@ -1364,207 +1172,167 @@ public class Account implements BaseAccount
* Never null
.
* @throws MessagingException
*/
- public void switchLocalStorage(final String newStorageProviderId) throws MessagingException
- {
- if (!mLocalStorageProviderId.equals(newStorageProviderId))
- {
+ public void switchLocalStorage(final String newStorageProviderId) throws MessagingException {
+ if (!mLocalStorageProviderId.equals(newStorageProviderId)) {
getLocalStore().switchLocalStorage(newStorageProviderId);
}
}
- public synchronized boolean goToUnreadMessageSearch()
- {
+ public synchronized boolean goToUnreadMessageSearch() {
return goToUnreadMessageSearch;
}
- public synchronized void setGoToUnreadMessageSearch(boolean goToUnreadMessageSearch)
- {
+ public synchronized void setGoToUnreadMessageSearch(boolean goToUnreadMessageSearch) {
this.goToUnreadMessageSearch = goToUnreadMessageSearch;
}
- public boolean isNotificationShowsUnreadCount()
- {
+ public boolean isNotificationShowsUnreadCount() {
return mNotificationShowsUnreadCount;
}
- public void setNotificationShowsUnreadCount(boolean notificationShowsUnreadCount)
- {
+ public void setNotificationShowsUnreadCount(boolean notificationShowsUnreadCount) {
this.mNotificationShowsUnreadCount = notificationShowsUnreadCount;
}
- public synchronized boolean subscribedFoldersOnly()
- {
+ public synchronized boolean subscribedFoldersOnly() {
return subscribedFoldersOnly;
}
- public synchronized void setSubscribedFoldersOnly(boolean subscribedFoldersOnly)
- {
+ public synchronized void setSubscribedFoldersOnly(boolean subscribedFoldersOnly) {
this.subscribedFoldersOnly = subscribedFoldersOnly;
}
- public synchronized int getMaximumPolledMessageAge()
- {
+ public synchronized int getMaximumPolledMessageAge() {
return maximumPolledMessageAge;
}
- public synchronized void setMaximumPolledMessageAge(int maximumPolledMessageAge)
- {
+ public synchronized void setMaximumPolledMessageAge(int maximumPolledMessageAge) {
this.maximumPolledMessageAge = maximumPolledMessageAge;
}
- public synchronized int getMaximumAutoDownloadMessageSize()
- {
+ public synchronized int getMaximumAutoDownloadMessageSize() {
return maximumAutoDownloadMessageSize;
}
- public synchronized void setMaximumAutoDownloadMessageSize(int maximumAutoDownloadMessageSize)
- {
+ public synchronized void setMaximumAutoDownloadMessageSize(int maximumAutoDownloadMessageSize) {
this.maximumAutoDownloadMessageSize = maximumAutoDownloadMessageSize;
}
- public Date getEarliestPollDate()
- {
+ public Date getEarliestPollDate() {
int age = getMaximumPolledMessageAge();
- if (age >= 0)
- {
+ if (age >= 0) {
Calendar now = Calendar.getInstance();
now.set(Calendar.HOUR_OF_DAY, 0);
now.set(Calendar.MINUTE, 0);
now.set(Calendar.SECOND, 0);
now.set(Calendar.MILLISECOND, 0);
- if (age < 28)
- {
+ if (age < 28) {
now.add(Calendar.DATE, age * -1);
- }
- else switch (age)
- {
- case 28:
- now.add(Calendar.MONTH, -1);
- break;
- case 56:
- now.add(Calendar.MONTH, -2);
- break;
- case 84:
- now.add(Calendar.MONTH, -3);
- break;
- case 168:
- now.add(Calendar.MONTH, -6);
- break;
- case 365:
- now.add(Calendar.YEAR, -1);
- break;
+ } else switch (age) {
+ case 28:
+ now.add(Calendar.MONTH, -1);
+ break;
+ case 56:
+ now.add(Calendar.MONTH, -2);
+ break;
+ case 84:
+ now.add(Calendar.MONTH, -3);
+ break;
+ case 168:
+ now.add(Calendar.MONTH, -6);
+ break;
+ case 365:
+ now.add(Calendar.YEAR, -1);
+ break;
}
return now.getTime();
- }
- else
- {
+ } else {
return null;
}
}
- public MessageFormat getMessageFormat()
- {
+ public MessageFormat getMessageFormat() {
return mMessageFormat;
}
- public void setMessageFormat(MessageFormat messageFormat)
- {
+ public void setMessageFormat(MessageFormat messageFormat) {
this.mMessageFormat = messageFormat;
}
- public QuoteStyle getQuoteStyle()
- {
+ public QuoteStyle getQuoteStyle() {
return mQuoteStyle;
}
- public void setQuoteStyle(QuoteStyle quoteStyle)
- {
+ public void setQuoteStyle(QuoteStyle quoteStyle) {
this.mQuoteStyle = quoteStyle;
}
- public synchronized String getQuotePrefix()
- {
+ public synchronized String getQuotePrefix() {
return mQuotePrefix;
}
- public synchronized void setQuotePrefix(String quotePrefix)
- {
+ public synchronized void setQuotePrefix(String quotePrefix) {
mQuotePrefix = quotePrefix;
}
- public synchronized boolean isReplyAfterQuote()
- {
+ public synchronized boolean isReplyAfterQuote() {
return mReplyAfterQuote;
}
- public synchronized void setReplyAfterQuote(boolean replyAfterQuote)
- {
+ public synchronized void setReplyAfterQuote(boolean replyAfterQuote) {
mReplyAfterQuote = replyAfterQuote;
}
- public boolean getEnableMoveButtons()
- {
+ public boolean getEnableMoveButtons() {
return mEnableMoveButtons;
}
- public void setEnableMoveButtons(boolean enableMoveButtons)
- {
+ public void setEnableMoveButtons(boolean enableMoveButtons) {
mEnableMoveButtons = enableMoveButtons;
}
- public String getCryptoApp()
- {
+ public String getCryptoApp() {
return mCryptoApp;
}
- public void setCryptoApp(String cryptoApp)
- {
+ public void setCryptoApp(String cryptoApp) {
mCryptoApp = cryptoApp;
// invalidate the provider
mCryptoProvider = null;
}
- public boolean getCryptoAutoSignature()
- {
+ public boolean getCryptoAutoSignature() {
return mCryptoAutoSignature;
}
- public void setCryptoAutoSignature(boolean cryptoAutoSignature)
- {
+ public void setCryptoAutoSignature(boolean cryptoAutoSignature) {
mCryptoAutoSignature = cryptoAutoSignature;
}
- public synchronized boolean syncRemoteDeletions()
- {
+ public synchronized boolean syncRemoteDeletions() {
return mSyncRemoteDeletions;
}
- public synchronized void setSyncRemoteDeletions(boolean syncRemoteDeletions)
- {
+ public synchronized void setSyncRemoteDeletions(boolean syncRemoteDeletions) {
mSyncRemoteDeletions = syncRemoteDeletions;
}
- public synchronized String getLastSelectedFolderName()
- {
+ public synchronized String getLastSelectedFolderName() {
return lastSelectedFolderName;
}
- public synchronized void setLastSelectedFolderName(String folderName)
- {
+ public synchronized void setLastSelectedFolderName(String folderName) {
lastSelectedFolderName = folderName;
}
- public synchronized CryptoProvider getCryptoProvider()
- {
- if (mCryptoProvider == null)
- {
+ public synchronized CryptoProvider getCryptoProvider() {
+ if (mCryptoProvider == null) {
mCryptoProvider = CryptoProvider.createInstance(getCryptoApp());
}
return mCryptoProvider;
}
- public synchronized NotificationSetting getNotificationSetting()
- {
+ public synchronized NotificationSetting getNotificationSetting() {
return mNotificationSetting;
}
@@ -1572,11 +1340,9 @@ public class Account implements BaseAccount
* @return true
if our {@link StorageProvider} is ready. (e.g.
* card inserted)
*/
- public boolean isAvailable(Context context)
- {
+ public boolean isAvailable(Context context) {
String localStorageProviderId = getLocalStorageProviderId();
- if (localStorageProviderId == null)
- {
+ if (localStorageProviderId == null) {
return true; // defaults to internal memory
}
return StorageManager.getInstance(K9.app).isReady(localStorageProviderId);
diff --git a/src/com/fsck/k9/AccountStats.java b/src/com/fsck/k9/AccountStats.java
index c8b4167fc..d69685e66 100644
--- a/src/com/fsck/k9/AccountStats.java
+++ b/src/com/fsck/k9/AccountStats.java
@@ -5,8 +5,7 @@ package com.fsck.k9;
import java.io.Serializable;
-public class AccountStats implements Serializable
-{
+public class AccountStats implements Serializable {
private static final long serialVersionUID = -5706839923710842234L;
public long size = -1;
public int unreadMessageCount = 0;
diff --git a/src/com/fsck/k9/BaseAccount.java b/src/com/fsck/k9/BaseAccount.java
index 4d7eda82a..2d6b643eb 100644
--- a/src/com/fsck/k9/BaseAccount.java
+++ b/src/com/fsck/k9/BaseAccount.java
@@ -1,7 +1,6 @@
package com.fsck.k9;
-public interface BaseAccount
-{
+public interface BaseAccount {
public String getEmail();
public void setEmail(String email);
public String getDescription();
diff --git a/src/com/fsck/k9/EmailAddressAdapter.java b/src/com/fsck/k9/EmailAddressAdapter.java
index 390a1d15c..d9bb59940 100644
--- a/src/com/fsck/k9/EmailAddressAdapter.java
+++ b/src/com/fsck/k9/EmailAddressAdapter.java
@@ -24,14 +24,11 @@ import android.view.View;
import android.widget.ResourceCursorAdapter;
import android.widget.TextView;
-public class EmailAddressAdapter extends ResourceCursorAdapter
-{
+public class EmailAddressAdapter extends ResourceCursorAdapter {
private static EmailAddressAdapter sInstance;
- public static EmailAddressAdapter getInstance(Context context)
- {
- if (sInstance == null)
- {
+ public static EmailAddressAdapter getInstance(Context context) {
+ if (sInstance == null) {
sInstance = new EmailAddressAdapter(context);
}
@@ -41,15 +38,13 @@ public class EmailAddressAdapter extends ResourceCursorAdapter
private final Contacts mContacts;
- private EmailAddressAdapter(Context context)
- {
+ private EmailAddressAdapter(Context context) {
super(context, R.layout.recipient_dropdown_item, null);
mContacts = Contacts.getInstance(context);
}
@Override
- public final String convertToString(final Cursor cursor)
- {
+ public final String convertToString(final Cursor cursor) {
final String name = mContacts.getName(cursor);
final String address = mContacts.getEmail(cursor);
@@ -57,8 +52,7 @@ public class EmailAddressAdapter extends ResourceCursorAdapter
}
@Override
- public final void bindView(final View view, final Context context, final Cursor cursor)
- {
+ public final void bindView(final View view, final Context context, final Cursor cursor) {
final TextView text1 = (TextView) view.findViewById(R.id.text1);
final TextView text2 = (TextView) view.findViewById(R.id.text2);
text1.setText(mContacts.getName(cursor));
@@ -66,8 +60,7 @@ public class EmailAddressAdapter extends ResourceCursorAdapter
}
@Override
- public Cursor runQueryOnBackgroundThread(CharSequence constraint)
- {
+ public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
return mContacts.searchContacts(constraint);
}
}
diff --git a/src/com/fsck/k9/EmailAddressValidator.java b/src/com/fsck/k9/EmailAddressValidator.java
index 052615621..957a1384b 100644
--- a/src/com/fsck/k9/EmailAddressValidator.java
+++ b/src/com/fsck/k9/EmailAddressValidator.java
@@ -4,20 +4,16 @@ package com.fsck.k9;
import android.text.util.Rfc822Tokenizer;
import android.widget.AutoCompleteTextView.Validator;
-public class EmailAddressValidator implements Validator
-{
- public CharSequence fixText(CharSequence invalidText)
- {
+public class EmailAddressValidator implements Validator {
+ public CharSequence fixText(CharSequence invalidText) {
return "";
}
- public boolean isValid(CharSequence text)
- {
+ public boolean isValid(CharSequence text) {
return Rfc822Tokenizer.tokenize(text).length > 0;
}
- public boolean isValidAddressOnly(CharSequence text)
- {
+ public boolean isValidAddressOnly(CharSequence text) {
return com.fsck.k9.helper.Regex.EMAIL_ADDRESS_PATTERN.matcher(text).matches();
}
}
diff --git a/src/com/fsck/k9/EmailReceivedIntent.java b/src/com/fsck/k9/EmailReceivedIntent.java
index c834e67a6..24b209a92 100644
--- a/src/com/fsck/k9/EmailReceivedIntent.java
+++ b/src/com/fsck/k9/EmailReceivedIntent.java
@@ -1,7 +1,6 @@
package com.fsck.k9;
-public class EmailReceivedIntent
-{
+public class EmailReceivedIntent {
public static final String ACTION_EMAIL_RECEIVED = "com.fsck.k9.intent.action.EMAIL_RECEIVED";
public static final String EXTRA_ACCOUNT = "com.fsck.k9.intent.extra.ACCOUNT";
diff --git a/src/com/fsck/k9/FontSizes.java b/src/com/fsck/k9/FontSizes.java
index 77f9a0f9c..a45216b2e 100644
--- a/src/com/fsck/k9/FontSizes.java
+++ b/src/com/fsck/k9/FontSizes.java
@@ -7,8 +7,7 @@ import android.webkit.WebSettings.TextSize;
* Manage font size of the information displayed in the account list, folder
* list, message list and in the message view.
*/
-public class FontSizes
-{
+public class FontSizes {
/*
* Keys for the preference storage.
*/
@@ -126,8 +125,7 @@ public class FontSizes
/**
* Create a FontSizes
object with default values.
*/
- public FontSizes()
- {
+ public FontSizes() {
accountName = MEDIUM;
accountDescription = SMALL;
@@ -153,8 +151,7 @@ public class FontSizes
*
* @param editor Used to save the font size settings.
*/
- public void save(SharedPreferences.Editor editor)
- {
+ public void save(SharedPreferences.Editor editor) {
editor.putInt(ACCOUNT_NAME, accountName);
editor.putInt(ACCOUNT_DESCRIPTION, accountDescription);
@@ -181,8 +178,7 @@ public class FontSizes
*
* @param prefs Used to load the font size settings.
*/
- public void load(SharedPreferences prefs)
- {
+ public void load(SharedPreferences prefs) {
accountName = prefs.getInt(ACCOUNT_NAME, accountName);
accountDescription = prefs.getInt(ACCOUNT_DESCRIPTION, accountDescription);
@@ -204,198 +200,163 @@ public class FontSizes
setMessageViewContent(prefs.getInt(MESSAGE_VIEW_CONTENT, 3));
}
- public int getAccountName()
- {
+ public int getAccountName() {
return accountName;
}
- public void setAccountName(int accountName)
- {
+ public void setAccountName(int accountName) {
this.accountName = accountName;
}
- public int getAccountDescription()
- {
+ public int getAccountDescription() {
return accountDescription;
}
- public void setAccountDescription(int accountDescription)
- {
+ public void setAccountDescription(int accountDescription) {
this.accountDescription = accountDescription;
}
- public int getFolderName()
- {
+ public int getFolderName() {
return folderName;
}
- public void setFolderName(int folderName)
- {
+ public void setFolderName(int folderName) {
this.folderName = folderName;
}
- public int getFolderStatus()
- {
+ public int getFolderStatus() {
return folderStatus;
}
- public void setFolderStatus(int folderStatus)
- {
+ public void setFolderStatus(int folderStatus) {
this.folderStatus = folderStatus;
}
- public int getMessageListSubject()
- {
+ public int getMessageListSubject() {
return messageListSubject;
}
- public void setMessageListSubject(int messageListSubject)
- {
+ public void setMessageListSubject(int messageListSubject) {
this.messageListSubject = messageListSubject;
}
- public int getMessageListSender()
- {
+ public int getMessageListSender() {
return messageListSender;
}
- public void setMessageListSender(int messageListSender)
- {
+ public void setMessageListSender(int messageListSender) {
this.messageListSender = messageListSender;
}
- public int getMessageListDate()
- {
+ public int getMessageListDate() {
return messageListDate;
}
- public void setMessageListDate(int messageListDate)
- {
+ public void setMessageListDate(int messageListDate) {
this.messageListDate = messageListDate;
}
- public int getMessageListPreview()
- {
+ public int getMessageListPreview() {
return messageListPreview;
}
- public void setMessageListPreview(int messageListPreview)
- {
+ public void setMessageListPreview(int messageListPreview) {
this.messageListPreview = messageListPreview;
}
- public int getMessageViewSender()
- {
+ public int getMessageViewSender() {
return messageViewSender;
}
- public void setMessageViewSender(int messageViewSender)
- {
+ public void setMessageViewSender(int messageViewSender) {
this.messageViewSender = messageViewSender;
}
- public int getMessageViewTo()
- {
+ public int getMessageViewTo() {
return messageViewTo;
}
- public void setMessageViewTo(int messageViewTo)
- {
+ public void setMessageViewTo(int messageViewTo) {
this.messageViewTo = messageViewTo;
}
- public int getMessageViewCC()
- {
+ public int getMessageViewCC() {
return messageViewCC;
}
- public void setMessageViewCC(int messageViewCC)
- {
+ public void setMessageViewCC(int messageViewCC) {
this.messageViewCC = messageViewCC;
}
- public int getMessageViewAdditionalHeaders()
- {
+ public int getMessageViewAdditionalHeaders() {
return messageViewAdditionalHeaders;
}
- public void setMessageViewAdditionalHeaders(int messageViewAdditionalHeaders)
- {
+ public void setMessageViewAdditionalHeaders(int messageViewAdditionalHeaders) {
this.messageViewAdditionalHeaders = messageViewAdditionalHeaders;
}
- public int getMessageViewSubject()
- {
+ public int getMessageViewSubject() {
return messageViewSubject;
}
- public void setMessageViewSubject(int messageViewSubject)
- {
+ public void setMessageViewSubject(int messageViewSubject) {
this.messageViewSubject = messageViewSubject;
}
- public int getMessageViewTime()
- {
+ public int getMessageViewTime() {
return messageViewTime;
}
- public void setMessageViewTime(int messageViewTime)
- {
+ public void setMessageViewTime(int messageViewTime) {
this.messageViewTime = messageViewTime;
}
- public int getMessageViewDate()
- {
+ public int getMessageViewDate() {
return messageViewDate;
}
- public void setMessageViewDate(int messageViewDate)
- {
+ public void setMessageViewDate(int messageViewDate) {
this.messageViewDate = messageViewDate;
}
- public TextSize getMessageViewContent()
- {
+ public TextSize getMessageViewContent() {
return messageViewContent;
}
- public int getMessageViewContentAsInt()
- {
- switch (messageViewContent)
- {
- case SMALLEST:
- return 1;
- case SMALLER:
- return 2;
- default:
- case NORMAL:
- return 3;
- case LARGER:
- return 4;
- case LARGEST:
- return 5;
+ public int getMessageViewContentAsInt() {
+ switch (messageViewContent) {
+ case SMALLEST:
+ return 1;
+ case SMALLER:
+ return 2;
+ default:
+ case NORMAL:
+ return 3;
+ case LARGER:
+ return 4;
+ case LARGEST:
+ return 5;
}
}
- public void setMessageViewContent(int size)
- {
- switch (size)
- {
- case 1:
- messageViewContent = TextSize.SMALLEST;
- break;
- case 2:
- messageViewContent = TextSize.SMALLER;
- break;
- case 3:
- messageViewContent = TextSize.NORMAL;
- break;
- case 4:
- messageViewContent = TextSize.LARGER;
- break;
- case 5:
- messageViewContent = TextSize.LARGEST;
- break;
+ public void setMessageViewContent(int size) {
+ switch (size) {
+ case 1:
+ messageViewContent = TextSize.SMALLEST;
+ break;
+ case 2:
+ messageViewContent = TextSize.SMALLER;
+ break;
+ case 3:
+ messageViewContent = TextSize.NORMAL;
+ break;
+ case 4:
+ messageViewContent = TextSize.LARGER;
+ break;
+ case 5:
+ messageViewContent = TextSize.LARGEST;
+ break;
}
}
}
diff --git a/src/com/fsck/k9/Identity.java b/src/com/fsck/k9/Identity.java
index 3810bc210..1aead56d6 100644
--- a/src/com/fsck/k9/Identity.java
+++ b/src/com/fsck/k9/Identity.java
@@ -2,8 +2,7 @@ package com.fsck.k9;
import java.io.Serializable;
-public class Identity implements Serializable
-{
+public class Identity implements Serializable {
private static final long serialVersionUID = -1666669071480985760L;
private String mDescription;
private String mName;
@@ -12,69 +11,56 @@ public class Identity implements Serializable
private boolean mSignatureUse;
private String replyTo;
- public synchronized String getName()
- {
+ public synchronized String getName() {
return mName;
}
- public synchronized void setName(String name)
- {
+ public synchronized void setName(String name) {
mName = name;
}
- public synchronized String getEmail()
- {
+ public synchronized String getEmail() {
return mEmail;
}
- public synchronized void setEmail(String email)
- {
+ public synchronized void setEmail(String email) {
mEmail = email;
}
- public synchronized boolean getSignatureUse()
- {
+ public synchronized boolean getSignatureUse() {
return mSignatureUse;
}
- public synchronized void setSignatureUse(boolean signatureUse)
- {
+ public synchronized void setSignatureUse(boolean signatureUse) {
mSignatureUse = signatureUse;
}
- public synchronized String getSignature()
- {
+ public synchronized String getSignature() {
return mSignature;
}
- public synchronized void setSignature(String signature)
- {
+ public synchronized void setSignature(String signature) {
mSignature = signature;
}
- public synchronized String getDescription()
- {
+ public synchronized String getDescription() {
return mDescription;
}
- public synchronized void setDescription(String description)
- {
+ public synchronized void setDescription(String description) {
mDescription = description;
}
- public synchronized String getReplyTo()
- {
+ public synchronized String getReplyTo() {
return replyTo;
}
- public synchronized void setReplyTo(String replyTo)
- {
+ public synchronized void setReplyTo(String replyTo) {
this.replyTo = replyTo;
}
@Override
- public synchronized String toString()
- {
+ public synchronized String toString() {
return "Account.Identity(description=" + mDescription + ", name=" + mName + ", email=" + mEmail + ", replyTo=" + replyTo + ", signature=" + mSignature;
}
}
diff --git a/src/com/fsck/k9/K9.java b/src/com/fsck/k9/K9.java
index a925a028e..f8b45a1e3 100644
--- a/src/com/fsck/k9/K9.java
+++ b/src/com/fsck/k9/K9.java
@@ -35,16 +35,14 @@ import com.fsck.k9.service.MailService;
import com.fsck.k9.service.ShutdownReceiver;
import com.fsck.k9.service.StorageGoneReceiver;
-public class K9 extends Application
-{
+public class K9 extends Application {
/**
* Components that are interested in knowing when the K9 instance is
* available and ready (Android invokes Application.onCreate() after other
* components') should implement this interface and register using
* {@link K9#registerApplicationAware(ApplicationAware)}.
*/
- public static interface ApplicationAware
- {
+ public static interface ApplicationAware {
/**
* Called when the Application instance is available and ready.
*
@@ -68,8 +66,7 @@ public class K9 extends Application
private static List observers = new ArrayList();
- public enum BACKGROUND_OPS
- {
+ public enum BACKGROUND_OPS {
WHEN_CHECKED, ALWAYS, NEVER, WHEN_CHECKED_AUTO_SYNC
}
@@ -178,7 +175,7 @@ public class K9 extends Application
private static String mQuietTimeEnds = null;
private static boolean compactLayouts = false;
-
+
private static boolean useGalleryBugWorkaround = false;
private static boolean galleryBuggy;
@@ -187,31 +184,27 @@ public class K9 extends Application
/**
* The MIME type(s) of attachments we're willing to view.
*/
- public static final String[] ACCEPTABLE_ATTACHMENT_VIEW_TYPES = new String[]
- {
+ public static final String[] ACCEPTABLE_ATTACHMENT_VIEW_TYPES = new String[] {
"*/*",
};
/**
* The MIME type(s) of attachments we're not willing to view.
*/
- public static final String[] UNACCEPTABLE_ATTACHMENT_VIEW_TYPES = new String[]
- {
+ public static final String[] UNACCEPTABLE_ATTACHMENT_VIEW_TYPES = new String[] {
};
/**
* The MIME type(s) of attachments we're willing to download to SD.
*/
- public static final String[] ACCEPTABLE_ATTACHMENT_DOWNLOAD_TYPES = new String[]
- {
+ public static final String[] ACCEPTABLE_ATTACHMENT_DOWNLOAD_TYPES = new String[] {
"*/*",
};
/**
* The MIME type(s) of attachments we're not willing to download to SD.
*/
- public static final String[] UNACCEPTABLE_ATTACHMENT_DOWNLOAD_TYPES = new String[]
- {
+ public static final String[] UNACCEPTABLE_ATTACHMENT_DOWNLOAD_TYPES = new String[] {
};
/**
@@ -283,11 +276,9 @@ public class K9 extends Application
public static final int CONNECTIVITY_ID = -3;
- public static class Intents
- {
+ public static class Intents {
- public static class EmailReceived
- {
+ public static class EmailReceived {
public static final String ACTION_EMAIL_RECEIVED = "com.fsck.k9.intent.action.EMAIL_RECEIVED";
public static final String ACTION_EMAIL_DELETED = "com.fsck.k9.intent.action.EMAIL_DELETED";
public static final String ACTION_REFRESH_OBSERVER = "com.fsck.k9.intent.action.REFRESH_OBSERVER";
@@ -309,27 +300,23 @@ public class K9 extends Application
* enables or disables the Compose activity, the boot receiver and the service based on
* whether any accounts are configured.
*/
- public static void setServicesEnabled(Context context)
- {
+ public static void setServicesEnabled(Context context) {
int acctLength = Preferences.getPreferences(context).getAvailableAccounts().size();
setServicesEnabled(context, acctLength > 0, null);
}
- public static void setServicesEnabled(Context context, Integer wakeLockId)
- {
+ public static void setServicesEnabled(Context context, Integer wakeLockId) {
setServicesEnabled(context, Preferences.getPreferences(context).getAvailableAccounts().size() > 0, wakeLockId);
}
- public static void setServicesEnabled(Context context, boolean enabled, Integer wakeLockId)
- {
+ public static void setServicesEnabled(Context context, boolean enabled, Integer wakeLockId) {
PackageManager pm = context.getPackageManager();
if (!enabled && pm.getComponentEnabledSetting(new ComponentName(context, MailService.class)) ==
- PackageManager.COMPONENT_ENABLED_STATE_ENABLED)
- {
+ PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
/*
* If no accounts now exist but the service is still enabled we're about to disable it
* so we'll reschedule to kill off any existing alarms.
@@ -338,14 +325,12 @@ public class K9 extends Application
}
Class>[] classes = { MessageCompose.class, BootReceiver.class, MailService.class };
- for (Class> clazz : classes)
- {
+ for (Class> clazz : classes) {
boolean alreadyEnabled = pm.getComponentEnabledSetting(new ComponentName(context, clazz)) ==
PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
- if (enabled != alreadyEnabled)
- {
+ if (enabled != alreadyEnabled) {
pm.setComponentEnabledSetting(
new ComponentName(context, clazz),
enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED :
@@ -355,8 +340,7 @@ public class K9 extends Application
}
if (enabled && pm.getComponentEnabledSetting(new ComponentName(context, MailService.class)) ==
- PackageManager.COMPONENT_ENABLED_STATE_ENABLED)
- {
+ PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
/*
* And now if accounts do exist then we've just enabled the service and we want to
* schedule alarms for the new accounts.
@@ -371,8 +355,7 @@ public class K9 extends Application
* would make K-9 auto-start. We don't want auto-start because the initialization
* sequence isn't safe while some events occur (SD card unmount).
*/
- protected void registerReceivers()
- {
+ protected void registerReceivers() {
final StorageGoneReceiver receiver = new StorageGoneReceiver();
final IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_MEDIA_EJECT);
@@ -382,18 +365,13 @@ public class K9 extends Application
final BlockingQueue queue = new SynchronousQueue();
// starting a new thread to handle unmount events
- new Thread(new Runnable()
- {
+ new Thread(new Runnable() {
@Override
- public void run()
- {
+ public void run() {
Looper.prepare();
- try
- {
+ try {
queue.put(new Handler());
- }
- catch (InterruptedException e)
- {
+ } catch (InterruptedException e) {
Log.e(K9.LOG_TAG, "", e);
}
Looper.loop();
@@ -401,14 +379,11 @@ public class K9 extends Application
}, "Unmount-thread").start();
- try
- {
+ try {
final Handler storageGoneHandler = queue.take();
registerReceiver(receiver, filter, null, storageGoneHandler);
Log.i(K9.LOG_TAG, "Registered: unmount receiver");
- }
- catch (InterruptedException e)
- {
+ } catch (InterruptedException e) {
Log.e(K9.LOG_TAG, "Unable to register unmount receiver", e);
}
@@ -416,8 +391,7 @@ public class K9 extends Application
Log.i(K9.LOG_TAG, "Registered: shutdown receiver");
}
- public static void save(SharedPreferences.Editor editor)
- {
+ public static void save(SharedPreferences.Editor editor) {
editor.putBoolean("enableDebugLogging", K9.DEBUG);
editor.putBoolean("enableSensitiveLogging", K9.DEBUG_SENSITIVE);
editor.putString("backgroundOperations", K9.backgroundOps.toString());
@@ -426,7 +400,7 @@ public class K9 extends Application
editor.putBoolean("useVolumeKeysForNavigation", mUseVolumeKeysForNavigation);
editor.putBoolean("useVolumeKeysForListNavigation", mUseVolumeKeysForListNavigation);
editor.putBoolean("manageBack", mManageBack);
- editor.putBoolean("zoomControlsEnabled",mZoomControlsEnabled);
+ editor.putBoolean("zoomControlsEnabled", mZoomControlsEnabled);
editor.putBoolean("mobileOptimizedLayout", mMobileOptimizedLayout);
editor.putBoolean("quietTimeEnabled", mQuietTimeEnabled);
editor.putString("quietTimeStarts", mQuietTimeStarts);
@@ -435,16 +409,16 @@ public class K9 extends Application
editor.putBoolean("startIntegratedInbox", mStartIntegratedInbox);
editor.putBoolean("measureAccounts", mMeasureAccounts);
editor.putBoolean("countSearchMessages", mCountSearchMessages);
- editor.putBoolean("messageListStars",mMessageListStars);
- editor.putBoolean("messageListCheckboxes",mMessageListCheckboxes);
- editor.putBoolean("messageListTouchable",mMessageListTouchable);
- editor.putInt("messageListPreviewLines",mMessageListPreviewLines);
+ editor.putBoolean("messageListStars", mMessageListStars);
+ editor.putBoolean("messageListCheckboxes", mMessageListCheckboxes);
+ editor.putBoolean("messageListTouchable", mMessageListTouchable);
+ editor.putInt("messageListPreviewLines", mMessageListPreviewLines);
- editor.putBoolean("showCorrespondentNames",mShowCorrespondentNames);
- editor.putBoolean("showContactName",mShowContactName);
- editor.putBoolean("changeRegisteredNameColor",mChangeContactNameColor);
- editor.putInt("registeredNameColor",mContactNameColor);
- editor.putBoolean("messageViewFixedWidthFont",mMessageViewFixedWidthFont);
+ editor.putBoolean("showCorrespondentNames", mShowCorrespondentNames);
+ editor.putBoolean("showContactName", mShowContactName);
+ editor.putBoolean("changeRegisteredNameColor", mChangeContactNameColor);
+ editor.putInt("registeredNameColor", mContactNameColor);
+ editor.putBoolean("messageViewFixedWidthFont", mMessageViewFixedWidthFont);
editor.putBoolean("messageViewReturnToList", mMessageViewReturnToList);
editor.putString("language", language);
@@ -454,15 +428,14 @@ public class K9 extends Application
editor.putBoolean("confirmDelete", mConfirmDelete);
editor.putBoolean("keyguardPrivacy", mKeyguardPrivacy);
-
+
editor.putBoolean("compactLayouts", compactLayouts);
fontSizes.save(editor);
}
@Override
- public void onCreate()
- {
+ public void onCreate() {
maybeSetupStrictMode();
super.onCreate();
app = this;
@@ -482,17 +455,17 @@ public class K9 extends Application
mStartIntegratedInbox = sprefs.getBoolean("startIntegratedInbox", false);
mMeasureAccounts = sprefs.getBoolean("measureAccounts", true);
mCountSearchMessages = sprefs.getBoolean("countSearchMessages", true);
- mMessageListStars = sprefs.getBoolean("messageListStars",true);
- mMessageListCheckboxes = sprefs.getBoolean("messageListCheckboxes",false);
- mMessageListTouchable = sprefs.getBoolean("messageListTouchable",false);
+ mMessageListStars = sprefs.getBoolean("messageListStars", true);
+ mMessageListCheckboxes = sprefs.getBoolean("messageListCheckboxes", false);
+ mMessageListTouchable = sprefs.getBoolean("messageListTouchable", false);
mMessageListPreviewLines = sprefs.getInt("messageListPreviewLines", 2);
mMobileOptimizedLayout = sprefs.getBoolean("mobileOptimizedLayout", false);
- mZoomControlsEnabled = sprefs.getBoolean("zoomControlsEnabled",false);
+ mZoomControlsEnabled = sprefs.getBoolean("zoomControlsEnabled", false);
mQuietTimeEnabled = sprefs.getBoolean("quietTimeEnabled", false);
- mQuietTimeStarts = sprefs.getString("quietTimeStarts", "21:00" );
- mQuietTimeEnds= sprefs.getString("quietTimeEnds", "7:00");
+ mQuietTimeStarts = sprefs.getString("quietTimeStarts", "21:00");
+ mQuietTimeEnds = sprefs.getString("quietTimeEnds", "7:00");
mShowCorrespondentNames = sprefs.getBoolean("showCorrespondentNames", true);
mShowContactName = sprefs.getBoolean("showContactName", false);
@@ -506,17 +479,14 @@ public class K9 extends Application
mConfirmDelete = sprefs.getBoolean("confirmDelete", false);
mKeyguardPrivacy = sprefs.getBoolean("keyguardPrivacy", false);
-
+
compactLayouts = sprefs.getBoolean("compactLayouts", false);
fontSizes.load(sprefs);
- try
- {
+ try {
setBackgroundOps(BACKGROUND_OPS.valueOf(sprefs.getString("backgroundOperations", "WHEN_CHECKED")));
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
setBackgroundOps(BACKGROUND_OPS.WHEN_CHECKED);
}
@@ -536,12 +506,9 @@ public class K9 extends Application
setServicesEnabled(this);
registerReceivers();
- MessagingController.getInstance(this).addListener(new MessagingListener()
- {
- private void broadcastIntent(String action, Account account, String folder, Message message)
- {
- try
- {
+ MessagingController.getInstance(this).addListener(new MessagingListener() {
+ private void broadcastIntent(String action, Account account, String folder, Message message) {
+ try {
Uri uri = Uri.parse("email://messages/" + account.getAccountNumber() + "/" + Uri.encode(folder) + "/" + Uri.encode(message.getUid()));
Intent intent = new Intent(action, uri);
intent.putExtra(K9.Intents.EmailReceived.EXTRA_ACCOUNT, account.getDescription());
@@ -561,9 +528,7 @@ public class K9 extends Application
+ " message uid=" + message.getUid()
);
- }
- catch (MessagingException e)
- {
+ } catch (MessagingException e) {
Log.w(K9.LOG_TAG, "Error: action=" + action
+ " account=" + account.getDescription()
+ " folder=" + folder
@@ -573,26 +538,22 @@ public class K9 extends Application
}
@Override
- public void synchronizeMailboxRemovedMessage(Account account, String folder, Message message)
- {
+ public void synchronizeMailboxRemovedMessage(Account account, String folder, Message message) {
broadcastIntent(K9.Intents.EmailReceived.ACTION_EMAIL_DELETED, account, folder, message);
}
@Override
- public void messageDeleted(Account account, String folder, Message message)
- {
+ public void messageDeleted(Account account, String folder, Message message) {
broadcastIntent(K9.Intents.EmailReceived.ACTION_EMAIL_DELETED, account, folder, message);
}
@Override
- public void synchronizeMailboxNewMessage(Account account, String folder, Message message)
- {
+ public void synchronizeMailboxNewMessage(Account account, String folder, Message message) {
broadcastIntent(K9.Intents.EmailReceived.ACTION_EMAIL_RECEIVED, account, folder, message);
}
@Override
- public void searchStats(final AccountStats stats)
- {
+ public void searchStats(final AccountStats stats) {
// let observers know a fetch occured
K9.this.sendBroadcast(new Intent(K9.Intents.EmailReceived.ACTION_REFRESH_OBSERVER, null));
}
@@ -602,22 +563,19 @@ public class K9 extends Application
notifyObservers();
}
- private void maybeSetupStrictMode()
- {
+ private void maybeSetupStrictMode() {
if (!K9.DEVELOPER_MODE)
return;
- try
- {
+ try {
Class> strictMode = Class.forName("android.os.StrictMode");
Method enableDefaults = strictMode.getMethod("enableDefaults");
enableDefaults.invoke(strictMode);
}
- catch (Exception e)
- {
+ catch (Exception e) {
// Discard , as it means we're not running on a device with strict mode
- Log.v(K9.LOG_TAG, "Failed to turn on strict mode "+e);
+ Log.v(K9.LOG_TAG, "Failed to turn on strict mode " + e);
}
}
@@ -628,20 +586,14 @@ public class K9 extends Application
* other components' onCreate(), here is a way to notify interested
* component that the application is available and ready
*/
- protected void notifyObservers()
- {
- for (final ApplicationAware aware : observers)
- {
- if (K9.DEBUG)
- {
+ protected void notifyObservers() {
+ for (final ApplicationAware aware : observers) {
+ if (K9.DEBUG) {
Log.v(K9.LOG_TAG, "Initializing observer: " + aware);
}
- try
- {
+ try {
aware.initializeComponent(this);
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
Log.w(K9.LOG_TAG, "Failure when notifying " + aware, e);
}
}
@@ -653,147 +605,118 @@ public class K9 extends Application
* @param component
* Never null
.
*/
- public static void registerApplicationAware(final ApplicationAware component)
- {
- if (!observers.contains(component))
- {
+ public static void registerApplicationAware(final ApplicationAware component) {
+ if (!observers.contains(component)) {
observers.add(component);
}
}
- public static String getK9Language()
- {
+ public static String getK9Language() {
return language;
}
- public static void setK9Language(String nlanguage)
- {
+ public static void setK9Language(String nlanguage) {
language = nlanguage;
}
- public static int getK9Theme()
- {
+ public static int getK9Theme() {
return theme;
}
- public static void setK9Theme(int ntheme)
- {
+ public static void setK9Theme(int ntheme) {
theme = ntheme;
}
- public static BACKGROUND_OPS getBackgroundOps()
- {
+ public static BACKGROUND_OPS getBackgroundOps() {
return backgroundOps;
}
- public static boolean setBackgroundOps(BACKGROUND_OPS backgroundOps)
- {
+ public static boolean setBackgroundOps(BACKGROUND_OPS backgroundOps) {
BACKGROUND_OPS oldBackgroundOps = K9.backgroundOps;
K9.backgroundOps = backgroundOps;
return backgroundOps != oldBackgroundOps;
}
- public static boolean setBackgroundOps(String nbackgroundOps)
- {
+ public static boolean setBackgroundOps(String nbackgroundOps) {
return setBackgroundOps(BACKGROUND_OPS.valueOf(nbackgroundOps));
}
- public static boolean gesturesEnabled()
- {
+ public static boolean gesturesEnabled() {
return mGesturesEnabled;
}
- public static void setGesturesEnabled(boolean gestures)
- {
+ public static void setGesturesEnabled(boolean gestures) {
mGesturesEnabled = gestures;
}
- public static boolean useVolumeKeysForNavigationEnabled()
- {
+ public static boolean useVolumeKeysForNavigationEnabled() {
return mUseVolumeKeysForNavigation;
}
- public static void setUseVolumeKeysForNavigation(boolean volume)
- {
+ public static void setUseVolumeKeysForNavigation(boolean volume) {
mUseVolumeKeysForNavigation = volume;
}
- public static boolean useVolumeKeysForListNavigationEnabled()
- {
+ public static boolean useVolumeKeysForListNavigationEnabled() {
return mUseVolumeKeysForListNavigation;
}
- public static void setUseVolumeKeysForListNavigation(boolean enabled)
- {
+ public static void setUseVolumeKeysForListNavigation(boolean enabled) {
mUseVolumeKeysForListNavigation = enabled;
}
- public static boolean manageBack()
- {
+ public static boolean manageBack() {
return mManageBack;
}
- public static void setManageBack(boolean manageBack)
- {
+ public static void setManageBack(boolean manageBack) {
mManageBack = manageBack;
}
- public static boolean zoomControlsEnabled()
- {
+ public static boolean zoomControlsEnabled() {
return mZoomControlsEnabled;
}
- public static void setZoomControlsEnabled(boolean zoomControlsEnabled)
- {
+ public static void setZoomControlsEnabled(boolean zoomControlsEnabled) {
mZoomControlsEnabled = zoomControlsEnabled;
}
- public static boolean mobileOptimizedLayout()
- {
+ public static boolean mobileOptimizedLayout() {
return mMobileOptimizedLayout;
}
- public static void setMobileOptimizedLayout(boolean mobileOptimizedLayout)
- {
+ public static void setMobileOptimizedLayout(boolean mobileOptimizedLayout) {
mMobileOptimizedLayout = mobileOptimizedLayout;
}
- public static boolean getQuietTimeEnabled()
- {
+ public static boolean getQuietTimeEnabled() {
return mQuietTimeEnabled;
}
- public static void setQuietTimeEnabled(boolean quietTimeEnabled)
- {
+ public static void setQuietTimeEnabled(boolean quietTimeEnabled) {
mQuietTimeEnabled = quietTimeEnabled;
}
- public static String getQuietTimeStarts()
- {
+ public static String getQuietTimeStarts() {
return mQuietTimeStarts;
}
- public static void setQuietTimeStarts(String quietTimeStarts)
- {
+ public static void setQuietTimeStarts(String quietTimeStarts) {
mQuietTimeStarts = quietTimeStarts;
}
- public static String getQuietTimeEnds()
- {
+ public static String getQuietTimeEnds() {
return mQuietTimeEnds;
}
- public static void setQuietTimeEnds(String quietTimeEnds)
- {
+ public static void setQuietTimeEnds(String quietTimeEnds) {
mQuietTimeEnds = quietTimeEnds;
}
- public static boolean isQuietTime()
- {
- if (!mQuietTimeEnabled)
- {
+ public static boolean isQuietTime() {
+ if (!mQuietTimeEnabled) {
return false;
}
@@ -804,34 +727,29 @@ public class K9 extends Application
Integer endHour = Integer.parseInt(mQuietTimeEnds.split(":")[0]);
Integer endMinute = Integer.parseInt(mQuietTimeEnds.split(":")[1]);
- Integer now = (time.hour * 60 ) + time.minute;
+ Integer now = (time.hour * 60) + time.minute;
Integer quietStarts = startHour * 60 + startMinute;
- Integer quietEnds = endHour * 60 +endMinute;
+ Integer quietEnds = endHour * 60 + endMinute;
// If start and end times are the same, we're never quiet
- if (quietStarts.equals(quietEnds))
- {
+ if (quietStarts.equals(quietEnds)) {
return false;
}
// 21:00 - 05:00 means we want to be quiet if it's after 9 or before 5
- if (quietStarts > quietEnds)
- {
+ if (quietStarts > quietEnds) {
// if it's 22:00 or 03:00 but not 8:00
- if ( now >= quietStarts || now <= quietEnds)
- {
+ if (now >= quietStarts || now <= quietEnds) {
return true;
}
}
// 01:00 - 05:00
- else
- {
+ else {
// if it' 2:00 or 4:00 but not 8:00 or 0:00
- if ( now >= quietStarts && now <= quietEnds)
- {
+ if (now >= quietStarts && now <= quietEnds) {
return true;
}
}
@@ -841,214 +759,170 @@ public class K9 extends Application
- public static boolean startIntegratedInbox()
- {
+ public static boolean startIntegratedInbox() {
return mStartIntegratedInbox;
}
- public static void setStartIntegratedInbox(boolean startIntegratedInbox)
- {
+ public static void setStartIntegratedInbox(boolean startIntegratedInbox) {
mStartIntegratedInbox = startIntegratedInbox;
}
- public static boolean showAnimations()
- {
+ public static boolean showAnimations() {
return mAnimations;
}
- public static void setAnimations(boolean animations)
- {
+ public static void setAnimations(boolean animations) {
mAnimations = animations;
}
- public static boolean messageListTouchable()
- {
+ public static boolean messageListTouchable() {
return mMessageListTouchable;
}
- public static void setMessageListTouchable(boolean touchy)
- {
+ public static void setMessageListTouchable(boolean touchy) {
mMessageListTouchable = touchy;
}
- public static int messageListPreviewLines()
- {
+ public static int messageListPreviewLines() {
return mMessageListPreviewLines;
}
- public static void setMessageListPreviewLines(int lines)
- {
+ public static void setMessageListPreviewLines(int lines) {
mMessageListPreviewLines = lines;
}
- public static boolean messageListStars()
- {
+ public static boolean messageListStars() {
return mMessageListStars;
}
- public static void setMessageListStars(boolean stars)
- {
+ public static void setMessageListStars(boolean stars) {
mMessageListStars = stars;
}
- public static boolean messageListCheckboxes()
- {
+ public static boolean messageListCheckboxes() {
return mMessageListCheckboxes;
}
- public static void setMessageListCheckboxes(boolean checkboxes)
- {
+ public static void setMessageListCheckboxes(boolean checkboxes) {
mMessageListCheckboxes = checkboxes;
}
- public static boolean showCorrespondentNames()
- {
+ public static boolean showCorrespondentNames() {
return mShowCorrespondentNames;
}
- public static void setShowCorrespondentNames(boolean showCorrespondentNames)
- {
+ public static void setShowCorrespondentNames(boolean showCorrespondentNames) {
mShowCorrespondentNames = showCorrespondentNames;
}
- public static boolean showContactName()
- {
+ public static boolean showContactName() {
return mShowContactName;
}
- public static void setShowContactName(boolean showContactName)
- {
+ public static void setShowContactName(boolean showContactName) {
mShowContactName = showContactName;
}
- public static boolean changeContactNameColor()
- {
+ public static boolean changeContactNameColor() {
return mChangeContactNameColor;
}
- public static void setChangeContactNameColor(boolean changeContactNameColor)
- {
+ public static void setChangeContactNameColor(boolean changeContactNameColor) {
mChangeContactNameColor = changeContactNameColor;
}
- public static int getContactNameColor()
- {
+ public static int getContactNameColor() {
return mContactNameColor;
}
- public static void setContactNameColor(int contactNameColor)
- {
+ public static void setContactNameColor(int contactNameColor) {
mContactNameColor = contactNameColor;
}
- public static boolean messageViewFixedWidthFont()
- {
+ public static boolean messageViewFixedWidthFont() {
return mMessageViewFixedWidthFont;
}
- public static void setMessageViewFixedWidthFont(boolean fixed)
- {
+ public static void setMessageViewFixedWidthFont(boolean fixed) {
mMessageViewFixedWidthFont = fixed;
}
- public static boolean messageViewReturnToList()
- {
+ public static boolean messageViewReturnToList() {
return mMessageViewReturnToList;
}
- public static void setMessageViewReturnToList(boolean messageViewReturnToList)
- {
+ public static void setMessageViewReturnToList(boolean messageViewReturnToList) {
mMessageViewReturnToList = messageViewReturnToList;
}
- public static Method getMethod(Class> classObject, String methodName)
- {
- try
- {
+ public static Method getMethod(Class> classObject, String methodName) {
+ try {
return classObject.getMethod(methodName, boolean.class);
- }
- catch (NoSuchMethodException e)
- {
+ } catch (NoSuchMethodException e) {
Log.i(K9.LOG_TAG, "Can't get method " +
classObject.toString() + "." + methodName);
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
Log.e(K9.LOG_TAG, "Error while using reflection to get method " +
classObject.toString() + "." + methodName, e);
}
return null;
}
- public static FontSizes getFontSizes()
- {
+ public static FontSizes getFontSizes() {
return fontSizes;
}
- public static boolean measureAccounts()
- {
+ public static boolean measureAccounts() {
return mMeasureAccounts;
}
- public static void setMeasureAccounts(boolean measureAccounts)
- {
+ public static void setMeasureAccounts(boolean measureAccounts) {
mMeasureAccounts = measureAccounts;
}
- public static boolean countSearchMessages()
- {
+ public static boolean countSearchMessages() {
return mCountSearchMessages;
}
- public static void setCountSearchMessages(boolean countSearchMessages)
- {
+ public static void setCountSearchMessages(boolean countSearchMessages) {
mCountSearchMessages = countSearchMessages;
}
- public static boolean useGalleryBugWorkaround()
- {
+ public static boolean useGalleryBugWorkaround() {
return useGalleryBugWorkaround;
}
- public static void setUseGalleryBugWorkaround(boolean useGalleryBugWorkaround)
- {
+ public static void setUseGalleryBugWorkaround(boolean useGalleryBugWorkaround) {
K9.useGalleryBugWorkaround = useGalleryBugWorkaround;
}
- public static boolean isGalleryBuggy()
- {
+ public static boolean isGalleryBuggy() {
return galleryBuggy;
}
- public static boolean confirmDelete()
- {
+ public static boolean confirmDelete() {
return mConfirmDelete;
}
- public static void setConfirmDelete(final boolean confirm)
- {
+ public static void setConfirmDelete(final boolean confirm) {
mConfirmDelete = confirm;
}
/**
* @return Whether privacy rules should be applied when system is locked
*/
- public static boolean keyguardPrivacy()
- {
+ public static boolean keyguardPrivacy() {
return mKeyguardPrivacy;
}
- public static void setKeyguardPrivacy(final boolean state)
- {
+ public static void setKeyguardPrivacy(final boolean state) {
mKeyguardPrivacy = state;
}
-
- public static boolean useCompactLayouts()
- {
+
+ public static boolean useCompactLayouts() {
return compactLayouts;
}
- public static void setCompactLayouts(boolean compactLayouts)
- {
+ public static void setCompactLayouts(boolean compactLayouts) {
K9.compactLayouts = compactLayouts;
}
@@ -1061,16 +935,12 @@ public class K9 extends Application
*
* @return true, if a buggy Gallery 3D package was found. False, otherwise.
*/
- private boolean checkForBuggyGallery()
- {
- try
- {
+ private boolean checkForBuggyGallery() {
+ try {
PackageInfo pi = getPackageManager().getPackageInfo("com.cooliris.media", 0);
return (pi.versionCode == 30682);
- }
- catch (NameNotFoundException e)
- {
+ } catch (NameNotFoundException e) {
return false;
}
}
diff --git a/src/com/fsck/k9/NotificationSetting.java b/src/com/fsck/k9/NotificationSetting.java
index ff9a6c7a0..6885ae1d3 100644
--- a/src/com/fsck/k9/NotificationSetting.java
+++ b/src/com/fsck/k9/NotificationSetting.java
@@ -3,8 +3,7 @@ package com.fsck.k9;
/**
* Describes how a notification should behave.
*/
-public class NotificationSetting
-{
+public class NotificationSetting {
/**
* Ring notification kill switch. Allow disabling ringtones without losing
@@ -38,8 +37,7 @@ public class NotificationSetting
* true
to allow ringtones, false
* otherwise.
*/
- public synchronized void setRing(boolean ring)
- {
+ public synchronized void setRing(boolean ring) {
mRing = ring;
}
@@ -47,68 +45,55 @@ public class NotificationSetting
* @return true
if ringtone is allowed to play,
* false
otherwise.
*/
- public synchronized boolean shouldRing()
- {
+ public synchronized boolean shouldRing() {
return mRing;
}
- public synchronized String getRingtone()
- {
+ public synchronized String getRingtone() {
return mRingtoneUri;
}
- public synchronized void setRingtone(String ringtoneUri)
- {
+ public synchronized void setRingtone(String ringtoneUri) {
mRingtoneUri = ringtoneUri;
}
- public synchronized boolean isLed()
- {
+ public synchronized boolean isLed() {
return mLed;
}
- public synchronized void setLed(final boolean led)
- {
+ public synchronized void setLed(final boolean led) {
mLed = led;
}
- public synchronized int getLedColor()
- {
+ public synchronized int getLedColor() {
return mLedColor;
}
- public synchronized void setLedColor(int color)
- {
+ public synchronized void setLedColor(int color) {
mLedColor = color;
}
- public synchronized boolean shouldVibrate()
- {
+ public synchronized boolean shouldVibrate() {
return mVibrate;
}
- public synchronized void setVibrate(boolean vibrate)
- {
+ public synchronized void setVibrate(boolean vibrate) {
mVibrate = vibrate;
}
- public synchronized int getVibratePattern()
- {
+ public synchronized int getVibratePattern() {
return mVibratePattern;
}
- public synchronized int getVibrateTimes()
- {
+ public synchronized int getVibrateTimes() {
return mVibrateTimes;
}
- public synchronized void setVibratePattern(int pattern)
- {
+ public synchronized void setVibratePattern(int pattern) {
mVibratePattern = pattern;
}
- public synchronized void setVibrateTimes(int times)
- {
+ public synchronized void setVibrateTimes(int times) {
mVibrateTimes = times;
}
@@ -122,45 +107,41 @@ public class NotificationSetting
* @return Pattern multiplied by the number of times requested.
*/
- public long[] getVibration()
- {
+ public long[] getVibration() {
return getVibration(mVibratePattern, mVibrateTimes);
}
- public static long[] getVibration(int pattern, int times)
- {
+ public static long[] getVibration(int pattern, int times) {
// These are "off, on" patterns, specified in milliseconds
- long[] pattern0 = new long[] {300,200}; // like the default pattern
- long[] pattern1 = new long[] {100,200};
- long[] pattern2 = new long[] {100,500};
- long[] pattern3 = new long[] {200,200};
- long[] pattern4 = new long[] {200,500};
- long[] pattern5 = new long[] {500,500};
+ long[] pattern0 = new long[] {300, 200}; // like the default pattern
+ long[] pattern1 = new long[] {100, 200};
+ long[] pattern2 = new long[] {100, 500};
+ long[] pattern3 = new long[] {200, 200};
+ long[] pattern4 = new long[] {200, 500};
+ long[] pattern5 = new long[] {500, 500};
long[] selectedPattern = pattern0; //default pattern
- switch (pattern)
- {
- case 1:
- selectedPattern = pattern1;
- break;
- case 2:
- selectedPattern = pattern2;
- break;
- case 3:
- selectedPattern = pattern3;
- break;
- case 4:
- selectedPattern = pattern4;
- break;
- case 5:
- selectedPattern = pattern5;
- break;
+ switch (pattern) {
+ case 1:
+ selectedPattern = pattern1;
+ break;
+ case 2:
+ selectedPattern = pattern2;
+ break;
+ case 3:
+ selectedPattern = pattern3;
+ break;
+ case 4:
+ selectedPattern = pattern4;
+ break;
+ case 5:
+ selectedPattern = pattern5;
+ break;
}
long[] repeatedPattern = new long[selectedPattern.length * times];
- for (int n = 0; n < times; n++)
- {
+ for (int n = 0; n < times; n++) {
System.arraycopy(selectedPattern, 0, repeatedPattern, n * selectedPattern.length, selectedPattern.length);
}
// Do not wait before starting the vibration pattern.
diff --git a/src/com/fsck/k9/Preferences.java b/src/com/fsck/k9/Preferences.java
index 5769267f8..dece28412 100644
--- a/src/com/fsck/k9/Preferences.java
+++ b/src/com/fsck/k9/Preferences.java
@@ -11,8 +11,7 @@ import android.util.Log;
import com.fsck.k9.preferences.Editor;
import com.fsck.k9.preferences.Storage;
-public class Preferences
-{
+public class Preferences {
/**
* Immutable empty {@link Account} array
@@ -21,10 +20,8 @@ public class Preferences
private static Preferences preferences;
- public static synchronized Preferences getPreferences(Context context)
- {
- if (preferences == null)
- {
+ public static synchronized Preferences getPreferences(Context context) {
+ if (preferences == null) {
preferences = new Preferences(context);
}
return preferences;
@@ -36,12 +33,10 @@ public class Preferences
private Account newAccount;
private Context mContext;
- private Preferences(Context context)
- {
+ private Preferences(Context context) {
mStorage = Storage.getStorage(context);
mContext = context;
- if (mStorage.size() == 0)
- {
+ if (mStorage.size() == 0) {
Log.i(K9.LOG_TAG, "Preferences storage is zero-size, importing from Android-style preferences");
Editor editor = mStorage.edit();
editor.copy(context.getSharedPreferences("AndroidMail.Main", Context.MODE_PRIVATE));
@@ -49,20 +44,15 @@ public class Preferences
}
}
- private synchronized void loadAccounts()
- {
+ private synchronized void loadAccounts() {
String accountUuids = getPreferences().getString("accountUuids", null);
- if ((accountUuids != null) && (accountUuids.length() != 0))
- {
+ if ((accountUuids != null) && (accountUuids.length() != 0)) {
String[] uuids = accountUuids.split(",");
accounts = new ArrayList(uuids.length);
- for (String uuid : uuids)
- {
+ for (String uuid : uuids) {
accounts.add(new Account(this, uuid));
}
- }
- else
- {
+ } else {
accounts = new ArrayList();
}
}
@@ -72,15 +62,12 @@ public class Preferences
* registered the method returns an empty array.
* @return all accounts
*/
- public synchronized Account[] getAccounts()
- {
- if (accounts == null)
- {
+ public synchronized Account[] getAccounts() {
+ if (accounts == null) {
loadAccounts();
}
- if ((newAccount != null) && newAccount.getAccountNumber() != -1)
- {
+ if ((newAccount != null) && newAccount.getAccountNumber() != -1) {
accounts.add(newAccount);
newAccount = null;
}
@@ -93,23 +80,18 @@ public class Preferences
* registered the method returns an empty array.
* @return all accounts with {@link Account#isAvailable(Context)}
*/
- public synchronized Collection getAvailableAccounts()
- {
- if (accounts == null)
- {
+ public synchronized Collection getAvailableAccounts() {
+ if (accounts == null) {
loadAccounts();
}
- if ((newAccount != null) && newAccount.getAccountNumber() != -1)
- {
+ if ((newAccount != null) && newAccount.getAccountNumber() != -1) {
accounts.add(newAccount);
newAccount = null;
}
Collection retval = new ArrayList(accounts.size());
- for (Account account : accounts)
- {
- if (account.isAvailable(mContext))
- {
+ for (Account account : accounts) {
+ if (account.isAvailable(mContext)) {
retval.add(account);
}
}
@@ -117,43 +99,35 @@ public class Preferences
return retval;
}
- public synchronized Account getAccount(String uuid)
- {
- if (accounts == null)
- {
+ public synchronized Account getAccount(String uuid) {
+ if (accounts == null) {
loadAccounts();
}
- for (Account account : accounts)
- {
- if (account.getUuid().equals(uuid))
- {
+ for (Account account : accounts) {
+ if (account.getUuid().equals(uuid)) {
return account;
}
}
- if ((newAccount != null) && newAccount.getUuid().equals(uuid))
- {
+ if ((newAccount != null) && newAccount.getUuid().equals(uuid)) {
return newAccount;
}
return null;
}
- public synchronized Account newAccount()
- {
+ public synchronized Account newAccount() {
newAccount = new Account(K9.app);
return newAccount;
}
- public synchronized void deleteAccount(Account account)
- {
+ public synchronized void deleteAccount(Account account) {
accounts.remove(account);
account.delete(this);
- if (newAccount == account)
- {
+ if (newAccount == account) {
newAccount = null;
}
}
@@ -163,16 +137,13 @@ public class Preferences
* the first account in the list is marked as default and then returned. If
* there are no accounts on the system the method returns null.
*/
- public Account getDefaultAccount()
- {
+ public Account getDefaultAccount() {
String defaultAccountUuid = getPreferences().getString("defaultAccountUuid", null);
Account defaultAccount = getAccount(defaultAccountUuid);
- if (defaultAccount == null)
- {
+ if (defaultAccount == null) {
Collection accounts = getAvailableAccounts();
- if (accounts.size() > 0)
- {
+ if (accounts.size() > 0) {
defaultAccount = accounts.iterator().next();
setDefaultAccount(defaultAccount);
}
@@ -181,24 +152,19 @@ public class Preferences
return defaultAccount;
}
- public void setDefaultAccount(Account account)
- {
+ public void setDefaultAccount(Account account) {
getPreferences().edit().putString("defaultAccountUuid", account.getUuid()).commit();
}
- public void dump()
- {
- if (Config.LOGV)
- {
- for (String key : getPreferences().getAll().keySet())
- {
+ public void dump() {
+ if (Config.LOGV) {
+ for (String key : getPreferences().getAll().keySet()) {
Log.v(K9.LOG_TAG, key + " = " + getPreferences().getAll().get(key));
}
}
}
- public SharedPreferences getPreferences()
- {
+ public SharedPreferences getPreferences() {
return mStorage;
}
}
diff --git a/src/com/fsck/k9/SearchAccount.java b/src/com/fsck/k9/SearchAccount.java
index a31d42aba..79161061d 100644
--- a/src/com/fsck/k9/SearchAccount.java
+++ b/src/com/fsck/k9/SearchAccount.java
@@ -10,8 +10,7 @@ import android.content.Context;
import com.fsck.k9.mail.Flag;
-public class SearchAccount implements BaseAccount, SearchSpecification, Serializable
-{
+public class SearchAccount implements BaseAccount, SearchSpecification, Serializable {
private static final long serialVersionUID = -4388420303235543976L;
private Flag[] mRequiredFlags = null;
private Flag[] mForbiddenFlags = null;
@@ -24,116 +23,93 @@ public class SearchAccount implements BaseAccount, SearchSpecification, Serializ
private String[] accountUuids = null;
private String[] folderNames = null;
- public SearchAccount(Preferences preferences)
- {
+ public SearchAccount(Preferences preferences) {
}
- protected synchronized void delete(Preferences preferences)
- {
+ protected synchronized void delete(Preferences preferences) {
}
- public synchronized void save(Preferences preferences)
- {
+ public synchronized void save(Preferences preferences) {
}
- public SearchAccount(Context context, boolean nintegrate, Flag[] requiredFlags, Flag[] forbiddenFlags)
- {
+ public SearchAccount(Context context, boolean nintegrate, Flag[] requiredFlags, Flag[] forbiddenFlags) {
mRequiredFlags = requiredFlags;
mForbiddenFlags = forbiddenFlags;
integrate = nintegrate;
}
@Override
- public synchronized String getEmail()
- {
+ public synchronized String getEmail() {
return email;
}
@Override
- public synchronized void setEmail(String email)
- {
+ public synchronized void setEmail(String email) {
this.email = email;
}
- public Flag[] getRequiredFlags()
- {
+ public Flag[] getRequiredFlags() {
return mRequiredFlags;
}
- public Flag[] getForbiddenFlags()
- {
+ public Flag[] getForbiddenFlags() {
return mForbiddenFlags;
}
- public boolean isIntegrate()
- {
+ public boolean isIntegrate() {
return integrate;
}
- public String getDescription()
- {
+ public String getDescription() {
return description;
}
- public void setDescription(String description)
- {
+ public void setDescription(String description) {
this.description = description;
}
- public String getQuery()
- {
+ public String getQuery() {
return query;
}
- public void setQuery(String query)
- {
+ public void setQuery(String query) {
this.query = query;
}
- public String getUuid()
- {
- if(mUuid == null )
- {
- setUuid( UUID.randomUUID().toString());
+ public String getUuid() {
+ if (mUuid == null) {
+ setUuid(UUID.randomUUID().toString());
}
return mUuid;
}
- public void setUuid(String nUuid)
- {
+ public void setUuid(String nUuid) {
mUuid = nUuid;
}
- public void setIntegrate(boolean integrate)
- {
+ public void setIntegrate(boolean integrate) {
this.integrate = integrate;
}
- public boolean isBuiltin()
- {
+ public boolean isBuiltin() {
return builtin;
}
- public void setBuiltin(boolean builtin)
- {
+ public void setBuiltin(boolean builtin) {
this.builtin = builtin;
}
- public String[] getAccountUuids()
- {
+ public String[] getAccountUuids() {
return accountUuids;
}
- public void setAccountUuids(String[] accountUuids)
- {
+ public void setAccountUuids(String[] accountUuids) {
this.accountUuids = accountUuids;
}
@Override
- public String[] getFolderNames()
- {
+ public String[] getFolderNames() {
return folderNames;
}
- public void setFolderNames(String[] folderNames)
- {
+ public void setFolderNames(String[] folderNames) {
this.folderNames = folderNames;
}
}
diff --git a/src/com/fsck/k9/SearchSpecification.java b/src/com/fsck/k9/SearchSpecification.java
index 6cec76d72..a1f1de0a8 100644
--- a/src/com/fsck/k9/SearchSpecification.java
+++ b/src/com/fsck/k9/SearchSpecification.java
@@ -3,8 +3,7 @@ package com.fsck.k9;
import com.fsck.k9.mail.Flag;
-public interface SearchSpecification
-{
+public interface SearchSpecification {
public Flag[] getRequiredFlags();
diff --git a/src/com/fsck/k9/activity/AccessibleEmailContentActivity.java b/src/com/fsck/k9/activity/AccessibleEmailContentActivity.java
index 80beca186..4b62641e4 100644
--- a/src/com/fsck/k9/activity/AccessibleEmailContentActivity.java
+++ b/src/com/fsck/k9/activity/AccessibleEmailContentActivity.java
@@ -23,8 +23,7 @@ import android.text.Html;
import android.text.Spanned;
import android.widget.ArrayAdapter;
-public class AccessibleEmailContentActivity extends ListActivity
-{
+public class AccessibleEmailContentActivity extends ListActivity {
/**
* Immutable empty String array
*/
@@ -34,8 +33,7 @@ public class AccessibleEmailContentActivity extends ListActivity
* Called when the activity is first created.
*/
@Override
- public void onCreate(Bundle savedInstanceState)
- {
+ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String htmlSource = getIntent().getStringExtra("content");
@@ -43,10 +41,8 @@ public class AccessibleEmailContentActivity extends ListActivity
String[] rawListItems = parsedHtml.toString().split("\n");
ArrayList cleanedList = new ArrayList();
- for (String rawListItem : rawListItems)
- {
- if (rawListItem.trim().length() > 0)
- {
+ for (String rawListItem : rawListItems) {
+ if (rawListItem.trim().length() > 0) {
addToCleanedList(cleanedList, rawListItem);
}
}
@@ -57,30 +53,21 @@ public class AccessibleEmailContentActivity extends ListActivity
setListAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, listItems));
}
- private void addToCleanedList(ArrayList cleanedList, String line)
- {
- if (line.length() < 80)
- {
+ private void addToCleanedList(ArrayList cleanedList, String line) {
+ if (line.length() < 80) {
cleanedList.add(line);
- }
- else
- {
- while (line.length() > 80)
- {
+ } else {
+ while (line.length() > 80) {
int cutPoint = line.indexOf(" ", 80);
- if ((cutPoint > 0) && (cutPoint < line.length()))
- {
+ if ((cutPoint > 0) && (cutPoint < line.length())) {
cleanedList.add(line.substring(0, cutPoint));
line = line.substring(cutPoint).trim();
- }
- else
- {
+ } else {
cleanedList.add(line);
line = "";
}
}
- if (line.length() > 0)
- {
+ if (line.length() > 0) {
cleanedList.add(line);
}
}
diff --git a/src/com/fsck/k9/activity/Accounts.java b/src/com/fsck/k9/activity/Accounts.java
index 43396a848..75f9f161a 100644
--- a/src/com/fsck/k9/activity/Accounts.java
+++ b/src/com/fsck/k9/activity/Accounts.java
@@ -32,8 +32,7 @@ import com.fsck.k9.view.ColorChip;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
-public class Accounts extends K9ListActivity implements OnItemClickListener, OnClickListener
-{
+public class Accounts extends K9ListActivity implements OnItemClickListener, OnClickListener {
/**
* Immutable empty {@link BaseAccount} array
@@ -61,45 +60,33 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
private SearchAccount integratedInboxAccount = null;
private FontSizes mFontSizes = K9.getFontSizes();
- class AccountsHandler extends Handler
- {
- private void setViewTitle()
- {
+ class AccountsHandler extends Handler {
+ private void setViewTitle() {
String dispString = mListener.formatHeader(Accounts.this, getString(R.string.accounts_title), mUnreadMessageCount, getTimeFormat());
setTitle(dispString);
}
- public void refreshTitle()
- {
- runOnUiThread(new Runnable()
- {
- public void run()
- {
+ public void refreshTitle() {
+ runOnUiThread(new Runnable() {
+ public void run() {
setViewTitle();
}
});
}
- public void dataChanged()
- {
- runOnUiThread(new Runnable()
- {
- public void run()
- {
- if (mAdapter != null)
- {
+ public void dataChanged() {
+ runOnUiThread(new Runnable() {
+ public void run() {
+ if (mAdapter != null) {
mAdapter.notifyDataSetChanged();
}
}
});
}
- public void workingAccount(final Account account, final int res)
- {
- runOnUiThread(new Runnable()
- {
- public void run()
- {
+ public void workingAccount(final Account account, final int res) {
+ runOnUiThread(new Runnable() {
+ public void run() {
String toastText = getString(res, account.getDescription());
Toast toast = Toast.makeText(getApplication(), toastText, Toast.LENGTH_SHORT);
@@ -108,15 +95,11 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
});
}
- public void accountSizeChanged(final Account account, final long oldSize, final long newSize)
- {
- runOnUiThread(new Runnable()
- {
- public void run()
- {
+ public void accountSizeChanged(final Account account, final long oldSize, final long newSize) {
+ runOnUiThread(new Runnable() {
+ public void run() {
AccountStats stats = accountStats.get(account.getUuid());
- if (newSize != -1 && stats != null && K9.measureAccounts())
- {
+ if (newSize != -1 && stats != null && K9.measureAccounts()) {
stats.size = newSize;
}
String toastText = getString(R.string.account_size_changed, account.getDescription(),
@@ -124,94 +107,71 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
Toast toast = Toast.makeText(getApplication(), toastText, Toast.LENGTH_LONG);
toast.show();
- if (mAdapter != null)
- {
+ if (mAdapter != null) {
mAdapter.notifyDataSetChanged();
}
}
});
}
- public void progress(final boolean progress)
- {
- runOnUiThread(new Runnable()
- {
- public void run()
- {
+ public void progress(final boolean progress) {
+ runOnUiThread(new Runnable() {
+ public void run() {
setProgressBarIndeterminateVisibility(progress);
}
});
}
- public void progress(final int progress)
- {
- runOnUiThread(new Runnable()
- {
- public void run()
- {
+ public void progress(final int progress) {
+ runOnUiThread(new Runnable() {
+ public void run() {
getWindow().setFeatureInt(Window.FEATURE_PROGRESS, progress);
}
});
}
}
- ActivityListener mListener = new ActivityListener()
- {
+ ActivityListener mListener = new ActivityListener() {
@Override
- public void folderStatusChanged(Account account, String folderName, int unreadMessageCount)
- {
- try
- {
+ public void folderStatusChanged(Account account, String folderName, int unreadMessageCount) {
+ try {
AccountStats stats = account.getStats(Accounts.this);
- if (stats == null)
- {
+ if (stats == null) {
Log.w(K9.LOG_TAG, "Unable to get account stats");
- }
- else
- {
+ } else {
accountStatusChanged(account, stats);
}
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
Log.e(K9.LOG_TAG, "Unable to get account stats", e);
}
}
@Override
- public void accountStatusChanged(BaseAccount account, AccountStats stats)
- {
+ public void accountStatusChanged(BaseAccount account, AccountStats stats) {
AccountStats oldStats = accountStats.get(account.getUuid());
int oldUnreadMessageCount = 0;
- if (oldStats != null)
- {
+ if (oldStats != null) {
oldUnreadMessageCount = oldStats.unreadMessageCount;
}
- if (stats == null)
- {
+ if (stats == null) {
stats = new AccountStats(); // empty stats for unavailable accounts
}
accountStats.put(account.getUuid(), stats);
- if (account instanceof Account)
- {
+ if (account instanceof Account) {
mUnreadMessageCount += stats.unreadMessageCount - oldUnreadMessageCount;
}
mHandler.dataChanged();
pendingWork.remove(account);
- if (pendingWork.isEmpty())
- {
+ if (pendingWork.isEmpty()) {
mHandler.progress(Window.PROGRESS_END);
mHandler.refreshTitle();
- }
- else
- {
+ } else {
int level = (Window.PROGRESS_END / mAdapter.getCount()) * (mAdapter.getCount() - pendingWork.size()) ;
mHandler.progress(level);
}
}
@Override
- public void accountSizeChanged(Account account, long oldSize, long newSize)
- {
+ public void accountSizeChanged(Account account, long oldSize, long newSize) {
mHandler.accountSizeChanged(account, oldSize, newSize);
}
@@ -220,8 +180,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
Account account,
String folder,
int totalMessagesInMailbox,
- int numNewMessages)
- {
+ int numNewMessages) {
super.synchronizeMailboxFinished(account, folder, totalMessagesInMailbox, numNewMessages);
MessagingController.getInstance(getApplication()).getAccountStats(Accounts.this, account, mListener);
@@ -231,24 +190,21 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
}
@Override
- public void synchronizeMailboxStarted(Account account, String folder)
- {
+ public void synchronizeMailboxStarted(Account account, String folder) {
super.synchronizeMailboxStarted(account, folder);
mHandler.progress(true);
mHandler.refreshTitle();
}
@Override
- public void synchronizeMailboxProgress(Account account, String folder, int completed, int total)
- {
+ public void synchronizeMailboxProgress(Account account, String folder, int completed, int total) {
super.synchronizeMailboxProgress(account, folder, completed, total);
mHandler.refreshTitle();
}
@Override
public void synchronizeMailboxFailed(Account account, String folder,
- String message)
- {
+ String message) {
super.synchronizeMailboxFailed(account, folder, message);
mHandler.progress(false);
mHandler.refreshTitle();
@@ -256,58 +212,50 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
}
@Override
- public void sendPendingMessagesStarted(Account account)
- {
+ public void sendPendingMessagesStarted(Account account) {
super.sendPendingMessagesStarted(account);
mHandler.refreshTitle();
}
@Override
- public void sendPendingMessagesCompleted(Account account)
- {
+ public void sendPendingMessagesCompleted(Account account) {
super.sendPendingMessagesCompleted(account);
mHandler.refreshTitle();
}
@Override
- public void sendPendingMessagesFailed(Account account)
- {
+ public void sendPendingMessagesFailed(Account account) {
super.sendPendingMessagesFailed(account);
mHandler.refreshTitle();
}
@Override
- public void pendingCommandsProcessing(Account account)
- {
+ public void pendingCommandsProcessing(Account account) {
super.pendingCommandsProcessing(account);
mHandler.refreshTitle();
}
@Override
- public void pendingCommandsFinished(Account account)
- {
+ public void pendingCommandsFinished(Account account) {
super.pendingCommandsFinished(account);
mHandler.refreshTitle();
}
@Override
- public void pendingCommandStarted(Account account, String commandTitle)
- {
+ public void pendingCommandStarted(Account account, String commandTitle) {
super.pendingCommandStarted(account, commandTitle);
mHandler.refreshTitle();
}
@Override
- public void pendingCommandCompleted(Account account, String commandTitle)
- {
+ public void pendingCommandCompleted(Account account, String commandTitle) {
super.pendingCommandCompleted(account, commandTitle);
mHandler.refreshTitle();
}
@Override
- public void systemStatusChanged()
- {
+ public void systemStatusChanged() {
mHandler.refreshTitle();
}
};
@@ -318,15 +266,13 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
public static final String EXTRA_STARTUP = "startup";
- public static void actionLaunch(Context context)
- {
+ public static void actionLaunch(Context context) {
Intent intent = new Intent(context, Accounts.class);
intent.putExtra(EXTRA_STARTUP, true);
context.startActivity(intent);
}
- public static void listAccounts(Context context)
- {
+ public static void listAccounts(Context context) {
Intent intent = new Intent(context, Accounts.class);
intent.putExtra(EXTRA_STARTUP, false);
context.startActivity(intent);
@@ -334,8 +280,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
@Override
- public void onCreate(Bundle icicle)
- {
+ public void onCreate(Bundle icicle) {
super.onCreate(icicle);
unreadAccount = new SearchAccount(this, false, null, null);
@@ -349,20 +294,14 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
Account[] accounts = Preferences.getPreferences(this).getAccounts();
Intent intent = getIntent();
boolean startup = intent.getBooleanExtra(EXTRA_STARTUP, true);
- if (startup && K9.startIntegratedInbox())
- {
+ if (startup && K9.startIntegratedInbox()) {
onOpenAccount(integratedInboxAccount);
finish();
- }
- else if (startup && accounts.length == 1)
- {
- if (onOpenAccount(accounts[0]))
- {
+ } else if (startup && accounts.length == 1) {
+ if (onOpenAccount(accounts[0])) {
finish();
}
- }
- else
- {
+ } else {
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
requestWindowFeature(Window.FEATURE_PROGRESS);
@@ -374,8 +313,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
findViewById(R.id.next).setOnClickListener(this);
registerForContextMenu(listView);
- if (icicle != null && icicle.containsKey(SELECTED_CONTEXT_ACCOUNT))
- {
+ if (icicle != null && icicle.containsKey(SELECTED_CONTEXT_ACCOUNT)) {
String accountUuid = icicle.getString("selectedContextAccount");
mSelectedContextAccount = Preferences.getPreferences(this).getAccount(accountUuid);
}
@@ -385,32 +323,26 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
}
@SuppressWarnings("unchecked")
- private void restoreAccountStats(Bundle icicle)
- {
- if (icicle != null)
- {
+ private void restoreAccountStats(Bundle icicle) {
+ if (icicle != null) {
Map oldStats = (Map)icicle.get(ACCOUNT_STATS);
- if (oldStats != null)
- {
+ if (oldStats != null) {
accountStats.putAll(oldStats);
}
}
}
@Override
- public void onSaveInstanceState(Bundle outState)
- {
+ public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
- if (mSelectedContextAccount != null)
- {
+ if (mSelectedContextAccount != null) {
outState.putString(SELECTED_CONTEXT_ACCOUNT, mSelectedContextAccount.getUuid());
}
outState.putSerializable(ACCOUNT_STATS, accountStats);
}
@Override
- public void onResume()
- {
+ public void onResume() {
super.onResume();
refresh();
@@ -418,19 +350,16 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
}
@Override
- public void onPause()
- {
+ public void onPause() {
super.onPause();
MessagingController.getInstance(getApplication()).removeListener(mListener);
}
- private void refresh()
- {
+ private void refresh() {
BaseAccount[] accounts = Preferences.getPreferences(this).getAccounts();
List newAccounts = new ArrayList(accounts.length + 4);
- if (accounts.length > 0)
- {
+ if (accounts.length > 0) {
newAccounts.add(integratedInboxAccount);
newAccounts.add(unreadAccount);
}
@@ -439,31 +368,24 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
mAdapter = new AccountsAdapter(newAccounts.toArray(EMPTY_BASE_ACCOUNT_ARRAY));
getListView().setAdapter(mAdapter);
- if (newAccounts.size() > 0)
- {
+ if (newAccounts.size() > 0) {
mHandler.progress(Window.PROGRESS_START);
}
pendingWork.clear();
- for (BaseAccount account : newAccounts)
- {
+ for (BaseAccount account : newAccounts) {
- if (account instanceof Account)
- {
+ if (account instanceof Account) {
pendingWork.put(account, "true");
Account realAccount = (Account)account;
MessagingController.getInstance(getApplication()).getAccountStats(Accounts.this, realAccount, mListener);
- }
- else if (K9.countSearchMessages() && account instanceof SearchAccount)
- {
+ } else if (K9.countSearchMessages() && account instanceof SearchAccount) {
pendingWork.put(account, "true");
final SearchAccount searchAccount = (SearchAccount)account;
- MessagingController.getInstance(getApplication()).searchLocalMessages(searchAccount, null, new MessagingListener()
- {
+ MessagingController.getInstance(getApplication()).searchLocalMessages(searchAccount, null, new MessagingListener() {
@Override
- public void searchStats(AccountStats stats)
- {
+ public void searchStats(AccountStats stats) {
mListener.accountStatusChanged(searchAccount, stats);
}
});
@@ -472,18 +394,15 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
}
- private void onAddNewAccount()
- {
+ private void onAddNewAccount() {
AccountSetupBasics.actionNewAccount(this);
}
- private void onEditAccount(Account account)
- {
+ private void onEditAccount(Account account) {
AccountSettings.actionSettings(this, account);
}
- private void onEditPrefs()
- {
+ private void onEditPrefs() {
Prefs.actionPrefs(this);
}
@@ -493,40 +412,30 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
* all accounts are to be checked. This is handled accordingly in
* MessagingController.checkMail().
*/
- private void onCheckMail(Account account)
- {
+ private void onCheckMail(Account account) {
MessagingController.getInstance(getApplication()).checkMail(this, account, true, true, null);
- if (account == null)
- {
+ if (account == null) {
MessagingController.getInstance(getApplication()).sendPendingMessages(null);
- }
- else
- {
+ } else {
MessagingController.getInstance(getApplication()).sendPendingMessages(account, null);
}
}
- private void onClearCommands(Account account)
- {
+ private void onClearCommands(Account account) {
MessagingController.getInstance(getApplication()).clearAllPending(account);
}
- private void onEmptyTrash(Account account)
- {
+ private void onEmptyTrash(Account account) {
MessagingController.getInstance(getApplication()).emptyTrash(account, null);
}
- private void onCompose()
- {
+ private void onCompose() {
Account defaultAccount = Preferences.getPreferences(this).getDefaultAccount();
- if (defaultAccount != null)
- {
+ if (defaultAccount != null) {
MessageCompose.actionCompose(this, defaultAccount);
- }
- else
- {
+ } else {
onAddNewAccount();
}
}
@@ -537,108 +446,86 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
* @param account the account to open ({@link SearchAccount} or {@link Account})
* @return false if unsuccessfull
*/
- private boolean onOpenAccount(BaseAccount account)
- {
- if (account instanceof SearchAccount)
- {
+ private boolean onOpenAccount(BaseAccount account) {
+ if (account instanceof SearchAccount) {
SearchAccount searchAccount = (SearchAccount)account;
MessageList.actionHandle(this, searchAccount.getDescription(), searchAccount);
- }
- else
- {
+ } else {
Account realAccount = (Account)account;
- if (!realAccount.isAvailable(this))
- {
+ if (!realAccount.isAvailable(this)) {
Log.i(K9.LOG_TAG, "refusing to open account that is not available");
return false;
}
- if (K9.FOLDER_NONE.equals(realAccount.getAutoExpandFolderName()))
- {
+ if (K9.FOLDER_NONE.equals(realAccount.getAutoExpandFolderName())) {
FolderList.actionHandleAccount(this, realAccount);
- }
- else
- {
+ } else {
MessageList.actionHandleFolder(this, realAccount, realAccount.getAutoExpandFolderName());
}
}
return true;
}
- public void onClick(View view)
- {
- if (view.getId() == R.id.next)
- {
+ public void onClick(View view) {
+ if (view.getId() == R.id.next) {
onAddNewAccount();
}
}
- private void onDeleteAccount(Account account)
- {
+ private void onDeleteAccount(Account account) {
mSelectedContextAccount = account;
showDialog(DIALOG_REMOVE_ACCOUNT);
}
@Override
- public Dialog onCreateDialog(int id)
- {
- switch (id)
- {
- case DIALOG_REMOVE_ACCOUNT:
- return createRemoveAccountDialog();
- case DIALOG_CLEAR_ACCOUNT:
- return createClearAccountDialog();
- case DIALOG_RECREATE_ACCOUNT:
- return createRecreateAccountDialog();
+ public Dialog onCreateDialog(int id) {
+ switch (id) {
+ case DIALOG_REMOVE_ACCOUNT:
+ return createRemoveAccountDialog();
+ case DIALOG_CLEAR_ACCOUNT:
+ return createClearAccountDialog();
+ case DIALOG_RECREATE_ACCOUNT:
+ return createRecreateAccountDialog();
}
return super.onCreateDialog(id);
}
@Override
- public void onPrepareDialog(int id, Dialog d)
- {
+ public void onPrepareDialog(int id, Dialog d) {
AlertDialog alert = (AlertDialog) d;
- switch (id)
- {
- case DIALOG_REMOVE_ACCOUNT:
- alert.setMessage(getString(R.string.account_delete_dlg_instructions_fmt,
- mSelectedContextAccount.getDescription()));
- break;
- case DIALOG_CLEAR_ACCOUNT:
- alert.setMessage(getString(R.string.account_clear_dlg_instructions_fmt,
- mSelectedContextAccount.getDescription()));
- break;
- case DIALOG_RECREATE_ACCOUNT:
- alert.setMessage(getString(R.string.account_recreate_dlg_instructions_fmt,
- mSelectedContextAccount.getDescription()));
- break;
+ switch (id) {
+ case DIALOG_REMOVE_ACCOUNT:
+ alert.setMessage(getString(R.string.account_delete_dlg_instructions_fmt,
+ mSelectedContextAccount.getDescription()));
+ break;
+ case DIALOG_CLEAR_ACCOUNT:
+ alert.setMessage(getString(R.string.account_clear_dlg_instructions_fmt,
+ mSelectedContextAccount.getDescription()));
+ break;
+ case DIALOG_RECREATE_ACCOUNT:
+ alert.setMessage(getString(R.string.account_recreate_dlg_instructions_fmt,
+ mSelectedContextAccount.getDescription()));
+ break;
}
super.onPrepareDialog(id, d);
}
- private Dialog createRemoveAccountDialog()
- {
+ private Dialog createRemoveAccountDialog() {
return new AlertDialog.Builder(this)
.setTitle(R.string.account_delete_dlg_title)
.setMessage(getString(R.string.account_delete_dlg_instructions_fmt, mSelectedContextAccount.getDescription()))
- .setPositiveButton(R.string.okay_action, new DialogInterface.OnClickListener()
- {
- public void onClick(DialogInterface dialog, int whichButton)
- {
+ .setPositiveButton(R.string.okay_action, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int whichButton) {
dismissDialog(DIALOG_REMOVE_ACCOUNT);
removeDialog(DIALOG_REMOVE_ACCOUNT);
- if (mSelectedContextAccount instanceof Account)
- {
+ if (mSelectedContextAccount instanceof Account) {
Account realAccount = (Account)mSelectedContextAccount;
- try
- {
+ try {
realAccount.getLocalStore().delete();
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
// Ignore, this may lead to localStores on sd-cards that are currently not inserted to be left
}
MessagingController.getInstance(getApplication()).notifyAccountCancel(Accounts.this, realAccount);
@@ -648,10 +535,8 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
}
}
})
- .setNegativeButton(R.string.cancel_action, new DialogInterface.OnClickListener()
- {
- public void onClick(DialogInterface dialog, int whichButton)
- {
+ .setNegativeButton(R.string.cancel_action, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int whichButton) {
dismissDialog(DIALOG_REMOVE_ACCOUNT);
removeDialog(DIALOG_REMOVE_ACCOUNT);
}
@@ -659,30 +544,24 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
.create();
}
- private Dialog createClearAccountDialog()
- {
+ private Dialog createClearAccountDialog() {
return new AlertDialog.Builder(this)
.setTitle(R.string.account_clear_dlg_title)
.setMessage(getString(R.string.account_clear_dlg_instructions_fmt, mSelectedContextAccount.getDescription()))
- .setPositiveButton(R.string.okay_action, new DialogInterface.OnClickListener()
- {
- public void onClick(DialogInterface dialog, int whichButton)
- {
+ .setPositiveButton(R.string.okay_action, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int whichButton) {
dismissDialog(DIALOG_CLEAR_ACCOUNT);
removeDialog(DIALOG_CLEAR_ACCOUNT);
- if (mSelectedContextAccount instanceof Account)
- {
+ if (mSelectedContextAccount instanceof Account) {
Account realAccount = (Account)mSelectedContextAccount;
mHandler.workingAccount(realAccount, R.string.clearing_account);
MessagingController.getInstance(getApplication()).clear(realAccount, null);
}
}
})
- .setNegativeButton(R.string.cancel_action, new DialogInterface.OnClickListener()
- {
- public void onClick(DialogInterface dialog, int whichButton)
- {
+ .setNegativeButton(R.string.cancel_action, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int whichButton) {
dismissDialog(DIALOG_CLEAR_ACCOUNT);
removeDialog(DIALOG_CLEAR_ACCOUNT);
}
@@ -690,30 +569,24 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
.create();
}
- private Dialog createRecreateAccountDialog()
- {
+ private Dialog createRecreateAccountDialog() {
return new AlertDialog.Builder(this)
.setTitle(R.string.account_recreate_dlg_title)
.setMessage(getString(R.string.account_recreate_dlg_instructions_fmt, mSelectedContextAccount.getDescription()))
- .setPositiveButton(R.string.okay_action, new DialogInterface.OnClickListener()
- {
- public void onClick(DialogInterface dialog, int whichButton)
- {
+ .setPositiveButton(R.string.okay_action, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int whichButton) {
dismissDialog(DIALOG_RECREATE_ACCOUNT);
removeDialog(DIALOG_RECREATE_ACCOUNT);
- if (mSelectedContextAccount instanceof Account)
- {
+ if (mSelectedContextAccount instanceof Account) {
Account realAccount = (Account)mSelectedContextAccount;
mHandler.workingAccount(realAccount, R.string.recreating_account);
MessagingController.getInstance(getApplication()).recreate(realAccount, null);
}
}
})
- .setNegativeButton(R.string.cancel_action, new DialogInterface.OnClickListener()
- {
- public void onClick(DialogInterface dialog, int whichButton)
- {
+ .setNegativeButton(R.string.cancel_action, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int whichButton) {
dismissDialog(DIALOG_RECREATE_ACCOUNT);
removeDialog(DIALOG_RECREATE_ACCOUNT);
}
@@ -722,117 +595,105 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
}
@Override
- public boolean onContextItemSelected(MenuItem item)
- {
+ public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo)item.getMenuInfo();
// submenus don't actually set the menuInfo, so the "advanced"
// submenu wouldn't work.
- if (menuInfo != null)
- {
+ if (menuInfo != null) {
mSelectedContextAccount = (BaseAccount)getListView().getItemAtPosition(menuInfo.position);
}
Account realAccount = null;
- if (mSelectedContextAccount instanceof Account)
- {
+ if (mSelectedContextAccount instanceof Account) {
realAccount = (Account)mSelectedContextAccount;
}
- switch (item.getItemId())
- {
- case R.id.delete_account:
- onDeleteAccount(realAccount);
- break;
- case R.id.edit_account:
- onEditAccount(realAccount);
- break;
- case R.id.open:
- onOpenAccount(mSelectedContextAccount);
- break;
- case R.id.check_mail:
- onCheckMail(realAccount);
- break;
- case R.id.clear_pending:
- onClearCommands(realAccount);
- break;
- case R.id.empty_trash:
- onEmptyTrash(realAccount);
- break;
- case R.id.compact:
- onCompact(realAccount);
- break;
- case R.id.clear:
- onClear(realAccount);
- break;
- case R.id.recreate:
- onRecreate(realAccount);
- break;
+ switch (item.getItemId()) {
+ case R.id.delete_account:
+ onDeleteAccount(realAccount);
+ break;
+ case R.id.edit_account:
+ onEditAccount(realAccount);
+ break;
+ case R.id.open:
+ onOpenAccount(mSelectedContextAccount);
+ break;
+ case R.id.check_mail:
+ onCheckMail(realAccount);
+ break;
+ case R.id.clear_pending:
+ onClearCommands(realAccount);
+ break;
+ case R.id.empty_trash:
+ onEmptyTrash(realAccount);
+ break;
+ case R.id.compact:
+ onCompact(realAccount);
+ break;
+ case R.id.clear:
+ onClear(realAccount);
+ break;
+ case R.id.recreate:
+ onRecreate(realAccount);
+ break;
}
return true;
}
- private void onCompact(Account account)
- {
+ private void onCompact(Account account) {
mHandler.workingAccount(account, R.string.compacting_account);
MessagingController.getInstance(getApplication()).compact(account, null);
}
- private void onClear(Account account)
- {
+ private void onClear(Account account) {
showDialog(DIALOG_CLEAR_ACCOUNT);
}
- private void onRecreate(Account account)
- {
+ private void onRecreate(Account account) {
showDialog(DIALOG_RECREATE_ACCOUNT);
}
- public void onItemClick(AdapterView> parent, View view, int position, long id)
- {
+ public void onItemClick(AdapterView> parent, View view, int position, long id) {
BaseAccount account = (BaseAccount)parent.getItemAtPosition(position);
onOpenAccount(account);
}
@Override
- public boolean onOptionsItemSelected(MenuItem item)
- {
- switch (item.getItemId())
- {
- case R.id.add_new_account:
- onAddNewAccount();
- break;
- case R.id.edit_prefs:
- onEditPrefs();
- break;
- case R.id.check_mail:
- onCheckMail(null);
- break;
- case R.id.compose:
- onCompose();
- break;
- case R.id.about:
- onAbout();
- break;
- case R.id.search:
- onSearchRequested();
- break;
- default:
- return super.onOptionsItemSelected(item);
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.add_new_account:
+ onAddNewAccount();
+ break;
+ case R.id.edit_prefs:
+ onEditPrefs();
+ break;
+ case R.id.check_mail:
+ onCheckMail(null);
+ break;
+ case R.id.compose:
+ onCompose();
+ break;
+ case R.id.about:
+ onAbout();
+ break;
+ case R.id.search:
+ onSearchRequested();
+ break;
+ default:
+ return super.onOptionsItemSelected(item);
}
return true;
}
- private static String[][] USED_LIBRARIES = new String[][]
- {
+ private static String[][] USED_LIBRARIES = new String[][] {
new String[] {"jutf7", "http://jutf7.sourceforge.net/"},
new String[] {"JZlib", "http://www.jcraft.com/jzlib/"},
new String[] {"Commons IO", "http://commons.apache.org/io/"},
new String[] {"Mime4j", "http://james.apache.org/mime4j/"},
};
- private void onAbout()
- {
+ private void onAbout() {
String appName = getString(R.string.app_name);
String year = "2011";
WebView wv = new WebView(this);
@@ -863,8 +724,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
.append("
");
StringBuilder libs = new StringBuilder().append("
");
- for (String[] library : USED_LIBRARIES)
- {
+ for (String[] library : USED_LIBRARIES) {
libs.append("- " + library[0] + "
");
}
libs.append("
");
@@ -881,10 +741,8 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
new AlertDialog.Builder(this)
.setView(wv)
.setCancelable(true)
- .setPositiveButton(R.string.okay_action, new DialogInterface.OnClickListener()
- {
- public void onClick(DialogInterface d, int c)
- {
+ .setPositiveButton(R.string.okay_action, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface d, int c) {
d.dismiss();
}
})
@@ -896,79 +754,62 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
*
* @return String version
*/
- private String getVersionNumber()
- {
+ private String getVersionNumber() {
String version = "?";
- try
- {
+ try {
PackageInfo pi = getPackageManager().getPackageInfo(getPackageName(), 0);
version = pi.versionName;
- }
- catch (PackageManager.NameNotFoundException e)
- {
+ } catch (PackageManager.NameNotFoundException e) {
//Log.e(TAG, "Package name not found", e);
}
return version;
}
- public boolean onItemLongClick(AdapterView> parent, View view, int position, long id)
- {
+ public boolean onItemLongClick(AdapterView> parent, View view, int position, long id) {
return true;
}
@Override
- public boolean onCreateOptionsMenu(Menu menu)
- {
+ public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.accounts_option, menu);
return true;
}
@Override
- public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo)
- {
+ public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle(R.string.accounts_context_menu_title);
getMenuInflater().inflate(R.menu.accounts_context, menu);
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
BaseAccount account = mAdapter.getItem(info.position);
- if (account instanceof SearchAccount)
- {
- for (int i = 0; i < menu.size(); i++)
- {
+ if (account instanceof SearchAccount) {
+ for (int i = 0; i < menu.size(); i++) {
MenuItem item = menu.getItem(i);
- if (item.getItemId() != R.id.open)
- {
+ if (item.getItemId() != R.id.open) {
item.setVisible(false);
}
}
}
}
- class AccountsAdapter extends ArrayAdapter
- {
- public AccountsAdapter(BaseAccount[] accounts)
- {
+ class AccountsAdapter extends ArrayAdapter {
+ public AccountsAdapter(BaseAccount[] accounts) {
super(Accounts.this, 0, accounts);
}
@Override
- public View getView(int position, View convertView, ViewGroup parent)
- {
+ public View getView(int position, View convertView, ViewGroup parent) {
final BaseAccount account = getItem(position);
View view;
- if (convertView != null)
- {
+ if (convertView != null) {
view = convertView;
- }
- else
- {
+ } else {
view = getLayoutInflater().inflate(R.layout.accounts_item, parent, false);
}
AccountViewHolder holder = (AccountViewHolder) view.getTag();
- if (holder == null)
- {
+ if (holder == null) {
holder = new AccountViewHolder();
holder.description = (TextView) view.findViewById(R.id.description);
holder.email = (TextView) view.findViewById(R.id.email);
@@ -1002,35 +843,27 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
holder.description.getBackground().setAlpha(255);
}
*/
- if (stats != null && account instanceof Account && stats.size >= 0)
- {
+ if (stats != null && account instanceof Account && stats.size >= 0) {
holder.email.setText(SizeFormatter.formatSize(Accounts.this, stats.size));
holder.email.setVisibility(View.VISIBLE);
- }
- else
- {
- if (account.getEmail().equals(account.getDescription()))
- {
+ } else {
+ if (account.getEmail().equals(account.getDescription())) {
holder.email.setVisibility(View.GONE);
- }
- else
- {
+ } else {
holder.email.setVisibility(View.VISIBLE);
holder.email.setText(account.getEmail());
}
}
String description = account.getDescription();
- if (description == null || description.length() == 0)
- {
+ if (description == null || description.length() == 0) {
description = account.getEmail();
}
holder.description.setText(description);
Integer unreadMessageCount = null;
- if (stats != null)
- {
+ if (stats != null) {
unreadMessageCount = stats.unreadMessageCount;
holder.newMessageCount.setText(Integer.toString(unreadMessageCount));
holder.newMessageCount.setVisibility(unreadMessageCount > 0 ? View.VISIBLE : View.GONE);
@@ -1041,43 +874,31 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
holder.flaggedMessageCount.setOnClickListener(new AccountClickListener(account, SearchModifier.FLAGGED));
holder.newMessageCount.setOnClickListener(new AccountClickListener(account, SearchModifier.UNREAD));
- holder.activeIcons.setOnClickListener(new OnClickListener()
- {
- public void onClick(View v)
- {
+ holder.activeIcons.setOnClickListener(new OnClickListener() {
+ public void onClick(View v) {
Toast toast = Toast.makeText(getApplication(), getString(R.string.tap_hint), Toast.LENGTH_SHORT);
toast.show();
}
}
);
- }
- else
- {
+ } else {
holder.newMessageCount.setVisibility(View.GONE);
holder.flaggedMessageCount.setVisibility(View.GONE);
}
- if (account instanceof Account)
- {
+ if (account instanceof Account) {
Account realAccount = (Account)account;
holder.chip.setBackgroundDrawable(realAccount.generateColorChip().drawable());
- if (unreadMessageCount == null)
- {
+ if (unreadMessageCount == null) {
holder.chip.getBackground().setAlpha(0);
- }
- else if (unreadMessageCount == 0)
- {
+ } else if (unreadMessageCount == 0) {
holder.chip.getBackground().setAlpha(127);
- }
- else
- {
+ } else {
holder.chip.getBackground().setAlpha(255);
}
- }
- else
- {
+ } else {
holder.chip.setBackgroundDrawable(new ColorChip(0xff999999).drawable());
}
@@ -1085,22 +906,16 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
holder.description.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mFontSizes.getAccountName());
holder.email.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mFontSizes.getAccountDescription());
- if (K9.useCompactLayouts())
- {
+ if (K9.useCompactLayouts()) {
holder.accountsItemLayout.setMinimumHeight(0);
}
- if (account instanceof SearchAccount || K9.useCompactLayouts())
- {
+ if (account instanceof SearchAccount || K9.useCompactLayouts()) {
holder.folders.setVisibility(View.GONE);
- }
- else
- {
+ } else {
holder.folders.setVisibility(View.VISIBLE);
- holder.folders.setOnClickListener(new OnClickListener()
- {
- public void onClick(View v)
- {
+ holder.folders.setOnClickListener(new OnClickListener() {
+ public void onClick(View v) {
FolderList.actionHandleAccount(Accounts.this, (Account)account);
}
@@ -1110,8 +925,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
return view;
}
- class AccountViewHolder
- {
+ class AccountViewHolder {
public TextView description;
public TextView email;
public TextView newMessageCount;
@@ -1122,14 +936,11 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
public LinearLayout accountsItemLayout;
}
}
- private Flag[] combine(Flag[] set1, Flag[] set2)
- {
- if (set1 == null)
- {
+ private Flag[] combine(Flag[] set1, Flag[] set2) {
+ if (set1 == null) {
return set2;
}
- if (set2 == null)
- {
+ if (set2 == null) {
return set1;
}
Set flags = new HashSet();
@@ -1138,66 +949,53 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
return flags.toArray(EMPTY_FLAG_ARRAY);
}
- private class AccountClickListener implements OnClickListener
- {
+ private class AccountClickListener implements OnClickListener {
final BaseAccount account;
final SearchModifier searchModifier;
- AccountClickListener(BaseAccount nAccount, SearchModifier nSearchModifier)
- {
+ AccountClickListener(BaseAccount nAccount, SearchModifier nSearchModifier) {
account = nAccount;
searchModifier = nSearchModifier;
}
@Override
- public void onClick(View v)
- {
+ public void onClick(View v) {
String description = getString(R.string.search_title, account.getDescription(), getString(searchModifier.resId));
- if (account instanceof SearchAccount)
- {
+ if (account instanceof SearchAccount) {
SearchAccount searchAccount = (SearchAccount)account;
MessageList.actionHandle(Accounts.this,
description, "", searchAccount.isIntegrate(),
combine(searchAccount.getRequiredFlags(), searchModifier.requiredFlags),
combine(searchAccount.getForbiddenFlags(), searchModifier.forbiddenFlags));
- }
- else
- {
- SearchSpecification searchSpec = new SearchSpecification()
- {
+ } else {
+ SearchSpecification searchSpec = new SearchSpecification() {
@Override
- public String[] getAccountUuids()
- {
+ public String[] getAccountUuids() {
return new String[] { account.getUuid() };
}
@Override
- public Flag[] getForbiddenFlags()
- {
+ public Flag[] getForbiddenFlags() {
return searchModifier.forbiddenFlags;
}
@Override
- public String getQuery()
- {
+ public String getQuery() {
return "";
}
@Override
- public Flag[] getRequiredFlags()
- {
+ public Flag[] getRequiredFlags() {
return searchModifier.requiredFlags;
}
@Override
- public boolean isIntegrate()
- {
+ public boolean isIntegrate() {
return false;
}
@Override
- public String[] getFolderNames()
- {
+ public String[] getFolderNames() {
return null;
}
diff --git a/src/com/fsck/k9/activity/ActivityListener.java b/src/com/fsck/k9/activity/ActivityListener.java
index 1a1b7354f..e458a251a 100644
--- a/src/com/fsck/k9/activity/ActivityListener.java
+++ b/src/com/fsck/k9/activity/ActivityListener.java
@@ -10,8 +10,7 @@ import com.fsck.k9.R;
import com.fsck.k9.controller.MessagingListener;
import com.fsck.k9.service.MailService;
-public class ActivityListener extends MessagingListener
-{
+public class ActivityListener extends MessagingListener {
private String mLoadingFolderName = null;
private String mLoadingHeaderFolderName = null;
private String mLoadingAccountDescription = null;
@@ -22,61 +21,44 @@ public class ActivityListener extends MessagingListener
private String mProcessingCommandTitle = null;
- public String formatHeader(Context context, String activityPrefix, int unreadMessageCount, DateFormat timeFormat)
- {
+ public String formatHeader(Context context, String activityPrefix, int unreadMessageCount, DateFormat timeFormat) {
String operation = null;
String progress = null;
if (mLoadingAccountDescription != null
|| mSendingAccountDescription != null
|| mLoadingHeaderFolderName != null
- || mProcessingAccountDescription != null)
- {
+ || mProcessingAccountDescription != null) {
progress = (mFolderTotal > 0 ?
context.getString(R.string.folder_progress, mFolderCompleted, mFolderTotal) : "");
- if (mLoadingFolderName != null || mLoadingHeaderFolderName != null)
- {
+ if (mLoadingFolderName != null || mLoadingHeaderFolderName != null) {
String displayName = mLoadingFolderName;
- if (K9.INBOX.equalsIgnoreCase(displayName))
- {
+ if (K9.INBOX.equalsIgnoreCase(displayName)) {
displayName = context.getString(R.string.special_mailbox_name_inbox);
}
- if (mLoadingHeaderFolderName != null)
- {
+ if (mLoadingHeaderFolderName != null) {
operation = context.getString(R.string.status_loading_account_folder_headers, mLoadingAccountDescription, displayName, progress);
- }
- else
- {
+ } else {
operation = context.getString(R.string.status_loading_account_folder, mLoadingAccountDescription, displayName, progress);
}
}
- else if (mSendingAccountDescription != null)
- {
+ else if (mSendingAccountDescription != null) {
operation = context.getString(R.string.status_sending_account, mSendingAccountDescription, progress);
- }
- else if (mProcessingAccountDescription != null)
- {
+ } else if (mProcessingAccountDescription != null) {
operation = context.getString(R.string.status_processing_account, mProcessingAccountDescription,
mProcessingCommandTitle != null ? mProcessingCommandTitle : "",
progress);
}
- }
- else
- {
+ } else {
long nextPollTime = MailService.getNextPollTime();
- if (nextPollTime != -1)
- {
+ if (nextPollTime != -1) {
operation = context.getString(R.string.status_next_poll, timeFormat.format(nextPollTime));
- }
- else if (MailService.isSyncDisabled())
- {
+ } else if (MailService.isSyncDisabled()) {
operation = context.getString(R.string.status_syncing_off);
- }
- else
- {
+ } else {
operation = "";
}
}
@@ -93,15 +75,13 @@ public class ActivityListener extends MessagingListener
Account account,
String folder,
int totalMessagesInMailbox,
- int numNewMessages)
- {
+ int numNewMessages) {
mLoadingAccountDescription = null;
mLoadingFolderName = null;
}
@Override
- public void synchronizeMailboxStarted(Account account, String folder)
- {
+ public void synchronizeMailboxStarted(Account account, String folder) {
mLoadingAccountDescription = account.getDescription();
mLoadingFolderName = folder;
mFolderCompleted = 0;
@@ -110,23 +90,20 @@ public class ActivityListener extends MessagingListener
@Override
- public void synchronizeMailboxHeadersStarted(Account account, String folder)
- {
+ public void synchronizeMailboxHeadersStarted(Account account, String folder) {
mLoadingHeaderFolderName = folder;
}
@Override
- public void synchronizeMailboxHeadersProgress(Account account, String folder, int completed, int total)
- {
+ public void synchronizeMailboxHeadersProgress(Account account, String folder, int completed, int total) {
mFolderCompleted = completed;
mFolderTotal = total;
}
@Override
public void synchronizeMailboxHeadersFinished(Account account, String folder,
- int total, int completed)
- {
+ int total, int completed) {
mLoadingHeaderFolderName = null;
mFolderCompleted = 0;
mFolderTotal = 0;
@@ -134,72 +111,61 @@ public class ActivityListener extends MessagingListener
@Override
- public void synchronizeMailboxProgress(Account account, String folder, int completed, int total)
- {
+ public void synchronizeMailboxProgress(Account account, String folder, int completed, int total) {
mFolderCompleted = completed;
mFolderTotal = total;
}
@Override
public void synchronizeMailboxFailed(Account account, String folder,
- String message)
- {
+ String message) {
mLoadingAccountDescription = null;
mLoadingFolderName = null;
}
@Override
- public void sendPendingMessagesStarted(Account account)
- {
+ public void sendPendingMessagesStarted(Account account) {
mSendingAccountDescription = account.getDescription();
}
@Override
- public void sendPendingMessagesCompleted(Account account)
- {
+ public void sendPendingMessagesCompleted(Account account) {
mSendingAccountDescription = null;
}
@Override
- public void sendPendingMessagesFailed(Account account)
- {
+ public void sendPendingMessagesFailed(Account account) {
mSendingAccountDescription = null;
}
@Override
- public void pendingCommandsProcessing(Account account)
- {
+ public void pendingCommandsProcessing(Account account) {
mProcessingAccountDescription = account.getDescription();
mFolderCompleted = 0;
mFolderTotal = 0;
}
@Override
- public void pendingCommandsFinished(Account account)
- {
+ public void pendingCommandsFinished(Account account) {
mProcessingAccountDescription = null;
}
@Override
- public void pendingCommandStarted(Account account, String commandTitle)
- {
+ public void pendingCommandStarted(Account account, String commandTitle) {
mProcessingCommandTitle = commandTitle;
}
@Override
- public void pendingCommandCompleted(Account account, String commandTitle)
- {
+ public void pendingCommandCompleted(Account account, String commandTitle) {
mProcessingCommandTitle = null;
}
- public int getFolderCompleted()
- {
+ public int getFolderCompleted() {
return mFolderCompleted;
}
- public int getFolderTotal()
- {
+ public int getFolderTotal() {
return mFolderTotal;
}
diff --git a/src/com/fsck/k9/activity/ChooseAccount.java b/src/com/fsck/k9/activity/ChooseAccount.java
index 75a186432..6b04f6b76 100644
--- a/src/com/fsck/k9/activity/ChooseAccount.java
+++ b/src/com/fsck/k9/activity/ChooseAccount.java
@@ -27,8 +27,7 @@ import java.util.List;
*
* @see K9ExpandableListActivity
*/
-public class ChooseAccount extends K9ExpandableListActivity
-{
+public class ChooseAccount extends K9ExpandableListActivity {
/**
* {@link Intent} extended data name for storing {@link Account#getUuid()
@@ -42,8 +41,7 @@ public class ChooseAccount extends K9ExpandableListActivity
public static final String EXTRA_IDENTITY = ChooseAccount.class.getName() + "_identity";
@Override
- protected void onCreate(final Bundle savedInstanceState)
- {
+ protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
@@ -55,17 +53,14 @@ public class ChooseAccount extends K9ExpandableListActivity
final ExpandableListAdapter adapter = createAdapter();
setListAdapter(adapter);
- expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener()
- {
+ expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,
- int childPosition, long id)
- {
+ int childPosition, long id) {
final Identity identity = (Identity) adapter.getChild(groupPosition, childPosition);
final Account account = (Account) adapter.getGroup(groupPosition);
- if (!account.isAvailable(v.getContext()))
- {
+ if (!account.isAvailable(v.getContext())) {
Log.i(K9.LOG_TAG, "Refusing selection of unavailable account");
return true;
}
@@ -81,15 +76,12 @@ public class ChooseAccount extends K9ExpandableListActivity
final Bundle extras = getIntent().getExtras();
final String uuid = extras.getString(EXTRA_ACCOUNT);
- if (uuid != null)
- {
+ if (uuid != null) {
final Account[] accounts = Preferences.getPreferences(this).getAccounts();
final int length = accounts.length;
- for (int i = 0; i < length; i++)
- {
+ for (int i = 0; i < length; i++) {
final Account account = accounts[i];
- if (uuid.equals(account.getUuid()))
- {
+ if (uuid.equals(account.getUuid())) {
// setSelectedChild() doesn't seem to obey the
// shouldExpandGroup parameter (2.1), manually expanding
// group
@@ -97,16 +89,13 @@ public class ChooseAccount extends K9ExpandableListActivity
final List identities = account.getIdentities();
final Identity identity = (Identity) extras.getSerializable(EXTRA_IDENTITY);
- if (identity == null)
- {
+ if (identity == null) {
expandableListView.setSelectedChild(i, 0, true);
break;
}
- for (int j = 0; j < identities.size(); j++)
- {
+ for (int j = 0; j < identities.size(); j++) {
final Identity loopIdentity = identities.get(j);
- if (identity.equals(loopIdentity))
- {
+ if (identity.equals(loopIdentity)) {
expandableListView.setSelectedChild(i, j, true);
break;
}
@@ -117,8 +106,7 @@ public class ChooseAccount extends K9ExpandableListActivity
}
}
- private ExpandableListAdapter createAdapter()
- {
+ private ExpandableListAdapter createAdapter() {
return new IdentitiesAdapter(this, getLayoutInflater());
}
@@ -131,65 +119,53 @@ public class ChooseAccount extends K9ExpandableListActivity
* Children represent {@link Identity identities} of the parent account
*
*/
- public static class IdentitiesAdapter extends BaseExpandableListAdapter
- {
+ public static class IdentitiesAdapter extends BaseExpandableListAdapter {
private Context mContext;
private LayoutInflater mLayoutInflater;
- public IdentitiesAdapter(final Context context, final LayoutInflater layoutInflater)
- {
+ public IdentitiesAdapter(final Context context, final LayoutInflater layoutInflater) {
mContext = context;
mLayoutInflater = layoutInflater;
}
@Override
- public Object getChild(int groupPosition, int childPosition)
- {
+ public Object getChild(int groupPosition, int childPosition) {
return getAccounts()[groupPosition].getIdentity(childPosition);
}
@Override
- public long getChildId(int groupPosition, int childPosition)
- {
+ public long getChildId(int groupPosition, int childPosition) {
return Integer.valueOf(childPosition).longValue();
}
@Override
- public int getChildrenCount(int groupPosition)
- {
+ public int getChildrenCount(int groupPosition) {
return getAccounts()[groupPosition].getIdentities().size();
}
@Override
- public Object getGroup(int groupPosition)
- {
+ public Object getGroup(int groupPosition) {
return getAccounts()[groupPosition];
}
@Override
- public int getGroupCount()
- {
+ public int getGroupCount() {
return getAccounts().length;
}
@Override
- public long getGroupId(int groupPosition)
- {
+ public long getGroupId(int groupPosition) {
return Integer.valueOf(groupPosition).longValue();
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
- ViewGroup parent)
- {
+ ViewGroup parent) {
final View v;
- if (convertView == null)
- {
+ if (convertView == null) {
v = mLayoutInflater.inflate(R.layout.choose_account_item, parent, false);
- }
- else
- {
+ } else {
v = convertView;
}
@@ -221,18 +197,14 @@ public class ChooseAccount extends K9ExpandableListActivity
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
- View convertView, ViewGroup parent)
- {
+ View convertView, ViewGroup parent) {
final Account account = getAccounts()[groupPosition];
final Identity identity = account.getIdentity(childPosition);
final View v;
- if (convertView == null)
- {
+ if (convertView == null) {
v = mLayoutInflater.inflate(R.layout.choose_identity_item, parent, false);
- }
- else
- {
+ } else {
v = convertView;
}
@@ -250,20 +222,17 @@ public class ChooseAccount extends K9ExpandableListActivity
}
@Override
- public boolean hasStableIds()
- {
+ public boolean hasStableIds() {
// returning false since accounts/identities are mutable
return false;
}
@Override
- public boolean isChildSelectable(int groupPosition, int childPosition)
- {
+ public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
- private Account[] getAccounts()
- {
+ private Account[] getAccounts() {
return Preferences.getPreferences(mContext).getAccounts();
}
}
diff --git a/src/com/fsck/k9/activity/ChooseFolder.java b/src/com/fsck/k9/activity/ChooseFolder.java
index 843e87035..4f1a42866 100644
--- a/src/com/fsck/k9/activity/ChooseFolder.java
+++ b/src/com/fsck/k9/activity/ChooseFolder.java
@@ -24,8 +24,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
-public class ChooseFolder extends K9ListActivity
-{
+public class ChooseFolder extends K9ListActivity {
String mFolder;
String mSelectFolder;
Account mAccount;
@@ -61,8 +60,7 @@ public class ChooseFolder extends K9ListActivity
public static final String EXTRA_SHOW_DISPLAYABLE_ONLY = "com.fsck.k9.ChooseFolder_showDisplayableOnly";
@Override
- public void onCreate(Bundle savedInstanceState)
- {
+ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
@@ -75,30 +73,24 @@ public class ChooseFolder extends K9ListActivity
mMessageReference = (MessageReference)intent.getSerializableExtra(EXTRA_MESSAGE);
mFolder = intent.getStringExtra(EXTRA_CUR_FOLDER);
mSelectFolder = intent.getStringExtra(EXTRA_SEL_FOLDER);
- if (intent.getStringExtra(EXTRA_SHOW_CURRENT) != null)
- {
+ if (intent.getStringExtra(EXTRA_SHOW_CURRENT) != null) {
hideCurrentFolder = false;
}
- if (intent.getStringExtra(EXTRA_SHOW_FOLDER_NONE) != null)
- {
+ if (intent.getStringExtra(EXTRA_SHOW_FOLDER_NONE) != null) {
showOptionNone = true;
}
- if (intent.getStringExtra(EXTRA_SHOW_DISPLAYABLE_ONLY) != null)
- {
+ if (intent.getStringExtra(EXTRA_SHOW_DISPLAYABLE_ONLY) != null) {
showDisplayableOnly = true;
}
if (mFolder == null)
mFolder = "";
- mAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1)
- {
+ mAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1) {
private Filter myFilter = null;
@Override
- public Filter getFilter()
- {
- if (myFilter == null)
- {
+ public Filter getFilter() {
+ if (myFilter == null) {
myFilter = new FolderListFilter(this);
}
return myFilter;
@@ -111,16 +103,13 @@ public class ChooseFolder extends K9ListActivity
MessagingController.getInstance(getApplication()).listFolders(mAccount, false, mListener);
- this.getListView().setOnItemClickListener(new AdapterView.OnItemClickListener()
- {
- public void onItemClick(AdapterView> parent, View view, int position, long id)
- {
+ this.getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ public void onItemClick(AdapterView> parent, View view, int position, long id) {
Intent intent = new Intent();
intent.putExtra(EXTRA_ACCOUNT, mAccount.getUuid());
intent.putExtra(EXTRA_CUR_FOLDER, mFolder);
String destFolderName = (String)((TextView)view).getText();
- if (heldInbox != null && getString(R.string.special_mailbox_name_inbox).equals(destFolderName))
- {
+ if (heldInbox != null && getString(R.string.special_mailbox_name_inbox).equals(destFolderName)) {
destFolderName = heldInbox;
}
intent.putExtra(EXTRA_NEW_FOLDER, destFolderName);
@@ -132,8 +121,7 @@ public class ChooseFolder extends K9ListActivity
}
- class ChooseFolderHandler extends Handler
- {
+ class ChooseFolderHandler extends Handler {
private static final int MSG_PROGRESS = 2;
@@ -141,95 +129,81 @@ public class ChooseFolder extends K9ListActivity
private static final int MSG_SET_SELECTED_FOLDER = 4;
@Override
- public void handleMessage(android.os.Message msg)
- {
- switch (msg.what)
- {
- case MSG_PROGRESS:
- setProgressBarIndeterminateVisibility(msg.arg1 != 0);
- break;
- case MSG_DATA_CHANGED:
- mAdapter.notifyDataSetChanged();
+ public void handleMessage(android.os.Message msg) {
+ switch (msg.what) {
+ case MSG_PROGRESS:
+ setProgressBarIndeterminateVisibility(msg.arg1 != 0);
+ break;
+ case MSG_DATA_CHANGED:
+ mAdapter.notifyDataSetChanged();
- /*
- * Only enable the text filter after the list has been
- * populated to avoid possible race conditions because our
- * FolderListFilter isn't really thread-safe.
- */
- getListView().setTextFilterEnabled(true);
- break;
- case MSG_SET_SELECTED_FOLDER:
- getListView().setSelection(msg.arg1);
- break;
+ /*
+ * Only enable the text filter after the list has been
+ * populated to avoid possible race conditions because our
+ * FolderListFilter isn't really thread-safe.
+ */
+ getListView().setTextFilterEnabled(true);
+ break;
+ case MSG_SET_SELECTED_FOLDER:
+ getListView().setSelection(msg.arg1);
+ break;
}
}
- public void progress(boolean progress)
- {
+ public void progress(boolean progress) {
android.os.Message msg = new android.os.Message();
msg.what = MSG_PROGRESS;
msg.arg1 = progress ? 1 : 0;
sendMessage(msg);
}
- public void setSelectedFolder(int position)
- {
+ public void setSelectedFolder(int position) {
android.os.Message msg = new android.os.Message();
msg.what = MSG_SET_SELECTED_FOLDER;
msg.arg1 = position;
sendMessage(msg);
}
- public void dataChanged()
- {
+ public void dataChanged() {
sendEmptyMessage(MSG_DATA_CHANGED);
}
}
- @Override public boolean onCreateOptionsMenu(Menu menu)
- {
+ @Override public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.folder_select_option, menu);
return true;
}
- @Override public boolean onOptionsItemSelected(MenuItem item)
- {
- switch (item.getItemId())
- {
+ @Override public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
- case R.id.display_1st_class:
- {
- setDisplayMode(FolderMode.FIRST_CLASS);
- return true;
- }
- case R.id.display_1st_and_2nd_class:
- {
- setDisplayMode(FolderMode.FIRST_AND_SECOND_CLASS);
- return true;
- }
- case R.id.display_not_second_class:
- {
- setDisplayMode(FolderMode.NOT_SECOND_CLASS);
- return true;
- }
- case R.id.display_all:
- {
- setDisplayMode(FolderMode.ALL);
- return true;
- }
- default:
- return super.onOptionsItemSelected(item);
+ case R.id.display_1st_class: {
+ setDisplayMode(FolderMode.FIRST_CLASS);
+ return true;
+ }
+ case R.id.display_1st_and_2nd_class: {
+ setDisplayMode(FolderMode.FIRST_AND_SECOND_CLASS);
+ return true;
+ }
+ case R.id.display_not_second_class: {
+ setDisplayMode(FolderMode.NOT_SECOND_CLASS);
+ return true;
+ }
+ case R.id.display_all: {
+ setDisplayMode(FolderMode.ALL);
+ return true;
+ }
+ default:
+ return super.onOptionsItemSelected(item);
}
}
- private void setDisplayMode(FolderMode aMode)
- {
+ private void setDisplayMode(FolderMode aMode) {
mMode = aMode;
// invalidate the current filter as it is working on an inval
- if (myFilter != null)
- {
+ if (myFilter != null) {
myFilter.invalidate();
}
//re-populate the list
@@ -237,59 +211,47 @@ public class ChooseFolder extends K9ListActivity
false, mListener);
}
- private MessagingListener mListener = new MessagingListener()
- {
+ private MessagingListener mListener = new MessagingListener() {
@Override
- public void listFoldersStarted(Account account)
- {
- if (!account.equals(mAccount))
- {
+ public void listFoldersStarted(Account account) {
+ if (!account.equals(mAccount)) {
return;
}
mHandler.progress(true);
}
@Override
- public void listFoldersFailed(Account account, String message)
- {
- if (!account.equals(mAccount))
- {
+ public void listFoldersFailed(Account account, String message) {
+ if (!account.equals(mAccount)) {
return;
}
mHandler.progress(false);
}
@Override
- public void listFoldersFinished(Account account)
- {
- if (!account.equals(mAccount))
- {
+ public void listFoldersFinished(Account account) {
+ if (!account.equals(mAccount)) {
return;
}
mHandler.progress(false);
}
@Override
- public void listFolders(Account account, Folder[] folders)
- {
- if (!account.equals(mAccount))
- {
+ public void listFolders(Account account, Folder[] folders) {
+ if (!account.equals(mAccount)) {
return;
}
Account.FolderMode aMode = mMode;
Preferences prefs = Preferences.getPreferences(getApplication().getApplicationContext());
ArrayList localFolders = new ArrayList();
- for (Folder folder : folders)
- {
+ for (Folder folder : folders) {
String name = folder.getName();
// Inbox needs to be compared case-insensitively
- if (hideCurrentFolder && (name.equals(mFolder) || (K9.INBOX.equalsIgnoreCase(mFolder) && K9.INBOX.equalsIgnoreCase(name))))
- {
+ if (hideCurrentFolder && (name.equals(mFolder) || (K9.INBOX.equalsIgnoreCase(mFolder) && K9.INBOX.equalsIgnoreCase(name)))) {
continue;
}
- try
- {
+ try {
folder.refresh(prefs);
Folder.FolderClass fMode = folder.getDisplayClass();
@@ -297,13 +259,10 @@ public class ChooseFolder extends K9ListActivity
|| (aMode == Account.FolderMode.FIRST_AND_SECOND_CLASS &&
fMode != Folder.FolderClass.FIRST_CLASS &&
fMode != Folder.FolderClass.SECOND_CLASS)
- || (aMode == Account.FolderMode.NOT_SECOND_CLASS && fMode == Folder.FolderClass.SECOND_CLASS))
- {
+ || (aMode == Account.FolderMode.NOT_SECOND_CLASS && fMode == Folder.FolderClass.SECOND_CLASS)) {
continue;
}
- }
- catch (MessagingException me)
- {
+ } catch (MessagingException me) {
Log.e(K9.LOG_TAG, "Couldn't get prefs to check for displayability of folder " + folder.getName(), me);
}
@@ -311,29 +270,22 @@ public class ChooseFolder extends K9ListActivity
}
- if (showOptionNone)
- {
+ if (showOptionNone) {
localFolders.add(K9.FOLDER_NONE);
}
- Collections.sort(localFolders, new Comparator()
- {
- public int compare(String aName, String bName)
- {
- if (K9.FOLDER_NONE.equalsIgnoreCase(aName))
- {
+ Collections.sort(localFolders, new Comparator() {
+ public int compare(String aName, String bName) {
+ if (K9.FOLDER_NONE.equalsIgnoreCase(aName)) {
return -1;
}
- if (K9.FOLDER_NONE.equalsIgnoreCase(bName))
- {
+ if (K9.FOLDER_NONE.equalsIgnoreCase(bName)) {
return 1;
}
- if (K9.INBOX.equalsIgnoreCase(aName))
- {
+ if (K9.INBOX.equalsIgnoreCase(aName)) {
return -1;
}
- if (K9.INBOX.equalsIgnoreCase(bName))
- {
+ if (K9.INBOX.equalsIgnoreCase(bName)) {
return 1;
}
@@ -342,49 +294,36 @@ public class ChooseFolder extends K9ListActivity
});
mAdapter.setNotifyOnChange(false);
int selectedFolder = -1;
- try
- {
+ try {
mAdapter.clear();
int position = 0;
- for (String name : localFolders)
- {
- if (K9.INBOX.equalsIgnoreCase(name))
- {
+ for (String name : localFolders) {
+ if (K9.INBOX.equalsIgnoreCase(name)) {
mAdapter.add(getString(R.string.special_mailbox_name_inbox));
heldInbox = name;
- }
- else if (!K9.ERROR_FOLDER_NAME.equals(name))
- {
+ } else if (!K9.ERROR_FOLDER_NAME.equals(name)) {
mAdapter.add(name);
}
- if (mSelectFolder != null)
- {
+ if (mSelectFolder != null) {
/*
* Never select EXTRA_CUR_FOLDER (mFolder) if EXTRA_SEL_FOLDER
* (mSelectedFolder) was provided.
*/
- if (name.equals(mSelectFolder))
- {
+ if (name.equals(mSelectFolder)) {
selectedFolder = position;
}
- }
- else if (name.equals(mFolder) ||
- (K9.INBOX.equalsIgnoreCase(mFolder) && K9.INBOX.equalsIgnoreCase(name)))
- {
+ } else if (name.equals(mFolder) ||
+ (K9.INBOX.equalsIgnoreCase(mFolder) && K9.INBOX.equalsIgnoreCase(name))) {
selectedFolder = position;
}
position++;
}
- }
- finally
- {
+ } finally {
mAdapter.setNotifyOnChange(true);
- runOnUiThread(new Runnable()
- {
- public void run()
- {
+ runOnUiThread(new Runnable() {
+ public void run() {
// runOnUiThread(
mAdapter.notifyDataSetChanged();
}
@@ -393,8 +332,7 @@ public class ChooseFolder extends K9ListActivity
mHandler.dataChanged();
- if (selectedFolder != -1)
- {
+ if (selectedFolder != -1) {
mHandler.setSelectedFolder(selectedFolder);
}
}
diff --git a/src/com/fsck/k9/activity/ChooseIdentity.java b/src/com/fsck/k9/activity/ChooseIdentity.java
index 7c6336ad8..a769ddfae 100644
--- a/src/com/fsck/k9/activity/ChooseIdentity.java
+++ b/src/com/fsck/k9/activity/ChooseIdentity.java
@@ -15,8 +15,7 @@ import com.fsck.k9.Preferences;
import com.fsck.k9.R;
import java.util.List;
-public class ChooseIdentity extends K9ListActivity
-{
+public class ChooseIdentity extends K9ListActivity {
Account mAccount;
String mUID;
ArrayAdapter adapter;
@@ -27,8 +26,7 @@ public class ChooseIdentity extends K9ListActivity
protected List identities = null;
@Override
- public void onCreate(Bundle savedInstanceState)
- {
+ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
@@ -48,24 +46,20 @@ public class ChooseIdentity extends K9ListActivity
@Override
- public void onResume()
- {
+ public void onResume() {
super.onResume();
refreshView();
}
- protected void refreshView()
- {
+ protected void refreshView() {
adapter.setNotifyOnChange(false);
adapter.clear();
identities = mAccount.getIdentities();
- for (Identity identity : identities)
- {
+ for (Identity identity : identities) {
String description = identity.getDescription();
- if (description == null || description.trim().length() == 0)
- {
+ if (description == null || description.trim().length() == 0) {
description = getString(R.string.message_view_from_format, identity.getName(), identity.getEmail());
}
adapter.add(description);
@@ -74,24 +68,18 @@ public class ChooseIdentity extends K9ListActivity
adapter.notifyDataSetChanged();
}
- protected void setupClickListeners()
- {
- this.getListView().setOnItemClickListener(new AdapterView.OnItemClickListener()
- {
- public void onItemClick(AdapterView> parent, View view, int position, long id)
- {
+ protected void setupClickListeners() {
+ this.getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ public void onItemClick(AdapterView> parent, View view, int position, long id) {
Identity identity = mAccount.getIdentity(position);
String email = identity.getEmail();
- if (email != null && !email.trim().equals(""))
- {
+ if (email != null && !email.trim().equals("")) {
Intent intent = new Intent();
intent.putExtra(EXTRA_IDENTITY, mAccount.getIdentity(position));
setResult(RESULT_OK, intent);
finish();
- }
- else
- {
+ } else {
Toast.makeText(ChooseIdentity.this, getString(R.string.identity_has_no_email),
Toast.LENGTH_LONG).show();
}
diff --git a/src/com/fsck/k9/activity/ColorPickerDialog.java b/src/com/fsck/k9/activity/ColorPickerDialog.java
index d892fe6e5..b5f93edee 100644
--- a/src/com/fsck/k9/activity/ColorPickerDialog.java
+++ b/src/com/fsck/k9/activity/ColorPickerDialog.java
@@ -18,12 +18,10 @@ import android.widget.*;
import com.fsck.k9.view.ColorPickerBox;
-public class ColorPickerDialog
-{
+public class ColorPickerDialog {
private static final String TAG = ColorPickerDialog.class.getSimpleName();
- public interface OnColorChangedListener
- {
+ public interface OnColorChangedListener {
void colorChanged(int color);
}
@@ -45,8 +43,7 @@ public class ColorPickerDialog
float sizeUiDp = 240.f;
float sizeUiPx; // diset di constructor
- public ColorPickerDialog(Context context, OnColorChangedListener listener, int color )
- {
+ public ColorPickerDialog(Context context, OnColorChangedListener listener, int color) {
this.listener = listener;
this.colorOld = color;
this.colorNew = color;
@@ -73,15 +70,12 @@ public class ColorPickerDialog
viewColorOld.setBackgroundColor(color);
viewColorNew.setBackgroundColor(color);
- viewHue.setOnTouchListener(new View.OnTouchListener()
- {
+ viewHue.setOnTouchListener(new View.OnTouchListener() {
@Override
- public boolean onTouch(View v, MotionEvent event)
- {
+ public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_MOVE
|| event.getAction() == MotionEvent.ACTION_DOWN
- || event.getAction() == MotionEvent.ACTION_UP)
- {
+ || event.getAction() == MotionEvent.ACTION_UP) {
float y = event.getY(); // dalam px, bukan dp
if (y < 0.f) y = 0.f;
@@ -101,15 +95,12 @@ public class ColorPickerDialog
return false;
}
});
- viewBox.setOnTouchListener(new View.OnTouchListener()
- {
+ viewBox.setOnTouchListener(new View.OnTouchListener() {
@Override
- public boolean onTouch(View v, MotionEvent event)
- {
+ public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_MOVE
|| event.getAction() == MotionEvent.ACTION_DOWN
- || event.getAction() == MotionEvent.ACTION_UP)
- {
+ || event.getAction() == MotionEvent.ACTION_UP) {
float x = event.getX(); // dalam px, bukan dp
float y = event.getY(); // dalam px, bukan dp
@@ -135,24 +126,18 @@ public class ColorPickerDialog
dialog = new AlertDialog.Builder(context)
.setView(view)
- .setPositiveButton(R.string.okay_action, new DialogInterface.OnClickListener()
- {
+ .setPositiveButton(R.string.okay_action, new DialogInterface.OnClickListener() {
@Override
- public void onClick(DialogInterface dialog, int which)
- {
- if (ColorPickerDialog.this.listener != null)
- {
+ public void onClick(DialogInterface dialog, int which) {
+ if (ColorPickerDialog.this.listener != null) {
ColorPickerDialog.this.listener.colorChanged(colorNew);
}
}
})
- .setNegativeButton(R.string.cancel_action, new DialogInterface.OnClickListener()
- {
+ .setNegativeButton(R.string.cancel_action, new DialogInterface.OnClickListener() {
@Override
- public void onClick(DialogInterface dialog, int which)
- {
- if (ColorPickerDialog.this.listener != null)
- {
+ public void onClick(DialogInterface dialog, int which) {
+ if (ColorPickerDialog.this.listener != null) {
}
}
})
@@ -161,39 +146,35 @@ public class ColorPickerDialog
}
@SuppressWarnings("deprecation")
- protected void placeArrow()
- {
+ protected void placeArrow() {
float y = sizeUiPx - (hue * sizeUiPx / 360.f);
if (y == sizeUiPx) y = 0.f;
AbsoluteLayout.LayoutParams layoutParams = (AbsoluteLayout.LayoutParams) arrow.getLayoutParams();
- layoutParams.y = (int) (y + 4);
+ layoutParams.y = (int)(y + 4);
arrow.setLayoutParams(layoutParams);
}
@SuppressWarnings("deprecation")
- protected void placeSpyglass()
- {
+ protected void placeSpyglass() {
float x = sat * sizeUiPx;
float y = (1.f - val) * sizeUiPx;
AbsoluteLayout.LayoutParams layoutParams = (AbsoluteLayout.LayoutParams) viewSpyglass.getLayoutParams();
- layoutParams.x = (int) (x + 3);
- layoutParams.y = (int) (y + 3);
+ layoutParams.x = (int)(x + 3);
+ layoutParams.y = (int)(y + 3);
viewSpyglass.setLayoutParams(layoutParams);
}
float[] tmp01 = new float[3];
- private int calculateColor()
- {
+ private int calculateColor() {
tmp01[0] = hue;
tmp01[1] = sat;
tmp01[2] = val;
return Color.HSVToColor(tmp01);
}
- public void show()
- {
+ public void show() {
dialog.show();
}
}
diff --git a/src/com/fsck/k9/activity/EditIdentity.java b/src/com/fsck/k9/activity/EditIdentity.java
index 7ff7d5679..6fff570cb 100644
--- a/src/com/fsck/k9/activity/EditIdentity.java
+++ b/src/com/fsck/k9/activity/EditIdentity.java
@@ -13,8 +13,7 @@ import com.fsck.k9.Preferences;
import com.fsck.k9.R;
import java.util.List;
-public class EditIdentity extends K9Activity
-{
+public class EditIdentity extends K9Activity {
public static final String EXTRA_IDENTITY = "com.fsck.k9.EditIdentity_identity";
public static final String EXTRA_IDENTITY_INDEX = "com.fsck.k9.EditIdentity_identity_index";
@@ -33,8 +32,7 @@ public class EditIdentity extends K9Activity
private EditText mReplyTo;
@Override
- public void onCreate(Bundle savedInstanceState)
- {
+ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mIdentity = (Identity)getIntent().getSerializableExtra(EXTRA_IDENTITY);
@@ -42,8 +40,7 @@ public class EditIdentity extends K9Activity
String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
- if (mIdentityIndex == -1)
- {
+ if (mIdentityIndex == -1) {
mIdentity = new Identity();
}
@@ -53,8 +50,7 @@ public class EditIdentity extends K9Activity
* If we're being reloaded we override the original account with the one
* we saved
*/
- if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_IDENTITY))
- {
+ if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_IDENTITY)) {
mIdentity = (Identity)savedInstanceState.getSerializable(EXTRA_IDENTITY);
}
@@ -77,40 +73,30 @@ public class EditIdentity extends K9Activity
mSignatureUse = (CheckBox)findViewById(R.id.signature_use);
mSignatureView = (EditText)findViewById(R.id.signature);
mSignatureUse.setChecked(mIdentity.getSignatureUse());
- mSignatureUse.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
- {
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
- {
- if (isChecked)
- {
+ mSignatureUse.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+ if (isChecked) {
mSignatureLayout.setVisibility(View.VISIBLE);
mSignatureView.setText(mIdentity.getSignature());
- }
- else
- {
+ } else {
mSignatureLayout.setVisibility(View.GONE);
}
}
});
- if (mSignatureUse.isChecked())
- {
+ if (mSignatureUse.isChecked()) {
mSignatureView.setText(mIdentity.getSignature());
- }
- else
- {
+ } else {
mSignatureLayout.setVisibility(View.GONE);
}
}
@Override
- public void onResume()
- {
+ public void onResume() {
super.onResume();
}
- private void saveIdentity()
- {
+ private void saveIdentity() {
mIdentity.setDescription(mDescriptionView.getText().toString());
mIdentity.setEmail(mEmailView.getText().toString());
@@ -119,22 +105,16 @@ public class EditIdentity extends K9Activity
mIdentity.setSignatureUse(mSignatureUse.isChecked());
mIdentity.setSignature(mSignatureView.getText().toString());
- if (mReplyTo.getText().length() == 0)
- {
+ if (mReplyTo.getText().length() == 0) {
mIdentity.setReplyTo(null);
- }
- else
- {
+ } else {
mIdentity.setReplyTo(mReplyTo.getText().toString());
}
List identities = mAccount.getIdentities();
- if (mIdentityIndex == -1)
- {
+ if (mIdentityIndex == -1) {
identities.add(mIdentity);
- }
- else
- {
+ } else {
identities.remove(mIdentityIndex);
identities.add(mIdentityIndex, mIdentity);
}
@@ -145,10 +125,8 @@ public class EditIdentity extends K9Activity
}
@Override
- public boolean onKeyDown(int keyCode, KeyEvent event)
- {
- if (keyCode == KeyEvent.KEYCODE_BACK)
- {
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ if (keyCode == KeyEvent.KEYCODE_BACK) {
saveIdentity();
return true;
}
@@ -156,8 +134,7 @@ public class EditIdentity extends K9Activity
}
@Override
- public void onSaveInstanceState(Bundle outState)
- {
+ public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putSerializable(EXTRA_IDENTITY, mIdentity);
}
diff --git a/src/com/fsck/k9/activity/FolderInfoHolder.java b/src/com/fsck/k9/activity/FolderInfoHolder.java
index e07cf4b67..98d8f6034 100644
--- a/src/com/fsck/k9/activity/FolderInfoHolder.java
+++ b/src/com/fsck/k9/activity/FolderInfoHolder.java
@@ -9,8 +9,7 @@ import com.fsck.k9.R;
import com.fsck.k9.mail.Folder;
import com.fsck.k9.mail.MessagingException;
-public class FolderInfoHolder implements Comparable
-{
+public class FolderInfoHolder implements Comparable {
public String name;
public String displayName;
public long lastChecked;
@@ -23,85 +22,66 @@ public class FolderInfoHolder implements Comparable
public boolean pushActive;
@Override
- public boolean equals(Object o)
- {
+ public boolean equals(Object o) {
return this.name.equals(((FolderInfoHolder)o).name);
}
@Override
- public int hashCode()
- {
+ public int hashCode() {
return name.hashCode();
}
- public int compareTo(FolderInfoHolder o)
- {
+ public int compareTo(FolderInfoHolder o) {
String s1 = this.name;
String s2 = o.name;
int ret = s1.compareToIgnoreCase(s2);
- if (ret != 0)
- {
+ if (ret != 0) {
return ret;
- }
- else
- {
+ } else {
return s1.compareTo(s2);
}
}
- private String truncateStatus(String mess)
- {
- if (mess != null && mess.length() > 27)
- {
+ private String truncateStatus(String mess) {
+ if (mess != null && mess.length() > 27) {
mess = mess.substring(0, 27);
}
return mess;
}
// constructor for an empty object for comparisons
- public FolderInfoHolder()
- {
+ public FolderInfoHolder() {
}
- public FolderInfoHolder(Context context, Folder folder, Account account)
- {
- if (context == null)
- {
+ public FolderInfoHolder(Context context, Folder folder, Account account) {
+ if (context == null) {
throw new IllegalArgumentException("null context given");
}
populate(context, folder, account);
}
- public FolderInfoHolder(Context context, Folder folder, Account account, int unreadCount)
- {
+ public FolderInfoHolder(Context context, Folder folder, Account account, int unreadCount) {
populate(context, folder, account, unreadCount);
}
- public void populate(Context context, Folder folder, Account account, int unreadCount)
- {
+ public void populate(Context context, Folder folder, Account account, int unreadCount) {
- try
- {
+ try {
folder.open(Folder.OpenMode.READ_WRITE);
// unreadCount = folder.getUnreadMessageCount();
- }
- catch (MessagingException me)
- {
+ } catch (MessagingException me) {
Log.e(K9.LOG_TAG, "Folder.getUnreadMessageCount() failed", me);
}
- populate(context,folder,account);
+ populate(context, folder, account);
this.unreadMessageCount = unreadCount;
- try
- {
+ try {
this.flaggedMessageCount = folder.getFlaggedMessageCount();
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
Log.e(K9.LOG_TAG, "Unable to get flaggedMessageCount", e);
}
@@ -110,50 +90,40 @@ public class FolderInfoHolder implements Comparable
}
- public void populate(Context context, Folder folder, Account account)
- {
+ public void populate(Context context, Folder folder, Account account) {
this.folder = folder;
this.name = folder.getName();
this.lastChecked = folder.getLastUpdate();
this.status = truncateStatus(folder.getStatus());
- if (this.name.equalsIgnoreCase(K9.INBOX))
- {
+ if (this.name.equalsIgnoreCase(K9.INBOX)) {
this.displayName = context.getString(R.string.special_mailbox_name_inbox);
- }
- else
- {
+ } else {
this.displayName = folder.getName();
}
- if (this.name.equals(account.getOutboxFolderName()))
- {
+ if (this.name.equals(account.getOutboxFolderName())) {
this.displayName = String.format(context.getString(R.string.special_mailbox_name_outbox_fmt), this.name);
}
- if (this.name.equals(account.getDraftsFolderName()))
- {
+ if (this.name.equals(account.getDraftsFolderName())) {
this.displayName = String.format(context.getString(R.string.special_mailbox_name_drafts_fmt), this.name);
}
- if (this.name.equals(account.getTrashFolderName()))
- {
+ if (this.name.equals(account.getTrashFolderName())) {
this.displayName = String.format(context.getString(R.string.special_mailbox_name_trash_fmt), this.name);
}
- if (this.name.equals(account.getSentFolderName()))
- {
+ if (this.name.equals(account.getSentFolderName())) {
this.displayName = String.format(context.getString(R.string.special_mailbox_name_sent_fmt), this.name);
}
- if (this.name.equals(account.getArchiveFolderName()))
- {
+ if (this.name.equals(account.getArchiveFolderName())) {
this.displayName = String.format(context.getString(R.string.special_mailbox_name_archive_fmt), this.name);
}
- if (this.name.equals(account.getSpamFolderName()))
- {
+ if (this.name.equals(account.getSpamFolderName())) {
this.displayName = String.format(context.getString(R.string.special_mailbox_name_spam_fmt), this.name);
}
}
diff --git a/src/com/fsck/k9/activity/FolderList.java b/src/com/fsck/k9/activity/FolderList.java
index 6ef59138d..66d39f5a5 100644
--- a/src/com/fsck/k9/activity/FolderList.java
+++ b/src/com/fsck/k9/activity/FolderList.java
@@ -46,8 +46,7 @@ import java.util.List;
* Activity shows list of the Account's folders
*/
-public class FolderList extends K9ListActivity
-{
+public class FolderList extends K9ListActivity {
private static final int DIALOG_MARK_ALL_AS_READ = 1;
@@ -74,15 +73,11 @@ public class FolderList extends K9ListActivity
private FontSizes mFontSizes = K9.getFontSizes();
private Context context;
- class FolderListHandler extends Handler
- {
+ class FolderListHandler extends Handler {
- public void refreshTitle()
- {
- runOnUiThread(new Runnable()
- {
- public void run()
- {
+ public void refreshTitle() {
+ runOnUiThread(new Runnable() {
+ public void run() {
String dispString = mAdapter.mListener.formatHeader(FolderList.this,
getString(R.string.folder_list_title, mAccount.getDescription()), mUnreadMessageCount, getTimeFormat());
@@ -93,12 +88,9 @@ public class FolderList extends K9ListActivity
}
- public void newFolders(final List newFolders)
- {
- runOnUiThread(new Runnable()
- {
- public void run()
- {
+ public void newFolders(final List newFolders) {
+ runOnUiThread(new Runnable() {
+ public void run() {
mAdapter.mFolders.clear();
mAdapter.mFolders.addAll(newFolders);
mHandler.dataChanged();
@@ -106,12 +98,9 @@ public class FolderList extends K9ListActivity
});
}
- public void workingAccount(final int res)
- {
- runOnUiThread(new Runnable()
- {
- public void run()
- {
+ public void workingAccount(final int res) {
+ runOnUiThread(new Runnable() {
+ public void run() {
String toastText = getString(res, mAccount.getDescription());
Toast toast = Toast.makeText(getApplication(), toastText, Toast.LENGTH_SHORT);
toast.show();
@@ -119,12 +108,9 @@ public class FolderList extends K9ListActivity
});
}
- public void accountSizeChanged(final long oldSize, final long newSize)
- {
- runOnUiThread(new Runnable()
- {
- public void run()
- {
+ public void accountSizeChanged(final long oldSize, final long newSize) {
+ runOnUiThread(new Runnable() {
+ public void run() {
String toastText = getString(R.string.account_size_changed, mAccount.getDescription(), SizeFormatter.formatSize(getApplication(), oldSize), SizeFormatter.formatSize(getApplication(), newSize));
Toast toast = Toast.makeText(getApplication(), toastText, Toast.LENGTH_LONG);
@@ -133,17 +119,13 @@ public class FolderList extends K9ListActivity
});
}
- public void folderLoading(final String folder, final boolean loading)
- {
- runOnUiThread(new Runnable()
- {
- public void run()
- {
+ public void folderLoading(final String folder, final boolean loading) {
+ runOnUiThread(new Runnable() {
+ public void run() {
FolderInfoHolder folderHolder = mAdapter.getFolder(folder);
- if (folderHolder != null)
- {
+ if (folderHolder != null) {
folderHolder.loading = loading;
}
@@ -151,24 +133,18 @@ public class FolderList extends K9ListActivity
});
}
- public void progress(final boolean progress)
- {
- runOnUiThread(new Runnable()
- {
- public void run()
- {
+ public void progress(final boolean progress) {
+ runOnUiThread(new Runnable() {
+ public void run() {
setProgressBarIndeterminateVisibility(progress);
}
});
}
- public void dataChanged()
- {
- runOnUiThread(new Runnable()
- {
- public void run()
- {
+ public void dataChanged() {
+ runOnUiThread(new Runnable() {
+ public void run() {
mAdapter.notifyDataSetChanged();
}
});
@@ -181,19 +157,15 @@ public class FolderList extends K9ListActivity
* queueing up a remote update of the folder.
*/
- private void checkMail(FolderInfoHolder folder)
- {
+ private void checkMail(FolderInfoHolder folder) {
TracingPowerManager pm = TracingPowerManager.getPowerManager(this);
final TracingWakeLock wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "FolderList checkMail");
wakeLock.setReferenceCounted(false);
wakeLock.acquire(K9.WAKE_LOCK_TIMEOUT);
- MessagingListener listener = new MessagingListener()
- {
+ MessagingListener listener = new MessagingListener() {
@Override
- public void synchronizeMailboxFinished(Account account, String folder, int totalMessagesInMailbox, int numNewMessages)
- {
- if (!account.equals(mAccount))
- {
+ public void synchronizeMailboxFinished(Account account, String folder, int totalMessagesInMailbox, int numNewMessages) {
+ if (!account.equals(mAccount)) {
return;
}
wakeLock.release();
@@ -201,10 +173,8 @@ public class FolderList extends K9ListActivity
@Override
public void synchronizeMailboxFailed(Account account, String folder,
- String message)
- {
- if (!account.equals(mAccount))
- {
+ String message) {
+ if (!account.equals(mAccount)) {
return;
}
wakeLock.release();
@@ -214,47 +184,39 @@ public class FolderList extends K9ListActivity
sendMail(mAccount);
}
- public static Intent actionHandleAccountIntent(Context context, Account account)
- {
+ public static Intent actionHandleAccountIntent(Context context, Account account) {
return actionHandleAccountIntent(context, account, null, false);
}
- public static Intent actionHandleAccountIntent(Context context, Account account, String initialFolder)
- {
+ public static Intent actionHandleAccountIntent(Context context, Account account, String initialFolder) {
return actionHandleAccountIntent(context, account, initialFolder, false);
}
- public static Intent actionHandleAccountIntent(Context context, Account account, String initialFolder, boolean fromShortcut)
- {
+ public static Intent actionHandleAccountIntent(Context context, Account account, String initialFolder, boolean fromShortcut) {
Intent intent = new Intent(context, FolderList.class);
intent.putExtra(EXTRA_ACCOUNT, account.getUuid());
- if (initialFolder != null)
- {
+ if (initialFolder != null) {
intent.putExtra(EXTRA_INITIAL_FOLDER, initialFolder);
}
- if (fromShortcut)
- {
+ if (fromShortcut) {
intent.putExtra(EXTRA_FROM_SHORTCUT, true);
}
return intent;
}
- private static void actionHandleAccount(Context context, Account account, String initialFolder)
- {
+ private static void actionHandleAccount(Context context, Account account, String initialFolder) {
Intent intent = actionHandleAccountIntent(context, account, initialFolder);
context.startActivity(intent);
}
- public static void actionHandleAccount(Context context, Account account)
- {
+ public static void actionHandleAccount(Context context, Account account) {
actionHandleAccount(context, account, null);
}
- public static Intent actionHandleNotification(Context context, Account account, String initialFolder)
- {
+ public static Intent actionHandleNotification(Context context, Account account, String initialFolder) {
Intent intent = new Intent(
Intent.ACTION_VIEW,
Uri.parse("email://accounts/" + account.getAccountNumber()),
@@ -264,16 +226,14 @@ public class FolderList extends K9ListActivity
intent.putExtra(EXTRA_ACCOUNT, account.getUuid());
intent.putExtra(EXTRA_FROM_NOTIFICATION, true);
- if (initialFolder != null)
- {
+ if (initialFolder != null) {
intent.putExtra(EXTRA_INITIAL_FOLDER, initialFolder);
}
return intent;
}
@Override
- public void onCreate(Bundle savedInstanceState)
- {
+ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
@@ -283,10 +243,8 @@ public class FolderList extends K9ListActivity
mListView.setLongClickable(true);
mListView.setFastScrollEnabled(true);
mListView.setScrollingCacheEnabled(true);
- mListView.setOnItemClickListener(new OnItemClickListener()
- {
- public void onItemClick(AdapterView> parent, View view, int position, long id)
- {
+ mListView.setOnItemClickListener(new OnItemClickListener() {
+ public void onItemClick(AdapterView> parent, View view, int position, long id) {
onOpenFolder(((FolderInfoHolder)mAdapter.getItem(id)).name);
}
});
@@ -302,8 +260,7 @@ public class FolderList extends K9ListActivity
}
@Override
- public void onNewIntent(Intent intent)
- {
+ public void onNewIntent(Intent intent) {
setIntent(intent); // onNewIntent doesn't autoset our "internal" intent
String initialFolder;
@@ -312,8 +269,7 @@ public class FolderList extends K9ListActivity
String accountUuid = intent.getStringExtra(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
- if (mAccount == null)
- {
+ if (mAccount == null) {
// This shouldn't normally happen. But apparently it does. See issue 2261.
finish();
return;
@@ -321,32 +277,24 @@ public class FolderList extends K9ListActivity
initialFolder = intent.getStringExtra(EXTRA_INITIAL_FOLDER);
boolean fromNotification = intent.getBooleanExtra(EXTRA_FROM_NOTIFICATION, false);
- if (fromNotification && mAccount.goToUnreadMessageSearch())
- {
+ if (fromNotification && mAccount.goToUnreadMessageSearch()) {
MessagingController.getInstance(getApplication()).notifyAccountCancel(this, mAccount);
openUnreadSearch(this, mAccount);
finish();
- }
- else if (initialFolder != null && !K9.FOLDER_NONE.equals(initialFolder))
- {
+ } else if (initialFolder != null && !K9.FOLDER_NONE.equals(initialFolder)) {
onOpenFolder(initialFolder);
finish();
- }
- else if (intent.getBooleanExtra(EXTRA_FROM_SHORTCUT, false) &&
- !K9.FOLDER_NONE.equals(mAccount.getAutoExpandFolderName()))
- {
+ } else if (intent.getBooleanExtra(EXTRA_FROM_SHORTCUT, false) &&
+ !K9.FOLDER_NONE.equals(mAccount.getAutoExpandFolderName())) {
onOpenFolder(mAccount.getAutoExpandFolderName());
finish();
- }
- else
- {
+ } else {
initializeActivityView();
}
}
- private void initializeActivityView()
- {
+ private void initializeActivityView() {
mAdapter = new FolderListAdapter();
restorePreviousData();
@@ -357,24 +305,20 @@ public class FolderList extends K9ListActivity
}
@SuppressWarnings("unchecked")
- private void restorePreviousData()
- {
+ private void restorePreviousData() {
final Object previousData = getLastNonConfigurationInstance();
- if (previousData != null)
- {
+ if (previousData != null) {
mAdapter.mFolders = (ArrayList) previousData;
}
}
- @Override public Object onRetainNonConfigurationInstance()
- {
+ @Override public Object onRetainNonConfigurationInstance() {
return (mAdapter == null) ? null : mAdapter.mFolders;
}
- @Override public void onPause()
- {
+ @Override public void onPause() {
super.onPause();
MessagingController.getInstance(getApplication()).removeListener(mAdapter.mListener);
}
@@ -384,12 +328,10 @@ public class FolderList extends K9ListActivity
* messages for any folder that is currently open. This guarantees that things
* like unread message count and read status are updated.
*/
- @Override public void onResume()
- {
+ @Override public void onResume() {
super.onResume();
- if (!mAccount.isAvailable(this))
- {
+ if (!mAccount.isAvailable(this)) {
Log.i(K9.LOG_TAG, "account unavaliabale, not showing folder-list but account-list");
startActivity(new Intent(this, Accounts.class));
finish();
@@ -409,25 +351,20 @@ public class FolderList extends K9ListActivity
@Override
- public void onBackPressed()
- {
+ public void onBackPressed() {
// This will be called either automatically for you on 2.0
// or later, or by the code above on earlier versions of the
// platform.
- if (K9.manageBack())
- {
+ if (K9.manageBack()) {
onAccounts();
- }
- else
- {
+ } else {
// TODO - when we move to android 2.0, uncomment this instead.
// super.onBackPressed()
finish();
}
}
- @Override public boolean onKeyDown(int keyCode, KeyEvent event)
- {
+ @Override public boolean onKeyDown(int keyCode, KeyEvent event) {
//Shortcuts that work no matter what is selected
if (
@@ -436,8 +373,7 @@ public class FolderList extends K9ListActivity
keyCode == KeyEvent.KEYCODE_BACK
&& event.getRepeatCount() == 0
- && K9.manageBack())
- {
+ && K9.manageBack()) {
// Take care of calling this method on earlier versions of
// the platform where it doesn't exist.
onBackPressed();
@@ -445,129 +381,105 @@ public class FolderList extends K9ListActivity
}
- switch (keyCode)
+ switch (keyCode) {
+ case KeyEvent.KEYCODE_Q:
+ //case KeyEvent.KEYCODE_BACK:
{
- case KeyEvent.KEYCODE_Q:
- //case KeyEvent.KEYCODE_BACK:
- {
- onAccounts();
- return true;
- }
+ onAccounts();
+ return true;
+ }
- case KeyEvent.KEYCODE_S:
- {
- onEditAccount();
- return true;
- }
+ case KeyEvent.KEYCODE_S: {
+ onEditAccount();
+ return true;
+ }
- case KeyEvent.KEYCODE_H:
- {
- Toast toast = Toast.makeText(this, R.string.folder_list_help_key, Toast.LENGTH_LONG);
- toast.show();
- return true;
- }
+ case KeyEvent.KEYCODE_H: {
+ Toast toast = Toast.makeText(this, R.string.folder_list_help_key, Toast.LENGTH_LONG);
+ toast.show();
+ return true;
+ }
- case KeyEvent.KEYCODE_1:
- {
- setDisplayMode(FolderMode.FIRST_CLASS);
- return true;
- }
- case KeyEvent.KEYCODE_2:
- {
- setDisplayMode(FolderMode.FIRST_AND_SECOND_CLASS);
- return true;
- }
- case KeyEvent.KEYCODE_3:
- {
- setDisplayMode(FolderMode.NOT_SECOND_CLASS);
- return true;
- }
- case KeyEvent.KEYCODE_4:
- {
- setDisplayMode(FolderMode.ALL);
- return true;
- }
+ case KeyEvent.KEYCODE_1: {
+ setDisplayMode(FolderMode.FIRST_CLASS);
+ return true;
+ }
+ case KeyEvent.KEYCODE_2: {
+ setDisplayMode(FolderMode.FIRST_AND_SECOND_CLASS);
+ return true;
+ }
+ case KeyEvent.KEYCODE_3: {
+ setDisplayMode(FolderMode.NOT_SECOND_CLASS);
+ return true;
+ }
+ case KeyEvent.KEYCODE_4: {
+ setDisplayMode(FolderMode.ALL);
+ return true;
+ }
}//switch
return super.onKeyDown(keyCode, event);
}//onKeyDown
- private void setDisplayMode(FolderMode newMode)
- {
+ private void setDisplayMode(FolderMode newMode) {
mAccount.setFolderDisplayMode(newMode);
mAccount.save(Preferences.getPreferences(this));
- if (mAccount.getFolderPushMode() != FolderMode.NONE)
- {
+ if (mAccount.getFolderPushMode() != FolderMode.NONE) {
MailService.actionRestartPushers(this, null);
}
onRefresh(false);
}
- private void onRefresh(final boolean forceRemote)
- {
+ private void onRefresh(final boolean forceRemote) {
MessagingController.getInstance(getApplication()).listFolders(mAccount, forceRemote, mAdapter.mListener);
}
- private void onEditPrefs()
- {
+ private void onEditPrefs() {
Prefs.actionPrefs(this);
}
- private void onEditAccount()
- {
+ private void onEditAccount() {
AccountSettings.actionSettings(this, mAccount);
}
- private void onEditFolder(Account account, String folderName)
- {
+ private void onEditFolder(Account account, String folderName) {
FolderSettings.actionSettings(this, account, folderName);
}
- private void onAccounts()
- {
+ private void onAccounts() {
Accounts.listAccounts(this);
finish();
}
- private void onEmptyTrash(final Account account)
- {
+ private void onEmptyTrash(final Account account) {
mHandler.dataChanged();
MessagingController.getInstance(getApplication()).emptyTrash(account, null);
}
- private void onExpunge(final Account account, String folderName)
- {
+ private void onExpunge(final Account account, String folderName) {
MessagingController.getInstance(getApplication()).expunge(account, folderName, null);
}
- private void onClearFolder(Account account, String folderName)
- {
+ private void onClearFolder(Account account, String folderName) {
// There has to be a cheaper way to get at the localFolder object than this
LocalFolder localFolder = null;
- try
- {
- if (account == null || folderName == null || !account.isAvailable(FolderList.this))
- {
+ try {
+ if (account == null || folderName == null || !account.isAvailable(FolderList.this)) {
Log.i(K9.LOG_TAG, "not clear folder of unavailable account");
return;
}
localFolder = account.getLocalStore().getFolder(folderName);
localFolder.open(Folder.OpenMode.READ_WRITE);
localFolder.clearAllMessages();
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
Log.e(K9.LOG_TAG, "Exception while clearing folder", e);
- }
- finally
- {
- if (localFolder != null)
- {
+ } finally {
+ if (localFolder != null) {
localFolder.close();
}
}
@@ -578,147 +490,134 @@ public class FolderList extends K9ListActivity
- private void sendMail(Account account)
- {
+ private void sendMail(Account account) {
MessagingController.getInstance(getApplication()).sendPendingMessages(account, mAdapter.mListener);
}
- @Override public boolean onOptionsItemSelected(MenuItem item)
- {
- switch (item.getItemId())
- {
- case R.id.compose:
- MessageCompose.actionCompose(this, mAccount);
+ @Override public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.compose:
+ MessageCompose.actionCompose(this, mAccount);
- return true;
+ return true;
- case R.id.check_mail:
- MessagingController.getInstance(getApplication()).checkMail(this, mAccount, true, true, mAdapter.mListener);
+ case R.id.check_mail:
+ MessagingController.getInstance(getApplication()).checkMail(this, mAccount, true, true, mAdapter.mListener);
- return true;
+ return true;
- case R.id.send_messages:
- MessagingController.getInstance(getApplication()).sendPendingMessages(mAccount, null);
- return true;
- case R.id.accounts:
- onAccounts();
+ case R.id.send_messages:
+ MessagingController.getInstance(getApplication()).sendPendingMessages(mAccount, null);
+ return true;
+ case R.id.accounts:
+ onAccounts();
- return true;
+ return true;
- case R.id.list_folders:
- onRefresh(REFRESH_REMOTE);
+ case R.id.list_folders:
+ onRefresh(REFRESH_REMOTE);
- return true;
+ return true;
- case R.id.account_settings:
- onEditAccount();
+ case R.id.account_settings:
+ onEditAccount();
- return true;
+ return true;
- case R.id.app_settings:
- onEditPrefs();
+ case R.id.app_settings:
+ onEditPrefs();
- return true;
+ return true;
- case R.id.empty_trash:
- onEmptyTrash(mAccount);
+ case R.id.empty_trash:
+ onEmptyTrash(mAccount);
- return true;
+ return true;
- case R.id.compact:
- onCompact(mAccount);
+ case R.id.compact:
+ onCompact(mAccount);
- return true;
+ return true;
- case R.id.display_1st_class:
- {
- setDisplayMode(FolderMode.FIRST_CLASS);
- return true;
- }
- case R.id.display_1st_and_2nd_class:
- {
- setDisplayMode(FolderMode.FIRST_AND_SECOND_CLASS);
- return true;
- }
- case R.id.display_not_second_class:
- {
- setDisplayMode(FolderMode.NOT_SECOND_CLASS);
- return true;
- }
- case R.id.display_all:
- {
- setDisplayMode(FolderMode.ALL);
- return true;
- }
- default:
- return super.onOptionsItemSelected(item);
+ case R.id.display_1st_class: {
+ setDisplayMode(FolderMode.FIRST_CLASS);
+ return true;
+ }
+ case R.id.display_1st_and_2nd_class: {
+ setDisplayMode(FolderMode.FIRST_AND_SECOND_CLASS);
+ return true;
+ }
+ case R.id.display_not_second_class: {
+ setDisplayMode(FolderMode.NOT_SECOND_CLASS);
+ return true;
+ }
+ case R.id.display_all: {
+ setDisplayMode(FolderMode.ALL);
+ return true;
+ }
+ default:
+ return super.onOptionsItemSelected(item);
}
}
- private void onOpenFolder(String folder)
- {
+ private void onOpenFolder(String folder) {
MessageList.actionHandleFolder(this, mAccount, folder);
- if (K9.manageBack())
- {
+ if (K9.manageBack()) {
finish();
}
}
- private void onCompact(Account account)
- {
+ private void onCompact(Account account) {
mHandler.workingAccount(R.string.compacting_account);
MessagingController.getInstance(getApplication()).compact(account, null);
}
- @Override public boolean onCreateOptionsMenu(Menu menu)
- {
+ @Override public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.folder_list_option, menu);
return true;
}
- @Override public boolean onContextItemSelected(MenuItem item)
- {
+ @Override public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item .getMenuInfo();
FolderInfoHolder folder = (FolderInfoHolder) mAdapter.getItem(info.position);
- switch (item.getItemId())
- {
- case R.id.open_folder:
- onOpenFolder(folder.name);
- break;
+ switch (item.getItemId()) {
+ case R.id.open_folder:
+ onOpenFolder(folder.name);
+ break;
- case R.id.mark_all_as_read:
- onMarkAllAsRead(mAccount, folder.name);
- break;
+ case R.id.mark_all_as_read:
+ onMarkAllAsRead(mAccount, folder.name);
+ break;
- case R.id.send_messages:
- sendMail(mAccount);
+ case R.id.send_messages:
+ sendMail(mAccount);
- break;
+ break;
- case R.id.check_mail:
- checkMail(folder);
+ case R.id.check_mail:
+ checkMail(folder);
- break;
+ break;
- case R.id.folder_settings:
- onEditFolder(mAccount, folder.name);
+ case R.id.folder_settings:
+ onEditFolder(mAccount, folder.name);
- break;
+ break;
- case R.id.empty_trash:
- onEmptyTrash(mAccount);
+ case R.id.empty_trash:
+ onEmptyTrash(mAccount);
- break;
- case R.id.expunge:
- onExpunge(mAccount, folder.name);
+ break;
+ case R.id.expunge:
+ onExpunge(mAccount, folder.name);
- break;
+ break;
- case R.id.clear_local_folder:
- onClearFolder(mAccount,folder.name);
- break;
+ case R.id.clear_local_folder:
+ onClearFolder(mAccount, folder.name);
+ break;
}
return super.onContextItemSelected(item);
@@ -727,55 +626,46 @@ public class FolderList extends K9ListActivity
private FolderInfoHolder mSelectedContextFolder = null;
- private void onMarkAllAsRead(final Account account, final String folder)
- {
+ private void onMarkAllAsRead(final Account account, final String folder) {
mSelectedContextFolder = mAdapter.getFolder(folder);
showDialog(DIALOG_MARK_ALL_AS_READ);
}
@Override
- public Dialog onCreateDialog(int id)
- {
- switch (id)
- {
- case DIALOG_MARK_ALL_AS_READ:
- return createMarkAllAsReadDialog();
+ public Dialog onCreateDialog(int id) {
+ switch (id) {
+ case DIALOG_MARK_ALL_AS_READ:
+ return createMarkAllAsReadDialog();
}
return super.onCreateDialog(id);
}
@Override
- public void onPrepareDialog(int id, Dialog dialog)
- {
- switch (id)
- {
- case DIALOG_MARK_ALL_AS_READ:
- ((AlertDialog)dialog).setMessage(getString(R.string.mark_all_as_read_dlg_instructions_fmt,
- mSelectedContextFolder.displayName));
+ public void onPrepareDialog(int id, Dialog dialog) {
+ switch (id) {
+ case DIALOG_MARK_ALL_AS_READ:
+ ((AlertDialog)dialog).setMessage(getString(R.string.mark_all_as_read_dlg_instructions_fmt,
+ mSelectedContextFolder.displayName));
- break;
+ break;
- default:
- super.onPrepareDialog(id, dialog);
+ default:
+ super.onPrepareDialog(id, dialog);
}
}
- private Dialog createMarkAllAsReadDialog()
- {
+ private Dialog createMarkAllAsReadDialog() {
return new AlertDialog.Builder(this)
.setTitle(R.string.mark_all_as_read_dlg_title)
.setMessage(getString(R.string.mark_all_as_read_dlg_instructions_fmt,
mSelectedContextFolder.displayName))
- .setPositiveButton(R.string.okay_action, new DialogInterface.OnClickListener()
- {
- public void onClick(DialogInterface dialog, int whichButton)
- {
+ .setPositiveButton(R.string.okay_action, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int whichButton) {
dismissDialog(DIALOG_MARK_ALL_AS_READ);
- try
- {
+ try {
MessagingController.getInstance(getApplication()).markAllMessagesRead(mAccount, mSelectedContextFolder.name);
@@ -784,18 +674,14 @@ public class FolderList extends K9ListActivity
mHandler.dataChanged();
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
// Ignore
}
}
})
- .setNegativeButton(R.string.cancel_action, new DialogInterface.OnClickListener()
- {
- public void onClick(DialogInterface dialog, int whichButton)
- {
+ .setNegativeButton(R.string.cancel_action, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int whichButton) {
dismissDialog(DIALOG_MARK_ALL_AS_READ);
}
})
@@ -804,8 +690,7 @@ public class FolderList extends K9ListActivity
}
- @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo)
- {
+ @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
getMenuInflater().inflate(R.menu.folder_context, menu);
@@ -817,70 +702,55 @@ public class FolderList extends K9ListActivity
if (!folder.name.equals(mAccount.getTrashFolderName()))
menu.findItem(R.id.empty_trash).setVisible(false);
- if (folder.name.equals(mAccount.getOutboxFolderName()))
- {
+ if (folder.name.equals(mAccount.getOutboxFolderName())) {
menu.findItem(R.id.check_mail).setVisible(false);
- }
- else
- {
+ } else {
menu.findItem(R.id.send_messages).setVisible(false);
}
- if (K9.ERROR_FOLDER_NAME.equals(folder.name))
- {
+ if (K9.ERROR_FOLDER_NAME.equals(folder.name)) {
menu.findItem(R.id.expunge).setVisible(false);
}
menu.setHeaderTitle(folder.displayName);
}
- class FolderListAdapter extends BaseAdapter
- {
+ class FolderListAdapter extends BaseAdapter {
private ArrayList mFolders = new ArrayList();
- public Object getItem(long position)
- {
+ public Object getItem(long position) {
return getItem((int)position);
}
- public Object getItem(int position)
- {
+ public Object getItem(int position) {
return mFolders.get(position);
}
- public long getItemId(int position)
- {
+ public long getItemId(int position) {
return position ;
}
- public int getCount()
- {
+ public int getCount() {
return mFolders.size();
}
@Override
- public boolean isEnabled(int item)
- {
+ public boolean isEnabled(int item) {
return true;
}
@Override
- public boolean areAllItemsEnabled()
- {
+ public boolean areAllItemsEnabled() {
return true;
}
- private ActivityListener mListener = new ActivityListener()
- {
+ private ActivityListener mListener = new ActivityListener() {
@Override
- public void accountStatusChanged(BaseAccount account, AccountStats stats)
- {
- if (!account.equals(mAccount))
- {
+ public void accountStatusChanged(BaseAccount account, AccountStats stats) {
+ if (!account.equals(mAccount)) {
return;
}
- if (stats == null)
- {
+ if (stats == null) {
return;
}
mUnreadMessageCount = stats.unreadMessageCount;
@@ -888,10 +758,8 @@ public class FolderList extends K9ListActivity
}
@Override
- public void listFoldersStarted(Account account)
- {
- if (!account.equals(mAccount))
- {
+ public void listFoldersStarted(Account account) {
+ if (!account.equals(mAccount)) {
return;
}
@@ -899,26 +767,21 @@ public class FolderList extends K9ListActivity
}
@Override
- public void listFoldersFailed(Account account, String message)
- {
- if (!account.equals(mAccount))
- {
+ public void listFoldersFailed(Account account, String message) {
+ if (!account.equals(mAccount)) {
return;
}
mHandler.progress(false);
- if (Config.LOGV)
- {
+ if (Config.LOGV) {
Log.v(K9.LOG_TAG, "listFoldersFailed " + message);
}
}
@Override
- public void listFoldersFinished(Account account)
- {
- if (!account.equals(mAccount))
- {
+ public void listFoldersFinished(Account account) {
+ if (!account.equals(mAccount)) {
return;
}
@@ -929,10 +792,8 @@ public class FolderList extends K9ListActivity
}
@Override
- public void listFolders(Account account, Folder[] folders)
- {
- if (!account.equals(mAccount))
- {
+ public void listFolders(Account account, Folder[] folders) {
+ if (!account.equals(mAccount)) {
return;
}
@@ -941,10 +802,8 @@ public class FolderList extends K9ListActivity
Account.FolderMode aMode = account.getFolderDisplayMode();
Preferences prefs = Preferences.getPreferences(getApplication().getApplicationContext());
- for (Folder folder : folders)
- {
- try
- {
+ for (Folder folder : folders) {
+ try {
folder.refresh(prefs);
Folder.FolderClass fMode = folder.getDisplayClass();
@@ -953,49 +812,36 @@ public class FolderList extends K9ListActivity
|| (aMode == Account.FolderMode.FIRST_AND_SECOND_CLASS &&
fMode != Folder.FolderClass.FIRST_CLASS &&
fMode != Folder.FolderClass.SECOND_CLASS)
- || (aMode == Account.FolderMode.NOT_SECOND_CLASS && fMode == Folder.FolderClass.SECOND_CLASS))
- {
+ || (aMode == Account.FolderMode.NOT_SECOND_CLASS && fMode == Folder.FolderClass.SECOND_CLASS)) {
continue;
}
- }
- catch (MessagingException me)
- {
+ } catch (MessagingException me) {
Log.e(K9.LOG_TAG, "Couldn't get prefs to check for displayability of folder " + folder.getName(), me);
}
FolderInfoHolder holder = null;
int folderIndex = getFolderIndex(folder.getName());
- if (folderIndex >= 0)
- {
+ if (folderIndex >= 0) {
holder = (FolderInfoHolder) getItem(folderIndex);
}
int unreadMessageCount = 0;
- try
- {
+ try {
unreadMessageCount = folder.getUnreadMessageCount();
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
Log.e(K9.LOG_TAG, "Unable to get unreadMessageCount for " + mAccount.getDescription() + ":"
+ folder.getName());
}
- if (holder == null)
- {
+ if (holder == null) {
holder = new FolderInfoHolder(context, folder, mAccount, unreadMessageCount);
- }
- else
- {
+ } else {
holder.populate(context, folder, mAccount, unreadMessageCount);
}
- if (folder.isInTopGroup())
- {
+ if (folder.isInTopGroup()) {
topFolders.add(holder);
- }
- else
- {
+ } else {
newFolders.add(holder);
}
}
@@ -1008,12 +854,10 @@ public class FolderList extends K9ListActivity
}
@Override
- public void synchronizeMailboxStarted(Account account, String folder)
- {
+ public void synchronizeMailboxStarted(Account account, String folder) {
super.synchronizeMailboxStarted(account, folder);
mHandler.refreshTitle();
- if (!account.equals(mAccount))
- {
+ if (!account.equals(mAccount)) {
return;
}
@@ -1024,8 +868,7 @@ public class FolderList extends K9ListActivity
}
@Override
- public void synchronizeMailboxHeadersStarted(Account account, String folder)
- {
+ public void synchronizeMailboxHeadersStarted(Account account, String folder) {
super.synchronizeMailboxHeadersStarted(account, folder);
mHandler.refreshTitle();
@@ -1033,17 +876,15 @@ public class FolderList extends K9ListActivity
@Override
- public void synchronizeMailboxHeadersProgress(Account account, String folder, int completed, int total)
- {
- super.synchronizeMailboxHeadersProgress(account,folder,completed, total);
+ public void synchronizeMailboxHeadersProgress(Account account, String folder, int completed, int total) {
+ super.synchronizeMailboxHeadersProgress(account, folder, completed, total);
mHandler.refreshTitle();
}
@Override
public void synchronizeMailboxHeadersFinished(Account account, String folder,
- int total, int completed)
- {
- super.synchronizeMailboxHeadersFinished(account,folder, total, completed);
+ int total, int completed) {
+ super.synchronizeMailboxHeadersFinished(account, folder, total, completed);
mHandler.refreshTitle();
}
@@ -1052,19 +893,16 @@ public class FolderList extends K9ListActivity
@Override
- public void synchronizeMailboxProgress(Account account, String folder, int completed, int total)
- {
+ public void synchronizeMailboxProgress(Account account, String folder, int completed, int total) {
super.synchronizeMailboxProgress(account, folder, completed, total);
mHandler.refreshTitle();
}
@Override
- public void synchronizeMailboxFinished(Account account, String folder, int totalMessagesInMailbox, int numNewMessages)
- {
+ public void synchronizeMailboxFinished(Account account, String folder, int totalMessagesInMailbox, int numNewMessages) {
super.synchronizeMailboxFinished(account, folder, totalMessagesInMailbox, numNewMessages);
mHandler.refreshTitle();
- if (!account.equals(mAccount))
- {
+ if (!account.equals(mAccount)) {
return;
}
mHandler.progress(false);
@@ -1075,37 +913,27 @@ public class FolderList extends K9ListActivity
}
- private void refreshFolder(Account account, String folderName)
- {
+ private void refreshFolder(Account account, String folderName) {
// There has to be a cheaper way to get at the localFolder object than this
Folder localFolder = null;
- try
- {
- if (account != null && folderName != null)
- {
- if (!account.isAvailable(FolderList.this))
- {
+ try {
+ if (account != null && folderName != null) {
+ if (!account.isAvailable(FolderList.this)) {
Log.i(K9.LOG_TAG, "not refreshing folder of unavailable account");
return;
}
localFolder = account.getLocalStore().getFolder(folderName);
int unreadMessageCount = localFolder.getUnreadMessageCount();
FolderInfoHolder folderHolder = getFolder(folderName);
- if (folderHolder != null)
- {
+ if (folderHolder != null) {
folderHolder.populate(context, localFolder, mAccount, unreadMessageCount);
mHandler.dataChanged();
}
}
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
Log.e(K9.LOG_TAG, "Exception while populating folder", e);
- }
- finally
- {
- if (localFolder != null)
- {
+ } finally {
+ if (localFolder != null) {
localFolder.close();
}
}
@@ -1114,12 +942,10 @@ public class FolderList extends K9ListActivity
@Override
public void synchronizeMailboxFailed(Account account, String folder,
- String message)
- {
+ String message) {
super.synchronizeMailboxFailed(account, folder, message);
mHandler.refreshTitle();
- if (!account.equals(mAccount))
- {
+ if (!account.equals(mAccount)) {
return;
}
@@ -1133,8 +959,7 @@ public class FolderList extends K9ListActivity
// mHandler.folderStatus(folder, mess);
FolderInfoHolder holder = getFolder(folder);
- if (holder != null)
- {
+ if (holder != null) {
holder.lastChecked = 0;
}
@@ -1143,16 +968,13 @@ public class FolderList extends K9ListActivity
}
@Override
- public void setPushActive(Account account, String folderName, boolean enabled)
- {
- if (!account.equals(mAccount))
- {
+ public void setPushActive(Account account, String folderName, boolean enabled) {
+ if (!account.equals(mAccount)) {
return;
}
FolderInfoHolder holder = getFolder(folderName);
- if (holder != null)
- {
+ if (holder != null) {
holder.pushActive = enabled;
mHandler.dataChanged();
@@ -1162,39 +984,32 @@ public class FolderList extends K9ListActivity
@Override
public void messageDeleted(Account account,
- String folder, Message message)
- {
+ String folder, Message message) {
synchronizeMailboxRemovedMessage(account,
folder, message);
}
@Override
- public void emptyTrashCompleted(Account account)
- {
- if (!account.equals(mAccount))
- {
+ public void emptyTrashCompleted(Account account) {
+ if (!account.equals(mAccount)) {
return;
}
refreshFolder(account, mAccount.getTrashFolderName());
}
@Override
- public void folderStatusChanged(Account account, String folderName, int unreadMessageCount)
- {
- if (!account.equals(mAccount))
- {
+ public void folderStatusChanged(Account account, String folderName, int unreadMessageCount) {
+ if (!account.equals(mAccount)) {
return;
}
refreshFolder(account, folderName);
}
@Override
- public void sendPendingMessagesCompleted(Account account)
- {
+ public void sendPendingMessagesCompleted(Account account) {
super.sendPendingMessagesCompleted(account);
mHandler.refreshTitle();
- if (!account.equals(mAccount))
- {
+ if (!account.equals(mAccount)) {
return;
}
@@ -1204,13 +1019,11 @@ public class FolderList extends K9ListActivity
}
@Override
- public void sendPendingMessagesStarted(Account account)
- {
+ public void sendPendingMessagesStarted(Account account) {
super.sendPendingMessagesStarted(account);
mHandler.refreshTitle();
- if (!account.equals(mAccount))
- {
+ if (!account.equals(mAccount)) {
return;
}
@@ -1219,12 +1032,10 @@ public class FolderList extends K9ListActivity
}
@Override
- public void sendPendingMessagesFailed(Account account)
- {
+ public void sendPendingMessagesFailed(Account account) {
super.sendPendingMessagesFailed(account);
mHandler.refreshTitle();
- if (!account.equals(mAccount))
- {
+ if (!account.equals(mAccount)) {
return;
}
@@ -1233,10 +1044,8 @@ public class FolderList extends K9ListActivity
}
@Override
- public void accountSizeChanged(Account account, long oldSize, long newSize)
- {
- if (!account.equals(mAccount))
- {
+ public void accountSizeChanged(Account account, long oldSize, long newSize) {
+ if (!account.equals(mAccount)) {
return;
}
@@ -1245,95 +1054,77 @@ public class FolderList extends K9ListActivity
}
@Override
- public void pendingCommandsProcessing(Account account)
- {
+ public void pendingCommandsProcessing(Account account) {
super.pendingCommandsProcessing(account);
mHandler.refreshTitle();
}
@Override
- public void pendingCommandsFinished(Account account)
- {
+ public void pendingCommandsFinished(Account account) {
super.pendingCommandsFinished(account);
mHandler.refreshTitle();
}
@Override
- public void pendingCommandStarted(Account account, String commandTitle)
- {
+ public void pendingCommandStarted(Account account, String commandTitle) {
super.pendingCommandStarted(account, commandTitle);
mHandler.refreshTitle();
}
@Override
- public void pendingCommandCompleted(Account account, String commandTitle)
- {
+ public void pendingCommandCompleted(Account account, String commandTitle) {
super.pendingCommandCompleted(account, commandTitle);
mHandler.refreshTitle();
}
@Override
- public void systemStatusChanged()
- {
+ public void systemStatusChanged() {
mHandler.refreshTitle();
}
};
- public int getFolderIndex(String folder)
- {
+ public int getFolderIndex(String folder) {
FolderInfoHolder searchHolder = new FolderInfoHolder();
searchHolder.name = folder;
return mFolders.indexOf(searchHolder);
}
- public FolderInfoHolder getFolder(String folder)
- {
+ public FolderInfoHolder getFolder(String folder) {
FolderInfoHolder holder = null;
int index = getFolderIndex(folder);
- if (index >= 0)
- {
+ if (index >= 0) {
holder = (FolderInfoHolder) getItem(index);
- if (holder != null)
- {
+ if (holder != null) {
return holder;
}
}
return null;
}
- public View getView(int position, View convertView, ViewGroup parent)
- {
- if (position <= getCount())
- {
+ public View getView(int position, View convertView, ViewGroup parent) {
+ if (position <= getCount()) {
return getItemView(position, convertView, parent);
- }
- else
- {
+ } else {
// XXX TODO - should catch an exception here
return null;
}
}
- public View getItemView(int itemPosition, View convertView, ViewGroup parent)
- {
+ public View getItemView(int itemPosition, View convertView, ViewGroup parent) {
FolderInfoHolder folder = (FolderInfoHolder) getItem(itemPosition);
View view;
- if (convertView != null)
- {
+ if (convertView != null) {
view = convertView;
- }
- else
- {
+ } else {
view = mInflater.inflate(R.layout.folder_list_item, parent, false);
}
FolderViewHolder holder = (FolderViewHolder) view.getTag();
- if (holder == null)
- {
+ if (holder == null) {
holder = new FolderViewHolder();
holder.folderName = (TextView) view.findViewById(R.id.folder_name);
holder.newMessageCount = (TextView) view.findViewById(R.id.folder_unread_message_count);
@@ -1347,77 +1138,58 @@ public class FolderList extends K9ListActivity
view.setTag(holder);
}
- if (folder == null)
- {
+ if (folder == null) {
return view;
}
holder.folderName.setText(folder.displayName);
String statusText = "";
- if (folder.loading)
- {
+ if (folder.loading) {
statusText = getString(R.string.status_loading);
- }
- else if (folder.status != null)
- {
+ } else if (folder.status != null) {
statusText = folder.status;
- }
- else if (folder.lastChecked != 0)
- {
+ } else if (folder.lastChecked != 0) {
Date lastCheckedDate = new Date(folder.lastChecked);
- statusText = getTimeFormat().format(lastCheckedDate) + " "+
+ statusText = getTimeFormat().format(lastCheckedDate) + " " +
getDateFormat().format(lastCheckedDate);
}
- if (folder.pushActive)
- {
- statusText = getString(R.string.folder_push_active_symbol) + " "+ statusText;
+ if (folder.pushActive) {
+ statusText = getString(R.string.folder_push_active_symbol) + " " + statusText;
}
- if (statusText != null)
- {
+ if (statusText != null) {
holder.folderStatus.setText(statusText);
holder.folderStatus.setVisibility(View.VISIBLE);
- }
- else
- {
+ } else {
holder.folderStatus.setText(null);
holder.folderStatus.setVisibility(View.GONE);
}
- if (folder.unreadMessageCount != 0)
- {
+ if (folder.unreadMessageCount != 0) {
holder.newMessageCount.setText(Integer
.toString(folder.unreadMessageCount));
holder.newMessageCount.setOnClickListener(new FolderClickListener(mAccount, folder.name, folder.displayName, SearchModifier.UNREAD));
holder.newMessageCount.setVisibility(View.VISIBLE);
- }
- else
- {
+ } else {
holder.newMessageCount.setVisibility(View.GONE);
}
- if (K9.messageListStars() && folder.flaggedMessageCount > 0)
- {
+ if (K9.messageListStars() && folder.flaggedMessageCount > 0) {
holder.flaggedMessageCount.setText(Integer
.toString(folder.flaggedMessageCount));
holder.flaggedMessageCount.setOnClickListener(new FolderClickListener(mAccount, folder.name, folder.displayName, SearchModifier.FLAGGED));
holder.flaggedMessageCount.setVisibility(View.VISIBLE);
- }
- else
- {
+ } else {
holder.flaggedMessageCount.setVisibility(View.GONE);
}
- if (K9.useCompactLayouts() && holder.folderListItemLayout != null)
- {
+ if (K9.useCompactLayouts() && holder.folderListItemLayout != null) {
holder.folderListItemLayout.setMinimumHeight(0);
}
- holder.activeIcons.setOnClickListener(new OnClickListener()
- {
- public void onClick(View v)
- {
+ holder.activeIcons.setOnClickListener(new OnClickListener() {
+ public void onClick(View v) {
Toast toast = Toast.makeText(getApplication(), getString(R.string.tap_hint), Toast.LENGTH_SHORT);
toast.show();
}
@@ -1435,20 +1207,17 @@ public class FolderList extends K9ListActivity
}
@Override
- public boolean hasStableIds()
- {
+ public boolean hasStableIds() {
return false;
}
- public boolean isItemSelectable(int position)
- {
+ public boolean isItemSelectable(int position) {
return true;
}
}
- static class FolderViewHolder
- {
+ static class FolderViewHolder {
public TextView folderName;
public TextView folderStatus;
@@ -1462,62 +1231,52 @@ public class FolderList extends K9ListActivity
public LinearLayout folderListItemLayout;
}
- private class FolderClickListener implements OnClickListener
- {
+ private class FolderClickListener implements OnClickListener {
final BaseAccount account;
final String folderName;
final String displayName;
final SearchModifier searchModifier;
- FolderClickListener(BaseAccount nAccount, String folderName, String displayName, SearchModifier nSearchModifier)
- {
+ FolderClickListener(BaseAccount nAccount, String folderName, String displayName, SearchModifier nSearchModifier) {
account = nAccount;
this.folderName = folderName;
searchModifier = nSearchModifier;
this.displayName = displayName;
}
@Override
- public void onClick(View v)
- {
+ public void onClick(View v) {
String description = getString(R.string.search_title,
getString(R.string.message_list_title, account.getDescription(), displayName),
getString(searchModifier.resId));
- SearchSpecification searchSpec = new SearchSpecification()
- {
+ SearchSpecification searchSpec = new SearchSpecification() {
@Override
- public String[] getAccountUuids()
- {
+ public String[] getAccountUuids() {
return new String[] { account.getUuid() };
}
@Override
- public Flag[] getForbiddenFlags()
- {
+ public Flag[] getForbiddenFlags() {
return searchModifier.forbiddenFlags;
}
@Override
- public String getQuery()
- {
+ public String getQuery() {
return "";
}
@Override
- public Flag[] getRequiredFlags()
- {
+ public Flag[] getRequiredFlags() {
return searchModifier.requiredFlags;
}
@Override
- public boolean isIntegrate()
- {
+ public boolean isIntegrate() {
return false;
}
@Override
- public String[] getFolderNames()
- {
+ public String[] getFolderNames() {
return new String[] { folderName };
}
@@ -1530,45 +1289,37 @@ public class FolderList extends K9ListActivity
private static Flag[] UNREAD_FLAG_ARRAY = { Flag.SEEN };
- private void openUnreadSearch(Context context, final Account account)
- {
+ private void openUnreadSearch(Context context, final Account account) {
String description = getString(R.string.search_title, mAccount.getDescription(), getString(R.string.unread_modifier));
- SearchSpecification searchSpec = new SearchSpecification()
- {
+ SearchSpecification searchSpec = new SearchSpecification() {
//interface has no override @Override
- public String[] getAccountUuids()
- {
+ public String[] getAccountUuids() {
return new String[] { account.getUuid() };
}
//interface has no override @Override
- public Flag[] getForbiddenFlags()
- {
+ public Flag[] getForbiddenFlags() {
return UNREAD_FLAG_ARRAY;
}
//interface has no override @Override
- public String getQuery()
- {
+ public String getQuery() {
return "";
}
@Override
- public Flag[] getRequiredFlags()
- {
+ public Flag[] getRequiredFlags() {
return null;
}
@Override
- public boolean isIntegrate()
- {
+ public boolean isIntegrate() {
return false;
}
@Override
- public String[] getFolderNames()
- {
+ public String[] getFolderNames() {
return null;
}
diff --git a/src/com/fsck/k9/activity/FolderListFilter.java b/src/com/fsck/k9/activity/FolderListFilter.java
index cf248b201..364af8879 100644
--- a/src/com/fsck/k9/activity/FolderListFilter.java
+++ b/src/com/fsck/k9/activity/FolderListFilter.java
@@ -15,8 +15,7 @@ import com.fsck.k9.K9;
*
* @author Marcus@Wolschon.biz
*/
-public class FolderListFilter extends Filter
-{
+public class FolderListFilter extends Filter {
/**
* ArrayAdapter that contains the list of folders displayed in the
* ListView.
@@ -36,8 +35,7 @@ public class FolderListFilter extends Filter
*
* @param folderNames
*/
- public FolderListFilter(final ArrayAdapter folderNames)
- {
+ public FolderListFilter(final ArrayAdapter folderNames) {
this.mFolders = folderNames;
}
@@ -48,30 +46,24 @@ public class FolderListFilter extends Filter
* @see #publishResults(CharSequence, FilterResults)
*/
@Override
- protected FilterResults performFiltering(CharSequence searchTerm)
- {
+ protected FilterResults performFiltering(CharSequence searchTerm) {
FilterResults results = new FilterResults();
// Copy the values from mFolders to mOriginalValues if this is the
// first time this method is called.
- if (mOriginalValues == null)
- {
+ if (mOriginalValues == null) {
int count = mFolders.getCount();
mOriginalValues = new ArrayList(count);
- for (int i = 0; i < count; i++)
- {
+ for (int i = 0; i < count; i++) {
mOriginalValues.add(mFolders.getItem(i));
}
}
- if ((searchTerm == null) || (searchTerm.length() == 0))
- {
+ if ((searchTerm == null) || (searchTerm.length() == 0)) {
ArrayList list = new ArrayList(mOriginalValues);
results.values = list;
results.count = list.size();
- }
- else
- {
+ } else {
final String searchTermString = searchTerm.toString().toLowerCase();
final String[] words = searchTermString.split(" ");
final int wordCount = words.length;
@@ -80,14 +72,11 @@ public class FolderListFilter extends Filter
final ArrayList newValues = new ArrayList();
- for (final T value : values)
- {
+ for (final T value : values) {
final String valueText = value.toString().toLowerCase();
- for (int k = 0; k < wordCount; k++)
- {
- if (valueText.contains(words[k]))
- {
+ for (int k = 0; k < wordCount; k++) {
+ if (valueText.contains(words[k])) {
newValues.add(value);
break;
}
@@ -107,26 +96,20 @@ public class FolderListFilter extends Filter
*/
@SuppressWarnings("unchecked")
@Override
- protected void publishResults(CharSequence constraint, FilterResults results)
- {
+ protected void publishResults(CharSequence constraint, FilterResults results) {
// Don't notify for every change
mFolders.setNotifyOnChange(false);
//noinspection unchecked
final List folders = (List) results.values;
mFolders.clear();
- if (folders != null)
- {
- for (T folder : folders)
- {
- if (folder != null)
- {
+ if (folders != null) {
+ for (T folder : folders) {
+ if (folder != null) {
mFolders.add(folder);
}
}
- }
- else
- {
+ } else {
Log.w(K9.LOG_TAG, "FolderListFilter.publishResults - null search-result ");
}
@@ -134,8 +117,7 @@ public class FolderListFilter extends Filter
mFolders.notifyDataSetChanged();
}
- public void invalidate()
- {
+ public void invalidate() {
mOriginalValues = null;
}
}
diff --git a/src/com/fsck/k9/activity/InsertableHtmlContent.java b/src/com/fsck/k9/activity/InsertableHtmlContent.java
index 76ced9dae..168b90b71 100644
--- a/src/com/fsck/k9/activity/InsertableHtmlContent.java
+++ b/src/com/fsck/k9/activity/InsertableHtmlContent.java
@@ -12,8 +12,7 @@ import java.io.Serializable;
*
* TODO: This container should also have a text part, along with its insertion point. Or maybe a generic InsertableContent and maintain one each for Html and Text?
*/
-class InsertableHtmlContent implements Serializable
-{
+class InsertableHtmlContent implements Serializable {
private static final long serialVersionUID = 2397327034L;
// Default to a headerInsertionPoint at the beginning of the message.
private int headerInsertionPoint = 0;
@@ -28,18 +27,15 @@ class InsertableHtmlContent implements Serializable
/**
* Defines where user content should be inserted, either before or after quoted content.
*/
- public enum InsertionLocation
- {
+ public enum InsertionLocation {
BEFORE_QUOTE, AFTER_QUOTE
}
- public void setHeaderInsertionPoint(int headerInsertionPoint)
- {
+ public void setHeaderInsertionPoint(int headerInsertionPoint) {
this.headerInsertionPoint = headerInsertionPoint;
}
- public void setFooterInsertionPoint(int footerInsertionPoint)
- {
+ public void setFooterInsertionPoint(int footerInsertionPoint) {
this.footerInsertionPoint = footerInsertionPoint;
}
@@ -47,8 +43,7 @@ class InsertableHtmlContent implements Serializable
* Get the quoted content.
* @return Quoted content.
*/
- public String getQuotedContent()
- {
+ public String getQuotedContent() {
return quotedContent.toString();
}
@@ -56,8 +51,7 @@ class InsertableHtmlContent implements Serializable
* Set the quoted content. The insertion point should be set against this content.
* @param content
*/
- public void setQuotedContent(StringBuilder content)
- {
+ public void setQuotedContent(StringBuilder content) {
this.quotedContent = content;
}
@@ -70,8 +64,7 @@ class InsertableHtmlContent implements Serializable
* existing header and quoted content.
* @param content Content to add.
*/
- public void insertIntoQuotedHeader(final String content)
- {
+ public void insertIntoQuotedHeader(final String content) {
quotedContent.insert(headerInsertionPoint, content);
// Update the location of the footer insertion point.
footerInsertionPoint += content.length();
@@ -85,8 +78,7 @@ class InsertableHtmlContent implements Serializable
* existing footer and quoted content.
* @param content Content to add.
*/
- public void insertIntoQuotedFooter(final String content)
- {
+ public void insertIntoQuotedFooter(final String content) {
quotedContent.insert(footerInsertionPoint, content);
// Update the location of the footer insertion point to the end of the inserted content.
footerInsertionPoint += content.length();
@@ -95,8 +87,7 @@ class InsertableHtmlContent implements Serializable
/**
* Remove all quoted content.
*/
- public void clearQuotedContent()
- {
+ public void clearQuotedContent() {
quotedContent.setLength(0);
footerInsertionPoint = 0;
headerInsertionPoint = 0;
@@ -107,8 +98,7 @@ class InsertableHtmlContent implements Serializable
* inserted content buffer.
* @param content
*/
- public void setUserContent(final String content)
- {
+ public void setUserContent(final String content) {
userContent = new StringBuilder(content);
}
@@ -116,8 +106,7 @@ class InsertableHtmlContent implements Serializable
* Configure where user content should be inserted, either before or after the quoted content.
* @param insertionLocation Where to insert user content.
*/
- public void setInsertionLocation(final InsertionLocation insertionLocation)
- {
+ public void setInsertionLocation(final InsertionLocation insertionLocation) {
this.insertionLocation = insertionLocation;
}
@@ -125,14 +114,10 @@ class InsertableHtmlContent implements Serializable
* Fetch the insertion point based upon the quote style.
* @return Insertion point
*/
- public int getInsertionPoint()
- {
- if (insertionLocation == InsertionLocation.BEFORE_QUOTE)
- {
+ public int getInsertionPoint() {
+ if (insertionLocation == InsertionLocation.BEFORE_QUOTE) {
return headerInsertionPoint;
- }
- else
- {
+ } else {
return footerInsertionPoint;
}
}
@@ -142,8 +127,7 @@ class InsertableHtmlContent implements Serializable
* @return Composed string.
*/
@Override
- public String toString()
- {
+ public String toString() {
final int insertionPoint = getInsertionPoint();
// Inserting and deleting was twice as fast as instantiating a new StringBuilder and
// using substring() to build the new pieces.
@@ -156,8 +140,7 @@ class InsertableHtmlContent implements Serializable
* Return debugging information for this container.
* @return Debug string.
*/
- public String toDebugString()
- {
+ public String toDebugString() {
return "InsertableHtmlContent{" +
"headerInsertionPoint=" + headerInsertionPoint +
", footerInsertionPoint=" + footerInsertionPoint +
diff --git a/src/com/fsck/k9/activity/K9Activity.java b/src/com/fsck/k9/activity/K9Activity.java
index f59b63014..3fa72700b 100644
--- a/src/com/fsck/k9/activity/K9Activity.java
+++ b/src/com/fsck/k9/activity/K9Activity.java
@@ -19,23 +19,19 @@ import com.fsck.k9.K9;
import com.fsck.k9.helper.DateFormatter;
-public class K9Activity extends Activity
-{
+public class K9Activity extends Activity {
private GestureDetector gestureDetector;
protected ScrollView mTopView;
@Override
- public void onCreate(Bundle icicle)
- {
+ public void onCreate(Bundle icicle) {
onCreate(icicle, true);
}
- public void onCreate(Bundle icicle, boolean useTheme)
- {
+ public void onCreate(Bundle icicle, boolean useTheme) {
setLanguage(this, K9.getK9Language());
- if (useTheme)
- {
+ if (useTheme) {
setTheme(K9.getK9Theme());
}
super.onCreate(icicle);
@@ -46,20 +42,14 @@ public class K9Activity extends Activity
}
- public static void setLanguage(Context context, String language)
- {
+ public static void setLanguage(Context context, String language) {
Locale locale;
- if (language == null || language.equals(""))
- {
+ if (language == null || language.equals("")) {
locale = Locale.getDefault();
- }
- else if (language.length() == 5 && language.charAt(2) == '_')
- {
+ } else if (language.length() == 5 && language.charAt(2) == '_') {
// language is in the form: en_US
locale = new Locale(language.substring(0, 2), language.substring(3));
- }
- else
- {
+ } else {
locale = new Locale(language);
}
Configuration config = new Configuration();
@@ -69,15 +59,13 @@ public class K9Activity extends Activity
}
@Override
- public boolean dispatchTouchEvent(MotionEvent ev)
- {
+ public boolean dispatchTouchEvent(MotionEvent ev) {
super.dispatchTouchEvent(ev);
return gestureDetector.onTouchEvent(ev);
}
@Override
- public void onResume()
- {
+ public void onResume() {
super.onResume();
setupFormats();
}
@@ -85,43 +73,35 @@ public class K9Activity extends Activity
private java.text.DateFormat mDateFormat;
private java.text.DateFormat mTimeFormat;
- private void setupFormats()
- {
+ private void setupFormats() {
mDateFormat = DateFormatter.getDateFormat(this);
mTimeFormat = android.text.format.DateFormat.getTimeFormat(this); // 12/24 date format
}
- public java.text.DateFormat getTimeFormat()
- {
+ public java.text.DateFormat getTimeFormat() {
return mTimeFormat;
}
- public java.text.DateFormat getDateFormat()
- {
+ public java.text.DateFormat getDateFormat() {
return mDateFormat;
}
- protected void onNext()
- {
+ protected void onNext() {
}
- protected void onPrevious()
- {
+ protected void onPrevious() {
}
- protected Animation inFromRightAnimation()
- {
+ protected Animation inFromRightAnimation() {
return slideAnimation(0.0f, +1.0f);
}
- protected Animation outToLeftAnimation()
- {
+ protected Animation outToLeftAnimation() {
return slideAnimation(0.0f, -1.0f);
}
- private Animation slideAnimation(float right, float left)
- {
+ private Animation slideAnimation(float right, float left) {
Animation slide = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, right, Animation.RELATIVE_TO_PARENT, left,
@@ -133,27 +113,21 @@ public class K9Activity extends Activity
return slide;
}
- class MyGestureDetector extends SimpleOnGestureListener
- {
+ class MyGestureDetector extends SimpleOnGestureListener {
private static final float SWIPE_MIN_DISTANCE_DIP = 130.0f;
private static final float SWIPE_MAX_OFF_PATH_DIP = 250f;
private static final float SWIPE_THRESHOLD_VELOCITY_DIP = 325f;
@Override
- public boolean onDoubleTap(MotionEvent ev)
- {
+ public boolean onDoubleTap(MotionEvent ev) {
super.onDoubleTap(ev);
- if (mTopView != null)
- {
+ if (mTopView != null) {
int height = getResources().getDisplayMetrics().heightPixels;
- if (ev.getRawY() < (height/4))
- {
+ if (ev.getRawY() < (height / 4)) {
mTopView.fullScroll(View.FOCUS_UP);
- }
- else if (ev.getRawY() > (height - height/4))
- {
+ } else if (ev.getRawY() > (height - height / 4)) {
mTopView.fullScroll(View.FOCUS_DOWN);
}
@@ -162,10 +136,8 @@ public class K9Activity extends Activity
}
@Override
- public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
- {
- if (K9.gesturesEnabled())
- {
+ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
+ if (K9.gesturesEnabled()) {
// Convert the dips to pixels
final float mGestureScale = getResources().getDisplayMetrics().density;
int min_distance = (int)(SWIPE_MIN_DISTANCE_DIP * mGestureScale + 0.5f);
@@ -173,22 +145,16 @@ public class K9Activity extends Activity
int max_off_path = (int)(SWIPE_MAX_OFF_PATH_DIP * mGestureScale + 0.5f);
- try
- {
+ try {
if (Math.abs(e1.getY() - e2.getY()) > max_off_path)
return false;
// right to left swipe
- if (e1.getX() - e2.getX() > min_distance && Math.abs(velocityX) > min_velocity)
- {
+ if (e1.getX() - e2.getX() > min_distance && Math.abs(velocityX) > min_velocity) {
onNext();
- }
- else if (e2.getX() - e1.getX() > min_distance && Math.abs(velocityX) > min_velocity)
- {
+ } else if (e2.getX() - e1.getX() > min_distance && Math.abs(velocityX) > min_velocity) {
onPrevious();
}
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
// nothing
}
}
diff --git a/src/com/fsck/k9/activity/K9ExpandableListActivity.java b/src/com/fsck/k9/activity/K9ExpandableListActivity.java
index c5438289a..3e1b509a7 100644
--- a/src/com/fsck/k9/activity/K9ExpandableListActivity.java
+++ b/src/com/fsck/k9/activity/K9ExpandableListActivity.java
@@ -8,12 +8,10 @@ import com.fsck.k9.K9;
/**
* @see ExpandableListActivity
*/
-public class K9ExpandableListActivity extends ExpandableListActivity
-{
+public class K9ExpandableListActivity extends ExpandableListActivity {
@Override
- protected void onCreate(Bundle savedInstanceState)
- {
+ protected void onCreate(Bundle savedInstanceState) {
setTheme(K9.getK9Theme());
super.onCreate(savedInstanceState);
}
diff --git a/src/com/fsck/k9/activity/K9ListActivity.java b/src/com/fsck/k9/activity/K9ListActivity.java
index 4a9d60aea..204182be2 100644
--- a/src/com/fsck/k9/activity/K9ListActivity.java
+++ b/src/com/fsck/k9/activity/K9ListActivity.java
@@ -9,11 +9,9 @@ import android.os.Bundle;
import com.fsck.k9.K9;
import com.fsck.k9.helper.DateFormatter;
-public class K9ListActivity extends ListActivity
-{
+public class K9ListActivity extends ListActivity {
@Override
- public void onCreate(Bundle icicle)
- {
+ public void onCreate(Bundle icicle) {
K9Activity.setLanguage(this, K9.getK9Language());
setTheme(K9.getK9Theme());
super.onCreate(icicle);
@@ -21,8 +19,7 @@ public class K9ListActivity extends ListActivity
}
@Override
- public void onResume()
- {
+ public void onResume() {
super.onResume();
setupFormats();
}
@@ -30,80 +27,64 @@ public class K9ListActivity extends ListActivity
private java.text.DateFormat mDateFormat;
private java.text.DateFormat mTimeFormat;
- private void setupFormats()
- {
+ private void setupFormats() {
mDateFormat = DateFormatter.getDateFormat(this);
mTimeFormat = android.text.format.DateFormat.getTimeFormat(this); // 12/24 date format
}
- public java.text.DateFormat getTimeFormat()
- {
+ public java.text.DateFormat getTimeFormat() {
return mTimeFormat;
}
- public java.text.DateFormat getDateFormat()
- {
+ public java.text.DateFormat getDateFormat() {
return mDateFormat;
}
@Override
- public boolean onKeyDown(int keyCode, KeyEvent event)
- {
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
// Shortcuts that work no matter what is selected
- switch (keyCode)
- {
- case KeyEvent.KEYCODE_VOLUME_UP:
- {
- final ListView listView = getListView();
- if (K9.useVolumeKeysForListNavigationEnabled())
- {
- int currentPosition = listView.getSelectedItemPosition();
- if (currentPosition == AdapterView.INVALID_POSITION || listView.isInTouchMode())
- {
- currentPosition = listView.getFirstVisiblePosition();
- }
- if (currentPosition > 0)
- {
- listView.setSelection(currentPosition - 1);
- }
- return true;
+ switch (keyCode) {
+ case KeyEvent.KEYCODE_VOLUME_UP: {
+ final ListView listView = getListView();
+ if (K9.useVolumeKeysForListNavigationEnabled()) {
+ int currentPosition = listView.getSelectedItemPosition();
+ if (currentPosition == AdapterView.INVALID_POSITION || listView.isInTouchMode()) {
+ currentPosition = listView.getFirstVisiblePosition();
}
+ if (currentPosition > 0) {
+ listView.setSelection(currentPosition - 1);
+ }
+ return true;
}
- case KeyEvent.KEYCODE_VOLUME_DOWN:
- {
- final ListView listView = getListView();
- if (K9.useVolumeKeysForListNavigationEnabled())
- {
- int currentPosition = listView.getSelectedItemPosition();
- if (currentPosition == AdapterView.INVALID_POSITION || listView.isInTouchMode())
- {
- currentPosition = listView.getFirstVisiblePosition();
- }
+ }
+ case KeyEvent.KEYCODE_VOLUME_DOWN: {
+ final ListView listView = getListView();
+ if (K9.useVolumeKeysForListNavigationEnabled()) {
+ int currentPosition = listView.getSelectedItemPosition();
+ if (currentPosition == AdapterView.INVALID_POSITION || listView.isInTouchMode()) {
+ currentPosition = listView.getFirstVisiblePosition();
+ }
- if (currentPosition < listView.getCount())
- {
- listView.setSelection(currentPosition + 1);
- }
- return true;
+ if (currentPosition < listView.getCount()) {
+ listView.setSelection(currentPosition + 1);
}
+ return true;
}
}
+ }
return super.onKeyDown(keyCode, event);
}
@Override
- public boolean onKeyUp(int keyCode, KeyEvent event)
- {
+ public boolean onKeyUp(int keyCode, KeyEvent event) {
// Swallow these events too to avoid the audible notification of a volume change
- if (K9.useVolumeKeysForListNavigationEnabled())
- {
- if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP) || (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN))
- {
+ if (K9.useVolumeKeysForListNavigationEnabled()) {
+ if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP) || (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) {
if (K9.DEBUG)
Log.v(K9.LOG_TAG, "Swallowed key up.");
return true;
}
}
- return super.onKeyUp(keyCode,event);
+ return super.onKeyUp(keyCode, event);
}
}
diff --git a/src/com/fsck/k9/activity/K9PreferenceActivity.java b/src/com/fsck/k9/activity/K9PreferenceActivity.java
index 98deec3fe..fff69b028 100644
--- a/src/com/fsck/k9/activity/K9PreferenceActivity.java
+++ b/src/com/fsck/k9/activity/K9PreferenceActivity.java
@@ -7,11 +7,9 @@ import android.preference.ListPreference;
import android.preference.Preference;
-public class K9PreferenceActivity extends PreferenceActivity
-{
+public class K9PreferenceActivity extends PreferenceActivity {
@Override
- public void onCreate(Bundle icicle)
- {
+ public void onCreate(Bundle icicle) {
K9Activity.setLanguage(this, K9.getK9Language());
// http://code.google.com/p/k9mail/issues/detail?id=2439
// Re-enable themeing support in preferences when
@@ -30,8 +28,7 @@ public class K9PreferenceActivity extends PreferenceActivity
*
* @return The {@link ListPreference} instance identified by {@code key}.
*/
- protected ListPreference setupListPreference(final String key, final String value)
- {
+ protected ListPreference setupListPreference(final String key, final String value) {
final ListPreference prefView = (ListPreference) findPreference(key);
prefView.setValue(value);
prefView.setSummary(prefView.getEntry());
@@ -53,8 +50,7 @@ public class K9PreferenceActivity extends PreferenceActivity
* entry from entries is selected.
*/
protected void initListPreference(final ListPreference prefView, final String value,
- final CharSequence[] entries, final CharSequence[] entryValues)
- {
+ final CharSequence[] entries, final CharSequence[] entryValues) {
prefView.setEntries(entries);
prefView.setEntryValues(entryValues);
prefView.setValue(value);
@@ -65,12 +61,10 @@ public class K9PreferenceActivity extends PreferenceActivity
/**
* This class handles value changes of the {@link ListPreference} objects.
*/
- private static class PreferenceChangeListener implements Preference.OnPreferenceChangeListener
- {
+ private static class PreferenceChangeListener implements Preference.OnPreferenceChangeListener {
private ListPreference mPrefView;
- private PreferenceChangeListener(final ListPreference prefView)
- {
+ private PreferenceChangeListener(final ListPreference prefView) {
this.mPrefView = prefView;
}
@@ -78,8 +72,7 @@ public class K9PreferenceActivity extends PreferenceActivity
* Show the preference value in the preference summary field.
*/
@Override
- public boolean onPreferenceChange(final Preference preference, final Object newValue)
- {
+ public boolean onPreferenceChange(final Preference preference, final Object newValue) {
final String summary = newValue.toString();
final int index = mPrefView.findIndexOfValue(summary);
mPrefView.setSummary(mPrefView.getEntries()[index]);
diff --git a/src/com/fsck/k9/activity/LauncherShortcuts.java b/src/com/fsck/k9/activity/LauncherShortcuts.java
index fd9c20cfb..58107e54d 100644
--- a/src/com/fsck/k9/activity/LauncherShortcuts.java
+++ b/src/com/fsck/k9/activity/LauncherShortcuts.java
@@ -18,19 +18,16 @@ import com.fsck.k9.K9;
import com.fsck.k9.Preferences;
import com.fsck.k9.R;
-public class LauncherShortcuts extends K9ListActivity implements OnItemClickListener
-{
+public class LauncherShortcuts extends K9ListActivity implements OnItemClickListener {
private AccountsAdapter mAdapter;
private FontSizes mFontSizes = K9.getFontSizes();
@Override
- public void onCreate(Bundle icicle)
- {
+ public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// finish() immediately if we aren't supposed to be here
- if (!Intent.ACTION_CREATE_SHORTCUT.equals(getIntent().getAction()))
- {
+ if (!Intent.ACTION_CREATE_SHORTCUT.equals(getIntent().getAction())) {
finish();
return;
}
@@ -43,23 +40,20 @@ public class LauncherShortcuts extends K9ListActivity implements OnItemClickList
refresh();
}
- private void refresh()
- {
+ private void refresh() {
Account[] accounts = Preferences.getPreferences(this).getAccounts();
mAdapter = new AccountsAdapter(accounts);
getListView().setAdapter(mAdapter);
}
- private void setupShortcut(Account account)
- {
+ private void setupShortcut(Account account) {
final Intent shortcutIntent = FolderList.actionHandleAccountIntent(this, account, null, true);
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
String description = account.getDescription();
- if (description == null || description.length() == 0)
- {
+ if (description == null || description.length() == 0) {
description = account.getEmail();
}
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, description);
@@ -70,38 +64,30 @@ public class LauncherShortcuts extends K9ListActivity implements OnItemClickList
finish();
}
- public void onItemClick(AdapterView> parent, View view, int position, long id)
- {
+ public void onItemClick(AdapterView> parent, View view, int position, long id) {
Account account = (Account) parent.getItemAtPosition(position);
setupShortcut(account);
}
- class AccountsAdapter extends ArrayAdapter
- {
- public AccountsAdapter(Account[] accounts)
- {
+ class AccountsAdapter extends ArrayAdapter {
+ public AccountsAdapter(Account[] accounts) {
super(LauncherShortcuts.this, 0, accounts);
}
@Override
- public View getView(int position, View convertView, ViewGroup parent)
- {
+ public View getView(int position, View convertView, ViewGroup parent) {
final Account account = getItem(position);
final View view;
- if (convertView != null)
- {
+ if (convertView != null) {
view = convertView;
- }
- else
- {
+ } else {
view = getLayoutInflater().inflate(R.layout.accounts_item, parent, false);
view.findViewById(R.id.active_icons).setVisibility(View.GONE);
}
AccountViewHolder holder = (AccountViewHolder) view.getTag();
- if (holder == null)
- {
+ if (holder == null) {
holder = new AccountViewHolder();
holder.description = (TextView) view.findViewById(R.id.description);
holder.email = (TextView) view.findViewById(R.id.email);
@@ -111,18 +97,14 @@ public class LauncherShortcuts extends K9ListActivity implements OnItemClickList
}
String description = account.getDescription();
- if (account.getEmail().equals(description))
- {
+ if (account.getEmail().equals(description)) {
holder.email.setVisibility(View.GONE);
- }
- else
- {
+ } else {
holder.email.setVisibility(View.VISIBLE);
holder.email.setText(account.getEmail());
}
- if (description == null || description.length() == 0)
- {
+ if (description == null || description.length() == 0) {
description = account.getEmail();
}
@@ -137,8 +119,7 @@ public class LauncherShortcuts extends K9ListActivity implements OnItemClickList
return view;
}
- class AccountViewHolder
- {
+ class AccountViewHolder {
public TextView description;
public TextView email;
public View chip;
diff --git a/src/com/fsck/k9/activity/ManageIdentities.java b/src/com/fsck/k9/activity/ManageIdentities.java
index e493d5de2..3e5d83813 100644
--- a/src/com/fsck/k9/activity/ManageIdentities.java
+++ b/src/com/fsck/k9/activity/ManageIdentities.java
@@ -11,20 +11,16 @@ import com.fsck.k9.Identity;
import com.fsck.k9.Preferences;
import com.fsck.k9.R;
-public class ManageIdentities extends ChooseIdentity
-{
+public class ManageIdentities extends ChooseIdentity {
private boolean mIdentitiesChanged = false;
public static final String EXTRA_IDENTITIES = "com.fsck.k9.EditIdentity_identities";
private static final int ACTIVITY_EDIT_IDENTITY = 1;
@Override
- protected void setupClickListeners()
- {
- this.getListView().setOnItemClickListener(new AdapterView.OnItemClickListener()
- {
- public void onItemClick(AdapterView> parent, View view, int position, long id)
- {
+ protected void setupClickListeners() {
+ this.getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ public void onItemClick(AdapterView> parent, View view, int position, long id) {
editItem(position);
}
});
@@ -33,8 +29,7 @@ public class ManageIdentities extends ChooseIdentity
registerForContextMenu(listView);
}
- private void editItem(int i)
- {
+ private void editItem(int i) {
Intent intent = new Intent(ManageIdentities.this, EditIdentity.class);
intent.putExtra(EditIdentity.EXTRA_ACCOUNT, mAccount.getUuid());
intent.putExtra(EditIdentity.EXTRA_IDENTITY, mAccount.getIdentity(i));
@@ -43,92 +38,80 @@ public class ManageIdentities extends ChooseIdentity
}
@Override
- public boolean onCreateOptionsMenu(Menu menu)
- {
+ public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.manage_identities_option, menu);
return true;
}
@Override
- public boolean onOptionsItemSelected(MenuItem item)
- {
- switch (item.getItemId())
- {
- case R.id.new_identity:
- Intent intent = new Intent(ManageIdentities.this, EditIdentity.class);
- intent.putExtra(EditIdentity.EXTRA_ACCOUNT, mAccount.getUuid());
- startActivityForResult(intent, ACTIVITY_EDIT_IDENTITY);
- break;
- default:
- return super.onOptionsItemSelected(item);
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.new_identity:
+ Intent intent = new Intent(ManageIdentities.this, EditIdentity.class);
+ intent.putExtra(EditIdentity.EXTRA_ACCOUNT, mAccount.getUuid());
+ startActivityForResult(intent, ACTIVITY_EDIT_IDENTITY);
+ break;
+ default:
+ return super.onOptionsItemSelected(item);
}
return true;
}
@Override
- public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo)
- {
+ public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle(R.string.manage_identities_context_menu_title);
getMenuInflater().inflate(R.menu.manage_identities_context, menu);
}
@Override
- public boolean onContextItemSelected(MenuItem item)
- {
+ public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo)item.getMenuInfo();
- switch (item.getItemId())
- {
- case R.id.edit:
- editItem(menuInfo.position);
- break;
- case R.id.up:
- if (menuInfo.position > 0)
- {
- Identity identity = identities.remove(menuInfo.position);
- identities.add(menuInfo.position - 1, identity);
- mIdentitiesChanged = true;
- refreshView();
- }
-
- break;
- case R.id.down:
- if (menuInfo.position < identities.size() - 1)
- {
- Identity identity = identities.remove(menuInfo.position);
- identities.add(menuInfo.position + 1, identity);
- mIdentitiesChanged = true;
- refreshView();
- }
- break;
- case R.id.top:
+ switch (item.getItemId()) {
+ case R.id.edit:
+ editItem(menuInfo.position);
+ break;
+ case R.id.up:
+ if (menuInfo.position > 0) {
Identity identity = identities.remove(menuInfo.position);
- identities.add(0, identity);
+ identities.add(menuInfo.position - 1, identity);
mIdentitiesChanged = true;
refreshView();
- break;
- case R.id.remove:
- if (identities.size() > 1)
- {
- identities.remove(menuInfo.position);
- mIdentitiesChanged = true;
- refreshView();
- }
- else
- {
- Toast.makeText(this, getString(R.string.no_removable_identity),
- Toast.LENGTH_LONG).show();
- }
- break;
+ }
+
+ break;
+ case R.id.down:
+ if (menuInfo.position < identities.size() - 1) {
+ Identity identity = identities.remove(menuInfo.position);
+ identities.add(menuInfo.position + 1, identity);
+ mIdentitiesChanged = true;
+ refreshView();
+ }
+ break;
+ case R.id.top:
+ Identity identity = identities.remove(menuInfo.position);
+ identities.add(0, identity);
+ mIdentitiesChanged = true;
+ refreshView();
+ break;
+ case R.id.remove:
+ if (identities.size() > 1) {
+ identities.remove(menuInfo.position);
+ mIdentitiesChanged = true;
+ refreshView();
+ } else {
+ Toast.makeText(this, getString(R.string.no_removable_identity),
+ Toast.LENGTH_LONG).show();
+ }
+ break;
}
return true;
}
@Override
- public void onResume()
- {
+ public void onResume() {
super.onResume();
//mAccount.refresh(Preferences.getPreferences(getApplication().getApplicationContext()));
refreshView();
@@ -136,19 +119,15 @@ public class ManageIdentities extends ChooseIdentity
@Override
- public boolean onKeyDown(int keyCode, KeyEvent event)
- {
- if (keyCode == KeyEvent.KEYCODE_BACK)
- {
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ if (keyCode == KeyEvent.KEYCODE_BACK) {
saveIdentities();
}
return super.onKeyDown(keyCode, event);
}
- private void saveIdentities()
- {
- if (mIdentitiesChanged)
- {
+ private void saveIdentities() {
+ if (mIdentitiesChanged) {
mAccount.setIdentities(identities);
mAccount.save(Preferences.getPreferences(getApplication().getApplicationContext()));
}
diff --git a/src/com/fsck/k9/activity/MessageCompose.java b/src/com/fsck/k9/activity/MessageCompose.java
index 74ebdf4d9..3352808d7 100644
--- a/src/com/fsck/k9/activity/MessageCompose.java
+++ b/src/com/fsck/k9/activity/MessageCompose.java
@@ -71,8 +71,7 @@ import com.fsck.k9.mail.internet.TextBody;
import com.fsck.k9.mail.store.LocalStore;
import com.fsck.k9.mail.store.LocalStore.LocalAttachmentBody;
-public class MessageCompose extends K9Activity implements OnClickListener, OnFocusChangeListener
-{
+public class MessageCompose extends K9Activity implements OnClickListener, OnFocusChangeListener {
private static final int DIALOG_SAVE_OR_DISCARD_DRAFT_MESSAGE = 1;
private static final String ACTION_REPLY = "com.fsck.k9.intent.action.REPLY";
@@ -193,43 +192,40 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
*/
private String mDraftUid;
- private Handler mHandler = new Handler()
- {
+ private Handler mHandler = new Handler() {
@Override
- public void handleMessage(android.os.Message msg)
- {
- switch (msg.what)
- {
- case MSG_PROGRESS_ON:
- setProgressBarIndeterminateVisibility(true);
- break;
- case MSG_PROGRESS_OFF:
- setProgressBarIndeterminateVisibility(false);
- break;
- case MSG_UPDATE_TITLE:
- updateTitle();
- break;
- case MSG_SKIPPED_ATTACHMENTS:
- Toast.makeText(
- MessageCompose.this,
- getString(R.string.message_compose_attachments_skipped_toast),
- Toast.LENGTH_LONG).show();
- break;
- case MSG_SAVED_DRAFT:
- Toast.makeText(
- MessageCompose.this,
- getString(R.string.message_saved_toast),
- Toast.LENGTH_LONG).show();
- break;
- case MSG_DISCARDED_DRAFT:
- Toast.makeText(
- MessageCompose.this,
- getString(R.string.message_discarded_toast),
- Toast.LENGTH_LONG).show();
- break;
- default:
- super.handleMessage(msg);
- break;
+ public void handleMessage(android.os.Message msg) {
+ switch (msg.what) {
+ case MSG_PROGRESS_ON:
+ setProgressBarIndeterminateVisibility(true);
+ break;
+ case MSG_PROGRESS_OFF:
+ setProgressBarIndeterminateVisibility(false);
+ break;
+ case MSG_UPDATE_TITLE:
+ updateTitle();
+ break;
+ case MSG_SKIPPED_ATTACHMENTS:
+ Toast.makeText(
+ MessageCompose.this,
+ getString(R.string.message_compose_attachments_skipped_toast),
+ Toast.LENGTH_LONG).show();
+ break;
+ case MSG_SAVED_DRAFT:
+ Toast.makeText(
+ MessageCompose.this,
+ getString(R.string.message_saved_toast),
+ Toast.LENGTH_LONG).show();
+ break;
+ case MSG_DISCARDED_DRAFT:
+ Toast.makeText(
+ MessageCompose.this,
+ getString(R.string.message_discarded_toast),
+ Toast.LENGTH_LONG).show();
+ break;
+ default:
+ super.handleMessage(msg);
+ break;
}
}
};
@@ -239,8 +235,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
private Validator mAddressValidator;
- static class Attachment implements Serializable
- {
+ static class Attachment implements Serializable {
private static final long serialVersionUID = 3642382876618963734L;
public String name;
public String contentType;
@@ -254,10 +249,8 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
* @param context
* @param account
*/
- public static void actionCompose(Context context, Account account)
- {
- if (account == null)
- {
+ public static void actionCompose(Context context, Account account) {
+ if (account == null) {
account = Preferences.getPreferences(context).getDefaultAccount();
}
Intent i = new Intent(context, MessageCompose.class);
@@ -279,17 +272,13 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
Account account,
Message message,
boolean replyAll,
- String messageBody)
- {
+ String messageBody) {
Intent i = new Intent(context, MessageCompose.class);
i.putExtra(EXTRA_MESSAGE_BODY, messageBody);
i.putExtra(EXTRA_MESSAGE_REFERENCE, message.makeMessageReference());
- if (replyAll)
- {
+ if (replyAll) {
i.setAction(ACTION_REPLY_ALL);
- }
- else
- {
+ } else {
i.setAction(ACTION_REPLY);
}
context.startActivity(i);
@@ -306,8 +295,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
Context context,
Account account,
Message message,
- String messageBody)
- {
+ String messageBody) {
Intent i = new Intent(context, MessageCompose.class);
i.putExtra(EXTRA_MESSAGE_BODY, messageBody);
i.putExtra(EXTRA_MESSAGE_REFERENCE, message.makeMessageReference());
@@ -324,8 +312,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
* @param account
* @param message
*/
- public static void actionEditDraft(Context context, Account account, Message message)
- {
+ public static void actionEditDraft(Context context, Account account, Message message) {
Intent i = new Intent(context, MessageCompose.class);
i.putExtra(EXTRA_MESSAGE_REFERENCE, message.makeMessageReference());
i.setAction(ACTION_EDIT_DRAFT);
@@ -333,8 +320,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
}
@Override
- public void onCreate(Bundle savedInstanceState)
- {
+ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.message_compose);
@@ -344,7 +330,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
mMessageReference = (MessageReference) intent.getSerializableExtra(EXTRA_MESSAGE_REFERENCE);
mSourceMessageBody = intent.getStringExtra(EXTRA_MESSAGE_BODY);
- if(K9.DEBUG && mSourceMessageBody != null)
+ if (K9.DEBUG && mSourceMessageBody != null)
Log.d(K9.LOG_TAG, "Composing message with explicitly specified message body.");
final String accountUuid = (mMessageReference != null) ?
@@ -353,13 +339,11 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
- if (mAccount == null)
- {
+ if (mAccount == null) {
mAccount = Preferences.getPreferences(this).getDefaultAccount();
}
- if (mAccount == null)
- {
+ if (mAccount == null) {
/*
* There are no accounts set up. This should not have happened. Prompt the
* user to set up an account as an acceptable bailout.
@@ -395,37 +379,31 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
mQuotedHTML.configure();
// Disable the ability to click links in the quoted HTML page. I think this is a nice feature, but if someone
// feels this should be a preference (or should go away all together), I'm ok with that too. -achen 20101130
- mQuotedHTML.setWebViewClient(new WebViewClient()
- {
+ mQuotedHTML.setWebViewClient(new WebViewClient() {
@Override
- public boolean shouldOverrideUrlLoading(WebView view, String url)
- {
+ public boolean shouldOverrideUrlLoading(WebView view, String url) {
return true;
}
});
- TextWatcher watcher = new TextWatcher()
- {
+ TextWatcher watcher = new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start,
int before, int after) { }
public void onTextChanged(CharSequence s, int start,
- int before, int count)
- {
+ int before, int count) {
mDraftNeedsSaving = true;
}
public void afterTextChanged(android.text.Editable s) { }
};
- TextWatcher sigwatcher = new TextWatcher()
- {
+ TextWatcher sigwatcher = new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start,
int before, int after) { }
public void onTextChanged(CharSequence s, int start,
- int before, int count)
- {
+ int before, int count) {
mDraftNeedsSaving = true;
mSignatureChanged = true;
}
@@ -470,8 +448,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
mSubjectView.setOnFocusChangeListener(this);
- if (savedInstanceState != null)
- {
+ if (savedInstanceState != null) {
/*
* This data gets used in onCreate, so grab it here instead of onRestoreInstanceState
*/
@@ -482,40 +459,33 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
final String action = intent.getAction();
initFromIntent(intent);
- if (mIdentity == null)
- {
+ if (mIdentity == null) {
mIdentity = mAccount.getIdentity(0);
}
- if (mAccount.isSignatureBeforeQuotedText())
- {
+ if (mAccount.isSignatureBeforeQuotedText()) {
mSignatureView = upperSignature;
lowerSignature.setVisibility(View.GONE);
- }
- else
- {
+ } else {
mSignatureView = lowerSignature;
upperSignature.setVisibility(View.GONE);
}
mSignatureView.addTextChangedListener(sigwatcher);
- if (!mIdentity.getSignatureUse())
- {
+ if (!mIdentity.getSignatureUse()) {
mSignatureView.setVisibility(View.GONE);
}
mMessageFormat = mAccount.getMessageFormat();
- if (!mSourceMessageProcessed)
- {
+ if (!mSourceMessageProcessed) {
updateFrom();
updateSignature();
if (ACTION_REPLY.equals(action) ||
ACTION_REPLY_ALL.equals(action) ||
ACTION_FORWARD.equals(action) ||
- ACTION_EDIT_DRAFT.equals(action))
- {
+ ACTION_EDIT_DRAFT.equals(action)) {
/*
* If we need to load the message we add ourself as a message listener here
* so we can kick it off. Normally we add in onResume but we don't
@@ -530,11 +500,9 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
MessagingController.getInstance(getApplication()).loadMessageForView(account, folderName, sourceMessageUid, null);
}
- if (!ACTION_EDIT_DRAFT.equals(action))
- {
+ if (!ACTION_EDIT_DRAFT.equals(action)) {
String bccAddress = mAccount.getAlwaysBcc();
- if ((bccAddress != null) && !("".equals(bccAddress)))
- {
+ if ((bccAddress != null) && !("".equals(bccAddress))) {
addAddress(mBccView, new Address(bccAddress, ""));
}
}
@@ -548,15 +516,13 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
}
if (ACTION_REPLY.equals(action) ||
- ACTION_REPLY_ALL.equals(action))
- {
+ ACTION_REPLY_ALL.equals(action)) {
mMessageReference.flag = Flag.ANSWERED;
}
if (ACTION_REPLY.equals(action) ||
ACTION_REPLY_ALL.equals(action) ||
- ACTION_EDIT_DRAFT.equals(action))
- {
+ ACTION_EDIT_DRAFT.equals(action)) {
//change focus to message body.
mMessageContentView.requestFocus();
}
@@ -569,50 +535,37 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
initializeCrypto();
final CryptoProvider crypto = mAccount.getCryptoProvider();
- if (crypto.isAvailable(this))
- {
+ if (crypto.isAvailable(this)) {
mEncryptLayout.setVisibility(View.VISIBLE);
- mCryptoSignatureCheckbox.setOnClickListener(new OnClickListener()
- {
+ mCryptoSignatureCheckbox.setOnClickListener(new OnClickListener() {
@Override
- public void onClick(View v)
- {
+ public void onClick(View v) {
CheckBox checkBox = (CheckBox) v;
- if (checkBox.isChecked())
- {
+ if (checkBox.isChecked()) {
mPreventDraftSaving = true;
- if (!crypto.selectSecretKey(MessageCompose.this, mPgpData))
- {
+ if (!crypto.selectSecretKey(MessageCompose.this, mPgpData)) {
mPreventDraftSaving = false;
}
checkBox.setChecked(false);
- }
- else
- {
+ } else {
mPgpData.setSignatureKeyId(0);
updateEncryptLayout();
}
}
});
- if (mAccount.getCryptoAutoSignature())
- {
+ if (mAccount.getCryptoAutoSignature()) {
long ids[] = crypto.getSecretKeyIdsFromEmail(this, mIdentity.getEmail());
- if (ids != null && ids.length > 0)
- {
+ if (ids != null && ids.length > 0) {
mPgpData.setSignatureKeyId(ids[0]);
mPgpData.setSignatureUserId(crypto.getUserId(this, ids[0]));
- }
- else
- {
+ } else {
mPgpData.setSignatureKeyId(0);
mPgpData.setSignatureUserId(null);
}
}
updateEncryptLayout();
- }
- else
- {
+ } else {
mEncryptLayout.setVisibility(View.GONE);
}
@@ -624,20 +577,16 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
*
* @param intent The (external) intent that started the activity.
*/
- private void initFromIntent(final Intent intent)
- {
+ private void initFromIntent(final Intent intent) {
final String action = intent.getAction();
- if (Intent.ACTION_VIEW.equals(action) || Intent.ACTION_SENDTO.equals(action))
- {
+ if (Intent.ACTION_VIEW.equals(action) || Intent.ACTION_SENDTO.equals(action)) {
/*
* Someone has clicked a mailto: link. The address is in the URI.
*/
- if (intent.getData() != null)
- {
+ if (intent.getData() != null) {
Uri uri = intent.getData();
- if ("mailto".equals(uri.getScheme()))
- {
+ if ("mailto".equals(uri.getScheme())) {
initializeFromMailto(uri);
}
}
@@ -652,8 +601,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
}
//TODO: Use constant Intent.ACTION_SEND_MULTIPLE once we drop Android 1.5 support
else if (Intent.ACTION_SEND.equals(action) ||
- "android.intent.action.SEND_MULTIPLE".equals(action))
- {
+ "android.intent.action.SEND_MULTIPLE".equals(action)) {
/*
* Note: Here we allow a slight deviation from the documentated behavior.
* EXTRA_TEXT is used as message body (if available) regardless of the MIME
@@ -661,30 +609,22 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
* using EXTRA_STREAM.
*/
CharSequence text = intent.getCharSequenceExtra(Intent.EXTRA_TEXT);
- if (text != null)
- {
+ if (text != null) {
mMessageContentView.setText(text);
}
String type = intent.getType();
- if (Intent.ACTION_SEND.equals(action))
- {
+ if (Intent.ACTION_SEND.equals(action)) {
Uri stream = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
- if (stream != null)
- {
+ if (stream != null) {
addAttachment(stream, type);
}
- }
- else
- {
+ } else {
ArrayList list = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
- if (list != null)
- {
- for (Parcelable parcelable : list)
- {
+ if (list != null) {
+ for (Parcelable parcelable : list) {
Uri stream = (Uri) parcelable;
- if (stream != null)
- {
+ if (stream != null) {
addAttachment(stream, type);
}
}
@@ -692,8 +632,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
}
String subject = intent.getStringExtra(Intent.EXTRA_SUBJECT);
- if (subject != null)
- {
+ if (subject != null) {
mSubjectView.setText(subject);
}
@@ -701,38 +640,31 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
String[] extraCc = intent.getStringArrayExtra(Intent.EXTRA_CC);
String[] extraBcc = intent.getStringArrayExtra(Intent.EXTRA_BCC);
- if (extraEmail != null)
- {
+ if (extraEmail != null) {
setRecipients(mToView, Arrays.asList(extraEmail));
}
boolean ccOrBcc = false;
- if (extraCc != null)
- {
+ if (extraCc != null) {
ccOrBcc |= setRecipients(mCcView, Arrays.asList(extraCc));
}
- if (extraBcc != null)
- {
+ if (extraBcc != null) {
ccOrBcc |= setRecipients(mBccView, Arrays.asList(extraBcc));
}
- if (ccOrBcc)
- {
+ if (ccOrBcc) {
// Display CC and BCC text fields if CC or BCC recipients were set by the intent.
onAddCcBcc();
}
}
}
- private boolean setRecipients(TextView view, List recipients)
- {
+ private boolean setRecipients(TextView view, List recipients) {
boolean recipientAdded = false;
- if (recipients != null)
- {
+ if (recipients != null) {
StringBuffer addressList = new StringBuffer();
- for (String recipient : recipients)
- {
+ for (String recipient : recipients) {
addressList.append(recipient);
addressList.append(", ");
recipientAdded = true;
@@ -743,10 +675,8 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
return recipientAdded;
}
- private void initializeCrypto()
- {
- if (mPgpData != null)
- {
+ private void initializeCrypto() {
+ if (mPgpData != null) {
return;
}
mPgpData = new PgpData();
@@ -755,17 +685,13 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
/**
* Fill the encrypt layout with the latest data about signature key and encryption keys.
*/
- public void updateEncryptLayout()
- {
- if (!mPgpData.hasSignatureKey())
- {
+ public void updateEncryptLayout() {
+ if (!mPgpData.hasSignatureKey()) {
mCryptoSignatureCheckbox.setText(R.string.btn_crypto_sign);
mCryptoSignatureCheckbox.setChecked(false);
mCryptoSignatureUserId.setVisibility(View.INVISIBLE);
mCryptoSignatureUserIdRest.setVisibility(View.INVISIBLE);
- }
- else
- {
+ } else {
// if a signature key is selected, then the checkbox itself has no text
mCryptoSignatureCheckbox.setText("");
mCryptoSignatureCheckbox.setChecked(true);
@@ -775,18 +701,15 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
mCryptoSignatureUserIdRest.setText("");
String userId = mPgpData.getSignatureUserId();
- if (userId == null)
- {
+ if (userId == null) {
userId = mAccount.getCryptoProvider().getUserId(this, mPgpData.getSignatureKeyId());
mPgpData.setSignatureUserId(userId);
}
- if (userId != null)
- {
+ if (userId != null) {
String chunks[] = mPgpData.getSignatureUserId().split(" <", 2);
mCryptoSignatureUserId.setText(chunks[0]);
- if (chunks.length > 1)
- {
+ if (chunks.length > 1) {
mCryptoSignatureUserIdRest.setText("<" + chunks[1]);
}
}
@@ -794,15 +717,13 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
}
@Override
- public void onResume()
- {
+ public void onResume() {
super.onResume();
MessagingController.getInstance(getApplication()).addListener(mListener);
}
@Override
- public void onPause()
- {
+ public void onPause() {
super.onPause();
saveIfNeeded();
MessagingController.getInstance(getApplication()).removeListener(mListener);
@@ -817,13 +738,11 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
* Quoted text,
*/
@Override
- protected void onSaveInstanceState(Bundle outState)
- {
+ protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
saveIfNeeded();
ArrayList attachments = new ArrayList();
- for (int i = 0, count = mAttachments.getChildCount(); i < count; i++)
- {
+ for (int i = 0, count = mAttachments.getChildCount(); i < count; i++) {
View view = mAttachments.getChildAt(i);
Attachment attachment = (Attachment) view.getTag();
attachments.add(attachment.uri);
@@ -844,13 +763,11 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
}
@Override
- protected void onRestoreInstanceState(Bundle savedInstanceState)
- {
+ protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
ArrayList attachments = savedInstanceState.getParcelableArrayList(STATE_KEY_ATTACHMENTS);
mAttachments.removeAllViews();
- for (Parcelable p : attachments)
- {
+ for (Parcelable p : attachments) {
Uri uri = (Uri) p;
addAttachment(uri);
}
@@ -858,19 +775,15 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
mMessageFormat = (MessageFormat)savedInstanceState.getSerializable(STATE_KEY_MESSAGE_FORMAT);
mCcView.setVisibility(savedInstanceState.getBoolean(STATE_KEY_CC_SHOWN) ? View.VISIBLE : View.GONE);
mBccView.setVisibility(savedInstanceState.getBoolean(STATE_KEY_BCC_SHOWN) ? View.VISIBLE : View.GONE);
- if (mMessageFormat == MessageFormat.HTML)
- {
+ if (mMessageFormat == MessageFormat.HTML) {
mQuotedHtmlContent = (InsertableHtmlContent) savedInstanceState.getSerializable(STATE_KEY_HTML_QUOTE);
mQuotedTextBar.setVisibility(savedInstanceState.getBoolean(STATE_KEY_QUOTED_TEXT_SHOWN) ? View.VISIBLE : View.GONE);
mQuotedHTML.setVisibility(savedInstanceState.getBoolean(STATE_KEY_QUOTED_TEXT_SHOWN) ? View.VISIBLE : View.GONE);
- if (mQuotedHtmlContent != null && mQuotedHtmlContent.getQuotedContent() != null)
- {
+ if (mQuotedHtmlContent != null && mQuotedHtmlContent.getQuotedContent() != null) {
mQuotedHTML.loadDataWithBaseURL("http://", mQuotedHtmlContent.getQuotedContent(), "text/html", "utf-8", null);
mQuotedTextEdit.setVisibility(View.VISIBLE);
}
- }
- else
- {
+ } else {
mQuotedTextBar.setVisibility(savedInstanceState.getBoolean(STATE_KEY_QUOTED_TEXT_SHOWN) ? View.VISIBLE : View.GONE);
mQuotedText.setVisibility(savedInstanceState.getBoolean(STATE_KEY_QUOTED_TEXT_SHOWN) ? View.VISIBLE : View.GONE);
}
@@ -889,45 +802,34 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
mDraftNeedsSaving = false;
}
- private void updateTitle()
- {
- if (mSubjectView.getText().length() == 0)
- {
+ private void updateTitle() {
+ if (mSubjectView.getText().length() == 0) {
setTitle(R.string.compose_title);
- }
- else
- {
+ } else {
setTitle(mSubjectView.getText().toString());
}
}
- public void onFocusChange(View view, boolean focused)
- {
- if (!focused)
- {
+ public void onFocusChange(View view, boolean focused) {
+ if (!focused) {
updateTitle();
}
}
- private void addAddresses(MultiAutoCompleteTextView view, Address[] addresses)
- {
- if (addresses == null)
- {
+ private void addAddresses(MultiAutoCompleteTextView view, Address[] addresses) {
+ if (addresses == null) {
return;
}
- for (Address address : addresses)
- {
+ for (Address address : addresses) {
addAddress(view, address);
}
}
- private void addAddress(MultiAutoCompleteTextView view, Address address)
- {
+ private void addAddress(MultiAutoCompleteTextView view, Address address) {
view.append(address + ", ");
}
- private Address[] getAddresses(MultiAutoCompleteTextView view)
- {
+ private Address[] getAddresses(MultiAutoCompleteTextView view) {
return Address.parseUnencoded(view.getText().toString().trim());
}
@@ -938,13 +840,11 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
* appended and HTML separators between composed text and quoted text are not added.
* @param isDraft If we should build a message that will be saved as a draft (as opposed to sent).
*/
- private TextBody buildText(boolean isDraft)
- {
+ private TextBody buildText(boolean isDraft) {
boolean replyAfterQuote = false;
String action = getIntent().getAction();
if (mAccount.isReplyAfterQuote() &&
- (ACTION_REPLY.equals(action) || ACTION_REPLY_ALL.equals(action)))
- {
+ (ACTION_REPLY.equals(action) || ACTION_REPLY_ALL.equals(action))) {
replyAfterQuote = true;
}
@@ -953,22 +853,18 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
// Handle HTML separate from the rest of the text content. HTML mode doesn't allow signature after the quoted
// text, nor does it allow reply after quote. Users who want that functionality will need to stick with text
// mode.
- if (mMessageFormat == MessageFormat.HTML)
- {
+ if (mMessageFormat == MessageFormat.HTML) {
// Add the signature.
- if (!isDraft)
- {
+ if (!isDraft) {
text = appendSignature(text);
}
text = HtmlConverter.textToHtmlFragment(text);
// Insert it into the existing content object.
if (K9.DEBUG && mQuotedHtmlContent != null)
Log.d(K9.LOG_TAG, "insertable: " + mQuotedHtmlContent.toDebugString());
- if (mQuotedHtmlContent != null)
- {
+ if (mQuotedHtmlContent != null) {
// Remove the quoted part if it's no longer visible.
- if (mQuotedTextBar.getVisibility() != View.VISIBLE)
- {
+ if (mQuotedTextBar.getVisibility() != View.VISIBLE) {
mQuotedHtmlContent.clearQuotedContent();
}
@@ -978,19 +874,14 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
// location. We only add the extra separators when we're sending, that way when we
// load a draft, we don't have to know the length of the separators to remove them
// before editing.
- if (mAccount.getQuoteStyle() == QuoteStyle.PREFIX && replyAfterQuote)
- {
+ if (mAccount.getQuoteStyle() == QuoteStyle.PREFIX && replyAfterQuote) {
mQuotedHtmlContent.setInsertionLocation(InsertableHtmlContent.InsertionLocation.AFTER_QUOTE);
- if (!isDraft)
- {
+ if (!isDraft) {
text = "
" + text;
}
- }
- else
- {
+ } else {
mQuotedHtmlContent.setInsertionLocation(InsertableHtmlContent.InsertionLocation.BEFORE_QUOTE);
- if (!isDraft)
- {
+ if (!isDraft) {
text += "
";
}
}
@@ -1003,45 +894,35 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
body.setComposedMessageLength(text.length());
body.setComposedMessageOffset(mQuotedHtmlContent.getInsertionPoint());
return body;
- }
- else
- {
+ } else {
TextBody body = new TextBody(text);
body.setComposedMessageLength(text.length());
// Not in reply to anything so the message starts at the beginning (0).
body.setComposedMessageOffset(0);
return body;
}
- }
- else if (mMessageFormat == MessageFormat.TEXT)
- {
+ } else if (mMessageFormat == MessageFormat.TEXT) {
// Capture composed message length before we start attaching quoted parts and signatures.
Integer composedMessageLength = text.length();
Integer composedMessageOffset = 0;
// Placing the signature before the quoted text does not make sense if replyAfterQuote is true.
- if (!replyAfterQuote && !isDraft && mAccount.isSignatureBeforeQuotedText())
- {
+ if (!replyAfterQuote && !isDraft && mAccount.isSignatureBeforeQuotedText()) {
text = appendSignature(text);
}
- if (mQuotedTextBar.getVisibility() == View.VISIBLE)
- {
- if (replyAfterQuote)
- {
+ if (mQuotedTextBar.getVisibility() == View.VISIBLE) {
+ if (replyAfterQuote) {
composedMessageOffset = mQuotedText.getText().toString().length() + "\n".length();
text = mQuotedText.getText().toString() + "\n" + text;
- }
- else
- {
+ } else {
text += "\n\n" + mQuotedText.getText().toString();
}
}
// Note: If user has selected reply after quote AND signature before quote, ignore the
// latter setting and append the signature at the end.
- if (!isDraft && (!mAccount.isSignatureBeforeQuotedText() || replyAfterQuote))
- {
+ if (!isDraft && (!mAccount.isSignatureBeforeQuotedText() || replyAfterQuote)) {
text = appendSignature(text);
}
@@ -1051,9 +932,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
body.setComposedMessageOffset(composedMessageOffset);
return body;
- }
- else
- {
+ } else {
// Shouldn't happen.
return new TextBody("");
}
@@ -1067,8 +946,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
* @return Message to be sent.
* @throws MessagingException
*/
- private MimeMessage createMessage(boolean isDraft) throws MessagingException
- {
+ private MimeMessage createMessage(boolean isDraft) throws MessagingException {
MimeMessage message = new MimeMessage();
message.addSentDate(new Date());
Address from = new Address(mIdentity.getEmail(), mIdentity.getName());
@@ -1080,38 +958,31 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
message.setHeader("User-Agent", getString(R.string.message_header_mua));
final String replyTo = mIdentity.getReplyTo();
- if (replyTo != null)
- {
+ if (replyTo != null) {
message.setReplyTo(new Address[] { new Address(replyTo) });
}
- if (mInReplyTo != null)
- {
+ if (mInReplyTo != null) {
message.setInReplyTo(mInReplyTo);
}
- if (mReferences != null)
- {
+ if (mReferences != null) {
message.setReferences(mReferences);
}
// Build the body.
// TODO FIXME - body can be either an HTML or Text part, depending on whether we're in HTML mode or not. Should probably fix this so we don't mix up html and text parts.
TextBody body = null;
- if (mPgpData.getEncryptedData() != null)
- {
+ if (mPgpData.getEncryptedData() != null) {
String text = mPgpData.getEncryptedData();
body = new TextBody(text);
- }
- else
- {
+ } else {
body = buildText(isDraft);
}
final boolean hasAttachments = mAttachments.getChildCount() > 0;
- if (mMessageFormat == MessageFormat.HTML)
- {
+ if (mMessageFormat == MessageFormat.HTML) {
// HTML message (with alternative text part)
// This is the compiled MIME part for an HTML message.
@@ -1120,8 +991,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
composedMimeMessage.addBodyPart(new MimeBodyPart(body, "text/html"));
composedMimeMessage.addBodyPart(new MimeBodyPart(new TextBody(HtmlConverter.htmlToText(body.getText())), "text/plain"));
- if (hasAttachments)
- {
+ if (hasAttachments) {
// If we're HTML and have attachments, we have a MimeMultipart container to hold the
// whole message (mp here), of which one part is a MimeMultipart container
// (composedMimeMessage) with the user's composed messages, and subsequent parts for
@@ -1130,33 +1000,25 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
mp.addBodyPart(new MimeBodyPart(composedMimeMessage));
addAttachmentsToMessage(mp);
message.setBody(mp);
- }
- else
- {
+ } else {
// If no attachments, our multipart/alternative part is the only one we need.
message.setBody(composedMimeMessage);
}
- }
- else
- {
+ } else {
// Text-only message.
- if (hasAttachments)
- {
+ if (hasAttachments) {
MimeMultipart mp = new MimeMultipart();
mp.addBodyPart(new MimeBodyPart(body, "text/plain"));
addAttachmentsToMessage(mp);
message.setBody(mp);
- }
- else
- {
+ } else {
// No attachments to include, just stick the text body in the message and call it good.
message.setBody(body);
}
}
// If this is a draft, add metadata for thawing.
- if (isDraft)
- {
+ if (isDraft) {
// Add the identity to the message.
message.addHeader(K9.IDENTITY_HEADER, buildIdentityHeader(body));
}
@@ -1169,10 +1031,8 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
* @param mp MimeMultipart container in which to insert parts.
* @throws MessagingException
*/
- private void addAttachmentsToMessage(final MimeMultipart mp) throws MessagingException
- {
- for (int i = 0, count = mAttachments.getChildCount(); i < count; i++)
- {
+ private void addAttachmentsToMessage(final MimeMultipart mp) throws MessagingException {
+ for (int i = 0, count = mAttachments.getChildCount(); i < count; i++) {
Attachment attachment = (Attachment) mAttachments.getChildAt(i).getTag();
MimeBodyPart bp = new MimeBodyPart(
@@ -1215,8 +1075,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
// FYI, there's nothing in the code that requires these variables to one letter. They're one
// letter simply to save space. This name sucks. It's too similar to Account.Identity.
- private enum IdentityField
- {
+ private enum IdentityField {
LENGTH("l"),
OFFSET("o"),
MESSAGE_FORMAT("f"),
@@ -1228,13 +1087,11 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
private final String value;
- IdentityField(String value)
- {
+ IdentityField(String value) {
this.value = value;
}
- public String value()
- {
+ public String value() {
return value;
}
@@ -1243,8 +1100,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
* checked for integer-ness during decoding.
* @return
*/
- public static IdentityField[] getIntegerFields()
- {
+ public static IdentityField[] getIntegerFields() {
return new IdentityField[] { LENGTH, OFFSET };
}
}
@@ -1262,17 +1118,13 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
* @param body {@link TextBody} to analyze for body length and offset.
* @return Identity string.
*/
- private String buildIdentityHeader(final TextBody body)
- {
+ private String buildIdentityHeader(final TextBody body) {
Uri.Builder uri = new Uri.Builder();
- if(body.getComposedMessageLength() != null && body.getComposedMessageOffset() != null)
- {
+ if (body.getComposedMessageLength() != null && body.getComposedMessageOffset() != null) {
// See if the message body length is already in the TextBody.
uri.appendQueryParameter(IdentityField.LENGTH.value(), body.getComposedMessageLength().toString());
uri.appendQueryParameter(IdentityField.OFFSET.value(), body.getComposedMessageOffset().toString());
- }
- else
- {
+ } else {
// If not, calculate it now.
uri.appendQueryParameter(IdentityField.LENGTH.value(), Integer.toString(body.getText().length()));
uri.appendQueryParameter(IdentityField.OFFSET.value(), Integer.toString(0));
@@ -1281,26 +1133,22 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
uri.appendQueryParameter(IdentityField.MESSAGE_FORMAT.value(), mMessageFormat.name());
// If we're not using the standard identity of signature, append it on to the identity blob.
- if (mSignatureChanged)
- {
+ if (mSignatureChanged) {
uri.appendQueryParameter(IdentityField.SIGNATURE.value(), mSignatureView.getText().toString());
}
- if (mIdentityChanged)
- {
+ if (mIdentityChanged) {
uri.appendQueryParameter(IdentityField.NAME.value(), mIdentity.getName());
uri.appendQueryParameter(IdentityField.EMAIL.value(), mIdentity.getEmail());
}
- if (mMessageReference != null)
- {
+ if (mMessageReference != null) {
uri.appendQueryParameter(IdentityField.ORIGINAL_MESSAGE.value(), mMessageReference.toIdentityString());
}
String k9identity = IDENTITY_VERSION_1 + uri.build().getEncodedQuery();
- if (K9.DEBUG)
- {
+ if (K9.DEBUG) {
Log.d(K9.LOG_TAG, "Generated identity: " + k9identity);
}
@@ -1312,29 +1160,24 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
* @param identityString
* @return
*/
- private Map parseIdentityHeader(final String identityString)
- {
+ private Map parseIdentityHeader(final String identityString) {
Map identity = new HashMap();
if (K9.DEBUG)
Log.d(K9.LOG_TAG, "Decoding identity: " + identityString);
- if (identityString == null || identityString.length() < 1)
- {
+ if (identityString == null || identityString.length() < 1) {
return identity;
}
// Check to see if this is a "next gen" identity.
- if (identityString.charAt(0) == IDENTITY_VERSION_1.charAt(0) && identityString.length() > 2)
- {
+ if (identityString.charAt(0) == IDENTITY_VERSION_1.charAt(0) && identityString.length() > 2) {
Uri.Builder builder = new Uri.Builder();
builder.encodedQuery(identityString.substring(1)); // Need to cut off the ! at the beginning.
Uri uri = builder.build();
- for (IdentityField key : IdentityField.values())
- {
+ for (IdentityField key : IdentityField.values()) {
String value = uri.getQueryParameter(key.value());
- if (value != null)
- {
+ if (value != null) {
identity.put(key, value);
}
}
@@ -1343,23 +1186,16 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
Log.d(K9.LOG_TAG, "Decoded identity: " + identity.toString());
// Sanity check our Integers so that recipients of this result don't have to.
- for (IdentityField key : IdentityField.getIntegerFields())
- {
- if (identity.get(key) != null)
- {
- try
- {
+ for (IdentityField key : IdentityField.getIntegerFields()) {
+ if (identity.get(key) != null) {
+ try {
Integer.parseInt(identity.get(key));
- }
- catch (NumberFormatException e)
- {
+ } catch (NumberFormatException e) {
Log.e(K9.LOG_TAG, "Invalid " + key.name() + " field in identity: " + identity.get(key));
}
}
}
- }
- else
- {
+ } else {
// Legacy identity
if (K9.DEBUG)
@@ -1367,28 +1203,21 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
StringTokenizer tokens = new StringTokenizer(identityString, ":", false);
// First item is the body length. We use this to separate the composed reply from the quoted text.
- if (tokens.hasMoreTokens())
- {
+ if (tokens.hasMoreTokens()) {
String bodyLengthS = Utility.base64Decode(tokens.nextToken());
- try
- {
+ try {
identity.put(IdentityField.LENGTH, Integer.valueOf(bodyLengthS).toString());
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
Log.e(K9.LOG_TAG, "Unable to parse bodyLength '" + bodyLengthS + "'");
}
}
- if (tokens.hasMoreTokens())
- {
+ if (tokens.hasMoreTokens()) {
identity.put(IdentityField.SIGNATURE, Utility.base64Decode(tokens.nextToken()));
}
- if (tokens.hasMoreTokens())
- {
+ if (tokens.hasMoreTokens()) {
identity.put(IdentityField.NAME, Utility.base64Decode(tokens.nextToken()));
}
- if (tokens.hasMoreTokens())
- {
+ if (tokens.hasMoreTokens()) {
identity.put(IdentityField.EMAIL, Utility.base64Decode(tokens.nextToken()));
}
}
@@ -1397,14 +1226,11 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
}
- private String appendSignature(String text)
- {
- if (mIdentity.getSignatureUse())
- {
+ private String appendSignature(String text) {
+ if (mIdentity.getSignatureUse()) {
String signature = mSignatureView.getText().toString();
- if (signature != null && !signature.contentEquals(""))
- {
+ if (signature != null && !signature.contentEquals("")) {
text += "\n" + signature;
}
}
@@ -1413,19 +1239,15 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
}
- private void sendMessage()
- {
+ private void sendMessage() {
new SendMessageTask().execute();
}
- private void saveMessage()
- {
+ private void saveMessage() {
new SaveMessageTask().execute();
}
- private void saveIfNeeded()
- {
- if (!mDraftNeedsSaving || mPreventDraftSaving || mPgpData.hasEncryptionKeys())
- {
+ private void saveIfNeeded() {
+ if (!mDraftNeedsSaving || mPreventDraftSaving || mPgpData.hasEncryptionKeys()) {
return;
}
@@ -1433,78 +1255,59 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
saveMessage();
}
- public void onEncryptionKeySelectionDone()
- {
- if (mPgpData.hasEncryptionKeys())
- {
+ public void onEncryptionKeySelectionDone() {
+ if (mPgpData.hasEncryptionKeys()) {
onSend();
- }
- else
- {
+ } else {
Toast.makeText(this, R.string.send_aborted, Toast.LENGTH_SHORT).show();
}
}
- public void onEncryptDone()
- {
- if (mPgpData.getEncryptedData() != null)
- {
+ public void onEncryptDone() {
+ if (mPgpData.getEncryptedData() != null) {
onSend();
- }
- else
- {
+ } else {
Toast.makeText(this, R.string.send_aborted, Toast.LENGTH_SHORT).show();
}
}
- private void onSend()
- {
- if (getAddresses(mToView).length == 0 && getAddresses(mCcView).length == 0 && getAddresses(mBccView).length == 0)
- {
+ private void onSend() {
+ if (getAddresses(mToView).length == 0 && getAddresses(mCcView).length == 0 && getAddresses(mBccView).length == 0) {
mToView.setError(getString(R.string.message_compose_error_no_recipients));
Toast.makeText(this, getString(R.string.message_compose_error_no_recipients), Toast.LENGTH_LONG).show();
return;
}
- if (mEncryptCheckbox.isChecked() && !mPgpData.hasEncryptionKeys())
- {
+ if (mEncryptCheckbox.isChecked() && !mPgpData.hasEncryptionKeys()) {
// key selection before encryption
String emails = "";
Address[][] addresses = new Address[][] { getAddresses(mToView),
getAddresses(mCcView),
getAddresses(mBccView)
};
- for (Address[] addressArray : addresses)
- {
- for (Address address : addressArray)
- {
- if (emails.length() != 0)
- {
+ for (Address[] addressArray : addresses) {
+ for (Address address : addressArray) {
+ if (emails.length() != 0) {
emails += ",";
}
emails += address.getAddress();
}
}
- if (emails.length() != 0)
- {
+ if (emails.length() != 0) {
emails += ",";
}
emails += mIdentity.getEmail();
mPreventDraftSaving = true;
- if (!mAccount.getCryptoProvider().selectEncryptionKeys(MessageCompose.this, emails, mPgpData))
- {
+ if (!mAccount.getCryptoProvider().selectEncryptionKeys(MessageCompose.this, emails, mPgpData)) {
mPreventDraftSaving = false;
}
return;
}
- if (mPgpData.hasEncryptionKeys() || mPgpData.hasSignatureKey())
- {
- if (mPgpData.getEncryptedData() == null)
- {
+ if (mPgpData.hasEncryptionKeys() || mPgpData.hasSignatureKey()) {
+ if (mPgpData.getEncryptedData() == null) {
String text = buildText(false).getText();
mPreventDraftSaving = true;
- if (!mAccount.getCryptoProvider().encrypt(this, text, mPgpData))
- {
+ if (!mAccount.getCryptoProvider().encrypt(this, text, mPgpData)) {
mPreventDraftSaving = false;
}
return;
@@ -1512,25 +1315,22 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
}
sendMessage();
- if (mMessageReference != null && mMessageReference.flag != null)
- {
+ if (mMessageReference != null && mMessageReference.flag != null) {
if (K9.DEBUG)
Log.d(K9.LOG_TAG, "Setting referenced message (" + mMessageReference.folderName + ", " + mMessageReference.uid + ") flag to " + mMessageReference.flag);
final Account account = Preferences.getPreferences(this).getAccount(mMessageReference.accountUuid);
final String folderName = mMessageReference.folderName;
final String sourceMessageUid = mMessageReference.uid;
- MessagingController.getInstance(getApplication()).setFlag(account, folderName, new String[]{sourceMessageUid}, mMessageReference.flag, true);
+ MessagingController.getInstance(getApplication()).setFlag(account, folderName, new String[] {sourceMessageUid}, mMessageReference.flag, true);
}
mDraftNeedsSaving = false;
finish();
}
- private void onDiscard()
- {
- if (mDraftUid != null)
- {
+ private void onDiscard() {
+ if (mDraftUid != null) {
MessagingController.getInstance(getApplication()).deleteDraft(mAccount, mDraftUid);
mDraftUid = null;
}
@@ -1539,15 +1339,13 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
finish();
}
- private void onSave()
- {
+ private void onSave() {
mDraftNeedsSaving = true;
saveIfNeeded();
finish();
}
- private void onAddCcBcc()
- {
+ private void onAddCcBcc() {
mCcView.setVisibility(View.VISIBLE);
mBccView.setVisibility(View.VISIBLE);
}
@@ -1555,18 +1353,13 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
/**
* Kick off a picker for whatever kind of MIME types we'll accept and let Android take over.
*/
- private void onAddAttachment()
- {
- if (K9.isGalleryBuggy())
- {
- if (K9.useGalleryBugWorkaround())
- {
+ private void onAddAttachment() {
+ if (K9.isGalleryBuggy()) {
+ if (K9.useGalleryBugWorkaround()) {
Toast.makeText(MessageCompose.this,
getString(R.string.message_compose_use_workaround),
Toast.LENGTH_LONG).show();
- }
- else
- {
+ } else {
Toast.makeText(MessageCompose.this,
getString(R.string.message_compose_buggy_gallery),
Toast.LENGTH_LONG).show();
@@ -1579,10 +1372,8 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
/**
* Kick off a picker for the specified MIME type and let Android take over.
*/
- private void onAddAttachment2(final String mime_type)
- {
- if (mAccount.getCryptoProvider().isAvailable(this))
- {
+ private void onAddAttachment2(final String mime_type) {
+ if (mAccount.getCryptoProvider().isAvailable(this)) {
Toast.makeText(this, R.string.attachment_encryption_unsupported, Toast.LENGTH_LONG).show();
}
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
@@ -1591,13 +1382,11 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
startActivityForResult(Intent.createChooser(i, null), ACTIVITY_REQUEST_PICK_ATTACHMENT);
}
- private void addAttachment(Uri uri)
- {
+ private void addAttachment(Uri uri) {
addAttachment(uri, null);
}
- private void addAttachment(Uri uri, String contentType)
- {
+ private void addAttachment(Uri uri, String contentType) {
long size = -1;
String name = null;
@@ -1610,52 +1399,38 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
null,
null);
- if (metadataCursor != null)
- {
- try
- {
- if (metadataCursor.moveToFirst())
- {
+ if (metadataCursor != null) {
+ try {
+ if (metadataCursor.moveToFirst()) {
name = metadataCursor.getString(0);
size = metadataCursor.getInt(1);
}
- }
- finally
- {
+ } finally {
metadataCursor.close();
}
}
- if (name == null)
- {
+ if (name == null) {
name = uri.getLastPathSegment();
}
- if ((contentType == null) || (contentType.indexOf('*') != -1))
- {
+ if ((contentType == null) || (contentType.indexOf('*') != -1)) {
contentType = contentResolver.getType(uri);
}
- if (contentType == null)
- {
+ if (contentType == null) {
contentType = MimeUtility.getMimeTypeByExtension(name);
}
- if (size <= 0)
- {
+ if (size <= 0) {
String uriString = uri.toString();
- if (uriString.startsWith("file://"))
- {
+ if (uriString.startsWith("file://")) {
Log.v(K9.LOG_TAG, uriString.substring("file://".length()));
File f = new File(uriString.substring("file://".length()));
size = f.length();
- }
- else
- {
+ } else {
Log.v(K9.LOG_TAG, "Not a file: " + uriString);
}
- }
- else
- {
+ } else {
Log.v(K9.LOG_TAG, "old attachment.size: " + size);
}
Log.v(K9.LOG_TAG, "new attachment.size: " + size);
@@ -1677,61 +1452,52 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
}
@Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data)
- {
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// if a CryptoSystem activity is returning, then mPreventDraftSaving was set to true
mPreventDraftSaving = false;
- if (mAccount.getCryptoProvider().onActivityResult(this, requestCode, resultCode, data, mPgpData))
- {
+ if (mAccount.getCryptoProvider().onActivityResult(this, requestCode, resultCode, data, mPgpData)) {
return;
}
if (resultCode != RESULT_OK)
return;
- if (data == null)
- {
+ if (data == null) {
return;
}
- switch (requestCode)
- {
- case ACTIVITY_REQUEST_PICK_ATTACHMENT:
- addAttachment(data.getData());
- mDraftNeedsSaving = true;
- break;
- case ACTIVITY_CHOOSE_IDENTITY:
- onIdentityChosen(data);
- break;
- case ACTIVITY_CHOOSE_ACCOUNT:
- onAccountChosen(data);
- break;
+ switch (requestCode) {
+ case ACTIVITY_REQUEST_PICK_ATTACHMENT:
+ addAttachment(data.getData());
+ mDraftNeedsSaving = true;
+ break;
+ case ACTIVITY_CHOOSE_IDENTITY:
+ onIdentityChosen(data);
+ break;
+ case ACTIVITY_CHOOSE_ACCOUNT:
+ onAccountChosen(data);
+ break;
}
}
- private void onAccountChosen(final Intent intent)
- {
+ private void onAccountChosen(final Intent intent) {
final Bundle extras = intent.getExtras();
final String uuid = extras.getString(ChooseAccount.EXTRA_ACCOUNT);
final Identity identity = (Identity) extras.getSerializable(ChooseAccount.EXTRA_IDENTITY);
final Account account = Preferences.getPreferences(this).getAccount(uuid);
- if (!mAccount.equals(account))
- {
- if (K9.DEBUG)
- {
+ if (!mAccount.equals(account)) {
+ if (K9.DEBUG) {
Log.v(K9.LOG_TAG, "Switching account from " + mAccount + " to " + account);
}
// on draft edit, make sure we don't keep previous message UID
- if (ACTION_EDIT_DRAFT.equals(getIntent().getAction()))
- {
+ if (ACTION_EDIT_DRAFT.equals(getIntent().getAction())) {
mMessageReference = null;
}
// test whether there is something to save
- if (mDraftNeedsSaving || (mDraftUid != null))
- {
+ if (mDraftNeedsSaving || (mDraftUid != null)) {
final String previousDraftUid = mDraftUid;
final Account previousAccount = mAccount;
@@ -1741,25 +1507,20 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
// actual account switch
mAccount = account;
- if (K9.DEBUG)
- {
+ if (K9.DEBUG) {
Log.v(K9.LOG_TAG, "Account switch, saving new draft in new account");
}
saveMessage();
- if (previousDraftUid != null)
- {
- if (K9.DEBUG)
- {
+ if (previousDraftUid != null) {
+ if (K9.DEBUG) {
Log.v(K9.LOG_TAG, "Account switch, deleting draft from previous account: "
+ previousDraftUid);
}
MessagingController.getInstance(getApplication()).deleteDraft(previousAccount,
previousDraftUid);
}
- }
- else
- {
+ } else {
mAccount = account;
}
// not sure how to handle mFolder, mSourceMessage?
@@ -1768,14 +1529,12 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
switchToIdentity(identity);
}
- private void onIdentityChosen(Intent intent)
- {
+ private void onIdentityChosen(Intent intent) {
Bundle bundle = intent.getExtras();
switchToIdentity((Identity) bundle.getSerializable(ChooseIdentity.EXTRA_IDENTITY));
}
- private void switchToIdentity(Identity identity)
- {
+ private void switchToIdentity(Identity identity) {
mIdentity = identity;
mIdentityChanged = true;
mDraftNeedsSaving = true;
@@ -1783,137 +1542,117 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
updateSignature();
}
- private void updateFrom()
- {
- if (mIdentityChanged)
- {
+ private void updateFrom() {
+ if (mIdentityChanged) {
mFromView.setVisibility(View.VISIBLE);
}
mFromView.setText(getString(R.string.message_view_from_format, mIdentity.getName(), mIdentity.getEmail()));
}
- private void updateSignature()
- {
- if (mIdentity.getSignatureUse())
- {
+ private void updateSignature() {
+ if (mIdentity.getSignatureUse()) {
mSignatureView.setText(mIdentity.getSignature());
mSignatureView.setVisibility(View.VISIBLE);
- }
- else
- {
+ } else {
mSignatureView.setVisibility(View.GONE);
}
}
- public void onClick(View view)
- {
- switch (view.getId())
- {
- case R.id.attachment_delete:
- /*
- * The view is the delete button, and we have previously set the tag of
- * the delete button to the view that owns it. We don't use parent because the
- * view is very complex and could change in the future.
- */
- mAttachments.removeView((View) view.getTag());
- mDraftNeedsSaving = true;
- break;
- case R.id.quoted_text_delete:
- deleteQuotedText();
- mDraftNeedsSaving = true;
- break;
- case R.id.quoted_text_edit:
- mMessageFormat = MessageFormat.TEXT;
- if (mMessageReference != null) // shouldn't happen...
- {
- // TODO - Should we check if mSourceMessageBody is already present and bypass the MessagingController call?
- MessagingController.getInstance(getApplication()).addListener(mListener);
- final Account account = Preferences.getPreferences(this).getAccount(mMessageReference.accountUuid);
- final String folderName = mMessageReference.folderName;
- final String sourceMessageUid = mMessageReference.uid;
- MessagingController.getInstance(getApplication()).loadMessageForView(account, folderName, sourceMessageUid, null);
- }
- break;
+ public void onClick(View view) {
+ switch (view.getId()) {
+ case R.id.attachment_delete:
+ /*
+ * The view is the delete button, and we have previously set the tag of
+ * the delete button to the view that owns it. We don't use parent because the
+ * view is very complex and could change in the future.
+ */
+ mAttachments.removeView((View) view.getTag());
+ mDraftNeedsSaving = true;
+ break;
+ case R.id.quoted_text_delete:
+ deleteQuotedText();
+ mDraftNeedsSaving = true;
+ break;
+ case R.id.quoted_text_edit:
+ mMessageFormat = MessageFormat.TEXT;
+ if (mMessageReference != null) { // shouldn't happen...
+ // TODO - Should we check if mSourceMessageBody is already present and bypass the MessagingController call?
+ MessagingController.getInstance(getApplication()).addListener(mListener);
+ final Account account = Preferences.getPreferences(this).getAccount(mMessageReference.accountUuid);
+ final String folderName = mMessageReference.folderName;
+ final String sourceMessageUid = mMessageReference.uid;
+ MessagingController.getInstance(getApplication()).loadMessageForView(account, folderName, sourceMessageUid, null);
+ }
+ break;
}
}
/**
* Delete the quoted text.
*/
- private void deleteQuotedText()
- {
+ private void deleteQuotedText() {
mQuotedTextBar.setVisibility(View.GONE);
mQuotedText.setVisibility(View.GONE);
mQuotedHTML.setVisibility(View.GONE);
- if (mQuotedHtmlContent != null)
- {
+ if (mQuotedHtmlContent != null) {
mQuotedHtmlContent.clearQuotedContent();
}
}
@Override
- public boolean onOptionsItemSelected(MenuItem item)
- {
- switch (item.getItemId())
- {
- case R.id.send:
- mPgpData.setEncryptionKeys(null);
- onSend();
- break;
- case R.id.save:
- onSave();
- break;
- case R.id.discard:
- onDiscard();
- break;
- case R.id.add_cc_bcc:
- onAddCcBcc();
- break;
- case R.id.add_attachment:
- onAddAttachment();
- break;
- case R.id.add_attachment_image:
- onAddAttachment2("image/*");
- break;
- case R.id.add_attachment_video:
- onAddAttachment2("video/*");
- break;
- case R.id.choose_identity:
- onChooseIdentity();
- break;
- default:
- return super.onOptionsItemSelected(item);
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.send:
+ mPgpData.setEncryptionKeys(null);
+ onSend();
+ break;
+ case R.id.save:
+ onSave();
+ break;
+ case R.id.discard:
+ onDiscard();
+ break;
+ case R.id.add_cc_bcc:
+ onAddCcBcc();
+ break;
+ case R.id.add_attachment:
+ onAddAttachment();
+ break;
+ case R.id.add_attachment_image:
+ onAddAttachment2("image/*");
+ break;
+ case R.id.add_attachment_video:
+ onAddAttachment2("video/*");
+ break;
+ case R.id.choose_identity:
+ onChooseIdentity();
+ break;
+ default:
+ return super.onOptionsItemSelected(item);
}
return true;
}
- private void onChooseIdentity()
- {
+ private void onChooseIdentity() {
// keep things simple: trigger account choice only if there are more
// than 1 account
- if (Preferences.getPreferences(this).getAvailableAccounts().size() > 1)
- {
+ if (Preferences.getPreferences(this).getAvailableAccounts().size() > 1) {
final Intent intent = new Intent(this, ChooseAccount.class);
intent.putExtra(ChooseAccount.EXTRA_ACCOUNT, mAccount.getUuid());
intent.putExtra(ChooseAccount.EXTRA_IDENTITY, mIdentity);
startActivityForResult(intent, ACTIVITY_CHOOSE_ACCOUNT);
- }
- else if (mAccount.getIdentities().size() > 1)
- {
+ } else if (mAccount.getIdentities().size() > 1) {
Intent intent = new Intent(this, ChooseIdentity.class);
intent.putExtra(ChooseIdentity.EXTRA_ACCOUNT, mAccount.getUuid());
startActivityForResult(intent, ACTIVITY_CHOOSE_IDENTITY);
- }
- else
- {
+ } else {
Toast.makeText(this, getString(R.string.no_identities),
Toast.LENGTH_LONG).show();
}
}
@Override
- public boolean onCreateOptionsMenu(Menu menu)
- {
+ public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.message_compose_option, menu);
@@ -1922,13 +1661,11 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
* if the work-around for the Gallery bug is enabled (see Issue 1186).
*/
int found = 0;
- for (int i = menu.size() - 1; i >= 0; i--)
- {
+ for (int i = menu.size() - 1; i >= 0; i--) {
MenuItem item = menu.getItem(i);
int id = item.getItemId();
if ((id == R.id.add_attachment_image) ||
- (id == R.id.add_attachment_video))
- {
+ (id == R.id.add_attachment_video)) {
item.setVisible(K9.useGalleryBugWorkaround());
found++;
}
@@ -1941,62 +1678,50 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
}
@Override
- public void onBackPressed()
- {
+ public void onBackPressed() {
// This will be called either automatically for you on 2.0
// or later, or by the code above on earlier versions of the
// platform.
- if (mDraftNeedsSaving)
- {
+ if (mDraftNeedsSaving) {
showDialog(DIALOG_SAVE_OR_DISCARD_DRAFT_MESSAGE);
- }
- else
- {
+ } else {
finish();
}
}
@Override
- public Dialog onCreateDialog(int id)
- {
- switch (id)
- {
- case DIALOG_SAVE_OR_DISCARD_DRAFT_MESSAGE:
- return new AlertDialog.Builder(this)
- .setTitle(R.string.save_or_discard_draft_message_dlg_title)
- .setMessage(R.string.save_or_discard_draft_message_instructions_fmt)
- .setPositiveButton(R.string.save_draft_action, new DialogInterface.OnClickListener()
- {
- public void onClick(DialogInterface dialog, int whichButton)
- {
- dismissDialog(DIALOG_SAVE_OR_DISCARD_DRAFT_MESSAGE);
- onSave();
- }
- })
- .setNegativeButton(R.string.discard_action, new DialogInterface.OnClickListener()
- {
- public void onClick(DialogInterface dialog, int whichButton)
- {
- dismissDialog(DIALOG_SAVE_OR_DISCARD_DRAFT_MESSAGE);
- onDiscard();
- }
- })
- .create();
+ public Dialog onCreateDialog(int id) {
+ switch (id) {
+ case DIALOG_SAVE_OR_DISCARD_DRAFT_MESSAGE:
+ return new AlertDialog.Builder(this)
+ .setTitle(R.string.save_or_discard_draft_message_dlg_title)
+ .setMessage(R.string.save_or_discard_draft_message_instructions_fmt)
+ .setPositiveButton(R.string.save_draft_action, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int whichButton) {
+ dismissDialog(DIALOG_SAVE_OR_DISCARD_DRAFT_MESSAGE);
+ onSave();
+ }
+ })
+ .setNegativeButton(R.string.discard_action, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int whichButton) {
+ dismissDialog(DIALOG_SAVE_OR_DISCARD_DRAFT_MESSAGE);
+ onDiscard();
+ }
+ })
+ .create();
}
return super.onCreateDialog(id);
}
@Override
- public boolean onKeyDown(int keyCode, KeyEvent event)
- {
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
if (
// TODO - when we move to android 2.0, uncomment this.
// android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ECLAIR &&
keyCode == KeyEvent.KEYCODE_BACK
&& event.getRepeatCount() == 0
- && K9.manageBack())
- {
+ && K9.manageBack()) {
// Take care of calling this method on earlier versions of
// the platform where it doesn't exist.
onBackPressed();
@@ -2009,41 +1734,29 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
/**
* Returns true if all attachments were able to be attached, otherwise returns false.
*/
- private boolean loadAttachments(Part part, int depth) throws MessagingException
- {
- if (part.getBody() instanceof Multipart)
- {
+ private boolean loadAttachments(Part part, int depth) throws MessagingException {
+ if (part.getBody() instanceof Multipart) {
Multipart mp = (Multipart) part.getBody();
boolean ret = true;
- for (int i = 0, count = mp.getCount(); i < count; i++)
- {
- if (!loadAttachments(mp.getBodyPart(i), depth + 1))
- {
+ for (int i = 0, count = mp.getCount(); i < count; i++) {
+ if (!loadAttachments(mp.getBodyPart(i), depth + 1)) {
ret = false;
}
}
return ret;
- }
- else
- {
+ } else {
String contentType = MimeUtility.unfoldAndDecode(part.getContentType());
String name = MimeUtility.getHeaderParameter(contentType, "name");
- if (name != null)
- {
+ if (name != null) {
Body body = part.getBody();
- if (body != null && body instanceof LocalAttachmentBody)
- {
+ if (body != null && body instanceof LocalAttachmentBody) {
final Uri uri = ((LocalAttachmentBody) body).getContentUri();
- mHandler.post(new Runnable()
- {
- public void run()
- {
+ mHandler.post(new Runnable() {
+ public void run() {
addAttachment(uri);
}
});
- }
- else
- {
+ } else {
return false;
}
}
@@ -2056,28 +1769,19 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
* depending on the type of message being composed.
* @param message Source message
*/
- private void processSourceMessage(Message message)
- {
+ private void processSourceMessage(Message message) {
String action = getIntent().getAction();
- try
- {
- if (ACTION_REPLY.equals(action) || ACTION_REPLY_ALL.equals(action))
- {
- if (message.getSubject() != null)
- {
+ try {
+ if (ACTION_REPLY.equals(action) || ACTION_REPLY_ALL.equals(action)) {
+ if (message.getSubject() != null) {
final String subject = prefix.matcher(message.getSubject()).replaceFirst("");
- if (!subject.toLowerCase().startsWith("re:"))
- {
+ if (!subject.toLowerCase().startsWith("re:")) {
mSubjectView.setText("Re: " + subject);
- }
- else
- {
+ } else {
mSubjectView.setText(subject);
}
- }
- else
- {
+ } else {
mSubjectView.setText("");
}
@@ -2086,19 +1790,15 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
* or sender address.
*/
Address[] replyToAddresses;
- if (message.getReplyTo().length > 0)
- {
+ if (message.getReplyTo().length > 0) {
replyToAddresses = message.getReplyTo();
- }
- else
- {
+ } else {
replyToAddresses = message.getFrom();
}
// if we're replying to a message we sent, we probably meant
// to reply to the recipient of that message
- if (mAccount.isAnIdentity(replyToAddresses))
- {
+ if (mAccount.isAnIdentity(replyToAddresses)) {
replyToAddresses = message.getRecipients(RecipientType.TO);
}
@@ -2106,26 +1806,20 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
- if (message.getMessageId() != null && message.getMessageId().length() > 0)
- {
+ if (message.getMessageId() != null && message.getMessageId().length() > 0) {
mInReplyTo = message.getMessageId();
- if (message.getReferences() != null && message.getReferences().length > 0)
- {
+ if (message.getReferences() != null && message.getReferences().length > 0) {
StringBuffer buffy = new StringBuffer();
- for (int i=0; i < message.getReferences().length; i++)
+ for (int i = 0; i < message.getReferences().length; i++)
buffy.append(message.getReferences()[i]);
mReferences = buffy.toString() + " " + mInReplyTo;
- }
- else
- {
+ } else {
mReferences = mInReplyTo;
}
- }
- else
- {
+ } else {
if (K9.DEBUG)
Log.d(K9.LOG_TAG, "could not get Message-ID.");
}
@@ -2133,59 +1827,44 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
// Quote the message and setup the UI.
populateUIWithQuotedMessage();
- if (ACTION_REPLY_ALL.equals(action) || ACTION_REPLY.equals(action))
- {
+ if (ACTION_REPLY_ALL.equals(action) || ACTION_REPLY.equals(action)) {
Identity useIdentity = null;
- for (Address address : message.getRecipients(RecipientType.TO))
- {
+ for (Address address : message.getRecipients(RecipientType.TO)) {
Identity identity = mAccount.findIdentity(address);
- if (identity != null)
- {
+ if (identity != null) {
useIdentity = identity;
break;
}
}
- if (useIdentity == null)
- {
- if (message.getRecipients(RecipientType.CC).length > 0)
- {
- for (Address address : message.getRecipients(RecipientType.CC))
- {
+ if (useIdentity == null) {
+ if (message.getRecipients(RecipientType.CC).length > 0) {
+ for (Address address : message.getRecipients(RecipientType.CC)) {
Identity identity = mAccount.findIdentity(address);
- if (identity != null)
- {
+ if (identity != null) {
useIdentity = identity;
break;
}
}
}
}
- if (useIdentity != null)
- {
+ if (useIdentity != null) {
Identity defaultIdentity = mAccount.getIdentity(0);
- if (useIdentity != defaultIdentity)
- {
+ if (useIdentity != defaultIdentity) {
switchToIdentity(useIdentity);
}
}
}
- if (ACTION_REPLY_ALL.equals(action))
- {
- for (Address address : message.getRecipients(RecipientType.TO))
- {
- if (!mAccount.isAnIdentity(address))
- {
+ if (ACTION_REPLY_ALL.equals(action)) {
+ for (Address address : message.getRecipients(RecipientType.TO)) {
+ if (!mAccount.isAnIdentity(address)) {
addAddress(mToView, address);
}
}
- if (message.getRecipients(RecipientType.CC).length > 0)
- {
- for (Address address : message.getRecipients(RecipientType.CC))
- {
- if (!mAccount.isAnIdentity(address) && !Utility.arrayContains(replyToAddresses, address))
- {
+ if (message.getRecipients(RecipientType.CC).length > 0) {
+ for (Address address : message.getRecipients(RecipientType.CC)) {
+ if (!mAccount.isAnIdentity(address) && !Utility.arrayContains(replyToAddresses, address)) {
addAddress(mCcView, address);
}
@@ -2193,124 +1872,94 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
mCcView.setVisibility(View.VISIBLE);
}
}
- }
- else if (ACTION_FORWARD.equals(action))
- {
- if (message.getSubject() != null && !message.getSubject().toLowerCase().startsWith("fwd:"))
- {
+ } else if (ACTION_FORWARD.equals(action)) {
+ if (message.getSubject() != null && !message.getSubject().toLowerCase().startsWith("fwd:")) {
mSubjectView.setText("Fwd: " + message.getSubject());
- }
- else
- {
+ } else {
mSubjectView.setText(message.getSubject());
}
// Quote the message and setup the UI.
populateUIWithQuotedMessage();
- if (!mSourceMessageProcessed)
- {
- if (!loadAttachments(message, 0))
- {
+ if (!mSourceMessageProcessed) {
+ if (!loadAttachments(message, 0)) {
mHandler.sendEmptyMessage(MSG_SKIPPED_ATTACHMENTS);
}
}
- }
- else if (ACTION_EDIT_DRAFT.equals(action))
- {
+ } else if (ACTION_EDIT_DRAFT.equals(action)) {
mDraftUid = message.getUid();
mSubjectView.setText(message.getSubject());
addAddresses(mToView, message.getRecipients(RecipientType.TO));
- if (message.getRecipients(RecipientType.CC).length > 0)
- {
+ if (message.getRecipients(RecipientType.CC).length > 0) {
addAddresses(mCcView, message.getRecipients(RecipientType.CC));
mCcView.setVisibility(View.VISIBLE);
}
Address[] bccRecipients = message.getRecipients(RecipientType.BCC);
- if (bccRecipients.length > 0)
- {
+ if (bccRecipients.length > 0) {
addAddresses(mBccView, bccRecipients);
String bccAddress = mAccount.getAlwaysBcc();
- if (bccRecipients.length == 1 && bccAddress != null && bccAddress.equals(bccRecipients[0].toString()))
- {
+ if (bccRecipients.length == 1 && bccAddress != null && bccAddress.equals(bccRecipients[0].toString())) {
// If the auto-bcc is the only entry in the BCC list, don't show the Bcc fields.
mBccView.setVisibility(View.GONE);
- }
- else
- {
+ } else {
mBccView.setVisibility(View.VISIBLE);
}
}
// Read In-Reply-To header from draft
final String[] inReplyTo = message.getHeader("In-Reply-To");
- if ((inReplyTo != null) && (inReplyTo.length >= 1))
- {
+ if ((inReplyTo != null) && (inReplyTo.length >= 1)) {
mInReplyTo = inReplyTo[0];
}
// Read References header from draft
final String[] references = message.getHeader("References");
- if ((references != null) && (references.length >= 1))
- {
+ if ((references != null) && (references.length >= 1)) {
mReferences = references[0];
}
- if (!mSourceMessageProcessed)
- {
+ if (!mSourceMessageProcessed) {
loadAttachments(message, 0);
}
// Decode the identity header when loading a draft.
// See buildIdentityHeader(TextBody) for a detailed description of the composition of this blob.
Map k9identity = new HashMap();
- if (message.getHeader(K9.IDENTITY_HEADER) != null && message.getHeader(K9.IDENTITY_HEADER).length > 0 && message.getHeader(K9.IDENTITY_HEADER)[0] != null)
- {
+ if (message.getHeader(K9.IDENTITY_HEADER) != null && message.getHeader(K9.IDENTITY_HEADER).length > 0 && message.getHeader(K9.IDENTITY_HEADER)[0] != null) {
k9identity = parseIdentityHeader(message.getHeader(K9.IDENTITY_HEADER)[0]);
}
Identity newIdentity = new Identity();
- if (k9identity.containsKey(IdentityField.SIGNATURE))
- {
+ if (k9identity.containsKey(IdentityField.SIGNATURE)) {
newIdentity.setSignatureUse(true);
newIdentity.setSignature(k9identity.get(IdentityField.SIGNATURE));
mSignatureChanged = true;
- }
- else
- {
+ } else {
newIdentity.setSignatureUse(message.getFolder().getAccount().getSignatureUse());
newIdentity.setSignature(mIdentity.getSignature());
}
- if (k9identity.containsKey(IdentityField.NAME))
- {
+ if (k9identity.containsKey(IdentityField.NAME)) {
newIdentity.setName(k9identity.get(IdentityField.NAME));
mIdentityChanged = true;
- }
- else
- {
+ } else {
newIdentity.setName(mIdentity.getName());
}
- if (k9identity.containsKey(IdentityField.EMAIL))
- {
+ if (k9identity.containsKey(IdentityField.EMAIL)) {
newIdentity.setEmail(k9identity.get(IdentityField.EMAIL));
mIdentityChanged = true;
- }
- else
- {
+ } else {
newIdentity.setEmail(mIdentity.getEmail());
}
- if (k9identity.containsKey(IdentityField.ORIGINAL_MESSAGE))
- {
+ if (k9identity.containsKey(IdentityField.ORIGINAL_MESSAGE)) {
mMessageReference = null;
- try
- {
+ try {
mMessageReference = new MessageReference(k9identity.get(IdentityField.ORIGINAL_MESSAGE));
- } catch (MessagingException e)
- {
+ } catch (MessagingException e) {
Log.e(K9.LOG_TAG, "Could not decode message reference in identity.", e);
}
}
@@ -2329,25 +1978,19 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
// Always respect the user's current composition format preference, even if the
// draft was saved in a different format.
// TODO - The current implementation doesn't allow a user in HTML mode to edit a draft that wasn't saved with K9mail.
- if (mMessageFormat == MessageFormat.HTML)
- {
- if (k9identity.get(IdentityField.MESSAGE_FORMAT) == null || !MessageFormat.valueOf(k9identity.get(IdentityField.MESSAGE_FORMAT)).equals(MessageFormat.HTML))
- {
+ if (mMessageFormat == MessageFormat.HTML) {
+ if (k9identity.get(IdentityField.MESSAGE_FORMAT) == null || !MessageFormat.valueOf(k9identity.get(IdentityField.MESSAGE_FORMAT)).equals(MessageFormat.HTML)) {
// This message probably wasn't created by us. The exception is legacy
// drafts created before the advent of HTML composition. In those cases,
// we'll display the whole message (including the quoted part) in the
// composition window. If that's the case, try and convert it to text to
// match the behavior in text mode.
mMessageContentView.setText(getBodyTextFromMessage(message, MessageFormat.TEXT));
- }
- else
- {
+ } else {
Part part = MimeUtility.findFirstPartByMimeType(message, "text/html");
- if (part != null) // Shouldn't happen if we were the one who saved it.
- {
+ if (part != null) { // Shouldn't happen if we were the one who saved it.
String text = MimeUtility.getTextFromPart(part);
- if (K9.DEBUG)
- {
+ if (K9.DEBUG) {
Log.d(K9.LOG_TAG, "Loading message with offset " + bodyOffset + ", length " + bodyLength + ". Text length is " + text.length() + ".");
}
@@ -2359,8 +2002,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
StringBuilder quotedHTML = new StringBuilder();
quotedHTML.append(text.substring(0, bodyOffset)); // stuff before the reply
quotedHTML.append(text.substring(bodyOffset + bodyLength));
- if (quotedHTML.length() > 0)
- {
+ if (quotedHTML.length() > 0) {
mQuotedHtmlContent = new InsertableHtmlContent();
mQuotedHtmlContent.setQuotedContent(quotedHTML);
mQuotedHtmlContent.setHeaderInsertionPoint(bodyOffset);
@@ -2371,25 +2013,18 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
}
}
}
- }
- else if (mMessageFormat == MessageFormat.TEXT)
- {
+ } else if (mMessageFormat == MessageFormat.TEXT) {
MessageFormat format = k9identity.get(IdentityField.MESSAGE_FORMAT) != null
? MessageFormat.valueOf(k9identity.get(IdentityField.MESSAGE_FORMAT))
: null;
- if (format == null)
- {
+ if (format == null) {
mMessageContentView.setText(getBodyTextFromMessage(message, MessageFormat.TEXT));
- }
- else if (format.equals(MessageFormat.HTML))
- {
+ } else if (format.equals(MessageFormat.HTML)) {
// We are in text mode, but have an HTML message.
Part htmlPart = MimeUtility.findFirstPartByMimeType(message, "text/html");
- if (htmlPart != null) // Shouldn't happen if we were the one who saved it.
- {
+ if (htmlPart != null) { // Shouldn't happen if we were the one who saved it.
String text = MimeUtility.getTextFromPart(htmlPart);
- if (K9.DEBUG)
- {
+ if (K9.DEBUG) {
Log.d(K9.LOG_TAG, "Loading message with offset " + bodyOffset + ", length " + bodyLength + ". Text length is " + text.length() + ".");
}
@@ -2406,22 +2041,16 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
mQuotedTextBar.setVisibility(View.VISIBLE);
mQuotedText.setVisibility(View.VISIBLE);
- }
- else
- {
+ } else {
Log.e(K9.LOG_TAG, "Found an HTML draft but couldn't find the HTML part! Something's wrong.");
}
- }
- else if (format.equals(MessageFormat.TEXT))
- {
+ } else if (format.equals(MessageFormat.TEXT)) {
Part textPart = MimeUtility.findFirstPartByMimeType(message, "text/plain");
- if (textPart != null)
- {
+ if (textPart != null) {
String text = MimeUtility.getTextFromPart(textPart);
// If we had a body length (and it was valid), separate the composition from the quoted text
// and put them in their respective places in the UI.
- if (bodyLength != null && bodyLength + 1 < text.length()) // + 1 to get rid of the newline we added when saving the draft
- {
+ if (bodyLength != null && bodyLength + 1 < text.length()) { // + 1 to get rid of the newline we added when saving the draft
String bodyText = text.substring(0, bodyLength);
String quotedText = text.substring(bodyLength + 1, text.length());
@@ -2431,22 +2060,16 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
mQuotedTextBar.setVisibility(View.VISIBLE);
mQuotedText.setVisibility(View.VISIBLE);
mQuotedHTML.setVisibility(View.VISIBLE);
- }
- else
- {
+ } else {
mMessageContentView.setText(text);
}
}
- }
- else
- {
+ } else {
Log.e(K9.LOG_TAG, "Unhandled message format.");
}
}
}
- }
- catch (MessagingException me)
- {
+ } catch (MessagingException me) {
/**
* Let the user continue composing their message even if we have a problem processing
* the source message. Log it as an error, though.
@@ -2461,8 +2084,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
* Build and populate the UI with the quoted message.
* @throws MessagingException
*/
- private void populateUIWithQuotedMessage() throws MessagingException
- {
+ private void populateUIWithQuotedMessage() throws MessagingException {
// TODO -- I am assuming that mSourceMessageBody will always be a text part. Is this a safe assumption?
// Handle the original message in the reply
@@ -2470,8 +2092,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
String content = mSourceMessageBody != null
? mSourceMessageBody
: getBodyTextFromMessage(mSourceMessage, mMessageFormat);
- if (mMessageFormat == MessageFormat.HTML)
- {
+ if (mMessageFormat == MessageFormat.HTML) {
// Add the HTML reply header to the top of the content.
mQuotedHtmlContent = quoteOriginalHtmlMessage(mSourceMessage, content, mAccount.getQuoteStyle());
// Load the message with the reply header.
@@ -2482,9 +2103,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
mQuotedTextEdit.setVisibility(View.VISIBLE);
mQuotedText.setVisibility(View.GONE);
- }
- else if (mMessageFormat == MessageFormat.TEXT)
- {
+ } else if (mMessageFormat == MessageFormat.TEXT) {
mQuotedText.setText(quoteOriginalTextMessage(mSourceMessage, content, mAccount.getQuoteStyle()));
mQuotedTextBar.setVisibility(View.VISIBLE);
@@ -2504,43 +2123,35 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
* @return Text in desired format.
* @throws MessagingException
*/
- private String getBodyTextFromMessage(final Message message, final MessageFormat format) throws MessagingException
- {
+ private String getBodyTextFromMessage(final Message message, final MessageFormat format) throws MessagingException {
Part part;
- if (format == MessageFormat.HTML)
- {
+ if (format == MessageFormat.HTML) {
// HTML takes precedence, then text.
part = MimeUtility.findFirstPartByMimeType(message, "text/html");
- if (part != null)
- {
- if(K9.DEBUG)
+ if (part != null) {
+ if (K9.DEBUG)
Log.d(K9.LOG_TAG, "getBodyTextFromMessage: HTML requested, HTML found.");
return MimeUtility.getTextFromPart(part);
}
part = MimeUtility.findFirstPartByMimeType(message, "text/plain");
- if (part != null)
- {
- if(K9.DEBUG)
+ if (part != null) {
+ if (K9.DEBUG)
Log.d(K9.LOG_TAG, "getBodyTextFromMessage: HTML requested, text found.");
return HtmlConverter.textToHtml(MimeUtility.getTextFromPart(part));
}
- }
- else if (format == MessageFormat.TEXT)
- {
+ } else if (format == MessageFormat.TEXT) {
// Text takes precedence, then html.
part = MimeUtility.findFirstPartByMimeType(message, "text/plain");
- if (part != null)
- {
- if(K9.DEBUG)
+ if (part != null) {
+ if (K9.DEBUG)
Log.d(K9.LOG_TAG, "getBodyTextFromMessage: Text requested, text found.");
return MimeUtility.getTextFromPart(part);
}
part = MimeUtility.findFirstPartByMimeType(message, "text/html");
- if (part != null)
- {
- if(K9.DEBUG)
+ if (part != null) {
+ if (K9.DEBUG)
Log.d(K9.LOG_TAG, "getBodyTextFromMessage: Text requested, HTML found.");
return HtmlConverter.htmlToText(MimeUtility.getTextFromPart(part));
}
@@ -2579,13 +2190,11 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
* @param content Content to examine for HTML insertion points
* @return Insertion points and HTML to use for insertion.
*/
- private InsertableHtmlContent findInsertionPoints(final String content)
- {
+ private InsertableHtmlContent findInsertionPoints(final String content) {
InsertableHtmlContent insertable = new InsertableHtmlContent();
// If there is no content, don't bother doing any of the regex dancing.
- if (content == null || content.equals(""))
- {
+ if (content == null || content.equals("")) {
return insertable;
}
@@ -2595,20 +2204,17 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
boolean hasBodyTag = false;
// First see if we have an opening HTML tag. If we don't find one, we'll add one later.
Matcher htmlMatcher = FIND_INSERTION_POINT_HTML.matcher(content);
- if (htmlMatcher.matches())
- {
+ if (htmlMatcher.matches()) {
hasHtmlTag = true;
}
// Look for a HEAD tag. If we're missing a BODY tag, we'll use the close of the HEAD to start our content.
Matcher headMatcher = FIND_INSERTION_POINT_HEAD.matcher(content);
- if (headMatcher.matches())
- {
+ if (headMatcher.matches()) {
hasHeadTag = true;
}
// Look for a BODY tag. This is the ideal place for us to start our content.
Matcher bodyMatcher = FIND_INSERTION_POINT_BODY.matcher(content);
- if (bodyMatcher.matches())
- {
+ if (bodyMatcher.matches()) {
hasBodyTag = true;
}
@@ -2617,22 +2223,17 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
// Given our inspections, let's figure out where to start our content.
// This is the ideal case -- there's a BODY tag and we insert ourselves just after it.
- if (hasBodyTag)
- {
+ if (hasBodyTag) {
insertable.setQuotedContent(new StringBuilder(content));
insertable.setHeaderInsertionPoint(bodyMatcher.end(FIND_INSERTION_POINT_FIRST_GROUP));
- }
- else if (hasHeadTag)
- {
+ } else if (hasHeadTag) {
// Now search for a HEAD tag. We can insert after there.
// If BlackBerry sees a HEAD tag, it inserts right after that, so long as there is no BODY tag. It doesn't
// try to add BODY, either. Right or wrong, it seems to work fine.
insertable.setQuotedContent(new StringBuilder(content));
insertable.setHeaderInsertionPoint(headMatcher.end(FIND_INSERTION_POINT_FIRST_GROUP));
- }
- else if (hasHtmlTag)
- {
+ } else if (hasHtmlTag) {
// Lastly, check for an HTML tag.
// In this case, it will add a HEAD, but no BODY.
StringBuilder newContent = new StringBuilder(content);
@@ -2641,9 +2242,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
insertable.setQuotedContent(newContent);
// The new insertion point is the end of the HTML tag, plus the length of the HEAD content.
insertable.setHeaderInsertionPoint(htmlMatcher.end(FIND_INSERTION_POINT_FIRST_GROUP) + FIND_INSERTION_POINT_HEAD_CONTENT.length());
- }
- else
- {
+ } else {
// If we have none of the above, we probably have a fragment of HTML. Yahoo! and Gmail both do this.
// Again, we add a HEAD, but not BODY.
StringBuilder newContent = new StringBuilder(content);
@@ -2662,14 +2261,12 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
boolean hasBodyEndTag = false;
// First see if we have an opening HTML tag. If we don't find one, we'll add one later.
Matcher htmlEndMatcher = FIND_INSERTION_POINT_HTML_END.matcher(insertable.getQuotedContent());
- if (htmlEndMatcher.matches())
- {
+ if (htmlEndMatcher.matches()) {
hasHtmlEndTag = true;
}
// Look for a BODY tag. This is the ideal place for us to place our footer.
Matcher bodyEndMatcher = FIND_INSERTION_POINT_BODY_END.matcher(insertable.getQuotedContent());
- if (bodyEndMatcher.matches())
- {
+ if (bodyEndMatcher.matches()) {
hasBodyEndTag = true;
}
@@ -2678,17 +2275,12 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
// Now figure out where to put our footer.
// This is the ideal case -- there's a BODY tag and we insert ourselves just before it.
- if (hasBodyEndTag)
- {
+ if (hasBodyEndTag) {
insertable.setFooterInsertionPoint(bodyEndMatcher.start(FIND_INSERTION_POINT_FIRST_GROUP));
- }
- else if (hasHtmlEndTag)
- {
+ } else if (hasHtmlEndTag) {
// Check for an HTML tag. Add ourselves just before it.
insertable.setFooterInsertionPoint(htmlEndMatcher.start(FIND_INSERTION_POINT_FIRST_GROUP));
- }
- else
- {
+ } else {
// If we have none of the above, we probably have a fragment of HTML.
// Set our footer insertion point as the end of the string.
insertable.setFooterInsertionPoint(insertable.getQuotedContent().length());
@@ -2697,13 +2289,10 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
return insertable;
}
- class Listener extends MessagingListener
- {
+ class Listener extends MessagingListener {
@Override
- public void loadMessageForViewStarted(Account account, String folder, String uid)
- {
- if ((mMessageReference == null) || !mMessageReference.uid.equals(uid))
- {
+ public void loadMessageForViewStarted(Account account, String folder, String uid) {
+ if ((mMessageReference == null) || !mMessageReference.uid.equals(uid)) {
return;
}
@@ -2711,10 +2300,8 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
}
@Override
- public void loadMessageForViewFinished(Account account, String folder, String uid, Message message)
- {
- if ((mMessageReference == null) || !mMessageReference.uid.equals(uid))
- {
+ public void loadMessageForViewFinished(Account account, String folder, String uid, Message message) {
+ if ((mMessageReference == null) || !mMessageReference.uid.equals(uid)) {
return;
}
@@ -2722,36 +2309,27 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
}
@Override
- public void loadMessageForViewBodyAvailable(Account account, String folder, String uid, final Message message)
- {
- if ((mMessageReference == null) || !mMessageReference.uid.equals(uid))
- {
+ public void loadMessageForViewBodyAvailable(Account account, String folder, String uid, final Message message) {
+ if ((mMessageReference == null) || !mMessageReference.uid.equals(uid)) {
return;
}
mSourceMessage = message;
- runOnUiThread(new Runnable()
- {
- public void run()
- {
+ runOnUiThread(new Runnable() {
+ public void run() {
// We check to see if we've previously processed the source message since this
// could be called when switching from HTML to text replies. If that happens, we
// only want to update the UI with quoted text (which picks the appropriate
// part).
- if (mSourceProcessed)
- {
- try
- {
+ if (mSourceProcessed) {
+ try {
populateUIWithQuotedMessage();
- } catch (MessagingException e)
- {
+ } catch (MessagingException e) {
// Hm, if we couldn't populate the UI after source reprocessing, let's just delete it?
deleteQuotedText();
Log.e(K9.LOG_TAG, "Could not re-process source message; deleting quoted text to be safe.", e);
}
- }
- else
- {
+ } else {
processSourceMessage(message);
mSourceProcessed = true;
}
@@ -2760,10 +2338,8 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
}
@Override
- public void loadMessageForViewFailed(Account account, String folder, String uid, Throwable t)
- {
- if ((mMessageReference == null) || !mMessageReference.uid.equals(uid))
- {
+ public void loadMessageForViewFailed(Account account, String folder, String uid, Throwable t) {
+ if ((mMessageReference == null) || !mMessageReference.uid.equals(uid)) {
return;
}
mHandler.sendEmptyMessage(MSG_PROGRESS_OFF);
@@ -2771,32 +2347,26 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
}
@Override
- public void messageUidChanged(Account account, String folder, String oldUid, String newUid)
- {
+ public void messageUidChanged(Account account, String folder, String oldUid, String newUid) {
//TODO: is this really necessary here? mDraftUid is update after the call to MessagingController.saveDraft()
// Track UID changes of the draft message
if (account.equals(mAccount) &&
folder.equals(mAccount.getDraftsFolderName()) &&
- oldUid.equals(mDraftUid))
- {
+ oldUid.equals(mDraftUid)) {
mDraftUid = newUid;
}
// Track UID changes of the source message
- if (mMessageReference != null)
- {
+ if (mMessageReference != null) {
final Account sourceAccount = Preferences.getPreferences(MessageCompose.this).getAccount(mMessageReference.accountUuid);
final String sourceFolder = mMessageReference.folderName;
final String sourceMessageUid = mMessageReference.uid;
- if (account.equals(sourceAccount) && (folder.equals(sourceFolder)))
- {
- if (oldUid.equals(sourceMessageUid))
- {
+ if (account.equals(sourceAccount) && (folder.equals(sourceFolder))) {
+ if (oldUid.equals(sourceMessageUid)) {
mMessageReference.uid = newUid;
}
- if ((mSourceMessage != null) && (oldUid.equals(mSourceMessage.getUid())))
- {
+ if ((mSourceMessage != null) && (oldUid.equals(mSourceMessage.getUid()))) {
mSourceMessage.setUid(newUid);
}
}
@@ -2808,12 +2378,10 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
* When we are launched with an intent that includes a mailto: URI, we can actually
* gather quite a few of our message fields from it.
*/
- private void initializeFromMailto(Uri mailtoUri)
- {
+ private void initializeFromMailto(Uri mailtoUri) {
String schemaSpecific = mailtoUri.getSchemeSpecificPart();
int end = schemaSpecific.indexOf('?');
- if (end == -1)
- {
+ if (end == -1) {
end = schemaSpecific.length();
}
@@ -2830,8 +2398,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
// Read additional recipients from the "to" parameter.
List to = uri.getQueryParameters("to");
- if (recipient.length() != 0)
- {
+ if (recipient.length() != 0) {
to = new ArrayList(to);
to.add(0, recipient);
}
@@ -2843,61 +2410,49 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
// Read blind carbon copy recipients from the "bcc" parameter.
ccOrBcc |= setRecipients(mBccView, uri.getQueryParameters("bcc"));
- if (ccOrBcc)
- {
+ if (ccOrBcc) {
// Display CC and BCC text fields if CC or BCC recipients were set by the intent.
onAddCcBcc();
}
// Read subject from the "subject" parameter.
List subject = uri.getQueryParameters("subject");
- if (subject.size() > 0)
- {
+ if (subject.size() > 0) {
mSubjectView.setText(subject.get(0));
}
// Read message body from the "body" parameter.
List body = uri.getQueryParameters("body");
- if (body.size() > 0)
- {
+ if (body.size() > 0) {
mMessageContentView.setText(body.get(0));
}
}
- private class SendMessageTask extends AsyncTask
- {
+ private class SendMessageTask extends AsyncTask {
@Override
- protected Void doInBackground(Void... params)
- {
+ protected Void doInBackground(Void... params) {
/*
* Create the message from all the data the user has entered.
*/
MimeMessage message;
- try
- {
+ try {
message = createMessage(false); // isDraft = true
- }
- catch (MessagingException me)
- {
+ } catch (MessagingException me) {
Log.e(K9.LOG_TAG, "Failed to create new message for send or save.", me);
throw new RuntimeException("Failed to create a new message for send or save.", me);
}
- try
- {
+ try {
final Contacts contacts = Contacts.getInstance(MessageCompose.this);
contacts.markAsContacted(message.getRecipients(RecipientType.TO));
contacts.markAsContacted(message.getRecipients(RecipientType.CC));
contacts.markAsContacted(message.getRecipients(RecipientType.BCC));
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
Log.e(K9.LOG_TAG, "Failed to mark contact as contacted.", e);
}
MessagingController.getInstance(getApplication()).sendMessage(mAccount, message, null);
- if (mDraftUid != null)
- {
+ if (mDraftUid != null) {
MessagingController.getInstance(getApplication()).deleteDraft(mAccount, mDraftUid);
mDraftUid = null;
}
@@ -2906,22 +2461,17 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
}
}
- private class SaveMessageTask extends AsyncTask
- {
+ private class SaveMessageTask extends AsyncTask {
@Override
- protected Void doInBackground(Void... params)
- {
+ protected Void doInBackground(Void... params) {
/*
* Create the message from all the data the user has entered.
*/
MimeMessage message;
- try
- {
+ try {
message = createMessage(true); // isDraft = true
- }
- catch (MessagingException me)
- {
+ } catch (MessagingException me) {
Log.e(K9.LOG_TAG, "Failed to create new message for send or save.", me);
throw new RuntimeException("Failed to create a new message for send or save.", me);
}
@@ -2929,18 +2479,14 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
/*
* Save a draft
*/
- if (mDraftUid != null)
- {
+ if (mDraftUid != null) {
message.setUid(mDraftUid);
- }
- else if (ACTION_EDIT_DRAFT.equals(getIntent().getAction()))
- {
+ } else if (ACTION_EDIT_DRAFT.equals(getIntent().getAction())) {
/*
* We're saving a previously saved draft, so update the new message's uid
* to the old message's uid.
*/
- if (mMessageReference != null)
- {
+ if (mMessageReference != null) {
message.setUid(mMessageReference.uid);
}
}
@@ -2950,8 +2496,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
mDraftUid = draftMessage.getUid();
// Don't display the toast if the user is just changing the orientation
- if ((getChangingConfigurations() & ActivityInfo.CONFIG_ORIENTATION) == 0)
- {
+ if ((getChangingConfigurations() & ActivityInfo.CONFIG_ORIENTATION) == 0) {
mHandler.sendEmptyMessage(MSG_SAVED_DRAFT);
}
return null;
@@ -2969,11 +2514,9 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
* @return Quoted text.
* @throws MessagingException
*/
- private String quoteOriginalTextMessage(final Message originalMessage, final String messageBody, final QuoteStyle quoteStyle) throws MessagingException
- {
+ private String quoteOriginalTextMessage(final Message originalMessage, final String messageBody, final QuoteStyle quoteStyle) throws MessagingException {
String body = messageBody == null ? "" : messageBody;
- if (quoteStyle == QuoteStyle.PREFIX)
- {
+ if (quoteStyle == QuoteStyle.PREFIX) {
StringBuilder quotedText = new StringBuilder(body.length() + QUOTE_BUFFER_LENGTH);
quotedText.append(String.format(
getString(R.string.message_compose_reply_header_fmt),
@@ -2989,30 +2532,23 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
quotedText.append(wrappedText.replaceAll("(?m)^", escapedPrefix));
return quotedText.toString().replaceAll("\\\r", "");
- }
- else if (quoteStyle == QuoteStyle.HEADER)
- {
+ } else if (quoteStyle == QuoteStyle.HEADER) {
StringBuilder quotedText = new StringBuilder(body.length() + QUOTE_BUFFER_LENGTH);
quotedText.append("\n");
quotedText.append(getString(R.string.message_compose_quote_header_separator)).append("\n");
- if (originalMessage.getFrom() != null && Address.toString(originalMessage.getFrom()).length() != 0)
- {
+ if (originalMessage.getFrom() != null && Address.toString(originalMessage.getFrom()).length() != 0) {
quotedText.append(getString(R.string.message_compose_quote_header_from)).append(" ").append(Address.toString(originalMessage.getFrom())).append("\n");
}
- if (originalMessage.getSentDate() != null)
- {
+ if (originalMessage.getSentDate() != null) {
quotedText.append(getString(R.string.message_compose_quote_header_send_date)).append(" ").append(originalMessage.getSentDate()).append("\n");
}
- if (originalMessage.getRecipients(RecipientType.TO) != null && originalMessage.getRecipients(RecipientType.TO).length != 0)
- {
+ if (originalMessage.getRecipients(RecipientType.TO) != null && originalMessage.getRecipients(RecipientType.TO).length != 0) {
quotedText.append(getString(R.string.message_compose_quote_header_to)).append(" ").append(Address.toString(originalMessage.getRecipients(RecipientType.TO))).append("\n");
}
- if (originalMessage.getRecipients(RecipientType.CC) != null && originalMessage.getRecipients(RecipientType.CC).length != 0)
- {
+ if (originalMessage.getRecipients(RecipientType.CC) != null && originalMessage.getRecipients(RecipientType.CC).length != 0) {
quotedText.append(getString(R.string.message_compose_quote_header_cc)).append(" ").append(Address.toString(originalMessage.getRecipients(RecipientType.CC))).append("\n");
}
- if (originalMessage.getSubject() != null)
- {
+ if (originalMessage.getSubject() != null) {
quotedText.append(getString(R.string.message_compose_quote_header_subject)).append(" ").append(originalMessage.getSubject()).append("\n");
}
quotedText.append("\n");
@@ -3020,9 +2556,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
quotedText.append(body);
return quotedText.toString();
- }
- else
- {
+ } else {
// Shouldn't ever happen.
return body;
}
@@ -3036,12 +2570,10 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
* @return Modified insertable message.
* @throws MessagingException
*/
- private InsertableHtmlContent quoteOriginalHtmlMessage(final Message originalMessage, final String messageBody, final QuoteStyle quoteStyle) throws MessagingException
- {
+ private InsertableHtmlContent quoteOriginalHtmlMessage(final Message originalMessage, final String messageBody, final QuoteStyle quoteStyle) throws MessagingException {
InsertableHtmlContent insertable = findInsertionPoints(messageBody);
- if (quoteStyle == QuoteStyle.PREFIX)
- {
+ if (quoteStyle == QuoteStyle.PREFIX) {
StringBuilder header = new StringBuilder(QUOTE_BUFFER_LENGTH);
header.append("");
// Remove all trailing newlines so that the quote starts immediately after the header. "Be like Gmail!"
@@ -3056,31 +2588,24 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
insertable.insertIntoQuotedHeader(header.toString());
insertable.insertIntoQuotedFooter(footer);
- }
- else if (quoteStyle == QuoteStyle.HEADER)
- {
+ } else if (quoteStyle == QuoteStyle.HEADER) {
StringBuilder header = new StringBuilder();
header.append("
\n");
header.append("
\n"); // This gets converted into a horizontal line during html to text conversion.
- if (mSourceMessage.getFrom() != null && Address.toString(mSourceMessage.getFrom()).length() != 0)
- {
+ if (mSourceMessage.getFrom() != null && Address.toString(mSourceMessage.getFrom()).length() != 0) {
header.append("").append(getString(R.string.message_compose_quote_header_from)).append(" ").append(HtmlConverter.textToHtmlFragment(Address.toString(mSourceMessage.getFrom()))).append("
\n");
}
- if (mSourceMessage.getSentDate() != null)
- {
+ if (mSourceMessage.getSentDate() != null) {
header.append("").append(getString(R.string.message_compose_quote_header_send_date)).append(" ").append(mSourceMessage.getSentDate()).append("
\n");
}
- if (mSourceMessage.getRecipients(RecipientType.TO) != null && mSourceMessage.getRecipients(RecipientType.TO).length != 0)
- {
+ if (mSourceMessage.getRecipients(RecipientType.TO) != null && mSourceMessage.getRecipients(RecipientType.TO).length != 0) {
header.append("").append(getString(R.string.message_compose_quote_header_to)).append(" ").append(HtmlConverter.textToHtmlFragment(Address.toString(mSourceMessage.getRecipients(RecipientType.TO)))).append("
\n");
}
- if (mSourceMessage.getRecipients(RecipientType.CC) != null && mSourceMessage.getRecipients(RecipientType.CC).length != 0)
- {
+ if (mSourceMessage.getRecipients(RecipientType.CC) != null && mSourceMessage.getRecipients(RecipientType.CC).length != 0) {
header.append("").append(getString(R.string.message_compose_quote_header_cc)).append(" ").append(HtmlConverter.textToHtmlFragment(Address.toString(mSourceMessage.getRecipients(RecipientType.CC)))).append("
\n");
}
- if (mSourceMessage.getSubject() != null)
- {
+ if (mSourceMessage.getSubject() != null) {
header.append("").append(getString(R.string.message_compose_quote_header_subject)).append(" ").append(HtmlConverter.textToHtmlFragment(mSourceMessage.getSubject())).append("
\n");
}
header.append("\n");
diff --git a/src/com/fsck/k9/activity/MessageInfoHolder.java b/src/com/fsck/k9/activity/MessageInfoHolder.java
index d12ca12ff..e19fb953a 100644
--- a/src/com/fsck/k9/activity/MessageInfoHolder.java
+++ b/src/com/fsck/k9/activity/MessageInfoHolder.java
@@ -4,8 +4,7 @@ import java.util.Date;
import com.fsck.k9.helper.MessageHelper;
import com.fsck.k9.mail.store.LocalStore.LocalMessage;
-public class MessageInfoHolder
-{
+public class MessageInfoHolder {
public String date;
public Date compareDate;
public String compareSubject;
@@ -27,16 +26,13 @@ public class MessageInfoHolder
public String uri;
// Empty constructor for comparison
- public MessageInfoHolder()
- {
+ public MessageInfoHolder() {
this.selected = false;
}
@Override
- public boolean equals(Object o)
- {
- if (o instanceof MessageInfoHolder == false)
- {
+ public boolean equals(Object o) {
+ if (o instanceof MessageInfoHolder == false) {
return false;
}
MessageInfoHolder other = (MessageInfoHolder)o;
@@ -44,15 +40,12 @@ public class MessageInfoHolder
}
@Override
- public int hashCode()
- {
+ public int hashCode() {
return uid.hashCode();
}
- public String getDate(MessageHelper messageHelper)
- {
- if (date == null)
- {
+ public String getDate(MessageHelper messageHelper) {
+ if (date == null) {
date = messageHelper.formatDate(message.getSentDate());
}
return date;
diff --git a/src/com/fsck/k9/activity/MessageList.java b/src/com/fsck/k9/activity/MessageList.java
index 57f32a4ad..5562c88d1 100644
--- a/src/com/fsck/k9/activity/MessageList.java
+++ b/src/com/fsck/k9/activity/MessageList.java
@@ -80,30 +80,26 @@ import com.fsck.k9.mail.store.LocalStore.LocalFolder;
*/
public class MessageList
extends K9Activity
- implements OnClickListener, AdapterView.OnItemClickListener, AnimationListener
-{
+ implements OnClickListener, AdapterView.OnItemClickListener, AnimationListener {
/**
* Reverses the result of a {@link Comparator}.
*
* @param
*/
- public static class ReverseComparator implements Comparator
- {
+ public static class ReverseComparator implements Comparator {
private Comparator mDelegate;
/**
* @param delegate
* Never null
.
*/
- public ReverseComparator(final Comparator delegate)
- {
+ public ReverseComparator(final Comparator delegate) {
mDelegate = delegate;
}
@Override
- public int compare(final T object1, final T object2)
- {
+ public int compare(final T object1, final T object2) {
// arg1 & 2 are mixed up, this is done on purpose
return mDelegate.compare(object2, object1);
}
@@ -115,8 +111,7 @@ public class MessageList
*
* @param
*/
- public static class ComparatorChain implements Comparator
- {
+ public static class ComparatorChain implements Comparator {
private List> mChain;
@@ -124,20 +119,16 @@ public class MessageList
* @param chain
* Comparator chain. Never null
.
*/
- public ComparatorChain(final List> chain)
- {
+ public ComparatorChain(final List> chain) {
mChain = chain;
}
@Override
- public int compare(T object1, T object2)
- {
+ public int compare(T object1, T object2) {
int result = 0;
- for (final Comparator comparator : mChain)
- {
+ for (final Comparator comparator : mChain) {
result = comparator.compare(object1, object2);
- if (result != 0)
- {
+ if (result != 0) {
break;
}
}
@@ -146,74 +137,60 @@ public class MessageList
}
- public static class AttachmentComparator implements Comparator
- {
+ public static class AttachmentComparator implements Comparator {
@Override
- public int compare(MessageInfoHolder object1, MessageInfoHolder object2)
- {
+ public int compare(MessageInfoHolder object1, MessageInfoHolder object2) {
return (object1.message.hasAttachments() ? 0 : 1) - (object2.message.hasAttachments() ? 0 : 1);
}
}
- public static class FlaggedComparator implements Comparator
- {
+ public static class FlaggedComparator implements Comparator {
@Override
- public int compare(MessageInfoHolder object1, MessageInfoHolder object2)
- {
+ public int compare(MessageInfoHolder object1, MessageInfoHolder object2) {
return (object1.flagged ? 0 : 1) - (object2.flagged ? 0 : 1);
}
}
- public static class UnreadComparator implements Comparator
- {
+ public static class UnreadComparator implements Comparator {
@Override
- public int compare(MessageInfoHolder object1, MessageInfoHolder object2)
- {
+ public int compare(MessageInfoHolder object1, MessageInfoHolder object2) {
return (object1.read ? 1 : 0) - (object2.read ? 1 : 0);
}
}
- public static class SenderComparator implements Comparator
- {
+ public static class SenderComparator implements Comparator {
@Override
- public int compare(MessageInfoHolder object1, MessageInfoHolder object2)
- {
+ public int compare(MessageInfoHolder object1, MessageInfoHolder object2) {
return object1.compareCounterparty.toLowerCase().compareTo(object2.compareCounterparty.toLowerCase());
}
}
- public static class DateComparator implements Comparator
- {
+ public static class DateComparator implements Comparator {
@Override
- public int compare(MessageInfoHolder object1, MessageInfoHolder object2)
- {
+ public int compare(MessageInfoHolder object1, MessageInfoHolder object2) {
return object1.compareDate.compareTo(object2.compareDate);
}
}
- public static class SubjectComparator implements Comparator
- {
+ public static class SubjectComparator implements Comparator {
@Override
- public int compare(MessageInfoHolder arg0, MessageInfoHolder arg1)
- {
+ public int compare(MessageInfoHolder arg0, MessageInfoHolder arg1) {
// XXX doesn't respect the Comparator contract since it alters the compared object
- if (arg0.compareSubject == null)
- {
+ if (arg0.compareSubject == null) {
arg0.compareSubject = Utility.stripSubject(arg0.message.getSubject());
}
- if (arg1.compareSubject == null)
- {
+ if (arg1.compareSubject == null) {
arg1.compareSubject = Utility.stripSubject(arg1.message.getSubject());
}
return arg0.compareSubject.compareToIgnoreCase(arg1.compareSubject);
@@ -249,8 +226,7 @@ public class MessageList
*/
private static final Map> SORT_COMPARATORS;
- static
- {
+ static {
// fill the mapping at class time loading
final Map> map = new EnumMap>(SORT_TYPE.class);
@@ -330,18 +306,13 @@ public class MessageList
private StorageManager.StorageListener mStorageListener = new StorageListenerImplementation();
- private final class StorageListenerImplementation implements StorageManager.StorageListener
- {
+ private final class StorageListenerImplementation implements StorageManager.StorageListener {
@Override
- public void onUnmount(String providerId)
- {
- if (mAccount != null && providerId.equals(mAccount.getLocalStorageProviderId()))
- {
- runOnUiThread(new Runnable()
- {
+ public void onUnmount(String providerId) {
+ if (mAccount != null && providerId.equals(mAccount.getLocalStorageProviderId())) {
+ runOnUiThread(new Runnable() {
@Override
- public void run()
- {
+ public void run() {
onAccountUnavailable();
}
});
@@ -349,28 +320,19 @@ public class MessageList
}
@Override
- public void onMount(String providerId)
- {
+ public void onMount(String providerId) {
// no-op
}
}
- class MessageListHandler
- {
- public void removeMessage(final List messages)
- {
- runOnUiThread(new Runnable()
- {
- public void run()
- {
- for (MessageInfoHolder message : messages)
- {
- if (message != null)
- {
- if (mFolderName == null || (message.folder != null && message.folder.name.equals(mFolderName)))
- {
- if (message.selected && mSelectedCount > 0)
- {
+ class MessageListHandler {
+ public void removeMessage(final List messages) {
+ runOnUiThread(new Runnable() {
+ public void run() {
+ for (MessageInfoHolder message : messages) {
+ if (message != null) {
+ if (mFolderName == null || (message.folder != null && message.folder.name.equals(mFolderName))) {
+ if (message.selected && mSelectedCount > 0) {
mSelectedCount--;
}
mAdapter.messages.remove(message);
@@ -385,25 +347,18 @@ public class MessageList
});
}
- public void addMessages(final List messages)
- {
+ public void addMessages(final List messages) {
final boolean wasEmpty = mAdapter.messages.isEmpty();
- runOnUiThread(new Runnable()
- {
- public void run()
- {
- for (final MessageInfoHolder message : messages)
- {
- if (mFolderName == null || (message.folder != null && message.folder.name.equals(mFolderName)))
- {
+ runOnUiThread(new Runnable() {
+ public void run() {
+ for (final MessageInfoHolder message : messages) {
+ if (mFolderName == null || (message.folder != null && message.folder.name.equals(mFolderName))) {
int index;
- synchronized (mAdapter.messages)
- {
+ synchronized (mAdapter.messages) {
index = Collections.binarySearch(mAdapter.messages, message, getComparator());
}
- if (index < 0)
- {
+ if (index < 0) {
index = (index * -1) - 1;
}
@@ -411,8 +366,7 @@ public class MessageList
}
}
- if (wasEmpty)
- {
+ if (wasEmpty) {
mListView.setSelection(0);
}
resetUnreadCountOnThread();
@@ -422,26 +376,19 @@ public class MessageList
});
}
- private void resetUnreadCount()
- {
- runOnUiThread(new Runnable()
- {
- public void run()
- {
+ private void resetUnreadCount() {
+ runOnUiThread(new Runnable() {
+ public void run() {
resetUnreadCountOnThread();
}
});
}
- private void resetUnreadCountOnThread()
- {
- if (mQueryString != null)
- {
+ private void resetUnreadCountOnThread() {
+ if (mQueryString != null) {
int unreadCount = 0;
- synchronized (mAdapter.messages)
- {
- for (MessageInfoHolder holder : mAdapter.messages)
- {
+ synchronized (mAdapter.messages) {
+ for (MessageInfoHolder holder : mAdapter.messages) {
unreadCount += holder.read ? 0 : 1;
}
}
@@ -450,16 +397,12 @@ public class MessageList
}
}
- private void sortMessages()
- {
+ private void sortMessages() {
final Comparator chainComparator = getComparator();
- runOnUiThread(new Runnable()
- {
- public void run()
- {
- synchronized (mAdapter.messages)
- {
+ runOnUiThread(new Runnable() {
+ public void run() {
+ synchronized (mAdapter.messages) {
Collections.sort(mAdapter.messages, chainComparator);
}
mAdapter.notifyDataSetChanged();
@@ -471,34 +414,26 @@ public class MessageList
* @return The comparator to use to display messages in an ordered
* fashion. Never null
.
*/
- protected Comparator getComparator()
- {
- final List> chain = new ArrayList>(2 /* we add 2 comparators at most */ );
+ protected Comparator getComparator() {
+ final List> chain = new ArrayList>(2 /* we add 2 comparators at most */);
{
// add the specified comparator
final Comparator comparator = SORT_COMPARATORS.get(sortType);
- if (sortAscending)
- {
+ if (sortAscending) {
chain.add(comparator);
- }
- else
- {
+ } else {
chain.add(new ReverseComparator(comparator));
}
}
{
// add the date comparator if not already specified
- if (sortType != SORT_TYPE.SORT_DATE)
- {
+ if (sortType != SORT_TYPE.SORT_DATE) {
final Comparator comparator = SORT_COMPARATORS.get(SORT_TYPE.SORT_DATE);
- if (sortDateAscending)
- {
+ if (sortDateAscending) {
chain.add(comparator);
- }
- else
- {
+ } else {
chain.add(new ReverseComparator(comparator));
}
}
@@ -510,43 +445,33 @@ public class MessageList
return chainComparator;
}
- public void folderLoading(String folder, boolean loading)
- {
- if (mCurrentFolder != null && mCurrentFolder.name.equals(folder))
- {
+ public void folderLoading(String folder, boolean loading) {
+ if (mCurrentFolder != null && mCurrentFolder.name.equals(folder)) {
mCurrentFolder.loading = loading;
}
}
- private void refreshTitle()
- {
- runOnUiThread(new Runnable()
- {
- public void run()
- {
+ private void refreshTitle() {
+ runOnUiThread(new Runnable() {
+ public void run() {
refreshTitleOnThread();
}
});
}
- private void refreshTitleOnThread()
- {
+ private void refreshTitleOnThread() {
setWindowTitle();
setWindowProgress();
}
- private void setWindowProgress()
- {
+ private void setWindowProgress() {
int level = Window.PROGRESS_END;
- if (mCurrentFolder != null && mCurrentFolder.loading && mAdapter.mListener.getFolderTotal() > 0)
- {
+ if (mCurrentFolder != null && mCurrentFolder.loading && mAdapter.mListener.getFolderTotal() > 0) {
int divisor = mAdapter.mListener.getFolderTotal();
- if (divisor != 0)
- {
+ if (divisor != 0) {
level = (Window.PROGRESS_END / divisor) * (mAdapter.mListener.getFolderCompleted()) ;
- if (level > Window.PROGRESS_END)
- {
+ if (level > Window.PROGRESS_END) {
level = Window.PROGRESS_END;
}
}
@@ -555,76 +480,59 @@ public class MessageList
getWindow().setFeatureInt(Window.FEATURE_PROGRESS, level);
}
- private void setWindowTitle()
- {
+ private void setWindowTitle() {
String displayName;
- if (mFolderName != null)
- {
+ if (mFolderName != null) {
displayName = mFolderName;
- if (K9.INBOX.equalsIgnoreCase(displayName))
- {
+ if (K9.INBOX.equalsIgnoreCase(displayName)) {
displayName = getString(R.string.special_mailbox_name_inbox);
}
String dispString = mAdapter.mListener.formatHeader(MessageList.this, getString(R.string.message_list_title, mAccount.getDescription(), displayName), mUnreadMessageCount, getTimeFormat());
setTitle(dispString);
- }
- else if (mQueryString != null)
- {
- if (mTitle != null)
- {
+ } else if (mQueryString != null) {
+ if (mTitle != null) {
String dispString = mAdapter.mListener.formatHeader(MessageList.this, mTitle, mUnreadMessageCount, getTimeFormat());
setTitle(dispString);
- }
- else
- {
- setTitle(getString(R.string.search_results) + ": "+ mQueryString);
+ } else {
+ setTitle(getString(R.string.search_results) + ": " + mQueryString);
}
}
}
- public void progress(final boolean progress)
- {
- runOnUiThread(new Runnable()
- {
- public void run()
- {
+ public void progress(final boolean progress) {
+ runOnUiThread(new Runnable() {
+ public void run() {
showProgressIndicator(progress);
}
});
}
}
- public static void actionHandleFolder(Context context, Account account, String folder)
- {
- Intent intent = actionHandleFolderIntent(context,account,folder);
+ public static void actionHandleFolder(Context context, Account account, String folder) {
+ Intent intent = actionHandleFolderIntent(context, account, folder);
context.startActivity(intent);
}
- public static Intent actionHandleFolderIntent(Context context, Account account, String folder)
- {
+ public static Intent actionHandleFolderIntent(Context context, Account account, String folder) {
Intent intent = new Intent(context, MessageList.class);
intent.putExtra(EXTRA_ACCOUNT, account.getUuid());
- if (folder != null)
- {
+ if (folder != null) {
intent.putExtra(EXTRA_FOLDER, folder);
}
return intent;
}
- public static void actionHandle(Context context, String title, String queryString, boolean integrate, Flag[] flags, Flag[] forbiddenFlags)
- {
+ public static void actionHandle(Context context, String title, String queryString, boolean integrate, Flag[] flags, Flag[] forbiddenFlags) {
Intent intent = new Intent(context, MessageList.class);
intent.putExtra(EXTRA_QUERY, queryString);
- if (flags != null)
- {
+ if (flags != null) {
intent.putExtra(EXTRA_QUERY_FLAGS, Utility.combine(flags, ','));
}
- if (forbiddenFlags != null)
- {
+ if (forbiddenFlags != null) {
intent.putExtra(EXTRA_FORBIDDEN_FLAGS, Utility.combine(forbiddenFlags, ','));
}
intent.putExtra(EXTRA_INTEGRATE, integrate);
@@ -632,16 +540,13 @@ public class MessageList
context.startActivity(intent);
}
- public static void actionHandle(Context context, String title, SearchSpecification searchSpecification)
- {
+ public static void actionHandle(Context context, String title, SearchSpecification searchSpecification) {
Intent intent = new Intent(context, MessageList.class);
intent.putExtra(EXTRA_QUERY, searchSpecification.getQuery());
- if (searchSpecification.getRequiredFlags() != null)
- {
+ if (searchSpecification.getRequiredFlags() != null) {
intent.putExtra(EXTRA_QUERY_FLAGS, Utility.combine(searchSpecification.getRequiredFlags(), ','));
}
- if (searchSpecification.getForbiddenFlags() != null)
- {
+ if (searchSpecification.getForbiddenFlags() != null) {
intent.putExtra(EXTRA_FORBIDDEN_FLAGS, Utility.combine(searchSpecification.getForbiddenFlags(), ','));
}
intent.putExtra(EXTRA_INTEGRATE, searchSpecification.isIntegrate());
@@ -652,31 +557,25 @@ public class MessageList
}
@Override
- public void onItemClick(AdapterView> parent, View view, int position, long id)
- {
- if (mCurrentFolder != null && ((position+1) == mAdapter.getCount()))
- {
+ public void onItemClick(AdapterView> parent, View view, int position, long id) {
+ if (mCurrentFolder != null && ((position + 1) == mAdapter.getCount())) {
mController.loadMoreMessages(mAccount, mFolderName, mAdapter.mListener);
return;
}
MessageInfoHolder message = (MessageInfoHolder) mAdapter.getItem(position);
- if (mSelectedCount > 0)
- {
+ if (mSelectedCount > 0) {
// In multiselect mode make sure that clicking on the item results
// in toggling the 'selected' checkbox.
setSelected(message, !message.selected);
- }
- else
- {
+ } else {
onOpenMessage(message);
}
}
@Override
- public void onCreate(Bundle savedInstanceState)
- {
- context=this;
+ public void onCreate(Bundle savedInstanceState) {
+ context = this;
super.onCreate(savedInstanceState);
mInflater = getLayoutInflater();
@@ -685,8 +584,7 @@ public class MessageList
}
@Override
- public void onNewIntent(Intent intent)
- {
+ public void onNewIntent(Intent intent) {
setIntent(intent); // onNewIntent doesn't autoset our "internal" intent
// Only set "touchable" when we're first starting up the activity.
@@ -699,30 +597,25 @@ public class MessageList
mFolderName = intent.getStringExtra(EXTRA_FOLDER);
mQueryString = intent.getStringExtra(EXTRA_QUERY);
- if (mAccount != null && !mAccount.isAvailable(this))
- {
+ if (mAccount != null && !mAccount.isAvailable(this)) {
Log.i(K9.LOG_TAG, "not opening MessageList of unavailable account");
onAccountUnavailable();
return;
}
String queryFlags = intent.getStringExtra(EXTRA_QUERY_FLAGS);
- if (queryFlags != null)
- {
+ if (queryFlags != null) {
String[] flagStrings = queryFlags.split(",");
mQueryFlags = new Flag[flagStrings.length];
- for (int i = 0; i < flagStrings.length; i++)
- {
+ for (int i = 0; i < flagStrings.length; i++) {
mQueryFlags[i] = Flag.valueOf(flagStrings[i]);
}
}
String forbiddenFlags = intent.getStringExtra(EXTRA_FORBIDDEN_FLAGS);
- if (forbiddenFlags != null)
- {
+ if (forbiddenFlags != null) {
String[] flagStrings = forbiddenFlags.split(",");
mForbiddenFlags = new Flag[flagStrings.length];
- for (int i = 0; i < flagStrings.length; i++)
- {
+ for (int i = 0; i < flagStrings.length; i++) {
mForbiddenFlags[i] = Flag.valueOf(flagStrings[i]);
}
}
@@ -733,16 +626,14 @@ public class MessageList
// Take the initial folder into account only if we are *not* restoring
// the activity already.
- if (mFolderName == null && mQueryString == null)
- {
+ if (mFolderName == null && mQueryString == null) {
mFolderName = mAccount.getAutoExpandFolderName();
}
mAdapter = new MessageListAdapter();
restorePreviousData();
- if (mFolderName != null)
- {
+ if (mFolderName != null) {
mCurrentFolder = mAdapter.getFolder(mFolderName, mAccount);
}
@@ -751,19 +642,16 @@ public class MessageList
}
@SuppressWarnings("unchecked")
- private void restorePreviousData()
- {
+ private void restorePreviousData() {
final Object previousData = getLastNonConfigurationInstance();
- if (previousData != null)
- {
+ if (previousData != null) {
mAdapter.messages.addAll((List) previousData);
}
}
@Override
- public void onPause()
- {
+ public void onPause() {
super.onPause();
mController.removeListener(mAdapter.mListener);
saveListState();
@@ -771,32 +659,25 @@ public class MessageList
StorageManager.getInstance(getApplication()).removeListener(mStorageListener);
}
- public void saveListState()
- {
+ public void saveListState() {
mState = new Bundle();
mState.putInt(EXTRA_LIST_POSITION, mListView.getSelectedItemPosition());
}
- public void restoreListState()
- {
- if (mState == null)
- {
+ public void restoreListState() {
+ if (mState == null) {
return;
}
int pos = mState.getInt(EXTRA_LIST_POSITION, ListView.INVALID_POSITION);
- if (pos >= mListView.getCount())
- {
+ if (pos >= mListView.getCount()) {
pos = mListView.getCount() - 1;
}
- if (pos == ListView.INVALID_POSITION)
- {
+ if (pos == ListView.INVALID_POSITION) {
mListView.setSelected(false);
- }
- else
- {
+ } else {
mListView.setSelection(pos);
}
}
@@ -807,12 +688,10 @@ public class MessageList
* are updated.
*/
@Override
- public void onResume()
- {
+ public void onResume() {
super.onResume();
- if (mAccount != null && !mAccount.isAvailable(this))
- {
+ if (mAccount != null && !mAccount.isAvailable(this)) {
onAccountUnavailable();
return;
}
@@ -826,48 +705,34 @@ public class MessageList
sortDateAscending = mController.isSortAscending(SORT_TYPE.SORT_DATE);
mController.addListener(mAdapter.mListener);
- if (mAccount != null)
- {
+ if (mAccount != null) {
mController.notifyAccountCancel(this, mAccount);
MessagingController.getInstance(getApplication()).notifyAccountCancel(this, mAccount);
}
- if (mAdapter.messages.isEmpty())
- {
- if (mFolderName != null)
- {
+ if (mAdapter.messages.isEmpty()) {
+ if (mFolderName != null) {
mController.listLocalMessages(mAccount, mFolderName, mAdapter.mListener);
- }
- else if (mQueryString != null)
- {
+ } else if (mQueryString != null) {
mController.searchLocalMessages(mAccountUuids, mFolderNames, null, mQueryString, mIntegrate, mQueryFlags, mForbiddenFlags, mAdapter.mListener);
}
- }
- else
- {
- new Thread()
- {
+ } else {
+ new Thread() {
@Override
- public void run()
- {
+ public void run() {
mAdapter.markAllMessagesAsDirty();
- if (mFolderName != null)
- {
+ if (mFolderName != null) {
mController.listLocalMessagesSynchronous(mAccount, mFolderName, mAdapter.mListener);
- }
- else if (mQueryString != null)
- {
+ } else if (mQueryString != null) {
mController.searchLocalMessagesSynchronous(mAccountUuids, mFolderNames, null, mQueryString, mIntegrate, mQueryFlags, mForbiddenFlags, mAdapter.mListener);
}
mAdapter.pruneDirtyMessages();
- runOnUiThread(new Runnable()
- {
- public void run()
- {
+ runOnUiThread(new Runnable() {
+ public void run() {
mAdapter.notifyDataSetChanged();
restoreListState();
}
@@ -878,15 +743,13 @@ public class MessageList
.start();
}
- if (mAccount != null && mFolderName != null)
- {
+ if (mAccount != null && mFolderName != null) {
mController.getFolderUnreadMessageCount(mAccount, mFolderName, mAdapter.mListener);
}
mHandler.refreshTitle();
}
- private void initializeLayout()
- {
+ private void initializeLayout() {
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
requestWindowFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.message_list);
@@ -913,12 +776,9 @@ public class MessageList
// Gesture detection
gestureDetector = new GestureDetector(new MyGestureDetector());
- gestureListener = new View.OnTouchListener()
- {
- public boolean onTouch(View v, MotionEvent event)
- {
- if (gestureDetector.onTouchEvent(event))
- {
+ gestureListener = new View.OnTouchListener() {
+ public boolean onTouch(View v, MotionEvent event) {
+ if (gestureDetector.onTouchEvent(event)) {
return true;
}
return false;
@@ -929,44 +789,34 @@ public class MessageList
}
@Override
- public Object onRetainNonConfigurationInstance()
- {
+ public Object onRetainNonConfigurationInstance() {
return mAdapter.messages;
}
@Override
- public void onBackPressed()
- {
+ public void onBackPressed() {
// This will be called either automatically for you on 2.0
// or later, or by the code above on earlier versions of the
// platform.
- if (K9.manageBack())
- {
- if (mQueryString == null)
- {
+ if (K9.manageBack()) {
+ if (mQueryString == null) {
onShowFolderList();
- }
- else
- {
+ } else {
onAccounts();
}
- }
- else
- {
+ } else {
finish();
}
}
@Override
- public boolean onKeyDown(int keyCode, KeyEvent event)
- {
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
if (
// XXX TODO - when we go to android 2.0, uncomment this
// android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ECLAIR &&
keyCode == KeyEvent.KEYCODE_BACK
&& event.getRepeatCount() == 0
- )
- {
+ ) {
// Take care of calling this method on earlier versions of
// the platform where it doesn't exist.
onBackPressed();
@@ -974,212 +824,163 @@ public class MessageList
}
// Shortcuts that work no matter what is selected
- switch (keyCode)
- {
+ switch (keyCode) {
- // messagelist is actually a K9Activity, not a K9ListActivity
- // This saddens me greatly, but to support volume key navigation
- // in MessageView, we implement this bit of wrapper code
- case KeyEvent.KEYCODE_VOLUME_UP:
- {
- if (K9.useVolumeKeysForListNavigationEnabled())
- {
- int currentPosition = mListView.getSelectedItemPosition();
- if (currentPosition == AdapterView.INVALID_POSITION || mListView.isInTouchMode())
- {
- currentPosition = mListView.getFirstVisiblePosition();
- }
- if (currentPosition > 0)
- {
- mListView.setSelection(currentPosition - 1);
- }
- return true;
+ // messagelist is actually a K9Activity, not a K9ListActivity
+ // This saddens me greatly, but to support volume key navigation
+ // in MessageView, we implement this bit of wrapper code
+ case KeyEvent.KEYCODE_VOLUME_UP: {
+ if (K9.useVolumeKeysForListNavigationEnabled()) {
+ int currentPosition = mListView.getSelectedItemPosition();
+ if (currentPosition == AdapterView.INVALID_POSITION || mListView.isInTouchMode()) {
+ currentPosition = mListView.getFirstVisiblePosition();
}
- return false;
+ if (currentPosition > 0) {
+ mListView.setSelection(currentPosition - 1);
+ }
+ return true;
}
- case KeyEvent.KEYCODE_VOLUME_DOWN:
- {
- if (K9.useVolumeKeysForListNavigationEnabled())
- {
- int currentPosition = mListView.getSelectedItemPosition();
- if (currentPosition == AdapterView.INVALID_POSITION || mListView.isInTouchMode())
- {
- currentPosition = mListView.getFirstVisiblePosition();
- }
+ return false;
+ }
+ case KeyEvent.KEYCODE_VOLUME_DOWN: {
+ if (K9.useVolumeKeysForListNavigationEnabled()) {
+ int currentPosition = mListView.getSelectedItemPosition();
+ if (currentPosition == AdapterView.INVALID_POSITION || mListView.isInTouchMode()) {
+ currentPosition = mListView.getFirstVisiblePosition();
+ }
- if (currentPosition < mListView.getCount())
- {
- mListView.setSelection(currentPosition + 1);
- }
- return true;
+ if (currentPosition < mListView.getCount()) {
+ mListView.setSelection(currentPosition + 1);
}
+ return true;
+ }
+ return false;
+ }
+ case KeyEvent.KEYCODE_DPAD_LEFT: {
+ if (mBatchButtonArea.hasFocus()) {
return false;
- }
- case KeyEvent.KEYCODE_DPAD_LEFT:
- {
- if (mBatchButtonArea.hasFocus())
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- case KeyEvent.KEYCODE_DPAD_RIGHT:
- {
- if (mBatchButtonArea.hasFocus())
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- case KeyEvent.KEYCODE_C:
- {
- onCompose();
+ } else {
return true;
}
- case KeyEvent.KEYCODE_Q:
- {
- onShowFolderList();
- return true;
- }
- case KeyEvent.KEYCODE_O:
- {
- onCycleSort();
- return true;
- }
- case KeyEvent.KEYCODE_I:
- {
- onToggleSortAscending();
- return true;
- }
- case KeyEvent.KEYCODE_H:
- {
- Toast toast = Toast.makeText(this, R.string.message_list_help_key, Toast.LENGTH_LONG);
- toast.show();
+ }
+ case KeyEvent.KEYCODE_DPAD_RIGHT: {
+ if (mBatchButtonArea.hasFocus()) {
+ return false;
+ } else {
return true;
}
}
+ case KeyEvent.KEYCODE_C: {
+ onCompose();
+ return true;
+ }
+ case KeyEvent.KEYCODE_Q: {
+ onShowFolderList();
+ return true;
+ }
+ case KeyEvent.KEYCODE_O: {
+ onCycleSort();
+ return true;
+ }
+ case KeyEvent.KEYCODE_I: {
+ onToggleSortAscending();
+ return true;
+ }
+ case KeyEvent.KEYCODE_H: {
+ Toast toast = Toast.makeText(this, R.string.message_list_help_key, Toast.LENGTH_LONG);
+ toast.show();
+ return true;
+ }
+ }
boolean retval = true;
int position = mListView.getSelectedItemPosition();
- try
- {
- if (position >= 0)
- {
+ try {
+ if (position >= 0) {
MessageInfoHolder message = (MessageInfoHolder) mAdapter.getItem(position);
- if (message != null)
- {
- switch (keyCode)
- {
- case KeyEvent.KEYCODE_DEL:
- {
- onDelete(message, position);
- return true;
- }
- case KeyEvent.KEYCODE_S:
- {
- setSelected(message, !message.selected);
- return true;
- }
- case KeyEvent.KEYCODE_D:
- {
- onDelete(message, position);
- return true;
- }
- case KeyEvent.KEYCODE_F:
- {
- onForward(message);
- return true;
- }
- case KeyEvent.KEYCODE_A:
- {
- onReplyAll(message);
- return true;
- }
- case KeyEvent.KEYCODE_R:
- {
- onReply(message);
- return true;
- }
- case KeyEvent.KEYCODE_G:
- {
- onToggleFlag(message);
- return true;
- }
- case KeyEvent.KEYCODE_M:
- {
- onMove(message);
- return true;
- }
- case KeyEvent.KEYCODE_V:
- {
- onArchive(message);
- return true;
- }
- case KeyEvent.KEYCODE_Y:
- {
- onCopy(message);
- return true;
- }
- case KeyEvent.KEYCODE_Z:
- {
- onToggleRead(message);
- return true;
- }
+ if (message != null) {
+ switch (keyCode) {
+ case KeyEvent.KEYCODE_DEL: {
+ onDelete(message, position);
+ return true;
+ }
+ case KeyEvent.KEYCODE_S: {
+ setSelected(message, !message.selected);
+ return true;
+ }
+ case KeyEvent.KEYCODE_D: {
+ onDelete(message, position);
+ return true;
+ }
+ case KeyEvent.KEYCODE_F: {
+ onForward(message);
+ return true;
+ }
+ case KeyEvent.KEYCODE_A: {
+ onReplyAll(message);
+ return true;
+ }
+ case KeyEvent.KEYCODE_R: {
+ onReply(message);
+ return true;
+ }
+ case KeyEvent.KEYCODE_G: {
+ onToggleFlag(message);
+ return true;
+ }
+ case KeyEvent.KEYCODE_M: {
+ onMove(message);
+ return true;
+ }
+ case KeyEvent.KEYCODE_V: {
+ onArchive(message);
+ return true;
+ }
+ case KeyEvent.KEYCODE_Y: {
+ onCopy(message);
+ return true;
+ }
+ case KeyEvent.KEYCODE_Z: {
+ onToggleRead(message);
+ return true;
+ }
}
}
}
- }
- finally
- {
+ } finally {
retval = super.onKeyDown(keyCode, event);
}
return retval;
}
@Override
- public boolean onKeyUp(int keyCode, KeyEvent event)
- {
+ public boolean onKeyUp(int keyCode, KeyEvent event) {
// Swallow these events too to avoid the audible notification of a volume change
- if (K9.useVolumeKeysForListNavigationEnabled())
- {
- if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP) || (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN))
- {
+ if (K9.useVolumeKeysForListNavigationEnabled()) {
+ if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP) || (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) {
if (K9.DEBUG)
Log.v(K9.LOG_TAG, "Swallowed key up.");
return true;
}
}
- return super.onKeyUp(keyCode,event);
+ return super.onKeyUp(keyCode, event);
}
- private void onResendMessage(MessageInfoHolder message)
- {
+ private void onResendMessage(MessageInfoHolder message) {
MessageCompose.actionEditDraft(this, message.message.getFolder().getAccount(), message.message);
}
- private void onOpenMessage(MessageInfoHolder message)
- {
- if (message.folder.name.equals(message.message.getFolder().getAccount().getDraftsFolderName()))
- {
+ private void onOpenMessage(MessageInfoHolder message) {
+ if (message.folder.name.equals(message.message.getFolder().getAccount().getDraftsFolderName())) {
MessageCompose.actionEditDraft(this, message.message.getFolder().getAccount(), message.message);
- }
- else
- {
+ } else {
// Need to get the list before the sort starts
ArrayList messageRefs = new ArrayList();
- synchronized (mAdapter.messages)
- {
- for (MessageInfoHolder holder : mAdapter.messages)
- {
+ synchronized (mAdapter.messages) {
+ for (MessageInfoHolder holder : mAdapter.messages) {
MessageReference ref = holder.message.makeMessageReference();
messageRefs.add(ref);
}
@@ -1197,58 +998,45 @@ public class MessageList
* then go away. I've gone back and forth on this, and this gives a
* better UI experience, so I am putting it back in.
*/
- if (!message.read)
- {
+ if (!message.read) {
message.read = true;
}
}
- private void onAccounts()
- {
+ private void onAccounts() {
Accounts.listAccounts(this);
finish();
}
- private void onShowFolderList()
- {
+ private void onShowFolderList() {
FolderList.actionHandleAccount(this, mAccount);
finish();
}
- private void onCompose()
- {
- if (mQueryString != null)
- {
+ private void onCompose() {
+ if (mQueryString != null) {
/*
* If we have a query string, we don't have an account to let
* compose start the default action.
*/
MessageCompose.actionCompose(this, null);
- }
- else
- {
+ } else {
MessageCompose.actionCompose(this, mAccount);
}
}
- private void onEditPrefs()
- {
+ private void onEditPrefs() {
Prefs.actionPrefs(this);
}
- private void onEditAccount()
- {
+ private void onEditAccount() {
AccountSettings.actionSettings(this, mAccount);
}
- private void changeSort(SORT_TYPE newSortType)
- {
- if (sortType == newSortType)
- {
+ private void changeSort(SORT_TYPE newSortType) {
+ if (sortType == newSortType) {
onToggleSortAscending();
- }
- else
- {
+ } else {
sortType = newSortType;
mController.setSortType(sortType);
sortAscending = mController.isSortAscending(sortType);
@@ -1257,8 +1045,7 @@ public class MessageList
}
}
- private void reSort()
- {
+ private void reSort() {
int toastString = sortType.getToast(sortAscending);
Toast toast = Toast.makeText(this, toastString, Toast.LENGTH_SHORT);
@@ -1267,15 +1054,12 @@ public class MessageList
mHandler.sortMessages();
}
- private void onCycleSort()
- {
+ private void onCycleSort() {
SORT_TYPE[] sorts = SORT_TYPE.values();
int curIndex = 0;
- for (int i = 0; i < sorts.length; i++)
- {
- if (sorts[i] == sortType)
- {
+ for (int i = 0; i < sorts.length; i++) {
+ if (sorts[i] == sortType) {
curIndex = i;
break;
}
@@ -1283,16 +1067,14 @@ public class MessageList
curIndex++;
- if (curIndex == sorts.length)
- {
+ if (curIndex == sorts.length) {
curIndex = 0;
}
changeSort(sorts[curIndex]);
}
- private void onToggleSortAscending()
- {
+ private void onToggleSortAscending() {
mController.setSortAscending(sortType, !sortAscending);
sortAscending = mController.isSortAscending(sortType);
@@ -1301,21 +1083,17 @@ public class MessageList
reSort();
}
- private void onDelete(MessageInfoHolder holder, int position)
- {
+ private void onDelete(MessageInfoHolder holder, int position) {
mAdapter.removeMessage(holder);
mController.deleteMessages(new Message[] { holder.message }, null);
}
- private void onMove(MessageInfoHolder holder)
- {
- if (!mController.isMoveCapable(holder.message.getFolder().getAccount()))
- {
+ private void onMove(MessageInfoHolder holder) {
+ if (!mController.isMoveCapable(holder.message.getFolder().getAccount())) {
return;
}
- if (!mController.isMoveCapable(holder.message))
- {
+ if (!mController.isMoveCapable(holder.message)) {
Toast toast = Toast.makeText(this, R.string.move_copy_cannot_copy_unsynced_message, Toast.LENGTH_LONG);
toast.show();
return;
@@ -1331,15 +1109,12 @@ public class MessageList
startActivityForResult(intent, ACTIVITY_CHOOSE_FOLDER_MOVE);
}
- private void onArchive(MessageInfoHolder holder)
- {
- if (!mController.isMoveCapable(holder.message.getFolder().getAccount()))
- {
+ private void onArchive(MessageInfoHolder holder) {
+ if (!mController.isMoveCapable(holder.message.getFolder().getAccount())) {
return;
}
- if (!mController.isMoveCapable(holder.message))
- {
+ if (!mController.isMoveCapable(holder.message)) {
Toast toast = Toast.makeText(this, R.string.move_copy_cannot_copy_unsynced_message, Toast.LENGTH_LONG);
toast.show();
return;
@@ -1348,15 +1123,12 @@ public class MessageList
onMoveChosen(holder, holder.message.getFolder().getAccount().getArchiveFolderName());
}
- private void onSpam(MessageInfoHolder holder)
- {
- if (!mController.isMoveCapable(holder.message.getFolder().getAccount()))
- {
+ private void onSpam(MessageInfoHolder holder) {
+ if (!mController.isMoveCapable(holder.message.getFolder().getAccount())) {
return;
}
- if (!mController.isMoveCapable(holder.message))
- {
+ if (!mController.isMoveCapable(holder.message)) {
Toast toast = Toast.makeText(this, R.string.move_copy_cannot_copy_unsynced_message, Toast.LENGTH_LONG);
toast.show();
return;
@@ -1365,15 +1137,12 @@ public class MessageList
onMoveChosen(holder, holder.message.getFolder().getAccount().getSpamFolderName());
}
- private void onCopy(MessageInfoHolder holder)
- {
- if (!mController.isCopyCapable(holder.message.getFolder().getAccount()))
- {
+ private void onCopy(MessageInfoHolder holder) {
+ if (!mController.isCopyCapable(holder.message.getFolder().getAccount())) {
return;
}
- if (!mController.isCopyCapable(holder.message))
- {
+ if (!mController.isCopyCapable(holder.message)) {
Toast toast = Toast.makeText(this, R.string.move_copy_cannot_copy_unsynced_message, Toast.LENGTH_LONG);
toast.show();
return;
@@ -1390,71 +1159,61 @@ public class MessageList
}
@Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data)
- {
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_OK)
return;
- switch (requestCode)
- {
- case ACTIVITY_CHOOSE_FOLDER_MOVE:
- case ACTIVITY_CHOOSE_FOLDER_COPY:
- {
- if (data == null)
- return;
+ switch (requestCode) {
+ case ACTIVITY_CHOOSE_FOLDER_MOVE:
+ case ACTIVITY_CHOOSE_FOLDER_COPY: {
+ if (data == null)
+ return;
- final String destFolderName = data.getStringExtra(ChooseFolder.EXTRA_NEW_FOLDER);
- final MessageReference ref = (MessageReference)data.getSerializableExtra(ChooseFolder.EXTRA_MESSAGE);
- final MessageInfoHolder m = mAdapter.getMessage(ref);
+ final String destFolderName = data.getStringExtra(ChooseFolder.EXTRA_NEW_FOLDER);
+ final MessageReference ref = (MessageReference)data.getSerializableExtra(ChooseFolder.EXTRA_MESSAGE);
+ final MessageInfoHolder m = mAdapter.getMessage(ref);
- if ((destFolderName != null) && (m != null))
- {
- final Account account = m.message.getFolder().getAccount();
-
- account.setLastSelectedFolderName(destFolderName);
-
- switch (requestCode)
- {
- case ACTIVITY_CHOOSE_FOLDER_MOVE:
- onMoveChosen(m, destFolderName);
- break;
-
- case ACTIVITY_CHOOSE_FOLDER_COPY:
- onCopyChosen(m, destFolderName);
- break;
- }
- }
- break;
- }
- case ACTIVITY_CHOOSE_FOLDER_MOVE_BATCH:
- case ACTIVITY_CHOOSE_FOLDER_COPY_BATCH:
- {
- final String destFolderName = data.getStringExtra(ChooseFolder.EXTRA_NEW_FOLDER);
- final String accountUuid = data.getStringExtra(ChooseFolder.EXTRA_ACCOUNT);
- final Account account = Preferences.getPreferences(this).getAccount(accountUuid);
+ if ((destFolderName != null) && (m != null)) {
+ final Account account = m.message.getFolder().getAccount();
account.setLastSelectedFolderName(destFolderName);
- switch (requestCode)
- {
- case ACTIVITY_CHOOSE_FOLDER_MOVE_BATCH:
- onMoveChosenBatch(destFolderName);
- break;
+ switch (requestCode) {
+ case ACTIVITY_CHOOSE_FOLDER_MOVE:
+ onMoveChosen(m, destFolderName);
+ break;
- case ACTIVITY_CHOOSE_FOLDER_COPY_BATCH:
- onCopyChosenBatch(destFolderName);
- break;
+ case ACTIVITY_CHOOSE_FOLDER_COPY:
+ onCopyChosen(m, destFolderName);
+ break;
}
}
+ break;
+ }
+ case ACTIVITY_CHOOSE_FOLDER_MOVE_BATCH:
+ case ACTIVITY_CHOOSE_FOLDER_COPY_BATCH: {
+ final String destFolderName = data.getStringExtra(ChooseFolder.EXTRA_NEW_FOLDER);
+ final String accountUuid = data.getStringExtra(ChooseFolder.EXTRA_ACCOUNT);
+ final Account account = Preferences.getPreferences(this).getAccount(accountUuid);
+
+ account.setLastSelectedFolderName(destFolderName);
+
+ switch (requestCode) {
+ case ACTIVITY_CHOOSE_FOLDER_MOVE_BATCH:
+ onMoveChosenBatch(destFolderName);
+ break;
+
+ case ACTIVITY_CHOOSE_FOLDER_COPY_BATCH:
+ onCopyChosenBatch(destFolderName);
+ break;
+ }
+ }
}
}
- private void onMoveChosen(MessageInfoHolder holder, String folderName)
- {
- if (mController.isMoveCapable(holder.message.getFolder().getAccount()) && folderName != null)
- {
- if (K9.FOLDER_NONE.equalsIgnoreCase(folderName))
- {
+ private void onMoveChosen(MessageInfoHolder holder, String folderName) {
+ if (mController.isMoveCapable(holder.message.getFolder().getAccount()) && folderName != null) {
+ if (K9.FOLDER_NONE.equalsIgnoreCase(folderName)) {
return;
}
mAdapter.removeMessage(holder);
@@ -1462,305 +1221,242 @@ public class MessageList
}
}
- private void onCopyChosen(MessageInfoHolder holder, String folderName)
- {
- if (mController.isCopyCapable(holder.message.getFolder().getAccount()) && folderName != null)
- {
+ private void onCopyChosen(MessageInfoHolder holder, String folderName) {
+ if (mController.isCopyCapable(holder.message.getFolder().getAccount()) && folderName != null) {
mController.copyMessage(holder.message.getFolder().getAccount(),
holder.message.getFolder().getName(), holder.message, folderName, null);
}
}
- private void onReply(MessageInfoHolder holder)
- {
+ private void onReply(MessageInfoHolder holder) {
MessageCompose.actionReply(this, holder.message.getFolder().getAccount(), holder.message, false, null);
}
- private void onReplyAll(MessageInfoHolder holder)
- {
+ private void onReplyAll(MessageInfoHolder holder) {
MessageCompose.actionReply(this, holder.message.getFolder().getAccount(), holder.message, true, null);
}
- private void onForward(MessageInfoHolder holder)
- {
+ private void onForward(MessageInfoHolder holder) {
MessageCompose.actionForward(this, holder.message.getFolder().getAccount(), holder.message, null);
}
- private void onMarkAllAsRead(final Account account, final String folder)
- {
+ private void onMarkAllAsRead(final Account account, final String folder) {
showDialog(DIALOG_MARK_ALL_AS_READ);
}
- private void onExpunge(final Account account, String folderName)
- {
+ private void onExpunge(final Account account, String folderName) {
mController.expunge(account, folderName, null);
}
@Override
- public Dialog onCreateDialog(int id)
- {
- switch (id)
- {
- case DIALOG_MARK_ALL_AS_READ:
- return createMarkAllAsReadDialog();
+ public Dialog onCreateDialog(int id) {
+ switch (id) {
+ case DIALOG_MARK_ALL_AS_READ:
+ return createMarkAllAsReadDialog();
}
return super.onCreateDialog(id);
}
@Override
- public void onPrepareDialog(int id, Dialog dialog)
- {
- switch (id)
- {
- case DIALOG_MARK_ALL_AS_READ:
- {
- if (mCurrentFolder != null)
- {
- ((AlertDialog)dialog).setMessage(getString(R.string.mark_all_as_read_dlg_instructions_fmt,
- mCurrentFolder.displayName));
- }
- break;
- }
- default:
- {
- super.onPrepareDialog(id, dialog);
+ public void onPrepareDialog(int id, Dialog dialog) {
+ switch (id) {
+ case DIALOG_MARK_ALL_AS_READ: {
+ if (mCurrentFolder != null) {
+ ((AlertDialog)dialog).setMessage(getString(R.string.mark_all_as_read_dlg_instructions_fmt,
+ mCurrentFolder.displayName));
}
+ break;
+ }
+ default: {
+ super.onPrepareDialog(id, dialog);
+ }
}
}
- private Dialog createMarkAllAsReadDialog()
- {
+ private Dialog createMarkAllAsReadDialog() {
return new AlertDialog.Builder(this)
.setTitle(R.string.mark_all_as_read_dlg_title)
.setMessage(getString(R.string.mark_all_as_read_dlg_instructions_fmt,
mCurrentFolder.displayName))
- .setPositiveButton(R.string.okay_action, new DialogInterface.OnClickListener()
- {
- public void onClick(DialogInterface dialog, int whichButton)
- {
+ .setPositiveButton(R.string.okay_action, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int whichButton) {
dismissDialog(DIALOG_MARK_ALL_AS_READ);
- try
- {
+ try {
mController.markAllMessagesRead(mAccount, mCurrentFolder.name);
- synchronized (mAdapter.messages)
- {
- for (MessageInfoHolder holder : mAdapter.messages)
- {
+ synchronized (mAdapter.messages) {
+ for (MessageInfoHolder holder : mAdapter.messages) {
holder.read = true;
}
}
mHandler.sortMessages();
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
// Ignore
}
}
})
- .setNegativeButton(R.string.cancel_action, new DialogInterface.OnClickListener()
- {
- public void onClick(DialogInterface dialog, int whichButton)
- {
+ .setNegativeButton(R.string.cancel_action, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int whichButton) {
dismissDialog(DIALOG_MARK_ALL_AS_READ);
}
})
.create();
}
- private void onToggleRead(MessageInfoHolder holder)
- {
+ private void onToggleRead(MessageInfoHolder holder) {
mController.setFlag(holder.message.getFolder().getAccount(), holder.message.getFolder().getName(), new String[] { holder.uid }, Flag.SEEN, !holder.read);
holder.read = !holder.read;
mHandler.sortMessages();
}
- private void onToggleFlag(MessageInfoHolder holder)
- {
+ private void onToggleFlag(MessageInfoHolder holder) {
mController.setFlag(holder.message.getFolder().getAccount(), holder.message.getFolder().getName(), new String[] { holder.uid }, Flag.FLAGGED, !holder.flagged);
holder.flagged = !holder.flagged;
mHandler.sortMessages();
}
- private void checkMail(Account account, String folderName)
- {
+ private void checkMail(Account account, String folderName) {
mController.synchronizeMailbox(account, folderName, mAdapter.mListener, null);
mController.sendPendingMessages(account, mAdapter.mListener);
}
@Override
- public boolean onOptionsItemSelected(MenuItem item)
- {
+ public boolean onOptionsItemSelected(MenuItem item) {
int itemId = item.getItemId();
- switch (itemId)
- {
- case R.id.compose:
- {
- onCompose();
- return true;
- }
- case R.id.accounts:
- {
- onAccounts();
- return true;
- }
- case R.id.set_sort_date:
- {
- changeSort(SORT_TYPE.SORT_DATE);
- return true;
- }
- case R.id.set_sort_subject:
- {
- changeSort(SORT_TYPE.SORT_SUBJECT);
- return true;
- }
- case R.id.set_sort_sender:
- {
- changeSort(SORT_TYPE.SORT_SENDER);
- return true;
- }
- case R.id.set_sort_flag:
- {
- changeSort(SORT_TYPE.SORT_FLAGGED);
- return true;
- }
- case R.id.set_sort_unread:
- {
- changeSort(SORT_TYPE.SORT_UNREAD);
- return true;
- }
- case R.id.set_sort_attach:
- {
- changeSort(SORT_TYPE.SORT_ATTACHMENT);
- return true;
- }
- case R.id.select_all:
- case R.id.batch_select_all:
- {
- setAllSelected(true);
- toggleBatchButtons();
- return true;
- }
- case R.id.batch_deselect_all:
- {
- setAllSelected(false);
- toggleBatchButtons();
- return true;
- }
- case R.id.batch_delete_op:
- {
- deleteSelected();
- return true;
- }
- case R.id.batch_mark_read_op:
- {
- flagSelected(Flag.SEEN, true);
- return true;
- }
- case R.id.batch_mark_unread_op:
- {
- flagSelected(Flag.SEEN, false);
- return true;
- }
- case R.id.batch_flag_op:
- {
- flagSelected(Flag.FLAGGED, true);
- return true;
- }
- case R.id.batch_unflag_op:
- {
- flagSelected(Flag.FLAGGED, false);
- return true;
- }
- case R.id.app_settings:
- {
- onEditPrefs();
- return true;
- }
+ switch (itemId) {
+ case R.id.compose: {
+ onCompose();
+ return true;
+ }
+ case R.id.accounts: {
+ onAccounts();
+ return true;
+ }
+ case R.id.set_sort_date: {
+ changeSort(SORT_TYPE.SORT_DATE);
+ return true;
+ }
+ case R.id.set_sort_subject: {
+ changeSort(SORT_TYPE.SORT_SUBJECT);
+ return true;
+ }
+ case R.id.set_sort_sender: {
+ changeSort(SORT_TYPE.SORT_SENDER);
+ return true;
+ }
+ case R.id.set_sort_flag: {
+ changeSort(SORT_TYPE.SORT_FLAGGED);
+ return true;
+ }
+ case R.id.set_sort_unread: {
+ changeSort(SORT_TYPE.SORT_UNREAD);
+ return true;
+ }
+ case R.id.set_sort_attach: {
+ changeSort(SORT_TYPE.SORT_ATTACHMENT);
+ return true;
+ }
+ case R.id.select_all:
+ case R.id.batch_select_all: {
+ setAllSelected(true);
+ toggleBatchButtons();
+ return true;
+ }
+ case R.id.batch_deselect_all: {
+ setAllSelected(false);
+ toggleBatchButtons();
+ return true;
+ }
+ case R.id.batch_delete_op: {
+ deleteSelected();
+ return true;
+ }
+ case R.id.batch_mark_read_op: {
+ flagSelected(Flag.SEEN, true);
+ return true;
+ }
+ case R.id.batch_mark_unread_op: {
+ flagSelected(Flag.SEEN, false);
+ return true;
+ }
+ case R.id.batch_flag_op: {
+ flagSelected(Flag.FLAGGED, true);
+ return true;
+ }
+ case R.id.batch_unflag_op: {
+ flagSelected(Flag.FLAGGED, false);
+ return true;
+ }
+ case R.id.app_settings: {
+ onEditPrefs();
+ return true;
+ }
}
- if (mQueryString != null)
- {
+ if (mQueryString != null) {
// None of the options after this point are "safe" for search results
//TODO: This is not true for "unread" and "starred" searches in regular folders
return false;
}
- switch (itemId)
- {
- case R.id.check_mail:
- {
- if (mFolderName != null)
- {
- checkMail(mAccount, mFolderName);
- }
- return true;
+ switch (itemId) {
+ case R.id.check_mail: {
+ if (mFolderName != null) {
+ checkMail(mAccount, mFolderName);
}
- case R.id.send_messages:
- {
- mController.sendPendingMessages(mAccount, mAdapter.mListener);
- return true;
+ return true;
+ }
+ case R.id.send_messages: {
+ mController.sendPendingMessages(mAccount, mAdapter.mListener);
+ return true;
+ }
+ case R.id.list_folders: {
+ onShowFolderList();
+ return true;
+ }
+ case R.id.mark_all_as_read: {
+ if (mFolderName != null) {
+ onMarkAllAsRead(mAccount, mFolderName);
}
- case R.id.list_folders:
- {
- onShowFolderList();
- return true;
+ return true;
+ }
+ case R.id.folder_settings: {
+ if (mFolderName != null) {
+ FolderSettings.actionSettings(this, mAccount, mFolderName);
}
- case R.id.mark_all_as_read:
- {
- if (mFolderName != null)
- {
- onMarkAllAsRead(mAccount, mFolderName);
- }
- return true;
- }
- case R.id.folder_settings:
- {
- if (mFolderName != null)
- {
- FolderSettings.actionSettings(this, mAccount, mFolderName);
- }
- return true;
- }
- case R.id.account_settings:
- {
- onEditAccount();
- return true;
- }
- case R.id.batch_copy_op:
- {
- onCopyBatch();
- return true;
- }
- case R.id.batch_archive_op:
- {
- onArchiveBatch();
- return true;
- }
- case R.id.batch_spam_op:
- {
- onSpamBatch();
- return true;
- }
- case R.id.batch_move_op:
- {
- onMoveBatch();
- return true;
- }
- case R.id.expunge:
- {
- if (mCurrentFolder != null)
- {
- onExpunge(mAccount, mCurrentFolder.name);
- }
- return true;
- }
- default:
- {
- return super.onOptionsItemSelected(item);
+ return true;
+ }
+ case R.id.account_settings: {
+ onEditAccount();
+ return true;
+ }
+ case R.id.batch_copy_op: {
+ onCopyBatch();
+ return true;
+ }
+ case R.id.batch_archive_op: {
+ onArchiveBatch();
+ return true;
+ }
+ case R.id.batch_spam_op: {
+ onSpamBatch();
+ return true;
+ }
+ case R.id.batch_move_op: {
+ onMoveBatch();
+ return true;
+ }
+ case R.id.expunge: {
+ if (mCurrentFolder != null) {
+ onExpunge(mAccount, mCurrentFolder.name);
}
+ return true;
+ }
+ default: {
+ return super.onOptionsItemSelected(item);
+ }
}
}
@@ -1770,18 +1466,15 @@ public class MessageList
R.id.batch_select_all, R.id.batch_deselect_all
};
- private void setOpsState(Menu menu, boolean state, boolean enabled)
- {
- for (int id : batch_ops)
- {
+ private void setOpsState(Menu menu, boolean state, boolean enabled) {
+ for (int id : batch_ops) {
menu.findItem(id).setVisible(state);
menu.findItem(id).setEnabled(enabled);
}
}
@Override
- public boolean onPrepareOptionsMenu(Menu menu)
- {
+ public boolean onPrepareOptionsMenu(Menu menu) {
boolean anySelected = anySelected();
menu.findItem(R.id.select_all).setVisible(! anySelected);
@@ -1789,8 +1482,7 @@ public class MessageList
setOpsState(menu, true, anySelected);
- if (mQueryString != null)
- {
+ if (mQueryString != null) {
menu.findItem(R.id.mark_all_as_read).setVisible(false);
menu.findItem(R.id.list_folders).setVisible(false);
menu.findItem(R.id.expunge).setVisible(false);
@@ -1802,28 +1494,20 @@ public class MessageList
menu.findItem(R.id.send_messages).setVisible(false);
menu.findItem(R.id.folder_settings).setVisible(false);
menu.findItem(R.id.account_settings).setVisible(false);
- }
- else
- {
- if (mCurrentFolder != null && mCurrentFolder.name.equals(mAccount.getOutboxFolderName()))
- {
+ } else {
+ if (mCurrentFolder != null && mCurrentFolder.name.equals(mAccount.getOutboxFolderName())) {
menu.findItem(R.id.check_mail).setVisible(false);
- }
- else
- {
+ } else {
menu.findItem(R.id.send_messages).setVisible(false);
}
- if (mCurrentFolder != null && K9.ERROR_FOLDER_NAME.equals(mCurrentFolder.name))
- {
+ if (mCurrentFolder != null && K9.ERROR_FOLDER_NAME.equals(mCurrentFolder.name)) {
menu.findItem(R.id.expunge).setVisible(false);
}
- if (K9.FOLDER_NONE.equalsIgnoreCase(mAccount.getArchiveFolderName()))
- {
+ if (K9.FOLDER_NONE.equalsIgnoreCase(mAccount.getArchiveFolderName())) {
menu.findItem(R.id.batch_archive_op).setVisible(false);
}
- if (K9.FOLDER_NONE.equalsIgnoreCase(mAccount.getSpamFolderName()))
- {
+ if (K9.FOLDER_NONE.equalsIgnoreCase(mAccount.getSpamFolderName())) {
menu.findItem(R.id.batch_spam_op).setVisible(false);
}
}
@@ -1841,8 +1525,7 @@ public class MessageList
}
@Override
- public boolean onCreateOptionsMenu(Menu menu)
- {
+ public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.message_list_option, menu);
@@ -1850,136 +1533,109 @@ public class MessageList
}
@Override
- public boolean onContextItemSelected(MenuItem item)
- {
+ public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
MessageInfoHolder holder = mSelectedMessage;
// don't need this anymore
mSelectedMessage = null;
- if (holder == null)
- {
+ if (holder == null) {
holder = (MessageInfoHolder) mAdapter.getItem(info.position);
}
- switch (item.getItemId())
- {
- case R.id.open:
- {
- onOpenMessage(holder);
- break;
- }
- case R.id.select:
- {
- setSelected(holder, true);
- break;
- }
- case R.id.deselect:
- {
- setSelected(holder, false);
- break;
- }
- case R.id.delete:
- {
- onDelete(holder, info.position);
- break;
- }
- case R.id.reply:
- {
- onReply(holder);
- break;
- }
- case R.id.reply_all:
- {
- onReplyAll(holder);
- break;
- }
- case R.id.forward:
- {
- onForward(holder);
- break;
- }
- case R.id.send_again:
- {
- onResendMessage(holder);
- break;
+ switch (item.getItemId()) {
+ case R.id.open: {
+ onOpenMessage(holder);
+ break;
+ }
+ case R.id.select: {
+ setSelected(holder, true);
+ break;
+ }
+ case R.id.deselect: {
+ setSelected(holder, false);
+ break;
+ }
+ case R.id.delete: {
+ onDelete(holder, info.position);
+ break;
+ }
+ case R.id.reply: {
+ onReply(holder);
+ break;
+ }
+ case R.id.reply_all: {
+ onReplyAll(holder);
+ break;
+ }
+ case R.id.forward: {
+ onForward(holder);
+ break;
+ }
+ case R.id.send_again: {
+ onResendMessage(holder);
+ break;
- }
- case R.id.mark_as_read:
- {
- onToggleRead(holder);
- break;
- }
- case R.id.flag:
- {
- onToggleFlag(holder);
- break;
- }
- case R.id.archive:
- {
- onArchive(holder);
- break;
- }
- case R.id.spam:
- {
- onSpam(holder);
- break;
- }
- case R.id.move:
- {
- onMove(holder);
- break;
- }
- case R.id.copy:
- {
- onCopy(holder);
- break;
- }
- case R.id.send_alternate:
- {
- onSendAlternate(mAccount, holder);
- break;
- }
- case R.id.same_sender:
- {
- MessageList.actionHandle(MessageList.this,
- "From "+holder.sender, holder.senderAddress, true,
- null, null);
- break;
- }
+ }
+ case R.id.mark_as_read: {
+ onToggleRead(holder);
+ break;
+ }
+ case R.id.flag: {
+ onToggleFlag(holder);
+ break;
+ }
+ case R.id.archive: {
+ onArchive(holder);
+ break;
+ }
+ case R.id.spam: {
+ onSpam(holder);
+ break;
+ }
+ case R.id.move: {
+ onMove(holder);
+ break;
+ }
+ case R.id.copy: {
+ onCopy(holder);
+ break;
+ }
+ case R.id.send_alternate: {
+ onSendAlternate(mAccount, holder);
+ break;
+ }
+ case R.id.same_sender: {
+ MessageList.actionHandle(MessageList.this,
+ "From " + holder.sender, holder.senderAddress, true,
+ null, null);
+ break;
+ }
}
return super.onContextItemSelected(item);
}
- public void onSendAlternate(Account account, MessageInfoHolder holder)
- {
+ public void onSendAlternate(Account account, MessageInfoHolder holder) {
mController.sendAlternate(this, account, holder.message);
}
- public void showProgressIndicator(boolean status)
- {
+ public void showProgressIndicator(boolean status) {
setProgressBarIndeterminateVisibility(status);
ProgressBar bar = (ProgressBar)mListView.findViewById(R.id.message_list_progress);
- if (bar == null)
- {
+ if (bar == null) {
return;
}
bar.setIndeterminate(true);
- if (status)
- {
+ if (status) {
bar.setVisibility(ProgressBar.VISIBLE);
- }
- else
- {
+ } else {
bar.setVisibility(ProgressBar.INVISIBLE);
}
}
- class MyGestureDetector extends SimpleOnGestureListener
- {
+ class MyGestureDetector extends SimpleOnGestureListener {
@Override
- public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
- {
+ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
if (e2 == null || e1 == null)
return true;
@@ -1989,17 +1645,14 @@ public class MessageList
boolean movedAcross = (Math.abs(deltaX) > Math.abs(deltaY * 4));
boolean steadyHand = (Math.abs(deltaX / deltaY) > 2);
- if (movedAcross && steadyHand)
- {
+ if (movedAcross && steadyHand) {
boolean selected = (deltaX > 0);
int position = mListView.pointToPosition((int)e1.getX(), (int)e1.getY());
- if (position != AdapterView.INVALID_POSITION)
- {
+ if (position != AdapterView.INVALID_POSITION) {
MessageInfoHolder msgInfoHolder = (MessageInfoHolder) mAdapter.getItem(position);
- if (msgInfoHolder != null && msgInfoHolder.selected != selected)
- {
+ if (msgInfoHolder != null && msgInfoHolder.selected != selected) {
msgInfoHolder.selected = selected;
mSelectedCount += (selected ? 1 : -1);
mAdapter.notifyDataSetChanged();
@@ -2013,8 +1666,7 @@ public class MessageList
}
@Override
- public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo)
- {
+ public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
@@ -2023,8 +1675,7 @@ public class MessageList
// dialog is up
mSelectedMessage = message;
- if (message == null)
- {
+ if (message == null) {
return;
}
@@ -2032,80 +1683,65 @@ public class MessageList
menu.setHeaderTitle(message.message.getSubject());
- if (message.read)
- {
+ if (message.read) {
menu.findItem(R.id.mark_as_read).setTitle(R.string.mark_as_unread_action);
}
- if (message.flagged)
- {
+ if (message.flagged) {
menu.findItem(R.id.flag).setTitle(R.string.unflag_action);
}
Account account = message.message.getFolder().getAccount();
- if (!mController.isCopyCapable(account))
- {
+ if (!mController.isCopyCapable(account)) {
menu.findItem(R.id.copy).setVisible(false);
}
- if (!mController.isMoveCapable(account))
- {
+ if (!mController.isMoveCapable(account)) {
menu.findItem(R.id.move).setVisible(false);
menu.findItem(R.id.archive).setVisible(false);
menu.findItem(R.id.spam).setVisible(false);
}
- if (K9.FOLDER_NONE.equalsIgnoreCase(account.getArchiveFolderName()))
- {
+ if (K9.FOLDER_NONE.equalsIgnoreCase(account.getArchiveFolderName())) {
menu.findItem(R.id.archive).setVisible(false);
}
- if (K9.FOLDER_NONE.equalsIgnoreCase(account.getSpamFolderName()))
- {
+ if (K9.FOLDER_NONE.equalsIgnoreCase(account.getSpamFolderName())) {
menu.findItem(R.id.spam).setVisible(false);
}
- if (message.selected)
- {
+ if (message.selected) {
menu.findItem(R.id.select).setVisible(false);
menu.findItem(R.id.deselect).setVisible(true);
- }
- else
- {
+ } else {
menu.findItem(R.id.select).setVisible(true);
menu.findItem(R.id.deselect).setVisible(false);
}
}
- class MessageListAdapter extends BaseAdapter
- {
+ class MessageListAdapter extends BaseAdapter {
private final List messages = java.util.Collections.synchronizedList(new ArrayList());
- private final ActivityListener mListener = new ActivityListener()
- {
+ private final ActivityListener mListener = new ActivityListener() {
@Override
- public void synchronizeMailboxStarted(Account account, String folder)
- {
+ public void synchronizeMailboxStarted(Account account, String folder) {
super.synchronizeMailboxStarted(account, folder);
- if (updateForMe(account, folder))
- {
+ if (updateForMe(account, folder)) {
mHandler.progress(true);
mHandler.folderLoading(folder, true);
}
mHandler.refreshTitle();
}
@Override
- public void synchronizeMailboxHeadersProgress(Account account, String folder, int completed, int total)
- {
- super.synchronizeMailboxHeadersProgress(account,folder,completed, total);
+ public void synchronizeMailboxHeadersProgress(Account account, String folder, int completed, int total) {
+ super.synchronizeMailboxHeadersProgress(account, folder, completed, total);
mHandler.refreshTitle();
}
@Override
public void synchronizeMailboxHeadersFinished(Account account, String folder,
- int total, int completed)
- {
- super.synchronizeMailboxHeadersFinished(account,folder, total, completed);
+ int total, int completed) {
+ super.synchronizeMailboxHeadersFinished(account, folder, total, completed);
mHandler.refreshTitle();
}
@@ -2114,12 +1750,10 @@ public class MessageList
@Override
public void synchronizeMailboxFinished(Account account, String folder,
- int totalMessagesInMailbox, int numNewMessages)
- {
+ int totalMessagesInMailbox, int numNewMessages) {
super.synchronizeMailboxFinished(account, folder, totalMessagesInMailbox, numNewMessages);
- if (updateForMe(account, folder))
- {
+ if (updateForMe(account, folder)) {
mHandler.progress(false);
mHandler.folderLoading(folder, false);
mHandler.sortMessages();
@@ -2128,12 +1762,10 @@ public class MessageList
}
@Override
- public void synchronizeMailboxFailed(Account account, String folder, String message)
- {
+ public void synchronizeMailboxFailed(Account account, String folder, String message) {
super.synchronizeMailboxFailed(account, folder, message);
- if (updateForMe(account, folder))
- {
+ if (updateForMe(account, folder)) {
mHandler.progress(false);
mHandler.folderLoading(folder, false);
mHandler.sortMessages();
@@ -2142,197 +1774,161 @@ public class MessageList
}
@Override
- public void sendPendingMessagesStarted(Account account)
- {
+ public void sendPendingMessagesStarted(Account account) {
super.sendPendingMessagesStarted(account);
mHandler.refreshTitle();
}
@Override
- public void sendPendingMessagesCompleted(Account account)
- {
+ public void sendPendingMessagesCompleted(Account account) {
super.sendPendingMessagesCompleted(account);
mHandler.refreshTitle();
}
@Override
- public void sendPendingMessagesFailed(Account account)
- {
+ public void sendPendingMessagesFailed(Account account) {
super.sendPendingMessagesFailed(account);
mHandler.refreshTitle();
}
@Override
- public void synchronizeMailboxProgress(Account account, String folder, int completed, int total)
- {
+ public void synchronizeMailboxProgress(Account account, String folder, int completed, int total) {
super.synchronizeMailboxProgress(account, folder, completed, total);
mHandler.refreshTitle();
}
@Override
- public void synchronizeMailboxAddOrUpdateMessage(Account account, String folder, Message message)
- {
+ public void synchronizeMailboxAddOrUpdateMessage(Account account, String folder, Message message) {
addOrUpdateMessage(account, folder, message, true);
}
@Override
- public void synchronizeMailboxRemovedMessage(Account account, String folder,Message message)
- {
+ public void synchronizeMailboxRemovedMessage(Account account, String folder, Message message) {
MessageInfoHolder holder = getMessage(message);
- if (holder == null)
- {
+ if (holder == null) {
Log.w(K9.LOG_TAG, "Got callback to remove non-existent message with UID " + message.getUid());
- }
- else
- {
+ } else {
removeMessage(holder);
}
}
@Override
- public void listLocalMessagesStarted(Account account, String folder)
- {
+ public void listLocalMessagesStarted(Account account, String folder) {
if ((mQueryString != null && folder == null) ||
(account != null && account.equals(mAccount))
- )
- {
+ ) {
mHandler.progress(true);
- if (folder != null)
- {
+ if (folder != null) {
mHandler.folderLoading(folder, true);
}
}
}
@Override
- public void listLocalMessagesFailed(Account account, String folder, String message)
- {
+ public void listLocalMessagesFailed(Account account, String folder, String message) {
if ((mQueryString != null && folder == null) ||
- (account != null && account.equals(mAccount)))
- {
+ (account != null && account.equals(mAccount))) {
mHandler.sortMessages();
mHandler.progress(false);
- if (folder != null)
- {
+ if (folder != null) {
mHandler.folderLoading(folder, false);
}
}
}
@Override
- public void listLocalMessagesFinished(Account account, String folder)
- {
+ public void listLocalMessagesFinished(Account account, String folder) {
if ((mQueryString != null && folder == null) ||
- (account != null && account.equals(mAccount)))
- {
+ (account != null && account.equals(mAccount))) {
mHandler.sortMessages();
mHandler.progress(false);
- if (folder != null)
- {
+ if (folder != null) {
mHandler.folderLoading(folder, false);
}
}
}
@Override
- public void listLocalMessagesRemoveMessage(Account account, String folder,Message message)
- {
+ public void listLocalMessagesRemoveMessage(Account account, String folder, Message message) {
MessageInfoHolder holder = getMessage(message);
- if (holder != null)
- {
+ if (holder != null) {
removeMessage(holder);
}
}
@Override
- public void listLocalMessagesAddMessages(Account account, String folder, List messages)
- {
+ public void listLocalMessagesAddMessages(Account account, String folder, List messages) {
addOrUpdateMessages(account, folder, messages, false);
}
@Override
- public void listLocalMessagesUpdateMessage(Account account, String folder, Message message)
- {
+ public void listLocalMessagesUpdateMessage(Account account, String folder, Message message) {
addOrUpdateMessage(account, folder, message, false);
}
@Override
- public void searchStats(AccountStats stats)
- {
+ public void searchStats(AccountStats stats) {
mUnreadMessageCount = stats.unreadMessageCount;
mHandler.refreshTitle();
}
@Override
- public void folderStatusChanged(Account account, String folder, int unreadMessageCount)
- {
+ public void folderStatusChanged(Account account, String folder, int unreadMessageCount) {
super.folderStatusChanged(account, folder, unreadMessageCount);
- if (updateForMe(account, folder))
- {
+ if (updateForMe(account, folder)) {
mUnreadMessageCount = unreadMessageCount;
mHandler.refreshTitle();
}
}
@Override
- public void pendingCommandsProcessing(Account account)
- {
+ public void pendingCommandsProcessing(Account account) {
super.pendingCommandsProcessing(account);
mHandler.refreshTitle();
}
@Override
- public void pendingCommandsFinished(Account account)
- {
+ public void pendingCommandsFinished(Account account) {
super.pendingCommandsFinished(account);
mHandler.refreshTitle();
}
@Override
- public void pendingCommandStarted(Account account, String commandTitle)
- {
+ public void pendingCommandStarted(Account account, String commandTitle) {
super.pendingCommandStarted(account, commandTitle);
mHandler.refreshTitle();
}
@Override
- public void pendingCommandCompleted(Account account, String commandTitle)
- {
+ public void pendingCommandCompleted(Account account, String commandTitle) {
super.pendingCommandCompleted(account, commandTitle);
mHandler.refreshTitle();
}
@Override
- public void messageUidChanged(Account account, String folder, String oldUid, String newUid)
- {
+ public void messageUidChanged(Account account, String folder, String oldUid, String newUid) {
MessageReference ref = new MessageReference();
ref.accountUuid = account.getUuid();
ref.folderName = folder;
ref.uid = oldUid;
MessageInfoHolder holder = getMessage(ref);
- if (holder != null)
- {
+ if (holder != null) {
holder.uid = newUid;
holder.message.setUid(newUid);
}
}
@Override
- public void systemStatusChanged()
- {
+ public void systemStatusChanged() {
mHandler.refreshTitle();
}
};
- private boolean updateForMe(Account account, String folder)
- {
- if ((account.equals(mAccount) && mFolderName != null && folder.equals(mFolderName)))
- {
+ private boolean updateForMe(Account account, String folder) {
+ if ((account.equals(mAccount) && mFolderName != null && folder.equals(mFolderName))) {
return true;
- }
- else
- {
+ } else {
return false;
}
}
@@ -2341,31 +1937,23 @@ public class MessageList
private Drawable mAnsweredIcon;
private View footerView = null;
- MessageListAdapter()
- {
+ MessageListAdapter() {
mAttachmentIcon = getResources().getDrawable(R.drawable.ic_email_attachment_small);
mAnsweredIcon = getResources().getDrawable(R.drawable.ic_email_answered_small);
}
- public void markAllMessagesAsDirty()
- {
- for (MessageInfoHolder holder : mAdapter.messages)
- {
+ public void markAllMessagesAsDirty() {
+ for (MessageInfoHolder holder : mAdapter.messages) {
holder.dirty = true;
}
}
- public void pruneDirtyMessages()
- {
- synchronized (mAdapter.messages)
- {
+ public void pruneDirtyMessages() {
+ synchronized (mAdapter.messages) {
Iterator iter = mAdapter.messages.iterator();
- while (iter.hasNext())
- {
+ while (iter.hasNext()) {
MessageInfoHolder holder = iter.next();
- if (holder.dirty)
- {
- if (holder.selected)
- {
+ if (holder.dirty) {
+ if (holder.selected) {
mSelectedCount--;
toggleBatchButtons();
}
@@ -2375,30 +1963,25 @@ public class MessageList
}
}
- public void removeMessages(List holders)
- {
- if (holders != null)
- {
+ public void removeMessages(List holders) {
+ if (holders != null) {
mHandler.removeMessage(holders);
}
}
- public void removeMessage(MessageInfoHolder holder)
- {
+ public void removeMessage(MessageInfoHolder holder) {
List messages = new ArrayList();
messages.add(holder);
removeMessages(messages);
}
- private void addOrUpdateMessage(Account account, String folderName, Message message, boolean verifyAgainstSearch)
- {
+ private void addOrUpdateMessage(Account account, String folderName, Message message, boolean verifyAgainstSearch) {
List messages = new ArrayList();
messages.add(message);
addOrUpdateMessages(account, folderName, messages, verifyAgainstSearch);
}
- private void addOrUpdateMessages(final Account account, final String folderName, final List providedMessages, final boolean verifyAgainstSearch)
- {
+ private void addOrUpdateMessages(final Account account, final String folderName, final List providedMessages, final boolean verifyAgainstSearch) {
// we copy the message list because the callback doesn't expect
// the callbacks to mutate it.
final List messages = new ArrayList(providedMessages);
@@ -2411,47 +1994,32 @@ public class MessageList
// cache field into local variable for faster access for JVM without JIT
final MessageHelper messageHelper = mMessageHelper;
- for (Message message : messages)
- {
+ for (Message message : messages) {
MessageInfoHolder m = getMessage(message);
- if (message.isSet(Flag.DELETED))
- {
- if (m != null)
- {
+ if (message.isSet(Flag.DELETED)) {
+ if (m != null) {
messagesToRemove.add(m);
}
- }
- else
- {
+ } else {
final Folder messageFolder = message.getFolder();
final Account messageAccount = messageFolder.getAccount();
- if (m == null)
- {
- if (updateForMe(account, folderName))
- {
+ if (m == null) {
+ if (updateForMe(account, folderName)) {
m = new MessageInfoHolder();
messageHelper.populate(m, message, new FolderInfoHolder(MessageList.this, messageFolder, messageAccount), messageAccount);
messagesToAdd.add(m);
- }
- else
- {
- if (mQueryString != null)
- {
- if (verifyAgainstSearch)
- {
+ } else {
+ if (mQueryString != null) {
+ if (verifyAgainstSearch) {
messagesToSearch.add(message);
- }
- else
- {
+ } else {
m = new MessageInfoHolder();
messageHelper.populate(m, message, new FolderInfoHolder(MessageList.this, messageFolder, messageAccount), messageAccount);
messagesToAdd.add(m);
}
}
}
- }
- else
- {
+ } else {
m.dirty = false; // as we reload the message, unset its dirty flag
messageHelper.populate(m, message, new FolderInfoHolder(MessageList.this, messageFolder, account), account);
needsSort = true;
@@ -2459,47 +2027,37 @@ public class MessageList
}
}
- if (messagesToSearch.size() > 0)
- {
+ if (messagesToSearch.size() > 0) {
mController.searchLocalMessages(mAccountUuids, mFolderNames, messagesToSearch.toArray(EMPTY_MESSAGE_ARRAY), mQueryString, mIntegrate, mQueryFlags, mForbiddenFlags,
- new MessagingListener()
- {
+ new MessagingListener() {
@Override
- public void listLocalMessagesAddMessages(Account account, String folder, List messages)
- {
+ public void listLocalMessagesAddMessages(Account account, String folder, List messages) {
addOrUpdateMessages(account, folder, messages, false);
}
});
}
- if (messagesToRemove.size() > 0)
- {
+ if (messagesToRemove.size() > 0) {
removeMessages(messagesToRemove);
}
- if (messagesToAdd.size() > 0)
- {
+ if (messagesToAdd.size() > 0) {
mHandler.addMessages(messagesToAdd);
}
- if (needsSort)
- {
+ if (needsSort) {
mHandler.sortMessages();
mHandler.resetUnreadCount();
}
}
- public MessageInfoHolder getMessage(Message message)
- {
+ public MessageInfoHolder getMessage(Message message) {
return getMessage(message.makeMessageReference());
}
// XXX TODO - make this not use a for loop
- public MessageInfoHolder getMessage(MessageReference messageReference)
- {
- synchronized (mAdapter.messages)
- {
- for (MessageInfoHolder holder : mAdapter.messages)
- {
+ public MessageInfoHolder getMessage(MessageReference messageReference) {
+ synchronized (mAdapter.messages) {
+ for (MessageInfoHolder holder : mAdapter.messages) {
/*
* 2010-06-21 - cketti
* Added null pointer check. Not sure what's causing 'holder'
@@ -2508,8 +2066,7 @@ public class MessageList
* Please remove this comment once the cause was found and the
* bug(?) fixed.
*/
- if ((holder != null) && holder.message.equalsReference(messageReference))
- {
+ if ((holder != null) && holder.message.equalsReference(messageReference)) {
return holder;
}
}
@@ -2517,24 +2074,17 @@ public class MessageList
return null;
}
- public FolderInfoHolder getFolder(String folder, Account account)
- {
+ public FolderInfoHolder getFolder(String folder, Account account) {
LocalFolder local_folder = null;
- try
- {
+ try {
LocalStore localStore = account.getLocalStore();
local_folder = localStore.getFolder(folder);
return new FolderInfoHolder(context, local_folder, account);
- }
- catch (Exception e)
- {
- Log.e(K9.LOG_TAG, "getFolder(" + folder + ") goes boom: ",e);
+ } catch (Exception e) {
+ Log.e(K9.LOG_TAG, "getFolder(" + folder + ") goes boom: ", e);
return null;
- }
- finally
- {
- if (local_folder != null)
- {
+ } finally {
+ if (local_folder != null) {
local_folder.close();
}
}
@@ -2542,10 +2092,8 @@ public class MessageList
private static final int NON_MESSAGE_ITEMS = 1;
- private final OnClickListener flagClickListener = new OnClickListener()
- {
- public void onClick(View v)
- {
+ private final OnClickListener flagClickListener = new OnClickListener() {
+ public void onClick(View v) {
// Perform action on clicks
MessageInfoHolder message = (MessageInfoHolder) getItem((Integer)v.getTag());
onToggleFlag(message);
@@ -2553,86 +2101,62 @@ public class MessageList
};
@Override
- public int getCount()
- {
+ public int getCount() {
return messages.size() + NON_MESSAGE_ITEMS;
}
@Override
- public long getItemId(int position)
- {
- try
- {
- MessageInfoHolder messageHolder =(MessageInfoHolder) getItem(position);
- if (messageHolder != null)
- {
+ public long getItemId(int position) {
+ try {
+ MessageInfoHolder messageHolder = (MessageInfoHolder) getItem(position);
+ if (messageHolder != null) {
return messageHolder.message.getId();
}
- }
- catch (Exception e)
- {
- Log.i(K9.LOG_TAG,"getItemId("+position+") ",e);
+ } catch (Exception e) {
+ Log.i(K9.LOG_TAG, "getItemId(" + position + ") ", e);
}
return -1;
}
- public Object getItem(long position)
- {
+ public Object getItem(long position) {
return getItem((int)position);
}
@Override
- public Object getItem(int position)
- {
- try
- {
- synchronized (mAdapter.messages)
- {
- if (position < mAdapter.messages.size())
- {
+ public Object getItem(int position) {
+ try {
+ synchronized (mAdapter.messages) {
+ if (position < mAdapter.messages.size()) {
return mAdapter.messages.get(position);
}
}
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
Log.e(K9.LOG_TAG, "getItem(" + position + "), but folder.messages.size() = " + mAdapter.messages.size(), e);
}
return null;
}
@Override
- public View getView(int position, View convertView, ViewGroup parent)
- {
+ public View getView(int position, View convertView, ViewGroup parent) {
- if (position == mAdapter.messages.size())
- {
+ if (position == mAdapter.messages.size()) {
return getFooterView(position, convertView, parent);
- }
- else
- {
+ } else {
return getItemView(position, convertView, parent);
}
}
- public View getItemView(int position, View convertView, ViewGroup parent)
- {
+ public View getItemView(int position, View convertView, ViewGroup parent) {
MessageInfoHolder message = (MessageInfoHolder) getItem(position);
View view;
- if ((convertView != null) && (convertView.getId() == R.layout.message_list_item))
- {
+ if ((convertView != null) && (convertView.getId() == R.layout.message_list_item)) {
view = convertView;
- }
- else
- {
- if (mTouchView)
- {
+ } else {
+ if (mTouchView) {
view = mInflater.inflate(R.layout.message_list_item_touchable, parent, false);
view.setId(R.layout.message_list_item);
- }
- else
- {
+ } else {
view = mInflater.inflate(R.layout.message_list_item, parent, false);
view.setId(R.layout.message_list_item);
}
@@ -2640,8 +2164,7 @@ public class MessageList
MessageViewHolder holder = (MessageViewHolder) view.getTag();
- if (holder == null)
- {
+ if (holder == null) {
holder = new MessageViewHolder();
holder.subject = (TextView) view.findViewById(R.id.subject);
holder.from = (TextView) view.findViewById(R.id.from);
@@ -2653,43 +2176,34 @@ public class MessageList
holder.flagged.setOnClickListener(flagClickListener);
- if (!mStars)
- {
+ if (!mStars) {
holder.flagged.setVisibility(View.GONE);
}
- if (mCheckboxes)
- {
+ if (mCheckboxes) {
holder.selected.setVisibility(View.VISIBLE);
}
- if (holder.selected != null)
- {
+ if (holder.selected != null) {
holder.selected.setOnCheckedChangeListener(holder);
}
holder.subject.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mFontSizes.getMessageListSubject());
holder.date.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mFontSizes.getMessageListDate());
- if (mTouchView)
- {
+ if (mTouchView) {
holder.preview.setLines(mPreviewLines);
holder.preview.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mFontSizes.getMessageListPreview());
- }
- else
- {
+ } else {
holder.from.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mFontSizes.getMessageListSender());
}
view.setTag(holder);
}
- if (message != null)
- {
+ if (message != null) {
bindView(position, view, holder, message);
- }
- else
- {
+ } else {
// This branch code is triggered when the local store
// hands us an invalid message
@@ -2697,8 +2211,7 @@ public class MessageList
holder.subject.setText(getString(R.string.general_no_subject));
holder.subject.setTypeface(null, Typeface.NORMAL);
String noSender = getString(R.string.general_no_sender);
- if (holder.preview != null)
- {
+ if (holder.preview != null) {
holder.preview.setText(noSender, TextView.BufferType.SPANNABLE);
Spannable str = (Spannable) holder.preview.getText();
@@ -2709,9 +2222,7 @@ public class MessageList
noSender.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
);
- }
- else
- {
+ } else {
holder.from.setText(noSender);
holder.from.setTypeface(null, Typeface.NORMAL);
holder.from.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
@@ -2723,8 +2234,7 @@ public class MessageList
holder.position = -1;
holder.selected.setChecked(false);
- if (!mCheckboxes)
- {
+ if (!mCheckboxes) {
holder.selected.setVisibility(View.GONE);
}
holder.flagged.setChecked(false);
@@ -2749,8 +2259,7 @@ public class MessageList
* Never null
.
*/
private void bindView(final int position, final View view, final MessageViewHolder holder,
- final MessageInfoHolder message)
- {
+ final MessageInfoHolder message) {
holder.subject.setTypeface(null, message.read ? Typeface.NORMAL : Typeface.BOLD);
// XXX TODO there has to be some way to walk our view hierarchy and get this
@@ -2762,8 +2271,7 @@ public class MessageList
holder.position = -1;
holder.selected.setChecked(message.selected);
- if (!mCheckboxes)
- {
+ if (!mCheckboxes) {
holder.selected.setVisibility(message.selected ? View.VISIBLE : View.GONE);
}
@@ -2773,18 +2281,14 @@ public class MessageList
holder.chip.getBackground().setAlpha(message.read ? 127 : 255);
view.getBackground().setAlpha(message.downloaded ? 0 : 127);
- if ((message.message.getSubject() == null) || message.message.getSubject().equals(""))
- {
+ if ((message.message.getSubject() == null) || message.message.getSubject().equals("")) {
holder.subject.setText(getText(R.string.general_no_subject));
- }
- else
- {
+ } else {
holder.subject.setText(message.message.getSubject());
}
int senderTypeface = message.read ? Typeface.NORMAL : Typeface.BOLD;
- if (holder.preview != null)
- {
+ if (holder.preview != null) {
/*
* In the touchable UI, we have previews. Otherwise, we
* have just a "from" line.
@@ -2806,10 +2310,8 @@ public class MessageList
message.sender.length() + 1,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
);
- }
- else
- {
- holder.from.setText(new SpannableStringBuilder(recipientSigil(message)).append( message.sender));
+ } else {
+ holder.from.setText(new SpannableStringBuilder(recipientSigil(message)).append(message.sender));
holder.from.setTypeface(null, senderTypeface);
}
@@ -2823,30 +2325,21 @@ public class MessageList
holder.position = position;
}
- private String recipientSigil (MessageInfoHolder message)
- {
- if (message.message.toMe())
- {
+ private String recipientSigil(MessageInfoHolder message) {
+ if (message.message.toMe()) {
return getString(R.string.messagelist_sent_to_me_sigil);
- }
- else if (message.message.ccMe())
- {
+ } else if (message.message.ccMe()) {
return getString(R.string.messagelist_sent_cc_me_sigil);
- }
- else
- {
+ } else {
return "";
}
}
- public View getFooterView(int position, View convertView, ViewGroup parent)
- {
- if (footerView == null)
- {
+ public View getFooterView(int position, View convertView, ViewGroup parent) {
+ if (footerView == null) {
footerView = mInflater.inflate(R.layout.message_list_item_footer, parent, false);
- if (mQueryString != null)
- {
+ if (mQueryString != null) {
footerView.setVisibility(View.GONE);
}
footerView.setId(R.layout.message_list_item_footer);
@@ -2859,35 +2352,23 @@ public class MessageList
FooterViewHolder holder = (FooterViewHolder)footerView.getTag();
- if (mCurrentFolder != null && mAccount != null)
- {
- if (mCurrentFolder.loading)
- {
+ if (mCurrentFolder != null && mAccount != null) {
+ if (mCurrentFolder.loading) {
holder.main.setText(getString(R.string.status_loading_more));
holder.progress.setVisibility(ProgressBar.VISIBLE);
- }
- else
- {
- if (!mCurrentFolder.lastCheckFailed)
- {
- if (mAccount.getDisplayCount() == 0 )
- {
+ } else {
+ if (!mCurrentFolder.lastCheckFailed) {
+ if (mAccount.getDisplayCount() == 0) {
holder.main.setText(getString(R.string.message_list_load_more_messages_action));
- }
- else
- {
+ } else {
holder.main.setText(String.format(getString(R.string.load_more_messages_fmt), mAccount.getDisplayCount()));
}
- }
- else
- {
+ } else {
holder.main.setText(getString(R.string.status_loading_more_failed));
}
holder.progress.setVisibility(ProgressBar.INVISIBLE);
}
- }
- else
- {
+ } else {
holder.progress.setVisibility(ProgressBar.INVISIBLE);
}
@@ -2895,27 +2376,21 @@ public class MessageList
}
@Override
- public boolean hasStableIds()
- {
+ public boolean hasStableIds() {
return true;
}
- public boolean isItemSelectable(int position)
- {
- if (position < mAdapter.messages.size())
- {
+ public boolean isItemSelectable(int position) {
+ if (position < mAdapter.messages.size()) {
return true;
- }
- else
- {
+ } else {
return false;
}
}
}
class MessageViewHolder
- implements OnCheckedChangeListener
- {
+ implements OnCheckedChangeListener {
public TextView subject;
public TextView preview;
public TextView from;
@@ -2927,33 +2402,23 @@ public class MessageList
public int position = -1;
@Override
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
- {
- if (position!=-1)
- {
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+ if (position != -1) {
MessageInfoHolder message = (MessageInfoHolder) mAdapter.getItem(position);
- if (message.selected!=isChecked)
- {
- if (isChecked)
- {
+ if (message.selected != isChecked) {
+ if (isChecked) {
mSelectedCount++;
- }
- else if (mSelectedCount > 0)
- {
+ } else if (mSelectedCount > 0) {
mSelectedCount--;
}
// We must set the flag before showing the buttons as the
// buttons text depends on what is selected.
message.selected = isChecked;
- if (!mCheckboxes)
- {
- if (isChecked)
- {
+ if (!mCheckboxes) {
+ if (isChecked) {
selected.setVisibility(View.VISIBLE);
- }
- else
- {
+ } else {
selected.setVisibility(View.GONE);
}
}
@@ -2963,20 +2428,16 @@ public class MessageList
}
}
- private void hideBatchButtons()
- {
- if (mBatchButtonArea.getVisibility() != View.GONE)
- {
+ private void hideBatchButtons() {
+ if (mBatchButtonArea.getVisibility() != View.GONE) {
mBatchButtonArea.setVisibility(View.GONE);
mBatchButtonArea.startAnimation(
AnimationUtils.loadAnimation(this, R.anim.footer_disappear));
}
}
- private void showBatchButtons()
- {
- if (mBatchButtonArea.getVisibility() != View.VISIBLE)
- {
+ private void showBatchButtons() {
+ if (mBatchButtonArea.getVisibility() != View.VISIBLE) {
mBatchButtonArea.setVisibility(View.VISIBLE);
Animation animation = AnimationUtils.loadAnimation(this, R.anim.footer_appear);
animation.setAnimationListener(this);
@@ -2984,47 +2445,34 @@ public class MessageList
}
}
- private void toggleBatchButtons()
- {
+ private void toggleBatchButtons() {
- runOnUiThread(new Runnable()
- {
+ runOnUiThread(new Runnable() {
@Override
- public void run()
- {
+ public void run() {
- if (mSelectedCount < 0)
- {
+ if (mSelectedCount < 0) {
mSelectedCount = 0;
}
int readButtonIconId;
int flagButtonIconId;
- if (mSelectedCount==0)
- {
+ if (mSelectedCount == 0) {
readButtonIconId = R.drawable.ic_button_mark_read;
flagButtonIconId = R.drawable.ic_button_flag;
hideBatchButtons();
- }
- else
- {
+ } else {
boolean newReadState = computeBatchDirection(false);
- if (newReadState)
- {
+ if (newReadState) {
readButtonIconId = R.drawable.ic_button_mark_read;
- }
- else
- {
+ } else {
readButtonIconId = R.drawable.ic_button_mark_unread;
}
boolean newFlagState = computeBatchDirection(true);
- if (newFlagState)
- {
+ if (newFlagState) {
flagButtonIconId = R.drawable.ic_button_flag;
- }
- else
- {
+ } else {
flagButtonIconId = R.drawable.ic_button_unflag;
}
showBatchButtons();
@@ -3040,35 +2488,25 @@ public class MessageList
}
- static class FooterViewHolder
- {
+ static class FooterViewHolder {
public ProgressBar progress;
public TextView main;
}
- private boolean computeBatchDirection(boolean flagged)
- {
+ private boolean computeBatchDirection(boolean flagged) {
boolean newState = false;
- synchronized (mAdapter.messages)
- {
- for (MessageInfoHolder holder : mAdapter.messages)
- {
- if (holder.selected)
- {
- if (flagged)
- {
- if (!holder.flagged)
- {
+ synchronized (mAdapter.messages) {
+ for (MessageInfoHolder holder : mAdapter.messages) {
+ if (holder.selected) {
+ if (flagged) {
+ if (!holder.flagged) {
newState = true;
break;
}
- }
- else
- {
- if (!holder.read)
- {
+ } else {
+ if (!holder.read) {
newState = true;
break;
}
@@ -3079,14 +2517,10 @@ public class MessageList
return newState;
}
- private boolean anySelected()
- {
- synchronized (mAdapter.messages)
- {
- for (MessageInfoHolder holder : mAdapter.messages)
- {
- if (holder.selected)
- {
+ private boolean anySelected() {
+ synchronized (mAdapter.messages) {
+ for (MessageInfoHolder holder : mAdapter.messages) {
+ if (holder.selected) {
return true;
}
}
@@ -3095,43 +2529,30 @@ public class MessageList
}
@Override
- public void onClick(View v)
- {
+ public void onClick(View v) {
boolean newState = false;
List messageList = new ArrayList();
List removeHolderList = new ArrayList();
- if (v == mBatchDoneButton)
- {
+ if (v == mBatchDoneButton) {
setAllSelected(false);
return;
}
- if (v == mBatchFlagButton)
- {
+ if (v == mBatchFlagButton) {
newState = computeBatchDirection(true);
- }
- else
- {
+ } else {
newState = computeBatchDirection(false);
}
- synchronized (mAdapter.messages)
- {
- for (MessageInfoHolder holder : mAdapter.messages)
- {
- if (holder.selected)
- {
- if (v == mBatchDeleteButton)
- {
+ synchronized (mAdapter.messages) {
+ for (MessageInfoHolder holder : mAdapter.messages) {
+ if (holder.selected) {
+ if (v == mBatchDeleteButton) {
removeHolderList.add(holder);
- }
- else if (v == mBatchFlagButton)
- {
+ } else if (v == mBatchFlagButton) {
holder.flagged = newState;
- }
- else if (v == mBatchReadButton)
- {
+ } else if (v == mBatchReadButton) {
holder.read = newState;
}
messageList.add(holder.message);
@@ -3140,48 +2561,36 @@ public class MessageList
}
mAdapter.removeMessages(removeHolderList);
- if (!messageList.isEmpty())
- {
- if (v == mBatchDeleteButton)
- {
+ if (!messageList.isEmpty()) {
+ if (v == mBatchDeleteButton) {
mController.deleteMessages(messageList.toArray(EMPTY_MESSAGE_ARRAY), null);
mSelectedCount = 0;
toggleBatchButtons();
- }
- else
- {
+ } else {
mController.setFlag(messageList.toArray(EMPTY_MESSAGE_ARRAY), (v == mBatchReadButton ? Flag.SEEN : Flag.FLAGGED), newState);
}
- }
- else
- {
+ } else {
// Should not happen
Toast.makeText(this, R.string.no_message_seletected_toast, Toast.LENGTH_SHORT).show();
}
mHandler.sortMessages();
}
- public void onAnimationEnd(Animation animation)
- {
+ public void onAnimationEnd(Animation animation) {
}
- public void onAnimationRepeat(Animation animation)
- {
+ public void onAnimationRepeat(Animation animation) {
}
- public void onAnimationStart(Animation animation)
- {
+ public void onAnimationStart(Animation animation) {
}
- private void setAllSelected(boolean isSelected)
- {
+ private void setAllSelected(boolean isSelected) {
mSelectedCount = 0;
- synchronized (mAdapter.messages)
- {
- for (MessageInfoHolder holder : mAdapter.messages)
- {
+ synchronized (mAdapter.messages) {
+ for (MessageInfoHolder holder : mAdapter.messages) {
holder.selected = isSelected;
mSelectedCount += (isSelected ? 1 : 0);
}
@@ -3190,10 +2599,8 @@ public class MessageList
toggleBatchButtons();
}
- private void setSelected(MessageInfoHolder holder, boolean newState)
- {
- if (holder.selected != newState)
- {
+ private void setSelected(MessageInfoHolder holder, boolean newState) {
+ if (holder.selected != newState) {
holder.selected = newState;
mSelectedCount += (newState ? 1 : -1);
}
@@ -3201,22 +2608,15 @@ public class MessageList
toggleBatchButtons();
}
- private void flagSelected(Flag flag, boolean newState)
- {
+ private void flagSelected(Flag flag, boolean newState) {
List messageList = new ArrayList();
- synchronized (mAdapter.messages)
- {
- for (MessageInfoHolder holder : mAdapter.messages)
- {
- if (holder.selected)
- {
+ synchronized (mAdapter.messages) {
+ for (MessageInfoHolder holder : mAdapter.messages) {
+ if (holder.selected) {
messageList.add(holder.message);
- if (flag == Flag.SEEN)
- {
+ if (flag == Flag.SEEN) {
holder.read = newState;
- }
- else if (flag == Flag.FLAGGED)
- {
+ } else if (flag == Flag.FLAGGED) {
holder.flagged = newState;
}
}
@@ -3226,16 +2626,12 @@ public class MessageList
mHandler.sortMessages();
}
- private void deleteSelected()
- {
+ private void deleteSelected() {
List messageList = new ArrayList();
List removeHolderList = new ArrayList();
- synchronized (mAdapter.messages)
- {
- for (MessageInfoHolder holder : mAdapter.messages)
- {
- if (holder.selected)
- {
+ synchronized (mAdapter.messages) {
+ for (MessageInfoHolder holder : mAdapter.messages) {
+ if (holder.selected) {
removeHolderList.add(holder);
messageList.add(holder.message);
}
@@ -3248,22 +2644,16 @@ public class MessageList
toggleBatchButtons();
}
- private void onMoveBatch()
- {
- if (!mController.isMoveCapable(mAccount))
- {
+ private void onMoveBatch() {
+ if (!mController.isMoveCapable(mAccount)) {
return;
}
- synchronized (mAdapter.messages)
- {
- for (MessageInfoHolder holder : mAdapter.messages)
- {
- if (holder.selected)
- {
+ synchronized (mAdapter.messages) {
+ for (MessageInfoHolder holder : mAdapter.messages) {
+ if (holder.selected) {
Message message = holder.message;
- if (!mController.isMoveCapable(message))
- {
+ if (!mController.isMoveCapable(message)) {
Toast toast = Toast.makeText(this,
R.string.move_copy_cannot_copy_unsynced_message, Toast.LENGTH_LONG);
toast.show();
@@ -3281,24 +2671,18 @@ public class MessageList
startActivityForResult(intent, ACTIVITY_CHOOSE_FOLDER_MOVE_BATCH);
}
- private void onMoveChosenBatch(String folderName)
- {
- if (!mController.isMoveCapable(mAccount))
- {
+ private void onMoveChosenBatch(String folderName) {
+ if (!mController.isMoveCapable(mAccount)) {
return;
}
List messageList = new ArrayList();
List removeHolderList = new ArrayList();
- synchronized (mAdapter.messages)
- {
- for (MessageInfoHolder holder : mAdapter.messages)
- {
- if (holder.selected)
- {
+ synchronized (mAdapter.messages) {
+ for (MessageInfoHolder holder : mAdapter.messages) {
+ if (holder.selected) {
Message message = holder.message;
- if (!mController.isMoveCapable(message))
- {
+ if (!mController.isMoveCapable(message)) {
Toast toast = Toast.makeText(this,
R.string.move_copy_cannot_copy_unsynced_message, Toast.LENGTH_LONG);
toast.show();
@@ -3316,22 +2700,16 @@ public class MessageList
toggleBatchButtons();
}
- private void onArchiveBatch()
- {
- if (!mController.isMoveCapable(mAccount))
- {
+ private void onArchiveBatch() {
+ if (!mController.isMoveCapable(mAccount)) {
return;
}
- synchronized (mAdapter.messages)
- {
- for (MessageInfoHolder holder : mAdapter.messages)
- {
- if (holder.selected)
- {
+ synchronized (mAdapter.messages) {
+ for (MessageInfoHolder holder : mAdapter.messages) {
+ if (holder.selected) {
Message message = holder.message;
- if (!mController.isMoveCapable(message))
- {
+ if (!mController.isMoveCapable(message)) {
Toast toast = Toast.makeText(this, R.string.move_copy_cannot_copy_unsynced_message, Toast.LENGTH_LONG);
toast.show();
return;
@@ -3341,29 +2719,22 @@ public class MessageList
}
String folderName = mAccount.getArchiveFolderName();
- if (K9.FOLDER_NONE.equalsIgnoreCase(folderName))
- {
+ if (K9.FOLDER_NONE.equalsIgnoreCase(folderName)) {
return;
}
onMoveChosenBatch(folderName);
}
- private void onSpamBatch()
- {
- if (!mController.isMoveCapable(mAccount))
- {
+ private void onSpamBatch() {
+ if (!mController.isMoveCapable(mAccount)) {
return;
}
- synchronized (mAdapter.messages)
- {
- for (MessageInfoHolder holder : mAdapter.messages)
- {
- if (holder.selected)
- {
+ synchronized (mAdapter.messages) {
+ for (MessageInfoHolder holder : mAdapter.messages) {
+ if (holder.selected) {
Message message = holder.message;
- if (!mController.isMoveCapable(message))
- {
+ if (!mController.isMoveCapable(message)) {
Toast toast = Toast.makeText(this, R.string.move_copy_cannot_copy_unsynced_message, Toast.LENGTH_LONG);
toast.show();
return;
@@ -3373,29 +2744,22 @@ public class MessageList
}
String folderName = mAccount.getSpamFolderName();
- if (K9.FOLDER_NONE.equalsIgnoreCase(folderName))
- {
+ if (K9.FOLDER_NONE.equalsIgnoreCase(folderName)) {
return;
}
onMoveChosenBatch(folderName);
}
- private void onCopyBatch()
- {
- if (!mController.isCopyCapable(mAccount))
- {
+ private void onCopyBatch() {
+ if (!mController.isCopyCapable(mAccount)) {
return;
}
- synchronized (mAdapter.messages)
- {
- for (MessageInfoHolder holder : mAdapter.messages)
- {
- if (holder.selected)
- {
+ synchronized (mAdapter.messages) {
+ for (MessageInfoHolder holder : mAdapter.messages) {
+ if (holder.selected) {
Message message = holder.message;
- if (!mController.isCopyCapable(message))
- {
+ if (!mController.isCopyCapable(message)) {
Toast toast = Toast.makeText(this,
R.string.move_copy_cannot_copy_unsynced_message, Toast.LENGTH_LONG);
toast.show();
@@ -3413,23 +2777,17 @@ public class MessageList
startActivityForResult(intent, ACTIVITY_CHOOSE_FOLDER_COPY_BATCH);
}
- private void onCopyChosenBatch(String folderName)
- {
- if (!mController.isCopyCapable(mAccount))
- {
+ private void onCopyChosenBatch(String folderName) {
+ if (!mController.isCopyCapable(mAccount)) {
return;
}
List messageList = new ArrayList();
- synchronized (mAdapter.messages)
- {
- for (MessageInfoHolder holder : mAdapter.messages)
- {
- if (holder.selected)
- {
+ synchronized (mAdapter.messages) {
+ for (MessageInfoHolder holder : mAdapter.messages) {
+ if (holder.selected) {
Message message = holder.message;
- if (!mController.isCopyCapable(message))
- {
+ if (!mController.isCopyCapable(message)) {
Toast toast = Toast.makeText(this,
R.string.move_copy_cannot_copy_unsynced_message, Toast.LENGTH_LONG);
toast.show();
@@ -3442,8 +2800,7 @@ public class MessageList
mController.copyMessages(mAccount, mCurrentFolder.name, messageList.toArray(EMPTY_MESSAGE_ARRAY), folderName, null);
}
- protected void onAccountUnavailable()
- {
+ protected void onAccountUnavailable() {
finish();
// TODO inform user about account unavailability using Toast
Accounts.listAccounts(this);
diff --git a/src/com/fsck/k9/activity/MessageReference.java b/src/com/fsck/k9/activity/MessageReference.java
index eda8f0864..98ae77212 100644
--- a/src/com/fsck/k9/activity/MessageReference.java
+++ b/src/com/fsck/k9/activity/MessageReference.java
@@ -9,8 +9,7 @@ import com.fsck.k9.mail.MessagingException;
import java.io.Serializable;
import java.util.StringTokenizer;
-public class MessageReference implements Serializable
-{
+public class MessageReference implements Serializable {
private static final long serialVersionUID = -1625198750239083389L;
public String accountUuid;
public String folderName;
@@ -20,8 +19,7 @@ public class MessageReference implements Serializable
/**
* Initialize an empty MessageReference.
*/
- public MessageReference()
- {
+ public MessageReference() {
}
// Version identifier for use when serializing. This will allow us to introduce future versions
@@ -34,42 +32,33 @@ public class MessageReference implements Serializable
* @param identity Serialized identity.
* @throws MessagingException On missing or corrupted identity.
*/
- public MessageReference(final String identity) throws MessagingException
- {
+ public MessageReference(final String identity) throws MessagingException {
// Can't be null and must be at least length one so we can check the version.
- if (identity == null || identity.length() < 1)
- {
+ if (identity == null || identity.length() < 1) {
throw new MessagingException("Null or truncated MessageReference identity.");
}
// Version check.
- if (identity.charAt(0) == IDENTITY_VERSION_1.charAt(0))
- {
+ if (identity.charAt(0) == IDENTITY_VERSION_1.charAt(0)) {
// Split the identity, stripping away the first two characters representing the version and delimiter.
StringTokenizer tokens = new StringTokenizer(identity.substring(2), IDENTITY_SEPARATOR, false);
- if (tokens.countTokens() >= 3)
- {
+ if (tokens.countTokens() >= 3) {
accountUuid = Utility.base64Decode(tokens.nextToken());
folderName = Utility.base64Decode(tokens.nextToken());
uid = Utility.base64Decode(tokens.nextToken());
- if (tokens.hasMoreTokens())
- {
+ if (tokens.hasMoreTokens()) {
final String flagString = tokens.nextToken();
- try
- {
+ try {
flag = Flag.valueOf(flagString);
- } catch (IllegalArgumentException ie)
- {
+ } catch (IllegalArgumentException ie) {
throw new MessagingException("Could not thaw message flag '" + flagString + "'", ie);
}
}
if (K9.DEBUG)
Log.d(K9.LOG_TAG, "Thawed " + toString());
- }
- else
- {
+ } else {
throw new MessagingException("Invalid MessageReference in " + identity + " identity.");
}
}
@@ -80,8 +69,7 @@ public class MessageReference implements Serializable
*
* @return Serialized string.
*/
- public String toIdentityString()
- {
+ public String toIdentityString() {
StringBuilder refString = new StringBuilder();
refString.append(IDENTITY_VERSION_1);
@@ -91,8 +79,7 @@ public class MessageReference implements Serializable
refString.append(Utility.base64Encode(folderName));
refString.append(IDENTITY_SEPARATOR);
refString.append(Utility.base64Encode(uid));
- if (flag != null)
- {
+ if (flag != null) {
refString.append(IDENTITY_SEPARATOR);
refString.append(flag.name());
}
@@ -101,25 +88,21 @@ public class MessageReference implements Serializable
}
@Override
- public boolean equals(Object o)
- {
- if (o instanceof MessageReference == false)
- {
+ public boolean equals(Object o) {
+ if (o instanceof MessageReference == false) {
return false;
}
MessageReference other = (MessageReference)o;
if ((accountUuid == other.accountUuid || (accountUuid != null && accountUuid.equals(other.accountUuid)))
&& (folderName == other.folderName || (folderName != null && folderName.equals(other.folderName)))
- && (uid == other.uid || (uid != null && uid.equals(other.uid))))
- {
+ && (uid == other.uid || (uid != null && uid.equals(other.uid)))) {
return true;
}
return false;
}
@Override
- public int hashCode()
- {
+ public int hashCode() {
final int MULTIPLIER = 31;
int result = 1;
@@ -130,13 +113,12 @@ public class MessageReference implements Serializable
}
@Override
- public String toString()
- {
+ public String toString() {
return "MessageReference{" +
- "accountUuid='" + accountUuid + '\'' +
- ", folderName='" + folderName + '\'' +
- ", uid='" + uid + '\'' +
- ", flag=" + flag +
- '}';
+ "accountUuid='" + accountUuid + '\'' +
+ ", folderName='" + folderName + '\'' +
+ ", uid='" + uid + '\'' +
+ ", flag=" + flag +
+ '}';
}
}
diff --git a/src/com/fsck/k9/activity/MessageView.java b/src/com/fsck/k9/activity/MessageView.java
index bc2cc731c..87fe292e4 100644
--- a/src/com/fsck/k9/activity/MessageView.java
+++ b/src/com/fsck/k9/activity/MessageView.java
@@ -38,8 +38,7 @@ import com.fsck.k9.view.MessageHeader;
import java.io.Serializable;
import java.util.*;
-public class MessageView extends K9Activity implements OnClickListener
-{
+public class MessageView extends K9Activity implements OnClickListener {
private static final String EXTRA_MESSAGE_REFERENCE = "com.fsck.k9.MessageView_messageReference";
private static final String EXTRA_MESSAGE_REFERENCES = "com.fsck.k9.MessageView_messageReferences";
private static final String EXTRA_NEXT = "com.fsck.k9.MessageView_next";
@@ -85,20 +84,15 @@ public class MessageView extends K9Activity implements OnClickListener
private Contacts mContacts;
private StorageManager.StorageListener mStorageListener = new StorageListenerImplementation();
- private final class StorageListenerImplementation implements StorageManager.StorageListener
- {
+ private final class StorageListenerImplementation implements StorageManager.StorageListener {
@Override
- public void onUnmount(String providerId)
- {
- if (!providerId.equals(mAccount.getLocalStorageProviderId()))
- {
+ public void onUnmount(String providerId) {
+ if (!providerId.equals(mAccount.getLocalStorageProviderId())) {
return;
}
- runOnUiThread(new Runnable()
- {
+ runOnUiThread(new Runnable() {
@Override
- public void run()
- {
+ public void run() {
onAccountUnavailable();
}
});
@@ -110,23 +104,16 @@ public class MessageView extends K9Activity implements OnClickListener
@Override
- public boolean dispatchTouchEvent(MotionEvent ev)
- {
- if (ev.getAction() == MotionEvent.ACTION_UP)
- {
+ public boolean dispatchTouchEvent(MotionEvent ev) {
+ if (ev.getAction() == MotionEvent.ACTION_UP) {
// Text selection is finished. Allow scrolling again.
mToggleScrollView.setScrolling(true);
- }
- else if (K9.zoomControlsEnabled())
- {
+ } else if (K9.zoomControlsEnabled()) {
// If we have system zoom controls enabled, disable scrolling so the screen isn't wiggling around while
// trying to zoom.
- if (ev.getAction() == MotionEvent.ACTION_POINTER_2_DOWN)
- {
+ if (ev.getAction() == MotionEvent.ACTION_POINTER_2_DOWN) {
mToggleScrollView.setScrolling(false);
- }
- else if (ev.getAction() == MotionEvent.ACTION_POINTER_2_UP)
- {
+ } else if (ev.getAction() == MotionEvent.ACTION_POINTER_2_UP) {
mToggleScrollView.setScrolling(true);
}
}
@@ -134,156 +121,121 @@ public class MessageView extends K9Activity implements OnClickListener
}
@Override
- public boolean dispatchKeyEvent(KeyEvent event)
- {
+ public boolean dispatchKeyEvent(KeyEvent event) {
boolean ret = false;
- if (KeyEvent.ACTION_DOWN == event.getAction())
- {
+ if (KeyEvent.ACTION_DOWN == event.getAction()) {
ret = onKeyDown(event.getKeyCode(), event);
}
- if (!ret)
- {
+ if (!ret) {
ret = super.dispatchKeyEvent(event);
}
return ret;
}
@Override
- public boolean onKeyDown(final int keyCode, final KeyEvent event)
- {
- switch (keyCode)
- {
- case KeyEvent.KEYCODE_VOLUME_UP:
- {
- if (K9.useVolumeKeysForNavigationEnabled())
- {
- onNext();
- return true;
- }
- }
- case KeyEvent.KEYCODE_VOLUME_DOWN:
- {
- if (K9.useVolumeKeysForNavigationEnabled())
- {
- onPrevious();
- return true;
- }
- }
- case KeyEvent.KEYCODE_SHIFT_LEFT:
- case KeyEvent.KEYCODE_SHIFT_RIGHT:
- {
- /*
- * Selecting text started via shift key. Disable scrolling as
- * this causes problems when selecting text.
- */
- mToggleScrollView.setScrolling(false);
- break;
- }
- case KeyEvent.KEYCODE_DEL:
- {
- onDelete();
- return true;
- }
- case KeyEvent.KEYCODE_D:
- {
- onDelete();
- return true;
- }
- case KeyEvent.KEYCODE_F:
- {
- onForward();
- return true;
- }
- case KeyEvent.KEYCODE_A:
- {
- onReplyAll();
- return true;
- }
- case KeyEvent.KEYCODE_R:
- {
- onReply();
- return true;
- }
- case KeyEvent.KEYCODE_G:
- {
- onFlag();
- return true;
- }
- case KeyEvent.KEYCODE_M:
- {
- onMove();
- return true;
- }
- case KeyEvent.KEYCODE_S:
- {
- onRefile(mAccount.getSpamFolderName());
- return true;
- }
- case KeyEvent.KEYCODE_V:
- {
- onRefile(mAccount.getArchiveFolderName());
- return true;
- }
- case KeyEvent.KEYCODE_Y:
- {
- onCopy();
- return true;
- }
- case KeyEvent.KEYCODE_J:
- case KeyEvent.KEYCODE_P:
- {
- onPrevious();
- return true;
- }
- case KeyEvent.KEYCODE_N:
- case KeyEvent.KEYCODE_K:
- {
+ public boolean onKeyDown(final int keyCode, final KeyEvent event) {
+ switch (keyCode) {
+ case KeyEvent.KEYCODE_VOLUME_UP: {
+ if (K9.useVolumeKeysForNavigationEnabled()) {
onNext();
return true;
}
- case KeyEvent.KEYCODE_Z:
- {
- mHandler.post(new Runnable()
- {
- public void run()
- {
- if (mScreenReaderEnabled)
- {
- mAccessibleMessageContentView.zoomIn();
- }
- else
- {
- if (event.isShiftPressed())
- {
- mMessageContentView.zoomIn();
- }
- else
- {
- mMessageContentView.zoomOut();
- }
+ }
+ case KeyEvent.KEYCODE_VOLUME_DOWN: {
+ if (K9.useVolumeKeysForNavigationEnabled()) {
+ onPrevious();
+ return true;
+ }
+ }
+ case KeyEvent.KEYCODE_SHIFT_LEFT:
+ case KeyEvent.KEYCODE_SHIFT_RIGHT: {
+ /*
+ * Selecting text started via shift key. Disable scrolling as
+ * this causes problems when selecting text.
+ */
+ mToggleScrollView.setScrolling(false);
+ break;
+ }
+ case KeyEvent.KEYCODE_DEL: {
+ onDelete();
+ return true;
+ }
+ case KeyEvent.KEYCODE_D: {
+ onDelete();
+ return true;
+ }
+ case KeyEvent.KEYCODE_F: {
+ onForward();
+ return true;
+ }
+ case KeyEvent.KEYCODE_A: {
+ onReplyAll();
+ return true;
+ }
+ case KeyEvent.KEYCODE_R: {
+ onReply();
+ return true;
+ }
+ case KeyEvent.KEYCODE_G: {
+ onFlag();
+ return true;
+ }
+ case KeyEvent.KEYCODE_M: {
+ onMove();
+ return true;
+ }
+ case KeyEvent.KEYCODE_S: {
+ onRefile(mAccount.getSpamFolderName());
+ return true;
+ }
+ case KeyEvent.KEYCODE_V: {
+ onRefile(mAccount.getArchiveFolderName());
+ return true;
+ }
+ case KeyEvent.KEYCODE_Y: {
+ onCopy();
+ return true;
+ }
+ case KeyEvent.KEYCODE_J:
+ case KeyEvent.KEYCODE_P: {
+ onPrevious();
+ return true;
+ }
+ case KeyEvent.KEYCODE_N:
+ case KeyEvent.KEYCODE_K: {
+ onNext();
+ return true;
+ }
+ case KeyEvent.KEYCODE_Z: {
+ mHandler.post(new Runnable() {
+ public void run() {
+ if (mScreenReaderEnabled) {
+ mAccessibleMessageContentView.zoomIn();
+ } else {
+ if (event.isShiftPressed()) {
+ mMessageContentView.zoomIn();
+ } else {
+ mMessageContentView.zoomOut();
}
}
- });
- return true;
- }
- case KeyEvent.KEYCODE_H:
- {
- Toast toast = Toast.makeText(this, R.string.message_help_key, Toast.LENGTH_LONG);
- toast.show();
- return true;
- }
+ }
+ });
+ return true;
+ }
+ case KeyEvent.KEYCODE_H: {
+ Toast toast = Toast.makeText(this, R.string.message_help_key, Toast.LENGTH_LONG);
+ toast.show();
+ return true;
+ }
}
return super.onKeyDown(keyCode, event);
}
@Override
- public boolean onKeyUp(int keyCode, KeyEvent event)
- {
+ public boolean onKeyUp(int keyCode, KeyEvent event) {
// Swallow these events too to avoid the audible notification of a volume change
- if (K9.useVolumeKeysForNavigationEnabled())
- {
- if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP) || (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN))
- {
+ if (K9.useVolumeKeysForNavigationEnabled()) {
+ if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP) || (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) {
if (K9.DEBUG)
Log.v(K9.LOG_TAG, "Swallowed key up.");
return true;
@@ -292,38 +244,25 @@ public class MessageView extends K9Activity implements OnClickListener
return super.onKeyUp(keyCode, event);
}
- class MessageViewHandler extends Handler
- {
- public void setHeaders (final Message message)
- {
- runOnUiThread(new Runnable()
- {
- public void run()
- {
- try
- {
- mHeaderContainer.populate( message,mAccount);
- mHeaderContainer.setOnFlagListener( new OnClickListener()
- {
- @Override public void onClick(View v)
- {
- if (mMessage != null)
- {
+ class MessageViewHandler extends Handler {
+ public void setHeaders(final Message message) {
+ runOnUiThread(new Runnable() {
+ public void run() {
+ try {
+ mHeaderContainer.populate(message, mAccount);
+ mHeaderContainer.setOnFlagListener(new OnClickListener() {
+ @Override public void onClick(View v) {
+ if (mMessage != null) {
onFlag();
}
}
});
- }
- catch (Exception me)
- {
+ } catch (Exception me) {
Log.e(K9.LOG_TAG, "setHeaders - error", me);
}
- if (mMessage.isSet(Flag.X_DOWNLOADED_FULL))
- {
+ if (mMessage.isSet(Flag.X_DOWNLOADED_FULL)) {
mDownloadRemainder.setVisibility(View.GONE);
- }
- else
- {
+ } else {
mDownloadRemainder.setEnabled(true);
mDownloadRemainder.setVisibility(View.VISIBLE);
}
@@ -332,51 +271,37 @@ public class MessageView extends K9Activity implements OnClickListener
}
- public void progress(final boolean progress)
- {
- runOnUiThread(new Runnable()
- {
- public void run()
- {
+ public void progress(final boolean progress) {
+ runOnUiThread(new Runnable() {
+ public void run() {
setProgressBarIndeterminateVisibility(progress);
}
});
}
- public void addAttachment(final View attachmentView)
- {
- runOnUiThread(new Runnable()
- {
- public void run()
- {
+ public void addAttachment(final View attachmentView) {
+ runOnUiThread(new Runnable() {
+ public void run() {
mAttachments.addView(attachmentView);
mAttachments.setVisibility(View.VISIBLE);
}
});
}
- public void removeAllAttachments()
- {
- runOnUiThread(new Runnable()
- {
- public void run()
- {
- for (int i = 0, count = mAttachments.getChildCount(); i < count; i++)
- {
+ public void removeAllAttachments() {
+ runOnUiThread(new Runnable() {
+ public void run() {
+ for (int i = 0, count = mAttachments.getChildCount(); i < count; i++) {
mAttachments.removeView(mAttachments.getChildAt(i));
}
}
});
}
- public void setAttachmentsEnabled(final boolean enabled)
- {
- runOnUiThread(new Runnable()
- {
- public void run()
- {
- for (int i = 0, count = mAttachments.getChildCount(); i < count; i++)
- {
+ public void setAttachmentsEnabled(final boolean enabled) {
+ runOnUiThread(new Runnable() {
+ public void run() {
+ for (int i = 0, count = mAttachments.getChildCount(); i < count; i++) {
AttachmentView attachment = (AttachmentView) mAttachments.getChildAt(i);
attachment.viewButton.setEnabled(enabled);
attachment.downloadButton.setEnabled(enabled);
@@ -387,24 +312,18 @@ public class MessageView extends K9Activity implements OnClickListener
- public void networkError()
- {
- runOnUiThread(new Runnable()
- {
- public void run()
- {
+ public void networkError() {
+ runOnUiThread(new Runnable() {
+ public void run() {
Toast.makeText(MessageView.this,
R.string.status_network_error, Toast.LENGTH_LONG).show();
}
});
}
- public void invalidIdError()
- {
- runOnUiThread(new Runnable()
- {
- public void run()
- {
+ public void invalidIdError() {
+ runOnUiThread(new Runnable() {
+ public void run() {
Toast.makeText(MessageView.this,
R.string.status_invalid_id_error, Toast.LENGTH_LONG).show();
}
@@ -412,12 +331,9 @@ public class MessageView extends K9Activity implements OnClickListener
}
- public void fetchingAttachment()
- {
- runOnUiThread(new Runnable()
- {
- public void run()
- {
+ public void fetchingAttachment() {
+ runOnUiThread(new Runnable() {
+ public void run() {
Toast.makeText(MessageView.this,
getString(R.string.message_view_fetching_attachment_toast),
Toast.LENGTH_SHORT).show();
@@ -425,12 +341,9 @@ public class MessageView extends K9Activity implements OnClickListener
});
}
- public void showShowPictures(final boolean show)
- {
- runOnUiThread(new Runnable()
- {
- public void run()
- {
+ public void showShowPictures(final boolean show) {
+ runOnUiThread(new Runnable() {
+ public void run() {
mShowPicturesSection.setVisibility(show ? View.VISIBLE : View.GONE);
}
});
@@ -438,26 +351,22 @@ public class MessageView extends K9Activity implements OnClickListener
}
- public static void actionView(Context context, MessageReference messRef, List messReferences)
- {
+ public static void actionView(Context context, MessageReference messRef, List messReferences) {
actionView(context, messRef, messReferences, null);
}
- public static void actionView(Context context, MessageReference messRef, List messReferences, Bundle extras)
- {
+ public static void actionView(Context context, MessageReference messRef, List messReferences, Bundle extras) {
Intent i = new Intent(context, MessageView.class);
i.putExtra(EXTRA_MESSAGE_REFERENCE, messRef);
i.putExtra(EXTRA_MESSAGE_REFERENCES, (Serializable) messReferences);
- if (extras != null)
- {
+ if (extras != null) {
i.putExtras(extras);
}
context.startActivity(i);
}
@Override
- public void onCreate(Bundle icicle)
- {
+ public void onCreate(Bundle icicle) {
super.onCreate(icicle, false);
mContacts = Contacts.getInstance(this);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
@@ -470,13 +379,10 @@ public class MessageView extends K9Activity implements OnClickListener
mHeaderContainer = (MessageHeader) findViewById(R.id.header_container);
mScreenReaderEnabled = isScreenReaderActive();
- if (mScreenReaderEnabled)
- {
+ if (mScreenReaderEnabled) {
mAccessibleMessageContentView.setVisibility(View.VISIBLE);
mMessageContentView.setVisibility(View.GONE);
- }
- else
- {
+ } else {
mAccessibleMessageContentView.setVisibility(View.GONE);
mMessageContentView.setVisibility(View.VISIBLE);
}
@@ -486,23 +392,16 @@ public class MessageView extends K9Activity implements OnClickListener
setTitle("");
Intent intent = getIntent();
Uri uri = intent.getData();
- if (icicle != null)
- {
+ if (icicle != null) {
restoreMessageReferences(icicle);
mPgpData = (PgpData) icicle.getSerializable(STATE_PGP_DATA);
updateDecryptLayout();
- }
- else
- {
- if (uri == null)
- {
+ } else {
+ if (uri == null) {
restoreMessageReferencesExtra(intent);
- }
- else
- {
+ } else {
List segmentList = uri.getPathSegments();
- if (segmentList.size() != 3)
- {
+ if (segmentList.size() != 3) {
//TODO: Use ressource to externalize message
Toast.makeText(this, "Invalid intent uri: " + uri.toString(), Toast.LENGTH_LONG).show();
return;
@@ -511,17 +410,14 @@ public class MessageView extends K9Activity implements OnClickListener
String accountId = segmentList.get(0);
Collection accounts = Preferences.getPreferences(this).getAvailableAccounts();
boolean found = false;
- for (Account account : accounts)
- {
- if (String.valueOf(account.getAccountNumber()).equals(accountId))
- {
+ for (Account account : accounts) {
+ if (String.valueOf(account.getAccountNumber()).equals(accountId)) {
mAccount = account;
found = true;
break;
}
}
- if (!found)
- {
+ if (!found) {
//TODO: Use ressource to externalize message
Toast.makeText(this, "Invalid account id: " + accountId, Toast.LENGTH_LONG).show();
return;
@@ -540,8 +436,7 @@ public class MessageView extends K9Activity implements OnClickListener
if (K9.DEBUG)
Log.d(K9.LOG_TAG, "MessageView got message " + mMessageReference);
- if (intent.getBooleanExtra(EXTRA_NEXT, false))
- {
+ if (intent.getBooleanExtra(EXTRA_NEXT, false)) {
next.requestFocus();
}
@@ -552,21 +447,18 @@ public class MessageView extends K9Activity implements OnClickListener
}
@SuppressWarnings("unchecked")
- private void restoreMessageReferences(Bundle icicle)
- {
+ private void restoreMessageReferences(Bundle icicle) {
mMessageReference = (MessageReference) icicle.getSerializable(EXTRA_MESSAGE_REFERENCE);
mMessageReferences = (ArrayList) icicle.getSerializable(EXTRA_MESSAGE_REFERENCES);
}
@SuppressWarnings("unchecked")
- private void restoreMessageReferencesExtra(Intent intent)
- {
+ private void restoreMessageReferencesExtra(Intent intent) {
mMessageReference = (MessageReference) intent.getSerializableExtra(EXTRA_MESSAGE_REFERENCE);
mMessageReferences = (ArrayList) intent.getSerializableExtra(EXTRA_MESSAGE_REFERENCES);
}
- private void setupButtonViews()
- {
+ private void setupButtonViews() {
setOnClickListener(R.id.from);
setOnClickListener(R.id.reply);
setOnClickListener(R.id.reply_all);
@@ -598,35 +490,26 @@ public class MessageView extends K9Activity implements OnClickListener
((Account.ScrollButtons.ALWAYS == scrollButtons)
||
(Account.ScrollButtons.KEYBOARD_AVAILABLE == scrollButtons &&
- (this.getResources().getConfiguration().hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO)))
- {
+ (this.getResources().getConfiguration().hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO))) {
scrollButtons();
- }
- else // never or the keyboard is open
- {
+ } else { // never or the keyboard is open
staticButtons();
}
Account.ScrollButtons scrollMoveButtons = mAccount.getScrollMessageViewMoveButtons();
if ((Account.ScrollButtons.ALWAYS == scrollMoveButtons)
|| (Account.ScrollButtons.KEYBOARD_AVAILABLE == scrollMoveButtons &&
- (this.getResources().getConfiguration().hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO)))
- {
+ (this.getResources().getConfiguration().hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO))) {
scrollMoveButtons();
- }
- else
- {
+ } else {
staticMoveButtons();
}
- if (!mAccount.getEnableMoveButtons())
- {
+ if (!mAccount.getEnableMoveButtons()) {
View buttons = findViewById(R.id.move_buttons);
- if (buttons != null)
- {
+ if (buttons != null) {
buttons.setVisibility(View.GONE);
}
buttons = findViewById(R.id.scrolling_move_buttons);
- if (buttons != null)
- {
+ if (buttons != null) {
buttons.setVisibility(View.GONE);
}
}
@@ -635,8 +518,7 @@ public class MessageView extends K9Activity implements OnClickListener
}
- private void setupHeaderLayout()
- {
+ private void setupHeaderLayout() {
mShowPicturesSection = findViewById(R.id.show_pictures_section);
mShowPictures = false;
@@ -650,31 +532,23 @@ public class MessageView extends K9Activity implements OnClickListener
}
- private void setupDecryptLayout()
- {
+ private void setupDecryptLayout() {
mDecryptLayout = findViewById(R.id.layout_decrypt);
mDecryptButton = (Button) findViewById(R.id.btn_decrypt);
- mDecryptButton.setOnClickListener(new OnClickListener()
- {
+ mDecryptButton.setOnClickListener(new OnClickListener() {
@Override
- public void onClick(View v)
- {
- try
- {
+ public void onClick(View v) {
+ try {
String data = null;
Part part = MimeUtility.findFirstPartByMimeType(mMessage, "text/plain");
- if (part == null)
- {
+ if (part == null) {
part = MimeUtility.findFirstPartByMimeType(mMessage, "text/html");
}
- if (part != null)
- {
+ if (part != null) {
data = MimeUtility.getTextFromPart(part);
}
mAccount.getCryptoProvider().decrypt(MessageView.this, data, mPgpData);
- }
- catch (MessagingException me)
- {
+ } catch (MessagingException me) {
Log.e(K9.LOG_TAG, "Unable to decrypt email.", me);
}
}
@@ -686,8 +560,7 @@ public class MessageView extends K9Activity implements OnClickListener
mCryptoSignatureLayout.setVisibility(View.INVISIBLE);
}
- private boolean isScreenReaderActive()
- {
+ private boolean isScreenReaderActive() {
final String SCREENREADER_INTENT_ACTION = "android.accessibilityservice.AccessibilityService";
final String SCREENREADER_INTENT_CATEGORY = "android.accessibilityservice.category.FEEDBACK_SPOKEN";
// Restrict the set of intents to only accessibility services that have
@@ -699,23 +572,20 @@ public class MessageView extends K9Activity implements OnClickListener
ContentResolver cr = getContentResolver();
Cursor cursor = null;
int status = 0;
- for (ResolveInfo screenReader : screenReaders)
- {
+ for (ResolveInfo screenReader : screenReaders) {
// All screen readers are expected to implement a content provider
// that responds to
// content://.providers.StatusProvider
cursor = cr.query(Uri.parse("content://" + screenReader.serviceInfo.packageName
+ ".providers.StatusProvider"), null, null, null, null);
- if (cursor != null)
- {
+ if (cursor != null) {
cursor.moveToFirst();
// These content providers use a special cursor that only has
// one element,
// an integer that is 1 if the screen reader is running.
status = cursor.getInt(0);
cursor.close();
- if (status == 1)
- {
+ if (status == 1) {
return true;
}
}
@@ -724,8 +594,7 @@ public class MessageView extends K9Activity implements OnClickListener
}
@Override
- protected void onSaveInstanceState(Bundle outState)
- {
+ protected void onSaveInstanceState(Bundle outState) {
outState.putSerializable(EXTRA_MESSAGE_REFERENCE, mMessageReference);
outState.putSerializable(EXTRA_MESSAGE_REFERENCES, mMessageReferences);
outState.putSerializable(STATE_PGP_DATA, mPgpData);
@@ -733,16 +602,14 @@ public class MessageView extends K9Activity implements OnClickListener
}
@Override
- protected void onRestoreInstanceState(Bundle savedInstanceState)
- {
+ protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
setLoadPictures(savedInstanceState.getBoolean(SHOW_PICTURES));
initializeCrypto((PgpData) savedInstanceState.getSerializable(STATE_PGP_DATA));
updateDecryptLayout();
}
- private void displayMessage(MessageReference ref)
- {
+ private void displayMessage(MessageReference ref) {
mMessageReference = ref;
if (K9.DEBUG)
Log.d(K9.LOG_TAG, "MessageView displaying message " + mMessageReference);
@@ -767,14 +634,12 @@ public class MessageView extends K9Activity implements OnClickListener
setupDisplayMessageButtons();
}
- private void setupDisplayMessageButtons()
- {
+ private void setupDisplayMessageButtons() {
mDelete.setEnabled(true);
next.setEnabled(mNextMessage != null);
previous.setEnabled(mPreviousMessage != null);
// If moving isn't support at all, then all of them must be disabled anyway.
- if (mController.isMoveCapable(mAccount))
- {
+ if (mController.isMoveCapable(mAccount)) {
// Only enable the button if the Archive folder is not the current folder and not NONE.
mArchive.setEnabled(!mMessageReference.folderName.equals(mAccount.getArchiveFolderName()) &&
!K9.FOLDER_NONE.equalsIgnoreCase(mAccount.getArchiveFolderName()));
@@ -782,18 +647,14 @@ public class MessageView extends K9Activity implements OnClickListener
mSpam.setEnabled(!mMessageReference.folderName.equals(mAccount.getSpamFolderName()) &&
!K9.FOLDER_NONE.equalsIgnoreCase(mAccount.getSpamFolderName()));
mMove.setEnabled(true);
- }
- else
- {
+ } else {
disableMoveButtons();
}
}
- private void staticButtons()
- {
+ private void staticButtons() {
View buttons = findViewById(R.id.scrolling_buttons);
- if (buttons != null)
- {
+ if (buttons != null) {
buttons.setVisibility(View.GONE);
}
next = findViewById(R.id.next);
@@ -801,11 +662,9 @@ public class MessageView extends K9Activity implements OnClickListener
mDelete = findViewById(R.id.delete);
}
- private void scrollButtons()
- {
+ private void scrollButtons() {
View buttons = findViewById(R.id.bottom_buttons);
- if (buttons != null)
- {
+ if (buttons != null) {
buttons.setVisibility(View.GONE);
}
next = findViewById(R.id.next_scrolling);
@@ -813,11 +672,9 @@ public class MessageView extends K9Activity implements OnClickListener
mDelete = findViewById(R.id.delete_scrolling);
}
- private void staticMoveButtons()
- {
+ private void staticMoveButtons() {
View buttons = findViewById(R.id.scrolling_move_buttons);
- if (buttons != null)
- {
+ if (buttons != null) {
buttons.setVisibility(View.GONE);
}
mArchive = findViewById(R.id.archive);
@@ -825,11 +682,9 @@ public class MessageView extends K9Activity implements OnClickListener
mSpam = findViewById(R.id.spam);
}
- private void scrollMoveButtons()
- {
+ private void scrollMoveButtons() {
View buttons = findViewById(R.id.move_buttons);
- if (buttons != null)
- {
+ if (buttons != null) {
buttons.setVisibility(View.GONE);
}
mArchive = findViewById(R.id.archive_scrolling);
@@ -837,8 +692,7 @@ public class MessageView extends K9Activity implements OnClickListener
mSpam = findViewById(R.id.spam_scrolling);
}
- private void disableButtons()
- {
+ private void disableButtons() {
setLoadPictures(false);
disableMoveButtons();
next.setEnabled(false);
@@ -846,24 +700,20 @@ public class MessageView extends K9Activity implements OnClickListener
mDelete.setEnabled(false);
}
- private void disableMoveButtons()
- {
+ private void disableMoveButtons() {
mArchive.setEnabled(false);
mMove.setEnabled(false);
mSpam.setEnabled(false);
}
- private void setOnClickListener(int viewCode)
- {
+ private void setOnClickListener(int viewCode) {
View thisView = findViewById(viewCode);
- if (thisView != null)
- {
+ if (thisView != null) {
thisView.setOnClickListener(this);
}
}
- private void findSurroundingMessagesUid()
- {
+ private void findSurroundingMessagesUid() {
mNextMessage = mPreviousMessage = null;
int i = mMessageReferences.indexOf(mMessageReference);
if (i < 0)
@@ -875,11 +725,9 @@ public class MessageView extends K9Activity implements OnClickListener
}
@Override
- public void onResume()
- {
+ public void onResume() {
super.onResume();
- if (!mAccount.isAvailable(this))
- {
+ if (!mAccount.isAvailable(this)) {
onAccountUnavailable();
return;
}
@@ -887,14 +735,12 @@ public class MessageView extends K9Activity implements OnClickListener
}
@Override
- protected void onPause()
- {
+ protected void onPause() {
StorageManager.getInstance(getApplication()).removeListener(mStorageListener);
super.onPause();
}
- protected void onAccountUnavailable()
- {
+ protected void onAccountUnavailable() {
finish();
// TODO inform user about account unavailability using Toast
Accounts.listAccounts(this);
@@ -903,14 +749,10 @@ public class MessageView extends K9Activity implements OnClickListener
/**
* Called from UI thread when user select Delete
*/
- private void onDelete()
- {
- if (K9.confirmDelete())
- {
+ private void onDelete() {
+ if (K9.confirmDelete()) {
showDialog(R.id.dialog_confirm_delete);
- }
- else
- {
+ } else {
delete();
}
}
@@ -919,37 +761,30 @@ public class MessageView extends K9Activity implements OnClickListener
* @param id
* @return Never null
*/
- protected Dialog createConfirmDeleteDialog(final int id)
- {
+ protected Dialog createConfirmDeleteDialog(final int id) {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.dialog_confirm_delete_title);
builder.setMessage(R.string.dialog_confirm_delete_message);
builder.setPositiveButton(R.string.dialog_confirm_delete_confirm_button,
- new DialogInterface.OnClickListener()
- {
+ new DialogInterface.OnClickListener() {
@Override
- public void onClick(DialogInterface dialog, int which)
- {
+ public void onClick(DialogInterface dialog, int which) {
dismissDialog(id);
delete();
}
});
builder.setNegativeButton(R.string.dialog_confirm_delete_cancel_button,
- new DialogInterface.OnClickListener()
- {
+ new DialogInterface.OnClickListener() {
@Override
- public void onClick(DialogInterface dialog, int which)
- {
+ public void onClick(DialogInterface dialog, int which) {
dismissDialog(id);
}
});
return builder.create();
}
- private void delete()
- {
- if (mMessage != null)
- {
+ private void delete() {
+ if (mMessage != null) {
// Disable the delete button after it's tapped (to try to prevent
// accidental clicks)
disableButtons();
@@ -961,22 +796,18 @@ public class MessageView extends K9Activity implements OnClickListener
}
}
- private void onRefile(String dstFolder)
- {
- if (!mController.isMoveCapable(mAccount))
- {
+ private void onRefile(String dstFolder) {
+ if (!mController.isMoveCapable(mAccount)) {
return;
}
- if (!mController.isMoveCapable(mMessage))
- {
+ if (!mController.isMoveCapable(mMessage)) {
Toast toast = Toast.makeText(this, R.string.move_copy_cannot_copy_unsynced_message, Toast.LENGTH_LONG);
toast.show();
return;
}
String srcFolder = mMessageReference.folderName;
Message messageToMove = mMessage;
- if (K9.FOLDER_NONE.equalsIgnoreCase(dstFolder))
- {
+ if (K9.FOLDER_NONE.equalsIgnoreCase(dstFolder)) {
return;
}
showNextMessageOrReturn();
@@ -986,100 +817,72 @@ public class MessageView extends K9Activity implements OnClickListener
- private void showNextMessageOrReturn()
- {
- if (K9.messageViewReturnToList())
- {
+ private void showNextMessageOrReturn() {
+ if (K9.messageViewReturnToList()) {
finish();
- }
- else
- {
+ } else {
showNextMessage();
}
}
- private void showNextMessage()
- {
+ private void showNextMessage() {
findSurroundingMessagesUid();
mMessageReferences.remove(mMessageReference);
- if (mLastDirection == NEXT && mNextMessage != null)
- {
+ if (mLastDirection == NEXT && mNextMessage != null) {
onNext();
- }
- else if (mLastDirection == PREVIOUS && mPreviousMessage != null)
- {
+ } else if (mLastDirection == PREVIOUS && mPreviousMessage != null) {
onPrevious();
- }
- else if (mNextMessage != null)
- {
+ } else if (mNextMessage != null) {
onNext();
- }
- else if (mPreviousMessage != null)
- {
+ } else if (mPreviousMessage != null) {
onPrevious();
- }
- else
- {
+ } else {
finish();
}
}
- private void onReply()
- {
- if (mMessage != null)
- {
+ private void onReply() {
+ if (mMessage != null) {
MessageCompose.actionReply(this, mAccount, mMessage, false, mPgpData.getDecryptedData());
finish();
}
}
- private void onReplyAll()
- {
- if (mMessage != null)
- {
+ private void onReplyAll() {
+ if (mMessage != null) {
MessageCompose.actionReply(this, mAccount, mMessage, true, mPgpData.getDecryptedData());
finish();
}
}
- private void onForward()
- {
- if (mMessage != null)
- {
+ private void onForward() {
+ if (mMessage != null) {
MessageCompose.actionForward(this, mAccount, mMessage, mPgpData.getDecryptedData());
finish();
}
}
- private void onFlag()
- {
- if (mMessage != null)
- {
+ private void onFlag() {
+ if (mMessage != null) {
mController.setFlag(mAccount,
mMessage.getFolder().getName(), new String[] {mMessage.getUid()}, Flag.FLAGGED, !mMessage.isSet(Flag.FLAGGED));
- try
- {
+ try {
mMessage.setFlag(Flag.FLAGGED, !mMessage.isSet(Flag.FLAGGED));
- mHandler.setHeaders( mMessage);
+ mHandler.setHeaders(mMessage);
prepareMenuItems();
- }
- catch (MessagingException me)
- {
+ } catch (MessagingException me) {
Log.e(K9.LOG_TAG, "Could not set flag on local message", me);
}
}
}
- private void onMove()
- {
+ private void onMove() {
if ((!mController.isMoveCapable(mAccount))
- || (mMessage == null))
- {
+ || (mMessage == null)) {
return;
}
- if (!mController.isMoveCapable(mMessage))
- {
+ if (!mController.isMoveCapable(mMessage)) {
Toast toast = Toast.makeText(this, R.string.move_copy_cannot_copy_unsynced_message, Toast.LENGTH_LONG);
toast.show();
return;
@@ -1088,15 +891,12 @@ public class MessageView extends K9Activity implements OnClickListener
startRefileActivity(ACTIVITY_CHOOSE_FOLDER_MOVE);
}
- private void onCopy()
- {
+ private void onCopy() {
if ((!mController.isCopyCapable(mAccount))
- || (mMessage == null))
- {
+ || (mMessage == null)) {
return;
}
- if (!mController.isCopyCapable(mMessage))
- {
+ if (!mController.isCopyCapable(mMessage)) {
Toast toast = Toast.makeText(this, R.string.move_copy_cannot_copy_unsynced_message, Toast.LENGTH_LONG);
toast.show();
return;
@@ -1105,8 +905,7 @@ public class MessageView extends K9Activity implements OnClickListener
startRefileActivity(ACTIVITY_CHOOSE_FOLDER_COPY);
}
- private void startRefileActivity(int activity)
- {
+ private void startRefileActivity(int activity) {
Intent intent = new Intent(this, ChooseFolder.class);
intent.putExtra(ChooseFolder.EXTRA_ACCOUNT, mAccount.getUuid());
intent.putExtra(ChooseFolder.EXTRA_CUR_FOLDER, mMessageReference.folderName);
@@ -1117,64 +916,54 @@ public class MessageView extends K9Activity implements OnClickListener
@Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data)
- {
- if (mAccount.getCryptoProvider().onActivityResult(this, requestCode, resultCode, data, mPgpData))
- {
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (mAccount.getCryptoProvider().onActivityResult(this, requestCode, resultCode, data, mPgpData)) {
return;
}
if (resultCode != RESULT_OK)
return;
- switch (requestCode)
- {
- case ACTIVITY_CHOOSE_FOLDER_MOVE:
- case ACTIVITY_CHOOSE_FOLDER_COPY:
- if (data == null)
- return;
- String destFolderName = data.getStringExtra(ChooseFolder.EXTRA_NEW_FOLDER);
- String srcFolderName = data.getStringExtra(ChooseFolder.EXTRA_CUR_FOLDER);
- MessageReference ref = (MessageReference) data.getSerializableExtra(ChooseFolder.EXTRA_MESSAGE);
- if (mMessageReference.equals(ref))
- {
- mAccount.setLastSelectedFolderName(destFolderName);
- switch (requestCode)
- {
- case ACTIVITY_CHOOSE_FOLDER_MOVE:
- Message messageToMove = mMessage;
- showNextMessageOrReturn();
- mController.moveMessage(mAccount,
- srcFolderName, messageToMove, destFolderName, null);
- break;
- case ACTIVITY_CHOOSE_FOLDER_COPY:
- mController.copyMessage(mAccount,
- srcFolderName, mMessage, destFolderName, null);
- break;
- }
+ switch (requestCode) {
+ case ACTIVITY_CHOOSE_FOLDER_MOVE:
+ case ACTIVITY_CHOOSE_FOLDER_COPY:
+ if (data == null)
+ return;
+ String destFolderName = data.getStringExtra(ChooseFolder.EXTRA_NEW_FOLDER);
+ String srcFolderName = data.getStringExtra(ChooseFolder.EXTRA_CUR_FOLDER);
+ MessageReference ref = (MessageReference) data.getSerializableExtra(ChooseFolder.EXTRA_MESSAGE);
+ if (mMessageReference.equals(ref)) {
+ mAccount.setLastSelectedFolderName(destFolderName);
+ switch (requestCode) {
+ case ACTIVITY_CHOOSE_FOLDER_MOVE:
+ Message messageToMove = mMessage;
+ showNextMessageOrReturn();
+ mController.moveMessage(mAccount,
+ srcFolderName, messageToMove, destFolderName, null);
+ break;
+ case ACTIVITY_CHOOSE_FOLDER_COPY:
+ mController.copyMessage(mAccount,
+ srcFolderName, mMessage, destFolderName, null);
+ break;
}
- break;
+ }
+ break;
}
}
- private void onSendAlternate()
- {
- if (mMessage != null)
- {
+ private void onSendAlternate() {
+ if (mMessage != null) {
mController.sendAlternate(this, mAccount, mMessage);
}
}
@Override
- protected void onNext()
- {
- if (mNextMessage == null)
- {
+ protected void onNext() {
+ if (mNextMessage == null) {
Toast.makeText(this, getString(R.string.end_of_folder), Toast.LENGTH_SHORT).show();
return;
}
mLastDirection = NEXT;
disableButtons();
- if (K9.showAnimations())
- {
+ if (K9.showAnimations()) {
mTopView.startAnimation(outToLeftAnimation());
}
displayMessage(mNextMessage);
@@ -1182,52 +971,42 @@ public class MessageView extends K9Activity implements OnClickListener
}
@Override
- protected void onPrevious()
- {
- if (mPreviousMessage == null)
- {
+ protected void onPrevious() {
+ if (mPreviousMessage == null) {
Toast.makeText(this, getString(R.string.end_of_folder), Toast.LENGTH_SHORT).show();
return;
}
mLastDirection = PREVIOUS;
disableButtons();
- if (K9.showAnimations())
- {
+ if (K9.showAnimations()) {
mTopView.startAnimation(inFromRightAnimation());
}
displayMessage(mPreviousMessage);
previous.requestFocus();
}
- private void onMarkAsUnread()
- {
- if (mMessage != null)
- {
+ private void onMarkAsUnread() {
+ if (mMessage != null) {
mController.setFlag(
mAccount,
mMessageReference.folderName,
new String[] { mMessage.getUid() },
Flag.SEEN,
false);
- try
- {
+ try {
mMessage.setFlag(Flag.SEEN, false);
mHandler.setHeaders(mMessage);
String subject = mMessage.getSubject();
setTitle(subject);
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
Log.e(K9.LOG_TAG, "Unable to unset SEEN flag on message", e);
}
}
}
- private void onDownloadRemainder()
- {
- if (mMessage.isSet(Flag.X_DOWNLOADED_FULL))
- {
+ private void onDownloadRemainder() {
+ if (mMessage.isSet(Flag.X_DOWNLOADED_FULL)) {
return;
}
mDownloadRemainder.setEnabled(false);
@@ -1238,8 +1017,7 @@ public class MessageView extends K9Activity implements OnClickListener
mListener);
}
- private void onShowPictures()
- {
+ private void onShowPictures() {
// TODO: Download attachments that are used as inline image
setLoadPictures(true);
}
@@ -1251,152 +1029,139 @@ public class MessageView extends K9Activity implements OnClickListener
* @param enable true, if (network) images should be loaded.
* false, otherwise.
*/
- private void setLoadPictures(boolean enable)
- {
+ private void setLoadPictures(boolean enable) {
mMessageContentView.blockNetworkData(!enable);
mShowPictures = enable;
mHandler.showShowPictures(false);
}
- public void onClick(View view)
- {
- switch (view.getId())
- {
- case R.id.reply:
- case R.id.reply_scrolling:
- onReply();
- break;
- case R.id.reply_all:
- onReplyAll();
- break;
- case R.id.delete:
- case R.id.delete_scrolling:
- onDelete();
- break;
- case R.id.forward:
- case R.id.forward_scrolling:
- onForward();
- break;
- case R.id.archive:
- case R.id.archive_scrolling:
- onRefile(mAccount.getArchiveFolderName());
- break;
- case R.id.spam:
- case R.id.spam_scrolling:
- onRefile(mAccount.getSpamFolderName());
- break;
- case R.id.move:
- case R.id.move_scrolling:
- onMove();
- break;
- case R.id.next:
- case R.id.next_scrolling:
- onNext();
- break;
- case R.id.previous:
- case R.id.previous_scrolling:
- onPrevious();
- break;
- case R.id.download:
- ((AttachmentView)view).saveFile();
- break;
- case R.id.show_pictures:
- onShowPictures();
- break;
- case R.id.download_remainder:
- onDownloadRemainder();
- break;
+ public void onClick(View view) {
+ switch (view.getId()) {
+ case R.id.reply:
+ case R.id.reply_scrolling:
+ onReply();
+ break;
+ case R.id.reply_all:
+ onReplyAll();
+ break;
+ case R.id.delete:
+ case R.id.delete_scrolling:
+ onDelete();
+ break;
+ case R.id.forward:
+ case R.id.forward_scrolling:
+ onForward();
+ break;
+ case R.id.archive:
+ case R.id.archive_scrolling:
+ onRefile(mAccount.getArchiveFolderName());
+ break;
+ case R.id.spam:
+ case R.id.spam_scrolling:
+ onRefile(mAccount.getSpamFolderName());
+ break;
+ case R.id.move:
+ case R.id.move_scrolling:
+ onMove();
+ break;
+ case R.id.next:
+ case R.id.next_scrolling:
+ onNext();
+ break;
+ case R.id.previous:
+ case R.id.previous_scrolling:
+ onPrevious();
+ break;
+ case R.id.download:
+ ((AttachmentView)view).saveFile();
+ break;
+ case R.id.show_pictures:
+ onShowPictures();
+ break;
+ case R.id.download_remainder:
+ onDownloadRemainder();
+ break;
}
}
@Override
- public boolean onOptionsItemSelected(MenuItem item)
- {
- switch (item.getItemId())
- {
- case R.id.delete:
- onDelete();
- break;
- case R.id.reply:
- onReply();
- break;
- case R.id.reply_all:
- onReplyAll();
- break;
- case R.id.forward:
- onForward();
- break;
- case R.id.send_alternate:
- onSendAlternate();
- break;
- case R.id.mark_as_unread:
- onMarkAsUnread();
- break;
- case R.id.flag:
- onFlag();
- break;
- case R.id.archive:
- onRefile(mAccount.getArchiveFolderName());
- break;
- case R.id.spam:
- onRefile(mAccount.getSpamFolderName());
- break;
- case R.id.move:
- onMove();
- break;
- case R.id.copy:
- onCopy();
- break;
- case R.id.show_full_header:
- runOnUiThread(new Runnable()
- {
- @Override public void run()
- {
- mHeaderContainer.onShowAdditionalHeaders();
- }
- });
- break;
- case R.id.select_text:
- mToggleScrollView.setScrolling(false);
- mMessageContentView.emulateShiftHeld();
- break;
- default:
- return super.onOptionsItemSelected(item);
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.delete:
+ onDelete();
+ break;
+ case R.id.reply:
+ onReply();
+ break;
+ case R.id.reply_all:
+ onReplyAll();
+ break;
+ case R.id.forward:
+ onForward();
+ break;
+ case R.id.send_alternate:
+ onSendAlternate();
+ break;
+ case R.id.mark_as_unread:
+ onMarkAsUnread();
+ break;
+ case R.id.flag:
+ onFlag();
+ break;
+ case R.id.archive:
+ onRefile(mAccount.getArchiveFolderName());
+ break;
+ case R.id.spam:
+ onRefile(mAccount.getSpamFolderName());
+ break;
+ case R.id.move:
+ onMove();
+ break;
+ case R.id.copy:
+ onCopy();
+ break;
+ case R.id.show_full_header:
+ runOnUiThread(new Runnable() {
+ @Override public void run() {
+ mHeaderContainer.onShowAdditionalHeaders();
+ }
+ });
+ break;
+ case R.id.select_text:
+ mToggleScrollView.setScrolling(false);
+ mMessageContentView.emulateShiftHeld();
+ break;
+ default:
+ return super.onOptionsItemSelected(item);
}
return true;
}
@Override
- public boolean onCreateOptionsMenu(Menu menu)
- {
+ public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.message_view_option, menu);
optionsMenu = menu;
prepareMenuItems();
- if (!mController.isCopyCapable(mAccount))
- {
+ if (!mController.isCopyCapable(mAccount)) {
menu.findItem(R.id.copy).setVisible(false);
}
- if (!mController.isMoveCapable(mAccount))
- {
+ if (!mController.isMoveCapable(mAccount)) {
menu.findItem(R.id.move).setVisible(false);
menu.findItem(R.id.archive).setVisible(false);
menu.findItem(R.id.spam).setVisible(false);
}
- if (K9.FOLDER_NONE.equalsIgnoreCase(mAccount.getArchiveFolderName()))
- {
+ if (K9.FOLDER_NONE.equalsIgnoreCase(mAccount.getArchiveFolderName())) {
menu.findItem(R.id.archive).setVisible(false);
}
- if (K9.FOLDER_NONE.equalsIgnoreCase(mAccount.getSpamFolderName()))
- {
+ if (K9.FOLDER_NONE.equalsIgnoreCase(mAccount.getSpamFolderName())) {
menu.findItem(R.id.spam).setVisible(false);
}
return true;
}
@Override
- public boolean onPrepareOptionsMenu(Menu menu)
- {
+ public boolean onPrepareOptionsMenu(Menu menu) {
prepareMenuItems();
return super.onPrepareOptionsMenu(menu);
}
@@ -1408,77 +1173,58 @@ public class MessageView extends K9Activity implements OnClickListener
* @see android.app.Activity#onCreateDialog(int)
*/
@Override
- protected Dialog onCreateDialog(final int id)
- {
- switch (id)
- {
- case R.id.dialog_confirm_delete:
- {
- return createConfirmDeleteDialog(id);
- }
+ protected Dialog onCreateDialog(final int id) {
+ switch (id) {
+ case R.id.dialog_confirm_delete: {
+ return createConfirmDeleteDialog(id);
+ }
}
return super.onCreateDialog(id);
}
- private void prepareMenuItems()
- {
+ private void prepareMenuItems() {
Menu menu = optionsMenu;
- if (menu != null)
- {
+ if (menu != null) {
MenuItem flagItem = menu.findItem(R.id.flag);
- if (flagItem != null && mMessage != null)
- {
+ if (flagItem != null && mMessage != null) {
flagItem.setTitle((mMessage.isSet(Flag.FLAGGED) ? R.string.unflag_action : R.string.flag_action));
}
MenuItem additionalHeadersItem = menu.findItem(R.id.show_full_header);
- if (additionalHeadersItem != null)
- {
+ if (additionalHeadersItem != null) {
additionalHeadersItem.setTitle(mHeaderContainer.additionalHeadersVisible() ?
R.string.hide_full_header_action : R.string.show_full_header_action);
}
}
}
- public void displayMessage(Account account, String folder, String uid, Message message)
- {
- try
- {
+ public void displayMessage(Account account, String folder, String uid, Message message) {
+ try {
if (MessageView.this.mMessage != null
&& MessageView.this.mMessage.isSet(Flag.X_DOWNLOADED_PARTIAL)
- && message.isSet(Flag.X_DOWNLOADED_FULL))
- {
+ && message.isSet(Flag.X_DOWNLOADED_FULL)) {
mHandler.setHeaders(message);
}
MessageView.this.mMessage = message;
mHandler.removeAllAttachments();
String text, type;
- if (mPgpData.getDecryptedData() != null)
- {
+ if (mPgpData.getDecryptedData() != null) {
text = mPgpData.getDecryptedData();
type = "text/plain";
- }
- else
- {
+ } else {
// getTextForDisplay() always returns HTML-ified content.
text = ((LocalMessage) mMessage).getTextForDisplay();
type = "text/html";
}
- if (text != null)
- {
+ if (text != null) {
final String emailText = text;
final String contentType = type;
- mHandler.post(new Runnable()
- {
- public void run()
- {
+ mHandler.post(new Runnable() {
+ public void run() {
mTopView.scrollTo(0, 0);
- if (mScreenReaderEnabled)
- {
+ if (mScreenReaderEnabled) {
mAccessibleMessageContentView.loadDataWithBaseURL("http://",
emailText, contentType, "utf-8", null);
- }
- else
- {
+ } else {
mMessageContentView.loadDataWithBaseURL("http://", emailText,
contentType, "utf-8", null);
mMessageContentView.scrollTo(0, 0);
@@ -1489,97 +1235,72 @@ public class MessageView extends K9Activity implements OnClickListener
// If the message contains external pictures and the "Show pictures"
// button wasn't already pressed, see if the user's preferences has us
// showing them anyway.
- if (Utility.hasExternalImages(text) && !mShowPictures)
- {
+ if (Utility.hasExternalImages(text) && !mShowPictures) {
if ((account.getShowPictures() == Account.ShowPictures.ALWAYS) ||
((account.getShowPictures() == Account.ShowPictures.ONLY_FROM_CONTACTS) &&
- mContacts.isInContacts(message.getFrom()[0].getAddress())))
- {
+ mContacts.isInContacts(message.getFrom()[0].getAddress()))) {
onShowPictures();
- }
- else
- {
+ } else {
mHandler.showShowPictures(true);
}
}
- }
- else
- {
- mHandler.post(new Runnable()
- {
- public void run()
- {
+ } else {
+ mHandler.post(new Runnable() {
+ public void run() {
mMessageContentView.loadUrl("file:///android_asset/empty.html");
updateDecryptLayout();
}
});
}
renderAttachments(mMessage, 0);
- }
- catch (Exception e)
- {
- if (Config.LOGV)
- {
+ } catch (Exception e) {
+ if (Config.LOGV) {
Log.v(K9.LOG_TAG, "loadMessageForViewBodyAvailable", e);
}
}
}
- private void renderAttachments(Part part, int depth) throws MessagingException
- {
- if (part.getBody() instanceof Multipart)
- {
+ private void renderAttachments(Part part, int depth) throws MessagingException {
+ if (part.getBody() instanceof Multipart) {
Multipart mp = (Multipart) part.getBody();
- for (int i = 0; i < mp.getCount(); i++)
- {
+ for (int i = 0; i < mp.getCount(); i++) {
renderAttachments(mp.getBodyPart(i), depth + 1);
}
- }
- else if (part instanceof LocalAttachmentBodyPart)
- {
+ } else if (part instanceof LocalAttachmentBodyPart) {
String contentDisposition = MimeUtility.unfoldAndDecode(part.getDisposition());
// Inline parts with a content-id are almost certainly components of an HTML message
// not attachments. Don't show attachment download buttons for them.
if (contentDisposition != null &&
MimeUtility.getHeaderParameter(contentDisposition, null).matches("^(?i:inline)")
- && part.getHeader("Content-ID") != null)
- {
+ && part.getHeader("Content-ID") != null) {
return;
}
renderPartAsAttachment(part);
}
}
- private void renderPartAsAttachment(Part part) throws MessagingException
- {
+ private void renderPartAsAttachment(Part part) throws MessagingException {
LayoutInflater inflater = getLayoutInflater();
AttachmentView view = (AttachmentView)inflater.inflate(R.layout.message_view_attachment, null);
- if (view.populateFromPart(part, mMessage, mAccount, mController, mListener))
- {
+ if (view.populateFromPart(part, mMessage, mAccount, mController, mListener)) {
mHandler.addAttachment(view);
}
return;
}
- class Listener extends MessagingListener
- {
+ class Listener extends MessagingListener {
@Override
public void loadMessageForViewHeadersAvailable(Account account, String folder, String uid,
- final Message message)
- {
+ final Message message) {
if (!mMessageReference.uid.equals(uid) || !mMessageReference.folderName.equals(folder)
- || !mMessageReference.accountUuid.equals(account.getUuid()))
- {
+ || !mMessageReference.accountUuid.equals(account.getUuid())) {
return;
}
MessageView.this.mMessage = message;
if (!message.isSet(Flag.X_DOWNLOADED_FULL)
- && !message.isSet(Flag.X_DOWNLOADED_PARTIAL))
- {
- mHandler.post(new Runnable()
- {
- public void run()
- {
+ && !message.isSet(Flag.X_DOWNLOADED_PARTIAL)) {
+ mHandler.post(new Runnable() {
+ public void run() {
mMessageContentView.loadUrl("file:///android_asset/downloading.html");
updateDecryptLayout();
}
@@ -1590,11 +1311,9 @@ public class MessageView extends K9Activity implements OnClickListener
@Override
public void loadMessageForViewBodyAvailable(Account account, String folder, String uid,
- Message message)
- {
+ Message message) {
if (!mMessageReference.uid.equals(uid) || !mMessageReference.folderName.equals(folder)
- || !mMessageReference.accountUuid.equals(account.getUuid()))
- {
+ || !mMessageReference.accountUuid.equals(account.getUuid())) {
return;
}
@@ -1605,29 +1324,21 @@ public class MessageView extends K9Activity implements OnClickListener
@Override
public void loadMessageForViewFailed(Account account, String folder, String uid,
- final Throwable t)
- {
+ final Throwable t) {
if (!mMessageReference.uid.equals(uid) || !mMessageReference.folderName.equals(folder)
- || !mMessageReference.accountUuid.equals(account.getUuid()))
- {
+ || !mMessageReference.accountUuid.equals(account.getUuid())) {
return;
}
- mHandler.post(new Runnable()
- {
- public void run()
- {
+ mHandler.post(new Runnable() {
+ public void run() {
setProgressBarIndeterminateVisibility(false);
- if (t instanceof IllegalArgumentException)
- {
+ if (t instanceof IllegalArgumentException) {
mHandler.invalidIdError();
- }
- else
- {
+ } else {
mHandler.networkError();
}
if ((MessageView.this.mMessage == null) ||
- !MessageView.this.mMessage.isSet(Flag.X_DOWNLOADED_PARTIAL))
- {
+ !MessageView.this.mMessage.isSet(Flag.X_DOWNLOADED_PARTIAL)) {
mMessageContentView.loadUrl("file:///android_asset/empty.html");
updateDecryptLayout();
}
@@ -1637,34 +1348,26 @@ public class MessageView extends K9Activity implements OnClickListener
@Override
public void loadMessageForViewFinished(Account account, String folder, String uid,
- Message message)
- {
+ Message message) {
if (!mMessageReference.uid.equals(uid) || !mMessageReference.folderName.equals(folder)
- || !mMessageReference.accountUuid.equals(account.getUuid()))
- {
+ || !mMessageReference.accountUuid.equals(account.getUuid())) {
return;
}
- mHandler.post(new Runnable()
- {
- public void run()
- {
+ mHandler.post(new Runnable() {
+ public void run() {
setProgressBarIndeterminateVisibility(false);
}
});
}
@Override
- public void loadMessageForViewStarted(Account account, String folder, String uid)
- {
+ public void loadMessageForViewStarted(Account account, String folder, String uid) {
if (!mMessageReference.uid.equals(uid) || !mMessageReference.folderName.equals(folder)
- || !mMessageReference.accountUuid.equals(account.getUuid()))
- {
+ || !mMessageReference.accountUuid.equals(account.getUuid())) {
return;
}
- mHandler.post(new Runnable()
- {
- public void run()
- {
+ mHandler.post(new Runnable() {
+ public void run() {
updateDecryptLayout();
setProgressBarIndeterminateVisibility(true);
}
@@ -1673,26 +1376,21 @@ public class MessageView extends K9Activity implements OnClickListener
@Override
public void loadAttachmentStarted(Account account, Message message,
- Part part, Object tag, boolean requiresDownload)
- {
- if (mMessage != message)
- {
+ Part part, Object tag, boolean requiresDownload) {
+ if (mMessage != message) {
return;
}
mHandler.setAttachmentsEnabled(false);
mHandler.progress(true);
- if (requiresDownload)
- {
+ if (requiresDownload) {
mHandler.fetchingAttachment();
}
}
@Override
public void loadAttachmentFinished(Account account, Message message,
- Part part, Object tag)
- {
- if (mMessage != message)
- {
+ Part part, Object tag) {
+ if (mMessage != message) {
return;
}
mHandler.setAttachmentsEnabled(true);
@@ -1700,23 +1398,18 @@ public class MessageView extends K9Activity implements OnClickListener
Object[] params = (Object[]) tag;
boolean download = (Boolean) params[0];
AttachmentView attachment = (AttachmentView) params[1];
- if (download)
- {
+ if (download) {
attachment.writeFile();
- }
- else
- {
+ } else {
attachment.showFile();
}
}
@Override
public void loadAttachmentFailed(Account account, Message message, Part part,
- Object tag, String reason)
- {
- if (mMessage != message)
- {
+ Object tag, String reason) {
+ if (mMessage != message) {
return;
}
mHandler.setAttachmentsEnabled(true);
@@ -1726,18 +1419,13 @@ public class MessageView extends K9Activity implements OnClickListener
}
- private void initializeCrypto(PgpData data)
- {
- if (data == null)
- {
- if (mAccount == null)
- {
+ private void initializeCrypto(PgpData data) {
+ if (data == null) {
+ if (mAccount == null) {
mAccount = Preferences.getPreferences(this).getAccount(mMessageReference.accountUuid);
}
mPgpData = new PgpData();
- }
- else
- {
+ } else {
mPgpData = data;
}
}
@@ -1746,56 +1434,40 @@ public class MessageView extends K9Activity implements OnClickListener
* Fill the decrypt layout with signature data, if known, make controls visible, if
* they should be visible.
*/
- public void updateDecryptLayout()
- {
- if (mPgpData.getSignatureKeyId() != 0)
- {
+ public void updateDecryptLayout() {
+ if (mPgpData.getSignatureKeyId() != 0) {
mCryptoSignatureUserIdRest.setText(
getString(R.string.key_id, Long.toHexString(mPgpData.getSignatureKeyId() & 0xffffffffL)));
String userId = mPgpData.getSignatureUserId();
- if (userId == null)
- {
+ if (userId == null) {
userId = getString(R.string.unknown_crypto_signature_user_id);
}
String chunks[] = userId.split(" <", 2);
String name = chunks[0];
- if (chunks.length > 1)
- {
+ if (chunks.length > 1) {
mCryptoSignatureUserIdRest.setText("<" + chunks[1]);
}
mCryptoSignatureUserId.setText(name);
- if (mPgpData.getSignatureSuccess())
- {
+ if (mPgpData.getSignatureSuccess()) {
mCryptoSignatureStatusImage.setImageResource(R.drawable.overlay_ok);
- }
- else if (mPgpData.getSignatureUnknown())
- {
+ } else if (mPgpData.getSignatureUnknown()) {
mCryptoSignatureStatusImage.setImageResource(R.drawable.overlay_error);
- }
- else
- {
+ } else {
mCryptoSignatureStatusImage.setImageResource(R.drawable.overlay_error);
}
mCryptoSignatureLayout.setVisibility(View.VISIBLE);
mDecryptLayout.setVisibility(View.VISIBLE);
- }
- else
- {
+ } else {
mCryptoSignatureLayout.setVisibility(View.INVISIBLE);
}
- if (false || ((mMessage == null) && (mPgpData.getDecryptedData() == null)))
- {
+ if (false || ((mMessage == null) && (mPgpData.getDecryptedData() == null))) {
mDecryptLayout.setVisibility(View.GONE);
return;
}
- if (mPgpData.getDecryptedData() != null)
- {
- if (mPgpData.getSignatureKeyId() == 0)
- {
+ if (mPgpData.getDecryptedData() != null) {
+ if (mPgpData.getSignatureKeyId() == 0) {
mDecryptLayout.setVisibility(View.GONE);
- }
- else
- {
+ } else {
// no need to show this after decryption/verification
mDecryptButton.setVisibility(View.GONE);
}
@@ -1803,37 +1475,27 @@ public class MessageView extends K9Activity implements OnClickListener
}
mDecryptButton.setVisibility(View.VISIBLE);
CryptoProvider crypto = mAccount.getCryptoProvider();
- if (crypto.isEncrypted(mMessage))
- {
+ if (crypto.isEncrypted(mMessage)) {
mDecryptButton.setText(R.string.btn_decrypt);
mDecryptLayout.setVisibility(View.VISIBLE);
- }
- else if (crypto.isSigned(mMessage))
- {
+ } else if (crypto.isSigned(mMessage)) {
mDecryptButton.setText(R.string.btn_verify);
mDecryptLayout.setVisibility(View.VISIBLE);
- }
- else
- {
+ } else {
mDecryptLayout.setVisibility(View.GONE);
- try
- {
+ try {
// check for PGP/MIME encryption
Part pgp = MimeUtility.findFirstPartByMimeType(mMessage, "application/pgp-encrypted");
- if (pgp != null)
- {
+ if (pgp != null) {
Toast.makeText(this, R.string.pgp_mime_unsupported, Toast.LENGTH_LONG).show();
}
- }
- catch (MessagingException e)
- {
+ } catch (MessagingException e) {
// nothing to do...
}
}
}
- public void onDecryptDone()
- {
+ public void onDecryptDone() {
// TODO: this might not be enough if the orientation was changed while in APG,
// sometimes shows the original encrypted content
mMessageContentView.loadDataWithBaseURL("email://", mPgpData.getDecryptedData(), "text/plain", "utf-8", null);
diff --git a/src/com/fsck/k9/activity/ProgressListener.java b/src/com/fsck/k9/activity/ProgressListener.java
index 6d8f6fdc3..5617b0616 100644
--- a/src/com/fsck/k9/activity/ProgressListener.java
+++ b/src/com/fsck/k9/activity/ProgressListener.java
@@ -6,8 +6,7 @@ import android.content.Context;
/**
* A listener that the user can register for global, persistent progress events.
*/
-public interface ProgressListener
-{
+public interface ProgressListener {
/**
* @param context
* @param title
diff --git a/src/com/fsck/k9/activity/Search.java b/src/com/fsck/k9/activity/Search.java
index 52f3c4a4d..3f2a2a077 100644
--- a/src/com/fsck/k9/activity/Search.java
+++ b/src/com/fsck/k9/activity/Search.java
@@ -2,7 +2,6 @@ package com.fsck.k9.activity;
import com.fsck.k9.activity.MessageList;
-public class Search extends MessageList
-{
+public class Search extends MessageList {
}
diff --git a/src/com/fsck/k9/activity/SearchModifier.java b/src/com/fsck/k9/activity/SearchModifier.java
index c9e48ca81..b23330c80 100644
--- a/src/com/fsck/k9/activity/SearchModifier.java
+++ b/src/com/fsck/k9/activity/SearchModifier.java
@@ -6,16 +6,14 @@ package com.fsck.k9.activity;
import com.fsck.k9.R;
import com.fsck.k9.mail.Flag;
-enum SearchModifier
-{
+enum SearchModifier {
FLAGGED(R.string.flagged_modifier, new Flag[] { Flag.FLAGGED}, null), UNREAD(R.string.unread_modifier, null, new Flag[] { Flag.SEEN});
final int resId;
final Flag[] requiredFlags;
final Flag[] forbiddenFlags;
- SearchModifier(int nResId, Flag[] nRequiredFlags, Flag[] nForbiddenFlags)
- {
+ SearchModifier(int nResId, Flag[] nRequiredFlags, Flag[] nForbiddenFlags) {
resId = nResId;
requiredFlags = nRequiredFlags;
forbiddenFlags = nForbiddenFlags;
diff --git a/src/com/fsck/k9/activity/setup/AccountSettings.java b/src/com/fsck/k9/activity/setup/AccountSettings.java
index ecf577fd8..84c452110 100644
--- a/src/com/fsck/k9/activity/setup/AccountSettings.java
+++ b/src/com/fsck/k9/activity/setup/AccountSettings.java
@@ -36,8 +36,7 @@ import com.fsck.k9.mail.store.StorageManager;
import com.fsck.k9.mail.store.LocalStore.LocalFolder;
-public class AccountSettings extends K9PreferenceActivity
-{
+public class AccountSettings extends K9PreferenceActivity {
private static final String EXTRA_ACCOUNT = "account";
private static final int SELECT_AUTO_EXPAND_FOLDER = 1;
@@ -164,29 +163,24 @@ public class AccountSettings extends K9PreferenceActivity
private ListPreference mTrashFolder;
- public static void actionSettings(Context context, Account account)
- {
+ public static void actionSettings(Context context, Account account) {
Intent i = new Intent(context, AccountSettings.class);
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
context.startActivity(i);
}
@Override
- public void onCreate(Bundle savedInstanceState)
- {
+ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
- try
- {
+ try {
final Store store = mAccount.getRemoteStore();
mIsPushCapable = store.isPushCapable();
mIsExpungeCapable = store.isExpungeCapable();
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
Log.e(K9.LOG_TAG, "Could not get remote store", e);
}
@@ -195,10 +189,8 @@ public class AccountSettings extends K9PreferenceActivity
mAccountDescription = (EditTextPreference) findPreference(PREFERENCE_DESCRIPTION);
mAccountDescription.setSummary(mAccount.getDescription());
mAccountDescription.setText(mAccount.getDescription());
- mAccountDescription.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
- {
- public boolean onPreferenceChange(Preference preference, Object newValue)
- {
+ mAccountDescription.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
mAccountDescription.setSummary(summary);
mAccountDescription.setText(summary);
@@ -209,10 +201,8 @@ public class AccountSettings extends K9PreferenceActivity
mMessageFormat = (ListPreference) findPreference(PREFERENCE_MESSAGE_FORMAT);
mMessageFormat.setValue(mAccount.getMessageFormat().name());
mMessageFormat.setSummary(mMessageFormat.getEntry());
- mMessageFormat.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
- {
- public boolean onPreferenceChange(Preference preference, Object newValue)
- {
+ mMessageFormat.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mMessageFormat.findIndexOfValue(summary);
mMessageFormat.setSummary(mMessageFormat.getEntries()[index]);
@@ -224,11 +214,9 @@ public class AccountSettings extends K9PreferenceActivity
mAccountQuotePrefix = (EditTextPreference) findPreference(PREFERENCE_QUOTE_PREFIX);
mAccountQuotePrefix.setSummary(mAccount.getQuotePrefix());
mAccountQuotePrefix.setText(mAccount.getQuotePrefix());
- mAccountQuotePrefix.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
- {
+ mAccountQuotePrefix.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
- public boolean onPreferenceChange(Preference preference, Object newValue)
- {
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
final String value = newValue.toString();
mAccountQuotePrefix.setSummary(value);
mAccountQuotePrefix.setText(value);
@@ -241,21 +229,16 @@ public class AccountSettings extends K9PreferenceActivity
mComposingScreen = (PreferenceScreen) findPreference(PREFERENCE_SCREEN_COMPOSING);
- Preference.OnPreferenceChangeListener quoteStyleListener = new Preference.OnPreferenceChangeListener()
- {
+ Preference.OnPreferenceChangeListener quoteStyleListener = new Preference.OnPreferenceChangeListener() {
@Override
- public boolean onPreferenceChange(Preference preference, Object newValue)
- {
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
final QuoteStyle style = QuoteStyle.valueOf(newValue.toString());
int index = mQuoteStyle.findIndexOfValue(newValue.toString());
mQuoteStyle.setSummary(mQuoteStyle.getEntries()[index]);
- if (style == QuoteStyle.PREFIX)
- {
+ if (style == QuoteStyle.PREFIX) {
mComposingScreen.addPreference(mAccountQuotePrefix);
mComposingScreen.addPreference(mReplyAfterQuote);
- }
- else if (style == QuoteStyle.HEADER)
- {
+ } else if (style == QuoteStyle.HEADER) {
mComposingScreen.removePreference(mAccountQuotePrefix);
mComposingScreen.removePreference(mReplyAfterQuote);
}
@@ -273,10 +256,8 @@ public class AccountSettings extends K9PreferenceActivity
mCheckFrequency = (ListPreference) findPreference(PREFERENCE_FREQUENCY);
mCheckFrequency.setValue(String.valueOf(mAccount.getAutomaticCheckIntervalMinutes()));
mCheckFrequency.setSummary(mCheckFrequency.getEntry());
- mCheckFrequency.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
- {
- public boolean onPreferenceChange(Preference preference, Object newValue)
- {
+ mCheckFrequency.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mCheckFrequency.findIndexOfValue(summary);
mCheckFrequency.setSummary(mCheckFrequency.getEntries()[index]);
@@ -288,10 +269,8 @@ public class AccountSettings extends K9PreferenceActivity
mDisplayMode = (ListPreference) findPreference(PREFERENCE_DISPLAY_MODE);
mDisplayMode.setValue(mAccount.getFolderDisplayMode().name());
mDisplayMode.setSummary(mDisplayMode.getEntry());
- mDisplayMode.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
- {
- public boolean onPreferenceChange(Preference preference, Object newValue)
- {
+ mDisplayMode.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mDisplayMode.findIndexOfValue(summary);
mDisplayMode.setSummary(mDisplayMode.getEntries()[index]);
@@ -303,10 +282,8 @@ public class AccountSettings extends K9PreferenceActivity
mSyncMode = (ListPreference) findPreference(PREFERENCE_SYNC_MODE);
mSyncMode.setValue(mAccount.getFolderSyncMode().name());
mSyncMode.setSummary(mSyncMode.getEntry());
- mSyncMode.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
- {
- public boolean onPreferenceChange(Preference preference, Object newValue)
- {
+ mSyncMode.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mSyncMode.findIndexOfValue(summary);
mSyncMode.setSummary(mSyncMode.getEntries()[index]);
@@ -319,10 +296,8 @@ public class AccountSettings extends K9PreferenceActivity
mPushMode.setEnabled(mIsPushCapable);
mPushMode.setValue(mAccount.getFolderPushMode().name());
mPushMode.setSummary(mPushMode.getEntry());
- mPushMode.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
- {
- public boolean onPreferenceChange(Preference preference, Object newValue)
- {
+ mPushMode.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mPushMode.findIndexOfValue(summary);
mPushMode.setSummary(mPushMode.getEntries()[index]);
@@ -334,10 +309,8 @@ public class AccountSettings extends K9PreferenceActivity
mTargetMode = (ListPreference) findPreference(PREFERENCE_TARGET_MODE);
mTargetMode.setValue(mAccount.getFolderTargetMode().name());
mTargetMode.setSummary(mTargetMode.getEntry());
- mTargetMode.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
- {
- public boolean onPreferenceChange(Preference preference, Object newValue)
- {
+ mTargetMode.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mTargetMode.findIndexOfValue(summary);
mTargetMode.setSummary(mTargetMode.getEntries()[index]);
@@ -349,10 +322,8 @@ public class AccountSettings extends K9PreferenceActivity
mDeletePolicy = (ListPreference) findPreference(PREFERENCE_DELETE_POLICY);
mDeletePolicy.setValue("" + mAccount.getDeletePolicy());
mDeletePolicy.setSummary(mDeletePolicy.getEntry());
- mDeletePolicy.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
- {
- public boolean onPreferenceChange(Preference preference, Object newValue)
- {
+ mDeletePolicy.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mDeletePolicy.findIndexOfValue(summary);
mDeletePolicy.setSummary(mDeletePolicy.getEntries()[index]);
@@ -365,10 +336,8 @@ public class AccountSettings extends K9PreferenceActivity
mExpungePolicy.setEnabled(mIsExpungeCapable);
mExpungePolicy.setValue(mAccount.getExpungePolicy());
mExpungePolicy.setSummary(mExpungePolicy.getEntry());
- mExpungePolicy.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
- {
- public boolean onPreferenceChange(Preference preference, Object newValue)
- {
+ mExpungePolicy.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mExpungePolicy.findIndexOfValue(summary);
mExpungePolicy.setSummary(mExpungePolicy.getEntries()[index]);
@@ -386,10 +355,8 @@ public class AccountSettings extends K9PreferenceActivity
mSearchableFolders = (ListPreference) findPreference(PREFERENCE_SEARCHABLE_FOLDERS);
mSearchableFolders.setValue(mAccount.getSearchableFolders().name());
mSearchableFolders.setSummary(mSearchableFolders.getEntry());
- mSearchableFolders.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
- {
- public boolean onPreferenceChange(Preference preference, Object newValue)
- {
+ mSearchableFolders.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mSearchableFolders.findIndexOfValue(summary);
mSearchableFolders.setSummary(mSearchableFolders.getEntries()[index]);
@@ -401,10 +368,8 @@ public class AccountSettings extends K9PreferenceActivity
mDisplayCount = (ListPreference) findPreference(PREFERENCE_DISPLAY_COUNT);
mDisplayCount.setValue(String.valueOf(mAccount.getDisplayCount()));
mDisplayCount.setSummary(mDisplayCount.getEntry());
- mDisplayCount.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
- {
- public boolean onPreferenceChange(Preference preference, Object newValue)
- {
+ mDisplayCount.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mDisplayCount.findIndexOfValue(summary);
mDisplayCount.setSummary(mDisplayCount.getEntries()[index]);
@@ -416,10 +381,8 @@ public class AccountSettings extends K9PreferenceActivity
mMessageAge = (ListPreference) findPreference(PREFERENCE_MESSAGE_AGE);
mMessageAge.setValue(String.valueOf(mAccount.getMaximumPolledMessageAge()));
mMessageAge.setSummary(mMessageAge.getEntry());
- mMessageAge.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
- {
- public boolean onPreferenceChange(Preference preference, Object newValue)
- {
+ mMessageAge.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mMessageAge.findIndexOfValue(summary);
mMessageAge.setSummary(mMessageAge.getEntries()[index]);
@@ -431,10 +394,8 @@ public class AccountSettings extends K9PreferenceActivity
mMessageSize = (ListPreference) findPreference(PREFERENCE_MESSAGE_SIZE);
mMessageSize.setValue(String.valueOf(mAccount.getMaximumAutoDownloadMessageSize()));
mMessageSize.setSummary(mMessageSize.getEntry());
- mMessageSize.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
- {
- public boolean onPreferenceChange(Preference preference, Object newValue)
- {
+ mMessageSize.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mMessageSize.findIndexOfValue(summary);
mMessageSize.setSummary(mMessageSize.getEntries()[index]);
@@ -450,10 +411,8 @@ public class AccountSettings extends K9PreferenceActivity
mAccountScrollButtons = (ListPreference) findPreference(PREFERENCE_HIDE_BUTTONS);
mAccountScrollButtons.setValue("" + mAccount.getScrollMessageViewButtons());
mAccountScrollButtons.setSummary(mAccountScrollButtons.getEntry());
- mAccountScrollButtons.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
- {
- public boolean onPreferenceChange(Preference preference, Object newValue)
- {
+ mAccountScrollButtons.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mAccountScrollButtons.findIndexOfValue(summary);
mAccountScrollButtons.setSummary(mAccountScrollButtons.getEntries()[index]);
@@ -468,10 +427,8 @@ public class AccountSettings extends K9PreferenceActivity
mAccountScrollMoveButtons = (ListPreference) findPreference(PREFERENCE_HIDE_MOVE_BUTTONS);
mAccountScrollMoveButtons.setValue("" + mAccount.getScrollMessageViewMoveButtons());
mAccountScrollMoveButtons.setSummary(mAccountScrollMoveButtons.getEntry());
- mAccountScrollMoveButtons.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
- {
- public boolean onPreferenceChange(Preference preference, Object newValue)
- {
+ mAccountScrollMoveButtons.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mAccountScrollMoveButtons.findIndexOfValue(summary);
mAccountScrollMoveButtons.setSummary(mAccountScrollMoveButtons.getEntries()[index]);
@@ -483,10 +440,8 @@ public class AccountSettings extends K9PreferenceActivity
mAccountShowPictures = (ListPreference) findPreference(PREFERENCE_SHOW_PICTURES);
mAccountShowPictures.setValue("" + mAccount.getShowPictures());
mAccountShowPictures.setSummary(mAccountShowPictures.getEntry());
- mAccountShowPictures.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
- {
- public boolean onPreferenceChange(Preference preference, Object newValue)
- {
+ mAccountShowPictures.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mAccountShowPictures.findIndexOfValue(summary);
mAccountShowPictures.setSummary(mAccountShowPictures.getEntries()[index]);
@@ -503,8 +458,7 @@ public class AccountSettings extends K9PreferenceActivity
int i = 0;
final String[] providerLabels = new String[providers.size()];
final String[] providerIds = new String[providers.size()];
- for (final Map.Entry entry : providers.entrySet())
- {
+ for (final Map.Entry entry : providers.entrySet()) {
providerIds[i] = entry.getKey();
providerLabels[i] = entry.getValue();
i++;
@@ -514,10 +468,8 @@ public class AccountSettings extends K9PreferenceActivity
mLocalStorageProvider.setValue(mAccount.getLocalStorageProviderId());
mLocalStorageProvider.setSummary(providers.get(mAccount.getLocalStorageProviderId()));
- mLocalStorageProvider.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
- {
- public boolean onPreferenceChange(Preference preference, Object newValue)
- {
+ mLocalStorageProvider.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
mLocalStorageProvider.setSummary(providers.get(newValue));
return true;
}
@@ -528,16 +480,13 @@ public class AccountSettings extends K9PreferenceActivity
mPushPollOnConnect = (CheckBoxPreference) findPreference(PREFERENCE_PUSH_POLL_ON_CONNECT);
mIdleRefreshPeriod = (ListPreference) findPreference(PREFERENCE_IDLE_REFRESH_PERIOD);
mMaxPushFolders = (ListPreference) findPreference(PREFERENCE_MAX_PUSH_FOLDERS);
- if (mIsPushCapable)
- {
+ if (mIsPushCapable) {
mPushPollOnConnect.setChecked(mAccount.isPushPollOnConnect());
mIdleRefreshPeriod.setValue(String.valueOf(mAccount.getIdleRefreshMinutes()));
mIdleRefreshPeriod.setSummary(mIdleRefreshPeriod.getEntry());
- mIdleRefreshPeriod.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
- {
- public boolean onPreferenceChange(Preference preference, Object newValue)
- {
+ mIdleRefreshPeriod.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mIdleRefreshPeriod.findIndexOfValue(summary);
mIdleRefreshPeriod.setSummary(mIdleRefreshPeriod.getEntries()[index]);
@@ -548,10 +497,8 @@ public class AccountSettings extends K9PreferenceActivity
mMaxPushFolders.setValue(String.valueOf(mAccount.getMaxPushFolders()));
mMaxPushFolders.setSummary(mMaxPushFolders.getEntry());
- mMaxPushFolders.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
- {
- public boolean onPreferenceChange(Preference preference, Object newValue)
- {
+ mMaxPushFolders.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mMaxPushFolders.findIndexOfValue(summary);
mMaxPushFolders.setSummary(mMaxPushFolders.getEntries()[index]);
@@ -559,9 +506,7 @@ public class AccountSettings extends K9PreferenceActivity
return false;
}
});
- }
- else
- {
+ } else {
mPushPollOnConnect.setEnabled(false);
mMaxPushFolders.setEnabled(false);
mIdleRefreshPeriod.setEnabled(false);
@@ -590,10 +535,8 @@ public class AccountSettings extends K9PreferenceActivity
mAccountVibratePattern = (ListPreference) findPreference(PREFERENCE_VIBRATE_PATTERN);
mAccountVibratePattern.setValue(String.valueOf(mAccount.getNotificationSetting().getVibratePattern()));
mAccountVibratePattern.setSummary(mAccountVibratePattern.getEntry());
- mAccountVibratePattern.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
- {
- public boolean onPreferenceChange(Preference preference, Object newValue)
- {
+ mAccountVibratePattern.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mAccountVibratePattern.findIndexOfValue(summary);
mAccountVibratePattern.setSummary(mAccountVibratePattern.getEntries()[index]);
@@ -606,11 +549,9 @@ public class AccountSettings extends K9PreferenceActivity
mAccountVibrateTimes = (ListPreference) findPreference(PREFERENCE_VIBRATE_TIMES);
mAccountVibrateTimes.setValue(String.valueOf(mAccount.getNotificationSetting().getVibrateTimes()));
mAccountVibrateTimes.setSummary(String.valueOf(mAccount.getNotificationSetting().getVibrateTimes()));
- mAccountVibrateTimes.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
- {
+ mAccountVibrateTimes.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
- public boolean onPreferenceChange(Preference preference, Object newValue)
- {
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
final String value = newValue.toString();
mAccountVibrateTimes.setSummary(value);
mAccountVibrateTimes.setValue(value);
@@ -631,50 +572,40 @@ public class AccountSettings extends K9PreferenceActivity
new PopulateFolderPrefsTask().execute();
mChipColor = findPreference(PREFERENCE_CHIP_COLOR);
- mChipColor.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener()
- {
- public boolean onPreferenceClick(Preference preference)
- {
+ mChipColor.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
+ public boolean onPreferenceClick(Preference preference) {
onChooseChipColor();
return false;
}
});
mLedColor = findPreference(PREFERENCE_LED_COLOR);
- mLedColor.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener()
- {
- public boolean onPreferenceClick(Preference preference)
- {
+ mLedColor.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
+ public boolean onPreferenceClick(Preference preference) {
onChooseLedColor();
return false;
}
});
findPreference(PREFERENCE_COMPOSITION).setOnPreferenceClickListener(
- new Preference.OnPreferenceClickListener()
- {
- public boolean onPreferenceClick(Preference preference)
- {
+ new Preference.OnPreferenceClickListener() {
+ public boolean onPreferenceClick(Preference preference) {
onCompositionSettings();
return true;
}
});
findPreference(PREFERENCE_MANAGE_IDENTITIES).setOnPreferenceClickListener(
- new Preference.OnPreferenceClickListener()
- {
- public boolean onPreferenceClick(Preference preference)
- {
+ new Preference.OnPreferenceClickListener() {
+ public boolean onPreferenceClick(Preference preference) {
onManageIdentities();
return true;
}
});
findPreference(PREFERENCE_INCOMING).setOnPreferenceClickListener(
- new Preference.OnPreferenceClickListener()
- {
- public boolean onPreferenceClick(Preference preference)
- {
+ new Preference.OnPreferenceClickListener() {
+ public boolean onPreferenceClick(Preference preference) {
mIncomingChanged = true;
onIncomingSettings();
return true;
@@ -682,10 +613,8 @@ public class AccountSettings extends K9PreferenceActivity
});
findPreference(PREFERENCE_OUTGOING).setOnPreferenceClickListener(
- new Preference.OnPreferenceClickListener()
- {
- public boolean onPreferenceClick(Preference preference)
- {
+ new Preference.OnPreferenceClickListener() {
+ public boolean onPreferenceClick(Preference preference) {
onOutgoingSettings();
return true;
}
@@ -693,28 +622,23 @@ public class AccountSettings extends K9PreferenceActivity
mCryptoApp = (ListPreference) findPreference(PREFERENCE_CRYPTO_APP);
CharSequence cryptoAppEntries[] = mCryptoApp.getEntries();
- if (!new Apg().isAvailable(this))
- {
+ if (!new Apg().isAvailable(this)) {
int apgIndex = mCryptoApp.findIndexOfValue(Apg.NAME);
- if (apgIndex >= 0)
- {
+ if (apgIndex >= 0) {
cryptoAppEntries[apgIndex] = "APG (" + getResources().getString(R.string.account_settings_crypto_app_not_available) + ")";
mCryptoApp.setEntries(cryptoAppEntries);
}
}
mCryptoApp.setValue(String.valueOf(mAccount.getCryptoApp()));
mCryptoApp.setSummary(mCryptoApp.getEntry());
- mCryptoApp.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
- {
- public boolean onPreferenceChange(Preference preference, Object newValue)
- {
+ mCryptoApp.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
String value = newValue.toString();
int index = mCryptoApp.findIndexOfValue(value);
mCryptoApp.setSummary(mCryptoApp.getEntries()[index]);
mCryptoApp.setValue(value);
handleCryptoAppDependencies();
- if (Apg.NAME.equals(value))
- {
+ if (Apg.NAME.equals(value)) {
Apg.createInstance(null).test(AccountSettings.this);
}
return false;
@@ -727,28 +651,21 @@ public class AccountSettings extends K9PreferenceActivity
handleCryptoAppDependencies();
}
- private void handleCryptoAppDependencies()
- {
- if ("".equals(mCryptoApp.getValue()))
- {
+ private void handleCryptoAppDependencies() {
+ if ("".equals(mCryptoApp.getValue())) {
mCryptoAutoSignature.setEnabled(false);
- }
- else
- {
+ } else {
mCryptoAutoSignature.setEnabled(true);
}
}
@Override
- public void onResume()
- {
+ public void onResume() {
super.onResume();
}
- private void saveSettings()
- {
- if (mAccountDefault.isChecked())
- {
+ private void saveSettings() {
+ if (mAccountDefault.isChecked()) {
Preferences.getPreferences(this).setDefaultAccount(mAccount);
}
@@ -788,8 +705,7 @@ public class AccountSettings extends K9PreferenceActivity
mAccount.setTrashFolderName(mTrashFolder.getValue());
- if (mIsPushCapable)
- {
+ if (mIsPushCapable) {
mAccount.setPushPollOnConnect(mPushPollOnConnect.isChecked());
mAccount.setIdleRefreshMinutes(Integer.parseInt(mIdleRefreshPeriod.getValue()));
mAccount.setMaxPushFolders(Integer.parseInt(mMaxPushFolders.getValue()));
@@ -801,23 +717,18 @@ public class AccountSettings extends K9PreferenceActivity
boolean needsPushRestart = mAccount.setFolderPushMode(Account.FolderMode.valueOf(mPushMode.getValue()));
boolean displayModeChanged = mAccount.setFolderDisplayMode(Account.FolderMode.valueOf(mDisplayMode.getValue()));
- if (mAccount.getFolderPushMode() != FolderMode.NONE)
- {
+ if (mAccount.getFolderPushMode() != FolderMode.NONE) {
needsPushRestart |= displayModeChanged;
needsPushRestart |= mIncomingChanged;
}
SharedPreferences prefs = mAccountRingtone.getPreferenceManager().getSharedPreferences();
String newRingtone = prefs.getString(PREFERENCE_RINGTONE, null);
- if (newRingtone != null)
- {
+ if (newRingtone != null) {
mAccount.getNotificationSetting().setRing(true);
mAccount.getNotificationSetting().setRingtone(newRingtone);
- }
- else
- {
- if (mAccount.getNotificationSetting().shouldRing())
- {
+ } else {
+ if (mAccount.getNotificationSetting().shouldRing()) {
mAccount.getNotificationSetting().setRingtone(null);
}
}
@@ -828,94 +739,73 @@ public class AccountSettings extends K9PreferenceActivity
mAccount.setEnableMoveButtons(mAccountEnableMoveButtons.isChecked());
mAccount.save(Preferences.getPreferences(this));
- if (needsRefresh && needsPushRestart)
- {
+ if (needsRefresh && needsPushRestart) {
MailService.actionReset(this, null);
- }
- else if (needsRefresh)
- {
+ } else if (needsRefresh) {
MailService.actionReschedulePoll(this, null);
- }
- else if (needsPushRestart)
- {
+ } else if (needsPushRestart) {
MailService.actionRestartPushers(this, null);
}
// TODO: refresh folder list here
}
@Override
- public void onActivityResult(int requestCode, int resultCode, Intent data)
- {
- if (resultCode == RESULT_OK)
- {
- switch (requestCode)
- {
- case SELECT_AUTO_EXPAND_FOLDER:
- mAutoExpandFolder.setSummary(translateFolder(data.getStringExtra(ChooseFolder.EXTRA_NEW_FOLDER)));
- break;
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (resultCode == RESULT_OK) {
+ switch (requestCode) {
+ case SELECT_AUTO_EXPAND_FOLDER:
+ mAutoExpandFolder.setSummary(translateFolder(data.getStringExtra(ChooseFolder.EXTRA_NEW_FOLDER)));
+ break;
}
}
super.onActivityResult(requestCode, resultCode, data);
}
@Override
- public boolean onKeyDown(int keyCode, KeyEvent event)
- {
- if (keyCode == KeyEvent.KEYCODE_BACK)
- {
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ if (keyCode == KeyEvent.KEYCODE_BACK) {
saveSettings();
}
return super.onKeyDown(keyCode, event);
}
- private void onCompositionSettings()
- {
+ private void onCompositionSettings() {
AccountSetupComposition.actionEditCompositionSettings(this, mAccount);
}
- private void onManageIdentities()
- {
+ private void onManageIdentities() {
Intent intent = new Intent(this, ManageIdentities.class);
intent.putExtra(ChooseIdentity.EXTRA_ACCOUNT, mAccount.getUuid());
startActivityForResult(intent, ACTIVITY_MANAGE_IDENTITIES);
}
- private void onIncomingSettings()
- {
+ private void onIncomingSettings() {
AccountSetupIncoming.actionEditIncomingSettings(this, mAccount);
}
- private void onOutgoingSettings()
- {
+ private void onOutgoingSettings() {
AccountSetupOutgoing.actionEditOutgoingSettings(this, mAccount);
}
- public void onChooseChipColor()
- {
- new ColorPickerDialog(this, new ColorPickerDialog.OnColorChangedListener()
- {
- public void colorChanged(int color)
- {
+ public void onChooseChipColor() {
+ new ColorPickerDialog(this, new ColorPickerDialog.OnColorChangedListener() {
+ public void colorChanged(int color) {
mAccount.setChipColor(color);
}
},
mAccount.getChipColor()).show();
}
- public void onChooseLedColor()
- {
- new ColorPickerDialog(this, new ColorPickerDialog.OnColorChangedListener()
- {
- public void colorChanged(int color)
- {
+ public void onChooseLedColor() {
+ new ColorPickerDialog(this, new ColorPickerDialog.OnColorChangedListener() {
+ public void colorChanged(int color) {
mAccount.getNotificationSetting().setLedColor(color);
}
},
mAccount.getNotificationSetting().getLedColor()).show();
}
- public void onChooseAutoExpandFolder()
- {
+ public void onChooseAutoExpandFolder() {
Intent selectIntent = new Intent(this, ChooseFolder.class);
selectIntent.putExtra(ChooseFolder.EXTRA_ACCOUNT, mAccount.getUuid());
@@ -926,32 +816,23 @@ public class AccountSettings extends K9PreferenceActivity
startActivityForResult(selectIntent, SELECT_AUTO_EXPAND_FOLDER);
}
- private String translateFolder(String in)
- {
- if (K9.INBOX.equalsIgnoreCase(in))
- {
+ private String translateFolder(String in) {
+ if (K9.INBOX.equalsIgnoreCase(in)) {
return getString(R.string.special_mailbox_name_inbox);
- }
- else
- {
+ } else {
return in;
}
}
- private String reverseTranslateFolder(String in)
- {
- if (getString(R.string.special_mailbox_name_inbox).equals(in))
- {
+ private String reverseTranslateFolder(String in) {
+ if (getString(R.string.special_mailbox_name_inbox).equals(in)) {
return K9.INBOX;
- }
- else
- {
+ } else {
return in;
}
}
- private void doVibrateTest(Preference preference)
- {
+ private void doVibrateTest(Preference preference) {
// Do the vibration to show the user what it's like.
Vibrator vibrate = (Vibrator)preference.getContext().getSystemService(Context.VIBRATOR_SERVICE);
vibrate.vibrate(NotificationSetting.getVibration(
@@ -959,21 +840,16 @@ public class AccountSettings extends K9PreferenceActivity
Integer.parseInt(mAccountVibrateTimes.getValue())), -1);
}
- private class PopulateFolderPrefsTask extends AsyncTask
- {
- List extends Folder> folders = new LinkedList();
+ private class PopulateFolderPrefsTask extends AsyncTask {
+ List extends Folder > folders = new LinkedList();
String[] allFolderValues;
String[] allFolderLabels;
@Override
- protected Void doInBackground(Void... params)
- {
- try
- {
+ protected Void doInBackground(Void... params) {
+ try {
folders = mAccount.getLocalStore().getPersonalNamespaces(false);
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
/// this can't be checked in
}
allFolderValues = new String[folders.size()+2];
@@ -987,9 +863,8 @@ public class AccountSettings extends K9PreferenceActivity
allFolderLabels[1] = mAccount.getOutboxFolderName();
- int i =2;
- for (Folder folder : folders)
- {
+ int i = 2;
+ for (Folder folder : folders) {
allFolderLabels[i] = folder.getName();
allFolderValues[i] = folder.getName();
i++;
@@ -998,8 +873,7 @@ public class AccountSettings extends K9PreferenceActivity
}
@Override
- protected void onPreExecute()
- {
+ protected void onPreExecute() {
mAutoExpandFolder = (ListPreference)findPreference(PREFERENCE_AUTO_EXPAND_FOLDER);
mAutoExpandFolder.setEnabled(false);
mArchiveFolder = (ListPreference)findPreference(PREFERENCE_ARCHIVE_FOLDER);
@@ -1018,15 +892,14 @@ public class AccountSettings extends K9PreferenceActivity
}
@Override
- protected void onPostExecute(Void res)
- {
- initListPreference(mAutoExpandFolder, mAccount.getAutoExpandFolderName(), allFolderLabels,allFolderValues);
- initListPreference(mArchiveFolder, mAccount.getArchiveFolderName(), allFolderLabels,allFolderValues);
- initListPreference(mDraftsFolder, mAccount.getDraftsFolderName(), allFolderLabels,allFolderValues);
- initListPreference(mOutboxFolder, mAccount.getOutboxFolderName(), allFolderLabels,allFolderValues);
- initListPreference(mSentFolder, mAccount.getSentFolderName(), allFolderLabels,allFolderValues);
- initListPreference(mSpamFolder, mAccount.getSpamFolderName(), allFolderLabels,allFolderValues);
- initListPreference(mTrashFolder, mAccount.getTrashFolderName(), allFolderLabels,allFolderValues);
+ protected void onPostExecute(Void res) {
+ initListPreference(mAutoExpandFolder, mAccount.getAutoExpandFolderName(), allFolderLabels, allFolderValues);
+ initListPreference(mArchiveFolder, mAccount.getArchiveFolderName(), allFolderLabels, allFolderValues);
+ initListPreference(mDraftsFolder, mAccount.getDraftsFolderName(), allFolderLabels, allFolderValues);
+ initListPreference(mOutboxFolder, mAccount.getOutboxFolderName(), allFolderLabels, allFolderValues);
+ initListPreference(mSentFolder, mAccount.getSentFolderName(), allFolderLabels, allFolderValues);
+ initListPreference(mSpamFolder, mAccount.getSpamFolderName(), allFolderLabels, allFolderValues);
+ initListPreference(mTrashFolder, mAccount.getTrashFolderName(), allFolderLabels, allFolderValues);
mAutoExpandFolder.setEnabled(true);
mArchiveFolder.setEnabled(true);
mDraftsFolder.setEnabled(true);
diff --git a/src/com/fsck/k9/activity/setup/AccountSetupAccountType.java b/src/com/fsck/k9/activity/setup/AccountSetupAccountType.java
index 13dc1e9e0..f4a7f34cb 100644
--- a/src/com/fsck/k9/activity/setup/AccountSetupAccountType.java
+++ b/src/com/fsck/k9/activity/setup/AccountSetupAccountType.java
@@ -21,8 +21,7 @@ import java.net.URI;
* passed in email address, password and makeDefault are then passed on to the
* AccountSetupIncoming activity.
*/
-public class AccountSetupAccountType extends K9Activity implements OnClickListener
-{
+public class AccountSetupAccountType extends K9Activity implements OnClickListener {
private static final String EXTRA_ACCOUNT = "account";
private static final String EXTRA_MAKE_DEFAULT = "makeDefault";
@@ -31,8 +30,7 @@ public class AccountSetupAccountType extends K9Activity implements OnClickListen
private boolean mMakeDefault;
- public static void actionSelectAccountType(Context context, Account account, boolean makeDefault)
- {
+ public static void actionSelectAccountType(Context context, Account account, boolean makeDefault) {
Intent i = new Intent(context, AccountSetupAccountType.class);
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
i.putExtra(EXTRA_MAKE_DEFAULT, makeDefault);
@@ -40,8 +38,7 @@ public class AccountSetupAccountType extends K9Activity implements OnClickListen
}
@Override
- public void onCreate(Bundle savedInstanceState)
- {
+ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.account_setup_account_type);
((Button)findViewById(R.id.pop)).setOnClickListener(this);
@@ -53,74 +50,59 @@ public class AccountSetupAccountType extends K9Activity implements OnClickListen
mMakeDefault = getIntent().getBooleanExtra(EXTRA_MAKE_DEFAULT, false);
}
- private void onPop()
- {
- try
- {
+ private void onPop() {
+ try {
URI uri = new URI(mAccount.getStoreUri());
uri = new URI("pop3", uri.getUserInfo(), uri.getHost(), uri.getPort(), null, null, null);
mAccount.setStoreUri(uri.toString());
AccountSetupIncoming.actionIncomingSettings(this, mAccount, mMakeDefault);
finish();
- }
- catch (Exception use)
- {
+ } catch (Exception use) {
failure(use);
}
}
- private void onImap()
- {
- try
- {
+ private void onImap() {
+ try {
URI uri = new URI(mAccount.getStoreUri());
uri = new URI("imap", uri.getUserInfo(), uri.getHost(), uri.getPort(), null, null, null);
mAccount.setStoreUri(uri.toString());
AccountSetupIncoming.actionIncomingSettings(this, mAccount, mMakeDefault);
finish();
- }
- catch (Exception use)
- {
+ } catch (Exception use) {
failure(use);
}
}
- private void onWebDav()
- {
- try
- {
+ private void onWebDav() {
+ try {
URI uri = new URI(mAccount.getStoreUri());
uri = new URI("webdav", uri.getUserInfo(), uri.getHost(), uri.getPort(), null, null, null);
mAccount.setStoreUri(uri.toString());
AccountSetupIncoming.actionIncomingSettings(this, mAccount, mMakeDefault);
finish();
- }
- catch (Exception use)
- {
+ } catch (Exception use) {
failure(use);
}
}
- public void onClick(View v)
- {
- switch (v.getId())
- {
- case R.id.pop:
- onPop();
- break;
- case R.id.imap:
- onImap();
- break;
- case R.id.webdav:
- onWebDav();
- break;
+ public void onClick(View v) {
+ switch (v.getId()) {
+ case R.id.pop:
+ onPop();
+ break;
+ case R.id.imap:
+ onImap();
+ break;
+ case R.id.webdav:
+ onWebDav();
+ break;
}
}
- private void failure(Exception use)
- {
+ private void failure(Exception use) {
Log.e(K9.LOG_TAG, "Failure", use);
String toastText = getString(R.string.account_setup_bad_uri, use.getMessage());
diff --git a/src/com/fsck/k9/activity/setup/AccountSetupBasics.java b/src/com/fsck/k9/activity/setup/AccountSetupBasics.java
index 2df9c811a..aff63ee2d 100644
--- a/src/com/fsck/k9/activity/setup/AccountSetupBasics.java
+++ b/src/com/fsck/k9/activity/setup/AccountSetupBasics.java
@@ -35,8 +35,7 @@ import java.net.URLEncoder;
* AccountSetupAccountType activity.
*/
public class AccountSetupBasics extends K9Activity
- implements OnClickListener, TextWatcher
-{
+ implements OnClickListener, TextWatcher {
private final static String EXTRA_ACCOUNT = "com.fsck.k9.AccountSetupBasics.account";
private final static int DIALOG_NOTE = 1;
private final static String STATE_KEY_PROVIDER =
@@ -53,15 +52,13 @@ public class AccountSetupBasics extends K9Activity
private EmailAddressValidator mEmailValidator = new EmailAddressValidator();
- public static void actionNewAccount(Context context)
- {
+ public static void actionNewAccount(Context context) {
Intent i = new Intent(context, AccountSetupBasics.class);
context.startActivity(i);
}
@Override
- public void onCreate(Bundle savedInstanceState)
- {
+ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.account_setup_basics);
mPrefs = Preferences.getPreferences(this);
@@ -77,59 +74,48 @@ public class AccountSetupBasics extends K9Activity
mEmailView.addTextChangedListener(this);
mPasswordView.addTextChangedListener(this);
- if (mPrefs.getAccounts().length > 0)
- {
+ if (mPrefs.getAccounts().length > 0) {
mDefaultView.setVisibility(View.VISIBLE);
}
- if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_ACCOUNT))
- {
+ if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_ACCOUNT)) {
String accountUuid = savedInstanceState.getString(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
}
- if (savedInstanceState != null && savedInstanceState.containsKey(STATE_KEY_PROVIDER))
- {
+ if (savedInstanceState != null && savedInstanceState.containsKey(STATE_KEY_PROVIDER)) {
mProvider = (Provider)savedInstanceState.getSerializable(STATE_KEY_PROVIDER);
}
}
@Override
- public void onResume()
- {
+ public void onResume() {
super.onResume();
validateFields();
}
@Override
- public void onSaveInstanceState(Bundle outState)
- {
+ public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
- if (mAccount != null)
- {
+ if (mAccount != null) {
outState.putString(EXTRA_ACCOUNT, mAccount.getUuid());
}
- if (mProvider != null)
- {
+ if (mProvider != null) {
outState.putSerializable(STATE_KEY_PROVIDER, mProvider);
}
}
- public void afterTextChanged(Editable s)
- {
+ public void afterTextChanged(Editable s) {
validateFields();
}
- public void beforeTextChanged(CharSequence s, int start, int count, int after)
- {
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
- public void onTextChanged(CharSequence s, int start, int before, int count)
- {
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
}
- private void validateFields()
- {
+ private void validateFields() {
String email = mEmailView.getText().toString();
boolean valid = Utility.requiredFieldValid(mEmailView)
&& Utility.requiredFieldValid(mPasswordView)
@@ -145,61 +131,45 @@ public class AccountSetupBasics extends K9Activity
Utility.setCompoundDrawablesAlpha(mNextButton, mNextButton.isEnabled() ? 255 : 128);
}
- private String getOwnerName()
- {
+ private String getOwnerName() {
String name = null;
- try
- {
+ try {
name = Contacts.getInstance(this).getOwnerName();
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
Log.e(K9.LOG_TAG, "Could not get owner name, using default account name", e);
}
- if (name == null || name.length() == 0)
- {
- try
- {
+ if (name == null || name.length() == 0) {
+ try {
name = getDefaultAccountName();
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
Log.e(K9.LOG_TAG, "Could not get default account name", e);
}
}
- if (name == null)
- {
+ if (name == null) {
name = "";
}
return name;
}
- private String getDefaultAccountName()
- {
+ private String getDefaultAccountName() {
String name = null;
Account account = Preferences.getPreferences(this).getDefaultAccount();
- if (account != null)
- {
+ if (account != null) {
name = account.getName();
}
return name;
}
@Override
- public Dialog onCreateDialog(int id)
- {
- if (id == DIALOG_NOTE)
- {
- if (mProvider != null && mProvider.note != null)
- {
+ public Dialog onCreateDialog(int id) {
+ if (id == DIALOG_NOTE) {
+ if (mProvider != null && mProvider.note != null) {
return new AlertDialog.Builder(this)
.setMessage(mProvider.note)
.setPositiveButton(
getString(R.string.okay_action),
- new DialogInterface.OnClickListener()
- {
- public void onClick(DialogInterface dialog, int which)
- {
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
finishAutoSetup();
}
})
@@ -212,8 +182,7 @@ public class AccountSetupBasics extends K9Activity
return null;
}
- private void finishAutoSetup()
- {
+ private void finishAutoSetup() {
String email = mEmailView.getText().toString();
String password = mPasswordView.getText().toString();
String[] emailParts = splitEmail(email);
@@ -221,8 +190,7 @@ public class AccountSetupBasics extends K9Activity
String domain = emailParts[1];
URI incomingUri = null;
URI outgoingUri = null;
- try
- {
+ try {
String userEnc = URLEncoder.encode(user, "UTF-8");
String passwordEnc = URLEncoder.encode(password, "UTF-8");
@@ -258,14 +226,10 @@ public class AccountSetupBasics extends K9Activity
mAccount.setOutboxFolderName(getString(R.string.special_mailbox_name_outbox));
mAccount.setSentFolderName(getString(R.string.special_mailbox_name_sent));
AccountSetupCheckSettings.actionCheckSettings(this, mAccount, true, true);
- }
- catch (UnsupportedEncodingException enc)
- {
+ } catch (UnsupportedEncodingException enc) {
// This really shouldn't happen since the encoding is hardcoded to UTF-8
Log.e(K9.LOG_TAG, "Couldn't urlencode username or password.", enc);
- }
- catch (URISyntaxException use)
- {
+ } catch (URISyntaxException use) {
/*
* If there is some problem with the URI we give up and go on to
* manual setup.
@@ -275,14 +239,12 @@ public class AccountSetupBasics extends K9Activity
}
@Override
- protected void onNext()
- {
+ protected void onNext() {
String email = mEmailView.getText().toString();
String[] emailParts = splitEmail(email);
String domain = emailParts[1];
mProvider = findProviderForDomain(domain);
- if (mProvider == null)
- {
+ if (mProvider == null) {
/*
* We don't have default settings for this account, start the manual
* setup process.
@@ -291,25 +253,19 @@ public class AccountSetupBasics extends K9Activity
return;
}
- if (mProvider.note != null)
- {
+ if (mProvider.note != null) {
showDialog(DIALOG_NOTE);
- }
- else
- {
+ } else {
finishAutoSetup();
}
}
@Override
- public void onActivityResult(int requestCode, int resultCode, Intent data)
- {
- if (resultCode == RESULT_OK)
- {
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (resultCode == RESULT_OK) {
mAccount.setDescription(mAccount.getEmail());
mAccount.save(Preferences.getPreferences(this));
- if (mDefaultView.isChecked())
- {
+ if (mDefaultView.isChecked()) {
Preferences.getPreferences(this).setDefaultAccount(mAccount);
}
K9.setServicesEnabled(this);
@@ -318,8 +274,7 @@ public class AccountSetupBasics extends K9Activity
}
}
- private void onManualSetup()
- {
+ private void onManualSetup() {
String email = mEmailView.getText().toString();
String password = mPasswordView.getText().toString();
String[] emailParts = splitEmail(email);
@@ -329,8 +284,7 @@ public class AccountSetupBasics extends K9Activity
mAccount = Preferences.getPreferences(this).newAccount();
mAccount.setName(getOwnerName());
mAccount.setEmail(email);
- try
- {
+ try {
String userEnc = URLEncoder.encode(user, "UTF-8");
String passwordEnc = URLEncoder.encode(password, "UTF-8");
@@ -338,14 +292,10 @@ public class AccountSetupBasics extends K9Activity
null, null);
mAccount.setStoreUri(uri.toString());
mAccount.setTransportUri(uri.toString());
- }
- catch (UnsupportedEncodingException enc)
- {
+ } catch (UnsupportedEncodingException enc) {
// This really shouldn't happen since the encoding is hardcoded to UTF-8
Log.e(K9.LOG_TAG, "Couldn't urlencode username or password.", enc);
- }
- catch (URISyntaxException use)
- {
+ } catch (URISyntaxException use) {
/*
* If we can't set up the URL we just continue. It's only for
* convenience.
@@ -360,16 +310,14 @@ public class AccountSetupBasics extends K9Activity
finish();
}
- public void onClick(View v)
- {
- switch (v.getId())
- {
- case R.id.next:
- onNext();
- break;
- case R.id.manual_setup:
- onManualSetup();
- break;
+ public void onClick(View v) {
+ switch (v.getId()) {
+ case R.id.next:
+ onNext();
+ break;
+ case R.id.manual_setup:
+ onManualSetup();
+ break;
}
}
@@ -380,69 +328,52 @@ public class AccountSetupBasics extends K9Activity
* @param name
* @return
*/
- private String getXmlAttribute(XmlResourceParser xml, String name)
- {
+ private String getXmlAttribute(XmlResourceParser xml, String name) {
int resId = xml.getAttributeResourceValue(null, name, 0);
- if (resId == 0)
- {
+ if (resId == 0) {
return xml.getAttributeValue(null, name);
- }
- else
- {
+ } else {
return getString(resId);
}
}
- private Provider findProviderForDomain(String domain)
- {
- try
- {
+ private Provider findProviderForDomain(String domain) {
+ try {
XmlResourceParser xml = getResources().getXml(R.xml.providers);
int xmlEventType;
Provider provider = null;
- while ((xmlEventType = xml.next()) != XmlResourceParser.END_DOCUMENT)
- {
+ while ((xmlEventType = xml.next()) != XmlResourceParser.END_DOCUMENT) {
if (xmlEventType == XmlResourceParser.START_TAG
&& "provider".equals(xml.getName())
- && domain.equalsIgnoreCase(getXmlAttribute(xml, "domain")))
- {
+ && domain.equalsIgnoreCase(getXmlAttribute(xml, "domain"))) {
provider = new Provider();
provider.id = getXmlAttribute(xml, "id");
provider.label = getXmlAttribute(xml, "label");
provider.domain = getXmlAttribute(xml, "domain");
provider.note = getXmlAttribute(xml, "note");
- }
- else if (xmlEventType == XmlResourceParser.START_TAG
- && "incoming".equals(xml.getName())
- && provider != null)
- {
+ } else if (xmlEventType == XmlResourceParser.START_TAG
+ && "incoming".equals(xml.getName())
+ && provider != null) {
provider.incomingUriTemplate = new URI(getXmlAttribute(xml, "uri"));
provider.incomingUsernameTemplate = getXmlAttribute(xml, "username");
- }
- else if (xmlEventType == XmlResourceParser.START_TAG
- && "outgoing".equals(xml.getName())
- && provider != null)
- {
+ } else if (xmlEventType == XmlResourceParser.START_TAG
+ && "outgoing".equals(xml.getName())
+ && provider != null) {
provider.outgoingUriTemplate = new URI(getXmlAttribute(xml, "uri"));
provider.outgoingUsernameTemplate = getXmlAttribute(xml, "username");
- }
- else if (xmlEventType == XmlResourceParser.END_TAG
- && "provider".equals(xml.getName())
- && provider != null)
- {
+ } else if (xmlEventType == XmlResourceParser.END_TAG
+ && "provider".equals(xml.getName())
+ && provider != null) {
return provider;
}
}
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
Log.e(K9.LOG_TAG, "Error while trying to load provider settings.", e);
}
return null;
}
- private String[] splitEmail(String email)
- {
+ private String[] splitEmail(String email) {
String[] retParts = new String[2];
String[] emailParts = email.split("@");
retParts[0] = (emailParts.length > 0) ? emailParts[0] : "";
@@ -450,8 +381,7 @@ public class AccountSetupBasics extends K9Activity
return retParts;
}
- static class Provider implements Serializable
- {
+ static class Provider implements Serializable {
private static final long serialVersionUID = 8511656164616538989L;
public String id;
diff --git a/src/com/fsck/k9/activity/setup/AccountSetupCheckSettings.java b/src/com/fsck/k9/activity/setup/AccountSetupCheckSettings.java
index 35015a1b0..facae58e2 100644
--- a/src/com/fsck/k9/activity/setup/AccountSetupCheckSettings.java
+++ b/src/com/fsck/k9/activity/setup/AccountSetupCheckSettings.java
@@ -34,8 +34,7 @@ import java.security.cert.X509Certificate;
* XXX NOTE: The manifest for this app has it ignore config changes, because
* it doesn't correctly deal with restarting while its thread is running.
*/
-public class AccountSetupCheckSettings extends K9Activity implements OnClickListener
-{
+public class AccountSetupCheckSettings extends K9Activity implements OnClickListener {
public static final int ACTIVITY_REQUEST_CODE = 1;
@@ -62,8 +61,7 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList
private boolean mDestroyed;
public static void actionCheckSettings(Activity context, Account account,
- boolean checkIncoming, boolean checkOutgoing)
- {
+ boolean checkIncoming, boolean checkOutgoing) {
Intent i = new Intent(context, AccountSetupCheckSettings.class);
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
i.putExtra(EXTRA_CHECK_INCOMING, checkIncoming);
@@ -72,8 +70,7 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList
}
@Override
- public void onCreate(Bundle savedInstanceState)
- {
+ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.account_setup_check_settings);
mMessageView = (TextView)findViewById(R.id.message);
@@ -88,58 +85,44 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList
mCheckIncoming = getIntent().getBooleanExtra(EXTRA_CHECK_INCOMING, false);
mCheckOutgoing = getIntent().getBooleanExtra(EXTRA_CHECK_OUTGOING, false);
- new Thread()
- {
+ new Thread() {
@Override
- public void run()
- {
+ public void run() {
Store store = null;
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
- try
- {
- if (mDestroyed)
- {
+ try {
+ if (mDestroyed) {
return;
}
- if (mCanceled)
- {
+ if (mCanceled) {
finish();
return;
}
- if (mCheckIncoming)
- {
+ if (mCheckIncoming) {
store = mAccount.getRemoteStore();
- if (store instanceof WebDavStore)
- {
+ if (store instanceof WebDavStore) {
setMessage(R.string.account_setup_check_settings_authenticate);
- }
- else
- {
+ } else {
setMessage(R.string.account_setup_check_settings_check_incoming_msg);
}
store.checkSettings();
- if (store instanceof WebDavStore)
- {
+ if (store instanceof WebDavStore) {
setMessage(R.string.account_setup_check_settings_fetch);
}
MessagingController.getInstance(getApplication()).listFoldersSynchronous(mAccount, true, null);
MessagingController.getInstance(getApplication()).synchronizeMailbox(mAccount, K9.INBOX , null, null);
}
- if (mDestroyed)
- {
+ if (mDestroyed) {
return;
}
- if (mCanceled)
- {
+ if (mCanceled) {
finish();
return;
}
- if (mCheckOutgoing)
- {
- if (!(mAccount.getRemoteStore() instanceof WebDavStore))
- {
+ if (mCheckOutgoing) {
+ if (!(mAccount.getRemoteStore() instanceof WebDavStore)) {
setMessage(R.string.account_setup_check_settings_check_outgoing_msg);
}
Transport transport = Transport.getInstance(mAccount);
@@ -147,34 +130,26 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList
transport.open();
transport.close();
}
- if (mDestroyed)
- {
+ if (mDestroyed) {
return;
}
- if (mCanceled)
- {
+ if (mCanceled) {
finish();
return;
}
setResult(RESULT_OK);
finish();
- }
- catch (final AuthenticationFailedException afe)
- {
+ } catch (final AuthenticationFailedException afe) {
Log.e(K9.LOG_TAG, "Error while testing settings", afe);
showErrorDialog(
R.string.account_setup_failed_dlg_auth_message_fmt,
afe.getMessage() == null ? "" : afe.getMessage());
- }
- catch (final CertificateValidationException cve)
- {
+ } catch (final CertificateValidationException cve) {
Log.e(K9.LOG_TAG, "Error while testing settings", cve);
acceptKeyDialog(
R.string.account_setup_failed_dlg_certificate_message_fmt,
cve);
- }
- catch (final Throwable t)
- {
+ } catch (final Throwable t) {
Log.e(K9.LOG_TAG, "Error while testing settings", t);
showErrorDialog(
R.string.account_setup_failed_dlg_server_message_fmt,
@@ -188,21 +163,16 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList
}
@Override
- public void onDestroy()
- {
+ public void onDestroy() {
super.onDestroy();
mDestroyed = true;
mCanceled = true;
}
- private void setMessage(final int resId)
- {
- mHandler.post(new Runnable()
- {
- public void run()
- {
- if (mDestroyed)
- {
+ private void setMessage(final int resId) {
+ mHandler.post(new Runnable() {
+ public void run() {
+ if (mDestroyed) {
return;
}
mMessageView.setText(getString(resId));
@@ -210,14 +180,10 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList
});
}
- private void showErrorDialog(final int msgResId, final Object... args)
- {
- mHandler.post(new Runnable()
- {
- public void run()
- {
- if (mDestroyed)
- {
+ private void showErrorDialog(final int msgResId, final Object... args) {
+ mHandler.post(new Runnable() {
+ public void run() {
+ if (mDestroyed) {
return;
}
mProgressBar.setIndeterminate(false);
@@ -228,21 +194,17 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList
.setNegativeButton(
getString(R.string.account_setup_failed_dlg_continue_action),
- new DialogInterface.OnClickListener()
- {
- public void onClick(DialogInterface dialog, int which)
- {
- mCanceled=false;
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ mCanceled = false;
setResult(RESULT_OK);
finish();
}
})
.setPositiveButton(
getString(R.string.account_setup_failed_dlg_edit_details_action),
- new DialogInterface.OnClickListener()
- {
- public void onClick(DialogInterface dialog, int which)
- {
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
finish();
}
})
@@ -250,44 +212,32 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList
}
});
}
- private void acceptKeyDialog(final int msgResId, final Object... args)
- {
- mHandler.post(new Runnable()
- {
- public void run()
- {
- if (mDestroyed)
- {
+ private void acceptKeyDialog(final int msgResId, final Object... args) {
+ mHandler.post(new Runnable() {
+ public void run() {
+ if (mDestroyed) {
return;
}
final X509Certificate[] chain = TrustManagerFactory.getLastCertChain();
String exMessage = "Unknown Error";
Exception ex = ((Exception)args[0]);
- if (ex != null)
- {
- if (ex.getCause() != null)
- {
- if (ex.getCause().getCause() != null)
- {
+ if (ex != null) {
+ if (ex.getCause() != null) {
+ if (ex.getCause().getCause() != null) {
exMessage = ex.getCause().getCause().getMessage();
- }
- else
- {
+ } else {
exMessage = ex.getCause().getMessage();
}
- }
- else
- {
+ } else {
exMessage = ex.getMessage();
}
}
mProgressBar.setIndeterminate(false);
StringBuffer chainInfo = new StringBuffer(100);
- for (int i = 0; i < chain.length; i++)
- {
+ for (int i = 0; i < chain.length; i++) {
// display certificate chain information
chainInfo.append("Certificate chain[" + i + "]:\n");
chainInfo.append("Subject: " + chain[i].getSubjectDN().toString() + "\n");
@@ -297,31 +247,24 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList
new AlertDialog.Builder(AccountSetupCheckSettings.this)
.setTitle(getString(R.string.account_setup_failed_dlg_invalid_certificate_title))
//.setMessage(getString(R.string.account_setup_failed_dlg_invalid_certificate)
- .setMessage(getString(msgResId,exMessage)
+ .setMessage(getString(msgResId, exMessage)
+ " " + chainInfo.toString()
)
.setCancelable(true)
.setPositiveButton(
getString(R.string.account_setup_failed_dlg_invalid_certificate_accept),
- new DialogInterface.OnClickListener()
- {
- public void onClick(DialogInterface dialog, int which)
- {
- try
- {
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ try {
String alias = mAccount.getUuid();
- if (mCheckIncoming)
- {
+ if (mCheckIncoming) {
alias = alias + ".incoming";
}
- if (mCheckOutgoing)
- {
+ if (mCheckOutgoing) {
alias = alias + ".outgoing";
}
TrustManagerFactory.addCertificateChain(alias, chain);
- }
- catch (CertificateException e)
- {
+ } catch (CertificateException e) {
showErrorDialog(
R.string.account_setup_failed_dlg_certificate_message_fmt,
e.getMessage() == null ? "" : e.getMessage());
@@ -332,10 +275,8 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList
})
.setNegativeButton(
getString(R.string.account_setup_failed_dlg_invalid_certificate_reject),
- new DialogInterface.OnClickListener()
- {
- public void onClick(DialogInterface dialog, int which)
- {
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
finish();
}
})
@@ -345,26 +286,22 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList
}
@Override
- public void onActivityResult(int reqCode, int resCode, Intent data)
- {
+ public void onActivityResult(int reqCode, int resCode, Intent data) {
setResult(resCode);
finish();
}
- private void onCancel()
- {
+ private void onCancel() {
mCanceled = true;
setMessage(R.string.account_setup_check_settings_canceling_msg);
}
- public void onClick(View v)
- {
- switch (v.getId())
- {
- case R.id.cancel:
- onCancel();
- break;
+ public void onClick(View v) {
+ switch (v.getId()) {
+ case R.id.cancel:
+ onCancel();
+ break;
}
}
}
diff --git a/src/com/fsck/k9/activity/setup/AccountSetupComposition.java b/src/com/fsck/k9/activity/setup/AccountSetupComposition.java
index 933e35999..f0bed3220 100644
--- a/src/com/fsck/k9/activity/setup/AccountSetupComposition.java
+++ b/src/com/fsck/k9/activity/setup/AccountSetupComposition.java
@@ -15,8 +15,7 @@ import com.fsck.k9.Preferences;
import com.fsck.k9.R;
import com.fsck.k9.activity.K9Activity;
-public class AccountSetupComposition extends K9Activity
-{
+public class AccountSetupComposition extends K9Activity {
private static final String EXTRA_ACCOUNT = "account";
@@ -31,8 +30,7 @@ public class AccountSetupComposition extends K9Activity
private RadioButton mAccountSignatureAfterLocation;
private LinearLayout mAccountSignatureLayout;
- public static void actionEditCompositionSettings(Activity context, Account account)
- {
+ public static void actionEditCompositionSettings(Activity context, Account account) {
Intent i = new Intent(context, AccountSetupComposition.class);
i.setAction(Intent.ACTION_EDIT);
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
@@ -41,8 +39,7 @@ public class AccountSetupComposition extends K9Activity
@Override
- public void onCreate(Bundle savedInstanceState)
- {
+ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
@@ -54,8 +51,7 @@ public class AccountSetupComposition extends K9Activity
* If we're being reloaded we override the original account with the one
* we saved
*/
- if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_ACCOUNT))
- {
+ if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_ACCOUNT)) {
accountUuid = savedInstanceState.getString(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
}
@@ -74,20 +70,15 @@ public class AccountSetupComposition extends K9Activity
mAccountSignatureUse = (CheckBox)findViewById(R.id.account_signature_use);
boolean useSignature = mAccount.getSignatureUse();
mAccountSignatureUse.setChecked(useSignature);
- mAccountSignatureUse.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
- {
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
- {
- if (isChecked)
- {
+ mAccountSignatureUse.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+ if (isChecked) {
mAccountSignatureLayout.setVisibility(View.VISIBLE);
mAccountSignature.setText(mAccount.getSignature());
boolean isSignatureBeforeQuotedText = mAccount.isSignatureBeforeQuotedText();
mAccountSignatureBeforeLocation.setChecked(isSignatureBeforeQuotedText);
mAccountSignatureAfterLocation.setChecked(!isSignatureBeforeQuotedText);
- }
- else
- {
+ } else {
mAccountSignatureLayout.setVisibility(View.GONE);
}
}
@@ -98,35 +89,29 @@ public class AccountSetupComposition extends K9Activity
mAccountSignatureBeforeLocation = (RadioButton)findViewById(R.id.account_signature_location_before_quoted_text);
mAccountSignatureAfterLocation = (RadioButton)findViewById(R.id.account_signature_location_after_quoted_text);
- if (useSignature)
- {
+ if (useSignature) {
mAccountSignature.setText(mAccount.getSignature());
boolean isSignatureBeforeQuotedText = mAccount.isSignatureBeforeQuotedText();
mAccountSignatureBeforeLocation.setChecked(isSignatureBeforeQuotedText);
mAccountSignatureAfterLocation.setChecked(!isSignatureBeforeQuotedText);
- }
- else
- {
+ } else {
mAccountSignatureLayout.setVisibility(View.GONE);
}
}
@Override
- public void onResume()
- {
+ public void onResume() {
super.onResume();
//mAccount.refresh(Preferences.getPreferences(this));
}
- private void saveSettings()
- {
+ private void saveSettings() {
mAccount.setEmail(mAccountEmail.getText().toString());
mAccount.setAlwaysBcc(mAccountAlwaysBcc.getText().toString());
mAccount.setName(mAccountName.getText().toString());
mAccount.setSignatureUse(mAccountSignatureUse.isChecked());
- if (mAccountSignatureUse.isChecked())
- {
+ if (mAccountSignatureUse.isChecked()) {
mAccount.setSignature(mAccountSignature.getText().toString());
boolean isSignatureBeforeQuotedText = mAccountSignatureBeforeLocation.isChecked();
mAccount.setSignatureBeforeQuotedText(isSignatureBeforeQuotedText);
@@ -136,25 +121,21 @@ public class AccountSetupComposition extends K9Activity
}
@Override
- public boolean onKeyDown(int keyCode, KeyEvent event)
- {
- if (keyCode == KeyEvent.KEYCODE_BACK)
- {
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ if (keyCode == KeyEvent.KEYCODE_BACK) {
saveSettings();
}
return super.onKeyDown(keyCode, event);
}
@Override
- public void onSaveInstanceState(Bundle outState)
- {
+ public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putSerializable(EXTRA_ACCOUNT, mAccount.getUuid());
}
@Override
- public void onActivityResult(int requestCode, int resultCode, Intent data)
- {
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
mAccount.save(Preferences.getPreferences(this));
finish();
}
diff --git a/src/com/fsck/k9/activity/setup/AccountSetupIncoming.java b/src/com/fsck/k9/activity/setup/AccountSetupIncoming.java
index a4ff63aad..7d9f28155 100644
--- a/src/com/fsck/k9/activity/setup/AccountSetupIncoming.java
+++ b/src/com/fsck/k9/activity/setup/AccountSetupIncoming.java
@@ -22,38 +22,30 @@ import java.net.URISyntaxException;
import java.net.URLDecoder;
import java.net.URLEncoder;
-public class AccountSetupIncoming extends K9Activity implements OnClickListener
-{
+public class AccountSetupIncoming extends K9Activity implements OnClickListener {
private static final String EXTRA_ACCOUNT = "account";
private static final String EXTRA_MAKE_DEFAULT = "makeDefault";
- private static final int popPorts[] =
- {
+ private static final int popPorts[] = {
110, 995, 995, 110, 110
};
- private static final String popSchemes[] =
- {
+ private static final String popSchemes[] = {
"pop3", "pop3+ssl", "pop3+ssl+", "pop3+tls", "pop3+tls+"
};
- private static final int imapPorts[] =
- {
+ private static final int imapPorts[] = {
143, 993, 993, 143, 143
};
- private static final String imapSchemes[] =
- {
+ private static final String imapSchemes[] = {
"imap", "imap+ssl", "imap+ssl+", "imap+tls", "imap+tls+"
};
- private static final int webdavPorts[] =
- {
+ private static final int webdavPorts[] = {
80, 443, 443, 443, 443
};
- private static final String webdavSchemes[] =
- {
+ private static final String webdavSchemes[] = {
"webdav", "webdav+ssl", "webdav+ssl+", "webdav+tls", "webdav+tls+"
};
- private static final String authTypes[] =
- {
+ private static final String authTypes[] = {
"PLAIN", "CRAM_MD5"
};
@@ -78,16 +70,14 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
private CheckBox compressionOther;
private CheckBox subscribedFoldersOnly;
- public static void actionIncomingSettings(Activity context, Account account, boolean makeDefault)
- {
+ public static void actionIncomingSettings(Activity context, Account account, boolean makeDefault) {
Intent i = new Intent(context, AccountSetupIncoming.class);
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
i.putExtra(EXTRA_MAKE_DEFAULT, makeDefault);
context.startActivity(i);
}
- public static void actionEditIncomingSettings(Activity context, Account account)
- {
+ public static void actionEditIncomingSettings(Activity context, Account account) {
Intent i = new Intent(context, AccountSetupIncoming.class);
i.setAction(Intent.ACTION_EDIT);
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
@@ -95,8 +85,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
}
@Override
- public void onCreate(Bundle savedInstanceState)
- {
+ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.account_setup_incoming);
@@ -119,8 +108,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
mNextButton.setOnClickListener(this);
- SpinnerOption securityTypes[] =
- {
+ SpinnerOption securityTypes[] = {
new SpinnerOption(0, getString(R.string.account_setup_incoming_security_none_label)),
new SpinnerOption(1,
getString(R.string.account_setup_incoming_security_ssl_optional_label)),
@@ -132,8 +120,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
// This needs to be kept in sync with the list at the top of the file.
// that makes me somewhat unhappy
- SpinnerOption authTypeSpinnerOptions[] =
- {
+ SpinnerOption authTypeSpinnerOptions[] = {
new SpinnerOption(0, "PLAIN"),
new SpinnerOption(1, "CRAM_MD5")
};
@@ -152,15 +139,12 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
* Updates the port when the user changes the security type. This allows
* us to show a reasonable default which the user can change.
*/
- mSecurityTypeView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
- {
- public void onItemSelected(AdapterView> parent, View view, int position, long id)
- {
+ mSecurityTypeView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
+ public void onItemSelected(AdapterView> parent, View view, int position, long id) {
updatePortFromSecurityType();
}
- public void onNothingSelected(AdapterView> parent)
- {
+ public void onNothingSelected(AdapterView> parent) {
}
});
@@ -168,19 +152,15 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
* Calls validateFields() which enables or disables the Next button
* based on the fields' validity.
*/
- TextWatcher validationTextWatcher = new TextWatcher()
- {
- public void afterTextChanged(Editable s)
- {
+ TextWatcher validationTextWatcher = new TextWatcher() {
+ public void afterTextChanged(Editable s) {
validateFields();
}
- public void beforeTextChanged(CharSequence s, int start, int count, int after)
- {
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
- public void onTextChanged(CharSequence s, int start, int before, int count)
- {
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
}
};
mUsernameView.addTextChangedListener(validationTextWatcher);
@@ -201,65 +181,51 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
* If we're being reloaded we override the original account with the one
* we saved
*/
- if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_ACCOUNT))
- {
+ if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_ACCOUNT)) {
accountUuid = savedInstanceState.getString(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
}
- try
- {
+ try {
URI uri = new URI(mAccount.getStoreUri());
String username = null;
String password = null;
String authType = null;
- if (uri.getUserInfo() != null)
- {
+ if (uri.getUserInfo() != null) {
String[] userInfoParts = uri.getUserInfo().split(":");
- if (userInfoParts.length == 3)
- {
+ if (userInfoParts.length == 3) {
authType = userInfoParts[0];
username = URLDecoder.decode(userInfoParts[1], "UTF-8");
password = URLDecoder.decode(userInfoParts[2], "UTF-8");
- }
- else if (userInfoParts.length == 2)
- {
+ } else if (userInfoParts.length == 2) {
username = URLDecoder.decode(userInfoParts[0], "UTF-8");
password = URLDecoder.decode(userInfoParts[1], "UTF-8");
- }
- else if (userInfoParts.length == 1)
- {
+ } else if (userInfoParts.length == 1) {
username = URLDecoder.decode(userInfoParts[0], "UTF-8");
}
}
- if (username != null)
- {
+ if (username != null) {
mUsernameView.setText(username);
}
- if (password != null)
- {
+ if (password != null) {
mPasswordView.setText(password);
}
- if (authType != null)
- {
- for (int i = 0; i < authTypes.length; i++)
- {
- if (authTypes[i].equals(authType))
- {
+ if (authType != null) {
+ for (int i = 0; i < authTypes.length; i++) {
+ if (authTypes[i].equals(authType)) {
SpinnerOption.setSpinnerOptionValue(mAuthTypeView, i);
}
}
}
- if (uri.getScheme().startsWith("pop3"))
- {
+ if (uri.getScheme().startsWith("pop3")) {
serverLabelView.setText(R.string.account_setup_incoming_pop_server_label);
mAccountPorts = popPorts;
mAccountSchemes = popSchemes;
@@ -273,15 +239,12 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
findViewById(R.id.compression_section).setVisibility(View.GONE);
findViewById(R.id.compression_label).setVisibility(View.GONE);
mAccount.setDeletePolicy(Account.DELETE_POLICY_NEVER);
- }
- else if (uri.getScheme().startsWith("imap"))
- {
+ } else if (uri.getScheme().startsWith("imap")) {
serverLabelView.setText(R.string.account_setup_incoming_imap_server_label);
mAccountPorts = imapPorts;
mAccountSchemes = imapSchemes;
- if (uri.getPath() != null && uri.getPath().length() > 0)
- {
+ if (uri.getPath() != null && uri.getPath().length() > 0) {
mImapPathPrefixView.setText(uri.getPath().substring(1));
}
@@ -291,13 +254,10 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
findViewById(R.id.webdav_auth_path_section).setVisibility(View.GONE);
mAccount.setDeletePolicy(Account.DELETE_POLICY_ON_DELETE);
- if (!Intent.ACTION_EDIT.equals(getIntent().getAction()))
- {
+ if (!Intent.ACTION_EDIT.equals(getIntent().getAction())) {
findViewById(R.id.imap_folder_setup_section).setVisibility(View.GONE);
}
- }
- else if (uri.getScheme().startsWith("webdav"))
- {
+ } else if (uri.getScheme().startsWith("webdav")) {
serverLabelView.setText(R.string.account_setup_incoming_webdav_server_label);
mAccountPorts = webdavPorts;
mAccountSchemes = webdavSchemes;
@@ -309,49 +269,35 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
findViewById(R.id.compression_section).setVisibility(View.GONE);
findViewById(R.id.compression_label).setVisibility(View.GONE);
subscribedFoldersOnly.setVisibility(View.GONE);
- if (uri.getPath() != null && uri.getPath().length() > 0)
- {
+ if (uri.getPath() != null && uri.getPath().length() > 0) {
String[] pathParts = uri.getPath().split("\\|");
- for (int i = 0, count = pathParts.length; i < count; i++)
- {
- if (i == 0)
- {
+ for (int i = 0, count = pathParts.length; i < count; i++) {
+ if (i == 0) {
if (pathParts[0] != null &&
- pathParts[0].length() > 1)
- {
+ pathParts[0].length() > 1) {
mWebdavPathPrefixView.setText(pathParts[0].substring(1));
}
- }
- else if (i == 1)
- {
+ } else if (i == 1) {
if (pathParts[1] != null &&
- pathParts[1].length() > 1)
- {
+ pathParts[1].length() > 1) {
mWebdavAuthPathView.setText(pathParts[1]);
}
- }
- else if (i == 2)
- {
+ } else if (i == 2) {
if (pathParts[2] != null &&
- pathParts[2].length() > 1)
- {
+ pathParts[2].length() > 1) {
mWebdavMailboxPathView.setText(pathParts[2]);
}
}
}
}
mAccount.setDeletePolicy(Account.DELETE_POLICY_ON_DELETE);
- }
- else
- {
+ } else {
throw new Exception("Unknown account type: " + mAccount.getStoreUri());
}
- for (int i = 0; i < mAccountSchemes.length; i++)
- {
- if (mAccountSchemes[i].equals(uri.getScheme()))
- {
+ for (int i = 0; i < mAccountSchemes.length; i++) {
+ if (mAccountSchemes[i].equals(uri.getScheme())) {
SpinnerOption.setSpinnerOptionValue(mSecurityTypeView, i);
}
}
@@ -359,39 +305,31 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
compressionWifi.setChecked(mAccount.useCompression(Account.TYPE_WIFI));
compressionOther.setChecked(mAccount.useCompression(Account.TYPE_OTHER));
- if (uri.getHost() != null)
- {
+ if (uri.getHost() != null) {
mServerView.setText(uri.getHost());
}
- if (uri.getPort() != -1)
- {
+ if (uri.getPort() != -1) {
mPortView.setText(Integer.toString(uri.getPort()));
- }
- else
- {
+ } else {
updatePortFromSecurityType();
}
subscribedFoldersOnly.setChecked(mAccount.subscribedFoldersOnly());
validateFields();
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
failure(e);
}
}
@Override
- public void onSaveInstanceState(Bundle outState)
- {
+ public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString(EXTRA_ACCOUNT, mAccount.getUuid());
}
- private void validateFields()
- {
+ private void validateFields() {
mNextButton
.setEnabled(Utility.requiredFieldValid(mUsernameView)
&& Utility.requiredFieldValid(mPasswordView)
@@ -400,33 +338,25 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
Utility.setCompoundDrawablesAlpha(mNextButton, mNextButton.isEnabled() ? 255 : 128);
}
- private void updatePortFromSecurityType()
- {
- if (mAccountPorts != null)
- {
+ private void updatePortFromSecurityType() {
+ if (mAccountPorts != null) {
int securityType = (Integer)((SpinnerOption)mSecurityTypeView.getSelectedItem()).value;
mPortView.setText(Integer.toString(mAccountPorts[securityType]));
}
}
@Override
- public void onActivityResult(int requestCode, int resultCode, Intent data)
- {
- if (resultCode == RESULT_OK)
- {
- if (Intent.ACTION_EDIT.equals(getIntent().getAction()))
- {
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (resultCode == RESULT_OK) {
+ if (Intent.ACTION_EDIT.equals(getIntent().getAction())) {
mAccount.save(Preferences.getPreferences(this));
finish();
- }
- else
- {
+ } else {
/*
* Set the username and password for the outgoing settings to the username and
* password the user just set for incoming.
*/
- try
- {
+ try {
String usernameEnc = URLEncoder.encode(mUsernameView.getText().toString(), "UTF-8");
String passwordEnc = URLEncoder.encode(mPasswordView.getText().toString(), "UTF-8");
URI oldUri = new URI(mAccount.getTransportUri());
@@ -439,14 +369,10 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
null,
null);
mAccount.setTransportUri(uri.toString());
- }
- catch (UnsupportedEncodingException enc)
- {
+ } catch (UnsupportedEncodingException enc) {
// This really shouldn't happen since the encoding is hardcoded to UTF-8
Log.e(K9.LOG_TAG, "Couldn't urlencode username or password.", enc);
- }
- catch (URISyntaxException use)
- {
+ } catch (URISyntaxException use) {
/*
* If we can't set up the URL we just continue. It's only for
* convenience.
@@ -461,18 +387,13 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
}
@Override
- protected void onNext()
- {
- try
- {
+ protected void onNext() {
+ try {
int securityType = (Integer)((SpinnerOption)mSecurityTypeView.getSelectedItem()).value;
String path = null;
- if (mAccountSchemes[securityType].startsWith("imap"))
- {
+ if (mAccountSchemes[securityType].startsWith("imap")) {
path = "/" + mImapPathPrefixView.getText();
- }
- else if (mAccountSchemes[securityType].startsWith("webdav"))
- {
+ } else if (mAccountSchemes[securityType].startsWith("webdav")) {
path = "/" + mWebdavPathPrefixView.getText();
path = path + "|" + mWebdavAuthPathView.getText();
path = path + "|" + mWebdavMailboxPathView.getText();
@@ -484,13 +405,10 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
String userEnc = URLEncoder.encode(user, "UTF-8");
String passwordEnc = URLEncoder.encode(password, "UTF-8");
- if (mAccountSchemes[securityType].startsWith("imap"))
- {
+ if (mAccountSchemes[securityType].startsWith("imap")) {
String authType = ((SpinnerOption)mAuthTypeView.getSelectedItem()).label;
userInfo = authType + ":" + userEnc + ":" + passwordEnc;
- }
- else
- {
+ } else {
userInfo = userEnc + ":" + passwordEnc;
}
URI uri = new URI(
@@ -510,33 +428,25 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
mAccount.setSubscribedFoldersOnly(subscribedFoldersOnly.isChecked());
AccountSetupCheckSettings.actionCheckSettings(this, mAccount, true, false);
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
failure(e);
}
}
- public void onClick(View v)
- {
- try
- {
- switch (v.getId())
- {
- case R.id.next:
- onNext();
- break;
+ public void onClick(View v) {
+ try {
+ switch (v.getId()) {
+ case R.id.next:
+ onNext();
+ break;
}
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
failure(e);
}
}
- private void failure(Exception use)
- {
+ private void failure(Exception use) {
Log.e(K9.LOG_TAG, "Failure", use);
String toastText = getString(R.string.account_setup_bad_uri, use.getMessage());
diff --git a/src/com/fsck/k9/activity/setup/AccountSetupNames.java b/src/com/fsck/k9/activity/setup/AccountSetupNames.java
index 4b577e9b3..493633e99 100644
--- a/src/com/fsck/k9/activity/setup/AccountSetupNames.java
+++ b/src/com/fsck/k9/activity/setup/AccountSetupNames.java
@@ -16,8 +16,7 @@ import com.fsck.k9.*;
import com.fsck.k9.activity.K9Activity;
import com.fsck.k9.helper.Utility;
-public class AccountSetupNames extends K9Activity implements OnClickListener
-{
+public class AccountSetupNames extends K9Activity implements OnClickListener {
private static final String EXTRA_ACCOUNT = "account";
private EditText mDescription;
@@ -28,16 +27,14 @@ public class AccountSetupNames extends K9Activity implements OnClickListener
private Button mDoneButton;
- public static void actionSetNames(Context context, Account account)
- {
+ public static void actionSetNames(Context context, Account account) {
Intent i = new Intent(context, AccountSetupNames.class);
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
context.startActivity(i);
}
@Override
- public void onCreate(Bundle savedInstanceState)
- {
+ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.account_setup_names);
mDescription = (EditText)findViewById(R.id.account_description);
@@ -45,19 +42,15 @@ public class AccountSetupNames extends K9Activity implements OnClickListener
mDoneButton = (Button)findViewById(R.id.done);
mDoneButton.setOnClickListener(this);
- TextWatcher validationTextWatcher = new TextWatcher()
- {
- public void afterTextChanged(Editable s)
- {
+ TextWatcher validationTextWatcher = new TextWatcher() {
+ public void afterTextChanged(Editable s) {
validateFields();
}
- public void beforeTextChanged(CharSequence s, int start, int count, int after)
- {
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
- public void onTextChanged(CharSequence s, int start, int before, int count)
- {
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
}
};
mName.addTextChangedListener(validationTextWatcher);
@@ -73,27 +66,22 @@ public class AccountSetupNames extends K9Activity implements OnClickListener
* just leave the saved value alone.
*/
// mDescription.setText(mAccount.getDescription());
- if (mAccount.getName() != null)
- {
+ if (mAccount.getName() != null) {
mName.setText(mAccount.getName());
}
- if (!Utility.requiredFieldValid(mName))
- {
+ if (!Utility.requiredFieldValid(mName)) {
mDoneButton.setEnabled(false);
}
}
- private void validateFields()
- {
+ private void validateFields() {
mDoneButton.setEnabled(Utility.requiredFieldValid(mName));
Utility.setCompoundDrawablesAlpha(mDoneButton, mDoneButton.isEnabled() ? 255 : 128);
}
@Override
- protected void onNext()
- {
- if (Utility.requiredFieldValid(mDescription))
- {
+ protected void onNext() {
+ if (Utility.requiredFieldValid(mDescription)) {
mAccount.setDescription(mDescription.getText().toString());
}
mAccount.setName(mName.getText().toString());
@@ -101,13 +89,11 @@ public class AccountSetupNames extends K9Activity implements OnClickListener
finish();
}
- public void onClick(View v)
- {
- switch (v.getId())
- {
- case R.id.done:
- onNext();
- break;
+ public void onClick(View v) {
+ switch (v.getId()) {
+ case R.id.done:
+ onNext();
+ break;
}
}
}
diff --git a/src/com/fsck/k9/activity/setup/AccountSetupOptions.java b/src/com/fsck/k9/activity/setup/AccountSetupOptions.java
index b8dbb9f6b..47cee8a8b 100644
--- a/src/com/fsck/k9/activity/setup/AccountSetupOptions.java
+++ b/src/com/fsck/k9/activity/setup/AccountSetupOptions.java
@@ -14,8 +14,7 @@ import com.fsck.k9.*;
import com.fsck.k9.activity.K9Activity;
import com.fsck.k9.mail.Store;
-public class AccountSetupOptions extends K9Activity implements OnClickListener
-{
+public class AccountSetupOptions extends K9Activity implements OnClickListener {
private static final String EXTRA_ACCOUNT = "account";
private static final String EXTRA_MAKE_DEFAULT = "makeDefault";
@@ -31,8 +30,7 @@ public class AccountSetupOptions extends K9Activity implements OnClickListener
private Account mAccount;
- public static void actionOptions(Context context, Account account, boolean makeDefault)
- {
+ public static void actionOptions(Context context, Account account, boolean makeDefault) {
Intent i = new Intent(context, AccountSetupOptions.class);
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
i.putExtra(EXTRA_MAKE_DEFAULT, makeDefault);
@@ -40,8 +38,7 @@ public class AccountSetupOptions extends K9Activity implements OnClickListener
}
@Override
- public void onCreate(Bundle savedInstanceState)
- {
+ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.account_setup_options);
@@ -53,8 +50,7 @@ public class AccountSetupOptions extends K9Activity implements OnClickListener
findViewById(R.id.next).setOnClickListener(this);
- SpinnerOption checkFrequencies[] =
- {
+ SpinnerOption checkFrequencies[] = {
new SpinnerOption(-1,
getString(R.string.account_setup_options_mail_check_frequency_never)),
new SpinnerOption(1,
@@ -88,8 +84,7 @@ public class AccountSetupOptions extends K9Activity implements OnClickListener
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mCheckFrequencyView.setAdapter(checkFrequenciesAdapter);
- SpinnerOption displayCounts[] =
- {
+ SpinnerOption displayCounts[] = {
new SpinnerOption(10, getString(R.string.account_setup_options_mail_display_count_10)),
new SpinnerOption(25, getString(R.string.account_setup_options_mail_display_count_25)),
new SpinnerOption(50, getString(R.string.account_setup_options_mail_display_count_50)),
@@ -116,31 +111,24 @@ public class AccountSetupOptions extends K9Activity implements OnClickListener
boolean isPushCapable = false;
- try
- {
+ try {
Store store = mAccount.getRemoteStore();
isPushCapable = store.isPushCapable();
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
Log.e(K9.LOG_TAG, "Could not get remote store", e);
}
- if (!isPushCapable)
- {
+ if (!isPushCapable) {
mPushEnable.setVisibility(View.GONE);
- }
- else
- {
+ } else {
mPushEnable.setChecked(true);
}
}
- private void onDone()
- {
+ private void onDone() {
mAccount.setDescription(mAccount.getEmail());
mAccount.setNotifyNewMail(mNotifyView.isChecked());
mAccount.setShowOngoing(mNotifySyncView.isChecked());
@@ -149,19 +137,15 @@ public class AccountSetupOptions extends K9Activity implements OnClickListener
mAccount.setDisplayCount((Integer)((SpinnerOption)mDisplayCountView
.getSelectedItem()).value);
- if (mPushEnable.isChecked())
- {
+ if (mPushEnable.isChecked()) {
mAccount.setFolderPushMode(Account.FolderMode.FIRST_CLASS);
- }
- else
- {
+ } else {
mAccount.setFolderPushMode(Account.FolderMode.NONE);
}
mAccount.save(Preferences.getPreferences(this));
if (mAccount.equals(Preferences.getPreferences(this).getDefaultAccount()) ||
- getIntent().getBooleanExtra(EXTRA_MAKE_DEFAULT, false))
- {
+ getIntent().getBooleanExtra(EXTRA_MAKE_DEFAULT, false)) {
Preferences.getPreferences(this).setDefaultAccount(mAccount);
}
K9.setServicesEnabled(this);
@@ -169,13 +153,11 @@ public class AccountSetupOptions extends K9Activity implements OnClickListener
finish();
}
- public void onClick(View v)
- {
- switch (v.getId())
- {
- case R.id.next:
- onDone();
- break;
+ public void onClick(View v) {
+ switch (v.getId()) {
+ case R.id.next:
+ onDone();
+ break;
}
}
}
diff --git a/src/com/fsck/k9/activity/setup/AccountSetupOutgoing.java b/src/com/fsck/k9/activity/setup/AccountSetupOutgoing.java
index 42a31d733..a89678a8c 100644
--- a/src/com/fsck/k9/activity/setup/AccountSetupOutgoing.java
+++ b/src/com/fsck/k9/activity/setup/AccountSetupOutgoing.java
@@ -23,19 +23,16 @@ import java.net.URLDecoder;
import java.net.URLEncoder;
public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
- OnCheckedChangeListener
-{
+ OnCheckedChangeListener {
private static final String EXTRA_ACCOUNT = "account";
private static final String EXTRA_MAKE_DEFAULT = "makeDefault";
- private static final int smtpPorts[] =
- {
+ private static final int smtpPorts[] = {
25, 465, 465, 25, 25
};
- private static final String smtpSchemes[] =
- {
+ private static final String smtpSchemes[] = {
"smtp", "smtp+ssl", "smtp+ssl+", "smtp+tls", "smtp+tls+"
};
/*
@@ -49,8 +46,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
};
*/
- private static final String authTypes[] =
- {
+ private static final String authTypes[] = {
"PLAIN", "CRAM_MD5"
};
private EditText mUsernameView;
@@ -65,16 +61,14 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
private Account mAccount;
private boolean mMakeDefault;
- public static void actionOutgoingSettings(Context context, Account account, boolean makeDefault)
- {
+ public static void actionOutgoingSettings(Context context, Account account, boolean makeDefault) {
Intent i = new Intent(context, AccountSetupOutgoing.class);
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
i.putExtra(EXTRA_MAKE_DEFAULT, makeDefault);
context.startActivity(i);
}
- public static void actionEditOutgoingSettings(Context context, Account account)
- {
+ public static void actionEditOutgoingSettings(Context context, Account account) {
Intent i = new Intent(context, AccountSetupOutgoing.class);
i.setAction(Intent.ACTION_EDIT);
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
@@ -82,24 +76,19 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
}
@Override
- public void onCreate(Bundle savedInstanceState)
- {
+ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.account_setup_outgoing);
String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
- try
- {
- if (new URI(mAccount.getStoreUri()).getScheme().startsWith("webdav"))
- {
+ try {
+ if (new URI(mAccount.getStoreUri()).getScheme().startsWith("webdav")) {
mAccount.setTransportUri(mAccount.getStoreUri());
AccountSetupCheckSettings.actionCheckSettings(this, mAccount, false, true);
}
- }
- catch (URISyntaxException e)
- {
+ } catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
@@ -118,8 +107,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
mNextButton.setOnClickListener(this);
mRequireLoginView.setOnCheckedChangeListener(this);
- SpinnerOption securityTypes[] =
- {
+ SpinnerOption securityTypes[] = {
new SpinnerOption(0, getString(R.string.account_setup_incoming_security_none_label)),
new SpinnerOption(1,
getString(R.string.account_setup_incoming_security_ssl_optional_label)),
@@ -131,8 +119,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
// This needs to be kept in sync with the list at the top of the file.
// that makes me somewhat unhappy
- SpinnerOption authTypeSpinnerOptions[] =
- {
+ SpinnerOption authTypeSpinnerOptions[] = {
new SpinnerOption(0, "PLAIN"),
new SpinnerOption(1, "CRAM_MD5")
};
@@ -153,15 +140,12 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
* Updates the port when the user changes the security type. This allows
* us to show a reasonable default which the user can change.
*/
- mSecurityTypeView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
- {
- public void onItemSelected(AdapterView> parent, View view, int position, long id)
- {
+ mSecurityTypeView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
+ public void onItemSelected(AdapterView> parent, View view, int position, long id) {
updatePortFromSecurityType();
}
- public void onNothingSelected(AdapterView> parent)
- {
+ public void onNothingSelected(AdapterView> parent) {
}
});
@@ -169,19 +153,15 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
* Calls validateFields() which enables or disables the Next button
* based on the fields' validity.
*/
- TextWatcher validationTextWatcher = new TextWatcher()
- {
- public void afterTextChanged(Editable s)
- {
+ TextWatcher validationTextWatcher = new TextWatcher() {
+ public void afterTextChanged(Editable s) {
validateFields();
}
- public void beforeTextChanged(CharSequence s, int start, int count, int after)
- {
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
- public void onTextChanged(CharSequence s, int start, int before, int count)
- {
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
}
};
mUsernameView.addTextChangedListener(validationTextWatcher);
@@ -203,82 +183,64 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
* If we're being reloaded we override the original account with the one
* we saved
*/
- if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_ACCOUNT))
- {
+ if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_ACCOUNT)) {
accountUuid = savedInstanceState.getString(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
}
- try
- {
+ try {
URI uri = new URI(mAccount.getTransportUri());
String username = null;
String password = null;
String authType = null;
- if (uri.getUserInfo() != null)
- {
+ if (uri.getUserInfo() != null) {
String[] userInfoParts = uri.getUserInfo().split(":");
username = URLDecoder.decode(userInfoParts[0], "UTF-8");
- if (userInfoParts.length > 1)
- {
+ if (userInfoParts.length > 1) {
password = URLDecoder.decode(userInfoParts[1], "UTF-8");
}
- if (userInfoParts.length > 2)
- {
+ if (userInfoParts.length > 2) {
authType = userInfoParts[2];
}
}
- if (username != null)
- {
+ if (username != null) {
mUsernameView.setText(username);
mRequireLoginView.setChecked(true);
}
- if (password != null)
- {
+ if (password != null) {
mPasswordView.setText(password);
}
- if (authType != null)
- {
- for (int i = 0; i < authTypes.length; i++)
- {
- if (authTypes[i].equals(authType))
- {
+ if (authType != null) {
+ for (int i = 0; i < authTypes.length; i++) {
+ if (authTypes[i].equals(authType)) {
SpinnerOption.setSpinnerOptionValue(mAuthTypeView, i);
}
}
}
- for (int i = 0; i < smtpSchemes.length; i++)
- {
- if (smtpSchemes[i].equals(uri.getScheme()))
- {
+ for (int i = 0; i < smtpSchemes.length; i++) {
+ if (smtpSchemes[i].equals(uri.getScheme())) {
SpinnerOption.setSpinnerOptionValue(mSecurityTypeView, i);
}
}
- if (uri.getHost() != null)
- {
+ if (uri.getHost() != null) {
mServerView.setText(uri.getHost());
}
- if (uri.getPort() != -1)
- {
+ if (uri.getPort() != -1) {
mPortView.setText(Integer.toString(uri.getPort()));
- }
- else
- {
+ } else {
updatePortFromSecurityType();
}
validateFields();
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
/*
* We should always be able to parse our own settings.
*/
@@ -288,14 +250,12 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
}
@Override
- public void onSaveInstanceState(Bundle outState)
- {
+ public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString(EXTRA_ACCOUNT, mAccount.getUuid());
}
- private void validateFields()
- {
+ private void validateFields() {
mNextButton
.setEnabled(
Utility.domainFieldValid(mServerView) &&
@@ -306,24 +266,18 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
Utility.setCompoundDrawablesAlpha(mNextButton, mNextButton.isEnabled() ? 255 : 128);
}
- private void updatePortFromSecurityType()
- {
+ private void updatePortFromSecurityType() {
int securityType = (Integer)((SpinnerOption)mSecurityTypeView.getSelectedItem()).value;
mPortView.setText(Integer.toString(smtpPorts[securityType]));
}
@Override
- public void onActivityResult(int requestCode, int resultCode, Intent data)
- {
- if (resultCode == RESULT_OK)
- {
- if (Intent.ACTION_EDIT.equals(getIntent().getAction()))
- {
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (resultCode == RESULT_OK) {
+ if (Intent.ACTION_EDIT.equals(getIntent().getAction())) {
mAccount.save(Preferences.getPreferences(this));
finish();
- }
- else
- {
+ } else {
AccountSetupOptions.actionOptions(this, mAccount, mMakeDefault);
finish();
}
@@ -331,33 +285,26 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
}
@Override
- protected void onNext()
- {
+ protected void onNext() {
int securityType = (Integer)((SpinnerOption)mSecurityTypeView.getSelectedItem()).value;
URI uri;
- try
- {
+ try {
String usernameEnc = URLEncoder.encode(mUsernameView.getText().toString(), "UTF-8");
String passwordEnc = URLEncoder.encode(mPasswordView.getText().toString(), "UTF-8");
String userInfo = null;
String authType = ((SpinnerOption)mAuthTypeView.getSelectedItem()).label;
- if (mRequireLoginView.isChecked())
- {
+ if (mRequireLoginView.isChecked()) {
userInfo = usernameEnc + ":" + passwordEnc + ":" + authType;
}
uri = new URI(smtpSchemes[securityType], userInfo, mServerView.getText().toString(),
Integer.parseInt(mPortView.getText().toString()), null, null, null);
mAccount.setTransportUri(uri.toString());
AccountSetupCheckSettings.actionCheckSettings(this, mAccount, false, true);
- }
- catch (UnsupportedEncodingException enc)
- {
+ } catch (UnsupportedEncodingException enc) {
// This really shouldn't happen since the encoding is hardcoded to UTF-8
Log.e(K9.LOG_TAG, "Couldn't urlencode username or password.", enc);
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
/*
* It's unrecoverable if we cannot create a URI from components that
* we validated to be safe.
@@ -367,23 +314,19 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
}
- public void onClick(View v)
- {
- switch (v.getId())
- {
- case R.id.next:
- onNext();
- break;
+ public void onClick(View v) {
+ switch (v.getId()) {
+ case R.id.next:
+ onNext();
+ break;
}
}
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
- {
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mRequireLoginSettingsView.setVisibility(isChecked ? View.VISIBLE : View.GONE);
validateFields();
}
- private void failure(Exception use)
- {
+ private void failure(Exception use) {
Log.e(K9.LOG_TAG, "Failure", use);
String toastText = getString(R.string.account_setup_bad_uri, use.getMessage());
diff --git a/src/com/fsck/k9/activity/setup/FolderSettings.java b/src/com/fsck/k9/activity/setup/FolderSettings.java
index 29b6d51b5..cd48f0475 100644
--- a/src/com/fsck/k9/activity/setup/FolderSettings.java
+++ b/src/com/fsck/k9/activity/setup/FolderSettings.java
@@ -19,8 +19,7 @@ import com.fsck.k9.mail.store.LocalStore;
import com.fsck.k9.mail.store.LocalStore.LocalFolder;
import com.fsck.k9.service.MailService;
-public class FolderSettings extends K9PreferenceActivity
-{
+public class FolderSettings extends K9PreferenceActivity {
private static final String EXTRA_FOLDER_NAME = "com.fsck.k9.folderName";
private static final String EXTRA_ACCOUNT = "com.fsck.k9.account";
@@ -40,8 +39,7 @@ public class FolderSettings extends K9PreferenceActivity
private ListPreference mSyncClass;
private ListPreference mPushClass;
- public static void actionSettings(Context context, Account account, String folderName)
- {
+ public static void actionSettings(Context context, Account account, String folderName) {
Intent i = new Intent(context, FolderSettings.class);
i.putExtra(EXTRA_FOLDER_NAME, folderName);
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
@@ -49,35 +47,28 @@ public class FolderSettings extends K9PreferenceActivity
}
@Override
- public void onCreate(Bundle savedInstanceState)
- {
+ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String folderName = (String)getIntent().getSerializableExtra(EXTRA_FOLDER_NAME);
String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
Account mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
- try
- {
+ try {
LocalStore localStore = mAccount.getLocalStore();
mFolder = localStore.getFolder(folderName);
mFolder.open(OpenMode.READ_WRITE);
- }
- catch (MessagingException me)
- {
+ } catch (MessagingException me) {
Log.e(K9.LOG_TAG, "Unable to edit folder " + folderName + " preferences", me);
return;
}
boolean isPushCapable = false;
Store store = null;
- try
- {
+ try {
store = mAccount.getRemoteStore();
isPushCapable = store.isPushCapable();
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
Log.e(K9.LOG_TAG, "Could not get remote store", e);
}
@@ -95,10 +86,8 @@ public class FolderSettings extends K9PreferenceActivity
mDisplayClass = (ListPreference) findPreference(PREFERENCE_DISPLAY_CLASS);
mDisplayClass.setValue(mFolder.getDisplayClass().name());
mDisplayClass.setSummary(mDisplayClass.getEntry());
- mDisplayClass.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
- {
- public boolean onPreferenceChange(Preference preference, Object newValue)
- {
+ mDisplayClass.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mDisplayClass.findIndexOfValue(summary);
mDisplayClass.setSummary(mDisplayClass.getEntries()[index]);
@@ -110,10 +99,8 @@ public class FolderSettings extends K9PreferenceActivity
mSyncClass = (ListPreference) findPreference(PREFERENCE_SYNC_CLASS);
mSyncClass.setValue(mFolder.getRawSyncClass().name());
mSyncClass.setSummary(mSyncClass.getEntry());
- mSyncClass.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
- {
- public boolean onPreferenceChange(Preference preference, Object newValue)
- {
+ mSyncClass.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mSyncClass.findIndexOfValue(summary);
mSyncClass.setSummary(mSyncClass.getEntries()[index]);
@@ -126,10 +113,8 @@ public class FolderSettings extends K9PreferenceActivity
mPushClass.setEnabled(isPushCapable);
mPushClass.setValue(mFolder.getRawPushClass().name());
mPushClass.setSummary(mPushClass.getEntry());
- mPushClass.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
- {
- public boolean onPreferenceChange(Preference preference, Object newValue)
- {
+ mPushClass.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString();
int index = mPushClass.findIndexOfValue(summary);
mPushClass.setSummary(mPushClass.getEntries()[index]);
@@ -140,13 +125,11 @@ public class FolderSettings extends K9PreferenceActivity
}
@Override
- public void onResume()
- {
+ public void onResume() {
super.onResume();
}
- private void saveSettings() throws MessagingException
- {
+ private void saveSettings() throws MessagingException {
mFolder.setInTopGroup(mInTopGroup.isChecked());
mFolder.setIntegrate(mIntegrate.isChecked());
// We call getPushClass() because display class changes can affect push class when push class is set to inherit
@@ -162,24 +145,18 @@ public class FolderSettings extends K9PreferenceActivity
FolderClass newDisplayClass = mFolder.getDisplayClass();
if (oldPushClass != newPushClass
- || (newPushClass != FolderClass.NO_CLASS && oldDisplayClass != newDisplayClass))
- {
+ || (newPushClass != FolderClass.NO_CLASS && oldDisplayClass != newDisplayClass)) {
MailService.actionRestartPushers(getApplication(), null);
}
}
@Override
- public boolean onKeyDown(int keyCode, KeyEvent event)
- {
- if (keyCode == KeyEvent.KEYCODE_BACK)
- {
- try
- {
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ if (keyCode == KeyEvent.KEYCODE_BACK) {
+ try {
saveSettings();
- }
- catch (MessagingException e)
- {
- Log.e(K9.LOG_TAG,"Saving folder settings failed "+e);
+ } catch (MessagingException e) {
+ Log.e(K9.LOG_TAG, "Saving folder settings failed " + e);
}
}
return super.onKeyDown(keyCode, event);
diff --git a/src/com/fsck/k9/activity/setup/FontSizeSettings.java b/src/com/fsck/k9/activity/setup/FontSizeSettings.java
index bf0369591..b51f2da99 100644
--- a/src/com/fsck/k9/activity/setup/FontSizeSettings.java
+++ b/src/com/fsck/k9/activity/setup/FontSizeSettings.java
@@ -17,8 +17,7 @@ import com.fsck.k9.activity.K9PreferenceActivity;
*
* @see FontSizes
*/
-public class FontSizeSettings extends K9PreferenceActivity
-{
+public class FontSizeSettings extends K9PreferenceActivity {
/*
* Keys of the preferences defined in res/xml/font_preferences.xml
*/
@@ -62,15 +61,13 @@ public class FontSizeSettings extends K9PreferenceActivity
*
* @param context The application context.
*/
- public static void actionEditSettings(Context context)
- {
+ public static void actionEditSettings(Context context) {
Intent i = new Intent(context, FontSizeSettings.class);
context.startActivity(i);
}
@Override
- public void onCreate(Bundle savedInstanceState)
- {
+ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FontSizes fontSizes = K9.getFontSizes();
@@ -133,8 +130,7 @@ public class FontSizeSettings extends K9PreferenceActivity
* Update the global FontSize object and permanently store the (possibly
* changed) font size settings.
*/
- private void saveSettings()
- {
+ private void saveSettings() {
FontSizes fontSizes = K9.getFontSizes();
fontSizes.setAccountName(Integer.parseInt(mAccountName.getValue()));
@@ -164,10 +160,8 @@ public class FontSizeSettings extends K9PreferenceActivity
}
@Override
- public boolean onKeyDown(int keyCode, KeyEvent event)
- {
- if (keyCode == KeyEvent.KEYCODE_BACK)
- {
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ if (keyCode == KeyEvent.KEYCODE_BACK) {
saveSettings();
}
return super.onKeyDown(keyCode, event);
diff --git a/src/com/fsck/k9/activity/setup/Prefs.java b/src/com/fsck/k9/activity/setup/Prefs.java
index 334084572..fdd190b54 100644
--- a/src/com/fsck/k9/activity/setup/Prefs.java
+++ b/src/com/fsck/k9/activity/setup/Prefs.java
@@ -29,8 +29,7 @@ import com.fsck.k9.preferences.TimePickerPreference;
import com.fsck.k9.service.MailService;
-public class Prefs extends K9PreferenceActivity
-{
+public class Prefs extends K9PreferenceActivity {
/**
* Immutable empty {@link CharSequence} array
@@ -57,7 +56,7 @@ public class Prefs extends K9PreferenceActivity
private static final String PREFERENCE_MESSAGELIST_PREVIEW_LINES = "messagelist_preview_lines";
private static final String PREFERENCE_MESSAGELIST_STARS = "messagelist_stars";
private static final String PREFERENCE_MESSAGELIST_CHECKBOXES = "messagelist_checkboxes";
- private static final String PREFERENCE_MESSAGELIST_SHOW_CORRESPONDENT_NAMES= "messagelist_show_correspondent_names";
+ private static final String PREFERENCE_MESSAGELIST_SHOW_CORRESPONDENT_NAMES = "messagelist_show_correspondent_names";
private static final String PREFERENCE_MESSAGELIST_SHOW_CONTACT_NAME = "messagelist_show_contact_name";
private static final String PREFERENCE_MESSAGELIST_CONTACT_NAME_COLOR = "messagelist_contact_name_color";
private static final String PREFERENCE_MESSAGEVIEW_FIXEDWIDTH = "messageview_fixedwidth_font";
@@ -112,15 +111,13 @@ public class Prefs extends K9PreferenceActivity
- public static void actionPrefs(Context context)
- {
+ public static void actionPrefs(Context context) {
Intent i = new Intent(context, Prefs.class);
context.startActivity(i);
}
@Override
- public void onCreate(Bundle savedInstanceState)
- {
+ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.global_preferences);
@@ -130,10 +127,8 @@ public class Prefs extends K9PreferenceActivity
Vector entryValueVector = new Vector(Arrays.asList(mLanguage.getEntryValues()));
String supportedLanguages[] = getResources().getStringArray(R.array.supported_languages);
HashSet supportedLanguageSet = new HashSet(Arrays.asList(supportedLanguages));
- for (int i = entryVector.size() - 1; i > -1; --i)
- {
- if (!supportedLanguageSet.contains(entryValueVector.get(i)))
- {
+ for (int i = entryVector.size() - 1; i > -1; --i) {
+ if (!supportedLanguageSet.contains(entryValueVector.get(i))) {
entryVector.remove(i);
entryValueVector.remove(i);
}
@@ -146,10 +141,8 @@ public class Prefs extends K9PreferenceActivity
mTheme = setupListPreference(PREFERENCE_THEME, theme);
findPreference(PREFERENCE_FONT_SIZE).setOnPreferenceClickListener(
- new Preference.OnPreferenceClickListener()
- {
- public boolean onPreferenceClick(Preference preference)
- {
+ new Preference.OnPreferenceClickListener() {
+ public boolean onPreferenceClick(Preference preference) {
onFontSizeSettings();
return true;
}
@@ -159,8 +152,7 @@ public class Prefs extends K9PreferenceActivity
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++)
- {
+ for (int i = 0 ; i < formats.length; i++) {
String format = formats[i];
entries[i] = DateFormatter.getSampleDate(this, format);
values[i] = format;
@@ -172,7 +164,7 @@ public class Prefs extends K9PreferenceActivity
mGestures = (CheckBoxPreference)findPreference(PREFERENCE_GESTURES);
mGestures.setChecked(K9.gesturesEnabled());
-
+
compactLayouts = (CheckBoxPreference)findPreference(PREFERENCE_COMPACT_LAYOUTS);
compactLayouts.setChecked(K9.useCompactLayouts());
@@ -219,26 +211,18 @@ public class Prefs extends K9PreferenceActivity
mChangeContactNameColor = (CheckBoxPreference)findPreference(PREFERENCE_MESSAGELIST_CONTACT_NAME_COLOR);
mChangeContactNameColor.setChecked(K9.changeContactNameColor());
- if (K9.changeContactNameColor())
- {
+ if (K9.changeContactNameColor()) {
mChangeContactNameColor.setSummary(R.string.global_settings_registered_name_color_changed);
- }
- else
- {
+ } else {
mChangeContactNameColor.setSummary(R.string.global_settings_registered_name_color_default);
}
- mChangeContactNameColor.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
- {
- public boolean onPreferenceChange(Preference preference, Object newValue)
- {
+ mChangeContactNameColor.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
final Boolean checked = (Boolean) newValue;
- if (checked)
- {
+ if (checked) {
onChooseContactNameColor();
mChangeContactNameColor.setSummary(R.string.global_settings_registered_name_color_changed);
- }
- else
- {
+ } else {
mChangeContactNameColor.setSummary(R.string.global_settings_registered_name_color_default);
}
mChangeContactNameColor.setChecked(checked);
@@ -256,8 +240,7 @@ public class Prefs extends K9PreferenceActivity
mZoomControlsEnabled.setChecked(K9.zoomControlsEnabled());
mMobileOptimizedLayout = (CheckBoxPreference) findPreference(PREFERENCE_MESSAGEVIEW_MOBILE_LAYOUT);
- if (Integer.parseInt(Build.VERSION.SDK) <= 7 )
- {
+ if (Integer.parseInt(Build.VERSION.SDK) <= 7) {
mMobileOptimizedLayout.setEnabled(false);
}
@@ -270,10 +253,8 @@ public class Prefs extends K9PreferenceActivity
mQuietTimeStarts = (TimePickerPreference) findPreference(PREFERENCE_QUIET_TIME_STARTS);
mQuietTimeStarts.setDefaultValue(K9.getQuietTimeStarts());
mQuietTimeStarts.setSummary(K9.getQuietTimeStarts());
- mQuietTimeStarts.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
- {
- public boolean onPreferenceChange(Preference preference, Object newValue)
- {
+ mQuietTimeStarts.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
final String time = (String) newValue;
mQuietTimeStarts.setSummary(time);
return false;
@@ -283,10 +264,8 @@ public class Prefs extends K9PreferenceActivity
mQuietTimeEnds = (TimePickerPreference) findPreference(PREFERENCE_QUIET_TIME_ENDS);
mQuietTimeEnds.setSummary(K9.getQuietTimeEnds());
mQuietTimeEnds.setDefaultValue(K9.getQuietTimeEnds());
- mQuietTimeEnds.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
- {
- public boolean onPreferenceChange(Preference preference, Object newValue)
- {
+ mQuietTimeEnds.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
final String time = (String) newValue;
mQuietTimeEnds.setSummary(time);
return false;
@@ -308,8 +287,7 @@ public class Prefs extends K9PreferenceActivity
mSensitiveLogging.setChecked(K9.DEBUG_SENSITIVE);
}
- private void saveSettings()
- {
+ private void saveSettings() {
SharedPreferences preferences = Preferences.getPreferences(this).getPreferences();
K9.setK9Language(mLanguage.getValue());
@@ -346,8 +324,7 @@ public class Prefs extends K9PreferenceActivity
boolean needsRefresh = K9.setBackgroundOps(mBackgroundOps.getValue());
K9.setUseGalleryBugWorkaround(mUseGalleryBugWorkaround.isChecked());
- if (!K9.DEBUG && mDebugLogging.isChecked())
- {
+ if (!K9.DEBUG && mDebugLogging.isChecked()) {
Toast.makeText(this, R.string.debug_logging_enabled, Toast.LENGTH_LONG).show();
}
K9.DEBUG = mDebugLogging.isChecked();
@@ -358,20 +335,16 @@ public class Prefs extends K9PreferenceActivity
DateFormatter.setDateFormat(editor, mDateFormat.getValue());
editor.commit();
- if (needsRefresh)
- {
+ if (needsRefresh) {
MailService.actionReset(this, null);
}
}
@Override
- public boolean onKeyDown(int keyCode, KeyEvent event)
- {
- if (keyCode == KeyEvent.KEYCODE_BACK)
- {
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ if (keyCode == KeyEvent.KEYCODE_BACK) {
saveSettings();
- if (K9.manageBack())
- {
+ if (K9.manageBack()) {
Accounts.listAccounts(this);
finish();
return true;
@@ -380,17 +353,13 @@ public class Prefs extends K9PreferenceActivity
return super.onKeyDown(keyCode, event);
}
- private void onFontSizeSettings()
- {
+ private void onFontSizeSettings() {
FontSizeSettings.actionEditSettings(this);
}
- private void onChooseContactNameColor()
- {
- new ColorPickerDialog(this, new ColorPickerDialog.OnColorChangedListener()
- {
- public void colorChanged(int color)
- {
+ private void onChooseContactNameColor() {
+ new ColorPickerDialog(this, new ColorPickerDialog.OnColorChangedListener() {
+ public void colorChanged(int color) {
K9.setContactNameColor(color);
}
},
diff --git a/src/com/fsck/k9/activity/setup/SpinnerHelper.java b/src/com/fsck/k9/activity/setup/SpinnerHelper.java
index 1d5431ed2..bcf70e1fc 100644
--- a/src/com/fsck/k9/activity/setup/SpinnerHelper.java
+++ b/src/com/fsck/k9/activity/setup/SpinnerHelper.java
@@ -7,29 +7,23 @@ import android.content.Context;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
-public class SpinnerHelper
-{
- public static void initSpinner(Context context, Spinner spinner, int entryRes, int valueRes, String curVal)
- {
+public class SpinnerHelper {
+ public static void initSpinner(Context context, Spinner spinner, int entryRes, int valueRes, String curVal) {
String[] entryArray = context.getResources().getStringArray(entryRes);
String[] valueArray = context.getResources().getStringArray(valueRes);
initSpinner(context, spinner, entryArray, valueArray, curVal);
}
- public static void initSpinner(Context context, Spinner spinner, String[] entryArray, String[] valueArray, String curVal)
- {
+ public static void initSpinner(Context context, Spinner spinner, String[] entryArray, String[] valueArray, String curVal) {
- if (entryArray.length != valueArray.length)
- {
+ if (entryArray.length != valueArray.length) {
throw new RuntimeException("Entry and value arrays are of unequal lenght");
}
EntryValue[] entryValues = new EntryValue[entryArray.length];
int curSelection = 0;
- for (int i = 0; i < entryArray.length; i++)
- {
+ for (int i = 0; i < entryArray.length; i++) {
entryValues[i] = new EntryValue(entryArray[i], valueArray[i]);
- if (valueArray[i].equals(curVal))
- {
+ if (valueArray[i].equals(curVal)) {
curSelection = i;
}
}
@@ -40,50 +34,37 @@ public class SpinnerHelper
spinner.setSelection(curSelection);
}
- public static String getSpinnerValue(Spinner spinner)
- {
+ public static String getSpinnerValue(Spinner spinner) {
EntryValue entryValue = (EntryValue)spinner.getSelectedItem();
- if (entryValue != null)
- {
+ if (entryValue != null) {
return entryValue.getValue();
- }
- else
- {
+ } else {
return null;
}
}
- public static String getSpinnerEntry(Spinner spinner)
- {
+ public static String getSpinnerEntry(Spinner spinner) {
EntryValue entryValue = (EntryValue)spinner.getSelectedItem();
- if (entryValue != null)
- {
+ if (entryValue != null) {
return entryValue.getEntry();
- }
- else
- {
+ } else {
return null;
}
}
- private static class EntryValue
- {
+ private static class EntryValue {
final String entry;
final String value;
- EntryValue(String entry, String value)
- {
+ EntryValue(String entry, String value) {
this.entry = entry;
this.value = value;
}
@Override
- public String toString()
- {
+ public String toString() {
return entry;
}
- public String getEntry()
- {
+ public String getEntry() {
return entry;
}
- public String getValue()
- {
+ public String getValue() {
return value;
}
}
diff --git a/src/com/fsck/k9/activity/setup/SpinnerOption.java b/src/com/fsck/k9/activity/setup/SpinnerOption.java
index 10a6c04c6..89275b974 100644
--- a/src/com/fsck/k9/activity/setup/SpinnerOption.java
+++ b/src/com/fsck/k9/activity/setup/SpinnerOption.java
@@ -6,34 +6,28 @@ package com.fsck.k9.activity.setup;
import android.widget.Spinner;
-public class SpinnerOption
-{
+public class SpinnerOption {
public Object value;
public String label;
- public static void setSpinnerOptionValue(Spinner spinner, Object value)
- {
- for (int i = 0, count = spinner.getCount(); i < count; i++)
- {
+ public static void setSpinnerOptionValue(Spinner spinner, Object value) {
+ for (int i = 0, count = spinner.getCount(); i < count; i++) {
SpinnerOption so = (SpinnerOption)spinner.getItemAtPosition(i);
- if (so.value.equals(value))
- {
+ if (so.value.equals(value)) {
spinner.setSelection(i, true);
return;
}
}
}
- public SpinnerOption(Object value, String label)
- {
+ public SpinnerOption(Object value, String label) {
this.value = value;
this.label = label;
}
@Override
- public String toString()
- {
+ public String toString() {
return label;
}
}
diff --git a/src/com/fsck/k9/controller/MessageDateComparator.java b/src/com/fsck/k9/controller/MessageDateComparator.java
index 6b652bfea..ec45ce130 100644
--- a/src/com/fsck/k9/controller/MessageDateComparator.java
+++ b/src/com/fsck/k9/controller/MessageDateComparator.java
@@ -4,25 +4,16 @@ package com.fsck.k9.controller;
import java.util.Comparator;
import com.fsck.k9.mail.Message;
-public class MessageDateComparator implements Comparator
-{
- public int compare(Message o1, Message o2)
- {
- try
- {
- if (o1.getSentDate() == null)
- {
+public class MessageDateComparator implements Comparator {
+ public int compare(Message o1, Message o2) {
+ try {
+ if (o1.getSentDate() == null) {
return 1;
- }
- else if (o2.getSentDate() == null)
- {
+ } else if (o2.getSentDate() == null) {
return -1;
- }
- else
+ } else
return o2.getSentDate().compareTo(o1.getSentDate());
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
return 0;
}
}
diff --git a/src/com/fsck/k9/controller/MessageRemovalListener.java b/src/com/fsck/k9/controller/MessageRemovalListener.java
index efb018cfe..38973dde4 100644
--- a/src/com/fsck/k9/controller/MessageRemovalListener.java
+++ b/src/com/fsck/k9/controller/MessageRemovalListener.java
@@ -2,7 +2,6 @@ package com.fsck.k9.controller;
import com.fsck.k9.mail.Message;
-public interface MessageRemovalListener
-{
+public interface MessageRemovalListener {
public void messageRemoved(Message message);
}
diff --git a/src/com/fsck/k9/controller/MessageRetrievalListener.java b/src/com/fsck/k9/controller/MessageRetrievalListener.java
index 17c9699a5..24ecb52e2 100644
--- a/src/com/fsck/k9/controller/MessageRetrievalListener.java
+++ b/src/com/fsck/k9/controller/MessageRetrievalListener.java
@@ -3,8 +3,7 @@ package com.fsck.k9.controller;
import com.fsck.k9.mail.Message;
-public interface MessageRetrievalListener
-{
+public interface MessageRetrievalListener {
public void messageStarted(String uid, int number, int ofTotal);
public void messageFinished(Message message, int number, int ofTotal);
diff --git a/src/com/fsck/k9/controller/MessagingController.java b/src/com/fsck/k9/controller/MessagingController.java
index e8f063bb1..bb116ac63 100644
--- a/src/com/fsck/k9/controller/MessagingController.java
+++ b/src/com/fsck/k9/controller/MessagingController.java
@@ -76,8 +76,7 @@ import com.fsck.k9.mail.store.LocalStore.PendingCommand;
* it removes itself. Thus, any commands that that activity submitted are
* removed from the queue once the activity is no longer active.
*/
-public class MessagingController implements Runnable
-{
+public class MessagingController implements Runnable {
/**
* Immutable empty {@link String} array
@@ -141,8 +140,7 @@ public class MessagingController implements Runnable
private final ExecutorService threadPool = Executors.newCachedThreadPool();
- public enum SORT_TYPE
- {
+ public enum SORT_TYPE {
SORT_DATE(R.string.sort_earliest_first, R.string.sort_latest_first, false),
SORT_SUBJECT(R.string.sort_subject_alpha, R.string.sort_subject_re_alpha, true),
SORT_SENDER(R.string.sort_sender_alpha, R.string.sort_sender_re_alpha, true),
@@ -154,26 +152,20 @@ public class MessagingController implements Runnable
private int descendingToast;
private boolean defaultAscending;
- SORT_TYPE(int ascending, int descending, boolean ndefaultAscending)
- {
+ SORT_TYPE(int ascending, int descending, boolean ndefaultAscending) {
ascendingToast = ascending;
descendingToast = descending;
defaultAscending = ndefaultAscending;
}
- public int getToast(boolean ascending)
- {
- if (ascending)
- {
+ public int getToast(boolean ascending) {
+ if (ascending) {
return ascendingToast;
- }
- else
- {
+ } else {
return descendingToast;
}
}
- public boolean isDefaultAscending()
- {
+ public boolean isDefaultAscending() {
return defaultAscending;
}
}
@@ -194,31 +186,25 @@ public class MessagingController implements Runnable
// Key is accountUuid:folderName:messageUid , value is unimportant
private ConcurrentHashMap deletedUids = new ConcurrentHashMap();
- private String createMessageKey(Account account, String folder, Message message)
- {
+ private String createMessageKey(Account account, String folder, Message message) {
return createMessageKey(account, folder, message.getUid());
}
- private String createMessageKey(Account account, String folder, String uid)
- {
+ private String createMessageKey(Account account, String folder, String uid) {
return account.getUuid() + ":" + folder + ":" + uid;
}
- private void suppressMessage(Account account, String folder, Message message)
- {
+ private void suppressMessage(Account account, String folder, Message message) {
- if (account == null || folder == null || message == null)
- {
+ if (account == null || folder == null || message == null) {
return;
}
String messKey = createMessageKey(account, folder, message);
deletedUids.put(messKey, "true");
}
- private void unsuppressMessage(Account account, String folder, String uid)
- {
- if (account == null || folder == null || uid == null)
- {
+ private void unsuppressMessage(Account account, String folder, String uid) {
+ if (account == null || folder == null || uid == null) {
return;
}
String messKey = createMessageKey(account, folder, uid);
@@ -226,16 +212,13 @@ public class MessagingController implements Runnable
}
- private boolean isMessageSuppressed(Account account, String folder, Message message)
- {
- if (account == null || folder == null || message == null)
- {
+ private boolean isMessageSuppressed(Account account, String folder, Message message) {
+ if (account == null || folder == null || message == null) {
return false;
}
String messKey = createMessageKey(account, folder, message);
- if (deletedUids.containsKey(messKey))
- {
+ if (deletedUids.containsKey(messKey)) {
return true;
}
@@ -245,14 +228,12 @@ public class MessagingController implements Runnable
/**
* @param application {@link K9}
*/
- private MessagingController(Application application)
- {
+ private MessagingController(Application application) {
mApplication = application;
mThread = new Thread(this);
mThread.setName("MessagingController");
mThread.start();
- if (memorizingListener != null)
- {
+ if (memorizingListener != null) {
addListener(memorizingListener);
}
}
@@ -263,58 +244,43 @@ public class MessagingController implements Runnable
* @param application {@link K9}
* @return
*/
- public synchronized static MessagingController getInstance(Application application)
- {
- if (inst == null)
- {
+ public synchronized static MessagingController getInstance(Application application) {
+ if (inst == null) {
inst = new MessagingController(application);
}
return inst;
}
- public boolean isBusy()
- {
+ public boolean isBusy() {
return mBusy;
}
@Override
- public void run()
- {
+ public void run() {
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
- while (true)
- {
+ while (true) {
String commandDescription = null;
- try
- {
+ try {
final Command command = mCommands.take();
- if (command != null)
- {
+ if (command != null) {
commandDescription = command.description;
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "Running " + (command.isForeground ? "Foreground" : "Background") + " command '" + command.description + "', seq = " + command.sequence);
mBusy = true;
- try
- {
+ try {
command.runnable.run();
- }
- catch (UnavailableAccountException e)
- {
+ } catch (UnavailableAccountException e) {
// retry later
- new Thread()
- {
+ new Thread() {
@Override
- public void run()
- {
- try
- {
+ public void run() {
+ try {
sleep(30 * 1000);
mCommands.put(command);
- }
- catch (InterruptedException e)
- {
+ } catch (InterruptedException e) {
Log.e(K9.LOG_TAG, "interrupted while putting a pending command for"
+ " an unavailable account back into the queue."
+ " THIS SHOULD NEVER HAPPEN.");
@@ -327,38 +293,30 @@ public class MessagingController implements Runnable
Log.i(K9.LOG_TAG, (command.isForeground ? "Foreground" : "Background") +
" Command '" + command.description + "' completed");
- for (MessagingListener l : getListeners(command.listener))
- {
+ for (MessagingListener l : getListeners(command.listener)) {
l.controllerCommandCompleted(mCommands.size() > 0);
}
}
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
Log.e(K9.LOG_TAG, "Error running command '" + commandDescription + "'", e);
}
mBusy = false;
}
}
- private void put(String description, MessagingListener listener, Runnable runnable)
- {
+ private void put(String description, MessagingListener listener, Runnable runnable) {
putCommand(mCommands, description, listener, runnable, true);
}
- private void putBackground(String description, MessagingListener listener, Runnable runnable)
- {
+ private void putBackground(String description, MessagingListener listener, Runnable runnable) {
putCommand(mCommands, description, listener, runnable, false);
}
- private void putCommand(BlockingQueue queue, String description, MessagingListener listener, Runnable runnable, boolean isForeground)
- {
+ private void putCommand(BlockingQueue queue, String description, MessagingListener listener, Runnable runnable, boolean isForeground) {
int retries = 10;
Exception e = null;
- while (retries-- > 0)
- {
- try
- {
+ while (retries-- > 0) {
+ try {
Command command = new Command();
command.listener = listener;
command.runnable = runnable;
@@ -366,15 +324,10 @@ public class MessagingController implements Runnable
command.isForeground = isForeground;
queue.put(command);
return;
- }
- catch (InterruptedException ie)
- {
- try
- {
+ } catch (InterruptedException ie) {
+ try {
Thread.sleep(200);
- }
- catch (InterruptedException ne)
- {
+ } catch (InterruptedException ne) {
}
e = ie;
}
@@ -383,35 +336,28 @@ public class MessagingController implements Runnable
}
- public void addListener(MessagingListener listener)
- {
+ public void addListener(MessagingListener listener) {
mListeners.add(listener);
refreshListener(listener);
}
- public void refreshListener(MessagingListener listener)
- {
- if (memorizingListener != null && listener != null)
- {
+ public void refreshListener(MessagingListener listener) {
+ if (memorizingListener != null && listener != null) {
memorizingListener.refreshOther(listener);
}
}
- public void removeListener(MessagingListener listener)
- {
+ public void removeListener(MessagingListener listener) {
mListeners.remove(listener);
}
- public Set getListeners()
- {
+ public Set getListeners() {
return mListeners;
}
- public Set getListeners(MessagingListener listener)
- {
- if (listener == null)
- {
+ public Set getListeners(MessagingListener listener) {
+ if (listener == null) {
return mListeners;
}
@@ -434,13 +380,10 @@ public class MessagingController implements Runnable
* @param listener
* @throws MessagingException
*/
- public void listFolders(final Account account, final boolean refreshRemote, final MessagingListener listener)
- {
- threadPool.execute(new Runnable()
- {
+ public void listFolders(final Account account, final boolean refreshRemote, final MessagingListener listener) {
+ threadPool.execute(new Runnable() {
@Override
- public void run()
- {
+ public void run() {
listFoldersSynchronous(account, refreshRemote, listener);
}
});
@@ -458,78 +401,58 @@ public class MessagingController implements Runnable
* @param listener
* @throws MessagingException
*/
- public void listFoldersSynchronous(final Account account, final boolean refreshRemote, final MessagingListener listener)
- {
- for (MessagingListener l : getListeners(listener))
- {
+ public void listFoldersSynchronous(final Account account, final boolean refreshRemote, final MessagingListener listener) {
+ for (MessagingListener l : getListeners(listener)) {
l.listFoldersStarted(account);
}
- List extends Folder> localFolders = null;
- if (!account.isAvailable(mApplication))
- {
+ List extends Folder > localFolders = null;
+ if (!account.isAvailable(mApplication)) {
Log.i(K9.LOG_TAG, "not listing folders of unavailable account");
- }
- else
- {
- try
- {
+ } else {
+ try {
Store localStore = account.getLocalStore();
localFolders = localStore.getPersonalNamespaces(false);
Folder[] folderArray = localFolders.toArray(EMPTY_FOLDER_ARRAY);
- if (refreshRemote || localFolders.size() == 0)
- {
+ if (refreshRemote || localFolders.size() == 0) {
doRefreshRemote(account, listener);
return;
}
- for (MessagingListener l : getListeners(listener))
- {
+ for (MessagingListener l : getListeners(listener)) {
l.listFolders(account, folderArray);
}
- }
- catch (Exception e)
- {
- for (MessagingListener l : getListeners(listener))
- {
+ } catch (Exception e) {
+ for (MessagingListener l : getListeners(listener)) {
l.listFoldersFailed(account, e.getMessage());
}
addErrorMessage(account, null, e);
return;
- }
- finally
- {
- if (localFolders != null)
- {
- for (Folder localFolder : localFolders)
- {
+ } finally {
+ if (localFolders != null) {
+ for (Folder localFolder : localFolders) {
closeFolder(localFolder);
}
}
}
}
- for (MessagingListener l : getListeners(listener))
- {
+ for (MessagingListener l : getListeners(listener)) {
l.listFoldersFinished(account);
}
}
- private void doRefreshRemote(final Account account, MessagingListener listener)
- {
- put("doRefreshRemote", listener, new Runnable()
- {
+ private void doRefreshRemote(final Account account, MessagingListener listener) {
+ put("doRefreshRemote", listener, new Runnable() {
@Override
- public void run()
- {
- List extends Folder> localFolders = null;
- try
- {
+ public void run() {
+ List extends Folder > localFolders = null;
+ try {
Store store = account.getRemoteStore();
- List extends Folder> remoteFolders = store.getPersonalNamespaces(false);
+ List extends Folder > remoteFolders = store.getPersonalNamespaces(false);
LocalStore localStore = account.getLocalStore();
HashSet remoteFolderNames = new HashSet();
@@ -537,14 +460,11 @@ public class MessagingController implements Runnable
localFolders = localStore.getPersonalNamespaces(false);
HashSet localFolderNames = new HashSet();
- for (Folder localFolder : localFolders)
- {
+ for (Folder localFolder : localFolders) {
localFolderNames.add(localFolder.getName());
}
- for (Folder remoteFolder : remoteFolders)
- {
- if (localFolderNames.contains(remoteFolder.getName()) == false)
- {
+ for (Folder remoteFolder : remoteFolders) {
+ if (localFolderNames.contains(remoteFolder.getName()) == false) {
LocalFolder localFolder = localStore.getFolder(remoteFolder.getName());
foldersToCreate.add(localFolder);
}
@@ -557,11 +477,9 @@ public class MessagingController implements Runnable
/*
* Clear out any folders that are no longer on the remote store.
*/
- for (Folder localFolder : localFolders)
- {
+ for (Folder localFolder : localFolders) {
String localFolderName = localFolder.getName();
- if (!account.isSpecialFolder(localFolderName) && !remoteFolderNames.contains(localFolderName))
- {
+ if (!account.isSpecialFolder(localFolderName) && !remoteFolderNames.contains(localFolderName)) {
localFolder.delete(false);
}
}
@@ -569,29 +487,20 @@ public class MessagingController implements Runnable
localFolders = localStore.getPersonalNamespaces(false);
Folder[] folderArray = localFolders.toArray(EMPTY_FOLDER_ARRAY);
- for (MessagingListener l : getListeners())
- {
+ for (MessagingListener l : getListeners()) {
l.listFolders(account, folderArray);
}
- for (MessagingListener l : getListeners())
- {
+ for (MessagingListener l : getListeners()) {
l.listFoldersFinished(account);
}
- }
- catch (Exception e)
- {
- for (MessagingListener l : getListeners())
- {
+ } catch (Exception e) {
+ for (MessagingListener l : getListeners()) {
l.listFoldersFailed(account, "");
}
addErrorMessage(account, null, e);
- }
- finally
- {
- if (localFolders != null)
- {
- for (Folder localFolder : localFolders)
- {
+ } finally {
+ if (localFolders != null) {
+ for (Folder localFolder : localFolders) {
closeFolder(localFolder);
}
}
@@ -610,13 +519,10 @@ public class MessagingController implements Runnable
* @param listener
* @throws MessagingException
*/
- public void listLocalMessages(final Account account, final String folder, final MessagingListener listener)
- {
- threadPool.execute(new Runnable()
- {
+ public void listLocalMessages(final Account account, final String folder, final MessagingListener listener) {
+ threadPool.execute(new Runnable() {
@Override
- public void run()
- {
+ public void run() {
listLocalMessagesSynchronous(account, folder, listener);
}
});
@@ -631,18 +537,15 @@ public class MessagingController implements Runnable
* @param listener
* @throws MessagingException
*/
- public void listLocalMessagesSynchronous(final Account account, final String folder, final MessagingListener listener)
- {
+ public void listLocalMessagesSynchronous(final Account account, final String folder, final MessagingListener listener) {
- for (MessagingListener l : getListeners(listener))
- {
+ for (MessagingListener l : getListeners(listener)) {
l.listLocalMessagesStarted(account, folder);
}
Folder localFolder = null;
MessageRetrievalListener retrievalListener =
- new MessageRetrievalListener()
- {
+ new MessageRetrievalListener() {
List pendingMessages = new ArrayList();
@@ -652,36 +555,27 @@ public class MessagingController implements Runnable
@Override
public void messageStarted(String message, int number, int ofTotal) {}
@Override
- public void messageFinished(Message message, int number, int ofTotal)
- {
+ public void messageFinished(Message message, int number, int ofTotal) {
- if (!isMessageSuppressed(account, folder, message))
- {
+ if (!isMessageSuppressed(account, folder, message)) {
pendingMessages.add(message);
totalDone++;
- if (pendingMessages.size() > 10)
- {
+ if (pendingMessages.size() > 10) {
addPendingMessages();
}
- }
- else
- {
- for (MessagingListener l : getListeners(listener))
- {
+ } else {
+ for (MessagingListener l : getListeners(listener)) {
l.listLocalMessagesRemoveMessage(account, folder, message);
}
}
}
@Override
- public void messagesFinished(int number)
- {
+ public void messagesFinished(int number) {
addPendingMessages();
}
- private void addPendingMessages()
- {
- for (MessagingListener l : getListeners(listener))
- {
+ private void addPendingMessages() {
+ for (MessagingListener l : getListeners(listener)) {
l.listLocalMessagesAddMessages(account, folder, pendingMessages);
}
pendingMessages.clear();
@@ -690,8 +584,7 @@ public class MessagingController implements Runnable
- try
- {
+ try {
Store localStore = account.getLocalStore();
localFolder = localStore.getFolder(folder);
localFolder.open(OpenMode.READ_WRITE);
@@ -703,27 +596,20 @@ public class MessagingController implements Runnable
if (K9.DEBUG)
Log.v(K9.LOG_TAG, "Got ack that callbackRunner finished");
- for (MessagingListener l : getListeners(listener))
- {
+ for (MessagingListener l : getListeners(listener)) {
l.listLocalMessagesFinished(account, folder);
}
- }
- catch (Exception e)
- {
- for (MessagingListener l : getListeners(listener))
- {
+ } catch (Exception e) {
+ for (MessagingListener l : getListeners(listener)) {
l.listLocalMessagesFailed(account, folder, e.getMessage());
}
addErrorMessage(account, null, e);
- }
- finally
- {
+ } finally {
closeFolder(localFolder);
}
}
- public void searchLocalMessages(SearchSpecification searchSpecification, final Message[] messages, final MessagingListener listener)
- {
+ public void searchLocalMessages(SearchSpecification searchSpecification, final Message[] messages, final MessagingListener listener) {
searchLocalMessages(searchSpecification.getAccountUuids(), searchSpecification.getFolderNames(), messages,
searchSpecification.getQuery(), searchSpecification.isIntegrate(), searchSpecification.getRequiredFlags(), searchSpecification.getForbiddenFlags(), listener);
}
@@ -734,10 +620,8 @@ public class MessagingController implements Runnable
* @throws MessagingException
*/
public void searchLocalMessages(final String[] accountUuids, final String[] folderNames, final Message[] messages, final String query, final boolean integrate,
- final Flag[] requiredFlags, final Flag[] forbiddenFlags, final MessagingListener listener)
- {
- if (K9.DEBUG)
- {
+ final Flag[] requiredFlags, final Flag[] forbiddenFlags, final MessagingListener listener) {
+ if (K9.DEBUG) {
Log.i(K9.LOG_TAG, "searchLocalMessages ("
+ "accountUuids=" + Utility.combine(accountUuids, ',')
+ ", folderNames = " + Utility.combine(folderNames, ',')
@@ -749,22 +633,18 @@ public class MessagingController implements Runnable
+ ")");
}
- threadPool.execute(new Runnable()
- {
+ threadPool.execute(new Runnable() {
@Override
- public void run()
- {
- searchLocalMessagesSynchronous(accountUuids,folderNames, messages, query, integrate, requiredFlags, forbiddenFlags, listener);
+ public void run() {
+ searchLocalMessagesSynchronous(accountUuids, folderNames, messages, query, integrate, requiredFlags, forbiddenFlags, listener);
}
});
}
- public void searchLocalMessagesSynchronous(final String[] accountUuids, final String[] folderNames, final Message[] messages, final String query, final boolean integrate, final Flag[] requiredFlags, final Flag[] forbiddenFlags, final MessagingListener listener)
- {
+ public void searchLocalMessagesSynchronous(final String[] accountUuids, final String[] folderNames, final Message[] messages, final String query, final boolean integrate, final Flag[] requiredFlags, final Flag[] forbiddenFlags, final MessagingListener listener) {
final AccountStats stats = new AccountStats();
final Set accountUuidsSet = new HashSet();
- if (accountUuids != null)
- {
+ if (accountUuids != null) {
accountUuidsSet.addAll(Arrays.asList(accountUuids));
}
final Preferences prefs = Preferences.getPreferences(mApplication.getApplicationContext());
@@ -772,84 +652,64 @@ public class MessagingController implements Runnable
List foldersToSearch = null;
boolean displayableOnly = false;
boolean noSpecialFolders = true;
- for (final Account account : accounts)
- {
- if (!account.isAvailable(mApplication))
- {
+ for (final Account account : accounts) {
+ if (!account.isAvailable(mApplication)) {
Log.d(K9.LOG_TAG, "searchLocalMessagesSynchronous() ignores account that is not available");
continue;
}
- if (accountUuids != null && !accountUuidsSet.contains(account.getUuid()))
- {
+ if (accountUuids != null && !accountUuidsSet.contains(account.getUuid())) {
continue;
}
- if (accountUuids != null && accountUuidsSet.contains(account.getUuid()))
- {
+ if (accountUuids != null && accountUuidsSet.contains(account.getUuid())) {
displayableOnly = true;
noSpecialFolders = true;
- }
- else if (!integrate && folderNames == null)
- {
+ } else if (!integrate && folderNames == null) {
Account.Searchable searchableFolders = account.getSearchableFolders();
- switch (searchableFolders)
- {
- case NONE:
- continue;
- case DISPLAYABLE:
- displayableOnly = true;
- break;
+ switch (searchableFolders) {
+ case NONE:
+ continue;
+ case DISPLAYABLE:
+ displayableOnly = true;
+ break;
}
}
List messagesToSearch = null;
- if (messages != null)
- {
+ if (messages != null) {
messagesToSearch = new LinkedList();
- for (Message message : messages)
- {
- if (message.getFolder().getAccount().getUuid().equals(account.getUuid()))
- {
+ for (Message message : messages) {
+ if (message.getFolder().getAccount().getUuid().equals(account.getUuid())) {
messagesToSearch.add(message);
}
}
- if (messagesToSearch.isEmpty())
- {
+ if (messagesToSearch.isEmpty()) {
continue;
}
}
- if (listener != null)
- {
+ if (listener != null) {
listener.listLocalMessagesStarted(account, null);
}
- if (integrate || displayableOnly || folderNames != null || noSpecialFolders)
- {
+ if (integrate || displayableOnly || folderNames != null || noSpecialFolders) {
List tmpFoldersToSearch = new LinkedList();
- try
- {
+ try {
LocalStore store = account.getLocalStore();
- List extends Folder> folders = store.getPersonalNamespaces(false);
+ List extends Folder > folders = store.getPersonalNamespaces(false);
Set folderNameSet = null;
- if (folderNames != null)
- {
+ if (folderNames != null) {
folderNameSet = new HashSet();
folderNameSet.addAll(Arrays.asList(folderNames));
}
- for (Folder folder : folders)
- {
+ for (Folder folder : folders) {
LocalFolder localFolder = (LocalFolder)folder;
boolean include = true;
folder.refresh(prefs);
String localFolderName = localFolder.getName();
- if (integrate)
- {
+ if (integrate) {
include = localFolder.isIntegrate();
- }
- else
- {
- if (folderNameSet != null)
- {
+ } else {
+ if (folderNameSet != null) {
if (!folderNameSet.contains(localFolderName))
{
@@ -858,118 +718,91 @@ public class MessagingController implements Runnable
}
// Never exclude the INBOX (see issue 1817)
else if (noSpecialFolders && !localFolderName.equalsIgnoreCase(K9.INBOX) &&
- !localFolderName.equals(account.getArchiveFolderName()) && account.isSpecialFolder(localFolderName))
- {
+ !localFolderName.equals(account.getArchiveFolderName()) && account.isSpecialFolder(localFolderName)) {
include = false;
- }
- else if (displayableOnly && modeMismatch(account.getFolderDisplayMode(), folder.getDisplayClass()))
- {
+ } else if (displayableOnly && modeMismatch(account.getFolderDisplayMode(), folder.getDisplayClass())) {
include = false;
}
}
- if (include)
- {
+ if (include) {
tmpFoldersToSearch.add(localFolder);
}
}
- if (tmpFoldersToSearch.size() < 1)
- {
+ if (tmpFoldersToSearch.size() < 1) {
continue;
}
foldersToSearch = tmpFoldersToSearch;
- }
- catch (MessagingException me)
- {
+ } catch (MessagingException me) {
Log.e(K9.LOG_TAG, "Unable to restrict search folders in Account " + account.getDescription() + ", searching all", me);
addErrorMessage(account, null, me);
}
}
- MessageRetrievalListener retrievalListener = new MessageRetrievalListener()
- {
+ MessageRetrievalListener retrievalListener = new MessageRetrievalListener() {
@Override
public void messageStarted(String message, int number, int ofTotal) {}
@Override
- public void messageFinished(Message message, int number, int ofTotal)
- {
- if (!isMessageSuppressed(message.getFolder().getAccount(), message.getFolder().getName(), message))
- {
+ public void messageFinished(Message message, int number, int ofTotal) {
+ if (!isMessageSuppressed(message.getFolder().getAccount(), message.getFolder().getName(), message)) {
List messages = new ArrayList();
messages.add(message);
stats.unreadMessageCount += (!message.isSet(Flag.SEEN)) ? 1 : 0;
stats.flaggedMessageCount += (message.isSet(Flag.FLAGGED)) ? 1 : 0;
- if (listener != null)
- {
+ if (listener != null) {
listener.listLocalMessagesAddMessages(account, null, messages);
}
}
}
@Override
- public void messagesFinished(int number)
- {
+ public void messagesFinished(int number) {
}
};
- try
- {
- String[] queryFields = {"html_content","subject","sender_list"};
+ try {
+ String[] queryFields = {"html_content", "subject", "sender_list"};
LocalStore localStore = account.getLocalStore();
localStore.searchForMessages(retrievalListener, queryFields
, query, foldersToSearch,
messagesToSearch == null ? null : messagesToSearch.toArray(EMPTY_MESSAGE_ARRAY),
requiredFlags, forbiddenFlags);
- }
- catch (Exception e)
- {
- if (listener != null)
- {
+ } catch (Exception e) {
+ if (listener != null) {
listener.listLocalMessagesFailed(account, null, e.getMessage());
}
addErrorMessage(account, null, e);
- }
- finally
- {
- if (listener != null)
- {
+ } finally {
+ if (listener != null) {
listener.listLocalMessagesFinished(account, null);
}
}
}
- if (listener != null)
- {
+ if (listener != null) {
listener.searchStats(stats);
}
}
- public void loadMoreMessages(Account account, String folder, MessagingListener listener)
- {
- try
- {
+ public void loadMoreMessages(Account account, String folder, MessagingListener listener) {
+ try {
LocalStore localStore = account.getLocalStore();
LocalFolder localFolder = localStore.getFolder(folder);
- if (localFolder.getVisibleLimit() > 0 )
- {
+ if (localFolder.getVisibleLimit() > 0) {
localFolder.setVisibleLimit(localFolder.getVisibleLimit() + account.getDisplayCount());
}
synchronizeMailbox(account, folder, listener, null);
- }
- catch (MessagingException me)
- {
+ } catch (MessagingException me) {
addErrorMessage(account, null, me);
throw new RuntimeException("Unable to set visible limit on folder", me);
}
}
- public void resetVisibleLimits(Collection accounts)
- {
- for (Account account : accounts)
- {
+ public void resetVisibleLimits(Collection accounts) {
+ for (Account account : accounts) {
account.resetVisibleLimits();
}
}
@@ -981,13 +814,10 @@ public class MessagingController implements Runnable
* @param listener
* @param providedRemoteFolder TODO
*/
- public void synchronizeMailbox(final Account account, final String folder, final MessagingListener listener, final Folder providedRemoteFolder)
- {
- putBackground("synchronizeMailbox", listener, new Runnable()
- {
+ public void synchronizeMailbox(final Account account, final String folder, final MessagingListener listener, final Folder providedRemoteFolder) {
+ putBackground("synchronizeMailbox", listener, new Runnable() {
@Override
- public void run()
- {
+ public void run() {
synchronizeMailboxSynchronous(account, folder, listener, providedRemoteFolder);
}
});
@@ -1002,25 +832,21 @@ public class MessagingController implements Runnable
* TODO Break this method up into smaller chunks.
* @param providedRemoteFolder TODO
*/
- private void synchronizeMailboxSynchronous(final Account account, final String folder, final MessagingListener listener, Folder providedRemoteFolder)
- {
+ private void synchronizeMailboxSynchronous(final Account account, final String folder, final MessagingListener listener, Folder providedRemoteFolder) {
Folder remoteFolder = null;
LocalFolder tLocalFolder = null;
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "Synchronizing folder " + account.getDescription() + ":" + folder);
- for (MessagingListener l : getListeners(listener))
- {
+ for (MessagingListener l : getListeners(listener)) {
l.synchronizeMailboxStarted(account, folder);
}
/*
* We don't ever sync the Outbox or errors folder
*/
- if (folder.equals(account.getOutboxFolderName()) || folder.equals(account.getErrorFolderName()))
- {
- for (MessagingListener l : getListeners(listener))
- {
+ if (folder.equals(account.getOutboxFolderName()) || folder.equals(account.getErrorFolderName())) {
+ for (MessagingListener l : getListeners(listener)) {
l.synchronizeMailboxFinished(account, folder, 0, 0);
}
@@ -1028,17 +854,13 @@ public class MessagingController implements Runnable
}
Exception commandException = null;
- try
- {
+ try {
if (K9.DEBUG)
Log.d(K9.LOG_TAG, "SYNC: About to process pending commands for account " + account.getDescription());
- try
- {
+ try {
processPendingCommandsSynchronous(account);
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
addErrorMessage(account, null, e);
Log.e(K9.LOG_TAG, "Failure processing command, but allow message sync attempt", e);
@@ -1059,27 +881,22 @@ public class MessagingController implements Runnable
localFolder.updateLastUid();
Message[] localMessages = localFolder.getMessages(null);
HashMap localUidMap = new HashMap();
- for (Message message : localMessages)
- {
+ for (Message message : localMessages) {
localUidMap.put(message.getUid(), message);
}
- if (providedRemoteFolder != null)
- {
+ if (providedRemoteFolder != null) {
if (K9.DEBUG)
Log.v(K9.LOG_TAG, "SYNC: using providedRemoteFolder " + folder);
remoteFolder = providedRemoteFolder;
- }
- else
- {
+ } else {
Store remoteStore = account.getRemoteStore();
if (K9.DEBUG)
Log.v(K9.LOG_TAG, "SYNC: About to get remote folder " + folder);
remoteFolder = remoteStore.getFolder(folder);
- if (! verifyOrCreateRemoteSpecialFolder(account, folder, remoteFolder, listener))
- {
+ if (! verifyOrCreateRemoteSpecialFolder(account, folder, remoteFolder, listener)) {
return;
}
@@ -1109,8 +926,7 @@ public class MessagingController implements Runnable
Log.v(K9.LOG_TAG, "SYNC: About to open remote folder " + folder);
remoteFolder.open(OpenMode.READ_WRITE);
- if (Account.EXPUNGE_ON_POLL.equals(account.getExpungePolicy()))
- {
+ if (Account.EXPUNGE_ON_POLL.equals(account.getExpungePolicy())) {
if (K9.DEBUG)
Log.d(K9.LOG_TAG, "SYNC: Expunging folder " + account.getDescription() + ":" + folder);
remoteFolder.expunge();
@@ -1125,8 +941,7 @@ public class MessagingController implements Runnable
int visibleLimit = localFolder.getVisibleLimit();
- if (visibleLimit < 0)
- {
+ if (visibleLimit < 0) {
visibleLimit = K9.DEFAULT_VISIBLE_LIMIT;
}
@@ -1139,16 +954,12 @@ public class MessagingController implements Runnable
final Date earliestDate = account.getEarliestPollDate();
- if (remoteMessageCount > 0)
- {
+ if (remoteMessageCount > 0) {
/* Message numbers start at 1. */
int remoteStart;
- if (visibleLimit > 0 )
- {
+ if (visibleLimit > 0) {
remoteStart = Math.max(0, remoteMessageCount - visibleLimit) + 1;
- }
- else
- {
+ } else {
remoteStart = 1;
}
int remoteEnd = remoteMessageCount;
@@ -1157,8 +968,7 @@ public class MessagingController implements Runnable
Log.v(K9.LOG_TAG, "SYNC: About to get messages " + remoteStart + " through " + remoteEnd + " for folder " + folder);
final AtomicInteger headerProgress = new AtomicInteger(0);
- for (MessagingListener l : getListeners(listener))
- {
+ for (MessagingListener l : getListeners(listener)) {
l.synchronizeMailboxHeadersStarted(account, folder);
}
@@ -1167,16 +977,13 @@ public class MessagingController implements Runnable
int messageCount = remoteMessageArray.length;
- for (Message thisMess : remoteMessageArray)
- {
+ for (Message thisMess : remoteMessageArray) {
headerProgress.incrementAndGet();
- for (MessagingListener l : getListeners(listener))
- {
+ for (MessagingListener l : getListeners(listener)) {
l.synchronizeMailboxHeadersProgress(account, folder, headerProgress.get(), messageCount);
}
Message localMessage = localUidMap.get(thisMess.getUid());
- if (localMessage == null || !localMessage.olderThan(earliestDate))
- {
+ if (localMessage == null || !localMessage.olderThan(earliestDate)) {
remoteMessages.add(thisMess);
remoteUidMap.put(thisMess.getUid(), thisMess);
}
@@ -1185,30 +992,23 @@ public class MessagingController implements Runnable
Log.v(K9.LOG_TAG, "SYNC: Got " + remoteUidMap.size() + " messages for folder " + folder);
remoteMessageArray = null;
- for (MessagingListener l : getListeners(listener))
- {
+ for (MessagingListener l : getListeners(listener)) {
l.synchronizeMailboxHeadersFinished(account, folder, headerProgress.get(), remoteUidMap.size());
}
- }
- else if (remoteMessageCount < 0)
- {
+ } else if (remoteMessageCount < 0) {
throw new Exception("Message count " + remoteMessageCount + " for folder " + folder);
}
/*
* Remove any messages that are in the local store but no longer on the remote store or are too old
*/
- if (account.syncRemoteDeletions())
- {
- for (Message localMessage : localMessages)
- {
- if (remoteUidMap.get(localMessage.getUid()) == null)
- {
+ if (account.syncRemoteDeletions()) {
+ for (Message localMessage : localMessages) {
+ if (remoteUidMap.get(localMessage.getUid()) == null) {
localMessage.destroy();
- for (MessagingListener l : getListeners(listener))
- {
+ for (MessagingListener l : getListeners(listener)) {
l.synchronizeMailboxRemovedMessage(account, folder, localMessage);
}
}
@@ -1225,8 +1025,7 @@ public class MessagingController implements Runnable
setLocalFlaggedCountToRemote(localFolder, remoteFolder);
- for (MessagingListener l : getListeners())
- {
+ for (MessagingListener l : getListeners()) {
l.folderStatusChanged(account, folder, unreadMessageCount);
}
@@ -1239,20 +1038,17 @@ public class MessagingController implements Runnable
Log.d(K9.LOG_TAG, "Done synchronizing folder " + account.getDescription() + ":" + folder +
" @ " + new Date() + " with " + newMessages + " new messages");
- for (MessagingListener l : getListeners(listener))
- {
+ for (MessagingListener l : getListeners(listener)) {
l.synchronizeMailboxFinished(account, folder, remoteMessageCount, newMessages);
}
- if (commandException != null)
- {
+ if (commandException != null) {
String rootMessage = getRootCauseMessage(commandException);
Log.e(K9.LOG_TAG, "Root cause failure in " + account.getDescription() + ":" +
tLocalFolder.getName() + " was '" + rootMessage + "'");
localFolder.setStatus(rootMessage);
- for (MessagingListener l : getListeners(listener))
- {
+ for (MessagingListener l : getListeners(listener)) {
l.synchronizeMailboxFailed(account, folder, rootMessage);
}
}
@@ -1260,39 +1056,29 @@ public class MessagingController implements Runnable
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "Done synchronizing folder " + account.getDescription() + ":" + folder);
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
Log.e(K9.LOG_TAG, "synchronizeMailbox", e);
// If we don't set the last checked, it can try too often during
// failure conditions
String rootMessage = getRootCauseMessage(e);
- if (tLocalFolder != null)
- {
- try
- {
+ if (tLocalFolder != null) {
+ try {
tLocalFolder.setStatus(rootMessage);
tLocalFolder.setLastChecked(System.currentTimeMillis());
- }
- catch (MessagingException me)
- {
+ } catch (MessagingException me) {
Log.e(K9.LOG_TAG, "Could not set last checked on folder " + account.getDescription() + ":" +
tLocalFolder.getName(), e);
}
}
- for (MessagingListener l : getListeners(listener))
- {
- l.synchronizeMailboxFailed( account, folder, rootMessage);
+ for (MessagingListener l : getListeners(listener)) {
+ l.synchronizeMailboxFailed(account, folder, rootMessage);
}
addErrorMessage(account, null, e);
Log.e(K9.LOG_TAG, "Failed synchronizing folder " + account.getDescription() + ":" + folder + " @ " + new Date());
- }
- finally
- {
- if (providedRemoteFolder == null)
- {
+ } finally {
+ if (providedRemoteFolder == null) {
closeFolder(remoteFolder);
}
@@ -1302,10 +1088,8 @@ public class MessagingController implements Runnable
}
- private void closeFolder(Folder f)
- {
- if (f != null)
- {
+ private void closeFolder(Folder f) {
+ if (f != null) {
f.close();
}
}
@@ -1318,18 +1102,13 @@ public class MessagingController implements Runnable
* designed and on Imap folders during error conditions. This allows us
* to treat Pop3 and Imap the same in this code.
*/
- private boolean verifyOrCreateRemoteSpecialFolder(final Account account, final String folder, final Folder remoteFolder, final MessagingListener listener) throws MessagingException
- {
+ private boolean verifyOrCreateRemoteSpecialFolder(final Account account, final String folder, final Folder remoteFolder, final MessagingListener listener) throws MessagingException {
if (folder.equals(account.getTrashFolderName()) ||
folder.equals(account.getSentFolderName()) ||
- folder.equals(account.getDraftsFolderName()))
- {
- if (!remoteFolder.exists())
- {
- if (!remoteFolder.create(FolderType.HOLDS_MESSAGES))
- {
- for (MessagingListener l : getListeners(listener))
- {
+ folder.equals(account.getDraftsFolderName())) {
+ if (!remoteFolder.exists()) {
+ if (!remoteFolder.create(FolderType.HOLDS_MESSAGES)) {
+ for (MessagingListener l : getListeners(listener)) {
l.synchronizeMailboxFinished(account, folder, 0, 0);
}
if (K9.DEBUG)
@@ -1341,21 +1120,15 @@ public class MessagingController implements Runnable
}
return true;
}
- private int setLocalUnreadCountToRemote(LocalFolder localFolder, Folder remoteFolder, int newMessageCount) throws MessagingException
- {
+ private int setLocalUnreadCountToRemote(LocalFolder localFolder, Folder remoteFolder, int newMessageCount) throws MessagingException {
int remoteUnreadMessageCount = remoteFolder.getUnreadMessageCount();
- if (remoteUnreadMessageCount != -1)
- {
+ if (remoteUnreadMessageCount != -1) {
localFolder.setUnreadMessageCount(remoteUnreadMessageCount);
- }
- else
- {
+ } else {
int unreadCount = 0;
Message[] messages = localFolder.getMessages(null, false);
- for (Message message : messages)
- {
- if (!message.isSet(Flag.SEEN) && !message.isSet(Flag.DELETED))
- {
+ for (Message message : messages) {
+ if (!message.isSet(Flag.SEEN) && !message.isSet(Flag.DELETED)) {
unreadCount++;
}
}
@@ -1364,21 +1137,15 @@ public class MessagingController implements Runnable
return localFolder.getUnreadMessageCount();
}
- private void setLocalFlaggedCountToRemote(LocalFolder localFolder, Folder remoteFolder) throws MessagingException
- {
+ private void setLocalFlaggedCountToRemote(LocalFolder localFolder, Folder remoteFolder) throws MessagingException {
int remoteFlaggedMessageCount = remoteFolder.getFlaggedMessageCount();
- if (remoteFlaggedMessageCount != -1)
- {
+ if (remoteFlaggedMessageCount != -1) {
localFolder.setFlaggedMessageCount(remoteFlaggedMessageCount);
- }
- else
- {
+ } else {
int flaggedCount = 0;
Message[] messages = localFolder.getMessages(null, false);
- for (Message message : messages)
- {
- if (message.isSet(Flag.FLAGGED) && !message.isSet(Flag.DELETED))
- {
+ for (Message message : messages) {
+ if (message.isSet(Flag.FLAGGED) && !message.isSet(Flag.DELETED)) {
flaggedCount++;
}
}
@@ -1387,30 +1154,24 @@ public class MessagingController implements Runnable
}
private int downloadMessages(final Account account, final Folder remoteFolder,
- final LocalFolder localFolder, List inputMessages, boolean flagSyncOnly) throws MessagingException
- {
+ final LocalFolder localFolder, List inputMessages, boolean flagSyncOnly) throws MessagingException {
final Date earliestDate = account.getEarliestPollDate();
Date downloadStarted = new Date(); // now
- if (earliestDate != null)
- {
- if (K9.DEBUG)
- {
+ if (earliestDate != null) {
+ if (K9.DEBUG) {
Log.d(K9.LOG_TAG, "Only syncing messages after " + earliestDate);
}
}
final String folder = remoteFolder.getName();
int unreadBeforeStart = 0;
- try
- {
+ try {
AccountStats stats = account.getStats(mApplication);
unreadBeforeStart = stats.unreadMessageCount;
- }
- catch (MessagingException e)
- {
+ } catch (MessagingException e) {
Log.e(K9.LOG_TAG, "Unable to getUnreadMessageCount for account: " + account, e);
}
@@ -1420,15 +1181,13 @@ public class MessagingController implements Runnable
List messages = new ArrayList(inputMessages);
- for (Message message : messages)
- {
- evaluateMessageForDownload(message, folder,localFolder, remoteFolder, account,unsyncedMessages, syncFlagMessages ,flagSyncOnly);
+ for (Message message : messages) {
+ evaluateMessageForDownload(message, folder, localFolder, remoteFolder, account, unsyncedMessages, syncFlagMessages , flagSyncOnly);
}
final AtomicInteger progress = new AtomicInteger(0);
final int todo = unsyncedMessages.size() + syncFlagMessages.size();
- for (MessagingListener l : getListeners())
- {
+ for (MessagingListener l : getListeners()) {
l.synchronizeMailboxProgress(account, folder, progress.get(), todo);
}
@@ -1438,8 +1197,7 @@ public class MessagingController implements Runnable
messages.clear();
final ArrayList largeMessages = new ArrayList();
final ArrayList smallMessages = new ArrayList();
- if (unsyncedMessages.size() > 0)
- {
+ if (unsyncedMessages.size() > 0) {
/*
* Reverse the order of the messages. Depending on the server this may get us
@@ -1449,14 +1207,12 @@ public class MessagingController implements Runnable
int visibleLimit = localFolder.getVisibleLimit();
int listSize = unsyncedMessages.size();
- if ((visibleLimit > 0) && (listSize > visibleLimit))
- {
+ if ((visibleLimit > 0) && (listSize > visibleLimit)) {
unsyncedMessages = unsyncedMessages.subList(listSize - visibleLimit, listSize);
}
FetchProfile fp = new FetchProfile();
- if (remoteFolder.supportsFetchingFlags())
- {
+ if (remoteFolder.supportsFetchingFlags()) {
fp.add(FetchProfile.Item.FLAGS);
}
fp.add(FetchProfile.Item.ENVELOPE);
@@ -1465,20 +1221,17 @@ public class MessagingController implements Runnable
Log.d(K9.LOG_TAG, "SYNC: About to fetch " + unsyncedMessages.size() + " unsynced messages for folder " + folder);
- fetchUnsyncedMessages(account, remoteFolder, localFolder, unsyncedMessages, smallMessages,largeMessages, progress, todo, fp);
+ fetchUnsyncedMessages(account, remoteFolder, localFolder, unsyncedMessages, smallMessages, largeMessages, progress, todo, fp);
// If a message didn't exist, messageFinished won't be called, but we shouldn't try again
// If we got here, nothing failed
- for (Message message : unsyncedMessages)
- {
+ for (Message message : unsyncedMessages) {
String newPushState = remoteFolder.getNewPushState(localFolder.getPushState(), message);
- if (newPushState != null)
- {
+ if (newPushState != null) {
localFolder.setPushState(newPushState);
}
}
- if (K9.DEBUG)
- {
+ if (K9.DEBUG) {
Log.d(K9.LOG_TAG, "SYNC: Synced unsynced messages for folder " + folder);
}
@@ -1519,18 +1272,15 @@ public class MessagingController implements Runnable
* download.
*/
- refreshLocalMessageFlags(account,remoteFolder,localFolder,syncFlagMessages,progress,todo);
+ refreshLocalMessageFlags(account, remoteFolder, localFolder, syncFlagMessages, progress, todo);
if (K9.DEBUG)
Log.d(K9.LOG_TAG, "SYNC: Synced remote messages for folder " + folder + ", " + newMessages.get() + " new messages");
- localFolder.purgeToVisibleLimit(new MessageRemovalListener()
- {
+ localFolder.purgeToVisibleLimit(new MessageRemovalListener() {
@Override
- public void messageRemoved(Message message)
- {
- for (MessagingListener l : getListeners())
- {
+ public void messageRemoved(Message message) {
+ for (MessagingListener l : getListeners()) {
l.synchronizeMailboxRemovedMessage(account, folder, message);
}
}
@@ -1545,12 +1295,10 @@ public class MessagingController implements Runnable
// fortunately, we just don't care.
Long oldestMessageTime = localFolder.getOldestMessageDate();
- if (oldestMessageTime != null)
- {
+ if (oldestMessageTime != null) {
Date oldestExtantMessage = new Date(oldestMessageTime);
- if (oldestExtantMessage.before(downloadStarted) &&
- oldestExtantMessage.after(new Date(account.getLatestOldMessageSeenTime())))
- {
+ if (oldestExtantMessage.before(downloadStarted) &&
+ oldestExtantMessage.after(new Date(account.getLatestOldMessageSeenTime()))) {
account.setLatestOldMessageSeenTime(oldestExtantMessage.getTime());
account.save(Preferences.getPreferences(mApplication.getApplicationContext()));
}
@@ -1564,33 +1312,24 @@ public class MessagingController implements Runnable
final Account account,
final List unsyncedMessages,
final ArrayList syncFlagMessages,
- boolean flagSyncOnly) throws MessagingException
- {
- if (message.isSet(Flag.DELETED))
- {
+ boolean flagSyncOnly) throws MessagingException {
+ if (message.isSet(Flag.DELETED)) {
syncFlagMessages.add(message);
return;
- }
- else if (isMessageSuppressed(account, folder, message))
- {
+ } else if (isMessageSuppressed(account, folder, message)) {
return;
}
Message localMessage = localFolder.getMessage(message.getUid());
- if (localMessage == null)
- {
- if (!flagSyncOnly)
- {
- if (!message.isSet(Flag.X_DOWNLOADED_FULL) && !message.isSet(Flag.X_DOWNLOADED_PARTIAL))
- {
+ if (localMessage == null) {
+ if (!flagSyncOnly) {
+ if (!message.isSet(Flag.X_DOWNLOADED_FULL) && !message.isSet(Flag.X_DOWNLOADED_PARTIAL)) {
if (K9.DEBUG)
Log.v(K9.LOG_TAG, "Message with uid " + message.getUid() + " has not yet been downloaded");
unsyncedMessages.add(message);
- }
- else
- {
+ } else {
if (K9.DEBUG)
Log.v(K9.LOG_TAG, "Message with uid " + message.getUid() + " is partially or fully downloaded");
@@ -1602,35 +1341,27 @@ public class MessagingController implements Runnable
localMessage.setFlag(Flag.X_DOWNLOADED_FULL, message.isSet(Flag.X_DOWNLOADED_FULL));
localMessage.setFlag(Flag.X_DOWNLOADED_PARTIAL, message.isSet(Flag.X_DOWNLOADED_PARTIAL));
- for (MessagingListener l : getListeners())
- {
+ for (MessagingListener l : getListeners()) {
l.synchronizeMailboxAddOrUpdateMessage(account, folder, localMessage);
- if (!localMessage.isSet(Flag.SEEN))
- {
+ if (!localMessage.isSet(Flag.SEEN)) {
l.synchronizeMailboxNewMessage(account, folder, localMessage);
}
}
}
}
- }
- else if (!localMessage.isSet(Flag.DELETED))
- {
+ } else if (!localMessage.isSet(Flag.DELETED)) {
if (K9.DEBUG)
Log.v(K9.LOG_TAG, "Message with uid " + message.getUid() + " is present in the local store");
- if (!localMessage.isSet(Flag.X_DOWNLOADED_FULL) && !localMessage.isSet(Flag.X_DOWNLOADED_PARTIAL))
- {
+ if (!localMessage.isSet(Flag.X_DOWNLOADED_FULL) && !localMessage.isSet(Flag.X_DOWNLOADED_PARTIAL)) {
if (K9.DEBUG)
Log.v(K9.LOG_TAG, "Message with uid " + message.getUid()
+ " is not downloaded, even partially; trying again");
unsyncedMessages.add(message);
- }
- else
- {
+ } else {
String newPushState = remoteFolder.getNewPushState(localFolder.getPushState(), message);
- if (newPushState != null)
- {
+ if (newPushState != null) {
localFolder.setPushState(newPushState);
}
syncFlagMessages.add(message);
@@ -1645,8 +1376,7 @@ public class MessagingController implements Runnable
final ArrayList largeMessages,
final AtomicInteger progress,
final int todo,
- FetchProfile fp) throws MessagingException
- {
+ FetchProfile fp) throws MessagingException {
final String folder = remoteFolder.getName();
final Date earliestDate = account.getEarliestPollDate();
@@ -1657,75 +1387,57 @@ public class MessagingController implements Runnable
final List chunk = new ArrayList(UNSYNC_CHUNK_SIZE);
remoteFolder.fetch(unsyncedMessages.toArray(EMPTY_MESSAGE_ARRAY), fp,
- new MessageRetrievalListener()
- {
+ new MessageRetrievalListener() {
@Override
- public void messageFinished(Message message, int number, int ofTotal)
- {
- try
- {
+ public void messageFinished(Message message, int number, int ofTotal) {
+ try {
String newPushState = remoteFolder.getNewPushState(localFolder.getPushState(), message);
- if (newPushState != null)
- {
+ if (newPushState != null) {
localFolder.setPushState(newPushState);
}
- if (message.isSet(Flag.DELETED) || message.olderThan(earliestDate))
- {
+ if (message.isSet(Flag.DELETED) || message.olderThan(earliestDate)) {
- if (K9.DEBUG)
- {
- if (message.isSet(Flag.DELETED))
- {
+ if (K9.DEBUG) {
+ if (message.isSet(Flag.DELETED)) {
Log.v(K9.LOG_TAG, "Newly downloaded message " + account + ":" + folder + ":" + message.getUid()
+ " was marked deleted on server, skipping");
- }
- else
- {
+ } else {
Log.d(K9.LOG_TAG, "Newly downloaded message " + message.getUid() + " is older than "
+ earliestDate + ", skipping");
}
}
progress.incrementAndGet();
- for (MessagingListener l : getListeners())
- {
+ for (MessagingListener l : getListeners()) {
l.synchronizeMailboxProgress(account, folder, progress.get(), todo);
}
return;
}
- if (message.getSize() > account.getMaximumAutoDownloadMessageSize())
- {
+ if (message.getSize() > account.getMaximumAutoDownloadMessageSize()) {
largeMessages.add(message);
- }
- else
- {
+ } else {
smallMessages.add(message);
}
// And include it in the view
- if (message.getSubject() != null && message.getFrom() != null)
- {
+ if (message.getSubject() != null && message.getFrom() != null) {
/*
* We check to make sure that we got something worth
* showing (subject and from) because some protocols
* (POP) may not be able to give us headers for
* ENVELOPE, only size.
*/
- if (!isMessageSuppressed(account, folder, message))
- {
+ if (!isMessageSuppressed(account, folder, message)) {
// keep message for delayed storing
chunk.add(message);
- if (chunk.size() >= UNSYNC_CHUNK_SIZE)
- {
+ if (chunk.size() >= UNSYNC_CHUNK_SIZE) {
writeUnsyncedMessages(chunk, localFolder, account, folder);
chunk.clear();
}
}
}
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
Log.e(K9.LOG_TAG, "Error while storing downloaded message.", e);
addErrorMessage(account, null, e);
}
@@ -1735,14 +1447,12 @@ public class MessagingController implements Runnable
public void messageStarted(String uid, int number, int ofTotal) {}
@Override
- public void messagesFinished(int total)
- {
+ public void messagesFinished(int total) {
// FIXME this method is almost never invoked by various Stores! Don't rely on it unless fixed!!
}
});
- if (chunk.size() > 0)
- {
+ if (chunk.size() > 0) {
writeUnsyncedMessages(chunk, localFolder, account, folder);
chunk.clear();
}
@@ -1759,56 +1469,44 @@ public class MessagingController implements Runnable
* @param account
* @param folder
*/
- private void writeUnsyncedMessages(final List messages, final LocalFolder localFolder, final Account account, final String folder)
- {
- if (K9.DEBUG)
- {
+ private void writeUnsyncedMessages(final List messages, final LocalFolder localFolder, final Account account, final String folder) {
+ if (K9.DEBUG) {
Log.v(K9.LOG_TAG, "Batch writing " + Integer.toString(messages.size()) + " messages");
}
- try
- {
+ try {
// Store the new message locally
localFolder.appendMessages(messages.toArray(new Message[messages.size()]));
- for (final Message message : messages)
- {
+ for (final Message message : messages) {
final Message localMessage = localFolder.getMessage(message.getUid());
syncFlags(localMessage, message);
if (K9.DEBUG)
Log.v(K9.LOG_TAG, "About to notify listeners that we got a new unsynced message "
+ account + ":" + folder + ":" + message.getUid());
- for (final MessagingListener l : getListeners())
- {
+ for (final MessagingListener l : getListeners()) {
l.synchronizeMailboxAddOrUpdateMessage(account, folder, localMessage);
}
}
- }
- catch (final Exception e)
- {
+ } catch (final Exception e) {
Log.e(K9.LOG_TAG, "Error while storing downloaded message.", e);
addErrorMessage(account, null, e);
}
}
- private boolean shouldImportMessage(final Account account, final String folder, final Message message, final AtomicInteger progress, final Date earliestDate)
- {
+ private boolean shouldImportMessage(final Account account, final String folder, final Message message, final AtomicInteger progress, final Date earliestDate) {
- if (isMessageSuppressed(account, folder, message))
- {
- if (K9.DEBUG)
- {
- Log.d(K9.LOG_TAG, "Message " + message.getUid() + " was suppressed "+
- "but just downloaded. "+
+ if (isMessageSuppressed(account, folder, message)) {
+ if (K9.DEBUG) {
+ Log.d(K9.LOG_TAG, "Message " + message.getUid() + " was suppressed " +
+ "but just downloaded. " +
"The race condition means we wasted some bandwidth. Oh well.");
}
return false;
}
- if (message.olderThan(earliestDate))
- {
- if (K9.DEBUG)
- {
+ if (message.olderThan(earliestDate)) {
+ if (K9.DEBUG) {
Log.d(K9.LOG_TAG, "Message " + message.getUid() + " is older than "
+ earliestDate + ", hence not saving");
}
@@ -1824,8 +1522,7 @@ public class MessagingController implements Runnable
final int unreadBeforeStart,
final AtomicInteger newMessages,
final int todo,
- FetchProfile fp) throws MessagingException
- {
+ FetchProfile fp) throws MessagingException {
final String folder = remoteFolder.getName();
final Date earliestDate = account.getEarliestPollDate();
@@ -1834,27 +1531,21 @@ public class MessagingController implements Runnable
Log.d(K9.LOG_TAG, "SYNC: Fetching small messages for folder " + folder);
remoteFolder.fetch(smallMessages.toArray(new Message[smallMessages.size()]),
- fp, new MessageRetrievalListener()
- {
+ fp, new MessageRetrievalListener() {
@Override
- public void messageFinished(Message message, int number, int ofTotal)
- {
- try
- {
+ public void messageFinished(Message message, int number, int ofTotal) {
+ try {
- if (!shouldImportMessage(account, folder, message, progress, earliestDate))
- {
+ if (!shouldImportMessage(account, folder, message, progress, earliestDate)) {
progress.incrementAndGet();
return;
}
// Store the updated message locally
- final Message localMessage = localFolder.storeSmallMessage(message, new Runnable()
- {
+ final Message localMessage = localFolder.storeSmallMessage(message, new Runnable() {
@Override
- public void run()
- {
+ public void run() {
progress.incrementAndGet();
}
});
@@ -1863,26 +1554,21 @@ public class MessagingController implements Runnable
+ account + ":" + folder + ":" + message.getUid());
// Update the listener with what we've found
- for (MessagingListener l : getListeners())
- {
+ for (MessagingListener l : getListeners()) {
l.synchronizeMailboxAddOrUpdateMessage(account, folder, localMessage);
l.synchronizeMailboxProgress(account, folder, progress.get(), todo);
- if (!localMessage.isSet(Flag.SEEN))
- {
+ if (!localMessage.isSet(Flag.SEEN)) {
l.synchronizeMailboxNewMessage(account, folder, localMessage);
}
}
// Send a notification of this message
- if (shouldNotifyForMessage(account, localFolder, message))
- {
+ if (shouldNotifyForMessage(account, localFolder, message)) {
newMessages.incrementAndGet();
notifyAccount(mApplication, account, message, unreadBeforeStart, newMessages);
}
- }
- catch (MessagingException me)
- {
+ } catch (MessagingException me) {
addErrorMessage(account, null, me);
Log.e(K9.LOG_TAG, "SYNC: fetch small messages", me);
}
@@ -1908,8 +1594,7 @@ public class MessagingController implements Runnable
final int unreadBeforeStart,
final AtomicInteger newMessages,
final int todo,
- FetchProfile fp) throws MessagingException
- {
+ FetchProfile fp) throws MessagingException {
final String folder = remoteFolder.getName();
final Date earliestDate = account.getEarliestPollDate();
@@ -1918,17 +1603,14 @@ public class MessagingController implements Runnable
Log.d(K9.LOG_TAG, "SYNC: Fetching large messages for folder " + folder);
remoteFolder.fetch(largeMessages.toArray(new Message[largeMessages.size()]), fp, null);
- for (Message message : largeMessages)
- {
+ for (Message message : largeMessages) {
- if (!shouldImportMessage(account, folder, message, progress, earliestDate))
- {
+ if (!shouldImportMessage(account, folder, message, progress, earliestDate)) {
progress.incrementAndGet();
continue;
}
- if (message.getBody() == null)
- {
+ if (message.getBody() == null) {
/*
* The provider was unable to get the structure of the message, so
* we'll download a reasonable portion of the messge and mark it as
@@ -1952,28 +1634,22 @@ public class MessagingController implements Runnable
// Certain (POP3) servers give you the whole message even when you ask for only the first x Kb
- if (!message.isSet(Flag.X_DOWNLOADED_FULL))
- {
+ if (!message.isSet(Flag.X_DOWNLOADED_FULL)) {
/*
* Mark the message as fully downloaded if the message size is smaller than
* the account's autodownload size limit, otherwise mark as only a partial
* download. This will prevent the system from downloading the same message
* twice.
*/
- if (message.getSize() < account.getMaximumAutoDownloadMessageSize())
- {
+ if (message.getSize() < account.getMaximumAutoDownloadMessageSize()) {
localMessage.setFlag(Flag.X_DOWNLOADED_FULL, true);
- }
- else
- {
+ } else {
// Set a flag indicating that the message has been partially downloaded and
// is ready for view.
localMessage.setFlag(Flag.X_DOWNLOADED_PARTIAL, true);
}
}
- }
- else
- {
+ } else {
/*
* We have a structure to deal with, from which
* we can pull down the parts we want to actually store.
@@ -1988,8 +1664,7 @@ public class MessagingController implements Runnable
/*
* Now download the parts we're interested in storing.
*/
- for (Part part : viewables)
- {
+ for (Part part : viewables) {
remoteFolder.fetchPart(message, part, null);
}
// Store the updated message locally
@@ -2008,19 +1683,16 @@ public class MessagingController implements Runnable
// Update the listener with what we've found
progress.incrementAndGet();
Message localMessage = localFolder.getMessage(message.getUid());
- for (MessagingListener l : getListeners())
- {
+ for (MessagingListener l : getListeners()) {
l.synchronizeMailboxAddOrUpdateMessage(account, folder, localMessage);
l.synchronizeMailboxProgress(account, folder, progress.get(), todo);
- if (!localMessage.isSet(Flag.SEEN))
- {
+ if (!localMessage.isSet(Flag.SEEN)) {
l.synchronizeMailboxNewMessage(account, folder, localMessage);
}
}
// Send a notification of this message
- if (shouldNotifyForMessage(account, localFolder, message))
- {
+ if (shouldNotifyForMessage(account, localFolder, message)) {
newMessages.incrementAndGet();
notifyAccount(mApplication, account, message, unreadBeforeStart, newMessages);
}
@@ -2036,12 +1708,10 @@ public class MessagingController implements Runnable
ArrayList syncFlagMessages,
final AtomicInteger progress,
final int todo
- ) throws MessagingException
- {
+ ) throws MessagingException {
final String folder = remoteFolder.getName();
- if (remoteFolder.supportsFetchingFlags())
- {
+ if (remoteFolder.supportsFetchingFlags()) {
if (K9.DEBUG)
Log.d(K9.LOG_TAG, "SYNC: About to sync flags for "
+ syncFlagMessages.size() + " remote messages for folder " + folder);
@@ -2050,67 +1720,49 @@ public class MessagingController implements Runnable
fp.add(FetchProfile.Item.FLAGS);
List undeletedMessages = new LinkedList();
- for (Message message : syncFlagMessages)
- {
- if (!message.isSet(Flag.DELETED))
- {
+ for (Message message : syncFlagMessages) {
+ if (!message.isSet(Flag.DELETED)) {
undeletedMessages.add(message);
}
}
remoteFolder.fetch(undeletedMessages.toArray(EMPTY_MESSAGE_ARRAY), fp, null);
- for (Message remoteMessage : syncFlagMessages)
- {
+ for (Message remoteMessage : syncFlagMessages) {
Message localMessage = localFolder.getMessage(remoteMessage.getUid());
boolean messageChanged = syncFlags(localMessage, remoteMessage);
- if (messageChanged)
- {
- if (localMessage.isSet(Flag.DELETED) || isMessageSuppressed(account, folder, localMessage))
- {
- for (MessagingListener l : getListeners())
- {
+ if (messageChanged) {
+ if (localMessage.isSet(Flag.DELETED) || isMessageSuppressed(account, folder, localMessage)) {
+ for (MessagingListener l : getListeners()) {
l.synchronizeMailboxRemovedMessage(account, folder, localMessage);
}
- }
- else
- {
- for (MessagingListener l : getListeners())
- {
+ } else {
+ for (MessagingListener l : getListeners()) {
l.synchronizeMailboxAddOrUpdateMessage(account, folder, localMessage);
}
}
}
progress.incrementAndGet();
- for (MessagingListener l : getListeners())
- {
+ for (MessagingListener l : getListeners()) {
l.synchronizeMailboxProgress(account, folder, progress.get(), todo);
}
}
}
}
- private boolean syncFlags(Message localMessage, Message remoteMessage) throws MessagingException
- {
+ private boolean syncFlags(Message localMessage, Message remoteMessage) throws MessagingException {
boolean messageChanged = false;
- if (localMessage == null || localMessage.isSet(Flag.DELETED))
- {
+ if (localMessage == null || localMessage.isSet(Flag.DELETED)) {
return false;
}
- if (remoteMessage.isSet(Flag.DELETED))
- {
- if (localMessage.getFolder().getAccount().syncRemoteDeletions())
- {
+ if (remoteMessage.isSet(Flag.DELETED)) {
+ if (localMessage.getFolder().getAccount().syncRemoteDeletions()) {
localMessage.setFlag(Flag.DELETED, true);
messageChanged = true;
}
- }
- else
- {
- for (Flag flag : new Flag[] { Flag.SEEN, Flag.FLAGGED, Flag.ANSWERED })
- {
- if (remoteMessage.isSet(flag) != localMessage.isSet(flag))
- {
+ } else {
+ for (Flag flag : new Flag[] { Flag.SEEN, Flag.FLAGGED, Flag.ANSWERED }) {
+ if (remoteMessage.isSet(flag) != localMessage.isSet(flag)) {
localMessage.setFlag(flag, remoteMessage.isSet(flag));
messageChanged = true;
}
@@ -2118,55 +1770,39 @@ public class MessagingController implements Runnable
}
return messageChanged;
}
- private String getRootCauseMessage(Throwable t)
- {
+ private String getRootCauseMessage(Throwable t) {
Throwable rootCause = t;
Throwable nextCause = rootCause;
- do
- {
+ do {
nextCause = rootCause.getCause();
- if (nextCause != null)
- {
+ if (nextCause != null) {
rootCause = nextCause;
}
- }
- while (nextCause != null);
+ } while (nextCause != null);
return rootCause.getMessage();
}
- private void queuePendingCommand(Account account, PendingCommand command)
- {
- try
- {
+ private void queuePendingCommand(Account account, PendingCommand command) {
+ try {
LocalStore localStore = account.getLocalStore();
localStore.addPendingCommand(command);
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
addErrorMessage(account, null, e);
throw new RuntimeException("Unable to enqueue pending command", e);
}
}
- private void processPendingCommands(final Account account)
- {
- putBackground("processPendingCommands", null, new Runnable()
- {
+ private void processPendingCommands(final Account account) {
+ putBackground("processPendingCommands", null, new Runnable() {
@Override
- public void run()
- {
- try
- {
+ public void run() {
+ try {
processPendingCommandsSynchronous(account);
- }
- catch (UnavailableStorageException e)
- {
+ } catch (UnavailableStorageException e) {
Log.i(K9.LOG_TAG, "Failed to process pending command because storage is not available - trying again later.");
throw new UnavailableAccountException(e);
- }
- catch (MessagingException me)
- {
+ } catch (MessagingException me) {
Log.e(K9.LOG_TAG, "processPendingCommands", me);
addErrorMessage(account, null, me);
@@ -2180,37 +1816,31 @@ public class MessagingController implements Runnable
});
}
- private void processPendingCommandsSynchronous(Account account) throws MessagingException
- {
+ private void processPendingCommandsSynchronous(Account account) throws MessagingException {
LocalStore localStore = account.getLocalStore();
ArrayList commands = localStore.getPendingCommands();
int progress = 0;
int todo = commands.size();
- if (todo == 0)
- {
+ if (todo == 0) {
return;
}
- for (MessagingListener l : getListeners())
- {
+ for (MessagingListener l : getListeners()) {
l.pendingCommandsProcessing(account);
l.synchronizeMailboxProgress(account, null, progress, todo);
}
PendingCommand processingCommand = null;
- try
- {
- for (PendingCommand command : commands)
- {
+ try {
+ for (PendingCommand command : commands) {
processingCommand = command;
if (K9.DEBUG)
Log.d(K9.LOG_TAG, "Processing pending command '" + command + "'");
String[] components = command.command.split("\\.");
String commandTitle = components[components.length - 1];
- for (MessagingListener l : getListeners())
- {
+ for (MessagingListener l : getListeners()) {
l.pendingCommandStarted(account, commandTitle);
}
/*
@@ -2218,78 +1848,49 @@ public class MessagingController implements Runnable
* most likely due to a server or IO error and it must be retried before any
* other command processes. This maintains the order of the commands.
*/
- try
- {
- if (PENDING_COMMAND_APPEND.equals(command.command))
- {
+ try {
+ if (PENDING_COMMAND_APPEND.equals(command.command)) {
processPendingAppend(command, account);
- }
- else if (PENDING_COMMAND_SET_FLAG_BULK.equals(command.command))
- {
+ } else if (PENDING_COMMAND_SET_FLAG_BULK.equals(command.command)) {
processPendingSetFlag(command, account);
- }
- else if (PENDING_COMMAND_SET_FLAG.equals(command.command))
- {
+ } else if (PENDING_COMMAND_SET_FLAG.equals(command.command)) {
processPendingSetFlagOld(command, account);
- }
- else if (PENDING_COMMAND_MARK_ALL_AS_READ.equals(command.command))
- {
+ } else if (PENDING_COMMAND_MARK_ALL_AS_READ.equals(command.command)) {
processPendingMarkAllAsRead(command, account);
- }
- else if (PENDING_COMMAND_MOVE_OR_COPY_BULK.equals(command.command))
- {
+ } else if (PENDING_COMMAND_MOVE_OR_COPY_BULK.equals(command.command)) {
processPendingMoveOrCopy(command, account);
- }
- else if (PENDING_COMMAND_MOVE_OR_COPY.equals(command.command))
- {
+ } else if (PENDING_COMMAND_MOVE_OR_COPY.equals(command.command)) {
processPendingMoveOrCopyOld(command, account);
- }
- else if (PENDING_COMMAND_EMPTY_TRASH.equals(command.command))
- {
+ } else if (PENDING_COMMAND_EMPTY_TRASH.equals(command.command)) {
processPendingEmptyTrash(command, account);
- }
- else if (PENDING_COMMAND_EXPUNGE.equals(command.command))
- {
+ } else if (PENDING_COMMAND_EXPUNGE.equals(command.command)) {
processPendingExpunge(command, account);
}
localStore.removePendingCommand(command);
if (K9.DEBUG)
Log.d(K9.LOG_TAG, "Done processing pending command '" + command + "'");
- }
- catch (MessagingException me)
- {
- if (me.isPermanentFailure())
- {
+ } catch (MessagingException me) {
+ if (me.isPermanentFailure()) {
addErrorMessage(account, null, me);
Log.e(K9.LOG_TAG, "Failure of command '" + command + "' was permanent, removing command from queue");
localStore.removePendingCommand(processingCommand);
- }
- else
- {
+ } else {
throw me;
}
- }
- finally
- {
+ } finally {
progress++;
- for (MessagingListener l : getListeners())
- {
+ for (MessagingListener l : getListeners()) {
l.synchronizeMailboxProgress(account, null, progress, todo);
l.pendingCommandCompleted(account, commandTitle);
}
}
}
- }
- catch (MessagingException me)
- {
+ } catch (MessagingException me) {
addErrorMessage(account, null, me);
Log.e(K9.LOG_TAG, "Could not process command '" + processingCommand + "'", me);
throw me;
- }
- finally
- {
- for (MessagingListener l : getListeners())
- {
+ } finally {
+ for (MessagingListener l : getListeners()) {
l.pendingCommandsFinished(account);
}
}
@@ -2308,18 +1909,15 @@ public class MessagingController implements Runnable
* @throws MessagingException
*/
private void processPendingAppend(PendingCommand command, Account account)
- throws MessagingException
- {
+ throws MessagingException {
Folder remoteFolder = null;
LocalFolder localFolder = null;
- try
- {
+ try {
String folder = command.arguments[0];
String uid = command.arguments[1];
- if (account.getErrorFolderName().equals(folder))
- {
+ if (account.getErrorFolderName().equals(folder)) {
return;
}
@@ -2327,56 +1925,45 @@ public class MessagingController implements Runnable
localFolder = localStore.getFolder(folder);
LocalMessage localMessage = (LocalMessage) localFolder.getMessage(uid);
- if (localMessage == null)
- {
+ if (localMessage == null) {
return;
}
Store remoteStore = account.getRemoteStore();
remoteFolder = remoteStore.getFolder(folder);
- if (!remoteFolder.exists())
- {
- if (!remoteFolder.create(FolderType.HOLDS_MESSAGES))
- {
+ if (!remoteFolder.exists()) {
+ if (!remoteFolder.create(FolderType.HOLDS_MESSAGES)) {
return;
}
}
remoteFolder.open(OpenMode.READ_WRITE);
- if (remoteFolder.getMode() != OpenMode.READ_WRITE)
- {
+ if (remoteFolder.getMode() != OpenMode.READ_WRITE) {
return;
}
Message remoteMessage = null;
- if (!localMessage.getUid().startsWith(K9.LOCAL_UID_PREFIX))
- {
+ if (!localMessage.getUid().startsWith(K9.LOCAL_UID_PREFIX)) {
remoteMessage = remoteFolder.getMessage(localMessage.getUid());
}
- if (remoteMessage == null)
- {
- if (localMessage.isSet(Flag.X_REMOTE_COPY_STARTED))
- {
+ if (remoteMessage == null) {
+ if (localMessage.isSet(Flag.X_REMOTE_COPY_STARTED)) {
Log.w(K9.LOG_TAG, "Local message with uid " + localMessage.getUid() +
" has flag " + Flag.X_REMOTE_COPY_STARTED + " already set, checking for remote message with " +
" same message id");
String rUid = remoteFolder.getUidFromMessageId(localMessage);
- if (rUid != null)
- {
+ if (rUid != null) {
Log.w(K9.LOG_TAG, "Local message has flag " + Flag.X_REMOTE_COPY_STARTED + " already set, and there is a remote message with " +
" uid " + rUid + ", assuming message was already copied and aborting this copy");
String oldUid = localMessage.getUid();
localMessage.setUid(rUid);
localFolder.changeUid(localMessage);
- for (MessagingListener l : getListeners())
- {
+ for (MessagingListener l : getListeners()) {
l.messageUidChanged(account, folder, oldUid, localMessage.getUid());
}
return;
- }
- else
- {
+ } else {
Log.w(K9.LOG_TAG, "No remote message with message-id found, proceeding with append");
}
}
@@ -2393,13 +1980,10 @@ public class MessagingController implements Runnable
remoteFolder.appendMessages(new Message[] { localMessage });
localFolder.changeUid(localMessage);
- for (MessagingListener l : getListeners())
- {
+ for (MessagingListener l : getListeners()) {
l.messageUidChanged(account, folder, oldUid, localMessage.getUid());
}
- }
- else
- {
+ } else {
/*
* If the remote message exists we need to determine which copy to keep.
*/
@@ -2411,17 +1995,14 @@ public class MessagingController implements Runnable
remoteFolder.fetch(new Message[] { remoteMessage }, fp, null);
Date localDate = localMessage.getInternalDate();
Date remoteDate = remoteMessage.getInternalDate();
- if (remoteDate != null && remoteDate.compareTo(localDate) > 0)
- {
+ if (remoteDate != null && remoteDate.compareTo(localDate) > 0) {
/*
* If the remote message is newer than ours we'll just
* delete ours and move on. A sync will get the server message
* if we need to be able to see it.
*/
localMessage.destroy();
- }
- else
- {
+ } else {
/*
* Otherwise we'll upload our message and then delete the remote message.
*/
@@ -2435,31 +2016,24 @@ public class MessagingController implements Runnable
remoteFolder.appendMessages(new Message[] { localMessage });
localFolder.changeUid(localMessage);
- for (MessagingListener l : getListeners())
- {
+ for (MessagingListener l : getListeners()) {
l.messageUidChanged(account, folder, oldUid, localMessage.getUid());
}
- if (remoteDate != null)
- {
+ if (remoteDate != null) {
remoteMessage.setFlag(Flag.DELETED, true);
- if (Account.EXPUNGE_IMMEDIATELY.equals(account.getExpungePolicy()))
- {
+ if (Account.EXPUNGE_IMMEDIATELY.equals(account.getExpungePolicy())) {
remoteFolder.expunge();
}
}
}
}
- }
- finally
- {
+ } finally {
closeFolder(remoteFolder);
closeFolder(localFolder);
}
}
- private void queueMoveOrCopy(Account account, String srcFolder, String destFolder, boolean isCopy, String uids[])
- {
- if (account.getErrorFolderName().equals(srcFolder))
- {
+ private void queueMoveOrCopy(Account account, String srcFolder, String destFolder, boolean isCopy, String uids[]) {
+ if (account.getErrorFolderName().equals(srcFolder)) {
return;
}
PendingCommand command = new PendingCommand();
@@ -2481,15 +2055,12 @@ public class MessagingController implements Runnable
* @throws MessagingException
*/
private void processPendingMoveOrCopy(PendingCommand command, Account account)
- throws MessagingException
- {
+ throws MessagingException {
Folder remoteSrcFolder = null;
Folder remoteDestFolder = null;
- try
- {
+ try {
String srcFolder = command.arguments[0];
- if (account.getErrorFolderName().equals(srcFolder))
- {
+ if (account.getErrorFolderName().equals(srcFolder)) {
return;
}
String destFolder = command.arguments[1];
@@ -2498,28 +2069,23 @@ public class MessagingController implements Runnable
remoteSrcFolder = remoteStore.getFolder(srcFolder);
List messages = new ArrayList();
- for (int i = 3; i < command.arguments.length; i++)
- {
+ for (int i = 3; i < command.arguments.length; i++) {
String uid = command.arguments[i];
- if (!uid.startsWith(K9.LOCAL_UID_PREFIX))
- {
+ if (!uid.startsWith(K9.LOCAL_UID_PREFIX)) {
messages.add(remoteSrcFolder.getMessage(uid));
}
}
boolean isCopy = false;
- if (isCopyS != null)
- {
+ if (isCopyS != null) {
isCopy = Boolean.parseBoolean(isCopyS);
}
- if (!remoteSrcFolder.exists())
- {
+ if (!remoteSrcFolder.exists()) {
throw new MessagingException("processingPendingMoveOrCopy: remoteFolder " + srcFolder + " does not exist", true);
}
remoteSrcFolder.open(OpenMode.READ_WRITE);
- if (remoteSrcFolder.getMode() != OpenMode.READ_WRITE)
- {
+ if (remoteSrcFolder.getMode() != OpenMode.READ_WRITE) {
throw new MessagingException("processingPendingMoveOrCopy: could not open remoteSrcFolder " + srcFolder + " read/write", true);
}
@@ -2527,41 +2093,31 @@ public class MessagingController implements Runnable
Log.d(K9.LOG_TAG, "processingPendingMoveOrCopy: source folder = " + srcFolder
+ ", " + messages.size() + " messages, destination folder = " + destFolder + ", isCopy = " + isCopy);
- if (!isCopy && destFolder.equals(account.getTrashFolderName()))
- {
+ if (!isCopy && destFolder.equals(account.getTrashFolderName())) {
if (K9.DEBUG)
Log.d(K9.LOG_TAG, "processingPendingMoveOrCopy doing special case for deleting message");
String destFolderName = destFolder;
- if (K9.FOLDER_NONE.equals(destFolderName))
- {
+ if (K9.FOLDER_NONE.equals(destFolderName)) {
destFolderName = null;
}
remoteSrcFolder.delete(messages.toArray(EMPTY_MESSAGE_ARRAY), destFolderName);
- }
- else
- {
+ } else {
remoteDestFolder = remoteStore.getFolder(destFolder);
- if (isCopy)
- {
+ if (isCopy) {
remoteSrcFolder.copyMessages(messages.toArray(EMPTY_MESSAGE_ARRAY), remoteDestFolder);
- }
- else
- {
+ } else {
remoteSrcFolder.moveMessages(messages.toArray(EMPTY_MESSAGE_ARRAY), remoteDestFolder);
}
}
- if (!isCopy && Account.EXPUNGE_IMMEDIATELY.equals(account.getExpungePolicy()))
- {
+ if (!isCopy && Account.EXPUNGE_IMMEDIATELY.equals(account.getExpungePolicy())) {
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "processingPendingMoveOrCopy expunging folder " + account.getDescription() + ":" + srcFolder);
remoteSrcFolder.expunge();
}
- }
- finally
- {
+ } finally {
closeFolder(remoteSrcFolder);
closeFolder(remoteDestFolder);
}
@@ -2569,13 +2125,10 @@ public class MessagingController implements Runnable
}
- private void queueSetFlag(final Account account, final String folderName, final String newState, final String flag, final String[] uids)
- {
- putBackground("queueSetFlag " + account.getDescription() + ":" + folderName, null, new Runnable()
- {
+ private void queueSetFlag(final Account account, final String folderName, final String newState, final String flag, final String[] uids) {
+ putBackground("queueSetFlag " + account.getDescription() + ":" + folderName, null, new Runnable() {
@Override
- public void run()
- {
+ public void run() {
PendingCommand command = new PendingCommand();
command.command = PENDING_COMMAND_SET_FLAG_BULK;
int length = 3 + uids.length;
@@ -2596,12 +2149,10 @@ public class MessagingController implements Runnable
* @param account
*/
private void processPendingSetFlag(PendingCommand command, Account account)
- throws MessagingException
- {
+ throws MessagingException {
String folder = command.arguments[0];
- if (account.getErrorFolderName().equals(folder))
- {
+ if (account.getErrorFolderName().equals(folder)) {
return;
}
@@ -2618,36 +2169,28 @@ public class MessagingController implements Runnable
* unnecessary connections to POP3 servers.
*/
// TODO: This should actually call a supportsSettingFlag(flag) method.
- (!remoteFolder.supportsFetchingFlags() && !Flag.DELETED.equals(flag)))
- {
+ (!remoteFolder.supportsFetchingFlags() && !Flag.DELETED.equals(flag))) {
return;
}
- try
- {
+ try {
remoteFolder.open(OpenMode.READ_WRITE);
- if (remoteFolder.getMode() != OpenMode.READ_WRITE)
- {
+ if (remoteFolder.getMode() != OpenMode.READ_WRITE) {
return;
}
List messages = new ArrayList();
- for (int i = 3; i < command.arguments.length; i++)
- {
+ for (int i = 3; i < command.arguments.length; i++) {
String uid = command.arguments[i];
- if (!uid.startsWith(K9.LOCAL_UID_PREFIX))
- {
+ if (!uid.startsWith(K9.LOCAL_UID_PREFIX)) {
messages.add(remoteFolder.getMessage(uid));
}
}
- if (messages.size() == 0)
- {
+ if (messages.size() == 0) {
return;
}
remoteFolder.setFlags(messages.toArray(EMPTY_MESSAGE_ARRAY), new Flag[] { flag }, newState);
- }
- finally
- {
+ } finally {
closeFolder(remoteFolder);
}
}
@@ -2655,13 +2198,11 @@ public class MessagingController implements Runnable
// TODO: This method is obsolete and is only for transition from K-9 2.0 to K-9 2.1
// Eventually, it should be removed
private void processPendingSetFlagOld(PendingCommand command, Account account)
- throws MessagingException
- {
+ throws MessagingException {
String folder = command.arguments[0];
String uid = command.arguments[1];
- if (account.getErrorFolderName().equals(folder))
- {
+ if (account.getErrorFolderName().equals(folder)) {
return;
}
if (K9.DEBUG)
@@ -2671,42 +2212,32 @@ public class MessagingController implements Runnable
Flag flag = Flag.valueOf(command.arguments[3]);
Folder remoteFolder = null;
- try
- {
+ try {
Store remoteStore = account.getRemoteStore();
remoteFolder = remoteStore.getFolder(folder);
- if (!remoteFolder.exists())
- {
+ if (!remoteFolder.exists()) {
return;
}
remoteFolder.open(OpenMode.READ_WRITE);
- if (remoteFolder.getMode() != OpenMode.READ_WRITE)
- {
+ if (remoteFolder.getMode() != OpenMode.READ_WRITE) {
return;
}
Message remoteMessage = null;
- if (!uid.startsWith(K9.LOCAL_UID_PREFIX))
- {
+ if (!uid.startsWith(K9.LOCAL_UID_PREFIX)) {
remoteMessage = remoteFolder.getMessage(uid);
}
- if (remoteMessage == null)
- {
+ if (remoteMessage == null) {
return;
}
remoteMessage.setFlag(flag, newState);
- }
- finally
- {
+ } finally {
closeFolder(remoteFolder);
}
}
- private void queueExpunge(final Account account, final String folderName)
- {
- putBackground("queueExpunge " + account.getDescription() + ":" + folderName, null, new Runnable()
- {
+ private void queueExpunge(final Account account, final String folderName) {
+ putBackground("queueExpunge " + account.getDescription() + ":" + folderName, null, new Runnable() {
@Override
- public void run()
- {
+ public void run() {
PendingCommand command = new PendingCommand();
command.command = PENDING_COMMAND_EXPUNGE;
@@ -2719,12 +2250,10 @@ public class MessagingController implements Runnable
});
}
private void processPendingExpunge(PendingCommand command, Account account)
- throws MessagingException
- {
+ throws MessagingException {
String folder = command.arguments[0];
- if (account.getErrorFolderName().equals(folder))
- {
+ if (account.getErrorFolderName().equals(folder)) {
return;
}
if (K9.DEBUG)
@@ -2732,23 +2261,18 @@ public class MessagingController implements Runnable
Store remoteStore = account.getRemoteStore();
Folder remoteFolder = remoteStore.getFolder(folder);
- try
- {
- if (!remoteFolder.exists())
- {
+ try {
+ if (!remoteFolder.exists()) {
return;
}
remoteFolder.open(OpenMode.READ_WRITE);
- if (remoteFolder.getMode() != OpenMode.READ_WRITE)
- {
+ if (remoteFolder.getMode() != OpenMode.READ_WRITE) {
return;
}
remoteFolder.expunge();
if (K9.DEBUG)
Log.d(K9.LOG_TAG, "processPendingExpunge: complete for folder = " + folder);
- }
- finally
- {
+ } finally {
closeFolder(remoteFolder);
}
}
@@ -2757,21 +2281,18 @@ public class MessagingController implements Runnable
// TODO: This method is obsolete and is only for transition from K-9 2.0 to K-9 2.1
// Eventually, it should be removed
private void processPendingMoveOrCopyOld(PendingCommand command, Account account)
- throws MessagingException
- {
+ throws MessagingException {
String srcFolder = command.arguments[0];
String uid = command.arguments[1];
String destFolder = command.arguments[2];
String isCopyS = command.arguments[3];
boolean isCopy = false;
- if (isCopyS != null)
- {
+ if (isCopyS != null) {
isCopy = Boolean.parseBoolean(isCopyS);
}
- if (account.getErrorFolderName().equals(srcFolder))
- {
+ if (account.getErrorFolderName().equals(srcFolder)) {
return;
}
@@ -2779,23 +2300,19 @@ public class MessagingController implements Runnable
Folder remoteSrcFolder = remoteStore.getFolder(srcFolder);
Folder remoteDestFolder = remoteStore.getFolder(destFolder);
- if (!remoteSrcFolder.exists())
- {
+ if (!remoteSrcFolder.exists()) {
throw new MessagingException("processPendingMoveOrCopyOld: remoteFolder " + srcFolder + " does not exist", true);
}
remoteSrcFolder.open(OpenMode.READ_WRITE);
- if (remoteSrcFolder.getMode() != OpenMode.READ_WRITE)
- {
+ if (remoteSrcFolder.getMode() != OpenMode.READ_WRITE) {
throw new MessagingException("processPendingMoveOrCopyOld: could not open remoteSrcFolder " + srcFolder + " read/write", true);
}
Message remoteMessage = null;
- if (!uid.startsWith(K9.LOCAL_UID_PREFIX))
- {
+ if (!uid.startsWith(K9.LOCAL_UID_PREFIX)) {
remoteMessage = remoteSrcFolder.getMessage(uid);
}
- if (remoteMessage == null)
- {
+ if (remoteMessage == null) {
throw new MessagingException("processPendingMoveOrCopyOld: remoteMessage " + uid + " does not exist", true);
}
@@ -2803,8 +2320,7 @@ public class MessagingController implements Runnable
Log.d(K9.LOG_TAG, "processPendingMoveOrCopyOld: source folder = " + srcFolder
+ ", uid = " + uid + ", destination folder = " + destFolder + ", isCopy = " + isCopy);
- if (!isCopy && destFolder.equals(account.getTrashFolderName()))
- {
+ if (!isCopy && destFolder.equals(account.getTrashFolderName())) {
if (K9.DEBUG)
Log.d(K9.LOG_TAG, "processPendingMoveOrCopyOld doing special case for deleting message");
@@ -2814,79 +2330,62 @@ public class MessagingController implements Runnable
}
remoteDestFolder.open(OpenMode.READ_WRITE);
- if (remoteDestFolder.getMode() != OpenMode.READ_WRITE)
- {
+ if (remoteDestFolder.getMode() != OpenMode.READ_WRITE) {
throw new MessagingException("processPendingMoveOrCopyOld: could not open remoteDestFolder " + srcFolder + " read/write", true);
}
- if (isCopy)
- {
+ if (isCopy) {
remoteSrcFolder.copyMessages(new Message[] { remoteMessage }, remoteDestFolder);
- }
- else
- {
+ } else {
remoteSrcFolder.moveMessages(new Message[] { remoteMessage }, remoteDestFolder);
}
remoteSrcFolder.close();
remoteDestFolder.close();
}
- private void processPendingMarkAllAsRead(PendingCommand command, Account account) throws MessagingException
- {
+ private void processPendingMarkAllAsRead(PendingCommand command, Account account) throws MessagingException {
String folder = command.arguments[0];
Folder remoteFolder = null;
LocalFolder localFolder = null;
- try
- {
+ try {
Store localStore = account.getLocalStore();
localFolder = (LocalFolder) localStore.getFolder(folder);
localFolder.open(OpenMode.READ_WRITE);
Message[] messages = localFolder.getMessages(null, false);
- for (Message message : messages)
- {
- if (!message.isSet(Flag.SEEN))
- {
+ for (Message message : messages) {
+ if (!message.isSet(Flag.SEEN)) {
message.setFlag(Flag.SEEN, true);
- for (MessagingListener l : getListeners())
- {
+ for (MessagingListener l : getListeners()) {
l.listLocalMessagesUpdateMessage(account, folder, message);
}
}
}
localFolder.setUnreadMessageCount(0);
- for (MessagingListener l : getListeners())
- {
+ for (MessagingListener l : getListeners()) {
l.folderStatusChanged(account, folder, 0);
}
- if (account.getErrorFolderName().equals(folder))
- {
+ if (account.getErrorFolderName().equals(folder)) {
return;
}
Store remoteStore = account.getRemoteStore();
remoteFolder = remoteStore.getFolder(folder);
- if (!remoteFolder.exists())
- {
+ if (!remoteFolder.exists()) {
return;
}
remoteFolder.open(OpenMode.READ_WRITE);
- if (remoteFolder.getMode() != OpenMode.READ_WRITE)
- {
+ if (remoteFolder.getMode() != OpenMode.READ_WRITE) {
return;
}
remoteFolder.setFlags(new Flag[] {Flag.SEEN}, true);
remoteFolder.close();
- }
- catch (UnsupportedOperationException uoe)
- {
+ } catch (UnsupportedOperationException uoe) {
Log.w(K9.LOG_TAG, "Could not mark all server-side as read because store doesn't support operation", uoe);
- }
- finally
- {
+ } finally {
closeFolder(localFolder);
closeFolder(remoteFolder);
}
@@ -2894,16 +2393,12 @@ public class MessagingController implements Runnable
static long uidfill = 0;
static AtomicBoolean loopCatch = new AtomicBoolean();
- public void addErrorMessage(Account account, String subject, Throwable t)
- {
- if (!loopCatch.compareAndSet(false, true))
- {
+ public void addErrorMessage(Account account, String subject, Throwable t) {
+ if (!loopCatch.compareAndSet(false, true)) {
return;
}
- try
- {
- if (t == null)
- {
+ try {
+ if (t == null) {
return;
}
@@ -2912,37 +2407,27 @@ public class MessagingController implements Runnable
t.printStackTrace(ps);
ps.close();
- if (subject == null)
- {
+ if (subject == null) {
subject = getRootCauseMessage(t);
}
addErrorMessage(account, subject, baos.toString());
- }
- catch (Throwable it)
- {
+ } catch (Throwable it) {
Log.e(K9.LOG_TAG, "Could not save error message to " + account.getErrorFolderName(), it);
- }
- finally
- {
+ } finally {
loopCatch.set(false);
}
}
- public void addErrorMessage(Account account, String subject, String body)
- {
- if (!K9.ENABLE_ERROR_FOLDER)
- {
+ public void addErrorMessage(Account account, String subject, String body) {
+ if (!K9.ENABLE_ERROR_FOLDER) {
return;
}
- if (!loopCatch.compareAndSet(false, true))
- {
+ if (!loopCatch.compareAndSet(false, true)) {
return;
}
- try
- {
- if (body == null || body.length() < 1)
- {
+ try {
+ if (body == null || body.length() < 1) {
return;
}
@@ -2967,21 +2452,16 @@ public class MessagingController implements Runnable
localFolder.clearMessagesOlderThan(nowTime - (15 * 60 * 1000));
- }
- catch (Throwable it)
- {
+ } catch (Throwable it) {
Log.e(K9.LOG_TAG, "Could not save error message to " + account.getErrorFolderName(), it);
- }
- finally
- {
+ } finally {
loopCatch.set(false);
}
}
- public void markAllMessagesRead(final Account account, final String folder)
- {
+ public void markAllMessagesRead(final Account account, final String folder) {
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "Marking all messages in " + account.getDescription() + ":" + folder + " as read");
@@ -2997,17 +2477,13 @@ public class MessagingController implements Runnable
public void setFlag(
final Message[] messages,
final Flag flag,
- final boolean newState)
- {
- actOnMessages(messages, new MessageActor()
- {
+ final boolean newState) {
+ actOnMessages(messages, new MessageActor() {
@Override
public void act(final Account account, final Folder folder,
- final List messages)
- {
+ final List messages) {
String[] uids = new String[messages.size()];
- for (int i = 0; i < messages.size(); i++)
- {
+ for (int i = 0; i < messages.size(); i++) {
uids[i] = messages.get(i).getUid();
}
setFlag(account, folder.getName(), uids, flag, newState);
@@ -3022,29 +2498,24 @@ public class MessagingController implements Runnable
final String folderName,
final String[] uids,
final Flag flag,
- final boolean newState)
- {
+ final boolean newState) {
// TODO: put this into the background, but right now that causes odd behavior
// because the FolderMessageList doesn't have its own cache of the flag states
Folder localFolder = null;
- try
- {
+ try {
Store localStore = account.getLocalStore();
localFolder = localStore.getFolder(folderName);
localFolder.open(OpenMode.READ_WRITE);
ArrayList messages = new ArrayList();
- for (String uid : uids)
- {
+ for (String uid : uids) {
// Allows for re-allowing sending of messages that could not be sent
if (flag == Flag.FLAGGED && !newState
&& uid != null
- && account.getOutboxFolderName().equals(folderName))
- {
+ && account.getOutboxFolderName().equals(folderName)) {
sendCount.remove(uid);
}
Message msg = localFolder.getMessage(uid);
- if (msg != null)
- {
+ if (msg != null) {
messages.add(msg);
}
}
@@ -3052,66 +2523,51 @@ public class MessagingController implements Runnable
localFolder.setFlags(messages.toArray(EMPTY_MESSAGE_ARRAY), new Flag[] {flag}, newState);
- for (MessagingListener l : getListeners())
- {
+ for (MessagingListener l : getListeners()) {
l.folderStatusChanged(account, folderName, localFolder.getUnreadMessageCount());
}
- if (account.getErrorFolderName().equals(folderName))
- {
+ if (account.getErrorFolderName().equals(folderName)) {
return;
}
queueSetFlag(account, folderName, Boolean.toString(newState), flag.toString(), uids);
processPendingCommands(account);
- }
- catch (MessagingException me)
- {
+ } catch (MessagingException me) {
addErrorMessage(account, null, me);
throw new RuntimeException(me);
- }
- finally
- {
+ } finally {
closeFolder(localFolder);
}
}//setMesssageFlag
- public void clearAllPending(final Account account)
- {
- try
- {
+ public void clearAllPending(final Account account) {
+ try {
Log.w(K9.LOG_TAG, "Clearing pending commands!");
LocalStore localStore = account.getLocalStore();
localStore.removePendingCommands();
- }
- catch (MessagingException me)
- {
+ } catch (MessagingException me) {
Log.e(K9.LOG_TAG, "Unable to clear pending command", me);
addErrorMessage(account, null, me);
}
}
public void loadMessageForViewRemote(final Account account, final String folder,
- final String uid, final MessagingListener listener)
- {
- put("loadMessageForViewRemote", listener, new Runnable()
- {
+ final String uid, final MessagingListener listener) {
+ put("loadMessageForViewRemote", listener, new Runnable() {
@Override
- public void run()
- {
+ public void run() {
Folder remoteFolder = null;
LocalFolder localFolder = null;
- try
- {
+ try {
LocalStore localStore = account.getLocalStore();
localFolder = localStore.getFolder(folder);
localFolder.open(OpenMode.READ_WRITE);
Message message = localFolder.getMessage(uid);
- if (message.isSet(Flag.X_DOWNLOADED_FULL))
- {
+ if (message.isSet(Flag.X_DOWNLOADED_FULL)) {
/*
* If the message has been synchronized since we were called we'll
* just hand it back cause it's ready to go.
@@ -3120,9 +2576,7 @@ public class MessagingController implements Runnable
fp.add(FetchProfile.Item.ENVELOPE);
fp.add(FetchProfile.Item.BODY);
localFolder.fetch(new Message[] { message }, fp, null);
- }
- else
- {
+ } else {
/*
* At this point the message is not available, so we need to download it
* fully if possible.
@@ -3149,31 +2603,23 @@ public class MessagingController implements Runnable
}
// now that we have the full message, refresh the headers
- for (MessagingListener l : getListeners(listener))
- {
+ for (MessagingListener l : getListeners(listener)) {
l.loadMessageForViewHeadersAvailable(account, folder, uid, message);
}
- for (MessagingListener l : getListeners(listener))
- {
+ for (MessagingListener l : getListeners(listener)) {
l.loadMessageForViewBodyAvailable(account, folder, uid, message);
}
- for (MessagingListener l : getListeners(listener))
- {
+ for (MessagingListener l : getListeners(listener)) {
l.loadMessageForViewFinished(account, folder, uid, message);
}
- }
- catch (Exception e)
- {
- for (MessagingListener l : getListeners(listener))
- {
+ } catch (Exception e) {
+ for (MessagingListener l : getListeners(listener)) {
l.loadMessageForViewFailed(account, folder, uid, e);
}
addErrorMessage(account, null, e);
- }
- finally
- {
+ } finally {
closeFolder(remoteFolder);
closeFolder(localFolder);
}
@@ -3182,65 +2628,51 @@ public class MessagingController implements Runnable
}
public void loadMessageForView(final Account account, final String folder, final String uid,
- final MessagingListener listener)
- {
- for (MessagingListener l : getListeners(listener))
- {
+ final MessagingListener listener) {
+ for (MessagingListener l : getListeners(listener)) {
l.loadMessageForViewStarted(account, folder, uid);
}
- threadPool.execute(new Runnable()
- {
+ threadPool.execute(new Runnable() {
@Override
- public void run()
- {
+ public void run() {
- try
- {
+ try {
LocalStore localStore = account.getLocalStore();
LocalFolder localFolder = localStore.getFolder(folder);
localFolder.open(OpenMode.READ_WRITE);
LocalMessage message = (LocalMessage)localFolder.getMessage(uid);
- if (message==null
- || message.getId()==0)
- {
+ if (message == null
+ || message.getId() == 0) {
throw new IllegalArgumentException("Message not found: folder=" + folder + ", uid=" + uid);
}
- if (!message.isSet(Flag.SEEN))
- {
+ if (!message.isSet(Flag.SEEN)) {
message.setFlag(Flag.SEEN, true);
setFlag(new Message[] { message }, Flag.SEEN, true);
}
- for (MessagingListener l : getListeners(listener))
- {
+ for (MessagingListener l : getListeners(listener)) {
l.loadMessageForViewHeadersAvailable(account, folder, uid, message);
}
FetchProfile fp = new FetchProfile();
fp.add(FetchProfile.Item.ENVELOPE);
fp.add(FetchProfile.Item.BODY);
- localFolder.fetch(new Message[]
- {
+ localFolder.fetch(new Message[] {
message
}, fp, null);
localFolder.close();
- for (MessagingListener l : getListeners(listener))
- {
+ for (MessagingListener l : getListeners(listener)) {
l.loadMessageForViewBodyAvailable(account, folder, uid, message);
}
- for (MessagingListener l : getListeners(listener))
- {
+ for (MessagingListener l : getListeners(listener)) {
l.loadMessageForViewFinished(account, folder, uid, message);
}
- }
- catch (Exception e)
- {
- for (MessagingListener l : getListeners(listener))
- {
+ } catch (Exception e) {
+ for (MessagingListener l : getListeners(listener)) {
l.loadMessageForViewFailed(account, folder, uid, e);
}
addErrorMessage(account, null, e);
@@ -3262,31 +2694,25 @@ public class MessagingController implements Runnable
final Message message,
final Part part,
final Object tag,
- final MessagingListener listener)
- {
+ final MessagingListener listener) {
/*
* Check if the attachment has already been downloaded. If it has there's no reason to
* download it, so we just tell the listener that it's ready to go.
*/
- if (part.getBody() != null)
- {
- for (MessagingListener l : getListeners())
- {
+ if (part.getBody() != null) {
+ for (MessagingListener l : getListeners()) {
l.loadAttachmentStarted(account, message, part, tag, false);
}
- if (listener != null)
- {
+ if (listener != null) {
listener.loadAttachmentStarted(account, message, part, tag, false);
}
- for (MessagingListener l : getListeners())
- {
+ for (MessagingListener l : getListeners()) {
l.loadAttachmentFinished(account, message, part, tag);
}
- if (listener != null)
- {
+ if (listener != null) {
listener.loadAttachmentFinished(account, message, part, tag);
}
return;
@@ -3294,31 +2720,25 @@ public class MessagingController implements Runnable
- for (MessagingListener l : getListeners())
- {
+ for (MessagingListener l : getListeners()) {
l.loadAttachmentStarted(account, message, part, tag, true);
}
- if (listener != null)
- {
+ if (listener != null) {
listener.loadAttachmentStarted(account, message, part, tag, false);
}
- put("loadAttachment", listener, new Runnable()
- {
+ put("loadAttachment", listener, new Runnable() {
@Override
- public void run()
- {
+ public void run() {
Folder remoteFolder = null;
LocalFolder localFolder = null;
- try
- {
+ try {
LocalStore localStore = account.getLocalStore();
ArrayList viewables = new ArrayList();
ArrayList attachments = new ArrayList();
MimeUtility.collectParts(message, viewables, attachments);
- for (Part attachment : attachments)
- {
+ for (Part attachment : attachments) {
attachment.setBody(null);
}
Store remoteStore = account.getRemoteStore();
@@ -3332,33 +2752,25 @@ public class MessagingController implements Runnable
remoteFolder.fetchPart(remoteMessage, part, null);
localFolder.updateMessage((LocalMessage)message);
- for (MessagingListener l : getListeners())
- {
+ for (MessagingListener l : getListeners()) {
l.loadAttachmentFinished(account, message, part, tag);
}
- if (listener != null)
- {
+ if (listener != null) {
listener.loadAttachmentFinished(account, message, part, tag);
}
- }
- catch (MessagingException me)
- {
+ } catch (MessagingException me) {
if (K9.DEBUG)
Log.v(K9.LOG_TAG, "Exception loading attachment", me);
- for (MessagingListener l : getListeners())
- {
+ for (MessagingListener l : getListeners()) {
l.loadAttachmentFailed(account, message, part, tag, me.getMessage());
}
- if (listener != null)
- {
+ if (listener != null) {
listener.loadAttachmentFailed(account, message, part, tag, me.getMessage());
}
addErrorMessage(account, null, me);
- }
- finally
- {
+ } finally {
closeFolder(localFolder);
closeFolder(remoteFolder);
}
@@ -3375,10 +2787,8 @@ public class MessagingController implements Runnable
*/
public void sendMessage(final Account account,
final Message message,
- MessagingListener listener)
- {
- try
- {
+ MessagingListener listener) {
+ try {
LocalStore localStore = account.getLocalStore();
LocalFolder localFolder = localStore.getFolder(account.getOutboxFolderName());
localFolder.open(OpenMode.READ_WRITE);
@@ -3387,9 +2797,7 @@ public class MessagingController implements Runnable
localMessage.setFlag(Flag.X_DOWNLOADED_FULL, true);
localFolder.close();
sendPendingMessages(account, listener);
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
/*
for (MessagingListener l : getListeners())
{
@@ -3402,12 +2810,10 @@ public class MessagingController implements Runnable
}
- public void sendPendingMessages(MessagingListener listener)
- {
+ public void sendPendingMessages(MessagingListener listener) {
final Preferences prefs = Preferences.getPreferences(mApplication.getApplicationContext());
Account[] accounts = prefs.getAccounts();
- for (Account account : accounts)
- {
+ for (Account account : accounts) {
sendPendingMessages(account, listener);
}
}
@@ -3419,29 +2825,21 @@ public class MessagingController implements Runnable
* @param listener
*/
public void sendPendingMessages(final Account account,
- MessagingListener listener)
- {
- putBackground("sendPendingMessages", listener, new Runnable()
- {
+ MessagingListener listener) {
+ putBackground("sendPendingMessages", listener, new Runnable() {
@Override
- public void run()
- {
- if (!account.isAvailable(mApplication))
- {
+ public void run() {
+ if (!account.isAvailable(mApplication)) {
throw new UnavailableAccountException();
}
- if (messagesPendingSend(account))
- {
+ if (messagesPendingSend(account)) {
notifyWhileSending(account);
- try
- {
+ try {
sendPendingMessagesSynchronous(account);
- }
- finally
- {
+ } finally {
notifyWhileSendingDone(account);
}
}
@@ -3449,26 +2847,21 @@ public class MessagingController implements Runnable
});
}
- private void cancelNotification(int id)
- {
+ private void cancelNotification(int id) {
NotificationManager notifMgr =
(NotificationManager)mApplication.getSystemService(Context.NOTIFICATION_SERVICE);
notifMgr.cancel(id);
}
- private void notifyWhileSendingDone(Account account)
- {
- if (account.isShowOngoing())
- {
+ private void notifyWhileSendingDone(Account account) {
+ if (account.isShowOngoing()) {
cancelNotification(K9.FETCHING_EMAIL_NOTIFICATION - account.getAccountNumber());
}
}
- private void notifyWhileSending(Account account)
- {
- if (!account.isShowOngoing())
- {
+ private void notifyWhileSending(Account account) {
+ if (!account.isShowOngoing()) {
return;
}
NotificationManager notifMgr =
@@ -3481,16 +2874,14 @@ public class MessagingController implements Runnable
account.getDescription() , pi);
notif.flags = Notification.FLAG_ONGOING_EVENT;
- if (K9.NOTIFICATION_LED_WHILE_SYNCING)
- {
+ if (K9.NOTIFICATION_LED_WHILE_SYNCING) {
configureNotification(notif, null, null, account.getNotificationSetting().getLedColor(), K9.NOTIFICATION_LED_BLINK_FAST, true);
}
notifMgr.notify(K9.FETCHING_EMAIL_NOTIFICATION - account.getAccountNumber(), notif);
}
- private void notifySendFailed(Account account, Exception lastFailure)
- {
+ private void notifySendFailed(Account account, Exception lastFailure) {
NotificationManager notifMgr = (NotificationManager)mApplication.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notif = new Notification(R.drawable.stat_notify_email_generic, mApplication.getString(R.string.send_failure_subject), System.currentTimeMillis());
@@ -3506,10 +2897,8 @@ public class MessagingController implements Runnable
}
- private void notifyFetchingMail(final Account account, final Folder folder)
- {
- if (account.isShowOngoing())
- {
+ private void notifyFetchingMail(final Account account, final Folder folder) {
+ if (account.isShowOngoing()) {
final NotificationManager notifMgr = (NotificationManager)mApplication
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notif = new Notification(R.drawable.ic_menu_refresh,
@@ -3521,47 +2910,36 @@ public class MessagingController implements Runnable
+ mApplication.getString(R.string.notification_bg_title_separator) + folder.getName(), pi);
notif.flags = Notification.FLAG_ONGOING_EVENT;
- if (K9.NOTIFICATION_LED_WHILE_SYNCING)
- {
+ if (K9.NOTIFICATION_LED_WHILE_SYNCING) {
configureNotification(notif, null, null, account.getNotificationSetting().getLedColor(), K9.NOTIFICATION_LED_BLINK_FAST, true);
}
notifMgr.notify(K9.FETCHING_EMAIL_NOTIFICATION - account.getAccountNumber(), notif);
}
}
- private void notifyFetchingMailCancel (final Account account)
- {
- if (account.isShowOngoing())
- {
+ private void notifyFetchingMailCancel(final Account account) {
+ if (account.isShowOngoing()) {
cancelNotification(K9.FETCHING_EMAIL_NOTIFICATION - account.getAccountNumber());
}
}
- public boolean messagesPendingSend(final Account account)
- {
+ public boolean messagesPendingSend(final Account account) {
Folder localFolder = null;
- try
- {
+ try {
localFolder = account.getLocalStore().getFolder(
account.getOutboxFolderName());
- if (!localFolder.exists())
- {
+ if (!localFolder.exists()) {
return false;
}
localFolder.open(OpenMode.READ_WRITE);
- if (localFolder.getMessageCount() > 0)
- {
+ if (localFolder.getMessageCount() > 0) {
return true;
}
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
Log.e(K9.LOG_TAG, "Exception while checking for unsent messages", e);
- }
- finally
- {
+ } finally {
closeFolder(localFolder);
}
return false;
@@ -3571,21 +2949,17 @@ public class MessagingController implements Runnable
* Attempt to send any messages that are sitting in the Outbox.
* @param account
*/
- public void sendPendingMessagesSynchronous(final Account account)
- {
+ public void sendPendingMessagesSynchronous(final Account account) {
Folder localFolder = null;
Exception lastFailure = null;
- try
- {
+ try {
Store localStore = account.getLocalStore();
localFolder = localStore.getFolder(
account.getOutboxFolderName());
- if (!localFolder.exists())
- {
+ if (!localFolder.exists()) {
return;
}
- for (MessagingListener l : getListeners())
- {
+ for (MessagingListener l : getListeners()) {
l.sendPendingMessagesStarted(account);
}
localFolder.open(OpenMode.READ_WRITE);
@@ -3593,8 +2967,7 @@ public class MessagingController implements Runnable
Message[] localMessages = localFolder.getMessages(null);
int progress = 0;
int todo = localMessages.length;
- for (MessagingListener l : getListeners())
- {
+ for (MessagingListener l : getListeners()) {
l.synchronizeMailboxProgress(account, account.getSentFolderName(), progress, todo);
}
/*
@@ -3609,19 +2982,15 @@ public class MessagingController implements Runnable
Log.i(K9.LOG_TAG, "Scanning folder '" + account.getOutboxFolderName() + "' (" + ((LocalFolder)localFolder).getId() + ") for messages to send");
Transport transport = Transport.getInstance(account);
- for (Message message : localMessages)
- {
- if (message.isSet(Flag.DELETED))
- {
+ for (Message message : localMessages) {
+ if (message.isSet(Flag.DELETED)) {
message.destroy();
continue;
}
- try
- {
+ try {
AtomicInteger count = new AtomicInteger(0);
AtomicInteger oldCount = sendCount.putIfAbsent(message.getUid(), count);
- if (oldCount != null)
- {
+ if (oldCount != null) {
count = oldCount;
}
@@ -3629,8 +2998,7 @@ public class MessagingController implements Runnable
Log.i(K9.LOG_TAG, "Send count for message " + message.getUid() + " is " + count.get());
localFolder.fetch(new Message[] { message }, fp, null);
- try
- {
+ try {
message.setFlag(Flag.X_SEND_IN_PROGRESS, true);
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "Sending message with UID " + message.getUid());
@@ -3638,23 +3006,19 @@ public class MessagingController implements Runnable
message.setFlag(Flag.X_SEND_IN_PROGRESS, false);
message.setFlag(Flag.SEEN, true);
progress++;
- for (MessagingListener l : getListeners())
- {
+ for (MessagingListener l : getListeners()) {
l.synchronizeMailboxProgress(account, account.getSentFolderName(), progress, todo);
}
- if (K9.FOLDER_NONE.equals(account.getSentFolderName()))
- {
+ if (K9.FOLDER_NONE.equals(account.getSentFolderName())) {
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "Sent folder set to " + K9.FOLDER_NONE + ", deleting sent message");
message.setFlag(Flag.DELETED, true);
- }
- else
- {
- LocalFolder localSentFolder = (LocalFolder) localStore.getFolder( account.getSentFolderName());
+ } else {
+ LocalFolder localSentFolder = (LocalFolder) localStore.getFolder(account.getSentFolderName());
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "Moving sent message to folder '" + account.getSentFolderName() + "' (" + localSentFolder.getId() + ") ");
- localFolder.moveMessages( new Message[] { message }, localSentFolder);
+ localFolder.moveMessages(new Message[] { message }, localSentFolder);
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "Moved sent message to folder '" + account.getSentFolderName() + "' (" + localSentFolder.getId() + ") ");
@@ -3666,55 +3030,39 @@ public class MessagingController implements Runnable
processPendingCommands(account);
}
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
message.setFlag(Flag.X_SEND_FAILED, true);
Log.e(K9.LOG_TAG, "Failed to send message", e);
- for (MessagingListener l : getListeners())
- {
- l.synchronizeMailboxFailed( account, localFolder.getName(), getRootCauseMessage(e));
+ for (MessagingListener l : getListeners()) {
+ l.synchronizeMailboxFailed(account, localFolder.getName(), getRootCauseMessage(e));
}
lastFailure = e;
}
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
Log.e(K9.LOG_TAG, "Failed to fetch message for sending", e);
- for (MessagingListener l : getListeners())
- {
- l.synchronizeMailboxFailed( account, localFolder.getName(), getRootCauseMessage(e));
+ for (MessagingListener l : getListeners()) {
+ l.synchronizeMailboxFailed(account, localFolder.getName(), getRootCauseMessage(e));
}
lastFailure = e;
}
}
- for (MessagingListener l : getListeners())
- {
+ for (MessagingListener l : getListeners()) {
l.sendPendingMessagesCompleted(account);
}
- if (lastFailure != null)
- {
+ if (lastFailure != null) {
notifySendFailed(account, lastFailure);
}
- }
- catch (UnavailableStorageException e)
- {
+ } catch (UnavailableStorageException e) {
Log.i(K9.LOG_TAG, "Failed to send pending messages because storage is not available - trying again later.");
throw new UnavailableAccountException(e);
- }
- catch (Exception e)
- {
- for (MessagingListener l : getListeners())
- {
+ } catch (Exception e) {
+ for (MessagingListener l : getListeners()) {
l.sendPendingMessagesFailed(account);
}
addErrorMessage(account, null, e);
- }
- finally
- {
- if (lastFailure == null)
- {
+ } finally {
+ if (lastFailure == null) {
cancelNotification(K9.SEND_FAILED_NOTIFICATION - account.getAccountNumber());
}
closeFolder(localFolder);
@@ -3722,20 +3070,14 @@ public class MessagingController implements Runnable
}
public void getAccountStats(final Context context, final Account account,
- final MessagingListener l)
- {
- Runnable unreadRunnable = new Runnable()
- {
+ final MessagingListener l) {
+ Runnable unreadRunnable = new Runnable() {
@Override
- public void run()
- {
- try
- {
+ public void run() {
+ try {
AccountStats stats = account.getStats(context);
l.accountStatusChanged(account, stats);
- }
- catch (MessagingException me)
- {
+ } catch (MessagingException me) {
Log.e(K9.LOG_TAG, "Count not get unread count for account " + account.getDescription(),
me);
}
@@ -3747,22 +3089,16 @@ public class MessagingController implements Runnable
}
public void getFolderUnreadMessageCount(final Account account, final String folderName,
- final MessagingListener l)
- {
- Runnable unreadRunnable = new Runnable()
- {
+ final MessagingListener l) {
+ Runnable unreadRunnable = new Runnable() {
@Override
- public void run()
- {
+ public void run() {
int unreadMessageCount = 0;
- try
- {
+ try {
Folder localFolder = account.getLocalStore().getFolder(folderName);
unreadMessageCount = localFolder.getUnreadMessageCount();
- }
- catch (MessagingException me)
- {
+ } catch (MessagingException me) {
Log.e(K9.LOG_TAG, "Count not get unread count for account " + account.getDescription(), me);
}
l.folderStatusChanged(account, folderName, unreadMessageCount);
@@ -3775,98 +3111,75 @@ public class MessagingController implements Runnable
- public boolean isMoveCapable(Message message)
- {
+ public boolean isMoveCapable(Message message) {
return !message.getUid().startsWith(K9.LOCAL_UID_PREFIX);
}
- public boolean isCopyCapable(Message message)
- {
+ public boolean isCopyCapable(Message message) {
return isMoveCapable(message);
}
- public boolean isMoveCapable(final Account account)
- {
- try
- {
+ public boolean isMoveCapable(final Account account) {
+ try {
Store localStore = account.getLocalStore();
Store remoteStore = account.getRemoteStore();
return localStore.isMoveCapable() && remoteStore.isMoveCapable();
- }
- catch (MessagingException me)
- {
+ } catch (MessagingException me) {
Log.e(K9.LOG_TAG, "Exception while ascertaining move capability", me);
return false;
}
}
- public boolean isCopyCapable(final Account account)
- {
- try
- {
+ public boolean isCopyCapable(final Account account) {
+ try {
Store localStore = account.getLocalStore();
Store remoteStore = account.getRemoteStore();
return localStore.isCopyCapable() && remoteStore.isCopyCapable();
- }
- catch (MessagingException me)
- {
+ } catch (MessagingException me) {
Log.e(K9.LOG_TAG, "Exception while ascertaining copy capability", me);
return false;
}
}
public void moveMessages(final Account account, final String srcFolder, final Message[] messages, final String destFolder,
- final MessagingListener listener)
- {
- for (Message message : messages)
- {
+ final MessagingListener listener) {
+ for (Message message : messages) {
suppressMessage(account, srcFolder, message);
}
- putBackground("moveMessages", null, new Runnable()
- {
+ putBackground("moveMessages", null, new Runnable() {
@Override
- public void run()
- {
+ public void run() {
moveOrCopyMessageSynchronous(account, srcFolder, messages, destFolder, false, listener);
}
});
}
public void moveMessage(final Account account, final String srcFolder, final Message message, final String destFolder,
- final MessagingListener listener)
- {
+ final MessagingListener listener) {
moveMessages(account, srcFolder, new Message[] { message }, destFolder, listener);
}
public void copyMessages(final Account account, final String srcFolder, final Message[] messages, final String destFolder,
- final MessagingListener listener)
- {
- putBackground("copyMessages", null, new Runnable()
- {
+ final MessagingListener listener) {
+ putBackground("copyMessages", null, new Runnable() {
@Override
- public void run()
- {
+ public void run() {
moveOrCopyMessageSynchronous(account, srcFolder, messages, destFolder, true, listener);
}
});
}
public void copyMessage(final Account account, final String srcFolder, final Message message, final String destFolder,
- final MessagingListener listener)
- {
+ final MessagingListener listener) {
copyMessages(account, srcFolder, new Message[] { message }, destFolder, listener);
}
private void moveOrCopyMessageSynchronous(final Account account, final String srcFolder, final Message[] inMessages,
- final String destFolder, final boolean isCopy, MessagingListener listener)
- {
- try
- {
+ final String destFolder, final boolean isCopy, MessagingListener listener) {
+ try {
Store localStore = account.getLocalStore();
Store remoteStore = account.getRemoteStore();
- if (!isCopy && (!remoteStore.isMoveCapable() || !localStore.isMoveCapable()))
- {
+ if (!isCopy && (!remoteStore.isMoveCapable() || !localStore.isMoveCapable())) {
return;
}
- if (isCopy && (!remoteStore.isCopyCapable() || !localStore.isCopyCapable()))
- {
+ if (isCopy && (!remoteStore.isCopyCapable() || !localStore.isCopyCapable())) {
return;
}
@@ -3874,22 +3187,18 @@ public class MessagingController implements Runnable
Folder localDestFolder = localStore.getFolder(destFolder);
List uids = new LinkedList();
- for (Message message : inMessages)
- {
+ for (Message message : inMessages) {
String uid = message.getUid();
- if (!uid.startsWith(K9.LOCAL_UID_PREFIX))
- {
+ if (!uid.startsWith(K9.LOCAL_UID_PREFIX)) {
uids.add(uid);
}
}
Message[] messages = localSrcFolder.getMessages(uids.toArray(EMPTY_STRING_ARRAY), null);
- if (messages.length > 0)
- {
+ if (messages.length > 0) {
Map origUidMap = new HashMap();
- for (Message message : messages)
- {
+ for (Message message : messages) {
origUidMap.put(message.getUid(), message);
}
@@ -3897,21 +3206,16 @@ public class MessagingController implements Runnable
Log.i(K9.LOG_TAG, "moveOrCopyMessageSynchronous: source folder = " + srcFolder
+ ", " + messages.length + " messages, " + ", destination folder = " + destFolder + ", isCopy = " + isCopy);
- if (isCopy)
- {
+ if (isCopy) {
FetchProfile fp = new FetchProfile();
fp.add(FetchProfile.Item.ENVELOPE);
fp.add(FetchProfile.Item.BODY);
localSrcFolder.fetch(messages, fp, null);
localSrcFolder.copyMessages(messages, localDestFolder);
- }
- else
- {
+ } else {
localSrcFolder.moveMessages(messages, localDestFolder);
- for (String origUid : origUidMap.keySet())
- {
- for (MessagingListener l : getListeners())
- {
+ for (String origUid : origUidMap.keySet()) {
+ for (MessagingListener l : getListeners()) {
l.messageUidChanged(account, srcFolder, origUid, origUidMap.get(origUid).getUid());
}
unsuppressMessage(account, srcFolder, origUid);
@@ -3922,75 +3226,55 @@ public class MessagingController implements Runnable
}
processPendingCommands(account);
- }
- catch (UnavailableStorageException e)
- {
+ } catch (UnavailableStorageException e) {
Log.i(K9.LOG_TAG, "Failed to move/copy message because storage is not available - trying again later.");
throw new UnavailableAccountException(e);
- }
- catch (MessagingException me)
- {
+ } catch (MessagingException me) {
addErrorMessage(account, null, me);
throw new RuntimeException("Error moving message", me);
}
}
- public void expunge(final Account account, final String folder, final MessagingListener listener)
- {
- putBackground("expunge", null, new Runnable()
- {
+ public void expunge(final Account account, final String folder, final MessagingListener listener) {
+ putBackground("expunge", null, new Runnable() {
@Override
- public void run()
- {
+ public void run() {
queueExpunge(account, folder);
}
});
}
- public void deleteDraft(final Account account, String uid)
- {
+ public void deleteDraft(final Account account, String uid) {
LocalFolder localFolder = null;
- try
- {
+ try {
LocalStore localStore = account.getLocalStore();
localFolder = localStore.getFolder(account.getDraftsFolderName());
localFolder.open(OpenMode.READ_WRITE);
Message message = localFolder.getMessage(uid);
- if (message != null)
- {
+ if (message != null) {
deleteMessages(new Message[] { message }, null);
}
- }
- catch (MessagingException me)
- {
+ } catch (MessagingException me) {
addErrorMessage(account, null, me);
- }
- finally
- {
+ } finally {
closeFolder(localFolder);
}
}
- public void deleteMessages(final Message[] messages, final MessagingListener listener)
- {
- actOnMessages(messages, new MessageActor()
- {
+ public void deleteMessages(final Message[] messages, final MessagingListener listener) {
+ actOnMessages(messages, new MessageActor() {
@Override
public void act(final Account account, final Folder folder,
- final List messages)
- {
- for (Message message : messages)
- {
+ final List messages) {
+ for (Message message : messages) {
suppressMessage(account, folder.getName(), message);
}
- putBackground("deleteMessages", null, new Runnable()
- {
+ putBackground("deleteMessages", null, new Runnable() {
@Override
- public void run()
- {
+ public void run() {
deleteMessagesSynchronous(account, folder.getName(), messages.toArray(EMPTY_MESSAGE_ARRAY), listener);
}
});
@@ -4001,44 +3285,34 @@ public class MessagingController implements Runnable
}
private void deleteMessagesSynchronous(final Account account, final String folder, final Message[] messages,
- MessagingListener listener)
- {
+ MessagingListener listener) {
Folder localFolder = null;
Folder localTrashFolder = null;
String[] uids = getUidsFromMessages(messages);
- try
- {
+ try {
//We need to make these callbacks before moving the messages to the trash
//as messages get a new UID after being moved
- for (Message message : messages)
- {
- if (listener != null)
- {
+ for (Message message : messages) {
+ if (listener != null) {
listener.messageDeleted(account, folder, message);
}
- for (MessagingListener l : getListeners())
- {
+ for (MessagingListener l : getListeners()) {
l.messageDeleted(account, folder, message);
}
}
Store localStore = account.getLocalStore();
localFolder = localStore.getFolder(folder);
- if (folder.equals(account.getTrashFolderName()) || K9.FOLDER_NONE.equals(account.getTrashFolderName()))
- {
+ if (folder.equals(account.getTrashFolderName()) || K9.FOLDER_NONE.equals(account.getTrashFolderName())) {
if (K9.DEBUG)
Log.d(K9.LOG_TAG, "Deleting messages in trash folder or trash set to -None-, not copying");
localFolder.setFlags(messages, new Flag[] { Flag.DELETED }, true);
- }
- else
- {
+ } else {
localTrashFolder = localStore.getFolder(account.getTrashFolderName());
- if (!localTrashFolder.exists())
- {
+ if (!localTrashFolder.exists()) {
localTrashFolder.create(Folder.FolderType.HOLDS_MESSAGES);
}
- if (localTrashFolder.exists())
- {
+ if (localTrashFolder.exists()) {
if (K9.DEBUG)
Log.d(K9.LOG_TAG, "Deleting messages in normal folder, moving");
@@ -4047,11 +3321,9 @@ public class MessagingController implements Runnable
}
}
- for (MessagingListener l : getListeners())
- {
+ for (MessagingListener l : getListeners()) {
l.folderStatusChanged(account, folder, localFolder.getUnreadMessageCount());
- if (localTrashFolder != null)
- {
+ if (localTrashFolder != null) {
l.folderStatusChanged(account, account.getTrashFolderName(), localTrashFolder.getUnreadMessageCount());
}
}
@@ -4059,92 +3331,67 @@ public class MessagingController implements Runnable
if (K9.DEBUG)
Log.d(K9.LOG_TAG, "Delete policy for account " + account.getDescription() + " is " + account.getDeletePolicy());
- if (folder.equals(account.getOutboxFolderName()))
- {
- for (Message message : messages)
- {
+ if (folder.equals(account.getOutboxFolderName())) {
+ for (Message message : messages) {
// If the message was in the Outbox, then it has been copied to local Trash, and has
// to be copied to remote trash
PendingCommand command = new PendingCommand();
command.command = PENDING_COMMAND_APPEND;
command.arguments =
- new String[]
- {
+ new String[] {
account.getTrashFolderName(),
message.getUid()
};
queuePendingCommand(account, command);
}
processPendingCommands(account);
- }
- else if ( account.getDeletePolicy() == Account.DELETE_POLICY_ON_DELETE)
- {
- if (folder.equals(account.getTrashFolderName()))
- {
+ } else if (account.getDeletePolicy() == Account.DELETE_POLICY_ON_DELETE) {
+ if (folder.equals(account.getTrashFolderName())) {
queueSetFlag(account, folder, Boolean.toString(true), Flag.DELETED.toString(), uids);
- }
- else
- {
+ } else {
queueMoveOrCopy(account, folder, account.getTrashFolderName(), false, uids);
}
processPendingCommands(account);
- }
- else if (account.getDeletePolicy() == Account.DELETE_POLICY_MARK_AS_READ)
- {
+ } else if (account.getDeletePolicy() == Account.DELETE_POLICY_MARK_AS_READ) {
queueSetFlag(account, folder, Boolean.toString(true), Flag.SEEN.toString(), uids);
processPendingCommands(account);
- }
- else
- {
+ } else {
if (K9.DEBUG)
Log.d(K9.LOG_TAG, "Delete policy " + account.getDeletePolicy() + " prevents delete from server");
}
- for (String uid : uids)
- {
+ for (String uid : uids) {
unsuppressMessage(account, folder, uid);
}
- }
- catch (UnavailableStorageException e)
- {
+ } catch (UnavailableStorageException e) {
Log.i(K9.LOG_TAG, "Failed to delete message because storage is not available - trying again later.");
throw new UnavailableAccountException(e);
- }
- catch (MessagingException me)
- {
+ } catch (MessagingException me) {
addErrorMessage(account, null, me);
throw new RuntimeException("Error deleting message from local store.", me);
- }
- finally
- {
+ } finally {
closeFolder(localFolder);
closeFolder(localTrashFolder);
}
}
- private String[] getUidsFromMessages(Message[] messages)
- {
+ private String[] getUidsFromMessages(Message[] messages) {
String[] uids = new String[messages.length];
- for (int i = 0; i < messages.length; i++)
- {
+ for (int i = 0; i < messages.length; i++) {
uids[i] = messages[i].getUid();
}
return uids;
}
- private void processPendingEmptyTrash(PendingCommand command, Account account) throws MessagingException
- {
+ private void processPendingEmptyTrash(PendingCommand command, Account account) throws MessagingException {
Store remoteStore = account.getRemoteStore();
Folder remoteFolder = remoteStore.getFolder(account.getTrashFolderName());
- try
- {
- if (remoteFolder.exists())
- {
+ try {
+ if (remoteFolder.exists()) {
remoteFolder.open(OpenMode.READ_WRITE);
remoteFolder.setFlags(new Flag [] { Flag.DELETED }, true);
- if (Account.EXPUNGE_IMMEDIATELY.equals(account.getExpungePolicy()))
- {
+ if (Account.EXPUNGE_IMMEDIATELY.equals(account.getExpungePolicy())) {
remoteFolder.expunge();
}
@@ -4155,30 +3402,23 @@ public class MessagingController implements Runnable
}
- }
- finally
- {
+ } finally {
closeFolder(remoteFolder);
}
}
- public void emptyTrash(final Account account, MessagingListener listener)
- {
- putBackground("emptyTrash", listener, new Runnable()
- {
+ public void emptyTrash(final Account account, MessagingListener listener) {
+ putBackground("emptyTrash", listener, new Runnable() {
@Override
- public void run()
- {
+ public void run() {
Folder localFolder = null;
- try
- {
+ try {
Store localStore = account.getLocalStore();
localFolder = localStore.getFolder(account.getTrashFolderName());
localFolder.open(OpenMode.READ_WRITE);
localFolder.setFlags(new Flag[] { Flag.DELETED }, true);
- for (MessagingListener l : getListeners())
- {
+ for (MessagingListener l : getListeners()) {
l.emptyTrashCompleted(account);
}
List args = new ArrayList();
@@ -4187,67 +3427,52 @@ public class MessagingController implements Runnable
command.arguments = args.toArray(EMPTY_STRING_ARRAY);
queuePendingCommand(account, command);
processPendingCommands(account);
- }
- catch (UnavailableStorageException e)
- {
+ } catch (UnavailableStorageException e) {
Log.i(K9.LOG_TAG, "Failed to empty trash because storage is not available - trying again later.");
throw new UnavailableAccountException(e);
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
Log.e(K9.LOG_TAG, "emptyTrash failed", e);
addErrorMessage(account, null, e);
- }
- finally
- {
+ } finally {
closeFolder(localFolder);
}
}
});
}
- public void sendAlternate(final Context context, Account account, Message message)
- {
+ public void sendAlternate(final Context context, Account account, Message message) {
if (K9.DEBUG)
Log.d(K9.LOG_TAG, "About to load message " + account.getDescription() + ":" + message.getFolder().getName()
+ ":" + message.getUid() + " for sendAlternate");
loadMessageForView(account, message.getFolder().getName(),
- message.getUid(), new MessagingListener()
- {
+ message.getUid(), new MessagingListener() {
@Override
public void loadMessageForViewBodyAvailable(Account account, String folder, String uid,
- Message message)
- {
+ Message message) {
if (K9.DEBUG)
Log.d(K9.LOG_TAG, "Got message " + account.getDescription() + ":" + folder
+ ":" + message.getUid() + " for sendAlternate");
- try
- {
- Intent msg=new Intent(Intent.ACTION_SEND);
+ try {
+ Intent msg = new Intent(Intent.ACTION_SEND);
String quotedText = null;
Part part = MimeUtility.findFirstPartByMimeType(message,
"text/plain");
- if (part == null)
- {
+ if (part == null) {
part = MimeUtility.findFirstPartByMimeType(message, "text/html");
}
- if (part != null)
- {
+ if (part != null) {
quotedText = MimeUtility.getTextFromPart(part);
}
- if (quotedText != null)
- {
+ if (quotedText != null) {
msg.putExtra(Intent.EXTRA_TEXT, quotedText);
}
msg.putExtra(Intent.EXTRA_SUBJECT, "Fwd: " + message.getSubject());
msg.setType("text/plain");
context.startActivity(Intent.createChooser(msg, context.getString(R.string.send_alternate_chooser_title)));
- }
- catch (MessagingException me)
- {
+ } catch (MessagingException me) {
Log.e(K9.LOG_TAG, "Unable to send email through alternate program", me);
}
}
@@ -4266,12 +3491,10 @@ public class MessagingController implements Runnable
public void checkMail(final Context context, final Account account,
final boolean ignoreLastCheckedTime,
final boolean useManualWakeLock,
- final MessagingListener listener)
- {
+ final MessagingListener listener) {
TracingWakeLock twakeLock = null;
- if (useManualWakeLock)
- {
+ if (useManualWakeLock) {
TracingPowerManager pm = TracingPowerManager.getPowerManager(context);
twakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "K9 MessagingController.checkMail");
@@ -4280,61 +3503,46 @@ public class MessagingController implements Runnable
}
final TracingWakeLock wakeLock = twakeLock;
- for (MessagingListener l : getListeners())
- {
+ for (MessagingListener l : getListeners()) {
l.checkMailStarted(context, account);
}
- putBackground("checkMail", listener, new Runnable()
- {
+ putBackground("checkMail", listener, new Runnable() {
@Override
- public void run()
- {
+ public void run() {
- try
- {
+ try {
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "Starting mail check");
Preferences prefs = Preferences.getPreferences(context);
Account[] accounts;
- if (account != null)
- {
- accounts = new Account[]
- {
+ if (account != null) {
+ accounts = new Account[] {
account
};
- }
- else
- {
+ } else {
accounts = prefs.getAccounts();
}
- for (final Account account : accounts)
- {
- checkMailForAccount(context, account,ignoreLastCheckedTime, prefs, listener);
+ for (final Account account : accounts) {
+ checkMailForAccount(context, account, ignoreLastCheckedTime, prefs, listener);
}
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
Log.e(K9.LOG_TAG, "Unable to synchronize mail", e);
addErrorMessage(account, null, e);
}
- putBackground("finalize sync", null, new Runnable()
- {
+ putBackground("finalize sync", null, new Runnable() {
@Override
- public void run()
- {
+ public void run() {
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "Finished mail sync");
- if (wakeLock != null)
- {
+ if (wakeLock != null) {
wakeLock.release();
}
- for (MessagingListener l : getListeners())
- {
+ for (MessagingListener l : getListeners()) {
l.checkMailFinished(context, account);
}
@@ -4350,19 +3558,15 @@ public class MessagingController implements Runnable
private void checkMailForAccount(final Context context, final Account account,
final boolean ignoreLastCheckedTime,
final Preferences prefs,
- final MessagingListener listener)
- {
- if (!account.isAvailable(context))
- {
- if (K9.DEBUG)
- {
+ final MessagingListener listener) {
+ if (!account.isAvailable(context)) {
+ if (K9.DEBUG) {
Log.i(K9.LOG_TAG, "Skipping synchronizing unavailable account " + account.getDescription());
}
return;
}
final long accountInterval = account.getAutomaticCheckIntervalMinutes() * 60 * 1000;
- if (!ignoreLastCheckedTime && accountInterval <= 0)
- {
+ if (!ignoreLastCheckedTime && accountInterval <= 0) {
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "Skipping synchronizing account " + account.getDescription());
return;
@@ -4375,22 +3579,19 @@ public class MessagingController implements Runnable
sendPendingMessages(account, listener);
- try
- {
+ try {
Account.FolderMode aDisplayMode = account.getFolderDisplayMode();
Account.FolderMode aSyncMode = account.getFolderSyncMode();
Store localStore = account.getLocalStore();
- for (final Folder folder : localStore.getPersonalNamespaces(false))
- {
+ for (final Folder folder : localStore.getPersonalNamespaces(false)) {
folder.open(Folder.OpenMode.READ_WRITE);
folder.refresh(prefs);
Folder.FolderClass fDisplayClass = folder.getDisplayClass();
Folder.FolderClass fSyncClass = folder.getSyncClass();
- if (modeMismatch(aDisplayMode, fDisplayClass))
- {
+ if (modeMismatch(aDisplayMode, fDisplayClass)) {
// Never sync a folder that isn't displayed
/*
if (K9.DEBUG)
@@ -4401,8 +3602,7 @@ public class MessagingController implements Runnable
continue;
}
- if (modeMismatch(aSyncMode, fSyncClass))
- {
+ if (modeMismatch(aSyncMode, fSyncClass)) {
// Do not sync folders in the wrong class
/*
if (K9.DEBUG)
@@ -4414,32 +3614,22 @@ public class MessagingController implements Runnable
}
synchronizeFolder(account, folder, ignoreLastCheckedTime, accountInterval, listener);
}
- }
- catch (MessagingException e)
- {
+ } catch (MessagingException e) {
Log.e(K9.LOG_TAG, "Unable to synchronize account " + account.getName(), e);
addErrorMessage(account, null, e);
- }
- finally
- {
- putBackground("clear notification flag for " + account.getDescription(), null, new Runnable()
- {
+ } finally {
+ putBackground("clear notification flag for " + account.getDescription(), null, new Runnable() {
@Override
- public void run()
- {
+ public void run() {
if (K9.DEBUG)
Log.v(K9.LOG_TAG, "Clearing notification flag for " + account.getDescription());
account.setRingNotified(false);
- try
- {
+ try {
AccountStats stats = account.getStats(context);
- if (stats == null || stats.unreadMessageCount == 0)
- {
+ if (stats == null || stats.unreadMessageCount == 0) {
notifyAccountCancel(context, account);
}
- }
- catch (MessagingException e)
- {
+ } catch (MessagingException e) {
Log.e(K9.LOG_TAG, "Unable to getUnreadMessageCount for account: " + account, e);
}
}
@@ -4456,8 +3646,7 @@ public class MessagingController implements Runnable
final Folder folder,
final boolean ignoreLastCheckedTime,
final long accountInterval,
- final MessagingListener listener )
- {
+ final MessagingListener listener) {
if (K9.DEBUG)
@@ -4465,8 +3654,7 @@ public class MessagingController implements Runnable
new Date(folder.getLastChecked()));
if (!ignoreLastCheckedTime && folder.getLastChecked() >
- (System.currentTimeMillis() - accountInterval))
- {
+ (System.currentTimeMillis() - accountInterval)) {
if (K9.DEBUG)
Log.v(K9.LOG_TAG, "Not syncing folder " + folder.getName()
+ ", previously synced @ " + new Date(folder.getLastChecked())
@@ -4474,14 +3662,11 @@ public class MessagingController implements Runnable
return;
}
- putBackground("sync" + folder.getName(), null, new Runnable()
- {
+ putBackground("sync" + folder.getName(), null, new Runnable() {
@Override
- public void run()
- {
+ public void run() {
LocalFolder tLocalFolder = null;
- try
- {
+ try {
// In case multiple Commands get enqueued, don't run more than
// once
final LocalStore localStore = account.getLocalStore();
@@ -4489,8 +3674,7 @@ public class MessagingController implements Runnable
tLocalFolder.open(Folder.OpenMode.READ_WRITE);
if (!ignoreLastCheckedTime && tLocalFolder.getLastChecked() >
- (System.currentTimeMillis() - accountInterval))
- {
+ (System.currentTimeMillis() - accountInterval)) {
if (K9.DEBUG)
Log.v(K9.LOG_TAG, "Not running Command for folder " + folder.getName()
+ ", previously synced @ " + new Date(folder.getLastChecked())
@@ -4498,24 +3682,17 @@ public class MessagingController implements Runnable
return;
}
notifyFetchingMail(account, folder);
- try
- {
+ try {
synchronizeMailboxSynchronous(account, folder.getName(), listener, null);
- }
- finally
- {
+ } finally {
notifyFetchingMailCancel(account);
}
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
Log.e(K9.LOG_TAG, "Exception while processing folder " +
account.getDescription() + ":" + folder.getName(), e);
addErrorMessage(account, null, e);
- }
- finally
- {
+ } finally {
closeFolder(tLocalFolder);
}
}
@@ -4527,50 +3704,36 @@ public class MessagingController implements Runnable
- public void compact(final Account account, final MessagingListener ml)
- {
- putBackground("compact:" + account.getDescription(), ml, new Runnable()
- {
+ public void compact(final Account account, final MessagingListener ml) {
+ putBackground("compact:" + account.getDescription(), ml, new Runnable() {
@Override
- public void run()
- {
- try
- {
+ public void run() {
+ try {
LocalStore localStore = account.getLocalStore();
long oldSize = localStore.getSize();
localStore.compact();
long newSize = localStore.getSize();
- if (ml != null)
- {
+ if (ml != null) {
ml.accountSizeChanged(account, oldSize, newSize);
}
- for (MessagingListener l : getListeners())
- {
+ for (MessagingListener l : getListeners()) {
l.accountSizeChanged(account, oldSize, newSize);
}
- }
- catch (UnavailableStorageException e)
- {
+ } catch (UnavailableStorageException e) {
Log.i(K9.LOG_TAG, "Failed to compact account because storage is not available - trying again later.");
throw new UnavailableAccountException(e);
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
Log.e(K9.LOG_TAG, "Failed to compact account " + account.getDescription(), e);
}
}
});
}
- public void clear(final Account account, final MessagingListener ml)
- {
- putBackground("clear:" + account.getDescription(), ml, new Runnable()
- {
+ public void clear(final Account account, final MessagingListener ml) {
+ putBackground("clear:" + account.getDescription(), ml, new Runnable() {
@Override
- public void run()
- {
- try
- {
+ public void run() {
+ try {
LocalStore localStore = account.getLocalStore();
long oldSize = localStore.getSize();
localStore.clear();
@@ -4580,39 +3743,29 @@ public class MessagingController implements Runnable
stats.size = newSize;
stats.unreadMessageCount = 0;
stats.flaggedMessageCount = 0;
- if (ml != null)
- {
+ if (ml != null) {
ml.accountSizeChanged(account, oldSize, newSize);
ml.accountStatusChanged(account, stats);
}
- for (MessagingListener l : getListeners())
- {
+ for (MessagingListener l : getListeners()) {
l.accountSizeChanged(account, oldSize, newSize);
l.accountStatusChanged(account, stats);
}
- }
- catch (UnavailableStorageException e)
- {
+ } catch (UnavailableStorageException e) {
Log.i(K9.LOG_TAG, "Failed to clear account because storage is not available - trying again later.");
throw new UnavailableAccountException(e);
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
Log.e(K9.LOG_TAG, "Failed to clear account " + account.getDescription(), e);
}
}
});
}
- public void recreate(final Account account, final MessagingListener ml)
- {
- putBackground("recreate:" + account.getDescription(), ml, new Runnable()
- {
+ public void recreate(final Account account, final MessagingListener ml) {
+ putBackground("recreate:" + account.getDescription(), ml, new Runnable() {
@Override
- public void run()
- {
- try
- {
+ public void run() {
+ try {
LocalStore localStore = account.getLocalStore();
long oldSize = localStore.getSize();
localStore.recreate();
@@ -4622,24 +3775,18 @@ public class MessagingController implements Runnable
stats.size = newSize;
stats.unreadMessageCount = 0;
stats.flaggedMessageCount = 0;
- if (ml != null)
- {
+ if (ml != null) {
ml.accountSizeChanged(account, oldSize, newSize);
ml.accountStatusChanged(account, stats);
}
- for (MessagingListener l : getListeners())
- {
+ for (MessagingListener l : getListeners()) {
l.accountSizeChanged(account, oldSize, newSize);
l.accountStatusChanged(account, stats);
}
- }
- catch (UnavailableStorageException e)
- {
+ } catch (UnavailableStorageException e) {
Log.i(K9.LOG_TAG, "Failed to recreate an account because storage is not available - trying again later.");
throw new UnavailableAccountException(e);
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
Log.e(K9.LOG_TAG, "Failed to recreate account " + account.getDescription(), e);
}
}
@@ -4647,18 +3794,15 @@ public class MessagingController implements Runnable
}
- private boolean shouldNotifyForMessage(Account account, LocalFolder localFolder, Message message)
- {
+ private boolean shouldNotifyForMessage(Account account, LocalFolder localFolder, Message message) {
// Do not notify if the user does not have notifications
// enabled or if the message has been read
- if (!account.isNotifyNewMail() || message.isSet(Flag.SEEN) || (account.getName() == null))
- {
+ if (!account.isNotifyNewMail() || message.isSet(Flag.SEEN) || (account.getName() == null)) {
return false;
}
Folder folder = message.getFolder();
- if (folder != null)
- {
+ if (folder != null) {
// No notification for new messages in Trash, Drafts, Spam or Sent folder.
// But do notify if it's the INBOX (see issue 1817).
String folderName = folder.getName();
@@ -4666,26 +3810,20 @@ public class MessagingController implements Runnable
(account.getTrashFolderName().equals(folderName)
|| account.getDraftsFolderName().equals(folderName)
|| account.getSpamFolderName().equals(folderName)
- || account.getSentFolderName().equals(folderName)))
- {
+ || account.getSentFolderName().equals(folderName))) {
return false;
}
}
- if (message.getUid() != null && localFolder.getLastUid() != null)
- {
- try
- {
+ if (message.getUid() != null && localFolder.getLastUid() != null) {
+ try {
Integer messageUid = Integer.parseInt(message.getUid());
- if (messageUid <= localFolder.getLastUid())
- {
- if(K9.DEBUG)
+ if (messageUid <= localFolder.getLastUid()) {
+ if (K9.DEBUG)
Log.d(K9.LOG_TAG, "Message uid is " + messageUid + ", max message uid is " + localFolder.getLastUid() + ". Skipping notification.");
return false;
}
- }
- catch (NumberFormatException e)
- {
+ } catch (NumberFormatException e) {
// Nothing to be done here.
}
}
@@ -4699,22 +3837,18 @@ public class MessagingController implements Runnable
/** Creates a notification of new email messages
* ringtone, lights, and vibration to be played
*/
- private boolean notifyAccount(Context context, Account account, Message message, int previousUnreadMessageCount, AtomicInteger newMessageCount)
- {
+ private boolean notifyAccount(Context context, Account account, Message message, int previousUnreadMessageCount, AtomicInteger newMessageCount) {
// If we don't even have an account name, don't show the notification
// (This happens during initial account setup)
//
- if (account.getName() == null)
- {
+ if (account.getName() == null) {
return false;
}
// If the account us a POP3 account and the message is older than
// the oldest message we've previously seen then don't notify about it
- if (account.getStoreUri().startsWith("pop3") )
- {
- if ( message.olderThan(new Date(account.getLatestOldMessageSeenTime())))
- {
+ if (account.getStoreUri().startsWith("pop3")) {
+ if (message.olderThan(new Date(account.getLatestOldMessageSeenTime()))) {
return false;
}
}
@@ -4723,41 +3857,31 @@ public class MessagingController implements Runnable
// If we have a message, set the notification to ": "
StringBuilder messageNotice = new StringBuilder();
final KeyguardManager keyguardService = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
- try
- {
- if (message.getFrom() != null)
- {
+ try {
+ if (message.getFrom() != null) {
Address[] fromAddrs = message.getFrom();
String from = fromAddrs.length > 0 ? fromAddrs[0].toFriendly().toString() : null;
String subject = message.getSubject();
- if (subject == null)
- {
+ if (subject == null) {
subject = context.getString(R.string.general_no_subject);
}
- if (from != null)
- {
+ if (from != null) {
// Show From: address by default
- if (!account.isAnIdentity(fromAddrs))
- {
+ if (!account.isAnIdentity(fromAddrs)) {
messageNotice.append(from).append(": ").append(subject);
}
// show To: if the message was sent from me
- else
- {
- if (!account.isNotifySelfNewMail())
- {
+ else {
+ if (!account.isNotifySelfNewMail()) {
return false;
}
Address[] rcpts = message.getRecipients(Message.RecipientType.TO);
String to = rcpts.length > 0 ? rcpts[0].toFriendly().toString() : null;
- if (to != null)
- {
+ if (to != null) {
messageNotice.append(String.format(context.getString(R.string.message_to_fmt), to)).append(": ").append(subject);
- }
- else
- {
+ } else {
messageNotice.append(context.getString(R.string.general_no_sender)).append(": ").append(subject);
}
@@ -4765,17 +3889,14 @@ public class MessagingController implements Runnable
}
}
}
- }
- catch (MessagingException e)
- {
+ } catch (MessagingException e) {
Log.e(K9.LOG_TAG, "Unable to get message information for notification.", e);
}
// If privacy mode active and keyguard active
// OR
// If we could not set a per-message notification, revert to a default message
- if ((K9.keyguardPrivacy() && keyguardService.inKeyguardRestrictedInputMode()) || messageNotice.length() == 0)
- {
+ if ((K9.keyguardPrivacy() && keyguardService.inKeyguardRestrictedInputMode()) || messageNotice.length() == 0) {
messageNotice = new StringBuilder(context.getString(R.string.notification_new_title));
}
@@ -4783,8 +3904,7 @@ public class MessagingController implements Runnable
(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notif = new Notification(R.drawable.stat_notify_email_generic, messageNotice, System.currentTimeMillis());
final int unreadCount = previousUnreadMessageCount + newMessageCount.get();
- if (account.isNotificationShowsUnreadCount())
- {
+ if (account.isNotificationShowsUnreadCount()) {
notif.number = unreadCount;
}
@@ -4797,15 +3917,14 @@ public class MessagingController implements Runnable
// Only ring or vibrate if we have not done so already on this
// account and fetch
boolean ringAndVibrate = false;
- if (!account.isRingNotified())
- {
+ if (!account.isRingNotified()) {
account.setRingNotified(true);
ringAndVibrate = true;
}
NotificationSetting n = account.getNotificationSetting();
- configureNotification(notif, ( n.shouldRing() ? n.getRingtone() : null), (n.shouldVibrate() ? n.getVibration() : null), (n.isLed() ? n.getLedColor() : null), K9.NOTIFICATION_LED_BLINK_SLOW, ringAndVibrate);
+ configureNotification(notif, (n.shouldRing() ? n.getRingtone() : null), (n.shouldVibrate() ? n.getVibration() : null), (n.isLed() ? n.getLedColor() : null), K9.NOTIFICATION_LED_BLINK_SLOW, ringAndVibrate);
notifMgr.notify(account.getAccountNumber(), notif);
return true;
@@ -4832,39 +3951,30 @@ public class MessagingController implements Runnable
final Integer ledColor,
final int ledSpeed,
- final boolean ringAndVibrate)
- {
+ final boolean ringAndVibrate) {
// if it's quiet time, then we shouldn't be ringing, buzzing or flashing
- if (K9.isQuietTime())
- {
+ if (K9.isQuietTime()) {
return;
}
- if (ringAndVibrate)
- {
- if (ringtone != null)
- {
+ if (ringAndVibrate) {
+ if (ringtone != null) {
notification.sound = TextUtils.isEmpty(ringtone) ? null : Uri.parse(ringtone);
notification.audioStreamType = AudioManager.STREAM_NOTIFICATION;
}
- if (vibrationPattern != null )
- {
+ if (vibrationPattern != null) {
notification.vibrate = vibrationPattern;
}
}
- if (ledColor != null )
- {
+ if (ledColor != null) {
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
notification.ledARGB = ledColor;
- if (ledSpeed == K9.NOTIFICATION_LED_BLINK_SLOW)
- {
+ if (ledSpeed == K9.NOTIFICATION_LED_BLINK_SLOW) {
notification.ledOnMS = K9.NOTIFICATION_LED_ON_TIME;
notification.ledOffMS = K9.NOTIFICATION_LED_OFF_TIME;
- }
- else if (ledSpeed == K9.NOTIFICATION_LED_BLINK_FAST)
- {
+ } else if (ledSpeed == K9.NOTIFICATION_LED_BLINK_FAST) {
notification.ledOnMS = K9.NOTIFICATION_LED_FAST_ON_TIME;
notification.ledOffMS = K9.NOTIFICATION_LED_FAST_OFF_TIME;
}
@@ -4872,8 +3982,7 @@ public class MessagingController implements Runnable
}
/** Cancel a notification of new email messages */
- public void notifyAccountCancel(Context context, Account account)
- {
+ public void notifyAccountCancel(Context context, Account account) {
NotificationManager notifMgr =
(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
notifMgr.cancel(account.getAccountNumber());
@@ -4886,17 +3995,14 @@ public class MessagingController implements Runnable
* @param message Message to save.
* @return Message representing the entry in the local store.
*/
- public Message saveDraft(final Account account, final Message message)
- {
+ public Message saveDraft(final Account account, final Message message) {
Message localMessage = null;
- try
- {
+ try {
LocalStore localStore = account.getLocalStore();
LocalFolder localFolder = localStore.getFolder(account.getDraftsFolderName());
localFolder.open(OpenMode.READ_WRITE);
// Save the message to the store.
- localFolder.appendMessages(new Message[]
- {
+ localFolder.appendMessages(new Message[] {
message
});
// Fetch the message back from the store. This is the Message that's returned to the caller.
@@ -4905,25 +4011,21 @@ public class MessagingController implements Runnable
PendingCommand command = new PendingCommand();
command.command = PENDING_COMMAND_APPEND;
- command.arguments = new String[]
- {
+ command.arguments = new String[] {
localFolder.getName(),
localMessage.getUid()
};
queuePendingCommand(account, command);
processPendingCommands(account);
- }
- catch (MessagingException e)
- {
+ } catch (MessagingException e) {
Log.e(K9.LOG_TAG, "Unable to save message as draft.", e);
addErrorMessage(account, null, e);
}
return localMessage;
}
- public boolean modeMismatch(Account.FolderMode aMode, Folder.FolderClass fMode)
- {
+ public boolean modeMismatch(Account.FolderMode aMode, Folder.FolderClass fMode) {
if (aMode == Account.FolderMode.NONE
|| (aMode == Account.FolderMode.FIRST_CLASS &&
fMode != Folder.FolderClass.FIRST_CLASS)
@@ -4931,19 +4033,15 @@ public class MessagingController implements Runnable
fMode != Folder.FolderClass.FIRST_CLASS &&
fMode != Folder.FolderClass.SECOND_CLASS)
|| (aMode == Account.FolderMode.NOT_SECOND_CLASS &&
- fMode == Folder.FolderClass.SECOND_CLASS))
- {
+ fMode == Folder.FolderClass.SECOND_CLASS)) {
return true;
- }
- else
- {
+ } else {
return false;
}
}
static AtomicInteger sequencing = new AtomicInteger(0);
- static class Command implements Comparable
- {
+ static class Command implements Comparable {
public Runnable runnable;
public MessagingListener listener;
@@ -4955,78 +4053,58 @@ public class MessagingController implements Runnable
int sequence = sequencing.getAndIncrement();
@Override
- public int compareTo(Command other)
- {
- if (other.isForeground && !isForeground)
- {
+ public int compareTo(Command other) {
+ if (other.isForeground && !isForeground) {
return 1;
- }
- else if (!other.isForeground && isForeground)
- {
+ } else if (!other.isForeground && isForeground) {
return -1;
- }
- else
- {
+ } else {
return (sequence - other.sequence);
}
}
}
- public MessagingListener getCheckMailListener()
- {
+ public MessagingListener getCheckMailListener() {
return checkMailListener;
}
- public void setCheckMailListener(MessagingListener checkMailListener)
- {
- if (this.checkMailListener != null)
- {
+ public void setCheckMailListener(MessagingListener checkMailListener) {
+ if (this.checkMailListener != null) {
removeListener(this.checkMailListener);
}
this.checkMailListener = checkMailListener;
- if (this.checkMailListener != null)
- {
+ if (this.checkMailListener != null) {
addListener(this.checkMailListener);
}
}
- public SORT_TYPE getSortType()
- {
+ public SORT_TYPE getSortType() {
return sortType;
}
- public void setSortType(SORT_TYPE sortType)
- {
+ public void setSortType(SORT_TYPE sortType) {
this.sortType = sortType;
}
- public boolean isSortAscending(SORT_TYPE sortType)
- {
+ public boolean isSortAscending(SORT_TYPE sortType) {
Boolean sortAsc = sortAscending.get(sortType);
- if (sortAsc == null)
- {
+ if (sortAsc == null) {
return sortType.isDefaultAscending();
- }
- else return sortAsc;
+ } else return sortAsc;
}
- public void setSortAscending(SORT_TYPE sortType, boolean nsortAscending)
- {
+ public void setSortAscending(SORT_TYPE sortType, boolean nsortAscending) {
sortAscending.put(sortType, nsortAscending);
}
- public Collection getPushers()
- {
+ public Collection getPushers() {
return pushers.values();
}
- public boolean setupPushing(final Account account)
- {
- try
- {
+ public boolean setupPushing(final Account account) {
+ try {
Pusher previousPusher = pushers.remove(account);
- if (previousPusher != null)
- {
+ if (previousPusher != null) {
previousPusher.stop();
}
Preferences prefs = Preferences.getPreferences(mApplication);
@@ -5037,11 +4115,9 @@ public class MessagingController implements Runnable
List names = new ArrayList();
Store localStore = account.getLocalStore();
- for (final Folder folder : localStore.getPersonalNamespaces(false))
- {
+ for (final Folder folder : localStore.getPersonalNamespaces(false)) {
if (folder.getName().equals(account.getErrorFolderName())
- || folder.getName().equals(account.getOutboxFolderName()))
- {
+ || folder.getName().equals(account.getOutboxFolderName())) {
/*
if (K9.DEBUG)
Log.v(K9.LOG_TAG, "Not pushing folder " + folder.getName() +
@@ -5056,8 +4132,7 @@ public class MessagingController implements Runnable
Folder.FolderClass fDisplayClass = folder.getDisplayClass();
Folder.FolderClass fPushClass = folder.getPushClass();
- if (modeMismatch(aDisplayMode, fDisplayClass))
- {
+ if (modeMismatch(aDisplayMode, fDisplayClass)) {
// Never push a folder that isn't displayed
/*
if (K9.DEBUG)
@@ -5068,8 +4143,7 @@ public class MessagingController implements Runnable
continue;
}
- if (modeMismatch(aPushMode, fPushClass))
- {
+ if (modeMismatch(aPushMode, fPushClass)) {
// Do not push folders in the wrong class
/*
if (K9.DEBUG)
@@ -5085,13 +4159,11 @@ public class MessagingController implements Runnable
names.add(folder.getName());
}
- if (names.size() > 0)
- {
+ if (names.size() > 0) {
PushReceiver receiver = new MessagingControllerPushReceiver(mApplication, account, this);
int maxPushFolders = account.getMaxPushFolders();
- if (names.size() > maxPushFolders)
- {
+ if (names.size() > maxPushFolders) {
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "Count of folders to push for account " + account.getDescription() + " is " + names.size()
+ ", greater than limit of " + maxPushFolders + ", truncating");
@@ -5099,79 +4171,63 @@ public class MessagingController implements Runnable
names = names.subList(0, maxPushFolders);
}
- try
- {
+ try {
Store store = account.getRemoteStore();
- if (!store.isPushCapable())
- {
+ if (!store.isPushCapable()) {
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "Account " + account.getDescription() + " is not push capable, skipping");
return false;
}
Pusher pusher = store.getPusher(receiver);
- if (pusher != null)
- {
+ if (pusher != null) {
Pusher oldPusher = pushers.putIfAbsent(account, pusher);
- if (oldPusher == null)
- {
+ if (oldPusher == null) {
pusher.start(names);
}
}
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
Log.e(K9.LOG_TAG, "Could not get remote store", e);
return false;
}
return true;
- }
- else
- {
+ } else {
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "No folders are configured for pushing in account " + account.getDescription());
return false;
}
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
Log.e(K9.LOG_TAG, "Got exception while setting up pushing", e);
}
return false;
}
- public void stopAllPushing()
- {
+ public void stopAllPushing() {
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "Stopping all pushers");
Iterator iter = pushers.values().iterator();
- while (iter.hasNext())
- {
+ while (iter.hasNext()) {
Pusher pusher = iter.next();
iter.remove();
pusher.stop();
}
}
- public void messagesArrived(final Account account, final Folder remoteFolder, final List messages, final boolean flagSyncOnly)
- {
+ public void messagesArrived(final Account account, final Folder remoteFolder, final List messages, final boolean flagSyncOnly) {
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "Got new pushed email messages for account " + account.getDescription()
+ ", folder " + remoteFolder.getName());
final CountDownLatch latch = new CountDownLatch(1);
putBackground("Push messageArrived of account " + account.getDescription()
- + ", folder " + remoteFolder.getName(), null, new Runnable()
- {
+ + ", folder " + remoteFolder.getName(), null, new Runnable() {
@Override
- public void run()
- {
+ public void run() {
LocalFolder localFolder = null;
- try
- {
+ try {
LocalStore localStore = account.getLocalStore();
localFolder = localStore.getFolder(remoteFolder.getName());
localFolder.open(OpenMode.READ_WRITE);
@@ -5188,70 +4244,54 @@ public class MessagingController implements Runnable
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "messagesArrived newCount = " + newCount + ", unread count = " + unreadMessageCount);
- if (unreadMessageCount == 0)
- {
+ if (unreadMessageCount == 0) {
notifyAccountCancel(mApplication, account);
}
- for (MessagingListener l : getListeners())
- {
+ for (MessagingListener l : getListeners()) {
l.folderStatusChanged(account, remoteFolder.getName(), unreadMessageCount);
}
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
String rootMessage = getRootCauseMessage(e);
String errorMessage = "Push failed: " + rootMessage;
- try
- {
+ try {
// Oddly enough, using a local variable gets rid of a
// potential null pointer access warning with Eclipse.
LocalFolder folder = localFolder;
folder.setStatus(errorMessage);
- }
- catch (Exception se)
- {
+ } catch (Exception se) {
Log.e(K9.LOG_TAG, "Unable to set failed status on localFolder", se);
}
- for (MessagingListener l : getListeners())
- {
+ for (MessagingListener l : getListeners()) {
l.synchronizeMailboxFailed(account, remoteFolder.getName(), errorMessage);
}
addErrorMessage(account, null, e);
- }
- finally
- {
+ } finally {
closeFolder(localFolder);
latch.countDown();
}
}
});
- try
- {
+ try {
latch.await();
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
Log.e(K9.LOG_TAG, "Interrupted while awaiting latch release", e);
}
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "MessagingController.messagesArrivedLatch released");
}
- public void systemStatusChanged()
- {
- for (MessagingListener l : getListeners())
- {
+ public void systemStatusChanged() {
+ for (MessagingListener l : getListeners()) {
l.systemStatusChanged();
}
}
enum MemorizingState { STARTED, FINISHED, FAILED }
- static class Memory
- {
+ static class Memory {
Account account;
String folderName;
MemorizingState syncingState = null;
@@ -5267,32 +4307,26 @@ public class MessagingController implements Runnable
int folderTotal = 0;
String processingCommandTitle = null;
- Memory(Account nAccount, String nFolderName)
- {
+ Memory(Account nAccount, String nFolderName) {
account = nAccount;
folderName = nFolderName;
}
- String getKey()
- {
+ String getKey() {
return getMemoryKey(account, folderName);
}
}
- static String getMemoryKey(Account taccount, String tfolderName)
- {
+ static String getMemoryKey(Account taccount, String tfolderName) {
return taccount.getDescription() + ":" + tfolderName;
}
- static class MemorizingListener extends MessagingListener
- {
+ static class MemorizingListener extends MessagingListener {
HashMap memories = new HashMap(31);
- Memory getMemory(Account account, String folderName)
- {
+ Memory getMemory(Account account, String folderName) {
Memory memory = memories.get(getMemoryKey(account, folderName));
- if (memory == null)
- {
+ if (memory == null) {
memory = new Memory(account, folderName);
memories.put(memory.getKey(), memory);
}
@@ -5300,8 +4334,7 @@ public class MessagingController implements Runnable
}
@Override
- public synchronized void synchronizeMailboxStarted(Account account, String folder)
- {
+ public synchronized void synchronizeMailboxStarted(Account account, String folder) {
Memory memory = getMemory(account, folder);
memory.syncingState = MemorizingState.STARTED;
memory.folderCompleted = 0;
@@ -5310,8 +4343,7 @@ public class MessagingController implements Runnable
@Override
public synchronized void synchronizeMailboxFinished(Account account, String folder,
- int totalMessagesInMailbox, int numNewMessages)
- {
+ int totalMessagesInMailbox, int numNewMessages) {
Memory memory = getMemory(account, folder);
memory.syncingState = MemorizingState.FINISHED;
memory.syncingTotalMessagesInMailbox = totalMessagesInMailbox;
@@ -5320,126 +4352,105 @@ public class MessagingController implements Runnable
@Override
public synchronized void synchronizeMailboxFailed(Account account, String folder,
- String message)
- {
+ String message) {
Memory memory = getMemory(account, folder);
memory.syncingState = MemorizingState.FAILED;
memory.failureMessage = message;
}
- synchronized void refreshOther(MessagingListener other)
- {
- if (other != null)
- {
+ synchronized void refreshOther(MessagingListener other) {
+ if (other != null) {
Memory syncStarted = null;
Memory sendStarted = null;
Memory processingStarted = null;
- for (Memory memory : memories.values())
- {
+ for (Memory memory : memories.values()) {
- if (memory.syncingState != null)
- {
- switch (memory.syncingState)
- {
- case STARTED:
- syncStarted = memory;
- break;
- case FINISHED:
- other.synchronizeMailboxFinished(memory.account, memory.folderName,
- memory.syncingTotalMessagesInMailbox, memory.syncingNumNewMessages);
- break;
- case FAILED:
- other.synchronizeMailboxFailed(memory.account, memory.folderName,
- memory.failureMessage);
- break;
+ if (memory.syncingState != null) {
+ switch (memory.syncingState) {
+ case STARTED:
+ syncStarted = memory;
+ break;
+ case FINISHED:
+ other.synchronizeMailboxFinished(memory.account, memory.folderName,
+ memory.syncingTotalMessagesInMailbox, memory.syncingNumNewMessages);
+ break;
+ case FAILED:
+ other.synchronizeMailboxFailed(memory.account, memory.folderName,
+ memory.failureMessage);
+ break;
}
}
- if (memory.sendingState != null)
- {
- switch (memory.sendingState)
- {
- case STARTED:
- sendStarted = memory;
- break;
- case FINISHED:
- other.sendPendingMessagesCompleted(memory.account);
- break;
- case FAILED:
- other.sendPendingMessagesFailed(memory.account);
- break;
+ if (memory.sendingState != null) {
+ switch (memory.sendingState) {
+ case STARTED:
+ sendStarted = memory;
+ break;
+ case FINISHED:
+ other.sendPendingMessagesCompleted(memory.account);
+ break;
+ case FAILED:
+ other.sendPendingMessagesFailed(memory.account);
+ break;
}
}
- if (memory.pushingState != null)
- {
- switch (memory.pushingState)
- {
- case STARTED:
- other.setPushActive(memory.account, memory.folderName, true);
- break;
- case FINISHED:
- other.setPushActive(memory.account, memory.folderName, false);
- break;
+ if (memory.pushingState != null) {
+ switch (memory.pushingState) {
+ case STARTED:
+ other.setPushActive(memory.account, memory.folderName, true);
+ break;
+ case FINISHED:
+ other.setPushActive(memory.account, memory.folderName, false);
+ break;
}
}
- if (memory.processingState != null)
- {
- switch (memory.processingState)
- {
- case STARTED:
- processingStarted = memory;
- break;
- case FINISHED:
- case FAILED:
- other.pendingCommandsFinished(memory.account);
- break;
+ if (memory.processingState != null) {
+ switch (memory.processingState) {
+ case STARTED:
+ processingStarted = memory;
+ break;
+ case FINISHED:
+ case FAILED:
+ other.pendingCommandsFinished(memory.account);
+ break;
}
}
}
Memory somethingStarted = null;
- if (syncStarted != null)
- {
+ if (syncStarted != null) {
other.synchronizeMailboxStarted(syncStarted.account, syncStarted.folderName);
somethingStarted = syncStarted;
}
- if (sendStarted != null)
- {
+ if (sendStarted != null) {
other.sendPendingMessagesStarted(sendStarted.account);
somethingStarted = sendStarted;
}
- if (processingStarted != null)
- {
+ if (processingStarted != null) {
other.pendingCommandsProcessing(processingStarted.account);
- if (processingStarted.processingCommandTitle != null)
- {
+ if (processingStarted.processingCommandTitle != null) {
other.pendingCommandStarted(processingStarted.account, processingStarted.processingCommandTitle);
- }
- else
- {
+ } else {
other.pendingCommandCompleted(processingStarted.account, processingStarted.processingCommandTitle);
}
somethingStarted = processingStarted;
}
- if (somethingStarted != null && somethingStarted.folderTotal > 0)
- {
+ if (somethingStarted != null && somethingStarted.folderTotal > 0) {
other.synchronizeMailboxProgress(somethingStarted.account, somethingStarted.folderName, somethingStarted.folderCompleted, somethingStarted.folderTotal);
}
}
}
@Override
- public synchronized void setPushActive(Account account, String folderName, boolean active)
- {
+ public synchronized void setPushActive(Account account, String folderName, boolean active) {
Memory memory = getMemory(account, folderName);
memory.pushingState = (active ? MemorizingState.STARTED : MemorizingState.FINISHED);
}
@Override
- public synchronized void sendPendingMessagesStarted(Account account)
- {
+ public synchronized void sendPendingMessagesStarted(Account account) {
Memory memory = getMemory(account, null);
memory.sendingState = MemorizingState.STARTED;
memory.folderCompleted = 0;
@@ -5447,23 +4458,20 @@ public class MessagingController implements Runnable
}
@Override
- public synchronized void sendPendingMessagesCompleted(Account account)
- {
+ public synchronized void sendPendingMessagesCompleted(Account account) {
Memory memory = getMemory(account, null);
memory.sendingState = MemorizingState.FINISHED;
}
@Override
- public synchronized void sendPendingMessagesFailed(Account account)
- {
+ public synchronized void sendPendingMessagesFailed(Account account) {
Memory memory = getMemory(account, null);
memory.sendingState = MemorizingState.FAILED;
}
@Override
- public synchronized void synchronizeMailboxProgress(Account account, String folderName, int completed, int total)
- {
+ public synchronized void synchronizeMailboxProgress(Account account, String folderName, int completed, int total) {
Memory memory = getMemory(account, folderName);
memory.folderCompleted = completed;
memory.folderTotal = total;
@@ -5471,67 +4479,57 @@ public class MessagingController implements Runnable
@Override
- public synchronized void pendingCommandsProcessing(Account account)
- {
+ public synchronized void pendingCommandsProcessing(Account account) {
Memory memory = getMemory(account, null);
memory.processingState = MemorizingState.STARTED;
memory.folderCompleted = 0;
memory.folderTotal = 0;
}
@Override
- public synchronized void pendingCommandsFinished(Account account)
- {
+ public synchronized void pendingCommandsFinished(Account account) {
Memory memory = getMemory(account, null);
memory.processingState = MemorizingState.FINISHED;
}
@Override
- public synchronized void pendingCommandStarted(Account account, String commandTitle)
- {
+ public synchronized void pendingCommandStarted(Account account, String commandTitle) {
Memory memory = getMemory(account, null);
memory.processingCommandTitle = commandTitle;
}
@Override
- public synchronized void pendingCommandCompleted(Account account, String commandTitle)
- {
+ public synchronized void pendingCommandCompleted(Account account, String commandTitle) {
Memory memory = getMemory(account, null);
memory.processingCommandTitle = null;
}
}
- private void actOnMessages(Message[] messages, MessageActor actor)
- {
+ private void actOnMessages(Message[] messages, MessageActor actor) {
Map>> accountMap = new HashMap>>();
- for (Message message : messages)
- {
+ for (Message message : messages) {
Folder folder = message.getFolder();
Account account = folder.getAccount();
Map> folderMap = accountMap.get(account);
- if (folderMap == null)
- {
+ if (folderMap == null) {
folderMap = new HashMap>();
accountMap.put(account, folderMap);
}
List