Example #1
0
 public void addView(final View view, AndroidLocation location) {
   if (view == null) {
     return;
   }
   addView(
       view,
       android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
       android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
       location);
 }
Example #2
0
 public void addView(final View view, int w, int h, AndroidLocation location) {
   if (view == null) {
     return;
   }
   android.widget.RelativeLayout viewLayout = new android.widget.RelativeLayout(this);
   android.widget.RelativeLayout.LayoutParams relativeParams =
       AndroidGame.createRelativeLayout(location, w, h);
   viewLayout.addView(view, relativeParams);
   addView(viewLayout);
 }
Example #3
0
    public Web(final Loon activity, final WebProcess webProcess, final String url) {

      super(activity);
      this.url = url;
      this.activity = activity;
      // 允许显示滚动条
      this.setHorizontalScrollBarEnabled(true);
      // 清空原有的缓存数据
      this.clearCache(true);
      // 隐藏当前View
      this.setVisible(false);
      // 不要背景图
      java.lang.reflect.Method drawable = null;
      try {
        drawable =
            this.getClass()
                .getMethod("setBackgroundDrawable", android.graphics.drawable.Drawable.class);
        drawable.invoke(this, (android.graphics.drawable.Drawable) null);
      } catch (Exception ex) {
        try {
          drawable =
              this.getClass().getMethod("setBackground", android.graphics.drawable.Drawable.class);
          drawable.invoke(this, (android.graphics.drawable.Drawable) null);
        } catch (Exception e) {

        }
      }
      // 进行细节设置
      webSettings = getSettings();
      // 数据库访问权限开启
      webSettings.setAllowFileAccess(true);
      // 密码保存与Form信息不保存
      // webSettings.setSavePassword(false);
      webSettings.setSaveFormData(false);
      if (!webSettings.getJavaScriptEnabled()) {
        // 响应JavaScript事件
        webSettings.setJavaScriptEnabled(true);
      }
      // 允许JavaScript脚本打开新的窗口
      webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
      // 允许自动加载图像资源
      webSettings.setLoadsImagesAutomatically(true);
      // 不支持网页缩放
      webSettings.setSupportZoom(false);

      // 当流程监听存在时
      if (webProcess != null) {
        setWebViewClient(
            new android.webkit.WebViewClient() {

              @Override
              public void onPageStarted(android.webkit.WebView view, String url, Bitmap favicon) {
                webProcess.onPageStarted(url, favicon);
                super.onPageStarted(view, url, favicon);
              }

              @Override
              public void onPageFinished(android.webkit.WebView view, String url) {
                webProcess.onPageFinished(url);
                super.onPageFinished(view, url);
              }

              @Override
              public void onLoadResource(android.webkit.WebView view, String url) {
                webProcess.onLoadResource(url);
                super.onLoadResource(view, url);
              }

              @Override
              public boolean shouldOverrideUrlLoading(android.webkit.WebView view, String url) {
                webProcess.shouldOverrideUrlLoading(url);
                return super.shouldOverrideUrlLoading(view, url);
              }

              @Override
              public void onReceivedHttpAuthRequest(
                  android.webkit.WebView view,
                  android.webkit.HttpAuthHandler handler,
                  String host,
                  String realm) {
                webProcess.onReceivedHttpAuthRequest(handler, host, realm);
                super.onReceivedHttpAuthRequest(view, handler, host, realm);
              }
            });
      }

      // 加载进度条
      final android.widget.ProgressBar progress = new android.widget.ProgressBar(activity);
      activity.addView(progress, AndroidLocation.CENTER);
      setWebChromeClient(
          new android.webkit.WebChromeClient() {
            @Override
            public void onProgressChanged(
                final android.webkit.WebView view, final int newProgress) {
              Loon.self.runOnUiThread(
                  new Runnable() {
                    @Override
                    public void run() {
                      progress.setProgress(newProgress);
                      progress.setVisibility(newProgress == 100 ? View.GONE : View.VISIBLE);
                      if (newProgress == 100) {
                        activity.removeView(progress);
                      }
                      setVisible(newProgress == 100 ? true : false);
                    }
                  });
            }
          });
      if (url != null) {
        loadUrl(url);
      }
    }