diff --git a/app/src/main/java/org/isoron/uhabits/activities/habits/list/views/CheckmarkPanelView.java b/app/src/main/java/org/isoron/uhabits/activities/habits/list/views/CheckmarkPanelView.java
index 1f206ad4b..66061b83b 100644
--- a/app/src/main/java/org/isoron/uhabits/activities/habits/list/views/CheckmarkPanelView.java
+++ b/app/src/main/java/org/isoron/uhabits/activities/habits/list/views/CheckmarkPanelView.java
@@ -198,7 +198,7 @@ public class CheckmarkPanelView extends LinearLayout
int values[] = new int[nButtons];
for (int i = 0; i < nButtons; i++)
- values[i] = new Random().nextInt(3);
+ values[i] = Math.min(2, new Random().nextInt(4));
setValues(values);
}
diff --git a/app/src/main/java/org/isoron/uhabits/activities/habits/list/views/NumberButtonView.java b/app/src/main/java/org/isoron/uhabits/activities/habits/list/views/NumberButtonView.java
index ff4e622d6..07594cb6e 100644
--- a/app/src/main/java/org/isoron/uhabits/activities/habits/list/views/NumberButtonView.java
+++ b/app/src/main/java/org/isoron/uhabits/activities/habits/list/views/NumberButtonView.java
@@ -20,11 +20,12 @@
package org.isoron.uhabits.activities.habits.list.views;
import android.content.*;
+import android.content.res.*;
import android.graphics.*;
import android.support.annotation.*;
+import android.text.*;
import android.util.*;
import android.view.*;
-import android.widget.*;
import org.isoron.uhabits.*;
import org.isoron.uhabits.activities.habits.list.controllers.*;
@@ -33,9 +34,12 @@ import org.isoron.uhabits.utils.*;
import static org.isoron.uhabits.utils.AttributeSetUtils.*;
import static org.isoron.uhabits.utils.ColorUtils.*;
-public class NumberButtonView extends TextView
+public class NumberButtonView extends View
{
- private static Typeface TYPEFACE =
+ private static Typeface BOLD_TYPEFACE =
+ Typeface.create("sans-serif-condensed", Typeface.BOLD);
+
+ private static Typeface NORMAL_TYPEFACE =
Typeface.create("sans-serif-condensed", Typeface.NORMAL);
private int color;
@@ -44,7 +48,19 @@ public class NumberButtonView extends TextView
private int threshold;
- private StyledResources res;
+ private String unit;
+
+ private RectF rect;
+
+ private TextPaint pRegular;
+
+ private Resources res;
+
+ private TextPaint pBold;
+
+ private int grey;
+
+ private float em;
public NumberButtonView(@Nullable Context context)
{
@@ -52,33 +68,34 @@ public class NumberButtonView extends TextView
init();
}
- public NumberButtonView(@Nullable Context context,
- @Nullable AttributeSet attrs)
+ public NumberButtonView(@Nullable Context ctx, @Nullable AttributeSet attrs)
{
- super(context, attrs);
+ super(ctx, attrs);
init();
- if (context != null && attrs != null)
+ if (ctx != null && attrs != null)
{
- int color = getIntAttribute(context, attrs, "color", 0);
- int value = getIntAttribute(context, attrs, "value", 0);
- int threshold = getIntAttribute(context, attrs, "threshold", 1);
+ int color = getIntAttribute(ctx, attrs, "color", 0);
+ int value = getIntAttribute(ctx, attrs, "value", 0);
+ int threshold = getIntAttribute(ctx, attrs, "threshold", 1);
+ String unit = getAttribute(ctx, attrs, "unit", "min");
setColor(getAndroidTestColor(color));
setThreshold(threshold);
setValue(value);
+ setUnit(unit);
}
}
private static String formatValue(int v)
{
double fv = (double) v;
- if(v >= 1e9) return String.format("%.1fG", fv / 1e9);
- if(v >= 1e8) return String.format("%.0fM", fv / 1e6);
- if(v >= 1e7) return String.format("%.1fM", fv / 1e6);
- if(v >= 1e6) return String.format("%.1fM", fv / 1e6);
- if(v >= 1e5) return String.format("%.0fk", fv / 1e3);
- if(v >= 1e4) return String.format("%.1fk", fv / 1e3);
- if(v >= 1e3) return String.format("%.1fk", fv / 1e3);
+ if (v >= 1e9) return String.format("%.1fG", fv / 1e9);
+ if (v >= 1e8) return String.format("%.0fM", fv / 1e6);
+ if (v >= 1e7) return String.format("%.1fM", fv / 1e6);
+ if (v >= 1e6) return String.format("%.1fM", fv / 1e6);
+ if (v >= 1e5) return String.format("%.0fk", fv / 1e3);
+ if (v >= 1e4) return String.format("%.1fk", fv / 1e3);
+ if (v >= 1e3) return String.format("%.1fk", fv / 1e3);
return String.format("%d", v);
}
@@ -97,35 +114,72 @@ public class NumberButtonView extends TextView
public void setThreshold(int threshold)
{
this.threshold = threshold;
- updateText();
+ postInvalidate();
+ }
+
+ public void setUnit(String unit)
+ {
+ this.unit = unit;
+ postInvalidate();
}
public void setValue(int value)
{
this.value = value;
- updateText();
+ postInvalidate();
}
- private void init()
+ @Override
+ protected void onDraw(Canvas canvas)
{
- res = new StyledResources(getContext());
+ if(value < threshold)
+ {
+ pRegular.setColor(grey);
+ pBold.setColor(grey);
+ }
+ else
+ {
+ pRegular.setColor(color);
+ pBold.setColor(color);
+ }
- setWillNotDraw(false);
+ String fv = formatValue(value);
- setMinHeight(
- getResources().getDimensionPixelSize(R.dimen.checkmarkHeight));
- setMinWidth(
- getResources().getDimensionPixelSize(R.dimen.checkmarkWidth));
+ rect.set(0, 0, getWidth(), getHeight());
+ rect.offset(0, - 0.1f * em);
+ canvas.drawText(fv, rect.centerX(), rect.centerY(), pBold);
- setFocusable(false);
- setGravity(Gravity.CENTER);
- setTypeface(TYPEFACE);
+ rect.offset(0, 1.25f * em);
+ canvas.drawText(unit, rect.centerX(), rect.centerY(), pRegular);
}
- private void updateText()
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
+ {
+ int width = (int) res.getDimension(R.dimen.checkmarkWidth);
+ int height = (int) res.getDimension(R.dimen.checkmarkHeight);
+ setMeasuredDimension(width, height);
+ }
+
+ private void init()
{
- int lowColor = res.getColor(R.attr.lowContrastTextColor);
- setTextColor(value >= threshold ? color : lowColor);
- setText(formatValue(value));
+ StyledResources sr = new StyledResources(getContext());
+ res = getContext().getResources();
+
+ rect = new RectF();
+ pRegular = new TextPaint();
+ pRegular.setTextSize(res.getDimension(R.dimen.smallerTextSize));
+ pRegular.setTypeface(NORMAL_TYPEFACE);
+ pRegular.setAntiAlias(true);
+ pRegular.setTextAlign(Paint.Align.CENTER);
+
+ pBold = new TextPaint();
+ pBold.setTextSize(res.getDimension(R.dimen.smallTextSize));
+ pBold.setTypeface(BOLD_TYPEFACE);
+ pBold.setAntiAlias(true);
+ pBold.setTextAlign(Paint.Align.CENTER);
+
+ em = pBold.measureText("m");
+ grey = sr.getColor(R.attr.lowContrastTextColor);
}
}
diff --git a/app/src/main/java/org/isoron/uhabits/activities/habits/list/views/NumberPanelView.java b/app/src/main/java/org/isoron/uhabits/activities/habits/list/views/NumberPanelView.java
index cfbf3de15..e21bfa263 100644
--- a/app/src/main/java/org/isoron/uhabits/activities/habits/list/views/NumberPanelView.java
+++ b/app/src/main/java/org/isoron/uhabits/activities/habits/list/views/NumberPanelView.java
@@ -57,6 +57,8 @@ public class NumberPanelView extends LinearLayout
private Controller controller;
+ private String unit;
+
@NonNull
private Habit habit;
@@ -79,11 +81,18 @@ public class NumberPanelView extends LinearLayout
setColor(getAndroidTestColor(paletteColor));
setButtonCount(getIntAttribute(ctx, attrs, "button_count", 5));
setThreshold(getIntAttribute(ctx, attrs, "threshold", 1));
+ setUnit(getAttribute(ctx, attrs, "unit", "min"));
}
if(isInEditMode()) initEditMode();
}
+ public void setUnit(String unit)
+ {
+ this.unit = unit;
+ setupButtons();
+ }
+
public void initEditMode()
{
int values[] = new int[nButtons];
@@ -243,6 +252,7 @@ public class NumberPanelView extends LinearLayout
buttonView.setValue(values[i + dataOffset]);
buttonView.setColor(color);
buttonView.setThreshold(threshold);
+ buttonView.setUnit(unit);
setupButtonControllers(timestamp, buttonView);
timestamp -= day;
}
diff --git a/app/src/main/res/layout/list_habits_panel_preview.xml b/app/src/main/res/layout/list_habits_panel_preview.xml
index 54393cad1..b08a1b7b6 100644
--- a/app/src/main/res/layout/list_habits_panel_preview.xml
+++ b/app/src/main/res/layout/list_habits_panel_preview.xml
@@ -30,7 +30,8 @@
android:layout_height="wrap_content"
app:button_count="8"
app:color="1"
- app:threshold="10"
+ app:threshold="10000"
+ app:unit="steps"
/>
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml
index bb938b840..e8ddfd3df 100644
--- a/app/src/main/res/values/dimens.xml
+++ b/app/src/main/res/values/dimens.xml
@@ -19,7 +19,7 @@
20dp
- 42dp
+ 48dp
48dp
450dp
8dp