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:com.doomy.library.Internal.Marker.java

public Marker(Context context, AttributeSet attrs, int defStyleAttr, String maxValue) {
    super(context, attrs, defStyleAttr);
    DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DiscreteSeekBar,
            R.attr.discreteSeekBarStyle, R.style.DefaultSeekBar);

    int padding = (int) (PADDING_DP * displayMetrics.density) * 2;
    int textAppearanceId = a.getResourceId(R.styleable.DiscreteSeekBar_dsb_indicatorTextAppearance,
            R.style.DefaultIndicatorTextAppearance);
    mNumber = new TextView(context);
    //Add some padding to this textView so the bubble has some space to breath
    mNumber.setPadding(padding, 0, padding, 0);
    mNumber.setTextAppearance(context, textAppearanceId);
    mNumber.setGravity(Gravity.CENTER);//ww  w.j a  v  a 2  s  .  co  m
    mNumber.setText(maxValue);
    mNumber.setMaxLines(1);
    mNumber.setSingleLine(true);
    SeekBarCompat.setTextDirection(mNumber, TEXT_DIRECTION_LOCALE);
    mNumber.setVisibility(View.INVISIBLE);

    //add some padding for the elevation shadow not to be clipped
    //I'm sure there are better ways of doing this...
    setPadding(padding, padding, padding, padding);

    resetSizes(maxValue);

    mSeparation = (int) (SEPARATION_DP * displayMetrics.density);
    int thumbSize = (int) (ThumbDrawable.DEFAULT_SIZE_DP * displayMetrics.density);
    ColorStateList color = a.getColorStateList(R.styleable.DiscreteSeekBar_dsb_indicatorColor);
    mMarkerDrawable = new MarkerDrawable(color, thumbSize);
    mMarkerDrawable.setCallback(this);
    mMarkerDrawable.setMarkerListener(this);
    mMarkerDrawable.setExternalOffset(padding);

    //Elevation for anroid 5+
    float elevation = a.getDimension(R.styleable.DiscreteSeekBar_dsb_indicatorElevation,
            ELEVATION_DP * displayMetrics.density);
    ViewCompat.setElevation(this, elevation);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        SeekBarCompat.setOutlineProvider(this, mMarkerDrawable);
    }
    a.recycle();
}

From source file:in.sc9.discreteslider.internal.Marker.java

public Marker(Context context, AttributeSet attrs, int defStyleAttr, String maxValue) {
    super(context, attrs, defStyleAttr);
    DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DiscreteSlider,
            R.attr.discreteSeekBarStyle, R.style.Widget_DiscreteSeekBar);

    int padding = (int) (PADDING_DP * displayMetrics.density) * 2;
    int textAppearanceId = a.getResourceId(R.styleable.DiscreteSlider_dsb_indicatorTextAppearance,
            R.style.Widget_DiscreteIndicatorTextAppearance);
    mNumber = new TextView(context);
    //Add some padding to this textView so the bubble has some space to breath
    mNumber.setPadding(padding, 0, padding, 0);
    mNumber.setTextAppearance(context, textAppearanceId);
    mNumber.setGravity(Gravity.CENTER);/*from   w w w  .  j a v  a2 s  .c om*/
    mNumber.setText(maxValue);
    mNumber.setMaxLines(1);
    mNumber.setSingleLine(true);
    SeekBarCompat.setTextDirection(mNumber, TEXT_DIRECTION_LOCALE);
    mNumber.setVisibility(View.INVISIBLE);

    //add some padding for the elevation shadow not to be clipped
    //I'm sure there are better ways of doing this...
    setPadding(padding, padding, padding, padding);

    resetSizes(maxValue);

    mSeparation = (int) (SEPARATION_DP * displayMetrics.density);
    int thumbSize = (int) (ThumbDrawable.DEFAULT_SIZE_DP * displayMetrics.density);
    ColorStateList color = a.getColorStateList(R.styleable.DiscreteSlider_dsb_indicatorColor);
    mMarkerDrawable = new MarkerDrawable(color, thumbSize);
    mMarkerDrawable.setCallback(this);
    mMarkerDrawable.setMarkerListener(this);
    mMarkerDrawable.setExternalOffset(padding);

    //Elevation for anroid 5+
    float elevation = a.getDimension(R.styleable.DiscreteSlider_dsb_indicatorElevation,
            ELEVATION_DP * displayMetrics.density);
    ViewCompat.setElevation(this, elevation);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        SeekBarCompat.setOutlineProvider(this, mMarkerDrawable);
    }
    a.recycle();
}

From source file:com.jinzht.pro.discreteseekbar.internal.Marker.java

public Marker(Context context, AttributeSet attrs, int defStyleAttr, String maxValue) {
    super(context, attrs, defStyleAttr);
    DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DiscreteSeekBar,
            R.attr.discreteSeekBarStyle, R.style.Widget_DiscreteSeekBar);

    int padding = (int) (PADDING_DP * displayMetrics.density) * 2;
    int textAppearanceId = a.getResourceId(R.styleable.DiscreteSeekBar_dsb_indicatorTextAppearance,
            R.style.Widget_DiscreteIndicatorTextAppearance);
    mNumber = new TextView(context);
    //Add some padding to this textView so the bubble has some space to breath
    mNumber.setPadding(padding, 0, padding, 0);
    mNumber.setTextAppearance(context, textAppearanceId);
    mNumber.setGravity(Gravity.CENTER);//  www . j a  v  a 2  s . c om
    mNumber.setText(maxValue);
    mNumber.setMaxLines(1);
    mNumber.setSingleLine(true);
    SeekBarCompat.setTextDirection(mNumber, TEXT_DIRECTION_LOCALE);
    mNumber.setVisibility(View.INVISIBLE);

    //add some padding for the elevation shadow not to be clipped
    //I'm sure there are better ways of doing this...
    setPadding(padding, padding, padding, padding);

    resetSizes(maxValue);

    mSeparation = (int) (SEPARATION_DP * displayMetrics.density);
    int thumbSize = (int) (ThumbDrawable.DEFAULT_SIZE_DP * displayMetrics.density);
    ColorStateList color = a.getColorStateList(R.styleable.DiscreteSeekBar_dsb_indicatorColor);
    mMarkerDrawable = new MarkerDrawable(color, thumbSize);
    mMarkerDrawable.setCallback(this);
    mMarkerDrawable.setMarkerListener(this);
    mMarkerDrawable.setExternalOffset(padding);

    //Elevation for anroid 5+
    float elevation = a.getDimension(R.styleable.DiscreteSeekBar_dsb_indicatorElevation,
            ELEVATION_DP * displayMetrics.density);
    ViewCompat.setElevation(this, elevation);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        SeekBarCompat.setOutlineProvider(this, mMarkerDrawable);
    }
    a.recycle();
}

From source file:com.mightyworkouts.seekbar.internal.Marker.java

public Marker(Context context, AttributeSet attrs, int defStyleAttr, String maxValue) {
    super(context, attrs, defStyleAttr);
    DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DiscreteSeekBar,
            R.attr.discreteSeekBarStyle, R.style.Widget_DiscreteSeekBar);

    int padding = (int) (PADDING_DP * displayMetrics.density) * 2;
    int textAppearanceId = a.getResourceId(R.styleable.DiscreteSeekBar_dsb_indicatorTextAppearance,
            R.style.Widget_DiscreteIndicatorTextAppearance);
    mNumber = new TextView(context);
    //Add some padding to this textView so the bubble has some space to breath
    mNumber.setPadding(padding, 0, padding, 0);
    mNumber.setTextAppearance(context, textAppearanceId);
    mNumber.setGravity(Gravity.CENTER);//  w ww .j a  va2 s.  c  o  m
    mNumber.setText(maxValue);
    mNumber.setMaxLines(1);
    mNumber.setSingleLine(true);
    SeekBarCompat.setTextDirection(mNumber, TEXT_DIRECTION_LOCALE);
    mNumber.setVisibility(View.INVISIBLE);

    //add some padding for the elevation shadow not to be clipped
    //I'm sure there are better ways of doing this...
    setPadding(padding, padding, padding, padding);

    resetSizes(maxValue);

    mSeparation = (int) (SEPARATION_DP * displayMetrics.density);
    int thumbSize = (int) (ThumbDrawable.DEFAULT_SIZE_DP * displayMetrics.density);
    ColorStateList color = a.getColorStateList(R.styleable.DiscreteSeekBar_dsb_indicatorColor);
    mMarkerDrawable = new MarkerDrawable(context, color, thumbSize);
    mMarkerDrawable.setCallback(this);
    mMarkerDrawable.setMarkerListener(this);
    mMarkerDrawable.setExternalOffset(padding);

    //Elevation for anroid 5+
    float elevation = a.getDimension(R.styleable.DiscreteSeekBar_dsb_indicatorElevation,
            ELEVATION_DP * displayMetrics.density);
    ViewCompat.setElevation(this, elevation);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        SeekBarCompat.setOutlineProvider(this, mMarkerDrawable);
    }
    a.recycle();
}

From source file:com.bitflake.counter.HorizontalPicker.java

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

    // create the selector wheel paint
    TextPaint paint = new TextPaint();
    paint.setAntiAlias(true);//from w ww  . j ava 2 s. com
    textPaint = paint;

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

    CharSequence[] values;
    int ellipsize = 3; // END default value
    int sideItems = this.sideItems;

    try {
        textColor = a.getColorStateList(R.styleable.HorizontalPicker_android_textColor);
        if (textColor == null) {
            textColor = ColorStateList.valueOf(0xFF000000);
        }

        values = a.getTextArray(R.styleable.HorizontalPicker_values);
        ellipsize = a.getInt(R.styleable.HorizontalPicker_android_ellipsize, ellipsize);
        marqueeRepeatLimit = a.getInt(R.styleable.HorizontalPicker_android_marqueeRepeatLimit,
                marqueeRepeatLimit);
        dividerSize = a.getDimension(R.styleable.HorizontalPicker_dividerSize, dividerSize);
        sideItems = a.getInt(R.styleable.HorizontalPicker_sideItems, sideItems);

        float textSize = a.getDimension(R.styleable.HorizontalPicker_android_textSize, -1);
        if (textSize > -1) {
            setTextSize(textSize);
        }
    } finally {
        a.recycle();
    }

    switch (ellipsize) {
    case 1:
        setEllipsize(TextUtils.TruncateAt.START);
        break;
    case 2:
        setEllipsize(TextUtils.TruncateAt.MIDDLE);
        break;
    case 3:
        setEllipsize(TextUtils.TruncateAt.END);
        break;
    case 4:
        setEllipsize(TextUtils.TruncateAt.MARQUEE);
        break;
    }

    Paint.FontMetricsInt fontMetricsInt = textPaint.getFontMetricsInt();
    boringMetrics = new BoringLayout.Metrics();
    boringMetrics.ascent = fontMetricsInt.ascent;
    boringMetrics.bottom = fontMetricsInt.bottom;
    boringMetrics.descent = fontMetricsInt.descent;
    boringMetrics.leading = fontMetricsInt.leading;
    boringMetrics.top = fontMetricsInt.top;
    boringMetrics.width = itemWidth;

    setWillNotDraw(false);

    flingScrollerX = new OverScroller(context);
    adjustScrollerX = new OverScroller(context, new DecelerateInterpolator(2.5f));

    // initialize constants
    ViewConfiguration configuration = ViewConfiguration.get(context);
    touchSlop = configuration.getScaledTouchSlop();
    mMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity();
    maximumFlingVelocity = configuration.getScaledMaximumFlingVelocity()
            / SELECTOR_MAX_FLING_VELOCITY_ADJUSTMENT;
    overscrollDistance = configuration.getScaledOverscrollDistance();

    previousScrollerX = Integer.MIN_VALUE;

    setValues(values);
    setSideItems(sideItems);

    touchHelper = new PickerTouchHelper(this);
    ViewCompat.setAccessibilityDelegate(this, touchHelper);

}

From source file:kr.selfcontrol.selflocklauncher.picker.HorizontalPicker.java

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

    // create the selector wheel paint
    TextPaint paint = new TextPaint();
    paint.setAntiAlias(true);//from   ww w  .  ja v  a2s.  c o m
    mTextPaint = paint;

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

    CharSequence[] values;
    int ellipsize = 3; // END default value
    int sideItems = mSideItems;

    try {
        mTextColor = a.getColorStateList(R.styleable.HorizontalPicker_android_textColor);
        if (mTextColor == null) {
            mTextColor = ColorStateList.valueOf(0xFF000000);
        }

        values = a.getTextArray(R.styleable.HorizontalPicker_values);
        ellipsize = a.getInt(R.styleable.HorizontalPicker_android_ellipsize, ellipsize);
        mMarqueeRepeatLimit = a.getInt(R.styleable.HorizontalPicker_android_marqueeRepeatLimit,
                mMarqueeRepeatLimit);
        mDividerSize = a.getDimension(R.styleable.HorizontalPicker_dividerSize, mDividerSize);
        sideItems = a.getInt(R.styleable.HorizontalPicker_sideItems, sideItems);

        float textSize = a.getDimension(R.styleable.HorizontalPicker_android_textSize, -1);
        if (textSize > -1) {
            setTextSize(textSize);
        }
    } finally {
        a.recycle();
    }

    switch (ellipsize) {
    case 1:
        setEllipsize(TextUtils.TruncateAt.START);
        break;
    case 2:
        setEllipsize(TextUtils.TruncateAt.MIDDLE);
        break;
    case 3:
        setEllipsize(TextUtils.TruncateAt.END);
        break;
    case 4:
        setEllipsize(TextUtils.TruncateAt.MARQUEE);
        break;
    }

    Paint.FontMetricsInt fontMetricsInt = mTextPaint.getFontMetricsInt();
    mBoringMetrics = new BoringLayout.Metrics();
    mBoringMetrics.ascent = fontMetricsInt.ascent;
    mBoringMetrics.bottom = fontMetricsInt.bottom;
    mBoringMetrics.descent = fontMetricsInt.descent;
    mBoringMetrics.leading = fontMetricsInt.leading;
    mBoringMetrics.top = fontMetricsInt.top;
    mBoringMetrics.width = mItemWidth;

    setWillNotDraw(false);

    mFlingScrollerX = new OverScroller(context);
    mAdjustScrollerX = new OverScroller(context, new DecelerateInterpolator(2.5f));

    // initialize constants
    ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = configuration.getScaledTouchSlop();
    mMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity();
    mMaximumFlingVelocity = configuration.getScaledMaximumFlingVelocity()
            / SELECTOR_MAX_FLING_VELOCITY_ADJUSTMENT;
    mOverscrollDistance = configuration.getScaledOverscrollDistance();

    mPreviousScrollerX = Integer.MIN_VALUE;

    setValues(values);
    setSideItems(sideItems);

    mTouchHelper = new PickerTouchHelper(this);
    ViewCompat.setAccessibilityDelegate(this, mTouchHelper);

}

From source file:com.alimuzaffar.lib.widgets.PinEntryEditText.java

private void init(Context context, AttributeSet attrs) {
    float multi = context.getResources().getDisplayMetrics().density;
    mLineStroke = multi * mLineStroke;//  w w w.ja v  a  2 s .  c om
    mLineStrokeSelected = multi * mLineStrokeSelected;
    mSpace = multi * mSpace; //convert to pixels for our density
    mTextBottomPadding = multi * mTextBottomPadding; //convert to pixels for our density

    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.PinEntryEditText, 0, 0);
    try {
        TypedValue outValue = new TypedValue();
        ta.getValue(R.styleable.PinEntryEditText_pinAnimationType, outValue);
        mAnimatedType = outValue.data;
        mMask = ta.getString(R.styleable.PinEntryEditText_pinCharacterMask);
        mLineStroke = ta.getDimension(R.styleable.PinEntryEditText_pinLineStroke, mLineStroke);
        mLineStrokeSelected = ta.getDimension(R.styleable.PinEntryEditText_pinLineStrokeSelected,
                mLineStrokeSelected);
        mSpace = ta.getDimension(R.styleable.PinEntryEditText_pinCharacterSpacing, mSpace);
        mTextBottomPadding = ta.getDimension(R.styleable.PinEntryEditText_pinTextBottomPadding,
                mTextBottomPadding);
        mIsDigitSquare = ta.getBoolean(R.styleable.PinEntryEditText_pinBackgroundIsSquare, mIsDigitSquare);
        mPinBackground = ta.getDrawable(R.styleable.PinEntryEditText_pinBackgroundDrawable);
        ColorStateList colors = ta.getColorStateList(R.styleable.PinEntryEditText_pinLineColors);
        if (colors != null) {
            mColorStates = colors;
        }
    } finally {
        ta.recycle();
    }

    mCharPaint = new Paint(getPaint());
    mLastCharPaint = new Paint(getPaint());
    mLinesPaint = new Paint(getPaint());
    mLinesPaint.setStrokeWidth(mLineStroke);

    TypedValue outValue = new TypedValue();
    context.getTheme().resolveAttribute(R.attr.colorControlActivated, outValue, true);
    int colorSelected = outValue.data;
    mColors[0] = colorSelected;

    int colorFocused = isInEditMode() ? Color.GRAY : ContextCompat.getColor(context, R.color.pin_normal);
    mColors[1] = colorFocused;

    int colorUnfocused = isInEditMode() ? Color.GRAY : ContextCompat.getColor(context, R.color.pin_normal);
    mColors[2] = colorUnfocused;

    setBackgroundResource(0);

    mMaxLength = attrs.getAttributeIntValue(XML_NAMESPACE_ANDROID, "maxLength", 4);
    mNumChars = mMaxLength;

    //Disable copy paste
    super.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        public void onDestroyActionMode(ActionMode mode) {
        }

        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            return false;
        }
    });
    // When tapped, move cursor to end of text.
    super.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            setSelection(getText().length());
            if (mClickListener != null) {
                mClickListener.onClick(v);
            }
        }
    });

    super.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            setSelection(getText().length());
            return true;
        }
    });

    //If input type is password and no mask is set, use a default mask
    if ((getInputType() & InputType.TYPE_TEXT_VARIATION_PASSWORD) == InputType.TYPE_TEXT_VARIATION_PASSWORD
            && TextUtils.isEmpty(mMask)) {
        mMask = "\u25CF";
    } else if ((getInputType()
            & InputType.TYPE_NUMBER_VARIATION_PASSWORD) == InputType.TYPE_NUMBER_VARIATION_PASSWORD
            && TextUtils.isEmpty(mMask)) {
        mMask = "\u25CF";
    }

    if (!TextUtils.isEmpty(mMask)) {
        mMaskChars = getMaskChars();
    }

    //Height of the characters, used if there is a background drawable
    getPaint().getTextBounds("|", 0, 1, mTextHeight);
}

From source file:com.github.shareme.gwsdiscreteseekbar.library.Marker.java

@SuppressWarnings("deprecation")
public Marker(Context context, AttributeSet attrs, int defStyleAttr, String maxValue) {
    super(context, attrs, defStyleAttr);
    DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DiscreteSeekBar,
            R.attr.discreteSeekBarStyle, R.style.Widget_DiscreteSeekBar);

    int padding = (int) (PADDING_DP * displayMetrics.density) * 2;
    int textAppearanceId = a.getResourceId(R.styleable.DiscreteSeekBar_dsb_indicatorTextAppearance,
            R.style.Widget_DiscreteIndicatorTextAppearance);
    mNumber = new TextView(context);
    //Add some padding to this textView so the bubble has some space to breath
    mNumber.setPadding(padding, 0, padding, 0);
    //TODO: setTextAppearance is depreciated
    mNumber.setTextAppearance(context, textAppearanceId);
    mNumber.setGravity(Gravity.CENTER);/*from www.j  ava2  s.c o  m*/
    mNumber.setText(maxValue);
    mNumber.setMaxLines(1);
    mNumber.setSingleLine(true);
    //changed from TEXT_DIRECTION_LOCALE TO ViewCompat.LAYOUT_DIRECTION_LOCALE
    SeekBarCompat.setTextDirection(mNumber, ViewCompat.LAYOUT_DIRECTION_LOCALE);
    mNumber.setVisibility(View.INVISIBLE);

    //add some padding for the elevation shadow not to be clipped
    //I'm sure there are better ways of doing this...
    setPadding(padding, padding, padding, padding);

    resetSizes(maxValue);

    mSeparation = (int) (SEPARATION_DP * displayMetrics.density);
    int thumbSize = (int) (ThumbDrawable.DEFAULT_SIZE_DP * displayMetrics.density);
    ColorStateList color = a.getColorStateList(R.styleable.DiscreteSeekBar_dsb_indicatorColor);
    if (color != null) {
        mMarkerDrawable = new MarkerDrawable(color, thumbSize);
    }
    mMarkerDrawable.setCallback(this);
    mMarkerDrawable.setMarkerListener(this);
    mMarkerDrawable.setExternalOffset(padding);

    //Elevation for anroid 5+
    float elevation = a.getDimension(R.styleable.DiscreteSeekBar_dsb_indicatorElevation,
            ELEVATION_DP * displayMetrics.density);
    ViewCompat.setElevation(this, elevation);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        SeekBarCompat.setOutlineProvider(this, mMarkerDrawable);
    }
    a.recycle();
}

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

private void init(Context context) {
    // Get both the scrollbar states drawables
    TypedArray ta = context.getTheme().obtainStyledAttributes(ATTRS);
    useThumbDrawable(context, ta.getDrawable(THUMB_DRAWABLE));
    mTrackDrawable = ta.getDrawable(TRACK_DRAWABLE);

    mOverlayDrawableLeft = ta.getDrawable(PREVIEW_BACKGROUND_LEFT);
    mOverlayDrawableRight = ta.getDrawable(PREVIEW_BACKGROUND_RIGHT);
    mOverlayPosition = ta.getInt(OVERLAY_POSITION, OVERLAY_FLOATING);

    mScrollCompleted = true;//from   ww w  .  j  a va2 s  .  c  o  m

    getSectionsFromIndexer();

    mOverlaySize = context.getResources().getDimensionPixelSize(R.dimen.fastscroll_overlay_size);
    mOverlayPos = new RectF();
    mScrollFade = new ScrollFade();
    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setTextAlign(Paint.Align.CENTER);
    mPaint.setTextSize(mOverlaySize / 2);

    ColorStateList textColor = ta.getColorStateList(TEXT_COLOR);
    int textColorNormal = textColor.getDefaultColor();
    mPaint.setColor(textColorNormal);
    mPaint.setStyle(Paint.Style.FILL_AND_STROKE);

    // to show mOverlayDrawable properly
    if (mList.getWidth() > 0 && mList.getHeight() > 0) {
        onSizeChanged(mList.getWidth(), mList.getHeight(), 0, 0);
    }

    mState = STATE_NONE;
    refreshDrawableState();

    ta.recycle();

    mScaledTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    mMatchDragPosition = context
            .getApplicationInfo().targetSdkVersion >= android.os.Build.VERSION_CODES.HONEYCOMB;

    setScrollbarPosition(Compat.getVerticalScrollbarPosition(mList));
}

From source file:com.common.widget.hzlib.FastScroller.java

private void init(Context context) {
    // Get both the scrollbar states drawables
    TypedArray ta = context.getTheme().obtainStyledAttributes(ATTRS);
    useThumbDrawable(context, ta.getDrawable(THUMB_DRAWABLE));
    mTrackDrawable = ta.getDrawable(TRACK_DRAWABLE);

    mOverlayDrawableLeft = ta.getDrawable(PREVIEW_BACKGROUND_LEFT);
    mOverlayDrawableRight = ta.getDrawable(PREVIEW_BACKGROUND_RIGHT);
    mOverlayPosition = ta.getInt(OVERLAY_POSITION, OVERLAY_FLOATING);

    mScrollCompleted = true;//w ww . j av a 2s .c  o  m

    getSectionsFromIndexer();

    mOverlaySize = context.getResources().getDimensionPixelSize(R.dimen.fastscroll_overlay_size);
    mOverlayPos = new RectF();
    mScrollFade = new ScrollFade();
    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setTextAlign(Paint.Align.CENTER);
    mPaint.setTextSize(mOverlaySize / 2);

    ColorStateList textColor = ta.getColorStateList(TEXT_COLOR);
    int textColorNormal = textColor.getDefaultColor();
    mPaint.setColor(textColorNormal);
    mPaint.setStyle(Paint.Style.FILL_AND_STROKE);

    // to show mOverlayDrawable properly
    if (mList.getWidth() > 0 && mList.getHeight() > 0) {
        onSizeChanged(mList.getWidth(), mList.getHeight(), 0, 0);
    }

    mState = STATE_NONE;
    refreshDrawableState();

    ta.recycle();

    mScaledTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    mMatchDragPosition = context
            .getApplicationInfo().targetSdkVersion >= android.os.Build.VERSION_CODES.HONEYCOMB;

    setScrollbarPosition(mList.getVerticalScrollbarPosition());
}