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,


is it possible to get your full project, so that we can replay your use-case? Indeed, we are not able to figure out where this issue may come from, as we are not able to reproduce.


Best regards,


Olivier

Dear Olivier,

 

Thank you for your reply. 

 

I replaced mWidget.getResultAsText(); by mathWidgetApi.getResultAsText(); in my onRecognitionEnd function.

But it did't take an effect.  The results are as follows. 

Are there any other points to modify?

 

06-04 10:15:14.536 4747-4747/com.myscript.atk.math.sample D/MainActivity: Math Widget recognition: 1
06-04 10:15:15.121 4747-4747/com.myscript.atk.math.sample D/MainActivity: Math Widget recognition: 12
06-04 10:15:15.709 4747-4747/com.myscript.atk.math.sample D/MainActivity: Math Widget recognition: 123
06-04 10:15:16.730 4747-4747/com.myscript.atk.math.sample D/MainActivity: Math Widget recognition: 123L
06-04 10:15:17.037 4747-4747/com.myscript.atk.math.sample D/MainActivity: Math Widget recognition: 1234

-- tap the button from here --

06-04 10:15:20.111 4747-4747/com.myscript.atk.math.sample D/MainActivity: Math Widget recognition: 1234
06-04 10:15:45.723 4747-4747/com.myscript.atk.math.sample D/MainActivity: Math Widget recognition: 1234
06-04 10:15:48.847 4747-4747/com.myscript.atk.math.sample D/MainActivity: Math Widget recognition: 1234
06-04 10:15:51.856 4747-4747/com.myscript.atk.math.sample D/MainActivity: Math Widget recognition: 1234
06-04 10:15:53.840 4747-4747/com.myscript.atk.math.sample D/MainActivity: Math Widget recognition: 1234

 Best regards,

Dear Kurima San,


after reviewing again your code, can you please replace mWidget.getResultAsText(); by mathWidgetApi.getResultAsText(); in your onRecognitionEnd function?


Let us know if this works.


Best regards,


Olivier

Thank you for your reply and sorry for my late reply.

 

I think I'm using MathWidget as same as the code you suggested.

But my app outputs as below when I tap the "clear(=undo)" button.   

06-01 15:36:49.246 3211-3211/com.myscript.atk.math.sample D/MainActivity: Math Widget recognition: 1
06-01 15:36:51.197 3211-3211/com.myscript.atk.math.sample D/MainActivity: Math Widget recognition: 12
06-01 15:36:52.434 3211-3211/com.myscript.atk.math.sample D/MainActivity: Math Widget recognition: 123
06-01 15:36:55.088 3211-3211/com.myscript.atk.math.sample D/MainActivity: Math Widget recognition: 123↼
06-01 15:36:55.514 3211-3211/com.myscript.atk.math.sample D/MainActivity: Math Widget recognition: 1234

-- tap the button from here --

06-01 15:37:00.211 3211-3211/com.myscript.atk.math.sample D/MainActivity: Math Widget recognition: 1234
06-01 15:37:03.914 3211-3211/com.myscript.atk.math.sample D/MainActivity: Math Widget recognition: 1234
06-01 15:37:05.757 3211-3211/com.myscript.atk.math.sample D/MainActivity: Math Widget recognition: 1234
06-01 15:37:07.713 3211-3211/com.myscript.atk.math.sample D/MainActivity: Math Widget recognition: 1234
06-01 15:37:09.666 3211-3211/com.myscript.atk.math.sample D/MainActivity: Math Widget recognition: 1234

 

Could I have whole project files you tested or could you run MainActivity.java I showed you?

I made it only modifying some lines of MainActivity.java in MathWidgetSample MyScript_ATK-android-2.2.zip.


Best regards,

Dear Kurima Yoshida San,


Thank you  for contacting us and the interest you show to our MathWidget.


Currently, I tried to reproduce your use-case on my side using the latest 2.2 release of the ATK, and it is working fine.


Here is the way I implemented the undo/redo:


public boolean onOptionsItemSelected(MenuItem item)
{
int itemId = item.getItemId();
if (itemId == ID_MENU_UNDO) {
    Log.d(TAG, "Call undo");
mWidget.undo();
  } else if (itemId == ID_MENU_REDO) {
    Log.d(TAG, "Call redo");
mWidget.redo();
  }
return super.onOptionsItemSelected(item);
}


And the result in logcat:


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


I then get the following logcat:

05-18 16:46:13.648 1588-1588/com.myscript.atk.math.sample D/MainActivity: text result is: 1
05-18 16:46:15.558 1588-1588/com.myscript.atk.math.sample D/MainActivity: text result is: 1+3
05-18 16:46:16.421 1588-1588/com.myscript.atk.math.sample D/MainActivity: text result is: 1+3=4
05-18 16:46:16.549 1588-1588/com.myscript.atk.math.sample D/MainActivity: text result is: 1+3=4
05-18 16:46:18.307 1588-1588/com.myscript.atk.math.sample D/MainActivity: text result is: 1+3=4
05-18 16:46:19.141 1588-1588/com.myscript.atk.math.sample D/MainActivity: text result is: [[1+3]/L]
05-18 16:46:19.479 1588-1588/com.myscript.atk.math.sample D/MainActivity: text result is: [[1+3]/4]
05-18 16:46:20.303 1588-1588/com.myscript.atk.math.sample D/MainActivity: text result is: [[1+3]/4]=1
05-18 16:46:20.427 1588-1588/com.myscript.atk.math.sample D/MainActivity: text result is: [[1+3]/4]=1
05-18 16:46:22.681 1588-1588/com.myscript.atk.math.sample D/MainActivity: Call undo
05-18 16:46:22.732 1588-1588/com.myscript.atk.math.sample D/MainActivity: text result is: 1+3
05-18 16:46:23.569 1588-1588/com.myscript.atk.math.sample D/MainActivity: text result is: 1+3=4
05-18 16:46:23.604 1588-1588/com.myscript.atk.math.sample D/MainActivity: text result is: 1+3=4
05-18 16:46:26.716 1588-1588/com.myscript.atk.math.sample D/MainActivity: Call undo
05-18 16:46:26.753 1588-1588/com.myscript.atk.math.sample D/MainActivity: text result is:
05-18 16:46:27.508 1588-1588/com.myscript.atk.math.sample D/MainActivity: text result is:
05-18 16:46:31.095 1588-1588/com.myscript.atk.math.sample D/MainActivity: Call redo
05-18 16:46:31.132 1588-1588/com.myscript.atk.math.sample D/MainActivity: text result is: 1+3
05-18 16:46:31.975 1588-1588/com.myscript.atk.math.sample D/MainActivity: text result is: 1+3=4
05-18 16:46:33.112 1588-1588/com.myscript.atk.math.sample D/MainActivity: Call redo
05-18 16:46:33.170 1588-1588/com.myscript.atk.math.sample D/MainActivity: text result is: [[1+3]/4]
05-18 16:46:34.022 1588-1588/com.myscript.atk.math.sample D/MainActivity: text result is: [[1+3]/4]=1
05-18 16:46:35.410 1588-1588/com.myscript.atk.math.sample D/MainActivity: text result is: [[1+3]/4]=1
05-18 16:46:35.931 1588-1588/com.myscript.atk.math.sample D/MainActivity: text result is: [[1+3]/4]+
05-18 16:46:37.299 1588-1588/com.myscript.atk.math.sample D/MainActivity: text result is: [[1+3]/4]+2
05-18 16:46:38.218 1588-1588/com.myscript.atk.math.sample D/MainActivity: text result is: [[1+3]/4]+2=3
05-18 16:46:38.395 1588-1588/com.myscript.atk.math.sample D/MainActivity: text result is: [[1+3]/4]+2=3
05-18 16:46:43.805 1588-1588/com.myscript.atk.math.sample D/MainActivity: Call undo
05-18 16:46:43.861 1588-1588/com.myscript.atk.math.sample D/MainActivity: text result is: [[1+3]/4]
05-18 16:46:44.797 1588-1588/com.myscript.atk.math.sample D/MainActivity: text result is: [[1+3]/4]=1
05-18 16:46:48.760 1588-1588/com.myscript.atk.math.sample D/MainActivity: Call redo


As you can see, when calling undo/redo, the text result is updated accordingly.


Best regards,


Olivier