Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increased the font size used in widget buttons #5883

Merged
merged 11 commits into from
Jan 16, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ private void adjustButtonFontSize(ViewGroup view) {
if (childView instanceof ViewGroup) {
adjustButtonFontSize((ViewGroup) childView);
} else if (childView instanceof Button) {
((Button) childView).setTextSize(QuestionFontSizeUtils.getFontSize(settings, FontSize.BODY_MEDIUM));
((Button) childView).setTextSize(QuestionFontSizeUtils.getFontSize(settings, FontSize.BODY_LARGE));
}
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.odk.collect.android.widgets.utilities

import org.odk.collect.android.application.Collect
import org.odk.collect.android.injection.DaggerUtils
import org.odk.collect.settings.keys.ProjectKeys
import org.odk.collect.shared.settings.Settings

object QuestionFontSizeUtils {
const val DEFAULT_FONT_SIZE = 21
private const val HEADLINE_6_DIFF = -1
private const val SUBTITLE_1_DIFF = -5
private const val BODY_MEDIUM_DIFF = -7
private const val BODY_LARGE_DIFF = -5

@JvmStatic
fun getFontSize(settings: Settings, fontSize: FontSize?): Int {
val settingsValue = settings.getString(ProjectKeys.KEY_FONT_SIZE)!!.toInt()

return when (fontSize) {
FontSize.HEADLINE_6 -> settingsValue + HEADLINE_6_DIFF
FontSize.SUBTITLE_1 -> settingsValue + SUBTITLE_1_DIFF
FontSize.BODY_MEDIUM -> settingsValue + BODY_MEDIUM_DIFF
FontSize.BODY_LARGE -> settingsValue + BODY_LARGE_DIFF
else -> throw IllegalArgumentException()
}
}

@JvmStatic
@Deprecated("Use {@link QuestionFontSizeUtils#getFontSize(Settings, FontSize)} instead")
fun getQuestionFontSize(): Int {
return try {
val fontSize = DaggerUtils.getComponent(Collect.getInstance()).settingsProvider().getUnprotectedSettings().getString(ProjectKeys.KEY_FONT_SIZE)!!.toInt()
fontSize + HEADLINE_6_DIFF
} catch (e: Exception) {
DEFAULT_FONT_SIZE
} catch (e: Error) {
DEFAULT_FONT_SIZE
}
}

enum class FontSize {
HEADLINE_6, SUBTITLE_1, BODY_MEDIUM, BODY_LARGE
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<com.google.android.material.button.MaterialButton
android:id="@+id/arbitrary_file_button"
style="?materialButtonStyle"
style="?widgetButtonQuestionWidgetStyle"
android:text="@string/choose_file"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Expand Down
4 changes: 2 additions & 2 deletions collect_app/src/main/res/layout/audio_widget_answer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeButton
android:id="@+id/capture_button"
style="?materialButtonStyle"
style="?widgetButtonQuestionWidgetStyle"
android:text="@string/capture_audio"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeButton
android:id="@+id/choose_button"
android:layout_marginTop="@dimen/margin_small"
style="?materialButtonStyle"
style="?widgetButtonQuestionWidgetStyle"
android:text="@string/choose_sound"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Expand Down
2 changes: 1 addition & 1 deletion collect_app/src/main/res/layout/barcode_widget_answer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<com.google.android.material.button.MaterialButton
android:id="@+id/barcode_button"
style="?materialButtonStyle"
style="?widgetButtonQuestionWidgetStyle"
android:text="@string/get_barcode"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Expand Down
2 changes: 1 addition & 1 deletion collect_app/src/main/res/layout/bearing_widget_answer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeButton
android:id="@+id/bearing_button"
style="?materialButtonStyle"
style="?widgetButtonQuestionWidgetStyle"
android:text="@string/get_bearing"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Expand Down
2 changes: 1 addition & 1 deletion collect_app/src/main/res/layout/date_widget_answer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeButton
android:id="@+id/date_button"
style="?materialButtonStyle"
style="?widgetButtonQuestionWidgetStyle"
android:text="@string/select_date"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<com.google.android.material.button.MaterialButton
android:id="@+id/ex_arbitrary_file_button"
style="?materialButtonStyle"
style="?widgetButtonQuestionWidgetStyle"
android:text="@string/launch_app"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Expand Down
2 changes: 1 addition & 1 deletion collect_app/src/main/res/layout/ex_audio_widget_answer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<com.google.android.material.button.MaterialButton
android:id="@+id/launch_external_app_button"
style="?materialButtonStyle"
style="?widgetButtonQuestionWidgetStyle"
android:text="@string/launch_app"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Expand Down
2 changes: 1 addition & 1 deletion collect_app/src/main/res/layout/ex_image_widget_answer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<com.google.android.material.button.MaterialButton
android:id="@+id/launch_external_app_button"
style="?materialButtonStyle"
style="?widgetButtonQuestionWidgetStyle"
android:text="@string/launch_app"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Expand Down
4 changes: 2 additions & 2 deletions collect_app/src/main/res/layout/ex_video_widget_answer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

<com.google.android.material.button.MaterialButton
android:id="@+id/capture_video_button"
style="?materialButtonStyle"
style="?widgetButtonQuestionWidgetStyle"
android:text="@string/launch_app"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<com.google.android.material.button.MaterialButton
android:id="@+id/play_video_button"
style="?materialButtonStyle"
style="?widgetButtonQuestionWidgetStyle"
android:text="@string/play_video"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
2 changes: 1 addition & 1 deletion collect_app/src/main/res/layout/geo_widget_answer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeButton
android:id="@+id/simple_button"
style="?materialButtonStyle"
style="?widgetButtonQuestionWidgetStyle"
android:text="@string/get_location"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Expand Down
2 changes: 1 addition & 1 deletion collect_app/src/main/res/layout/osm_widget_answer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeButton
android:id="@+id/launch_open_map_kit_button"
style="?materialButtonStyle"
style="?widgetButtonQuestionWidgetStyle"
android:text="@string/capture_osm"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeButton
android:id="@+id/widget_button"
style="?materialButtonStyle"
style="?widgetButtonQuestionWidgetStyle"
android:text="@string/select_value"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeButton
android:id="@+id/button"
style="?materialButtonStyle"
style="?widgetButtonQuestionWidgetStyle"
android:text="@string/select_place"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down
2 changes: 1 addition & 1 deletion collect_app/src/main/res/layout/time_widget_answer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeButton
android:id="@+id/time_button"
style="?materialButtonStyle"
style="?widgetButtonQuestionWidgetStyle"
android:text="@string/select_time"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Expand Down
2 changes: 1 addition & 1 deletion collect_app/src/main/res/layout/url_widget_answer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<org.odk.collect.androidshared.ui.multiclicksafe.MultiClickSafeButton
android:id="@+id/url_button"
style="?materialButtonStyle"
style="?widgetButtonQuestionWidgetStyle"
android:text="@string/open_url"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Expand Down
2 changes: 1 addition & 1 deletion collect_app/src/main/res/layout/widget_answer_button.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.button.MaterialButton xmlns:android="http://schemas.android.com/apk/res/android"
style="?materialButtonStyle"
style="?widgetButtonQuestionWidgetStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content">

Expand Down
6 changes: 6 additions & 0 deletions collect_app/src/main/res/values/buttons.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Widget.Collect.Button.QuestionWidget" parent="Widget.Material3.Button">
<item name="android:paddingTop">12dp</item>
<item name="android:paddingBottom">12dp</item>
<item name="android:textAppearance">?textAppearanceBodyLarge</item>
</style>

<style name="Widget.Collect.Button" parent="Widget.Material3.Button">
<item name="android:paddingTop">12dp</item>
<item name="android:paddingBottom">12dp</item>
Expand Down
16 changes: 8 additions & 8 deletions collect_app/src/main/res/values/theme.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,16 @@
<item name="materialButtonOutlinedIconStyle">@style/Widget.Collect.Button.OutlinedButton.Icon</item>
<item name="materialIconButtonOutlinedStyle">@style/Widget.Collect.Button.IconButton.Outlined</item>
<item name="borderlessButtonIconStyle">@style/Widget.Collect.Button.TextButton.Icon</item>
<item name="materialButtonStyle">@style/Widget.Collect.Button</item>
<item name="materialButtonOutlinedStyle">@style/Widget.Collect.Button.OutlinedButton</item>
<item name="borderlessButtonStyle">@style/Widget.Collect.Button.TextButton</item>
<item name="materialAlertDialogTheme">@style/Theme.Collect.Dialog.Alert</item>

<!-- Custom style for buttons used in question widgets -->
<item name="widgetButtonQuestionWidgetStyle">@style/Widget.Collect.Button.QuestionWidget</item>

<!-- Custom theme text appearance for larger buttons -->
<item name="textAppearanceLabelExtraLarge">@style/TextAppearance.Collect.LabelExtraLarge
</item>
<item name="textAppearanceLabelExtraLarge">@style/TextAppearance.Collect.LabelExtraLarge</item>

<!-- Needed to make scrollbars always visible -->
<item name="android:scrollbars">vertical</item>
Expand All @@ -117,12 +123,6 @@
<!-- Use locale for text direction in views -->
<item name="android:textDirection">locale</item>


<item name="materialButtonStyle">@style/Widget.Collect.Button</item>
<item name="materialButtonOutlinedStyle">@style/Widget.Collect.Button.OutlinedButton</item>
<item name="borderlessButtonStyle">@style/Widget.Collect.Button.TextButton</item>
<item name="materialAlertDialogTheme">@style/Theme.Collect.Dialog.Alert</item>

<!-- Sets up theme correction for anything using `AlertDialog.Builder` -->
<item name="alertDialogTheme">@style/Theme.Collect.Dialog.Alert</item>
<item name="android:alertDialogTheme">@style/Theme.Collect.Dialog.Alert</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public ArbitraryFileWidget createWidget() {
public void whenFontSizeChanged_CustomFontSizeShouldBeUsed() {
settingsProvider.getUnprotectedSettings().save(KEY_FONT_SIZE, "30");

assertThat((int) getWidget().binding.arbitraryFileButton.getTextSize(), is(QuestionFontSizeUtils.getFontSize(settingsProvider.getUnprotectedSettings(), FontSize.BODY_MEDIUM)));
assertThat((int) getWidget().binding.arbitraryFileButton.getTextSize(), is(QuestionFontSizeUtils.getFontSize(settingsProvider.getUnprotectedSettings(), FontSize.BODY_LARGE)));
assertThat((int) getWidget().binding.arbitraryFileAnswerText.getTextSize(), is(QuestionFontSizeUtils.getFontSize(settingsProvider.getUnprotectedSettings(), FontSize.HEADLINE_6)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public ExArbitraryFileWidget createWidget() {
public void whenFontSizeChanged_CustomFontSizeShouldBeUsed() {
settingsProvider.getUnprotectedSettings().save(KEY_FONT_SIZE, "30");

assertThat((int) getWidget().binding.exArbitraryFileButton.getTextSize(), is(QuestionFontSizeUtils.getFontSize(settingsProvider.getUnprotectedSettings(), FontSize.BODY_MEDIUM)));
assertThat((int) getWidget().binding.exArbitraryFileButton.getTextSize(), is(QuestionFontSizeUtils.getFontSize(settingsProvider.getUnprotectedSettings(), FontSize.BODY_LARGE)));
assertThat((int) getWidget().binding.exArbitraryFileAnswerText.getTextSize(), is(QuestionFontSizeUtils.getFontSize(settingsProvider.getUnprotectedSettings(), FontSize.HEADLINE_6)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void whenWidgetCreated_shouldLaunchButtonHaveProperName() {
public void whenFontSizeChanged_CustomFontSizeShouldBeUsed() {
settingsProvider.getUnprotectedSettings().save(KEY_FONT_SIZE, "30");

assertThat((int) getWidget().binding.launchExternalAppButton.getTextSize(), is(QuestionFontSizeUtils.getFontSize(settingsProvider.getUnprotectedSettings(), FontSize.BODY_MEDIUM)));
assertThat((int) getWidget().binding.launchExternalAppButton.getTextSize(), is(QuestionFontSizeUtils.getFontSize(settingsProvider.getUnprotectedSettings(), FontSize.BODY_LARGE)));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void whenWidgetCreated_shouldLaunchButtonHaveProperName() {
public void whenFontSizeChanged_CustomFontSizeShouldBeUsed() {
settingsProvider.getUnprotectedSettings().save(KEY_FONT_SIZE, "30");

assertThat((int) getWidget().binding.launchExternalAppButton.getTextSize(), is(QuestionFontSizeUtils.getFontSize(settingsProvider.getUnprotectedSettings(), FontSize.BODY_MEDIUM)));
assertThat((int) getWidget().binding.launchExternalAppButton.getTextSize(), is(QuestionFontSizeUtils.getFontSize(settingsProvider.getUnprotectedSettings(), FontSize.BODY_LARGE)));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public void whenWidgetCreated_shouldButtonsHaveProperNames() {
public void whenFontSizeChanged_CustomFontSizeShouldBeUsed() {
settingsProvider.getUnprotectedSettings().save(KEY_FONT_SIZE, "30");

assertThat((int) getWidget().binding.captureVideoButton.getTextSize(), is(QuestionFontSizeUtils.getFontSize(settingsProvider.getUnprotectedSettings(), FontSize.BODY_MEDIUM)));
assertThat((int) getWidget().binding.playVideoButton.getTextSize(), is(QuestionFontSizeUtils.getFontSize(settingsProvider.getUnprotectedSettings(), FontSize.BODY_MEDIUM)));
assertThat((int) getWidget().binding.captureVideoButton.getTextSize(), is(QuestionFontSizeUtils.getFontSize(settingsProvider.getUnprotectedSettings(), FontSize.BODY_LARGE)));
assertThat((int) getWidget().binding.playVideoButton.getTextSize(), is(QuestionFontSizeUtils.getFontSize(settingsProvider.getUnprotectedSettings(), FontSize.BODY_LARGE)));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class SelectOneFromMapWidgetTest {

assertThat(
widget.binding.button.textSize.toInt(),
equalTo(QuestionFontSizeUtils.getFontSize(settings, FontSize.BODY_MEDIUM))
equalTo(QuestionFontSizeUtils.getFontSize(settings, FontSize.BODY_LARGE))
)
}

Expand Down
4 changes: 4 additions & 0 deletions material/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@
<attr name="materialButtonIconStyle" format="reference" />
<attr name="borderlessButtonIconStyle" format="reference" />
</declare-styleable>

<declare-styleable name="CollectCustomAttributes">
<attr name="widgetButtonQuestionWidgetStyle" format="reference" />
</declare-styleable>
</resources>