├── .gitignore ├── .idea └── runConfigurations.xml ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── github │ │ └── tlaabs │ │ └── timetableviewdemo │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── github │ │ │ └── tlaabs │ │ │ └── timetableviewdemo │ │ │ ├── EditActivity.java │ │ │ └── MainActivity.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ ├── ic_kitty.xml │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ ├── activity_edit.xml │ │ ├── activity_main.xml │ │ ├── edit_appbar.xml │ │ └── time_box.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── 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 │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── github │ └── tlaabs │ └── timetableviewdemo │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── timetableview ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src ├── androidTest └── java │ └── com │ └── github │ └── tlaabs │ └── timetableview │ └── ExampleInstrumentedTest.java ├── main ├── AndroidManifest.xml ├── java │ └── com │ │ └── github │ │ └── tlaabs │ │ └── timetableview │ │ ├── HighlightMode.java │ │ ├── SaveManager.java │ │ ├── Schedule.java │ │ ├── Sticker.java │ │ ├── Time.java │ │ └── TimetableView.java └── res │ ├── drawable │ └── item_border.xml │ ├── layout │ ├── inner_table.xml │ ├── table_header.xml │ └── view_timetable.xml │ └── values │ ├── attrs_timetable.xml │ ├── colors.xml │ └── strings.xml └── test └── java └── com └── github └── tlaabs └── timetableview └── ExampleUnitTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/android,androidstudio 3 | # Edit at https://www.gitignore.io/?templates=android,androidstudio 4 | 5 | ### Android ### 6 | # Built application files 7 | *.apk 8 | *.ap_ 9 | *.aab 10 | 11 | # Files for the ART/Dalvik VM 12 | *.dex 13 | 14 | # Java class files 15 | *.class 16 | 17 | # Generated files 18 | bin/ 19 | gen/ 20 | out/ 21 | 22 | # Gradle files 23 | .gradle/ 24 | build/ 25 | 26 | # Local configuration file (sdk path, etc) 27 | local.properties 28 | 29 | # Proguard folder generated by Eclipse 30 | proguard/ 31 | 32 | # Log Files 33 | *.log 34 | 35 | # Android Studio Navigation editor temp files 36 | .navigation/ 37 | 38 | # Android Studio captures folder 39 | captures/ 40 | 41 | # IntelliJ 42 | *.iml 43 | .idea/workspace.xml 44 | .idea/tasks.xml 45 | .idea/gradle.xml 46 | .idea/assetWizardSettings.xml 47 | .idea/dictionaries 48 | .idea/libraries 49 | .idea/caches 50 | 51 | # Keystore files 52 | # Uncomment the following lines if you do not want to check your keystore files in. 53 | #*.jks 54 | #*.keystore 55 | 56 | # External native build folder generated in Android Studio 2.2 and later 57 | .externalNativeBuild 58 | 59 | # Google Services (e.g. APIs or Firebase) 60 | google-services.json 61 | 62 | # Freeline 63 | freeline.py 64 | freeline/ 65 | freeline_project_description.json 66 | 67 | # fastlane 68 | fastlane/report.xml 69 | fastlane/Preview.html 70 | fastlane/screenshots 71 | fastlane/test_output 72 | fastlane/readme.md 73 | 74 | ### Android Patch ### 75 | gen-external-apklibs 76 | 77 | ### AndroidStudio ### 78 | # Covers files to be ignored for android development using Android Studio. 79 | 80 | # Built application files 81 | 82 | # Files for the ART/Dalvik VM 83 | 84 | # Java class files 85 | 86 | # Generated files 87 | 88 | # Gradle files 89 | .gradle 90 | 91 | # Signing files 92 | .signing/ 93 | 94 | # Local configuration file (sdk path, etc) 95 | 96 | # Proguard folder generated by Eclipse 97 | 98 | # Log Files 99 | 100 | # Android Studio 101 | /*/build/ 102 | /*/local.properties 103 | /*/out 104 | /*/*/build 105 | /*/*/production 106 | *.ipr 107 | *~ 108 | *.swp 109 | 110 | # Android Patch 111 | 112 | # External native build folder generated in Android Studio 2.2 and later 113 | 114 | # NDK 115 | obj/ 116 | 117 | # IntelliJ IDEA 118 | *.iws 119 | /out/ 120 | 121 | # User-specific configurations 122 | .idea/caches/ 123 | .idea/libraries/ 124 | .idea/shelf/ 125 | .idea/.name 126 | .idea/compiler.xml 127 | .idea/copyright/profiles_settings.xml 128 | .idea/encodings.xml 129 | .idea/misc.xml 130 | .idea/modules.xml 131 | .idea/scopes/scope_settings.xml 132 | .idea/vcs.xml 133 | .idea/jsLibraryMappings.xml 134 | .idea/datasources.xml 135 | .idea/dataSources.ids 136 | .idea/sqlDataSources.xml 137 | .idea/dynamic.xml 138 | .idea/uiDesigner.xml 139 | 140 | # OS-specific files 141 | .DS_Store 142 | .DS_Store? 143 | ._* 144 | .Spotlight-V100 145 | .Trashes 146 | ehthumbs.db 147 | Thumbs.db 148 | 149 | # Legacy Eclipse project files 150 | .classpath 151 | .project 152 | .cproject 153 | .settings/ 154 | 155 | # Mobile Tools for Java (J2ME) 156 | .mtj.tmp/ 157 | 158 | # Package Files # 159 | *.war 160 | *.ear 161 | 162 | # virtual machine crash logs (Reference: http://www.java.com/en/download/help/error_hotspot.xml) 163 | hs_err_pid* 164 | 165 | ## Plugin-specific files: 166 | 167 | # mpeltonen/sbt-idea plugin 168 | .idea_modules/ 169 | 170 | # JIRA plugin 171 | atlassian-ide-plugin.xml 172 | 173 | # Mongo Explorer plugin 174 | .idea/mongoSettings.xml 175 | 176 | # Crashlytics plugin (for Android Studio and IntelliJ) 177 | com_crashlytics_export_strings.xml 178 | crashlytics.properties 179 | crashlytics-build.properties 180 | fabric.properties 181 | 182 | ### AndroidStudio Patch ### 183 | 184 | !/gradle/wrapper/gradle-wrapper.jar 185 | 186 | # End of https://www.gitignore.io/api/android,androidstudio -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TimetableView 2 | [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) 3 | [![API](https://img.shields.io/badge/API-19%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=19) 4 | [![](https://jitpack.io/v/tlaabs/TimetableView.svg)](https://jitpack.io/#tlaabs/TimetableView) 5 | 6 | Android Library that creates simple time table. 7 | 8 | 9 | ![img0](https://postfiles.pstatic.net/MjAxOTAxMjdfMTUz/MDAxNTQ4NTcyNTU5NTk4.M9hWyDvljjkoBDW-naLrTRqRAXUM8WRUyZXptTLKbs8g.b0FN12d8Cmxp5OWZqlQcusL_mJYNKgx6a_XLe_1ALOog.JPEG.tlaabs/Screenshot_Air.jpg?type=w773) 10 | ![img1](https://user-images.githubusercontent.com/8165219/62833150-b88d3180-bc74-11e9-9b20-02a0ad03e778.jpg) 11 | 12 | 13 | ## How to import 14 | Add it in your root build.gradle 15 | ```gradle 16 | allprojects { 17 | repositories { 18 | ... 19 | maven { url 'https://jitpack.io' } 20 | } 21 | } 22 | ``` 23 | Add the dependency 24 | ```gradle 25 | dependencies { 26 | implementation 'com.github.tlaabs:TimetableView:1.0.3-fx1' 27 | } 28 | ``` 29 | 30 | ## Usage 31 | Add following XML namespace inside your XML layout file. 32 | 33 | ```gradle 34 | xmlns:app="http://schemas.android.com/apk/res-auto" 35 | ``` 36 | 37 | ### TimetableView in layout 38 | ```xml 39 | 45 | ``` 46 | 47 | ### Attribute descriptions 48 | ```gradle 49 | app:row_count="12" // sets number of table rows (default:12) 50 | app:column_count="6" // sets number of table column (default:6) 51 | app:cell_height="50dp" // sets table cell height (default:50dp) 52 | app:side_cell_width="30dp" // sets left side cell width (default:30dp) 53 | app:header_title="@array/my_header_title" // sets header title (default:eng) 54 | app:sticker_colors="@array/my_sticker_color" // sets schedule sticker colors 55 | app:start_time="9" // sets start time (range : 0 ~ 24) 56 | app:header_highlight_color="@color/highlight" // sets header highlight color (default : #74a4f3) 57 | app:header_highlight_image="@drawable/ic_kitty" // set header highlight image src 58 | app:header_highlight_image_size="36dp" // set header highlight image width,height(square) 59 | app:header_highlight_type="image" // set header highlight type - color/image (default : color) 60 | ``` 61 | 62 | ### Change header title 63 | First, write a string-array as below on values/strings.xml. 64 | ```xml 65 | 66 | 67 | Mon 68 | Tue 69 | Wed 70 | Thu 71 | Fri 72 | 73 | ``` 74 | Then, apply that to timetable attribute. 75 | ```xml 76 | 82 | ``` 83 | 84 | ### OnStickerSelectedListener 85 | OnStickerSelectedListener is invoked when clicked by user. 86 | 87 | idx is used to edit or delete. 88 | ```java 89 | timetable.setOnStickerSelectEventListener(new TimetableView.OnStickerSelectedListener() { 90 | @Override 91 | public void OnStickerSelected(int idx, ArrayList schedules) { 92 | // ... 93 | } 94 | }); 95 | ``` 96 | 97 | ### Add schdule 98 | ```java 99 | ArrayList schedules = new ArrayList(); 100 | Schedule schedule = new Schedule(); 101 | schedule.setClassTitle("Data Structure"); // sets subject 102 | schedule.setClassPlace("IT-601"); // sets place 103 | schedule.setProfessorName("Won Kim"); // sets professor 104 | schedule.setStartTime(new Time(10,0)); // sets the beginning of class time (hour,minute) 105 | schedule.setEndTime(new Time(13,30)); // sets the end of class time (hour,minute) 106 | schedules.add(schedule); 107 | //.. add one or more schedules 108 | timetable.add(schedules); 109 | ``` 110 | 111 | ### Edit schedule 112 | Before you edit,you need to get a sticker idx by using OnStickerSelectedListener. 113 | ```java 114 | timetable.edit(idx,schedules); 115 | ``` 116 | 117 | ### Delete schdule 118 | ```java 119 | timetable.remove(idx); 120 | timetable.removeAll(); // remove all items 121 | ``` 122 | 123 | ### Highlight header 124 | **1.Color type(Default)** 125 | ```xml 126 | 132 | ``` 133 | **2.Image type** 134 | ```xml 135 | 143 | ``` 144 | Then, 145 | ```java 146 | timetable.setHeaderHighlight(idx); 147 | ``` 148 | 149 | ### Restore and save 150 | Using SaveManager, you can save all timetable schdule datas in json format. 151 | ```java 152 | String json = timetable.createSaveData(); // save 153 | timetable.load(json); // restore 154 | ``` 155 | 156 | # License 157 | ```xml 158 | Copyright 2019 tlaabs 159 | 160 | Licensed under the Apache License, Version 2.0 (the "License"); 161 | you may not use this file except in compliance with the License. 162 | You may obtain a copy of the License at 163 | 164 | http://www.apache.org/licenses/LICENSE-2.0 165 | 166 | Unless required by applicable law or agreed to in writing, software 167 | distributed under the License is distributed on an "AS IS" BASIS, 168 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 169 | See the License for the specific language governing permissions and 170 | limitations under the License. 171 | ``` 172 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 28 5 | defaultConfig { 6 | applicationId "com.github.tlaabs.timetableviewdemo" 7 | minSdkVersion 19 8 | targetSdkVersion 28 9 | versionCode 4 10 | versionName "1.0.3-fx1" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation fileTree(dir: 'libs', include: ['*.jar']) 23 | implementation 'com.android.support:appcompat-v7:28.0.0' 24 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 25 | testImplementation 'junit:junit:4.12' 26 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 27 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 28 | 29 | implementation project(':timetableview') 30 | } 31 | -------------------------------------------------------------------------------- /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/androidTest/java/com/github/tlaabs/timetableviewdemo/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.github.tlaabs.timetableviewdemo; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.github.devsim.timetableviewdemo", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/tlaabs/timetableviewdemo/EditActivity.java: -------------------------------------------------------------------------------- 1 | package com.github.tlaabs.timetableviewdemo; 2 | 3 | import android.app.TimePickerDialog; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.os.Bundle; 8 | import android.view.View; 9 | import android.widget.AdapterView; 10 | import android.widget.Button; 11 | import android.widget.EditText; 12 | import android.widget.Spinner; 13 | import android.widget.TextView; 14 | import android.widget.TimePicker; 15 | 16 | import com.github.tlaabs.timetableview.Schedule; 17 | import com.github.tlaabs.timetableview.Time; 18 | 19 | import java.util.ArrayList; 20 | 21 | public class EditActivity extends AppCompatActivity implements View.OnClickListener { 22 | public static final int RESULT_OK_ADD = 1; 23 | public static final int RESULT_OK_EDIT = 2; 24 | public static final int RESULT_OK_DELETE = 3; 25 | 26 | private Context context; 27 | 28 | private Button deleteBtn; 29 | private Button submitBtn; 30 | private EditText subjectEdit; 31 | private EditText classroomEdit; 32 | private EditText professorEdit; 33 | private Spinner daySpinner; 34 | private TextView startTv; 35 | private TextView endTv; 36 | 37 | //request mode 38 | private int mode; 39 | 40 | private Schedule schedule; 41 | private int editIdx; 42 | 43 | @Override 44 | protected void onCreate(Bundle savedInstanceState) { 45 | super.onCreate(savedInstanceState); 46 | setContentView(R.layout.activity_edit); 47 | init(); 48 | } 49 | 50 | private void init(){ 51 | this.context = this; 52 | deleteBtn = findViewById(R.id.delete_btn); 53 | submitBtn = findViewById(R.id.submit_btn); 54 | subjectEdit = findViewById(R.id.subject_edit); 55 | classroomEdit = findViewById(R.id.classroom_edit); 56 | professorEdit = findViewById(R.id.professor_edit); 57 | daySpinner = findViewById(R.id.day_spinner); 58 | startTv = findViewById(R.id.start_time); 59 | endTv = findViewById(R.id.end_time); 60 | 61 | //set the default time 62 | schedule = new Schedule(); 63 | schedule.setStartTime(new Time(10,0)); 64 | schedule.setEndTime(new Time(13,30)); 65 | 66 | checkMode(); 67 | initView(); 68 | } 69 | 70 | /** check whether the mode is ADD or EDIT */ 71 | private void checkMode(){ 72 | Intent i = getIntent(); 73 | mode = i.getIntExtra("mode",MainActivity.REQUEST_ADD); 74 | 75 | if(mode == MainActivity.REQUEST_EDIT){ 76 | loadScheduleData(); 77 | deleteBtn.setVisibility(View.VISIBLE); 78 | } 79 | } 80 | private void initView(){ 81 | submitBtn.setOnClickListener(this); 82 | deleteBtn.setOnClickListener(this); 83 | 84 | daySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 85 | @Override 86 | public void onItemSelected(AdapterView parent, View view, int position, long id) { 87 | schedule.setDay(position); 88 | } 89 | 90 | @Override 91 | public void onNothingSelected(AdapterView parent) { 92 | 93 | } 94 | }); 95 | startTv.setOnClickListener(new View.OnClickListener() { 96 | @Override 97 | public void onClick(View v) { 98 | TimePickerDialog dialog = new TimePickerDialog(context,listener,schedule.getStartTime().getHour(), schedule.getStartTime().getMinute(), false); 99 | dialog.show(); 100 | } 101 | 102 | private TimePickerDialog.OnTimeSetListener listener = new TimePickerDialog.OnTimeSetListener() { 103 | @Override 104 | public void onTimeSet(TimePicker view, int hourOfDay, int minute) { 105 | startTv.setText(hourOfDay + ":" + minute); 106 | schedule.getStartTime().setHour(hourOfDay); 107 | schedule.getStartTime().setMinute(minute); 108 | } 109 | }; 110 | }); 111 | endTv.setOnClickListener(new View.OnClickListener() { 112 | @Override 113 | public void onClick(View v) { 114 | TimePickerDialog dialog = new TimePickerDialog(context,listener,schedule.getEndTime().getHour(), schedule.getEndTime().getMinute(), false); 115 | dialog.show(); 116 | } 117 | 118 | private TimePickerDialog.OnTimeSetListener listener = new TimePickerDialog.OnTimeSetListener() { 119 | @Override 120 | public void onTimeSet(TimePicker view, int hourOfDay, int minute) { 121 | endTv.setText(hourOfDay + ":" + minute); 122 | schedule.getEndTime().setHour(hourOfDay); 123 | schedule.getEndTime().setMinute(minute); 124 | } 125 | }; 126 | }); 127 | } 128 | 129 | @Override 130 | public void onClick(View v) { 131 | switch (v.getId()){ 132 | case R.id.submit_btn: 133 | if(mode == MainActivity.REQUEST_ADD){ 134 | inputDataProcessing(); 135 | Intent i = new Intent(); 136 | ArrayList schedules = new ArrayList(); 137 | //you can add more schedules to ArrayList 138 | schedules.add(schedule); 139 | i.putExtra("schedules",schedules); 140 | setResult(RESULT_OK_ADD,i); 141 | finish(); 142 | } 143 | else if(mode == MainActivity.REQUEST_EDIT){ 144 | inputDataProcessing(); 145 | Intent i = new Intent(); 146 | ArrayList schedules = new ArrayList(); 147 | schedules.add(schedule); 148 | i.putExtra("idx",editIdx); 149 | i.putExtra("schedules",schedules); 150 | setResult(RESULT_OK_EDIT,i); 151 | finish(); 152 | } 153 | break; 154 | case R.id.delete_btn: 155 | Intent i = new Intent(); 156 | i.putExtra("idx",editIdx); 157 | setResult(RESULT_OK_DELETE, i); 158 | finish(); 159 | break; 160 | } 161 | } 162 | 163 | private void loadScheduleData(){ 164 | Intent i = getIntent(); 165 | editIdx = i.getIntExtra("idx",-1); 166 | ArrayList schedules = (ArrayList)i.getSerializableExtra("schedules"); 167 | schedule = schedules.get(0); 168 | subjectEdit.setText(schedule.getClassTitle()); 169 | classroomEdit.setText(schedule.getClassPlace()); 170 | professorEdit.setText(schedule.getProfessorName()); 171 | daySpinner.setSelection(schedule.getDay()); 172 | } 173 | 174 | private void inputDataProcessing(){ 175 | schedule.setClassTitle(subjectEdit.getText().toString()); 176 | schedule.setClassPlace(classroomEdit.getText().toString()); 177 | schedule.setProfessorName(professorEdit.getText().toString()); 178 | } 179 | } 180 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/tlaabs/timetableviewdemo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.github.tlaabs.timetableviewdemo; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.content.SharedPreferences; 6 | import android.preference.PreferenceManager; 7 | import android.support.annotation.Nullable; 8 | import android.support.v7.app.AppCompatActivity; 9 | import android.os.Bundle; 10 | import android.view.View; 11 | import android.widget.Button; 12 | import android.widget.Toast; 13 | 14 | import com.github.tlaabs.timetableview.Schedule; 15 | import com.github.tlaabs.timetableview.TimetableView; 16 | 17 | import java.util.ArrayList; 18 | 19 | public class MainActivity extends AppCompatActivity implements View.OnClickListener { 20 | private Context context; 21 | public static final int REQUEST_ADD = 1; 22 | public static final int REQUEST_EDIT = 2; 23 | 24 | private Button addBtn; 25 | private Button clearBtn; 26 | private Button saveBtn; 27 | private Button loadBtn; 28 | 29 | private TimetableView timetable; 30 | @Override 31 | protected void onCreate(Bundle savedInstanceState) { 32 | super.onCreate(savedInstanceState); 33 | setContentView(R.layout.activity_main); 34 | 35 | init(); 36 | } 37 | 38 | private void init(){ 39 | this.context = this; 40 | addBtn = findViewById(R.id.add_btn); 41 | clearBtn = findViewById(R.id.clear_btn); 42 | saveBtn = findViewById(R.id.save_btn); 43 | loadBtn = findViewById(R.id.load_btn); 44 | 45 | timetable = findViewById(R.id.timetable); 46 | timetable.setHeaderHighlight(2); 47 | initView(); 48 | } 49 | 50 | private void initView(){ 51 | addBtn.setOnClickListener(this); 52 | clearBtn.setOnClickListener(this); 53 | saveBtn.setOnClickListener(this); 54 | loadBtn.setOnClickListener(this); 55 | 56 | timetable.setOnStickerSelectEventListener(new TimetableView.OnStickerSelectedListener() { 57 | @Override 58 | public void OnStickerSelected(int idx, ArrayList schedules) { 59 | Intent i = new Intent(context, EditActivity.class); 60 | i.putExtra("mode",REQUEST_EDIT); 61 | i.putExtra("idx", idx); 62 | i.putExtra("schedules", schedules); 63 | startActivityForResult(i,REQUEST_EDIT); 64 | } 65 | }); 66 | } 67 | 68 | @Override 69 | public void onClick(View v) { 70 | switch (v.getId()){ 71 | case R.id.add_btn: 72 | Intent i = new Intent(this,EditActivity.class); 73 | i.putExtra("mode",REQUEST_ADD); 74 | startActivityForResult(i,REQUEST_ADD); 75 | break; 76 | case R.id.clear_btn: 77 | timetable.removeAll(); 78 | break; 79 | case R.id.save_btn: 80 | saveByPreference(timetable.createSaveData()); 81 | break; 82 | case R.id.load_btn: 83 | loadSavedData(); 84 | break; 85 | } 86 | } 87 | 88 | @Override 89 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { 90 | switch (requestCode){ 91 | case REQUEST_ADD: 92 | if(resultCode == EditActivity.RESULT_OK_ADD){ 93 | ArrayList item = (ArrayList)data.getSerializableExtra("schedules"); 94 | timetable.add(item); 95 | } 96 | break; 97 | case REQUEST_EDIT: 98 | /** Edit -> Submit */ 99 | if(resultCode == EditActivity.RESULT_OK_EDIT){ 100 | int idx = data.getIntExtra("idx",-1); 101 | ArrayList item = (ArrayList)data.getSerializableExtra("schedules"); 102 | timetable.edit(idx,item); 103 | } 104 | /** Edit -> Delete */ 105 | else if(resultCode == EditActivity.RESULT_OK_DELETE){ 106 | int idx = data.getIntExtra("idx",-1); 107 | timetable.remove(idx); 108 | } 109 | break; 110 | } 111 | } 112 | 113 | /** save timetableView's data to SharedPreferences in json format */ 114 | private void saveByPreference(String data){ 115 | SharedPreferences mPref = PreferenceManager.getDefaultSharedPreferences(this); 116 | SharedPreferences.Editor editor = mPref.edit(); 117 | editor.putString("timetable_demo",data); 118 | editor.commit(); 119 | Toast.makeText(this,"saved!",Toast.LENGTH_SHORT).show(); 120 | } 121 | 122 | /** get json data from SharedPreferences and then restore the timetable */ 123 | private void loadSavedData(){ 124 | timetable.removeAll(); 125 | SharedPreferences mPref = PreferenceManager.getDefaultSharedPreferences(this); 126 | String savedData = mPref.getString("timetable_demo",""); 127 | if(savedData == null && savedData.equals("")) return; 128 | timetable.load(savedData); 129 | Toast.makeText(this,"loaded!",Toast.LENGTH_SHORT).show(); 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /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/drawable/ic_kitty.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 11 | 13 | 15 | 17 | 18 | 19 | 20 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 42 | 44 | 45 | -------------------------------------------------------------------------------- /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/res/layout/activity_edit.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 16 | 17 | 22 | 23 | 28 | 29 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 17 | 18 |