示例#1
0
 public void initWebview(WebView paramWebView) {
   WebSettings localWebSettings = paramWebView.getSettings();
   localWebSettings.setJavaScriptEnabled(true);
   if (Build.VERSION.SDK_INT > 7) localWebSettings.setPluginState(WebSettings.PluginState.ON);
   localWebSettings.setSupportZoom(true);
   localWebSettings.setBuiltInZoomControls(true);
   localWebSettings.setAllowFileAccess(true);
   localWebSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
   localWebSettings.setUseWideViewPort(true);
   if (Build.VERSION.SDK_INT >= 8) {
     localWebSettings.setLoadWithOverviewMode(true);
     localWebSettings.setDatabaseEnabled(true);
     localWebSettings.setDomStorageEnabled(true);
     localWebSettings.setGeolocationEnabled(true);
     localWebSettings.setAppCacheEnabled(true);
   }
   if (Build.VERSION.SDK_INT >= 11) ;
   try {
     Class[] arrayOfClass = new Class[1];
     arrayOfClass[0] = Boolean.TYPE;
     Method localMethod =
         WebSettings.class.getDeclaredMethod("setDisplayZoomControls", arrayOfClass);
     localMethod.setAccessible(true);
     Object[] arrayOfObject = new Object[1];
     arrayOfObject[0] = Boolean.valueOf(false);
     localMethod.invoke(localWebSettings, arrayOfObject);
     return;
   } catch (Exception localException) {
     com.taobao.newxp.common.Log.e(ExchangeConstants.LOG_TAG, "", localException);
   }
 }
 @SuppressLint("SetJavaScriptEnabled")
 public void configureSetting(WebViewBridge webViewBridge) {
   WebSettings settings = webViewBridge.getSettings();
   settings.setJavaScriptEnabled(true);
   settings.setJavaScriptCanOpenWindowsAutomatically(true);
   settings.setGeolocationEnabled(true);
   settings.setDomStorageEnabled(true);
   File databasePath = new File(mContext.getCacheDir(), "webstorage");
   settings.setDatabasePath(databasePath.toString());
   settings.setAppCacheEnabled(true);
   settings.setAppCacheMaxSize(1024 * 1024 * 4);
 }
示例#3
0
  private void initializeSettings(WebSettings settings) {
    settings.setJavaScriptEnabled(true);

    // configure local storage apis and their database paths.
    settings.setAppCachePath(getDir("appcache", 0).getPath());
    settings.setGeolocationDatabasePath(getDir("geolocation", 0).getPath());
    settings.setDatabasePath(getDir("databases", 0).getPath());

    settings.setAppCacheEnabled(true);
    settings.setGeolocationEnabled(true);
    settings.setDatabaseEnabled(true);
    settings.setDomStorageEnabled(true);
  }
  /** Create and initialize web container. */
  public void init() {
    LOG.d(TAG, "DroidGap.init()");

    // Create web container
    this.appView = new WebView(DroidGap.this);
    this.appView.setId(100);

    this.appView.setLayoutParams(
        new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT, 1.0F));

    this.appView.setWebChromeClient(new CordovaChromeClient(DroidGap.this));
    this.setWebViewClient(this.appView, new CordovaWebViewClient(this));

    this.appView.setInitialScale(0);
    this.appView.setVerticalScrollBarEnabled(false);
    this.appView.requestFocusFromTouch();

    // Enable JavaScript
    WebSettings settings = this.appView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);

    // Set the nav dump for HTC
    settings.setNavDump(true);

    // Enable database
    settings.setDatabaseEnabled(true);
    String databasePath =
        this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    settings.setDatabasePath(databasePath);

    // Enable DOM storage
    settings.setDomStorageEnabled(true);

    // Enable built-in geolocation
    settings.setGeolocationEnabled(true);

    // Add web view but make it invisible while loading URL
    this.appView.setVisibility(View.INVISIBLE);
    root.addView(this.appView);
    setContentView(root);

    // Clear cancel flag
    this.cancelLoadUrl = false;
  }
示例#5
0
  public synchronized void initPreferences() {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    WebSettings webSettings = getSettings();

    webSettings.setLoadWithOverviewMode(true);
    webSettings.setTextZoom(100);
    webSettings.setUseWideViewPort(true);

    webSettings.setBlockNetworkImage(!sp.getBoolean(context.getString(R.string.sp_images), true));
    webSettings.setJavaScriptEnabled(
        sp.getBoolean(context.getString(R.string.sp_javascript), true));
    webSettings.setJavaScriptCanOpenWindowsAutomatically(
        sp.getBoolean(context.getString(R.string.sp_javascript), true));
    webSettings.setGeolocationEnabled(sp.getBoolean(context.getString(R.string.sp_location), true));
    webSettings.setSupportMultipleWindows(
        sp.getBoolean(context.getString(R.string.sp_multiple_windows), false));
    webSettings.setSaveFormData(sp.getBoolean(context.getString(R.string.sp_passwords), true));

    boolean textReflow = sp.getBoolean(context.getString(R.string.sp_text_reflow), true);
    if (textReflow) {
      webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        try {
          webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING);
        } catch (Exception e) {
        }
      }
    } else {
      webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
    }

    int userAgent = Integer.valueOf(sp.getString(context.getString(R.string.sp_user_agent), "0"));
    if (userAgent == 1) {
      webSettings.setUserAgentString(BrowserUnit.UA_DESKTOP);
    } else if (userAgent == 2) {
      webSettings.setUserAgentString(
          sp.getString(context.getString(R.string.sp_user_agent_custom), userAgentOriginal));
    } else {
      webSettings.setUserAgentString(userAgentOriginal);
    }

    int mode = Integer.valueOf(sp.getString(context.getString(R.string.sp_rendering), "0"));
    initRendering(mode);

    webViewClient.enableAdBlock(sp.getBoolean(context.getString(R.string.sp_ad_block), true));
  }
 static void b(WebSettings webSettings, boolean z) {
   webSettings.setGeolocationEnabled(z);
 }
示例#7
0
  @SuppressLint("SetJavaScriptEnabled")
  @SuppressWarnings("deprecation")
  private void initWebViewSettings() {
    this.setInitialScale(0);
    this.setVerticalScrollBarEnabled(false);
    // TODO: The Activity is the one that should call requestFocus().
    if (shouldRequestFocusOnInit()) {
      this.requestFocusFromTouch();
    }
    this.setInitialScale(0);
    this.setVerticalScrollBarEnabled(false);
    if (shouldRequestFocusOnInit()) {
      this.requestFocusFromTouch();
    }
    // Enable JavaScript
    final WebSettings settings = this.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);

    // Set the nav dump for HTC 2.x devices (disabling for ICS, deprecated entirely for Jellybean
    // 4.2)
    try {
      Method gingerbread_getMethod =
          WebSettings.class.getMethod("setNavDump", new Class[] {boolean.class});

      String manufacturer = android.os.Build.MANUFACTURER;
      Log.d(TAG, "CordovaWebView is running on device made by: " + manufacturer);
      if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB
          && android.os.Build.MANUFACTURER.contains("HTC")) {
        gingerbread_getMethod.invoke(settings, true);
      }
    } catch (NoSuchMethodException e) {
      Log.d(TAG, "We are on a modern version of Android, we will deprecate HTC 2.3 devices in 2.8");
    } catch (IllegalArgumentException e) {
      Log.d(TAG, "Doing the NavDump failed with bad arguments");
    } catch (IllegalAccessException e) {
      Log.d(
          TAG, "This should never happen: IllegalAccessException means this isn't Android anymore");
    } catch (InvocationTargetException e) {
      Log.d(
          TAG,
          "This should never happen: InvocationTargetException means this isn't Android anymore.");
    }

    // We don't save any form data in the application
    settings.setSaveFormData(false);
    settings.setSavePassword(false);

    // Jellybean rightfully tried to lock this down. Too bad they didn't give us a whitelist
    // while we do this
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
      Level16Apis.enableUniversalAccess(settings);
    }
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
      Level17Apis.setMediaPlaybackRequiresUserGesture(settings, false);
    }
    // Enable database
    // We keep this disabled because we use or shim to get around DOM_EXCEPTION_ERROR_16
    String databasePath =
        getContext().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    settings.setDatabaseEnabled(true);
    settings.setDatabasePath(databasePath);

    // Determine whether we're in debug or release mode, and turn on Debugging!
    ApplicationInfo appInfo = getContext().getApplicationContext().getApplicationInfo();
    if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0
        && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
      enableRemoteDebugging();
    }

    settings.setGeolocationDatabasePath(databasePath);

    // Enable DOM storage
    settings.setDomStorageEnabled(true);

    // Enable built-in geolocation
    settings.setGeolocationEnabled(true);

    // Enable AppCache
    // Fix for CB-2282
    settings.setAppCacheMaxSize(5 * 1048576);
    settings.setAppCachePath(databasePath);
    settings.setAppCacheEnabled(true);

    // Fix for CB-1405
    // Google issue 4641
    settings.getUserAgentString();

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
    if (this.receiver == null) {
      this.receiver =
          new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
              settings.getUserAgentString();
            }
          };
      getContext().registerReceiver(this.receiver, intentFilter);
    }
    // end CB-1405
  }
示例#8
0
  // 封装WebView
  public static void wrapWebView(Context context, WebView webView, WebViewClient webclient) {
    WebSettings webSettings = webView.getSettings();
    webSettings.setSavePassword(false);
    webSettings.setSaveFormData(false);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setSupportZoom(false);

    // 设置定位可用
    if (context != null) {
      webSettings.setDatabaseEnabled(true);
      String dir =
          context.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();

      // 启用地理定位
      webSettings.setGeolocationEnabled(true);
      // 设置定位的数据库路径
      webSettings.setGeolocationDatabasePath(dir);

      // 最重要的方法,一定要设置,这就是出不来的主要原因

      webSettings.setDomStorageEnabled(true);
    }
    //
    webView.setWebChromeClient(
        new WebChromeClient() {
          @Override
          public void onGeolocationPermissionsShowPrompt(String origin, Callback callback) {
            callback.invoke(origin, true, false);
            super.onGeolocationPermissionsShowPrompt(origin, callback);
          }
        });
    webView.setWebViewClient(webclient);
    // webView.setWebViewClient(new WebViewClient() {
    //
    // // 加载链接
    // @Override
    // public boolean shouldOverrideUrlLoading(WebView view, String url) {
    // view.loadUrl(url);
    // return true;
    // }
    //
    // // 链接开始加载时
    // @Override
    // public void onPageStarted(WebView view, String url, Bitmap favicon) {
    // super.onPageStarted(view, url, favicon);
    // if (progress != null) {
    // progress.setVisibility(View.VISIBLE);
    // }
    // }
    //
    // // 链接加载完成
    // @Override
    // public void onPageFinished(WebView view, String url) {
    // super.onPageFinished(view, url);
    // if (progress != null) {
    // progress.setVisibility(View.GONE);
    // }
    // }
    //
    // @Override
    // public void onReceivedSslError(WebView view, SslErrorHandler handler,
    // SslError error) {
    // super.onReceivedSslError(view, handler, error);
    // }
    //
    // // webview无网络情况下的人性化处理
    // @Override
    // public void onReceivedError(WebView view, int errorCode, String
    // description, String failingUrl) {
    // super.onReceivedError(view, errorCode, description, failingUrl);
    // view.loadData("", "text/html", "utf-8");
    // Toast.makeText(view.getContext(), "网络不给力",
    // android.widget.Toast.LENGTH_LONG).show();
    // }
    // });
  }
示例#9
0
  /** 初始化主页面视图 * */
  private void initContentWebView() {
    contentWebView = (WebView) this.findViewById(R.id.webView1);

    contentWebView.setWebChromeClient(new WebChromeClientEx(PortalActivity.this));
    contentWebView.setWebViewClient(new WebViewClientEx(this));
    contentWebView.setInitialScale(0);
    contentWebView.setScrollBarStyle(0); // 滚动条风格,为0就是不给滚动条留空间,滚动条覆盖在网页上
    contentWebView.setVerticalScrollBarEnabled(false);
    contentWebView.requestFocusFromTouch();

    // Enable JavaScript
    WebSettings settings = contentWebView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);

    // Set the nav dump for HTC
    settings.setNavDump(true);

    // 支持html5的localStorage
    settings.setDatabaseEnabled(true);
    String databasePath =
        this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    settings.setDatabasePath(databasePath);
    settings.setDomStorageEnabled(true);

    // Enable built-in geolocation
    settings.setGeolocationEnabled(true);

    // Clear cancel flag
    this.cancelLoadUrl = false;

    String version = android.os.Build.VERSION.RELEASE;
    if (version != null && version.indexOf("4.0") != -1) {
      this.clearCache();
    }
    contentWebView.addJavascriptInterface(
        new Object() {
          @SuppressWarnings("unused")
          public void eventHandle(String params) {
            appEventHandle(new AppEvent(params));
          }

          @SuppressWarnings("unused")
          public String getAndroidVersion() {
            return android.os.Build.VERSION.RELEASE;
          }

          @SuppressWarnings("unused")
          public void openAppSetting() {
            openSettingDlg();
          }

          @SuppressWarnings("unused")
          public void checkPage(String success) {
            if ("true".equalsIgnoreCase(success)) {
              loadSuccess = true;
              spinnerStop();
            } else {
              PortalActivity me = PortalActivity.this;
              me.runOnUiThread(
                  new Runnable() {
                    public void run() {
                      showErrorTip("连接超时,似乎加载的页面不正常!请检查网络和配置");
                      openSettingDlg();
                    }
                  });
            }
          }
        },
        "nativeApp");
    contentWebView.addJavascriptInterface(
        new Object() {
          @SuppressWarnings("unused")
          public void testCall() {
            injectJSObject();
          }
        },
        "justepApp");

    contentWebView.setDownloadListener(new JustepAppWebViewDownLoadListener());

    /**
     * contentWebView.setWebViewClient(new WebViewClient() {
     *
     * <p>});
     */
  }
示例#10
0
  @SuppressLint("SetJavaScriptEnabled")
  @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    try {
      // get url and navigatio preference (default true)
      final String url = getIntent().getStringExtra(getPackageName() + ".URL");
      final boolean navigation =
          getIntent().getBooleanExtra(getPackageName() + ".NAVIGATION", true);

      setContentView(R.layout.webviewnav);

      // if we want navigation bar and not hide it, make it visible. Make it invisible if not.
      if (navigation && !hideNavigationBar) {
        findViewById(R.id.webBottomBar).setVisibility(View.VISIBLE);
      } else {
        findViewById(R.id.webBottomBar).setVisibility(View.GONE);
      }

      mButtonBack = (ImageButton) findViewById(R.id.buttonWebBack);
      mButtonForward = (ImageButton) findViewById(R.id.buttonWebForward);
      mButtonStop = (ImageButton) findViewById(R.id.buttonWebStop);

      mProgressView = (ProgressBar) findViewById(R.id.progressBar);
      mProgressView.setIndeterminate(true);

      // init webview
      mWebView = (WebView) findViewById(R.id.webView);

      // disable hw accel as it creates flickering pages, html5 video won't work with this
      if (Build.VERSION.SDK_INT >= 11 && Build.VERSION.SDK_INT < 16)
        mWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

      // This hides white bar on the right
      mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);

      WebSettings settings = mWebView.getSettings();
      // enable plugins before java script
      settings.setPluginState(PluginState.ON);

      // TODO test these two settings with a big webpage (cafe lotty?)
      settings.setLoadWithOverviewMode(true);
      settings.setUseWideViewPort(true);
      // enable javascript and zoom controls
      settings.setJavaScriptEnabled(true);
      settings.setBuiltInZoomControls(true);
      settings.setGeolocationEnabled(true);
      settings.setDatabaseEnabled(true);
      String databasePath = getDir("database_ext", Context.MODE_PRIVATE).getPath();
      settings.setDatabasePath(databasePath);
      settings.setGeolocationDatabasePath(databasePath);
      settings.setDomStorageEnabled(true);
      settings.setAppCacheEnabled(true);

      // allow XMLHttpRequests
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
        settings.setAllowUniversalAccessFromFileURLs(true);

      MetaioWebViewClient client = new MetaioWebViewClient();
      mWebView.setWebViewClient(client);
      mWebView.setWebChromeClient(new MetaioWebChromeClient());

      registerForContextMenu(mWebView);

      if (savedInstanceState != null) {
        mWebView.restoreState(savedInstanceState);
      } else {

        // if we don't have to override the url, load it in the webview
        if (!client.shouldOverrideUrlLoading(mWebView, url)) mWebView.loadUrl(url);
      }
    } catch (Exception e) {
      MetaioCloudPlugin.log(Log.ERROR, "WebViewActivity.onCreate", e);
    }
  }