Example usage for android.view MenuItem setVisible

List of usage examples for android.view MenuItem setVisible

Introduction

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

Prototype

public MenuItem setVisible(boolean visible);

Source Link

Document

Sets the visibility of the menu item.

Usage

From source file:com.cypress.cysmart.BLEServiceFragments.CSCService.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.clear();//from   w  w  w . jav a2s . c  o  m
    inflater.inflate(R.menu.global, menu);
    MenuItem graph = menu.findItem(R.id.graph);
    MenuItem log = menu.findItem(R.id.log);
    MenuItem search = menu.findItem(R.id.search);
    search.setVisible(false);
    graph.setVisible(true);
    log.setVisible(true);
    super.onCreateOptionsMenu(menu, inflater);
}

From source file:com.prasanna.android.stacknetwork.QuestionActivity.java

private void setupMenuIfAuthenticatedUser() {
    if (AppUtils.inAuthenticatedRealm(this)) {
        MenuItem favorite = setupFavoriteActionBarIcon();
        favorite.setVisible(true);
        menu.findItem(R.id.menu_refresh).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
        setupAddComment(menu);//from www  . j  a  v  a2  s .co  m
    }
}

From source file:de.skubware.opentraining.activity.create_workout.ExerciseTypeDetailFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {

    // MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.exercise_detail_menu, menu);

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

            // assert, that an exercise was choosen
            if (mExercise == null) {
                Log.wtf(TAG, "No exercise has been choosen. This should not happen");
                return true;
            }/*from w  w  w.  j a  v  a2 s.  c  om*/

            // add exercise to workout or create a new one
            if (mWorkout == null) {
                SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getActivity());
                String defaultWorkoutName = settings.getString("default_workout_name", "Workout");

                mWorkout = new Workout(defaultWorkoutName, new FitnessExercise(mExercise));
            } else {

                // assert that there is not already such an exercise in the
                // workout
                for (FitnessExercise fEx : mWorkout.getFitnessExercises()) {
                    if (fEx.getExType().equals(mExercise)) {
                        Toast.makeText(getActivity(), getString(R.string.exercise_already_in_workout),
                                Toast.LENGTH_LONG).show();
                        return true;
                    }
                }

                mWorkout.addFitnessExercise(new FitnessExercise(mExercise));
            }

            // update Workout in Activity
            if (getActivity() instanceof Callbacks) {
                // was launched by ExerciseTypeListActivity
                ((Callbacks) getActivity()).onWorkoutChanged(mWorkout);
            } else {
                // was launched by ExerciseTypeDetailActivity
                Intent i = new Intent();
                i.putExtra(ExerciseTypeListActivity.ARG_WORKOUT, mWorkout);
                getActivity().setResult(Activity.RESULT_OK, i);
                getActivity().finish();
            }

            Toast.makeText(getActivity(), getString(R.string.exercise) + " " + mExercise.getLocalizedName()
                    + " " + getString(R.string.has_been_added), Toast.LENGTH_SHORT).show();

            return true;
        }
    });

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

            String license = "";

            if (mExercise.getImageLicenseMap().values().iterator().hasNext()) {
                license = mExercise.getImageLicenseMap().values().iterator().next().toString();
            } else {
                license = getString(R.string.no_license_available);
            }

            builder.setMessage(license);
            builder.create().show();

            return true;
        }
    });

    // configure menu_item_description
    MenuItem menu_item_description = (MenuItem) menu.findItem(R.id.menu_item_description);
    menu_item_description.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            if (mExercise.getDescription() == null || mExercise.getDescription().equals("")) {
                Toast.makeText(getActivity(), getString(R.string.no_description_available), Toast.LENGTH_LONG)
                        .show();
                return true;
            }

            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setTitle(getString(R.string.description));

            builder.setMessage(Html.fromHtml(mExercise.getDescription()));
            builder.create().show();

            return true;
        }
    });

    // configure menu_item_delete_exercise
    if (mExercise != null && mExercise.getExerciseSource() == ExerciseSource.CUSTOM) {
        MenuItem menu_item_delete_exercise = (MenuItem) menu.findItem(R.id.menu_item_delete_exercise);
        menu_item_delete_exercise.setVisible(true);
        menu_item_delete_exercise.setOnMenuItemClickListener(new OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                IDataProvider dataProvider = new DataProvider(getActivity());
                dataProvider.deleteCustomExercise(mExercise);

                if (getActivity() instanceof Callbacks) {
                    // was launched by ExerciseTypeListActivity
                    ((Callbacks) getActivity()).onExerciseDeleted(mExercise);
                } else {
                    // was launched by ExerciseTypeDetailActivity
                    Intent i = new Intent();
                    i.putExtra(ARG_DELETED_EXERCISE, mExercise);
                    getActivity().setResult(RESULT_EXERCISE_CHANGED, i);
                    getActivity().finish();
                }

                return false;
            }
        });
    }

    // configure menu_item_upload_exercise
    MenuItem menu_item_upload_exercise = (MenuItem) menu.findItem(R.id.menu_item_upload_exercise);
    menu_item_upload_exercise.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            Context context = ExerciseTypeDetailFragment.this.getActivity();

            //UploadExerciseAsyncTask exUpload = new UploadExerciseAsyncTask(context);
            //exUpload.execute(mExercise);

            UploadExerciseImagesAsyncTask exImageUpload = new UploadExerciseImagesAsyncTask(context);
            exImageUpload.execute(mExercise);

            return true;
        }
    });

    // configure menu_item_send_exercise_feedback
    MenuItem menu_item_delete_exercise = (MenuItem) menu.findItem(R.id.menu_item_send_exercise_feedback);
    menu_item_delete_exercise.setVisible(true);
    menu_item_delete_exercise.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {

            FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
            Fragment prev = getActivity().getSupportFragmentManager().findFragmentByTag("dialog");
            if (prev != null) {
                ft.remove(prev);
            }
            ft.addToBackStack(null);

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

            return false;
        }
    });

}

From source file:org.geometerplus.android.fbreader.network.NetworkLibraryActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);

    final NetworkTree tree = getCurrentTree();
    for (Action a : myOptionsMenuActions) {
        final MenuItem item = menu.findItem(a.Code);
        if (a.isVisible(tree)) {
            item.setVisible(true);
            item.setEnabled(a.isEnabled(tree));
            item.setTitle(a.getOptionsLabel(tree));
        } else {/*w  ww . j a  v  a  2s  .com*/
            item.setVisible(false);
        }
    }
    return true;
}

From source file:com.github.chenxiaolong.dualbootpatcher.MainActivity.java

public void showExit(boolean visible) {
    Menu menu = mDrawerView.getMenu();
    MenuItem item = menu.findItem(R.id.nav_exit);
    if (item != null) {
        item.setVisible(visible);
    }/*from w  w w  .  ja  v  a2s.c  o  m*/
}

From source file:com.github.chenxiaolong.dualbootpatcher.MainActivity.java

public void showReboot(boolean visible) {
    Menu menu = mDrawerView.getMenu();
    MenuItem item = menu.findItem(R.id.nav_reboot);
    if (item != null) {
        item.setVisible(visible);
    }// w  w  w  .j a v  a2s . c  om
}

From source file:com.epishie.tabs.feature.subreddits.SubredditsActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);

    MenuItem sidebar = menu.findItem(R.id.sidebar);
    MenuItem sortGroup = menu.findItem(R.id.sort);
    MenuItem refresh = menu.findItem(R.id.refresh);
    SubredditViewModel subreddit = mAdapter.getSubreddit(mPages.getCurrentItem());
    if (subreddit != null) {
        sortGroup.setVisible(true);
        sortGroup.setVisible(true);/* w  w w .  j a  v  a 2  s  .com*/
        MenuItem sortItem = menu.findItem(SORT_OPTIONS.get(mAdapter.getSort().ordinal()).first);
        sortItem.setChecked(true);
        refresh.setVisible(true);
    } else {
        sidebar.setVisible(false);
        sortGroup.setVisible(false);
        refresh.setVisible(false);
    }

    return true;
}

From source file:com.example.android.pharmacyinventory.EditorActivity.java

/**
 * This method is called after invalidateOptionsMenu(), so that the
 * menu can be updated (some menu items can be hidden or made visible).
 *///  w w  w. j a v  a2s .c o m
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    // If this is a new drug, hide the "Delete" menu item.
    if (mCurrentDrugUri == null) {
        MenuItem menuItem = menu.findItem(R.id.action_delete);
        menuItem.setVisible(false);
    }
    return true;
}

From source file:ca.ualberta.cs.drivr.MainActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem item = menu.findItem(R.id.action_settings);
    item.setVisible(false);
    super.onPrepareOptionsMenu(menu);
    return true;/*  ww  w. j  a v a  2  s.c  o m*/
}

From source file:org.exoplatform.ui.social.ComposeMessageActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem attach = menu.findItem(R.id.menu_compose_attach);
    if (attach != null) {
        if (composeType == ExoConstants.COMPOSE_POST_TYPE) {
            // show the attach photo menu item
            attach.setVisible(true);
        } else if (composeType == ExoConstants.COMPOSE_COMMENT_TYPE) {
            // hide the attach photo menu item
            attach.setVisible(false);/*from   w  w  w.j av a 2s.  c  o  m*/
        }
    }
    return true;
}