Example usage for android.content.res TypedArray getValue

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

Introduction

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

Prototype

public boolean getValue(@StyleableRes int index, TypedValue outValue) 

Source Link

Document

Retrieve the raw TypedValue for the attribute at index.

Usage

From source file:com.flashgugu.library.widgets.paginationseekbar.PaginationSeekBar.java

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

    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));
        mIndicator.setListener(mFloaterListener);
    }
    a.recycle();

    setNumericTransformer(new DefaultNumericTransformer());

    initPagecountPerOneboard(pageCountPerOneBoard);

}

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

public DiscreteSeekBar(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    setFocusable(true);//from w  w  w .  jav a  2  s  . 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, 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);
    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));
        mIndicator.setListener(mFloaterListener);
    }
    a.recycle();

    setNumericTransformer(new DefaultNumericTransformer());

}

From source file:com.mightyworkouts.seekbar.DiscreteSeekBar.java

public DiscreteSeekBar(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    MightyWorkoutHelper.printLog(CommonUtils.WARN, this.getClass().getName(), "CONSTRUCTOR DiscreteSeekBar");
    setFocusable(true);//from  w w w.  j  a v  a  2s  .  c o  m

    setWillNotDraw(false);

    /*bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.green_slider_thumb)
        .copy(Bitmap.Config.ARGB_8888, true);*/

    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    float density = context.getResources().getDisplayMetrics().density;
    mTrackHeight = (int) (4 * 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, 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);
    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(context, rippleColor);
    if (isLollipopOrGreater) {
        SeekBarCompat.setBackground(this, mRipple);
    } else {
        mRipple.setCallback(this);
    }

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

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

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

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

    setNumericTransformer(new DefaultNumericTransformer());

}

From source file:android.support.v7ox.app.AppCompatDelegateImplV7.java

private void applyFixedSizeWindow() {
    ContentFrameLayout cfl = (ContentFrameLayout) mSubDecor.findViewById(android.R.id.content);

    // This is a bit weird. In the framework, the window sizing attributes control
    // the decor view's size, meaning that any padding is inset for the min/max widths below.
    // We don't control measurement at that level, so we need to workaround it by making sure
    // that the decor view's padding is taken into account.
    final View windowDecor = mWindow.getDecorView();
    cfl.setDecorPadding(windowDecor.getPaddingLeft(), windowDecor.getPaddingTop(),
            windowDecor.getPaddingRight(), windowDecor.getPaddingBottom());

    TypedArray a = mContext.obtainStyledAttributes(R.styleable.AppCompatTheme);
    a.getValue(R.styleable.AppCompatTheme_windowMinWidthMajor_ox, cfl.getMinWidthMajor());
    a.getValue(R.styleable.AppCompatTheme_windowMinWidthMinor_ox, cfl.getMinWidthMinor());

    if (a.hasValue(R.styleable.AppCompatTheme_windowFixedWidthMajor_ox)) {
        a.getValue(R.styleable.AppCompatTheme_windowFixedWidthMajor_ox, cfl.getFixedWidthMajor());
    }//  w w w .j  ava 2s . c  om
    if (a.hasValue(R.styleable.AppCompatTheme_windowFixedWidthMinor_ox)) {
        a.getValue(R.styleable.AppCompatTheme_windowFixedWidthMinor_ox, cfl.getFixedWidthMinor());
    }
    if (a.hasValue(R.styleable.AppCompatTheme_windowFixedHeightMajor_ox)) {
        a.getValue(R.styleable.AppCompatTheme_windowFixedHeightMajor_ox, cfl.getFixedHeightMajor());
    }
    if (a.hasValue(R.styleable.AppCompatTheme_windowFixedHeightMinor_ox)) {
        a.getValue(R.styleable.AppCompatTheme_windowFixedHeightMinor_ox, cfl.getFixedHeightMinor());
    }
    a.recycle();

    cfl.requestLayout();
}

From source file:android.support.v7.app.AppCompatDelegateImplV7.java

private void applyFixedSizeWindow() {
    TypedArray a = mContext.obtainStyledAttributes(R.styleable.Theme);

    TypedValue mFixedWidthMajor = null;/*from   www  .  j  ava 2s .  c  o m*/
    TypedValue mFixedWidthMinor = null;
    TypedValue mFixedHeightMajor = null;
    TypedValue mFixedHeightMinor = null;

    if (a.hasValue(R.styleable.Theme_windowFixedWidthMajor)) {
        if (mFixedWidthMajor == null)
            mFixedWidthMajor = new TypedValue();
        a.getValue(R.styleable.Theme_windowFixedWidthMajor, mFixedWidthMajor);
    }
    if (a.hasValue(R.styleable.Theme_windowFixedWidthMinor)) {
        if (mFixedWidthMinor == null)
            mFixedWidthMinor = new TypedValue();
        a.getValue(R.styleable.Theme_windowFixedWidthMinor, mFixedWidthMinor);
    }
    if (a.hasValue(R.styleable.Theme_windowFixedHeightMajor)) {
        if (mFixedHeightMajor == null)
            mFixedHeightMajor = new TypedValue();
        a.getValue(R.styleable.Theme_windowFixedHeightMajor, mFixedHeightMajor);
    }
    if (a.hasValue(R.styleable.Theme_windowFixedHeightMinor)) {
        if (mFixedHeightMinor == null)
            mFixedHeightMinor = new TypedValue();
        a.getValue(R.styleable.Theme_windowFixedHeightMinor, mFixedHeightMinor);
    }

    final DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
    final boolean isPortrait = metrics.widthPixels < metrics.heightPixels;
    int w = ViewGroup.LayoutParams.MATCH_PARENT;
    int h = ViewGroup.LayoutParams.MATCH_PARENT;

    final TypedValue tvw = isPortrait ? mFixedWidthMinor : mFixedWidthMajor;
    if (tvw != null && tvw.type != TypedValue.TYPE_NULL) {
        if (tvw.type == TypedValue.TYPE_DIMENSION) {
            w = (int) tvw.getDimension(metrics);
        } else if (tvw.type == TypedValue.TYPE_FRACTION) {
            w = (int) tvw.getFraction(metrics.widthPixels, metrics.widthPixels);
        }
    }

    final TypedValue tvh = isPortrait ? mFixedHeightMajor : mFixedHeightMinor;
    if (tvh != null && tvh.type != TypedValue.TYPE_NULL) {
        if (tvh.type == TypedValue.TYPE_DIMENSION) {
            h = (int) tvh.getDimension(metrics);
        } else if (tvh.type == TypedValue.TYPE_FRACTION) {
            h = (int) tvh.getFraction(metrics.heightPixels, metrics.heightPixels);
        }
    }

    if (w != ViewGroup.LayoutParams.MATCH_PARENT || h != ViewGroup.LayoutParams.MATCH_PARENT) {
        mWindow.setLayout(w, h);
    }

    a.recycle();
}

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

public DiscreteSlider(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    setFocusable(true);// ww  w.ja  v  a2 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.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.klinker.deskclock.widget.multiwaveview.GlowPadView.java

public GlowPadView(Context context, AttributeSet attrs) {
    super(context, attrs);
    Resources res = context.getResources();

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GlowPadView);
    mInnerRadius = a.getDimension(R.styleable.GlowPadView_innerRadius, mInnerRadius);
    mOuterRadius = a.getDimension(R.styleable.GlowPadView_outerRadius, mOuterRadius);
    mSnapMargin = a.getDimension(R.styleable.GlowPadView_snapMargin, mSnapMargin);
    mVibrationDuration = a.getInt(R.styleable.GlowPadView_vibrationDuration, mVibrationDuration);
    mFeedbackCount = a.getInt(R.styleable.GlowPadView_feedbackCount, mFeedbackCount);
    TypedValue handle = a.peekValue(R.styleable.GlowPadView_handleDrawable);
    mHandleDrawable = new TargetDrawable(res, handle != null ? handle.resourceId : 0, 2);
    mHandleDrawable.setState(TargetDrawable.STATE_INACTIVE);
    mOuterRing = new TargetDrawable(res, getResourceId(a, R.styleable.GlowPadView_outerRingDrawable), 1);

    mAlwaysTrackFinger = a.getBoolean(R.styleable.GlowPadView_alwaysTrackFinger, false);

    int pointId = getResourceId(a, R.styleable.GlowPadView_pointDrawable);
    Drawable pointDrawable = pointId != 0 ? res.getDrawable(pointId) : null;
    mGlowRadius = a.getDimension(R.styleable.GlowPadView_glowRadius, 0.0f);

    TypedValue outValue = new TypedValue();

    // Read array of target drawables
    if (a.getValue(R.styleable.GlowPadView_targetDrawables, outValue)) {
        internalSetTargetResources(outValue.resourceId);
    }//w w w . jav a  2s . c  o  m
    if (mTargetDrawables == null || mTargetDrawables.size() == 0) {
        throw new IllegalStateException("Must specify at least one target drawable");
    }

    // Read array of target descriptions
    if (a.getValue(R.styleable.GlowPadView_targetDescriptions, outValue)) {
        final int resourceId = outValue.resourceId;
        if (resourceId == 0) {
            throw new IllegalStateException("Must specify target descriptions");
        }
        setTargetDescriptionsResourceId(resourceId);
    }

    // Read array of direction descriptions
    if (a.getValue(R.styleable.GlowPadView_directionDescriptions, outValue)) {
        final int resourceId = outValue.resourceId;
        if (resourceId == 0) {
            throw new IllegalStateException("Must specify direction descriptions");
        }
        setDirectionDescriptionsResourceId(resourceId);
    }

    a.recycle();

    // Use gravity attribute from LinearLayout
    //a = context.obtainStyledAttributes(attrs, R.styleable.LinearLayout);
    mGravity = a.getInt(R.styleable.GlowPadView_android_gravity, Gravity.TOP);
    a.recycle();

    setVibrateEnabled(mVibrationDuration > 0);

    assignDefaultsIfNeeded();

    mPointCloud = new PointCloud(pointDrawable);
    mPointCloud.makePointCloud(mInnerRadius, mOuterRadius);
    mPointCloud.glowManager.setRadius(mGlowRadius);
}

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.  j  ava 2s.  co  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.android.incallui.widget.multiwaveview.GlowPadView.java

public GlowPadView(Context context, AttributeSet attrs) {
    super(context, attrs);
    Resources res = context.getResources();

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GlowPadView);
    mInnerRadius = a.getDimension(R.styleable.GlowPadView_innerRadius, mInnerRadius);
    mOuterRadius = a.getDimension(R.styleable.GlowPadView_outerRadius, mOuterRadius);
    mSnapMargin = a.getDimension(R.styleable.GlowPadView_snapMargin, mSnapMargin);
    mVibrationDuration = a.getInt(R.styleable.GlowPadView_vibrationDuration, mVibrationDuration);
    mFeedbackCount = a.getInt(R.styleable.GlowPadView_feedbackCount, mFeedbackCount);
    mAllowScaling = a.getBoolean(R.styleable.GlowPadView_allowScaling, false);
    TypedValue handle = a.peekValue(R.styleable.GlowPadView_handleDrawable);
    setHandleDrawable(handle != null ? handle.resourceId : R.drawable.ic_incall_audio_handle);
    mOuterRing = new TargetDrawable(res, getResourceId(a, R.styleable.GlowPadView_outerRingDrawable), 1);

    mAlwaysTrackFinger = a.getBoolean(R.styleable.GlowPadView_alwaysTrackFinger, false);

    int pointId = getResourceId(a, R.styleable.GlowPadView_pointDrawable);
    Drawable pointDrawable = pointId != 0 ? res.getDrawable(pointId) : null;
    mGlowRadius = a.getDimension(R.styleable.GlowPadView_glowRadius, 0.0f);

    TypedValue outValue = new TypedValue();

    // Read array of target drawables
    if (a.getValue(R.styleable.GlowPadView_targetDrawables, outValue)) {
        internalSetTargetResources(outValue.resourceId);
    }/*ww w . ja v  a 2  s  . c  o  m*/
    if (mTargetDrawables == null || mTargetDrawables.size() == 0) {
        throw new IllegalStateException("Must specify at least one target drawable");
    }

    // Read array of target descriptions
    if (a.getValue(R.styleable.GlowPadView_targetDescriptions, outValue)) {
        final int resourceId = outValue.resourceId;
        if (resourceId == 0) {
            throw new IllegalStateException("Must specify target descriptions");
        }
        setTargetDescriptionsResourceId(resourceId);
    }

    // Read array of direction descriptions
    if (a.getValue(R.styleable.GlowPadView_directionDescriptions, outValue)) {
        final int resourceId = outValue.resourceId;
        if (resourceId == 0) {
            throw new IllegalStateException("Must specify direction descriptions");
        }
        setDirectionDescriptionsResourceId(resourceId);
    }

    // Use gravity attribute from LinearLayout
    //a = context.obtainStyledAttributes(attrs, R.styleable.LinearLayout);
    mGravity = a.getInt(R.styleable.GlowPadView_android_gravity, Gravity.TOP);
    a.recycle();

    setVibrateEnabled(mVibrationDuration > 0);

    assignDefaultsIfNeeded();

    mPointCloud = new PointCloud(pointDrawable);
    mPointCloud.makePointCloud(mInnerRadius, mOuterRadius);
    mPointCloud.glowManager.setRadius(mGlowRadius);

    mExploreByTouchHelper = new GlowpadExploreByTouchHelper(this);
    ViewCompat.setAccessibilityDelegate(this, mExploreByTouchHelper);
}

From source file:cn.djangoogle.pull2load.internal.LoadingLayout.java

public LoadingLayout(Context context, final Mode mode, final Orientation scrollDirection, TypedArray attrs) {
    super(context);
    mMode = mode;/*from  ww w.  j av a  2  s  .com*/
    mScrollDirection = scrollDirection;

    switch (scrollDirection) {
    case HORIZONTAL:
        LayoutInflater.from(context).inflate(R.layout.pull2load_header_horizontal, this);
        break;
    case VERTICAL:
    default:
        LayoutInflater.from(context).inflate(R.layout.pull2load_header_vertical, this);
        break;
    }

    mInnerLayout = (FrameLayout) findViewById(R.id.fl_inner);
    mHeaderText = (TextView) mInnerLayout.findViewById(R.id.pull_to_refresh_text);
    mHeaderProgressWheel = (ProgressWheel) mInnerLayout.findViewById(R.id.pull_to_refresh_progress_wheel);
    mSubHeaderText = (TextView) mInnerLayout.findViewById(R.id.pull_to_refresh_sub_text);
    mHeaderImage = (ImageView) mInnerLayout.findViewById(R.id.pull_to_refresh_image);

    LayoutParams lp = (LayoutParams) mInnerLayout.getLayoutParams();

    switch (mode) {
    case PULL_FROM_END:
        lp.gravity = scrollDirection == Orientation.VERTICAL ? Gravity.TOP : Gravity.LEFT;

        // Load in labels
        mPullLabel = context.getString(R.string.pull_to_refresh_from_bottom_pull_label);
        mRefreshingLabel = context.getString(R.string.pull_to_refresh_from_bottom_refreshing_label);
        mReleaseLabel = context.getString(R.string.pull_to_refresh_from_bottom_release_label);
        break;

    case PULL_FROM_START:
    default:
        lp.gravity = scrollDirection == Orientation.VERTICAL ? Gravity.BOTTOM : Gravity.RIGHT;

        // Load in labels
        mPullLabel = context.getString(R.string.pull_to_refresh_pull_label);
        mRefreshingLabel = context.getString(R.string.pull_to_refresh_refreshing_label);
        mReleaseLabel = context.getString(R.string.pull_to_refresh_release_label);
        break;
    }

    if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderBackground)) {
        Drawable background = attrs.getDrawable(R.styleable.PullToRefresh_ptrHeaderBackground);
        if (null != background) {
            ViewCompat.setBackground(this, background);
        }
    }

    if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderTextAppearance)) {
        TypedValue styleID = new TypedValue();
        attrs.getValue(R.styleable.PullToRefresh_ptrHeaderTextAppearance, styleID);
        setTextAppearance(styleID.data);
    }
    if (attrs.hasValue(R.styleable.PullToRefresh_ptrSubHeaderTextAppearance)) {
        TypedValue styleID = new TypedValue();
        attrs.getValue(R.styleable.PullToRefresh_ptrSubHeaderTextAppearance, styleID);
        setSubTextAppearance(styleID.data);
    }

    // Text Color attrs need to be set after TextAppearance attrs
    if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderTextColor)) {
        ColorStateList colors = attrs.getColorStateList(R.styleable.PullToRefresh_ptrHeaderTextColor);
        if (null != colors) {
            setTextColor(colors);
        }
    }
    if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderSubTextColor)) {
        ColorStateList colors = attrs.getColorStateList(R.styleable.PullToRefresh_ptrHeaderSubTextColor);
        if (null != colors) {
            setSubTextColor(colors);
        }
    }

    // Try and get defined drawable from Attrs
    Drawable imageDrawable = null;
    if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawable)) {
        imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawable);
    }

    // Check Specific Drawable from Attrs, these overrite the generic
    // drawable attr above
    switch (mode) {
    case PULL_FROM_START:
    default:
        if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawableStart)) {
            imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawableStart);
        } else if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawableTop)) {
            Pull2LoadCommonUtil.warnDeprecation("ptrDrawableTop", "ptrDrawableStart");
            imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawableTop);
        }
        break;

    case PULL_FROM_END:
        if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawableEnd)) {
            imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawableEnd);
        } else if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawableBottom)) {
            Pull2LoadCommonUtil.warnDeprecation("ptrDrawableBottom", "ptrDrawableEnd");
            imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawableBottom);
        }
        break;
    }

    // If we don't have a user defined drawable, load the default
    if (null == imageDrawable) {
        imageDrawable = ContextCompat.getDrawable(context, getDefaultDrawableResId());
    }

    // Set Drawable, and save width/height
    setLoadingDrawable(imageDrawable);

    reset();
}