Example usage for android.content.res TypedArray getInteger

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

Introduction

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

Prototype

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

Source Link

Document

Retrieve the integer value for the attribute at index.

Usage

From source file:com.hezaijin.advance.widgets.view.progress.DiscreteSeekBar.java

public DiscreteSeekBar(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setFocusable(true);//  w ww  . j  a  v a2s  .  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.DiscreteSeekBar,
            R.attr.discreteSeekBarStyle, defStyle);

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

    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[] { 0xff009688 });
    }
    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);

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

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

    setNumericTransformer(new DefaultNumericTransformer());

}

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

public TitlePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;//from  ww w .ja v  a 2 s. co  m

    // Load defaults from resources
    final Resources res = getResources();
    final int defaultFooterColor = res.getColor(context.getResources()
            .getIdentifier("default_title_indicator_footer_color", "color", context.getPackageName()));
    // final int defaultFooterColor = res
    // .getColor(R.color.default_title_indicator_footer_color);
    final float defaultFooterLineHeight = res.getDimension(context.getResources()
            .getIdentifier("default_title_indicator_footer_line_height", "dimen", context.getPackageName()));
    // final float defaultFooterLineHeight = res
    // .getDimension(R.dimen.default_title_indicator_footer_line_height);
    final int defaultFooterIndicatorStyle = res.getInteger(context.getResources().getIdentifier(
            "default_title_indicator_footer_indicator_style", "integer", context.getPackageName()));
    // final int defaultFooterIndicatorStyle = res
    // .getInteger(R.integer.default_title_indicator_footer_indicator_style);
    final float defaultFooterIndicatorHeight = res.getDimension(context.getResources().getIdentifier(
            "default_title_indicator_footer_indicator_height", "dimen", context.getPackageName()));
    // final float defaultFooterIndicatorHeight = res
    // .getDimension(R.dimen.default_title_indicator_footer_indicator_height);
    final float defaultFooterIndicatorUnderlinePadding = res.getDimension(context.getResources().getIdentifier(
            "default_title_indicator_footer_indicator_underline_padding", "dimen", context.getPackageName()));
    // final float defaultFooterIndicatorUnderlinePadding = res
    // .getDimension(R.dimen.default_title_indicator_footer_indicator_underline_padding);
    final float defaultFooterPadding = res.getDimension(context.getResources()
            .getIdentifier("default_title_indicator_footer_padding", "dimen", context.getPackageName()));
    // final float defaultFooterPadding = res
    // .getDimension(R.dimen.default_title_indicator_footer_padding);
    final int defaultLinePosition = res.getInteger(context.getResources()
            .getIdentifier("default_title_indicator_line_position", "integer", context.getPackageName()));
    // final int defaultLinePosition = res
    // .getInteger(R.integer.default_title_indicator_line_position);
    final int defaultSelectedColor = res.getColor(context.getResources()
            .getIdentifier("default_title_indicator_selected_color", "color", context.getPackageName()));
    // final int defaultSelectedColor = res
    // .getColor(R.color.default_title_indicator_selected_color);
    final boolean defaultSelectedBold = res.getBoolean(context.getResources()
            .getIdentifier("default_title_indicator_selected_bold", "bool", context.getPackageName()));
    // final boolean defaultSelectedBold = res
    // .getBoolean(R.bool.default_title_indicator_selected_bold);
    final int defaultTextColor = res.getColor(context.getResources()
            .getIdentifier("default_title_indicator_text_color", "color", context.getPackageName()));
    // final int defaultTextColor = res
    // .getColor(R.color.default_title_indicator_text_color);
    final float defaultTextSize = res.getDimension(context.getResources()
            .getIdentifier("default_title_indicator_text_size", "dimen", context.getPackageName()));
    // final float defaultTextSize = res
    // .getDimension(R.dimen.default_title_indicator_text_size);
    final float defaultTitlePadding = res.getDimension(context.getResources()
            .getIdentifier("default_title_indicator_title_padding", "dimen", context.getPackageName()));
    // final float defaultTitlePadding = res
    // .getDimension(R.dimen.default_title_indicator_title_padding);
    final float defaultClipPadding = res.getDimension(context.getResources()
            .getIdentifier("default_title_indicator_clip_padding", "dimen", context.getPackageName()));
    // final float defaultClipPadding = res
    // .getDimension(R.dimen.default_title_indicator_clip_padding);
    final float defaultTopPadding = res.getDimension(context.getResources()
            .getIdentifier("default_title_indicator_top_padding", "dimen", context.getPackageName()));
    // final float defaultTopPadding = res
    // .getDimension(R.dimen.default_title_indicator_top_padding);

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

    // Retrieve the colors to be used for this view and apply them.
    mFooterLineHeight = a.getDimension(getResources().getIdentifier("TitlePageIndicator_footerLineHeight",
            "styleable", context.getPackageName()), defaultFooterLineHeight);
    // mFooterLineHeight = a.getDimension(
    // R.styleable.TitlePageIndicator_footerLineHeight,
    // defaultFooterLineHeight);
    mFooterIndicatorStyle = IndicatorStyle
            .fromValue(a.getInteger(getResources().getIdentifier("TitlePageIndicator_footerIndicatorStyle",
                    "styleable", context.getPackageName()), defaultFooterIndicatorStyle));
    // mFooterIndicatorStyle = IndicatorStyle.fromValue(a.getInteger(
    // R.styleable.TitlePageIndicator_footerIndicatorStyle,
    // defaultFooterIndicatorStyle));
    mFooterIndicatorHeight = a.getDimension(getResources()
            .getIdentifier("TitlePageIndicator_footerIndicatorHeight", "styleable", context.getPackageName()),
            defaultFooterIndicatorHeight);
    // mFooterIndicatorHeight = a.getDimension(
    // R.styleable.TitlePageIndicator_footerIndicatorHeight,
    // defaultFooterIndicatorHeight);
    mFooterIndicatorUnderlinePadding = a
            .getDimension(getResources().getIdentifier("TitlePageIndicator_footerIndicatorUnderlinePadding",
                    "styleable", context.getPackageName()), defaultFooterIndicatorUnderlinePadding);
    // mFooterIndicatorUnderlinePadding = a.getDimension(
    // R.styleable.TitlePageIndicator_footerIndicatorUnderlinePadding,
    // defaultFooterIndicatorUnderlinePadding);
    mFooterPadding = a.getDimension(getResources().getIdentifier("TitlePageIndicator_footerPadding",
            "styleable", context.getPackageName()), defaultFooterPadding);
    // mFooterPadding = a.getDimension(
    // R.styleable.TitlePageIndicator_footerPadding,
    // defaultFooterPadding);
    mLinePosition = LinePosition
            .fromValue(a.getInteger(getResources().getIdentifier("TitlePageIndicator_linePosition", "styleable",
                    context.getPackageName()), defaultLinePosition));
    // mLinePosition = LinePosition.fromValue(a.getInteger(
    // R.styleable.TitlePageIndicator_linePosition,
    // defaultLinePosition));
    mTopPadding = a.getDimension(getResources().getIdentifier("TitlePageIndicator_topPadding", "styleable",
            context.getPackageName()), defaultTopPadding);
    // mTopPadding =
    // a.getDimension(R.styleable.TitlePageIndicator_topPadding,
    // defaultTopPadding);
    mTitlePadding = a.getDimension(getResources().getIdentifier("TitlePageIndicator_titlePadding", "styleable",
            context.getPackageName()), defaultTitlePadding);
    // mTitlePadding = a.getDimension(
    // R.styleable.TitlePageIndicator_titlePadding,
    // defaultTitlePadding);
    mClipPadding = a.getDimension(getResources().getIdentifier("TitlePageIndicator_clipPadding", "styleable",
            context.getPackageName()), defaultClipPadding);
    // mClipPadding = a.getDimension(
    // R.styleable.TitlePageIndicator_clipPadding, defaultClipPadding);
    mColorSelected = a.getColor(getResources().getIdentifier("TitlePageIndicator_selectedColor", "styleable",
            context.getPackageName()), defaultSelectedColor);
    // mColorSelected = a.getColor(
    // R.styleable.TitlePageIndicator_selectedColor,
    // defaultSelectedColor);
    mColorText = a.getColor(getResources().getIdentifier("TitlePageIndicator_android_textColor", "styleable",
            context.getPackageName()), defaultTextColor);
    // mColorText = a.getColor(
    // R.styleable.TitlePageIndicator_android_textColor,
    // defaultTextColor);
    mBoldText = a.getBoolean(getResources().getIdentifier("TitlePageIndicator_selectedBold", "styleable",
            context.getPackageName()), defaultSelectedBold);
    // mBoldText = a.getBoolean(R.styleable.TitlePageIndicator_selectedBold,
    // defaultSelectedBold);

    final float textSize = a.getDimension(getResources().getIdentifier("TitlePageIndicator_android_textSize",
            "styleable", context.getPackageName()), defaultTextSize);
    // final float textSize = a.getDimension(
    // R.styleable.TitlePageIndicator_android_textSize,
    // defaultTextSize);
    final int footerColor = a.getColor(getResources().getIdentifier("TitlePageIndicator_footerColor",
            "styleable", context.getPackageName()), defaultFooterColor);
    // final int footerColor = a.getColor(
    // R.styleable.TitlePageIndicator_footerColor, defaultFooterColor);
    mPaintText.setTextSize(textSize);
    mPaintText.setAntiAlias(true);
    mPaintFooterLine.setStyle(Paint.Style.FILL_AND_STROKE);
    mPaintFooterLine.setStrokeWidth(mFooterLineHeight);
    mPaintFooterLine.setColor(footerColor);
    mPaintFooterIndicator.setStyle(Paint.Style.FILL_AND_STROKE);
    mPaintFooterIndicator.setColor(footerColor);

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

    a.recycle();

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

From source file:com.doomy.library.DiscreteSeekBar.java

public DiscreteSeekBar(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setFocusable(true);/*  w ww .j a  v  a2 s.  com*/
    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.DiscreteSeekBar,
            R.attr.discreteSeekBarStyle, defStyle);

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

    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[] { 0xff009688 });
    }
    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);

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

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

    setNumericTransformer(new DefaultNumericTransformer());

}

From source file:io.plaidapp.core.ui.widget.CollapsingTitleLayout.java

private void parseTextAttrs(TypedArray ta) {
    if (ta.hasValue(R.styleable.CollapsingTitleLayout_collapsedTextSize)) {
        collapsedTextSize = ta.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_collapsedTextSize, 0);
        paint.setTextSize(collapsedTextSize);
    }/*w  w w . ja v  a 2 s .com*/
    if (ta.hasValue(R.styleable.CollapsingTitleLayout_android_textColor)) {
        paint.setColor(ta.getColor(R.styleable.CollapsingTitleLayout_android_textColor, Color.WHITE));
    }
    if (ta.hasValue(R.styleable.CollapsingTitleLayout_android_fontFamily)) {
        try {
            fontResId = ta.getResourceId(R.styleable.CollapsingTitleLayout_android_fontFamily, 0);
            Typeface font = ResourcesCompat.getFont(getContext(), fontResId);
            if (font != null) {
                paint.setTypeface(font);
            }
        } catch (Resources.NotFoundException nfe) {
            // swallow; use default typeface
        }
    }
    if (ta.hasValue(R.styleable.CollapsingTitleLayout_maxExpandedTextSize)) {
        maxExpandedTextSize = ta.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_maxExpandedTextSize,
                Integer.MAX_VALUE);
    }
    if (ta.hasValue(R.styleable.CollapsingTitleLayout_lineHeightHint)) {
        lineHeightHint = ta.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_lineHeightHint, 0);
    }
    if (ta.hasValue(R.styleable.CollapsingTitleLayout_android_maxLines)) {
        maxLines = ta.getInteger(R.styleable.CollapsingTitleLayout_android_maxLines, 5);
    }
}

From source file:com.acious.android.paginationseekbar.PaginationSeekBar.java

public PaginationSeekBar(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setFocusable(true);/*from   ww  w  .  j a  va  2 s  .c om*/
    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.PaginationSeekBar,
            R.attr.paginationSeekBarStyle, defStyle);

    int max = 100;
    int min = 0;
    int value = 1;
    mMirrorForRtl = a.getBoolean(R.styleable.PaginationSeekBar_psb_mirrorForRtl, mMirrorForRtl);
    mAllowTrackClick = a.getBoolean(R.styleable.PaginationSeekBar_psb_allowTrackClickToDrag, mAllowTrackClick);

    int indexMax = R.styleable.PaginationSeekBar_psb_max;
    int indexMin = R.styleable.PaginationSeekBar_psb_min;
    int indexValue = R.styleable.PaginationSeekBar_psb_value;
    pageCountPerOneBoard = R.styleable.PaginationSeekBar_psb_pageCountPerOneBoard;
    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);
        }
    }
    if (a.getValue(pageCountPerOneBoard, out)) {
        pageCountPerOneBoard = a.getInteger(pageCountPerOneBoard, pageCountPerOneBoard);
    }
    mMin = min;
    mMax = Math.max(min + 1, max);
    mValue = Math.max(min, Math.min(max, value));
    updateKeyboardRange();

    mPrevPageText = a.getString(R.styleable.PaginationSeekBar_psb_indicatorPrevPageText);
    mNextPageText = a.getString(R.styleable.PaginationSeekBar_psb_indicatorNextPageText);
    mIndicatorFormatter = a.getString(R.styleable.PaginationSeekBar_psb_indicatorFormatter);

    ColorStateList trackColor = a.getColorStateList(R.styleable.PaginationSeekBar_psb_trackColor);
    ColorStateList progressColor = a.getColorStateList(R.styleable.PaginationSeekBar_psb_progressColor);
    ColorStateList rippleColor = a.getColorStateList(R.styleable.PaginationSeekBar_psb_rippleColor);
    int thumbTextColor = a.getColor(R.styleable.PaginationSeekBar_psb_thumbTextColor, Color.WHITE);
    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[] { 0xff009688 });
    }
    if (editMode && thumbTextColor == 0) {
        thumbTextColor = Color.WHITE;
    }
    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);

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

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

    setNumericTransformer(new DefaultNumericTransformer());

    initPagecountPerOneboard(pageCountPerOneBoard);

}

From source file:com.wl.tabguidance.utils.TabLayoutTitleStrip.java

public TabLayoutTitleStrip(final Context context, final AttributeSet attrs, final int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    //Init NTS/*from w ww  .j  av a 2 s  .com*/

    // Always draw
    setWillNotDraw(false);
    // Speed and fix for pre 17 API
    ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, null);
    setLayerType(LAYER_TYPE_SOFTWARE, null);

    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.TabTitleStrip);
    try {
        setStripColor(typedArray.getColor(R.styleable.TabTitleStrip_nts_color, DEFAULT_STRIP_COLOR));
        setTitleSize(typedArray.getDimension(R.styleable.TabTitleStrip_nts_size, DEFAULT_TITLE_SIZE));
        setStripWeight(typedArray.getDimension(R.styleable.TabTitleStrip_nts_weight, DEFAULT_STRIP_WEIGHT));
        setStripFactor(typedArray.getFloat(R.styleable.TabTitleStrip_nts_factor, DEFAULT_STRIP_FACTOR));
        setStripType(typedArray.getInt(R.styleable.TabTitleStrip_nts_type, StripType.LINE_INDEX));
        setStripGravity(typedArray.getInt(R.styleable.TabTitleStrip_nts_gravity, StripGravity.BOTTOM_INDEX));

        setTypeface(typedArray.getString(R.styleable.TabTitleStrip_nts_typeface));
        setInactiveColor(
                typedArray.getColor(R.styleable.TabTitleStrip_nts_inactive_color, DEFAULT_INACTIVE_COLOR));
        setActiveColor(typedArray.getColor(R.styleable.TabTitleStrip_nts_active_color, DEFAULT_ACTIVE_COLOR));
        setAnimationDuration(typedArray.getInteger(R.styleable.TabTitleStrip_nts_animation_duration,
                DEFAULT_ANIMATION_DURATION));
        setCornersRadius(
                typedArray.getDimension(R.styleable.TabTitleStrip_nts_corners_radius, DEFAULT_CORNER_RADIUS));

        // Get titles
        String[] titles = null;
        try {
            final int titlesResId = typedArray.getResourceId(R.styleable.TabTitleStrip_nts_titles, 0);
            titles = titlesResId == 0 ? null : typedArray.getResources().getStringArray(titlesResId);
        } catch (Exception exception) {
            titles = null;
            exception.printStackTrace();
        } finally {
            if (titles == null) {
                if (isInEditMode()) {
                    titles = new String[new Random().nextInt(5) + 1];
                    Arrays.fill(titles, PREVIEW_TITLE);
                } else
                    titles = new String[0];
            }

            setTitles(titles);
        }

        // Init animator
        mAnimator.setFloatValues(MIN_FRACTION, MAX_FRACTION);
        mAnimator.setInterpolator(new LinearInterpolator());
        mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(final ValueAnimator animation) {
                updateIndicatorPosition((Float) animation.getAnimatedValue());
            }
        });
    } finally {
        typedArray.recycle();
    }
}

From source file:org.androfarsh.widget.DragGridLayout.java

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

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

    mDebugMode = a.getBoolean(R.styleable.DragGridLayout_debug_mode, mDebugMode);
    mCellDrawable = a.getDrawable(R.styleable.DragGridLayout_cell_drawable);
    mHighlightDrawable = a.getDrawable(R.styleable.DragGridLayout_highlight_drawable);
    setCellCount(a.getInteger(R.styleable.DragGridLayout_cell_count, DEFAULT_CELL_COUNT));
    mGravity = a.getInteger(R.styleable.DragGridLayout_android_gravity, DEFAULT_GRAVITY);

    final int rootViewRes = a.getResourceId(R.styleable.DragGridLayout_root_layout, UNKNOWN);
    if (rootViewRes != UNKNOWN) {
        String resTypeName = getResources().getResourceTypeName(rootViewRes);
        if ("layout".equals(resTypeName)) {
            setRootViewRes(rootViewRes);
        } else if ("id".equals(resTypeName)) {
            mRootViewId = rootViewRes;/*w  w  w. j av  a  2 s . co  m*/
        }
    }

    a.recycle();

    init();
}

From source file:com.github.shareme.gwsmaterialuikit.library.material.widget.TabPageIndicator.java

protected void applyStyle(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TabPageIndicator, defStyleAttr,
            defStyleRes);/*www  .j a  va2  s. co m*/

    int textAppearance = 0;
    int mode = -1;
    int rippleStyle = 0;

    for (int i = 0, count = a.getIndexCount(); i < count; i++) {
        int attr = a.getIndex(i);
        if (attr == R.styleable.TabPageIndicator_tpi_tabPadding)
            mTabPadding = a.getDimensionPixelSize(attr, 0);
        else if (attr == R.styleable.TabPageIndicator_tpi_tabRipple)
            rippleStyle = a.getResourceId(attr, 0);
        else if (attr == R.styleable.TabPageIndicator_tpi_indicatorColor)
            mPaint.setColor(a.getColor(attr, 0));
        else if (attr == R.styleable.TabPageIndicator_tpi_indicatorHeight)
            mIndicatorHeight = a.getDimensionPixelSize(attr, 0);
        else if (attr == R.styleable.TabPageIndicator_tpi_indicatorAtTop)
            mIndicatorAtTop = a.getBoolean(attr, true);
        else if (attr == R.styleable.TabPageIndicator_tpi_tabSingleLine)
            mTabSingleLine = a.getBoolean(attr, true);
        else if (attr == R.styleable.TabPageIndicator_android_textAppearance)
            textAppearance = a.getResourceId(attr, 0);
        else if (attr == R.styleable.TabPageIndicator_tpi_mode)
            mode = a.getInteger(attr, 0);
    }

    a.recycle();

    if (mTabPadding < 0)
        mTabPadding = ThemeUtil.dpToPx(context, 12);

    if (mIndicatorHeight < 0)
        mIndicatorHeight = ThemeUtil.dpToPx(context, 2);

    if (mode >= 0) {
        if (mMode != mode || getChildCount() == 0) {
            mMode = mode;
            removeAllViews();
            if (mMode == MODE_SCROLL) {
                addView(mTabContainer, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                        ViewGroup.LayoutParams.MATCH_PARENT));
                setFillViewport(false);
            } else if (mMode == MODE_FIXED) {
                addView(mTabContainer, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.MATCH_PARENT));
                setFillViewport(true);
            }
        }
    }

    if (textAppearance != 0 && mTextAppearance != textAppearance) {
        mTextAppearance = textAppearance;
        for (int i = 0, count = mTabContainer.getChildCount(); i < count; i++) {
            CheckedTextView tv = (CheckedTextView) mTabContainer.getChildAt(i);
            tv.setTextAppearance(context, mTextAppearance);
        }
    }

    if (rippleStyle != 0 && rippleStyle != mTabRippleStyle) {
        mTabRippleStyle = rippleStyle;
        for (int i = 0, count = mTabContainer.getChildCount(); i < count; i++)
            ViewUtil.setBackground(mTabContainer.getChildAt(i),
                    new RippleDrawable.Builder(getContext(), mTabRippleStyle).build());
    }

    if (mViewPager != null)
        notifyDataSetChanged();
    requestLayout();
}

From source file:com.fuzz.indicator.CutoutViewIndicator.java

@SuppressWarnings("ResourceType")
protected void init(Context context, AttributeSet attrs, int defStyleAttr) {
    if (attrs != null) {
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CutoutViewIndicator);
        setIndicatorDrawableId(a.getResourceId(R.styleable.CutoutViewIndicator_rcv_drawable, 0));
        setInternalSpacing(a.getDimensionPixelOffset(R.styleable.CutoutViewIndicator_rcv_internal_margin, 0));

        // The superclass will have resolved orientation by now.
        if (getOrientation() == HORIZONTAL) {
            setPerpendicularLength(//from  w  w w  . j  a  v a2s. c o  m
                    a.getDimensionPixelSize(R.styleable.CutoutViewIndicator_rcv_height, WRAP_CONTENT));
            setCellLength(a.getDimensionPixelOffset(R.styleable.CutoutViewIndicator_rcv_width, WRAP_CONTENT));
        } else {
            setPerpendicularLength(
                    a.getDimensionPixelSize(R.styleable.CutoutViewIndicator_rcv_width, WRAP_CONTENT));
            setCellLength(a.getDimensionPixelOffset(R.styleable.CutoutViewIndicator_rcv_height, WRAP_CONTENT));
        }

        if (isInEditMode()) {
            editModePageCount = a.getInteger(R.styleable.CutoutViewIndicator_rcv_tools_indicator_count, 2);
        }

        String generatorName = a.getString(R.styleable.CutoutViewIndicator_rcv_generator_class_name);
        if (generatorName != null) {
            CCGFactory.constructGeneratorFrom(context, attrs, defStyleAttr, generatorName,
                    new ConstructorCallback() {
                        @Override
                        public void onGenerated(@NonNull CutoutCellGenerator generated) {
                            CutoutViewIndicator.this.generator = generated;
                        }

                        @Override
                        public void onFailed(@NonNull String message) {
                            if (!message.isEmpty()) {
                                Log.e(TAG, message);
                                if (isInEditMode()) {
                                    String tag = "resources.invalid";
                                    logger.logToLayoutLib(tag, message);
                                }
                            }
                        }
                    });

        }

        setCellBackgroundId(a.getResourceId(R.styleable.CutoutViewIndicator_rcv_drawable_unselected, 0));
        a.recycle();
    }
    if (isInEditMode()) {
        setStateProxy(EDIT_MODE_PROXY);
    }
}

From source file:com.appsummary.luoxf.myappsummary.navigationtabstrip.NavigationTabStrip.java

public NavigationTabStrip(final Context context, final AttributeSet attrs, final int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    //Init NTS/*from   w ww  .j  av  a  2 s . c  om*/

    // Always draw
    setWillNotDraw(false);
    // More speed!
    setLayerType(LAYER_TYPE_HARDWARE, null);

    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NavigationTabStrip);
    try {
        setStripColor(typedArray.getColor(R.styleable.NavigationTabStrip_nts_color, DEFAULT_STRIP_COLOR));
        setTitleSize(typedArray.getDimension(R.styleable.NavigationTabStrip_nts_size, DEFAULT_TITLE_SIZE));
        setStripWeight(
                typedArray.getDimension(R.styleable.NavigationTabStrip_nts_weight, DEFAULT_STRIP_WEIGHT));
        setStripFactor(typedArray.getFloat(R.styleable.NavigationTabStrip_nts_factor, DEFAULT_STRIP_FACTOR));
        setStripType(typedArray.getInt(R.styleable.NavigationTabStrip_nts_type, StripType.LINE_INDEX));
        setStripGravity(
                typedArray.getInt(R.styleable.NavigationTabStrip_nts_gravity, StripGravity.BOTTOM_INDEX));

        setTypeface(typedArray.getString(R.styleable.NavigationTabStrip_nts_typeface));
        setInactiveColor(
                typedArray.getColor(R.styleable.NavigationTabStrip_nts_inactive_color, DEFAULT_INACTIVE_COLOR));
        setActiveColor(
                typedArray.getColor(R.styleable.NavigationTabStrip_nts_active_color, DEFAULT_ACTIVE_COLOR));
        setAnimationDuration(typedArray.getInteger(R.styleable.NavigationTabStrip_nts_animation_duration,
                DEFAULT_ANIMATION_DURATION));
        setCornersRadius(typedArray.getDimension(R.styleable.NavigationTabStrip_nts_corners_radius,
                DEFAULT_CORNER_RADIUS));

        // Get titles
        String[] titles = null;
        try {
            final int titlesResId = typedArray.getResourceId(R.styleable.NavigationTabStrip_nts_titles, 0);
            titles = titlesResId == 0 ? null : typedArray.getResources().getStringArray(titlesResId);
        } catch (Exception exception) {
            titles = null;
            exception.printStackTrace();
        } finally {
            if (titles == null) {
                if (isInEditMode()) {
                    titles = new String[new Random().nextInt(5) + 1];
                    Arrays.fill(titles, PREVIEW_TITLE);
                } else
                    titles = new String[0];
            }

            setTitles(titles);
        }

        // Init animator
        mAnimator.setFloatValues(MIN_FRACTION, MAX_FRACTION);
        mAnimator.setInterpolator(new LinearInterpolator());
        mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(final ValueAnimator animation) {
                updateIndicatorPosition((Float) animation.getAnimatedValue());
            }
        });
    } finally {
        typedArray.recycle();
    }
}