From 0f9bc2622f6a4e72bc66b838aa4fdef721b8a6de Mon Sep 17 00:00:00 2001 From: pl2ufawr6 <2023312111429@whu.edu.cn> Date: Tue, 8 Apr 2025 23:06:02 +0800 Subject: [PATCH] ADD file via upload --- 获取课表/showkebiao.java | 94 ++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 获取课表/showkebiao.java diff --git a/获取课表/showkebiao.java b/获取课表/showkebiao.java new file mode 100644 index 0000000..3ebd2c4 --- /dev/null +++ b/获取课表/showkebiao.java @@ -0,0 +1,94 @@ +package com.example.fuckyou; + +import static com.example.fuckyou.MainActivity.kebiaodata; + +import android.annotation.SuppressLint; +import android.graphics.Color; +import android.os.Bundle; +import android.util.Log; +import android.widget.TextView; + +import androidx.activity.EdgeToEdge; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; + +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; + +public class showkebiao extends AppCompatActivity { + private static List alltext=new ArrayList<>(); + public static Date firstSunday(Date startdate) + { + Calendar calendar=Calendar.getInstance(); + calendar.setTime(startdate); + for (int i=0;i>=-6;i--) + { + calendar.add(Calendar.DATE,i); + if (calendar.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY) + { + break; + } + } + return calendar.getTime(); + } + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + EdgeToEdge.enable(this); + setContentView(R.layout.activity_showkebiao); + ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { + Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); + v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); + return insets; + }); + for (int i=23;i<=113;i++) { + int resID = getResources().getIdentifier("textView" + i, "id", getPackageName()); + TextView textView = findViewById(resID); + if (textView != null) { + alltext.add(textView); + textView.setText(""); + } + } + MyDatabaseHelper db=new MyDatabaseHelper(this); + List kebiaodata= null; + /*try { + kebiaodata = db.alllesson(); + } catch (ParseException e) { + throw new RuntimeException(e); + }*/ + + Date date=new Date(); + Log.d("timing",date.toString()); + Date thissunday=firstSunday(date); + try { + kebiaodata=db.lessoninweek(thissunday); + } catch (ParseException e) { + throw new RuntimeException(e); + } + for (Lesson test:kebiaodata) + { + int num=13*test.day+test.fromClass-1; + TextView temp= alltext.get(num); + int cutoff = 4; + String firstPart = test.name.substring(0, Math.min(cutoff, test.name.length())); + String secondPart = test.name.length() > cutoff ? test.name.substring(cutoff) : ""; + temp.setText(firstPart); + temp.setBackgroundColor(Color.parseColor("#FFBB33")); + for(int i=1;i<=test.endClass-test.fromClass;i++) + { + TextView tt=alltext.get(num+i); + tt.setText(secondPart); + tt.setBackgroundColor(Color.parseColor("#FFBB33")); + if (i>=3) + { + tt.setText("same"); + } + } + } + } +} \ No newline at end of file