mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Improve widget colors
This commit is contained in:
@@ -57,4 +57,35 @@ public class ColorHelper
|
||||
|
||||
return a << ALPHA_CHANNEL | r << RED_CHANNEL | g << GREEN_CHANNEL | b << BLUE_CHANNEL;
|
||||
}
|
||||
|
||||
public static int setHue(int color, float newHue)
|
||||
{
|
||||
return setHSVParameter(color, newHue, 0);
|
||||
}
|
||||
|
||||
public static int setSaturation(int color, float newSaturation)
|
||||
{
|
||||
return setHSVParameter(color, newSaturation, 1);
|
||||
}
|
||||
|
||||
public static int setValue(int color, float newValue)
|
||||
{
|
||||
return setHSVParameter(color, newValue, 2);
|
||||
}
|
||||
|
||||
public static int setMinValue(int color, float newValue)
|
||||
{
|
||||
float hsv[] = new float[3];
|
||||
Color.colorToHSV(color, hsv);
|
||||
hsv[2] = Math.max(hsv[2], newValue);
|
||||
return Color.HSVToColor(hsv);
|
||||
}
|
||||
|
||||
private static int setHSVParameter(int color, float newValue, int index)
|
||||
{
|
||||
float hsv[] = new float[3];
|
||||
Color.colorToHSV(color, hsv);
|
||||
hsv[index] = newValue;
|
||||
return Color.HSVToColor(hsv);
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,9 @@ public class HabitHistoryView extends ScrollableDataView
|
||||
private Rect baseLocation;
|
||||
private int primaryColor;
|
||||
|
||||
private boolean isBackgroundTransparent;
|
||||
private int textColor;
|
||||
|
||||
public HabitHistoryView(Context context, AttributeSet attrs)
|
||||
{
|
||||
super(context, attrs);
|
||||
@@ -70,7 +73,6 @@ public class HabitHistoryView extends ScrollableDataView
|
||||
public void setHabit(Habit habit)
|
||||
{
|
||||
this.habit = habit;
|
||||
this.primaryColor = habit.color;
|
||||
createColors();
|
||||
fetchData();
|
||||
postInvalidate();
|
||||
@@ -134,20 +136,39 @@ public class HabitHistoryView extends ScrollableDataView
|
||||
|
||||
private void createColors()
|
||||
{
|
||||
int primaryColorBright = Color.argb(127, Color.red(primaryColor), Color.green(primaryColor),
|
||||
Color.blue(primaryColor));
|
||||
int grey = Color.argb(25, 0, 0, 0);
|
||||
if(habit != null)
|
||||
this.primaryColor = habit.color;
|
||||
|
||||
if(isBackgroundTransparent)
|
||||
{
|
||||
primaryColor = ColorHelper.setMinValue(primaryColor, 0.75f);
|
||||
}
|
||||
|
||||
int red = Color.red(primaryColor);
|
||||
int green = Color.green(primaryColor);
|
||||
int blue = Color.blue(primaryColor);
|
||||
|
||||
if(isBackgroundTransparent)
|
||||
{
|
||||
colors = new int[3];
|
||||
colors[0] = grey;
|
||||
colors[1] = primaryColorBright;
|
||||
colors[0] = Color.argb(64, 0, 0, 0);
|
||||
colors[1] = Color.argb(128, red, green, blue);
|
||||
colors[2] = primaryColor;
|
||||
textColor = Color.rgb(255, 255, 255);
|
||||
}
|
||||
else
|
||||
{
|
||||
colors = new int[3];
|
||||
colors[0] = Color.argb(25, 0, 0, 0);
|
||||
colors[1] = Color.argb(127, red, green, blue);
|
||||
colors[2] = primaryColor;
|
||||
textColor = Color.argb(128, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
protected void createPaints()
|
||||
{
|
||||
pTextHeader = new Paint();
|
||||
pTextHeader.setColor(Color.argb(64, 0, 0, 0));
|
||||
pTextHeader.setTextAlign(Align.LEFT);
|
||||
pTextHeader.setAntiAlias(true);
|
||||
|
||||
@@ -212,6 +233,8 @@ public class HabitHistoryView extends ScrollableDataView
|
||||
previousYear = "";
|
||||
justPrintedYear = false;
|
||||
|
||||
pTextHeader.setColor(textColor);
|
||||
|
||||
updateDate();
|
||||
GregorianCalendar currentDate = (GregorianCalendar) baseDate.clone();
|
||||
|
||||
@@ -302,4 +325,10 @@ public class HabitHistoryView extends ScrollableDataView
|
||||
justPrintedYear = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void setIsBackgroundTransparent(boolean isBackgroundTransparent)
|
||||
{
|
||||
this.isBackgroundTransparent = isBackgroundTransparent;
|
||||
createColors();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,6 +55,8 @@ public class HabitScoreView extends ScrollableDataView
|
||||
private int columnHeight;
|
||||
private int nColumns;
|
||||
|
||||
private int textColor;
|
||||
private int dimmedTextColor;
|
||||
private int[] colors;
|
||||
private int[] scores;
|
||||
private int primaryColor;
|
||||
@@ -70,7 +72,7 @@ public class HabitScoreView extends ScrollableDataView
|
||||
public void setHabit(Habit habit)
|
||||
{
|
||||
this.habit = habit;
|
||||
this.primaryColor = habit.color;
|
||||
createColors();
|
||||
fetchData();
|
||||
postInvalidate();
|
||||
}
|
||||
@@ -89,6 +91,26 @@ public class HabitScoreView extends ScrollableDataView
|
||||
|
||||
private void createColors()
|
||||
{
|
||||
if(habit != null)
|
||||
this.primaryColor = habit.color;
|
||||
|
||||
if(isBackgroundTransparent)
|
||||
{
|
||||
primaryColor = ColorHelper.setSaturation(primaryColor, 0.75f);
|
||||
primaryColor = ColorHelper.setValue(primaryColor, 1.0f);
|
||||
}
|
||||
|
||||
if(isBackgroundTransparent)
|
||||
{
|
||||
textColor = Color.argb(192, 255, 255, 255);
|
||||
dimmedTextColor = Color.argb(128, 255, 255, 255);
|
||||
}
|
||||
else
|
||||
{
|
||||
textColor = Color.argb(128, 0, 0, 0);
|
||||
dimmedTextColor = Color.argb(32, 0, 0, 0);
|
||||
}
|
||||
|
||||
colors = new int[4];
|
||||
|
||||
colors[0] = Color.rgb(230, 230, 230);
|
||||
@@ -100,18 +122,14 @@ public class HabitScoreView extends ScrollableDataView
|
||||
protected void createPaints()
|
||||
{
|
||||
pText = new Paint();
|
||||
pText.setColor(Color.argb(64, 0, 0, 0));
|
||||
pText.setTextAlign(Paint.Align.LEFT);
|
||||
pText.setAntiAlias(true);
|
||||
|
||||
pGraph = new Paint();
|
||||
pGraph.setTextAlign(Paint.Align.CENTER);
|
||||
pGraph.setAntiAlias(true);
|
||||
|
||||
pGrid = new Paint();
|
||||
pGrid.setColor(Color.argb(64, 0, 0, 0));
|
||||
pGrid.setAntiAlias(true);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -186,10 +204,13 @@ public class HabitScoreView extends ScrollableDataView
|
||||
float lineHeight = pText.getFontSpacing();
|
||||
|
||||
rect.set(0, 0, nColumns * columnWidth, columnHeight);
|
||||
rect.offset(0, 1f);
|
||||
|
||||
drawGrid(canvas, rect);
|
||||
|
||||
String previousMonth = "";
|
||||
|
||||
pText.setColor(textColor);
|
||||
pGraph.setColor(primaryColor);
|
||||
prevRect.setEmpty();
|
||||
|
||||
@@ -240,7 +261,7 @@ public class HabitScoreView extends ScrollableDataView
|
||||
int nRows = 5;
|
||||
float rowHeight = rGrid.height() / nRows;
|
||||
|
||||
pGrid.setColor(Color.argb(20, 0, 0, 0));
|
||||
pGrid.setColor(dimmedTextColor);
|
||||
for (int i = 0; i < nRows; i++)
|
||||
{
|
||||
canvas.drawText(String.format("%d%%", (100 - i * 100 / nRows)), rGrid.left + 0.5f * em,
|
||||
@@ -280,6 +301,7 @@ public class HabitScoreView extends ScrollableDataView
|
||||
public void setIsBackgroundTransparent(boolean isBackgroundTransparent)
|
||||
{
|
||||
this.isBackgroundTransparent = isBackgroundTransparent;
|
||||
createColors();
|
||||
}
|
||||
|
||||
private void setModeOrColor(Paint p, PorterDuffXfermode mode, int color)
|
||||
|
||||
@@ -25,7 +25,6 @@ import android.util.AttributeSet;
|
||||
|
||||
import org.isoron.helpers.ColorHelper;
|
||||
import org.isoron.helpers.DateHelper;
|
||||
import org.isoron.uhabits.R;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
import org.isoron.uhabits.models.Streak;
|
||||
|
||||
@@ -55,6 +54,10 @@ public class HabitStreakView extends ScrollableDataView
|
||||
private int baseSize;
|
||||
private int primaryColor;
|
||||
|
||||
private boolean isBackgroundTransparent;
|
||||
private int textColor;
|
||||
private Paint pBarText;
|
||||
|
||||
public HabitStreakView(Context context, AttributeSet attrs)
|
||||
{
|
||||
super(context, attrs);
|
||||
@@ -65,7 +68,6 @@ public class HabitStreakView extends ScrollableDataView
|
||||
public void setHabit(Habit habit)
|
||||
{
|
||||
this.habit = habit;
|
||||
this.primaryColor = habit.color;
|
||||
|
||||
createColors();
|
||||
fetchData();
|
||||
@@ -110,20 +112,45 @@ public class HabitStreakView extends ScrollableDataView
|
||||
}
|
||||
|
||||
private void createColors()
|
||||
{
|
||||
if(habit != null)
|
||||
this.primaryColor = 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[1] = Color.argb(80, Color.red(primaryColor), Color.green(primaryColor), Color.blue(
|
||||
primaryColor));
|
||||
colors[2] = Color.argb(170, Color.red(primaryColor), Color.green(primaryColor),
|
||||
Color.blue(primaryColor));
|
||||
colors[0] = Color.argb(30, 0, 0, 0);
|
||||
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.rgb(255, 255, 255);
|
||||
pBarText = pText;
|
||||
}
|
||||
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] = Color.argb(32, 0, 0, 0);
|
||||
textColor = Color.argb(128, 0, 0, 0);
|
||||
pBarText = pBar;
|
||||
}
|
||||
}
|
||||
|
||||
protected void createPaints()
|
||||
{
|
||||
pText = new Paint();
|
||||
pText.setColor(Color.argb(64, 0, 0, 0));
|
||||
pText.setTextAlign(Paint.Align.CENTER);
|
||||
pText.setAntiAlias(true);
|
||||
|
||||
@@ -199,6 +226,8 @@ public class HabitStreakView extends ScrollableDataView
|
||||
int nStreaks = startTimes.length;
|
||||
int start = nStreaks - nColumns - getDataOffset();
|
||||
|
||||
pText.setColor(textColor);
|
||||
|
||||
String previousMonth = "";
|
||||
|
||||
for (int offset = 0; offset < nColumns && start + offset < nStreaks; offset++)
|
||||
@@ -216,7 +245,7 @@ public class HabitStreakView extends ScrollableDataView
|
||||
rect.offset(offset * columnWidth, headerHeight + columnHeight - height);
|
||||
|
||||
canvas.drawRect(rect, pBar);
|
||||
canvas.drawText(Long.toString(l), rect.centerX(), rect.top - barHeaderOffset, pBar);
|
||||
canvas.drawText(Long.toString(l), rect.centerX(), rect.top - barHeaderOffset, pBarText);
|
||||
|
||||
if (!month.equals(previousMonth))
|
||||
canvas.drawText(month, rect.centerX(), rect.bottom + lineHeight * 1.2f, pText);
|
||||
@@ -224,4 +253,10 @@ public class HabitStreakView extends ScrollableDataView
|
||||
previousMonth = month;
|
||||
}
|
||||
}
|
||||
|
||||
public void setIsBackgroundTransparent(boolean isBackgroundTransparent)
|
||||
{
|
||||
this.isBackgroundTransparent = isBackgroundTransparent;
|
||||
createColors();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ public class HistoryWidgetProvider extends BaseWidgetProvider
|
||||
protected View buildCustomView(Context context, int maxHeight, int maxWidth, Habit habit)
|
||||
{
|
||||
HabitHistoryView view = new HabitHistoryView(context, null);
|
||||
view.setIsBackgroundTransparent(true);
|
||||
view.setHabit(habit);
|
||||
view.measure(maxWidth, maxHeight);
|
||||
view.layout(0, 0, maxWidth, maxHeight);
|
||||
|
||||
@@ -22,7 +22,6 @@ import android.view.View;
|
||||
import org.isoron.helpers.DialogHelper;
|
||||
import org.isoron.uhabits.R;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
import org.isoron.uhabits.views.HabitScoreView;
|
||||
import org.isoron.uhabits.views.HabitStreakView;
|
||||
|
||||
public class StreakWidgetProvider extends BaseWidgetProvider
|
||||
@@ -31,6 +30,7 @@ public class StreakWidgetProvider extends BaseWidgetProvider
|
||||
protected View buildCustomView(Context context, int maxHeight, int maxWidth, Habit habit)
|
||||
{
|
||||
HabitStreakView view = new HabitStreakView(context, null);
|
||||
view.setIsBackgroundTransparent(true);
|
||||
view.setHabit(habit);
|
||||
view.measure(maxWidth, maxHeight);
|
||||
view.layout(0, 0, maxWidth, maxHeight);
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
|
||||
<solid android:color="#3fffffff" />
|
||||
<solid android:color="#3f000000" />
|
||||
<corners android:radius="10dp" />
|
||||
</shape>
|
||||
@@ -15,8 +15,8 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="Wake up early"
|
||||
android:textColor="#3f000000"/>
|
||||
android:text="Habit"
|
||||
android:textColor="#ffffff"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView"
|
||||
|
||||
Reference in New Issue
Block a user