|
| 1 | +package com.bin.david.smarttable; |
| 2 | + |
| 3 | +import android.graphics.Paint; |
| 4 | +import android.os.Bundle; |
| 5 | +import android.support.annotation.Nullable; |
| 6 | +import android.support.v7.app.AppCompatActivity; |
| 7 | +import android.view.View; |
| 8 | +import android.view.WindowManager; |
| 9 | +import android.widget.Button; |
| 10 | +import android.widget.EditText; |
| 11 | + |
| 12 | +import com.bin.david.form.core.SmartTable; |
| 13 | +import com.bin.david.form.data.CellInfo; |
| 14 | +import com.bin.david.form.data.column.Column; |
| 15 | +import com.bin.david.form.data.format.IFormat; |
| 16 | +import com.bin.david.form.data.format.grid.BaseGridFormat; |
| 17 | +import com.bin.david.form.data.format.selected.BaseSelectFormat; |
| 18 | +import com.bin.david.form.data.table.FormTableData; |
| 19 | +import com.bin.david.form.data.table.TableData; |
| 20 | +import com.bin.david.form.utils.DensityUtils; |
| 21 | +import com.bin.david.smarttable.bean.Form; |
| 22 | + |
| 23 | +/** |
| 24 | + * Created by huang on 2018/4/10. |
| 25 | + */ |
| 26 | + |
| 27 | +public class FormModeActivity extends AppCompatActivity { |
| 28 | + |
| 29 | + private SmartTable<Form> table; |
| 30 | + private View llBottom; |
| 31 | + private Button searchBtn; |
| 32 | + private EditText editText; |
| 33 | + private Form selectForm; |
| 34 | + |
| 35 | + @Override |
| 36 | + protected void onCreate(@Nullable Bundle savedInstanceState) { |
| 37 | + super.onCreate(savedInstanceState); |
| 38 | + setContentView(R.layout.activity_edit_table); |
| 39 | + table = (SmartTable<Form>) findViewById(R.id.table); |
| 40 | + int dp5 = DensityUtils.dp2px(this,10); |
| 41 | + table.getConfig().setVerticalPadding(dp5) |
| 42 | + .setTextLeftOffset(dp5); |
| 43 | + llBottom = findViewById(R.id.ll_bottom); |
| 44 | + searchBtn = (Button) findViewById(R.id.tv_query); |
| 45 | + searchBtn.setOnClickListener(new View.OnClickListener() { |
| 46 | + @Override |
| 47 | + public void onClick(View v) { |
| 48 | + if(selectForm !=null){ |
| 49 | + selectForm.setName(editText.getText().toString()); |
| 50 | + table.invalidate(); |
| 51 | + editText.setText(""); |
| 52 | + } |
| 53 | + } |
| 54 | + }); |
| 55 | + editText = (EditText)findViewById(R.id.edit_query) ; |
| 56 | + Form[][] forms = { |
| 57 | + { |
| 58 | + new Form("姓名", Paint.Align.LEFT), Form.Empty, |
| 59 | + new Form("性别", Paint.Align.LEFT), Form.Empty, |
| 60 | + new Form("出生日期", Paint.Align.LEFT),Form.Empty, |
| 61 | + new Form("民族", Paint.Align.LEFT), Form.Empty, |
| 62 | + new Form("婚否", Paint.Align.LEFT), Form.Empty, |
| 63 | + new Form(1, 4, "照片") |
| 64 | + }, |
| 65 | + { |
| 66 | + new Form("学历", Paint.Align.LEFT), Form.Empty, |
| 67 | + new Form("专业", Paint.Align.LEFT), new Form(3, 1, ""), |
| 68 | + new Form("何种语言", Paint.Align.LEFT), new Form(3, 1, "") |
| 69 | + }, |
| 70 | + { |
| 71 | + new Form("籍贯", Paint.Align.LEFT), Form.Empty, |
| 72 | + new Form(2, 1, "户口所在地", Paint.Align.LEFT), new Form(3, 1, ""), |
| 73 | + Form.Empty, new Form(2, 1, "") |
| 74 | + }, |
| 75 | + { |
| 76 | + new Form(2, 1, "现住址电话", Paint.Align.LEFT), new Form(8, 1, "") |
| 77 | + |
| 78 | + }, |
| 79 | + { |
| 80 | + new Form(2, 1, "身份证号码", Paint.Align.LEFT), new Form(4, 1, "") |
| 81 | + , new Form(2, 1, "暂住证号码", Paint.Align.LEFT), new Form(3, 1, "") |
| 82 | + }, |
| 83 | + { |
| 84 | + new Form(2, 1, "应急联系人及电话", Paint.Align.LEFT), new Form(4, 1, "") |
| 85 | + , new Form(2, 1, "联系人电话号码", Paint.Align.LEFT), new Form(3, 1, "") |
| 86 | + }, |
| 87 | + { |
| 88 | + new Form(2, 1, "申请职位", Paint.Align.LEFT), new Form(4, 1, "") |
| 89 | + , new Form(2, 1, "本人要求待遇", Paint.Align.LEFT), new Form(3, 1, "") |
| 90 | + }, |
| 91 | + { |
| 92 | + new Form(11, 1, "家庭成员及主要社会关系") |
| 93 | + }, |
| 94 | + |
| 95 | + { |
| 96 | + new Form(2, 1, "姓名"), |
| 97 | + new Form(2, 1, "与本人关系"), |
| 98 | + new Form(7, 1, "单位及职务"), |
| 99 | + }, |
| 100 | + { |
| 101 | + new Form(2, 1, ""), |
| 102 | + new Form(2, 1, ""), |
| 103 | + new Form(7, 1, ""), |
| 104 | + }, |
| 105 | + { |
| 106 | + new Form(2, 1, ""), |
| 107 | + new Form(2, 1, ""), |
| 108 | + new Form(7, 1, ""), |
| 109 | + }, |
| 110 | + { |
| 111 | + new Form(2, 1, ""), |
| 112 | + new Form(2, 1, ""), |
| 113 | + new Form(7, 1, ""), |
| 114 | + }, |
| 115 | + { |
| 116 | + new Form(2, 1, ""), |
| 117 | + new Form(2, 1, ""), |
| 118 | + new Form(7, 1, ""), |
| 119 | + }, |
| 120 | + { |
| 121 | + new Form(2, 1, ""), |
| 122 | + new Form(2, 1, ""), |
| 123 | + new Form(7, 1, ""), |
| 124 | + }, |
| 125 | + { |
| 126 | + new Form(2, 1, ""), |
| 127 | + new Form(2, 1, ""), |
| 128 | + new Form(7, 1, ""), |
| 129 | + }, |
| 130 | + { |
| 131 | + new Form(11, 1, "工作经历") |
| 132 | + }, |
| 133 | + { |
| 134 | + new Form(4, 1, "起止时间"), |
| 135 | + new Form(6, 1, "单位"), |
| 136 | + new Form(1, 1, ""), |
| 137 | + }, |
| 138 | + { |
| 139 | + new Form(4, 1, ""), |
| 140 | + new Form(6, 1, ""), |
| 141 | + new Form(1, 1, ""), |
| 142 | + }, |
| 143 | + { |
| 144 | + new Form(4, 1, ""), |
| 145 | + new Form(6, 1, ""), |
| 146 | + new Form(1, 1, ""), |
| 147 | + }, |
| 148 | + { |
| 149 | + new Form(4, 1, ""), |
| 150 | + new Form(6, 1, ""), |
| 151 | + new Form(1, 1, ""), |
| 152 | + }, |
| 153 | + { |
| 154 | + new Form(11, 1, "本人保证以下资料全部属实,否则本人愿意承担由此造成的一切后果") |
| 155 | + }, |
| 156 | + { |
| 157 | + new Form(2, 1, "申请人签名"), new Form(4, 1, "") |
| 158 | + , new Form(2, 1, "日期"), new Form(3, 1, "") |
| 159 | + } |
| 160 | + |
| 161 | + }; |
| 162 | + final FormTableData<Form> tableData = FormTableData.create(table, "登记表", 11, forms); |
| 163 | + tableData.setFormat(new IFormat<Form>() { |
| 164 | + @Override |
| 165 | + public String format(Form form) { |
| 166 | + if (form != null) { |
| 167 | + return form.getName(); |
| 168 | + } else { |
| 169 | + return ""; |
| 170 | + } |
| 171 | + } |
| 172 | + }); |
| 173 | + table.setSelectFormat(new BaseSelectFormat()); |
| 174 | + tableData.setOnItemClickListener(new TableData.OnItemClickListener<Form>() { |
| 175 | + @Override |
| 176 | + public void onClick(Column column, String value, Form form, int col, int row) { |
| 177 | + if(form !=null){ |
| 178 | + selectForm = form; |
| 179 | + editText.setFocusable(true); |
| 180 | + editText.setFocusableInTouchMode(true); |
| 181 | + editText.requestFocus(); |
| 182 | + getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); |
| 183 | + } |
| 184 | + |
| 185 | + } |
| 186 | + |
| 187 | + }); |
| 188 | + table.getConfig().setTableGridFormat(new BaseGridFormat(){ |
| 189 | + @Override |
| 190 | + protected boolean isShowHorizontalLine(int col, int row, CellInfo cellInfo) { |
| 191 | + if(row == tableData.getLineSize() -1){ |
| 192 | + return false; |
| 193 | + } |
| 194 | + return true; |
| 195 | + } |
| 196 | + |
| 197 | + @Override |
| 198 | + protected boolean isShowVerticalLine(int col, int row, CellInfo cellInfo) { |
| 199 | + if(row == tableData.getLineSize() -1){ |
| 200 | + return false; |
| 201 | + } |
| 202 | + return true; |
| 203 | + } |
| 204 | + }); |
| 205 | + table.setTableData(tableData); |
| 206 | + |
| 207 | + |
| 208 | + } |
| 209 | +} |
0 commit comments