Application Tool Kit

Answered

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,


Best Answer

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 Kurima San,


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


Best regards,


Olivier

Dear Olivier

 

Sorry, I changed the permission.

Try this link below.

...

 

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

 

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

Answer

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

 

I understand.

Thank you so much for many replies.

I'll consider to upgrade to the iink SDK.

 

Best regards,

 

Kurima