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

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

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,


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,

 

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,

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,

 

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 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.

 

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, our clear button is to clear teh full widget, result should then be null after clear.


Best regards,


Olviier

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,


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,

 

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

Login or Signup to post a comment