I am displaying a large number of overlays on a map; the process takes 5-10 seconds. Rather than using a progress bar I want the overlays to appear gradually on the map over this time.
So for every 25 lines that are calculated I am trying to show them before continuing:
for (KmlRoad road :roads)
{
// 25 lines in this array
Polyline pline = new Polyline();
pline.getOutlinePaint().setColor(Color.RED);
pline.setPoints(road.points);
map.getOverlayManager().add(pline);
++roadsShown;
}
map.invalidate();
progressText.setText(roadsShown + " roads");
But nothing happens for a while and then all the overlays (several hundred of them) appear at once. The 'progressText' isn't updated, either.
I have also tried doing the calculation part in an async task, and sending an intent to the map activity for every 25 lines. It gives the same result, unless I add
SystemClock.sleep(xx);
to to async task, which seems very crude and is only guessing at how long the lines take to draw. Here's the code in the async task, which is called every time 25 lines have been calculated:
private void sendRoads(ArrayList<KmlRoad> roads25)
{
ArrayList<KmlRoad> theseRoads = new ArrayList<>(roads25);
// prepare array for next batch while we deal with this one
roads25.clear();
Intent intent = new Intent("newRoads");
intent.putParcelableArrayListExtra("newRoads", theseRoads);
LocalBroadcastManager.getInstance(activity).sendBroadcast(intent);
// procSpped is a crude assessment of how slow the device runs,
// generated by doing a repeat loop of math functions
SystemClock.sleep(2 * activity.procSpeed);
}
... and (if using the async method) the receiver in the main activity, which surrounds the line-drawing code above:
private final BroadcastReceiver onNewRoad = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
ArrayList<KmlRoad> roads = intent.getParcelableArrayListExtra("newRoads");
....
....
}
};
What can I do to make this show as intended?.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…