示例#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
 private void saveOutput(Bitmap croppedImage) {
   if (mSaveUri != null) {
     if (croppedImage != null) {
       OutputStream outputStream = null;
       try {
         outputStream = mContentResolver.openOutputStream(mSaveUri);
         if (outputStream != null) {
           croppedImage.compress(mOutputFormat, 100, outputStream);
         }
       } catch (IOException ex) {
         // TODO: report error to caller
         Logger.e(TAG, "Cannot open file: " + mSaveUri, ex);
       } finally {
         Util.closeSilently(outputStream);
       }
     }
     Bundle extras = new Bundle();
     extras.putString(MediaStore.EXTRA_OUTPUT, croppedImage == null ? null : mSaveUri.getPath());
     setResult(RESULT_OK, new Intent(mSaveUri.toString()).putExtras(extras));
   } else {
     Bundle extras = new Bundle();
     extras.putParcelable(HikeConstants.Extras.BITMAP, croppedImage);
     setResult(RESULT_OK, new Intent().putExtras(extras));
   }
   finish();
 }
示例#4
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);
            }
          }
        });
  }
示例#5
0
  /**
   * call this function with parameter as true to enable the debugging for javascript. The
   * debuggable for javascript will get enabled only after KITKAT version.
   *
   * @param setEnabled
   */
  @JavascriptInterface
  public void setDebuggableEnabled(final String setEnabled) {
    Logger.d(tag, "set debuggable enabled called with " + setEnabled);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
      if (null == mHandler) {
        return;
      }
      mHandler.post(
          new Runnable() {
            @SuppressLint("NewApi")
            @Override
            public void run() {
              if (Boolean.valueOf(setEnabled)) {

                WebView.setWebContentsDebuggingEnabled(true);
              } else {
                WebView.setWebContentsDebuggingEnabled(false);
              }
            }
          });
    }
  }
  @Override
  public STResult call() throws Exception {
    Logger.d(getClass().getSimpleName(), "CategoryId: " + category.getCategoryId());

    String directoryPath =
        StickerManager.getInstance().getStickerDirectoryForCategoryId(category.getCategoryId());
    if (directoryPath == null) {
      setException(new StickerException(StickerException.DIRECTORY_NOT_EXISTS));
      Logger.e(
          StickerDownloadManager.TAG,
          "Sticker download failed directory does not exist for task : " + taskId);
      return STResult.DOWNLOAD_FAILED;
    }

    File largeStickerDir = new File(directoryPath + HikeConstants.LARGE_STICKER_ROOT);
    File smallStickerDir = new File(directoryPath + HikeConstants.SMALL_STICKER_ROOT);
    int totalNumber = 0;
    boolean reachedEnd = false;
    boolean retry = true;
    int existingStickerNumber = 0;

    JSONArray existingStickerIds = new JSONArray();

    if (smallStickerDir.exists()) {
      String[] stickerIds = smallStickerDir.list(StickerManager.getInstance().stickerFileFilter);
      for (String stickerId : stickerIds) {
        existingStickerIds.put(stickerId);
        existingStickerNumber++;
        Logger.d(getClass().getSimpleName(), "Existing id: " + stickerId);
      }
    } else {
      smallStickerDir.mkdirs();
      Logger.d(getClass().getSimpleName(), "No existing sticker");
    }
    if (!largeStickerDir.exists()) largeStickerDir.mkdirs();

    Utils.makeNoMediaFile(largeStickerDir);
    Utils.makeNoMediaFile(smallStickerDir);
    while (shouldContinue(reachedEnd, totalNumber, existingStickerNumber)) {

      try {

        JSONObject request = new JSONObject();
        request.put(StickerManager.CATEGORY_ID, category.getCategoryId());
        request.put(HikeConstants.STICKER_IDS, existingStickerIds);
        request.put(HikeConstants.RESOLUTION_ID, Utils.getResolutionId());
        request.put(HikeConstants.NUMBER_OF_STICKERS, getStickerDownloadSize());
        if (source != null) {
          request.put(HikeConstants.DOWNLOAD_SOURCE, source.ordinal());
        }

        String urlString = AccountUtils.base + "/stickers";
        if (AccountUtils.ssl) {
          urlString = AccountUtils.HTTPS_STRING + AccountUtils.host + "/v1" + "/stickers";
        }
        setDownloadUrl(urlString);

        Logger.d(
            StickerDownloadManager.TAG, "Sticker Download Task Request : " + request.toString());
        Logger.d(
            StickerDownloadManager.TAG,
            "Starting download task : " + taskId + " url : " + urlString);
        JSONObject response = (JSONObject) download(request, HttpRequestType.POST);

        if (response == null
            || !HikeConstants.OK.equals(response.getString(HikeConstants.STATUS))) {
          setException(new StickerException(StickerException.NULL_OR_INVALID_RESPONSE));
          Logger.e(
              StickerDownloadManager.TAG,
              "Sticker download failed null or invalid response for task : " + taskId);
          return STResult.DOWNLOAD_FAILED;
        }
        Logger.d(
            StickerDownloadManager.TAG,
            "Got response for download task : " + taskId + " response : " + response.toString());
        int length = response.toString().getBytes().length;

        if (length > Utils.getFreeSpace()) {
          setException(new StickerException(StickerException.OUT_OF_SPACE));
          Logger.e(
              StickerDownloadManager.TAG,
              "Sticker download failed directory out of space for task : " + taskId);
          return STResult.DOWNLOAD_FAILED;
        }

        totalNumber = response.optInt(HikeConstants.TOTAL_STICKERS, -1);
        reachedEnd = response.optBoolean(HikeConstants.REACHED_STICKER_END);
        Logger.d(getClass().getSimpleName(), "Reached end? " + reachedEnd);
        Logger.d(getClass().getSimpleName(), "Sticker count: " + totalNumber);
        JSONObject data = response.getJSONObject(HikeConstants.DATA_2);
        for (Iterator<String> keys = data.keys(); keys.hasNext(); ) {
          String stickerId = keys.next();
          String stickerData = data.getString(stickerId);
          existingStickerIds.put(stickerId);
          existingStickerNumber++;

          try {
            byte[] byteArray =
                StickerManager.getInstance()
                    .saveLargeStickers(largeStickerDir.getAbsolutePath(), stickerId, stickerData);
            StickerManager.getInstance()
                .saveSmallStickers(smallStickerDir.getAbsolutePath(), stickerId, byteArray);
          } catch (FileNotFoundException e) {
            Logger.w(getClass().getSimpleName(), e);
          } catch (IOException e) {
            Logger.w(getClass().getSimpleName(), e);
          }
        }

      } catch (StickerException e) {
        Logger.e(StickerDownloadManager.TAG, "Sticker download failed for task : " + taskId, e);
        setException(e);
        return STResult.DOWNLOAD_FAILED;
      } catch (Exception e) {
        Logger.e(StickerDownloadManager.TAG, "Sticker download failed for task : " + taskId, e);
        setException(new StickerException(e));
        return STResult.DOWNLOAD_FAILED;
      }

      if (getRetryPolicy() != null) {
        ((DefaultRetryPolicy) getRetryPolicy()).reset();
      }
      if (totalNumber != 0) {
        sendProgressOrResult(null, true, existingStickerNumber / totalNumber);
      }
      if (category.getTotalStickers() != totalNumber) {
        category.setTotalStickers(totalNumber);
        HikeConversationsDatabase.getInstance()
            .updateStickerCountForStickerCategory(category.getCategoryId(), totalNumber);
      }
    }

    if (isSucessfull(reachedEnd, totalNumber, existingStickerNumber)) {
      return STResult.SUCCESS;
    } else {
      return STResult.DOWNLOAD_FAILED;
    }
  }
  @Override
  public void onReceive(Context context, Intent intent) {
    /*
     * no name setting, so don't bother pulling in SMS's yet or The user doesn't want us pulling in his SMS.
     */

    Logger.d("HikeMessageReceiver", System.currentTimeMillis() + "");
    Logger.d("HikeMessageReceiver", "message received");

    // If the User is not authenticated and the GCMID is not sent to the server and the user is
    // connected.

    HikeSharedPreferenceUtil mprefs = HikeSharedPreferenceUtil.getInstance();

    if (Utils.isUserOnline(context)
        && (!Utils.isUserAuthenticated(context))
        && !mprefs.getData(HikeMessengerApp.GCM_ID_SENT_PRELOAD, false)) {

      Intent in = new Intent(HikeService.REGISTER_TO_GCM_ACTION);
      mprefs.saveData(HikeConstants.REGISTER_GCM_SIGNUP, HikeConstants.REGISTEM_GCM_BEFORE_SIGNUP);
      LocalBroadcastManager.getInstance(context.getApplicationContext()).sendBroadcast(in);
      return;
    }

    if (!Utils.isUserSignedUp(context, false)
        || !PreferenceManager.getDefaultSharedPreferences(context)
            .getBoolean(HikeConstants.RECEIVE_SMS_PREF, false)) {
      return;
    }

    Logger.d(getClass().getSimpleName(), "Received SMS message");
    Bundle extras = intent.getExtras();
    if (extras != null) {
      Logger.d(getClass().getSimpleName(), "Received SMS message with extras " + extras.keySet());
      Object[] extra = (Object[]) extras.get("pdus");
      Logger.d(getClass().getSimpleName(), "Extras length is " + extra.length);
      for (int i = 0; i < extra.length; ++i) {
        SmsMessage sms = SmsMessage.createFromPdu((byte[]) extra[i]);

        String body = sms.getMessageBody();
        long timestamp = sms.getTimestampMillis() / 1000;
        String from = sms.getOriginatingAddress();
        ContactInfo contactInfo = HikeMessengerApp.getContactManager().getContact(from, true, true);
        if (contactInfo == null) {
          Logger.d(
              getClass().getSimpleName(),
              "Ignoring SMS message because contact not in addressbook phone_no=" + from);
          return;
        }
        try {

          JSONObject msg = new JSONObject();
          msg.put(HikeConstants.TYPE, HikeConstants.MqttMessageTypes.MESSAGE);
          msg.put(HikeConstants.FROM, contactInfo.getMsisdn());

          JSONObject data = new JSONObject();
          data.put(HikeConstants.SMS_MESSAGE, body);
          data.put(HikeConstants.TIMESTAMP, timestamp);
          data.put(HikeConstants.MESSAGE_ID, makeSMSId(from, body, timestamp));

          msg.put(HikeConstants.DATA, data);

          writeToNativeSMSDb(context, msg);

          Logger.d(getClass().getSimpleName(), "Received SMS " + msg.toString());
          Intent smsReceivedIntent = new Intent(context, HikeService.class);
          smsReceivedIntent.putExtra(HikeConstants.Extras.SMS_MESSAGE, msg.toString());
          context.startService(smsReceivedIntent);

          this.abortBroadcast();
        } catch (JSONException e) {
          Logger.e(getClass().getSimpleName(), "Invalid data for SMS message", e);
          return;
        }
      }
    }
  }
示例#8
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);
 }
示例#9
0
 /**
  * calling this function will generate logs for testing at the android IDE. The first param will
  * be tag used for logging and the second param is data that is used for logging. this will create
  * verbose logs for testing purposes.
  *
  * @param tag
  * @param data
  */
 @JavascriptInterface
 public void logFromJS(String tag, String data) {
   Logger.v(tag, data);
 }
示例#10
0
  @Override
  public void onCreate(Bundle icicle) {
    overridePendingTransition(R.anim.fade_in_animation, R.anim.fade_out_animation);

    super.onCreate(icicle);

    mContentResolver = getContentResolver();

    getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.cropimage);

    /*
     * Added to fix a Android issue for devices that support hardware acceleration. http://android-developers.blogspot.in/2011/03/android-30 -hardware-acceleration.html
     */
    mImageView = (CropImageView) findViewById(R.id.image);
    try {
      Method method = mImageView.getClass().getMethod("setLayerType", Integer.TYPE, Paint.class);
      method.invoke(mImageView, 1, null);
    } catch (IllegalArgumentException e) {
      Logger.e(getClass().getSimpleName(), "Exception during reflection", e);
    } catch (IllegalAccessException e) {
      Logger.e(getClass().getSimpleName(), "Exception during reflection", e);
    } catch (InvocationTargetException e) {
      Logger.e(getClass().getSimpleName(), "Exception during reflection", e);
    } catch (SecurityException e) {
      Logger.e(getClass().getSimpleName(), "Exception during reflection", e);
    } catch (NoSuchMethodException e) {
      Logger.e(getClass().getSimpleName(), "Exception during reflection", e);
    }

    showStorageToast(this);

    Intent intent = getIntent();
    Bundle extras = intent.getExtras();
    if (extras != null) {
      if (extras.getString(HikeConstants.Extras.CIRCLE_CROP) != null) {
        mCircleCrop = true;
        mAspectX = 1;
        mAspectY = 1;
      }

      if (extras.containsKey(HikeConstants.Extras.RETURN_CROP_RESULT_TO_FILE)) {
        returnToFile = extras.getBoolean(HikeConstants.Extras.RETURN_CROP_RESULT_TO_FILE);
      }

      mImagePath = extras.getString(HikeConstants.Extras.IMAGE_PATH);
      mSaveUri =
          extras.containsKey(MediaStore.EXTRA_OUTPUT)
              ? getImageUri(extras.getString(MediaStore.EXTRA_OUTPUT))
              : null;

      // look here
      mBitmap = getBitmap(mImagePath);
      String imageOrientation = Utils.getImageOrientation(mImagePath);
      mBitmap = HikeBitmapFactory.rotateBitmap(mBitmap, Utils.getRotatedAngle(imageOrientation));

      mAspectX = extras.getInt(HikeConstants.Extras.ASPECT_X);
      mAspectY = extras.getInt(HikeConstants.Extras.ASPECT_Y);
      mOutputX = extras.getInt(HikeConstants.Extras.OUTPUT_X);
      mOutputY = extras.getInt(HikeConstants.Extras.OUTPUT_Y);
      mScale = extras.getBoolean(HikeConstants.Extras.SCALE, true);
      mScaleUp = extras.getBoolean(HikeConstants.Extras.SCALE_UP, true);
    }

    if (mBitmap == null) {
      Toast toast =
          Toast.makeText(this, getResources().getString(R.string.image_failed), Toast.LENGTH_LONG);
      toast.show();
      Logger.d(TAG, "Unable to open bitmap");
      finish();
      return;
    }

    // Make UI fullscreen.
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

    findViewById(R.id.rotateLeft)
        .setOnClickListener(
            new View.OnClickListener() {
              public void onClick(View v) {
                mBitmap = Util.rotateImage(mBitmap, -90);
                RotateBitmap rotateBitmap = new RotateBitmap(mBitmap);
                mImageView.setImageRotateBitmapResetBase(rotateBitmap, true);
                mRunFaceDetection.run();
              }
            });

    setupActionBar();

    startFaceDetection();
  }