Example usage for android.content.res TypedArray getResourceId

List of usage examples for android.content.res TypedArray getResourceId

Introduction

In this page you can find the example usage for android.content.res TypedArray getResourceId.

Prototype

@AnyRes
public int getResourceId(@StyleableRes int index, int defValue) 

Source Link

Document

Retrieves the resource identifier for the attribute at index.

Usage

From source file:cn.oddcloud.www.navigationtabbar.ntb.NavigationTabBar.java

@SuppressWarnings("ResourceAsColor")
public NavigationTabBar(final Context context, final AttributeSet attrs, final int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    //Init NTB//w  ww. j av a 2s.  c  o  m

    // Always draw
    setWillNotDraw(false);
    // Speed and fix for pre 17 API
    ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, null);
    setLayerType(LAYER_TYPE_SOFTWARE, null);

    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NavigationTabBar);
    try {
        setIsTitled(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_titled, false));
        setIsBadged(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badged, false));
        setIsScaled(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_scaled, true));
        setIsTinted(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_tinted, true));
        setIsSwiped(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_swiped, true));
        setTitleSize(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_title_size, AUTO_SIZE));
        setIsBadgeUseTypeface(
                typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badge_use_typeface, false));

        setTitleMode(typedArray.getInt(R.styleable.NavigationTabBar_ntb_title_mode, TitleMode.ALL_INDEX));
        setBadgeSize(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_badge_size, AUTO_SIZE));
        setBadgePosition(
                typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_position, BadgePosition.RIGHT_INDEX));
        setBadgeGravity(
                typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_gravity, BadgeGravity.TOP_INDEX));
        setBadgeBgColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_badge_bg_color, AUTO_COLOR));
        setBadgeTitleColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_badge_title_color, AUTO_COLOR));

        setTypeface(typedArray.getString(R.styleable.NavigationTabBar_ntb_typeface));
        setInactiveColor(
                typedArray.getColor(R.styleable.NavigationTabBar_ntb_inactive_color, DEFAULT_INACTIVE_COLOR));
        setActiveColor(
                typedArray.getColor(R.styleable.NavigationTabBar_ntb_active_color, DEFAULT_ACTIVE_COLOR));
        setBgColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_bg_color, DEFAULT_BG_COLOR));
        setAnimationDuration(typedArray.getInteger(R.styleable.NavigationTabBar_ntb_animation_duration,
                DEFAULT_ANIMATION_DURATION));
        setCornersRadius(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_corners_radius, 0.0F));
        setIconSizeFraction(
                typedArray.getFloat(R.styleable.NavigationTabBar_ntb_icon_size_fraction, AUTO_SCALE));

        // Init animator
        mAnimator.setFloatValues(MIN_FRACTION, MAX_FRACTION);
        mAnimator.setInterpolator(new LinearInterpolator());
        mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(final ValueAnimator animation) {
                updateIndicatorPosition((Float) animation.getAnimatedValue());
            }
        });

        // Set preview models
        if (isInEditMode()) {
            // Get preview colors
            String[] previewColors = null;
            try {
                final int previewColorsId = typedArray
                        .getResourceId(R.styleable.NavigationTabBar_ntb_preview_colors, 0);
                previewColors = previewColorsId == 0 ? null
                        : typedArray.getResources().getStringArray(previewColorsId);
            } catch (Exception exception) {
                previewColors = null;
                exception.printStackTrace();
            } finally {
                if (previewColors == null)
                    previewColors = typedArray.getResources().getStringArray(R.array.default_preview);

                for (String previewColor : previewColors)
                    mModels.add(new Model.Builder(null, Color.parseColor(previewColor)).build());
                requestLayout();
            }
        }
    } finally {
        typedArray.recycle();
    }
}

From source file:com.anysoftkeyboard.keyboards.views.AnyKeyboardBaseView.java

private boolean setKeyIconValueFromTheme(KeyboardTheme theme, TypedArray remoteTypeArray, final int localAttrId,
        final int remoteTypedArrayIndex) {
    final int keyCode;
    try {//from   www. j a  v a2 s.  com

        if (localAttrId == R.attr.iconKeyShift) {
            keyCode = KeyCodes.SHIFT;
        } else if (localAttrId == R.attr.iconKeyControl) {
            keyCode = KeyCodes.CTRL;
        } else if (localAttrId == R.attr.iconKeyAction) {
            keyCode = KeyCodes.ENTER;
        } else if (localAttrId == R.attr.iconKeyBackspace) {
            keyCode = KeyCodes.DELETE;
        } else if (localAttrId == R.attr.iconKeyCancel) {
            keyCode = KeyCodes.CANCEL;
        } else if (localAttrId == R.attr.iconKeyGlobe) {
            keyCode = KeyCodes.MODE_ALPHABET;
        } else if (localAttrId == R.attr.iconKeySpace) {
            keyCode = KeyCodes.SPACE;
        } else if (localAttrId == R.attr.iconKeyTab) {
            keyCode = KeyCodes.TAB;
        } else if (localAttrId == R.attr.iconKeyArrowDown) {
            keyCode = KeyCodes.ARROW_DOWN;
        } else if (localAttrId == R.attr.iconKeyArrowLeft) {
            keyCode = KeyCodes.ARROW_LEFT;
        } else if (localAttrId == R.attr.iconKeyArrowRight) {
            keyCode = KeyCodes.ARROW_RIGHT;
        } else if (localAttrId == R.attr.iconKeyArrowUp) {
            keyCode = KeyCodes.ARROW_UP;
        } else if (localAttrId == R.attr.iconKeyInputMoveHome) {
            keyCode = KeyCodes.MOVE_HOME;
        } else if (localAttrId == R.attr.iconKeyInputMoveEnd) {
            keyCode = KeyCodes.MOVE_END;
        } else if (localAttrId == R.attr.iconKeyMic) {
            keyCode = KeyCodes.VOICE_INPUT;
        } else if (localAttrId == R.attr.iconKeySettings) {
            keyCode = KeyCodes.SETTINGS;
        } else if (localAttrId == R.attr.iconKeyCondenseNormal) {
            keyCode = KeyCodes.MERGE_LAYOUT;
        } else if (localAttrId == R.attr.iconKeyCondenseSplit) {
            keyCode = KeyCodes.SPLIT_LAYOUT;
        } else if (localAttrId == R.attr.iconKeyCondenseCompactToRight) {
            keyCode = KeyCodes.COMPACT_LAYOUT_TO_RIGHT;
        } else if (localAttrId == R.attr.iconKeyCondenseCompactToLeft) {
            keyCode = KeyCodes.COMPACT_LAYOUT_TO_LEFT;
        } else {
            keyCode = 0;
        }

        if (keyCode == 0) {
            if (BuildConfig.DEBUG)
                throw new IllegalArgumentException(
                        "No valid keycode for attr " + remoteTypeArray.getResourceId(remoteTypedArrayIndex, 0));
            Log.w(TAG, "No valid keycode for attr %d", remoteTypeArray.getResourceId(remoteTypedArrayIndex, 0));
            return false;
        } else {
            mKeysIconBuilders.put(keyCode,
                    DrawableBuilder.build(theme, remoteTypeArray, remoteTypedArrayIndex));
            Log.d(TAG, "DrawableBuilders size is %d, newest key code %d for resId %d (at index %d)",
                    mKeysIconBuilders.size(), keyCode, remoteTypeArray.getResourceId(remoteTypedArrayIndex, 0),
                    remoteTypedArrayIndex);
            return true;
        }
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:com.anysoftkeyboard.keyboards.views.AnyKeyboardViewBase.java

private boolean setKeyIconValueFromTheme(KeyboardTheme theme, TypedArray remoteTypeArray, final int localAttrId,
        final int remoteTypedArrayIndex) {
    final int keyCode;
    try {/*from  ww w  . j av a2  s.  c  o  m*/
        switch (localAttrId) {
        case R.attr.iconKeyShift:
            keyCode = KeyCodes.SHIFT;
            break;
        case R.attr.iconKeyControl:
            keyCode = KeyCodes.CTRL;
            break;
        case R.attr.iconKeyAction:
            keyCode = KeyCodes.ENTER;
            break;
        case R.attr.iconKeyBackspace:
            keyCode = KeyCodes.DELETE;
            break;
        case R.attr.iconKeyCancel:
            keyCode = KeyCodes.CANCEL;
            break;
        case R.attr.iconKeyGlobe:
            keyCode = KeyCodes.MODE_ALPHABET;
            break;
        case R.attr.iconKeySpace:
            keyCode = KeyCodes.SPACE;
            break;
        case R.attr.iconKeyTab:
            keyCode = KeyCodes.TAB;
            break;
        case R.attr.iconKeyArrowDown:
            keyCode = KeyCodes.ARROW_DOWN;
            break;
        case R.attr.iconKeyArrowLeft:
            keyCode = KeyCodes.ARROW_LEFT;
            break;
        case R.attr.iconKeyArrowRight:
            keyCode = KeyCodes.ARROW_RIGHT;
            break;
        case R.attr.iconKeyArrowUp:
            keyCode = KeyCodes.ARROW_UP;
            break;
        case R.attr.iconKeyInputMoveHome:
            keyCode = KeyCodes.MOVE_HOME;
            break;
        case R.attr.iconKeyInputMoveEnd:
            keyCode = KeyCodes.MOVE_END;
            break;
        case R.attr.iconKeyMic:
            keyCode = KeyCodes.VOICE_INPUT;
            break;
        case R.attr.iconKeySettings:
            keyCode = KeyCodes.SETTINGS;
            break;
        case R.attr.iconKeyCondenseNormal:
            keyCode = KeyCodes.MERGE_LAYOUT;
            break;
        case R.attr.iconKeyCondenseSplit:
            keyCode = KeyCodes.SPLIT_LAYOUT;
            break;
        case R.attr.iconKeyCondenseCompactToRight:
            keyCode = KeyCodes.COMPACT_LAYOUT_TO_RIGHT;
            break;
        case R.attr.iconKeyCondenseCompactToLeft:
            keyCode = KeyCodes.COMPACT_LAYOUT_TO_LEFT;
            break;
        case R.attr.iconKeyClipboardCopy:
            keyCode = KeyCodes.CLIPBOARD_COPY;
            break;
        case R.attr.iconKeyClipboardCut:
            keyCode = KeyCodes.CLIPBOARD_CUT;
            break;
        case R.attr.iconKeyClipboardPaste:
            keyCode = KeyCodes.CLIPBOARD_PASTE;
            break;
        case R.attr.iconKeyClipboardSelect:
            keyCode = KeyCodes.CLIPBOARD_SELECT_ALL;
            break;
        case R.attr.iconKeyQuickText:
            keyCode = KeyCodes.QUICK_TEXT;
            break;
        default:
            keyCode = 0;
        }
        if (keyCode == 0) {
            if (BuildConfig.DEBUG)
                throw new IllegalArgumentException(
                        "No valid keycode for attr " + remoteTypeArray.getResourceId(remoteTypedArrayIndex, 0));
            Logger.w(TAG, "No valid keycode for attr %d",
                    remoteTypeArray.getResourceId(remoteTypedArrayIndex, 0));
            return false;
        } else {
            mKeysIconBuilders.put(keyCode,
                    DrawableBuilder.build(theme, remoteTypeArray, remoteTypedArrayIndex));
            Logger.d(TAG, "DrawableBuilders size is %d, newest key code %d for resId %d (at index %d)",
                    mKeysIconBuilders.size(), keyCode, remoteTypeArray.getResourceId(remoteTypedArrayIndex, 0),
                    remoteTypedArrayIndex);
            return true;
        }
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:android.content.pm.PackageParser.java

private boolean parsePackageItemInfo(Package owner, PackageItemInfo outInfo, String[] outError, String tag,
        TypedArray sa, int nameRes, int labelRes, int iconRes, int logoRes, int bannerRes) {
    String name = sa.getNonConfigurationString(nameRes, 0);
    if (name == null) {
        outError[0] = tag + " does not specify android:name";
        return false;
    }//  www  . jav  a 2  s  .c om

    outInfo.name = buildClassName(owner.applicationInfo.packageName, name, outError);
    if (outInfo.name == null) {
        return false;
    }

    int iconVal = sa.getResourceId(iconRes, 0);
    if (iconVal != 0) {
        outInfo.icon = iconVal;
        outInfo.nonLocalizedLabel = null;
    }

    int logoVal = sa.getResourceId(logoRes, 0);
    if (logoVal != 0) {
        outInfo.logo = logoVal;
    }

    int bannerVal = sa.getResourceId(bannerRes, 0);
    if (bannerVal != 0) {
        outInfo.banner = bannerVal;
    }

    TypedValue v = sa.peekValue(labelRes);
    if (v != null && (outInfo.labelRes = v.resourceId) == 0) {
        outInfo.nonLocalizedLabel = v.coerceToString();
    }

    outInfo.packageName = owner.packageName;

    return true;
}

From source file:com.arlib.floatingsearchview.FloatingSearchView.java

private void applyXmlAttributes(AttributeSet attrs) {

    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.FloatingSearchView);

    try {// w w w  . j  a  v a 2 s  .  co  m

        setDismissOnOutsideClick(true);

        int searchBarWidth = a.getDimensionPixelSize(
                R.styleable.FloatingSearchView_floatingSearch_searchBarWidth,
                ViewGroup.LayoutParams.MATCH_PARENT);

        mQuerySection.getLayoutParams().width = searchBarWidth;
        mDivider.getLayoutParams().width = searchBarWidth;
        mSuggestionListContainer.getLayoutParams().width = searchBarWidth;

        int searchBarLeftMargin = a.getDimensionPixelSize(
                R.styleable.FloatingSearchView_floatingSearch_searchBarMarginLeft,
                ATTRS_SEARCH_BAR_MARGIN_DEFAULT);
        int searchBarTopMargin = a.getDimensionPixelSize(
                R.styleable.FloatingSearchView_floatingSearch_searchBarMarginTop,
                ATTRS_SEARCH_BAR_MARGIN_DEFAULT);
        int searchBarRightMargin = a.getDimensionPixelSize(
                R.styleable.FloatingSearchView_floatingSearch_searchBarMarginRight,
                ATTRS_SEARCH_BAR_MARGIN_DEFAULT);

        LayoutParams querySectionLP = (LayoutParams) mQuerySection.getLayoutParams();
        LayoutParams dividerLP = (LayoutParams) mDivider.getLayoutParams();
        LinearLayout.LayoutParams suggestListSectionLP = (LinearLayout.LayoutParams) mSuggestionsSection
                .getLayoutParams();

        querySectionLP.setMargins(searchBarLeftMargin, searchBarTopMargin, searchBarRightMargin, 0);
        dividerLP.setMargins(searchBarLeftMargin, 0, searchBarRightMargin,
                ((MarginLayoutParams) mDivider.getLayoutParams()).bottomMargin);
        suggestListSectionLP.setMargins(searchBarLeftMargin, 0, searchBarRightMargin, 0);

        mQuerySection.setLayoutParams(querySectionLP);
        mDivider.setLayoutParams(dividerLP);
        mSuggestionsSection.setLayoutParams(suggestListSectionLP);

        setSearchHint(a.getString(R.styleable.FloatingSearchView_floatingSearch_searchHint));

        setShowHintWhenNotFocused(
                a.getBoolean(R.styleable.FloatingSearchView_floatingSearch_showSearchHintWhenNotFocused,
                        ATTRS_SEARCH_BAR_SHOW_SEARCH_HINT_NOT_FOCUSED_DEFAULT));

        setLeftShowMenu(a.getBoolean(R.styleable.FloatingSearchView_floatingSearch_showMenuAction,
                ATTRS_SEARCH_BAR_SHOW_MENU_ACTION_DEFAULT));

        setShowVoiceInput(a.getBoolean(R.styleable.FloatingSearchView_floatingSearch_showVoiceInput,
                ATTRS_SEARCH_BAR_SHOW_VOICE_ACTION_DEFAULT));

        setShowSearchKey(a.getBoolean(R.styleable.FloatingSearchView_floatingSearch_showSearchKey,
                ATTRS_SEARCH_BAR_SHOW_SEARCH_KEY_DEFAULT));

        setVoiceSearchHint(a.getString(R.styleable.FloatingSearchView_floatingSearch_voiceRecHint));

        setDismissOnOutsideClick(
                a.getBoolean(R.styleable.FloatingSearchView_floatingSearch_dismissOnOutsideTouch,
                        ATTRS_DISMISS_ON_OUTSIDE_TOUCH_DEFAULT));

        setShowOverflowMenu(a.getBoolean(R.styleable.FloatingSearchView_floatingSearch_showOverFlowMenu,
                ATTRS_SHOW_OVERFLOW_MENU_DEFAULT));

        setSuggestionItemTextSize(
                a.getDimensionPixelSize(R.styleable.FloatingSearchView_floatingSearch_searchSuggestionTextSize,
                        Util.spToPx(ATTRS_SUGGESTION_TEXT_SIZE_SP_DEFAULT)));

        if (a.hasValue(R.styleable.FloatingSearchView_floatingSearch_menu)) {
            inflateOverflowMenu(a.getResourceId(R.styleable.FloatingSearchView_floatingSearch_menu, 0));
        }

        setHideOverflowMenuWhenFocused(
                a.getBoolean(R.styleable.FloatingSearchView_floatingSearch_hideOverflowMenuWhenFocused,
                        ATTRS_HIDE_OVERFLOW_MENU_FOCUSED_DEFAULT));

    } finally {

        a.recycle();
    }
}

From source file:android.content.pm.PackageParser.java

private boolean parseIntent(Resources res, XmlPullParser parser, AttributeSet attrs, boolean allowGlobs,
        boolean allowAutoVerify, IntentInfo outInfo, String[] outError)
        throws XmlPullParserException, IOException {

    TypedArray sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestIntentFilter);

    int priority = sa.getInt(com.android.internal.R.styleable.AndroidManifestIntentFilter_priority, 0);
    outInfo.setPriority(priority);//from   w  ww . j a v  a 2  s.  c om

    TypedValue v = sa.peekValue(com.android.internal.R.styleable.AndroidManifestIntentFilter_label);
    if (v != null && (outInfo.labelRes = v.resourceId) == 0) {
        outInfo.nonLocalizedLabel = v.coerceToString();
    }

    outInfo.icon = sa.getResourceId(com.android.internal.R.styleable.AndroidManifestIntentFilter_icon, 0);

    outInfo.logo = sa.getResourceId(com.android.internal.R.styleable.AndroidManifestIntentFilter_logo, 0);

    outInfo.banner = sa.getResourceId(com.android.internal.R.styleable.AndroidManifestIntentFilter_banner, 0);

    if (allowAutoVerify) {
        outInfo.setAutoVerify(
                sa.getBoolean(com.android.internal.R.styleable.AndroidManifestIntentFilter_autoVerify, false));
    }

    sa.recycle();

    int outerDepth = parser.getDepth();
    int type;
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
            && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
        if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
            continue;
        }

        String nodeName = parser.getName();
        if (nodeName.equals("action")) {
            String value = attrs.getAttributeValue(ANDROID_RESOURCES, "name");
            if (value == null || value == "") {
                outError[0] = "No value supplied for <android:name>";
                return false;
            }
            XmlUtils.skipCurrentTag(parser);

            outInfo.addAction(value);
        } else if (nodeName.equals("category")) {
            String value = attrs.getAttributeValue(ANDROID_RESOURCES, "name");
            if (value == null || value == "") {
                outError[0] = "No value supplied for <android:name>";
                return false;
            }
            XmlUtils.skipCurrentTag(parser);

            outInfo.addCategory(value);

        } else if (nodeName.equals("data")) {
            sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestData);

            String str = sa.getNonConfigurationString(
                    com.android.internal.R.styleable.AndroidManifestData_mimeType, 0);
            if (str != null) {
                try {
                    outInfo.addDataType(str);
                } catch (IntentFilter.MalformedMimeTypeException e) {
                    outError[0] = e.toString();
                    sa.recycle();
                    return false;
                }
            }

            str = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestData_scheme, 0);
            if (str != null) {
                outInfo.addDataScheme(str);
            }

            str = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestData_ssp, 0);
            if (str != null) {
                outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_LITERAL);
            }

            str = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestData_sspPrefix,
                    0);
            if (str != null) {
                outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_PREFIX);
            }

            str = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestData_sspPattern,
                    0);
            if (str != null) {
                if (!allowGlobs) {
                    outError[0] = "sspPattern not allowed here; ssp must be literal";
                    return false;
                }
                outInfo.addDataSchemeSpecificPart(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
            }

            String host = sa
                    .getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestData_host, 0);
            String port = sa
                    .getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestData_port, 0);
            if (host != null) {
                outInfo.addDataAuthority(host, port);
            }

            str = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestData_path, 0);
            if (str != null) {
                outInfo.addDataPath(str, PatternMatcher.PATTERN_LITERAL);
            }

            str = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestData_pathPrefix,
                    0);
            if (str != null) {
                outInfo.addDataPath(str, PatternMatcher.PATTERN_PREFIX);
            }

            str = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestData_pathPattern,
                    0);
            if (str != null) {
                if (!allowGlobs) {
                    outError[0] = "pathPattern not allowed here; path must be literal";
                    return false;
                }
                outInfo.addDataPath(str, PatternMatcher.PATTERN_SIMPLE_GLOB);
            }

            sa.recycle();
            XmlUtils.skipCurrentTag(parser);
        } else if (!RIGID_PARSER) {
            Slog.w(TAG, "Unknown element under <intent-filter>: " + parser.getName() + " at "
                    + mArchiveSourcePath + " " + parser.getPositionDescription());
            XmlUtils.skipCurrentTag(parser);
        } else {
            outError[0] = "Bad element under <intent-filter>: " + parser.getName();
            return false;
        }
    }

    outInfo.hasDefault = outInfo.hasCategory(Intent.CATEGORY_DEFAULT);

    if (DEBUG_PARSER) {
        final StringBuilder cats = new StringBuilder("Intent d=");
        cats.append(outInfo.hasDefault);
        cats.append(", cat=");

        final Iterator<String> it = outInfo.categoriesIterator();
        if (it != null) {
            while (it.hasNext()) {
                cats.append(' ');
                cats.append(it.next());
            }
        }
        Slog.d(TAG, cats.toString());
    }

    return true;
}

From source file:co.ceryle.radiorealbutton.library.RadioRealButtonGroup.java

private void getAttributes(AttributeSet attrs) {
    TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.RadioRealButtonGroup);

    bottomLineColor = ta.getColor(R.styleable.RadioRealButtonGroup_rrbg_bottomLineColor, Color.GRAY);
    bottomLineSize = ta.getDimensionPixelSize(R.styleable.RadioRealButtonGroup_rrbg_bottomLineSize, 0);
    bottomLineBringToFront = ta.getBoolean(R.styleable.RadioRealButtonGroup_rrbg_bottomLineBringToFront, false);
    bottomLineRadius = ta.getDimensionPixelSize(R.styleable.RadioRealButtonGroup_rrbg_bottomLineRadius, 0);

    selectorColor = ta.getColor(R.styleable.RadioRealButtonGroup_rrbg_selectorColor, Color.GRAY);
    selectorBringToFront = ta.getBoolean(R.styleable.RadioRealButtonGroup_rrbg_selectorBringToFront, false);
    selectorAboveOfBottomLine = ta.getBoolean(R.styleable.RadioRealButtonGroup_rrbg_selectorAboveOfBottomLine,
            false);/*from  w  w  w  . j  a va 2 s.co m*/
    selectorSize = ta.getDimensionPixelSize(R.styleable.RadioRealButtonGroup_rrbg_selectorSize, 12);
    selectorRadius = ta.getDimensionPixelSize(R.styleable.RadioRealButtonGroup_rrbg_selectorRadius, 0);

    animateSelector = ta.getInt(R.styleable.RadioRealButtonGroup_rrbg_animateSelector, 0);
    animateSelectorDuration = ta.getInt(R.styleable.RadioRealButtonGroup_rrbg_animateSelector_duration, 500);
    animateSelectorDelay = ta.getInt(R.styleable.RadioRealButtonGroup_rrbg_animateSelector_delay, 0);

    dividerSize = ta.getDimensionPixelSize(R.styleable.RadioRealButtonGroup_rrbg_dividerSize, 0);
    boolean hasDividerSize = ta.hasValue(R.styleable.RadioRealButtonGroup_rrbg_dividerSize);
    dividerRadius = ta.getDimensionPixelSize(R.styleable.RadioRealButtonGroup_rrbg_dividerRadius, 0);
    dividerPadding = ta.getDimensionPixelSize(R.styleable.RadioRealButtonGroup_rrbg_dividerPadding, 30);
    dividerColor = ta.getColor(R.styleable.RadioRealButtonGroup_rrbg_dividerColor, Color.TRANSPARENT);
    dividerBackgroundColor = ta.getColor(R.styleable.RadioRealButtonGroup_rrbg_dividerBackgroundColor,
            Color.WHITE);
    hasDividerBackgroundColor = ta.hasValue(R.styleable.RadioRealButtonGroup_rrbg_dividerBackgroundColor);

    selectorDividerSize = ta.getDimensionPixelSize(R.styleable.RadioRealButtonGroup_rrbg_selectorDividerSize,
            dividerSize);
    if (!hasDividerSize) {
        dividerSize = selectorDividerSize;
    }
    selectorDividerRadius = ta
            .getDimensionPixelSize(R.styleable.RadioRealButtonGroup_rrbg_selectorDividerRadius, 0);
    selectorDividerPadding = ta
            .getDimensionPixelSize(R.styleable.RadioRealButtonGroup_rrbg_selectorDividerPadding, 0);
    selectorDividerColor = ta.getColor(R.styleable.RadioRealButtonGroup_rrbg_selectorDividerColor,
            Color.TRANSPARENT);

    radius = ta.getDimension(R.styleable.RadioRealButtonGroup_rrbg_radius, 0);

    animateImages = ta.getInt(R.styleable.RadioRealButtonGroup_rrbg_animateDrawables_enter, 0);
    hasAnimateImages = ta.hasValue(R.styleable.RadioRealButtonGroup_rrbg_animateDrawables_enter);
    animateImagesExit = ta.getInt(R.styleable.RadioRealButtonGroup_rrbg_animateDrawables_exit, 0);
    animateImagesDuration = ta.getInt(R.styleable.RadioRealButtonGroup_rrbg_animateDrawables_enterDuration,
            500);
    animateImagesExitDuration = ta.getInt(R.styleable.RadioRealButtonGroup_rrbg_animateDrawables_exitDuration,
            100);
    animateImagesScale = ta.getFloat(R.styleable.RadioRealButtonGroup_rrbg_animateDrawables_scale, 1.2f);

    animateTexts = ta.getInt(R.styleable.RadioRealButtonGroup_rrbg_animateTexts_enter, 0);
    hasAnimateTexts = ta.hasValue(R.styleable.RadioRealButtonGroup_rrbg_animateTexts_enter);
    animateTextsExit = ta.getInt(R.styleable.RadioRealButtonGroup_rrbg_animateTexts_exit, 0);
    animateTextsDuration = ta.getInt(R.styleable.RadioRealButtonGroup_rrbg_animateTexts_enterDuration, 500);
    animateTextsExitDuration = ta.getInt(R.styleable.RadioRealButtonGroup_rrbg_animateTexts_exitDuration, 100);
    animateTextsScale = ta.getFloat(R.styleable.RadioRealButtonGroup_rrbg_animateTexts_scale, 1.2f);

    lastPosition = initialPosition = ta.getInt(R.styleable.RadioRealButtonGroup_rrbg_checkedPosition, -1);
    checkedButtonId = ta.getResourceId(R.styleable.RadioRealButtonGroup_rrbg_checkedButton, NO_ID);

    buttonPadding = ta.getDimensionPixelSize(R.styleable.RadioRealButtonGroup_rrbg_buttonsPadding, 0);
    buttonPaddingLeft = ta.getDimensionPixelSize(R.styleable.RadioRealButtonGroup_rrbg_buttonsPaddingLeft, 0);
    buttonPaddingRight = ta.getDimensionPixelSize(R.styleable.RadioRealButtonGroup_rrbg_buttonsPaddingRight, 0);
    buttonPaddingTop = ta.getDimensionPixelSize(R.styleable.RadioRealButtonGroup_rrbg_buttonsPaddingTop, 0);
    buttonPaddingBottom = ta.getDimensionPixelSize(R.styleable.RadioRealButtonGroup_rrbg_buttonsPaddingBottom,
            0);

    hasPadding = ta.hasValue(R.styleable.RadioRealButtonGroup_rrbg_buttonsPadding);
    hasPaddingLeft = ta.hasValue(R.styleable.RadioRealButtonGroup_rrbg_buttonsPaddingLeft);
    hasPaddingRight = ta.hasValue(R.styleable.RadioRealButtonGroup_rrbg_buttonsPaddingRight);
    hasPaddingTop = ta.hasValue(R.styleable.RadioRealButtonGroup_rrbg_buttonsPaddingTop);
    hasPaddingBottom = ta.hasValue(R.styleable.RadioRealButtonGroup_rrbg_buttonsPaddingBottom);

    groupBackgroundColor = ta.getColor(R.styleable.RadioRealButtonGroup_rrbg_backgroundColor, Color.WHITE);

    selectorTop = ta.getBoolean(R.styleable.RadioRealButtonGroup_rrbg_selectorTop, false);
    selectorBottom = ta.getBoolean(R.styleable.RadioRealButtonGroup_rrbg_selectorBottom, true);

    borderSize = ta.getDimensionPixelSize(R.styleable.RadioRealButtonGroup_rrbg_borderSize,
            ConversionHelper.dpToPx(getContext(), 1));
    borderColor = ta.getColor(R.styleable.RadioRealButtonGroup_rrbg_borderColor, Color.BLACK);

    boolean hasBorderSize = ta.hasValue(R.styleable.RadioRealButtonGroup_rrbg_borderSize);
    boolean hasBorderColor = ta.hasValue(R.styleable.RadioRealButtonGroup_rrbg_borderColor);
    hasBorder = hasBorderColor || hasBorderSize;

    clickable = ta.getBoolean(R.styleable.RadioRealButtonGroup_android_clickable, true);
    hasClickable = ta.hasValue(R.styleable.RadioRealButtonGroup_android_clickable);
    enabled = ta.getBoolean(R.styleable.RadioRealButtonGroup_android_enabled, true);
    hasEnabled = ta.hasValue(R.styleable.RadioRealButtonGroup_android_enabled);

    animationType = ta.getInt(R.styleable.RadioRealButtonGroup_rrbg_selectorAnimationType, 0);
    enableDeselection = ta.getBoolean(R.styleable.RadioRealButtonGroup_rrbg_enableDeselection, false);

    hasAnimation = ta.getBoolean(R.styleable.RadioRealButtonGroup_rrbg_animate, true);

    selectorFullSize = ta.getBoolean(R.styleable.RadioRealButtonGroup_rrbg_selectorFullSize, false);

    ta.recycle();
}

From source file:com.facebook.litho.InternalNode.java

void applyAttributes(TypedArray a) {
    for (int i = 0, size = a.getIndexCount(); i < size; i++) {
        final int attr = a.getIndex(i);

        if (attr == R.styleable.ComponentLayout_android_layout_width) {
            int width = a.getLayoutDimension(attr, -1);
            // We don't support WRAP_CONTENT or MATCH_PARENT so no-op for them
            if (width >= 0) {
                widthPx(width);/*from  w ww  . j  a  va2s.c  o m*/
            }
        } else if (attr == R.styleable.ComponentLayout_android_layout_height) {
            int height = a.getLayoutDimension(attr, -1);
            // We don't support WRAP_CONTENT or MATCH_PARENT so no-op for them
            if (height >= 0) {
                heightPx(height);
            }
        } else if (attr == R.styleable.ComponentLayout_android_paddingLeft) {
            paddingPx(LEFT, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_paddingTop) {
            paddingPx(TOP, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_paddingRight) {
            paddingPx(RIGHT, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_paddingBottom) {
            paddingPx(BOTTOM, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_paddingStart && SUPPORTS_RTL) {
            paddingPx(START, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_paddingEnd && SUPPORTS_RTL) {
            paddingPx(END, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_padding) {
            paddingPx(ALL, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_layout_marginLeft) {
            marginPx(LEFT, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_layout_marginTop) {
            marginPx(TOP, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_layout_marginRight) {
            marginPx(RIGHT, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_layout_marginBottom) {
            marginPx(BOTTOM, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_layout_marginStart && SUPPORTS_RTL) {
            marginPx(START, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_layout_marginEnd && SUPPORTS_RTL) {
            marginPx(END, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_layout_margin) {
            marginPx(ALL, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_importantForAccessibility
                && SDK_INT >= JELLY_BEAN) {
            importantForAccessibility(a.getInt(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_android_duplicateParentState) {
            duplicateParentState(a.getBoolean(attr, false));
        } else if (attr == R.styleable.ComponentLayout_android_background) {
            if (TypedArrayUtils.isColorAttribute(a, R.styleable.ComponentLayout_android_background)) {
                backgroundColor(a.getColor(attr, 0));
            } else {
                backgroundRes(a.getResourceId(attr, -1));
            }
        } else if (attr == R.styleable.ComponentLayout_android_foreground) {
            if (TypedArrayUtils.isColorAttribute(a, R.styleable.ComponentLayout_android_foreground)) {
                foregroundColor(a.getColor(attr, 0));
            } else {
                foregroundRes(a.getResourceId(attr, -1));
            }
        } else if (attr == R.styleable.ComponentLayout_android_contentDescription) {
            contentDescription(a.getString(attr));
        } else if (attr == R.styleable.ComponentLayout_flex_direction) {
            flexDirection(YogaFlexDirection.fromInt(a.getInteger(attr, 0)));
        } else if (attr == R.styleable.ComponentLayout_flex_wrap) {
            wrap(YogaWrap.fromInt(a.getInteger(attr, 0)));
        } else if (attr == R.styleable.ComponentLayout_flex_justifyContent) {
            justifyContent(YogaJustify.fromInt(a.getInteger(attr, 0)));
        } else if (attr == R.styleable.ComponentLayout_flex_alignItems) {
            alignItems(YogaAlign.fromInt(a.getInteger(attr, 0)));
        } else if (attr == R.styleable.ComponentLayout_flex_alignSelf) {
            alignSelf(YogaAlign.fromInt(a.getInteger(attr, 0)));
        } else if (attr == R.styleable.ComponentLayout_flex_positionType) {
            positionType(YogaPositionType.fromInt(a.getInteger(attr, 0)));
        } else if (attr == R.styleable.ComponentLayout_flex) {
            final float flex = a.getFloat(attr, -1);
            if (flex >= 0f) {
                flex(flex);
            }
        } else if (attr == R.styleable.ComponentLayout_flex_left) {
            positionPx(LEFT, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_flex_top) {
            positionPx(TOP, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_flex_right) {
            positionPx(RIGHT, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_flex_bottom) {
            positionPx(BOTTOM, a.getDimensionPixelOffset(attr, 0));
        } else if (attr == R.styleable.ComponentLayout_flex_layoutDirection) {
            final int layoutDirection = a.getInteger(attr, -1);
            layoutDirection(YogaDirection.fromInt(layoutDirection));
        }
    }
}

From source file:com.arlib.floatingsearchview.FloatingSearchView.java

private void applyXmlAttributes(AttributeSet attrs) {

    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.FloatingSearchView);

    try {/*from  ww w.j av  a2 s  . c  o m*/

        int searchBarWidth = a.getDimensionPixelSize(
                R.styleable.FloatingSearchView_floatingSearch_searchBarWidth,
                ViewGroup.LayoutParams.MATCH_PARENT);
        mQuerySection.getLayoutParams().width = searchBarWidth;
        mDivider.getLayoutParams().width = searchBarWidth;
        mSuggestionListContainer.getLayoutParams().width = searchBarWidth;
        int searchBarLeftMargin = a.getDimensionPixelSize(
                R.styleable.FloatingSearchView_floatingSearch_searchBarMarginLeft,
                ATTRS_SEARCH_BAR_MARGIN_DEFAULT);
        int searchBarTopMargin = a.getDimensionPixelSize(
                R.styleable.FloatingSearchView_floatingSearch_searchBarMarginTop,
                ATTRS_SEARCH_BAR_MARGIN_DEFAULT);
        int searchBarRightMargin = a.getDimensionPixelSize(
                R.styleable.FloatingSearchView_floatingSearch_searchBarMarginRight,
                ATTRS_SEARCH_BAR_MARGIN_DEFAULT);
        LayoutParams querySectionLP = (LayoutParams) mQuerySection.getLayoutParams();
        LayoutParams dividerLP = (LayoutParams) mDivider.getLayoutParams();
        LinearLayout.LayoutParams suggestListSectionLP = (LinearLayout.LayoutParams) mSuggestionsSection
                .getLayoutParams();
        int cardPadding = Util.dpToPx(CARD_VIEW_TOP_BOTTOM_SHADOW_HEIGHT);
        querySectionLP.setMargins(searchBarLeftMargin, searchBarTopMargin, searchBarRightMargin, 0);
        dividerLP.setMargins(searchBarLeftMargin + cardPadding, 0, searchBarRightMargin + cardPadding,
                ((MarginLayoutParams) mDivider.getLayoutParams()).bottomMargin);
        suggestListSectionLP.setMargins(searchBarLeftMargin, 0, searchBarRightMargin, 0);
        mQuerySection.setLayoutParams(querySectionLP);
        mDivider.setLayoutParams(dividerLP);
        mSuggestionsSection.setLayoutParams(suggestListSectionLP);

        setQueryTextSize(
                a.getDimensionPixelSize(R.styleable.FloatingSearchView_floatingSearch_searchInputTextSize,
                        ATTRS_QUERY_TEXT_SIZE_SP_DEFAULT));
        setSearchHint(a.getString(R.styleable.FloatingSearchView_floatingSearch_searchHint));
        setShowSearchKey(a.getBoolean(R.styleable.FloatingSearchView_floatingSearch_showSearchKey,
                ATTRS_SEARCH_BAR_SHOW_SEARCH_KEY_DEFAULT));
        setCloseSearchOnKeyboardDismiss(
                a.getBoolean(R.styleable.FloatingSearchView_floatingSearch_close_search_on_keyboard_dismiss,
                        ATTRS_DISMISS_ON_KEYBOARD_DISMISS_DEFAULT));
        setDismissOnOutsideClick(
                a.getBoolean(R.styleable.FloatingSearchView_floatingSearch_dismissOnOutsideTouch,
                        ATTRS_DISMISS_ON_OUTSIDE_TOUCH_DEFAULT));
        setSuggestionItemTextSize(
                a.getDimensionPixelSize(R.styleable.FloatingSearchView_floatingSearch_searchSuggestionTextSize,
                        Util.spToPx(ATTRS_SUGGESTION_TEXT_SIZE_SP_DEFAULT)));
        //noinspection ResourceType
        mLeftActionMode = a.getInt(R.styleable.FloatingSearchView_floatingSearch_leftActionMode,
                ATTRS_SEARCH_BAR_LEFT_ACTION_MODE_DEFAULT);
        if (a.hasValue(R.styleable.FloatingSearchView_floatingSearch_menu)) {
            mMenuId = a.getResourceId(R.styleable.FloatingSearchView_floatingSearch_menu, -1);
        }
        setDimBackground(a.getBoolean(R.styleable.FloatingSearchView_floatingSearch_dimBackground,
                ATTRS_SHOW_DIM_BACKGROUND_DEFAULT));
        setShowMoveUpSuggestion(a.getBoolean(R.styleable.FloatingSearchView_floatingSearch_showMoveSuggestionUp,
                ATTRS_SHOW_MOVE_UP_SUGGESTION_DEFAULT));
        this.mSuggestionSectionAnimDuration = a.getInt(
                R.styleable.FloatingSearchView_floatingSearch_suggestionsListAnimDuration,
                ATTRS_SUGGESTION_ANIM_DURATION_DEFAULT);
        setBackgroundColor(a.getColor(R.styleable.FloatingSearchView_floatingSearch_backgroundColor,
                Util.getColor(getContext(), R.color.background)));
        setLeftActionIconColor(a.getColor(R.styleable.FloatingSearchView_floatingSearch_leftActionColor,
                Util.getColor(getContext(), R.color.left_action_icon)));
        setActionMenuOverflowColor(
                a.getColor(R.styleable.FloatingSearchView_floatingSearch_actionMenuOverflowColor,
                        Util.getColor(getContext(), R.color.overflow_icon_color)));
        setMenuItemIconColor(a.getColor(R.styleable.FloatingSearchView_floatingSearch_menuItemIconColor,
                Util.getColor(getContext(), R.color.menu_icon_color)));
        setDividerColor(a.getColor(R.styleable.FloatingSearchView_floatingSearch_dividerColor,
                Util.getColor(getContext(), R.color.divider)));
        setClearBtnColor(a.getColor(R.styleable.FloatingSearchView_floatingSearch_clearBtnColor,
                Util.getColor(getContext(), R.color.clear_btn_color)));
        int viewTextColor = a.getColor(R.styleable.FloatingSearchView_floatingSearch_viewTextColor,
                Util.getColor(getContext(), R.color.dark_gray));
        setViewTextColor(viewTextColor);
        setQueryTextColor(a.getColor(R.styleable.FloatingSearchView_floatingSearch_viewSearchInputTextColor,
                viewTextColor));
        setSuggestionsTextColor(a.getColor(
                R.styleable.FloatingSearchView_floatingSearch_viewSuggestionItemTextColor, viewTextColor));
        setHintTextColor(a.getColor(R.styleable.FloatingSearchView_floatingSearch_hintTextColor,
                Util.getColor(getContext(), R.color.hint_color)));
        setSuggestionRightIconColor(
                a.getColor(R.styleable.FloatingSearchView_floatingSearch_suggestionRightIconColor,
                        Util.getColor(getContext(), R.color.gray_active_icon)));
    } finally {
        a.recycle();
    }
}

From source file:android.content.pm.PackageParser.java

private PermissionGroup parsePermissionGroup(Package owner, int flags, Resources res, XmlPullParser parser,
        AttributeSet attrs, String[] outError) throws XmlPullParserException, IOException {
    PermissionGroup perm = new PermissionGroup(owner);

    TypedArray sa = res.obtainAttributes(attrs,
            com.android.internal.R.styleable.AndroidManifestPermissionGroup);

    if (!parsePackageItemInfo(owner, perm.info, outError, "<permission-group>", sa,
            com.android.internal.R.styleable.AndroidManifestPermissionGroup_name,
            com.android.internal.R.styleable.AndroidManifestPermissionGroup_label,
            com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon,
            com.android.internal.R.styleable.AndroidManifestPermissionGroup_logo,
            com.android.internal.R.styleable.AndroidManifestPermissionGroup_banner)) {
        sa.recycle();//from  w w  w.jav  a  2s  .  co m
        mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
        return null;
    }

    perm.info.descriptionRes = sa
            .getResourceId(com.android.internal.R.styleable.AndroidManifestPermissionGroup_description, 0);
    perm.info.flags = sa
            .getInt(com.android.internal.R.styleable.AndroidManifestPermissionGroup_permissionGroupFlags, 0);
    perm.info.priority = sa.getInt(com.android.internal.R.styleable.AndroidManifestPermissionGroup_priority, 0);
    if (perm.info.priority > 0 && (flags & PARSE_IS_SYSTEM) == 0) {
        perm.info.priority = 0;
    }

    sa.recycle();

    if (!parseAllMetaData(res, parser, attrs, "<permission-group>", perm, outError)) {
        mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
        return null;
    }

    owner.permissionGroups.add(perm);

    return perm;
}