package com.qiyou.mb.android.ui;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.RemoteException;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import com.iflytek.speech.ErrorCode;
import com.iflytek.speech.ISpeechModule;
import com.iflytek.speech.InitListener;
import com.iflytek.speech.SpeechConstant;
import com.iflytek.speech.SpeechSynthesizer;
import com.iflytek.speech.SpeechUtility;
import com.iflytek.speech.SynthesizerListener;
import com.qiyou.mb.android.Activity_qiyouBase;
import com.qiyou.mb.android.QiYouApplication;
import com.qiyou.mb.android.QiYouConstant;
import com.qiyou.mb.android.R;
import com.qiyou.mb.android.upgrade.UpdateManager;
import com.qiyou.mb.android.utils.log.QLog;

public class Website extends Activity_qiyouBase {
	public static final String TAG ="com.qiyou.Website";
	public static final String dTAG ="com.qiyou";
	
	private WebView webView;
//	TextView textView;  
     ProgressBar progressBar; 
	@Override
	protected void onCreate(Bundle savedInstanceState) { 
//		updateActionBar(false);
		super.onCreate(savedInstanceState); 
		app = (QiYouApplication) getApplication();
		setContentView(R.layout.web_site);
		 initialWebview();
		
	}
	 
	@SuppressLint("SetJavaScriptEnabled")
	void initialWebview(){
		webView = (WebView) findViewById(R.id.webview);
		 progressBar = (ProgressBar) findViewById(R.id.webprogress);
		webView.loadUrl( QiYouConstant.BASE_URL+"list");
//		webView.loadUrl( "WWW.BAIDU.COM");
		WebSettings setting = webView.getSettings();
		setting.setJavaScriptEnabled(true);//支持js 
		setting.setDefaultTextEncodingName("GBK");//设置字符编码
		webView.setScrollBarStyle(0);//滚动条风格，为0指滚动条不占用空间，直接覆盖在网页上
		
		
/*		 webView.setWebChromeClient(new WebChromeClient(){
			
			 @Override
		        public boolean shouldOverrideUrlLoading(WebView view, String url) {

		         view.loadUrl(url);   //在当前的webview中跳转到新的url

		         return true;
		        }
		}); */

		webView.setWebViewClient(new WebViewClient(){
			
			 @Override  
             public void onPageFinished(WebView view, String url) {  
                     // TODO Auto-generated method stub  
                     super.onPageFinished(view, url);  
                     //页面下载完毕,却不代表页面渲染完毕显示出来  
                     //WebChromeClient中progress==100时也是一样  
                     if (webView.getContentHeight() != 0) {  
                             //这个时候网页才显示  
                     }  
             }  
			 
	        @Override
	        public boolean shouldOverrideUrlLoading(WebView view, String url) {

//	         view.loadUrl(url);   //在当前的webview中跳转到新的url
	        	if(Uri.parse(url).getHost().equals("www.i7lv.com"))
	            {
	                // This is my web site, so do not override; let my WebView load
	                // the page
	                return false;
	            }
	            // Otherwise, the link is not for a page on my site, so launch
	            // another Activity that handles URLs
	            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
	            startActivity(intent);
	            return true;

	         
	        }
	       });
		
			 	webView.setWebChromeClient(new WebChromeClient(){  
		            @Override  
		            public void onProgressChanged(WebView view, int newProgress) {  
		                    // TODO Auto-generated method stub  
		                    super.onProgressChanged(view, newProgress);  
		                    //这里将textView换成你的progress来设置进度  
		                     if (newProgress == 0) {  
		//                                    textView.setVisibility(View.VISIBLE);  
		                                     progressBar.setVisibility(View.VISIBLE);  
		                             }  
//		                    textView.setText(newProgress+"");  
//		                    textView.postInvalidate();  
		                    progressBar.setProgress(newProgress);  
		                    progressBar.postInvalidate();  
		                     if (newProgress == 100) {  
		//                                    textView.setVisibility(View.GONE);  
		                                     progressBar.setVisibility(View.GONE);  
		                             }  
		            }  
		    });  
	}
	
	
	 
	 
}
