• android WebView onJsAler onJsC…


    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 {
       

        privateHandler mHandler = new Handler();
        privateWebView mWebView;
        privateNcpRegisterDAO dao = null;
        
        public voidonCreate(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 = newBuilder(Register_protocolActivity.this);
                                 builder.setTitle("计算1+2的值");
                                 builder.setMessage(message);
                                 builder.setPositiveButton(android.R.string.ok, newAlertDialog.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, Stringmessage, final JsResult result) {
                          Builder builder = newBuilder(Register_protocolActivity.this);
                          builder.setTitle("退出确认");
                          builder.setMessage(message);
                          builder.setPositiveButton(android.R.string.ok, newAlertDialog.OnClickListener() {
                              public void onClick(DialogInterface dialog, int which) {
                                  //result.confirm();
                               //从协义开始到发送注册信息,这些步骤退出后直接清零复位表,不然如果非正常关机后再重启会再次进入该页
                               dao.Clear_NcpStep_Set0();
                                 finish();
                                  
                              }
            
                          });
                          builder.setNeutralButton(android.R.string.cancel, newAlertDialog.OnClickListener() {
            
                           public void onClick(DialogInterface dialog, int which) {
                                  result.cancel();
                              }
            
                          });
                          builder.setCancelable(false);
                          builder.create();
                          builder.show();
                          return true;
                      }
               
            };
          //设置setWebChromeClient对象
            mWebView.setWebChromeClient(wvcc);
          
          
          
        }
        
        final classAction {  
           
          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 = newIntent(MainActivity.this,Register.class);
                       Intent intent = newIntent(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 voidonBackPressed() {
                  // TODO Auto-generated method stub
                  return;
                  //super.onBackPressed();
        }
        
       @Override
        protectedvoid onStop() {
           super.onStop();
           System.out.println("onStop!!");
           finish();
           // The activity is no longer visible (it is now "stopped")
        }

    }
  • 相关阅读:
    字符串中包含最多的字符
    循环左移操作 (左旋转字符串)
    翻转字符串
    和为s的连续正数序列
    Unity之使用技巧记录
    Unity资源
    各种IDE的使用
    Unity3d之MonoBehavior自带方法的执行顺序
    c#之new关键词——隐藏基类方法
    算法——各种类型对象通用的二分法插入排序
  • 原文地址:https://www.cnblogs.com/xiaowangba/p/6314321.html
Copyright © 2020-2023  润新知