Merge branch 'hotfix/1.7.1' into dev

pull/286/head
Alinson S. Xavier 9 years ago
commit 50e21b2cc1

@ -46,12 +46,12 @@ public class CheckmarkButtonViewTest extends BaseViewTest
public void setUp() public void setUp()
{ {
super.setUp(); super.setUp();
setSimilarityCutoff(0.03f); setSimilarityCutoff(0.015f);
latch = new CountDownLatch(1); latch = new CountDownLatch(1);
view = new CheckmarkButtonView(targetContext); view = new CheckmarkButtonView(targetContext);
view.setValue(Checkmark.UNCHECKED); view.setValue(Checkmark.UNCHECKED);
view.setColor(ColorUtils.getAndroidTestColor(7)); view.setColor(ColorUtils.getAndroidTestColor(5));
measureView(view, dpToPixels(40), dpToPixels(40)); measureView(view, dpToPixels(40), dpToPixels(40));
} }

@ -20,26 +20,34 @@
package org.isoron.uhabits.activities.habits.list.views; package org.isoron.uhabits.activities.habits.list.views;
import android.content.*; import android.content.*;
import android.content.res.*;
import android.graphics.*;
import android.support.annotation.*; import android.support.annotation.*;
import android.text.*;
import android.util.*; import android.util.*;
import android.view.*; import android.view.*;
import android.widget.*;
import org.isoron.uhabits.*; import org.isoron.uhabits.*;
import org.isoron.uhabits.activities.habits.list.controllers.*; import org.isoron.uhabits.activities.habits.list.controllers.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.utils.*; import org.isoron.uhabits.utils.*;
import static android.view.View.MeasureSpec.*;
import static org.isoron.uhabits.models.Checkmark.*;
import static org.isoron.uhabits.utils.AttributeSetUtils.*; import static org.isoron.uhabits.utils.AttributeSetUtils.*;
import static org.isoron.uhabits.utils.ColorUtils.*;
public class CheckmarkButtonView extends TextView public class CheckmarkButtonView extends View
{ {
private int color; private int color;
private int value; private int value;
private StyledResources res; private StyledResources styledRes;
private TextPaint paint;
private int lowContrastColor;
private RectF rect;
public CheckmarkButtonView(@Nullable Context context) public CheckmarkButtonView(@Nullable Context context)
{ {
@ -47,25 +55,25 @@ public class CheckmarkButtonView extends TextView
init(); init();
} }
public CheckmarkButtonView(@Nullable Context context, public CheckmarkButtonView(@Nullable Context ctx, @Nullable AttributeSet attrs)
@Nullable AttributeSet attrs)
{ {
super(context, attrs); super(ctx, attrs);
init(); init();
if (context != null && attrs != null) if(ctx == null) throw new IllegalStateException();
{ if(attrs == null) throw new IllegalStateException();
int color = getIntAttribute(context, attrs, "color", 0);
int value = getIntAttribute(context, attrs, "value", 0); int paletteColor = getIntAttribute(ctx, attrs, "color", 0);
setColor(getAndroidTestColor(color)); setColor(ColorUtils.getAndroidTestColor(paletteColor));
setValue(value);
} int value = getIntAttribute(ctx, attrs, "value", 0);
setValue(value);
} }
public void setColor(int color) public void setColor(int color)
{ {
this.color = color; this.color = color;
updateText(); postInvalidate();
} }
public void setController(final CheckmarkButtonController controller) public void setController(final CheckmarkButtonController controller)
@ -77,54 +85,60 @@ public class CheckmarkButtonView extends TextView
public void setValue(int value) public void setValue(int value)
{ {
this.value = value; this.value = value;
updateText(); postInvalidate();
} }
public void toggle() public void toggle()
{ {
value = (value == Checkmark.CHECKED_EXPLICITLY ? Checkmark.UNCHECKED : value = (value == CHECKED_EXPLICITLY ? UNCHECKED : CHECKED_EXPLICITLY);
Checkmark.CHECKED_EXPLICITLY);
performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
updateText(); postInvalidate();
} }
private void init() @Override
protected void onDraw(Canvas canvas)
{ {
res = new StyledResources(getContext()); super.onDraw(canvas);
Resources resources = getResources();
setWillNotDraw(false); paint.setColor(value == CHECKED_EXPLICITLY ? color : lowContrastColor);
int id = (value == UNCHECKED ? R.string.fa_times : R.string.fa_check);
String label = resources.getString(id);
float em = paint.measureText("m");
setMinHeight( rect.set(0, 0, getWidth(), getHeight());
getResources().getDimensionPixelSize(R.dimen.checkmarkHeight)); rect.offset(0, 0.4f * em);
setMinWidth( canvas.drawText(label, rect.centerX(), rect.centerY(), paint);
getResources().getDimensionPixelSize(R.dimen.checkmarkWidth)); }
setFocusable(false); @Override
setGravity(Gravity.CENTER); protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
setTypeface(InterfaceUtils.getFontAwesome(getContext())); {
Resources res = getResources();
int height = res.getDimensionPixelSize(R.dimen.checkmarkHeight);
int width = res.getDimensionPixelSize(R.dimen.checkmarkWidth);
widthMeasureSpec = makeMeasureSpec(width, EXACTLY);
heightMeasureSpec = makeMeasureSpec(height, EXACTLY);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
} }
private void updateText() private void init()
{ {
int lowContrastColor = res.getColor(R.attr.lowContrastTextColor); setFocusable(false);
if (value == Checkmark.CHECKED_EXPLICITLY) Resources res = getResources();
{ styledRes = new StyledResources(getContext());
setText(R.string.fa_check);
setTextColor(color); paint = new TextPaint();
} paint.setTypeface(InterfaceUtils.getFontAwesome(getContext()));
paint.setAntiAlias(true);
if (value == Checkmark.CHECKED_IMPLICITLY) paint.setTextAlign(Paint.Align.CENTER);
{ paint.setTextSize(res.getDimension(R.dimen.regularTextSize));
setText(R.string.fa_check);
setTextColor(lowContrastColor); rect = new RectF();
} color = ColorUtils.getAndroidTestColor(0);
lowContrastColor = styledRes.getColor(R.attr.lowContrastTextColor);
if (value == Checkmark.UNCHECKED)
{
setText(R.string.fa_times);
setTextColor(lowContrastColor);
}
} }
} }

@ -236,6 +236,7 @@ public class HabitCardView extends FrameLayout
scoreRing.setPercentage(rand.nextFloat()); scoreRing.setPercentage(rand.nextFloat());
checkmarkPanel.setColor(color); checkmarkPanel.setColor(color);
numberPanel.setColor(color); numberPanel.setColor(color);
checkmarkPanel.setButtonCount(5);
} }
private void refresh() private void refresh()

Loading…
Cancel
Save