mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-13 14:51:51 -04:00
A little custom controls
This commit is contained in:
parent
b96b9489df
commit
5666b2973a
@ -32,6 +32,11 @@
|
|||||||
android:screenOrientation="sensorLandscape"
|
android:screenOrientation="sensorLandscape"
|
||||||
android:name=".MCLauncherActivity"
|
android:name=".MCLauncherActivity"
|
||||||
android:configChanges="keyboardHidden|orientation|screenSize"/>
|
android:configChanges="keyboardHidden|orientation|screenSize"/>
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:screenOrientation="sensorLandscape"
|
||||||
|
android:name=".CustomControlsActivity"
|
||||||
|
android:configChanges="keyboardHidden|orientation|screenSize"/>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:launchMode="standard"
|
android:launchMode="standard"
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
package net.kdt.pojavlaunch;
|
||||||
|
|
||||||
|
import android.support.v7.app.*;
|
||||||
|
import android.os.*;
|
||||||
|
|
||||||
|
public class CustomControlsActivity extends AppCompatActivity
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -7,10 +7,10 @@ import android.graphics.drawable.*;
|
|||||||
import android.os.*;
|
import android.os.*;
|
||||||
import android.support.design.widget.*;
|
import android.support.design.widget.*;
|
||||||
import android.support.v4.widget.*;
|
import android.support.v4.widget.*;
|
||||||
|
import android.support.v7.app.*;
|
||||||
import android.system.*;
|
import android.system.*;
|
||||||
import android.util.*;
|
import android.util.*;
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
import android.view.GestureDetector.*;
|
|
||||||
import android.view.View.*;
|
import android.view.View.*;
|
||||||
import android.view.inputmethod.*;
|
import android.view.inputmethod.*;
|
||||||
import android.widget.*;
|
import android.widget.*;
|
||||||
@ -26,18 +26,18 @@ import javax.crypto.*;
|
|||||||
import javax.microedition.khronos.egl.*;
|
import javax.microedition.khronos.egl.*;
|
||||||
import javax.microedition.khronos.opengles.*;
|
import javax.microedition.khronos.opengles.*;
|
||||||
import net.kdt.pojavlaunch.exit.*;
|
import net.kdt.pojavlaunch.exit.*;
|
||||||
|
import net.kdt.pojavlaunch.prefs.*;
|
||||||
|
import optifine.*;
|
||||||
|
import org.apache.harmony.security.fortress.*;
|
||||||
import org.lwjgl.input.*;
|
import org.lwjgl.input.*;
|
||||||
import org.lwjgl.opengl.*;
|
import org.lwjgl.opengl.*;
|
||||||
import org.lwjgl.util.applet.*;
|
import org.lwjgl.util.applet.*;
|
||||||
import org.lwjgl.util.glu.tessellation.*;
|
import org.lwjgl.util.glu.tessellation.*;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import java.security.Provider.*;
|
|
||||||
import org.apache.harmony.security.fortress.*;
|
|
||||||
import optifine.*;
|
|
||||||
import net.kdt.pojavlaunch.prefs.*;
|
|
||||||
|
|
||||||
public class MainActivity extends Activity implements OnTouchListener, OnClickListener
|
public class MainActivity extends AppCompatActivity implements OnTouchListener, OnClickListener
|
||||||
{
|
{
|
||||||
public static final String initText = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA ";
|
public static final String initText = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA ";
|
||||||
|
|
||||||
@ -498,7 +498,7 @@ public class MainActivity extends Activity implements OnTouchListener, OnClickLi
|
|||||||
pointerCaptureListener = new OnTouchListener(){
|
pointerCaptureListener = new OnTouchListener(){
|
||||||
private int x, y;
|
private int x, y;
|
||||||
|
|
||||||
private String getMoving(int pos, boolean xOrY) {
|
private String getMoving(float pos, boolean xOrY) {
|
||||||
if (pos == 0) {
|
if (pos == 0) {
|
||||||
return "STOPPED";
|
return "STOPPED";
|
||||||
} else if (pos > 0) {
|
} else if (pos > 0) {
|
||||||
@ -526,8 +526,8 @@ public class MainActivity extends Activity implements OnTouchListener, OnClickLi
|
|||||||
|
|
||||||
builder.append("XPos=" + x + "\n");
|
builder.append("XPos=" + x + "\n");
|
||||||
builder.append("YPos=" + y + "\n\n");
|
builder.append("YPos=" + y + "\n\n");
|
||||||
builder.append("MovingX=" + getMoving(x, true) + "\n");
|
builder.append("MovingX=" + getMoving(e.getX(), true) + "\n");
|
||||||
builder.append("MovingY=" + getMoving(y, false) + "\n");
|
builder.append("MovingY=" + getMoving(e.getY(), false) + "\n");
|
||||||
|
|
||||||
debugText.setText(builder.toString());
|
debugText.setText(builder.toString());
|
||||||
}
|
}
|
||||||
@ -1245,12 +1245,4 @@ public class MainActivity extends Activity implements OnTouchListener, OnClickLi
|
|||||||
}
|
}
|
||||||
return hotbarKeys[((x - barx) / mcscale(20)) % 9];
|
return hotbarKeys[((x - barx) / mcscale(20)) % 9];
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SingleTapConfirm extends SimpleOnGestureListener
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public boolean onSingleTapUp(MotionEvent event) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
12
app/src/main/java/net/kdt/pojavlaunch/SingleTapConfirm.java
Normal file
12
app/src/main/java/net/kdt/pojavlaunch/SingleTapConfirm.java
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package net.kdt.pojavlaunch;
|
||||||
|
|
||||||
|
import android.view.*;
|
||||||
|
import android.view.GestureDetector.*;
|
||||||
|
|
||||||
|
public class SingleTapConfirm extends SimpleOnGestureListener
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public boolean onSingleTapUp(MotionEvent event) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package net.kdt.pojavlaunch.value.customcontrols;
|
||||||
|
import net.kdt.pojavlaunch.*;
|
||||||
|
|
||||||
|
public class ControlButton
|
||||||
|
{
|
||||||
|
// Concept...
|
||||||
|
public String name;
|
||||||
|
public float x;
|
||||||
|
public float y;
|
||||||
|
public int lwjglKeycode;
|
||||||
|
public boolean holdCtrl;
|
||||||
|
public boolean holdAlt;
|
||||||
|
public boolean holdShift;
|
||||||
|
// public boolean hold
|
||||||
|
|
||||||
|
public void execute(MainActivity act, boolean isDown) {
|
||||||
|
act.sendKeyPress(lwjglKeycode, isDown);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,73 @@
|
|||||||
|
package net.kdt.pojavlaunch.value.customcontrols;
|
||||||
|
|
||||||
|
import android.content.*;
|
||||||
|
import android.view.*;
|
||||||
|
import android.view.View.*;
|
||||||
|
import android.widget.*;
|
||||||
|
import net.kdt.pojavlaunch.*;
|
||||||
|
|
||||||
|
public class ControlView extends Button implements OnTouchListener
|
||||||
|
{
|
||||||
|
private GestureDetector mGestureDetector;
|
||||||
|
private View.OnClickListener mClickListener;
|
||||||
|
private ControlButton mProperties;
|
||||||
|
|
||||||
|
public ControlView(Context ctx, ControlButton properties) {
|
||||||
|
super(ctx);
|
||||||
|
|
||||||
|
setOnTouchListener(this);
|
||||||
|
mGestureDetector = new GestureDetector(ctx, new SingleTapConfirm());
|
||||||
|
mProperties = properties;
|
||||||
|
|
||||||
|
setText(properties.name);
|
||||||
|
setTranslationX(moveX = properties.x);
|
||||||
|
setTranslationY(moveY = properties.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setTranslationX(float x)
|
||||||
|
{
|
||||||
|
super.setTranslationX(x);
|
||||||
|
mProperties.x = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setTranslationY(float y) {
|
||||||
|
super.setTranslationY(y);
|
||||||
|
mProperties.y = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
private float moveX, moveY;
|
||||||
|
private float downX, downY;
|
||||||
|
@Override
|
||||||
|
public boolean onTouch(View view, MotionEvent event) {
|
||||||
|
if (mGestureDetector.onTouchEvent(event)) {
|
||||||
|
mClickListener.onClick(view);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (event.getActionMasked()) {
|
||||||
|
case MotionEvent.ACTION_DOWN:
|
||||||
|
downX = event.getX();
|
||||||
|
downY = event.getY();
|
||||||
|
break;
|
||||||
|
case MotionEvent.ACTION_UP:
|
||||||
|
case MotionEvent.ACTION_MOVE:
|
||||||
|
moveX += event.getX() - downX;
|
||||||
|
moveY += event.getY() - downY;
|
||||||
|
|
||||||
|
setTranslationX(moveX);
|
||||||
|
setTranslationY(moveY);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setOnClickListener(View.OnClickListener l) {
|
||||||
|
// super.setOnClickListener(p1);
|
||||||
|
|
||||||
|
mClickListener = l;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package net.kdt.pojavlaunch.value.customcontrols;
|
||||||
|
import android.widget.*;
|
||||||
|
import android.content.*;
|
||||||
|
import android.util.*;
|
||||||
|
|
||||||
|
public class ControlsLayout extends FrameLayout
|
||||||
|
{
|
||||||
|
public ControlsLayout(Context ctx) {
|
||||||
|
super(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ControlsLayout(Context ctx, AttributeSet attrs) {
|
||||||
|
super(ctx, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadLayout(CustomControls controlLayout) {
|
||||||
|
for (ControlButton button : controlLayout.button) {
|
||||||
|
addView(new ControlView(getContext(), button));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
package net.kdt.pojavlaunch.value.customcontrols;
|
||||||
|
|
||||||
|
public class CustomControls
|
||||||
|
{
|
||||||
|
public ControlButton[] button = new ControlButton[]{};
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user