General questions

Answered

Stop at waitForIdle

 Hello, please forgive my English is not very good, so I am using Google Translate. Thank you for your powerful myscript, it is great.However, I ran into some problems when I used it. I put myscript in the service and used aidl to transmit information, but I didn't know why, so I stopped at waitForIdle.


 

//Initialization will be called once every time 
      engine = MyScriptApp.getEngine();
        Configuration conf = engine.getConfiguration();
        conf.setBoolean("text.guides.enable", true);
//        conf.setBoolean("export.jiix.text.chars", true);
        //export.jiix.strokes
//        conf.setBoolean("export.jiix.strokes", true);
        String confDir = "zip://" + getPackageCodePath() + "!/assets/conf";
        conf.setStringArray("configuration-manager.search-path", new String[]{confDir});
        String tempDir = null;
        tempDir = getExternalCacheDir().getPath() + File.separator + "tmp";
        conf.setString("content-package.temp-folder", tempDir);
        conf.setString("math.configuration.bundle", "math");
        DisplayMetrics displayMetrics = getResources().getDisplayMetrics();

        // Create a renderer with a null render target
        float dpiX = displayMetrics.xdpi;
        float dpiY = displayMetrics.ydpi;
        renderer = engine.createRenderer(dpiX, dpiY, null);

        // Create the editor
        editor = engine.createEditor(renderer);

        // The editor requires a font metrics provider and a view size *before* calling setPart()
        Map<String, Typeface> typefaceMap = new HashMap<>();
        editor.setFontMetricsProvider(new FontMetricsProvider(displayMetrics, typefaceMap));

        editor.setViewSize(640, 480);

        // Create a temporary package and part for the editor to work with
        packager = null;
        try {
            packager = engine.createPackage("text.iink");
            part = packager.createPart("Text");
            editor.setPart(part);
        } catch (IOException e) {
            Log.d(TAG, "onCreate_IOException:" + e.getMessage());
            e.printStackTrace();
        }

 

 

 private String setPenEvent(List<PointerEvent> events) {
        Log.d(TAG, "events.size():" + events.size());
        editor.pointerEvents(events.toArray(new PointerEvent[0]), false);
        editor.waitForIdle();
        ContentBlock block = editor.getRootBlock();
        return outputBlock(block, 3);
    }

 

 

    private String outputBlock(ContentBlock block, int tag) {
        Log.d(TAG, "tag():" + tag);
        String msg = "";
        try {
            msg += editor.export_(block, MimeType.JIIX);
            Log.d(TAG, "outputBlock_export1:" + tag + "/" + msg);
        } catch (IOException e) {
            Log.d(TAG, "outputBlock_IOException1:" + e.getMessage());
            e.printStackTrace();
        }
        return msg;
    }

 

 

 

//   After the conversion is complete, clean up 
 private void clearMyScript() {
        if (packager != null) {
            packager.close();
            packager = null;
        }
        if (part != null) {
            part.close();
            part = null;
        }
    }

 

 

 

 


Best Answer

Dear Zxw3935,


thank you for contacting us.


If I understand well, when adding ink, lot of time is spent in the "waitForIdle"?


Currently, when using the "batch-mode", the waitForIdle function is necessary to ensure the recogntion processed has ended. You can then call the "export_" function and get the recognition result.


Also, what has to be kept in mind is that the recognition process is very demanding, and the more strokes you add, the longer it will take. It is also very dependant of the hardware (CPU, RAM) on which the recognition process is run.


In your case, did you try providing few strokes? Is it working fine?


Best regards,


Olivier

1 Comment

Answer

Dear Zxw3935,


thank you for contacting us.


If I understand well, when adding ink, lot of time is spent in the "waitForIdle"?


Currently, when using the "batch-mode", the waitForIdle function is necessary to ensure the recogntion processed has ended. You can then call the "export_" function and get the recognition result.


Also, what has to be kept in mind is that the recognition process is very demanding, and the more strokes you add, the longer it will take. It is also very dependant of the hardware (CPU, RAM) on which the recognition process is run.


In your case, did you try providing few strokes? Is it working fine?


Best regards,


Olivier