Example usage for android.content.res TypedArray getColorStateList

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

Introduction

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

Prototype

@Nullable
public ColorStateList getColorStateList(@StyleableRes int index) 

Source Link

Document

Retrieve the ColorStateList for the attribute at index.

Usage

From source file:in.sc9.discreteslider.DiscreteSlider.java

public DiscreteSlider(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    setFocusable(true);//from w  w  w.  ja  v a 2s .c o  m
    setWillNotDraw(false);

    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    float density = context.getResources().getDisplayMetrics().density;
    mTrackHeight = (int) (1 * density);
    mScrubberHeight = (int) (4 * density);
    int thumbSize = (int) (density * ThumbDrawable.DEFAULT_SIZE_DP);

    //Extra pixels for a touch area of 48dp
    int touchBounds = (int) (density * 32);
    mAddedTouchBounds = (touchBounds - thumbSize) / 2;

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DiscreteSlider, defStyleAttr,
            R.style.Widget_DiscreteSeekBar);

    int max = 100;
    int min = 0;
    int value = 0;
    mMirrorForRtl = a.getBoolean(R.styleable.DiscreteSlider_dsb_mirrorForRtl, mMirrorForRtl);
    mAllowTrackClick = a.getBoolean(R.styleable.DiscreteSlider_dsb_allowTrackClickToDrag, mAllowTrackClick);
    mIndicatorPopupEnabled = a.getBoolean(R.styleable.DiscreteSlider_dsb_indicatorPopupEnabled,
            mIndicatorPopupEnabled);
    mIndicatorTextFromArray = a.getBoolean(R.styleable.DiscreteSlider_dsb_indicatorTextFromArray,
            mIndicatorTextFromArray);
    int indexMax = R.styleable.DiscreteSlider_dsb_max;
    int indexMin = R.styleable.DiscreteSlider_dsb_min;
    int indexValue = R.styleable.DiscreteSlider_dsb_value;
    final TypedValue out = new TypedValue();
    //Not sure why, but we wanted to be able to use dimensions here...
    if (a.getValue(indexMax, out)) {
        if (out.type == TypedValue.TYPE_DIMENSION) {
            max = a.getDimensionPixelSize(indexMax, max);
        } else {
            max = a.getInteger(indexMax, max);
        }
    }
    if (a.getValue(indexMin, out)) {
        if (out.type == TypedValue.TYPE_DIMENSION) {
            min = a.getDimensionPixelSize(indexMin, min);
        } else {
            min = a.getInteger(indexMin, min);
        }
    }
    if (a.getValue(indexValue, out)) {
        if (out.type == TypedValue.TYPE_DIMENSION) {
            value = a.getDimensionPixelSize(indexValue, value);
        } else {
            value = a.getInteger(indexValue, value);
        }
    }

    mMin = min;
    mMax = Math.max(min + 1, max);
    mValue = Math.max(min, Math.min(max, value));
    updateKeyboardRange();

    mIndicatorFormatter = a.getString(R.styleable.DiscreteSlider_dsb_indicatorFormatter);

    mDiscretePointsEnabled = a.getBoolean(R.styleable.DiscreteSlider_dsb_discretePointsEnabled, false);
    mDiscretePointsShowAlways = a.getBoolean(R.styleable.DiscreteSlider_dsb_discretePointsShowAlways, false);

    ColorStateList trackColor = a.getColorStateList(R.styleable.DiscreteSlider_dsb_trackColor);
    ColorStateList progressColor = a.getColorStateList(R.styleable.DiscreteSlider_dsb_progressColor);
    ColorStateList rippleColor = a.getColorStateList(R.styleable.DiscreteSlider_dsb_rippleColor);
    int discretePointColor = a.getColor(R.styleable.DiscreteSlider_dsb_discretePointsColor, Color.RED);

    mtextColor = a.getColor(R.styleable.DiscreteSlider_dsb_textColor, Color.BLACK);
    mTextSize = a.getDimensionPixelSize(R.styleable.DiscreteSlider_dsb_TextSize, mTextSize);
    mTextPaddingTop = a.getDimensionPixelSize(R.styleable.DiscreteSlider_dsb_TextSize, mTextPaddingTop);
    textStyle = a.getInt(R.styleable.DiscreteSlider_dsb_TextStyle, textStyle);

    boolean editMode = isInEditMode();
    if (editMode || rippleColor == null) {
        rippleColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { Color.DKGRAY });
    }
    if (editMode || trackColor == null) {
        trackColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { Color.GRAY });
    }
    if (editMode || progressColor == null) {
        progressColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { DEFAULT_THUMB_COLOR });
    }
    if (editMode) {
        discretePointColor = Color.RED;
        mtextColor = Color.BLACK;
    }
    mRipple = SeekBarCompat.getRipple(rippleColor);
    if (isLollipopOrGreater) {
        SeekBarCompat.setBackground(this, mRipple);
    } else {
        mRipple.setCallback(this);
    }

    TrackRectDrawable shapeDrawable = new TrackRectDrawable(trackColor);
    mTrack = shapeDrawable;
    mTrack.setCallback(this);

    shapeDrawable = new TrackRectDrawable(progressColor);
    mScrubber = shapeDrawable;
    mScrubber.setCallback(this);

    mThumb = new ThumbDrawable(progressColor, thumbSize);
    mThumb.setCallback(this);
    mThumb.setBounds(0, 0, mThumb.getIntrinsicWidth(), mThumb.getIntrinsicHeight());

    textArray = new String[((mMax - mMin) + 1)];

    int j = mMin;
    for (int i = 0; i < ((mMax - mMin) + 1); i++) {
        if (j <= mMax) {
            textArray[i] = j + "";
            j++;
        } else
            break;
    }

    if (!editMode) {
        mIndicator = new PopupIndicator(context, attrs, defStyleAttr, convertValueToMessage(mMax));
        mIndicator.setListener(mFloaterListener);
    }
    a.recycle();

    setNumericTransformer(new DefaultNumericTransformer());

    mDiscretePoints = new Paint(Paint.ANTI_ALIAS_FLAG);
    mDiscretePoints.setColor(discretePointColor);
    mDiscretePoints.setStyle(Paint.Style.FILL);
    mDiscretePointsTran = new Paint(Paint.ANTI_ALIAS_FLAG);
    mDiscretePointsTran.setColor(Color.TRANSPARENT);
    mDiscretePointsTran.setStyle(Paint.Style.FILL_AND_STROKE);
    position = new RectF();

}

From source file:com.bei.test.view.tab.PagerSlidingTabStrip.java

public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setFillViewport(true);//from   w ww.  ja va 2 s  .  co  m
    setWillNotDraw(false);
    mTabsContainer = new LinearLayout(context);
    mTabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    addView(mTabsContainer);

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

    DisplayMetrics dm = getResources().getDisplayMetrics();
    mScrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mScrollOffset, dm);
    mIndicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mIndicatorHeight, dm);
    mUnderlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mUnderlineHeight, dm);
    mDividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mDividerPadding, dm);
    mTabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mTabPadding, dm);
    mDividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mDividerWidth, dm);
    mTabNormalTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mTabNormalTextSize, dm);
    mTabSelectTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mTabSelectTextSize, dm);

    mDividerPaint = new Paint();
    mDividerPaint.setAntiAlias(true);
    mDividerPaint.setStrokeWidth(mDividerWidth);

    // get system attrs for container
    TypedArray a = context.obtainStyledAttributes(attrs, ANDROID_ATTRS);
    int textPrimaryColor = a.getColor(TEXT_COLOR_PRIMARY, getResources().getColor(android.R.color.black));
    mUnderlineColor = textPrimaryColor;
    mDividerColor = textPrimaryColor;
    mIndicatorColor = textPrimaryColor;
    int padding = a.getDimensionPixelSize(PADDING_INDEX, 0);
    mPaddingLeft = padding > 0 ? padding : a.getDimensionPixelSize(PADDING_LEFT_INDEX, 0);
    mPaddingRight = padding > 0 ? padding : a.getDimensionPixelSize(PADDING_RIGHT_INDEX, 0);
    a.recycle();

    String tabTextTypefaceName = "sans-serif";
    // Use Roboto Medium as the default typeface from API 21 onwards
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        tabTextTypefaceName = "sans-serif-medium";
        mTabTextTypefaceStyle = Typeface.NORMAL;
    }

    // get custom attrs for tabs and container
    a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);
    mIndicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, mIndicatorColor);
    mIndicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight,
            mIndicatorHeight);
    mUnderlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, mUnderlineColor);
    mUnderlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight,
            mUnderlineHeight);
    mDividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, mDividerColor);
    mDividerWidth = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerWidth, mDividerWidth);
    mDividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding,
            mDividerPadding);
    isExpandTabs = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, isExpandTabs);
    mScrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, mScrollOffset);
    isPaddingMiddle = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsPaddingMiddle, isPaddingMiddle);
    mTabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight,
            mTabPadding);
    mTabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground,
            mTabBackgroundResId);
    mTabNormalTextSize = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabNormalTextSize,
            mTabNormalTextSize);
    mTabSelectTextSize = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabSelectTextSize,
            mTabSelectTextSize);

    mTabTextColor = a.hasValue(R.styleable.PagerSlidingTabStrip_pstsTabTextColor)
            ? a.getColorStateList(R.styleable.PagerSlidingTabStrip_pstsTabTextColor)
            : null;
    mTabTextTypefaceStyle = a.getInt(R.styleable.PagerSlidingTabStrip_pstsTabTextStyle, mTabTextTypefaceStyle);
    isTabTextAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTabTextAllCaps, isTabTextAllCaps);
    int tabTextAlpha = a.getInt(R.styleable.PagerSlidingTabStrip_pstsTabTextAlpha, DEF_VALUE_TAB_TEXT_ALPHA);
    String fontFamily = a.getString(R.styleable.PagerSlidingTabStrip_pstsTabTextFontFamily);
    a.recycle();

    //Tab text color selector
    if (mTabTextColor == null) {
        mTabTextColor = createColorStateList(textPrimaryColor, textPrimaryColor, Color.argb(tabTextAlpha,
                Color.red(textPrimaryColor), Color.green(textPrimaryColor), Color.blue(textPrimaryColor)));
    }

    //Tab text typeface and style
    if (fontFamily != null) {
        tabTextTypefaceName = fontFamily;
    }
    mTabTextTypeface = Typeface.create(tabTextTypefaceName, mTabTextTypefaceStyle);

    //Bottom padding for the tabs container parent view to show indicator and underline
    setTabsContainerParentViewPaddings();

    //Configure tab's container LayoutParams for either equal divided space or just wrap tabs
    mTabLayoutParams = isExpandTabs ? new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f)
            : new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
}

From source file:com.example.michaelg.myapplication.Item.discreteseekbar.DiscreteSeekBar.java

public DiscreteSeekBar(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    setFocusable(true);/*from ww  w .ja v  a 2s.  c  o  m*/
    setWillNotDraw(false);

    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    float density = context.getResources().getDisplayMetrics().density;

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DiscreteSeekBar, defStyleAttr,
            R.style.Widget_DiscreteSeekBar);

    int max = 100;
    int min = 0;
    int value = 0;
    mMirrorForRtl = a.getBoolean(R.styleable.DiscreteSeekBar_dsb_mirrorForRtl, mMirrorForRtl);
    mAllowTrackClick = a.getBoolean(R.styleable.DiscreteSeekBar_dsb_allowTrackClickToDrag, mAllowTrackClick);
    mIndicatorPopupEnabled = a.getBoolean(R.styleable.DiscreteSeekBar_dsb_indicatorPopupEnabled,
            mIndicatorPopupEnabled);
    mTrackHeight = a.getDimensionPixelSize(R.styleable.DiscreteSeekBar_dsb_trackHeight, (int) (1 * density));
    mScrubberHeight = a.getDimensionPixelSize(R.styleable.DiscreteSeekBar_dsb_scrubberHeight,
            (int) (4 * density));
    int thumbSize = a.getDimensionPixelSize(R.styleable.DiscreteSeekBar_dsb_thumbSize,
            (int) (density * ThumbDrawable.DEFAULT_SIZE_DP));
    int separation = a.getDimensionPixelSize(R.styleable.DiscreteSeekBar_dsb_indicatorSeparation,
            (int) (SEPARATION_DP * density));

    //Extra pixels for a minimum touch area of 32dp
    int touchBounds = (int) (density * 32);
    mAddedTouchBounds = Math.max(0, (touchBounds - thumbSize) / 2);

    int indexMax = R.styleable.DiscreteSeekBar_dsb_max;
    int indexMin = R.styleable.DiscreteSeekBar_dsb_min;
    int indexValue = R.styleable.DiscreteSeekBar_dsb_value;
    final TypedValue out = new TypedValue();
    //Not sure why, but we wanted to be able to use dimensions here...
    if (a.getValue(indexMax, out)) {
        if (out.type == TypedValue.TYPE_DIMENSION) {
            max = a.getDimensionPixelSize(indexMax, max);
        } else {
            max = a.getInteger(indexMax, max);
        }
    }
    if (a.getValue(indexMin, out)) {
        if (out.type == TypedValue.TYPE_DIMENSION) {
            min = a.getDimensionPixelSize(indexMin, min);
        } else {
            min = a.getInteger(indexMin, min);
        }
    }
    if (a.getValue(indexValue, out)) {
        if (out.type == TypedValue.TYPE_DIMENSION) {
            value = a.getDimensionPixelSize(indexValue, value);
        } else {
            value = a.getInteger(indexValue, value);
        }
    }

    mMin = min;
    mMax = Math.max(min + 1, max);
    mValue = Math.max(min, Math.min(max, value));
    updateKeyboardRange();

    mIndicatorFormatter = a.getString(R.styleable.DiscreteSeekBar_dsb_indicatorFormatter);

    ColorStateList trackColor = a.getColorStateList(R.styleable.DiscreteSeekBar_dsb_trackColor);
    ColorStateList progressColor = a.getColorStateList(R.styleable.DiscreteSeekBar_dsb_progressColor);
    ColorStateList rippleColor = a.getColorStateList(R.styleable.DiscreteSeekBar_dsb_rippleColor);
    boolean editMode = isInEditMode();
    if (editMode || rippleColor == null) {
        rippleColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { Color.DKGRAY });
    }
    if (editMode || trackColor == null) {
        trackColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { Color.GRAY });
    }
    if (editMode || progressColor == null) {
        progressColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { DEFAULT_THUMB_COLOR });
    }

    mRipple = SeekBarCompat.getRipple(rippleColor);
    if (isLollipopOrGreater) {
        SeekBarCompat.setBackground(this, mRipple);
    } else {
        mRipple.setCallback(this);
    }

    TrackRectDrawable shapeDrawable = new TrackRectDrawable(trackColor);
    mTrack = shapeDrawable;
    mTrack.setCallback(this);

    shapeDrawable = new TrackRectDrawable(progressColor);
    mScrubber = shapeDrawable;
    mScrubber.setCallback(this);

    mThumb = new ThumbDrawable(progressColor, thumbSize);
    mThumb.setCallback(this);
    mThumb.setBounds(0, 0, mThumb.getIntrinsicWidth(), mThumb.getIntrinsicHeight());

    if (!editMode) {
        mIndicator = new PopupIndicator(context, attrs, defStyleAttr, convertValueToMessage(mMax), thumbSize,
                thumbSize + mAddedTouchBounds + separation);
        mIndicator.setListener(mFloaterListener);
    }
    a.recycle();

    setNumericTransformer(new DefaultNumericTransformer());

}

From source file:com.qingsongchou.library.widget.tab.PagerSlidingTabStrip.java

public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setFillViewport(true);// w  ww . j a v a  2 s. com
    setWillNotDraw(false);
    mTabsContainer = new LinearLayout(context);
    mTabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    addView(mTabsContainer);

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

    DisplayMetrics dm = getResources().getDisplayMetrics();
    mScrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mScrollOffset, dm);
    mIndicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mIndicatorHeight, dm);
    mUnderlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mUnderlineHeight, dm);
    mDividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mDividerPadding, dm);
    mTabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mTabPadding, dm);
    mDividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mDividerWidth, dm);
    mTabNormalTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mTabNormalTextSize, dm);
    mTabSelectTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mTabSelectTextSize, dm);

    WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    wm.getDefaultDisplay().getMetrics(dm);
    screenWidth = dm.widthPixels;

    mDividerPaint = new Paint();
    mDividerPaint.setAntiAlias(true);
    mDividerPaint.setStrokeWidth(mDividerWidth);

    // get system attrs for container
    TypedArray a = context.obtainStyledAttributes(attrs, ANDROID_ATTRS);
    int textPrimaryColor = a.getColor(TEXT_COLOR_PRIMARY, getResources().getColor(android.R.color.black));
    mUnderlineColor = textPrimaryColor;
    mDividerColor = textPrimaryColor;
    mIndicatorColor = textPrimaryColor;
    int padding = a.getDimensionPixelSize(PADDING_INDEX, 0);
    mPaddingLeft = padding > 0 ? padding : a.getDimensionPixelSize(PADDING_LEFT_INDEX, 0);
    mPaddingRight = padding > 0 ? padding : a.getDimensionPixelSize(PADDING_RIGHT_INDEX, 0);
    a.recycle();

    String tabTextTypefaceName = "sans-serif";
    // Use Roboto Medium as the default typeface from API 21 onwards
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        tabTextTypefaceName = "sans-serif-medium";
        mTabTextTypefaceStyle = Typeface.NORMAL;
    }

    // get custom attrs for tabs and container
    a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);
    mIndicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsQscIndicatorColor, mIndicatorColor);
    mIndicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsQscIndicatorHeight,
            mIndicatorHeight);
    mUnderlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsQscUnderlineColor, mUnderlineColor);
    mUnderlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsQscUnderlineHeight,
            mUnderlineHeight);
    mDividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsQscDividerColor, mDividerColor);
    mDividerWidth = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsQscDividerWidth,
            mDividerWidth);
    mDividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsQscDividerPadding,
            mDividerPadding);
    isExpandTabs = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsQscShouldExpand, isExpandTabs);
    mScrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsQscScrollOffset,
            mScrollOffset);
    isPaddingMiddle = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsQscPaddingMiddle, isPaddingMiddle);
    mTabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsQscTabPaddingLeftRight,
            mTabPadding);
    mTabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsQscTabBackground,
            mTabBackgroundResId);
    mTabNormalTextSize = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsQscTabNormalTextSize,
            mTabNormalTextSize);
    mTabSelectTextSize = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsQscTabSelectTextSize,
            mTabSelectTextSize);

    mTabTextColor = a.hasValue(R.styleable.PagerSlidingTabStrip_pstsQscTabTextColor)
            ? a.getColorStateList(R.styleable.PagerSlidingTabStrip_pstsQscTabTextColor)
            : null;
    mTabTextTypefaceStyle = a.getInt(R.styleable.PagerSlidingTabStrip_pstsQscTabTextStyle,
            mTabTextTypefaceStyle);
    isTabTextAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsQscTabTextAllCaps, isTabTextAllCaps);
    int tabTextAlpha = a.getInt(R.styleable.PagerSlidingTabStrip_pstsQscTabTextAlpha, DEF_VALUE_TAB_TEXT_ALPHA);
    String fontFamily = a.getString(R.styleable.PagerSlidingTabStrip_pstsQscTabTextFontFamily);
    a.recycle();

    //Tab text color selector
    if (mTabTextColor == null) {
        mTabTextColor = createColorStateList(textPrimaryColor, textPrimaryColor, Color.argb(tabTextAlpha,
                Color.red(textPrimaryColor), Color.green(textPrimaryColor), Color.blue(textPrimaryColor)));
    }

    //Tab text typeface and style
    if (fontFamily != null) {
        tabTextTypefaceName = fontFamily;
    }
    mTabTextTypeface = Typeface.create(tabTextTypefaceName, mTabTextTypefaceStyle);

    //Bottom padding for the tabs container parent view to show indicator and underline
    setTabsContainerParentViewPaddings();

    //Configure tab's container LayoutParams for either equal divided space or just wrap tabs
    mTabLayoutParams = isExpandTabs ? new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f)
            : new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
}

From source file:com.appeaser.sublimepickerlibrary.timepicker.SublimeTimePicker.java

private void initializeLayout() {
    mContext = getContext();/*  ww w .  ja  v  a  2  s . co  m*/
    setCurrentLocale(Locale.getDefault());

    // process style attributes
    final TypedArray a = mContext.obtainStyledAttributes(R.styleable.SublimeTimePicker);
    final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final Resources res = mContext.getResources();

    mSelectHours = res.getString(R.string.select_hours);
    mSelectMinutes = res.getString(R.string.select_minutes);

    DateFormatSymbols dfs = DateFormatSymbols.getInstance(mCurrentLocale);
    String[] amPmStrings = dfs.getAmPmStrings();/*{"AM", "PM"}*/

    if (amPmStrings.length == 2 && !TextUtils.isEmpty(amPmStrings[0]) && !TextUtils.isEmpty(amPmStrings[1])) {
        mAmText = amPmStrings[0].length() > 2 ? amPmStrings[0].substring(0, 2) : amPmStrings[0];
        mPmText = amPmStrings[1].length() > 2 ? amPmStrings[1].substring(0, 2) : amPmStrings[1];
    } else {
        // Defaults
        mAmText = "AM";
        mPmText = "PM";
    }

    final int layoutResourceId = R.layout.time_picker_layout;
    final View mainView = inflater.inflate(layoutResourceId, this);

    mHeaderView = mainView.findViewById(R.id.time_header);

    // Set up hour/minute labels.
    mHourView = (TextView) mainView.findViewById(R.id.hours);
    mHourView.setOnClickListener(mClickListener);

    ViewCompat.setAccessibilityDelegate(mHourView, new ClickActionDelegate(mContext, R.string.select_hours));

    mSeparatorView = (TextView) mainView.findViewById(R.id.separator);

    mMinuteView = (TextView) mainView.findViewById(R.id.minutes);
    mMinuteView.setOnClickListener(mClickListener);

    ViewCompat.setAccessibilityDelegate(mMinuteView,
            new ClickActionDelegate(mContext, R.string.select_minutes));

    // Now that we have text appearances out of the way, make sure the hour
    // and minute views are correctly sized.
    mHourView.setMinWidth(computeStableWidth(mHourView, 24));
    mMinuteView.setMinWidth(computeStableWidth(mMinuteView, 60));

    // Set up AM/PM labels.
    mAmPmLayout = mainView.findViewById(R.id.ampm_layout);
    mAmLabel = (CheckedTextView) mAmPmLayout.findViewById(R.id.am_label);
    mAmLabel.setText(obtainVerbatim(amPmStrings[0]));
    mAmLabel.setOnClickListener(mClickListener);
    mPmLabel = (CheckedTextView) mAmPmLayout.findViewById(R.id.pm_label);
    mPmLabel.setText(obtainVerbatim(amPmStrings[1]));
    mPmLabel.setOnClickListener(mClickListener);

    ColorStateList headerTextColor = a.getColorStateList(R.styleable.SublimeTimePicker_spHeaderTextColor);

    if (headerTextColor != null) {
        mHourView.setTextColor(headerTextColor);
        mSeparatorView.setTextColor(headerTextColor);
        mMinuteView.setTextColor(headerTextColor);
        mAmLabel.setTextColor(headerTextColor);
        mPmLabel.setTextColor(headerTextColor);
    }

    // Set up header background, if available.
    if (SUtils.isApi_22_OrHigher()) {
        if (a.hasValueOrEmpty(R.styleable.SublimeTimePicker_spHeaderBackground)) {
            SUtils.setViewBackground(mHeaderView,
                    a.getDrawable(R.styleable.SublimeTimePicker_spHeaderBackground));
        }
    } else {
        if (a.hasValue(R.styleable.SublimeTimePicker_spHeaderBackground)) {
            SUtils.setViewBackground(mHeaderView,
                    a.getDrawable(R.styleable.SublimeTimePicker_spHeaderBackground));
        }
    }

    a.recycle();

    mRadialTimePickerView = (RadialTimePickerView) mainView.findViewById(R.id.radial_picker);

    setupListeners();

    mAllowAutoAdvance = true;

    // Set up for keyboard mode.
    mDoublePlaceholderText = res.getString(R.string.time_placeholder);
    mDeletedKeyFormat = res.getString(R.string.deleted_key);
    mPlaceholderText = mDoublePlaceholderText.charAt(0);
    mAmKeyCode = mPmKeyCode = -1;
    generateLegalTimesTree();

    // Initialize with current time
    final Calendar calendar = Calendar.getInstance(mCurrentLocale);
    final int currentHour = calendar.get(Calendar.HOUR_OF_DAY);
    final int currentMinute = calendar.get(Calendar.MINUTE);
    initialize(currentHour, currentMinute, false /* 12h */, HOUR_INDEX);
}

From source file:net.yaly.ViewPagerDoubleIndicator.java

public ViewPagerDoubleIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setFillViewport(true);/* w w w . j a v a 2  s.c  om*/
    setWillNotDraw(false);
    mTabsContainer = new LinearLayout(context);
    mTabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    addView(mTabsContainer);

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

    //
    DisplayMetrics dm = getResources().getDisplayMetrics();
    mScrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mScrollOffset, dm);
    mIndicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mIndicatorHeight, dm);
    mUnderlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mUnderlineHeight, dm);
    mDividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mDividerPadding, dm);
    mTabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mTabPadding, dm);
    mDividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mDividerWidth, dm);
    mTabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mTabTextSize, dm);
    // ?
    mDividerPaint = new Paint();
    mDividerPaint.setAntiAlias(true);
    mDividerPaint.setStrokeWidth(mDividerWidth);

    // get system attrs for container?
    TypedArray a = context.obtainStyledAttributes(attrs, ANDROID_ATTRS);
    int textPrimaryColor = a.getColor(TEXT_COLOR_PRIMARY, getResources().getColor(android.R.color.black));
    mUnderlineColor = textPrimaryColor;
    mDividerColor = textPrimaryColor;
    mBaseLineColor = textPrimaryColor;
    mIndicatorColor = textPrimaryColor;
    int padding = a.getDimensionPixelSize(PADDING_INDEX, 0);
    mPaddingLeft = padding > 0 ? padding : a.getDimensionPixelSize(PADDING_LEFT_INDEX, 0);
    mPaddingRight = padding > 0 ? padding : a.getDimensionPixelSize(PADDING_RIGHT_INDEX, 0);
    a.recycle();

    String tabTextTypefaceName = "sans-serif";
    // Use Roboto Medium as the default typeface from API 21 onwards
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        tabTextTypefaceName = "sans-serif-medium";
        mTabTextTypefaceStyle = Typeface.NORMAL;
    }

    // get custom attrs for tabs and container ?attr?
    a = context.obtainStyledAttributes(attrs, R.styleable.ViewPagerDoubleIndicator);
    mBaseLineColor = a.getColor(R.styleable.ViewPagerDoubleIndicator_vpdiBaseLineColor, mBaseLineColor);
    mIndicatorColor = a.getColor(R.styleable.ViewPagerDoubleIndicator_vpdiIndicatorColor, mIndicatorColor);
    mIndicatorHeight = a.getDimensionPixelSize(R.styleable.ViewPagerDoubleIndicator_vpdiIndicatorHeight,
            mIndicatorHeight);
    mUnderlineColor = a.getColor(R.styleable.ViewPagerDoubleIndicator_vpdiUnderlineColor, mUnderlineColor);
    mUnderlineHeight = a.getDimensionPixelSize(R.styleable.ViewPagerDoubleIndicator_vpdiUnderlineHeight,
            mUnderlineHeight);
    mDividerColor = a.getColor(R.styleable.ViewPagerDoubleIndicator_vpdiDividerColor, mDividerColor);
    mDividerWidth = a.getDimensionPixelSize(R.styleable.ViewPagerDoubleIndicator_vpdiDividerWidth,
            mDividerWidth);
    mDividerPadding = a.getDimensionPixelSize(R.styleable.ViewPagerDoubleIndicator_vpdiDividerPadding,
            mDividerPadding);
    isExpandTabs = a.getBoolean(R.styleable.ViewPagerDoubleIndicator_vpdiShouldExpand, isExpandTabs);
    mScrollOffset = a.getDimensionPixelSize(R.styleable.ViewPagerDoubleIndicator_vpdiScrollOffset,
            mScrollOffset);
    isPaddingMiddle = a.getBoolean(R.styleable.ViewPagerDoubleIndicator_vpdiPaddingMiddle, isPaddingMiddle);
    isHorizontalSplit = a.getBoolean(R.styleable.ViewPagerDoubleIndicator_vpdiHorizontalSplit,
            isHorizontalSplit);
    mTabPadding = a.getDimensionPixelSize(R.styleable.ViewPagerDoubleIndicator_vpdiTabPaddingLeftRight,
            mTabPadding);
    mTabBackgroundResId = a.getResourceId(R.styleable.ViewPagerDoubleIndicator_vpdiTabBackground,
            mTabBackgroundResId);
    mTabTextSize = a.getDimensionPixelSize(R.styleable.ViewPagerDoubleIndicator_vpdiTabTextSize, mTabTextSize);
    mTabTextColor = a.hasValue(R.styleable.ViewPagerDoubleIndicator_vpdiTabTextColor)
            ? a.getColorStateList(R.styleable.ViewPagerDoubleIndicator_vpdiTabTextColor)
            : null;
    mTabTextColorUnSelected = a.hasValue(R.styleable.ViewPagerDoubleIndicator_vpdiTabTextColorUnSelected)
            ? a.getColorStateList(R.styleable.ViewPagerDoubleIndicator_vpdiTabTextColorUnSelected)
            : null;
    mTabTextTypefaceStyle = a.getInt(R.styleable.ViewPagerDoubleIndicator_vpdiTabTextStyle,
            mTabTextTypefaceStyle);
    isTabTextAllCaps = a.getBoolean(R.styleable.ViewPagerDoubleIndicator_vpdiTabTextAllCaps, isTabTextAllCaps);
    int tabTextAlpha = a.getInt(R.styleable.ViewPagerDoubleIndicator_vpdiTabTextAlpha,
            DEF_VALUE_TAB_TEXT_ALPHA);
    String fontFamily = a.getString(R.styleable.ViewPagerDoubleIndicator_vpdiTabTextFontFamily);
    a.recycle();

    //Tab text color selector
    if (mTabTextColor == null) {
        mTabTextColor = createColorStateList(textPrimaryColor, textPrimaryColor, Color.argb(tabTextAlpha,
                Color.red(textPrimaryColor), Color.green(textPrimaryColor), Color.blue(textPrimaryColor)));
    }

    //Tab text typeface and style
    if (fontFamily != null) {
        tabTextTypefaceName = fontFamily;
    }
    mTabTextTypeface = Typeface.create(tabTextTypefaceName, mTabTextTypefaceStyle);

    //Bottom padding for the tabs container parent view to show indicator and underline
    setTabsContainerParentViewPaddings();

    //Configure tab's container LayoutParams for either equal divided space or just wrap tabs
    //?Viewlayout? TODO
    if (isHorizontalSplit) {
        mTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,
                1f);//?view
    } else {
        mTabLayoutParams = isExpandTabs ? new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f)
                : new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);//?view
    }
}

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);//w  w w .j a va  2  s . com
        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.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;//from w  w w  .  j  av  a2 s. com
        } 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.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);/* w  w  w. jav a 2s.c o m*/
        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.albedinsky.android.ui.widget.SeekBarWidget.java

/**
 * Called from one of constructors of this view to perform its initialization.
 * <p>/* ww  w.ja  v a  2  s  . com*/
 * Initialization is done via parsing of the specified <var>attrs</var> set and obtaining for
 * this view specific data from it that can be used to configure this new view instance. The
 * specified <var>defStyleAttr</var> and <var>defStyleRes</var> are used to obtain default data
 * from the current theme provided by the specified <var>context</var>.
 */
@SuppressWarnings("ConstantConditions")
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    this.ensureRect();
    this.ensureDecorator();
    mDecorator.processAttributes(context, attrs, defStyleAttr, defStyleRes);
    this.mAnimations = Animations.get(this);

    /**
     * Process attributes.
     */
    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Ui_SeekBar, defStyleAttr,
            defStyleRes);
    if (typedArray != null) {
        final Rect indicatorTextPadding = new Rect();
        final int n = typedArray.getIndexCount();
        for (int i = 0; i < n; i++) {
            final int index = typedArray.getIndex(i);
            if (index == R.styleable.Ui_SeekBar_android_enabled) {
                setEnabled(typedArray.getBoolean(index, true));
            } else if (index == R.styleable.Ui_SeekBar_uiDiscrete) {
                setDiscrete(typedArray.getBoolean(index, false));
            } else if (index == R.styleable.Ui_SeekBar_uiDiscretePreviewEnabled) {
                setDiscretePreviewEnabled(typedArray.getBoolean(index, true));
            } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIntervalRatio) {
                setDiscreteIntervalRatio(typedArray.getFloat(index, mDiscreteIntervalRatio));
            } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIndicator) {
                setDiscreteIndicator(typedArray.getResourceId(index, 0));
            } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIndicatorTextAppearance) {
                setDiscreteIndicatorTextAppearance(typedArray.getResourceId(index, 0));
            } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIndicatorTextGravity) {
                setDiscreteIndicatorTextGravity(
                        typedArray.getInteger(index, DISCRETE_INDICATOR_TEXT_INFO.gravity));
            } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIndicatorTextPaddingStart) {
                indicatorTextPadding.left = typedArray.getDimensionPixelSize(index, 0);
            } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIndicatorTextPaddingTop) {
                indicatorTextPadding.top = typedArray.getDimensionPixelSize(index, 0);
            } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIndicatorTextPaddingEnd) {
                indicatorTextPadding.right = typedArray.getDimensionPixelSize(index, 0);
            } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIndicatorTextPaddingBottom) {
                indicatorTextPadding.bottom = typedArray.getDimensionPixelSize(index, 0);
            } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIntervalTickMarkColor) {
                setDiscreteIntervalTickMarkColor(typedArray.getColorStateList(index));
            } else if (index == R.styleable.Ui_SeekBar_uiDiscreteIntervalTickMarkRadius) {
                setDiscreteIntervalTickMarkRadius(typedArray.getDimensionPixelSize(index, 0));
            }
        }
        setDiscreteIndicatorTextPadding(indicatorTextPadding.left, indicatorTextPadding.top,
                indicatorTextPadding.right, indicatorTextPadding.bottom);
        typedArray.recycle();
    }
    this.applyProgressTints();
    this.applyThumbTint();
}