Search in sources :

Example 81 with ShapeDrawable

use of android.graphics.drawable.ShapeDrawable in project PhotoNoter by yydcdut.

the class FloatingActionButton method createCircleDrawable.

/**
     * 绘制一个drawable出来
     *
     * @param color
     * @param strokeWidth
     * @return
     */
private Drawable createCircleDrawable(int color, float strokeWidth) {
    //拿到alpha
    int alpha = Color.alpha(color);
    //拿到rgb
    int opaqueColor = opaque(color);
    //圆
    ShapeDrawable fillDrawable = new ShapeDrawable(new OvalShape());
    //笔
    final Paint paint = fillDrawable.getPaint();
    paint.setAntiAlias(true);
    paint.setColor(opaqueColor);
    Drawable[] layers = { fillDrawable, createInnerStrokesDrawable(opaqueColor, strokeWidth) };
    //将Drawable[] layers 合成 LayerDrawable drawable
    LayerDrawable drawable = (alpha == 255 || !mStrokeVisible) ? new LayerDrawable(layers) : new TranslucentLayerDrawable(alpha, layers);
    //一半的描边宽度
    int halfStrokeWidth = (int) (strokeWidth / 2f);
    //描边的drawable
    drawable.setLayerInset(1, halfStrokeWidth, halfStrokeWidth, halfStrokeWidth, halfStrokeWidth);
    //返回这个drawable
    return drawable;
}
Also used : LayerDrawable(android.graphics.drawable.LayerDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) StateListDrawable(android.graphics.drawable.StateListDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) Paint(android.graphics.Paint) OvalShape(android.graphics.drawable.shapes.OvalShape) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint)

Example 82 with ShapeDrawable

use of android.graphics.drawable.ShapeDrawable in project UltimateAndroid by cymcsg.

the class FloatingActionButton method createDrawable.

private Drawable createDrawable(int color) {
    OvalShape ovalShape = new OvalShape();
    ShapeDrawable shapeDrawable = new ShapeDrawable(ovalShape);
    shapeDrawable.getPaint().setColor(color);
    if (mShadow) {
        LayerDrawable layerDrawable = new LayerDrawable(new Drawable[] { getResources().getDrawable(R.drawable.floating_acition_button_shadow), shapeDrawable });
        int shadowSize = getDimension(mType == TYPE_NORMAL ? R.dimen.fab_shadow_size : R.dimen.fab_mini_shadow_size);
        layerDrawable.setLayerInset(1, shadowSize, shadowSize, shadowSize, shadowSize);
        return layerDrawable;
    } else {
        return shapeDrawable;
    }
}
Also used : LayerDrawable(android.graphics.drawable.LayerDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) OvalShape(android.graphics.drawable.shapes.OvalShape) SuppressLint(android.annotation.SuppressLint)

Example 83 with ShapeDrawable

use of android.graphics.drawable.ShapeDrawable in project UltimateAndroid by cymcsg.

the class ProgressbarWheelActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.progress_wheel_activity);
    pw_two = (ProgressWheel) findViewById(R.id.progressBarTwo);
    pw_three = (ProgressWheel) findViewById(R.id.progressBarThree);
    pw_four = (ProgressWheel) findViewById(R.id.progressBarFour);
    //pw_five = (ProgressWheel) findViewById(R.id.progressBarFive);
    ShapeDrawable bg = new ShapeDrawable(new RectShape());
    int[] pixels = new int[] { 0xFF2E9121, 0xFF2E9121, 0xFF2E9121, 0xFF2E9121, 0xFF2E9121, 0xFF2E9121, 0xFFFFFFFF, 0xFFFFFFFF };
    Bitmap bm = Bitmap.createBitmap(pixels, 8, 1, Bitmap.Config.ARGB_8888);
    Shader shader = new BitmapShader(bm, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
    pw_three.setRimShader(shader);
    pw_three.spin();
    pw_four.spin();
    final Runnable r = new Runnable() {

        public void run() {
            running = true;
            while (progress < 361) {
                pw_two.incrementProgress();
                progress++;
                try {
                    Thread.sleep(15);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            running = false;
        }
    };
    Button spin = (Button) findViewById(R.id.btn_spin);
    spin.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            if (!running) {
                if (pw_two.isSpinning) {
                    pw_two.stopSpinning();
                }
                pw_two.resetCount();
                pw_two.setText("Loading...");
                pw_two.spin();
            }
        }
    });
    Button increment = (Button) findViewById(R.id.btn_increment);
    increment.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            if (!running) {
                progress = 0;
                pw_two.resetCount();
                Thread s = new Thread(r);
                s.start();
            }
        }
    });
}
Also used : RectShape(android.graphics.drawable.shapes.RectShape) Bitmap(android.graphics.Bitmap) Button(android.widget.Button) ShapeDrawable(android.graphics.drawable.ShapeDrawable) OnClickListener(android.view.View.OnClickListener) BitmapShader(android.graphics.BitmapShader) Shader(android.graphics.Shader) BitmapShader(android.graphics.BitmapShader) View(android.view.View)

Example 84 with ShapeDrawable

use of android.graphics.drawable.ShapeDrawable in project UltimateAndroid by cymcsg.

the class DefaultSectionAdapter method getItemView.

@Override
@SuppressWarnings(value = { "deprecation" })
public View getItemView(int section, int position, View convertView, ViewGroup parent) {
    TextView tv = null;
    if (convertView != null) {
        tv = (TextView) convertView;
    } else {
        tv = new TextView(context);
        RectShape rs = new RectShape();
        ShapeDrawable sd = new BottomBorderBackground(rs, Color.WHITE, Color.GRAY);
        tv.setBackgroundDrawable(sd);
        tv.setPadding(20, 0, 0, 0);
        tv.setGravity(Gravity.CENTER_VERTICAL);
    }
    tv.setLayoutParams(new LayoutParams(300, itemHeight));
    tv.setText("s" + section + " p" + position);
    return tv;
}
Also used : RectShape(android.graphics.drawable.shapes.RectShape) LayoutParams(android.view.ViewGroup.LayoutParams) ShapeDrawable(android.graphics.drawable.ShapeDrawable) TextView(android.widget.TextView)

Example 85 with ShapeDrawable

use of android.graphics.drawable.ShapeDrawable in project SwipeToLoadLayout by Aspsine.

the class GoogleCircleProgressView 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);
    mProgressDrawable.setStartEndTrim(0f, 0.75f);
}
Also used : ShapeDrawable(android.graphics.drawable.ShapeDrawable) OvalShape(android.graphics.drawable.shapes.OvalShape) Paint(android.graphics.Paint)

Aggregations

ShapeDrawable (android.graphics.drawable.ShapeDrawable)96 OvalShape (android.graphics.drawable.shapes.OvalShape)44 Paint (android.graphics.Paint)32 Drawable (android.graphics.drawable.Drawable)24 LayerDrawable (android.graphics.drawable.LayerDrawable)24 StateListDrawable (android.graphics.drawable.StateListDrawable)17 SuppressLint (android.annotation.SuppressLint)16 ClipDrawable (android.graphics.drawable.ClipDrawable)16 Bitmap (android.graphics.Bitmap)15 BitmapDrawable (android.graphics.drawable.BitmapDrawable)15 BitmapShader (android.graphics.BitmapShader)14 RoundRectShape (android.graphics.drawable.shapes.RoundRectShape)14 AnimationDrawable (android.graphics.drawable.AnimationDrawable)13 ColorDrawable (android.graphics.drawable.ColorDrawable)9 RectShape (android.graphics.drawable.shapes.RectShape)8 Shape (android.graphics.drawable.shapes.Shape)7 Canvas (android.graphics.Canvas)6 Resources (android.content.res.Resources)5 Shader (android.graphics.Shader)5 TypedArray (android.content.res.TypedArray)4