Exemplo n.º 1
0
 private void changeGrouping() {
   boolean grouped =
       SettingsManager.contactsShowAccounts() || SettingsManager.contactsShowGroups();
   ((CheckBoxPreference)
           getPreferenceScreen()
               .findPreference(getString(R.string.contacts_stay_active_chats_key)))
       .setChecked(grouped);
   ((CheckBoxPreference)
           getPreferenceScreen()
               .findPreference(getString(R.string.contacts_show_empty_groups_key)))
       .setEnabled(grouped);
 }
Exemplo n.º 2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (isFinishing()) return;

    actionWithItem = null;

    setContentView(R.layout.status_editor);

    Intent intent = getIntent();
    account = StatusEditor.getAccount(intent);
    if (account == null) setTitle(getString(R.string.status_editor));
    else
      setTitle(
          getString(
              R.string.status_editor_for, AccountManager.getInstance().getVerboseName(account)));

    ListView listView = getListView();
    LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
    View header = inflater.inflate(R.layout.status_editor_header, listView, false);
    listView.addHeaderView(header, null, false);
    listView.setOnItemClickListener(this);
    registerForContextMenu(listView);
    setListAdapter(new StatusEditorAdapter(this));

    statusTextView = (EditText) header.findViewById(R.id.status_text);
    statusModeView = (Spinner) header.findViewById(R.id.status_mode);
    statusModeView.setAdapter(new StatusModeAdapter(this));
    ((Button) findViewById(R.id.ok)).setOnClickListener(this);

    StatusMode statusMode;
    String statusText;
    if (savedInstanceState == null) {
      if (account == null) {
        statusMode = SettingsManager.statusMode();
        statusText = SettingsManager.statusText();
      } else {
        AccountItem accountItem = AccountManager.getInstance().getAccount(account);
        if (accountItem == null) {
          Application.getInstance().onError(R.string.NO_SUCH_ACCOUNT);
          finish();
          return;
        }
        statusMode = accountItem.getFactualStatusMode();
        statusText = accountItem.getStatusText();
      }
    } else {
      statusMode = StatusMode.valueOf(savedInstanceState.getString(SAVED_MODE));
      statusText = savedInstanceState.getString(SAVED_TEXT);
    }
    showStatus(statusMode, statusText);
  }
Exemplo n.º 3
0
 /**
  * Sets status for all accounts.
  *
  * @param statusMode
  * @param statusText can be <code>null</code> if value was not changed.
  */
 public void setStatus(StatusMode statusMode, String statusText) {
   SettingsManager.setStatusMode(statusMode);
   if (statusText != null) {
     addSavedStatus(statusMode, statusText);
     SettingsManager.setStatusText(statusText);
   }
   for (AccountItem accountItem : accountItems.values()) {
     setStatus(
         accountItem, statusMode, statusText == null ? accountItem.getStatusText() : statusText);
   }
   resendPresence();
   onAccountsChanged(new ArrayList<String>(AccountManager.getInstance().getAllAccounts()));
 }
  private void showSecurityMenu() {
    PopupMenu popup = new PopupMenu(getActivity(), securityButton);
    popup.inflate(R.menu.security);
    popup.setOnMenuItemClickListener(this);

    Menu menu = popup.getMenu();

    SecurityLevel securityLevel = OTRManager.getInstance().getSecurityLevel(account, user);

    if (securityLevel == SecurityLevel.plain) {
      menu.findItem(R.id.action_start_encryption)
          .setVisible(true)
          .setEnabled(
              SettingsManager.securityOtrMode() != SettingsManager.SecurityOtrMode.disabled);
    } else {
      menu.findItem(R.id.action_restart_encryption).setVisible(true);
    }

    boolean isEncrypted = securityLevel != SecurityLevel.plain;

    menu.findItem(R.id.action_stop_encryption).setEnabled(isEncrypted);
    menu.findItem(R.id.action_verify_with_fingerprint).setEnabled(isEncrypted);
    menu.findItem(R.id.action_verify_with_question).setEnabled(isEncrypted);
    menu.findItem(R.id.action_verify_with_shared_secret).setEnabled(isEncrypted);

    popup.show();
  }
  private void sendMessage() {
    String text = inputView.getText().toString().trim();

    if (text.isEmpty()) {
      return;
    }

    clearInputText();

    sendMessage(text);

    listener.onMessageSent();

    if (SettingsManager.chatsHideKeyboard() == SettingsManager.ChatsHideKeyboard.always
        || (getActivity().getResources().getBoolean(R.bool.landscape)
            && SettingsManager.chatsHideKeyboard()
                == SettingsManager.ChatsHideKeyboard.landscape)) {
      ChatViewer.hideKeyboard(getActivity());
    }
  }
Exemplo n.º 6
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (isFinishing()) return;

    addPreferencesFromResource(R.xml.preference_editor);

    getPreferenceScreen()
        .findPreference(getString(R.string.preference_accounts_key))
        .setIntent(AccountList.createIntent(this));
    getPreferenceScreen()
        .findPreference(getString(R.string.events_phrases))
        .setIntent(PhraseList.createIntent(this));

    getPreferenceScreen()
        .findPreference(getString(R.string.cache_clear_key))
        .setOnPreferenceClickListener(this);
    getPreferenceScreen()
        .findPreference(getString(R.string.security_clear_certificate_key))
        .setOnPreferenceClickListener(this);
    getPreferenceScreen()
        .findPreference(getString(R.string.contacts_reset_offline_key))
        .setOnPreferenceClickListener(this);
    getPreferenceScreen()
        .findPreference(getString(R.string.debug_log_key))
        .setEnabled(LogManager.isDebugable());

    // Force request sound. This will set default value if not specified.
    SettingsManager.eventsSound();
    SettingsManager.chatsAttentionSound();

    PreferenceScreen about =
        (PreferenceScreen)
            getPreferenceScreen().findPreference(getString(R.string.preference_about_key));
    about.setSummary(
        getString(R.string.application_name) + "\n" + getString(R.string.application_version));
    about.setIntent(AboutViewer.createIntent(this));
    PreferenceSummaryHelper.updateSummary(getPreferenceScreen());
  }
Exemplo n.º 7
0
 /**
  * Sets status for account.
  *
  * @param account
  * @param statusMode
  * @param statusText
  */
 public void setStatus(String account, StatusMode statusMode, String statusText) {
   addSavedStatus(statusMode, statusText);
   AccountItem accountItem = getAccount(account);
   setStatus(accountItem, statusMode, statusText);
   try {
     PresenceManager.getInstance().resendPresence(account);
   } catch (NetworkException e) {
   }
   boolean found = false;
   for (AccountItem check : accountItems.values())
     if (check.isEnabled() && SettingsManager.statusMode() == check.getRawStatusMode()) {
       found = true;
       break;
     }
   if (!found) SettingsManager.setStatusMode(statusMode);
   found = false;
   for (AccountItem check : accountItems.values())
     if (check.isEnabled() && SettingsManager.statusText().equals(check.getStatusText())) {
       found = true;
       break;
     }
   if (!found) SettingsManager.setStatusText(statusText);
   onAccountChanged(account);
 }
Exemplo n.º 8
0
  /**
   * Creates new account.
   *
   * @param user full or bare jid.
   * @param password
   * @param accountType xmpp account type can be replaced depend on server part.
   * @param syncable
   * @param storePassword
   * @param useOrbot
   * @return assigned account name.
   * @throws NetworkException if user or server part are invalid.
   */
  public String addAccount(
      String user,
      String password,
      AccountType accountType,
      boolean syncable,
      boolean storePassword,
      boolean useOrbot)
      throws NetworkException {
    if (accountType.getProtocol().isOAuth()) {
      int index = 1;
      while (true) {
        user = String.valueOf(index);
        boolean found = false;
        for (AccountItem accountItem : accountItems.values())
          if (accountItem
                  .getConnectionSettings()
                  .getServerName()
                  .equals(accountType.getFirstServer())
              && accountItem.getConnectionSettings().getUserName().equals(user)) {
            found = true;
            break;
          }
        if (!found) break;
        index++;
      }
    }

    if (user == null) throw new NetworkException(R.string.EMPTY_USER_NAME);

    if (user.indexOf("@") == -1) {
      if ("".equals(accountType.getFirstServer()))
        throw new NetworkException(R.string.EMPTY_SERVER_NAME);
      else user += "@" + accountType.getFirstServer();
    }

    String serverName = StringUtils.parseServer(user);
    String userName = StringUtils.parseName(user);
    String resource = StringUtils.parseResource(user);
    String host = accountType.getHost();
    int port = accountType.getPort();
    boolean tlsRequired = accountType.isTLSRequired();
    if (useOrbot) tlsRequired = true;

    if ("".equals(serverName)) {
      throw new NetworkException(R.string.EMPTY_SERVER_NAME);
    } else if (!accountType.isAllowServer() && !serverName.equals(accountType.getFirstServer()))
      throw new NetworkException(R.string.INCORRECT_USER_NAME);

    if ("".equals(userName)) throw new NetworkException(R.string.EMPTY_USER_NAME);
    if ("".equals(resource)) resource = "android" + StringUtils.randomString(8);

    if (accountType.getId() == R.array.account_type_xmpp) {
      host = serverName;
      for (AccountType check : accountTypes)
        if (check.getServers().contains(serverName)) {
          accountType = check;
          host = check.getHost();
          port = check.getPort();
          tlsRequired = check.isTLSRequired();
          break;
        }
    }

    AccountItem accountItem;
    for (; ; ) {
      if (getAccount(userName + '@' + serverName + '/' + resource) == null) break;
      resource = "android" + StringUtils.randomString(8);
    }

    accountItem =
        addAccount(
            accountType.getProtocol(),
            true,
            host,
            port,
            serverName,
            userName,
            storePassword,
            password,
            resource,
            getNextColorIndex(),
            0,
            StatusMode.available,
            SettingsManager.statusText(),
            true,
            true,
            tlsRequired ? TLSMode.required : TLSMode.enabled,
            false,
            useOrbot ? ProxyType.orbot : ProxyType.none,
            "localhost",
            8080,
            "",
            "",
            syncable,
            null,
            null,
            ArchiveMode.available);
    onAccountChanged(accountItem.getAccount());
    if (accountItems.size() > 1 && SettingsManager.contactsEnableShowAccounts())
      SettingsManager.enableContactsShowAccount();
    return accountItem.getAccount();
  }
Exemplo n.º 9
0
 /**
  * @return Selected account to show contacts. <code>null</code> if
  *     <ul>
  *       <li>there is no selected account,
  *       <li>selected account does not exists or disabled,
  *       <li>Group by account is enabled.
  *     </ul>
  */
 public String getSelectedAccount() {
   if (SettingsManager.contactsShowAccounts()) return null;
   String selected = SettingsManager.contactsSelectedAccount();
   if (enabledAccounts.contains(selected)) return selected;
   return null;
 }
Exemplo n.º 10
0
 public void changeForeground() {
   if (SettingsManager.eventsPersistent() && Application.getInstance().isInitialized())
     startForegroundWrapper(NotificationManager.getInstance().getPersistentNotification());
   else stopForegroundWrapper();
 }
  @Override
  protected void onResume() {
    super.onResume();
    barPainter.setDefaultColor();
    rebuildAccountToggle();
    Application.getInstance().addUIListener(OnAccountChangedListener.class, this);

    if (action != null) {
      switch (action) {
        case ContactList.ACTION_ROOM_INVITE:
        case Intent.ACTION_SEND:
        case Intent.ACTION_CREATE_SHORTCUT:
          if (Intent.ACTION_SEND.equals(action)) {
            sendText = getIntent().getStringExtra(Intent.EXTRA_TEXT);
          }
          Toast.makeText(this, getString(R.string.select_contact), Toast.LENGTH_LONG).show();
          break;
        case Intent.ACTION_VIEW:
          {
            action = null;
            Uri data = getIntent().getData();
            if (data != null && "xmpp".equals(data.getScheme())) {
              XMPPUri xmppUri;
              try {
                xmppUri = XMPPUri.parse(data);
              } catch (IllegalArgumentException e) {
                xmppUri = null;
              }
              if (xmppUri != null && "message".equals(xmppUri.getQueryType())) {
                ArrayList<String> texts = xmppUri.getValues("body");
                String text = null;
                if (texts != null && !texts.isEmpty()) {
                  text = texts.get(0);
                }
                openChat(xmppUri.getPath(), text);
              }
            }
            break;
          }
        case Intent.ACTION_SENDTO:
          {
            action = null;
            Uri data = getIntent().getData();
            if (data != null) {
              String path = data.getPath();
              if (path != null && path.startsWith("/")) {
                openChat(path.substring(1), null);
              }
            }
            break;
          }
      }
    }

    if (Application.getInstance().doNotify()) {
      if (!SettingsManager.isTranslationSuggested()) {
        Locale currentLocale = getResources().getConfiguration().locale;
        if (!currentLocale.getLanguage().equals("en")
            && !getResources().getBoolean(R.bool.is_translated)) {
          new TranslationDialog().show(getFragmentManager(), "TRANSLATION_DIALOG");
          SettingsManager.setTranslationSuggested();
        }
      }

      if (SettingsManager.bootCount() > 2
          && !SettingsManager.connectionStartAtBoot()
          && !SettingsManager.startAtBootSuggested()) {
        StartAtBootDialogFragment.newInstance().show(getFragmentManager(), "START_AT_BOOT");
      }
      if (!SettingsManager.contactIntegrationSuggested()
          && Application.getInstance().isContactsSupported()) {
        if (AccountManager.getInstance().getAllAccounts().isEmpty()) {
          SettingsManager.setContactIntegrationSuggested();
        } else {
          ContactIntegrationDialogFragment.newInstance()
              .show(getFragmentManager(), "CONTACT_INTEGRATION");
        }
      }
    }
  }