├── 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 | [](https://jitpack.io/#zion830/RangeTimePickerDialog)
4 | 
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 |
19 |
20 |
29 |
30 |
40 |
41 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zion830/TimeRangePickerDialog/b0e7f8290c08d6043dc3ca947e3f31896bb16ff2/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zion830/TimeRangePickerDialog/b0e7f8290c08d6043dc3ca947e3f31896bb16ff2/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zion830/TimeRangePickerDialog/b0e7f8290c08d6043dc3ca947e3f31896bb16ff2/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zion830/TimeRangePickerDialog/b0e7f8290c08d6043dc3ca947e3f31896bb16ff2/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zion830/TimeRangePickerDialog/b0e7f8290c08d6043dc3ca947e3f31896bb16ff2/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zion830/TimeRangePickerDialog/b0e7f8290c08d6043dc3ca947e3f31896bb16ff2/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zion830/TimeRangePickerDialog/b0e7f8290c08d6043dc3ca947e3f31896bb16ff2/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zion830/TimeRangePickerDialog/b0e7f8290c08d6043dc3ca947e3f31896bb16ff2/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zion830/TimeRangePickerDialog/b0e7f8290c08d6043dc3ca947e3f31896bb16ff2/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zion830/TimeRangePickerDialog/b0e7f8290c08d6043dc3ca947e3f31896bb16ff2/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #6200EE
4 | #3700B3
5 | #03DAC5
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | RangeTimePickerDialog
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/zion830/com/rangetimepickerdialog/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package zion830.com.rangetimepickerdialog
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | ext.kotlin_version = '1.7.20'
5 | repositories {
6 | google()
7 | mavenCentral()
8 | maven { url "https://jitpack.io" }
9 | }
10 | dependencies {
11 | classpath 'com.android.tools.build:gradle:4.2.2'
12 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
13 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
14 |
15 | // NOTE: Do not place your application dependencies here; they belong
16 | // in the individual module build.gradle files
17 | }
18 | }
19 |
20 | allprojects {
21 | repositories {
22 | google()
23 | mavenCentral()
24 |
25 | }
26 | }
27 |
28 | task clean(type: Delete) {
29 | delete rootProject.buildDir
30 | }
31 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zion830/TimeRangePickerDialog/b0e7f8290c08d6043dc3ca947e3f31896bb16ff2/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue May 26 20:39:53 KST 2020
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/range_picker_dialog/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/range_picker_dialog/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'com.github.dcendents.android-maven'
4 | group = 'com.github.zion830'
5 | version = '1.0'
6 |
7 | android {
8 | compileSdkVersion 29
9 | buildToolsVersion "29.0.3"
10 |
11 | defaultConfig {
12 | minSdkVersion 21
13 | targetSdkVersion 29
14 | versionCode 1
15 | versionName "1.0"
16 |
17 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
18 | consumerProguardFiles 'consumer-rules.pro'
19 | }
20 | viewBinding {
21 | enabled = true
22 | }
23 | buildTypes {
24 | release {
25 | minifyEnabled false
26 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
27 | }
28 | }
29 |
30 | }
31 |
32 | dependencies {
33 | implementation fileTree(dir: 'libs', include: ['*.jar'])
34 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
35 | implementation 'androidx.appcompat:appcompat:1.1.0'
36 | implementation 'androidx.core:core-ktx:1.2.0'
37 | testImplementation 'junit:junit:4.12'
38 | androidTestImplementation 'androidx.test.ext:junit:1.1.1'
39 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
40 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
41 | implementation 'com.google.android.material:material:1.1.0'
42 | }
43 |
--------------------------------------------------------------------------------
/range_picker_dialog/consumer-rules.pro:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zion830/TimeRangePickerDialog/b0e7f8290c08d6043dc3ca947e3f31896bb16ff2/range_picker_dialog/consumer-rules.pro
--------------------------------------------------------------------------------
/range_picker_dialog/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 |
--------------------------------------------------------------------------------
/range_picker_dialog/src/androidTest/java/zion830/com/range_picker_dialog/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package zion830.com.range_picker_dialog
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.range_picker_dialog.test", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/range_picker_dialog/src/androidTest/java/zion830/com/range_picker_dialog/TimeRangePickerTest.kt:
--------------------------------------------------------------------------------
1 | package zion830.com.range_picker_dialog
2 |
3 | import android.content.Context
4 | import androidx.test.core.app.ApplicationProvider
5 | import org.junit.Assert
6 | import org.junit.Before
7 | import org.junit.Test
8 |
9 | class TimeRangePickerTest {
10 | private lateinit var timeRangePicker: TimeRangePicker
11 |
12 | @Before
13 | fun setUp() {
14 | val app: Context = ApplicationProvider.getApplicationContext()
15 | timeRangePicker = TimeRangePicker(app)
16 | }
17 |
18 | @Test
19 | fun testSetTimeInterval() {
20 | timeRangePicker.timeInterval = 100
21 | Assert.assertEquals(timeRangePicker.timeInterval, TimeRangePicker.maxInterval)
22 | }
23 |
24 | @Test
25 | fun testGetDisplayedMinutes() {
26 | val method =
27 | timeRangePicker::class.java.getDeclaredMethod("getDisplayedValue", Int::class.java)
28 | method.isAccessible = true
29 | val result: Array = method.invoke(timeRangePicker, 10) as Array
30 | Assert.assertArrayEquals(result, arrayOf("00", "10", "20", "30", "40", "50"))
31 | }
32 | }
--------------------------------------------------------------------------------
/range_picker_dialog/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/range_picker_dialog/src/main/java/zion830/com/range_picker_dialog/Buildable.kt:
--------------------------------------------------------------------------------
1 | package zion830.com.range_picker_dialog
2 |
3 | interface Buildable {
4 |
5 | fun build(): T
6 | }
--------------------------------------------------------------------------------
/range_picker_dialog/src/main/java/zion830/com/range_picker_dialog/OnTimeRangeSelectedListener.kt:
--------------------------------------------------------------------------------
1 | package zion830.com.range_picker_dialog
2 |
3 | interface OnTimeRangeSelectedListener {
4 |
5 | fun onTimeSelected(timeRange: TimeRange)
6 | }
--------------------------------------------------------------------------------
/range_picker_dialog/src/main/java/zion830/com/range_picker_dialog/TimePickerUtils.kt:
--------------------------------------------------------------------------------
1 | package zion830.com.range_picker_dialog
2 |
3 | import androidx.annotation.IntRange
4 | import java.util.*
5 |
6 | internal object TimePickerUtils {
7 | const val MINUTE_FORMAT = "%02d"
8 | const val MINUTES_MIN = 0
9 | const val MINUTES_MAX = 60
10 |
11 | private const val DEFAULT_HOUR_RANGE = 1
12 | private const val AM = "AM"
13 | private const val PM = "PM"
14 | private const val timeTextFormat = "%s %d:%02d - %s %d:%02d"
15 |
16 | fun getCurrentTimeRange(): TimeRange {
17 | val startHour = Calendar.getInstance()[Calendar.HOUR_OF_DAY]
18 | val endHour = if (startHour < 23) startHour + DEFAULT_HOUR_RANGE else startHour
19 | return TimeRange(startHour, MINUTES_MIN, endHour, MINUTES_MIN)
20 | }
21 |
22 | fun getReadableTimeString(
23 | @IntRange(from = 1, to = 23) startHour: Int,
24 | @IntRange(from = 0, to = 59) startMin: Int,
25 | @IntRange(from = 1, to = 23) endHour: Int,
26 | @IntRange(from = 0, to = 59) endMin: Int
27 | ): String = timeTextFormat.format(
28 | getAmPm(startHour), getHourForAmPm(startHour), startMin,
29 | getAmPm(endHour), getHourForAmPm(endHour), endMin
30 | )
31 |
32 | fun isCorrectSequence(timeRange: TimeRange): Boolean = with(timeRange) {
33 | isCorrectSequence(startHour, startMinute, endHour, startHour)
34 | }
35 |
36 | fun isCorrectSequence(
37 | @IntRange(from = 1, to = 23) startHour: Int,
38 | @IntRange(from = 0, to = 59) startMin: Int,
39 | @IntRange(from = 1, to = 23) endHour: Int,
40 | @IntRange(from = 0, to = 59) endMin: Int
41 | ) = when {
42 | startHour < endHour -> true
43 | startHour > endHour -> false
44 | else -> startMin < endMin
45 | }
46 |
47 | private fun getAmPm(@IntRange(from = 1, to = 23) hour: Int) = if (hour >= 12) PM else AM
48 |
49 | private fun getHourForAmPm(hour: Int) = when {
50 | hour == 0 -> 12
51 | hour > 12 -> hour - 12
52 | else -> hour
53 | }
54 | }
--------------------------------------------------------------------------------
/range_picker_dialog/src/main/java/zion830/com/range_picker_dialog/TimeRange.kt:
--------------------------------------------------------------------------------
1 | package zion830.com.range_picker_dialog
2 |
3 | import androidx.annotation.IntRange
4 |
5 | data class TimeRange(
6 | @IntRange(from = 1, to = 23) val startHour: Int,
7 | @IntRange(from = 0, to = 59) val startMinute: Int,
8 | @IntRange(from = 1, to = 23) val endHour: Int,
9 | @IntRange(from = 0, to = 59) val endMinute: Int
10 | ) {
11 | // Time string like 'AM 10:30 - PM 1:00'
12 | val readableTimeRange =
13 | TimePickerUtils.getReadableTimeString(startHour, startMinute, endHour, endMinute)
14 |
15 | // Return whether the start time is earlier than the end time
16 | fun isCorrectSequence() =
17 | TimePickerUtils.isCorrectSequence(startHour, startMinute, endHour, endMinute)
18 | }
--------------------------------------------------------------------------------
/range_picker_dialog/src/main/java/zion830/com/range_picker_dialog/TimeRangePicker.kt:
--------------------------------------------------------------------------------
1 | package zion830.com.range_picker_dialog
2 |
3 | import android.annotation.SuppressLint
4 | import android.content.Context
5 | import android.os.Build
6 | import android.util.AttributeSet
7 | import android.util.Log
8 | import android.widget.NumberPicker
9 | import android.widget.TimePicker
10 | import androidx.annotation.IntRange
11 | import androidx.core.math.MathUtils
12 |
13 | internal class TimeRangePicker @JvmOverloads constructor(
14 | context: Context,
15 | attrs: AttributeSet? = null
16 | ) : TimePicker(context, attrs) {
17 | var timeInterval = defaultInterval
18 | set(@IntRange(from = 0, to = 60) value) {
19 | if (field !in minInterval..maxInterval) {
20 | Log.w("RangeTimePicker", "timeInterval must be between $minInterval..$maxInterval")
21 | }
22 |
23 | field = MathUtils.clamp(value, minInterval, maxInterval)
24 | setInterval(field)
25 | invalidate()
26 | }
27 |
28 | companion object {
29 | const val defaultInterval = 10
30 | const val minInterval = 1
31 | const val maxInterval = 60
32 | }
33 |
34 | init {
35 | setInterval(timeInterval)
36 | setDisplayedMinute(0)
37 | }
38 |
39 | @SuppressLint("PrivateApi")
40 | fun setInterval(@IntRange(from = 1, to = 60) interval: Int) {
41 | try {
42 | val classForId = Class.forName("com.android.internal.R\$id")
43 | val fieldId = classForId.getField("minute").getInt(null)
44 | (this.findViewById(fieldId) as NumberPicker).run {
45 | minValue = TimePickerUtils.MINUTES_MIN
46 | maxValue = TimePickerUtils.MINUTES_MAX / interval - 1
47 | displayedValues = getDisplayedValue()
48 | }
49 | } catch (e: Exception) {
50 | e.printStackTrace()
51 | }
52 | }
53 |
54 | fun setDisplayedHour(@IntRange(from = 0, to = 23) hour: Int) =
55 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
56 | this.hour = MathUtils.clamp(hour, 0, 23)
57 | } else {
58 | this.currentHour = MathUtils.clamp(hour, 0, 23)
59 | }
60 |
61 | fun setDisplayedMinute(@IntRange(from = 0, to = 59) minute: Int) =
62 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
63 | this.minute = minute
64 | } else {
65 | this.currentMinute = minute
66 | }
67 |
68 | fun getDisplayedHour() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
69 | hour
70 | } else {
71 | currentHour
72 | }
73 |
74 | fun getDisplayedMinute(): Int = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
75 | minute * timeInterval
76 | } else {
77 | currentMinute * timeInterval
78 | }
79 |
80 | private fun getDisplayedValue(interval: Int = timeInterval): Array {
81 | val minutesArray = ArrayList()
82 | for (i in 0 until TimePickerUtils.MINUTES_MAX step interval) {
83 | minutesArray.add(String.format(TimePickerUtils.MINUTE_FORMAT, i))
84 | }
85 |
86 | return minutesArray.toArray(arrayOf(""))
87 | }
88 | }
--------------------------------------------------------------------------------
/range_picker_dialog/src/main/java/zion830/com/range_picker_dialog/TimeRangePickerBottomSheet.kt:
--------------------------------------------------------------------------------
1 | package zion830.com.range_picker_dialog
2 |
3 | import android.os.Bundle
4 | import android.view.LayoutInflater
5 | import android.view.View
6 | import android.view.ViewGroup
7 | import androidx.fragment.app.FragmentActivity
8 | import com.google.android.material.bottomsheet.BottomSheetDialogFragment
9 | import zion830.com.range_picker_dialog.databinding.TimeRangePickerBottomSheetDialogBinding
10 |
11 | /**
12 | * TimeRangePicker based on BottomSheetDialogFragment.
13 | * If you want to use TimeRangePickerBottomSheet, you need to add Material Components for Android.
14 | * Note the following link : https://material.io/develop/android/docs/getting-started/
15 | */
16 | class TimeRangePickerBottomSheet : BottomSheetDialogFragment() {
17 | private lateinit var binding: TimeRangePickerBottomSheetDialogBinding
18 |
19 | override fun onCreateView(
20 | inflater: LayoutInflater,
21 | container: ViewGroup?,
22 | savedInstanceState: Bundle?
23 | ): View {
24 | binding = TimeRangePickerBottomSheetDialogBinding.inflate(inflater)
25 | initView()
26 | return binding.root
27 | }
28 |
29 | fun show(fragmentActivity: FragmentActivity) {
30 | show(fragmentActivity.supportFragmentManager, TAG)
31 | }
32 |
33 | private fun initView() {
34 | with(binding) {
35 | tpStart.setIs24HourView(true)
36 | tpEnd.setIs24HourView(true)
37 | }
38 | }
39 |
40 | class Builder : Buildable, TimeRangeSelectable {
41 |
42 | override fun setOnDayMode(OnDayMode: Boolean): Builder {
43 | TODO("Not yet implemented")
44 | }
45 |
46 | override fun setTimeInterval(timeInterval: Int): Builder {
47 | TODO("Not yet implemented")
48 | }
49 |
50 | override fun setOnTimeRangeSelectedListener(timeRangeSelectedListener: OnTimeRangeSelectedListener): Builder {
51 | TODO("Not yet implemented")
52 | }
53 |
54 | override fun setTimeRange(timeRange: TimeRange): Builder {
55 | TODO("Not yet implemented")
56 | }
57 |
58 | override fun build(): TimeRangePickerBottomSheet {
59 | TODO("Not yet implemented")
60 | }
61 | }
62 |
63 | companion object {
64 | private val TAG = TimeRangePickerBottomSheet::class.java.name
65 |
66 | fun getInstance(
67 | ): TimeRangePickerBottomSheet {
68 | val pickBottomSheetFragment = TimeRangePickerBottomSheet()
69 | return pickBottomSheetFragment
70 | }
71 | }
72 | }
--------------------------------------------------------------------------------
/range_picker_dialog/src/main/java/zion830/com/range_picker_dialog/TimeRangePickerDialog.kt:
--------------------------------------------------------------------------------
1 | package zion830.com.range_picker_dialog
2 |
3 | import android.os.Bundle
4 | import android.util.Log
5 | import android.view.LayoutInflater
6 | import android.view.View
7 | import android.view.ViewGroup
8 | import androidx.annotation.IntRange
9 | import androidx.fragment.app.DialogFragment
10 | import androidx.fragment.app.FragmentManager
11 | import zion830.com.range_picker_dialog.databinding.TimeRangePickerDialogBinding
12 |
13 | /**
14 | * TimeRangePicker based on DialogFragment.
15 | */
16 | class TimeRangePickerDialog : DialogFragment() {
17 | // Listener called when time is selected
18 | var onTimeRangeSelectedListener: OnTimeRangeSelectedListener? = null
19 |
20 | // OK button is disabled if end time is earlier than start time
21 | var oneDayMode = true
22 |
23 | // Minute time interval. default value is 10
24 | var interval = TimeRangePicker.defaultInterval
25 |
26 | // default range is {current hour}:00 ~ {current hour + 1}:00
27 | var timeRange = TimePickerUtils.getCurrentTimeRange()
28 |
29 | private lateinit var binding: TimeRangePickerDialogBinding
30 |
31 | override fun onCreateView(
32 | inflater: LayoutInflater,
33 | container: ViewGroup?,
34 | savedInstanceState: Bundle?
35 | ): View? {
36 | binding = TimeRangePickerDialogBinding.inflate(inflater)
37 | setUpTab()
38 | initView()
39 | setTimeRange()
40 | return binding.root
41 | }
42 |
43 | fun show(fragmentManager: FragmentManager) {
44 | super.show(fragmentManager, TAG)
45 | }
46 |
47 | private fun initView() {
48 | with(binding) {
49 | tpStart.timeInterval = interval
50 | tpEnd.timeInterval = interval
51 | btnOk.setUsable(isOkBtnUsable())
52 | tpStart.setOnTimeChangedListener { _, _, _ -> btnOk.setUsable(isOkBtnUsable()) }
53 | tpEnd.setOnTimeChangedListener { _, _, _ -> btnOk.setUsable(isOkBtnUsable()) }
54 | btnOk.setOnClickListener {
55 | onTimeRangeSelectedListener?.onTimeSelected(getSelectedTimeRange())
56 | dismiss()
57 | }
58 | btnCancel.setOnClickListener { dismiss() }
59 | }
60 | }
61 |
62 | private fun setTimeRange() {
63 | with(binding) {
64 | tpStart.setDisplayedHour(timeRange.startHour)
65 | tpStart.setDisplayedMinute(timeRange.startMinute / interval)
66 | tpEnd.setDisplayedHour(timeRange.endHour)
67 | tpEnd.setDisplayedMinute(timeRange.endMinute / interval)
68 | }
69 | }
70 |
71 | private fun getSelectedTimeRange() = with(binding) {
72 | TimeRange(
73 | tpStart.getDisplayedHour(),
74 | tpStart.getDisplayedMinute(),
75 | tpEnd.getDisplayedHour(),
76 | tpEnd.getDisplayedMinute()
77 | )
78 | }
79 |
80 | private fun setUpTab() {
81 | if (context == null) {
82 | Log.e(TAG, "context is null")
83 | return
84 | }
85 |
86 | val tabHost = binding.tabHost.apply { setup() }
87 | val startTimeTitle = context!!.getString(R.string.start_time)
88 | val endTimeTitle = context!!.getString(R.string.end_time)
89 | val startTimeTab = tabHost.newTabSpec(startTimeTitle).apply {
90 | setContent(R.id.tab_start_time)
91 | setIndicator(startTimeTitle)
92 | }
93 | val endTimeTab = tabHost.newTabSpec(endTimeTitle).apply {
94 | setContent(R.id.tab_end_time)
95 | setIndicator(endTimeTitle)
96 | }
97 | tabHost.apply {
98 | addTab(startTimeTab)
99 | addTab(endTimeTab)
100 | }
101 | }
102 |
103 | private fun isOkBtnUsable(): Boolean {
104 | if (!oneDayMode) {
105 | return true
106 | }
107 |
108 | return TimePickerUtils.isCorrectSequence(getSelectedTimeRange())
109 | }
110 |
111 | class Builder : Buildable, TimeRangeSelectable {
112 | private var listener: OnTimeRangeSelectedListener? = null
113 | private var defaultTimeInterval = TimeRangePicker.defaultInterval
114 | private var defaultTimeRange = TimePickerUtils.getCurrentTimeRange()
115 | private var defaultOnDayMode = true
116 |
117 | override fun setOnDayMode(OnDayMode: Boolean): Builder {
118 | defaultOnDayMode = OnDayMode
119 | return this
120 | }
121 |
122 | override fun setTimeInterval(timeInterval: Int): Builder {
123 | defaultTimeInterval = timeInterval
124 | return this
125 | }
126 |
127 | override fun setOnTimeRangeSelectedListener(timeRangeSelectedListener: OnTimeRangeSelectedListener): Builder {
128 | listener = timeRangeSelectedListener
129 | return this
130 | }
131 |
132 | fun setOnTimeRangeSelectedListener(onSelected: (timeRange: TimeRange) -> Unit): Builder {
133 | listener = object : OnTimeRangeSelectedListener {
134 | override fun onTimeSelected(timeRange: TimeRange) {
135 | onSelected(timeRange)
136 | }
137 | }
138 | return this
139 | }
140 |
141 | fun setTimeRange(
142 | @IntRange(from = 1, to = 23) startHour: Int,
143 | @IntRange(from = 0, to = 59) startMinute: Int,
144 | @IntRange(from = 1, to = 23) endHour: Int,
145 | @IntRange(from = 0, to = 59) endMinute: Int
146 | ): Builder {
147 | defaultTimeRange = TimeRange(startHour, startMinute, endHour, endMinute)
148 | return this
149 | }
150 |
151 | override fun setTimeRange(timeRange: TimeRange): Builder {
152 | defaultTimeRange = timeRange
153 | return this
154 | }
155 |
156 | override fun build() = TimeRangePickerDialog().apply {
157 | onTimeRangeSelectedListener = listener
158 | interval = defaultTimeInterval
159 | oneDayMode = defaultOnDayMode
160 | timeRange = defaultTimeRange
161 | }
162 | }
163 |
164 | companion object {
165 | private val TAG = TimeRangePickerDialog::class.java.name
166 | }
167 | }
--------------------------------------------------------------------------------
/range_picker_dialog/src/main/java/zion830/com/range_picker_dialog/TimeRangeSelectable.kt:
--------------------------------------------------------------------------------
1 | package zion830.com.range_picker_dialog
2 |
3 | interface TimeRangeSelectable> {
4 |
5 | fun setOnDayMode(OnDayMode: Boolean): T
6 |
7 | fun setTimeInterval(timeInterval: Int): T
8 |
9 | fun setOnTimeRangeSelectedListener(timeRangeSelectedListener: OnTimeRangeSelectedListener): T
10 |
11 | fun setTimeRange(timeRange: TimeRange): T
12 | }
13 |
--------------------------------------------------------------------------------
/range_picker_dialog/src/main/java/zion830/com/range_picker_dialog/ViewExt.kt:
--------------------------------------------------------------------------------
1 | package zion830.com.range_picker_dialog
2 |
3 | import android.graphics.Color
4 | import android.widget.Button
5 |
6 | fun Button.setUsable(
7 | usable: Boolean,
8 | usableColorResId: Int = Color.BLACK,
9 | disableColorResId: Int = context.getColor(R.color.color_4D000000)
10 | ) {
11 | isEnabled = usable
12 | setTextColor(if (usable) usableColorResId else disableColorResId)
13 | }
--------------------------------------------------------------------------------
/range_picker_dialog/src/main/res/drawable/btn_back.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/range_picker_dialog/src/main/res/layout/time_range_picker_bottom_sheet_dialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
20 |
21 |
32 |
33 |
43 |
44 |
53 |
54 |
67 |
--------------------------------------------------------------------------------
/range_picker_dialog/src/main/res/layout/time_range_picker_dialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
16 |
17 |
21 |
22 |
26 |
27 |
32 |
33 |
38 |
39 |
40 |
41 |
46 |
47 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
70 |
71 |
84 |
--------------------------------------------------------------------------------
/range_picker_dialog/src/main/res/values-ja-rJP/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | OK
4 | 開始
5 | 終わり
6 |
--------------------------------------------------------------------------------
/range_picker_dialog/src/main/res/values-ko/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 확인
4 | 시작 시간
5 | 종료 시간
6 |
--------------------------------------------------------------------------------
/range_picker_dialog/src/main/res/values-zh-rCN/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 好
4 | 启程
5 | 末尾
6 |
--------------------------------------------------------------------------------
/range_picker_dialog/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #EA1C00
4 | #000000
5 | #D81B60
6 |
7 | #4D000000
8 |
9 |
--------------------------------------------------------------------------------
/range_picker_dialog/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | OK
4 | START
5 | END
6 |
--------------------------------------------------------------------------------
/range_picker_dialog/src/test/java/zion830/com/range_picker_dialog/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package zion830.com.range_picker_dialog
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name='RangeTimePickerDialog'
2 | include ':app'
3 | include ':range_picker_dialog'
4 |
--------------------------------------------------------------------------------