예제 #1
0
  private void initWebView() {
    WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setPluginsEnabled(true);
    settings.setAllowFileAccess(false);
    settings.setPluginState(WebSettings.PluginState.ON);

    webView.setBackgroundColor(0x00000000); // transparent
    webView.setVerticalScrollBarEnabled(false);
    webView.setHorizontalScrollBarEnabled(false);
    webView.setWebChromeClient(new OpenXAdWebChromeClient());

    addView(webView);
  }
  @Override
  protected void onStart() {
    super.onStart();

    try {
      jsonSrc = FileUtils.readFromAssetsFile(that, "json2.js");
      androidJsSrc = FileUtils.readFromAssetsFile(that, "android.js");
    } catch (IOException e1) {
      throw new RuntimeException(e1);
    }

    mObserver = new HtmlEventObserver();

    // TODO
    // RpcReceiverManager mFacadeManager = getRpcReceiverManager();
    // mFacadeManager.getReceiver(EventFacade.class).addGlobalEventObserver(mObserver);
    // mAPIWrapperSource = generateAPIWrapper();

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, config.getLOG_TAG());
    mWebView.setKeepScreenOn(true);

    mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    mWebView.setScrollbarFadingEnabled(false);
    mWebView.setVerticalScrollBarEnabled(false);
    mWebView.setHorizontalScrollBarEnabled(false);
    mWebView.setScrollContainer(false);

    WebSettings webSettings = mWebView.getSettings();
    webSettings.setSavePassword(false);
    webSettings.setSaveFormData(false);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setPluginsEnabled(true);

    webSettings.setSupportZoom(false);
    webSettings.setSupportZoom(true);
    webSettings.setBuiltInZoomControls(true);
    webSettings.setUseWideViewPort(true);
    webSettings.setLoadWithOverviewMode(true);

    mWebView.addJavascriptInterface(mWrapper, "_rpc_wrapper");
    mWebView.addJavascriptInterface(
        new Object() {

          @SuppressWarnings("unused")
          public void register(String event, int id) {
            mObserver.register(event, id);
          }
        },
        "_callback_wrapper");

    if (Build.VERSION.SDK_INT >= 5) {
      try {
        Method m1 = WebSettings.class.getMethod("setDomStorageEnabled", new Class[] {Boolean.TYPE});
        m1.invoke(webSettings, Boolean.TRUE);

        Method m2 = WebSettings.class.getMethod("setDatabaseEnabled", new Class[] {Boolean.TYPE});
        m2.invoke(webSettings, Boolean.TRUE);

        Method m3 = WebSettings.class.getMethod("setDatabasePath", new Class[] {String.class});
        m3.invoke(webSettings, this.getFilesDir().getParent() + "/databases/");
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    mWebView.setWebChromeClient(new WebChromeClient() {});

    mWebView.setWebViewClient(
        new WebViewClient() {
          //        	public void onReceivedError(WebView view, int errorCode, String description,
          // String failingUrl) {
          //        		Toast.makeText(that, "Error: " + description, Toast.LENGTH_SHORT).show();
          //        	}
        });

    webSettings.setCacheMode(WebSettings.LOAD_NORMAL);

    if (Build.VERSION.SDK_INT >= 11 && Build.VERSION.SDK_INT < 14) {
      mWebView.setSystemUiVisibility(WebView.STATUS_BAR_HIDDEN);
    } else if (Build.VERSION.SDK_INT >= 14) {
      mWebView.setSystemUiVisibility(WebView.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
    }

    mWebView.loadUrl("javascript:" + jsonSrc);
    mWebView.loadUrl("javascript:" + androidJsSrc);
    mWebView.loadUrl("javascript:" + mAPIWrapperSource);
    Log.d(
        config.getLOG_TAG(),
        "Launch Webview: "
            + "file://"
            + this.getFilesDir().getAbsolutePath()
            + "/"
            + config.getMAIN_SCRIPT_NAME());
    mWebView.loadUrl(
        "file://" + this.getFilesDir().getAbsolutePath() + "/" + config.getMAIN_SCRIPT_NAME());
  }
예제 #3
0
  public WebFrame(Activity context, boolean allowNavigation, boolean scroll, boolean showExit) {
    super(context);
    initCompatibility();
    mActivity = context;
    mWebView = new WebView(context);
    mWebView.setVerticalScrollBarEnabled(scroll);
    mWebView.setHorizontalScrollBarEnabled(scroll);
    mWebView.setBackgroundColor(Color.TRANSPARENT);
    setLayer(mWebView);
    WebSettings webSettings = mWebView.getSettings();
    webSettings.setSavePassword(false);
    webSettings.setSaveFormData(false);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setPluginsEnabled(true);
    webSettings.setSupportZoom(enableZoom);
    webSettings.setBuiltInZoomControls(enableZoom);
    mWebViewClient = new WebViewClient(mActivity, allowNavigation);
    mWebView.setWebViewClient(mWebViewClient);

    final Activity localContext = context;
    if (showExit) {
      ImageView bg = new ImageView(context);
      bg.setBackgroundColor(Color.TRANSPARENT);
      addView(
          bg,
          new FrameLayout.LayoutParams(
              android.view.ViewGroup.LayoutParams.FILL_PARENT,
              android.view.ViewGroup.LayoutParams.FILL_PARENT,
              Gravity.CENTER));
      addView(
          mWebView,
          new FrameLayout.LayoutParams(
              android.view.ViewGroup.LayoutParams.FILL_PARENT,
              android.view.ViewGroup.LayoutParams.FILL_PARENT,
              Gravity.CENTER));
      mExitButton = new ImageView(context);
      mExitButton.setAdjustViewBounds(false);
      mExitButton.setOnClickListener(
          new OnClickListener() {

            @Override
            public void onClick(View v) {
              localContext.finish();
            }
          });
      int buttonSize =
          (int)
              TypedValue.applyDimension(
                  TypedValue.COMPLEX_UNIT_DIP, 35, getResources().getDisplayMetrics());
      mExitButton.setImageDrawable(
          ResourceManager.getStaticResource(
              context, ResourceManager.DEFAULT_SKIP_IMAGE_RESOURCE_ID));
      FrameLayout.LayoutParams params =
          new FrameLayout.LayoutParams(buttonSize, buttonSize, Gravity.TOP | Gravity.RIGHT);
      int margin =
          (int)
              TypedValue.applyDimension(
                  TypedValue.COMPLEX_UNIT_DIP, 6, getResources().getDisplayMetrics());
      params.topMargin = margin;
      params.rightMargin = margin;
      addView(mExitButton, params);
    } else {
      addView(
          mWebView,
          new FrameLayout.LayoutParams(
              android.view.ViewGroup.LayoutParams.FILL_PARENT,
              android.view.ViewGroup.LayoutParams.FILL_PARENT,
              Gravity.CENTER));
    }
  }