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

Improve overriding dimens #1852

Merged
merged 11 commits into from
Apr 21, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
android:id="@+id/question"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/item_margin_vertical"
android:layout_marginEnd="@dimen/item_margin_horizontal"
android:layout_marginStart="@dimen/barcode_question_margin_start"
android:layout_marginEnd="@dimen/barcode_question_margin_end"
/>

</LinearLayout>
Expand Down
1 change: 0 additions & 1 deletion contrib/barcode/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,4 @@
<dimen name="barcode_reticle_stroke_width">4dp</dimen>
<dimen name="barcode_reticle_corner_radius">8dp</dimen>
<dimen name="check_box_item_gap">16dp</dimen>
<dimen name="padding_default">16dp</dimen>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ fun Questionnaire.QuestionnaireItemAnswerOptionComponent.itemAnswerOptionImage(
"image/jpg",
"image/png" -> {
val bitmap = BitmapFactory.decodeByteArray(it.data, 0, it.data.size)
val imageSize = context.resources.getDimensionPixelOffset(R.dimen.choice_button_image)
val imageSize =
context.resources.getDimensionPixelOffset(R.dimen.item_answer_media_image_size)
val drawable: Drawable = BitmapDrawable(context.resources, bitmap)
drawable.setBounds(0, 0, imageSize, imageSize)
drawable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Google LLC
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,9 +23,11 @@ import androidx.recyclerview.widget.RecyclerView
/**
* ItemDecoration that applies a specified margin to the items. Use this instead of manually adding
* a margin to the item's layout.
* @param margin Int value for the desired margin used as item offset
* @param marginVertical Int value for the desired vertical margin used as item offset
* @param marginHorizontal Int value for the desired horizontal margin used as item offset
*/
class MarginItemDecoration(private val margin: Int) : RecyclerView.ItemDecoration() {
class MarginItemDecoration(private val marginVertical: Int, private val marginHorizontal: Int) :
RecyclerView.ItemDecoration() {
override fun getItemOffsets(
outRect: Rect,
view: View,
Expand All @@ -34,11 +36,11 @@ class MarginItemDecoration(private val margin: Int) : RecyclerView.ItemDecoratio
) {
outRect.apply {
if (parent.getChildAdapterPosition(view) == 0) {
top = margin
top = marginVertical
}
left = margin
right = margin
bottom = margin
left = marginHorizontal
right = marginHorizontal
bottom = marginVertical
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ internal class OptionSelectDialogFragment(
val recyclerView: RecyclerView = view.findViewById(R.id.recycler_view)
recyclerView.layoutManager = LinearLayoutManager(requireContext())
recyclerView.addItemDecoration(
MarginItemDecoration(resources.getDimensionPixelOffset(R.dimen.item_margin_vertical))
MarginItemDecoration(
marginVertical = resources.getDimensionPixelOffset(R.dimen.option_item_margin_vertical),
marginHorizontal = resources.getDimensionPixelOffset(R.dimen.option_item_margin_horizontal)
)
)

val adapter = OptionSelectAdapter(multiSelectEnabled = config.multiSelect)
Expand Down
12 changes: 6 additions & 6 deletions datacapture/src/main/res/layout/attachment_file_preview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/item_margin_horizontal"
android:layout_marginTop="@dimen/attachment_preview_base_margin"
android:layout_marginTop="@dimen/attachment_preview_margin_top"
>

<View
android:id="@+id/file_icon_background"
style="?attr/questionnaireAttachmentPreviewIconBackgroundStyle"
android:layout_width="@dimen/attachment_photo_preview_max_width"
android:layout_height="@dimen/attachment_photo_preview_max_height"
android:layout_width="@dimen/attachment_preview_photo_and_preview_file_icon_background_width"
android:layout_height="@dimen/attachment_preview_photo_and_preview_file_icon_background_height"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:background="@drawable/rounded_corner_preview_icon_bg_filled"
Expand All @@ -39,7 +39,7 @@
style="?attr/questionnaireAttachmentPreviewIconStyle"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_margin="@dimen/item_margin_horizontal"
android:layout_margin="@dimen/attachment_preview_file_icon_margin"
android:contentDescription="@string/cd_file_icon_preview"
app:layout_constraintBottom_toBottomOf="@id/file_icon_background"
app:layout_constraintEnd_toEndOf="@id/file_icon_background"
Expand All @@ -54,7 +54,7 @@
style="?attr/questionnaireAttachmentDividerStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/attachment_preview_base_margin"
android:layout_marginTop="@dimen/attachment_preview_divider_margin_top"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/file_icon_background"
/>
Expand All @@ -64,7 +64,7 @@
style="?attr/questionnaireAttachmentPreviewTitleStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/attachment_preview_base_margin"
android:layout_marginHorizontal="@dimen/attachment_preview_title_margin_horizontal"
app:layout_constraintBottom_toBottomOf="@id/file_icon_background"
app:layout_constraintEnd_toStartOf="@id/file_delete"
app:layout_constraintHorizontal_bias="0.0"
Expand Down
10 changes: 5 additions & 5 deletions datacapture/src/main/res/layout/attachment_photo_preview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/item_margin_horizontal"
android:layout_marginTop="@dimen/attachment_preview_base_margin"
android:layout_marginTop="@dimen/attachment_preview_margin_top"
>

<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/photo_thumbnail"
android:layout_width="@dimen/attachment_photo_preview_max_width"
android:layout_height="@dimen/attachment_photo_preview_max_height"
android:layout_width="@dimen/attachment_preview_photo_and_preview_file_icon_background_width"
android:layout_height="@dimen/attachment_preview_photo_and_preview_file_icon_background_height"
android:contentDescription="@string/cd_photo_preview"
android:scaleType="centerCrop"
app:layout_constraintStart_toStartOf="parent"
Expand All @@ -40,7 +40,7 @@
style="?attr/questionnaireAttachmentDividerStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/attachment_preview_base_margin"
android:layout_marginTop="@dimen/attachment_preview_divider_margin_top"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/photo_thumbnail"
/>
Expand All @@ -50,7 +50,7 @@
style="?attr/questionnaireAttachmentPreviewTitleStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/attachment_preview_base_margin"
android:layout_marginHorizontal="@dimen/attachment_preview_title_margin_horizontal"
app:layout_constraintBottom_toBottomOf="@id/photo_thumbnail"
app:layout_constraintEnd_toStartOf="@id/photo_delete"
app:layout_constraintHorizontal_bias="0.0"
Expand Down
32 changes: 16 additions & 16 deletions datacapture/src/main/res/layout/attachment_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/padding_default"
android:layout_marginVertical="@dimen/item_margin_vertical"
android:orientation="vertical"
>

Expand Down Expand Up @@ -49,7 +49,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/item_margin_horizontal"
android:layout_marginTop="@dimen/padding_default"
android:layout_marginTop="@dimen/header_margin_bottom"
android:orientation="horizontal"
>

Expand All @@ -58,8 +58,8 @@
style="?attr/questionnaireAttachmentTakePhotoButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/padding_half_size"
android:paddingHorizontal="@dimen/padding_default"
android:layout_marginEnd="@dimen/attachment_action_button_margin_end"
android:paddingHorizontal="@dimen/attachment_action_button_padding_horizontal"
android:visibility="gone"
/>

Expand All @@ -68,8 +68,8 @@
style="?attr/questionnaireAttachmentUploadButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/padding_half_size"
android:paddingHorizontal="@dimen/padding_default"
android:layout_marginEnd="@dimen/attachment_action_button_margin_end"
android:paddingHorizontal="@dimen/attachment_action_button_padding_horizontal"
android:text="@string/upload_photo"
android:visibility="gone"
app:icon="@drawable/ic_image_file"
Expand All @@ -80,8 +80,8 @@
style="?attr/questionnaireAttachmentUploadButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/padding_half_size"
android:paddingHorizontal="@dimen/padding_default"
android:layout_marginEnd="@dimen/attachment_action_button_margin_end"
android:paddingHorizontal="@dimen/attachment_action_button_padding_horizontal"
android:text="@string/upload_audio"
android:visibility="gone"
app:icon="@drawable/ic_audio_file"
Expand All @@ -92,8 +92,8 @@
style="?attr/questionnaireAttachmentUploadButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/padding_half_size"
android:paddingHorizontal="@dimen/padding_default"
android:layout_marginEnd="@dimen/attachment_action_button_margin_end"
android:paddingHorizontal="@dimen/attachment_action_button_padding_horizontal"
android:text="@string/upload_video"
android:visibility="gone"
app:icon="@drawable/ic_video_file"
Expand All @@ -104,8 +104,8 @@
style="?attr/questionnaireAttachmentUploadButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/padding_half_size"
android:paddingHorizontal="@dimen/padding_default"
android:layout_marginEnd="@dimen/attachment_action_button_margin_end"
android:paddingHorizontal="@dimen/attachment_action_button_padding_horizontal"
android:text="@string/upload_document"
android:visibility="gone"
app:icon="@drawable/ic_document_file"
Expand All @@ -116,8 +116,8 @@
style="?attr/questionnaireAttachmentUploadButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/padding_half_size"
android:paddingHorizontal="@dimen/padding_default"
android:layout_marginEnd="@dimen/attachment_action_button_margin_end"
android:paddingHorizontal="@dimen/attachment_action_button_padding_horizontal"
android:text="@string/upload_file"
android:visibility="gone"
app:icon="@drawable/ic_file"
Expand All @@ -131,7 +131,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/item_margin_horizontal"
android:layout_marginTop="@dimen/item_margin_horizontal"
android:layout_marginTop="@dimen/attachment_divider_margin_top"
android:visibility="gone"
/>

Expand All @@ -141,7 +141,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/item_margin_horizontal"
android:layout_marginTop="@dimen/item_margin_horizontal"
android:layout_marginTop="@dimen/attachment_uploaded_label_margin_top"
android:layout_marginBottom="@dimen/attachment_uploaded_label_margin_bottom"
android:text="@string/uploaded"
android:visibility="gone"
Expand Down
8 changes: 4 additions & 4 deletions datacapture/src/main/res/layout/boolean_choice_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/item_margin_horizontal"
android:layout_marginTop="@dimen/padding_default"
android:layout_marginVertical="@dimen/item_margin_vertical"
android:orientation="vertical"
>

<com.google.android.fhir.datacapture.views.HeaderView
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/padding_default"
android:layout_marginBottom="@dimen/header_margin_bottom"
/>

<com.google.android.fhir.datacapture.views.MediaView
Expand All @@ -48,8 +48,8 @@
android:layout_height="wrap_content"
android:orientation="vertical"
app:flow_horizontalBias="0"
app:flow_horizontalGap="@dimen/radio_button_item_gap"
app:flow_verticalGap="@dimen/padding_default"
app:flow_horizontalGap="@dimen/option_item_margin_horizontal"
app:flow_verticalGap="@dimen/option_item_margin_vertical"
app:flow_horizontalStyle="packed"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down
4 changes: 2 additions & 2 deletions datacapture/src/main/res/layout/check_box_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
android:id="@+id/check_box"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/item_margin_horizontal"
android:drawablePadding="@dimen/item_margin_horizontal"
android:layout_marginHorizontal="@dimen/option_item_margin_horizontal"
android:drawablePadding="@dimen/icon_drawable_padding"
/>
8 changes: 4 additions & 4 deletions datacapture/src/main/res/layout/checkbox_group_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/item_margin_horizontal"
android:layout_marginTop="@dimen/padding_default"
android:layout_marginVertical="@dimen/item_margin_vertical"
android:orientation="vertical"
>

<com.google.android.fhir.datacapture.views.HeaderView
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/padding_default"
android:layout_marginBottom="@dimen/header_margin_bottom"
/>

<com.google.android.fhir.datacapture.views.MediaView
Expand All @@ -48,8 +48,8 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
app:flow_horizontalBias="0"
app:flow_horizontalGap="@dimen/radio_button_item_gap"
app:flow_verticalGap="@dimen/padding_default"
app:flow_horizontalGap="@dimen/option_item_margin_horizontal"
app:flow_verticalGap="@dimen/option_item_margin_vertical"
app:flow_horizontalStyle="packed"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down
4 changes: 2 additions & 2 deletions datacapture/src/main/res/layout/date_picker_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/item_margin_horizontal"
android:layout_marginTop="@dimen/padding_default"
android:layout_marginVertical="@dimen/item_margin_vertical"
android:orientation="vertical"
>

<com.google.android.fhir.datacapture.views.HeaderView
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/padding_default"
android:layout_marginBottom="@dimen/header_margin_bottom"
/>

<com.google.android.fhir.datacapture.views.MediaView
Expand Down
6 changes: 3 additions & 3 deletions datacapture/src/main/res/layout/date_time_picker_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/item_margin_horizontal"
android:layout_marginTop="@dimen/padding_default"
android:layout_marginVertical="@dimen/item_margin_vertical"
android:orientation="vertical"
>

<com.google.android.fhir.datacapture.views.HeaderView
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/padding_default"
android:layout_marginBottom="@dimen/header_margin_bottom"
/>

<com.google.android.fhir.datacapture.views.MediaView
Expand Down Expand Up @@ -68,7 +68,7 @@
</com.google.android.material.textfield.TextInputLayout>

<Space
android:layout_width="@dimen/item_margin_horizontal"
android:layout_width="@dimen/date_picker_and_time_picker_gap"
android:layout_height="match_parent"
/>

Expand Down
2 changes: 1 addition & 1 deletion datacapture/src/main/res/layout/display_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/item_margin_horizontal"
android:layout_marginTop="@dimen/padding_default"
android:layout_marginVertical="@dimen/item_margin_vertical"
android:orientation="vertical"
>

Expand Down
4 changes: 2 additions & 2 deletions datacapture/src/main/res/layout/drop_down_list_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
android:id="@+id/answer_option_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawablePadding="@dimen/item_margin_horizontal"
android:drawablePadding="@dimen/icon_drawable_padding"
android:ellipsize="end"
android:maxLines="1"
android:padding="@dimen/padding_drop_down"
android:padding="@dimen/drop_down_padding"
android:textAppearance="?attr/questionnaireDropDownTextStyle"
/>
Loading