package com.example.waoperations;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Field;
import java.text.Normalizer;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;



import com.example.waoperations.adapter.NavDrawerListAdapter;
import com.example.waoperations.model.NavDrawerItem;
import com.example.waoperations.Inventory.InventorySummary;
import com.example.waoperations.CycleCount.CycleCountSummary;
import com.example.waoperations.Picking.PickingSummary;
import com.example.waoperations.PutAway.PutAwaySummary;
import com.example.waoperations.Receiving.ReceivingSummary;
import com.example.waoperations.Shipping.ShippingSummary;
import com.example.waoperations.R;


import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.database.Cursor;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.StrictMode;
import android.app.ActionBar;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Fragment;
import android.app.FragmentManager;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivityWA extends Activity {

	
	  private DrawerLayout mDrawerLayout;
	    private ListView mDrawerList;
	    private ActionBarDrawerToggle mDrawerToggle;
	  
	    // nav drawer title
	    private CharSequence mDrawerTitle;
	  
	    // used to store app title
	    private CharSequence mTitle;
	  
	    // slide menu items
	    private String[] navMenuTitles;
	    private TypedArray navMenuIcons;
	  
	    private ArrayList<NavDrawerItem> navDrawerItems;
	    private NavDrawerListAdapter adapter;
	  private Button Picking;
	  private Button Receiving;
	  private Button Putaway;
	  private Button Shipping;
	  private Button Inventory;
	  private Button CycleCount,Replenishment;
		private Button Aduanas;
		private Button Transferencias;
	@Override
	 protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		FontsOverride.setDefaultFont(this, "MONOSPACE", "fonts/opensans-light.ttf");
		setContentView(R.layout.wamenu);
	    ActionBar actionBar = getActionBar();
	    actionBar.hide();
	    // more stuff here...
	    
	    actionBar.setSubtitle("Assistant");
	    actionBar.setTitle("Warehouse");
	    actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.ForestGreen)));
	    actionBar.setDisplayShowTitleEnabled(false);  // required to force redraw, without, gray color
	    actionBar.setDisplayShowTitleEnabled(true);
	    actionBar.setDisplayHomeAsUpEnabled(false);
	    actionBar.show(); 
	    
	    mTitle = mDrawerTitle = getTitle();

		// load slide menu items
		navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items);

		// nav drawer icons from resources
		navMenuIcons = getResources()
				.obtainTypedArray(R.array.nav_drawer_icons);

		mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
		mDrawerList = (ListView) findViewById(R.id.list_slidermenu);

		navDrawerItems = new ArrayList<NavDrawerItem>();

		// adding nav drawer items to array
		// Home
        // navDrawerItems.add(new NavDrawerItem(navMenuTitles[0], navMenuIcons.getResourceId(0, -1)));
		// Find People
	    //navDrawerItems.add(new NavDrawerItem(navMenuTitles[1], navMenuIcons.getResourceId(1, -1)));
		// Photos
	    //navDrawerItems.add(new NavDrawerItem(navMenuTitles[2], navMenuIcons.getResourceId(2, -1)));
		// Communities, Will add a counter here
  
		
		// Recycle the typed array
		navMenuIcons.recycle();

		mDrawerList.setOnItemClickListener(new SlideMenuClickListener());

		// setting the nav drawer list adapter
		adapter = new NavDrawerListAdapter(getApplicationContext(),
				navDrawerItems);
		mDrawerList.setAdapter(adapter);

		// enabling action bar app icon and behaving it as toggle button
		getActionBar().setDisplayHomeAsUpEnabled(true);
		getActionBar().setHomeButtonEnabled(true);

		mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
				R.drawable.ic_drawer, //nav menu toggle icon
				R.string.app_name, // nav drawer open - description for accessibility
				R.string.app_name // nav drawer close - description for accessibility
		) {
			public void onDrawerClosed(View view) {
				//getActionBar().setTitle(mTitle);
				// calling onPrepareOptionsMenu() to show action bar icons
				invalidateOptionsMenu();
			}

			public void onDrawerOpened(View drawerView) {
				//getActionBar().setTitle(mDrawerTitle);
				// calling onPrepareOptionsMenu() to hide action bar icons
				invalidateOptionsMenu();
			}
		};
		mDrawerLayout.setDrawerListener(mDrawerToggle);

		if (savedInstanceState == null) {
			// on first time display view for first nav item
			displayView(0);
		}
	    
		Picking =    (Button)findViewById(R.id.pick);
		Receiving =  (Button)findViewById(R.id.receive);
		Putaway =    (Button)findViewById(R.id.put);
		Shipping =   (Button)findViewById(R.id.ship);
		Inventory = (Button)findViewById(R.id.inventory);
		CycleCount = (Button)findViewById(R.id.cyclecount);
		Replenishment = (Button)findViewById(R.id.replenishment);
		Aduanas = (Button)findViewById(R.id.aduanas);
 		Transferencias = (Button)findViewById(R.id.transference);
		
	}


	 public void onPicking(View view) {  
		    Intent intento = new Intent(getApplicationContext(), OrderLoad.class);
		    intento.putExtra("tipo","0");
		    startActivity(intento);	  
			}	
	 
	 public void onReceiving(View view) {  
		    Intent intento = new Intent(getApplicationContext(), OrderLoad.class);
		    intento.putExtra("tipo","1");
		    startActivity(intento);	  
			}	
	 
	 public void onPutaway(View view) {  
		    Intent intento = new Intent(getApplicationContext(), OrderLoad.class);
		    intento.putExtra("tipo","2");
		    startActivity(intento);	  
			}	
	 public void onShipping(View view) {
		 Intent intento = new Intent(getApplicationContext(), OrderLoadTransfer.class);
		 intento.putExtra("tipo","10");
		 startActivity(intento);

			}	
	 public void onInventory(View view) {  
		    Intent intento = new Intent(getApplicationContext(), OrderLoad.class);
		    intento.putExtra("tipo","4");
		    startActivity(intento);	  
			}
	 public void onCycleCount(View view) {  
   		
    		 new AlertDialog.Builder(this)
  	        .setIcon(android.R.drawable.ic_dialog_alert)
  	        .setTitle("Módulo de Conteo Cíclico")
  	        .setMessage("Seleccione el tipo de inventario a realizar:")
  	        .setPositiveButton("Cíclico", new DialogInterface.OnClickListener()
  	       {	
  	        @Override
  	        public void onClick(DialogInterface dialog, int which) {
  	        	  Intent intento = new Intent(getApplicationContext(), OrderLoad.class);
  	 		    intento.putExtra("tipo","9");
  	 		    startActivity(intento);	  
  	        	
  	        }

  	    })
  	    .setNegativeButton("Posición",new DialogInterface.OnClickListener()
  	       {	
  	        @Override
  	        public void onClick(DialogInterface dialog, int which) {
  	        	Intent intento = new Intent(getApplicationContext(), OrderLoad.class);
 				    intento.putExtra("tipo","5");
 				    startActivity(intento);	 

  	        }

  	    })
  	    .show();
    	
		   
			}
	 public void onReplenishment(View view) {  
		    Intent intento = new Intent(getApplicationContext(), OrderLoad.class);
		    intento.putExtra("tipo","6");
		    startActivity(intento);	  
			}
	 public void onStats(View view) {  
		    Intent intento = new Intent(getApplicationContext(), OrderLoad.class);
		    intento.putExtra("tipo","7");
		    startActivity(intento);	  
			}
	 public void onAduanas(View view) {  
		    Intent intento = new Intent(getApplicationContext(), OrderLoadTransfer.class);
		    intento.putExtra("tipo","8");
		    startActivity(intento);	  
			}
	 public void onTransference(View view) {  
		   // Intent intento = new Intent(getApplicationContext(), OrderLoadTransfer.class);
		    //intento.putExtra("tipo","9");
		    //startActivity(intento);	  

    		 new AlertDialog.Builder(this)
 	        .setIcon(android.R.drawable.ic_dialog_alert)
 	        .setTitle("Módulo de Transferencias")
 	        .setMessage("Seleccione bodega de Transferencia para continuar:")
 	        .setPositiveButton("Bodega AC", new DialogInterface.OnClickListener()
 	       {	
 	        @Override
 	        public void onClick(DialogInterface dialog, int which) {
 	        	  Intent intento = new Intent(getApplicationContext(), OrderLoadTransfer.class);
 	 		    intento.putExtra("tipo","9");
 	 		    startActivity(intento);	  
 	        }

 	    })
 	    .setNegativeButton("Bodega Zurquí",new DialogInterface.OnClickListener()
 	       {	
 	        @Override
 	        public void onClick(DialogInterface dialog, int which) {
 	        	Intent intento = new Intent(getApplicationContext(), OrderLoadTransfer.class);
				    intento.putExtra("tipo","12");
				    startActivity(intento);	 
 	        }

 	    })
 	    .show();
		    
		    
		    
		    
		    
			}
	 
	 private class SlideMenuClickListener implements
	 ListView.OnItemClickListener {
	 @Override
	 public void onItemClick(AdapterView<?> parent, View view, int position,
	 	long id) {
	 // display view for selected nav drawer item
	 displayView(position);
	 }
	 }
	 @SuppressWarnings("unused")
	private void displayView(int position) {
		
		}
	 
	     @Override   
	    public void setTitle(CharSequence title) {
	        mTitle = title;
	        getActionBar().setTitle(mTitle);
	    }
	     
	     
	    @Override
	    protected void onPostCreate(Bundle savedInstanceState) {
	        super.onPostCreate(savedInstanceState);
	        // Sync the toggle state after onRestoreInstanceState has occurred.
	        mDrawerToggle.syncState();
	    }
	 
	    @Override
	    public void onConfigurationChanged(Configuration newConfig) {
	        super.onConfigurationChanged(newConfig);
	        // Pass any configuration change to the drawer toggls
	        mDrawerToggle.onConfigurationChanged(newConfig);
	    }
	     

}
