Skip to content

A beautiful little Android view to pick hours, minutes and seconds.

License

Notifications You must be signed in to change notification settings

DeweyReed/HmsPickerView

Repository files navigation

JitPack Android Arsenal

HmsPickerView

A beautiful little Android view to pick hours, minutes and seconds.

Port

Land

Installation

Step 1. Add it in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Step 2. Add the dependency

dependencies {
    implementation "com.github.DeweyReed:HmsPickerView:${version}"
}

Usage

In the XML:

<xyz.aprildown.hmspickerview.HmsPickerView
    android:id="@+id/hmsPickerView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
<attr name="hpv_time_text_size" format="dimension" />
<!--default: 40sp port, 32sp land-->
<attr name="hpv_digit_text_size" format="dimension" />
<!--default: 40sp port, 24sp land-->

In the code:

fun getHours(): Int
fun setHours(hours: Int)

fun getMinutes(): Int
fun setMinutes(minutes: Int)

fun getSeconds(): Int
fun setSeconds(seconds: Int)

fun getTimeInMillis(): Long
fun setTimeInMillis(time: Long)

fun setTimeTextSize(@Px textSize: Int)
fun setDigitTextSize(@Px textSize: Int)

fun setListener(l: HmsPickerView.Listener)
interface Listener {
    /**
     * Indicates [HmsPickerView] now has an valid input(anything except 00h 00m 00s).
     * This methods can be used to allow user to go forward (such as enabling "next" button).
     */
    fun onHmsPickerViewHasValidInput(hmsPickerView: HmsPickerView)

    /**
     * Indicates [HmsPickerView]'s input becomes 00h 00m 00s.
     * This methods can be used to prevent user from going forward(such as disabling "next" button).
     */
    fun onHmsPickerViewHasNoInput(hmsPickerView: HmsPickerView)
}

Use this view in a dialog

  1. Create a XML file like this one.
  2. Wrap it into an AlertDialog like this one.

🦄 Please star this repo if you like it 🦄

License

LICENSE