mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
Allow theme to be fixed during tests
This commit is contained in:
@@ -25,6 +25,7 @@ import android.os.Looper;
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
|
||||
import org.isoron.uhabits.helpers.DateHelper;
|
||||
import org.isoron.uhabits.helpers.UIHelper;
|
||||
import org.isoron.uhabits.tasks.BaseTask;
|
||||
import org.junit.Before;
|
||||
|
||||
@@ -48,10 +49,9 @@ public class BaseTest
|
||||
}
|
||||
|
||||
targetContext = InstrumentationRegistry.getTargetContext();
|
||||
targetContext.setTheme(R.style.AppBaseTheme);
|
||||
|
||||
testContext = InstrumentationRegistry.getContext();
|
||||
|
||||
UIHelper.setFixedTheme(R.style.AppBaseTheme);
|
||||
DateHelper.setFixedLocalTime(FIXED_LOCAL_TIME);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,9 @@ package org.isoron.uhabits.unit.views;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
|
||||
import org.isoron.uhabits.R;
|
||||
import org.isoron.uhabits.helpers.DateHelper;
|
||||
import org.isoron.uhabits.helpers.UIHelper;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
import org.isoron.uhabits.unit.HabitFixtures;
|
||||
import org.isoron.uhabits.views.CheckmarkWidgetView;
|
||||
@@ -43,6 +45,7 @@ public class CheckmarkWidgetViewTest extends ViewTest
|
||||
public void setup()
|
||||
{
|
||||
super.setup();
|
||||
UIHelper.setFixedTheme(R.style.TransparentWidgetTheme);
|
||||
|
||||
habit = HabitFixtures.createShortHabit();
|
||||
view = new CheckmarkWidgetView(targetContext);
|
||||
|
||||
@@ -51,6 +51,12 @@ public abstract class UIHelper
|
||||
public static final int THEME_DARK = 1;
|
||||
|
||||
private static Typeface fontAwesome;
|
||||
private static Integer fixedTheme;
|
||||
|
||||
public static void setFixedTheme(Integer fixedTheme)
|
||||
{
|
||||
UIHelper.fixedTheme = fixedTheme;
|
||||
}
|
||||
|
||||
public interface OnSavedListener
|
||||
{
|
||||
@@ -202,18 +208,25 @@ public abstract class UIHelper
|
||||
|
||||
public static int getStyledColor(Context context, int attrId)
|
||||
{
|
||||
int[] attrs = new int[]{ attrId };
|
||||
TypedArray ta = context.obtainStyledAttributes(attrs);
|
||||
TypedArray ta = getTypedArray(context, attrId);
|
||||
int color = ta.getColor(0, 0);
|
||||
ta.recycle();
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
public static Drawable getStyledDrawable(Context context, int attrId)
|
||||
private static TypedArray getTypedArray(Context context, int attrId)
|
||||
{
|
||||
int[] attrs = new int[]{ attrId };
|
||||
TypedArray ta = context.obtainStyledAttributes(attrs);
|
||||
if(fixedTheme != null)
|
||||
return context.getTheme().obtainStyledAttributes(fixedTheme, attrs);
|
||||
else
|
||||
return context.obtainStyledAttributes(attrs);
|
||||
}
|
||||
|
||||
public static Drawable getStyledDrawable(Context context, int attrId)
|
||||
{
|
||||
TypedArray ta = getTypedArray(context, attrId);
|
||||
Drawable drawable = ta.getDrawable(0);
|
||||
ta.recycle();
|
||||
|
||||
@@ -222,8 +235,7 @@ public abstract class UIHelper
|
||||
|
||||
public static boolean getStyledBoolean(Context context, int attrId)
|
||||
{
|
||||
int[] attrs = new int[]{ attrId };
|
||||
TypedArray ta = context.obtainStyledAttributes(attrs);
|
||||
TypedArray ta = getTypedArray(context, attrId);
|
||||
boolean bool = ta.getBoolean(0, false);
|
||||
ta.recycle();
|
||||
|
||||
@@ -232,8 +244,7 @@ public abstract class UIHelper
|
||||
|
||||
public static float getStyledFloat(Context context, int attrId)
|
||||
{
|
||||
int[] attrs = new int[]{ attrId };
|
||||
TypedArray ta = context.obtainStyledAttributes(attrs);
|
||||
TypedArray ta = getTypedArray(context, attrId);
|
||||
float f = ta.getFloat(0, 0);
|
||||
ta.recycle();
|
||||
|
||||
@@ -242,10 +253,9 @@ public abstract class UIHelper
|
||||
|
||||
static int getStyleResource(Context context, int attrId)
|
||||
{
|
||||
int[] attr = new int[] { attrId };
|
||||
TypedArray array = context.obtainStyledAttributes(attr);
|
||||
int resourceId = array.getResourceId(0, -1);
|
||||
array.recycle();
|
||||
TypedArray ta = getTypedArray(context, attrId);
|
||||
int resourceId = ta.getResourceId(0, -1);
|
||||
ta.recycle();
|
||||
|
||||
return resourceId;
|
||||
}
|
||||
|
||||
@@ -41,8 +41,8 @@ grep -q "FAILURES\!\!\!" ${OUTPUT_DIR}/runner.txt && failed=1
|
||||
info "Fetching failed generated files..."
|
||||
mkdir -p ${OUTPUT_DIR}/failed
|
||||
adb pull /mnt/sdcard/test-screenshots/ ${OUTPUT_DIR}/failed >> $LOG 2>> $LOG
|
||||
adb pull /sdcard/Android/data/${PACKAGE_NAME}/files/test-screenshots/ \
|
||||
${OUTPUT_DIR}/failed >> $LOG 2>> $LOG
|
||||
adb pull /storage/sdcard/test-screenshots/ ${OUTPUT_DIR}/failed >> $LOG 2>> $LOG
|
||||
adb pull /sdcard/Android/data/${PACKAGE_NAME}/files/test-screenshots/ ${OUTPUT_DIR}/failed >> $LOG 2>> $LOG
|
||||
adb shell rm -r /sdcard/Android/data/${PACKAGE_NAME}/files/test-screenshots/ >> $LOG 2>> $LOG
|
||||
|
||||
info "Fetching logcat..."
|
||||
|
||||
Reference in New Issue
Block a user