Ejemplo n.º 1
0
  @Kroll.method
  public void setHtml(String html, @Kroll.argument(optional = true) KrollDict d) {
    setProperty(TiC.PROPERTY_HTML, html);
    setProperty(OPTIONS_IN_SETHTML, d);

    // If the web view has not been created yet, don't set html here. It will be set in
    // processProperties() when the
    // view is created.
    TiUIView v = peekView();
    if (v != null) {
      if (TiApplication.isUIThread()) {
        ((TiUIWebView) v).setHtml(html, d);
      } else {
        getMainHandler().sendEmptyMessage(MSG_SET_HTML);
      }
    }
  }
Ejemplo n.º 2
0
  public void reload() {
    switch (reloadMethod) {
      case DATA:
        if (reloadData != null && reloadData instanceof TiBlob) {
          setData((TiBlob) reloadData);
        } else {
          Log.d(
              TAG,
              "reloadMethod points to data but reloadData is null or of wrong type. Calling default",
              Log.DEBUG_MODE);
          getWebView().reload();
        }
        break;

      case HTML:
        if (reloadData == null || (reloadData instanceof HashMap<?, ?>)) {
          setHtml(
              TiConvert.toString(getProxy().getProperty(TiC.PROPERTY_HTML)),
              (HashMap<String, Object>) reloadData);
        } else {
          Log.d(
              TAG,
              "reloadMethod points to html but reloadData is of wrong type. Calling default",
              Log.DEBUG_MODE);
          getWebView().reload();
        }
        break;

      case URL:
        if (reloadData != null && reloadData instanceof String) {
          setUrl((String) reloadData);
        } else {
          Log.d(
              TAG,
              "reloadMethod points to url but reloadData is null or of wrong type. Calling default",
              Log.DEBUG_MODE);
          getWebView().reload();
        }
        break;

      default:
        getWebView().reload();
    }
  }
Ejemplo n.º 3
0
  public void setHtml(String html, HashMap<String, Object> d) {
    if (d == null) {
      setHtml(html);
      return;
    }

    reloadMethod = reloadTypes.HTML;
    reloadData = d;
    String baseUrl = TiC.URL_ANDROID_ASSET_RESOURCES;
    String mimeType = "text/html";
    if (d.containsKey(TiC.PROPERTY_BASE_URL_WEBVIEW)) {
      baseUrl = TiConvert.toString(d.get(TiC.PROPERTY_BASE_URL_WEBVIEW));
    }
    if (d.containsKey(TiC.PROPERTY_MIMETYPE)) {
      mimeType = TiConvert.toString(d.get(TiC.PROPERTY_MIMETYPE));
    }

    setHtmlInternal(html, baseUrl, mimeType);
  }
Ejemplo n.º 4
0
  @Override
  public void propertySet(String key, Object newValue, Object oldValue, boolean changedProperty) {
    switch (key) {
      case TiC.PROPERTY_SCALES_PAGE_TO_FIT:
        getWebView().getSettings().setLoadWithOverviewMode(TiConvert.toBoolean(newValue));
        break;
      case TiC.PROPERTY_CACHE_MODE:
        getWebView()
            .getSettings()
            .setCacheMode(TiConvert.toInt(newValue, AndroidModule.WEBVIEW_LOAD_DEFAULT));
        break;
      case TiC.PROPERTY_URL:
        if (!TiC.URL_ANDROID_ASSET_RESOURCES.equals(TiConvert.toString(newValue))) {
          setUrl(TiConvert.toString(newValue));
        } else {
          setUrl(null);
        }
        break;
      case TiC.PROPERTY_HTML:
        setHtml(
            TiConvert.toString(newValue),
            (HashMap<String, Object>) (proxy.getProperty(WebViewProxy.OPTIONS_IN_SETHTML)));
        break;
      case TiC.PROPERTY_DATA:
        if (newValue instanceof TiBlob) {
          setData((TiBlob) newValue);
        } else {
          setData(null);
        }
        break;
      case TiC.PROPERTY_LIGHT_TOUCH_ENABLED:
        getWebView().getSettings().setLightTouchEnabled(TiConvert.toBoolean(newValue));
        break;
      case TiC.PROPERTY_PLUGIN_STATE:
        setPluginState(TiConvert.toInt(newValue));
        break;
      case TiC.PROPERTY_SHOW_SCROLLBARS:
        boolean value = TiConvert.toBoolean(newValue);
        getWebView().setVerticalScrollBarEnabled(value);
        getWebView().setHorizontalScrollBarEnabled(value);
        break;
      case TiC.PROPERTY_OVER_SCROLL_MODE:
        nativeView.setOverScrollMode(TiConvert.toInt(newValue, View.OVER_SCROLL_ALWAYS));
        break;
      case TiC.PROPERTY_SCROLLING_ENABLED:
        setScrollingEnabled(newValue);
        break;
      case TiC.PROPERTY_SHOW_HORIZONTAL_SCROLL_INDICATOR:
        nativeView.setHorizontalScrollBarEnabled(TiConvert.toBoolean(newValue));
        break;
      case TiC.PROPERTY_SHOW_VERTICAL_SCROLL_INDICATOR:
        nativeView.setVerticalScrollBarEnabled(TiConvert.toBoolean(newValue));
        break;
      case TiC.PROPERTY_ENABLE_JAVASCRIPT_INTERFACE:
        boolean enableJavascriptInterface = TiConvert.toBoolean(newValue, true);
        if (Build.VERSION.SDK_INT > 16 || enableJavascriptInterface) {
          client.getBinding().addJavascriptInterfaces();
        } else {
          client.getBinding().removeJavascriptInterfaces();
        }
        break;
      default:
        super.propertySet(key, newValue, oldValue, changedProperty);
        break;
    }

    if (changedProperty) {
      // If TiUIView's propertyChanged ended up making a TiBackgroundDrawable
      // for the background, we must set the WebView background color to transparent
      // in order to see any of it.
      boolean isBgRelated =
          (key.startsWith(TiC.PROPERTY_BACKGROUND_PREFIX)
              || key.startsWith(TiC.PROPERTY_BORDER_PREFIX));
      if (isBgRelated
          && nativeView != null
          && nativeView.getBackground() instanceof TiBackgroundDrawable) {
        nativeView.setBackgroundColor(Color.TRANSPARENT);
      }
    }
  }