Improved custom controls. Fix wrong OpenJDK link

This commit is contained in:
khanhduytran0
2020-05-09 12:48:36 +07:00
parent 55c3c3959f
commit e1ac898e5b
6 changed files with 164 additions and 102 deletions

View File

@@ -48,6 +48,7 @@ import com.theqvd.android.xpro.Config;
import net.kdt.pojavlaunch.value.customcontrols.*;
import com.google.gson.*;
import org.lwjgl.opengl.*;
import android.view.inputmethod.*;
public class VncCanvasActivity extends AppCompatActivity
{
@@ -130,6 +131,7 @@ public class VncCanvasActivity extends AppCompatActivity
}
mControlLayout = findViewById(R.id.main_controllayout);
mControlLayout.setModifiable(false);
if (modPath == null) {
ControlButton[] specialButtons = ControlButton.getSpecialButtons();
specialButtons[0].specialButtonListener = new View.OnClickListener(){
@@ -159,6 +161,25 @@ public class VncCanvasActivity extends AppCompatActivity
};
mControlLayout.loadLayout(getSharedPreferences(getPackageName() + "_preferences", MODE_PRIVATE).getString("defaultCtrl", Tools.CTRLMAP_PATH + "/default.json"));
mControlLayout.setControlVisible(false);
boolean controlVisible = false;
for (ControlView specialView : mControlLayout.getSpecialControlViewArray()) {
switch (specialView.getProperties().keycode) {
case ControlButton.SPECIALBTN_KEYBOARD:
InputMethodManager inputMgr = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
inputMgr.toggleSoftInput(0, 0);
break;
case ControlButton.SPECIALBTN_TOGGLECTRL:
controlVisible = !controlVisible;
mControlLayout.setControlVisible(controlVisible);
break;
case ControlButton.SPECIALBTN_MOUSEPRI:
break;
case ControlButton.SPECIALBTN_MOUSESEC:
break;
}
}
mControlLayout.setupKeyEvent(new ControlsLayout.ControlListener(){
@Override
public void onKey(MetaKeyBase vncKey, boolean down)

View File

@@ -85,8 +85,8 @@ public class CustomControlsActivity extends AppCompatActivity
}
ctrlLayout.setActivity(this);
ctrlLayout.loadLayout(mCtrl);
ctrlLayout.setModifiable(true);
ctrlLayout.loadLayout(mCtrl);
}
@Override

View File

@@ -191,7 +191,7 @@ public class PojavLoginActivity extends MineActivity
publishProgress(null);
try {
// BEGIN download openjdk
URL url = new URL("https://github.com/khanhduytran0/PojavLauncher/releases/download/v3.0.1-preview1/net.kdt.pojavlaunch.openjdkv3.zip");
URL url = new URL("https://github.com/khanhduytran0/PojavLauncher/releases/download/v3.0.1_preview1/net.kdt.pojavlaunch.openjdkv3.zip");
URLConnection connection = url.openConnection();
connection.connect();
int fileLength = connection.getContentLength();

View File

@@ -14,8 +14,10 @@ public class ControlButton implements Cloneable
public static int pixelOf50dp;
public static int pixelOf80dp;
public static final int SPECIALBTN_KEYBOARD = 0;
public static final int SPECIALBTN_TOGGLECTRL = 1;
public static final int SPECIALBTN_KEYBOARD = -1;
public static final int SPECIALBTN_TOGGLECTRL = -2;
public static final int SPECIALBTN_MOUSEPRI = -3;
public static final int SPECIALBTN_MOUSESEC = -4;
private static ControlButton[] SPECIAL_BUTTONS;
private static String[] SPECIAL_BUTTON_NAME_ARRAY;
@@ -23,10 +25,10 @@ public class ControlButton implements Cloneable
public static ControlButton[] getSpecialButtons(){
if (SPECIAL_BUTTONS == null) {
SPECIAL_BUTTONS = new ControlButton[]{
new ControlButton("Keyboard", -1, pixelOf2dp * 3 + pixelOf80dp * 2, pixelOf2dp, pixelOf80dp, pixelOf30dp),
new ControlButton("GUI", -2, pixelOf2dp, AndroidDisplay.windowHeight - pixelOf50dp * 2 + pixelOf2dp * 4),
new ControlButton("PRI", -3, pixelOf2dp, AndroidDisplay.windowHeight - pixelOf50dp * 4 + pixelOf2dp * 2),
new ControlButton("SEC", -4, pixelOf2dp * 3 + pixelOf50dp * 2, AndroidDisplay.windowHeight - pixelOf50dp * 4 + pixelOf2dp * 2)
new ControlButton("Keyboard", SPECIALBTN_KEYBOARD, pixelOf2dp * 3 + pixelOf80dp * 2, pixelOf2dp, pixelOf80dp, pixelOf30dp),
new ControlButton("GUI", SPECIALBTN_TOGGLECTRL, pixelOf2dp, AndroidDisplay.windowHeight - pixelOf50dp * 2 + pixelOf2dp * 4),
new ControlButton("PRI", SPECIALBTN_MOUSEPRI, pixelOf2dp, AndroidDisplay.windowHeight - pixelOf50dp * 4 + pixelOf2dp * 2),
new ControlButton("SEC", SPECIALBTN_MOUSESEC, pixelOf2dp * 3 + pixelOf50dp * 2, AndroidDisplay.windowHeight - pixelOf50dp * 4 + pixelOf2dp * 2)
};
}

View File

@@ -19,16 +19,14 @@ public class ControlView extends Button implements OnLongClickListener, OnTouchL
private boolean mCanModify = false;
private boolean mCanTriggerLongClick = true;
public ControlView(Context ctx, ControlButton properties) {
public ControlView(Context ctx, ControlButton properties, boolean modifiable) {
super(ctx);
mGestureDetector = new GestureDetector(ctx, new SingleTapConfirm());
setBackgroundResource(R.drawable.control_button);
setOnLongClickListener(this);
setOnTouchListener(this);
setModifiable(modifiable);
setProperties(properties);
mHandleView = new SelectionEndHandleView(this);
@@ -42,10 +40,79 @@ public class ControlView extends Button implements OnLongClickListener, OnTouchL
return mProperties;
}
@Override
public boolean onLongClick(View p1)
{
if (!mCanTriggerLongClick || !mCanModify) return false;
if (mHandleView.isShowing()) {
mHandleView.hide();
} else {
if (getParent() != null) {
((ControlsLayout) getParent()).hideAllHandleViews();
}
mHandleView.show();
}
return true;
}
private float moveX, moveY;
private float downX, downY;
@Override
public boolean onTouch(View view, MotionEvent event) {
if (!mCanModify) {
mCanTriggerLongClick = false;
return false;
}
switch (event.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
mCanTriggerLongClick = true;
downX = event.getX();
downY = event.getY();
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_MOVE:
mCanTriggerLongClick = false;
moveX += event.getX() - downX;
moveY += event.getY() - downY;
setTranslationX(moveX);
setTranslationY(moveY);
setModified(true);
break;
}
return false;
}
public void setActivity(CustomControlsActivity activity) {
mActivity = activity;
}
@Override
public void setLayoutParams(ViewGroup.LayoutParams params)
{
super.setLayoutParams(params);
mProperties.width = params.width;
mProperties.height = params.height;
setModified(true);
}
public void setModifiable(boolean z) {
mCanModify = z;
if (z) {
setOnLongClickListener(this);
setOnTouchListener(this);
} else {
setOnLongClickListener(null);
setOnTouchListener(null);
}
}
public void setModified(boolean z) {
if (mActivity != null) mActivity.isModified = z;
}
@@ -67,17 +134,6 @@ public class ControlView extends Button implements OnLongClickListener, OnTouchL
setLayoutParams(new FrameLayout.LayoutParams(properties.width, properties.height));
}
@Override
public void setLayoutParams(ViewGroup.LayoutParams params)
{
super.setLayoutParams(params);
mProperties.width = params.width;
mProperties.height = params.height;
setModified(true);
}
@Override
public void setTranslationX(float x)
{
@@ -95,59 +151,8 @@ public class ControlView extends Button implements OnLongClickListener, OnTouchL
setProperties(mProperties);
}
@Override
public boolean onLongClick(View p1)
{
if (!mCanTriggerLongClick || !mCanModify) return false;
if (mHandleView.isShowing()) {
mHandleView.hide();
} else {
if (getParent() != null) {
((ControlsLayout) getParent()).hideAllHandleViews();
}
mHandleView.show();
}
return true;
}
private float moveX, moveY;
private float downX, downY;
@Override
public boolean onTouch(View view, MotionEvent event) {
if (!mCanModify) {
mCanTriggerLongClick = false;
return false;
}
switch (event.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
mCanTriggerLongClick = true;
downX = event.getX();
downY = event.getY();
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_MOVE:
mCanTriggerLongClick = false;
moveX += event.getX() - downX;
moveY += event.getY() - downY;
setTranslationX(moveX);
setTranslationY(moveY);
setModified(true);
break;
}
return false;
}
public void setModifiable(boolean z) {
mCanModify = z;
}
public ControlView clone() {
ControlView cloneObj = new ControlView(getContext(), mProperties);
ControlView cloneObj = new ControlView(getContext(), mProperties, mCanModify);
cloneObj.setTranslationX(getTranslationX());
cloneObj.setTranslationY(getTranslationY());
cloneObj.setTranslationZ(getTranslationZ());

View File

@@ -7,26 +7,54 @@ import com.google.gson.*;
import net.kdt.pojavlaunch.*;
import android.support.v7.app.*;
import android.androidVNC.*;
import java.util.*;
public class ControlsLayout extends FrameLayout
{
private boolean mCanModify;
private CustomControls mLayout;
private CustomControlsActivity mActivity;
private List<ControlView> mControlViewList;
public ControlsLayout(Context ctx) {
super(ctx);
this(ctx, null);
}
public ControlsLayout(Context ctx, AttributeSet attrs) {
super(ctx, attrs);
mControlViewList = new ArrayList<ControlView>();
}
@Override
public void addView(View view) {
super.addView(view);
if (view instanceof ControlView) mControlViewList.add((ControlView) view);
}
@Override
public void removeView(View view) {
super.removeView(view);
if (view instanceof ControlView) mControlViewList.remove((ControlView) view);
}
public ControlView[] getControlViewArray() {
return mControlViewList.toArray(new ControlView[0]);
}
public ControlView[] getSpecialControlViewArray() {
List<ControlView> specialViewList = new ArrayList<ControlView>();
for (ControlView view : getControlViewArray()) {
if (view.getProperties().keycode < 0) {
specialViewList.add(view);
}
}
return specialViewList.toArray(new ControlView[0]);
}
public void hideAllHandleViews() {
for (int i = 0; i < getChildCount(); i++) {
View view = getChildAt(i);
if (view instanceof ControlView) {
((ControlView) view).getHandleView().hide();
}
for (final ControlView view : mControlViewList) {
view.getHandleView().hide();
}
}
@@ -40,23 +68,36 @@ public class ControlsLayout extends FrameLayout
public void loadLayout(CustomControls controlLayout) {
mLayout = controlLayout;
removeAllViews();
// Safety remove only ControlView views
for (ControlView view : mControlViewList) {
removeView(view);
}
for (ControlButton button : controlLayout.button) {
if (button.keycode < 0) {
// Set special button
}
addControlView(button);
}
setModified(false);
}
public void setControlVisible(boolean visible) {
for (final ControlView ctrlView : mControlViewList) {
if (ctrlView.getProperties().keycode == ControlButton.SPECIALBTN_TOGGLECTRL) continue;
ctrlView.setVisibility(visible ? (
(ctrlView.getProperties().hidden && !mCanModify) ?
View.INVISIBLE :
View.VISIBLE
) :
View.GONE
);
}
}
public void setupKeyEvent(final ControlListener listener) {
for (int i = 0; i < getChildCount(); i++) {
View v = getChildAt(i);
if (v instanceof ControlView) {
final ControlView ctrlView = (ControlView) v;
ctrlView.setOnTouchListener(new View.OnTouchListener(){
for (final ControlView ctrlView : mControlViewList) {
if (ctrlView.getProperties().keycode < 0) continue;
ctrlView.setOnTouchListener(new View.OnTouchListener(){
@Override
public boolean onTouch(View view, MotionEvent event)
@@ -66,7 +107,7 @@ public class ControlsLayout extends FrameLayout
case MotionEvent.ACTION_DOWN: isDown = true; break;
case MotionEvent.ACTION_UP: isDown = false; break;
}
for (int i = 0; i < MetaKeyBean.keysByKeyCode.size(); i++) {
MetaKeyBase key = MetaKeyBean.keysByKeyCode.valueAt(i);
if (ctrlView.getProperties().keycode == key.keyEvent) {
@@ -76,7 +117,6 @@ public class ControlsLayout extends FrameLayout
return false;
}
});
}
}
}
@@ -86,10 +126,8 @@ public class ControlsLayout extends FrameLayout
}
private void addControlView(ControlButton controlButton) {
final ControlView view = new ControlView(getContext(), controlButton);
view.setModifiable(mCanModify);
final ControlView view = new ControlView(getContext(), controlButton, mCanModify);
addView(view);
setModified(true);
}
@@ -97,7 +135,6 @@ public class ControlsLayout extends FrameLayout
mLayout.button.remove(controlButton.getProperties());
controlButton.setVisibility(View.GONE);
removeView(controlButton);
setModified(true);
}
@@ -112,16 +149,13 @@ public class ControlsLayout extends FrameLayout
public void setModifiable(boolean z) {
mCanModify = z;
for (int i = 0; i < getChildCount(); i++) {
View v = getChildAt(i);
if (v instanceof ControlView) {
((ControlView) v).setModifiable(z);
}
for (final ControlView view : mControlViewList) {
view.setModifiable(z);
}
}
private void setModified(boolean z) {
if (mActivity != null) mActivity.isModified = z;
if (mActivity != null && mCanModify) mActivity.isModified = z;
}
public static interface ControlListener {