private void onDone() { mAccount.setDescription(mAccount.getEmail()); mAccount.setNotifyNewMail(mNotifyView.isChecked()); mAccount.setShowOngoing(mNotifySyncView.isChecked()); mAccount.setAutomaticCheckIntervalMinutes( (Integer) ((SpinnerOption) mCheckFrequencyView.getSelectedItem()).value); mAccount.setDisplayCount((Integer) ((SpinnerOption) mDisplayCountView.getSelectedItem()).value); if (mPushEnable.isChecked()) { mAccount.setFolderPushMode(Account.FolderMode.FIRST_CLASS); } else { mAccount.setFolderPushMode(Account.FolderMode.NONE); } mAccount.save(Preferences.getPreferences(this)); if (mAccount.equals(Preferences.getPreferences(this).getDefaultAccount()) || getIntent().getBooleanExtra(EXTRA_MAKE_DEFAULT, false)) { Preferences.getPreferences(this).setDefaultAccount(mAccount); } K9.setServicesEnabled(this); AccountSetupNames.actionSetNames(this, mAccount); finish(); }
@Override public void onCreate() { if (K9.DEVELOPER_MODE) { StrictMode.enableDefaults(); } PRNGFixes.apply(); super.onCreate(); app = this; sIsDebuggable = ((getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0); K9MailLib.setDebugStatus( new K9MailLib.DebugStatus() { @Override public boolean enabled() { return DEBUG; } @Override public boolean debugSensitive() { return DEBUG_SENSITIVE; } }); checkCachedDatabaseVersion(); Preferences prefs = Preferences.getPreferences(this); loadPrefs(prefs); /* * 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()); LocalKeyStore.setKeyStoreLocation(getDir("KeyStore", MODE_PRIVATE).toString()); /* * Enable background sync of messages */ setServicesEnabled(this); registerReceivers(); 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); if (K9.DEBUG) Log.d( K9.LOG_TAG, "Broadcasted: action=" + action + " account=" + account.getDescription() + " folder=" + folder + " message uid=" + message.getUid()); } catch (MessagingException e) { Log.w( K9.LOG_TAG, "Error: action=" + action + " account=" + account.getDescription() + " folder=" + folder + " message uid=" + message.getUid()); } } private void updateUnreadWidget() { try { UnreadWidgetProvider.updateUnreadCount(K9.this); } catch (Exception e) { if (K9.DEBUG) { Log.e(LOG_TAG, "Error while updating unread widget(s)", e); } } } @Override public void synchronizeMailboxRemovedMessage( Account account, String folder, Message message) { broadcastIntent( K9.Intents.EmailReceived.ACTION_EMAIL_DELETED, account, folder, message); updateUnreadWidget(); } @Override public void messageDeleted(Account account, String folder, Message message) { broadcastIntent( K9.Intents.EmailReceived.ACTION_EMAIL_DELETED, account, folder, message); updateUnreadWidget(); } @Override public void synchronizeMailboxNewMessage( Account account, String folder, Message message) { broadcastIntent( K9.Intents.EmailReceived.ACTION_EMAIL_RECEIVED, account, folder, message); updateUnreadWidget(); } @Override public void folderStatusChanged( Account account, String folderName, int unreadMessageCount) { updateUnreadWidget(); // let observers know a change occurred Intent intent = new Intent(K9.Intents.EmailReceived.ACTION_REFRESH_OBSERVER, null); intent.putExtra(K9.Intents.EmailReceived.EXTRA_ACCOUNT, account.getDescription()); intent.putExtra(K9.Intents.EmailReceived.EXTRA_FOLDER, folderName); K9.this.sendBroadcast(intent); } }); notifyObservers(); }
/** * 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).getAvailableAccounts().size(); setServicesEnabled(context, acctLength > 0, null); }
@Override public void onCreate() { maybeSetupStrictMode(); super.onCreate(); app = this; galleryBuggy = checkForBuggyGallery(); Preferences prefs = Preferences.getPreferences(this); SharedPreferences sprefs = prefs.getPreferences(); DEBUG = sprefs.getBoolean("enableDebugLogging", false); DEBUG_SENSITIVE = sprefs.getBoolean("enableSensitiveLogging", false); mAnimations = sprefs.getBoolean("animations", true); mGesturesEnabled = sprefs.getBoolean("gesturesEnabled", true); mUseVolumeKeysForNavigation = sprefs.getBoolean("useVolumeKeysForNavigation", false); mUseVolumeKeysForListNavigation = sprefs.getBoolean("useVolumeKeysForListNavigation", false); mManageBack = sprefs.getBoolean("manageBack", false); mStartIntegratedInbox = sprefs.getBoolean("startIntegratedInbox", false); mMeasureAccounts = sprefs.getBoolean("measureAccounts", true); mCountSearchMessages = sprefs.getBoolean("countSearchMessages", true); mHideSpecialAccounts = sprefs.getBoolean("hideSpecialAccounts", 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); mQuietTimeEnabled = sprefs.getBoolean("quietTimeEnabled", false); mQuietTimeStarts = sprefs.getString("quietTimeStarts", "21:00"); mQuietTimeEnds = sprefs.getString("quietTimeEnds", "7:00"); mShowCorrespondentNames = sprefs.getBoolean("showCorrespondentNames", true); mShowContactName = sprefs.getBoolean("showContactName", false); mChangeContactNameColor = sprefs.getBoolean("changeRegisteredNameColor", false); mContactNameColor = sprefs.getInt("registeredNameColor", 0xff00008f); mMessageViewFixedWidthFont = sprefs.getBoolean("messageViewFixedWidthFont", false); mMessageViewReturnToList = sprefs.getBoolean("messageViewReturnToList", false); useGalleryBugWorkaround = sprefs.getBoolean("useGalleryBugWorkaround", K9.isGalleryBuggy()); mConfirmDelete = sprefs.getBoolean("confirmDelete", false); mKeyguardPrivacy = sprefs.getBoolean("keyguardPrivacy", false); compactLayouts = sprefs.getBoolean("compactLayouts", false); fontSizes.load(sprefs); try { setBackgroundOps( BACKGROUND_OPS.valueOf(sprefs.getString("backgroundOperations", "WHEN_CHECKED"))); } catch (Exception e) { setBackgroundOps(BACKGROUND_OPS.WHEN_CHECKED); } K9.setK9Language(sprefs.getString("language", "")); K9.setK9Theme(sprefs.getInt("theme", android.R.style.Theme_Light)); /* * 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); registerReceivers(); 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); if (K9.DEBUG) Log.d( K9.LOG_TAG, "Broadcasted: action=" + action + " account=" + account.getDescription() + " folder=" + folder + " message uid=" + message.getUid()); } catch (MessagingException e) { Log.w( K9.LOG_TAG, "Error: action=" + action + " account=" + account.getDescription() + " folder=" + folder + " message uid=" + message.getUid()); } } @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); } @Override public void searchStats(final AccountStats stats) { // let observers know a fetch occured K9.this.sendBroadcast( new Intent(K9.Intents.EmailReceived.ACTION_REFRESH_OBSERVER, null)); } }); notifyObservers(); }