blob: 2cefa45163b6dcfb1924d3cf343a1b6f4e3fad9c [file] [log] [blame]
Brad Stenninge07508c2018-11-03 21:45:07 -07001/*
2 * Copyright (C) 2018 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 */
16package com.android.car.theme;
17
18import android.content.Context;
19import android.content.res.TypedArray;
20import android.graphics.drawable.Drawable;
21
22/**
23 * Various utility methods associated with theming.
24 */
25public class Themes {
26
27 /**
davidln81a02992018-11-06 17:17:38 -080028 * Returns the color assigned to the given attribute.
Brad Stenninge07508c2018-11-03 21:45:07 -070029 */
30 public static int getAttrColor(Context context, int attr) {
31 TypedArray ta = context.obtainStyledAttributes(new int[]{attr});
32 int colorAccent = ta.getColor(0, 0);
33 ta.recycle();
34 return colorAccent;
35 }
36
37 /**
davidln81a02992018-11-06 17:17:38 -080038 * Returns the boolean assigned to the given attribute.
Brad Stenninge07508c2018-11-03 21:45:07 -070039 */
40 public static boolean getAttrBoolean(Context context, int attr) {
41 TypedArray ta = context.obtainStyledAttributes(new int[]{attr});
42 boolean value = ta.getBoolean(0, false);
43 ta.recycle();
44 return value;
45 }
46
47 /**
davidln81a02992018-11-06 17:17:38 -080048 * Returns the Drawable assigned to the given attribute.
Brad Stenninge07508c2018-11-03 21:45:07 -070049 */
50 public static Drawable getAttrDrawable(Context context, int attr) {
51 TypedArray ta = context.obtainStyledAttributes(new int[]{attr});
52 Drawable value = ta.getDrawable(0);
53 ta.recycle();
54 return value;
55 }
56
57 /**
davidln81a02992018-11-06 17:17:38 -080058 * Returns the Integer assigned to the given attribute.
Brad Stenninge07508c2018-11-03 21:45:07 -070059 */
60 public static int getAttrInteger(Context context, int attr) {
61 TypedArray ta = context.obtainStyledAttributes(new int[]{attr});
62 int value = ta.getInteger(0, 0);
63 ta.recycle();
64 return value;
65 }
davidln81a02992018-11-06 17:17:38 -080066
67 /**
68 * Returns the identifier of the resolved resource assigned to the given attribute.
69 */
70 public static int getAttrResourceId(Context context, int attr) {
71 TypedArray ta = context.obtainStyledAttributes(new int[]{attr});
72 int resId = ta.getResourceId(0, 0);
73 ta.recycle();
74 return resId;
75 }
Brad Stenninge07508c2018-11-03 21:45:07 -070076}