global: fix theme situation and clean up cruft while adding more cruft
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
752e61d1c7
commit
918076a670
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -6,5 +6,5 @@
|
||||
android:left="8dp"
|
||||
android:right="8dp"
|
||||
android:top="4dp" />
|
||||
<solid android:color="?android:attr/colorPrimary" />
|
||||
<solid android:color="#444444" /> <!-- TODO(msf): themeify this -->
|
||||
</shape>
|
||||
|
@ -4,6 +4,6 @@
|
||||
android:viewportHeight="24"
|
||||
android:viewportWidth="24">
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:fillColor="?android:attr/colorForeground"
|
||||
android:pathData="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2V7H6v12zM19,4h-3.5l-1,-1h-5l-1,1H5v2h14V4z" />
|
||||
</vector>
|
||||
|
@ -1,9 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportHeight="24"
|
||||
android:viewportWidth="24">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2V7H6v12zM19,4h-3.5l-1,-1h-5l-1,1H5v2h14V4z" />
|
||||
</vector>
|
@ -4,6 +4,6 @@
|
||||
android:viewportHeight="24"
|
||||
android:viewportWidth="24">
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:fillColor="?android:attr/colorForeground"
|
||||
android:pathData="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z" />
|
||||
</vector>
|
||||
|
9
app/src/main/res/drawable/ic_action_edit_inverse.xml
Normal file
9
app/src/main/res/drawable/ic_action_edit_inverse.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportHeight="24"
|
||||
android:viewportWidth="24">
|
||||
<path
|
||||
android:fillColor="?android:attr/colorBackground"
|
||||
android:pathData="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z" />
|
||||
</vector>
|
@ -4,6 +4,6 @@
|
||||
android:viewportHeight="24"
|
||||
android:viewportWidth="24">
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:fillColor="?android:attr/colorForeground"
|
||||
android:pathData="M6,2c-1.1,0 -1.99,0.9 -1.99,2L4,20c0,1.1 0.89,2 1.99,2L18,22c1.1,0 2,-0.9 2,-2L20,8l-6,-6L6,2zM13,9L13,3.5L18.5,9L13,9z" />
|
||||
</vector>
|
||||
|
9
app/src/main/res/drawable/ic_action_open_inverse.xml
Normal file
9
app/src/main/res/drawable/ic_action_open_inverse.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportHeight="24"
|
||||
android:viewportWidth="24">
|
||||
<path
|
||||
android:fillColor="?android:attr/colorBackground"
|
||||
android:pathData="M6,2c-1.1,0 -1.99,0.9 -1.99,2L4,20c0,1.1 0.89,2 1.99,2L18,22c1.1,0 2,-0.9 2,-2L20,8l-6,-6L6,2zM13,9L13,3.5L18.5,9L13,9z" />
|
||||
</vector>
|
@ -5,6 +5,6 @@
|
||||
android:viewportHeight="24"
|
||||
android:viewportWidth="24">
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:fillColor="?android:attr/colorForeground"
|
||||
android:pathData="M17,3L5,3c-1.11,0 -2,0.9 -2,2v14c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2L21,7l-4,-4zM12,19c-1.66,0 -3,-1.34 -3,-3s1.34,-3 3,-3 3,1.34 3,3 -1.34,3 -3,3zM15,9L5,9L5,5h10v4z" />
|
||||
</vector>
|
||||
|
@ -4,6 +4,6 @@
|
||||
android:viewportHeight="24"
|
||||
android:viewportWidth="24">
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:fillColor="?android:attr/colorForeground"
|
||||
android:pathData="M19.43,12.98c0.04,-0.32 0.07,-0.64 0.07,-0.98s-0.03,-0.66 -0.07,-0.98l2.11,-1.65c0.19,-0.15 0.24,-0.42 0.12,-0.64l-2,-3.46c-0.12,-0.22 -0.39,-0.3 -0.61,-0.22l-2.49,1c-0.52,-0.4 -1.08,-0.73 -1.69,-0.98l-0.38,-2.65C14.46,2.18 14.25,2 14,2h-4c-0.25,0 -0.46,0.18 -0.49,0.42l-0.38,2.65c-0.61,0.25 -1.17,0.59 -1.69,0.98l-2.49,-1c-0.23,-0.09 -0.49,0 -0.61,0.22l-2,3.46c-0.13,0.22 -0.07,0.49 0.12,0.64l2.11,1.65c-0.04,0.32 -0.07,0.65 -0.07,0.98s0.03,0.66 0.07,0.98l-2.11,1.65c-0.19,0.15 -0.24,0.42 -0.12,0.64l2,3.46c0.12,0.22 0.39,0.3 0.61,0.22l2.49,-1c0.52,0.4 1.08,0.73 1.69,0.98l0.38,2.65c0.03,0.24 0.24,0.42 0.49,0.42h4c0.25,0 0.46,-0.18 0.49,-0.42l0.38,-2.65c0.61,-0.25 1.17,-0.59 1.69,-0.98l2.49,1c0.23,0.09 0.49,0 0.61,-0.22l2,-3.46c0.12,-0.22 0.07,-0.49 -0.12,-0.64l-2.11,-1.65zM12,15.5c-1.93,0 -3.5,-1.57 -3.5,-3.5s1.57,-3.5 3.5,-3.5 3.5,1.57 3.5,3.5 -1.57,3.5 -3.5,3.5z" />
|
||||
</vector>
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="@color/list_item_activated" android:state_activated="true" />
|
||||
<item android:drawable="@android:color/transparent" />
|
||||
<item android:drawable="@color/list_item_activated" android:state_activated="true" /> <!-- TODO(msf): themeify this -->
|
||||
<item android:drawable="@android:color/transparent" /> <!-- TODO(msf): themeify this -->
|
||||
</selector>
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:color="@color/list_item_ripple">
|
||||
android:color="@color/list_item_ripple"> <!-- TODO(msf): themeify this -->
|
||||
<item android:drawable="@drawable/list_item_background" />
|
||||
</ripple>
|
||||
|
@ -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" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/public_key_label"
|
||||
|
@ -44,7 +44,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="@{fragment::onRequestCreateConfig}"
|
||||
app:fab_icon="@drawable/ic_action_edit"
|
||||
app:fab_icon="@drawable/ic_action_edit_inverse"
|
||||
app:fab_size="mini"
|
||||
app:fab_title="@string/create_empty" />
|
||||
|
||||
@ -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" />
|
||||
</com.wireguard.android.widget.fab.FloatingActionsMenu>
|
||||
|
@ -1,5 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<!-- TODO(msf): remove these two hard-coded colors -->
|
||||
<color name="list_item_activated">#cfd8dc</color> <!-- Blue Grey 200 -->
|
||||
<color name="list_item_ripple">#808e95</color> <!-- Blue Grey 200 dark -->
|
||||
|
||||
<!-- TODO(zx2c4): set this once we have a color decided - <color name="accent">#2196F3</color> -->
|
||||
</resources>
|
||||
|
@ -1,7 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar" />
|
||||
<style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar">
|
||||
<!--TODO(zx2c4): set this once we have a color decided: <item name="colorAccent">@color/accent</item>-->
|
||||
</style>
|
||||
|
||||
<style name="SettingsTheme" parent="AppTheme">
|
||||
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
|
||||
@ -9,6 +11,7 @@
|
||||
|
||||
<style name="fab_label" parent="android:TextAppearance.DeviceDefault.Inverse">
|
||||
<item name="android:background">@drawable/fab_label_background</item>
|
||||
<item name="android:textColor">#ffffff</item> <!-- TODO(msf): themeify this -->
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user