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