├── .gitignore ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .gitignore ├── build.gradle ├── gradle.properties ├── maven-push.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── harrywhewell │ │ └── scrolldatepicker │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── harrywhewell │ │ │ └── scrolldatepicker │ │ │ ├── DayScrollDatePicker.java │ │ │ ├── DayScrollDatePickerAdapter.java │ │ │ ├── DayScrollDatePickerViewHolder.java │ │ │ ├── MonthScrollDatePicker.java │ │ │ ├── MonthScrollDatePickerAdapter.java │ │ │ ├── MonthScrollDatePickerViewHolder.java │ │ │ ├── OnChildClickedListener.java │ │ │ ├── OnChildDateSelectedListener.java │ │ │ ├── OnDateSelectedListener.java │ │ │ ├── Style.java │ │ │ ├── TitleValueCallback.java │ │ │ └── Util.java │ └── res │ │ ├── drawable │ │ └── bg_circle_drawable.xml │ │ ├── layout │ │ ├── date_picker_scroll_day.xml │ │ ├── date_picker_scroll_month.xml │ │ ├── day_list_item.xml │ │ └── month_list_item.xml │ │ └── values │ │ ├── attrs.xml │ │ ├── colors.xml │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── harrywhewell │ └── scrolldatepicker │ └── ExampleUnitTest.java ├── sample ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── harrywhewell │ │ └── scrolldatepicker │ │ └── sample │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── harrywhewell │ │ │ └── scrolldatepicker │ │ │ └── sample │ │ │ ├── DayScrollDatePickerActivity.java │ │ │ ├── MainActivity.java │ │ │ └── MonthScrollDatePickerActivity.java │ └── res │ │ ├── layout │ │ ├── activity_day_scroll_date_picker.xml │ │ ├── activity_main.xml │ │ └── activity_month_scroll_date_picker.xml │ │ ├── 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-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── harrywhewell │ └── scrolldatepicker │ └── sample │ └── ExampleUnitTest.java ├── settings.gradle └── web ├── dayScreenShot.png └── monthScreenShot.png /.gitignore: -------------------------------------------------------------------------------- 1 | # [Android] ======================== 2 | # Built application files 3 | *.apk 4 | *.ap_ 5 | 6 | # Files for the Dalvik VM 7 | *.dex 8 | 9 | # Java class files 10 | *.class 11 | 12 | # Generated files 13 | bin/ 14 | gen/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | 30 | ## Directory-based project format: 31 | .idea/ 32 | 33 | ## File-based project format: 34 | *.ipr 35 | *.iws 36 | 37 | ## Plugin-specific files: 38 | 39 | # IntelliJ 40 | out/ 41 | 42 | # mpeltonen/sbt-idea plugin 43 | .idea_modules/ 44 | 45 | # JIRA plugin 46 | atlassian-ide-plugin.xml 47 | 48 | # Crashlytics plugin (for Android Studio and IntelliJ) 49 | com_crashlytics_export_strings.xml 50 | 51 | 52 | # [Maven] ======================== 53 | target/ 54 | pom.xml.tag 55 | pom.xml.releaseBackup 56 | pom.xml.versionsBackup 57 | pom.xml.next 58 | release.properties 59 | 60 | 61 | # [Gradle-Android] ======================== 62 | 63 | # Ignore Gradle GUI config 64 | gradle-app.setting 65 | 66 | # Gradle Signing 67 | signing.properties 68 | trestle.keystore 69 | 70 | # Mobile Tools for Java (J2ME) 71 | .mtj.tmp/ 72 | 73 | # Package Files # 74 | *.jar 75 | *.war 76 | *.ear 77 | 78 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 79 | hs_err_pid* 80 | 81 | # Misc 82 | /.idea/workspace.xml 83 | .DS_Store 84 | /captures 85 | **/*.iml 86 | *.class 87 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

Scroll Date Picker

2 |

3 | A custom horizontally scrolling date picker for Android. 4 |

5 |

6 | On Maven Central: Version 0.0.1 7 | Platform: Android 8 | License: MIT 9 |

10 | 11 | --- 12 | ## Screenshots 13 |

14 | DayScrollDatePicker 15 | MonthScrollDatePicker 16 |

17 | ## Features 18 | - Easy to use views to implement horizontal scrolling date pickers 19 | - Custom Atributes allow the user to set the style. 20 | - Ability to set start and end dates. 21 | - Simple way to implement date input. 22 | 23 | ## Installation 24 | Install by adding the library to your module's `build.gradle` file. 25 | ``` gradle 26 | compile 'com.github.gastricspark:scrolldatepicker:0.0.1' 27 | ``` 28 | 29 | ## Usage 30 | To include a `ScrollDatePicker` within your application all you have to do is implement it in your layout 31 | and then get the value on your activity. 32 | 33 | ### Set Up 34 | Inlcude either `MonthScrollDatePicker` or `DayScrollDatePicker` within your layout. 35 | ``` 36 | 41 | ``` 42 | Then just treat it like any other view, find it by id.
43 | ` mPicker = (DayScrollDatePicker) findViewById(R.id.day_picker); `
44 | Then once you have an object of it you can set the start date (local date by default) 45 | and the end date (infinate by default ).
46 | ` mPicker.setStartDate(10, 10, 2010); `
47 | ` mPicker.setEndDate(11, 11, 2011); ` 48 | 49 | ### Attributes 50 | You can define some attributes to style the `ScrollDatePicker` ; 51 | - `baseColor` the default color of the selector 52 | - `baseTextColor` the default color of the views text 53 | - `selectedColor` the selected color of the selector 54 | - `selectedTextColor` the selected text color of the selector 55 | - `showTitle` if the title should be shown e.g. '2016' (true by defualt) 56 | - `showFullDate` if the full date should be shown e.g. '28 Feburary 2016' (true by default) 57 | 58 | ### Getting Date 59 | Getting date from the view is really easy, all you have to do is call `getSelectedDate` 60 | and then implement the `OnDateSelectedListener`. 61 | ``` 62 | mPicker.getSelectedDate(new OnDateSelectedListener() { 63 | @Override 64 | public void onDateSelected(@Nullable Date date) { 65 | if(date != null){ 66 | // do something with selected date 67 | } 68 | } 69 | }); 70 | ``` 71 | ### Sample App 72 | There is a sample application included so that you can see how to implement the Scroll Date Pickers, as well as definie their 73 | attributes and get their values. 74 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.1.2' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /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 19 | VERSION_NAME=0.0.1 20 | VERSION_CODE=1 21 | GROUP=com.github.GastricSpark 22 | 23 | POM_DESCRIPTION= A Custom Horizontal Scroll DatePicker 24 | POM_URL=https://github.com/GastricSpark/ProjectName 25 | POM_SCM_URL=https://github.com/GastricSpark/ProjectName 26 | POM_SCM_CONNECTION=scm:git@github.com:GastricSpark/ScrollDatePicker.git 27 | POM_SCM_DEV_CONNECTION=scm:git@github.com:GastricSpark/ScrollDatePicker.git 28 | POM_LICENCE_NAME=The Apache Software License, Version 2.0 29 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt 30 | POM_LICENCE_DIST=repo 31 | POM_DEVELOPER_ID=GastricSpark 32 | POM_DEVELOPER_NAME=Harry Whewell 33 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 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.10-all.zip 7 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /library/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply from: 'maven-push.gradle' 3 | 4 | android { 5 | compileSdkVersion 24 6 | buildToolsVersion "24.0.1" 7 | 8 | defaultConfig { 9 | minSdkVersion 19 10 | targetSdkVersion 24 11 | versionCode 1 12 | versionName "1.0" 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 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:24.2.1' 26 | compile 'com.android.support:design:24.2.1' 27 | compile 'com.android.support:support-v4:24.2.1' 28 | compile 'joda-time:joda-time:2.9.2' 29 | } 30 | -------------------------------------------------------------------------------- /library/gradle.properties: -------------------------------------------------------------------------------- 1 | POM_NAME=ScrollDatePicker 2 | POM_ARTIFACT_ID=scrolldatepicker 3 | POM_PACKAGING=aar 4 | -------------------------------------------------------------------------------- /library/maven-push.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Chris Banes 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply plugin: 'maven' 18 | apply plugin: 'signing' 19 | 20 | def isReleaseBuild() { 21 | return VERSION_NAME.contains("SNAPSHOT") == false 22 | } 23 | 24 | def getReleaseRepositoryUrl() { 25 | return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL 26 | : "https://oss.sonatype.org/service/local/staging/deploy/maven2/" 27 | } 28 | 29 | def getSnapshotRepositoryUrl() { 30 | return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL 31 | : "https://oss.sonatype.org/content/repositories/snapshots/" 32 | } 33 | 34 | def getRepositoryUsername() { 35 | return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : "" 36 | } 37 | 38 | def getRepositoryPassword() { 39 | return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : "" 40 | } 41 | 42 | afterEvaluate { project -> 43 | uploadArchives { 44 | repositories { 45 | mavenDeployer { 46 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } 47 | 48 | pom.groupId = GROUP 49 | pom.artifactId = POM_ARTIFACT_ID 50 | pom.version = VERSION_NAME 51 | 52 | repository(url: getReleaseRepositoryUrl()) { 53 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) 54 | } 55 | snapshotRepository(url: getSnapshotRepositoryUrl()) { 56 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) 57 | } 58 | 59 | pom.project { 60 | name POM_NAME 61 | packaging POM_PACKAGING 62 | description POM_DESCRIPTION 63 | url POM_URL 64 | 65 | scm { 66 | url POM_SCM_URL 67 | connection POM_SCM_CONNECTION 68 | developerConnection POM_SCM_DEV_CONNECTION 69 | } 70 | 71 | licenses { 72 | license { 73 | name POM_LICENCE_NAME 74 | url POM_LICENCE_URL 75 | distribution POM_LICENCE_DIST 76 | } 77 | } 78 | 79 | developers { 80 | developer { 81 | id POM_DEVELOPER_ID 82 | name POM_DEVELOPER_NAME 83 | } 84 | } 85 | } 86 | } 87 | } 88 | } 89 | 90 | signing { 91 | required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") } 92 | sign configurations.archives 93 | } 94 | 95 | //task androidJavadocs(type: Javadoc) { 96 | //source = android.sourceSets.main.allJava 97 | //} 98 | 99 | //task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) { 100 | //classifier = 'javadoc' 101 | //from androidJavadocs.destinationDir 102 | //} 103 | 104 | task androidSourcesJar(type: Jar) { 105 | classifier = 'sources' 106 | from android.sourceSets.main.java.sourceFiles 107 | } 108 | 109 | artifacts { 110 | archives androidSourcesJar 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /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 /Users/harry/Library/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 | -------------------------------------------------------------------------------- /library/src/androidTest/java/com/harrywhewell/scrolldatepicker/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.harrywhewell.scrolldatepicker; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /library/src/main/java/com/harrywhewell/scrolldatepicker/DayScrollDatePicker.java: -------------------------------------------------------------------------------- 1 | package com.harrywhewell.scrolldatepicker; 2 | 3 | 4 | import android.content.Context; 5 | import android.content.res.TypedArray; 6 | import android.graphics.drawable.Drawable; 7 | import android.support.annotation.Nullable; 8 | import android.support.v7.widget.LinearLayoutManager; 9 | import android.support.v7.widget.RecyclerView; 10 | import android.util.AttributeSet; 11 | import android.view.LayoutInflater; 12 | import android.widget.LinearLayout; 13 | import android.widget.TextView; 14 | 15 | import org.joda.time.LocalDate; 16 | 17 | /** 18 | * Date picker which displays the days of the month in a horizontal list. 19 | * If no end date is set the date picker will continue to infinity. 20 | */ 21 | public class DayScrollDatePicker extends LinearLayout implements TitleValueCallback, OnChildDateSelectedListener { 22 | 23 | private TextView mMonthTextView; 24 | private TextView mFullDateTextView; 25 | private RecyclerView mDayRecyclerView; 26 | 27 | private int mBaseTextColor; 28 | 29 | private DayScrollDatePickerAdapter mAdapter; 30 | 31 | private boolean mShowTitle; 32 | private boolean mShowFullDate; 33 | 34 | private OnDateSelectedListener mListener; 35 | 36 | private Style mStyle; 37 | 38 | public DayScrollDatePicker(Context context, AttributeSet attrs) { 39 | super(context, attrs); 40 | LayoutInflater.from(context).inflate(R.layout.date_picker_scroll_day, this, true); 41 | getViewElements(); 42 | setAttributeValues(context.getTheme().obtainStyledAttributes(attrs, R.styleable.ScrollDatePicker, 0, 0)); 43 | DayScrollDatePickerViewHolder.onDateSelected(this); 44 | initView(); 45 | } 46 | 47 | /** 48 | * Get all the view elements from date_picker_scroll_day layout. 49 | */ 50 | private void getViewElements(){ 51 | mMonthTextView = (TextView) findViewById(R.id.date_picker_scroll_day_month); 52 | mFullDateTextView = (TextView) findViewById(R.id.date_picker_scroll_day_full_date); 53 | mDayRecyclerView = (RecyclerView) findViewById(R.id.date_picker_scroll_day_recycler_view); 54 | } 55 | 56 | /** 57 | * If attribute values have been set, get them. 58 | * If not get default values. 59 | * @param a styled attributes 60 | */ 61 | private void setAttributeValues(TypedArray a){ 62 | int baseColor; 63 | int selectedTextColor; 64 | int selectedColor; 65 | try{ 66 | mBaseTextColor = a.getColor(R.styleable.ScrollDatePicker_baseTextColor, 67 | getResources().getColor(R.color.default_base_text)); 68 | baseColor = a.getColor(R.styleable.ScrollDatePicker_baseColor, 69 | getResources().getColor(R.color.default_base)); 70 | selectedTextColor = a.getColor(R.styleable.ScrollDatePicker_selectedTextColor, 71 | getResources().getColor(R.color.default_selected_text)); 72 | selectedColor = a.getColor(R.styleable.ScrollDatePicker_selectedColor, 73 | getResources().getColor(R.color.default_selected)); 74 | 75 | mShowTitle = a.getBoolean(R.styleable.ScrollDatePicker_showTitle, true); 76 | mShowFullDate = a.getBoolean(R.styleable.ScrollDatePicker_showFullDate, true); 77 | 78 | } finally { 79 | a.recycle(); 80 | } 81 | 82 | Drawable background = Util.setDrawableBackgroundColor( 83 | getResources().getDrawable(R.drawable.bg_circle_drawable), baseColor); 84 | Drawable selectedBackground = Util.setDrawableBackgroundColor( 85 | getResources().getDrawable(R.drawable.bg_circle_drawable), selectedColor); 86 | mStyle = new Style(selectedColor, baseColor, selectedTextColor, mBaseTextColor, background, selectedBackground); 87 | } 88 | 89 | /** 90 | * Set values onto view elements. 91 | */ 92 | private void initView(){ 93 | setShowTitle(this.mShowTitle); 94 | setShowFullDate(this.mShowFullDate); 95 | setTextColor(); 96 | initRecyclerView(); 97 | } 98 | 99 | /** 100 | * set up Recycler view and its adapter 101 | */ 102 | private void initRecyclerView(){ 103 | mAdapter = new DayScrollDatePickerAdapter(mStyle, this); 104 | mDayRecyclerView.setAdapter(mAdapter); 105 | LinearLayoutManager layoutManager 106 | = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false); 107 | mDayRecyclerView.setLayoutManager(layoutManager); 108 | } 109 | 110 | /** 111 | * Set values onto view elements. 112 | * @param show boolean, if true show title 113 | */ 114 | private void setShowTitle(boolean show){ 115 | if(show){ 116 | mMonthTextView.setVisibility(VISIBLE); 117 | }else{ 118 | mMonthTextView.setVisibility(GONE); 119 | } 120 | } 121 | 122 | /** 123 | * Set values onto view elements. 124 | * @param show boolean, if true show full date 125 | */ 126 | private void setShowFullDate(boolean show){ 127 | if(show){ 128 | mFullDateTextView.setVisibility(VISIBLE); 129 | }else{ 130 | mFullDateTextView.setVisibility(GONE); 131 | } 132 | } 133 | 134 | /** 135 | * Sets the text color of full date and title. 136 | */ 137 | private void setTextColor(){ 138 | mMonthTextView.setTextColor(mBaseTextColor); 139 | mFullDateTextView.setTextColor(mBaseTextColor); 140 | } 141 | 142 | /** 143 | * Sets the start date on the DayScrollPicker 144 | * @param day start day e.g. 28 145 | * @param month start month e.g. 10 146 | * @param year start year e.g. 2010 147 | */ 148 | public void setStartDate(int day, int month, int year){ 149 | mAdapter.setStartDate(day, month, year); 150 | mAdapter.notifyDataSetChanged(); 151 | } 152 | 153 | /** 154 | * Sets the end date on the DayScrollPicker 155 | * @param day start day e.g. 28 156 | * @param month start month e.g. 10 157 | * @param year start year e.g. 2010 158 | */ 159 | public void setEndDate(int day, int month, int year){ 160 | mAdapter.setEndDate(day, month, year); 161 | mAdapter.notifyDataSetChanged();; 162 | } 163 | 164 | /** 165 | * Gets the current selected date as a Date. 166 | */ 167 | public void getSelectedDate(OnDateSelectedListener listener){ 168 | this.mListener = listener; 169 | } 170 | 171 | 172 | @Override 173 | public void onDateSelectedChild(@Nullable LocalDate date) { 174 | if(date != null) { 175 | mFullDateTextView.setText(String.format("%s %s %s", date.toString("dd"), 176 | date.toString("MMMM"), date.toString("yyyy"))); 177 | mListener.onDateSelected(date.toDate()); 178 | } 179 | } 180 | 181 | @Override 182 | public void onTitleValueReturned(LocalDate date) { 183 | mMonthTextView.setText(date.toString("MMMM")); 184 | } 185 | } 186 | -------------------------------------------------------------------------------- /library/src/main/java/com/harrywhewell/scrolldatepicker/DayScrollDatePickerAdapter.java: -------------------------------------------------------------------------------- 1 | package com.harrywhewell.scrolldatepicker; 2 | 3 | import android.support.v7.widget.RecyclerView; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | 8 | import org.joda.time.Days; 9 | import org.joda.time.LocalDate; 10 | import org.joda.time.Months; 11 | 12 | class DayScrollDatePickerAdapter extends RecyclerView.Adapter{ 13 | 14 | private LocalDate startDate; 15 | private LocalDate endDate; 16 | 17 | private TitleValueCallback callback; 18 | 19 | 20 | private Style style; 21 | 22 | private Integer selectedPosition = null; 23 | 24 | public DayScrollDatePickerAdapter(Style style, TitleValueCallback callback){ 25 | this.callback = callback; 26 | this.startDate = new LocalDate(); 27 | this.style = style; 28 | callback.onTitleValueReturned(startDate); 29 | } 30 | 31 | public void setStartDate(int day, int month, int year){ 32 | this.startDate = startDate.withDayOfMonth(day).withMonthOfYear(month).withYear(year); 33 | callback.onTitleValueReturned(startDate); 34 | } 35 | 36 | public void setEndDate(int day, int month, int year){ 37 | this.endDate = startDate.withDayOfMonth(day).withMonthOfYear(month).withYear(year); 38 | } 39 | 40 | @Override 41 | public DayScrollDatePickerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 42 | View itemView = LayoutInflater.from(parent.getContext()).inflate( 43 | R.layout.day_list_item, 44 | parent, 45 | false); 46 | return new DayScrollDatePickerViewHolder(style, itemView); 47 | } 48 | 49 | @Override 50 | public void onBindViewHolder(final DayScrollDatePickerViewHolder holder, int position) { 51 | LocalDate dateTime = startDate.plusDays(position); 52 | callback.onTitleValueReturned(dateTime); 53 | 54 | holder.onBind(dateTime, new OnChildClickedListener() { 55 | @Override 56 | public void onChildClick(boolean clicked) { 57 | if(clicked){ 58 | if(selectedPosition != null){ 59 | notifyItemChanged(selectedPosition); 60 | } 61 | selectedPosition = holder.getAdapterPosition(); 62 | } 63 | } 64 | }); 65 | if(selectedPosition != null && selectedPosition == holder.getAdapterPosition()){ 66 | holder.styleViewSection(true); 67 | } 68 | } 69 | 70 | @Override 71 | public int getItemCount() { 72 | if(endDate != null){ 73 | return Days.daysBetween(startDate, endDate).getDays() + 1; 74 | }else{ 75 | return Integer.MAX_VALUE; 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /library/src/main/java/com/harrywhewell/scrolldatepicker/DayScrollDatePickerViewHolder.java: -------------------------------------------------------------------------------- 1 | package com.harrywhewell.scrolldatepicker; 2 | 3 | import android.graphics.drawable.Drawable; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.util.Log; 6 | import android.view.View; 7 | import android.widget.TextView; 8 | 9 | import org.joda.time.LocalDate; 10 | 11 | class DayScrollDatePickerViewHolder extends RecyclerView.ViewHolder{ 12 | 13 | public TextView dayNameTextView; 14 | public TextView dayValueTextView; 15 | 16 | private int selectedTextColor; 17 | private int baseTextColor; 18 | private int selectedColor; 19 | private Drawable selectedBackground; 20 | private Drawable background; 21 | 22 | private OnChildClickedListener clickedListener; 23 | private static OnChildDateSelectedListener dateSelectedListener; 24 | 25 | public DayScrollDatePickerViewHolder(Style style, View itemView) { 26 | super(itemView); 27 | dayNameTextView = (TextView) itemView.findViewById(R.id.day_name); 28 | dayValueTextView = (TextView) itemView.findViewById(R.id.day_value); 29 | init(style); 30 | dateSelectedListener.onDateSelectedChild(null); 31 | } 32 | 33 | private void init(Style style){ 34 | selectedTextColor = style.getSelectedTextColor(); 35 | baseTextColor = style.getBaseTextColor(); 36 | selectedBackground = style.getSelectedBackground(); 37 | background = style.getBackground(); 38 | selectedColor = style.getSelectedColor(); 39 | } 40 | 41 | public void styleViewSection(boolean selected){ 42 | dayNameTextView.setTextColor(selected ? selectedColor : baseTextColor); 43 | dayValueTextView.setTextColor(selected ? selectedTextColor : baseTextColor); 44 | dayValueTextView.setBackground(selected ? selectedBackground : background); 45 | 46 | } 47 | 48 | public static void onDateSelected(OnChildDateSelectedListener listener){ 49 | dateSelectedListener = listener; 50 | } 51 | 52 | public void onBind(final LocalDate value, OnChildClickedListener listener){ 53 | this.clickedListener = listener; 54 | clickedListener.onChildClick(false); 55 | 56 | Log.d("LOG", value.toString()); 57 | 58 | styleViewSection(false); 59 | dayNameTextView.setText(value.toString("EEE")); 60 | dayValueTextView.setText(value.toString("dd")); 61 | 62 | 63 | dayValueTextView.setOnClickListener(new View.OnClickListener() { 64 | @Override 65 | public void onClick(View view) { 66 | styleViewSection(true); 67 | clickedListener.onChildClick(true); 68 | dateSelectedListener.onDateSelectedChild(value); 69 | } 70 | }); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /library/src/main/java/com/harrywhewell/scrolldatepicker/MonthScrollDatePicker.java: -------------------------------------------------------------------------------- 1 | package com.harrywhewell.scrolldatepicker; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.drawable.Drawable; 6 | import android.support.annotation.Nullable; 7 | import android.support.v7.widget.LinearLayoutManager; 8 | import android.support.v7.widget.RecyclerView; 9 | import android.util.AttributeSet; 10 | import android.view.LayoutInflater; 11 | import android.widget.LinearLayout; 12 | import android.widget.TextView; 13 | 14 | import org.joda.time.LocalDate; 15 | 16 | 17 | /** 18 | * Date picker which displays the months of the year in a horizontal list. 19 | * If no end date is set the date picker will continue to infinity. 20 | */ 21 | public class MonthScrollDatePicker extends LinearLayout implements TitleValueCallback, OnChildDateSelectedListener { 22 | 23 | private TextView mYearTextView; 24 | private TextView mFullDateTextView; 25 | private RecyclerView mMonthRecyclerView; 26 | 27 | private MonthScrollDatePickerAdapter mAdapter; 28 | 29 | private int mBaseTextColor; 30 | 31 | private boolean mShowTitle; 32 | private boolean mShowFullDate; 33 | 34 | private Style mStyle; 35 | 36 | private OnDateSelectedListener mListener; 37 | 38 | public MonthScrollDatePicker(Context context, AttributeSet attrs) { 39 | super(context, attrs); 40 | LayoutInflater.from(context).inflate(R.layout.date_picker_scroll_month, this, true); 41 | getViewElements(); 42 | setAttributeValues(context.getTheme().obtainStyledAttributes(attrs, R.styleable.ScrollDatePicker, 0, 0)); 43 | MonthScrollDatePickerViewHolder.onDateSelected(this); 44 | initView(); 45 | } 46 | 47 | /** 48 | * Get all the view elements from date_picker_scroll_month layout. 49 | */ 50 | private void getViewElements(){ 51 | mYearTextView = (TextView) findViewById(R.id.date_picker_scroll_month_year); 52 | mFullDateTextView = (TextView) findViewById(R.id.date_picker_scroll_month_full_date); 53 | mMonthRecyclerView = (RecyclerView) findViewById(R.id.date_picker_scroll_month_recycler_view); 54 | } 55 | 56 | /** 57 | * If attribute values have been set, get them. 58 | * If not get default values. 59 | * @param a styled attributes 60 | */ 61 | private void setAttributeValues(TypedArray a){ 62 | int baseColor; 63 | int selectedTextColor; 64 | int selectedColor; 65 | try{ 66 | mBaseTextColor = a.getColor(R.styleable.ScrollDatePicker_baseTextColor, 67 | getResources().getColor(R.color.default_base_text)); 68 | baseColor = a.getColor(R.styleable.ScrollDatePicker_baseColor, 69 | getResources().getColor(R.color.default_base)); 70 | selectedTextColor = a.getColor(R.styleable.ScrollDatePicker_selectedTextColor, 71 | getResources().getColor(R.color.default_selected_text)); 72 | selectedColor = a.getColor(R.styleable.ScrollDatePicker_selectedColor, 73 | getResources().getColor(R.color.default_selected)); 74 | 75 | mShowTitle = a.getBoolean(R.styleable.ScrollDatePicker_showTitle, true); 76 | mShowFullDate = a.getBoolean(R.styleable.ScrollDatePicker_showFullDate, true); 77 | 78 | } finally { 79 | a.recycle(); 80 | } 81 | 82 | Drawable background = Util.setDrawableBackgroundColor( 83 | getResources().getDrawable(R.drawable.bg_circle_drawable), baseColor); 84 | Drawable selectedBackground = Util.setDrawableBackgroundColor( 85 | getResources().getDrawable(R.drawable.bg_circle_drawable), selectedColor); 86 | mStyle = new Style(selectedColor, baseColor, selectedTextColor, mBaseTextColor, background, selectedBackground); 87 | } 88 | 89 | /** 90 | * Set values onto view elements. 91 | */ 92 | private void initView(){ 93 | setShowTitle(this.mShowTitle); 94 | setShowFullDate(this.mShowFullDate); 95 | setTextColor(); 96 | initRecyclerView(); 97 | } 98 | 99 | /** 100 | * set up Recycler view and its adapter 101 | */ 102 | private void initRecyclerView(){ 103 | mAdapter = new MonthScrollDatePickerAdapter(mStyle, this); 104 | mMonthRecyclerView.setAdapter(mAdapter); 105 | LinearLayoutManager layoutManager 106 | = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false); 107 | mMonthRecyclerView.setLayoutManager(layoutManager); 108 | } 109 | 110 | /** 111 | * Set values onto view elements. 112 | * @param show boolean, if true show title 113 | */ 114 | private void setShowTitle(boolean show){ 115 | if(show){ 116 | mYearTextView.setVisibility(VISIBLE); 117 | }else{ 118 | mYearTextView.setVisibility(GONE); 119 | } 120 | } 121 | 122 | /** 123 | * Set values onto view elements. 124 | * @param show boolean, if true show full date 125 | */ 126 | private void setShowFullDate(boolean show){ 127 | if(show){ 128 | mFullDateTextView.setVisibility(VISIBLE); 129 | }else{ 130 | mFullDateTextView.setVisibility(GONE); 131 | } 132 | } 133 | 134 | /** 135 | * Sets the text color of full date and title. 136 | */ 137 | private void setTextColor(){ 138 | mYearTextView.setTextColor(mBaseTextColor); 139 | mFullDateTextView.setTextColor(mBaseTextColor); 140 | } 141 | 142 | /** 143 | * Gets the current selected date as a Date. 144 | */ 145 | public void getSelectedDate(OnDateSelectedListener listener){ 146 | this.mListener = listener; 147 | } 148 | 149 | /** 150 | * Sets the start month on the MonthScrollDatePicker. 151 | * Presumes year as local. 152 | * @param month start month e.g. 10 153 | */ 154 | public void setStartMonth(int month){ 155 | mAdapter.setStartMonth(month); 156 | mAdapter.notifyDataSetChanged(); 157 | } 158 | 159 | /** 160 | * Sets the start date on the MonthScrollDatePicker 161 | * @param month start month e.g. 10 162 | * @param year start year e.g. 2016 163 | */ 164 | public void setStartDate(int month, int year){ 165 | mAdapter.setStartDate(month, year); 166 | mAdapter.notifyDataSetChanged(); 167 | } 168 | 169 | /** 170 | * Sets the end date of the MonthScrollDatePicker. 171 | * @param month end month e.g. 10 172 | * @param year end year e.g. 2016 173 | */ 174 | public void setEndDate(int month, int year){ 175 | mAdapter.setEndDate(month, year); 176 | mAdapter.notifyDataSetChanged(); 177 | } 178 | 179 | @Override 180 | public void onTitleValueReturned(LocalDate date) { 181 | mYearTextView.setText(date.toString("yyyy")); 182 | } 183 | 184 | @Override 185 | public void onDateSelectedChild(@Nullable LocalDate date) { 186 | if(date != null) { 187 | mFullDateTextView.setText(String.format("%s %s", date.toString("MMMM"), date.toString("yyyy"))); 188 | mListener.onDateSelected(date.toDate()); 189 | } 190 | } 191 | } 192 | -------------------------------------------------------------------------------- /library/src/main/java/com/harrywhewell/scrolldatepicker/MonthScrollDatePickerAdapter.java: -------------------------------------------------------------------------------- 1 | package com.harrywhewell.scrolldatepicker; 2 | 3 | import android.support.v7.widget.RecyclerView; 4 | 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | 9 | import org.joda.time.LocalDate; 10 | import org.joda.time.Months; 11 | 12 | /** 13 | * Adapter to supply MonthScrollDatePicker with date data 14 | */ 15 | class MonthScrollDatePickerAdapter extends RecyclerView.Adapter{ 16 | 17 | private LocalDate startDate; 18 | private LocalDate endDate; 19 | 20 | private TitleValueCallback callback; 21 | 22 | 23 | private Style style; 24 | 25 | private Integer selectedPosition = null; 26 | 27 | 28 | public MonthScrollDatePickerAdapter(Style style, TitleValueCallback callback) { 29 | this.callback = callback; 30 | this.startDate = new LocalDate(); 31 | this.style = style; 32 | callback.onTitleValueReturned(startDate); 33 | } 34 | 35 | public void setStartDate(int month, int year){ 36 | this.startDate = startDate.withMonthOfYear(month).withYear(year); 37 | callback.onTitleValueReturned(startDate); 38 | } 39 | 40 | public void setStartMonth(int month){ 41 | this.startDate = startDate.withMonthOfYear(month); 42 | callback.onTitleValueReturned(startDate); 43 | } 44 | 45 | public void setEndDate(int month, int year){ 46 | this.endDate = startDate.withMonthOfYear(month).withYear(year); 47 | } 48 | @Override 49 | public MonthScrollDatePickerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 50 | View itemView = LayoutInflater.from(parent.getContext()).inflate( 51 | R.layout.month_list_item, 52 | parent, 53 | false); 54 | return new MonthScrollDatePickerViewHolder(style, itemView); 55 | } 56 | 57 | @Override 58 | public void onBindViewHolder(final MonthScrollDatePickerViewHolder holder, final int position) { 59 | LocalDate dateTime = startDate.plusMonths(position); 60 | callback.onTitleValueReturned(dateTime); 61 | 62 | holder.onBind(dateTime, new OnChildClickedListener() { 63 | @Override 64 | public void onChildClick(boolean clicked) { 65 | if(clicked){ 66 | if(selectedPosition != null){ 67 | notifyItemChanged(selectedPosition); 68 | } 69 | selectedPosition = holder.getAdapterPosition(); 70 | } 71 | } 72 | }); 73 | if(selectedPosition != null && selectedPosition == holder.getAdapterPosition()){ 74 | holder.styleViewSection(true); 75 | } 76 | } 77 | 78 | @Override 79 | public int getItemCount() { 80 | if(endDate != null){ 81 | return Months.monthsBetween(startDate, endDate).getMonths() + 1; 82 | }else{ 83 | return Integer.MAX_VALUE; 84 | } 85 | 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /library/src/main/java/com/harrywhewell/scrolldatepicker/MonthScrollDatePickerViewHolder.java: -------------------------------------------------------------------------------- 1 | package com.harrywhewell.scrolldatepicker; 2 | 3 | import android.graphics.drawable.Drawable; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.util.Log; 6 | import android.view.View; 7 | import android.widget.TextView; 8 | 9 | import org.joda.time.LocalDate; 10 | 11 | /** 12 | * ViewHolder for month_list_item layout 13 | */ 14 | class MonthScrollDatePickerViewHolder extends RecyclerView.ViewHolder{ 15 | 16 | public TextView monthTextView; 17 | 18 | private int selectedTextColor; 19 | private int baseTextColor; 20 | private Drawable selectedBackground; 21 | private Drawable background; 22 | 23 | private OnChildClickedListener clickedListener; 24 | private static OnChildDateSelectedListener dateSelectedListener; 25 | 26 | 27 | public MonthScrollDatePickerViewHolder(Style style, View itemView) { 28 | super(itemView); 29 | monthTextView = (TextView) itemView.findViewById(R.id.month_list_item_name); 30 | init(style); 31 | dateSelectedListener.onDateSelectedChild(null); 32 | 33 | } 34 | 35 | private void init(Style style){ 36 | selectedTextColor = style.getSelectedTextColor(); 37 | baseTextColor = style.getBaseTextColor(); 38 | selectedBackground = style.getSelectedBackground(); 39 | background = style.getBackground(); 40 | } 41 | 42 | public void styleViewSection(boolean selected){ 43 | monthTextView.setTextColor(selected ? selectedTextColor : baseTextColor); 44 | monthTextView.setBackground(selected ? selectedBackground : background); 45 | 46 | } 47 | 48 | public static void onDateSelected(OnChildDateSelectedListener listener){ 49 | dateSelectedListener = listener; 50 | } 51 | 52 | public void onBind(final LocalDate value, OnChildClickedListener listener){ 53 | this.clickedListener = listener; 54 | clickedListener.onChildClick(false); 55 | 56 | Log.d("LOG", value.toString()); 57 | 58 | styleViewSection(false); 59 | monthTextView.setText(value.toString("MMM")); 60 | 61 | 62 | monthTextView.setOnClickListener(new View.OnClickListener() { 63 | @Override 64 | public void onClick(View view) { 65 | styleViewSection(true); 66 | clickedListener.onChildClick(true); 67 | dateSelectedListener.onDateSelectedChild(value); 68 | } 69 | }); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /library/src/main/java/com/harrywhewell/scrolldatepicker/OnChildClickedListener.java: -------------------------------------------------------------------------------- 1 | package com.harrywhewell.scrolldatepicker; 2 | 3 | public interface OnChildClickedListener { 4 | void onChildClick(boolean clicked); 5 | } 6 | -------------------------------------------------------------------------------- /library/src/main/java/com/harrywhewell/scrolldatepicker/OnChildDateSelectedListener.java: -------------------------------------------------------------------------------- 1 | package com.harrywhewell.scrolldatepicker; 2 | 3 | import android.support.annotation.Nullable; 4 | 5 | import org.joda.time.LocalDate; 6 | 7 | public interface OnChildDateSelectedListener { 8 | void onDateSelectedChild(@Nullable LocalDate date); 9 | } 10 | -------------------------------------------------------------------------------- /library/src/main/java/com/harrywhewell/scrolldatepicker/OnDateSelectedListener.java: -------------------------------------------------------------------------------- 1 | package com.harrywhewell.scrolldatepicker; 2 | 3 | import android.support.annotation.Nullable; 4 | 5 | import java.util.Date; 6 | 7 | public interface OnDateSelectedListener { 8 | void onDateSelected(@Nullable Date date); 9 | } 10 | -------------------------------------------------------------------------------- /library/src/main/java/com/harrywhewell/scrolldatepicker/Style.java: -------------------------------------------------------------------------------- 1 | package com.harrywhewell.scrolldatepicker; 2 | 3 | import android.graphics.drawable.Drawable; 4 | 5 | class Style { 6 | private int selectedColor; 7 | private int baseColor; 8 | private int selectedTextColor; 9 | private int baseTextColor; 10 | private Drawable background; 11 | private Drawable selectedBackground; 12 | 13 | public Style(int selectedColor, int baseColor, int selectedTextColor, int baseTextColor, Drawable background, Drawable selectedBackground) { 14 | this.selectedColor = selectedColor; 15 | this.baseColor = baseColor; 16 | this.selectedTextColor = selectedTextColor; 17 | this.baseTextColor = baseTextColor; 18 | this.background = background; 19 | this.selectedBackground = selectedBackground; 20 | } 21 | 22 | public int getSelectedColor() { 23 | return selectedColor; 24 | } 25 | 26 | public int getBaseColor() { 27 | return baseColor; 28 | } 29 | 30 | public int getSelectedTextColor() { 31 | return selectedTextColor; 32 | } 33 | 34 | public int getBaseTextColor() { 35 | return baseTextColor; 36 | } 37 | 38 | public Drawable getBackground() { 39 | return background; 40 | } 41 | 42 | public Drawable getSelectedBackground() { 43 | return selectedBackground; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /library/src/main/java/com/harrywhewell/scrolldatepicker/TitleValueCallback.java: -------------------------------------------------------------------------------- 1 | package com.harrywhewell.scrolldatepicker; 2 | 3 | import org.joda.time.LocalDate; 4 | 5 | public interface TitleValueCallback { 6 | void onTitleValueReturned(LocalDate date); 7 | } 8 | -------------------------------------------------------------------------------- /library/src/main/java/com/harrywhewell/scrolldatepicker/Util.java: -------------------------------------------------------------------------------- 1 | package com.harrywhewell.scrolldatepicker; 2 | 3 | import android.graphics.drawable.Drawable; 4 | import android.graphics.drawable.GradientDrawable; 5 | 6 | class Util { 7 | public static Drawable setDrawableBackgroundColor(Drawable drawable, int color){ 8 | GradientDrawable gradientDrawable = (GradientDrawable) drawable.mutate(); 9 | gradientDrawable.setColor(color); 10 | return gradientDrawable; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /library/src/main/res/drawable/bg_circle_drawable.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 7 | 10 | -------------------------------------------------------------------------------- /library/src/main/res/layout/date_picker_scroll_day.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 18 | 22 | 28 | 29 | 38 | -------------------------------------------------------------------------------- /library/src/main/res/layout/date_picker_scroll_month.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 19 | 23 | 29 | 30 | 39 | -------------------------------------------------------------------------------- /library/src/main/res/layout/day_list_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 19 | 26 | -------------------------------------------------------------------------------- /library/src/main/res/layout/month_list_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 19 | -------------------------------------------------------------------------------- /library/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /library/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #686868 4 | #FFFFFF 5 | #FFFFFF 6 | #000000 7 | -------------------------------------------------------------------------------- /library/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | ScrollDatePicker 3 | Left Arrow 4 | Right Arrow 5 | 6 | -------------------------------------------------------------------------------- /library/src/test/java/com/harrywhewell/scrolldatepicker/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.harrywhewell.scrolldatepicker; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 24 5 | buildToolsVersion "24.0.1" 6 | 7 | defaultConfig { 8 | applicationId "com.harrywhewell.scrolldatepicker.sample" 9 | minSdkVersion 19 10 | targetSdkVersion 24 11 | versionCode 1 12 | versionName "1.0" 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(include: ['*.jar'], dir: 'libs') 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:24.2.1' 26 | compile project(':library') 27 | } 28 | -------------------------------------------------------------------------------- /sample/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 /Users/harry/Library/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 | -------------------------------------------------------------------------------- /sample/src/androidTest/java/com/harrywhewell/scrolldatepicker/sample/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.harrywhewell.scrolldatepicker.sample; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 23 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /sample/src/main/java/com/harrywhewell/scrolldatepicker/sample/DayScrollDatePickerActivity.java: -------------------------------------------------------------------------------- 1 | package com.harrywhewell.scrolldatepicker.sample; 2 | 3 | import android.support.annotation.Nullable; 4 | import android.support.v7.app.ActionBar; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.os.Bundle; 7 | import android.widget.TextView; 8 | 9 | import com.harrywhewell.scrolldatepicker.DayScrollDatePicker; 10 | import com.harrywhewell.scrolldatepicker.OnDateSelectedListener; 11 | 12 | import java.util.Date; 13 | 14 | public class DayScrollDatePickerActivity extends AppCompatActivity { 15 | 16 | private DayScrollDatePicker mPicker; 17 | private TextView mValueTextView; 18 | 19 | @Override 20 | protected void onCreate(Bundle savedInstanceState) { 21 | super.onCreate(savedInstanceState); 22 | setContentView(R.layout.activity_day_scroll_date_picker); 23 | setUpActionBar(); 24 | initViews(); 25 | getValue(); 26 | } 27 | 28 | private void setUpActionBar(){ 29 | ActionBar actionBar = getSupportActionBar(); 30 | assert actionBar != null; 31 | actionBar.setTitle(R.string.day_scroll_date_picker); 32 | actionBar.setDisplayHomeAsUpEnabled(true); 33 | 34 | } 35 | 36 | // Initialise views 37 | private void initViews() { 38 | mPicker = (DayScrollDatePicker) findViewById(R.id.day_date_picker); 39 | mValueTextView = (TextView) findViewById(R.id.value_text_view); 40 | setUpPicker(); 41 | } 42 | 43 | private void setUpPicker() { 44 | mPicker.setStartDate(20, 11, 2016); // set start date for the picker 45 | mPicker.setEndDate(20, 12, 2016); // set end date for the picker 46 | } 47 | 48 | private void getValue() { 49 | mPicker.getSelectedDate(new OnDateSelectedListener() { 50 | @Override 51 | public void onDateSelected(@Nullable Date date) { 52 | if (date != null) { 53 | mValueTextView.setText(date.toString()); // set picker selected value onto textView 54 | } 55 | } 56 | }); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /sample/src/main/java/com/harrywhewell/scrolldatepicker/sample/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.harrywhewell.scrolldatepicker.sample; 2 | 3 | import android.content.Intent; 4 | import android.support.v7.app.ActionBar; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.os.Bundle; 7 | import android.view.View; 8 | import android.widget.Button; 9 | 10 | public class MainActivity extends AppCompatActivity { 11 | 12 | private Button mDayPickerBtn; 13 | private Button mMonthPickerBtn; 14 | 15 | @Override 16 | protected void onCreate(Bundle savedInstanceState) { 17 | super.onCreate(savedInstanceState); 18 | setContentView(R.layout.activity_main); 19 | setUpActionBar(); 20 | initViews(); 21 | } 22 | 23 | private void setUpActionBar(){ 24 | ActionBar actionBar = getSupportActionBar(); 25 | assert actionBar != null; 26 | actionBar.setTitle(R.string.sample); 27 | } 28 | 29 | // Initialise button views 30 | private void initViews(){ 31 | mDayPickerBtn = (Button) findViewById(R.id.day_date_picker_btn); 32 | mMonthPickerBtn = (Button) findViewById(R.id.month_date_picker_btn); 33 | setOnClickListeners(); 34 | } 35 | 36 | // Set button views onClickListeners 37 | private void setOnClickListeners(){ 38 | mDayPickerBtn.setOnClickListener(new View.OnClickListener() { 39 | @Override 40 | public void onClick(View view) { 41 | //Start DayScrollDatePickerActivity 42 | startActivity( new Intent(MainActivity.this, DayScrollDatePickerActivity.class)); 43 | } 44 | }); 45 | 46 | mMonthPickerBtn.setOnClickListener(new View.OnClickListener() { 47 | @Override 48 | public void onClick(View view) { 49 | //Start MonthScrollDatePickerActivity 50 | startActivity( new Intent(MainActivity.this, MonthScrollDatePickerActivity.class)); 51 | } 52 | }); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /sample/src/main/java/com/harrywhewell/scrolldatepicker/sample/MonthScrollDatePickerActivity.java: -------------------------------------------------------------------------------- 1 | package com.harrywhewell.scrolldatepicker.sample; 2 | 3 | import android.support.annotation.Nullable; 4 | import android.support.v7.app.ActionBar; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.os.Bundle; 7 | import android.widget.TextView; 8 | 9 | import com.harrywhewell.scrolldatepicker.MonthScrollDatePicker; 10 | import com.harrywhewell.scrolldatepicker.OnDateSelectedListener; 11 | 12 | import java.util.Date; 13 | 14 | public class MonthScrollDatePickerActivity extends AppCompatActivity { 15 | 16 | private MonthScrollDatePicker mPicker; 17 | private TextView mValueTextView; 18 | 19 | @Override 20 | protected void onCreate(Bundle savedInstanceState) { 21 | super.onCreate(savedInstanceState); 22 | setContentView(R.layout.activity_month_scroll_date_picker); 23 | setUpActionBar(); 24 | initViews(); 25 | getValue(); 26 | } 27 | 28 | private void setUpActionBar(){ 29 | ActionBar actionBar = getSupportActionBar(); 30 | assert actionBar != null; 31 | actionBar.setTitle(R.string.month_scroll_date_picker); 32 | actionBar.setDisplayHomeAsUpEnabled(true); 33 | 34 | } 35 | 36 | // Initialise views 37 | private void initViews (){ 38 | mPicker = (MonthScrollDatePicker) findViewById(R.id.month_date_picker); 39 | mValueTextView = (TextView) findViewById(R.id.value_text_view); 40 | setUpPicker(); 41 | } 42 | 43 | private void setUpPicker(){ 44 | mPicker.setStartDate(11, 2016); // set start date for the picker 45 | mPicker.setEndDate(3, 2018); // set end date for the picker 46 | } 47 | 48 | private void getValue(){ 49 | mPicker.getSelectedDate(new OnDateSelectedListener() { 50 | @Override 51 | public void onDateSelected(@Nullable Date date) { 52 | if(date != null){ 53 | mValueTextView.setText(date.toString()); // set picker selected value onto textView 54 | } 55 | } 56 | }); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_day_scroll_date_picker.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 25 | 31 | 32 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 |