├── .gitignore ├── .idea ├── codeStyles │ └── codeStyleConfig.xml ├── dictionaries │ └── salahamassi.xml ├── encodings.xml ├── misc.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── example │ │ └── dateEditText │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── dateEditText │ │ │ └── MainActivity.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── example │ └── dateEditText │ └── ExampleUnitTest.kt ├── build.gradle ├── dateedittext ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── msa │ │ └── dateedittext │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── msa │ │ │ └── dateedittext │ │ │ ├── Date+Extensions.kt │ │ │ └── DateEditText.kt │ └── res │ │ └── values │ │ ├── attrs.xml │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── msa │ └── dateedittext │ └── ExampleUnitTest.java ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | /local.properties 2 | .cxx 3 | 4 | # Built application files 5 | /*/build/ 6 | /build 7 | 8 | # Local configuration file (sdk path, etc) 9 | local.properties 10 | 11 | # Gradle generated files 12 | .gradle/ 13 | 14 | # OS-specific files 15 | .DS_Store 16 | .DS_Store? 17 | ._* 18 | .Spotlight-V100 19 | .Trashes 20 | ehthumbs.db 21 | Thumbs.db 22 | 23 | # User-specific configurations 24 | *.iml 25 | /.idea/* 26 | /captures 27 | .externalNativeBuild 28 | 29 | # Built application files 30 | *.apk 31 | *.ap_ 32 | 33 | commitlint.config.js 34 | node_modules/ 35 | package-lock.json 36 | package.json -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/dictionaries/salahamassi.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | myyyy 5 | validatedd 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 17 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Android FixDate EditText 2 | 3 | ![PHOTO-2019-07-12-15-35-49](https://user-images.githubusercontent.com/17902030/61145155-63c49280-a4df-11e9-849f-b031209a5c20.jpg) 4 | 5 | # What is it? 6 | This library simplified the way of get date from user input, Allows the user to enter a date as a text and then verify it based on date format, divider character and min or max date with other options. 7 | 8 | ------ 9 | 10 | # How to use it? 11 | 12 | ## First Install 13 | 14 | ```gradle 15 | 16 | implementation 'com.github.salahamassi:android-mask-date-editText:v1.02' 17 | 18 | ``` 19 | ------ 20 | 21 | ## Second Usage 22 | 1- Define new DateEdit text inside you layout xml 23 | ```xml 24 | 28 | ``` 29 | 2- start listening to user input from your acticity, fragment or any android UI components 30 | ```kotlin 31 | dateEditText.listen() 32 | ``` 33 | and just that's it! 34 | 35 | ------ 36 | 37 | ## More options 38 | please download the sample and watch the video to dive more deep. 39 | 40 | ### `DateEditText` attrs 41 | * `dateFormat` 42 | * You can choose between two format "ddMMyyyy" or "MMyy" maybe in the future i will add more, you can add and then make pull request. 43 | 44 | * `dividerCharacter` 45 | * You can choose between three divider Character "/" or "-" or "." 46 | 47 | * `maxDate` 48 | * Set the max date which can user enter it as a string from xml and as a Date object from the code. 49 | 50 | * `minDate` 51 | * Set the min date which can user enter it as a string from xml and as a Date object from the code. 52 | 53 | * `autoCorrect` 54 | * If you want to show error alert to user if he enters something invalid set autoCorrect = false, if you want autocorrecting to what the user inputing set it to "true". 55 | 56 | 57 | * `helperTextEnabled` 58 | * Show helper text, Used just with TextInputLayout. 59 | 60 | * `helperTextHighlightedColor` 61 | * Highlighted helper text color for what user inputed. 62 | 63 | # Screenshot 64 | ![Screenshot_1562879351](https://user-images.githubusercontent.com/17902030/61085592-5228af80-a439-11e9-9e83-a8eeb003b434.png) 65 | 66 | # Video 67 | [![android mask date edit text](https://user-images.githubusercontent.com/17902030/61090744-5d370c00-a448-11e9-9534-fa4896745420.png)](https://www.youtube.com/watch?v=7X8RxxemEaQ) 68 | 69 | # Developer contact 70 | * [Facebook](https://www.facebook.com/profile.php?id=100006656534009) 71 | * [Twitter](https://twitter.com/salahamassi) 72 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | apply plugin: 'kotlin-android' 4 | 5 | apply plugin: 'kotlin-android-extensions' 6 | 7 | android { 8 | compileSdkVersion 29 9 | buildToolsVersion "29.0.0" 10 | defaultConfig { 11 | applicationId "com.example.dateEditText" 12 | minSdkVersion 15 13 | targetSdkVersion 29 14 | versionCode 1 15 | versionName "1.0" 16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 17 | } 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | } 25 | 26 | dependencies { 27 | implementation fileTree(dir: 'libs', include: ['*.jar']) 28 | implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 29 | implementation 'androidx.appcompat:appcompat:1.0.2' 30 | implementation 'androidx.core:core-ktx:1.0.2' 31 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3' 32 | implementation 'com.google.android.material:material:1.0.0' 33 | implementation project(path: ':dateedittext') 34 | testImplementation 'junit:junit:4.12' 35 | androidTestImplementation 'androidx.test:runner:1.2.0' 36 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' 37 | } 38 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/example/dateEditText/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.example.dateEditText 2 | 3 | import androidx.test.InstrumentationRegistry 4 | import androidx.test.runner.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getTargetContext() 22 | assertEquals("com.example.dateEditText", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/dateEditText/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.example.dateEditText 2 | 3 | import android.os.Bundle 4 | import androidx.appcompat.app.AppCompatActivity 5 | import kotlinx.android.synthetic.main.activity_main.* 6 | 7 | class MainActivity : AppCompatActivity() { 8 | 9 | override fun onCreate(savedInstanceState: Bundle?) { 10 | super.onCreate(savedInstanceState) 11 | setContentView(R.layout.activity_main) 12 | firstDateEditText.listen() 13 | secondDateEditText.listen() 14 | thirdDateEditText.listen() 15 | fourthDateEditText.listen() 16 | fifthDateEditText.listen() 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 10 | 12 | 14 | 16 | 18 | 20 | 22 | 24 | 26 | 28 | 30 | 32 | 34 | 36 | 38 | 40 | 42 | 44 | 46 | 48 | 50 | 52 | 54 | 56 | 58 | 60 | 62 | 64 | 66 | 68 | 70 | 72 | 74 | 75 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 16 | 17 | 20 | 21 | 34 | 35 | 54 | 55 | 56 | 70 | 71 | 83 | 84 | 98 | 99 | 100 | 101 | 115 | 116 | 134 | 135 | 149 | 150 | 162 | 163 | 173 | 174 | 175 | 189 | 190 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/salahamassi/Android-Mask-Date-EditText/21eb819ba2b8a52d1ed5fb29090af25f6400e6bb/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/salahamassi/Android-Mask-Date-EditText/21eb819ba2b8a52d1ed5fb29090af25f6400e6bb/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/salahamassi/Android-Mask-Date-EditText/21eb819ba2b8a52d1ed5fb29090af25f6400e6bb/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/salahamassi/Android-Mask-Date-EditText/21eb819ba2b8a52d1ed5fb29090af25f6400e6bb/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/salahamassi/Android-Mask-Date-EditText/21eb819ba2b8a52d1ed5fb29090af25f6400e6bb/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/salahamassi/Android-Mask-Date-EditText/21eb819ba2b8a52d1ed5fb29090af25f6400e6bb/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/salahamassi/Android-Mask-Date-EditText/21eb819ba2b8a52d1ed5fb29090af25f6400e6bb/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/salahamassi/Android-Mask-Date-EditText/21eb819ba2b8a52d1ed5fb29090af25f6400e6bb/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/salahamassi/Android-Mask-Date-EditText/21eb819ba2b8a52d1ed5fb29090af25f6400e6bb/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/salahamassi/Android-Mask-Date-EditText/21eb819ba2b8a52d1ed5fb29090af25f6400e6bb/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #008577 4 | #00574B 5 | #D81B60 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | DateEditText 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/com/example/dateEditText/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.example.dateEditText 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | ext.kotlin_version = '1.3.41' 5 | repositories { 6 | google() 7 | jcenter() 8 | 9 | } 10 | dependencies { 11 | classpath 'com.android.tools.build:gradle:3.6.1' 12 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 13 | // NOTE: Do not place your application dependencies here; they belong 14 | // in the individual module build.gradle files 15 | } 16 | } 17 | 18 | allprojects { 19 | repositories { 20 | google() 21 | jcenter() 22 | maven{ url "https://jitpack.io" } 23 | 24 | } 25 | } 26 | 27 | task clean(type: Delete) { 28 | delete rootProject.buildDir 29 | } 30 | -------------------------------------------------------------------------------- /dateedittext/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /dateedittext/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'kotlin-android-extensions' 3 | apply plugin: 'kotlin-android' 4 | 5 | android { 6 | compileSdkVersion 29 7 | buildToolsVersion "29.0.0" 8 | 9 | 10 | defaultConfig { 11 | minSdkVersion 15 12 | targetSdkVersion 29 13 | versionCode 1 14 | versionName "1.0" 15 | 16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 17 | 18 | } 19 | 20 | buildTypes { 21 | release { 22 | minifyEnabled false 23 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 24 | } 25 | } 26 | 27 | } 28 | 29 | dependencies { 30 | implementation fileTree(dir: 'libs', include: ['*.jar']) 31 | 32 | implementation 'androidx.appcompat:appcompat:1.0.2' 33 | implementation 'com.google.android.material:material:1.0.0' 34 | implementation 'com.github.jitpack:gradle-simple:1.0' 35 | testImplementation 'junit:junit:4.12' 36 | androidTestImplementation 'androidx.test:runner:1.2.0' 37 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' 38 | implementation "androidx.core:core-ktx:1.0.2" 39 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 40 | } 41 | repositories { 42 | mavenCentral() 43 | } 44 | -------------------------------------------------------------------------------- /dateedittext/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /dateedittext/src/androidTest/java/com/msa/dateedittext/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.msa.dateedittext; 2 | 3 | import android.content.Context; 4 | import androidx.test.InstrumentationRegistry; 5 | import androidx.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.msa.dateedittext.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /dateedittext/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /dateedittext/src/main/java/com/msa/dateedittext/Date+Extensions.kt: -------------------------------------------------------------------------------- 1 | package com.msa.dateedittext 2 | 3 | import java.text.SimpleDateFormat 4 | import java.util.* 5 | 6 | 7 | fun String.toDate(format: String): Date? { 8 | val sdf = SimpleDateFormat(format, Locale.US) 9 | return sdf.parse(this) 10 | } 11 | 12 | 13 | fun Date.toString(format: String): String { 14 | val sdf = SimpleDateFormat(format, Locale.US) 15 | return sdf.format(this) 16 | } 17 | 18 | -------------------------------------------------------------------------------- /dateedittext/src/main/java/com/msa/dateedittext/DateEditText.kt: -------------------------------------------------------------------------------- 1 | package com.msa.dateedittext 2 | 3 | import android.annotation.SuppressLint 4 | import android.content.Context 5 | import android.content.res.TypedArray 6 | import android.graphics.Color 7 | import android.text.* 8 | import android.text.style.ForegroundColorSpan 9 | import android.util.AttributeSet 10 | import android.view.Gravity 11 | import com.google.android.material.textfield.TextInputEditText 12 | import com.google.android.material.textfield.TextInputLayout 13 | import java.text.ParseException 14 | import java.text.SimpleDateFormat 15 | import java.util.* 16 | 17 | 18 | /** 19 | * This class Allows the user to enter a date as a text and then verify it based on date format, divider character 20 | * and min or max date with other options 21 | */ 22 | class DateEditText : TextInputEditText { 23 | 24 | 25 | enum class DateFormat(val value: String) { 26 | DDMMyyyy("ddMMyyyy"), 27 | MMyy("MMyy"), 28 | } 29 | 30 | enum class DividerCharacter(val value: String) { 31 | Minus("-"), 32 | Slash("/"), 33 | Point(".") 34 | } 35 | 36 | 37 | private var dividerCharacter = DividerCharacter.Minus 38 | private var dateFormat = DateFormat.DDMMyyyy 39 | 40 | var maxDate: Date? = null 41 | set(value) { 42 | validateMinMaxDate(minDate, value) 43 | field = value 44 | } 45 | 46 | var minDate: Date? = null 47 | set(value) { 48 | validateMinMaxDate(value, maxDate) 49 | field = value 50 | } 51 | 52 | var autoCorrect: Boolean = false 53 | var helperTextEnabled = false 54 | var helperTextHighlightedColor = Color.BLUE 55 | 56 | 57 | private val dateLength: Int 58 | get() { 59 | return if (dateFormat == DateFormat.DDMMyyyy) { 60 | 10 61 | } else { 62 | 5 63 | } 64 | } 65 | 66 | private val firstDividerPosition = 2 67 | private val nextDividerPosition = 5 68 | private var edited = false 69 | private var valueWithError: String? = null 70 | 71 | 72 | 73 | constructor(context: Context?) : super(context) { 74 | initDateEditText() 75 | 76 | } 77 | 78 | constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) { 79 | initDateEditText(attrs = attrs) 80 | } 81 | 82 | constructor(context: Context?, attrs: AttributeSet?, defStyle: Int) : super(context, attrs, defStyle) { 83 | initDateEditText(attrs = attrs) 84 | } 85 | 86 | /** 87 | * init edit text with given arguments from AttributeSet 88 | * @param attrs: AttributeSet 89 | */ 90 | @SuppressLint("RtlHardcoded") 91 | private fun initDateEditText(attrs: AttributeSet? = null) { 92 | gravity = Gravity.LEFT 93 | isCursorVisible = false 94 | setOnClickListener { setSelection(text?.length ?: 0) } 95 | inputType = InputType.TYPE_CLASS_NUMBER 96 | if (attrs == null) { 97 | return 98 | } 99 | val typedArray = context.obtainStyledAttributes(attrs, R.styleable.DateEditText, 0, 0) 100 | getDividerCharacter(typedArray) 101 | getDateFormat(typedArray) 102 | getMaxDate(typedArray) 103 | getMinDate(typedArray) 104 | autoCorrect = typedArray.getBoolean(R.styleable.DateEditText_autoCorrect, true) 105 | helperTextEnabled = typedArray.getBoolean(R.styleable.DateEditText_helperTextEnabled, false) 106 | helperTextHighlightedColor = typedArray.getColor(R.styleable.DateEditText_helperTextHighlightedColor, Color.BLUE) 107 | validateMinMaxDate(minDate, maxDate) 108 | typedArray.recycle() 109 | } 110 | 111 | /** 112 | * get Date Format using from array and set edit text hint based on date format 113 | * @param typedArray: TypedArray 114 | */ 115 | private fun getDateFormat(typedArray: TypedArray) { 116 | val dateFormat = typedArray.getInt(R.styleable.DateEditText_dateFormat, 0) 117 | if (dateFormat == 0) { 118 | this.dateFormat = DateFormat.DDMMyyyy 119 | } else if (dateFormat == 1) { 120 | this.dateFormat = DateFormat.MMyy 121 | } 122 | if (hint.isNullOrEmpty()){ 123 | hint = getDateFormatFromDivider() 124 | } 125 | } 126 | 127 | /** 128 | * get Divider Character from typed array 129 | * @param typedArray: TypedArray 130 | */ 131 | private fun getDividerCharacter(typedArray: TypedArray) { 132 | val dividerCharacter = typedArray.getInt(R.styleable.DateEditText_dividerCharacter, 0) 133 | when (dividerCharacter) { 134 | 0 -> { 135 | this.dividerCharacter = DividerCharacter.Slash 136 | } 137 | 1 -> { 138 | this.dividerCharacter = DividerCharacter.Minus 139 | } 140 | 2 -> { 141 | this.dividerCharacter = DividerCharacter.Point 142 | } 143 | } 144 | } 145 | 146 | /** 147 | * get max date from typed array and throw Exception if the date is invalid 148 | * @param typedArray: TypedArray 149 | * @throws IllegalArgumentException 150 | */ 151 | private fun getMaxDate(typedArray: TypedArray) { 152 | val maxDateString = typedArray.getString(R.styleable.DateEditText_maxDate) ?: return 153 | val format = getDateFormatFromDivider() 154 | validateMinMaxDate(date = maxDateString) 155 | try { 156 | maxDate = SimpleDateFormat(format, Locale.getDefault()).parse(maxDateString) 157 | } catch (e: ParseException) { 158 | throw IllegalArgumentException("max date must be entered as a format and divider character") 159 | } 160 | } 161 | 162 | /** 163 | * get min date from typed array and throw an Exception if the date is invalid 164 | * @param typedArray: TypedArray 165 | * @throws IllegalArgumentException 166 | */ 167 | private fun getMinDate(typedArray: TypedArray) { 168 | val minDateString = typedArray.getString(R.styleable.DateEditText_minDate) ?: return 169 | val format = getDateFormatFromDivider() 170 | validateMinMaxDate(date = minDateString) 171 | try { 172 | minDate = SimpleDateFormat(format, Locale.getDefault()).parse(minDateString) 173 | } catch (e: ParseException) { 174 | throw IllegalArgumentException("min date must be entered as a format and divider character") 175 | } 176 | } 177 | 178 | /** 179 | * validate min and max date, throw an Exception if the date is invalid 180 | * @param date: String 181 | * @throws IllegalArgumentException 182 | */ 183 | private fun validateMinMaxDate(date: String) { 184 | if (dateFormat == DateFormat.MMyy) { 185 | if (date.length != 5) { 186 | throw IllegalArgumentException("Invalid date") 187 | } 188 | val month = date.substring(0, 2).toInt() 189 | if (month > 12 || month <= 0) { 190 | throw IllegalArgumentException("Invalid date") 191 | } 192 | } else if (dateFormat == DateFormat.DDMMyyyy) { 193 | if (date.length != 10) { 194 | throw IllegalArgumentException("Invalid date") 195 | } 196 | 197 | val day = date.substring(0, 2).toInt() 198 | val month = date.substring(3, 5).toInt() 199 | val year = date.substring(6, 10).toInt() 200 | val isLeapYear = (year % 100 != 0 || year % 400 != 0) 201 | 202 | if (month > 12 || month <= 0) { 203 | throw IllegalArgumentException("Invalid date") 204 | } 205 | if (day > 31 || day == 0) { 206 | throw IllegalArgumentException("Invalid date") 207 | } else if (day == 31 && (month == 4 || month == 6 || month == 9 || month == 11)) { 208 | throw IllegalArgumentException("Invalid date") 209 | } else if (month == 2 && day == 31) { 210 | throw IllegalArgumentException("Invalid date") 211 | } else if (month == 2 && day == 29 && !isLeapYear) { 212 | throw IllegalArgumentException("Invalid date") 213 | } 214 | } 215 | } 216 | 217 | /** 218 | * validate min and max date, throw an Exception if the min date >= max date 219 | * @throws IllegalArgumentException 220 | */ 221 | private fun validateMinMaxDate(minDate: Date?, maxDate: Date?) { 222 | val mMinDate = minDate ?: return 223 | val mMaxDate = maxDate ?: return 224 | if (mMinDate >= mMaxDate) { 225 | throw IllegalArgumentException("min date must be smaller than max date") 226 | } 227 | } 228 | 229 | /** 230 | * user should call this function from activity or any android ui components to start listening and updating the edit text 231 | */ 232 | fun listen() { 233 | addTextChangedListener(dateTextWatcher) 234 | } 235 | 236 | /** 237 | * When an object of this type is attached to an Editable, its methods will be called when the text is changed. "from https://developer.android.com/reference/android/text/TextWatcher" 238 | * All updates and validation of text are done here 239 | */ 240 | private val dateTextWatcher = object : TextWatcher { 241 | override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { 242 | if (edited) { 243 | edited = false 244 | return 245 | } 246 | var value = getEditText() 247 | value = validate(value) 248 | if (valueWithError != null && before < count){ 249 | edited = true 250 | setText(valueWithError) 251 | setSelection(text?.length ?: 0) 252 | valueWithError = null 253 | return 254 | } 255 | setError(value= null,errorMessage = null) 256 | value = manageDateDivider(value, firstDividerPosition, start, before) 257 | if (dateFormat == DateFormat.DDMMyyyy) { 258 | value = manageDateDivider(value, nextDividerPosition, start, before) 259 | } 260 | edited = true 261 | setText(value) 262 | setSelection(text?.length ?: 0) 263 | renderHelperText(value = value) 264 | } 265 | 266 | override fun afterTextChanged(s: Editable) {} 267 | 268 | override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {} 269 | } 270 | 271 | /** 272 | * validate user text input 273 | * @param value: String (user text input) 274 | */ 275 | private fun validate(value: String): String { 276 | if (dateFormat == DateFormat.MMyy) { 277 | return validateMMyyDateFormat(value) 278 | } else if (dateFormat == DateFormat.DDMMyyyy) { 279 | return validateddMMyyyyDateFormat(value) 280 | 281 | } 282 | return value 283 | } 284 | 285 | /** 286 | * validate user text input for DDMMyyyy Date Format 287 | * @param value: String (user text input) 288 | * @return the corrected value 289 | */ 290 | private fun validateddMMyyyyDateFormat(value: String): String { 291 | var mValue = value 292 | 293 | // validate day 294 | if (mValue.length >= 2) { 295 | val day = mValue.substring(0, 2).toInt() 296 | if (day > 31 || day == 0) { 297 | if (autoCorrect){ 298 | mValue = "31" 299 | }else{ 300 | setError(value= mValue.substring(0, 2), errorMessage = context.getString(R.string.invalid_day)) 301 | } 302 | } 303 | } 304 | 305 | // validate month 306 | if (mValue.length >= 5) { 307 | val month = mValue.substring(3, 5).toInt() 308 | if (month > 12 || month == 0) { 309 | if (autoCorrect){ 310 | mValue = mValue.replace(month.toString(), "12", false) 311 | }else{ 312 | setError(value= mValue.substring(0,5), errorMessage = context.getString(R.string.invalid_month)) 313 | } 314 | } 315 | // validate day of month 316 | val day = mValue.substring(0, 2).toInt() 317 | if (day == 31 && (month == 4 || month == 6 || month == 9 || month == 11)) { 318 | if (autoCorrect){ 319 | mValue = mValue.replace(day.toString(), "30", false) 320 | }else{ 321 | setError(value= mValue.substring(0,5), errorMessage = context.getString(R.string.invalid_day_of_month)) 322 | } 323 | } else if (month == 2 && day == 31) { 324 | if (autoCorrect){ 325 | mValue = mValue.replace(day.toString(), "29", false) 326 | }else{ 327 | setError(value= mValue.substring(0,5), errorMessage = context.getString(R.string.invalid_day_of_month)) 328 | } 329 | } 330 | } 331 | 332 | // validate max && min date 333 | if (mValue.length == 10) { 334 | val year = mValue.substring(6, 10).toInt() 335 | if (maxDate != null) { 336 | val maxDate = maxDate!! 337 | val format = getDateFormatFromDivider() 338 | val inputDate = value.toDate(format = format) 339 | if (inputDate != null && inputDate > maxDate) { 340 | if (autoCorrect){ 341 | mValue = maxDate.toString(format = format) 342 | }else{ 343 | setError(value= mValue, errorMessage = context.getString(R.string.invalid_date_max)) 344 | } 345 | } 346 | } 347 | if (minDate != null) { 348 | val minDate = minDate!! 349 | val format = getDateFormatFromDivider() 350 | val inputDate = value.toDate(format = format) 351 | if (inputDate != null && inputDate < minDate) { 352 | if (autoCorrect){ 353 | mValue = minDate.toString(format = format) 354 | }else{ 355 | setError(value= mValue, errorMessage = context.getString(R.string.invalid_date_min)) 356 | } 357 | } 358 | } 359 | //not Leap year 360 | if (isLeapYear(year).not()) { 361 | val month = mValue.substring(3, 5).toInt() 362 | val day = mValue.substring(0, 2).toInt() 363 | if (month == 2 && day >= 28) { 364 | if (autoCorrect){ 365 | mValue = mValue.replace(day.toString(), "28", false) 366 | }else{ 367 | setError(value= mValue, errorMessage = context.getString(R.string.invalid_day_of_month_leap_year)) 368 | } 369 | } 370 | } 371 | } 372 | return mValue 373 | } 374 | 375 | private fun isLeapYear(year: Int) = when { 376 | year % 4 == 0 -> { 377 | when { 378 | year % 100 == 0 -> year % 400 == 0 379 | else -> true 380 | } 381 | } 382 | else -> false 383 | } 384 | 385 | /** 386 | * validate user text input for MMyy Date Format 387 | * @param value: String (user text input) 388 | * @return the corrected value 389 | */ 390 | private fun validateMMyyDateFormat(value: String): String { 391 | var mValue = value 392 | 393 | // validate month 394 | if (mValue.length >= 2) { 395 | val month = mValue.substring(0, 2).toInt() 396 | if (month > 12 || month == 0) { 397 | if (autoCorrect) { 398 | mValue = "12" 399 | } else { 400 | setError(value= month.toString(), errorMessage = context.getString(R.string.invalid_month)) 401 | } 402 | } 403 | } 404 | // validate year 405 | if (mValue.length == 5) { 406 | if (maxDate != null) { 407 | val maxDate = maxDate!! 408 | val format = getDateFormatFromDivider() 409 | val inputDate = value.toDate(format = format) 410 | if (inputDate != null && inputDate > maxDate) { 411 | if (autoCorrect){ 412 | mValue = maxDate.toString(format = format) 413 | }else{ 414 | setError(value= mValue, errorMessage = context.getString(R.string.invalid_date_max)) 415 | } 416 | } 417 | } 418 | if (minDate != null) { 419 | val minDate = minDate!! 420 | val format = getDateFormatFromDivider() 421 | val inputDate = value.toDate(format = format) 422 | if (inputDate != null && inputDate < minDate) { 423 | if (autoCorrect) { 424 | mValue = minDate.toString(format = format) 425 | }else{ 426 | setError(value= mValue, errorMessage = context.getString(R.string.invalid_date_min)) 427 | } 428 | } 429 | } 430 | } 431 | return mValue 432 | } 433 | 434 | /** 435 | * get edit text based on dateFormat length 436 | */ 437 | private fun getEditText(): String { 438 | return if ((text?.length ?: 0) >= dateLength) 439 | text.toString().substring(0, dateLength) 440 | else 441 | text.toString() 442 | } 443 | 444 | /** 445 | * @author Ícaro Mota from stackoverflow 446 | * add or remove divider character to the user text input 447 | * @param working: user text input 448 | * @param position: the position where we want to insert the divider character on user text input 449 | * @param start: start editing position 450 | * @param before: length before editing 451 | * @return the text after add ir removing divider character from user text input 452 | */ 453 | private fun manageDateDivider(working: String, position: Int, start: Int, before: Int): String { 454 | if (working.length == position) { 455 | return if (before <= position && start < position) 456 | working + dividerCharacter.value 457 | else 458 | working.dropLast(1) 459 | } 460 | return working 461 | } 462 | 463 | /** 464 | * get date format based on divider character 465 | * @return date format with divider character 466 | */ 467 | private fun getDateFormatFromDivider(): String { 468 | return when (dateFormat) { 469 | DateFormat.MMyy -> dateFormat.value.substring(0, 2) + dividerCharacter.value + dateFormat.value.substring( 470 | 2, 471 | 4 472 | ) 473 | DateFormat.DDMMyyyy -> dateFormat.value.substring( 474 | 0, 475 | 2 476 | ) + dividerCharacter.value + dateFormat.value.substring( 477 | 2, 478 | 4 479 | ) + dividerCharacter.value + dateFormat.value.substring(4, 8) 480 | } 481 | } 482 | 483 | /** 484 | * set error to edit text 485 | * @param errorMessage error message will render 486 | * @param value the value which has the error 487 | */ 488 | private fun setError(errorMessage: String?, value: String?){ 489 | valueWithError = value 490 | if (parent.parent is TextInputLayout){ 491 | val parentTextInputLayout = parent.parent as TextInputLayout 492 | parentTextInputLayout.helperText = null 493 | parentTextInputLayout.error = errorMessage 494 | if (errorMessage == null){ 495 | parentTextInputLayout.isErrorEnabled = false 496 | } 497 | }else{ 498 | error = errorMessage 499 | } 500 | } 501 | 502 | /** 503 | * render helper text if the parent of edit text is TextInputLayout 504 | * @param value user text input after validation process 505 | */ 506 | private fun renderHelperText(value: String) { 507 | 508 | if (parent.parent is TextInputLayout && helperTextEnabled){ 509 | val textInputLayout = parent.parent as TextInputLayout 510 | if (value.isEmpty()){ 511 | textInputLayout.helperText = null 512 | return 513 | } 514 | textInputLayout.isHelperTextEnabled = true 515 | val hint = getDateFormatFromDivider() 516 | val spannableString = SpannableString(hint) 517 | val foregroundSpan = ForegroundColorSpan(helperTextHighlightedColor) 518 | spannableString.setSpan( 519 | foregroundSpan, 520 | 0, 521 | value.length , 522 | Spannable.SPAN_EXCLUSIVE_EXCLUSIVE 523 | ) 524 | textInputLayout.helperText = spannableString 525 | } 526 | } 527 | } 528 | 529 | -------------------------------------------------------------------------------- /dateedittext/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 | -------------------------------------------------------------------------------- /dateedittext/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Date Edit Text 3 | Invalid Day 4 | Invalid Month 5 | Invalid Day Of Month 6 | Invalid day Of Month For Leap Year 7 | Invalid Date Max Date 8 | Invalid Date Min Date 9 | 10 | -------------------------------------------------------------------------------- /dateedittext/src/test/java/com/msa/dateedittext/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.msa.dateedittext; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app's APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | # Kotlin code style for this project: "official" or "obsolete": 21 | kotlin.code.style=official 22 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/salahamassi/Android-Mask-Date-EditText/21eb819ba2b8a52d1ed5fb29090af25f6400e6bb/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Mar 05 15:59:31 IST 2020 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':dateedittext' 2 | --------------------------------------------------------------------------------