package com.html;
import com.sqlite.Dao.NcpRegisterDAO;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.webkit.JsResult;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.Toast;
public class Register_protocolActivity extends Activity {
private Handler mHandler = new Handler();
private WebView mWebView;
private NcpRegisterDAO dao = null;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//踩上一脚,记录有了就知道复位的时候要去哪里
dao = new NcpRegisterDAO(Register_protocolActivity.this);
String name = "MainActivity";
dao.add_Stepped(name);
//隐藏标题栏
//requestWindowFeature(Window.FEATURE_NO_TITLE);
//隐藏状态栏
//getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
//该ACTIVITY不需要layout设置,所以直接指向MainActivity的main
setContentView(R.layout.protocol);
//将WebView实例化
mWebView = (WebView) this.findViewById(R.id.webView);
//WebView打开权限
mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
mWebView.getSettings().setJavaScriptEnabled(true);
//WebView,SWF文件运行权限
mWebView.getSettings().setPluginsEnabled(true);
mWebView.addJavascriptInterface(new Action(), "ncp");
mWebView.loadUrl("file:///android_asset/protocol.html");
// 创建WebViewChromeClient
WebChromeClient wvcc = new WebChromeClient() {
// 处理Alert事件
public boolean onJsAlert(WebView view, String url, String message, final JsResult result) {
// 构建一个Builder来显示网页中的alert对话框
Builder builder = new Builder(Register_protocolActivity.this);
builder.setTitle("计算1+2的值");
builder.setMessage(message);
builder.setPositiveButton(android.R.string.ok, new AlertDialog.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
result.confirm();
}
});
builder.setCancelable(false);
builder.create();
builder.show();
return true;
}
// 处理Confirm事件
public boolean onJsConfirm(WebView view, String url, String message, final JsResult result) {
Builder builder = new Builder(Register_protocolActivity.this);
builder.setTitle("退出确认");
builder.setMessage(message);
builder.setPositiveButton(android.R.string.ok, new AlertDialog.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//result.confirm();
// 从协义开始到发送注册信息,这些步骤退出后直接清零复位表,不然如果非正常关机后再重启会再次进入该页
dao.Clear_NcpStep_Set0();
finish();
}
});
builder.setNeutralButton(android.R.string.cancel, new AlertDialog.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
result.cancel();
}
});
builder.setCancelable(false);
builder.create();
builder.show();
return true;
}
};
// 设置setWebChromeClient对象
mWebView.setWebChromeClient(wvcc);
}
final class Action {
Action() {
}
public void clickOnAndroid_register() {
mHandler.post(new Runnable() {
public void run() {
// mWebView.loadUrl("javascript:wave()");
Toast.makeText(getBaseContext(), "欢迎进入注册!", Toast.LENGTH_SHORT).show();
//Intent intent = new Intent(MainActivity.this,Register.class);
Intent intent = new Intent(Register_protocolActivity.this,Register_IDcard.class);
Register_protocolActivity.this.startActivity(intent);
//设置切换动画,从右边进入,左边退出
overridePendingTransition(R.xml.in_from_right, R.xml.out_to_left);
}
});
}
public void clickOnAndroid_quit() {
mHandler.post(new Runnable() {
public void run() {
finish();
}
});
}
}
//禁止回退
public void onBackPressed() {
// TODO Auto-generated method stub
return;
//super.onBackPressed();
}
@Override
protected void onStop() {
super.onStop();
System.out.println("onStop!!");
finish();
// The activity is no longer visible (it is now "stopped")
}
}