Tweak transparency and colors

pull/84/merge
Alinson S. Xavier 10 years ago
parent 8b18e32a16
commit 7977d5247c

@ -230,6 +230,16 @@ public abstract class UIHelper
return bool; return bool;
} }
public static float getStyledFloat(Context context, int attrId)
{
int[] attrs = new int[]{ attrId };
TypedArray ta = context.obtainStyledAttributes(attrs);
float f = ta.getFloat(0, 0);
ta.recycle();
return f;
}
static int getStyleResource(Context context, int attrId) static int getStyleResource(Context context, int attrId)
{ {
int[] attr = new int[] { attrId }; int[] attr = new int[] { attrId };

@ -20,7 +20,6 @@
package org.isoron.uhabits.views; package org.isoron.uhabits.views;
import android.content.Context; import android.content.Context;
import android.graphics.Color;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.util.AttributeSet; import android.util.AttributeSet;
@ -28,6 +27,7 @@ import android.widget.TextView;
import org.isoron.uhabits.R; import org.isoron.uhabits.R;
import org.isoron.uhabits.helpers.ColorHelper; import org.isoron.uhabits.helpers.ColorHelper;
import org.isoron.uhabits.helpers.UIHelper;
import org.isoron.uhabits.models.Checkmark; import org.isoron.uhabits.models.Checkmark;
import org.isoron.uhabits.models.Habit; import org.isoron.uhabits.models.Habit;
import org.isoron.uhabits.models.Score; import org.isoron.uhabits.models.Score;
@ -44,7 +44,6 @@ public class CheckmarkWidgetView extends HabitWidgetView implements HabitDataVie
private RingView ring; private RingView ring;
private TextView label; private TextView label;
private int checkmarkValue; private int checkmarkValue;
private int inactiveColor;
public CheckmarkWidgetView(Context context) public CheckmarkWidgetView(Context context)
{ {
@ -63,8 +62,6 @@ public class CheckmarkWidgetView extends HabitWidgetView implements HabitDataVie
ring = (RingView) findViewById(R.id.scoreRing); ring = (RingView) findViewById(R.id.scoreRing);
label = (TextView) findViewById(R.id.label); label = (TextView) findViewById(R.id.label);
inactiveColor = ColorHelper.CSV_PALETTE[11];
if(isInEditMode()) if(isInEditMode())
{ {
percentage = 0.75f; percentage = 0.75f;
@ -80,7 +77,7 @@ public class CheckmarkWidgetView extends HabitWidgetView implements HabitDataVie
{ {
super.setHabit(habit); super.setHabit(habit);
this.name = habit.name; this.name = habit.name;
this.activeColor = ColorHelper.CSV_PALETTE[habit.color]; this.activeColor = ColorHelper.getColor(getContext(), habit.color);
refresh(); refresh();
} }
@ -88,40 +85,41 @@ public class CheckmarkWidgetView extends HabitWidgetView implements HabitDataVie
{ {
if (backgroundPaint == null || frame == null || ring == null) return; if (backgroundPaint == null || frame == null || ring == null) return;
Context context = getContext();
String text; String text;
int backgroundColor; int backgroundColor;
int foregroundColor; int foregroundColor;
float alpha;
switch (checkmarkValue) switch (checkmarkValue)
{ {
case Checkmark.CHECKED_EXPLICITLY: case Checkmark.CHECKED_EXPLICITLY:
text = getResources().getString(R.string.fa_check); text = getResources().getString(R.string.fa_check);
backgroundColor = activeColor; backgroundColor = activeColor;
foregroundColor = Color.WHITE; foregroundColor =
alpha = 1.0f; UIHelper.getStyledColor(context, R.attr.highContrastReverseTextColor);
setShadowAlpha(0x4f);
rebuildBackground();
backgroundPaint.setColor(backgroundColor);
frame.setBackgroundDrawable(background);
break; break;
case Checkmark.CHECKED_IMPLICITLY: case Checkmark.CHECKED_IMPLICITLY:
text = getResources().getString(R.string.fa_check); text = getResources().getString(R.string.fa_check);
backgroundColor = inactiveColor; backgroundColor = UIHelper.getStyledColor(context, R.attr.cardBackgroundColor);
foregroundColor = ColorHelper.CSV_PALETTE[12]; foregroundColor = UIHelper.getStyledColor(context, R.attr.mediumContrastTextColor);
alpha = 0.5f;
break; break;
case Checkmark.UNCHECKED: case Checkmark.UNCHECKED:
default: default:
text = getResources().getString(R.string.fa_times); text = getResources().getString(R.string.fa_times);
backgroundColor = inactiveColor; backgroundColor = UIHelper.getStyledColor(context, R.attr.cardBackgroundColor);
foregroundColor = ColorHelper.CSV_PALETTE[12]; foregroundColor = UIHelper.getStyledColor(context, R.attr.mediumContrastTextColor);
alpha = 0.5f;
break; break;
} }
backgroundPaint.setColor(backgroundColor);
frame.setBackgroundDrawable(background);
setAlpha(alpha);
ring.setPercentage(percentage); ring.setPercentage(percentage);
ring.setPrecision(0.125f); ring.setPrecision(0.125f);
ring.setColor(foregroundColor); ring.setColor(foregroundColor);
@ -167,10 +165,4 @@ public class CheckmarkWidgetView extends HabitWidgetView implements HabitDataVie
{ {
return R.layout.widget_checkmark; return R.layout.widget_checkmark;
} }
@Override
protected int getShadowAlpha()
{
return 0x4f;
}
} }

@ -49,6 +49,13 @@ public abstract class HabitWidgetView extends FrameLayout implements HabitDataV
protected Habit habit; protected Habit habit;
protected ViewGroup frame; protected ViewGroup frame;
public void setShadowAlpha(int shadowAlpha)
{
this.shadowAlpha = shadowAlpha;
}
private int shadowAlpha;
public HabitWidgetView(Context context) public HabitWidgetView(Context context)
{ {
super(context); super(context);
@ -64,19 +71,23 @@ public abstract class HabitWidgetView extends FrameLayout implements HabitDataV
private void init() private void init()
{ {
inflate(getContext(), getInnerLayoutId(), this); inflate(getContext(), getInnerLayoutId(), this);
initBackground(); shadowAlpha = (int) (255 * UIHelper.getStyledFloat(getContext(), R.attr.widgetShadowAlpha));
rebuildBackground();
} }
protected abstract @NonNull Integer getInnerLayoutId(); protected abstract @NonNull Integer getInnerLayoutId();
private void initBackground() protected void rebuildBackground()
{ {
Context context = getContext(); Context context = getContext();
context.setTheme(R.style.DarkWidgetTheme); context.setTheme(R.style.TransparentWidgetTheme);
int backgroundAlpha =
(int) (255 * UIHelper.getStyledFloat(context, R.attr.widgetBackgroundAlpha));
int shadowRadius = (int) UIHelper.dpToPixels(context, 2); int shadowRadius = (int) UIHelper.dpToPixels(context, 2);
int shadowOffset = (int) UIHelper.dpToPixels(context, 1); int shadowOffset = (int) UIHelper.dpToPixels(context, 1);
int shadowColor = Color.argb(getShadowAlpha(), 0, 0, 0); int shadowColor = Color.argb(shadowAlpha, 0, 0, 0);
float cornerRadius = UIHelper.dpToPixels(context, 5); float cornerRadius = UIHelper.dpToPixels(context, 5);
float[] radii = new float[8]; float[] radii = new float[8];
@ -93,17 +104,12 @@ public abstract class HabitWidgetView extends FrameLayout implements HabitDataV
backgroundPaint = innerDrawable.getPaint(); backgroundPaint = innerDrawable.getPaint();
backgroundPaint.setShadowLayer(shadowRadius, shadowOffset, shadowOffset, shadowColor); backgroundPaint.setShadowLayer(shadowRadius, shadowOffset, shadowOffset, shadowColor);
backgroundPaint.setColor(UIHelper.getStyledColor(context, R.attr.cardBackgroundColor)); backgroundPaint.setColor(UIHelper.getStyledColor(context, R.attr.cardBackgroundColor));
backgroundPaint.setAlpha(0x1f); backgroundPaint.setAlpha(backgroundAlpha);
frame = (ViewGroup) findViewById(R.id.frame); frame = (ViewGroup) findViewById(R.id.frame);
frame.setBackgroundDrawable(background); frame.setBackgroundDrawable(background);
} }
protected int getShadowAlpha()
{
return 0x2f;
}
@Override @Override
public void setHabit(@NonNull Habit habit) public void setHabit(@NonNull Habit habit)
{ {

@ -32,13 +32,9 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="1" android:layout_weight="1"
habit:percentage="0.25"
habit:thickness="2" habit:thickness="2"
habit:textSize="16" habit:textSize="16"
habit:color="@color/white"
habit:inactiveColor="@color/white"
habit:enableFontAwesome="true" habit:enableFontAwesome="true"
habit:text="@string/fa_check"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:layout_marginLeft="12dp" android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"/> android:layout_marginRight="12dp"/>

@ -44,6 +44,9 @@
<attr name="toolbarPopupTheme" format="reference"/> <attr name="toolbarPopupTheme" format="reference"/>
<attr name="widgetShadowAlpha" format="float"/>
<attr name="widgetBackgroundAlpha" format="float"/>
<!-- Pre-Lollipop --> <!-- Pre-Lollipop -->
<attr name="cardBackground" format="reference"/> <attr name="cardBackground" format="reference"/>
<attr name="headerBackground" format="reference"/> <attr name="headerBackground" format="reference"/>

@ -48,15 +48,15 @@
<item>@color/grey_500</item> <item>@color/grey_500</item>
</array> </array>
<array name="darkWidgetPalette"> <array name="transparentWidgetPalette">
<item>@color/red_900</item> <item>@color/red_800</item>
<item>@color/deep_orange_900</item> <item>@color/deep_orange_800</item>
<item>@color/yellow_900</item> <item>@color/yellow_800</item>
<item>@color/lime_800</item> <item>@color/lime_800</item>
<item>@color/green_800</item> <item>@color/green_700</item>
<item>@color/teal_800</item> <item>@color/teal_700</item>
<item>@color/cyan_800</item> <item>@color/cyan_700</item>
<item>@color/light_blue_800</item> <item>@color/light_blue_700</item>
<item>@color/deep_purple_700</item> <item>@color/deep_purple_700</item>
<item>@color/purple_700</item> <item>@color/purple_700</item>
<item>@color/pink_700</item> <item>@color/pink_700</item>

@ -44,12 +44,12 @@
<item name="palette">@array/lightPalette</item> <item name="palette">@array/lightPalette</item>
<item name="highContrastReverseTextColor">@color/white</item> <item name="highContrastReverseTextColor">@color/white</item>
<item name="mediumContrastReverseTextColor">@color/grey_500</item> <item name="mediumContrastReverseTextColor">@color/white_a6</item>
<item name="lowContrastReverseTextColor">@color/grey_700</item> <item name="lowContrastReverseTextColor">@color/white_a2</item>
<item name="highContrastTextColor">@color/grey_800</item> <item name="highContrastTextColor">@color/black_aa</item>
<item name="mediumContrastTextColor">@color/grey_500</item> <item name="mediumContrastTextColor">@color/black_a6</item>
<item name="lowContrastTextColor">@color/grey_300</item> <item name="lowContrastTextColor">@color/black_a2</item>
<item name="iconAdd">@drawable/ic_action_add_dark</item> <item name="iconAdd">@drawable/ic_action_add_dark</item>
<item name="iconArchive">@drawable/ic_action_archive_dark</item> <item name="iconArchive">@drawable/ic_action_archive_dark</item>
@ -60,6 +60,8 @@
<item name="toolbarPopupTheme">@style/ThemeOverlay.AppCompat.Light</item> <item name="toolbarPopupTheme">@style/ThemeOverlay.AppCompat.Light</item>
<item name="aboutScreenColor">@color/blue_800</item> <item name="aboutScreenColor">@color/blue_800</item>
<item name="widgetShadowAlpha">0.25</item>
<item name="widgetBackgroundAlpha">1</item>
</style> </style>
<style name="SmallSpinner"> <style name="SmallSpinner">
@ -109,6 +111,9 @@
<item name="palette">@array/darkPalette</item> <item name="palette">@array/darkPalette</item>
<item name="aboutScreenColor">@color/blue_300</item> <item name="aboutScreenColor">@color/blue_300</item>
<item name="widgetShadowAlpha">0.25</item>
<item name="widgetBackgroundAlpha">1</item>
</style> </style>
<style name="AppBaseThemeDark.PureBlack"> <style name="AppBaseThemeDark.PureBlack">
@ -127,18 +132,21 @@
<item name="highContrastReverseTextColor">@color/black</item> <item name="highContrastReverseTextColor">@color/black</item>
</style> </style>
<style name="DarkWidgetTheme" parent="AppBaseThemeDark"> <style name="TransparentWidgetTheme" parent="AppBaseThemeDark">
<item name="cardBackgroundColor">@color/black</item> <item name="cardBackgroundColor">@color/black</item>
<item name="highContrastTextColor">@color/white</item> <item name="highContrastTextColor">@color/white</item>
<item name="mediumContrastTextColor">@color/white</item> <item name="mediumContrastTextColor">@color/white_ac</item>
<item name="lowContrastTextColor">@color/white_a0</item> <item name="lowContrastTextColor">@color/white_a0</item>
<item name="highContrastReverseTextColor">@color/white</item> <item name="highContrastReverseTextColor">@color/white</item>
<item name="mediumContrastReverseTextColor">@color/grey_500</item> <item name="mediumContrastReverseTextColor">@color/grey_500</item>
<item name="lowContrastReverseTextColor">@color/grey_800</item> <item name="lowContrastReverseTextColor">@color/grey_800</item>
<item name="palette">@array/darkWidgetPalette</item> <item name="palette">@array/transparentWidgetPalette</item>
<item name="widgetShadowAlpha">0</item>
<item name="widgetBackgroundAlpha">0.25</item>
</style> </style>
<style name="time_label"> <style name="time_label">

Loading…
Cancel
Save