package com.mapzen.android.sdk.sample;

import com.mapzen.android.graphics.FeaturePickListener;
import com.mapzen.android.graphics.MapFragment;
import com.mapzen.android.graphics.MapzenMap;
import com.mapzen.android.graphics.OnMapReadyCallback;
import com.mapzen.tangram.LngLat;

import android.os.Bundle;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Demonstrates how to use the {@link FeaturePickListener}.
 */
public class FeaturePickListenerActivity extends BaseDemoActivity {

  private static final String PROP_SEARCH_INDEX = "searchIndex";
  private static final String PROP_STATE = "state";
  private static final String PROP_NAME = "name";

  MapzenMap map;

  FeaturePickListener listener = new FeaturePickListener() {
    @Override
    public void onFeaturePick(Map<String, String> properties, float positionX, float positionY) {
      String title;
      if (properties.containsKey(PROP_SEARCH_INDEX)) {
        title =
            getString(R.string.feature) + " " + properties.get(PROP_SEARCH_INDEX) + " " + properties
                .get(PROP_STATE);
      } else {
        title = properties.get(PROP_NAME);
      }
      if (title != null && !title.isEmpty()) {
        Toast.makeText(FeaturePickListenerActivity.this, title, Toast.LENGTH_SHORT).show();
      }
    }
  };

  @Override protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sample_mapzen);

    final MapFragment mapFragment =
        (MapFragment) getSupportFragmentManager().findFragmentById(R.id.fragment);
    mapFragment.getMapAsync(new OnMapReadyCallback() {
      @Override public void onMapReady(MapzenMap map) {
        FeaturePickListenerActivity.this.map = map;
        map.setZoom(15f);
        map.setPosition(new LngLat(-122.394046, 37.789747));
        map.setFeaturePickListener(listener);
        showSearchResults();
      }
    });
  }

  private void showSearchResults() {
    LngLat result3 = new LngLat(-122.392799, 37.782511);
    LngLat result4 = new LngLat(-122.397477, 37.788243);
    LngLat result5 = new LngLat(-122.393528, 37.789227);
    List<LngLat> results = new ArrayList();
    results.add(result3);
    results.add(result4);
    results.add(result5);
    map.drawSearchResults(results, 1);
  }

}

@@ -238,16 +238,66 @@
 llback;%0A
+import com.mapzen.android.graphics.model.Polygon;%0A
 import c
@@ -383,59 +383,8 @@
 t;%0A%0A
-import java.util.ArrayList;%0Aimport java.util.List;%0A
 impo
@@ -543,176 +543,8 @@
  %7B%0A%0A
-  private static final String PROP_SEARCH_INDEX = %22searchIndex%22;%0A  private static final String PROP_STATE = %22state%22;%0A  private static final String PROP_NAME = %22name%22;%0A%0A
   Ma
@@ -740,284 +740,66 @@
     
-String title;%0A      if (properties.containsKey(PROP_SEARCH_INDEX)) %7B%0A        title =%0A            getString(R.string.feature) + %22 %22 + properties.get(PROP_SEARCH_INDEX) + %22 %22 + properties%0A                .get(PROP_STATE);%0A      %7D else %7B%0A        title = properties.get(PROP_NAME)
+if (positionX == 0.0 && positionY == 0.0) %7B%0A        return
 ;%0A  
@@ -814,51 +814,34 @@
     
-if (
+String 
 title 
-!
 = 
-null && !title.isEmpty()) %7B%0A  
+%22Polygon%22;%0A
     
@@ -922,32 +922,24 @@
 RT).show();%0A
-      %7D%0A
     %7D%0A  %7D;%0A%0A
@@ -1616,17 +1616,17 @@
 t result
-3
+1
  = new L
@@ -1673,17 +1673,17 @@
 t result
-4
+2
  = new L
@@ -1730,17 +1730,17 @@
 t result
-5
+3
  = new L
@@ -1778,59 +1778,56 @@
     
-List%3CLngLat%3E results = new ArrayList
+Polygon polygon = new Polygon.Builder
 ()
-;
 %0A    
-results
+    
 .add
@@ -1837,23 +1837,19 @@
 sult
-3);
+1)
 %0A    
-results
+    
 .add
@@ -1859,74 +1859,99 @@
 sult
-4);%0A    results.add(result5);%0A    map.drawSearchResults(results, 1
+2)%0A        .add(result3)%0A        .add(result1)%0A        .build();%0A    map.addPolygon(polygon
 );%0A 

Update feature pick listener example with polygon (#400)