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
17package androidx.core.graphics.drawable;
18
19import android.content.res.Resources;
20import android.graphics.Bitmap;
21import android.graphics.Outline;
22import android.graphics.Rect;
23import android.view.Gravity;
24import android.view.View;
25
26import androidx.annotation.RequiresApi;
27
28@RequiresApi(21)
29class RoundedBitmapDrawable21 extends RoundedBitmapDrawable {
30    protected RoundedBitmapDrawable21(Resources res, Bitmap bitmap) {
31        super(res, bitmap);
32    }
33
34    @Override
35    public void getOutline(Outline outline) {
36        updateDstRect();
37        outline.setRoundRect(mDstRect, getCornerRadius());
38    }
39
40    @Override
41    public void setMipMap(boolean mipMap) {
42        if (mBitmap != null) {
43            mBitmap.setHasMipMap(mipMap);
44            invalidateSelf();
45        }
46    }
47
48    @Override
49    public boolean hasMipMap() {
50        return mBitmap != null && mBitmap.hasMipMap();
51    }
52
53    @Override
54    void gravityCompatApply(int gravity, int bitmapWidth, int bitmapHeight,
55            Rect bounds, Rect outRect) {
56        Gravity.apply(gravity, bitmapWidth, bitmapHeight,
57                bounds, outRect, View.LAYOUT_DIRECTION_LTR);
58    }
59}
60