diff --git a/.gitignore b/.gitignore
index 147c5d9e0daf750c0a8412c59799eec0ad090179..37a4eb8b43d978ea05b2c6e3fb934f9b40dddd4d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,11 +1,15 @@
*.iml
.gradle
/local.properties
-/.idea/workspace.xml
+/.idea/caches
/.idea/libraries
+/.idea/modules.xml
+/.idea/workspace.xml
+/.idea/navEditor.xml
+/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
-.directory
-.idea/
+/entry/.preview
+.cxx
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 0000000000000000000000000000000000000000..8ce21bee96bf332652df7afb0b4a69da85184d1e
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,2 @@
+## 0.0.1-SNAPSHOT
+ohos 第一个版本,完整实现了原库的全部api
diff --git a/README.OPENSOURCE b/README.OPENSOURCE
new file mode 100644
index 0000000000000000000000000000000000000000..f6a3ea4775a81fa3e2de2390109a1a2b4492e4b7
--- /dev/null
+++ b/README.OPENSOURCE
@@ -0,0 +1,20 @@
+[
+
+ {
+
+ "Name": "Android-SwitchDateTimePicker",
+
+ "License": "Apache License",
+
+ "License File": "License",
+
+ "Version Number": "2.0",
+
+ "Upstream URL": "https://hub.fastgit.org/Kunzisoft/Android-SwitchDateTimePicker",
+
+ "Description": "用于在同一UI中使用DatePicker(日历)和TimePicker(时钟)在对话框中选择日期对象"
+
+
+ }
+
+]
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..6d368e6e8e17f103085e46abfe784bfa79272045
--- /dev/null
+++ b/README.md
@@ -0,0 +1,76 @@
+# Ohos-SwitchDateTimePicker
+
+#### 项目介绍
+- 项目名称:Ohos-SwitchDateTimePicker
+- 所属系列:openharmony的第三方组件适配移植
+- 功能:用于在同一 UI 中使用 DatePicker(日历)和 TimePicker(时钟)在对话框中选择日期对象
+- 项目移植状态:主功能完成
+- 调用差异:无
+- 开发版本:sdk6,DevEco Studio 2.2 Beta1
+- 基线版本:Release 2.0
+
+#### 效果演示
+
+
+#### 安装教程
+
+1.在项目根目录下的build.gradle文件中,
+ ```gradle
+allprojects {
+ repositories {
+ maven {
+ url 'https://s01.oss.sonatype.org/content/repositories/snapshots/'
+ }
+ }
+}
+ ```
+2.在entry模块的build.gradle文件中,
+ ```gradle
+ dependencies {
+ implementation('com.gitee.chinasoft_ohos:Ohos-SwitchDateTimePicker:0.0.1-SNAPSHOT')
+ ......
+ }
+ ```
+
+在sdk6,DevEco Studio 2.2 Beta1下项目可直接运行
+如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件,
+并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下
+
+#### 使用说明
+```java
+dateTimeFragment.set24HoursMode(false);
+dateTimeFragment.setHighlightAMPMSelection(false);
+dateTimeFragment.setMinimumDateTime(new GregorianCalendar(2015, Calendar.JANUARY, 1).getTime());
+dateTimeFragment.setMaximumDateTime(new GregorianCalendar(2025, Calendar.DECEMBER, 31).getTime());
+```
+#### 测试信息
+
+CodeCheck代码测试无异常
+
+CloudTest代码测试无异常
+
+病毒安全检测通过
+
+当前版本demo功能与原组件基本无差异
+
+
+#### 版本迭代
+
+- 0.0.1-SNAPSHOT
+
+#### 版权和许可信息
+```
+Copyright (c) 2016 JAMET Jeremy
+
+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.
+```
\ No newline at end of file
diff --git a/ReadMe.md b/ReadMe.md
deleted file mode 100644
index b06c47f31dbb7031e3a691bdb68398fef1634929..0000000000000000000000000000000000000000
--- a/ReadMe.md
+++ /dev/null
@@ -1,191 +0,0 @@
-[](http://android-arsenal.com/details/1/4513)
-
-# Android SwitchDateTime Picker
-
- SwitchDateTime Picker is a library for select a *Date* object in dialog with a DatePicker (Calendar) and a TimePicker (Clock) in the same UI.
-
-
-
-
-## Contributions
-
-You can contribute in different ways to help us on our work.
-
-* Add features by a pull request.
-* Help to translate into your language
-* [Donate](https://www.kunzisoft.com/donation) 人◕ ‿‿ ◕人Y for a better service and a quick development of your features.
-
-## Installation
-Add the JitPack repository in your build.gradle at the end of repositories:
-```
- allprojects {
- repositories {
- ...
- maven { url "https://jitpack.io" }
- }
- }
-```
-And add the dependency
-[](https://jitpack.io/#Kunzisoft/Android-SwitchDateTimePicker)
-*replacing ${version} with the version number in jitpack*
-
-```
- dependencies {
- compile 'com.github.Kunzisoft:Android-SwitchDateTimePicker:${version}'
- }
-```
-
-## Usage
-
-### SimpleDateFormat for Day and Month
-You can specify a particular [*SimpleDateFormat*](https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html) for value of Day and Month with **setSimpleDateMonthAndDayFormat(SimpleDateFormat format)**
-Warning, the format must satisfy the regular expression : **(M|w|W|D|d|F|E|u|\s)***
-, for example *dd MMMM*
-
-### 24 Hours mode
-By default, time is in 12 hours mode, If you want a 24-hour display, use:
-`dateTimeFragment.set24HoursMode(true);`
-before the "show"
-
-#### Hightligh selected AM / PM
-In 24 hours mode, If you want to highlight the selected AM or PM, use :
-`dateTimeFragment.setHighlightAMPMSelection(true);`
-
-### Start with a specific view
-For launch Dialog with a specific view, call :
-`dateTimeFragment.startAtTimeView();`, `dateTimeFragment.startAtCalendarView();` or `dateTimeFragment.startAtYearView();`
-before the "show"
-
-### Define minimum and maximum
-For just allow selection after or/and before dates, use :
-`dateTimeFragment.setMinimumDateTime(Date minimum);`
-and
-`dateTimeFragment.setMaximumDateTime(Date maximum);`
-
-### TimeZone
-Optionally define a timezone :
-`dateTimeFragment.setTimeZone(TimeZone.getDefault());`
-
-### Style
-You can customize the style to change color, bold, etc... of each element.
-You need to use a Theme.AppCompat theme (or descendant) with SwitchDateTime's activity. (`compile 'com.android.support:appcompat-v7:25.1.0'` in gradle)
-
-
-
-In your *styles.xml*, you can redefine each style separately, but you must keep each item, for example : change size of "year label"
-```
-
-
-
-
-
-
-
-
-
-```
-Styles elements : https://github.com/Kunzisoft/Android-SwitchDateTimePicker/blob/master/switchdatetime/src/main/res/values/styles.xml
-
-#### AlertStyle
-To customize the AlertDialog that is shown, use :
-`void setAlertStyle(@StyleRes int styleId)`
-
-### Sample
-You can see
-https://github.com/J-Jamet/Android-SwitchDateTimePicker/blob/master/sample/src/main/java/com/kunzisoft/switchdatetimesample/Sample.java
-for complete sample.
-```
-// Initialize
-SwitchDateTimeDialogFragment dateTimeDialogFragment = SwitchDateTimeDialogFragment.newInstance(
- "Title example",
- "OK",
- "Cancel"
-);
-
-// Assign values
-dateTimeDialogFragment.startAtCalendarView();
-dateTimeDialogFragment.set24HoursMode(true);
-dateTimeDialogFragment.setMinimumDateTime(new GregorianCalendar(2015, Calendar.JANUARY, 1).getTime());
-dateTimeDialogFragment.setMaximumDateTime(new GregorianCalendar(2025, Calendar.DECEMBER, 31).getTime());
-dateTimeDialogFragment.setDefaultDateTime(new GregorianCalendar(2017, Calendar.MARCH, 4, 15, 20).getTime());
-
-// Define new day and month format
-try {
- dateTimeDialogFragment.setSimpleDateMonthAndDayFormat(new SimpleDateFormat("dd MMMM", Locale.getDefault()));
-} catch (SwitchDateTimeDialogFragment.SimpleDateMonthAndDayFormatException e) {
- Log.e(TAG, e.getMessage());
-}
-
-// Set listener
-dateTimeDialogFragment.setOnButtonClickListener(new SwitchDateTimeDialogFragment.OnButtonClickListener() {
- @Override
- public void onPositiveButtonClick(Date date) {
- // Date is get on positive button click
- // Do something
- }
-
- @Override
- public void onNegativeButtonClick(Date date) {
- // Date is get on negative button click
- }
-});
-
-// Show
-dateTimeDialogFragment.show(getSupportFragmentManager(), "dialog_time");
-```
-
-#### Neutral button
-
-
-
-To use with a neutral button, initialize with another parameter and implement the *OnButtonWithNeutralClickListener* :
-```
-SwitchDateTimeDialogFragment dateTimeDialogFragment = SwitchDateTimeDialogFragment.newInstance(
- "Title example",
- "OK",
- "Cancel",
- "Clean"
-);
-
-dateTimeFragment.setOnButtonClickListener(new SwitchDateTimeDialogFragment.OnButtonWithNeutralClickListener() {
- @Override
- public void onPositiveButtonClick(Date date) {
- }
-
- @Override
- public void onNegativeButtonClick(Date date) {
- }
-
- @Override
- public void onNeutralButtonClick(Date date) {
- }
-});
-```
-
-## Bonus
-You can follow the project live on https://www.livecoding.tv/kunzisoft/
-
-## License
-
-Copyright (c) 2016 JAMET Jeremy
-
-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.
diff --git a/art/demo1.gif b/art/demo1.gif
deleted file mode 100644
index c5a4e8c4ef4f5475dda01e3e881174e5e3cab488..0000000000000000000000000000000000000000
Binary files a/art/demo1.gif and /dev/null differ
diff --git a/art/demo2.gif b/art/demo2.gif
deleted file mode 100644
index 6481d4039e627efbca83da21188f9d67fa1b5bf4..0000000000000000000000000000000000000000
Binary files a/art/demo2.gif and /dev/null differ
diff --git a/art/ic_launcher.svg b/art/ic_launcher.svg
deleted file mode 100644
index 271eb19e96f27e838427aee09ab489bb4a585be8..0000000000000000000000000000000000000000
--- a/art/ic_launcher.svg
+++ /dev/null
@@ -1,2028 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/art/ic_launcher_round.svg b/art/ic_launcher_round.svg
deleted file mode 100644
index 8a6158c6558973445d41592055802fcabab2c98e..0000000000000000000000000000000000000000
--- a/art/ic_launcher_round.svg
+++ /dev/null
@@ -1,1951 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/art/logo.png b/art/logo.png
deleted file mode 100644
index 3a72a10ecde71afd5a5c5748a9bffe99d94f37f5..0000000000000000000000000000000000000000
Binary files a/art/logo.png and /dev/null differ
diff --git a/art/screen1.png b/art/screen1.png
deleted file mode 100644
index 40962cbfe8bc832a2ac9389c275f653170c8f32e..0000000000000000000000000000000000000000
Binary files a/art/screen1.png and /dev/null differ
diff --git a/art/screen2.jpg b/art/screen2.jpg
deleted file mode 100644
index 6bee40dee1fd565517ed7ec210ec402a6795d54f..0000000000000000000000000000000000000000
Binary files a/art/screen2.jpg and /dev/null differ
diff --git a/art/screen3.jpg b/art/screen3.jpg
deleted file mode 100644
index 32258465cbdfe37c8782212c701e754721b00393..0000000000000000000000000000000000000000
Binary files a/art/screen3.jpg and /dev/null differ
diff --git a/build.gradle b/build.gradle
index f932f02d63dd2a8c13a40de1c6ce3739a6ffb412..0214b75b5b5ee2c380e8d3d250a78d1a03b94225 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,21 +1,39 @@
+// Top-level build file where you can add configuration options common to all sub-projects/modules.
+apply plugin: 'com.huawei.ohos.app'
+
+ohos {
+ compileSdkVersion 5
+ defaultConfig {
+ compatibleSdkVersion 5
+ }
+}
+
buildscript {
repositories {
+ maven {
+ url 'https://repo.huaweicloud.com/repository/maven/'
+ }
+ maven {
+ url 'https://developer.huawei.com/repo/'
+ }
+ mavenCentral()
jcenter()
- google()
}
dependencies {
- classpath 'com.android.tools.build:gradle:3.1.2'
+ classpath 'com.huawei.ohos:hap:2.4.5.0'
+ classpath 'com.huawei.ohos:decctest:1.2.4.1'
}
}
allprojects {
repositories {
+ maven {
+ url 'https://repo.huaweicloud.com/repository/maven/'
+ }
+ maven {
+ url 'https://developer.huawei.com/repo/'
+ }
+ mavenCentral()
jcenter()
- maven { url "https://maven.google.com" }
- maven { url 'https://jitpack.io' }
}
}
-
-task clean(type: Delete) {
- delete rootProject.buildDir
-}
diff --git a/sample/.gitignore b/entry/.gitignore
similarity index 100%
rename from sample/.gitignore
rename to entry/.gitignore
diff --git a/entry/build.gradle b/entry/build.gradle
new file mode 100644
index 0000000000000000000000000000000000000000..127766a1aa6ebf118daeb08bdc2b979013d273e2
--- /dev/null
+++ b/entry/build.gradle
@@ -0,0 +1,29 @@
+apply plugin: 'com.huawei.ohos.hap'
+apply plugin: 'com.huawei.ohos.decctest'
+
+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'
+ compile project(path: ':switchdatetime')
+}
+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..1d555f0867c3dc9bc6e9bc323eff773772004676
--- /dev/null
+++ b/entry/src/main/config.json
@@ -0,0 +1,55 @@
+{
+ "app": {
+ "bundleName": "com.kunzisoft.switchdatetimesample",
+ "vendor": "kunzisoft",
+ "version": {
+ "code": 1000000,
+ "name": "1.0.0"
+ }
+ },
+ "deviceConfig": {},
+ "module": {
+ "package": "com.kunzisoft.switchdatetimesample",
+ "name": ".MyApplication",
+ "mainAbility": "com.kunzisoft.switchdatetimesample.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.kunzisoft.switchdatetimesample.MainAbility",
+ "icon": "$media:icon",
+ "description": "$string:mainability_description",
+ "label": "$string:entry_MainAbility",
+ "type": "page",
+ "launchType": "standard"
+ },
+ {
+ "orientation": "unspecified",
+ "name": "com.kunzisoft.switchdatetimesample.test",
+ "icon": "$media:icon",
+ "description": "$string:test_description",
+ "label": "$string:entry_test",
+ "type": "page",
+ "launchType": "standard"
+ }
+ ]
+ }
+}
\ No newline at end of file
diff --git a/entry/src/main/java/com/kunzisoft/switchdatetimesample/MainAbility.java b/entry/src/main/java/com/kunzisoft/switchdatetimesample/MainAbility.java
new file mode 100644
index 0000000000000000000000000000000000000000..9f0cc4db5c702ac29179ee786d9a9055d1273463
--- /dev/null
+++ b/entry/src/main/java/com/kunzisoft/switchdatetimesample/MainAbility.java
@@ -0,0 +1,14 @@
+package com.kunzisoft.switchdatetimesample;
+
+import com.kunzisoft.switchdatetimesample.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/kunzisoft/switchdatetimesample/MyApplication.java b/entry/src/main/java/com/kunzisoft/switchdatetimesample/MyApplication.java
new file mode 100644
index 0000000000000000000000000000000000000000..f5013761777ecdb916161813859b6d3ce9df5134
--- /dev/null
+++ b/entry/src/main/java/com/kunzisoft/switchdatetimesample/MyApplication.java
@@ -0,0 +1,10 @@
+package com.kunzisoft.switchdatetimesample;
+
+import ohos.aafwk.ability.AbilityPackage;
+
+public class MyApplication extends AbilityPackage {
+ @Override
+ public void onInitialize() {
+ super.onInitialize();
+ }
+}
diff --git a/sample/src/main/java/com/kunzisoft/switchdatetimesample/Sample.java b/entry/src/main/java/com/kunzisoft/switchdatetimesample/slice/MainAbilitySlice.java
similarity index 50%
rename from sample/src/main/java/com/kunzisoft/switchdatetimesample/Sample.java
rename to entry/src/main/java/com/kunzisoft/switchdatetimesample/slice/MainAbilitySlice.java
index 426c898cc9e094befcd0987695e4cb22dfd57d68..0d651ef0ed3f49aa7f024b28e4c2e4d0ffbe841e 100644
--- a/sample/src/main/java/com/kunzisoft/switchdatetimesample/Sample.java
+++ b/entry/src/main/java/com/kunzisoft/switchdatetimesample/slice/MainAbilitySlice.java
@@ -1,57 +1,44 @@
-package com.kunzisoft.switchdatetimesample;
-
-import android.os.Bundle;
-import android.support.v7.app.AppCompatActivity;
-import android.util.Log;
-import android.view.View;
-import android.widget.Button;
-import android.widget.TextView;
+package com.kunzisoft.switchdatetimesample.slice;
import com.kunzisoft.switchdatetime.SwitchDateTimeDialogFragment;
+import com.kunzisoft.switchdatetimesample.ResourceTable;
+
+import ohos.aafwk.ability.AbilitySlice;
+import ohos.aafwk.content.Intent;
+import ohos.agp.components.Button;
+import ohos.agp.components.Component;
+import ohos.agp.components.Text;
+import ohos.agp.utils.Color;
+import ohos.agp.window.service.WindowManager;
import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.Locale;
-import java.util.TimeZone;
-
-/**
- * Sample class for an example of using the API SwitchDateTimePicker
- * @author JJamet
- */
-public class Sample extends AppCompatActivity {
+import java.util.*;
+public class MainAbilitySlice extends AbilitySlice {
private static final String TAG = "Sample";
private static final String TAG_DATETIME_FRAGMENT = "TAG_DATETIME_FRAGMENT";
private static final String STATE_TEXTVIEW = "STATE_TEXTVIEW";
- private TextView textView;
+ private Text textView;
private SwitchDateTimeDialogFragment dateTimeFragment;
@Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_sample);
-
- textView = findViewById(R.id.textView);
- if (savedInstanceState != null) {
- // Restore value from saved state
- textView.setText(savedInstanceState.getCharSequence(STATE_TEXTVIEW));
- }
+ public void onStart(Intent intent) {
+ super.onStart(intent);
+ super.setUIContent(ResourceTable.Layout_ability_main);
+ WindowManager.getInstance().getTopWindow().get().setStatusBarColor(Color.getIntColor("#b71c1c"));
+ textView = (Text) findComponentById(ResourceTable.Id_textView);
// Construct SwitchDateTimePicker
- dateTimeFragment = (SwitchDateTimeDialogFragment) getSupportFragmentManager().findFragmentByTag(TAG_DATETIME_FRAGMENT);
- if(dateTimeFragment == null) {
- dateTimeFragment = SwitchDateTimeDialogFragment.newInstance(
- getString(R.string.label_datetime_dialog),
- getString(android.R.string.ok),
- getString(android.R.string.cancel),
- getString(R.string.clean) // Optional
- );
- }
+ dateTimeFragment = SwitchDateTimeDialogFragment.newInstance(
+ getAbility(),
+ getString(ResourceTable.String_label_datetime_dialog),
+ "OK",
+ "Cancel",
+ getString(ResourceTable.String_clean) // Optional
+ );
// Optionally define a timezone
dateTimeFragment.setTimeZone(TimeZone.getDefault());
@@ -68,15 +55,15 @@ public class Sample extends AppCompatActivity {
try {
dateTimeFragment.setSimpleDateMonthAndDayFormat(new SimpleDateFormat("MMMM dd", Locale.getDefault()));
} catch (SwitchDateTimeDialogFragment.SimpleDateMonthAndDayFormatException e) {
- Log.e(TAG, e.getMessage());
+
+ e.fillInStackTrace();
}
// Set listener for date
- // Or use dateTimeFragment.setOnButtonClickListener(new SwitchDateTimeDialogFragment.OnButtonClickListener() {
dateTimeFragment.setOnButtonClickListener(new SwitchDateTimeDialogFragment.OnButtonWithNeutralClickListener() {
@Override
public void onPositiveButtonClick(Date date) {
- textView.setText(myDateFormat.format(date));
+ textView.setText(myDateFormat.format(date));
}
@Override
@@ -91,22 +78,25 @@ public class Sample extends AppCompatActivity {
}
});
- Button buttonView = findViewById(R.id.button);
- buttonView.setOnClickListener(new View.OnClickListener() {
+ Button buttonView = (Button) findComponentById(ResourceTable.Id_button);
+ buttonView.setClickedListener(new Component.ClickedListener() {
@Override
- public void onClick(View view) {
+ public void onClick(Component view) {
// Re-init each time
dateTimeFragment.startAtCalendarView();
dateTimeFragment.setDefaultDateTime(new GregorianCalendar(2017, Calendar.MARCH, 4, 15, 20).getTime());
- dateTimeFragment.show(getSupportFragmentManager(), TAG_DATETIME_FRAGMENT);
+ dateTimeFragment.show();
}
});
}
@Override
- public void onSaveInstanceState(Bundle savedInstanceState) {
- // Save the current textView
- savedInstanceState.putCharSequence(STATE_TEXTVIEW, textView.getText());
- super.onSaveInstanceState(savedInstanceState);
+ public void onActive() {
+ super.onActive();
+ }
+
+ @Override
+ public void onForeground(Intent intent) {
+ super.onForeground(intent);
}
-}
\ No newline at end of file
+}
diff --git a/entry/src/main/resources/base/element/color.json b/entry/src/main/resources/base/element/color.json
new file mode 100644
index 0000000000000000000000000000000000000000..c7a45cd13bcc2f862d4706942671f8a65a141613
--- /dev/null
+++ b/entry/src/main/resources/base/element/color.json
@@ -0,0 +1,16 @@
+{
+ "color": [
+ {
+ "name": "colorPrimary",
+ "value": "#f44336"
+ },
+ {
+ "name": "colorPrimaryDark",
+ "value": "#b71c1c"
+ },
+ {
+ "name": "colorAccent",
+ "value": "#f44336"
+ }
+ ]
+}
\ 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..4305acc8a5f99508c58505357c08bd7cb11d4999
--- /dev/null
+++ b/entry/src/main/resources/base/element/string.json
@@ -0,0 +1,44 @@
+{
+ "string": [
+ {
+ "name": "entry_MainAbility",
+ "value": "Switch DateTime Picker"
+ },
+ {
+ "name": "mainability_description",
+ "value": "Java_Empty Ability"
+ },
+ {
+ "name": "mainability_HelloWorld",
+ "value": "Hello World"
+ },
+ {
+ "name": "switch_datetime_picker_name",
+ "value": "Switch DateTime Picker"
+ },
+ {
+ "name": "open_datetime_dialog",
+ "value": "OPEN DATETIME DIALOG"
+ },
+ {
+ "name": "open_datetime_dialog_with_neutral_button",
+ "value": "Open DateTime Dialog with Neutral Button"
+ },
+ {
+ "name": "clean",
+ "value": "Clean"
+ },
+ {
+ "name": "test_description",
+ "value": "Java_Empty Ability"
+ },
+ {
+ "name": "test_HelloWorld",
+ "value": "Hello World"
+ },
+ {
+ "name": "entry_test",
+ "value": "entry_test"
+ }
+ ]
+}
\ 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/graphic/background_ability_test.xml b/entry/src/main/resources/base/graphic/background_ability_test.xml
new file mode 100644
index 0000000000000000000000000000000000000000..a002c2353e78af3a15235e00738328ff566bc085
--- /dev/null
+++ b/entry/src/main/resources/base/graphic/background_ability_test.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
\ 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..93551debc3e9db647f03b4629d61492157004d98
--- /dev/null
+++ b/entry/src/main/resources/base/layout/ability_main.xml
@@ -0,0 +1,31 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
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..b7756b0683940812afad715d432038052948fb8e
--- /dev/null
+++ b/entry/src/main/resources/en/element/string.json
@@ -0,0 +1,28 @@
+{
+ "string": [
+ {
+ "name": "entry_MainAbility",
+ "value": "Switch DateTime Picker"
+ },
+ {
+ "name": "mainability_description",
+ "value": "Java_Empty Ability"
+ },
+ {
+ "name": "mainability_HelloWorld",
+ "value": "Hello World"
+ },
+ {
+ "name": "entry_test",
+ "value": "entry_test"
+ },
+ {
+ "name": "test_description",
+ "value": "Java_Empty Ability"
+ },
+ {
+ "name": "test_HelloWorld",
+ "value": "Hello World"
+ }
+ ]
+}
\ No newline at end of file
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..4260af6a341e37f16000a4d16ab06f5343ec5176
--- /dev/null
+++ b/entry/src/main/resources/zh/element/string.json
@@ -0,0 +1,28 @@
+{
+ "string": [
+ {
+ "name": "entry_MainAbility",
+ "value": "Switch DateTime Picker"
+ },
+ {
+ "name": "mainability_description",
+ "value": "Java_Empty Ability"
+ },
+ {
+ "name": "mainability_HelloWorld",
+ "value": "你好,世界"
+ },
+ {
+ "name": "entry_test",
+ "value": "entry_test"
+ },
+ {
+ "name": "test_description",
+ "value": "Java_Empty Ability"
+ },
+ {
+ "name": "test_HelloWorld",
+ "value": "你好,世界"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/entry/src/ohosTest/java/com/kunzisoft/switchdatetimesample/ExampleOhosTest.java b/entry/src/ohosTest/java/com/kunzisoft/switchdatetimesample/ExampleOhosTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..d0a88941921c46f48a37d456298b24cae8c602fc
--- /dev/null
+++ b/entry/src/ohosTest/java/com/kunzisoft/switchdatetimesample/ExampleOhosTest.java
@@ -0,0 +1,14 @@
+package com.kunzisoft.switchdatetimesample;
+
+import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class ExampleOhosTest {
+ @Test
+ public void testBundleName() {
+ final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName();
+ assertEquals("com.kunzisoft.switchdatetimesample", actualBundleName);
+ }
+}
\ No newline at end of file
diff --git a/entry/src/test/java/com/kunzisoft/switchdatetimesample/ExampleTest.java b/entry/src/test/java/com/kunzisoft/switchdatetimesample/ExampleTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..da479ee5e6d417ad69745cbc5d3e2f880798cca9
--- /dev/null
+++ b/entry/src/test/java/com/kunzisoft/switchdatetimesample/ExampleTest.java
@@ -0,0 +1,9 @@
+package com.kunzisoft.switchdatetimesample;
+
+import org.junit.Test;
+
+public class ExampleTest {
+ @Test
+ public void onStart() {
+ }
+}
diff --git a/gradle.properties b/gradle.properties
deleted file mode 100644
index aac7c9b4614ccfde6c721f24994cf30885a791d0..0000000000000000000000000000000000000000
--- a/gradle.properties
+++ /dev/null
@@ -1,17 +0,0 @@
-# Project-wide Gradle settings.
-
-# IDE (e.g. Android Studio) users:
-# Gradle settings configured through the IDE *will override*
-# any settings specified in this file.
-
-# For more details on how to configure your build environment visit
-# http://www.gradle.org/docs/current/userguide/build_environment.html
-
-# Specifies the JVM arguments used for the daemon process.
-# The setting is particularly useful for tweaking memory settings.
-org.gradle.jvmargs=-Xmx1536m
-
-# When configured, Gradle will run in incubating parallel mode.
-# This option should only be used with decoupled projects. More details, visit
-# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
-# org.gradle.parallel=true
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
index 13372aef5e24af05341d49695ee84e5f9b594659..490fda8577df6c95960ba7077c43220e5bb2c0d9 100644
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 61e9e82c879eeb6727badbaadf5e235f5251aff2..f59159e865d4b59feb1b8c44b001f62fc5d58df4 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,5 @@
-#Sat Apr 21 18:46:38 CEST 2018
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-4.4-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 100644
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/img/demo.gif b/img/demo.gif
new file mode 100644
index 0000000000000000000000000000000000000000..6916acd7830a0aa69b9b058aaca139290344d746
Binary files /dev/null and b/img/demo.gif differ
diff --git a/sample/build.gradle b/sample/build.gradle
deleted file mode 100644
index 7fe252e44362b931d3611989cd00921bed188edf..0000000000000000000000000000000000000000
--- a/sample/build.gradle
+++ /dev/null
@@ -1,28 +0,0 @@
-apply plugin: "com.android.application"
-
-android {
- compileSdkVersion 27
- buildToolsVersion "27.0.3"
-
- defaultConfig {
- applicationId "com.kunzisoft.switchdatetimepicker.sample"
- minSdkVersion 14
- targetSdkVersion 27
- versionCode 20
- versionName "2.0"
- }
-
- buildTypes {
- release {
- minifyEnabled false
- proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
- }
- }
-}
-
-def supportVersion = "27.1.1"
-
-dependencies {
- implementation "com.android.support:appcompat-v7:$supportVersion"
- implementation project(path: ":switchdatetime")
-}
diff --git a/sample/proguard-rules.pro b/sample/proguard-rules.pro
deleted file mode 100644
index 402c367de1b92a2fcfb3bb3c10e23bf502656060..0000000000000000000000000000000000000000
--- a/sample/proguard-rules.pro
+++ /dev/null
@@ -1,17 +0,0 @@
-# Add project specific ProGuard rules here.
-# By default, the flags in this file are appended to flags specified
-# in /home/joker/Software/android-sdk-linux/tools/proguard/proguard-android.txt
-# You can edit the include path and order by changing the proguardFiles
-# directive in build.gradle.
-#
-# For more details, see
-# http://developer.android.com/guide/developing/tools/proguard.html
-
-# Add any project specific keep options here:
-
-# If your project uses WebView with JS, uncomment the following
-# and specify the fully qualified class name to the JavaScript interface
-# class:
-#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
-# public *;
-#}
diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml
deleted file mode 100644
index a022672f126eae4f867621586c02c45258d05e84..0000000000000000000000000000000000000000
--- a/sample/src/main/AndroidManifest.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/sample/src/main/res/layout/activity_sample.xml b/sample/src/main/res/layout/activity_sample.xml
deleted file mode 100644
index 696c0f69bd3c6230c0474296a81f0bea34498d61..0000000000000000000000000000000000000000
--- a/sample/src/main/res/layout/activity_sample.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
-
-
-
-
-
-
diff --git a/sample/src/main/res/mipmap-hdpi/ic_launcher.png b/sample/src/main/res/mipmap-hdpi/ic_launcher.png
deleted file mode 100644
index 0086aff14615bc59f489a3786ec41f8e7dd9d519..0000000000000000000000000000000000000000
Binary files a/sample/src/main/res/mipmap-hdpi/ic_launcher.png and /dev/null differ
diff --git a/sample/src/main/res/mipmap-hdpi/ic_launcher_round.png b/sample/src/main/res/mipmap-hdpi/ic_launcher_round.png
deleted file mode 100644
index 8b6876607be7cc2d870d88d3860b2a4dd9bdd453..0000000000000000000000000000000000000000
Binary files a/sample/src/main/res/mipmap-hdpi/ic_launcher_round.png and /dev/null differ
diff --git a/sample/src/main/res/mipmap-ldpi/ic_launcher.png b/sample/src/main/res/mipmap-ldpi/ic_launcher.png
deleted file mode 100644
index b0d8014db7b039ba210356c824dcba2de84bd0f6..0000000000000000000000000000000000000000
Binary files a/sample/src/main/res/mipmap-ldpi/ic_launcher.png and /dev/null differ
diff --git a/sample/src/main/res/mipmap-ldpi/ic_launcher_round.png b/sample/src/main/res/mipmap-ldpi/ic_launcher_round.png
deleted file mode 100644
index 87b085f81d1f557f09918ed3bbe0ca4372831882..0000000000000000000000000000000000000000
Binary files a/sample/src/main/res/mipmap-ldpi/ic_launcher_round.png and /dev/null differ
diff --git a/sample/src/main/res/mipmap-mdpi/ic_launcher.png b/sample/src/main/res/mipmap-mdpi/ic_launcher.png
deleted file mode 100644
index 1abf744e9463c39f4771f3ba7a397c346eb5d375..0000000000000000000000000000000000000000
Binary files a/sample/src/main/res/mipmap-mdpi/ic_launcher.png and /dev/null differ
diff --git a/sample/src/main/res/mipmap-mdpi/ic_launcher_round.png b/sample/src/main/res/mipmap-mdpi/ic_launcher_round.png
deleted file mode 100644
index b23bb23a993abb6a621a51f971e1ef8bc40efc16..0000000000000000000000000000000000000000
Binary files a/sample/src/main/res/mipmap-mdpi/ic_launcher_round.png and /dev/null differ
diff --git a/sample/src/main/res/mipmap-xhdpi/ic_launcher.png b/sample/src/main/res/mipmap-xhdpi/ic_launcher.png
deleted file mode 100644
index 48ce419dd51d544248c34fa0b183068768744aac..0000000000000000000000000000000000000000
Binary files a/sample/src/main/res/mipmap-xhdpi/ic_launcher.png and /dev/null differ
diff --git a/sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png
deleted file mode 100644
index 8464a97e9434ff2bb80f88bfe5375ae3d317e45a..0000000000000000000000000000000000000000
Binary files a/sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png and /dev/null differ
diff --git a/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png b/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
deleted file mode 100644
index 39f4bb1bd974688e3b0f703a18abf06cea016fb8..0000000000000000000000000000000000000000
Binary files a/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png and /dev/null differ
diff --git a/sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
deleted file mode 100644
index 037784c78e250e1a048fc061543065d44028e97f..0000000000000000000000000000000000000000
Binary files a/sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png and /dev/null differ
diff --git a/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png
deleted file mode 100644
index 6efc26f113dae48cef2c1ff30db34aec951460ca..0000000000000000000000000000000000000000
Binary files a/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png and /dev/null differ
diff --git a/sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
deleted file mode 100644
index 07e5f5710bd7c5333dff2d62c97486045396b911..0000000000000000000000000000000000000000
Binary files a/sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png and /dev/null differ
diff --git a/sample/src/main/res/values-w820dp/dimens.xml b/sample/src/main/res/values-w820dp/dimens.xml
deleted file mode 100644
index 63fc816444614bd64f68a372d1f93211628ee51d..0000000000000000000000000000000000000000
--- a/sample/src/main/res/values-w820dp/dimens.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
- 64dp
-
diff --git a/sample/src/main/res/values/colors.xml b/sample/src/main/res/values/colors.xml
deleted file mode 100644
index 69a6fdd34064121854ecfd5ee57dae3f8bfc7670..0000000000000000000000000000000000000000
--- a/sample/src/main/res/values/colors.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
- #f44336
- #b71c1c
- #f44336
-
diff --git a/sample/src/main/res/values/dimens.xml b/sample/src/main/res/values/dimens.xml
deleted file mode 100644
index 47c82246738c4d056e8030d3a259206f42e8e15d..0000000000000000000000000000000000000000
--- a/sample/src/main/res/values/dimens.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
- 16dp
- 16dp
-
diff --git a/sample/src/main/res/values/strings.xml b/sample/src/main/res/values/strings.xml
deleted file mode 100644
index a3c77ca04ef2bfa81ae3c02e4b4b13b696df7f04..0000000000000000000000000000000000000000
--- a/sample/src/main/res/values/strings.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
- Switch DateTime Picker
- Open DateTime Dialog
- Open DateTime Dialog with Neutral Button
- Clean
-
diff --git a/sample/src/main/res/values/styles.xml b/sample/src/main/res/values/styles.xml
deleted file mode 100644
index 90987ae49dc2b79841118963409531437965cd3c..0000000000000000000000000000000000000000
--- a/sample/src/main/res/values/styles.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-
-
-
-
-
diff --git a/settings.gradle b/settings.gradle
index c087e907b1544bffd1ed151782aa1eb9b4caef5c..9557f6b9bdb377543c4219b4d950b2c6bdb8d182 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -1 +1 @@
-include ':sample', ':switchdatetime'
+include ':entry', ':switchdatetime'
\ No newline at end of file
diff --git a/switchdatetime/build.gradle b/switchdatetime/build.gradle
index 1bed9df2a7cc23beb977e2bdb3143f179f3dfdc6..8a480603aa76991490f0147a3da86346caeb0d00 100644
--- a/switchdatetime/build.gradle
+++ b/switchdatetime/build.gradle
@@ -1,28 +1,26 @@
-apply plugin: "com.android.library"
-
-android {
- compileSdkVersion 27
- buildToolsVersion "27.0.3"
+apply plugin: 'com.huawei.ohos.library'
+ohos {
+ compileSdkVersion 5
defaultConfig {
- minSdkVersion 14
- targetSdkVersion 27
- versionCode 20
- versionName "2.0"
+ compatibleSdkVersion 5
}
-
buildTypes {
release {
- minifyEnabled false
- proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
+ proguardOpt {
+ proguardEnabled false
+ rulesFiles 'proguard-rules.pro'
+ }
}
}
+ tasks.withType(JavaCompile){
+ options.compilerArgs +=["-AeventBusIndex=org.greenrobot.eventbus.MyEventBusIndex"]
+ }
}
-def supportVersion = "27.0.2"
-
dependencies {
- implementation "com.android.support:appcompat-v7:$supportVersion"
- implementation "com.android.support:recyclerview-v7:$supportVersion"
- implementation 'com.github.prolificinteractive:material-calendarview:1.5.0'
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
+ testImplementation 'junit:junit:4.13'
+ implementation 'io.openharmony.tpc.thirdlib:EventBus:1.0.4'
+ annotationProcessor 'io.openharmony.tpc.thirdlib:eventbus-annotation-processor:1.0.1'
}
diff --git a/switchdatetime/consumer-rules.pro b/switchdatetime/consumer-rules.pro
new file mode 100644
index 0000000000000000000000000000000000000000..9dccc613bc71b04b83531f550bdab2fb667ecfc9
--- /dev/null
+++ b/switchdatetime/consumer-rules.pro
@@ -0,0 +1 @@
+# Add har specific ProGuard rules for consumer here.
\ No newline at end of file
diff --git a/switchdatetime/proguard-rules.pro b/switchdatetime/proguard-rules.pro
index 402c367de1b92a2fcfb3bb3c10e23bf502656060..f7666e47561d514b2a76d5a7dfbb43ede86da92a 100644
--- a/switchdatetime/proguard-rules.pro
+++ b/switchdatetime/proguard-rules.pro
@@ -1,17 +1 @@
-# Add project specific ProGuard rules here.
-# By default, the flags in this file are appended to flags specified
-# in /home/joker/Software/android-sdk-linux/tools/proguard/proguard-android.txt
-# You can edit the include path and order by changing the proguardFiles
-# directive in build.gradle.
-#
-# For more details, see
-# http://developer.android.com/guide/developing/tools/proguard.html
-
-# Add any project specific keep options here:
-
-# If your project uses WebView with JS, uncomment the following
-# and specify the fully qualified class name to the JavaScript interface
-# class:
-#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
-# public *;
-#}
+# config module specific ProGuard rules here.
\ No newline at end of file
diff --git a/switchdatetime/src/main/AndroidManifest.xml b/switchdatetime/src/main/AndroidManifest.xml
deleted file mode 100644
index aaaa8868c732939f04476176ab103daec6c1635c..0000000000000000000000000000000000000000
--- a/switchdatetime/src/main/AndroidManifest.xml
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
-
-
-
diff --git a/switchdatetime/src/main/config.json b/switchdatetime/src/main/config.json
new file mode 100644
index 0000000000000000000000000000000000000000..b95beba688585bfde3d1a6d6db336740e6d7600e
--- /dev/null
+++ b/switchdatetime/src/main/config.json
@@ -0,0 +1,33 @@
+{
+ "app": {
+ "bundleName": "com.kunzisoft.switchdatetimesample",
+ "vendor": "kunzisoft",
+ "version": {
+ "code": 1000000,
+ "name": "1.0.0"
+ }
+ },
+ "deviceConfig": {},
+ "module": {
+ "package": "com.kunzisoft.switchdatetime",
+ "deviceType": [
+ "phone"
+ ],
+ "distro": {
+ "deliveryWithInstall": true,
+ "moduleName": "switchdatetime",
+ "moduleType": "har"
+ },
+ "abilities": [
+ {
+ "orientation": "unspecified",
+ "name": "com.kunzisoft.switchdatetime.SwitchDateTimeDialogFragment",
+ "icon": "$media:icon",
+ "description": "$string:switchdatetimedialogfragment_description",
+ "label": "$string:switchdatetime_SwitchDateTimeDialogFragment",
+ "type": "page",
+ "launchType": "standard"
+ }
+ ]
+ }
+}
\ No newline at end of file
diff --git a/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/MyApplication.java b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/MyApplication.java
new file mode 100644
index 0000000000000000000000000000000000000000..391462286257fec5403945c61dcd8d00549b0df1
--- /dev/null
+++ b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/MyApplication.java
@@ -0,0 +1,25 @@
+package com.kunzisoft.switchdatetime;
+
+import ohos.aafwk.ability.AbilityPackage;
+
+import org.greenrobot.eventbus.EventBus;
+
+import java.io.File;
+
+public class MyApplication extends AbilityPackage {
+ private static MyApplication mInstance;
+ private File mRootDir;
+
+ @Override
+ public void onInitialize() {
+ super.onInitialize();
+ if (mInstance == null) {
+ mInstance = this;
+ }
+ EventBus.initThreadForHos(getUITaskDispatcher());
+ }
+
+ public static MyApplication getInstance() {
+ return mInstance;
+ }
+}
diff --git a/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/SwitchDateTimeDialogFragment.java b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/SwitchDateTimeDialogFragment.java
index 33b49955377f0a3310577ebc192751856555361e..b7af0a4c4492db02e56f938681e85631964ac702 100644
--- a/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/SwitchDateTimeDialogFragment.java
+++ b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/SwitchDateTimeDialogFragment.java
@@ -1,43 +1,33 @@
package com.kunzisoft.switchdatetime;
-import android.app.Dialog;
-import android.content.DialogInterface;
-import android.graphics.Color;
-import android.os.Bundle;
-import android.support.annotation.NonNull;
-import android.support.annotation.StyleRes;
-import android.support.v4.app.DialogFragment;
-import android.support.v7.app.AlertDialog;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.view.animation.Animation;
-import android.widget.ImageButton;
-import android.widget.TextView;
-import android.widget.ViewAnimator;
-
import com.kunzisoft.switchdatetime.date.OnYearSelectedListener;
import com.kunzisoft.switchdatetime.date.widget.ListPickerYearView;
+import com.kunzisoft.switchdatetime.event.MessageEvent;
+import com.kunzisoft.switchdatetime.provider.PageProvider;
+import com.kunzisoft.switchdatetime.time.RadialPickerLayout;
import com.kunzisoft.switchdatetime.time.SwitchTimePicker;
-import com.prolificinteractive.materialcalendarview.CalendarDay;
-import com.prolificinteractive.materialcalendarview.MaterialCalendarView;
-import com.prolificinteractive.materialcalendarview.OnDateSelectedListener;
+import ohos.aafwk.ability.Ability;
+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.window.dialog.CommonDialog;
+import ohos.app.Context;
+
+import org.greenrobot.eventbus.EventBus;
+import org.greenrobot.eventbus.Subscribe;
+import org.greenrobot.eventbus.ThreadMode;
+
+import java.text.DateFormatSymbols;
import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.Locale;
-import java.util.TimeZone;
+import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-/**
- * A fragment that displays a dialog window with Date and Time who can be selected by switch button
- * @author J-Jamet
- */
-public class SwitchDateTimeDialogFragment extends DialogFragment {
-
+public class SwitchDateTimeDialogFragment extends CommonDialog {
private static final String TAG = "SwitchDateTimeDialogFrg";
private static final String STATE_DATETIME = "STATE_DATETIME";
@@ -69,52 +59,67 @@ public class SwitchDateTimeDialogFragment extends DialogFragment {
private SimpleDateFormat dayAndMonthSimpleDate;
private SimpleDateFormat yearSimpleDate;
- private ViewAnimator viewSwitcher;
+ private PageFlipper viewSwitcher;
private SwitchTimePicker timePicker;
- private MaterialCalendarView materialCalendarView;
+ // private MaterialCalendarView materialCalendarView;
private ListPickerYearView listPickerYearView;
- private TextView monthAndDayHeaderValues;
- private TextView yearHeaderValues;
+ private Text monthAndDayHeaderValues;
+ private Text yearHeaderValues;
private boolean blockAnimationIn;
private boolean blockAnimationOut;
+ private static Context mContext;
+ private PageSlider pageSlider;
+ private PageProvider pageProvider;
+ private Image left_arrow;
+ private Image right_arrow;
+ private Text text_month;
+ private Calendar calendar = Calendar.getInstance();
+ private static final String[] MONTH_NAME = DateFormatSymbols.getInstance().getMonths();
+ private int original_year = 2016;
+ private int original_month = 2;
+ private int original_day = 1;
+ private Component dateTimeLayout;
+
+ private SwitchDateTimeDialogFragment(Context context) {
+ super(context);
+ }
+
/**
* Create a new instance of SwitchDateTimeDialogFragment
- * @param label Title of dialog
+ *
+ * @param label Title of dialog
* @param positiveButton Text for positive button
* @param negativeButton Text for negative button
+ * @param context context
* @return DialogFragment
*/
- public static SwitchDateTimeDialogFragment newInstance(String label, String positiveButton, String negativeButton) {
- return newInstance(label, positiveButton, negativeButton, null);
+ public static SwitchDateTimeDialogFragment newInstance(Context context, String label, String positiveButton, String negativeButton) {
+ return newInstance(context, label, positiveButton, negativeButton, null);
}
/**
- * Create a new instance of SwitchDateTimeDialogFragment
- * @param label Title of dialog
+ * SwitchDateTimeDialogFragment
+ *
+ * @param context context
+ * @param label Title of dialog
* @param positiveButton Text for positive button
* @param negativeButton Text for negative button
- * @return DialogFragment
+ * @param neutralButton Text for negative button
+ * @return switchDateTimeDialogFragment
*/
- public static SwitchDateTimeDialogFragment newInstance(String label, String positiveButton, String negativeButton, String neutralButton) {
- SwitchDateTimeDialogFragment switchDateTimeDialogFragment = new SwitchDateTimeDialogFragment();
- // Add arguments
- Bundle args = new Bundle();
- args.putString(TAG_LABEL, label);
- args.putString(TAG_POSITIVE_BUTTON, positiveButton);
- args.putString(TAG_NEGATIVE_BUTTON, negativeButton);
- if (neutralButton != null) {
- args.putString(TAG_NEUTRAL_BUTTON, neutralButton);
- }
- switchDateTimeDialogFragment.setArguments(args);
-
+ public static SwitchDateTimeDialogFragment newInstance(Context context, String label, String positiveButton,
+ String negativeButton, String neutralButton) {
+ mContext = context;
+ SwitchDateTimeDialogFragment switchDateTimeDialogFragment = new SwitchDateTimeDialogFragment(context);
return switchDateTimeDialogFragment;
}
/**
* Set listener for actions
+ *
* @param onButtonClickListener Listener for click
*/
public void setOnButtonClickListener(OnButtonClickListener onButtonClickListener) {
@@ -122,129 +127,157 @@ public class SwitchDateTimeDialogFragment extends DialogFragment {
}
@Override
- public void onSaveInstanceState(Bundle savedInstanceState) {
- // Save the current datetime and position
- savedInstanceState.putLong(STATE_DATETIME, dateTimeCalendar.getTimeInMillis());
- savedInstanceState.putInt(STATE_CURRENT_POSITION, currentPosition);
- timePicker.onSaveInstanceState(savedInstanceState);
-
- super.onSaveInstanceState(savedInstanceState);
- }
-
- @Override
- public @NonNull Dialog onCreateDialog(Bundle savedInstanceState) {
- super.onCreateDialog(savedInstanceState);
-
- assert getActivity() != null;
- assert getContext() != null;
-
+ protected void onCreate() {
+ super.onCreate();
+ EventBus.getDefault().register(this);
dateTimeCalendar.setTimeZone(timeZone);
- if(getArguments() != null) {
- mLabel = getArguments().getString(TAG_LABEL);
- mPositiveButton = getArguments().getString(TAG_POSITIVE_BUTTON);
- mNegativeButton = getArguments().getString(TAG_NEGATIVE_BUTTON);
- mNeutralButton = getArguments().getString(TAG_NEUTRAL_BUTTON);
- }
-
- if(savedInstanceState != null) {
- currentPosition = savedInstanceState.getInt(STATE_CURRENT_POSITION);
- dateTimeCalendar.setTime(new Date(savedInstanceState.getLong(STATE_DATETIME)));
- }
-
// Throw exception if default select date isn't between minimumDateTime and maximumDateTime
- if(dateTimeCalendar.before(minimumDateTime) || dateTimeCalendar.after(maximumDateTime))
+ if (dateTimeCalendar.before(minimumDateTime) || dateTimeCalendar.after(maximumDateTime))
throw new RuntimeException("Default date " + dateTimeCalendar.getTime() + " must be between "
+ minimumDateTime.getTime() + " and " + maximumDateTime.getTime());
- LayoutInflater inflater = LayoutInflater.from(getActivity());
- getActivity().getTheme().applyStyle(R.style.Theme_SwitchDateTime, false);
- View dateTimeLayout = inflater.inflate(R.layout.dialog_switch_datetime_picker,
- (ViewGroup) getActivity().findViewById(R.id.datetime_picker));
+ LayoutScatter inflater = LayoutScatter.getInstance(mContext);
+
+ dateTimeLayout = inflater.parse(ResourceTable.Layout_dialog_switch_datetime_picker,
+ (ComponentContainer) ((Ability) mContext).findComponentById(ResourceTable.Id_datetime_picker),
+ true);
// Set label
- TextView labelView = dateTimeLayout.findViewById(R.id.label);
- if(mLabel != null)
+ Text labelView = (Text) dateTimeLayout.findComponentById(ResourceTable.Id_label);
+ if (mLabel != null)
labelView.setText(mLabel);
else
- labelView.setText(getString(R.string.label_datetime_dialog));
+ labelView.setText(mContext.getString(ResourceTable.String_label_datetime_dialog));
// Lock animation for fast clicks
blockAnimationIn = false;
blockAnimationOut = false;
- viewSwitcher = dateTimeLayout.findViewById(R.id.dateSwitcher);
- viewSwitcher.getInAnimation().setAnimationListener(new Animation.AnimationListener() {
+ viewSwitcher = (PageFlipper) dateTimeLayout.findComponentById(ResourceTable.Id_dateSwitcher);
+
+ AnimatorProperty inAnimation = new AnimatorProperty(viewSwitcher);
+ inAnimation.moveFromX(840).moveToX(0).setDuration(500);
+ viewSwitcher.setIncomingAnimation(inAnimation);
+ viewSwitcher.getIncomingAnimation().setStateChangedListener(new Animator.StateChangedListener() {
@Override
- public void onAnimationStart(Animation animation) {
+ public void onStart(Animator animator) {
blockAnimationIn = true;
}
@Override
- public void onAnimationEnd(Animation animation) {
+ public void onStop(Animator animator) {
+
+ }
+
+ @Override
+ public void onCancel(Animator animator) {
+
+ }
+
+ @Override
+ public void onEnd(Animator animator) {
blockAnimationIn = false;
- currentPosition = viewSwitcher.getDisplayedChild();
+ currentPosition = viewSwitcher.getCurrentIndex();
+ }
+
+ @Override
+ public void onPause(Animator animator) {
+
}
@Override
- public void onAnimationRepeat(Animation animation) {}
+ public void onResume(Animator animator) {
+
+ }
});
- viewSwitcher.getOutAnimation().setAnimationListener(new Animation.AnimationListener() {
+ AnimatorProperty outAnimation = new AnimatorProperty(viewSwitcher);
+ outAnimation.moveByX(0).moveToX(-840).setDuration(500);
+ viewSwitcher.setOutgoingAnimation(outAnimation);
+ viewSwitcher.getOutgoingAnimation().setStateChangedListener(new Animator.StateChangedListener() {
@Override
- public void onAnimationStart(Animation animation) {
+ public void onStart(Animator animator) {
blockAnimationOut = true;
}
@Override
- public void onAnimationEnd(Animation animation) {
+ public void onStop(Animator animator) {
+
+ }
+
+ @Override
+ public void onCancel(Animator animator) {
+
+ }
+
+ @Override
+ public void onEnd(Animator animator) {
blockAnimationOut = false;
}
@Override
- public void onAnimationRepeat(Animation animation) {}
+ public void onPause(Animator animator) {
+
+ }
+
+ @Override
+ public void onResume(Animator animator) {
+
+ }
});
// Defined the start position
- if(startAtPosition != UNDEFINED_POSITION)
+ if (startAtPosition != UNDEFINED_POSITION) {
currentPosition = startAtPosition;
- viewSwitcher.setDisplayedChild(currentPosition);
+ }
+ viewSwitcher.setCurrentIndex(currentPosition);
+ // viewSwitcher.setCurrentIndex(0);
+ if (viewSwitcher.getCurrentIndex() == 0) {
+ ((RadialPickerLayout) ((DirectionalLayout) viewSwitcher.getCurrentComponent()).getComponentAt(0)).refresh();
+ }
// Button for switch between Hours/Minutes, Calendar and YearList
- ImageButton buttonSwitch = dateTimeLayout.findViewById(R.id.button_switch);
- buttonSwitch.setBackgroundColor(Color.TRANSPARENT);
- buttonSwitch.setOnClickListener(new View.OnClickListener() {
+ Image buttonSwitch = (Image) dateTimeLayout.findComponentById(ResourceTable.Id_button_switch);
+ ShapeElement shapeElement = new ShapeElement();
+ shapeElement.setRgbColor(RgbColor.fromArgbInt(Color.TRANSPARENT.getValue()));
+ buttonSwitch.setBackground(shapeElement);
+ buttonSwitch.setClickedListener(new Component.ClickedListener() {
@Override
- public void onClick(View view) {
- Utils.animLabelElement(view);
- if(!(blockAnimationIn && blockAnimationOut))
+ public void onClick(Component component) {
+ Utils.animLabelElement(component);
+ if (!(blockAnimationIn && blockAnimationOut)) {
viewSwitcher.showNext();
+ if (viewSwitcher.getCurrentIndex() == 0) {
+ ((RadialPickerLayout) ((DirectionalLayout) viewSwitcher.getCurrentComponent()).getComponentAt(0)).refresh();
+ }
+ }
}
});
// Values header hourOfDay minutes
- View timeHeaderValues = dateTimeLayout.findViewById(R.id.time_header_values);
- View.OnClickListener onTimeClickListener =
+ Component timeHeaderValues = dateTimeLayout.findComponentById(ResourceTable.Id_time_header_values);
+ Component.ClickedListener onTimeClickListener =
new OnClickHeaderElementListener(HeaderViewsPosition.VIEW_HOURS_AND_MINUTES.getPosition());
- timeHeaderValues.setOnClickListener(onTimeClickListener);
+ timeHeaderValues.setClickedListener(onTimeClickListener);
// Values header month day
- monthAndDayHeaderValues = dateTimeLayout.findViewById(R.id.date_picker_month_and_day);
- View.OnClickListener onMonthAndDayClickListener =
+ monthAndDayHeaderValues = (Text) dateTimeLayout.findComponentById(ResourceTable.Id_date_picker_month_and_day);
+ Component.ClickedListener onMonthAndDayClickListener =
new OnClickHeaderElementListener(HeaderViewsPosition.VIEW_MONTH_AND_DAY.getPosition());
- monthAndDayHeaderValues.setOnClickListener(onMonthAndDayClickListener);
+ monthAndDayHeaderValues.setClickedListener(onMonthAndDayClickListener);
// Values header year
- yearHeaderValues = dateTimeLayout.findViewById(R.id.date_picker_year);
- View.OnClickListener onYearClickListener =
+ yearHeaderValues = (Text) dateTimeLayout.findComponentById(ResourceTable.Id_date_picker_year);
+ Component.ClickedListener onYearClickListener =
new OnClickHeaderElementListener(HeaderViewsPosition.VIEW_YEAR.getPosition());
- yearHeaderValues.setOnClickListener(onYearClickListener);
+ yearHeaderValues.setClickedListener(onYearClickListener);
// Init simple date format if null
- if(dayAndMonthSimpleDate == null)
+ if (dayAndMonthSimpleDate == null)
dayAndMonthSimpleDate = new SimpleDateFormat("MMMM dd", Locale.getDefault());
- if(yearSimpleDate == null)
+ if (yearSimpleDate == null)
yearSimpleDate = new SimpleDateFormat("yyyy", Locale.getDefault());
dayAndMonthSimpleDate.setTimeZone(timeZone);
yearSimpleDate.setTimeZone(timeZone);
-
+
// Init headers
yearHeaderValues.setText(yearSimpleDate.format(dateTimeCalendar.getTime()));
monthAndDayHeaderValues.setText(dayAndMonthSimpleDate.format(dateTimeCalendar.getTime()));
@@ -258,102 +291,246 @@ public class SwitchDateTimeDialogFragment extends DialogFragment {
}
};
// Init time with saved elements
- timePicker = new SwitchTimePicker(getContext(), onTimeSelectedListener, savedInstanceState);
+ timePicker = new SwitchTimePicker(mContext, onTimeSelectedListener, null);
timePicker.setIs24HourMode(is24HoursMode);
timePicker.setHighlightAMPMSelection(highlightAMPMSelection);
timePicker.setHourOfDay(dateTimeCalendar.get(Calendar.HOUR_OF_DAY));
timePicker.setMinute(dateTimeCalendar.get(Calendar.MINUTE));
- timePicker.onCreateView(dateTimeLayout, savedInstanceState);
+ timePicker.onCreateView(dateTimeLayout, null);
timePicker.setOnClickTimeListener(onTimeClickListener);
-
- // Construct DatePicker
- materialCalendarView = dateTimeLayout.findViewById(com.kunzisoft.switchdatetime.R.id.datePicker);
- materialCalendarView.state().edit()
- .setMinimumDate(CalendarDay.from(minimumDateTime))
- .setMaximumDate(CalendarDay.from(maximumDateTime))
- .commit();
- materialCalendarView.setCurrentDate(dateTimeCalendar);
- materialCalendarView.setDateSelected(dateTimeCalendar, true);
- materialCalendarView.setOnDateChangedListener(new OnDateSelectedListener() {
- @Override
- public void onDateSelected(@NonNull MaterialCalendarView widget, @NonNull CalendarDay calendarDay, boolean selected) {
- dateTimeCalendar.set(Calendar.YEAR, calendarDay.getYear());
- dateTimeCalendar.set(Calendar.MONTH, calendarDay.getMonth());
- dateTimeCalendar.set(Calendar.DAY_OF_MONTH, calendarDay.getDay());
- listPickerYearView.assignCurrentYear(calendarDay.getYear());
- yearHeaderValues.setText(yearSimpleDate.format(dateTimeCalendar.getTime()));
- monthAndDayHeaderValues.setText(dayAndMonthSimpleDate.format(dateTimeCalendar.getTime()));
- timePicker.clickHour();
- }
- });
- materialCalendarView.invalidate();
-
// Construct YearPicker
- listPickerYearView = dateTimeLayout.findViewById(R.id.yearPicker);
+ listPickerYearView = (ListPickerYearView) dateTimeLayout.findComponentById(ResourceTable.Id_yearPicker);
listPickerYearView.setMinYear(minimumDateTime.get(Calendar.YEAR));
listPickerYearView.setMaxYear(maximumDateTime.get(Calendar.YEAR));
listPickerYearView.assignCurrentYear(dateTimeCalendar.get(Calendar.YEAR));
listPickerYearView.setDatePickerListener(new OnYearSelectedListener() {
@Override
- public void onYearSelected(View view, int yearPicker) {
+ public void onYearSelected(Component view, int yearPicker) {
dateTimeCalendar.set(Calendar.YEAR, yearPicker);
yearHeaderValues.setText(yearSimpleDate.format(dateTimeCalendar.getTime()));
- // Unfortunately, we have lags here and thread isn't a solution :/
- materialCalendarView.setCurrentDate(dateTimeCalendar.getTime());
- materialCalendarView.setDateSelected(dateTimeCalendar, true);
- // For resolve bug of switch year
- materialCalendarView.goToNext();
- materialCalendarView.goToPrevious();
}
});
+ //BuildDatePicker
+ CalendarPicker();
// Assign buttons
- AlertDialog.Builder db;
- if (alertStyleId != 0) {
- db = new AlertDialog.Builder(getContext(), alertStyleId);
+ Button btPositive = (Button) dateTimeLayout.findComponentById(ResourceTable.Id_btPositive);
+ Button btNegative = (Button) dateTimeLayout.findComponentById(ResourceTable.Id_btNegative);
+ Button btNeutral = (Button) dateTimeLayout.findComponentById(ResourceTable.Id_btNeutral);
+ setContentCustomComponent(dateTimeLayout);
+ setSize(1020, 2280);
+ btPositive.setClickedListener(new Component.ClickedListener() {
+ @Override
+ public void onClick(Component component) {
+ if (mListener != null) {
+ mListener.onPositiveButtonClick(dateTimeCalendar.getTime());
+ }
+ destroy();
+ }
+ });
+ btNegative.setClickedListener(new Component.ClickedListener() {
+ @Override
+ public void onClick(Component component) {
+ // Close dialog
+ if (mListener != null) {
+ mListener.onNegativeButtonClick(dateTimeCalendar.getTime());
+ }
+ destroy();
+ }
+ });
+ btNeutral.setClickedListener(new Component.ClickedListener() {
+ @Override
+ public void onClick(Component component) {
+ if (mListener != null) {
+ if (mListener instanceof OnButtonWithNeutralClickListener)
+ ((OnButtonWithNeutralClickListener) mListener).onNeutralButtonClick(dateTimeCalendar.getTime());
+ }
+ destroy();
+ }
+ });
+
+ }
+
+ private void CalendarPicker() {
+ calendar.set(original_year, original_month, original_day);
+ text_month = (Text) dateTimeLayout.findComponentById(ResourceTable.Id_month);
+ left_arrow = (Image) dateTimeLayout.findComponentById(ResourceTable.Id_left_arrow);
+ left_arrow.setClickedListener(new Component.ClickedListener() {
+ @Override
+ public void onClick(Component component) {
+ pageSlider.setCurrentPage(pageSlider.getCurrentPage() - 1);
+ }
+ });
+ right_arrow = (Image) dateTimeLayout.findComponentById(ResourceTable.Id_right_arrow);
+ right_arrow.setClickedListener(new Component.ClickedListener() {
+ @Override
+ public void onClick(Component component) {
+ pageSlider.setCurrentPage(pageSlider.getCurrentPage() + 1);
+ }
+ });
+ pageSlider = (PageSlider) dateTimeLayout.findComponentById(ResourceTable.Id_pageslider);
+ pageProvider = new PageProvider(mContext, calendar);
+ pageSlider.setProvider(pageProvider);
+ pageSlider.addPageChangedListener(new PageSlider.PageChangedListener() {
+ @Override
+ public void onPageSliding(int i, float v, int i1) {
+ setMonth();
+ }
+
+ @Override
+ public void onPageSlideStateChanged(int i) {
+ }
+
+ @Override
+ public void onPageChosen(int i) {
+ }
+ });
+
+ Calendar calendar = Calendar.getInstance();
+ int current_year = calendar.get(Calendar.YEAR);
+ int current_month = calendar.get(Calendar.MONTH);
+ int diff_year = current_year - original_year;
+ int diff_month = current_month - original_month;
+ int offset = diff_year * 12 + diff_month;
+ pageSlider.setCurrentPage(12);
+ setMonth();
+ }
+
+ /**
+ * 设置月份
+ */
+ public void setMonth() {
+ String s = "";
+ String mon = "";
+ int year = original_year;
+ int month = original_month + pageSlider.getCurrentPage();
+ if (month > 11) {
+ int times = month / 12;
+ year = year + times;
+ month = month - 12 * times;
+
+ }
+ switch (month) {
+ case 0:
+ s = "一月" + year;
+ mon = "一月";
+ break;
+ case 1:
+ s = "二月" + year;
+ mon = "二月";
+ break;
+ case 2:
+ s = "三月" + year;
+ mon = "三月";
+ break;
+ case 3:
+ s = "四月" + year;
+ mon = "四月";
+ break;
+ case 4:
+ s = "五月" + year;
+ mon = "五月";
+ break;
+ case 5:
+ s = "六月" + year;
+ mon = "六月";
+ break;
+ case 6:
+ s = "七月" + year;
+ mon = "七月 ";
+ break;
+ case 7:
+ s = "八月" + year;
+ mon = "八月 ";
+ break;
+ case 8:
+ s = "九月" + year;
+ mon = "九月";
+ break;
+ case 9:
+ s = "十月" + year;
+ mon = "十月";
+ break;
+ case 10:
+ s = "十一月 " + year;
+ mon = "十一月";
+ break;
+ case 11:
+ s = "十二月 " + year;
+ mon = "十二月 ";
+ break;
+ default:
+ break;
+ }
+ text_month.setText(s);
+ MessageEvent.month = mon;
+ }
+
+ /**
+ * onMessageEvent
+ *
+ * @param messageEvent messageEvent
+ */
+ @Subscribe(threadMode = ThreadMode.MAIN)
+ public void onMessageEvent(MessageEvent messageEvent) {
+
+ if (Integer.valueOf(messageEvent.getDay()) < 10) {
+ monthAndDayHeaderValues.setText(MessageEvent.month + "0" + messageEvent.getDay());
} else {
- db = new AlertDialog.Builder(getContext());
+ monthAndDayHeaderValues.setText(MessageEvent.month + messageEvent.getDay());
}
- db.setView(dateTimeLayout);
- if(mPositiveButton == null)
- mPositiveButton = getString(android.R.string.ok);
- db.setPositiveButton(mPositiveButton, new
- DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- if(mListener !=null) {
- mListener.onPositiveButtonClick(dateTimeCalendar.getTime());
- }
- }
- });
- if(mNegativeButton == null)
- mNegativeButton = getString(android.R.string.cancel);
- db.setNegativeButton(mNegativeButton, new
- DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- // Close dialog
- if(mListener !=null) {
- mListener.onNegativeButtonClick(dateTimeCalendar.getTime());
- }
- }
- });
- if (mNeutralButton != null) {
- db.setNeutralButton(mNeutralButton, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- if (mListener != null) {
- if(mListener instanceof OnButtonWithNeutralClickListener)
- ((OnButtonWithNeutralClickListener) mListener).onNeutralButtonClick(dateTimeCalendar.getTime());
- }
- }
- });
+ switch (MessageEvent.month.trim()) {
+
+ case "一月":
+ dateTimeCalendar.set(Calendar.MONTH, 0);
+ break;
+ case "二月":
+ dateTimeCalendar.set(Calendar.MONTH, 1);
+ break;
+ case "三月":
+ dateTimeCalendar.set(Calendar.MONTH, 2);
+ break;
+ case "四月":
+ dateTimeCalendar.set(Calendar.MONTH, 3);
+ break;
+ case "五月":
+ dateTimeCalendar.set(Calendar.MONTH, 4);
+ break;
+ case "六月":
+ dateTimeCalendar.set(Calendar.MONTH, 5);
+ break;
+ case "七月":
+ dateTimeCalendar.set(Calendar.MONTH, 6);
+ break;
+ case "八月":
+ dateTimeCalendar.set(Calendar.MONTH, 7);
+ break;
+ case "九月":
+ dateTimeCalendar.set(Calendar.MONTH, 8);
+ break;
+ case "十月":
+ dateTimeCalendar.set(Calendar.MONTH, 9);
+ break;
+ case "十一月":
+ dateTimeCalendar.set(Calendar.MONTH, 10);
+
+ break;
+ case "十二月":
+ dateTimeCalendar.set(Calendar.MONTH, 11);
+ break;
+ default:
+ break;
}
- return db.create();
+ dateTimeCalendar.set(Calendar.DAY_OF_MONTH, Integer.parseInt(messageEvent.getDay()));
+ viewSwitcher.showPrevious();
+ ((RadialPickerLayout) ((DirectionalLayout) viewSwitcher.getCurrentComponent()).getComponentAt(0)).refresh();
}
@Override
- public void onDismiss(DialogInterface dialog) {
- super.onDismiss(dialog);
+ protected void onDestroy() {
+ super.onDestroy();
+ EventBus.getDefault().unregister(this);
startAtPosition = UNDEFINED_POSITION;
}
@@ -380,15 +557,21 @@ public class SwitchDateTimeDialogFragment extends DialogFragment {
/**
* Assign default year at start
+ *
+ * @param year year
*/
public void setDefaultYear(int year) {
this.dateTimeCalendar.set(Calendar.YEAR, year);
}
/**
+ * setYear
+ *
+ * @param year year
* @deprecated Does not change after launch
* {@link #setDefaultYear(int)}
*/
+
@Deprecated
public void setYear(int year) {
setDefaultYear(year);
@@ -396,15 +579,18 @@ public class SwitchDateTimeDialogFragment extends DialogFragment {
/**
* Assign default month at start (ex: Calendar.DECEMBER)
- * @see Calendar
+ *
+ * @param month month
*/
public void setDefaultMonth(int month) {
this.dateTimeCalendar.set(Calendar.MONTH, month);
}
/**
- * @deprecated Does not change after launch
- * {@link #setDefaultMonth(int)}
+ * setMonth
+ *
+ * @param month month
+ * @deprecated Does not change after launch {@link #setDefaultMonth(int)}
*/
@Deprecated
public void setMonth(int month) {
@@ -413,12 +599,17 @@ public class SwitchDateTimeDialogFragment extends DialogFragment {
/**
* Assign default day at start
+ *
+ * @param day day
*/
public void setDefaultDay(int day) {
this.dateTimeCalendar.set(Calendar.DAY_OF_MONTH, day);
}
/**
+ * setDay
+ *
+ * @param day day
* @deprecated Does not change after launch
* {@link #setDefaultDay(int)}
*/
@@ -429,12 +620,17 @@ public class SwitchDateTimeDialogFragment extends DialogFragment {
/**
* Assign default hour of day (in 24 hours) at start
+ *
+ * @param hourOfDay hourOfDay
*/
public void setDefaultHourOfDay(int hourOfDay) {
this.dateTimeCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
}
/**
+ * hour
+ *
+ * @param hour hour
* @deprecated Does not change after launch and 24 hours format
* {@link #setDefaultHourOfDay(int)}
*/
@@ -445,12 +641,17 @@ public class SwitchDateTimeDialogFragment extends DialogFragment {
/**
* Assign default minute at start
+ *
+ * @param minute minute
*/
public void setDefaultMinute(int minute) {
this.dateTimeCalendar.set(Calendar.MINUTE, minute);
}
/**
+ * setMinute
+ *
+ * @param minute
* @deprecated Does not change after launch
* {@link #setDefaultMinute(int)}
*/
@@ -461,6 +662,8 @@ public class SwitchDateTimeDialogFragment extends DialogFragment {
/**
* Get current year
+ *
+ * @return dateTimeCalendar dateTimeCalendar
*/
public int getYear() {
return this.dateTimeCalendar.get(Calendar.YEAR);
@@ -468,6 +671,7 @@ public class SwitchDateTimeDialogFragment extends DialogFragment {
/**
* Get current month as Calendar.MONTH
+ *
* @see Calendar
*/
public int getMonth() {
@@ -476,6 +680,8 @@ public class SwitchDateTimeDialogFragment extends DialogFragment {
/**
* Get current day
+ *
+ * @return dateTimeCalendar dateTimeCalendar
*/
public int getDay() {
return this.dateTimeCalendar.get(Calendar.DAY_OF_MONTH);
@@ -483,6 +689,8 @@ public class SwitchDateTimeDialogFragment extends DialogFragment {
/**
* Get current hour of day (hour in 24 hours)
+ *
+ * @return dateTimeCalendar dateTimeCalendar
*/
public int getHourOfDay() {
return this.dateTimeCalendar.get(Calendar.HOUR_OF_DAY);
@@ -490,6 +698,8 @@ public class SwitchDateTimeDialogFragment extends DialogFragment {
/**
* Get current minute
+ *
+ * @return dateTimeCalendar dateTimeCalendar
*/
public int getMinute() {
return this.dateTimeCalendar.get(Calendar.MINUTE);
@@ -497,6 +707,8 @@ public class SwitchDateTimeDialogFragment extends DialogFragment {
/**
* Assign default DateTime at start
+ *
+ * @param date date
*/
public void setDefaultDateTime(Date date) {
this.dateTimeCalendar.setTime(date);
@@ -504,6 +716,8 @@ public class SwitchDateTimeDialogFragment extends DialogFragment {
/**
* Assign minimum DateTime who can be selected
+ *
+ * @param date date
*/
public void setMinimumDateTime(Date date) {
this.minimumDateTime.setTime(date);
@@ -511,6 +725,8 @@ public class SwitchDateTimeDialogFragment extends DialogFragment {
/**
* Assign maximum DateTime who can be selected
+ *
+ * @param date date
*/
public void setMaximumDateTime(Date date) {
this.maximumDateTime.setTime(date);
@@ -518,6 +734,8 @@ public class SwitchDateTimeDialogFragment extends DialogFragment {
/**
* Get minimum DateTime who can be selected
+ *
+ * @return minimumDateTime.getTime() Get minimum DateTime who can be selected
*/
public Date getMinimumDateTime() {
return minimumDateTime.getTime();
@@ -525,6 +743,8 @@ public class SwitchDateTimeDialogFragment extends DialogFragment {
/**
* Get maximum DateTime who can be selected
+ *
+ * @return maximumDateTime.getTime() Get maximum DateTime who can be selected
*/
public Date getMaximumDateTime() {
return maximumDateTime.getTime();
@@ -532,6 +752,8 @@ public class SwitchDateTimeDialogFragment extends DialogFragment {
/**
* Return default SimpleDateFormat for Month and Day
+ *
+ * @return Return default SimpleDateFormat for Month and Day
*/
public SimpleDateFormat getSimpleDateMonthAndDayFormat() {
return dayAndMonthSimpleDate;
@@ -539,12 +761,14 @@ public class SwitchDateTimeDialogFragment extends DialogFragment {
/**
* Assign a SimpleDateFormat like "d MMM" to show formatted DateTime
+ *
* @param simpleDateFormat Format to show month and day
+ * @throws SimpleDateMonthAndDayFormatException @throws SimpleDateMonthAndDayFormatException
*/
- public void setSimpleDateMonthAndDayFormat(SimpleDateFormat simpleDateFormat) throws SimpleDateMonthAndDayFormatException{
+ public void setSimpleDateMonthAndDayFormat(SimpleDateFormat simpleDateFormat) throws SimpleDateMonthAndDayFormatException {
Pattern patternMonthAndDay = Pattern.compile("(M|w|W|D|d|F|E|u|\\s)*");
Matcher matcherMonthAndDay = patternMonthAndDay.matcher(simpleDateFormat.toPattern());
- if(!matcherMonthAndDay.matches()) {
+ if (!matcherMonthAndDay.matches()) {
throw new SimpleDateMonthAndDayFormatException(simpleDateFormat.toPattern() + "isn't allowed for " + patternMonthAndDay.pattern());
}
this.dayAndMonthSimpleDate = simpleDateFormat;
@@ -552,6 +776,8 @@ public class SwitchDateTimeDialogFragment extends DialogFragment {
/**
* Define if time must be in 24 hours mode or in 12 hours, must be applied before "show"
+ *
+ * @param is24HoursMode is24HoursMode
*/
public void set24HoursMode(boolean is24HoursMode) {
this.is24HoursMode = is24HoursMode;
@@ -559,25 +785,31 @@ public class SwitchDateTimeDialogFragment extends DialogFragment {
/**
* Highlight AM or PM selected, by default AM or PM selected is not highlight. Only works if 24 hours mode is activated
+ *
* @param highlightAMPMSelection true to visually highlight selected item
*/
public void setHighlightAMPMSelection(boolean highlightAMPMSelection) {
this.highlightAMPMSelection = highlightAMPMSelection;
}
-
+
/**
- * Set timezone different from default
- */
+ * Set timezone different from default
+ *
+ * @param timeZone timeZone
+ */
public void setTimeZone(TimeZone timeZone) {
- if(timeZone != null) {
+ if (timeZone != null) {
this.timeZone = timeZone;
}
}
/**
* Define if the AlertDialog must be styled, must be applied before "show"
+ *
+ * @param styleId styleId
*/
- public void setAlertStyle(@StyleRes int styleId) {
+
+ public void setAlertStyle(int styleId) {
this.alertStyleId = styleId;
}
@@ -594,7 +826,18 @@ public class SwitchDateTimeDialogFragment extends DialogFragment {
* Callback class for assign action on positive and negative button
*/
public interface OnButtonClickListener {
+ /**
+ * onPositiveButtonClick
+ *
+ * @param date date
+ */
void onPositiveButtonClick(Date date);
+
+ /**
+ * onNegativeButtonClick
+ *
+ * @param date date
+ */
void onNegativeButtonClick(Date date);
}
@@ -602,17 +845,26 @@ public class SwitchDateTimeDialogFragment extends DialogFragment {
* Callback class for assign action on positive, negative and neutral button
*/
public interface OnButtonWithNeutralClickListener extends OnButtonClickListener {
+ /**
+ * onNeutralButtonClick
+ *
+ * @param date date
+ */
void onNeutralButtonClick(Date date);
}
/**
* Enumeration of header views
*/
- public enum HeaderViewsPosition {
- VIEW_HOURS_AND_MINUTES(0), VIEW_MONTH_AND_DAY(1), VIEW_YEAR(2);
+ public enum HeaderViewsPosition {VIEW_HOURS_AND_MINUTES(0), VIEW_MONTH_AND_DAY(1), VIEW_YEAR(2);
private int positionSwitch;
+ /**
+ * position
+ *
+ * @param position position
+ */
HeaderViewsPosition(int position) {
this.positionSwitch = position;
}
@@ -625,7 +877,7 @@ public class SwitchDateTimeDialogFragment extends DialogFragment {
/**
* Listener for click on Header element
*/
- public class OnClickHeaderElementListener implements View.OnClickListener{
+ public class OnClickHeaderElementListener implements Component.ClickedListener {
private int positionView;
OnClickHeaderElementListener(int positionView) {
@@ -633,13 +885,16 @@ public class SwitchDateTimeDialogFragment extends DialogFragment {
}
@Override
- public void onClick(View view) {
+ public void onClick(Component view) {
Utils.animLabelElement(view);
- if(viewSwitcher.getDisplayedChild() != positionView)
- viewSwitcher.setDisplayedChild(positionView);
+ if (viewSwitcher.getCurrentIndex() != positionView) {
+ viewSwitcher.setCurrentIndex(positionView);
+ if (viewSwitcher.getCurrentIndex() == 0) {
+ ((RadialPickerLayout) ((DirectionalLayout) viewSwitcher.getCurrentComponent()).getComponentAt(0)).refresh();
+ }
+ }
startAtPosition = positionView;
}
}
}
-
diff --git a/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/Utils.java b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/Utils.java
index 72f1cede5c2786c40ff3c7a78800cafad6a01230..3fcdc9a24876f13792dd155711ad082b0470e32e 100644
--- a/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/Utils.java
+++ b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/Utils.java
@@ -1,50 +1,75 @@
package com.kunzisoft.switchdatetime;
-import android.animation.Keyframe;
-import android.animation.ObjectAnimator;
-import android.animation.PropertyValuesHolder;
-import android.annotation.SuppressLint;
-import android.os.Build;
-import android.view.View;
-import android.view.accessibility.AccessibilityManager;
+import ohos.accessibility.AccessibilitySystemAbilityClient;
+import ohos.agp.animation.Animator;
+import ohos.agp.animation.AnimatorProperty;
+import ohos.agp.components.Component;
+import ohos.agp.window.service.DisplayAttributes;
+import ohos.agp.window.service.DisplayManager;
+import ohos.app.Context;
public class Utils {
private static final int ANIMATION_DELAY = 0;
private static final int PULSE_ANIMATOR_DURATION = 544;
- public static void animLabelElement(View view) {
- ObjectAnimator monthDayAnim = getPulseAnimator(view, 0.9F, 1.05F);
- monthDayAnim.setStartDelay(ANIMATION_DELAY);
+ /**
+ * animLabelElement
+ *
+ * @param component component
+ */
+ public static void animLabelElement(Component component) {
+ AnimatorProperty monthDayAnim = getPulseAnimator(component, 0.9F, 1.05F);
+ monthDayAnim.setDelay(ANIMATION_DELAY);
monthDayAnim.start();
}
- public static ObjectAnimator getPulseAnimator(View labelToAnimate, float decreaseRatio, float increaseRatio) {
- Keyframe k0 = Keyframe.ofFloat(0f, 1f);
- Keyframe k1 = Keyframe.ofFloat(0.275f, decreaseRatio);
- Keyframe k2 = Keyframe.ofFloat(0.69f, increaseRatio);
- Keyframe k3 = Keyframe.ofFloat(1f, 1f);
-
- PropertyValuesHolder scaleX = PropertyValuesHolder.ofKeyframe("scaleX", k0, k1, k2, k3);
- PropertyValuesHolder scaleY = PropertyValuesHolder.ofKeyframe("scaleY", k0, k1, k2, k3);
- ObjectAnimator pulseAnimator = ObjectAnimator.ofPropertyValuesHolder(labelToAnimate, scaleX, scaleY);
- pulseAnimator.setDuration(PULSE_ANIMATOR_DURATION);
+ /**
+ * getPulseAnimator
+ *
+ * @param labelToAnimate labelToAnimate
+ * @param decreaseRatio decreaseRatio
+ * @param increaseRatio increaseRatio
+ * @return pulseAnimator pulseAnimator
+ */
+ public static AnimatorProperty getPulseAnimator(Component labelToAnimate, float decreaseRatio, float increaseRatio) {
+ AnimatorProperty pulseAnimator = new AnimatorProperty(labelToAnimate);
+ pulseAnimator.scaleXFrom(decreaseRatio).scaleYFrom(decreaseRatio).scaleX(1).scaleY(1).setDuration(PULSE_ANIMATOR_DURATION);
+ pulseAnimator.setCurveType(Animator.CurveType.ACCELERATE);
return pulseAnimator;
}
- public static boolean isTouchExplorationEnabled(AccessibilityManager accessibilityManager) {
- return Build.VERSION.SDK_INT >= 14 && accessibilityManager.isTouchExplorationEnabled();
+ /**
+ * 是否触摸
+ *
+ * @param accessibilityManager accessibilityManager
+ * @return accessibilityManager.isAccessibilityCaptionEnabled() accessibilityManager.isAccessibilityCaptionEnabled()
+ */
+ public static boolean isTouchExplorationEnabled(AccessibilitySystemAbilityClient accessibilityManager) {
+ return accessibilityManager.isAccessibilityCaptionEnabled();
}
/**
* Try to speak the specified text, for accessibility. Only available on JB or later.
+ *
* @param text Text to announce.
+ * @param view view
+ */
+ public static void tryAccessibilityAnnounce(Component view, String text) {
+ assert view != null;
+ view.announceAccessibility(text);
+ }
+
+ /**
+ * vp2px
+ *
+ * @param context context
+ * @param vp vp
+ * @return vp2px vp
*/
- @SuppressLint("NewApi")
- public static void tryAccessibilityAnnounce(View view, CharSequence text) {
- if (Build.VERSION.SDK_INT >= 16 && view != null && text != null) {
- view.announceForAccessibility(text);
- }
+ public static int vp2px(Context context, float vp) {
+ DisplayAttributes attributes = DisplayManager.getInstance().getDefaultDisplay(context).get().getAttributes();
+ return (int) (vp * attributes.densityPixels + 0.5f);
}
}
diff --git a/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/date/OnYearSelectedListener.java b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/date/OnYearSelectedListener.java
index b210a423d359ba3a3a59d6de00a360d65b8b6301..974eb481b5c5309d64f3fd830083fe4c12ffaccf 100644
--- a/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/date/OnYearSelectedListener.java
+++ b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/date/OnYearSelectedListener.java
@@ -1,16 +1,18 @@
package com.kunzisoft.switchdatetime.date;
-import android.view.View;
+import ohos.agp.components.Component;
/**
* Listener for select year
+ *
* @author JJamet
*/
public interface OnYearSelectedListener {
/**
* Call when year is selected
+ *
* @param view of event
* @param year selected
*/
- void onYearSelected(View view, int year);
+ void onYearSelected(Component view, int year);
}
diff --git a/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/date/utils/AttrUtils.java b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/date/utils/AttrUtils.java
new file mode 100644
index 0000000000000000000000000000000000000000..92ff9ab8efb760eddbd99c77be974ddd1a36f006
--- /dev/null
+++ b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/date/utils/AttrUtils.java
@@ -0,0 +1,185 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved.
+ *
+ * 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
+ *
+ * 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.kunzisoft.switchdatetime.date.utils;
+
+import ohos.agp.components.AttrSet;
+import ohos.agp.components.element.Element;
+
+/**
+ * get attr value class
+ */
+public class AttrUtils {
+ /**
+ * get the int value from AttrSet
+ *
+ * @param attrs the attrSet
+ * @param name the attrName
+ * @param defaultValue the defaultValue
+ * @return int value
+ */
+ public static int getIntFromAttr(AttrSet attrs, String name, int defaultValue) {
+ int value = defaultValue;
+ try {
+ if (attrs.getAttr(name).isPresent() && attrs.getAttr(name).get() != null) {
+ value = attrs.getAttr(name).get().getIntegerValue();
+ }
+ } catch (Exception e) {
+ return value;
+ }
+ return value;
+ }
+
+ /**
+ * get the float value from AttrSet
+ *
+ * @param attrs the attrSet
+ * @param name the attrName
+ * @param defaultValue the defaultValue
+ * @return float value
+ */
+ public static float getFloatFromAttr(AttrSet attrs, String name, float defaultValue) {
+ float value = defaultValue;
+ try {
+ if (attrs.getAttr(name).isPresent() && attrs.getAttr(name).get() != null) {
+ value = attrs.getAttr(name).get().getFloatValue();
+ }
+ } catch (Exception e) {
+ return value;
+ }
+ return value;
+ }
+
+ /**
+ * get the boolean value from AttrSet
+ *
+ * @param attrs the attrSet
+ * @param name the attrName
+ * @param defaultValue the defaultValue
+ * @return boolean value
+ */
+ public static boolean getBooleanFromAttr(AttrSet attrs, String name, boolean defaultValue) {
+ boolean value = defaultValue;
+ try {
+ if (attrs.getAttr(name).isPresent() && attrs.getAttr(name).get() != null) {
+ value = attrs.getAttr(name).get().getBoolValue();
+ }
+ } catch (Exception e) {
+ return value;
+ }
+ return value;
+ }
+
+ /**
+ * get the long value from AttrSet
+ *
+ * @param attrs the attrSet
+ * @param name the attrName
+ * @param defaultValue the defaultValue
+ * @return long value
+ */
+ public static long getLongFromAttr(AttrSet attrs, String name, long defaultValue) {
+ long value = defaultValue;
+ try {
+ if (attrs.getAttr(name).isPresent() && attrs.getAttr(name).get() != null) {
+ value = attrs.getAttr(name).get().getLongValue();
+ }
+ } catch (Exception e) {
+ return value;
+ }
+ return value;
+ }
+
+ /**
+ * get the color value from AttrSet
+ *
+ * @param attrs the attrSet
+ * @param name the attrName
+ * @param defaultValue the defaultValue
+ * @return int colorValue
+ */
+ public static int getColorFromAttr(AttrSet attrs, String name, int defaultValue) {
+ int value = defaultValue;
+ try {
+ if (attrs.getAttr(name).isPresent() && attrs.getAttr(name).get() != null) {
+ value = attrs.getAttr(name).get().getColorValue().getValue();
+ }
+ } catch (Exception e) {
+ return value;
+ }
+ return value;
+ }
+
+ /**
+ * get the dimensionValue value from AttrSet
+ *
+ * @param attrs the attrSet
+ * @param name the attrName
+ * @param defaultValue the defaultValue
+ * @return int dimensionValue
+ */
+ public static int getDimensionFromAttr(AttrSet attrs, String name, int defaultValue) {
+ int value = defaultValue;
+ try {
+ if (attrs.getAttr(name).isPresent() && attrs.getAttr(name).get() != null) {
+ value = attrs.getAttr(name).get().getDimensionValue();
+ }
+ } catch (Exception e) {
+ return value;
+ }
+ return value;
+ }
+
+ /**
+ * get the String value from AttrSet
+ *
+ * @param attrs the attrSet
+ * @param name the attrName
+ * @param defaultValue the defaultValue
+ * @return String value
+ */
+ public static String getStringFromAttr(AttrSet attrs, String name, String defaultValue) {
+ String value = defaultValue;
+ try {
+ if (attrs.getAttr(name).isPresent() && attrs.getAttr(name).get() != null) {
+ value = attrs.getAttr(name).get().getStringValue();
+ }
+ } catch (Exception e) {
+ return value;
+ }
+ return value;
+ }
+
+ /**
+ * get the Element value from AttrSet
+ *
+ * @param attrs the attrSet
+ * @param name the attrName
+ * @param defaultValue the defaultValue
+ * @return Element value
+ */
+ public static Element getElementFromAttr(AttrSet attrs, String name, Element defaultValue) {
+ Element value = defaultValue;
+ try {
+ if (attrs.getAttr(name).isPresent() && attrs.getAttr(name).get() != null) {
+ value = attrs.getAttr(name).get().getElement();
+ }
+ } catch (Exception e) {
+ return value;
+ }
+ return value;
+ }
+}
diff --git a/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/date/utils/LogUtil.java b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/date/utils/LogUtil.java
new file mode 100644
index 0000000000000000000000000000000000000000..ec7d55cf137e611019146092654df3e08a216b4a
--- /dev/null
+++ b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/date/utils/LogUtil.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved.
+ *
+ * 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
+ *
+ * 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.kunzisoft.switchdatetime.date.utils;
+
+import ohos.hiviewdfx.HiLog;
+import ohos.hiviewdfx.HiLogLabel;
+
+public class LogUtil {
+ private static final HiLogLabel LABEL = new HiLogLabel(HiLog.LOG_APP, 0x00201, "MY_TAG");
+
+ /**
+ * 打印数据信息
+ *
+ * @param value value
+ */
+ public static void d(String value) {
+ HiLog.debug(LABEL, "输出的值: " + value);
+ }
+
+ /**
+ * 打印数据信息
+ *
+ * @param value value
+ */
+ public static void i(String value) {
+ HiLog.info(LABEL, "输出的值: " + value);
+ }
+
+ /**
+ * 打印数据信息
+ *
+ * @param value value
+ */
+ public static void w(String value) {
+ HiLog.warn(LABEL, "输出的值: " + value);
+ }
+
+ /**
+ * 打印数据信息
+ *
+ * @param value value
+ */
+ public static void e(String value) {
+ HiLog.error(LABEL, "输出的值: " + value);
+ }
+}
diff --git a/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/date/widget/ListPickerYearView.java b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/date/widget/ListPickerYearView.java
index b940e8db8f972b3f38a4cfa35ba69f5dd58d32ca..03f1747d6f6b7154026f202e492b989ecc90382c 100644
--- a/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/date/widget/ListPickerYearView.java
+++ b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/date/widget/ListPickerYearView.java
@@ -1,30 +1,26 @@
package com.kunzisoft.switchdatetime.date.widget;
-import android.content.Context;
-import android.content.res.Resources;
-import android.content.res.TypedArray;
-import android.support.v7.widget.LinearLayoutManager;
-import android.support.v7.widget.RecyclerView;
-import android.util.AttributeSet;
-import android.util.Log;
-import android.view.View;
-import android.view.ViewGroup;
-
-import com.kunzisoft.switchdatetime.R;
+import com.kunzisoft.switchdatetime.Utils;
+import com.kunzisoft.switchdatetime.date.utils.AttrUtils;
import com.kunzisoft.switchdatetime.date.OnYearSelectedListener;
+import com.kunzisoft.switchdatetime.date.utils.LogUtil;
+
+import ohos.agp.components.*;
+import ohos.app.Context;
import java.util.ArrayList;
+
/**
* ListView for select one year, year selected is highlight
* To get the year, assign an OnYearSelectedListener
- * @see com.kunzisoft.switchdatetime.date.OnYearSelectedListener#onYearSelected(View, int)
+ *
* @author JJamet
+ * @see OnYearSelectedListener#onYearSelected(Component, int)
*/
-public class ListPickerYearView extends RecyclerView implements YearPickerAdapter.OnClickYearListener{
+public class ListPickerYearView extends ListContainer implements YearPickerAdapter.OnClickYearListener {
private final static String TAG = "ListPickerYearView";
-
private int minYear = 1970;
private int maxYear = 2100;
private int currentYear;
@@ -34,41 +30,52 @@ public class ListPickerYearView extends RecyclerView implements YearPickerAdapte
private int mChildSize;
private int mViewSize;
+ /**
+ * 构造方法
+ *
+ * @param context context
+ */
public ListPickerYearView(Context context) {
this(context, null, 0);
}
- public ListPickerYearView(Context context, AttributeSet attrs) {
+ /**
+ * 构造方法
+ *
+ * @param context context
+ * @param attrs attrs
+ */
+ public ListPickerYearView(Context context, AttrSet attrs) {
this(context, attrs, 0);
}
- public ListPickerYearView(Context context, AttributeSet attrs, int defStyleAttr) {
- super(context, attrs, defStyleAttr);
+ /**
+ * 构造方法
+ *
+ * @param context context
+ * @param attrs attrs
+ * @param defStyleAttr defStyleAttr
+ */
+ public ListPickerYearView(Context context, AttrSet attrs, int defStyleAttr) {
+ super(context, attrs, "");
init(context, attrs);
}
- private void init(Context context, AttributeSet attrs) {
- setLayoutManager(new LinearLayoutManager(context));
+ private void init(Context context, AttrSet attrs) {
+ setLayoutManager(new DirectionalLayoutManager());
- if(attrs != null) {
- TypedArray yearTypedArray = getContext().obtainStyledAttributes(attrs, R.styleable.ListPickerYearView);
- setMinYear(yearTypedArray.getInt(R.styleable.ListPickerYearView_minYear, minYear));
- setMaxYear(yearTypedArray.getInt(R.styleable.ListPickerYearView_maxYear, minYear));
- currentYear = yearTypedArray.getInt(R.styleable.ListPickerYearView_defaultYear, YearPickerAdapter.UNDEFINED);
- yearTypedArray.recycle();
+ if (attrs != null) {
+ setMinYear(AttrUtils.getIntFromAttr(attrs, "minYear", minYear));
+ setMaxYear(AttrUtils.getIntFromAttr(attrs, "maxYear", minYear));
+ currentYear = AttrUtils.getIntFromAttr(attrs, "defaultYear", YearPickerAdapter.UNDEFINED);
}
- setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
-
- Resources resources = context.getResources();
- mViewSize = resources.getDimensionPixelOffset(R.dimen.date_picker_view_animator_height);
- mChildSize = resources.getDimensionPixelOffset(R.dimen.year_label_height);
-
- setVerticalFadingEdgeEnabled(true);
- setFadingEdgeLength(mChildSize / 3);
+ setLayoutConfig(new LayoutConfig(LayoutConfig.MATCH_PARENT, LayoutConfig.MATCH_CONTENT));
- mAdapter = new YearPickerAdapter();
- setAdapter(mAdapter);
+ mViewSize = Utils.vp2px(context, 270);
+ mChildSize = Utils.vp2px(context, 64);
+ mAdapter = new YearPickerAdapter(context);
+ setItemProvider(mAdapter);
mAdapter.setOnClickYearListener(this);
@@ -79,13 +86,13 @@ public class ListPickerYearView extends RecyclerView implements YearPickerAdapte
* Assign years to adapter only if view is init
*/
private void injectYearsInAdapter() {
- if(mAdapter != null) {
+ if (mAdapter != null && minYear <= maxYear) {
ArrayList years = new ArrayList<>();
for (int year = minYear; year <= maxYear; year++) {
years.add(year);
}
mAdapter.setListYears(years);
- mAdapter.notifyDataSetChanged();
+ mAdapter.notifyDataSetItemRangeChanged(0, years.size() - 1);
}
}
@@ -93,46 +100,47 @@ public class ListPickerYearView extends RecyclerView implements YearPickerAdapte
* Refresh list and center on the selected year
*/
public void refreshAndCenter() {
- mAdapter.notifyDataSetChanged();
- centerListOn(currentYear - minYear -1);
+ mAdapter.notifyDataChanged();
+ centerListOn(currentYear - minYear - 1);
}
@Override
- public void onItemYearClick(View view, Integer year, int position) {
+ public void onItemYearClick(Component view, Integer year, int position) {
int positionOldYear = mAdapter.getPositionSelectedYear();
currentYear = year;
-
- // TODO Vibrate
- //mController.tryVibrate();
- if(yearChangeListener != null) {
+ if (yearChangeListener != null) {
yearChangeListener.onYearSelected(view, year);
}
try {
mAdapter.setSelectedYear(currentYear);
} catch (YearPickerAdapter.SelectYearException e) {
- Log.e(TAG, e.getMessage());
+
+ e.fillInStackTrace();
}
- mAdapter.notifyDataSetChanged();
- mAdapter.notifyItemChanged(positionOldYear);
- mAdapter.notifyItemChanged(position);
+ mAdapter.notifyDataChanged();
+ mAdapter.notifyDataSetItemChanged(positionOldYear);
+ mAdapter.notifyDataSetItemChanged(position);
}
/**
* Center list on the selected year
+ *
* @param position of year in the list
*/
public void centerListOn(final int position) {
- getLayoutManager().scrollToPosition(position);
+ scrollTo(position);
try {
- getLayoutManager().scrollVerticallyBy(mViewSize / 2 - mChildSize / 2, null, null);
- } catch(Exception e){
- Log.w(TAG, "Can't scroll more");
+ scrollTo(0, mViewSize / 2 - mChildSize / 2);
+
+ } catch (Exception e) {
+ LogUtil.w("Can't scroll more");
}
}
/**
* Attach listener for select year
+ *
* @param onYearSelectedListener listener
*/
public void setDatePickerListener(OnYearSelectedListener onYearSelectedListener) {
@@ -141,7 +149,8 @@ public class ListPickerYearView extends RecyclerView implements YearPickerAdapte
/**
* Get current minYear
- * @return
+ *
+ * @return minYear minYear
*/
public int getMinYear() {
return minYear;
@@ -149,6 +158,7 @@ public class ListPickerYearView extends RecyclerView implements YearPickerAdapte
/**
* Set minimum year of list
+ *
* @param minYear minimum year
*/
public void setMinYear(int minYear) {
@@ -158,7 +168,8 @@ public class ListPickerYearView extends RecyclerView implements YearPickerAdapte
/**
* Get maximum year of list
- * @return
+ *
+ * @return maxYear maxYear
*/
public int getMaxYear() {
return maxYear;
@@ -166,7 +177,8 @@ public class ListPickerYearView extends RecyclerView implements YearPickerAdapte
/**
* Set maximum year of list
- * @param maxYear
+ *
+ * @param maxYear maxYear
*/
public void setMaxYear(int maxYear) {
this.maxYear = maxYear;
@@ -175,7 +187,8 @@ public class ListPickerYearView extends RecyclerView implements YearPickerAdapte
/**
* Get current year selected
- * @return
+ *
+ * @return currentYear currentYear
*/
public int getYearSelected() {
return currentYear;
@@ -183,15 +196,16 @@ public class ListPickerYearView extends RecyclerView implements YearPickerAdapte
/**
* Assign current year and refresh list
+ *
* @param year
*/
public void assignCurrentYear(int year) {
currentYear = year;
- if(mAdapter != null) {
+ if (mAdapter != null) {
try {
mAdapter.setSelectedYear(currentYear);
} catch (YearPickerAdapter.SelectYearException e) {
- Log.e(TAG, e.getMessage());
+ e.fillInStackTrace();
}
}
refreshAndCenter();
diff --git a/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/date/widget/TextCircularIndicatorView.java b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/date/widget/TextCircularIndicatorView.java
index f6b0458c78465b39a9d39f7be03b02a2f2c9f9d3..284d97886c36e7116d52cfebe38c7bb380dd07f0 100644
--- a/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/date/widget/TextCircularIndicatorView.java
+++ b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/date/widget/TextCircularIndicatorView.java
@@ -1,35 +1,55 @@
+
package com.kunzisoft.switchdatetime.date.widget;
-import android.annotation.SuppressLint;
-import android.content.Context;
-import android.content.res.TypedArray;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.support.annotation.ColorInt;
-import android.support.v7.widget.AppCompatTextView;
-import android.util.AttributeSet;
+import com.kunzisoft.switchdatetime.date.utils.AttrUtils;
-import com.kunzisoft.switchdatetime.R;
+import ohos.agp.components.AttrSet;
+import ohos.agp.components.Component;
+import ohos.agp.components.Text;
+import ohos.agp.render.Canvas;
+import ohos.agp.render.Paint;
+import ohos.agp.utils.Color;
+import ohos.agp.utils.TextAlignment;
+import ohos.app.Context;
/**
* TextView with circular colored background
+ *
* @author JJamet
*/
-public class TextCircularIndicatorView extends AppCompatTextView {
+public class TextCircularIndicatorView extends Text implements Component.DrawTask {
- private int mCircleColor = Color.BLUE;
+ private int mCircleColor = Color.BLUE.getValue();
private Paint mCirclePaint = new Paint();
+ /**
+ * 构造方法
+ *
+ * @param context context
+ */
public TextCircularIndicatorView(Context context) {
- this(context, null, 0);
+ this(context, null, "0");
}
- public TextCircularIndicatorView(Context context, AttributeSet attrs) {
- this(context, attrs, 0);
+ /**
+ * 构造方法
+ *
+ * @param context context
+ * @param attrs attrs
+ */
+ public TextCircularIndicatorView(Context context, AttrSet attrs) {
+ this(context, attrs, "0");
+
}
- public TextCircularIndicatorView(Context context, AttributeSet attrs, int defStyleAttr) {
+ /**
+ * 构造方法
+ *
+ * @param context context
+ * @param attrs attrs
+ * @param defStyleAttr defStyleAttr
+ */
+ public TextCircularIndicatorView(Context context, AttrSet attrs, String defStyleAttr) {
super(context, attrs, defStyleAttr);
init(attrs);
}
@@ -37,38 +57,35 @@ public class TextCircularIndicatorView extends AppCompatTextView {
/**
* Initialize constructor
*/
- private void init(AttributeSet attrs) {
-
- if(attrs != null) {
- TypedArray circularIndicatorTypedArray = getContext().obtainStyledAttributes(attrs, R.styleable.TextCircularIndicatorView);
- setCircleColor(circularIndicatorTypedArray.getColor(R.styleable.TextCircularIndicatorView_colorCircleIndicator, mCircleColor));
- circularIndicatorTypedArray.recycle();
+ private void init(AttrSet attrs) {
+ if (attrs != null) {
+ setCircleColor(AttrUtils.getColorFromAttr(attrs, "colorCircleIndicator", mCircleColor));
}
mCirclePaint.setFakeBoldText(true);
mCirclePaint.setAntiAlias(true);
- mCirclePaint.setColor(mCircleColor);
- mCirclePaint.setTextAlign(Paint.Align.CENTER);
- mCirclePaint.setStyle(Paint.Style.FILL);
+ mCirclePaint.setColor(new Color(mCircleColor));
+ mCirclePaint.setTextAlign(TextAlignment.CENTER);
+ mCirclePaint.setStyle(Paint.Style.FILL_STYLE);
}
- @SuppressLint("GetContentDescriptionOverride")
@Override
- public CharSequence getContentDescription() {
+ public CharSequence getComponentDescription() {
return getText();
}
@Override
- public void onDraw(Canvas canvas) {
+ public void onDraw(Component component, Canvas canvas) {
int width = getWidth();
int height = getHeight();
int radius = Math.min(width, height) / 2;
canvas.drawCircle(width / 2, height / 2, radius, mCirclePaint);
- super.onDraw(canvas);
}
/**
* Get color of background circle
+ *
+ * @return mCircleColor mCircleColor
*/
public int getCircleColor() {
return mCircleColor;
@@ -76,9 +93,17 @@ public class TextCircularIndicatorView extends AppCompatTextView {
/**
* Set color of background circle
+ *
+ * @param color color
*/
- public void setCircleColor(@ColorInt int color) {
+ public void setCircleColor(int color) {
this.mCircleColor = color;
}
-}
\ No newline at end of file
+ /**
+ * setIndicator setIndicator
+ */
+ public void setIndicator() {
+ addDrawTask(this, 1);
+ }
+}
diff --git a/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/date/widget/YearPickerAdapter.java b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/date/widget/YearPickerAdapter.java
index ee97d005270c78bfacb921eac6786a6cf7d295e3..3158f5d01c28abc8d0b51c540f46de5f160b97a5 100644
--- a/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/date/widget/YearPickerAdapter.java
+++ b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/date/widget/YearPickerAdapter.java
@@ -1,12 +1,10 @@
package com.kunzisoft.switchdatetime.date.widget;
-import android.support.v7.widget.RecyclerView;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.TextView;
+import com.kunzisoft.switchdatetime.ResourceTable;
-import com.kunzisoft.switchdatetime.R;
+import ohos.agp.components.*;
+import ohos.agp.utils.Color;
+import ohos.app.Context;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -16,78 +14,98 @@ import java.util.Locale;
/**
* Adapter for manage elements of ListPickerYearView
+ *
* @author JJamet
*/
-class YearPickerAdapter extends RecyclerView.Adapter {
+class YearPickerAdapter extends BaseItemProvider {
private static final int LIST_ITEM_TYPE_STANDARD = 0;
private static final int LIST_ITEM_TYPE_INDICATOR = 1;
-
public static final int UNDEFINED = -1;
-
private SimpleDateFormat yearFormat;
private Calendar calendar;
private List listYears;
private Integer selectedYear;
private int positionSelectedYear;
+ private int oldSelectedPosition = -1;
private OnClickYearListener onClickYearListener;
+ private Context mContext;
/**
* Initialize adapter with list of years and element selected
+ *
+ * @param context 上下文
*/
- YearPickerAdapter() {
+ YearPickerAdapter(Context context) {
this.listYears = new ArrayList<>();
this.selectedYear = UNDEFINED;
this.yearFormat = new SimpleDateFormat("yyyy", Locale.getDefault());
this.calendar = Calendar.getInstance();
+ this.mContext = context;
}
@Override
- public long getItemId(int i) {
- return listYears.get(i);
+ public int getCount() {
+ return listYears.size();
}
@Override
- public int getItemCount() {
- return listYears.size();
+ public Object getItem(int i) {
+ return listYears.get(i);
}
@Override
- public TextIndicatorViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
- switch (viewType) {
- default:
- case LIST_ITEM_TYPE_STANDARD:
- return new TextIndicatorViewHolder(
- LayoutInflater.from(parent.getContext()).inflate(R.layout.year_text, parent, false));
- case LIST_ITEM_TYPE_INDICATOR:
- return new TextIndicatorViewHolder(
- LayoutInflater.from(parent.getContext()).inflate(R.layout.year_text_indicator, parent, false));
- }
+ public long getItemId(int i) {
+ return listYears.get(i);
}
@Override
- public void onBindViewHolder(TextIndicatorViewHolder holder, int position) {
- Integer currentYear = listYears.get(position);
+ public Component getComponent(int i, Component component, ComponentContainer componentContainer) {
+ Integer currentYear = listYears.get(i);
+ TextIndicatorViewHolder holder;
+
+ if (component == null || oldSelectedPosition == i || positionSelectedYear == i) {
+ component = LayoutScatter.getInstance(mContext).parse(ResourceTable.Layout_year_text, null, false);
+ holder = new TextIndicatorViewHolder(component);
+ component.setTag(holder);
+ } else {
+ holder = (TextIndicatorViewHolder) component.getTag();
+ }
calendar.set(Calendar.YEAR, currentYear);
holder.textView.setText(yearFormat.format(calendar.getTime()));
- if(onClickYearListener != null)
- holder.container.setOnClickListener(new BufferYearClickListener(currentYear, position));
+ int viewType = getItemComponentType(i);
+ switch (viewType) {
+ case LIST_ITEM_TYPE_INDICATOR:
+ holder.textView.setIndicator();
+ holder.textView.setTextColor(Color.WHITE);
+ break;
+ default:
+ holder.textView.setTextColor(new Color(mContext.getColor(ResourceTable.Color_textColorDefault)));
+ break;
+ }
+
+ if (onClickYearListener != null) {
+ holder.container.setClickedListener(new BufferYearClickListener(currentYear, i));
+ }
+ return component;
}
@Override
- public int getItemViewType(int position) {
- if(listYears.get(position).equals(selectedYear))
+ public int getItemComponentType(int position) {
+ if (listYears.get(position).equals(selectedYear)) {
return LIST_ITEM_TYPE_INDICATOR;
- else
+ } else {
return LIST_ITEM_TYPE_STANDARD;
+ }
}
/**
* Get the list of years
+ *
* @return years
*/
public List getListYears() {
@@ -96,6 +114,7 @@ class YearPickerAdapter extends RecyclerView.Adapter listYears) {
@@ -111,13 +130,18 @@ class YearPickerAdapter extends RecyclerView.Adapter listYears) {
super("Year selected " + yearSelected + " must be in list of years : " + listYears);
diff --git a/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/event/MessageEvent.java b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/event/MessageEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..0a9f65fa5da154dd3434d7029d4e9d0101969bb2
--- /dev/null
+++ b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/event/MessageEvent.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved.
+ *
+ * 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
+ *
+ * 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.kunzisoft.switchdatetime.event;
+
+public class MessageEvent {
+ private String day;
+ public static String month = "";
+
+ /**
+ * 构造方法
+ *
+ * @param day day
+ */
+ public MessageEvent(String day) {
+ this.day = day;
+
+ }
+
+ public String getDay() {
+ return day;
+ }
+
+ public void setDay(String day) {
+ this.day = day;
+ }
+}
diff --git a/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/provider/CalendarProvider.java b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/provider/CalendarProvider.java
new file mode 100644
index 0000000000000000000000000000000000000000..c7f23dd90220b108eeec2b85f7dd2dbcc7da8285
--- /dev/null
+++ b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/provider/CalendarProvider.java
@@ -0,0 +1,194 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved.
+ *
+ * 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
+ *
+ * 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.kunzisoft.switchdatetime.provider;
+
+
+import com.kunzisoft.switchdatetime.ResourceTable;
+import com.kunzisoft.switchdatetime.event.MessageEvent;
+
+import ohos.agp.components.*;
+import ohos.agp.utils.Color;
+import ohos.app.Context;
+
+import org.greenrobot.eventbus.EventBus;
+
+
+import java.util.Calendar;
+
+
+public class CalendarProvider extends BaseItemProvider {
+ private Context context;
+ private Calendar calendar;
+ private int current_month = 0;
+ private int original_year;
+ private int original_month;
+ private int original_day;
+ private int year;
+ private int month;
+ private int day;
+ private int dayOfWeek;
+ private int firstWeekOffset = 0;
+ private int offset = 0;
+ private ViewHolder viewHolder = null;
+ private DependentLayout lastview = null;
+ private boolean isCk = true;
+ private boolean isCurrentMonth;
+
+ /**
+ * 构造方法
+ *
+ * @param context context
+ * @param calendar calendar
+ */
+ public CalendarProvider(Context context, Calendar calendar) {
+ this.context = context;
+ this.calendar = calendar;
+ original_year = calendar.get(Calendar.YEAR);
+ original_month = calendar.get(Calendar.MONTH);
+ original_day = calendar.get(Calendar.DAY_OF_MONTH);
+ current_month = calendar.get(Calendar.MONTH);
+ int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
+ firstWeekOffset = Calendar.SATURDAY - dayOfWeek + 1;
+ offset = firstWeekOffset - 7;
+ }
+
+ @Override
+ public int getCount() {
+ return 49;
+ }
+
+ @Override
+ public Object getItem(int i) {
+ return null;
+ }
+
+ @Override
+ public long getItemId(int i) {
+ return 0;
+ }
+
+ @Override
+ public Component getComponent(int position, Component componentP, ComponentContainer componentContainer) {
+ Component component = componentP;
+ if (component == null) {
+ component = LayoutScatter.getInstance(context)
+ .parse(ResourceTable.Layout_calendar_item_layout, null, false);
+ viewHolder = new ViewHolder();
+ component.setTag(viewHolder);
+ } else {
+ if (component.getTag() instanceof ViewHolder) {
+ viewHolder = (ViewHolder) component.getTag();
+ }
+ }
+ if (viewHolder != null) {
+ viewHolder.item_root = (DependentLayout) component.findComponentById(ResourceTable.Id_item_root);
+ viewHolder.item_text = (Text) component.findComponentById(ResourceTable.Id_item_text);
+ viewHolder.item_background = (Image) component.findComponentById(ResourceTable.Id_item_background);
+ setData(position, viewHolder);
+ viewHolder.item_root.setClickedListener(new Component.ClickedListener() {
+ @Override
+ public void onClick(Component component) {
+
+ if (position < 7) {
+ return;
+ }
+ if (lastview == null) {
+ lastview = (DependentLayout) component;
+ }
+ clearBackground(lastview);
+ Image image = (Image) component.findComponentById(ResourceTable.Id_item_background);
+ image.setVisibility(Component.VISIBLE);
+ Text item_text = (Text) component.findComponentById(ResourceTable.Id_item_text);
+ item_text.setTextColor(Color.WHITE);
+ lastview = (DependentLayout) component;
+ EventBus.getDefault().post(new MessageEvent(item_text.getText()));
+ }
+ });
+ }
+ return component;
+ }
+
+ class ViewHolder {
+ private DependentLayout item_root;
+ private Text item_text;
+ private Image item_background;
+ }
+
+ private void setData(int position, ViewHolder viewHolder) {
+ switch (position) {
+ case 0:
+ viewHolder.item_text.setText("周日");
+
+ break;
+ case 1:
+ viewHolder.item_text.setText("周一");
+ break;
+ case 2:
+ viewHolder.item_text.setText("周二");
+ break;
+ case 3:
+ viewHolder.item_text.setText("周三");
+ break;
+ case 4:
+ viewHolder.item_text.setText("周四");
+ break;
+ case 5:
+ viewHolder.item_text.setText("周五");
+ break;
+ case 6:
+ viewHolder.item_text.setText("周六");
+ break;
+ default:
+ break;
+ }
+ if (position < 7) {
+ return;
+ }
+ resetCalendar();
+ calendar.add(Calendar.DAY_OF_YEAR, offset);
+ offset++;
+ year = calendar.get(Calendar.YEAR);
+ month = calendar.get(Calendar.MONTH);
+ dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
+ day = calendar.get(Calendar.DAY_OF_MONTH);
+ isCurrentMonth = isCurrentMonth(month);
+ viewHolder.item_text.setText(String.valueOf(day));
+
+
+ if (!isCurrentMonth) {
+ viewHolder.item_text.setTextColor(Color.GRAY);
+ viewHolder.item_root.setEnabled(false);
+ } else {
+ viewHolder.item_root.setEnabled(true);
+ }
+ }
+
+ private void resetCalendar() {
+ calendar.set(original_year, original_month, original_day);
+ }
+
+ private boolean isCurrentMonth(int month) {
+ return current_month == month;
+ }
+
+ private void clearBackground(DependentLayout lastview) {
+ Image image = (Image) lastview.findComponentById(ResourceTable.Id_item_background);
+ image.setVisibility(Component.HIDE);
+ Text item_text = (Text) lastview.findComponentById(ResourceTable.Id_item_text);
+ item_text.setTextColor(Color.BLACK);
+ }
+}
\ No newline at end of file
diff --git a/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/provider/PageProvider.java b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/provider/PageProvider.java
new file mode 100644
index 0000000000000000000000000000000000000000..6778e23707ea1cc1c80fa7e00f7d732dfb81fb5c
--- /dev/null
+++ b/switchdatetime/src/main/java/com/kunzisoft/switchdatetime/provider/PageProvider.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved.
+ *
+ * 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
+ *