Questions about a few annotations.

70 views
Skip to first unread message

Moliata

unread,
Jun 22, 2017, 12:09:35 PM6/22/17
to App Inventor Open Source Development
Hello, everyone.
I am new to this group & today I would like to ask a few questions about 2 annotations.

1. @UsesAssets
I would like to know usage of this annotation, also how to use it in extensions.
2. @SimplePropertyCopier
I would like to know usage of this annotation, also how to use it in extensions.

Thank you for help,
Regards, Moliata.

Moliata

unread,
Jun 22, 2017, 12:42:34 PM6/22/17
to App Inventor Open Source Development

Moliata

unread,
Jun 26, 2017, 2:26:36 PM6/26/17
to App Inventor Open Source Development
Hello? Is these forums dead? As I see no one is hoping to help me.

Evan Patton

unread,
Jun 27, 2017, 6:08:06 PM6/27/17
to App Inventor Open Source Development
Hi Moliata,

1. I don't have any examples on hand of how to use the UsesAssets annotation in an extension, but my understanding is that the assets must be placed within the component source hierarchy alongside your extension source code. You then annotate with @UsesAssets with a comma-separated list of the file names relative to your class name. The external component generator should then pick them up when you package your extension. 
2. The SimplePropertyCopier annotation is only used for when custom behavior is needed in the companion to handle copying properties from an old component to a new component with the same name. For example, it's used in AndroidViewComponent to handle copying the width/height of a component (width and height have values with special semantics that must be handled separately). If SimplePropertyCopier doesn't exist, the normal getter/setter are used. All you need to do to use it is annotate a method called "Copy" + propertyName that takes the old component as a parameter and then update the property for the current component instance. See AndroidViewComponent.java for an example. I would strongly consider that you confirm whether or not any special behavior is required as this is very rarely used in the App Inventor code base and only for special circumstances.

Evan
Message has been deleted
Message has been deleted

Moliata

unread,
Jun 29, 2017, 1:09:30 PM6/29/17
to App Inventor Open Source Development
Hello, Evan!
Thank you for your response. If I am saying true, after using @UsesAssets(fileNames = "..."), those assets will be packed with an extension and afterwards I upload it into App Inventor. Those files will appear in Assets tab? Also, if I want to copy width of WebViewer, what do I need after getView()?
public int width;

@SimplePropertyCopier
public void CopyWidth(WebViewer webViewer) {
  width 
= webViewer.getView().???
}
Kindly thanks for your help,
Regards, Moliata.

Evan Patton

unread,
Jun 29, 2017, 10:33:36 PM6/29/17
to App Inventor Open Source Development
The assets do not appear under media. These will be packaged as assets into the final APK when it is built. Because assets are part of the APK, they can only be modified at compile time, so for example they won't be available in the companion app if you do live development (this needs to be addressed in a future extensions update).

As for the copy annotation, what exactly are you trying to accomplish? You shouldn't actually need to override CopyWidth in your example unless you want behavior other than what is accomplished in the AndroidViewComponent.java example I linked previously. Unfortunately, I can't really tell you what to put there because it would depend on what you are trying to accomplish.

Evan

Moliata

unread,
Jul 1, 2017, 4:43:54 PM7/1/17
to App Inventor Open Source Development
Hey!
1. Question about asset stuff... So after importing assets with @UsesAssets(fileNames = "test.png"), how should I use "fetch" those files?
2. Now about copier... For an example, I would like to copy WebViewer's width & assign it to my variable using @SimplePropertyCopier. How can I do that?

Evan Patton

unread,
Jul 11, 2017, 2:59:34 PM7/11/17
to App Inventor Open Source Development
1) You can use the openMedia method of MediaUtil with the MediaSource specified as ASSET. Alternatively you can use the Android API AssetManager, however this will only work in compiled apps, not the companion, since assets are compile-time included in the APK file.
2) The copier method will only be called in the companion when updating the view hierarchy, and it will only be called with the previous instance of the same component. Unless you are subclassing WebViewer or providing a custom copy method on that class specifically, the SimplePropertyCopier is not what you want. You should just be able to get the width/height by calling webViewer1.Width/Height after the first layout occurs.

Evan

Moliata

unread,
Jul 14, 2017, 3:02:52 AM7/14/17
to App Inventor Open Source Development
Ok thank you for the help.
P.S: If I am right, @SimplePropertyCopier annotation is not usable by extensions.

Evan Patton

unread,
Jul 14, 2017, 9:10:52 AM7/14/17
to App Inventor Open Source Development
Hi Moliata,

It is usable by extensions, as it is a runtime annotation that is used by the code in runtime.scm to perform copies of properties during a refresh of the companion. However, it's use case is extremely narrow so my expectation is that it's not capable of doing what you want.

Evan

Moliata

unread,
Jul 14, 2017, 2:58:40 PM7/14/17
to App Inventor Open Source Development
Thanks!
I meant that it is not made for use in extensions. Thank you for the help.
Reply all
Reply to author
Forward
0 new messages