Search in sources :

Example 6 with InvalidReferenceException

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;
}
Also used : Bitmap(android.graphics.Bitmap) File(java.io.File) DisplayMetrics(android.util.DisplayMetrics) SuppressLint(android.annotation.SuppressLint) InvalidReferenceException(org.javarosa.core.reference.InvalidReferenceException)

Aggregations

InvalidReferenceException (org.javarosa.core.reference.InvalidReferenceException)6 File (java.io.File)5 Bitmap (android.graphics.Bitmap)3 DisplayMetrics (android.util.DisplayMetrics)3 SuppressLint (android.annotation.SuppressLint)2 Intent (android.content.Intent)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 ActivityNotFoundException (android.content.ActivityNotFoundException)1 AppCompatImageButton (android.support.v7.widget.AppCompatImageButton)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 CheckBox (android.widget.CheckBox)1 LinearLayout (android.widget.LinearLayout)1 RadioButton (android.widget.RadioButton)1 RelativeLayout (android.widget.RelativeLayout)1 IDataReference (org.javarosa.core.model.IDataReference)1 QuestionDef (org.javarosa.core.model.QuestionDef)1 Reference (org.javarosa.core.reference.Reference)1 ResourceReferenceFactory (org.javarosa.core.reference.ResourceReferenceFactory)1