Skip to content

Commit

Permalink
Support location widget to get current location
Browse files Browse the repository at this point in the history
  • Loading branch information
LZRS committed Nov 28, 2023
1 parent 704d753 commit 47d3126
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import com.google.android.fhir.datacapture.views.factories.EditTextIntegerViewHo
import com.google.android.fhir.datacapture.views.factories.EditTextMultiLineViewHolderFactory
import com.google.android.fhir.datacapture.views.factories.EditTextSingleLineViewHolderFactory
import com.google.android.fhir.datacapture.views.factories.GroupViewHolderFactory
import com.google.android.fhir.datacapture.views.factories.LocationWidgetViewHolderFactory
import com.google.android.fhir.datacapture.views.factories.QuantityViewHolderFactory
import com.google.android.fhir.datacapture.views.factories.QuestionnaireItemDialogSelectViewHolderFactory
import com.google.android.fhir.datacapture.views.factories.QuestionnaireItemViewHolder
Expand Down Expand Up @@ -95,6 +96,7 @@ internal class QuestionnaireEditAdapter(
QuestionnaireViewHolderType.SLIDER -> SliderViewHolderFactory
QuestionnaireViewHolderType.PHONE_NUMBER -> PhoneNumberViewHolderFactory
QuestionnaireViewHolderType.ATTACHMENT -> AttachmentViewHolderFactory
QuestionnaireViewHolderType.LOCATION_WIDGET -> LocationWidgetViewHolderFactory
}
return viewHolderFactory.create(parent)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ enum class QuestionnaireViewHolderType(val value: Int) {
SLIDER(15),
PHONE_NUMBER(16),
ATTACHMENT(17),
LOCATION_WIDGET(18),
;

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ enum class ItemControlTypes(
RADIO_BUTTON("radio-button", QuestionnaireViewHolderType.RADIO_GROUP),
SLIDER("slider", QuestionnaireViewHolderType.SLIDER),
PHONE_NUMBER("phone-number", QuestionnaireViewHolderType.PHONE_NUMBER),
LOCATION_WIDGET("location-widget", QuestionnaireViewHolderType.LOCATION_WIDGET),
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.android.fhir.datacapture.views.factories

import android.view.View
import com.google.android.fhir.datacapture.R
import com.google.android.fhir.datacapture.views.HeaderView
import com.google.android.fhir.datacapture.views.QuestionnaireViewItem
import com.google.android.material.textfield.MaterialAutoCompleteTextView

internal object LocationWidgetViewHolderFactory :
QuestionnaireItemViewHolderFactory(R.layout.location_widget_view) {
override fun getQuestionnaireItemViewHolderDelegate(): QuestionnaireItemViewHolderDelegate =
object : QuestionnaireItemViewHolderDelegate {
private lateinit var header: HeaderView
private lateinit var autoCompleteTextView: MaterialAutoCompleteTextView

override lateinit var questionnaireViewItem: QuestionnaireViewItem

override fun init(itemView: View) {
header = itemView.findViewById(R.id.header)
autoCompleteTextView = itemView.findViewById(R.id.autoCompleteTextView)
}

override fun bind(questionnaireViewItem: QuestionnaireViewItem) {
header.bind(questionnaireViewItem)
autoCompleteTextView.setText("-83.694710, 42.256500, 0") // todo:
autoCompleteTextView.setAdapter(null)
}

override fun setReadOnly(isReadOnly: Boolean) {
// TODO("Not yet implemented")
}
}
}
13 changes: 13 additions & 0 deletions datacapture/src/main/res/drawable/gm_location_on_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal"
>
<path
android:fillColor="@android:color/white"
android:pathData="M480,480q33,0 56.5,-23.5T560,400q0,-33 -23.5,-56.5T480,320q-33,0 -56.5,23.5T400,400q0,33 23.5,56.5T480,480ZM480,774q122,-112 181,-203.5T720,408q0,-109 -69.5,-178.5T480,160q-101,0 -170.5,69.5T240,408q0,71 59,162.5T480,774ZM480,880Q319,743 239.5,625.5T160,408q0,-150 96.5,-239T480,80q127,0 223.5,89T800,408q0,100 -79.5,217.5T480,880ZM480,400Z"
/>
</vector>
7 changes: 2 additions & 5 deletions datacapture/src/main/res/layout/display_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@
android:layout_height="wrap_content"
/>

<com.google.android.fhir.datacapture.views.MediaView
android:id="@+id/item_media"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>



</LinearLayout>
48 changes: 48 additions & 0 deletions datacapture/src/main/res/layout/location_widget_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_marginHorizontal="@dimen/item_margin_horizontal"
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"
/>

<com.google.android.fhir.datacapture.views.MediaView
android:id="@+id/item_media"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text_input_layout"
style="?attr/questionnaireTextInputLayoutStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:endIconDrawable="@drawable/gm_location_on_24"
app:endIconMode="custom"
app:errorIconDrawable="@null"
app:hintEnabled="true"
>

<com.google.android.material.textfield.MaterialAutoCompleteTextView
android:id="@+id/autoCompleteTextView"
style="@style/Questionnaire.AutoCompleteTextViewOutlinedBoxStyle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
android:imeOptions="flagNoExtractUi"
android:inputType="none"
android:singleLine="true"
/>

</com.google.android.material.textfield.TextInputLayout>

</LinearLayout>
53 changes: 53 additions & 0 deletions demo/src/main/assets/test-location-widget.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"resourceType": "Questionnaire",
"language": "en",
"status": "active",
"date": "2020-11-18T07:24:47.111Z",
"extension": [
{
"url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-launchContext",
"extension": [
{
"url": "name",
"valueCoding": {
"system": "http://hl7.org/fhir/uv/sdc/CodeSystem/launchContext",
"code": "client",
"display": "Client as a Patient"
}
},
{
"url": "type",
"valueCode": "Patient"
}
]
}
],
"item": [
{
"linkId": "PR",
"type": "group",
"text": "Test Group",
"item": [
{
"linkId": "Location widget",
"type": "string",
"text": "Record GPS Location",
"required": true,
"extension": [
{
"url": "https://github.com/google/android-fhir/StructureDefinition/questionnaire-itemControl",
"valueCodeableConcept": {
"coding": [
{
"system": "https://github.com/google/android-fhir/questionnaire-item-control",
"code": "location-widget"
}
]
}
}
]
}
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ class AddPatientFragment : Fragment(R.layout.add_patient_fragment) {

private fun updateArguments() {
requireArguments()
.putString(QUESTIONNAIRE_FILE_PATH_KEY, "new-patient-registration-paginated.json")
// .putString(QUESTIONNAIRE_FILE_PATH_KEY, "new-patient-registration-paginated.json")
.putString(QUESTIONNAIRE_FILE_PATH_KEY, "test-location-widget.json")
}

private fun addQuestionnaireFragment() {
Expand Down

0 comments on commit 47d3126

Please sign in to comment.