From 13ed6684218c8d0e4da8885f68790e0d52d45eee Mon Sep 17 00:00:00 2001 From: Kumaraswamy B G <71964026+XomaDev@users.noreply.github.com> Date: Sat, 23 Oct 2021 19:37:08 +0530 Subject: [PATCH 1/8] Extract repeated lines Extracts repeated lines of code to a method. --- .../DynamicComponents/DynamicComponents.java | 95 ++++++++----------- 1 file changed, 42 insertions(+), 53 deletions(-) diff --git a/src/com/yusufcihan/DynamicComponents/DynamicComponents.java b/src/com/yusufcihan/DynamicComponents/DynamicComponents.java index 9018881..6723aab 100644 --- a/src/com/yusufcihan/DynamicComponents/DynamicComponents.java +++ b/src/com/yusufcihan/DynamicComponents/DynamicComponents.java @@ -62,7 +62,7 @@ public class DynamicComponents extends AndroidNonvisibleComponent { private final HashMap COMPONENT_IDS = new HashMap<>(); private Object lastUsedId = ""; - private ArrayList componentListeners = new ArrayList<>(); + private final ArrayList componentListeners = new ArrayList<>(); private JSONArray propertiesArray = new JSONArray(); private final Util UTIL_INSTANCE = new Util(); @@ -307,59 +307,50 @@ public YailDictionary GetComponentMeta(Component component) { } @SimpleFunction(description = "Get meta data about events for the specified component.") - public YailDictionary GetEventMeta(Component component) { - Method[] mMethods = component.getClass().getMethods(); - YailDictionary mEvents = new YailDictionary(); - - for (Method mMethod : mMethods) { - SimpleEvent mAnnotation = mMethod.getAnnotation(SimpleEvent.class); - boolean mIsDeprecated = !isEmptyOrNull(mMethod.getAnnotation(Deprecated.class)); - String mName = mMethod.getName(); - YailDictionary mEventMeta = new YailDictionary(); + public YailDictionary GetEventMeta(Component component) throws Exception { + return getMetaDictionary(component, SimpleEvent.class); + } - if (!isEmptyOrNull(mAnnotation)) { - // Return all metadata - mEventMeta.put("description", mAnnotation.description()); - mEventMeta.put("isDeprecated", mIsDeprecated); - mEventMeta.put("userVisible", mAnnotation.userVisible()); - } else { - // Return the least amount of metadata if no - // annotation is provided - mEventMeta.put("isDeprecated", mIsDeprecated); - } + @SimpleFunction(description = "Get meta data about functions for the specified component.") + public YailDictionary GetFunctionMeta(Component component) throws Exception { + return getMetaDictionary(component, SimpleFunction.class); + } - mEvents.put(mName, mEventMeta); + @SuppressWarnings({"rawtypes", "unchecked"}) + private YailDictionary getMetaDictionary(Component component, Class annotationClass) throws Exception { + YailDictionary dictionaries = new YailDictionary(); + if (component == null) { + return dictionaries; } - return mEvents; - } - - @SimpleFunction(description = "Get meta data about functions for the specified component.") - public YailDictionary GetFunctionMeta(Component component) { - Method[] mMethods = component.getClass().getMethods(); - YailDictionary mFunctions = new YailDictionary(); + for (Method method : component.getClass().getMethods()) { + YailDictionary dictionary = new YailDictionary(); + Object annotation = method.getAnnotation(annotationClass); - for (Method mMethod : mMethods) { - SimpleFunction mAnnotation = mMethod.getAnnotation(SimpleFunction.class); - boolean mIsDeprecated = !isEmptyOrNull(mMethod.getAnnotation(Deprecated.class)); - String mName = mMethod.getName(); - YailDictionary mFunctionMeta = new YailDictionary(); + final boolean isDeprecated = !isEmptyOrNull( + method.getAnnotation(Deprecated.class)); + final String methodName = method.getName(); - if (!isEmptyOrNull(mAnnotation)) { - // Return all metadata - mFunctionMeta.put("description", mAnnotation.description()); - mFunctionMeta.put("isDeprecated", mIsDeprecated); - mFunctionMeta.put("userVisible", mAnnotation.userVisible()); - } else { - // Return the least amount of metadata if no - // annotation is provided - mFunctionMeta.put("isDeprecated", mIsDeprecated); + if (annotation != null) { + dictionary.put("description", invoke(annotation, "description")); + dictionary.put("isDeprecated", isDeprecated); + dictionary.put("userVisible", invoke(annotation, "userVisible")); } - - mFunctions.put(mName, mFunctionMeta); + dictionary.put("isDeprecated", isDeprecated); + dictionaries.put(methodName, dictionary); } + return dictionaries; + } - return mFunctions; + /** + * Does a simple invoke on the object given + * @param object Invoke object + * @param methodName Name of the method + */ + + private Object invoke(Object object, String methodName) throws Exception { + return object.getClass().getMethod( + methodName).invoke(object); } @SimpleFunction(description = "Returns the ID of the specified component.") @@ -375,15 +366,14 @@ public String GetName(Component component) { @SimpleFunction(description = "Returns the position of the specified component according to its parent view. Index begins at one.") public int GetOrder(AndroidViewComponent component) { - View mComponent = (View) component.getView(); - int mIndex = 0; - ViewGroup mParent = (!isEmptyOrNull(mComponent) ? (ViewGroup) mComponent.getParent() : null); + // (non null) + View mComponent = component.getView(); + ViewGroup mParent = (ViewGroup) mComponent.getParent(); if (!isEmptyOrNull(mComponent) && !isEmptyOrNull(mParent)) { - mIndex = mParent.indexOfChild(mComponent) + 1; + return mParent.indexOfChild(mComponent) + 1; } - - return mIndex; + return 0; } @SimpleFunction(description = "Get a properties value.") @@ -563,13 +553,12 @@ private Method findMethod(String name, Object component) { @SimpleFunction(description = "Sets the order of the specified component according to its parent view. Typing zero will move the component to the end, index begins at one.") public void SetOrder(AndroidViewComponent component, int index) { - index = index - 1; View mComponent = component.getView(); ViewGroup mParent = (ViewGroup) mComponent.getParent(); mParent.removeView(mComponent); mParent.addView(mComponent, - Math.min(index, mParent.getChildCount())); + Math.min(index - 1, mParent.getChildCount())); } @SimpleFunction(description = "Set a property of the specified component, including those only available from the Designer.") From 96684740f50f4642301d627cdc27c7bcf7b4d4a1 Mon Sep 17 00:00:00 2001 From: Kumaraswamy B G <71964026+XomaDev@users.noreply.github.com> Date: Sat, 23 Oct 2021 19:40:04 +0530 Subject: [PATCH 2/8] Refactor newInstance --- .../yusufcihan/DynamicComponents/DynamicComponents.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/com/yusufcihan/DynamicComponents/DynamicComponents.java b/src/com/yusufcihan/DynamicComponents/DynamicComponents.java index 6723aab..a68e381 100644 --- a/src/com/yusufcihan/DynamicComponents/DynamicComponents.java +++ b/src/com/yusufcihan/DynamicComponents/DynamicComponents.java @@ -50,7 +50,7 @@ public class DynamicComponents extends AndroidNonvisibleComponent { private static final String TAG = "DynamicComponents"; // Base package name for components - private final String BASE = "com.google.appinventor.components.runtime."; + private static final String BASE = "com.google.appinventor.components.runtime."; // Whether component creation should happen on the UI thread private boolean postOnUiThread = false; @@ -110,13 +110,14 @@ public void newInstance(Constructor constructor, String id, AndroidViewCompon Component mComponent = null; try { - mComponent = (Component) constructor.newInstance((ComponentContainer) input); + mComponent = (Component) constructor.newInstance(input); } catch(Exception e) { throw new YailRuntimeError(e.getMessage(), TAG); } finally { - if (!isEmptyOrNull(mComponent)) { + if (mComponent != null) { String mComponentClassName = mComponent.getClass().getSimpleName(); - if (mComponentClassName == "ImageSprite" || mComponentClassName == "Sprite") { + if (mComponentClassName.equals("ImageSprite") + || mComponentClassName.equals("Sprite")) { Invoke(mComponent, "Initialize", new YailList()); } From e0d0c0d2b0ccdce0ae19453d382f3d9c55ab3e3c Mon Sep 17 00:00:00 2001 From: Kumaraswamy B G <71964026+XomaDev@users.noreply.github.com> Date: Sat, 23 Oct 2021 19:42:36 +0530 Subject: [PATCH 3/8] Add checking and exception to "Thread" property. --- .../yusufcihan/DynamicComponents/DynamicComponents.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/com/yusufcihan/DynamicComponents/DynamicComponents.java b/src/com/yusufcihan/DynamicComponents/DynamicComponents.java index a68e381..0f67a92 100644 --- a/src/com/yusufcihan/DynamicComponents/DynamicComponents.java +++ b/src/com/yusufcihan/DynamicComponents/DynamicComponents.java @@ -166,7 +166,12 @@ public boolean isEmptyOrNull(Object item) { ) @SimpleProperty(userVisible = false) public void Thread(String thread) { - postOnUiThread = (thread == "UI"); + if (thread.equalsIgnoreCase("UI")) { + postOnUiThread = true; + } else if (thread.equalsIgnoreCase("Main")) { + postOnUiThread = false; + } + throw new YailRuntimeError("Unexpected value '" + thread + "'", TAG); } @SimpleEvent(description = "Is called after a component has been created.") From 031c883cabe643b31704432336be0b2ca5e66dec Mon Sep 17 00:00:00 2001 From: Kumaraswamy B G <71964026+XomaDev@users.noreply.github.com> Date: Sat, 23 Oct 2021 19:49:43 +0530 Subject: [PATCH 4/8] Remove redundancy and Inlining --- .../DynamicComponents/DynamicComponents.java | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/com/yusufcihan/DynamicComponents/DynamicComponents.java b/src/com/yusufcihan/DynamicComponents/DynamicComponents.java index 0f67a92..110b33a 100644 --- a/src/com/yusufcihan/DynamicComponents/DynamicComponents.java +++ b/src/com/yusufcihan/DynamicComponents/DynamicComponents.java @@ -29,10 +29,7 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Set; -import java.util.UUID; +import java.util.*; @DesignerComponent( description = "Dynamic Components is an extension that creates any component in your App Inventor distribution programmatically, " + @@ -116,7 +113,7 @@ public void newInstance(Constructor constructor, String id, AndroidViewCompon } finally { if (mComponent != null) { String mComponentClassName = mComponent.getClass().getSimpleName(); - if (mComponentClassName.equals("ImageSprite") + if (mComponentClassName.equals("ImageSprite") || mComponentClassName.equals("Sprite")) { Invoke(mComponent, "Initialize", new YailList()); } @@ -486,7 +483,7 @@ public String ListDetails(Component component) { @SimpleFunction(description = "Moves the specified component to the specified view.") public void Move(AndroidViewComponent arrangement, AndroidViewComponent component) { - View mComponent = (View) component.getView(); + View mComponent = component.getView(); ViewGroup mParent = (!isEmptyOrNull(mComponent) ? (ViewGroup) mComponent.getParent() : null); mParent.removeView(mComponent); @@ -624,18 +621,20 @@ public void Schema(AndroidViewComponent in, final String template, final YailLis @Override public void onCreation(Component component, String id) { try { - if (id == mId && mJson.has("properties")) { + if (Objects.equals(id, mId) && mJson.has("properties")) { JSONObject mProperties = mJson.getJSONObject("properties"); JSONArray keys = mProperties.names(); - for (int k = 0; k < keys.length(); k++) { - Invoke( - (Component) GetComponent(mId), - keys.getString(k), - YailList.makeList(new Object[] { - mProperties.get(keys.getString(k)) - }) - ); + if (keys != null) { + for (int k = 0; k < keys.length(); k++) { + Invoke( + (Component) GetComponent(mId), + keys.getString(k), + YailList.makeList(new Object[] { + mProperties.get(keys.getString(k)) + }) + ); + } } componentListeners.remove(this); @@ -659,8 +658,7 @@ public void onCreation(Component component, String id) { @SimpleFunction(description = "Returns all IDs of components created with the Dynamic Components extension.") public YailList UsedIDs() { - Set mKeys = COMPONENTS.keySet(); - return YailList.makeList(mKeys); + return YailList.makeList(COMPONENTS.keySet()); } @SimpleProperty(description = "Returns the version of the Dynamic Components extension.") From 92250569f12ba40d9df9106dbeb4dd151772e1fd Mon Sep 17 00:00:00 2001 From: Kumaraswamy B G <71964026+XomaDev@users.noreply.github.com> Date: Sat, 23 Oct 2021 20:18:41 +0530 Subject: [PATCH 5/8] Fix bug in Invoke method Fixes the problem where if the invoke result is an empty string just containing spaces, a fully empty string would be returned. --- .../DynamicComponents/DynamicComponents.java | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/com/yusufcihan/DynamicComponents/DynamicComponents.java b/src/com/yusufcihan/DynamicComponents/DynamicComponents.java index 110b33a..51c8444 100644 --- a/src/com/yusufcihan/DynamicComponents/DynamicComponents.java +++ b/src/com/yusufcihan/DynamicComponents/DynamicComponents.java @@ -425,7 +425,6 @@ public YailDictionary GetPropertyMeta(Component component) { @SimpleFunction(description = "Invokes a method with parameters.") public Object Invoke(Component component, String name, YailList parameters) { if (!isEmptyOrNull(component)) { - Object mInvokedMethod = null; Method[] mMethods = component.getClass().getMethods(); try { @@ -449,16 +448,11 @@ public Object Invoke(Component component, String name, YailList parameters) { mParametersArrayList.add(mParameters[i]); } } - - mInvokedMethod = mMethod.invoke(component, mParametersArrayList.toArray()); + Object mInvokedMethod = mMethod.invoke(component, + mParametersArrayList.toArray()); + return mInvokedMethod == null ? "" : mInvokedMethod; } catch (Exception e) { throw new YailRuntimeError(e.getMessage(), TAG); - } finally { - if (!isEmptyOrNull(mInvokedMethod)) { - return mInvokedMethod; - } else { - return ""; - } } } else { throw new YailRuntimeError("Component cannot be null.", TAG); From c7ff1bacb775092b6794b43b7c9c198018cfab05 Mon Sep 17 00:00:00 2001 From: Kumaraswamy B G <71964026+XomaDev@users.noreply.github.com> Date: Sat, 23 Oct 2021 20:34:56 +0530 Subject: [PATCH 6/8] Improve and optimize auto-object casting --- .../DynamicComponents/DynamicComponents.java | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/src/com/yusufcihan/DynamicComponents/DynamicComponents.java b/src/com/yusufcihan/DynamicComponents/DynamicComponents.java index 51c8444..4b7ef00 100644 --- a/src/com/yusufcihan/DynamicComponents/DynamicComponents.java +++ b/src/com/yusufcihan/DynamicComponents/DynamicComponents.java @@ -432,24 +432,30 @@ public Object Invoke(Component component, String name, YailList parameters) { Method mMethod = UTIL_INSTANCE.getMethod(mMethods, name, mParameters.length); Class[] mRequestedMethodParameters = mMethod.getParameterTypes(); - ArrayList mParametersArrayList = new ArrayList(); + for (int i = 0; i < mRequestedMethodParameters.length; i++) { - if ("int".equals(mRequestedMethodParameters[i].getName())) { - mParametersArrayList.add(Integer.parseInt(mParameters[i].toString())); - } else if ("float".equals(mRequestedMethodParameters[i].getName())) { - mParametersArrayList.add(Float.parseFloat(mParameters[i].toString())); - } else if ("double".equals(mRequestedMethodParameters[i].getName())) { - mParametersArrayList.add(Double.parseDouble(mParameters[i].toString())); - } else if ("java.lang.String".equals(mRequestedMethodParameters[i].getName())) { - mParametersArrayList.add(mParameters[i].toString()); - } else if ("boolean".equals(mRequestedMethodParameters[i].getName())) { - mParametersArrayList.add(Boolean.parseBoolean(mParameters[i].toString())); - } else { - mParametersArrayList.add(mParameters[i]); + final Object object = mParameters[i]; + final String value = String.valueOf(object); + + switch (mRequestedMethodParameters[i].getName()) { + case "int": + mParameters[i] = Integer.parseInt(value); + break; + case "float": + mParameters[i] = Float.parseFloat(value); + break; + case "double": + mParameters[i] = Double.parseDouble(value); + break; + case "java.lang.String": + mParameters[i] = value; + break; + case "boolean": + mParameters[i] = Boolean.parseBoolean(value); + break; } } - Object mInvokedMethod = mMethod.invoke(component, - mParametersArrayList.toArray()); + Object mInvokedMethod = mMethod.invoke(component, mParameters); return mInvokedMethod == null ? "" : mInvokedMethod; } catch (Exception e) { throw new YailRuntimeError(e.getMessage(), TAG); From 9a83539e6fba8e271c7be3fffdbc37fd3275698c Mon Sep 17 00:00:00 2001 From: Kumaraswamy B G <71964026+XomaDev@users.noreply.github.com> Date: Sat, 23 Oct 2021 20:48:08 +0530 Subject: [PATCH 7/8] Add dispatch event method A method that dispatches event on the main thread --- .../DynamicComponents/DynamicComponents.java | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/com/yusufcihan/DynamicComponents/DynamicComponents.java b/src/com/yusufcihan/DynamicComponents/DynamicComponents.java index 4b7ef00..d7b4808 100644 --- a/src/com/yusufcihan/DynamicComponents/DynamicComponents.java +++ b/src/com/yusufcihan/DynamicComponents/DynamicComponents.java @@ -29,7 +29,10 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Method; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Objects; +import java.util.UUID; @DesignerComponent( description = "Dynamic Components is an extension that creates any component in your App Inventor distribution programmatically, " + @@ -148,6 +151,15 @@ public void notifyListenersOfCreation(Component component, String id) { listener.onCreation(component, id); } } + + private void dispatchEvent(final String name, final Object... parameters) { + new Handler(Looper.getMainLooper()).post(new Runnable() { + @Override + public void run() { + EventDispatcher.dispatchEvent(DynamicComponents.this, name, parameters); + } + }); + } } public boolean isEmptyOrNull(Object item) { @@ -167,28 +179,19 @@ public void Thread(String thread) { postOnUiThread = true; } else if (thread.equalsIgnoreCase("Main")) { postOnUiThread = false; + } else { + throw new YailRuntimeError("Unexpected value '" + thread + "'", TAG); } - throw new YailRuntimeError("Unexpected value '" + thread + "'", TAG); } @SimpleEvent(description = "Is called after a component has been created.") public void ComponentBuilt(final Component component, final String id, final String type) { - new Handler(Looper.getMainLooper()).post(new Runnable() { - @Override - public void run() { - EventDispatcher.dispatchEvent(DynamicComponents.this, "ComponentBuilt", component, id, type); - } - }); + UTIL_INSTANCE.dispatchEvent("ComponentBuilt", component, id, type); } @SimpleEvent(description = "Is called after a schema has/mostly finished component creation.") public void SchemaCreated(final String name, final YailList parameters) { - new Handler(Looper.getMainLooper()).post(new Runnable() { - @Override - public void run() { - EventDispatcher.dispatchEvent(DynamicComponents.this, "SchemaCreated", name, parameters); - } - }); + UTIL_INSTANCE.dispatchEvent("SchemaCreated", name, parameters); } @SimpleFunction(description = "Assign a new ID to a previously created dynamic component.") From 0ecd76add867dd85b6772519b5f444ccc4e10386 Mon Sep 17 00:00:00 2001 From: Kumaraswamy B G <71964026+XomaDev@users.noreply.github.com> Date: Sat, 23 Oct 2021 21:01:54 +0530 Subject: [PATCH 8/8] Minor changes and improvements `isEmptyOrNull` method was always inverted, it's now renamed and changed accordingly. With some minor changes and improvements. --- .../DynamicComponents/DynamicComponents.java | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/com/yusufcihan/DynamicComponents/DynamicComponents.java b/src/com/yusufcihan/DynamicComponents/DynamicComponents.java index d7b4808..f2826a3 100644 --- a/src/com/yusufcihan/DynamicComponents/DynamicComponents.java +++ b/src/com/yusufcihan/DynamicComponents/DynamicComponents.java @@ -162,10 +162,10 @@ public void run() { } } - public boolean isEmptyOrNull(Object item) { - return item instanceof String - ? ((String) item).replace(" ", "").isEmpty() - : item == null; + public boolean isNotEmptyOrNull(Object item) { + return item instanceof String ? ! + ((String) item).replace(" ", "").isEmpty() + : item != null; } @DesignerProperty( @@ -256,7 +256,7 @@ public void run() { @SimpleFunction(description = "Generates a random ID to create a component with.") public String GenerateID() { - String id = ""; + String id; do { id = UUID.randomUUID().toString(); @@ -274,11 +274,11 @@ public Object GetComponent(String id) { public YailDictionary GetComponentMeta(Component component) { Class mClass = component.getClass(); DesignerComponent mDesignerAnnotation = mClass.getAnnotation(DesignerComponent.class); - boolean mHasDesigner = !isEmptyOrNull(mDesignerAnnotation); - boolean mHasObject = false; + boolean mHasDesigner = isNotEmptyOrNull(mDesignerAnnotation); + boolean mHasObject; SimpleObject mObjectAnnotation = mClass.getAnnotation(SimpleObject.class); YailDictionary mMeta = new YailDictionary(); - mHasObject = !isEmptyOrNull(mObjectAnnotation); + mHasObject = isNotEmptyOrNull(mObjectAnnotation); if (mHasDesigner && mHasObject) { // Return all metadata @@ -333,7 +333,7 @@ private YailDictionary getMetaDictionary(Component component, Class annotationCl YailDictionary dictionary = new YailDictionary(); Object annotation = method.getAnnotation(annotationClass); - final boolean isDeprecated = !isEmptyOrNull( + final boolean isDeprecated = isNotEmptyOrNull( method.getAnnotation(Deprecated.class)); final String methodName = method.getName(); @@ -376,7 +376,7 @@ public int GetOrder(AndroidViewComponent component) { View mComponent = component.getView(); ViewGroup mParent = (ViewGroup) mComponent.getParent(); - if (!isEmptyOrNull(mComponent) && !isEmptyOrNull(mParent)) { + if (isNotEmptyOrNull(mComponent) && isNotEmptyOrNull(mParent)) { return mParent.indexOfChild(mComponent) + 1; } return 0; @@ -394,13 +394,13 @@ public YailDictionary GetPropertyMeta(Component component) { for (Method mMethod : mMethods) { DesignerProperty mDesignerAnnotation = mMethod.getAnnotation(DesignerProperty.class); - boolean mHasDesigner = !isEmptyOrNull(mDesignerAnnotation); - boolean mHasProperty = false; + boolean mHasDesigner = isNotEmptyOrNull(mDesignerAnnotation); + boolean mHasProperty; SimpleProperty mPropertyAnnotation = mMethod.getAnnotation(SimpleProperty.class); String mName = mMethod.getName(); YailDictionary mPropertyMeta = new YailDictionary(); Object mValue = Invoke(component, mName, new YailList()); - mHasProperty = !isEmptyOrNull(mPropertyAnnotation); + mHasProperty = isNotEmptyOrNull(mPropertyAnnotation); if (mHasProperty) { mPropertyMeta.put("description", mPropertyAnnotation.description()); @@ -414,7 +414,7 @@ public YailDictionary GetPropertyMeta(Component component) { mPropertyMeta.put("designer", mDesignerMeta); } - mPropertyMeta.put("isDeprecated", (!isEmptyOrNull(mMethod.getAnnotation(Deprecated.class)))); + mPropertyMeta.put("isDeprecated", (isNotEmptyOrNull(mMethod.getAnnotation(Deprecated.class)))); mPropertyMeta.put("isDesignerProperty", mHasDesigner); mPropertyMeta.put("userVisible", mPropertyAnnotation.userVisible()); mPropertyMeta.put("value", mValue); @@ -427,7 +427,7 @@ public YailDictionary GetPropertyMeta(Component component) { @SimpleFunction(description = "Invokes a method with parameters.") public Object Invoke(Component component, String name, YailList parameters) { - if (!isEmptyOrNull(component)) { + if (isNotEmptyOrNull(component)) { Method[] mMethods = component.getClass().getMethods(); try { @@ -487,9 +487,9 @@ public String ListDetails(Component component) { @SimpleFunction(description = "Moves the specified component to the specified view.") public void Move(AndroidViewComponent arrangement, AndroidViewComponent component) { View mComponent = component.getView(); - ViewGroup mParent = (!isEmptyOrNull(mComponent) ? (ViewGroup) mComponent.getParent() : null); - mParent.removeView(mComponent); + ((ViewGroup) mComponent.getParent()). + removeView(mComponent); ViewGroup mArrangement = (ViewGroup) arrangement.getView(); ViewGroup mTarget = (ViewGroup) mArrangement.getChildAt(0); @@ -507,7 +507,7 @@ public String RandomUUID() { public void Remove(String id) { Object component = COMPONENTS.get(id); - if (isEmptyOrNull(component)) { + if (component == null) { return; } try { @@ -591,12 +591,12 @@ public void Schema(AndroidViewComponent in, final String template, final YailLis JSONObject mScheme = new JSONObject(template); String newTemplate = template; - if (!isEmptyOrNull(template) && mScheme.has("components")) { + if (isNotEmptyOrNull(template) && mScheme.has("components")) { propertiesArray = new JSONArray(); JSONArray mKeys = (mScheme.has("keys") ? mScheme.getJSONArray("keys") : null); - if (!isEmptyOrNull(mKeys) && mKeys.length() == parameters.length() - 1) { + if (isNotEmptyOrNull(mKeys) && mKeys.length() == parameters.length() - 1) { for (int i = 0; i < mKeys.length(); i++) { String keyPercent = "%" + mKeys.getString(i); String keyBracket = "{" + mKeys.getString(i) + "}";