milosmns / actual-number-picker

Android: A horizontal number picker
GNU General Public License v3.0
222 stars 36 forks source link

Picker is not working for high values range #8

Closed mathias21 closed 7 years ago

mathias21 commented 7 years ago

When using number picker with high range values like years, max value is always selected.

Setup used: <me.angrybyte.numberpicker.view.ActualNumberPicker android:id="@+id/actual_picker" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_centerHorizontal="true" android:background="@color/PrimaryColor" app:bar_color="@android:color/white" app:bar_width="1dp" app:bars_count="10" app:controls_color="@android:color/white" app:draw_over_controls="true" app:draw_over_text="false" app:fast_controls_color="@android:color/darker_gray" app:highlight_color="@color/PrimaryColor" app:max_value="2016" app:min_value="2000" app:selection_color="@color/PrimaryColor" app:show_bars="true" app:show_controls="false" app:show_fast_controls="false" app:show_highlight="true" app:show_text="true" app:text_color="@android:color/white" app:text_size="16sp" app:value="2008" />

ActualNumberPicker.java, line 682: mValue = (int) Math.floor(percent * mMaxValue + mMinValue);

new value is being calculated assuming mMinValue will be zero or close to zero?

milosmns commented 7 years ago

Haha, I think I know what it is. :) Java will automatically convert to int when multiplying. Can you try that calculation with your numbers in a sample Java project? Let me know which numbers you get on your local JVM.

mathias21 commented 7 years ago

Hi @milosmns

I've tried with the numbers you can see in the code, 2000 - 2016 with 2008 as selected. The value that I get is 4016, obviously it is rounding up to 1 with the percentage. Are you sure mMinValue should be added to mMaxValue * percent? I would say it should be a subtract ^_^

Didn't review the logic too much so maybe I'm completely being a fool. If I have time next weekend I will play a bit overriding the method.

milosmns commented 7 years ago

Good catch though. I'll test it this week, and update when fixed. I you fix it before that, send a pull request and I'll check it out.

mathias21 commented 7 years ago

Thanks @milosmns!

Awesome library btw. Really like it. ^_^

milosmns commented 7 years ago

Thanks :) I'll have to check it out over the weekend, too busy this week.

milosmns commented 7 years ago

Waiting for the pull request

milosmns commented 7 years ago

Version increased to 1.3, @ 8b4394f4b61b47a88d9d1b74f0e831f779d487a1