mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-09 18:48:51 -06:00
Create color palette for widgets
This commit is contained in:
@@ -28,7 +28,6 @@ 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;
|
||||
@@ -64,7 +63,7 @@ public class CheckmarkWidgetView extends HabitWidgetView implements HabitDataVie
|
||||
ring = (RingView) findViewById(R.id.scoreRing);
|
||||
label = (TextView) findViewById(R.id.label);
|
||||
|
||||
inactiveColor = UIHelper.getStyledColor(getContext(), R.attr.cardBackgroundColor);
|
||||
inactiveColor = ColorHelper.CSV_PALETTE[11];
|
||||
|
||||
if(isInEditMode())
|
||||
{
|
||||
@@ -92,6 +91,7 @@ public class CheckmarkWidgetView extends HabitWidgetView implements HabitDataVie
|
||||
String text;
|
||||
int backgroundColor;
|
||||
int foregroundColor;
|
||||
float alpha;
|
||||
|
||||
switch (checkmarkValue)
|
||||
{
|
||||
@@ -99,24 +99,28 @@ public class CheckmarkWidgetView extends HabitWidgetView implements HabitDataVie
|
||||
text = getResources().getString(R.string.fa_check);
|
||||
backgroundColor = activeColor;
|
||||
foregroundColor = Color.WHITE;
|
||||
alpha = 1.0f;
|
||||
break;
|
||||
|
||||
case Checkmark.CHECKED_IMPLICITLY:
|
||||
text = getResources().getString(R.string.fa_check);
|
||||
backgroundColor = inactiveColor;
|
||||
foregroundColor = UIHelper.getStyledColor(getContext(), R.attr.mediumContrastTextColor);
|
||||
foregroundColor = ColorHelper.CSV_PALETTE[12];
|
||||
alpha = 0.5f;
|
||||
break;
|
||||
|
||||
case Checkmark.UNCHECKED:
|
||||
default:
|
||||
text = getResources().getString(R.string.fa_times);
|
||||
backgroundColor = inactiveColor;
|
||||
foregroundColor = UIHelper.getStyledColor(getContext(), R.attr.mediumContrastTextColor);
|
||||
foregroundColor = ColorHelper.CSV_PALETTE[12];
|
||||
alpha = 0.5f;
|
||||
break;
|
||||
}
|
||||
|
||||
backgroundPaint.setColor(backgroundColor);
|
||||
frame.setBackgroundDrawable(background);
|
||||
setAlpha(alpha);
|
||||
|
||||
ring.setPercentage(percentage);
|
||||
ring.setPrecision(0.125f);
|
||||
@@ -163,4 +167,10 @@ public class CheckmarkWidgetView extends HabitWidgetView implements HabitDataVie
|
||||
{
|
||||
return R.layout.widget_checkmark;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getShadowAlpha()
|
||||
{
|
||||
return 0x4f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ package org.isoron.uhabits.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.RectF;
|
||||
import android.util.AttributeSet;
|
||||
@@ -104,22 +103,10 @@ public class HabitFrequencyView extends ScrollableDataView implements HabitDataV
|
||||
this.primaryColor = ColorHelper.getColor(getContext(), habit.color);
|
||||
}
|
||||
|
||||
if (isBackgroundTransparent)
|
||||
{
|
||||
primaryColor = ColorHelper.setSaturation(primaryColor, 0.75f);
|
||||
primaryColor = ColorHelper.setValue(primaryColor, 1.0f);
|
||||
|
||||
textColor = Color.argb(192, 255, 255, 255);
|
||||
gridColor = Color.argb(128, 255, 255, 255);
|
||||
}
|
||||
else
|
||||
{
|
||||
textColor = UIHelper.getStyledColor(getContext(), R.attr.mediumContrastTextColor);
|
||||
gridColor = UIHelper.getStyledColor(getContext(), R.attr.lowContrastTextColor);
|
||||
}
|
||||
textColor = UIHelper.getStyledColor(getContext(), R.attr.mediumContrastTextColor);
|
||||
gridColor = UIHelper.getStyledColor(getContext(), R.attr.lowContrastTextColor);
|
||||
|
||||
colors = new int[4];
|
||||
|
||||
colors[0] = gridColor;
|
||||
colors[3] = primaryColor;
|
||||
colors[1] = ColorHelper.mixColors(colors[0], colors[3], 0.66f);
|
||||
|
||||
@@ -21,7 +21,6 @@ package org.isoron.uhabits.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffXfermode;
|
||||
@@ -114,20 +113,9 @@ public class HabitScoreView extends ScrollableDataView implements HabitDataView
|
||||
if(habit != null)
|
||||
this.primaryColor = ColorHelper.getColor(getContext(), habit.color);
|
||||
|
||||
if (isBackgroundTransparent)
|
||||
{
|
||||
primaryColor = ColorHelper.setSaturation(primaryColor, 0.75f);
|
||||
primaryColor = ColorHelper.setValue(primaryColor, 1.0f);
|
||||
|
||||
textColor = Color.argb(192, 255, 255, 255);
|
||||
gridColor = Color.argb(128, 255, 255, 255);
|
||||
}
|
||||
else
|
||||
{
|
||||
textColor = UIHelper.getStyledColor(getContext(), R.attr.mediumContrastTextColor);
|
||||
gridColor = UIHelper.getStyledColor(getContext(), R.attr.lowContrastTextColor);
|
||||
backgroundColor = UIHelper.getStyledColor(getContext(), R.attr.cardBackgroundColor);
|
||||
}
|
||||
textColor = UIHelper.getStyledColor(getContext(), R.attr.mediumContrastTextColor);
|
||||
gridColor = UIHelper.getStyledColor(getContext(), R.attr.lowContrastTextColor);
|
||||
backgroundColor = UIHelper.getStyledColor(getContext(), R.attr.cardBackgroundColor);
|
||||
}
|
||||
|
||||
protected void createPaints()
|
||||
|
||||
@@ -127,36 +127,17 @@ public class HabitStreakView extends View implements HabitDataView
|
||||
if(habit != null)
|
||||
this.primaryColor = ColorHelper.getColor(getContext(), habit.color);
|
||||
|
||||
if(isBackgroundTransparent)
|
||||
{
|
||||
primaryColor = ColorHelper.setSaturation(primaryColor, 0.75f);
|
||||
primaryColor = ColorHelper.setValue(primaryColor, 1.0f);
|
||||
}
|
||||
|
||||
int red = Color.red(primaryColor);
|
||||
int green = Color.green(primaryColor);
|
||||
int blue = Color.blue(primaryColor);
|
||||
|
||||
if(isBackgroundTransparent)
|
||||
{
|
||||
colors = new int[4];
|
||||
colors[3] = primaryColor;
|
||||
colors[2] = Color.argb(213, red, green, blue);
|
||||
colors[1] = Color.argb(170, red, green, blue);
|
||||
colors[0] = Color.argb(128, red, green, blue);
|
||||
textColor = Color.WHITE;
|
||||
reverseTextColor = Color.WHITE;
|
||||
}
|
||||
else
|
||||
{
|
||||
colors = new int[4];
|
||||
colors[3] = primaryColor;
|
||||
colors[2] = Color.argb(192, red, green, blue);
|
||||
colors[1] = Color.argb(96, red, green, blue);
|
||||
colors[0] = UIHelper.getStyledColor(getContext(), R.attr.lowContrastTextColor);
|
||||
textColor = UIHelper.getStyledColor(getContext(), R.attr.mediumContrastTextColor);
|
||||
reverseTextColor = UIHelper.getStyledColor(getContext(), R.attr.highContrastReverseTextColor);
|
||||
}
|
||||
colors = new int[4];
|
||||
colors[3] = primaryColor;
|
||||
colors[2] = Color.argb(192, red, green, blue);
|
||||
colors[1] = Color.argb(96, red, green, blue);
|
||||
colors[0] = UIHelper.getStyledColor(getContext(), R.attr.lowContrastTextColor);
|
||||
textColor = UIHelper.getStyledColor(getContext(), R.attr.mediumContrastTextColor);
|
||||
reverseTextColor = UIHelper.getStyledColor(getContext(), R.attr.highContrastReverseTextColor);
|
||||
}
|
||||
|
||||
protected void createPaints()
|
||||
|
||||
@@ -72,11 +72,11 @@ public abstract class HabitWidgetView extends FrameLayout implements HabitDataV
|
||||
private void initBackground()
|
||||
{
|
||||
Context context = getContext();
|
||||
context.setTheme(R.style.AppBaseThemeDark);
|
||||
context.setTheme(R.style.DarkWidgetTheme);
|
||||
|
||||
int shadowRadius = (int) UIHelper.dpToPixels(context, 2);
|
||||
int shadowOffset = (int) UIHelper.dpToPixels(context, 1);
|
||||
int shadowColor = Color.argb(96, 0, 0, 0);
|
||||
int shadowColor = Color.argb(getShadowAlpha(), 0, 0, 0);
|
||||
|
||||
float cornerRadius = UIHelper.dpToPixels(context, 5);
|
||||
float[] radii = new float[8];
|
||||
@@ -93,11 +93,17 @@ 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);
|
||||
|
||||
frame = (ViewGroup) findViewById(R.id.frame);
|
||||
frame.setBackgroundDrawable(background);
|
||||
}
|
||||
|
||||
protected int getShadowAlpha()
|
||||
{
|
||||
return 0x2f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHabit(@NonNull Habit habit)
|
||||
{
|
||||
|
||||
@@ -35,6 +35,7 @@ public class ScoreWidgetProvider extends BaseWidgetProvider
|
||||
protected View buildCustomView(Context context, Habit habit)
|
||||
{
|
||||
HabitScoreView dataView = new HabitScoreView(context);
|
||||
dataView.setIsBackgroundTransparent(true);
|
||||
GraphWidgetView view = new GraphWidgetView(context, dataView);
|
||||
view.setHabit(habit);
|
||||
return view;
|
||||
|
||||
Reference in New Issue
Block a user