That fuck shit the fascists are using
1/**
2 * Copyright (C) 2015 Open Whisper Systems
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18package org.tm.archive.util;
19
20import android.content.Context;
21import android.content.res.Resources.Theme;
22import android.content.res.TypedArray;
23import android.graphics.drawable.Drawable;
24import android.util.TypedValue;
25
26import androidx.annotation.ArrayRes;
27import androidx.annotation.AttrRes;
28import androidx.annotation.DimenRes;
29import androidx.annotation.NonNull;
30import androidx.appcompat.content.res.AppCompatResources;
31
32public class ResUtil {
33
34 public static int getColor(Context context, @AttrRes int attr) {
35 final TypedArray styledAttributes = context.obtainStyledAttributes(new int[]{attr});
36 final int result = styledAttributes.getColor(0, -1);
37 styledAttributes.recycle();
38 return result;
39 }
40
41 public static int getDrawableRes(Context c, @AttrRes int attr) {
42 return getDrawableRes(c.getTheme(), attr);
43 }
44
45 public static int getDrawableRes(Theme theme, @AttrRes int attr) {
46 final TypedValue out = new TypedValue();
47 theme.resolveAttribute(attr, out, true);
48 return out.resourceId;
49 }
50
51 public static Drawable getDrawable(Context c, @AttrRes int attr) {
52 return AppCompatResources.getDrawable(c, getDrawableRes(c, attr));
53 }
54
55 public static int[] getResourceIds(Context c, @ArrayRes int array) {
56 final TypedArray typedArray = c.getResources().obtainTypedArray(array);
57 final int[] resourceIds = new int[typedArray.length()];
58 for (int i = 0; i < typedArray.length(); i++) {
59 resourceIds[i] = typedArray.getResourceId(i, 0);
60 }
61 typedArray.recycle();
62 return resourceIds;
63 }
64
65 public static float getFloat(@NonNull Context context, @DimenRes int resId) {
66 TypedValue value = new TypedValue();
67 context.getResources().getValue(resId, value, true);
68 return value.getFloat();
69 }
70}