My solution TO First Challenge,Second


#1

first you get the orientation when taking photo using this:
private int getOrientationStyle(){
int orientation=getResources().getConfiguration().orientation;
switch(orientation){
case Configuration.ORIENTATION_LANDSCAPE:
return orientation;
case Configuration.ORIENTATION_PORTRAIT:
return orientation;
default:
return orientation;
}
}

secondly to update/create the photo of the Crime using the filename and the orientation as a member variable, note u shd also serialize the orientation
then you return the data to calling activity
private void returnData(boolean status,int orientation){

	Intent intent=new Intent();
	if(this.getFileName()==null) return;
	intent.putExtra(FILE_NAME, getFileName());
	intent.putExtra(ORIENTATION, orientation);
	if(status){
		getActivity().setResult(Activity.RESULT_OK, intent);

	}else{
		getActivity().setResult(Activity.RESULT_CANCELED);

	}
	getActivity().finish();

}

then in your onActivityResult of the Crime Fragment you do this:
else if(requestCode==REQUEST_PHOTO ){
String fileName=data.getStringExtra(CrimeCameraFragment.FILE_NAME);
int orientation=data.getIntExtra(CrimeCameraFragment.ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
if(fileName !=null) {
if(mCrime.getPhoto() !=null)PictureUtils.deleteRecentFile(mCrime, getActivity());//delete the file if already exist using Context.deleteFile(filename), note i did this in my picture utils, just to keep clean

				Photo photo=new  Photo(fileName,orientation);
				
				mCrime.setPhoto(photo);
		

				showPhoto();
			}
				
	}

Note :::::: Very important. Remove the orientation style in the manifest and add orientationEventListener to your CrimeCameraFragment class and Enable it . note disable it before releasing the camera when not needed

if (orientation == ORIENTATION_UNKNOWN) return;
android.hardware.Camera.CameraInfo info =
new android.hardware.Camera.CameraInfo();
android.hardware.Camera.getCameraInfo(0, info);
orientation = (orientation + 45) / 90 * 90;
int rotation = 0;
if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
rotation = (info.orientation - orientation + 360) % 360;
} else { // back-facing camera
rotation = (info.orientation + orientation) % 360;
}
if(mCamera !=null){
Parameters parameters=mCamera.getParameters();
parameters.setRotation(rotation);
mCamera.setParameters(parameters);
mCamera.setDisplayOrientation(rotation);
}

Note: you have to check if the orientation is in portrait mode so u can rotate the drawable resource

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mImageView=new ImageView(getActivity());
String imagePath= (String)getArguments().getSerializable(EXTRA_IMAGE_PATH);
int orientation=getArguments().getInt(ORIENTATION);
BitmapDrawable bitmapDrawable=PictureUtils.getScaledDrawable(getActivity(), imagePath);
if(orientation==Configuration.ORIENTATION_PORTRAIT){
bitmapDrawable=PictureUtils.rotateDrawable(mImageView, bitmapDrawable);
}
mImageView.setImageDrawable(bitmapDrawable);
return mImageView;
}

see the rotateDrawable method:
public static BitmapDrawable rotateDrawable(ImageView imgView,BitmapDrawable drawable){
Matrix matrix= new Matrix();
matrix.postRotate(90);
Bitmap bitmap=Bitmap.createBitmap(drawable.getBitmap(),0,0,drawable.getIntrinsicWidth(),drawable.getIntrinsicHeight(),matrix,true);
drawable=new BitmapDrawable(imgView.getResources(),bitmap);

	return  drawable;
	
}

thats done . its simple


#2

Why not rewriting this:

private int getOrientationStyle(){ int orientation=getResources().getConfiguration().orientation; switch(orientation){ case Configuration.ORIENTATION_LANDSCAPE: return orientation; case Configuration.ORIENTATION_PORTRAIT: return orientation; default: return orientation; } }

, into this:

private int getOrientationStyle(){ return getResources().getConfiguration().orientation; }

also, perhaps you should use “Code” display button when posting to make code more readable and distinguished from the comments. It also shows nice indentation.