package com.mapzen.tangram.android;

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;

import android.view.View;
import android.view.MotionEvent;

import com.mapzen.tangram.MapController;
import com.mapzen.tangram.MapView;

import java.io.File;

public class MainActivity extends Activity {

    MapController mapController;
    MapView mapView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);

        setContentView(R.layout.main);

        mapView = (MapView)findViewById(R.id.map);
        mapController = new MapController(this, mapView);
        mapController.setMapZoom(16);
        mapController.setMapPosition(-74.00976419448854, 40.70532700869127);

        mapController.setTapGestureListener(new View.OnGenericMotionListener() {
            @Override
            public boolean onGenericMotion(View v, MotionEvent event) {
                double[] mapPos = mapController.getMapPosition();
                double[] tapCoord = mapController.coordinatesAtScreenPosition(event.getX(), event.getY());
                double[] viewCenter = mapController.coordinatesAtScreenPosition(mapView.getWidth() * 0.5, mapView.getHeight() * 0.5);

                mapController.setMapPosition( mapPos[0] + (tapCoord[0] - viewCenter[0]), mapPos[1] + (tapCoord[1] - viewCenter[1]));

                return true;
            }
        });

        try {
            File cacheDir = new File(getExternalCacheDir().getAbsolutePath() + "/tile_cache");
            mapController.setTileCache(cacheDir, 30 * 1024 * 1024);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}


@@ -987,74 +987,8 @@
 ) %7B%0A
-                double%5B%5D mapPos = mapController.getMapPosition();%0A
     
@@ -1110,261 +1110,64 @@
     
-double%5B%5D viewCenter = mapController.coordinatesAtScreenPosition(mapView.getWidth() * 0.5, mapView.getHeight() * 0.5);%0A%0A                mapController.setMapPosition( mapPos%5B0%5D + (tapCoord%5B0%5D - viewCenter%5B0%5D), mapPos%5B1%5D + (tapCoord%5B1%5D - viewCenter%5B1%5D)
+mapController.setMapPosition(tapCoord%5B0%5D, tapCoord%5B1%5D
 );%0A
-%0A
     

Simplify tap callback in Android demo