Last active
November 28, 2016 11:04
-
-
Save tsherdiwala/2e4c63771bfeb252adaa86dd8ad3b6ba to your computer and use it in GitHub Desktop.
Crime Reference.
This file contains hidden or 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
public class CrimeLab{ | |
public File getPhotoFile(Crime crime) { | |
File externalFilesDir = mContext.getExternalFilesDir(Environment.DIRECTORY_PICTURES); | |
if (externalFilesDir == null) { | |
return null; | |
} | |
return new File(externalFilesDir, crime.getPhotoFilename()); | |
} | |
} |
This file contains hidden or 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
public class DetailFragment{ | |
private void updatePhotoView() { | |
if (mPhotoFile == null || !mPhotoFile.exists()) { | |
mPhotoView.setImageDrawable(null); | |
} else { | |
Bitmap bitmap = PictureUtils.getScaledBitmap(mPhotoFile.getPath(), getActivity()); | |
mPhotoView.setImageBitmap(bitmap); | |
} | |
} | |
private void requestPhotoFromCamera(){ | |
final Intent captureImage = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); | |
boolean canTakePhoto = mPhotoFile != null && captureImage.resolveActivity(packageManager) != null; | |
mPhotoButton.setEnabled(canTakePhoto); | |
if (canTakePhoto) { | |
Uri uri = Uri.fromFile(mPhotoFile); | |
captureImage.putExtra(MediaStore.EXTRA_OUTPUT, uri); | |
} | |
mPhotoButton.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
startActivityForResult(captureImage, REQUEST_PHOTO); | |
} | |
}); | |
} | |
} |
This file contains hidden or 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
public class PictureUtils { | |
public static Bitmap getScaledBitmap(String path, int destWidth, int destHeight) { | |
// Read in the dimensions of the image on disk | |
BitmapFactory.Options options = new BitmapFactory.Options(); | |
options.inJustDecodeBounds = true; | |
BitmapFactory.decodeFile(path, options); | |
float srcWidth = options.outWidth; | |
float srcHeight = options.outHeight; | |
// Figure out how much to scale down by | |
int inSampleSize = 1; | |
if (srcHeight > destHeight || srcWidth > destWidth) { | |
if (srcWidth > srcHeight) { | |
inSampleSize = Math.round(srcHeight / destHeight); | |
} else { | |
inSampleSize = Math.round(srcWidth / destWidth); | |
} | |
} | |
options = new BitmapFactory.Options(); | |
options.inSampleSize = inSampleSize; | |
// Read in and create final bitmap | |
return BitmapFactory.decodeFile(path, options); | |
} | |
public static Bitmap getScaledBitmap(String path, Activity activity) { | |
Point size = new Point(); | |
activity.getWindowManager().getDefaultDisplay() | |
.getSize(size); | |
return getScaledBitmap(path, size.x, size.y); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment