mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
View tests: use fixed screen density
This commit is contained in:
@@ -78,6 +78,7 @@ public class BaseAndroidTest
|
||||
targetContext = InstrumentationRegistry.getTargetContext();
|
||||
testContext = InstrumentationRegistry.getContext();
|
||||
|
||||
InterfaceUtils.setFixedResolution(2.0f);
|
||||
DateUtils.setFixedLocalTime(FIXED_LOCAL_TIME);
|
||||
setTheme(R.style.AppBaseTheme);
|
||||
setLocale("en", "US");
|
||||
|
||||
@@ -100,17 +100,18 @@ public class BaseViewTest extends BaseAndroidTest
|
||||
return view;
|
||||
}
|
||||
|
||||
protected int dpToPixels(int dp)
|
||||
protected float dpToPixels(int dp)
|
||||
{
|
||||
return (int) InterfaceUtils.dpToPixels(targetContext, dp);
|
||||
return InterfaceUtils.dpToPixels(targetContext, dp);
|
||||
}
|
||||
|
||||
protected void measureView(View view, int width, int height)
|
||||
protected void measureView(View view, float width, float height)
|
||||
{
|
||||
int specWidth = makeMeasureSpec(width, View.MeasureSpec.EXACTLY);
|
||||
int specHeight = makeMeasureSpec(height, View.MeasureSpec.EXACTLY);
|
||||
int specWidth = makeMeasureSpec((int) width, View.MeasureSpec.EXACTLY);
|
||||
int specHeight = makeMeasureSpec((int) height, View.MeasureSpec.EXACTLY);
|
||||
|
||||
view.setLayoutParams(new ViewGroup.LayoutParams(width, height));
|
||||
view.setLayoutParams(
|
||||
new ViewGroup.LayoutParams((int) width, (int) height));
|
||||
view.measure(specWidth, specHeight);
|
||||
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ package org.isoron.uhabits.activities.common.views;
|
||||
|
||||
import android.support.test.runner.*;
|
||||
import android.test.suitebuilder.annotation.*;
|
||||
import android.util.*;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
@@ -58,8 +57,6 @@ public class ScoreChartTest extends BaseViewTest
|
||||
@Test
|
||||
public void testRender() throws Throwable
|
||||
{
|
||||
Log.d("HabitScoreViewTest",
|
||||
String.format("height=%d", dpToPixels(100)));
|
||||
assertRenders(view, BASE_PATH + "render.png");
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,14 @@ public abstract class InterfaceUtils
|
||||
{
|
||||
private static Typeface fontAwesome;
|
||||
|
||||
@Nullable
|
||||
private static Float fixedResolution = null;
|
||||
|
||||
public static void setFixedResolution(@Nullable Float f)
|
||||
{
|
||||
fixedResolution = f;
|
||||
}
|
||||
|
||||
public static Typeface getFontAwesome(Context context)
|
||||
{
|
||||
if(fontAwesome == null) fontAwesome =
|
||||
@@ -43,6 +51,8 @@ public abstract class InterfaceUtils
|
||||
|
||||
public static float dpToPixels(Context context, float dp)
|
||||
{
|
||||
if(fixedResolution != null) return dp * fixedResolution;
|
||||
|
||||
Resources resources = context.getResources();
|
||||
DisplayMetrics metrics = resources.getDisplayMetrics();
|
||||
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, metrics);
|
||||
@@ -50,6 +60,8 @@ public abstract class InterfaceUtils
|
||||
|
||||
public static float spToPixels(Context context, float sp)
|
||||
{
|
||||
if(fixedResolution != null) return sp * fixedResolution;
|
||||
|
||||
Resources resources = context.getResources();
|
||||
DisplayMetrics metrics = resources.getDisplayMetrics();
|
||||
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, metrics);
|
||||
|
||||
Reference in New Issue
Block a user