Android ShapeDrawable - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android ShapeDrawable class.

This code example shows how to use the following methods:getPaint, setIntrinsicHeight, setIntrinsicWidth
 
        this.userHandle = userHandle;
    } 
 
    private static ShapeDrawable createRectShape(int width, int height, int color) {
        ShapeDrawable shape = new ShapeDrawable(new RectShape());
        shape.setIntrinsicHeight(height);
        shape.setIntrinsicWidth(width);
        shape.getPaint().setColor(color);
        return shape;
    } 
} 
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getPaint
        } 
 
        private ShapeHolder addBall(float x, float y) {
            OvalShape circle = new OvalShape();
            circle.resize(50f * mDensity, 50f * mDensity);
            ShapeDrawable drawable = new ShapeDrawable(circle);
            ShapeHolder shapeHolder = new ShapeHolder(drawable);
            shapeHolder.setX(x - 25f);
            shapeHolder.setY(y - 25f);
            int red = (int)(100 + Math.random() * 155);
            int green = (int)(100 + Math.random() * 155);
            int blue = (int)(100 + Math.random() * 155);
            int color = 0xff000000 | red << 16 | green << 8 | blue;
            Paint paint = drawable.getPaint(); //new Paint(Paint.ANTI_ALIAS_FLAG);
            int darkColor = 0xff000000 | red/4 << 16 | green/4 << 8 | blue/4;
            RadialGradient gradient = new RadialGradient(37.5f, 12.5f,
                    50f, color, darkColor, Shader.TileMode.CLAMP);
            paint.setShader(gradient);
            shapeHolder.setPaint(paint);
            balls.add(shapeHolder);
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getPaint
 
@RunWith(TestRunners.WithDefaults.class) 
public class ShapeDrawableTest { 
    @Test 
    public void getPaint_ShouldReturnTheSamePaint() throws Exception { 
        ShapeDrawable shapeDrawable = new ShapeDrawable();
        Paint paint = shapeDrawable.getPaint();
        assertNotNull(paint);
        assertThat(shapeDrawable.getPaint()).isSameAs(paint);
    } 
} 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setIntrinsicHeight, setIntrinsicWidth
This code example shows how to use the following methods:setShape, resize
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getPaint
		 
		int r = dipToPixels(DEFAULT_CORNER_RADIUS_DIP);
		float[] outerR = new float[] {r, r, r, r, r, r, r, r};
         
		RoundRectShape rr = new RoundRectShape(outerR, null, null);
		ShapeDrawable drawable = new ShapeDrawable(rr);
		drawable.getPaint().setColor(badgeColor);
		 
		return drawable;
		 
	} 
	 
	private void applyLayoutParams() { 
		 
		FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		 
		switch (badgePosition) {
		case POSITION_TOP_LEFT:
			lp.gravity = Gravity.LEFT | Gravity.TOP;
			lp.setMargins(badgeMarginH, badgeMarginV, 0, 0);
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getPaint
        } 
 
        private ShapeHolder addBall(float x, float y) {
            OvalShape circle = new OvalShape();
            circle.resize(50f * mDensity, 50f * mDensity);
            ShapeDrawable drawable = new ShapeDrawable(circle);
            ShapeHolder shapeHolder = new ShapeHolder(drawable);
            shapeHolder.setX(x - 25f);
            shapeHolder.setY(y - 25f);
            int red = (int)(100 + Math.random() * 155);
            int green = (int)(100 + Math.random() * 155);
            int blue = (int)(100 + Math.random() * 155);
            int color = 0xff000000 | red << 16 | green << 8 | blue;
            Paint paint = drawable.getPaint(); //new Paint(Paint.ANTI_ALIAS_FLAG);
            int darkColor = 0xff000000 | red/4 << 16 | green/4 << 8 | blue/4;
            RadialGradient gradient = new RadialGradient(37.5f, 12.5f,
                    50f, color, darkColor, Shader.TileMode.CLAMP);
            paint.setShader(gradient);
            shapeHolder.setPaint(paint);
            balls.add(shapeHolder);
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:ofInt, setBounds, getPaint
    	/* Setup shape */ 
        shape = new OvalShape();
        shape.resize(50, 50);
 
    	/* Setup drawable */ 
		myShapeDrawable = new ShapeDrawable(shape);
		myShapeDrawable.getPaint().set(paint);
		myShapeDrawable.setBounds(125, 225, 275, 375);
 
    	/* Setup view (which will draw our drawable) */ 
		final MyView myView = new MyView(this);
		setContentView(myView);
 
    	/* Setup Animator */ 
		ObjectAnimator a = ObjectAnimator.ofInt(myShapeDrawable, "alpha", 0, 100);
		a.setDuration(10000);
 
		a.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        	/* Listen to the update event */ 
			@Override 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setShaderFactory, setShape
      Toast.makeText(context, result, Toast.LENGTH_SHORT).show();
      return System.currentTimeMillis();
   } 
    
   public static PaintDrawable getPaintDrawable(int startX, int endX){
      PaintDrawable drawable = new PaintDrawable();
      drawable.setShape(new RectShape());
      drawable.setShaderFactory(getShaderFactory(startX, endX));
      return drawable;
   } 
 
   public static ShapeDrawable.ShaderFactory
   getShaderFactory(final int startX, final int endX){
      return new ShapeDrawable.ShaderFactory(){
 
         @Override 
         public Shader resize(int width, int height) {
            return new LinearGradient(startX, 0, endX, 0,
                  new int[]{ 0xFFDCDAD5, 0xFFFDFDF4, 
                  0xFFFFFFFF, 0xFFFDFBEF }, 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getPaint, setIntrinsicHeight, setIntrinsicWidth, setShape
				LayoutParams.WRAP_CONTENT);
    } 
    @Override 
	public boolean onTouch(View view, MotionEvent me) {
		if (me.getAction() == MotionEvent.ACTION_DOWN) {
			ShapeDrawable rectangle = new ShapeDrawable ();
	        rectangle.setShape(new RectShape());
	        rectangle.setIntrinsicHeight(100);
	        rectangle.setIntrinsicWidth(200);
	        rectangle.getPaint().setColor(Color.GREEN);
	        iView = new ImageView(this);
	        iView.setImageDrawable(rectangle); 
	         
			layout.addView(iView, params);
		} 
		if (me.getAction() == MotionEvent.ACTION_UP) {
			status = STOP_DRAGGING;
			 
		} else if (me.getAction() == MotionEvent.ACTION_MOVE) {
			if (status == START_DRAGGING) {
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Android ShapeDrawable Questions & Answers:

See Code Examples for Android ShapeDrawable Methods: