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:org.de.jmg.learn.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    try {/* www  .j a  va2 s  .c o  m*/
        getMenuInflater().inflate(R.menu.main, menu);
        //findViewById(R.menu.main).setBackgroundColor(Color.BLACK);
        //.setBackgroundColor(Color.BLACK);
        //resize();
        OptionsMenu = menu;
        if (OptionsMenu != null) {
            mnuAddNew = menu.findItem(R.id.mnuAddWord);
            mnuUploadToQuizlet = menu.findItem(R.id.mnuUploadToQuizlet);
            Resources resources = context.getResources();
            DisplayMetrics metrics = resources.getDisplayMetrics();
            int height = metrics.heightPixels;
            int viewTop = this.findViewById(Window.ID_ANDROID_CONTENT).getTop();
            height = height - viewTop;
            double scale = (double) height / (double) 950;
            if (scale < .5f) {
                isSmallDevice = true;
            }
            if (Build.VERSION.SDK_INT < 11) {
                menu.findItem(R.id.mnuOpenQuizlet).setVisible(false);
                menu.findItem(R.id.mnuUploadToQuizlet).setVisible(false);
            }
            /*
            if (isSmallDevice)
            {
            MenuItemCompat.setShowAsAction(menu.findItem(R.id.mnuSaveAs), MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
            }
            */
            MenuItem mnuQuizlet = menu.findItem(R.id.mnuLoginQuizlet);
            mnuQuizlet.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    //throw new RuntimeException("Test");
                    return false;
                }
            });
            if (BuildConfig.DEBUG) {
                mnuQuizlet.setVisible(true);
            } else {
                mnuQuizlet.setVisible(false);
            }
            MenuItem mnuAskReverse = OptionsMenu.findItem(R.id.mnuAskReverse);
            mnuAskReverse.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    item.setChecked(!item.isChecked());
                    vok.reverse = item.isChecked();
                    setMnuReverse();
                    return true;
                }
            });
            setMnuReverse();
            /*
            if (isSmallDevice)
            {
            MenuItem m = menu.findItem(R.id.mnuHome);
            MenuItemCompat.setShowAsAction(m,MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
            m = menu.findItem(R.id.mnuFileOpen);
            MenuItemCompat.setShowAsAction(m,MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
            m = menu.findItem(R.id.mnuSaveAs);
            MenuItemCompat.setShowAsAction(m,MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
            m = menu.findItem(R.id.mnuAddWord);
            MenuItemCompat.setShowAsAction(m,MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
            //lib.ShowToast(this,"Menus set to IF_ROOM!");
            }
            */
            mainView.getViewTreeObserver()
                    .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

                        @Override
                        public void onGlobalLayout() {
                            // Ensure you call it only once :
                            lib.removeLayoutListener(mainView.getViewTreeObserver(), this);
                            //MainActivity.this.SetShowAsAction(mnuUploadToQuizlet);
                        }
                    });

            return true;
        }
        throw new RuntimeException("menu is null!");
    } catch (Exception ex) {
        lib.ShowException(this, ex);
    }

    return false;
}

From source file:de.vanita5.twittnuker.util.Utils.java

public static void setMenuForStatus(final Context context, final Menu menu, final ParcelableStatus status) {
    if (context == null || menu == null || status == null)
        return;//from  www.j  a  v  a  2  s .  c  om
    final int activatedColor = ThemeUtils.getUserThemeColor(context);
    final boolean isMyRetweet = isMyRetweet(status);
    final MenuItem delete = menu.findItem(MENU_DELETE);
    if (delete != null) {
        delete.setVisible(status.account_id == status.user_id && !isMyRetweet);
    }
    final MenuItem retweet = menu.findItem(MENU_RETWEET);
    if (retweet != null) {
        final Drawable icon = retweet.getIcon().mutate();
        retweet.setVisible(!status.user_is_protected || isMyRetweet);
        if (isMyRetweet) {
            icon.setColorFilter(activatedColor, Mode.SRC_ATOP);
            retweet.setTitle(R.string.cancel_retweet);
        } else {
            icon.clearColorFilter();
            retweet.setTitle(R.string.retweet);
        }
    }
    final MenuItem itemRetweetSubmenu = menu.findItem(R.id.retweet_submenu);
    if (itemRetweetSubmenu != null) {
        final Drawable icon = itemRetweetSubmenu.getIcon().mutate();
        if (isMyRetweet) {
            icon.setColorFilter(activatedColor, Mode.SRC_ATOP);
        } else {
            icon.clearColorFilter();
        }
    }
    final MenuItem favorite = menu.findItem(MENU_FAVORITE);
    if (favorite != null) {
        final Drawable icon = favorite.getIcon().mutate();
        if (status.is_favorite) {
            icon.setColorFilter(activatedColor, Mode.SRC_ATOP);
            favorite.setTitle(R.string.unfavorite);
        } else {
            icon.clearColorFilter();
            favorite.setTitle(R.string.favorite);
        }
    }
    final MenuItem love = menu.findItem(MENU_LOVE);
    if (love != null) {
        final Drawable icon = love.getIcon().mutate();
        love.setVisible(!status.user_is_protected || isMyRetweet);
        if (isMyRetweet && status.is_favorite) {
            icon.setColorFilter(activatedColor, Mode.SRC_ATOP);
        } else {
            icon.clearColorFilter();
        }
    }
    final MenuItem translate = menu.findItem(MENU_TRANSLATE);
    if (translate != null) {
        final AccountWithCredentials account = Account.getAccountWithCredentials(context, status.account_id);
        final boolean isOfficialKey = AccountWithCredentials.isOfficialCredentials(context, account);
        setMenuItemAvailability(menu, MENU_TRANSLATE, isOfficialKey);
    }
    final MenuItem shareItem = menu.findItem(R.id.share_submenu);
    final Menu shareSubmenu = shareItem != null && shareItem.hasSubMenu() ? shareItem.getSubMenu() : null;
    if (shareSubmenu != null) {
        final Intent shareIntent = createStatusShareIntent(context, status);
        shareSubmenu.removeGroup(MENU_GROUP_STATUS_SHARE);
        addIntentToMenu(context, shareSubmenu, shareIntent, MENU_GROUP_STATUS_SHARE);
    }
}

From source file:com.github.akinaru.hcidebugger.activity.HciDebuggerActivity.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  ww  w  .  ja v  a 2 s.  com
            public boolean onMenuItemClick(MenuItem item) {
                clearAdapter();
                return true;
            }
        });
    }

    //bluetoooth scan button
    item = menu.findItem(R.id.scan_btn);
    if (item != null) {
        item.setIcon(R.drawable.ic_action_scanning);
        item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

            @Override
            public boolean onMenuItemClick(MenuItem item) {
                toggleScan(item);
                return true;
            }
        });
    }

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

            @Override
            public boolean onMenuItemClick(MenuItem item) {
                toggleBtState();
                return true;
            }
        });
        if (mBluetoothAdapter.isEnabled()) {
            item.setIcon(R.drawable.ic_bluetooth);
        } else {
            item.setIcon(R.drawable.ic_bluetooth_disabled);
        }
    }

    //reset snoop file button
    if (Build.VERSION.SDK_INT <= 22) {
        item = menu.findItem(R.id.reset_snoop_file);
        item.setVisible(true);
        if (item != null) {
            item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    resetSnoopFile();
                    refresh();
                    return true;
                }
            });
        }
    }

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

            @Override
            public boolean onMenuItemClick(MenuItem item) {
                filter();
                return true;
            }
        });
    }

    //refresh button
    item = menu.findItem(R.id.refresh);
    if (item != null) {
        if (getResources().getConfiguration().orientation != Configuration.ORIENTATION_PORTRAIT) {

            item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    refresh();
                    return true;
                }
            });
        } else {
            item.setVisible(false);
        }
    }

    item = menu.findItem(R.id.share);

    if (item != null) {
        // Fetch and store ShareActionProvider
        mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
        setSharedIntent();
    }

    return super.onCreateOptionsMenu(menu);
}

From source file:com.smc.tw.waltz.MainActivity.java

private void resetLayout() {
    if (DEBUG)// w w  w . j  a  va2  s  .c  o m
        Log.d(TAG, "resetLayout");

    MenuItem menuDropbox = mNavigationView.getMenu().findItem(R.id.navigation_dropbox);
    MenuItem menuDeviceList = mNavigationView.getMenu().findItem(R.id.navigation_device_list);
    MenuItem menuSignin = mNavigationView.getMenu().findItem(R.id.navigation_signin);
    MenuItem menuSignout = mNavigationView.getMenu().findItem(R.id.navigation_signout);

    View headerLayout = mNavigationView.getHeaderView(0);
    TextView userInfoView = (TextView) headerLayout.findViewById(R.id.navigation_header_user_name);

    if (MainApplication.isUserSignedIn()) {
        if (menuSignin != null) {
            menuSignin.setEnabled(false);
            menuSignin.setVisible(false);
        }

        if (menuSignout != null) {
            menuSignout.setEnabled(true);
            menuSignout.setVisible(true);
        }

        if (menuDropbox != null) {
            menuDropbox.setEnabled(true);
            menuDropbox.setVisible(true);
        }

        UserManager userManager = MainApplication.getUserManager();

        String name = userManager.getUsername();

        userInfoView.setText(name);

        userInfoView.setVisibility(View.VISIBLE);
    } else {
        if (menuSignin != null) {
            menuSignin.setEnabled(true);
            menuSignin.setVisible(true);
        }

        if (menuSignout != null) {
            menuSignout.setEnabled(false);
            menuSignout.setVisible(false);
        }

        if (menuDropbox != null) {
            menuDropbox.setEnabled(false);
            menuDropbox.setVisible(false);
        }

        userInfoView.setVisibility(View.GONE);
    }

    if (mShowDropbox) {
        showDropboxAssociation();

        if (menuDropbox != null)
            menuDropbox.setChecked(true);
    } else {
        showDeviceList();

        mDeviceListFragment.notifyDataSetChanged();

        if (menuDeviceList != null)
            menuDeviceList.setChecked(true);
    }
}

From source file:com.amaze.carbonfilemanager.activities.MainActivity.java

public void invalidatePasteButton(MenuItem paste) {
    if (MOVE_PATH != null || COPY_PATH != null) {
        paste.setVisible(true);
    } else {/* w  ww  . j  a v  a 2  s .  c om*/
        paste.setVisible(false);
    }
}

From source file:net.zorgblub.typhon.fragment.ReadingFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {

    AppCompatActivity activity = (AppCompatActivity) getActivity();

    if (activity == null) {
        return;/*from  w w w  .  ja va  2  s  .com*/
    }

    MenuItem nightMode = menu.findItem(R.id.profile_night);
    MenuItem dayMode = menu.findItem(R.id.profile_day);

    MenuItem tts = menu.findItem(R.id.text_to_speech);
    tts.setEnabled(ttsAvailable);

    activity.getSupportActionBar().show();

    if (config.getColourProfile() == ColourProfile.DAY) {
        dayMode.setVisible(false);
        nightMode.setVisible(true);
    } else {
        dayMode.setVisible(true);
        nightMode.setVisible(false);
    }

    // Only show open file item if we have a file manager installed
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("file/*");
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    if (!PlatformUtil.isIntentAvailable(context, intent)) {
        menu.findItem(R.id.open_file).setVisible(false);
    }

    activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

From source file:org.getlantern.firetweet.util.Utils.java

public static void setMenuForStatus(final Context context, final Menu menu, final ParcelableStatus status,
        final ParcelableCredentials account) {
    if (context == null || menu == null || status == null)
        return;/* ww  w  .  j  a v  a 2  s .  com*/
    final Resources resources = context.getResources();
    final int retweetHighlight = resources.getColor(R.color.highlight_retweet);
    final int favoriteHighlight = resources.getColor(R.color.highlight_favorite);
    final boolean isMyRetweet = isMyRetweet(status);
    final MenuItem delete = menu.findItem(MENU_DELETE);
    if (delete != null) {
        delete.setVisible(status.account_id == status.user_id && !isMyRetweet);
    }
    final MenuItem retweet = menu.findItem(MENU_RETWEET);
    if (retweet != null) {
        retweet.setVisible(!status.user_is_protected || isMyRetweet);
        ActionIconDrawable.setMenuHighlight(retweet, new FiretweetMenuInfo(isMyRetweet, retweetHighlight));
        retweet.setTitle(isMyRetweet ? R.string.cancel_retweet : R.string.retweet);
    }
    final MenuItem retweetSubItem = menu.findItem(R.id.retweet_submenu);
    if (retweetSubItem != null) {
        ActionIconDrawable.setMenuHighlight(retweetSubItem,
                new FiretweetMenuInfo(isMyRetweet, retweetHighlight));
    }
    final MenuItem favorite = menu.findItem(MENU_FAVORITE);
    if (favorite != null) {
        ActionIconDrawable.setMenuHighlight(favorite,
                new FiretweetMenuInfo(status.is_favorite, favoriteHighlight));
        favorite.setTitle(status.is_favorite ? R.string.unfavorite : R.string.favorite);
    }
    final MenuItem translate = menu.findItem(MENU_TRANSLATE);
    if (translate != null) {
        final boolean isOfficialKey = isOfficialCredentials(context, account);
        final SharedPreferencesWrapper prefs = SharedPreferencesWrapper.getInstance(context,
                SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
        final boolean forcePrivateApis = prefs.getBoolean(KEY_FORCE_USING_PRIVATE_APIS, false);
        setMenuItemAvailability(menu, MENU_TRANSLATE, forcePrivateApis || isOfficialKey);
    }
    menu.removeGroup(MENU_GROUP_STATUS_EXTENSION);
    addIntentToMenuForExtension(context, menu, MENU_GROUP_STATUS_EXTENSION, INTENT_ACTION_EXTENSION_OPEN_STATUS,
            EXTRA_STATUS, EXTRA_STATUS_JSON, status);
    //final MenuItem shareItem = menu.findItem(R.id.share);
    //final ActionProvider shareProvider = MenuItemCompat.getActionProvider(shareItem);
    /*
    if (shareProvider instanceof SupportStatusShareProvider) {
    ((SupportStatusShareProvider) shareProvider).setStatus(status);
    } else if (shareProvider instanceof ShareActionProvider) {
    final Intent shareIntent = createStatusShareIntent(context, status);
    ((ShareActionProvider) shareProvider).setShareIntent(shareIntent);
    final Menu shareSubMenu = shareItem.getSubMenu();
    final Intent shareIntent = createStatusShareIntent(context, status);
    shareSubMenu.removeGroup(MENU_GROUP_STATUS_SHARE);
    addIntentToMenu(context, shareSubMenu, shareIntent, MENU_GROUP_STATUS_SHARE);
    } */

}

From source file:com.aujur.ebookreader.activity.ReadingFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {

    SherlockFragmentActivity activity = getSherlockActivity();

    if (activity == null) {
        return;//from  ww  w.  j  a v a  2 s  .  co m
    }

    MenuItem nightMode = menu.findItem(R.id.profile_night);
    MenuItem dayMode = menu.findItem(R.id.profile_day);

    MenuItem tts = menu.findItem(R.id.text_to_speech);
    tts.setEnabled(ttsAvailable);

    activity.getSupportActionBar().show();

    if (config.getColourProfile() == ColourProfile.DAY) {
        dayMode.setVisible(false);
        nightMode.setVisible(true);
    } else {
        dayMode.setVisible(true);
        nightMode.setVisible(false);
    }

    // Only show open file item if we have a file manager installed
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("file/*");
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    if (!isIntentAvailable(context, intent)) {
        menu.findItem(R.id.open_file).setVisible(false);
    }

    activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

From source file:com.kanchi.periyava.old.Activity.MainActivity.java

/**
 * Performs the actual navigation logic, updating the main content fragment.
 *///from   w  w w  . j a va2s  .co  m
private void navigate(final int itemId) {
    Bundle bundle = new Bundle();
    MenuItem item;
    Message msg = Message.obtain();
    switch (itemId) {
    case R.id.about_peetham:
        msg.what = ConstValues.ABOUT_PEETHAM;
        getFlowHandler().sendMessage(msg);
        break;
    case R.id.about_acharays:
        msg.what = ConstValues.ABOUT_ACHARAYAS;
        getFlowHandler().sendMessage(msg);
        break;

    case R.id.aboutus:
        msg.what = ConstValues.ABOUT_US;
        getFlowHandler().sendMessage(msg);
        break;

    case R.id.privacy:
        msg.what = ConstValues.PRIVACY_POLICY;
        getFlowHandler().sendMessage(msg);
        break;

    case R.id.feedback:
        msg.what = ConstValues.HELP_FEEDBACK;
        getFlowHandler().sendMessage(msg);
        break;
    case R.id.exit:
        android.os.Process.killProcess(android.os.Process.myPid());
        break;
    case R.id.signin:
        msg.what = ConstValues.LOGIN;
        getFlowHandler().sendMessage(msg);
        break;
    case R.id.signout:
        super.ShowMessage(MessageDisplay.DO_YOU_WANT_EXIT, new DialogActionCallback() {
            @Override
            public void onOKClick(String errorCode) {
                Message msg = Message.obtain();
                msg.what = ConstValues.DASHBOARD_WITHOUT_LOGIN;
                getFlowHandler().sendMessage(msg);
            }

            @Override
            public void onCancelClick(String errorCode) {

            }
        });

        break;
    case R.id.dashboard:
        if (UserProfile.getUserProfile().isLoggedIn) {
            msg.what = ConstValues.DASHBOARD_LOGIN;

        } else {
            msg.what = ConstValues.DASHBOARD_WITHOUT_LOGIN;

        }
        getFlowHandler().sendMessage(msg);
        break;
    case R.id.books:
        msg.what = ConstValues.BOOKS_LIST;
        getFlowHandler().sendMessage(msg);
        break;
    /*case R.id.devithinkural:
      msg.what = ConstValues.DEIVATHIN_KURAL;
      getFlowHandler().sendMessage(msg);
      break;*/
    case R.id.satsang:
        if (UserProfile.getUserProfile().isLoggedIn) {
            msg.what = ConstValues.SATSANG_LIST_LOGIN;

        } else {
            msg.what = ConstValues.SATSANG_LIST_WITHOUT_LOGIN;

        }
        getFlowHandler().sendMessage(msg);

        break;
    case R.id.japam:
        if (UserProfile.getInstance().isjoinedsatsang == true) {
            super.showFragment(new Japam(), null, R.id.content, true, Japam.TAG);
        } else {
            ShowSnackBar(context, getWindow().getDecorView(), getResources().getString(R.string.err_not_joined),
                    null, null);
        }
        break;
    case R.id.radio:
        if (!NetworkConnection.isConnected(context)) {
            msg.what = ConstValues.ERROR_INTERNET_CONNECTION;
            getFlowHandler().sendMessage(msg);

        } else {
            item = globalmenu.findItem(R.id.radio);
            item.setVisible(true);
            msg.what = ConstValues.RADIO;
            getFlowHandler().sendMessage(msg);
        }
        break;
    case R.id.gallery:
        msg.what = ConstValues.PHOTO_LIST;
        getFlowHandler().sendMessage(msg);
        break;
    case R.id.videos:
        msg.what = ConstValues.VIDEO_LIST;
        getFlowHandler().sendMessage(msg);
        break;

    /*case R.id.setting:
      super.showFragment(new Setting(), null, R.id.content, true, Setting.TAG);
      break;
            
    case R.id.about:
      super.showFragment(mAbout, null, R.id.content, true, mAbout.TAG);
      break;
      */
    default:
        // ignore
        break;
    }
}