Skip to content

Commit

Permalink
格式化序号
Browse files Browse the repository at this point in the history
  • Loading branch information
huangyanbin committed Mar 26, 2018
1 parent 953f317 commit 9468be5
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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.sequence.ISequenceFormat;
import com.bin.david.form.data.format.sequence.NumberSequenceFormat;
import com.bin.david.form.data.style.FontStyle;
import com.bin.david.form.data.style.LineStyle;
import com.bin.david.form.data.table.ArrayTableData;
Expand Down Expand Up @@ -113,7 +114,7 @@ public void onClick(Column column, String value, StudentInfo checked, int col, i
}
});

tableData.setYSequenceFormat(new ISequenceFormat() {
tableData.setYSequenceFormat(new NumberSequenceFormat() {
@Override
public String format(Integer integer) {
return (6-integer+1)+"";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ protected void onCreate(Bundle savedInstanceState) {
items.add(new MainItem(ArrayColumnModeActivity.class,"数组List转列"));
items.add(new MainItem(ArrayModeActivity.class,"数组模式1(日程表)"));
items.add(new MainItem(SeatModeActivity.class,"数组模式2(选座)"));
items.add(new MainItem(SeatModeActivity.class,"课程表"));
items.add(new MainItem(PagerModeActivity.class,"分页模式"));
items.add(new MainItem(MultParseModeActivity.class,"多行解析模式"));
items.add(new MainItem(JXLExcelModeActivity.class,"JXL Excel"));
Expand Down
32 changes: 32 additions & 0 deletions app/src/main/java/com/bin/david/smarttable/bean/Course.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.bin.david.smarttable.bean;

/**
* Created by huang on 2018/3/21.
*/

public class Course {

private String name;
private int period;

public Course(String name, int period) {
this.name = name;
this.period = period;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getPeriod() {
return period;
}

public void setPeriod(int period) {
this.period = period;
}
}
12 changes: 5 additions & 7 deletions form/src/main/java/com/bin/david/form/component/XSequence.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ protected void drawBackground(Canvas canvas, Rect showRect, TableConfig config,

private float showTextNum(Canvas canvas, Rect showRect, TableConfig config, float left, int i, float right) {
if(DrawUtils.isMixHorizontalRect(showRect,(int)left,(int)right)) {
String text = format.format(i+1);
draw(canvas, (int)left, rect.top,(int)right, rect.bottom,text,i, config);

draw(canvas, (int)left, rect.top,(int)right, rect.bottom,i, config);
}
left = right;
return left;
}

private void draw(Canvas canvas,int left,int top, int right,int bottom,String text,int position,TableConfig config){
private void draw(Canvas canvas,int left,int top, int right,int bottom,int position,TableConfig config){
Paint paint= config.getPaint();
tempRect.set(left,top,right,bottom);
//绘制背景
Expand All @@ -141,10 +141,8 @@ private void draw(Canvas canvas,int left,int top, int right,int bottom,String te
if(backgroundFormat != null&& backgroundFormat.getTextColor(position) != TableConfig.INVALID_COLOR){
paint.setColor(backgroundFormat.getTextColor(position));
}
//字体缩放
paint.setTextSize(paint.getTextSize()*(config.getZoom()>1?1:config.getZoom()));
paint.setTextAlign(Paint.Align.CENTER);
canvas.drawText(text,(right +left)/2, DrawUtils.getTextCenterY((bottom+top)/2,paint) ,paint);
format.draw(canvas,position,tempRect,config);


}

Expand Down
15 changes: 6 additions & 9 deletions form/src/main/java/com/bin/david/form/component/YSequence.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void onDraw(Canvas canvas, Rect showRect, TableData<T> tableData, TableCo
float bottom = tempTop + info.getTitleHeight();
if (DrawUtils.isVerticalMixRect(showRect, (int) top, (int) bottom)) {
tempRect.set(rect.left, (int) tempTop, rect.right, (int) bottom);
draw(canvas,tempRect, format.format(num), num, config);
draw(canvas,tempRect, num, config);
}
tempTop = bottom;
top += info.getTitleHeight();
Expand All @@ -103,7 +103,7 @@ public void onDraw(Canvas canvas, Rect showRect, TableData<T> tableData, TableCo
tempBottom = bottom-info.getCountHeight();
tempRect.set(rect.left, tempBottom,
rect.right, bottom);
draw(canvas,tempRect,format.format(num +totalSize+1),num +totalSize+1, config);
draw(canvas,tempRect,num +totalSize+1, config);
}
if(isFixedTitle || isFixedCount){
canvas.save();
Expand All @@ -115,7 +115,7 @@ public void onDraw(Canvas canvas, Rect showRect, TableData<T> tableData, TableCo
if(showRect.bottom >= rect.top) {
if (DrawUtils.isVerticalMixRect(showRect, (int)top, (int)bottom)) {
tempRect.set(rect.left, (int)top, rect.right, (int)bottom);
draw(canvas, tempRect,format.format(num),num, config);
draw(canvas, tempRect,num, config);
}
}else{
break;
Expand All @@ -127,7 +127,7 @@ public void onDraw(Canvas canvas, Rect showRect, TableData<T> tableData, TableCo
float bottom = top+info.getCountHeight();
if(DrawUtils.isVerticalMixRect(showRect,(int)top,(int)bottom)) {
tempRect.set(rect.left, (int)top, rect.right, (int)bottom);
draw(canvas,rect, format.format(num),num, config);
draw(canvas,rect,num, config);
}
}
if(isFixedTitle || isFixedCount){
Expand Down Expand Up @@ -182,7 +182,7 @@ private void drawLeftAndTop(Canvas canvas,Rect showRect,Rect rect,TableConfig co
canvas.restore();
}

private void draw(Canvas canvas,Rect rect,String text,int position,TableConfig config){
private void draw(Canvas canvas,Rect rect,int position,TableConfig config){
Paint paint= config.getPaint();
ICellBackgroundFormat<Integer> backgroundFormat = config.getYSequenceCellBgFormat();
int textColor =TableConfig.INVALID_COLOR;
Expand All @@ -199,10 +199,7 @@ private void draw(Canvas canvas,Rect rect,String text,int position,TableConfig c
if(textColor != TableConfig.INVALID_COLOR){
paint.setColor(textColor);
}
float hZoom = (config.getZoom()>1?1:config.getZoom());
paint.setTextSize(paint.getTextSize()*hZoom);
paint.setTextAlign(Paint.Align.CENTER);
canvas.drawText(text,rect.centerX(), DrawUtils.getTextCenterY(rect.centerY(),paint) ,paint);
format.draw(canvas,position-1,rect,config);
}

public int getWidth() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.bin.david.form.data.format.sequence;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;

import com.bin.david.form.core.TableConfig;
import com.bin.david.form.utils.DrawUtils;

/**
* Created by huang on 2018/3/21.
*/

public abstract class BaseSequenceFormat implements ISequenceFormat{
@Override
public void draw(Canvas canvas, int sequence, Rect rect, TableConfig config) {
//字体缩放
Paint paint = config.getPaint();
paint.setTextSize(paint.getTextSize()*(config.getZoom()>1?1:config.getZoom()));
paint.setTextAlign(Paint.Align.CENTER);
canvas.drawText(format(sequence+1),rect.centerX(), DrawUtils.getTextCenterY(rect.centerY(),paint) ,paint);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.bin.david.form.data.format.sequence;

import android.graphics.Canvas;
import android.graphics.Rect;

import com.bin.david.form.core.TableConfig;
import com.bin.david.form.data.format.IFormat;

/**
Expand All @@ -10,4 +14,7 @@

public interface ISequenceFormat extends IFormat<Integer>{


void draw(Canvas canvas, int sequence, Rect rect,TableConfig config);

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Created by huang on 2017/11/7.
*/

public class LetterSequenceFormat implements ISequenceFormat{
public class LetterSequenceFormat extends BaseSequenceFormat{

@Override
public String format(Integer position) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package com.bin.david.form.data.format.sequence;



/**
* Created by huang on 2017/11/7.
*/

public class NumberSequenceFormat implements ISequenceFormat{
public class NumberSequenceFormat extends BaseSequenceFormat{

@Override
public String format(Integer position) {
return String.valueOf(position);
}


}

0 comments on commit 9468be5

Please sign in to comment.