GithubHelp home page GithubHelp logo

droppers / timerangepicker Goto Github PK

View Code? Open in Web Editor NEW
300.0 300.0 38.0 5.85 MB

A customizable, easy-to-use, and functional circular time range picker library for Android. Use this library to mimic Apple's iOS or Samsung's bedtime picker.

License: MIT License

Kotlin 100.00%
android java kotlin picker range slider time-picker time-range

timerangepicker's Introduction

Hello there ๐Ÿ‘‹

I am a 24-year-old software developer located in Vorden, The Netherlands. In my spare time I like to contribute to open-source projects and stay up to date with the latest technologies.

Contact me

timerangepicker's People

Contributors

adrijanrogan avatar droppers avatar pelmenstar1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

timerangepicker's Issues

Exception is thrown with empty message when trp_hourFormat attribute has invalid value.

If invalid value is passed to enum property, we will get a build error:
AAPT: error: '420' is incompatible with attribute trp_hourFormat (attr) enum [FORMAT_SYSTEM=0, FORMAT_12=1, FORMAT_24=2]

Code:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <nl.joery.timerangepicker.TimeRangePicker
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:trp_hourFormat="420" />

</LinearLayout>

But, nevertheless, if we pass a reference to integer with invalid value, we won't get any build error and code compiles successfully:
ints.xml

<resources>
    <integer name="some_invalid_value">3</integer>
</resources>

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <nl.joery.timerangepicker.TimeRangePicker
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:trp_hourFormat="@integer/some_invalid_value" />

</LinearLayout>

Full code

In runtime, we will get exception with no message:

     Caused by: java.lang.IllegalArgumentException
        at nl.joery.timerangepicker.TimeRangePicker$HourFormat$Companion.fromId(TimeRangePicker.kt:1160)
        at nl.joery.timerangepicker.TimeRangePicker.initAttributes(TimeRangePicker.kt:147)
        at nl.joery.timerangepicker.TimeRangePicker.<init>(TimeRangePicker.kt:114)
        at nl.joery.timerangepicker.TimeRangePicker.<init>(TimeRangePicker.kt:39)
        at nl.joery.timerangepicker.TimeRangePicker.<init>(TimeRangePicker.kt)

Library tries to handle such cases but unsuccessfully:

hourFormat = HourFormat.fromId(
attr.getInt(
R.styleable.TimeRangePicker_trp_hourFormat,
_hourFormat.id
)
) ?: _hourFormat // Sets public property to determine 24 / 12 format automatically

fun fromId(id: Int): HourFormat? {
for (f in values()) {
if (f.id == id) return f
}
throw IllegalArgumentException()
}

Method fromId never returns null, but throws exception with empty message on invalid value, but initAttributes expects that fromId returns null and assignes default value (HourFormat.FORMAT_12) if returned enum value is null.

So, what's expected behavior? To leave default value, or to throw exception. If the last one, it's better to throw exception with some message like 'Invalid attribute value(trp_hourFormat=value)'

Create view from code

Is it possible to create everything from code without touching xml?It is possible to create everything from code without touching xml

a massy bug !

Greetings @Droppers ! I admire your project. I am attempting to use it but when I try to change the endTime programmatically, it doesn't work. Additionally, the editor crashes when I try to change it from XML.

How to setting StartTime, EndTime?

i'll try set StartTime And EndTime.

binding.timerangepicker.startTime = TimeRangePicker.Time(6, 0)
binding.timerangepicker.endTime =TimeRangePicker.Time(8, 0)

but only StartTime set yet

i want all set at the same time on code

someone can you help me?

init StartTime and EndTime by calendar.

Great library.
How can I pass a calendar to set StartTime and EndTime for Picker?
**picker.setStartTime(calendar);**

I tried to use setStartTimeMinutes but seem it is not correct.

picker.setStartTimeMinutes((int) TimeUnit.MILLISECONDS.toMinutes(Calendar.getInstance().getTimeInMillis()));

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.