예제 #1
0
 private static File pickedGalleryPicture(Context context, Uri photoPath) throws IOException {
   InputStream pictureInputStream = context.getContentResolver().openInputStream(photoPath);
   File directory = EasyImage.tempImageDirectory(context);
   File photoFile = new File(directory, UUID.randomUUID().toString());
   photoFile.createNewFile();
   EasyImage.writeToFile(pictureInputStream, photoFile);
   return photoFile;
 }
예제 #2
0
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (resultCode == RESULT_OK && requestCode == ACTION_REQUEST_NEW_PRINTER) {

      //            /** CLEAR THE ARRAYLIST AND REFRESH THE LIST OF PRINTERS **/
      //            arrPrinters.clear();
      //            new fetchPrintersList().execute();

    } else if (resultCode == RESULT_OK) {
      EasyImage.handleActivityResult(
          requestCode,
          resultCode,
          data,
          OldCategoryCreator.this,
          new DefaultCallback() {

            @Override
            public void onImagePicked(File imageFile, EasyImage.ImageSource source) {
              super.onImagePicked(imageFile, source);
              onPhotoReturned(imageFile);
            }

            @Override
            public void onImagePickerError(Exception e, EasyImage.ImageSource source) {
              super.onImagePickerError(e, source);
            }

            @Override
            public void onCanceled(EasyImage.ImageSource source) {
              super.onCanceled(source);
            }
          });
    }
  }
예제 #3
0
 private static void onPictureReturnedFromCamera(Activity activity, Callbacks callbacks) {
   try {
     File photoFile = EasyImage.takenCameraPicture(activity);
     callbacks.onImagePicked(photoFile, ImageSource.CAMERA);
   } catch (Exception e) {
     callbacks.onImagePickerError(e, ImageSource.CAMERA);
   }
 }
예제 #4
0
 private static void onPictureReturnedFromGallery(
     Intent data, Activity activity, Callbacks callbacks) {
   try {
     Uri photoPath = data.getData();
     File photoFile = EasyImage.pickedGalleryPicture(activity, photoPath);
     callbacks.onImagePicked(photoFile, ImageSource.GALLERY);
   } catch (Exception e) {
     e.printStackTrace();
     callbacks.onImagePickerError(e, ImageSource.GALLERY);
   }
 }
예제 #5
0
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    EasyImage.handleActivityResult(
        requestCode,
        resultCode,
        data,
        this,
        new EasyImage.Callbacks() {
          @Override
          public void onImagePickerError(Exception e, EasyImage.ImageSource imageSource, int i) {
            showToast("出错啦,请重新试试");
          }

          @Override
          public void onImagePicked(File file, EasyImage.ImageSource imageSource, int i) {
            UCrop.of(Uri.fromFile(file), Uri.fromFile(file))
                .withMaxResultSize(800, 800)
                .start(AddSouvenirActivity.this);
          }

          @Override
          public void onCanceled(EasyImage.ImageSource imageSource, int i) {
            if (imageSource == EasyImage.ImageSource.CAMERA) {
              File photoFile = EasyImage.lastlyTakenButCanceledPhoto(AddSouvenirActivity.this);
              if (photoFile != null) {
                photoFile.delete();
              }
            }
          }
        });
    if (resultCode == RESULT_OK && requestCode == UCrop.REQUEST_CROP) {
      try {
        imgfile = new File(new URI(UCrop.getOutput(data).toString()));
      } catch (URISyntaxException e) {
        e.printStackTrace();
      }
      Glide.with(this).load(imgfile).into(ivAlbum);
    } else if (resultCode == UCrop.RESULT_ERROR) {
      showToast("出错啦,请稍后再试");
      Throwable throwable = UCrop.getError(data);
      if (throwable != null) {
        Logger.e(throwable.getMessage());
      }
    }
  }
예제 #6
0
  @Override
  protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode == RESULT_OK && requestCode == ACTION_REQUEST_NEW_CATEGORY) {

      /** CLEAR THE ARRAYLIST AND REFRESH THE SPINNER CATEGORIES DATA * */
      arrCategory.clear();
      new fetchMenuCategories().execute();

    } else if (resultCode == RESULT_OK) {
      EasyImage.handleActivityResult(
          requestCode,
          resultCode,
          data,
          this,
          new DefaultCallback() {

            @Override
            public void onImagePicked(File imageFile, EasyImage.ImageSource source) {
              super.onImagePicked(imageFile, source);
              onPhotoReturned(imageFile);
              //                Log.e("DATA", String.valueOf(data));

              if (source == EasyImage.ImageSource.CAMERA) {
                imgSource = 1;
              } else {
                imgSource = 2;
              }
            }

            @Override
            public void onImagePickerError(Exception e, EasyImage.ImageSource source) {
              super.onImagePickerError(e, source);
            }

            @Override
            public void onCanceled(EasyImage.ImageSource source) {
              super.onCanceled(source);
            }
          });
    }
  }