-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #210 from OpenSRP/209-text-with-image-widget
209 text with image widget
- Loading branch information
Showing
8 changed files
with
1,114 additions
and
925 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1,878 changes: 955 additions & 923 deletions
1,878
android-json-form-wizard/src/main/java/com/vijay/jsonwizard/utils/FormUtils.java
Large diffs are not rendered by default.
Oops, something went wrong.
98 changes: 98 additions & 0 deletions
98
android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/ImageViewFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package com.vijay.jsonwizard.widgets; | ||
|
||
import android.content.Context; | ||
import android.graphics.Bitmap; | ||
import android.graphics.Color; | ||
import android.text.TextUtils; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.widget.ImageView; | ||
import android.widget.TextView; | ||
|
||
import com.rey.material.util.ViewUtil; | ||
import com.vijay.jsonwizard.R; | ||
import com.vijay.jsonwizard.constants.JsonFormConstants; | ||
import com.vijay.jsonwizard.fragments.JsonFormFragment; | ||
import com.vijay.jsonwizard.interfaces.CommonListener; | ||
import com.vijay.jsonwizard.interfaces.FormWidgetFactory; | ||
import com.vijay.jsonwizard.utils.FormUtils; | ||
|
||
import org.json.JSONArray; | ||
import org.json.JSONObject; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ImageViewFactory implements FormWidgetFactory { | ||
|
||
private View rootLayout; | ||
private TextView descriptionTextView; | ||
|
||
@Override | ||
public List<View> getViewsFromJson(String stepName, Context context, JsonFormFragment formFragment, JSONObject jsonObject, CommonListener listener, boolean popup) throws Exception { | ||
List<View> views = new ArrayList<>(1); | ||
rootLayout = LayoutInflater.from(context).inflate(getLayout(), null); | ||
descriptionTextView = rootLayout.findViewById(R.id.imageViewLabel); | ||
setWidgetTags(jsonObject, stepName); | ||
setViewConfigs(jsonObject, context); | ||
views.add(rootLayout); | ||
return views; | ||
} | ||
|
||
@Override | ||
public List<View> getViewsFromJson(String stepName, Context context, JsonFormFragment formFragment, JSONObject jsonObject, CommonListener listener) throws Exception { | ||
return getViewsFromJson(stepName, context, formFragment, jsonObject, listener, false); | ||
} | ||
|
||
private int getLayout() { | ||
return R.layout.native_form_image_view; | ||
} | ||
|
||
private void setWidgetTags(JSONObject jsonObject, String stepName) { | ||
setBasicTags(jsonObject, rootLayout); | ||
setBasicTags(jsonObject, descriptionTextView); | ||
|
||
JSONArray canvasIds = new JSONArray(); | ||
rootLayout.setId(ViewUtil.generateViewId()); | ||
canvasIds.put(rootLayout.getId()); | ||
rootLayout.setTag(R.id.canvas_ids, canvasIds); | ||
rootLayout.setTag(R.id.type, jsonObject.optString(JsonFormConstants.TYPE)); | ||
rootLayout.setTag(R.id.address, stepName + ":" + jsonObject.optString(JsonFormConstants.KEY)); | ||
rootLayout.setTag(R.id.extraPopup, false); | ||
} | ||
|
||
private void setBasicTags(JSONObject jsonObject, View view) { | ||
String key = jsonObject.optString(JsonFormConstants.KEY, ""); | ||
String openMrsEntityParent = jsonObject.optString(JsonFormConstants.OPENMRS_ENTITY_PARENT, ""); | ||
String openMrsEntity = jsonObject.optString(JsonFormConstants.OPENMRS_ENTITY, ""); | ||
String openMrsEntityId = jsonObject.optString(JsonFormConstants.OPENMRS_ENTITY_ID, ""); | ||
|
||
view.setTag(R.id.key, key); | ||
view.setTag(R.id.openmrs_entity_parent, openMrsEntityParent); | ||
view.setTag(R.id.openmrs_entity, openMrsEntity); | ||
view.setTag(R.id.openmrs_entity_id, openMrsEntityId); | ||
} | ||
|
||
private void setViewConfigs(JSONObject jsonObject, Context context) { | ||
String descriptionText = jsonObject.optString(JsonFormConstants.TEXT, ""); | ||
String imageFile = jsonObject.optString(JsonFormConstants.IMAGE_FILE, ""); | ||
|
||
if (!TextUtils.isEmpty(descriptionText)) { | ||
descriptionTextView.setText(descriptionText); | ||
String textColor = jsonObject.optString(JsonFormConstants.TEXT_COLOR, "#000000"); | ||
descriptionTextView.setTextColor(Color.parseColor(textColor)); | ||
String textSize = jsonObject.optString(JsonFormConstants.TEXT_SIZE, String.valueOf(context.getResources().getDimension(R.dimen.label_text_size))); | ||
descriptionTextView.setTextSize(FormUtils.getValueFromSpOrDpOrPx(textSize, context)); | ||
} | ||
|
||
if (!TextUtils.isEmpty(imageFile)) { | ||
String folderName = jsonObject.optString(JsonFormConstants.IMAGE_FOLDER, ""); | ||
Bitmap bitmap = FormUtils.getBitmap(context, folderName, imageFile); | ||
if (bitmap != null) { | ||
ImageView imageView = rootLayout.findViewById(R.id.image); | ||
imageView.setImageBitmap(bitmap); | ||
} | ||
} | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
android-json-form-wizard/src/main/res/layout/native_form_image_view.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:id="@+id/native_form_text_and_image" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:baselineAligned="true" | ||
android:paddingBottom="@dimen/label_bottom_padding"> | ||
|
||
<TextView | ||
android:id="@+id/imageViewLabel" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginTop="8dp" | ||
android:paddingBottom="20dp" | ||
android:text="Sample text" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
<ImageView | ||
android:id="@+id/image" | ||
android:layout_width="match_parent" | ||
android:layout_height="300dp" | ||
android:layout_gravity="center_horizontal" | ||
android:layout_marginStart="8dp" | ||
android:layout_marginTop="8dp" | ||
android:layout_marginEnd="8dp" | ||
android:layout_marginBottom="8dp" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintHorizontal_bias="1.0" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@+id/imageViewLabel" | ||
app:layout_constraintVertical_bias="0.394" /> | ||
|
||
</android.support.constraint.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters