diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-06-05 02:36:52 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-06-05 02:44:32 +0200 |
commit | d636e137176c108a637a80f39aff34e7aaaa7c52 (patch) | |
tree | 19968e0a13175245b9257c28614aad38d12b885e /app/src | |
parent | dea60e13c0f32d5e1f2b6f36e5657ff7350894ce (diff) |
fab: properly get theme color
Harsh changed this before, but my original way is what the support
library does internally.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src')
-rw-r--r-- | app/src/main/java/com/wireguard/android/widget/fab/FloatingActionButton.java | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/app/src/main/java/com/wireguard/android/widget/fab/FloatingActionButton.java b/app/src/main/java/com/wireguard/android/widget/fab/FloatingActionButton.java index de9b8f37..6ef38b56 100644 --- a/app/src/main/java/com/wireguard/android/widget/fab/FloatingActionButton.java +++ b/app/src/main/java/com/wireguard/android/widget/fab/FloatingActionButton.java @@ -7,7 +7,6 @@ package com.wireguard.android.widget.fab; import android.content.Context; -import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.*; import android.graphics.Paint.Style; @@ -19,7 +18,6 @@ import android.support.annotation.*; import android.support.v4.content.ContextCompat; import android.support.v7.widget.AppCompatImageButton; import android.util.AttributeSet; -import android.util.TypedValue; import android.widget.TextView; import com.wireguard.android.R; @@ -60,12 +58,12 @@ public class FloatingActionButton extends AppCompatImageButton { } public static int getColorFromTheme(final Context context, final int themeResource, @ColorRes final int fallback) { - final TypedValue typedValue = new TypedValue(); - final Resources.Theme theme = context.getTheme(); - theme.resolveAttribute(themeResource, typedValue, true); - @ColorInt final int color = typedValue.data; - return color == 0 ? fallback : color; - + final TypedArray a = context.obtainStyledAttributes(new int[]{themeResource}); + try { + return a.getColor(0, ContextCompat.getColor(context, fallback)); + } finally { + a.recycle(); + } } void init(final Context context, final AttributeSet attributeSet) { @@ -222,6 +220,7 @@ public class FloatingActionButton extends AppCompatImageButton { final LayerDrawable layerDrawable = new LayerDrawable( new Drawable[]{ + //TODO(msf); replace these pngs with programatic elevation getResources().getDrawable(mSize == SIZE_NORMAL ? R.drawable.fab_bg_normal : R.drawable.fab_bg_mini, null), createFillDrawable(strokeWidth), createOuterStrokeDrawable(strokeWidth), |