Example usage for android.content.res TypedArray getInteger

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

Introduction

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

Prototype

public int getInteger(@StyleableRes int index, int defValue) 

Source Link

Document

Retrieve the integer value for the attribute at index.

Usage

From source file:com.gigamole.library.ntb.NavigationTabBar.java

public NavigationTabBar(final Context context, final AttributeSet attrs, final int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    //Init NTB/* w  ww.j  a  v a2 s.  c o  m*/

    // Always draw
    setWillNotDraw(false);
    // More speed!
    setLayerType(LAYER_TYPE_HARDWARE, 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));
        setIsBadgeUseTypeface(
                typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badge_use_typeface, false));

        setTitleMode(typedArray.getInt(R.styleable.NavigationTabBar_ntb_title_mode, TitleMode.ALL_INDEX));
        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, 0));
        setBadgeTitleColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_badge_title_color, 0));

        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));
        setAnimationDuration(typedArray.getInteger(R.styleable.NavigationTabBar_ntb_animation_duration,
                DEFAULT_ANIMATION_DURATION));
        setCornersRadius(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_corners_radius, 0.0F));

        // 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.android.contacts.list.ContactListItemView.java

public ContactListItemView(Context context, AttributeSet attrs) {
    super(context, attrs);

    TypedArray a;

    if (R.styleable.ContactListItemView != null) {
        // Read all style values
        a = getContext().obtainStyledAttributes(attrs, R.styleable.ContactListItemView);
        mPreferredHeight = a.getDimensionPixelSize(R.styleable.ContactListItemView_list_item_height,
                mPreferredHeight);//ww  w .  j a  va  2s  . c  om
        mActivatedBackgroundDrawable = a.getDrawable(R.styleable.ContactListItemView_activated_background);

        mGapBetweenImageAndText = a.getDimensionPixelOffset(
                R.styleable.ContactListItemView_list_item_gap_between_image_and_text, mGapBetweenImageAndText);
        mGapBetweenIndexerAndImage = a.getDimensionPixelOffset(
                R.styleable.ContactListItemView_list_item_gap_between_indexer_and_image,
                mGapBetweenIndexerAndImage);
        mGapBetweenLabelAndData = a.getDimensionPixelOffset(
                R.styleable.ContactListItemView_list_item_gap_between_label_and_data, mGapBetweenLabelAndData);
        mPresenceIconMargin = a.getDimensionPixelOffset(
                R.styleable.ContactListItemView_list_item_presence_icon_margin, mPresenceIconMargin);
        mPresenceIconSize = a.getDimensionPixelOffset(
                R.styleable.ContactListItemView_list_item_presence_icon_size, mPresenceIconSize);
        mDefaultPhotoViewSize = a.getDimensionPixelOffset(R.styleable.ContactListItemView_list_item_photo_size,
                mDefaultPhotoViewSize);
        mTextIndent = a.getDimensionPixelOffset(R.styleable.ContactListItemView_list_item_text_indent,
                mTextIndent);
        mTextOffsetTop = a.getDimensionPixelOffset(R.styleable.ContactListItemView_list_item_text_offset_top,
                mTextOffsetTop);
        mAvatarOffsetTop = a.getDimensionPixelOffset(
                R.styleable.ContactListItemView_list_item_avatar_offset_top, mAvatarOffsetTop);
        mDataViewWidthWeight = a.getInteger(R.styleable.ContactListItemView_list_item_data_width_weight,
                mDataViewWidthWeight);
        mLabelViewWidthWeight = a.getInteger(R.styleable.ContactListItemView_list_item_label_width_weight,
                mLabelViewWidthWeight);
        mNameTextViewTextColor = a.getColor(R.styleable.ContactListItemView_list_item_name_text_color,
                mNameTextViewTextColor);
        mNameTextViewTextSize = (int) a.getDimension(R.styleable.ContactListItemView_list_item_name_text_size,
                (int) getResources().getDimension(R.dimen.contact_browser_list_item_text_size));
        mVideoCallIconSize = a.getDimensionPixelOffset(
                R.styleable.ContactListItemView_list_item_video_call_icon_size, mVideoCallIconSize);
        mVideoCallIconMargin = a.getDimensionPixelOffset(
                R.styleable.ContactListItemView_list_item_video_call_icon_margin, mVideoCallIconMargin);

        setPaddingRelative(a.getDimensionPixelOffset(R.styleable.ContactListItemView_list_item_padding_left, 0),
                a.getDimensionPixelOffset(R.styleable.ContactListItemView_list_item_padding_top, 0),
                a.getDimensionPixelOffset(R.styleable.ContactListItemView_list_item_padding_right, 0),
                a.getDimensionPixelOffset(R.styleable.ContactListItemView_list_item_padding_bottom, 0));

        a.recycle();
    }

    mTextHighlighter = new TextHighlighter(Typeface.BOLD);

    if (R.styleable.Theme != null) {
        a = getContext().obtainStyledAttributes(R.styleable.Theme);
        mSecondaryTextColor = a.getColorStateList(R.styleable.Theme_android_textColorSecondary);
        a.recycle();
    }

    mHeaderWidth = getResources().getDimensionPixelSize(R.dimen.contact_list_section_header_width);

    if (mActivatedBackgroundDrawable != null) {
        mActivatedBackgroundDrawable.setCallback(this);
    }

    mNameHighlightSequence = new ArrayList<HighlightSequence>();
    mNumberHighlightSequence = new ArrayList<HighlightSequence>();

    setLayoutDirection(View.LAYOUT_DIRECTION_LOCALE);
}

From source file:com.bulletnoid.android.widget.StaggeredGridView.StaggeredGridView2.java

public StaggeredGridView2(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    if (attrs != null) {
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.StgStaggeredGridView);
        mColCount = a.getInteger(R.styleable.StgStaggeredGridView_stgNumColumns, 2);
        mDrawSelectorOnTop = a.getBoolean(R.styleable.StgStaggeredGridView_stgDrawSelectorOnTop, false);
    } else {//  www. j  av a 2 s .c  o  m
        mColCount = 2;
        mDrawSelectorOnTop = false;
    }

    final ViewConfiguration vc = ViewConfiguration.get(context);
    mTouchSlop = vc.getScaledTouchSlop();
    mMaximumVelocity = vc.getScaledMaximumFlingVelocity();
    mFlingVelocity = vc.getScaledMinimumFlingVelocity();
    //mScroller=ScrollerCompat.from(context);

    mTopEdge = new EdgeEffectCompat(context);
    mBottomEdge = new EdgeEffectCompat(context);
    setWillNotDraw(false);
    setClipToPadding(false);
    this.setFocusableInTouchMode(false);

    if (mSelector == null) {
        useDefaultSelector();
    }

    mMinimumVelocity = vc.getScaledMinimumFlingVelocity();
    mMaximumVelocity = vc.getScaledMaximumFlingVelocity();
    mOverscrollDistance = vc.getScaledOverscrollDistance(); //TODO
    mOverflingDistance = vc.getScaledOverflingDistance();
}

From source file:com.cocoa.cocoautils.widget.navigationtabbar.ntb.NavigationTabBar.java

@SuppressWarnings("ResourceAsColor")
public NavigationTabBar(final Context context, final AttributeSet attrs, final int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    //Init NTB//from ww w  .j a v a2s .  c om

    // 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, -2f));
        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, -2f));
        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: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/*from  w ww.  j  a v a 2s. c  om*/

    // 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:devlight.io.library.ntb.NavigationTabBar.java

@SuppressWarnings({ "ResourceAsColor", "ResourceType" })
public NavigationTabBar(final Context context, final AttributeSet attrs, final int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    //Init NTB/*from w  ww. j a  v  a 2  s . com*/

    // 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.homechart.app.commont.matertab.MaterialTabs.java

public MaterialTabs(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setFillViewport(true);//  w  ww .  j ava 2  s  . c om
    setWillNotDraw(false);
    tabsContainer = new LinearLayout(context);
    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    addView(tabsContainer);

    DisplayMetrics dm = getResources().getDisplayMetrics();
    indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm);
    underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm);
    tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);

    // Get system attrs (android:textSize and android:textColor).
    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);
    tabTextSize = a.getDimensionPixelSize(TEXT_COLOR_INDEX, tabTextSize);
    int textPrimaryColor = a.getColor(TEXT_COLOR_PRIMARY, 0);
    tabTextColorUnselected = a.getColor(TEXT_COLOR_INDEX, textPrimaryColor);

    underlineColor = textPrimaryColor;
    indicatorColor = textPrimaryColor;
    int padding = a.getDimensionPixelSize(PADDING_INDEX, 0);
    paddingLeft = padding > 0 ? padding : a.getDimensionPixelSize(PADDING_LEFT_INDEX, 0);
    paddingRight = padding > 0 ? padding : a.getDimensionPixelSize(PADDING_RIGHT_INDEX, 0);
    a.recycle();

    a = context.obtainStyledAttributes(attrs, R.styleable.MaterialTabs);

    // Get custom attrs of MaterialTabs.
    indicatorColor = a.getColor(R.styleable.MaterialTabs_mtIndicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.MaterialTabs_mtUnderlineColor, underlineColor);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.MaterialTabs_mtIndicatorHeight, indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.MaterialTabs_mtUnderlineHeight, underlineHeight);
    tabPadding = a.getDimensionPixelSize(R.styleable.MaterialTabs_mtTabPaddingLeftRight, tabPadding);
    sameWeightTabs = a.getBoolean(R.styleable.MaterialTabs_mtSameWeightTabs, sameWeightTabs);
    textAllCaps = a.getBoolean(R.styleable.MaterialTabs_mtTextAllCaps, textAllCaps);
    isPaddingMiddle = a.getBoolean(R.styleable.MaterialTabs_mtPaddingMiddle, isPaddingMiddle);
    tabTypefaceUnselectedStyle = a.getInt(R.styleable.MaterialTabs_mtTextUnselectedStyle, Typeface.BOLD);
    tabTypefaceSelectedStyle = a.getInt(R.styleable.MaterialTabs_mtTextSelectedStyle, Typeface.BOLD);
    tabTextColorSelected = a.getColor(R.styleable.MaterialTabs_mtTextColorSelected, textPrimaryColor);

    // Get custom attrs of MaterialRippleLayout.
    rippleColor = a.getColor(R.styleable.MaterialTabs_mtMrlRippleColor, MaterialRippleLayout.DEFAULT_COLOR);
    // Making default ripple highlight color the same as rippleColor but with 1/4 the alpha.
    rippleHighlightColor = Color.argb((int) (Color.alpha(rippleColor) * 0.25), Color.red(rippleColor),
            Color.green(rippleColor), Color.blue(rippleColor));
    rippleHighlightColor = a.getColor(R.styleable.MaterialTabs_mtMrlRippleHighlightColor, rippleHighlightColor);
    rippleDiameterDp = a.getDimension(R.styleable.MaterialTabs_mtMrlRippleDiameter,
            MaterialRippleLayout.DEFAULT_DIAMETER_DP);
    rippleOverlay = a.getBoolean(R.styleable.MaterialTabs_mtMrlRippleOverlay,
            MaterialRippleLayout.DEFAULT_RIPPLE_OVERLAY);
    rippleDuration = a.getInt(R.styleable.MaterialTabs_mtMrlRippleDuration,
            MaterialRippleLayout.DEFAULT_DURATION);
    rippleAlphaFloat = a.getFloat(R.styleable.MaterialTabs_mtMrlRippleAlpha,
            MaterialRippleLayout.DEFAULT_ALPHA);
    rippleDelayClick = a.getBoolean(R.styleable.MaterialTabs_mtMrlRippleDelayClick,
            MaterialRippleLayout.DEFAULT_DELAY_CLICK);
    rippleFadeDuration = a.getInteger(R.styleable.MaterialTabs_mtMrlRippleFadeDuration,
            MaterialRippleLayout.DEFAULT_FADE_DURATION);
    ripplePersistent = a.getBoolean(R.styleable.MaterialTabs_mtMrlRipplePersistent,
            MaterialRippleLayout.DEFAULT_PERSISTENT);
    rippleInAdapter = a.getBoolean(R.styleable.MaterialTabs_mtMrlRippleInAdapter,
            MaterialRippleLayout.DEFAULT_SEARCH_ADAPTER);
    rippleRoundedCornersDp = a.getDimension(R.styleable.MaterialTabs_mtMrlRippleRoundedCorners,
            MaterialRippleLayout.DEFAULT_ROUNDED_CORNERS_DP);

    a.recycle();

    setMarginBottomTabContainer();

    rectPaint = new Paint();
    rectPaint.setAntiAlias(true);
    rectPaint.setStyle(Style.FILL);

    defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.MATCH_PARENT);
    expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);

    if (locale == null) {
        locale = getResources().getConfiguration().locale;
    }
}

From source file:io.karim.MaterialTabs.java

public MaterialTabs(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setFillViewport(true);/*  www  . j  a va 2 s  .co  m*/
    setWillNotDraw(false);
    tabsContainer = new LinearLayout(context);
    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    addView(tabsContainer);

    DisplayMetrics dm = getResources().getDisplayMetrics();
    indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm);
    underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm);
    tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);

    // Get system attrs (android:textSize and android:textColor).
    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);
    tabTextSize = a.getDimensionPixelSize(TEXT_SIZE_INDEX, tabTextSize);
    int textPrimaryColor = a.getColor(TEXT_COLOR_PRIMARY, android.R.color.white);
    tabTextColorUnselected = a.getColor(TEXT_COLOR_INDEX, textPrimaryColor);

    underlineColor = textPrimaryColor;
    indicatorColor = textPrimaryColor;
    int padding = a.getDimensionPixelSize(PADDING_INDEX, 0);
    paddingLeft = padding > 0 ? padding : a.getDimensionPixelSize(PADDING_LEFT_INDEX, 0);
    paddingRight = padding > 0 ? padding : a.getDimensionPixelSize(PADDING_RIGHT_INDEX, 0);
    a.recycle();

    a = context.obtainStyledAttributes(attrs, R.styleable.MaterialTabs);

    // Get custom attrs of MaterialTabs.
    indicatorColor = a.getColor(R.styleable.MaterialTabs_mtIndicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.MaterialTabs_mtUnderlineColor, underlineColor);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.MaterialTabs_mtIndicatorHeight, indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.MaterialTabs_mtUnderlineHeight, underlineHeight);
    tabPadding = a.getDimensionPixelSize(R.styleable.MaterialTabs_mtTabPaddingLeftRight, tabPadding);
    sameWeightTabs = a.getBoolean(R.styleable.MaterialTabs_mtSameWeightTabs, sameWeightTabs);
    textAllCaps = a.getBoolean(R.styleable.MaterialTabs_mtTextAllCaps, textAllCaps);
    isPaddingMiddle = a.getBoolean(R.styleable.MaterialTabs_mtPaddingMiddle, isPaddingMiddle);
    tabTypefaceUnselectedStyle = a.getInt(R.styleable.MaterialTabs_mtTextUnselectedStyle, Typeface.BOLD);
    tabTypefaceSelectedStyle = a.getInt(R.styleable.MaterialTabs_mtTextSelectedStyle, Typeface.BOLD);
    tabTextColorSelected = a.getColor(R.styleable.MaterialTabs_mtTextColorSelected, textPrimaryColor);

    // Get custom attrs of MaterialRippleLayout.
    rippleColor = a.getColor(R.styleable.MaterialTabs_mtMrlRippleColor, MaterialRippleLayout.DEFAULT_COLOR);
    // Making default ripple highlight color the same as rippleColor but with 1/4 the alpha.
    rippleHighlightColor = Color.argb((int) (Color.alpha(rippleColor) * 0.25), Color.red(rippleColor),
            Color.green(rippleColor), Color.blue(rippleColor));
    rippleHighlightColor = a.getColor(R.styleable.MaterialTabs_mtMrlRippleHighlightColor, rippleHighlightColor);
    rippleDiameterDp = a.getDimension(R.styleable.MaterialTabs_mtMrlRippleDiameter,
            MaterialRippleLayout.DEFAULT_DIAMETER_DP);
    rippleOverlay = a.getBoolean(R.styleable.MaterialTabs_mtMrlRippleOverlay,
            MaterialRippleLayout.DEFAULT_RIPPLE_OVERLAY);
    rippleDuration = a.getInt(R.styleable.MaterialTabs_mtMrlRippleDuration,
            MaterialRippleLayout.DEFAULT_DURATION);
    rippleAlphaFloat = a.getFloat(R.styleable.MaterialTabs_mtMrlRippleAlpha,
            MaterialRippleLayout.DEFAULT_ALPHA);
    rippleDelayClick = a.getBoolean(R.styleable.MaterialTabs_mtMrlRippleDelayClick,
            MaterialRippleLayout.DEFAULT_DELAY_CLICK);
    rippleFadeDuration = a.getInteger(R.styleable.MaterialTabs_mtMrlRippleFadeDuration,
            MaterialRippleLayout.DEFAULT_FADE_DURATION);
    ripplePersistent = a.getBoolean(R.styleable.MaterialTabs_mtMrlRipplePersistent,
            MaterialRippleLayout.DEFAULT_PERSISTENT);
    rippleInAdapter = a.getBoolean(R.styleable.MaterialTabs_mtMrlRippleInAdapter,
            MaterialRippleLayout.DEFAULT_SEARCH_ADAPTER);
    rippleRoundedCornersDp = a.getDimension(R.styleable.MaterialTabs_mtMrlRippleRoundedCorners,
            MaterialRippleLayout.DEFAULT_ROUNDED_CORNERS_DP);

    a.recycle();

    setMarginBottomTabContainer();

    rectPaint = new Paint();
    rectPaint.setAntiAlias(true);
    rectPaint.setStyle(Style.FILL);

    defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.MATCH_PARENT);
    expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);

    if (locale == null) {
        locale = getResources().getConfiguration().locale;
    }
}

From source file:com.github.shareme.gwsmaterialuikit.library.material.app.Dialog.java

public Dialog applyStyle(int resId) {
    Context context = getContext();
    TypedArray a = context.obtainStyledAttributes(resId, R.styleable.Dialog);

    int layout_width = mLayoutWidth;
    int layout_height = mLayoutHeight;
    boolean layoutParamsDefined = false;
    int titleTextAppearance = 0;
    int titleTextColor = 0;
    boolean titleTextColorDefined = false;
    int actionBackground = 0;
    int actionRipple = 0;
    int actionTextAppearance = 0;
    ColorStateList actionTextColors = null;
    int positiveActionBackground = 0;
    int positiveActionRipple = 0;
    int positiveActionTextAppearance = 0;
    ColorStateList positiveActionTextColors = null;
    int negativeActionBackground = 0;
    int negativeActionRipple = 0;
    int negativeActionTextAppearance = 0;
    ColorStateList negativeActionTextColors = null;
    int neutralActionBackground = 0;
    int neutralActionRipple = 0;
    int neutralActionTextAppearance = 0;
    ColorStateList neutralActionTextColors = null;

    for (int i = 0, count = a.getIndexCount(); i < count; i++) {
        int attr = a.getIndex(i);

        if (attr == R.styleable.Dialog_android_layout_width) {
            layout_width = a.getLayoutDimension(attr, ViewGroup.LayoutParams.WRAP_CONTENT);
            layoutParamsDefined = true;//ww  w  .j  a va 2  s . co m
        } else if (attr == R.styleable.Dialog_android_layout_height) {
            layout_height = a.getLayoutDimension(attr, ViewGroup.LayoutParams.WRAP_CONTENT);
            layoutParamsDefined = true;
        } else if (attr == R.styleable.Dialog_di_maxWidth)
            maxWidth(a.getDimensionPixelOffset(attr, 0));
        else if (attr == R.styleable.Dialog_di_maxHeight)
            maxHeight(a.getDimensionPixelOffset(attr, 0));
        else if (attr == R.styleable.Dialog_di_dimAmount)
            dimAmount(a.getFloat(attr, 0));
        else if (attr == R.styleable.Dialog_di_backgroundColor)
            backgroundColor(a.getColor(attr, 0));
        else if (attr == R.styleable.Dialog_di_maxElevation)
            maxElevation(a.getDimensionPixelOffset(attr, 0));
        else if (attr == R.styleable.Dialog_di_elevation)
            elevation(a.getDimensionPixelOffset(attr, 0));
        else if (attr == R.styleable.Dialog_di_cornerRadius)
            cornerRadius(a.getDimensionPixelOffset(attr, 0));
        else if (attr == R.styleable.Dialog_di_layoutDirection)
            layoutDirection(a.getInteger(attr, 0));
        else if (attr == R.styleable.Dialog_di_titleTextAppearance)
            titleTextAppearance = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_titleTextColor) {
            titleTextColor = a.getColor(attr, 0);
            titleTextColorDefined = true;
        } else if (attr == R.styleable.Dialog_di_actionBackground)
            actionBackground = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_actionRipple)
            actionRipple = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_actionTextAppearance)
            actionTextAppearance = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_actionTextColor)
            actionTextColors = a.getColorStateList(attr);
        else if (attr == R.styleable.Dialog_di_positiveActionBackground)
            positiveActionBackground = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_positiveActionRipple)
            positiveActionRipple = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_positiveActionTextAppearance)
            positiveActionTextAppearance = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_positiveActionTextColor)
            positiveActionTextColors = a.getColorStateList(attr);
        else if (attr == R.styleable.Dialog_di_negativeActionBackground)
            negativeActionBackground = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_negativeActionRipple)
            negativeActionRipple = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_negativeActionTextAppearance)
            negativeActionTextAppearance = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_negativeActionTextColor)
            negativeActionTextColors = a.getColorStateList(attr);
        else if (attr == R.styleable.Dialog_di_neutralActionBackground)
            neutralActionBackground = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_neutralActionRipple)
            neutralActionRipple = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_neutralActionTextAppearance)
            neutralActionTextAppearance = a.getResourceId(attr, 0);
        else if (attr == R.styleable.Dialog_di_neutralActionTextColor)
            neutralActionTextColors = a.getColorStateList(attr);
        else if (attr == R.styleable.Dialog_di_inAnimation)
            inAnimation(a.getResourceId(attr, 0));
        else if (attr == R.styleable.Dialog_di_outAnimation)
            outAnimation(a.getResourceId(attr, 0));
        else if (attr == R.styleable.Dialog_di_dividerColor)
            dividerColor(a.getColor(attr, 0));
        else if (attr == R.styleable.Dialog_di_dividerHeight)
            dividerHeight(a.getDimensionPixelOffset(attr, 0));
        else if (attr == R.styleable.Dialog_di_cancelable)
            cancelable(a.getBoolean(attr, true));
        else if (attr == R.styleable.Dialog_di_canceledOnTouchOutside)
            canceledOnTouchOutside(a.getBoolean(attr, true));
    }

    a.recycle();

    if (layoutParamsDefined)
        layoutParams(layout_width, layout_height);

    if (titleTextAppearance != 0)
        titleTextAppearance(titleTextAppearance);

    if (titleTextColorDefined)
        titleColor(titleTextColor);

    if (actionBackground != 0)
        actionBackground(actionBackground);

    if (actionRipple != 0)
        actionRipple(actionRipple);

    if (actionTextAppearance != 0)
        actionTextAppearance(actionTextAppearance);

    if (actionTextColors != null)
        actionTextColor(actionTextColors);

    if (positiveActionBackground != 0)
        positiveActionBackground(positiveActionBackground);

    if (positiveActionRipple != 0)
        positiveActionRipple(positiveActionRipple);

    if (positiveActionTextAppearance != 0)
        positiveActionTextAppearance(positiveActionTextAppearance);

    if (positiveActionTextColors != null)
        positiveActionTextColor(positiveActionTextColors);

    if (negativeActionBackground != 0)
        negativeActionBackground(negativeActionBackground);

    if (negativeActionRipple != 0)
        negativeActionRipple(negativeActionRipple);

    if (negativeActionTextAppearance != 0)
        negativeActionTextAppearance(negativeActionTextAppearance);

    if (negativeActionTextColors != null)
        negativeActionTextColor(negativeActionTextColors);

    if (neutralActionBackground != 0)
        neutralActionBackground(neutralActionBackground);

    if (neutralActionRipple != 0)
        neutralActionRipple(neutralActionRipple);

    if (neutralActionTextAppearance != 0)
        neutralActionTextAppearance(neutralActionTextAppearance);

    if (neutralActionTextColors != null)
        neutralActionTextColor(neutralActionTextColors);

    return this;
}

From source file:com.lovely3x.eavlibrary.EasyAdapterView.java

/**
 * ??/*from   w w w  .  ja v  a2 s  .c  o m*/
 *
 * @param attrs ?
 */
protected void initAttrs(AttributeSet attrs) {
    if (attrs != null) {

        TypedArray typeArray = null;
        try {
            typeArray = getContext().obtainStyledAttributes(attrs, R.styleable.EasyAdapterView);

            mLayoutDirectly = typeArray.getInteger(R.styleable.EasyAdapterView_orientation,
                    LAYOUT_DIRECTLY_VERTICAL);
            mViewMode = ViewMode.wrap(typeArray.getInteger(R.styleable.EasyAdapterView_mode, LIST_VIEW.mValue));

            mDividerHeight = typeArray.getDimensionPixelOffset(R.styleable.EasyAdapterView_dividerHeight,
                    mDividerHeight);
            Drawable divider = typeArray.getDrawable(R.styleable.EasyAdapterView_divider);
            if (divider != null)
                mDivider = divider;

            switch (mLayoutDirectly) {
            case LAYOUT_DIRECTLY_HORIZONTAL: {
                setHorizontalScrollBarEnabled(true);
                setVerticalScrollBarEnabled(false);

            }
                break;
            case LAYOUT_DIRECTLY_VERTICAL: {
                setVerticalScrollBarEnabled(true);
                setHorizontalScrollBarEnabled(false);
            }
                break;
            }

        } finally {
            if (typeArray != null)
                typeArray.recycle();
        }

    }
}