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 | |
Owen Lin | b4cadaf | 2012-07-04 15:48:59 +0800 | [diff] [blame^] | 19 | import android.app.Activity; |
Owen Lin | 76bfd87 | 2012-06-27 19:01:21 +0800 | [diff] [blame] | 20 | import android.os.Build; |
Owen Lin | 0c4c03a | 2012-06-22 12:31:33 +0800 | [diff] [blame] | 21 | import android.provider.MediaStore.MediaColumns; |
Owen Lin | 9199c4d | 2012-06-20 16:54:24 +0800 | [diff] [blame] | 22 | import android.view.View; |
| 23 | |
| 24 | public class ApiHelper { |
Owen Lin | 987f533 | 2012-06-28 11:10:02 +0800 | [diff] [blame] | 25 | public static interface VERSION_CODES { |
| 26 | // These value are copied from Build.VERSION_CODES |
| 27 | public static final int GINGERBREAD_MR1 = 10; |
| 28 | public static final int HONEYCOMB = 11; |
| 29 | public static final int HONEYCOMB_MR1 = 12; |
| 30 | public static final int HONEYCOMB_MR2 = 13; |
| 31 | public static final int ICE_CREAM_SANDWICH = 14; |
| 32 | public static final int ICE_CREAM_SANDWICH_MR1 = 15; |
| 33 | public static final int JELLY_BEAN = 16; |
| 34 | } |
Owen Lin | 9199c4d | 2012-06-20 16:54:24 +0800 | [diff] [blame] | 35 | |
| 36 | public static final boolean HAS_VIEW_SYSTEM_UI_FLAG_LAYOUT_STABLE = |
| 37 | hasField(View.class, "SYSTEM_UI_FLAG_LAYOUT_STABLE"); |
| 38 | |
| 39 | public static final boolean HAS_VIEW_SYSTEM_UI_FLAG_HIDE_NAVIGATION = |
| 40 | hasField(View.class, "SYSTEM_UI_FLAG_HIDE_NAVIGATION"); |
| 41 | |
Owen Lin | 0c4c03a | 2012-06-22 12:31:33 +0800 | [diff] [blame] | 42 | public static final boolean HAS_MEDIA_COLUMNS_WIDTH_AND_HEIGHT = |
| 43 | hasField(MediaColumns.class, "WIDTH"); |
| 44 | |
Owen Lin | 76bfd87 | 2012-06-27 19:01:21 +0800 | [diff] [blame] | 45 | public static final boolean HAS_REUSING_BITMAP_IN_BITMAP_REGION_DECODER = |
Owen Lin | 987f533 | 2012-06-28 11:10:02 +0800 | [diff] [blame] | 46 | Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN; |
Owen Lin | 76bfd87 | 2012-06-27 19:01:21 +0800 | [diff] [blame] | 47 | |
Owen Lin | 5b981d1 | 2012-06-28 17:12:20 +0800 | [diff] [blame] | 48 | public static final boolean HAS_REUSING_BITMAP_IN_BITMAP_FACTORY = |
| 49 | Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB; |
| 50 | |
Chih-Chung Chang | 7c3c938 | 2012-07-03 12:49:45 +0800 | [diff] [blame] | 51 | public static final boolean HAS_SET_BEAM_PUSH_URIS = |
| 52 | Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN; |
| 53 | |
| 54 | public static final boolean HAS_SET_DEFALT_BUFFER_SIZE = hasMethod( |
| 55 | "android.graphics.SurfaceTexture", "setDefaultBufferSize", |
| 56 | int.class, int.class); |
| 57 | |
Chih-Chung Chang | a207d33 | 2012-07-03 19:33:46 +0800 | [diff] [blame] | 58 | public static final boolean HAS_MTP = |
| 59 | Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB_MR1; |
| 60 | |
Chih-Chung Chang | 9341cc2 | 2012-07-04 16:54:02 +0800 | [diff] [blame] | 61 | public static final boolean HAS_AUTO_FOCUS_MOVE_CALLBACK = |
| 62 | Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN; |
| 63 | |
Owen Lin | b4cadaf | 2012-07-04 15:48:59 +0800 | [diff] [blame^] | 64 | public static final boolean HAS_ACTIVITY_INVALIDATE_OPTIONS_MENU = |
| 65 | hasMethod(Activity.class, "invalidateOptionsMenu"); |
| 66 | |
Owen Lin | 9199c4d | 2012-06-20 16:54:24 +0800 | [diff] [blame] | 67 | private static boolean hasField(Class<?> klass, String fieldName) { |
| 68 | try { |
| 69 | klass.getDeclaredField(fieldName); |
| 70 | return true; |
| 71 | } catch (NoSuchFieldException e) { |
| 72 | return false; |
| 73 | } |
| 74 | } |
Chih-Chung Chang | 7c3c938 | 2012-07-03 12:49:45 +0800 | [diff] [blame] | 75 | |
| 76 | private static boolean hasMethod(String className, String methodName, |
| 77 | Class<?>... parameterTypes) { |
| 78 | try { |
Owen Lin | b4cadaf | 2012-07-04 15:48:59 +0800 | [diff] [blame^] | 79 | Class<?> klass = Class.forName(className); |
Chih-Chung Chang | 7c3c938 | 2012-07-03 12:49:45 +0800 | [diff] [blame] | 80 | klass.getDeclaredMethod(methodName, parameterTypes); |
| 81 | return true; |
| 82 | } catch (Throwable th) { |
| 83 | return false; |
| 84 | } |
| 85 | } |
Owen Lin | b4cadaf | 2012-07-04 15:48:59 +0800 | [diff] [blame^] | 86 | |
| 87 | private static boolean hasMethod( |
| 88 | Class<?> klass, String methodName, Class<?> ... paramTypes) { |
| 89 | try { |
| 90 | klass.getDeclaredMethod(methodName, paramTypes); |
| 91 | return true; |
| 92 | } catch (NoSuchMethodException e) { |
| 93 | return false; |
| 94 | } |
| 95 | } |
Owen Lin | 9199c4d | 2012-06-20 16:54:24 +0800 | [diff] [blame] | 96 | } |