|
|
@@ -14,6 +14,7 @@ import android.text.InputFilter;
|
|
|
import android.text.InputType;
|
|
|
import android.text.TextWatcher;
|
|
|
import android.util.Log;
|
|
|
+import android.view.KeyEvent;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.Menu;
|
|
|
import android.view.MenuItem;
|
|
|
@@ -27,16 +28,19 @@ import android.widget.CompoundButton;
|
|
|
import android.widget.EditText;
|
|
|
import android.widget.ExpandableListView;
|
|
|
import android.widget.Switch;
|
|
|
+import android.widget.TextView;
|
|
|
|
|
|
|
|
|
import com.usai.redant.CommonEditor.CommonEditor.CommonEditorActionCellHolder;
|
|
|
import com.usai.redant.CommonEditor.CommonEditor.CommonEditorCellHolder;
|
|
|
+import com.usai.redant.CommonEditor.CommonEditor.CommonEditorDateRangeCellHolder;
|
|
|
import com.usai.redant.CommonEditor.CommonEditor.CommonEditorEditCellHolder;
|
|
|
import com.usai.redant.CommonEditor.CommonEditor.CommonEditorEnumCellHolder;
|
|
|
import com.usai.redant.CommonEditor.CommonEditor.CommonEditorImageCellHolder;
|
|
|
import com.usai.redant.CommonEditor.CommonEditor.CommonEditorLabelCellHolder;
|
|
|
import com.usai.redant.CommonEditor.CommonEditor.CommonEditorModelCellHolder;
|
|
|
import com.usai.redant.CommonEditor.CommonEditor.CommonEditorMultipleActionCellHolder;
|
|
|
+import com.usai.redant.CommonEditor.CommonEditor.CommonEditorRangeCellHolder;
|
|
|
import com.usai.redant.CommonEditor.CommonEditor.CommonEditorSectionHeaderHolder;
|
|
|
import com.usai.redant.CommonEditor.CommonEditor.CommonEditorSignatureCellHolder;
|
|
|
import com.usai.redant.CommonEditor.CommonEditor.CommonEditorSwitchCellHolder;
|
|
|
@@ -45,6 +49,7 @@ import com.usai.redant.redantmobile.R;
|
|
|
import com.usai.redant.util.Network;
|
|
|
|
|
|
import org.json.JSONArray;
|
|
|
+import org.json.JSONException;
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
@@ -68,10 +73,14 @@ import static android.view.Gravity.TOP;
|
|
|
|
|
|
public class CommonEditorActivity extends AppCompatActivity implements View.OnLayoutChangeListener{
|
|
|
|
|
|
- private ExpandableListView listView;
|
|
|
- private ExpandAdapter adapter;
|
|
|
+
|
|
|
+ public ExpandAdapter adapter;
|
|
|
public String service_url;
|
|
|
|
|
|
+ public boolean hasChildView;
|
|
|
+ public ExpandableListView listView;
|
|
|
+ public View rootView;
|
|
|
+
|
|
|
/**Child Activity Override*/
|
|
|
public void download_success() {
|
|
|
|
|
|
@@ -90,7 +99,7 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
|
|
|
public JSONArray missingfields;
|
|
|
}
|
|
|
|
|
|
- private ProgressDialog showProgressAlert(String title,String msg) {
|
|
|
+ public ProgressDialog showProgressAlert(String title,String msg) {
|
|
|
ProgressDialog pd = new ProgressDialog(this);
|
|
|
pd.setTitle(title);
|
|
|
pd.setMessage(msg);
|
|
|
@@ -144,11 +153,20 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
- setContentView(R.layout.activity_common_editor);
|
|
|
|
|
|
-// service_url = "http://192.168.0.133:8080/site/isales/getAddCustomer.htm";
|
|
|
|
|
|
- listView = (ExpandableListView)findViewById(R.id.list_view);
|
|
|
+ if (!hasChildView) {
|
|
|
+ setContentView(R.layout.activity_common_editor);
|
|
|
+
|
|
|
+// rootView = findViewById(R.id.root_layout);
|
|
|
+ listView = (ExpandableListView)findViewById(R.id.list_view);
|
|
|
+ }
|
|
|
+
|
|
|
+ rootView = getWindow().getDecorView().findViewById(android.R.id.content);
|
|
|
+
|
|
|
+ if (listView == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
adapter = new ExpandAdapter(this);
|
|
|
|
|
|
@@ -288,11 +306,13 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
protected void onResume() {
|
|
|
super.onResume();
|
|
|
- View rootView = findViewById(R.id.root_layout);
|
|
|
- rootView.addOnLayoutChangeListener(this);
|
|
|
+ if (rootView != null) {
|
|
|
+ rootView.addOnLayoutChangeListener(this);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -439,6 +459,60 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
|
|
|
signatureIsChanged(url_down,url_up,group,child);
|
|
|
}
|
|
|
|
|
|
+ // date range
|
|
|
+ if (requestCode == 14) {
|
|
|
+ int group = data.getIntExtra("group",0);
|
|
|
+ int child = data.getIntExtra("child",0);
|
|
|
+ String min = data.getStringExtra("min");
|
|
|
+ String max = data.getStringExtra("max");
|
|
|
+
|
|
|
+ String min_components[] = min.split("/");
|
|
|
+ String max_components[] = max.split("/");
|
|
|
+
|
|
|
+ if (min_components.length == max_components.length) {
|
|
|
+
|
|
|
+ int min_year = Integer.valueOf(min_components[2]);
|
|
|
+ int min_month = Integer.valueOf(min_components[0]);
|
|
|
+ int min_day = Integer.valueOf(min_components[1]);
|
|
|
+
|
|
|
+ int max_year = Integer.valueOf(max_components[2]);
|
|
|
+ int max_month = Integer.valueOf(max_components[0]);
|
|
|
+ int max_day = Integer.valueOf(max_components[1]);
|
|
|
+
|
|
|
+ if (min_year > max_year) {
|
|
|
+ showWarningAlert("minimum can't larger than maximum");
|
|
|
+ return;
|
|
|
+ } else if (min_year == max_year) {
|
|
|
+
|
|
|
+ if (min_month > max_month) {
|
|
|
+ showWarningAlert("minimum can't larger than maximum");
|
|
|
+ return;
|
|
|
+ } else if (min_month == max_month) {
|
|
|
+
|
|
|
+ if (min_day > max_day) {
|
|
|
+ showWarningAlert("minimum can't larger than maximum");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ commonEditorRangeDidChange(min,max,group,child);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void showWarningAlert(String msg) {
|
|
|
+
|
|
|
+ new AlertDialog.Builder(mCtx)
|
|
|
+ .setTitle("Warning")
|
|
|
+ .setMessage(msg)
|
|
|
+ .show();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
public void signatureIsChanged(String url_down,String url_up,int group,int child) {
|
|
|
@@ -1582,6 +1656,24 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
|
|
|
}
|
|
|
|
|
|
} // edit
|
|
|
+ else if (itemjson.optString("control").equals("range")) {
|
|
|
+
|
|
|
+ String min_str = itemjson.optString("min_value","");
|
|
|
+ String max_str = itemjson.optString("max_value","");
|
|
|
+
|
|
|
+ String required = itemjson.optString("required");
|
|
|
+ if (required != null && required.equals("true") && (min_str.length() < 1 && max_str.length() < 1)) {
|
|
|
+ cancommit = false;
|
|
|
+ String mfield = itemjson.optString("aname") + " is missing";
|
|
|
+ fields.put(mfield);
|
|
|
+ } else {
|
|
|
+ JSONObject range_obj = new JSONObject();
|
|
|
+ range_obj.put("min",min_str);
|
|
|
+ range_obj.put("max",max_str);
|
|
|
+ upparams.put(itemjson.optString("name"),range_obj.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ } // range
|
|
|
else {
|
|
|
|
|
|
if (itemjson.optString("value") != null && !itemjson.optString("value").isEmpty()) {
|
|
|
@@ -1650,11 +1742,14 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
|
|
|
public static int COMMON_EDITOR_CELL_TYPE_SWITCH = 8;
|
|
|
public static int COMMON_EDITOR_CELL_TYPE_TEXT_VIEW = 9;
|
|
|
public static int COMMON_EDITOR_CELL_TYPE_SECTION_HEADER = 10;
|
|
|
+ public static int COMMON_EDITOR_CELL_TYPE_RANGE = 11;
|
|
|
+ public static int COMMON_EDITOR_CELL_TYPE_DATE_RANGE = 12;
|
|
|
+
|
|
|
/**
|
|
|
* ExpandListView Adapter
|
|
|
* */
|
|
|
- JSONArray content_data_control;
|
|
|
- JSONObject content_data_download;
|
|
|
+ public JSONArray content_data_control;
|
|
|
+ public JSONObject content_data_download;
|
|
|
|
|
|
public class ExpandAdapter extends BaseExpandableListAdapter {
|
|
|
|
|
|
@@ -1714,7 +1809,7 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
|
|
|
|
|
|
@Override
|
|
|
public long getChildId(int groupPosition, int childPosition) {
|
|
|
- return childPosition;
|
|
|
+ return groupPosition * 1000 + childPosition;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -1820,6 +1915,21 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
|
|
|
holder = new CommonEditorSignatureCellHolder(mCtx,convertView);
|
|
|
setUpSignatureCellHolder((CommonEditorSignatureCellHolder)holder,convertView,item_json,readonly,groupPosition,childPosition);
|
|
|
|
|
|
+ } else if (control.equals("range")) {
|
|
|
+
|
|
|
+ String type = item_json.optString("type");
|
|
|
+ if (type != null && type.equals("date")) {
|
|
|
+ convertView = LayoutInflater.from(mCtx).inflate(R.layout.common_editor_date_range_cell,null);
|
|
|
+ holder = new CommonEditorDateRangeCellHolder(mCtx,convertView);
|
|
|
+ setUpDateRangeCellHolder((CommonEditorDateRangeCellHolder)holder,convertView,item_json,readonly,groupPosition,childPosition);
|
|
|
+ } else {
|
|
|
+ convertView = LayoutInflater.from(mCtx).inflate(R.layout.common_editor_range_cell,null);
|
|
|
+ holder = new CommonEditorRangeCellHolder(mCtx,convertView);
|
|
|
+ setUpRangeCellHolder((CommonEditorRangeCellHolder)holder,convertView,item_json,readonly,groupPosition,childPosition);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
} else {
|
|
|
convertView = LayoutInflater.from(mCtx).inflate(R.layout.common_editor_edit_cell_small,null);
|
|
|
holder = new CommonEditorEditCellHolder(mCtx,convertView);
|
|
|
@@ -1883,7 +1993,19 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
|
|
|
holder = (CommonEditorSignatureCellHolder)convertView.getTag();
|
|
|
setUpSignatureCellHolder((CommonEditorSignatureCellHolder)holder,convertView,item_json,readonly,groupPosition,childPosition);
|
|
|
|
|
|
- } else {
|
|
|
+ } else if (control.equals("range")) {
|
|
|
+
|
|
|
+ String type = item_json.optString("type");
|
|
|
+ if (type != null && type.equals("date")) {
|
|
|
+ holder = (CommonEditorDateRangeCellHolder)convertView.getTag();
|
|
|
+ setUpDateRangeCellHolder((CommonEditorDateRangeCellHolder)holder,convertView,item_json,readonly,groupPosition,childPosition);
|
|
|
+ } else {
|
|
|
+ holder = (CommonEditorRangeCellHolder)convertView.getTag();
|
|
|
+ setUpRangeCellHolder((CommonEditorRangeCellHolder)holder,convertView,item_json,readonly,groupPosition,childPosition);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ } else {
|
|
|
holder = (CommonEditorEditCellHolder)convertView.getTag();
|
|
|
setUpEditCellHolder((CommonEditorEditCellHolder)holder,convertView,item_json,readonly,groupPosition,childPosition);
|
|
|
|
|
|
@@ -1907,7 +2029,7 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
|
|
|
@Override
|
|
|
public int getChildTypeCount() {
|
|
|
|
|
|
- return 11;
|
|
|
+ return 13;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -1949,6 +2071,14 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
|
|
|
return COMMON_EDITOR_CELL_TYPE_SIGNATURE;
|
|
|
} else if (control.equals("header")){
|
|
|
return COMMON_EDITOR_CELL_TYPE_SECTION_HEADER;
|
|
|
+ } else if (control.equals("range")){
|
|
|
+ String type = item_json.optString("type");
|
|
|
+ if (type != null && type.equals("date")) {
|
|
|
+ return COMMON_EDITOR_CELL_TYPE_DATE_RANGE;
|
|
|
+ } else {
|
|
|
+ return COMMON_EDITOR_CELL_TYPE_RANGE;
|
|
|
+ }
|
|
|
+
|
|
|
} else {
|
|
|
return COMMON_EDITOR_CELL_TYPE_EDIT;
|
|
|
}
|
|
|
@@ -2432,7 +2562,15 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
|
|
|
|
|
|
holder.text_field.setTag(group + "_" + child + "_" + "TextFiled");
|
|
|
holder.text_field.setText(value);
|
|
|
- holder.text_field.addTextChangedListener(new TextFieldTextWatcher(mCtx,holder.text_field,group,child));
|
|
|
+ if (holder.textWatcher == null) {
|
|
|
+ TextFieldTextWatcher textWatcher = new TextFieldTextWatcher(mCtx,holder.text_field,group,child);
|
|
|
+ holder.text_field.addTextChangedListener(textWatcher);
|
|
|
+ holder.textWatcher = textWatcher;
|
|
|
+ } else {
|
|
|
+ TextFieldTextWatcher textWatcher = (TextFieldTextWatcher)holder.textWatcher;
|
|
|
+ textWatcher.group = group;
|
|
|
+ textWatcher.child = child;
|
|
|
+ }
|
|
|
holder.text_field.setOnFocusChangeListener(new EditTextFocusListener(mCtx,holder.text_field,group,child));
|
|
|
|
|
|
|
|
|
@@ -2972,6 +3110,93 @@ public class CommonEditorActivity extends AppCompatActivity implements View.OnLa
|
|
|
holder.hideControlBtn(hideControlBtn);
|
|
|
}
|
|
|
|
|
|
+ public void setUpRangeCellHolder(CommonEditorRangeCellHolder holder, View cell, JSONObject item_json, boolean readonly, int group, int child) {
|
|
|
+
|
|
|
+ holder.clearTextWather();
|
|
|
+
|
|
|
+ String title = item_json.optString("aname");
|
|
|
+ holder.group = group;
|
|
|
+ holder.child = child;
|
|
|
+ holder.title_lb.setText(title);
|
|
|
+
|
|
|
+ String type = item_json.optString("type");
|
|
|
+ String keyboard = item_json.optString("keyboard");
|
|
|
+
|
|
|
+ int inputType = 0;
|
|
|
+ if (keyboard != null) {
|
|
|
+ if (keyboard.equals("number")) {
|
|
|
+ inputType = EditorInfo.TYPE_CLASS_NUMBER;
|
|
|
+ } else if (keyboard.equals("email")) {
|
|
|
+ inputType = EditorInfo.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
|
|
|
+ } else if (keyboard.equals("phone")) {
|
|
|
+ inputType = EditorInfo.TYPE_CLASS_PHONE;
|
|
|
+ } else {
|
|
|
+ inputType = EditorInfo.TYPE_CLASS_TEXT;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ holder.min_et.setInputType(inputType);
|
|
|
+ holder.max_et.setInputType(inputType);
|
|
|
+
|
|
|
+ String min_str = item_json.optString("min_value");
|
|
|
+ String max_str = item_json.optString("max_value");
|
|
|
+
|
|
|
+ holder.min_et.setText(min_str);
|
|
|
+ holder.max_et.setText(max_str);
|
|
|
+
|
|
|
+// if (disable == 1 || readonly) {
|
|
|
+// holder.text_field.setEnabled(false);
|
|
|
+// holder.text_field.setTextColor(Color.LTGRAY);
|
|
|
+// } else {
|
|
|
+// holder.text_field.setEnabled(true);
|
|
|
+// holder.text_field.setTextColor(Color.BLACK);
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+ holder.resetTextWather();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setUpDateRangeCellHolder(CommonEditorDateRangeCellHolder holder, View cell, JSONObject item_json, boolean readonly, int group, int child) {
|
|
|
+
|
|
|
+ String title = item_json.optString("aname");
|
|
|
+ holder.group = group;
|
|
|
+ holder.child = child;
|
|
|
+ holder.title_lb.setText(title);
|
|
|
+
|
|
|
+// String type = item_json.optString("type");
|
|
|
+
|
|
|
+ String min_str = item_json.optString("min_value");
|
|
|
+ String max_str = item_json.optString("max_value");
|
|
|
+
|
|
|
+ holder.min_btn.setText(min_str);
|
|
|
+ holder.max_btn.setText(max_str);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void commonEditorRangeDidChange(String min, String max, int group, int child) {
|
|
|
+ String section_key = "section_" + group;
|
|
|
+ String item_key = "item_" + child;
|
|
|
+
|
|
|
+ try {
|
|
|
+ JSONObject section_json = content_data_download.getJSONObject(section_key);
|
|
|
+ JSONObject item_json = ((JSONArray)content_data_control.getJSONArray(group)).getJSONObject(child);
|
|
|
+
|
|
|
+ item_json.put("max_value",max);
|
|
|
+ item_json.put("min_value",min);
|
|
|
+
|
|
|
+ section_json.put(item_key,item_json);
|
|
|
+ content_data_download.put(section_key,section_json);
|
|
|
+ content_data_control = translateChange(content_data_download,changed_data);
|
|
|
+
|
|
|
+ adapter.notifyDataSetChanged();
|
|
|
+
|
|
|
+ } catch (JSONException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
private Context mCtx = this;
|
|
|
|
|
|
/**Month Picker*/
|