mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2026-04-18 16:46:58 -04:00
Custom control: select default and load control in game
This commit is contained in:
@@ -20,10 +20,12 @@ public abstract class AbstractMetaKeyBean extends com.antlersoft.android.dbimpl.
|
||||
public static final int GEN_ID_MOUSECLICK = 4;
|
||||
public static final String GEN_FIELD_MOUSEBUTTONS = "MOUSEBUTTONS";
|
||||
public static final int GEN_ID_MOUSEBUTTONS = 5;
|
||||
public static final String GEN_FIELD_KEYEVENT = "KEYEVENT";
|
||||
public static final int GEN_ID_KEYEVENT = 6;
|
||||
public static final String GEN_FIELD_KEYSYM = "KEYSYM";
|
||||
public static final int GEN_ID_KEYSYM = 6;
|
||||
public static final int GEN_ID_KEYSYM = 7;
|
||||
public static final String GEN_FIELD_SHORTCUT = "SHORTCUT";
|
||||
public static final int GEN_ID_SHORTCUT = 7;
|
||||
public static final int GEN_ID_SHORTCUT = 8;
|
||||
|
||||
// SQL Command for creating the table
|
||||
public static String GEN_CREATE = "CREATE TABLE META_KEY (" +
|
||||
@@ -33,6 +35,7 @@ public abstract class AbstractMetaKeyBean extends com.antlersoft.android.dbimpl.
|
||||
"METAFLAGS INTEGER," +
|
||||
"MOUSECLICK INTEGER," +
|
||||
"MOUSEBUTTONS INTEGER," +
|
||||
"KEYEVENT INTEGER," +
|
||||
"KEYSYM INTEGER," +
|
||||
"SHORTCUT TEXT" +
|
||||
")";
|
||||
@@ -44,6 +47,7 @@ public abstract class AbstractMetaKeyBean extends com.antlersoft.android.dbimpl.
|
||||
private int gen_metaFlags;
|
||||
private boolean gen_mouseClick;
|
||||
private int gen_mouseButtons;
|
||||
private int gen_keyEvent;
|
||||
private int gen_keySym;
|
||||
private java.lang.String gen_shortcut;
|
||||
|
||||
@@ -63,6 +67,8 @@ public abstract class AbstractMetaKeyBean extends com.antlersoft.android.dbimpl.
|
||||
public void setMouseClick(boolean arg_mouseClick) { gen_mouseClick = arg_mouseClick; }
|
||||
public int getMouseButtons() { return gen_mouseButtons; }
|
||||
public void setMouseButtons(int arg_mouseButtons) { gen_mouseButtons = arg_mouseButtons; }
|
||||
public int getKeyEvent() { return gen_keyEvent; }
|
||||
public void setKeyEvent(int arg_keyEvent) { gen_keySym = arg_keyEvent; }
|
||||
public int getKeySym() { return gen_keySym; }
|
||||
public void setKeySym(int arg_keySym) { gen_keySym = arg_keySym; }
|
||||
public java.lang.String getShortcut() { return gen_shortcut; }
|
||||
@@ -76,6 +82,7 @@ public abstract class AbstractMetaKeyBean extends com.antlersoft.android.dbimpl.
|
||||
values.put(GEN_FIELD_METAFLAGS,Integer.toString(this.gen_metaFlags));
|
||||
values.put(GEN_FIELD_MOUSECLICK,(this.gen_mouseClick ? "1" : "0"));
|
||||
values.put(GEN_FIELD_MOUSEBUTTONS,Integer.toString(this.gen_mouseButtons));
|
||||
values.put(GEN_FIELD_KEYEVENT,Integer.toString(this.gen_keyEvent));
|
||||
values.put(GEN_FIELD_KEYSYM,Integer.toString(this.gen_keySym));
|
||||
values.put(GEN_FIELD_SHORTCUT,this.gen_shortcut);
|
||||
return values;
|
||||
@@ -98,8 +105,9 @@ public abstract class AbstractMetaKeyBean extends com.antlersoft.android.dbimpl.
|
||||
result[3] = cursor.getColumnIndex(GEN_FIELD_METAFLAGS);
|
||||
result[4] = cursor.getColumnIndex(GEN_FIELD_MOUSECLICK);
|
||||
result[5] = cursor.getColumnIndex(GEN_FIELD_MOUSEBUTTONS);
|
||||
result[6] = cursor.getColumnIndex(GEN_FIELD_KEYSYM);
|
||||
result[7] = cursor.getColumnIndex(GEN_FIELD_SHORTCUT);
|
||||
result[6] = cursor.getColumnIndex(GEN_FIELD_KEYEVENT);
|
||||
result[7] = cursor.getColumnIndex(GEN_FIELD_KEYSYM);
|
||||
result[8] = cursor.getColumnIndex(GEN_FIELD_SHORTCUT);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -125,6 +133,9 @@ public abstract class AbstractMetaKeyBean extends com.antlersoft.android.dbimpl.
|
||||
if ( columnIndices[GEN_ID_MOUSEBUTTONS] >= 0 && ! cursor.isNull(columnIndices[GEN_ID_MOUSEBUTTONS])) {
|
||||
gen_mouseButtons = (int)cursor.getInt(columnIndices[GEN_ID_MOUSEBUTTONS]);
|
||||
}
|
||||
if ( columnIndices[GEN_ID_KEYEVENT] >= 0 && ! cursor.isNull(columnIndices[GEN_ID_KEYEVENT])) {
|
||||
gen_keyEvent = (int)cursor.getInt(columnIndices[GEN_ID_KEYEVENT]);
|
||||
}
|
||||
if ( columnIndices[GEN_ID_KEYSYM] >= 0 && ! cursor.isNull(columnIndices[GEN_ID_KEYSYM])) {
|
||||
gen_keySym = (int)cursor.getInt(columnIndices[GEN_ID_KEYSYM]);
|
||||
}
|
||||
@@ -143,6 +154,7 @@ public abstract class AbstractMetaKeyBean extends com.antlersoft.android.dbimpl.
|
||||
gen_metaFlags = (int)values.getAsInteger(GEN_FIELD_METAFLAGS);
|
||||
gen_mouseClick = (values.getAsInteger(GEN_FIELD_MOUSECLICK) != 0);
|
||||
gen_mouseButtons = (int)values.getAsInteger(GEN_FIELD_MOUSEBUTTONS);
|
||||
gen_keyEvent = (int)values.getAsInteger(GEN_FIELD_KEYEVENT);
|
||||
gen_keySym = (int)values.getAsInteger(GEN_FIELD_KEYSYM);
|
||||
gen_shortcut = values.getAsString(GEN_FIELD_SHORTCUT);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@ public interface IMetaKey {
|
||||
@FieldAccessor
|
||||
int getMouseButtons();
|
||||
@FieldAccessor
|
||||
int getKeyEvent();
|
||||
@FieldAccessor
|
||||
int getKeySym();
|
||||
@FieldAccessor
|
||||
String getShortcut();
|
||||
|
||||
@@ -7,10 +7,10 @@ package android.androidVNC;
|
||||
* @author Michael A. MacDonald
|
||||
*
|
||||
*/
|
||||
class MetaKeyBase implements Comparable<MetaKeyBase> {
|
||||
int keySym;
|
||||
public class MetaKeyBase implements Comparable<MetaKeyBase> {
|
||||
public int keySym;
|
||||
int mouseButtons;
|
||||
int keyEvent;
|
||||
public int keyEvent;
|
||||
String name;
|
||||
boolean isMouse;
|
||||
boolean isKeyEvent;
|
||||
|
||||
@@ -3,40 +3,41 @@
|
||||
*/
|
||||
package android.androidVNC;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.antlersoft.android.dbimpl.NewInstance;
|
||||
|
||||
import android.view.KeyEvent;
|
||||
import android.util.*;
|
||||
import android.view.*;
|
||||
import com.antlersoft.android.dbimpl.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Michael A. MacDonald
|
||||
*
|
||||
*/
|
||||
class MetaKeyBean extends AbstractMetaKeyBean implements Comparable<MetaKeyBean> {
|
||||
static final ArrayList<MetaKeyBase> allKeys;
|
||||
static final String[] allKeysNames;
|
||||
static final HashMap<Integer,MetaKeyBase> keysByKeyCode;
|
||||
static final HashMap<Integer,MetaKeyBase> keysByMouseButton;
|
||||
static final HashMap<Integer,MetaKeyBase> keysByKeySym;
|
||||
static final MetaKeyBean keyCtrlAltDel;
|
||||
static final MetaKeyBean keyArrowLeft;
|
||||
static final MetaKeyBean keyArrowRight;
|
||||
static final MetaKeyBean keyArrowUp;
|
||||
static final MetaKeyBean keyArrowDown;
|
||||
public class MetaKeyBean extends AbstractMetaKeyBean implements Comparable<MetaKeyBean> {
|
||||
static ArrayList<MetaKeyBase> allKeys;
|
||||
static String[] allKeysNames;
|
||||
public static ArrayMap<Integer,MetaKeyBase> keysByKeyCode;
|
||||
static ArrayMap<Integer,MetaKeyBase> keysByMouseButton;
|
||||
static MetaKeyBean keyCtrlAltDel;
|
||||
static MetaKeyBean keyArrowLeft;
|
||||
static MetaKeyBean keyArrowRight;
|
||||
static MetaKeyBean keyArrowUp;
|
||||
static MetaKeyBean keyArrowDown;
|
||||
|
||||
static final NewInstance<MetaKeyBean> NEW;
|
||||
static NewInstance<MetaKeyBean> NEW;
|
||||
|
||||
static {
|
||||
initStatic();
|
||||
}
|
||||
|
||||
public static void initStatic() {
|
||||
allKeys = new ArrayList<MetaKeyBase>();
|
||||
|
||||
allKeys.add(new MetaKeyBase("Hangul", 0xff31));
|
||||
allKeys.add(new MetaKeyBase("Hangul_Start", 0xff32));
|
||||
allKeys.add(new MetaKeyBase("Hangul_End", 0xff33));
|
||||
allKeys.add(new MetaKeyBase("Hangul_Hanja", 0xff34));
|
||||
allKeys.add(new MetaKeyBase("Kana_Shift", 0xff2e));
|
||||
allKeys.add(new MetaKeyBase("Right_Alt", 0xffea));
|
||||
allKeys.add(new MetaKeyBase("Kana_Shift", 0xff2e, KeyEvent.KEYCODE_KANA));
|
||||
allKeys.add(new MetaKeyBase("Right_Alt", 0xffea, KeyEvent.KEYCODE_ALT_RIGHT));
|
||||
|
||||
allKeys.add(new MetaKeyBase(VncCanvas.MOUSE_BUTTON_LEFT,"Mouse Left"));
|
||||
allKeys.add(new MetaKeyBase(VncCanvas.MOUSE_BUTTON_MIDDLE,"Mouse Middle"));
|
||||
@@ -44,24 +45,24 @@ class MetaKeyBean extends AbstractMetaKeyBean implements Comparable<MetaKeyBean>
|
||||
allKeys.add(new MetaKeyBase(VncCanvas.MOUSE_BUTTON_SCROLL_DOWN, "Mouse Scroll Down"));
|
||||
allKeys.add(new MetaKeyBase(VncCanvas.MOUSE_BUTTON_SCROLL_UP, "Mouse Scroll Up"));
|
||||
|
||||
allKeys.add(new MetaKeyBase("Home", 0xFF50));
|
||||
allKeys.add(new MetaKeyBase("Arrow Left", 0xFF51));
|
||||
allKeys.add(new MetaKeyBase("Arrow Up", 0xFF52));
|
||||
allKeys.add(new MetaKeyBase("Arrow Right", 0xFF53));
|
||||
allKeys.add(new MetaKeyBase("Arrow Down", 0xFF54));
|
||||
allKeys.add(new MetaKeyBase("Page Up", 0xFF55));
|
||||
allKeys.add(new MetaKeyBase("Page Down", 0xFF56));
|
||||
allKeys.add(new MetaKeyBase("End", 0xFF57));
|
||||
allKeys.add(new MetaKeyBase("Insert", 0xFF63));
|
||||
allKeys.add(new MetaKeyBase("Home", 0xFF50, KeyEvent.KEYCODE_HOME));
|
||||
allKeys.add(new MetaKeyBase("Arrow Left", 0xFF51, KeyEvent.KEYCODE_DPAD_LEFT));
|
||||
allKeys.add(new MetaKeyBase("Arrow Up", 0xFF52, KeyEvent.KEYCODE_DPAD_UP));
|
||||
allKeys.add(new MetaKeyBase("Arrow Right", 0xFF53, KeyEvent.KEYCODE_DPAD_RIGHT));
|
||||
allKeys.add(new MetaKeyBase("Arrow Down", 0xFF54, KeyEvent.KEYCODE_DPAD_DOWN));
|
||||
allKeys.add(new MetaKeyBase("Page Up", 0xFF55, KeyEvent.KEYCODE_PAGE_UP));
|
||||
allKeys.add(new MetaKeyBase("Page Down", 0xFF56, KeyEvent.KEYCODE_PAGE_DOWN));
|
||||
allKeys.add(new MetaKeyBase("End", 0xFF57 /* ??? HELPME */));
|
||||
allKeys.add(new MetaKeyBase("Insert", 0xFF63, KeyEvent.KEYCODE_INSERT));
|
||||
allKeys.add(new MetaKeyBase("Delete", 0xFFFF, KeyEvent.KEYCODE_DEL));
|
||||
allKeys.add(new MetaKeyBase("Num Lock", 0xFF7F));
|
||||
allKeys.add(new MetaKeyBase("Break", 0xFF6b));
|
||||
allKeys.add(new MetaKeyBase("Scroll Lock", 0xFF14));
|
||||
allKeys.add(new MetaKeyBase("Print Scrn", 0xFF15));
|
||||
allKeys.add(new MetaKeyBase("Escape", 0xFF1B));
|
||||
allKeys.add(new MetaKeyBase("Num Lock", 0xFF7F, KeyEvent.KEYCODE_NUM_LOCK));
|
||||
allKeys.add(new MetaKeyBase("Break", 0xFF6b, KeyEvent.KEYCODE_BREAK));
|
||||
allKeys.add(new MetaKeyBase("Scroll Lock", 0xFF14, KeyEvent.KEYCODE_SCROLL_LOCK));
|
||||
allKeys.add(new MetaKeyBase("Print Scrn", 0xFF15 /* ??? HELPME */));
|
||||
allKeys.add(new MetaKeyBase("Escape", 0xFF1B, KeyEvent.KEYCODE_ESCAPE));
|
||||
allKeys.add(new MetaKeyBase("Enter", 0xFF0D, KeyEvent.KEYCODE_ENTER));
|
||||
allKeys.add(new MetaKeyBase("Tab", 0xFF09, KeyEvent.KEYCODE_TAB));
|
||||
allKeys.add(new MetaKeyBase("BackSpace", 0xFF08));
|
||||
allKeys.add(new MetaKeyBase("BackSpace", 0xFF08, KeyEvent.KEYCODE_ESCAPE));
|
||||
allKeys.add(new MetaKeyBase("Space", 0x020, KeyEvent.KEYCODE_SPACE));
|
||||
|
||||
StringBuilder sb = new StringBuilder(" ");
|
||||
@@ -84,14 +85,13 @@ class MetaKeyBean extends AbstractMetaKeyBean implements Comparable<MetaKeyBean>
|
||||
if (i<9)
|
||||
sb.append(' ');
|
||||
sb.append(Integer.toString(i+1));
|
||||
allKeys.add(new MetaKeyBase(sb.toString(), 0xFFBE + i));
|
||||
allKeys.add(new MetaKeyBase(sb.toString(), 0xFFBE + i, KeyEvent.KEYCODE_F1 + i));
|
||||
}
|
||||
|
||||
java.util.Collections.sort(allKeys);
|
||||
allKeysNames = new String[allKeys.size()];
|
||||
keysByKeyCode = new HashMap<Integer,MetaKeyBase>();
|
||||
keysByMouseButton = new HashMap<Integer,MetaKeyBase>();
|
||||
keysByKeySym = new HashMap<Integer,MetaKeyBase>();
|
||||
keysByKeyCode = new ArrayMap<Integer,MetaKeyBase>();
|
||||
keysByMouseButton = new ArrayMap<Integer,MetaKeyBase>();
|
||||
for (int i=0; i<allKeysNames.length; ++i)
|
||||
{
|
||||
MetaKeyBase b=allKeys.get(i);
|
||||
@@ -100,8 +100,8 @@ class MetaKeyBean extends AbstractMetaKeyBean implements Comparable<MetaKeyBean>
|
||||
keysByKeyCode.put(b.keyEvent,b);
|
||||
if (b.isMouse)
|
||||
keysByMouseButton.put(b.mouseButtons,b);
|
||||
else
|
||||
keysByKeySym.put(b.keySym,b);
|
||||
// else
|
||||
// keysByKeySym.put(b.keySym,b);
|
||||
}
|
||||
NEW = new NewInstance<MetaKeyBean>() {
|
||||
|
||||
@@ -114,10 +114,10 @@ class MetaKeyBean extends AbstractMetaKeyBean implements Comparable<MetaKeyBean>
|
||||
}
|
||||
};
|
||||
keyCtrlAltDel = new MetaKeyBean(0,VncCanvas.CTRL_MASK|VncCanvas.ALT_MASK,keysByKeyCode.get(KeyEvent.KEYCODE_DEL));
|
||||
keyArrowLeft = new MetaKeyBean(0,0,keysByKeySym.get(0xFF51));
|
||||
keyArrowUp = new MetaKeyBean(0,0,keysByKeySym.get(0xFF52));
|
||||
keyArrowRight = new MetaKeyBean(0,0,keysByKeySym.get(0xFF53));
|
||||
keyArrowDown = new MetaKeyBean(0,0,keysByKeySym.get(0xFF54));
|
||||
keyArrowLeft = new MetaKeyBean(0,0,keysByKeyCode.get(KeyEvent.KEYCODE_DPAD_LEFT));
|
||||
keyArrowUp = new MetaKeyBean(0,0,keysByKeyCode.get(KeyEvent.KEYCODE_DPAD_UP));
|
||||
keyArrowRight = new MetaKeyBean(0,0,keysByKeyCode.get(KeyEvent.KEYCODE_DPAD_RIGHT));
|
||||
keyArrowDown = new MetaKeyBean(0,0,keysByKeyCode.get(KeyEvent.KEYCODE_DPAD_DOWN));
|
||||
}
|
||||
|
||||
private boolean _regenDesc;
|
||||
@@ -131,8 +131,10 @@ class MetaKeyBean extends AbstractMetaKeyBean implements Comparable<MetaKeyBean>
|
||||
_regenDesc = true;
|
||||
if (toCopy.isMouseClick())
|
||||
setMouseButtons(toCopy.getMouseButtons());
|
||||
else
|
||||
else {
|
||||
setKeyEvent(toCopy.getKeyEvent());
|
||||
setKeySym(toCopy.getKeySym());
|
||||
}
|
||||
setMetaListId(toCopy.getMetaListId());
|
||||
setMetaFlags(toCopy.getMetaFlags());
|
||||
}
|
||||
@@ -180,7 +182,7 @@ class MetaKeyBean extends AbstractMetaKeyBean implements Comparable<MetaKeyBean>
|
||||
if (isMouseClick())
|
||||
base=keysByMouseButton.get(getMouseButtons());
|
||||
else
|
||||
base=keysByKeySym.get(getKeySym());
|
||||
base=keysByKeyCode.get(getKeyEvent());
|
||||
sb.append(base.name);
|
||||
setKeyDesc(sb.toString());
|
||||
}
|
||||
@@ -198,6 +200,19 @@ class MetaKeyBean extends AbstractMetaKeyBean implements Comparable<MetaKeyBean>
|
||||
_regenDesc = false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.androidVNC.AbstractMetaKeyBean#setKeySym(int)
|
||||
*/
|
||||
@Override
|
||||
public void setKeyEvent(int arg_keyEvent) {
|
||||
if (arg_keyEvent!=getKeyEvent() || isMouseClick())
|
||||
{
|
||||
setMouseClick(false);
|
||||
_regenDesc=true;
|
||||
super.setKeyEvent(arg_keyEvent);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.androidVNC.AbstractMetaKeyBean#setKeySym(int)
|
||||
*/
|
||||
@@ -238,12 +253,10 @@ class MetaKeyBean extends AbstractMetaKeyBean implements Comparable<MetaKeyBean>
|
||||
|
||||
void setKeyBase(MetaKeyBase base)
|
||||
{
|
||||
if (base.isMouse)
|
||||
{
|
||||
if (base.isMouse) {
|
||||
setMouseButtons(base.mouseButtons);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
setKeyEvent(base.keyEvent);
|
||||
setKeySym(base.keySym);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -540,7 +540,7 @@ class MetaKeyDialog extends Dialog implements ConnectionSettable {
|
||||
{
|
||||
base = MetaKeyBean.keysByMouseButton.get(_currentKeyBean.getMouseButtons());
|
||||
} else {
|
||||
base = MetaKeyBean.keysByKeySym.get(_currentKeyBean.getKeySym());
|
||||
base = MetaKeyBean.keysByKeyCode.get(_currentKeyBean.getKeyEvent());
|
||||
}
|
||||
if (base != null) {
|
||||
int index = Collections.binarySearch(MetaKeyBean.allKeys,base);
|
||||
|
||||
@@ -130,13 +130,16 @@ public class VncCanvas extends ImageView {
|
||||
handleRREPaint = new Paint();
|
||||
handleRREPaint.setStyle(Style.FILL);
|
||||
}
|
||||
/*
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
Toast.makeText(getContext(), "x=" + event.getX() + ",y=" + event.getY() + ",event=" + MotionEvent.actionToString(event.getAction()), Toast.LENGTH_SHORT).show();
|
||||
return super.onTouchEvent(event);
|
||||
if (vncActivity.inputHandler == null) {
|
||||
return super.onTouchEvent(event);
|
||||
} else {
|
||||
return vncActivity.inputHandler.onTouchEvent(event);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Create a view showing a VNC connection
|
||||
* @param context Containing context (activity)
|
||||
@@ -944,6 +947,16 @@ public class VncCanvas extends ImageView {
|
||||
maintainConnection = false;
|
||||
}
|
||||
|
||||
void sendKeyboardKey(MetaKeyBean meta, boolean down) {
|
||||
try {
|
||||
rfb.writeKeyEvent(meta.getKeySym(), meta.getMetaFlags(), down);
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
ioe.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
void sendMetaKey(MetaKeyBean meta)
|
||||
{
|
||||
if (meta.isMouseClick())
|
||||
|
||||
@@ -45,6 +45,8 @@ import net.kdt.pojavlaunch.prefs.*;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import com.theqvd.android.xpro.Config;
|
||||
import net.kdt.pojavlaunch.value.customcontrols.*;
|
||||
import com.google.gson.*;
|
||||
|
||||
public class VncCanvasActivity extends AppCompatActivity
|
||||
{
|
||||
@@ -83,12 +85,15 @@ public class VncCanvasActivity extends AppCompatActivity
|
||||
private TextView textLog;
|
||||
private ScrollView contentScroll;
|
||||
private ToggleButton toggleLog;
|
||||
private ControlsLayout mControlLayout;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
|
||||
super.onCreate(icicle);
|
||||
|
||||
MetaKeyBean.initStatic();
|
||||
|
||||
mProfile = PojavProfile.getCurrentProfileContent(this);
|
||||
mVersionInfo = Tools.getVersionInfo(mProfile.getVersion());
|
||||
|
||||
@@ -97,6 +102,34 @@ public class VncCanvasActivity extends AppCompatActivity
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
|
||||
setContentView(R.layout.canvas);
|
||||
|
||||
mControlLayout = findViewById(R.id.main_controllayout);
|
||||
mControlLayout.loadLayout(getSharedPreferences(getPackageName() + "_preferences", Context.MODE_PRIVATE).getString("defaultCtrl", Tools.CTRLMAP_PATH + "/default.json"));
|
||||
mControlLayout.setupKeyEvent(new ControlsLayout.ControlListener(){
|
||||
@Override
|
||||
public void onKey(MetaKeyBase vncKey, boolean down)
|
||||
{
|
||||
vncCanvas.sendKeyboardKey(new MetaKeyBean(0, 0, vncKey), down);
|
||||
}
|
||||
});
|
||||
|
||||
ControlButton[] specialButtons = ControlButton.getSpecialButtons();
|
||||
specialButtons[0].specialButtonListener = new View.OnClickListener(){
|
||||
|
||||
@Override
|
||||
public void onClick(View p1)
|
||||
{
|
||||
// showKeyboard();
|
||||
}
|
||||
};
|
||||
specialButtons[1].specialButtonListener = new View.OnClickListener(){
|
||||
|
||||
@Override
|
||||
public void onClick(View view)
|
||||
{
|
||||
// MainActivity.this.onClick(toggleControlButton);
|
||||
}
|
||||
};
|
||||
|
||||
database = new VncDatabase(VncCanvasActivity.this);
|
||||
connection = new ConnectionBean();
|
||||
@@ -399,7 +432,7 @@ public class VncCanvasActivity extends AppCompatActivity
|
||||
});
|
||||
|
||||
panner = new Panner(VncCanvasActivity.this, vncCanvas.handler);
|
||||
inputHandler = getInputHandlerById(R.id.itemInputMouse);
|
||||
inputHandler = getInputHandlerById(R.id.itemInputTouchpad);
|
||||
}
|
||||
}, 200);
|
||||
}
|
||||
@@ -489,6 +522,7 @@ public class VncCanvasActivity extends AppCompatActivity
|
||||
mJavaProcess.writeToProcess("export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/minecraft_lib/lwjgl" + (isLwjgl3 ? "3" : "2"));
|
||||
mJavaProcess.writeToProcess("echo \"Running Minecraft: " + fromStringArray(mJreArgs.toArray(new String[0])) + "\"");
|
||||
mJavaProcess.writeToProcess(mJreArgs.toArray(new String[0]));
|
||||
mJavaProcess.writeToProcess("exit");
|
||||
} catch (Throwable th) {
|
||||
th.printStackTrace();
|
||||
Tools.showError(this, th);
|
||||
@@ -798,11 +832,6 @@ public class VncCanvasActivity extends AppCompatActivity
|
||||
return inputHandler.onTrackballEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
return inputHandler.onTouchEvent(event);
|
||||
}
|
||||
|
||||
private void selectColorModel() {
|
||||
// Stop repainting the desktop
|
||||
// because the display is composited!
|
||||
|
||||
@@ -127,7 +127,7 @@ public class ActionPopupWindow extends PinnedPopupWindow implements OnClickListe
|
||||
final EditText editName = dialog.findViewById(R.id.controlsetting_edit_name);
|
||||
editName.setText(properties.name);
|
||||
|
||||
final Spinner spinnerKeycode = dialog.findViewById(R.id.controlsetting_spinner_lwjglkeycode);
|
||||
final Spinner spinnerKeycode = dialog.findViewById(R.id.controlsetting_spinner_keycode);
|
||||
ArrayAdapter<String> adapter = new ArrayAdapter<String>(view.getContext(), android.R.layout.simple_spinner_item);
|
||||
|
||||
String[] oldSpecialArr = ControlButton.buildSpecialButtonArray();
|
||||
@@ -137,13 +137,13 @@ public class ActionPopupWindow extends PinnedPopupWindow implements OnClickListe
|
||||
}
|
||||
|
||||
adapter.addAll(specialArr);
|
||||
adapter.addAll(AndroidLWJGLKeycode.generateKeyName());
|
||||
adapter.addAll(Android2LWJGLKeycode.generateKeyName());
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_list_item_single_choice);
|
||||
spinnerKeycode.setAdapter(adapter);
|
||||
if (properties.lwjglKeycode < 0) {
|
||||
spinnerKeycode.setSelection(properties.lwjglKeycode + 2);
|
||||
if (properties.keycode < 0) {
|
||||
spinnerKeycode.setSelection(properties.keyindex);
|
||||
} else {
|
||||
spinnerKeycode.setSelection(AndroidLWJGLKeycode.getIndexByLWJGLKey(properties.lwjglKeycode + 2));
|
||||
spinnerKeycode.setSelection(Android2LWJGLKeycode.getIndexByLWJGLKey(properties.keyindex + 2));
|
||||
}
|
||||
spinnerKeycode.setOnItemSelectedListener(new Spinner.OnItemSelectedListener(){
|
||||
|
||||
@@ -169,12 +169,13 @@ public class ActionPopupWindow extends PinnedPopupWindow implements OnClickListe
|
||||
if (editName.getText().toString().isEmpty()) {
|
||||
editName.setError(view.getResources().getString(R.string.global_error_field_empty));
|
||||
} else {
|
||||
properties.lwjglKeycode = AndroidLWJGLKeycode.getKeyIndex(spinnerKeycode.getSelectedItemPosition()) - 2;
|
||||
properties.keycode = Android2LWJGLKeycode.getKeyIndex(spinnerKeycode.getSelectedItemPosition()) - 2;
|
||||
properties.name = editName.getText().toString();
|
||||
if (properties.lwjglKeycode < 0) {
|
||||
properties.name = ControlButton.getSpecialButtons()[properties.lwjglKeycode + 2].name;
|
||||
if (properties.keycode < 0) {
|
||||
properties.name = ControlButton.getSpecialButtons()[properties.keycode + 2].name;
|
||||
}
|
||||
properties.hidden = checkHidden.isChecked();
|
||||
properties.keyindex = spinnerKeycode.getSelectedItemPosition();
|
||||
|
||||
mHandleView.mView.updateProperties();
|
||||
mHandleView.mView.setModified(true);
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.*;
|
||||
import org.lwjgl.input.*;
|
||||
import org.lwjgl.opengl.*;
|
||||
|
||||
public class AndroidLWJGLKeycode {
|
||||
public class Android2LWJGLKeycode {
|
||||
// Fix double letters on MC 1.9 and above
|
||||
public static boolean isBackspaceAfterChar;
|
||||
private static final ArrayMap<Integer, Integer> androidToLwjglMap;
|
||||
@@ -207,7 +207,7 @@ public class AndroidLWJGLKeycode {
|
||||
}
|
||||
|
||||
public static int getKeyIndex(int index) {
|
||||
return androidToLwjglMap.valueAt(index);
|
||||
return androidToLwjglMap.keyAt(index);
|
||||
}
|
||||
|
||||
public static int getIndexByLWJGLKey(int lwjglKey) {
|
||||
@@ -21,6 +21,8 @@ public class CustomControlsActivity extends AppCompatActivity
|
||||
private ControlsLayout ctrlLayout;
|
||||
private CustomControls mCtrl;
|
||||
|
||||
private SharedPreferences mPref;
|
||||
|
||||
public boolean isModified = false;
|
||||
|
||||
private Gson gson;
|
||||
@@ -31,6 +33,8 @@ public class CustomControlsActivity extends AppCompatActivity
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.control_mapping);
|
||||
|
||||
mPref = getSharedPreferences(getPackageName() + "_preferences", Context.MODE_PRIVATE);
|
||||
|
||||
gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
|
||||
// Menu
|
||||
@@ -63,7 +67,17 @@ public class CustomControlsActivity extends AppCompatActivity
|
||||
});
|
||||
|
||||
mCtrl = new CustomControls();
|
||||
generateDefaultControlMap();
|
||||
String defaultControl = mPref.getString("defaultCtrl", "");
|
||||
if (defaultControl.isEmpty() || defaultControl.endsWith("/default.json")) {
|
||||
generateDefaultControlMap();
|
||||
try {
|
||||
doSaveCtrl("default");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
loadControl(defaultControl);
|
||||
}
|
||||
|
||||
ctrlLayout = (ControlsLayout) findViewById(R.id.customctrl_controllayout);
|
||||
ctrlLayout.setActivity(this);
|
||||
@@ -81,8 +95,37 @@ public class CustomControlsActivity extends AppCompatActivity
|
||||
save(true);
|
||||
}
|
||||
|
||||
private void setDefaultControlJson(String path) {
|
||||
mPref.edit().putString("defaultCtrl", path).commit();
|
||||
}
|
||||
|
||||
private void dialogSelectDefaultCtrl() {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(R.string.customctrl_selectdefault);
|
||||
builder.setPositiveButton(android.R.string.cancel, null);
|
||||
|
||||
final AlertDialog dialog = builder.create();
|
||||
FileListView flv = new FileListView(this);
|
||||
flv.listFileAt(Tools.CTRLMAP_PATH);
|
||||
flv.setFileSelectedListener(new FileSelectedListener(){
|
||||
|
||||
@Override
|
||||
public void onFileSelected(File file, String path, String name) {
|
||||
if (name.endsWith(".json")) {
|
||||
setDefaultControlJson(path);
|
||||
dialog.dismiss();
|
||||
}
|
||||
}
|
||||
});
|
||||
dialog.setView(flv);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private String doSaveCtrl(String name) throws Exception {
|
||||
String jsonPath = Tools.CTRLMAP_PATH + "/" + name + ".json";
|
||||
ctrlLayout.saveLayout(jsonPath);
|
||||
|
||||
return jsonPath;
|
||||
}
|
||||
|
||||
private void save(final boolean exit) {
|
||||
@@ -118,9 +161,9 @@ public class CustomControlsActivity extends AppCompatActivity
|
||||
edit.setError(getResources().getString(R.string.global_error_field_empty));
|
||||
} else {
|
||||
try {
|
||||
ctrlLayout.saveLayout(Tools.CTRLMAP_PATH + "/" + edit.getText().toString() + ".json");
|
||||
String jsonPath = doSaveCtrl(edit.getText().toString());
|
||||
|
||||
Toast.makeText(CustomControlsActivity.this, getString(R.string.global_save) + ": " + getString(android.R.string.ok), Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(CustomControlsActivity.this, getString(R.string.global_save) + ": " + jsonPath, Toast.LENGTH_SHORT).show();
|
||||
|
||||
dialog.dismiss();
|
||||
if (exit) {
|
||||
@@ -140,7 +183,7 @@ public class CustomControlsActivity extends AppCompatActivity
|
||||
|
||||
private void actionLoad() {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle("Select control json file");
|
||||
builder.setTitle(R.string.customctrl_title_selectctrl);
|
||||
builder.setPositiveButton(android.R.string.cancel, null);
|
||||
|
||||
final AlertDialog dialog = builder.create();
|
||||
@@ -151,7 +194,7 @@ public class CustomControlsActivity extends AppCompatActivity
|
||||
@Override
|
||||
public void onFileSelected(File file, String path, String name) {
|
||||
if (name.endsWith(".json")) {
|
||||
loadControl(path, name);
|
||||
loadControl(path);
|
||||
dialog.dismiss();
|
||||
}
|
||||
}
|
||||
@@ -160,12 +203,14 @@ public class CustomControlsActivity extends AppCompatActivity
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private void loadControl(String path, String name) {
|
||||
private void loadControl(String path) {
|
||||
try {
|
||||
selectedName = name;
|
||||
|
||||
mCtrl = gson.fromJson(Tools.read(path), CustomControls.class);
|
||||
ctrlLayout.loadLayout(mCtrl);
|
||||
|
||||
selectedName = new File(path).getName();
|
||||
// Remove `.json`
|
||||
selectedName = selectedName.substring(0, selectedName.length() - 5);
|
||||
} catch (Exception e) {
|
||||
Tools.showError(CustomControlsActivity.this, e);
|
||||
}
|
||||
|
||||
@@ -304,7 +304,7 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
|
||||
onClick(toggleControlButton);
|
||||
this.drawerLayout.closeDrawers();
|
||||
|
||||
AndroidLWJGLKeycode.isBackspaceAfterChar = mVersionInfo.minimumLauncherVersion >= 18;
|
||||
Android2LWJGLKeycode.isBackspaceAfterChar = mVersionInfo.minimumLauncherVersion >= 18;
|
||||
|
||||
placeMouseAt(AndroidDisplay.windowWidth / 2, AndroidDisplay.windowHeight / 2);
|
||||
new Thread(new Runnable(){
|
||||
@@ -709,14 +709,14 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
|
||||
@Override
|
||||
public boolean onKeyUp(int keyCode, KeyEvent event)
|
||||
{
|
||||
AndroidLWJGLKeycode.execKey(this, event, keyCode, false);
|
||||
Android2LWJGLKeycode.execKey(this, event, keyCode, false);
|
||||
return super.onKeyUp(keyCode, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event)
|
||||
{
|
||||
AndroidLWJGLKeycode.execKey(this, event, keyCode, true);
|
||||
Android2LWJGLKeycode.execKey(this, event, keyCode, true);
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
@@ -1059,11 +1059,11 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
|
||||
private void dialogSendCustomKey() {
|
||||
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
|
||||
dialog.setTitle(R.string.control_customkey);
|
||||
dialog.setItems(AndroidLWJGLKeycode.generateKeyName(), new DialogInterface.OnClickListener(){
|
||||
dialog.setItems(Android2LWJGLKeycode.generateKeyName(), new DialogInterface.OnClickListener(){
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dInterface, int position) {
|
||||
AndroidLWJGLKeycode.execKeyIndex(MainActivity.this, position);
|
||||
Android2LWJGLKeycode.execKeyIndex(MainActivity.this, position);
|
||||
}
|
||||
});
|
||||
dialog.show();
|
||||
|
||||
@@ -48,7 +48,8 @@ public class ControlButton implements Cloneable
|
||||
public float y;
|
||||
public int width = pixelOf50dp;
|
||||
public int height = pixelOf50dp;
|
||||
public int lwjglKeycode;
|
||||
public int keycode;
|
||||
public int keyindex;
|
||||
public boolean hidden;
|
||||
public boolean holdCtrl;
|
||||
public boolean holdAlt;
|
||||
@@ -60,25 +61,25 @@ public class ControlButton implements Cloneable
|
||||
this("", Keyboard.CHAR_NONE, 0, 0);
|
||||
}
|
||||
|
||||
public ControlButton(String name, int lwjglKeycode) {
|
||||
this(name, lwjglKeycode, 0, 0);
|
||||
public ControlButton(String name, int keycode) {
|
||||
this(name, keycode, 0, 0);
|
||||
}
|
||||
|
||||
public ControlButton(String name, int lwjglKeycode, float x, float y) {
|
||||
this(name, lwjglKeycode, x, y, pixelOf50dp, pixelOf50dp);
|
||||
public ControlButton(String name, int keycode, float x, float y) {
|
||||
this(name, keycode, x, y, pixelOf50dp, pixelOf50dp);
|
||||
}
|
||||
|
||||
public ControlButton(android.content.Context ctx, int resId, int lwjglKeycode, float x, float y, boolean isSquare) {
|
||||
this(ctx.getResources().getString(resId), lwjglKeycode, x, y, isSquare ? pixelOf50dp : pixelOf80dp, isSquare ? pixelOf50dp : pixelOf30dp);
|
||||
public ControlButton(android.content.Context ctx, int resId, int keycode, float x, float y, boolean isSquare) {
|
||||
this(ctx.getResources().getString(resId), keycode, x, y, isSquare ? pixelOf50dp : pixelOf80dp, isSquare ? pixelOf50dp : pixelOf30dp);
|
||||
}
|
||||
|
||||
public ControlButton(String name, int lwjglKeycode, float x, float y, boolean isSquare) {
|
||||
this(name, lwjglKeycode, x, y, isSquare ? pixelOf50dp : pixelOf80dp, isSquare ? pixelOf50dp : pixelOf30dp);
|
||||
public ControlButton(String name, int keycode, float x, float y, boolean isSquare) {
|
||||
this(name, keycode, x, y, isSquare ? pixelOf50dp : pixelOf80dp, isSquare ? pixelOf50dp : pixelOf30dp);
|
||||
}
|
||||
|
||||
public ControlButton(String name, int lwjglKeycode, float x, float y, int width, int height) {
|
||||
public ControlButton(String name, int keycode, float x, float y, int width, int height) {
|
||||
this.name = name;
|
||||
this.lwjglKeycode = lwjglKeycode;
|
||||
this.keycode = keycode;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
@@ -86,10 +87,10 @@ public class ControlButton implements Cloneable
|
||||
}
|
||||
|
||||
public void execute(MainActivity act, boolean isDown) {
|
||||
act.sendKeyPress(lwjglKeycode, isDown);
|
||||
act.sendKeyPress(keycode, isDown);
|
||||
}
|
||||
|
||||
public ControlButton clone() {
|
||||
return new ControlButton(name, lwjglKeycode, x, y, width, height);
|
||||
return new ControlButton(name, keycode, x, y, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ public class ControlView extends Button implements OnLongClickListener, OnTouchL
|
||||
@Override
|
||||
public boolean onLongClick(View p1)
|
||||
{
|
||||
if (!mCanTriggerLongClick) return false;
|
||||
if (!mCanTriggerLongClick || !mCanModify) return false;
|
||||
|
||||
if (mHandleView.isShowing()) {
|
||||
mHandleView.hide();
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.view.*;
|
||||
import com.google.gson.*;
|
||||
import net.kdt.pojavlaunch.*;
|
||||
import android.support.v7.app.*;
|
||||
import android.androidVNC.*;
|
||||
|
||||
public class ControlsLayout extends FrameLayout
|
||||
{
|
||||
@@ -29,6 +30,14 @@ public class ControlsLayout extends FrameLayout
|
||||
}
|
||||
}
|
||||
|
||||
public void loadLayout(String jsonPath) {
|
||||
try {
|
||||
loadLayout(new Gson().fromJson(Tools.read(jsonPath), CustomControls.class));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void loadLayout(CustomControls controlLayout) {
|
||||
mLayout = controlLayout;
|
||||
removeAllViews();
|
||||
@@ -38,6 +47,35 @@ public class ControlsLayout extends FrameLayout
|
||||
|
||||
setModified(false);
|
||||
}
|
||||
|
||||
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(){
|
||||
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent event)
|
||||
{
|
||||
boolean isDown = false;
|
||||
switch (event.getActionMasked()) {
|
||||
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) {
|
||||
listener.onKey(key, isDown);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addControlButton(ControlButton controlButton) {
|
||||
mLayout.button.add(controlButton);
|
||||
@@ -82,4 +120,8 @@ public class ControlsLayout extends FrameLayout
|
||||
private void setModified(boolean z) {
|
||||
if (mActivity != null) mActivity.isModified = z;
|
||||
}
|
||||
|
||||
public static interface ControlListener {
|
||||
public void onKey(MetaKeyBase vncKey, boolean down);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,13 @@
|
||||
android:id="@+id/zoomer"
|
||||
android:layout_gravity="bottom|center"/>
|
||||
|
||||
<net.kdt.pojavlaunch.value.customcontrols.ControlsLayout
|
||||
android:id="@+id/main_controllayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
</net.kdt.pojavlaunch.value.customcontrols.ControlsLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:animateLayoutChanges="true"
|
||||
android:id="@+id/content_log_layout"
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<Spinner
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:id="@+id/controlsetting_spinner_lwjglkeycode"/>
|
||||
android:id="@+id/controlsetting_spinner_keycode"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
@@ -13,5 +13,5 @@
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_ctrl_selectdefault"
|
||||
android:title="@string/customctrl_seleftdefault"/>
|
||||
android:title="@string/customctrl_selectdefault"/>
|
||||
</menu>
|
||||
|
||||
@@ -184,11 +184,12 @@
|
||||
<string name="control_more3"></string>
|
||||
<string name="control_more4"></string>
|
||||
|
||||
<string name="customctrl_keyname">LWJGL Keycode</string>
|
||||
<string name="customctrl_keyname">Keycode</string>
|
||||
<string name="customctrl_specialkey">Special Key</string>
|
||||
<string name="customctrl_hidden">Hidden</string>
|
||||
<string name="customctrl_addbutton">Add button</string>
|
||||
<string name="customctrl_seleftdefault">Select default Control json</string>
|
||||
<string name="customctrl_title_selectctrl">Select default Control json</string>
|
||||
<string name="customctrl_selectdefault">Select default Control json</string>
|
||||
|
||||
<!-- Update part (unused now) -->
|
||||
<string name="update_console">Update console</string>
|
||||
|
||||
Reference in New Issue
Block a user