Optimize the view remover procedure to fix the lag in builds with Ingame Custom Controls

This commit is contained in:
artdeell 2021-03-08 19:28:18 +03:00
parent a9322ffe0e
commit 0b41acac2b

View File

@ -44,13 +44,14 @@ public class ControlLayout extends FrameLayout
if (mModifiable) { if (mModifiable) {
hideAllHandleViews(); hideAllHandleViews();
} }
//if (getChildAt(0) instanceof MinecraftGLView) { /*if (getChildAt(0) instanceof MinecraftGLView) {
// View viewGL = getChildAt(0); View viewGL = getChildAt(0);
// View viewTouchpad = getChildAt(1); View viewTouchpad = getChildAt(1);
// removeAllViews(); removeAllViews();
// addView(viewGL); addView(viewGL);
// addView(viewTouchpad); addView(viewTouchpad);
//} else { } else {
removeAllViews();*/
removeAllButtons(); removeAllButtons();
//} //}
if (mLayout != null) { if (mLayout != null) {
@ -99,13 +100,14 @@ public class ControlLayout extends FrameLayout
} }
private void removeAllButtons() { private void removeAllButtons() {
List<View> viewList = new ArrayList<>(); List<View> viewList = new ArrayList<>();
View v;
for(int i = 0; i < getChildCount(); i++) { for(int i = 0; i < getChildCount(); i++) {
viewList.add(getChildAt(i)); v = getChildAt(i);
if(v instanceof ControlButton) viewList.add(v);
} }
for(View v : viewList) { v = null;
if(v instanceof ControlButton) { for(View v2 : viewList) {
removeView(v); removeView(v2);
}
} }
viewList = null; viewList = null;
System.gc(); System.gc();