Fix previews in Layout Editor

pull/452/head^2
Alinson S. Xavier 7 years ago
parent a3e0d7ffb1
commit a839631aae

@ -299,10 +299,18 @@ public class FrequencyChart extends ScrollableChart
}
private void initDateFormats()
{
if (isInEditMode())
{
dfMonth = new SimpleDateFormat("MMM", Locale.getDefault());
dfYear = new SimpleDateFormat("yyyy", Locale.getDefault());
}
else
{
dfMonth = AndroidDateFormats.fromSkeleton("MMM");
dfYear = AndroidDateFormats.fromSkeleton("yyyy");
}
}
private void initRects()
{
@ -326,5 +334,6 @@ public class FrequencyChart extends ScrollableChart
frequency.put(new Timestamp(date), values);
date.add(Calendar.MONTH, -1);
}
maxFreq = getMaxFreq(frequency);
}
}

@ -427,10 +427,18 @@ public class HistoryChart extends ScrollableChart
}
private void initDateFormats()
{
if (isInEditMode())
{
dfMonth = new SimpleDateFormat("MMM", Locale.getDefault());
dfYear = new SimpleDateFormat("yyyy", Locale.getDefault());
}
else
{
dfMonth = AndroidDateFormats.fromSkeleton("MMM");
dfYear = AndroidDateFormats.fromSkeleton("yyyy");
}
}
private void initRects()
{

@ -410,10 +410,20 @@ public class ScoreChart extends ScrollableChart
private void initDateFormats()
{
dfYear = AndroidDateFormats.fromSkeleton("yyyy");
if (isInEditMode())
{
dfMonth = new SimpleDateFormat("MMM", Locale.getDefault());
dfYear = new SimpleDateFormat("yyyy", Locale.getDefault());
dfDay = new SimpleDateFormat("d", Locale.getDefault());
}
else
{
dfMonth = AndroidDateFormats.fromSkeleton("MMM");
dfYear = AndroidDateFormats.fromSkeleton("yyyy");
dfDay = AndroidDateFormats.fromSkeleton("d");
}
}
private void initPaints()
{

@ -234,7 +234,7 @@ public class StreakChart extends View
streaks = Collections.emptyList();
dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM);
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
if (!isInEditMode()) dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
rect = new RectF();
baseSize = getResources().getDimensionPixelSize(R.dimen.baseSize);
}

@ -107,6 +107,16 @@ public class BarCard extends HabitCard
HabitsApplication app = (HabitsApplication) appContext;
taskRunner = app.getComponent().getTaskRunner();
}
if (isInEditMode()) initEditMode();
}
private void initEditMode()
{
int color = PaletteUtils.getAndroidTestColor(1);
title.setTextColor(color);
chart.setColor(color);
chart.populateWithRandomData();
}
private class RefreshTask implements Task

@ -18,14 +18,14 @@
~ with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
android:orientation="vertical">
<org.isoron.uhabits.activities.habits.show.views.BarCard
android:id="@+id/barCard"
<org.isoron.uhabits.activities.habits.show.views.ScoreCard
style="@style/Card"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" />
</LinearLayout>
Loading…
Cancel
Save