NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

Image

private void startActivityFromGallery() {
mImgConfig.isImgFromCamera = false;
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.putExtra(Intent.EXTRA_LOCAL_ONLY, !mImgConfig.allowOnlineImages);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, ImageTags.IntentCode.REQUEST_CODE_SELECT_PHOTO);
if (mImgConfig.debug)
Log.e(ImageTags.Tags.TAG, "Gallery Start with Single Image mode");
}

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private void startActivityFromGalleryMultiImg() {
mImgConfig.isImgFromCamera = false;
Intent photoPickerIntent = new Intent();
photoPickerIntent.putExtra(Intent.EXTRA_LOCAL_ONLY, !mImgConfig.allowOnlineImages);
photoPickerIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
photoPickerIntent.setAction(Intent.ACTION_GET_CONTENT);
photoPickerIntent.setType("image/*");
startActivityForResult(Intent.createChooser(photoPickerIntent, "Select Picture"), ImageTags.IntentCode.REQUEST_CODE_SELECT_MULTI_PHOTO);
if (mImgConfig.debug)
Log.e(ImageTags.Tags.TAG, "Gallery Start with Multiple Images mode");
}

private void startActivityFromCamera() {
mImgConfig.isImgFromCamera = true;
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
mImageUri = FileProvider.getUriForFile(this, this.getApplicationContext().getPackageName() + ".provider", destination);
intent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), ImageTags.IntentCode.CAMERA_REQUEST);
if (mImgConfig.debug)
Log.e(ImageTags.Tags.TAG, "Camera Start");
}

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (mImgConfig.debug)
Log.e(ImageTags.Tags.TAG, "onActivityResult() called with: " + "requestCode = [" + requestCode + "]," +
" resultCode = [" + resultCode + "], data = [" + data + "]");
if (resultCode == RESULT_OK) {
switch (requestCode) {
case ImageTags.IntentCode.CAMERA_REQUEST:
new CompressImageTask(destination.getAbsolutePath(), mImgConfig
, ImageActivity.this).execute();

break;
case ImageTags.IntentCode.REQUEST_CODE_SELECT_PHOTO:
processOneImage(data);
break;
case ImageTags.IntentCode.REQUEST_CODE_SELECT_MULTI_PHOTO:
processMutliPhoto(data);
break;
default:
break;
}
} else {
Intent intent = new Intent();
intent.setAction("net.alhazmy13.mediapicker.rxjava.image.service");
intent.putExtra(ImageTags.Tags.PICK_ERROR, "user did not select any image");
sendBroadcast(intent);
finish();
}
}

public void processOneImage(Intent data) {
try {
Uri selectedImage = data.getData();
String rawPath = selectedImage.toString();
if (rawPath != null) {
//For 'Select pic from Google Drive - app Crash' fix
if (rawPath.contains("com.google.android.apps.docs.storage")) {
String fileTempPath = getCacheDir().getPath();
new ImageActivity.SaveImageFromGoogleDriveTask(fileTempPath, mImgConfig, selectedImage, ImageActivity.this).execute();
} else {
String selectedImagePath = FileProcessing.getPath(this, selectedImage);
new ImageActivity.CompressImageTask(selectedImagePath,
mImgConfig, ImageActivity.this).execute();
}
}
} catch (Exception ex) {
ex.printStackTrace();
}

}

private static class SaveImageFromGoogleDriveTask extends AsyncTask<Void, Void, Void> {

private final ImageConfig mImgConfig;
private final List<String> listOfImgs;
private List<String> destinationPaths;
private List<Uri> destinationUris;
private WeakReference<ImageActivity> mContext;


SaveImageFromGoogleDriveTask(String absolutePath, ImageConfig imageConfig, Uri uri, ImageActivity context) {
List<String> list = new ArrayList<>();
list.add(absolutePath);
this.listOfImgs = list;

List<Uri> uris = new ArrayList<>();
uris.add(uri);
destinationUris = uris;

this.mContext = new WeakReference<>(context);
this.destinationPaths = new ArrayList<>();
this.mImgConfig = imageConfig;
}


@Override
protected Void doInBackground(Void... params) {

for (int i = 0; i < listOfImgs.size(); i++) {
String path = listOfImgs.get(i);
Uri uriPath = destinationUris.get(i);
try {
String fileName = "drive_img_" + System.currentTimeMillis() + ".jpg";
String fullImagePath = path + "/" + fileName;
boolean isFileSaved = saveFile(uriPath, fullImagePath);
if (isFileSaved) {
destinationPaths.add(fullImagePath);
}
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}

@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
new CompressImageTask(destinationPaths, mImgConfig, mContext.get()).execute();
}

boolean filenotfoundexecption;

//For Google Drive
boolean saveFile(Uri sourceuri, String destination) throws IOException {
filenotfoundexecption = false;
int originalsize;
InputStream input = null;
try {
input = mContext.get().getContentResolver().openInputStream(sourceuri);
} catch (FileNotFoundException e) {
e.printStackTrace();
filenotfoundexecption = true;
}

try {
originalsize = input.available();
BufferedInputStream bis;
BufferedOutputStream bos;
try {
bis = new BufferedInputStream(input);
bos = new BufferedOutputStream(new FileOutputStream(destination, false));
byte[] buf = new byte[originalsize];
bis.read(buf);
do {
bos.write(buf);
} while (bis.read(buf) != -1);
} catch (IOException e) {
filenotfoundexecption = true;
return false;
}
} catch (NullPointerException e) {
filenotfoundexecption = true;
}
return true;
}

}




     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.