Owen Lin | 9199c4d | 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 | d5b66ad | 2012-07-09 14:59:51 +0800 | [diff] [blame] | 19 | import android.app.admin.DevicePolicyManager; |
| 20 | import android.content.ComponentName; |
Ahbong Chang | 5c12683 | 2012-07-11 13:56:46 +0800 | [diff] [blame] | 21 | import android.hardware.Camera; |
Owen Lin | 76bfd87 | 2012-06-27 19:01:21 +0800 | [diff] [blame] | 22 | import android.os.Build; |
Owen Lin | 0c4c03a | 2012-06-22 12:31:33 +0800 | [diff] [blame] | 23 | import android.provider.MediaStore.MediaColumns; |
Owen Lin | 9199c4d | 2012-06-20 16:54:24 +0800 | [diff] [blame] | 24 | import android.view.View; |
| 25 | |
Angus Kong | 708bfce | 2012-07-13 11:54:05 +0800 | [diff] [blame] | 26 | import java.lang.reflect.Field; |
| 27 | |
Owen Lin | 9199c4d | 2012-06-20 16:54:24 +0800 | [diff] [blame] | 28 | public class ApiHelper { |
Owen Lin | 987f533 | 2012-06-28 11:10:02 +0800 | [diff] [blame] | 29 | public static interface VERSION_CODES { |
| 30 | // These value are copied from Build.VERSION_CODES |
| 31 | public static final int GINGERBREAD_MR1 = 10; |
| 32 | public static final int HONEYCOMB = 11; |
| 33 | public static final int HONEYCOMB_MR1 = 12; |
| 34 | public static final int HONEYCOMB_MR2 = 13; |
| 35 | public static final int ICE_CREAM_SANDWICH = 14; |
| 36 | public static final int ICE_CREAM_SANDWICH_MR1 = 15; |
| 37 | public static final int JELLY_BEAN = 16; |
Wu-cheng Li | ea1d1d2 | 2012-08-25 21:10:04 +0800 | [diff] [blame] | 38 | public static final int JELLY_BEAN_MR1 = 17; |
Owen Lin | 987f533 | 2012-06-28 11:10:02 +0800 | [diff] [blame] | 39 | } |
Owen Lin | 9199c4d | 2012-06-20 16:54:24 +0800 | [diff] [blame] | 40 | |
Pin Ting | 026f5ae | 2012-09-19 15:05:28 +0800 | [diff] [blame] | 41 | public static final boolean USE_888_PIXEL_FORMAT = |
| 42 | Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN; |
| 43 | |
Yuli Huang | 51fbbcf | 2012-08-06 17:55:30 +0800 | [diff] [blame] | 44 | public static final boolean ENABLE_PHOTO_EDITOR = |
| 45 | Build.VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH; |
| 46 | |
Owen Lin | 9199c4d | 2012-06-20 16:54:24 +0800 | [diff] [blame] | 47 | public static final boolean HAS_VIEW_SYSTEM_UI_FLAG_LAYOUT_STABLE = |
| 48 | hasField(View.class, "SYSTEM_UI_FLAG_LAYOUT_STABLE"); |
| 49 | |
| 50 | public static final boolean HAS_VIEW_SYSTEM_UI_FLAG_HIDE_NAVIGATION = |
| 51 | hasField(View.class, "SYSTEM_UI_FLAG_HIDE_NAVIGATION"); |
| 52 | |
Owen Lin | 0c4c03a | 2012-06-22 12:31:33 +0800 | [diff] [blame] | 53 | public static final boolean HAS_MEDIA_COLUMNS_WIDTH_AND_HEIGHT = |
| 54 | hasField(MediaColumns.class, "WIDTH"); |
| 55 | |
Owen Lin | 76bfd87 | 2012-06-27 19:01:21 +0800 | [diff] [blame] | 56 | public static final boolean HAS_REUSING_BITMAP_IN_BITMAP_REGION_DECODER = |
Owen Lin | 987f533 | 2012-06-28 11:10:02 +0800 | [diff] [blame] | 57 | Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN; |
Owen Lin | 76bfd87 | 2012-06-27 19:01:21 +0800 | [diff] [blame] | 58 | |
Owen Lin | 5b981d1 | 2012-06-28 17:12:20 +0800 | [diff] [blame] | 59 | public static final boolean HAS_REUSING_BITMAP_IN_BITMAP_FACTORY = |
| 60 | Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB; |
| 61 | |
Chih-Chung Chang | 7c3c938 | 2012-07-03 12:49:45 +0800 | [diff] [blame] | 62 | public static final boolean HAS_SET_BEAM_PUSH_URIS = |
| 63 | Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN; |
| 64 | |
| 65 | public static final boolean HAS_SET_DEFALT_BUFFER_SIZE = hasMethod( |
| 66 | "android.graphics.SurfaceTexture", "setDefaultBufferSize", |
| 67 | int.class, int.class); |
| 68 | |
Chih-Chung Chang | 00862f1 | 2012-07-13 14:57:26 +0800 | [diff] [blame] | 69 | public static final boolean HAS_RELEASE_SURFACE_TEXTURE = hasMethod( |
| 70 | "android.graphics.SurfaceTexture", "release"); |
| 71 | |
Wu-cheng Li | 8df785a | 2012-08-07 15:07:42 +0800 | [diff] [blame] | 72 | public static final boolean HAS_SURFACE_TEXTURE = |
| 73 | Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB; |
| 74 | |
Chih-Chung Chang | a207d33 | 2012-07-03 19:33:46 +0800 | [diff] [blame] | 75 | public static final boolean HAS_MTP = |
| 76 | Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB_MR1; |
| 77 | |
Chih-Chung Chang | 9341cc2 | 2012-07-04 16:54:02 +0800 | [diff] [blame] | 78 | public static final boolean HAS_AUTO_FOCUS_MOVE_CALLBACK = |
| 79 | Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN; |
| 80 | |
Owen Lin | 362f50c | 2012-07-04 18:20:13 +0800 | [diff] [blame] | 81 | public static final boolean HAS_REMOTE_VIEWS_SERVICE = |
| 82 | Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB; |
| 83 | |
Owen Lin | 3969aca | 2012-07-05 17:06:56 +0800 | [diff] [blame] | 84 | public static final boolean HAS_INTENT_EXTRA_LOCAL_ONLY = |
| 85 | Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB; |
| 86 | |
Yuli Huang | 5424e32 | 2012-07-06 15:12:26 +0800 | [diff] [blame] | 87 | public static final boolean HAS_SET_SYSTEM_UI_VISIBILITY = |
| 88 | hasMethod(View.class, "setSystemUiVisibility", int.class); |
| 89 | |
Owen Lin | bc1489c | 2012-07-24 14:34:07 +0800 | [diff] [blame] | 90 | public static final boolean HAS_FACE_DETECTION; |
| 91 | static { |
| 92 | boolean hasFaceDetection = false; |
| 93 | try { |
| 94 | Class<?> listenerClass = Class.forName( |
| 95 | "android.hardware.Camera$FaceDetectionListener"); |
| 96 | hasFaceDetection = |
| 97 | hasMethod(Camera.class, "setFaceDetectionListener", listenerClass) && |
| 98 | hasMethod(Camera.class, "startFaceDetection") && |
| 99 | hasMethod(Camera.class, "stopFaceDetection") && |
| 100 | hasMethod(Camera.Parameters.class, "getMaxNumDetectedFaces"); |
| 101 | } catch (Throwable t) { |
| 102 | } |
| 103 | HAS_FACE_DETECTION = hasFaceDetection; |
| 104 | } |
Ahbong Chang | 5c12683 | 2012-07-11 13:56:46 +0800 | [diff] [blame] | 105 | |
Hung-ying Tyan | d5b66ad | 2012-07-09 14:59:51 +0800 | [diff] [blame] | 106 | public static final boolean HAS_GET_CAMERA_DISABLED = |
| 107 | hasMethod(DevicePolicyManager.class, "getCameraDisabled", ComponentName.class); |
| 108 | |
Angus Kong | 708bfce | 2012-07-13 11:54:05 +0800 | [diff] [blame] | 109 | public static final boolean HAS_MEDIA_ACTION_SOUND = |
| 110 | Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN; |
| 111 | |
Wu-cheng Li | f67891c | 2012-08-29 14:41:42 +0800 | [diff] [blame] | 112 | public static final boolean HAS_OLD_PANORAMA = |
| 113 | Build.VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH; |
Ahbong Chang | 208a15b | 2012-07-17 16:58:17 +0800 | [diff] [blame] | 114 | |
Chih-Chung Chang | 5a0e374 | 2012-07-20 11:38:48 +0800 | [diff] [blame] | 115 | public static final boolean HAS_TIME_LAPSE_RECORDING = |
| 116 | Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB; |
| 117 | |
Angus Kong | 8538bbd | 2012-07-25 02:05:19 +0800 | [diff] [blame] | 118 | public static final boolean HAS_ZOOM_WHEN_RECORDING = |
Angus Kong | b593dbc | 2012-07-20 15:59:50 +0800 | [diff] [blame] | 119 | Build.VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH; |
| 120 | |
Angus Kong | 6f9a145 | 2012-07-25 01:51:19 +0800 | [diff] [blame] | 121 | public static final boolean HAS_CAMERA_FOCUS_AREA = |
| 122 | Build.VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH; |
| 123 | |
Angus Kong | cd8e78b | 2012-07-31 09:50:12 +0800 | [diff] [blame] | 124 | public static final boolean HAS_CAMERA_METERING_AREA = |
| 125 | Build.VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH; |
| 126 | |
Pin Ting | f3b0384 | 2012-07-30 16:11:24 -0700 | [diff] [blame] | 127 | public static final boolean HAS_FINE_RESOLUTION_QUALITY_LEVELS = |
| 128 | Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB; |
| 129 | |
Chih-Chung Chang | ebd7187 | 2012-07-31 13:03:24 +0800 | [diff] [blame] | 130 | public static final boolean HAS_MOTION_EVENT_TRANSFORM = |
| 131 | Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB; |
| 132 | |
Pin Ting | 0a0cc9b | 2012-09-25 15:20:36 +0800 | [diff] [blame^] | 133 | public static final boolean HAS_EFFECTS_RECORDING = |
| 134 | Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN; |
Pin Ting | 6da4724 | 2012-08-07 15:53:18 -0700 | [diff] [blame] | 135 | |
Pin Ting | ee87994 | 2012-08-08 11:50:31 -0700 | [diff] [blame] | 136 | public static final boolean HAS_GET_SUPPORTED_VIDEO_SIZE = |
| 137 | Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB; |
| 138 | |
Chih-Chung Chang | 00862f1 | 2012-07-13 14:57:26 +0800 | [diff] [blame] | 139 | public static final boolean HAS_SET_ICON_ATTRIBUTE = |
| 140 | Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB; |
| 141 | |
Owen Lin | 6ae93db | 2012-07-31 14:22:02 +0800 | [diff] [blame] | 142 | public static final boolean HAS_MEDIA_PROVIDER_FILES_TABLE = |
| 143 | Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB; |
| 144 | |
Angus Kong | fbf6dba | 2012-08-07 17:15:14 +0800 | [diff] [blame] | 145 | public static final boolean HAS_SURFACE_TEXTURE_RECORDING = |
| 146 | Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN; |
Owen Lin | 00e4a6e | 2012-07-17 16:50:31 +0800 | [diff] [blame] | 147 | |
Owen Lin | 00e4a6e | 2012-07-17 16:50:31 +0800 | [diff] [blame] | 148 | public static final boolean HAS_ACTION_BAR = |
| 149 | Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB; |
| 150 | |
Wu-cheng Li | 622246a | 2012-08-22 15:31:01 +0800 | [diff] [blame] | 151 | // Ex: View.setTranslationX. |
| 152 | public static final boolean HAS_VIEW_TRANSFORM_PROPERTIES = |
| 153 | Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB; |
| 154 | |
Wu-cheng Li | ea1d1d2 | 2012-08-25 21:10:04 +0800 | [diff] [blame] | 155 | public static final boolean HAS_CAMERA_HDR = |
| 156 | Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1; |
| 157 | |
Owen Lin | 0fb7f34 | 2012-09-04 11:44:57 +0800 | [diff] [blame] | 158 | public static final boolean HAS_OPTIONS_IN_MUTABLE = |
| 159 | Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB; |
| 160 | |
Wu-cheng Li | 36d16bc | 2012-08-21 15:05:17 +0800 | [diff] [blame] | 161 | public static final boolean CAN_START_PREVIEW_IN_JPEG_CALLBACK = |
| 162 | Build.VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH; |
| 163 | |
Teng-Hui Zhu | 3e8946e | 2012-08-24 14:50:37 -0700 | [diff] [blame] | 164 | public static final boolean HAS_MEDIA_MUXER = |
Teng-Hui Zhu | 53b1c29 | 2012-09-23 15:02:56 -0700 | [diff] [blame] | 165 | Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN; |
Teng-Hui Zhu | 3e8946e | 2012-08-24 14:50:37 -0700 | [diff] [blame] | 166 | |
Wu-cheng Li | 36d16bc | 2012-08-21 15:05:17 +0800 | [diff] [blame] | 167 | public static int getIntFieldIfExists(Class<?> klass, String fieldName, |
| 168 | Class<?> obj, int defaultVal) { |
| 169 | try { |
| 170 | Field f = klass.getDeclaredField(fieldName); |
| 171 | return f.getInt(obj); |
| 172 | } catch (Exception e) { |
| 173 | return defaultVal; |
| 174 | } |
| 175 | } |
| 176 | |
Owen Lin | 9199c4d | 2012-06-20 16:54:24 +0800 | [diff] [blame] | 177 | private static boolean hasField(Class<?> klass, String fieldName) { |
| 178 | try { |
| 179 | klass.getDeclaredField(fieldName); |
| 180 | return true; |
| 181 | } catch (NoSuchFieldException e) { |
| 182 | return false; |
| 183 | } |
| 184 | } |
Chih-Chung Chang | 7c3c938 | 2012-07-03 12:49:45 +0800 | [diff] [blame] | 185 | |
| 186 | private static boolean hasMethod(String className, String methodName, |
| 187 | Class<?>... parameterTypes) { |
| 188 | try { |
Owen Lin | b4cadaf | 2012-07-04 15:48:59 +0800 | [diff] [blame] | 189 | Class<?> klass = Class.forName(className); |
Chih-Chung Chang | 7c3c938 | 2012-07-03 12:49:45 +0800 | [diff] [blame] | 190 | klass.getDeclaredMethod(methodName, parameterTypes); |
| 191 | return true; |
| 192 | } catch (Throwable th) { |
| 193 | return false; |
| 194 | } |
| 195 | } |
Owen Lin | b4cadaf | 2012-07-04 15:48:59 +0800 | [diff] [blame] | 196 | |
| 197 | private static boolean hasMethod( |
| 198 | Class<?> klass, String methodName, Class<?> ... paramTypes) { |
| 199 | try { |
| 200 | klass.getDeclaredMethod(methodName, paramTypes); |
| 201 | return true; |
| 202 | } catch (NoSuchMethodException e) { |
| 203 | return false; |
| 204 | } |
| 205 | } |
Owen Lin | 9199c4d | 2012-06-20 16:54:24 +0800 | [diff] [blame] | 206 | } |