Custom controls: can move or not

This commit is contained in:
khanhduytran0
2020-04-11 09:52:18 +07:00
parent 5666b2973a
commit 9a64dde80c
2 changed files with 17 additions and 0 deletions

View File

@@ -11,6 +11,7 @@ public class ControlView extends Button implements OnTouchListener
private GestureDetector mGestureDetector;
private View.OnClickListener mClickListener;
private ControlButton mProperties;
private boolean mCanMove = false;
public ControlView(Context ctx, ControlButton properties) {
super(ctx);
@@ -44,6 +45,8 @@ public class ControlView extends Button implements OnTouchListener
if (mGestureDetector.onTouchEvent(event)) {
mClickListener.onClick(view);
return true;
} else if (!mCanMove) {
return false;
}
switch (event.getActionMasked()) {
@@ -70,4 +73,8 @@ public class ControlView extends Button implements OnTouchListener
mClickListener = l;
}
public void setCanMove(boolean z) {
mCanMove = z;
}
}

View File

@@ -2,6 +2,7 @@ package net.kdt.pojavlaunch.value.customcontrols;
import android.widget.*;
import android.content.*;
import android.util.*;
import android.view.*;
public class ControlsLayout extends FrameLayout
{
@@ -18,4 +19,13 @@ public class ControlsLayout extends FrameLayout
addView(new ControlView(getContext(), button));
}
}
public void setCanMove(boolean z) {
for (int i = 0; i < getChildCount(); i++) {
View v = getChildAt(i);
if (v instanceof ControlView) {
((ControlView) v).setCanMove(z);
}
}
}
}