├── app ├── .gitignore ├── src │ └── main │ │ ├── res │ │ ├── values │ │ │ ├── strings.xml │ │ │ ├── colors.xml │ │ │ └── styles.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 │ │ ├── mipmap-anydpi-v26 │ │ │ ├── ic_launcher.xml │ │ │ └── ic_launcher_round.xml │ │ ├── menu │ │ │ └── menu_main.xml │ │ ├── layout │ │ │ ├── item_horizontal_picker.xml │ │ │ ├── item_vertical_picker.xml │ │ │ ├── activity_text_picker.xml │ │ │ ├── dialog_to_position.xml │ │ │ ├── activity_main.xml │ │ │ ├── dialog_setting.xml │ │ │ └── activity_date_picker.xml │ │ ├── drawable-v24 │ │ │ └── ic_launcher_foreground.xml │ │ └── drawable │ │ │ └── ic_launcher_background.xml │ │ ├── java │ │ └── demo │ │ │ └── simple │ │ │ └── picker │ │ │ ├── KTX.kt │ │ │ ├── BaseActivity.kt │ │ │ ├── TextPickerActivity.kt │ │ │ ├── LogLinearLayoutManager.kt │ │ │ ├── DatePickerActivity.kt │ │ │ └── MainActivity.kt │ │ └── AndroidManifest.xml ├── proguard-rules.pro └── build.gradle ├── .jitpack.yml ├── picker_layoutmanager ├── .gitignore ├── consumer-rules.pro ├── src │ └── main │ │ ├── AndroidManifest.xml │ │ ├── res │ │ ├── layout │ │ │ └── item_text_picker.xml │ │ └── values │ │ │ └── attrs.xml │ │ └── java │ │ └── me │ │ └── simple │ │ └── picker │ │ ├── timepicker │ │ ├── SecondPickerView.kt │ │ ├── MinutePickerView.kt │ │ ├── HourPickerView.kt │ │ └── TimePickerView.kt │ │ ├── datepicker │ │ ├── MonthPickerView.kt │ │ ├── YearPickerView.kt │ │ ├── DayPickerView.kt │ │ └── DatePickerView.kt │ │ ├── utils │ │ ├── CenterHelperLineItemDecoration.kt │ │ └── PickerUtils.kt │ │ ├── PickerItemDecoration.kt │ │ ├── widget │ │ ├── TextPickerView.kt │ │ └── TextPickerLinearLayout.kt │ │ ├── PickerRecyclerView.kt │ │ └── PickerLayoutManager.kt ├── proguard-rules.pro └── build.gradle ├── files ├── gif_picker.gif ├── gif_text_picker.gif └── gif_date_time_picker.gif ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .idea ├── codeStyles │ ├── codeStyleConfig.xml │ └── Project.xml ├── compiler.xml ├── vcs.xml ├── gradle.xml ├── misc.xml └── jarRepositories.xml ├── .gitignore ├── settings.gradle ├── LICENSE ├── gradle.properties ├── gradlew.bat ├── README.md └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /.jitpack.yml: -------------------------------------------------------------------------------- 1 | jdk: 2 | - openjdk11 -------------------------------------------------------------------------------- /picker_layoutmanager/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /picker_layoutmanager/consumer-rules.pro: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /files/gif_picker.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simplepeng/PickerLayoutManager/HEAD/files/gif_picker.gif -------------------------------------------------------------------------------- /files/gif_text_picker.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simplepeng/PickerLayoutManager/HEAD/files/gif_text_picker.gif -------------------------------------------------------------------------------- /files/gif_date_time_picker.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simplepeng/PickerLayoutManager/HEAD/files/gif_date_time_picker.gif -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | PickerLayoutManager 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simplepeng/PickerLayoutManager/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simplepeng/PickerLayoutManager/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simplepeng/PickerLayoutManager/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simplepeng/PickerLayoutManager/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simplepeng/PickerLayoutManager/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simplepeng/PickerLayoutManager/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /picker_layoutmanager/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simplepeng/PickerLayoutManager/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simplepeng/PickerLayoutManager/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simplepeng/PickerLayoutManager/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simplepeng/PickerLayoutManager/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simplepeng/PickerLayoutManager/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/java/demo/simple/picker/KTX.kt: -------------------------------------------------------------------------------- 1 | package demo.simple.picker 2 | 3 | import android.content.res.Resources 4 | 5 | val Float.dp: Float 6 | get() = Resources.getSystem().displayMetrics.density * this + 0.5f -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #6200EE 4 | #3700B3 5 | #03DAC5 6 | 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Nov 27 22:49:18 CST 2021 2 | distributionBase=GRADLE_USER_HOME 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip 4 | distributionPath=wrapper/dists 5 | zipStorePath=wrapper/dists 6 | zipStoreBase=GRADLE_USER_HOME -------------------------------------------------------------------------------- /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/java/demo/simple/picker/BaseActivity.kt: -------------------------------------------------------------------------------- 1 | package demo.simple.picker 2 | 3 | import android.widget.Toast 4 | import androidx.appcompat.app.AppCompatActivity 5 | 6 | open class BaseActivity : AppCompatActivity() { 7 | 8 | 9 | fun toast(text:String?){ 10 | Toast.makeText(this,text,Toast.LENGTH_SHORT).show() 11 | } 12 | } -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | dependencyResolutionManagement { 2 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) 3 | repositories { 4 | google() 5 | mavenCentral() 6 | jcenter() // Warning: this repository is going to shut down soon 7 | maven { url 'https://jitpack.io' } 8 | } 9 | } 10 | rootProject.name='PickerLayoutManager' 11 | include ':app' 12 | include ':picker_layoutmanager' 13 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /picker_layoutmanager/src/main/res/layout/item_text_picker.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 11 | 12 | 15 | 16 | 19 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 19 | 20 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | 13 | 14 | 15 | 16 | 18 | -------------------------------------------------------------------------------- /picker_layoutmanager/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 | -------------------------------------------------------------------------------- /picker_layoutmanager/src/main/java/me/simple/picker/timepicker/SecondPickerView.kt: -------------------------------------------------------------------------------- 1 | package me.simple.picker.timepicker 2 | 3 | import android.content.Context 4 | import android.util.AttributeSet 5 | import me.simple.picker.utils.PickerUtils 6 | import me.simple.picker.widget.TextPickerView 7 | 8 | open class SecondPickerView @JvmOverloads constructor( 9 | context: Context, 10 | attrs: AttributeSet? = null, 11 | defStyleAttr: Int = 0 12 | ) : TextPickerView(context, attrs, defStyleAttr) { 13 | 14 | init { 15 | setMinuteInterval() 16 | } 17 | 18 | fun setMinuteInterval(start: Int = 0, end: Int = 60) { 19 | mItems.clear() 20 | for (minute in start until end) { 21 | mItems.add(PickerUtils.formatTwoChars(minute)) 22 | } 23 | adapter?.notifyDataSetChanged() 24 | } 25 | 26 | fun getSecond() = getSelectedItem() 27 | } -------------------------------------------------------------------------------- /picker_layoutmanager/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.library' 3 | id 'kotlin-android' 4 | id 'maven-publish' 5 | } 6 | 7 | afterEvaluate { 8 | publishing { 9 | publications { 10 | release(MavenPublication) { 11 | from components.release 12 | } 13 | } 14 | } 15 | } 16 | 17 | android { 18 | compileSdk 31 19 | 20 | defaultConfig { 21 | minSdk 16 22 | targetSdk 31 23 | } 24 | 25 | compileOptions { 26 | sourceCompatibility JavaVersion.VERSION_1_8 27 | targetCompatibility JavaVersion.VERSION_1_8 28 | } 29 | 30 | kotlinOptions { 31 | jvmTarget = '1.8' 32 | } 33 | 34 | //指定不生成BuildConfig.java 35 | buildFeatures{ 36 | buildConfig = false 37 | } 38 | } 39 | 40 | dependencies { 41 | api "androidx.recyclerview:recyclerview:1.2.1" 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/java/demo/simple/picker/TextPickerActivity.kt: -------------------------------------------------------------------------------- 1 | package demo.simple.picker 2 | 3 | import android.os.Bundle 4 | import demo.simple.picker.databinding.ActivityTextPickerBinding 5 | 6 | class TextPickerActivity : BaseActivity() { 7 | 8 | private val binding by lazy { ActivityTextPickerBinding.inflate(this.layoutInflater) } 9 | 10 | override fun onCreate(savedInstanceState: Bundle?) { 11 | super.onCreate(savedInstanceState) 12 | setContentView(binding.root) 13 | 14 | val items = mutableListOf() 15 | for (index in 0 until 100) { 16 | items.add(index.toString()) 17 | } 18 | 19 | binding.textPickerView.setData(items) 20 | 21 | // textPickerView.run { 22 | // setVisibleCount(5) 23 | // setIsLoop(true) 24 | // setSelectedIsBold(true) 25 | // setSelectedTextColor(Color.RED) 26 | // 27 | // resetLayoutManager() 28 | // } 29 | } 30 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /picker_layoutmanager/src/main/java/me/simple/picker/timepicker/MinutePickerView.kt: -------------------------------------------------------------------------------- 1 | package me.simple.picker.timepicker 2 | 3 | import android.content.Context 4 | import android.util.AttributeSet 5 | import me.simple.picker.utils.PickerUtils 6 | import me.simple.picker.widget.TextPickerView 7 | 8 | open class MinutePickerView @JvmOverloads constructor( 9 | context: Context, 10 | attrs: AttributeSet? = null, 11 | defStyleAttr: Int = 0 12 | ) : TextPickerView(context, attrs, defStyleAttr) { 13 | 14 | init { 15 | setMinuteInterval() 16 | } 17 | 18 | fun setMinuteInterval( 19 | start: Int = PickerUtils.START_MINUTE, 20 | end: Int = PickerUtils.END_MINUTE 21 | ) { 22 | mItems.clear() 23 | for (minute in start..end) { 24 | mItems.add(PickerUtils.formatTwoChars(minute)) 25 | } 26 | adapter!!.notifyDataSetChanged() 27 | } 28 | 29 | fun getMinuteStr() = getSelectedItem() 30 | 31 | fun getMinute() = getMinuteStr().toInt() 32 | } -------------------------------------------------------------------------------- /picker_layoutmanager/src/main/java/me/simple/picker/timepicker/HourPickerView.kt: -------------------------------------------------------------------------------- 1 | package me.simple.picker.timepicker 2 | 3 | import android.content.Context 4 | import android.util.AttributeSet 5 | import me.simple.picker.utils.PickerUtils 6 | import me.simple.picker.widget.TextPickerView 7 | 8 | open class HourPickerView @JvmOverloads constructor( 9 | context: Context, 10 | attrs: AttributeSet? = null, 11 | defStyleAttr: Int = 0 12 | ) : TextPickerView(context, attrs, defStyleAttr) { 13 | 14 | init { 15 | setHourInterval() 16 | } 17 | 18 | @SuppressWarnings 19 | fun setHourInterval( 20 | start: Int = PickerUtils.START_HOUR, 21 | end: Int = PickerUtils.END_HOUR 22 | ) { 23 | mItems.clear() 24 | for (hour in start..end) { 25 | mItems.add(PickerUtils.formatTwoChars(hour)) 26 | } 27 | adapter?.notifyDataSetChanged() 28 | } 29 | 30 | fun getHourStr() = getSelectedItem() 31 | 32 | fun getHour() = getHourStr().toInt() 33 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/item_horizontal_picker.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_vertical_picker.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_text_picker.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 21 | -------------------------------------------------------------------------------- /picker_layoutmanager/src/main/java/me/simple/picker/datepicker/MonthPickerView.kt: -------------------------------------------------------------------------------- 1 | package me.simple.picker.datepicker 2 | 3 | import android.content.Context 4 | import android.util.AttributeSet 5 | import me.simple.picker.utils.PickerUtils 6 | import me.simple.picker.widget.TextPickerView 7 | 8 | open class MonthPickerView @JvmOverloads constructor( 9 | context: Context, 10 | attrs: AttributeSet? = null, 11 | defStyleAttr: Int = 0 12 | ) : TextPickerView(context, attrs, defStyleAttr) { 13 | 14 | init { 15 | setMonthInterval() 16 | } 17 | 18 | fun setMonthInterval( 19 | startMonth: Int = 1, 20 | endMonth: Int = 12 21 | ) { 22 | mItems.clear() 23 | for (month in startMonth..endMonth) { 24 | mItems.add(PickerUtils.formatTwoChars(month)) 25 | } 26 | adapter?.notifyDataSetChanged() 27 | } 28 | 29 | fun getMonthStr() = getSelectedItem() 30 | 31 | fun getMonth() = getSelectedItem().toInt() 32 | 33 | fun selectedItem(number: Int) { 34 | selectedItem(PickerUtils.formatTwoChars(number)) 35 | } 36 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Peng Chen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /app/src/main/java/demo/simple/picker/LogLinearLayoutManager.kt: -------------------------------------------------------------------------------- 1 | package demo.simple.picker 2 | 3 | import android.content.Context 4 | import android.util.AttributeSet 5 | import android.util.Log 6 | import androidx.recyclerview.widget.LinearLayoutManager 7 | import androidx.recyclerview.widget.RecyclerView 8 | 9 | class LogLinearLayoutManager : LinearLayoutManager { 10 | 11 | private val TAG = "LogLinearLayoutManager" 12 | 13 | constructor(context: Context?) : super(context) 14 | constructor(context: Context?, orientation: Int, reverseLayout: Boolean) : super( 15 | context, 16 | orientation, 17 | reverseLayout 18 | ) 19 | 20 | constructor( 21 | context: Context?, 22 | attrs: AttributeSet?, 23 | defStyleAttr: Int, 24 | defStyleRes: Int 25 | ) : super(context, attrs, defStyleAttr, defStyleRes) 26 | 27 | override fun onLayoutChildren(recycler: RecyclerView.Recycler?, state: RecyclerView.State?) { 28 | super.onLayoutChildren(recycler, state) 29 | 30 | Log.d(TAG, "onLayoutChildren") 31 | } 32 | 33 | override fun isAutoMeasureEnabled(): Boolean { 34 | // return false 35 | return super.isAutoMeasureEnabled() 36 | } 37 | } -------------------------------------------------------------------------------- /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=-Xmx1536m 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 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | # Kotlin code style for this project: "official" or "obsolete": 21 | kotlin.code.style=official 22 | -------------------------------------------------------------------------------- /picker_layoutmanager/src/main/java/me/simple/picker/datepicker/YearPickerView.kt: -------------------------------------------------------------------------------- 1 | package me.simple.picker.datepicker 2 | 3 | import android.content.Context 4 | import android.util.AttributeSet 5 | import me.simple.picker.utils.PickerUtils 6 | import me.simple.picker.widget.TextPickerView 7 | 8 | open class YearPickerView @JvmOverloads constructor( 9 | context: Context, 10 | attrs: AttributeSet? = null, 11 | defStyleAttr: Int = 0 12 | ) : TextPickerView(context, attrs, defStyleAttr) { 13 | 14 | init { 15 | setYearInterval() 16 | } 17 | 18 | fun setYearInterval( 19 | startYear: Int = PickerUtils.START_YEAR, 20 | endYear: Int = PickerUtils.getCurrentYear() 21 | ) { 22 | mItems.clear() 23 | for (year in startYear..endYear) { 24 | mItems.add(year.toString()) 25 | } 26 | adapter?.notifyDataSetChanged() 27 | } 28 | 29 | fun getYear(position: Int): Int { 30 | return mItems[position].toInt() 31 | } 32 | 33 | fun getYear(): Int { 34 | return getYearStr().toInt() 35 | } 36 | 37 | fun getYearStr(): String { 38 | return getSelectedItem() 39 | } 40 | 41 | fun selectedItem(number: Int) { 42 | selectedItem(number.toString()) 43 | } 44 | } -------------------------------------------------------------------------------- /picker_layoutmanager/src/main/java/me/simple/picker/datepicker/DayPickerView.kt: -------------------------------------------------------------------------------- 1 | package me.simple.picker.datepicker 2 | 3 | import android.content.Context 4 | import android.util.AttributeSet 5 | import me.simple.picker.utils.PickerUtils 6 | import me.simple.picker.widget.TextPickerView 7 | 8 | open class DayPickerView @JvmOverloads constructor( 9 | context: Context, 10 | attrs: AttributeSet? = null, 11 | defStyleAttr: Int = 0 12 | ) : TextPickerView(context, attrs, defStyleAttr) { 13 | 14 | init { 15 | setDayInterval() 16 | } 17 | 18 | fun setDayInterval( 19 | startDay: Int = 1, 20 | endDay: Int = 31 21 | ) { 22 | mItems.clear() 23 | for (day in startDay..endDay) { 24 | mItems.add(PickerUtils.formatTwoChars(day)) 25 | } 26 | adapter?.notifyDataSetChanged() 27 | } 28 | 29 | fun setDayIntervalByMonth( 30 | year: Int, 31 | month: Int, 32 | startDay: Int = 1 33 | ) { 34 | setDayInterval(startDay, endDay = PickerUtils.getDayCountInMonth(year, month)) 35 | } 36 | 37 | fun getDayStr() = getSelectedItem() 38 | 39 | fun getDay() = getDayStr().toInt() 40 | 41 | fun selectedItem(number: Int) { 42 | selectedItem(PickerUtils.formatTwoChars(number)) 43 | } 44 | } -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | 29 | 30 | -------------------------------------------------------------------------------- /picker_layoutmanager/src/main/java/me/simple/picker/utils/CenterHelperLineItemDecoration.kt: -------------------------------------------------------------------------------- 1 | package me.simple.picker.utils 2 | 3 | import android.graphics.Canvas 4 | import android.graphics.Color 5 | import android.graphics.Paint 6 | import androidx.recyclerview.widget.RecyclerView 7 | import me.simple.picker.PickerLayoutManager 8 | 9 | open class CenterHelperLineItemDecoration : RecyclerView.ItemDecoration() { 10 | 11 | private val mPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { 12 | color = Color.RED 13 | style = Paint.Style.FILL 14 | } 15 | 16 | override fun onDrawOver(canvas: Canvas, parent: RecyclerView, state: RecyclerView.State) { 17 | super.onDrawOver(canvas, parent, state) 18 | if (parent.layoutManager == null || parent.layoutManager !is PickerLayoutManager) return 19 | 20 | drawCenterLine(canvas, parent) 21 | } 22 | 23 | private fun drawCenterLine(canvas: Canvas, parent: RecyclerView) { 24 | val width = parent.width.toFloat() 25 | val height = parent.height.toFloat() 26 | val lm = parent.layoutManager as PickerLayoutManager 27 | 28 | if (lm.orientation == PickerLayoutManager.HORIZONTAL) { 29 | canvas.drawLine(width / 2, 0f, width / 2, height, mPaint) 30 | } else { 31 | canvas.drawLine(0f, height / 2f, width, height / 2f, mPaint) 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | id 'kotlin-android' 4 | } 5 | 6 | android { 7 | compileSdk 30 8 | 9 | defaultConfig { 10 | applicationId "demo.simple.pickerlayoutmanager" 11 | minSdk 16 12 | targetSdk 30 13 | versionCode 1 14 | versionName "1.0" 15 | 16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 17 | 18 | viewBinding { 19 | enabled = true 20 | } 21 | } 22 | 23 | buildTypes { 24 | release { 25 | minifyEnabled false 26 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 27 | } 28 | } 29 | 30 | compileOptions { 31 | sourceCompatibility JavaVersion.VERSION_1_8 32 | targetCompatibility JavaVersion.VERSION_1_8 33 | } 34 | 35 | kotlinOptions { 36 | jvmTarget = '1.8' 37 | } 38 | } 39 | 40 | dependencies { 41 | implementation 'androidx.core:core-ktx:1.3.2' 42 | implementation 'androidx.appcompat:appcompat:1.2.0' 43 | implementation 'com.google.android.material:material:1.3.0' 44 | implementation 'androidx.constraintlayout:constraintlayout:2.0.4' 45 | testImplementation 'junit:junit:4.+' 46 | androidTestImplementation 'androidx.test.ext:junit:1.1.2' 47 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' 48 | 49 | // implementation project(path: ':picker_layoutmanager') 50 | implementation 'com.github.simplepeng:PickerLayoutManager:v1.0.5' 51 | } 52 | -------------------------------------------------------------------------------- /app/src/main/res/layout/dialog_to_position.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 18 | 19 |