コード例 #1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_quick_search_bar);
    final List<ParcelableCredentials> accounts = ParcelableAccount.getCredentialsList(this, false);
    final AccountsSpinnerAdapter accountsSpinnerAdapter =
        new AccountsSpinnerAdapter(this, R.layout.spinner_item_account_icon);
    accountsSpinnerAdapter.setDropDownViewResource(R.layout.list_item_user);
    accountsSpinnerAdapter.addAll(accounts);
    mAccountSpinner.setAdapter(accountsSpinnerAdapter);
    mAccountSpinner.setOnItemSelectedListener(this);
    if (savedInstanceState == null) {
      final Intent intent = getIntent();
      final int index =
          accountsSpinnerAdapter.findItemPosition(intent.getLongExtra(EXTRA_ACCOUNT_ID, -1));
      if (index != -1) {
        mAccountSpinner.setSelection(index);
      }
    }
    mMainContent.setOnFitSystemWindowsListener(this);
    mUsersSearchAdapter = new SuggestionsAdapter(this);
    mSuggestionsList.setAdapter(mUsersSearchAdapter);
    mSuggestionsList.setOnItemClickListener(this);
    mSearchSubmit.setOnClickListener(this);

    EditTextEnterHandler.attach(
        mSearchQuery,
        new EnterListener() {
          @Override
          public boolean shouldCallListener() {
            return true;
          }

          @Override
          public boolean onHitEnter() {
            doSearch();
            return true;
          }
        },
        true);
    mSearchQuery.addTextChangedListener(
        new TextWatcher() {
          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {
            mTextChanged = true;
          }

          @Override
          public void afterTextChanged(Editable s) {
            getSupportLoaderManager().restartLoader(0, null, QuickSearchBarActivity.this);
          }
        });

    getSupportLoaderManager().initLoader(0, null, this);
  }
コード例 #2
0
  @NonNull
  @Override
  public Dialog onCreateDialog(final Bundle savedInstanceState) {
    final Context wrapped = ThemeUtils.getDialogThemedContext(getActivity());
    final AlertDialog.Builder builder = new AlertDialog.Builder(wrapped);
    final Context context = builder.getContext();
    mValidator = new TwidereValidator(context);
    final LayoutInflater inflater = LayoutInflater.from(context);
    @SuppressLint("InflateParams")
    final View view = inflater.inflate(R.layout.dialog_status_quote_retweet, null);
    final DummyStatusHolderAdapter adapter = new DummyStatusHolderAdapter(context);
    adapter.setShouldShowAccountsColor(true);
    final IStatusViewHolder holder =
        new StatusViewHolder(adapter, view.findViewById(R.id.item_content));
    final ParcelableStatus status = getStatus();

    assert status != null;

    builder.setView(view);
    builder.setTitle(R.string.retweet_quote_confirm_title);
    if (isMyRetweet(status)) {
      builder.setPositiveButton(R.string.cancel_retweet, this);
    } else if (!status.user_is_protected) {
      builder.setPositiveButton(R.string.retweet, this);
    }
    builder.setNeutralButton(R.string.quote, this);
    builder.setNegativeButton(android.R.string.cancel, null);

    holder.displayStatus(status, null, false, true);

    view.findViewById(R.id.item_menu).setVisibility(View.GONE);
    view.findViewById(R.id.action_buttons).setVisibility(View.GONE);
    view.findViewById(R.id.item_content).setFocusable(false);
    view.findViewById(R.id.comment_container)
        .setVisibility(status.user_is_protected ? View.GONE : View.VISIBLE);
    final ComposeMaterialEditText mEditComment =
        (ComposeMaterialEditText) view.findViewById(R.id.edit_comment);
    mEditComment.setAccountId(status.account_id);

    final boolean sendByEnter = mPreferences.getBoolean(KEY_QUICK_SEND);
    final EditTextEnterHandler enterHandler =
        EditTextEnterHandler.attach(
            mEditComment,
            new EditTextEnterHandler.EnterListener() {
              @Override
              public boolean shouldCallListener() {
                return true;
              }

              @Override
              public boolean onHitEnter() {
                final AsyncTwitterWrapper twitter = mTwitterWrapper;
                final ParcelableStatus status = getStatus();
                if (twitter == null || status == null) return false;
                retweetOrQuote(twitter, status);
                dismiss();
                return true;
              }
            },
            sendByEnter);
    enterHandler.addTextChangedListener(
        new TextWatcher() {
          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {
            updateTextCount(getDialog(), s, status);
          }

          @Override
          public void afterTextChanged(Editable s) {}
        });
    final View commentMenu = view.findViewById(R.id.comment_menu);

    mPopupMenu =
        new PopupMenu(context, commentMenu, Gravity.NO_GRAVITY, R.attr.actionOverflowMenuStyle, 0);
    commentMenu.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            mPopupMenu.show();
          }
        });
    commentMenu.setOnTouchListener(mPopupMenu.getDragToOpenListener());
    mPopupMenu.inflate(R.menu.menu_dialog_comment);
    final Menu menu = mPopupMenu.getMenu();
    MenuUtils.setMenuItemAvailability(
        menu, R.id.quote_original_status, status.retweet_id > 0 || status.quoted_id > 0);
    mPopupMenu.setOnMenuItemClickListener(
        new PopupMenu.OnMenuItemClickListener() {
          @Override
          public boolean onMenuItemClick(MenuItem item) {
            if (item.isCheckable()) {
              item.setChecked(!item.isChecked());
              return true;
            }
            return false;
          }
        });

    final Dialog dialog = builder.create();
    dialog.setOnShowListener(
        new DialogInterface.OnShowListener() {
          @Override
          public void onShow(DialogInterface dialog) {
            updateTextCount(dialog, mEditComment.getText(), status);
          }
        });
    return dialog;
  }