use of org.javarosa.core.reference.InvalidReferenceException in project collect by opendatakit.
the class LikertWidget method setImageFromOtherSource.
public String setImageFromOtherSource(String imageURI, ImageView imageView) {
String errorMsg = null;
try {
String imageFilename = ReferenceManager.instance().deriveReference(imageURI).getLocalURI();
final File imageFile = new File(imageFilename);
if (imageFile.exists()) {
Bitmap b = null;
try {
DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
int screenWidth = metrics.widthPixels;
int screenHeight = metrics.heightPixels;
b = ImageFileUtils.getBitmapScaledToDisplay(imageFile, screenHeight, screenWidth);
} catch (OutOfMemoryError e) {
errorMsg = "ERROR: " + e.getMessage();
}
if (b != null) {
imageView.setAdjustViewBounds(true);
imageView.setImageBitmap(b);
} else if (errorMsg == null) {
// Loading the image failed. The image work when in .jpg format
errorMsg = getContext().getString(R.string.file_invalid, imageFile);
}
} else {
errorMsg = getContext().getString(R.string.file_missing, imageFile);
}
if (errorMsg != null) {
Timber.e(errorMsg);
}
} catch (InvalidReferenceException e) {
Timber.d(e, "Invalid image reference due to %s ", e.getMessage());
}
return errorMsg;
}
Aggregations