TimePicker accepts values higher than 24h - android

I'm using TimePicker and on newer devices, there is an option to set values from the keyboard:
The problem is that, input accepts values way above 24h. User can put there any 2 digits number (e.g. 82) and still can click "OK".
Because of obvious reasons, it is not acceptable behavior. Is there any way to restrict what values are accepted or at least block the possibility to use the keyboard to input hours/minutes?
Ps. I'm using Afollestad's material dialogs, but as far as I know, he is using default TimePicker below, the only differences are styles and few extensions. I tried without this library, just by using TimePickerDialog and it's exactly the same. If a user sets input higher than 23/59 it's just set to 23/59 accordingly.
Edit: My bad, now I can see that, dialog from this library is not validating the input. With the default implementation, click validates input.

The problem was with the library I've used. I made a PR that fixes this issue. Hopefully, it will be merged in the close future.

Related

How to specify which keys to show on soft keyboard? (Android)

One, probably a stupid question.
Is it possible to choose which keys to appear on Android keyboard (other than just setting input type)?
For example, can I specify I only want to show keys:
0,1,2,3,4,5,6,7,8,9,A,B?
Or should I write completely custom keyboard for it?
I don't care about layout and styling.
I need it only for one activity.
Is it possible to choose which keys to appear on Android keyboard (other than just setting input type)?
Write your own input method editor and hope that the user elects to enable and use it.
Otherwise, no.
can I specify I only want to show keys: 0,1,2,3,4,5,6,7,8,9,A,B?
No. Bear in mind that there are hundreds of input method editors, not just one. Unless you are deploying only to a single device model, there will be many editors that your users will encounter.

input date picker on android shows wrong picker on WebView

I've got an HTML5 INPUT (type="datetime-local") in a WebView, but when I select it, it shows a date-time field that looks like this:
But the same identical element in Chrome looks like this:
This is under Android 7.1, with Chrome v55 installed, so Chrome is being used the WebView component. So, both should show the same thing, right?
I need the latter picker to show up in the WebView, it is much more user friendly (to scroll you can just flick up and down rather than having to repeatedly press the plus or minute buttons.
How do I accomplish this?
Update: I have tried creating this natively using a DatePickerDialog and it does the same thing! I'm targeting minSdkVersion=22, targetSdkVersion=25 (although I have also tried minSdkVersion=25). How do I force Android to display the correct picker for my app?
Update 2: I downloaded a sample app using the native DatePickerDialog and it displays the dialog ok. I don't like the idea of having to try to find the difference between the two projects which is causing the behavioral difference as it could be anything and take an excessive amount of time to find.
Update 3: Using the answer provided by Oleg, I was able to reproduce the second picker using android:Theme.Holo.Light.DarkActionBar. But if I use android:Theme.DeviceDefault.Light I can get a calendar view for input type="date". But the corresponding time picker in the Default theme (the round clock) does not show up for input type="time" and ``input type="datetime-local"` doesn't use the calendar view either.
As discussed in comments, you are likely missing the proper theme. Given that you have access to working app, please apply the same theme, it should solve it

Numeric keyboard as default, but allow text

I'm currently developing an application targeted at android and desktop devices using apache cordova and HTML5.
In order to get the numeric keyboard to pop up I've used input type="number", which works fine.
However, the input field should also accept strings. The current functionality of type=number is that the ui seems to allow for strings to be entered, but the value property of the element is not changed if the input is invalid (e.g not numberic).
Is there a way of getting the numberic keyboard on mobile devices, while still being able to enter text?
My inital tries consisted of capturing the keydown event and manually setting the this.value property. I've tried this using jQuerys .val() and of course the more 'native' approach element.val += char. None of which work. UI is updated, but the change is not reflected in the model.
EDIT
For the next guy trying to achieve this.
1) The HTML solution.
As #LuudJacobs mentions in the comments below; There's currently no way to decide which keyboard is shown except for defining the type-attribute. Though some devices have a button to go back to alphabet keyboard, its not the case for every device. And can not be used reliably.
2) Writing a phonegap/cordova plugin.
It is possible to write a plugin to show and hide the keyboard at will. But, as far as I could find, there is currently no way of programmatically telling it to default to the symbols keyboard. Thus the functionality achieved is similar to using type=number and type=text in the HTML. Another problem with this approach is the diversity of keyboard for android devices, where even users themselves can install their custom keyboard. The functionality of the keyboard can are therefore unknown. What works on one device, may not work on the next.
3) JS/HTML/Canvas solution
Finally... A feasible solution. I suggest taking a look at this walkthrough as it shows an easy way to creating the keyboard using just html and js. Another option would be to use a canvas, and draw the keyboard yourself, but I would imagine that this is more error prone and harder to do.
As explained in the HTML5 spec you can not have anything but valid floats in a input type="number". So You can not. On a sidenote: how would users enter text when they'd only have a numeric keyboard?

Custom Application specific Keyboard in Android

I want to create a custom keyboard for my application. ie. consider a simple text input and when I click on that, I want a custom keyboard to appear. For ex : a dialler like keyboard, having keys 0-9 and then some custom buttons for my application. Is it possible to do that in android?
Yes, this is possible. There are two ways to approach this:
Create your own input method (keyboard) - here's an example on google of how this can be done: http://developer.android.com/resources/samples/SoftKeyboard/index.html - you'll then need to set this keyboard as an IME in your app.
Create your own view with a bunch of buttons to handle your own stuff. This won't be a "keyboard" in a true android way, but it would do everything you need for your app. I have seen apps that contain their own "keyboards" designed in this way.
In addition, keep in mind that even the basic android keyboard has several "versions" available: alpha, keypad, symbols, etc.
Which way you prefer to go depends on your specific needs, your development abilities and time constraints.
Create your own view with a bunch of buttons to handle your own stuff. This won't be a "keyboard" in a true android way, but it would do everything you need for your app. I have seen apps that contain their own "keyboards" designed in this way.
In addition, keep in mind that even the basic android keyboard has several "versions" available: alpha, keypad, symbols, etc.
Which way you prefer to go depends on your specific needs, your development abilities and time constraints.

Create a custom InputType

Is it possible to create a custom InputType for the Android keyboard to use?
I want to make it so the keyboard shows the number pad first and then after a user types in a float or an integer followed by a space I want it to switch to the default alpha keyboard.
I tried using a TextWatcher instance, but this seems buggy on anything above 2.0 (sometimes it would lose a character, this doesn't happen on 1.6 or below).
Any ideas?
Thanks for reading.
Yes, it is possible.
I haven't done it myself, but the evidence is in apps that serve as input types. Look up apps such as Swype and 8pen; they serve as different input types, with Swype building on a keyboard similar to the default and 8pen providing a different input UI altogether.

Categories

Resources