├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── zion830 │ │ └── com │ │ └── rangetimepickerdialog │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── zion830 │ │ │ └── com │ │ │ └── rangetimepickerdialog │ │ │ └── MainActivity.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ └── activity_main.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 │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── zion830 │ └── com │ └── rangetimepickerdialog │ └── ExampleUnitTest.kt ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── range_picker_dialog ├── .gitignore ├── build.gradle ├── consumer-rules.pro ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── zion830 │ │ └── com │ │ └── range_picker_dialog │ │ ├── ExampleInstrumentedTest.kt │ │ └── TimeRangePickerTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── zion830 │ │ │ └── com │ │ │ └── range_picker_dialog │ │ │ ├── Buildable.kt │ │ │ ├── OnTimeRangeSelectedListener.kt │ │ │ ├── TimePickerUtils.kt │ │ │ ├── TimeRange.kt │ │ │ ├── TimeRangePicker.kt │ │ │ ├── TimeRangePickerBottomSheet.kt │ │ │ ├── TimeRangePickerDialog.kt │ │ │ ├── TimeRangeSelectable.kt │ │ │ └── ViewExt.kt │ └── res │ │ ├── drawable │ │ └── btn_back.xml │ │ ├── layout │ │ ├── time_range_picker_bottom_sheet_dialog.xml │ │ └── time_range_picker_dialog.xml │ │ ├── values-ja-rJP │ │ └── strings.xml │ │ ├── values-ko │ │ └── strings.xml │ │ ├── values-zh-rCN │ │ └── strings.xml │ │ └── values │ │ ├── colors.xml │ │ └── strings.xml │ └── test │ └── java │ └── zion830 │ └── com │ └── range_picker_dialog │ └── ExampleUnitTest.kt └── settings.gradle /README.md: -------------------------------------------------------------------------------- 1 | # TimeRangePickerDialog 2 | 3 | [![label1](https://jitpack.io/v/zion830/RangeTimePickerDialog.svg)](https://jitpack.io/#zion830/RangeTimePickerDialog) 4 | ![label2](https://img.shields.io/badge/API-21%2B-blue.svg?style=flat) 5 | 6 | Custom dialog for selecting the time range on Android. 7 | 8 | ## How To Start 9 | 1. Add it in your root build.gradle at the end of repositories: 10 | ```gradle 11 | allprojects { 12 | repositories { 13 | ... 14 | maven { url 'https://jitpack.io' } 15 | } 16 | } 17 | ``` 18 | 2. Add the dependency. The latest version is `1.3` 19 | ```gradle 20 | dependencies { 21 | implementation "com.github.zion830:RangeTimePickerDialog:$version_code" 22 | } 23 | ``` 24 | ## Usage 25 | - Show TimeRangePickerDialog 26 | ```kotlin 27 | TimeRangePickerDialog.Builder() 28 | .setTimeRange(10, 20, 16, 40) 29 | .setOnTimeRangeSelectedListener { timeRange -> /* Use selected time range */ } 30 | .build() 31 | .show(supportFragmentManager) 32 | ``` 33 | ## Options 34 | #### TimeRangePickerDialog 35 | | name| description| 36 | |---|---| 37 | |`timeRange`|First selected time. Default range is `${current hour}:00 ~ ${current hour + 1}:00`| 38 | | `oneDayMode`| `OK` button is disabled if `end time` is earlier than `start time`. Default value is true.| 39 | | `timeInterval`| Minute time interval. Default value is 10.| 40 | 41 | #### TimeRange 42 | | name| description| 43 | |---|---| 44 | |`startHour`|Selected start hour.| 45 | |`startMinute`|Selected start minute.| 46 | |`endHour`|Selected end hour.| 47 | |`endMinute`|Selected end minute.| 48 | | `readableTimeRange`| Return Time string like `AM 10:30 - PM 1:00`.| 49 | | `isCorrectSequence`| Return whether `start time` is earlier than `end time`.| 50 | 51 | ## License 52 | [MIT](https://choosealicense.com/licenses/mit/) 53 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | 5 | android { 6 | compileSdkVersion 33 7 | buildToolsVersion "29.0.3" 8 | 9 | defaultConfig { 10 | applicationId "zion830.com.rangetimepickerdialog" 11 | minSdkVersion 23 12 | targetSdkVersion 33 13 | versionCode 1 14 | versionName "1.0" 15 | 16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 17 | } 18 | 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | 26 | } 27 | 28 | dependencies { 29 | implementation fileTree(dir: 'libs', include: ['*.jar']) 30 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 31 | implementation 'androidx.appcompat:appcompat:1.1.0' 32 | implementation 'androidx.core:core-ktx:1.2.0' 33 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3' 34 | testImplementation 'junit:junit:4.12' 35 | androidTestImplementation 'androidx.test.ext:junit:1.1.1' 36 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' 37 | implementation 'com.google.android.material:material:1.1.0' 38 | 39 | implementation project(':range_picker_dialog') 40 | } 41 | -------------------------------------------------------------------------------- /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/zion830/com/rangetimepickerdialog/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package zion830.com.rangetimepickerdialog 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("zion830.com.rangetimepickerdialog", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/java/zion830/com/rangetimepickerdialog/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package zion830.com.rangetimepickerdialog 2 | 3 | import android.os.Bundle 4 | import androidx.appcompat.app.AppCompatActivity 5 | import kotlinx.android.synthetic.main.activity_main.* 6 | import zion830.com.range_picker_dialog.TimeRangePickerBottomSheet 7 | import zion830.com.range_picker_dialog.TimeRangePickerDialog 8 | 9 | class MainActivity : AppCompatActivity() { 10 | 11 | override fun onCreate(savedInstanceState: Bundle?) { 12 | super.onCreate(savedInstanceState) 13 | setContentView(R.layout.activity_main) 14 | 15 | btn_show_dialog.setOnClickListener { 16 | showDialog() 17 | } 18 | btn_show_bottom_sheet_dialog.setOnClickListener { 19 | showBottomSheetDialog() 20 | } 21 | } 22 | 23 | private fun showDialog() { 24 | TimeRangePickerDialog.Builder() 25 | .setTimeRange(10, 20, 16, 40) 26 | .setTimeInterval(20) 27 | .setOnDayMode(false) 28 | .setOnTimeRangeSelectedListener { tv_selected_range.text = it.readableTimeRange } 29 | .build() 30 | .show(supportFragmentManager) 31 | } 32 | 33 | private fun showBottomSheetDialog() { 34 | TimeRangePickerBottomSheet.getInstance().show(this) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /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 | 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/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 |