mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Merge branch 'hotfix/1.7.1' into dev
This commit is contained in:
@@ -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));
|
||||||
|
|
||||||
|
int value = getIntAttribute(ctx, attrs, "value", 0);
|
||||||
setValue(value);
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDraw(Canvas canvas)
|
||||||
|
{
|
||||||
|
super.onDraw(canvas);
|
||||||
|
Resources resources = getResources();
|
||||||
|
|
||||||
|
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");
|
||||||
|
|
||||||
|
rect.set(0, 0, getWidth(), getHeight());
|
||||||
|
rect.offset(0, 0.4f * em);
|
||||||
|
canvas.drawText(label, rect.centerX(), rect.centerY(), paint);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
|
||||||
|
{
|
||||||
|
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 init()
|
private void init()
|
||||||
{
|
{
|
||||||
res = new StyledResources(getContext());
|
|
||||||
|
|
||||||
setWillNotDraw(false);
|
|
||||||
|
|
||||||
setMinHeight(
|
|
||||||
getResources().getDimensionPixelSize(R.dimen.checkmarkHeight));
|
|
||||||
setMinWidth(
|
|
||||||
getResources().getDimensionPixelSize(R.dimen.checkmarkWidth));
|
|
||||||
|
|
||||||
setFocusable(false);
|
setFocusable(false);
|
||||||
setGravity(Gravity.CENTER);
|
|
||||||
setTypeface(InterfaceUtils.getFontAwesome(getContext()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateText()
|
Resources res = getResources();
|
||||||
{
|
styledRes = new StyledResources(getContext());
|
||||||
int lowContrastColor = res.getColor(R.attr.lowContrastTextColor);
|
|
||||||
|
|
||||||
if (value == Checkmark.CHECKED_EXPLICITLY)
|
paint = new TextPaint();
|
||||||
{
|
paint.setTypeface(InterfaceUtils.getFontAwesome(getContext()));
|
||||||
setText(R.string.fa_check);
|
paint.setAntiAlias(true);
|
||||||
setTextColor(color);
|
paint.setTextAlign(Paint.Align.CENTER);
|
||||||
}
|
paint.setTextSize(res.getDimension(R.dimen.regularTextSize));
|
||||||
|
|
||||||
if (value == Checkmark.CHECKED_IMPLICITLY)
|
rect = new RectF();
|
||||||
{
|
color = ColorUtils.getAndroidTestColor(0);
|
||||||
setText(R.string.fa_check);
|
lowContrastColor = styledRes.getColor(R.attr.lowContrastTextColor);
|
||||||
setTextColor(lowContrastColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
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()
|
||||||
|
|||||||
Reference in New Issue
Block a user