xyz.kumaraswamy.tools.aix (3.7 KB)
package xyz.kumaraswamy.tools;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.ComponentContainer;
import com.google.appinventor.components.runtime.util.YailList;
import java.lang.reflect.Field;
import java.util.ArrayList;
@SuppressWarnings("unused")
public class Tools extends AndroidNonvisibleComponent {
public Tools(ComponentContainer container) {
super(container.$form());
}
@SimpleFunction(description = "Finds all the components of the Type Given")
public YailList ListAllComponents(String name) throws IllegalAccessException {
ArrayList<Object> components = new ArrayList<>();
Field[] fields = form.getClass().getDeclaredFields();
for (Field field : fields) {
field.setAccessible(true);
Object object = field.get(form);
if (object == null || !object.getClass().getSimpleName().equals(name)) {
continue;
}
components.add(object);
}
return YailList.makeList(components);
}
}
Hope this helps ![]()
