/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package androidx.core.graphics;

import android.graphics.Bitmap;
import android.os.Build;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;

/**
 * Helper for accessing features in {@link android.graphics.Bitmap}.
 */
public final class BitmapCompat {
    static class BitmapCompatBaseImpl {
        public boolean hasMipMap(Bitmap bitmap) {
            return false;
        }

        public void setHasMipMap(Bitmap bitmap, boolean hasMipMap) {
        }

        public int getAllocationByteCount(Bitmap bitmap) {
            return bitmap.getByteCount();
        }
    }

    @RequiresApi(18)
    static class BitmapCompatApi18Impl extends BitmapCompatBaseImpl {
        @Override
        public boolean hasMipMap(Bitmap bitmap){
            return bitmap.hasMipMap();
        }

        @Override
        public void setHasMipMap(Bitmap bitmap, boolean hasMipMap) {
            bitmap.setHasMipMap(hasMipMap);
        }
    }

    @RequiresApi(19)
    static class BitmapCompatApi19Impl extends BitmapCompatApi18Impl {
        @Override
        public int getAllocationByteCount(Bitmap bitmap) {
            return bitmap.getAllocationByteCount();
        }
    }

    /**
     * Select the correct implementation to use for the current platform.
     */
    static final BitmapCompatBaseImpl IMPL;
    static {
        if (Build.VERSION.SDK_INT >= 19) {
            IMPL = new BitmapCompatApi19Impl();
        } else if (Build.VERSION.SDK_INT >= 18) {
            IMPL = new BitmapCompatApi18Impl();
        } else {
            IMPL = new BitmapCompatBaseImpl();
        }
    }

    public static boolean hasMipMap(@NonNull Bitmap bitmap) {
        return IMPL.hasMipMap(bitmap);
    }

    public static void setHasMipMap(@NonNull Bitmap bitmap, boolean hasMipMap) {
        IMPL.setHasMipMap(bitmap, hasMipMap);
    }

    /**
     * Returns the size of the allocated memory used to store this bitmap's pixels in a backwards
     * compatible way.
     *
     * @param bitmap the bitmap in which to return its allocation size
     * @return the allocation size in bytes
     */
    public static int getAllocationByteCount(@NonNull Bitmap bitmap) {
        return IMPL.getAllocationByteCount(bitmap);
    }

    private BitmapCompat() {}
}
@@ -743,48 +743,8 @@
 ull;
-%0Aimport androidx.annotation.RequiresApi;
 %0A%0A/*
@@ -860,485 +860,107 @@
     
-static class BitmapCompatBaseImpl %7B%0A        public boolean hasMipMap(Bitmap bitmap) %7B%0A            return false;%0A        %7D%0A%0A        public void setHasMipMap(Bitmap bitmap, boolean hasMipMap) %7B%0A        %7D%0A%0A        public int getAllocationByteCount(Bitmap bitmap) %7B%0A            return bitmap.getByteCount();%0A        %7D%0A    %7D%0A%0A    @RequiresApi(18)%0A    static class BitmapCompatApi18Impl extends BitmapCompatBaseImpl %7B%0A        @Override%0A        public boolean hasMipMap(Bitmap bitmap)
+public static boolean hasMipMap(@NonNull Bitmap bitmap) %7B%0A        if (Build.VERSION.SDK_INT %3E= 18) 
 %7B%0A  
@@ -1006,25 +1006,24 @@
       %7D%0A
-%0A
         
 @Overrid
@@ -1010,38 +1010,45 @@
   %7D%0A        
-@Override
+return false;
 %0A    
+%7D%0A%0A
     public v
@@ -1050,954 +1050,153 @@
 lic 
-void setHasMipMap(Bitmap bitmap, boolean hasMipMap) %7B%0A            bitmap.setHasMipMap(hasMipMap);%0A        %7D%0A    %7D%0A%0A    @RequiresApi(19)%0A    static class BitmapCompatApi19Impl extends BitmapCompatApi18Impl %7B%0A        @Override%0A        public int getAllocationByteCount(Bitmap bitmap) %7B%0A            return bitmap.getAllocationByteCount();%0A        %7D%0A    %7D%0A%0A    /**%0A     * Select the correct implementation to use for the current platform.%0A     */%0A    static final BitmapCompatBaseImpl IMPL;%0A    static %7B%0A        if (Build.VERSION.SDK_INT %3E= 19) %7B%0A            IMPL = new BitmapCompatApi19Impl();%0A        %7D else if (Build.VERSION.SDK_INT %3E= 18) %7B%0A            IMPL = new BitmapCompatApi18Impl();%0A        %7D else %7B%0A            IMPL = new BitmapCompatBaseImpl();%0A        %7D%0A    %7D%0A%0A    public static boolean hasMipMap(@NonNull Bitmap bitmap) %7B%0A        return IMPL.hasMipMap(bitmap);%0A    %7D%0A%0A    public static void setHasMipMap(@NonNull Bitmap bitmap, boolean 
+static void setHasMipMap(@NonNull Bitmap bitmap, boolean hasMipMap) %7B%0A        if (Build.VERSION.SDK_INT %3E= 18) %7B%0A            bitmap.setHasMipMap(
 hasM
@@ -1193,34 +1193,33 @@
 ipMap(hasMipMap)
- %7B
+;
 %0A        IMPL.se
@@ -1215,45 +1215,9 @@
     
-IMPL.setHasMipMap(bitmap, hasMipMap);
+%7D
 %0A   
@@ -1542,32 +1542,79 @@
 itmap bitmap) %7B%0A
+        if (Build.VERSION.SDK_INT %3E= 19) %7B%0A    
         return I
@@ -1616,12 +1616,14 @@
 urn 
-IMPL
+bitmap
 .get
@@ -1642,22 +1642,64 @@
 teCount(
-bitmap
+);%0A        %7D%0A        return bitmap.getByteCount(
 );%0A    %7D
@@ -1731,8 +1731,9 @@
 t() %7B%7D%0A%7D
+%0A

Remove BitmapCompat API abstractions.