Created
May 28, 2015 04:38
-
-
Save yaronv/fafecc43e685b8932bec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void onActivityResult(int requestCode, int resultCode, Intent data) { | |
super.onActivityResult(requestCode, resultCode, data); | |
ImageView viewImage = (ImageView) findViewById(R.id.image_placeholder); | |
ImageView analyzeIcon = (ImageView) findViewById(R.id.analyze_icon); | |
if (resultCode == RESULT_OK) { | |
if (requestCode == 1) { | |
File f = new File(Environment.getExternalStorageDirectory().toString()); | |
for (File temp : f.listFiles()) { | |
if (temp.getName().equals("temp.jpg")) { | |
f = temp; | |
break; | |
} | |
} | |
try { | |
Bitmap bitmap; | |
BitmapFactory.Options bitmapOptions = new BitmapFactory.Options(); | |
bitmap = BitmapFactory.decodeFile(f.getAbsolutePath(), bitmapOptions); | |
viewImage.setImageBitmap(bitmap); | |
viewImage.setBackgroundResource(R.drawable.shape_view_border); | |
analyzeIcon.setVisibility(View.VISIBLE); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} else if (requestCode == 2) { | |
Uri selectedImage = data.getData(); | |
String[] filePath = { MediaStore.Images.Media.DATA }; | |
Cursor c = getContentResolver().query(selectedImage,filePath, null, null, null); | |
c.moveToFirst(); | |
int columnIndex = c.getColumnIndex(filePath[0]); | |
String picturePath = c.getString(columnIndex); | |
c.close(); | |
Bitmap thumbnail = (BitmapFactory.decodeFile(picturePath)); | |
viewImage.setImageBitmap(thumbnail); | |
analyzeIcon.setVisibility(View.VISIBLE); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment