├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── drawable │ │ │ │ ├── end.png │ │ │ │ ├── book.png │ │ │ │ ├── start.png │ │ │ │ ├── time.png │ │ │ │ ├── trash.png │ │ │ │ ├── user.png │ │ │ │ ├── calendar.png │ │ │ │ ├── category.png │ │ │ │ ├── location.png │ │ │ │ ├── add_select.png │ │ │ │ ├── arrow_left.png │ │ │ │ ├── item_bg.xml │ │ │ │ ├── btn.xml │ │ │ │ └── ic_launcher_background.xml │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── icon.png │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── styles.xml │ │ │ │ └── colors.xml │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── layout │ │ │ │ ├── activity_main.xml │ │ │ │ ├── activity_option.xml │ │ │ │ ├── add_course_item.xml │ │ │ │ ├── lession_item.xml │ │ │ │ ├── add_lesson_item.xml │ │ │ │ └── activity_update_course.xml │ │ │ └── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── hemou │ │ │ │ └── curriculum │ │ │ │ ├── view │ │ │ │ ├── RoundTextView.java │ │ │ │ └── TimeTableView.java │ │ │ │ ├── util │ │ │ │ └── JsonDataUtil.java │ │ │ │ ├── activity │ │ │ │ ├── MainActivity.java │ │ │ │ ├── OptionActivity.java │ │ │ │ └── UpdateCourseActivity.java │ │ │ │ ├── adapter │ │ │ │ └── LessonAdapter.java │ │ │ │ ├── dao │ │ │ │ └── CourseDao.java │ │ │ │ └── pojo │ │ │ │ └── Course.java │ │ └── AndroidManifest.xml │ ├── androidTest │ │ └── java │ │ │ └── com │ │ │ └── hemou │ │ │ └── curriculum │ │ │ └── ExampleInstrumentedTest.java │ └── test │ │ └── java │ │ └── com │ │ └── hemou │ │ └── curriculum │ │ └── ExampleUnitTest.java ├── release │ └── output.json ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── img ├── 1.gif ├── image-20200406122410892.png └── image-20200406122425961.png ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .idea ├── encodings.xml ├── runConfigurations.xml ├── misc.xml └── codeStyles │ └── Project.xml ├── README.md ├── gradle.properties ├── .gitignore ├── gradlew.bat ├── gradlew └── LICENSE /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | rootProject.name='Curriculum' 3 | -------------------------------------------------------------------------------- /img/1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeMOua/timetable/HEAD/img/1.gif -------------------------------------------------------------------------------- /app/src/main/res/drawable/end.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeMOua/timetable/HEAD/app/src/main/res/drawable/end.png -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeMOua/timetable/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /img/image-20200406122410892.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeMOua/timetable/HEAD/img/image-20200406122410892.png -------------------------------------------------------------------------------- /img/image-20200406122425961.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeMOua/timetable/HEAD/img/image-20200406122425961.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/book.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeMOua/timetable/HEAD/app/src/main/res/drawable/book.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeMOua/timetable/HEAD/app/src/main/res/drawable/start.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/time.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeMOua/timetable/HEAD/app/src/main/res/drawable/time.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/trash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeMOua/timetable/HEAD/app/src/main/res/drawable/trash.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/user.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeMOua/timetable/HEAD/app/src/main/res/drawable/user.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/calendar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeMOua/timetable/HEAD/app/src/main/res/drawable/calendar.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/category.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeMOua/timetable/HEAD/app/src/main/res/drawable/category.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/location.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeMOua/timetable/HEAD/app/src/main/res/drawable/location.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeMOua/timetable/HEAD/app/src/main/res/mipmap-xhdpi/icon.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/add_select.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeMOua/timetable/HEAD/app/src/main/res/drawable/add_select.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/arrow_left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeMOua/timetable/HEAD/app/src/main/res/drawable/arrow_left.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeMOua/timetable/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeMOua/timetable/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeMOua/timetable/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeMOua/timetable/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeMOua/timetable/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeMOua/timetable/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeMOua/timetable/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeMOua/timetable/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeMOua/timetable/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HeMOua/timetable/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /app/release/output.json: -------------------------------------------------------------------------------- 1 | [{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":1,"versionName":"1.0","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}] -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 课程表 3 | 上一周 4 | 下一周 5 | 返回 6 | 删除课程 7 | 8 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Apr 02 13:03:52 CST 2020 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/item_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 课程表 2 | Android课程表控件 3 | 4 | **2020-5-18更新** 5 | 6 | 增加自定义课程信息功能 7 | 8 | 1 9 | 10 | **2020-4-6** 11 | 12 |
13 | image-20200406122425961 14 | image-20200406122410892 15 |
16 |
17 | 18 | 介绍:[点击这里](https://www.cnblogs.com/hemou/p/12641871.html) -------------------------------------------------------------------------------- /app/src/main/res/drawable/btn.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Android 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 23 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/hemou/curriculum/view/RoundTextView.java: -------------------------------------------------------------------------------- 1 | package com.hemou.curriculum.view; 2 | 3 | import android.content.Context; 4 | import android.graphics.drawable.GradientDrawable; 5 | import android.os.Build; 6 | 7 | import androidx.annotation.ColorInt; 8 | import androidx.appcompat.widget.AppCompatTextView; 9 | 10 | public class RoundTextView extends AppCompatTextView { 11 | 12 | public RoundTextView(Context context) { 13 | super(context); 14 | } 15 | 16 | public RoundTextView(Context context, int radius, @ColorInt int bkColor){ 17 | super(context); 18 | GradientDrawable gradientDrawable = new GradientDrawable(); 19 | gradientDrawable.setCornerRadius(radius); 20 | gradientDrawable.setColor(bkColor); 21 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { 22 | setBackground(gradientDrawable); 23 | } 24 | } 25 | 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 15 | 16 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/hemou/curriculum/util/JsonDataUtil.java: -------------------------------------------------------------------------------- 1 | package com.hemou.curriculum.util; 2 | 3 | import android.content.Context; 4 | import android.content.res.AssetManager; 5 | 6 | import java.io.BufferedReader; 7 | import java.io.IOException; 8 | import java.io.InputStreamReader; 9 | 10 | public class JsonDataUtil { 11 | 12 | public static String getJson(Context context, String fileName){ 13 | StringBuilder stringBuilder = new StringBuilder(); 14 | try { 15 | //获取assets资源管理器 16 | AssetManager assetManager = context.getAssets(); 17 | //通过管理器打开文件并读取 18 | BufferedReader bf = new BufferedReader(new InputStreamReader( 19 | assetManager.open(fileName))); 20 | String line; 21 | while ((line = bf.readLine()) != null) { 22 | stringBuilder.append(line); 23 | } 24 | } catch (IOException e) { 25 | e.printStackTrace(); 26 | } 27 | return stringBuilder.toString(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app's APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | 21 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 29 5 | buildToolsVersion "29.0.2" 6 | defaultConfig { 7 | applicationId "com.hemou.curriculum" 8 | minSdkVersion 21 9 | targetSdkVersion 29 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | 21 | testOptions { 22 | unitTests.returnDefaultValues = true 23 | } 24 | } 25 | 26 | dependencies { 27 | implementation group: 'com.alibaba', name: 'fastjson', version: '1.2.61' 28 | implementation group: 'commons-io', name: 'commons-io', version: '2.6' 29 | implementation fileTree(dir: 'libs', include: ['*.jar']) 30 | implementation 'androidx.appcompat:appcompat:1.1.0' 31 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3' 32 | testImplementation 'junit:junit:4.12' 33 | androidTestImplementation 'androidx.test.ext:junit:1.1.1' 34 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' 35 | } 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.aar 4 | *.ap_ 5 | *.aab 6 | 7 | # Files for the ART/Dalvik VM 8 | *.dex 9 | 10 | # Java class files 11 | *.class 12 | 13 | # Generated files 14 | bin/ 15 | gen/ 16 | out/ 17 | # Uncomment the following line in case you need and you don't have the release build type files in your app 18 | # release/ 19 | 20 | # Gradle files 21 | .gradle/ 22 | build/ 23 | 24 | # Local configuration file (sdk path, etc) 25 | local.properties 26 | 27 | # Proguard folder generated by Eclipse 28 | proguard/ 29 | 30 | # Log Files 31 | *.log 32 | 33 | # Android Studio Navigation editor temp files 34 | .navigation/ 35 | 36 | # Android Studio captures folder 37 | captures/ 38 | 39 | # IntelliJ 40 | *.iml 41 | .idea/workspace.xml 42 | .idea/tasks.xml 43 | .idea/gradle.xml 44 | .idea/assetWizardSettings.xml 45 | .idea/dictionaries 46 | .idea/libraries 47 | # Android Studio 3 in .gitignore file. 48 | .idea/caches 49 | .idea/modules.xml 50 | # Comment next line if keeping position of elements in Navigation Editor is relevant for you 51 | .idea/navEditor.xml 52 | 53 | # Keystore files 54 | # Uncomment the following lines if you do not want to check your keystore files in. 55 | #*.jks 56 | #*.keystore 57 | 58 | # External native build folder generated in Android Studio 2.2 and later 59 | .externalNativeBuild 60 | .cxx/ 61 | 62 | # Google Services (e.g. APIs or Firebase) 63 | # google-services.json 64 | 65 | # Freeline 66 | freeline.py 67 | freeline/ 68 | freeline_project_description.json 69 | 70 | # fastlane 71 | fastlane/report.xml 72 | fastlane/Preview.html 73 | fastlane/screenshots 74 | fastlane/test_output 75 | fastlane/readme.md 76 | 77 | # Version control 78 | vcs.xml 79 | 80 | # lint 81 | lint/intermediates/ 82 | lint/generated/ 83 | lint/outputs/ 84 | lint/tmp/ 85 | # lint/reports/ 86 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #008577 4 | #00574B 5 | #D81B60 6 | #ffffff 7 | 8 | #76B9ED 9 | #ffe6e6e6 10 | #333333 11 | 12 | #8AD297 13 | #5ABF6C 14 | #F9A883 15 | #F79060 16 | #88CFCC 17 | #63C0BD 18 | #F19C99 19 | #ED837F 20 | #F7C56B 21 | #F5B94E 22 | #D2A596 23 | #CA9483 24 | #67BDDE 25 | #31A6D3 26 | #9CCF5A 27 | #8BC73D 28 | #9AB4CF 29 | #87A6C6 30 | #9AB4CF 31 | #87A6C6 32 | #E593AD 33 | #6DB69C 34 | #E593AD 35 | #DF7999 36 | #E2C38A 37 | #D6A858 38 | #B29FD2 39 | #997FC3 40 | #E2C490 41 | #DDB97B 42 | #7B7B7B 43 | #ADADAD 44 | #2DACA1 45 | #000000 46 | 47 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/hemou/curriculum/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.hemou.curriculum; 2 | 3 | import android.content.Context; 4 | 5 | import androidx.test.ext.junit.runners.AndroidJUnit4; 6 | import androidx.test.platform.app.InstrumentationRegistry; 7 | 8 | import com.hemou.curriculum.dao.CourseDao; 9 | import com.hemou.curriculum.pojo.Course; 10 | 11 | import org.json.JSONException; 12 | import org.junit.Test; 13 | import org.junit.runner.RunWith; 14 | 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | 18 | import static org.junit.Assert.assertEquals; 19 | 20 | /** 21 | * Instrumented test, which will execute on an Android device. 22 | * 23 | * @see Testing documentation 24 | */ 25 | @RunWith(AndroidJUnit4.class) 26 | public class ExampleInstrumentedTest { 27 | 28 | 29 | @Test 30 | public void useAppContext() { 31 | // Context of the app under test. 32 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); 33 | 34 | assertEquals("com.hemou.curriculum", appContext.getPackageName()); 35 | } 36 | 37 | public void testJson() throws JSONException { 38 | List courseList = new ArrayList<>(); 39 | courseList.add((new Course("形式与政策", "肖惠朝", 1, 7, "3:5:s:XC-D"))); 40 | courseList.add((new Course("计算机信息安全", "李照明", 1, 11, "3:5:d:XC207;5:3:n:XC205"))); 41 | courseList.add((new Course("软件工程", "彭惠玲", 1, 12, "2:3:n:XC412;5:1:n:XC308"))); 42 | courseList.add((new Course("Web前端开发", "罗豪凡", 1, 12, "1:5:n:XC412;3:1:n:XC412"))); 43 | courseList.add((new Course("JavaWeb高级编程", "刁文广", 5, 16, "1:3:n:XC412;3:7:n:XC412"))); 44 | courseList.add((new Course("Android应用开发", "卢向华", 5, 16, "4:3:n:XD110;5:5:n:XC310"))); 45 | courseList.add((new Course("计算机视觉应用", "王国强", 1, 8, "2:5:n:XC305;4:1:n:XC409"))); 46 | courseList.add((new Course("计算机新技术", "李淳凡", 6, 9, "1:1:n:XC4;1:7:n:XC4;2:1:n:XC4;3:3:n:XC4"))); 47 | 48 | CourseDao dao = new CourseDao(InstrumentationRegistry.getInstrumentation().getContext()); 49 | for(Course course : courseList){ 50 | dao.insert(course); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /app/src/main/java/com/hemou/curriculum/activity/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.hemou.curriculum.activity; 2 | 3 | import android.content.Intent; 4 | import android.content.SharedPreferences; 5 | import android.os.Bundle; 6 | import android.util.Log; 7 | import android.view.View; 8 | 9 | import androidx.appcompat.app.AppCompatActivity; 10 | 11 | import com.hemou.curriculum.R; 12 | import com.hemou.curriculum.dao.CourseDao; 13 | import com.hemou.curriculum.pojo.Course; 14 | import com.hemou.curriculum.view.TimeTableView; 15 | 16 | import java.util.ArrayList; 17 | import java.util.Date; 18 | import java.util.List; 19 | 20 | public class MainActivity extends AppCompatActivity { 21 | 22 | private CourseDao courseDao = new CourseDao(this); 23 | private TimeTableView timeTable; 24 | private SharedPreferences sp; 25 | 26 | @Override 27 | protected void onCreate(Bundle savedInstanceState) { 28 | super.onCreate(savedInstanceState); 29 | setContentView(R.layout.activity_main); 30 | 31 | sp = getSharedPreferences("config", MODE_PRIVATE); 32 | timeTable = findViewById(R.id.timeTable); 33 | timeTable.addListener(new View.OnClickListener() { 34 | @Override 35 | public void onClick(View v) { 36 | categoryListener(); 37 | } 38 | }); 39 | } 40 | 41 | @Override 42 | protected void onStart() { 43 | super.onStart(); 44 | //获取开学时间 45 | long date = sp.getLong("date", new Date().getTime()); 46 | timeTable.loadData(acquireData(), new Date(date)); 47 | Log.i("test", new Date(date).toString()); 48 | } 49 | 50 | private List acquireData() { 51 | List courses = new ArrayList<>(); 52 | sp = getSharedPreferences("config", MODE_PRIVATE); 53 | if (sp.getBoolean("isFirstUse", true)) {//首次使用 54 | sp.edit().putBoolean("isFirstUse", false).apply(); 55 | }else { 56 | courses = courseDao.listAll(); 57 | } 58 | return courses; 59 | } 60 | 61 | /** 62 | * 菜单 63 | */ 64 | public void categoryListener() { 65 | Intent intent = new Intent(this, OptionActivity.class); 66 | startActivity(intent); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_option.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 14 | 19 | 24 | 31 | 40 | 46 | 47 | 48 | 49 | 53 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /app/src/test/java/com/hemou/curriculum/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.hemou.curriculum; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.alibaba.fastjson.JSONArray; 5 | import com.alibaba.fastjson.JSONObject; 6 | import com.hemou.curriculum.activity.MainActivity; 7 | import com.hemou.curriculum.pojo.Course; 8 | import com.hemou.curriculum.view.TimeTableView; 9 | 10 | import org.junit.Test; 11 | 12 | import java.io.IOException; 13 | import java.text.ParseException; 14 | import java.text.SimpleDateFormat; 15 | import java.util.ArrayList; 16 | import java.util.Date; 17 | import java.util.HashMap; 18 | import java.util.List; 19 | import java.util.Map; 20 | 21 | /** 22 | * Example local unit test, which will execute on the development machine (host). 23 | * 24 | * @see Testing documentation 25 | */ 26 | public class ExampleUnitTest { 27 | 28 | @Test 29 | public void testReflect(){ 30 | TimeTableView timeTable = new TimeTableView(new MainActivity()); 31 | Map map = new HashMap<>(); 32 | map.put("maxSection", 100); 33 | map.put("radius", 20); 34 | map.put("numberSize", 30); 35 | timeTable.initParams(map); 36 | System.out.println(timeTable); 37 | } 38 | 39 | @Test 40 | public void testJson() throws IOException { 41 | JSONObject jsonObject = new JSONObject(); 42 | 43 | List courseList = new ArrayList<>(); 44 | courseList.add((new Course("形式与政策", "肖惠朝", 1, 7, "3:5:s:XC-D"))); 45 | courseList.add((new Course("计算机信息安全", "李照明", 1, 11, "3:5:d:XC207;5:3:n:XC205"))); 46 | courseList.add((new Course("软件工程", "彭惠玲", 1, 12, "2:3:n:XC412;5:1:n:XC308"))); 47 | courseList.add((new Course("Web前端开发", "罗豪凡", 1, 12, "1:5:n:XC412;3:1:n:XC412"))); 48 | courseList.add((new Course("JavaWeb高级编程", "刁文广", 5, 16, "1:3:n:XC412;3:7:n:XC412"))); 49 | courseList.add((new Course("Android应用开发", "卢向华", 5, 16, "4:3:n:XD110;5:5:n:XC310"))); 50 | courseList.add((new Course("计算机视觉应用", "王国强", 1, 8, "2:5:n:XC305;4:1:n:XC409"))); 51 | courseList.add((new Course("计算机新技术", "李淳凡", 6, 9, "1:1:n:XC4;1:7:n:XC4;2:1:n:XC4;3:3:n:XC4"))); 52 | 53 | JSONArray courses = JSON.parseArray(JSON.toJSONString(courseList)); 54 | 55 | jsonObject.put("courses", courses); 56 | jsonObject.put("max_section", 9); 57 | jsonObject.put("radius", 8); 58 | jsonObject.put("table_line_width", 1); 59 | jsonObject.put("number_size", 14); 60 | jsonObject.put("title_size", 18); 61 | jsonObject.put("course_size", 12); 62 | jsonObject.put("button_size", 12); 63 | jsonObject.put("cell_height", 75); 64 | jsonObject.put("title_height", 30); 65 | jsonObject.put("number_width", 20); 66 | 67 | // List cs = JSON.parseArray(jsonObject.getJSONArray("courses").toJSONString(), Course.class); 68 | // System.out.println(cs.toString()); 69 | } 70 | 71 | @Test 72 | public void testWeek() throws ParseException { 73 | Date startDate = new SimpleDateFormat("yyyy-MM-dd").parse("2020-2-24"); 74 | System.out.println(startDate.getTime()); 75 | } 76 | } -------------------------------------------------------------------------------- /app/src/main/java/com/hemou/curriculum/adapter/LessonAdapter.java: -------------------------------------------------------------------------------- 1 | package com.hemou.curriculum.adapter; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.BaseAdapter; 8 | import android.widget.ImageView; 9 | import android.widget.TextView; 10 | 11 | import androidx.annotation.NonNull; 12 | 13 | import com.hemou.curriculum.R; 14 | import com.hemou.curriculum.dao.CourseDao; 15 | import com.hemou.curriculum.pojo.Course; 16 | 17 | import java.util.List; 18 | 19 | public class LessonAdapter extends BaseAdapter { 20 | 21 | private CourseDao dao; 22 | private Context context; 23 | private LayoutInflater layoutInflater; 24 | private List courseList; 25 | private View.OnClickListener listener; 26 | 27 | public LessonAdapter(Context context, @NonNull List courseList, View.OnClickListener listener){ 28 | this.context = context; 29 | this.courseList = courseList; 30 | this.layoutInflater = LayoutInflater.from(context); 31 | this.listener = listener; 32 | dao = new CourseDao(context); 33 | } 34 | 35 | @Override 36 | public int getCount() { 37 | return courseList.size(); 38 | } 39 | 40 | @Override 41 | public Object getItem(int position) { 42 | return null; 43 | } 44 | 45 | @Override 46 | public long getItemId(int position) { 47 | return courseList.get(position).getId(); 48 | } 49 | 50 | @Override 51 | public View getView(int position, View convertView, ViewGroup parent) { 52 | ViewHolder holder = null; 53 | if(null == convertView){ 54 | convertView = layoutInflater.inflate(R.layout.lession_item, null); 55 | holder = new ViewHolder(); 56 | holder.ivDel = convertView.findViewById(R.id.ivDel); 57 | holder.tvDay = convertView.findViewById(R.id.tvDay); 58 | holder.tvSection = convertView.findViewById(R.id.tvSection); 59 | holder.tvWeekType = convertView.findViewById(R.id.tvWeekType); 60 | holder.tvClassroom = convertView.findViewById(R.id.tvClassroom); 61 | holder.ivDel.setTag(courseList.get(position)); 62 | holder.ivDel.setOnClickListener(listener); 63 | convertView.setTag(holder); 64 | }else{ 65 | holder = (ViewHolder) convertView.getTag(); 66 | } 67 | setContent(position, holder); 68 | return convertView; 69 | } 70 | 71 | private void setContent(int i, ViewHolder view){ 72 | view.tvDay.setText(String.format("星期%d", courseList.get(i).getDay())); 73 | view.tvSection.setText(String.format("第%s节课", courseList.get(i).getSection())); 74 | String weekType = courseList.get(i).getWeekType(); 75 | if("s".equals(weekType)){ 76 | view.tvWeekType.setText("单周"); 77 | }else if("d".equals(weekType)){ 78 | view.tvWeekType.setText("双周"); 79 | }else{ 80 | view.tvWeekType.setText("正常周次"); 81 | } 82 | view.tvClassroom.setText(String.valueOf(courseList.get(i).getClassroom())); 83 | } 84 | 85 | static class ViewHolder{ 86 | TextView tvDay; 87 | TextView tvSection; 88 | TextView tvWeekType; 89 | TextView tvClassroom; 90 | ImageView ivDel; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /app/src/main/res/layout/add_course_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 11 | 12 | 16 | 21 | 28 | 29 | 30 | 34 | 39 | 46 | 47 | 48 | 49 | 53 | 54 | 59 | 67 | 68 | 73 | 81 | 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /app/src/main/res/layout/lession_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 16 | 17 | 21 | 26 | 34 | 42 | 47 | 48 | 49 | 53 | 58 | 66 | 67 | 68 | 69 | 73 | 78 | 85 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | xmlns:android 14 | 15 | ^$ 16 | 17 | 18 | 19 |
20 |
21 | 22 | 23 | 24 | xmlns:.* 25 | 26 | ^$ 27 | 28 | 29 | BY_NAME 30 | 31 |
32 |
33 | 34 | 35 | 36 | .*:id 37 | 38 | http://schemas.android.com/apk/res/android 39 | 40 | 41 | 42 |
43 |
44 | 45 | 46 | 47 | .*:name 48 | 49 | http://schemas.android.com/apk/res/android 50 | 51 | 52 | 53 |
54 |
55 | 56 | 57 | 58 | name 59 | 60 | ^$ 61 | 62 | 63 | 64 |
65 |
66 | 67 | 68 | 69 | style 70 | 71 | ^$ 72 | 73 | 74 | 75 |
76 |
77 | 78 | 79 | 80 | .* 81 | 82 | ^$ 83 | 84 | 85 | BY_NAME 86 | 87 |
88 |
89 | 90 | 91 | 92 | .* 93 | 94 | http://schemas.android.com/apk/res/android 95 | 96 | 97 | ANDROID_ATTRIBUTE_ORDER 98 | 99 |
100 |
101 | 102 | 103 | 104 | .* 105 | 106 | .* 107 | 108 | 109 | BY_NAME 110 | 111 |
112 |
113 |
114 |
115 |
116 |
-------------------------------------------------------------------------------- /app/src/main/res/layout/add_lesson_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 12 | 13 | 17 | 22 | 31 | 40 | 41 | 42 | 46 | 51 | 56 | 64 | 72 | 80 | 81 | 82 | 83 | 84 | 88 | 93 | 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /app/src/main/java/com/hemou/curriculum/dao/CourseDao.java: -------------------------------------------------------------------------------- 1 | package com.hemou.curriculum.dao; 2 | 3 | import android.content.ContentValues; 4 | import android.content.Context; 5 | import android.database.Cursor; 6 | import android.database.sqlite.SQLiteDatabase; 7 | import android.database.sqlite.SQLiteOpenHelper; 8 | import android.text.TextUtils; 9 | 10 | import androidx.annotation.NonNull; 11 | 12 | import com.hemou.curriculum.pojo.Course; 13 | 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | 17 | public class CourseDao extends SQLiteOpenHelper { 18 | 19 | private String tableName = "t_course"; 20 | 21 | public CourseDao(Context context){ 22 | super(context, "timetable.db", null, 1); 23 | } 24 | 25 | @Override 26 | public void onCreate(SQLiteDatabase db) { 27 | String sql = "create table t_course(" + 28 | "_id integer primary key autoincrement," + 29 | "courseName varchar(50)," + 30 | "teacherName varchar(50)," + 31 | "classroom varchar(50), " + 32 | "weekType varchar(50), " + 33 | "day integer," + 34 | "section integer," + 35 | "startWeek integer," + 36 | "endWeek integer," + 37 | "courseTime varchar(255)" + 38 | ")"; 39 | db.execSQL(sql); 40 | } 41 | 42 | public long insert(String nullColumnHack, ContentValues values){ 43 | SQLiteDatabase database = getWritableDatabase(); 44 | long count = database.insert(tableName, nullColumnHack, values); 45 | database.close(); 46 | return count; 47 | } 48 | 49 | public long insert(@NonNull Course course){ 50 | SQLiteDatabase database = getWritableDatabase(); 51 | ContentValues values = new ContentValues(); 52 | if(!TextUtils.isEmpty(course.getCourseName())){ 53 | values.put("courseName", course.getCourseName()); 54 | } 55 | if(!TextUtils.isEmpty(course.getTeacherName())){ 56 | values.put("teacherName", course.getTeacherName()); 57 | } 58 | if(!TextUtils.isEmpty(course.getCourseTime())) { 59 | values.put("courseTime", course.getCourseTime()); 60 | } 61 | if(course.getStartWeek() != 0) { 62 | values.put("startWeek", course.getStartWeek()); 63 | } 64 | if(course.getEndWeek() != 0) { 65 | values.put("endWeek", course.getEndWeek()); 66 | } 67 | long count = database.insert(tableName, null, values); 68 | database.close(); 69 | return count; 70 | } 71 | 72 | public int delete(String whereClause, String[] whereArgs){ 73 | SQLiteDatabase database = getWritableDatabase(); 74 | int count = database.delete(tableName, whereClause, whereArgs); 75 | database.close(); 76 | return count; 77 | } 78 | 79 | public int delete(int id){ 80 | SQLiteDatabase database = getWritableDatabase(); 81 | int count = database.delete(tableName, "_id=?", new String[]{String.valueOf(id)}); 82 | database.close(); 83 | return count; 84 | } 85 | 86 | public int update(ContentValues values, String whereClause, String[] whereArgs){ 87 | SQLiteDatabase database = getWritableDatabase(); 88 | int count = database.update(tableName, values, whereClause, whereArgs); 89 | database.close(); 90 | return count; 91 | } 92 | 93 | public int update(Course course){ 94 | SQLiteDatabase database = getWritableDatabase(); 95 | ContentValues values = new ContentValues(); 96 | if(!TextUtils.isEmpty(course.getCourseName())){ 97 | values.put("courseName", course.getCourseName()); 98 | } 99 | if(!TextUtils.isEmpty(course.getTeacherName())){ 100 | values.put("teacherName", course.getTeacherName()); 101 | } 102 | if(null != course.getCourseTime()) { 103 | values.put("courseTime", course.getCourseTime()); 104 | } 105 | if(course.getStartWeek() != 0) { 106 | values.put("startWeek", course.getStartWeek()); 107 | } 108 | if(course.getEndWeek() != 0) { 109 | values.put("endWeek", course.getEndWeek()); 110 | } 111 | int count = database.update(tableName, values, "_id=?", new String[]{String.valueOf(course.getId())}); 112 | database.close(); 113 | return count; 114 | } 115 | 116 | public List listAll(){ 117 | List list = new ArrayList<>(); 118 | SQLiteDatabase database = getWritableDatabase(); 119 | Cursor data = database.query(tableName, null, null, null, null, null, null); 120 | if(data.getCount() > 0){ 121 | while(data.moveToNext()) { 122 | Course course = new Course(); 123 | course.setId(data.getInt(0)); 124 | course.setCourseName(data.getString(1)); 125 | course.setTeacherName(data.getString(2)); 126 | course.setClassroom(data.getString(3)); 127 | course.setWeekType(data.getString(4)); 128 | course.setDay(data.getInt(5)); 129 | course.setSection(data.getInt(6)); 130 | course.setStartWeek(data.getInt(7)); 131 | course.setEndWeek(data.getInt(8)); 132 | course.setCourseTime(data.getString(9)); 133 | list.add(course); 134 | } 135 | } 136 | database.close(); 137 | return list; 138 | } 139 | 140 | @Override 141 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 142 | 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /app/src/main/java/com/hemou/curriculum/pojo/Course.java: -------------------------------------------------------------------------------- 1 | package com.hemou.curriculum.pojo; 2 | 3 | import android.text.TextUtils; 4 | 5 | import java.io.Serializable; 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | import java.util.Objects; 9 | 10 | public class Course implements Cloneable, Serializable { 11 | private int id; 12 | private String courseName;//课程名 13 | private String teacherName;//教师名 14 | //格式:星期-节次-单双周-房号 15 | private String courseTime;//上课时间 16 | private int startWeek;//开始周次 17 | private int endWeek;//结束周次 18 | 19 | private String classroom;//教室 20 | private String weekType;//单双周类型 21 | private int day;//星期几 22 | private int section;//节次 23 | 24 | 25 | public Course() { 26 | } 27 | 28 | public Course(String courseName, String teacherName, int startWeek, int endWeek, String courseTime) { 29 | this.courseName = courseName; 30 | this.teacherName = teacherName; 31 | this.courseTime = courseTime; 32 | this.startWeek = startWeek; 33 | this.endWeek = endWeek; 34 | } 35 | 36 | public String getWeekType() { 37 | return weekType; 38 | } 39 | 40 | public void setWeekType(String weekType) { 41 | this.weekType = weekType; 42 | } 43 | 44 | public int getId() { 45 | return id; 46 | } 47 | 48 | public void setId(int id) { 49 | this.id = id; 50 | } 51 | 52 | public String getCourseName() { 53 | return courseName; 54 | } 55 | 56 | public void setCourseName(String courseName) { 57 | this.courseName = courseName; 58 | } 59 | 60 | public String getTeacherName() { 61 | return teacherName; 62 | } 63 | 64 | public void setTeacherName(String teacherName) { 65 | this.teacherName = teacherName; 66 | } 67 | 68 | public int getDay() { 69 | return day; 70 | } 71 | 72 | public void setDay(int day) { 73 | this.day = day; 74 | } 75 | 76 | public int getSection() { 77 | return section; 78 | } 79 | 80 | public void setSection(int section) { 81 | this.section = section; 82 | } 83 | 84 | public String getCourseTime() { 85 | return courseTime; 86 | } 87 | 88 | public void setCourseTime(String courseTime) { 89 | this.courseTime = courseTime; 90 | } 91 | 92 | public int getStartWeek() { 93 | return startWeek; 94 | } 95 | 96 | public void setStartWeek(int startWeek) { 97 | this.startWeek = startWeek; 98 | } 99 | 100 | public int getEndWeek() { 101 | return endWeek; 102 | } 103 | 104 | public void setEndWeek(int endWeek) { 105 | this.endWeek = endWeek; 106 | } 107 | 108 | public String getClassroom() { 109 | return classroom; 110 | } 111 | 112 | public void setClassroom(String classroom) { 113 | this.classroom = classroom; 114 | } 115 | 116 | 117 | public Course clone() { 118 | try { 119 | return (Course) super.clone(); 120 | } catch (CloneNotSupportedException e) { 121 | throw new RuntimeException(e); 122 | } 123 | } 124 | 125 | @Override 126 | public String toString() { 127 | return "Course{" + 128 | "id=" + id + 129 | ", courseName='" + courseName + '\'' + 130 | ", teacherName='" + teacherName + '\'' + 131 | ", classroom='" + classroom + '\'' + 132 | ", weekType='" + weekType + '\'' + 133 | ", day=" + day + 134 | ", section=" + section + 135 | ", startWeek=" + startWeek + 136 | ", endWeek=" + endWeek + 137 | ", courseTime='" + courseTime + '\'' + 138 | '}'; 139 | } 140 | 141 | @Override 142 | public boolean equals(Object o) { 143 | if (this == o) return true; 144 | if (o == null || getClass() != o.getClass()) return false; 145 | Course course = (Course) o; 146 | return startWeek == course.startWeek && 147 | endWeek == course.endWeek && 148 | Objects.equals(courseName, course.courseName) && 149 | Objects.equals(teacherName, course.teacherName); 150 | } 151 | 152 | @Override 153 | public int hashCode() { 154 | return Objects.hash(courseName, teacherName, startWeek, endWeek); 155 | } 156 | 157 | public List toDetail() { 158 | List courseList = new ArrayList<>(); 159 | if (TextUtils.isEmpty(courseTime)) return courseList; 160 | String[] courseArray = courseTime.split(";"); 161 | for (int i = 0; i < courseArray.length; i++) { 162 | Course clone = this.clone(); 163 | String[] info = courseArray[i].split(":"); 164 | 165 | clone.setDay(Integer.parseInt(info[0])); 166 | clone.setSection(Integer.parseInt(info[1])); 167 | clone.setWeekType(info[2]); 168 | clone.setClassroom(info[3]); 169 | 170 | courseList.add(clone); 171 | } 172 | return courseList; 173 | } 174 | 175 | public String toTime(){ 176 | return String.format("%d:%d:%s:%s", day, section, weekType, classroom); 177 | } 178 | 179 | public static Course toCourse(List courseList, int id){ 180 | if(null == courseList)return null; 181 | Course course = new Course(); 182 | course.setId(id); 183 | StringBuffer sb = new StringBuffer(); 184 | for(int i = 0, len = courseList.size(); i < len; i++){ 185 | sb.append(courseList.get(i).toTime()); 186 | if(i != len - 1)sb.append(";"); 187 | } 188 | course.setCourseTime(String.valueOf(sb)); 189 | return course; 190 | } 191 | } 192 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/java/com/hemou/curriculum/activity/OptionActivity.java: -------------------------------------------------------------------------------- 1 | package com.hemou.curriculum.activity; 2 | 3 | import android.app.DatePickerDialog; 4 | import android.content.DialogInterface; 5 | import android.content.Intent; 6 | import android.content.SharedPreferences; 7 | import android.os.Bundle; 8 | import android.view.View; 9 | import android.widget.AdapterView; 10 | import android.widget.ArrayAdapter; 11 | import android.widget.DatePicker; 12 | import android.widget.EditText; 13 | import android.widget.ListView; 14 | import android.widget.Toast; 15 | 16 | import androidx.appcompat.app.AlertDialog; 17 | import androidx.appcompat.app.AppCompatActivity; 18 | 19 | import com.hemou.curriculum.R; 20 | import com.hemou.curriculum.dao.CourseDao; 21 | import com.hemou.curriculum.pojo.Course; 22 | 23 | import java.util.Calendar; 24 | import java.util.Date; 25 | import java.util.List; 26 | 27 | public class OptionActivity extends AppCompatActivity { 28 | 29 | private CourseDao courseDao = new CourseDao(this); 30 | 31 | private ListView lvContent; 32 | private List courseList; 33 | 34 | @Override 35 | protected void onCreate(Bundle savedInstanceState) { 36 | super.onCreate(savedInstanceState); 37 | setContentView(R.layout.activity_option); 38 | 39 | lvContent = findViewById(R.id.lvContent); 40 | lvContent.setOnItemClickListener(new AdapterView.OnItemClickListener() { 41 | @Override 42 | public void onItemClick(AdapterView parent, View view, int position, long id) { 43 | Course course = courseList.get(position); 44 | Intent intent = new Intent(OptionActivity.this, UpdateCourseActivity.class); 45 | intent.putExtra("course", course); 46 | startActivity(intent); 47 | } 48 | }); 49 | } 50 | 51 | @Override 52 | protected void onStart() { 53 | super.onStart(); 54 | show(); 55 | } 56 | 57 | /** 58 | * 所有课程 59 | */ 60 | private void show() { 61 | courseList = courseDao.listAll(); 62 | int listSize = courseList.size(); 63 | if (listSize > 0) { 64 | String[] courseNames = new String[listSize]; 65 | for (int i = 0; i < listSize; i++) courseNames[i] = courseList.get(i).getCourseName(); 66 | ArrayAdapter arrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, courseNames); 67 | lvContent.setAdapter(arrayAdapter); 68 | } else { 69 | Toast.makeText(this, "暂无数据,请添加课程!", Toast.LENGTH_SHORT).show(); 70 | } 71 | } 72 | 73 | /** 74 | * 返回 75 | * 76 | * @param view 77 | */ 78 | public void back(View view) { 79 | this.finish(); 80 | } 81 | 82 | /** 83 | * 添加课程 84 | * 85 | * @param view 86 | */ 87 | public void addCourse(View view) { 88 | final View inflate = getLayoutInflater().inflate(R.layout.add_course_item, null); 89 | new AlertDialog.Builder(this) 90 | .setView(inflate) 91 | .setPositiveButton("添加", new DialogInterface.OnClickListener() { 92 | @Override 93 | public void onClick(DialogInterface dialog, int which) { 94 | String courseName = ((EditText) inflate.findViewById(R.id.etCourseName)).getText().toString(); 95 | String teacherName = ((EditText) inflate.findViewById(R.id.etTeacherName)).getText().toString(); 96 | String startWeek = ((EditText) inflate.findViewById(R.id.etStartWeek)).getText().toString(); 97 | String endWeek = ((EditText) inflate.findViewById(R.id.etEndWeek)).getText().toString(); 98 | if ("".equals(courseName) || "".equals(startWeek) || "".equals(endWeek)) { 99 | Toast.makeText(OptionActivity.this, "课程名和周次信息不可为空!", Toast.LENGTH_SHORT).show(); 100 | } else { 101 | Course course = new Course(); 102 | course.setCourseName(courseName); 103 | course.setTeacherName(teacherName); 104 | course.setStartWeek(Integer.parseInt(startWeek)); 105 | course.setEndWeek(Integer.parseInt(endWeek)); 106 | long insert = courseDao.insert(course); 107 | if (insert != -1) { 108 | Toast.makeText(OptionActivity.this, "添加课程成功!", Toast.LENGTH_SHORT).show(); 109 | show(); 110 | }else{ 111 | Toast.makeText(OptionActivity.this, "添加失败!", Toast.LENGTH_SHORT).show(); 112 | } 113 | } 114 | } 115 | }) 116 | .setNegativeButton("取消", null) 117 | .create() 118 | .show(); 119 | } 120 | 121 | /** 122 | * 修改开学时间 123 | * @param view 124 | */ 125 | public void alterDate(View view) { 126 | final SharedPreferences config = getSharedPreferences("config", MODE_PRIVATE); 127 | final DatePicker datePicker = new DatePicker(this); 128 | long date = config.getLong("date", 0); 129 | if(date != 0){ 130 | Calendar c = Calendar.getInstance(); 131 | c.setTime(new Date(date)); 132 | datePicker.init(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DATE), null); 133 | } 134 | new DatePickerDialog.Builder(this) 135 | .setTitle("选择开学日期") 136 | .setView(datePicker) 137 | .setPositiveButton("确定", new DialogInterface.OnClickListener() { 138 | @Override 139 | public void onClick(DialogInterface dialog, int which) { 140 | int year = datePicker.getYear(); 141 | int month = datePicker.getMonth(); 142 | int dayOfMonth = datePicker.getDayOfMonth(); 143 | Calendar calendar = Calendar.getInstance(); 144 | calendar.set(year, month, dayOfMonth, 0, 0, 0); 145 | Date time = calendar.getTime(); 146 | config.edit().putLong("date", time.getTime()).apply(); 147 | } 148 | }) 149 | .setNegativeButton("取消", null) 150 | .create() 151 | .show(); 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_update_course.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 13 | 18 | 24 | 30 | 37 | 38 | 39 | 45 | 46 | 47 | 50 | 54 | 55 | 56 | 64 | 65 | 69 | 74 | 81 | 82 | 83 | 87 | 92 | 99 | 100 | 101 | 102 | 106 | 107 | 112 | 120 | 121 | 126 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 145 | 151 | 152 | 153 | 154 | 164 | 174 | 184 | 185 | 186 | 187 | 188 | 189 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /app/src/main/java/com/hemou/curriculum/activity/UpdateCourseActivity.java: -------------------------------------------------------------------------------- 1 | package com.hemou.curriculum.activity; 2 | 3 | import android.content.DialogInterface; 4 | import android.os.Bundle; 5 | import android.text.TextUtils; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.EditText; 9 | import android.widget.ListAdapter; 10 | import android.widget.ListView; 11 | import android.widget.RadioGroup; 12 | import android.widget.TextView; 13 | import android.widget.Toast; 14 | 15 | import androidx.appcompat.app.AlertDialog; 16 | import androidx.appcompat.app.AppCompatActivity; 17 | 18 | import com.hemou.curriculum.R; 19 | import com.hemou.curriculum.adapter.LessonAdapter; 20 | import com.hemou.curriculum.dao.CourseDao; 21 | import com.hemou.curriculum.pojo.Course; 22 | 23 | import java.util.Iterator; 24 | import java.util.List; 25 | 26 | public class UpdateCourseActivity extends AppCompatActivity { 27 | 28 | private CourseDao courseDao = new CourseDao(this); 29 | private ListView mListView; 30 | private Course course; 31 | 32 | @Override 33 | protected void onCreate(Bundle savedInstanceState) { 34 | super.onCreate(savedInstanceState); 35 | setContentView(R.layout.activity_update_course); 36 | mListView = findViewById(R.id.lvLesson); 37 | 38 | course = (Course) getIntent().getSerializableExtra("course"); 39 | showLessonInfo(); 40 | showCourseInfo(); 41 | } 42 | 43 | /** 44 | * 显示课程信息 45 | */ 46 | private void showCourseInfo() { 47 | ((TextView) findViewById(R.id.tvCourseName)).setText(course.getCourseName()); 48 | ((EditText) findViewById(R.id.etCourseName)).setText(course.getCourseName()); 49 | ((EditText) findViewById(R.id.etTeacherName)).setText(course.getTeacherName()); 50 | ((EditText) findViewById(R.id.etStartWeek)).setText(String.valueOf(course.getStartWeek())); 51 | ((EditText) findViewById(R.id.etEndWeek)).setText(String.valueOf(course.getEndWeek())); 52 | } 53 | 54 | /** 55 | * 显示课次信息 56 | */ 57 | private void showLessonInfo() { 58 | List courseList = course.toDetail(); 59 | if (courseList == null) return; 60 | LessonAdapter adapter = new LessonAdapter(this, courseList, new DeleteListener(courseList)); 61 | mListView.setAdapter(adapter); 62 | setListViewHeight(mListView); 63 | } 64 | 65 | private class DeleteListener implements View.OnClickListener { 66 | 67 | private List courseList; 68 | public DeleteListener(List courseList){ 69 | this.courseList = courseList; 70 | } 71 | 72 | @Override 73 | public void onClick(final View v) { 74 | new AlertDialog.Builder(UpdateCourseActivity.this) 75 | .setTitle("删除课次") 76 | .setPositiveButton("确定删除", new DialogInterface.OnClickListener() { 77 | @Override 78 | public void onClick(DialogInterface dialog, int which) { 79 | deleteLesson(v, courseList); 80 | } 81 | }) 82 | .setNegativeButton("取消", null) 83 | .create() 84 | .show(); 85 | 86 | } 87 | } 88 | 89 | private void deleteLesson(View v, List courseList){ 90 | Course course = (Course) v.getTag(); 91 | Iterator iterator = courseList.iterator(); 92 | while (iterator.hasNext()) { 93 | Course c = iterator.next(); 94 | if (c.getDay() == course.getDay() && 95 | c.getSection() == course.getSection() && 96 | c.getWeekType().equals(course.getWeekType()) && 97 | c.getClassroom().equals(course.getClassroom())) { 98 | iterator.remove(); 99 | break; 100 | } 101 | } 102 | Course toCourse = Course.toCourse(courseList, UpdateCourseActivity.this.course.getId()); 103 | if (null != toCourse) { 104 | int update = courseDao.update(toCourse); 105 | if (update > 0) { 106 | String time = toCourse.getCourseTime(); 107 | UpdateCourseActivity.this.course.setCourseTime(time); 108 | Toast.makeText(UpdateCourseActivity.this, "删除成功!", Toast.LENGTH_SHORT).show(); 109 | showLessonInfo(); 110 | return; 111 | } 112 | } 113 | Toast.makeText(UpdateCourseActivity.this, "删除失败!", Toast.LENGTH_SHORT).show(); 114 | } 115 | 116 | /** 117 | * 设置ListView高度 118 | * 119 | * @param listView 120 | */ 121 | public void setListViewHeight(ListView listView) { 122 | ListAdapter listAdapter = listView.getAdapter(); 123 | if (listAdapter == null) { 124 | return; 125 | } 126 | //总高度 127 | int totalHeight = 0; 128 | //测量并累加高度 129 | int count = listAdapter.getCount(); 130 | if (count > 0) { 131 | View listItem = listAdapter.getView(0, null, listView); 132 | listItem.measure(0, 0); 133 | totalHeight += listItem.getMeasuredHeight() * count; 134 | } 135 | //设置高度 136 | ViewGroup.LayoutParams params = listView.getLayoutParams(); 137 | params.height = totalHeight; 138 | listView.setLayoutParams(params); 139 | } 140 | 141 | /** 142 | * 返回 143 | * 144 | * @param view 145 | */ 146 | public void back(View view) { 147 | this.finish(); 148 | } 149 | 150 | /** 151 | * 添加课次 152 | * 153 | * @param view 154 | */ 155 | public void addLesson(View view) { 156 | final View inflate = getLayoutInflater().inflate(R.layout.add_lesson_item, null); 157 | new AlertDialog.Builder(this) 158 | .setTitle("添加课次") 159 | .setView(inflate) 160 | .setPositiveButton("添加", new DialogInterface.OnClickListener() { 161 | @Override 162 | public void onClick(DialogInterface dialog, int which) { 163 | //封装信息 164 | Course course = new Course(); 165 | //星期 166 | String day = ((EditText) inflate.findViewById(R.id.tvDay)).getText().toString(); 167 | if (!TextUtils.isEmpty(day)) { 168 | course.setDay(Integer.parseInt(day)); 169 | } else { 170 | Toast.makeText(UpdateCourseActivity.this, "星期不可为空!", Toast.LENGTH_SHORT).show(); 171 | return; 172 | } 173 | //节次 174 | String section = ((EditText) inflate.findViewById(R.id.tvSection)).getText().toString(); 175 | if (!TextUtils.isEmpty(section)) { 176 | course.setSection(Integer.parseInt(section)); 177 | } else { 178 | Toast.makeText(UpdateCourseActivity.this, "节次不可为空!", Toast.LENGTH_SHORT).show(); 179 | return; 180 | } 181 | //单双周 182 | int rbId = ((RadioGroup) inflate.findViewById(R.id.rgWeekType)).getCheckedRadioButtonId(); 183 | if (R.id.rbSingleWeek == rbId) { 184 | course.setWeekType("s"); 185 | } else if (R.id.rbNormalWeek == rbId) { 186 | course.setWeekType("n"); 187 | } else if (R.id.rbDoubleWeek == rbId) { 188 | course.setWeekType("d"); 189 | } else { 190 | Toast.makeText(UpdateCourseActivity.this, "周类型尚未选择!", Toast.LENGTH_SHORT).show(); 191 | return; 192 | } 193 | //教室 194 | String classroom = ((EditText) inflate.findViewById(R.id.tvClassroom)).getText().toString(); 195 | if (!TextUtils.isEmpty(classroom)) { 196 | course.setClassroom(classroom); 197 | } else { 198 | Toast.makeText(UpdateCourseActivity.this, "教室尚未填写!", Toast.LENGTH_SHORT).show(); 199 | return; 200 | } 201 | //组装上课时间 202 | String courseTime = UpdateCourseActivity.this.course.getCourseTime(); 203 | int id = UpdateCourseActivity.this.course.getId(); 204 | if (TextUtils.isEmpty(courseTime)) { 205 | course.setCourseTime(course.toTime()); 206 | } else { 207 | course.setCourseTime(courseTime + ";" + course.toTime()); 208 | } 209 | course.setId(id); 210 | //修改 211 | int update = courseDao.update(course); 212 | if (update > 0) { 213 | UpdateCourseActivity.this.course.setCourseTime(course.getCourseTime()); 214 | Toast.makeText(UpdateCourseActivity.this, "添加成功!", Toast.LENGTH_SHORT).show(); 215 | showLessonInfo(); 216 | } else { 217 | Toast.makeText(UpdateCourseActivity.this, "添加失败!", Toast.LENGTH_SHORT).show(); 218 | } 219 | } 220 | }) 221 | .setNegativeButton("取消", null) 222 | .create() 223 | .show(); 224 | } 225 | 226 | /** 227 | * @param view 228 | */ 229 | public void delCourse(View view) { 230 | new AlertDialog.Builder(this) 231 | .setTitle("删除课程") 232 | .setPositiveButton("确定删除", new DialogInterface.OnClickListener() { 233 | @Override 234 | public void onClick(DialogInterface dialog, int which) { 235 | int delete = courseDao.delete(course.getId()); 236 | if (delete > 0) { 237 | Toast.makeText(UpdateCourseActivity.this, "删除成功!", Toast.LENGTH_SHORT).show(); 238 | UpdateCourseActivity.this.finish(); 239 | } else { 240 | Toast.makeText(UpdateCourseActivity.this, "删除失败!", Toast.LENGTH_SHORT).show(); 241 | } 242 | } 243 | }) 244 | .setNegativeButton("取消", null) 245 | .create() 246 | .show(); 247 | } 248 | 249 | /** 250 | * 保存修改 251 | * 252 | * @param view 253 | */ 254 | public void save(View view) { 255 | //封装信息 256 | Course course = new Course(); 257 | //id 258 | course.setId(this.course.getId()); 259 | //课程名 260 | String courseName = ((EditText) findViewById(R.id.etCourseName)).getText().toString(); 261 | if (!TextUtils.isEmpty(courseName)) { 262 | course.setCourseName(courseName); 263 | } 264 | //老师名 265 | String teacherName = ((EditText) findViewById(R.id.etTeacherName)).getText().toString(); 266 | if (!TextUtils.isEmpty(teacherName)) { 267 | course.setTeacherName(teacherName); 268 | } 269 | course.setStartWeek(Integer.parseInt(((EditText) findViewById(R.id.etStartWeek)).getText().toString())); 270 | course.setEndWeek(Integer.parseInt(((EditText) findViewById(R.id.etEndWeek)).getText().toString())); 271 | if (this.course.equals(course)) { 272 | Toast.makeText(this, "您尚未修改课程信息\n无需保存!", Toast.LENGTH_SHORT).show(); 273 | } else { 274 | int update = courseDao.update(course); 275 | if (update > 0) { 276 | Toast.makeText(this, "修改成功!", Toast.LENGTH_SHORT).show(); 277 | } else { 278 | Toast.makeText(this, "修改失败!", Toast.LENGTH_SHORT).show(); 279 | } 280 | } 281 | } 282 | } 283 | -------------------------------------------------------------------------------- /app/src/main/java/com/hemou/curriculum/view/TimeTableView.java: -------------------------------------------------------------------------------- 1 | package com.hemou.curriculum.view; 2 | 3 | import android.content.Context; 4 | import android.graphics.Color; 5 | import android.text.TextUtils; 6 | import android.util.AttributeSet; 7 | import android.view.Gravity; 8 | import android.view.MotionEvent; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.widget.ImageView; 12 | import android.widget.LinearLayout; 13 | import android.widget.RelativeLayout; 14 | import android.widget.TextView; 15 | 16 | import androidx.annotation.Nullable; 17 | 18 | import com.hemou.curriculum.pojo.Course; 19 | import com.hemou.curriculum.R; 20 | 21 | import java.lang.reflect.InvocationTargetException; 22 | import java.lang.reflect.Method; 23 | import java.util.ArrayList; 24 | import java.util.Collections; 25 | import java.util.Comparator; 26 | import java.util.Date; 27 | import java.util.HashMap; 28 | import java.util.List; 29 | import java.util.Map; 30 | 31 | public class TimeTableView extends LinearLayout { 32 | 33 | //星期 34 | private String[] weekTitle = {"一", "二", "三", "四", "五", "六", "七"}; 35 | //最大星期数 36 | private int weeksNum = weekTitle.length; 37 | //最大节数 38 | private int maxSection = 9; 39 | 40 | //圆角半径 41 | private int radius = 8; 42 | //线宽 43 | private int tableLineWidth = 1; 44 | //数字字体大小 45 | private int numberSize = 14; 46 | //标题字体大小 47 | private int titleSize = 18; 48 | //课表信息字体大小 49 | private int courseSize = 12; 50 | //底部按钮大小 51 | private int buttonSize = 12; 52 | 53 | //单元格高度 54 | private int cellHeight = 75; 55 | //星期标题高度 56 | private int titleHeight = 30; 57 | //最左边数字宽度 58 | private int numberWidth = 20; 59 | 60 | private Context mContext; 61 | private List courseList; 62 | private Map colorMap = new HashMap<>(); 63 | private Map> courseMap = new HashMap<>(); 64 | 65 | //开学日期 66 | private Date startDate; 67 | private long weekNum; 68 | 69 | //菜单栏 70 | private ImageView mCategory; 71 | //周次信息 72 | private TextView mWeekTitle; 73 | private LinearLayout mMainLayout; 74 | private RelativeLayout mTitleLayout; 75 | 76 | private int currentX; 77 | 78 | public TimeTableView(Context context) { 79 | super(context); 80 | this.mContext = context; 81 | initView(); 82 | } 83 | 84 | public TimeTableView(Context context, @Nullable AttributeSet attrs) { 85 | super(context, attrs); 86 | this.mContext = context; 87 | initView(); 88 | } 89 | 90 | /** 91 | * 初始化/修改默认参数 92 | * 93 | * @param params 参数 94 | */ 95 | public void initParams(Map params) { 96 | if (!params.isEmpty()) { 97 | try { 98 | for (String key : params.keySet()) { 99 | Class timeTableClass = TimeTableView.class; 100 | String methodName = "set" + key.substring(0, 1).toUpperCase() + key.substring(1); 101 | Method method = timeTableClass.getDeclaredMethod(methodName, int.class); 102 | method.invoke(this, params.get(key)); 103 | } 104 | } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { 105 | e.printStackTrace(); 106 | } 107 | } 108 | preprocessorParam(); 109 | } 110 | 111 | /** 112 | * 数据预处理 113 | */ 114 | private void preprocessorParam() { 115 | tableLineWidth = dip2px(tableLineWidth); 116 | cellHeight = dip2px(cellHeight); 117 | titleHeight = dip2px(titleHeight); 118 | numberWidth = dip2px(numberWidth); 119 | } 120 | 121 | /** 122 | * 设置菜单按钮的监听事件 123 | * @param listener 124 | */ 125 | public void addListener(OnClickListener listener){ 126 | mCategory.setOnClickListener(listener); 127 | } 128 | 129 | /** 130 | * 加载数据 131 | * 132 | * @param courses 133 | */ 134 | public void loadData(List courses, Date date) { 135 | this.courseList = courses; 136 | this.startDate = date; 137 | weekNum = calcWeek(startDate); 138 | handleData(courseMap, courses, weekNum); 139 | flushView(courseMap, weekNum); 140 | } 141 | 142 | /** 143 | * 处理数据 144 | * @param courseMap 处理结果 145 | * @param courseList 数据 146 | * @param weekNum 周次 147 | */ 148 | private void handleData(Map> courseMap, List courseList, long weekNum) { 149 | courseMap.clear(); 150 | for (Course c : courseList) { 151 | if (c.getStartWeek() > weekNum || c.getEndWeek() < weekNum) continue; 152 | String courseTime = c.getCourseTime(); 153 | if(TextUtils.isEmpty(courseTime))continue; 154 | String[] courseArray = courseTime.split(";"); 155 | for (int i = 0; i < courseArray.length; i++) { 156 | Course clone = c.clone(); 157 | String[] info = courseArray[i].split(":"); 158 | if ("n".equals(info[2]) || weekNum % 2 == 0 && "d".equals(info[2]) || weekNum % 2 == 1 && "s".equals(info[2])) {//非单双周 159 | clone.setDay(Integer.parseInt(info[0])); 160 | clone.setSection(Integer.parseInt(info[1])); 161 | clone.setClassroom(info[3]); 162 | 163 | List courses = courseMap.get(clone.getDay()); 164 | if (null == courses) { 165 | courses = new ArrayList<>(); 166 | courseMap.put(clone.getDay(), courses); 167 | } 168 | courses.add(clone); 169 | } 170 | } 171 | } 172 | } 173 | 174 | /** 175 | * 初始化视图 176 | */ 177 | private void initView(){ 178 | preprocessorParam(); 179 | //周次标题 180 | addWeekTitle(this); 181 | //星期标签 182 | addWeekLabel(this); 183 | //课程信息 184 | flushView(null, weekNum); 185 | } 186 | 187 | /** 188 | * 刷新课程视图 189 | * @param courseMap 课程数据 190 | * @param weekNum 周次 191 | */ 192 | private void flushView(Map> courseMap, long weekNum) { 193 | //初始化主布局 194 | if (null != mMainLayout) removeView(mMainLayout); 195 | mMainLayout = new LinearLayout(mContext); 196 | mMainLayout.setOrientation(HORIZONTAL); 197 | mMainLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); 198 | addView(mMainLayout); 199 | //周次标题 200 | mWeekTitle.setText("第 " + weekNum + " 周"); 201 | //左侧节次标签 202 | addLeftNumber(mMainLayout); 203 | //课程信息 204 | if (null == courseMap || courseMap.isEmpty()) {//数据为空 205 | addVerticalTableLine(mMainLayout); 206 | TextView emptyLayoutTextView = createTextView("已结课,或未添加课程信息!", titleSize, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 0, getResources().getColor(R.color.textColor), Color.WHITE); 207 | mMainLayout.addView(emptyLayoutTextView); 208 | } else {//不为空 209 | for (int i = 1; i <= weeksNum; i++) { 210 | addVerticalTableLine(mMainLayout); 211 | addDayCourse(mMainLayout, courseMap, i); 212 | } 213 | } 214 | invalidate(); 215 | } 216 | 217 | /** 218 | * 周次标题 219 | * 220 | * @param pViewGroup 221 | */ 222 | private void addWeekTitle(ViewGroup pViewGroup) { 223 | mTitleLayout = new RelativeLayout(mContext); 224 | mTitleLayout.setPadding(8, 15, 8, 15); 225 | mTitleLayout.setBackgroundColor(getResources().getColor(R.color.titleColor)); 226 | //周次信息 227 | mWeekTitle = new TextView(mContext); 228 | mWeekTitle.setTextSize(titleSize); 229 | mWeekTitle.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); 230 | mWeekTitle.setGravity(Gravity.CENTER_HORIZONTAL); 231 | mTitleLayout.addView(mWeekTitle); 232 | //左侧菜单栏 233 | mCategory = new ImageView(mContext); 234 | mCategory.setImageResource(R.drawable.category); 235 | mCategory.setLayoutParams(new LayoutParams(dip2px(30), dip2px(30))); 236 | mTitleLayout.addView(mCategory); 237 | 238 | pViewGroup.addView(mTitleLayout); 239 | addHorizontalTableLine(pViewGroup); 240 | } 241 | 242 | /** 243 | * 添加星期标签 244 | */ 245 | private void addWeekLabel(ViewGroup pViewGroup) { 246 | LinearLayout mTitleLayout = new LinearLayout(mContext); 247 | mTitleLayout.setOrientation(HORIZONTAL); 248 | mTitleLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, titleHeight)); 249 | addView(mTitleLayout); 250 | //空白符 251 | TextView space = new TextView(mContext); 252 | space.setLayoutParams(new ViewGroup.LayoutParams(numberWidth, ViewGroup.LayoutParams.MATCH_PARENT)); 253 | space.setBackgroundColor(getResources().getColor(R.color.titleColor)); 254 | mTitleLayout.addView(space); 255 | //星期 256 | for (int i = 0; i < weeksNum; i++) { 257 | addVerticalTableLine(mTitleLayout); 258 | TextView title = createTextView(weekTitle[i], titleSize, 0, ViewGroup.LayoutParams.MATCH_PARENT, 1, getResources().getColor(R.color.textColor), getResources().getColor(R.color.titleColor)); 259 | mTitleLayout.addView(title); 260 | } 261 | } 262 | 263 | /** 264 | * 添加左侧节次数字 265 | */ 266 | private void addLeftNumber(ViewGroup pViewGroup) { 267 | LinearLayout leftLayout = new LinearLayout(mContext); 268 | leftLayout.setOrientation(VERTICAL); 269 | leftLayout.setLayoutParams(new LayoutParams(numberWidth, ViewGroup.LayoutParams.WRAP_CONTENT)); 270 | for (int i = 1; i <= maxSection; i++) { 271 | addHorizontalTableLine(leftLayout); 272 | TextView number = createTextView(String.valueOf(i), numberSize, ViewGroup.LayoutParams.MATCH_PARENT, cellHeight, 1, getResources().getColor(R.color.textColor), Color.WHITE); 273 | leftLayout.addView(number); 274 | } 275 | pViewGroup.addView(leftLayout); 276 | } 277 | 278 | /** 279 | * 添加单天课程 280 | * 281 | * @param pViewGroup pViewGroup 父组件 282 | * @param day 星期 283 | */ 284 | private void addDayCourse(ViewGroup pViewGroup, Map> courseMap, int day) { 285 | LinearLayout linearLayout = new LinearLayout(mContext); 286 | linearLayout.setLayoutParams(new LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1)); 287 | linearLayout.setOrientation(VERTICAL); 288 | List courses = getCourses(courseMap, day); 289 | if (null != courses) { 290 | for (int i = 0, size = courses.size(); i < size; i++) { 291 | Course course = courses.get(i); 292 | int section = course.getSection(); 293 | if (i == 0) addBlankCell(linearLayout, section - 1); 294 | else 295 | addBlankCell(linearLayout, course.getSection() - courses.get(i - 1).getSection() - 2); 296 | addCourseCell(linearLayout, course); 297 | if (i == size - 1) addBlankCell(linearLayout, maxSection - section - 1); 298 | } 299 | } else { 300 | addBlankCell(linearLayout, maxSection); 301 | } 302 | pViewGroup.addView(linearLayout); 303 | } 304 | 305 | /** 306 | * 获取单天课程信息 307 | * 308 | * @param day 星期 309 | * @return 课程信息List 310 | */ 311 | public List getCourses(Map> courseMap, int day) { 312 | final List courses = courseMap.get(day); 313 | if (null != courses) { 314 | Collections.sort(courses, new Comparator() { 315 | @Override 316 | public int compare(Course o1, Course o2) { 317 | return o1.getSection() - o2.getSection(); 318 | } 319 | }); 320 | } 321 | return courses; 322 | } 323 | 324 | /** 325 | * 添加课程单元格 326 | * @param pViewGroup 父组件 327 | * @param course 课程信息 328 | */ 329 | private void addCourseCell(ViewGroup pViewGroup, Course course) { 330 | addHorizontalTableLine(pViewGroup); 331 | RoundTextView textView = new RoundTextView(mContext, radius, getColor(colorMap, course.getCourseName())); 332 | textView.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, cellHeight * 2 + tableLineWidth)); 333 | textView.setTextSize(courseSize); 334 | textView.setTextColor(Color.WHITE); 335 | textView.setGravity(Gravity.CENTER); 336 | textView.setText(String.format("%s\n%s\n%d~%d周\n%s", course.getCourseName(), course.getTeacherName(), course.getStartWeek(), course.getEndWeek(), course.getClassroom())); 337 | pViewGroup.addView(textView); 338 | } 339 | 340 | 341 | /** 342 | * 添加空白块 343 | * 344 | * @param pViewGroup 父组件 345 | * @param num 空白块数量 346 | */ 347 | private void addBlankCell(ViewGroup pViewGroup, int num) { 348 | for (int i = 0; i < num; i++) { 349 | addHorizontalTableLine(pViewGroup); 350 | TextView blank = new TextView(mContext); 351 | blank.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, cellHeight)); 352 | pViewGroup.addView(blank); 353 | } 354 | } 355 | 356 | /** 357 | * 添加垂直线 358 | * 359 | * @param pViewGroup 父组件 360 | */ 361 | private void addVerticalTableLine(ViewGroup pViewGroup) { 362 | View view = new View(mContext); 363 | view.setLayoutParams(new ViewGroup.LayoutParams(tableLineWidth, ViewGroup.LayoutParams.MATCH_PARENT)); 364 | view.setBackgroundColor(getResources().getColor(R.color.viewLine)); 365 | pViewGroup.addView(view); 366 | } 367 | 368 | /** 369 | * 添加水平线 370 | * 371 | * @param pViewGroup 父组件 372 | */ 373 | private void addHorizontalTableLine(ViewGroup pViewGroup) { 374 | View view = new View(mContext); 375 | view.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, tableLineWidth)); 376 | view.setBackgroundColor(getResources().getColor(R.color.viewLine)); 377 | pViewGroup.addView(view); 378 | } 379 | 380 | /** 381 | * 创建TextView 382 | * 383 | * @param content 文本内容 384 | * @param color 字体颜色 385 | * @param size 字体大小 386 | * @param width 宽度 387 | * @param height 高度 388 | * @param weight 权重 389 | * @return 390 | */ 391 | private TextView createTextView(String content, int size, int width, int height, int weight, int color, int bkColor) { 392 | TextView textView = new TextView(mContext); 393 | textView.setLayoutParams(new LayoutParams(width, height, weight)); 394 | if(bkColor != -1)textView.setBackgroundColor(bkColor); 395 | textView.setTextColor(color); 396 | textView.setGravity(Gravity.CENTER); 397 | textView.setTextSize(size); 398 | textView.setText(content); 399 | return textView; 400 | } 401 | 402 | private void toggleWeek(int flag){ 403 | if(flag < 0){ 404 | weekNum = weekNum - 1 <= 0 ? weekNum : weekNum - 1; 405 | }else{ 406 | weekNum = weekNum + 1 > 19 ? weekNum : weekNum + 1; 407 | } 408 | handleData(courseMap, courseList, weekNum); 409 | flushView(courseMap, weekNum); 410 | } 411 | 412 | /** 413 | * 计算当前周次 414 | * @param date 415 | * @return 416 | */ 417 | private long calcWeek(Date date) { 418 | return (new Date().getTime() - date.getTime()) / (1000 * 3600 * 24 * 7) + 1; 419 | } 420 | 421 | private int getColor(Map map, String name) { 422 | Integer tip = map.get(name); 423 | if (null != tip) { 424 | return tip; 425 | } else { 426 | int i = getResources().getColor(color[map.size() % color.length]); 427 | map.put(name, i); 428 | return i; 429 | } 430 | } 431 | 432 | private int dip2px(float dpValue) { 433 | float scale = mContext.getResources().getDisplayMetrics().density; 434 | return (int) (dpValue * scale); 435 | } 436 | 437 | private int color[] = { 438 | R.color.one, R.color.two, R.color.three, 439 | R.color.four, R.color.five, R.color.six, 440 | R.color.seven, R.color.eight, R.color.nine, 441 | R.color.ten, R.color.eleven, R.color.twelve, 442 | R.color.thirteen, R.color.fourteen, R.color.fifteen 443 | }; 444 | 445 | @Override 446 | public boolean onTouchEvent(MotionEvent event) { 447 | switch (event.getAction()) { 448 | case MotionEvent.ACTION_DOWN: 449 | currentX = (int) event.getX(); 450 | break; 451 | case MotionEvent.ACTION_UP: 452 | int i = (int) event.getX() - currentX; 453 | if(i > 30){ 454 | toggleWeek(-1); 455 | }else if(i < -30){ 456 | toggleWeek(1); 457 | } 458 | break; 459 | } 460 | return true; 461 | } 462 | 463 | public void setMaxSection(int maxSection) { 464 | this.maxSection = maxSection; 465 | } 466 | 467 | public void setRadius(int radius) { 468 | this.radius = radius; 469 | } 470 | 471 | public void setTableLineWidth(int tableLineWidth) { 472 | this.tableLineWidth = tableLineWidth; 473 | } 474 | 475 | public void setNumberSize(int numberSize) { 476 | this.numberSize = numberSize; 477 | } 478 | 479 | public void setTitleSize(int titleSize) { 480 | this.titleSize = titleSize; 481 | } 482 | 483 | public void setCourseSize(int courseSize) { 484 | this.courseSize = courseSize; 485 | } 486 | 487 | public void setButtonSize(int buttonSize) { 488 | this.buttonSize = buttonSize; 489 | } 490 | 491 | public void setCellHeight(int cellHeight) { 492 | this.cellHeight = cellHeight; 493 | } 494 | 495 | public void setTitleHeight(int titleHeight) { 496 | this.titleHeight = titleHeight; 497 | } 498 | 499 | public void setNumberWidth(int numberWidth) { 500 | this.numberWidth = numberWidth; 501 | } 502 | } 503 | --------------------------------------------------------------------------------