Fix previews in Layout Editor

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

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

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

@ -410,9 +410,19 @@ public class ScoreChart extends ScrollableChart
private void initDateFormats() private void initDateFormats()
{ {
dfYear = AndroidDateFormats.fromSkeleton("yyyy"); if (isInEditMode())
dfMonth = AndroidDateFormats.fromSkeleton("MMM"); {
dfDay = AndroidDateFormats.fromSkeleton("d"); 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() private void initPaints()

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

@ -107,6 +107,16 @@ public class BarCard extends HabitCard
HabitsApplication app = (HabitsApplication) appContext; HabitsApplication app = (HabitsApplication) appContext;
taskRunner = app.getComponent().getTaskRunner(); 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 private class RefreshTask implements Task

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