Search in sources :

Example 56 with PopupMenu

use of android.widget.PopupMenu in project KISS by Neamar.

the class AppResult method buildPopupMenu.

@Override
protected PopupMenu buildPopupMenu(Context context, final RecordAdapter parent, View parentView) {
    PopupMenu menu = inflatePopupMenu(R.menu.menu_item_app, context, parentView);
    if ((context instanceof MainActivity) && (!((MainActivity) context).isOnSearchView())) {
        menu.getMenu().removeItem(R.id.item_remove);
    }
    try {
        // app installed under /system can't be uninstalled
        boolean isSameProfile = true;
        ApplicationInfo ai;
        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            LauncherApps launcher = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE);
            LauncherActivityInfo info = launcher.getActivityList(this.appPojo.packageName, this.appPojo.userHandle.getRealHandle()).get(0);
            ai = info.getApplicationInfo();
            isSameProfile = this.appPojo.userHandle.isCurrentUser();
        } else {
            ai = context.getPackageManager().getApplicationInfo(this.appPojo.packageName, 0);
        }
        // Need to AND the flags with SYSTEM:
        if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0 && isSameProfile) {
            menu.getMenuInflater().inflate(R.menu.menu_item_app_uninstall, menu.getMenu());
        }
    } catch (NameNotFoundException | IndexOutOfBoundsException e) {
    // should not happen
    }
    //append root menu if available
    if (KissApplication.getRootHandler(context).isRootActivated() && KissApplication.getRootHandler(context).isRootAvailable()) {
        menu.getMenuInflater().inflate(R.menu.menu_item_app_root, menu.getMenu());
    }
    return menu;
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ApplicationInfo(android.content.pm.ApplicationInfo) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) LauncherApps(android.content.pm.LauncherApps) MainActivity(fr.neamar.kiss.MainActivity) PopupMenu(android.widget.PopupMenu)

Example 57 with PopupMenu

use of android.widget.PopupMenu in project KISS by Neamar.

the class Result method getPopupMenu.

/**
     * How to display the popup menu
     *
     * @return a PopupMenu object
     */
public PopupMenu getPopupMenu(final Context context, final RecordAdapter parent, View parentView) {
    PopupMenu menu = buildPopupMenu(context, parent, parentView);
    menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

        public boolean onMenuItemClick(MenuItem item) {
            return popupMenuClickHandler(context, parent, item);
        }
    });
    return menu;
}
Also used : MenuItem(android.view.MenuItem) PopupMenu(android.widget.PopupMenu)

Example 58 with PopupMenu

use of android.widget.PopupMenu in project xabber-android by redsolution.

the class LogFilesAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
    FileViewHolder fileHolder = (FileViewHolder) holder;
    final File file = files[position];
    fileHolder.fileName.setText(file.getName());
    holder.itemView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            PopupMenu popup = new PopupMenu(holder.itemView.getContext(), holder.itemView);
            popup.inflate(R.menu.item_log_file);
            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    switch(item.getItemId()) {
                        case R.id.action_log_file_open:
                            viewFile(file, holder.itemView.getContext());
                            return true;
                        case R.id.action_log_file_send:
                            sendFile(file, holder.itemView.getContext());
                            return true;
                    }
                    return false;
                }
            });
            popup.show();
        }
    });
}
Also used : MenuItem(android.view.MenuItem) File(java.io.File) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) PopupMenu(android.widget.PopupMenu)

Example 59 with PopupMenu

use of android.widget.PopupMenu in project cardslib by gabrielemariotti.

the class CardHeaderView method _buildPopupMenu.

/**
     * Build the menu
     * @return
     */
private PopupMenu _buildPopupMenu() {
    PopupMenu popup = new PopupMenu(getContext(), mImageButtonOverflow);
    if (mCardHeader.getPopupMenu() > CardHeader.NO_POPUP_MENU) {
        MenuInflater inflater = popup.getMenuInflater();
        inflater.inflate(mCardHeader.getPopupMenu(), popup.getMenu());
    }
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            if (mCardHeader.getPopupMenuListener() != null) {
                // This individual card has it unique menu
                mCardHeader.getPopupMenuListener().onMenuItemClick(mCardHeader.getParentCard(), item);
            }
            return false;
        }
    });
    popup.setOnDismissListener(new PopupMenu.OnDismissListener() {

        @Override
        public void onDismiss(PopupMenu menu) {
            if (mImageButtonOverflow != null)
                mImageButtonOverflow.setSelected(false);
        }
    });
    return popup;
}
Also used : MenuInflater(android.view.MenuInflater) MenuItem(android.view.MenuItem) PopupMenu(android.widget.PopupMenu)

Example 60 with PopupMenu

use of android.widget.PopupMenu in project cardslib by gabrielemariotti.

the class HeaderFragment method init_standard_header_with_overflow_button_dynamic_menu.

/**
     * This method builds a standard header with overflow button with a dynamic menu
     */
private void init_standard_header_with_overflow_button_dynamic_menu() {
    //Create a Card
    Card card = new Card(getActivity());
    //Create a CardHeader
    CardHeader header = new CardHeader(getActivity());
    //Set the header title
    header.setTitle(getString(R.string.demo_header_basetitle));
    //Add a popup menu. This method set OverFlow button to visible
    header.setPopupMenu(R.menu.popupmain, new CardHeader.OnClickCardHeaderPopupMenuListener() {

        @Override
        public void onMenuItemClick(BaseCard card, MenuItem item) {
            Toast.makeText(getActivity(), "Click on " + item.getTitle(), Toast.LENGTH_SHORT).show();
        }
    });
    //Add a PopupMenuPrepareListener to add dynamically a menu entry
    //it is optional.
    header.setPopupMenuPrepareListener(new CardHeader.OnPrepareCardHeaderPopupMenuListener() {

        @Override
        public boolean onPreparePopupMenu(BaseCard card, PopupMenu popupMenu) {
            popupMenu.getMenu().add("Dynamic item");
            return true;
        }
    });
    card.addCardHeader(header);
    //Set card in the CardView
    CardView cardView = (CardView) getActivity().findViewById(R.id.carddemo_header_overflow_dynamic);
    cardView.setCard(card);
}
Also used : BaseCard(it.gmariotti.cardslib.library.internal.base.BaseCard) CardHeader(it.gmariotti.cardslib.library.internal.CardHeader) CardView(it.gmariotti.cardslib.library.view.CardView) MenuItem(android.view.MenuItem) BaseCard(it.gmariotti.cardslib.library.internal.base.BaseCard) CustomExpandCard(it.gmariotti.cardslib.demo.cards.CustomExpandCard) CustomHeaderInnerCard(it.gmariotti.cardslib.demo.cards.CustomHeaderInnerCard) Card(it.gmariotti.cardslib.library.internal.Card) PopupMenu(android.widget.PopupMenu)

Aggregations

PopupMenu (android.widget.PopupMenu)99 MenuItem (android.view.MenuItem)60 View (android.view.View)44 TextView (android.widget.TextView)41 ImageView (android.widget.ImageView)30 RecyclerView (android.support.v7.widget.RecyclerView)22 TargetApi (android.annotation.TargetApi)20 SlowTest (io.github.hidroh.materialistic.test.suite.SlowTest)19 Test (org.junit.Test)19 ShadowPopupMenu (org.robolectric.shadows.ShadowPopupMenu)19 RoboMenuItem (org.robolectric.fakes.RoboMenuItem)18 Intent (android.content.Intent)14 Context (android.content.Context)12 DialogAction (com.afollestad.materialdialogs.DialogAction)12 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)12 MenuInflater (android.view.MenuInflater)10 AdapterView (android.widget.AdapterView)10 ListView (android.widget.ListView)10 Menu (android.view.Menu)9 NonNull (android.support.annotation.NonNull)8