From 9468be501ac50f617cdad3c3f6b533ac4c9ab724 Mon Sep 17 00:00:00 2001 From: huangyanbin <873825232@qq.com> Date: Mon, 26 Mar 2018 17:22:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E5=BA=8F=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../david/smarttable/DesktopModeActivity.java | 3 +- .../bin/david/smarttable/MainActivity.java | 1 + .../com/bin/david/smarttable/bean/Course.java | 32 +++++++++++++++++++ .../bin/david/form/component/XSequence.java | 12 +++---- .../bin/david/form/component/YSequence.java | 15 ++++----- .../format/sequence/BaseSequenceFormat.java | 23 +++++++++++++ .../data/format/sequence/ISequenceFormat.java | 7 ++++ .../format/sequence/LetterSequenceFormat.java | 2 +- .../format/sequence/NumberSequenceFormat.java | 5 ++- 9 files changed, 81 insertions(+), 19 deletions(-) create mode 100644 app/src/main/java/com/bin/david/smarttable/bean/Course.java create mode 100644 form/src/main/java/com/bin/david/form/data/format/sequence/BaseSequenceFormat.java diff --git a/app/src/main/java/com/bin/david/smarttable/DesktopModeActivity.java b/app/src/main/java/com/bin/david/smarttable/DesktopModeActivity.java index db5f440..270e944 100644 --- a/app/src/main/java/com/bin/david/smarttable/DesktopModeActivity.java +++ b/app/src/main/java/com/bin/david/smarttable/DesktopModeActivity.java @@ -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; @@ -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)+""; 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 2722cb3..4bf0c6e 100644 --- a/app/src/main/java/com/bin/david/smarttable/MainActivity.java +++ b/app/src/main/java/com/bin/david/smarttable/MainActivity.java @@ -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")); diff --git a/app/src/main/java/com/bin/david/smarttable/bean/Course.java b/app/src/main/java/com/bin/david/smarttable/bean/Course.java new file mode 100644 index 0000000..27b7f0b --- /dev/null +++ b/app/src/main/java/com/bin/david/smarttable/bean/Course.java @@ -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; + } +} diff --git a/form/src/main/java/com/bin/david/form/component/XSequence.java b/form/src/main/java/com/bin/david/form/component/XSequence.java index b76908c..0c5a1bb 100644 --- a/form/src/main/java/com/bin/david/form/component/XSequence.java +++ b/form/src/main/java/com/bin/david/form/component/XSequence.java @@ -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); //绘制背景 @@ -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); + } diff --git a/form/src/main/java/com/bin/david/form/component/YSequence.java b/form/src/main/java/com/bin/david/form/component/YSequence.java index 0e3f331..d5b4fa8 100644 --- a/form/src/main/java/com/bin/david/form/component/YSequence.java +++ b/form/src/main/java/com/bin/david/form/component/YSequence.java @@ -91,7 +91,7 @@ public void onDraw(Canvas canvas, Rect showRect, TableData 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(); @@ -103,7 +103,7 @@ public void onDraw(Canvas canvas, Rect showRect, TableData 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(); @@ -115,7 +115,7 @@ public void onDraw(Canvas canvas, Rect showRect, TableData 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; @@ -127,7 +127,7 @@ public void onDraw(Canvas canvas, Rect showRect, TableData 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){ @@ -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 backgroundFormat = config.getYSequenceCellBgFormat(); int textColor =TableConfig.INVALID_COLOR; @@ -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() { diff --git a/form/src/main/java/com/bin/david/form/data/format/sequence/BaseSequenceFormat.java b/form/src/main/java/com/bin/david/form/data/format/sequence/BaseSequenceFormat.java new file mode 100644 index 0000000..901593e --- /dev/null +++ b/form/src/main/java/com/bin/david/form/data/format/sequence/BaseSequenceFormat.java @@ -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); + } +} diff --git a/form/src/main/java/com/bin/david/form/data/format/sequence/ISequenceFormat.java b/form/src/main/java/com/bin/david/form/data/format/sequence/ISequenceFormat.java index 3b39157..e370f5e 100644 --- a/form/src/main/java/com/bin/david/form/data/format/sequence/ISequenceFormat.java +++ b/form/src/main/java/com/bin/david/form/data/format/sequence/ISequenceFormat.java @@ -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; /** @@ -10,4 +14,7 @@ public interface ISequenceFormat extends IFormat{ + + void draw(Canvas canvas, int sequence, Rect rect,TableConfig config); + } diff --git a/form/src/main/java/com/bin/david/form/data/format/sequence/LetterSequenceFormat.java b/form/src/main/java/com/bin/david/form/data/format/sequence/LetterSequenceFormat.java index 99124ff..e91d0da 100644 --- a/form/src/main/java/com/bin/david/form/data/format/sequence/LetterSequenceFormat.java +++ b/form/src/main/java/com/bin/david/form/data/format/sequence/LetterSequenceFormat.java @@ -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) { diff --git a/form/src/main/java/com/bin/david/form/data/format/sequence/NumberSequenceFormat.java b/form/src/main/java/com/bin/david/form/data/format/sequence/NumberSequenceFormat.java index 8d4d116..139d04a 100644 --- a/form/src/main/java/com/bin/david/form/data/format/sequence/NumberSequenceFormat.java +++ b/form/src/main/java/com/bin/david/form/data/format/sequence/NumberSequenceFormat.java @@ -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); } + + }