Example usage for android.content.res TypedArray getDimensionPixelOffset

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

Introduction

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

Prototype

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

Source Link

Document

Retrieve a dimensional unit attribute at index for use as an offset in raw pixels.

Usage

From source file:com.glm.view.SlidingLayer.java

/**
 * Constructor for the sliding layer.<br>
 * By default this panel will/*from w w w. j  a  v  a2s.co m*/
 * <ol>
 *     <li>{@link #setStickTo(int)} with param {@link #STICK_TO_AUTO}</li>
 *    <li>Use no shadow drawable. (i.e. with width of 0)</li>
 *    <li>Close when the panel is tapped</li>
 *    <li>Open when the offset is tapped, but will have an offset of 0</li>
 * </ol>
 * @param context a reference to an existing context
 * @param attrs attribute set constructed from attributes set in android .xml file
 * @param defStyle style res id
 */
public SlidingLayer(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;
    // Style
    final TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SlidingLayer);

    // Set the side of the screen
    setStickTo(ta.getInt(R.styleable.SlidingLayer_stickTo, STICK_TO_AUTO));

    // Sets the shadow drawable
    int shadowRes = ta.getResourceId(R.styleable.SlidingLayer_shadowDrawable, -1);
    if (shadowRes != -1) {
        setShadowDrawable(shadowRes);
    }

    // Sets the shadow width
    setShadowWidth((int) ta.getDimension(R.styleable.SlidingLayer_shadowWidth, 0));

    // Sets the ability to close the layer by tapping in any empty space
    closeOnTapEnabled = ta.getBoolean(R.styleable.SlidingLayer_closeOnTapEnabled, true);
    // Sets the ability to open the layout by tapping on any of the exposed closed layer
    openOnTapEnabled = ta.getBoolean(R.styleable.SlidingLayer_openOnTapEnabled, true);

    // How much of the view sticks out when closed
    setOffsetWidth(ta.getDimensionPixelOffset(R.styleable.SlidingLayer_offsetWidth, 0));

    ta.recycle();

    init();
}

From source file:com.wunderlist.slidinglayer.SlidingLayer.java

/**
 * Constructor for the sliding layer.<br>
 * By default this panel will//from   w  ww  . j a  va2s . c om
 * <ol>
 * <li>{@link #setStickTo(int)} with param {@link #STICK_TO_RIGHT}</li>
 * <li>Use no shadow drawable. (i.e. with size of 0)</li>
 * <li>Close when the panel is tapped</li>
 * <li>Open when the offset is tapped, but will have an offset of 0</li>
 * </ol>
 *
 * @param context  a reference to an existing context
 * @param attrs    attribute set constructed from attributes set in android .xml file
 * @param defStyle style res id
 */
public SlidingLayer(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // Style
    final TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SlidingLayer);

    // Set the side of the screen
    setStickTo(ta.getInt(R.styleable.SlidingLayer_stickTo, STICK_TO_RIGHT));

    // Sets the shadow drawable
    int shadowRes = ta.getResourceId(R.styleable.SlidingLayer_shadowDrawable, INVALID_VALUE);
    if (shadowRes != INVALID_VALUE) {
        setShadowDrawable(shadowRes);
    }

    // Sets the shadow size
    mShadowSize = (int) ta.getDimension(R.styleable.SlidingLayer_shadowSize, 0);

    // Sets the ability to open or close the layer by tapping in any empty space
    changeStateOnTap = ta.getBoolean(R.styleable.SlidingLayer_changeStateOnTap, true);

    // How much of the view sticks out when closed
    mOffsetDistance = ta.getDimensionPixelOffset(R.styleable.SlidingLayer_offsetDistance, 0);

    // Sets the size of the preview summary, if any
    mPreviewOffsetDistance = ta.getDimensionPixelOffset(R.styleable.SlidingLayer_previewOffsetDistance,
            INVALID_VALUE);

    // If showing offset is greater than preview mode offset dimension, exception is thrown
    checkPreviewModeConsistency();

    ta.recycle();

    init();
}

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);//from  w  w w .  ja v  a2s.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:bk.vinhdo.taxiads.utils.view.SlidingLayer.java

/**
 * Constructor for the sliding layer.<br>
 * By default this panel will// www .  j  a v a 2 s  .  c o m
 * <ol>
 * <li>{@link #setStickTo(int)} with param {@link #STICK_TO_AUTO}</li>
 * <li>Use no shadow drawable. (i.e. with width of 0)</li>
 * <li>Close when the panel is tapped</li>
 * <li>Open when the offset is tapped, but will have an offset of 0</li>
 * </ol>
 * 
 * @param context
 *            a reference to an existing context
 * @param attrs
 *            attribute set constructed from attributes set in android .xml
 *            file
 * @param defStyle
 *            style res id
 */
public SlidingLayer(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // Style
    final TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SlidingLayer);

    // Set the side of the screen
    setStickTo(ta.getInt(R.styleable.SlidingLayer_stickTo, STICK_TO_AUTO));

    // Sets the shadow drawable
    int shadowRes = ta.getResourceId(R.styleable.SlidingLayer_shadowDrawableSliding, -1);
    if (shadowRes != -1) {
        setShadowDrawable(shadowRes);
    }

    // Sets the shadow width
    setShadowWidth((int) ta.getDimension(R.styleable.SlidingLayer_shadowWidthSliding, 0));

    // Sets the ability to close the layer by tapping in any empty space
    closeOnTapEnabled = ta.getBoolean(R.styleable.SlidingLayer_closeOnTapEnabled, true);

    // Sets the ability to open the layout by tapping on any of the exposed
    // closed layer
    openOnTapEnabled = ta.getBoolean(R.styleable.SlidingLayer_openOnTapEnabled, true);

    // How much of the view sticks out when closed
    setOffsetWidth(ta.getDimensionPixelOffset(R.styleable.SlidingLayer_offsetWidth, 0));

    ta.recycle();

    init();
}

From source file:com.appunite.list.GridView.java

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

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GridView, defStyle, 0);

    int hSpacing = a.getDimensionPixelOffset(R.styleable.GridView_horizontalSpacing, 0);
    setHorizontalSpacing(hSpacing);// www .ja va  2  s . c o  m

    int vSpacing = a.getDimensionPixelOffset(R.styleable.GridView_verticalSpacing, 0);
    setVerticalSpacing(vSpacing);

    int index = a.getInt(R.styleable.GridView_stretchMode, STRETCH_COLUMN_WIDTH);
    if (index >= 0) {
        setStretchMode(index);
    }

    int columnWidth = a.getDimensionPixelOffset(R.styleable.GridView_columnWidth, -1);
    if (columnWidth > 0) {
        setColumnWidth(columnWidth);
    }

    int numColumns = a.getInt(R.styleable.GridView_numColumns, 1);
    setNumColumns(numColumns);

    index = a.getInt(R.styleable.GridView_android_gravity, -1);
    if (index >= 0) {
        setGravity(index);
    }

    a.recycle();
}

From source file:com.pt.treasuretrash.widget.SlidingLayer.java

/**
 * Constructor for the sliding layer.<br>
 * By default this panel will/* w  w  w. j  av a 2 s  .c o  m*/
 * <ol>
 * <li>{@link #setStickTo(int)} with param {@link #STICK_TO_AUTO}</li>
 * <li>Use no shadow drawable. (i.e. with width of 0)</li>
 * <li>Close when the panel is tapped</li>
 * <li>Open when the offset is tapped, but will have an offset of 0</li>
 * </ol>
 * 
 * @param context
 *            a reference to an existing context
 * @param attrs
 *            attribute set constructed from attributes set in android .xml
 *            file
 * @param defStyle
 *            style res id
 */
public SlidingLayer(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // Style
    final TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SlidingLayer);

    // Set the side of the screen
    setStickTo(ta.getInt(R.styleable.SlidingLayer_stickTo, STICK_TO_AUTO));

    // Sets the shadow drawable
    int shadowRes = ta.getResourceId(R.styleable.SlidingLayer_shadowDrawable, -1);
    if (shadowRes != -1) {
        setShadowDrawable(shadowRes);
    }

    // Sets the shadow width
    setShadowWidth((int) ta.getDimension(R.styleable.SlidingLayer_shadowWidth, 0));

    // Sets the ability to close the layer by tapping in any empty space
    closeOnTapEnabled = ta.getBoolean(R.styleable.SlidingLayer_closeOnTapEnabled, true);
    // Sets the ability to open the layout by tapping on any of the exposed
    // closed layer
    openOnTapEnabled = ta.getBoolean(R.styleable.SlidingLayer_openOnTapEnabled, true);

    // How much of the view sticks out when closed
    setOffsetWidth(ta.getDimensionPixelOffset(R.styleable.SlidingLayer_offsetWidth, 0));

    ta.recycle();

    init();
}

From source file:com.astuetz.PagerSlidingTabStripMenu.java

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

    // setFillViewport(true);
    setWillNotDraw(false);//  w w w. j a  va 2  s. co m

    tabsContainer = new LinearLayout(context);
    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    tabsContainer.setGravity(Gravity.CENTER);
    addView(tabsContainer);

    DisplayMetrics dm = getResources().getDisplayMetrics();

    scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);
    indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm);
    underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm);
    dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm);
    tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
    dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);

    mTabPaddingTop = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mTabPaddingTop, dm);
    mTabPaddingBottom = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mTabPaddingBottom, dm);
    mTabDrawablePadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mTabDrawablePadding, dm);

    // get system attrs (android:textSize and android:textColor)

    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);

    tabTextSize = a.getDimensionPixelSize(0, tabTextSize);
    tabTextColor = a.getColor(1, tabTextColor);

    a.recycle();

    // get custom attrs

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

    indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor);
    dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight,
            indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight,
            underlineHeight);
    dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding,
            dividerPadding);
    tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding);
    tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground,
            tabBackgroundResId);
    shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand);
    scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset);
    textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps);
    mIconPostion = IconPosition
            .fromValue(a.getInteger(R.styleable.PagerSlidingTabStrip_pstsIconPosition, mIconPostion.value));
    mTabPaddingTop = a.getDimensionPixelOffset(R.styleable.PagerSlidingTabStrip_pstsTabPaddingTop,
            mTabPaddingTop);
    mTabPaddingBottom = a.getDimensionPixelOffset(R.styleable.PagerSlidingTabStrip_pstsTabPaddingBottom,
            mTabPaddingBottom);
    mTabDrawablePadding = a.getDimensionPixelOffset(R.styleable.PagerSlidingTabStrip_pstsTabDrawablePadding,
            mTabDrawablePadding);

    a.recycle();

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

    dividerPaint = new Paint();
    dividerPaint.setAntiAlias(true);
    dividerPaint.setStrokeWidth(dividerWidth);

    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:org.kde.necessitas.ministro.ExtractStyle.java

public void extractViewInformations(String styleName, int styleId, JSONObject json, String qtClassName,
        AttributeSet attribSet) {
    try {//from  ww w  . j  a  v a 2s  .c  o m
        int[] viewAttrs;
        viewAttrs = (int[]) styleableClass.getDeclaredField("View").get(null);
        TypedArray a = m_theme.obtainStyledAttributes(attribSet, viewAttrs, styleId, 0);

        if (null != qtClassName)
            json.put("qtClass", qtClassName);

        final int N = a.getIndexCount();
        for (int i = 0; i < N; i++) {
            int attr = a.getIndex(i);
            if (attr == View_background)
                json.put("View_background", getDrawable(a.getDrawable(attr), styleName + "_View_background"));
            else if (attr == View_padding)
                json.put("View_padding", a.getDimensionPixelSize(attr, -1));
            else if (attr == View_paddingLeft)
                json.put("View_paddingLeft", a.getDimensionPixelSize(attr, -1));
            else if (attr == View_paddingTop)
                json.put("View_paddingTop", a.getDimensionPixelSize(attr, -1));
            else if (attr == View_paddingRight)
                json.put("View_paddingRight", a.getDimensionPixelSize(attr, -1));
            else if (attr == View_paddingBottom)
                json.put("View_paddingBottom", a.getDimensionPixelSize(attr, -1));
            else if (attr == View_scrollX)
                json.put("View_paddingBottom", a.getDimensionPixelOffset(attr, 0));
            else if (attr == View_scrollY)
                json.put("View_scrollY", a.getDimensionPixelOffset(attr, 0));
            else if (attr == View_id)
                json.put("View_id", a.getResourceId(attr, -1));
            else if (attr == View_tag)
                json.put("View_tag", a.getText(attr));
            else if (attr == View_fitsSystemWindows)
                json.put("View_fitsSystemWindows", a.getBoolean(attr, false));
            else if (attr == View_focusable)
                json.put("View_focusable", a.getBoolean(attr, false));
            else if (attr == View_focusableInTouchMode)
                json.put("View_focusableInTouchMode", a.getBoolean(attr, false));
            else if (attr == View_clickable)
                json.put("View_clickable", a.getBoolean(attr, false));
            else if (attr == View_longClickable)
                json.put("View_longClickable", a.getBoolean(attr, false));
            else if (attr == View_saveEnabled)
                json.put("View_saveEnabled", a.getBoolean(attr, true));
            else if (attr == View_duplicateParentState)
                json.put("View_duplicateParentState", a.getBoolean(attr, false));
            else if (attr == View_visibility)
                json.put("View_visibility", a.getInt(attr, 0));
            else if (attr == View_drawingCacheQuality)
                json.put("View_drawingCacheQuality", a.getInt(attr, 0));
            else if (attr == View_drawingCacheQuality)
                json.put("View_contentDescription", a.getString(attr));
            else if (attr == View_soundEffectsEnabled)
                json.put("View_soundEffectsEnabled", a.getBoolean(attr, true));
            else if (attr == View_hapticFeedbackEnabled)
                json.put("View_hapticFeedbackEnabled", a.getBoolean(attr, true));
            else if (attr == View_scrollbars)
                json.put("View_scrollbars", a.getInt(attr, 0));
            else if (attr == View_fadingEdge)
                json.put("View_fadingEdge", a.getInt(attr, 0));
            else if (attr == View_scrollbarStyle)
                json.put("View_scrollbarStyle", a.getInt(attr, 0));
            else if (attr == View_isScrollContainer)
                json.put("View_isScrollContainer", a.getBoolean(attr, false));
            else if (attr == View_keepScreenOn)
                json.put("View_keepScreenOn", a.getBoolean(attr, false));
            else if (attr == View_filterTouchesWhenObscured)
                json.put("View_filterTouchesWhenObscured", a.getBoolean(attr, false));
            else if (attr == View_nextFocusLeft)
                json.put("View_nextFocusLeft", a.getResourceId(attr, -1));
            else if (attr == View_nextFocusRight)
                json.put("View_nextFocusRight", a.getResourceId(attr, -1));
            else if (attr == View_nextFocusUp)
                json.put("View_nextFocusUp", a.getResourceId(attr, -1));
            else if (attr == View_nextFocusDown)
                json.put("View_nextFocusDown", a.getResourceId(attr, -1));
            else if (attr == View_minWidth)
                json.put("View_minWidth", a.getDimensionPixelSize(attr, 0));
            else if (attr == View_minHeight)
                json.put("View_minHeight", a.getDimensionPixelSize(attr, 0));
            else if (attr == View_onClick)
                json.put("View_onClick", a.getString(attr));
            else if (attr == View_overScrollMode)
                json.put("View_overScrollMode", a.getInt(attr, 1));
        }
        a.recycle();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:am.widget.indicatortabstrip.IndicatorTabStrip.java

public IndicatorTabStrip(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    setItemClickable(true);/*  w w  w  . j  a v  a2  s  .c  o  m*/
    setClickSmoothScroll(true);
    final float density = getResources().getDisplayMetrics().density;
    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.setTextAlign(Align.CENTER);
    if (Build.VERSION.SDK_INT > 4) {
        updateTextPaintDensity();
    }
    mTagLocation = new TagLocation(TagLocation.LOCATION_EDGE);
    final TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);
    int n = a.getIndexCount();
    int textSize = (int) (DEFAULT_TEXT_SIZE * density);
    ColorStateList textColors = null;
    Drawable divider = null;
    for (int i = 0; i < n; i++) {
        int attr = a.getIndex(i);
        switch (attr) {
        case 0:
            textSize = a.getDimensionPixelSize(attr, textSize);
            break;
        case 1:
            textColors = a.getColorStateList(attr);
            break;
        case 2:
            divider = a.getDrawable(attr);
            break;
        }
    }
    a.recycle();
    float scale = 1;
    Drawable itemBackground = null;
    ColorStateList gradient = null;
    Drawable indicator = null;
    int indicatorWidthMode = INDICATOR_WIDTH_MODE_SET;
    int indicatorPadding = 0;
    int indicatorWidth = INDICATOR_WIDTH_BY_DRAWABLE;
    int indicatorHeight = INDICATOR_HEIGHT_BY_DRAWABLE;
    Drawable interval = null;
    int minItemWidth = (int) (DEFAULT_ITEM_WIDTH * density);
    int minItemHeight = (int) (DEFAULT_ITEM_HEIGHT * density);
    int tagTextSize = (int) (DEFAULT_TAG_TEXT_SIZE * density);
    int tagTextColor = DEFAULT_TAG_TEXT_COLOR;
    Drawable tagBackground = getDefaultTagBackground();
    int tagMinSizeMode = TAG_MIN_SIZE_MODE_HAS_TEXT;
    int tagMinWidth = (int) (DEFAULT_TAG_MIN_SIZE * density);
    int tagMinHeight = (int) (DEFAULT_TAG_MIN_SIZE * density);
    int tagPaddingLeft = 0;
    int tagPaddingTop = 0;
    int tagPaddingRight = 0;
    int tagPaddingBottom = 0;
    int tagMarginLeft = 0;
    int tagMarginTop = 0;
    int tagMarginRight = 0;
    int tagMarginBottom = 0;
    TypedArray custom = context.obtainStyledAttributes(attrs, R.styleable.IndicatorTabStrip);
    textSize = custom.getDimensionPixelSize(R.styleable.IndicatorTabStrip_ttsTextSize, textSize);
    if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsTextColor))
        textColors = custom.getColorStateList(R.styleable.IndicatorTabStrip_ttsTextColor);
    scale = custom.getFloat(R.styleable.IndicatorTabStrip_ttsTextScale, scale);
    if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsBackground))
        itemBackground = custom.getDrawable(R.styleable.IndicatorTabStrip_ttsBackground);
    if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsGradient))
        gradient = custom.getColorStateList(R.styleable.IndicatorTabStrip_ttsGradient);
    if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsDivider))
        divider = custom.getDrawable(R.styleable.IndicatorTabStrip_ttsDivider);
    if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsIndicator))
        indicator = custom.getDrawable(R.styleable.IndicatorTabStrip_ttsIndicator);
    indicatorWidthMode = custom.getInt(R.styleable.IndicatorTabStrip_ttsIndicatorWidthMode, indicatorWidthMode);
    indicatorPadding = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsIndicatorPadding,
            indicatorPadding);
    indicatorWidth = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsIndicatorWidth,
            indicatorWidth);
    indicatorHeight = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsIndicatorHeight,
            indicatorHeight);
    if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsInterval))
        interval = custom.getDrawable(R.styleable.IndicatorTabStrip_ttsInterval);
    minItemWidth = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsMinItemWidth, minItemWidth);
    minItemHeight = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsMinItemHeight,
            minItemHeight);
    tagTextSize = custom.getDimensionPixelSize(R.styleable.IndicatorTabStrip_ttsTagTextSize, tagTextSize);
    tagTextColor = custom.getColor(R.styleable.IndicatorTabStrip_ttsTagTextColor, tagTextColor);
    if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsTagBackground))
        tagBackground = custom.getDrawable(R.styleable.IndicatorTabStrip_ttsTagBackground);
    tagMinSizeMode = custom.getInt(R.styleable.IndicatorTabStrip_ttsTagMinSizeMode, tagMinSizeMode);
    tagMinWidth = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagMinWidth, tagMinWidth);
    tagMinHeight = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagMinHeight, tagMinHeight);
    if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsTagPadding)) {
        final int padding = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagPadding, 0);
        tagPaddingLeft = padding;
        tagPaddingTop = padding;
        tagPaddingRight = padding;
        tagPaddingBottom = padding;
    }
    tagPaddingLeft = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagPaddingLeft,
            tagPaddingLeft);
    tagPaddingTop = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagPaddingTop,
            tagPaddingTop);
    tagPaddingRight = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagPaddingRight,
            tagPaddingRight);
    tagPaddingBottom = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagPaddingBottom,
            tagPaddingBottom);
    if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsTagMargin)) {
        final int margin = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagMargin, 0);
        tagMarginLeft = margin;
        tagMarginTop = margin;
        tagMarginRight = margin;
        tagMarginBottom = margin;
    }
    tagMarginLeft = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagMarginLeft,
            tagMarginLeft);
    tagMarginTop = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagMarginTop, tagMarginTop);
    tagMarginRight = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagMarginRight,
            tagMarginRight);
    tagMarginBottom = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagMarginBottom,
            tagMarginBottom);
    custom.recycle();
    setTextSize(textSize);
    if (textColors != null) {
        setTextColor(textColors);
    } else {
        setTextColor(DEFAULT_TEXT_COLOR);
    }
    setTextScale(scale);
    setItemBackground(itemBackground);
    setGradient(gradient);
    setDivider(divider);
    setIndicator(indicator);
    setIndicatorWidthMode(indicatorWidthMode);
    setIndicatorPadding(indicatorPadding);
    setIndicatorWidth(indicatorWidth);
    setIndicatorHeight(indicatorHeight);
    setInterval(interval);
    setMinItemWidth(minItemWidth);
    setMinItemHeight(minItemHeight);
    setTagTextSize(tagTextSize);
    setTagTextColor(tagTextColor);
    setTagBackground(tagBackground);
    setTagMinSizeMode(tagMinSizeMode);
    setTagMinWidth(tagMinWidth);
    setTagMinHeight(tagMinHeight);
    setTagPadding(tagPaddingLeft, tagPaddingTop, tagPaddingRight, tagPaddingBottom);
    setTagMargin(tagMarginLeft, tagMarginTop, tagMarginRight, tagMarginBottom);
}

From source file:com.edgar.banner.BannerPagerView.java

private void init(AttributeSet attrs, int defStyle) {
    Context context = getContext();
    Resources resource = context.getResources();
    LayoutInflater.from(getContext()).inflate(R.layout.banner_layout, this, true);
    mViewPage = (LoopViewPager) findViewById(R.id.carouse_viewpager);
    setBannerScroller(new BannerScroller(getContext()));
    mViewPage.setOverScrollMode(View.OVER_SCROLL_NEVER);
    mViewPage.setOnPageChangeListener(mCarousePageListener);
    mBannerPageAdapter = new DefaultBannerPageViewAdapter();
    mIndicatorParams.gravity = Gravity.BOTTOM;
    mPointPadding = resource.getDimensionPixelOffset(R.dimen.point_margin);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BannerPagerView, defStyle, 0);
    int N = a.getIndexCount();
    for (int i = 0; i < N; i++) {
        int attr = a.getIndex(i);
        if (attr == R.styleable.BannerPagerView_bannerAnimation) {
            int transformerType = a.getInt(attr, 0);
            setBannerPageTransformer(true, TransformerType.convert(transformerType));
        } else if (attr == R.styleable.BannerPagerView_enableAutoPlayer) {
            setEnableAutoPlay(a.getBoolean(attr, false));
        } else if (attr == R.styleable.BannerPagerView_indicatorStyle) {
            mIndicatorStyle = a.getInt(attr, IndicatorStyle.CIRCLE_INDICATOR);
        } else if (attr == R.styleable.BannerPagerView_indicatorLayout) {
            int resId = a.getResourceId(attr, 0);
            if (resId != 0) {
                View indicatorView = LayoutInflater.from(context).inflate(resId, this, false);
                if (!(indicatorView instanceof BannerIndicator)) {
                    throw new IllegalArgumentException("Your indicator must implements BannerIndicator.");
                }// ww w  .  j a v  a2  s  .  c  o m
                mIndicatorView = indicatorView;
                mBannerIndicator = (BannerIndicator) indicatorView;
                addView(mIndicatorView);
            }
        } else if (attr == R.styleable.BannerPagerView_unSelectDrawable) {
            mUnSelectedDrawable = a.getDrawable(attr);
        } else if (attr == R.styleable.BannerPagerView_selectedDrawable) {
            mSelectedDrawable = a.getDrawable(attr);
        } else if (attr == R.styleable.BannerPagerView_indicatorGravity) {
            mIndicatorGravity = a.getInt(attr, Gravity.CENTER);
        } else if (attr == R.styleable.BannerPagerView_pointPadding) {
            mPointPadding = a.getDimensionPixelOffset(attr, mPointPadding);
        } else if (attr == R.styleable.BannerPagerView_indicatorBackground) {
            mIndicatorBackground = a.getDrawable(attr);
        }
    }

    if (mUnSelectedDrawable == null) {
        mUnSelectedDrawable = ContextCompat.getDrawable(context, R.drawable.def_circle_normal_background);
    }
    if (mSelectedDrawable == null) {
        mSelectedDrawable = ContextCompat.getDrawable(context, R.drawable.def_circle_selected_background);
    }
    if (mIndicatorBackground == null) {
        mIndicatorBackground = new ColorDrawable(resource.getColor(R.color.indicator_background));
    }
    if (mBannerIndicator == null) {
        setIndicatorStyle(mIndicatorStyle);
    }

    a.recycle();
}