public class MainActivity2 extends AppCompatActivity {
private Button goalAnalysisButton;
private Button dailyCheckInButton;
private Button statisticsButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
goalAnalysisButton = findViewById(R.id.GoalAnalysisButton);
dailyCheckInButton = findViewById(R.id.DailyCheckInButton);
statisticsButton = findViewById(R.id.StatisticsButton);
// 目标与分析按钮点击事件
goalAnalysisButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity2.this, GoalAnalysis.class);
startActivity(intent);
}
});
// 每日打卡按钮点击事件
dailyCheckInButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity2.this, DailyCheckIn.class);
startActivity(intent);
}
});
}
// 处理统计与分析按钮点击事件
public void queryStatisticsData(View view) {
new Thread() {
@Override
public void run() {
// 在后台线程中执行查询统计数据的操作
// 获取当前登录用户的 studentId
String studentId = StudentDao.getCurrentLoggedInUserId();
// 获取学生对象
StudentDao studentDao = new StudentDao();
Student student = studentDao.findStudent(studentId);
if (student != null) {
// 获取 setGoal、setRecord 和完成度百分比
int setGoal = student.getSetGoal();
int setRecord = student.getSetRecord();
double completionPercentage = PlanningDao.calculateCompletionPercentage(studentId);
// 创建一个列表存储数据
ArrayList<StatisticData> statisticDataList = new ArrayList<>();
statisticDataList.add(new StatisticData(studentId, setGoal, setRecord, completionPercentage));
// 将数据传递给 Statistics 类(com.example.demo3 包下)
Intent intent = new Intent(MainActivity2.this, Statistics.class);
intent.putParcelableArrayListExtra("statisticDataList", statisticDataList);
startActivity(intent);
}
}
}.start();
}
}