Attempt to fix

This commit is contained in:
khanhduytran0
2020-06-13 18:27:43 +07:00
parent 9e68f13aec
commit f02ec695f8
7 changed files with 94 additions and 52 deletions

View File

@@ -92,14 +92,12 @@ public class CustomControlsActivity extends AppCompatActivity
}
private void setDefaultControlJson(String path) {
try {
// Load before save to make sure control is not error
ctrlLayout.loadLayout(new Gson().fromJson(Tools.read(path), CustomControls.class));
LauncherPreferences.DEFAULT_PREF.edit().putString("defaultCtrl", path).commit();
LauncherPreferences.PREF_DEFAULTCTRL_PATH = path;
} catch (Throwable th) {
Tools.showError(this, th);
}
// Load before save to make sure control is not error
boolean loaded = ctrlLayout.loadLayout(path);
LauncherPreferences.DEFAULT_PREF.edit().putString("defaultCtrl", path).commit();
LauncherPreferences.PREF_DEFAULTCTRL_PATH = path;
}
private void dialogSelectDefaultCtrl() {

View File

@@ -734,16 +734,15 @@ public class MCLauncherActivity extends AppCompatActivity
}
@Override
protected void onPostExecute(Throwable p1)
protected void onPostExecute(Throwable th)
{
playButton.setText("Play");
playButton.setEnabled(true);
launchProgress.setMax(100);
launchProgress.setProgress(0);
statusIsLaunching(false);
if(p1 != null) {
p1.printStackTrace();
Tools.showError(MCLauncherActivity.this, p1);
if(th != null) {
Tools.showError(MCLauncherActivity.this, th);
}
if(!launchWithError) {
crashView.setLastCrash("");
@@ -783,12 +782,11 @@ public class MCLauncherActivity extends AppCompatActivity
mTask = null;
}
private Gson gsonss = gson;
public static final String MINECRAFT_RES = "http://resources.download.minecraft.net/";
public JAssets downloadIndex(String versionName, File output) throws Exception {
String versionJson = DownloadUtils.downloadString("http://s3.amazonaws.com/Minecraft.Download/indexes/" + versionName + ".json");
JAssets version = gsonss.fromJson(versionJson, JAssets.class);
JAssets version = gson.fromJson(versionJson, JAssets.class);
output.getParentFile().mkdirs();
Tools.write(output.getAbsolutePath(), versionJson.getBytes(Charset.forName("UTF-8")));
return version;

View File

@@ -103,7 +103,6 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
// private String mQueueText = new String();
private JMinecraftVersionList.Version mVersionInfo;
private View.OnTouchListener glTouchListener;
// private Button[] controlButtons;
@@ -111,7 +110,9 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
/*
private LinearLayout contentCanvas;
private AWTSurfaceView contentCanvasView;
*/
*/
private boolean isResuming = false;
private boolean lastEnabled = false;
private boolean lastGrab = false;
private boolean isExited = false;
@@ -314,6 +315,9 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
controlLayout.loadLayout(LauncherPreferences.PREF_DEFAULTCTRL_PATH);
controlLayout.setModifiable(false);
// Override non-special control buttons touch listener
// toggleGui(null);
// onClick(toggleControlButton);
this.drawerLayout.closeDrawers();
@@ -564,6 +568,7 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
builder.append("XPos=" + x + "\n");
builder.append("YPos=" + y + "\n\n");
builder.append("MovingX=" + getMoving(e.getX(), true) + "\n");
builder.append("MovingY=" + getMoving(e.getY(), false) + "\n");
@@ -593,15 +598,6 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
case MotionEvent.ACTION_CANCEL: // 3
case MotionEvent.ACTION_POINTER_UP: // 6
AndroidDisplay.putMouseEventWithCoords(rightOverride ? (byte) 1 : (byte) 0, (byte) 0, x, y, 0, System.nanoTime());
/*
if (!triggeredLeftMouseButton && Math.abs(initialX - x) < fingerStillThreshold && Math.abs(initialY - y) < fingerStillThreshold) {
sendMouseButton(1, true);
sendMouseButton(1, false);
}
if (triggeredLeftMouseButton) {
sendMouseButton(0, false);
}
*/
sendMouseButton(AndroidDisplay.mouseLeft ? 0 : 1, true);
sendMouseButton(AndroidDisplay.mouseLeft ? 0 : 1, false);
@@ -612,7 +608,6 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
}
return true;
// If onClick fail with false, change back to true
}
};
@@ -629,7 +624,7 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
glSurfaceView.setOnHoverListener(new View.OnHoverListener(){
@Override
public boolean onHover(View p1, MotionEvent p2) {
if (!AndroidDisplay.grab && isResumed()) {
if (!AndroidDisplay.grab && isResuming) {
return glTouchListener.onTouch(p1, p2);
}
return true;
@@ -665,6 +660,7 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
Thread.sleep(200);
runCraft();
} catch (Throwable e) {
isExited = true;
Tools.showError(MainActivity.this, e, true);
}
}
@@ -683,9 +679,7 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
});
glSurfaceView.setPreserveEGLContextOnPause(true);
glSurfaceView.setRenderMode(MinecraftGLView.RENDERMODE_CONTINUOUSLY);
glSurfaceView.requestRender();
} catch (Throwable e) {
e.printStackTrace();
Tools.showError(this, e, true);
}
@@ -739,6 +733,7 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
@Override
public void onResume() {
super.onResume();
isResuming = true;
glSurfaceView.requestRender();
}
@@ -755,12 +750,19 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
@Override
protected void onPause()
{
isResuming = false;
if (AndroidDisplay.grab){
sendKeyPress(Keyboard.KEY_ESCAPE);
}
super.onPause();
}
@Override
protected void onStop() {
isResuming = false;
super.onStop();
}
@Override
public void onClick(View view) {
/*
@@ -793,6 +795,12 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
default:
return false;
}
if (v instanceof ControlView) {
}
/*
switch (v.getId()) {
case R.id.control_up: sendKeyPress(Keyboard.KEY_W, isDown); break;

View File

@@ -163,6 +163,7 @@ public final class Tools
private static void showError(final Context ctx, final Throwable e, final boolean exitIfOk, final boolean showMore)
{
e.printStackTrace();
Runnable runnable = new Runnable(){
@Override

View File

@@ -58,8 +58,10 @@ public class ControlView extends Button implements OnLongClickListener, OnTouchL
setOnClickListener((View.OnClickListener) properties.specialButtonListener);
} else if (properties.specialButtonListener instanceof View.OnTouchListener) {
setOnTouchListener((View.OnTouchListener) properties.specialButtonListener);
} else if (properties == null) {
// Maybe ignore?
} else {
throw new IllegalArgumentException("Field " + ControlButton.class.getName() + ".specialButtonListener must be View.OnClickListener or View.OnTouchListener");
throw new IllegalArgumentException("Field " + ControlButton.class.getName() + ".specialButtonListener must be View.OnClickListener or View.OnTouchListener instead of " + properties.specialButtonListener.getClass().getName());
}
setLayoutParams(new FrameLayout.LayoutParams(properties.width, properties.height));
@@ -92,10 +94,12 @@ public class ControlView extends Button implements OnLongClickListener, OnTouchL
}
@Override
public boolean onLongClick(View p1)
public boolean onLongClick(View thiz)
{
// This should never happend
if (!mCanModify) throw new IllegalAccessError("Attemp to trigger built-in onLongClick() on a non-modifiable ControlView button");
if (!mCanTriggerLongClick) return false;
if (mHandleView.isShowing()) {
mHandleView.hide();
} else {
@@ -110,12 +114,9 @@ public class ControlView extends Button implements OnLongClickListener, OnTouchL
private float moveX, moveY;
private float downX, downY;
@Override
public boolean onTouch(View view, MotionEvent event) {
if (!mCanModify) {
mCanTriggerLongClick = false;
return false;
}
public boolean onTouch(View thiz, MotionEvent event) {
// This should never happend
if (!mCanModify) throw new IllegalAccessError("Attemp to trigger built-in onTouch() on a non-modifiable ControlView button");
switch (event.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
@@ -137,7 +138,16 @@ public class ControlView extends Button implements OnLongClickListener, OnTouchL
return false;
}
public void setModifiable(boolean z) {
mCanModify = z;
public void setModifiable(boolean canModify) {
mCanModify = canModify;
// mCanTriggerLongClick &= canModify;
setOnLongClickListener(canModify ? this : null);
if (canModify) {
setOnTouchListener(this);
} /* else if (mProperties instanceof View.OnTouchListener) {
setOnTouchListener((View.OnTouchListener) mProperties);
} */ else {
setOnTouchListener(null);
}
}
}

View File

@@ -30,22 +30,30 @@ public class ControlsLayout extends FrameLayout
}
}
public void loadLayout(String jsonPath) {
public boolean loadLayout(String jsonPath) {
try {
loadLayout(new Gson().fromJson(Tools.read(jsonPath), CustomControls.class));
} catch (Exception e) {
e.printStackTrace();
return loadLayout(new Gson().fromJson(Tools.read(jsonPath), CustomControls.class));
} catch (Throwable th) {
Tools.showError(getContext(), th);
}
return false;
}
public void loadLayout(CustomControls controlLayout) {
mLayout = controlLayout;
removeAllViews();
for (ControlButton button : controlLayout.button) {
addControlView(button);
}
public boolean loadLayout(CustomControls controlLayout) {
try {
mLayout = controlLayout;
removeAllViews();
for (ControlButton button : controlLayout.button) {
addControlView(button);
}
setModified(false);
setModified(false);
return true;
} catch (Throwable th) {
Tools.showError(getContext(), th);
}
return false;
}
public void addControlButton(ControlButton controlButton) {
@@ -78,6 +86,22 @@ public class ControlsLayout extends FrameLayout
mActivity = activity;
}
/*
* Setting non-special buttons listener
*
* @param listener, the touch listener to initialize.
*/
public void setNonspecBtnsListener(View.OnTouchListener listener) {
for (int i = 0; i < getChildCount(); i++) {
View view = getChildAt(i);
if (view instanceof ControlView && ((ControlView) view).getProperties().keycode < 0) {
ControlView currView = ((ControlView) view);
currView.getProperties().specialButtonListener = listener;
currView.setOnTouchListener(listener);
}
}
}
public void toggleControlVisible() {
if (mCanModify) return; // Not using on custom controls activity

View File

@@ -33,7 +33,7 @@
<string name="login_select_account">Select account</string>
<!-- Hint -->
<string name="hint_select_account">To select, click it. To delete an account, hold it.</string>
<string name="hint_select_account">Tip: Hold an account to delete</string>
<string name="hint_control_mapping">"This feature is not yet finished so can't apply custom control at the moment!\nSwipe from right to left to open menu ◀\nHold a button to customize: edit, resize or delete."</string>
<!-- Warning -->
@@ -109,6 +109,9 @@
<string name="mcl_version_clone">Clone</string>
<!-- Errors... buggy? -->
<string name="error_category_launch">Error</string>
<!-- Global strings -->
<string name="global_add">Add</string>
<string name="global_edit">Edit</string>