Search in sources :

Example 1 with AuthType

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

the class AccountSetupBasics method onManualSetup.

private void onManualSetup() {
    String email = mEmailView.getText().toString();
    String[] emailParts = splitEmail(email);
    String user = email;
    String domain = emailParts[1];
    String password = null;
    String clientCertificateAlias = null;
    AuthType authenticationType;
    if (mClientCertificateCheckBox.isChecked()) {
        authenticationType = AuthType.EXTERNAL;
        clientCertificateAlias = mClientCertificateSpinner.getAlias();
    } else {
        authenticationType = AuthType.PLAIN;
        password = mPasswordView.getText().toString();
    }
    if (mAccount == null) {
        mAccount = Preferences.getPreferences(this).newAccount();
    }
    mAccount.setName(getOwnerName());
    mAccount.setEmail(email);
    // set default uris
    // NOTE: they will be changed again in AccountSetupAccountType!
    ServerSettings storeServer = new ServerSettings(ServerSettings.Type.IMAP, "mail." + domain, -1, ConnectionSecurity.SSL_TLS_REQUIRED, authenticationType, user, password, clientCertificateAlias);
    ServerSettings transportServer = new ServerSettings(ServerSettings.Type.SMTP, "mail." + domain, -1, ConnectionSecurity.SSL_TLS_REQUIRED, authenticationType, user, password, clientCertificateAlias);
    String storeUri = RemoteStore.createStoreUri(storeServer);
    String transportUri = Transport.createTransportUri(transportServer);
    mAccount.setStoreUri(storeUri);
    mAccount.setTransportUri(transportUri);
    setupFolderNames(domain);
    AccountSetupAccountType.actionSelectAccountType(this, mAccount, false);
    finish();
}
Also used : ServerSettings(com.fsck.k9.mail.ServerSettings) AuthType(com.fsck.k9.mail.AuthType)

Example 2 with AuthType

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

the class AccountSetupIncoming method validateFields.

/**
     * This is invoked only when the user makes changes to a widget, not when
     * widgets are changed programmatically.  (The logic is simpler when you know
     * that this is the last thing called after an input change.)
     */
private void validateFields() {
    AuthType authType = getSelectedAuthType();
    boolean isAuthTypeExternal = (AuthType.EXTERNAL == authType);
    ConnectionSecurity connectionSecurity = getSelectedSecurity();
    boolean hasConnectionSecurity = (connectionSecurity != ConnectionSecurity.NONE);
    if (isAuthTypeExternal && !hasConnectionSecurity) {
        // Notify user of an invalid combination of AuthType.EXTERNAL & ConnectionSecurity.NONE
        String toastText = getString(R.string.account_setup_incoming_invalid_setting_combo_notice, getString(R.string.account_setup_incoming_auth_type_label), AuthType.EXTERNAL.toString(), getString(R.string.account_setup_incoming_security_label), ConnectionSecurity.NONE.toString());
        Toast.makeText(this, toastText, Toast.LENGTH_LONG).show();
        // Reset the views back to their previous settings without recursing through here again
        OnItemSelectedListener onItemSelectedListener = mAuthTypeView.getOnItemSelectedListener();
        mAuthTypeView.setOnItemSelectedListener(null);
        mAuthTypeView.setSelection(mCurrentAuthTypeViewPosition, false);
        mAuthTypeView.setOnItemSelectedListener(onItemSelectedListener);
        updateViewFromAuthType();
        onItemSelectedListener = mSecurityTypeView.getOnItemSelectedListener();
        mSecurityTypeView.setOnItemSelectedListener(null);
        mSecurityTypeView.setSelection(mCurrentSecurityTypeViewPosition, false);
        mSecurityTypeView.setOnItemSelectedListener(onItemSelectedListener);
        updateAuthPlainTextFromSecurityType(getSelectedSecurity());
        mPortView.removeTextChangedListener(validationTextWatcher);
        mPortView.setText(mCurrentPortViewSetting);
        mPortView.addTextChangedListener(validationTextWatcher);
        authType = getSelectedAuthType();
        isAuthTypeExternal = (AuthType.EXTERNAL == authType);
        connectionSecurity = getSelectedSecurity();
        hasConnectionSecurity = (connectionSecurity != ConnectionSecurity.NONE);
    } else {
        mCurrentAuthTypeViewPosition = mAuthTypeView.getSelectedItemPosition();
        mCurrentSecurityTypeViewPosition = mSecurityTypeView.getSelectedItemPosition();
        mCurrentPortViewSetting = mPortView.getText().toString();
    }
    boolean hasValidCertificateAlias = mClientCertificateSpinner.getAlias() != null;
    boolean hasValidUserName = Utility.requiredFieldValid(mUsernameView);
    boolean hasValidPasswordSettings = hasValidUserName && !isAuthTypeExternal && Utility.requiredFieldValid(mPasswordView);
    boolean hasValidExternalAuthSettings = hasValidUserName && isAuthTypeExternal && hasConnectionSecurity && hasValidCertificateAlias;
    mNextButton.setEnabled(Utility.domainFieldValid(mServerView) && Utility.requiredFieldValid(mPortView) && (hasValidPasswordSettings || hasValidExternalAuthSettings));
    Utility.setCompoundDrawablesAlpha(mNextButton, mNextButton.isEnabled() ? 255 : 128);
}
Also used : ConnectionSecurity(com.fsck.k9.mail.ConnectionSecurity) OnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener) AuthType(com.fsck.k9.mail.AuthType)

Example 3 with AuthType

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

the class AccountSetupIncoming method initializeViewListeners.

/**
     * Called at the end of either {@code onCreate()} or
     * {@code onRestoreInstanceState()}, after the views have been initialized,
     * so that the listeners are not triggered during the view initialization.
     * This avoids needless calls to {@code validateFields()} which is called
     * immediately after this is called.
     */
private void initializeViewListeners() {
    /*
         * 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() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            /*
                 * We keep our own record of the spinner state so we
                 * know for sure that onItemSelected() was called
                 * because of user input, not because of spinner
                 * state initialization. This assures that the port
                 * will not be replaced with a default value except
                 * on user input.
                 */
            if (mCurrentSecurityTypeViewPosition != position) {
                updatePortFromSecurityType();
                validateFields();
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        /* unused */
        }
    });
    mAuthTypeView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (mCurrentAuthTypeViewPosition == position) {
                return;
            }
            updateViewFromAuthType();
            validateFields();
            AuthType selection = getSelectedAuthType();
            // Have the user select (or confirm) the client certificate
            if (AuthType.EXTERNAL == selection) {
                // This may again invoke validateFields()
                mClientCertificateSpinner.chooseCertificate();
            } else {
                mPasswordView.requestFocus();
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        /* unused */
        }
    });
    mClientCertificateSpinner.setOnClientCertificateChangedListener(clientCertificateChangedListener);
    mUsernameView.addTextChangedListener(validationTextWatcher);
    mPasswordView.addTextChangedListener(validationTextWatcher);
    mServerView.addTextChangedListener(validationTextWatcher);
    mPortView.addTextChangedListener(validationTextWatcher);
}
Also used : AuthType(com.fsck.k9.mail.AuthType) OnItemSelectedListener(android.widget.AdapterView.OnItemSelectedListener) View(android.view.View)

Example 4 with AuthType

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

the class AccountSetupIncoming method updateViewFromAuthType.

/**
     * Shows/hides password field and client certificate spinner
     */
private void updateViewFromAuthType() {
    AuthType authType = getSelectedAuthType();
    boolean isAuthTypeExternal = (AuthType.EXTERNAL == authType);
    if (isAuthTypeExternal) {
        // hide password fields, show client certificate fields
        mPasswordView.setVisibility(View.GONE);
        mPasswordLabelView.setVisibility(View.GONE);
        mClientCertificateLabelView.setVisibility(View.VISIBLE);
        mClientCertificateSpinner.setVisibility(View.VISIBLE);
    } else {
        // show password fields, hide client certificate fields
        mPasswordView.setVisibility(View.VISIBLE);
        mPasswordLabelView.setVisibility(View.VISIBLE);
        mClientCertificateLabelView.setVisibility(View.GONE);
        mClientCertificateSpinner.setVisibility(View.GONE);
    }
}
Also used : AuthType(com.fsck.k9.mail.AuthType)

Example 5 with AuthType

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

the class AccountSetupOutgoing method updateViewFromAuthType.

/**
     * Shows/hides password field and client certificate spinner
     */
private void updateViewFromAuthType() {
    AuthType authType = getSelectedAuthType();
    boolean isAuthTypeExternal = (AuthType.EXTERNAL == authType);
    if (isAuthTypeExternal) {
        // hide password fields, show client certificate fields
        mPasswordView.setVisibility(View.GONE);
        mPasswordLabelView.setVisibility(View.GONE);
        mClientCertificateLabelView.setVisibility(View.VISIBLE);
        mClientCertificateSpinner.setVisibility(View.VISIBLE);
    } else {
        // show password fields, hide client certificate fields
        mPasswordView.setVisibility(View.VISIBLE);
        mPasswordLabelView.setVisibility(View.VISIBLE);
        mClientCertificateLabelView.setVisibility(View.GONE);
        mClientCertificateSpinner.setVisibility(View.GONE);
    }
}
Also used : AuthType(com.fsck.k9.mail.AuthType)

Aggregations

AuthType (com.fsck.k9.mail.AuthType)14 ServerSettings (com.fsck.k9.mail.ServerSettings)7 ConnectionSecurity (com.fsck.k9.mail.ConnectionSecurity)6 URISyntaxException (java.net.URISyntaxException)6 URI (java.net.URI)5 OnItemSelectedListener (android.widget.AdapterView.OnItemSelectedListener)4 View (android.view.View)2 HashMap (java.util.HashMap)2 SharedPreferences (android.content.SharedPreferences)1 Account (com.fsck.k9.Account)1 Preferences (com.fsck.k9.Preferences)1 Store (com.fsck.k9.mail.Store)1 RemoteStore (com.fsck.k9.mail.store.RemoteStore)1 StoreConfig (com.fsck.k9.mail.store.StoreConfig)1 InvalidSettingValueException (com.fsck.k9.preferences.Settings.InvalidSettingValueException)1 Map (java.util.Map)1 Matchers.anyString (org.mockito.Matchers.anyString)1