Add widget font size configuration

pull/437/head
Alex Baker 8 years ago
parent b1671e74fa
commit 93aec24ca9

@ -45,6 +45,8 @@ public class ScrollableViewsFactory implements RemoteViewsService.RemoteViewsFac
private final String filterId;
private final boolean showDueDates;
private final boolean hideCheckboxes;
private final float textSize;
private final float dueDateTextSize;
private TodorooCursor<Task> cursor;
@ -71,6 +73,8 @@ public class ScrollableViewsFactory implements RemoteViewsService.RemoteViewsFac
this.themeTextColor = themeTextColor;
showDueDates = preferences.getBoolean(WidgetConfigActivity.PREF_SHOW_DUE_DATE + widgetId, false);
hideCheckboxes = preferences.getBoolean(WidgetConfigActivity.PREF_HIDE_CHECKBOXES + widgetId, false);
textSize = (float) preferences.getInt(WidgetConfigActivity.PREF_FONT_SIZE + widgetId, 16);
dueDateTextSize = Math.max(10, textSize * 14 / 20);
}
@Override
@ -150,7 +154,7 @@ public class ScrollableViewsFactory implements RemoteViewsService.RemoteViewsFac
} else {
row.setInt(R.id.widget_text, "setPaintFlags", Paint.ANTI_ALIAS_FLAG);
}
row.setFloat(R.id.widget_text, "setTextSize", textSize);
if (showDueDates) {
formatDueDate(row, task, textColor);
} else if (task.hasDueDate() && task.isOverdue()) {
@ -226,6 +230,7 @@ public class ScrollableViewsFactory implements RemoteViewsService.RemoteViewsFac
? resources.getString(R.string.TAd_completed, DateUtilities.getRelativeDateStringWithTime(context, task.getCompletionDate()))
: DateUtilities.getRelativeDateStringWithTime(context, task.getDueDate()));
row.setTextColor(R.id.widget_due_date, task.isOverdue() ? resources.getColor(R.color.overdue) : textColor);
row.setFloat(R.id.widget_due_date, "setTextSize", dueDateTextSize);
} else {
row.setViewVisibility(R.id.widget_due_date, View.GONE);
}

@ -27,6 +27,7 @@ public class WidgetConfigActivity extends InjectingAppCompatActivity implements
public static final String PREF_COLOR = "widget-color-";
public static final String PREF_HIDE_HEADER = "widget-hide-header-";
public static final String PREF_WIDGET_OPACITY = "widget-opacity-v2-";
public static final String PREF_FONT_SIZE = "widget-font-size-";
@Inject Tracker tracker;
@Inject DialogBuilder dialogBuilder;

@ -43,6 +43,7 @@ public class WidgetConfigDialog extends InjectingDialogFragment {
private static final String EXTRA_THEME = "extra_theme";
private static final String EXTRA_APP_WIDGET_ID = "extra_app_widget_id";
private static final String EXTRA_OPACITY = "extra_opacity";
private static final String EXTRA_FONT_SIZE = "extra_font_size";
private static final String FRAG_TAG_SEEKBAR = "frag_tag_seekbar";
public static WidgetConfigDialog newWidgetConfigDialog(int appWidgetId) {
@ -61,6 +62,7 @@ public class WidgetConfigDialog extends InjectingDialogFragment {
private static final int REQUEST_THEME_SELECTION = 1006;
private static final int REQUEST_COLOR_SELECTION = 1007;
private static final int REQUEST_OPACITY = 1008;
private static final int REQUEST_FONT_SIZE = 1009;
@BindView(R.id.opacity_value) TextView opacityValue;
@BindView(R.id.selected_filter) TextView selectedFilter;
@ -69,6 +71,7 @@ public class WidgetConfigDialog extends InjectingDialogFragment {
@BindView(R.id.hideDueDate) CheckBox hideDueDate;
@BindView(R.id.hideCheckboxes) CheckBox hideCheckBoxes;
@BindView(R.id.hideHeader) CheckBox hideHeader;
@BindView(R.id.font_size_value) TextView selectedFontSize;
@Inject DialogBuilder dialogBuilder;
@Inject DefaultFilterProvider defaultFilterProvider;
@ -83,6 +86,7 @@ public class WidgetConfigDialog extends InjectingDialogFragment {
private int appWidgetId;
private WidgetConfigCallback callback;
private int opacityPercentage;
private int fontSize;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
@ -96,15 +100,18 @@ public class WidgetConfigDialog extends InjectingDialogFragment {
filter = savedInstanceState.getParcelable(EXTRA_FILTER);
appWidgetId = savedInstanceState.getInt(EXTRA_APP_WIDGET_ID);
opacityPercentage = savedInstanceState.getInt(EXTRA_OPACITY);
fontSize = savedInstanceState.getInt(EXTRA_FONT_SIZE);
} else {
filter = defaultFilterProvider.getDefaultFilter();
opacityPercentage = 100;
fontSize = 16;
}
updateFilter();
updateTheme();
updateColor();
updateOpacity();
updateFontSize();
return dialogBuilder.newDialog()
.setView(view)
@ -115,7 +122,12 @@ public class WidgetConfigDialog extends InjectingDialogFragment {
callback.ok();
}
})
.setNegativeButton(android.R.string.cancel, null)
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
callback.cancel();
}
})
.show();
}
@ -126,6 +138,7 @@ public class WidgetConfigDialog extends InjectingDialogFragment {
outState.putInt(EXTRA_APP_WIDGET_ID, appWidgetId);
outState.putInt(EXTRA_THEME, themeIndex);
outState.putInt(EXTRA_OPACITY, opacityPercentage);
outState.putInt(EXTRA_FONT_SIZE, fontSize);
outState.putParcelable(EXTRA_FILTER, filter);
}
@ -151,6 +164,10 @@ public class WidgetConfigDialog extends InjectingDialogFragment {
opacityValue.setText(NumberFormat.getPercentInstance().format(opacityPercentage / 100.0));
}
private void updateFontSize() {
selectedFontSize.setText(NumberFormat.getIntegerInstance().format(fontSize));
}
private void updateTheme() {
selectedTheme.setText(themeCache.getWidgetTheme(themeIndex).getName());
}
@ -187,6 +204,13 @@ public class WidgetConfigDialog extends InjectingDialogFragment {
seekBarDialog.show(getChildFragmentManager(), FRAG_TAG_SEEKBAR);
}
@OnClick(R.id.font_size)
public void showFontSizeSlider() {
SeekBarDialog seekBarDialog = newSeekBarDialog(R.layout.dialog_font_size_seekbar, 16);
seekBarDialog.setTargetFragment(this, REQUEST_FONT_SIZE);
seekBarDialog.show(getChildFragmentManager(), FRAG_TAG_SEEKBAR);
}
@Override
protected void inject(DialogFragmentComponent component) {
component.inject(this);
@ -214,6 +238,11 @@ public class WidgetConfigDialog extends InjectingDialogFragment {
opacityPercentage = data.getIntExtra(SeekBarDialog.EXTRA_VALUE, 100);
updateOpacity();
}
} else if (requestCode == REQUEST_FONT_SIZE) {
if (resultCode == Activity.RESULT_OK) {
fontSize = data.getIntExtra(SeekBarDialog.EXTRA_VALUE, 16);
updateFontSize();
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}
@ -227,6 +256,7 @@ public class WidgetConfigDialog extends InjectingDialogFragment {
preferences.setInt(WidgetConfigActivity.PREF_THEME + appWidgetId, themeIndex);
preferences.setInt(WidgetConfigActivity.PREF_COLOR + appWidgetId, colorIndex);
preferences.setInt(WidgetConfigActivity.PREF_WIDGET_OPACITY + appWidgetId, (int)(255.0 * ((double) opacityPercentage / 100.0)));
preferences.setInt(WidgetConfigActivity.PREF_FONT_SIZE + appWidgetId, fontSize);
// force update after setting preferences
context.sendBroadcast(new Intent(context, TasksWidget.class) {{

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.rey.material.widget.Slider xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/slider"
style="@style/Material.Widget.Slider.Discrete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:minHeight="?attr/listPreferredItemHeight"
android:paddingEnd="@dimen/keyline_first"
android:paddingLeft="@dimen/keyline_first"
android:paddingRight="@dimen/keyline_first"
android:paddingStart="@dimen/keyline_first"
app:sl_discreteMode="true"
app:sl_maxValue="22"
app:sl_minValue="10"
app:sl_stepValue="2"
app:sl_travelAnimDuration="50" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@id/slider"
android:paddingEnd="@dimen/keyline_first"
android:paddingLeft="@dimen/keyline_first"
android:paddingRight="@dimen/keyline_first"
android:paddingStart="@dimen/keyline_first"
android:paddingTop="5dp"
android:text="10" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="@id/slider"
android:paddingEnd="@dimen/keyline_first"
android:paddingLeft="@dimen/keyline_first"
android:paddingRight="@dimen/keyline_first"
android:paddingStart="@dimen/keyline_first"
android:paddingTop="5dp"
android:text="22" />
</RelativeLayout>

@ -120,6 +120,34 @@
</RelativeLayout>
<RelativeLayout
android:id="@+id/font_size"
style="@style/WidgetConfigRow">
<TextView
android:id="@+id/font_size_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:textColor="?attr/asTextColor"
android:textSize="18sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="@id/font_size_value"
android:layout_toStartOf="@id/font_size_value"
android:text="@string/font_size"
android:gravity="start"
android:textAlignment="viewStart"
android:textColor="?attr/asTextColor"
android:textSize="18sp" />
</RelativeLayout>
<CheckBox
android:id="@+id/hideDueDate"
style="@style/WidgetConfigRow.CheckBox"

Loading…
Cancel
Save