Skip to content

Commit

Permalink
增加表格网格格式化
Browse files Browse the repository at this point in the history
  • Loading branch information
huangyanbin committed Mar 10, 2018
1 parent 2650063 commit cdcce5e
Show file tree
Hide file tree
Showing 24 changed files with 177 additions and 10 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<activity android:name=".MapModeActivity" />
<activity android:name=".WelcomeActivity" />
<activity android:name=".GridModeActivity"/>
<activity android:name=".AvatorModeActivity"/>
<activity
android:name=".ChoiceExcelActivity"
android:label="@string/title_activity_choice_excel"
Expand Down
175 changes: 175 additions & 0 deletions app/src/main/java/com/bin/david/smarttable/AvatorModeActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
package com.bin.david.smarttable;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.NinePatch;
import android.graphics.Paint;
import android.graphics.Rect;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;

import com.bin.david.form.core.SmartTable;
import com.bin.david.form.core.TableConfig;
import com.bin.david.form.data.CellInfo;
import com.bin.david.form.data.column.Column;
import com.bin.david.form.data.format.bg.IBackgroundFormat;
import com.bin.david.form.data.format.bg.ICellBackgroundFormat;
import com.bin.david.form.data.format.draw.ImageResDrawFormat;
import com.bin.david.form.data.format.grid.BaseGridFormat;
import com.bin.david.form.data.format.title.TitleDrawFormat;
import com.bin.david.form.data.style.FontStyle;
import com.bin.david.form.data.style.LineStyle;
import com.bin.david.form.data.table.ArrayTableData;
import com.bin.david.form.utils.DensityUtils;
import com.bin.david.form.utils.DrawUtils;


public class AvatorModeActivity extends AppCompatActivity {

private SmartTable<Integer> table;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_full_table);
FontStyle.setDefaultTextSize(DensityUtils.sp2px(this,15));
table = (SmartTable<Integer>) 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<Integer>() {
@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<Integer> tableData = ArrayTableData.create(table, "头像表", data,
new ImageResDrawFormat<Integer>(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<CellInfo>(){

@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<Integer>() {
@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){

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 0 additions & 10 deletions app/src/main/java/com/bin/david/smarttable/SeatModeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);


Expand Down
Binary file added app/src/main/res/mipmap-xhdpi/avator_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-xhdpi/avator_10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-xhdpi/avator_11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-xhdpi/avator_12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-xhdpi/avator_13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-xhdpi/avator_14.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-xhdpi/avator_15.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-xhdpi/avator_16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-xhdpi/avator_17.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-xhdpi/avator_18.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-xhdpi/avator_19.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-xhdpi/avator_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-xhdpi/avator_20.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-xhdpi/avator_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-xhdpi/avator_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-xhdpi/avator_5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-xhdpi/avator_6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-xhdpi/avator_7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-xhdpi/avator_8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-xhdpi/avator_9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit cdcce5e

Please sign in to comment.