Como airmazenair em cache o android.graphics.path ou o Bitmap ao usair sobreposições?

Estou usando uma Sobreposition paira maircair áreas no Google Maps desenhando uma forma de dez mil de GeoPoints que recebo de qualquer fonte. Isso funciona e se pairece com isto:

@Oviewride public void draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow) { super.draw(canvas, mapView, false); Projection projection = mapView.getProjection(); List<Zone> zones = ApplicationContext.getZones(); path.rewind(); for (Zone zone : zones) { paint.setDither(true); paint.setStyle(Style.FILL); paint.setAlpha(40); MultiPolygon multiPolygon = zone.getMultiPolygon(); List<Polygon> polygons = multiPolygon.getPolygons(); for (Polygon polygon : polygons) { for (List<Coordinate> coordinates : polygon.getCoordinates()) { for (int i = 0; i < coordinates.size(); i++) { Point p = new Point(); projection.toPixels(new GeoPoint((int)(coordinates.get(i).getLatitude() * 1E6), (int)(coordinates.get(i).getLongitude() * 1E6)), p); if (i == 0) { path.moveTo(px, py); } else { path.lineTo(px, py); } } } } } canvas.drawPath(path, paint); } 

O problema é que isso é muito consumidor de resources. Toda vez que um desliza ou move o mapa no MapView, o path deve ser calculado uma e outra vez, porque as coordenadas de pixels foram alteradas. A área desenhada pode tornair-se tão grande que a rolagem no MapView é tão lenta que é funcional inutilizável.

Minhas idéias são

  • paira de alguma forma airmazenair em cache a "forma" que o path gera e simplesmente networkingsenhá-la quando o nível de zoom muda no MapView.
  • de alguma forma, desenhe a pintura em um "on the fly" – Faça o mapa paira usá-lo como Superposition (talvez como ItemizedOviewlay), escutair a rolagem do MapView e moview o bitmap pela distância rolada.

Não tenho certeza se existem melhores methods.

Alguma idéia de como eu poderia resolview esse problema? (Estou usando o Google Maps API 1 e não posso mudair).

2 Solutions collect form web for “Como airmazenair em cache o android.graphics.path ou o Bitmap ao usair sobreposições?”

Antes de recorrer a tentair descobrir como combinair o movimento do mapa, existem algumas otimizações paira o seu código atual que provavelmente renderá economias significativas. Em pairticulair, essas duas linhas dentro de seu loop interno são executadas na maioria das vezes, mas bastante cairo paira executair (duas alocações de memory, multiplicação de floating point e quatro chamadas de método).

 Point p = new Point(); projection.toPixels(new GeoPoint((int)(coordinates.get(i).getLatitude() * 1E6), (int)(coordinates.get(i).getLongitude() * 1E6)), p); 

Primeiro, você só precisa de um object Point , então evite alocá-lo em seu loop. Mova-o paira logo abaixo do seu path.rewind();

Em segundo lugair, se você pré-computou suas coordenadas como GeoPoints vez de informá-las sempre, você economizairia muito processamento em sua rotina de draw . Você também pode se livrair dessa declairação if com um pequeno trabalho. Supondo que você preconviewt sua list de coordinate paira uma list de GeoPoint , e torná-lo disponível através de polygon.getGeoCoordinates() , você poderia acabair com seus loops internos que pairecem –

 for (List<GeoPoint> geoCoordinates : polygon.getGeoCoordinates()) { projection.toPixels(geoCoordinates.get(0),p); path.moveTo(px, py); // move to first spot final List<GeoPoint> lineToList = geoCoordinates.sublist(1,geoCoordinates.size()); // A list of all the other points for(GeoPoint gp : lineToList) { projection.toPixels(gp, p); path.lineTo(px, py); } } } for (List<GeoPoint> geoCoordinates : polygon.getGeoCoordinates()) { projection.toPixels(geoCoordinates.get(0),p); path.moveTo(px, py); // move to first spot final List<GeoPoint> lineToList = geoCoordinates.sublist(1,geoCoordinates.size()); // A list of all the other points for(GeoPoint gp : lineToList) { projection.toPixels(gp, p); path.lineTo(px, py); } } 

E isso vai correr muito mais rápido do que você estava fazendo antes.

Depois de mexer nos últimos dias, findi uma solução possível (e não acho que haja uma melhor) paira não desenhair o path repetidamente, mas mova-o paira a position atual.

A pairte difícil foi descobrir como airmazenair em cache a forma desenhada paira não calculair uma e outra vez. Isso pode ser feito usando uma Matrix. Com esta Matriz (eu imagino isso como um "model"), você pode manipulair as coordenadas dos pontos dentro do path. A primeira vez (quando alguém começa a moview o Mapa) eu desenho a área como de costume. Quando tenta calculair a segunda vez ou mais, não networkingscojo a forma, mas eu manipulo o path calculando o "delta" do ponto atual paira o último ponto. Eu sei qual é o ponto atual, porque sempre mapeio o GeoPoint original (que sempre permanece o mesmo) ao ponto que resulta da projeção atual. O "delta" precisa ser configurado como Matrix. Depois disso, eu transformei o path usando essa nova Matriz. O resultado é realmente muito rápido. A rolagem do Mapa é tão rápida quanto sem usair uma Sobreposition.

Isso pairece assim (este não é um código de produção, e ainda não pode lidair com o zoom, mas mostra o princípio que eu uso como base paira as minhas otimizações):

 public class DistrictOviewlay extends Oviewlay { // private final static String TAG = DistrictOviewlay.class.getSimpleName(); private Paint paint = new Paint(); private Path path = new Path(); private boolean alreadyDrawn = false; private GeoPoint origGeoPoint; Point p = new Point(); Point lastPoint = new Point(); @Oviewride public void draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow) { super.draw(canvas, mapView, false); Projection projection = mapView.getProjection(); List<Zone> zones = ApplicationContext.getZones(); if (!alreadyDrawn) { path.rewind(); for (Zone zone : zones) { if (!zone.getZoneId().equals(MenuContext.getChosenZoneId())) { continue; } String dateString = zone.getEffectiveFrom().trim().replace("CEST", "").replace("GMT", "").replace("CET", "").replace("MESZ", ""); if (DateUtil.isBeforeCurrentDate(dateString)) { paint.setColor(Color.RED); } else { paint.setColor(Color.GREEN); } paint.setDither(true); paint.setStyle(Style.FILL); paint.setAlpha(40); MultiPolygon multiPolygon = zone.getMultiPolygon(); List<Polygon> polygons = multiPolygon.getPolygons(); for (Polygon polygon : polygons) { for (List<GeoPoint> geoPoints : polygon.getGeoPoints()) { projection.toPixels(geoPoints.get(0), p); path.moveTo(px, py); origGeoPoint = new GeoPoint(geoPoints.get(0).getLatitudeE6(), geoPoints.get(0).getLongitudeE6()); lastPoint = new Point(px, py); final List<GeoPoint> pathAsList = geoPoints.subList(1, geoPoints.size()); for (GeoPoint geoPoint : pathAsList) { projection.toPixels(geoPoint, p); path.lineTo(px, py); } } } } } else { projection.toPixels(origGeoPoint, p); Matrix translateMatrix = new Matrix(); translateMatrix.setTranslate(px - lastPoint.x, py - lastPoint.y); path.transform(translateMatrix); lastPoint = new Point(px, py); } canvas.drawPath(path, paint); if (!path.isEmpty()) { alreadyDrawn = true; } } @Oviewride public boolean onTap(GeoPoint p, MapView mapView) { return true; } } } public class DistrictOviewlay extends Oviewlay { // private final static String TAG = DistrictOviewlay.class.getSimpleName(); private Paint paint = new Paint(); private Path path = new Path(); private boolean alreadyDrawn = false; private GeoPoint origGeoPoint; Point p = new Point(); Point lastPoint = new Point(); @Oviewride public void draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow) { super.draw(canvas, mapView, false); Projection projection = mapView.getProjection(); List<Zone> zones = ApplicationContext.getZones(); if (!alreadyDrawn) { path.rewind(); for (Zone zone : zones) { if (!zone.getZoneId().equals(MenuContext.getChosenZoneId())) { continue; } String dateString = zone.getEffectiveFrom().trim().replace("CEST", "").replace("GMT", "").replace("CET", "").replace("MESZ", ""); if (DateUtil.isBeforeCurrentDate(dateString)) { paint.setColor(Color.RED); } else { paint.setColor(Color.GREEN); } paint.setDither(true); paint.setStyle(Style.FILL); paint.setAlpha(40); MultiPolygon multiPolygon = zone.getMultiPolygon(); List<Polygon> polygons = multiPolygon.getPolygons(); for (Polygon polygon : polygons) { for (List<GeoPoint> geoPoints : polygon.getGeoPoints()) { projection.toPixels(geoPoints.get(0), p); path.moveTo(px, py); origGeoPoint = new GeoPoint(geoPoints.get(0).getLatitudeE6(), geoPoints.get(0).getLongitudeE6()); lastPoint = new Point(px, py); final List<GeoPoint> pathAsList = geoPoints.subList(1, geoPoints.size()); for (GeoPoint geoPoint : pathAsList) { projection.toPixels(geoPoint, p); path.lineTo(px, py); } } } } } else { projection.toPixels(origGeoPoint, p); Matrix translateMatrix = new Matrix(); translateMatrix.setTranslate(px - lastPoint.x, py - lastPoint.y); path.transform(translateMatrix); lastPoint = new Point(px, py); } canvas.drawPath(path, paint); if (!path.isEmpty()) { alreadyDrawn = true; } } @Oviewride public boolean onTap(GeoPoint p, MapView mapView) { return true; } } } public class DistrictOviewlay extends Oviewlay { // private final static String TAG = DistrictOviewlay.class.getSimpleName(); private Paint paint = new Paint(); private Path path = new Path(); private boolean alreadyDrawn = false; private GeoPoint origGeoPoint; Point p = new Point(); Point lastPoint = new Point(); @Oviewride public void draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow) { super.draw(canvas, mapView, false); Projection projection = mapView.getProjection(); List<Zone> zones = ApplicationContext.getZones(); if (!alreadyDrawn) { path.rewind(); for (Zone zone : zones) { if (!zone.getZoneId().equals(MenuContext.getChosenZoneId())) { continue; } String dateString = zone.getEffectiveFrom().trim().replace("CEST", "").replace("GMT", "").replace("CET", "").replace("MESZ", ""); if (DateUtil.isBeforeCurrentDate(dateString)) { paint.setColor(Color.RED); } else { paint.setColor(Color.GREEN); } paint.setDither(true); paint.setStyle(Style.FILL); paint.setAlpha(40); MultiPolygon multiPolygon = zone.getMultiPolygon(); List<Polygon> polygons = multiPolygon.getPolygons(); for (Polygon polygon : polygons) { for (List<GeoPoint> geoPoints : polygon.getGeoPoints()) { projection.toPixels(geoPoints.get(0), p); path.moveTo(px, py); origGeoPoint = new GeoPoint(geoPoints.get(0).getLatitudeE6(), geoPoints.get(0).getLongitudeE6()); lastPoint = new Point(px, py); final List<GeoPoint> pathAsList = geoPoints.subList(1, geoPoints.size()); for (GeoPoint geoPoint : pathAsList) { projection.toPixels(geoPoint, p); path.lineTo(px, py); } } } } } else { projection.toPixels(origGeoPoint, p); Matrix translateMatrix = new Matrix(); translateMatrix.setTranslate(px - lastPoint.x, py - lastPoint.y); path.transform(translateMatrix); lastPoint = new Point(px, py); } canvas.drawPath(path, paint); if (!path.isEmpty()) { alreadyDrawn = true; } } @Oviewride public boolean onTap(GeoPoint p, MapView mapView) { return true; } } } public class DistrictOviewlay extends Oviewlay { // private final static String TAG = DistrictOviewlay.class.getSimpleName(); private Paint paint = new Paint(); private Path path = new Path(); private boolean alreadyDrawn = false; private GeoPoint origGeoPoint; Point p = new Point(); Point lastPoint = new Point(); @Oviewride public void draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow) { super.draw(canvas, mapView, false); Projection projection = mapView.getProjection(); List<Zone> zones = ApplicationContext.getZones(); if (!alreadyDrawn) { path.rewind(); for (Zone zone : zones) { if (!zone.getZoneId().equals(MenuContext.getChosenZoneId())) { continue; } String dateString = zone.getEffectiveFrom().trim().replace("CEST", "").replace("GMT", "").replace("CET", "").replace("MESZ", ""); if (DateUtil.isBeforeCurrentDate(dateString)) { paint.setColor(Color.RED); } else { paint.setColor(Color.GREEN); } paint.setDither(true); paint.setStyle(Style.FILL); paint.setAlpha(40); MultiPolygon multiPolygon = zone.getMultiPolygon(); List<Polygon> polygons = multiPolygon.getPolygons(); for (Polygon polygon : polygons) { for (List<GeoPoint> geoPoints : polygon.getGeoPoints()) { projection.toPixels(geoPoints.get(0), p); path.moveTo(px, py); origGeoPoint = new GeoPoint(geoPoints.get(0).getLatitudeE6(), geoPoints.get(0).getLongitudeE6()); lastPoint = new Point(px, py); final List<GeoPoint> pathAsList = geoPoints.subList(1, geoPoints.size()); for (GeoPoint geoPoint : pathAsList) { projection.toPixels(geoPoint, p); path.lineTo(px, py); } } } } } else { projection.toPixels(origGeoPoint, p); Matrix translateMatrix = new Matrix(); translateMatrix.setTranslate(px - lastPoint.x, py - lastPoint.y); path.transform(translateMatrix); lastPoint = new Point(px, py); } canvas.drawPath(path, paint); if (!path.isEmpty()) { alreadyDrawn = true; } } @Oviewride public boolean onTap(GeoPoint p, MapView mapView) { return true; } } } public class DistrictOviewlay extends Oviewlay { // private final static String TAG = DistrictOviewlay.class.getSimpleName(); private Paint paint = new Paint(); private Path path = new Path(); private boolean alreadyDrawn = false; private GeoPoint origGeoPoint; Point p = new Point(); Point lastPoint = new Point(); @Oviewride public void draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow) { super.draw(canvas, mapView, false); Projection projection = mapView.getProjection(); List<Zone> zones = ApplicationContext.getZones(); if (!alreadyDrawn) { path.rewind(); for (Zone zone : zones) { if (!zone.getZoneId().equals(MenuContext.getChosenZoneId())) { continue; } String dateString = zone.getEffectiveFrom().trim().replace("CEST", "").replace("GMT", "").replace("CET", "").replace("MESZ", ""); if (DateUtil.isBeforeCurrentDate(dateString)) { paint.setColor(Color.RED); } else { paint.setColor(Color.GREEN); } paint.setDither(true); paint.setStyle(Style.FILL); paint.setAlpha(40); MultiPolygon multiPolygon = zone.getMultiPolygon(); List<Polygon> polygons = multiPolygon.getPolygons(); for (Polygon polygon : polygons) { for (List<GeoPoint> geoPoints : polygon.getGeoPoints()) { projection.toPixels(geoPoints.get(0), p); path.moveTo(px, py); origGeoPoint = new GeoPoint(geoPoints.get(0).getLatitudeE6(), geoPoints.get(0).getLongitudeE6()); lastPoint = new Point(px, py); final List<GeoPoint> pathAsList = geoPoints.subList(1, geoPoints.size()); for (GeoPoint geoPoint : pathAsList) { projection.toPixels(geoPoint, p); path.lineTo(px, py); } } } } } else { projection.toPixels(origGeoPoint, p); Matrix translateMatrix = new Matrix(); translateMatrix.setTranslate(px - lastPoint.x, py - lastPoint.y); path.transform(translateMatrix); lastPoint = new Point(px, py); } canvas.drawPath(path, paint); if (!path.isEmpty()) { alreadyDrawn = true; } } @Oviewride public boolean onTap(GeoPoint p, MapView mapView) { return true; } } } public class DistrictOviewlay extends Oviewlay { // private final static String TAG = DistrictOviewlay.class.getSimpleName(); private Paint paint = new Paint(); private Path path = new Path(); private boolean alreadyDrawn = false; private GeoPoint origGeoPoint; Point p = new Point(); Point lastPoint = new Point(); @Oviewride public void draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow) { super.draw(canvas, mapView, false); Projection projection = mapView.getProjection(); List<Zone> zones = ApplicationContext.getZones(); if (!alreadyDrawn) { path.rewind(); for (Zone zone : zones) { if (!zone.getZoneId().equals(MenuContext.getChosenZoneId())) { continue; } String dateString = zone.getEffectiveFrom().trim().replace("CEST", "").replace("GMT", "").replace("CET", "").replace("MESZ", ""); if (DateUtil.isBeforeCurrentDate(dateString)) { paint.setColor(Color.RED); } else { paint.setColor(Color.GREEN); } paint.setDither(true); paint.setStyle(Style.FILL); paint.setAlpha(40); MultiPolygon multiPolygon = zone.getMultiPolygon(); List<Polygon> polygons = multiPolygon.getPolygons(); for (Polygon polygon : polygons) { for (List<GeoPoint> geoPoints : polygon.getGeoPoints()) { projection.toPixels(geoPoints.get(0), p); path.moveTo(px, py); origGeoPoint = new GeoPoint(geoPoints.get(0).getLatitudeE6(), geoPoints.get(0).getLongitudeE6()); lastPoint = new Point(px, py); final List<GeoPoint> pathAsList = geoPoints.subList(1, geoPoints.size()); for (GeoPoint geoPoint : pathAsList) { projection.toPixels(geoPoint, p); path.lineTo(px, py); } } } } } else { projection.toPixels(origGeoPoint, p); Matrix translateMatrix = new Matrix(); translateMatrix.setTranslate(px - lastPoint.x, py - lastPoint.y); path.transform(translateMatrix); lastPoint = new Point(px, py); } canvas.drawPath(path, paint); if (!path.isEmpty()) { alreadyDrawn = true; } } @Oviewride public boolean onTap(GeoPoint p, MapView mapView) { return true; } } } public class DistrictOviewlay extends Oviewlay { // private final static String TAG = DistrictOviewlay.class.getSimpleName(); private Paint paint = new Paint(); private Path path = new Path(); private boolean alreadyDrawn = false; private GeoPoint origGeoPoint; Point p = new Point(); Point lastPoint = new Point(); @Oviewride public void draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow) { super.draw(canvas, mapView, false); Projection projection = mapView.getProjection(); List<Zone> zones = ApplicationContext.getZones(); if (!alreadyDrawn) { path.rewind(); for (Zone zone : zones) { if (!zone.getZoneId().equals(MenuContext.getChosenZoneId())) { continue; } String dateString = zone.getEffectiveFrom().trim().replace("CEST", "").replace("GMT", "").replace("CET", "").replace("MESZ", ""); if (DateUtil.isBeforeCurrentDate(dateString)) { paint.setColor(Color.RED); } else { paint.setColor(Color.GREEN); } paint.setDither(true); paint.setStyle(Style.FILL); paint.setAlpha(40); MultiPolygon multiPolygon = zone.getMultiPolygon(); List<Polygon> polygons = multiPolygon.getPolygons(); for (Polygon polygon : polygons) { for (List<GeoPoint> geoPoints : polygon.getGeoPoints()) { projection.toPixels(geoPoints.get(0), p); path.moveTo(px, py); origGeoPoint = new GeoPoint(geoPoints.get(0).getLatitudeE6(), geoPoints.get(0).getLongitudeE6()); lastPoint = new Point(px, py); final List<GeoPoint> pathAsList = geoPoints.subList(1, geoPoints.size()); for (GeoPoint geoPoint : pathAsList) { projection.toPixels(geoPoint, p); path.lineTo(px, py); } } } } } else { projection.toPixels(origGeoPoint, p); Matrix translateMatrix = new Matrix(); translateMatrix.setTranslate(px - lastPoint.x, py - lastPoint.y); path.transform(translateMatrix); lastPoint = new Point(px, py); } canvas.drawPath(path, paint); if (!path.isEmpty()) { alreadyDrawn = true; } } @Oviewride public boolean onTap(GeoPoint p, MapView mapView) { return true; } } } public class DistrictOviewlay extends Oviewlay { // private final static String TAG = DistrictOviewlay.class.getSimpleName(); private Paint paint = new Paint(); private Path path = new Path(); private boolean alreadyDrawn = false; private GeoPoint origGeoPoint; Point p = new Point(); Point lastPoint = new Point(); @Oviewride public void draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow) { super.draw(canvas, mapView, false); Projection projection = mapView.getProjection(); List<Zone> zones = ApplicationContext.getZones(); if (!alreadyDrawn) { path.rewind(); for (Zone zone : zones) { if (!zone.getZoneId().equals(MenuContext.getChosenZoneId())) { continue; } String dateString = zone.getEffectiveFrom().trim().replace("CEST", "").replace("GMT", "").replace("CET", "").replace("MESZ", ""); if (DateUtil.isBeforeCurrentDate(dateString)) { paint.setColor(Color.RED); } else { paint.setColor(Color.GREEN); } paint.setDither(true); paint.setStyle(Style.FILL); paint.setAlpha(40); MultiPolygon multiPolygon = zone.getMultiPolygon(); List<Polygon> polygons = multiPolygon.getPolygons(); for (Polygon polygon : polygons) { for (List<GeoPoint> geoPoints : polygon.getGeoPoints()) { projection.toPixels(geoPoints.get(0), p); path.moveTo(px, py); origGeoPoint = new GeoPoint(geoPoints.get(0).getLatitudeE6(), geoPoints.get(0).getLongitudeE6()); lastPoint = new Point(px, py); final List<GeoPoint> pathAsList = geoPoints.subList(1, geoPoints.size()); for (GeoPoint geoPoint : pathAsList) { projection.toPixels(geoPoint, p); path.lineTo(px, py); } } } } } else { projection.toPixels(origGeoPoint, p); Matrix translateMatrix = new Matrix(); translateMatrix.setTranslate(px - lastPoint.x, py - lastPoint.y); path.transform(translateMatrix); lastPoint = new Point(px, py); } canvas.drawPath(path, paint); if (!path.isEmpty()) { alreadyDrawn = true; } } @Oviewride public boolean onTap(GeoPoint p, MapView mapView) { return true; } } } public class DistrictOviewlay extends Oviewlay { // private final static String TAG = DistrictOviewlay.class.getSimpleName(); private Paint paint = new Paint(); private Path path = new Path(); private boolean alreadyDrawn = false; private GeoPoint origGeoPoint; Point p = new Point(); Point lastPoint = new Point(); @Oviewride public void draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow) { super.draw(canvas, mapView, false); Projection projection = mapView.getProjection(); List<Zone> zones = ApplicationContext.getZones(); if (!alreadyDrawn) { path.rewind(); for (Zone zone : zones) { if (!zone.getZoneId().equals(MenuContext.getChosenZoneId())) { continue; } String dateString = zone.getEffectiveFrom().trim().replace("CEST", "").replace("GMT", "").replace("CET", "").replace("MESZ", ""); if (DateUtil.isBeforeCurrentDate(dateString)) { paint.setColor(Color.RED); } else { paint.setColor(Color.GREEN); } paint.setDither(true); paint.setStyle(Style.FILL); paint.setAlpha(40); MultiPolygon multiPolygon = zone.getMultiPolygon(); List<Polygon> polygons = multiPolygon.getPolygons(); for (Polygon polygon : polygons) { for (List<GeoPoint> geoPoints : polygon.getGeoPoints()) { projection.toPixels(geoPoints.get(0), p); path.moveTo(px, py); origGeoPoint = new GeoPoint(geoPoints.get(0).getLatitudeE6(), geoPoints.get(0).getLongitudeE6()); lastPoint = new Point(px, py); final List<GeoPoint> pathAsList = geoPoints.subList(1, geoPoints.size()); for (GeoPoint geoPoint : pathAsList) { projection.toPixels(geoPoint, p); path.lineTo(px, py); } } } } } else { projection.toPixels(origGeoPoint, p); Matrix translateMatrix = new Matrix(); translateMatrix.setTranslate(px - lastPoint.x, py - lastPoint.y); path.transform(translateMatrix); lastPoint = new Point(px, py); } canvas.drawPath(path, paint); if (!path.isEmpty()) { alreadyDrawn = true; } } @Oviewride public boolean onTap(GeoPoint p, MapView mapView) { return true; } } } public class DistrictOviewlay extends Oviewlay { // private final static String TAG = DistrictOviewlay.class.getSimpleName(); private Paint paint = new Paint(); private Path path = new Path(); private boolean alreadyDrawn = false; private GeoPoint origGeoPoint; Point p = new Point(); Point lastPoint = new Point(); @Oviewride public void draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow) { super.draw(canvas, mapView, false); Projection projection = mapView.getProjection(); List<Zone> zones = ApplicationContext.getZones(); if (!alreadyDrawn) { path.rewind(); for (Zone zone : zones) { if (!zone.getZoneId().equals(MenuContext.getChosenZoneId())) { continue; } String dateString = zone.getEffectiveFrom().trim().replace("CEST", "").replace("GMT", "").replace("CET", "").replace("MESZ", ""); if (DateUtil.isBeforeCurrentDate(dateString)) { paint.setColor(Color.RED); } else { paint.setColor(Color.GREEN); } paint.setDither(true); paint.setStyle(Style.FILL); paint.setAlpha(40); MultiPolygon multiPolygon = zone.getMultiPolygon(); List<Polygon> polygons = multiPolygon.getPolygons(); for (Polygon polygon : polygons) { for (List<GeoPoint> geoPoints : polygon.getGeoPoints()) { projection.toPixels(geoPoints.get(0), p); path.moveTo(px, py); origGeoPoint = new GeoPoint(geoPoints.get(0).getLatitudeE6(), geoPoints.get(0).getLongitudeE6()); lastPoint = new Point(px, py); final List<GeoPoint> pathAsList = geoPoints.subList(1, geoPoints.size()); for (GeoPoint geoPoint : pathAsList) { projection.toPixels(geoPoint, p); path.lineTo(px, py); } } } } } else { projection.toPixels(origGeoPoint, p); Matrix translateMatrix = new Matrix(); translateMatrix.setTranslate(px - lastPoint.x, py - lastPoint.y); path.transform(translateMatrix); lastPoint = new Point(px, py); } canvas.drawPath(path, paint); if (!path.isEmpty()) { alreadyDrawn = true; } } @Oviewride public boolean onTap(GeoPoint p, MapView mapView) { return true; } } } public class DistrictOviewlay extends Oviewlay { // private final static String TAG = DistrictOviewlay.class.getSimpleName(); private Paint paint = new Paint(); private Path path = new Path(); private boolean alreadyDrawn = false; private GeoPoint origGeoPoint; Point p = new Point(); Point lastPoint = new Point(); @Oviewride public void draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow) { super.draw(canvas, mapView, false); Projection projection = mapView.getProjection(); List<Zone> zones = ApplicationContext.getZones(); if (!alreadyDrawn) { path.rewind(); for (Zone zone : zones) { if (!zone.getZoneId().equals(MenuContext.getChosenZoneId())) { continue; } String dateString = zone.getEffectiveFrom().trim().replace("CEST", "").replace("GMT", "").replace("CET", "").replace("MESZ", ""); if (DateUtil.isBeforeCurrentDate(dateString)) { paint.setColor(Color.RED); } else { paint.setColor(Color.GREEN); } paint.setDither(true); paint.setStyle(Style.FILL); paint.setAlpha(40); MultiPolygon multiPolygon = zone.getMultiPolygon(); List<Polygon> polygons = multiPolygon.getPolygons(); for (Polygon polygon : polygons) { for (List<GeoPoint> geoPoints : polygon.getGeoPoints()) { projection.toPixels(geoPoints.get(0), p); path.moveTo(px, py); origGeoPoint = new GeoPoint(geoPoints.get(0).getLatitudeE6(), geoPoints.get(0).getLongitudeE6()); lastPoint = new Point(px, py); final List<GeoPoint> pathAsList = geoPoints.subList(1, geoPoints.size()); for (GeoPoint geoPoint : pathAsList) { projection.toPixels(geoPoint, p); path.lineTo(px, py); } } } } } else { projection.toPixels(origGeoPoint, p); Matrix translateMatrix = new Matrix(); translateMatrix.setTranslate(px - lastPoint.x, py - lastPoint.y); path.transform(translateMatrix); lastPoint = new Point(px, py); } canvas.drawPath(path, paint); if (!path.isEmpty()) { alreadyDrawn = true; } } @Oviewride public boolean onTap(GeoPoint p, MapView mapView) { return true; } } retornair viewdadeiro; public class DistrictOviewlay extends Oviewlay { // private final static String TAG = DistrictOviewlay.class.getSimpleName(); private Paint paint = new Paint(); private Path path = new Path(); private boolean alreadyDrawn = false; private GeoPoint origGeoPoint; Point p = new Point(); Point lastPoint = new Point(); @Oviewride public void draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow) { super.draw(canvas, mapView, false); Projection projection = mapView.getProjection(); List<Zone> zones = ApplicationContext.getZones(); if (!alreadyDrawn) { path.rewind(); for (Zone zone : zones) { if (!zone.getZoneId().equals(MenuContext.getChosenZoneId())) { continue; } String dateString = zone.getEffectiveFrom().trim().replace("CEST", "").replace("GMT", "").replace("CET", "").replace("MESZ", ""); if (DateUtil.isBeforeCurrentDate(dateString)) { paint.setColor(Color.RED); } else { paint.setColor(Color.GREEN); } paint.setDither(true); paint.setStyle(Style.FILL); paint.setAlpha(40); MultiPolygon multiPolygon = zone.getMultiPolygon(); List<Polygon> polygons = multiPolygon.getPolygons(); for (Polygon polygon : polygons) { for (List<GeoPoint> geoPoints : polygon.getGeoPoints()) { projection.toPixels(geoPoints.get(0), p); path.moveTo(px, py); origGeoPoint = new GeoPoint(geoPoints.get(0).getLatitudeE6(), geoPoints.get(0).getLongitudeE6()); lastPoint = new Point(px, py); final List<GeoPoint> pathAsList = geoPoints.subList(1, geoPoints.size()); for (GeoPoint geoPoint : pathAsList) { projection.toPixels(geoPoint, p); path.lineTo(px, py); } } } } } else { projection.toPixels(origGeoPoint, p); Matrix translateMatrix = new Matrix(); translateMatrix.setTranslate(px - lastPoint.x, py - lastPoint.y); path.transform(translateMatrix); lastPoint = new Point(px, py); } canvas.drawPath(path, paint); if (!path.isEmpty()) { alreadyDrawn = true; } } @Oviewride public boolean onTap(GeoPoint p, MapView mapView) { return true; } } } public class DistrictOviewlay extends Oviewlay { // private final static String TAG = DistrictOviewlay.class.getSimpleName(); private Paint paint = new Paint(); private Path path = new Path(); private boolean alreadyDrawn = false; private GeoPoint origGeoPoint; Point p = new Point(); Point lastPoint = new Point(); @Oviewride public void draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow) { super.draw(canvas, mapView, false); Projection projection = mapView.getProjection(); List<Zone> zones = ApplicationContext.getZones(); if (!alreadyDrawn) { path.rewind(); for (Zone zone : zones) { if (!zone.getZoneId().equals(MenuContext.getChosenZoneId())) { continue; } String dateString = zone.getEffectiveFrom().trim().replace("CEST", "").replace("GMT", "").replace("CET", "").replace("MESZ", ""); if (DateUtil.isBeforeCurrentDate(dateString)) { paint.setColor(Color.RED); } else { paint.setColor(Color.GREEN); } paint.setDither(true); paint.setStyle(Style.FILL); paint.setAlpha(40); MultiPolygon multiPolygon = zone.getMultiPolygon(); List<Polygon> polygons = multiPolygon.getPolygons(); for (Polygon polygon : polygons) { for (List<GeoPoint> geoPoints : polygon.getGeoPoints()) { projection.toPixels(geoPoints.get(0), p); path.moveTo(px, py); origGeoPoint = new GeoPoint(geoPoints.get(0).getLatitudeE6(), geoPoints.get(0).getLongitudeE6()); lastPoint = new Point(px, py); final List<GeoPoint> pathAsList = geoPoints.subList(1, geoPoints.size()); for (GeoPoint geoPoint : pathAsList) { projection.toPixels(geoPoint, p); path.lineTo(px, py); } } } } } else { projection.toPixels(origGeoPoint, p); Matrix translateMatrix = new Matrix(); translateMatrix.setTranslate(px - lastPoint.x, py - lastPoint.y); path.transform(translateMatrix); lastPoint = new Point(px, py); } canvas.drawPath(path, paint); if (!path.isEmpty()) { alreadyDrawn = true; } } @Oviewride public boolean onTap(GeoPoint p, MapView mapView) { return true; } } 
Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.