// Path: MarsImages/MarsImages/src/main/java/gov/nasa/jpl/hi/marsimages/JsonReader.java
// public class JsonReader {
//     public static JSONObject readJsonFromUrl(String url) throws IOException, JSONException {
//         InputStream is = new URL(url).openStream();
//         //noinspection TryFinallyCanBeTryWithResources
//         try {
//             BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
//             String jsonText = readAll(rd);
//             return new JSONObject(jsonText);
//         } finally {
//             is.close();
//         }
//     }
// 
//     private static String readAll(Reader rd) throws IOException {
//         StringBuilder sb = new StringBuilder();
//         int cp;
//         while ((cp = rd.read()) != -1) {
//             sb.append((char) cp);
//         }
//         return sb.toString();
//     }
// }
// 
// Path: MarsImages/MarsImages/src/main/java/gov/nasa/jpl/hi/marsimages/MarsImagesApp.java
// public static MarsImagesApp MARS_IMAGES;


import android.graphics.PointF;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.FrameLayout;
import com.mapbox.mapboxsdk.geometry.BoundingBox;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.overlay.Marker;
import com.mapbox.mapboxsdk.views.MapView;
import com.powellware.marsimages.R;
import org.apache.commons.csv.CSVRecord;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import gov.nasa.jpl.hi.marsimages.JsonReader;
import static gov.nasa.jpl.hi.marsimages.MarsImagesApp.MARS_IMAGES;
    private int maxZoom;
    private int maxNativeZoom;
    private int defaultZoom;
    private double centerLat;
    private double centerLon;
    private double upperLeftLat;
    private double upperLeftLon;
    private double upperRightLat;
    private double upperRightLon;
    private double lowerLeftLat;
    private double lowerLeftLon;
    private int mapPixelWidth;
    private int mapPixelHeight;

    private int latestSiteIndex;
    private MapView mapView;
    private ArrayList<LatLng> points;
    private HashMap<Integer, int[]> rmcsForPoints;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_map);
        final FrameLayout frameLayout = (FrameLayout) findViewById(R.id.mapContainer);
        String missionName = MARS_IMAGES.getMissionName();
        new AsyncTask<String, Void, Void>() {
            @Override
            protected Void doInBackground(String... params) {
                String missionName = params[0];
                try {
                    String url = "http://merpublic.s3.amazonaws.com/maps/" + missionName + "Map.json";
// Path: MarsImages/MarsImages/src/main/java/gov/nasa/jpl/hi/marsimages/JsonReader.java
// public class JsonReader {
//     public static JSONObject readJsonFromUrl(String url) throws IOException, JSONException {
//         InputStream is = new URL(url).openStream();
//         //noinspection TryFinallyCanBeTryWithResources
//         try {
//             BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
//             String jsonText = readAll(rd);
//             return new JSONObject(jsonText);
//         } finally {
//             is.close();
//         }
//     }
// 
//     private static String readAll(Reader rd) throws IOException {
//         StringBuilder sb = new StringBuilder();
//         int cp;
//         while ((cp = rd.read()) != -1) {
//             sb.append((char) cp);
//         }
//         return sb.toString();
//     }
// }
// 
// Path: MarsImages/MarsImages/src/main/java/gov/nasa/jpl/hi/marsimages/MarsImagesApp.java
// public static MarsImagesApp MARS_IMAGES;


// Path: MarsImages/MarsImages/src/main/java/gov/nasa/jpl/hi/marsimages/ui/MapActivity.java
import android.graphics.PointF;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.FrameLayout;
import com.mapbox.mapboxsdk.geometry.BoundingBox;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.overlay.Marker;
import com.mapbox.mapboxsdk.views.MapView;
import com.powellware.marsimages.R;
import org.apache.commons.csv.CSVRecord;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import gov.nasa.jpl.hi.marsimages.JsonReader;
import static gov.nasa.jpl.hi.marsimages.MarsImagesApp.MARS_IMAGES;

    private int maxZoom;
    private int maxNativeZoom;
    private int defaultZoom;
    private double centerLat;
    private double centerLon;
    private double upperLeftLat;
    private double upperLeftLon;
    private double upperRightLat;
    private double upperRightLon;
    private double lowerLeftLat;
    private double lowerLeftLon;
    private int mapPixelWidth;
    private int mapPixelHeight;

    private int latestSiteIndex;
    private MapView mapView;
    private ArrayList<LatLng> points;
    private HashMap<Integer, int[]> rmcsForPoints;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_map);
        final FrameLayout frameLayout = (FrameLayout) findViewById(R.id.mapContainer);
        String missionName = MARS_IMAGES.getMissionName();
        new AsyncTask<String, Void, Void>() {
            @Override
            protected Void doInBackground(String... params) {
                String missionName = params[0];
                try {
                    String url = "http://merpublic.s3.amazonaws.com/maps/" + missionName + "Map.json";
                    JSONObject jsonObject = JsonReader.readJsonFromUrl(url);