mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -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);
|
||||
}
|
||||
|
||||
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,21 +113,10 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
protected void createPaints()
|
||||
{
|
||||
|
||||
@@ -127,28 +127,10 @@ 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);
|
||||
@@ -157,7 +139,6 @@ public class HabitStreakView extends View implements HabitDataView
|
||||
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;
|
||||
|
||||
@@ -48,6 +48,22 @@
|
||||
<item>@color/grey_500</item>
|
||||
</array>
|
||||
|
||||
<array name="darkWidgetPalette">
|
||||
<item>@color/red_900</item>
|
||||
<item>@color/deep_orange_900</item>
|
||||
<item>@color/yellow_900</item>
|
||||
<item>@color/lime_800</item>
|
||||
<item>@color/green_800</item>
|
||||
<item>@color/teal_800</item>
|
||||
<item>@color/cyan_800</item>
|
||||
<item>@color/light_blue_800</item>
|
||||
<item>@color/deep_purple_700</item>
|
||||
<item>@color/purple_700</item>
|
||||
<item>@color/pink_700</item>
|
||||
<item>@color/black_aa</item>
|
||||
<item>@color/black_aa</item>
|
||||
</array>
|
||||
|
||||
<!-- Time and Date picker -->
|
||||
<color name="circle_background">#f2f2f2</color>
|
||||
<color name="line_background">#cccccc</color>
|
||||
@@ -355,4 +371,22 @@
|
||||
|
||||
<color name="white">#ffffff</color>
|
||||
<color name="black">#000000</color>
|
||||
|
||||
<color name="black_ae">#ef000000</color>
|
||||
<color name="black_ac">#cf000000</color>
|
||||
<color name="black_aa">#af000000</color>
|
||||
<color name="black_a8">#8f000000</color>
|
||||
<color name="black_a6">#6f000000</color>
|
||||
<color name="black_a4">#4f000000</color>
|
||||
<color name="black_a2">#2f000000</color>
|
||||
<color name="black_a0">#0f000000</color>
|
||||
|
||||
<color name="white_ae">#efffffff</color>
|
||||
<color name="white_ac">#cfffffff</color>
|
||||
<color name="white_aa">#afffffff</color>
|
||||
<color name="white_a8">#8fffffff</color>
|
||||
<color name="white_a6">#6fffffff</color>
|
||||
<color name="white_a4">#4fffffff</color>
|
||||
<color name="white_a2">#2fffffff</color>
|
||||
<color name="white_a0">#0fffffff</color>
|
||||
</resources>
|
||||
@@ -127,6 +127,20 @@
|
||||
<item name="highContrastReverseTextColor">@color/black</item>
|
||||
</style>
|
||||
|
||||
<style name="DarkWidgetTheme" parent="AppBaseThemeDark">
|
||||
<item name="cardBackgroundColor">@color/black</item>
|
||||
|
||||
<item name="highContrastTextColor">@color/white</item>
|
||||
<item name="mediumContrastTextColor">@color/white</item>
|
||||
<item name="lowContrastTextColor">@color/white_a0</item>
|
||||
|
||||
<item name="highContrastReverseTextColor">@color/white</item>
|
||||
<item name="mediumContrastReverseTextColor">@color/grey_500</item>
|
||||
<item name="lowContrastReverseTextColor">@color/grey_800</item>
|
||||
|
||||
<item name="palette">@array/darkWidgetPalette</item>
|
||||
</style>
|
||||
|
||||
<style name="time_label">
|
||||
<item name="android:textSize">@dimen/time_label_size</item>
|
||||
<item name="android:textColor">@color/numbers_text_color</item>
|
||||
|
||||
Reference in New Issue
Block a user