Skip to content

Commit

Permalink
custom glass progessbar
Browse files Browse the repository at this point in the history
  • Loading branch information
jignesh13 committed Apr 30, 2019
1 parent fbf8acb commit cc91a9a
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 1 deletion.
111 changes: 111 additions & 0 deletions app/src/main/java/com/example/glassprogessview/HeartView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package com.example.glassprogessview;

import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.RectF;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

public class HeartView extends View {

private Path path;

private Paint paint;
private float progess=0.5f;

public HeartView(Context context) {
super(context);

path = new Path();
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
}


public HeartView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);

path = new Path();
paint = new Paint(Paint.ANTI_ALIAS_FLAG);

}

public HeartView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);

path = new Path();
paint = new Paint(Paint.ANTI_ALIAS_FLAG);

}

public HeartView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
path = new Path();
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
}

@Override
protected void onDraw(Canvas canvas) {


// Fill the canvas with background color
//canvas.drawColor(Color.WHITE);
paint.setShader(null);

float width = getWidth();
float height = getHeight();

// Starting point
path.moveTo(width / 2, height / 5);

// Upper left path
path.cubicTo(5 * width / 14, 0,
0, height / 15,
width / 28, 2 * height / 5);

// Lower left path
path.cubicTo(width / 14, 2 * height / 3,
3 * width / 7, 5 * height / 6,
width / 2, height);

// Lower right path
path.cubicTo(4 * width / 7, 5 * height / 6,
13 * width / 14, 2 * height / 3,
27 * width / 28, 2 * height / 5);

// Upper right path
path.cubicTo(width, height / 15,
9 * width / 14, 0,
width / 2, height / 5);
paint.setStrokeWidth(5.0f);
paint.setColor(Color.RED);
paint.setStyle(Style.STROKE);

canvas.drawPath(path, paint);
RectF rectF=new RectF(0,(canvas.getHeight()*progess),getWidth(),getHeight());
paint.setStyle(Style.FILL);
canvas.clipPath(path);

canvas.drawRect(rectF,paint);
super.onDraw(canvas);

}
public void setprogess(float newprogess){

ValueAnimator valueAnimator=ValueAnimator.ofFloat(progess,newprogess).setDuration(600);
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
progess = (float) valueAnimator.getAnimatedValue();
invalidate();
}
});
valueAnimator.start();
}

}
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
android:layout_height="match_parent"
tools:context=".MainActivity">

<com.example.glassprogessview.VesselView
<com.example.glassprogessview.Heart
android:id="@+id/vesselview"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down

0 comments on commit cc91a9a

Please sign in to comment.