Search in sources :

Example 41 with PopupMenu

use of android.support.v7.widget.PopupMenu in project MTweaks-KernelAdiutorMOD by morogoku.

the class CardView method refresh.

@Override
protected void refresh() {
    super.refresh();
    if (mTitle != null) {
        if (mTitleText != null) {
            mTitle.setText(mTitleText);
            mTitleParent.setVisibility(View.VISIBLE);
            if (mLayoutParent != null) {
                LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) mLayout.getLayoutParams();
                layoutParams.topMargin = -mLayout.getPaddingLeft();
                mLayout.requestLayout();
                mLayout.setPadding(mLayout.getPaddingLeft(), 0, mLayout.getPaddingRight(), mLayout.getPaddingBottom());
            }
        } else {
            mTitleParent.setVisibility(View.GONE);
        }
    }
    if (mMenuButton != null && mOnMenuListener != null) {
        mMenuButton.setVisibility(View.VISIBLE);
        mPopupMenu = new PopupMenu(mMenuButton.getContext(), mMenuButton);
        mOnMenuListener.onMenuReady(this, mPopupMenu);
    }
    if (mRootView != null && getOnItemClickListener() != null) {
        mRootView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                getOnItemClickListener().onClick(CardView.this);
            }
        });
    }
}
Also used : AppCompatImageView(android.support.v7.widget.AppCompatImageView) TextView(android.widget.TextView) View(android.view.View) LinearLayout(android.widget.LinearLayout) PopupMenu(android.support.v7.widget.PopupMenu)

Example 42 with PopupMenu

use of android.support.v7.widget.PopupMenu in project TamTime by flyingrub.

the class FavoriteStopsFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.view_recycler_load, container, false);
    setHasOptionsMenu(true);
    recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
    LinearLayout linearLayout = (LinearLayout) view.findViewById(R.id.progress);
    linearLayout.setVisibility(View.GONE);
    TextView textView = (TextView) view.findViewById(R.id.empty_view);
    textView.setText(getString(R.string.no_favorite_stop));
    // use this setting to improve performance if you know that changes
    // in content do not change the layout size of the RecyclerView
    recyclerView.setHasFixedSize(false);
    layoutManager = new LinearLayoutManager(getActivity());
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.setBackgroundColor(getResources().getColor(R.color.windowBackgroundCard));
    favoriteStops = new FavoriteStops(getActivity());
    getActivity().setTitle(getString(R.string.all_stops_favs));
    if (favoriteStops.getFavoriteStop().size() == 0) {
        textView.setVisibility(View.VISIBLE);
        recyclerView.setVisibility(View.GONE);
        return view;
    }
    adapter = new FavoriteAdapter(favoriteStops.getFavoriteStop());
    recyclerView.setAdapter(adapter);
    adapter.SetOnItemClickListener(new FavoriteAdapter.OnItemClickListener() {

        @Override
        public void onItemClick(View v, int position) {
            selectitem(position);
        }
    });
    adapter.SetOnMenuClickListener(new FavoriteAdapter.OnMenuClickListener() {

        @Override
        public void onItemClick(View v, final int position) {
            // Creating the instance of PopupMenu
            PopupMenu popup = new PopupMenu(getActivity(), v);
            // Inflating the Popup using xml file
            popup.getMenuInflater().inflate(R.menu.delete_menu, popup.getMenu());
            // registering popup with OnMenuItemClickListener
            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    favoriteStops.remove(position);
                    recyclerView.swapAdapter(new FavoriteAdapter(favoriteStops.getFavoriteStop()), false);
                    return true;
                }
            });
            // showing popup menu
            popup.show();
        }
    });
    return view;
}
Also used : MenuItem(android.view.MenuItem) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) TextView(android.widget.TextView) FavoriteStops(flying.grub.tamtime.data.persistence.FavoriteStops) FavoriteAdapter(flying.grub.tamtime.adapter.FavoriteAdapter) LinearLayout(android.widget.LinearLayout) PopupMenu(android.support.v7.widget.PopupMenu)

Example 43 with PopupMenu

use of android.support.v7.widget.PopupMenu in project TamTime by flyingrub.

the class HomeFragment method setupFavStopLine.

public void setupFavStopLine() {
    homeAdapter = new HomeAdapter(favoriteStopLine.getFavStopLines(), getActivity(), favHomeView, searchView);
    homeAdapter.SetOnItemClickListener(new HomeAdapter.OnItemClickListener() {

        @Override
        public void onItemClick(View view, final int position) {
            PopupMenu popup = new PopupMenu(getActivity(), view);
            // Inflating the Popup using xml file
            popup.getMenuInflater().inflate(R.menu.remove_from_home, popup.getMenu());
            // registering popup with OnMenuItemClickListener
            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    favoriteStopLine.removeLineStop(position - 1);
                    setupFavStopLine();
                    return true;
                }
            });
            popup.show();
        }
    });
    favStopLinesRecycler.swapAdapter(homeAdapter, false);
}
Also used : HomeAdapter(flying.grub.tamtime.adapter.HomeAdapter) MenuItem(android.view.MenuItem) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) SearchView(flying.grub.tamtime.layout.SearchView) FavHomeView(flying.grub.tamtime.layout.FavHomeView) PopupMenu(android.support.v7.widget.PopupMenu)

Example 44 with PopupMenu

use of android.support.v7.widget.PopupMenu in project Rocket by mozilla-tw.

the class DownloadListAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
    if (viewHolder instanceof DownloadViewHolder) {
        DownloadViewHolder holder = (DownloadViewHolder) viewHolder;
        DownloadInfo downloadInfo = mDownloadInfo.get(position);
        if (!TextUtils.isEmpty(downloadInfo.getFileName())) {
            holder.title.setText(downloadInfo.getFileName());
        } else {
            holder.title.setText(R.string.unknown);
        }
        holder.icon.setImageResource(mappingIcon(downloadInfo));
        String subtitle = "";
        if (DownloadManager.STATUS_SUCCESSFUL == downloadInfo.getStatus()) {
            subtitle = downloadInfo.getSize() + ", " + downloadInfo.getDate();
        } else {
            subtitle = statusConvertStr(downloadInfo.getStatus());
        }
        holder.subtitle.setText(subtitle);
        holder.action.setTag(R.id.status, downloadInfo.getStatus());
        holder.action.setTag(R.id.row_id, downloadInfo.getRowId());
        holder.action.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(final View view) {
                final long rowid = (long) view.getTag(R.id.row_id);
                int status = (int) view.getTag(R.id.status);
                final PopupMenu popupMenu = new PopupMenu(view.getContext(), view);
                popupMenu.getMenuInflater().inflate(R.menu.menu_delete, popupMenu.getMenu());
                popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                    @Override
                    public boolean onMenuItemClick(MenuItem menuItem) {
                        switch(menuItem.getItemId()) {
                            case R.id.remove:
                                removeItem(rowid);
                                TelemetryWrapper.downloadRemoveFile();
                                popupMenu.dismiss();
                                return true;
                            case R.id.delete:
                                delete(view, rowid);
                                TelemetryWrapper.downloadDeleteFile();
                                popupMenu.dismiss();
                                return true;
                            case R.id.cancel:
                                cancel(rowid);
                                popupMenu.dismiss();
                                return true;
                            default:
                                break;
                        }
                        return false;
                    }
                });
                if (DownloadManager.STATUS_RUNNING == status) {
                    popupMenu.getMenu().findItem(R.id.remove).setVisible(false);
                    popupMenu.getMenu().findItem(R.id.delete).setVisible(false);
                    popupMenu.getMenu().findItem(R.id.cancel).setVisible(true);
                } else {
                    popupMenu.getMenu().findItem(R.id.remove).setVisible(true);
                    popupMenu.getMenu().findItem(R.id.delete).setVisible(true);
                    popupMenu.getMenu().findItem(R.id.cancel).setVisible(false);
                }
                popupMenu.show();
                TelemetryWrapper.showFileContextMenu();
            }
        });
        holder.itemView.setTag(downloadInfo);
        holder.itemView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                DownloadInfo download = (DownloadInfo) view.getTag();
                TelemetryWrapper.downloadOpenFile(false);
                if (new File(URI.create(download.getFileUri()).getPath()).exists()) {
                    IntentUtils.intentOpenFile(view.getContext(), download.getFileUri(), download.getMimeType());
                } else {
                    Toast.makeText(mContext, R.string.cannot_find_the_file, Toast.LENGTH_LONG).show();
                }
            }
        });
    } else if (viewHolder instanceof OnOpeningViewHolder) {
        viewHolder.itemView.setVisibility(View.GONE);
    }
}
Also used : DownloadInfo(org.mozilla.focus.download.DownloadInfo) MenuItem(android.view.MenuItem) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) File(java.io.File) PopupMenu(android.widget.PopupMenu)

Example 45 with PopupMenu

use of android.support.v7.widget.PopupMenu in project samourai-wallet-android by Samourai-Wallet.

the class LandingActivity method showPopup.

/**
 * Shows overflow menu manually
 *
 * @param v
 */
public void showPopup(View v) {
    Context wrapper = new ContextThemeWrapper(this, R.style.popMenuStyle);
    PopupMenu popup = new PopupMenu(wrapper, v, Gravity.LEFT);
    MenuInflater inflater = popup.getMenuInflater();
    inflater.inflate(R.menu.landing_activity_menu, popup.getMenu());
    popup.setOnMenuItemClickListener(this);
    popup.show();
}
Also used : Context(android.content.Context) ContextThemeWrapper(android.view.ContextThemeWrapper) MenuInflater(android.view.MenuInflater) PopupMenu(android.support.v7.widget.PopupMenu)

Aggregations

PopupMenu (android.support.v7.widget.PopupMenu)142 MenuItem (android.view.MenuItem)116 View (android.view.View)86 TextView (android.widget.TextView)63 RecyclerView (android.support.v7.widget.RecyclerView)54 ImageView (android.widget.ImageView)40 Intent (android.content.Intent)32 PopupMenu (android.widget.PopupMenu)31 List (java.util.List)27 ArrayList (java.util.ArrayList)26 MenuInflater (android.view.MenuInflater)23 Menu (android.view.Menu)22 Bundle (android.os.Bundle)20 LayoutInflater (android.view.LayoutInflater)20 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)20 Context (android.content.Context)18 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)18 AdapterView (android.widget.AdapterView)17 DialogInterface (android.content.DialogInterface)16 ViewGroup (android.view.ViewGroup)15