public static AngleFlip getExifTargetOrientation(String filename) { if (GalleryFileFilter.canManipulateJpeg(filename)) { File jpegFile = new File(filename); try { Metadata metadata = JpegMetadataReader.readMetadata(jpegFile);  Directory exifDirectory = metadata.getDirectory(ExifDirectory.class); String orientation = exifDirectory.getString(ExifDirectory.TAG_ORIENTATION);  if (orientation == null) { Log.log(Log.LEVEL_TRACE, MODULE, "Picture " + filename + " has no EXIF ORIENTATION tag"); return null; } else { Log.log(Log.LEVEL_TRACE, MODULE, "Picture " + filename + " EXIF ORIENTATION: " + orientation);  int or = 0; AngleFlip af = null; try { or = Integer.parseInt(orientation); } catch (NumberFormatException e) { Log.log(Log.LEVEL_ERROR, MODULE, "Couldn't parse orientation " + orientation + " for " + filename); return null; }  switch (or) { case 1: af = new AngleFlip(0, false); break;  case 2: af = new AngleFlip(0, true); break;  case 3: af = new AngleFlip(2, false); break;  case 4: af = new AngleFlip(2, true); break;  case 5: af = new AngleFlip(1, true); break;  case 6: af = new AngleFlip(1, false); break;  case 7: af = new AngleFlip(3, true); break;  case 8: af = new AngleFlip(3, false); break;  default: Log.log(Log.LEVEL_ERROR, MODULE, "Couldn't parse orientation " + orientation + " for " + filename); return null; }  Log.log(Log.LEVEL_TRACE, MODULE, "Angle: " + af.angle + " Flipped: " + af.flip); return af; } } catch (FileNotFoundException e) { Log.logException(Log.LEVEL_ERROR, MODULE, e); return null; } catch (JpegProcessingException e) { Log.logException(Log.LEVEL_ERROR, MODULE, e); return null; } } else {
public static ImageUtils.AngleFlip getExifTargetOrientation(String filename) { try { Class c = Class.forName("com.gallery.GalleryRemote.util.ExifImageUtils"); Method m =c.getMethod("getExifTargetOrientation", new Class[] {String.class}); return (AngleFlip) m.invoke(null, new Object[] {filename}); } catch (Throwable e) { Log.logException(Log.LEVEL_ERROR, MODULE, e);
	public static AngleFlip getExifTargetOrientation(String filename) {		if (GalleryFileFilter.canManipulateJpeg(filename)) {			File jpegFile = new File(filename);			try {				Metadata metadata = JpegMetadataReader.readMetadata(jpegFile);				Directory exifDirectory = metadata.getDirectory(ExifDirectory.class);				String orientation = exifDirectory.getString(ExifDirectory.TAG_ORIENTATION);				if (orientation == null) {					Log.log(Log.LEVEL_TRACE, MODULE, "Picture " + filename + " has no EXIF ORIENTATION tag");					return null;				} else {					Log.log(Log.LEVEL_TRACE, MODULE, "Picture " + filename + " EXIF ORIENTATION: " + orientation);					int or = 0;					AngleFlip af = null;					try {						or = Integer.parseInt(orientation);					} catch (NumberFormatException e) {						Log.log(Log.LEVEL_ERROR, MODULE, "Couldn't parse orientation " + orientation + " for " + filename);						return null;					}					switch (or) {						case 1:							af = new AngleFlip(0, false);							break;						case 2:							af = new AngleFlip(0, true);							break;						case 3:							af = new AngleFlip(2, false);							break;						case 4:							af = new AngleFlip(2, true);							break;						case 5:							af = new AngleFlip(1, true);							break;						case 6:							af = new AngleFlip(1, false);							break;						case 7:							af = new AngleFlip(3, true);							break;						case 8:							af = new AngleFlip(3, false);							break;						default:							Log.log(Log.LEVEL_ERROR, MODULE, "Couldn't parse orientation " + orientation + " for " + filename);							return null;					}					Log.log(Log.LEVEL_TRACE, MODULE, "Angle: " + af.angle + " Flipped: " + af.flip);					return af;				}			} catch (FileNotFoundException e) {				Log.logException(Log.LEVEL_ERROR, MODULE, e);				return null;			} catch (JpegProcessingException e) {				Log.logException(Log.LEVEL_ERROR, MODULE, e);				return null;			}		} else {			return null;		}	}