Text

Answered

Why contentPackage.getPart(0) always give a new ContentPart?

 I think contentPackage.getPart(0) should give me the first content part in the package, but the reality is that the method always give a new content part, I pass 0 for the method but I can not get the first ContentPart.

This must be wrong, under this circumstances, I can't get the content part I just worked on.

How to make ContentPackage just return the first ContentPart when I call ContentPackage.getPart(0) ?


Best Answer

Hello,


Due to native wrappers if you want to compare parts, you should rather compare their identifers to check whether they are identical.

For instance, in java :


      contentPart= contentPackage.getPart(0);

      contentPart2 = contentPackage.getPart(0);


      if ( contentPart.getId().equals(contentPart2.getId()) ){
        Log.d(TAG, "Both parts are identical, id1= : " + contentPart.getId() + " , id2= " + contentPart2.getId());
      }else{
        Log.d(TAG, "Both parts are different, id1= : " + contentPart.getId() + " , id2= " + contentPart2.getId());
      }


Best regards,


Gwenaëlle


Answer

Hello,


Due to native wrappers if you want to compare parts, you should rather compare their identifers to check whether they are identical.

For instance, in java :


      contentPart= contentPackage.getPart(0);

      contentPart2 = contentPackage.getPart(0);


      if ( contentPart.getId().equals(contentPart2.getId()) ){
        Log.d(TAG, "Both parts are identical, id1= : " + contentPart.getId() + " , id2= " + contentPart2.getId());
      }else{
        Log.d(TAG, "Both parts are different, id1= : " + contentPart.getId() + " , id2= " + contentPart2.getId());
      }


Best regards,


Gwenaëlle

Thanks for your answer.

The question I want to ask is that why the contentPackage?.getPart(0) give me two different contentPart, I use the same content package and the same parameter.

Look at the code bellow,  the contentPart_0 and contentPart_1 should be one object, but I found they are different.

val contentPart_0 = contentPackage?.getPart(0)
val contentPart_1 = contentPackage?.getPart(0)
Log.d("${contentPart_0 == contentPart_1}")   //false
Log.d("$contentPart_0")  //com.myscript.iink.ContentPart@29d3af9
Log.d("$contentPart_1")  //com.myscript.iink.ContentPart@a802a3e

 For the same ContentPackage, get the ContentPart with the same index, then the same object should be returned.In some cases, these ContentParts will be used as key values in a Map. For an Editor whoes part is already the first ContentPart, set the same ContentPart will make partChanging、partChanged、ContentChanged called, and this process will take a lot of time.

I want to know why the same code return different ContentPart, and I want to know how to make the getPart(0) return the same ContentPart when I called it twice.

Hello,



I am not sure to understand your request.


Let's examine the following code:


      contentPackage = engine.createPackage(file);

    //  contentPart= contentPackage.getPart(0);

      contentPart = contentPackage.createPart("Text"); // Choose type of content (possible values are: "Text Document", "Text", "Diagram", "Math", and "Drawing")

      contentPart= contentPackage.getPart(0);



After the createPackage , if I uncomment the commented line and run the code I will get an "out of bonud" exception, as the package has not part yet.


But the 4th line will return me the Text part that was created the line above.


If this does not answer your request, please, share your code.


Regards,


Gwenaëlle