Search in sources :

Example 11 with OvalShape

use of android.graphics.drawable.shapes.OvalShape in project PhotoNoter by yydcdut.

the class CircleProgressBar method onLayout.

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    super.onLayout(changed, left, top, right, bottom);
    final float density = getContext().getResources().getDisplayMetrics().density;
    mDiameter = Math.min(getMeasuredWidth(), getMeasuredHeight());
    if (mDiameter <= 0) {
        mDiameter = (int) density * DEFAULT_CIRCLE_DIAMETER;
    }
    if (getBackground() == null && mCircleBackgroundEnabled) {
        final int shadowYOffset = (int) (density * Y_OFFSET);
        final int shadowXOffset = (int) (density * X_OFFSET);
        mShadowRadius = (int) (density * SHADOW_RADIUS);
        if (elevationSupported()) {
            mBgCircle = new ShapeDrawable(new OvalShape());
            ViewCompat.setElevation(this, SHADOW_ELEVATION * density);
        } else {
            OvalShape oval = new OvalShadow(mShadowRadius, mDiameter - mShadowRadius * 2);
            mBgCircle = new ShapeDrawable(oval);
            ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, mBgCircle.getPaint());
            mBgCircle.getPaint().setShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset, KEY_SHADOW_COLOR);
            final int padding = (int) mShadowRadius;
            // set padding so the inner image sits correctly within the shadow.
            setPadding(padding, padding, padding, padding);
        }
        mBgCircle.getPaint().setColor(mBackGroundColor);
        setBackgroundDrawable(mBgCircle);
    }
    mProgressDrawable.setBackgroundColor(mBackGroundColor);
    mProgressDrawable.setColorSchemeColors(mColors);
    mProgressDrawable.setSizeParameters(mDiameter, mDiameter, mInnerRadius <= 0 ? (mDiameter - mProgressStokeWidth * 2) / 4 : mInnerRadius, mProgressStokeWidth, mArrowWidth < 0 ? mProgressStokeWidth * 4 : mArrowWidth, mArrowHeight < 0 ? mProgressStokeWidth * 2 : mArrowHeight);
    if (isShowArrow()) {
        mProgressDrawable.showArrowOnFirstStart(true);
        mProgressDrawable.setArrowScale(1f);
        mProgressDrawable.showArrow(true);
    }
    super.setImageDrawable(null);
    super.setImageDrawable(mProgressDrawable);
    mProgressDrawable.setAlpha(255);
    if (getVisibility() == VISIBLE) {
        mProgressDrawable.start();
    }
}
Also used : ShapeDrawable(android.graphics.drawable.ShapeDrawable) OvalShape(android.graphics.drawable.shapes.OvalShape) Paint(android.graphics.Paint)

Example 12 with OvalShape

use of android.graphics.drawable.shapes.OvalShape in project PhotoNoter by yydcdut.

the class TextDrawable method drawBorder.

/**
     * 画边界
     *
     * @param canvas
     */
private void drawBorder(Canvas canvas) {
    RectF rect = new RectF(getBounds());
    //上下左右都加个borderThickness / 2长度
    rect.inset(borderThickness / 2, borderThickness / 2);
    if (shape instanceof OvalShape) {
        //椭圆
        canvas.drawOval(rect, borderPaint);
    } else if (shape instanceof RoundRectShape) {
        //圆角Rect
        canvas.drawRoundRect(rect, radius, radius, borderPaint);
    } else {
        //Rect
        canvas.drawRect(rect, borderPaint);
    }
}
Also used : RectF(android.graphics.RectF) RoundRectShape(android.graphics.drawable.shapes.RoundRectShape) OvalShape(android.graphics.drawable.shapes.OvalShape)

Example 13 with OvalShape

use of android.graphics.drawable.shapes.OvalShape in project PhotoNoter by yydcdut.

the class FloatingActionButton method createOuterStrokeDrawable.

/**
     * 绘制外层的drawable
     * 就是画边框
     *
     * @param strokeWidth
     * @return
     */
private Drawable createOuterStrokeDrawable(float strokeWidth) {
    //圆
    ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape());
    //笔
    final Paint paint = shapeDrawable.getPaint();
    //锯齿
    paint.setAntiAlias(true);
    //描边宽度
    paint.setStrokeWidth(strokeWidth);
    //描边style,就是中空
    paint.setStyle(Style.STROKE);
    //颜色黑色,用来画边框
    paint.setColor(Color.BLACK);
    //透明度
    paint.setAlpha(opacityToAlpha(0.02f));
    return shapeDrawable;
}
Also used : ShapeDrawable(android.graphics.drawable.ShapeDrawable) Paint(android.graphics.Paint) OvalShape(android.graphics.drawable.shapes.OvalShape)

Example 14 with OvalShape

use of android.graphics.drawable.shapes.OvalShape in project PhotoNoter by yydcdut.

the class FloatingActionButton method createInnerStrokesDrawable.

/**
     * 创建内层drawable
     *
     * @param color
     * @param strokeWidth
     * @return
     */
private Drawable createInnerStrokesDrawable(final int color, float strokeWidth) {
    //不描边的话直接返回一个颜色为透明的drawable
    if (!mStrokeVisible) {
        return new ColorDrawable(Color.TRANSPARENT);
    }
    //圆 drawable
    ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape());
    //这个暗颜色
    final int bottomStrokeColor = darkenColor(color);
    //比bottomStrokeColor透明一半
    final int bottomStrokeColorHalfTransparent = halfTransparent(bottomStrokeColor);
    //这个亮颜色
    final int topStrokeColor = lightenColor(color);
    //比topStrokeColor透明一半
    final int topStrokeColorHalfTransparent = halfTransparent(topStrokeColor);
    final Paint paint = shapeDrawable.getPaint();
    //锯齿
    paint.setAntiAlias(true);
    //描边宽度
    paint.setStrokeWidth(strokeWidth);
    //描边
    paint.setStyle(Style.STROKE);
    //draws a linear gradient
    shapeDrawable.setShaderFactory(new ShaderFactory() {

        @Override
        public Shader resize(int width, int height) {
            return new LinearGradient(width / 2, 0, width / 2, height, new int[] { topStrokeColor, topStrokeColorHalfTransparent, color, bottomStrokeColorHalfTransparent, bottomStrokeColor }, new float[] { 0f, 0.2f, 0.5f, 0.8f, 1f }, TileMode.CLAMP);
        }
    });
    return shapeDrawable;
}
Also used : LinearGradient(android.graphics.LinearGradient) ShaderFactory(android.graphics.drawable.ShapeDrawable.ShaderFactory) ColorDrawable(android.graphics.drawable.ColorDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) Paint(android.graphics.Paint) OvalShape(android.graphics.drawable.shapes.OvalShape) Shader(android.graphics.Shader) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint)

Example 15 with OvalShape

use of android.graphics.drawable.shapes.OvalShape in project weex-example by KalicyZhou.

the class CircleProgressBar method onLayout.

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    super.onLayout(changed, left, top, right, bottom);
    final float density = getContext().getResources().getDisplayMetrics().density;
    mDiameter = Math.min(getMeasuredWidth(), getMeasuredHeight());
    if (mDiameter <= 0) {
        mDiameter = (int) density * DEFAULT_CIRCLE_DIAMETER;
    }
    if (getBackground() == null && mCircleBackgroundEnabled) {
        final int shadowYOffset = (int) (density * Y_OFFSET);
        final int shadowXOffset = (int) (density * X_OFFSET);
        mShadowRadius = (int) (density * SHADOW_RADIUS);
        if (elevationSupported()) {
            mBgCircle = new ShapeDrawable(new OvalShape());
            ViewCompat.setElevation(this, SHADOW_ELEVATION * density);
        } else {
            OvalShape oval = new OvalShadow(mShadowRadius, mDiameter - mShadowRadius * 2);
            mBgCircle = new ShapeDrawable(oval);
            ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, mBgCircle.getPaint());
            mBgCircle.getPaint().setShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset, KEY_SHADOW_COLOR);
            final int padding = (int) mShadowRadius;
            // set padding so the inner image sits correctly within the shadow.
            setPadding(padding, padding, padding, padding);
        }
        mBgCircle.getPaint().setColor(mBackGroundColor);
        setBackgroundDrawable(mBgCircle);
    }
    mProgressDrawable.setBackgroundColor(mBackGroundColor);
    mProgressDrawable.setColorSchemeColors(mColors);
    if (isShowArrow()) {
        mProgressDrawable.setArrowScale(1f);
        mProgressDrawable.showArrow(true);
    }
    super.setImageDrawable(null);
    super.setImageDrawable(mProgressDrawable);
    mProgressDrawable.setAlpha(255);
    if (getVisibility() == VISIBLE) {
        mProgressDrawable.setStartEndTrim(0, (float) 0.8);
    }
}
Also used : ShapeDrawable(android.graphics.drawable.ShapeDrawable) OvalShape(android.graphics.drawable.shapes.OvalShape) Paint(android.graphics.Paint)

Aggregations

OvalShape (android.graphics.drawable.shapes.OvalShape)44 ShapeDrawable (android.graphics.drawable.ShapeDrawable)40 Paint (android.graphics.Paint)17 SuppressLint (android.annotation.SuppressLint)10 StateListDrawable (android.graphics.drawable.StateListDrawable)8 ColorDrawable (android.graphics.drawable.ColorDrawable)7 LayerDrawable (android.graphics.drawable.LayerDrawable)7 Drawable (android.graphics.drawable.Drawable)5 ImageView (android.widget.ImageView)5 LinearGradient (android.graphics.LinearGradient)3 Shader (android.graphics.Shader)3 ShaderFactory (android.graphics.drawable.ShapeDrawable.ShaderFactory)3 View (android.view.View)3 Bitmap (android.graphics.Bitmap)2 Rect (android.graphics.Rect)2 RectF (android.graphics.RectF)2 RoundRectShape (android.graphics.drawable.shapes.RoundRectShape)2 FloatingActionButton (android.support.design.widget.FloatingActionButton)2 LinearInterpolator (android.view.animation.LinearInterpolator)2 RelativeLayout (android.widget.RelativeLayout)2