From 81ff73433136c82f1b391a6a276309644a995355 Mon Sep 17 00:00:00 2001 From: FirstWithThisName Date: Thu, 22 Feb 2024 15:18:17 +0100 Subject: [PATCH] Migrated to android-image-cropper version 4.5.0 --- app/build.gradle | 2 +- app/src/main/AndroidManifest.xml | 2 +- .../com/easyfitness/CustomDrawerAdapter.java | 5 +- .../java/com/easyfitness/MainActivity.java | 5 +- .../java/com/easyfitness/ProfileFragment.java | 57 +++------ .../easyfitness/ProgressImagesFragment.java | 78 ++++-------- .../machines/MachineDetailsFragment.java | 105 +++-------------- .../java/com/easyfitness/utils/ImageUtil.java | 111 +++++++++--------- 8 files changed, 115 insertions(+), 250 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index a3cff004..238a53e7 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -100,6 +100,6 @@ dependencies { implementation 'com.mikhaellopez:circularimageview:3.2.0' implementation 'com.github.f0ris.sweetalert:library:1.6.2' implementation 'com.github.onurkagan:ktoast:1.0.3' - implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0' + implementation 'com.vanniktech:android-image-cropper:4.5.0' implementation 'com.github.ivbaranov:materialfavoritebutton:0.1.5' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index bbeeac46..b9547d24 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -44,7 +44,7 @@ android:name=".intro.MainIntroActivity" android:theme="@style/Theme.Intro" /> arg0) { //drawerHolder.icon.setImageDrawable(view.getResources().getDrawable(dItem.getImgResID())); - ImageUtil imgUtil = new ImageUtil(); // Check if path is pointing to a thumb else create it and use it. - String thumbPath = imgUtil.getThumbPath(dItem.getImg()); + String thumbPath = ImageUtil.getThumbPath(dItem.getImg()); if (thumbPath != null) ImageUtil.setPic(drawerHolder.roundProfile, thumbPath); else diff --git a/app/src/main/java/com/easyfitness/MainActivity.java b/app/src/main/java/com/easyfitness/MainActivity.java index a6251279..de89c858 100644 --- a/app/src/main/java/com/easyfitness/MainActivity.java +++ b/app/src/main/java/com/easyfitness/MainActivity.java @@ -32,6 +32,7 @@ import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; import androidx.drawerlayout.widget.DrawerLayout; +import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentTransaction; import androidx.lifecycle.ViewModelProvider; @@ -883,10 +884,8 @@ public void setCurrentProfile(Profile newProfil) { } private void setPhotoProfile(String path) { - ImageUtil imgUtil = new ImageUtil(); - // Check if path is pointing to a thumb else create it and use it. - String thumbPath = imgUtil.getThumbPath(path); + String thumbPath = ImageUtil.getThumbPath(path); boolean success = false; if (thumbPath != null) { success = ImageUtil.setPic(roundProfile, thumbPath); diff --git a/app/src/main/java/com/easyfitness/ProfileFragment.java b/app/src/main/java/com/easyfitness/ProfileFragment.java index cea4dd9e..0709088c 100644 --- a/app/src/main/java/com/easyfitness/ProfileFragment.java +++ b/app/src/main/java/com/easyfitness/ProfileFragment.java @@ -56,7 +56,7 @@ public class ProfileFragment extends Fragment { private DAOBodyMeasure daoBodyMeasure = null; private DAOBodyPart daoBodyPart = null; private ImageUtil imgUtil = null; - private final OnClickListener onClickMachinePhoto = v -> CreatePhotoSourceDialog(); + private final OnClickListener onClickMachinePhoto = v -> imgUtil.createPhotoSourceDialog(); private AppViMo appViMo; private ProfileViMo profileViMo; private final OnClickListener mOnClickListener = view -> { @@ -123,11 +123,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, /* Initialisation des valeurs */ - imgUtil = new ImageUtil(roundProfile); + imgUtil = new ImageUtil(this, roundProfile); // ImageView must be set in OnStart. Not in OnCreateView - /* Initialisation des boutons */ - genderEdit.setCustomDialogBuilder(view1 -> { SweetAlertDialog dlg = new SweetAlertDialog(view1.getContext(), SweetAlertDialog.NORMAL_TYPE) .setTitleText(getContext().getString(R.string.edit_value)) @@ -190,6 +188,18 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, requestForSave(); }); + imgUtil.setOnPicTakenListener(uriFilePath -> { + File storageDir = getActivity().getExternalFilesDir(Environment.DIRECTORY_PICTURES); + try { + File newFile = ImageUtil.moveFile(new File(uriFilePath), storageDir, "newfile.jpg"); + ImageUtil.saveThumb(newFile.getAbsolutePath()); + profileViMo.setPhoto(newFile.getAbsolutePath()); + requestForSave(); + } catch (Exception e) { + e.printStackTrace(); + } + }); + profileViMo = new ViewModelProvider(this).get(ProfileViMo.class); profileViMo.getBirthday().observe(getViewLifecycleOwner(), birthday -> { if (birthday.getTime() == 0) { @@ -307,43 +317,4 @@ private void requestForSave() { isSaving = false; } - - public Fragment getFragment() { - return this; - } - - private boolean CreatePhotoSourceDialog() { - if (imgUtil == null) - imgUtil = new ImageUtil(); - - return imgUtil.CreatePhotoSourceDialog(this); - } - - public void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - - switch (requestCode) { - case ImageUtil.REQUEST_TAKE_PHOTO: - if (resultCode == Activity.RESULT_OK) { - profileViMo.setPhoto(imgUtil.getFilePath()); - requestForSave(); - imgUtil.saveThumb(imgUtil.getFilePath()); - } - break; - case ImageUtil.REQUEST_PICK_GALERY_PHOTO: - if (resultCode == Activity.RESULT_OK) { - File storageDir = getActivity().getExternalFilesDir(Environment.DIRECTORY_PICTURES); - Uri selectedImageUri = data.getData(); - try { - File newFile = imgUtil.copyFileFromUri(getContext(), selectedImageUri, storageDir, "newfile.jpg"); - imgUtil.saveThumb(newFile.getAbsolutePath()); - profileViMo.setPhoto(newFile.getAbsolutePath()); - requestForSave(); - } catch (Exception e) { - e.printStackTrace(); - } - } - break; - } - } } diff --git a/app/src/main/java/com/easyfitness/ProgressImagesFragment.java b/app/src/main/java/com/easyfitness/ProgressImagesFragment.java index 1366e5f9..8ce83eab 100644 --- a/app/src/main/java/com/easyfitness/ProgressImagesFragment.java +++ b/app/src/main/java/com/easyfitness/ProgressImagesFragment.java @@ -1,8 +1,5 @@ package com.easyfitness; -import android.app.Activity; -import android.content.Intent; -import android.net.Uri; import android.os.Bundle; import android.os.Environment; import android.view.LayoutInflater; @@ -43,7 +40,7 @@ public class ProgressImagesFragment extends Fragment { private int imageCount = 0; - private final View.OnClickListener onClickAddProgressImage = v -> createPhotoSourceDialog(); + private final View.OnClickListener onClickAddProgressImage = v -> imgUtil.createPhotoSourceDialog(); /** @@ -62,17 +59,6 @@ public static ProgressImagesFragment newInstance(String name, int id) { return f; } - private boolean createPhotoSourceDialog() { - if (imgUtil == null) { - imgUtil = new ImageUtil(); - imgUtil.setOnDeleteImageListener(u -> { - deleteCurrentImage(); - }); - } - - return imgUtil.CreatePhotoSourceDialog(this); - } - @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @@ -91,6 +77,27 @@ public View onCreateView(@NonNull LayoutInflater inflater, olderImageButton.setOnClickListener(v -> showOlderImage()); photoButton.setOnClickListener(onClickAddProgressImage); + imgUtil = new ImageUtil(this); + imgUtil.setOnDeleteImageListener(u -> { + deleteCurrentImage(); + }); + imgUtil.setOnPicTakenListener(uriFilePath -> { + File storageDir = getActivity().getExternalFilesDir(Environment.DIRECTORY_PICTURES); + try { + File newFile = ImageUtil.moveFile(new File(uriFilePath), storageDir, generateFileName()); + daoProgressImage.addProgressImage( + new Date(System.currentTimeMillis()), // maybe user input + newFile, + appViMo.getProfile().getValue().getId() + ); + imageOffset = 0; + showProgressImage(); + updateImageNavigation(); + } catch (Exception e) { + e.printStackTrace(); + } + }); + updateImageNavigation(); return view; } @@ -99,7 +106,7 @@ private void deleteCurrentImage() { daoProgressImage.deleteImage(image.getId()); new File(image.getFile()).delete(); - imageOffset = imageOffset >= (imageCount-1)? imageOffset-1 : imageOffset; + imageOffset = imageOffset >= (imageCount - 1) ? imageOffset - 1 : imageOffset; updateImageNavigation(); } @@ -116,7 +123,7 @@ private void showNewerImage() { private void updateImageNavigation() { showProgressImage(); imageCount = daoProgressImage.count(appViMo.getProfile().getValue().getId()); - progressImageIndex.setText((imageOffset+1) + " / " + imageCount); + progressImageIndex.setText((imageOffset + 1) + " / " + imageCount); if (image != null) { progressImageDate.setText( DateConverter.dateToLocalDateStr(image.getCreated(), getContext()) @@ -124,7 +131,7 @@ private void updateImageNavigation() { } else { progressImageDate.setText(DateConverter.currentDate(getContext())); } - if ((imageOffset+1) >= imageCount) { + if ((imageOffset + 1) >= imageCount) { olderImageButton.setEnabled(false); } else { olderImageButton.setEnabled(true); @@ -152,39 +159,4 @@ private String generateFileName() { // TODO hard coded ending ? return String.format("%10d.jpg", System.currentTimeMillis() / 1000); } - - public void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - - switch (requestCode) { - case ImageUtil.REQUEST_TAKE_PHOTO: - if (resultCode == Activity.RESULT_OK) { - daoProgressImage.addProgressImage( - new Date(System.currentTimeMillis()), // maybe user input - new File(imgUtil.getFilePath()), - appViMo.getProfile().getValue().getId() - ); - } - break; - case ImageUtil.REQUEST_PICK_GALERY_PHOTO: - if (resultCode == Activity.RESULT_OK) { - File storageDir = getActivity().getExternalFilesDir(Environment.DIRECTORY_PICTURES); - Uri selectedImageUri = data.getData(); - try { - File newFile = imgUtil.copyFileFromUri(getContext(), selectedImageUri, storageDir, generateFileName()); - daoProgressImage.addProgressImage( - new Date(System.currentTimeMillis()), // maybe user input - newFile, - appViMo.getProfile().getValue().getId() - ); - } catch (Exception e) { - e.printStackTrace(); - } - } - break; - } - imageOffset = 0; - showProgressImage(); - updateImageNavigation(); - } } diff --git a/app/src/main/java/com/easyfitness/machines/MachineDetailsFragment.java b/app/src/main/java/com/easyfitness/machines/MachineDetailsFragment.java index 37016da6..5fd3dbfb 100644 --- a/app/src/main/java/com/easyfitness/machines/MachineDetailsFragment.java +++ b/app/src/main/java/com/easyfitness/machines/MachineDetailsFragment.java @@ -4,12 +4,9 @@ import android.app.AlertDialog; import android.content.Intent; import android.graphics.BitmapFactory; -import android.net.Uri; import android.os.Bundle; -import android.os.Environment; import android.text.Editable; import android.text.TextWatcher; -import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; @@ -25,6 +22,7 @@ import androidx.fragment.app.Fragment; +import com.canhub.cropper.CropImage; import com.easyfitness.DAO.DAOMachine; import com.easyfitness.DAO.DAOProfile; import com.easyfitness.DAO.Machine; @@ -40,14 +38,10 @@ import com.easyfitness.views.EditableInputView; import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.onurkaganaldemir.ktoastlib.KToast; -import com.theartofdev.edmodo.cropper.CropImage; import java.io.File; -import java.io.IOException; -import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collections; -import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -74,8 +68,11 @@ public class MachineDetailsFragment extends Fragment { View fragmentView = null; ImageUtil imgUtil = null; - private final OnLongClickListener onLongClickMachinePhoto = v -> CreatePhotoSourceDialog(); - private final OnClickListener onClickMachinePhoto = v -> CreatePhotoSourceDialog(); + private final OnLongClickListener onLongClickMachinePhoto = v -> { + imgUtil.createPhotoSourceDialog(); + return true; + }; + private final OnClickListener onClickMachinePhoto = v -> imgUtil.createPhotoSourceDialog(); boolean isCreateMuscleDialogActive = false; private final OnClickListener onClickMusclesList = v -> CreateMuscleDialog(); private final OnFocusChangeListener onFocusMachineList = (arg0, arg1) -> { @@ -137,7 +134,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa machinePhotoLayout = view.findViewById(R.id.machine_photo_layout); machineAction = view.findViewById(R.id.actionCamera); - imgUtil = new ImageUtil(machinePhoto); + imgUtil = new ImageUtil(this, machinePhoto); Bundle args = this.getArguments(); @@ -245,6 +242,13 @@ public void onGlobalLayout() { requestForSave(); }); + imgUtil.setOnPicTakenListener(uriFilePath -> { + ImageUtil.setPic(machinePhoto, uriFilePath); + ImageUtil.saveThumb(uriFilePath); + mCurrentPhotoPath = uriFilePath; + requestForSave(); + }); + if (getParentFragment() instanceof ExerciseDetailsPager) { pager = (ExerciseDetailsPager) getParentFragment(); } @@ -275,7 +279,7 @@ private List sortedSelectedMuscles() { } }}; Collections.sort(selectedMuscleNames); - return selectedMuscleNames; + return selectedMuscleNames; } private boolean CreateMuscleDialog() { @@ -339,89 +343,10 @@ private void registerNegativeButtonFor(AlertDialog.Builder muscleSelectionDialog muscleSelectionDialog.setNegativeButton(getResources().getString(android.R.string.cancel), (dialog, whichButton) -> isCreateMuscleDialogActive = false); } - private boolean CreatePhotoSourceDialog() { - if (imgUtil == null) - imgUtil = new ImageUtil(); - - return imgUtil.CreatePhotoSourceDialog(this); - } - - public void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - - switch (requestCode) { - case ImageUtil.REQUEST_TAKE_PHOTO: - if (resultCode == Activity.RESULT_OK) { - mCurrentPhotoPath = imgUtil.getFilePath(); - ImageUtil.setPic(machinePhoto, mCurrentPhotoPath); - ImageUtil.saveThumb(mCurrentPhotoPath); - imgUtil.galleryAddPic(this, mCurrentPhotoPath); - requestForSave(); - } - break; - case ImageUtil.REQUEST_PICK_GALERY_PHOTO: - if (resultCode == Activity.RESULT_OK) { - String realPath = RealPathUtil.getRealPath(this.getContext(), data.getData()); - - ImageUtil.setPic(machinePhoto, realPath); - ImageUtil.saveThumb(realPath); - mCurrentPhotoPath = realPath; - requestForSave(); - } - break; - case CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE: - CropImage.ActivityResult result = CropImage.getActivityResult(data); - if (resultCode == Activity.RESULT_OK) { - Uri resultUri = result.getUri(); - String realPath = RealPathUtil.getRealPath(this.getContext(), resultUri); - - // Le fichier est crée dans le cache. - // Déplacer le fichier dans le repertoire de FastNFitness - File SourceFile = new File(realPath); - - File storageDir = null; - String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); - String imageFileName = "JPEG_" + timeStamp + ".jpg"; - String state = Environment.getExternalStorageState(); - if (!Environment.MEDIA_MOUNTED.equals(state)) { - return; - } else { - //We use the FastNFitness directory for saving our .csv file. - storageDir = Environment.getExternalStoragePublicDirectory("/FastnFitness/Camera/"); - if (!storageDir.exists()) { - storageDir.mkdirs(); - } - } - File DestinationFile = null; - - try { - DestinationFile = imgUtil.moveFile(SourceFile, storageDir); - Log.v("Moving", "Moving file successful."); - realPath = DestinationFile.getPath(); - } catch (IOException e) { - e.printStackTrace(); - Log.e("Moving", "Moving file failed."); - } - - ImageUtil.setPic(machinePhoto, realPath); - ImageUtil.saveThumb(realPath); - mCurrentPhotoPath = realPath; - requestForSave(); - } else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) { - Exception error = result.getError(); - } - break; - } - } - public void setMuscleText(String t) { musclesList.setText(t); } - public MachineDetailsFragment getThis() { - return this; - } - public void requestForSave() { saveMachine(); } diff --git a/app/src/main/java/com/easyfitness/utils/ImageUtil.java b/app/src/main/java/com/easyfitness/utils/ImageUtil.java index 0552475e..b3ac7dce 100644 --- a/app/src/main/java/com/easyfitness/utils/ImageUtil.java +++ b/app/src/main/java/com/easyfitness/utils/ImageUtil.java @@ -15,19 +15,18 @@ import android.os.Environment; import android.provider.MediaStore; import android.util.Log; -import android.view.Gravity; import android.widget.ImageView; -import android.widget.ImageView.ScaleType; import android.widget.ListView; +import androidx.activity.result.ActivityResultLauncher; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; -import androidx.core.content.FileProvider; import androidx.fragment.app.Fragment; -import com.easyfitness.BuildConfig; +import com.canhub.cropper.CropImageContract; +import com.canhub.cropper.CropImageContractOptions; +import com.canhub.cropper.CropImageOptions; import com.easyfitness.R; -import com.onurkaganaldemir.ktoastlib.KToast; import java.io.File; import java.io.FileInputStream; @@ -37,11 +36,8 @@ import java.io.InputStream; import java.io.OutputStream; import java.nio.channels.FileChannel; -import java.nio.channels.WritableByteChannel; -import java.nio.file.Files; import java.text.SimpleDateFormat; import java.util.Date; -import java.util.zip.ZipOutputStream; public class ImageUtil { @@ -50,14 +46,28 @@ public class ImageUtil { public static final int REQUEST_DELETE_IMAGE = 3; private String mFilePath = null; private ImageView imgView = null; + private Fragment fragment = null; private ImageUtil.OnDeleteImageListener mDeleteImageListener; + private OnPictureTakenListener mPicTakenListener; private static final String THUMB_PATH = "/thumb/"; - - public ImageUtil() { + private ActivityResultLauncher cropImage; + + public ImageUtil(Fragment fragment) { + this.fragment = fragment; + cropImage = fragment.registerForActivityResult(new CropImageContract(), (result -> { + if (result.isSuccessful()) { + if (mPicTakenListener != null) { + mPicTakenListener.onPictureTaken(result.getUriFilePath(fragment.getContext(), true)); + } + } else { + Log.e(getClass().getName(), "Failed to get an image", result.getError()); + } + })); } - public ImageUtil(ImageView view) { + public ImageUtil(Fragment fragment, ImageView view) { + this(fragment); imgView = view; } @@ -71,7 +81,7 @@ static public String saveThumb(String pPath) { // Determine how much to scale down the image float scaleFactor = 1; - if (photoH!=0) { + if (photoH != 0) { scaleFactor = photoW / photoH; //Math.min(photoW/targetW, photoH/targetH); } @@ -123,7 +133,7 @@ static public boolean setPic(ImageView mImageView, String pPath) { // Determine how much to scale down the image int scaleFactor = 1; - if (targetW!=0) { + if (targetW != 0) { scaleFactor = photoW / targetW; //Math.min(photoW/targetW, photoH/targetH); } @@ -142,7 +152,7 @@ static public boolean setPic(ImageView mImageView, String pPath) { } public static void copyFileToStream(File internalFile, OutputStream zipFile) { - try (InputStream inputStream = new FileInputStream(internalFile)) { + try (InputStream inputStream = new FileInputStream(internalFile)) { copyStream(inputStream, zipFile); } catch (FileNotFoundException e) { throw new RuntimeException(e); @@ -190,7 +200,7 @@ public static String getThumbPath(String pPath) { return pathOfThumbImage; } } - }catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); return null; } @@ -204,7 +214,11 @@ public void setOnDeleteImageListener(ImageUtil.OnDeleteImageListener listener) { mDeleteImageListener = listener; } - public boolean CreatePhotoSourceDialog(Fragment fragment) { + public void setOnPicTakenListener(OnPictureTakenListener mPicTakenListner) { + this.mPicTakenListener = mPicTakenListner; + } + + public void createPhotoSourceDialog() { String[] optionListArray = new String[3]; optionListArray[0] = fragment.getResources().getString(R.string.camera); optionListArray[1] = fragment.getResources().getString(R.string.gallery); @@ -219,13 +233,19 @@ public boolean CreatePhotoSourceDialog(Fragment fragment) { switch (which) { // Camera case 0: - - dispatchTakePictureIntent(fragment); + CropImageOptions cameraOptions = new CropImageOptions(); + cameraOptions.imageSourceIncludeGallery = false; + cameraOptions.imageSourceIncludeCamera = true; + CropImageContractOptions camOptions = new CropImageContractOptions(null, cameraOptions); + cropImage.launch(camOptions); break; // Galery case 1: - getGaleryPict(fragment); - + CropImageOptions galeryOptions = new CropImageOptions(); + galeryOptions.imageSourceIncludeGallery = true; + galeryOptions.imageSourceIncludeCamera = false; + CropImageContractOptions galOptions = new CropImageContractOptions(null, galeryOptions); + cropImage.launch(galOptions); break; case 2: // Delete picture if (mDeleteImageListener != null) @@ -236,31 +256,6 @@ public boolean CreatePhotoSourceDialog(Fragment fragment) { } }); itemActionBuilder.show(); - - return true; - } - - private void dispatchTakePictureIntent(Fragment fragment) { - Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); - // Ensure that there's a camera activity to handle the intent - if (takePictureIntent.resolveActivity(fragment.getActivity().getPackageManager()) != null) { - // Create the File where the photo should go - File photo = null; - try { - photo = createImageFile(fragment); - mFilePath = photo.getAbsolutePath(); - } catch (IOException ex) { - KToast.errorToast(fragment.getActivity(), "error", Gravity.BOTTOM, KToast.LENGTH_LONG); - } - // Continue only if the File was successfully created - if (photo != null) { - Uri photoURI = FileProvider.getUriForFile(fragment.getContext(), - BuildConfig.APPLICATION_ID + ".fileprovider", - photo); - takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI); - fragment.startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO); - } - } } private File createImageFile(Fragment fragment) throws IOException { @@ -275,6 +270,7 @@ private File createImageFile(Fragment fragment) throws IOException { ); return image; } + private Uri createMediaStoreImage(Fragment fragment) throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); @@ -363,8 +359,7 @@ static public File copyFile(File file, File dir, String newFileName, boolean mov static public File copyFileFromStream(InputStream inputStream, File destFolder, String newFileName) { File newFile = null; - try - { + try { // create directory if it doesn't exists destFolder.mkdirs(); @@ -374,8 +369,8 @@ static public File copyFileFromStream(InputStream inputStream, File destFolder, copyStream(inputStream, outputStream); } - } catch ( Exception e ){ - Log.e( "TAG", "Exception occurred " + e.getMessage()); + } catch (Exception e) { + Log.e("TAG", "Exception occurred " + e.getMessage()); } return newFile; } @@ -389,20 +384,18 @@ private static void copyStream(InputStream in, OutputStream out) throws IOExcept } } - static public File copyFileFromUri(Context context, Uri fileUri, File destFolder, String newFileName) - { + static public File copyFileFromUri(Context context, Uri fileUri, File destFolder, String newFileName) { FileInputStream inputStream = null; File newFile = null; - try - { + try { ContentResolver content = context.getContentResolver(); - inputStream = (FileInputStream) content.openInputStream(fileUri); + inputStream = (FileInputStream) content.openInputStream(fileUri); newFile = copyFileFromStream(inputStream, destFolder, newFileName); - } catch ( Exception e ){ - Log.e( "TAG", "Exception occurred " + e.getMessage()); - } finally{ + } catch (Exception e) { + Log.e("TAG", "Exception occurred " + e.getMessage()); + } finally { } return newFile; @@ -411,4 +404,8 @@ static public File copyFileFromUri(Context context, Uri fileUri, File destFolder public interface OnDeleteImageListener { void onDeleteImage(ImageUtil imgUtil); } + + public interface OnPictureTakenListener { + void onPictureTaken(String uriFilePath); + } }