package com.manubet.android.touristAndroid;






import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;

import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
 
public class InfoWeb extends Activity {

   static String currentUrl="http://touristdroid.blogspot.com/";
   static WebView web;
   boolean back,forward;
   private static ProgressDialog progressBar;  
   private static Context context;

	@Override
	public void onCreate(Bundle savedInstanceState) 
	{
		 super.onCreate(savedInstanceState);
		 setContentView(R.layout.web);
	     web = (WebView) findViewById(R.id.webview);
    	context=this;

        web.getSettings().setSupportZoom(true);       
        web.getSettings().setBuiltInZoomControls(true);
        web.getSettings().setUseWideViewPort(true);

        web.invokeZoomPicker();
        web.setInitialScale(30);
        this.load();
               
        web.setWebViewClient(new WebViewClient()
       {    
        	public void onPageFinished(WebView view, String url) {
            if (progressBar.isShowing()) {
                progressBar.dismiss();
            } 
        }});
	}
	
static void load(){
	web.loadUrl(currentUrl);
	progressBar = ProgressDialog.show(context, "Cargando", "Espere, por favor...");
 }
 
 @Override
 public boolean onPrepareOptionsMenu (Menu menu){
	    back=web.canGoBack();
	    forward=web.canGoForward();
	    if(!back){
	    	menu.getItem(0).setIcon(R.drawable.icon_back_off);
	    }
	    else {
	    	menu.getItem(0).setIcon(R.drawable.icon_back);
	    }
	    if(!forward){
	    	menu.getItem(2).setIcon(R.drawable.icon_forward_off);
	    } 
	    else {
	    	menu.getItem(2).setIcon(R.drawable.icon_forward);
	    }
	return true;}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
	
	    MenuInflater inflater = getMenuInflater();
	    inflater.inflate(R.layout.menuweb, menu);
	    return(super.onCreateOptionsMenu(menu));
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
	    switch (item.getItemId()) {
	    case R.id.atras:
	    	if(back) web.goBack();
	    	else 	            Toast.makeText(getBaseContext(), 
                    getResources().getString(R.string.no_back), 
                    Toast.LENGTH_LONG).show();		
			return(true);
	    case R.id.actualizar:
	    	web.reload();
	        return true; 
	    case R.id.adelante:
	    	if(forward) web.goForward();
	    	else 	            Toast.makeText(getBaseContext(), 
                    getResources().getString(R.string.no_forward), 
                    Toast.LENGTH_LONG).show();		
	        return true; 

	    default:
	        return super.onOptionsItemSelected(item);
	    }
	}  
}
