Пример #1
0
    @Override
    public void run() {
      if (height != 0) {
        height = (int) (Utils.densityMultiplier * height); // javascript returns us in dp
        WebView webView = mWebView.get();
        if (webView != null) {
          Logger.i(
              tag,
              "HeightRunnable called with height="
                  + height
                  + " and current height is "
                  + webView.getHeight());

          int initHeight = webView.getMeasuredHeight();

          Logger.i("HeightAnim", "InitHeight = " + initHeight + " TargetHeight = " + height);

          if (initHeight == height) {
            return;
          } else if (initHeight > height) {
            collapse(webView, height);
          } else if (initHeight < height) {
            expand(webView, height);
          }
        }
      }
    }
Пример #2
0
  /**
   * calling this function will share the screenshot of the webView along with the text at the top
   * and a caption text to all social network platforms by calling the system's intent.
   *
   * @param text : heading of the image with the webView's screenshot.
   * @param caption : intent caption
   */
  @JavascriptInterface
  public void share(String text, String caption) {
    FileOutputStream fos = null;
    File cardShareImageFile = null;
    Activity mContext = weakActivity.get();
    if (mContext != null) {
      try {
        if (TextUtils.isEmpty(text)) {
          text = mContext.getString(R.string.cardShareHeading); // fallback
        }

        cardShareImageFile =
            new File(mContext.getExternalCacheDir(), System.currentTimeMillis() + ".jpg");
        fos = new FileOutputStream(cardShareImageFile);
        View share =
            LayoutInflater.from(mContext).inflate(com.bsb.hike.R.layout.web_card_share, null);
        // set card image
        ImageView image = (ImageView) share.findViewById(com.bsb.hike.R.id.image);
        Bitmap b = Utils.viewToBitmap(mWebView);
        image.setImageBitmap(b);

        // set heading here
        TextView heading = (TextView) share.findViewById(R.id.heading);
        heading.setText(text);

        // set description text
        TextView tv = (TextView) share.findViewById(com.bsb.hike.R.id.description);
        tv.setText(Html.fromHtml(mContext.getString(com.bsb.hike.R.string.cardShareDescription)));

        Bitmap shB = Utils.undrawnViewToBitmap(share);
        Logger.i(
            tag,
            " width height of layout to share " + share.getWidth() + " , " + share.getHeight());
        shB.compress(Bitmap.CompressFormat.JPEG, 100, fos);
        fos.flush();
        Logger.i(tag, "share webview card " + cardShareImageFile.getAbsolutePath());
        Utils.startShareImageIntent(
            "image/jpeg",
            "file://" + cardShareImageFile.getAbsolutePath(),
            TextUtils.isEmpty(caption)
                ? mContext.getString(com.bsb.hike.R.string.cardShareCaption)
                : caption);
      } catch (Exception e) {
        e.printStackTrace();
        showToast(mContext.getString(com.bsb.hike.R.string.error_card_sharing));
      } finally {
        if (fos != null) {
          try {
            fos.close();
          } catch (IOException e) {
            // Do nothing
            e.printStackTrace();
          }
        }
      }
      if (cardShareImageFile != null && cardShareImageFile.exists()) {
        cardShareImageFile.deleteOnExit();
      }
    }
  }
Пример #3
0
  /**
   * Call this function to open a full page webView within hike.
   *
   * @param title : the title on the action bar.
   * @param url : the url that will be loaded.
   */
  @JavascriptInterface
  public void openFullPage(final String title, final String url) {
    Logger.i(tag, "open full page called with title " + title + " , and url = " + url);

    if (null == mHandler) {
      return;
    }
    mHandler.post(
        new Runnable() {
          @Override
          public void run() {
            if (weakActivity.get() != null) {
              Intent intent =
                  IntentManager.getWebViewActivityIntent(weakActivity.get(), url, title);
              weakActivity.get().startActivity(intent);
            }
          }
        });
  }
Пример #4
0
 /**
  * Whenever the content's height is changed, the html will call this function to resize the height
  * of the Android Webview. Calling this function is MUST, whenever the height of the content
  * changes.
  *
  * @param height : the new height when the content is reloaded.
  */
 @JavascriptInterface
 public void onResize(String height) {
   Logger.i(
       tag, "onresize called with height=" + (Integer.parseInt(height) * Utils.densityMultiplier));
   resizeWebview(height);
 }