├── .gitignore ├── .idea ├── .gitignore ├── .name ├── compiler.xml ├── gradle.xml ├── inspectionProfiles │ └── Project_Default.xml ├── jarRepositories.xml ├── misc.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro ├── release │ ├── datetimepicker.apk │ └── output-metadata.json └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── gredicer │ │ └── datetimepickerDemo │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── ic_launcher-playstore.png │ ├── java │ │ └── com │ │ │ └── gredicer │ │ │ └── datetimepickerDemo │ │ │ └── MainActivity.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ ├── ic_launcher_background.xml │ │ ├── shape_button_corners.xml │ │ ├── shape_button_corners0.xml │ │ ├── shape_button_corners1.xml │ │ ├── shape_button_corners2.xml │ │ ├── shape_button_corners3.xml │ │ ├── shape_button_corners4.xml │ │ └── shape_button_corners5.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher_foreground.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher_foreground.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher_foreground.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher_foreground.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher_foreground.png │ │ ├── values-night │ │ └── themes.xml │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── themes.xml │ └── test │ └── java │ └── com │ └── gredicer │ └── datetimepickerDemo │ └── ExampleUnitTest.kt ├── build.gradle ├── datetimepicker ├── .gitignore ├── build.gradle ├── consumer-rules.pro ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── gredicer │ │ └── datetimepicker │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── gredicer │ │ │ └── datetimepicker │ │ │ ├── DatePickerAdapter.kt │ │ │ ├── DateTimePickerFragment.kt │ │ │ ├── DecelerateAnimator.kt │ │ │ ├── OutsideClickDialog.kt │ │ │ ├── PickAdapter.kt │ │ │ └── ScrollPickerView.kt │ └── res │ │ ├── drawable │ │ ├── shape_button_corners.xml │ │ └── shape_dialog_corners.xml │ │ ├── layout │ │ └── fragment_datetime_picker.xml │ │ └── values │ │ ├── attrs.xml │ │ ├── strings.xml │ │ └── themes.xml │ └── test │ └── java │ └── com │ └── gredicer │ └── datetimepicker │ └── ExampleUnitTest.kt ├── demo.gif ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.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 | local.properties 16 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | DatetimePickerDemo -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 20 | 21 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 36 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | 29 | 30 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # datetimepicker 2 | 一个非常好看的时间选择控件 3 | 4 | [![](https://jitpack.io/v/Gredicer/datetimepicker.svg)](https://jitpack.io/#Gredicer/datetimepicker) 5 | 6 | ### 演示效果 7 | ![](demo.gif) 8 | 9 | ### 引用 10 | Step 1. Add it in your root build.gradle at the end of repositories: 11 | ```kotlin 12 | allprojects { 13 | repositories { 14 | ... 15 | maven { url 'https://jitpack.io' } 16 | } 17 | } 18 | ``` 19 | 20 | Step 2. Add the dependency 21 | ```kotlin 22 | dependencies { 23 | implementation 'com.github.Gredicer:datetimepicker:V1.0.0' 24 | } 25 | ``` 26 | 27 | ### 使用 28 | 29 | 示例代码: 30 | 31 | ``` 32 | val dialog = DateTimePickerFragment.newInstance().mode(0).default("2010-10-10 11:11:11") 33 | 34 | btn.setOnClickListener { 35 | dialog.show(this.supportFragmentManager, null) 36 | } 37 | 38 | dialog.listener = object : DateTimePickerFragment.OnClickListener { 39 | override fun onClickListener(selectTime: String) { 40 | Toast.makeText(applicationContext, selectTime, Toast.LENGTH_SHORT).show() 41 | } 42 | } 43 | ``` 44 | 45 | `.default` 用来设置初始值,如果不设置默认为当前时间 46 | `mode`的值对应为: 47 | 48 | ``` 49 | 0:默认,年月日时分 50 | 1:年选择 51 | 2:年月选择 52 | 3:年月日选择 53 | 4:时间选择 54 | 5:设定初始时间 55 | ``` 56 | 57 | 58 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | id 'kotlin-android' 4 | id 'kotlin-android-extensions' 5 | } 6 | 7 | android { 8 | compileSdkVersion 30 9 | buildToolsVersion "30.0.3" 10 | 11 | defaultConfig { 12 | applicationId "com.gredicer.datetimepickerDemo" 13 | minSdkVersion 19 14 | targetSdkVersion 30 15 | versionCode 1 16 | versionName "1.0" 17 | 18 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 19 | } 20 | 21 | buildTypes { 22 | release { 23 | minifyEnabled false 24 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 25 | } 26 | } 27 | compileOptions { 28 | sourceCompatibility JavaVersion.VERSION_1_8 29 | targetCompatibility JavaVersion.VERSION_1_8 30 | } 31 | kotlinOptions { 32 | jvmTarget = '1.8' 33 | } 34 | buildFeatures { 35 | viewBinding true 36 | } 37 | } 38 | 39 | dependencies { 40 | 41 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 42 | implementation 'androidx.core:core-ktx:1.6.0' 43 | implementation 'androidx.appcompat:appcompat:1.3.1' 44 | implementation 'com.google.android.material:material:1.4.0' 45 | implementation 'androidx.constraintlayout:constraintlayout:2.0.4' 46 | implementation project(path: ':datetimepicker') 47 | testImplementation 'junit:junit:4.13.2' 48 | androidTestImplementation 'androidx.test.ext:junit:1.1.3' 49 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' 50 | implementation 'com.yanzhenjie:sofia:1.0.5' 51 | } -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /app/release/datetimepicker.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gredicer/datetimepicker/4a41584100e0ca00ae03427b1f3113fae2545a5f/app/release/datetimepicker.apk -------------------------------------------------------------------------------- /app/release/output-metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 2, 3 | "artifactType": { 4 | "type": "APK", 5 | "kind": "Directory" 6 | }, 7 | "applicationId": "com.gredicer.datetimepickerDemo", 8 | "variantName": "release", 9 | "elements": [ 10 | { 11 | "type": "SINGLE", 12 | "filters": [], 13 | "versionCode": 1, 14 | "versionName": "1.0", 15 | "outputFile": "app-release.apk" 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /app/src/androidTest/java/com/gredicer/datetimepickerDemo/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.gredicer.datetimepickerDemo 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("com.gredicer.datetimepickerDemo", appContext.packageName) 23 | } 24 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/ic_launcher-playstore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gredicer/datetimepicker/4a41584100e0ca00ae03427b1f3113fae2545a5f/app/src/main/ic_launcher-playstore.png -------------------------------------------------------------------------------- /app/src/main/java/com/gredicer/datetimepickerDemo/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.gredicer.datetimepickerDemo 2 | 3 | import android.os.Bundle 4 | import android.util.Log 5 | import android.widget.Toast 6 | import androidx.appcompat.app.AppCompatActivity 7 | import com.gredicer.datetimepicker.DateTimePickerFragment 8 | import com.yanzhenjie.sofia.Sofia 9 | import kotlinx.android.synthetic.main.activity_main.* 10 | import java.text.SimpleDateFormat 11 | import java.util.* 12 | 13 | class MainActivity : AppCompatActivity() { 14 | override fun onCreate(savedInstanceState: Bundle?) { 15 | super.onCreate(savedInstanceState) 16 | setContentView(R.layout.activity_main) 17 | 18 | Sofia.with(this) 19 | .statusBarDarkFont() // 状态栏深色字体。 20 | .invasionStatusBar() //内容入侵状态栏 21 | .navigationBarBackgroundAlpha(0) // 导航栏背景透明度。 22 | .statusBarBackgroundAlpha(0) // 状态栏背景透明度。 23 | .invasionNavigationBar() // 内容入侵导航栏。 24 | 25 | val dialog = DateTimePickerFragment.newInstance() 26 | btn1.setOnClickListener { 27 | dialog.mode(0) 28 | dialog.show(this.supportFragmentManager, null) 29 | } 30 | 31 | btn2.setOnClickListener { 32 | dialog.mode(1) 33 | dialog.show(this.supportFragmentManager, null) 34 | } 35 | 36 | btn3.setOnClickListener { 37 | dialog.mode(2) 38 | dialog.show(this.supportFragmentManager, null) 39 | } 40 | 41 | btn4.setOnClickListener { 42 | dialog.mode(3) 43 | dialog.show(this.supportFragmentManager, null) 44 | } 45 | 46 | btn5.setOnClickListener { 47 | dialog.mode(4) 48 | dialog.show(this.supportFragmentManager, null) 49 | } 50 | 51 | 52 | btn6.setOnClickListener { 53 | dialog.mode(0).default("2010-10-10 11:11:11") 54 | dialog.show(this.supportFragmentManager, null) 55 | } 56 | 57 | 58 | dialog.listener = object : DateTimePickerFragment.OnClickListener { 59 | override fun onClickListener(selectTime: String) { 60 | Toast.makeText(applicationContext, selectTime, Toast.LENGTH_SHORT).show() 61 | } 62 | } 63 | 64 | } 65 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 10 | 12 | 14 | 16 | 18 | 20 | 22 | 24 | 26 | 28 | 30 | 32 | 34 | 36 | 38 | 40 | 42 | 44 | 46 | 48 | 50 | 52 | 54 | 56 | 58 | 60 | 62 | 64 | 66 | 68 | 70 | 72 | 74 | 75 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/shape_button_corners.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/shape_button_corners0.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/shape_button_corners1.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/shape_button_corners2.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/shape_button_corners3.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/shape_button_corners4.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/shape_button_corners5.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 |