├── .gitignore
├── .idea
├── compiler.xml
├── gradle.xml
├── misc.xml
└── vcs.xml
├── LICENSE
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── jsc
│ │ └── exam
│ │ └── com
│ │ └── wheelview
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── jsc
│ │ │ └── exam
│ │ │ └── com
│ │ │ └── wheelview
│ │ │ ├── BaseActivity.java
│ │ │ ├── BaseEmptyFragmentActivity.java
│ │ │ ├── EmptyFragmentActivity.java
│ │ │ ├── MainActivity.java
│ │ │ ├── bean
│ │ │ └── ClassItem.java
│ │ │ ├── fragments
│ │ │ ├── ColumnWheelFragment.java
│ │ │ ├── DateTimeWheelFragment.java
│ │ │ └── WheelViewFragment.java
│ │ │ └── utils
│ │ │ ├── CompatResourceUtils.java
│ │ │ ├── ViewOutlineUtils.java
│ │ │ └── WindowUtils.java
│ └── res
│ │ ├── drawable-v21
│ │ └── item_background_ripple_001.xml
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable-xxhdpi
│ │ ├── btn_background.png
│ │ ├── ic_chevron_left_white_24dp.png
│ │ ├── kit_ic_assignment_blue_24dp.png
│ │ └── kit_ic_chevron_right_gray_24dp.png
│ │ ├── drawable
│ │ ├── ic_launcher_background.xml
│ │ ├── ripple_round_corner_white_r4.xml
│ │ └── wheel_view_demo_qr_code.png
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ ├── fragment_wheel_dialog.xml
│ │ └── fragment_wheel_view.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── attrs.xml
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── jsc
│ └── exam
│ └── com
│ └── wheelview
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── output
├── WheelDemo.apk
├── output.json
└── shots
│ ├── column_wheel01.png
│ ├── column_wheel02.png
│ ├── column_wheel03.png
│ ├── column_wheel04.png
│ ├── column_wheel05.png
│ ├── date_time_wheel01.png
│ ├── date_time_wheel02.png
│ ├── date_time_wheel03.png
│ ├── date_time_wheel04.png
│ ├── date_time_wheel05.png
│ └── wheel_view.png
├── settings.gradle
└── wheelViewLibrary
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
├── androidTest
└── java
│ └── jsc
│ └── kit
│ └── wheel
│ └── ExampleInstrumentedTest.java
├── main
├── AndroidManifest.xml
├── java
│ └── jsc
│ │ └── kit
│ │ └── wheel
│ │ ├── base
│ │ ├── IWheel.java
│ │ ├── IWheelViewSetting.java
│ │ ├── WheelItem.java
│ │ ├── WheelItemView.java
│ │ ├── WheelMaskView.java
│ │ └── WheelView.java
│ │ └── dialog
│ │ ├── ColumnWheelDialog.java
│ │ ├── DateItem.java
│ │ ├── DateTimeWheelDialog.java
│ │ └── WheelDialogInterface.java
└── res
│ ├── layout
│ ├── wheel_dialog_base.xml
│ └── wheel_dialog_title_bar.xml
│ └── values
│ ├── wheel_attrs.xml
│ ├── wheel_color.xml
│ ├── wheel_dimens.xml
│ ├── wheel_ids.xml
│ ├── wheel_strings.xml
│ └── wheel_style.xml
└── test
└── java
└── jsc
└── kit
└── wheel
└── ExampleUnitTest.java
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches/build_file_checksums.ser
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | .DS_Store
9 | /build
10 | /captures
11 | .externalNativeBuild
12 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
20 |
21 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # WheelView
2 |
3 | ### 1、attrs
4 | + 1.1、[WheelView](/wheelLibrary/src/main/java/jsc/kit/wheel/base/WheelView.java)
5 |
6 | | 名称 | 类型 | 描述 |
7 | |:---|:---|:---|
8 | |`wheelTextColor`|color|选中item字体颜色|
9 | |`wheelTextSize`|dimension|字体大小|
10 | |`wheelShowCount`|integer|显示item条数,与`wheelItemVerticalSpace`决定了控件的高度|
11 | |`wheelTotalOffsetX`|dimension|X轴方向总弯曲度,决定弧形效果|
12 | |`wheelItemVerticalSpace`|dimension|两个item之间的间距,与`wheelShowCount`决定了控件的高度|
13 | |`wheelRotationX`|float|已X轴为轴心旋转角度,决定3D效果|
14 | |`wheelVelocityUnits`|integer|自动翻滚速度单位|
15 |
16 | + 1.2、[WheelMaskView](/wheelLibrary/src/main/java/jsc/kit/wheel/base/WheelMaskView.java)
17 |
18 | | 名称 | 类型 | 描述 |
19 | |:---|:---|:---|
20 | |`wheelMaskLineColor`|color|中间选中item的两条分割线颜色|
21 |
22 | + 1.3、[WheelItemView](/wheelLibrary/src/main/java/jsc/kit/wheel/base/WheelItemView.java)
23 |
24 | | 子View | 类型 | 属性 |
25 | |:---|:---|:---|
26 | |`wheelView`|[WheelView](/wheelLibrary/src/main/java/jsc/kit/wheel/base/WheelView.java)|[WheelView](/wheelLibrary/src/main/java/jsc/kit/wheel/base/WheelView.java)所有属性|
27 | |`wheelMaskView`|[WheelMaskView](/wheelLibrary/src/main/java/jsc/kit/wheel/base/WheelMaskView.java)|[WheelMaskView](/wheelLibrary/src/main/java/jsc/kit/wheel/base/WheelMaskView.java)所有属性|
28 |
29 | ### 2、usage
30 | | 组件 | 使用示例 |
31 | |:---|:---|
32 | |[WheelView](/wheelLibrary/src/main/java/jsc/kit/wheel/base/WheelView.java)|[WheelViewFragment](/app/src/main/java/jsc/exam/com/wheelview/fragments/WheelViewFragment.java)|
33 | |[ColumnWheelDialog](wheelLibrary/src/main/java/jsc/kit/wheel/dialog/ColumnWheelDialog.java)|[ColumnWheelFragment](/app/src/main/java/jsc/exam/com/wheelview/fragments/ColumnWheelFragment.java)|
34 | |[DateTimeWheelDialog](wheelLibrary/src/main/java/jsc/kit/wheel/dialog/DateTimeWheelDialog.java)|[DateTimeWheelFragment](/app/src/main/java/jsc/exam/com/wheelview/fragments/DateTimeWheelFragment.java)|
35 |
36 | ### 3、Screenshots
37 | + 3.1、[WheelView](/wheelLibrary/src/main/java/jsc/kit/wheel/base/WheelView.java)
38 |
39 | 
40 |
41 | + 3.2、[ColumnWheelDialog](/wheelLibrary/src/main/java/jsc/kit/wheel/dialog/ColumnWheelDialog.java)
42 |
43 | 
44 | 
45 | 
46 | 
47 | 
48 |
49 | + 3.3、[DateTimeWheelDialog](/wheelLibrary/src/main/java/jsc/kit/wheel/dialog/DateTimeWheelDialog.java)
50 |
51 | 
52 | 
53 | 
54 | 
55 | 
56 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | }
4 |
5 | android {
6 | compileSdk 32
7 |
8 | defaultConfig {
9 | applicationId "jsc.exam.com.wheelview"
10 | minSdk 21
11 | targetSdk 32
12 | versionCode 1
13 | versionName "1.0"
14 |
15 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
16 | }
17 |
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 | compileOptions {
25 | sourceCompatibility JavaVersion.VERSION_1_8
26 | targetCompatibility JavaVersion.VERSION_1_8
27 | }
28 | buildFeatures {
29 | viewBinding true
30 | }
31 | }
32 |
33 | dependencies {
34 |
35 | implementation 'androidx.appcompat:appcompat:1.3.0'
36 | implementation 'com.google.android.material:material:1.6.1'
37 | implementation project(path: ':wheelViewLibrary')
38 | implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
39 | testImplementation 'junit:junit:4.13.2'
40 | androidTestImplementation 'androidx.test.ext:junit:1.1.3'
41 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
42 | }
43 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/jsc/exam/com/wheelview/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package jsc.exam.com.wheelview;
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() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("jsc.exam.com.wheelview", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
15 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/java/jsc/exam/com/wheelview/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package jsc.exam.com.wheelview;
2 |
3 | import androidx.appcompat.app.AppCompatActivity;
4 |
5 | public abstract class BaseActivity extends AppCompatActivity {
6 |
7 | private boolean firstLoad = true;
8 |
9 | public abstract void onLazyLoad();
10 |
11 | public void onReLazyLoad() {
12 |
13 | }
14 |
15 | @Override
16 | protected void onResume() {
17 | super.onResume();
18 | if (firstLoad) {
19 | firstLoad = false;
20 | onLazyLoad();
21 | } else {
22 | onReLazyLoad();
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/app/src/main/java/jsc/exam/com/wheelview/BaseEmptyFragmentActivity.java:
--------------------------------------------------------------------------------
1 | package jsc.exam.com.wheelview;
2 |
3 | import android.content.pm.ActivityInfo;
4 | import android.os.Bundle;
5 | import android.view.Window;
6 | import android.view.WindowManager;
7 |
8 | import androidx.annotation.Nullable;
9 | import androidx.appcompat.app.ActionBar;
10 | import androidx.appcompat.app.AppCompatActivity;
11 | import androidx.fragment.app.Fragment;
12 |
13 | public abstract class BaseEmptyFragmentActivity extends AppCompatActivity {
14 |
15 | public final static String EXTRA_FULL_SCREEN = "full_screen";
16 | public final static String EXTRA_SHOW_ACTION_BAR = "show_action_bar";
17 | public final static String EXTRA_FRAGMENT_CLASS_NAME = "class_name";
18 | public final static String EXTRA_TITLE = "title";
19 | public final static String EXTRA_LANDSCAPE = "landscape";
20 |
21 | public abstract void initActionBar(ActionBar actionBar);
22 |
23 | @Override
24 | protected void onCreate(@Nullable Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | if (getIntent().getBooleanExtra(EXTRA_FULL_SCREEN, false)) {
27 | //without ActionBar
28 | requestWindowFeature(Window.FEATURE_NO_TITLE);
29 | if (getSupportActionBar() != null)
30 | getSupportActionBar().hide();
31 | //show full screen
32 | getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
33 | } else {
34 | if (getIntent().getBooleanExtra(EXTRA_SHOW_ACTION_BAR, true)) {
35 | initActionBar(getSupportActionBar());
36 | } else if (getSupportActionBar() != null) {
37 | getSupportActionBar().hide();
38 | }
39 | }
40 |
41 | String className = getIntent().getStringExtra(EXTRA_FRAGMENT_CLASS_NAME);
42 | if (className != null && className.length() > 0) {
43 | Class> clzz = null;
44 | Object obj = null;
45 | try {
46 | clzz = Class.forName(className);
47 | obj = clzz.newInstance();
48 | } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
49 | e.printStackTrace();
50 | }
51 | if (obj instanceof Fragment) {
52 | Fragment fragment = (Fragment) obj;
53 | Bundle arguments = getIntent().getExtras();
54 | if (arguments != null) {
55 | fragment.setArguments(arguments);
56 | }
57 | getSupportFragmentManager().beginTransaction().replace(android.R.id.content, fragment).commit();
58 | }
59 | }
60 | }
61 |
62 | @Override
63 | protected void onResume() {
64 | if (getIntent().getBooleanExtra(EXTRA_LANDSCAPE, false)
65 | && getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
66 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
67 | }
68 | super.onResume();
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/app/src/main/java/jsc/exam/com/wheelview/EmptyFragmentActivity.java:
--------------------------------------------------------------------------------
1 | package jsc.exam.com.wheelview;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.graphics.Color;
6 | import android.os.Bundle;
7 | import android.text.TextUtils;
8 | import android.util.TypedValue;
9 | import android.view.Gravity;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.widget.FrameLayout;
13 | import android.widget.ImageView;
14 | import android.widget.TextView;
15 |
16 | import androidx.appcompat.app.ActionBar;
17 | import androidx.appcompat.widget.ActionMenuView;
18 |
19 | import jsc.exam.com.wheelview.utils.CompatResourceUtils;
20 | import jsc.exam.com.wheelview.utils.WindowUtils;
21 |
22 | /**
23 | *
Email:1006368252@qq.com
24 | *
QQ:1006368252
25 | *
https://github.com/JustinRoom/WheelViewDemo
26 | *
27 | * @author jiangshicheng
28 | */
29 | public class EmptyFragmentActivity extends BaseEmptyFragmentActivity {
30 |
31 | public static void launch(Context context, Bundle extras) {
32 | context.startActivity(createIntent(context, extras));
33 | }
34 |
35 | private static Intent createIntent(Context context, Bundle extras) {
36 | Intent intent = new Intent(context, EmptyFragmentActivity.class);
37 | if (extras != null)
38 | intent.putExtras(extras);
39 | return intent;
40 | }
41 |
42 | @Override
43 | public void initActionBar(ActionBar actionBar) {
44 | if (actionBar == null)
45 | return;
46 |
47 | //You can initialize custom action bar here.
48 | int padding = CompatResourceUtils.getDimensionPixelSize(this, R.dimen.space_12);
49 | FrameLayout customView = new FrameLayout(this);
50 | // customView.setPadding(padding, 0, padding, 0);
51 | ActionBar.LayoutParams barParams = new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, WindowUtils.getActionBarSize(this));
52 | actionBar.setDisplayShowCustomEnabled(true);
53 | actionBar.setCustomView(customView, barParams);
54 | //添加标题
55 | TextView tvTitle = new TextView(this);
56 | tvTitle.setTextColor(Color.WHITE);
57 | tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
58 | tvTitle.setGravity(Gravity.CENTER);
59 | tvTitle.setText(getClass().getSimpleName().replace("Activity", ""));
60 | customView.addView(tvTitle, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
61 | //添加返回按钮
62 | ImageView ivBack = new ImageView(this);
63 | ivBack.setPadding(padding / 2, 0, padding / 2, 0);
64 | ivBack.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
65 | ivBack.setImageResource(R.drawable.ic_chevron_left_white_24dp);
66 | ivBack.setBackground(WindowUtils.getSelectableItemBackgroundBorderless(this));
67 | customView.addView(ivBack, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT));
68 | ivBack.setOnClickListener(new View.OnClickListener() {
69 | @Override
70 | public void onClick(View v) {
71 | onBackPressed();
72 | }
73 | });
74 | //添加menu菜单
75 | ActionMenuView actionMenuView = new ActionMenuView(this);
76 | FrameLayout.LayoutParams menuParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
77 | menuParams.gravity = Gravity.END | Gravity.CENTER_VERTICAL;
78 | customView.addView(actionMenuView, menuParams);
79 |
80 | String title = getIntent().getStringExtra(EXTRA_TITLE);
81 | tvTitle.setText(TextUtils.isEmpty(title) ? getClass().getSimpleName().replace("Activity", "") : title);
82 | }
83 | }
--------------------------------------------------------------------------------
/app/src/main/java/jsc/exam/com/wheelview/MainActivity.java:
--------------------------------------------------------------------------------
1 | package jsc.exam.com.wheelview;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.view.View;
6 |
7 | import jsc.exam.com.wheelview.bean.ClassItem;
8 | import jsc.exam.com.wheelview.databinding.ActivityMainBinding;
9 | import jsc.exam.com.wheelview.fragments.ColumnWheelFragment;
10 | import jsc.exam.com.wheelview.fragments.DateTimeWheelFragment;
11 | import jsc.exam.com.wheelview.fragments.WheelViewFragment;
12 | import jsc.exam.com.wheelview.utils.ViewOutlineUtils;
13 |
14 | public class MainActivity extends BaseActivity {
15 |
16 | ActivityMainBinding binding;
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | binding = ActivityMainBinding.inflate(getLayoutInflater());
21 | setContentView(binding.getRoot());
22 | binding.btnWheelView.setOnClickListener(new View.OnClickListener() {
23 | @Override
24 | public void onClick(View v) {
25 | toNewActivity(new ClassItem(ClassItem.TYPE_FRAGMENT, "WheelView", WheelViewFragment.class, true, true));
26 | }
27 | });
28 | binding.btnColumnWheelDialog.setOnClickListener(new View.OnClickListener() {
29 | @Override
30 | public void onClick(View v) {
31 | toNewActivity(new ClassItem(ClassItem.TYPE_FRAGMENT, "ColumnWheelDialog", ColumnWheelFragment.class, true, true));
32 | }
33 | });
34 | binding.btnDateTimeWheelDialog.setOnClickListener(new View.OnClickListener() {
35 | @Override
36 | public void onClick(View v) {
37 | toNewActivity(new ClassItem(ClassItem.TYPE_FRAGMENT, "DateTimeWheelDialog", DateTimeWheelFragment.class, true, true));
38 | }
39 | });
40 | ViewOutlineUtils.applyEllipticOutline(binding.btnWheelView);
41 | ViewOutlineUtils.applyEllipticOutline(binding.btnColumnWheelDialog);
42 | ViewOutlineUtils.applyEllipticOutline(binding.btnDateTimeWheelDialog);
43 | }
44 |
45 | private void toNewActivity(ClassItem item) {
46 | switch (item.getType()) {
47 | case ClassItem.TYPE_ACTIVITY:
48 | startActivity(new Intent(this, item.getClazz()));
49 | break;
50 | case ClassItem.TYPE_FRAGMENT:
51 | Bundle bundle = new Bundle();
52 | bundle.putString(EmptyFragmentActivity.EXTRA_TITLE, item.getLabel());
53 | bundle.putBoolean(EmptyFragmentActivity.EXTRA_FULL_SCREEN, false);
54 | bundle.putBoolean(EmptyFragmentActivity.EXTRA_SHOW_ACTION_BAR, true);
55 | if (item.isLandscape())
56 | bundle.putBoolean(EmptyFragmentActivity.EXTRA_LANDSCAPE, true);
57 | bundle.putString(EmptyFragmentActivity.EXTRA_FRAGMENT_CLASS_NAME, item.getClazz().getName());
58 | EmptyFragmentActivity.launch(this, bundle);
59 | break;
60 | }
61 | }
62 |
63 | @Override
64 | public void onLazyLoad() {
65 |
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/app/src/main/java/jsc/exam/com/wheelview/bean/ClassItem.java:
--------------------------------------------------------------------------------
1 | package jsc.exam.com.wheelview.bean;
2 |
3 |
4 | import androidx.annotation.IntDef;
5 |
6 | import java.lang.annotation.Retention;
7 | import java.lang.annotation.RetentionPolicy;
8 |
9 | public class ClassItem {
10 | public static final int TYPE_ACTIVITY = 0;
11 | public static final int TYPE_FRAGMENT = 1;
12 | @IntDef({TYPE_ACTIVITY, TYPE_FRAGMENT})
13 | @Retention(RetentionPolicy.SOURCE)
14 | public @interface Type {
15 | }
16 |
17 | private String label;
18 | private Class> clazz;
19 | private int type;
20 | private boolean updated;
21 | private boolean isLandscape;
22 |
23 | public ClassItem() {
24 | }
25 |
26 | public ClassItem(@Type int type, String label, Class> clazz, boolean updated) {
27 | this(type, label, clazz, updated, false);
28 | }
29 | public ClassItem(@Type int type, String label, Class> clazz, boolean updated, boolean isLandscape) {
30 | this.type = type;
31 | this.label = label;
32 | this.clazz = clazz;
33 | this.updated = updated;
34 | this.isLandscape = isLandscape;
35 | }
36 |
37 | public String getLabel() {
38 | return label;
39 | }
40 |
41 | public void setLabel(String label) {
42 | this.label = label;
43 | }
44 |
45 | public Class> getClazz() {
46 | return clazz;
47 | }
48 |
49 | public void setClazz(Class> clazz) {
50 | this.clazz = clazz;
51 | }
52 |
53 | public boolean isUpdated() {
54 | return updated;
55 | }
56 |
57 | public void setUpdated(boolean updated) {
58 | this.updated = updated;
59 | }
60 |
61 | public void setType(@Type int type) {
62 | this.type = type;
63 | }
64 |
65 | public int getType() {
66 | return type;
67 | }
68 |
69 | public boolean isLandscape() {
70 | return isLandscape;
71 | }
72 |
73 | public void setLandscape(boolean landscape) {
74 | isLandscape = landscape;
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/app/src/main/java/jsc/exam/com/wheelview/fragments/ColumnWheelFragment.java:
--------------------------------------------------------------------------------
1 | package jsc.exam.com.wheelview.fragments;
2 |
3 | import android.os.Bundle;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.TextView;
8 |
9 | import androidx.annotation.NonNull;
10 | import androidx.annotation.Nullable;
11 | import androidx.fragment.app.Fragment;
12 |
13 | import java.util.Random;
14 |
15 | import jsc.exam.com.wheelview.R;
16 | import jsc.kit.wheel.base.WheelItem;
17 | import jsc.kit.wheel.dialog.ColumnWheelDialog;
18 |
19 | /**
20 | *
Email:1006368252@qq.com
21 | *
QQ:1006368252
22 | *
https://github.com/JustinRoom/WheelViewDemo
23 | *
24 | * @author jiangshicheng
25 | */
26 | public class ColumnWheelFragment extends Fragment {
27 |
28 | TextView tvResult;
29 | ColumnWheelDialog dialog1 = null;
30 | ColumnWheelDialog dialog2 = null;
31 | ColumnWheelDialog dialog3 = null;
32 | ColumnWheelDialog dialog4 = null;
33 | ColumnWheelDialog dialog5 = null;
34 |
35 | @Nullable
36 | @Override
37 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
38 | View root = inflater.inflate(R.layout.fragment_wheel_dialog, container, false);
39 | tvResult = root.findViewById(R.id.tv_result);
40 | root.findViewById(R.id.btn_choose_time_1).setOnClickListener(new View.OnClickListener() {
41 | @Override
42 | public void onClick(View v) {
43 | if (dialog1 == null)
44 | dialog1 = createDialog(1);
45 | else
46 | dialog1.show();
47 | }
48 | });
49 | root.findViewById(R.id.btn_choose_time_2).setOnClickListener(new View.OnClickListener() {
50 | @Override
51 | public void onClick(View v) {
52 | if (dialog2 == null)
53 | dialog2 = createDialog(2);
54 | else
55 | dialog2.show();
56 | }
57 | });
58 | root.findViewById(R.id.btn_choose_time_3).setOnClickListener(new View.OnClickListener() {
59 | @Override
60 | public void onClick(View v) {
61 | if (dialog3 == null)
62 | dialog3 = createDialog(3);
63 | else
64 | dialog3.show();
65 | }
66 | });
67 | root.findViewById(R.id.btn_choose_time_4).setOnClickListener(new View.OnClickListener() {
68 | @Override
69 | public void onClick(View v) {
70 | if (dialog4 == null)
71 | dialog4 = createDialog(4);
72 | else
73 | dialog4.show();
74 | }
75 | });
76 | root.findViewById(R.id.btn_choose_time_5).setOnClickListener(new View.OnClickListener() {
77 | @Override
78 | public void onClick(View v) {
79 | if (dialog5 == null)
80 | dialog5 = createDialog(5);
81 | else
82 | dialog5.show();
83 | }
84 | });
85 | return root;
86 | }
87 |
88 | private ColumnWheelDialog createDialog(int type) {
89 | ColumnWheelDialog dialog = new ColumnWheelDialog<>(getActivity());
90 | dialog.show();
91 | dialog.setTitle("选择菜单");
92 | dialog.setCancelButton("取消", null);
93 | dialog.setOKButton("确定", new ColumnWheelDialog.OnClickCallBack() {
94 | @Override
95 | public boolean callBack(View v, @Nullable WheelItem item0, @Nullable WheelItem item1, @Nullable WheelItem item2, @Nullable WheelItem item3, @Nullable WheelItem item4) {
96 | String result = "";
97 | if (item0 != null)
98 | result += item0.getShowText() + "\n";
99 | if (item1 != null)
100 | result += item1.getShowText() + "\n";
101 | if (item2 != null)
102 | result += item2.getShowText() + "\n";
103 | if (item3 != null)
104 | result += item3.getShowText() + "\n";
105 | if (item4 != null)
106 | result += item4.getShowText() + "\n";
107 | tvResult.setText(result);
108 | return false;
109 | }
110 | });
111 | switch (type) {
112 | case 1:
113 | dialog.setItems(
114 | initItems("菜单选项一"),
115 | null,
116 | null,
117 | null,
118 | null
119 | );
120 | dialog.setSelected(
121 | new Random().nextInt(50),
122 | 0,
123 | 0,
124 | 0,
125 | 0
126 | );
127 | break;
128 | case 2:
129 | dialog.setItems(
130 | initItems("菜单选项一"),
131 | initItems("菜单选项二"),
132 | null,
133 | null,
134 | null
135 | );
136 | dialog.setSelected(
137 | new Random().nextInt(50),
138 | new Random().nextInt(50),
139 | 0,
140 | 0,
141 | 0
142 | );
143 | break;
144 | case 3:
145 | dialog.setItems(
146 | initItems("菜单选项一"),
147 | initItems("菜单选项二"),
148 | initItems("菜单选项三"),
149 | null,
150 | null
151 | );
152 | dialog.setSelected(
153 | new Random().nextInt(50),
154 | new Random().nextInt(50),
155 | new Random().nextInt(50),
156 | 0,
157 | 0
158 | );
159 | break;
160 | case 4:
161 | dialog.setItems(
162 | initItems("菜单选项一"),
163 | initItems("菜单选项二"),
164 | initItems("菜单选项三"),
165 | initItems("菜单选项四"),
166 | null
167 | );
168 | dialog.setSelected(
169 | new Random().nextInt(50),
170 | new Random().nextInt(50),
171 | new Random().nextInt(50),
172 | new Random().nextInt(50),
173 | 0
174 | );
175 | break;
176 | case 5:
177 | dialog.setItems(
178 | initItems("菜单选项一"),
179 | initItems("菜单选项二"),
180 | initItems("菜单选项三"),
181 | initItems("菜单选项四"),
182 | initItems("菜单选项五")
183 | );
184 | dialog.setSelected(
185 | new Random().nextInt(50),
186 | new Random().nextInt(50),
187 | new Random().nextInt(50),
188 | new Random().nextInt(50),
189 | new Random().nextInt(50)
190 | );
191 | break;
192 | }
193 | return dialog;
194 | }
195 |
196 | private WheelItem[] initItems(String label) {
197 | final WheelItem[] items = new WheelItem[50];
198 | for (int i = 0; i < 50; i++) {
199 | items[i] = new WheelItem(label + (i < 10 ? "0" + i : "" + i));
200 | }
201 | return items;
202 | }
203 | }
204 |
--------------------------------------------------------------------------------
/app/src/main/java/jsc/exam/com/wheelview/fragments/DateTimeWheelFragment.java:
--------------------------------------------------------------------------------
1 | package jsc.exam.com.wheelview.fragments;
2 |
3 | import android.os.Bundle;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.TextView;
8 |
9 | import androidx.annotation.NonNull;
10 | import androidx.annotation.Nullable;
11 | import androidx.fragment.app.Fragment;
12 |
13 | import java.text.SimpleDateFormat;
14 | import java.util.Calendar;
15 | import java.util.Date;
16 | import java.util.Random;
17 |
18 | import jsc.exam.com.wheelview.R;
19 | import jsc.kit.wheel.dialog.ColumnWheelDialog;
20 | import jsc.kit.wheel.dialog.DateTimeWheelDialog;
21 |
22 | /**
23 | *
Email:1006368252@qq.com
24 | *
QQ:1006368252
25 | *
https://github.com/JustinRoom/WheelViewDemo
26 | *
27 | * @author jiangshicheng
28 | */
29 | public class DateTimeWheelFragment extends Fragment {
30 |
31 | TextView tvResult;
32 | DateTimeWheelDialog dialog1 = null;
33 | DateTimeWheelDialog dialog2 = null;
34 | DateTimeWheelDialog dialog3 = null;
35 | DateTimeWheelDialog dialog4 = null;
36 | DateTimeWheelDialog dialog5 = null;
37 |
38 | @Nullable
39 | @Override
40 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
41 | View root = inflater.inflate(R.layout.fragment_wheel_dialog, container, false);
42 | tvResult = root.findViewById(R.id.tv_result);
43 | root.findViewById(R.id.btn_choose_time_1).setOnClickListener(new View.OnClickListener() {
44 | @Override
45 | public void onClick(View v) {
46 | if (dialog1 == null)
47 | dialog1 = createDialog(1);
48 | else
49 | dialog1.show();
50 | }
51 | });
52 | root.findViewById(R.id.btn_choose_time_2).setOnClickListener(new View.OnClickListener() {
53 | @Override
54 | public void onClick(View v) {
55 | if (dialog2 == null)
56 | dialog2 = createDialog(2);
57 | else
58 | dialog2.show();
59 | }
60 | });
61 | root.findViewById(R.id.btn_choose_time_3).setOnClickListener(new View.OnClickListener() {
62 | @Override
63 | public void onClick(View v) {
64 | if (dialog3 == null)
65 | dialog3 = createDialog(3);
66 | else
67 | dialog3.show();
68 | }
69 | });
70 | root.findViewById(R.id.btn_choose_time_4).setOnClickListener(new View.OnClickListener() {
71 | @Override
72 | public void onClick(View v) {
73 | if (dialog4 == null)
74 | dialog4 = createDialog(4);
75 | else
76 | dialog4.show();
77 | }
78 | });
79 | root.findViewById(R.id.btn_choose_time_5).setOnClickListener(new View.OnClickListener() {
80 | @Override
81 | public void onClick(View v) {
82 | if (dialog5 == null)
83 | dialog5 = createDialog(5);
84 | else
85 | dialog5.show();
86 | }
87 | });
88 | return root;
89 | }
90 |
91 | private DateTimeWheelDialog createDialog(int type) {
92 | Calendar calendar = Calendar.getInstance();
93 | calendar.set(Calendar.YEAR, 2022);
94 | calendar.set(Calendar.MONTH, 0);
95 | calendar.set(Calendar.DAY_OF_MONTH, 1);
96 | calendar.set(Calendar.HOUR_OF_DAY, 0);
97 | calendar.set(Calendar.MINUTE, 0);
98 | Date startDate = calendar.getTime();
99 | calendar = Calendar.getInstance();
100 | calendar.set(Calendar.YEAR, 2050);
101 | Date endDate = calendar.getTime();
102 |
103 | DateTimeWheelDialog dialog = new DateTimeWheelDialog(getActivity());
104 | // dialog.setShowCount(7);
105 | // dialog.setItemVerticalSpace(24);
106 | dialog.show();
107 | dialog.setTitle("选择时间");
108 | int config = DateTimeWheelDialog.SHOW_YEAR_MONTH_DAY_HOUR_MINUTE;
109 | switch (type) {
110 | case 1:
111 | config = DateTimeWheelDialog.SHOW_YEAR;
112 | break;
113 | case 2:
114 | config = DateTimeWheelDialog.SHOW_YEAR_MONTH;
115 | break;
116 | case 3:
117 | config = DateTimeWheelDialog.SHOW_YEAR_MONTH_DAY;
118 | break;
119 | case 4:
120 | config = DateTimeWheelDialog.SHOW_YEAR_MONTH_DAY_HOUR;
121 | break;
122 | case 5:
123 | config = DateTimeWheelDialog.SHOW_YEAR_MONTH_DAY_HOUR_MINUTE;
124 | break;
125 | }
126 | dialog.configShowUI(config);
127 | dialog.setCancelButton("取消", null);
128 | dialog.setOKButton("确定", new DateTimeWheelDialog.OnClickCallBack() {
129 | @Override
130 | public boolean callBack(View v, @NonNull Date selectedDate) {
131 | tvResult.setText(SimpleDateFormat.getInstance().format(selectedDate));
132 | return false;
133 | }
134 | });
135 | dialog.setDateArea(startDate, endDate, true);
136 | dialog.updateSelectedDate(new Date());
137 | return dialog;
138 | }
139 | }
140 |
--------------------------------------------------------------------------------
/app/src/main/java/jsc/exam/com/wheelview/fragments/WheelViewFragment.java:
--------------------------------------------------------------------------------
1 | package jsc.exam.com.wheelview.fragments;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.TextView;
9 |
10 | import androidx.annotation.NonNull;
11 | import androidx.annotation.Nullable;
12 | import androidx.fragment.app.Fragment;
13 |
14 | import java.util.Locale;
15 | import java.util.Random;
16 |
17 | import jsc.exam.com.wheelview.R;
18 | import jsc.kit.wheel.base.WheelItem;
19 | import jsc.kit.wheel.base.WheelItemView;
20 | import jsc.kit.wheel.base.WheelView;
21 |
22 | public class WheelViewFragment extends Fragment {
23 |
24 | TextView tvSelectedItems;
25 | WheelItemView wheelViewLeft;
26 | WheelItemView wheelViewCenter;
27 | WheelItemView wheelViewRight;
28 | WheelView.OnSelectedListener listener = new WheelView.OnSelectedListener() {
29 | @Override
30 | public void onSelected(Context context, int selectedIndex) {
31 | tvSelectedItems.setText(String.format(Locale.CHINA, "{left:%d, center:%d, right:%d}", wheelViewLeft.getSelectedIndex(), wheelViewCenter.getSelectedIndex(), wheelViewRight.getSelectedIndex()));
32 | }
33 | };
34 |
35 | @Nullable
36 | @Override
37 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
38 | View root = inflater.inflate(R.layout.fragment_wheel_view, container, false);
39 | tvSelectedItems = root.findViewById(R.id.tv_selected_items);
40 | wheelViewLeft = root.findViewById(R.id.wheel_view_left);
41 | wheelViewCenter = root.findViewById(R.id.wheel_view_center);
42 | wheelViewRight = root.findViewById(R.id.wheel_view_right);
43 | wheelViewLeft.setOnSelectedListener(listener);
44 | wheelViewCenter.setOnSelectedListener(listener);
45 | wheelViewRight.setOnSelectedListener(listener);
46 | root.findViewById(R.id.btn_random).setOnClickListener(new View.OnClickListener() {
47 | @Override
48 | public void onClick(View v) {
49 | wheelViewLeft.setSelectedIndex(new Random().nextInt(50));
50 | wheelViewCenter.setSelectedIndex(new Random().nextInt(50));
51 | wheelViewRight.setSelectedIndex(new Random().nextInt(50));
52 | }
53 | });
54 | loadData(wheelViewLeft, "很长的左边菜单");
55 | loadData(wheelViewCenter, "中间菜单");
56 | loadData(wheelViewRight, "很长的右边边菜单");
57 | return root;
58 | }
59 |
60 | private void loadData(WheelItemView wheelItemView) {
61 | String[] randomShowText = {"菜单", "子菜单", "父系菜单", "很长的家族菜单", "ScrollMenu"};
62 | Random random = new Random();
63 | WheelItem[] items = new WheelItem[50];
64 | for (int i = 0; i < 50; i++) {
65 | items[i] = new WheelItem(randomShowText[random.nextInt(5)] + (i < 10 ? "0" + i : "" + i));
66 | }
67 | wheelItemView.setItems(items);
68 | }
69 |
70 | private void loadData(WheelItemView wheelItemView, String label) {
71 | WheelItem[] items = new WheelItem[50];
72 | for (int i = 0; i < 50; i++) {
73 | items[i] = new WheelItem(label + (i < 10 ? "0" + i : "" + i));
74 | }
75 | wheelItemView.setItems(items);
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/app/src/main/java/jsc/exam/com/wheelview/utils/CompatResourceUtils.java:
--------------------------------------------------------------------------------
1 | package jsc.exam.com.wheelview.utils;
2 |
3 | import android.content.Context;
4 | import android.graphics.drawable.Drawable;
5 | import android.util.TypedValue;
6 | import android.view.View;
7 |
8 | import androidx.annotation.ColorRes;
9 | import androidx.annotation.DimenRes;
10 | import androidx.annotation.DrawableRes;
11 | import androidx.annotation.NonNull;
12 | import androidx.fragment.app.Fragment;
13 |
14 | /**
15 | *
Email:1006368252@qq.com
16 | *
QQ:1006368252
17 | *
https://github.com/JustinRoom/WheelViewDemo
18 | *
19 | * @author jiangshicheng
20 | */
21 | public class CompatResourceUtils {
22 |
23 | //color
24 | public static int getColor(@NonNull Context context, @ColorRes int resId){
25 | int color;
26 | if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M){
27 | color = context.getResources().getColor(resId, context.getTheme());
28 | } else {
29 | color = context.getResources().getColor(resId);
30 | }
31 | return color;
32 | }
33 |
34 | //drawable
35 | public static Drawable getDrawable(@NonNull Context context, @DrawableRes int resId){
36 | Drawable drawable;
37 | if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M){
38 | drawable = context.getResources().getDrawable(resId, context.getTheme());
39 | } else {
40 | drawable = context.getResources().getDrawable(resId);
41 | }
42 | return drawable;
43 | }
44 |
45 | //dimension
46 | public static int getDimensionPixelSize(@NonNull Context context, @DimenRes int id){
47 | return context.getResources().getDimensionPixelSize(id);
48 | }
49 |
50 | public static int getDimensionPixelSize(@NonNull View view, @DimenRes int id){
51 | return view.getResources().getDimensionPixelSize(id);
52 | }
53 |
54 | public static int getDimensionPixelSize(@NonNull Fragment fragment, @DimenRes int id){
55 | return fragment.getResources().getDimensionPixelSize(id);
56 | }
57 |
58 | public static int dp2Px(@NonNull Context context, float dp){
59 | return (int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, context.getResources().getDisplayMetrics()) + .5f);
60 | }
61 | }
--------------------------------------------------------------------------------
/app/src/main/java/jsc/exam/com/wheelview/utils/ViewOutlineUtils.java:
--------------------------------------------------------------------------------
1 | package jsc.exam.com.wheelview.utils;
2 |
3 | import android.graphics.Outline;
4 | import android.graphics.Path;
5 | import android.os.Build;
6 | import android.view.View;
7 | import android.view.ViewOutlineProvider;
8 |
9 | public class ViewOutlineUtils {
10 |
11 | /**
12 | * 圆
13 | *
14 | * @param view
15 | */
16 | public static void applyCircleOutline(View view) {
17 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
18 | view.setOutlineProvider(new ViewOutlineProvider() {
19 | @Override
20 | public void getOutline(View view, Outline outline) {
21 | if (view.getWidth() > 0 && view.getHeight() > 0) {
22 | int min = Math.min(view.getWidth(), view.getHeight());
23 | int l = (view.getWidth() - min) / 2;
24 | int t = (view.getHeight() - min) / 2;
25 | outline.setOval(l, t, l + min, t + min);
26 | }
27 | }
28 | });
29 | view.setClipToOutline(true);
30 | }
31 | }
32 |
33 | /**
34 | * 椭圆
35 | *
36 | * @param view
37 | */
38 | public static void applyEllipticOutline(View view) {
39 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
40 | view.setOutlineProvider(new ViewOutlineProvider() {
41 | @Override
42 | public void getOutline(View view, Outline outline) {
43 | if (view.getWidth() > 0 && view.getHeight() > 0) {
44 | float radius = Math.min(view.getWidth(), view.getHeight()) / 2.0f;
45 | outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), radius);
46 | }
47 | }
48 | });
49 | view.setClipToOutline(true);
50 | }
51 | }
52 |
53 | /**
54 | * 椭圆
55 | *
56 | * @param view
57 | */
58 | public static void applyHorizontalEllipticOutline(View view) {
59 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
60 | view.setOutlineProvider(new ViewOutlineProvider() {
61 | @Override
62 | public void getOutline(View view, Outline outline) {
63 | if (view.getWidth() > 0 && view.getHeight() > 0) {
64 | float radius = view.getHeight() / 2.0f;
65 | outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), radius);
66 | }
67 | }
68 | });
69 | view.setClipToOutline(true);
70 | }
71 | }
72 |
73 | /**
74 | * 圆角
75 | *
76 | * @param view
77 | * @param radius
78 | */
79 | public static void applyRoundOutline(View view, final float radius) {
80 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
81 | view.setOutlineProvider(new ViewOutlineProvider() {
82 | @Override
83 | public void getOutline(View view, Outline outline) {
84 | if (view.getWidth() > 0 && view.getHeight() > 0) {
85 | outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), radius);
86 | }
87 | }
88 | });
89 | view.setClipToOutline(true);
90 | }
91 | }
92 |
93 | /**
94 | * 左下、右下圆角
95 | *
96 | * @param view
97 | * @param radius
98 | */
99 | public static void applyBottomRoundOutline(View view, final float radius) {
100 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
101 | view.setOutlineProvider(new ViewOutlineProvider() {
102 | @Override
103 | public void getOutline(View view, Outline outline) {
104 | if (view.getWidth() > 0 && view.getHeight() > 0) {
105 | int bottomExtra = (int) (view.getHeight() + radius + 0.5f);
106 | outline.setRoundRect(0, 0 - bottomExtra, view.getWidth(), view.getHeight(), radius);
107 | }
108 | }
109 | });
110 | view.setClipToOutline(true);
111 | }
112 | }
113 |
114 | /**
115 | * 左上、右上圆角
116 | *
117 | * @param view
118 | * @param radius
119 | */
120 | public static void applyTopRoundOutline(View view, final float radius) {
121 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
122 | view.setOutlineProvider(new ViewOutlineProvider() {
123 | @Override
124 | public void getOutline(View view, Outline outline) {
125 | if (view.getWidth() > 0 && view.getHeight() > 0) {
126 | int bottomExtra = (int) (view.getHeight() + radius + 0.5f);
127 | outline.setRoundRect(0, 0, view.getWidth(), view.getHeight() + bottomExtra, radius);
128 | }
129 | }
130 | });
131 | view.setClipToOutline(true);
132 | }
133 | }
134 |
135 | /**
136 | * 左上、右上圆角
137 | *
138 | * @param view
139 | */
140 | public static void applyTopRoundOutlineLR(View view) {
141 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
142 | view.setOutlineProvider(new ViewOutlineProvider() {
143 | @Override
144 | public void getOutline(View view, Outline outline) {
145 | if (view.getWidth() > 0 && view.getHeight() > 0) {
146 | float radius = view.getHeight() / 2.0f;
147 | outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), radius);
148 | }
149 | }
150 | });
151 | view.setClipToOutline(true);
152 | }
153 | }
154 |
155 |
156 | public static void applyConvexPathOutline(View view, final float radius) {
157 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
158 | view.setOutlineProvider(new ViewOutlineProvider() {
159 | @Override
160 | public void getOutline(View view, Outline outline) {
161 | if (view.getWidth() > 0 && view.getHeight() > 0) {
162 | Path path = new Path();
163 | path.moveTo(0, view.getHeight());
164 | path.lineTo(0, radius);
165 | path.quadTo(0, 0, radius, 0);
166 | path.lineTo(view.getWidth() - radius, 0);
167 | path.quadTo(view.getWidth(), 0, view.getWidth(), radius);
168 | path.lineTo(view.getWidth(), view.getHeight());
169 | path.close();
170 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q || path.isConvex()) {
171 | outline.setConvexPath(path);
172 | }
173 | }
174 | }
175 | });
176 | view.setClipToOutline(true);
177 | }
178 | }
179 |
180 | public static void clearOutline(View view) {
181 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
182 | view.setOutlineProvider(null);
183 | view.setClipToOutline(false);
184 | }
185 | }
186 | }
187 |
--------------------------------------------------------------------------------
/app/src/main/java/jsc/exam/com/wheelview/utils/WindowUtils.java:
--------------------------------------------------------------------------------
1 | package jsc.exam.com.wheelview.utils;
2 |
3 | import android.annotation.TargetApi;
4 | import android.content.Context;
5 | import android.content.res.TypedArray;
6 | import android.graphics.drawable.Drawable;
7 | import android.os.Build;
8 | import android.util.TypedValue;
9 |
10 | import androidx.annotation.NonNull;
11 |
12 | /**
13 | *
Email:1006368252@qq.com
14 | *
QQ:1006368252
15 | *
https://github.com/JustinRoom/WheelViewDemo
16 | *
17 | * @author jiangshicheng
18 | */
19 | public final class WindowUtils {
20 |
21 | /**
22 | * Get status bar height.
23 | *
24 | * @param context context
25 | * @return the height of status bar
26 | */
27 | public static int getStatusBarHeight(@NonNull Context context) {
28 | int statusBarHeight = 0;
29 | int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
30 | if (resourceId > 0) {
31 | statusBarHeight = CompatResourceUtils.getDimensionPixelSize(context, resourceId);
32 | }
33 | return statusBarHeight;
34 | }
35 |
36 | /**
37 | * Get action bar height.
38 | *
39 | * @param context context
40 | * @return the height of action bar
41 | */
42 | public static int getActionBarSize(@NonNull Context context) {
43 | TypedValue typedValue = new TypedValue();
44 | int[] attribute = new int[]{android.R.attr.actionBarSize};
45 | TypedArray array = context.obtainStyledAttributes(typedValue.resourceId, attribute);
46 | int actionBarSize = array.getDimensionPixelSize(0, 0);
47 | array.recycle();
48 | return actionBarSize;
49 | }
50 |
51 | /**
52 | * Get system selectable item background borderless.
53 | * @param context context
54 | * @return selectable item background borderless
55 | */
56 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
57 | public static Drawable getSelectableItemBackgroundBorderless(Context context){
58 | TypedValue typedValue = new TypedValue();
59 | context.getTheme().resolveAttribute(android.R.attr.selectableItemBackgroundBorderless, typedValue, true);
60 | int[] attribute = new int[]{android.R.attr.selectableItemBackgroundBorderless};
61 | TypedArray typedArray = context.obtainStyledAttributes(typedValue.resourceId, attribute);
62 | Drawable drawable = typedArray.getDrawable(0);
63 | typedArray.recycle();
64 | return drawable;
65 | }
66 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v21/item_background_ripple_001.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 | -
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/btn_background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JustinRoom/WheelViewDemo/df0e3f0ad2ae24c822b9aae26d33bac4ce349845/app/src/main/res/drawable-xxhdpi/btn_background.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_chevron_left_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JustinRoom/WheelViewDemo/df0e3f0ad2ae24c822b9aae26d33bac4ce349845/app/src/main/res/drawable-xxhdpi/ic_chevron_left_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/kit_ic_assignment_blue_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JustinRoom/WheelViewDemo/df0e3f0ad2ae24c822b9aae26d33bac4ce349845/app/src/main/res/drawable-xxhdpi/kit_ic_assignment_blue_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/kit_ic_chevron_right_gray_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JustinRoom/WheelViewDemo/df0e3f0ad2ae24c822b9aae26d33bac4ce349845/app/src/main/res/drawable-xxhdpi/kit_ic_chevron_right_gray_24dp.png
--------------------------------------------------------------------------------
/app/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 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ripple_round_corner_white_r4.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 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/wheel_view_demo_qr_code.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JustinRoom/WheelViewDemo/df0e3f0ad2ae24c822b9aae26d33bac4ce349845/app/src/main/res/drawable/wheel_view_demo_qr_code.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
22 |
23 |
36 |
37 |
50 |
51 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_wheel_dialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
21 |
22 |
27 |
28 |
33 |
34 |
39 |
40 |
45 |
46 |
47 |
48 |
53 |
54 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_wheel_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
22 |
23 |
29 |
30 |
37 |
38 |
39 |
40 |
47 |
48 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JustinRoom/WheelViewDemo/df0e3f0ad2ae24c822b9aae26d33bac4ce349845/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JustinRoom/WheelViewDemo/df0e3f0ad2ae24c822b9aae26d33bac4ce349845/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JustinRoom/WheelViewDemo/df0e3f0ad2ae24c822b9aae26d33bac4ce349845/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JustinRoom/WheelViewDemo/df0e3f0ad2ae24c822b9aae26d33bac4ce349845/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JustinRoom/WheelViewDemo/df0e3f0ad2ae24c822b9aae26d33bac4ce349845/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JustinRoom/WheelViewDemo/df0e3f0ad2ae24c822b9aae26d33bac4ce349845/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JustinRoom/WheelViewDemo/df0e3f0ad2ae24c822b9aae26d33bac4ce349845/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JustinRoom/WheelViewDemo/df0e3f0ad2ae24c822b9aae26d33bac4ce349845/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JustinRoom/WheelViewDemo/df0e3f0ad2ae24c822b9aae26d33bac4ce349845/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JustinRoom/WheelViewDemo/df0e3f0ad2ae24c822b9aae26d33bac4ce349845/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 48dp
4 |
5 | 1dip
6 | 2dip
7 | 3dip
8 | 4dip
9 | 5dip
10 | 6dip
11 | 7dip
12 | 8dip
13 | 9dip
14 | 10dip
15 | 11dip
16 | 12dip
17 | 13dip
18 | 14dip
19 | 15dip
20 | 16dip
21 | 17dip
22 | 18dip
23 | 19dip
24 | 20dip
25 | 21dip
26 | 22dip
27 | 23dip
28 | 24dip
29 | 25dip
30 | 26dip
31 | 27dip
32 | 28dip
33 | 29dip
34 | 30dip
35 | 31dip
36 | 32dip
37 | 33dip
38 | 34dip
39 | 35dip
40 | 36dip
41 | 37dip
42 | 38dip
43 | 39dip
44 | 40dip
45 | 41dip
46 | 42dip
47 | 43dip
48 | 44dip
49 | 45dip
50 | 46dip
51 | 47dip
52 | 48dip
53 | 49dip
54 | 50dip
55 | 56dip
56 | 64dip
57 | 72dip
58 |
59 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | WheelView
3 |
4 | \n1、update DateTimeWheelDialog component.
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/test/java/jsc/exam/com/wheelview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package jsc.exam.com.wheelview;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 | plugins {
3 | id 'com.android.application' version '7.2.1' apply false
4 | id 'com.android.library' version '7.2.1' apply false
5 | }
6 |
7 | task clean(type: Delete) {
8 | delete rootProject.buildDir
9 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app"s APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Enables namespacing of each library's R class so that its R class includes only the
19 | # resources declared in the library itself and none from the library's dependencies,
20 | # thereby reducing the size of the R class for that library
21 | android.nonTransitiveRClass=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JustinRoom/WheelViewDemo/df0e3f0ad2ae24c822b9aae26d33bac4ce349845/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Aug 10 13:54:57 CST 2023
2 | distributionBase=GRADLE_USER_HOME
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
4 | distributionPath=wrapper/dists
5 | zipStorePath=wrapper/dists
6 | zipStoreBase=GRADLE_USER_HOME
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/output/WheelDemo.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JustinRoom/WheelViewDemo/df0e3f0ad2ae24c822b9aae26d33bac4ce349845/output/WheelDemo.apk
--------------------------------------------------------------------------------
/output/output.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "outputType": {
4 | "type": "APK"
5 | },
6 | "apkData": {
7 | "type": "MAIN",
8 | "splits": [],
9 | "versionCode": 13,
10 | "versionName": "0.5.4",
11 | "enabled": true,
12 | "outputFile": "WheelDemo.apk",
13 | "fullName": "release",
14 | "baseName": "release",
15 | "content": "\n1、update DateTimeWheelDialog component."
16 | },
17 | "path": "WheelDemo.apk",
18 | "properties": {}
19 | }
20 | ]
--------------------------------------------------------------------------------
/output/shots/column_wheel01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JustinRoom/WheelViewDemo/df0e3f0ad2ae24c822b9aae26d33bac4ce349845/output/shots/column_wheel01.png
--------------------------------------------------------------------------------
/output/shots/column_wheel02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JustinRoom/WheelViewDemo/df0e3f0ad2ae24c822b9aae26d33bac4ce349845/output/shots/column_wheel02.png
--------------------------------------------------------------------------------
/output/shots/column_wheel03.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JustinRoom/WheelViewDemo/df0e3f0ad2ae24c822b9aae26d33bac4ce349845/output/shots/column_wheel03.png
--------------------------------------------------------------------------------
/output/shots/column_wheel04.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JustinRoom/WheelViewDemo/df0e3f0ad2ae24c822b9aae26d33bac4ce349845/output/shots/column_wheel04.png
--------------------------------------------------------------------------------
/output/shots/column_wheel05.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JustinRoom/WheelViewDemo/df0e3f0ad2ae24c822b9aae26d33bac4ce349845/output/shots/column_wheel05.png
--------------------------------------------------------------------------------
/output/shots/date_time_wheel01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JustinRoom/WheelViewDemo/df0e3f0ad2ae24c822b9aae26d33bac4ce349845/output/shots/date_time_wheel01.png
--------------------------------------------------------------------------------
/output/shots/date_time_wheel02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JustinRoom/WheelViewDemo/df0e3f0ad2ae24c822b9aae26d33bac4ce349845/output/shots/date_time_wheel02.png
--------------------------------------------------------------------------------
/output/shots/date_time_wheel03.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JustinRoom/WheelViewDemo/df0e3f0ad2ae24c822b9aae26d33bac4ce349845/output/shots/date_time_wheel03.png
--------------------------------------------------------------------------------
/output/shots/date_time_wheel04.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JustinRoom/WheelViewDemo/df0e3f0ad2ae24c822b9aae26d33bac4ce349845/output/shots/date_time_wheel04.png
--------------------------------------------------------------------------------
/output/shots/date_time_wheel05.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JustinRoom/WheelViewDemo/df0e3f0ad2ae24c822b9aae26d33bac4ce349845/output/shots/date_time_wheel05.png
--------------------------------------------------------------------------------
/output/shots/wheel_view.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JustinRoom/WheelViewDemo/df0e3f0ad2ae24c822b9aae26d33bac4ce349845/output/shots/wheel_view.png
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | pluginManagement {
2 | repositories {
3 | gradlePluginPortal()
4 | google()
5 | mavenCentral()
6 | }
7 | }
8 | dependencyResolutionManagement {
9 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
10 | repositories {
11 | google()
12 | mavenCentral()
13 | }
14 | }
15 | rootProject.name = "WheelViewDemo"
16 | include ':app'
17 | include ':wheelViewLibrary'
18 |
--------------------------------------------------------------------------------
/wheelViewLibrary/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/wheelViewLibrary/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.library'
3 | }
4 |
5 | android {
6 | compileSdk 32
7 |
8 | defaultConfig {
9 | minSdk 21
10 | targetSdk 32
11 |
12 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
13 | consumerProguardFiles "consumer-rules.pro"
14 | }
15 |
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | compileOptions {
23 | sourceCompatibility JavaVersion.VERSION_1_8
24 | targetCompatibility JavaVersion.VERSION_1_8
25 | }
26 | }
27 |
28 | dependencies {
29 |
30 | implementation 'androidx.appcompat:appcompat:1.3.0'
31 | implementation 'com.google.android.material:material:1.6.1'
32 | testImplementation 'junit:junit:4.13.2'
33 | androidTestImplementation 'androidx.test.ext:junit:1.1.3'
34 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
35 | }
--------------------------------------------------------------------------------
/wheelViewLibrary/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 |
--------------------------------------------------------------------------------
/wheelViewLibrary/src/androidTest/java/jsc/kit/wheel/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package jsc.kit.wheel;
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() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("jsc.kit.wheel.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/wheelViewLibrary/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/wheelViewLibrary/src/main/java/jsc/kit/wheel/base/IWheel.java:
--------------------------------------------------------------------------------
1 | package jsc.kit.wheel.base;
2 |
3 | /**
4 | *
Email:1006368252@qq.com
5 | *
QQ:1006368252
6 | *
https://github.com/JustinRoom/WheelViewDemo
7 | *
8 | * @author jiangshicheng
9 | */
10 | public interface IWheel {
11 |
12 | String getShowText();
13 | }
14 |
--------------------------------------------------------------------------------
/wheelViewLibrary/src/main/java/jsc/kit/wheel/base/IWheelViewSetting.java:
--------------------------------------------------------------------------------
1 | package jsc.kit.wheel.base;
2 |
3 | import androidx.annotation.ColorInt;
4 |
5 | /**
6 | *
Email:1006368252@qq.com
7 | *
QQ:1006368252
8 | *
https://github.com/JustinRoom/WheelViewDemo
9 | *
10 | * @author jiangshicheng
11 | */
12 | public interface IWheelViewSetting {
13 |
14 | void setTextSize(float textSize);
15 |
16 | void setTextColor(@ColorInt int textColor);
17 |
18 | void setShowCount(int showCount);
19 |
20 | void setTotalOffsetX(int totalOffsetX);
21 |
22 | void setItemVerticalSpace(int itemVerticalSpace);
23 |
24 | void setItems(IWheel[] items);
25 |
26 | int getSelectedIndex();
27 |
28 | void setSelectedIndex(int targetIndexPosition);
29 |
30 | void setSelectedIndex(int targetIndexPosition, boolean withAnimation);
31 |
32 | void setOnSelectedListener(WheelView.OnSelectedListener onSelectedListener);
33 |
34 | boolean isScrolling();
35 | }
36 |
--------------------------------------------------------------------------------
/wheelViewLibrary/src/main/java/jsc/kit/wheel/base/WheelItem.java:
--------------------------------------------------------------------------------
1 | package jsc.kit.wheel.base;
2 |
3 | /**
4 | *
Email:1006368252@qq.com
5 | *
QQ:1006368252
6 | *
https://github.com/JustinRoom/WheelViewDemo
7 | *
8 | * @author jiangshicheng
9 | */
10 | public class WheelItem implements IWheel {
11 |
12 | String label;
13 |
14 | public WheelItem(String label) {
15 | this.label = label;
16 | }
17 |
18 | @Override
19 | public String getShowText() {
20 | return label;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/wheelViewLibrary/src/main/java/jsc/kit/wheel/base/WheelItemView.java:
--------------------------------------------------------------------------------
1 | package jsc.kit.wheel.base;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Color;
6 | import android.util.AttributeSet;
7 | import android.util.TypedValue;
8 | import android.view.ViewGroup;
9 | import android.widget.FrameLayout;
10 |
11 | import androidx.annotation.ColorInt;
12 | import androidx.annotation.NonNull;
13 | import androidx.annotation.Nullable;
14 |
15 | import jsc.kit.wheel.R;
16 |
17 | /**
18 | * Wheel view with selected mask.
19 | *
20 | *
Email:1006368252@qq.com
21 | *
QQ:1006368252
22 | *
https://github.com/JustinRoom/WheelViewDemo
23 | *
24 | * @author jiangshicheng
25 | */
26 | public class WheelItemView extends FrameLayout implements IWheelViewSetting {
27 |
28 | private WheelView wheelView;
29 | private WheelMaskView wheelMaskView;
30 |
31 | public WheelItemView(@NonNull Context context) {
32 | super(context);
33 | initAttr(context, null, 0);
34 | }
35 |
36 | public WheelItemView(@NonNull Context context, @Nullable AttributeSet attrs) {
37 | super(context, attrs);
38 | initAttr(context, attrs, 0);
39 | }
40 |
41 | public WheelItemView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
42 | super(context, attrs, defStyleAttr);
43 | initAttr(context, attrs, defStyleAttr);
44 | }
45 |
46 | private void initAttr(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
47 | wheelView = new WheelView(context);
48 | wheelView.initAttr(context, attrs, defStyleAttr);
49 | wheelMaskView = new WheelMaskView(context);
50 | wheelMaskView.initAttr(context, attrs, defStyleAttr);
51 | addView(wheelView, new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
52 | addView(wheelMaskView, new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
53 | }
54 |
55 | @Override
56 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
57 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
58 | ViewGroup.LayoutParams params = wheelMaskView.getLayoutParams();
59 | params.height = wheelView.getMeasuredHeight();
60 | wheelMaskView.setLayoutParams(params);
61 | wheelMaskView.updateMask(wheelView.getShowCount(), wheelView.getItemHeight());
62 | }
63 |
64 | @Override
65 | public void setTextSize(float textSize) {
66 | wheelView.setTextSize(textSize);
67 | }
68 |
69 | @Override
70 | public void setTextColor(@ColorInt int textColor) {
71 | wheelView.setTextColor(textColor);
72 | }
73 |
74 | @Override
75 | public void setShowCount(int showCount) {
76 | wheelView.setShowCount(showCount);
77 | }
78 |
79 | @Override
80 | public void setTotalOffsetX(int totalOffsetX) {
81 | wheelView.setTotalOffsetX(totalOffsetX);
82 | }
83 |
84 | @Override
85 | public void setItemVerticalSpace(int itemVerticalSpace) {
86 | wheelView.setItemVerticalSpace(itemVerticalSpace);
87 | }
88 |
89 | @Override
90 | public void setItems(IWheel[] items) {
91 | wheelView.setItems(items);
92 | }
93 |
94 | @Override
95 | public int getSelectedIndex() {
96 | return wheelView.getSelectedIndex();
97 | }
98 |
99 | @Override
100 | public void setSelectedIndex(int targetIndexPosition) {
101 | setSelectedIndex(targetIndexPosition, true);
102 | }
103 |
104 | @Override
105 | public void setSelectedIndex(int targetIndexPosition, boolean withAnimation) {
106 | wheelView.setSelectedIndex(targetIndexPosition, withAnimation);
107 | }
108 |
109 | @Override
110 | public void setOnSelectedListener(WheelView.OnSelectedListener onSelectedListener) {
111 | wheelView.setOnSelectedListener(onSelectedListener);
112 | }
113 |
114 | public void setMaskLineColor(@ColorInt int color) {
115 | wheelMaskView.setLineColor(color);
116 | }
117 |
118 | @Override
119 | public boolean isScrolling() {
120 | return wheelView.isScrolling();
121 | }
122 |
123 | public WheelView getWheelView() {
124 | return wheelView;
125 | }
126 |
127 | public WheelMaskView getWheelMaskView() {
128 | return wheelMaskView;
129 | }
130 | }
131 |
--------------------------------------------------------------------------------
/wheelViewLibrary/src/main/java/jsc/kit/wheel/base/WheelMaskView.java:
--------------------------------------------------------------------------------
1 | package jsc.kit.wheel.base;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Canvas;
6 | import android.graphics.Color;
7 | import android.graphics.Paint;
8 | import android.util.AttributeSet;
9 | import android.view.View;
10 |
11 | import androidx.annotation.ColorInt;
12 | import androidx.annotation.Nullable;
13 |
14 | import jsc.kit.wheel.R;
15 |
16 | /**
17 | *
Email:1006368252@qq.com
18 | *
QQ:1006368252
19 | *
https://github.com/JustinRoom/WheelViewDemo
20 | *
21 | * @author jiangshicheng
22 | */
23 | public class WheelMaskView extends View {
24 |
25 | private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
26 | private int top = 0;
27 | private int bottom = 0;
28 | private int lineColor = 0x8F0000FF;
29 |
30 | public WheelMaskView(Context context) {
31 | super(context);
32 | initAttr(context, null, 0);
33 | }
34 |
35 | public WheelMaskView(Context context, @Nullable AttributeSet attrs) {
36 | super(context, attrs);
37 | initAttr(context, attrs, 0);
38 | }
39 |
40 | public WheelMaskView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
41 | super(context, attrs, defStyleAttr);
42 | initAttr(context, attrs, defStyleAttr);
43 | }
44 |
45 | public void initAttr(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
46 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.WheelMaskView, defStyleAttr, 0);
47 | lineColor = a.getColor(R.styleable.WheelMaskView_wheelMaskLineColor, 0x8F0000FF);
48 | a.recycle();
49 |
50 | paint.setStyle(Paint.Style.STROKE);
51 | paint.setStrokeWidth(1);
52 | }
53 |
54 | public void updateMask(int heightCount, int itemHeight) {
55 | if (heightCount > 0) {
56 | int centerIndex = heightCount / 2;
57 | top = centerIndex * itemHeight;
58 | bottom = top + itemHeight;
59 | } else {
60 | top = 0;
61 | bottom = 0;
62 | }
63 | invalidate();
64 | }
65 |
66 | public void setLineColor(@ColorInt int lineColor) {
67 | this.lineColor = lineColor;
68 | invalidate();
69 | }
70 |
71 | @Override
72 | protected void onDraw(Canvas canvas) {
73 | if (top > 0 && bottom > 0) {
74 | paint.setColor(lineColor);
75 | canvas.drawLine(0, top, getWidth(), top, paint);
76 | canvas.drawLine(0, bottom, getWidth(), bottom, paint);
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/wheelViewLibrary/src/main/java/jsc/kit/wheel/base/WheelView.java:
--------------------------------------------------------------------------------
1 | package jsc.kit.wheel.base;
2 |
3 | import android.animation.Animator;
4 | import android.animation.ValueAnimator;
5 | import android.content.Context;
6 | import android.content.res.TypedArray;
7 | import android.graphics.Camera;
8 | import android.graphics.Canvas;
9 | import android.graphics.Color;
10 | import android.graphics.Matrix;
11 | import android.graphics.Paint;
12 | import android.graphics.Rect;
13 | import android.graphics.RectF;
14 | import android.text.TextPaint;
15 | import android.util.AttributeSet;
16 | import android.util.TypedValue;
17 | import android.view.MotionEvent;
18 | import android.view.VelocityTracker;
19 | import android.view.View;
20 | import android.view.ViewConfiguration;
21 | import android.view.animation.LinearInterpolator;
22 | import android.widget.OverScroller;
23 |
24 | import androidx.annotation.ColorInt;
25 | import androidx.annotation.Nullable;
26 |
27 | import jsc.kit.wheel.R;
28 |
29 | /**
30 | * Wheel view without selected mask.
31 | *
32 | *
33 | * {@code attrs:}
34 | *
{@link R.styleable#WheelView_wheelTextColor}
35 | *
{@link R.styleable#WheelView_wheelTextSize}
36 | *
{@link R.styleable#WheelView_wheelShowCount}
37 | *
{@link R.styleable#WheelView_wheelTotalOffsetX}
38 | *
{@link R.styleable#WheelView_wheelItemVerticalSpace}
39 | *
40 | *
Email:1006368252@qq.com
41 | *
QQ:1006368252
42 | *
https://github.com/JustinRoom/WheelViewDemo
43 | *
44 | * @author jiangshicheng
45 | */
46 | public class WheelView extends View implements IWheelViewSetting {
47 |
48 | private final String TAG = "WheelView";
49 | private static final float DEFAULT_ROTATION_X = 45.0f;
50 | private static final int DEFAULT_VELOCITY_UNITS = 600;
51 | private TextPaint textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
52 | private Camera camera = new Camera();
53 | private Matrix matrix = new Matrix();
54 | private float textBaseLine = 0;
55 |
56 | private IWheel[] items = null;
57 | /**
58 | * The color of show text.
59 | */
60 | private int textColor = Color.BLACK;
61 | /**
62 | * The size of showing text.
63 | * Default value is 14dp.
64 | */
65 | private float textSize = 0.0f;
66 | /**
67 | * The offset pixel from x coordination.
68 | *
text align {@code right} with a positive value
69 | *
text align {@code center} with 0 value
70 | *
text align {@code left} with a negative value
71 | */
72 | private int totalOffsetX = 0;
73 | /**
74 | * the average pixel length of show text.
75 | */
76 | private float averageShowTextLength = 0;
77 | /**
78 | * The most showing item count.
79 | * use it to measure view's height
80 | */
81 | private int showCount = 5;
82 | /**
83 | * The most draw item count.
84 | */
85 | private int drawCount = showCount + 2;
86 | private Rect[] defaultRectArray = null;
87 | private Rect[] drawRectArray = null;
88 | private int offsetY = 0;
89 | private int totalMoveY = 0;//
90 | private float wheelRotationX = 0;
91 | private int velocityUnits = 0;
92 |
93 | /**
94 | * the space width of two items
95 | */
96 | private int itemVerticalSpace = 0;
97 | /**
98 | * the height of every item
99 | */
100 | private int itemHeight = 0;
101 | private float lastX = 0.0f;
102 | private float lastY = 0.0f;
103 | private int[] calculateResult = new int[2];//for saving the calculate result.
104 | private int selectedIndex = 0;//the selected index position
105 | private OnSelectedListener onSelectedListener = null;
106 | private ValueAnimator animator = null;
107 | private boolean isScrolling = false;
108 | private boolean isAnimatorCanceledForwardly = false;//whether cancel auto scroll animation forwardly
109 |
110 | private static final long CLICK_EVENT_INTERNAL_TIME = 1000;
111 | private RectF rectF = new RectF();
112 | private long touchDownTimeStamp = 0;
113 |
114 | //about fling action
115 | private int mMinimumVelocity;
116 | private int mMaximumVelocity;
117 | private int scaledTouchSlop;
118 | private VelocityTracker mVelocityTracker = null;
119 | private OverScroller mOverScroller;
120 | private int flingDirection = 0;//-1向上、1向下
121 |
122 | public WheelView(Context context) {
123 | super(context);
124 | initAttr(context, null, 0);
125 | }
126 |
127 | public WheelView(Context context, @Nullable AttributeSet attrs) {
128 | super(context, attrs);
129 | initAttr(context, attrs, 0);
130 | }
131 |
132 | public WheelView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
133 | super(context, attrs, defStyleAttr);
134 | initAttr(context, attrs, defStyleAttr);
135 | }
136 |
137 | public void initAttr(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
138 | mOverScroller = new OverScroller(context);
139 | final ViewConfiguration viewConfiguration = ViewConfiguration.get(context);
140 | mMinimumVelocity = viewConfiguration.getScaledMinimumFlingVelocity();
141 | mMaximumVelocity = viewConfiguration.getScaledMaximumFlingVelocity();
142 | scaledTouchSlop = viewConfiguration.getScaledTouchSlop();
143 |
144 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.WheelView, defStyleAttr, 0);
145 | float defaultTextSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 14, getResources().getDisplayMetrics());
146 | textColor = a.getColor(R.styleable.WheelView_wheelTextColor, 0xFF333333);
147 | textSize = a.getDimension(R.styleable.WheelView_wheelTextSize, defaultTextSize);
148 | showCount = a.getInt(R.styleable.WheelView_wheelShowCount, 5);
149 | totalOffsetX = a.getDimensionPixelSize(R.styleable.WheelView_wheelTotalOffsetX, 0);
150 | itemVerticalSpace = a.getDimensionPixelSize(R.styleable.WheelView_wheelItemVerticalSpace, 32);
151 | wheelRotationX = a.getFloat(R.styleable.WheelView_wheelRotationX, DEFAULT_ROTATION_X);
152 | velocityUnits = a.getInteger(R.styleable.WheelView_wheelVelocityUnits, DEFAULT_VELOCITY_UNITS);
153 | if (velocityUnits < 0) {
154 | velocityUnits = Math.abs(velocityUnits);
155 | }
156 | a.recycle();
157 |
158 | initConfig();
159 | if (isInEditMode()) {
160 | IWheel[] items = new IWheel[50];
161 | for (int i = 0; i < items.length; i++) {
162 | items[i] = new WheelItem("菜单选项" + (i < 10 ? "0" + i : String.valueOf(i)));
163 | }
164 | setItems(items);
165 | }
166 | }
167 |
168 | private void initConfig() {
169 | textPaint.setColor(textColor);
170 | textPaint.setTextSize(textSize);
171 | Paint.FontMetrics fontMetrics = textPaint.getFontMetrics();
172 |
173 | String testText = "菜单选项";
174 | Rect rect = new Rect();
175 | textPaint.getTextBounds(testText, 0, testText.length(), rect);
176 | itemHeight = rect.height() + itemVerticalSpace;
177 | textBaseLine = -itemHeight / 2.0f + (itemHeight - fontMetrics.bottom + fontMetrics.top) / 2 - fontMetrics.top;
178 |
179 | if (showCount < 5) {
180 | showCount = 5;
181 | }
182 | if (showCount % 2 == 0) {
183 | showCount++;
184 | }
185 | drawCount = showCount + 2;
186 | defaultRectArray = new Rect[drawCount];
187 | drawRectArray = new Rect[drawCount];
188 | for (int i = 0; i < drawCount; i++) {
189 | defaultRectArray[i] = new Rect();
190 | drawRectArray[i] = new Rect();
191 | }
192 | }
193 |
194 | @Override
195 | public void setTextSize(float textSize) {
196 | this.textSize = textSize;
197 | initConfig();
198 | requestLayout();
199 | }
200 |
201 | @Override
202 | public void setTextColor(@ColorInt int textColor) {
203 | this.textColor = textColor;
204 | textPaint.setColor(textColor);
205 | invalidate();
206 | }
207 |
208 | @Override
209 | public void setShowCount(int showCount) {
210 | this.showCount = showCount;
211 | initConfig();
212 | requestLayout();
213 | }
214 |
215 | @Override
216 | public void setTotalOffsetX(int totalOffsetX) {
217 | this.totalOffsetX = totalOffsetX;
218 | invalidate();
219 | }
220 |
221 | @Override
222 | public void setItemVerticalSpace(int itemVerticalSpace) {
223 | this.itemVerticalSpace = itemVerticalSpace;
224 | initConfig();
225 | requestLayout();
226 | }
227 |
228 | /**
229 | * Set the fling velocity units.
230 | * The default value is {@link #DEFAULT_VELOCITY_UNITS}.
231 | * @param velocityUnits the velocity units
232 | */
233 | public void setVelocityUnits(int velocityUnits) {
234 | this.velocityUnits = Math.abs(velocityUnits);
235 | }
236 |
237 | @Override
238 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
239 | int top = 0 - itemHeight;
240 | for (int i = 0; i < drawCount; i++) {
241 | defaultRectArray[i].set(0, top, 0, top + itemHeight);
242 | top += itemHeight;
243 | }
244 | heightMeasureSpec = MeasureSpec.makeMeasureSpec(itemHeight * showCount, MeasureSpec.EXACTLY);
245 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
246 | }
247 |
248 | @Override
249 | public boolean onTouchEvent(MotionEvent event) {
250 | if (isEmpty())
251 | return super.onTouchEvent(event);
252 |
253 | initVelocityTrackerIfNotExists();
254 | switch (event.getAction()) {
255 | case MotionEvent.ACTION_DOWN:
256 | //add event into velocity tracker.
257 | mVelocityTracker.clear();
258 |
259 | //stop fling and reset fling direction
260 | flingDirection = 0;
261 | mOverScroller.forceFinished(true);
262 |
263 | if (animator != null && animator.isRunning()) {
264 | isAnimatorCanceledForwardly = true;
265 | animator.cancel();
266 | }
267 | lastX = event.getX();
268 | lastY = event.getY();
269 |
270 | //Make it as a click event when touch down,
271 | //and record touch down time stamp.
272 | touchDownTimeStamp = System.currentTimeMillis();
273 | break;
274 | case MotionEvent.ACTION_MOVE:
275 | //add event into velocity tracker and compute velocity.
276 | mVelocityTracker.addMovement(event);
277 |
278 | float currentX = event.getX();
279 | float currentY = event.getY();
280 | int distance = (int) (currentY - lastY);
281 |
282 | int direction = 0;
283 | if (distance == 0)
284 | break;
285 |
286 | //if moved, cancel click event
287 | touchDownTimeStamp = 0;
288 | direction = distance / Math.abs(distance);
289 |
290 | //initialize touch area
291 | rectF.set(0, 0, getWidth(), getHeight());
292 | if (rectF.contains(currentX, currentY)) {
293 | //inside touch area, execute move event.
294 | lastX = currentX;
295 | lastY = currentY;
296 | updateByTotalMoveY(totalMoveY + distance, direction);
297 | }
298 | break;
299 | case MotionEvent.ACTION_UP:
300 | case MotionEvent.ACTION_CANCEL:
301 | if (System.currentTimeMillis() - touchDownTimeStamp <= CLICK_EVENT_INTERNAL_TIME) {
302 | //it's a click event, do it
303 | executeClickEvent(event.getX(), event.getY());
304 | break;
305 | }
306 |
307 | //calculate current velocity
308 | final VelocityTracker velocityTracker = mVelocityTracker;
309 | velocityTracker.computeCurrentVelocity(velocityUnits, mMaximumVelocity);
310 | float currentVelocity = velocityTracker.getYVelocity();
311 | recycleVelocityTracker();
312 |
313 | final int tempFlingDirection = currentVelocity == 0 ? 0 : (currentVelocity < 0 ? -1 : 1);
314 | if (Math.abs(currentVelocity) >= mMinimumVelocity) {
315 | //it's a fling event.
316 | flingDirection = tempFlingDirection;
317 | mOverScroller.fling(
318 | 0, totalMoveY,
319 | 0, (int) currentVelocity,
320 | 0, 0,
321 | -(getItemCount() + showCount / 2) * itemHeight, (showCount / 2) * itemHeight,
322 | 0, 0
323 | );
324 | invalidate();
325 | } else {
326 | calculateSelectedIndex(totalMoveY, tempFlingDirection);
327 | selectedIndex = calculateResult[0];
328 | offsetY = calculateResult[1];
329 | //execute rebound animation
330 | executeAnimation(
331 | totalMoveY,
332 | 0 - selectedIndex * itemHeight
333 | );
334 | }
335 | break;
336 |
337 | }
338 | return true;
339 | }
340 |
341 | public void setOnSelectedListener(OnSelectedListener onSelectedListener) {
342 | this.onSelectedListener = onSelectedListener;
343 | }
344 |
345 | public void setItems(IWheel[] items) {
346 | this.items = items;
347 | if (!isEmpty()) {
348 | averageShowTextLength = calAverageShowTextLength();
349 | invalidate();
350 | }
351 | }
352 |
353 | public int getItemHeight() {
354 | return itemHeight;
355 | }
356 |
357 | public int getShowCount() {
358 | return showCount;
359 | }
360 |
361 | /**
362 | * Get the current selected index position.
363 | *
364 | * @return the current selected index position
365 | */
366 | public int getSelectedIndex() {
367 | return selectedIndex;
368 | }
369 |
370 | /**
371 | * Scroll to fixed index position with animation.
372 | *
373 | * @param targetIndexPosition the target index position
374 | */
375 | public void setSelectedIndex(int targetIndexPosition) {
376 | setSelectedIndex(targetIndexPosition, true);
377 | }
378 |
379 | /**
380 | * Set the 3D rotation.
381 | *
382 | * @param wheelRotationX the rotate wheel base x axis
383 | */
384 | public void setWheelRotationX(float wheelRotationX) {
385 | if (this.wheelRotationX != wheelRotationX) {
386 | this.wheelRotationX = wheelRotationX;
387 | invalidate();
388 | }
389 | }
390 |
391 | /**
392 | * Scroll to fixed index position.
393 | *
394 | * @param targetIndexPosition the target index position
395 | * @param withAnimation true, scroll with animation
396 | */
397 | public void setSelectedIndex(int targetIndexPosition, boolean withAnimation) {
398 | if (targetIndexPosition < 0 || targetIndexPosition >= getItemCount())
399 | throw new IndexOutOfBoundsException("Out of array bounds.");
400 | if (withAnimation) {
401 | executeAnimation(totalMoveY, 0 - itemHeight * targetIndexPosition);
402 | } else {
403 | totalMoveY = 0 - itemHeight * targetIndexPosition;
404 | selectedIndex = targetIndexPosition;
405 | offsetY = 0;
406 | invalidate();
407 | if (onSelectedListener != null)
408 | onSelectedListener.onSelected(getContext(), selectedIndex);
409 | }
410 | }
411 |
412 | @Override
413 | public boolean isScrolling() {
414 | return isScrolling;
415 | }
416 |
417 | /**
418 | * Calculate average pixel length of show text.
419 | *
420 | * @return the average pixel length of show text
421 | */
422 | private float calAverageShowTextLength() {
423 | float totalLength = 0;
424 | String showText = null;
425 | for (IWheel wheel : items) {
426 | showText = wheel.getShowText();
427 | if (showText == null || showText.length() == 0)
428 | continue;
429 | totalLength += textPaint.measureText(showText);
430 | }
431 | return totalLength / getItemCount();
432 | }
433 |
434 | /**
435 | * Execute click event.
436 | *
437 | * @return true, valid click event, else invalid.
438 | */
439 | private void executeClickEvent(float upX, float upY) {
440 | boolean isValidTempSelectedIndex = false;
441 | int tempSelectedIndex = selectedIndex - drawCount / 2;
442 | for (int i = 0; i < drawCount; i++) {
443 | rectF.set(drawRectArray[i]);
444 | if (rectF.contains(upX, upY)) {
445 | isValidTempSelectedIndex = true;
446 | break;
447 | }
448 | tempSelectedIndex++;
449 | }
450 | if (isValidTempSelectedIndex
451 | && tempSelectedIndex >= 0
452 | && tempSelectedIndex < getItemCount()) {
453 | //Move to target selected index
454 | setSelectedIndex(tempSelectedIndex);
455 | }
456 | }
457 |
458 | private int getItemCount() {
459 | return items == null ? 0 : items.length;
460 | }
461 |
462 | private IWheel getItemAt(int position) {
463 | if (isEmpty() || position < 0 || position >= getItemCount())
464 | return null;
465 | return items[position];
466 | }
467 |
468 | private boolean isEmpty() {
469 | return getItemCount() == 0;
470 | }
471 |
472 | /**
473 | * Execute animation.
474 | */
475 | private void executeAnimation(int... values) {
476 | //if it's invalid animation, call back immediately.
477 | if (invalidAnimation(values)) {
478 | if (onSelectedListener != null)
479 | onSelectedListener.onSelected(getContext(), selectedIndex);
480 | return;
481 | }
482 | int duration = 0;
483 | for (int i = 0; i < values.length; i++) {
484 | if (i > 0) {
485 | duration += Math.abs(values[i] - values[i - 1]);
486 | }
487 | }
488 | if (duration == 0) {
489 | if (onSelectedListener != null)
490 | onSelectedListener.onSelected(getContext(), selectedIndex);
491 | return;
492 | }
493 | createAnimatorIfNecessary();
494 | if (animator.isRunning()) {
495 | isAnimatorCanceledForwardly = true;
496 | animator.cancel();
497 | }
498 | animator.setIntValues(values);
499 | animator.setDuration(calSuitableDuration(duration));
500 | animator.start();
501 | }
502 |
503 | private boolean invalidAnimation(int... values) {
504 | if (values == null || values.length < 2)
505 | return true;
506 | int firstValue = values[0];
507 | for (int value : values) {
508 | if (firstValue != value)
509 | return false;
510 | }
511 | return true;
512 | }
513 |
514 | private int calSuitableDuration(int duration) {
515 | int result = duration;
516 | while (result > 1200) {
517 | result = result / 2;
518 | }
519 | return result;
520 | }
521 |
522 | /**
523 | * Create auto-scroll animation.
524 | */
525 | private void createAnimatorIfNecessary() {
526 | if (animator == null) {
527 | animator = new ValueAnimator();
528 | animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
529 | @Override
530 | public void onAnimationUpdate(ValueAnimator animation) {
531 | int tempTotalMoveY = (int) animation.getAnimatedValue();
532 | updateByTotalMoveY(tempTotalMoveY, 0);
533 | }
534 | });
535 | animator.setInterpolator(new LinearInterpolator());
536 | animator.addListener(new Animator.AnimatorListener() {
537 |
538 | @Override
539 | public void onAnimationStart(Animator animation) {
540 | isScrolling = true;
541 | }
542 |
543 | @Override
544 | public void onAnimationEnd(Animator animation) {
545 | isScrolling = false;
546 | //Cancel animation forwardly.
547 | if (isAnimatorCanceledForwardly) {
548 | isAnimatorCanceledForwardly = false;
549 | return;
550 | }
551 |
552 | if (onSelectedListener != null)
553 | onSelectedListener.onSelected(getContext(), selectedIndex);
554 | }
555 |
556 | @Override
557 | public void onAnimationCancel(Animator animation) {
558 |
559 | }
560 |
561 | @Override
562 | public void onAnimationRepeat(Animator animation) {
563 |
564 | }
565 | });
566 | }
567 | }
568 |
569 | public int getTotalMoveY() {
570 | return totalMoveY;
571 | }
572 |
573 | private void updateByTotalMoveY(final int totalMoveY, int direction) {
574 | calculateSelectedIndex(totalMoveY, direction);
575 | this.totalMoveY = totalMoveY;
576 | this.selectedIndex = calculateResult[0];
577 | this.offsetY = calculateResult[1];
578 | invalidate();
579 | }
580 |
581 | private void calculateSelectedIndex(int totalMoveY, int direction) {
582 | int selectedIndex = totalMoveY / (0 - itemHeight);
583 | int rest = totalMoveY % (0 - itemHeight);
584 | if (direction > 0 && rest != 0) {
585 | selectedIndex ++;
586 | rest = itemHeight - Math.abs(rest);
587 | }
588 | //move up
589 | if (direction < 0 && Math.abs(rest) >= itemHeight / 4) {
590 | selectedIndex++;
591 | }
592 | //move down
593 | if (direction > 0 && Math.abs(rest) >= itemHeight / 4) {
594 | selectedIndex --;
595 | }
596 |
597 | selectedIndex = Math.max(selectedIndex, 0);
598 | selectedIndex = Math.min(selectedIndex, getItemCount() - 1);
599 | int offsetY = (0 - selectedIndex * itemHeight) - totalMoveY;
600 | calculateResult[0] = selectedIndex;
601 | calculateResult[1] = offsetY;
602 | }
603 |
604 | @Override
605 | public void computeScroll() {
606 | if (mOverScroller.computeScrollOffset()) {
607 | totalMoveY = mOverScroller.getCurrY();
608 | updateByTotalMoveY(totalMoveY, 0);
609 | invalidate();
610 | return;
611 | }
612 |
613 | if (flingDirection != 0) {
614 | final int flingDirectionCopy = flingDirection;
615 | flingDirection = 0;
616 | calculateSelectedIndex(totalMoveY, flingDirectionCopy);
617 | selectedIndex = calculateResult[0];
618 | offsetY = calculateResult[1];
619 | //execute rebound animation
620 | executeAnimation(
621 | totalMoveY,
622 | 0 - selectedIndex * itemHeight
623 | );
624 | }
625 | }
626 |
627 | @Override
628 | protected void onDraw(Canvas canvas) {
629 | if (isEmpty())
630 | return;
631 |
632 | int tempStartSelectedIndex = selectedIndex - drawCount / 2;
633 | for (int i = 0; i < drawCount; i++) {
634 | Rect rect = drawRectArray[i];
635 | rect.set(defaultRectArray[i]);
636 | //record touch area for click event
637 | rect.left = 0;
638 | rect.right = getWidth();
639 | if (tempStartSelectedIndex >= 0 && tempStartSelectedIndex < getItemCount()) {
640 | drawItem(canvas, rect, getItemAt(tempStartSelectedIndex), -offsetY, textPaint);
641 | }
642 | tempStartSelectedIndex++;
643 | }
644 | computeScroll();
645 | }
646 |
647 | private void drawItem(Canvas canvas, Rect rect, IWheel item, int offsetY, TextPaint textPaint) {
648 | String text = item == null ? "" : item.getShowText();
649 | if (text == null || text.trim().length() == 0)
650 | return;
651 |
652 | rect.offset(0, offsetY);
653 | textPaint.setAlpha(calAlpha(rect));
654 | final int offsetX = totalOffsetX == 0 ? 0 : calOffsetX(totalOffsetX, rect);
655 | final float w = textPaint.measureText(text);
656 |
657 | float startX = 0;
658 | if (totalOffsetX > 0) {
659 | //show text align right
660 | final float rightAlignPosition = (getWidth() + averageShowTextLength) / 2.0f;
661 | startX = rightAlignPosition - w + offsetX;
662 | } else if (totalOffsetX < 0) {
663 | //show text align left
664 | final float leftAlignPosition = (getWidth() - averageShowTextLength) / 2.0f;
665 | startX = leftAlignPosition + offsetX;
666 | } else {
667 | //show text align center_horizontal
668 | startX = (getWidth() - w) / 2.0f + offsetX;
669 | }
670 | float centerX = getWidth() / 2.0f;
671 | float centerY = rect.exactCenterY();
672 | float baseLine = centerY + textBaseLine;
673 | matrix.reset();
674 | camera.save();
675 | camera.rotateX(calRotationX(rect, wheelRotationX));
676 | camera.getMatrix(matrix);
677 | camera.restore();
678 | matrix.preTranslate(-centerX, -centerY);
679 | matrix.postTranslate(centerX, centerY);
680 | if (totalOffsetX > 0) {
681 | float skewX = 0 - calSkewX(rect);
682 | centerX = (startX + w) / 2.0f;
683 | matrix.setSkew(skewX, 0, centerX, centerY);
684 | } else if (totalOffsetX < 0) {
685 | float skewX = calSkewX(rect);
686 | centerX = (startX + w) / 2.0f;
687 | matrix.setSkew(skewX, 0, centerX, centerY);
688 | }
689 | canvas.save();
690 | canvas.concat(matrix);
691 | canvas.drawText(text, startX, baseLine, textPaint);
692 | canvas.restore();
693 | }
694 |
695 | private int calAlpha(Rect rect) {
696 | int centerY = getHeight() / 2;
697 | int distance = Math.abs(centerY - rect.centerY());
698 | int totalDistance = itemHeight * (showCount / 2);
699 | float alpha = 0.6f * distance / totalDistance;
700 | return (int) ((1 - alpha) * 0xFF);
701 | }
702 |
703 | private float calRotationX(Rect rect, float baseRotationX) {
704 | int centerY = getHeight() / 2;
705 | int distance = centerY - rect.centerY();
706 | int totalDistance = itemHeight * (showCount / 2);
707 | return baseRotationX * distance * 1.0f / totalDistance;
708 | }
709 |
710 | private float calSkewX(Rect rect) {
711 | int centerY = getHeight() / 2;
712 | int distance = centerY - rect.centerY();
713 | int totalDistance = itemHeight * (showCount / 2);
714 | return 0.3f * distance / totalDistance;
715 | }
716 |
717 | private int calOffsetX(int totalOffsetX, Rect rect) {
718 | int centerY = getHeight() / 2;
719 | int distance = Math.abs(centerY - rect.centerY());
720 | int totalDistance = itemHeight * (showCount / 2);
721 | return totalOffsetX * distance / totalDistance;
722 | }
723 |
724 | private void initVelocityTrackerIfNotExists() {
725 | if (mVelocityTracker == null) {
726 | mVelocityTracker = VelocityTracker.obtain();
727 | }
728 | }
729 |
730 | private void recycleVelocityTracker() {
731 | if (mVelocityTracker != null) {
732 | mVelocityTracker.recycle();
733 | mVelocityTracker = null;
734 | }
735 | }
736 |
737 | public interface OnSelectedListener {
738 | void onSelected(Context context, int selectedIndex);
739 | }
740 | }
741 |
--------------------------------------------------------------------------------
/wheelViewLibrary/src/main/java/jsc/kit/wheel/dialog/ColumnWheelDialog.java:
--------------------------------------------------------------------------------
1 | package jsc.kit.wheel.dialog;
2 |
3 | import android.app.Dialog;
4 | import android.content.Context;
5 | import android.graphics.Color;
6 | import android.os.Bundle;
7 | import android.text.TextUtils;
8 | import android.view.Gravity;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.view.Window;
12 | import android.widget.LinearLayout;
13 | import android.widget.TextView;
14 | import android.widget.Toast;
15 |
16 | import androidx.annotation.NonNull;
17 | import androidx.annotation.Nullable;
18 |
19 | import java.util.ArrayList;
20 | import java.util.List;
21 |
22 | import jsc.kit.wheel.R;
23 | import jsc.kit.wheel.base.IWheel;
24 | import jsc.kit.wheel.base.WheelItemView;
25 |
26 | /**
27 | * date time picker dialog
28 | *
Email:1006368252@qq.com
29 | *
QQ:1006368252
30 | *
https://github.com/JustinRoom/WheelViewDemo
31 | *
32 | * @author jiangshicheng
33 | */
34 | public class ColumnWheelDialog extends Dialog {
35 |
36 | private TextView tvTitle;
37 | private TextView tvCancel;
38 | private TextView tvOK;
39 |
40 | private WheelItemView wheelItemView0;
41 | private WheelItemView wheelItemView1;
42 | private WheelItemView wheelItemView2;
43 | private WheelItemView wheelItemView3;
44 | private WheelItemView wheelItemView4;
45 |
46 | private T0[] items0;
47 | private T1[] items1;
48 | private T2[] items2;
49 | private T3[] items3;
50 | private T4[] items4;
51 | private CharSequence clickTipsWhenIsScrolling = "Scrolling, wait a minute.";
52 |
53 | private OnClickCallBack cancelCallBack = null;
54 | private OnClickCallBack okCallBack = null;
55 |
56 | private boolean isViewInitialized = false;
57 | private float textSize;
58 | private int itemVerticalSpace;
59 |
60 | public ColumnWheelDialog(@NonNull Context context) {
61 | this(context, R.style.WheelDialog);
62 | }
63 |
64 | private ColumnWheelDialog(@NonNull Context context, int themeResId) {
65 | super(context, themeResId);
66 | }
67 |
68 | @Override
69 | protected void onCreate(Bundle savedInstanceState) {
70 | super.onCreate(savedInstanceState);
71 | requestWindowFeature(Window.FEATURE_NO_TITLE);
72 | if (getWindow() != null) {
73 | getWindow().setGravity(Gravity.BOTTOM);
74 | getWindow().setBackgroundDrawable(null);
75 | getWindow().getDecorView().setBackgroundColor(Color.TRANSPARENT);
76 | }
77 | setContentView(R.layout.wheel_dialog_base);
78 | initView();
79 | }
80 |
81 | private void initView() {
82 | isViewInitialized = true;
83 | LinearLayout lyPickerContainer = findViewById(R.id.wheel_id_picker_container);
84 | wheelItemView0 = new WheelItemView(lyPickerContainer.getContext());
85 | lyPickerContainer.addView(wheelItemView0, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1));
86 | wheelItemView1 = new WheelItemView(lyPickerContainer.getContext());
87 | lyPickerContainer.addView(wheelItemView1, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1));
88 | wheelItemView2 = new WheelItemView(lyPickerContainer.getContext());
89 | lyPickerContainer.addView(wheelItemView2, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1));
90 | wheelItemView3 = new WheelItemView(lyPickerContainer.getContext());
91 | lyPickerContainer.addView(wheelItemView3, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1));
92 | wheelItemView4 = new WheelItemView(lyPickerContainer.getContext());
93 | lyPickerContainer.addView(wheelItemView4, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1));
94 | if (textSize > 0) {
95 | wheelItemView0.setTextSize(textSize);
96 | wheelItemView1.setTextSize(textSize);
97 | wheelItemView2.setTextSize(textSize);
98 | wheelItemView3.setTextSize(textSize);
99 | wheelItemView4.setTextSize(textSize);
100 | }
101 | if (itemVerticalSpace > 0) {
102 | wheelItemView0.setItemVerticalSpace(itemVerticalSpace);
103 | wheelItemView1.setItemVerticalSpace(itemVerticalSpace);
104 | wheelItemView2.setItemVerticalSpace(itemVerticalSpace);
105 | wheelItemView3.setItemVerticalSpace(itemVerticalSpace);
106 | wheelItemView4.setItemVerticalSpace(itemVerticalSpace);
107 | }
108 |
109 | tvTitle = findViewById(R.id.wheel_id_title_bar_title);
110 | tvCancel = findViewById(R.id.wheel_id_title_bar_cancel);
111 | tvOK = findViewById(R.id.wheel_id_title_bar_ok);
112 | tvCancel.setOnClickListener(new View.OnClickListener() {
113 | @Override
114 | public void onClick(View v) {
115 | if (cancelCallBack == null) {
116 | dismiss();
117 | return;
118 | }
119 | if (!cancelCallBack.callBack(
120 | v,
121 | wheelItemView0.isShown() ? items0[wheelItemView0.getSelectedIndex()] : null,
122 | wheelItemView1.isShown() ? items1[wheelItemView1.getSelectedIndex()] : null,
123 | wheelItemView2.isShown() ? items2[wheelItemView2.getSelectedIndex()] : null,
124 | wheelItemView3.isShown() ? items3[wheelItemView3.getSelectedIndex()] : null,
125 | wheelItemView4.isShown() ? items4[wheelItemView4.getSelectedIndex()] : null
126 | )) dismiss();
127 | }
128 | });
129 | tvOK.setOnClickListener(new View.OnClickListener() {
130 | @Override
131 | public void onClick(View v) {
132 | if (okCallBack == null) {
133 | dismiss();
134 | return;
135 | }
136 | if (isScrolling()) {
137 | if (!TextUtils.isEmpty(clickTipsWhenIsScrolling))
138 | Toast.makeText(v.getContext(), clickTipsWhenIsScrolling, Toast.LENGTH_SHORT).show();
139 | return;
140 | }
141 | if (!okCallBack.callBack(
142 | v,
143 | wheelItemView0.isShown() ? items0[wheelItemView0.getSelectedIndex()] : null,
144 | wheelItemView1.isShown() ? items1[wheelItemView1.getSelectedIndex()] : null,
145 | wheelItemView2.isShown() ? items2[wheelItemView2.getSelectedIndex()] : null,
146 | wheelItemView3.isShown() ? items3[wheelItemView3.getSelectedIndex()] : null,
147 | wheelItemView4.isShown() ? items4[wheelItemView4.getSelectedIndex()] : null
148 | )) dismiss();
149 | }
150 | });
151 | }
152 |
153 | @Override
154 | public void show() {
155 | super.show();
156 | if (getWindow() != null) {
157 | getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
158 | }
159 | }
160 |
161 | public void setClickTipsWhenIsScrolling(CharSequence clickTipsWhenIsScrolling) {
162 | this.clickTipsWhenIsScrolling = clickTipsWhenIsScrolling;
163 | }
164 |
165 | public void setTitle(CharSequence title) {
166 | ensureIsViewInitialized();
167 | tvTitle.setText(title);
168 | }
169 |
170 | public void setTextSize(float textSize) {
171 | this.textSize = textSize;
172 | }
173 |
174 | public void setItemVerticalSpace(int itemVerticalSpace) {
175 | this.itemVerticalSpace = itemVerticalSpace;
176 | }
177 |
178 | public void setOKButton(CharSequence ok, OnClickCallBack okCallBack) {
179 | ensureIsViewInitialized();
180 | tvOK.setText(ok);
181 | this.okCallBack = okCallBack;
182 | }
183 |
184 | public void setCancelButton(CharSequence cancel, OnClickCallBack cancelCallBack) {
185 | ensureIsViewInitialized();
186 | tvCancel.setText(cancel);
187 | this.cancelCallBack = cancelCallBack;
188 | }
189 |
190 | public void setItems(T0[] items0, T1[] items1, T2[] items2, T3[] items3, T4[] items4) {
191 | setItems(items0, items1, items2, items3, items4, -1);
192 | }
193 |
194 | /**
195 | *
196 | * @param items0 items0
197 | * @param items1 items1
198 | * @param items2 items2
199 | * @param items3 items3
200 | * @param items4 items4
201 | * @param totalOffsetX the total offset of x axis. The default value is 4dp.
202 | */
203 | public void setItems(T0[] items0, T1[] items1, T2[] items2, T3[] items3, T4[] items4, int totalOffsetX) {
204 | ensureIsViewInitialized();
205 | if (totalOffsetX == -1) {
206 | totalOffsetX = getContext().getResources().getDimensionPixelSize(R.dimen.wheel_picker_total_offset_x);
207 | }
208 | this.items0 = items0;
209 | this.items1 = items1;
210 | this.items2 = items2;
211 | this.items3 = items3;
212 | this.items4 = items4;
213 | updateShowPicker(wheelItemView0, items0);
214 | updateShowPicker(wheelItemView1, items1);
215 | updateShowPicker(wheelItemView2, items2);
216 | updateShowPicker(wheelItemView3, items3);
217 | updateShowPicker(wheelItemView4, items4);
218 | updateOffsetX(totalOffsetX);
219 | }
220 |
221 | public void setSelected(int selected0, int selected1, int selected2, int selected3, int selected4) {
222 | executeSelected(wheelItemView0, selected0);
223 | executeSelected(wheelItemView1, selected1);
224 | executeSelected(wheelItemView2, selected2);
225 | executeSelected(wheelItemView3, selected3);
226 | executeSelected(wheelItemView4, selected4);
227 | }
228 |
229 | private boolean isScrolling() {
230 | return isScrolling(wheelItemView0)
231 | || isScrolling(wheelItemView1)
232 | || isScrolling(wheelItemView2)
233 | || isScrolling(wheelItemView3)
234 | || isScrolling(wheelItemView4);
235 | }
236 |
237 | private void ensureIsViewInitialized() {
238 | if (!isViewInitialized)
239 | throw new IllegalStateException("View wasn't initialized, call show() first.");
240 | }
241 |
242 | private void updateShowPicker(WheelItemView wheelItemView, IWheel[] items) {
243 | boolean hide = (items == null || items.length == 0);
244 | wheelItemView.setVisibility(hide ? View.GONE : View.VISIBLE);
245 | if (!hide)
246 | wheelItemView.setItems(items);
247 | }
248 |
249 | private void executeSelected(WheelItemView view, int selectedIndex) {
250 | if (view.isShown())
251 | view.setSelectedIndex(selectedIndex);
252 | }
253 |
254 | private void updateOffsetX(int totalOffsetX) {
255 | List views = new ArrayList<>();
256 | addVisibleView(views, wheelItemView0);
257 | addVisibleView(views, wheelItemView1);
258 | addVisibleView(views, wheelItemView2);
259 | addVisibleView(views, wheelItemView3);
260 | addVisibleView(views, wheelItemView4);
261 | for (int i = 0; i < views.size(); i++) {
262 | views.get(i).setTotalOffsetX(0);
263 | }
264 | if (views.size() > 2) {
265 | views.get(0).setTotalOffsetX(totalOffsetX);
266 | views.get(views.size() - 1).setTotalOffsetX(-totalOffsetX);
267 | }
268 | }
269 |
270 | private void addVisibleView(List views, WheelItemView v) {
271 | if (v.isShown())
272 | views.add(v);
273 | }
274 |
275 | private boolean isScrolling(WheelItemView view) {
276 | return view.isShown() && view.isScrolling();
277 | }
278 |
279 | public interface OnClickCallBack {
280 | boolean callBack(View v, @Nullable D0 item0, @Nullable D1 item1, @Nullable D2 item2, @Nullable D3 item3, @Nullable D4 item4);
281 | }
282 | }
283 |
--------------------------------------------------------------------------------
/wheelViewLibrary/src/main/java/jsc/kit/wheel/dialog/DateItem.java:
--------------------------------------------------------------------------------
1 | package jsc.kit.wheel.dialog;
2 |
3 | import androidx.annotation.IntDef;
4 |
5 | import java.lang.annotation.Retention;
6 | import java.lang.annotation.RetentionPolicy;
7 | import java.util.Locale;
8 |
9 | import jsc.kit.wheel.base.IWheel;
10 |
11 | /**
12 | *
Email:1006368252@qq.com
13 | *
QQ:1006368252
14 | *
https://github.com/JustinRoom/WheelViewDemo
15 | *
16 | * @author jiangshicheng
17 | */
18 | public class DateItem implements IWheel {
19 |
20 | public static final int TYPE_YEAR = 0;
21 | public static final int TYPE_MONTH = 1;
22 | public static final int TYPE_DAY = 2;
23 | public static final int TYPE_HOUR = 3;
24 | public static final int TYPE_MINUTE = 4;
25 |
26 | @IntDef({TYPE_YEAR, TYPE_MONTH, TYPE_DAY, TYPE_HOUR, TYPE_MINUTE})
27 | @Retention(RetentionPolicy.SOURCE)
28 | public @interface DateType {
29 | }
30 |
31 | private int type;
32 | private int value;
33 |
34 | public DateItem() {
35 | }
36 |
37 | public DateItem(int value) {
38 | this(TYPE_YEAR, value);
39 | }
40 |
41 | public DateItem(@DateType int type, int value) {
42 | this.type = type;
43 | this.value = value;
44 | }
45 |
46 | public int getValue() {
47 | return value;
48 | }
49 |
50 | public void setValue(int value) {
51 | this.value = value;
52 | }
53 |
54 | @Override
55 | public String getShowText() {
56 | return String.format(Locale.CHINA, getFormatStringByType(), (value < 10 ? "0" + value : "" + value));
57 | }
58 |
59 | private String getFormatStringByType() {
60 | String result = "";
61 | switch (type) {
62 | case TYPE_YEAR:
63 | result = "%s年";
64 | break;
65 | case TYPE_MONTH:
66 | result = "%s月";
67 | break;
68 | case TYPE_DAY:
69 | result = "%s日";
70 | break;
71 | case TYPE_HOUR:
72 | result = "%s时";
73 | break;
74 | case TYPE_MINUTE:
75 | result = "%s分";
76 | break;
77 | }
78 | return result;
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/wheelViewLibrary/src/main/java/jsc/kit/wheel/dialog/DateTimeWheelDialog.java:
--------------------------------------------------------------------------------
1 | package jsc.kit.wheel.dialog;
2 |
3 | import android.app.Dialog;
4 | import android.content.Context;
5 | import android.graphics.Color;
6 | import android.os.Bundle;
7 | import android.text.TextUtils;
8 | import android.util.Log;
9 | import android.view.Gravity;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.view.Window;
13 | import android.widget.LinearLayout;
14 | import android.widget.TextView;
15 | import android.widget.Toast;
16 |
17 | import androidx.annotation.IntDef;
18 | import androidx.annotation.NonNull;
19 |
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.RetentionPolicy;
22 | import java.util.ArrayList;
23 | import java.util.Calendar;
24 | import java.util.Date;
25 | import java.util.List;
26 | import java.util.Locale;
27 |
28 | import jsc.kit.wheel.R;
29 | import jsc.kit.wheel.base.WheelItemView;
30 | import jsc.kit.wheel.base.WheelView;
31 |
32 | /**
33 | * date time picker dialog
34 | *
Email:1006368252@qq.com
35 | *
QQ:1006368252
36 | *
https://github.com/JustinRoom/WheelViewDemo
37 | *
38 | * @author jiangshicheng
39 | */
40 | public class DateTimeWheelDialog extends Dialog {
41 |
42 | public static final int SHOW_YEAR = 0;
43 | public static final int SHOW_YEAR_MONTH = 1;
44 | public static final int SHOW_YEAR_MONTH_DAY = 2;
45 | public static final int SHOW_YEAR_MONTH_DAY_HOUR = 3;
46 | public static final int SHOW_YEAR_MONTH_DAY_HOUR_MINUTE = 4;
47 |
48 | @IntDef({
49 | SHOW_YEAR,
50 | SHOW_YEAR_MONTH,
51 | SHOW_YEAR_MONTH_DAY,
52 | SHOW_YEAR_MONTH_DAY_HOUR,
53 | SHOW_YEAR_MONTH_DAY_HOUR_MINUTE
54 | })
55 | @Retention(RetentionPolicy.SOURCE)
56 | public @interface ShowConfig {
57 | }
58 |
59 | private final int MIN_MONTH = 1;
60 | private final int MAX_MONTH = 12;
61 | private final int MIN_DAY = 1;
62 | private final int MIN_HOUR = 0;
63 | private final int MAX_HOUR = 23;
64 | private final int MIN_MINUTE = 0;
65 | private final int MAX_MINUTE = 59;
66 | private TextView tvTitle;
67 | private TextView tvCancel;
68 | private TextView tvOK;
69 | private CharSequence clickTipsWhenIsScrolling = "Scrolling, wait a minute.";
70 |
71 | private WheelItemView mYearView;
72 | private WheelItemView mMonthView;
73 | private WheelItemView mDayView;
74 | private WheelItemView mHourView;
75 | private WheelItemView mMinuteView;
76 |
77 | private final List yearItems = new ArrayList<>();
78 | private final List monthItems = new ArrayList<>();
79 | private final List dayItems = new ArrayList<>();
80 | private final List hourItems = new ArrayList<>();
81 | private final List minuteItems = new ArrayList<>();
82 |
83 | private final Calendar startCalendar = Calendar.getInstance();
84 | private final Calendar endCalendar = Calendar.getInstance();
85 | private final Calendar selectedCalendar = Calendar.getInstance();
86 | private OnClickCallBack cancelCallBack = null;
87 | private OnClickCallBack okCallBack = null;
88 |
89 | private int showCount = 5;
90 | private int itemVerticalSpace = 32;
91 | private boolean isViewInitialized = false;
92 | private boolean keepLastSelected = false;
93 | private int showConfig = SHOW_YEAR_MONTH_DAY_HOUR_MINUTE;
94 |
95 | public DateTimeWheelDialog(@NonNull Context context) {
96 | this(context, R.style.WheelDialog);
97 | }
98 |
99 | private DateTimeWheelDialog(@NonNull Context context, int themeResId) {
100 | super(context, themeResId);
101 | }
102 |
103 | @Override
104 | protected void onCreate(Bundle savedInstanceState) {
105 | super.onCreate(savedInstanceState);
106 | requestWindowFeature(Window.FEATURE_NO_TITLE);
107 | if (getWindow() != null) {
108 | getWindow().setGravity(Gravity.BOTTOM);
109 | getWindow().setBackgroundDrawable(null);
110 | getWindow().getDecorView().setBackgroundColor(Color.TRANSPARENT);
111 | }
112 | setContentView(R.layout.wheel_dialog_base);
113 | initView();
114 | initOnScrollListener();
115 | }
116 |
117 | private void initView() {
118 | isViewInitialized = true;
119 | LinearLayout mPickerContainer = findViewById(R.id.wheel_id_picker_container);
120 | //year
121 | mYearView = new WheelItemView(mPickerContainer.getContext());
122 | mYearView.setItemVerticalSpace(itemVerticalSpace);
123 | mYearView.setShowCount(showCount);
124 | mPickerContainer.addView(mYearView, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1));
125 | //month
126 | mMonthView = new WheelItemView(mPickerContainer.getContext());
127 | mMonthView.setItemVerticalSpace(itemVerticalSpace);
128 | mMonthView.setShowCount(showCount);
129 | mPickerContainer.addView(mMonthView, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1));
130 | //day
131 | mDayView = new WheelItemView(mPickerContainer.getContext());
132 | mDayView.setItemVerticalSpace(itemVerticalSpace);
133 | mDayView.setShowCount(showCount);
134 | mPickerContainer.addView(mDayView, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1));
135 | //hour
136 | mHourView = new WheelItemView(mPickerContainer.getContext());
137 | mHourView.setItemVerticalSpace(itemVerticalSpace);
138 | mHourView.setShowCount(showCount);
139 | mPickerContainer.addView(mHourView, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1));
140 | //minute
141 | mMinuteView = new WheelItemView(mPickerContainer.getContext());
142 | mMinuteView.setItemVerticalSpace(itemVerticalSpace);
143 | mMinuteView.setShowCount(showCount);
144 | mPickerContainer.addView(mMinuteView, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1));
145 |
146 | tvTitle = findViewById(R.id.wheel_id_title_bar_title);
147 | tvCancel = findViewById(R.id.wheel_id_title_bar_cancel);
148 | tvOK = findViewById(R.id.wheel_id_title_bar_ok);
149 | tvCancel.setOnClickListener(new View.OnClickListener() {
150 | @Override
151 | public void onClick(View v) {
152 | if (cancelCallBack == null) {
153 | dismiss();
154 | return;
155 | }
156 | if (!cancelCallBack.callBack(v, selectedCalendar.getTime())) dismiss();
157 | }
158 | });
159 | tvOK.setOnClickListener(new View.OnClickListener() {
160 | @Override
161 | public void onClick(View v) {
162 | if (okCallBack == null) {
163 | dismiss();
164 | return;
165 | }
166 | if (isScrolling()) {
167 | if (!TextUtils.isEmpty(clickTipsWhenIsScrolling))
168 | Toast.makeText(v.getContext(), clickTipsWhenIsScrolling, Toast.LENGTH_SHORT).show();
169 | return;
170 | }
171 | if (!okCallBack.callBack(v, selectedCalendar.getTime())) dismiss();
172 | }
173 | });
174 | }
175 |
176 | @Override
177 | public void show() {
178 | super.show();
179 | if (getWindow() != null) {
180 | getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
181 | }
182 | }
183 |
184 | public void setShowCount(int showCount) {
185 | this.showCount = showCount;
186 | }
187 |
188 | public void setItemVerticalSpace(int itemVerticalSpace) {
189 | this.itemVerticalSpace = itemVerticalSpace;
190 | }
191 |
192 | public void setClickTipsWhenIsScrolling(CharSequence clickTipsWhenIsScrolling) {
193 | this.clickTipsWhenIsScrolling = clickTipsWhenIsScrolling;
194 | }
195 |
196 | public void setTitle(CharSequence title) {
197 | ensureIsViewInitialized();
198 | tvTitle.setText(title);
199 | }
200 |
201 | public void setOKButton(CharSequence ok, OnClickCallBack okCallBack) {
202 | ensureIsViewInitialized();
203 | tvOK.setText(ok);
204 | this.okCallBack = okCallBack;
205 | }
206 |
207 | public void setCancelButton(CharSequence cancel, OnClickCallBack cancelCallBack) {
208 | ensureIsViewInitialized();
209 | tvCancel.setText(cancel);
210 | this.cancelCallBack = cancelCallBack;
211 | }
212 |
213 | public void configShowUI(@ShowConfig int config) {
214 | configShowUI(config, getContext().getResources().getDimensionPixelSize(R.dimen.wheel_picker_total_offset_x));
215 | }
216 |
217 | public void configShowUI(@ShowConfig int showConfig, int totalOffsetX) {
218 | ensureIsViewInitialized();
219 | this.showConfig = showConfig;
220 | mYearView.setTotalOffsetX(0);
221 | mMonthView.setTotalOffsetX(0);
222 | mDayView.setTotalOffsetX(0);
223 | mHourView.setTotalOffsetX(0);
224 | mMinuteView.setTotalOffsetX(0);
225 | switch (showConfig) {
226 | case SHOW_YEAR:
227 | mYearView.setVisibility(View.VISIBLE);
228 | mMonthView.setVisibility(View.GONE);
229 | mDayView.setVisibility(View.GONE);
230 | mHourView.setVisibility(View.GONE);
231 | mMinuteView.setVisibility(View.GONE);
232 | break;
233 | case SHOW_YEAR_MONTH:
234 | mYearView.setVisibility(View.VISIBLE);
235 | mMonthView.setVisibility(View.VISIBLE);
236 | mDayView.setVisibility(View.GONE);
237 | mHourView.setVisibility(View.GONE);
238 | mMinuteView.setVisibility(View.GONE);
239 | break;
240 | case SHOW_YEAR_MONTH_DAY:
241 | mYearView.setVisibility(View.VISIBLE);
242 | mMonthView.setVisibility(View.VISIBLE);
243 | mDayView.setVisibility(View.VISIBLE);
244 | mHourView.setVisibility(View.GONE);
245 | mMinuteView.setVisibility(View.GONE);
246 | mYearView.setTotalOffsetX(totalOffsetX);
247 | mDayView.setTotalOffsetX(-totalOffsetX);
248 | break;
249 | case SHOW_YEAR_MONTH_DAY_HOUR:
250 | mYearView.setVisibility(View.VISIBLE);
251 | mMonthView.setVisibility(View.VISIBLE);
252 | mDayView.setVisibility(View.VISIBLE);
253 | mHourView.setVisibility(View.VISIBLE);
254 | mMinuteView.setVisibility(View.GONE);
255 | mYearView.setTotalOffsetX(totalOffsetX);
256 | mHourView.setTotalOffsetX(-totalOffsetX);
257 | break;
258 | case SHOW_YEAR_MONTH_DAY_HOUR_MINUTE:
259 | mYearView.setVisibility(View.VISIBLE);
260 | mMonthView.setVisibility(View.VISIBLE);
261 | mDayView.setVisibility(View.VISIBLE);
262 | mHourView.setVisibility(View.VISIBLE);
263 | mMinuteView.setVisibility(View.VISIBLE);
264 | mYearView.setTotalOffsetX(totalOffsetX);
265 | mMinuteView.setTotalOffsetX(-totalOffsetX);
266 | break;
267 | }
268 | }
269 |
270 | public void setDateArea(@NonNull Date startDate, @NonNull Date endDate, boolean keepLastSelected) {
271 | ensureIsViewInitialized();
272 | if (startDate.after(endDate))
273 | throw new IllegalArgumentException("start date should be before end date");
274 | startCalendar.setTime(startDate);
275 | endCalendar.setTime(endDate);
276 | selectedCalendar.setTimeInMillis(startDate.getTime());
277 | this.keepLastSelected = keepLastSelected;
278 | initAreaDate();
279 | }
280 |
281 | public void updateSelectedDate(@NonNull Date selectedDate) {
282 | ensureIsViewInitialized();
283 | if (selectedDate.before(startCalendar.getTime()) || selectedDate.after(endCalendar.getTime()))
284 | throw new IllegalArgumentException("selected date must be between start date and end date");
285 | selectedCalendar.setTime(selectedDate);
286 | initSelectedDate();
287 | }
288 |
289 | private void initAreaDate() {
290 | int startYear = startCalendar.get(Calendar.YEAR);
291 | int endYear = endCalendar.get(Calendar.YEAR);
292 | int startMonth = startCalendar.get(Calendar.MONTH) + 1;
293 | int startDay = startCalendar.get(Calendar.DAY_OF_MONTH);
294 | int startHour = startCalendar.get(Calendar.HOUR_OF_DAY);
295 | int startMinute = startCalendar.get(Calendar.MINUTE);
296 |
297 | updateItems(yearItems, DateItem.TYPE_YEAR, startYear, endYear);
298 | updateItems(monthItems, DateItem.TYPE_MONTH, startMonth, MAX_MONTH);
299 | int dayActualMaximum = startCalendar.getActualMaximum(Calendar.DAY_OF_MONTH);
300 | updateItems(dayItems, DateItem.TYPE_DAY, startDay, dayActualMaximum);
301 | updateItems(hourItems, DateItem.TYPE_HOUR, startHour, MAX_HOUR);
302 | updateItems(minuteItems, DateItem.TYPE_MINUTE, startMinute, MAX_MINUTE);
303 | mYearView.setItems(toArray(yearItems));
304 | mMonthView.setItems(toArray(monthItems));
305 | mDayView.setItems(toArray(dayItems));
306 | mHourView.setItems(toArray(hourItems));
307 | mMinuteView.setItems(toArray(minuteItems));
308 | }
309 |
310 | private void initOnScrollListener() {
311 | mYearView.setOnSelectedListener(new WheelView.OnSelectedListener() {
312 | @Override
313 | public void onSelected(Context context, int selectedIndex) {
314 | selectedCalendar.set(Calendar.YEAR, yearItems.get(selectedIndex).getValue());
315 | if (showConfig > SHOW_YEAR)
316 | onYearChanged();
317 | }
318 | });
319 | mMonthView.setOnSelectedListener(new WheelView.OnSelectedListener() {
320 | @Override
321 | public void onSelected(Context context, int selectedIndex) {
322 | int oldDayCount = getDayCount(selectedCalendar.get(Calendar.YEAR), selectedCalendar.get(Calendar.MONTH) + 1);
323 | int month = monthItems.get(selectedIndex).getValue();
324 | int newDayCount = getDayCount(selectedCalendar.get(Calendar.YEAR), month);
325 | if (newDayCount < oldDayCount) {
326 | int oldSelectedDay = selectedCalendar.get(Calendar.DAY_OF_MONTH);
327 | selectedCalendar.set(Calendar.DAY_OF_MONTH, Math.min(newDayCount, oldSelectedDay));
328 | }
329 | selectedCalendar.set(Calendar.MONTH, month - 1);
330 | if (showConfig > SHOW_YEAR_MONTH)
331 | onMonthChanged();
332 | }
333 | });
334 | mDayView.setOnSelectedListener(new WheelView.OnSelectedListener() {
335 | @Override
336 | public void onSelected(Context context, int selectedIndex) {
337 | selectedCalendar.set(Calendar.DAY_OF_MONTH, dayItems.get(selectedIndex).getValue());
338 | if (showConfig > SHOW_YEAR_MONTH_DAY)
339 | onDayChanged();
340 | }
341 | });
342 | mHourView.setOnSelectedListener(new WheelView.OnSelectedListener() {
343 | @Override
344 | public void onSelected(Context context, int selectedIndex) {
345 | selectedCalendar.set(Calendar.HOUR_OF_DAY, hourItems.get(selectedIndex).getValue());
346 | if (showConfig > SHOW_YEAR_MONTH_DAY_HOUR)
347 | onHourChanged();
348 | }
349 | });
350 | mMinuteView.setOnSelectedListener(new WheelView.OnSelectedListener() {
351 | @Override
352 | public void onSelected(Context context, int selectedIndex) {
353 | selectedCalendar.set(Calendar.MINUTE, minuteItems.get(selectedIndex).getValue());
354 | }
355 | });
356 | }
357 |
358 | private void initSelectedDate() {
359 | int year = selectedCalendar.get(Calendar.YEAR);
360 | int month = selectedCalendar.get(Calendar.MONTH);
361 | int day = selectedCalendar.get(Calendar.DAY_OF_MONTH);
362 | int hour = selectedCalendar.get(Calendar.HOUR_OF_DAY);
363 | int minute = selectedCalendar.get(Calendar.MINUTE);
364 | int index = findSelectedIndexByValue(yearItems, year);
365 | mYearView.setSelectedIndex(index, false);
366 | index = findSelectedIndexByValue(monthItems, month);
367 | mMonthView.setSelectedIndex(index, false);
368 | index = findSelectedIndexByValue(dayItems, day);
369 | mDayView.setSelectedIndex(index, false);
370 | index = findSelectedIndexByValue(hourItems, hour);
371 | mHourView.setSelectedIndex(index, false);
372 | index = findSelectedIndexByValue(minuteItems, minute);
373 | mMinuteView.setSelectedIndex(index, false);
374 | }
375 |
376 | private void onYearChanged() {
377 | //update month list
378 | int startYear = startCalendar.get(Calendar.YEAR);
379 | int endYear = endCalendar.get(Calendar.YEAR);
380 | int selectedYear = selectedCalendar.get(Calendar.YEAR);
381 | int startMonth = startCalendar.get(Calendar.MONTH) + 1;
382 | int endMonth = endCalendar.get(Calendar.MONTH) + 1;
383 | int selectedMonth = selectedCalendar.get(Calendar.MONTH) + 1;
384 | int tempIndex = -1;
385 | int lastSelectedIndex = -1;
386 | int startValue, endValue;
387 | if (isSameValue(selectedYear, startYear)) {
388 | startValue = startMonth;
389 | endValue = MAX_MONTH;
390 | } else if (isSameValue(selectedYear, endYear)) {
391 | startValue = MIN_MONTH;
392 | endValue = endMonth;
393 | } else {
394 | startValue = MIN_MONTH;
395 | endValue = MAX_MONTH;
396 | }
397 | monthItems.clear();
398 | for (int i = startValue; i <= endValue; i++) {
399 | tempIndex++;
400 | monthItems.add(new DateItem(DateItem.TYPE_MONTH, i));
401 | if (isSameValue(selectedMonth, i)) {
402 | lastSelectedIndex = tempIndex;
403 | }
404 | }
405 | int newSelectedIndex = keepLastSelected ? (lastSelectedIndex == -1 ? 0 : lastSelectedIndex) : 0;
406 | mMonthView.setItems(toArray(monthItems));
407 | mMonthView.setSelectedIndex(newSelectedIndex);
408 | }
409 |
410 | private void onMonthChanged() {
411 | //update day list
412 | int startYear = startCalendar.get(Calendar.YEAR);
413 | int endYear = endCalendar.get(Calendar.YEAR);
414 | int selectedYear = selectedCalendar.get(Calendar.YEAR);
415 | int startMonth = startCalendar.get(Calendar.MONTH) + 1;
416 | int endMonth = endCalendar.get(Calendar.MONTH) + 1;
417 | int selectedMonth = selectedCalendar.get(Calendar.MONTH) + 1;
418 | int startDay = startCalendar.get(Calendar.DAY_OF_MONTH);
419 | int endDay = endCalendar.get(Calendar.DAY_OF_MONTH);
420 | int selectedDay = selectedCalendar.get(Calendar.DAY_OF_MONTH);
421 | int tempIndex = -1;
422 | int lastSelectedIndex = -1;
423 | int startValue, endValue;
424 | if (isSameValue(selectedYear, startYear) && isSameValue(selectedMonth, startMonth)) {
425 | startValue = startDay;
426 | endValue = getDayCount(selectedYear, selectedMonth);
427 | } else if (isSameValue(selectedYear, endYear) && isSameValue(selectedMonth, endMonth)) {
428 | startValue = MIN_DAY;
429 | endValue = endDay;
430 | } else {
431 | startValue = MIN_DAY;
432 | endValue = getDayCount(selectedYear, selectedMonth);
433 | }
434 | dayItems.clear();
435 | for (int i = startValue; i <= endValue; i++) {
436 | tempIndex++;
437 | dayItems.add(new DateItem(DateItem.TYPE_DAY, i));
438 | if (isSameValue(selectedDay, i)) {
439 | lastSelectedIndex = tempIndex;
440 | }
441 | }
442 | int newSelectedIndex = keepLastSelected ? (lastSelectedIndex == -1 ? 0 : lastSelectedIndex) : 0;
443 | mDayView.setItems(toArray(dayItems));
444 | mDayView.setSelectedIndex(newSelectedIndex, false);
445 | }
446 |
447 | private int getDayCount(int year, int month) {
448 | int day = 0;
449 | if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
450 | day = 29;
451 | } else {
452 | day = 28;
453 | }
454 | switch (month) {
455 | case 1:
456 | case 3:
457 | case 5:
458 | case 7:
459 | case 8:
460 | case 10:
461 | case 12:
462 | return 31;
463 | case 4:
464 | case 6:
465 | case 9:
466 | case 11:
467 | return 30;
468 | case 2:
469 | return day;
470 |
471 | }
472 | return 0;
473 | }
474 |
475 | private void onDayChanged() {
476 | //update hour list
477 | int startYear = startCalendar.get(Calendar.YEAR);
478 | int endYear = endCalendar.get(Calendar.YEAR);
479 | int selectedYear = selectedCalendar.get(Calendar.YEAR);
480 | int startMonth = startCalendar.get(Calendar.MONTH) + 1;
481 | int endMonth = endCalendar.get(Calendar.MONTH) + 1;
482 | int selectedMonth = selectedCalendar.get(Calendar.MONTH) + 1;
483 | int startDay = startCalendar.get(Calendar.DAY_OF_MONTH);
484 | int endDay = endCalendar.get(Calendar.DAY_OF_MONTH);
485 | int selectedDay = selectedCalendar.get(Calendar.DAY_OF_MONTH);
486 | int startHour = startCalendar.get(Calendar.HOUR_OF_DAY);
487 | int endHour = endCalendar.get(Calendar.HOUR_OF_DAY);
488 | int selectedHour = selectedCalendar.get(Calendar.HOUR_OF_DAY);
489 | int tempIndex = -1;
490 | int lastSelectedIndex = -1;
491 | int startValue, endValue;
492 | if (isSameValue(selectedYear, startYear) && isSameValue(selectedMonth, startMonth) && isSameValue(selectedDay, startDay)) {
493 | startValue = startHour;
494 | endValue = MAX_HOUR;
495 | } else if (isSameValue(selectedYear, endYear) && isSameValue(selectedMonth, endMonth) && isSameValue(selectedDay, endDay)) {
496 | startValue = MIN_HOUR;
497 | endValue = endHour;
498 | } else {
499 | startValue = MIN_HOUR;
500 | endValue = MAX_HOUR;
501 | }
502 | hourItems.clear();
503 | for (int i = startValue; i <= endValue; i++) {
504 | tempIndex++;
505 | hourItems.add(new DateItem(DateItem.TYPE_HOUR, i));
506 | if (isSameValue(selectedHour, i)) {
507 | lastSelectedIndex = tempIndex;
508 | }
509 | }
510 | int newSelectedIndex = keepLastSelected ? (lastSelectedIndex == -1 ? 0 : lastSelectedIndex) : 0;
511 | mHourView.setItems(toArray(hourItems));
512 | mHourView.setSelectedIndex(newSelectedIndex);
513 | }
514 |
515 | private void onHourChanged() {
516 | //update minute list
517 | int startYear = startCalendar.get(Calendar.YEAR);
518 | int endYear = endCalendar.get(Calendar.YEAR);
519 | int selectedYear = selectedCalendar.get(Calendar.YEAR);
520 | int startMonth = startCalendar.get(Calendar.MONTH) + 1;
521 | int endMonth = endCalendar.get(Calendar.MONTH) + 1;
522 | int selectedMonth = selectedCalendar.get(Calendar.MONTH) + 1;
523 | int startDay = startCalendar.get(Calendar.DAY_OF_MONTH);
524 | int endDay = endCalendar.get(Calendar.DAY_OF_MONTH);
525 | int selectedDay = selectedCalendar.get(Calendar.DAY_OF_MONTH);
526 | int startHour = startCalendar.get(Calendar.HOUR_OF_DAY);
527 | int endHour = endCalendar.get(Calendar.HOUR_OF_DAY);
528 | int selectedHour = selectedCalendar.get(Calendar.HOUR_OF_DAY);
529 | int startMinute = startCalendar.get(Calendar.MINUTE);
530 | int endMinute = endCalendar.get(Calendar.MINUTE);
531 | int selectedMinute = selectedCalendar.get(Calendar.MINUTE);
532 | int tempIndex = -1;
533 | int lastSelectedIndex = -1;
534 | int startValue, endValue;
535 | if (isSameValue(selectedYear, startYear) && isSameValue(selectedMonth, startMonth) && isSameValue(selectedDay, startDay) && isSameValue(selectedHour, startHour)) {
536 | startValue = startMinute;
537 | endValue = MAX_MINUTE;
538 | } else if (selectedYear == endYear && selectedMonth == endMonth && selectedDay == endDay && selectedHour == endHour) {
539 | startValue = MIN_MINUTE;
540 | endValue = endMinute;
541 | } else {
542 | startValue = MIN_MINUTE;
543 | endValue = MAX_MINUTE;
544 | }
545 | minuteItems.clear();
546 | for (int i = startValue; i <= endValue; i++) {
547 | tempIndex++;
548 | minuteItems.add(new DateItem(DateItem.TYPE_MINUTE, i));
549 | if (isSameValue(selectedMinute, i)) {
550 | lastSelectedIndex = tempIndex;
551 | }
552 | }
553 | int newSelectedIndex = keepLastSelected ? (lastSelectedIndex == -1 ? 0 : lastSelectedIndex) : 0;
554 | mMinuteView.setItems(toArray(minuteItems));
555 | mMinuteView.setSelectedIndex(newSelectedIndex);
556 | }
557 |
558 | private int findSelectedIndexByValue(List items, int value) {
559 | int selectedIndex = 0;
560 | for (int i = 0; i < items.size(); i++) {
561 | if (isSameValue(value, items.get(i).getValue())) {
562 | selectedIndex = i;
563 | break;
564 | }
565 | }
566 | return selectedIndex;
567 | }
568 |
569 | private void updateItems(@NonNull List list, @DateItem.DateType int type, int startValue, int endValue) {
570 | list.clear();
571 | for (int i = startValue; i <= endValue; i++) {
572 | list.add(new DateItem(type, i));
573 | }
574 | }
575 |
576 | private boolean isScrolling() {
577 | if (showConfig == SHOW_YEAR) {
578 | return mYearView.isScrolling();
579 | } else if (showConfig == SHOW_YEAR_MONTH) {
580 | return mYearView.isScrolling()
581 | || mMonthView.isScrolling();
582 | } else if (showConfig == SHOW_YEAR_MONTH_DAY) {
583 | return mYearView.isScrolling()
584 | || mMonthView.isScrolling()
585 | || mDayView.isScrolling();
586 | } else if (showConfig == SHOW_YEAR_MONTH_DAY_HOUR) {
587 | return mYearView.isScrolling()
588 | || mMonthView.isScrolling()
589 | || mDayView.isScrolling()
590 | || mHourView.isScrolling();
591 | } else {
592 | return mYearView.isScrolling()
593 | || mMonthView.isScrolling()
594 | || mDayView.isScrolling()
595 | || mHourView.isScrolling()
596 | || mMinuteView.isScrolling();
597 | }
598 | }
599 |
600 | private boolean isSameValue(int value1, int value2) {
601 | return value1 == value2;
602 | }
603 |
604 | private DateItem[] toArray(List items) {
605 | DateItem[] result = new DateItem[items.size()];
606 | items.toArray(result);
607 | return result;
608 | }
609 |
610 | private void ensureIsViewInitialized() {
611 | if (!isViewInitialized)
612 | throw new IllegalStateException("View wasn't initialized, call show() first.");
613 | }
614 |
615 | public interface OnClickCallBack {
616 | boolean callBack(View v, @NonNull Date selectedDate);
617 | }
618 | }
619 |
--------------------------------------------------------------------------------
/wheelViewLibrary/src/main/java/jsc/kit/wheel/dialog/WheelDialogInterface.java:
--------------------------------------------------------------------------------
1 | package jsc.kit.wheel.dialog;
2 |
3 | import jsc.kit.wheel.base.IWheel;
4 |
5 | public interface WheelDialogInterface {
6 |
7 | boolean onClick(int witch, int selectedIndex, T item);
8 | }
--------------------------------------------------------------------------------
/wheelViewLibrary/src/main/res/layout/wheel_dialog_base.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
19 |
20 |
--------------------------------------------------------------------------------
/wheelViewLibrary/src/main/res/layout/wheel_dialog_title_bar.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
18 |
19 |
31 |
32 |
44 |
45 |
--------------------------------------------------------------------------------
/wheelViewLibrary/src/main/res/values/wheel_attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/wheelViewLibrary/src/main/res/values/wheel_color.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #F2F2F2
4 |
5 | @color/wheel_default_background
6 | @color/wheel_text_color_1
7 | #D81B60
8 | #008577
9 |
10 | #000000
11 | #FFFFFF
12 | #333333
13 | #666666
14 | #999999
15 | #CCCCCC
16 |
--------------------------------------------------------------------------------
/wheelViewLibrary/src/main/res/values/wheel_dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 15dp
5 | 15dp
6 | 15dp
7 |
8 | 0dp
9 | 4dp
10 | 0dp
11 | 4dp
12 |
13 | 4dp
14 |
15 |
--------------------------------------------------------------------------------
/wheelViewLibrary/src/main/res/values/wheel_ids.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/wheelViewLibrary/src/main/res/values/wheel_strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/wheelViewLibrary/src/main/res/values/wheel_style.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
--------------------------------------------------------------------------------
/wheelViewLibrary/src/test/java/jsc/kit/wheel/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package jsc.kit.wheel;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------