Commit 255714c9 authored by rahadi's avatar rahadi

WIP: error method for each prompt hierarchy

parent 20553845
......@@ -67,7 +67,7 @@ public class CaptionHierarchy extends BaseHierarchy {
ta.recycle();
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, Collect.getQuestionFontsize() - 1);
textView.setPadding(0, 45, 0, 45);
textView.setPadding(25, 45, 25, 45);
textView.setTextColor(ContextCompat.getColor(context, R.color.white));
textView.setBackground(drawable);
......
......@@ -7,11 +7,11 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import org.javarosa.form.api.FormEntryPrompt;
import id.ac.stis.capi.R;
import id.ac.stis.capi.lessthink.views.HierarchyErrorView;
import id.ac.stis.capi.odk.widgets.QuestionWidget;
import id.ac.stis.capi.odk.widgets.WidgetFactory;
......@@ -26,9 +26,11 @@ public class PromptHierarchy extends BaseHierarchy {
private Context context;
private View widgetView;
private LinearLayout widgetContainer;
private int type, prevType;
private QuestionWidget widget;
private FormEntryPrompt prompt;
private HierarchyErrorView errorView;
public PromptHierarchy(Context context, FormEntryPrompt prompt, int type, int prevType, int level, int prevLevel) {
super(level, prevLevel);
......@@ -43,6 +45,8 @@ public class PromptHierarchy extends BaseHierarchy {
widgetParams.setMargins(12, 12, 12, 12);
widget.setLayoutParams(widgetParams);
this.errorView = new HierarchyErrorView(context);
createWidgetView();
}
......@@ -58,12 +62,22 @@ public class PromptHierarchy extends BaseHierarchy {
RelativeLayout container = new RelativeLayout(context);
container.setBackgroundColor(ContextCompat.getColor(context, R.color.primary));
LinearLayout widgetContainer = new LinearLayout(context);
this.widgetContainer = new LinearLayout(context);
widgetContainer.setOrientation(LinearLayout.VERTICAL);
widgetContainer.setBackgroundColor(ContextCompat.getColor(context, R.color.white));
widgetContainer.addView(widget);
LinearLayout.LayoutParams errorParams = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
errorParams.leftMargin = 15;
errorParams.bottomMargin = 15;
errorParams.rightMargin = 15;
errorParams.topMargin = 15;
errorView.setLayoutParams(errorParams);
widgetContainer.addView(errorView);
RelativeLayout.LayoutParams widgetContainerParams = new RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
widgetContainerParams.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
......@@ -123,6 +137,18 @@ public class PromptHierarchy extends BaseHierarchy {
this.widgetView = container;
}
public void setError(String message) {
if (message == null) {
widgetContainer.setBackgroundColor(ContextCompat.getColor(context, R.color.white));
errorView.setVisibility(View.GONE);
} else {
widgetContainer.setBackgroundColor(ContextCompat.getColor(context, R.color.smooth_red));
errorView.setVisibility(View.VISIBLE);
}
errorView.setError(message);
}
@Override
public View getView() {
return widgetView;
......
package id.ac.stis.capi.lessthink.views;
import android.content.Context;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.util.TypedValue;
import android.view.Gravity;
import android.widget.LinearLayout;
import android.widget.TextView;
import id.ac.stis.capi.R;
import id.ac.stis.capi.odk.application.Collect;
/**
* Author : Rahadi Jalu
* Email : 14.8325@stis.ac.id
* Company: Politeknik Statistika STIS
*/
public class HierarchyErrorView extends LinearLayout {
private TextView messageView;
public HierarchyErrorView(Context context) {
super(context);
setVisibility(GONE);
setOrientation(HORIZONTAL);
setGravity(Gravity.CENTER_VERTICAL);
setPadding(25, 25, 25, 25);
setBackground(ContextCompat.getDrawable(context, R.drawable.bg_border_tb));
this.messageView = new TextView(context);
messageView.setGravity(Gravity.CENTER_VERTICAL);
messageView.setTextColor(ContextCompat.getColor(context, R.color.md_red_A700));
messageView.setTypeface(messageView.getTypeface(), Typeface.BOLD);
// messageView.setPaintFlags(messageView.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
messageView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_error_fill, 0, 0, 0);
messageView.setCompoundDrawablePadding(25);
messageView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, Collect.getQuestionFontsize() - 5);
addView(messageView);
}
public void setError(String message) {
if (message == null) {
setVisibility(GONE);
} else {
messageView.setText(message);
setVisibility(VISIBLE);
}
}
}
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="18dp"
android:height="18dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="@color/md_red_A700"
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM13,17h-2v-2h2v2zM13,13h-2L11,7h2v6z"/>
</vector>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@color/smooth_red" />
</shape>
</item>
<item
android:left="-2dp"
android:right="-2dp">
<shape>
<solid android:color="@android:color/transparent" />
<stroke
android:width="1dp"
android:color="@color/red_latte" />
</shape>
</item>
</layer-list>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment