Search in sources :

Example 61 with K9

use of com.fsck.k9.K9 in project k-9 by k9mail.

the class Accounts method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    if (!K9.isHideSpecialAccounts()) {
        createSpecialAccounts();
    }
    List<Account> accounts = Preferences.getPreferences(this).getAccounts();
    Intent intent = getIntent();
    // see if we should show the welcome message
    if (ACTION_IMPORT_SETTINGS.equals(intent.getAction())) {
        onImport();
    } else if (accounts.size() < 1) {
        WelcomeMessage.showWelcomeMessage(this);
        finish();
        return;
    }
    if (UpgradeDatabases.actionUpgradeDatabases(this, intent)) {
        finish();
        return;
    }
    boolean startup = intent.getBooleanExtra(EXTRA_STARTUP, true);
    if (startup && K9.startIntegratedInbox() && !K9.isHideSpecialAccounts()) {
        onOpenAccount(mUnifiedInboxAccount);
        finish();
        return;
    } else if (startup && accounts.size() == 1 && onOpenAccount(accounts.get(0))) {
        finish();
        return;
    }
    requestWindowFeature(Window.FEATURE_PROGRESS);
    mActionBar = getActionBar();
    initializeActionBar();
    setContentView(R.layout.accounts);
    ListView listView = getListView();
    listView.setOnItemClickListener(this);
    listView.setItemsCanFocus(false);
    listView.setScrollingCacheEnabled(false);
    registerForContextMenu(listView);
    if (icicle != null && icicle.containsKey(SELECTED_CONTEXT_ACCOUNT)) {
        String accountUuid = icicle.getString("selectedContextAccount");
        mSelectedContextAccount = Preferences.getPreferences(this).getAccount(accountUuid);
    }
    restoreAccountStats(icicle);
    mHandler.setViewTitle();
    // Handle activity restarts because of a configuration change (e.g. rotating the screen)
    mNonConfigurationInstance = (NonConfigurationInstance) getLastNonConfigurationInstance();
    if (mNonConfigurationInstance != null) {
        mNonConfigurationInstance.restore(this);
    }
    ChangeLog cl = new ChangeLog(this);
    if (cl.isFirstRun()) {
        cl.getLogDialog().show();
    }
}
Also used : SearchAccount(com.fsck.k9.search.SearchAccount) Account(com.fsck.k9.Account) BaseAccount(com.fsck.k9.BaseAccount) ListView(android.widget.ListView) Intent(android.content.Intent) ChangeLog(de.cketti.library.changelog.ChangeLog)

Example 62 with K9

use of com.fsck.k9.K9 in project k-9 by k9mail.

the class MessageProviderTest method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    mMockResolver = getMockContentResolver();
    mContext = K9.app;
    Preferences preferences = Preferences.getPreferences(getMockContext());
    List<Account> accountList = preferences.getAccounts();
    for (Account account : accountList) {
        preferences.deleteAccount(account);
    }
}
Also used : Account(com.fsck.k9.Account) Preferences(com.fsck.k9.Preferences) Before(org.junit.Before)

Example 63 with K9

use of com.fsck.k9.K9 in project k-9 by k9mail.

the class MessageList method onToggleTheme.

private void onToggleTheme() {
    if (K9.getK9MessageViewTheme() == K9.Theme.DARK) {
        K9.setK9MessageViewThemeSetting(K9.Theme.LIGHT);
    } else {
        K9.setK9MessageViewThemeSetting(K9.Theme.DARK);
    }
    new Thread(new Runnable() {

        @Override
        public void run() {
            Context appContext = getApplicationContext();
            Preferences prefs = Preferences.getPreferences(appContext);
            StorageEditor editor = prefs.getStorage().edit();
            K9.save(editor);
            editor.commit();
        }
    }).start();
    recreate();
}
Also used : Context(android.content.Context) Preferences(com.fsck.k9.Preferences) StorageEditor(com.fsck.k9.preferences.StorageEditor)

Example 64 with K9

use of com.fsck.k9.K9 in project k-9 by k9mail.

the class MessageProvider method delete.

@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
    if (K9.app == null) {
        return 0;
    }
    Timber.v("MessageProvider/delete: %s", uri);
    // Note: can only delete a message
    List<String> segments = uri.getPathSegments();
    int accountId = Integer.parseInt(segments.get(1));
    String folderName = segments.get(2);
    String msgUid = segments.get(3);
    // get account
    Account myAccount = null;
    for (Account account : Preferences.getPreferences(getContext()).getAccounts()) {
        if (account.getAccountNumber() == accountId) {
            myAccount = account;
            if (!account.isAvailable(getContext())) {
                Timber.w("not deleting messages because account is unavailable at the moment");
                return 0;
            }
        }
    }
    if (myAccount == null) {
        Timber.e("Could not find account with id %d", accountId);
    }
    if (myAccount != null) {
        MessageReference messageReference = new MessageReference(myAccount.getUuid(), folderName, msgUid, null);
        MessagingController controller = MessagingController.getInstance(getContext());
        controller.deleteMessage(messageReference, null);
    }
    // FIXME return the actual number of deleted messages
    return 0;
}
Also used : SearchAccount(com.fsck.k9.search.SearchAccount) Account(com.fsck.k9.Account) MessagingController(com.fsck.k9.controller.MessagingController) MessageReference(com.fsck.k9.activity.MessageReference)

Example 65 with K9

use of com.fsck.k9.K9 in project k-9 by k9mail.

the class CoreService method addWakeLock.

/**
     * Adds a new wake lock to the specified intent.
     *
     * <p>
     * This will add the wake lock to the central wake lock registry managed by this class.
     * </p>
     *
     * @param context
     *         A {@link Context} instance. Never {@code null}.
     * @param intent
     *         The {@link Intent} to add the wake lock registry ID as extra to. Never {@code null}.
     */
protected static void addWakeLock(Context context, Intent intent) {
    TracingWakeLock wakeLock = acquireWakeLock(context, "CoreService addWakeLock", K9.MAIL_SERVICE_WAKE_LOCK_TIMEOUT);
    Integer tmpWakeLockId = registerWakeLock(wakeLock);
    intent.putExtra(WAKE_LOCK_ID, tmpWakeLockId);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TracingWakeLock(com.fsck.k9.mail.power.TracingPowerManager.TracingWakeLock)

Aggregations

Account (com.fsck.k9.Account)20 MessagingException (com.fsck.k9.mail.MessagingException)13 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)11 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)10 LocalStore (com.fsck.k9.mailstore.LocalStore)10 Message (com.fsck.k9.mail.Message)9 Store (com.fsck.k9.mail.Store)9 LocalFolder (com.fsck.k9.mailstore.LocalFolder)9 UnavailableStorageException (com.fsck.k9.mailstore.UnavailableStorageException)9 Intent (android.content.Intent)8 Pop3Store (com.fsck.k9.mail.store.pop3.Pop3Store)8 LocalMessage (com.fsck.k9.mailstore.LocalMessage)8 SuppressLint (android.annotation.SuppressLint)7 BaseAccount (com.fsck.k9.BaseAccount)7 Preferences (com.fsck.k9.Preferences)7 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)7 CertificateValidationException (com.fsck.k9.mail.CertificateValidationException)7 Folder (com.fsck.k9.mail.Folder)7 SearchAccount (com.fsck.k9.search.SearchAccount)7