Search in sources :

Example 1 with PopupMenu

use of android.widget.PopupMenu in project android_frameworks_base by ParanoidAndroid.

the class RecentsPanelView method handleLongPress.

public void handleLongPress(final View selectedView, final View anchorView, final View thumbnailView) {
    thumbnailView.setSelected(true);
    final PopupMenu popup = new PopupMenu(mContext, anchorView == null ? selectedView : anchorView);
    mPopup = popup;
    popup.getMenuInflater().inflate(R.menu.recent_popup_menu, popup.getMenu());
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

        public boolean onMenuItemClick(MenuItem item) {
            if (item.getItemId() == R.id.recent_remove_item) {
                mRecentsContainer.removeViewInLayout(selectedView);
            } else if (item.getItemId() == R.id.recent_inspect_item) {
                ViewHolder viewHolder = (ViewHolder) selectedView.getTag();
                if (viewHolder != null) {
                    final TaskDescription ad = viewHolder.taskDescription;
                    startApplicationDetailsActivity(ad.packageName);
                    show(false);
                } else {
                    throw new IllegalStateException("Oops, no tag on view " + selectedView);
                }
            } else if (item.getItemId() == R.id.recent_launch_floating) {
                ViewHolder viewHolder = (ViewHolder) selectedView.getTag();
                if (viewHolder != null) {
                    final TaskDescription ad = viewHolder.taskDescription;
                    dismissAndGoBack();
                    Intent intent = ad.intent;
                    intent.addFlags(Intent.FLAG_FLOATING_WINDOW | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                    intent.setFlags(intent.getFlags() & ~Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);
                    getContext().startActivity(intent);
                }
            } else {
                return false;
            }
            return true;
        }
    });
    popup.setOnDismissListener(new PopupMenu.OnDismissListener() {

        public void onDismiss(PopupMenu menu) {
            thumbnailView.setSelected(false);
            mPopup = null;
        }
    });
    popup.show();
}
Also used : MenuItem(android.view.MenuItem) Intent(android.content.Intent) PopupMenu(android.widget.PopupMenu)

Example 2 with PopupMenu

use of android.widget.PopupMenu in project meatspace-android by RomainPiel.

the class ChatItemView method onViewChanged.

@Override
public void onViewChanged() {
    ButterKnife.inject(this);
    popupMenu = new PopupMenu(getContext(), menuButton);
    popupMenu.inflate(R.menu.card);
    menuButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            popupMenu.show();
        }
    });
}
Also used : ImageView(android.widget.ImageView) InjectView(butterknife.InjectView) TextView(android.widget.TextView) View(android.view.View) PopupMenu(android.widget.PopupMenu)

Example 3 with PopupMenu

use of android.widget.PopupMenu in project NewPipe by TeamNewPipe.

the class MissionAdapter method buildPopup.

private void buildPopup(final ViewHolder h) {
    PopupMenu popup = new PopupMenu(mContext, h.menu);
    popup.inflate(R.menu.mission);
    Menu menu = popup.getMenu();
    MenuItem start = menu.findItem(R.id.start);
    MenuItem pause = menu.findItem(R.id.pause);
    MenuItem view = menu.findItem(R.id.view);
    MenuItem delete = menu.findItem(R.id.delete);
    MenuItem checksum = menu.findItem(R.id.checksum);
    // Set to false first
    start.setVisible(false);
    pause.setVisible(false);
    view.setVisible(false);
    delete.setVisible(false);
    checksum.setVisible(false);
    if (!h.mission.finished) {
        if (!h.mission.running) {
            if (h.mission.errCode == -1) {
                start.setVisible(true);
            }
            delete.setVisible(true);
        } else {
            pause.setVisible(true);
        }
    } else {
        view.setVisible(true);
        delete.setVisible(true);
        checksum.setVisible(true);
    }
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            int id = item.getItemId();
            switch(id) {
                case R.id.start:
                    mManager.resumeMission(h.position);
                    mBinder.onMissionAdded(mManager.getMission(h.position));
                    return true;
                case R.id.pause:
                    mManager.pauseMission(h.position);
                    mBinder.onMissionRemoved(mManager.getMission(h.position));
                    h.lastTimeStamp = -1;
                    h.lastDone = -1;
                    return true;
                case R.id.view:
                    File f = new File(h.mission.location, h.mission.name);
                    String ext = Utility.getFileExt(h.mission.name);
                    Log.d(TAG, "Viewing file: " + f.getAbsolutePath() + " ext: " + ext);
                    if (ext == null) {
                        Log.w(TAG, "Can't view file because it has no extension: " + h.mission.name);
                        return false;
                    }
                    String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext.substring(1));
                    Log.v(TAG, "Mime: " + mime + " package: " + mContext.getApplicationContext().getPackageName() + ".provider");
                    if (f.exists()) {
                        viewFileWithFileProvider(f, mime);
                    } else {
                        Log.w(TAG, "File doesn't exist");
                    }
                    return true;
                case R.id.delete:
                    mManager.deleteMission(h.position);
                    notifyDataSetChanged();
                    return true;
                case R.id.md5:
                case R.id.sha1:
                    DownloadMission mission = mManager.getMission(h.position);
                    new ChecksumTask().execute(mission.location + "/" + mission.name, ALGORITHMS.get(id));
                    return true;
                default:
                    return false;
            }
        }
    });
    popup.show();
}
Also used : DownloadMission(us.shandian.giga.get.DownloadMission) MenuItem(android.view.MenuItem) PopupMenu(android.widget.PopupMenu) Menu(android.view.Menu) File(java.io.File) PopupMenu(android.widget.PopupMenu)

Example 4 with PopupMenu

use of android.widget.PopupMenu in project SeriesGuide by UweTrottmann.

the class ExtensionsAdapter method getView.

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    if (getItemViewType(position) == VIEW_TYPE_ADD) {
        if (convertView == null) {
            convertView = mLayoutInflater.inflate(LAYOUT_ADD, parent, false);
        }
        // warn non-supporters that they only can add a few extensions
        boolean isAtLimit = getCount() - 1 == ExtensionsConfigurationFragment.EXTENSION_LIMIT_FREE && !Utils.hasAccessToX(getContext());
        convertView.findViewById(R.id.textViewItemExtensionAddLabel).setVisibility(isAtLimit ? View.GONE : View.VISIBLE);
        convertView.findViewById(R.id.textViewItemExtensionAddLimit).setVisibility(isAtLimit ? View.VISIBLE : View.GONE);
        return convertView;
    }
    ViewHolder viewHolder;
    if (convertView == null) {
        convertView = mLayoutInflater.inflate(LAYOUT_EXTENSION, parent, false);
        viewHolder = new ViewHolder(convertView);
        convertView.setTag(viewHolder);
    } else {
        viewHolder = (ViewHolder) convertView.getTag();
    }
    final ExtensionManager.Extension extension = getItem(position);
    viewHolder.description.setText(extension.description);
    // title
    viewHolder.title.setText(extension.label);
    // icon
    if (extension.icon != null) {
        viewHolder.icon.setImageDrawable(extension.icon);
    } else {
        viewHolder.icon.setImageResource(R.drawable.ic_launcher);
    }
    // overflow menu
    viewHolder.settings.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
            popupMenu.getMenuInflater().inflate(R.menu.extension_menu, popupMenu.getMenu());
            if (extension.settingsActivity == null) {
                MenuItem item = popupMenu.getMenu().findItem(R.id.menu_action_extension_settings);
                item.setVisible(false);
                item.setEnabled(false);
            }
            popupMenu.setOnMenuItemClickListener(new OverflowItemClickListener(position));
            popupMenu.show();
        }
    });
    return convertView;
}
Also used : ExtensionManager(com.battlelancer.seriesguide.extensions.ExtensionManager) MenuItem(android.view.MenuItem) ImageView(android.widget.ImageView) BindView(butterknife.BindView) TextView(android.widget.TextView) View(android.view.View) PopupMenu(android.widget.PopupMenu)

Example 5 with PopupMenu

use of android.widget.PopupMenu in project SeriesGuide by UweTrottmann.

the class MoviesWatchListFragment method onPopupMenuClick.

@Override
public void onPopupMenuClick(View v, final int movieTmdbId) {
    PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
    popupMenu.getMenu().add(0, CONTEXT_WATCHLIST_REMOVE_ID, 0, R.string.watchlist_remove);
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch(item.getItemId()) {
                case CONTEXT_WATCHLIST_REMOVE_ID:
                    {
                        MovieTools.removeFromWatchlist(SgApp.from(getActivity()), movieTmdbId);
                        return true;
                    }
            }
            return false;
        }
    });
    popupMenu.show();
}
Also used : MenuItem(android.view.MenuItem) PopupMenu(android.widget.PopupMenu)

Aggregations

PopupMenu (android.widget.PopupMenu)88 MenuItem (android.view.MenuItem)52 View (android.view.View)38 TextView (android.widget.TextView)35 ImageView (android.widget.ImageView)29 RecyclerView (android.support.v7.widget.RecyclerView)21 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 Context (android.content.Context)12 DialogAction (com.afollestad.materialdialogs.DialogAction)12 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)12 Intent (android.content.Intent)11 NonNull (android.support.annotation.NonNull)8 Menu (android.view.Menu)7 AdapterView (android.widget.AdapterView)6 ListView (android.widget.ListView)6 Song (io.hefuyi.listener.mvp.model.Song)6