Application Tool Kit

MathWidgetApi.undo() doesn't update MathWidgetApi.getResultAsText() value

On MyScript_ATK-android-2.2,

MathWidgetApi.getResultAsText() result is not changed after calling MathWidgetApi.undo().

 

On MyScript_ATK-ios-2.2, MathWidgetApi.getResultAsText() result is changed.

 

Is there any way to get updated recognition result after calling undo()?

 

The matter can be seen in MathWidgetSample with adding some changes to MainActivity.java as below.

  

package com.myscript.atk.math.sample;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.myscript.atk.math.widget.MathWidgetApi;
import com.myscript.certificate.MyCertificate;

public class MainActivity extends Activity implements MathWidgetApi.OnRecognitionListener
{
    private static final String TAG = "MainActivity";

    private MathWidgetApi mWidget;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        // Set application title
        setTitle(getResources().getString(R.string.activity_name));

        mWidget = (MathWidgetApi) findViewById(R.id.mathWidget);

        if (!mWidget.registerCertificate(MyCertificate.getBytes()))
        {
            AlertDialog.Builder dlgAlert  = new AlertDialog.Builder(this);
            dlgAlert.setMessage("Please use a valid certificate.");
            dlgAlert.setTitle("Invalid certificate");
            dlgAlert.setCancelable(false);
            dlgAlert.setPositiveButton("OK", new DialogInterface.OnClickListener()
            {
                public void onClick(DialogInterface dialog, int which)
                {
                    //dismiss the dialog
                }
            });
            dlgAlert.create().show();
            return;
        } else {
            mWidget.setBeautificationOption(MathWidgetApi.RecognitionBeautification.BeautifyDisabled);
            mWidget.setOnRecognitionListener(this);
        }

        mWidget.clearSearchPath();
        mWidget.addSearchDir("zip://" + getPackageCodePath() + "!/assets/conf/");
        mWidget.configure("math", "standard");

        // Configure clear button
        final View clearButton = findViewById(R.id.action_clear);
        if (clearButton != null)
        {
            clearButton.setOnClickListener(new View.OnClickListener()
            {
                @Override
                public void onClick(final View view)
                {
                    //mWidget.clear(true);
                    if (mWidget.canUndo()) {
                        mWidget.undo();
                    }
                }
            });
        }
    }

    @Override
    protected void onDestroy()
    {
        if (mWidget != null)
        {
            mWidget.release();
            mWidget = null;
        }

        super.onDestroy();
    }

    @Override
    public void onRecognitionBegin(MathWidgetApi mathWidgetApi) {
    }

    @Override
    public void onRecognitionEnd(MathWidgetApi mathWidgetApi) {
        String inputText = mWidget.getResultAsText();
        Log.d(TAG, "Math Widget recognition: " + inputText);
    }
} 

When you click the CLEAR button, mWidget.undo() is executed.  

Then onRecognitionEnd event is processed and

mWidget.getResultAsText() result is outputted to logcat.


Best regards,


Dear Olivier

 

I understand.

Thank you so much for many replies.

I'll consider to upgrade to the iink SDK.

 

Best regards,

 

Kurima

Dear Kurima,


this is indeed a limitation.


Unfortunately, we have no alternative to offer, and no update of the MathWidget is planned (if possible, we recommend you upgrade to the iink SDK).


Best regards,


Olivier

Dear Olivier

 

Thank you for your reply.

I feel I am approaching the goal...

 

I modified the code acording to your advice.

Then I tapped the CLEAR button, the result of mathWidgetApi.getResultAsText() was updated.

 

But, when I tap the CLEAR button, written charactors are beautified.

 

I want to disable beautification.

So I have already added the line as below.

mWidget.setBeautificationOption(MathWidgetApi.RecognitionBeautification.BeautifyDisabled);

 

How can I obtain updated mathWidgetApi.getResultAsText() result without doing beautification?

 

I tried removing "mWidget.solve();", but the result of "mathWidgetApi.getResultAsText()" was not updated again.

 

Best regards,

 

Kurima

Dear Kurima San,


thank you for the update.


First, when configuring the widget, you should ensure you set the Undo/Redo Listener:


} else {
mWidget.setBeautificationOption(MathWidgetApi.RecognitionBeautification.BeautifyDisabled);
mWidget.setOnRecognitionListener(this);
mWidget.setOnUndoRedoListener(this);
}


Also, in your  clearButton.setOnClickListener, adding mWidget.solve() after undo updates the text result. Nevertheless, please note forcing the solve will do the fontify and solve.


clearButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(final View view)
  {
//mWidget.clear(true);
if (mWidget.canUndo()) {
mWidget.undo();
mWidget.solve();
    }
  }
});




Best regards,


Olivier

Dear Olivier

 

Sorry, I changed the permission.

Try this link below.

...

 

Best regards,

 

Kurima

Dear Kurima San,


Currently, I am not able to access your project. I need your authorization :-)


Best regards,


Olivier

Dear Olivier,

 

Thank you for your reply.

 

Yes, I implemented MathWidgetApi.OnUndoRedoListener.

But the app's behavior wasn't changed.

 

I uploaded the modified project.

...


Could you run MathWidgetSample in this project?

And, when you write "123" and tap the CLEAR button three times, what are output to Logcat?

 

Best regards,

 

Kurima

Dear Kurima,


currently, did you implement the MathWidgetApi.OnUndoRedoListener (https://developer.myscript.com/old-docs/atk/2.2/android/_/maw/ref/javadoc/com/myscript/atk/math/widget/MathWidgetApi.OnUndoRedoListener.html#onUndoRedoStateChanged-com.myscript.atk.math.widget.MathWidgetApi-) in your project? 


If so, your text result should indeed be updated when calling the CLEAR function.


Best regards,


Olivier

Dear Olivier,

 

I'm talking about the code I uploaded.

In the code, "CLEAR" button, executes undo() method.

I edited to check the undo() method's behavior.

 

About the code I uploaded,

when you write "123" and tap the CLEAR button three times,

what are output to Logcat?

And what should be output?

 

As you say, in the original code of MyScript_ATK-android-2.2.zip,

"CLEAR" button.

 

 Best regards,

 

Kurima

Dear Kurima San,


Currently, our clear button is to clear teh full widget, result should then be null after clear.


Best regards,


Olviier

Dear Olivier,

 

Thank you for your reply.

 

Let me check about your "expected behavior."

What is the output to Logcat when writing "123" and tapping the CLEAR button three times?

 

I think that should be as follows.

text result is: 1
text result is: 12
text result is: 123
text result is: 12
text result is: 1
text result is: 

  But in my environment it looks like the following. 

06-15 11:59:12.177 15861-15861/com.myscript.atk.math.sample D/MainActivity: text result is: 1
06-15 11:59:12.946 15861-15861/com.myscript.atk.math.sample D/MainActivity: text result is: 12
06-15 11:59:13.834 15861-15861/com.myscript.atk.math.sample D/MainActivity: text result is: 123
06-15 11:59:16.094 15861-15861/com.myscript.atk.math.sample D/MainActivity: text result is: 123
06-15 11:59:17.947 15861-15861/com.myscript.atk.math.sample D/MainActivity: text result is: 123
06-15 11:59:19.768 15861-15861/com.myscript.atk.math.sample D/MainActivity: text result is: 123

 Best regards, 

 

Kurima

Dear Kurima San,


Currently, I left my onUndoRedoStateChanged function empty:


  @Override
  public void onUndoRedoStateChanged(MathWidgetApi mathWidgetApi) {
  }


Also, we do not recommend you get the updated result in the onUndoRedoStateChanged but in the onRecognitionEnd function:

  @Override
  public void onRecognitionEnd(MathWidgetApi mathWidgetApi) {
    String textResult = mathWidgetApi.getResultAsText();
    Log.d(TAG, "text result is: " +textResult);
  }


This way, I am getting the expected behavior.

Best regards,


Olivier



Dear Olivier,

 

Thank you for your reply.

 

To add the line "mWidget.setOnUndoRedoListener(this);", I should also implement "MathWidgetApi.OnUndoRedoListener". 

So I added "mWidget.setOnUndoRedoListener(this);" and implement "MathWidgetApi.OnUndoRedoListener". 

 

Is there anything to do in "onUndoRedoStateChanged()" method?

I just added logging code as follows.

 

  @Override
  public void onUndoRedoStateChanged(MathWidgetApi mathWidgetApi) {
    String inputText = mathWidgetApi.getResultAsText();
    Log.d(TAG, "Math Widget recognition(onUndoRedoStateChanged): " + inputText);
  }

 As the result, mathWidgetApi.getResultAsText() value is not still changed after executing undo().

 

06-06 09:24:52.827 7183-7183/com.myscript.atk.math.sample D/MainActivity: Math Widget recognition: 1
06-06 09:24:52.863 7183-7183/com.myscript.atk.math.sample D/MainActivity: Math Widget recognition(onUndoRedoStateChanged): 1
06-06 09:24:53.922 7183-7183/com.myscript.atk.math.sample D/MainActivity: Math Widget recognition: 12
06-06 09:24:55.310 7183-7183/com.myscript.atk.math.sample D/MainActivity: Math Widget recognition: 123
06-06 09:24:58.018 7183-7183/com.myscript.atk.math.sample D/MainActivity: Math Widget recognition: 123L
06-06 09:24:58.582 7183-7183/com.myscript.atk.math.sample D/MainActivity: Math Widget recognition: 1234
06-06 09:25:00.745 7183-7183/com.myscript.atk.math.sample D/MainActivity: Math Widget recognition: 12345
06-06 09:25:01.361 7183-7183/com.myscript.atk.math.sample D/MainActivity: Math Widget recognition: 12345
06-06 09:25:03.007 7183-7183/com.myscript.atk.math.sample D/MainActivity: Math Widget recognition: 12345
06-06 09:25:03.039 7183-7183/com.myscript.atk.math.sample D/MainActivity: Math Widget recognition(onUndoRedoStateChanged): 12345
06-06 09:25:07.364 7183-7183/com.myscript.atk.math.sample D/MainActivity: Math Widget recognition: 12345
06-06 09:25:09.743 7183-7183/com.myscript.atk.math.sample D/MainActivity: Math Widget recognition: 12345
06-06 09:25:11.063 7183-7183/com.myscript.atk.math.sample D/MainActivity: Math Widget recognition: 12345
06-06 09:25:11.910 7183-7183/com.myscript.atk.math.sample D/MainActivity: Math Widget recognition: 12345
06-06 09:25:12.684 7183-7183/com.myscript.atk.math.sample D/MainActivity: Math Widget recognition: 12345
06-06 09:25:13.464 7183-7183/com.myscript.atk.math.sample D/MainActivity: Math Widget recognition: 12345
06-06 09:25:13.492 7183-7183/com.myscript.atk.math.sample D/MainActivity: Math Widget recognition(onUndoRedoStateChanged): 12345

Best regards,


Kurima

Dear Kurima Yoshida San,


Thank you for your project.


The reason is that you are not setting the Undo Redo Listener. You should add it as as follows in the onCreate function:


    mWidget.addSearchDir("zip://" + getPackageCodePath() + "!/assets/conf/");
    mWidget.setOnUndoRedoListener(this);


Let us know if this helps.


Best regards,


Olivier

Dear Olivier,

 

I uploaded the full project to the following URL.


As I mentioned, I made this by modifying only some lines from MyScript_ATK-android-2.2.zip.

 

Please open "samples" project, and run MathWidgetSample.

Write some characters and then tap "CLEAR" button.

"CLEAR" button event handler executes MathWidgetApi.undo() and then

MathWidgetApi.getResultAsText() return value will be output to logcat.

 

Best regards,