Java Code Examples for android.view.MenuItem.SHOW_AS_ACTION_ALWAYS

The following are Jave code examples for showing how to use SHOW_AS_ACTION_ALWAYS of the android.view.MenuItem class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Hitalk   File: FloatingSearchView.java   View Source Code Vote up 4 votes
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();
    }
}