List of usage examples for android.view MenuItem isVisible
public boolean isVisible();
From source file:com.maskyn.fileeditorpro.activity.SelectFileActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { // menu items MenuItem imSetAsWorkingFolder = menu.findItem(R.id.im_set_as_working_folder); MenuItem imIsWorkingFolder = menu.findItem(R.id.im_is_working_folder); MenuItem imSelectFolder = menu.findItem(R.id.im_select_folder); if (imSetAsWorkingFolder != null) { // set the imSetAsWorkingFolder visible only if the two folder dont concide imSetAsWorkingFolder//www .j a v a2s . c o m .setVisible(!currentFolder.equals(PreferenceHelper.getWorkingFolder(SelectFileActivity.this))); } if (imIsWorkingFolder != null) { // set visible is the other is invisible imIsWorkingFolder.setVisible(!imSetAsWorkingFolder.isVisible()); } if (imSelectFolder != null) { imSelectFolder.setVisible(!wantAFile); } return super.onPrepareOptionsMenu(menu); }
From source file:cz.muni.fi.japanesedictionary.main.MainActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList); MenuItem noteItem = menu.findItem(R.id.ab_note); MenuItem favoriteItem = menu.findItem(R.id.favorite); MenuItem searchItem = menu.findItem(R.id.action_search); if (searchItem != null) { searchItem.setVisible(!drawerOpen); }/*w ww . j a v a2 s . com*/ if (drawerOpen) { //is open Log.i(LOG_TAG, "Drawer open"); mNoteVisible = noteItem != null && noteItem.isVisible(); mFavoriteVisible = favoriteItem != null && favoriteItem.isVisible(); mSearchVisible = MenuItemCompat.isActionViewExpanded(searchItem); if (noteItem != null) { noteItem.setVisible(false); } if (favoriteItem != null) { favoriteItem.setVisible(false); } Log.i(LOG_TAG, "Drawer open - hide search"); MenuItemCompat.collapseActionView(searchItem); if (searchItem != null) { searchItem.setVisible(false); searchItem.setEnabled(false); } } else { Log.i(LOG_TAG, "Drawer close"); if (favoriteItem != null) { favoriteItem.setVisible(mFavoriteVisible); } if (noteItem != null) { noteItem.setVisible(mNoteVisible); } if (searchItem != null) { searchItem.setVisible(true); searchItem.setEnabled(true); } if (mSearchVisible) { Log.i(LOG_TAG, "Drawer close, expand search"); MenuItemCompat.expandActionView(searchItem); mSearchView.setQuery(mCurFilter, false); } } return super.onPrepareOptionsMenu(menu); }
From source file:com.money.manager.ex.account.AccountTransactionListFragment.java
@Override public void onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); //force show add transaction MenuItem itemAddTransaction = menu.findItem(R.id.menu_add_transaction_account); if (itemAddTransaction != null) itemAddTransaction.setVisible(true); //manage dual panel if (getActivity() != null && getActivity() instanceof MainActivity) { MainActivity activity = (MainActivity) getActivity(); if (!activity.isDualPanel()) { //hide sync toolbar MenuItem itemSync = menu.findItem(R.id.menu_sync); if (itemSync != null) itemSync.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); // hide menu open database MenuItem itemOpenDatabase = menu.findItem(R.id.menu_open_database); if (itemOpenDatabase != null) { //itemOpenDatabase.setVisible(isShownOpenDatabaseItemMenu()); itemOpenDatabase.setShowAsAction( !itemSync.isVisible() ? MenuItem.SHOW_AS_ACTION_ALWAYS : MenuItem.SHOW_AS_ACTION_NEVER); }//from w ww.j av a 2 s .c o m //hide dash board MenuItem itemDashboard = menu.findItem(R.id.menu_dashboard); if (itemDashboard != null) itemDashboard.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); } } selectCurrentPeriod(menu); selectCurrentStatus(menu); }
From source file:github.daneren2005.dsub.fragments.SubsonicFragment.java
protected void recreateContextMenu(Menu menu) { List<MenuItem> menuItems = new ArrayList<MenuItem>(); for (int i = 0; i < menu.size(); i++) { MenuItem item = menu.getItem(i); if (item.isVisible()) { menuItems.add(item);/*from w w w . ja v a 2s .c o m*/ } } menu.clear(); for (int i = 0; i < menuItems.size(); i++) { MenuItem item = menuItems.get(i); menu.add(tag, item.getItemId(), Menu.NONE, item.getTitle()); } }
From source file:org.de.jmg.learn.MainActivity.java
private void _SetShowAsAction(final MenuItem m) { final View tb = this.findViewById(R.id.action_bar); int SizeOther = 0; int width;// w ww . ja v a 2 s . c om ActionMenu = null; if (tb != null) { width = tb.getWidth(); Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); double height = metrics.heightPixels; int viewTop = this.findViewById(Window.ID_ANDROID_CONTENT).getTop(); double scale = (height - viewTop) / (double) 950; if (scale < .5f) { isSmallDevice = true; } double ActionBarHeight = tb.getHeight(); if (isSmallDevice && ActionBarHeight / height > .15f) { try { FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) tb.getLayoutParams(); layoutParams.height = (int) (height * .15f); tb.setMinimumHeight((int) (height * .15f)); tb.setLayoutParams(layoutParams); tb.requestLayout(); } catch (Exception ex) { Log.e("SetToolbarHeight", ex.getMessage(), ex); } } if (width > 0) { ViewGroup g = (ViewGroup) tb; for (int i = 0; i < g.getChildCount(); i++) { View v = g.getChildAt(i); if ((v instanceof android.support.v7.widget.ActionMenuView)) { SizeOther += v.getWidth(); ActionMenu = (android.support.v7.widget.ActionMenuView) v; } } if (SizeOther < width * .7) _blnReverse = true; if ((_blnReverse || SizeOther > width * .7) && ActionMenu != null) { if (_blnReverse) { //if (!_hasBeenDownsized || _hasBeenDownsized) //{ MenuBuilder mm = (MenuBuilder) ActionMenu.getMenu(); int Actions = mm.getActionItems().size(); try { MenuItem mmm = ActionMenu.getMenu().getItem(Actions + _invisibleCount); if (mmm.isVisible()) { MenuItemCompat.setShowAsAction(mmm, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); } else { _invisibleCount += 1; _SetShowAsAction(mmm); } } catch (IndexOutOfBoundsException ex) { return; } //} } else { MenuItemCompat.setShowAsAction(m, MenuItemCompat.SHOW_AS_ACTION_NEVER); _hasBeenDownsized = true; } ActionMenu.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (ActionMenu != null) { lib.removeLayoutListener(ActionMenu.getViewTreeObserver(), this); int SizeNew = ActionMenu.getWidth(); Log.v("Test", "" + SizeNew); MenuBuilder mm = (MenuBuilder) ActionMenu.getMenu(); int count = mm.getActionItems().size(); if (count >= 1 && !(_blnReverse && SizeNew > tb.getWidth() * .7)) { MenuItem m = mm.getActionItems().get(count - 1); _SetShowAsAction(m); } } } }); } } } }
From source file:org.brandroid.openmanager.activities.OpenExplorer.java
private ImageButton makeMenuButton(final MenuItem item, ViewGroup parent) { ImageButton btn = (ImageButton) getLayoutInflater().inflate(R.layout.toolbar_button, parent, false); if (!item.isVisible()) btn.setVisibility(View.GONE); Drawable d = item.getIcon();//from w w w .j av a 2s . com if (d instanceof BitmapDrawable) ((BitmapDrawable) d).setGravity(Gravity.CENTER); btn.setImageDrawable(d); btn.setId(item.getItemId()); btn.setOnClickListener(this); btn.setLongClickable(true); btn.setFocusable(true); btn.setOnFocusChangeListener(this); btn.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { showToast(item.getTitle()); return true; } }); return btn; }
From source file:org.mozilla.gecko.BrowserApp.java
private void updateAddonMenuItem(int id, JSONObject options) { // Set attribute for the menu item in cache, if available if (mAddonMenuItemsCache != null && !mAddonMenuItemsCache.isEmpty()) { for (MenuItemInfo item : mAddonMenuItemsCache) { if (item.id == id) { item.label = options.optString("name", item.label); item.checkable = options.optBoolean("checkable", item.checkable); item.checked = options.optBoolean("checked", item.checked); item.enabled = options.optBoolean("enabled", item.enabled); item.visible = options.optBoolean("visible", item.visible); item.added = (mMenu != null); break; }/*from ww w .j a v a2s. c o m*/ } } if (mMenu == null) { return; } final MenuItem menuItem = mMenu.findItem(id); if (menuItem != null) { menuItem.setTitle(options.optString("name", menuItem.getTitle().toString())); menuItem.setCheckable(options.optBoolean("checkable", menuItem.isCheckable())); menuItem.setChecked(options.optBoolean("checked", menuItem.isChecked())); menuItem.setEnabled(options.optBoolean("enabled", menuItem.isEnabled())); menuItem.setVisible(options.optBoolean("visible", menuItem.isVisible())); } }
From source file:com.nest5.businessClient.Initialactivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { mMenu = menu;/*from ww w . j a va2s . c o m*/ MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.main_menu, menu); SharedPreferences defaultprefs = PreferenceManager.getDefaultSharedPreferences(mContext); boolean layouttables = defaultprefs.getBoolean("arrange_tables", false); if (layouttables) { MenuItem tables = mMenu.findItem(R.id.layouttables); if (!tables.isVisible()) { tables.setVisible(true); invalidateOptionsMenu(); } MenuItem mesas = mMenu.findItem(R.id.menu_show_tables); if (!mesas.isVisible()) { mesas.setVisible(true); invalidateOptionsMenu(); } } return true; }
From source file:com.nest5.businessClient.Initialactivity.java
public void onActivityResult(int requestCode, int resultCode, Intent intent) { IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent); // ////Log.i(TAG, String.valueOf(redeemCoupon)); if (scanResult != null) { }//from w ww. j a v a 2s .com if (requestCode == RETURN_FROM_DESIGN_TABLE) { String result = null; if (resultCode == RESULT_OK) { result = intent.getStringExtra(Setup.SAVED_TABLES); } if (resultCode == RESULT_CANCELED) { //Write your code if there's no result } if (result != null) { //load tables view and allow to make order for it showMesasLayout(); } } if (requestCode == RETURN_FROM_OPENCLOSE_TABLE) { Table actual = null; int clientes = 0; if (resultCode == RESULT_OK) { actual = intent.getParcelableExtra("MIMESA"); clientes = intent.getIntExtra("MIMESACLIENTES", 0); if (actual != null) { //load tables view and allow to make order for it currentTable = new CurrentTable<Table, Integer>(actual, clientes); statusText.setVisibility(View.VISIBLE); statusText.setText(actual.getName() + " con " + clientes + " Clientes."); //Log.i("MISPRUEBAS",currentTable.getTable().getName()); } } if (resultCode == RESULT_CANCELED) { //Write your code if there's no result } if (resultCode == Setup.CLOSE_TABLE) { //Log.i("MISPRUEBAS","volviendo de cerrar mesa"); actual = intent.getParcelableExtra("MIMESA"); //tomar mesa que se cierra, preguntar si es cancelar venta o pagar, si es cancelar borra de opentables, de orders etc y si es pagar, pone en currentsale y abre dialogo pagar if (actual != null) { //Log.i("MISPRUEBAS","volviendo de cerrar mesa y no esta nulo"); //load tables view and allow to make order for it currentTable = new CurrentTable<Table, Integer>(actual, 0); //Log.i("MISPRUEBAS","regreasa de dar clic en cerrar mesa con: "+currentTable.getTable().getName()); statusText.setVisibility(View.VISIBLE); statusText.setText("Cerrando: " + actual.getName()); openOtherWindow = true; openOtherWindowAction = OPEN_TABLE_ACTION; } } } // else continue with any other code you need in the method SharedPreferences defaultprefs = PreferenceManager.getDefaultSharedPreferences(mContext); boolean layouttables = defaultprefs.getBoolean("arrange_tables", false); MenuItem tablelayouts = mMenu.findItem(R.id.layouttables); MenuItem showtables = mMenu.findItem(R.id.menu_show_tables); boolean change = false; if (tablelayouts.isVisible() != layouttables) change = true; tablelayouts.setVisible(layouttables); showtables.setVisible(layouttables); if (change) { invalidateOptionsMenu(); } }