Java Code Examples for android.view.Menu

The following examples show how to use android.view.Menu. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Mizuu   Source File: TvShowEpisodesFragment.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.episodes_overview, menu);

    int padding = MizLib.convertDpToPixels(getActivity(), 16);

    SwitchCompat switchCompat = (SwitchCompat) menu.findItem(R.id.switch_button).getActionView();
    switchCompat.setChecked(mEpisodeLoader != null ? mEpisodeLoader.showAvailableFiles() : false);
    switchCompat.setText(R.string.choiceAvailableFiles);
    switchCompat.setSwitchPadding(padding);
    switchCompat.setPadding(0, 0, padding, 0);

    switchCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mEpisodeLoader.setShowAvailableFiles(isChecked);
            mEpisodeLoader.load();
            showProgressBar();
        }
    });

    super.onCreateOptionsMenu(menu, inflater);
}
 
Example 2
Source Project: Scoops   Source File: Scoop.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Apply the attributed menu item tint to all the icons if the attribute {@link R.attr#toolbarItemTint}
 *
 * @param context      the application context to derive the attr color from
 * @param menu          the menu to apply to
 */
public void apply(Context context, Menu menu){
    Flavor flavor = getCurrentFlavor();
    if(menu != null && menu.size() > 0 && flavor != null){
        int tint = AttrUtils.getColorAttr(context, flavor.getStyleResource(), R.attr.toolbarItemTint);
        for (int i = 0; i < menu.size(); i++) {
            MenuItem item = menu.getItem(i);
            Drawable icon = item.getIcon();
            if(icon != null){
                if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
                    icon.setTint(tint);
                }else{
                    icon.setColorFilter(tint, PorterDuff.Mode.SRC_ATOP);
                }
            }
        }
    }
}
 
Example 3
Source Project: science-journal   Source File: ExperimentListFragment.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
  super.onCreateOptionsMenu(menu, inflater);
  if (claimExperimentsMode) {
    inflater.inflate(R.menu.menu_claim_experiments, menu);
    ColorUtils.colorDrawable(
        applicationContext,
        menu.findItem(R.id.run_review_overflow_menu).getIcon(),
        R.color.claim_experiments_action_bar_text);

  } else {
    inflater.inflate(R.menu.menu_experiment_list, menu);
  }
  optionsMenu = menu;
  updateNetworkStatusIcon();
}
 
Example 4
Source Project: AndroidChromium   Source File: AppMenu.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates and sets up the App Menu.
 * @param menu Original menu created by the framework.
 * @param itemRowHeight Desired height for each app menu row.
 * @param itemDividerHeight Desired height for the divider between app menu items.
 * @param handler AppMenuHandler receives callbacks from AppMenu.
 * @param res Resources object used to get dimensions and style attributes.
 */
AppMenu(Menu menu, int itemRowHeight, int itemDividerHeight, AppMenuHandler handler,
        Resources res) {
    mMenu = menu;

    mItemRowHeight = itemRowHeight;
    assert mItemRowHeight > 0;

    mHandler = handler;

    mItemDividerHeight = itemDividerHeight;
    assert mItemDividerHeight >= 0;

    mNegativeSoftwareVerticalOffset =
            res.getDimensionPixelSize(R.dimen.menu_negative_software_vertical_offset);
    mVerticalFadeDistance = res.getDimensionPixelSize(R.dimen.menu_vertical_fade_distance);
}
 
Example 5
Source Project: BlackList   Source File: SMSConversationFragment.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.main, menu);

    MenuItem menuItem = menu.findItem(R.id.write_message);
    Utils.setMenuIconTint(getContext(), menuItem, R.attr.colorAccent);
    menuItem.setVisible(true);
    menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            // open activity with fragment of sending SMS
            openSMSSendActivity(contactName, contactNumber, messageEdit.getText().toString());
            messageEdit.setText("");
            return true;
        }
    });

    super.onCreateOptionsMenu(menu, inflater);
}
 
Example 6
@SuppressWarnings("ConstantConditions")
@Override
public void onPrepareOptionsMenu(Menu menu) {
    menu.findItem(R.id.action_add).setEnabled(preferenceFile != null && preferenceFile.isValidPreferenceFile());
    menu.findItem(R.id.action_add).setIcon(preferenceFile != null && preferenceFile.isValidPreferenceFile() ? R.drawable.ic_action_add : R.drawable.ic_action_add_disabled);
    MenuItem sortAlpha = menu.findItem(R.id.action_sort_alpha);
    MenuItem sortType = menu.findItem(R.id.action_sort_type);
    sortAlpha.setChecked(false);
    sortType.setChecked(false);
    if (PreferencesActivity.preferenceSortType == PreferenceSortType.ALPHANUMERIC) {
        sortAlpha.setChecked(true);
    } else if (PreferencesActivity.preferenceSortType == PreferenceSortType.TYPE_AND_ALPHANUMERIC) {
        sortType.setChecked(true);
    }
    menu.findItem(R.id.action_restore_file).setVisible(mListener != null && mListener.canRestoreFile(mFile));
    super.onPrepareOptionsMenu(menu);
}
 
Example 7
Source Project: foodie-app   Source File: DishInfoActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem menuItem = menu.findItem(R.id.action_favorite);
    Log.i(TAG, "Pre" + isDishFavorite);
    menuItem.setIcon(isDishFavorite?iconFavorite[1]:iconFavorite[0]);
    return super.onPrepareOptionsMenu(menu);
}
 
Example 8
Source Project: Android-HomeKey-Locker   Source File: MainActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {

    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}
 
Example 9
Source Project: ForPDA   Source File: DeviceFragment.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void addBaseToolbarMenu(Menu menu) {
    super.addBaseToolbarMenu(menu);
    copyLinkMenuItem = menu.add(R.string.copy_link)
            .setOnMenuItemClickListener(item -> {
                Utils.copyToClipBoard("https://4pda.ru/devdb/" + currentData.getId());
                return true;
            });

    shareMenuItem = menu.add(R.string.share)
            .setOnMenuItemClickListener(item -> {
                Utils.shareText("https://4pda.ru/devdb/" + currentData.getId());
                return true;
            });

    noteMenuItem = menu.add(R.string.create_note)
            .setOnMenuItemClickListener(item -> {
                String title = "DevDb: " + currentData.getBrandTitle() + " " + currentData.getTitle();
                String url = "https://4pda.ru/devdb/" + currentData.getId();
                NotesAddPopup.showAddNoteDialog(getContext(), title, url);
                return true;
            });

    toBrandMenuItem = menu.add(R.string.devices)
            .setOnMenuItemClickListener(item -> {
                IntentHandler.handle("https://4pda.ru/devdb/" + currentData.getCatId() + "/" + currentData.getBrandId());
                return true;
            });

    toBrandsMenuItem = menu.add(R.string.devices)
            .setOnMenuItemClickListener(item -> {
                IntentHandler.handle("https://4pda.ru/devdb/" + currentData.getCatId());
                return true;
            });

    refreshToolbarMenuItems(false);
}
 
Example 10
Source Project: Shield   Source File: LightAgentManager.java    License: MIT License 5 votes vote down vote up
public void onOptionsMenuClosed(Menu menu) {
    for (String name : agentList) {
        AgentInterface agent = agents.get(name);
        if (agent != null && agent instanceof FullOptionMenuLifecycle) {
            ((FullOptionMenuLifecycle) agent).onOptionsMenuClosed(menu);
        }
    }
}
 
Example 11
Source Project: Android_Blog_Demos   Source File: ColourImageActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_colour_image, menu);
    return true;
}
 
Example 12
@Override
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
    final MenuItem actionItemAdd = menu.add(0, OPTIONS_MENU_ADD, 0,
            R.string.user_dict_settings_add_menu_title).setIcon(R.drawable.ic_menu_add);
    actionItemAdd.setShowAsAction(
            MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
    final MenuItem actionItemDelete = menu.add(0, OPTIONS_MENU_DELETE, 0,
            R.string.user_dict_settings_delete).setIcon(android.R.drawable.ic_menu_delete);
    actionItemDelete.setShowAsAction(
            MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
}
 
Example 13
Source Project: delion   Source File: PrivacyPreferences.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.clear();
    MenuItem help = menu.add(
            Menu.NONE, R.id.menu_id_targeted_help, Menu.NONE, R.string.menu_help);
    help.setIcon(R.drawable.ic_help_and_feedback);
}
 
Example 14
Source Project: bitseal   Source File: IdentitiesActivity.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
  public boolean onPrepareOptionsMenu(Menu menu)
  {
  	SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
  	if (prefs.getBoolean(KEY_DATABASE_PASSPHRASE_SAVED, false) == false)
{
	menu.removeItem(R.id.menu_item_lock);
}
      return super.onPrepareOptionsMenu(menu);
  }
 
Example 15
Source Project: Ency   Source File: WebActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (isShowLikeIcon) {
        getMenuInflater().inflate(R.menu.menu_web1, menu);
        menuItem = menu.findItem(R.id.item_like);
        setLikeState(daoManager.queryByGuid(guid));
    } else {
        getMenuInflater().inflate(R.menu.menu_web2, menu);
    }
    return true;
}
 
Example 16
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main_menu, menu);
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
        MenuItem set_proxy_item = menu.findItem(R.id.set_proxy);
        set_proxy_item.setVisible(false);
    }
    return true;
}
 
Example 17
Source Project: ankihelper   Source File: FolioActivity.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main, menu);

    Config config = AppUtil.getSavedConfig(getApplicationContext());
    assert config != null;
    UiUtil.setColorIntToDrawable(config.getThemeColor(), menu.findItem(R.id.itemSearch).getIcon());
    UiUtil.setColorIntToDrawable(config.getThemeColor(), menu.findItem(R.id.itemConfig).getIcon());
    UiUtil.setColorIntToDrawable(config.getThemeColor(), menu.findItem(R.id.itemTts).getIcon());

    if (!config.isShowTts())
        menu.findItem(R.id.itemTts).setVisible(false);

    return true;
}
 
Example 18
Source Project: BotLibre   Source File: MainActivity.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
	MenuInflater menuInflater = getMenuInflater();
	menuInflater.inflate(R.menu.menu_main, menu);
	this.menu = menu;
	return true;
}
 
Example 19
Source Project: Travel-Mate   Source File: ShoppingCurrentCityActivity.java    License: MIT License 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.search_menu, menu);
    MenuItem item = menu.findItem(R.id.action_search);
    mSearchView.setMenuItem(item);
    return true;
}
 
Example 20
Source Project: BotLibre   Source File: WebMediumActivity.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
       boolean isAdmin = (MainActivity.user != null) && this.instance.isAdmin;
       if (!isAdmin || this.instance.isExternal) {
       	menu.findItem(R.id.menuAdmin).setEnabled(false);
       }
       if (isAdmin || this.instance.isFlagged) {
       	menu.findItem(R.id.menuFlag).setEnabled(false);
       }
    return true;
}
 
Example 21
Source Project: AndroidChromium   Source File: PrivacyPreferences.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.clear();
    MenuItem help = menu.add(
            Menu.NONE, R.id.menu_id_targeted_help, Menu.NONE, R.string.menu_help);
    help.setIcon(R.drawable.ic_help_and_feedback);
}
 
Example 22
Source Project: Tehreer-Android   Source File: OpenTypeShapingActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu_opentype_shaping, menu);

    return true;
}
 
Example 23
Source Project: cordova-plugin-app-update-demo   Source File: CordovaActivity.java    License: MIT License 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (appView != null) {
        appView.getPluginManager().postMessage("onCreateOptionsMenu", menu);
    }
    return super.onCreateOptionsMenu(menu);
}
 
Example 24
@Override
public void onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);

    searchItem = menu.findItem(R.id.action_search);
    layoutView = menu.findItem(R.id.action_changeView);

    // create search bar and search listener
    if (searchItem != null) {
        searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
        searchView.setOnQueryTextListener(this);
    }
}
 
Example 25
Source Project: android_gisapp   Source File: MainActivity.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
    if (null != mLayersFragment && !mLayersFragment.isDrawerOpen()) {
        // Only show items in the action bar relevant to this screen
        // if the drawer is not showing. Otherwise, let the drawer
        // decide what to show in the action bar.
        getMenuInflater().inflate(R.menu.main, menu);
        //restoreActionBar();

        return true;
    }
    return super.onCreateOptionsMenu(menu);
}
 
Example 26
Source Project: user-interface-samples   Source File: MainActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem logToggle = menu.findItem(R.id.menu_toggle_log);
    logToggle.setVisible(findViewById(R.id.sample_output) instanceof ViewAnimator);
    logToggle.setTitle(mLogShown ? R.string.sample_hide_log : R.string.sample_show_log);

    return super.onPrepareOptionsMenu(menu);
}
 
Example 27
@Override
public final boolean onPrepareOptionsMenu(final Menu menu) {
    super.onPrepareOptionsMenu(menu);
    if (menu != null) {
        updateMenuItems(menu);
    }
    return true;
}
 
Example 28
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    super.onCreateOptionsMenu(menu);
    final Intent i = getIntent();
    boolean showEnterJid = i != null && i.getBooleanExtra(EXTRA_SHOW_ENTER_JID, false);
    menu.findItem(R.id.action_scan_qr_code).setVisible(isCameraFeatureAvailable() && showEnterJid);
    MenuItem mMenuSearchView = menu.findItem(R.id.action_search);
    if (startSearching) {
        mMenuSearchView.expandActionView();
    }
    return true;
}
 
Example 29
Source Project: animation-samples   Source File: MainActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem logToggle = menu.findItem(R.id.menu_toggle_log);
    logToggle.setVisible(findViewById(R.id.sample_output) instanceof ViewAnimator);
    logToggle.setTitle(mLogShown ? R.string.sample_hide_log : R.string.sample_show_log);

    return super.onPrepareOptionsMenu(menu);
}
 
Example 30
Source Project: MOAAP   Source File: MainActivity.java    License: MIT License 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    Log.i(TAG, "called onCreateOptionsMenu");
    mItemSwitchCamera = menu.add("切换前置/后置摄像头");
    return true;
}