• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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.settings.notification.modes;
18 
19 import static com.google.common.base.Preconditions.checkNotNull;
20 
21 import android.content.Context;
22 import android.graphics.drawable.Drawable;
23 import android.graphics.drawable.LayerDrawable;
24 import android.graphics.drawable.ShapeDrawable;
25 import android.graphics.drawable.shapes.OvalShape;
26 
27 import androidx.annotation.DrawableRes;
28 import androidx.annotation.NonNull;
29 
30 import com.android.settings.R;
31 import com.android.settingslib.Utils;
32 
33 class IconUtil {
34 
applyTint(@onNull Context context, @NonNull Drawable icon)35     static Drawable applyTint(@NonNull Context context, @NonNull Drawable icon) {
36         icon = icon.mutate();
37         icon.setTintList(
38                 Utils.getColorAttr(context, android.R.attr.colorControlNormal));
39         return icon;
40     }
41 
42     /**
43      * Returns a variant of the supplied {@code icon} to be used in the icon picker. The inner icon
44      * is 36x36dp and it's contained into a circle of diameter 54dp.
45      */
makeIconCircle(@onNull Context context, @NonNull Drawable icon)46     static Drawable makeIconCircle(@NonNull Context context, @NonNull Drawable icon) {
47         ShapeDrawable background = new ShapeDrawable(new OvalShape());
48         background.getPaint().setColor(Utils.getColorAttrDefaultColor(context,
49                 com.android.internal.R.attr.materialColorSecondaryContainer));
50         icon.setTint(Utils.getColorAttrDefaultColor(context,
51                 com.android.internal.R.attr.materialColorOnSecondaryContainer));
52 
53         LayerDrawable layerDrawable = new LayerDrawable(new Drawable[] { background, icon });
54 
55         int circleDiameter = context.getResources().getDimensionPixelSize(
56                 R.dimen.zen_mode_icon_list_circle_diameter);
57         int iconSize = context.getResources().getDimensionPixelSize(
58                 R.dimen.zen_mode_icon_list_icon_size);
59         int iconPadding = (circleDiameter - iconSize) / 2;
60         layerDrawable.setBounds(0, 0, circleDiameter, circleDiameter);
61         layerDrawable.setLayerInset(1, iconPadding, iconPadding, iconPadding, iconPadding);
62 
63         return layerDrawable;
64     }
65 
makeIconCircle(@onNull Context context, @DrawableRes int iconResId)66     static Drawable makeIconCircle(@NonNull Context context, @DrawableRes int iconResId) {
67         return makeIconCircle(context, checkNotNull(context.getDrawable(iconResId)));
68     }
69 }
70