package com.wasu.cs.ui;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import cn.com.wasu.main.IntentConstant;
import com.wasu.comp.wasuwebview.WasuWebView;
import com.wasu.comp.wasuwebview.tv;
import com.wasu.compfactory.WasuCompFactory;
import com.wasu.cs.jsobject.WR;
import com.wasu.cs.jsobject.WR_Favorites;
import com.wasu.cs.jsobject.WR_History;
import com.wasu.cs.jsobject.WR_Term;
import com.wasu.cs.jsobject.WR_UserCenter;
import com.wasu.module.log.WLog;

public class ActivityWeb extends ActivityBase {

	private String TAG = "ActivityWeb";

	@SuppressLint("NewApi") @Override
	protected void doCreate(Bundle savedInstanceState) {
		WLog.i(TAG,"doCreate()");

		//create wasu webview
		WasuWebView webView = new WasuCompFactory().createWasuWebView(this);
		setContentView(webView);
		
		//parse intent
		Intent i = getIntent();
		if (i == null){
			postMessage("数据加载失败，请稍后重试！");
			finish();
		}
		
		String jsonUrl = i.getStringExtra(IntentConstant.DATAURI.value());
		if (TextUtils.isEmpty(jsonUrl)){
			postMessage("数据加载失败，请稍后重试！");
			finish();
		}
		
//		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){
//			WebView.setWebContentsDebuggingEnabled(true);
//		}
		
		webView.addJavascriptInterface(new WR(this, webView), "WR");
		webView.addJavascriptInterface(new WR_Term(this), "WR_Term");
		webView.addJavascriptInterface(new WR_History(this), "WR_History");
		webView.addJavascriptInterface(new WR_Favorites(this), "WR_Favorites");
		webView.addJavascriptInterface(new tv(this), "tv");
		webView.addJavascriptInterface(new WR_UserCenter(this), "WR_UserCenter");
		
		webView.loadUrl(jsonUrl);
	}

}
