Search in sources :

Example 1 with ListPopupWindow

use of android.support.v7.widget.ListPopupWindow in project cw-omnibus by commonsguy.

the class RowController method onTouch.

@Override
public boolean onTouch(View v, MotionEvent event) {
    if ((event.getButtonState() & MotionEvent.BUTTON_SECONDARY) != 0 && event.getAction() == MotionEvent.ACTION_DOWN) {
        adapter.onChecked(position, true, true);
        String[] items = itemView.getContext().getResources().getStringArray(R.array.popup);
        ArrayAdapter<String> adapter = new ArrayAdapter<>(itemView.getContext(), android.R.layout.simple_list_item_1, items);
        final ListPopupWindow popup = new ListPopupWindow(itemView.getContext());
        popup.setAnchorView(itemView);
        popup.setHorizontalOffset((int) event.getX());
        popup.setVerticalOffset((int) event.getY() - itemView.getHeight());
        popup.setAdapter(adapter);
        popup.setWidth(measureContentWidth(itemView.getContext(), adapter));
        popup.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (position == 0) {
                    ((MainActivity) itemView.getContext()).playVideo(videoUri);
                } else {
                    ((MainActivity) itemView.getContext()).showLargeThumbnail(videoUri);
                }
                popup.dismiss();
            }
        });
        popup.show();
        return (true);
    }
    return (false);
}
Also used : ListPopupWindow(android.widget.ListPopupWindow) AdapterView(android.widget.AdapterView) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ArrayAdapter(android.widget.ArrayAdapter)

Example 2 with ListPopupWindow

use of android.support.v7.widget.ListPopupWindow in project WordPress-Android by wordpress-mobile.

the class PostsListAdapter method showPagePopupMenu.

/*
     * user tapped "..." next to a page, show a popup menu of choices
     */
private void showPagePopupMenu(View view, final PostModel page) {
    Context context = view.getContext();
    final ListPopupWindow listPopup = new ListPopupWindow(context);
    listPopup.setAnchorView(view);
    listPopup.setWidth(context.getResources().getDimensionPixelSize(R.dimen.menu_item_width));
    listPopup.setModal(true);
    listPopup.setAdapter(new PageMenuAdapter(context, page));
    listPopup.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            listPopup.dismiss();
            if (mOnPostButtonClickListener != null) {
                int buttonId = (int) id;
                mOnPostButtonClickListener.onPostButtonClicked(buttonId, page);
            }
        }
    });
    listPopup.show();
}
Also used : Context(android.content.Context) ListPopupWindow(android.support.v7.widget.ListPopupWindow) AdapterView(android.widget.AdapterView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) WPNetworkImageView(org.wordpress.android.widgets.WPNetworkImageView) RecyclerView(android.support.v7.widget.RecyclerView)

Example 3 with ListPopupWindow

use of android.support.v7.widget.ListPopupWindow in project AisenWeiBo by wangdan.

the class CardMenuPopupHelper method tryShow.

public final boolean tryShow() {
    mPopup = new ListPopupWindow(mContext, null, mPopupStyleAttr, mPopupStyleRes);
    mPopup.setOnDismissListener(this);
    mPopup.setOnItemClickListener(this);
    mPopup.setAdapter(mAdapter);
    mPopup.setModal(true);
    View anchor = mAnchorView;
    if (anchor != null) {
        final boolean addGlobalListener = mTreeObserver == null;
        // Refresh to latest
        mTreeObserver = anchor.getViewTreeObserver();
        if (addGlobalListener)
            mTreeObserver.addOnGlobalLayoutListener(this);
        mPopup.setAnchorView(anchor);
        if (cardMenuOptions != null) {
            if (cardMenuOptions.dropDownGravity != -1) {
                mPopup.setDropDownGravity(cardMenuOptions.dropDownGravity);
            } else {
                mPopup.setDropDownGravity(mDropDownGravity);
            }
            if (cardMenuOptions.dropDownHorizontalOffset > 0) {
                mPopup.setHorizontalOffset(cardMenuOptions.dropDownHorizontalOffset);
            }
            if (cardMenuOptions.dropDownVerticalOffset > 0) {
                mPopup.setVerticalOffset(cardMenuOptions.dropDownVerticalOffset);
            }
        } else {
            mPopup.setDropDownGravity(mDropDownGravity);
        }
    } else {
        return false;
    }
    if (!mHasContentWidth) {
        mContentWidth = measureContentWidth();
        mHasContentWidth = true;
    }
    mPopup.setContentWidth(mContentWidth);
    mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
    mPopup.show();
    mPopup.getListView().setOnKeyListener(this);
    return true;
}
Also used : ListPopupWindow(android.support.v7.widget.ListPopupWindow) MenuView(android.support.v7.view.menu.MenuView) ListMenuItemView(android.support.v7.view.menu.ListMenuItemView) View(android.view.View) AdapterView(android.widget.AdapterView)

Example 4 with ListPopupWindow

use of android.support.v7.widget.ListPopupWindow in project mapbox-plugins-android by mapbox.

the class LocationLayerModesActivity method showModeListDialog.

private void showModeListDialog() {
    List<String> modes = new ArrayList<>();
    modes.add("Normal");
    modes.add("Compass");
    modes.add("GPS");
    ArrayAdapter<String> profileAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, modes);
    ListPopupWindow listPopup = new ListPopupWindow(this);
    listPopup.setAdapter(profileAdapter);
    listPopup.setAnchorView(locationModeBtn);
    listPopup.setOnItemClickListener((parent, itemView, position, id) -> {
        String selectedMode = modes.get(position);
        locationModeBtn.setText(selectedMode);
        if (selectedMode.contentEquals("Normal")) {
            setRendererMode(RenderMode.NORMAL);
        } else if (selectedMode.contentEquals("Compass")) {
            setRendererMode(RenderMode.COMPASS);
        } else if (selectedMode.contentEquals("GPS")) {
            setRendererMode(RenderMode.GPS);
        }
        listPopup.dismiss();
    });
    listPopup.show();
}
Also used : ListPopupWindow(android.support.v7.widget.ListPopupWindow) ArrayList(java.util.ArrayList) ArrayAdapter(android.widget.ArrayAdapter)

Example 5 with ListPopupWindow

use of android.support.v7.widget.ListPopupWindow in project Osmand by osmandapp.

the class EditFavoriteGroupDialogFragment method createMenuItems.

@Override
public void createMenuItems(Bundle savedInstanceState) {
    final OsmandApplication app = getMyApplication();
    FavouritesDbHelper helper = app.getFavorites();
    Bundle args = getArguments();
    if (args != null) {
        String groupName = args.getString(GROUP_NAME_KEY);
        if (groupName != null) {
            group = helper.getGroup(groupName);
        }
    }
    if (group == null) {
        return;
    }
    items.add(new TitleItem(Algorithms.isEmpty(group.name) ? app.getString(R.string.shared_string_favorites) : group.name));
    BaseBottomSheetItem editNameItem = new SimpleBottomSheetItem.Builder().setIcon(getContentIcon(R.drawable.ic_action_edit_dark)).setTitle(getString(R.string.edit_name)).setLayoutId(R.layout.bottom_sheet_item_simple).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            AlertDialog.Builder b = new AlertDialog.Builder(getContext());
            b.setTitle(R.string.favorite_group_name);
            final EditText nameEditText = new EditText(getContext());
            nameEditText.setText(group.name);
            b.setView(nameEditText);
            b.setNegativeButton(R.string.shared_string_cancel, null);
            b.setPositiveButton(R.string.shared_string_save, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String name = nameEditText.getText().toString();
                    boolean nameChanged = !Algorithms.objectEquals(group.name, name);
                    if (nameChanged) {
                        app.getFavorites().editFavouriteGroup(group, name, group.color, group.visible);
                        updateParentFragment();
                    }
                    dismiss();
                }
            });
            b.show();
        }
    }).create();
    items.add(editNameItem);
    final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
    final View changeColorView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.change_fav_color, null);
    ((ImageView) changeColorView.findViewById(R.id.change_color_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_appearance));
    updateColorView((ImageView) changeColorView.findViewById(R.id.colorImage));
    BaseBottomSheetItem changeColorItem = new BaseBottomSheetItem.Builder().setCustomView(changeColorView).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final ListPopupWindow popup = new ListPopupWindow(getActivity());
            popup.setAnchorView(changeColorView);
            popup.setContentWidth(AndroidUtils.dpToPx(app, 200f));
            popup.setModal(true);
            popup.setDropDownGravity(Gravity.END | Gravity.TOP);
            if (AndroidUiHelper.isOrientationPortrait(getActivity())) {
                popup.setVerticalOffset(AndroidUtils.dpToPx(app, 48f));
            } else {
                popup.setVerticalOffset(AndroidUtils.dpToPx(app, -48f));
            }
            popup.setHorizontalOffset(AndroidUtils.dpToPx(app, -6f));
            final FavoriteColorAdapter colorAdapter = new FavoriteColorAdapter(getActivity());
            popup.setAdapter(colorAdapter);
            popup.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    Integer color = colorAdapter.getItem(position);
                    if (color != null) {
                        if (color != group.color) {
                            app.getFavorites().editFavouriteGroup(group, group.name, color, group.visible);
                            updateParentFragment();
                        }
                    }
                    popup.dismiss();
                    dismiss();
                }
            });
            popup.show();
        }
    }).create();
    items.add(changeColorItem);
    BaseBottomSheetItem showOnMapItem = new BottomSheetItemWithCompoundButton.Builder().setChecked(group.visible).setIcon(getContentIcon(R.drawable.ic_map)).setTitle(getString(R.string.shared_string_show_on_map)).setLayoutId(R.layout.bottom_sheet_item_with_switch).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            boolean visible = !group.visible;
            app.getFavorites().editFavouriteGroup(group, group.name, group.color, visible);
            updateParentFragment();
            dismiss();
        }
    }).create();
    items.add(showOnMapItem);
    if (group.points.size() > 0) {
        items.add(new DividerHalfItem(getContext()));
        final MapMarkersHelper markersHelper = app.getMapMarkersHelper();
        final MapMarkersGroup markersGr = markersHelper.getOrCreateGroup(this.group);
        final boolean synced = markersHelper.isGroupSynced(markersGr.getId());
        BaseBottomSheetItem markersGroupItem = new SimpleBottomSheetItem.Builder().setIcon(getContentIcon(synced ? R.drawable.ic_action_delete_dark : R.drawable.ic_action_flag_dark)).setTitle(getString(synced ? R.string.remove_from_map_markers : R.string.shared_string_add_to_map_markers)).setLayoutId(R.layout.bottom_sheet_item_simple).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                if (synced) {
                    markersHelper.removeMarkersGroup(markersGr);
                } else {
                    markersHelper.addOrEnableGroup(markersGr);
                }
                dismiss();
                MapActivity.launchMapActivityMoveToTop(getActivity());
            }
        }).create();
        items.add(markersGroupItem);
        BaseBottomSheetItem shareItem = new SimpleBottomSheetItem.Builder().setIcon(getContentIcon(R.drawable.ic_action_gshare_dark)).setTitle(getString(R.string.shared_string_share)).setLayoutId(R.layout.bottom_sheet_item_simple).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                FavoritesTreeFragment fragment = getFavoritesTreeFragment();
                if (fragment != null) {
                    fragment.shareFavorites(EditFavoriteGroupDialogFragment.this.group);
                }
                dismiss();
            }
        }).create();
        items.add(shareItem);
    }
}
Also used : BaseBottomSheetItem(net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem) AlertDialog(android.support.v7.app.AlertDialog) SimpleBottomSheetItem(net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem) OsmandApplication(net.osmand.plus.OsmandApplication) DialogInterface(android.content.DialogInterface) TitleItem(net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem) ListPopupWindow(android.support.v7.widget.ListPopupWindow) DividerHalfItem(net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem) MapMarkersGroup(net.osmand.plus.MapMarkersHelper.MapMarkersGroup) ImageView(android.widget.ImageView) EditText(android.widget.EditText) Bundle(android.os.Bundle) FavouritesDbHelper(net.osmand.plus.FavouritesDbHelper) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ContextThemeWrapper(android.view.ContextThemeWrapper) MapMarkersHelper(net.osmand.plus.MapMarkersHelper) AdapterView(android.widget.AdapterView)

Aggregations

ListPopupWindow (android.support.v7.widget.ListPopupWindow)28 View (android.view.View)25 AdapterView (android.widget.AdapterView)25 TextView (android.widget.TextView)19 ImageView (android.widget.ImageView)10 ArrayAdapter (android.widget.ArrayAdapter)8 ArrayList (java.util.ArrayList)8 RecyclerView (android.support.v7.widget.RecyclerView)7 Handler (android.os.Handler)5 AbsListView (android.widget.AbsListView)5 List (java.util.List)5 DialogInterface (android.content.DialogInterface)4 ColorDrawable (android.graphics.drawable.ColorDrawable)4 Button (android.widget.Button)4 ListView (android.widget.ListView)4 SuppressLint (android.annotation.SuppressLint)3 Point (android.graphics.Point)3 Bundle (android.os.Bundle)3 AlertDialog (android.support.v7.app.AlertDialog)3 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)3