diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6ee63fd..739f26d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -42,6 +42,7 @@ + table; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_full_table); + FontStyle.setDefaultTextSize(DensityUtils.sp2px(this,15)); + table = (SmartTable) findViewById(R.id.table); + Integer[][] data = new Integer[20][]; + //构造假数据 + int avatorID = 0; + int avatorID2 = 0; + for(int i = 0;i <20; i++){ + Integer[] column = new Integer[10]; + for(int j= 0;j <10; j++){ + if(i ==0 || i == 19){ + if(j == 9){ + column[j] = 0; + } + }else if(i ==1 || i == 18){ + if(j == 9 || j ==8){ + column[j] = 0; + } + }else if(i == 2 || i == 17){ + if(j != 0){ + column[j] =0; + } + }else{ + if(i >4 && i <9 && j >2&& j <9) { + avatorID++; + column[j] = avatorID; + } else if(i >0 && i <5 && j >0&& j <9) { + avatorID2++; + column[j] = avatorID2; + }else { + column[j] = 0; + } + } + } + data[i] = column; + } + + FontStyle fontStyle = new FontStyle(this,10,ContextCompat.getColor(this,R.color.arc_text)); + table.getConfig().setColumnTitleStyle(fontStyle); + table.getConfig().setHorizontalPadding(10); + table.getConfig().setVerticalPadding(10); + LineStyle lineStyle = new LineStyle(); + lineStyle.setColor(ContextCompat.getColor(this,android.R.color.transparent)); + table.getConfig().setContentGridStyle(lineStyle); + table.getConfig().setShowXSequence(false); + table.getConfig().setFixedYSequence(true); + table.setZoom(true,1,0.5f); + table.getConfig().setTableGridFormat(new BaseGridFormat(){ + @Override + protected boolean isShowYSequenceHorizontalLine(int row) { + return false; + } + + @Override + protected boolean isShowYSequenceVerticalLine(int row) { + return false; + } + }); + Bitmap bmp_9 = BitmapFactory.decodeResource(getResources(), R.mipmap.set_bg); + final NinePatch ninePatch = new NinePatch(bmp_9, bmp_9.getNinePatchChunk(), null); + + table.getConfig().setYSequenceBackground(new IBackgroundFormat() { + @Override + public void drawBackground(Canvas canvas, Rect rect, Paint paint) { + ninePatch.draw(canvas, rect); + // DrawUtils.drawPatch(canvas,AvatorModeActivity.this,R.mipmap.set_bg,rect); + } + }); + table.getConfig().setYSequenceCellBgFormat(new ICellBackgroundFormat() { + @Override + public void drawBackground(Canvas canvas, Rect rect, Integer position, Paint paint) { + + } + + @Override + public int getTextColor(Integer integer) { + return ContextCompat.getColor(AvatorModeActivity.this,R.color.white); + } + }); + int size = DensityUtils.dp2px(this,30); + + + final ArrayTableData tableData = ArrayTableData.create(table, "头像表", data, + new ImageResDrawFormat(size,size) { + @Override + protected Context getContext() { + return AvatorModeActivity.this; + } + + + + @Override + protected int getResourceID(Integer status, String value, int position) { + if(status == null){return 0;} + if(status >0 && status <=20){ + return getResources().getIdentifier("avator_"+status, "mipmap", getPackageName()); + } + return 0; + } + }); + table.getConfig().setContentCellBackgroundFormat(new ICellBackgroundFormat(){ + + @Override + public void drawBackground(Canvas canvas, Rect rect, CellInfo cellInfo, Paint paint) { + if(cellInfo.data != null && (Integer)cellInfo.data == 0){ + paint.setStyle(Paint.Style.FILL); + paint.setColor(ContextCompat.getColor(AvatorModeActivity.this,R.color.cal_buckle_color)); + canvas.drawCircle(rect.centerX(),rect.centerY(),Math.min(rect.width(),rect.height())/2-15,paint); + } + } + + @Override + public int getTextColor(CellInfo cellInfo) { + return 0; + } + + }); + + tableData.setOnItemClickListener(new ArrayTableData.OnItemClickListener() { + @Override + public void onClick(Column column, String value, Integer checked, int col, int row) { + if(checked != null) { + Toast.makeText(AvatorModeActivity.this, "列:" + col + " 行:" + row + "数据:" + value, Toast.LENGTH_SHORT).show(); + tableData.getData()[col][row] = checked == 1?0:1; + } + table.invalidate(); + } + }); + table.setTableData(tableData); + + + } + + public void onClick(View view){ + + } +} diff --git a/app/src/main/java/com/bin/david/smarttable/MainActivity.java b/app/src/main/java/com/bin/david/smarttable/MainActivity.java index c679857..5442ac7 100644 --- a/app/src/main/java/com/bin/david/smarttable/MainActivity.java +++ b/app/src/main/java/com/bin/david/smarttable/MainActivity.java @@ -45,6 +45,7 @@ protected void onCreate(Bundle savedInstanceState) { items.add(new MainItem(TableListActivity.class,"测试手势冲突")); items.add(new MainItem(WelcomeActivity.class,"表格动画") ); items.add(new MainItem(GridModeActivity.class,"网格配置")); + items.add(new MainItem(AvatorModeActivity.class,"头像(高级)")); itemAdapter = new ItemAdapter(items); diff --git a/app/src/main/java/com/bin/david/smarttable/SeatModeActivity.java b/app/src/main/java/com/bin/david/smarttable/SeatModeActivity.java index a1619dc..3ea6426 100644 --- a/app/src/main/java/com/bin/david/smarttable/SeatModeActivity.java +++ b/app/src/main/java/com/bin/david/smarttable/SeatModeActivity.java @@ -136,16 +136,6 @@ public void onClick(Column column, String value, Integer checked, int col, int r table.invalidate(); } }); - tableData.setTitleDrawFormat(new TitleDrawFormat(){ - @Override - public void draw(Canvas c, Column column, Rect rect, TableConfig config) { - Paint paint = config.getPaint(); - paint.setTextSize(paint.getTextSize()*config.getZoom()); - //在这里设置对齐 - paint.setTextAlign(Paint.Align.CENTER); - DrawUtils.drawSingleText(c,paint,rect,column.getColumnName()); - } - }); table.setTableData(tableData); diff --git a/app/src/main/res/mipmap-xhdpi/avator_1.png b/app/src/main/res/mipmap-xhdpi/avator_1.png new file mode 100644 index 0000000..d7d9a56 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/avator_1.png differ diff --git a/app/src/main/res/mipmap-xhdpi/avator_10.png b/app/src/main/res/mipmap-xhdpi/avator_10.png new file mode 100644 index 0000000..69a8d61 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/avator_10.png differ diff --git a/app/src/main/res/mipmap-xhdpi/avator_11.png b/app/src/main/res/mipmap-xhdpi/avator_11.png new file mode 100644 index 0000000..dc0a169 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/avator_11.png differ diff --git a/app/src/main/res/mipmap-xhdpi/avator_12.png b/app/src/main/res/mipmap-xhdpi/avator_12.png new file mode 100644 index 0000000..ad2ca86 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/avator_12.png differ diff --git a/app/src/main/res/mipmap-xhdpi/avator_13.png b/app/src/main/res/mipmap-xhdpi/avator_13.png new file mode 100644 index 0000000..d556489 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/avator_13.png differ diff --git a/app/src/main/res/mipmap-xhdpi/avator_14.png b/app/src/main/res/mipmap-xhdpi/avator_14.png new file mode 100644 index 0000000..de43960 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/avator_14.png differ diff --git a/app/src/main/res/mipmap-xhdpi/avator_15.png b/app/src/main/res/mipmap-xhdpi/avator_15.png new file mode 100644 index 0000000..8566667 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/avator_15.png differ diff --git a/app/src/main/res/mipmap-xhdpi/avator_16.png b/app/src/main/res/mipmap-xhdpi/avator_16.png new file mode 100644 index 0000000..a6229d8 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/avator_16.png differ diff --git a/app/src/main/res/mipmap-xhdpi/avator_17.png b/app/src/main/res/mipmap-xhdpi/avator_17.png new file mode 100644 index 0000000..cb2d93c Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/avator_17.png differ diff --git a/app/src/main/res/mipmap-xhdpi/avator_18.png b/app/src/main/res/mipmap-xhdpi/avator_18.png new file mode 100644 index 0000000..074d57c Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/avator_18.png differ diff --git a/app/src/main/res/mipmap-xhdpi/avator_19.png b/app/src/main/res/mipmap-xhdpi/avator_19.png new file mode 100644 index 0000000..2b29c0f Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/avator_19.png differ diff --git a/app/src/main/res/mipmap-xhdpi/avator_2.png b/app/src/main/res/mipmap-xhdpi/avator_2.png new file mode 100644 index 0000000..efc0f46 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/avator_2.png differ diff --git a/app/src/main/res/mipmap-xhdpi/avator_20.png b/app/src/main/res/mipmap-xhdpi/avator_20.png new file mode 100644 index 0000000..c065583 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/avator_20.png differ diff --git a/app/src/main/res/mipmap-xhdpi/avator_3.png b/app/src/main/res/mipmap-xhdpi/avator_3.png new file mode 100644 index 0000000..004d35a Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/avator_3.png differ diff --git a/app/src/main/res/mipmap-xhdpi/avator_4.png b/app/src/main/res/mipmap-xhdpi/avator_4.png new file mode 100644 index 0000000..4494fff Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/avator_4.png differ diff --git a/app/src/main/res/mipmap-xhdpi/avator_5.png b/app/src/main/res/mipmap-xhdpi/avator_5.png new file mode 100644 index 0000000..26cfdf0 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/avator_5.png differ diff --git a/app/src/main/res/mipmap-xhdpi/avator_6.png b/app/src/main/res/mipmap-xhdpi/avator_6.png new file mode 100644 index 0000000..6880855 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/avator_6.png differ diff --git a/app/src/main/res/mipmap-xhdpi/avator_7.png b/app/src/main/res/mipmap-xhdpi/avator_7.png new file mode 100644 index 0000000..bf7e959 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/avator_7.png differ diff --git a/app/src/main/res/mipmap-xhdpi/avator_8.png b/app/src/main/res/mipmap-xhdpi/avator_8.png new file mode 100644 index 0000000..9f36f92 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/avator_8.png differ diff --git a/app/src/main/res/mipmap-xhdpi/avator_9.png b/app/src/main/res/mipmap-xhdpi/avator_9.png new file mode 100644 index 0000000..517b650 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/avator_9.png differ