Пример #1
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);
  }
Пример #2
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);
 }