|
|
@ -5,6 +5,7 @@ import android.app.AlertDialog; |
|
|
|
import android.content.Intent; |
|
|
|
import android.content.pm.PackageManager; |
|
|
|
import android.graphics.Bitmap; |
|
|
|
import android.graphics.BitmapFactory; |
|
|
|
import android.net.Uri; |
|
|
|
import android.os.Build; |
|
|
|
import android.os.Bundle; |
|
|
@ -28,8 +29,6 @@ import com.gmeremit.online.gmeremittance_native.R; |
|
|
|
import com.gmeremit.online.gmeremittance_native.base.BaseFragment; |
|
|
|
import com.gmeremit.online.gmeremittance_native.kycV2.KYCV2ActionListener; |
|
|
|
import com.gmeremit.online.gmeremittance_native.kycV2.presenter.KYCV2PresenterInterface; |
|
|
|
import com.gmeremit.online.gmeremittance_native.kycV2.view.KYCFormV2Activity; |
|
|
|
import com.gmeremit.online.gmeremittance_native.user_profile.view.ProfileActivity; |
|
|
|
import com.gmeremit.online.gmeremittance_native.utils.other.DisplayUtils; |
|
|
|
import com.gmeremit.online.gmeremittance_native.utils.other.Utility; |
|
|
|
import com.yalantis.ucrop.UCrop; |
|
|
@ -39,13 +38,13 @@ import java.io.File; |
|
|
|
import java.io.FileNotFoundException; |
|
|
|
import java.io.FileOutputStream; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.OutputStream; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.Date; |
|
|
|
|
|
|
|
import butterknife.BindView; |
|
|
|
import butterknife.ButterKnife; |
|
|
|
import butterknife.OnClick; |
|
|
|
import io.reactivex.Observable; |
|
|
|
import io.reactivex.disposables.CompositeDisposable; |
|
|
|
|
|
|
|
import static android.app.Activity.RESULT_OK; |
|
|
@ -68,6 +67,7 @@ public class KYCView3Fragment extends BaseFragment implements View.OnClickListen |
|
|
|
public static final int REQUEST_PERMISSION_BACK = 2002; |
|
|
|
public static final int REQUEST_PERMISSION_PASSBOOK = 2003; |
|
|
|
public static final int REQUEST_PERMISSION_PASSPORT = 2004; |
|
|
|
private static final int COMPRESS_QUALITY = 60; |
|
|
|
|
|
|
|
@BindView(R.id.iv_selfie_image) |
|
|
|
ImageView selfieImage; |
|
|
@ -92,6 +92,7 @@ public class KYCView3Fragment extends BaseFragment implements View.OnClickListen |
|
|
|
CompositeDisposable compositeDisposable = null; |
|
|
|
private Uri photoURI=null; |
|
|
|
private Uri croppedFileUri=null; |
|
|
|
private File photoFile; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@ -150,7 +151,7 @@ public class KYCView3Fragment extends BaseFragment implements View.OnClickListen |
|
|
|
private void takeAPictureV2(int requestCode) { |
|
|
|
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); |
|
|
|
if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) { |
|
|
|
File photoFile = null; |
|
|
|
photoFile = null; |
|
|
|
try { |
|
|
|
photoFile = createImageFile(); |
|
|
|
} catch (IOException ex) { |
|
|
@ -183,6 +184,13 @@ public class KYCView3Fragment extends BaseFragment implements View.OnClickListen |
|
|
|
return image; |
|
|
|
} |
|
|
|
|
|
|
|
private File createImageFileInCache(String destinationFileName) throws IOException |
|
|
|
{ |
|
|
|
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); |
|
|
|
String imageFileName = "JPEG_" + timeStamp + "_"; |
|
|
|
return new File(getActivity().getCacheDir(), destinationFileName+imageFileName); |
|
|
|
} |
|
|
|
|
|
|
|
private void galleryIntent(int requestCode) { |
|
|
|
Intent intent = new Intent(); |
|
|
|
intent.setType("image/*"); |
|
|
@ -349,14 +357,18 @@ public class KYCView3Fragment extends BaseFragment implements View.OnClickListen |
|
|
|
requestCode == PASSPORTREQ_CAMERA) { |
|
|
|
|
|
|
|
//TODO uri is available from camera |
|
|
|
requestToCropImage(); |
|
|
|
} |
|
|
|
// requestToCropImage(); |
|
|
|
Bitmap compressedBitmap=createBitmapThumbnailFromUri(photoURI); |
|
|
|
saveBitmapToFile(photoURI); |
|
|
|
Log.d("IMAGE_FILE","Original size: "+photoFile.length()/1000000); |
|
|
|
|
|
|
|
frontRegIdImage.setImageBitmap(compressedBitmap); |
|
|
|
} |
|
|
|
else if(requestCode== UCrop.REQUEST_CROP) |
|
|
|
{ |
|
|
|
if(resultCode==RESULT_OK){ |
|
|
|
//TODO create a thumbnail maintaining current aspect ratio and save the uri for later sending to server |
|
|
|
frontRegIdImage.setImageBitmap(createBitmapFromUri(croppedFileUri)); |
|
|
|
|
|
|
|
frontRegIdImage.setImageBitmap(createBitmapThumbnailFromUri(croppedFileUri)); |
|
|
|
} |
|
|
|
else |
|
|
|
Log.d("IMAGE_FILE", UCrop.getError(data).getMessage()); |
|
|
@ -367,8 +379,6 @@ public class KYCView3Fragment extends BaseFragment implements View.OnClickListen |
|
|
|
requestToCropImage(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (NullPointerException ex) { |
|
|
|
ex.printStackTrace(); |
|
|
|
Log.d("IMAGE_FILE", ex.getMessage()); |
|
|
@ -376,15 +386,34 @@ public class KYCView3Fragment extends BaseFragment implements View.OnClickListen |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void saveBitmapToFile(Uri data) { |
|
|
|
try { |
|
|
|
OutputStream fOut ; |
|
|
|
File compressedBitmapFile=createImageFile(); |
|
|
|
fOut = new FileOutputStream(compressedBitmapFile); |
|
|
|
Bitmap pictureBitmap = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), data); |
|
|
|
|
|
|
|
pictureBitmap.compress(Bitmap.CompressFormat.JPEG, COMPRESS_QUALITY, fOut); // saving the Bitmap to a file compressed as a JPEG with 85% compression rate |
|
|
|
fOut.flush(); // |
|
|
|
fOut.close(); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void requestToCropImage() |
|
|
|
{ |
|
|
|
try { |
|
|
|
|
|
|
|
croppedFileUri=Uri.fromFile(createImageFile()); |
|
|
|
UCrop cropper= UCrop.of(photoURI, croppedFileUri) |
|
|
|
.withAspectRatio(16, 9) |
|
|
|
.withMaxResultSize(400, 400); |
|
|
|
UCrop.Options options=new UCrop.Options(); |
|
|
|
options.setCompressionQuality(40); |
|
|
|
options.setMaxBitmapSize(800); |
|
|
|
UCrop cropper= UCrop.of(photoURI, croppedFileUri) |
|
|
|
.withAspectRatio(1, 1) |
|
|
|
.withOptions(options); |
|
|
|
|
|
|
|
cropper= DisplayUtils.advancedConfig(getActivity(), cropper); |
|
|
|
cropper.start(getActivity(),this); |
|
|
@ -428,19 +457,30 @@ public class KYCView3Fragment extends BaseFragment implements View.OnClickListen |
|
|
|
} |
|
|
|
return bm; |
|
|
|
} |
|
|
|
private Bitmap createBitmapFromUri(Uri data) { |
|
|
|
private Bitmap createBitmapThumbnailFromUri(Uri data) { |
|
|
|
|
|
|
|
Bitmap bm = null; |
|
|
|
Bitmap compressedBitmap= null; |
|
|
|
if (data != null) { |
|
|
|
try { |
|
|
|
bm = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), data); |
|
|
|
Bitmap bm = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), data); |
|
|
|
ByteArrayOutputStream stream = new ByteArrayOutputStream(); |
|
|
|
|
|
|
|
bm.compress(Bitmap.CompressFormat.JPEG,COMPRESS_QUALITY,stream); |
|
|
|
|
|
|
|
byte[] byteArray = stream.toByteArray(); |
|
|
|
long lengthbmp = byteArray.length/1000000; |
|
|
|
Log.d("IMAGE_FILE","Compressed size: "+lengthbmp); |
|
|
|
compressedBitmap = BitmapFactory.decodeByteArray(byteArray,0,byteArray.length); |
|
|
|
stream.flush(); |
|
|
|
stream.close(); |
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return bm; |
|
|
|
return compressedBitmap; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|