Пример #1
0
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
   super.onCreateOptionsMenu(menu);
   menu.add(0, OPTION_MENU_CLEAR_STATUSES_ID, 0, getResources().getText(R.string.clear_statuses))
       .setIcon(android.R.drawable.ic_menu_close_clear_cancel);
   return true;
 }
Пример #2
0
 @Override
 protected void onSaveInstanceState(Bundle outState) {
   super.onSaveInstanceState(outState);
   StatusMode statusMode = (StatusMode) statusModeView.getSelectedItem();
   outState.putString(SAVED_MODE, statusMode.name());
   outState.putString(SAVED_TEXT, statusTextView.getText().toString());
 }
Пример #3
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (isFinishing()) return;
    onInflate(savedInstanceState);
    if (isFinishing()) return;
    Collection<String> groups;
    Collection<String> selected;
    if (savedInstanceState != null) {
      groups = savedInstanceState.getStringArrayList(SAVED_GROUPS);
      selected = savedInstanceState.getStringArrayList(SAVED_SELECTED);
    } else {
      groups = getInitialGroups();
      selected = getInitialSelected();
    }

    listView = getListView();
    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    listView.setOnItemClickListener(this);
    arrayAdapter =
        new ArrayAdapter<>(
            this, android.R.layout.simple_list_item_multiple_choice, new ArrayList<String>());
    LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.add_item, listView, false);
    ((TextView) view.findViewById(android.R.id.message)).setText(R.string.group_add);
    listView.addFooterView(view, null, true);
    setListAdapter(arrayAdapter);
    setGroups(groups, selected);
  }
Пример #4
0
 @Override
 public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
   super.onCreateContextMenu(menu, v, menuInfo);
   AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
   actionWithItem = (SavedStatus) getListView().getItemAtPosition(info.position);
   if (actionWithItem == null) // Header
   return;
   menu.add(0, CONTEXT_MENU_SELECT_STATUS_ID, 0, getResources().getText(R.string.select_status));
   menu.add(0, CONTEXT_MENU_EDIT_STATUS_ID, 0, getResources().getText(R.string.edit_status));
   menu.add(0, CONTEXT_MENU_REMOVE_STATUS_ID, 0, getResources().getText(R.string.remove_status));
 }
Пример #5
0
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   super.onOptionsItemSelected(item);
   switch (item.getItemId()) {
     case OPTION_MENU_CLEAR_STATUSES_ID:
       AccountManager.getInstance().clearSavedStatuses();
       ((UpdatableAdapter) getListAdapter()).onChange();
       return true;
   }
   return false;
 }
Пример #6
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);
  }
Пример #7
0
 @Override
 public boolean onContextItemSelected(MenuItem item) {
   super.onContextItemSelected(item);
   switch (item.getItemId()) {
     case CONTEXT_MENU_SELECT_STATUS_ID:
       setStatus(actionWithItem.getStatusMode(), actionWithItem.getStatusText());
       finish();
       return true;
     case CONTEXT_MENU_EDIT_STATUS_ID:
       showStatus(actionWithItem.getStatusMode(), actionWithItem.getStatusText());
       return true;
     case CONTEXT_MENU_REMOVE_STATUS_ID:
       AccountManager.getInstance().removeSavedStatus(actionWithItem);
       ((UpdatableAdapter) getListAdapter()).onChange();
       return true;
   }
   return false;
 }
Пример #8
0
 @Override
 protected void onResume() {
   super.onResume();
   ((UpdatableAdapter) getListAdapter()).onChange();
 }
Пример #9
0
 @Override
 protected void onSaveInstanceState(Bundle outState) {
   super.onSaveInstanceState(outState);
   outState.putStringArrayList(SAVED_GROUPS, getGroups());
   outState.putStringArrayList(SAVED_SELECTED, getSelected());
 }