├── calendarviewsample
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── mipmap-hdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── dimens.xml
│ │ │ ├── styles.xml
│ │ │ └── colors.xml
│ │ ├── drawable
│ │ │ └── current_day_drawable.xml
│ │ ├── values-w820dp
│ │ │ └── dimens.xml
│ │ ├── values-v21
│ │ │ └── styles.xml
│ │ ├── layout
│ │ │ ├── test_view2.xml
│ │ │ ├── test_view1.xml
│ │ │ ├── activity_main.xml
│ │ │ └── content_main.xml
│ │ └── layout-land
│ │ │ └── content_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── sickmartian
│ │ └── calendarviewsample
│ │ └── MainActivity.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitmodules
├── .gitignore
├── gradle.properties
├── gradlew.bat
├── README.md
└── gradlew
/calendarviewsample/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':calendarview', ':calendarviewsample'
2 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sickmartian/CalendarView/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "calendarview"]
2 | path = calendarview
3 | url = https://github.com/sickmartian/CalendarViewLib.git
4 |
--------------------------------------------------------------------------------
/calendarviewsample/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sickmartian/CalendarView/HEAD/calendarviewsample/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/calendarviewsample/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sickmartian/CalendarView/HEAD/calendarviewsample/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/calendarviewsample/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sickmartian/CalendarView/HEAD/calendarviewsample/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/calendarviewsample/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sickmartian/CalendarView/HEAD/calendarviewsample/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/calendarviewsample/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sickmartian/CalendarView/HEAD/calendarviewsample/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/calendarviewsample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | CalendarView
3 | Switch
4 |
5 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/calendarviewsample/src/main/res/drawable/current_day_drawable.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
--------------------------------------------------------------------------------
/calendarviewsample/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/calendarviewsample/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 16dp
6 | 12sp
7 | 1dp
8 |
9 |
--------------------------------------------------------------------------------
/calendarviewsample/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 | >
2 |
3 |
10 |
11 |
--------------------------------------------------------------------------------
/calendarviewsample/src/main/res/layout/test_view2.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
11 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
10 | #built application files
11 | *.apk
12 | *.ap_
13 |
14 | # files for the dex VM
15 | *.dex
16 |
17 | # Java class files
18 | *.class
19 |
20 | # generated files
21 | bin/
22 | gen/
23 |
24 | # Local configuration file (sdk path, etc)
25 | local.properties
26 |
27 | # Windows thumbnail db
28 | Thumbs.db
29 |
30 | # OSX files
31 | .DS_Store
32 |
33 | # Eclipse project files
34 | .classpath
35 | .project
36 |
37 | # Android Studio
38 | *.iml
39 | .idea
40 | #.idea/workspace.xml - remove # and delete .idea if it better suit your needs.
41 | .gradle
42 | build/
--------------------------------------------------------------------------------
/calendarviewsample/src/main/res/layout/test_view1.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
11 |
16 |
--------------------------------------------------------------------------------
/calendarviewsample/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:\Users\leuu\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/calendarviewsample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 27
5 | defaultConfig {
6 | applicationId "com.sickmartian.calendarviewsample"
7 | minSdkVersion 14
8 | targetSdkVersion 27
9 | versionCode 1
10 | versionName "1.0"
11 | }
12 | buildTypes {
13 | release {
14 | minifyEnabled false
15 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
16 | }
17 | }
18 | }
19 |
20 | dependencies {
21 | implementation fileTree(dir: 'libs', include: ['*.jar'])
22 | testImplementation 'junit:junit:4.12'
23 | implementation 'com.android.support:appcompat-v7:27.1.1'
24 | implementation 'com.android.support:design:27.1.1'
25 | implementation project(':calendarview')
26 | }
27 |
--------------------------------------------------------------------------------
/calendarviewsample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
10 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/calendarviewsample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/calendarviewsample/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
15 |
16 |
22 |
23 |
24 |
25 |
26 |
27 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/calendarviewsample/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #2196F3
4 | #1976D2
5 | #BBDEFB
6 | #CDDC39
7 |
8 | #212121
9 | #727272
10 | #FFFFFF
11 | #E4E4E4
12 |
13 | #FFFFFF
14 | #E7E7E7
15 | #F0F4C3
16 | @color/colorPrimaryLight
17 | #F2F2F2
18 |
19 | #727272
20 | #81D4FA
21 | #0277BD
22 | #AAAAAA
23 |
24 | #FFFFFF
25 | #E4E4E4
26 |
27 | @color/colorAccent
28 | @color/colorPrimaryLight
29 | @android:color/white
30 |
31 | #88727272
32 |
33 | #FF5555
34 | #72727272
35 | #AAAAAA
36 | #9ACB28
37 |
--------------------------------------------------------------------------------
/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 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
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 Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Calendar View Library
2 |
3 | A Month and a Week view group to present data.
4 |
5 | Features:
6 | * Customizable colors and text sizes
7 | * Overflow mark below the day when the views don't fit
8 | * First day of the week can be set to Sunday, Saturday or Monday
9 |
10 | ### Screenshots
11 |
12 |
13 | ### Add to your project using gradle
14 | ```groovy
15 | compile 'com.sickmartian.calendarview:calendarview:1.0.0'
16 | ```
17 |
18 | ### Customizable properties at a glance
19 | ```xml
20 |
39 | ```
40 |
41 | ### API
42 |
43 | The API for getting the pressed, current and/or selected day works via the **DayMetadata** class. `DayMetadata` is just a value holder for the day, month and year. It takes the months of the year starting with 1 (so January is 1, December is 12, like joda-time does)
44 |
45 | Some methods also have a `Calendar` alternative that is just there for convenience, in this case the Day, Month and Year values will be read directly, no timezone awarenes is built in.
46 |
47 | Adding views to the view group can be done via the day of the month for the `MonthView` (`addViewToDayInCurrentMonth`) or using `DayMetadata` for the `WeekView` (`addViewToDay`).
48 |
49 | Alternatively you can use the cell id (`addViewToCell`), this is not perfect as the state won't be preserved on rotation in some cases but at least allows you to add data to neightbor months when using `MonthView`.
50 |
51 | First day of the week is set like this
52 | ```java
53 | mCalendarView.setFirstDayOfTheWeek(CalendarView.SUNDAY_SHIFT);
54 | ```
55 |
56 | ### In Action
57 | This library powers the [Trackendar app that you can find on Google Play](https://play.google.com/store/apps/details?id=com.sickmartian.calendartracker) download it to see it in a production scenario
58 |
59 | Alternatively just clone the repo and submodule using:
60 |
61 | `git clone --recursive https://github.com/sickmartian/CalendarView.git`
62 |
63 | The sample app that's on the screenshots can be used to test the library.
64 |
65 | ### License
66 |
67 | Copyright 2017 sickmartian
68 |
69 | Licensed under the Apache License, Version 2.0 (the "License");
70 | you may not use this file except in compliance with the License.
71 | You may obtain a copy of the License at
72 |
73 | http://www.apache.org/licenses/LICENSE-2.0
74 |
75 | Unless required by applicable law or agreed to in writing, software
76 | distributed under the License is distributed on an "AS IS" BASIS,
77 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
78 | See the License for the specific language governing permissions and
79 | limitations under the License.
80 |
81 |
--------------------------------------------------------------------------------
/calendarviewsample/src/main/res/layout-land/content_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
18 |
22 |
27 |
32 |
38 |
43 |
48 |
49 |
50 |
54 |
59 |
64 |
69 |
74 |
75 |
76 |
77 |
97 |
98 |
99 |
--------------------------------------------------------------------------------
/calendarviewsample/src/main/res/layout/content_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
18 |
22 |
27 |
32 |
38 |
43 |
48 |
49 |
50 |
54 |
59 |
64 |
69 |
74 |
75 |
76 |
77 |
97 |
98 |
99 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/calendarviewsample/src/main/java/com/sickmartian/calendarviewsample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.sickmartian.calendarviewsample;
2 |
3 | import android.app.DatePickerDialog;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.support.v7.widget.Toolbar;
7 | import android.view.View;
8 | import android.widget.Button;
9 | import android.widget.DatePicker;
10 | import android.widget.RadioButton;
11 | import android.widget.Toast;
12 |
13 | import com.sickmartian.calendarview.CalendarView;
14 | import com.sickmartian.calendarview.MonthView;
15 | import com.sickmartian.calendarview.WeekView;
16 |
17 | import java.util.ArrayList;
18 | import java.util.Calendar;
19 |
20 | public class MainActivity extends AppCompatActivity {
21 |
22 | private static final String DAY_PARAMETER = "day";
23 | private static final String MONTH_PARAMETER = "month";
24 | private static final String YEAR_PARAMETER = "year";
25 | private static final String FIRST_DAY_OF_WEEK_PARAMETER = "firstDay";
26 |
27 | CalendarView mCalendarView;
28 |
29 | private int mYear;
30 | private int mDay;
31 | private int mMonth;
32 |
33 | public void setStateByCalendar(Calendar cal) {
34 | mYear = cal.get(Calendar.YEAR);
35 | mMonth = cal.get(Calendar.MONTH) + 1; // We use base 1 months..
36 | // You should use joda time or a sane Calendar really
37 | mDay = cal.get(Calendar.DATE);
38 | }
39 |
40 | @Override
41 | protected void onCreate(Bundle savedInstanceState) {
42 | super.onCreate(savedInstanceState);
43 | setContentView(R.layout.activity_main);
44 | Toolbar toolbar = findViewById(R.id.toolbar);
45 | setSupportActionBar(toolbar);
46 |
47 | int firstDayOfWeek = CalendarView.SUNDAY_SHIFT;
48 | if (savedInstanceState == null) {
49 | Calendar cal = Calendar.getInstance();
50 | setStateByCalendar(cal);
51 | } else {
52 | mDay = savedInstanceState.getInt(DAY_PARAMETER);
53 | mMonth = savedInstanceState.getInt(MONTH_PARAMETER);
54 | mYear = savedInstanceState.getInt(YEAR_PARAMETER);
55 | firstDayOfWeek = savedInstanceState.getInt(FIRST_DAY_OF_WEEK_PARAMETER);
56 | }
57 |
58 | // The two views can't have the same id, or the state won't be preserved
59 | // correctly and they will throw an exception
60 | mCalendarView = findViewById(R.id.monthView);
61 | if (mCalendarView == null) {
62 | mCalendarView = findViewById(R.id.weekView);
63 | }
64 |
65 | setDateByStateDependingOnView();
66 | mCalendarView.setFirstDayOfTheWeek(firstDayOfWeek);
67 | mCalendarView.setCurrentDay(getCalendarForState());
68 |
69 | inputTestData();
70 |
71 | mCalendarView.setDaySelectedListener(new CalendarView.DaySelectionListener() {
72 | @Override
73 | public void onTapEnded(CalendarView calendarView, CalendarView.DayMetadata dayMetadata) {
74 | Toast.makeText(MainActivity.this, "onTapEnded " + Integer.toString(dayMetadata.getDay()), Toast.LENGTH_SHORT).show();
75 | mCalendarView.setSelectedDay(dayMetadata);
76 | }
77 |
78 | @Override
79 | public void onLongClick(CalendarView calendarView, CalendarView.DayMetadata dayMetadata) {
80 | Toast.makeText(MainActivity.this, "onLongClick " + Integer.toString(dayMetadata.getDay()), Toast.LENGTH_SHORT).show();
81 | mCalendarView.setSelectedDay(dayMetadata);
82 | }
83 | });
84 |
85 | Button setDate = findViewById(R.id.set_date);
86 | setDate.setOnClickListener(new View.OnClickListener() {
87 | @Override
88 | public void onClick(View v) {
89 | new DatePickerDialog(MainActivity.this,
90 | new DatePickerDialog.OnDateSetListener() {
91 | @Override
92 | public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
93 | Calendar selectedDay = Calendar.getInstance();
94 | selectedDay.set(Calendar.YEAR, year);
95 | selectedDay.set(Calendar.MONTH, monthOfYear);
96 | selectedDay.set(Calendar.DATE, dayOfMonth);
97 | selectedDay.set(Calendar.HOUR_OF_DAY, 0);
98 | selectedDay.set(Calendar.MINUTE, 0);
99 | selectedDay.set(Calendar.SECOND, 0);
100 | selectedDay.set(Calendar.MILLISECOND, 0);
101 |
102 | setStateByCalendar(selectedDay);
103 |
104 | setDateByStateDependingOnView();
105 | mCalendarView.setCurrentDay(selectedDay);
106 |
107 | inputTestData();
108 | }
109 | },
110 | mYear, mMonth - 1, mDay).show();
111 | }
112 | });
113 |
114 | RadioButton sunday = findViewById(R.id.start_sunday);
115 | sunday.setOnClickListener(new View.OnClickListener() {
116 | @Override
117 | public void onClick(View v) {
118 | mCalendarView.setFirstDayOfTheWeek(MonthView.SUNDAY_SHIFT);
119 | mCalendarView.setCurrentDay(getCalendarForState());
120 | }
121 | });
122 |
123 | RadioButton monday = findViewById(R.id.start_monday);
124 | monday.setOnClickListener(new View.OnClickListener() {
125 | @Override
126 | public void onClick(View v) {
127 | mCalendarView.setFirstDayOfTheWeek(MonthView.MONDAY_SHIFT);
128 | mCalendarView.setCurrentDay(getCalendarForState());
129 | }
130 | });
131 |
132 | RadioButton saturday = findViewById(R.id.start_saturday);
133 | saturday.setOnClickListener(new View.OnClickListener() {
134 | @Override
135 | public void onClick(View v) {
136 | mCalendarView.setFirstDayOfTheWeek(MonthView.SATURDAY_SHIFT);
137 | mCalendarView.setCurrentDay(getCalendarForState());
138 | }
139 | });
140 |
141 | Button addView1 = findViewById(R.id.add_content1);
142 | addView1.setOnClickListener(new View.OnClickListener() {
143 | @Override
144 | public void onClick(View v) {
145 | View testView = getLayoutInflater().inflate(R.layout.test_view1, null);
146 | mCalendarView.addViewToDay(mCalendarView.getSelectedDay(),
147 | testView);
148 | }
149 | });
150 |
151 | Button addView2 = findViewById(R.id.add_content2);
152 | addView2.setOnClickListener(new View.OnClickListener() {
153 | @Override
154 | public void onClick(View v) {
155 | View testView = getLayoutInflater().inflate(R.layout.test_view2, null);
156 | mCalendarView.addViewToCell(mCalendarView.getSelectedCell(),
157 | testView);
158 | }
159 | });
160 |
161 | Button delFirst = findViewById(R.id.remove_first);
162 | delFirst.setOnClickListener(new View.OnClickListener() {
163 | @Override
164 | public void onClick(View v) {
165 | ArrayList content = mCalendarView.getDayContent(mCalendarView.getSelectedDay());
166 | if (!(content != null && content.size() > 0)) return;
167 | content.remove(0);
168 | mCalendarView.setDayContent(mCalendarView.getSelectedDay(), content);
169 | }
170 | });
171 |
172 | Button delLast = findViewById(R.id.remove_last);
173 | delLast.setOnClickListener(new View.OnClickListener() {
174 | @Override
175 | public void onClick(View v) {
176 | ArrayList content = mCalendarView.getDayContent(mCalendarView.getSelectedDay());
177 | if (!(content != null && content.size() > 0)) return;
178 | content.remove(content.size() - 1);
179 | mCalendarView.setDayContent(mCalendarView.getSelectedDay(), content);
180 | }
181 | });
182 | }
183 |
184 | @Override
185 | protected void onSaveInstanceState(Bundle outState) {
186 | super.onSaveInstanceState(outState);
187 | outState.putInt(DAY_PARAMETER, mDay);
188 | outState.putInt(MONTH_PARAMETER, mMonth);
189 | outState.putInt(YEAR_PARAMETER, mYear);
190 | outState.putInt(FIRST_DAY_OF_WEEK_PARAMETER, mCalendarView.getFirstDayOfTheWeek());
191 | }
192 |
193 | private Calendar getCalendarForState() {
194 | Calendar newCalendar = Calendar.getInstance();
195 | newCalendar.setMinimalDaysInFirstWeek(1);
196 | newCalendar.setFirstDayOfWeek(Calendar.SUNDAY);
197 | newCalendar.set(Calendar.YEAR, mYear);
198 | newCalendar.set(Calendar.MONTH, mMonth - 1);
199 | newCalendar.set(Calendar.DATE, mDay);
200 | newCalendar.set(Calendar.HOUR_OF_DAY, 0);
201 | newCalendar.set(Calendar.MINUTE, 0);
202 | newCalendar.set(Calendar.SECOND, 0);
203 | newCalendar.set(Calendar.MILLISECOND, 0);
204 | return newCalendar;
205 | }
206 |
207 | private void setDateByStateDependingOnView() {
208 | // The window of data shown depends on the view,
209 | // so there isn't a shared interface for this
210 | if (mCalendarView instanceof MonthView) {
211 | ((MonthView)mCalendarView).setDate(mMonth, mYear);
212 | } else {
213 | ((WeekView)mCalendarView).setDate(new CalendarView.DayMetadata(mYear, mMonth, mDay));
214 | }
215 | }
216 |
217 | private void inputTestData() {
218 | if (mCalendarView instanceof WeekView) {
219 | WeekView weekView = (WeekView) mCalendarView;
220 |
221 | View testView1 = getLayoutInflater().inflate(R.layout.test_view1, null);
222 | weekView.addViewToCell(0, testView1);
223 | testView1 = getLayoutInflater().inflate(R.layout.test_view1, null);
224 | weekView.addViewToCell(1, testView1);
225 | testView1 = getLayoutInflater().inflate(R.layout.test_view2, null);
226 | weekView.addViewToCell(1, testView1);
227 | testView1 = getLayoutInflater().inflate(R.layout.test_view2, null);
228 | weekView.addViewToCell(1, testView1);
229 | testView1 = getLayoutInflater().inflate(R.layout.test_view2, null);
230 | weekView.addViewToCell(2, testView1);
231 | testView1 = getLayoutInflater().inflate(R.layout.test_view2, null);
232 | weekView.addViewToCell(3, testView1);
233 | } else {
234 | MonthView mMonthView = (MonthView) mCalendarView;
235 |
236 | View testView1 = getLayoutInflater().inflate(R.layout.test_view1, null);
237 | mMonthView.addViewToDayInCurrentMonth(1, testView1);
238 | testView1 = getLayoutInflater().inflate(R.layout.test_view1, null);
239 | mMonthView.addViewToDayInCurrentMonth(2, testView1);
240 | testView1 = getLayoutInflater().inflate(R.layout.test_view2, null);
241 | mMonthView.addViewToDayInCurrentMonth(2, testView1);
242 | testView1 = getLayoutInflater().inflate(R.layout.test_view2, null);
243 | mMonthView.addViewToDayInCurrentMonth(2, testView1);
244 | testView1 = getLayoutInflater().inflate(R.layout.test_view2, null);
245 | mMonthView.addViewToDayInCurrentMonth(3, testView1);
246 | testView1 = getLayoutInflater().inflate(R.layout.test_view2, null);
247 | mMonthView.addViewToDayInCurrentMonth(4, testView1);
248 |
249 | testView1 = getLayoutInflater().inflate(R.layout.test_view1, null);
250 | mMonthView.addViewToDayInCurrentMonth(30, testView1);
251 | testView1 = getLayoutInflater().inflate(R.layout.test_view1, null);
252 | mMonthView.addViewToDayInCurrentMonth(31, testView1);
253 |
254 | // Invalid day gets ignored
255 | testView1 = getLayoutInflater().inflate(R.layout.test_view1, null);
256 | mMonthView.addViewToDayInCurrentMonth(32, testView1);
257 |
258 | // Out of month cells get placed, but will get discarded if the
259 | // start of the week changes
260 | for (int i = 0; i < mMonthView.getFirstCellOfMonth(); i++) {
261 | testView1 = getLayoutInflater().inflate(R.layout.test_view2, null);
262 | mMonthView.addViewToCell(i, testView1);
263 | }
264 | for (int i = mMonthView.getLastCellOfMonth(); i < MonthView.DAYS_IN_GRID; i++) {
265 | testView1 = getLayoutInflater().inflate(R.layout.test_view2, null);
266 | mMonthView.addViewToCell(i, testView1);
267 | }
268 | }
269 | }
270 | }
271 |
--------------------------------------------------------------------------------