Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory Issues #2

Open
Julisons opened this issue Jul 12, 2017 · 3 comments

Comments

@Julisons
Copy link

commented Jul 12, 2017

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.

@Taishi-Y

This comment has been minimized.

Copy link
Owner

commented Jul 13, 2017

Thank you for creating issue!
Could you give me the class?
Thank you!

@Julisons

This comment has been minimized.

Copy link
Author

commented Jul 13, 2017

`
// 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();
}

}`

@Julisons

This comment has been minimized.

Copy link
Author

commented Jul 13, 2017

I had customized it to suit my needs... any one can as well do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.