Owen Lin | 7a5e1e7 | 2012-06-20 16:54:24 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.gallery3d.common; |
| 18 | |
Hung-ying Tyan | 8880e1f | 2012-07-09 14:59:51 +0800 | [diff] [blame] | 19 | import android.app.admin.DevicePolicyManager; |
| 20 | import android.content.ComponentName; |
Ahbong Chang | 4bfc86a | 2012-07-11 13:56:46 +0800 | [diff] [blame] | 21 | import android.hardware.Camera; |
Owen Lin | 30aa920 | 2012-06-27 19:01:21 +0800 | [diff] [blame] | 22 | import android.os.Build; |
Owen Lin | b47927b | 2012-06-22 12:31:33 +0800 | [diff] [blame] | 23 | import android.provider.MediaStore.MediaColumns; |
Owen Lin | 7a5e1e7 | 2012-06-20 16:54:24 +0800 | [diff] [blame] | 24 | import android.view.View; |
Michael Kolb | edc63dd | 2013-02-25 19:43:56 -0800 | [diff] [blame] | 25 | import android.view.WindowManager; |
Owen Lin | 7a5e1e7 | 2012-06-20 16:54:24 +0800 | [diff] [blame] | 26 | |
Angus Kong | 1b10bf5 | 2012-07-13 11:54:05 +0800 | [diff] [blame] | 27 | import java.lang.reflect.Field; |
| 28 | |
Owen Lin | 7a5e1e7 | 2012-06-20 16:54:24 +0800 | [diff] [blame] | 29 | public class ApiHelper { |
Owen Lin | 3a45725 | 2012-06-28 11:10:02 +0800 | [diff] [blame] | 30 | public static interface VERSION_CODES { |
| 31 | // These value are copied from Build.VERSION_CODES |
| 32 | public static final int GINGERBREAD_MR1 = 10; |
| 33 | public static final int HONEYCOMB = 11; |
| 34 | public static final int HONEYCOMB_MR1 = 12; |
| 35 | public static final int HONEYCOMB_MR2 = 13; |
| 36 | public static final int ICE_CREAM_SANDWICH = 14; |
| 37 | public static final int ICE_CREAM_SANDWICH_MR1 = 15; |
| 38 | public static final int JELLY_BEAN = 16; |
Wu-cheng Li | 46f9d24 | 2012-08-25 21:10:04 +0800 | [diff] [blame] | 39 | public static final int JELLY_BEAN_MR1 = 17; |
ztenghui | 8b9de91 | 2013-04-08 14:37:53 -0700 | [diff] [blame] | 40 | public static final int JELLY_BEAN_MR2 = 18; |
Owen Lin | 3a45725 | 2012-06-28 11:10:02 +0800 | [diff] [blame] | 41 | } |
Owen Lin | 7a5e1e7 | 2012-06-20 16:54:24 +0800 | [diff] [blame] | 42 | |
Bobby Georgescu | fb6132b | 2013-03-07 14:15:57 -0800 | [diff] [blame] | 43 | public static final boolean AT_LEAST_16 = Build.VERSION.SDK_INT >= 16; |
| 44 | |
Pin Ting | 2e1771b | 2012-09-19 15:05:28 +0800 | [diff] [blame] | 45 | public static final boolean USE_888_PIXEL_FORMAT = |
| 46 | Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN; |
| 47 | |
Yuli Huang | 778ec35 | 2012-08-06 17:55:30 +0800 | [diff] [blame] | 48 | public static final boolean ENABLE_PHOTO_EDITOR = |
| 49 | Build.VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH; |
| 50 | |
Owen Lin | 7a5e1e7 | 2012-06-20 16:54:24 +0800 | [diff] [blame] | 51 | public static final boolean HAS_VIEW_SYSTEM_UI_FLAG_LAYOUT_STABLE = |
| 52 | hasField(View.class, "SYSTEM_UI_FLAG_LAYOUT_STABLE"); |
| 53 | |
| 54 | public static final boolean HAS_VIEW_SYSTEM_UI_FLAG_HIDE_NAVIGATION = |
| 55 | hasField(View.class, "SYSTEM_UI_FLAG_HIDE_NAVIGATION"); |
| 56 | |
Owen Lin | b47927b | 2012-06-22 12:31:33 +0800 | [diff] [blame] | 57 | public static final boolean HAS_MEDIA_COLUMNS_WIDTH_AND_HEIGHT = |
| 58 | hasField(MediaColumns.class, "WIDTH"); |
| 59 | |
Owen Lin | 30aa920 | 2012-06-27 19:01:21 +0800 | [diff] [blame] | 60 | public static final boolean HAS_REUSING_BITMAP_IN_BITMAP_REGION_DECODER = |
Owen Lin | 3a45725 | 2012-06-28 11:10:02 +0800 | [diff] [blame] | 61 | Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN; |
Owen Lin | 30aa920 | 2012-06-27 19:01:21 +0800 | [diff] [blame] | 62 | |
Owen Lin | df4763c | 2012-06-28 17:12:20 +0800 | [diff] [blame] | 63 | public static final boolean HAS_REUSING_BITMAP_IN_BITMAP_FACTORY = |
| 64 | Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB; |
| 65 | |
Chih-Chung Chang | 6772173 | 2012-07-03 12:49:45 +0800 | [diff] [blame] | 66 | public static final boolean HAS_SET_BEAM_PUSH_URIS = |
| 67 | Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN; |
| 68 | |
| 69 | public static final boolean HAS_SET_DEFALT_BUFFER_SIZE = hasMethod( |
| 70 | "android.graphics.SurfaceTexture", "setDefaultBufferSize", |
| 71 | int.class, int.class); |
| 72 | |
Chih-Chung Chang | 840ae39 | 2012-07-13 14:57:26 +0800 | [diff] [blame] | 73 | public static final boolean HAS_RELEASE_SURFACE_TEXTURE = hasMethod( |
| 74 | "android.graphics.SurfaceTexture", "release"); |
| 75 | |
Wu-cheng Li | 211807b | 2012-08-07 15:07:42 +0800 | [diff] [blame] | 76 | public static final boolean HAS_SURFACE_TEXTURE = |
| 77 | Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB; |
| 78 | |
Chih-Chung Chang | 04ebde7 | 2012-07-03 19:33:46 +0800 | [diff] [blame] | 79 | public static final boolean HAS_MTP = |
| 80 | Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB_MR1; |
| 81 | |
Chih-Chung Chang | 097518e | 2012-07-04 16:54:02 +0800 | [diff] [blame] | 82 | public static final boolean HAS_AUTO_FOCUS_MOVE_CALLBACK = |
| 83 | Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN; |
| 84 | |
Owen Lin | a2cb30b | 2012-07-04 18:20:13 +0800 | [diff] [blame] | 85 | public static final boolean HAS_REMOTE_VIEWS_SERVICE = |
| 86 | Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB; |
| 87 | |
Owen Lin | fe9989a | 2012-07-05 17:06:56 +0800 | [diff] [blame] | 88 | public static final boolean HAS_INTENT_EXTRA_LOCAL_ONLY = |
| 89 | Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB; |
| 90 | |
Yuli Huang | b0774a3 | 2012-07-06 15:12:26 +0800 | [diff] [blame] | 91 | public static final boolean HAS_SET_SYSTEM_UI_VISIBILITY = |
| 92 | hasMethod(View.class, "setSystemUiVisibility", int.class); |
| 93 | |
Owen Lin | 81aef13 | 2012-07-24 14:34:07 +0800 | [diff] [blame] | 94 | public static final boolean HAS_FACE_DETECTION; |
| 95 | static { |
| 96 | boolean hasFaceDetection = false; |
| 97 | try { |
| 98 | Class<?> listenerClass = Class.forName( |
| 99 | "android.hardware.Camera$FaceDetectionListener"); |
| 100 | hasFaceDetection = |
| 101 | hasMethod(Camera.class, "setFaceDetectionListener", listenerClass) && |
| 102 | hasMethod(Camera.class, "startFaceDetection") && |
| 103 | hasMethod(Camera.class, "stopFaceDetection") && |
| 104 | hasMethod(Camera.Parameters.class, "getMaxNumDetectedFaces"); |
| 105 | } catch (Throwable t) { |
| 106 | } |
| 107 | HAS_FACE_DETECTION = hasFaceDetection; |
| 108 | } |
Ahbong Chang | 4bfc86a | 2012-07-11 13:56:46 +0800 | [diff] [blame] | 109 | |
Hung-ying Tyan | 8880e1f | 2012-07-09 14:59:51 +0800 | [diff] [blame] | 110 | public static final boolean HAS_GET_CAMERA_DISABLED = |
| 111 | hasMethod(DevicePolicyManager.class, "getCameraDisabled", ComponentName.class); |
| 112 | |
Angus Kong | 1b10bf5 | 2012-07-13 11:54:05 +0800 | [diff] [blame] | 113 | public static final boolean HAS_MEDIA_ACTION_SOUND = |
| 114 | Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN; |
| 115 | |
Wu-cheng Li | e44b08e | 2012-08-29 14:41:42 +0800 | [diff] [blame] | 116 | public static final boolean HAS_OLD_PANORAMA = |
| 117 | Build.VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH; |
Ahbong Chang | 80bacf0 | 2012-07-17 16:58:17 +0800 | [diff] [blame] | 118 | |
Chih-Chung Chang | a895fae | 2012-07-20 11:38:48 +0800 | [diff] [blame] | 119 | public static final boolean HAS_TIME_LAPSE_RECORDING = |
| 120 | Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB; |
| 121 | |
Angus Kong | d498a90 | 2012-07-25 02:05:19 +0800 | [diff] [blame] | 122 | public static final boolean HAS_ZOOM_WHEN_RECORDING = |
Angus Kong | 064c30b | 2012-07-20 15:59:50 +0800 | [diff] [blame] | 123 | Build.VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH; |
| 124 | |
Angus Kong | 6c64f55 | 2012-07-25 01:51:19 +0800 | [diff] [blame] | 125 | public static final boolean HAS_CAMERA_FOCUS_AREA = |
| 126 | Build.VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH; |
| 127 | |
Angus Kong | 68cdf08 | 2012-07-31 09:50:12 +0800 | [diff] [blame] | 128 | public static final boolean HAS_CAMERA_METERING_AREA = |
| 129 | Build.VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH; |
| 130 | |
Pin Ting | 4d063b3 | 2012-07-30 16:11:24 -0700 | [diff] [blame] | 131 | public static final boolean HAS_FINE_RESOLUTION_QUALITY_LEVELS = |
| 132 | Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB; |
| 133 | |
Chih-Chung Chang | abf0ea6 | 2012-07-31 13:03:24 +0800 | [diff] [blame] | 134 | public static final boolean HAS_MOTION_EVENT_TRANSFORM = |
| 135 | Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB; |
| 136 | |
Wu-cheng Li | f6b2ec8 | 2012-09-30 23:13:00 +0800 | [diff] [blame] | 137 | public static final boolean HAS_EFFECTS_RECORDING = false; |
Pin Ting | 28038df | 2012-08-07 15:53:18 -0700 | [diff] [blame] | 138 | |
Wu-cheng Li | 62e8403 | 2012-09-25 17:45:03 +0800 | [diff] [blame] | 139 | // "Background" filter does not have "context" input port in jelly bean. |
| 140 | public static final boolean HAS_EFFECTS_RECORDING_CONTEXT_INPUT = |
| 141 | Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1; |
| 142 | |
Pin Ting | 910935b | 2012-08-08 11:50:31 -0700 | [diff] [blame] | 143 | public static final boolean HAS_GET_SUPPORTED_VIDEO_SIZE = |
| 144 | Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB; |
| 145 | |
Chih-Chung Chang | 840ae39 | 2012-07-13 14:57:26 +0800 | [diff] [blame] | 146 | public static final boolean HAS_SET_ICON_ATTRIBUTE = |
| 147 | Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB; |
| 148 | |
Owen Lin | 90df352 | 2012-07-31 14:22:02 +0800 | [diff] [blame] | 149 | public static final boolean HAS_MEDIA_PROVIDER_FILES_TABLE = |
| 150 | Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB; |
| 151 | |
Angus Kong | 4e9b8e4 | 2012-08-07 17:15:14 +0800 | [diff] [blame] | 152 | public static final boolean HAS_SURFACE_TEXTURE_RECORDING = |
| 153 | Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN; |
Owen Lin | d84941f | 2012-07-17 16:50:31 +0800 | [diff] [blame] | 154 | |
Owen Lin | d84941f | 2012-07-17 16:50:31 +0800 | [diff] [blame] | 155 | public static final boolean HAS_ACTION_BAR = |
| 156 | Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB; |
| 157 | |
Wu-cheng Li | d41a508 | 2012-08-22 15:31:01 +0800 | [diff] [blame] | 158 | // Ex: View.setTranslationX. |
| 159 | public static final boolean HAS_VIEW_TRANSFORM_PROPERTIES = |
| 160 | Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB; |
| 161 | |
Wu-cheng Li | 46f9d24 | 2012-08-25 21:10:04 +0800 | [diff] [blame] | 162 | public static final boolean HAS_CAMERA_HDR = |
| 163 | Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1; |
| 164 | |
Owen Lin | a625b65 | 2012-09-04 11:44:57 +0800 | [diff] [blame] | 165 | public static final boolean HAS_OPTIONS_IN_MUTABLE = |
| 166 | Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB; |
| 167 | |
Wu-cheng Li | a31da58 | 2012-08-21 15:05:17 +0800 | [diff] [blame] | 168 | public static final boolean CAN_START_PREVIEW_IN_JPEG_CALLBACK = |
| 169 | Build.VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH; |
| 170 | |
John Reck | 38ff40d | 2012-10-06 16:15:52 -0700 | [diff] [blame] | 171 | public static final boolean HAS_VIEW_PROPERTY_ANIMATOR = |
| 172 | Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB_MR1; |
| 173 | |
John Reck | b75f5de | 2012-10-22 16:11:01 -0700 | [diff] [blame] | 174 | public static final boolean HAS_POST_ON_ANIMATION = |
| 175 | Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN; |
| 176 | |
Doris Liu | fdcec9b | 2012-11-02 18:22:07 -0700 | [diff] [blame] | 177 | public static final boolean HAS_ANNOUNCE_FOR_ACCESSIBILITY = |
| 178 | Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN; |
| 179 | |
Teng-Hui Zhu | b5f374c | 2012-11-13 10:39:38 -0800 | [diff] [blame] | 180 | public static final boolean HAS_OBJECT_ANIMATION = |
| 181 | Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB; |
| 182 | |
George Mount | 6eb3376 | 2012-11-16 15:44:26 -0800 | [diff] [blame] | 183 | public static final boolean HAS_GLES20_REQUIRED = |
| 184 | Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB; |
| 185 | |
Michael Kolb | edc63dd | 2013-02-25 19:43:56 -0800 | [diff] [blame] | 186 | public static final boolean HAS_ROTATION_ANIMATION = |
| 187 | hasField(WindowManager.LayoutParams.class, "rotationAnimation"); |
| 188 | |
Michael Kolb | 72d611a | 2013-04-15 11:35:52 -0700 | [diff] [blame] | 189 | public static final boolean HAS_ORIENTATION_LOCK = |
| 190 | Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR2; |
| 191 | |
George Mount | 091314b | 2013-03-15 07:52:15 -0700 | [diff] [blame] | 192 | public static final boolean HAS_CANCELLATION_SIGNAL = |
| 193 | Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN; |
| 194 | |
ztenghui | 8b9de91 | 2013-04-08 14:37:53 -0700 | [diff] [blame] | 195 | public static final boolean HAS_MEDIA_MUXER = |
| 196 | Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR2; |
| 197 | |
Wu-cheng Li | a31da58 | 2012-08-21 15:05:17 +0800 | [diff] [blame] | 198 | public static int getIntFieldIfExists(Class<?> klass, String fieldName, |
| 199 | Class<?> obj, int defaultVal) { |
| 200 | try { |
| 201 | Field f = klass.getDeclaredField(fieldName); |
| 202 | return f.getInt(obj); |
| 203 | } catch (Exception e) { |
| 204 | return defaultVal; |
| 205 | } |
| 206 | } |
| 207 | |
Owen Lin | 7a5e1e7 | 2012-06-20 16:54:24 +0800 | [diff] [blame] | 208 | private static boolean hasField(Class<?> klass, String fieldName) { |
| 209 | try { |
| 210 | klass.getDeclaredField(fieldName); |
| 211 | return true; |
| 212 | } catch (NoSuchFieldException e) { |
| 213 | return false; |
| 214 | } |
| 215 | } |
Chih-Chung Chang | 6772173 | 2012-07-03 12:49:45 +0800 | [diff] [blame] | 216 | |
| 217 | private static boolean hasMethod(String className, String methodName, |
| 218 | Class<?>... parameterTypes) { |
| 219 | try { |
Owen Lin | b1eb01c | 2012-07-04 15:48:59 +0800 | [diff] [blame] | 220 | Class<?> klass = Class.forName(className); |
Chih-Chung Chang | 6772173 | 2012-07-03 12:49:45 +0800 | [diff] [blame] | 221 | klass.getDeclaredMethod(methodName, parameterTypes); |
| 222 | return true; |
| 223 | } catch (Throwable th) { |
| 224 | return false; |
| 225 | } |
| 226 | } |
Owen Lin | b1eb01c | 2012-07-04 15:48:59 +0800 | [diff] [blame] | 227 | |
| 228 | private static boolean hasMethod( |
| 229 | Class<?> klass, String methodName, Class<?> ... paramTypes) { |
| 230 | try { |
| 231 | klass.getDeclaredMethod(methodName, paramTypes); |
| 232 | return true; |
| 233 | } catch (NoSuchMethodException e) { |
| 234 | return false; |
| 235 | } |
| 236 | } |
Owen Lin | 7a5e1e7 | 2012-06-20 16:54:24 +0800 | [diff] [blame] | 237 | } |