Open Julisons opened 7 years ago
Thank you for creating issue! Could you give me the class? Thank you!
` // add pkg here import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.util.AttributeSet; import android.util.Log; import android.view.Display; import android.view.View; import android.view.WindowManager;
import java.util.Random;
public class EqualizerView extends View implements Runnable {
int drawColor;
Paint drawPaint;
float maxHeight = 60;
float width = 4;
float separation = 20;
float midx, midy;
private Random rand;
private int delay = 100;
private int count = 5;
float[] newHeight = new float[count];
double[] angle = new double[count];
boolean isPaused = true;
public EqualizerView(Context context) {
super(context);
init(context);
}
public EqualizerView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public EqualizerView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
public void init(Context context) {
getRatio(context);
rand = new Random(10);
drawColor = 14635967;
drawPaint = new Paint();
drawPaint.setColor(-drawColor);
maxHeight *= ratio;
width *= ratio;
separation *= ratio;
for (int i = 0; i < 5; i++) {
newHeight[i] = 0;
angle[i] = i * Math.PI / 6.0;
}
}
public void getRatio(Context context) {
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
screen_width = display.getWidth();
screen_height = display.getHeight();
ratio = (float) screen_height / (float) 1920;
ratio2 = (float) screen_width / (float) 1080;
ratio = Math.min(ratio, ratio2);
}
public static float ratio;
public static float ratio2;
public static int screen_width;
public static int screen_height;
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
midx = canvas.getWidth() / 2;
midy = canvas.getHeight();
separation = canvas.getWidth() / 14.0f;
maxHeight = canvas.getHeight() * 0.72f;
if (getVisibility() == VISIBLE) {
if (!isPaused) {
for (int i = 0; i < count; i++) {
// public void drawRect(float left, float top, float right, float bottom, Paint paint)
canvas.drawRect(midx - width + ((i - 2) * separation), midy - newHeight[i], midx + width + ((i - 2) * separation), midy, drawPaint);
}
} else {
for (int i = 0; i < count; i++) {
canvas.drawRect(midx - width + ((i - 2) * separation), midy - newHeight[i], midx + width + ((i - 2) * separation), midy, drawPaint);
}
} postDelayed(this, delay);
}
}
@Override
public void run() {
if (!isPaused){
for (int i = 0; i < count; i++) {
angle[i] += 0.09;
newHeight[i] = rand.nextFloat() * getHeight() /2;//(float) (maxHeight * (Math.abs(Math.sin(angle[i]) / 2.5f) + 0.15));
}}
invalidate();
}
public void pause() {
isPaused = true;
delay = 1000;
setVisibility(INVISIBLE);
invalidate();
}
public void play() {
isPaused = false;
delay = 100;
setVisibility(VISIBLE);
invalidate();
}
public void setDrawColor(int color){
drawColor = color;
drawPaint.setColor(color);
invalidate();
}
}`
I had customized it to suit my needs... any one can as well do that.
has memory leaks, however I have made another class that uses a runnable and not the Value animator thing.... contact me incase one needs the class.