├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── values
│ │ │ │ ├── dimen.xml
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ └── layout
│ │ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── fantasy
│ │ │ └── doubledatepickerdemo
│ │ │ └── MainActivity.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── fantasy
│ │ │ └── doubledatepickerdemo
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── fantasy
│ │ └── doubledatepickerdemo
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── doubledatepicker
├── .gitignore
├── src
│ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── res
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── end_time_bg.png
│ │ │ │ └── begin_time_bg.png
│ │ │ ├── values
│ │ │ │ ├── dimen.xml
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── anim
│ │ │ │ ├── popwindow_enter.xml
│ │ │ │ └── popwindow_exit.xml
│ │ │ ├── drawable
│ │ │ │ ├── btn_selector.xml
│ │ │ │ ├── wheel_val.xml
│ │ │ │ └── ic_launcher_background.xml
│ │ │ └── layout
│ │ │ │ ├── popwindow_bottom_layout.xml
│ │ │ │ └── data_time_layout.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── fantasy
│ │ │ └── doubledatepicker
│ │ │ ├── OnWheelScrollListener.java
│ │ │ ├── OnWheelChangedListener.java
│ │ │ ├── WheelAdapter.java
│ │ │ ├── NumericWheelAdapter.java
│ │ │ ├── TimeUtil.java
│ │ │ ├── DoubleDateSelectDialog.java
│ │ │ └── WheelView.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── fantasy
│ │ │ └── doubledatepicker
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── fantasy
│ │ └── doubledatepicker
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .idea
├── encodings.xml
├── vcs.xml
├── modules.xml
├── runConfigurations.xml
└── misc.xml
├── gradle.properties
├── .gitignore
├── README.md
├── gradlew.bat
├── gradlew
└── LICENSE
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/doubledatepicker/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':doubledatepicker'
2 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darrenfantasy/DoubleDatePicker/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darrenfantasy/DoubleDatePicker/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darrenfantasy/DoubleDatePicker/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darrenfantasy/DoubleDatePicker/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darrenfantasy/DoubleDatePicker/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darrenfantasy/DoubleDatePicker/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darrenfantasy/DoubleDatePicker/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darrenfantasy/DoubleDatePicker/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darrenfantasy/DoubleDatePicker/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/doubledatepicker/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darrenfantasy/DoubleDatePicker/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darrenfantasy/DoubleDatePicker/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/doubledatepicker/src/main/res/mipmap-xhdpi/end_time_bg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darrenfantasy/DoubleDatePicker/HEAD/doubledatepicker/src/main/res/mipmap-xhdpi/end_time_bg.png
--------------------------------------------------------------------------------
/doubledatepicker/src/main/res/mipmap-xhdpi/begin_time_bg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darrenfantasy/DoubleDatePicker/HEAD/doubledatepicker/src/main/res/mipmap-xhdpi/begin_time_bg.png
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimen.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 17sp
4 |
5 | 3dp
6 | 16sp
7 |
--------------------------------------------------------------------------------
/doubledatepicker/src/main/res/values/dimen.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 17sp
4 |
5 | 3dp
6 | 16sp
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Jan 20 16:01:00 CST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/doubledatepicker/src/main/res/anim/popwindow_enter.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
--------------------------------------------------------------------------------
/doubledatepicker/src/main/res/anim/popwindow_exit.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/doubledatepicker/src/main/res/drawable/btn_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | DoubleDatePicker
3 |
4 | 确 认
5 | 取 消
6 |
7 |
8 | 请选择日期
9 |
10 | 开始于\n
11 | 结束于\n
12 |
13 | 开始时间不能大于结束时间
14 |
15 |
--------------------------------------------------------------------------------
/doubledatepicker/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | DoubleDatePicker
3 | 确 认
4 | 取 消
5 |
6 |
7 | 请选择日期
8 |
9 | 开始于\n
10 | 结束于\n
11 |
12 | 开始时间不能大于结束时间
13 |
14 |
--------------------------------------------------------------------------------
/app/src/test/java/com/fantasy/doubledatepickerdemo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.fantasy.doubledatepickerdemo;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/doubledatepicker/src/test/java/com/fantasy/doubledatepicker/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.fantasy.doubledatepicker;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 | #efefef
8 | #333333
9 | #45a2ff
10 | #ffffff
11 | #999999
12 | #7eb3ff
13 |
14 |
15 |
--------------------------------------------------------------------------------
/doubledatepicker/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 | #efefef
8 | #333333
9 | #45a2ff
10 | #ffffff
11 | #999999
12 | #7eb3ff
13 |
14 |
15 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/doubledatepicker/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/fantasy/doubledatepickerdemo/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.fantasy.doubledatepickerdemo;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.fantasy.doubledatepicker", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/doubledatepicker/src/androidTest/java/com/fantasy/doubledatepicker/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.fantasy.doubledatepicker;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.fantasy.doubledatepicker.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/doubledatepicker/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 26
5 |
6 |
7 |
8 | defaultConfig {
9 | minSdkVersion 15
10 | targetSdkVersion 26
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 |
16 | }
17 |
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 |
25 | }
26 |
27 | dependencies {
28 | implementation fileTree(dir: 'libs', include: ['*.jar'])
29 |
30 | implementation 'com.android.support:appcompat-v7:26.1.0'
31 | testImplementation 'junit:junit:4.12'
32 | androidTestImplementation 'com.android.support.test:runner:1.0.1'
33 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
34 | }
35 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # Intellij
36 | *.iml
37 | .idea/workspace.xml
38 | .idea/tasks.xml
39 | .idea/gradle.xml
40 | .idea/dictionaries
41 | .idea/libraries
42 |
43 | # Keystore files
44 | *.jks
45 |
46 | # External native build folder generated in Android Studio 2.2 and later
47 | .externalNativeBuild
48 |
49 | # Google Services (e.g. APIs or Firebase)
50 | google-services.json
51 |
52 | # Freeline
53 | freeline.py
54 | freeline/
55 | freeline_project_description.json
56 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | defaultConfig {
6 | applicationId "com.fantasy.doubledatepicker"
7 | minSdkVersion 15
8 | targetSdkVersion 26
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(dir: 'libs', include: ['*.jar'])
23 | implementation 'com.android.support:appcompat-v7:26.1.0'
24 | implementation 'com.android.support.constraint:constraint-layout:1.0.2'
25 | testImplementation 'junit:junit:4.12'
26 | androidTestImplementation 'com.android.support.test:runner:1.0.1'
27 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
28 | compile project(path: ':doubledatepicker')
29 | }
30 |
--------------------------------------------------------------------------------
/doubledatepicker/src/main/java/com/fantasy/doubledatepicker/OnWheelScrollListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Yuri Kanivets
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.fantasy.doubledatepicker;
18 |
19 | /**
20 | * Wheel scrolled listener interface.
21 | */
22 | public interface OnWheelScrollListener {
23 | /**
24 | * Callback method to be invoked when scrolling started.
25 | * @param wheel the wheel view whose state has changed.
26 | */
27 | void onScrollingStarted(WheelView wheel);
28 |
29 | /**
30 | * Callback method to be invoked when scrolling ended.
31 | * @param wheel the wheel view whose state has changed.
32 | */
33 | void onScrollingFinished(WheelView wheel);
34 | }
35 |
--------------------------------------------------------------------------------
/doubledatepicker/src/main/res/drawable/wheel_val.xml:
--------------------------------------------------------------------------------
1 |
2 |
19 |
20 |
21 |
22 |
27 |
28 |
31 |
--------------------------------------------------------------------------------
/doubledatepicker/src/main/java/com/fantasy/doubledatepicker/OnWheelChangedListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Yuri Kanivets
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.fantasy.doubledatepicker;
18 |
19 | /**
20 | * Wheel changed listener interface.
21 | *
The currentItemChanged() method is called whenever current wheel positions is changed:
22 | *
New Wheel position is set
23 | * Wheel view is scrolled
24 | */
25 | public interface OnWheelChangedListener {
26 | /**
27 | * Callback method to be invoked when current item changed
28 | * @param wheel the wheel view whose state has changed
29 | * @param oldValue the old value of current item
30 | * @param newValue the new value of current item
31 | */
32 | void onChanged(WheelView wheel, int oldValue, int newValue);
33 | }
34 |
--------------------------------------------------------------------------------
/doubledatepicker/src/main/java/com/fantasy/doubledatepicker/WheelAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Yuri Kanivets
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.fantasy.doubledatepicker;
18 |
19 | public interface WheelAdapter {
20 | /**
21 | * Gets items count
22 | * @return the count of wheel items
23 | */
24 | public int getItemsCount();
25 |
26 | /**
27 | * Gets a wheel item by index.
28 | *
29 | * @param index the item index
30 | * @return the wheel item text or null
31 | */
32 | public String getItem(int index);
33 |
34 | /**
35 | * Gets maximum item length. It is used to determine the wheel width.
36 | * If -1 is returned there will be used the default wheel width.
37 | *
38 | * @return the maximum item length or -1
39 | */
40 | public int getMaximumLength();
41 | }
42 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # DoubleDatePicker
2 | ### 安卓双日期选择器,可以选择开始日期和结束日期。
3 |
4 | 
5 |
6 |
7 |
8 | 
9 |
10 | ### How to
11 |
12 | **Step 1.** Add the JitPack repository to your build file
13 |
14 | Add it in your root build.gradle at the end of repositories:
15 |
16 | ```
17 | allprojects {
18 | repositories {
19 | ...
20 | maven { url 'https://jitpack.io' }
21 | }
22 | }
23 | ```
24 |
25 | **Step 2.** Add the dependency
26 |
27 | ```
28 | dependencies {
29 | compile 'com.github.darrenfantasy:DoubleDatePicker:1.0'
30 | }
31 | ```
32 |
33 | **Step 3.** API
34 |
35 | ```
36 | /**
37 | * @param context
38 | * @param allowedSmallestDate 日期选择器的起始日期
39 | * @param allowedBiggestDate 日期选择器的终止日期
40 | */
41 | public DoubleDateSelectDialog(Context context, String allowedSmallestDate, String allowedBiggestDate)
42 | ```
43 |
44 | ```
45 | /**
46 | *
47 | * @param context
48 | * @param allowedSmallestDate 日期选择器的起始日期
49 | * @param allowedBiggestDate 日期选择器的终止日期
50 | * @param defaultChooseDate 日期选择器默认选择日期
51 | */
52 | public DoubleDateSelectDialog(Context context, String allowedSmallestDate, String allowedBiggestDate, String defaultChooseDate)
53 | ```
54 |
55 | ```
56 | /**
57 | * set监听
58 | *
59 | * @param onDateSelectFinished 完成监听
60 | */
61 | public void setOnDateSelectFinished(OnDateSelectFinished onDateSelectFinished)
62 | ```
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
20 |
21 |
26 |
27 |
32 |
33 |
39 |
40 |
41 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/doubledatepicker/src/main/res/layout/popwindow_bottom_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
22 |
23 |
33 |
34 |
35 |
40 |
41 |
49 |
50 |
58 |
59 |
60 |
61 |
65 |
66 |
69 |
70 |
71 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/java/com/fantasy/doubledatepickerdemo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.fantasy.doubledatepickerdemo;
2 |
3 | import android.content.DialogInterface;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.os.Bundle;
6 | import android.view.View;
7 | import android.widget.Button;
8 | import android.widget.TextView;
9 |
10 | import com.fantasy.doubledatepicker.DoubleDateSelectDialog;
11 |
12 | /**
13 | * Created by darrenfantasy on 2018/01/20.
14 | */
15 | public class MainActivity extends AppCompatActivity {
16 | private Button mShowDatePickBtn;
17 | private DoubleDateSelectDialog mDoubleTimeSelectDialog;
18 | private TextView allowedSmallestTimeText, allowedBiggestTimeText, defaultChooseDateText;
19 | private String allowedSmallestTime, allowedBiggestTime, defaultChooseDate;
20 |
21 | @Override
22 | protected void onCreate(Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | setContentView(R.layout.activity_main);
25 | mShowDatePickBtn = findViewById(R.id.show_date_pick_btn);
26 | allowedSmallestTimeText = findViewById(R.id.allowedSmallestTimeText);
27 | allowedBiggestTimeText = findViewById(R.id.allowedBiggestTimeText);
28 | defaultChooseDateText = findViewById(R.id.defaultChooseDateText);
29 | allowedSmallestTime = "2017-11-12";
30 | allowedBiggestTime = "2018-02-11";
31 | defaultChooseDate = "2018-01-18";
32 | allowedSmallestTimeText.setText("起始日期: "+allowedSmallestTime);
33 | allowedBiggestTimeText.setText("结束日期: "+allowedBiggestTime);
34 | defaultChooseDateText.setText("默认选中日期: "+defaultChooseDate);
35 | mShowDatePickBtn.setOnClickListener(new View.OnClickListener() {
36 | @Override
37 | public void onClick(View v) {
38 | showCustomTimePicker();
39 | }
40 | });
41 | }
42 |
43 | public void showCustomTimePicker() {
44 |
45 | if (mDoubleTimeSelectDialog == null) {
46 | mDoubleTimeSelectDialog = new DoubleDateSelectDialog(this, allowedSmallestTime, allowedBiggestTime, defaultChooseDate);
47 | mDoubleTimeSelectDialog.setOnDateSelectFinished(new DoubleDateSelectDialog.OnDateSelectFinished() {
48 | @Override
49 | public void onSelectFinished(String startTime, String endTime) {
50 | mShowDatePickBtn.setText(startTime.replace("-", ".") + "至\n" + endTime.replace("-", "."));
51 |
52 | }
53 | });
54 |
55 | mDoubleTimeSelectDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
56 | @Override
57 | public void onDismiss(DialogInterface dialog) {
58 | }
59 | });
60 | }
61 | if (!mDoubleTimeSelectDialog.isShowing()) {
62 | mDoubleTimeSelectDialog.show();
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
27 |
28 |
32 |
33 |
46 |
47 |
58 |
59 |
--------------------------------------------------------------------------------
/doubledatepicker/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
27 |
28 |
32 |
33 |
46 |
47 |
58 |
59 |
--------------------------------------------------------------------------------
/doubledatepicker/src/main/java/com/fantasy/doubledatepicker/NumericWheelAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 Yuri Kanivets
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.fantasy.doubledatepicker;
18 |
19 |
20 | public class NumericWheelAdapter implements WheelAdapter {
21 |
22 | /**
23 | * The default min value
24 | */
25 | public static final int DEFAULT_MAX_VALUE = 9;
26 |
27 | /**
28 | * The default max value
29 | */
30 | private static final int DEFAULT_MIN_VALUE = 0;
31 |
32 | // Values
33 | private int minValue;
34 | private int maxValue;
35 |
36 | // format
37 | private String format;
38 |
39 | /**
40 | * Default constructor
41 | */
42 | public NumericWheelAdapter() {
43 | this(DEFAULT_MIN_VALUE, DEFAULT_MAX_VALUE);
44 | }
45 |
46 | /**
47 | * Constructor
48 | *
49 | * @param minValue the wheel min value
50 | * @param maxValue the wheel max value
51 | */
52 | public NumericWheelAdapter(int minValue, int maxValue) {
53 | this(minValue, maxValue, null);
54 | }
55 |
56 | /**
57 | * Constructor
58 | *
59 | * @param minValue the wheel min value
60 | * @param maxValue the wheel max value
61 | * @param format the format string
62 | */
63 | public NumericWheelAdapter(int minValue, int maxValue, String format) {
64 | this.minValue = minValue;
65 | this.maxValue = maxValue;
66 | this.format = format;
67 | }
68 |
69 | @Override
70 | public String getItem(int index) {
71 | if (index >= 0 && index < getItemsCount()) {
72 | int value = minValue + index;
73 | return format != null ? String.format(format, value) : Integer.toString(value);
74 | }
75 | return null;
76 | }
77 |
78 | @Override
79 | public int getItemsCount() {
80 | return maxValue - minValue + 1;
81 | }
82 |
83 | @Override
84 | public int getMaximumLength() {
85 | int max = Math.max(Math.abs(maxValue), Math.abs(minValue));
86 | int maxLen = format != null ? Integer.toString(max).length() + format.length() : Integer.toString(max).length();
87 | if (minValue < 0) {
88 | maxLen++;
89 | }
90 | return maxLen;
91 | }
92 |
93 | public int getmaxValue() {
94 | return maxValue;
95 | }
96 |
97 | public int getMinValue() {
98 | return minValue;
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/doubledatepicker/src/main/res/layout/data_time_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
16 |
17 |
23 |
24 |
28 |
29 |
34 |
35 |
41 |
42 |
47 |
48 |
53 |
54 |
60 |
61 |
66 |
67 |
72 |
73 |
79 |
80 |
85 |
86 |
91 |
92 |
98 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/doubledatepicker/src/main/java/com/fantasy/doubledatepicker/TimeUtil.java:
--------------------------------------------------------------------------------
1 | package com.fantasy.doubledatepicker;
2 |
3 | import android.support.annotation.NonNull;
4 |
5 | import java.text.ParseException;
6 | import java.text.SimpleDateFormat;
7 | import java.util.Calendar;
8 | import java.util.Date;
9 | import java.util.Locale;
10 |
11 | /**
12 | * Created by darrenfantasy on 2018/01/20.
13 | */
14 |
15 | public class TimeUtil {
16 |
17 | /**
18 | * 重一种模式,转换为另一种模式
19 | *
20 | * @param str
21 | * @param oldFormat 旧模式
22 | * @param newFormat 新模式
23 | * @return
24 | */
25 | public static String formatTime(@NonNull String str, @NonNull String oldFormat,
26 | @NonNull String newFormat) {
27 | if (str == null || oldFormat == null || newFormat == null) {
28 | return null;
29 | }
30 | SimpleDateFormat oldSDF = new SimpleDateFormat(oldFormat);
31 | SimpleDateFormat newSDF = new SimpleDateFormat(newFormat);
32 | String formatTime = null;
33 | try {
34 | Date oldD = oldSDF.parse(str);
35 | formatTime = newSDF.format(oldD);
36 | } catch (ParseException e) {
37 | e.printStackTrace();
38 | }
39 | return formatTime;
40 | }
41 |
42 | /**
43 | * 获取系统当前时间
44 | *
45 | * @return curTime
46 | */
47 | public static String getCurTime() {
48 | SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
49 | Date curDate = new Date(System.currentTimeMillis());//获取当前时间
50 | String curTime = formatter.format(curDate);
51 | return curTime;
52 | }
53 |
54 | /**
55 | * 获取系统当前日期
56 | *
57 | * @return curData
58 | */
59 | public static String getCurData() {
60 | SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
61 | Date curDate = new Date(System.currentTimeMillis());//获取当前时间
62 | String curData = formatter.format(curDate);
63 | return curData;
64 | }
65 |
66 | /**
67 | * 获取系统当前日期
68 | *
69 | * @return curData
70 | */
71 | public static String getCurData1() {
72 | SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
73 | Date curDate = new Date(System.currentTimeMillis());//获取当前时间
74 | String curData = formatter.format(curDate);
75 | return curData;
76 | }
77 |
78 | /**
79 | * 获取系统当前日期
80 | *
81 | * @return curData
82 | */
83 | public static String getCurData2() {
84 | SimpleDateFormat formatter = new SimpleDateFormat("yyyyMM");
85 | Date curDate = new Date(System.currentTimeMillis());//获取当前时间
86 | String curData = formatter.format(curDate);
87 | return curData;
88 | }
89 |
90 | public static String getCurData3() {
91 | SimpleDateFormat formatter = new SimpleDateFormat("yyyy");
92 | Date curDate = new Date(System.currentTimeMillis());//获取当前时间
93 | String curData = formatter.format(curDate);
94 | return curData;
95 | }
96 |
97 | public static int getCurrentHour() {
98 | Calendar calendar = Calendar.getInstance(Locale.CHINA);
99 | //创建一个日历引用d,通过静态方法getInstance() 从指定时区 Locale.CHINA 获得一个日期实例
100 | Date myDate = new Date();
101 | //创建一个Date实例
102 | calendar.setTime(myDate);
103 | //设置日历的时间,把一个新建Date实例myDate传入
104 | int hour = calendar.get(Calendar.HOUR);
105 | return hour;
106 | }
107 |
108 | public static int getCurrentMinute() {
109 | Calendar calendar = Calendar.getInstance();
110 | //创建一个日历引用d,通过静态方法getInstance() 从指定时区 Locale.CHINA 获得一个日期实例
111 | Date myDate = new Date();
112 | //创建一个Date实例
113 | calendar.setTime(myDate);
114 | //设置日历的时间,把一个新建Date实例myDate传入
115 | int minute = calendar.get(Calendar.MINUTE);
116 | return minute;
117 | }
118 |
119 | /**
120 | * 获取上月开始天
121 | *
122 | * @return curData
123 | */
124 | public static String getLastMonthBeginDate() {
125 | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
126 | Calendar calendar = Calendar.getInstance();
127 | calendar.add(Calendar.MONTH, -1);
128 | calendar.set(Calendar.DAY_OF_MONTH, 1);
129 | return format.format(calendar.getTime());
130 | }
131 |
132 | /**
133 | * 获取上月结束天
134 | *
135 | * @return curData
136 | */
137 | public static String getLastMonthEndDate() {
138 | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
139 | Calendar calendar = Calendar.getInstance();
140 | calendar.set(Calendar.DAY_OF_MONTH, 0);
141 | return format.format(calendar.getTime());
142 | }
143 |
144 | /**
145 | * 处理endtime(yyyy-mm-dd),需要穿当前日期的前一天
146 | * 如果当前时间是1号,后台返回的月份是上个月,day直接取上个月月末
147 | * 如果当时时间不是1号,后台返回当前月份,day需要拿当前日期的前一天
148 | */
149 | public static String formatDayContent(String year, String month) {
150 |
151 | String currentDate = TimeUtil.getCurData();
152 | String[] time = currentDate.split("-");
153 | String day = time[2];
154 | /*展示的年月不是当年或者当月,日都需要显示那个月后一天*/
155 | if (time[2].equals("1")||!time[0].equals(year)||!time[1].equals(month)) {
156 | day = getDayByYearAndMonth(Integer.parseInt(year), Integer.parseInt(month));
157 | } else {
158 | int dayIntger = Integer.parseInt(day) - 1;
159 | day = String.valueOf(dayIntger);
160 | }
161 | if(day.length()==1){
162 | day="0"+day;
163 | }
164 | return day;
165 | }
166 |
167 | /*根据年月获取天数的最大值*/
168 | public static String getDayByYearAndMonth(int year, int month) {
169 | Calendar time = Calendar.getInstance();
170 | time.clear();
171 | time.set(Calendar.YEAR, year);
172 | //year年
173 | time.set(Calendar.MONTH, month - 1);
174 | //Calendar对象默认一月为0,month月
175 | String day = time.getActualMaximum(Calendar.DAY_OF_MONTH) + "";//本月份的天数
176 | return day;
177 | }
178 | }
179 |
--------------------------------------------------------------------------------
/doubledatepicker/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/doubledatepicker/src/main/java/com/fantasy/doubledatepicker/DoubleDateSelectDialog.java:
--------------------------------------------------------------------------------
1 | package com.fantasy.doubledatepicker;
2 |
3 | import android.app.Dialog;
4 | import android.content.Context;
5 | import android.text.SpannableString;
6 | import android.text.Spanned;
7 | import android.text.TextUtils;
8 | import android.text.style.ForegroundColorSpan;
9 | import android.text.style.RelativeSizeSpan;
10 | import android.util.Log;
11 | import android.view.Gravity;
12 | import android.view.View;
13 | import android.view.ViewGroup;
14 | import android.view.Window;
15 | import android.view.WindowManager;
16 | import android.widget.LinearLayout;
17 | import android.widget.TextView;
18 | import android.widget.Toast;
19 |
20 | import java.text.ParseException;
21 | import java.text.SimpleDateFormat;
22 | import java.util.Arrays;
23 | import java.util.Calendar;
24 | import java.util.Date;
25 | import java.util.List;
26 | import java.util.Locale;
27 |
28 | /**
29 | * Created by darrenfantasy on 2018/01/20.
30 | */
31 |
32 | public class DoubleDateSelectDialog extends Dialog implements View.OnClickListener {
33 |
34 | private Context mContext;
35 |
36 | /**
37 | * 事件选取完毕监听
38 | */
39 | private OnDateSelectFinished onDateSelectFinished;
40 | /**
41 | * 开始、结束年份
42 | */
43 | private static int START_YEAR = 1900, END_YEAR = 2100;
44 | private static int START_MONTH = 1, END_MONTH = 12;
45 | private static int START_DAY = 1, END_DAY = 31;
46 | /**
47 | * 年
48 | */
49 | private WheelView mYearView;
50 | /**
51 | * 月
52 | */
53 | private WheelView mMonthView;
54 | /**
55 | * 日
56 | */
57 | private WheelView mDayView;
58 | /**
59 | * 时
60 | */
61 | private WheelView mHourView;
62 | /**
63 | * 分
64 | */
65 | private WheelView mMinuteView;
66 | /**
67 | * list列表(大月份)
68 | */
69 | private List mListBig;
70 | /**
71 | * list列表(小月份)
72 | */
73 | private List mListLittle;
74 |
75 | /* 是否只选择本年 */
76 | private boolean isOnlyThisYear = false;
77 |
78 | private boolean isShowMinute = false;
79 | /* 是否只选择本月 */
80 | private boolean isOnlyThisMonth = false;
81 |
82 | public static final String YEAR = "year";
83 | public static final String MONTH = "month";
84 | public static final String DAY = "day";
85 | private int year;
86 | private int month;
87 | private int day;
88 | private int hour;
89 | private int minute;
90 |
91 | private int curYear;
92 | private int curMonth;
93 | private int curDay;
94 |
95 | /**
96 | * 时间容器
97 | */
98 | private LinearLayout mTimeContainerLl;
99 | /**
100 | * 开始时间
101 | */
102 | private TextView mBeginTimeTv;
103 | /**
104 | * 结束时间
105 | */
106 | private TextView mEndTimeTv;
107 |
108 | /**
109 | * 选择的开始时间
110 | */
111 | private String mSelectStartTime;
112 | /**
113 | * 选择的结束时间
114 | */
115 | private String mSelectEndTime;
116 |
117 | /**
118 | * 当前选择时间模式
119 | */
120 | private TIME_TYPE mTimeType = TIME_TYPE.TYPE_START;
121 |
122 | /**
123 | * 最小时间
124 | */
125 | private String allowedSmallestTime = "1900-01-01";
126 | /**
127 | * 最大时间
128 | */
129 | private String allowedBiggestTime = "2099-12-31";
130 |
131 | private enum TIME_TYPE {
132 | TYPE_START,
133 | TYPE_END
134 | }
135 |
136 |
137 | public DoubleDateSelectDialog(Context context) {
138 | super(context, R.style.PopBottomDialogStyle);
139 | this.mContext = context;
140 | basicInit();
141 | initDialogView();
142 | init("", false);
143 | String monthS = String.format("%02d", curMonth);
144 | String dayS = String.format("%02d", curDay);
145 | String yearS = String.format("%02d", curYear);
146 | mSelectStartTime = yearS + "-" + monthS + "-" + dayS;
147 | mBeginTimeTv.setText(makeFormatContent(mContext.getString(R.string.begin_at), yearS + "." + monthS + "." + dayS));
148 | mSelectEndTime = yearS + "-" + monthS + "-" + dayS;
149 | mEndTimeTv.setText(makeFormatContent(mContext.getString(R.string.end_at), yearS + "." + monthS + "." + dayS));
150 | }
151 |
152 |
153 | /**
154 | * @param context
155 | * @param allowedSmallestDate 日期选择器的起始日期
156 | * @param allowedBiggestDate 日期选择器的终止日期
157 | */
158 | public DoubleDateSelectDialog(Context context, String allowedSmallestDate, String allowedBiggestDate) {
159 | super(context, R.style.PopBottomDialogStyle);
160 | this.mContext = context;
161 | this.allowedSmallestTime = allowedSmallestDate;
162 | this.allowedBiggestTime = allowedBiggestDate;
163 | basicInit();
164 | initDialogView();
165 |
166 | init("", false);
167 |
168 | String monthS = String.format("%02d", curMonth);
169 | String dayS = String.format("%02d", curDay);
170 | String yearS = String.format("%02d", curYear);
171 |
172 | mSelectStartTime = yearS + "-" + monthS + "-" + dayS;
173 | mBeginTimeTv.setText(makeFormatContent(mContext.getString(R.string.begin_at), yearS + "." + monthS + "." + dayS));
174 | mSelectEndTime = yearS + "-" + monthS + "-" + dayS;
175 | mEndTimeTv.setText(makeFormatContent(mContext.getString(R.string.end_at), yearS + "." + monthS + "." + dayS));
176 | }
177 |
178 | /**
179 | *
180 | * @param context
181 | * @param allowedSmallestDate 日期选择器的起始日期
182 | * @param allowedBiggestDate 日期选择器的终止日期
183 | * @param defaultChooseDate 日期选择器默认选择日期
184 | */
185 | public DoubleDateSelectDialog(Context context, String allowedSmallestDate, String allowedBiggestDate, String defaultChooseDate) {
186 | super(context, R.style.PopBottomDialogStyle);
187 | this.mContext = context;
188 | this.allowedSmallestTime = allowedSmallestDate;
189 | this.allowedBiggestTime = allowedBiggestDate;
190 | basicInit();
191 | initDialogView();
192 |
193 | init(defaultChooseDate, false);
194 |
195 | String monthS = String.format("%02d", curMonth);
196 | String dayS = String.format("%02d", curDay);
197 | String yearS = String.format("%02d", curYear);
198 |
199 | mSelectStartTime = yearS + "-" + monthS + "-" + dayS;
200 | mBeginTimeTv.setText(makeFormatContent(mContext.getString(R.string.begin_at), yearS + "." + monthS + "." + dayS));
201 | mSelectEndTime = yearS + "-" + monthS + "-" + dayS;
202 | mEndTimeTv.setText(makeFormatContent(mContext.getString(R.string.end_at), yearS + "." + monthS + "." + dayS));
203 | }
204 |
205 | private void basicInit() {
206 | setContentView(R.layout.popwindow_bottom_layout);
207 | setCanceledOnTouchOutside(true);
208 | Window mDialogWindow = getWindow();
209 | mDialogWindow.setGravity(Gravity.BOTTOM);
210 | WindowManager.LayoutParams lp = mDialogWindow.getAttributes();
211 | lp.y = 0;//设置Dialog距离底部的距离
212 | lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
213 | mDialogWindow.setAttributes(lp);
214 | }
215 |
216 | private void initDialogView() {
217 |
218 | mTimeContainerLl = findViewById(R.id.ll_tclTimeToTime);
219 | mBeginTimeTv = findViewById(R.id.tv_tclBeginTime);
220 | mEndTimeTv = findViewById(R.id.tv_tclEndTime);
221 |
222 | findViewById(R.id.tv_tclCancel).setOnClickListener(this);
223 | findViewById(R.id.tv_tclOk).setOnClickListener(this);
224 | mBeginTimeTv.setOnClickListener(this);
225 | mEndTimeTv.setOnClickListener(this);
226 |
227 | }
228 |
229 |
230 | @Override
231 | public void onClick(View v) {
232 | int i = v.getId();
233 | if (i == R.id.tv_tclBeginTime) {
234 | mTimeType = TIME_TYPE.TYPE_START;
235 | init(mSelectStartTime, false);
236 | mTimeContainerLl.setBackgroundResource(R.mipmap.begin_time_bg);
237 |
238 | } else if (i == R.id.tv_tclEndTime) {
239 | mTimeType = TIME_TYPE.TYPE_END;
240 | init(mSelectEndTime, false);
241 | mTimeContainerLl.setBackgroundResource(R.mipmap.end_time_bg);
242 |
243 | } else if (i == R.id.tv_tclCancel) {
244 | this.dismiss();
245 |
246 |
247 | } else if (i == R.id.tv_tclOk) {
248 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
249 | try {
250 | if (sdf.parse(mSelectStartTime).getTime() > sdf.parse(mSelectEndTime).getTime()) {
251 | Toast.makeText(mContext, R.string.time_start_larger_end_not_allowed, Toast.LENGTH_SHORT).show();
252 | } else {
253 | if (onDateSelectFinished != null) {
254 | onDateSelectFinished.onSelectFinished(mSelectStartTime, mSelectEndTime);
255 | }
256 | this.dismiss();
257 | }
258 | } catch (ParseException e) {
259 | e.printStackTrace();
260 | }
261 | }
262 | }
263 |
264 | private void init(String date, boolean isShowHour) {
265 | Calendar calendar = Calendar.getInstance();
266 | curYear = calendar.get(Calendar.YEAR);
267 | curMonth = calendar.get(Calendar.MONTH) + 1;
268 | curDay = calendar.get(Calendar.DATE);
269 | hour = calendar.get(Calendar.HOUR_OF_DAY);
270 | minute = calendar.get(Calendar.MINUTE);
271 | calendar.clear();
272 |
273 | if (!TextUtils.isEmpty(date)) {
274 | String[] ymd = date.split("-");
275 | if (ymd.length > 2) {
276 | curYear = Integer.parseInt(ymd[0]);
277 | curMonth = Integer.parseInt(ymd[1]);
278 | String[] dhm = ymd[2].split(" ");
279 | curDay = Integer.parseInt(dhm[0]);
280 | if (dhm.length > 1) {
281 | String[] hm = dhm[1].split(":");
282 | if (hm.length > 1) {
283 | hour = Integer.parseInt(hm[0]);
284 | minute = Integer.parseInt(hm[1]);
285 | }
286 | }
287 | }
288 | } else {
289 | String currentDateStr = curYear + "-" + curMonth + "-" + curDay;
290 | try {
291 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
292 | Date bt = sdf.parse(allowedSmallestTime);
293 | Date et = sdf.parse(allowedBiggestTime);
294 | Date currentDate = sdf.parse(currentDateStr);
295 | if (currentDate.before(bt) || currentDate.after(et)) {
296 | String[] ymd = allowedSmallestTime.split("-");
297 | if (ymd.length > 2) {
298 | curYear = Integer.parseInt(ymd[0]);
299 | curMonth = Integer.parseInt(ymd[1]);
300 | String[] dhm = ymd[2].split(" ");
301 | curDay = Integer.parseInt(dhm[0]);
302 | if (dhm.length > 1) {
303 | String[] hm = dhm[1].split(":");
304 | if (hm.length > 1) {
305 | hour = Integer.parseInt(hm[0]);
306 | minute = Integer.parseInt(hm[1]);
307 | }
308 | }
309 | }
310 | }
311 | } catch (ParseException e) {
312 | e.printStackTrace();
313 | }
314 | }
315 |
316 | mYearView = findViewById(R.id.year);
317 | mMonthView = findViewById(R.id.month);
318 | mDayView = findViewById(R.id.day);
319 | mHourView = findViewById(R.id.hour);
320 | mMinuteView = findViewById(R.id.minute);
321 |
322 | if (!isShowHour) {
323 | mHourView.setVisibility(View.GONE);
324 | mMinuteView.setVisibility(View.GONE);
325 | }
326 |
327 | if (!isShowMinute) {
328 | mMinuteView.setVisibility(View.GONE);
329 | }
330 |
331 | /* 年,月,日,时,分 等单位,和值同在 */
332 | findViewById(R.id.tv_yearUnit).setVisibility(mYearView.getVisibility());
333 |
334 | findViewById(R.id.tv_monthUnit).setVisibility(mMonthView.getVisibility());
335 |
336 | findViewById(R.id.tv_dayUnit).setVisibility(mDayView.getVisibility());
337 | findViewById(R.id.v_dayAndMinute).setVisibility(isShowHour ? View.VISIBLE : View.GONE);
338 |
339 | findViewById(R.id.tv_hourUnit).setVisibility(mHourView.getVisibility());
340 |
341 | findViewById(R.id.tv_minuteUnit).setVisibility(mMinuteView.getVisibility());
342 |
343 | initDatePicker();
344 |
345 | mYearView.removeChangingListener(yearWheelListener);
346 | mMonthView.removeChangingListener(monthWheelListener);
347 | mDayView.removeChangingListener(dayWheelListener);
348 |
349 | mYearView.addChangingListener(yearWheelListener);
350 | mMonthView.addChangingListener(monthWheelListener);
351 | mDayView.addChangingListener(dayWheelListener);
352 |
353 | }
354 |
355 | /**
356 | * 弹出日期时间选择器
357 | */
358 | private void initDatePicker() {
359 | Calendar calendar = Calendar.getInstance();
360 | year = calendar.get(Calendar.YEAR);
361 | month = calendar.get(Calendar.MONTH);
362 | day = calendar.get(Calendar.DATE);
363 |
364 | Log.d("darren", "year:" + year);
365 | Log.d("darren", "month:" + month);
366 | Log.d("darren", "day:" + day);
367 |
368 | String[] ymdStart = allowedSmallestTime.split("-");
369 | if (TextUtils.isEmpty(allowedBiggestTime))
370 | allowedBiggestTime = TimeUtil.getCurData();
371 | String[] ymdEnd = allowedBiggestTime.split("-");
372 |
373 | if (ymdStart.length > 2) {
374 | START_YEAR = Integer.parseInt(ymdStart[0]);
375 | START_MONTH = Integer.parseInt(ymdStart[1]);
376 | START_DAY = Integer.parseInt(ymdStart[2]);
377 | }
378 | if (ymdEnd.length > 2) {
379 | END_YEAR = Integer.parseInt(ymdEnd[0]);
380 | END_MONTH = Integer.parseInt(ymdEnd[1]);
381 | END_DAY = Integer.parseInt(ymdEnd[2]);
382 | }
383 |
384 |
385 | // 添加大小月月份并将其转换为list,方便之后的判断
386 | String[] monthsBig = {"1", "3", "5", "7", "8", "10", "12"};
387 | String[] monthsLittle = {"4", "6", "9", "11"};
388 |
389 | mListBig = Arrays.asList(monthsBig);
390 | mListLittle = Arrays.asList(monthsLittle);
391 |
392 | // 年
393 | mYearView.setAdapter(new NumericWheelAdapter(START_YEAR, END_YEAR));// 设置"年"的显示数据
394 | mYearView.setLabel("");// 添加文字
395 | int yearPos = isOnlyThisYear ? END_YEAR - START_YEAR : curYear != 0 ? curYear - START_YEAR : END_YEAR - START_YEAR;
396 | mYearView.setCurrentItem(yearPos);// 初始化时显示的数据 START_YEAR - END_YEAR
397 | mYearView.setCyclic(false);// 循环滚动
398 |
399 |
400 | // 月
401 | int startMonth = 1;
402 | if (isOnlyThisMonth) {
403 | startMonth = curMonth + 1;
404 | }
405 |
406 | //初始月份最大值应该是当年最大月
407 | int minMonth = (START_YEAR == curYear ? START_MONTH : 1);
408 |
409 | mMonthView.setAdapter(new NumericWheelAdapter(minMonth, END_YEAR == curYear ? END_MONTH : 12));
410 | mMonthView.setLabel("");
411 | mMonthView.setCurrentItem(isOnlyThisMonth ? 0 : curMonth != 0 ? curMonth - minMonth : month - minMonth);
412 | mMonthView.setCyclic(false);
413 |
414 | // 日
415 | //判断是否属于当前月份,如果不是,需要判断大小月,进行初始化
416 | // Log.d("darren","curMonth:"+curMonth);
417 | // Log.d("darren","month:"+month);
418 | int mEndDay = 31;
419 | // 判断大小月及是否闰年,用来确定"日"的数据
420 | if (mListBig.contains(String.valueOf(curMonth))) {
421 | mDayView.setAdapter(new NumericWheelAdapter(1, 31));
422 | mEndDay = 31;
423 | } else if (mListLittle.contains(String.valueOf(curMonth))) {
424 | mDayView.setAdapter(new NumericWheelAdapter(1, 30));
425 | mEndDay = 30;
426 | } else {
427 | if (((mYearView.getCurrentItem() + START_YEAR) % 4 == 0 && (mYearView.getCurrentItem() + START_YEAR) % 100 != 0)
428 | || (mYearView.getCurrentItem() + START_YEAR) % 400 == 0) {
429 | mDayView.setAdapter(new NumericWheelAdapter(1, 29));
430 | mEndDay = 29;
431 | } else {
432 | mDayView.setAdapter(new NumericWheelAdapter(1, 28));
433 | mEndDay = 28;
434 | }
435 |
436 | }
437 | int minDay = 1;
438 | if ((curMonth == END_MONTH && curYear == END_YEAR) && (curMonth == START_MONTH && curYear == START_YEAR)) {
439 | mDayView.setAdapter(new NumericWheelAdapter(START_DAY, END_DAY));
440 | minDay = START_DAY;
441 | } else if ((curMonth == END_MONTH && curYear == END_YEAR)) {
442 | mDayView.setAdapter(new NumericWheelAdapter(1, END_DAY));
443 | } else if ((curMonth == START_MONTH && curYear == START_YEAR)) {
444 | mDayView.setAdapter(new NumericWheelAdapter(START_DAY, mEndDay));
445 | minDay = START_DAY;
446 | } else {
447 | mDayView.setAdapter(new NumericWheelAdapter(1, mEndDay));
448 | }
449 |
450 | mDayView.setLabel("");
451 | mDayView.setCurrentItem(curDay == 0 ? day - minDay : curDay - minDay);
452 | mDayView.setCyclic(true);
453 |
454 | // 时
455 | mHourView.setAdapter(new NumericWheelAdapter(0, 23));
456 | mHourView.setLabel("");
457 | mHourView.setCurrentItem(hour);
458 | mHourView.setCyclic(true);
459 |
460 | // 分
461 | mMinuteView.setAdapter(new NumericWheelAdapter(0, 59));
462 | mMinuteView.setLabel("");
463 | mMinuteView.setCurrentItem(minute);
464 | mMinuteView.setCyclic(true);
465 |
466 | // 选择器字体的大小
467 | int textSize = mContext.getResources().getDimensionPixelSize(R.dimen.ymd_text_size);
468 | mDayView.TEXT_SIZE = textSize;
469 | mMonthView.TEXT_SIZE = textSize;
470 | mYearView.TEXT_SIZE = textSize;
471 | mHourView.TEXT_SIZE = textSize;
472 | mMinuteView.TEXT_SIZE = textSize;
473 | }
474 |
475 |
476 | /**
477 | * 添加对"年"监听
478 | */
479 | private OnWheelChangedListener yearWheelListener = new OnWheelChangedListener() {
480 | public void onChanged(WheelView wheel, int oldValue, int newValue) {
481 | int year_num = newValue + START_YEAR;
482 | int month_start_num = 1;
483 | if (year_num < END_YEAR && year_num > START_YEAR) {
484 | mMonthView.setAdapter(new NumericWheelAdapter(1, 12));
485 | month_start_num = 1;
486 | } else if (year_num == START_YEAR) {
487 | mMonthView.setAdapter(new NumericWheelAdapter(START_MONTH, 12));
488 | month_start_num = START_MONTH;
489 | } else if (year_num == END_YEAR) {
490 | mMonthView.setAdapter(new NumericWheelAdapter(1, END_MONTH));
491 | month_start_num = 1;
492 | }
493 | mMonthView.setCurrentItem(0);
494 |
495 | // 判断大小月及是否闰年,用来确定"日"的数据
496 | int mEndDay = 31;
497 | if (mListBig.contains(String.valueOf(mMonthView.getCurrentItem() + month_start_num))) {
498 | mDayView.setAdapter(new NumericWheelAdapter(1, 31));
499 | mEndDay = 31;
500 | } else if (mListLittle.contains(String.valueOf(mMonthView.getCurrentItem() + month_start_num))) {
501 | mDayView.setAdapter(new NumericWheelAdapter(1, 30));
502 | mEndDay = 30;
503 | } else {
504 | if ((year_num % 4 == 0 && year_num % 100 != 0) || year_num % 400 == 0) {
505 | mDayView.setAdapter(new NumericWheelAdapter(1, 29));
506 | mEndDay = 29;
507 | } else {
508 | mDayView.setAdapter(new NumericWheelAdapter(1, 28));
509 | mEndDay = 28;
510 | }
511 | }
512 | Log.d("darren", "year_num:" + year_num);
513 | Log.d("darren", "START_YEAR:" + START_YEAR);
514 | int temp = mMonthView.getCurrentItem() + 1;
515 | Log.d("darren", "mMonthView.getCurrentItem() + 1:" + temp);
516 | Log.d("darren", "START_MONTH:" + START_MONTH);
517 | if (year_num == START_YEAR && mMonthView.getCurrentItem() + month_start_num == START_MONTH) {
518 | mDayView.setAdapter(new NumericWheelAdapter(START_DAY, mEndDay));
519 | } else if (year_num == END_YEAR && mMonthView.getCurrentItem() + month_start_num == END_MONTH) {
520 | mDayView.setAdapter(new NumericWheelAdapter(1, END_DAY));
521 | }
522 | onScroll();
523 | mMonthView.setCurrentItem(mMonthView.getCurrentItem());
524 | mDayView.setCurrentItem(mDayView.getCurrentItem());
525 | }
526 | };
527 |
528 | /**
529 | * 添加对"月"监听
530 | */
531 | private OnWheelChangedListener monthWheelListener = new OnWheelChangedListener() {
532 | public void onChanged(WheelView wheel, int oldValue, int newValue) {
533 | int addMonth = 1;
534 | if (mYearView.getCurrentItem() == 0) {
535 | addMonth = START_MONTH;
536 | }
537 | int month_num = newValue + addMonth;
538 | // 判断大小月及是否闰年,用来确定"日"的数据
539 | int mEndDay = 31;
540 | if (mListBig.contains(String.valueOf(month_num))) {
541 | mDayView.setAdapter(new NumericWheelAdapter(1, 31));
542 | mEndDay = 31;
543 | } else if (mListLittle.contains(String.valueOf(month_num))) {
544 | mDayView.setAdapter(new NumericWheelAdapter(1, 30));
545 | mEndDay = 30;
546 | } else {
547 | if (((mYearView.getCurrentItem() + START_YEAR) % 4 == 0 && (mYearView.getCurrentItem() + START_YEAR) % 100 != 0)
548 | || (mYearView.getCurrentItem() + START_YEAR) % 400 == 0) {
549 | mDayView.setAdapter(new NumericWheelAdapter(1, 29));
550 | mEndDay = 29;
551 | } else {
552 | mDayView.setAdapter(new NumericWheelAdapter(1, 28));
553 | mEndDay = 28;
554 | }
555 |
556 | }
557 | if (month_num == START_MONTH && (mYearView.getCurrentItem() + START_YEAR) == START_YEAR) {
558 | mDayView.setAdapter(new NumericWheelAdapter(START_DAY, mEndDay));
559 | } else if (month_num == END_MONTH && (mYearView.getCurrentItem() + START_YEAR) == END_YEAR) {
560 | mDayView.setAdapter(new NumericWheelAdapter(1, END_DAY));
561 | }
562 | onScroll();
563 | mDayView.setCurrentItem(mDayView.getCurrentItem());
564 | }
565 | };
566 |
567 | /**
568 | * 添加对 日滚动控件 的添加
569 | */
570 | private OnWheelChangedListener dayWheelListener = new OnWheelChangedListener() {
571 | public void onChanged(WheelView wheel, int oldValue, int newValue) {
572 | mDayView.setCurrentItem(newValue);
573 | onScroll();
574 | }
575 | };
576 |
577 | private void onScroll() {
578 |
579 | int year = isOnlyThisYear ? Integer.parseInt(mYearView.getAdapter().getItem(0))
580 | : mYearView.getCurrentItem() + START_YEAR;
581 | int addMonth = 1;
582 | if (mYearView.getCurrentItem() == 0) {
583 | addMonth = START_MONTH;
584 | }
585 | int month = isOnlyThisMonth ? Integer.parseInt(mMonthView.getAdapter().getItem(0))
586 | : mMonthView.getCurrentItem() + addMonth;
587 | int addDay = 1;
588 | if ((mYearView.getCurrentItem() == 0 && mMonthView.getCurrentItem() == 0)) {
589 | addDay = START_DAY;
590 | }
591 | int day = mDayView.getCurrentItem() + addDay;
592 |
593 | String monthS = String.format("%02d", month);
594 | String dayS = String.format("%02d", day);
595 | String yearS = String.format("%02d", year);
596 |
597 |
598 | if (mTimeType == TIME_TYPE.TYPE_START) {
599 | mSelectStartTime = yearS + "-" + monthS + "-" + dayS;
600 | mBeginTimeTv.setText(makeFormatContent(mContext.getString(R.string.begin_at), yearS + "." + monthS + "." + dayS));
601 | } else {
602 | mSelectEndTime = yearS + "-" + monthS + "-" + dayS;
603 | mEndTimeTv.setText(makeFormatContent(mContext.getString(R.string.end_at), yearS + "." + monthS + "." + dayS));
604 | }
605 | }
606 |
607 | /**
608 | * 格式化显示的数据,必须返回SpannableString对象
609 | *
610 | * @param priFix 前缀
611 | * @param content 内容
612 | * @return 返回格式化的数据
613 | */
614 | private SpannableString makeFormatContent(String priFix, String content) {
615 | SpannableString spannableString = new SpannableString(priFix + content);
616 | spannableString.setSpan(new ForegroundColorSpan(mContext.getResources().getColor(R.color.black33)),
617 | priFix.length(), spannableString.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
618 | spannableString.setSpan(new RelativeSizeSpan(1.33f),
619 | priFix.length(), spannableString.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
620 | return spannableString;
621 | }
622 |
623 |
624 | /**
625 | * set监听
626 | *
627 | * @param onDateSelectFinished 完成监听
628 | */
629 | public void setOnDateSelectFinished(OnDateSelectFinished onDateSelectFinished) {
630 | this.onDateSelectFinished = onDateSelectFinished;
631 | }
632 |
633 | /**
634 | * 监听接口
635 | */
636 | public interface OnDateSelectFinished {
637 | /**
638 | * 监听方法
639 | *
640 | * @param startTime 开始时间
641 | * @param endTime 结束时间
642 | */
643 | void onSelectFinished(String startTime, String endTime);
644 | }
645 |
646 | }
647 |
--------------------------------------------------------------------------------
/doubledatepicker/src/main/java/com/fantasy/doubledatepicker/WheelView.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Android Wheel Control.
3 | * https://code.google.com/p/android-wheel/
4 | *
5 | * Copyright 2010 Yuri Kanivets
6 | *
7 | * Licensed under the Apache License, Version 2.0 (the "License");
8 | * you may not use this file except in compliance with the License.
9 | * You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 |
20 | package com.fantasy.doubledatepicker;
21 |
22 |
23 | import android.content.Context;
24 | import android.graphics.Canvas;
25 | import android.graphics.Paint;
26 | import android.graphics.Rect;
27 | import android.graphics.drawable.Drawable;
28 | import android.graphics.drawable.GradientDrawable;
29 | import android.graphics.drawable.GradientDrawable.Orientation;
30 | import android.os.Handler;
31 | import android.os.Message;
32 | import android.text.Layout;
33 | import android.text.StaticLayout;
34 | import android.text.TextPaint;
35 | import android.util.AttributeSet;
36 | import android.view.GestureDetector;
37 | import android.view.GestureDetector.SimpleOnGestureListener;
38 | import android.view.MotionEvent;
39 | import android.view.View;
40 | import android.view.animation.Interpolator;
41 | import android.widget.Scroller;
42 |
43 | import java.util.LinkedList;
44 | import java.util.List;
45 |
46 | /**
47 | * Numeric wheel view.
48 | */
49 | public class WheelView extends View {
50 | /** 滚动持续的时间 */
51 | private static final int SCROLLING_DURATION = 400;
52 |
53 | /** 最少滚动的位置 */
54 | private static final int MIN_DELTA_FOR_SCROLLING = 1;
55 |
56 | /** 当前值和标签的颜色 */
57 | private static final int VALUE_TEXT_COLOR = 0xFF40a0ff;
58 |
59 | /** item文字的颜色 */
60 | private static final int ITEMS_TEXT_COLOR = 0xFF919191;
61 |
62 | /** 顶部和底部阴影的颜色 */
63 | private static final int[] SHADOWS_COLORS = new int[] { 0xFF111111,
64 | 0x00AAAAAA, 0x00AAAAAA };
65 |
66 | /** 附加的item的高度 */
67 | private static final int ADDITIONAL_ITEM_HEIGHT = 60;
68 |
69 | /** 字体大小 */
70 | public int TEXT_SIZE;
71 |
72 | /** 顶部和底部item的偏移值 */
73 | private final int ITEM_OFFSET = TEXT_SIZE / 3;
74 |
75 | /** item布局的附加宽度 */
76 | private static final int ADDITIONAL_ITEMS_SPACE = 12;
77 |
78 | /** 标签偏移值 */
79 | private static final int LABEL_OFFSET = 22;
80 |
81 | /** 左右padding值 */
82 | private static final int PADDING = 0;
83 |
84 | /** 默认可见的item数目 */
85 | private static final int DEF_VISIABLE_ITEMS = 3;
86 |
87 | /** 初始化wheeladpater */
88 | private WheelAdapter adapter = null;
89 |
90 | /** 当前item位置 */
91 | private int currentItem = 0;
92 |
93 | /** item宽度 */
94 | private int itemsWidth = 0;
95 |
96 | /** 标签宽度 */
97 | private int labelWidth = 0;
98 |
99 | /** 可见item数目 */
100 | private int visibleItems = DEF_VISIABLE_ITEMS;
101 |
102 | /** item高度 */
103 | private int itemHeight = 0;
104 |
105 | /** item的字符串属性对象 */
106 | private TextPaint itemsPaint;
107 |
108 | /** value的字符串属性对象 */
109 | private TextPaint valuePaint;
110 |
111 | /** 当前选中颜色 */
112 | private int selectColor = VALUE_TEXT_COLOR;
113 |
114 | // Layouts
115 | private StaticLayout itemsLayout, labelLayout, valueLayout;
116 |
117 | private String label;
118 | private Drawable centerDrawableTop;
119 | private Drawable centerDrawableBottom;
120 |
121 | /** 顶部渐变drawable对象 */
122 | private GradientDrawable topShadow;
123 |
124 | /** 顶部渐变drawable对象 */
125 | private GradientDrawable bottomShadow;
126 |
127 | /** 滚动动作是否执行 */
128 | private boolean isScrollingPerformed;
129 |
130 | /** 滚动偏移量 */
131 | private int scrollingOffset;
132 |
133 | /** 手势侦测对象 */
134 | private GestureDetector gestureDetector;
135 |
136 | private Scroller scroller;
137 | private int lastScrollY;
138 |
139 | /** 是否可循环 */
140 | private boolean isCyclic = false;
141 |
142 | /** 实例化OnWheelChangedListener */
143 | private List changingListeners = new LinkedList();
144 | /** 实例化OnWheelScrollListener */
145 | private List scrollingListeners = new LinkedList();
146 |
147 | /**
148 | * Constructor
149 | */
150 | public WheelView(Context context, AttributeSet attrs, int defStyle) {
151 | super(context, attrs, defStyle);
152 | initData(context);
153 | }
154 |
155 | /**
156 | * Constructor
157 | */
158 | public WheelView(Context context, AttributeSet attrs) {
159 | super(context, attrs);
160 | initData(context);
161 | }
162 |
163 | /**
164 | * Constructor
165 | */
166 | public WheelView(Context context) {
167 | super(context);
168 | initData(context);
169 | }
170 |
171 | private void initData(Context context) {
172 | gestureDetector = new GestureDetector(context, gestureListener);
173 | gestureDetector.setIsLongpressEnabled(false);// 设置手势长按不起作用
174 |
175 | scroller = new Scroller(context);
176 | }
177 |
178 | /**
179 | * 获取滚轮适配器
180 | *
181 | * @return
182 | */
183 | public WheelAdapter getAdapter() {
184 | return adapter;
185 | }
186 |
187 | /**
188 | * 设置滚轮适配器
189 | *
190 | * @param adapter
191 | */
192 | public void setAdapter(WheelAdapter adapter) {
193 | this.adapter = adapter;
194 | invalidateLayouts();
195 | invalidate();// 是视图无效
196 |
197 | }
198 |
199 | /**
200 | * 设置指定的滚轮动画变化率
201 | *
202 | * @param interpolator
203 | */
204 | public void setInterpolator(Interpolator interpolator) {
205 | scroller.forceFinished(true);
206 | scroller = new Scroller(getContext(), interpolator);
207 | }
208 |
209 | /**
210 | * 得到可见item的数目
211 | *
212 | * @return the count of visible items
213 | */
214 | public int getVisibleItems() {
215 | return visibleItems;
216 | }
217 |
218 | /**
219 | * 设置可见item的数目
220 | *
221 | * @param count
222 | * the new count
223 | */
224 | public void setVisibleItems(int count) {
225 | visibleItems = count;
226 | invalidate();
227 | }
228 |
229 | /**
230 | * 得到标签
231 | *
232 | * @return
233 | */
234 | public String getLabel() {
235 | return label;
236 | }
237 |
238 | /**
239 | * 设置标签
240 | *
241 | * @param newLabel
242 | */
243 | public void setLabel(String newLabel) {
244 | if (label == null || !label.equals(newLabel)) {
245 | label = newLabel;
246 | labelLayout = null;
247 | invalidate();
248 | }
249 | }
250 |
251 | /**
252 | * 增加滚轮变化监听器
253 | *
254 | * @param listener
255 | */
256 | public void addChangingListener(OnWheelChangedListener listener) {
257 | changingListeners.add(listener);
258 | }
259 |
260 | /**
261 | * 移除滚轮变化监听器
262 | *
263 | * @param listener
264 | */
265 | public void removeChangingListener(OnWheelChangedListener listener) {
266 | changingListeners.remove(listener);
267 | }
268 |
269 | /**
270 | * 通知改变的监听器
271 | *
272 | * @param oldValue
273 | * @param newValue
274 | */
275 | protected void notifyChangingListeners(int oldValue, int newValue) {
276 | for (OnWheelChangedListener listener : changingListeners) {
277 | listener.onChanged(this, oldValue, newValue);
278 | }
279 | }
280 |
281 | /**
282 | * 增加滚轮监听器
283 | *
284 | * @param listener
285 | * the listener
286 | */
287 | public void addScrollingListener(OnWheelScrollListener listener) {
288 | scrollingListeners.add(listener);
289 | }
290 |
291 | /**
292 | * 移除滚轮监听器
293 | *
294 | * @param listener
295 | * the listener
296 | */
297 | public void removeScrollingListener(OnWheelScrollListener listener) {
298 | scrollingListeners.remove(listener);
299 | }
300 |
301 | /**
302 | * 通知监听器开始滚动
303 | */
304 | protected void notifyScrollingListenersAboutStart() {
305 | for (OnWheelScrollListener listener : scrollingListeners) {
306 | listener.onScrollingStarted(this);
307 | }
308 | }
309 |
310 | /**
311 | * 通知监听器结束滚动
312 | */
313 | protected void notifyScrollingListenersAboutEnd() {
314 | for (OnWheelScrollListener listener : scrollingListeners) {
315 | listener.onScrollingFinished(this);
316 | }
317 | }
318 |
319 | /**
320 | * 取得当前item
321 | *
322 | * @return
323 | */
324 | public int getCurrentItem() {
325 | return currentItem;
326 | }
327 |
328 | /**
329 | * 设置当前item
330 | * @param index
331 | * @param animated
332 | */
333 | public void setCurrentItem(int index, boolean animated) {
334 | if (adapter == null || adapter.getItemsCount() == 0) {
335 | return;
336 | }
337 | if (index < 0 || index >= adapter.getItemsCount()) {
338 | if (isCyclic) {
339 | while (index < 0) {
340 | index += adapter.getItemsCount();
341 | }
342 | index %= adapter.getItemsCount();
343 | } else {
344 | return;
345 | }
346 | }
347 | if (index != currentItem) {
348 | if (animated) {
349 | scroll(index - currentItem, SCROLLING_DURATION);
350 | } else {
351 | invalidateLayouts();
352 |
353 | int old = currentItem;
354 | currentItem = index;
355 |
356 | notifyChangingListeners(old, currentItem);
357 | invalidate();
358 | }
359 | }
360 | }
361 |
362 | /**
363 | * 设置当前item w/o 动画. 当index有误是不做任何响应.
364 | *
365 | * @param index
366 | * the item index
367 | */
368 | public void setCurrentItem(int index) {
369 | setCurrentItem(index, false);
370 | }
371 |
372 | /**
373 | * 测试滚轮是否可循环.
374 | *
375 | * @return true if wheel is cyclic
376 | */
377 | public boolean isCyclic() {
378 | return isCyclic;
379 | }
380 |
381 | /**
382 | * 设置滚轮循环标志
383 | *
384 | * @param isCyclic
385 | * the flag to set
386 | */
387 | public void setCyclic(boolean isCyclic) {
388 | this.isCyclic = isCyclic;
389 |
390 | invalidate();
391 | invalidateLayouts();
392 | }
393 |
394 | /**
395 | * 使布局无效
396 | */
397 | private void invalidateLayouts() {
398 | itemsLayout = null;
399 | valueLayout = null;
400 | scrollingOffset = 0;
401 | }
402 |
403 | /**
404 | * 初始化资源信息
405 | */
406 | private void initResourceIfNecessary() {
407 | if (itemsPaint == null) {
408 | itemsPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
409 | itemsPaint.setTextSize(TEXT_SIZE);
410 | }
411 |
412 | if (valuePaint == null) {
413 | valuePaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
414 | // | Paint.FAKE_BOLD_TEXT_FLAG
415 | valuePaint.setTextSize(TEXT_SIZE);
416 | valuePaint.setShadowLayer(0.1f, 0, 0.1f, 0xFFC0C0C0);
417 | }
418 |
419 | if (centerDrawableTop == null) {
420 | centerDrawableTop = getContext().getResources().getDrawable(R.drawable.wheel_val);
421 | }
422 | if (centerDrawableBottom == null) {
423 | centerDrawableBottom = getContext().getResources().getDrawable(R.drawable.wheel_val);
424 | }
425 |
426 | if (topShadow == null) {
427 | topShadow = new GradientDrawable(Orientation.TOP_BOTTOM,
428 | SHADOWS_COLORS);
429 | }
430 |
431 | if (bottomShadow == null) {
432 | bottomShadow = new GradientDrawable(Orientation.BOTTOM_TOP,
433 | SHADOWS_COLORS);
434 | }
435 |
436 | // setBackgroundResource(R.drawable.rectangle_shape);
437 | }
438 |
439 |
440 | /**
441 | * 计算layout所需的高度
442 | * @param layout
443 | * @return
444 | */
445 | private int getDesiredHeight(Layout layout) {
446 | if (layout == null) {
447 | return 0;
448 | }
449 |
450 | int desired = getItemHeight() * visibleItems - ITEM_OFFSET * 2
451 | - ADDITIONAL_ITEM_HEIGHT;
452 |
453 | desired = Math.max(desired,getSuggestedMinimumHeight());
454 | return desired;
455 | }
456 |
457 |
458 | /**
459 | * 通过index得到text
460 | * @param index
461 | * @return
462 | */
463 | private String getTextItem(int index){
464 | if(adapter == null || adapter.getItemsCount() == 0){
465 | return null;
466 | }
467 | int count = adapter.getItemsCount();
468 | if((index < 0 || index >= count) && !isCyclic){
469 | return null;
470 | }else{
471 | while(index < 0){
472 | index += count;
473 | }
474 | }
475 | index %= count;
476 | return adapter.getItem(index);
477 | }
478 |
479 | /**
480 | * 根据当前值构建text
481 | *
482 | * @param useCurrentValue
483 | * @return the text
484 | */
485 | private String buildText(boolean useCurrentValue) {
486 | StringBuilder itemsText = new StringBuilder();
487 | int addItems = visibleItems / 2 + 1;
488 |
489 | for (int i = currentItem - addItems; i <= currentItem + addItems; i++) {
490 | if (useCurrentValue || i != currentItem) {
491 | String text = getTextItem(i);
492 | if (text != null) {
493 | itemsText.append(text);
494 | }
495 | }
496 | if (i < currentItem + addItems) {
497 | itemsText.append("\n");
498 | }
499 | }
500 |
501 | return itemsText.toString();
502 | }
503 |
504 | /**
505 | * 返回可以表示的item的最大长度
506 | * @return the max length
507 | */
508 | private int getMaxTextLength() {
509 | WheelAdapter adapter = getAdapter();
510 | if (adapter == null) {
511 | return 0;
512 | }
513 |
514 | int adapterLength = adapter.getMaximumLength();
515 | if (adapterLength > 0) {
516 | return adapterLength;
517 | }
518 |
519 | String maxText = null;
520 | int addItems = visibleItems / 2;
521 | for (int i = Math.max(currentItem - addItems, 0);
522 | i < Math.min(currentItem + visibleItems, adapter.getItemsCount()); i++) {
523 | String text = adapter.getItem(i);
524 | if (text != null && (maxText == null || maxText.length() < text.length())) {
525 | maxText = text;
526 | }
527 | }
528 |
529 | return maxText != null ? maxText.length() : 0;
530 | }
531 |
532 | /**
533 | * 返回滚轮item的高度
534 | * @return the item height
535 | */
536 | private int getItemHeight() {
537 | if (itemHeight != 0) {
538 | return itemHeight;
539 | } else if (itemsLayout != null && itemsLayout.getLineCount() > 2) {
540 | itemHeight = itemsLayout.getLineTop(2) - itemsLayout.getLineTop(1);
541 | return itemHeight;
542 | }
543 |
544 | return getHeight() / visibleItems;
545 | }
546 |
547 | /**
548 | * 计算控制宽度和创建text布局
549 | * @param widthSize the input layout width
550 | * @param mode the layout mode
551 | * @return the calculated control width
552 | */
553 | private int calculateLayoutWidth(int widthSize, int mode) {
554 | initResourceIfNecessary();
555 |
556 | int width = widthSize;
557 |
558 | int maxLength = getMaxTextLength();
559 | if (maxLength > 0) {
560 | float textWidth = (float) Math.ceil(Layout.getDesiredWidth("0", itemsPaint));
561 | itemsWidth = (int) (maxLength * textWidth);
562 | } else {
563 | itemsWidth = 0;
564 | }
565 | itemsWidth += ADDITIONAL_ITEMS_SPACE; // make it some more
566 |
567 | labelWidth = 0;
568 | if (label != null && label.length() > 0) {
569 | labelWidth = (int) Math.ceil(Layout.getDesiredWidth(label, valuePaint));
570 | }
571 |
572 | boolean recalculate = false;
573 | if (mode == MeasureSpec.EXACTLY) {
574 | width = widthSize;
575 | recalculate = true;
576 | } else {
577 | width = itemsWidth + labelWidth + 2 * PADDING;
578 | if (labelWidth > 0) {
579 | width += LABEL_OFFSET;
580 | }
581 |
582 | // Check against our minimum width
583 | width = Math.max(width, getSuggestedMinimumWidth());
584 |
585 | if (mode == MeasureSpec.AT_MOST && widthSize < width) {
586 | width = widthSize;
587 | recalculate = true;
588 | }
589 | }
590 |
591 | if (recalculate) {
592 | // recalculate width
593 | int pureWidth = width - LABEL_OFFSET - 2 * PADDING;
594 | if (pureWidth <= 0) {
595 | itemsWidth = labelWidth = 0;
596 | }
597 | if (labelWidth > 0) {
598 | double newWidthItems = (double) itemsWidth * pureWidth
599 | / (itemsWidth + labelWidth);
600 | itemsWidth = (int) newWidthItems;
601 | labelWidth = pureWidth - itemsWidth;
602 | } else {
603 | itemsWidth = pureWidth + LABEL_OFFSET; // no label
604 | }
605 | }
606 |
607 | if (itemsWidth > 0) {
608 | createLayouts(itemsWidth, labelWidth);
609 | }
610 |
611 | return width;
612 | }
613 |
614 | /**
615 | * 创建布局
616 | * @param widthItems width of items layout
617 | * @param widthLabel width of label layout
618 | */
619 | private void createLayouts(int widthItems, int widthLabel) {
620 | if (itemsLayout == null || itemsLayout.getWidth() > widthItems) {
621 | itemsLayout = new StaticLayout(buildText(isScrollingPerformed), itemsPaint, widthItems,
622 | widthLabel > 0 ? Layout.Alignment.ALIGN_OPPOSITE : Layout.Alignment.ALIGN_CENTER,
623 | 1, ADDITIONAL_ITEM_HEIGHT, false);
624 | } else {
625 | itemsLayout.increaseWidthTo(widthItems);
626 | }
627 |
628 | if (!isScrollingPerformed && (valueLayout == null || valueLayout.getWidth() > widthItems)) {
629 | String text = getAdapter() != null ? getAdapter().getItem(currentItem) : null;
630 | valueLayout = new StaticLayout(text != null ? text : "",
631 | valuePaint, widthItems, widthLabel > 0 ?
632 | Layout.Alignment.ALIGN_OPPOSITE : Layout.Alignment.ALIGN_CENTER,
633 | 1, ADDITIONAL_ITEM_HEIGHT, false);
634 | } else if (isScrollingPerformed) {
635 | valueLayout = null;
636 | } else {
637 | valueLayout.increaseWidthTo(widthItems);
638 | }
639 |
640 | if (widthLabel > 0) {
641 | if (labelLayout == null || labelLayout.getWidth() > widthLabel) {
642 | labelLayout = new StaticLayout(label, valuePaint,
643 | widthLabel, Layout.Alignment.ALIGN_NORMAL, 1,
644 | ADDITIONAL_ITEM_HEIGHT, false);
645 | } else {
646 | labelLayout.increaseWidthTo(widthLabel);
647 | }
648 | }
649 | }
650 |
651 | @Override
652 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
653 | int widthMode = MeasureSpec.getMode(widthMeasureSpec);
654 | int heightMode = MeasureSpec.getMode(heightMeasureSpec);
655 | int widthSize = MeasureSpec.getSize(widthMeasureSpec);
656 | int heightSize = MeasureSpec.getSize(heightMeasureSpec);
657 |
658 | int width = calculateLayoutWidth(widthSize, widthMode);
659 |
660 | int height;
661 | if (heightMode == MeasureSpec.EXACTLY) {
662 | height = heightSize;
663 | } else {
664 | height = getDesiredHeight(itemsLayout);
665 |
666 | if (heightMode == MeasureSpec.AT_MOST) {
667 | height = Math.min(height, heightSize);
668 | }
669 | }
670 |
671 | setMeasuredDimension(width, height);
672 | }
673 |
674 | @Override
675 | protected void onDraw(Canvas canvas) {
676 | super.onDraw(canvas);
677 |
678 | if (itemsLayout == null) {
679 | if (itemsWidth == 0) {
680 | calculateLayoutWidth(getWidth(), MeasureSpec.EXACTLY);
681 | } else {
682 | createLayouts(itemsWidth, labelWidth);
683 | }
684 | }
685 |
686 | // drawCenterRect(canvas);
687 | if (itemsWidth > 0) {
688 | canvas.save();
689 | // Skip padding space and hide a part of top and bottom items
690 | canvas.translate(PADDING, -ITEM_OFFSET);
691 | drawItems(canvas);
692 | drawValue(canvas);
693 | canvas.restore();
694 | }
695 |
696 | // drawShadows(canvas);
697 | }
698 |
699 | /**
700 | * 在顶部和底部画阴影的控制
701 | * @param canvas the canvas for drawing
702 | */
703 | private void drawShadows(Canvas canvas) {
704 | topShadow.setBounds(0, 0, getWidth(), getHeight() / visibleItems);
705 | topShadow.draw(canvas);
706 |
707 | bottomShadow.setBounds(0, getHeight() - getHeight() / visibleItems,
708 | getWidth(), getHeight());
709 | bottomShadow.draw(canvas);
710 | }
711 |
712 | /**
713 | * 画value和标签的布局
714 | * @param canvas the canvas for drawing
715 | */
716 | private void drawValue(Canvas canvas) {
717 | valuePaint.setColor(selectColor);
718 | valuePaint.drawableState = getDrawableState();
719 |
720 | Rect bounds = new Rect();
721 | itemsLayout.getLineBounds(visibleItems / 2, bounds);
722 |
723 | // draw label
724 | if (labelLayout != null) {
725 | canvas.save();
726 | canvas.translate(itemsLayout.getWidth() + LABEL_OFFSET, bounds.top);
727 | labelLayout.draw(canvas);
728 | canvas.restore();
729 | }
730 |
731 | // draw current value
732 | if (valueLayout != null) {
733 | canvas.save();
734 | canvas.translate(0, bounds.top + scrollingOffset);
735 | valueLayout.draw(canvas);
736 | canvas.restore();
737 | }
738 | }
739 |
740 | /**
741 | * 画items
742 | * @param canvas the canvas for drawing
743 | */
744 | private void drawItems(Canvas canvas) {
745 | canvas.save();
746 |
747 | int top = itemsLayout.getLineTop(1);
748 | canvas.translate(0, - top + scrollingOffset);
749 |
750 | itemsPaint.setColor(ITEMS_TEXT_COLOR);
751 | itemsPaint.drawableState = getDrawableState();
752 | itemsLayout.draw(canvas);
753 |
754 | canvas.restore();
755 | }
756 |
757 | /**
758 | * 画当前值的矩形
759 | * @param canvas the canvas for drawing
760 | */
761 | private void drawCenterRect(Canvas canvas) {
762 | int center = getHeight() / 2;
763 | int offset = getItemHeight() / 2;
764 | /* centerDrawableTop.setBounds(0, center - offset, getWidth(), center - offset + 3);
765 | centerDrawableTop.draw(canvas);
766 | centerDrawableBottom.setBounds(0, center + offset - 3, getWidth(), center + offset);
767 | centerDrawableBottom.draw(canvas); */
768 | centerDrawableTop.setBounds(0, center - offset, getWidth(), center + offset);
769 | centerDrawableTop.draw(canvas);
770 | }
771 |
772 | @Override
773 | public boolean onTouchEvent(MotionEvent event) {
774 | WheelAdapter adapter = getAdapter();
775 | if (adapter == null) {
776 | return true;
777 | }
778 |
779 | if (!gestureDetector.onTouchEvent(event) && event.getAction() == MotionEvent.ACTION_UP) {
780 | justify();
781 | }
782 | return true;
783 | }
784 |
785 | /**
786 | * 滚动滚轮
787 | * @param delta the scrolling value
788 | */
789 | private void doScroll(int delta) {
790 | scrollingOffset += delta;
791 |
792 | int count = scrollingOffset / getItemHeight();
793 | int pos = currentItem - count;
794 | if (isCyclic && adapter.getItemsCount() > 0) {
795 | // fix position by rotating
796 | while (pos < 0) {
797 | pos += adapter.getItemsCount();
798 | }
799 | pos %= adapter.getItemsCount();
800 | } else if (isScrollingPerformed) {
801 | //
802 | if (pos < 0) {
803 | count = currentItem;
804 | pos = 0;
805 | } else if (pos >= adapter.getItemsCount()) {
806 | count = currentItem - adapter.getItemsCount() + 1;
807 | pos = adapter.getItemsCount() - 1;
808 | }
809 | } else {
810 | // fix position
811 | pos = Math.max(pos, 0);
812 | pos = Math.min(pos, adapter.getItemsCount() - 1);
813 | }
814 |
815 | int offset = scrollingOffset;
816 | if (pos != currentItem) {
817 | setCurrentItem(pos, false);
818 | } else {
819 | invalidate();
820 | }
821 |
822 | // update offset
823 | scrollingOffset = offset - count * getItemHeight();
824 | if (scrollingOffset > getHeight()) {
825 | scrollingOffset = scrollingOffset % getHeight() + getHeight();
826 | }
827 | }
828 |
829 | // gesture listener
830 | private SimpleOnGestureListener gestureListener = new SimpleOnGestureListener() {
831 | public boolean onDown(MotionEvent e) {
832 | if (isScrollingPerformed) {
833 | scroller.forceFinished(true);
834 | clearMessages();
835 | return true;
836 | }
837 | return false;
838 | }
839 |
840 | public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
841 | startScrolling();
842 | doScroll((int)-distanceY);
843 | return true;
844 | }
845 |
846 | public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
847 | lastScrollY = currentItem * getItemHeight() + scrollingOffset;
848 | int maxY = isCyclic ? 0x7FFFFFFF : adapter.getItemsCount() * getItemHeight();
849 | int minY = isCyclic ? -maxY : 0;
850 | scroller.fling(0, lastScrollY, 0, (int) -velocityY / 2, 0, 0, minY, maxY);
851 | setNextMessage(MESSAGE_SCROLL);
852 | return true;
853 | }
854 | };
855 |
856 |
857 | // Messages
858 | private final int MESSAGE_SCROLL = 0;
859 | private final int MESSAGE_JUSTIFY = 1;
860 |
861 | /**
862 | * Set next message to queue. Clears queue before.
863 | *
864 | * @param message the message to set
865 | */
866 | private void setNextMessage(int message) {
867 | clearMessages();
868 | animationHandler.sendEmptyMessage(message);
869 | }
870 |
871 | /**
872 | * Clears messages from queue
873 | */
874 | private void clearMessages() {
875 | animationHandler.removeMessages(MESSAGE_SCROLL);
876 | animationHandler.removeMessages(MESSAGE_JUSTIFY);
877 | }
878 |
879 | // animation handler
880 | private Handler animationHandler = new Handler() {
881 | public void handleMessage(Message msg) {
882 | scroller.computeScrollOffset();
883 | int currY = scroller.getCurrY();
884 | int delta = lastScrollY - currY;
885 | lastScrollY = currY;
886 | if (delta != 0) {
887 | doScroll(delta);
888 | }
889 |
890 | // scrolling is not finished when it comes to final Y
891 | // so, finish it manually
892 | if (Math.abs(currY - scroller.getFinalY()) < MIN_DELTA_FOR_SCROLLING) {
893 | currY = scroller.getFinalY();
894 | scroller.forceFinished(true);
895 | }
896 | if (!scroller.isFinished()) {
897 | animationHandler.sendEmptyMessage(msg.what);
898 | } else if (msg.what == MESSAGE_SCROLL) {
899 | justify();
900 | } else {
901 | finishScrolling();
902 | }
903 | }
904 | };
905 |
906 | /**
907 | * Justifies wheel
908 | */
909 | private void justify() {
910 | if (adapter == null) {
911 | return;
912 | }
913 |
914 | lastScrollY = 0;
915 | int offset = scrollingOffset;
916 | int itemHeight = getItemHeight();
917 | boolean needToIncrease = offset > 0 ? currentItem < adapter.getItemsCount() : currentItem > 0;
918 | if ((isCyclic || needToIncrease) && Math.abs((float) offset) > (float) itemHeight / 2) {
919 | if (offset < 0)
920 | offset += itemHeight + MIN_DELTA_FOR_SCROLLING;
921 | else
922 | offset -= itemHeight + MIN_DELTA_FOR_SCROLLING;
923 | }
924 | if (Math.abs(offset) > MIN_DELTA_FOR_SCROLLING) {
925 | scroller.startScroll(0, 0, 0, offset, SCROLLING_DURATION);
926 | setNextMessage(MESSAGE_JUSTIFY);
927 | } else {
928 | finishScrolling();
929 | }
930 | }
931 |
932 | /**
933 | * 开始滚动
934 | */
935 | private void startScrolling() {
936 | if (!isScrollingPerformed) {
937 | isScrollingPerformed = true;
938 | notifyScrollingListenersAboutStart();
939 | }
940 | }
941 |
942 | /**
943 | * 停止滚动
944 | */
945 | void finishScrolling() {
946 | if (isScrollingPerformed) {
947 | notifyScrollingListenersAboutEnd();
948 | isScrollingPerformed = false;
949 | }
950 | invalidateLayouts();
951 | invalidate();
952 | }
953 |
954 | public void scroll(int itemsToScroll, int time) {
955 | scroller.forceFinished(true);
956 |
957 | lastScrollY = scrollingOffset;
958 |
959 | int offset = itemsToScroll * getItemHeight();
960 |
961 | scroller.startScroll(0, lastScrollY, 0, offset - lastScrollY, time);
962 | setNextMessage(MESSAGE_SCROLL);
963 |
964 | startScrolling();
965 | }
966 |
967 | /**
968 | *
969 | * @param selectColor the selectColor to set
970 | */
971 | public void setSelectColor(int selectColor) {
972 | this.selectColor = selectColor;
973 | }
974 |
975 |
976 |
977 | }
978 |
--------------------------------------------------------------------------------