Text

What is the correct way to set the configuration again after making resource file dynamically.

What is the correct way to set the editor configuration , content package , content part  again after generating resource file dynamically.

Ex-  Set the configuration , content package ,content part. Now generate a custom resource file dynamically using "RecognitionAssetsBuilder" .

now what are the things are required to update like editor configuration, content package and content part , so that it will read our custom resource file.

Thanks & Regards


Dear Pankaj,

Currently, in order to set a configuration, this can be done either:
-at the engine level: https://developer.myscript.com/docs/interactive-ink/1.3/android/fundamentals/interactive-ink-runtime/#configuring-the-recognition
-or the editor level: https://developer.myscript.com/docs/interactive-ink/1.3/android/fundamentals/editing/#editor-level-configuration

In your case, when setting a new resource, I would recommend you set it at the editor level.

All you should normally need to do is set a part to the editor, the new resource should then be taken into account:
Configuration editorConfiguration = editor.getConfiguration();
editorConfiguration.setString("text.configuration.name", "myConf");
editor.setPart(contentPart);


You normally do not need to create a new engine or new contentPackage but can use the existing ones.

Let me know if this doesn't work.

Best regards,

Olivier

Hello Olivier,

Its not working . 

Code:

first i am  setting the  configuration as below; 

private void setTextConversionConfiguration{

Engine mEngine = AppController.getmEngine();
        Configuration conf = mEngine.getConfiguration();
        conf.setBoolean("text.guides.enable", false);
        conf.setString("text.configuration.bundle", "en_US");
        String confDir = "zip://" + mActivity.getPackageCodePath() 
         +"!/assets/conf";
        conf.setStringArray("configuration-manager.search-path", new String[]{confDir});
        String tempDir = mActivity.getFilesDir().getPath() + File.separator + "tmp";
        conf.setString("content-package.temp-folder", tempDir);
 DisplayMetrics displayMetrics = mActivity.getResources().getDisplayMetrics();
        Renderer renderer = mEngine.createRenderer(displayMetrics.xdpi, displayMetrics.ydpi, null);
        Map<String, Typeface> typefaceMap = new HashMap<>();
     Editor   mEditor = mEngine.createEditor(renderer);
        mEditor.setFontMetricsProvider(new FontMetricsProvider(displayMetrics, typefaceMap));

  String packageName = "myPackage.iink";
        File file = new File(Environment.getExternalStorageDirectory(), packageName);
        try { 
            mContentPackage = mEngine.createPackage(file);
            mContentPart = mContentPackage.createPart("Text"); 
            mEditor.setPart(mContentPart);
        } catch (Exception e) {
         e.toString();
        }

}

 now i generate resource file dynamically .

now if  i run the below code and the set the all configuration same by calling above method " setTextConversionConfiguration() " then the app get crash.

if (mContentPart != null) {
mContentPart.close();
mContentPart = null;
}
if (mContentPackage != null) {
mContentPackage.close();
mContentPackage = null;
}
mEditor.setPart(null);

Thanks & Regards

Pankaj Tyagi

Dear Pankaj,


Currently, I do not see anything wrong in the setTextConversionConfiguration function. Do you have an error message or the logs? This willl help.


Regardibg disposing the objects, you are not doing it the proper order. You should rather proceed as follows:

mEditor.waitForIdle();
mEditor.setPart(null);
mEditor.setFontMetricsProvider(null);
mEditor.close();
mEditor = null;

if (mContentPart != null) {
mContentPart.close();
mContentPart = null;
}
if (mContentPackage != null) {
mContentPackage.close();
mContentPackage = null;
}

Best regards,

Olivier

Hello Olivier ,

I don't have any logs .

But my app is still crashing after updating .

Regards,

Pankaj Tyagi

Dear Pankaj Tyagi,



We recommand you setting the configuration on the editor.

If we assume that your package is alreay opened and contains a single part and that you want to update dynamically your text configuration on your editor, the sequence would be:



   if (contentPart != null)
    {
      contentPart.close();
      contentPart = null;
    }
    contentPart = contentPackage.getPart(0);

    if (contentPart != null)
    {
      contentPart.close();
      contentPart = null;
    }

    editor.setPart(null);
    editor.clear();

    Configuration conf = editor.getConfiguration();
    conf.setString("text.configuration.name", "customResource");

    contentPart = contentPackage.createPart("Text");

    editor.setPart(contentPart);




Regards,


Gwenaëlle

Hello Gwenaëlle,

I applied changes suggested by you but now I am getting " Configuration resource not found " error in " onError() " Callback method of "IEditorListener", and app is still crashing.

Regards

Pankaj Tyagi

Dear Pankaj,


thank you for the update.


This error means the iink is not able to find your new configuration in your conf file.


Can you please provide your configuration file and the way you call your configuration?


Thank you,


Best regards,


Olivier

Login or Signup to post a comment
  • Support
  • Forums
  • Text
  • What is the correct way to set the configuration again after making resource file dynamically.