mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-09 18:48:51 -06:00
Tweak transparency and colors
This commit is contained in:
@@ -230,6 +230,16 @@ public abstract class UIHelper
|
||||
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)
|
||||
{
|
||||
int[] attr = new int[] { attrId };
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
package org.isoron.uhabits.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.AttributeSet;
|
||||
@@ -28,6 +27,7 @@ import android.widget.TextView;
|
||||
|
||||
import org.isoron.uhabits.R;
|
||||
import org.isoron.uhabits.helpers.ColorHelper;
|
||||
import org.isoron.uhabits.helpers.UIHelper;
|
||||
import org.isoron.uhabits.models.Checkmark;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
import org.isoron.uhabits.models.Score;
|
||||
@@ -44,7 +44,6 @@ public class CheckmarkWidgetView extends HabitWidgetView implements HabitDataVie
|
||||
private RingView ring;
|
||||
private TextView label;
|
||||
private int checkmarkValue;
|
||||
private int inactiveColor;
|
||||
|
||||
public CheckmarkWidgetView(Context context)
|
||||
{
|
||||
@@ -63,8 +62,6 @@ public class CheckmarkWidgetView extends HabitWidgetView implements HabitDataVie
|
||||
ring = (RingView) findViewById(R.id.scoreRing);
|
||||
label = (TextView) findViewById(R.id.label);
|
||||
|
||||
inactiveColor = ColorHelper.CSV_PALETTE[11];
|
||||
|
||||
if(isInEditMode())
|
||||
{
|
||||
percentage = 0.75f;
|
||||
@@ -80,7 +77,7 @@ public class CheckmarkWidgetView extends HabitWidgetView implements HabitDataVie
|
||||
{
|
||||
super.setHabit(habit);
|
||||
this.name = habit.name;
|
||||
this.activeColor = ColorHelper.CSV_PALETTE[habit.color];
|
||||
this.activeColor = ColorHelper.getColor(getContext(), habit.color);
|
||||
refresh();
|
||||
}
|
||||
|
||||
@@ -88,40 +85,41 @@ public class CheckmarkWidgetView extends HabitWidgetView implements HabitDataVie
|
||||
{
|
||||
if (backgroundPaint == null || frame == null || ring == null) return;
|
||||
|
||||
Context context = getContext();
|
||||
|
||||
String text;
|
||||
int backgroundColor;
|
||||
int foregroundColor;
|
||||
float alpha;
|
||||
|
||||
switch (checkmarkValue)
|
||||
{
|
||||
case Checkmark.CHECKED_EXPLICITLY:
|
||||
text = getResources().getString(R.string.fa_check);
|
||||
backgroundColor = activeColor;
|
||||
foregroundColor = Color.WHITE;
|
||||
alpha = 1.0f;
|
||||
foregroundColor =
|
||||
UIHelper.getStyledColor(context, R.attr.highContrastReverseTextColor);
|
||||
|
||||
setShadowAlpha(0x4f);
|
||||
rebuildBackground();
|
||||
|
||||
backgroundPaint.setColor(backgroundColor);
|
||||
frame.setBackgroundDrawable(background);
|
||||
break;
|
||||
|
||||
case Checkmark.CHECKED_IMPLICITLY:
|
||||
text = getResources().getString(R.string.fa_check);
|
||||
backgroundColor = inactiveColor;
|
||||
foregroundColor = ColorHelper.CSV_PALETTE[12];
|
||||
alpha = 0.5f;
|
||||
backgroundColor = UIHelper.getStyledColor(context, R.attr.cardBackgroundColor);
|
||||
foregroundColor = UIHelper.getStyledColor(context, R.attr.mediumContrastTextColor);
|
||||
break;
|
||||
|
||||
case Checkmark.UNCHECKED:
|
||||
default:
|
||||
text = getResources().getString(R.string.fa_times);
|
||||
backgroundColor = inactiveColor;
|
||||
foregroundColor = ColorHelper.CSV_PALETTE[12];
|
||||
alpha = 0.5f;
|
||||
backgroundColor = UIHelper.getStyledColor(context, R.attr.cardBackgroundColor);
|
||||
foregroundColor = UIHelper.getStyledColor(context, R.attr.mediumContrastTextColor);
|
||||
break;
|
||||
}
|
||||
|
||||
backgroundPaint.setColor(backgroundColor);
|
||||
frame.setBackgroundDrawable(background);
|
||||
setAlpha(alpha);
|
||||
|
||||
ring.setPercentage(percentage);
|
||||
ring.setPrecision(0.125f);
|
||||
ring.setColor(foregroundColor);
|
||||
@@ -167,10 +165,4 @@ public class CheckmarkWidgetView extends HabitWidgetView implements HabitDataVie
|
||||
{
|
||||
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 ViewGroup frame;
|
||||
|
||||
public void setShadowAlpha(int shadowAlpha)
|
||||
{
|
||||
this.shadowAlpha = shadowAlpha;
|
||||
}
|
||||
|
||||
private int shadowAlpha;
|
||||
|
||||
public HabitWidgetView(Context context)
|
||||
{
|
||||
super(context);
|
||||
@@ -64,19 +71,23 @@ public abstract class HabitWidgetView extends FrameLayout implements HabitDataV
|
||||
private void init()
|
||||
{
|
||||
inflate(getContext(), getInnerLayoutId(), this);
|
||||
initBackground();
|
||||
shadowAlpha = (int) (255 * UIHelper.getStyledFloat(getContext(), R.attr.widgetShadowAlpha));
|
||||
rebuildBackground();
|
||||
}
|
||||
|
||||
protected abstract @NonNull Integer getInnerLayoutId();
|
||||
|
||||
private void initBackground()
|
||||
protected void rebuildBackground()
|
||||
{
|
||||
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 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[] radii = new float[8];
|
||||
@@ -93,17 +104,12 @@ public abstract class HabitWidgetView extends FrameLayout implements HabitDataV
|
||||
backgroundPaint = innerDrawable.getPaint();
|
||||
backgroundPaint.setShadowLayer(shadowRadius, shadowOffset, shadowOffset, shadowColor);
|
||||
backgroundPaint.setColor(UIHelper.getStyledColor(context, R.attr.cardBackgroundColor));
|
||||
backgroundPaint.setAlpha(0x1f);
|
||||
backgroundPaint.setAlpha(backgroundAlpha);
|
||||
|
||||
frame = (ViewGroup) findViewById(R.id.frame);
|
||||
frame.setBackgroundDrawable(background);
|
||||
}
|
||||
|
||||
protected int getShadowAlpha()
|
||||
{
|
||||
return 0x2f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHabit(@NonNull Habit habit)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user