SHOW_AS_ACTION_ALWAYS源码实例Demo

android.view.MenuItem#SHOW_AS_ACTION_ALWAYS源码实例Demo

下面列出了android.view.MenuItem#SHOW_AS_ACTION_ALWAYS 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: react-native-navigation   文件: Button.java
private static Number parseShowAsAction(JSONObject json) {
    final Text showAsAction = TextParser.parse(json, "showAsAction");
    if (!showAsAction.hasValue()) {
        return new Number(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }

    switch (showAsAction.get()) {
        case "always":
            return new Number(MenuItem.SHOW_AS_ACTION_ALWAYS);
        case "never":
            return new Number(MenuItem.SHOW_AS_ACTION_NEVER);
        case "withText":
            return new Number(MenuItem.SHOW_AS_ACTION_WITH_TEXT);
        case "ifRoom":
        default:
            return new Number(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }
}
 
private Button createButton() {
    Button b = new Button();
    b.id = "btn1";
    b.text = new Text("button");
    b.color = new Colour(Color.RED);
    b.showAsAction = new Number(MenuItem.SHOW_AS_ACTION_ALWAYS);
    return b;
}
 
private void setIconButton(boolean enabled) {
    button.id = "btn1";
    button.icon = new Text("someIcon");
    button.color = new Colour(Color.RED);
    button.component.name = new NullText();
    button.component.componentId = new NullText();
    button.enabled = new Bool(enabled);
    button.showAsAction = new Number(MenuItem.SHOW_AS_ACTION_ALWAYS);
}
 
源代码4 项目: Dashchan   文件: ListUnit.java
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
	gridView.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE);
	gridView.clearChoices();
	mode.setTitle(instance.context.getString(R.string.text_selected_format, 0));
	int selectAllResId = ResourceUtils.getSystemSelectionIcon(instance.context, "actionModeSelectAllDrawable",
			"ic_menu_selectall_holo_dark");
	int flags = MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT;
	ActionIconSet set = new ActionIconSet(instance.context);
	menu.add(0, ACTION_MENU_SELECT_ALL, 0, R.string.action_select_all)
			.setIcon(selectAllResId).setShowAsAction(flags);
	menu.add(0, ACTION_MENU_DOWNLOAD_FILES, 0, R.string.action_download_files)
			.setIcon(set.getId(R.attr.actionDownload)).setShowAsAction(flags);
	return true;
}
 
源代码5 项目: Dashchan   文件: PostsPage.java
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
	PageHolder pageHolder = getPageHolder();
	ChanConfiguration configuration = getChanConfiguration();
	getAdapter().setSelectionModeEnabled(true);
	mode.setTitle(getString(R.string.text_selected_format, 0));
	int pasteResId = ResourceUtils.getSystemSelectionIcon(getActivity(), "actionModePasteDrawable",
			"ic_menu_paste_holo_dark");
	int flags = MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT;
	ChanConfiguration.Board board = configuration.safe().obtainBoard(pageHolder.boardName);
	menu.add(0, ACTION_MENU_MAKE_THREADSHOT, 0, R.string.action_make_threadshot)
			.setIcon(obtainIcon(R.attr.actionMakeThreadshot)).setShowAsAction(flags);
	if (replyable != null) {
		menu.add(0, ACTION_MENU_REPLY, 0, R.string.action_reply).setIcon(pasteResId).setShowAsAction(flags);
	}
	if (board.allowDeleting) {
		ChanConfiguration.Deleting deleting = configuration.safe().obtainDeleting(pageHolder.boardName);
		if (deleting != null && deleting.multiplePosts) {
			menu.add(0, ACTION_MENU_DELETE_POSTS, 0, R.string.action_delete)
					.setIcon(obtainIcon(R.attr.actionDelete)).setShowAsAction(flags);
		}
	}
	if (board.allowReporting) {
		ChanConfiguration.Reporting reporting = configuration.safe().obtainReporting(pageHolder.boardName);
		if (reporting != null && reporting.multiplePosts) {
			menu.add(0, ACTION_MENU_SEND_REPORT, 0, R.string.action_report)
					.setIcon(obtainIcon(R.attr.actionReport)).setShowAsAction(flags);
		}
	}
	return true;
}
 
源代码6 项目: Dashchan   文件: CommentTextView.java
@TargetApi(Build.VERSION_CODES.M)
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
	currentActionMode = mode;
	currentActionModeMenu = menu;
	setSelectionMode(true);
	int pasteResId = ResourceUtils.getSystemSelectionIcon(getContext(), "actionModePasteDrawable",
			"ic_menu_paste_holo_dark");
	ActionIconSet set = new ActionIconSet(getContext());
	int flags = MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT;
	if (C.API_MARSHMALLOW && mode.getType() == ActionMode.TYPE_FLOATING) {
		int order = 1; // Only "cut" menu item uses this order which doesn't present in non-editable TextView
		if (replyable != null) {
			menu.add(0, android.R.id.button1, order, R.string.action_quote)
					.setIcon(pasteResId).setShowAsAction(flags);
		}
		menu.add(0, android.R.id.button2, order, R.string.action_browser)
				.setIcon(set.getId(R.attr.actionForward)).setShowAsAction(flags);
	} else {
		if (replyable != null) {
			menu.add(0, android.R.id.button1, 0, R.string.action_quote).setIcon(pasteResId)
					.setShowAsAction(flags);
		}
		menu.add(0, android.R.id.button2, 0, R.string.action_browser).setIcon(set.getId(R.attr.actionForward))
				.setShowAsAction(flags);
	}
	// Stop selection fixation after creating action mode
	restoreSelectionRunnable = null;
	return true;
}
 
源代码7 项目: FloatingSearchView   文件: FloatingSearchView.java
private void parseMenu(XmlPullParser parser, AttributeSet attrs)
        throws XmlPullParserException, IOException {

    int eventType = parser.getEventType();
    String tagName;
    boolean lookingForEndOfUnknownTag = false;
    String unknownTagName = null;

    // This loop will skip to the menu start tag
    do {
        if (eventType == XmlPullParser.START_TAG) {
            tagName = parser.getName();
            if (tagName.equals("menu")) {
                // Go to next tag
                eventType = parser.next();
                break;
            }

            throw new RuntimeException("Expecting menu, got " + tagName);
        }
        eventType = parser.next();
    } while (eventType != XmlPullParser.END_DOCUMENT);

    boolean reachedEndOfMenu = false;

    while (!reachedEndOfMenu) {
        switch (eventType) {
            case XmlPullParser.START_TAG:
                if (lookingForEndOfUnknownTag) {
                    break;
                }

                tagName = parser.getName();
                if (tagName.equals("item")) {
                    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.MenuItem);
                    int itemShowAsAction = a.getInt(R.styleable.MenuItem_showAsAction, -1);

                    if((itemShowAsAction & MenuItem.SHOW_AS_ACTION_ALWAYS) != 0) {
                        int itemId = a.getResourceId(R.styleable.MenuItem_android_id, NO_ID);
                        if(itemId != NO_ID) mAlwaysShowingMenu.add(itemId);
                    }
                    a.recycle();
                } else {
                    lookingForEndOfUnknownTag = true;
                    unknownTagName = tagName;
                }
                break;

            case XmlPullParser.END_TAG:
                tagName = parser.getName();
                if (lookingForEndOfUnknownTag && tagName.equals(unknownTagName)) {
                    lookingForEndOfUnknownTag = false;
                    unknownTagName = null;
                } else if (tagName.equals("menu")) {
                    reachedEndOfMenu = true;
                }
                break;

            case XmlPullParser.END_DOCUMENT:
                throw new RuntimeException("Unexpected end of document");
        }

        eventType = parser.next();
    }
}
 
源代码8 项目: FloatingSearchView   文件: FloatingSearchView.java
private void parseMenu(XmlPullParser parser, AttributeSet attrs)
        throws XmlPullParserException, IOException {

    int eventType = parser.getEventType();
    String tagName;
    boolean lookingForEndOfUnknownTag = false;
    String unknownTagName = null;

    // This loop will skip to the menu start tag
    do {
        if (eventType == XmlPullParser.START_TAG) {
            tagName = parser.getName();
            if (tagName.equals("menu")) {
                // Go to next tag
                eventType = parser.next();
                break;
            }

            throw new RuntimeException("Expecting menu, got " + tagName);
        }
        eventType = parser.next();
    } while (eventType != XmlPullParser.END_DOCUMENT);

    boolean reachedEndOfMenu = false;

    while (!reachedEndOfMenu) {
        switch (eventType) {
            case XmlPullParser.START_TAG:
                if (lookingForEndOfUnknownTag) {
                    break;
                }

                tagName = parser.getName();
                if (tagName.equals("item")) {
                    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.MenuItem);
                    int itemShowAsAction = a.getInt(R.styleable.MenuItem_showAsAction, -1);

                    if((itemShowAsAction & MenuItem.SHOW_AS_ACTION_ALWAYS) != 0) {
                        int itemId = a.getResourceId(R.styleable.MenuItem_android_id, NO_ID);
                        if(itemId != NO_ID) mAlwaysShowingMenu.add(itemId);
                    }
                    a.recycle();
                } else {
                    lookingForEndOfUnknownTag = true;
                    unknownTagName = tagName;
                }
                break;

            case XmlPullParser.END_TAG:
                tagName = parser.getName();
                if (lookingForEndOfUnknownTag && tagName.equals(unknownTagName)) {
                    lookingForEndOfUnknownTag = false;
                    unknownTagName = null;
                } else if (tagName.equals("menu")) {
                    reachedEndOfMenu = true;
                }
                break;

            case XmlPullParser.END_DOCUMENT:
                throw new RuntimeException("Unexpected end of document");
        }

        eventType = parser.next();
    }
}