In Tablet, Kiosk devices (android).
My code:
<TextInput
keyboardType="numeric"/>
And keyboard show number within operator. How to avoid those operator?
In android, the keyboard is its own application. It decides what's shown in a given mode, and you have no control over it. The most you can do is give it a hint in the type, but the exact layout is the keyboard's final decision.
Also remember that on Android, the user can choose any keyboard program he wants. Not all keyboards will show the same set of keys for the same type- its whatever the keyboard app itself decides is appropriate.
If you really, really want to control it you can write your own keyboard, make it the default input method, and lock down the tablet since its a kiosk. But I really wouldn't suggest it.
As Gabe mentioned the Keyboard is not under the control of the app so you cant change the way it looks.
Assuming that you are using a TextInput you can use the onChangeText function to decide whether to update the state or not based on what the user inputs. The below code only takes in the numbers from a textinput.
handleTextChange = (text) => {
var cleanedString = '';
for (let i = 0; i < text.length; i++)
{
if (!isNaN(text[i])) {
cleanedString = cleanedString + text[i];
}
}
this.setState({ number : cleanedString });
};
Related
I have an hybrid app developed with ionic 1.x. When the app loads I am forcing the webview to take the focus from native side with the hope that after some initialization request a survey dialog appear and take the focus it self(When dialog appear I am forcing it to take focus). I am trying to make it work with talkback
The problem is that when you load the app from scratch the dialog is not focused so it is not read, after navigate through the app and come back to the original page then in works as expected, looks like as the user is in fact inside the page things works ok.
Is there any workaround or strategy to solve this particular situation?
Thanks in advance
I don't know if it helps you,
but we use it to focus on specific elements in the web view.
it works in android and ios,
but in android, before every element it read webview.
(if you found a solution for it please let me know)
function putFocus(elementForFocus) {
var $element = $(elementForFocus);
var focusInterval = 10; // ms, time between function calls
var focusTotalRepetitions = 10; // number of repetitions
$element.attr('tabindex', '0');
$element.blur();
var focusRepetitions = 0;
var interval = window.setTimeout(function () {
$element.focus();
}, focusInterval);
};
I am trying to use Odoo with the application Barcode & QR code Keyboard, from Nikola Antonov (just an example, I do not know if there are better options), in order to read barcodes for the pickings.
The first problem I had to face was I had to show the keyboard in this picking view
So I needed to create an input field in order to click in it and show the Android Keyboard, or in this case the Nikola Antonov keyboard. Then, I had to assign the function handler to this input text field:
this.$('#input_text_barcodes').on('keyup', self.getParent().barcode_scanner.handler);
The function is only working as expected if I use the normal Android Keyboard (AOSP) and only with numbers. The letters of the Android Keyboard or whatever character of the Nikola Antonov Keyboard are not working (only the backspace)
this.handler = function(e){
self.$('#aux_label').text('>> CODE: ' + e.which)
self.$('#aux_label').text('>> KEY CODE: ' + e.keyCode)
self.$('#aux_label').text('>> KEY: ' + e.key)
// [...]
I tried switching the languages of the keyboard as well, but with the same result
Should I change the keyup event?
Is there other way to catch the characters?
Finally I have asked to the developer of the application directly and he solved the problem quite fast. He made it work with numeric keys, that is enough for what I wanted to achieve.
I am having issues with a PhoneGap application that I'm working in. My app has lots of forms, since the objective of the app is mostly to provide a nice user interface to a database. However, whenever the user tries to edit an input field that is close to the bottom, the Android keyboard will pop up and cover the field, so that the user cannot see what he/she is writing.
Do you know if there is a workaround for this? Has anyone come across this issue on their apps?
What you can do in this case (what I did when I had this problem...): add on-focus event on fields, and scroll up document. So you will see input field on the top of page :)
I agree with Paulius, for Android I found this to be the cleanest solution.
I know this is an old question but I will share my solution for other people if any body is still facing this issue.
// fix keyboard hiding focused input texts
// using native keyboard plugin and move.min.js
// https://github.com/vitohe/ionic-plugins-keyboard/tree/f94842fec1bacf72107083d2e44735e417e8439d
// http://visionmedia.github.io/move.js/
// not tested on iOS so implementation is for Android only
if ($cordovaDevice.getPlatform() === "Android") {
// device is running Android
// attach showkeyboard event listener
// which is triggered when the native keyboard is opened
window.addEventListener('native.showkeyboard', keyboardShowHandler);
// native.showkeyboard callback
// e contains keyboard height
function keyboardShowHandler(e) {
// get viewport height
var viewportHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
// get the maximum allowed height without the need to scroll the page up/down
var scrollLimit = viewportHeight - (document.activeElement.offsetHeight + document.activeElement.offsetTop);
// if the keyboard height is bigger than the maximum allowed height
if (e.keyboardHeight > scrollLimit) {
// calculate the Y distance
var scrollYDistance = document.activeElement.offsetHeight + (e.keyboardHeight - scrollLimit);
// animate using move.min.js (CSS3 animations)
move(document.body).to(0, -scrollYDistance).duration('.2s').ease('in-out').end();
}
}
window.addEventListener('native.hidekeyboard', keyboardHideHandler);
// native.hidekeyboard callback
function keyboardHideHandler() {
// remove focus from activeElement
// which is naturally an input since the nativekeyboard is hiding
document.activeElement.blur();
// animate using move.min.js (CSS3 animations)
move(document.body).to(0, 0).duration('.2s').ease('in-out').end();
}
}
The end result is unbelievably smooth.
I am trying to capture input events on a text input. Using jQuery I am handling the keyup event to populate a list of matches (an auto-complete list). This works fine on the stock browsers and others such as Maxthon, but in Firefox mobile nothing happens while the keyboard is shown--I have to either press enter or hide the keyboard for it work work.
I am using jQuery 1.7.2, Android 2.3 and the latest version of Firefox (10 I believe). I have also tried other events such as input and keydown without any luck.
Is it possible to handle key/input events in Firefox mobile while the keyboard is shown?
The problem is that when word suggestions are turned on in the Android keyboard, Firefox is not triggering the key events during the time the keyboard is "guessing" words, although the values are sent to the text field. I would say this is a bug in Firefox, but I guess they have chosen to do it this way because the result of the key pressed is not consistent with the value the field gets if the keyboard suggests something different than the exact thing you write.
I solved this by using a sniffer that checks on the value if it has changed or not.
var $searchField;
var _keypressWatchingTimer = 0;
var _previousTerm = '';
function keypressStartWatching() {
keypressStopWatching();
_keypressWatchingTimer = setInterval(executeAutocomplete, 100);
}
function keypressStopWatching() {
if (_keypressWatchingTimer != 0) {
clearInterval(_keypressWatchingTimer);
_keypressWatchingTimer = 0;
}
}
function executeAutocomplete() {
var searchTerm = $searchField.val() || '';
if (_previousTerm == searchTerm)
return false;
searchApi.autocomplete(searchTerm);
_previousTerm = searchTerm;
}
function init() {
$searchField = $('#searchField')
.focus(keypressStartWatching)
.blur(keypressStopWatching)
.keyup(executeAutocomplete);
}
init();
I want to check if the native/hardware keyboard is used, and also if possible I want to disable the third party keyboards.
My goal is simple I use just the native android soft keyboard for entering values in my edit boxes and no other keyboard should be able to this
Thanks
EDIT
I know it is not good idea to do what I am trying to do, I know that the basic idea of android is to have intents and activities and services who know to handle some types of intent according intent-filter. But this in every rule there is an exception, especially when we talk about security.
I want to disable all third party keyboards, and if this is not possible to do it with some API or something... is there any workaround to this problem ?
EDIT
String s=Settings.Secure.getString(getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
This returns the currently enabled input method (keyboard),but I need something like the 'system keyboard' and I do not see any flag like that :-(.
List<InputMethodInfo> list = m.getInputMethodList();
One possible solution is to take the list[0] as the keyboard I am searching, but I do not want to relay on the order (except if the order is garanteed that always the keyboard with index 0 is the one that comes install with the phone)
this is the value of list
[InputMethodInfo{com.htc.android.htcime/.HTCIMEService, settings: com.htc.android.htcime.HTCIMESettings}, InputMethodInfo{com.volosyukivan/.WiFiInputMethod, settings: null}]
I want to check if the native/hardware keyboard is used
You can use the Configuration object to see if the device's hardware keyboard is hidden. Usually, that would imply they are using that keyboard, since most devices do not show an IME when the hardware keyboard is available. However, some devices might support both simultaneously, and I don't know how external keyboards (USB, Bluetooth) interact with this value.
also if possible I want to disable the third party keyboards.
Fortunately, this is not possible.
is there any workaround to this problem ?
There is no problem cited to this point in the question.
yes the will not be happy, but they will be much more unhappy if you let their secure data to be corrupt
If users choose to use an alternative keyboard, that is their choice as users. The user is perfectly capable of switching keyboards if they wish. The user is perfectly capable of making these decisions. It is entirely possible that an alternative keyboard is more secure than a built-in one, due to devices loaded with spyware from the factor, such as CarrierIQ. Hence, your assumption that you are improving security by attacking the user's choice of keyboard is fundamentally flawed.
Of course, you do not have to support using any keyboard at all, forcing users to use some sort of on-screen input option that you devise yourself. This is not completely secure either (e.g., tapjacking attacks), and it may cause usability problems for people who chose certain third-party keyboards for specific reasons (e.g., blind users, users with motor control issues).
I am not aware that there is a way to definitively determine what the firmware's own IME is, particularly since this varies by device and firmware.
Something like this should let you check if the user is using a non-standard keyboard. However, instead of preventing them using this keyboard, how about a helpful warning message about the possible security risks?
public boolean isUsingCustomInputMethod() {
InputMethodManager imm = (InputMethodManager) mCtx.getSystemService(
Context.INPUT_METHOD_SERVICE);
List<InputMethodInfo> mInputMethodProperties = imm.getEnabledInputMethodList();
final int N = mInputMethodProperties.size();
for (int i = 0; i < N; i++) {
InputMethodInfo imi = mInputMethodProperties.get(i);
if (imi.getId().equals(
Settings.Secure.getString(mCtx.getContentResolver(),
Settings.Secure.DEFAULT_INPUT_METHOD))) {
if ((imi.getServiceInfo().applicationInfo.flags &
ApplicationInfo.FLAG_SYSTEM) == 0) {
return true;
}
}
}
return false;
}
I find precise solution
InputMethodManager m = (InputMethodManager) ctx.getSystemService("input_method");
List<InputMethodInfo> a = m.getInputMethodList();
for (InputMethodInfo inputMethodInfo : a) {
if (inputMethodInfo.getIsDefaultResourceId() == 0) {
//it is not default
return false;
}
}
//it is default
return true;