1 /*
2  * Copyright (C) 2021 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.car.settings.common;
18 
19 import android.content.res.Resources;
20 import android.content.res.Resources.Theme;
21 import android.graphics.Color;
22 import android.graphics.drawable.GradientDrawable;
23 import android.util.AttributeSet;
24 
25 import com.android.car.settings.R;
26 
27 import org.xmlpull.v1.XmlPullParser;
28 import org.xmlpull.v1.XmlPullParserException;
29 
30 import java.io.IOException;
31 
32 /**
33  * Top-level icon background shape.
34  *
35  * Adapted from {@link com.android.settingslib.widget.AdaptiveIconShapeDrawable}
36  */
37 public class TopLevelIconShapeDrawable extends GradientDrawable {
TopLevelIconShapeDrawable()38     public TopLevelIconShapeDrawable() {
39         super();
40     }
41 
TopLevelIconShapeDrawable(Resources resources)42     public TopLevelIconShapeDrawable(Resources resources) {
43         super();
44         init(resources);
45     }
46 
47     @Override
inflate(Resources r, XmlPullParser parser, AttributeSet attrs, Theme theme)48     public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs, Theme theme)
49             throws XmlPullParserException, IOException {
50         super.inflate(r, parser, attrs, theme);
51         init(r);
52     }
53 
init(Resources resources)54     private void init(Resources resources) {
55         setShape(resources.getInteger(R.integer.config_top_level_icon_shape));
56 
57         boolean showBackground = resources.getBoolean(R.bool.config_show_top_level_icon_background);
58         if (!showBackground) {
59             setColor(Color.TRANSPARENT);
60         }
61     }
62 }
63