示例#1
0
文件: Loon.java 项目: cping/LGame
 /** 通过Url进行跳转 */
 @Override
 public void loadUrl(String url) {
   boolean isURL =
       url.startsWith("http://") || url.startsWith("https://") || url.startsWith("ftp://");
   if (!isURL) {
     try {
       if (activity.getAssets().open(url) != null) {
         super.loadUrl("file:///android_asset/" + url);
       } else {
         super.loadUrl("http://" + url);
       }
     } catch (IOException e) {
       super.loadUrl("http://" + url);
     }
   } else {
     super.loadUrl(url);
   }
 }
示例#2
0
文件: Loon.java 项目: cping/LGame
 public static String getResourcePath(String name) throws IOException {
   if (self == null) {
     return name;
   }
   if (LSystem.base().type() == LGame.Type.ANDROID) {
     if (name.toLowerCase().startsWith("assets/")) {
       name = StringUtils.replaceIgnoreCase(name, "assets/", "");
     }
     if (name.startsWith("/") || name.startsWith("\\")) {
       name = name.substring(1, name.length());
     }
   }
   File file = new File(self.getFilesDir(), name);
   if (!file.exists()) {
     retrieveFromAssets(self, name);
   }
   return file.getAbsolutePath();
 }
示例#3
0
文件: Loon.java 项目: cping/LGame
    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);
      }
    }