HeartlandSoftware / AndroidHeatMap

A heat map view for Android.
Apache License 2.0
127 stars 33 forks source link

Points not showing except added from onCreate() #9

Open sontqq opened 5 years ago

sontqq commented 5 years ago

Hey I am trying to add points to the heatmap each time the user touches the screen, but it doesn't work from the @Override public boolean onTouchEvent(MotionEvent event) method. Could anyone help? I've also tried invalidating and refreshing the heatmap without any success.

https://pastebin.com/4mHGyf1y

Here is my code.

tredpath commented 5 years ago

Before returning at the end of onTouchEvent refresh the heatmap:

if (event.getAction() == MotionEvent.ACTION_UP)
    heatMap.forceRefresh();
sontqq commented 5 years ago

Everytime I try to refresh the heatmap I get:

/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.sontme.esp.getlocation, PID: 21362
    java.lang.NegativeArraySizeException: -8920

However I didn't try to add any negative values. Any idea?

case MotionEvent.ACTION_UP:
                heatMap.setMinimum(0.0);
                heatMap.setMaximum(10000.0);
                HeatMap.DataPoint point = new HeatMap.DataPoint(xrf, yrf, xrf);
                heatMap.addData(point);
                heatMap.forceRefresh();
                break;
tredpath commented 5 years ago

Your xrf and yrf need divided by 100 to turn them into a decimal percent. The library doesn't do a lot of bounds checking so when it's trying to clip the region it needs to draw to if you have values that are greater than 100% (1.0) it will cause negative values in array sizes and cause the crash you're seeing.

teriame commented 4 years ago

For me, heatMap.forceRefresh(); after heatMap.addData(point); clears the whole canvas except for the point I added recently. How can I add points one after another by touching?

Manal-SE commented 2 years ago

what is the range of the points ? x=670 and y =870 for me