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

Add extensibility edittext #553

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ public class JsonFormConstants {
public static final String TOP_MARGIN = "top_margin";
public static final String BOTTOM_MARGIN = "bottom_margin";
public static final String LEFT_MARGIN = "left_margin";
public static final String RIGHT_MARGIN = "right_margin";
public static final String UPLOAD_BUTTON_TEXT = "uploadButtonText";
public static final String EXPANSION_PANEL = "expansion_panel";
public static final String JSON_OBJECT_KEY = "json_object_key";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ protected List<View> attachJson(String stepName, Context context, JsonFormFragme
attachInfoIcon(stepName, jsonObject, rootLayout, canvasIds, listener);

((JsonApi) context).addFormDataView(editText);
updateMargin(editText, jsonObject, context);
updateTopPadding(editText, jsonObject, context);
views.add(rootLayout);
return views;
}
Expand Down Expand Up @@ -153,6 +155,9 @@ public void run() {
editText.setHint(jsonObject.getString(JsonFormConstants.HINT));
editText.setFloatingLabelText(jsonObject.getString(JsonFormConstants.HINT));
}
else {
editText.setFloatingLabel(MaterialEditText.FLOATING_LABEL_NONE);
}
FormUtils.setEditMode(jsonObject, editText, editButton);
FormUtils.toggleEditTextVisibility(jsonObject, editText);

Expand Down Expand Up @@ -443,4 +448,29 @@ private MaterialEditText getViewUsingAddress(String stepName, String fieldKey, J
public Set<String> getCustomTranslatableWidgetFields() {
return new HashSet<>();
}

protected void updateTopPadding(MaterialEditText editText, JSONObject jsonObject, Context context) {
final int topPadding = jsonObject.has(JsonFormConstants.TOP_PADDING) ? getValueFromSpOrDpOrPx(context, jsonObject.optString(JsonFormConstants.TOP_PADDING, "0dp")) : editText.getFloatingLabelPadding();
editText.setFloatingLabelPadding(topPadding);
}

protected void updateMargin(MaterialEditText editText, JSONObject jsonObject, Context context) {
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) editText.getLayoutParams();

int leftMargin = normalizeValue(context, jsonObject, JsonFormConstants.LEFT_MARGIN, layoutParams.leftMargin);
int topMargin = normalizeValue(context, jsonObject, JsonFormConstants.TOP_MARGIN, layoutParams.topMargin);
int rightMargin = normalizeValue(context, jsonObject, JsonFormConstants.RIGHT_MARGIN, layoutParams.rightMargin);
int bottomMargin = normalizeValue(context, jsonObject, JsonFormConstants.BOTTOM_MARGIN, layoutParams.bottomMargin);

layoutParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin);
editText.setLayoutParams(layoutParams);
}

protected int getValueFromSpOrDpOrPx(Context context, String value) {
return FormUtils.getValueFromSpOrDpOrPx(value, context);
}

private int normalizeValue(Context context, JSONObject jsonObject, String key, int defaultValue) {
return jsonObject.has(key) ? getValueFromSpOrDpOrPx(context, jsonObject.optString(key, "0dp")) : defaultValue;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="60dp">
android:layout_height="wrap_content">

<RelativeLayout
android:id="@+id/edit_text_layout"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public class EditTextFactoryTest extends BaseTest {
public void setUp() {
MockitoAnnotations.initMocks(this);
factory = new EditTextFactory();

RelativeLayout.LayoutParams layoutParams = Mockito.mock(RelativeLayout.LayoutParams.class);
Mockito.when(editText.getLayoutParams()).thenReturn(layoutParams);
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_NAME=2.0.4-SNAPSHOT
VERSION_NAME=2.0.5-SNAPSHOT
VERSION_CODE=1
GROUP=org.smartregister
POM_SETTING_DESCRIPTION=OpenSRP Client Native Form Json Wizard
Expand Down