Adjust text size and position on HistoryView and StreakView

pull/84/head
Alinson S. Xavier 10 years ago
parent c757ce6548
commit c4bf31e778

@ -134,8 +134,10 @@ public class HabitHistoryView extends ScrollableDataView implements HabitDataVie
setScrollerBucketSize((int) baseSize); setScrollerBucketSize((int) baseSize);
squareSpacing = UIHelper.dpToPixels(getContext(), 1.0f); squareSpacing = UIHelper.dpToPixels(getContext(), 1.0f);
float maxTextSize = getResources().getDimensionPixelSize(R.dimen.regularTextSize); float minTextSize = getResources().getDimension(R.dimen.tinyTextSize);
float textSize = Math.min(baseSize * 0.5f, maxTextSize); float maxTextSize = getResources().getDimension(R.dimen.regularTextSize);
float textSize = height * 0.045f;
textSize = Math.max(Math.min(textSize, maxTextSize), minTextSize);
pSquareFg.setTextSize(textSize); pSquareFg.setTextSize(textSize);
pTextHeader.setTextSize(textSize); pTextHeader.setTextSize(textSize);
@ -301,11 +303,13 @@ public class HabitHistoryView extends ScrollableDataView implements HabitDataVie
private void drawAxis(Canvas canvas, RectF location) private void drawAxis(Canvas canvas, RectF location)
{ {
float verticalOffset = pTextHeader.getFontSpacing() * 0.4f;
for (String day : DateHelper.getLocaleDayNames(Calendar.SHORT)) for (String day : DateHelper.getLocaleDayNames(Calendar.SHORT))
{ {
location.offset(0, columnWidth); location.offset(0, columnWidth);
canvas.drawText(day, location.left + headerTextOffset, canvas.drawText(day, location.left + headerTextOffset,
location.bottom - headerTextOffset, pTextHeader); location.centerY() + verticalOffset, pTextHeader);
} }
} }

@ -111,10 +111,11 @@ public class HabitStreakView extends View implements HabitDataView
maxStreakCount = height / baseSize; maxStreakCount = height / baseSize;
this.width = width; this.width = width;
int maxTextSize = getResources().getDimensionPixelSize(R.dimen.regularTextSize); float minTextSize = getResources().getDimension(R.dimen.tinyTextSize);
float regularTextSize = Math.min(baseSize * 0.56f, maxTextSize); float maxTextSize = getResources().getDimension(R.dimen.regularTextSize);
float textSize = baseSize * 0.5f;
paint.setTextSize(regularTextSize); paint.setTextSize(Math.max(Math.min(textSize, maxTextSize), minTextSize));
em = paint.getFontSpacing(); em = paint.getFontSpacing();
textMargin = 0.5f * em; textMargin = 0.5f * em;

@ -22,7 +22,7 @@
android:minHeight="80dp" android:minHeight="80dp"
android:minWidth="80dp" android:minWidth="80dp"
android:minResizeWidth="40dp" android:minResizeWidth="40dp"
android:minResizeHeight="40dp" android:minResizeHeight="80dp"
android:initialLayout="@layout/widget_graph" android:initialLayout="@layout/widget_graph"
android:previewImage="@drawable/widget_preview_history" android:previewImage="@drawable/widget_preview_history"
android:resizeMode="vertical|horizontal" android:resizeMode="vertical|horizontal"

Loading…
Cancel
Save