diff options
Diffstat (limited to 'prebuilts/gradle/DarkTheme/Application/src/main/java/com/example/android/darktheme/ColorUtils.java')
-rw-r--r-- | prebuilts/gradle/DarkTheme/Application/src/main/java/com/example/android/darktheme/ColorUtils.java | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/prebuilts/gradle/DarkTheme/Application/src/main/java/com/example/android/darktheme/ColorUtils.java b/prebuilts/gradle/DarkTheme/Application/src/main/java/com/example/android/darktheme/ColorUtils.java new file mode 100644 index 00000000..f831ab0b --- /dev/null +++ b/prebuilts/gradle/DarkTheme/Application/src/main/java/com/example/android/darktheme/ColorUtils.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.android.darktheme; + +import android.content.Context; +import android.content.res.TypedArray; +import android.graphics.Color; + +import androidx.annotation.AttrRes; +import androidx.annotation.ColorInt; +import androidx.annotation.NonNull; + +public class ColorUtils { + + /** + * Queries the theme of the given {@code context} for a theme color. + * + * @param context the context holding the current theme. + * @param attrResId the theme color attribute to resolve. + * @return the theme color + */ + @ColorInt + public static int getThemeColor(@NonNull Context context, @AttrRes int attrResId) { + TypedArray a = context.obtainStyledAttributes(null, new int[]{attrResId}); + try { + return a.getColor(0, Color.MAGENTA); + } finally { + a.recycle(); + } + } +} |