Remove update option, more work at custom control

This commit is contained in:
khanhduytran0 2020-04-21 09:34:32 +07:00
parent da136c0011
commit 325835ddaa
20 changed files with 271 additions and 412 deletions

View File

@ -46,12 +46,6 @@
android:name=".MainActivity" android:name=".MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize"/> android:configChanges="keyboardHidden|orientation|screenSize"/>
<activity
android:screenOrientation="sensorLandscape"
android:label="@string/update_console"
android:name=".UpdateAppActivity"
android:configChanges="keyboardHidden|orientation|screenSize"/>
<activity <activity
android:screenOrientation="sensorLandscape" android:screenOrientation="sensorLandscape"
android:name=".prefs.LauncherPreferenceActivity" android:name=".prefs.LauncherPreferenceActivity"

View File

@ -1,55 +0,0 @@
package com.kdtapi.mclup;
import android.content.*;
import android.os.*;
import android.util.*;
import android.widget.*;
import java.io.*;
import net.kdt.pojavlaunch.*;
public abstract class UpContext
{
public abstract void onCreate() throws Exception;
public abstract void onFinish();
public abstract void onErrorw(String message);
private UpdateAppActivity activity;
public UpContext(UpdateAppActivity activity)
{
this.activity = activity;
}
public Context getContext()
{
return getUpActivity();
}
public UpdateAppActivity getUpActivity()
{
return activity;
}
public void onRun()
{
new AsyncTask<Void, Void, Void>(){
@Override
protected Void doInBackground(Void[] p1)
{
try{
onCreate();
onFinish();
new File(Tools.worksDir + "/installer.jar").delete();
}
catch(Exception e){
onErrorw(Log.getStackTraceString(e));
}
return null;
}
}.execute();
}
public ProgressBar getProgressBar()
{
return activity.getProgressBar();
}
public void log(String message)
{
activity.putLog(message);
}
}

View File

@ -203,7 +203,22 @@ public class AndroidLWJGLKeycode {
} }
public static void execKeyIndex(MainActivity mainActivity, int index) { public static void execKeyIndex(MainActivity mainActivity, int index) {
mainActivity.sendKeyPress(androidToLwjglMap.valueAt(index)); mainActivity.sendKeyPress(getKeyIndex(index));
}
public static int getKeyIndex(int index) {
return androidToLwjglMap.valueAt(index);
}
public static int getIndexByLWJGLKey(int lwjglKey) {
for (int i = 0; i < androidToLwjglMap.size(); i++) {
int currKey = androidToLwjglMap.valueAt(i);
if (currKey == lwjglKey) {
return i;
}
}
return 0;
} }
} }

View File

@ -102,7 +102,7 @@ public class CustomControlsActivity extends AppCompatActivity
@Override @Override
public void onShow(DialogInterface dialogInterface) { public void onShow(DialogInterface dialogInterface) {
Button button = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE); Button button = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
button.setOnClickListener(new View.OnClickListener() { button.setOnClickListener(new View.OnClickListener() {
@Override @Override
@ -128,18 +128,24 @@ public class CustomControlsActivity extends AppCompatActivity
private void actionLoad() { private void actionLoad() {
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Select OptiFine jar file"); builder.setTitle("Select control json file");
builder.setPositiveButton(android.R.string.cancel, null); builder.setPositiveButton(android.R.string.cancel, null);
final AlertDialog dialog = builder.create(); final AlertDialog dialog = builder.create();
FileListView flv = new FileListView(this); FileListView flv = new FileListView(this);
flv.listFileAt(Tools.CTRLMAP_PATH);
flv.setFileSelectedListener(new FileSelectedListener(){ flv.setFileSelectedListener(new FileSelectedListener(){
@Override @Override
public void onFileSelected(File file, String path, String name) { public void onFileSelected(File file, String path, String name) {
if (name.endsWith(".json")) { if (name.endsWith(".json")) {
// doInstallOptiFine(file); try {
mCtrl = gson.fromJson(Tools.read(path), CustomControls.class);
ctrlLayout.loadLayout(mCtrl);
dialog.dismiss(); dialog.dismiss();
} catch (Exception e) {
Tools.showError(CustomControlsActivity.this, e);
}
} }
} }
}); });

View File

@ -134,7 +134,7 @@ public class MCLauncherActivity extends AppCompatActivity
versions.add(fVer.getName()); versions.add(fVer.getName());
} }
} catch (Exception e) { } catch (Exception e) {
versions.add(getStr(R.string.error_title) + ":"); versions.add(getStr(com.android.internal.R.string.dlg_error_title) + ":");
versions.add(e.getMessage()); versions.add(e.getMessage());
} finally { } finally {
@ -844,18 +844,15 @@ public class MCLauncherActivity extends AppCompatActivity
case 1:{ // OptiFine installer case 1:{ // OptiFine installer
installOptiFine(); installOptiFine();
} break; } break;
case 2:{ // Check update case 2:{ // Custom controls
checkUpdate();
} break;
case 3:{ // Custom controls
if (Tools.enableDevFeatures) { if (Tools.enableDevFeatures) {
startActivity(new Intent(MCLauncherActivity.this, CustomControlsActivity.class)); startActivity(new Intent(MCLauncherActivity.this, CustomControlsActivity.class));
} }
} break; } break;
case 4:{ // Settings case 3:{ // Settings
startActivity(new Intent(MCLauncherActivity.this, LauncherPreferenceActivity.class)); startActivity(new Intent(MCLauncherActivity.this, LauncherPreferenceActivity.class));
} break; } break;
case 5:{ // About case 4:{ // About
final AlertDialog.Builder aboutB = new AlertDialog.Builder(MCLauncherActivity.this); final AlertDialog.Builder aboutB = new AlertDialog.Builder(MCLauncherActivity.this);
aboutB.setTitle(R.string.mcl_option_about); aboutB.setTitle(R.string.mcl_option_about);
try try
@ -970,7 +967,6 @@ public class MCLauncherActivity extends AppCompatActivity
dialog = new ProgressDialog(MCLauncherActivity.this); dialog = new ProgressDialog(MCLauncherActivity.this);
dialog.setTitle("Installing OptiFine"); dialog.setTitle("Installing OptiFine");
dialog.setMessage("Prepaping"); dialog.setMessage("Prepaping");
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dialog.setMax(5); dialog.setMax(5);
dialog.setCancelable(false); dialog.setCancelable(false);
dialog.show(); dialog.show();
@ -1010,7 +1006,7 @@ public class MCLauncherActivity extends AppCompatActivity
String[] output = Tools.patchOptifineInstaller(MCLauncherActivity.this, file[0]); String[] output = Tools.patchOptifineInstaller(MCLauncherActivity.this, file[0]);
File patchedFile = new File(output[1]); File patchedFile = new File(output[1]);
publishProgress("Converting OptiFine", null, "1", "ADD"); publishProgress("Converting OptiFine", null, null, Integer.toString(ProgressDialog.STYLE_SPINNER));
System.setOut(new PrintStream(logOut)); System.setOut(new PrintStream(logOut));
System.setErr(new PrintStream(logErr)); System.setErr(new PrintStream(logErr));
@ -1019,7 +1015,7 @@ public class MCLauncherActivity extends AppCompatActivity
@Override @Override
public void onReceived(String msg, int max, int current) public void onReceived(String msg, int max, int current)
{ {
publishProgress("Converting OptiFine: " + msg, Integer.toString(max), Integer.toString(current), "SET"); publishProgress("Converting OptiFine: " + msg, Integer.toString(max), null);
} }
}); });
@ -1032,7 +1028,7 @@ public class MCLauncherActivity extends AppCompatActivity
patchedFile.delete(); patchedFile.delete();
} }
publishProgress("Launching OptiFine installer", null, "1", "ADD"); publishProgress("Launching OptiFine installer", null, null, Integer.toString(ProgressDialog.STYLE_SPINNER));
File optDir = getDir("dalvik-cache", 0); File optDir = getDir("dalvik-cache", 0);
optDir.mkdir(); optDir.mkdir();
@ -1044,11 +1040,15 @@ public class MCLauncherActivity extends AppCompatActivity
Method installerMethod = installerClass.getDeclaredMethod("doInstall", File.class); Method installerMethod = installerClass.getDeclaredMethod("doInstall", File.class);
installerMethod.invoke(null, new File(Tools.MAIN_PATH)); installerMethod.invoke(null, new File(Tools.MAIN_PATH));
publishProgress("(4/5) Patching OptiFine Tweaker", null, "1", "ADD"); publishProgress("(4/5) Patching OptiFine Tweaker", null, null);
File optifineLibFile = new File(AndroidOptiFineUtilities.optifineOutputJar); File optifineLibFile = new File(AndroidOptiFineUtilities.optifineOutputJar);
if (!optifineLibFile.exists()) {
throw new FileNotFoundException(optifineLibFile.getAbsolutePath() + "\n\n--- OptiFine installer log ---\n" + currentLog.toString());
}
new OptiFinePatcher(optifineLibFile).saveTweaker(); new OptiFinePatcher(optifineLibFile).saveTweaker();
convertedFile.delete();
publishProgress("(5/5) Done!", null, "1", "ADD"); publishProgress("(5/5) Done!", null, null);
Thread.sleep(500); Thread.sleep(500);
} catch (Throwable th) { } catch (Throwable th) {
throwable = th; throwable = th;
@ -1076,12 +1076,10 @@ public class MCLauncherActivity extends AppCompatActivity
dialog.setMessage(text[0]); dialog.setMessage(text[0]);
if (text.length >= 2 && text[1] != null) { if (text.length >= 2 && text[1] != null) {
dialog.setMax(Integer.valueOf(text[1])); dialog.setMax(Integer.valueOf(text[1]));
} if (text.length >= 3) {
dialog.setProgress(dialog.getProgress() + 1);
} if (text.length >= 4) { } if (text.length >= 4) {
if (text[3].equals("ADD")) { dialog.setProgressStyle(Integer.parseInt(text[3]));
dialog.setProgress(dialog.getProgress() + Integer.valueOf(text[2]));
} else if (text[3].equals("SET")) {
dialog.setProgress(7 + Integer.valueOf(text[2]));
}
} }
} }
@ -1100,117 +1098,6 @@ public class MCLauncherActivity extends AppCompatActivity
} }
} }
public void updateAppProcess(final String ver)
{
new Thread(new Runnable(){
@Override
public void run()
{
try
{
DownloadUtils.downloadFile(Tools.mhomeUrl + "/installer_" + ver + ".jar", new File(Tools.worksDir + "/installer.jar"));
startActivity(new Intent(MCLauncherActivity.this, UpdateAppActivity.class));
}
catch (Throwable e)
{
e.printStackTrace();
mkToast("Download failed: " + e.getMessage());
}
}
}).start();
}
public void checkUpdate() {
final ProgressDialog progUp = new ProgressDialog(this);
progUp.setMessage(getStr(R.string.mcl_option_checkupdate));
progUp.setCancelable(false);
progUp.show();
new Thread(new Runnable(){
@Override
public void run()
{
final AlertDialog.Builder alUp = new AlertDialog.Builder(MCLauncherActivity.this);
alUp.setTitle(R.string.mcl_option_checkupdate);
try {
final int myVer = Tools.usingVerCode;
// final String currVerName = Tools.usingVerName;
String[] totalNewVer = DownloadUtils.downloadString(Tools.mhomeUrl + "/update.txt").split(";");
final int newVer = Integer.parseInt(totalNewVer[1]);
final String newVerName = totalNewVer[0];
//int myVer = 102;
runOnUiThread(new Runnable(){
@Override
public void run()
{
if(newVer != -1){
boolean isAvailable = myVer < newVer;
String isNewVerAvailable =
isAvailable ?
"A new version is available!\nSee changelog at Launcher News tab." :
"This launcher is up-to-date!";
if (myVer > newVer) {
isNewVerAvailable = "This is an unreleased version or unofficial version?";
}
alUp.setMessage(
"Received version " + newVerName + "\n" +
isNewVerAvailable
);
if(isAvailable){
alUp.setPositiveButton("Update", new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface p1, int p2)
{
updateAppProcess(newVerName);
}
});
}
}
else{
alUp.setMessage("Failed to check for update. Reason: No Internet connection");
}
alUp.setNegativeButton(android.R.string.cancel, null);
alUp.show();
}
});
} catch (final Exception e) {
Log.e(Tools.APP_NAME + ".CheckUpdateError", e.getMessage());
e.printStackTrace();
runOnUiThread(new Runnable(){
@Override
public void run()
{
alUp.setMessage("Failed to check for update. Reason: " + e.getMessage());
alUp.show();
}
});
} finally {
runOnUiThread(new Runnable(){
@Override
public void run()
{
progUp.dismiss();
}
});
}
}
}).start();
}
private class ViewPagerAdapter extends FragmentPagerAdapter { private class ViewPagerAdapter extends FragmentPagerAdapter {
List<Fragment> fragmentList = new ArrayList<>(); List<Fragment> fragmentList = new ArrayList<>();

View File

@ -1069,13 +1069,11 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
} }
private void openLogOutput() { private void openLogOutput() {
WindowAnimation.fadeIn(contentLog, 500); contentLog.setVisibility(View.VISIBLE);
} }
public void closeLogOutput(View view) { public void closeLogOutput(View view) {
//scrollLog.setVisibility(View.GONE); contentLog.setVisibility(View.GONE);
WindowAnimation.fadeOut(contentLog, 500);
} }
/* /*
private void openCanvasOutput() { private void openCanvasOutput() {
@ -1168,7 +1166,7 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
public void dialogForceClose() public void dialogForceClose()
{ {
new AlertDialog.Builder(this) new AlertDialog.Builder(this)
.setMessage(R.string.mcn_exit_confirm) .setMessage(getResources().getString(R.string.mcn_exit_confirm, getResources().getString(com.android.internal.R.string.force_close)))
.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, new DialogInterface.OnClickListener(){
@ -1181,7 +1179,7 @@ public class MainActivity extends AppCompatActivity implements OnTouchListener,
Log.w(Tools.APP_NAME, "Could not enable System.exit() method!", th); Log.w(Tools.APP_NAME, "Could not enable System.exit() method!", th);
} }
// If we are unable to enable exit, use method: kill myself. // If unable to enable exit, use method: kill self process.
android.os.Process.killProcess(android.os.Process.myPid()); android.os.Process.killProcess(android.os.Process.myPid());
// Toast.makeText(MainActivity.this, "Could not exit. Please force close this app.", Toast.LENGTH_LONG).show(); // Toast.makeText(MainActivity.this, "Could not exit. Please force close this app.", Toast.LENGTH_LONG).show();

View File

@ -52,6 +52,8 @@ public class PojavLoginActivity extends MineActivity
firstLaunchPrefs = getSharedPreferences("pojav_extract", MODE_PRIVATE); firstLaunchPrefs = getSharedPreferences("pojav_extract", MODE_PRIVATE);
new File(Tools.mpProfiles).mkdir(); new File(Tools.mpProfiles).mkdir();
// Remove vmos warning???
/*
if (isAndroid7() && !firstLaunchPrefs.getBoolean(PREF_IS_DONOTSHOWAGAIN_WARN, false)) { if (isAndroid7() && !firstLaunchPrefs.getBoolean(PREF_IS_DONOTSHOWAGAIN_WARN, false)) {
AlertDialog.Builder startDlg = new AlertDialog.Builder(PojavLoginActivity.this); AlertDialog.Builder startDlg = new AlertDialog.Builder(PojavLoginActivity.this);
startDlg.setTitle(R.string.warning_title); startDlg.setTitle(R.string.warning_title);
@ -109,8 +111,9 @@ public class PojavLoginActivity extends MineActivity
startDlg.show(); startDlg.show();
} else { } else {
*/
new InitTask().execute(); new InitTask().execute();
} // }
} }
private class InitTask extends AsyncTask<Void, String, Integer>{ private class InitTask extends AsyncTask<Void, String, Integer>{
@ -550,7 +553,7 @@ public class PojavLoginActivity extends MineActivity
{ {
// TODO: Implement this method // TODO: Implement this method
if(result[0].equals("ERROR")){ if(result[0].equals("ERROR")){
Tools.dialogOnUiThread(PojavLoginActivity.this, getResources().getString(R.string.error_title), strArrToString(result)); Tools.dialogOnUiThread(PojavLoginActivity.this, getResources().getString(com.android.internal.R.string.dlg_error_title), strArrToString(result));
} else{ } else{
MCProfile.Builder builder = new MCProfile.Builder(); MCProfile.Builder builder = new MCProfile.Builder();
builder.setAccessToken(result[1]); builder.setAccessToken(result[1]);

View File

@ -46,11 +46,7 @@ public class PojavProfile
if (profileCon.equals(":::::")) { if (profileCon.equals(":::::")) {
throw new RuntimeException("Profile not set or reset."); throw new RuntimeException("Profile not set or reset.");
} }
/*
if (true) {
throw new RuntimeException(profilePath + ":" + new File(profilePath).exists());
}
*/
return new File(profilePath).exists(); return new File(profilePath).exists();
} }
} }

View File

@ -163,26 +163,26 @@ public final class Tools
} }
*/ */
public static void showError(Activity ctx, Throwable e) public static void showError(Context ctx, Throwable e)
{ {
showError(ctx, e, false); showError(ctx, e, false);
} }
public static void showError(final Activity ctx, final Throwable e, final boolean exitIfOk) public static void showError(final Context ctx, final Throwable e, final boolean exitIfOk)
{ {
showError(ctx, e, exitIfOk, false); showError(ctx, e, exitIfOk, false);
} }
private static void showError(final Activity ctx, final Throwable e, final boolean exitIfOk, final boolean showMore) private static void showError(final Context ctx, final Throwable e, final boolean exitIfOk, final boolean showMore)
{ {
ctx.runOnUiThread(new Runnable(){ Runnable runnable = new Runnable(){
@Override @Override
public void run() public void run()
{ {
final String errMsg = showMore ? Log.getStackTraceString(e): e.getMessage(); final String errMsg = showMore ? Log.getStackTraceString(e): e.getMessage();
new AlertDialog.Builder((Context) ctx) new AlertDialog.Builder((Context) ctx)
.setTitle(R.string.error_title) .setTitle(com.android.internal.R.string.dlg_error_title)
.setMessage(errMsg) .setMessage(errMsg)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener(){ .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener(){
@ -192,8 +192,8 @@ public final class Tools
if(exitIfOk) { if(exitIfOk) {
if (ctx instanceof MainActivity) { if (ctx instanceof MainActivity) {
MainActivity.fullyExit(); MainActivity.fullyExit();
} else { } else if (ctx instanceof Activity) {
ctx.finish(); ((Activity) ctx).finish();
} }
} }
} }
@ -218,7 +218,7 @@ public final class Tools
if (ctx instanceof MainActivity) { if (ctx instanceof MainActivity) {
MainActivity.fullyExit(); MainActivity.fullyExit();
} else { } else {
ctx.finish(); ((Activity) ctx).finish();
} }
} }
} }
@ -227,7 +227,13 @@ public final class Tools
.setCancelable(!exitIfOk) .setCancelable(!exitIfOk)
.show(); .show();
} }
}); };
if (ctx instanceof Activity) {
((Activity) ctx).runOnUiThread(runnable);
} else {
runnable.run();
}
} }
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) {

View File

@ -1,61 +0,0 @@
package net.kdt.pojavlaunch;
import android.app.*;
import android.graphics.*;
import android.os.*;
import android.widget.*;
import dalvik.system.*;
import java.io.*;
import java.lang.reflect.*;
import net.kdt.pojavlaunch.*;
import android.util.*;
public class UpdateAppActivity extends Activity
{
private ProgressBar progress;
private TextView logView;
private boolean cancelable = false;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.launcher_update);
progress = (ProgressBar) findViewById(R.id.launcherupdateProgressBar);
logView = (TextView) findViewById(R.id.launcherupdateLogView);
logView.setTypeface(Typeface.MONOSPACE);
File inst = new File(Tools.worksDir + "/installer.jar");
try {
File optDir = getDir("dalvik-cache", 0);
optDir.mkdirs();
DexClassLoader mainLoader = new DexClassLoader(inst.getAbsolutePath(), optDir.getAbsolutePath(), getPackageManager().getPackageInfo(getPackageName(), 0).applicationInfo.nativeLibraryDir, MainActivity.class.getClassLoader());
Class mClass = mainLoader.loadClass("Main");
Method method = mClass.getMethod("main", UpdateAppActivity.class);
method.invoke(null, this);
} catch (Throwable th) {
putLog("----- AN ERROR OCCURRED -----");
putLog(Log.getStackTraceString(th));
putLog("----- FAILED TO UPDATE! -----");
} finally {
cancelable = true;
}
}
public void putLog(String message)
{
logView.append(message + "\n");
}
public ProgressBar getProgressBar()
{
return progress;
}
@Override
public void onBackPressed()
{
if (cancelable) super.onBackPressed();
}
}

View File

@ -1,62 +0,0 @@
package net.kdt.pojavlaunch;
import android.view.*;
public class WindowAnimation
{
public static void fadeIn(final View view, int duration) {
// 0.1 -> 1.0
doFade(view, true, duration);
}
public static void fadeOut(final View view, int duration) {
// 1.0 -> 0.1
doFade(view, false, duration);
}
private static void doFade(final View view, final boolean fadeIn, int duration) {
final long millis = ((long) duration) / 10l;
view.setVisibility(View.VISIBLE);
view.setAlpha(fadeIn ? 0 : 1);
view.setEnabled(false);
new Thread(new Runnable(){
private float alpha = fadeIn ? 0 : 1;
@Override
public void run()
{
try {
while (fadeIn ? alpha < 1 : alpha > 0) {
try {
Thread.sleep(millis);
} catch (InterruptedException e) {}
if (fadeIn) alpha += 0.1;
else alpha -= 0.1;
view.post(new Runnable(){
@Override
public void run()
{
view.setAlpha(alpha);
}
});
}
} finally {
view.post(new Runnable(){
@Override
public void run()
{
if (fadeIn) view.setEnabled(true);
else {
view.setVisibility(View.GONE);
}
}
});
}
}
}).start();
}
}

View File

@ -1,6 +1,8 @@
package net.kdt.pojavlaunch.value.customcontrols; package net.kdt.pojavlaunch.value.customcontrols;
import net.kdt.pojavlaunch.*; import net.kdt.pojavlaunch.*;
import android.view.*; import android.view.*;
import java.util.*;
import android.content.*;
public class ControlButton public class ControlButton
{ {
@ -10,11 +12,15 @@ public class ControlButton
public static int SPECIALBTN_TOGGLECTRL = 1; public static int SPECIALBTN_TOGGLECTRL = 1;
private static ControlButton[] SPECIAL_BUTTONS; private static ControlButton[] SPECIAL_BUTTONS;
private static String[] SPECIAL_BUTTON_NAME_ARRAY;
public static ControlButton[] getSpecialButtons(){ public static ControlButton[] getSpecialButtons(){
if (SPECIAL_BUTTONS == null) { if (SPECIAL_BUTTONS == null) {
ControlButton keyboardBtn = new ControlButton(); ControlButton keyboardBtn = new ControlButton();
keyboardBtn.lwjglKeycode = -1;
ControlButton toggleCtrlBtn = new ControlButton(); ControlButton toggleCtrlBtn = new ControlButton();
toggleCtrlBtn.lwjglKeycode = -2;
SPECIAL_BUTTONS = new ControlButton[]{ SPECIAL_BUTTONS = new ControlButton[]{
keyboardBtn, keyboardBtn,
@ -25,6 +31,18 @@ public class ControlButton
return SPECIAL_BUTTONS; return SPECIAL_BUTTONS;
} }
public static String[] buildSpecialButtonArray() {
if (SPECIAL_BUTTON_NAME_ARRAY == null) {
List<String> nameList = new ArrayList<String>();
for (ControlButton btn : getSpecialButtons()) {
nameList.add(btn.name);
}
SPECIAL_BUTTON_NAME_ARRAY = nameList.toArray(new String[0]);
}
return SPECIAL_BUTTON_NAME_ARRAY;
}
// Concept... // Concept...
public String name; public String name;
public float x; public float x;
@ -32,6 +50,7 @@ public class ControlButton
public int width = pixelOf50dp; public int width = pixelOf50dp;
public int height = pixelOf50dp; public int height = pixelOf50dp;
public int lwjglKeycode; public int lwjglKeycode;
public boolean hidden;
public boolean holdCtrl; public boolean holdCtrl;
public boolean holdAlt; public boolean holdAlt;
public boolean holdShift; public boolean holdShift;

View File

@ -20,12 +20,27 @@ public class ControlView extends Button implements OnTouchListener
setOnTouchListener(this); setOnTouchListener(this);
mGestureDetector = new GestureDetector(ctx, new SingleTapConfirm()); mGestureDetector = new GestureDetector(ctx, new SingleTapConfirm());
setProperties(properties);
}
public ControlButton getProperties() {
return mProperties;
}
public void setProperties(ControlButton properties) {
setProperties(properties, true);
}
public void setProperties(ControlButton properties, boolean changePos) {
mProperties = properties; mProperties = properties;
// com.android.internal.R.string.delete // com.android.internal.R.string.delete
// android.R.string. // android.R.string.
setText(properties.name); setText(properties.name);
if (changePos) {
setTranslationX(moveX = properties.x); setTranslationX(moveX = properties.x);
setTranslationY(moveY = properties.y); setTranslationY(moveY = properties.y);
}
setLayoutParams(new FrameLayout.LayoutParams(properties.width, properties.height)); setLayoutParams(new FrameLayout.LayoutParams(properties.width, properties.height));
} }
@ -43,6 +58,10 @@ public class ControlView extends Button implements OnTouchListener
mProperties.y = y; mProperties.y = y;
} }
public void updateProperties() {
setProperties(mProperties);
}
private float moveX, moveY; private float moveX, moveY;
private float downX, downY; private float downX, downY;
@Override @Override

View File

@ -19,6 +19,101 @@ public class ControlsLayout extends FrameLayout
super(ctx, attrs); super(ctx, attrs);
} }
private void showCtrlOption(final ControlView view) {
AlertDialog.Builder alert = new AlertDialog.Builder(getContext());
alert.setCancelable(false);
alert.setTitle(getResources().getString(R.string.global_edit) + " " + view.getText());
alert.setView(R.layout.control_setting);
alert.setPositiveButton(android.R.string.ok, null);
alert.setNegativeButton(android.R.string.cancel, null);
alert.setNeutralButton(com.android.internal.R.string.delete, new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface p1, int p2)
{
ControlButton.getSpecialButtons();
AlertDialog.Builder alert2 = new AlertDialog.Builder(getContext());
alert2.setCancelable(false);
alert2.setTitle(R.string.customctrl_specialkey);
alert2.setItems(ControlButton.buildSpecialButtonArray(), new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dInterface, int position) {
view.setProperties(ControlButton.getSpecialButtons()[position], false);
}
});
alert2.setPositiveButton(android.R.string.cancel, null);
alert2.show();
}
});
final AlertDialog dialog = alert.create();
final ControlButton properties = view.getProperties();
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialogInterface) {
final LinearLayout normalBtnLayout = dialog.findViewById(R.id.controlsetting_normalbtnlayout);
final EditText editName = dialog.findViewById(R.id.controlsetting_edit_name);
editName.setText(properties.name);
final Spinner spinnerKeycode = dialog.findViewById(R.id.controlsetting_spinner_lwjglkeycode);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(), android.R.layout.simple_spinner_item);
String[] specialArr = ControlButton.buildSpecialButtonArray();
for (int i = 0; i < specialArr.length; i++) {
specialArr[i] = "SPECIAL_" + specialArr[i];
}
adapter.addAll(specialArr);
adapter.addAll(AndroidLWJGLKeycode.generateKeyName());
adapter.setDropDownViewResource(android.R.layout.simple_list_item_single_choice);
spinnerKeycode.setAdapter(adapter);
spinnerKeycode.setSelection(AndroidLWJGLKeycode.getIndexByLWJGLKey(properties.lwjglKeycode) + 2);
spinnerKeycode.setOnItemSelectedListener(new Spinner.OnItemSelectedListener(){
@Override
public void onItemSelected(AdapterView<?> adapter, View view, int position, long id) {
normalBtnLayout.setVisibility(id < 2 ? View.GONE : View.VISIBLE);
}
@Override
public void onNothingSelected(AdapterView<?> adapter){
// Unused
}
});
final CheckBox checkHidden = dialog.findViewById(R.id.controlsetting_checkbox_hidden);
checkHidden.setChecked(properties.hidden);
Button button = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view2) {
if (editName.getText().toString().isEmpty()) {
editName.setError(getResources().getString(R.string.global_error_field_empty));
} else {
properties.lwjglKeycode = AndroidLWJGLKeycode.getKeyIndex(spinnerKeycode.getSelectedItemPosition()) - 2;
properties.name = editName.getText().toString();
properties.hidden = checkHidden.isChecked();
view.updateProperties();
dialog.dismiss();
}
}
});
}
});
dialog.show();
}
public void loadLayout(CustomControls controlLayout) { public void loadLayout(CustomControls controlLayout) {
mLayout = controlLayout; mLayout = controlLayout;
removeAllViews(); removeAllViews();
@ -28,10 +123,7 @@ public class ControlsLayout extends FrameLayout
@Override @Override
public void onClick(View p1) { public void onClick(View p1) {
AlertDialog.Builder alert = new AlertDialog.Builder(getContext()); showCtrlOption(view);
alert.setTitle(getResources().getString(R.string.global_edit) + " " + view.getText());
// alert.setView(edit);
alert.show();
} }
}); });
view.setCanMove(mCanMove); view.setCanMove(mCanMove);

View File

@ -1,5 +0,0 @@
package net.kdt.pojavlaunch.views;
public class MineButton
{
}

View File

@ -5,6 +5,22 @@
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical"> android:orientation="vertical">
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/customctrl_keyname"/>
<Spinner
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="@+id/controlsetting_spinner_lwjglkeycode"/>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical"
android:id="@+id/controlsetting_normalbtnlayout">
<TextView <TextView
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -16,21 +32,13 @@
android:singleLine="true" android:singleLine="true"
android:id="@+id/controlsetting_edit_name"/> android:id="@+id/controlsetting_edit_name"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/customctrl_keyname"/>
<Spinner
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="@+id/controlsetting_spinner_lwjglkeycode"/>
<CheckBox <CheckBox
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_width="match_parent" android:layout_width="match_parent"
android:text="@string/customctrl_hidden" android:text="@string/customctrl_hidden"
android:id="@+id/controlsetting_checkbox_hidden"/> android:id="@+id/controlsetting_checkbox_hidden"/>
</LinearLayout>
</LinearLayout> </LinearLayout>

View File

@ -244,6 +244,7 @@
</RelativeLayout> </RelativeLayout>
<LinearLayout <LinearLayout
android:animateLayoutChanges="true"
android:id="@+id/content_log_layout" android:id="@+id/content_log_layout"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -2,7 +2,7 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" > <menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item <item
android:id="@+id/nav_forceclose" android:id="@+id/nav_forceclose"
android:title="@string/control_forceclose" /> android:title="@*android:string/force_close" />
<item <item
android:id="@+id/nav_viewlog" android:id="@+id/nav_viewlog"
android:title="@string/control_viewout" /> android:title="@string/control_viewout" />

View File

@ -3,7 +3,6 @@
<string-array name="mcl_options"> <string-array name="mcl_options">
<item>@string/mcl_option_modmgr</item> <item>@string/mcl_option_modmgr</item>
<item>@string/mcl_option_optifineinstall</item> <item>@string/mcl_option_optifineinstall</item>
<item>@string/mcl_option_checkupdate</item>
<item>@string/mcl_option_customcontrol</item> <item>@string/mcl_option_customcontrol</item>
<item>@string/mcl_option_settings</item> <item>@string/mcl_option_settings</item>
<item>@string/mcl_option_about</item> <item>@string/mcl_option_about</item>

View File

@ -51,7 +51,6 @@
<!-- Error messages --> <!-- Error messages -->
<string name="error_checklog">Error! Please check the log below: %s</string> <string name="error_checklog">Error! Please check the log below: %s</string>
<string name="error_title">Error</string>
<string name="error_no_version">No version!</string> <string name="error_no_version">No version!</string>
<string name="error_load_version">Unable to load version %s</string> <string name="error_load_version">Unable to load version %s</string>
<string name="error_convert_lib">Unable to convert library %s</string> <string name="error_convert_lib">Unable to convert library %s</string>
@ -92,7 +91,7 @@
<string name="mcl_option_about">About</string> <string name="mcl_option_about">About</string>
<string name="mcl_setting_title_setmaxdxref">Set max DX references</string> <string name="mcl_setting_title_setmaxdxref">Set max DX references</string>
<string name="mcl_setting_subtitle_setmaxdxref">Increase If an error happend while converting: Too many ... references. You may try multi-dex option.</string> <string name="mcl_setting_subtitle_setmaxdxref">Increase If an error happend while converting: Too many ... references. You may try multi-dex option. Recommended: 4096 or 8192.</string>
<string name="mcl_setting_title_freeform">Launch Minecraft in Freeform mode</string> <string name="mcl_setting_title_freeform">Launch Minecraft in Freeform mode</string>
<string name="mcl_setting_subtitle_freeform">Launch Minecraft in floating window. Requires Android 7.0+</string> <string name="mcl_setting_subtitle_freeform">Launch Minecraft in floating window. Requires Android 7.0+</string>
<string name="mcl_setting_title_longpresstrigger">How long will trigger after long press</string> <string name="mcl_setting_title_longpresstrigger">How long will trigger after long press</string>
@ -146,7 +145,7 @@
<string name="mcn_exit_call">Exit</string> <string name="mcn_exit_call">Exit</string>
<string name="mcn_exit_crash">Game Crash detected! Click OK to exit.</string> <string name="mcn_exit_crash">Game Crash detected! Click OK to exit.</string>
<string name="mcn_exit_errcrash">Unable to locate crash!</string> <string name="mcn_exit_errcrash">Unable to locate crash!</string>
<string name="mcn_exit_confirm">Are you sure want to force exit?</string> <string name="mcn_exit_confirm">Are you sure want to %s ?</string>
<!-- MainActivity: Control buttons --> <!-- MainActivity: Control buttons -->
<string name="controls">Controls</string> <string name="controls">Controls</string>
@ -170,7 +169,6 @@
<string name="control_mouseon">Mouse: on </string> <string name="control_mouseon">Mouse: on </string>
<!-- MainActivity: Menu advanced controls --> <!-- MainActivity: Menu advanced controls -->
<string name="control_forceclose">Force close</string>
<string name="control_viewout">Log output</string> <string name="control_viewout">Log output</string>
<string name="control_adebug">PointerCapture Debug</string> <string name="control_adebug">PointerCapture Debug</string>
<string name="control_customkey">Send custom keycode</string> <string name="control_customkey">Send custom keycode</string>
@ -179,6 +177,7 @@
<string name="control_more4"></string> <string name="control_more4"></string>
<string name="customctrl_keyname">LWJGL Keycode</string> <string name="customctrl_keyname">LWJGL Keycode</string>
<string name="customctrl_specialkey">Special Key</string>
<string name="customctrl_hidden">Hidden</string> <string name="customctrl_hidden">Hidden</string>
<!-- Update part (unused now) --> <!-- Update part (unused now) -->