Skip to content

Commit

Permalink
🎉 Added: Move, SetOrder and GetOrder blocks! #20
Browse files Browse the repository at this point in the history
  • Loading branch information
ysfchn committed Aug 16, 2020
1 parent c794fb6 commit aa755c9
Showing 1 changed file with 93 additions and 0 deletions.
93 changes: 93 additions & 0 deletions src/com/yusufcihan/DynamicComponents/DynamicComponents.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import org.json.JSONException;
import org.json.JSONObject;

import android.view.View;
import android.view.ViewGroup;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.ArrayList;
Expand Down Expand Up @@ -292,6 +295,96 @@ public void ChangeId(String id, String newId) {
}


/*
-----------------------
Move
Moves the component to an another arrangement.
-- Parameters --
AndroidViewComponent arrangement : The arrangement that component placed in.
Component component : The component that will be reordered.
int index : The index that specifies the position.
-----------------------
*/
@SimpleFunction(description = "Moves the component to an another arrangement.")
public void Move(AndroidViewComponent arrangement, AndroidViewComponent component) {
View comp = (View)component.getView();
ViewGroup source = (ViewGroup)comp.getParent();
source.removeView(comp);

ViewGroup vg2 = (ViewGroup)arrangement.getView();
ViewGroup target = (ViewGroup)vg2.getChildAt(0);

target.addView(comp);
}


/*
-----------------------
GetOrder
Gets the position of the component according to its parent arrangement.
Index starts from 1.
-- Parameters --
AndroidViewComponent component : The visible component.
-----------------------
*/
@SimpleFunction(description = "Gets the position of the component according to its parent arrangement.\n"
+ "Index starts from 1.")
public int GetOrder(AndroidViewComponent component){
if ((component.getView() != null) && ((View)component.getView().getParent() != null))
{
View v = (View)component.getView();
ViewGroup vg = (ViewGroup)v.getParent();
int index = vg.indexOfChild(v);
return index + 1;
}
else
{
return 0;
}
}


/*
-----------------------
SetOrder
Sets the position of the component according to its parent arrangement.
Index starts from 1.
Typing 0 (zero) will move the component to the end.
-- Parameters --
AndroidViewComponent component : The component that will be reordered.
int index : The index that specifies the position.
-----------------------
*/
@SimpleFunction(description = "Sets the position of the component according to its parent arrangement.\n"
+ "Index starts from 1.\n"
+ "Typing 0 (zero) will move the component to the end.")
public void SetOrder(AndroidViewComponent component, int index) {
View comp = (View)component.getView();
ViewGroup source = (ViewGroup)comp.getParent();
source.removeView(comp);

// ViewGroup target = (ViewGroup)source.getChildAt(0);
index = index - 1;
int childCount = source.getChildCount();

if (index > childCount)
index = childCount;
source.addView(comp, index);
}


/*
-----------------------
Remove
Expand Down

0 comments on commit aa755c9

Please sign in to comment.