android.view.Menu Java Examples

The following examples show how to use android.view.Menu. 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   Author: MizzleDK   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   Author: 52inc   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   Author: google   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   Author: JackyAndroid   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   Author: kaliturin   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
Source Project: Android-PreferencesManager   Author: SimonMarquis   File: PreferencesFragment.java    License: Apache License 2.0 6 votes vote down vote up
@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   Author: Sambor123   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   Author: shaobin0604   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   Author: RadiationX   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   Author: Meituan-Dianping   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   Author: hongyangAndroid   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
Source Project: Android-Keyboard   Author: NlptechProduct   File: UserDictionaryAddWordFragment.java    License: Apache License 2.0 5 votes vote down vote up
@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   Author: derry   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   Author: JonathanCoe   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   Author: Jerry-1123   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
Source Project: telegram-sms   Author: telegram-sms   File: main_activity.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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   Author: mmjang   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   Author: BotLibre   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   Author: project-travel-mate   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   Author: BotLibre   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   Author: JackyAndroid   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   Author: Tehreer   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   Author: vaenow   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
Source Project: Cirrus_depricated   Author: skymania   File: OCFileListFragment.java    License: GNU General Public License v2.0 5 votes vote down vote up
@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   Author: nextgis   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   Author: android   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
Source Project: document-viewer   Author: SufficientlySecure   File: AbstractActionActivity.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public final boolean onPrepareOptionsMenu(final Menu menu) {
    super.onPrepareOptionsMenu(menu);
    if (menu != null) {
        updateMenuItems(menu);
    }
    return true;
}
 
Example #28
Source Project: Pix-Art-Messenger   Author: kriztan   File: ChooseContactActivity.java    License: GNU General Public License v3.0 5 votes vote down vote up
@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   Author: android   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   Author: johnhany   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;
}