Santiago Etchebehere | 8e9a847 | 2018-07-24 14:30:21 -0700 | [diff] [blame] | 1 | package com.android.wallpaper.asset; |
| 2 | |
Colin Cross | 1b7f208 | 2021-05-21 11:15:20 -0700 | [diff] [blame] | 3 | import android.os.Build; |
| 4 | |
| 5 | import androidx.exifinterface.media.ExifInterface; |
Santiago Etchebehere | 8e9a847 | 2018-07-24 14:30:21 -0700 | [diff] [blame] | 6 | |
| 7 | import java.io.IOException; |
| 8 | import java.io.InputStream; |
| 9 | |
Santiago Etchebehere | 8e9a847 | 2018-07-24 14:30:21 -0700 | [diff] [blame] | 10 | /** |
| 11 | * Provides access to basic ExifInterface APIs using {@link android.media.ExifInterface} in OMR1+ |
| 12 | * SDK or SupportLibrary's {@link ExifInterface} for earlier SDK versions. |
| 13 | */ |
| 14 | class ExifInterfaceCompat { |
| 15 | |
| 16 | public static final String TAG_ORIENTATION = ExifInterface.TAG_ORIENTATION; |
| 17 | public static final int EXIF_ORIENTATION_NORMAL = 1; |
| 18 | public static final int EXIF_ORIENTATION_UNKNOWN = -1; |
| 19 | |
| 20 | private ExifInterface mSupportExifInterface; |
| 21 | private android.media.ExifInterface mFrameworkExifInterface; |
| 22 | |
| 23 | /** |
| 24 | * Reads Exif tags from the specified image input stream. It's the caller's responsibility to |
| 25 | * close the given InputStream after use. |
| 26 | * @see ExifInterface#ExifInterface(InputStream) |
| 27 | * @see android.media.ExifInterface#ExifInterface(InputStream) |
| 28 | */ |
| 29 | public ExifInterfaceCompat(InputStream inputStream) throws IOException { |
| 30 | // O-MR1 added support for more formats (HEIF), which Support Library cannot implement, |
| 31 | // so use the framework version for SDK 27+ |
Colin Cross | 1b7f208 | 2021-05-21 11:15:20 -0700 | [diff] [blame] | 32 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { |
Santiago Etchebehere | 8e9a847 | 2018-07-24 14:30:21 -0700 | [diff] [blame] | 33 | mFrameworkExifInterface = new android.media.ExifInterface(inputStream); |
| 34 | } else { |
| 35 | mSupportExifInterface = new ExifInterface(inputStream); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | public int getAttributeInt(String tag, int defaultValue) { |
| 40 | return mFrameworkExifInterface != null |
| 41 | ? mFrameworkExifInterface.getAttributeInt(tag, defaultValue) |
| 42 | : mSupportExifInterface.getAttributeInt(tag, defaultValue); |
| 43 | } |
| 44 | |
| 45 | public String getAttribute(String tag) { |
| 46 | return mFrameworkExifInterface != null |
| 47 | ? mFrameworkExifInterface.getAttribute(tag) |
| 48 | : mSupportExifInterface.getAttribute(tag); |
| 49 | } |
| 50 | } |