├── .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 | [](https://opensource.org/licenses/Apache-2.0)
3 | [](https://android-arsenal.com/api?level=19)
4 | [](https://jitpack.io/#tlaabs/TimetableView)
5 |
6 | Android Library that creates simple time table.
7 |
8 |
9 | 
10 | 
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 |
23 |
24 |
29 |
30 |
35 |
36 |
41 |
42 |
43 |
44 |
52 |
53 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/edit_appbar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
16 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/time_box.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
15 |
22 |
28 |
35 |
36 |
--------------------------------------------------------------------------------
/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/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tlaabs/TimetableView/7d58cdd44dd9c562c7e4c67ace022be89d6acdee/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tlaabs/TimetableView/7d58cdd44dd9c562c7e4c67ace022be89d6acdee/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tlaabs/TimetableView/7d58cdd44dd9c562c7e4c67ace022be89d6acdee/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tlaabs/TimetableView/7d58cdd44dd9c562c7e4c67ace022be89d6acdee/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tlaabs/TimetableView/7d58cdd44dd9c562c7e4c67ace022be89d6acdee/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tlaabs/TimetableView/7d58cdd44dd9c562c7e4c67ace022be89d6acdee/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tlaabs/TimetableView/7d58cdd44dd9c562c7e4c67ace022be89d6acdee/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tlaabs/TimetableView/7d58cdd44dd9c562c7e4c67ace022be89d6acdee/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tlaabs/TimetableView/7d58cdd44dd9c562c7e4c67ace022be89d6acdee/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tlaabs/TimetableView/7d58cdd44dd9c562c7e4c67ace022be89d6acdee/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | TimetableViewDemo
3 |
4 |
5 |
6 | - Mon
7 | - Tue
8 | - Wed
9 | - Thu
10 | - Fri
11 |
12 |
13 |
14 | - Mon
15 | - Tue
16 | - Wed
17 | - Thu
18 | - Fri
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/github/tlaabs/timetableviewdemo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.github.tlaabs.timetableviewdemo;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.2.1'
11 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/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 |
15 |
16 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tlaabs/TimetableView/7d58cdd44dd9c562c7e4c67ace022be89d6acdee/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Aug 11 18:04:07 KST 2019
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.1.1-all.zip
7 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':timetableview'
2 |
--------------------------------------------------------------------------------
/timetableview/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/timetableview/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 28
5 |
6 | defaultConfig {
7 | minSdkVersion 19
8 | targetSdkVersion 28
9 | versionCode 3
10 | versionName "1.0.3"
11 |
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 |
14 | }
15 |
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 |
23 | }
24 |
25 | dependencies {
26 | implementation fileTree(dir: 'libs', include: ['*.jar'])
27 |
28 | implementation 'com.android.support:appcompat-v7:28.0.0'
29 | testImplementation 'junit:junit:4.12'
30 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
31 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
32 |
33 | implementation 'com.google.code.gson:gson:2.8.5'
34 | }
35 | apply plugin: 'com.github.dcendents.android-maven'
36 | group='com.github.tlaabs'
--------------------------------------------------------------------------------
/timetableview/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 |
--------------------------------------------------------------------------------
/timetableview/src/androidTest/java/com/github/tlaabs/timetableview/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.github.tlaabs.timetableview;
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.timetableview.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/timetableview/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/timetableview/src/main/java/com/github/tlaabs/timetableview/HighlightMode.java:
--------------------------------------------------------------------------------
1 | package com.github.tlaabs.timetableview;
2 |
3 | public enum HighlightMode {
4 | COLOR,
5 | IMAGE
6 | }
7 |
--------------------------------------------------------------------------------
/timetableview/src/main/java/com/github/tlaabs/timetableview/SaveManager.java:
--------------------------------------------------------------------------------
1 | package com.github.tlaabs.timetableview;
2 |
3 | import android.util.Log;
4 |
5 | import com.google.gson.JsonArray;
6 | import com.google.gson.JsonObject;
7 | import com.google.gson.JsonParser;
8 |
9 | import java.util.ArrayList;
10 | import java.util.Arrays;
11 | import java.util.HashMap;
12 |
13 | public class SaveManager {
14 | public static String saveSticker(HashMap stickers){
15 | JsonObject obj1 = new JsonObject();
16 | JsonArray arr1 = new JsonArray();
17 | int[] orders = getSortedKeySet(stickers);
18 | for(int i = 0 ; i < orders.length; i++){
19 | JsonObject obj2 = new JsonObject();
20 | int idx = orders[i];
21 | obj2.addProperty("idx",orders[i]);
22 | JsonArray arr2 = new JsonArray();//5
23 | ArrayList schedules = stickers.get(idx).getSchedules();
24 | for(Schedule schedule : schedules){
25 | JsonObject obj3 = new JsonObject();
26 | obj3.addProperty("classTitle",schedule.classTitle);
27 | obj3.addProperty("classPlace",schedule.classPlace);
28 | obj3.addProperty("professorName",schedule.getProfessorName());
29 | obj3.addProperty("day",schedule.getDay());
30 | JsonObject obj4 = new JsonObject();//startTime
31 | obj4.addProperty("hour",schedule.getStartTime().getHour());
32 | obj4.addProperty("minute",schedule.getStartTime().getMinute());
33 | obj3.add("startTime",obj4);
34 | JsonObject obj5 = new JsonObject();//endtTime
35 | obj5.addProperty("hour",schedule.getEndTime().getHour());
36 | obj5.addProperty("minute",schedule.getEndTime().getMinute());
37 | obj3.add("endTime",obj5);
38 | arr2.add(obj3);
39 | }
40 | obj2.add("schedule",arr2);
41 | arr1.add(obj2);
42 | }
43 | obj1.add("sticker",arr1);
44 | return obj1.toString();
45 | }
46 |
47 | public static HashMap loadSticker(String json){
48 | HashMap stickers = new HashMap();
49 | JsonParser parser = new JsonParser();
50 | JsonObject obj1 = (JsonObject)parser.parse(json);
51 | JsonArray arr1 = obj1.getAsJsonArray("sticker");
52 | for(int i = 0 ; i < arr1.size(); i++){
53 | Sticker sticker = new Sticker();
54 | JsonObject obj2 = (JsonObject)arr1.get(i);
55 | int idx = obj2.get("idx").getAsInt();
56 | JsonArray arr2 = (JsonArray)obj2.get("schedule");
57 | for(int k = 0 ; k < arr2.size(); k++){
58 | Schedule schedule = new Schedule();
59 | JsonObject obj3 = (JsonObject)arr2.get(k);
60 | schedule.setClassTitle(obj3.get("classTitle").getAsString());
61 | schedule.setClassPlace(obj3.get("classPlace").getAsString());
62 | schedule.setProfessorName(obj3.get("professorName").getAsString());
63 | schedule.setDay(obj3.get("day").getAsInt());
64 | Time startTime = new Time();
65 | JsonObject obj4 = (JsonObject)obj3.get("startTime");
66 | startTime.setHour(obj4.get("hour").getAsInt());
67 | startTime.setMinute(obj4.get("minute").getAsInt());
68 | Time endTime = new Time();
69 | JsonObject obj5 = (JsonObject)obj3.get("endTime");
70 | endTime.setHour(obj5.get("hour").getAsInt());
71 | endTime.setMinute(obj5.get("minute").getAsInt());
72 | schedule.setStartTime(startTime);
73 | schedule.setEndTime(endTime);
74 | sticker.addSchedule(schedule);
75 | }
76 | stickers.put(idx,sticker);
77 | }
78 | return stickers;
79 | }
80 |
81 |
82 | static private int[] getSortedKeySet(HashMap stickers){
83 | int[] orders = new int[stickers.size()];
84 | int i = 0;
85 | for(int key : stickers.keySet()){
86 | orders[i++] = key;
87 | }
88 | Arrays.sort(orders);
89 | return orders;
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/timetableview/src/main/java/com/github/tlaabs/timetableview/Schedule.java:
--------------------------------------------------------------------------------
1 | package com.github.tlaabs.timetableview;
2 |
3 | import java.io.Serializable;
4 |
5 | public class Schedule implements Serializable {
6 | static final int MON = 0;
7 | static final int TUE = 1;
8 | static final int WED = 2;
9 | static final int THU = 3;
10 | static final int FRI = 4;
11 | static final int SAT = 5;
12 | static final int SUN = 6;
13 |
14 | String classTitle="";
15 | String classPlace="";
16 | String professorName="";
17 | private int day = 0;
18 | private Time startTime;
19 | private Time endTime;
20 |
21 | public Schedule() {
22 | this.startTime = new Time();
23 | this.endTime = new Time();
24 | }
25 |
26 | public String getProfessorName() {
27 | return professorName;
28 | }
29 |
30 | public void setProfessorName(String professorName) {
31 | this.professorName = professorName;
32 | }
33 |
34 | public String getClassTitle() {
35 | return classTitle;
36 | }
37 |
38 | public void setClassTitle(String classTitle) {
39 | this.classTitle = classTitle;
40 | }
41 |
42 | public String getClassPlace() {
43 | return classPlace;
44 | }
45 |
46 | public void setClassPlace(String classPlace) {
47 | this.classPlace = classPlace;
48 | }
49 |
50 | public int getDay() {
51 | return day;
52 | }
53 |
54 | public void setDay(int day) {
55 | this.day = day;
56 | }
57 |
58 | public Time getStartTime() {
59 | return startTime;
60 | }
61 |
62 | public void setStartTime(Time startTime) {
63 | this.startTime = startTime;
64 | }
65 |
66 | public Time getEndTime() {
67 | return endTime;
68 | }
69 |
70 | public void setEndTime(Time endTime) {
71 | this.endTime = endTime;
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/timetableview/src/main/java/com/github/tlaabs/timetableview/Sticker.java:
--------------------------------------------------------------------------------
1 | package com.github.tlaabs.timetableview;
2 |
3 | import android.widget.TextView;
4 |
5 | import java.io.Serializable;
6 | import java.util.ArrayList;
7 |
8 | public class Sticker implements Serializable {
9 | private ArrayList view;
10 | private ArrayList schedules;
11 |
12 | public Sticker() {
13 | this.view = new ArrayList();
14 | this.schedules = new ArrayList();
15 | }
16 |
17 | public void addTextView(TextView v){
18 | view.add(v);
19 | }
20 |
21 | public void addSchedule(Schedule schedule){
22 | schedules.add(schedule);
23 | }
24 |
25 | public ArrayList getView() {
26 | return view;
27 | }
28 |
29 | public ArrayList getSchedules() {
30 | return schedules;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/timetableview/src/main/java/com/github/tlaabs/timetableview/Time.java:
--------------------------------------------------------------------------------
1 | package com.github.tlaabs.timetableview;
2 |
3 | import java.io.Serializable;
4 |
5 | public class Time implements Serializable {
6 | private int hour = 0;
7 | private int minute = 0;
8 |
9 | public Time(int hour, int minute) {
10 | this.hour = hour;
11 | this.minute = minute;
12 | }
13 |
14 | public Time() { }
15 |
16 | public int getHour() {
17 | return hour;
18 | }
19 |
20 | public void setHour(int hour) {
21 | this.hour = hour;
22 | }
23 |
24 | public int getMinute() {
25 | return minute;
26 | }
27 |
28 | public void setMinute(int minute) {
29 | this.minute = minute;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/timetableview/src/main/java/com/github/tlaabs/timetableview/TimetableView.java:
--------------------------------------------------------------------------------
1 | package com.github.tlaabs.timetableview;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.content.res.Resources;
6 | import android.content.res.TypedArray;
7 | import android.graphics.Color;
8 | import android.graphics.Point;
9 | import android.graphics.Typeface;
10 | import android.graphics.drawable.Drawable;
11 | import android.support.v7.content.res.AppCompatResources;
12 | import android.util.AttributeSet;
13 | import android.util.Log;
14 | import android.util.TypedValue;
15 | import android.view.Display;
16 | import android.view.Gravity;
17 | import android.view.LayoutInflater;
18 | import android.view.View;
19 | import android.widget.ImageView;
20 | import android.widget.LinearLayout;
21 | import android.widget.RelativeLayout;
22 | import android.widget.TableLayout;
23 | import android.widget.TableRow;
24 | import android.widget.TextView;
25 |
26 | import java.util.ArrayList;
27 | import java.util.Arrays;
28 | import java.util.HashMap;
29 |
30 | public class TimetableView extends LinearLayout {
31 | private static final int DEFAULT_ROW_COUNT = 12;
32 | private static final int DEFAULT_COLUMN_COUNT = 6;
33 | private static final int DEFAULT_CELL_HEIGHT_DP = 50;
34 | private static final int DEFAULT_SIDE_CELL_WIDTH_DP = 30;
35 | private static final int DEFAULT_START_TIME = 9;
36 |
37 | private static final int DEFAULT_SIDE_HEADER_FONT_SIZE_DP = 13;
38 | private static final int DEFAULT_HEADER_FONT_SIZE_DP = 15;
39 | private static final int DEFAULT_HEADER_HIGHLIGHT_FONT_SIZE_DP = 15;
40 | private static final int DEFAULT_STICKER_FONT_SIZE_DP = 13;
41 |
42 |
43 | private int rowCount;
44 | private int columnCount;
45 | private int cellHeight;
46 | private int sideCellWidth;
47 | private String[] headerTitle;
48 | private String[] stickerColors;
49 | private int startTime;
50 | private int headerHighlightColor;
51 |
52 | private RelativeLayout stickerBox;
53 | TableLayout tableHeader;
54 | TableLayout tableBox;
55 |
56 | private Context context;
57 |
58 | HashMap stickers = new HashMap();
59 | private int stickerCount = -1;
60 |
61 | private OnStickerSelectedListener stickerSelectedListener = null;
62 |
63 | private HighlightMode highlightMode = HighlightMode.COLOR;
64 | private int headerHighlightImageSize;
65 | private Drawable headerHighlightImage = null;
66 |
67 | public TimetableView(Context context) {
68 | super(context, null);
69 | this.context = context;
70 | }
71 |
72 | public TimetableView(Context context, AttributeSet attrs) {
73 | this(context, attrs, 0);
74 | }
75 |
76 | public TimetableView(Context context, AttributeSet attrs, int defStyleAttr) {
77 | super(context, attrs, defStyleAttr);
78 | this.context = context;
79 | getAttrs(attrs);
80 | init();
81 | }
82 |
83 | private void getAttrs(AttributeSet attrs) {
84 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TimetableView);
85 | rowCount = a.getInt(R.styleable.TimetableView_row_count, DEFAULT_ROW_COUNT) - 1;
86 | columnCount = a.getInt(R.styleable.TimetableView_column_count, DEFAULT_COLUMN_COUNT);
87 | cellHeight = a.getDimensionPixelSize(R.styleable.TimetableView_cell_height, dp2Px(DEFAULT_CELL_HEIGHT_DP));
88 | sideCellWidth = a.getDimensionPixelSize(R.styleable.TimetableView_side_cell_width, dp2Px(DEFAULT_SIDE_CELL_WIDTH_DP));
89 | int titlesId = a.getResourceId(R.styleable.TimetableView_header_title, R.array.default_header_title);
90 | headerTitle = a.getResources().getStringArray(titlesId);
91 | int colorsId = a.getResourceId(R.styleable.TimetableView_sticker_colors, R.array.default_sticker_color);
92 | stickerColors = a.getResources().getStringArray(colorsId);
93 | startTime = a.getInt(R.styleable.TimetableView_start_time, DEFAULT_START_TIME);
94 | headerHighlightColor = a.getColor(R.styleable.TimetableView_header_highlight_color, getResources().getColor(R.color.default_header_highlight_color));
95 | int highlightTypeValue = a.getInteger(R.styleable.TimetableView_header_highlight_type,0);
96 | if(highlightTypeValue == 0) highlightMode = HighlightMode.COLOR;
97 | else if(highlightTypeValue == 1) highlightMode = HighlightMode.IMAGE;
98 | headerHighlightImageSize = a.getDimensionPixelSize(R.styleable.TimetableView_header_highlight_image_size, dp2Px(24));
99 | headerHighlightImage = a.getDrawable(R.styleable.TimetableView_header_highlight_image);
100 | a.recycle();
101 | }
102 |
103 | private void init() {
104 | LayoutInflater layoutInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
105 | View view = layoutInflater.inflate(R.layout.view_timetable, this, false);
106 | addView(view);
107 |
108 | stickerBox = view.findViewById(R.id.sticker_box);
109 | tableHeader = view.findViewById(R.id.table_header);
110 | tableBox = view.findViewById(R.id.table_box);
111 |
112 | createTable();
113 | }
114 |
115 | public void setOnStickerSelectEventListener(OnStickerSelectedListener listener) {
116 | stickerSelectedListener = listener;
117 | }
118 |
119 | /**
120 | * date : 2019-02-08
121 | * get all schedules TimetableView has.
122 | */
123 | public ArrayList getAllSchedulesInStickers() {
124 | ArrayList allSchedules = new ArrayList();
125 | for (int key : stickers.keySet()) {
126 | for (Schedule schedule : stickers.get(key).getSchedules()) {
127 | allSchedules.add(schedule);
128 | }
129 | }
130 | return allSchedules;
131 | }
132 |
133 | /**
134 | * date : 2019-02-08
135 | * Used in Edit mode, To check a invalidate schedule.
136 | */
137 | public ArrayList getAllSchedulesInStickersExceptIdx(int idx) {
138 | ArrayList allSchedules = new ArrayList();
139 | for (int key : stickers.keySet()) {
140 | if (idx == key) continue;
141 | for (Schedule schedule : stickers.get(key).getSchedules()) {
142 | allSchedules.add(schedule);
143 | }
144 | }
145 | return allSchedules;
146 | }
147 |
148 | public void add(ArrayList schedules) {
149 | add(schedules, -1);
150 | }
151 |
152 | private void add(final ArrayList schedules, int specIdx) {
153 | final int count = specIdx < 0 ? ++stickerCount : specIdx;
154 | Sticker sticker = new Sticker();
155 | for (Schedule schedule : schedules) {
156 | TextView tv = new TextView(context);
157 |
158 | RelativeLayout.LayoutParams param = createStickerParam(schedule);
159 | tv.setLayoutParams(param);
160 | tv.setPadding(10, 0, 10, 0);
161 | tv.setText(schedule.getClassTitle() + "\n" + schedule.getClassPlace());
162 | tv.setTextColor(Color.parseColor("#FFFFFF"));
163 | tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, DEFAULT_STICKER_FONT_SIZE_DP);
164 | tv.setTypeface(null, Typeface.BOLD);
165 |
166 | tv.setOnClickListener(new OnClickListener() {
167 | @Override
168 | public void onClick(View v) {
169 | if(stickerSelectedListener != null)
170 | stickerSelectedListener.OnStickerSelected(count, schedules);
171 | }
172 | });
173 |
174 | sticker.addTextView(tv);
175 | sticker.addSchedule(schedule);
176 | stickers.put(count, sticker);
177 | stickerBox.addView(tv);
178 | }
179 | setStickerColor();
180 | }
181 |
182 | public String createSaveData() {
183 | return SaveManager.saveSticker(stickers);
184 | }
185 |
186 | public void load(String data) {
187 | removeAll();
188 | stickers = SaveManager.loadSticker(data);
189 | int maxKey = 0;
190 | for (int key : stickers.keySet()) {
191 | ArrayList schedules = stickers.get(key).getSchedules();
192 | add(schedules, key);
193 | if (maxKey < key) maxKey = key;
194 | }
195 | stickerCount = maxKey + 1;
196 | setStickerColor();
197 | }
198 |
199 | public void removeAll() {
200 | for (int key : stickers.keySet()) {
201 | Sticker sticker = stickers.get(key);
202 | for (TextView tv : sticker.getView()) {
203 | stickerBox.removeView(tv);
204 | }
205 | }
206 | stickers.clear();
207 | }
208 |
209 | public void edit(int idx, ArrayList schedules) {
210 | remove(idx);
211 | add(schedules, idx);
212 | }
213 |
214 | public void remove(int idx) {
215 | Sticker sticker = stickers.get(idx);
216 | for (TextView tv : sticker.getView()) {
217 | stickerBox.removeView(tv);
218 | }
219 | stickers.remove(idx);
220 | setStickerColor();
221 | }
222 |
223 | public void setHeaderHighlight(int idx) {
224 | if(idx < 0)return;
225 | TableRow row = (TableRow) tableHeader.getChildAt(0);
226 | View element = row.getChildAt(idx);
227 | if(highlightMode == HighlightMode.COLOR) {
228 | TextView tx = (TextView)element;
229 | tx.setTextColor(Color.parseColor("#FFFFFF"));
230 | tx.setBackgroundColor(headerHighlightColor);
231 | tx.setTypeface(null, Typeface.BOLD);
232 | tx.setTextSize(TypedValue.COMPLEX_UNIT_DIP, DEFAULT_HEADER_HIGHLIGHT_FONT_SIZE_DP);
233 | }
234 | else if(highlightMode == HighlightMode.IMAGE){
235 | RelativeLayout outer = new RelativeLayout(context);
236 | outer.setLayoutParams(createTableRowParam(cellHeight));
237 | ImageView iv = new ImageView(context);
238 | RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(headerHighlightImageSize,headerHighlightImageSize);
239 | params.addRule(RelativeLayout.CENTER_IN_PARENT,RelativeLayout.TRUE);
240 | iv.setLayoutParams(params);
241 | iv.setScaleType(ImageView.ScaleType.CENTER_CROP);
242 |
243 | row.removeViewAt(idx);
244 | outer.addView(iv);
245 | row.addView(outer,idx);
246 |
247 | if(headerHighlightImage != null) {
248 | iv.setImageDrawable(headerHighlightImage);
249 | }
250 |
251 | }
252 | }
253 |
254 | private void setStickerColor() {
255 | int size = stickers.size();
256 | int[] orders = new int[size];
257 | int i = 0;
258 | for (int key : stickers.keySet()) {
259 | orders[i++] = key;
260 | }
261 | Arrays.sort(orders);
262 |
263 | int colorSize = stickerColors.length;
264 |
265 | for (i = 0; i < size; i++) {
266 | for (TextView v : stickers.get(orders[i]).getView()) {
267 | v.setBackgroundColor(Color.parseColor(stickerColors[i % (colorSize)]));
268 | }
269 | }
270 |
271 | }
272 |
273 | private void createTable() {
274 | createTableHeader();
275 | for (int i = 0; i < rowCount; i++) {
276 | TableRow tableRow = new TableRow(context);
277 | tableRow.setLayoutParams(createTableLayoutParam());
278 |
279 | for (int k = 0; k < columnCount; k++) {
280 | TextView tv = new TextView(context);
281 | tv.setLayoutParams(createTableRowParam(cellHeight));
282 | if (k == 0) {
283 | tv.setText(getHeaderTime(i));
284 | tv.setTextColor(getResources().getColor(R.color.colorHeaderText));
285 | tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, DEFAULT_SIDE_HEADER_FONT_SIZE_DP);
286 | tv.setBackgroundColor(getResources().getColor(R.color.colorHeader));
287 | tv.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
288 | tv.setLayoutParams(createTableRowParam(sideCellWidth, cellHeight));
289 | } else {
290 | tv.setText("");
291 | tv.setBackground(getResources().getDrawable(R.drawable.item_border));
292 | tv.setGravity(Gravity.RIGHT);
293 | }
294 | tableRow.addView(tv);
295 | }
296 | tableBox.addView(tableRow);
297 | }
298 | }
299 |
300 | private void createTableHeader() {
301 | TableRow tableRow = new TableRow(context);
302 | tableRow.setLayoutParams(createTableLayoutParam());
303 |
304 | for (int i = 0; i < columnCount; i++) {
305 | TextView tv = new TextView(context);
306 | if (i == 0) {
307 | tv.setLayoutParams(createTableRowParam(sideCellWidth, cellHeight));
308 | } else {
309 | tv.setLayoutParams(createTableRowParam(cellHeight));
310 | }
311 | tv.setTextColor(getResources().getColor(R.color.colorHeaderText));
312 | tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, DEFAULT_HEADER_FONT_SIZE_DP);
313 | tv.setText(headerTitle[i]);
314 | tv.setGravity(Gravity.CENTER);
315 |
316 | tableRow.addView(tv);
317 | }
318 | tableHeader.addView(tableRow);
319 | }
320 |
321 | private RelativeLayout.LayoutParams createStickerParam(Schedule schedule) {
322 | int cell_w = calCellWidth();
323 |
324 | RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(cell_w, calStickerHeightPx(schedule));
325 | param.addRule(RelativeLayout.ALIGN_PARENT_TOP);
326 | param.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
327 | param.setMargins(sideCellWidth + cell_w * schedule.getDay(), calStickerTopPxByTime(schedule.getStartTime()), 0, 0);
328 |
329 | return param;
330 | }
331 |
332 | private int calCellWidth(){
333 | Display display = ((Activity) context).getWindowManager().getDefaultDisplay();
334 | Point size = new Point();
335 | display.getSize(size);
336 | int cell_w = (size.x-getPaddingLeft() - getPaddingRight()- sideCellWidth) / (columnCount - 1);
337 | return cell_w;
338 | }
339 |
340 | private int calStickerHeightPx(Schedule schedule) {
341 | int startTopPx = calStickerTopPxByTime(schedule.getStartTime());
342 | int endTopPx = calStickerTopPxByTime(schedule.getEndTime());
343 | int d = endTopPx - startTopPx;
344 |
345 | return d;
346 | }
347 |
348 | private int calStickerTopPxByTime(Time time) {
349 | int topPx = (time.getHour() - startTime) * cellHeight + (int) ((time.getMinute() / 60.0f) * cellHeight);
350 | return topPx;
351 | }
352 |
353 | private TableLayout.LayoutParams createTableLayoutParam() {
354 | return new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.MATCH_PARENT);
355 | }
356 |
357 | private TableRow.LayoutParams createTableRowParam(int h_px) {
358 | return new TableRow.LayoutParams(calCellWidth(), h_px);
359 | }
360 |
361 | private TableRow.LayoutParams createTableRowParam(int w_px, int h_px) {
362 | return new TableRow.LayoutParams(w_px, h_px);
363 | }
364 |
365 | private String getHeaderTime(int i) {
366 | int p = (startTime + i) % 24;
367 | int res = p <= 12 ? p : p - 12;
368 | return res + "";
369 | }
370 |
371 | static private int dp2Px(int dp) {
372 | return (int) (dp * Resources.getSystem().getDisplayMetrics().density);
373 | }
374 |
375 | private void onCreateByBuilder(Builder builder) {
376 | this.rowCount = builder.rowCount;
377 | this.columnCount = builder.columnCount;
378 | this.cellHeight = builder.cellHeight;
379 | this.sideCellWidth = builder.sideCellWidth;
380 | this.headerTitle = builder.headerTitle;
381 | this.stickerColors = builder.stickerColors;
382 | this.startTime = builder.startTime;
383 | this.headerHighlightColor = builder.headerHighlightColor;
384 |
385 | init();
386 | }
387 |
388 |
389 | public interface OnStickerSelectedListener {
390 | void OnStickerSelected(int idx, ArrayList schedules);
391 | }
392 |
393 | static class Builder {
394 | private Context context;
395 | private int rowCount;
396 | private int columnCount;
397 | private int cellHeight;
398 | private int sideCellWidth;
399 | private String[] headerTitle;
400 | private String[] stickerColors;
401 | private int startTime;
402 | private int headerHighlightColor;
403 |
404 | public Builder(Context context) {
405 | this.context = context;
406 | rowCount = DEFAULT_ROW_COUNT;
407 | columnCount = DEFAULT_COLUMN_COUNT;
408 | cellHeight = dp2Px(DEFAULT_CELL_HEIGHT_DP);
409 | sideCellWidth = dp2Px(DEFAULT_SIDE_CELL_WIDTH_DP);
410 | headerTitle = context.getResources().getStringArray(R.array.default_header_title);
411 | stickerColors = context.getResources().getStringArray(R.array.default_sticker_color);
412 | startTime = DEFAULT_START_TIME;
413 | headerHighlightColor = context.getResources().getColor(R.color.default_header_highlight_color);
414 | }
415 |
416 | public Builder setRowCount(int n) {
417 | this.rowCount = n;
418 | return this;
419 | }
420 |
421 | public Builder setColumnCount(int n) {
422 | this.columnCount = n;
423 | return this;
424 | }
425 |
426 | public Builder setCellHeight(int dp) {
427 | this.cellHeight = dp2Px(dp);
428 | return this;
429 | }
430 |
431 | public Builder setSideCellWidth(int dp) {
432 | this.sideCellWidth = dp2Px(dp);
433 | return this;
434 | }
435 |
436 | public Builder setHeaderTitle(String[] titles) {
437 | this.headerTitle = titles;
438 | return this;
439 | }
440 |
441 | public Builder setStickerColors(String[] colors) {
442 | this.stickerColors = colors;
443 | return this;
444 | }
445 |
446 | public Builder setStartTime(int t) {
447 | this.startTime = t;
448 | return this;
449 | }
450 |
451 | public Builder setHeaderHighlightColor(int c) {
452 | this.headerHighlightColor = c;
453 | return this;
454 | }
455 |
456 | public TimetableView build() {
457 | TimetableView timetableView = new TimetableView(context);
458 | timetableView.onCreateByBuilder(this);
459 | return timetableView;
460 | }
461 | }
462 | }
463 |
--------------------------------------------------------------------------------
/timetableview/src/main/res/drawable/item_border.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
--------------------------------------------------------------------------------
/timetableview/src/main/res/layout/inner_table.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
--------------------------------------------------------------------------------
/timetableview/src/main/res/layout/table_header.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
--------------------------------------------------------------------------------
/timetableview/src/main/res/layout/view_timetable.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
15 |
16 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/timetableview/src/main/res/values/attrs_timetable.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/timetableview/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #fcfcfc
4 | #7d7d7d
5 | #efefef
6 |
7 |
8 | - #f08676
9 | - #ecc369
10 | - #a7ca70
11 | - #7dd1c1
12 | - #7aa5e9
13 | - #fbaa68
14 | - #9f86e1
15 | - #78cb87
16 | - #d397ed
17 |
18 |
19 | #7d7d7d
20 | #7d7d7d
21 | #ffffff
22 | #74a4f3
23 | #ffffff
24 |
25 |
--------------------------------------------------------------------------------
/timetableview/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | - Mon
5 | - Tue
6 | - Wed
7 | - Thu
8 | - Fri
9 |
10 |
11 |
--------------------------------------------------------------------------------
/timetableview/src/test/java/com/github/tlaabs/timetableview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.github.tlaabs.timetableview;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------