View tests: create wrapper for getDimension; other fixes

pull/231/merge
Alinson S. Xavier 8 years ago
parent 1b97b9040d
commit 9f2f8f7117

@ -25,6 +25,7 @@ import android.content.res.*;
import android.os.*; import android.os.*;
import android.support.annotation.*; import android.support.annotation.*;
import android.support.test.*; import android.support.test.*;
import android.util.*;
import org.isoron.uhabits.models.*; import org.isoron.uhabits.models.*;
import org.isoron.uhabits.preferences.*; import org.isoron.uhabits.preferences.*;
@ -78,8 +79,8 @@ public class BaseAndroidTest
targetContext = InstrumentationRegistry.getTargetContext(); targetContext = InstrumentationRegistry.getTargetContext();
testContext = InstrumentationRegistry.getContext(); testContext = InstrumentationRegistry.getContext();
InterfaceUtils.setFixedResolution(2.0f);
DateUtils.setFixedLocalTime(FIXED_LOCAL_TIME); DateUtils.setFixedLocalTime(FIXED_LOCAL_TIME);
setResolution(2.0f);
setTheme(R.style.AppBaseTheme); setTheme(R.style.AppBaseTheme);
setLocale("en", "US"); setLocale("en", "US");
@ -127,6 +128,14 @@ public class BaseAndroidTest
config.setLocale(locale); config.setLocale(locale);
} }
protected void setResolution(float r)
{
DisplayMetrics dm = targetContext.getResources().getDisplayMetrics();
dm.density = r;
dm.scaledDensity = r;
InterfaceUtils.setFixedResolution(r);
}
protected void setTheme(@StyleRes int themeId) protected void setTheme(@StyleRes int themeId)
{ {
targetContext.setTheme(themeId); targetContext.setTheme(themeId);

@ -36,7 +36,7 @@ import static junit.framework.Assert.*;
public class BaseViewTest extends BaseAndroidTest public class BaseViewTest extends BaseAndroidTest
{ {
double similarityCutoff = 0.0005; double similarityCutoff = 0.00075;
@Override @Override
public void setUp() public void setUp()
@ -48,34 +48,16 @@ public class BaseViewTest extends BaseAndroidTest
throws IOException throws IOException
{ {
expectedImagePath = getVersionedPath(expectedImagePath); expectedImagePath = getVersionedPath(expectedImagePath);
Bitmap actual = renderView(view);
if(actual == null) throw new IllegalStateException("actual is null");
if (view.isLayoutRequested()) measureView(view, view.getMeasuredWidth(),
view.getMeasuredHeight());
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap expected = null;
Bitmap actual = view.getDrawingCache();
try try
{ {
expected = getBitmapFromAssets(expectedImagePath); Bitmap expected = getBitmapFromAssets(expectedImagePath);
} double distance = distance(actual, expected);
catch (Exception e)
{
String path = saveBitmap(expectedImagePath, "", actual);
fail(String.format("Could not open expected image. Actual " +
"rendered image saved to %s", path));
}
int width = actual.getWidth();
int height = actual.getHeight();
Bitmap scaledExpected =
Bitmap.createScaledBitmap(expected, width, height, true);
double distance = distance(actual, scaledExpected);
if (distance > similarityCutoff) if (distance > similarityCutoff)
{ {
saveBitmap(expectedImagePath, ".expected", scaledExpected); saveBitmap(expectedImagePath, ".expected", expected);
String path = saveBitmap(expectedImagePath, "", actual); String path = saveBitmap(expectedImagePath, "", actual);
fail(String.format("Image differs from expected " + fail(String.format("Image differs from expected " +
"(distance=%f). Actual rendered " + "(distance=%f). Actual rendered " +
@ -83,7 +65,14 @@ public class BaseViewTest extends BaseAndroidTest
} }
expected.recycle(); expected.recycle();
scaledExpected.recycle(); }
catch (IOException e)
{
String path = saveBitmap(expectedImagePath, "", actual);
fail(String.format("Could not open expected image. Actual " +
"rendered image saved to %s", path));
throw e;
}
} }
@NonNull @NonNull
@ -110,8 +99,7 @@ public class BaseViewTest extends BaseAndroidTest
int specWidth = makeMeasureSpec((int) width, View.MeasureSpec.EXACTLY); int specWidth = makeMeasureSpec((int) width, View.MeasureSpec.EXACTLY);
int specHeight = makeMeasureSpec((int) height, View.MeasureSpec.EXACTLY); int specHeight = makeMeasureSpec((int) height, View.MeasureSpec.EXACTLY);
view.setLayoutParams( view.setLayoutParams(new ViewGroup.LayoutParams((int) width, (int) height));
new ViewGroup.LayoutParams((int) width, (int) height));
view.measure(specWidth, specHeight); view.measure(specWidth, specHeight);
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
} }
@ -198,4 +186,17 @@ public class BaseViewTest extends BaseAndroidTest
return absolutePath; return absolutePath;
} }
public Bitmap renderView(View view)
{
int width = view.getMeasuredWidth();
int height = view.getMeasuredHeight();
if(view.isLayoutRequested())
measureView(view, width, height);
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
view.draw(canvas);
return bitmap;
}
} }

@ -33,6 +33,8 @@ import org.isoron.uhabits.models.*;
import org.isoron.uhabits.tasks.*; import org.isoron.uhabits.tasks.*;
import org.isoron.uhabits.utils.*; import org.isoron.uhabits.utils.*;
import static org.isoron.uhabits.utils.InterfaceUtils.*;
public class HistoryEditorDialog extends AppCompatDialogFragment public class HistoryEditorDialog extends AppCompatDialogFragment
implements DialogInterface.OnClickListener, ModelObservable.Listener implements DialogInterface.OnClickListener, ModelObservable.Listener
{ {
@ -83,7 +85,7 @@ public class HistoryEditorDialog extends AppCompatDialogFragment
} }
int padding = int padding =
(int) getResources().getDimension(R.dimen.history_editor_padding); (int) getDimension(getContext(), R.dimen.history_editor_padding);
historyChart.setPadding(padding, 0, padding, 0); historyChart.setPadding(padding, 0, padding, 0);
historyChart.setIsEditable(true); historyChart.setIsEditable(true);

@ -239,7 +239,7 @@ public class BarChart extends ScrollableChart
{ {
if (height < 9) height = 200; if (height < 9) height = 200;
float maxTextSize = getResources().getDimension(R.dimen.tinyTextSize); float maxTextSize = getDimension(getContext(), R.dimen.tinyTextSize);
float textSize = height * 0.06f; float textSize = height * 0.06f;
pText.setTextSize(Math.min(textSize, maxTextSize)); pText.setTextSize(Math.min(textSize, maxTextSize));
em = pText.getFontSpacing(); em = pText.getFontSpacing();

@ -33,6 +33,7 @@ import java.text.*;
import java.util.*; import java.util.*;
import static org.isoron.uhabits.models.Checkmark.*; import static org.isoron.uhabits.models.Checkmark.*;
import static org.isoron.uhabits.utils.InterfaceUtils.*;
public class HistoryChart extends ScrollableChart public class HistoryChart extends ScrollableChart
{ {
@ -251,9 +252,8 @@ public class HistoryChart extends ScrollableChart
float baseSize = height / 8.0f; float baseSize = height / 8.0f;
setScrollerBucketSize((int) baseSize); setScrollerBucketSize((int) baseSize);
squareSpacing = InterfaceUtils.dpToPixels(getContext(), 1.0f); squareSpacing = dpToPixels(getContext(), 1.0f);
float maxTextSize = float maxTextSize = getDimension(getContext(), R.dimen.regularTextSize);
getResources().getDimension(R.dimen.regularTextSize);
float textSize = height * 0.06f; float textSize = height * 0.06f;
textSize = Math.min(textSize, maxTextSize); textSize = Math.min(textSize, maxTextSize);

@ -79,7 +79,7 @@ public class RingView extends View
color = ColorUtils.getAndroidTestColor(0); color = ColorUtils.getAndroidTestColor(0);
thickness = dpToPixels(getContext(), 2); thickness = dpToPixels(getContext(), 2);
text = ""; text = "";
textSize = context.getResources().getDimension(R.dimen.smallTextSize); textSize = getDimension(context, R.dimen.smallTextSize);
init(); init();
} }
@ -98,14 +98,13 @@ public class RingView extends View
thickness = getFloatAttribute(ctx, attrs, "thickness", 0); thickness = getFloatAttribute(ctx, attrs, "thickness", 0);
thickness = dpToPixels(ctx, thickness); thickness = dpToPixels(ctx, thickness);
float defaultTextSize = float defaultTextSize = getDimension(ctx, R.dimen.smallTextSize);
ctx.getResources().getDimension(R.dimen.smallTextSize);
textSize = getFloatAttribute(ctx, attrs, "textSize", defaultTextSize); textSize = getFloatAttribute(ctx, attrs, "textSize", defaultTextSize);
textSize = spToPixels(ctx, textSize); textSize = spToPixels(ctx, textSize);
text = AttributeSetUtils.getAttribute(ctx, attrs, "text", ""); text = getAttribute(ctx, attrs, "text", "");
enableFontAwesome = AttributeSetUtils.getBooleanAttribute(ctx, attrs, enableFontAwesome =
"enableFontAwesome", false); getBooleanAttribute(ctx, attrs, "enableFontAwesome", false);
init(); init();
} }

@ -229,7 +229,7 @@ public class ScoreChart extends ScrollableChart
{ {
if (height < 9) height = 200; if (height < 9) height = 200;
float maxTextSize = getResources().getDimension(R.dimen.tinyTextSize); float maxTextSize = getDimension(getContext(), R.dimen.tinyTextSize);
float textSize = height * 0.06f; float textSize = height * 0.06f;
pText.setTextSize(Math.min(textSize, maxTextSize)); pText.setTextSize(Math.min(textSize, maxTextSize));
em = pText.getFontSpacing(); em = pText.getFontSpacing();

@ -33,6 +33,7 @@ import java.text.*;
import java.util.*; import java.util.*;
import static android.view.View.MeasureSpec.*; import static android.view.View.MeasureSpec.*;
import static org.isoron.uhabits.utils.InterfaceUtils.getDimension;
public class StreakChart extends View public class StreakChart extends View
{ {
@ -170,9 +171,9 @@ public class StreakChart extends View
{ {
this.width = width; this.width = width;
float minTextSize = getResources().getDimension(R.dimen.tinyTextSize); Context context = getContext();
float maxTextSize = float minTextSize = getDimension(context, R.dimen.tinyTextSize);
getResources().getDimension(R.dimen.regularTextSize); float maxTextSize = getDimension(context, R.dimen.regularTextSize);
float textSize = baseSize * 0.5f; float textSize = baseSize * 0.5f;
paint.setTextSize( paint.setTextSize(

@ -20,7 +20,6 @@
package org.isoron.uhabits.activities.habits.list; package org.isoron.uhabits.activities.habits.list;
import android.content.*; import android.content.*;
import android.content.res.*;
import android.support.annotation.*; import android.support.annotation.*;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.view.*; import android.view.*;
@ -40,6 +39,8 @@ import javax.inject.*;
import butterknife.*; import butterknife.*;
import static org.isoron.uhabits.utils.InterfaceUtils.*;
@ActivityScope @ActivityScope
public class ListHabitsRootView extends BaseRootView public class ListHabitsRootView extends BaseRootView
implements ModelObservable.Listener, TaskRunner.Listener implements ModelObservable.Listener, TaskRunner.Listener
@ -171,9 +172,9 @@ public class ListHabitsRootView extends BaseRootView
private int getCheckmarkCount() private int getCheckmarkCount()
{ {
Resources res = getResources(); float nameWidth = getDimension(getContext(), R.dimen.habitNameWidth);
float labelWidth = Math.max(getMeasuredWidth() / 3, res.getDimension(R.dimen.habitNameWidth)); float labelWidth = Math.max(getMeasuredWidth() / 3, nameWidth);
float buttonWidth = res.getDimension(R.dimen.checkmarkWidth); float buttonWidth = getDimension(getContext(), R.dimen.checkmarkWidth);
return Math.min(MAX_CHECKMARK_COUNT, Math.max(0, return Math.min(MAX_CHECKMARK_COUNT, Math.max(0,
(int) ((getMeasuredWidth() - labelWidth) / buttonWidth))); (int) ((getMeasuredWidth() - labelWidth) / buttonWidth)));
} }

@ -34,6 +34,8 @@ import org.isoron.uhabits.utils.*;
import static android.view.View.MeasureSpec.*; import static android.view.View.MeasureSpec.*;
import static org.isoron.uhabits.models.Checkmark.*; 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.InterfaceUtils.getDimension;
import static org.isoron.uhabits.utils.InterfaceUtils.getFontAwesome;
public class CheckmarkButtonView extends View public class CheckmarkButtonView extends View
{ {
@ -128,14 +130,13 @@ public class CheckmarkButtonView extends View
{ {
setFocusable(false); setFocusable(false);
Resources res = getResources();
styledRes = new StyledResources(getContext()); styledRes = new StyledResources(getContext());
paint = new TextPaint(); paint = new TextPaint();
paint.setTypeface(InterfaceUtils.getFontAwesome(getContext())); paint.setTypeface(getFontAwesome(getContext()));
paint.setAntiAlias(true); paint.setAntiAlias(true);
paint.setTextAlign(Paint.Align.CENTER); paint.setTextAlign(Paint.Align.CENTER);
paint.setTextSize(res.getDimension(R.dimen.smallTextSize)); paint.setTextSize(getDimension(getContext(), R.dimen.smallTextSize));
rect = new RectF(); rect = new RectF();
color = Color.BLACK; color = Color.BLACK;

@ -36,6 +36,7 @@ import java.util.*;
import static android.view.View.MeasureSpec.*; import static android.view.View.MeasureSpec.*;
import static org.isoron.uhabits.utils.AttributeSetUtils.*; import static org.isoron.uhabits.utils.AttributeSetUtils.*;
import static org.isoron.uhabits.utils.ColorUtils.*; import static org.isoron.uhabits.utils.ColorUtils.*;
import static org.isoron.uhabits.utils.InterfaceUtils.getDimension;
public class CheckmarkPanelView extends LinearLayout public class CheckmarkPanelView extends LinearLayout
implements Preferences.Listener implements Preferences.Listener
@ -154,9 +155,8 @@ public class CheckmarkPanelView extends LinearLayout
@Override @Override
protected void onMeasure(int widthSpec, int heightSpec) protected void onMeasure(int widthSpec, int heightSpec)
{ {
float buttonWidth = getResources().getDimension(R.dimen.checkmarkWidth); float buttonWidth = getDimension(getContext(), R.dimen.checkmarkWidth);
float buttonHeight = float buttonHeight = getDimension(getContext(), R.dimen.checkmarkHeight);
getResources().getDimension(R.dimen.checkmarkHeight);
float width = buttonWidth * nButtons; float width = buttonWidth * nButtons;

@ -20,7 +20,6 @@
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.graphics.*;
import android.support.annotation.*; import android.support.annotation.*;
import android.text.*; import android.text.*;
@ -34,6 +33,8 @@ import org.isoron.uhabits.utils.*;
import java.util.*; import java.util.*;
import static org.isoron.uhabits.utils.InterfaceUtils.*;
public class HeaderView extends ScrollableChart public class HeaderView extends ScrollableChart
implements Preferences.Listener, MidnightTimer.MidnightListener implements Preferences.Listener, MidnightTimer.MidnightListener
{ {
@ -123,9 +124,8 @@ public class HeaderView extends ScrollableChart
super.onDraw(canvas); super.onDraw(canvas);
GregorianCalendar day = DateUtils.getStartOfTodayCalendar(); GregorianCalendar day = DateUtils.getStartOfTodayCalendar();
Resources res = getContext().getResources(); float width = getDimension(getContext(), R.dimen.checkmarkWidth);
float width = res.getDimension(R.dimen.checkmarkWidth); float height = getDimension(getContext(), R.dimen.checkmarkHeight);
float height = res.getDimension(R.dimen.checkmarkHeight);
boolean reverse = shouldReverseCheckmarks(); boolean reverse = shouldReverseCheckmarks();
boolean isRtl = InterfaceUtils.isLayoutRtl(this); boolean isRtl = InterfaceUtils.isLayoutRtl(this);
@ -159,22 +159,20 @@ public class HeaderView extends ScrollableChart
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{ {
int width = MeasureSpec.getSize(widthMeasureSpec); int width = MeasureSpec.getSize(widthMeasureSpec);
int height = (int) getContext() int height = (int) getDimension(getContext(), R.dimen.checkmarkHeight);
.getResources()
.getDimension(R.dimen.checkmarkHeight);
setMeasuredDimension(width, height); setMeasuredDimension(width, height);
} }
private void init() private void init()
{ {
Resources res = getContext().getResources(); setScrollerBucketSize(
setScrollerBucketSize((int) res.getDimension(R.dimen.checkmarkWidth)); (int) getDimension(getContext(), R.dimen.checkmarkWidth));
StyledResources sr = new StyledResources(getContext()); StyledResources sr = new StyledResources(getContext());
paint = new TextPaint(); paint = new TextPaint();
paint.setColor(Color.BLACK); paint.setColor(Color.BLACK);
paint.setAntiAlias(true); paint.setAntiAlias(true);
paint.setTextSize(getResources().getDimension(R.dimen.tinyTextSize)); paint.setTextSize(getDimension(getContext(), R.dimen.tinyTextSize));
paint.setTextAlign(Paint.Align.CENTER); paint.setTextAlign(Paint.Align.CENTER);
paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setTypeface(Typeface.DEFAULT_BOLD);
paint.setColor(sr.getColor(R.attr.mediumContrastTextColor)); paint.setColor(sr.getColor(R.attr.mediumContrastTextColor));

@ -20,7 +20,6 @@
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.graphics.*;
import android.support.annotation.*; import android.support.annotation.*;
import android.text.*; import android.text.*;
@ -35,6 +34,7 @@ import java.text.*;
import static org.isoron.uhabits.utils.AttributeSetUtils.*; import static org.isoron.uhabits.utils.AttributeSetUtils.*;
import static org.isoron.uhabits.utils.ColorUtils.*; import static org.isoron.uhabits.utils.ColorUtils.*;
import static org.isoron.uhabits.utils.InterfaceUtils.*;
public class NumberButtonView extends View public class NumberButtonView extends View
{ {
@ -56,8 +56,6 @@ public class NumberButtonView extends View
private TextPaint pRegular; private TextPaint pRegular;
private Resources res;
private TextPaint pBold; private TextPaint pBold;
private int lightGrey; private int lightGrey;
@ -164,25 +162,25 @@ public class NumberButtonView extends View
@Override @Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{ {
int width = (int) res.getDimension(R.dimen.checkmarkWidth); int width = (int) getDimension(getContext(), R.dimen.checkmarkWidth);
int height = (int) res.getDimension(R.dimen.checkmarkHeight); int height = (int) getDimension(getContext(), R.dimen.checkmarkHeight);
setMeasuredDimension(width, height); setMeasuredDimension(width, height);
} }
private void init() private void init()
{ {
StyledResources sr = new StyledResources(getContext()); StyledResources sr = new StyledResources(getContext());
res = getContext().getResources();
rect = new RectF(); rect = new RectF();
pRegular = new TextPaint(); pRegular = new TextPaint();
pRegular.setTextSize(res.getDimension(R.dimen.smallerTextSize)); pRegular.setTextSize(
getDimension(getContext(), R.dimen.smallerTextSize));
pRegular.setTypeface(NORMAL_TYPEFACE); pRegular.setTypeface(NORMAL_TYPEFACE);
pRegular.setAntiAlias(true); pRegular.setAntiAlias(true);
pRegular.setTextAlign(Paint.Align.CENTER); pRegular.setTextAlign(Paint.Align.CENTER);
pBold = new TextPaint(); pBold = new TextPaint();
pBold.setTextSize(res.getDimension(R.dimen.smallTextSize)); pBold.setTextSize(getDimension(getContext(), R.dimen.smallTextSize));
pBold.setTypeface(BOLD_TYPEFACE); pBold.setTypeface(BOLD_TYPEFACE);
pBold.setAntiAlias(true); pBold.setAntiAlias(true);
pBold.setTextAlign(Paint.Align.CENTER); pBold.setTextAlign(Paint.Align.CENTER);

@ -36,6 +36,7 @@ import java.util.*;
import static android.view.View.MeasureSpec.*; import static android.view.View.MeasureSpec.*;
import static org.isoron.uhabits.utils.AttributeSetUtils.*; import static org.isoron.uhabits.utils.AttributeSetUtils.*;
import static org.isoron.uhabits.utils.ColorUtils.*; import static org.isoron.uhabits.utils.ColorUtils.*;
import static org.isoron.uhabits.utils.InterfaceUtils.*;
public class NumberPanelView extends LinearLayout public class NumberPanelView extends LinearLayout
implements Preferences.Listener implements Preferences.Listener
@ -178,9 +179,9 @@ public class NumberPanelView extends LinearLayout
@Override @Override
protected void onMeasure(int widthSpec, int heightSpec) protected void onMeasure(int widthSpec, int heightSpec)
{ {
float buttonWidth = getResources().getDimension(R.dimen.checkmarkWidth); Context context = getContext();
float buttonHeight = float buttonWidth = getDimension(context, R.dimen.checkmarkWidth);
getResources().getDimension(R.dimen.checkmarkHeight); float buttonHeight = getDimension(context, R.dimen.checkmarkHeight);
float width = buttonWidth * nButtons; float width = buttonWidth * nButtons;

@ -35,7 +35,7 @@ public abstract class InterfaceUtils
@Nullable @Nullable
private static Float fixedResolution = null; private static Float fixedResolution = null;
public static void setFixedResolution(@Nullable Float f) public static void setFixedResolution(@NonNull Float f)
{ {
fixedResolution = f; fixedResolution = f;
} }
@ -67,6 +67,18 @@ public abstract class InterfaceUtils
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, metrics); return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, metrics);
} }
public static float getDimension(Context context, int id)
{
float dim = context.getResources().getDimension(id);
if (fixedResolution == null) return dim;
else
{
DisplayMetrics dm = context.getResources().getDisplayMetrics();
float actualDensity = dm.density;
return dim / actualDensity * fixedResolution;
}
}
public static void setupEditorAction(@NonNull ViewGroup parent, public static void setupEditorAction(@NonNull ViewGroup parent,
@NonNull TextView.OnEditorActionListener listener) @NonNull TextView.OnEditorActionListener listener)
{ {

@ -149,14 +149,13 @@ public abstract class BaseWidget
private Bitmap getBitmapFromView(View view) private Bitmap getBitmapFromView(View view)
{ {
view.invalidate(); view.invalidate();
view.setDrawingCacheEnabled(true); int width = view.getMeasuredWidth();
view.buildDrawingCache(true); int height = view.getMeasuredHeight();
Bitmap drawingCache = view.getDrawingCache();
if(drawingCache == null) Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
throw new IllegalStateException("bitmap is null"); Canvas canvas = new Canvas(bitmap);
view.draw(canvas);
return drawingCache; return bitmap;
} }
@NonNull @NonNull

@ -29,6 +29,8 @@ import org.isoron.uhabits.models.*;
import org.isoron.uhabits.activities.common.views.*; import org.isoron.uhabits.activities.common.views.*;
import org.isoron.uhabits.utils.*; import org.isoron.uhabits.utils.*;
import static org.isoron.uhabits.utils.InterfaceUtils.getDimension;
public class CheckmarkWidgetView extends HabitWidgetView public class CheckmarkWidgetView extends HabitWidgetView
{ {
private int activeColor; private int activeColor;
@ -154,9 +156,10 @@ public class CheckmarkWidgetView extends HabitWidgetView
w *= scale; w *= scale;
h *= scale; h *= scale;
if (h < getResources().getDimension( if (h < getDimension(getContext(), R.dimen.checkmarkWidget_heightBreakpoint))
R.dimen.checkmarkWidget_heightBreakpoint)) ring.setVisibility(GONE); ring.setVisibility(GONE);
else ring.setVisibility(VISIBLE); else
ring.setVisibility(VISIBLE);
widthMeasureSpec = widthMeasureSpec =
MeasureSpec.makeMeasureSpec((int) w, MeasureSpec.EXACTLY); MeasureSpec.makeMeasureSpec((int) w, MeasureSpec.EXACTLY);
@ -164,8 +167,7 @@ public class CheckmarkWidgetView extends HabitWidgetView
MeasureSpec.makeMeasureSpec((int) h, MeasureSpec.EXACTLY); MeasureSpec.makeMeasureSpec((int) h, MeasureSpec.EXACTLY);
float textSize = 0.15f * h; float textSize = 0.15f * h;
float maxTextSize = float maxTextSize = getDimension(getContext(), R.dimen.smallerTextSize);
getResources().getDimension(R.dimen.smallerTextSize);
textSize = Math.min(textSize, maxTextSize); textSize = Math.min(textSize, maxTextSize);
label.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); label.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);

Loading…
Cancel
Save