Aurimas Liutikas | ac5fe7c | 2018-03-06 14:40:53 -0800 | [diff] [blame] | 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 | */ |
| 16 | package androidx.core.graphics; |
| 17 | |
| 18 | import android.graphics.Bitmap; |
| 19 | import android.os.Build; |
Aurimas Liutikas | 9dede51 | 2018-03-13 14:08:08 -0700 | [diff] [blame] | 20 | |
Aurimas Liutikas | ac5fe7c | 2018-03-06 14:40:53 -0800 | [diff] [blame] | 21 | import androidx.annotation.NonNull; |
Aurimas Liutikas | ac5fe7c | 2018-03-06 14:40:53 -0800 | [diff] [blame] | 22 | |
| 23 | /** |
| 24 | * Helper for accessing features in {@link android.graphics.Bitmap}. |
| 25 | */ |
| 26 | public final class BitmapCompat { |
Jake Wharton | 3bbdb0bd | 2018-03-16 18:12:41 -0400 | [diff] [blame] | 27 | public static boolean hasMipMap(@NonNull Bitmap bitmap) { |
| 28 | if (Build.VERSION.SDK_INT >= 18) { |
Aurimas Liutikas | ac5fe7c | 2018-03-06 14:40:53 -0800 | [diff] [blame] | 29 | return bitmap.hasMipMap(); |
| 30 | } |
Jake Wharton | 3bbdb0bd | 2018-03-16 18:12:41 -0400 | [diff] [blame] | 31 | return false; |
Aurimas Liutikas | ac5fe7c | 2018-03-06 14:40:53 -0800 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | public static void setHasMipMap(@NonNull Bitmap bitmap, boolean hasMipMap) { |
Jake Wharton | 3bbdb0bd | 2018-03-16 18:12:41 -0400 | [diff] [blame] | 35 | if (Build.VERSION.SDK_INT >= 18) { |
| 36 | bitmap.setHasMipMap(hasMipMap); |
| 37 | } |
Aurimas Liutikas | ac5fe7c | 2018-03-06 14:40:53 -0800 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Returns the size of the allocated memory used to store this bitmap's pixels in a backwards |
| 42 | * compatible way. |
| 43 | * |
| 44 | * @param bitmap the bitmap in which to return its allocation size |
| 45 | * @return the allocation size in bytes |
| 46 | */ |
| 47 | public static int getAllocationByteCount(@NonNull Bitmap bitmap) { |
Jake Wharton | 3bbdb0bd | 2018-03-16 18:12:41 -0400 | [diff] [blame] | 48 | if (Build.VERSION.SDK_INT >= 19) { |
| 49 | return bitmap.getAllocationByteCount(); |
| 50 | } |
| 51 | return bitmap.getByteCount(); |
Aurimas Liutikas | ac5fe7c | 2018-03-06 14:40:53 -0800 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | private BitmapCompat() {} |
Jake Wharton | 3bbdb0bd | 2018-03-16 18:12:41 -0400 | [diff] [blame] | 55 | } |