diff --git a/app/src/main/java/com/wireguard/android/widget/fab/AddFloatingActionButton.java b/app/src/main/java/com/wireguard/android/widget/fab/AddFloatingActionButton.java index d83050d9..e688a11a 100644 --- a/app/src/main/java/com/wireguard/android/widget/fab/AddFloatingActionButton.java +++ b/app/src/main/java/com/wireguard/android/widget/fab/AddFloatingActionButton.java @@ -16,6 +16,7 @@ import android.graphics.drawable.ShapeDrawable; import android.graphics.drawable.shapes.Shape; import android.support.annotation.ColorRes; import android.support.annotation.DrawableRes; +import android.support.v4.content.ContextCompat; import android.util.AttributeSet; import com.wireguard.android.R; @@ -38,7 +39,7 @@ public class AddFloatingActionButton extends FloatingActionButton { @Override void init(final Context context, final AttributeSet attributeSet) { final TypedArray attr = context.obtainStyledAttributes(attributeSet, R.styleable.AddFloatingActionButton, 0, 0); - mPlusColor = attr.getColor(R.styleable.AddFloatingActionButton_fab_plusIconColor, getColor(android.R.color.white)); + mPlusColor = attr.getColor(R.styleable.AddFloatingActionButton_fab_plusIconColor, FloatingActionButton.getColorFromTheme(context, android.R.attr.colorBackground, android.R.color.white)); attr.recycle(); super.init(context, attributeSet); @@ -59,7 +60,7 @@ public class AddFloatingActionButton extends FloatingActionButton { } public void setPlusColorResId(@ColorRes final int plusColor) { - setPlusColor(getColor(plusColor)); + setPlusColor(ContextCompat.getColor(getContext(), plusColor)); } @Override 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 3395ae44..a8d937ef 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 @@ -15,6 +15,8 @@ import android.graphics.drawable.*; 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.widget.TextView; @@ -56,15 +58,25 @@ 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(); + } + } + void init(final Context context, final AttributeSet attributeSet) { final TypedArray attr = context.obtainStyledAttributes(attributeSet, R.styleable.FloatingActionButton, 0, 0); mColorNormal = attr.getColor(R.styleable.FloatingActionButton_fab_colorNormal, - getColor(R.color.color_accent)); + getColorFromTheme(context, android.R.attr.colorAccent, android.R.color.holo_blue_bright)); mColorPressed = attr.getColor(R.styleable.FloatingActionButton_fab_colorPressed, - getColor(R.color.color_accent_dark)); + darkenOrLightenColor(mColorNormal)); //TODO(msf): use getColorForState on the accent color from theme instead to get darker states mColorDisabled = attr.getColor(R.styleable.FloatingActionButton_fab_colorDisabled, - getColor(android.R.color.darker_gray)); + ContextCompat.getColor(context, android.R.color.darker_gray)); //TODO(msf): load from theme mSize = attr.getInt(R.styleable.FloatingActionButton_fab_size, SIZE_NORMAL); mIcon = attr.getResourceId(R.styleable.FloatingActionButton_fab_icon, 0); mTitle = attr.getString(R.styleable.FloatingActionButton_fab_title); @@ -128,7 +140,7 @@ public class FloatingActionButton extends AppCompatImageButton { } public void setColorNormalResId(@ColorRes final int colorNormal) { - setColorNormal(getColor(colorNormal)); + setColorNormal(ContextCompat.getColor(getContext(), colorNormal)); } /** @@ -146,7 +158,7 @@ public class FloatingActionButton extends AppCompatImageButton { } public void setColorPressedResId(@ColorRes final int colorPressed) { - setColorPressed(getColor(colorPressed)); + setColorPressed(ContextCompat.getColor(getContext(), colorPressed)); } /** @@ -164,7 +176,7 @@ public class FloatingActionButton extends AppCompatImageButton { } public void setColorDisabledResId(@ColorRes final int colorDisabled) { - setColorDisabled(getColor(colorDisabled)); + setColorDisabled(ContextCompat.getColor(getContext(), colorDisabled)); } public boolean isStrokeVisible() { @@ -178,10 +190,6 @@ public class FloatingActionButton extends AppCompatImageButton { } } - int getColor(@ColorRes final int id) { - return getResources().getColor(id); - } - float getDimension(@DimenRes final int id) { return getResources().getDimension(id); } @@ -251,7 +259,7 @@ public class FloatingActionButton extends AppCompatImageButton { if (mIconDrawable != null) { return mIconDrawable; } else if (mIcon != 0) { - return getResources().getDrawable(mIcon, null); + return ContextCompat.getDrawable(getContext(), mIcon); } else { return new ColorDrawable(Color.TRANSPARENT); } @@ -311,7 +319,7 @@ public class FloatingActionButton extends AppCompatImageButton { return shapeDrawable; } - private int opacityToAlpha(final float opacity) { + private static int opacityToAlpha(final float opacity) { return (int) (255f * opacity); } @@ -323,6 +331,19 @@ public class FloatingActionButton extends AppCompatImageButton { return adjustColorBrightness(argb, 1.1f); } + public static int darkenOrLightenColor(final int argb) { + final float[] hsv = new float[3]; + Color.colorToHSV(argb, hsv); + final float factor; + if (hsv[2] < 0.2) + factor = 1.2f; + else + factor = 0.8f; + + hsv[2] = Math.min(hsv[2] * factor, 1f); + return Color.HSVToColor(Color.alpha(argb), hsv); + } + private static int adjustColorBrightness(final int argb, final float factor) { final float[] hsv = new float[3]; Color.colorToHSV(argb, hsv); diff --git a/app/src/main/java/com/wireguard/android/widget/fab/FloatingActionsMenu.java b/app/src/main/java/com/wireguard/android/widget/fab/FloatingActionsMenu.java index 02546e13..2733e77e 100644 --- a/app/src/main/java/com/wireguard/android/widget/fab/FloatingActionsMenu.java +++ b/app/src/main/java/com/wireguard/android/widget/fab/FloatingActionsMenu.java @@ -14,6 +14,7 @@ import android.animation.TimeInterpolator; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Canvas; +import android.graphics.Color; import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; @@ -22,6 +23,7 @@ import android.os.Parcelable; import android.support.annotation.ColorRes; import android.support.annotation.Keep; import android.support.annotation.NonNull; +import android.support.v4.content.ContextCompat; import android.support.v7.widget.AppCompatTextView; import android.util.AttributeSet; import android.view.ContextThemeWrapper; @@ -97,11 +99,11 @@ public class FloatingActionsMenu extends ViewGroup { final TypedArray attr = context.obtainStyledAttributes(attributeSet, R.styleable.FloatingActionsMenu, 0, 0); mAddButtonPlusColor = attr.getColor(R.styleable.FloatingActionsMenu_fab_addButtonPlusIconColor, - getColor(android.R.color.white)); + FloatingActionButton.getColorFromTheme(context, android.R.attr.colorBackground, android.R.color.white)); mAddButtonColorNormal = attr.getColor(R.styleable.FloatingActionsMenu_fab_addButtonColorNormal, - getColor(R.color.color_accent)); + FloatingActionButton.getColorFromTheme(context, android.R.attr.colorAccent, android.R.color.holo_blue_bright)); mAddButtonColorPressed = attr.getColor(R.styleable.FloatingActionsMenu_fab_addButtonColorPressed, - getColor(R.color.color_accent_dark)); + FloatingActionButton.darkenOrLightenColor(mAddButtonColorNormal)); //TODO(msf): use getColorForState on the accent color from theme instead to get darker states mAddButtonSize = attr.getInt(R.styleable.FloatingActionsMenu_fab_addButtonSize, FloatingActionButton.SIZE_NORMAL); mAddButtonStrokeVisible = attr.getBoolean(R.styleable.FloatingActionsMenu_fab_addButtonStrokeVisible, true); mExpandDirection = attr.getInt(R.styleable.FloatingActionsMenu_fab_expandDirection, EXPAND_UP); @@ -179,10 +181,6 @@ public class FloatingActionsMenu extends ViewGroup { mButtonsCount--; } - private int getColor(@ColorRes final int id) { - return getResources().getColor(id); - } - @Override protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) { measureChildren(widthMeasureSpec, heightMeasureSpec); diff --git a/app/src/main/res/drawable/fab_label_background.xml b/app/src/main/res/drawable/fab_label_background.xml index c0315fd6..d626f442 100644 --- a/app/src/main/res/drawable/fab_label_background.xml +++ b/app/src/main/res/drawable/fab_label_background.xml @@ -6,5 +6,5 @@ android:left="8dp" android:right="8dp" android:top="4dp" /> - + diff --git a/app/src/main/res/drawable/ic_action_delete.xml b/app/src/main/res/drawable/ic_action_delete.xml index 617ba001..34f27019 100644 --- a/app/src/main/res/drawable/ic_action_delete.xml +++ b/app/src/main/res/drawable/ic_action_delete.xml @@ -4,6 +4,6 @@ android:viewportHeight="24" android:viewportWidth="24"> diff --git a/app/src/main/res/drawable/ic_action_delete_black.xml b/app/src/main/res/drawable/ic_action_delete_black.xml deleted file mode 100644 index 8fc53e7b..00000000 --- a/app/src/main/res/drawable/ic_action_delete_black.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/app/src/main/res/drawable/ic_action_edit.xml b/app/src/main/res/drawable/ic_action_edit.xml index a0607f54..0a4d120e 100644 --- a/app/src/main/res/drawable/ic_action_edit.xml +++ b/app/src/main/res/drawable/ic_action_edit.xml @@ -4,6 +4,6 @@ android:viewportHeight="24" android:viewportWidth="24"> diff --git a/app/src/main/res/drawable/ic_action_edit_inverse.xml b/app/src/main/res/drawable/ic_action_edit_inverse.xml new file mode 100644 index 00000000..f1324ffb --- /dev/null +++ b/app/src/main/res/drawable/ic_action_edit_inverse.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_action_open.xml b/app/src/main/res/drawable/ic_action_open.xml index 55cb1248..ea56ba01 100644 --- a/app/src/main/res/drawable/ic_action_open.xml +++ b/app/src/main/res/drawable/ic_action_open.xml @@ -4,6 +4,6 @@ android:viewportHeight="24" android:viewportWidth="24"> diff --git a/app/src/main/res/drawable/ic_action_open_inverse.xml b/app/src/main/res/drawable/ic_action_open_inverse.xml new file mode 100644 index 00000000..9836107c --- /dev/null +++ b/app/src/main/res/drawable/ic_action_open_inverse.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_action_save.xml b/app/src/main/res/drawable/ic_action_save.xml index e572f978..690d119d 100644 --- a/app/src/main/res/drawable/ic_action_save.xml +++ b/app/src/main/res/drawable/ic_action_save.xml @@ -5,6 +5,6 @@ android:viewportHeight="24" android:viewportWidth="24"> diff --git a/app/src/main/res/drawable/ic_settings.xml b/app/src/main/res/drawable/ic_settings.xml index 8025452c..59577a40 100644 --- a/app/src/main/res/drawable/ic_settings.xml +++ b/app/src/main/res/drawable/ic_settings.xml @@ -4,6 +4,6 @@ android:viewportHeight="24" android:viewportWidth="24"> diff --git a/app/src/main/res/drawable/list_item_background.xml b/app/src/main/res/drawable/list_item_background.xml index f005ac1d..28d33737 100644 --- a/app/src/main/res/drawable/list_item_background.xml +++ b/app/src/main/res/drawable/list_item_background.xml @@ -1,5 +1,5 @@ - - + + diff --git a/app/src/main/res/drawable/list_item_background_anim.xml b/app/src/main/res/drawable/list_item_background_anim.xml index 2e962eb1..98bfded9 100644 --- a/app/src/main/res/drawable/list_item_background_anim.xml +++ b/app/src/main/res/drawable/list_item_background_anim.xml @@ -1,5 +1,5 @@ + android:color="@color/list_item_ripple"> diff --git a/app/src/main/res/layout/tunnel_editor_peer.xml b/app/src/main/res/layout/tunnel_editor_peer.xml index 40e16136..309ef7bb 100644 --- a/app/src/main/res/layout/tunnel_editor_peer.xml +++ b/app/src/main/res/layout/tunnel_editor_peer.xml @@ -51,7 +51,7 @@ android:background="@null" android:contentDescription="@string/delete" android:onClick="@{() -> collection.remove(item)}" - android:src="@drawable/ic_action_delete_black" /> + android:src="@drawable/ic_action_delete" /> @@ -53,7 +53,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="@{fragment::onRequestImportConfig}" - app:fab_icon="@drawable/ic_action_open" + app:fab_icon="@drawable/ic_action_open_inverse" app:fab_size="mini" app:fab_title="@string/create_from_file" /> diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 47a2d2b4..bb3b6e9b 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -1,5 +1,8 @@ + #cfd8dc #808e95 + + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 1fda6aa6..f5cd3814 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,7 +1,9 @@ -