Example #1
0
  /**
   * Control the size of the photo chosen from the gallery or snapped fresh from the camera!
   *
   * <p>If the photo is bigger than some threshold then reduce the size!
   *
   * @param uri
   */
  private void preProcessPhoto(final Uri uri) {
    startProgressDialog();
    ThreadWrapper.executeInWorkerThread(
        new Task() {
          @Override
          public void execute() {

            final Message msg = new Message();
            try {
              int retries = 0;
              while (true) {
                try {
                  if (retries == 5) {
                    throw new Exception("Cannot read photo. Please try again..");
                  }
                  preProcessPhotoRetryable(uri);
                  break;
                } catch (final Exception e) {
                  retries++;
                  Thread.sleep(750);
                }
              }
            } catch (final Exception e) {
              msg.what = EVENT_SEL_PHOTO_ERROR;
              msg.obj = e.getMessage() + "";
              MLog.i(TAG, "PhotoChoosingActivity.preProcessPhoto() failed", e);
              _photoSelectionHandler.sendMessage(msg);
            }
          }
        });
  }
Example #2
0
  @Override
  public void onCreate(final Bundle savedInstanceState) {

    MLog.i(TAG, "PhotoChoosingActivity.onCreate()");
    super.onCreate(savedInstanceState);

    ThreadWrapper.executeInWorkerThread(
        new Task() {
          @Override
          public void execute() {
            TEMP_PIC_PATH_ON_DISK = CacheUtils.getExternalCacheDir(_this).getPath() + "/photo.jpg";
            TEMP_THUMB_PATH_ON_DISK =
                CacheUtils.getExternalCacheDir(_this).getPath() + "/thumb.jpg";
            _thumbFile = new File(TEMP_THUMB_PATH_ON_DISK);
            _picFile = new File(TEMP_PIC_PATH_ON_DISK);
          }
        });
  }
Example #3
0
  /** Should be called after preprocessPhoto */
  private void postProcessPhoto() {

    startProgressDialog();
    ThreadWrapper.executeInWorkerThread(
        new Task() {
          @Override
          public void execute() {
            final Message msg = new Message();
            try {

              createFinalPic();

            } catch (final Exception e) {
              MLog.e(TAG, "Error in processing photo: ", e);
              msg.arg1 = EVENT_PHOTO_PROC_ERROR;
              msg.obj = "" + e.getMessage();
            }
            _photoDoneHandler.sendMessage(msg);
          }
        });
  }