• 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.systemui.tv.media.settings;
18 
19 import android.content.Context;
20 import android.content.res.ColorStateList;
21 import android.content.res.Resources;
22 import android.graphics.drawable.Drawable;
23 import android.graphics.drawable.LayerDrawable;
24 import android.util.Log;
25 import android.view.Gravity;
26 
27 import com.android.systemui.tv.res.R;
28 
29 /**
30  * Get themed settings icon with outer circle.
31  */
32 public class IconUtil {
33     private static final int INSET = 12;
34     private static final String TAG = "IconUtil";
35 
36     /**
37      * Add the border and return the compound icon.
38      */
getCompoundIcon(Context context, Drawable icon)39     public static Drawable getCompoundIcon(Context context, Drawable icon) {
40         Drawable container = context.getDrawable(R.drawable.media_dialog_icon_bg);
41 
42         Resources res = context.getResources();
43         try {
44             ColorStateList colorStateList = res.getColorStateList(R.color.media_dialog_icon);
45             icon.setTintList(colorStateList);
46         } catch (Exception e) {
47             Log.e(TAG, "Cannot set tint", e);
48 
49         }
50 
51         LayerDrawable compoundDrawable = new LayerDrawable(new Drawable[] {container, icon});
52         compoundDrawable.setLayerGravity(0, Gravity.CENTER);
53         compoundDrawable.setLayerGravity(1, Gravity.CENTER);
54         compoundDrawable.setLayerInset(1, INSET, INSET, INSET, INSET);
55         return compoundDrawable;
56     }
57 }
58