Example usage for android.content.res TypedArray getFloat

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

Introduction

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

Prototype

public float getFloat(@StyleableRes int index, float defValue) 

Source Link

Document

Retrieve the float value for the attribute at index.

Usage

From source file:net.opacapp.multilinecollapsingtoolbar.CollapsingTextHelper.java

void setCollapsedTextAppearance(int resId) {
    TypedArray a = mView.getContext().obtainStyledAttributes(resId,
            android.support.v7.appcompat.R.styleable.TextAppearance);
    if (a.hasValue(android.support.v7.appcompat.R.styleable.TextAppearance_android_textColor)) {
        mCollapsedTextColor = a.getColor(
                android.support.v7.appcompat.R.styleable.TextAppearance_android_textColor, mCollapsedTextColor);
    }//w  ww.  ja v a2 s .c  om
    if (a.hasValue(android.support.v7.appcompat.R.styleable.TextAppearance_android_textSize)) {
        mCollapsedTextSize = a.getDimensionPixelSize(
                android.support.v7.appcompat.R.styleable.TextAppearance_android_textSize,
                (int) mCollapsedTextSize);
    }
    mCollapsedShadowColor = a
            .getInt(android.support.v7.appcompat.R.styleable.TextAppearance_android_shadowColor, 0);
    mCollapsedShadowDx = a.getFloat(android.support.v7.appcompat.R.styleable.TextAppearance_android_shadowDx,
            0);
    mCollapsedShadowDy = a.getFloat(android.support.v7.appcompat.R.styleable.TextAppearance_android_shadowDy,
            0);
    mCollapsedShadowRadius = a
            .getFloat(android.support.v7.appcompat.R.styleable.TextAppearance_android_shadowRadius, 0);
    a.recycle();

    if (Build.VERSION.SDK_INT >= 16) {
        mCollapsedTypeface = readFontFamilyTypeface(resId);
    }

    recalculate();
}

From source file:sun.bo.lin.draggable.DraggableView.java

/**
 * Initialize XML attributes.//from  ww  w . j a  v a 2  s .c  o m
 *
 * @param attrs to be analyzed.
 */
private void initializeAttributes(AttributeSet attrs) {
    TypedArray attributes = getContext().obtainStyledAttributes(attrs, R.styleable.draggable_view);
    this.enableHorizontalAlphaEffect = attributes.getBoolean(
            R.styleable.draggable_view_enable_minimized_horizontal_alpha_effect,
            DEFAULT_ENABLE_HORIZONTAL_ALPHA_EFFECT);
    this.enableClickToMaximize = attributes.getBoolean(R.styleable.draggable_view_enable_click_to_maximize_view,
            DEFAULT_ENABLE_CLICK_TO_MAXIMIZE);
    this.enableClickToMinimize = attributes.getBoolean(R.styleable.draggable_view_enable_click_to_minimize_view,
            DEFAULT_ENABLE_CLICK_TO_MINIMIZE);
    this.topViewResize = attributes.getBoolean(R.styleable.draggable_view_top_view_resize,
            DEFAULT_TOP_VIEW_RESIZE);
    this.topViewHeight = attributes.getDimensionPixelSize(R.styleable.draggable_view_top_view_height,
            DEFAULT_TOP_VIEW_HEIGHT);
    this.scaleFactorX = attributes.getFloat(R.styleable.draggable_view_top_view_x_scale_factor,
            DEFAULT_SCALE_FACTOR);
    this.scaleFactorY = attributes.getFloat(R.styleable.draggable_view_top_view_y_scale_factor,
            DEFAULT_SCALE_FACTOR);
    this.marginBottom = attributes.getDimensionPixelSize(R.styleable.draggable_view_top_view_margin_bottom,
            DEFAULT_TOP_VIEW_MARGIN);
    this.marginRight = attributes.getDimensionPixelSize(R.styleable.draggable_view_top_view_margin_right,
            DEFAULT_TOP_VIEW_MARGIN);
    this.dragViewId = attributes.getResourceId(R.styleable.draggable_view_top_view_id, R.id.drag_view);
    this.secondViewId = attributes.getResourceId(R.styleable.draggable_view_bottom_view_id, R.id.second_view);
    attributes.recycle();
}

From source file:com.skumar.flexibleciruclarseekbar.CircularSeekBar.java

private void init(Context context, AttributeSet attrs, int defStyle) {

    Log.d(TAG, "Initialising CircularSeekBar ...");
    float density = context.getResources().getDisplayMetrics().density;

    // Defaults, may need to link this into theme settings
    int arcColor = Color.GREEN;
    int progressColor = Color.BLUE;
    int needleColor = Color.BLACK;
    int thumbHalfHeight = 0;
    int thumbHalfWidth = 0;
    mThumb = ContextCompat.getDrawable(getContext(), R.drawable.circular_slider_drawable);
    // Convert progress width to pixels for current density
    mProgressWidth = (int) (mProgressWidth * density);

    if (attrs != null) {
        // Attribute initialization
        final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircularSeekBar, defStyle, 0);

        Drawable thumb = a.getDrawable(R.styleable.CircularSeekBar_thumb);
        if (thumb != null) {
            mThumb = thumb;/* ww  w  . jav a  2s.c om*/
        }

        thumbHalfHeight = mThumb.getIntrinsicHeight() / 2;
        thumbHalfWidth = mThumb.getIntrinsicWidth() / 2;
        mThumb.setBounds(-thumbHalfWidth, -thumbHalfHeight, thumbHalfWidth, thumbHalfHeight);

        mMax = a.getInteger(R.styleable.CircularSeekBar_max, mMax);
        mProgress = a.getFloat(R.styleable.CircularSeekBar_progress, mProgress);
        mProgressWidth = (int) a.getDimension(R.styleable.CircularSeekBar_progressWidth, mProgressWidth);
        mArcWidth = (int) a.getDimension(R.styleable.CircularSeekBar_arcWidth, mArcWidth);
        mStartAngle = a.getInt(R.styleable.CircularSeekBar_startAngle, mStartAngle);
        mSweepAngle = a.getInt(R.styleable.CircularSeekBar_sweepAngle, mSweepAngle);
        mRotation = a.getInt(R.styleable.CircularSeekBar_rotation, mRotation);
        mRoundedEdges = a.getBoolean(R.styleable.CircularSeekBar_roundEdges, mRoundedEdges);
        mTouchInside = a.getBoolean(R.styleable.CircularSeekBar_touchInside, mTouchInside);
        mClockwise = a.getBoolean(R.styleable.CircularSeekBar_clockwise, mClockwise);
        mEnabled = a.getBoolean(R.styleable.CircularSeekBar_enabled, mEnabled);

        arcColor = a.getColor(R.styleable.CircularSeekBar_arcColor, arcColor);
        progressColor = a.getColor(R.styleable.CircularSeekBar_progressColor, progressColor);

        a.recycle();
    }

    mProgress = (mProgress > mMax) ? mMax : mProgress;
    mProgress = (mProgress < 0) ? 0 : mProgress;

    mSweepAngle = (mSweepAngle > 360) ? 360 : mSweepAngle;
    mSweepAngle = (mSweepAngle < 0) ? 0 : mSweepAngle;

    mProgressSweep = mProgress / mMax * mSweepAngle;

    mStartAngle = (mStartAngle > 360) ? 0 : mStartAngle;
    mStartAngle = (mStartAngle < 0) ? 0 : mStartAngle;

    mArcPaint = new Paint();
    mArcPaint.setColor(arcColor);
    mArcPaint.setAntiAlias(true);
    mArcPaint.setStyle(Paint.Style.STROKE);
    mArcPaint.setStrokeWidth(mArcWidth);

    mProgressPaint = new Paint();
    mProgressPaint.setColor(progressColor);
    mProgressPaint.setAntiAlias(true);
    mProgressPaint.setStyle(Paint.Style.STROKE);
    mProgressPaint.setStrokeWidth(mProgressWidth);

    mNeedleScalePaint = new Paint();
    mNeedleScalePaint.setColor(needleColor);
    mNeedleScalePaint.setAntiAlias(true);
    mNeedleScalePaint.setStrokeWidth(mNeedleThickness);
    mNeedleDistance = 30;
    mNeedleDP = 10;
    mMinimumNeedleScale = 0;
    isIncreaseCenter = false;
    mIncreaseCenterNeedle = 0;
    hasDotMarkers = false;
    mDotSize = 2;
    mHeightForPopup = 0;
    mDrawNeedleScaleUp = false;

    mProgressIncrement = 1;
    hasGradientColor = true;
    mMin = 0;
    mFraction = 1;
    drawMarkings = false;
    hasPopup = false;
    hasPopupIn = false;
    mPopup = new PopupBox(context);

    if (mRoundedEdges) {
        mArcPaint.setStrokeCap(Paint.Cap.ROUND);
        mProgressPaint.setStrokeCap(Paint.Cap.ROUND);
    }
}

From source file:silent.kuasapmaterial.libs.ProgressWheel.java

/**
 * Parse the attributes passed to the view from the XML
 *
 * @param a the attributes to parse//  www.ja va2s. com
 */
private void parseAttributes(TypedArray a) {
    // We transform the default values from DIP to pixels
    DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
    barWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, barWidth, metrics);
    rimWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, rimWidth, metrics);
    circleRadius = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, circleRadius, metrics);

    circleRadius = (int) a.getDimension(R.styleable.ProgressWheel_matProg_circleRadius, circleRadius);

    fillRadius = a.getBoolean(R.styleable.ProgressWheel_matProg_fillRadius, false);

    barWidth = (int) a.getDimension(R.styleable.ProgressWheel_matProg_barWidth, barWidth);

    rimWidth = (int) a.getDimension(R.styleable.ProgressWheel_matProg_rimWidth, rimWidth);

    float baseSpinSpeed = a.getFloat(R.styleable.ProgressWheel_matProg_spinSpeed, spinSpeed / 360.0f);
    spinSpeed = baseSpinSpeed * 360;

    barSpinCycleTime = a.getInt(R.styleable.ProgressWheel_matProg_barSpinCycleTime, (int) barSpinCycleTime);

    barColor = a.getColor(R.styleable.ProgressWheel_matProg_barColor, barColor);

    rimColor = a.getColor(R.styleable.ProgressWheel_matProg_rimColor, rimColor);

    circleColor = a.getColor(R.styleable.ProgressWheel_matProg_circleBackgroundColor, circleColor);
    isCircleBackground = a.getBoolean(R.styleable.ProgressWheel_matProg_circleBackground, isCircleBackground);

    isMaterial = a.getBoolean(R.styleable.ProgressWheel_matProg_material, isMaterial);

    shadowColor = a.getColor(R.styleable.ProgressWheel_matProg_shadowColor, shadowColor);
    isShadow = a.getBoolean(R.styleable.ProgressWheel_matProg_shadow, isShadow);
    mShadowSize = a.getFloat(R.styleable.ProgressWheel_matProg_shadowSize, mShadowSize);

    linearProgress = a.getBoolean(R.styleable.ProgressWheel_matProg_linearProgress, false);

    if (a.getBoolean(R.styleable.ProgressWheel_matProg_progressIndeterminate, false)) {
        spin();
    }

    // Recycle
    a.recycle();
}

From source file:com.owen.view.views.PieChart.java

/**
 * Class constructor taking a context and an attribute set. This constructor
 * is used by the layout engine to construct a {@link com.owen.view.views.PieChart} from a set of
 * XML attributes./* w  ww .  j  ava  2 s .co m*/
 *
 * @param context
 * @param attrs   An attribute set which can contain attributes from
 *                {@link PieChart} as well as attributes inherited
 *                from {@link android.view.View}.
 */
public PieChart(Context context, AttributeSet attrs) {
    super(context, attrs);

    // attrs contains the raw values for the XML attributes
    // that were specified in the layout, which don't include
    // attributes set by styles or themes, and which may have
    // unresolved references. Call obtainStyledAttributes()
    // to get the final values for each attribute.
    //
    // This call uses R.styleable.PieChart, which is an array of
    // the custom attributes that were declared in attrs.xml.
    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.PieChart, 0, 0);

    try {
        // Retrieve the values from the TypedArray and store into
        // fields of this class.
        //
        // The R.styleable.PieChart_* constants represent the index for
        // each custom attribute in the R.styleable.PieChart array.
        mShowText = a.getBoolean(R.styleable.PieChart_pie_showText, false);
        mTextY = a.getDimension(R.styleable.PieChart_pie_labelY, 0.0f);
        mTextWidth = a.getDimension(R.styleable.PieChart_pie_labelWidth, 0.0f);
        mTextHeight = a.getDimension(R.styleable.PieChart_pie_labelHeight, 0.0f);
        mTextPos = a.getInteger(R.styleable.PieChart_pie_labelPosition, 0);
        mTextColor = a.getColor(R.styleable.PieChart_pie_labelColor, 0xff000000);
        mHighlightStrength = a.getFloat(R.styleable.PieChart_pie_highlightStrength, 1.0f);
        mPieRotation = a.getInt(R.styleable.PieChart_pie_pieRotation, 0);
        mPointerRadius = a.getDimension(R.styleable.PieChart_pie_pointerRadius, 2.0f);
        mAutoCenterInSlice = a.getBoolean(R.styleable.PieChart_pie_autoCenterPointerInSlice, false);
    } finally {
        // release the TypedArray so that it can be reused.
        a.recycle();
    }

    init();
}

From source file:com.steve.wanqureader.presentation.ui.CanRefreshLayout.java

public CanRefreshLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CanRefreshLayout, defStyleAttr, 0);

    try {/*from  w w w  .  j  a  va 2  s.  c  om*/
        final int N = a.getIndexCount();
        for (int i = 0; i < N; i++) {
            int attr = a.getIndex(i);
            if (attr == R.styleable.CanRefreshLayout_can_enabled_up) {
                setRefreshEnabled(a.getBoolean(attr, true));

            } else if (attr == R.styleable.CanRefreshLayout_can_enabled_down) {
                setLoadMoreEnabled(a.getBoolean(attr, true));

            } else if (attr == R.styleable.CanRefreshLayout_can_style_up) {
                mHeadStyle = a.getInt(attr, CLASSIC);

            } else if (attr == R.styleable.CanRefreshLayout_can_style_down) {
                mFootStyle = a.getInt(attr, CLASSIC);

            } else if (attr == R.styleable.CanRefreshLayout_can_friction) {
                setFriction(a.getFloat(attr, DEFAULT_FRICTION));

            } else if (attr == R.styleable.CanRefreshLayout_can_duration) {
                mDuration = a.getInt(attr, DEFAULT_DURATION);

            } else if (attr == R.styleable.CanRefreshLayout_can_smooth_duration) {
                mSmoothDuration = a.getInt(attr, DEFAULT_SMOOTH_DURATION);

            } else if (attr == R.styleable.CanRefreshLayout_can_smooth_length) {
                mSmoothLength = a.getInt(attr, DEFAULT_SMOOTH_LENGTH);
            }
        }
    } finally {
        a.recycle();
    }
}

From source file:im.ene.lab.design.widget.coverflow.FeatureCoverFlow.java

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

    if (cacheSize <= 0)
        cacheSize = DEFAULT_MAX_CACHE_SIZE;
    mCachedFrames = new LruCoverCache(cacheSize);

    setChildrenDrawingOrderEnabled(true);
    setChildrenDrawingCacheEnabled(true);
    setChildrenDrawnWithCacheEnabled(true);

    mReflectionMatrix.preScale(1.0f, -1.0f);

    //init params from xml
    if (attrs != null) {
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FeatureCoverFlow, defStyle, 0);

        mCoverWidth = a.getDimensionPixelSize(R.styleable.FeatureCoverFlow_coverWidth, mCoverWidth);
        if (mCoverWidth % 2 == 1)
            mCoverWidth--;/*from  w ww  . ja va  2s  . com*/
        mCoverHeight = a.getDimensionPixelSize(R.styleable.FeatureCoverFlow_coverHeight, mCoverHeight);
        mSpacing = a.getFloat(R.styleable.FeatureCoverFlow_spacing, mSpacing);
        mRotationThreshold = a.getFloat(R.styleable.FeatureCoverFlow_rotationThreshold, mRotationThreshold);
        mScalingThreshold = a.getFloat(R.styleable.FeatureCoverFlow_scalingThreshold, mScalingThreshold);
        mAdjustPositionThreshold = a.getFloat(R.styleable.FeatureCoverFlow_adjustPositionThreshold,
                mAdjustPositionThreshold);
        mAdjustPositionMultiplier = a.getFloat(R.styleable.FeatureCoverFlow_adjustPositionMultiplier,
                mAdjustPositionMultiplier);
        mMaxRotationAngle = a.getFloat(R.styleable.FeatureCoverFlow_maxRotationAngle, mMaxRotationAngle);
        mMaxScaleFactor = a.getFloat(R.styleable.FeatureCoverFlow_maxScaleFactor, mMaxScaleFactor);
        mRadius = a.getFloat(R.styleable.FeatureCoverFlow_circlePathRadius, mRadius);
        mRadiusInMatrixSpace = a.getFloat(R.styleable.FeatureCoverFlow_circlePathRadiusInMatrixSpace,
                mRadiusInMatrixSpace);
        mReflectionHeight = a.getFloat(R.styleable.FeatureCoverFlow_reflectionHeight, mReflectionHeight);
        mReflectionGap = a.getDimensionPixelSize(R.styleable.FeatureCoverFlow_reflectionGap, mReflectionGap);
        mReflectionOpacity = a.getInteger(R.styleable.FeatureCoverFlow_reflectionOpacity, mReflectionOpacity);
        mTuningWidgetSize = a.getDimensionPixelSize(R.styleable.FeatureCoverFlow_tunningWidgetSize,
                mTuningWidgetSize);
        mAlignTime = a.getInteger(R.styleable.FeatureCoverFlow_alignAnimationTime, mAlignTime);
        mPaddingTop = a.getDimensionPixelSize(R.styleable.FeatureCoverFlow_verticalPaddingTop, mPaddingTop);
        mPaddingBottom = a.getDimensionPixelSize(R.styleable.FeatureCoverFlow_verticalPaddingBottom,
                mPaddingBottom);
        mReflectionBackgroundColor = a.getColor(R.styleable.FeatureCoverFlow_reflectionBackroundColor,
                Color.TRANSPARENT);

        a.recycle();
    }
}

From source file:com.canyinghao.canrefresh.CanRefreshLayout.java

public CanRefreshLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CanRefreshLayout, defStyleAttr, 0);

    try {/*  w  ww. ja v  a  2  s.  c om*/
        final int N = a.getIndexCount();
        for (int i = 0; i < N; i++) {
            int attr = a.getIndex(i);
            if (attr == R.styleable.CanRefreshLayout_can_enabled_up) {
                setRefreshEnabled(a.getBoolean(attr, true));

            } else if (attr == R.styleable.CanRefreshLayout_can_enabled_down) {
                setLoadMoreEnabled(a.getBoolean(attr, true));

            } else if (attr == R.styleable.CanRefreshLayout_can_style_up) {
                mHeadStyle = a.getInt(attr, CLASSIC);

            } else if (attr == R.styleable.CanRefreshLayout_can_style_down) {
                mFootStyle = a.getInt(attr, CLASSIC);

            } else if (attr == R.styleable.CanRefreshLayout_can_friction) {

                setFriction(a.getFloat(attr, DEFAULT_FRICTION));

            } else if (attr == R.styleable.CanRefreshLayout_can_duration) {

                mDuration = a.getInt(attr, DEFAULT_DURATION);

            } else if (attr == R.styleable.CanRefreshLayout_can_smooth_duration) {

                mSmoothDuration = a.getInt(attr, DEFAULT_SMOOTH_DURATION);

            } else if (attr == R.styleable.CanRefreshLayout_can_smooth_length) {

                mSmoothLength = a.getInt(attr, DEFAULT_SMOOTH_LENGTH);

            }
        }

    } finally {
        a.recycle();
    }

}

From source file:info.awesomedevelopment.tvgrid.library.TVGridView.java

@SuppressWarnings("deprecation")
private void init(AttributeSet attrs) {
    ActivityManager am = (ActivityManager) getContext().getSystemService(Context.ACTIVITY_SERVICE);
    mCache = new LruCache<>(am.getMemoryClass() * 1024);

    mYSize = new ValueAnimator();
    mXSize = new ValueAnimator();
    mYLocation = new ValueAnimator();
    mXLocation = new ValueAnimator();

    mXSize.addUpdateListener(xSizeListener);
    mYSize.addUpdateListener(ySizeListener);
    mYLocation.addUpdateListener(yLocationListener);
    mXLocation.addUpdateListener(xLocationListener);

    mSelectorAnimationSet.playTogether(mXLocation, mYLocation, mXSize, mYSize);
    mSelectorAnimationSet.setInterpolator(new AccelerateDecelerateInterpolator());
    mSelectorAnimationSet.setDuration(ANIMATION_DURATION);

    TypedValue fillAlpha = new TypedValue();
    getResources().getValue(R.dimen.tvg_defFillAlpha, fillAlpha, true);

    TypedValue fillAlphaSelected = new TypedValue();
    getResources().getValue(R.dimen.tvg_defFillAlphaSelected, fillAlphaSelected, true);

    if (attrs != null) {
        TypedArray a = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.TVGridView, 0, 0);

        try {/*from   w  w w  . j  a v a2 s .  c  o  m*/
            //noinspection ResourceType
            mStrokePosition = a.getInteger(R.styleable.TVGridView_tvg_strokePosition, OUTSIDE);
            //noinspection ResourceType
            mSelectorPosition = a.getInteger(R.styleable.TVGridView_tvg_selectorPosition, OVER);
            //noinspection ResourceType
            mSelectorShape = a.getInteger(R.styleable.TVGridView_tvg_selectorShape, RECTANGLE);

            mAnimateSelectorChanges = a.getBoolean(R.styleable.TVGridView_tvg_animateSelectorChanges,
                    getResources().getInteger(R.integer.tvg_defAnimateSelectorChanges) == 1);
            mIsFilled = a.getBoolean(R.styleable.TVGridView_tvg_filled,
                    getResources().getInteger(R.integer.tvg_defIsFilled) == 1);
            mFillAlpha = a.getFloat(R.styleable.TVGridView_tvg_fillAlpha, fillAlpha.getFloat());
            mFillAlphaSelected = a.getFloat(R.styleable.TVGridView_tvg_fillAlphaSelected,
                    fillAlphaSelected.getFloat());
            mFillColor = a.getColor(R.styleable.TVGridView_tvg_fillColor,
                    getResources().getColor(R.color.tvg_defFillColor));
            mFillColorSelected = a.getColor(R.styleable.TVGridView_tvg_fillColorSelected,
                    getResources().getColor(R.color.tvg_defFillColorSelected));
            mCornerRadiusX = a.getDimension(R.styleable.TVGridView_tvg_cornerRadius,
                    getResources().getDimension(R.dimen.tvg_defCornerRadius));
            mCornerRadiusY = a.getDimension(R.styleable.TVGridView_tvg_cornerRadius,
                    getResources().getDimension(R.dimen.tvg_defCornerRadius));
            mStrokeWidth = a.getDimension(R.styleable.TVGridView_tvg_strokeWidth,
                    getResources().getDimension(R.dimen.tvg_defStrokeWidth));
            mStrokeColor = a.getColor(R.styleable.TVGridView_tvg_strokeColor,
                    getResources().getColor(R.color.tvg_defStrokeColor));
            mStrokeColorSelected = a.getColor(R.styleable.TVGridView_tvg_strokeColorSelected,
                    getResources().getColor(R.color.tvg_defStrokeColorSelected));
            mStrokeMarginLeft = a.getDimension(R.styleable.TVGridView_tvg_marginLeft,
                    getResources().getDimension(R.dimen.tvg_defStrokeMarginLeft));
            mStrokeMarginTop = a.getDimension(R.styleable.TVGridView_tvg_marginTop,
                    getResources().getDimension(R.dimen.tvg_defStrokeMarginTop));
            mStrokeMarginRight = a.getDimension(R.styleable.TVGridView_tvg_marginRight,
                    getResources().getDimension(R.dimen.tvg_defStrokeMarginRight));
            mStrokeMarginBottom = a.getDimension(R.styleable.TVGridView_tvg_marginBottom,
                    getResources().getDimension(R.dimen.tvg_defStrokeMarginBottom));
            mStrokeSpacingLeft = a.getDimension(R.styleable.TVGridView_tvg_spacingLeft,
                    getResources().getDimension(R.dimen.tvg_defStrokeSpacingLeft));
            mStrokeSpacingTop = a.getDimension(R.styleable.TVGridView_tvg_spacingTop,
                    getResources().getDimension(R.dimen.tvg_defStrokeSpacingTop));
            mStrokeSpacingRight = a.getDimension(R.styleable.TVGridView_tvg_spacingRight,
                    getResources().getDimension(R.dimen.tvg_defStrokeSpacingRight));
            mStrokeSpacingBottom = a.getDimension(R.styleable.TVGridView_tvg_spacingBottom,
                    getResources().getDimension(R.dimen.tvg_defStrokeSpacingBottom));
        } finally {
            a.recycle();
        }
    } else {
        mStrokePosition = OUTSIDE;
        mSelectorPosition = OVER;
        mSelectorShape = RECTANGLE;

        mAnimateSelectorChanges = getResources().getInteger(R.integer.tvg_defAnimateSelectorChanges) == 1;
        mIsFilled = getResources().getInteger(R.integer.tvg_defIsFilled) == 1;
        mFillAlpha = fillAlpha.getFloat();
        mFillAlphaSelected = fillAlphaSelected.getFloat();
        mFillColor = getResources().getColor(R.color.tvg_defFillColor);
        mFillColorSelected = getResources().getColor(R.color.tvg_defFillColorSelected);
        mCornerRadiusX = getResources().getDimension(R.dimen.tvg_defCornerRadius);
        mCornerRadiusY = getResources().getDimension(R.dimen.tvg_defCornerRadius);
        mStrokeWidth = getResources().getDimension(R.dimen.tvg_defStrokeWidth);
        mStrokeColor = getResources().getColor(R.color.tvg_defStrokeColor);
        mStrokeColorSelected = getResources().getColor(R.color.tvg_defStrokeColorSelected);
        mStrokeMarginLeft = getResources().getDimension(R.dimen.tvg_defStrokeMarginLeft);
        mStrokeMarginTop = getResources().getDimension(R.dimen.tvg_defStrokeMarginTop);
        mStrokeMarginRight = getResources().getDimension(R.dimen.tvg_defStrokeMarginRight);
        mStrokeMarginBottom = getResources().getDimension(R.dimen.tvg_defStrokeMarginBottom);
        mStrokeSpacingLeft = getResources().getDimension(R.dimen.tvg_defStrokeSpacingLeft);
        mStrokeSpacingTop = getResources().getDimension(R.dimen.tvg_defStrokeSpacingTop);
        mStrokeSpacingRight = getResources().getDimension(R.dimen.tvg_defStrokeSpacingRight);
        mStrokeSpacingBottom = getResources().getDimension(R.dimen.tvg_defStrokeSpacingBottom);
    }

    addOnScrollListener(new OnScrollListener() {
        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
            if (newState == SCROLL_STATE_IDLE) {
                mEdgeChange = false;
                mHardScrollChange = false;
            }
        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            mScrollY = mScrollY + dy;

            if (mStrokeCellCurrentBounds == null || mStrokeCell == null)
                return;

            if (useAnimations()) {
                mSelectorAnimationSet.cancel();

                mStrokeCellCurrentBounds.offsetTo(mStrokeCellCurrentBounds.left - dx,
                        mStrokeCellCurrentBounds.top - dy);

                performSelectorAnimation();
            } else if (mHardScrollChange || mEdgeChange) {
                mStrokeCellCurrentBounds.offsetTo(mStrokeCellCurrentBounds.left - dx,
                        mStrokeCellCurrentBounds.top - dy);
                setPrevBounds();

                mStrokeCell.setBounds(mStrokeCellPrevBounds);
                invalidate();
            }
        }
    });

    setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            clearHighlightedView();
            return false;
        }
    });
}

From source file:android.widget.Gallery.java

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

    mGestureDetector = new GestureDetector(context, this);
    mGestureDetector.setIsLongpressEnabled(true);

    TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.Gallery, defStyle, 0);

    int index = a.getInt(com.android.internal.R.styleable.Gallery_gravity, -1);
    if (index >= 0) {
        setGravity(index);/*from ww  w.j a v  a2s  . com*/
    }

    int animationDuration = a.getInt(com.android.internal.R.styleable.Gallery_animationDuration, -1);
    if (animationDuration > 0) {
        setAnimationDuration(animationDuration);
    }

    int spacing = a.getDimensionPixelOffset(com.android.internal.R.styleable.Gallery_spacing, 0);
    setSpacing(spacing);

    float unselectedAlpha = a.getFloat(com.android.internal.R.styleable.Gallery_unselectedAlpha, 0.5f);
    setUnselectedAlpha(unselectedAlpha);

    a.recycle();

    // We draw the selected item last (because otherwise the item to the
    // right overlaps it)
    mGroupFlags |= FLAG_USE_CHILD_DRAWING_ORDER;

    mGroupFlags |= FLAG_SUPPORT_STATIC_TRANSFORMATIONS;
}