BitmapCompat.java revision ddb24f29a236175d3cda4c11bda98a6212ecf9e5
1/* 2 * Copyright (C) 2014 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 */ 16package android.support.v4.graphics; 17 18import android.graphics.Bitmap; 19 20/** 21 * Helper for accessing features in {@link android.graphics.Bitmap} 22 * introduced after API level 4 in a backwards compatible fashion. 23 */ 24public class BitmapCompat { 25 /** 26 * Interface for the full API. 27 */ 28 interface BitmapImpl { 29 public boolean hasMipMap(Bitmap bitmap); 30 public void setHasMipMap(Bitmap bitmap, boolean hasMipMap); 31 } 32 33 /** 34 * Interface implementation that doesn't use anything about v4 APIs. 35 */ 36 static class BaseBitmapImpl implements BitmapImpl { 37 @Override 38 public boolean hasMipMap(Bitmap bitmap) { 39 return false; 40 } 41 42 @Override 43 public void setHasMipMap(Bitmap bitmap, boolean hasMipMap) { 44 } 45 } 46 47 static class JbMr2BitmapCompatImpl extends BaseBitmapImpl { 48 @Override 49 public boolean hasMipMap(Bitmap bitmap){ 50 return BitmapCompatJellybeanMR2.hasMipMap(bitmap); 51 } 52 53 @Override 54 public void setHasMipMap(Bitmap bitmap, boolean hasMipMap) { 55 BitmapCompatJellybeanMR2.setHasMipMap(bitmap, hasMipMap); 56 } 57 } 58 59 /** 60 * Select the correct implementation to use for the current platform. 61 */ 62 static final BitmapImpl IMPL; 63 static { 64 final int version = android.os.Build.VERSION.SDK_INT; 65 if (version >= 18) { 66 IMPL = new JbMr2BitmapCompatImpl(); 67 } else { 68 IMPL = new BaseBitmapImpl(); 69 } 70 } 71 72 public static boolean hasMipMap(Bitmap bitmap) { 73 return IMPL.hasMipMap(bitmap); 74 } 75 76 public static void setHasMipMap(Bitmap bitmap, boolean hasMipMap) { 77 IMPL.setHasMipMap(bitmap, hasMipMap); 78 } 79}