summaryrefslogtreecommitdiffhomepage
path: root/app/src/main/java/com/wireguard
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2018-06-01 17:11:22 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2018-06-01 18:42:19 +0530
commit4edfdd8f3bf39fb578ef61e0c21cd06d0bb8a15d (patch)
tree0e0d93c561a8d458daf64f62201cab58daa7ff1b /app/src/main/java/com/wireguard
parent32d669a661edec69f88f5d2646071de761b87630 (diff)
FloatingActionButton: Make attribute grabbing not be terrible
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'app/src/main/java/com/wireguard')
-rw-r--r--app/src/main/java/com/wireguard/android/widget/fab/FloatingActionButton.java16
1 files changed, 8 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 a8d937ef..d132be59 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,6 +7,7 @@
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;
@@ -16,9 +17,9 @@ import android.graphics.drawable.ShapeDrawable.ShaderFactory;
import android.graphics.drawable.shapes.OvalShape;
import android.support.annotation.*;
import android.support.v4.content.ContextCompat;
-import android.support.v7.app.AppCompatDelegate;
import android.support.v7.widget.AppCompatImageButton;
import android.util.AttributeSet;
+import android.util.TypedValue;
import android.widget.TextView;
import com.wireguard.android.R;
@@ -58,14 +59,13 @@ public class FloatingActionButton extends AppCompatImageButton {
init(context, attrs);
}
- //TODO(msf): make not terrible
public static int getColorFromTheme(final Context context, final int themeResource, @ColorRes final int fallback) {
- TypedArray a = context.getTheme().obtainStyledAttributes(new int[]{themeResource});
- try {
- return a.getColor(0, ContextCompat.getColor(context, fallback));
- } finally {
- a.recycle();
- }
+ 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;
+
}
void init(final Context context, final AttributeSet attributeSet) {