private void chooseImage() { chooserType = ChooserType.REQUEST_PICK_PICTURE; imageChooserManager = new ImageChooserManager(this, ChooserType.REQUEST_PICK_PICTURE); imageChooserManager.setImageChooserListener(this); try { filePath = imageChooserManager.choose(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
private void takePicture() { chooserType = ChooserType.REQUEST_CAPTURE_PICTURE; imageChooserManager = new ImageChooserManager(this, ChooserType.REQUEST_CAPTURE_PICTURE, "TesteeMe", false); imageChooserManager.setImageChooserListener(this); try { filePath = imageChooserManager.choose(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == ChooserType.REQUEST_CAPTURE_PICTURE || requestCode == ChooserType.REQUEST_PICK_PICTURE) { if (resultCode == RESULT_OK) { if (imageChooserManager == null) { imageChooserManager = new ImageChooserManager(this, requestCode, FileUtils.getDirectory("TT")); imageChooserManager.setImageChooserListener(this); imageChooserManager.reinitialize(chooserPath); } imageChooserManager.submit(requestCode, data); } } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK && (requestCode == ChooserType.REQUEST_PICK_PICTURE || requestCode == ChooserType.REQUEST_CAPTURE_PICTURE)) { imageChooserManager.submit(requestCode, data); } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode != RESULT_CANCELED && resultCode == RESULT_OK) { File file; if (requestCode == ChooserType.REQUEST_PICK_PICTURE || requestCode == ChooserType.REQUEST_CAPTURE_PICTURE) { if (imageChooserManager == null) { reinitializeImageChooser(); } imageChooserManager.submit(requestCode, data); } // switch (requestCode) { // case 0: // // if (resultCode == RESULT_OK && intent != null) { // try { // Uri originalUri = intent.getData(); // // String[] filePathColumn = { MediaColumns.DATA }; // // Cursor cursor = getContentResolver().query(originalUri, // filePathColumn, null, null, null); // cursor.moveToFirst(); // // int columnIndex = cursor.getColumnIndex(filePathColumn[0]); // String picturePath = cursor.getString(columnIndex); // // //Bitmap bmp = BitmapFactory.decodeFile(picturePath); // // Matrix mat = new Matrix(); // // // Bitmap bMapRotate = null; //Bitmap.createBitmap(bmp, 0, 0, // bmp.getWidth(), bmp.getHeight(), mat, true); // // bMapRotate = Common.scaleImage(getApplicationContext(), // originalUri); // cursor.close(); // Bitmap bmpNew = Bitmap.createBitmap(bMapRotate, 0, 0, // bMapRotate.getWidth(), bMapRotate.getHeight(), mat, true); // mImage1.setImageBitmap(bmpNew); // //mImage1.setOnTouchListener(this); // imgAdd1.setVisibility(View.INVISIBLE); // } catch (IOException e) { // e.printStackTrace(); // } // } // break; // case 1: // // if (resultCode == RESULT_OK && intent != null) { // try { // Uri selectedImage = intent.getData(); // String[] filePathColumn = { MediaColumns.DATA }; // // Cursor cursor = getContentResolver().query(selectedImage, // filePathColumn, null, null, null); // cursor.moveToFirst(); // // int columnIndex = cursor.getColumnIndex(filePathColumn[0]); // String picturePath = cursor.getString(columnIndex); // // //Bitmap bmp = BitmapFactory.decodeFile(picturePath); // // Matrix mat = new Matrix(); // // // Bitmap bMapRotate = null; //Bitmap.createBitmap(bmp, 0, 0, // bmp.getWidth(), bmp.getHeight(), mat, true); // // bMapRotate = Common.scaleImage(getApplicationContext(), // selectedImage); // cursor.close(); // Bitmap bmpNew = Bitmap.createBitmap(bMapRotate, 0, 0, // bMapRotate.getWidth(), bMapRotate.getHeight(), mat, true); // mImage2.setImageBitmap(bmpNew); // //mImage2.setOnTouchListener(this); // imgAdd2.setVisibility(View.INVISIBLE); // } catch (IOException e) { // e.printStackTrace(); // } // // } // break; // // } } }
// Should be called if for some reason the ImageChooserManager is null (Due // to destroying of activity for low memory situations) private void reinitializeImageChooser() { imageChooserManager = new ImageChooserManager(this, chooserType); imageChooserManager.setImageChooserListener(this); imageChooserManager.reinitialize(filePath); }