|
| 1 | +package com.bin.david.smarttable; |
| 2 | + |
| 3 | +import android.content.Context; |
| 4 | +import android.content.res.Resources; |
| 5 | +import android.graphics.Bitmap; |
| 6 | +import android.graphics.BitmapFactory; |
| 7 | +import android.graphics.Canvas; |
| 8 | +import android.graphics.NinePatch; |
| 9 | +import android.graphics.Paint; |
| 10 | +import android.graphics.Rect; |
| 11 | +import android.os.Bundle; |
| 12 | +import android.support.v4.content.ContextCompat; |
| 13 | +import android.support.v7.app.AppCompatActivity; |
| 14 | +import android.view.View; |
| 15 | +import android.widget.Toast; |
| 16 | + |
| 17 | +import com.bin.david.form.core.SmartTable; |
| 18 | +import com.bin.david.form.core.TableConfig; |
| 19 | +import com.bin.david.form.data.CellInfo; |
| 20 | +import com.bin.david.form.data.column.Column; |
| 21 | +import com.bin.david.form.data.format.bg.IBackgroundFormat; |
| 22 | +import com.bin.david.form.data.format.bg.ICellBackgroundFormat; |
| 23 | +import com.bin.david.form.data.format.draw.ImageResDrawFormat; |
| 24 | +import com.bin.david.form.data.format.grid.BaseGridFormat; |
| 25 | +import com.bin.david.form.data.format.title.TitleDrawFormat; |
| 26 | +import com.bin.david.form.data.style.FontStyle; |
| 27 | +import com.bin.david.form.data.style.LineStyle; |
| 28 | +import com.bin.david.form.data.table.ArrayTableData; |
| 29 | +import com.bin.david.form.utils.DensityUtils; |
| 30 | +import com.bin.david.form.utils.DrawUtils; |
| 31 | + |
| 32 | + |
| 33 | +public class AvatorModeActivity extends AppCompatActivity { |
| 34 | + |
| 35 | + private SmartTable<Integer> table; |
| 36 | + @Override |
| 37 | + protected void onCreate(Bundle savedInstanceState) { |
| 38 | + super.onCreate(savedInstanceState); |
| 39 | + setContentView(R.layout.activity_full_table); |
| 40 | + FontStyle.setDefaultTextSize(DensityUtils.sp2px(this,15)); |
| 41 | + table = (SmartTable<Integer>) findViewById(R.id.table); |
| 42 | + Integer[][] data = new Integer[20][]; |
| 43 | + //构造假数据 |
| 44 | + int avatorID = 0; |
| 45 | + int avatorID2 = 0; |
| 46 | + for(int i = 0;i <20; i++){ |
| 47 | + Integer[] column = new Integer[10]; |
| 48 | + for(int j= 0;j <10; j++){ |
| 49 | + if(i ==0 || i == 19){ |
| 50 | + if(j == 9){ |
| 51 | + column[j] = 0; |
| 52 | + } |
| 53 | + }else if(i ==1 || i == 18){ |
| 54 | + if(j == 9 || j ==8){ |
| 55 | + column[j] = 0; |
| 56 | + } |
| 57 | + }else if(i == 2 || i == 17){ |
| 58 | + if(j != 0){ |
| 59 | + column[j] =0; |
| 60 | + } |
| 61 | + }else{ |
| 62 | + if(i >4 && i <9 && j >2&& j <9) { |
| 63 | + avatorID++; |
| 64 | + column[j] = avatorID; |
| 65 | + } else if(i >0 && i <5 && j >0&& j <9) { |
| 66 | + avatorID2++; |
| 67 | + column[j] = avatorID2; |
| 68 | + }else { |
| 69 | + column[j] = 0; |
| 70 | + } |
| 71 | + } |
| 72 | + } |
| 73 | + data[i] = column; |
| 74 | + } |
| 75 | + |
| 76 | + FontStyle fontStyle = new FontStyle(this,10,ContextCompat.getColor(this,R.color.arc_text)); |
| 77 | + table.getConfig().setColumnTitleStyle(fontStyle); |
| 78 | + table.getConfig().setHorizontalPadding(10); |
| 79 | + table.getConfig().setVerticalPadding(10); |
| 80 | + LineStyle lineStyle = new LineStyle(); |
| 81 | + lineStyle.setColor(ContextCompat.getColor(this,android.R.color.transparent)); |
| 82 | + table.getConfig().setContentGridStyle(lineStyle); |
| 83 | + table.getConfig().setShowXSequence(false); |
| 84 | + table.getConfig().setFixedYSequence(true); |
| 85 | + table.setZoom(true,1,0.5f); |
| 86 | + table.getConfig().setTableGridFormat(new BaseGridFormat(){ |
| 87 | + @Override |
| 88 | + protected boolean isShowYSequenceHorizontalLine(int row) { |
| 89 | + return false; |
| 90 | + } |
| 91 | + |
| 92 | + @Override |
| 93 | + protected boolean isShowYSequenceVerticalLine(int row) { |
| 94 | + return false; |
| 95 | + } |
| 96 | + }); |
| 97 | + Bitmap bmp_9 = BitmapFactory.decodeResource(getResources(), R.mipmap.set_bg); |
| 98 | + final NinePatch ninePatch = new NinePatch(bmp_9, bmp_9.getNinePatchChunk(), null); |
| 99 | + |
| 100 | + table.getConfig().setYSequenceBackground(new IBackgroundFormat() { |
| 101 | + @Override |
| 102 | + public void drawBackground(Canvas canvas, Rect rect, Paint paint) { |
| 103 | + ninePatch.draw(canvas, rect); |
| 104 | + // DrawUtils.drawPatch(canvas,AvatorModeActivity.this,R.mipmap.set_bg,rect); |
| 105 | + } |
| 106 | + }); |
| 107 | + table.getConfig().setYSequenceCellBgFormat(new ICellBackgroundFormat<Integer>() { |
| 108 | + @Override |
| 109 | + public void drawBackground(Canvas canvas, Rect rect, Integer position, Paint paint) { |
| 110 | + |
| 111 | + } |
| 112 | + |
| 113 | + @Override |
| 114 | + public int getTextColor(Integer integer) { |
| 115 | + return ContextCompat.getColor(AvatorModeActivity.this,R.color.white); |
| 116 | + } |
| 117 | + }); |
| 118 | + int size = DensityUtils.dp2px(this,30); |
| 119 | + |
| 120 | + |
| 121 | + final ArrayTableData<Integer> tableData = ArrayTableData.create(table, "头像表", data, |
| 122 | + new ImageResDrawFormat<Integer>(size,size) { |
| 123 | + @Override |
| 124 | + protected Context getContext() { |
| 125 | + return AvatorModeActivity.this; |
| 126 | + } |
| 127 | + |
| 128 | + |
| 129 | + |
| 130 | + @Override |
| 131 | + protected int getResourceID(Integer status, String value, int position) { |
| 132 | + if(status == null){return 0;} |
| 133 | + if(status >0 && status <=20){ |
| 134 | + return getResources().getIdentifier("avator_"+status, "mipmap", getPackageName()); |
| 135 | + } |
| 136 | + return 0; |
| 137 | + } |
| 138 | + }); |
| 139 | + table.getConfig().setContentCellBackgroundFormat(new ICellBackgroundFormat<CellInfo>(){ |
| 140 | + |
| 141 | + @Override |
| 142 | + public void drawBackground(Canvas canvas, Rect rect, CellInfo cellInfo, Paint paint) { |
| 143 | + if(cellInfo.data != null && (Integer)cellInfo.data == 0){ |
| 144 | + paint.setStyle(Paint.Style.FILL); |
| 145 | + paint.setColor(ContextCompat.getColor(AvatorModeActivity.this,R.color.cal_buckle_color)); |
| 146 | + canvas.drawCircle(rect.centerX(),rect.centerY(),Math.min(rect.width(),rect.height())/2-15,paint); |
| 147 | + } |
| 148 | + } |
| 149 | + |
| 150 | + @Override |
| 151 | + public int getTextColor(CellInfo cellInfo) { |
| 152 | + return 0; |
| 153 | + } |
| 154 | + |
| 155 | + }); |
| 156 | + |
| 157 | + tableData.setOnItemClickListener(new ArrayTableData.OnItemClickListener<Integer>() { |
| 158 | + @Override |
| 159 | + public void onClick(Column column, String value, Integer checked, int col, int row) { |
| 160 | + if(checked != null) { |
| 161 | + Toast.makeText(AvatorModeActivity.this, "列:" + col + " 行:" + row + "数据:" + value, Toast.LENGTH_SHORT).show(); |
| 162 | + tableData.getData()[col][row] = checked == 1?0:1; |
| 163 | + } |
| 164 | + table.invalidate(); |
| 165 | + } |
| 166 | + }); |
| 167 | + table.setTableData(tableData); |
| 168 | + |
| 169 | + |
| 170 | + } |
| 171 | + |
| 172 | + public void onClick(View view){ |
| 173 | + |
| 174 | + } |
| 175 | +} |
0 commit comments