Example usage for android.view MenuItem setOnMenuItemClickListener

List of usage examples for android.view MenuItem setOnMenuItemClickListener

Introduction

In this page you can find the example usage for android.view MenuItem setOnMenuItemClickListener.

Prototype

public MenuItem setOnMenuItemClickListener(MenuItem.OnMenuItemClickListener menuItemClickListener);

Source Link

Document

Set a custom listener for invocation of this menu item.

Usage

From source file:io.syng.fragment.profile.ProfileDialogFragment.java

@Nullable
@Override/*from www  . ja  v a2 s  .co  m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.profile_edit_dialog, container);
    TabLayout tabLayout = (TabLayout) view.findViewById(R.id.profile_tabs);
    mViewPager = (ViewPager) view.findViewById(R.id.profile_view_pager);

    mViewPager.addOnPageChangeListener(this);
    mToolbar = (Toolbar) view.findViewById(R.id.profile_toolbar);
    mToolbar.setTitle("Edit Profile");
    mToolbar.inflateMenu(R.menu.profile_menu);

    MenuItem exportProfile = mToolbar.getMenu().findItem(R.id.action_key_export);
    exportProfile.setVisible(false);
    exportProfile.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            return false;
        }
    });
    MenuItem importProfile = mToolbar.getMenu().findItem(R.id.action_key_import);
    importProfile.setVisible(false);
    importProfile.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            GeneralUtil.showProfileImportDialog(getActivity());
            return false;
        }
    });

    mToolbar.setNavigationIcon(R.drawable.ic_arrow_back_black_24dp);
    mToolbar.setNavigationOnClickListener(this);
    mToolbar.setOnMenuItemClickListener(this);
    tintMenuItem();

    mViewPager.setAdapter(new ProfileViewPagerAdapter(getChildFragmentManager(), getActivity(), mProfileId));
    tabLayout.setupWithViewPager(mViewPager);

    return view;
}

From source file:org.kiwix.kiwixmobile.views.KiwixWebView.java

@Override
protected void onCreateContextMenu(ContextMenu menu) {
    super.onCreateContextMenu(menu);
    final HitTestResult result = getHitTestResult();
    if (result.getType() == HitTestResult.IMAGE_ANCHOR_TYPE || result.getType() == HitTestResult.IMAGE_TYPE
            || result.getType() == HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
        MenuItem saveMenu = menu.add(0, 1, 0, getResources().getString(R.string.save_media));
        saveMenu.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            public boolean onMenuItemClick(MenuItem item) {
                Message msg = saveHandler.obtainMessage();
                requestFocusNodeHref(msg);
                return true;
            }/*from w  w  w .jav a 2 s .  c  om*/
        });
    }
}

From source file:com.github.akinaru.roboticbuttonpusher.activity.BaseActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    this.getMenuInflater().inflate(R.menu.toolbar_menu, menu);

    //clear button
    MenuItem item = menu.findItem(R.id.clear_btn);
    if (item != null) {
        item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

            @Override//from   w w w  .ja v  a  2s  . c  om
            public boolean onMenuItemClick(MenuItem item) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        debugTv.setText("");
                    }
                });
                return true;
            }
        });
    }

    return super.onCreateOptionsMenu(menu);
}

From source file:de.damdi.fitness.activity.manage_workouts.WorkoutDetailFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.workout_detail_menu, menu);

    // configure menu_item_rename_workout
    MenuItem menu_item_rename_workout = (MenuItem) menu.findItem(R.id.menu_item_rename_workout);
    menu_item_rename_workout.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {

            FragmentTransaction ft = getFragmentManager().beginTransaction();
            Fragment prev = getFragmentManager().findFragmentByTag("dialog");
            if (prev != null) {
                ft.remove(prev);/*from w  ww. j  a v  a  2 s .  c om*/
            }
            ft.addToBackStack(null);

            // Create and show the dialog.
            DialogFragment newFragment = RenameWorkoutDialogFragment.newInstance(mWorkout);
            newFragment.show(ft, "dialog");

            return true;
        }
    });

    // configure menu_item_delete_workout
    MenuItem menu_item_delete_workout = (MenuItem) menu.findItem(R.id.menu_item_delete_workout);
    menu_item_delete_workout.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

            builder.setTitle(getString(R.string.really_delete));
            builder.setMessage(getString(R.string.really_delete_long));

            builder.setPositiveButton(getString(R.string.delete_workout), new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int wich) {
                    IDataProvider dataProvider = new DataProvider(getActivity());
                    dataProvider.deleteWorkout(mWorkout);

                    if (getActivity() instanceof WorkoutDetailActivity) {
                        // request WorkoutListActivity to
                        // finish too
                        Intent i = new Intent();
                        getActivity().setResult(WorkoutListActivity.REQUEST_EXIT, i);
                    }

                    // finish WorkoutListActivity
                    getActivity().finish();

                    startActivity(new Intent(getActivity(), WorkoutListActivity.class));

                }
            });
            builder.setNegativeButton(getString(R.string.cancel), new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int wich) {
                    dialog.dismiss();
                }
            });

            builder.create().show();

            return true;
        }
    });

    // configure menu_item_edit_workout
    MenuItem menu_item_edit_workout = (MenuItem) menu.findItem(R.id.menu_item_edit_workout);
    menu_item_edit_workout.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {

            Intent editItent = new Intent(getActivity(), ExerciseTypeListActivity.class);
            editItent.putExtra(ExerciseTypeListActivity.ARG_WORKOUT, mWorkout);
            startActivity(editItent);

            // close the manage workout activities
            if (getActivity() instanceof WorkoutDetailActivity)
                getActivity().finishFromChild(getActivity());
            getActivity().finish();

            return true;
        }
    });

}

From source file:com.zzolta.android.gfrecipes.fragments.RecipeDetailFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.menu_detail, menu);

    final MenuItem share = menu.findItem(R.id.action_share);
    RecipeDetailShareActionProvider.getInstance()
            .setShareActionProvider((ShareActionProvider) MenuItemCompat.getActionProvider(share));

    final MenuItem clearSearchHistory = menu.findItem(R.id.action_clear_search_history);
    clearSearchHistory.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override/*ww  w .  j av  a 2 s . co  m*/
        public boolean onMenuItemClick(MenuItem item) {
            new Builder(getActivity()).setTitle(getString(R.string.action_clear_search_history))
                    .setMessage(getString(R.string.confirmation_clear_search_history))
                    .setIcon(drawable.ic_dialog_alert).setPositiveButton(string.yes, new OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            final SearchRecentSuggestions suggestions = new SearchRecentSuggestions(
                                    getActivity(), RecipeSearchRecentSuggestionsProvider.AUTHORITY,
                                    RecipeSearchRecentSuggestionsProvider.MODE);
                            suggestions.clearHistory();
                        }
                    }).setNegativeButton(string.no, null).show();
            return true;
        }
    });

    final MenuItem addToMyRecipes = menu.findItem(R.id.action_add_to_my_recipes);
    addToMyRecipes.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            myRecipeHandler(true);
            return true;
        }
    });

    final MenuItem removeFromMyRecipes = menu.findItem(R.id.action_remove_from_my_recipes);
    removeFromMyRecipes.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            myRecipeHandler(false);
            return true;
        }
    });
}

From source file:org.tunesremote.ArtistsListFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {

    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;

    // create context menu to play entire artist
    try {/*from   w  w w  . j  av a  2s . co m*/
        Response resp = (Response) adapter.getItem(info.position);
        final String artist = resp.getString("mlit");
        menu.setHeaderTitle(artist);

        MenuItem play = menu.add(R.string.artists_menu_play);
        play.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            public boolean onMenuItemClick(MenuItem item) {
                host.session.controlPlayArtist(artist, 0);
                host.setResult(Activity.RESULT_OK, new Intent());
                host.finish();
                return true;
            }
        });

        MenuItem queue = menu.add(R.string.artists_menu_queue);
        queue.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            public boolean onMenuItemClick(MenuItem item) {
                host.session.controlQueueArtist(artist);
                host.setResult(Activity.RESULT_OK, new Intent());
                host.finish();
                return true;
            }
        });

        MenuItem browse = menu.add(R.string.artists_menu_browse);
        browse.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            public boolean onMenuItemClick(MenuItem item) {
                Intent intent = new Intent(host, AlbumsActivity.class);
                intent.putExtra(Intent.EXTRA_TITLE, artist);
                host.startActivityForResult(intent, 1);
                return true;
            }
        });
    } catch (Exception e) {
        Log.w(TAG, "onCreateContextMenu:" + e.getMessage());
    }

}

From source file:com.koushikdutta.superuser.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater mi = new MenuInflater(this);
    mi.inflate(R.menu.app, menu);/* w w w  .j  a  v a  2s .c o  m*/
    MenuItem about = menu.findItem(R.id.about);
    about.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            getSupportFragmentManager().beginTransaction().addToBackStack(getString(R.string.about))
                    .replace(getListContainerId(), new AboutFragment(), "content").commit();
            return true;
        }
    });

    MenuItem settings = menu.findItem(R.id.settings);
    settings.setOnMenuItemClickListener(new OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(final MenuItem item) {
            getSupportFragmentManager().beginTransaction().addToBackStack(getString(R.string.settings))
                    .replace(getListContainerId(), new SettingsFragment(), "content").commit();
            return true;
        }
    });
    return super.onCreateOptionsMenu(menu);
}

From source file:de.skubware.opentraining.activity.create_exercise.ImageFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.create_exercise_image_fragment_menu, menu);

    // configure menu_item_take_photo
    MenuItem menu_item_take_photo = (MenuItem) menu.findItem(R.id.menu_item_take_photo);
    menu_item_take_photo.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            dispatchTakePictureIntent();
            return true;
        }/*from  w  w  w. j a v a 2  s.c o m*/
    });

    // configure menu_item_chose_photo
    MenuItem menu_item_chose_photo = (MenuItem) menu.findItem(R.id.menu_item_chose_photo);
    menu_item_chose_photo.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
            photoPickerIntent.setType("image/*");
            startActivityForResult(photoPickerIntent, CreateExerciseActivity.CHOSE_PICTURE);
            return true;
        }
    });
}

From source file:org.deviceconnect.android.deviceplugin.irkit.settings.fragment.IRKitRegisterIRFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    final MenuItem menuItem = menu.add(getString(R.string.menu_close));
    menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override//from ww w.  j  av a  2s.co  m
        public boolean onMenuItemClick(final MenuItem item) {
            if (item.getTitle().equals(menuItem.getTitle())) {
                getActivity().finish();
            }
            return true;
        }
    });
}

From source file:com.github.akinaru.bleremote.activity.BaseActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    this.getMenuInflater().inflate(R.menu.toolbar_menu, menu);

    //clear button
    MenuItem item = menu.findItem(R.id.add_image);
    if (item != null) {
        item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

            @Override/*from   w  w w.ja  v a  2 s  .c o m*/
            public boolean onMenuItemClick(MenuItem item) {
                mExitOnBrowse = true;
                startActivityForResult(MediaStoreUtils.getPickImageIntent(BaseActivity.this), REQUEST_PICTURE);
                return true;
            }
        });
    }

    deleteMenuItem = menu.findItem(R.id.delete_image);

    if (deleteMenuItem != null) {

        deleteMenuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

            @Override
            public boolean onMenuItemClick(MenuItem item) {
                //delete
                for (int i = 0; i < mDeleteBitmapList.size(); i++) {
                    mBitmapList.remove(mDeleteBitmapList.get(i));
                    File file = new File(directory, mDeleteBitmapList.get(i).getFileName());
                    file.delete();
                }
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        mBitmapRecyclerView.setAdapter(mAdapter);
                        mAdapter.notifyDataSetChanged();
                    }
                });

                return true;
            }
        });
    }

    return super.onCreateOptionsMenu(menu);
}