/* Copyright 2014 ESRI
 *
 * All rights reserved under the copyright laws of the United States
 * and applicable international laws, treaties, and conventions.
 *
 * You may freely redistribute and use this sample code, with or
 * without modification, provided you include the original copyright
 * notice and use restrictions.
 *
 * See the Sample code usage restrictions document for further information.
 *
 */

package com.arcgis.android.samples.cloudportal.querycloudfeatureservice;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

import com.esri.android.map.GraphicsLayer;
import com.esri.android.map.MapView;
import com.esri.android.map.ags.ArcGISFeatureLayer;


public class MainActivity extends Activity {

    MapView mMapView;
    ArcGISFeatureLayer featureLayer;
    GraphicsLayer graphicsLayer;

    String featureServiceURL;

    // The query params switching menu items.
    MenuItem mQueryUsMenuItem = null;
    MenuItem mQueryCaMenuItem = null;
    MenuItem mQueryFrMenuItem = null;
    MenuItem mQueryAuMenuItem = null;
    MenuItem mQueryBrMenuItem = null;

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

        // Retrieve the map and initial extent from XML layout
        mMapView = (MapView) findViewById(R.id.map);
        // Get the feature service URL from values->strings.xml
        featureServiceURL = this.getResources().getString(R.string.featureServiceURL);
        // Add Feature layer to the MapView
        featureLayer = new ArcGISFeatureLayer(featureServiceURL, ArcGISFeatureLayer.MODE.ONDEMAND);
        mMapView.addLayer(featureLayer);
        // Add Graphics layer to the MapView
        graphicsLayer = new GraphicsLayer();
        mMapView.addLayer(graphicsLayer);

        // Set the Esri logo to be visible, and enable map to wrap around date line.
        mMapView.setEsriLogoVisible(true);
        mMapView.enableWrapAround(true);
    }


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

        // Get the query params menu items.
        mQueryUsMenuItem = menu.getItem(0);
        mQueryCaMenuItem = menu.getItem(1);
        mQueryFrMenuItem = menu.getItem(2);
        mQueryAuMenuItem = menu.getItem(3);
        mQueryBrMenuItem = menu.getItem(4);

        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle menu item selection.
        switch (item.getItemId()) {
            case R.id.Query_US:
                mQueryUsMenuItem.setChecked(true);
                return true;
            case R.id.Query_CA:
                mQueryCaMenuItem.setChecked(true);
                return true;
            case R.id.Query_FR:
                mQueryFrMenuItem.setChecked(true);
                return true;
            case R.id.Query_AU:
                mQueryAuMenuItem.setChecked(true);
                return true;
            case R.id.Query_BR:
                mQueryBrMenuItem.setChecked(true);
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }

    protected void onPause() {
        super.onPause();
        mMapView.pause();
    }

    protected void onResume() {
        super.onResume();
        mMapView.unpause();
    }
}

@@ -531,75 +531,214 @@
 oid.
-os.Bundle;%0Aimport android.view.Menu;%0Aimport android.view.MenuItem;%0A
+app.ProgressDialog;%0Aimport android.os.Bundle;%0Aimport android.view.LayoutInflater;%0Aimport android.view.Menu;%0Aimport android.view.MenuItem;%0Aimport android.view.ViewGroup;%0A%0Aimport com.esri.android.map.Callout;
 %0Aimp
@@ -1010,37 +1010,192 @@
 er;%0A
-%0A    String featureServiceURL
+    private Callout mCallout;%0A%0A    private int mCalloutStyle;%0A    private ViewGroup calloutContent;%0A    boolean mIsMapLoaded;%0A    String featureServiceURL;%0A%0A    ProgressDialog progress
 ;%0A%0A 
@@ -2344,24 +2344,485 @@
 ound(true);%0A
+%0A        // Get the MapView's callout from xml-%3Eidentify_calloutstyle.xml%0A        mCalloutStyle = R.xml.identify_calloutstyle;%0A        LayoutInflater inflater = getLayoutInflater();%0A        mCallout = mMapView.getCallout();%0A        // Get the layout for the Callout from%0A        // layout-%3Eidentify_callout_content.xml%0A        calloutContent = (ViewGroup) inflater.inflate(R.layout.identify_callout_content, null);%0A        mCallout.setContent(calloutContent);%0A%0A
     %7D%0A%0A%0A    

set the callout on the map