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.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;
|
||||||
@@ -64,7 +63,7 @@ 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 = UIHelper.getStyledColor(getContext(), R.attr.cardBackgroundColor);
|
inactiveColor = ColorHelper.CSV_PALETTE[11];
|
||||||
|
|
||||||
if(isInEditMode())
|
if(isInEditMode())
|
||||||
{
|
{
|
||||||
@@ -92,6 +91,7 @@ public class CheckmarkWidgetView extends HabitWidgetView implements HabitDataVie
|
|||||||
String text;
|
String text;
|
||||||
int backgroundColor;
|
int backgroundColor;
|
||||||
int foregroundColor;
|
int foregroundColor;
|
||||||
|
float alpha;
|
||||||
|
|
||||||
switch (checkmarkValue)
|
switch (checkmarkValue)
|
||||||
{
|
{
|
||||||
@@ -99,24 +99,28 @@ public class CheckmarkWidgetView extends HabitWidgetView implements HabitDataVie
|
|||||||
text = getResources().getString(R.string.fa_check);
|
text = getResources().getString(R.string.fa_check);
|
||||||
backgroundColor = activeColor;
|
backgroundColor = activeColor;
|
||||||
foregroundColor = Color.WHITE;
|
foregroundColor = Color.WHITE;
|
||||||
|
alpha = 1.0f;
|
||||||
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 = inactiveColor;
|
||||||
foregroundColor = UIHelper.getStyledColor(getContext(), R.attr.mediumContrastTextColor);
|
foregroundColor = ColorHelper.CSV_PALETTE[12];
|
||||||
|
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 = inactiveColor;
|
||||||
foregroundColor = UIHelper.getStyledColor(getContext(), R.attr.mediumContrastTextColor);
|
foregroundColor = ColorHelper.CSV_PALETTE[12];
|
||||||
|
alpha = 0.5f;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
backgroundPaint.setColor(backgroundColor);
|
backgroundPaint.setColor(backgroundColor);
|
||||||
frame.setBackgroundDrawable(background);
|
frame.setBackgroundDrawable(background);
|
||||||
|
setAlpha(alpha);
|
||||||
|
|
||||||
ring.setPercentage(percentage);
|
ring.setPercentage(percentage);
|
||||||
ring.setPrecision(0.125f);
|
ring.setPrecision(0.125f);
|
||||||
@@ -163,4 +167,10 @@ public class CheckmarkWidgetView extends HabitWidgetView implements HabitDataVie
|
|||||||
{
|
{
|
||||||
return R.layout.widget_checkmark;
|
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.content.Context;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Color;
|
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.RectF;
|
import android.graphics.RectF;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
@@ -104,22 +103,10 @@ public class HabitFrequencyView extends ScrollableDataView implements HabitDataV
|
|||||||
this.primaryColor = ColorHelper.getColor(getContext(), habit.color);
|
this.primaryColor = ColorHelper.getColor(getContext(), habit.color);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isBackgroundTransparent)
|
textColor = UIHelper.getStyledColor(getContext(), R.attr.mediumContrastTextColor);
|
||||||
{
|
gridColor = UIHelper.getStyledColor(getContext(), R.attr.lowContrastTextColor);
|
||||||
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 = new int[4];
|
||||||
|
|
||||||
colors[0] = gridColor;
|
colors[0] = gridColor;
|
||||||
colors[3] = primaryColor;
|
colors[3] = primaryColor;
|
||||||
colors[1] = ColorHelper.mixColors(colors[0], colors[3], 0.66f);
|
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.content.Context;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Color;
|
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
import android.graphics.PorterDuffXfermode;
|
import android.graphics.PorterDuffXfermode;
|
||||||
@@ -114,20 +113,9 @@ public class HabitScoreView extends ScrollableDataView implements HabitDataView
|
|||||||
if(habit != null)
|
if(habit != null)
|
||||||
this.primaryColor = ColorHelper.getColor(getContext(), habit.color);
|
this.primaryColor = ColorHelper.getColor(getContext(), habit.color);
|
||||||
|
|
||||||
if (isBackgroundTransparent)
|
textColor = UIHelper.getStyledColor(getContext(), R.attr.mediumContrastTextColor);
|
||||||
{
|
gridColor = UIHelper.getStyledColor(getContext(), R.attr.lowContrastTextColor);
|
||||||
primaryColor = ColorHelper.setSaturation(primaryColor, 0.75f);
|
backgroundColor = UIHelper.getStyledColor(getContext(), R.attr.cardBackgroundColor);
|
||||||
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()
|
protected void createPaints()
|
||||||
|
|||||||
@@ -127,36 +127,17 @@ public class HabitStreakView extends View implements HabitDataView
|
|||||||
if(habit != null)
|
if(habit != null)
|
||||||
this.primaryColor = ColorHelper.getColor(getContext(), habit.color);
|
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 red = Color.red(primaryColor);
|
||||||
int green = Color.green(primaryColor);
|
int green = Color.green(primaryColor);
|
||||||
int blue = Color.blue(primaryColor);
|
int blue = Color.blue(primaryColor);
|
||||||
|
|
||||||
if(isBackgroundTransparent)
|
colors = new int[4];
|
||||||
{
|
colors[3] = primaryColor;
|
||||||
colors = new int[4];
|
colors[2] = Color.argb(192, red, green, blue);
|
||||||
colors[3] = primaryColor;
|
colors[1] = Color.argb(96, red, green, blue);
|
||||||
colors[2] = Color.argb(213, red, green, blue);
|
colors[0] = UIHelper.getStyledColor(getContext(), R.attr.lowContrastTextColor);
|
||||||
colors[1] = Color.argb(170, red, green, blue);
|
textColor = UIHelper.getStyledColor(getContext(), R.attr.mediumContrastTextColor);
|
||||||
colors[0] = Color.argb(128, red, green, blue);
|
reverseTextColor = UIHelper.getStyledColor(getContext(), R.attr.highContrastReverseTextColor);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void createPaints()
|
protected void createPaints()
|
||||||
|
|||||||
@@ -72,11 +72,11 @@ public abstract class HabitWidgetView extends FrameLayout implements HabitDataV
|
|||||||
private void initBackground()
|
private void initBackground()
|
||||||
{
|
{
|
||||||
Context context = getContext();
|
Context context = getContext();
|
||||||
context.setTheme(R.style.AppBaseThemeDark);
|
context.setTheme(R.style.DarkWidgetTheme);
|
||||||
|
|
||||||
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(96, 0, 0, 0);
|
int shadowColor = Color.argb(getShadowAlpha(), 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,11 +93,17 @@ 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);
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ public class ScoreWidgetProvider extends BaseWidgetProvider
|
|||||||
protected View buildCustomView(Context context, Habit habit)
|
protected View buildCustomView(Context context, Habit habit)
|
||||||
{
|
{
|
||||||
HabitScoreView dataView = new HabitScoreView(context);
|
HabitScoreView dataView = new HabitScoreView(context);
|
||||||
|
dataView.setIsBackgroundTransparent(true);
|
||||||
GraphWidgetView view = new GraphWidgetView(context, dataView);
|
GraphWidgetView view = new GraphWidgetView(context, dataView);
|
||||||
view.setHabit(habit);
|
view.setHabit(habit);
|
||||||
return view;
|
return view;
|
||||||
|
|||||||
@@ -48,6 +48,22 @@
|
|||||||
<item>@color/grey_500</item>
|
<item>@color/grey_500</item>
|
||||||
</array>
|
</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 -->
|
<!-- Time and Date picker -->
|
||||||
<color name="circle_background">#f2f2f2</color>
|
<color name="circle_background">#f2f2f2</color>
|
||||||
<color name="line_background">#cccccc</color>
|
<color name="line_background">#cccccc</color>
|
||||||
@@ -355,4 +371,22 @@
|
|||||||
|
|
||||||
<color name="white">#ffffff</color>
|
<color name="white">#ffffff</color>
|
||||||
<color name="black">#000000</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>
|
</resources>
|
||||||
@@ -127,6 +127,20 @@
|
|||||||
<item name="highContrastReverseTextColor">@color/black</item>
|
<item name="highContrastReverseTextColor">@color/black</item>
|
||||||
</style>
|
</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">
|
<style name="time_label">
|
||||||
<item name="android:textSize">@dimen/time_label_size</item>
|
<item name="android:textSize">@dimen/time_label_size</item>
|
||||||
<item name="android:textColor">@color/numbers_text_color</item>
|
<item name="android:textColor">@color/numbers_text_color</item>
|
||||||
|
|||||||
Reference in New Issue
Block a user