Show keyboard in Libgdx - android

I am trying to show the keyboard on a android device when a textfield is clicked in LibGdx. But as far as I can see have to detect when the textfield is clicked manually and then show the keyboard by calling Gdx.input.setOnscreenKeyboardVisible(true)?
This is the code I have so far:
textfield= new TextField("", skin);
textfield.setSize(300, 50);
textfield.setPosition((SCREEN.WIDTH/2) - textfield.getWidth()/2, 0);
//Gdx.input.setOnscreenKeyboardVisible(true);
//Gdx.input.getTextInput(this, "SOME TITLE" "TEXT");
textfield.setTextFieldListener(new TextFieldListener()
{
#Override
public void keyTyped(TextField textField, char key)
{
if (key == '\n')
{
textField.getOnscreenKeyboard().show(false);
}
}
});
Thanks for any help!

Moved from comment on original post (and edited to be more answer-like):
The keyboard is normally shown automatically when a text field gains focus or is touched. You shouldn't have to do it manually. This requires the stage to be registered as the input processor via this call:
Gdx.input.setInputProcessor(stage);

Related

Paste into a textfield under android does not work

I've got one problem with paste into a textfield in an codenameone app with android 4.1.1 and also 4.3: When I tip on the cursor the context-menu "paste" is shown - but very short and disappears then. I have no chance to paste a text in a textfield.
Under iOS I have no problem with it.
Do you have any idea?
Kind regards
Klaus
Can be reproduced with an empty App like this:
public void start()
{
if (current != null)
{
current.show();
return;
}
Form hi = new Form("Hi World");
hi.setScrollableY(true);
hi.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
TextField tmpTextField = new TextField();
Container tmpInnerContainer = new Container(new BoxLayout(BoxLayout.X_AXIS));
tmpInnerContainer.add(tmpTextField);
hi.add(tmpInnerContainer);
tmpTextField.setText("Textfield with a very long Text in it, Textfield with a very long Text in it");
hi.show();
}

How to make links among other text focusable for accessibility

I have a CheckedTextBox whose text is made up of two SpannableStrings, one of which is a URLSpan.
My question is, how do I make so that a user can move the accessibility focus through each span, eventually focusing on the URLspan itself? setMovementMethod and setLinksClickable doesn't seem to work for me.
SpannableStringBuilder builder = new SpannableStringBuilder();
SpannableString label = new SpannableString(getString(R.string.label));
label.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.text_color_primary)), 0, label.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
builder.append(label);
SpannableString link = new SpannableString(getString(R.string.link);
link.setSpan(new URLSpan(mUrl), 0, link.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
builder.append(link);
builder.append(".");
mCheckedTextBox.setText(builder);
//The following two methods do not work for what I'm trying to accomplish:
mCheckedTextBox.setMovementMethod(LinkMovementMethod.getInstance());
mCheckedTextBox.setLinksClickable(true);
I've checked on the Android Accessibility Help documentation and it seems that as long as the user hears a chime and can see the link in the local context menu, it is sufficient. However, I wanted to see if I can go that extra mile to enable the user to scroll and focus to the link portion of the text.
https://support.google.com/accessibility/android/answer/6378148?hl=en
Any help would be appreciated.
This isn't supported by the platform. Android's own documentation directs users to open the Local Context Menu to access links in TextViews:
https://support.google.com/accessibility/android/answer/6378148?hl=en
Maybe this can be the easiest solution..it worked for me.
textView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
ClassroomLog.log(TAG, "Textview Click listener ");
if (textView.getSelectionStart() == -1 && textView.getSelectionEnd() == -1){
// Perform your action here
}
}
});

Use text view of current app instead of Custom text View

I am trying to use this library for my emojicons https://github.com/ankushsachdeva/emojicon.
I have implemented it with my soft keyboard but it's not doing anything as in the code (MainActivity) of the given link, it uses EmojiconEditText instead of normal text view of any android app. Is there any way so that I can use edit text of any app instead of this custom one. My current source code for emoji is this.
popup = new EmojiconsPopup(mInputView, this);
popup.setOnEmojiconClickedListener(new EmojiconGridView.OnEmojiconClickedListener() {
#Override
public void onEmojiconClicked(Emojicon emojicon) {
if (emojicon == null){
return;
}
emojicon.getEmoji();
}
});
In this, I cannot figure out how to fetch Unicode for that particular emoji. If someone can help me how do I fetch emoji Unicode?
The code for emoji Unicode is in this https://github.com/ankushsachdeva/emojicon/tree/master/lib/src/github/ankushsachdeva/emojicon/emoji
I have got the answer after some struggle. I just need to call that string of unicodes in it with current input connection.
String text = emojicon.getEmoji();
mComposing.append(text);
commitTyped(getCurrentInputConnection());

customization of edit text and input type in android

I had customized edit text with floating label and i write a method to set input type which is working but for last edit text its showing number keyboard instead of normal keyboard take alook at my code
private void setFloatInputType(int inputType) {
if(inputType==16) {
input.setFocusable(false);
input.setOnFocusChangeListener(null);
input.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
setDatePicker();
}
});
}
else
if(inputType==0) {
input.setRawInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_NORMAL);
// input.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_NORMAL);
Log.d("INput TYp3", "" + input.getInputType());
}
else
input.setInputType(inputType);
I had debug the code it showsthat for third text field input type is set to
normal keyboard but os is popup numberic keyboard.
any suggestion will be highly appreciated.
Thanks,
Try replacing
input.setRawInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_NORMAL);
with
input.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_NORMAL);

EditText's selectAll() does not select the text, instead cursor is moved to position 0

My situation is: I have a EditText, and under it I have a button, called "select all". It's purpose is to let the user select all the text by pressing it.
When the button is clicked, I invoke selectAll() on the EditText, but instead of selecting all text, in some cases (generally, when the cursor is already positioned within the text somewhere), the cursor is moved to position 0 (start of text) and text remains unselected. Second click on the button will then select all. But of course it should happen on first click.
From this issue: Android EditText selectAll() doesn't works if one taps on the same field in android 4.x only it seems that this is a bug in android 4.0 and above. (Found no mention in Google issue tracker).
Does anyone know about a way to overcome this problem? It seems that the probelm is also in other selection methods and not only selectAll().
(p.s. This question is sort of duplicate of the issue I mentioned above. But I opened another question, because the author of that issue was satisfied and selected a partial answer (of setting android:selectAllOnFocus="true"), while in my case and scenario it does not help me and does not solve the problem.
Thanks.
Problem caused by IME. If showed cursor drag pointer then selection must be zero width.
You need cancel drag pointer. It can be doned by change text. For example replace:
Editable text = edit.getText();
if (text.length() > 0) {
text.replace(0, 1, text.subSequence(0, 1), 0, 1);
edit.selectAll();
}
We replace first symbol of text with same symbol. It cause cancel drag pointer and allow make selection without bug.
I was having a similar issue. I solved it (using Xamarin in C#, but the equivalent Java will work) with the following code:
private void InitFocus()
{
Java.Lang.Runnable rable = new Java.Lang.Runnable(()=>
{
EditText maleCount = FindViewById<EditText>(Resource.Id.txtMaleCount);
maleCount.RequestFocus();
maleCount.SelectAll();
});
new Handler().Post(rable);
}
I have 2 controls: One is a dropdown that lets you select a chicken house and then a set of buttons for each day of the week. Whenever you change the day of week or the chicken house, I want to set focus in the txtMaleCount EditText and then I want the value in that box selected (since it's a number and they're presumably going to replace it).
Clearly, the non-intuitive part was the need to Post it. Doing it directly (on the UI thread) didn't seem to have any effect.
Try this:
yourEditText.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
//((EditText)v).selectAll();
((EditText)v).setSelection(startValue, stopValue);
}
});
Or This:
yourEditText.setOnFocusChangedListener(new OnFocusChangedListener(){
#Override
public void onFocusChange(View v, boolean hasFocus){
if (hasFocus){
//((EditText)v).selectAll();
((EditText)v).setSelection(startValue, stopValue);
}
}
});
Or this:
theEditText.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
EditText editText = (EditText)view;
editText.setSelection(editText.getText().length()-1); // selects all the text
}
});
Or this:
theEditText.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
EditText editText = (EditText)view;
editText.performLongClick();
}
});
Hope this helps .. :)

Categories

Resources