Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加自定义单元格字体样式 #292

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 24 additions & 3 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions .idea/runConfigurations.xml

This file was deleted.

4 changes: 4 additions & 0 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@

![Zoom](/img/zoom.gif)

> Format cell

![缩放](/img/cellFormat.png)

> refresh function(Use SmartRefreshLayout)

![refresh](/img/refresh.gif)
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@

![缩放](/img/zoom.gif)

> 自定义单元格字体样式

![缩放](/img/cellFormat.png)

> 刷新功能(使用SmartRefreshLayout)

![刷新](/img/refresh.gif)
Expand Down
5 changes: 4 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ android {
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "com.bin.david.smarttable"
minSdkVersion 15
minSdkVersion 21
targetSdkVersion 25
versionCode 1
versionName "1.8.5"
Expand All @@ -29,6 +29,9 @@ android {
}

dependencies {
//有类中引用类ok的代码
implementation("com.squareup.okhttp3:okhttp:4.9.3")

compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
Expand Down
16 changes: 10 additions & 6 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
android:roundIcon="@mipmap/icon"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".CellFormatActivity"
android:exported="false" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand All @@ -41,15 +44,16 @@
<activity android:name=".ArrayColumnModeActivity" />
<activity android:name=".MapModeActivity" />
<activity android:name=".WelcomeActivity" />
<activity android:name=".GridModeActivity"/>
<activity android:name=".AvatorModeActivity"/>
<activity android:name=".DesktopModeActivity"/>
<activity android:name=".GridModeActivity" />
<activity android:name=".AvatorModeActivity" />
<activity android:name=".DesktopModeActivity" />
<activity
android:name=".ChoiceExcelActivity"
android:label="@string/title_activity_choice_excel"
android:theme="@style/AppTheme.NoActionBar"/>
<activity android:name=".FormModeActivity"
android:windowSoftInputMode="adjustPan"/>
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".FormModeActivity"
android:windowSoftInputMode="adjustPan" />
</application>

</manifest>
156 changes: 156 additions & 0 deletions app/src/main/java/com/bin/david/smarttable/CellFormatActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
package com.bin.david.smarttable;

import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;

import com.bin.david.form.core.SmartTable;
import com.bin.david.form.data.format.bg.BaseBackgroundFormat;
import com.bin.david.form.data.style.FontStyle;
import com.bin.david.form.data.style.LineStyle;
import com.bin.david.form.data.table.PageTableData;
import com.bin.david.form.utils.DensityUtils;
import com.bin.david.smarttable.bean.CompanyCellData;
import com.bin.david.smarttable.bean.CompanyInfo;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

/**
* author: DongYonghui
* email: [email protected]
* created on: 2022/3/11 10:08
* description:演示自定义单元格样式
*/
public class CellFormatActivity extends AppCompatActivity {
private CheckBox mFixFirstCheckBox;
private SmartTable<CompanyInfo> table;
private PageTableData<CompanyInfo> companyInfoPageTableData;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cell_format);

//初始化View
mFixFirstCheckBox = (CheckBox) findViewById(R.id.mFixFirstCheckBox);
table = (SmartTable<CompanyInfo>) findViewById(R.id.table);

//初始化表格
initTable();

//固定列设置
mFixFirstCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
if (null != companyInfoPageTableData && null != companyInfoPageTableData.getColumnByID(1))
companyInfoPageTableData.getColumnByID(1).setFixed(isChecked);
if (null != companyInfoPageTableData && null != companyInfoPageTableData.getColumnByID(2))
companyInfoPageTableData.getColumnByID(2).setFixed(isChecked);
if (null != table)
table.invalidate();
}
});
}

private void initTable() {

//添加表格数据
final List<CompanyInfo> companyInfos = new ArrayList<>();
addTestData(companyInfos);
companyInfoPageTableData = table.setData(companyInfos);

//标题样式设置
FontStyle titleStyle = new FontStyle();
titleStyle.setTextColor(Color.BLACK);
titleStyle.setTextSize(DensityUtils.sp2px(this, 16));
//设置需要加粗的标题集合
HashSet<String> boldTitlesSet = new HashSet<>();
boldTitlesSet.add("单位");
boldTitlesSet.add("一季度小计");
boldTitlesSet.add("二季度小计");
boldTitlesSet.add("三季度小计");
boldTitlesSet.add("四季度小计");
boldTitlesSet.add("总计");

int titleBgColor = Color.parseColor("#4DE0E0E0");
int titleLineColor = Color.parseColor("#1AB3B3B3");

//标题线条样式
LineStyle titleLineStyle = new LineStyle();
titleLineStyle.setColor(titleLineColor);


table.setZoom(true, 5, 0.2f);
table.getConfig()
//设置padding
.setVerticalPadding(DensityUtils.dp2px(this, 5))
.setColumnTitleVerticalPadding(DensityUtils.dp2px(this, 10))
//设置标题字体样式
.setColumnTitleStyle(titleStyle)
//设置标题需要加粗的集合
.setBoldTitlesSet(boldTitlesSet)
//设置标题背景
.setColumnTitleBackground(new BaseBackgroundFormat(titleBgColor))
//设置标题线条颜色
.setColumnTitleGridStyle(titleLineStyle)
// .setColumnTitleVerticalPadding(DensityUtils.dp2px(this,5))
//因此表的总标题和X Y坐标轴
.setShowTableTitle(false)
.setShowXSequence(false)
.setShowYSequence(false);
}

private void addTestData(List<CompanyInfo> companyInfos) {
for (int i = 0; i < 15; i++) {
CompanyInfo companyInfo = new CompanyInfo();
companyInfo.companyName = new CompanyCellData("建安集团", true);
companyInfo.companySectionInfo = new CompanyCellData[]{new CompanyCellData("财政"), new CompanyCellData("企业"), new CompanyCellData("转贷")};
companyInfo.dataOfMonth1 = new CompanyCellData[]{new CompanyCellData("--"), new CompanyCellData("23630"), new CompanyCellData("23630")};
companyInfo.dataOfMonth2 = new CompanyCellData[]{new CompanyCellData("23630"), new CompanyCellData("--"), new CompanyCellData("23630")};
companyInfo.dataOfMonth3 = new CompanyCellData[]{new CompanyCellData("--"), new CompanyCellData("23630"), new CompanyCellData("23630")};
companyInfo.dataOfMonth3Total = new CompanyCellData[]{new CompanyCellData("588832"), new CompanyCellData("66688"), new CompanyCellData("989832")};
companyInfo.dataOfMonth4 = new CompanyCellData[]{new CompanyCellData("--"), new CompanyCellData("23630"), new CompanyCellData("23630")};
companyInfo.dataOfMonth5 = new CompanyCellData[]{new CompanyCellData("23630"), new CompanyCellData("23630"), new CompanyCellData("--")};
companyInfo.dataOfMonth6 = new CompanyCellData[]{new CompanyCellData("23630"), new CompanyCellData("23630"), new CompanyCellData("23630")};
companyInfo.dataOfMonth6Total = new CompanyCellData[]{new CompanyCellData("588832"), new CompanyCellData("66688"), new CompanyCellData("989832")};
companyInfo.dataOfMonth7 = new CompanyCellData[]{new CompanyCellData("23630"), new CompanyCellData("23630"), new CompanyCellData("23630")};
companyInfo.dataOfMonth8 = new CompanyCellData[]{new CompanyCellData("23630"), new CompanyCellData("23630"), new CompanyCellData("23630")};
companyInfo.dataOfMonth9 = new CompanyCellData[]{new CompanyCellData("23630"), new CompanyCellData("23630"), new CompanyCellData("23630")};
companyInfo.dataOfMonth9Total = new CompanyCellData[]{new CompanyCellData("588832"), new CompanyCellData("66688"), new CompanyCellData("989832")};
companyInfo.dataOfMonth10 = new CompanyCellData[]{new CompanyCellData("23630"), new CompanyCellData("23630"), new CompanyCellData("23630")};
companyInfo.dataOfMonth11 = new CompanyCellData[]{new CompanyCellData("23630"), new CompanyCellData("23630"), new CompanyCellData("23630")};
companyInfo.dataOfMonth12 = new CompanyCellData[]{new CompanyCellData("23630"), new CompanyCellData("23630"), new CompanyCellData("23630")};
companyInfo.dataOfMonth12Total = new CompanyCellData[]{new CompanyCellData("588832"), new CompanyCellData("66688"), new CompanyCellData("989832")};
companyInfo.dataOfMonthAllTotal = new CompanyCellData[]{new CompanyCellData("588832"), new CompanyCellData("66688"), new CompanyCellData("989832")};

companyInfos.add(companyInfo);

companyInfo = new CompanyInfo();
companyInfo.companyName = new CompanyCellData("小计(建安)", true);
companyInfo.dataOfMonth1 = new CompanyCellData[]{new CompanyCellData("88888", true)};
companyInfo.dataOfMonth2 = new CompanyCellData[]{new CompanyCellData("88888", true)};
companyInfo.dataOfMonth3 = new CompanyCellData[]{new CompanyCellData("88888", true)};
companyInfo.dataOfMonth4 = new CompanyCellData[]{new CompanyCellData("88888", true)};
companyInfo.dataOfMonth5 = new CompanyCellData[]{new CompanyCellData("88888", true)};
companyInfo.dataOfMonth6 = new CompanyCellData[]{new CompanyCellData("88888", true)};
companyInfo.dataOfMonth7 = new CompanyCellData[]{new CompanyCellData("88888", true)};
companyInfo.dataOfMonth8 = new CompanyCellData[]{new CompanyCellData("88888", true)};
companyInfo.dataOfMonth9 = new CompanyCellData[]{new CompanyCellData("88888", true)};
companyInfo.dataOfMonth10 = new CompanyCellData[]{new CompanyCellData("88888", true)};
companyInfo.dataOfMonth11 = new CompanyCellData[]{new CompanyCellData("88888", true)};
companyInfo.dataOfMonth12 = new CompanyCellData[]{new CompanyCellData("88888", true)};
companyInfo.dataOfMonthAllTotal = new CompanyCellData[]{new CompanyCellData("88888", true)};
companyInfo.dataOfMonth3Total = new CompanyCellData[]{new CompanyCellData("88888", true)};
companyInfo.dataOfMonth6Total = new CompanyCellData[]{new CompanyCellData("88888", true)};
companyInfo.dataOfMonth9Total = new CompanyCellData[]{new CompanyCellData("88888", true)};
companyInfo.dataOfMonth12Total = new CompanyCellData[]{new CompanyCellData("88888", true)};
companyInfo.isTotalData = true;
companyInfos.add(companyInfo);
}
}

}
Loading