Paste into a textfield under android does not work - android

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();
}

Related

Combine TapGestureRecognizer and PanGestureRecognizer in Xamarin Android

I have the following structure.
Frame frame = new Frame();
Grid grid = new Grid();
ContentView contentView = new ContentView();
contentView.GestureRecognizers.Add(CreateSwipeEffect());
grid.Children.Add(contentView, 0, 0);
frame.GestureRecognizers.Add(CreateFrameTapEffect());
frame.Content = grid;
Frame has available two effects: first we can swipe(PanGesture) and second we can tap(TapGesture). On iOS platform this solution perfectly works. However on Android platform only swipe effect is firing. How can I solve this to have both effects available for Android platform?
I use your code in iOS and Android, yes, it works fine on iOS, and have issue on Android.
But if you add tapGenture and panGesture after you add label or frame control, it can works fine. Maybe some mechanisms of Android are a little different from iOS. Please take a look the following code, I test it on Android and iOS, it all works fine.
public Page17()
{
InitializeComponent();
var panGesture = new PanGestureRecognizer();
panGesture.PanUpdated += PanGesture_PanUpdated;
var tapGenture = new TapGestureRecognizer();
tapGenture.NumberOfTapsRequired = 1;
tapGenture.Tapped += TapGenture_Tapped;
Frame frame = new Frame();
frame.BackgroundColor = Color.AliceBlue;
Grid grid = new Grid();
Label label= new Label();
label.Text = "this is test!";
label.BackgroundColor = Color.Red;
grid.Children.Add(label,0,0);
frame.Content = grid;
stacklayout1.Children.Add(frame);
frame.GestureRecognizers.Add(tapGenture);
label.GestureRecognizers.Add(panGesture);
}
private void TapGenture_Tapped(object sender, EventArgs e)
{
Console.WriteLine("the tapgesture fire!");
}
private void PanGesture_PanUpdated(object sender, PanUpdatedEventArgs e)
{
Console.WriteLine("the pangesture fire");
}
You are dispatching Tap Event to Frame(parent) and Swip Event to ContentView(childview).
According to Input events overview:
Remember that hardware key events are always delivered to the View
currently in focus. They are dispatched starting from the top of the
View hierarchy, and then down, until they reach the appropriate
destination.
So based on your codes when you are tapping on the Frame, android system thought you want to fire the tap event on ContentView(which doesn't exist) because current focus is the contentview not the frame. So if you have specific needs to do that, you need to try other ways to implement it. If not, please register the tap event on ContentView.

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());

Xamarin.Forms: wrong button text alignment after click (Android)

I have a problem with Xamarin.Forms (version 1.2.2) on Android (Nexus 5).
The alignment of Button.Text is often not centered after performing a click.
In a short project, I figured out, that updating the UI causes the problem.
public class App
{
public static Page GetMainPage()
{
var label = new Label {
Text = "label",
};
var buttonBad = new Button {
Text = "buttonBad",
Command = new Command(() => label.Text += "1"),
};
var buttonGood = new Button {
Text = "buttonGood",
};
return new ContentPage {
Content = new StackLayout {
Children = {
buttonBad,
buttonGood,
label,
}
}
};
}
}
A click on "buttonBad" (updating the label.Text) causes the text-alignment of this button to not be centered anymore. A click on "buttonGood" does not cause the problem.
Is there a good workaround to solve this problem?
This workaround seems to be too complicated:
http://forums.xamarin.com/discussion/20608/fix-for-button-layout-bug-on-android
edit:
A programatically edit of the UI also cases the bug. Changing the label.Text in an async method after a short waiting leads the "buttonGood" to align its text wrong after a click.
edit2:
I created an example / test project on GitHub:
https://github.com/perpetual-mobile/ButtonTextAlignmentBug.git
The alignment is correct, when the StackLayout is replaced by an AbsolutLayout, but i need the StackLayout to work well.
Ok, after hours of dealing with this silly bug, I resolved it by implementing a custom renderer and overriding ChildDrawableStateChanged:
public override void ChildDrawableStateChanged(Android.Views.View child)
{
base.ChildDrawableStateChanged(child);
Control.Text = Control.Text;
}

Show keyboard in Libgdx

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);

Make a custom keyboard in Android having the same behavior as the soft keyboard

So, today I decided to try out Android, so please understand that I am a beginner in it.
What I want to achieve right now is to have a EditText, and a set of buttons to be used to enter data into the EditText.
What I've done currently is stick a set of button widgets in the XML layout, and I use this code to make the buttons insert stuff into the EditText:
final EditText inputline = (EditText) findViewById(R.id.textentry);
final Button my_button = (Button) findViewById(R.id.my_btn);
my_button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
inputline.append("a");
}
});
This kind of works, but I need help with a few issues:
it always appends the character at the end of the string, not at the current cursor position
similarly, when I call inputline.selectAll() and press my button, it inserts the text at the end of the string again; whereas I want it to delete the text first (as it's selected) and then insert the character
it seems tedious to write all that code for each of the buttons I have. Is there a better way to do this altogether?
Thanks for your help!
I have now pretty much solved by replacing inputline.append("a"); etc. with my custom function, lineInsert(), which you can see below.
public void lineInsert(CharSequence text) {
final EditText inputline = (EditText) findViewById(R.id.textentry);
int start = inputline.getSelectionStart();
int end = inputline.getSelectionEnd();
inputline.getText().replace(Math.min(start,end), Math.max(start,end), text, 0, text.length());
inputline.setSelection(inputline.getSelectionEnd());
}
This has the same behavior as the soft keyboard.

Categories

Resources