package edu.yalestc.yalepublic;

import android.app.ActionBar;
import android.app.Activity;
import android.app.SearchManager;
import android.content.Context;
import android.os.Bundle;
import android.view.Menu;
import android.widget.SearchView;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

/**
 * Created by Jason Liu on 10/18/14.
 */
public class MapView extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActionBar actionbar = getActionBar();
        actionbar.setDisplayHomeAsUpEnabled(true);     // Show home as a back arrow
        //actionbar.setDisplayShowHomeEnabled(true);     // Show application logo
        actionbar.setDisplayShowTitleEnabled(true);    // Show activity title/subtitle
        actionbar.setDisplayUseLogoEnabled(false);     // Use activity logo instead of activity icon
        actionbar.setTitle(getString(R.string.maps));  // Set title

        setContentView(R.layout.map_simple);

        // Get a handle to the Map Fragment
        GoogleMap map = ((MapFragment) getFragmentManager()
                .findFragmentById(R.id.map)).getMap();

        LatLng yale = new LatLng(41.3111, -72.9267);   // The - signifies the Western Hemisphere

        map.setMyLocationEnabled(true);
        map.moveCamera(CameraUpdateFactory.newLatLngZoom(yale, 13));

        map.addMarker(new MarkerOptions()
                .title("Yale")
                .snippet("The best university ever.")
                .position(yale));
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.map_menu, menu);

        // Associate searchable configuration with the SearchView
        SearchManager searchManager =
                (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        SearchView searchView =
                (SearchView) menu.findItem(R.id.search).getActionView();
        searchView.setSearchableInfo(
                searchManager.getSearchableInfo(getComponentName()));

        return super.onCreateOptionsMenu(menu);
    }
}

@@ -151,16 +151,54 @@
 ontext;%0A
+import android.database.MatrixCursor;%0A
 import a
@@ -215,16 +215,16 @@
 Bundle;%0A
-
 import a
@@ -532,16 +532,65 @@
 tions;%0A%0A
+import java.util.Arrays;%0Aimport java.util.List;%0A%0A
 /**%0A * C
@@ -667,16 +667,40 @@
 vity %7B%0A%0A
+    private Menu menu;%0A%0A
     @Ove
@@ -2061,16 +2061,42 @@
 , menu);
+%0A        this.menu = menu;
 %0A%0A      
@@ -2493,45 +2493,1269 @@
     
-return super.onCreateOptionsMenu(menu
+searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() %7B%0A%0A            @Override%0A            public boolean onQueryTextSubmit(String query) %7B%0A                return false;%0A            %7D%0A%0A            @Override%0A            public boolean onQueryTextChange(String query) %7B%0A                loadHistory(query);%0A                return true;%0A            %7D%0A%0A        %7D);%0A        return super.onCreateOptionsMenu(menu);%0A    %7D%0A%0A    private void loadHistory(String query) %7B%0A        // Cursor%0A        String%5B%5D columns = new String%5B%5D %7B %22_id%22, %22text%22 %7D;%0A        Object%5B%5D temp = new Object%5B%5D %7B 0, %22default%22 %7D;%0A        List%3CString%3E items = Arrays.asList(%22sup1%22, %22sup2%22, %22sup3%22);%0A%0A        MatrixCursor cursor = new MatrixCursor(columns);%0A%0A        for(int i = 0; i %3C items.size(); i++) %7B%0A            temp%5B0%5D = i;%0A            temp%5B1%5D = items.get(i);%0A            cursor.addRow(temp);%0A        %7D%0A%0A        // SearchView%0A        SearchManager manager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);%0A%0A        //final SearchView search = (SearchView) menu.findItem(R.id.search).getActionView();%0A        SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();%0A%0A        searchView.setSuggestionsAdapter(new MapAdapter(this, cursor, items)
 );%0A 

Add History loading function