androidx.appcompat.widget.ListPopupWindow Java Examples

The following examples show how to use androidx.appcompat.widget.ListPopupWindow. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AlbumsSpinner.java    From Matisse with Apache License 2.0 6 votes vote down vote up
public AlbumsSpinner(@NonNull Context context) {
    mListPopupWindow = new ListPopupWindow(context, null, R.attr.listPopupWindowStyle);
    mListPopupWindow.setModal(true);
    float density = context.getResources().getDisplayMetrics().density;
    mListPopupWindow.setContentWidth((int) (216 * density));
    mListPopupWindow.setHorizontalOffset((int) (16 * density));
    mListPopupWindow.setVerticalOffset((int) (-48 * density));

    mListPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            AlbumsSpinner.this.onItemSelected(parent.getContext(), position);
            if (mOnItemSelectedListener != null) {
                mOnItemSelectedListener.onItemSelected(parent, view, position, id);
            }
        }
    });
}
 
Example #2
Source File: MenuMainDemoFragment.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateDemoView(
    LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) {
  View view = layoutInflater.inflate(R.layout.cat_menu_fragment, viewGroup, false);
  Button button = view.findViewById(R.id.menu_button);
  Button iconMenuButton = view.findViewById(R.id.menu_button_with_icons);
  button.setOnClickListener(v -> showMenu(v, R.menu.popup_menu));
  iconMenuButton.setOnClickListener(v -> showMenu(v, R.menu.menu_with_icons));

  TextView contextMenuTextView = view.findViewById(R.id.context_menu_tv);
  registerForContextMenu(contextMenuTextView);

  Button listPopupWindowButton = view.findViewById(R.id.list_popup_window);
  ListPopupWindow listPopupWindow = initializeListPopupMenu(listPopupWindowButton);
  listPopupWindowButton.setOnClickListener(v -> listPopupWindow.show());

  return view;
}
 
Example #3
Source File: MenuMainDemoFragment.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
private ListPopupWindow initializeListPopupMenu(View v) {
  ListPopupWindow listPopupWindow =
      new ListPopupWindow(getContext(), null, R.attr.listPopupWindowStyle);
  ArrayAdapter<CharSequence> adapter =
      new ArrayAdapter<>(
          getContext(),
          popupItemLayout,
          getResources().getStringArray(R.array.cat_list_popup_window_content));
  listPopupWindow.setAdapter(adapter);
  listPopupWindow.setAnchorView(v);
  listPopupWindow.setOnItemClickListener(
      (parent, view, position, id) -> {
        Snackbar.make(
                getActivity().findViewById(android.R.id.content),
                adapter.getItem(position).toString(),
                Snackbar.LENGTH_LONG)
            .show();
        listPopupWindow.dismiss();
      });
  return listPopupWindow;
}
 
Example #4
Source File: Popup.java    From candybar with Apache License 2.0 5 votes vote down vote up
private Popup(Builder builder) {
    mPopupWindow = new ListPopupWindow(builder.mContext);
    mAdapter = new PopupAdapter(builder.mContext, builder.mItems);

    int width = getMeasuredWidth(builder.mContext);
    mPopupWindow.setWidth(width);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Drawable drawable = mPopupWindow.getBackground();
        if (drawable != null) {
            drawable.setColorFilter(ColorHelper.getAttributeColor(
                    builder.mContext, R.attr.card_background), PorterDuff.Mode.SRC_IN);
        }
    } else {
        mPopupWindow.setBackgroundDrawable(new ColorDrawable(
                ColorHelper.getAttributeColor(builder.mContext, R.attr.card_background)));
    }

    mPopupWindow.setAnchorView(builder.mTo);
    mPopupWindow.setAdapter(mAdapter);
    mPopupWindow.setOnItemClickListener((adapterView, view, i, l) -> {
        if (builder.mCallback != null) {
            builder.mCallback.onClick(this, i);
            return;
        }

        mPopupWindow.dismiss();
    });
}
 
Example #5
Source File: TransportOptionsPopup.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public TransportOptionsPopup(@NonNull Context context, @NonNull View anchor, @NonNull SelectedListener listener) {
  super(context);
  this.listener = listener;
  this.adapter  = new TransportOptionsAdapter(context, new LinkedList<TransportOption>());

  setVerticalOffset(context.getResources().getDimensionPixelOffset(R.dimen.transport_selection_popup_yoff));
  setHorizontalOffset(context.getResources().getDimensionPixelOffset(R.dimen.transport_selection_popup_xoff));
  setInputMethodMode(ListPopupWindow.INPUT_METHOD_NOT_NEEDED);
  setModal(true);
  setAnchorView(anchor);
  setAdapter(adapter);
  setContentWidth(context.getResources().getDimensionPixelSize(R.dimen.transport_selection_popup_width));

  setOnItemClickListener(this);
}
 
Example #6
Source File: TextInputSpinner.java    From HaoReader with GNU General Public License v3.0 5 votes vote down vote up
@SuppressLint("RestrictedApi")
private void init(Context context, AttributeSet attrs, int defStyleAttr) {
    setInputType(InputType.TYPE_NULL);
    setCursorVisible(false);
    Drawable arrow = getResources().getDrawable(R.drawable.ic_arrow_drop_down_black_24dp);
    arrow.setBounds(0, 0, arrow.getIntrinsicWidth(), arrow.getIntrinsicHeight());
    setCompoundDrawablesRelative(null, null, arrow, null);
    AppCompat.setTint(arrow, getResources().getColor(R.color.colorMenuText));

    TypedArray a = context.obtainStyledAttributes(attrs,
            R.styleable.TextInputSpinner, defStyleAttr, 0);
    mEntities = a.getTextArray(R.styleable.TextInputSpinner_android_entries);
    a.recycle();

    mPopup = new ListPopupWindow(context, attrs, defStyleAttr, R.style.AppTheme_PopupMenu_Overflow);
    mPopup.setAdapter(new ArrayAdapter<>(context, R.layout.support_simple_spinner_dropdown_item, mEntities));
    mPopup.setOnItemClickListener((parent, view, position, id) -> {
        setSelection(position);
        mPopup.dismiss();
    });
    mPopup.setAnchorView(this);
    mPopup.setVerticalOffset(-ScreenUtils.dpToPx(5));
    mPopup.setHorizontalOffset(ScreenUtils.dpToPx(4));
    mPopup.setWidth(getResources().getDisplayMetrics().widthPixels - ScreenUtils.dpToPx(16));
    mPopup.setModal(true);

    setSelection(0);
}
 
Example #7
Source File: MessageFormatSettingsActivity.java    From revolution-irc with GNU General Public License v3.0 5 votes vote down vote up
private void selectPreset(EditText editText, CharSequence[] presets) {
    ListPopupWindow menu = new ListPopupWindow(editText.getContext());
    menu.setAnchorView(editText);
    menu.setAdapter(new ArrayAdapter<>(this,
            R.layout.activity_message_format_settings_preset, presets));
    menu.setOnItemClickListener((AdapterView<?> parent, View view, int position, long id) -> {
        editText.setText(presets[position]);
        menu.dismiss();
    });
    menu.show();
}
 
Example #8
Source File: TransportOptionsPopup.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
public TransportOptionsPopup(@NonNull Context context, @NonNull View anchor, @NonNull SelectedListener listener) {
  super(context);
  this.listener = listener;
  this.adapter  = new TransportOptionsAdapter(context, new LinkedList<TransportOption>());

  setVerticalOffset(context.getResources().getDimensionPixelOffset(R.dimen.transport_selection_popup_yoff));
  setHorizontalOffset(context.getResources().getDimensionPixelOffset(R.dimen.transport_selection_popup_xoff));
  setInputMethodMode(ListPopupWindow.INPUT_METHOD_NOT_NEEDED);
  setModal(true);
  setAnchorView(anchor);
  setAdapter(adapter);
  setContentWidth(context.getResources().getDimensionPixelSize(R.dimen.transport_selection_popup_width));

  setOnItemClickListener(this);
}
 
Example #9
Source File: MaterialAutoCompleteTextView.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
public MaterialAutoCompleteTextView(
    @NonNull Context context, @Nullable AttributeSet attributeSet, int defStyleAttr) {
  super(wrap(context, attributeSet, defStyleAttr, 0), attributeSet, defStyleAttr);
  // Ensure we are using the correctly themed context rather than the context that was passed in.
  context = getContext();

  TypedArray attributes =
      ThemeEnforcement.obtainStyledAttributes(
          context,
          attributeSet,
          R.styleable.MaterialAutoCompleteTextView,
          defStyleAttr,
          R.style.Widget_AppCompat_AutoCompleteTextView);

  // Due to a framework bug, setting android:inputType="none" on xml has no effect. Therefore,
  // we check it here in case the autoCompleteTextView should be non-editable.
  if (attributes.hasValue(R.styleable.MaterialAutoCompleteTextView_android_inputType)) {
    int inputType =
        attributes.getInt(
            R.styleable.MaterialAutoCompleteTextView_android_inputType, InputType.TYPE_NULL);
    if (inputType == InputType.TYPE_NULL) {
      setKeyListener(null);
    }
  }

  accessibilityManager =
      (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);

  modalListPopup = new ListPopupWindow(context);
  modalListPopup.setModal(true);
  modalListPopup.setAnchorView(this);
  modalListPopup.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NOT_NEEDED);
  modalListPopup.setAdapter(getAdapter());
  modalListPopup.setOnItemClickListener(
      new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View selectedView, int position, long id) {
          Object selectedItem =
              position < 0 ? modalListPopup.getSelectedItem() : getAdapter().getItem(position);

          updateText(selectedItem);

          OnItemClickListener userOnitemClickListener = getOnItemClickListener();
          if (userOnitemClickListener != null) {
            if (selectedView == null || position < 0) {
              selectedView = modalListPopup.getSelectedView();
              position = modalListPopup.getSelectedItemPosition();
              id = modalListPopup.getSelectedItemId();
            }
            userOnitemClickListener.onItemClick(
                modalListPopup.getListView(), selectedView, position, id);
          }

          modalListPopup.dismiss();
        }
      });

  attributes.recycle();
}