Skip to content

Commit

Permalink
增加Json直接转换成表格
Browse files Browse the repository at this point in the history
  • Loading branch information
huangyanbin committed Feb 8, 2018
1 parent a597370 commit c164353
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<activity android:name=".MinModeActivity"/>
<activity android:name=".ArrayColumnModeActivity"/>
<activity android:name=".MapModeActivity"/>
<activity android:name=".WelcomeActivity"/>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ protected void onCreate(Bundle savedInstanceState) {
recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
ArrayList<MainItem> items = new ArrayList<>();
items.add(new MainItem(WelcomeActivity.class,"欢迎光临") );
items.add(new MainItem(ParseModeActivity.class,"解析模式"));
items.add(new MainItem(AnnotationModeActivity.class,"注解模式"));
items.add(new MainItem(RefreshActivity.class,"刷新加载加载更多"));
Expand Down
174 changes: 174 additions & 0 deletions app/src/main/java/com/bin/david/smarttable/WelcomeActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
package com.bin.david.smarttable;

import android.animation.ValueAnimator;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.Rect;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;

import com.bin.david.form.core.SmartTable;
import com.bin.david.form.core.TableConfig;
import com.bin.david.form.data.column.Column;
import com.bin.david.form.data.format.draw.IDrawFormat;
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.smarttable.bean.TableStyle;
import com.bin.david.smarttable.view.QuickChartDialog;

/**
* Created by huang on 2018/2/8.
* 欢迎页
*/

public class WelcomeActivity extends AppCompatActivity {
private SmartTable<Integer> table;

private QuickChartDialog quickChartDialog;
ArrayTableData<Integer> tableData;
ValueAnimator valueAnimator;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_weclome);
table = (SmartTable<Integer>) findViewById(R.id.table);
quickChartDialog = new QuickChartDialog();
Integer[][] data = {{0,1,2},{3,4,5},{6,7,8}};

table.getConfig()
.setHorizontalPadding(0)
.setVerticalPadding(0)
.setColumnTitleHorizontalPadding(0)
.setColumnTitleVerticalPadding(0)
.setShowXSequence(false)
.setShowYSequence(false)
.setShowTableTitle(false)
.setGridStyle(new LineStyle(-1,ContextCompat.getColor(this,android.R.color.transparent)));
tableData= ArrayTableData.create(table, "动画", data, null);
table.setTableData(tableData);
startAnim0();
}




public void onClick(View view){
quickChartDialog.showDialog(this, TableStyle.ANIM, new String[]{"翻转","单翻转"}, new QuickChartDialog.OnCheckChangeAdapter() {
@Override
public void onItemClick(String s, int position) {
switch (position){
case 0:
startAnim0();
break;
case 1:
startAnim1();
break;
}
}
});
}
private int rotateAngle0=0;
private void startAnim0(){
final int size = DensityUtils.dp2px(this,40);
IDrawFormat<Integer> format = new IDrawFormat<Integer>() {
@Override
public int measureWidth(Column<Integer> column, int position, TableConfig config) {
return size;
}

@Override
public int measureHeight(Column<Integer> column, int position, TableConfig config) {
return size;
}

@Override
public void draw(Canvas c, Column<Integer> column, Integer integer, String value, Rect rect, int position, TableConfig config) {
Paint paint = config.getPaint();
paint.setStyle(Paint.Style.FILL);
paint.setColor(ContextCompat.getColor(WelcomeActivity.this, R.color.arc1));
c.save();
c.clipRect(rect);
c.rotate(rotateAngle0,rect.centerX(),rect.centerY());
c.drawRect(rect.left+5,rect.top+5,rect.right-5,rect.bottom-5,paint);
c.restore();
}
};
tableData.setDrawFormat(format);
if(valueAnimator != null){
valueAnimator.cancel();
}
valueAnimator = ValueAnimator.ofInt(0,180).setDuration(1000);
valueAnimator.setRepeatMode(ValueAnimator.REVERSE);
valueAnimator.setRepeatCount(ValueAnimator.INFINITE);
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
rotateAngle0 = (int) animation.getAnimatedValue();
table.invalidate();
}
});
valueAnimator.start();
}
private int rotateAngle1=0;
private int rotatePosition =0;

private void startAnim1(){
final int size = DensityUtils.dp2px(this,40);
final int[] points = new int[]{0,1,2,5,8,7,6,3};
IDrawFormat<Integer> format = new IDrawFormat<Integer>() {
@Override
public int measureWidth(Column<Integer> column, int position, TableConfig config) {
return size*3/4;
}

@Override
public int measureHeight(Column<Integer> column, int position, TableConfig config) {
return size*3/4;
}

@Override
public void draw(Canvas c, Column<Integer> column, Integer val, String value, Rect rect, int position, TableConfig config) {

Paint paint = config.getPaint();
paint.setStyle(Paint.Style.FILL);
paint.setColor(ContextCompat.getColor(WelcomeActivity.this, R.color.arc1));
c.save();
if(val == points[rotatePosition]) {
c.rotate(rotateAngle1, rect.centerX(), rect.centerY());
}
c.drawRect(rect.left+5,rect.top+5,rect.right-5,rect.bottom-5,paint);
c.restore();
}
};
tableData.setDrawFormat(format);
if(valueAnimator != null){
valueAnimator.cancel();
}
valueAnimator = ValueAnimator.ofInt(0,180).setDuration(1000);
valueAnimator.setRepeatMode(ValueAnimator.RESTART);
valueAnimator.setRepeatCount(ValueAnimator.INFINITE);
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {

rotateAngle1 = (int) animation.getAnimatedValue();
if(rotateAngle1 >=179){
rotatePosition++;
if(rotatePosition ==8){
rotatePosition=0;
}
}
table.invalidate();
}
});
valueAnimator.start();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public enum TableStyle {
FIXED_COUNT_ROW("固定统计行"),
ZOOM("是否缩放"),
ALIGN("文字位置"),

ANIM("动画"),
FLING("Fling");


Expand Down
33 changes: 33 additions & 0 deletions app/src/main/res/layout/activity_weclome.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="match_parent"
tools:context="com.bin.david.smarttable.WelcomeActivity">

<com.bin.david.form.core.SmartTable
android:id="@+id/table"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"

/>


<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_marginBottom="10dp"
android:background="@drawable/dialog_btn_bg"
android:text="动画"
android:layout_gravity="bottom|center_horizontal"
android:onClick="onClick"
android:clickable="true"
android:textColor="#fff"
android:layout_height="45dp" />


</FrameLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,15 @@ public void setFormat(IFormat<T> format){
column.setFormat(format);
}
}

/**
* 设置绘制格式化
* @param format
*/
public void setDrawFormat(IDrawFormat<T> format){
for(Column<T> column:arrayColumns){
column.setDrawFormat(format);
}
}


/**
Expand Down

0 comments on commit c164353

Please sign in to comment.