package com.mapswithme.yopme.map;

import android.graphics.Bitmap;
import com.mapswithme.maps.api.MWMPoint;
import com.mapswithme.yopme.util.PixelBuffer;

public class MapRenderer implements MapDataProvider
{
	private final static String TAG = "MapRenderer";
	PixelBuffer mPixelBuffer = null;
	
	public MapRenderer(int width, int height)
	{
		mPixelBuffer = new PixelBuffer(width, height);
		mPixelBuffer.init();
		nativeCreateFramework(width, height);
	}
	
	public void terminate()
	{
		mPixelBuffer.terminate();
	}
	
	static volatile private MapRenderer mRenderer = null;
	
	static public MapRenderer GetRenderer()
	{
		if (mRenderer == null)
		{
			mRenderer = new MapRenderer(360, 640);
		}
		return mRenderer;
	}

	@Override
	public MapData getMyPositionData(double lat, double lon, double zoom)
	{
	  synchronized(MapRenderer.class)
	  {
  		mPixelBuffer.attachToThread();
  		if (nativeRenderMap(lat, lon, zoom, false, false, 0.0, 0.0) == false)
  		  return new MapData(null, new MWMPoint(lat, lon, ""));
  		
  		Bitmap bmp = mPixelBuffer.readBitmap();
  		mPixelBuffer.detachFromThread();
  		return new MapData(bmp, new MWMPoint(lat, lon, ""));
  	}
	}

	@Override
	public MapData getPOIData(MWMPoint poi, double zoom, boolean myLocationDetected ,double myLat, double myLon)
	{
	  synchronized(MapRenderer.class)
    {
  		mPixelBuffer.attachToThread();
  		if (nativeRenderMap(poi.getLat(), poi.getLon(), zoom, true, myLocationDetected, myLat, myLon) == false)
  		  return new MapData(null, poi);
  		
  		Bitmap bmp = mPixelBuffer.readBitmap();
  		mPixelBuffer.detachFromThread();
  		return new MapData(bmp, poi);
    }
	}
	
	private native void nativeCreateFramework(int width, int height);
	private native boolean nativeRenderMap(double lat, double lon, double zoom,
	                                       boolean needApiMark, boolean needMyLocation,
	                                       double myLat, double myLon);
}

@@ -833,24 +833,79 @@
 class)%0A%09  %7B%0A
+%09    final MWMPoint poi = new MWMPoint(lat, lon, %22%22);%0A%0A
   %09%09mPixelBu
@@ -978,23 +978,22 @@
 se, 
-false, 0.0, 0.0
+true, lat, lon
 ) ==
@@ -1035,41 +1035,14 @@
 ll, 
-new MWMPoint(lat, lon, %22%22));%0A  %09%09
+poi);%0A
 %0A  %09
@@ -1151,34 +1151,11 @@
 mp, 
-new MWMPoint(lat, lon, %22%22)
+poi
 );%0A 
@@ -1257,10 +1257,10 @@
 cted
- 
 ,
+ 
 doub
@@ -1507,20 +1507,16 @@
 , poi);%0A
-  %09%09
 %0A  %09%09Bit

Fix bug with location bitmap request.