diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml deleted file mode 100644 index 9d7f6283ccae1b7e719a9e46a295f91dd98ae087..0000000000000000000000000000000000000000 --- a/.github/FUNDING.yml +++ /dev/null @@ -1,12 +0,0 @@ -# These are supported funding model platforms - -github: lopspower -patreon: # Replace with a single Patreon username -open_collective: # Replace with a single Open Collective username -ko_fi: # Replace with a single Ko-fi username -tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel -community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry -liberapay: # Replace with a single Liberapay username -issuehunt: # Replace with a single IssueHunt username -otechie: # Replace with a single Otechie username -custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] diff --git a/.gitignore b/.gitignore index 322254857b1324e070a013229ada7a36f401415f..37a4eb8b43d978ea05b2c6e3fb934f9b40dddd4d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,15 @@ -# GENERATED -*build -buildsystem +*.iml .gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml .DS_Store - -# LOCAL -local.properties - -# IDEA -*.idea -*.iml \ No newline at end of file +/build +/captures +.externalNativeBuild +/entry/.preview +.cxx diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000000000000000000000000000000000000..12da5d127ca677b39456a7cf0611dfd302ca9df1 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +## 0.0.1-SNAPSHOT + +ohos第一个版本 + +* 实现了原库大部分api \ No newline at end of file diff --git a/README.OPENSOURCE b/README.OPENSOURCE new file mode 100644 index 0000000000000000000000000000000000000000..b539345a50f6399430fcbb67f0e5a653f8e8b0f4 --- /dev/null +++ b/README.OPENSOURCE @@ -0,0 +1,19 @@ +[ + +​ { + +​ "Name": "LazyDatePicker", + +​ "License": "Apache License", + +​ "License File": "LICENSE", + +​ "Version Number":"v1.1.0", + +​ "Upstream URL": "https://github.com/lopspower/LazyDatePicker", + +​ "Description": "This is an Android project to offer an alternative to the native Android Date Picker." + +​ } + +] \ No newline at end of file diff --git a/README.md b/README.md index 96115d79777ae83eb4d7a4f3fb74361657dc4fbc..20227e48921536e7633898fac864d39f1cf14e7d 100644 --- a/README.md +++ b/README.md @@ -1,166 +1,104 @@ -LazyDatePicker -================= +# LazyDatePicker -sample +#### 项目介绍 -[![Platform](https://img.shields.io/badge/platform-android-green.svg)](http://developer.android.com/index.html) -[![API](https://img.shields.io/badge/API-16%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=16) -[![Maven Central](https://img.shields.io/maven-central/v/com.mikhaellopez/lazydatepicker.svg?label=Maven%20Central)](https://search.maven.org/artifact/com.mikhaellopez/lazydatepicker) -
-[![Android Weekly](https://img.shields.io/badge/Android%20Weekly-%23317-orange.svg)](https://androidweekly.net/issues/issue-317) -[![Twitter](https://img.shields.io/badge/Twitter-@LopezMikhael-blue.svg?style=flat)](http://twitter.com/lopezmikhael) +* 项目名称:LazyDatePicker +* 所属系列:openharmony的第三方组件适配移植 +* 功能:日期选择器 +* 项目移植状态:主功能完成 +* 调用差异:无 +* 开发版本:sdk6,DevEco Studio 2.2 Beta1 +* 基线版本:Release v1.1.0 -This is an Android project to offer an alternative to the native Android Date Picker. +#### 效果演示 - - Android app on Google Play - +![输入图片说明](https://images.gitee.com/uploads/images/2021/0625/103828_8573e8b1_7648707.gif "LazyDatePicker.gif") -USAGE ------ +#### 安装教程 -To make a lazy date picker add LazyDatePicker in your layout XML and add LazyDatePicker library in your project or you can also grab it via Gradle: +1.在项目根目录下的build.gradle文件中 -```groovy -implementation 'com.mikhaellopez:lazydatepicker:1.1.0' -``` - -XML ------ - -```xml - -``` - -You must use the following properties in your XML to change your LazyDatePicker. - -| Properties | Type | Default | -| ----------------------- | -------------------------| ---------- | -| `app:ldp_text_color` | color | BLACK | -| `app:ldp_hint_color` | color | GRAY | -| `app:ldp_date_format` | mm-dd-yyyy or dd-mm-yyyy | mm-dd-yyyy | -| `app:ldp_show_full_date`| boolean | true | - -KOTLIN ------ - -```kotlin -lazyDatePicker.setDateFormat(LazyDatePicker.DateFormat.MM_DD_YYYY) -lazyDatePicker.setMinDate(minDate) -lazyDatePicker.setMaxDate(maxDate) - -// The date when is selected -lazyDatePicker.setOnDatePickListener { dateSelected -> - //... -} - -// True or false when date is selected -lazyDatePicker.setOnDateSelectedListener { dateSelected -> - //... +```txt +allprojects { + repositories { + maven { + url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' + } + } } ``` -JAVA ------ - -```java -LazyDatePicker lazyDatePicker = findViewById(R.id.lazyDatePicker); -lazyDatePicker.setDateFormat(LazyDatePicker.DateFormat.MM_DD_YYYY); -lazyDatePicker.setMinDate(minDate); -lazyDatePicker.setMaxDate(maxDate); +2.在entry模块下的build.gradle文件中 -lazyDatePicker.setOnDatePickListener(new LazyDatePicker.OnDatePickListener() { - @Override - public void onDatePick(Date dateSelected) { - //... - } -}); - -lazyDatePicker.setOnDateSelectedListener(new LazyDatePicker.OnDateSelectedListener() { - @Override - public void onDateSelected(Boolean dateSelected) { - //... - } -}); +```text +dependencies { + implementation('com.gitee.chinasoft_ohos:LazyDatePicker:0.0.1-SNAPSHOT') + ...... + } ``` -[LOCAL DATE](https://github.com/JakeWharton/ThreeTenABP) ------ +在sdk6,DevEco Studio2.2 Beta1下项目可直接运行 如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, 并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下 -You can used `LazyLocalDatePicker` instead of `LazyDatePicker` to have all method with `LocalDate` instead of `Date`. +#### 使用说明 -### XML: +在xml布局中引用 -```xml - +```txt + ``` -### KOTLIN: +并在外部设置最大值及最小值 + +```txt +// Define min & max date for sample + Date minDate = LazyDatePicker.stringToDate("01-01-2016", DATE_FORMAT); + Date maxDate = LazyDatePicker.stringToDate("12-31-2018", DATE_FORMAT); + +// Init LazyDatePicker + LazyDatePicker lazyDatePicker = (LazyDatePicker) findComponentById(ResourceTable.Id_lazyDatePicker); + lazyDatePicker.setMinDate(minDate); + lazyDatePicker.setMaxDate(maxDate); +``` -```kotlin -lazyLocalDatePicker.setDateFormat(LazyDatePicker.DateFormat.MM_DD_YYYY) -lazyLocalDatePicker.setMinLocalDate(minDate) -lazyLocalDatePicker.setMaxLocalDate(maxDate) +且支持设置监听 -// The localdate when is selected -lazyLocalDatePicker.setOnLocalDatePickListener { localDateSelected -> - //... -} - -// True or false when date is selected -lazyLocalDatePicker.setOnLocalDateSelectedListener { dateSelected -> - //... -} +```txt +lazyDatePicker.setOnDatePickListener(new LazyDatePicker.OnDatePickListener() { + @Override + public void onDatePick(Date dateSelected) { + new ToastDialog(MainAbilitySlice.this).setContentText( "Selected date: " + LazyDatePicker.dateToString(dateSelected, DATE_FORMAT)).show(); + } + }); + + lazyDatePicker.setOnDateSelectedListener(new LazyDatePicker.OnDateSelectedListener() { + @Override + public void onDateSelected(Boolean dateSelected) { + System.out.println("onDateSelected: " + dateSelected); + } + }); ``` -OVERRIDE ------ +#### 测试信息 -You can override day, month & year if you want like this in your `strings.xml`: +CodeCheck代码测试无异常 -```xml - - - D - M - Y - -``` - -You can also change the design of the picker by changing the dimensions like this in your `dimens.xml`: +CloudTest代码测试无异常 -```xml - - - 12dp - 2.5dp - 1dp - 6dp - -``` +病毒安全检测通过 -And to finish you can also completely redefine the layout by keeping the same name `layout_lazy_date_picker.xml` and keep all the ids. You can find the default one here: [**layout_lazy_date_picker.xml**](/lazydatepicker/src/main/res/layout/layout_lazy_date_picker.xml) +当前版本demo功能与原组件基本无差异 -SUPPORT ❤️ ------ +#### 版本迭代 -Find this library useful? Support it by joining [**stargazers**](https://github.com/lopspower/LazyDatePicker/stargazers) for this repository ⭐️ -
-And [**follow me**](https://github.com/lopspower?tab=followers) for my next creations 👍 +* 0.0.1-SNAPSHOT -LICENCE ------ +#### 版权和许可信息 -LazyDatePicker by [Lopez Mikhael](http://mikhaellopez.com/) is licensed under a [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0). +LazyDatePicker by Lopez Mikhael is licensed under a [Apache License 2.0](./LICENSE) \ No newline at end of file diff --git a/build.gradle b/build.gradle index 808dd0bfadc8f8a3eccb01d9d71f5ecf1d3c5a8f..3e251a71ea27ad3f566fb1181e7d464374d64dd0 100755 --- a/build.gradle +++ b/build.gradle @@ -1,18 +1,44 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. -apply from: 'dependencies.gradle' +apply plugin: 'com.huawei.ohos.app' + +//For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#ZH-CN_TOPIC_0000001154985555__section1112183053510 +ohos { + compileSdkVersion 6 + defaultConfig { + compatibleSdkVersion 5 + } +} buildscript { repositories { - google() - mavenCentral() - gradlePluginPortal() + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + maven { + url 'http://106.15.92.248:8081/repository/Releases/' + } + jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:4.2.1' - classpath 'com.github.ben-manes:gradle-versions-plugin:0.38.0' + classpath 'com.huawei.ohos:hap:2.4.5.0' + classpath 'com.huawei.ohos:decctest:1.2.4.1' } } -task clean(type: Delete) { - delete rootProject.buildDir -} \ No newline at end of file +allprojects { + repositories { + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + maven { + url 'http://106.15.92.248:8081/repository/Releases/' + } + jcenter() + } +} diff --git a/dependencies.gradle b/dependencies.gradle deleted file mode 100644 index ca3504e407f4ca1659db38d186fc4e9b3e39cf2e..0000000000000000000000000000000000000000 --- a/dependencies.gradle +++ /dev/null @@ -1,45 +0,0 @@ -allprojects { - repositories { - google() - mavenCentral() - } -} - -ext { - // APP VERSION - androidVersionCode = 8 - androidVersionName = "1.1.0" - libraryGroupId = 'com.mikhaellopez' - libraryArtifactId = 'lazydatepicker' - libraryVersion = androidVersionName - - // ANDROID VERSION - androidCompileSdkVersion = 30 - androidMinSdkVersion = 15 - androidTargetSdkVersion = 30 - - // ANDROID LIB - androidXAppCompat = "androidx.appcompat:appcompat:1.3.0" - - // HELPER - threetenabp = 'com.jakewharton.threetenabp:threetenabp:1.3.1' - - // DEPENDENCY CHECK STRATEGY - dependencyUpdatesStrategy = { - def isNonStable = { String version -> - def stableKeyword = ['RELEASE', 'FINAL', 'GA'].any { keyword -> - version.toUpperCase().contains(keyword) - } - def regex = /^[0-9,.v-]+(-r)?$/ - return !stableKeyword && !(version ==~ regex) - } - componentSelection { - all { - if (isNonStable(it.candidate.version) && !isNonStable(it.currentVersion)) { - reject('Release candidate') - } - } - } - } - -} \ No newline at end of file diff --git a/entry/.gitignore b/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..796b96d1c402326528b4ba3c12ee9d92d0e212e9 --- /dev/null +++ b/entry/.gitignore @@ -0,0 +1 @@ +/build diff --git a/entry/build.gradle b/entry/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..b3d59a5ad9abc9f4e3905c7662f920f39bf1bb3e --- /dev/null +++ b/entry/build.gradle @@ -0,0 +1,28 @@ +apply plugin: 'com.huawei.ohos.hap' +apply plugin: 'com.huawei.ohos.decctest' +//For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#ZH-CN_TOPIC_0000001154985555__section1112183053510 +ohos { + compileSdkVersion 6 + defaultConfig { + compatibleSdkVersion 5 + } + buildTypes { + release { + proguardOpt { + proguardEnabled false + rulesFiles 'proguard-rules.pro' + } + } + } + +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) + testImplementation 'junit:junit:4.13' + ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.100' + implementation project(':lazydatepicker') +} +decc { + supportType = ['html', 'xml'] +} diff --git a/entry/proguard-rules.pro b/entry/proguard-rules.pro new file mode 100644 index 0000000000000000000000000000000000000000..f7666e47561d514b2a76d5a7dfbb43ede86da92a --- /dev/null +++ b/entry/proguard-rules.pro @@ -0,0 +1 @@ +# config module specific ProGuard rules here. \ No newline at end of file diff --git a/entry/src/main/config.json b/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..14d7bdbbd7032183d87baead29ed00458d50ba0b --- /dev/null +++ b/entry/src/main/config.json @@ -0,0 +1,46 @@ +{ + "app": { + "bundleName": "com.mikhaellopez.lazydatepickersample", + "vendor": "mikhaellopez", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.mikhaellopez.lazydatepickersample", + "name": ".MyApplication", + "mainAbility": "com.mikhaellopez.lazydatepickersample.MainAbility", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry", + "installationFree": false + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "name": "com.mikhaellopez.lazydatepickersample.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:entry_MainAbility", + "type": "page", + "launchType": "standard" + } + ] + } +} \ No newline at end of file diff --git a/entry/src/main/java/com/mikhaellopez/lazydatepickersample/MainAbility.java b/entry/src/main/java/com/mikhaellopez/lazydatepickersample/MainAbility.java new file mode 100644 index 0000000000000000000000000000000000000000..0119871da438580e4a602003ab6e368bfc9af09d --- /dev/null +++ b/entry/src/main/java/com/mikhaellopez/lazydatepickersample/MainAbility.java @@ -0,0 +1,13 @@ +package com.mikhaellopez.lazydatepickersample; + +import com.mikhaellopez.lazydatepickersample.slice.MainAbilitySlice; +import ohos.aafwk.ability.Ability; +import ohos.aafwk.content.Intent; + +public class MainAbility extends Ability { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setMainRoute(MainAbilitySlice.class.getName()); + } +} diff --git a/entry/src/main/java/com/mikhaellopez/lazydatepickersample/MyApplication.java b/entry/src/main/java/com/mikhaellopez/lazydatepickersample/MyApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..8a211945f14ba68c470721ef352d2740331663e1 --- /dev/null +++ b/entry/src/main/java/com/mikhaellopez/lazydatepickersample/MyApplication.java @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.mikhaellopez.lazydatepickersample; + +import ohos.aafwk.ability.AbilityPackage; + +public class MyApplication extends AbilityPackage { + @Override + public void onInitialize() { + super.onInitialize(); + } +} diff --git a/entry/src/main/java/com/mikhaellopez/lazydatepickersample/slice/MainAbilitySlice.java b/entry/src/main/java/com/mikhaellopez/lazydatepickersample/slice/MainAbilitySlice.java new file mode 100644 index 0000000000000000000000000000000000000000..92ac353cffa0817354dc3833c1c5eeb1a8bc66d4 --- /dev/null +++ b/entry/src/main/java/com/mikhaellopez/lazydatepickersample/slice/MainAbilitySlice.java @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.mikhaellopez.lazydatepickersample.slice; + +import com.mikhaellopez.lazydatepicker.LazyDatePicker; +import com.mikhaellopez.lazydatepickersample.ResourceTable; + +import ohos.aafwk.ability.AbilitySlice; +import ohos.aafwk.content.Intent; +import ohos.agp.components.Component; +import ohos.agp.components.Text; +import ohos.agp.window.dialog.ToastDialog; + +import java.util.Date; + +/** + * MainAbilitySlice + * + * @since 2021-06-28 + */ +public class MainAbilitySlice extends AbilitySlice { + private static final String DATE_FORMAT = "MM-dd-yyyy"; + private LazyDatePicker lazyDatePicker; + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_ability_main); + + // Define min & max date for sample + Date minDate = LazyDatePicker.stringToDate("01-01-2016", DATE_FORMAT); + Date maxDate = LazyDatePicker.stringToDate("12-31-2018", DATE_FORMAT); + + // Init View + ((Text) findComponentById(ResourceTable.Id_textViewMinDate)) + .setText(LazyDatePicker.dateToString(minDate, DATE_FORMAT)); + ((Text) findComponentById(ResourceTable.Id_textViewMaxDate)) + .setText(LazyDatePicker.dateToString(maxDate, DATE_FORMAT)); + + Component component = findComponentById(ResourceTable.Id_root); + + // Init LazyDatePicker + lazyDatePicker = (LazyDatePicker) findComponentById(ResourceTable.Id_lazyDatePicker); + lazyDatePicker.setKeyboardVisibilityEvent(this, component); + + lazyDatePicker.setMinDate(minDate); + lazyDatePicker.setMaxDate(maxDate); + + lazyDatePicker.setOnDatePickListener(new LazyDatePicker.OnDatePickListener() { + @Override + public void onDatePick(Date dateSelected) { + new ToastDialog(MainAbilitySlice.this) + .setContentText("Selected date: " + LazyDatePicker.dateToString(dateSelected, DATE_FORMAT)) + .show(); + } + }); + + lazyDatePicker.setOnDateSelectedListener(new LazyDatePicker.OnDateSelectedListener() { + @Override + public void onDateSelected(Boolean isDateSelected) { + } + }); + } +} \ No newline at end of file diff --git a/entry/src/main/resources/base/element/string.json b/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..6e3df45cfd5ad24da99b05421a179acfd4f78dc5 --- /dev/null +++ b/entry/src/main/resources/base/element/string.json @@ -0,0 +1,20 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "entry_MainAbility" + }, + { + "name": "mainability_description", + "value": "Java_Empty Ability" + }, + { + "name": "mainability_HelloWorld", + "value": "Hello World" + }, + { + "name": "select_date_between_min_max_date", + "value": "For this sample, you need to select your date between this min & max date with mm-dd-yyyy format:" + } + ] +} \ No newline at end of file diff --git a/entry/src/main/resources/base/graphic/background_ability_main.xml b/entry/src/main/resources/base/graphic/background_ability_main.xml new file mode 100644 index 0000000000000000000000000000000000000000..c0c0a3df480fa387a452b9c40ca191cc918a3fc0 --- /dev/null +++ b/entry/src/main/resources/base/graphic/background_ability_main.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/layout/ability_main.xml b/entry/src/main/resources/base/layout/ability_main.xml new file mode 100644 index 0000000000000000000000000000000000000000..736225a0f157d5075d10ce3a61086277ef8390af --- /dev/null +++ b/entry/src/main/resources/base/layout/ability_main.xml @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lazydatepicker-example/src/main/res/layout/activity_main.xml b/entry/src/main/resources/base/layout/activity_main.xml old mode 100755 new mode 100644 similarity index 100% rename from lazydatepicker-example/src/main/res/layout/activity_main.xml rename to entry/src/main/resources/base/layout/activity_main.xml diff --git a/entry/src/main/resources/base/media/icon.png b/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/entry/src/main/resources/base/media/icon.png differ diff --git a/entry/src/main/resources/en/element/string.json b/entry/src/main/resources/en/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f5783e5abf990ec0085620d444a0fad7a91b1854 --- /dev/null +++ b/entry/src/main/resources/en/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "LazyDatePicker" + }, + { + "name": "mainability_description", + "value": "Java_Empty Ability" + }, + { + "name": "mainability_HelloWorld", + "value": "Hello World" + } + ] +} diff --git a/entry/src/main/resources/zh/element/string.json b/entry/src/main/resources/zh/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..04ad872de9e3c97e158b4f3ca8cf637ffb49207a --- /dev/null +++ b/entry/src/main/resources/zh/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "LazyDatePicker" + }, + { + "name": "mainability_description", + "value": "Java_Empty Ability" + }, + { + "name": "mainability_HelloWorld", + "value": "你好,世界" + } + ] +} \ No newline at end of file diff --git a/entry/src/ohosTest/java/com/mikhaellopez/lazydatepickersample/ExampleOhosTest.java b/entry/src/ohosTest/java/com/mikhaellopez/lazydatepickersample/ExampleOhosTest.java new file mode 100644 index 0000000000000000000000000000000000000000..1025ab215f4edee7ffba89725fee645037069860 --- /dev/null +++ b/entry/src/ohosTest/java/com/mikhaellopez/lazydatepickersample/ExampleOhosTest.java @@ -0,0 +1,15 @@ +package com.mikhaellopez.lazydatepickersample; + +import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class ExampleOhosTest { + // entry下需要context,无法进行单元测试 + @Test + public void testBundleName() { + final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName(); + assertEquals("com.mikhaellopez.lazydatepickersample", actualBundleName); + } +} \ No newline at end of file diff --git a/entry/src/test/java/com/mikhaellopez/lazydatepickersample/ExampleTest.java b/entry/src/test/java/com/mikhaellopez/lazydatepickersample/ExampleTest.java new file mode 100644 index 0000000000000000000000000000000000000000..7b00867b9b3991a0c54109d51530ed926f3933be --- /dev/null +++ b/entry/src/test/java/com/mikhaellopez/lazydatepickersample/ExampleTest.java @@ -0,0 +1,9 @@ +package com.mikhaellopez.lazydatepickersample; + +import org.junit.Test; + +public class ExampleTest { + @Test + public void onStart() { + } +} diff --git a/gradle.properties b/gradle.properties deleted file mode 100755 index 2d8d1e4dd150cb790e1efef522121e30222820d4..0000000000000000000000000000000000000000 --- a/gradle.properties +++ /dev/null @@ -1 +0,0 @@ -android.useAndroidX=true \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 13372aef5e24af05341d49695ee84e5f9b594659..490fda8577df6c95960ba7077c43220e5bb2c0d9 100755 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e1de9a2cadacdff733afb061bbec524648802dd6..f59159e865d4b59feb1b8c44b001f62fc5d58df4 100755 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Mon Mar 02 11:59:56 CET 2020 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://repo.huaweicloud.com/gradle/gradle-6.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip diff --git a/gradlew b/gradlew deleted file mode 100755 index 9d82f78915133e1c35a6ea51252590fb38efac2f..0000000000000000000000000000000000000000 --- a/gradlew +++ /dev/null @@ -1,160 +0,0 @@ -#!/usr/bin/env bash - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn ( ) { - echo "$*" -} - -die ( ) { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; -esac - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=$((i+1)) - done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") -} -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" - -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/gradlew.bat b/gradlew.bat deleted file mode 100755 index 8a0b282aa6885fb573c106b3551f7275c5f17e8e..0000000000000000000000000000000000000000 --- a/gradlew.bat +++ /dev/null @@ -1,90 +0,0 @@ -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windowz variants - -if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/lazydatepicker-example/build.gradle b/lazydatepicker-example/build.gradle deleted file mode 100755 index f9e08d345e647d97da97250ee7918fe31fd4c804..0000000000000000000000000000000000000000 --- a/lazydatepicker-example/build.gradle +++ /dev/null @@ -1,31 +0,0 @@ -apply plugin: 'com.android.application' -apply plugin: 'com.github.ben-manes.versions' - -android { - compileSdkVersion androidCompileSdkVersion - defaultConfig { - applicationId "com.mikhaellopez.lazydatepickersample" - minSdkVersion androidMinSdkVersion - targetSdkVersion androidTargetSdkVersion - versionCode 1 - versionName "1.0" - } - buildTypes { - release { - minifyEnabled false - } - } -} - -dependencies { - implementation project(':lazydatepicker') - //implementation "com.mikhaellopez:lazydatepicker:$androidVersionName" - - // ANDROID - implementation androidXAppCompat - // DATE - implementation threetenabp - - // DEPENDENCY CHECK STRATEGY - dependencyUpdates.resolutionStrategy dependencyUpdatesStrategy -} diff --git a/lazydatepicker-example/src/main/AndroidManifest.xml b/lazydatepicker-example/src/main/AndroidManifest.xml deleted file mode 100755 index 7ca7da6da7970d265964bc2831f7b3a9ee3677cd..0000000000000000000000000000000000000000 --- a/lazydatepicker-example/src/main/AndroidManifest.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/lazydatepicker-example/src/main/java/com/mikhaellopez/lazydatepickersample/MainActivity.java b/lazydatepicker-example/src/main/java/com/mikhaellopez/lazydatepickersample/MainActivity.java deleted file mode 100755 index a92d2f3eb15ca6f7378e06591477da770d7bbf39..0000000000000000000000000000000000000000 --- a/lazydatepicker-example/src/main/java/com/mikhaellopez/lazydatepickersample/MainActivity.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.mikhaellopez.lazydatepickersample; - -import android.os.Bundle; -import android.util.Log; -import android.widget.TextView; -import android.widget.Toast; - -import androidx.appcompat.app.AppCompatActivity; - -import com.mikhaellopez.lazydatepicker.LazyDatePicker; - -import java.util.Date; - -public class MainActivity extends AppCompatActivity { - - private static final String DATE_FORMAT = "MM-dd-yyyy"; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - - // Define min & max date for sample - Date minDate = LazyDatePicker.stringToDate("01-01-2016", DATE_FORMAT); - Date maxDate = LazyDatePicker.stringToDate("12-31-2018", DATE_FORMAT); - - // Init View - ((TextView) findViewById(R.id.textViewMinDate)).setText(LazyDatePicker.dateToString(minDate, DATE_FORMAT)); - ((TextView) findViewById(R.id.textViewMaxDate)).setText(LazyDatePicker.dateToString(maxDate, DATE_FORMAT)); - - // Init LazyDatePicker - LazyDatePicker lazyDatePicker = findViewById(R.id.lazyDatePicker); - lazyDatePicker.setMinDate(minDate); - lazyDatePicker.setMaxDate(maxDate); - - lazyDatePicker.setOnDatePickListener(new LazyDatePicker.OnDatePickListener() { - @Override - public void onDatePick(Date dateSelected) { - Toast.makeText(MainActivity.this, - "Selected date: " + LazyDatePicker.dateToString(dateSelected, DATE_FORMAT), - Toast.LENGTH_SHORT).show(); - } - }); - - lazyDatePicker.setOnDateSelectedListener(new LazyDatePicker.OnDateSelectedListener() { - @Override - public void onDateSelected(Boolean dateSelected) { - Log.d(MainActivity.class.getSimpleName(), "onDateSelected: " + dateSelected); - } - }); - } - -} diff --git a/lazydatepicker-example/src/main/java/com/mikhaellopez/lazydatepickersample/MainLocalDateActivity.java b/lazydatepicker-example/src/main/java/com/mikhaellopez/lazydatepickersample/MainLocalDateActivity.java deleted file mode 100755 index c673cd4d860bd57ab64a158fb4c515dd44509a28..0000000000000000000000000000000000000000 --- a/lazydatepicker-example/src/main/java/com/mikhaellopez/lazydatepickersample/MainLocalDateActivity.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.mikhaellopez.lazydatepickersample; - -import android.os.Bundle; -import android.util.Log; -import android.widget.TextView; -import android.widget.Toast; - -import androidx.appcompat.app.AppCompatActivity; - -import com.mikhaellopez.lazydatepicker.LazyLocalDatePicker; - -import org.threeten.bp.LocalDate; - -public class MainLocalDateActivity extends AppCompatActivity { - - private static final String DATE_FORMAT = "MM-dd-yyyy"; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_local_date_main); - - // Define min & max date for sample - LocalDate minDate = LazyLocalDatePicker.stringToLocalDate("01-01-2016", DATE_FORMAT); - LocalDate maxDate = LazyLocalDatePicker.stringToLocalDate("12-31-2018", DATE_FORMAT); - - // Init View - ((TextView) findViewById(R.id.textViewMinDate)).setText(LazyLocalDatePicker.dateToString(minDate, DATE_FORMAT)); - ((TextView) findViewById(R.id.textViewMaxDate)).setText(LazyLocalDatePicker.dateToString(maxDate, DATE_FORMAT)); - - // Init LazyLocalDatePicker - LazyLocalDatePicker lazyLocalDatePicker = findViewById(R.id.lazyLocalDatePicker); - lazyLocalDatePicker.setMinLocalDate(minDate); - lazyLocalDatePicker.setMaxLocalDate(maxDate); - - lazyLocalDatePicker.setOnLocalDatePickListener(new LazyLocalDatePicker.OnLocalDatePickListener() { - @Override - public void onLocalDatePick(LocalDate dateSelected) { - Toast.makeText(MainLocalDateActivity.this, - "Selected date: " + LazyLocalDatePicker.dateToString(dateSelected, DATE_FORMAT), - Toast.LENGTH_SHORT).show(); - } - }); - - lazyLocalDatePicker.setOnLocalDateSelectedListener(new LazyLocalDatePicker.OnLocalDateSelectedListener() { - @Override - public void onLocalDateSelected(Boolean dateSelected) { - Log.d(MainLocalDateActivity.class.getSimpleName(), "onLocalDateSelected: " + dateSelected); - } - }); - } - -} diff --git a/lazydatepicker-example/src/main/res/layout/activity_local_date_main.xml b/lazydatepicker-example/src/main/res/layout/activity_local_date_main.xml deleted file mode 100755 index 866cb16e18806722d965421590ef9226624b3855..0000000000000000000000000000000000000000 --- a/lazydatepicker-example/src/main/res/layout/activity_local_date_main.xml +++ /dev/null @@ -1,82 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/lazydatepicker-example/src/main/res/mipmap-hdpi/ic_launcher.png b/lazydatepicker-example/src/main/res/mipmap-hdpi/ic_launcher.png deleted file mode 100755 index cde69bcccec65160d92116f20ffce4fce0b5245c..0000000000000000000000000000000000000000 Binary files a/lazydatepicker-example/src/main/res/mipmap-hdpi/ic_launcher.png and /dev/null differ diff --git a/lazydatepicker-example/src/main/res/mipmap-mdpi/ic_launcher.png b/lazydatepicker-example/src/main/res/mipmap-mdpi/ic_launcher.png deleted file mode 100755 index c133a0cbd379f5af6dbf1a899a0293ca5eccfad0..0000000000000000000000000000000000000000 Binary files a/lazydatepicker-example/src/main/res/mipmap-mdpi/ic_launcher.png and /dev/null differ diff --git a/lazydatepicker-example/src/main/res/mipmap-xhdpi/ic_launcher.png b/lazydatepicker-example/src/main/res/mipmap-xhdpi/ic_launcher.png deleted file mode 100755 index bfa42f0e7b91d006d22352c9ff2f134e504e3c1d..0000000000000000000000000000000000000000 Binary files a/lazydatepicker-example/src/main/res/mipmap-xhdpi/ic_launcher.png and /dev/null differ diff --git a/lazydatepicker-example/src/main/res/mipmap-xxhdpi/ic_launcher.png b/lazydatepicker-example/src/main/res/mipmap-xxhdpi/ic_launcher.png deleted file mode 100755 index 324e72cdd7480cb983fa1bcc7ce686e51ef87fe7..0000000000000000000000000000000000000000 Binary files a/lazydatepicker-example/src/main/res/mipmap-xxhdpi/ic_launcher.png and /dev/null differ diff --git a/lazydatepicker-example/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/lazydatepicker-example/src/main/res/mipmap-xxxhdpi/ic_launcher.png deleted file mode 100755 index aee44e138434630332d88b1680f33c4b24c70ab3..0000000000000000000000000000000000000000 Binary files a/lazydatepicker-example/src/main/res/mipmap-xxxhdpi/ic_launcher.png and /dev/null differ diff --git a/lazydatepicker-example/src/main/res/values-v21/themes.xml b/lazydatepicker-example/src/main/res/values-v21/themes.xml deleted file mode 100644 index 084f7a4ea693669b6961b0394ec14fa87392953e..0000000000000000000000000000000000000000 --- a/lazydatepicker-example/src/main/res/values-v21/themes.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/lazydatepicker-example/src/main/res/values/colors.xml b/lazydatepicker-example/src/main/res/values/colors.xml deleted file mode 100755 index 745cd1297e15a74e72860a713596e8788bb80f76..0000000000000000000000000000000000000000 --- a/lazydatepicker-example/src/main/res/values/colors.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - #424242 - #212121 - @color/primary - diff --git a/lazydatepicker-example/src/main/res/values/strings.xml b/lazydatepicker-example/src/main/res/values/strings.xml deleted file mode 100755 index d9e082e4f5b85a3eb969e989783085ae07d29264..0000000000000000000000000000000000000000 --- a/lazydatepicker-example/src/main/res/values/strings.xml +++ /dev/null @@ -1,4 +0,0 @@ - - LazyDatePicker - - diff --git a/lazydatepicker-example/src/main/res/values/themes.xml b/lazydatepicker-example/src/main/res/values/themes.xml deleted file mode 100755 index 7cd0e88a42868f69e1bd1f24a7ae25ef055e2108..0000000000000000000000000000000000000000 --- a/lazydatepicker-example/src/main/res/values/themes.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - diff --git a/lazydatepicker/.gitignore b/lazydatepicker/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..796b96d1c402326528b4ba3c12ee9d92d0e212e9 --- /dev/null +++ b/lazydatepicker/.gitignore @@ -0,0 +1 @@ +/build diff --git a/lazydatepicker/build.gradle b/lazydatepicker/build.gradle index c7cad5f85434c6ab88777db83334fc80998d909d..e342bf9c4828f4db9d5d0a5136bfbf2a8977a807 100644 --- a/lazydatepicker/build.gradle +++ b/lazydatepicker/build.gradle @@ -1,22 +1,23 @@ -apply plugin: 'com.android.library' - -android { - compileSdkVersion androidCompileSdkVersion +apply plugin: 'com.huawei.ohos.library' +//For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#ZH-CN_TOPIC_0000001154985555__section1112183053510 +ohos { + compileSdkVersion 5 defaultConfig { - minSdkVersion androidMinSdkVersion - targetSdkVersion androidTargetSdkVersion - versionCode androidVersionCode - versionName androidVersionName + compatibleSdkVersion 5 } buildTypes { release { - minifyEnabled false + proguardOpt { + proguardEnabled false + rulesFiles 'proguard-rules.pro' + } } } + } dependencies { - implementation threetenabp + implementation fileTree(dir: 'libs', include: ['*.jar']) + testImplementation 'junit:junit:4.13' + api 'net.yslibrary.keyboardvisibilityevent.ohos:keyboardvisibilityevent:1.0.0' } - -apply from: rootProject.file('gradle/publish-mavencentral.gradle') diff --git a/lazydatepicker/consumer-rules.pro b/lazydatepicker/consumer-rules.pro new file mode 100644 index 0000000000000000000000000000000000000000..9dccc613bc71b04b83531f550bdab2fb667ecfc9 --- /dev/null +++ b/lazydatepicker/consumer-rules.pro @@ -0,0 +1 @@ +# Add har specific ProGuard rules for consumer here. \ No newline at end of file diff --git a/lazydatepicker/proguard-rules.pro b/lazydatepicker/proguard-rules.pro new file mode 100644 index 0000000000000000000000000000000000000000..f7666e47561d514b2a76d5a7dfbb43ede86da92a --- /dev/null +++ b/lazydatepicker/proguard-rules.pro @@ -0,0 +1 @@ +# config module specific ProGuard rules here. \ No newline at end of file diff --git a/lazydatepicker/src/main/AndroidManifest.xml b/lazydatepicker/src/main/AndroidManifest.xml deleted file mode 100644 index e005bb686e51f6c0d95175bcdd5090c78f92bba6..0000000000000000000000000000000000000000 --- a/lazydatepicker/src/main/AndroidManifest.xml +++ /dev/null @@ -1 +0,0 @@ - diff --git a/lazydatepicker/src/main/config.json b/lazydatepicker/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..162df39c839030100499dd4861022452b73f06f9 --- /dev/null +++ b/lazydatepicker/src/main/config.json @@ -0,0 +1,23 @@ +{ + "app": { + "bundleName": "com.mikhaellopez.lazydatepickersample", + "vendor": "mikhaellopez", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": { + }, + "module": { + "package": "com.mikhaellopez.lazydatepicker", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "lazydatepicker", + "moduleType": "har" + } + } +} \ No newline at end of file diff --git a/lazydatepicker/src/main/java/com/mikhaellopez/lazydatepicker/LazyDatePicker.java b/lazydatepicker/src/main/java/com/mikhaellopez/lazydatepicker/LazyDatePicker.java index fb30bdc689c8f4b256b1ed9f4eef56bf5cd9345f..2a93b833451ba87ba7da3b2bd0fc8fa5de009d82 100755 --- a/lazydatepicker/src/main/java/com/mikhaellopez/lazydatepicker/LazyDatePicker.java +++ b/lazydatepicker/src/main/java/com/mikhaellopez/lazydatepicker/LazyDatePicker.java @@ -1,21 +1,22 @@ package com.mikhaellopez.lazydatepicker; -import android.content.Context; -import android.content.res.TypedArray; -import android.graphics.Color; -import android.graphics.Rect; -import android.text.Editable; -import android.text.TextWatcher; -import android.util.AttributeSet; -import android.view.View; -import android.view.ViewTreeObserver; -import android.view.animation.CycleInterpolator; -import android.view.inputmethod.InputMethodManager; -import android.widget.EditText; -import android.widget.LinearLayout; -import android.widget.RelativeLayout; -import android.widget.TextView; - +import net.yslibrary.ohos.sample.keyboardvisibilityevent.KeyboardVisibilityEvent; +import net.yslibrary.ohos.sample.keyboardvisibilityevent.KeyboardVisibilityEventListener; +import ohos.aafwk.ability.AbilitySlice; +import ohos.agp.animation.Animator; +import ohos.agp.animation.AnimatorProperty; +import ohos.agp.colors.RgbColor; +import ohos.agp.components.*; +import ohos.agp.components.element.ShapeElement; +import ohos.agp.utils.Color; +import ohos.agp.utils.Rect; +import ohos.agp.window.service.DisplayManager; +import ohos.agp.window.service.Window; +import ohos.agp.window.service.WindowManager; +import ohos.app.Context; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; @@ -24,263 +25,290 @@ import java.util.Locale; /** * Copyright (C) 2020 Mikhael LOPEZ * Licensed under the Apache License Version 2.0 + * + * @since 2021-06-28 */ -public class LazyDatePicker extends RelativeLayout { - +public class LazyDatePicker extends DependentLayout { protected static final int LENGTH_DATE_COMPLETE = 8; + protected String date; + protected DateFormat dateFormat; - private EditText editLazyDatePickerReal; - private LinearLayout layoutLazyDatePicker; - private TextView textLazyDatePickerDate; - - private TextView textLazyDate1; - private View viewLazyDate1; - private TextView textLazyDate2; - private View viewLazyDate2; - private TextView textLazyDate3; - private View viewLazyDate3; - private TextView textLazyDate4; - private View viewLazyDate4; - private TextView textLazyDate5; - private View viewLazyDate5; - private TextView textLazyDate6; - private View viewLazyDate6; - private TextView textLazyDate7; - private View viewLazyDate7; - private TextView textLazyDate8; - private View viewLazyDate8; + private TextField editLazyDatePickerReal; + private DirectionalLayout layoutLazyDatePicker; + private Text textLazyDatePickerDate; + + private Text textLazyDate1; + private Component viewLazyDate1; + private Text textLazyDate2; + private Component viewLazyDate2; + private Text textLazyDate3; + private Component viewLazyDate3; + private Text textLazyDate4; + private Component viewLazyDate4; + private Text textLazyDate5; + private Component viewLazyDate5; + private Text textLazyDate6; + private Component viewLazyDate6; + private Text textLazyDate7; + private Component viewLazyDate7; + private Text textLazyDate8; + private Component viewLazyDate8; + private Component contentComponent; // Properties - protected String date; - private int textColor; - private int hintColor; + private Color textColor; + private Color hintColor; private Date minDate; private Date maxDate; - protected DateFormat dateFormat; private boolean keyboardVisible = false; private boolean shakeAnimationDoing = false; private boolean showFullDate = true; private OnDatePickListener onDatePickListener; private OnDateSelectedListener onDateSelectedListener; - private TextWatcher textWatcher; - - //region CONSTRUCTORS + private Text.TextObserver textWatcher; + private AnimatorProperty animatorProperty; + private String cacheString = ""; + private ShapeElement transparentElement = new ShapeElement(); + private ShapeElement textColorElement = new ShapeElement(); + private ShapeElement hintColorElement = new ShapeElement(); + private KeyboardVisibilityEvent keyboardVisibilityEvent; + + /** + * 默认构造方式 + * + * @param context + */ public LazyDatePicker(Context context) { - this(context, null); - } - - public LazyDatePicker(Context context, AttributeSet attrs) { - this(context, attrs, 0); - } + super(context); + } + + /** + * 布局引用构造方式 + * + * @param context + * @param attrSet + */ + public LazyDatePicker(Context context, AttrSet attrSet) { + super(context, attrSet); + init(context, attrSet); + } + + /** + * 布局设置主题构造方式 + * + * @param context + * @param attrSet + * @param styleName + */ + public LazyDatePicker(Context context, AttrSet attrSet, String styleName) { + super(context, attrSet, styleName); + init(context, attrSet); + } + + /** + * 设置软键盘监听事件 + * + * @param slice + * @param rootComponent + */ + public void setKeyboardVisibilityEvent(AbilitySlice slice, Component rootComponent) { + keyboardVisibilityEvent = new KeyboardVisibilityEvent(); + keyboardVisibilityEvent.setAbilitySliceRoot(rootComponent); + keyboardVisibilityEvent.registerEventListener(slice, new KeyboardVisibilityEventListener() { + @Override + public void onVisibilityChanged(boolean b) { + if (!b) { + editLazyDatePickerReal.clearFocus(); + } + } + }); - public LazyDatePicker(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - init(context, attrs, defStyleAttr); + Window window = slice.getWindow(); + window.setInputPanelDisplayType(WindowManager.LayoutConfig.INPUT_ADJUST_PAN); } - protected void init(Context context, AttributeSet attrs, int defStyleAttr) { - inflate(context, R.layout.layout_lazy_date_picker, this); + private void init(Context context, AttrSet attrs) { + contentComponent = LayoutScatter.getInstance(context) + .parse(ResourceTable.Layout_layout_lazy_date_picker, null, false); + addComponent(contentComponent); + textColor = attrs.getAttr("ldp_text_color").get().getColorValue(); + hintColor = attrs.getAttr("ldp_hint_color").get().getColorValue(); + showFullDate = attrs.getAttr("ldp_show_full_date").get().getBoolValue(); + int dateFormatValue = attrs.getAttr("ldp_date_format").get().getIntegerValue(); - // Load the styled attributes and set their properties - TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.LazyDatePicker, - defStyleAttr, 0); - textColor = attributes.getColor(R.styleable.LazyDatePicker_ldp_text_color, Color.BLACK); - hintColor = attributes.getColor(R.styleable.LazyDatePicker_ldp_hint_color, Color.GRAY); - showFullDate = attributes.getBoolean(R.styleable.LazyDatePicker_ldp_show_full_date, true); - - int dateFormatValue = attributes.getInteger(R.styleable.LazyDatePicker_ldp_date_format, - DateFormat.MM_DD_YYYY.getAttrValue()); dateFormat = DateFormat.fromValue(dateFormatValue); - - attributes.recycle(); - } - //endregion - - @Override - protected void onFinishInflate() { - super.onFinishInflate(); + transparentElement.setRgbColor(new RgbColor(0,0,0,0)); + textColorElement.setRgbColor(new RgbColor(0,0,0)); + hintColorElement.setRgbColor(new RgbColor(164, 164, 164)); initView(); + onAttachedToWindow(); } - @Override - protected void onAttachedToWindow() { - super.onAttachedToWindow(); - if (!isInEditMode()) { - - if (showFullDate) { - addKeyboardVisibilityListener(this, new OnKeyboardVisibilityListener() { - @Override - public void onVisibilityChange(boolean isVisible) { - if (keyboardVisible != isVisible) { - keyboardVisible = isVisible; - if (!keyboardVisible && editLazyDatePickerReal.isFocused()) { - editLazyDatePickerReal.clearFocus(); - } - } - } - }); - } - - editLazyDatePickerReal.setOnFocusChangeListener(new OnFocusChangeListener() { + private void onAttachedToWindow() { + if (showFullDate) { + addKeyboardVisibilityListener(this, new OnKeyboardVisibilityListener() { @Override - public void onFocusChange(View v, boolean hasFocus) { - showDate(date, hasFocus); - if (showFullDate) { - showFullDateLayout(hasFocus); + public void onVisibilityChange(boolean isVisible) { + if (keyboardVisible != isVisible) { + keyboardVisible = isVisible; + if (!keyboardVisible && editLazyDatePickerReal.isFocused()) { + editLazyDatePickerReal.clearFocus(); + } } } }); - - initTextWatcher(); } + + editLazyDatePickerReal.setFocusChangedListener(new FocusChangedListener() { + @Override + public void onFocusChange(Component component, boolean b) { + showDate(date, b); + if (showFullDate) { + showFullDateLayout(b); + } + } + }); + + initTextWatcher(); } - //region PRIVATE METHOD + // region PRIVATE METHOD private void initView() { date = ""; + editLazyDatePickerReal = (TextField) contentComponent + .findComponentById(ResourceTable.Id_edit_lazy_date_picker_real); + layoutLazyDatePicker = (DirectionalLayout) contentComponent + .findComponentById(ResourceTable.Id_layout_lazy_date_picker); + layoutLazyDatePicker = (DirectionalLayout) contentComponent + .findComponentById(ResourceTable.Id_layout_lazy_date_picker); + textLazyDatePickerDate = (Text) contentComponent + .findComponentById(ResourceTable.Id_text_lazy_date_picker_date); + + initialize(); + + if (dateFormat == DateFormat.MM_DD_YYYY) { + textLazyDate1.setText(getContext().getString(ResourceTable.String_ldp_month)); + textLazyDate2.setText(getContext().getString(ResourceTable.String_ldp_month)); + textLazyDate3.setText(getContext().getString(ResourceTable.String_ldp_day)); + textLazyDate4.setText(getContext().getString(ResourceTable.String_ldp_day)); + } else if (dateFormat == DateFormat.DD_MM_YYYY) { + textLazyDate1.setText(getContext().getString(ResourceTable.String_ldp_day)); + textLazyDate2.setText(getContext().getString(ResourceTable.String_ldp_day)); + textLazyDate3.setText(getContext().getString(ResourceTable.String_ldp_month)); + textLazyDate4.setText(getContext().getString(ResourceTable.String_ldp_month)); + } + + textLazyDate5.setText(getContext().getString(ResourceTable.String_ldp_year)); + textLazyDate6.setText(getContext().getString(ResourceTable.String_ldp_year)); + textLazyDate7.setText(getContext().getString(ResourceTable.String_ldp_year)); + textLazyDate8.setText(getContext().getString(ResourceTable.String_ldp_year)); + + textLazyDatePickerDate.setTextColor(textColor); + + contentComponent.findComponentById(ResourceTable.Id_btn_lazy_date_picker_on_focus) + .setClickedListener(new ClickedListener() { + @Override + public void onClick(Component component) { + showKeyboard(editLazyDatePickerReal); + } + }); + } - editLazyDatePickerReal = findViewById(R.id.edit_lazy_date_picker_real); - layoutLazyDatePicker = findViewById(R.id.layout_lazy_date_picker); - textLazyDatePickerDate = findViewById(R.id.text_lazy_date_picker_date); - - textLazyDate1 = findViewById(R.id.text_lazy_date_1); - viewLazyDate1 = findViewById(R.id.view_lazy_date_1); - textLazyDate2 = findViewById(R.id.text_lazy_date_2); - viewLazyDate2 = findViewById(R.id.view_lazy_date_2); - textLazyDate3 = findViewById(R.id.text_lazy_date_3); - viewLazyDate3 = findViewById(R.id.view_lazy_date_3); - textLazyDate4 = findViewById(R.id.text_lazy_date_4); - viewLazyDate4 = findViewById(R.id.view_lazy_date_4); - textLazyDate5 = findViewById(R.id.text_lazy_date_5); - viewLazyDate5 = findViewById(R.id.view_lazy_date_5); - textLazyDate6 = findViewById(R.id.text_lazy_date_6); - viewLazyDate6 = findViewById(R.id.view_lazy_date_6); - textLazyDate7 = findViewById(R.id.text_lazy_date_7); - viewLazyDate7 = findViewById(R.id.view_lazy_date_7); - textLazyDate8 = findViewById(R.id.text_lazy_date_8); - viewLazyDate8 = findViewById(R.id.view_lazy_date_8); + private void initialize() { + textLazyDate1 = (Text) contentComponent.findComponentById(ResourceTable.Id_text_lazy_date_1); + viewLazyDate1 = contentComponent.findComponentById(ResourceTable.Id_view_lazy_date_1); + textLazyDate2 = (Text) contentComponent.findComponentById(ResourceTable.Id_text_lazy_date_2); + viewLazyDate2 = contentComponent.findComponentById(ResourceTable.Id_view_lazy_date_2); + textLazyDate3 = (Text) contentComponent.findComponentById(ResourceTable.Id_text_lazy_date_3); + viewLazyDate3 = contentComponent.findComponentById(ResourceTable.Id_view_lazy_date_3); + textLazyDate4 = (Text) contentComponent.findComponentById(ResourceTable.Id_text_lazy_date_4); + viewLazyDate4 = contentComponent.findComponentById(ResourceTable.Id_view_lazy_date_4); + textLazyDate5 = (Text) contentComponent.findComponentById(ResourceTable.Id_text_lazy_date_5); + viewLazyDate5 = contentComponent.findComponentById(ResourceTable.Id_view_lazy_date_5); + textLazyDate6 = (Text) contentComponent.findComponentById(ResourceTable.Id_text_lazy_date_6); + viewLazyDate6 = contentComponent.findComponentById(ResourceTable.Id_view_lazy_date_6); + textLazyDate7 = (Text) contentComponent.findComponentById(ResourceTable.Id_text_lazy_date_7); + viewLazyDate7 = contentComponent.findComponentById(ResourceTable.Id_view_lazy_date_7); + textLazyDate8 = (Text) contentComponent.findComponentById(ResourceTable.Id_text_lazy_date_8); + viewLazyDate8 = contentComponent.findComponentById(ResourceTable.Id_view_lazy_date_8); textLazyDate1.setTextColor(hintColor); - viewLazyDate1.setBackgroundColor(hintColor); - viewLazyDate1.setVisibility(View.GONE); + viewLazyDate1.setBackground(hintColorElement); + viewLazyDate1.setVisibility(Component.HIDE); textLazyDate2.setTextColor(hintColor); - viewLazyDate2.setBackgroundColor(hintColor); - viewLazyDate2.setVisibility(View.GONE); + viewLazyDate2.setBackground(hintColorElement); + viewLazyDate2.setVisibility(Component.HIDE); textLazyDate3.setTextColor(hintColor); - viewLazyDate3.setBackgroundColor(hintColor); - viewLazyDate3.setVisibility(View.GONE); + viewLazyDate3.setBackground(hintColorElement); + viewLazyDate3.setVisibility(Component.HIDE); textLazyDate4.setTextColor(hintColor); - viewLazyDate4.setBackgroundColor(hintColor); - viewLazyDate4.setVisibility(View.GONE); + viewLazyDate4.setBackground(hintColorElement); + viewLazyDate4.setVisibility(Component.HIDE); textLazyDate5.setTextColor(hintColor); - viewLazyDate5.setBackgroundColor(hintColor); - viewLazyDate5.setVisibility(View.GONE); + viewLazyDate5.setBackground(hintColorElement); + viewLazyDate5.setVisibility(Component.HIDE); textLazyDate6.setTextColor(hintColor); - viewLazyDate6.setBackgroundColor(hintColor); - viewLazyDate6.setVisibility(View.GONE); + viewLazyDate6.setBackground(hintColorElement); + viewLazyDate6.setVisibility(Component.HIDE); textLazyDate7.setTextColor(hintColor); - viewLazyDate7.setBackgroundColor(hintColor); - viewLazyDate7.setVisibility(View.GONE); + viewLazyDate7.setBackground(hintColorElement); + viewLazyDate7.setVisibility(Component.HIDE); textLazyDate8.setTextColor(hintColor); - viewLazyDate8.setBackgroundColor(hintColor); - viewLazyDate8.setVisibility(View.GONE); - - if (dateFormat == DateFormat.MM_DD_YYYY) { - textLazyDate1.setText(getContext().getString(R.string.ldp_month)); - textLazyDate2.setText(getContext().getString(R.string.ldp_month)); - textLazyDate3.setText(getContext().getString(R.string.ldp_day)); - textLazyDate4.setText(getContext().getString(R.string.ldp_day)); - } else if (dateFormat == DateFormat.DD_MM_YYYY) { - textLazyDate1.setText(getContext().getString(R.string.ldp_day)); - textLazyDate2.setText(getContext().getString(R.string.ldp_day)); - textLazyDate3.setText(getContext().getString(R.string.ldp_month)); - textLazyDate4.setText(getContext().getString(R.string.ldp_month)); - } - - textLazyDate5.setText(getContext().getString(R.string.ldp_year)); - textLazyDate6.setText(getContext().getString(R.string.ldp_year)); - textLazyDate7.setText(getContext().getString(R.string.ldp_year)); - textLazyDate8.setText(getContext().getString(R.string.ldp_year)); - - textLazyDatePickerDate.setTextColor(textColor); - - findViewById(R.id.btn_lazy_date_picker_on_focus).setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - showKeyboard(editLazyDatePickerReal, getContext()); - } - }); + viewLazyDate8.setBackground(hintColorElement); + viewLazyDate8.setVisibility(Component.HIDE); } private void showFullDateLayout(boolean hasFocus) { if (!hasFocus && date.length() == LENGTH_DATE_COMPLETE) { - layoutLazyDatePicker.setVisibility(View.INVISIBLE); - textLazyDatePickerDate.setVisibility(View.VISIBLE); + layoutLazyDatePicker.setVisibility(Component.INVISIBLE); + textLazyDatePickerDate.setVisibility(Component.VISIBLE); textLazyDatePickerDate.setText(dateToString(getDate(), dateFormat.getCompleteFormatValue())); - - } else if (layoutLazyDatePicker.getVisibility() == View.INVISIBLE) { - layoutLazyDatePicker.setVisibility(View.VISIBLE); - textLazyDatePickerDate.setVisibility(View.GONE); + } else if (layoutLazyDatePicker.getVisibility() == Component.INVISIBLE) { + layoutLazyDatePicker.setVisibility(Component.VISIBLE); + textLazyDatePickerDate.setVisibility(Component.HIDE); } } - private boolean charIsValid(String date, char unicodeChar) { + private boolean charIsValid(String mDate, char unicodeChar) { // Check if char is a digit if (!Character.isDigit(unicodeChar)) { return false; } - int length = date.length(); + int length = mDate.length(); // Check Month & Day by dateFormat selected int value = Character.getNumericValue(unicodeChar); if (dateFormat == DateFormat.MM_DD_YYYY) { - if (length == 0 && value > 1) { // M1 - return false; - } else if (length == 1 && ((Character.getNumericValue(date.charAt(0)) == 1 && value > 2) - || (Character.getNumericValue(date.charAt(0)) == 0 && value == 0))) { // M2 - return false; - } else if (length == 2 && value > 3) { // D1 - return false; - } else if (length == 3 && ((Character.getNumericValue(date.charAt(2)) == 3 && value > 1) - || (Character.getNumericValue(date.charAt(2)) == 0 && value == 0))) { // D2 - return false; - } - + if (month(mDate, length, value, 1, 2, 3, 1)) return false; } else if (dateFormat == DateFormat.DD_MM_YYYY) { - if (length == 0 && value > 3) { // D1 - return false; - } else if (length == 1 && ((Character.getNumericValue(date.charAt(0)) == 3 && value > 1) - || (Character.getNumericValue(date.charAt(0)) == 0 && value == 0))) { // D2 - return false; - } else if (length == 2 && value > 1) { // M1 - return false; - } else if (length == 3 && ((Character.getNumericValue(date.charAt(2)) == 1 && value > 2) - || (Character.getNumericValue(date.charAt(2)) == 0 && value == 0))) { // M2 - return false; - } + if (month(mDate, length, value, 3, 1, 1, 2)) return false; } // Check if date is between min & max date if (length > 3 && minDateIsNotNull()) { - StringBuilder dateToCheckTmp = new StringBuilder(date + unicodeChar); + StringBuilder dateToCheckTmp = new StringBuilder(mDate + unicodeChar); while (dateToCheckTmp.length() < LENGTH_DATE_COMPLETE) { dateToCheckTmp.append("9"); } - if (checkMinDate(dateToCheckTmp)) return false; + if (checkMinDate(dateToCheckTmp)) { + return false; + } } if (length > 3 && maxDateIsNotNull()) { - StringBuilder dateToCheckTmp = new StringBuilder(date + unicodeChar); + StringBuilder dateToCheckTmp = new StringBuilder(mDate + unicodeChar); while (dateToCheckTmp.length() < LENGTH_DATE_COMPLETE) { dateToCheckTmp.append("0"); } - if (checkMaxDate(dateToCheckTmp)) return false; + if (checkMaxDate(dateToCheckTmp)) { + return false; + } } if (length > 6) { - StringBuilder dateToCheckTmp = new StringBuilder(date + unicodeChar); + StringBuilder dateToCheckTmp = new StringBuilder(mDate + unicodeChar); while (dateToCheckTmp.length() < LENGTH_DATE_COMPLETE) { dateToCheckTmp.append("9"); } @@ -290,178 +318,218 @@ public class LazyDatePicker extends RelativeLayout { return true; } + private boolean month(String mDate, int length, int value, int i, int i2, int i3, int i4) { + if (length == 0 && value > i) { // M1 + return true; + } else if (length == 1 && ((Character.getNumericValue(mDate.charAt(0)) == i && value > i2) + || (Character.getNumericValue(mDate.charAt(0)) == 0 && value == 0))) { // M2 + return true; + } else if (length == 2 && value > i3) { // D1 + return true; + } else if (length == 3 && ((Character.getNumericValue(mDate.charAt(2)) == i3 && value > i4) + || (Character.getNumericValue(mDate.charAt(2)) == 0 && value == 0))) { // D2 + return true; + } + return false; + } + private void showDate(String value, boolean hasFocus) { manageViewFocus(hasFocus, value.length()); switch (value.length()) { case 0: textLazyDate1.setText(getContext().getString(dateFormat == DateFormat.MM_DD_YYYY - ? R.string.ldp_month : R.string.ldp_day)); + ? ResourceTable.String_ldp_month : ResourceTable.String_ldp_day)); textLazyDate1.setTextColor(hintColor); break; case 1: - textLazyDate1.setTextColor(textColor); - textLazyDate1.setText(getLetterAt(0, value)); - textLazyDate2.setText(getContext().getString(dateFormat == DateFormat.MM_DD_YYYY - ? R.string.ldp_month : R.string.ldp_day)); - textLazyDate2.setTextColor(hintColor); + setProperty(value, textLazyDate1, 0, textLazyDate2, dateFormat == DateFormat.MM_DD_YYYY + ? ResourceTable.String_ldp_month : ResourceTable.String_ldp_day); break; case 2: - textLazyDate2.setTextColor(textColor); - textLazyDate2.setText(getLetterAt(1, value)); - textLazyDate3.setText(getContext().getString(dateFormat == DateFormat.MM_DD_YYYY - ? R.string.ldp_day : R.string.ldp_month)); - textLazyDate3.setTextColor(hintColor); + setProperty(value, textLazyDate2, 1, textLazyDate3, dateFormat == DateFormat.MM_DD_YYYY + ? ResourceTable.String_ldp_day : ResourceTable.String_ldp_month); break; case 3: - textLazyDate3.setTextColor(textColor); - textLazyDate3.setText(getLetterAt(2, value)); - textLazyDate4.setText(getContext().getString(dateFormat == DateFormat.MM_DD_YYYY - ? R.string.ldp_day : R.string.ldp_month)); - textLazyDate4.setTextColor(hintColor); + setProperty(value, textLazyDate3, 2, textLazyDate4, dateFormat == DateFormat.MM_DD_YYYY + ? ResourceTable.String_ldp_day : ResourceTable.String_ldp_month); break; case 4: - textLazyDate4.setTextColor(textColor); - textLazyDate4.setText(getLetterAt(3, value)); - textLazyDate5.setText(getContext().getString(R.string.ldp_year)); - textLazyDate5.setTextColor(hintColor); + setProperty(value, textLazyDate4, 3, textLazyDate5, ResourceTable.String_ldp_year); break; case 5: - textLazyDate5.setTextColor(textColor); - textLazyDate5.setText(getLetterAt(4, value)); - textLazyDate6.setText(getContext().getString(R.string.ldp_year)); - textLazyDate6.setTextColor(hintColor); + setProperty(value, textLazyDate5, 4, textLazyDate6, ResourceTable.String_ldp_year); break; case 6: - textLazyDate6.setTextColor(textColor); - textLazyDate6.setText(getLetterAt(5, value)); - textLazyDate7.setText(getContext().getString(R.string.ldp_year)); - textLazyDate7.setTextColor(hintColor); + setProperty(value, textLazyDate6, 5, textLazyDate7, ResourceTable.String_ldp_year); break; case 7: - textLazyDate7.setTextColor(textColor); - textLazyDate7.setText(getLetterAt(6, value)); - textLazyDate8.setText(getContext().getString(R.string.ldp_year)); - textLazyDate8.setTextColor(hintColor); + setProperty(value, textLazyDate7, 6, textLazyDate8, ResourceTable.String_ldp_year); break; case 8: textLazyDate8.setTextColor(textColor); textLazyDate8.setText(getLetterAt(7, value)); break; + default: + break; } } + private void setProperty(String value, Text textLazyDate, int i, Text mtextLazyDate, int p) { + textLazyDate.setTextColor(textColor); + textLazyDate.setText(getLetterAt(i, value)); + mtextLazyDate.setText(getContext().getString(p)); + mtextLazyDate.setTextColor(hintColor); + } + private void manageViewFocus(boolean hasFocus, int valueLength) { if (hasFocus) { - viewLazyDate1.setVisibility(View.VISIBLE); - viewLazyDate2.setVisibility(View.VISIBLE); - viewLazyDate3.setVisibility(View.VISIBLE); - viewLazyDate4.setVisibility(View.VISIBLE); - viewLazyDate5.setVisibility(View.VISIBLE); - viewLazyDate6.setVisibility(View.VISIBLE); - viewLazyDate7.setVisibility(View.VISIBLE); - viewLazyDate8.setVisibility(View.VISIBLE); + viewLazyDate1.setVisibility(Component.VISIBLE); + viewLazyDate2.setVisibility(Component.VISIBLE); + viewLazyDate3.setVisibility(Component.VISIBLE); + viewLazyDate4.setVisibility(Component.VISIBLE); + viewLazyDate5.setVisibility(Component.VISIBLE); + viewLazyDate6.setVisibility(Component.VISIBLE); + viewLazyDate7.setVisibility(Component.VISIBLE); + viewLazyDate8.setVisibility(Component.VISIBLE); switch (valueLength) { case 0: - viewLazyDate1.setVisibility(View.VISIBLE); - viewLazyDate1.setBackgroundColor(textColor); - viewLazyDate2.setBackgroundColor(hintColor); + viewLazyDate1.setVisibility(Component.VISIBLE); + viewLazyDate1.setBackground(textColorElement); + viewLazyDate2.setBackground(hintColorElement); break; case 1: - viewLazyDate1.setBackgroundColor(Color.TRANSPARENT); - viewLazyDate2.setVisibility(View.VISIBLE); - viewLazyDate2.setBackgroundColor(textColor); - viewLazyDate3.setBackgroundColor(hintColor); + viewLazyDate1.setBackground(transparentElement); + viewLazyDate2.setVisibility(Component.VISIBLE); + viewLazyDate2.setBackground(textColorElement); + viewLazyDate3.setBackground(hintColorElement); break; case 2: - viewLazyDate2.setBackgroundColor(Color.TRANSPARENT); - viewLazyDate3.setVisibility(View.VISIBLE); - viewLazyDate3.setBackgroundColor(textColor); - viewLazyDate4.setBackgroundColor(hintColor); + viewLazyDate2.setBackground(transparentElement); + viewLazyDate3.setVisibility(Component.VISIBLE); + viewLazyDate3.setBackground(textColorElement); + viewLazyDate4.setBackground(hintColorElement); break; case 3: - viewLazyDate3.setBackgroundColor(Color.TRANSPARENT); - viewLazyDate4.setVisibility(View.VISIBLE); - viewLazyDate4.setBackgroundColor(textColor); - viewLazyDate5.setBackgroundColor(hintColor); + viewLazyDate3.setBackground(transparentElement); + viewLazyDate4.setVisibility(Component.VISIBLE); + viewLazyDate4.setBackground(textColorElement); + viewLazyDate5.setBackground(hintColorElement); break; case 4: - viewLazyDate4.setBackgroundColor(Color.TRANSPARENT); - viewLazyDate5.setVisibility(View.VISIBLE); - viewLazyDate5.setBackgroundColor(textColor); - viewLazyDate6.setBackgroundColor(hintColor); + viewLazyDate4.setBackground(transparentElement); + viewLazyDate5.setVisibility(Component.VISIBLE); + viewLazyDate5.setBackground(textColorElement); + viewLazyDate6.setBackground(hintColorElement); break; case 5: - viewLazyDate5.setBackgroundColor(Color.TRANSPARENT); - viewLazyDate6.setVisibility(View.VISIBLE); - viewLazyDate6.setBackgroundColor(textColor); - viewLazyDate7.setBackgroundColor(hintColor); + viewLazyDate5.setBackground(transparentElement); + viewLazyDate6.setVisibility(Component.VISIBLE); + viewLazyDate6.setBackground(textColorElement); + viewLazyDate7.setBackground(hintColorElement); break; case 6: - viewLazyDate6.setBackgroundColor(Color.TRANSPARENT); - viewLazyDate7.setVisibility(View.VISIBLE); - viewLazyDate7.setBackgroundColor(textColor); - viewLazyDate8.setBackgroundColor(hintColor); + viewLazyDate6.setBackground(transparentElement); + viewLazyDate7.setVisibility(Component.VISIBLE); + viewLazyDate7.setBackground(textColorElement); + viewLazyDate8.setBackground(hintColorElement); break; case 7: - viewLazyDate7.setBackgroundColor(Color.TRANSPARENT); - viewLazyDate8.setVisibility(View.VISIBLE); - viewLazyDate8.setBackgroundColor(textColor); + viewLazyDate7.setBackground(transparentElement); + viewLazyDate8.setVisibility(Component.VISIBLE); + viewLazyDate8.setBackground(textColorElement); break; case 8: - viewLazyDate8.setBackgroundColor(Color.TRANSPARENT); + viewLazyDate8.setBackground(transparentElement); + break; + default: break; } } else { - viewLazyDate1.setVisibility(View.GONE); - viewLazyDate2.setVisibility(View.GONE); - viewLazyDate3.setVisibility(View.GONE); - viewLazyDate4.setVisibility(View.GONE); - viewLazyDate5.setVisibility(View.GONE); - viewLazyDate6.setVisibility(View.GONE); - viewLazyDate7.setVisibility(View.GONE); - viewLazyDate8.setVisibility(View.GONE); + viewLazyDate1.setVisibility(Component.HIDE); + viewLazyDate2.setVisibility(Component.HIDE); + viewLazyDate3.setVisibility(Component.HIDE); + viewLazyDate4.setVisibility(Component.HIDE); + viewLazyDate5.setVisibility(Component.HIDE); + viewLazyDate6.setVisibility(Component.HIDE); + viewLazyDate7.setVisibility(Component.HIDE); + viewLazyDate8.setVisibility(Component.HIDE); } } - //endregion - //region PROTECTED METHOD + /** + * region PROTECTED METHOD + */ protected void onDatePick() { if (onDatePickListener != null) { onDatePickListener.onDatePick(getDate()); } } + /** + * 日期选中回调 + */ protected void onDateSelected() { if (onDateSelectedListener != null) { onDateSelectedListener.onDateSelected(getDate() != null); } } + /** + * 检测最小日期是否为空 + * + * @return true/false + */ protected boolean minDateIsNotNull() { return minDate != null; } + /** + * 检测最大日期是否为空 + * + * @return true/false + */ protected boolean maxDateIsNotNull() { return maxDate != null; } + /** + * 检测最小日期是否有效 + * + * @param dateToCheckTmp + * @return true/false + */ protected boolean checkMinDate(StringBuilder dateToCheckTmp) { Date realDateToCheckTmp = stringToDate(dateToCheckTmp.toString(), dateFormat.getValue()); return realDateToCheckTmp == null || realDateToCheckTmp.before(minDate); } + /** + * 检测最大日期是否有效 + * + * @param dateToCheckTmp + * @return true/false + */ protected boolean checkMaxDate(StringBuilder dateToCheckTmp) { Date realDateToCheckTmp = stringToDate(dateToCheckTmp.toString(), dateFormat.getValue()); return realDateToCheckTmp == null || realDateToCheckTmp.after(maxDate); } + /** + * 检测当前日期格式是否正确 + * + * @param dateToCheckTmp 日期格式 + * @return true/false + */ protected boolean checkSameDate(StringBuilder dateToCheckTmp) { Date realDateToCheckTmp = stringToDate(dateToCheckTmp.toString(), dateFormat.getValue()); return dateToString(realDateToCheckTmp, dateFormat.getValue()).equals(dateToCheckTmp.toString()); } + /** + * 输入时动态改变颜色 + */ protected void fillDate() { detachTextWatcher(); editLazyDatePickerReal.setText(date); @@ -484,22 +552,25 @@ public class LazyDatePicker extends RelativeLayout { textLazyDate8.setTextColor(textColor); textLazyDate8.setText(getLetterAt(7, date)); - viewLazyDate1.setBackgroundColor(Color.TRANSPARENT); - viewLazyDate2.setBackgroundColor(Color.TRANSPARENT); - viewLazyDate3.setBackgroundColor(Color.TRANSPARENT); - viewLazyDate4.setBackgroundColor(Color.TRANSPARENT); - viewLazyDate5.setBackgroundColor(Color.TRANSPARENT); - viewLazyDate6.setBackgroundColor(Color.TRANSPARENT); - viewLazyDate7.setBackgroundColor(Color.TRANSPARENT); - viewLazyDate8.setBackgroundColor(Color.TRANSPARENT); + viewLazyDate1.setBackground(transparentElement); + viewLazyDate2.setBackground(transparentElement); + viewLazyDate3.setBackground(transparentElement); + viewLazyDate4.setBackground(transparentElement); + viewLazyDate5.setBackground(transparentElement); + viewLazyDate6.setBackground(transparentElement); + viewLazyDate7.setBackground(transparentElement); + viewLazyDate8.setBackground(transparentElement); if (showFullDate) { showFullDateLayout(editLazyDatePickerReal.isFocused()); } } - //endregion - //region PUBLIC METHOD + /** + * region PUBLIC METHOD + * + * @return 返回日期格式 + */ public Date getDate() { if (date.length() == LENGTH_DATE_COMPLETE) { return stringToDate(date, dateFormat.getValue()); @@ -507,6 +578,12 @@ public class LazyDatePicker extends RelativeLayout { return null; } + /** + * 设置日期格式 + * + * @param newDate + * @return true/false + */ public boolean setDate(Date newDate) { String tmpDate = dateToString(newDate, dateFormat.getValue()); @@ -523,25 +600,46 @@ public class LazyDatePicker extends RelativeLayout { return true; } + /** + * 设置最小日期 + * + * @param minDate 最小日期格式 + */ public void setMinDate(Date minDate) { - this.minDate = minDate; + this.minDate = (Date) minDate.clone(); clear(); } + /** + * 设置最大日期 + * + * @param maxDate 最大日期格式 + */ public void setMaxDate(Date maxDate) { - this.maxDate = maxDate; + this.maxDate = (Date) maxDate.clone(); clear(); } + /** + * 设置日期格式 + * + * @param dateFormat 日期格式 + */ public void setDateFormat(DateFormat dateFormat) { this.dateFormat = dateFormat; clear(); } + /** + * 清除 + */ public void clear() { initView(); } + /** + * 输入错误的动画效果 + */ public void shake() { shakeView(layoutLazyDatePicker); } @@ -553,174 +651,289 @@ public class LazyDatePicker extends RelativeLayout { public void setOnDateSelectedListener(OnDateSelectedListener onDateSelectedListener) { this.onDateSelectedListener = onDateSelectedListener; } - //endregion - //region TEXT WATCHER + // region TEXT WATCHER private void detachTextWatcher() { - editLazyDatePickerReal.removeTextChangedListener(textWatcher); + editLazyDatePickerReal.removeTextObserver(textWatcher); textWatcher = null; } private void initTextWatcher() { if (textWatcher == null) { - textWatcher = new TextWatcher() { + textWatcher = new Text.TextObserver() { @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { - } - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { + public void onTextUpdated(String s, int start, int before, int count) { if (!shakeAnimationDoing) { - if (before > 0) { + if (cacheString.length() > s.length()) { + // 删除 // Remove last char if (date.length() > 0) { date = date.substring(0, date.length() - 1); } - } else if (date.length() < LENGTH_DATE_COMPLETE && s.length() > 0 && charIsValid(date, s.charAt(s.length() - 1))) { + } else if (date.length() < LENGTH_DATE_COMPLETE && s.length() > 0 + && charIsValid(date, s.charAt(s.length() - 1))) { + // 增加 char unicodeChar = s.charAt(s.length() - 1); date += unicodeChar; if (date.length() == LENGTH_DATE_COMPLETE) { onDatePick(); } } else { + if (s.length() > 1) { + editLazyDatePickerReal.setText(s); + } shakeView(layoutLazyDatePicker); } - + cacheString = s; showDate(date, true); onDateSelected(); } } - - @Override - public void afterTextChanged(Editable s) { - } }; - editLazyDatePickerReal.addTextChangedListener(textWatcher); + editLazyDatePickerReal.addTextObserver(textWatcher); } } - //endregion - //region KEYBOARD - private void addKeyboardVisibilityListener(final View rootLayout, + private void addKeyboardVisibilityListener(final Component rootLayout, final OnKeyboardVisibilityListener onKeyboardVisibilityListener) { - rootLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { - @Override - public void onGlobalLayout() { - Rect r = new Rect(); - rootLayout.getWindowVisibleDisplayFrame(r); - int screenHeight = rootLayout.getRootView().getHeight(); - - // r.bottom is the position above soft keypad or device button. - // if keypad is shown, the r.bottom is smaller than that before. - int keypadHeight = screenHeight - r.bottom; - - boolean isVisible = keypadHeight > screenHeight * 0.15; // 0.15 ratio is perhaps - // enough to determine keypad height. - onKeyboardVisibilityListener.onVisibilityChange(isVisible); - } - }); + Rect r = new Rect(); + rootLayout.getWindowVisibleRect(r); + int screenHeight = DisplayManager.getInstance().getDefaultDisplay(getContext()).get().getAttributes().height; + + // r.bottom is the position above soft keypad or device button. + // if keypad is shown, the r.bottom is smaller than that before. + int keypadHeight = screenHeight - r.bottom; + + boolean isVisible = keypadHeight > screenHeight * 0.15; // 0.15 ratio is perhaps + // enough to determine keypad height. + onKeyboardVisibilityListener.onVisibilityChange(isVisible); } + /** + * 添加关键按键监听 + * + * @since 2021-06-28 + */ private interface OnKeyboardVisibilityListener { void onVisibilityChange(boolean isVisible); } - private void showKeyboard(EditText editText, Context context) { + private void showKeyboard(TextField editText) { editText.requestFocus(); - editText.setSelection(editText.length()); - InputMethodManager inputMethodManager = - (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); - if (inputMethodManager != null) - inputMethodManager.showSoftInput(editText, InputMethodManager.SHOW_FORCED); + showSoftInput(); + } + + /** + * 显示软键盘 + * + * @return true/false + */ + public static boolean showSoftInput() { + try { + Class inputClass = Class.forName("ohos.miscservices.inputmethod.InputMethodController"); + Method method = inputClass.getMethod("getInstance"); + Object object = method.invoke(new Object[]{}); + Method startInput = inputClass.getMethod("startInput",int.class,boolean.class); + return (boolean)startInput.invoke(object,1,true); + } catch (InvocationTargetException e) { + e.getMessage(); + } catch (NoSuchMethodException e) { + e.getMessage(); + } catch (IllegalAccessException e) { + e.getMessage(); + } catch (ClassNotFoundException e) { + e.getMessage(); + } + return false; } - //endregion - //region UTILS + // region UTILS private String getLetterAt(int position, String value) { return String.valueOf(value.charAt(position)); } - private void shakeView(View view) { + private void shakeView(Component view) { shakeAnimationDoing = true; - view.animate() - .translationX(-15).translationX(15) + animatorProperty = view.createAnimatorProperty() + .moveFromX(-15).moveToX(15) .setDuration(30) - .setInterpolator(new CycleInterpolator(5)) // 150 / 30 + .setCurveType(Animator.CurveType.CYCLE) + .setLoopedCount(3) .setDuration(150) - .withEndAction(new Runnable() { + .setStateChangedListener(new Animator.StateChangedListener() { + @Override + public void onStart(Animator animator) { + } + + @Override + public void onStop(Animator animator) { + } + + @Override + public void onCancel(Animator animator) { + } + @Override - public void run() { + public void onEnd(Animator animator) { shakeAnimationDoing = false; + animatorProperty.reset(); + } + + @Override + public void onPause(Animator animator) { + } + + @Override + public void onResume(Animator animator) { } - }) - .start(); + }); + animatorProperty.start(); } + /** + * 日期格式转字符串 + * + * @param date 日期 + * @param pattern 字符串 + * @return 字符串 + */ public static String dateToString(Date date, String pattern) { return new SimpleDateFormat(pattern, Locale.getDefault()).format(date); } + /** + * 字符串转日期格式 + * + * @param date 需要转换的日期格式 + * @param format 需要转换的字符串 + * @return 转换完成的字符串 + */ public static Date stringToDate(String date, String format) { try { return new SimpleDateFormat(format, Locale.getDefault()).parse(date); } catch (ParseException e) { - e.printStackTrace(); + e.getMessage(); } - return null; + return new Date(); } - //endregion + /** + * 输入完毕回调接口 + * + * @since 2021-06-28 + */ public interface OnDatePickListener { + /** + * 输入完毕回调接口 + * + * @param dateSelected + */ void onDatePick(Date dateSelected); } + /** + * 输入完毕回调接口 + * + * @since 2021-06-28 + */ public interface OnDateSelectedListener { + /** + * 输入完毕回调接口 + * + * @param dateSelected true/false + */ void onDateSelected(Boolean dateSelected); } + /** + * 日期枚举 + * + * @since 2021-06-28 + */ public enum DateFormat { + /** + * 日期格式 + */ MM_DD_YYYY, + /** + * 日期格式 + */ DD_MM_YYYY; + /** + * 获取日期格式 + * + * @return String + */ public String getValue() { switch (this) { case MM_DD_YYYY: return "MMddyyyy"; case DD_MM_YYYY: return "ddMMyyyy"; + default: + break; } throw new IllegalArgumentException("Not value available for this DateFormat: " + this); } + /** + * 获取字符串 + * + * @return String + */ public String getCompleteFormatValue() { switch (this) { case MM_DD_YYYY: return "MMM dd yyyy"; case DD_MM_YYYY: return "dd MMM yyyy"; + default: + break; } throw new IllegalArgumentException("Not value available for this DateFormat: " + this); } + /** + * 通过枚举获取日期格式 + * + * @return 枚举类 + */ public int getAttrValue() { switch (this) { case MM_DD_YYYY: return 1; case DD_MM_YYYY: return 2; + default: + break; } throw new IllegalArgumentException("Not value available for this DateFormat: " + this); } + /** + * 返回日期格式 + * + * @param value + * @return DateFormat + */ public static DateFormat fromValue(int value) { switch (value) { case 1: return MM_DD_YYYY; case 2: return DD_MM_YYYY; + default: + break; } throw new IllegalArgumentException("This value is not supported for DateFormat: " + value); } } + /** + * 清除焦点 + */ + public void clearFocus() { + editLazyDatePickerReal.clearFocus(); + } } diff --git a/lazydatepicker/src/main/java/com/mikhaellopez/lazydatepicker/LazyLocalDatePicker.java b/lazydatepicker/src/main/java/com/mikhaellopez/lazydatepicker/LazyLocalDatePicker.java index 378cb4b8abc121968218fe000725871dac124ded..c5d9d62f1e023d761d1bb685c8c65eb7f50ab67c 100644 --- a/lazydatepicker/src/main/java/com/mikhaellopez/lazydatepicker/LazyLocalDatePicker.java +++ b/lazydatepicker/src/main/java/com/mikhaellopez/lazydatepicker/LazyLocalDatePicker.java @@ -1,37 +1,52 @@ package com.mikhaellopez.lazydatepicker; -import android.content.Context; -import android.util.AttributeSet; +import ohos.agp.components.AttrSet; +import ohos.app.Context; -import org.threeten.bp.LocalDate; -import org.threeten.bp.format.DateTimeFormatter; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; /** - * Copyright (C) 2020 Mikhael LOPEZ - * Licensed under the Apache License Version 2.0 + * 本地日期选择类 + * + * @since 2021-06-28 */ public class LazyLocalDatePicker extends LazyDatePicker { - private LocalDate minDate; private LocalDate maxDate; private OnLocalDatePickListener onLocalDatePickListener; private OnLocalDateSelectedListener onLocalDateSelectedListener; - //region CONSTRUCTORS + /** + * 默认构造方式 + * + * @param context + */ public LazyLocalDatePicker(Context context) { - this(context, null); + super(context); } - public LazyLocalDatePicker(Context context, AttributeSet attrs) { - this(context, attrs, 0); + /** + * 布局引用构造方式 + * + * @param context + * @param attrSet + */ + public LazyLocalDatePicker(Context context, AttrSet attrSet) { + super(context, attrSet); } - public LazyLocalDatePicker(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); + /** + * 布局设置主题构造方式 + * + * @param context + * @param attrSet + * @param styleName + */ + public LazyLocalDatePicker(Context context, AttrSet attrSet, String styleName) { + super(context, attrSet, styleName); } - //endregion - //region PROTECTED METHOD @Override protected void onDatePick() { if (onLocalDatePickListener != null) { @@ -73,9 +88,12 @@ public class LazyLocalDatePicker extends LazyDatePicker { LocalDate realDateToCheckTmp = stringToLocalDate(dateToCheckTmp.toString(), dateFormat.getValue()); return dateToString(realDateToCheckTmp, dateFormat.getValue()).equals(dateToCheckTmp.toString()); } - //endregion - //region PUBLIC METHOD + /** + * region PUBLIC METHOD + * + * @return LocalDate + */ public LocalDate getLocalDate() { if (date.length() == LENGTH_DATE_COMPLETE) { return stringToLocalDate(date, dateFormat.getValue()); @@ -83,6 +101,12 @@ public class LazyLocalDatePicker extends LazyDatePicker { return null; } + /** + * 设置LocalDate + * + * @param newDate 需要设置的LocalDate + * @return boolean + */ public boolean setLocalDate(LocalDate newDate) { String tmpDate = dateToString(newDate, dateFormat.getValue()); @@ -99,41 +123,91 @@ public class LazyLocalDatePicker extends LazyDatePicker { return true; } + /** + * 设置最小的LocalDate + * + * @param minDate 需要设置的LocalDate + */ public void setMinLocalDate(LocalDate minDate) { this.minDate = minDate; clear(); } + /** + * 设置最大的LocalDate + * + * @param maxDate 需要设置的LocalDate + */ public void setMaxLocalDate(LocalDate maxDate) { this.maxDate = maxDate; clear(); } + /** + * 设置OnLocalDatePickListener + * + * @param onLocalDatePickListener + */ public void setOnLocalDatePickListener(OnLocalDatePickListener onLocalDatePickListener) { this.onLocalDatePickListener = onLocalDatePickListener; } + /** + * 设置OnLocalDateSelectedListener + * + * @param onLocalDateSelectedListener + */ public void setOnLocalDateSelectedListener(OnLocalDateSelectedListener onLocalDateSelectedListener) { this.onLocalDateSelectedListener = onLocalDateSelectedListener; } - //endregion - //region UTILS + /** + * 日期转字符串 + * + * @param date + * @param pattern + * @return String + */ public static String dateToString(LocalDate date, String pattern) { return DateTimeFormatter.ofPattern(pattern).format(date); } + /** + * 时间转LocalDate + * + * @param date + * @param format + * @return LocalDate + */ public static LocalDate stringToLocalDate(String date, String format) { return LocalDate.parse(date, DateTimeFormatter.ofPattern(format)); } - //endregion + /** + * 接口OnLocalDatePickListener + * + * @since 2021-06-28 + */ public interface OnLocalDatePickListener { + /** + * 输入完毕自动回调 + * + * @param dateSelected + */ void onLocalDatePick(LocalDate dateSelected); } + /** + * 接口OnLocalDateSelectedListener + * + * @since 2021-06-28 + */ public interface OnLocalDateSelectedListener { + /** + * 输入完毕自动回调 + * + * @param dateSelected + */ void onLocalDateSelected(Boolean dateSelected); } - } diff --git a/lazydatepicker/src/main/res/layout/layout_lazy_date_picker.xml b/lazydatepicker/src/main/res/layout/layout_lazy_date_picker.xml deleted file mode 100755 index 1a844346a0024b08cd8c3e6bcbd4973bdf9fbf67..0000000000000000000000000000000000000000 --- a/lazydatepicker/src/main/res/layout/layout_lazy_date_picker.xml +++ /dev/null @@ -1,238 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/lazydatepicker/src/main/res/values/attrs.xml b/lazydatepicker/src/main/res/values/attrs.xml deleted file mode 100644 index ca3cef5cc215bf578720aaec243a9bd867551683..0000000000000000000000000000000000000000 --- a/lazydatepicker/src/main/res/values/attrs.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/lazydatepicker/src/main/res/values/dimens.xml b/lazydatepicker/src/main/res/values/dimens.xml deleted file mode 100755 index 56eb7150054e2096b5f131a8fa46af0b22c640b6..0000000000000000000000000000000000000000 --- a/lazydatepicker/src/main/res/values/dimens.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - 12dp - 2.5dp - 1dp - 6dp - \ No newline at end of file diff --git a/lazydatepicker/src/main/res/values/strings.xml b/lazydatepicker/src/main/res/values/strings.xml deleted file mode 100644 index 6dd868ba8bdd501b9e0361fc2aa695abad048d54..0000000000000000000000000000000000000000 --- a/lazydatepicker/src/main/res/values/strings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - D - M - Y - \ No newline at end of file diff --git a/lazydatepicker/src/main/resources/base/element/string.json b/lazydatepicker/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..ed224622e9fbab0cbced3f1fce3a0c72e7b1a9f7 --- /dev/null +++ b/lazydatepicker/src/main/resources/base/element/string.json @@ -0,0 +1,20 @@ +{ + "string": [ + { + "name": "lazydatepicker_library", + "value": "lazydatepicker_library" + }, + { + "name": "ldp_day", + "value": "D" + }, + { + "name": "ldp_month", + "value": "M" + }, + { + "name": "ldp_year", + "value": "Y" + } + ] +} diff --git a/lazydatepicker/src/main/resources/base/layout/layout_lazy_date_picker.xml b/lazydatepicker/src/main/resources/base/layout/layout_lazy_date_picker.xml new file mode 100644 index 0000000000000000000000000000000000000000..56087b6f15f099c41e794b017f0da1aad236558a --- /dev/null +++ b/lazydatepicker/src/main/resources/base/layout/layout_lazy_date_picker.xml @@ -0,0 +1,246 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lazydatepicker/src/test/java/com/mikhaellopez/lazydatepicker/ExampleTest.java b/lazydatepicker/src/test/java/com/mikhaellopez/lazydatepicker/ExampleTest.java new file mode 100644 index 0000000000000000000000000000000000000000..50fa43d962ed13cc2d0e0f34f13666f9efa60427 --- /dev/null +++ b/lazydatepicker/src/test/java/com/mikhaellopez/lazydatepicker/ExampleTest.java @@ -0,0 +1,9 @@ +package com.mikhaellopez.lazydatepicker; + +import org.junit.Test; + +public class ExampleTest { + @Test + public void onStart() { + } +} diff --git a/preview/preview_2.gif b/preview/preview_2.gif deleted file mode 100644 index ba53e03b7ed509264dc99903f1a7abc072163c5f..0000000000000000000000000000000000000000 Binary files a/preview/preview_2.gif and /dev/null differ diff --git a/publish.sh b/publish.sh deleted file mode 100644 index 4324888c604bedba1ebab9b21fe4075c1427281e..0000000000000000000000000000000000000000 --- a/publish.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash -./gradlew clean -./gradlew uploadArchives \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 5d6a1173a18e02421244fdd1fd029f70bdc543b1..2ea285e173b846d88253ac75ed4aba4e9649f934 100755 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':lazydatepicker-example', ':lazydatepicker' +include ':entry', ':lazydatepicker'