Confusing concept on Crime object


#1

Hi Everyone,

Just a quick question: The code to save the array values to a crimes.JSON format file is understandable. What I can’t seem to wrap my head around is how the jpg gets saved. Is the filename that gets saved to the crimes.JSON file just a reference to the “sandbox”? Where can this be confirmed within the code?

Thanks,
fproof


#2

Look at listing 20.2. A random file name is generated an the raw jpeg data is written to it. So the JSON file name points to that file in the app’s private storage.


#3

Thanks. I see how the file name is generated and how the data is written. I guess what I mean to say is how/where does the JSON file name point to the specific file in code? I see that the crime class has an mPhoto member variable and json.put stores this variable to the JSON file, but how does a particular reference in that array point to the actual jpeg file? Is it the showPhoto() method ?


#4

because the crime object holding the photo object which is holding the path/name of the photo

look at showPhoto() method

private void showPhoto() { // (Re)set the image button's image based on our photo Photo p = mCrime.getPhoto(); BitmapDrawable b = null; if (p != null) { String path = getActivity() .getFileStreamPath(p.getFilename()).getAbsolutePath(); b = PictureUtils.getScaledDrawable(getActivity(), path); int orientation = p.getOrientation(); if (orientation == CrimeCameraActivity.ORIENTATION_PORTRAIT_INVERTED || orientation == CrimeCameraActivity.ORIENTATION_PORTRAIT_NORMAL){ b=PictureUtils.getPortraitDrawable(mPhotoView, b); } } mPhotoView.setImageDrawable(b); }

first we get the photo object from the selected crime

then we get the file from it’s filepath/file location

and then we use PictureUtils for scaling the image and showing it in thumbnails(imageView)

correct me if I wrong
I just trying to help :slight_smile: