Example usage for android.content.res TypedArray getDrawable

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

Introduction

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

Prototype

@Nullable
public Drawable getDrawable(@StyleableRes int index) 

Source Link

Document

Retrieve the Drawable for the attribute at index.

Usage

From source file:aierjun.com.aierjunlibrary.widget.tablayout.PagerSlidingTabStrip.java

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

    setFillViewport(true);//from  w w w .  ja va2 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();

    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);

    // get system attrs (android:textSize and android:textColor)
    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);

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

    tabBackgroundDrawable = createColorStateListDrawable(Color.TRANSPARENT,
            getResources().getColor(android.R.color.transparent));

    a.recycle();
    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);
    if (a.hasValue(R.styleable.PagerSlidingTabStrip_pstsTabBackground))
        tabBackgroundDrawable = a.getDrawable(R.styleable.PagerSlidingTabStrip_pstsTabBackground);
    shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand);
    scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset);
    textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps);
    tabchecktextcolor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsTabCheckTextColor, tabchecktextcolor);

    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:com.tandong.sa.vpic.UnderlinePageIndicator.java

public UnderlinePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;/*from  ww w  . j a v a  2  s .com*/

    final Resources res = getResources();

    // Load defaults from resources
    final boolean defaultFades = res.getBoolean(getResources()
            .getIdentifier("default_underline_indicator_fades", "bool", context.getPackageName()));
    // final boolean defaultFades = res
    // .getBoolean(R.bool.default_underline_indicator_fades);
    final int defaultFadeDelay = res.getInteger(getResources()
            .getIdentifier("default_underline_indicator_fade_delay", "integer", context.getPackageName()));
    // final int defaultFadeDelay = res
    // .getInteger(R.integer.default_underline_indicator_fade_delay);
    final int defaultFadeLength = res.getInteger(getResources()
            .getIdentifier("default_underline_indicator_fade_length", "integer", context.getPackageName()));
    // final int defaultFadeLength = res
    // .getInteger(R.integer.default_underline_indicator_fade_length);
    final int defaultSelectedColor = res.getColor(getResources()
            .getIdentifier("default_underline_indicator_selected_color", "color", context.getPackageName()));
    // final int defaultSelectedColor = res
    // .getColor(R.color.default_underline_indicator_selected_color);

    // Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, new int[] {
            getResources().getIdentifier("UnderlinePageIndicator", "styleable", context.getPackageName()) },
            defStyle, 0);
    // TypedArray a = context.obtainStyledAttributes(attrs,
    // R.styleable.UnderlinePageIndicator, defStyle, 0);

    setFades(a.getBoolean(
            getResources().getIdentifier("UnderlinePageIndicator_fades", "styleable", context.getPackageName()),
            defaultFades));
    // setFades(a.getBoolean(R.styleable.UnderlinePageIndicator_fades,
    // defaultFades));
    setSelectedColor(a.getColor(getResources().getIdentifier("UnderlinePageIndicator_selectedColor",
            "styleable", context.getPackageName()), defaultSelectedColor));
    // setSelectedColor(a.getColor(
    // R.styleable.UnderlinePageIndicator_selectedColor,
    // defaultSelectedColor));
    setFadeDelay(a.getInteger(getResources().getIdentifier("UnderlinePageIndicator_fadeDelay", "styleable",
            context.getPackageName()), defaultFadeDelay));
    // setFadeDelay(a.getInteger(R.styleable.UnderlinePageIndicator_fadeDelay,
    // defaultFadeDelay));
    setFadeLength(a.getInteger(getResources().getIdentifier("UnderlinePageIndicator_fadeLength", "styleable",
            context.getPackageName()), defaultFadeLength));
    // setFadeLength(a.getInteger(
    // R.styleable.UnderlinePageIndicator_fadeLength,
    // defaultFadeLength));

    Drawable background = a.getDrawable(getResources()
            .getIdentifier("UnderlinePageIndicator_android_background", "styleable", context.getPackageName()));
    // Drawable background = a
    // .getDrawable(R.styleable.UnderlinePageIndicator_android_background);
    if (background != null) {
        setBackgroundDrawable(background);
    }

    a.recycle();

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}

From source file:com.android.contacts.common.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  . j a  v a2  s.  co m*/
        mActivatedBackgroundDrawable = a.getDrawable(R.styleable.ContactListItemView_activated_background);

        mGapBetweenImageAndText = a.getDimensionPixelOffset(
                R.styleable.ContactListItemView_list_item_gap_between_image_and_text, mGapBetweenImageAndText);
        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);
        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.albedinsky.android.support.ui.widget.ViewPagerWidget.java

/**
 * Creates a new instance of ViewPagerWidget within the given <var>context</var>.
 *
 * @param context      Context in which will be this view presented.
 * @param attrs        Set of Xml attributes used to configure the new instance of this view.
 * @param defStyleAttr An attribute which contains a reference to a default style resource for
 *                     this view within a theme of the given context.
 *//*from   w w  w. j a  v a2 s .  c  o  m*/
public ViewPagerWidget(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs);
    /**
     * Process attributes.
     */
    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Ui_Widget_ViewPager,
            defStyleAttr, 0);
    if (typedArray != null) {
        this.ensurePullController();
        mPullController.setUpFromAttrs(context, attrs, defStyleAttr);

        final int n = typedArray.getIndexCount();
        for (int i = 0; i < n; i++) {
            final int index = typedArray.getIndex(i);
            if (index == R.styleable.Ui_Widget_ViewPager_android_background) {
                int resID = typedArray.getResourceId(index, -1);
                if (resID != -1) {
                    setBackgroundResource(resID);
                } else {
                    setBackgroundColor(typedArray.getColor(0, Color.TRANSPARENT));
                }
            } else if (index == R.styleable.Ui_Widget_ViewPager_uiPageMargin) {
                setPageMargin(typedArray.getDimensionPixelSize(index, 0));
            } else if (index == R.styleable.Ui_Widget_ViewPager_uiPageMarginDrawable) {
                setPageMarginDrawable(typedArray.getDrawable(index));
            } else if (index == R.styleable.Ui_Widget_ViewPager_uiPageSwipingEnabled) {
                updatePrivateFlags(PFLAG_PAGE_SWIPING_ENABLED, typedArray.getBoolean(index, true));
            } else if (index == R.styleable.Ui_Widget_ViewPager_uiPageFlingSwipingEnabled) {
                updatePrivateFlags(PFLAG_PAGE_FLING_SWIPING_ENABLED, typedArray.getBoolean(index, false));
            } else if (index == R.styleable.Ui_Widget_ViewPager_uiPageFlingSwipingSensitivity) {
                this.mPageFlingSwipingSensitivity = Math.max(0,
                        typedArray.getFloat(index, mPageFlingSwipingSensitivity));
            } else if (index == R.styleable.Ui_Widget_ViewPager_uiCurrentPage) {
                this.mCurrentPage = typedArray.getInteger(index, 0);
            } else if (index == R.styleable.Ui_Widget_ViewPager_uiOffScreenPageLimit) {
                setOffscreenPageLimit(typedArray.getInt(index, getOffscreenPageLimit()));
            } else if (index == R.styleable.Ui_Widget_ViewPager_uiPageScrollDuration) {
                this.mPageScrollDuration = typedArray.getInteger(index, mPageScrollDuration);
            } else if (index == R.styleable.Ui_Widget_ViewPager_uiPageScrollRelativeDurationEnabled) {
                updatePrivateFlags(PFLAG_PAGE_SCROLL_RELATIVE_DURATION_ENABLED,
                        typedArray.getBoolean(index, false));
            } else if (index == R.styleable.Ui_Widget_ViewPager_uiPullEnabled) {
                setPullEnabled(typedArray.getBoolean(index, false));
            }
        }
    }

    // Override default scroller so we can use custom durations for scroll if requested.
    this.mScroller = new WidgetScroller(context, SCROLLER_INTERPOLATOR);
}

From source file:com.actionbarsherlock.internal.widget.ActionBarView.java

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

    // Background is always provided by the container.
    setBackgroundResource(0);//from w w w .  ja  v a2  s .c  om

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SherlockActionBar, R.attr.actionBarStyle,
            0);

    ApplicationInfo appInfo = context.getApplicationInfo();
    PackageManager pm = context.getPackageManager();
    mNavigationMode = a.getInt(R.styleable.SherlockActionBar_navigationMode,
            ActionBar.NAVIGATION_MODE_STANDARD);
    mTitle = a.getText(R.styleable.SherlockActionBar_title);
    mSubtitle = a.getText(R.styleable.SherlockActionBar_subtitle);

    mLogo = a.getDrawable(R.styleable.SherlockActionBar_logo);
    if (mLogo == null) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            if (context instanceof Activity) {
                //Even though native methods existed in API 9 and 10 they don't work
                //so just parse the manifest to look for the logo pre-Honeycomb
                final int resId = loadLogoFromManifest((Activity) context);
                if (resId != 0) {
                    mLogo = context.getResources().getDrawable(resId);
                }
            }
        } else {
            if (context instanceof Activity) {
                try {
                    mLogo = pm.getActivityLogo(((Activity) context).getComponentName());
                } catch (NameNotFoundException e) {
                    Log.e(TAG, "Activity component name not found!", e);
                }
            }
            if (mLogo == null) {
                mLogo = appInfo.loadLogo(pm);
            }
        }
    }

    mIcon = a.getDrawable(R.styleable.SherlockActionBar_icon);
    if (mIcon == null) {
        if (context instanceof Activity) {
            try {
                mIcon = pm.getActivityIcon(((Activity) context).getComponentName());
            } catch (NameNotFoundException e) {
                Log.e(TAG, "Activity component name not found!", e);
            }
        }
        if (mIcon == null) {
            mIcon = appInfo.loadIcon(pm);
        }
    }

    final LayoutInflater inflater = LayoutInflater.from(context);

    final int homeResId = a.getResourceId(R.styleable.SherlockActionBar_homeLayout,
            R.layout.abs__action_bar_home);

    mHomeLayout = (HomeView) inflater.inflate(homeResId, this, false);

    mExpandedHomeLayout = (HomeView) inflater.inflate(homeResId, this, false);
    mExpandedHomeLayout.setUp(true);
    mExpandedHomeLayout.setOnClickListener(mExpandedActionViewUpListener);
    mExpandedHomeLayout.setContentDescription(getResources().getText(R.string.abs__action_bar_up_description));

    mTitleStyleRes = a.getResourceId(R.styleable.SherlockActionBar_titleTextStyle, 0);
    mSubtitleStyleRes = a.getResourceId(R.styleable.SherlockActionBar_subtitleTextStyle, 0);
    mProgressStyle = a.getResourceId(R.styleable.SherlockActionBar_progressBarStyle, 0);
    mIndeterminateProgressStyle = a.getResourceId(R.styleable.SherlockActionBar_indeterminateProgressStyle, 0);

    mProgressBarPadding = a.getDimensionPixelOffset(R.styleable.SherlockActionBar_progressBarPadding, 0);
    mItemPadding = a.getDimensionPixelOffset(R.styleable.SherlockActionBar_itemPadding, 0);

    setDisplayOptions(a.getInt(R.styleable.SherlockActionBar_displayOptions, DISPLAY_DEFAULT));

    final int customNavId = a.getResourceId(R.styleable.SherlockActionBar_customNavigationLayout, 0);
    if (customNavId != 0) {
        mCustomNavView = inflater.inflate(customNavId, this, false);
        mNavigationMode = ActionBar.NAVIGATION_MODE_STANDARD;
        setDisplayOptions(mDisplayOptions | ActionBar.DISPLAY_SHOW_CUSTOM);
    }

    mContentHeight = a.getLayoutDimension(R.styleable.SherlockActionBar_height, 0);

    a.recycle();

    mLogoNavItem = new ActionMenuItem(context, 0, android.R.id.home, 0, 0, mTitle);
    mHomeLayout.setOnClickListener(mUpClickListener);
    mHomeLayout.setClickable(true);
    mHomeLayout.setFocusable(true);
}

From source file:com.example.anumbrella.viewpager.CirclePagerIndicator.java

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

    ///*from w  w w . j a  va2  s. c o  m*/
    if (isInEditMode()) {
        return;
    }

    //??
    final Resources res = getResources();

    //
    //?

    //??
    final int defaultPageColor = res.getColor(R.color.default_circle_indicator_page_color);
    //
    final int defaultFillColor = res.getColor(R.color.default_circle_indicator_fill_color);
    //?
    final int defaultOrientation = res.getInteger(R.integer.default_circle_indicator_orientation);
    //
    final int defaultStrokeColor = res.getColor(R.color.default_circle_indicator_stroke_color);
    //
    final float defaultStrokeWidth = res.getDimension(R.dimen.default_circle_indicator_stroke_width);
    //??
    final float defaultRadius = res.getDimension(R.dimen.default_circle_indicator_radius);
    //??
    final boolean defaultCentered = res.getBoolean(R.bool.default_circle_indicator_centered);
    //?(?())
    final boolean defaultSnap = res.getBoolean(R.bool.default_circle_indicator_snap);

    //xml
    TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.CirclePagerIndicator, defStyle, 0);

    mCentered = array.getBoolean(R.styleable.CirclePagerIndicator_centered, defaultCentered);
    mOrientation = array.getInteger(R.styleable.CirclePagerIndicator_android_orientation, defaultOrientation);
    //
    mPaintPageFill.setStyle(Paint.Style.FILL);
    //
    mPaintPageFill.setColor(array.getColor(R.styleable.CirclePagerIndicator_pageColor, defaultPageColor));
    //
    mPaintFill.setStyle(Paint.Style.FILL);
    //
    mPaintFill.setColor(array.getColor(R.styleable.CirclePagerIndicator_fillColor, defaultFillColor));
    //
    mPaintStroke.setColor(array.getColor(R.styleable.CirclePagerIndicator_strokeColor, defaultStrokeColor));
    //(??)
    mPaintStroke.setStyle(Paint.Style.STROKE);
    //
    mPaintStroke.setStrokeWidth(
            array.getDimension(R.styleable.CirclePagerIndicator_strokeWidth, defaultStrokeWidth));
    //???
    mRadius = array.getDimension(R.styleable.CirclePagerIndicator_radius, defaultRadius);
    //?
    mSnap = array.getBoolean(R.styleable.CirclePagerIndicator_snap, defaultSnap);
    Drawable background = array.getDrawable(R.styleable.CirclePagerIndicator_android_background);
    if (background != null) {
        setBackgroundDrawable(background);
    }
    array.recycle();
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);

}

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  v a2  s.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.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.");
                }/* w  w  w  .j a  v  a 2  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();
}

From source file:com.manuelpeinado.numericpageindicator.NumericPageIndicator.java

@SuppressWarnings("deprecation")
public NumericPageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode()) {
        return;//from   w  ww. ja v a 2 s. c  om
    }

    // Load defaults from resources
    final Resources res = getResources();
    final int defaultTextColor = res.getColor(R.color.default_page_number_indicator_text_color);
    final int defaultPageNumberTextColor = res
            .getColor(R.color.default_page_number_indicator_page_number_text_color);
    final boolean defaultPageNumberTextBold = res
            .getBoolean(R.bool.default_page_number_indicator_page_number_text_bold);
    final int defaultButtonPressedColor = res
            .getColor(R.color.default_page_number_indicator_pressed_button_color);
    final float defaultTopPadding = res.getDimension(R.dimen.default_page_number_indicator_top_padding);
    final float defaultBottomPadding = res.getDimension(R.dimen.default_page_number_indicator_bottom_padding);
    final float defaultTextSize = res.getDimension(R.dimen.default_page_number_indicator_text_size);
    final boolean defaultShowChangePageButtons = res
            .getBoolean(R.bool.default_page_number_indicator_show_change_page_buttons);
    final boolean defaultShowStartEndButtons = res
            .getBoolean(R.bool.default_page_number_indicator_show_start_end_buttons);
    final boolean defaultShowImagesForPageControls = res
            .getBoolean(R.bool.default_page_number_indicator_show_images_for_page_controls);

    // Retrieve styles attributes
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.NumericPageIndicator, defStyle, 0);

    mTextTemplate = a.getString(R.styleable.NumericPageIndicator_textTemplate);
    if (mTextTemplate == null) {
        mTextTemplate = res.getString(R.string.default_page_number_indicator_text_template);
        ;
    }
    parseTextTemplate();

    mTextStartButton = a.getString(R.styleable.NumericPageIndicator_startButtonText);
    if (mTextStartButton == null) {
        mTextStartButton = res.getString(R.string.default_page_number_indicator_start_button_text);
    }
    mTextEndButton = a.getString(R.styleable.NumericPageIndicator_endButtonText);
    if (mTextEndButton == null) {
        mTextEndButton = res.getString(R.string.default_page_number_indicator_end_button_text);
    }
    mTextPreviousButton = a.getString(R.styleable.NumericPageIndicator_previousButtonText);
    if (mTextPreviousButton == null) {
        mTextPreviousButton = res.getString(R.string.default_page_number_indicator_previous_button_text);
    }
    mTextNextButton = a.getString(R.styleable.NumericPageIndicator_nextButtonText);
    if (mTextNextButton == null) {
        mTextNextButton = res.getString(R.string.default_page_number_indicator_next_button_text);
    }

    // these will be null if they are unused
    mStartButtonImage = getBitmapFromDrawable(a.getDrawable(R.styleable.NumericPageIndicator_startButtonImage));
    mEndButtonImage = getBitmapFromDrawable(a.getDrawable(R.styleable.NumericPageIndicator_endButtonImage));
    mPreviousButtonImage = getBitmapFromDrawable(
            a.getDrawable(R.styleable.NumericPageIndicator_previousButtonImage));
    mNextButtonImage = getBitmapFromDrawable(a.getDrawable(R.styleable.NumericPageIndicator_nextButtonImage));

    mColorText = a.getColor(R.styleable.NumericPageIndicator_android_textColor, defaultTextColor);
    mColorPageNumberText = a.getColor(R.styleable.NumericPageIndicator_pageNumberTextColor,
            defaultPageNumberTextColor);
    mPageNumberTextBold = a.getBoolean(R.styleable.NumericPageIndicator_pageNumberTextBold,
            defaultPageNumberTextBold);
    mColorPressedButton = a.getColor(R.styleable.NumericPageIndicator_pressedButtonColor,
            defaultButtonPressedColor);
    mPaddingTop = a.getDimension(R.styleable.NumericPageIndicator_android_paddingTop, defaultTopPadding);
    mPaddingBottom = a.getDimension(R.styleable.NumericPageIndicator_android_paddingBottom,
            defaultBottomPadding);
    mPaintText.setColor(mColorText);
    mShowChangePageButtons = a.getBoolean(R.styleable.NumericPageIndicator_showChangePageButtons,
            defaultShowChangePageButtons);
    mShowStartEndButtons = a.getBoolean(R.styleable.NumericPageIndicator_showStartEndButtons,
            defaultShowStartEndButtons);
    mShowImagesForPageControls = a.getBoolean(R.styleable.NumericPageIndicator_showImagesForPageControls,
            defaultShowImagesForPageControls);

    mPaintButtonBackground.setColor(mColorPressedButton);
    final float textSize = a.getDimension(R.styleable.NumericPageIndicator_android_textSize, defaultTextSize);
    mPaintText.setTextSize(textSize);
    mPaintText.setAntiAlias(true);

    mPaintPageNumberText.setColor(mColorPageNumberText);
    mPaintPageNumberText.setTextSize(textSize);
    mPaintPageNumberText.setAntiAlias(true);
    if (mPageNumberTextBold) {
        mPaintPageNumberText.setTypeface(Typeface.DEFAULT_BOLD);
    }

    final Drawable background = a.getDrawable(R.styleable.NumericPageIndicator_android_background);
    if (background != null) {
        setBackgroundDrawable(background);
    }

    a.recycle();
}

From source file:com.tandong.sa.vpic.CirclePageIndicator.java

public CirclePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;//from   w w  w .  j a  v a  2  s.  c  o m

    // Load defaults from resources
    final Resources res = getResources();
    final int defaultPageColor = res.getColor(context.getResources()
            .getIdentifier("default_circle_indicator_page_color", "color", context.getPackageName()));
    final int defaultFillColor = res.getColor(context.getResources()
            .getIdentifier("default_circle_indicator_fill_color", "color", context.getPackageName()));

    final int defaultOrientation = res.getInteger(context.getResources()
            .getIdentifier("default_circle_indicator_orientation", "integer", context.getPackageName()));

    final int defaultStrokeColor = res.getColor(context.getResources()
            .getIdentifier("default_circle_indicator_stroke_color", "color", context.getPackageName()));
    final float defaultStrokeWidth = res.getDimension(context.getResources()
            .getIdentifier("default_circle_indicator_stroke_width", "dimen", context.getPackageName()));
    final float defaultRadius = res.getDimension(context.getResources()
            .getIdentifier("default_circle_indicator_radius", "dimen", context.getPackageName()));
    final boolean defaultCentered = res.getBoolean(context.getResources()
            .getIdentifier("default_circle_indicator_centered", "bool", context.getPackageName()));

    final boolean defaultSnap = res.getBoolean(context.getResources()
            .getIdentifier("default_circle_indicator_snap", "bool", context.getPackageName()));

    // Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, new int[] {
            getResources().getIdentifier("CirclePageIndicator", "styleable", context.getPackageName()) },
            defStyle, 0);

    mCentered = a.getBoolean(
            getResources().getIdentifier("CirclePageIndicator_centered", "styleable", context.getPackageName()),
            defaultCentered);

    mOrientation = a.getInt(getResources().getIdentifier("CirclePageIndicator_android_orientation", "styleable",
            context.getPackageName()), defaultOrientation);

    mPaintPageFill.setStyle(Style.FILL);
    mPaintPageFill.setColor(a.getColor(getResources().getIdentifier("CirclePageIndicator_pageColor",
            "styleable", context.getPackageName()), defaultPageColor));
    mPaintStroke.setStyle(Style.STROKE);
    mPaintStroke.setColor(a.getColor(getResources().getIdentifier("CirclePageIndicator_strokeColor",
            "styleable", context.getPackageName()), defaultStrokeColor));
    mPaintStroke.setStrokeWidth(a.getDimension(getResources().getIdentifier("CirclePageIndicator_strokeWidth",
            "styleable", context.getPackageName()), defaultStrokeWidth));
    mPaintFill.setStyle(Style.FILL);
    mPaintFill.setColor(a.getColor(getResources().getIdentifier("CirclePageIndicator_fillColor", "styleable",
            context.getPackageName()), defaultFillColor));
    mRadius = a.getDimension(
            getResources().getIdentifier("CirclePageIndicator_radius", "styleable", context.getPackageName()),
            defaultRadius);
    mSnap = a.getBoolean(
            getResources().getIdentifier("CirclePageIndicator_snap", "styleable", context.getPackageName()),
            defaultSnap);

    Drawable background = a.getDrawable(getResources().getIdentifier("CirclePageIndicator_android_background",
            "styleable", context.getPackageName()));

    if (background != null) {
        setBackgroundDrawable(background);
    }

    a.recycle();

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}