@Override
 public void onActivityResult(int requestCode, int resultCode, Intent data) {
   if (resultCode == RESULT_OK) {
     if (Intent.ACTION_EDIT.equals(getIntent().getAction())) {
       boolean isPushCapable = false;
       try {
         Store store = mAccount.getRemoteStore();
         isPushCapable = store.isPushCapable();
       } catch (Exception e) {
         Log.e(VisualVoicemail.LOG_TAG, "Could not get remote store", e);
       }
       if (isPushCapable && mAccount.getFolderPushMode() != FolderMode.NONE) {
         MailService.actionRestartPushers(this, null);
       }
       mAccount.save(Preferences.getPreferences(this));
       finish();
     } else {
       // first time setup, return to AccountSetup activity to save account
       setResult(RESULT_OK);
       finish();
     }
   } else {
     if (!Intent.ACTION_EDIT.equals(
         getIntent().getAction())) { // remove account if failed initial setup
       if (mAccount != null) Preferences.getPreferences(this).deleteAccount(mAccount);
     }
   }
 }
Пример #2
0
  @Override
  public void onNewIntent(Intent intent) {
    setIntent(intent); // onNewIntent doesn't autoset our "internal" intent

    String initialFolder;

    mUnreadMessageCount = 0;
    String accountUuid = intent.getStringExtra(EXTRA_ACCOUNT);
    mAccount = Preferences.getPreferences(this).getAccount(accountUuid);

    if (mAccount == null) {
      // This shouldn't normally happen. But apparently it does. See issue 2261.
      finish();
      return;
    }

    initialFolder = intent.getStringExtra(EXTRA_INITIAL_FOLDER);
    boolean fromNotification = intent.getBooleanExtra(EXTRA_FROM_NOTIFICATION, false);
    if (fromNotification && mAccount.goToUnreadMessageSearch()) {
      MessagingController.getInstance(getApplication()).notifyAccountCancel(this, mAccount);
      openUnreadSearch(this, mAccount);
      finish();
    } 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())) {
      onOpenFolder(mAccount.getAutoExpandFolderName());
      finish();
    } else {

      initializeActivityView();
    }
  }
Пример #3
0
 private void setDisplayMode(FolderMode newMode) {
   mAccount.setFolderDisplayMode(newMode);
   mAccount.save(Preferences.getPreferences(this));
   if (mAccount.getFolderPushMode() != FolderMode.NONE) {
     MailService.actionRestartPushers(this, null);
   }
   onRefresh(false);
 }
Пример #4
0
  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();
  }
Пример #5
0
  /**
   * Load preferences into our statics.
   *
   * <p>If you're adding a preference here, odds are you'll need to add it to {@link
   * com.fsck.k9.preferences.GlobalSettings}, too.
   *
   * @param prefs Preferences to load
   */
  public static void loadPrefs(Preferences prefs) {
    SharedPreferences sprefs = prefs.getPreferences();
    DEBUG = sprefs.getBoolean("enableDebugLogging", false);
    if (!DEBUG && sIsDebuggable && Debug.isDebuggerConnected()) {
      // If the debugger is attached, we're probably (surprise surprise) debugging something.
      DEBUG = true;
      Log.i(K9.LOG_TAG, "Debugger attached; enabling debug logging.");
    }
    DEBUG_SENSITIVE = sprefs.getBoolean("enableSensitiveLogging", false);
    mAnimations = sprefs.getBoolean("animations", true);
    mGesturesEnabled = sprefs.getBoolean("gesturesEnabled", false);
    mUseVolumeKeysForNavigation = sprefs.getBoolean("useVolumeKeysForNavigation", false);
    mUseVolumeKeysForListNavigation = sprefs.getBoolean("useVolumeKeysForListNavigation", false);
    mStartIntegratedInbox = sprefs.getBoolean("startIntegratedInbox", false);
    mMeasureAccounts = sprefs.getBoolean("measureAccounts", true);
    mCountSearchMessages = sprefs.getBoolean("countSearchMessages", true);
    mHideSpecialAccounts = sprefs.getBoolean("hideSpecialAccounts", false);
    mMessageListSenderAboveSubject = sprefs.getBoolean("messageListSenderAboveSubject", false);
    mMessageListCheckboxes = sprefs.getBoolean("messageListCheckboxes", false);
    mMessageListStars = sprefs.getBoolean("messageListStars", true);
    mMessageListPreviewLines = sprefs.getInt("messageListPreviewLines", 2);

    mAutofitWidth = sprefs.getBoolean("autofitWidth", true);

    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);
    sShowContactPicture = sprefs.getBoolean("showContactPicture", true);
    mChangeContactNameColor = sprefs.getBoolean("changeRegisteredNameColor", false);
    mContactNameColor = sprefs.getInt("registeredNameColor", 0xff00008f);
    mMessageViewFixedWidthFont = sprefs.getBoolean("messageViewFixedWidthFont", false);
    mMessageViewReturnToList = sprefs.getBoolean("messageViewReturnToList", false);
    mMessageViewShowNext = sprefs.getBoolean("messageViewShowNext", false);
    mWrapFolderNames = sprefs.getBoolean("wrapFolderNames", false);
    mHideUserAgent = sprefs.getBoolean("hideUserAgent", false);
    mHideTimeZone = sprefs.getBoolean("hideTimeZone", false);

    mConfirmDelete = sprefs.getBoolean("confirmDelete", false);
    mConfirmDeleteStarred = sprefs.getBoolean("confirmDeleteStarred", false);
    mConfirmSpam = sprefs.getBoolean("confirmSpam", false);
    mConfirmDeleteFromNotification = sprefs.getBoolean("confirmDeleteFromNotification", true);

    try {
      String value = sprefs.getString("sortTypeEnum", Account.DEFAULT_SORT_TYPE.name());
      mSortType = SortType.valueOf(value);
    } catch (Exception e) {
      mSortType = Account.DEFAULT_SORT_TYPE;
    }

    boolean sortAscending = sprefs.getBoolean("sortAscending", Account.DEFAULT_SORT_ASCENDING);
    mSortAscending.put(mSortType, sortAscending);

    String notificationHideSubject = sprefs.getString("notificationHideSubject", null);
    if (notificationHideSubject == null) {
      // If the "notificationHideSubject" setting couldn't be found, the app was probably
      // updated. Look for the old "keyguardPrivacy" setting and map it to the new enum.
      sNotificationHideSubject =
          (sprefs.getBoolean("keyguardPrivacy", false))
              ? NotificationHideSubject.WHEN_LOCKED
              : NotificationHideSubject.NEVER;
    } else {
      sNotificationHideSubject = NotificationHideSubject.valueOf(notificationHideSubject);
    }

    String notificationQuickDelete = sprefs.getString("notificationQuickDelete", null);
    if (notificationQuickDelete != null) {
      sNotificationQuickDelete = NotificationQuickDelete.valueOf(notificationQuickDelete);
    }

    String lockScreenNotificationVisibility =
        sprefs.getString("lockScreenNotificationVisibility", null);
    if (lockScreenNotificationVisibility != null) {
      sLockScreenNotificationVisibility =
          LockScreenNotificationVisibility.valueOf(lockScreenNotificationVisibility);
    }

    String splitViewMode = sprefs.getString("splitViewMode", null);
    if (splitViewMode != null) {
      sSplitViewMode = SplitViewMode.valueOf(splitViewMode);
    }

    mAttachmentDefaultPath =
        sprefs.getString(
            "attachmentdefaultpath", Environment.getExternalStorageDirectory().toString());
    sUseBackgroundAsUnreadIndicator = sprefs.getBoolean("useBackgroundAsUnreadIndicator", true);
    sThreadedViewEnabled = sprefs.getBoolean("threadedView", true);
    fontSizes.load(sprefs);

    try {
      setBackgroundOps(
          BACKGROUND_OPS.valueOf(
              sprefs.getString(
                  "backgroundOperations", BACKGROUND_OPS.WHEN_CHECKED_AUTO_SYNC.name())));
    } catch (Exception e) {
      setBackgroundOps(BACKGROUND_OPS.WHEN_CHECKED_AUTO_SYNC);
    }

    sColorizeMissingContactPictures = sprefs.getBoolean("colorizeMissingContactPictures", true);

    sMessageViewArchiveActionVisible = sprefs.getBoolean("messageViewArchiveActionVisible", false);
    sMessageViewDeleteActionVisible = sprefs.getBoolean("messageViewDeleteActionVisible", true);
    sMessageViewMoveActionVisible = sprefs.getBoolean("messageViewMoveActionVisible", false);
    sMessageViewCopyActionVisible = sprefs.getBoolean("messageViewCopyActionVisible", false);
    sMessageViewSpamActionVisible = sprefs.getBoolean("messageViewSpamActionVisible", false);

    K9.setK9Language(sprefs.getString("language", ""));

    int themeValue = sprefs.getInt("theme", Theme.LIGHT.ordinal());
    // We used to save the resource ID of the theme. So convert that to the new format if
    // necessary.
    if (themeValue == Theme.DARK.ordinal() || themeValue == android.R.style.Theme) {
      K9.setK9Theme(Theme.DARK);
    } else {
      K9.setK9Theme(Theme.LIGHT);
    }

    themeValue = sprefs.getInt("messageViewTheme", Theme.USE_GLOBAL.ordinal());
    K9.setK9MessageViewThemeSetting(Theme.values()[themeValue]);
    themeValue = sprefs.getInt("messageComposeTheme", Theme.USE_GLOBAL.ordinal());
    K9.setK9ComposerThemeSetting(Theme.values()[themeValue]);
    K9.setUseFixedMessageViewTheme(sprefs.getBoolean("fixedMessageViewTheme", true));
  }
Пример #6
0
  @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();
  }
Пример #7
0
  /**
   * 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);
  }
  public void onBackPressed() {
    if (!Intent.ACTION_EDIT.equals(getIntent().getAction()) && mAccount != null)
      Preferences.getPreferences(this).deleteAccount(mAccount);

    super.onBackPressed();
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.account_setup_incoming);

    mUsernameView = (EditText) findViewById(R.id.account_username);
    mPasswordView = (EditText) findViewById(R.id.account_password);
    mClientCertificateSpinner =
        (ClientCertificateSpinner) findViewById(R.id.account_client_certificate_spinner);
    mClientCertificateLabelView = (TextView) findViewById(R.id.account_client_certificate_label);
    mPasswordLabelView = (TextView) findViewById(R.id.account_password_label);
    TextView serverLabelView = (TextView) findViewById(R.id.account_server_label);
    mServerView = (EditText) findViewById(R.id.account_server);
    mPortView = (EditText) findViewById(R.id.account_port);
    mSecurityTypeView = (Spinner) findViewById(R.id.account_security_type);
    mAuthTypeView = (Spinner) findViewById(R.id.account_auth_type);
    mImapAutoDetectNamespaceView = (CheckBox) findViewById(R.id.imap_autodetect_namespace);
    mImapPathPrefixView = (EditText) findViewById(R.id.imap_path_prefix);
    mWebdavPathPrefixView = (EditText) findViewById(R.id.webdav_path_prefix);
    mWebdavAuthPathView = (EditText) findViewById(R.id.webdav_auth_path);
    mWebdavMailboxPathView = (EditText) findViewById(R.id.webdav_mailbox_path);
    mNextButton = (Button) findViewById(R.id.next);
    mCompressionMobile = (CheckBox) findViewById(R.id.compression_mobile);
    mCompressionWifi = (CheckBox) findViewById(R.id.compression_wifi);
    mCompressionOther = (CheckBox) findViewById(R.id.compression_other);
    // mSubscribedFoldersOnly = (CheckBox)findViewById(R.id.subscribed_folders_only);
    mRequiresCellular = (CheckBox) findViewById(R.id.account_requires_cellular);
    mAccountName = (EditText) findViewById(R.id.account_name);

    mNextButton.setOnClickListener(this);

    mImapAutoDetectNamespaceView.setOnCheckedChangeListener(
        new OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mImapPathPrefixView.setEnabled(!isChecked);
            if (isChecked && mImapPathPrefixView.hasFocus()) {
              mImapPathPrefixView.focusSearch(View.FOCUS_UP).requestFocus();
            } else if (!isChecked) {
              mImapPathPrefixView.requestFocus();
            }
          }
        });

    mAuthTypeAdapter = AuthTypeAdapter.get(this);
    mAuthTypeView.setAdapter(mAuthTypeAdapter);

    /*
     * Only allow digits in the port field.
     */
    mPortView.setKeyListener(DigitsKeyListener.getInstance("0123456789"));

    String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
    mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
    // mMakeDefault = getIntent().getBooleanExtra(EXTRA_MAKE_DEFAULT, false);

    /*
     * If we're being reloaded we override the original account with the one
     * we saved
     */
    if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_ACCOUNT)) {
      accountUuid = savedInstanceState.getString(EXTRA_ACCOUNT);
      mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
    }

    boolean editSettings = Intent.ACTION_EDIT.equals(getIntent().getAction());

    try {
      ServerSettings settings = RemoteStore.decodeStoreUri(mAccount.getStoreUri());

      if (savedInstanceState == null) {
        // The first item is selected if settings.authenticationType is null or is not in
        // mAuthTypeAdapter
        mCurrentAuthTypeViewPosition =
            mAuthTypeAdapter.getAuthPosition(settings.authenticationType);
      } else {
        mCurrentAuthTypeViewPosition = savedInstanceState.getInt(STATE_AUTH_TYPE_POSITION);
      }
      mAuthTypeView.setSelection(mCurrentAuthTypeViewPosition, false);
      updateViewFromAuthType();

      if (settings.username != null) {
        mUsernameView.setText(settings.username);
      }

      if (settings.password != null) {
        mPasswordView.setText(settings.password);
      }

      if (settings.clientCertificateAlias != null) {
        mClientCertificateSpinner.setAlias(settings.clientCertificateAlias);
      }

      mStoreType = settings.type;
      if (Type.POP3 == settings.type) {
        serverLabelView.setText(R.string.account_setup_incoming_pop_server_label);
        findViewById(R.id.imap_path_prefix_section).setVisibility(View.GONE);
        findViewById(R.id.webdav_advanced_header).setVisibility(View.GONE);
        findViewById(R.id.webdav_mailbox_alias_section).setVisibility(View.GONE);
        findViewById(R.id.webdav_owa_path_section).setVisibility(View.GONE);
        findViewById(R.id.webdav_auth_path_section).setVisibility(View.GONE);
        findViewById(R.id.compression_section).setVisibility(View.GONE);
        findViewById(R.id.compression_label).setVisibility(View.GONE);
        // mSubscribedFoldersOnly.setVisibility(View.GONE);
      } else if (Type.IMAP == settings.type) {
        serverLabelView.setText(R.string.account_setup_incoming_imap_server_label);

        ImapStoreSettings imapSettings = (ImapStoreSettings) settings;

        mImapAutoDetectNamespaceView.setChecked(imapSettings.autoDetectNamespace);
        if (imapSettings.pathPrefix != null) {
          mImapPathPrefixView.setText(imapSettings.pathPrefix);
        }

        findViewById(R.id.webdav_advanced_header).setVisibility(View.GONE);
        findViewById(R.id.webdav_mailbox_alias_section).setVisibility(View.GONE);
        findViewById(R.id.webdav_owa_path_section).setVisibility(View.GONE);
        findViewById(R.id.webdav_auth_path_section).setVisibility(View.GONE);

        /*if (!editSettings) {
            findViewById(R.id.imap_folder_setup_section).setVisibility(View.GONE);
        }*/
      } else if (Type.WebDAV == settings.type) {
        serverLabelView.setText(R.string.account_setup_incoming_webdav_server_label);
        mConnectionSecurityChoices =
            new ConnectionSecurity[] {ConnectionSecurity.NONE, ConnectionSecurity.SSL_TLS_REQUIRED};

        // Hide the unnecessary fields
        findViewById(R.id.imap_path_prefix_section).setVisibility(View.GONE);
        findViewById(R.id.account_auth_type_label).setVisibility(View.GONE);
        findViewById(R.id.account_auth_type).setVisibility(View.GONE);
        findViewById(R.id.compression_section).setVisibility(View.GONE);
        findViewById(R.id.compression_label).setVisibility(View.GONE);
        // mSubscribedFoldersOnly.setVisibility(View.GONE);

        WebDavStoreSettings webDavSettings = (WebDavStoreSettings) settings;

        if (webDavSettings.path != null) {
          mWebdavPathPrefixView.setText(webDavSettings.path);
        }

        if (webDavSettings.authPath != null) {
          mWebdavAuthPathView.setText(webDavSettings.authPath);
        }

        if (webDavSettings.mailboxPath != null) {
          mWebdavMailboxPathView.setText(webDavSettings.mailboxPath);
        }
      } else {
        throw new Exception("Unknown account type: " + mAccount.getStoreUri());
      }

      if (!editSettings) {
        mAccount.setDeletePolicy(AccountCreator.getDefaultDeletePolicy(settings.type));
      }

      // Note that mConnectionSecurityChoices is configured above based on server type
      ConnectionSecurityAdapter securityTypesAdapter =
          ConnectionSecurityAdapter.get(this, mConnectionSecurityChoices);
      mSecurityTypeView.setAdapter(securityTypesAdapter);

      // Select currently configured security type
      if (savedInstanceState == null) {
        mCurrentSecurityTypeViewPosition =
            securityTypesAdapter.getConnectionSecurityPosition(settings.connectionSecurity);
      } else {

        /*
         * Restore the spinner state now, before calling
         * setOnItemSelectedListener(), thus avoiding a call to
         * onItemSelected(). Then, when the system restores the state
         * (again) in onRestoreInstanceState(), The system will see that
         * the new state is the same as the current state (set here), so
         * once again onItemSelected() will not be called.
         */
        mCurrentSecurityTypeViewPosition = savedInstanceState.getInt(STATE_SECURITY_TYPE_POSITION);
      }
      mSecurityTypeView.setSelection(mCurrentSecurityTypeViewPosition, false);

      updateAuthPlainTextFromSecurityType(settings.connectionSecurity);

      mCompressionMobile.setChecked(mAccount.useCompression(NetworkType.MOBILE));
      mCompressionWifi.setChecked(mAccount.useCompression(NetworkType.WIFI));
      mCompressionOther.setChecked(mAccount.useCompression(NetworkType.OTHER));

      if (settings.host != null) {
        mServerView.setText(settings.host);
      }

      if (settings.port != -1) {
        mPortView.setText(Integer.toString(settings.port));
      } else {
        updatePortFromSecurityType();
      }
      mCurrentPortViewSetting = mPortView.getText().toString();

      // mSubscribedFoldersOnly.setChecked(mAccount.subscribedFoldersOnly());
    } catch (Exception e) {
      failure(e);
    }
    // show & populate setup fields
    if (!Intent.ACTION_EDIT.equals(getIntent().getAction())) {
      findViewById(R.id.account_name_label).setVisibility(View.VISIBLE);
      mAccountName.setVisibility(View.VISIBLE);
      String desc = mAccount.getDescription();
      mAccountName.setText((desc != null ? desc : ""));
      findViewById(R.id.account_requires_cellular_label).setVisibility(View.VISIBLE);
      mRequiresCellular.setVisibility(View.VISIBLE);
      mRequiresCellular.setChecked(true);
    }
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.account_setup_check_settings);
    mMessageView = (TextView) findViewById(R.id.message);
    mProgressBar = (ProgressBar) findViewById(R.id.progress);
    ((Button) findViewById(R.id.cancel)).setOnClickListener(this);

    setMessage(R.string.account_setup_check_settings_retr_info_msg);
    mProgressBar.setIndeterminate(true);

    String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
    mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
    mDirection = (CheckDirection) getIntent().getSerializableExtra(EXTRA_CHECK_DIRECTION);

    new Thread() {
      @Override
      public void run() {
        Store store = null;
        Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
        try {
          if (mDestroyed) {
            return;
          }
          if (mCanceled) {
            finish();
            return;
          }

          final MessagingController ctrl = MessagingController.getInstance(getApplication());
          ctrl.clearCertificateErrorNotifications(
              AccountSetupCheckSettings.this, mAccount, mDirection);

          if (mDirection == CheckDirection.INCOMING) {
            store = mAccount.getRemoteStore();

            if (store instanceof WebDavStore) {
              setMessage(R.string.account_setup_check_settings_authenticate);
            } else {
              setMessage(R.string.account_setup_check_settings_check_incoming_msg);
            }
            store.checkSettings();

            if (store instanceof WebDavStore) {
              setMessage(R.string.account_setup_check_settings_fetch);
            }
            MessagingController.getInstance(getApplication())
                .listFoldersSynchronous(mAccount, true, null);
            MessagingController.getInstance(getApplication())
                .synchronizeMailbox(mAccount, mAccount.getInboxFolderName(), null, null);
          }
          if (mDestroyed) {
            return;
          }
          if (mCanceled) {
            finish();
            return;
          }
          if (mDirection == CheckDirection.OUTGOING) {
            if (!(mAccount.getRemoteStore() instanceof WebDavStore)) {
              setMessage(R.string.account_setup_check_settings_check_outgoing_msg);
            }
            Transport transport = Transport.getInstance(mAccount);
            transport.close();
            transport.open();
            transport.close();
          }
          if (mDestroyed) {
            return;
          }
          if (mCanceled) {
            finish();
            return;
          }
          setResult(RESULT_OK);
          finish();
        } 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) {
          handleCertificateValidationException(cve);
        } catch (final Throwable t) {
          Log.e(K9.LOG_TAG, "Error while testing settings", t);
          showErrorDialog(
              R.string.account_setup_failed_dlg_server_message_fmt,
              (t.getMessage() == null ? "" : t.getMessage()));
        }
      }
    }.start();
  }
Пример #11
0
  @Override
  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 {
      LocalStore localStore = mAccount.getLocalStore();
      mFolder = localStore.getFolder(folderName);
      mFolder.open(OpenMode.READ_WRITE);
    } catch (MessagingException me) {
      Log.e(K9.LOG_TAG, "Unable to edit folder " + folderName + " preferences", me);
      return;
    }

    boolean isPushCapable = false;
    Store store = null;
    try {
      store = mAccount.getRemoteStore();
      isPushCapable = store.isPushCapable();
    } catch (Exception e) {
      Log.e(K9.LOG_TAG, "Could not get remote store", e);
    }

    addPreferencesFromResource(R.xml.folder_settings_preferences);

    Preference category = findPreference(PREFERENCE_TOP_CATERGORY);
    category.setTitle(folderName);

    mInTopGroup = (CheckBoxPreference) findPreference(PREFERENCE_IN_TOP_GROUP);
    mInTopGroup.setChecked(mFolder.isInTopGroup());
    mIntegrate = (CheckBoxPreference) findPreference(PREFERENCE_INTEGRATE);
    mIntegrate.setChecked(mFolder.isIntegrate());

    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) {
            final String summary = newValue.toString();
            int index = mDisplayClass.findIndexOfValue(summary);
            mDisplayClass.setSummary(mDisplayClass.getEntries()[index]);
            mDisplayClass.setValue(summary);
            return false;
          }
        });

    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) {
            final String summary = newValue.toString();
            int index = mSyncClass.findIndexOfValue(summary);
            mSyncClass.setSummary(mSyncClass.getEntries()[index]);
            mSyncClass.setValue(summary);
            return false;
          }
        });

    mPushClass = (ListPreference) findPreference(PREFERENCE_PUSH_CLASS);
    mPushClass.setEnabled(isPushCapable);
    mPushClass.setValue(mFolder.getRawPushClass().name());
    mPushClass.setSummary(mPushClass.getEntry());
    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]);
            mPushClass.setValue(summary);
            return false;
          }
        });
  }
Пример #12
0
          @Override
          public void listFolders(Account account, Folder[] folders) {
            if (account.equals(mAccount)) {

              List<FolderInfoHolder> newFolders = new LinkedList<FolderInfoHolder>();
              List<FolderInfoHolder> topFolders = new LinkedList<FolderInfoHolder>();

              Account.FolderMode aMode = account.getFolderDisplayMode();
              Preferences prefs =
                  Preferences.getPreferences(getApplication().getApplicationContext());
              for (Folder folder : folders) {
                try {
                  folder.refresh(prefs);

                  Folder.FolderClass fMode = folder.getDisplayClass();

                  if ((aMode == Account.FolderMode.FIRST_CLASS
                          && fMode != Folder.FolderClass.FIRST_CLASS)
                      || (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)) {
                    continue;
                  }
                } 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) {
                  holder = (FolderInfoHolder) getItem(folderIndex);
                }
                int unreadMessageCount = 0;
                try {
                  unreadMessageCount = folder.getUnreadMessageCount();
                } catch (Exception e) {
                  Log.e(
                      K9.LOG_TAG,
                      "Unable to get unreadMessageCount for "
                          + mAccount.getDescription()
                          + ":"
                          + folder.getName());
                }

                if (holder == null) {
                  holder = new FolderInfoHolder(context, folder, mAccount, unreadMessageCount);
                } else {
                  holder.populate(context, folder, mAccount, unreadMessageCount);
                }
                if (folder.isInTopGroup()) {
                  topFolders.add(holder);
                } else {
                  newFolders.add(holder);
                }
              }
              Collections.sort(newFolders);
              Collections.sort(topFolders);
              topFolders.addAll(newFolders);
              mHandler.newFolders(topFolders);
            }
            super.listFolders(account, folders);
          }
Пример #13
0
 /* (non-Javadoc)
  * @see android.app.Activity#onStart()
  */
 @Override
 protected void onStart() {
   super.onStart();
   prefs.getPreferences(getBaseContext());
 }
Пример #14
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.account_setup_options);

    mCheckFrequencyView = (Spinner) findViewById(R.id.account_check_frequency);
    mDisplayCountView = (Spinner) findViewById(R.id.account_display_count);
    mNotifyView = (CheckBox) findViewById(R.id.account_notify);
    mNotifySyncView = (CheckBox) findViewById(R.id.account_notify_sync);
    mPushEnable = (CheckBox) findViewById(R.id.account_enable_push);

    findViewById(R.id.next).setOnClickListener(this);

    SpinnerOption checkFrequencies[] = {
      new SpinnerOption(-1, getString(R.string.account_setup_options_mail_check_frequency_never)),
      new SpinnerOption(1, getString(R.string.account_setup_options_mail_check_frequency_1min)),
      new SpinnerOption(5, getString(R.string.account_setup_options_mail_check_frequency_5min)),
      new SpinnerOption(10, getString(R.string.account_setup_options_mail_check_frequency_10min)),
      new SpinnerOption(15, getString(R.string.account_setup_options_mail_check_frequency_15min)),
      new SpinnerOption(30, getString(R.string.account_setup_options_mail_check_frequency_30min)),
      new SpinnerOption(60, getString(R.string.account_setup_options_mail_check_frequency_1hour)),
      new SpinnerOption(120, getString(R.string.account_setup_options_mail_check_frequency_2hour)),
      new SpinnerOption(180, getString(R.string.account_setup_options_mail_check_frequency_3hour)),
      new SpinnerOption(360, getString(R.string.account_setup_options_mail_check_frequency_6hour)),
      new SpinnerOption(720, getString(R.string.account_setup_options_mail_check_frequency_12hour)),
      new SpinnerOption(
          1440, getString(R.string.account_setup_options_mail_check_frequency_24hour)),
    };

    ArrayAdapter<SpinnerOption> checkFrequenciesAdapter =
        new ArrayAdapter<SpinnerOption>(
            this, android.R.layout.simple_spinner_item, checkFrequencies);
    checkFrequenciesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mCheckFrequencyView.setAdapter(checkFrequenciesAdapter);

    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)),
      new SpinnerOption(100, getString(R.string.account_setup_options_mail_display_count_100)),
      new SpinnerOption(250, getString(R.string.account_setup_options_mail_display_count_250)),
      new SpinnerOption(500, getString(R.string.account_setup_options_mail_display_count_500)),
      new SpinnerOption(1000, getString(R.string.account_setup_options_mail_display_count_1000)),
    };

    ArrayAdapter<SpinnerOption> displayCountsAdapter =
        new ArrayAdapter<SpinnerOption>(this, android.R.layout.simple_spinner_item, displayCounts);
    displayCountsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mDisplayCountView.setAdapter(displayCountsAdapter);

    String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
    mAccount = Preferences.getPreferences(this).getAccount(accountUuid);

    mNotifyView.setChecked(mAccount.isNotifyNewMail());
    mNotifySyncView.setChecked(mAccount.isShowOngoing());
    SpinnerOption.setSpinnerOptionValue(
        mCheckFrequencyView, mAccount.getAutomaticCheckIntervalMinutes());
    SpinnerOption.setSpinnerOptionValue(mDisplayCountView, mAccount.getDisplayCount());

    boolean isPushCapable = false;
    try {
      Store store = mAccount.getRemoteStore();
      isPushCapable = store.isPushCapable();
    } catch (Exception e) {
      Log.e(K9.LOG_TAG, "Could not get remote store", e);
    }

    if (!isPushCapable) {
      mPushEnable.setVisibility(View.GONE);
    } else {
      mPushEnable.setChecked(true);
    }
  }
Пример #15
0
Файл: K9.java Проект: kamilk/k-9
  @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();
  }