Example usage for android.widget PopupMenu getMenuInflater

List of usage examples for android.widget PopupMenu getMenuInflater

Introduction

In this page you can find the example usage for android.widget PopupMenu getMenuInflater.

Prototype

public MenuInflater getMenuInflater() 

Source Link

Usage

From source file:org.hawkular.client.android.fragment.AlertsFragment.java

private void showAlertMenu(final View alertView, final int alertPosition) {
    PopupMenu alertMenu = new PopupMenu(getActivity(), alertView);

    alertMenu.getMenuInflater().inflate(R.menu.popup_alerts, alertMenu.getMenu());

    alertMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override/*www.j  av  a  2 s .  co  m*/
        public boolean onMenuItemClick(MenuItem menuItem) {
            Alert alert = getAlertsAdapter().getItem(alertPosition);

            switch (menuItem.getItemId()) {
            case R.id.menu_resolve:
                BackendClient.of(AlertsFragment.this).resolveAlert(alert, new AlertActionCallback());
                return true;

            case R.id.menu_acknowledge:
                BackendClient.of(AlertsFragment.this).acknowledgeAlert(alert, new AlertActionCallback());
                return true;

            default:
                return false;
            }
        }
    });

    alertMenu.show();
}

From source file:org.videolan.vlc2.gui.video.VideoGridFragment.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void onContextPopupMenu(View anchor, final int position) {
    if (!LibVlcUtil.isHoneycombOrLater()) {
        // Call the "classic" context menu
        anchor.performLongClick();//from w  w  w . ja  va  2  s.c  o  m
        return;
    }

    PopupMenu popupMenu = new PopupMenu(getActivity(), anchor);
    popupMenu.getMenuInflater().inflate(R.menu.video_list, popupMenu.getMenu());
    Media media = mVideoAdapter.getItem(position);
    setContextMenuItems(popupMenu.getMenu(), media);
    popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            return handleContextItemSelected(item, position);
        }
    });
    popupMenu.show();
}

From source file:nodomain.freeyourgadget.gadgetbridge.activities.appmanager.AbstractAppManagerFragment.java

public boolean openPopupMenu(View view, int position) {
    PopupMenu popupMenu = new PopupMenu(getContext(), view);
    popupMenu.getMenuInflater().inflate(R.menu.appmanager_context, popupMenu.getMenu());
    Menu menu = popupMenu.getMenu();
    final GBDeviceApp selectedApp = appList.get(position);

    if (!selectedApp.isInCache()) {
        menu.removeItem(R.id.appmanager_app_reinstall);
        menu.removeItem(R.id.appmanager_app_delete_cache);
    }/*  w  ww. j  a v  a 2  s  . c o m*/
    if (!PebbleProtocol.UUID_PEBBLE_HEALTH.equals(selectedApp.getUUID())) {
        menu.removeItem(R.id.appmanager_health_activate);
        menu.removeItem(R.id.appmanager_health_deactivate);
    }
    if (!PebbleProtocol.UUID_WORKOUT.equals(selectedApp.getUUID())) {
        menu.removeItem(R.id.appmanager_hrm_activate);
        menu.removeItem(R.id.appmanager_hrm_deactivate);
    }
    if (!PebbleProtocol.UUID_WEATHER.equals(selectedApp.getUUID())) {
        menu.removeItem(R.id.appmanager_weather_activate);
        menu.removeItem(R.id.appmanager_weather_deactivate);
        menu.removeItem(R.id.appmanager_weather_install_provider);
    }
    if (selectedApp.getType() == GBDeviceApp.Type.APP_SYSTEM
            || selectedApp.getType() == GBDeviceApp.Type.WATCHFACE_SYSTEM) {
        menu.removeItem(R.id.appmanager_app_delete);
    }
    if (!selectedApp.isConfigurable()) {
        menu.removeItem(R.id.appmanager_app_configure);
    }

    if (PebbleProtocol.UUID_WEATHER.equals(selectedApp.getUUID())) {
        PackageManager pm = getActivity().getPackageManager();
        try {
            pm.getPackageInfo("ru.gelin.android.weather.notification", PackageManager.GET_ACTIVITIES);
            menu.removeItem(R.id.appmanager_weather_install_provider);
        } catch (PackageManager.NameNotFoundException e) {
            menu.removeItem(R.id.appmanager_weather_activate);
            menu.removeItem(R.id.appmanager_weather_deactivate);
        }
    }

    switch (selectedApp.getType()) {
    case WATCHFACE:
    case APP_GENERIC:
    case APP_ACTIVITYTRACKER:
        break;
    default:
        menu.removeItem(R.id.appmanager_app_openinstore);
    }
    //menu.setHeaderTitle(selectedApp.getName());
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            return onContextItemSelected(item, selectedApp);
        }
    });

    view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
    popupMenu.show();
    return true;
}

From source file:com.jwetherell.quick_response_code.EncoderActivity.java

@SuppressLint("NewApi")
public OnClickListener onclickPopUpMenu(MenuItem item) {
    //Creating the instance of PopupMenu
    PopupMenu popup = new PopupMenu(EncoderActivity.this, item.getActionView());
    //Inflating the Popup using xml file
    popup.getMenuInflater().inflate(R.menu.menu_contextual_wps, popup.getMenu());

    //registering popup with OnMenuItemClickListener
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            Toast.makeText(EncoderActivity.this, "You Clicked : " + item.getTitle(), Toast.LENGTH_SHORT).show();
            return true;
        }// w  w w  .  j  ava2 s .c  o m
    });

    popup.show(); //showing popup menu
    return null;

}

From source file:com.giltesa.taskcalendar.activity.Main.java

/**
 * Desde el metodo onOptionsItemSelected(), se tratan los eventos que produzcan los diferentes Items de los Menus.
 * Se tratan tanto los eventos del menu del boton fisico como los producidos por el boton del ActionBar.
 *//*from  w  w w .  ja v  a 2s.  com*/
@SuppressLint("NewApi")
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    //   Se trata el evento del boton Menu, y de sus SubMenus metidos en un PopupMenu:
    case R.id.main_actionbar_menu:
        PopupMenu popup = new PopupMenu(this, findViewById(R.id.main_actionbar_menu));
        MenuInflater inflater = popup.getMenuInflater();
        inflater.inflate(R.menu.main_menu, popup.getMenu());

        popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            public boolean onMenuItemClick(MenuItem item) {
                switch (item.getItemId()) {
                case R.id.main_menu_newtask:
                    // Se crea un Intent y un Bundle con la informacion a enviar al nuevo Activity:
                    Intent intent = new Intent(context, NewTask.class);
                    Bundle bundle = new Bundle();
                    bundle.putBoolean("isNewTask", true);
                    bundle.putInt("positionSlider", mViewPager.getCurrentItem());
                    intent.putExtra("dataActivity", bundle);
                    startActivityForResult(intent, Main.NEWTASK);
                    return true;

                case R.id.main_menu_settings:
                    startActivity(new Intent(Main.this, Settings.class));
                    return true;

                case R.id.main_menu_exit:
                    finish();
                    return true;

                default:
                    return false;
                }
            }
        });
        popup.show();
        return true;

    case R.id.main_actionbar_search:
        return true;

    case R.id.main_menu_newtask:
        // Se crea un Intent y un Bundle con la informacion a enviar al nuevo Activity:
        Intent intent = new Intent(context, NewTask.class);
        Bundle bundle = new Bundle();
        bundle.putBoolean("isNewTask", true);
        bundle.putInt("positionSlider", mViewPager.getCurrentItem());
        intent.putExtra("dataActivity", bundle);
        startActivityForResult(intent, Main.NEWTASK);
        return true;

    case R.id.main_menu_settings:
        startActivity(new Intent(Main.this, Settings.class));
        return true;

    case R.id.main_menu_exit:
        finish();
        return true;

    default:
        return false;
    }
}

From source file:com.maskyn.fileeditorpro.activity.SelectFileActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    currentFolder = PreferenceHelper.defaultFolder(this);

    ThemeUtils.setTheme(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_select_file);

    Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
    setSupportActionBar(toolbar);/*from   w ww.ja  v  a 2 s  .co  m*/

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    //final Actions action = (Actions) getIntent().getExtras().getSerializable("action");
    wantAFile = true; //action == Actions.SelectFile;
    mfabOkMode = false;
    folderOpenMode = getIntent().getBooleanExtra("foldermode", false);
    if (folderOpenMode)
        setTitle("Open Folder");

    listView = (ListView) findViewById(android.R.id.list);
    listView.setOnItemClickListener(this);
    listView.setTextFilterEnabled(true);

    mFab = (FloatingActionButton) findViewById(R.id.fabbutton);
    mFab.setColor(getResources().getColor(R.color.fab_light));
    mFab.setDrawable(getResources().getDrawable(R.drawable.ic_fab_add));

    mFab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!mfabOkMode) {
                PopupMenu popup = new PopupMenu(SelectFileActivity.this, v);

                popup.getMenuInflater().inflate(R.menu.popup_new_file, popup.getMenu());

                popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        int i = item.getItemId();
                        if (i == R.id.im_new_file) {
                            EditTextDialog.newInstance(EditTextDialog.Actions.NewFile)
                                    .show(getFragmentManager().beginTransaction(), "dialog");
                            return true;
                        } else if (i == R.id.im_new_folder) {
                            EditTextDialog.newInstance(EditTextDialog.Actions.NewFolder)
                                    .show(getFragmentManager().beginTransaction(), "dialog");
                            return true;
                        } else {
                            return false;
                        }
                    }
                });

                popup.show();
            }
            if (mfabOkMode) {
                finishWithResult(selectedFile);
            }
        }
    });

    mFab.listenTo(listView);

    String lastNavigatedPath = PreferenceHelper.getWorkingFolder(this);

    File file = new File(lastNavigatedPath);

    if (!file.exists()) {
        PreferenceHelper.setWorkingFolder(this, PreferenceHelper.defaultFolder(this));
        file = new File(PreferenceHelper.defaultFolder(this));
    }

    new UpdateList().execute(file.getAbsolutePath());
}

From source file:net.nakama.duckdroid.ui.Duckdroid.java

public void btnshowPopupBang(View view) {

    PopupMenu p = new PopupMenu(this, view);
    MenuInflater inflater = p.getMenuInflater();
    p.setOnMenuItemClickListener(bangListener);

    inflater.inflate(this.prefBangMenuId, p.getMenu());
    p.show();//from w  w  w.j a va  2s .c o  m

}

From source file:net.nakama.duckdroid.ui.Duckdroid.java

public void btnshowPopupSetting(View view) {
    PopupMenu popup = new PopupMenu(this, view);
    MenuInflater inflater = popup.getMenuInflater();
    popup.setOnMenuItemClickListener(this);
    inflater.inflate(R.menu.activity_duckdroid, popup.getMenu());
    popup.show();/*from   w w  w  .ja v  a 2  s. c o  m*/
}

From source file:de.uni_weimar.mheinz.androidtouchscope.display.HandleView.java

private PopupMenu createPopupMenu(View view, int menuId) {
    int[] pos = new int[2];
    view.getLocationOnScreen(pos);/*from   w ww.j  a v  a  2s.  c  o m*/
    View moveView = ((HostView) getParent()).getMovableView();
    moveView.layout(pos[0], pos[1], pos[0] + 10, pos[1] + 10);

    PopupMenu popup = new PopupMenu(getContext(), moveView);
    MenuInflater inflater = popup.getMenuInflater();
    inflater.inflate(menuId, popup.getMenu());
    return popup;
}

From source file:edu.usf.cutr.opentripplanner.android.fragments.DirectionListFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    ImageButton btnDisplayMap = (ImageButton) header.findViewById(R.id.btnDisplayMap);
    ImageButton btnShareDirections = (ImageButton) header.findViewById(R.id.btnShareDirections);
    ImageButton btnAlarmDirections = (ImageButton) header.findViewById(R.id.btnAlarmDirections);
    final OtpFragment ofl = this.getFragmentListener();
    final DirectionListFragment dlf = this;
    OnClickListener oclDisplayDirection = new OnClickListener() {
        @Override/* w w  w. jav a2 s .c o  m*/
        public void onClick(View arg0) {
            ofl.onSwitchedToMainFragment(dlf);
        }
    };
    btnDisplayMap.setOnClickListener(oclDisplayDirection);
    btnShareDirections.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {

            // create popup menu
            View menuItemView = getView().findViewById(R.id.btnShareDirections);
            PopupMenu popup = new PopupMenu(getActivity(), menuItemView);
            popup.getMenuInflater().inflate(R.menu.share_menu, popup.getMenu());
            menuItemView.setOnTouchListener(PopupMenuCompat.getDragToOpenListener(popup));

            //registering popup with OnMenuItemClickListener
            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                public boolean onMenuItemClick(MenuItem item) {

                    Intent itn = new Intent();
                    itn.setAction(Intent.ACTION_SEND);
                    itn.setType("text/plain");

                    // fill intend content based on chosen menu item
                    switch (item.getItemId()) {
                    case R.id.btnShareDirectionsShort:
                        itn.putExtra(Intent.EXTRA_TEXT, getDepartureArrivalHeaders(false));
                        break;
                    case R.id.btnShareDirectionsDetailed:
                        itn.putExtra(Intent.EXTRA_TEXT, getDepartureArrivalHeaders(true));
                        break;
                    default:
                        break;
                    }
                    startActivity(Intent.createChooser(itn, "Share via"));
                    return true;
                }
            });

            popup.show();
        }
    });
    btnAlarmDirections.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {

            // create popup menu
            View menuItemView = getView().findViewById(R.id.btnAlarmDirections);
            PopupMenu popup = new PopupMenu(getActivity(), menuItemView);
            popup.getMenuInflater().inflate(R.menu.alarm_menu, popup.getMenu());
            menuItemView.setOnTouchListener(PopupMenuCompat.getDragToOpenListener(popup));

            //registering popup with OnMenuItemClickListener
            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                public boolean onMenuItemClick(MenuItem item) {

                    switch (item.getItemId()) {
                    case R.id.btnAlarmDirectionsAlarm:
                        setAlarmItinerary();
                        break;
                    case R.id.btnAlarmDirectionsNotifications:
                        setNotificationsItinerary();
                        break;
                    case R.id.btnAlarmDirectionsCalendar:
                        setCalendarItinerary();
                        break;
                    default:
                        break;
                    }
                    return true;
                }
            });

            popup.show();
        }
    });

    fromHeader = (TextView) header.findViewById(R.id.fromHeader);
    toHeader = (TextView) header.findViewById(R.id.toHeader);
    departureTimeHeader = (TextView) header.findViewById(R.id.departureTimeHeader);
    arrivalTimeHeader = (TextView) header.findViewById(R.id.arrivalTimeHeader);
    tripList = (Spinner) header.findViewById(R.id.itinerarySelection);

    if (savedInstanceState != null) {
        otpBundle = (OTPBundle) savedInstanceState.getSerializable(OTPApp.BUNDLE_KEY_OTP_BUNDLE);
        fragmentListener.setOTPBundle(otpBundle);
    } else {
        otpBundle = fragmentListener.getOTPBundle();
    }

    fromHeader.setText(otpBundle.getFromText());
    toHeader.setText(otpBundle.getToText());
    setDepartureArrivalHeaders();

    ArrayList<Leg> currentItinerary = new ArrayList<Leg>();
    currentItinerary.addAll(fragmentListener.getCurrentItinerary());
    ArrayList<Itinerary> itineraryList = new ArrayList<Itinerary>();
    itineraryList.addAll(fragmentListener.getCurrentItineraryList());
    int currentItineraryIndex = fragmentListener.getCurrentItineraryIndex();

    ArrayList<Direction> directions = new ArrayList<Direction>();
    DirectionsGenerator dirGen = new DirectionsGenerator(currentItinerary,
            getActivity().getApplicationContext());
    ArrayList<Direction> tempDirections = dirGen.getDirections();
    if (tempDirections != null && !tempDirections.isEmpty()) {
        directions.addAll(tempDirections);
    }

    final Activity activity = this.getActivity();
    String[] itinerarySummaryList = new String[itineraryList.size()];

    boolean isTransitIsTagSet = false;
    for (int i = 0; i < itinerarySummaryList.length; i++) {
        isTransitIsTagSet = false;
        Itinerary it = itineraryList.get(i);
        for (Leg leg : it.legs) {
            TraverseMode traverseMode = TraverseMode.valueOf(leg.mode);
            if (traverseMode.isTransit()) {
                itinerarySummaryList[i] = ConversionUtils.getRouteShortNameSafe(leg.routeShortName,
                        leg.routeLongName, getActivity().getApplicationContext()) + ". ";
                isTransitIsTagSet = true;
                break;
            }
        }
        if (!isTransitIsTagSet) {
            itinerarySummaryList[i] = Integer.toString(i + 1) + ".   ";//Shown index is i + 1, to use 1-based indexes for the UI instead of 0-based
        }
    }

    for (int i = 0; i < itinerarySummaryList.length; i++) {
        Itinerary it = itineraryList.get(i);
        long tripDuration;
        if (PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext())
                .getInt(OTPApp.PREFERENCE_KEY_API_VERSION, OTPApp.API_VERSION_V1) == OTPApp.API_VERSION_V1) {
            tripDuration = it.duration;
        } else {
            tripDuration = it.duration / 1000;
        }
        itinerarySummaryList[i] += getString(R.string.step_by_step_total_duration) + " " + ConversionUtils
                .getFormattedDurationTextNoSeconds(tripDuration, false, getActivity().getApplicationContext());
        if (isTransitIsTagSet) {
            itinerarySummaryList[i] += "   " + getString(R.string.step_by_step_walking_duration) + " "
                    + ConversionUtils.getFormattedDurationTextNoSeconds(it.walkTime, false,
                            getActivity().getApplicationContext());
        }
    }

    ArrayAdapter<String> itineraryAdapter = new ArrayAdapter<String>(activity,
            android.R.layout.simple_spinner_item, itinerarySummaryList);

    itineraryAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    tripList.setAdapter(itineraryAdapter);

    AdapterView.OnItemSelectedListener itinerarySpinnerListener = new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (fragmentListener.getCurrentItineraryIndex() != position) {
                fragmentListener.onItinerarySelected(position, 3);
            }

            setDepartureArrivalHeaders();

            if (!isFragmentFirstLoad) {
                ArrayList<Direction> directions = new ArrayList<Direction>();
                DirectionsGenerator dirGen = new DirectionsGenerator(fragmentListener.getCurrentItinerary(),
                        getActivity().getApplicationContext());
                ArrayList<Direction> tempDirections = dirGen.getDirections();
                if (tempDirections != null && !tempDirections.isEmpty()) {
                    directions.addAll(tempDirections);
                }

                Direction direction_data[] = directions.toArray(new Direction[directions.size()]);

                DirectionExpandableListAdapter adapter = new DirectionExpandableListAdapter(
                        DirectionListFragment.this.getActivity(), R.layout.list_direction_item,
                        R.layout.list_subdirection_item, direction_data);

                elv.setAdapter(adapter);

            }
            openIfNonTransit();

            isFragmentFirstLoad = false;

        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    };
    tripList.setSelection(currentItineraryIndex);
    tripList.setOnItemSelectedListener(itinerarySpinnerListener);

    // Populate list with our static array of titles.
    elv = getExpandableListView();

    Direction direction_data[] = directions.toArray(new Direction[directions.size()]);

    DirectionExpandableListAdapter adapter = new DirectionExpandableListAdapter(this.getActivity(),
            R.layout.list_direction_item, R.layout.list_subdirection_item, direction_data);

    elv.addHeaderView(header);

    elv.setAdapter(adapter);

    elv.setGroupIndicator(null); // Get rid of the down arrow

    openIfNonTransit();

    if (savedInstanceState == null) {
        if (otpBundle.isFromInfoWindow()) {
            elv.expandGroup(otpBundle.getCurrentStepIndex());
            elv.setSelectedGroup(otpBundle.getCurrentStepIndex());
            otpBundle.setFromInfoWindow(false);
        }
    }
}