├── settings.gradle ├── demo.gif ├── header.png ├── library ├── gradle.properties ├── src │ └── main │ │ ├── AndroidManifest.xml │ │ ├── res │ │ ├── drawable-hdpi │ │ │ └── ic_launcher.png │ │ ├── drawable-mdpi │ │ │ └── ic_launcher.png │ │ ├── drawable-xhdpi │ │ │ └── ic_launcher.png │ │ ├── drawable-xxhdpi │ │ │ └── ic_launcher.png │ │ └── values │ │ │ ├── strings.xml │ │ │ ├── colors.xml │ │ │ ├── dimens.xml │ │ │ └── attrs.xml │ │ └── java │ │ └── com │ │ └── andexert │ │ └── calendarlistview │ │ └── library │ │ ├── DatePickerController.java │ │ ├── CalendarUtils.java │ │ ├── DayPickerView.java │ │ ├── SimpleMonthAdapter.java │ │ └── SimpleMonthView.java ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── LICENSE.txt ├── sample ├── gradle.properties ├── src │ └── main │ │ ├── res │ │ ├── drawable-hdpi │ │ │ └── ic_launcher.png │ │ ├── drawable-mdpi │ │ │ └── ic_launcher.png │ │ ├── drawable-xhdpi │ │ │ └── ic_launcher.png │ │ ├── drawable-xxhdpi │ │ │ └── ic_launcher.png │ │ ├── values │ │ │ ├── styles.xml │ │ │ ├── dimens.xml │ │ │ └── strings.xml │ │ ├── menu │ │ │ └── main.xml │ │ ├── values-w820dp │ │ │ └── dimens.xml │ │ └── layout │ │ │ └── activity_main.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── com │ │ └── andexert │ │ └── sample │ │ └── MainActivity.java ├── .gitignore └── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── LICENSE.txt ├── gradlew.bat ├── README.md └── gradlew /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':library', ':sample' 2 | -------------------------------------------------------------------------------- /demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/traex/CalendarListview/HEAD/demo.gif -------------------------------------------------------------------------------- /header.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/traex/CalendarListview/HEAD/header.png -------------------------------------------------------------------------------- /library/gradle.properties: -------------------------------------------------------------------------------- 1 | POM_NAME=CalendarListview Library 2 | POM_ARTIFACT_ID=library 3 | POM_PACKAGING=aar -------------------------------------------------------------------------------- /sample/gradle.properties: -------------------------------------------------------------------------------- 1 | POM_NAME=CalendarListview Sample 2 | POM_ARTIFACT_ID=sample 3 | POM_PACKAGING=aar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/traex/CalendarListview/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /library/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/traex/CalendarListview/HEAD/library/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /library/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/traex/CalendarListview/HEAD/library/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/traex/CalendarListview/HEAD/sample/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/traex/CalendarListview/HEAD/sample/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/traex/CalendarListview/HEAD/sample/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /library/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/traex/CalendarListview/HEAD/library/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /library/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/traex/CalendarListview/HEAD/library/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/traex/CalendarListview/HEAD/sample/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /library/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | CalendarListview 3 | 4 | 5 | sans-serif 6 | 7 | -------------------------------------------------------------------------------- /sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /sample/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /library/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #ff999999 5 | #E75F49 6 | #fff2f2f2 7 | -------------------------------------------------------------------------------- /sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | sample 5 | Hello world! 6 | Settings 7 | 8 | 9 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Dec 10 14:37:29 CET 2014 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-2.2.1-all.zip 7 | -------------------------------------------------------------------------------- /sample/src/main/res/menu/main.xml: -------------------------------------------------------------------------------- 1 | 4 | 8 | 9 | -------------------------------------------------------------------------------- /library/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16sp 4 | 16sp 5 | 10sp 6 | 50dip 7 | 16dip 8 | 270dip 9 | -------------------------------------------------------------------------------- /sample/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /sample/.gitignore: -------------------------------------------------------------------------------- 1 | #Android generated 2 | bin 3 | gen 4 | 5 | #Eclipse 6 | .project 7 | .classpath 8 | .settings 9 | 10 | #IntelliJ IDEA 11 | .idea 12 | *.iml 13 | *.ipr 14 | *.iws 15 | out 16 | 17 | #Maven 18 | target 19 | release.properties 20 | pom.xml.* 21 | project.properties 22 | 23 | #Ant 24 | build.xml 25 | local.properties 26 | proguard.cfg 27 | 28 | #OSX 29 | .DS_Store 30 | 31 | # Crashlytics 32 | com_crashlytics_export_strings.xml 33 | crashlytics-build.properties 34 | crashlytics.properties -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | #Android generated 2 | bin 3 | gen 4 | 5 | #Eclipse 6 | .project 7 | .classpath 8 | .settings 9 | 10 | #IntelliJ IDEA 11 | .idea 12 | *.iml 13 | *.ipr 14 | *.iws 15 | out 16 | 17 | #Gradle 18 | .gradle 19 | build 20 | 21 | #Maven 22 | target 23 | release.properties 24 | pom.xml.* 25 | project.properties 26 | 27 | #Ant 28 | build.xml 29 | local.properties 30 | gradle.properties 31 | proguard.cfg 32 | 33 | #OSX 34 | .DS_Store/ 35 | 36 | # Crashlytics 37 | com_crashlytics_export_strings.xml 38 | crashlytics-build.properties 39 | crashlytics.properties -------------------------------------------------------------------------------- /library/.gitignore: -------------------------------------------------------------------------------- 1 | #Android generated 2 | bin 3 | gen 4 | 5 | #Eclipse 6 | .project 7 | .classpath 8 | .settings 9 | 10 | #IntelliJ IDEA 11 | .idea 12 | *.iml 13 | *.ipr 14 | *.iws 15 | out 16 | 17 | #Gradle 18 | .gradle 19 | build 20 | 21 | #Maven 22 | target 23 | release.properties 24 | pom.xml.* 25 | project.properties 26 | 27 | #Ant 28 | build.xml 29 | local.properties 30 | gradle.properties 31 | proguard.cfg 32 | 33 | #OSX 34 | .DS_Store/ 35 | 36 | # Crashlytics 37 | com_crashlytics_export_strings.xml 38 | crashlytics-build.properties 39 | crashlytics.properties -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 22 5 | buildToolsVersion "22.0.1" 6 | 7 | defaultConfig { 8 | applicationId "com.andexert.sample" 9 | minSdkVersion 14 10 | targetSdkVersion 21 11 | versionCode 8 12 | versionName "1.2.3" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | compile project(':library') 25 | } -------------------------------------------------------------------------------- /library/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 22 5 | buildToolsVersion "22.0.1" 6 | 7 | defaultConfig { 8 | minSdkVersion 10 9 | targetSdkVersion 22 10 | versionCode 9 11 | versionName "1.2.3" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | compile fileTree(dir: 'libs', include: ['*.jar']) 23 | compile 'com.android.support:appcompat-v7:21.0.3' 24 | compile 'com.android.support:recyclerview-v7:21.0.3' 25 | } 26 | 27 | -------------------------------------------------------------------------------- /library/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/robin.chutaux/Documents/adt/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 | -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Robin Chutaux 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /library/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Robin Chutaux 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /library/src/main/java/com/andexert/calendarlistview/library/DatePickerController.java: -------------------------------------------------------------------------------- 1 | /*********************************************************************************** 2 | * The MIT License (MIT) 3 | 4 | * Copyright (c) 2014 Robin Chutaux 5 | 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ***********************************************************************************/ 24 | package com.andexert.calendarlistview.library; 25 | 26 | public interface DatePickerController { 27 | public abstract int getMaxYear(); 28 | 29 | public abstract void onDayOfMonthSelected(int year, int month, int day); 30 | 31 | public abstract void onDateRangeSelected(final SimpleMonthAdapter.SelectedDays selectedDays); 32 | 33 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/andexert/sample/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.andexert.sample; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.util.Log; 6 | import android.view.Menu; 7 | import android.view.MenuItem; 8 | 9 | import com.andexert.calendarlistview.library.DayPickerView; 10 | import com.andexert.calendarlistview.library.SimpleMonthAdapter; 11 | 12 | 13 | public class MainActivity extends Activity implements com.andexert.calendarlistview.library.DatePickerController { 14 | 15 | private DayPickerView dayPickerView; 16 | 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | setContentView(R.layout.activity_main); 21 | 22 | dayPickerView = (DayPickerView) findViewById(R.id.pickerView); 23 | dayPickerView.setController(this); 24 | } 25 | 26 | 27 | @Override 28 | public boolean onCreateOptionsMenu(Menu menu) { 29 | // Inflate the menu; this adds items to the action bar if it is present. 30 | getMenuInflater().inflate(R.menu.main, menu); 31 | return true; 32 | } 33 | 34 | @Override 35 | public boolean onOptionsItemSelected(MenuItem item) { 36 | // Handle action bar item clicks here. The action bar will 37 | // automatically handle clicks on the Home/Up button, so long 38 | // as you specify a parent activity in AndroidManifest.xml. 39 | int id = item.getItemId(); 40 | if (id == R.id.action_settings) { 41 | return true; 42 | } 43 | return super.onOptionsItemSelected(item); 44 | } 45 | 46 | @Override 47 | public int getMaxYear() 48 | { 49 | return 2015; 50 | } 51 | 52 | @Override 53 | public void onDayOfMonthSelected(int year, int month, int day) 54 | { 55 | Log.e("Day Selected", day + " / " + month + " / " + year); 56 | } 57 | 58 | @Override 59 | public void onDateRangeSelected(SimpleMonthAdapter.SelectedDays selectedDays) 60 | { 61 | 62 | Log.e("Date range selected", selectedDays.getFirst().toString() + " --> " + selectedDays.getLast().toString()); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /library/src/main/java/com/andexert/calendarlistview/library/CalendarUtils.java: -------------------------------------------------------------------------------- 1 | /*********************************************************************************** 2 | * The MIT License (MIT) 3 | 4 | * Copyright (c) 2014 Robin Chutaux 5 | 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ***********************************************************************************/ 24 | package com.andexert.calendarlistview.library; 25 | 26 | import java.util.Calendar; 27 | 28 | 29 | public class CalendarUtils 30 | { 31 | public static int getDaysInMonth(int month, int year) { 32 | switch (month) { 33 | case Calendar.JANUARY: 34 | case Calendar.MARCH: 35 | case Calendar.MAY: 36 | case Calendar.JULY: 37 | case Calendar.AUGUST: 38 | case Calendar.OCTOBER: 39 | case Calendar.DECEMBER: 40 | return 31; 41 | case Calendar.APRIL: 42 | case Calendar.JUNE: 43 | case Calendar.SEPTEMBER: 44 | case Calendar.NOVEMBER: 45 | return 30; 46 | case Calendar.FEBRUARY: 47 | return ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) ? 29 : 28; 48 | default: 49 | throw new IllegalArgumentException("Invalid Month"); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /library/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /library/src/main/java/com/andexert/calendarlistview/library/DayPickerView.java: -------------------------------------------------------------------------------- 1 | /*********************************************************************************** 2 | * The MIT License (MIT) 3 | 4 | * Copyright (c) 2014 Robin Chutaux 5 | 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ***********************************************************************************/ 24 | package com.andexert.calendarlistview.library; 25 | 26 | import android.content.Context; 27 | import android.content.res.TypedArray; 28 | import android.support.v7.widget.LinearLayoutManager; 29 | import android.support.v7.widget.RecyclerView; 30 | import android.util.AttributeSet; 31 | 32 | public class DayPickerView extends RecyclerView 33 | { 34 | protected Context mContext; 35 | protected SimpleMonthAdapter mAdapter; 36 | private DatePickerController mController; 37 | protected int mCurrentScrollState = 0; 38 | protected long mPreviousScrollPosition; 39 | protected int mPreviousScrollState = 0; 40 | private TypedArray typedArray; 41 | private OnScrollListener onScrollListener; 42 | 43 | public DayPickerView(Context context) 44 | { 45 | this(context, null); 46 | } 47 | 48 | public DayPickerView(Context context, AttributeSet attrs) 49 | { 50 | this(context, attrs, 0); 51 | } 52 | 53 | public DayPickerView(Context context, AttributeSet attrs, int defStyle) 54 | { 55 | super(context, attrs, defStyle); 56 | if (!isInEditMode()) 57 | { 58 | typedArray = context.obtainStyledAttributes(attrs, R.styleable.DayPickerView); 59 | setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); 60 | init(context); 61 | } 62 | } 63 | 64 | public void setController(DatePickerController mController) 65 | { 66 | this.mController = mController; 67 | setUpAdapter(); 68 | setAdapter(mAdapter); 69 | } 70 | 71 | 72 | public void init(Context paramContext) { 73 | setLayoutManager(new LinearLayoutManager(paramContext)); 74 | mContext = paramContext; 75 | setUpListView(); 76 | 77 | onScrollListener = new OnScrollListener() 78 | { 79 | @Override 80 | public void onScrolled(RecyclerView recyclerView, int dx, int dy) 81 | { 82 | super.onScrolled(recyclerView, dx, dy); 83 | final SimpleMonthView child = (SimpleMonthView) recyclerView.getChildAt(0); 84 | if (child == null) { 85 | return; 86 | } 87 | 88 | mPreviousScrollPosition = dy; 89 | mPreviousScrollState = mCurrentScrollState; 90 | } 91 | }; 92 | } 93 | 94 | 95 | protected void setUpAdapter() { 96 | if (mAdapter == null) { 97 | mAdapter = new SimpleMonthAdapter(getContext(), mController, typedArray); 98 | } 99 | mAdapter.notifyDataSetChanged(); 100 | } 101 | 102 | protected void setUpListView() { 103 | setVerticalScrollBarEnabled(false); 104 | setOnScrollListener(onScrollListener); 105 | setFadingEdgeLength(0); 106 | } 107 | 108 | public SimpleMonthAdapter.SelectedDays getSelectedDays() 109 | { 110 | return mAdapter.getSelectedDays(); 111 | } 112 | 113 | protected DatePickerController getController() 114 | { 115 | return mController; 116 | } 117 | 118 | protected TypedArray getTypedArray() 119 | { 120 | return typedArray; 121 | } 122 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | CalendarListview 2 | ================ 3 | 4 | ![CalendarListview](https://github.com/traex/CalendarListview/blob/master/header.png) 5 | 6 | CalendarListview provides a easy way to select dates with a calendar for API 10+. [You can find a sample](https://github.com/traex/CalendarListview/blob/master/sample/) that show how to add DatePickerView to your layout without customization. 7 | 8 | ![CalendarListview GIF](https://github.com/traex/CalendarListview/blob/master/demo.gif) 9 | 10 | ### Integration 11 | The lib is available on Maven Central, you can find it with [Gradle, please](http://gradleplease.appspot.com/#calendarlistview) 12 | ``` xml 13 | 14 | dependencies { 15 | compile 'com.github.traex.calendarlistview:library:1.2.3' 16 | } 17 | 18 | ``` 19 | 20 | ### Usage 21 | 22 | Declare a DayPickerView inside your layout XML file: 23 | 24 | ``` xml 25 | 26 | 31 | 32 | ``` 33 | 34 | Next, you have to implement `DatePickerController` in your Activity or your Fragment. You will have to set `getMaxYear` and `onDayOfMonthSelected`. The first one is the max year between the current one and this maxYear. The second one is called every time user selects a new date. 35 | 36 | ``` java 37 | 38 | @Override 39 | public int getMaxYear() 40 | { 41 | return 2015; 42 | } 43 | 44 | @Override 45 | public void onDayOfMonthSelected(int year, int month, int day) 46 | { 47 | Log.e("Day Selected", day + " / " + month + " / " + year); 48 | } 49 | 50 | ``` 51 | 52 | --- 53 | 54 | ### Customization 55 | 56 | CalendarListview is fully customizable: 57 | 58 | * app:colorCurrentDay [color def:#ff999999] --> The current day is always in bold but you can change its color 59 | * app:colorSelectedDayBackground [color def:#E75F49] --> If you click on a day, a circle indicator or a rouded rectangle indicator will be draw. 60 | * app:colorSelectedDayText [color def:#fff2f2f2] --> This is the text color of a selected day 61 | * app:colorPreviousDay [color def:#ff999999] --> In the current month you can choose to have a specific color for the past days 62 | * app:colorNormalDay [color def:#ff999999] --> Default text color for a day 63 | * app:colorMonthName [color def:#ff999999] --> Month name and year text color 64 | * app:colorDayName [color def:#ff999999] --> Day name text color 65 | * app:textSizeDay [dimension def:16sp] --> Font size for numeric day 66 | * app:textSizeMonth [dimension def:16sp] --> Font size for month name 67 | * app:textSizeDayName [dimension def:10sp] --> Font size for day name 68 | * app:headerMonthHeight [dimension def:50dip] --> Height of month name 69 | * app:drawRoundRect [boolean def:false] --> Draw a rounded rectangle for selected days instead of a circle 70 | * app:selectedDayRadius [dimension def:16dip] --> Set radius if you use default circle indicator 71 | * app:calendarHeight [dimension def:270dip] --> Height of each month/row 72 | * app:enablePreviousDay [boolean def:true] --> Enable past days in current month 73 | * app:currentDaySelected [boolean def:false] --> Select current day by default 74 | * app:firstMonth [enum def:-1] --> Start listview at the specified month 75 | * app:lastMonth [enum def:-1] --> End listview at the specified month 76 | 77 | ### Contact 78 | 79 | You can reach me at [+RobinChutaux](https://plus.google.com/+RobinChutaux) or for technical support feel free to open an issue [here](https://github.com/traex/CalendarListview/issues) :) 80 | 81 | ### Acknowledgements 82 | 83 | Thanks to [Flavien Laurent](https://github.com/flavienlaurent) for his [DateTimePicker](https://github.com/flavienlaurent/datetimepicker). 84 | 85 | ### MIT License 86 | 87 | ``` 88 | The MIT License (MIT) 89 | 90 | Copyright (c) 2014 Robin Chutaux 91 | 92 | Permission is hereby granted, free of charge, to any person obtaining a copy 93 | of this software and associated documentation files (the "Software"), to deal 94 | in the Software without restriction, including without limitation the rights 95 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 96 | copies of the Software, and to permit persons to whom the Software is 97 | furnished to do so, subject to the following conditions: 98 | 99 | The above copyright notice and this permission notice shall be included in 100 | all copies or substantial portions of the Software. 101 | 102 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 103 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 104 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 105 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 106 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 107 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 108 | THE SOFTWARE. 109 | ``` 110 | -------------------------------------------------------------------------------- /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 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 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 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /library/src/main/java/com/andexert/calendarlistview/library/SimpleMonthAdapter.java: -------------------------------------------------------------------------------- 1 | /*********************************************************************************** 2 | * The MIT License (MIT) 3 | 4 | * Copyright (c) 2014 Robin Chutaux 5 | 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ***********************************************************************************/ 24 | package com.andexert.calendarlistview.library; 25 | 26 | import android.content.Context; 27 | import android.content.res.TypedArray; 28 | import android.support.v7.widget.RecyclerView; 29 | import android.view.View; 30 | import android.view.ViewGroup; 31 | import android.view.ViewGroup.LayoutParams; 32 | import android.widget.AbsListView; 33 | 34 | import java.io.Serializable; 35 | import java.util.Calendar; 36 | import java.util.Date; 37 | import java.util.HashMap; 38 | 39 | public class SimpleMonthAdapter extends RecyclerView.Adapter implements SimpleMonthView.OnDayClickListener { 40 | protected static final int MONTHS_IN_YEAR = 12; 41 | private final TypedArray typedArray; 42 | private final Context mContext; 43 | private final DatePickerController mController; 44 | private final Calendar calendar; 45 | private final SelectedDays selectedDays; 46 | private final Integer firstMonth; 47 | private final Integer lastMonth; 48 | 49 | public SimpleMonthAdapter(Context context, DatePickerController datePickerController, TypedArray typedArray) { 50 | this.typedArray = typedArray; 51 | calendar = Calendar.getInstance(); 52 | firstMonth = typedArray.getInt(R.styleable.DayPickerView_firstMonth, calendar.get(Calendar.MONTH)); 53 | lastMonth = typedArray.getInt(R.styleable.DayPickerView_lastMonth, (calendar.get(Calendar.MONTH) - 1) % MONTHS_IN_YEAR); 54 | selectedDays = new SelectedDays<>(); 55 | mContext = context; 56 | mController = datePickerController; 57 | init(); 58 | } 59 | 60 | @Override 61 | public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) 62 | { 63 | final SimpleMonthView simpleMonthView = new SimpleMonthView(mContext, typedArray); 64 | return new ViewHolder(simpleMonthView, this); 65 | } 66 | 67 | @Override 68 | public void onBindViewHolder(ViewHolder viewHolder, int position) 69 | { 70 | final SimpleMonthView v = viewHolder.simpleMonthView; 71 | final HashMap drawingParams = new HashMap(); 72 | int month; 73 | int year; 74 | 75 | month = (firstMonth + (position % MONTHS_IN_YEAR)) % MONTHS_IN_YEAR; 76 | year = position / MONTHS_IN_YEAR + calendar.get(Calendar.YEAR) + ((firstMonth + (position % MONTHS_IN_YEAR)) / MONTHS_IN_YEAR); 77 | 78 | int selectedFirstDay = -1; 79 | int selectedLastDay = -1; 80 | int selectedFirstMonth = -1; 81 | int selectedLastMonth = -1; 82 | int selectedFirstYear = -1; 83 | int selectedLastYear = -1; 84 | 85 | if (selectedDays.getFirst() != null) 86 | { 87 | selectedFirstDay = selectedDays.getFirst().day; 88 | selectedFirstMonth = selectedDays.getFirst().month; 89 | selectedFirstYear = selectedDays.getFirst().year; 90 | } 91 | 92 | if (selectedDays.getLast() != null) 93 | { 94 | selectedLastDay = selectedDays.getLast().day; 95 | selectedLastMonth = selectedDays.getLast().month; 96 | selectedLastYear = selectedDays.getLast().year; 97 | } 98 | 99 | v.reuse(); 100 | 101 | drawingParams.put(SimpleMonthView.VIEW_PARAMS_SELECTED_BEGIN_YEAR, selectedFirstYear); 102 | drawingParams.put(SimpleMonthView.VIEW_PARAMS_SELECTED_LAST_YEAR, selectedLastYear); 103 | drawingParams.put(SimpleMonthView.VIEW_PARAMS_SELECTED_BEGIN_MONTH, selectedFirstMonth); 104 | drawingParams.put(SimpleMonthView.VIEW_PARAMS_SELECTED_LAST_MONTH, selectedLastMonth); 105 | drawingParams.put(SimpleMonthView.VIEW_PARAMS_SELECTED_BEGIN_DAY, selectedFirstDay); 106 | drawingParams.put(SimpleMonthView.VIEW_PARAMS_SELECTED_LAST_DAY, selectedLastDay); 107 | drawingParams.put(SimpleMonthView.VIEW_PARAMS_YEAR, year); 108 | drawingParams.put(SimpleMonthView.VIEW_PARAMS_MONTH, month); 109 | drawingParams.put(SimpleMonthView.VIEW_PARAMS_WEEK_START, calendar.getFirstDayOfWeek()); 110 | v.setMonthParams(drawingParams); 111 | v.invalidate(); 112 | } 113 | 114 | public long getItemId(int position) { 115 | return position; 116 | } 117 | 118 | @Override 119 | public int getItemCount() 120 | { 121 | int itemCount = (((mController.getMaxYear() - calendar.get(Calendar.YEAR)) + 1) * MONTHS_IN_YEAR); 122 | 123 | if (firstMonth != -1) 124 | itemCount -= firstMonth; 125 | 126 | if (lastMonth != -1) 127 | itemCount -= (MONTHS_IN_YEAR - lastMonth) - 1; 128 | 129 | return itemCount; 130 | } 131 | 132 | public static class ViewHolder extends RecyclerView.ViewHolder 133 | { 134 | final SimpleMonthView simpleMonthView; 135 | 136 | public ViewHolder(View itemView, SimpleMonthView.OnDayClickListener onDayClickListener) 137 | { 138 | super(itemView); 139 | simpleMonthView = (SimpleMonthView) itemView; 140 | simpleMonthView.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); 141 | simpleMonthView.setClickable(true); 142 | simpleMonthView.setOnDayClickListener(onDayClickListener); 143 | } 144 | } 145 | 146 | protected void init() { 147 | if (typedArray.getBoolean(R.styleable.DayPickerView_currentDaySelected, false)) 148 | onDayTapped(new CalendarDay(System.currentTimeMillis())); 149 | } 150 | 151 | public void onDayClick(SimpleMonthView simpleMonthView, CalendarDay calendarDay) { 152 | if (calendarDay != null) { 153 | onDayTapped(calendarDay); 154 | } 155 | } 156 | 157 | protected void onDayTapped(CalendarDay calendarDay) { 158 | mController.onDayOfMonthSelected(calendarDay.year, calendarDay.month, calendarDay.day); 159 | setSelectedDay(calendarDay); 160 | } 161 | 162 | public void setSelectedDay(CalendarDay calendarDay) { 163 | if (selectedDays.getFirst() != null && selectedDays.getLast() == null) 164 | { 165 | selectedDays.setLast(calendarDay); 166 | 167 | if (selectedDays.getFirst().month < calendarDay.month) 168 | { 169 | for (int i = 0; i < selectedDays.getFirst().month - calendarDay.month - 1; ++i) 170 | mController.onDayOfMonthSelected(selectedDays.getFirst().year, selectedDays.getFirst().month + i, selectedDays.getFirst().day); 171 | } 172 | 173 | mController.onDateRangeSelected(selectedDays); 174 | } 175 | else if (selectedDays.getLast() != null) 176 | { 177 | selectedDays.setFirst(calendarDay); 178 | selectedDays.setLast(null); 179 | } 180 | else 181 | selectedDays.setFirst(calendarDay); 182 | 183 | notifyDataSetChanged(); 184 | } 185 | 186 | public static class CalendarDay implements Serializable 187 | { 188 | private static final long serialVersionUID = -5456695978688356202L; 189 | private Calendar calendar; 190 | 191 | int day; 192 | int month; 193 | int year; 194 | 195 | public CalendarDay() { 196 | setTime(System.currentTimeMillis()); 197 | } 198 | 199 | public CalendarDay(int year, int month, int day) { 200 | setDay(year, month, day); 201 | } 202 | 203 | public CalendarDay(long timeInMillis) { 204 | setTime(timeInMillis); 205 | } 206 | 207 | public CalendarDay(Calendar calendar) { 208 | year = calendar.get(Calendar.YEAR); 209 | month = calendar.get(Calendar.MONTH); 210 | day = calendar.get(Calendar.DAY_OF_MONTH); 211 | } 212 | 213 | private void setTime(long timeInMillis) { 214 | if (calendar == null) { 215 | calendar = Calendar.getInstance(); 216 | } 217 | calendar.setTimeInMillis(timeInMillis); 218 | month = this.calendar.get(Calendar.MONTH); 219 | year = this.calendar.get(Calendar.YEAR); 220 | day = this.calendar.get(Calendar.DAY_OF_MONTH); 221 | } 222 | 223 | public void set(CalendarDay calendarDay) { 224 | year = calendarDay.year; 225 | month = calendarDay.month; 226 | day = calendarDay.day; 227 | } 228 | 229 | public void setDay(int year, int month, int day) { 230 | this.year = year; 231 | this.month = month; 232 | this.day = day; 233 | } 234 | 235 | public Date getDate() 236 | { 237 | if (calendar == null) { 238 | calendar = Calendar.getInstance(); 239 | } 240 | calendar.set(year, month, day); 241 | return calendar.getTime(); 242 | } 243 | 244 | @Override 245 | public String toString() 246 | { 247 | final StringBuilder stringBuilder = new StringBuilder(); 248 | stringBuilder.append("{ year: "); 249 | stringBuilder.append(year); 250 | stringBuilder.append(", month: "); 251 | stringBuilder.append(month); 252 | stringBuilder.append(", day: "); 253 | stringBuilder.append(day); 254 | stringBuilder.append(" }"); 255 | 256 | return stringBuilder.toString(); 257 | } 258 | } 259 | 260 | public SelectedDays getSelectedDays() 261 | { 262 | return selectedDays; 263 | } 264 | 265 | public static class SelectedDays implements Serializable 266 | { 267 | private static final long serialVersionUID = 3942549765282708376L; 268 | private K first; 269 | private K last; 270 | 271 | public K getFirst() 272 | { 273 | return first; 274 | } 275 | 276 | public void setFirst(K first) 277 | { 278 | this.first = first; 279 | } 280 | 281 | public K getLast() 282 | { 283 | return last; 284 | } 285 | 286 | public void setLast(K last) 287 | { 288 | this.last = last; 289 | } 290 | } 291 | } -------------------------------------------------------------------------------- /library/src/main/java/com/andexert/calendarlistview/library/SimpleMonthView.java: -------------------------------------------------------------------------------- 1 | /*********************************************************************************** 2 | * The MIT License (MIT) 3 | 4 | * Copyright (c) 2014 Robin Chutaux 5 | 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | ***********************************************************************************/ 24 | package com.andexert.calendarlistview.library; 25 | 26 | import android.content.Context; 27 | import android.content.res.Resources; 28 | import android.content.res.TypedArray; 29 | import android.graphics.Canvas; 30 | import android.graphics.Paint; 31 | import android.graphics.Paint.Align; 32 | import android.graphics.Paint.Style; 33 | import android.graphics.RectF; 34 | import android.graphics.Typeface; 35 | import android.text.format.DateUtils; 36 | import android.text.format.Time; 37 | import android.view.MotionEvent; 38 | import android.view.View; 39 | 40 | import java.security.InvalidParameterException; 41 | import java.text.DateFormatSymbols; 42 | import java.util.Calendar; 43 | import java.util.HashMap; 44 | import java.util.Locale; 45 | 46 | class SimpleMonthView extends View 47 | { 48 | 49 | public static final String VIEW_PARAMS_HEIGHT = "height"; 50 | public static final String VIEW_PARAMS_MONTH = "month"; 51 | public static final String VIEW_PARAMS_YEAR = "year"; 52 | public static final String VIEW_PARAMS_SELECTED_BEGIN_DAY = "selected_begin_day"; 53 | public static final String VIEW_PARAMS_SELECTED_LAST_DAY = "selected_last_day"; 54 | public static final String VIEW_PARAMS_SELECTED_BEGIN_MONTH = "selected_begin_month"; 55 | public static final String VIEW_PARAMS_SELECTED_LAST_MONTH = "selected_last_month"; 56 | public static final String VIEW_PARAMS_SELECTED_BEGIN_YEAR = "selected_begin_year"; 57 | public static final String VIEW_PARAMS_SELECTED_LAST_YEAR = "selected_last_year"; 58 | public static final String VIEW_PARAMS_WEEK_START = "week_start"; 59 | 60 | private static final int SELECTED_CIRCLE_ALPHA = 128; 61 | protected static int DEFAULT_HEIGHT = 32; 62 | protected static final int DEFAULT_NUM_ROWS = 6; 63 | protected static int DAY_SELECTED_CIRCLE_SIZE; 64 | protected static int DAY_SEPARATOR_WIDTH = 1; 65 | protected static int MINI_DAY_NUMBER_TEXT_SIZE; 66 | protected static int MIN_HEIGHT = 10; 67 | protected static int MONTH_DAY_LABEL_TEXT_SIZE; 68 | protected static int MONTH_HEADER_SIZE; 69 | protected static int MONTH_LABEL_TEXT_SIZE; 70 | 71 | protected int mPadding = 0; 72 | 73 | private String mDayOfWeekTypeface; 74 | private String mMonthTitleTypeface; 75 | 76 | protected Paint mMonthDayLabelPaint; 77 | protected Paint mMonthNumPaint; 78 | protected Paint mMonthTitleBGPaint; 79 | protected Paint mMonthTitlePaint; 80 | protected Paint mSelectedCirclePaint; 81 | protected int mCurrentDayTextColor; 82 | protected int mMonthTextColor; 83 | protected int mDayTextColor; 84 | protected int mDayNumColor; 85 | protected int mMonthTitleBGColor; 86 | protected int mPreviousDayColor; 87 | protected int mSelectedDaysColor; 88 | 89 | private final StringBuilder mStringBuilder; 90 | 91 | protected boolean mHasToday = false; 92 | protected boolean mIsPrev = false; 93 | protected int mSelectedBeginDay = -1; 94 | protected int mSelectedLastDay = -1; 95 | protected int mSelectedBeginMonth = -1; 96 | protected int mSelectedLastMonth = -1; 97 | protected int mSelectedBeginYear = -1; 98 | protected int mSelectedLastYear = -1; 99 | protected int mToday = -1; 100 | protected int mWeekStart = 1; 101 | protected int mNumDays = 7; 102 | protected int mNumCells = mNumDays; 103 | private int mDayOfWeekStart = 0; 104 | protected int mMonth; 105 | protected Boolean mDrawRect; 106 | protected int mRowHeight = DEFAULT_HEIGHT; 107 | protected int mWidth; 108 | protected int mYear; 109 | final Time today; 110 | 111 | private final Calendar mCalendar; 112 | private final Calendar mDayLabelCalendar; 113 | private final Boolean isPrevDayEnabled; 114 | 115 | private int mNumRows = DEFAULT_NUM_ROWS; 116 | 117 | private DateFormatSymbols mDateFormatSymbols = new DateFormatSymbols(); 118 | 119 | private OnDayClickListener mOnDayClickListener; 120 | 121 | public SimpleMonthView(Context context, TypedArray typedArray) 122 | { 123 | super(context); 124 | 125 | Resources resources = context.getResources(); 126 | mDayLabelCalendar = Calendar.getInstance(); 127 | mCalendar = Calendar.getInstance(); 128 | today = new Time(Time.getCurrentTimezone()); 129 | today.setToNow(); 130 | mDayOfWeekTypeface = resources.getString(R.string.sans_serif); 131 | mMonthTitleTypeface = resources.getString(R.string.sans_serif); 132 | mCurrentDayTextColor = typedArray.getColor(R.styleable.DayPickerView_colorCurrentDay, resources.getColor(R.color.normal_day)); 133 | mMonthTextColor = typedArray.getColor(R.styleable.DayPickerView_colorMonthName, resources.getColor(R.color.normal_day)); 134 | mDayTextColor = typedArray.getColor(R.styleable.DayPickerView_colorDayName, resources.getColor(R.color.normal_day)); 135 | mDayNumColor = typedArray.getColor(R.styleable.DayPickerView_colorNormalDay, resources.getColor(R.color.normal_day)); 136 | mPreviousDayColor = typedArray.getColor(R.styleable.DayPickerView_colorPreviousDay, resources.getColor(R.color.normal_day)); 137 | mSelectedDaysColor = typedArray.getColor(R.styleable.DayPickerView_colorSelectedDayBackground, resources.getColor(R.color.selected_day_background)); 138 | mMonthTitleBGColor = typedArray.getColor(R.styleable.DayPickerView_colorSelectedDayText, resources.getColor(R.color.selected_day_text)); 139 | 140 | mDrawRect = typedArray.getBoolean(R.styleable.DayPickerView_drawRoundRect, false); 141 | 142 | mStringBuilder = new StringBuilder(50); 143 | 144 | MINI_DAY_NUMBER_TEXT_SIZE = typedArray.getDimensionPixelSize(R.styleable.DayPickerView_textSizeDay, resources.getDimensionPixelSize(R.dimen.text_size_day)); 145 | MONTH_LABEL_TEXT_SIZE = typedArray.getDimensionPixelSize(R.styleable.DayPickerView_textSizeMonth, resources.getDimensionPixelSize(R.dimen.text_size_month)); 146 | MONTH_DAY_LABEL_TEXT_SIZE = typedArray.getDimensionPixelSize(R.styleable.DayPickerView_textSizeDayName, resources.getDimensionPixelSize(R.dimen.text_size_day_name)); 147 | MONTH_HEADER_SIZE = typedArray.getDimensionPixelOffset(R.styleable.DayPickerView_headerMonthHeight, resources.getDimensionPixelOffset(R.dimen.header_month_height)); 148 | DAY_SELECTED_CIRCLE_SIZE = typedArray.getDimensionPixelSize(R.styleable.DayPickerView_selectedDayRadius, resources.getDimensionPixelOffset(R.dimen.selected_day_radius)); 149 | 150 | mRowHeight = ((typedArray.getDimensionPixelSize(R.styleable.DayPickerView_calendarHeight, resources.getDimensionPixelOffset(R.dimen.calendar_height)) - MONTH_HEADER_SIZE) / 6); 151 | 152 | isPrevDayEnabled = typedArray.getBoolean(R.styleable.DayPickerView_enablePreviousDay, true); 153 | 154 | initView(); 155 | 156 | } 157 | 158 | private int calculateNumRows() { 159 | int offset = findDayOffset(); 160 | int dividend = (offset + mNumCells) / mNumDays; 161 | int remainder = (offset + mNumCells) % mNumDays; 162 | return (dividend + (remainder > 0 ? 1 : 0)); 163 | } 164 | 165 | private void drawMonthDayLabels(Canvas canvas) { 166 | int y = MONTH_HEADER_SIZE - (MONTH_DAY_LABEL_TEXT_SIZE / 2); 167 | int dayWidthHalf = (mWidth - mPadding * 2) / (mNumDays * 2); 168 | 169 | for (int i = 0; i < mNumDays; i++) { 170 | int calendarDay = (i + mWeekStart) % mNumDays; 171 | int x = (2 * i + 1) * dayWidthHalf + mPadding; 172 | mDayLabelCalendar.set(Calendar.DAY_OF_WEEK, calendarDay); 173 | canvas.drawText(mDateFormatSymbols.getShortWeekdays()[mDayLabelCalendar.get(Calendar.DAY_OF_WEEK)].toUpperCase(Locale.getDefault()), x, y, mMonthDayLabelPaint); 174 | } 175 | } 176 | 177 | private void drawMonthTitle(Canvas canvas) { 178 | int x = (mWidth + 2 * mPadding) / 2; 179 | int y = (MONTH_HEADER_SIZE - MONTH_DAY_LABEL_TEXT_SIZE) / 2 + (MONTH_LABEL_TEXT_SIZE / 3); 180 | StringBuilder stringBuilder = new StringBuilder(getMonthAndYearString().toLowerCase()); 181 | stringBuilder.setCharAt(0, Character.toUpperCase(stringBuilder.charAt(0))); 182 | canvas.drawText(stringBuilder.toString(), x, y, mMonthTitlePaint); 183 | } 184 | 185 | private int findDayOffset() { 186 | return (mDayOfWeekStart < mWeekStart ? (mDayOfWeekStart + mNumDays) : mDayOfWeekStart) 187 | - mWeekStart; 188 | } 189 | 190 | private String getMonthAndYearString() { 191 | int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_NO_MONTH_DAY; 192 | mStringBuilder.setLength(0); 193 | long millis = mCalendar.getTimeInMillis(); 194 | return DateUtils.formatDateRange(getContext(), millis, millis, flags); 195 | } 196 | 197 | private void onDayClick(SimpleMonthAdapter.CalendarDay calendarDay) { 198 | if (mOnDayClickListener != null && (isPrevDayEnabled || !((calendarDay.month == today.month) && (calendarDay.year == today.year) && calendarDay.day < today.monthDay))) { 199 | mOnDayClickListener.onDayClick(this, calendarDay); 200 | } 201 | } 202 | 203 | private boolean sameDay(int monthDay, Time time) { 204 | return (mYear == time.year) && (mMonth == time.month) && (monthDay == time.monthDay); 205 | } 206 | 207 | private boolean prevDay(int monthDay, Time time) { 208 | return ((mYear < time.year)) || (mYear == time.year && mMonth < time.month) || ( mMonth == time.month && monthDay < time.monthDay); 209 | } 210 | 211 | protected void drawMonthNums(Canvas canvas) { 212 | int y = (mRowHeight + MINI_DAY_NUMBER_TEXT_SIZE) / 2 - DAY_SEPARATOR_WIDTH + MONTH_HEADER_SIZE; 213 | int paddingDay = (mWidth - 2 * mPadding) / (2 * mNumDays); 214 | int dayOffset = findDayOffset(); 215 | int day = 1; 216 | 217 | while (day <= mNumCells) { 218 | int x = paddingDay * (1 + dayOffset * 2) + mPadding; 219 | if ((mMonth == mSelectedBeginMonth && mSelectedBeginDay == day && mSelectedBeginYear == mYear) || (mMonth == mSelectedLastMonth && mSelectedLastDay == day && mSelectedLastYear == mYear)) { 220 | if (mDrawRect) 221 | { 222 | RectF rectF = new RectF(x - DAY_SELECTED_CIRCLE_SIZE, (y - MINI_DAY_NUMBER_TEXT_SIZE / 3) - DAY_SELECTED_CIRCLE_SIZE, x + DAY_SELECTED_CIRCLE_SIZE, (y - MINI_DAY_NUMBER_TEXT_SIZE / 3) + DAY_SELECTED_CIRCLE_SIZE); 223 | canvas.drawRoundRect(rectF, 10.0f, 10.0f,mSelectedCirclePaint); 224 | } 225 | else 226 | canvas.drawCircle(x, y - MINI_DAY_NUMBER_TEXT_SIZE / 3, DAY_SELECTED_CIRCLE_SIZE, mSelectedCirclePaint); 227 | } 228 | if (mHasToday && (mToday == day)) { 229 | mMonthNumPaint.setColor(mCurrentDayTextColor); 230 | mMonthNumPaint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)); 231 | } else { 232 | mMonthNumPaint.setColor(mDayNumColor); 233 | mMonthNumPaint.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL)); 234 | } 235 | 236 | if ((mMonth == mSelectedBeginMonth && mSelectedBeginDay == day && mSelectedBeginYear == mYear) || (mMonth == mSelectedLastMonth && mSelectedLastDay == day && mSelectedLastYear == mYear)) 237 | mMonthNumPaint.setColor(mMonthTitleBGColor); 238 | 239 | if ((mSelectedBeginDay != -1 && mSelectedLastDay != -1 && mSelectedBeginYear == mSelectedLastYear && 240 | mSelectedBeginMonth == mSelectedLastMonth && 241 | mSelectedBeginDay == mSelectedLastDay && 242 | day == mSelectedBeginDay && 243 | mMonth == mSelectedBeginMonth && 244 | mYear == mSelectedBeginYear)) 245 | mMonthNumPaint.setColor(mSelectedDaysColor); 246 | 247 | if ((mSelectedBeginDay != -1 && mSelectedLastDay != -1 && mSelectedBeginYear == mSelectedLastYear && mSelectedBeginYear == mYear) && 248 | (((mMonth == mSelectedBeginMonth && mSelectedLastMonth == mSelectedBeginMonth) && ((mSelectedBeginDay < mSelectedLastDay && day > mSelectedBeginDay && day < mSelectedLastDay) || (mSelectedBeginDay > mSelectedLastDay && day < mSelectedBeginDay && day > mSelectedLastDay))) || 249 | ((mSelectedBeginMonth < mSelectedLastMonth && mMonth == mSelectedBeginMonth && day > mSelectedBeginDay) || (mSelectedBeginMonth < mSelectedLastMonth && mMonth == mSelectedLastMonth && day < mSelectedLastDay)) || 250 | ((mSelectedBeginMonth > mSelectedLastMonth && mMonth == mSelectedBeginMonth && day < mSelectedBeginDay) || (mSelectedBeginMonth > mSelectedLastMonth && mMonth == mSelectedLastMonth && day > mSelectedLastDay)))) 251 | { 252 | mMonthNumPaint.setColor(mSelectedDaysColor); 253 | } 254 | 255 | if ((mSelectedBeginDay != -1 && mSelectedLastDay != -1 && mSelectedBeginYear != mSelectedLastYear && ((mSelectedBeginYear == mYear && mMonth == mSelectedBeginMonth) || (mSelectedLastYear == mYear && mMonth == mSelectedLastMonth)) && 256 | (((mSelectedBeginMonth < mSelectedLastMonth && mMonth == mSelectedBeginMonth && day < mSelectedBeginDay) || (mSelectedBeginMonth < mSelectedLastMonth && mMonth == mSelectedLastMonth && day > mSelectedLastDay)) || 257 | ((mSelectedBeginMonth > mSelectedLastMonth && mMonth == mSelectedBeginMonth && day > mSelectedBeginDay) || (mSelectedBeginMonth > mSelectedLastMonth && mMonth == mSelectedLastMonth && day < mSelectedLastDay))))) 258 | { 259 | mMonthNumPaint.setColor(mSelectedDaysColor); 260 | } 261 | 262 | if ((mSelectedBeginDay != -1 && mSelectedLastDay != -1 && mSelectedBeginYear == mSelectedLastYear && mYear == mSelectedBeginYear) && 263 | ((mMonth > mSelectedBeginMonth && mMonth < mSelectedLastMonth && mSelectedBeginMonth < mSelectedLastMonth) || 264 | (mMonth < mSelectedBeginMonth && mMonth > mSelectedLastMonth && mSelectedBeginMonth > mSelectedLastMonth))) 265 | { 266 | mMonthNumPaint.setColor(mSelectedDaysColor); 267 | } 268 | 269 | if ((mSelectedBeginDay != -1 && mSelectedLastDay != -1 && mSelectedBeginYear != mSelectedLastYear) && 270 | ((mSelectedBeginYear < mSelectedLastYear && ((mMonth > mSelectedBeginMonth && mYear == mSelectedBeginYear) || (mMonth < mSelectedLastMonth && mYear == mSelectedLastYear))) || 271 | (mSelectedBeginYear > mSelectedLastYear && ((mMonth < mSelectedBeginMonth && mYear == mSelectedBeginYear) || (mMonth > mSelectedLastMonth && mYear == mSelectedLastYear))))) 272 | { 273 | mMonthNumPaint.setColor(mSelectedDaysColor); 274 | } 275 | 276 | if (!isPrevDayEnabled && prevDay(day, today) && today.month == mMonth && today.year == mYear) 277 | { 278 | mMonthNumPaint.setColor(mPreviousDayColor); 279 | mMonthNumPaint.setTypeface(Typeface.defaultFromStyle(Typeface.ITALIC)); 280 | } 281 | 282 | canvas.drawText(String.format("%d", day), x, y, mMonthNumPaint); 283 | 284 | dayOffset++; 285 | if (dayOffset == mNumDays) { 286 | dayOffset = 0; 287 | y += mRowHeight; 288 | } 289 | day++; 290 | } 291 | } 292 | 293 | public SimpleMonthAdapter.CalendarDay getDayFromLocation(float x, float y) { 294 | int padding = mPadding; 295 | if ((x < padding) || (x > mWidth - mPadding)) { 296 | return null; 297 | } 298 | 299 | int yDay = (int) (y - MONTH_HEADER_SIZE) / mRowHeight; 300 | int day = 1 + ((int) ((x - padding) * mNumDays / (mWidth - padding - mPadding)) - findDayOffset()) + yDay * mNumDays; 301 | 302 | if (mMonth > 11 || mMonth < 0 || CalendarUtils.getDaysInMonth(mMonth, mYear) < day || day < 1) 303 | return null; 304 | 305 | return new SimpleMonthAdapter.CalendarDay(mYear, mMonth, day); 306 | } 307 | 308 | protected void initView() { 309 | mMonthTitlePaint = new Paint(); 310 | mMonthTitlePaint.setFakeBoldText(true); 311 | mMonthTitlePaint.setAntiAlias(true); 312 | mMonthTitlePaint.setTextSize(MONTH_LABEL_TEXT_SIZE); 313 | mMonthTitlePaint.setTypeface(Typeface.create(mMonthTitleTypeface, Typeface.BOLD)); 314 | mMonthTitlePaint.setColor(mMonthTextColor); 315 | mMonthTitlePaint.setTextAlign(Align.CENTER); 316 | mMonthTitlePaint.setStyle(Style.FILL); 317 | 318 | mMonthTitleBGPaint = new Paint(); 319 | mMonthTitleBGPaint.setFakeBoldText(true); 320 | mMonthTitleBGPaint.setAntiAlias(true); 321 | mMonthTitleBGPaint.setColor(mMonthTitleBGColor); 322 | mMonthTitleBGPaint.setTextAlign(Align.CENTER); 323 | mMonthTitleBGPaint.setStyle(Style.FILL); 324 | 325 | mSelectedCirclePaint = new Paint(); 326 | mSelectedCirclePaint.setFakeBoldText(true); 327 | mSelectedCirclePaint.setAntiAlias(true); 328 | mSelectedCirclePaint.setColor(mSelectedDaysColor); 329 | mSelectedCirclePaint.setTextAlign(Align.CENTER); 330 | mSelectedCirclePaint.setStyle(Style.FILL); 331 | mSelectedCirclePaint.setAlpha(SELECTED_CIRCLE_ALPHA); 332 | 333 | mMonthDayLabelPaint = new Paint(); 334 | mMonthDayLabelPaint.setAntiAlias(true); 335 | mMonthDayLabelPaint.setTextSize(MONTH_DAY_LABEL_TEXT_SIZE); 336 | mMonthDayLabelPaint.setColor(mDayTextColor); 337 | mMonthDayLabelPaint.setTypeface(Typeface.create(mDayOfWeekTypeface, Typeface.NORMAL)); 338 | mMonthDayLabelPaint.setStyle(Style.FILL); 339 | mMonthDayLabelPaint.setTextAlign(Align.CENTER); 340 | mMonthDayLabelPaint.setFakeBoldText(true); 341 | 342 | mMonthNumPaint = new Paint(); 343 | mMonthNumPaint.setAntiAlias(true); 344 | mMonthNumPaint.setTextSize(MINI_DAY_NUMBER_TEXT_SIZE); 345 | mMonthNumPaint.setStyle(Style.FILL); 346 | mMonthNumPaint.setTextAlign(Align.CENTER); 347 | mMonthNumPaint.setFakeBoldText(false); 348 | } 349 | 350 | protected void onDraw(Canvas canvas) { 351 | drawMonthTitle(canvas); 352 | drawMonthDayLabels(canvas); 353 | drawMonthNums(canvas); 354 | } 355 | 356 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 357 | setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), mRowHeight * mNumRows + MONTH_HEADER_SIZE); 358 | } 359 | 360 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { 361 | mWidth = w; 362 | } 363 | 364 | public boolean onTouchEvent(MotionEvent event) { 365 | if (event.getAction() == MotionEvent.ACTION_UP) { 366 | SimpleMonthAdapter.CalendarDay calendarDay = getDayFromLocation(event.getX(), event.getY()); 367 | if (calendarDay != null) { 368 | onDayClick(calendarDay); 369 | } 370 | } 371 | return true; 372 | } 373 | 374 | public void reuse() { 375 | mNumRows = DEFAULT_NUM_ROWS; 376 | requestLayout(); 377 | } 378 | 379 | public void setMonthParams(HashMap params) { 380 | if (!params.containsKey(VIEW_PARAMS_MONTH) && !params.containsKey(VIEW_PARAMS_YEAR)) { 381 | throw new InvalidParameterException("You must specify month and year for this view"); 382 | } 383 | setTag(params); 384 | 385 | if (params.containsKey(VIEW_PARAMS_HEIGHT)) { 386 | mRowHeight = params.get(VIEW_PARAMS_HEIGHT); 387 | if (mRowHeight < MIN_HEIGHT) { 388 | mRowHeight = MIN_HEIGHT; 389 | } 390 | } 391 | if (params.containsKey(VIEW_PARAMS_SELECTED_BEGIN_DAY)) { 392 | mSelectedBeginDay = params.get(VIEW_PARAMS_SELECTED_BEGIN_DAY); 393 | } 394 | if (params.containsKey(VIEW_PARAMS_SELECTED_LAST_DAY)) { 395 | mSelectedLastDay = params.get(VIEW_PARAMS_SELECTED_LAST_DAY); 396 | } 397 | if (params.containsKey(VIEW_PARAMS_SELECTED_BEGIN_MONTH)) { 398 | mSelectedBeginMonth = params.get(VIEW_PARAMS_SELECTED_BEGIN_MONTH); 399 | } 400 | if (params.containsKey(VIEW_PARAMS_SELECTED_LAST_MONTH)) { 401 | mSelectedLastMonth = params.get(VIEW_PARAMS_SELECTED_LAST_MONTH); 402 | } 403 | if (params.containsKey(VIEW_PARAMS_SELECTED_BEGIN_YEAR)) { 404 | mSelectedBeginYear = params.get(VIEW_PARAMS_SELECTED_BEGIN_YEAR); 405 | } 406 | if (params.containsKey(VIEW_PARAMS_SELECTED_LAST_YEAR)) { 407 | mSelectedLastYear = params.get(VIEW_PARAMS_SELECTED_LAST_YEAR); 408 | } 409 | 410 | mMonth = params.get(VIEW_PARAMS_MONTH); 411 | mYear = params.get(VIEW_PARAMS_YEAR); 412 | 413 | mHasToday = false; 414 | mToday = -1; 415 | 416 | mCalendar.set(Calendar.MONTH, mMonth); 417 | mCalendar.set(Calendar.YEAR, mYear); 418 | mCalendar.set(Calendar.DAY_OF_MONTH, 1); 419 | mDayOfWeekStart = mCalendar.get(Calendar.DAY_OF_WEEK); 420 | 421 | if (params.containsKey(VIEW_PARAMS_WEEK_START)) { 422 | mWeekStart = params.get(VIEW_PARAMS_WEEK_START); 423 | } else { 424 | mWeekStart = mCalendar.getFirstDayOfWeek(); 425 | } 426 | 427 | mNumCells = CalendarUtils.getDaysInMonth(mMonth, mYear); 428 | for (int i = 0; i < mNumCells; i++) { 429 | final int day = i + 1; 430 | if (sameDay(day, today)) { 431 | mHasToday = true; 432 | mToday = day; 433 | } 434 | 435 | mIsPrev = prevDay(day, today); 436 | } 437 | 438 | mNumRows = calculateNumRows(); 439 | } 440 | 441 | public void setOnDayClickListener(OnDayClickListener onDayClickListener) { 442 | mOnDayClickListener = onDayClickListener; 443 | } 444 | 445 | public static abstract interface OnDayClickListener { 446 | public abstract void onDayClick(SimpleMonthView simpleMonthView, SimpleMonthAdapter.CalendarDay calendarDay); 447 | } 448 | } --------------------------------------------------------------------------------