Example usage for android.content.res TypedArray getDimension

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

Introduction

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

Prototype

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

Source Link

Document

Retrieve a dimensional unit attribute at index.

Usage

From source file:com.wunderlist.slidinglayer.SlidingLayer.java

/**
 * Constructor for the sliding layer.<br>
 * By default this panel will//from ww  w  .ja v  a 2  s . c  o  m
 * <ol>
 * <li>{@link #setStickTo(int)} with param {@link #STICK_TO_RIGHT}</li>
 * <li>Use no shadow drawable. (i.e. with size of 0)</li>
 * <li>Close when the panel is tapped</li>
 * <li>Open when the offset is tapped, but will have an offset of 0</li>
 * </ol>
 *
 * @param context  a reference to an existing context
 * @param attrs    attribute set constructed from attributes set in android .xml file
 * @param defStyle style res id
 */
public SlidingLayer(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // Style
    final TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SlidingLayer);

    // Set the side of the screen
    setStickTo(ta.getInt(R.styleable.SlidingLayer_stickTo, STICK_TO_RIGHT));

    // Sets the shadow drawable
    int shadowRes = ta.getResourceId(R.styleable.SlidingLayer_shadowDrawable, INVALID_VALUE);
    if (shadowRes != INVALID_VALUE) {
        setShadowDrawable(shadowRes);
    }

    // Sets the shadow size
    mShadowSize = (int) ta.getDimension(R.styleable.SlidingLayer_shadowSize, 0);

    // Sets the ability to open or close the layer by tapping in any empty space
    changeStateOnTap = ta.getBoolean(R.styleable.SlidingLayer_changeStateOnTap, true);

    // How much of the view sticks out when closed
    mOffsetDistance = ta.getDimensionPixelOffset(R.styleable.SlidingLayer_offsetDistance, 0);

    // Sets the size of the preview summary, if any
    mPreviewOffsetDistance = ta.getDimensionPixelOffset(R.styleable.SlidingLayer_previewOffsetDistance,
            INVALID_VALUE);

    // If showing offset is greater than preview mode offset dimension, exception is thrown
    checkPreviewModeConsistency();

    ta.recycle();

    init();
}

From source file:com.example.androidannotationtesttwo.widget.swiptlistview.SwipeListView.java

/**
 * Init ListView//from w ww.  j  av  a2s  .c  o m
 * 
 * @param attrs AttributeSet
 */
private void init(AttributeSet attrs) {

    int swipeMode = SWIPE_MODE_BOTH;
    boolean swipeOpenOnLongPress = true;
    boolean swipeCloseAllItemsWhenMoveList = true;
    long swipeAnimationTime = 0;
    float swipeOffsetLeft = 0;
    float swipeOffsetRight = 0;
    int swipeDrawableChecked = 0;
    int swipeDrawableUnchecked = 0;

    int swipeActionLeft = SWIPE_ACTION_REVEAL;
    int swipeActionRight = SWIPE_ACTION_REVEAL;

    if (attrs != null) {
        TypedArray styled = getContext().obtainStyledAttributes(attrs, R.styleable.SwipeListView);
        swipeMode = styled.getInt(R.styleable.SwipeListView_swipeMode, SWIPE_MODE_BOTH);
        swipeActionLeft = styled.getInt(R.styleable.SwipeListView_swipeActionLeft, SWIPE_ACTION_REVEAL);
        swipeActionRight = styled.getInt(R.styleable.SwipeListView_swipeActionRight, SWIPE_ACTION_REVEAL);
        swipeOffsetLeft = styled.getDimension(R.styleable.SwipeListView_swipeOffsetLeft, 0);
        swipeOffsetRight = styled.getDimension(R.styleable.SwipeListView_swipeOffsetRight, 0);
        swipeOpenOnLongPress = styled.getBoolean(R.styleable.SwipeListView_swipeOpenOnLongPress, true);
        swipeAnimationTime = styled.getInteger(R.styleable.SwipeListView_swipeAnimationTime, 0);
        swipeCloseAllItemsWhenMoveList = styled
                .getBoolean(R.styleable.SwipeListView_swipeCloseAllItemsWhenMoveList, true);
        swipeDrawableChecked = styled.getResourceId(R.styleable.SwipeListView_swipeDrawableChecked, 0);
        swipeDrawableUnchecked = styled.getResourceId(R.styleable.SwipeListView_swipeDrawableUnchecked, 0);
        swipeFrontView = styled.getResourceId(R.styleable.SwipeListView_swipeFrontView, 0);
        swipeBackView = styled.getResourceId(R.styleable.SwipeListView_swipeBackView, 0);

        isDropDownStyle = styled.getBoolean(R.styleable.SwipeListView_swipeIsDropDownStyle, false);
        isOnBottomStyle = styled.getBoolean(R.styleable.SwipeListView_swipeIsOnBottomStyle, false);
        isAutoLoadOnBottom = styled.getBoolean(R.styleable.SwipeListView_swipeIsAutoLoadOnBottom, false);

    }

    initOnBottomStyle();

    // should set, to run onScroll method and so on
    super.setOnScrollListener(this);

    if (swipeFrontView == 0 || swipeBackView == 0) {
        swipeFrontView = getContext().getResources().getIdentifier(SWIPE_DEFAULT_FRONT_VIEW, "id",
                getContext().getPackageName());
        swipeBackView = getContext().getResources().getIdentifier(SWIPE_DEFAULT_BACK_VIEW, "id",
                getContext().getPackageName());

        if (swipeFrontView == 0 || swipeBackView == 0) {
            throw new RuntimeException(String.format(
                    "You forgot the attributes swipeFrontView or swipeBackView. You can add this attributes or use '%s' and '%s' identifiers",
                    SWIPE_DEFAULT_FRONT_VIEW, SWIPE_DEFAULT_BACK_VIEW));
        }
    }

    final ViewConfiguration configuration = ViewConfiguration.get(getContext());
    touchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
    touchListener = new SwipeListViewTouchListener(this, swipeFrontView, swipeBackView);
    if (swipeAnimationTime > 0) {
        touchListener.setAnimationTime(swipeAnimationTime);
    }
    touchListener.setRightOffset(swipeOffsetRight);
    touchListener.setLeftOffset(swipeOffsetLeft);
    touchListener.setSwipeActionLeft(swipeActionLeft);
    touchListener.setSwipeActionRight(swipeActionRight);
    touchListener.setSwipeMode(swipeMode);
    touchListener.setSwipeClosesAllItemsWhenListMoves(swipeCloseAllItemsWhenMoveList);
    touchListener.setSwipeOpenOnLongPress(swipeOpenOnLongPress);
    touchListener.setSwipeDrawableChecked(swipeDrawableChecked);
    touchListener.setSwipeDrawableUnchecked(swipeDrawableUnchecked);
    setOnTouchListener(touchListener);
    setOnScrollListener(touchListener.makeScrollListener());
}

From source file:com.hua.news.widget.swipelistview.CopyOfSwipeListView.java

/**
 * Init ListView//from  w w  w.j a v  a2  s  . com
 * 
 * @param attrs AttributeSet
 */
private void init(AttributeSet attrs) {

    int swipeMode = SWIPE_MODE_BOTH;
    boolean swipeOpenOnLongPress = true;
    boolean swipeCloseAllItemsWhenMoveList = true;
    long swipeAnimationTime = 0;
    float swipeOffsetLeft = 0;
    float swipeOffsetRight = 0;
    int swipeDrawableChecked = 0;
    int swipeDrawableUnchecked = 0;

    int swipeActionLeft = SWIPE_ACTION_REVEAL;
    int swipeActionRight = SWIPE_ACTION_REVEAL;

    if (attrs != null) {
        TypedArray styled = getContext().obtainStyledAttributes(attrs, R.styleable.SwipeListView);
        swipeMode = styled.getInt(R.styleable.SwipeListView_swipeMode, SWIPE_MODE_BOTH);
        swipeActionLeft = styled.getInt(R.styleable.SwipeListView_swipeActionLeft, SWIPE_ACTION_REVEAL);
        swipeActionRight = styled.getInt(R.styleable.SwipeListView_swipeActionRight, SWIPE_ACTION_REVEAL);
        swipeOffsetLeft = styled.getDimension(R.styleable.SwipeListView_swipeOffsetLeft, 0);
        swipeOffsetRight = styled.getDimension(R.styleable.SwipeListView_swipeOffsetRight, 0);
        swipeOpenOnLongPress = styled.getBoolean(R.styleable.SwipeListView_swipeOpenOnLongPress, true);
        swipeAnimationTime = styled.getInteger(R.styleable.SwipeListView_swipeAnimationTime, 0);
        swipeCloseAllItemsWhenMoveList = styled
                .getBoolean(R.styleable.SwipeListView_swipeCloseAllItemsWhenMoveList, true);
        swipeDrawableChecked = styled.getResourceId(R.styleable.SwipeListView_swipeDrawableChecked, 0);
        swipeDrawableUnchecked = styled.getResourceId(R.styleable.SwipeListView_swipeDrawableUnchecked, 0);
        swipeFrontView = styled.getResourceId(R.styleable.SwipeListView_swipeFrontView, 0);
        swipeBackView = styled.getResourceId(R.styleable.SwipeListView_swipeBackView, 0);

        isDropDownStyle = styled.getBoolean(R.styleable.SwipeListView_swipeIsDropDownStyle, false);
        isOnBottomStyle = styled.getBoolean(R.styleable.SwipeListView_swipeIsOnBottomStyle, false);
        isAutoLoadOnBottom = styled.getBoolean(R.styleable.SwipeListView_swipeIsAutoLoadOnBottom, false);

    }

    initOnBottomStyle();

    // should set, to run onScroll method and so on
    super.setOnScrollListener(this);

    if (swipeFrontView == 0 || swipeBackView == 0) {
        swipeFrontView = getContext().getResources().getIdentifier(SWIPE_DEFAULT_FRONT_VIEW, "id",
                getContext().getPackageName());
        swipeBackView = getContext().getResources().getIdentifier(SWIPE_DEFAULT_BACK_VIEW, "id",
                getContext().getPackageName());

        if (swipeFrontView == 0 || swipeBackView == 0) {
            throw new RuntimeException(String.format(
                    "You forgot the attributes swipeFrontView or swipeBackView. You can add this attributes or use '%s' and '%s' identifiers",
                    SWIPE_DEFAULT_FRONT_VIEW, SWIPE_DEFAULT_BACK_VIEW));
        }
    }

    final ViewConfiguration configuration = ViewConfiguration.get(getContext());
    touchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
    touchListener = null;//new SwipeListViewTouchListener(this, swipeFrontView, swipeBackView);
    if (swipeAnimationTime > 0) {
        touchListener.setAnimationTime(swipeAnimationTime);
    }
    touchListener.setRightOffset(swipeOffsetRight);
    touchListener.setLeftOffset(swipeOffsetLeft);
    touchListener.setSwipeActionLeft(swipeActionLeft);
    touchListener.setSwipeActionRight(swipeActionRight);
    touchListener.setSwipeMode(swipeMode);
    touchListener.setSwipeClosesAllItemsWhenListMoves(swipeCloseAllItemsWhenMoveList);
    touchListener.setSwipeOpenOnLongPress(swipeOpenOnLongPress);
    touchListener.setSwipeDrawableChecked(swipeDrawableChecked);
    touchListener.setSwipeDrawableUnchecked(swipeDrawableUnchecked);
    setOnTouchListener(touchListener);
    setOnScrollListener(touchListener.makeScrollListener());
}

From source file:com.dirkgassen.wator.ui.view.RollingGraphView.java

/**
 * Read out the attributes from the given attribute set and initialize whatever they represent.
 *
 * @param attributeArray typed array containing the attribute values from the XML file
 *//*from  ww w  .  j  a va2  s .c  om*/
private void setupAttributes(TypedArray attributeArray) {
    String series1Name = attributeArray.getString(R.styleable.RollingGraphView_series1name);
    if (series1Name == null) {
        seriesNames = null;
    } else {
        String series2Name = attributeArray.getString(R.styleable.RollingGraphView_series2name);
        if (series2Name == null) {
            seriesNames = new String[] { series1Name };
        } else {
            String series3Name = attributeArray.getString(R.styleable.RollingGraphView_series3name);
            if (series3Name == null) {
                seriesNames = new String[] { series1Name, series2Name };
            } else {
                String series4Name = attributeArray.getString(R.styleable.RollingGraphView_series4name);
                if (series4Name == null) {
                    seriesNames = new String[] { series1Name, series2Name, series3Name };
                } else {
                    seriesNames = new String[] { series1Name, series2Name, series3Name, series4Name };
                }
            }
        }

        maxValues = attributeArray.getInt(R.styleable.RollingGraphView_maxValues, -1);
        seriesPaints = new Paint[seriesNames.length];

        seriesPaints[0] = new Paint(Paint.ANTI_ALIAS_FLAG);
        seriesPaints[0]
                .setColor(attributeArray.getColor(R.styleable.RollingGraphView_series1color, 0xFFFF0000));
        seriesPaints[0].setStrokeWidth(attributeArray
                .getDimension(R.styleable.RollingGraphView_series1thickness, 1 /* dp */ * displayDensity));
        seriesPaints[0].setTextSize(
                attributeArray.getDimension(R.styleable.RollingGraphView_label1textSize, 14 * displayDensity));
        if (seriesPaints.length > 1) {
            seriesPaints[1] = new Paint(Paint.ANTI_ALIAS_FLAG);
            seriesPaints[1]
                    .setColor(attributeArray.getColor(R.styleable.RollingGraphView_series2color, 0xFFFF0000));
            seriesPaints[1].setStrokeWidth(attributeArray
                    .getDimension(R.styleable.RollingGraphView_series2thickness, 1 /* dp */ * displayDensity));
            seriesPaints[1].setTextSize(attributeArray.getDimension(R.styleable.RollingGraphView_label2textSize,
                    14 * displayDensity));
            if (seriesPaints.length > 2) {
                seriesPaints[2] = new Paint(Paint.ANTI_ALIAS_FLAG);
                seriesPaints[2].setColor(
                        attributeArray.getColor(R.styleable.RollingGraphView_series3color, 0xFFFF0000));
                seriesPaints[2].setStrokeWidth(attributeArray.getDimension(
                        R.styleable.RollingGraphView_series3thickness, 1 /* dp */ * displayDensity));
                seriesPaints[2].setTextSize(attributeArray
                        .getDimension(R.styleable.RollingGraphView_label3textSize, 14 * displayDensity));
                if (seriesPaints.length > 3) {
                    seriesPaints[3] = new Paint(Paint.ANTI_ALIAS_FLAG);
                    seriesPaints[3].setColor(
                            attributeArray.getColor(R.styleable.RollingGraphView_series4color, 0xFFFF0000));
                    seriesPaints[3].setStrokeWidth(attributeArray.getDimension(
                            R.styleable.RollingGraphView_series4thickness, 1 /* dp */ * displayDensity));
                    seriesPaints[3].setTextSize(attributeArray
                            .getDimension(R.styleable.RollingGraphView_label4textSize, 14 * displayDensity));
                }
            }
        }
        background = getBackground();
        if (background == null) {
            background = new ColorDrawable(ContextCompat.getColor(getContext(), android.R.color.white));
        }
    }

    horizontal = attributeArray.getInt(R.styleable.RollingGraphView_android_orientation, 0) == 0;
}

From source file:devlight.io.library.ArcProgressStackView.java

public ArcProgressStackView(final Context context, final AttributeSet attrs, final int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    // Init CPSV/*from   www. jav a2s  . c  om*/

    // Always draw
    setWillNotDraw(false);
    setLayerType(LAYER_TYPE_SOFTWARE, null);
    ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, null);

    // Detect if features available
    mIsFeaturesAvailable = Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB;

    // Retrieve attributes from xml
    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ArcProgressStackView);
    try {
        setIsAnimated(typedArray.getBoolean(R.styleable.ArcProgressStackView_apsv_animated, true));
        setIsShadowed(typedArray.getBoolean(R.styleable.ArcProgressStackView_apsv_shadowed, true));
        setIsRounded(typedArray.getBoolean(R.styleable.ArcProgressStackView_apsv_rounded, false));
        setIsDragged(typedArray.getBoolean(R.styleable.ArcProgressStackView_apsv_dragged, false));
        setIsLeveled(typedArray.getBoolean(R.styleable.ArcProgressStackView_apsv_leveled, false));
        setTypeface(typedArray.getString(R.styleable.ArcProgressStackView_apsv_typeface));
        setTextColor(typedArray.getColor(R.styleable.ArcProgressStackView_apsv_text_color, Color.WHITE));
        setShadowRadius(typedArray.getDimension(R.styleable.ArcProgressStackView_apsv_shadow_radius,
                DEFAULT_SHADOW_RADIUS));
        setShadowDistance(typedArray.getDimension(R.styleable.ArcProgressStackView_apsv_shadow_distance,
                DEFAULT_SHADOW_DISTANCE));
        setShadowAngle(typedArray.getInteger(R.styleable.ArcProgressStackView_apsv_shadow_angle,
                (int) DEFAULT_SHADOW_ANGLE));
        setShadowColor(
                typedArray.getColor(R.styleable.ArcProgressStackView_apsv_shadow_color, DEFAULT_SHADOW_COLOR));
        setAnimationDuration(typedArray.getInteger(R.styleable.ArcProgressStackView_apsv_animation_duration,
                DEFAULT_ANIMATION_DURATION));
        setStartAngle(typedArray.getInteger(R.styleable.ArcProgressStackView_apsv_start_angle,
                (int) DEFAULT_START_ANGLE));
        setSweepAngle(typedArray.getInteger(R.styleable.ArcProgressStackView_apsv_sweep_angle,
                (int) DEFAULT_SWEEP_ANGLE));
        setProgressModelOffset(typedArray.getDimension(R.styleable.ArcProgressStackView_apsv_model_offset,
                DEFAULT_MODEL_OFFSET));
        setModelBgEnabled(typedArray.getBoolean(R.styleable.ArcProgressStackView_apsv_model_bg_enabled, false));

        // Set orientation
        final int orientationOrdinal = typedArray
                .getInt(R.styleable.ArcProgressStackView_apsv_indicator_orientation, 0);
        setIndicatorOrientation(
                orientationOrdinal == 0 ? IndicatorOrientation.VERTICAL : IndicatorOrientation.HORIZONTAL);

        // Retrieve interpolator
        Interpolator interpolator = null;
        try {
            final int interpolatorId = typedArray
                    .getResourceId(R.styleable.ArcProgressStackView_apsv_interpolator, 0);
            interpolator = interpolatorId == 0 ? null
                    : AnimationUtils.loadInterpolator(context, interpolatorId);
        } catch (Resources.NotFoundException exception) {
            interpolator = null;
            exception.printStackTrace();
        } finally {
            setInterpolator(interpolator);
        }

        // Set animation info if is available
        if (mIsFeaturesAvailable) {
            mProgressAnimator.setFloatValues(MIN_FRACTION, MAX_FRACTION);
            mProgressAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(final ValueAnimator animation) {
                    mAnimatedFraction = (float) animation.getAnimatedValue();
                    if (mAnimatorUpdateListener != null)
                        mAnimatorUpdateListener.onAnimationUpdate(animation);

                    postInvalidate();
                }
            });
        }

        // Check whether draw width dimension or fraction
        if (typedArray.hasValue(R.styleable.ArcProgressStackView_apsv_draw_width)) {
            final TypedValue drawWidth = new TypedValue();
            typedArray.getValue(R.styleable.ArcProgressStackView_apsv_draw_width, drawWidth);
            if (drawWidth.type == TypedValue.TYPE_DIMENSION)
                setDrawWidthDimension(drawWidth.getDimension(context.getResources().getDisplayMetrics()));
            else
                setDrawWidthFraction(drawWidth.getFraction(MAX_FRACTION, MAX_FRACTION));
        } else
            setDrawWidthFraction(DEFAULT_DRAW_WIDTH_FRACTION);

        // Set preview models
        if (isInEditMode()) {
            String[] preview = null;
            try {
                final int previewId = typedArray
                        .getResourceId(R.styleable.ArcProgressStackView_apsv_preview_colors, 0);
                preview = previewId == 0 ? null : typedArray.getResources().getStringArray(previewId);
            } catch (Exception exception) {
                preview = null;
                exception.printStackTrace();
            } finally {
                if (preview == null)
                    preview = typedArray.getResources().getStringArray(R.array.default_preview);

                final Random random = new Random();
                for (String previewColor : preview)
                    mModels.add(
                            new Model("", random.nextInt((int) MAX_PROGRESS), Color.parseColor(previewColor)));
                measure(mSize, mSize);
            }

            // Set preview model bg color
            mPreviewModelBgColor = typedArray.getColor(R.styleable.ArcProgressStackView_apsv_preview_bg,
                    Color.LTGRAY);
        }
    } finally {
        typedArray.recycle();
    }
}

From source file:com.gm.common.ui.widget.pageindicator.PageIndicatorView.java

private void initSizeAttribute(@NonNull TypedArray typedArray) {
    int orientationIndex = typedArray.getInt(R.styleable.PageIndicatorView_piv_orientation,
            Orientation.HORIZONTAL.ordinal());
    if (orientationIndex == 0) {
        orientation = Orientation.HORIZONTAL;
    } else {//from  w  ww.  ja v  a  2 s  . c om
        orientation = Orientation.VERTICAL;
    }

    radiusPx = (int) typedArray.getDimension(R.styleable.PageIndicatorView_piv_radius,
            DensityUtils.dpToPx(DEFAULT_RADIUS_DP));
    paddingPx = (int) typedArray.getDimension(R.styleable.PageIndicatorView_piv_padding,
            DensityUtils.dpToPx(DEFAULT_PADDING_DP));

    scaleFactor = typedArray.getFloat(R.styleable.PageIndicatorView_piv_scaleFactor,
            ScaleAnimation.DEFAULT_SCALE_FACTOR);
    if (scaleFactor < ScaleAnimation.MIN_SCALE_FACTOR) {
        scaleFactor = ScaleAnimation.MIN_SCALE_FACTOR;

    } else if (scaleFactor > ScaleAnimation.MAX_SCALE_FACTOR) {
        scaleFactor = ScaleAnimation.MAX_SCALE_FACTOR;
    }

    strokePx = (int) typedArray.getDimension(R.styleable.PageIndicatorView_piv_strokeWidth,
            DensityUtils.dpToPx(FillAnimation.DEFAULT_STROKE_DP));
    if (strokePx > radiusPx) {
        strokePx = radiusPx;
    }

    if (animationType != AnimationType.FILL) {
        strokePx = 0;
    }
}

From source file:com.xcy.xsdk.ui.listview.SwipeListView.java

/**
 * Init ListView/* w  ww  . java  2 s.co  m*/
 * 
 * @param attrs AttributeSet
 */
private void init(AttributeSet attrs) {

    int swipeMode = SWIPE_MODE_BOTH;
    boolean swipeOpenOnLongPress = true;
    boolean swipeCloseAllItemsWhenMoveList = true;
    long swipeAnimationTime = 0;
    float swipeOffsetLeft = 0;
    float swipeOffsetRight = 0;
    int swipeDrawableChecked = 0;
    int swipeDrawableUnchecked = 0;

    int swipeActionLeft = SWIPE_ACTION_REVEAL;
    int swipeActionRight = SWIPE_ACTION_REVEAL;

    if (attrs != null) {
        TypedArray styled = getContext().obtainStyledAttributes(attrs, R.styleable.SwipeListView);
        swipeMode = styled.getInt(R.styleable.SwipeListView_swipeMode, SWIPE_MODE_BOTH);
        swipeActionLeft = styled.getInt(R.styleable.SwipeListView_swipeActionLeft, SWIPE_ACTION_REVEAL);
        swipeActionRight = styled.getInt(R.styleable.SwipeListView_swipeActionRight, SWIPE_ACTION_REVEAL);
        swipeOffsetLeft = styled.getDimension(R.styleable.SwipeListView_swipeOffsetLeft, 0);
        swipeOffsetRight = styled.getDimension(R.styleable.SwipeListView_swipeOffsetRight, 0);
        swipeOpenOnLongPress = styled.getBoolean(R.styleable.SwipeListView_swipeOpenOnLongPress, true);
        swipeAnimationTime = styled.getInteger(R.styleable.SwipeListView_swipeAnimationTime, 0);
        swipeCloseAllItemsWhenMoveList = styled
                .getBoolean(R.styleable.SwipeListView_swipeCloseAllItemsWhenMoveList, true);
        swipeDrawableChecked = styled.getResourceId(R.styleable.SwipeListView_swipeDrawableChecked, 0);
        swipeDrawableUnchecked = styled.getResourceId(R.styleable.SwipeListView_swipeDrawableUnchecked, 0);
        swipeFrontView = styled.getResourceId(R.styleable.SwipeListView_swipeFrontView, 0);
        swipeBackView = styled.getResourceId(R.styleable.SwipeListView_swipeBackView, 0);

        isDropDownStyle = styled.getBoolean(R.styleable.SwipeListView_swipeIsDropDownStyle, false);
        isOnBottomStyle = styled.getBoolean(R.styleable.SwipeListView_swipeIsOnBottomStyle, false);
        isAutoLoadOnBottom = styled.getBoolean(R.styleable.SwipeListView_swipeIsAutoLoadOnBottom, false);

    }

    initOnBottomStyle();
    initOnHeaderStyle();

    // should set, to run onScroll method and so on
    super.setOnScrollListener(this);

    if (swipeFrontView == 0 || swipeBackView == 0) {
        swipeFrontView = getContext().getResources().getIdentifier(SWIPE_DEFAULT_FRONT_VIEW, "id",
                getContext().getPackageName());
        swipeBackView = getContext().getResources().getIdentifier(SWIPE_DEFAULT_BACK_VIEW, "id",
                getContext().getPackageName());

        if (swipeFrontView == 0 || swipeBackView == 0) {
            throw new RuntimeException(String.format(
                    "You forgot the attributes swipeFrontView or swipeBackView. You can add this attributes or use '%s' and '%s' identifiers",
                    SWIPE_DEFAULT_FRONT_VIEW, SWIPE_DEFAULT_BACK_VIEW));
        }
    }

    final ViewConfiguration configuration = ViewConfiguration.get(getContext());
    touchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
    touchListener = new SwipeListViewTouchListener(this, swipeFrontView, swipeBackView);
    if (swipeAnimationTime > 0) {
        touchListener.setAnimationTime(swipeAnimationTime);
    }
    touchListener.setRightOffset(swipeOffsetRight);
    touchListener.setLeftOffset(swipeOffsetLeft);
    touchListener.setSwipeActionLeft(swipeActionLeft);
    touchListener.setSwipeActionRight(swipeActionRight);
    touchListener.setSwipeMode(swipeMode);
    touchListener.setSwipeClosesAllItemsWhenListMoves(swipeCloseAllItemsWhenMoveList);
    touchListener.setSwipeOpenOnLongPress(swipeOpenOnLongPress);
    touchListener.setSwipeDrawableChecked(swipeDrawableChecked);
    touchListener.setSwipeDrawableUnchecked(swipeDrawableUnchecked);
    setOnTouchListener(touchListener);
    setOnScrollListener(touchListener.makeScrollListener());
}

From source file:com.nihaskalam.progressbuttonlibrary.CircularProgressButton.java

private void initAttributes(Context context, AttributeSet attributeSet) {
    String xmlProvidedSize = attributeSet.getAttributeValue("http://schemas.android.com/apk/res/android",
            "textSize");
    String[] parts = xmlProvidedSize.split("\\.");
    String part1 = parts[0];// ww  w. j  av  a2s .  c om
    textSize = new Integer(part1);
    if (textSize < 0) {
        float sourceTextSize = getTextSize();
        textSize = (int) (sourceTextSize / getContext().getResources().getDisplayMetrics().density);
    }
    TypedArray attr = getTypedArray(context, attributeSet, R.styleable.CircularProgressButton);
    if (attr == null) {
        return;
    }
    try {

        mIdleText = attr.getString(R.styleable.CircularProgressButton_pb_textIdle);
        mCompleteText = attr.getString(R.styleable.CircularProgressButton_pb_textComplete);
        mCancelText = attr.getString(R.styleable.CircularProgressButton_pb_textCancel);
        mErrorText = attr.getString(R.styleable.CircularProgressButton_pb_textError);
        mProgressText = attr.getString(R.styleable.CircularProgressButton_pb_textProgress);

        mIconComplete = attr.getResourceId(R.styleable.CircularProgressButton_pb_iconComplete, 0);
        mIconCancel = attr.getResourceId(R.styleable.CircularProgressButton_pb_iconCancel, 0);
        mIconError = attr.getResourceId(R.styleable.CircularProgressButton_pb_iconError, 0);
        mCornerRadius = attr.getDimension(R.styleable.CircularProgressButton_pb_cornerRadius, 0);
        mPaddingProgress = attr.getDimensionPixelSize(R.styleable.CircularProgressButton_pb_paddingProgress, 0);
        mIndeterminateProgressMode = attr.getBoolean(R.styleable.CircularProgressButton_pb_isIndeterminate,
                false);

        int blue = getColor(R.color.pb_blue);
        int white = getColor(R.color.pb_white);
        int grey = getColor(R.color.pb_grey);

        int idleStateSelector = attr.getResourceId(R.styleable.CircularProgressButton_pb_selectorIdle,
                R.color.pb_idle_state_selector);
        mIdleColorState = ContextCompat.getColorStateList(context, idleStateSelector);

        int completeStateSelector = attr.getResourceId(R.styleable.CircularProgressButton_pb_selectorComplete,
                R.color.pb_complete_state_selector);
        mCompleteColorState = ContextCompat.getColorStateList(context, completeStateSelector);
        int cancelStateSelector = attr.getResourceId(R.styleable.CircularProgressButton_pb_selectorCancel,
                R.color.pb_cancel_state_selector);
        mCancelColorState = ContextCompat.getColorStateList(context, cancelStateSelector);
        int errorStateSelector = attr.getResourceId(R.styleable.CircularProgressButton_pb_selectorError,
                R.color.pb_error_state_selector);
        mErrorColorState = ContextCompat.getColorStateList(context, errorStateSelector);

        mColorProgress = attr.getColor(R.styleable.CircularProgressButton_pb_colorProgress, white);
        mColorIndicator = attr.getColor(R.styleable.CircularProgressButton_pb_colorIndicator, blue);
        mColorProgressCancelIcon = attr.getColor(R.styleable.CircularProgressButton_pb_colorProgressCancelIcon,
                mColorIndicator);
        mColorIndicatorBackground = attr
                .getColor(R.styleable.CircularProgressButton_pb_colorIndicatorBackground, grey);
        mIdleStateTextColorAfterClick = attr.getColor(R.styleable.CircularProgressButton_pb_textColorAfterClick,
                getNormalColor(mIdleColorState));
        if (idleStateStrokeColor != -1) {
            mIdleStateBackgroundColorAfterClick = attr.getColor(
                    R.styleable.CircularProgressButton_pb_backgroundColorAfterClick,
                    getColor(idleStateStrokeColor));
        } else {
            mIdleStateBackgroundColorAfterClick = attr.getColor(
                    R.styleable.CircularProgressButton_pb_backgroundColorAfterClick,
                    getPressedColor(mIdleColorState));
        }
        mColorCancelText = attr.getColor(R.styleable.CircularProgressButton_pb_colorCancelText,
                getNormalColor(this.getTextColors()));
        mColorCompleteText = attr.getColor(R.styleable.CircularProgressButton_pb_colorCompleteText,
                getNormalColor(this.getTextColors()));
        mColorErrorText = attr.getColor(R.styleable.CircularProgressButton_pb_colorErrorText,
                getNormalColor(this.getTextColors()));
        mColorIdleText = getNormalColor(this.getTextColors());
    } finally {
        attr.recycle();
    }
}

From source file:org.akop.crosswords.view.CrosswordView.java

public CrosswordView(Context context, AttributeSet attrs) {
    super(context, attrs);

    if (!isInEditMode()) {
        setLayerType(View.LAYER_TYPE_HARDWARE, null);
    }//from  w  ww . j  av  a 2s.c o m

    // Set drawing defaults
    Resources r = context.getResources();
    DisplayMetrics dm = r.getDisplayMetrics();

    int cellFillColor = NORMAL_CELL_FILL_COLOR;
    int cheatedCellFillColor = CHEATED_CELL_FILL_COLOR;
    int mistakeCellFillColor = MISTAKE_CELL_FILL_COLOR;
    int selectedWordFillColor = SELECTED_WORD_FILL_COLOR;
    int selectedCellFillColor = SELECTED_CELL_FILL_COLOR;
    int textColor = TEXT_COLOR;
    int cellStrokeColor = CELL_STROKE_COLOR;
    int circleStrokeColor = CIRCLE_STROKE_COLOR;

    float numberTextSize = NUMBER_TEXT_SIZE * dm.scaledDensity;
    float answerTextSize = ANSWER_TEXT_SIZE * dm.scaledDensity;

    mCellSize = CELL_SIZE * dm.density;
    mNumberTextPadding = NUMBER_TEXT_PADDING * dm.density;
    mAnswerTextPadding = ANSWER_TEXT_PADDING * dm.density;

    // Read supplied attributes
    if (attrs != null) {
        Resources.Theme theme = context.getTheme();
        TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.Crossword, 0, 0);
        mCellSize = a.getDimension(R.styleable.Crossword_cellSize, mCellSize);
        mNumberTextPadding = a.getDimension(R.styleable.Crossword_numberTextPadding, mNumberTextPadding);
        numberTextSize = a.getDimension(R.styleable.Crossword_numberTextSize, numberTextSize);
        mAnswerTextPadding = a.getDimension(R.styleable.Crossword_answerTextPadding, mAnswerTextPadding);
        answerTextSize = a.getDimension(R.styleable.Crossword_answerTextSize, answerTextSize);
        cellFillColor = a.getColor(R.styleable.Crossword_defaultCellFillColor, cellFillColor);
        cheatedCellFillColor = a.getColor(R.styleable.Crossword_cheatedCellFillColor, cheatedCellFillColor);
        mistakeCellFillColor = a.getColor(R.styleable.Crossword_mistakeCellFillColor, mistakeCellFillColor);
        selectedWordFillColor = a.getColor(R.styleable.Crossword_selectedWordFillColor, selectedWordFillColor);
        selectedCellFillColor = a.getColor(R.styleable.Crossword_selectedCellFillColor, selectedCellFillColor);
        cellStrokeColor = a.getColor(R.styleable.Crossword_cellStrokeColor, cellStrokeColor);
        circleStrokeColor = a.getColor(R.styleable.Crossword_circleStrokeColor, circleStrokeColor);
        textColor = a.getColor(R.styleable.Crossword_textColor, textColor);
        a.recycle();
    }

    mMarkerSideLength = mCellSize * MARKER_TRIANGLE_LENGTH_FRACTION;

    // Init paints
    mCellFillPaint = new Paint();
    mCellFillPaint.setColor(cellFillColor);
    mCellFillPaint.setStyle(Paint.Style.FILL);

    mCheatedCellFillPaint = new Paint();
    mCheatedCellFillPaint.setColor(cheatedCellFillColor);
    mCheatedCellFillPaint.setStyle(Paint.Style.FILL);

    mMistakeCellFillPaint = new Paint();
    mMistakeCellFillPaint.setColor(mistakeCellFillColor);
    mMistakeCellFillPaint.setStyle(Paint.Style.FILL);

    mSelectedWordFillPaint = new Paint();
    mSelectedWordFillPaint.setColor(selectedWordFillColor);
    mSelectedWordFillPaint.setStyle(Paint.Style.FILL);

    mSelectedCellFillPaint = new Paint();
    mSelectedCellFillPaint.setColor(selectedCellFillColor);
    mSelectedCellFillPaint.setStyle(Paint.Style.FILL);

    mCellStrokePaint = new Paint();
    mCellStrokePaint.setColor(cellStrokeColor);
    mCellStrokePaint.setStyle(Paint.Style.STROKE);
    //      mCellStrokePaint.setStrokeWidth(1);

    mCircleStrokePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mCircleStrokePaint.setColor(circleStrokeColor);
    mCircleStrokePaint.setStyle(Paint.Style.STROKE);
    mCircleStrokePaint.setStrokeWidth(1);

    mNumberTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mNumberTextPaint.setColor(textColor);
    mNumberTextPaint.setTextAlign(Paint.Align.CENTER);
    mNumberTextPaint.setTextSize(numberTextSize);

    mNumberStrokePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mNumberStrokePaint.setColor(cellFillColor);
    mNumberStrokePaint.setTextAlign(Paint.Align.CENTER);
    mNumberStrokePaint.setTextSize(numberTextSize);
    mNumberStrokePaint.setStyle(Paint.Style.STROKE);
    mNumberStrokePaint.setStrokeWidth(NUMBER_TEXT_STROKE_WIDTH * dm.scaledDensity);

    mAnswerTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mAnswerTextPaint.setColor(textColor);
    mAnswerTextPaint.setTextSize(answerTextSize);
    mAnswerTextPaint.setTextAlign(Paint.Align.CENTER);

    // http://www.google.com/fonts/specimen/Kalam
    Typeface typeface = Typeface.createFromAsset(context.getAssets(), "kalam-regular.ttf");
    mAnswerTextPaint.setTypeface(typeface);

    // Init rest of the values
    mCircleRadius = (mCellSize / 2) - mCircleStrokePaint.getStrokeWidth();
    mPuzzleCells = EMPTY_CELLS;
    mPuzzleWidth = 0;
    mPuzzleHeight = 0;
    mAllowedChars = EMPTY_CHARS;

    mRenderScale = 0;
    mBitmapOffset = new PointF();
    mCenteredOffset = new PointF();
    mTranslationBounds = new RectF();

    mScaleDetector = new ScaleGestureDetector(context, new ScaleListener());
    mGestureDetector = new GestureDetector(context, new GestureListener());

    mContentRect = new RectF();
    mPuzzleRect = new RectF();

    mBitmapPaint = new Paint(Paint.FILTER_BITMAP_FLAG);

    mScroller = new Scroller(context, null, true);
    mZoomer = new Zoomer(context);

    setFocusableInTouchMode(true);
    setOnKeyListener(this);
}

From source file:com.trafi.anchorbottomsheetbehavior.AnchorBottomSheetBehavior.java

/**
 * Default constructor for inflating AnchorBottomSheetBehaviors from layout.
 *
 * @param context The {@link Context}.//  w  w w .j av  a  2s . co m
 * @param attrs   The {@link AttributeSet}.
 */
public AnchorBottomSheetBehavior(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray a = context.obtainStyledAttributes(attrs,
            android.support.design.R.styleable.BottomSheetBehavior_Layout);
    TypedValue value = a
            .peekValue(android.support.design.R.styleable.BottomSheetBehavior_Layout_behavior_peekHeight);
    if (value != null && value.data == PEEK_HEIGHT_AUTO) {
        setPeekHeight(value.data);
    } else {
        setPeekHeight(a.getDimensionPixelSize(
                android.support.design.R.styleable.BottomSheetBehavior_Layout_behavior_peekHeight,
                PEEK_HEIGHT_AUTO));
    }
    setHideable(a.getBoolean(android.support.design.R.styleable.BottomSheetBehavior_Layout_behavior_hideable,
            false));
    setSkipCollapsed(a.getBoolean(
            android.support.design.R.styleable.BottomSheetBehavior_Layout_behavior_skipCollapsed, false));
    a.recycle();

    a = context.obtainStyledAttributes(attrs, R.styleable.AnchorBottomSheetBehavior_Layout);
    mAnchorOffset = (int) a.getDimension(R.styleable.AnchorBottomSheetBehavior_Layout_behavior_anchorOffset, 0);
    //noinspection WrongConstant
    mState = a.getInt(R.styleable.AnchorBottomSheetBehavior_Layout_behavior_defaultState, mState);

    mShouldAnchoredBeforeExpand = a.getBoolean(
            R.styleable.AnchorBottomSheetBehavior_Layout_behavior_shouldAnchoredBeforeExpand, false);
    mShouldAnchoredBeforeCollapse = a.getBoolean(
            R.styleable.AnchorBottomSheetBehavior_Layout_behavior_shouldAnchoredBeforeCollapse, false);
    mExpandable = a.getBoolean(R.styleable.AnchorBottomSheetBehavior_Layout_behavior_expandable, true);
    a.recycle();

    ViewConfiguration configuration = ViewConfiguration.get(context);
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
    mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
}