I draw the constellation line in the AR view of android device. using the following code. I found that the movement speed of objects(line) became very slow with the time. At the begin it just take0.047seconds, but after one or two minutes, it almost take 1 seconds to draw the constellation line. How to deal with this issue and speed up. lenght1 = 352, length2 = 384. how to improve the performance.
private void drawConstellationLine(Canvas canvas, int displayHeight,
int displayWidth) {
int length;
float ex = 0, ey = 0, bx = 0, by = 0;
Paint pline = new Paint();
pline.setColor(Color.RED);
double time1 = System.currentTimeMillis();
int i,j,length1,length2;
for( i = 0, length1 = ShowMoon.starlinelist.size(); i<length1;i++)
{
for( j = 0, length2 = ShowMoon.starlist.size(); j<length2;j++){
//System.out.println("length2:"+length2);
if(ShowMoon.starlinelist.get(i).beginhr ==ShowMoon.starlist.get(j).hr) {
bx = (float)ShowMoon.starlist.get(j).x;
by = (float)ShowMoon.starlist.get(j).y;
}
if(ShowMoon.starlinelist.get(i).endhr ==ShowMoon.starlist.get(j).hr) {
ex = (float)ShowMoon.starlist.get(j).x;
ey = (float)ShowMoon.starlist.get(j).y;
}
}
if (((bx >= 0 && bx <=displayWidth) ||( ex >= 0 && ex <= displayWidth))
&& ((ey >= 0 && ey <=displayHeight) || (by >= 0 && by <= displayHeight))){
canvas.drawLine(bx, by, ex, ey, pline);
//
double time2 = System.currentTimeMillis();
System.out.println("time dif:"+(time2-time1));
}
}
0 comments:
Post a Comment