Clean up some code

This commit is contained in:
SerpentSpirale 2021-05-22 15:49:04 +02:00 committed by SerpentSpirale
parent 2fa4a2756e
commit 62ac772904
2 changed files with 111 additions and 344 deletions

View File

@ -21,7 +21,6 @@ import net.kdt.pojavlaunch.customcontrols.*;
import net.kdt.pojavlaunch.multirt.MultiRTUtils; import net.kdt.pojavlaunch.multirt.MultiRTUtils;
import net.kdt.pojavlaunch.customcontrols.gamepad.Gamepad; import net.kdt.pojavlaunch.customcontrols.gamepad.Gamepad;
import net.kdt.pojavlaunch.customcontrols.gamepad.GamepadJoystick;
import net.kdt.pojavlaunch.prefs.*; import net.kdt.pojavlaunch.prefs.*;
import net.kdt.pojavlaunch.utils.*; import net.kdt.pojavlaunch.utils.*;
@ -42,14 +41,14 @@ public class BaseMainActivity extends LoggableActivity {
private boolean rightOverride = false; private boolean rightOverride = false;
public float scaleFactor = 1; public float scaleFactor = 1;
private int fingerStillThreshold = 8; private final int fingerStillThreshold = 8;
private int initialX, initialY; private int initialX, initialY;
private int scrollInitialX, scrollInitialY; private int scrollInitialX, scrollInitialY;
private boolean mIsResuming = false; private boolean mIsResuming = false;
private static final int MSG_LEFT_MOUSE_BUTTON_CHECK = 1028; private static final int MSG_LEFT_MOUSE_BUTTON_CHECK = 1028;
private static final int MSG_DROP_ITEM_BUTTON_CHECK = 1029; private static final int MSG_DROP_ITEM_BUTTON_CHECK = 1029;
private static boolean triggeredLeftMouseButton = false; private static boolean triggeredLeftMouseButton = false;
private Handler theHandler = new Handler() { private final Handler theHandler = new Handler() {
public void handleMessage(Message msg) { public void handleMessage(Message msg) {
if (!LauncherPreferences.PREF_DISABLE_GESTURES) { if (!LauncherPreferences.PREF_DISABLE_GESTURES) {
switch (msg.what) { switch (msg.what) {
@ -79,15 +78,11 @@ public class BaseMainActivity extends LoggableActivity {
private boolean isVirtualMouseEnabled; private boolean isVirtualMouseEnabled;
private LinearLayout touchPad; private LinearLayout touchPad;
private ImageView mousePointer; private ImageView mousePointer;
//private EditText hiddenEditor;
// private ViewGroup overlayView;
private MinecraftAccount mProfile; private MinecraftAccount mProfile;
private DrawerLayout drawerLayout; private DrawerLayout drawerLayout;
private NavigationView navDrawer; private NavigationView navDrawer;
// protected CapturedEditText mKeyHandlerView;
private LinearLayout contentLog; private LinearLayout contentLog;
private TextView textLog; private TextView textLog;
private ScrollView contentScroll; private ScrollView contentScroll;
@ -97,7 +92,6 @@ public class BaseMainActivity extends LoggableActivity {
private TextView debugText; private TextView debugText;
private NavigationView.OnNavigationItemSelectedListener gameActionListener; private NavigationView.OnNavigationItemSelectedListener gameActionListener;
public NavigationView.OnNavigationItemSelectedListener ingameControlsEditorListener; public NavigationView.OnNavigationItemSelectedListener ingameControlsEditorListener;
// private String mQueueText = new String();
protected volatile JMinecraftVersionList.Version mVersionInfo; protected volatile JMinecraftVersionList.Version mVersionInfo;
@ -106,22 +100,13 @@ public class BaseMainActivity extends LoggableActivity {
private File logFile; private File logFile;
private PrintStream logStream; private PrintStream logStream;
private PerVersionConfig.VersionConfig config; private PerVersionConfig.VersionConfig config;
/* private final boolean lastEnabled = false;
private LinearLayout contentCanvas;
private AWTSurfaceView contentCanvasView;
*/
private boolean resuming;
private boolean lastEnabled = false;
private boolean lastGrab = false; private boolean lastGrab = false;
private boolean isExited = false; private final boolean isExited = false;
private boolean isLogAllow = false; private boolean isLogAllow = false;
public volatile int mouse_x, mouse_y; public volatile int mouse_x, mouse_y;
// private int navBarHeight = 40;
// private static Collection<? extends Provider.Service> rsaPkcs1List;
// @Override // @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -172,50 +157,36 @@ public class BaseMainActivity extends LoggableActivity {
drawerLayout = findViewById(R.id.main_drawer_options); drawerLayout = findViewById(R.id.main_drawer_options);
navDrawer = findViewById(R.id.main_navigation_view); navDrawer = findViewById(R.id.main_navigation_view);
gameActionListener = new NavigationView.OnNavigationItemSelectedListener() { gameActionListener = menuItem -> {
@Override switch (menuItem.getItemId()) {
public boolean onNavigationItemSelected(MenuItem menuItem) { case R.id.nav_forceclose: dialogForceClose(BaseMainActivity.this);
switch (menuItem.getItemId()) { break;
case R.id.nav_forceclose: dialogForceClose(BaseMainActivity.this); case R.id.nav_viewlog: openLogOutput();
break; break;
case R.id.nav_viewlog: openLogOutput(); case R.id.nav_debug: toggleDebug();
break; break;
case R.id.nav_debug: toggleDebug(); case R.id.nav_customkey: dialogSendCustomKey();
break; break;
case R.id.nav_customkey: dialogSendCustomKey(); case R.id.nav_mousespd: adjustMouseSpeedLive();
break; break;
case R.id.nav_mousespd: adjustMouseSpeedLive(); case R.id.nav_customctrl: openCustomControls();
break; break;
case R.id.nav_customctrl: openCustomControls();
break;
}
//Toast.makeText(MainActivity.this, menuItem.getTitle() + ":" + menuItem.getItemId(), Toast.LENGTH_SHORT).show();
drawerLayout.closeDrawers();
return true;
} }
drawerLayout.closeDrawers();
return true;
}; };
navDrawer.setNavigationItemSelectedListener( navDrawer.setNavigationItemSelectedListener(
gameActionListener); gameActionListener);
// this.overlayView = (ViewGroup) findViewById(R.id.main_control_overlay);
//this.hiddenEditor = findViewById(R.id.hiddenTextbox);
// Mouse pointer part
//this.mouseToggleButton = findButton(R.id.control_togglemouse);
this.touchPad = findViewById(R.id.main_touchpad); this.touchPad = findViewById(R.id.main_touchpad);
touchPad.setFocusable(false); touchPad.setFocusable(false);
this.mousePointer = findViewById(R.id.main_mouse_pointer); this.mousePointer = findViewById(R.id.main_mouse_pointer);
this.mousePointer.post(new Runnable(){ this.mousePointer.post(() -> {
ViewGroup.LayoutParams params = mousePointer.getLayoutParams();
@Override params.width = (int) (36 / 100f * LauncherPreferences.PREF_MOUSESCALE);
public void run() { params.height = (int) (54 / 100f * LauncherPreferences.PREF_MOUSESCALE);
ViewGroup.LayoutParams params = mousePointer.getLayoutParams();
params.width = (int) (36 / 100f * LauncherPreferences.PREF_MOUSESCALE);
params.height = (int) (54 / 100f * LauncherPreferences.PREF_MOUSESCALE);
}
}); });
this.contentLog = findViewById(R.id.content_log_layout); this.contentLog = findViewById(R.id.content_log_layout);
@ -223,63 +194,37 @@ public class BaseMainActivity extends LoggableActivity {
this.textLog = (TextView) contentScroll.getChildAt(0); this.textLog = (TextView) contentScroll.getChildAt(0);
this.toggleLog = findViewById(R.id.content_log_toggle_log); this.toggleLog = findViewById(R.id.content_log_toggle_log);
this.toggleLog.setChecked(false); this.toggleLog.setChecked(false);
// this.textLogBehindGL = (TextView) findViewById(R.id.main_log_behind_GL);
// this.textLogBehindGL.setTypeface(Typeface.MONOSPACE);
this.textLog.setTypeface(Typeface.MONOSPACE); this.textLog.setTypeface(Typeface.MONOSPACE);
this.toggleLog.setOnCheckedChangeListener(new ToggleButton.OnCheckedChangeListener(){ this.toggleLog.setOnCheckedChangeListener((button, isChecked) -> {
isLogAllow = isChecked;
@Override appendToLog("");
public void onCheckedChanged(CompoundButton button, boolean isChecked) });
{
isLogAllow = isChecked;
appendToLog("");
}
});
this.debugText = findViewById(R.id.content_text_debug); this.debugText = findViewById(R.id.content_text_debug);
this.minecraftGLView = findViewById(R.id.main_game_render_view); this.minecraftGLView = findViewById(R.id.main_game_render_view);
// toggleGui(null);
this.drawerLayout.closeDrawers(); this.drawerLayout.closeDrawers();
/*
mKeyHandlerView = findViewById(R.id.main_key_handler);
mKeyHandlerView.setSingleLine(false);
mKeyHandlerView.clearFocus();
AndroidLWJGLKeycode.isBackspaceAfterChar = true; // mVersionInfo.minimumLauncherVersion >= 18;
*/
placeMouseAt(CallbackBridge.physicalWidth / 2, CallbackBridge.physicalHeight / 2); placeMouseAt(CallbackBridge.physicalWidth / 2, CallbackBridge.physicalHeight / 2);
new Thread(new Runnable(){ new Thread(() -> {
while (!isExited) {
//private boolean isCapturing = false; if (lastGrab != CallbackBridge.isGrabbing())
@Override mousePointer.post(() -> {
public void run() if (!CallbackBridge.isGrabbing() && isVirtualMouseEnabled) {
{ touchPad.setVisibility(View.VISIBLE);
while (!isExited) { placeMouseAt(displayMetrics.widthPixels / 2, displayMetrics.heightPixels / 2);
if (lastGrab != CallbackBridge.isGrabbing())
mousePointer.post(new Runnable(){
@Override
public void run()
{
if (!CallbackBridge.isGrabbing() && isVirtualMouseEnabled) {
touchPad.setVisibility(View.VISIBLE);
placeMouseAt(displayMetrics.widthPixels / 2, displayMetrics.heightPixels / 2);
}
if (CallbackBridge.isGrabbing() && touchPad.getVisibility() != View.GONE) {
touchPad.setVisibility(View.GONE);
}
lastGrab = CallbackBridge.isGrabbing();
}
});
} }
}
}, "VirtualMouseGrabThread").start(); if (CallbackBridge.isGrabbing() && touchPad.getVisibility() != View.GONE) {
touchPad.setVisibility(View.GONE);
}
lastGrab = CallbackBridge.isGrabbing();
});
}
}, "VirtualMouseGrabThread").start();
if (isAndroid8OrHigher()) { if (isAndroid8OrHigher()) {
@ -372,7 +317,6 @@ public class BaseMainActivity extends LoggableActivity {
// System.loadLibrary("Regal"); // System.loadLibrary("Regal");
minecraftGLView.setFocusable(true); minecraftGLView.setFocusable(true);
// minecraftGLView.setEGLContextClientVersion(2);
glTouchListener = new OnTouchListener(){ glTouchListener = new OnTouchListener(){
private boolean isTouchInHotbar = false; private boolean isTouchInHotbar = false;
private int hotbarX, hotbarY; private int hotbarX, hotbarY;
@ -401,8 +345,7 @@ public class BaseMainActivity extends LoggableActivity {
} }
// System.out.println("Pre touch, isTouchInHotbar=" + Boolean.toString(isTouchInHotbar) + ", action=" + MotionEvent.actionToString(e.getActionMasked())); // System.out.println("Pre touch, isTouchInHotbar=" + Boolean.toString(isTouchInHotbar) + ", action=" + MotionEvent.actionToString(e.getActionMasked()));
/* int x = ((int) e.getX()) * scaleFactor;
int y = ((int) e.getY()) * scaleFactor;*/
if(e.getHistorySize() > 0 && CallbackBridge.isGrabbing()) { if(e.getHistorySize() > 0 && CallbackBridge.isGrabbing()) {
mouse_x += (int)(e.getX() - e.getHistoricalX(0)); mouse_x += (int)(e.getX() - e.getHistoricalX(0));
mouse_y += (int)(e.getY() - e.getHistoricalY(0)); mouse_y += (int)(e.getY() - e.getHistoricalY(0));
@ -444,7 +387,6 @@ public class BaseMainActivity extends LoggableActivity {
if (CallbackBridge.isGrabbing()) { if (CallbackBridge.isGrabbing()) {
// It cause hold left mouse while moving camera // It cause hold left mouse while moving camera
// CallbackBridge.putMouseEventWithCoords(rightOverride ? (byte) 1 : (byte) 0, (byte) 1, x, y);
initialX = mouse_x; initialX = mouse_x;
initialY = mouse_y; initialY = mouse_y;
theHandler.sendEmptyMessageDelayed(BaseMainActivity.MSG_LEFT_MOUSE_BUTTON_CHECK, LauncherPreferences.PREF_LONGPRESS_TRIGGER); theHandler.sendEmptyMessageDelayed(BaseMainActivity.MSG_LEFT_MOUSE_BUTTON_CHECK, LauncherPreferences.PREF_LONGPRESS_TRIGGER);
@ -459,7 +401,6 @@ public class BaseMainActivity extends LoggableActivity {
CallbackBridge.mouseY = mouse_y; CallbackBridge.mouseY = mouse_y;
// -TODO uncomment after fix wrong trigger // -TODO uncomment after fix wrong trigger
// CallbackBridge.putMouseEventWithCoords(rightOverride ? (byte) 1 : (byte) 0, (byte) 0, x, y);
CallbackBridge.sendCursorPos(mouse_x, mouse_y); CallbackBridge.sendCursorPos(mouse_x, mouse_y);
if (!rightOverride) { if (!rightOverride) {
CallbackBridge.mouseLeft = false; CallbackBridge.mouseLeft = false;
@ -467,8 +408,6 @@ public class BaseMainActivity extends LoggableActivity {
} }
if (CallbackBridge.isGrabbing()) { if (CallbackBridge.isGrabbing()) {
// System.out.println((String) ("[Math.abs(" + initialX + " - " + x + ") = " + Math.abs(initialX - x) + "] < " + fingerStillThreshold));
// System.out.println((String) ("[Math.abs(" + initialY + " - " + y + ") = " + Math.abs(initialY - y) + "] < " + fingerStillThreshold));
if (isTouchInHotbar && Math.abs(hotbarX - mouse_x) < fingerStillThreshold && Math.abs(hotbarY - mouse_y) < fingerStillThreshold) { if (isTouchInHotbar && Math.abs(hotbarX - mouse_x) < fingerStillThreshold && Math.abs(hotbarY - mouse_y) < fingerStillThreshold) {
sendKeyPress(hudKeyHandled, 0, false); sendKeyPress(hudKeyHandled, 0, false);
} else if (!triggeredLeftMouseButton && Math.abs(initialX - mouse_x) < fingerStillThreshold && Math.abs(initialY - mouse_y) < fingerStillThreshold) { } else if (!triggeredLeftMouseButton && Math.abs(initialX - mouse_x) < fingerStillThreshold && Math.abs(initialY - mouse_y) < fingerStillThreshold) {
@ -519,7 +458,6 @@ public class BaseMainActivity extends LoggableActivity {
CallbackBridge.DEBUG_STRING.setLength(0); CallbackBridge.DEBUG_STRING.setLength(0);
return true; return true;
// return !CallbackBridge.isGrabbing();
} }
}; };
@ -530,13 +468,9 @@ public class BaseMainActivity extends LoggableActivity {
private boolean debugErrored = false; private boolean debugErrored = false;
private String getMoving(float pos, boolean xOrY) { private String getMoving(float pos, boolean xOrY) {
if (pos == 0) { if (pos == 0) return "STOPPED";
return "STOPPED"; if (pos > 0) return xOrY ? "RIGHT" : "DOWN";
} else if (pos > 0) { return xOrY ? "LEFT" : "UP";
return xOrY ? "RIGHT" : "DOWN";
} else { // if (pos3 < 0) {
return xOrY ? "LEFT" : "UP";
}
} }
@Override @Override
@ -617,18 +551,14 @@ public class BaseMainActivity extends LoggableActivity {
JREUtils.setupBridgeWindow(new Surface(texture)); JREUtils.setupBridgeWindow(new Surface(texture));
new Thread(new Runnable(){ new Thread(() -> {
try {
@Override Thread.sleep(200);
public void run() { runCraft();
try { } catch (Throwable e) {
Thread.sleep(200); Tools.showError(BaseMainActivity.this, e, true);
runCraft(); }
} catch (Throwable e) { }, "JVM Main thread").start();
Tools.showError(BaseMainActivity.this, e, true);
}
}
}, "JVM Main thread").start();
} }
} }
@ -705,11 +635,7 @@ public class BaseMainActivity extends LoggableActivity {
boolean isKeyboard(KeyEvent evt) { boolean isKeyboard(KeyEvent evt) {
System.out.println("Event:" +evt); System.out.println("Event:" +evt);
//if((evt.getFlags() & KeyEvent.FLAG_SOFT_KEYBOARD) == KeyEvent.FLAG_SOFT_KEYBOARD) return true; return AndroidLWJGLKeycode.androidToLwjglMap.containsKey(evt.getKeyCode());
//if(evt.getSource() == InputDevice.SOURCE_KEYBOARD) return true;
//if(evt.getUnicodeChar() != 0) return true;
if(AndroidLWJGLKeycode.androidToLwjglMap.containsKey(evt.getKeyCode())) return true;
return false;
} }
@ -734,20 +660,18 @@ public class BaseMainActivity extends LoggableActivity {
return false; return false;
} }
//private Dialog menuDial;
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
mIsResuming = true; mIsResuming = true;
// if (minecraftGLView != null) minecraftGLView.requestRender();
final int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; final int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
final View decorView = getWindow().getDecorView(); final View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(uiOptions); decorView.setSystemUiVisibility(uiOptions);
} }
@Override @Override
protected void onPause() protected void onPause() {
{
if (CallbackBridge.isGrabbing()){ if (CallbackBridge.isGrabbing()){
sendKeyPress(LWJGLGLFWKeycode.GLFW_KEY_ESCAPE); sendKeyPress(LWJGLGLFWKeycode.GLFW_KEY_ESCAPE);
} }
@ -763,29 +687,7 @@ public class BaseMainActivity extends LoggableActivity {
return Build.VERSION.SDK_INT >= 26; return Build.VERSION.SDK_INT >= 26;
} }
// private FileObserver mLogObserver;
private void runCraft() throws Throwable { private void runCraft() throws Throwable {
/* Old logger
if (Tools.LAUNCH_TYPE != Tools.LTYPE_PROCESS) {
currLogFile = JREUtils.redirectStdio(true);
// DEPRECATED constructor (String) api 29
mLogObserver = new FileObserver(currLogFile.getAbsolutePath(), FileObserver.MODIFY){
@Override
public void onEvent(int event, String file) {
try {
if (event == FileObserver.MODIFY && currLogFile.length() > 0l) {
System.out.println(Tools.read(currLogFile.getAbsolutePath()));
Tools.write(currLogFile.getAbsolutePath(), "");
}
} catch (Throwable th) {
Tools.showError(MainActivity.this, th);
mLogObserver.stopWatching();
}
}
};
mLogObserver.startWatching();
}
*/
if(Tools.LOCAL_RENDERER == null) { if(Tools.LOCAL_RENDERER == null) {
Tools.LOCAL_RENDERER = LauncherPreferences.PREF_RENDERER; Tools.LOCAL_RENDERER = LauncherPreferences.PREF_RENDERER;
} }
@ -811,38 +713,6 @@ public class BaseMainActivity extends LoggableActivity {
private void checkJavaArgsIsLaunchable(String jreVersion) throws Throwable { private void checkJavaArgsIsLaunchable(String jreVersion) throws Throwable {
appendlnToLog("Info: Custom Java arguments: \"" + LauncherPreferences.PREF_CUSTOM_JAVA_ARGS + "\""); appendlnToLog("Info: Custom Java arguments: \"" + LauncherPreferences.PREF_CUSTOM_JAVA_ARGS + "\"");
/*
if (jreVersion.equals("1.8.0")) return;
// Test java
ShellProcessOperation shell = new ShellProcessOperation(new ShellProcessOperation.OnPrintListener(){
@Override
public void onPrintLine(String text){
appendlnToLog("[JRETest] " + text);
}
});
JREUtils.setJavaEnvironment(this, shell);
List<String> testArgs = new ArrayList<String>();
testArgs.add(Tools.homeJreDir + "/bin/java");
Tools.getJavaArgs(this, testArgs);
testArgs.add("-version");
new File(Tools.homeJreDir + "/bin/java").setExecutable(true);
// shell.writeToProcess("chmod 777 " + Tools.homeJreDir + "/bin/java");
shell.writeToProcess("set -e");
shell.writeToProcess(testArgs.toArray(new String[0]));
int exitCode = shell.waitFor();
appendlnToLog("Info: java test command exited with " + exitCode);
if (exitCode != 0) {
appendlnToLog("Error: the test returned non-zero exit code.");
// throw new RuntimeException(getString(R.string.mcn_check_fail_java));
}
*/
} }
private void checkLWJGL3Installed() { private void checkLWJGL3Installed() {
@ -878,11 +748,11 @@ public class BaseMainActivity extends LoggableActivity {
} }
public static String fromArray(List<String> arr) { public static String fromArray(List<String> arr) {
String s = ""; StringBuilder s = new StringBuilder();
for (String exec : arr) { for (String exec : arr) {
s = s + " " + exec; s.append(" ").append(exec);
} }
return s; return s.toString();
} }
private void toggleDebug() { private void toggleDebug() {
@ -892,15 +762,10 @@ public class BaseMainActivity extends LoggableActivity {
private void dialogSendCustomKey() { private void dialogSendCustomKey() {
AlertDialog.Builder dialog = new AlertDialog.Builder(this); AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setTitle(R.string.control_customkey); dialog.setTitle(R.string.control_customkey);
dialog.setItems(AndroidLWJGLKeycode.generateKeyName(), new DialogInterface.OnClickListener(){ dialog.setItems(AndroidLWJGLKeycode.generateKeyName(), (dInterface, position) -> AndroidLWJGLKeycode.execKeyIndex(BaseMainActivity.this, position));
@Override
public void onClick(DialogInterface dInterface, int position) {
AndroidLWJGLKeycode.execKeyIndex(BaseMainActivity.this, position);
}
});
dialog.show(); dialog.show();
} }
boolean isInEditor; boolean isInEditor;
private void openCustomControls() { private void openCustomControls() {
if(ingameControlsEditorListener != null) { if(ingameControlsEditorListener != null) {
@ -911,6 +776,7 @@ public class BaseMainActivity extends LoggableActivity {
isInEditor = true; isInEditor = true;
} }
} }
public void leaveCustomControls() { public void leaveCustomControls() {
if(this instanceof MainActivity) { if(this instanceof MainActivity) {
try { try {
@ -938,53 +804,21 @@ public class BaseMainActivity extends LoggableActivity {
contentLog.setVisibility(View.GONE); contentLog.setVisibility(View.GONE);
mIsResuming = true; mIsResuming = true;
} }
/*
private void openCanvasOutput() {
WindowAnimation.fadeIn(contentCanvas, 500);
}
public void closeCanvasOutput(View view) {
WindowAnimation.fadeOut(contentCanvas, 500);
}
*/
@Override @Override
public void appendToLog(final String text, boolean checkAllow) { public void appendToLog(final String text, boolean checkAllow) {
logStream.print(text); logStream.print(text);
if (checkAllow && !isLogAllow) return; if (checkAllow && !isLogAllow) return;
textLog.post(new Runnable(){ textLog.post(() -> {
@Override textLog.append(text);
public void run() { contentScroll.fullScroll(ScrollView.FOCUS_DOWN);
textLog.append(text); });
contentScroll.fullScroll(ScrollView.FOCUS_DOWN);
}
});
}
public String getMinecraftOption(String key) {
try {
String[] options = Tools.read(Tools.DIR_GAME_NEW + "/options.txt").split("\n");
for (String option : options) {
String[] optionKeyValue = option.split(":");
if (optionKeyValue[0].equals(key)) {
return optionKeyValue[1];
}
}
} catch (Exception e) {
e.printStackTrace();
}
return "";
} }
public int mcscale(int input) { public int mcscale(int input) {
return (int)((this.guiScale * input)/scaleFactor); return (int)((this.guiScale * input)/scaleFactor);
} }
/*
public int randomInRange(int min, int max) {
return min + (int)(Math.random() * (max - min + 1));
}
*/
public void toggleMenu(View v) { public void toggleMenu(View v) {
drawerLayout.openDrawer(Gravity.RIGHT); drawerLayout.openDrawer(Gravity.RIGHT);
@ -1012,24 +846,13 @@ public class BaseMainActivity extends LoggableActivity {
new AlertDialog.Builder(ctx) new AlertDialog.Builder(ctx)
.setMessage(R.string.mcn_exit_confirm) .setMessage(R.string.mcn_exit_confirm)
.setNegativeButton(android.R.string.cancel, null) .setNegativeButton(android.R.string.cancel, null)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener(){ .setPositiveButton(android.R.string.ok, (p1, p2) -> {
try {
@Override fullyExit();
public void onClick(DialogInterface p1, int p2) } catch (Throwable th) {
{ Log.w(Tools.APP_NAME, "Could not enable System.exit() method!", th);
try {
fullyExit();
} catch (Throwable th) {
Log.w(Tools.APP_NAME, "Could not enable System.exit() method!", th);
}
// If we are unable to enable exit, use method: kill myself.
// android.os.Process.killProcess(android.os.Process.myPid());
// Toast.makeText(MainActivity.this, "Could not exit. Please force close this app.", Toast.LENGTH_LONG).show();
} }
}) }).show();
.show();
} }
@Override @Override
@ -1058,7 +881,6 @@ public class BaseMainActivity extends LoggableActivity {
protected void setRightOverride(boolean val) { protected void setRightOverride(boolean val) {
this.rightOverride = val; this.rightOverride = val;
// this.secondaryButton.setBackgroundDrawable(this.rightOverride ? this.secondaryButtonColorBackground : this.secondaryButtonDefaultBackground);
} }
public static void sendKeyPress(int keyCode, int modifiers, boolean status) { public static void sendKeyPress(int keyCode, int modifiers, boolean status) {
@ -1089,10 +911,11 @@ public class BaseMainActivity extends LoggableActivity {
} catch (IllegalAccessException | NoSuchFieldException e) { } catch (IllegalAccessException | NoSuchFieldException e) {
} }
}else{ return;
sendKeyPress(0, keyChar, 0, CallbackBridge.getCurrentMods(), true);
sendKeyPress(0, keyChar, 0, CallbackBridge.getCurrentMods(), false);
} }
sendKeyPress(0, keyChar, 0, CallbackBridge.getCurrentMods(), true);
sendKeyPress(0, keyChar, 0, CallbackBridge.getCurrentMods(), false);
} }
public void sendKeyPress(int keyCode) { public void sendKeyPress(int keyCode) {
@ -1171,21 +994,15 @@ public class BaseMainActivity extends LoggableActivity {
public void onStopTrackingTouch(SeekBar seekBar) {} public void onStopTrackingTouch(SeekBar seekBar) {}
}); });
b.setView(v); b.setView(v);
b.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { b.setPositiveButton(android.R.string.ok, (dialogInterface, i) -> {
@Override LauncherPreferences.PREF_MOUSESPEED = ((float)tmpMouseSpeed)/100f;
public void onClick(DialogInterface dialogInterface, int i) { LauncherPreferences.DEFAULT_PREF.edit().putInt("mousespeed",tmpMouseSpeed).commit();
LauncherPreferences.PREF_MOUSESPEED = ((float)tmpMouseSpeed)/100f; dialogInterface.dismiss();
LauncherPreferences.DEFAULT_PREF.edit().putInt("mousespeed",tmpMouseSpeed).commit(); System.gc();
dialogInterface.dismiss();
System.gc();
}
}); });
b.setNegativeButton(android.R.string.cancel,new DialogInterface.OnClickListener() { b.setNegativeButton(android.R.string.cancel, (dialogInterface, i) -> {
@Override dialogInterface.dismiss();
public void onClick(DialogInterface dialogInterface, int i) { System.gc();
dialogInterface.dismiss();
System.gc();
}
}); });
b.show(); b.show();
} }

View File

@ -33,8 +33,7 @@ import static android.os.Build.VERSION_CODES.P;
import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_IGNORE_NOTCH; import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_IGNORE_NOTCH;
import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_NOTCH_SIZE; import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_NOTCH_SIZE;
public final class Tools public final class Tools {
{
public static final boolean ENABLE_DEV_FEATURES = BuildConfig.DEBUG; public static final boolean ENABLE_DEV_FEATURES = BuildConfig.DEBUG;
public static String APP_NAME = "null"; public static String APP_NAME = "null";
@ -441,31 +440,7 @@ public final class Tools
write(file2.getAbsolutePath(), loadFromAssetToByte(ctx, fileName)); write(file2.getAbsolutePath(), loadFromAssetToByte(ctx, fileName));
} }
} }
/*
public static void extractAssetFolder(Activity ctx, String path, String output) throws Exception {
extractAssetFolder(ctx, path, output, false);
}
public static void extractAssetFolder(Activity ctx, String path, String output, boolean overwrite) throws Exception {
AssetManager assetManager = ctx.getAssets();
String assets[] = null;
try {
assets = assetManager.list(path);
if (assets.length == 0) {
Tools.copyAssetFile(ctx, path, output, overwrite);
} else {
File dir = new File(output, path);
if (!dir.exists())
dir.mkdirs();
for (String sub : assets) {
extractAssetFolder(ctx, path + "/" + sub, output, overwrite);
}
}
} catch (Exception e) {
showError(ctx, e);
}
}
*/
public static void showError(Context ctx, Throwable e) { public static void showError(Context ctx, Throwable e) {
showError(ctx, e, false); showError(ctx, e, false);
} }
@ -490,45 +465,27 @@ public final class Tools
AlertDialog.Builder builder = new AlertDialog.Builder((Context) ctx) AlertDialog.Builder builder = new AlertDialog.Builder((Context) ctx)
.setTitle(titleId) .setTitle(titleId)
.setMessage(errMsg) .setMessage(errMsg)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener(){ .setPositiveButton(android.R.string.ok, (DialogInterface.OnClickListener) (p1, p2) -> {
if(exitIfOk) {
@Override if (ctx instanceof BaseMainActivity) {
public void onClick(DialogInterface p1, int p2) BaseMainActivity.fullyExit();
{ } else if (ctx instanceof Activity) {
if(exitIfOk) { ((Activity) ctx).finish();
if (ctx instanceof BaseMainActivity) {
BaseMainActivity.fullyExit();
} else if (ctx instanceof Activity) {
((Activity) ctx).finish();
}
} }
} }
}) })
.setNegativeButton(showMore ? R.string.error_show_less : R.string.error_show_more, new DialogInterface.OnClickListener(){ .setNegativeButton(showMore ? R.string.error_show_less : R.string.error_show_more, (DialogInterface.OnClickListener) (p1, p2) -> showError(ctx, titleId, e, exitIfOk, !showMore))
.setNeutralButton(android.R.string.copy, (DialogInterface.OnClickListener) (p1, p2) -> {
@Override ClipboardManager mgr = (ClipboardManager) ctx.getSystemService(Context.CLIPBOARD_SERVICE);
public void onClick(DialogInterface p1, int p2) mgr.setPrimaryClip(ClipData.newPlainText("error", Log.getStackTraceString(e)));
{ if(exitIfOk) {
showError(ctx, titleId, e, exitIfOk, !showMore); if (ctx instanceof BaseMainActivity) {
} BaseMainActivity.fullyExit();
}) } else {
.setNeutralButton(android.R.string.copy, new DialogInterface.OnClickListener(){ ((Activity) ctx).finish();
@Override
public void onClick(DialogInterface p1, int p2)
{
android.content.ClipboardManager mgr = (android.content.ClipboardManager) ctx.getSystemService(Context.CLIPBOARD_SERVICE);
mgr.setPrimaryClip(ClipData.newPlainText("error", Log.getStackTraceString(e)));
if(exitIfOk) {
if (ctx instanceof BaseMainActivity) {
BaseMainActivity.fullyExit();
} else {
((Activity) ctx).finish();
}
} }
} }
}) })
//.setNegativeButton("Report (not available)", null)
.setCancelable(!exitIfOk); .setCancelable(!exitIfOk);
try { try {
builder.show(); builder.show();
@ -546,18 +503,11 @@ public final class Tools
} }
public static void dialogOnUiThread(final Activity ctx, final CharSequence title, final CharSequence message) { public static void dialogOnUiThread(final Activity ctx, final CharSequence title, final CharSequence message) {
ctx.runOnUiThread(new Runnable(){ ctx.runOnUiThread(() -> new AlertDialog.Builder(ctx)
.setTitle(title)
@Override .setMessage(message)
public void run() { .setPositiveButton(android.R.string.ok, null)
new AlertDialog.Builder(ctx) .show());
.setTitle(title)
.setMessage(message)
.setPositiveButton(android.R.string.ok, null)
.show();
}
});
} }
public static void moveInside(String from, String to) { public static void moveInside(String from, String to) {