├── .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 | 15 | 16 | 17 | 37 | 54 | 55 | 56 | 57 | 58 | 59 | 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 | ![WheelView](/output/shots/wheel_view.png) 40 | 41 | + 3.2、[ColumnWheelDialog](/wheelLibrary/src/main/java/jsc/kit/wheel/dialog/ColumnWheelDialog.java) 42 | 43 | ![WheelView](/output/shots/column_wheel01.png) 44 | ![WheelView](/output/shots/column_wheel02.png) 45 | ![WheelView](/output/shots/column_wheel03.png) 46 | ![WheelView](/output/shots/column_wheel04.png) 47 | ![WheelView](/output/shots/column_wheel05.png) 48 | 49 | + 3.3、[DateTimeWheelDialog](/wheelLibrary/src/main/java/jsc/kit/wheel/dialog/DateTimeWheelDialog.java) 50 | 51 | ![OneColumnWheelDialog](/output/shots/date_time_wheel01.png) 52 | ![OneColumnWheelDialog](/output/shots/date_time_wheel02.png) 53 | ![OneColumnWheelDialog](/output/shots/date_time_wheel03.png) 54 | ![OneColumnWheelDialog](/output/shots/date_time_wheel04.png) 55 | ![OneColumnWheelDialog](/output/shots/date_time_wheel05.png) 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 |