Application Tool Kit

[Android ATK] Unable to "scroll to cursor" after adding "\n" via setText

Hello,

I've got a simple SignleLineWidget and a button. The button add a "\n" at the end of the text. I would like to recreate the behaviour of returnGesture. 

So when I add the LR character, I would like to put the cursor AFTER the LR, but it is located at the beginning of the string.

Then, i would like to "autoScrollWhenNearlyFull" after this action. Is there any way to do that ?


Thank you in advance !

Romain


Dear Romain,

thank you for contacting us.

I've got a simple SignleLineWidget and a button. The button add a "\n" at the end of the text. I would like to recreate the behaviour of returnGesture. 

So when I add the LR character, I would like to put the cursor AFTER the LR, but it is located at the beginning of the string.

=>If I understand well, when you have the "-" recognized (left to right gesture), you would like to replace it by "\n"? Am I right?
In that case, this can be done as follows:

public void onTextChanged(SingleLineWidgetApi w, String text, boolean intermediate) {
...

if(text.contains("-"))
{
//text=text+"\\n";
text=text.replace("-","\\n");
} ...

This way, the left to right gesture (which is normally recognized as "-") will be replace by "\n". I confirm it will not be added at the end but in replacement.
Let me know if my understanding is correct.

Then, i would like to "autoScrollWhenNearlyFull" after this action. Is there any way to do that ?

=>I am not sure to understand exactly: when the \n has been added, you want autoscroll to work only when reaching the right of the writing area? If so, maybe you can try to play with the autoscroll timers, using the "setAutoScrollDelays" functions

void setAutoScrollDelays(int delayWhenNearlyEmpty,
                         int delayWhenNearlyFull)

If this doesn't correspond to your needs, can you please provide with more specification, so that we can better understand your use-case.

Best regards,

Olivier

Hello,

To be precise :

LineReturn Gesture is TOP-BOTTOM-LEFT (  _|  ) . When I do it I got the wanted behaviour (which is the default behaviour) : "\n" is added at the end of the string, then it scrolls in order to make some free space for writing. 

image

But, I want to do the same thing with a button (my customers are not prepared to use _| gesture). So I added a button (the blue circle one on the image).

 

lineReturnButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        String text = myScriptWidget.getText();
        myScriptWidget.setText(text + "\n");
        myScriptWidget.setCursorIndex(text.length());
        myScriptWidget.scrollToCursor();
    }
});

 But the cursor is not set to the end. When I log it, it is set to the length of the substring after the last "\n". Like "Test me\nfoo", the cursor is set to 3 (length of foo). So I get the following :

image


This is not the behaviour expected. I want it to scrool to the end.


Furthermore, there is nothing to programmatically make it scroll further than the last character (in order to make some space for writing), exactly what is done after handwriting on the widget ? Because it seems that autoScroll is not triggered after setText.


Regards,

Romain

Dear Romain,

can you please try the following. This way, the cursor will be set to the end.

Let us know if this helps.

Best regards,

Olivier

int index = mWidget.getCursorIndex();
boolean replaced = mWidget.replaceCharacters(index, index, "\\n");
if (replaced) {
mWidget.setCursorIndex(index + 2);
isCorrectionMode++;
}

Hello,

your fix is not really what I expected. Your arrow is understandable by the customer. "\n" is only understandable by a programer. But with this fix, the cursor is set to the end. 

Furthermore, the autoscroll is not called after mWidget.setText("foo"). Is there a way to call it?

Regards


Dear Romain,


my fault, you should indeed add "\n" instead of "\\n":

mWidget.replaceCharacters(index, index, "\n");


Regarding autosroll, when adding text, by default it should be enabled (unless you disabled it). Depending on the size of the ink, either typeset will be done first then autoscroll later or the opposite will be done, i.e. autoscroll then typeset.


Best regards,


Olivier

Hello,

I verified all those statements :

  • autoscroll is enabled
  • autotypeset is enabled
  • autoscroll delay is 1000
  • the widget is enabled

The only action done is :

button.setOnClickListener(new OnClickListener(){
    void onClick()
    {
        mWidget.setText(mWidget.getText() + "something");
    }
});

After the setText, there is no autoscroll. Your code snippet did not helped. Is there any configuration to do ? (I copied the Android Dev Guide minimal example in order to begin).


Regards

Romain

Dear Romain,

we were indeed able to reproduce the behavior.

Unfortunately, at present we do not have any way to go around this.

Best regards,

Olivier

Hello,

Thank you for your support, I will be waiting for you next version so !

Romain

Login or Signup to post a comment