Skip to content

Commit

Permalink
添加注释以及修复缩放中心不准确问题
Browse files Browse the repository at this point in the history
  • Loading branch information
huangyanbin committed Dec 7, 2017
1 parent 036e846 commit 5ca43d7
Show file tree
Hide file tree
Showing 7 changed files with 226 additions and 53 deletions.
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:icon="@mipmap/icon"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:roundIcon="@mipmap/icon"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/bin/david/smarttable/ManyActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ private void zoom(TableStyle item) {
@Override
public void onItemClick(String s, int position) {
if (position == 0) {
table.setZoom(true,3);
table.setZoom(true,4,0.2f);
} else if (position == 1) {
table.setZoom(false,3);
table.setZoom(false);
}
table.invalidate();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,9 @@ private void zoom(TableStyle item) {
@Override
public void onItemClick(String s, int position) {
if (position == 0) {
table.setZoom(true,3);
table.setZoom(true,3,1);
} else if (position == 1) {
table.setZoom(false,3);
table.setZoom(false,3,1);
}
table.invalidate();
}
Expand Down
Binary file added app/src/main/res/mipmap-xxhdpi/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
95 changes: 86 additions & 9 deletions form/src/main/java/com/bin/david/form/core/SmartTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,15 @@ private void init(){

}


/**
*绘制
* 首先通过计算的table大小,计算table title大小
* 再通过 matrixHelper getZoomProviderRect计算实现缩放和位移的Rect
* 再绘制背景
* 绘制XY序号列
* 最后绘制内容
* @param canvas
*/
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Expand Down Expand Up @@ -123,6 +131,11 @@ private void drawGridBackground(Canvas canvas) {
canvas.drawRect(showRect,paint);
}

/**
* 获取表格配置
* 可以使用TableConfig进行样式的配置,包括颜色,是否固定,开启统计行等
* @return 表格配置
*/
public TableConfig getConfig() {
return config;
}
Expand Down Expand Up @@ -175,15 +188,26 @@ public boolean onTouchEvent(MotionEvent event) {
return matrixHelper.handlerTouchEvent(event);
}

/**
* 分发事件
* 在这里会去调用MatrixHelper onDisallowInterceptEvent方法
* 判断是否阻止parent拦截自己的事件
* @param event
* @return
*/
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
matrixHelper.onDisallowInterceptEvent(this,event);
return super.dispatchTouchEvent(event);
}




/**
* 表格移动缩放改变回调
* @param scale 缩放值
* @param translateX X位移值
* @param translateY Y位移值
*/
@Override
public void onTableChanged(float scale, float translateX, float translateY) {
if(tableData != null) {
Expand All @@ -192,15 +216,27 @@ public void onTableChanged(float scale, float translateX, float translateY) {
invalidate();
}
}

/**
* 获取列点击事件
*/
public OnColumnClickListener getOnColumnClickListener() {
return provider.getOnColumnClickListener();
}

/**
* 设置列点击事件,实现对列的监听
* @param onColumnClickListener 列点击事件
*/
public void setOnColumnClickListener(OnColumnClickListener onColumnClickListener) {
this.provider.setOnColumnClickListener(onColumnClickListener);
}

/**
* 列排序
* 你可以调用这个方法,对所有数据进行排序,排序根据设置的column排序
* @param column 列
* @param isReverse 是否反序
*/
public void setSortColumn(Column column,boolean isReverse){
if(tableData != null&& column !=null){
column.setReverseSort(isReverse);
Expand All @@ -215,27 +251,68 @@ public Rect getShowRect() {
}


/**
* 获取绘制表格内容者
* @return 绘制表格内容者
*/
public TableProvider<T> getProvider() {
return provider;
}


/**
* 获取表格数据
* TableData是解析数据之后对数据的封装对象,包含table column,rect等信息
* @return 表格数据
*/
public TableData<T> getTableData() {
return tableData;
}

public boolean isZoom() {
return matrixHelper.isCanZoom();


/**
* 开启缩放
* @param zoom 是否缩放
*/
public void setZoom(boolean zoom) {

matrixHelper.setCanZoom(zoom);
invalidate();

}

public void setZoom(boolean zoom,int maxScale) {
/**
* 开启缩放设置缩放值
* @param zoom 是否缩放
* @param maxZoom 最大缩放值
* @param minZoom 最小缩放值
*/
public void setZoom(boolean zoom,float maxZoom,float minZoom) {

matrixHelper.setMaxZoom(maxScale);
matrixHelper.setCanZoom(zoom);
matrixHelper.setMinZoom(minZoom);
matrixHelper.setMaxZoom(maxZoom);
invalidate();

}

public void addData(List<T> t,boolean isFoot){
/**
* 获取缩放移动辅助类
*如果你需要更多的移动功能,可以使用它
* @return 缩放移动辅助类
*/
public MatrixHelper getMatrixHelper() {
return matrixHelper;
}

/**
* 添加数据
* 通过这个方法可以实现动态添加数据,参数isFoot可以实现首尾添加
* @param t 新增数据
* @param isFoot 是否在尾部添加
*/
public void addData(List<T> t, boolean isFoot){
if(t != null && t.size() >0) {
int size = tableData.getT().size();
parser.addData(tableData, t,isFoot,config);
Expand Down
4 changes: 4 additions & 0 deletions form/src/main/java/com/bin/david/form/core/TableMeasurer.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ private int getTableWidth(TableData<T> tableData,TableConfig config){
return totalWidth;
}

/**
* 测量列的Rect
* @param tableData
*/
private void measureColumnSize(TableData<T> tableData){
List<Column> columnList = tableData.getColumns();
int left = 0;
Expand Down
Loading

0 comments on commit 5ca43d7

Please sign in to comment.