Allow theme to be fixed during tests

pull/84/merge
Alinson S. Xavier 10 years ago
parent dbca3238f6
commit 677a643e5b

@ -25,6 +25,7 @@ import android.os.Looper;
import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry;
import org.isoron.uhabits.helpers.DateHelper; import org.isoron.uhabits.helpers.DateHelper;
import org.isoron.uhabits.helpers.UIHelper;
import org.isoron.uhabits.tasks.BaseTask; import org.isoron.uhabits.tasks.BaseTask;
import org.junit.Before; import org.junit.Before;
@ -48,10 +49,9 @@ public class BaseTest
} }
targetContext = InstrumentationRegistry.getTargetContext(); targetContext = InstrumentationRegistry.getTargetContext();
targetContext.setTheme(R.style.AppBaseTheme);
testContext = InstrumentationRegistry.getContext(); testContext = InstrumentationRegistry.getContext();
UIHelper.setFixedTheme(R.style.AppBaseTheme);
DateHelper.setFixedLocalTime(FIXED_LOCAL_TIME); DateHelper.setFixedLocalTime(FIXED_LOCAL_TIME);
} }

@ -22,7 +22,9 @@ package org.isoron.uhabits.unit.views;
import android.support.test.runner.AndroidJUnit4; import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest; import android.test.suitebuilder.annotation.SmallTest;
import org.isoron.uhabits.R;
import org.isoron.uhabits.helpers.DateHelper; import org.isoron.uhabits.helpers.DateHelper;
import org.isoron.uhabits.helpers.UIHelper;
import org.isoron.uhabits.models.Habit; import org.isoron.uhabits.models.Habit;
import org.isoron.uhabits.unit.HabitFixtures; import org.isoron.uhabits.unit.HabitFixtures;
import org.isoron.uhabits.views.CheckmarkWidgetView; import org.isoron.uhabits.views.CheckmarkWidgetView;
@ -43,6 +45,7 @@ public class CheckmarkWidgetViewTest extends ViewTest
public void setup() public void setup()
{ {
super.setup(); super.setup();
UIHelper.setFixedTheme(R.style.TransparentWidgetTheme);
habit = HabitFixtures.createShortHabit(); habit = HabitFixtures.createShortHabit();
view = new CheckmarkWidgetView(targetContext); view = new CheckmarkWidgetView(targetContext);

@ -51,6 +51,12 @@ public abstract class UIHelper
public static final int THEME_DARK = 1; public static final int THEME_DARK = 1;
private static Typeface fontAwesome; private static Typeface fontAwesome;
private static Integer fixedTheme;
public static void setFixedTheme(Integer fixedTheme)
{
UIHelper.fixedTheme = fixedTheme;
}
public interface OnSavedListener public interface OnSavedListener
{ {
@ -202,18 +208,25 @@ public abstract class UIHelper
public static int getStyledColor(Context context, int attrId) public static int getStyledColor(Context context, int attrId)
{ {
int[] attrs = new int[]{ attrId }; TypedArray ta = getTypedArray(context, attrId);
TypedArray ta = context.obtainStyledAttributes(attrs);
int color = ta.getColor(0, 0); int color = ta.getColor(0, 0);
ta.recycle(); ta.recycle();
return color; return color;
} }
public static Drawable getStyledDrawable(Context context, int attrId) private static TypedArray getTypedArray(Context context, int attrId)
{ {
int[] attrs = new 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); Drawable drawable = ta.getDrawable(0);
ta.recycle(); ta.recycle();
@ -222,8 +235,7 @@ public abstract class UIHelper
public static boolean getStyledBoolean(Context context, int attrId) public static boolean getStyledBoolean(Context context, int attrId)
{ {
int[] attrs = new int[]{ attrId }; TypedArray ta = getTypedArray(context, attrId);
TypedArray ta = context.obtainStyledAttributes(attrs);
boolean bool = ta.getBoolean(0, false); boolean bool = ta.getBoolean(0, false);
ta.recycle(); ta.recycle();
@ -232,8 +244,7 @@ public abstract class UIHelper
public static float getStyledFloat(Context context, int attrId) public static float getStyledFloat(Context context, int attrId)
{ {
int[] attrs = new int[]{ attrId }; TypedArray ta = getTypedArray(context, attrId);
TypedArray ta = context.obtainStyledAttributes(attrs);
float f = ta.getFloat(0, 0); float f = ta.getFloat(0, 0);
ta.recycle(); ta.recycle();
@ -242,10 +253,9 @@ public abstract class UIHelper
static int getStyleResource(Context context, int attrId) static int getStyleResource(Context context, int attrId)
{ {
int[] attr = new int[] { attrId }; TypedArray ta = getTypedArray(context, attrId);
TypedArray array = context.obtainStyledAttributes(attr); int resourceId = ta.getResourceId(0, -1);
int resourceId = array.getResourceId(0, -1); ta.recycle();
array.recycle();
return resourceId; return resourceId;
} }

@ -41,8 +41,8 @@ grep -q "FAILURES\!\!\!" ${OUTPUT_DIR}/runner.txt && failed=1
info "Fetching failed generated files..." info "Fetching failed generated files..."
mkdir -p ${OUTPUT_DIR}/failed mkdir -p ${OUTPUT_DIR}/failed
adb pull /mnt/sdcard/test-screenshots/ ${OUTPUT_DIR}/failed >> $LOG 2>> $LOG adb pull /mnt/sdcard/test-screenshots/ ${OUTPUT_DIR}/failed >> $LOG 2>> $LOG
adb pull /sdcard/Android/data/${PACKAGE_NAME}/files/test-screenshots/ \ adb pull /storage/sdcard/test-screenshots/ ${OUTPUT_DIR}/failed >> $LOG 2>> $LOG
${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 adb shell rm -r /sdcard/Android/data/${PACKAGE_NAME}/files/test-screenshots/ >> $LOG 2>> $LOG
info "Fetching logcat..." info "Fetching logcat..."

Loading…
Cancel
Save