Ejemplo n.º 1
0
 @Override
 public void onClick(View view) {
   switch (view.getId()) {
     case R.id.ok:
       String user = userView.getText().toString();
       if ("".equals(user)) {
         Toast.makeText(this, getString(R.string.EMPTY_USER_NAME), Toast.LENGTH_LONG).show();
         return;
       }
       String account = (String) accountView.getSelectedItem();
       if (account == null) {
         Toast.makeText(this, getString(R.string.EMPTY_ACCOUNT), Toast.LENGTH_LONG).show();
         return;
       }
       try {
         RosterManager.getInstance()
             .createContact(account, user, nameView.getText().toString(), getSelected());
         PresenceManager.getInstance().requestSubscription(account, user);
       } catch (NetworkException e) {
         Application.getInstance().onError(e);
         finish();
         return;
       }
       MessageManager.getInstance().openChat(account, user);
       finish();
       break;
     default:
       break;
   }
 }
Ejemplo n.º 2
0
 /** Sends new presence information for all accounts. */
 public void resendPresence() {
   for (AccountItem accountItem : accountItems.values())
     try {
       PresenceManager.getInstance().resendPresence(accountItem.getAccount());
     } catch (NetworkException e) {
     }
 }
Ejemplo n.º 3
0
  @Override
  protected void onInflate(Bundle savedInstanceState) {
    setContentView(R.layout.contact_add);

    ListView listView = getListView();
    LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.contact_add_header, listView, false);
    listView.addHeaderView(view, null, false);

    accountView = (Spinner) view.findViewById(R.id.contact_account);
    accountView.setAdapter(new AccountChooseAdapter(this));
    accountView.setOnItemSelectedListener(this);
    userView = (EditText) view.findViewById(R.id.contact_user);
    nameView = (EditText) view.findViewById(R.id.contact_name);
    ((Button) view.findViewById(R.id.ok)).setOnClickListener(this);

    String name;
    Intent intent = getIntent();
    if (savedInstanceState != null) {
      account = savedInstanceState.getString(SAVED_ACCOUNT);
      user = savedInstanceState.getString(SAVED_USER);
      name = savedInstanceState.getString(SAVED_NAME);
    } else {
      account = getAccount(intent);
      user = getUser(intent);
      if (account == null || user == null) name = null;
      else {
        name = RosterManager.getInstance().getName(account, user);
        if (user.equals(name)) name = null;
      }
    }
    if (account == null) {
      Collection<String> accounts = AccountManager.getInstance().getAccounts();
      if (accounts.size() == 1) account = accounts.iterator().next();
    }
    if (account != null) {
      for (int position = 0; position < accountView.getCount(); position++)
        if (account.equals(accountView.getItemAtPosition(position))) {
          accountView.setSelection(position);
          break;
        }
    }
    if (user != null) userView.setText(user);
    if (name != null) nameView.setText(name);
    if (ACTION_SUBSCRIPTION_REQUEST.equals(intent.getAction())) {
      subscriptionRequest = PresenceManager.getInstance().getSubscriptionRequest(account, user);
      if (subscriptionRequest == null) {
        Application.getInstance().onError(R.string.ENTRY_IS_NOT_FOUND);
        finish();
        return;
      }
    } else {
      subscriptionRequest = null;
    }
  }
Ejemplo n.º 4
0
 @Override
 public void onDecline(DialogBuilder dialogBuilder) {
   super.onDecline(dialogBuilder);
   switch (dialogBuilder.getDialogId()) {
     case DIALOG_SUBSCRIPTION_REQUEST_ID:
       try {
         PresenceManager.getInstance()
             .discardSubscription(subscriptionRequest.getAccount(), subscriptionRequest.getUser());
       } catch (NetworkException e) {
         Application.getInstance().onError(e);
       }
       finish();
       break;
   }
 }
Ejemplo n.º 5
0
 @Override
 public void onAccept(DialogBuilder dialogBuilder) {
   super.onAccept(dialogBuilder);
   switch (dialogBuilder.getDialogId()) {
     case DIALOG_SUBSCRIPTION_REQUEST_ID:
       try {
         PresenceManager.getInstance()
             .acceptSubscription(subscriptionRequest.getAccount(), subscriptionRequest.getUser());
       } catch (NetworkException e) {
         Application.getInstance().onError(e);
       }
       getIntent().setAction(null);
       break;
   }
 }
Ejemplo n.º 6
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);
 }
Ejemplo n.º 7
0
 /**
  * Update user`s account.
  *
  * <p>It will reconnect to the server if changes was made.
  *
  * <p>It will remove old account and create new one if full jid was changed.
  *
  * @param account full source jid
  * @param host
  * @param port
  * @param serverName
  * @param userName
  * @param storePassword
  * @param password
  * @param resource
  * @param priority
  * @param enabled
  * @param saslEnabled
  * @param tlsMode
  * @param compression
  * @param syncable
  * @param archiveMode
  */
 public void updateAccount(
     String account,
     boolean custom,
     String host,
     int port,
     String serverName,
     String userName,
     boolean storePassword,
     String password,
     String resource,
     int priority,
     boolean enabled,
     boolean saslEnabled,
     TLSMode tlsMode,
     boolean compression,
     ProxyType proxyType,
     String proxyHost,
     int proxyPort,
     String proxyUser,
     String proxyPassword,
     boolean syncable,
     ArchiveMode archiveMode) {
   AccountItem result;
   AccountItem accountItem = getAccount(account);
   if (accountItem.getConnectionSettings().getServerName().equals(serverName)
       && accountItem.getConnectionSettings().getUserName().equals(userName)
       && accountItem.getConnectionSettings().getResource().equals(resource)) {
     result = accountItem;
     boolean reconnect = false;
     if (accountItem.getConnectionSettings().isCustom() != custom
         || !accountItem.getConnectionSettings().getHost().equals(host)
         || accountItem.getConnectionSettings().getPort() != port
         || !accountItem.getConnectionSettings().getPassword().equals(password)
         || accountItem.getConnectionSettings().getTlsMode() != tlsMode
         || accountItem.getConnectionSettings().isSaslEnabled() != saslEnabled
         || accountItem.getConnectionSettings().useCompression() != compression
         || accountItem.getConnectionSettings().getProxyType() != proxyType
         || !accountItem.getConnectionSettings().getProxyHost().equals(proxyHost)
         || accountItem.getConnectionSettings().getProxyPort() != proxyPort
         || !accountItem.getConnectionSettings().getProxyUser().equals(proxyUser)
         || !accountItem.getConnectionSettings().getProxyPassword().equals(proxyPassword)) {
       result.updateConnectionSettings(
           custom,
           host,
           port,
           password,
           saslEnabled,
           tlsMode,
           compression,
           proxyType,
           proxyHost,
           proxyPort,
           proxyUser,
           proxyPassword);
       reconnect = true;
     }
     if (result.isSyncable() != syncable) {
       result.setSyncable(syncable);
       for (OnAccountSyncableChangedListener listener :
           application.getManagers(OnAccountSyncableChangedListener.class))
         listener.onAccountSyncableChanged(result);
     }
     result.setStorePassword(storePassword);
     boolean changed = result.isEnabled() != enabled;
     result.setEnabled(enabled);
     if (result.getPriority() != priority) {
       result.setPriority(priority);
       try {
         PresenceManager.getInstance().resendPresence(account);
       } catch (NetworkException e) {
       }
     }
     if (result.getArchiveMode() != archiveMode) {
       reconnect =
           (result.getArchiveMode() == ArchiveMode.server) != (archiveMode == ArchiveMode.server);
       result.setArchiveMode(archiveMode);
       for (OnAccountArchiveModeChangedListener listener :
           application.getManagers(OnAccountArchiveModeChangedListener.class))
         listener.onAccountArchiveModeChanged(result);
     }
     if (changed && enabled) {
       enabledAccounts.add(account);
       onAccountEnabled(result);
       if (result.getRawStatusMode().isOnline()) onAccountOnline(result);
     }
     if (changed || reconnect) {
       result.updateConnection(true);
       result.forceReconnect();
     }
     if (changed && !enabled) {
       enabledAccounts.remove(account);
       if (result.getRawStatusMode().isOnline()) onAccountOffline(result);
       onAccountDisabled(result);
     }
     requestToWriteAccount(result);
   } else {
     int colorIndex = accountItem.getColorIndex();
     StatusMode statusMode = accountItem.getRawStatusMode();
     String statusText = accountItem.getStatusText();
     AccountProtocol protocol = accountItem.getConnectionSettings().getProtocol();
     KeyPair keyPair = accountItem.getKeyPair();
     Date lastSync = accountItem.getLastSync();
     removeAccountWithoutCallback(account);
     result =
         addAccount(
             protocol,
             custom,
             host,
             port,
             serverName,
             userName,
             storePassword,
             password,
             resource,
             colorIndex,
             priority,
             statusMode,
             statusText,
             enabled,
             saslEnabled,
             tlsMode,
             compression,
             proxyType,
             proxyHost,
             proxyPort,
             proxyUser,
             proxyPassword,
             syncable,
             keyPair,
             lastSync,
             archiveMode);
   }
   onAccountChanged(result.getAccount());
 }