2009-12-14 21:50:53 -05:00
|
|
|
|
2008-12-18 19:14:49 -05:00
|
|
|
package com.fsck.k9;
|
|
|
|
|
2009-12-14 21:50:53 -05:00
|
|
|
import android.app.Application;
|
|
|
|
import android.content.ComponentName;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.SharedPreferences;
|
2010-05-02 14:24:33 -04:00
|
|
|
import android.content.pm.PackageInfo;
|
2009-12-14 21:50:53 -05:00
|
|
|
import android.content.pm.PackageManager;
|
2010-05-02 14:24:33 -04:00
|
|
|
import android.content.pm.PackageManager.NameNotFoundException;
|
2009-12-14 21:50:53 -05:00
|
|
|
import android.net.Uri;
|
|
|
|
import android.util.Log;
|
2010-02-07 22:23:41 -05:00
|
|
|
import android.webkit.WebSettings;
|
|
|
|
|
2009-12-14 21:50:53 -05:00
|
|
|
import com.fsck.k9.activity.MessageCompose;
|
2010-05-19 14:17:06 -04:00
|
|
|
import com.fsck.k9.controller.MessagingController;
|
|
|
|
import com.fsck.k9.controller.MessagingListener;
|
2009-12-14 21:50:53 -05:00
|
|
|
import com.fsck.k9.mail.Address;
|
|
|
|
import com.fsck.k9.mail.Message;
|
|
|
|
import com.fsck.k9.mail.MessagingException;
|
|
|
|
import com.fsck.k9.mail.internet.BinaryTempFileBody;
|
2010-08-17 22:49:13 -04:00
|
|
|
import com.fsck.k9.provider.MessageProvider;
|
2009-12-14 21:50:53 -05:00
|
|
|
import com.fsck.k9.service.BootReceiver;
|
|
|
|
import com.fsck.k9.service.MailService;
|
|
|
|
|
|
|
|
import java.io.File;
|
2010-02-07 22:23:41 -05:00
|
|
|
import java.lang.reflect.Method;
|
2009-12-14 21:50:53 -05:00
|
|
|
|
|
|
|
public class K9 extends Application
|
|
|
|
{
|
|
|
|
public static Application app = null;
|
|
|
|
public static File tempDirectory;
|
|
|
|
public static final String LOG_TAG = "k9";
|
|
|
|
|
|
|
|
public enum BACKGROUND_OPS
|
|
|
|
{
|
2010-05-15 17:26:15 -04:00
|
|
|
WHEN_CHECKED, ALWAYS, NEVER, WHEN_CHECKED_AUTO_SYNC
|
2009-12-14 21:50:53 -05:00
|
|
|
}
|
|
|
|
|
2010-07-08 20:27:47 -04:00
|
|
|
private static String language = "";
|
2009-12-14 21:50:53 -05:00
|
|
|
private static int theme = android.R.style.Theme_Light;
|
|
|
|
|
2010-04-20 12:37:03 -04:00
|
|
|
private static final FontSizes fontSizes = new FontSizes();
|
|
|
|
|
2009-12-14 21:50:53 -05:00
|
|
|
private static BACKGROUND_OPS backgroundOps = BACKGROUND_OPS.WHEN_CHECKED;
|
|
|
|
/**
|
|
|
|
* Some log messages can be sent to a file, so that the logs
|
|
|
|
* can be read using unprivileged access (eg. Terminal Emulator)
|
|
|
|
* on the phone, without adb. Set to null to disable
|
|
|
|
*/
|
|
|
|
public static final String logFile = null;
|
2010-05-29 17:56:09 -04:00
|
|
|
//public static final String logFile = Environment.getExternalStorageDirectory() + "/k9mail/debug.log";
|
2009-12-14 21:50:53 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If this is enabled there will be additional logging information sent to
|
|
|
|
* Log.d, including protocol dumps.
|
|
|
|
* Controlled by Preferences at run-time
|
|
|
|
*/
|
|
|
|
public static boolean DEBUG = false;
|
|
|
|
|
2010-07-13 17:16:42 -04:00
|
|
|
/**
|
|
|
|
* Should K-9 log the conversation it has over the wire with
|
|
|
|
* SMTP servers?
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static boolean DEBUG_PROTOCOL_SMTP = true;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Should K-9 log the conversation it has over the wire with
|
|
|
|
* IMAP servers?
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static boolean DEBUG_PROTOCOL_IMAP = true;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Should K-9 log the conversation it has over the wire with
|
|
|
|
* POP3 servers?
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static boolean DEBUG_PROTOCOL_POP3 = true;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Should K-9 log the conversation it has over the wire with
|
|
|
|
* WebDAV servers?
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static boolean DEBUG_PROTOCOL_WEBDAV = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-12-14 21:50:53 -05:00
|
|
|
/**
|
|
|
|
* If this is enabled than logging that normally hides sensitive information
|
|
|
|
* like passwords will show that information.
|
|
|
|
*/
|
|
|
|
public static boolean DEBUG_SENSITIVE = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Can create messages containing stack traces that can be forwarded
|
|
|
|
* to the development team.
|
|
|
|
*/
|
|
|
|
public static boolean ENABLE_ERROR_FOLDER = true;
|
|
|
|
public static String ERROR_FOLDER_NAME = "K9mail-errors";
|
2010-01-02 20:50:51 -05:00
|
|
|
|
2010-01-09 18:02:40 -05:00
|
|
|
|
2009-12-26 19:54:19 -05:00
|
|
|
private static boolean mAnimations = true;
|
2009-12-14 21:50:53 -05:00
|
|
|
|
2010-01-09 18:02:40 -05:00
|
|
|
|
2010-01-17 17:49:03 -05:00
|
|
|
private static boolean mMessageListStars = true;
|
2010-01-18 19:43:52 -05:00
|
|
|
private static boolean mMessageListCheckboxes = false;
|
2010-01-12 22:37:13 -05:00
|
|
|
private static boolean mMessageListTouchable = false;
|
2010-06-06 17:33:33 -04:00
|
|
|
|
|
|
|
private static boolean mMessageViewFixedWidthFont = false;
|
2010-06-20 08:15:29 -04:00
|
|
|
private static boolean mMessageViewReturnToList = false;
|
2010-06-06 17:33:33 -04:00
|
|
|
|
2010-03-07 18:43:27 -05:00
|
|
|
private static boolean mGesturesEnabled = true;
|
2010-05-30 00:16:44 -04:00
|
|
|
private static boolean mManageBack = false;
|
2010-07-02 20:26:35 -04:00
|
|
|
private static boolean mStartIntegratedInbox = false;
|
2010-04-18 22:55:02 -04:00
|
|
|
private static boolean mMeasureAccounts = true;
|
|
|
|
private static boolean mCountSearchMessages = true;
|
2010-01-09 18:02:40 -05:00
|
|
|
|
2010-05-02 14:24:33 -04:00
|
|
|
private static boolean useGalleryBugWorkaround = false;
|
|
|
|
private static boolean galleryBuggy;
|
|
|
|
|
2010-02-07 22:23:41 -05:00
|
|
|
/**
|
|
|
|
* We use WebSettings.getBlockNetworkLoads() to prevent the WebView that displays email
|
|
|
|
* bodies from loading external resources over the network. Unfortunately this method
|
|
|
|
* isn't exposed via the official Android API. That's why we use reflection to be able
|
2010-04-29 00:59:14 -04:00
|
|
|
* to call the method.
|
2010-02-07 22:23:41 -05:00
|
|
|
*/
|
|
|
|
private static final Method mGetBlockNetworkLoads = getMethod(WebSettings.class, "setBlockNetworkLoads");
|
|
|
|
|
2010-01-09 18:02:40 -05:00
|
|
|
|
2009-12-14 21:50:53 -05:00
|
|
|
/**
|
|
|
|
* The MIME type(s) of attachments we're willing to send. At the moment it is not possible
|
|
|
|
* to open a chooser with a list of filter types, so the chooser is only opened with the first
|
|
|
|
* item in the list. The entire list will be used to filter down attachments that are added
|
|
|
|
* with Intent.ACTION_SEND.
|
|
|
|
*/
|
|
|
|
public static final String[] ACCEPTABLE_ATTACHMENT_SEND_TYPES = new String[]
|
|
|
|
{
|
|
|
|
"*/*"
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The MIME type(s) of attachments we're willing to view.
|
|
|
|
*/
|
|
|
|
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[]
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The MIME type(s) of attachments we're willing to download to SD.
|
|
|
|
*/
|
|
|
|
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[]
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The special name "INBOX" is used throughout the application to mean "Whatever folder
|
|
|
|
* the server refers to as the user's Inbox. Placed here to ease use.
|
|
|
|
*/
|
|
|
|
public static final String INBOX = "INBOX";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* For use when displaying that no folder is selected
|
|
|
|
*/
|
|
|
|
public static final String FOLDER_NONE = "-NONE-";
|
|
|
|
|
|
|
|
public static final String LOCAL_UID_PREFIX = "K9LOCAL:";
|
|
|
|
|
|
|
|
public static final String REMOTE_UID_PREFIX = "K9REMOTE:";
|
|
|
|
|
|
|
|
public static final String K9MAIL_IDENTITY = "X-K9mail-Identity";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Specifies how many messages will be shown in a folder by default. This number is set
|
|
|
|
* on each new folder and can be incremented with "Load more messages..." by the
|
|
|
|
* VISIBLE_LIMIT_INCREMENT
|
|
|
|
*/
|
|
|
|
public static int DEFAULT_VISIBLE_LIMIT = 25;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Number of additioanl messages to load when a user selectes "Load more messages..."
|
|
|
|
*/
|
|
|
|
public static int VISIBLE_LIMIT_INCREMENT = 25;
|
|
|
|
|
|
|
|
public static int MAX_SEND_ATTEMPTS = 5;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The maximum size of an attachment we're willing to download (either View or Save)
|
|
|
|
* Attachments that are base64 encoded (most) will be about 1.375x their actual size
|
|
|
|
* so we should probably factor that in. A 5MB attachment will generally be around
|
|
|
|
* 6.8MB downloaded but only 5MB saved.
|
|
|
|
*/
|
2010-07-18 21:55:09 -04:00
|
|
|
public static final int MAX_ATTACHMENT_DOWNLOAD_SIZE = (128 * 1024 * 1024);
|
2009-12-14 21:50:53 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Max time (in millis) the wake lock will be held for when background sync is happening
|
|
|
|
*/
|
|
|
|
public static final int WAKE_LOCK_TIMEOUT = 600000;
|
|
|
|
|
|
|
|
public static final int MANUAL_WAKE_LOCK_TIMEOUT = 120000;
|
|
|
|
|
|
|
|
public static final int PUSH_WAKE_LOCK_TIMEOUT = 60000;
|
|
|
|
|
|
|
|
public static final int MAIL_SERVICE_WAKE_LOCK_TIMEOUT = 30000;
|
|
|
|
|
|
|
|
public static final int BOOT_RECEIVER_WAKE_LOCK_TIMEOUT = 60000;
|
|
|
|
|
|
|
|
/**
|
2010-05-11 23:06:11 -04:00
|
|
|
* Time the LED is on when blinking on new email notification
|
2009-12-14 21:50:53 -05:00
|
|
|
*/
|
|
|
|
public static final int NOTIFICATION_LED_ON_TIME = 500;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Time the LED is off when blicking on new email notification
|
|
|
|
*/
|
|
|
|
public static final int NOTIFICATION_LED_OFF_TIME = 2000;
|
|
|
|
|
|
|
|
public static final boolean NOTIFICATION_LED_WHILE_SYNCING = false;
|
|
|
|
public static final int NOTIFICATION_LED_FAST_ON_TIME = 100;
|
|
|
|
public static final int NOTIFICATION_LED_FAST_OFF_TIME = 100;
|
|
|
|
|
|
|
|
public static final int NOTIFICATION_LED_SENDING_FAILURE_COLOR = 0xffff0000;
|
|
|
|
|
|
|
|
// Must not conflict with an account number
|
2010-05-11 23:06:11 -04:00
|
|
|
public static final int FETCHING_EMAIL_NOTIFICATION = -5000;
|
2009-12-14 21:50:53 -05:00
|
|
|
public static final int CONNECTIVITY_ID = -3;
|
|
|
|
|
2010-01-13 20:07:28 -05:00
|
|
|
|
2009-12-14 21:50:53 -05:00
|
|
|
public class Intents
|
|
|
|
{
|
|
|
|
|
|
|
|
public 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";
|
2010-08-17 22:49:13 -04:00
|
|
|
public static final String ACTION_REFRESH_OBSERVER = "com.fsck.k9.intent.action.REFRESH_OBSERVER";
|
2009-12-14 21:50:53 -05:00
|
|
|
public static final String EXTRA_ACCOUNT = "com.fsck.k9.intent.extra.ACCOUNT";
|
|
|
|
public static final String EXTRA_FOLDER = "com.fsck.k9.intent.extra.FOLDER";
|
|
|
|
public static final String EXTRA_SENT_DATE = "com.fsck.k9.intent.extra.SENT_DATE";
|
|
|
|
public static final String EXTRA_FROM = "com.fsck.k9.intent.extra.FROM";
|
|
|
|
public static final String EXTRA_TO = "com.fsck.k9.intent.extra.TO";
|
|
|
|
public static final String EXTRA_CC = "com.fsck.k9.intent.extra.CC";
|
|
|
|
public static final String EXTRA_BCC = "com.fsck.k9.intent.extra.BCC";
|
|
|
|
public static final String EXTRA_SUBJECT = "com.fsck.k9.intent.extra.SUBJECT";
|
|
|
|
public static final String EXTRA_FROM_SELF = "com.fsck.k9.intent.extra.FROM_SELF";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2008-12-18 19:14:49 -05:00
|
|
|
|
2009-12-14 21:50:53 -05:00
|
|
|
/**
|
|
|
|
* Called throughout the application when the number of accounts has changed. This method
|
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
int acctLength = Preferences.getPreferences(context).getAccounts().length;
|
|
|
|
|
|
|
|
setServicesEnabled(context, acctLength > 0, null);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setServicesEnabled(Context context, Integer wakeLockId)
|
|
|
|
{
|
|
|
|
setServicesEnabled(context, Preferences.getPreferences(context).getAccounts().length > 0, 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)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2010-02-07 16:23:33 -05:00
|
|
|
MailService.actionReset(context, wakeLockId);
|
2009-12-14 21:50:53 -05:00
|
|
|
}
|
2010-04-16 08:20:10 -04:00
|
|
|
Class<?>[] classes = { MessageCompose.class, BootReceiver.class, MailService.class };
|
2009-12-14 21:50:53 -05:00
|
|
|
|
2010-04-16 08:20:10 -04:00
|
|
|
for (Class<?> clazz : classes)
|
2009-12-14 21:50:53 -05:00
|
|
|
{
|
|
|
|
|
|
|
|
boolean alreadyEnabled = pm.getComponentEnabledSetting(new ComponentName(context, clazz)) ==
|
|
|
|
PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
|
|
|
|
|
|
|
|
if (enabled != alreadyEnabled)
|
|
|
|
{
|
|
|
|
pm.setComponentEnabledSetting(
|
|
|
|
new ComponentName(context, clazz),
|
|
|
|
enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED :
|
|
|
|
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
|
|
|
PackageManager.DONT_KILL_APP);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (enabled && pm.getComponentEnabledSetting(new ComponentName(context, MailService.class)) ==
|
|
|
|
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.
|
|
|
|
*/
|
2010-02-07 16:23:33 -05:00
|
|
|
MailService.actionReset(context, wakeLockId);
|
2009-12-14 21:50:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void save(SharedPreferences.Editor editor)
|
|
|
|
{
|
|
|
|
editor.putBoolean("enableDebugLogging", K9.DEBUG);
|
|
|
|
editor.putBoolean("enableSensitiveLogging", K9.DEBUG_SENSITIVE);
|
|
|
|
editor.putString("backgroundOperations", K9.backgroundOps.toString());
|
2009-12-26 19:54:19 -05:00
|
|
|
editor.putBoolean("animations", mAnimations);
|
2010-03-07 18:43:27 -05:00
|
|
|
editor.putBoolean("gesturesEnabled", mGesturesEnabled);
|
2010-05-30 00:16:44 -04:00
|
|
|
editor.putBoolean("manageBack", mManageBack);
|
2010-07-02 20:26:35 -04:00
|
|
|
editor.putBoolean("startIntegratedInbox", mStartIntegratedInbox);
|
2010-04-18 22:55:02 -04:00
|
|
|
editor.putBoolean("measureAccounts", mMeasureAccounts);
|
|
|
|
editor.putBoolean("countSearchMessages", mCountSearchMessages);
|
2010-01-17 17:49:03 -05:00
|
|
|
editor.putBoolean("messageListStars",mMessageListStars);
|
2010-01-18 19:43:52 -05:00
|
|
|
editor.putBoolean("messageListCheckboxes",mMessageListCheckboxes);
|
2010-01-12 22:37:13 -05:00
|
|
|
editor.putBoolean("messageListTouchable",mMessageListTouchable);
|
2010-06-06 17:33:33 -04:00
|
|
|
|
|
|
|
editor.putBoolean("messageViewFixedWidthFont",mMessageViewFixedWidthFont);
|
2010-06-20 08:15:29 -04:00
|
|
|
editor.putBoolean("messageViewReturnToList", mMessageViewReturnToList);
|
2010-06-06 17:33:33 -04:00
|
|
|
|
2010-07-08 20:27:47 -04:00
|
|
|
editor.putString("language", language);
|
2009-12-14 21:50:53 -05:00
|
|
|
editor.putInt("theme", theme);
|
2010-05-02 14:24:33 -04:00
|
|
|
editor.putBoolean("useGalleryBugWorkaround", useGalleryBugWorkaround);
|
2010-04-20 12:37:03 -04:00
|
|
|
|
|
|
|
fontSizes.save(editor);
|
2009-12-14 21:50:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate()
|
|
|
|
{
|
|
|
|
super.onCreate();
|
|
|
|
app = this;
|
2010-05-02 14:24:33 -04:00
|
|
|
|
|
|
|
galleryBuggy = checkForBuggyGallery();
|
|
|
|
|
2009-12-14 21:50:53 -05:00
|
|
|
Preferences prefs = Preferences.getPreferences(this);
|
|
|
|
SharedPreferences sprefs = prefs.getPreferences();
|
|
|
|
DEBUG = sprefs.getBoolean("enableDebugLogging", false);
|
|
|
|
DEBUG_SENSITIVE = sprefs.getBoolean("enableSensitiveLogging", false);
|
2009-12-26 19:54:19 -05:00
|
|
|
mAnimations = sprefs.getBoolean("animations", true);
|
2010-03-07 18:43:27 -05:00
|
|
|
mGesturesEnabled = sprefs.getBoolean("gesturesEnabled", true);
|
2010-05-30 00:16:44 -04:00
|
|
|
mManageBack = sprefs.getBoolean("manageBack", false);
|
2010-07-02 20:26:35 -04:00
|
|
|
mStartIntegratedInbox = sprefs.getBoolean("startIntegratedInbox", false);
|
2010-04-18 22:55:02 -04:00
|
|
|
mMeasureAccounts = sprefs.getBoolean("measureAccounts", true);
|
|
|
|
mCountSearchMessages = sprefs.getBoolean("countSearchMessages", true);
|
2010-01-17 17:49:03 -05:00
|
|
|
mMessageListStars = sprefs.getBoolean("messageListStars",true);
|
2010-01-18 19:43:52 -05:00
|
|
|
mMessageListCheckboxes = sprefs.getBoolean("messageListCheckboxes",false);
|
2010-01-12 22:37:13 -05:00
|
|
|
mMessageListTouchable = sprefs.getBoolean("messageListTouchable",false);
|
2010-06-06 17:33:33 -04:00
|
|
|
|
|
|
|
mMessageViewFixedWidthFont = sprefs.getBoolean("messageViewFixedWidthFont", false);
|
2010-06-20 08:15:29 -04:00
|
|
|
mMessageViewReturnToList = sprefs.getBoolean("messageViewReturnToList", false);
|
2010-06-06 17:33:33 -04:00
|
|
|
|
2010-05-02 14:24:33 -04:00
|
|
|
useGalleryBugWorkaround = sprefs.getBoolean("useGalleryBugWorkaround", K9.isGalleryBuggy());
|
2010-01-09 18:02:40 -05:00
|
|
|
|
2010-04-20 12:37:03 -04:00
|
|
|
fontSizes.load(sprefs);
|
2010-01-09 18:02:40 -05:00
|
|
|
|
2009-12-14 21:50:53 -05:00
|
|
|
try
|
|
|
|
{
|
|
|
|
setBackgroundOps(BACKGROUND_OPS.valueOf(sprefs.getString("backgroundOperations", "WHEN_CHECKED")));
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
setBackgroundOps(BACKGROUND_OPS.WHEN_CHECKED);
|
|
|
|
}
|
|
|
|
|
2010-07-08 20:27:47 -04:00
|
|
|
K9.setK9Language(sprefs.getString("language", ""));
|
2009-12-14 21:50:53 -05:00
|
|
|
K9.setK9Theme(sprefs.getInt("theme", android.R.style.Theme_Light));
|
|
|
|
MessagingController.getInstance(this).resetVisibleLimits(prefs.getAccounts());
|
2010-08-17 22:49:13 -04:00
|
|
|
MessageProvider mp = new MessageProvider();
|
|
|
|
mp.setApplication(this);
|
2009-12-14 21:50:53 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We have to give MimeMessage a temp directory because File.createTempFile(String, String)
|
|
|
|
* doesn't work in Android and MimeMessage does not have access to a Context.
|
|
|
|
*/
|
|
|
|
BinaryTempFileBody.setTempDirectory(getCacheDir());
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable background sync of messages
|
|
|
|
*/
|
|
|
|
|
|
|
|
setServicesEnabled(this);
|
|
|
|
|
|
|
|
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());
|
|
|
|
intent.putExtra(K9.Intents.EmailReceived.EXTRA_FOLDER, folder);
|
|
|
|
intent.putExtra(K9.Intents.EmailReceived.EXTRA_SENT_DATE, message.getSentDate());
|
|
|
|
intent.putExtra(K9.Intents.EmailReceived.EXTRA_FROM, Address.toString(message.getFrom()));
|
|
|
|
intent.putExtra(K9.Intents.EmailReceived.EXTRA_TO, Address.toString(message.getRecipients(Message.RecipientType.TO)));
|
|
|
|
intent.putExtra(K9.Intents.EmailReceived.EXTRA_CC, Address.toString(message.getRecipients(Message.RecipientType.CC)));
|
|
|
|
intent.putExtra(K9.Intents.EmailReceived.EXTRA_BCC, Address.toString(message.getRecipients(Message.RecipientType.BCC)));
|
|
|
|
intent.putExtra(K9.Intents.EmailReceived.EXTRA_SUBJECT, message.getSubject());
|
|
|
|
intent.putExtra(K9.Intents.EmailReceived.EXTRA_FROM_SELF, account.isAnIdentity(message.getFrom()));
|
|
|
|
K9.this.sendBroadcast(intent);
|
2010-01-02 20:50:41 -05:00
|
|
|
if (K9.DEBUG)
|
|
|
|
Log.d(K9.LOG_TAG, "Broadcasted: action=" + action
|
|
|
|
+ " account=" + account.getDescription()
|
|
|
|
+ " folder=" + folder
|
|
|
|
+ " message uid=" + message.getUid()
|
|
|
|
);
|
2009-12-14 21:50:53 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
catch (MessagingException e)
|
|
|
|
{
|
|
|
|
Log.w(K9.LOG_TAG, "Error: action=" + action
|
2009-12-20 00:41:43 -05:00
|
|
|
+ " account=" + account.getDescription()
|
|
|
|
+ " folder=" + folder
|
|
|
|
+ " message uid=" + message.getUid()
|
|
|
|
);
|
2009-12-14 21:50:53 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
broadcastIntent(K9.Intents.EmailReceived.ACTION_EMAIL_DELETED, account, folder, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void synchronizeMailboxNewMessage(Account account, String folder, Message message)
|
|
|
|
{
|
|
|
|
broadcastIntent(K9.Intents.EmailReceived.ACTION_EMAIL_RECEIVED, account, folder, message);
|
|
|
|
}
|
2009-12-20 00:41:43 -05:00
|
|
|
|
2009-12-14 21:50:53 -05:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-07-08 20:27:47 -04:00
|
|
|
public static String getK9Language()
|
|
|
|
{
|
|
|
|
return language;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setK9Language(String nlanguage)
|
|
|
|
{
|
|
|
|
language = nlanguage;
|
|
|
|
}
|
|
|
|
|
2009-12-14 21:50:53 -05:00
|
|
|
public static int getK9Theme()
|
|
|
|
{
|
|
|
|
return theme;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setK9Theme(int ntheme)
|
|
|
|
{
|
|
|
|
theme = ntheme;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static BACKGROUND_OPS getBackgroundOps()
|
|
|
|
{
|
|
|
|
return backgroundOps;
|
|
|
|
}
|
|
|
|
|
2010-02-07 16:23:33 -05:00
|
|
|
public static boolean setBackgroundOps(BACKGROUND_OPS backgroundOps)
|
2009-12-14 21:50:53 -05:00
|
|
|
{
|
2010-02-07 16:23:33 -05:00
|
|
|
BACKGROUND_OPS oldBackgroundOps = K9.backgroundOps;
|
2009-12-14 21:50:53 -05:00
|
|
|
K9.backgroundOps = backgroundOps;
|
2010-02-07 16:23:33 -05:00
|
|
|
return backgroundOps != oldBackgroundOps;
|
2009-12-14 21:50:53 -05:00
|
|
|
}
|
|
|
|
|
2010-02-07 16:23:33 -05:00
|
|
|
public static boolean setBackgroundOps(String nbackgroundOps)
|
2009-12-14 21:50:53 -05:00
|
|
|
{
|
2010-02-07 16:23:33 -05:00
|
|
|
return setBackgroundOps(BACKGROUND_OPS.valueOf(nbackgroundOps));
|
2009-12-14 21:50:53 -05:00
|
|
|
}
|
2009-12-26 19:54:19 -05:00
|
|
|
|
2010-03-07 18:43:27 -05:00
|
|
|
public static boolean gesturesEnabled()
|
|
|
|
{
|
|
|
|
return mGesturesEnabled;
|
|
|
|
}
|
2010-04-29 00:59:14 -04:00
|
|
|
|
2010-03-07 18:43:27 -05:00
|
|
|
public static void setGesturesEnabled(boolean gestures)
|
|
|
|
{
|
|
|
|
mGesturesEnabled = gestures;
|
|
|
|
}
|
2010-04-29 00:59:14 -04:00
|
|
|
|
2010-05-30 00:16:44 -04:00
|
|
|
|
|
|
|
public static boolean manageBack()
|
|
|
|
{
|
|
|
|
return mManageBack;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setManageBack(boolean manageBack)
|
|
|
|
{
|
|
|
|
mManageBack = manageBack;
|
|
|
|
}
|
|
|
|
|
2010-07-02 20:26:35 -04:00
|
|
|
public static boolean startIntegratedInbox()
|
|
|
|
{
|
|
|
|
return mStartIntegratedInbox;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setStartIntegratedInbox(boolean startIntegratedInbox)
|
|
|
|
{
|
|
|
|
mStartIntegratedInbox = startIntegratedInbox;
|
|
|
|
}
|
|
|
|
|
2010-07-11 11:30:40 -04:00
|
|
|
public static boolean showAnimations()
|
2009-12-26 19:54:19 -05:00
|
|
|
{
|
|
|
|
return mAnimations;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setAnimations(boolean animations)
|
|
|
|
{
|
|
|
|
mAnimations = animations;
|
|
|
|
}
|
2010-01-09 18:02:40 -05:00
|
|
|
|
2010-01-12 22:37:13 -05:00
|
|
|
public static boolean messageListTouchable()
|
|
|
|
{
|
|
|
|
return mMessageListTouchable;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setMessageListTouchable(boolean touchy)
|
|
|
|
{
|
|
|
|
mMessageListTouchable = touchy;
|
|
|
|
}
|
|
|
|
|
2010-01-17 17:49:03 -05:00
|
|
|
public static boolean messageListStars()
|
2010-01-09 18:02:40 -05:00
|
|
|
{
|
2010-01-17 17:49:03 -05:00
|
|
|
return mMessageListStars;
|
2010-01-09 18:02:40 -05:00
|
|
|
}
|
|
|
|
|
2010-01-17 17:49:03 -05:00
|
|
|
public static void setMessageListStars(boolean stars)
|
2010-01-09 18:02:40 -05:00
|
|
|
{
|
2010-01-17 17:49:03 -05:00
|
|
|
mMessageListStars = stars;
|
2010-01-09 18:02:40 -05:00
|
|
|
}
|
2010-01-18 19:43:52 -05:00
|
|
|
public static boolean messageListCheckboxes()
|
|
|
|
{
|
|
|
|
return mMessageListCheckboxes;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setMessageListCheckboxes(boolean checkboxes)
|
|
|
|
{
|
|
|
|
mMessageListCheckboxes = checkboxes;
|
|
|
|
}
|
2009-12-14 21:50:53 -05:00
|
|
|
|
|
|
|
|
2010-06-06 17:33:33 -04:00
|
|
|
public static boolean messageViewFixedWidthFont()
|
|
|
|
{
|
|
|
|
return mMessageViewFixedWidthFont;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setMessageViewFixedWidthFont(boolean fixed)
|
|
|
|
{
|
|
|
|
mMessageViewFixedWidthFont = fixed;
|
|
|
|
}
|
|
|
|
|
2010-06-20 08:15:29 -04:00
|
|
|
public static boolean messageViewReturnToList()
|
|
|
|
{
|
|
|
|
return mMessageViewReturnToList;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setMessageViewReturnToList(boolean messageViewReturnToList)
|
|
|
|
{
|
|
|
|
mMessageViewReturnToList = messageViewReturnToList;
|
|
|
|
}
|
|
|
|
|
2010-04-16 08:20:10 -04:00
|
|
|
private static Method getMethod(Class<?> classObject, String methodName)
|
2010-02-07 22:23:41 -05:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Method method = classObject.getMethod(methodName, boolean.class);
|
|
|
|
return method;
|
|
|
|
}
|
|
|
|
catch (NoSuchMethodException e)
|
|
|
|
{
|
|
|
|
Log.i(K9.LOG_TAG, "Can't get method " +
|
2010-04-29 00:59:14 -04:00
|
|
|
classObject.toString() + "." + methodName);
|
2010-02-07 22:23:41 -05:00
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Log.e(K9.LOG_TAG, "Error while using reflection to get method " +
|
2010-04-29 00:59:14 -04:00
|
|
|
classObject.toString() + "." + methodName, e);
|
2010-02-07 22:23:41 -05:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2009-12-14 21:50:53 -05:00
|
|
|
|
2010-02-07 22:23:41 -05:00
|
|
|
public static void setBlockNetworkLoads(WebSettings webSettings, boolean state)
|
|
|
|
{
|
|
|
|
if (mGetBlockNetworkLoads != null)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
mGetBlockNetworkLoads.invoke(webSettings, state);
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Log.e(K9.LOG_TAG, "Error on invoking WebSettings.setBlockNetworkLoads()", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-04-18 22:55:02 -04:00
|
|
|
|
2010-04-20 12:37:03 -04:00
|
|
|
public static FontSizes getFontSizes()
|
|
|
|
{
|
|
|
|
return fontSizes;
|
|
|
|
}
|
|
|
|
|
2010-04-18 22:55:02 -04:00
|
|
|
public static boolean measureAccounts()
|
|
|
|
{
|
|
|
|
return mMeasureAccounts;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setMeasureAccounts(boolean measureAccounts)
|
|
|
|
{
|
|
|
|
mMeasureAccounts = measureAccounts;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean countSearchMessages()
|
|
|
|
{
|
|
|
|
return mCountSearchMessages;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setCountSearchMessages(boolean countSearchMessages)
|
|
|
|
{
|
|
|
|
mCountSearchMessages = countSearchMessages;
|
|
|
|
}
|
2010-05-02 14:24:33 -04:00
|
|
|
|
|
|
|
public static boolean useGalleryBugWorkaround()
|
|
|
|
{
|
|
|
|
return useGalleryBugWorkaround;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setUseGalleryBugWorkaround(boolean useGalleryBugWorkaround)
|
|
|
|
{
|
|
|
|
K9.useGalleryBugWorkaround = useGalleryBugWorkaround;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isGalleryBuggy()
|
|
|
|
{
|
|
|
|
return galleryBuggy;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if this system contains a buggy Gallery 3D package.
|
2010-05-11 22:51:59 -04:00
|
|
|
*
|
2010-05-02 14:24:33 -04:00
|
|
|
* We have to work around the fact that those Gallery versions won't show
|
|
|
|
* any images or videos when the pick intent is used with a MIME type other
|
|
|
|
* than image/* or video/*. See issue 1186.
|
2010-05-11 22:51:59 -04:00
|
|
|
*
|
2010-05-02 14:24:33 -04:00
|
|
|
* @return true, if a buggy Gallery 3D package was found. False, otherwise.
|
|
|
|
*/
|
|
|
|
private boolean checkForBuggyGallery()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
PackageInfo pi = getPackageManager().getPackageInfo("com.cooliris.media", 0);
|
2010-05-11 22:51:59 -04:00
|
|
|
|
2010-05-02 14:24:33 -04:00
|
|
|
return (pi.versionCode == 30682);
|
|
|
|
}
|
|
|
|
catch (NameNotFoundException e)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2010-02-07 22:23:41 -05:00
|
|
|
}
|