mirror of
https://github.com/2009scape/2009Scape-mobile.git
synced 2025-12-21 09:01:56 -07:00
243 lines
9.2 KiB
Java
243 lines
9.2 KiB
Java
package net.kdt.pojavlaunch;
|
|
|
|
import android.app.*;
|
|
import android.content.*;
|
|
import android.text.*;
|
|
import android.text.method.*;
|
|
import android.view.*;
|
|
import android.widget.*;
|
|
import androidx.appcompat.app.*;
|
|
import com.kdt.pickafile.*;
|
|
import java.io.*;
|
|
import net.kdt.pojavlaunch.fragments.*;
|
|
import net.kdt.pojavlaunch.prefs.*;
|
|
import net.kdt.pojavlaunch.tasks.*;
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
|
import net.kdt.pojavlaunch.value.*;
|
|
|
|
public abstract class BaseLauncherActivity extends BaseActivity {
|
|
public Button mPlayButton;
|
|
public ConsoleFragment mConsoleView;
|
|
public CrashFragment mCrashView;
|
|
public ProgressBar mLaunchProgress;
|
|
public Spinner mVersionSelector;
|
|
public TextView mLaunchTextStatus, mTextVersion;
|
|
|
|
public JMinecraftVersionList mVersionList;
|
|
public MinecraftDownloaderTask mTask;
|
|
public MinecraftAccount mProfile;
|
|
public String[] mAvailableVersions;
|
|
|
|
public boolean mIsAssetsProcessing = false;
|
|
protected boolean canBack = false;
|
|
|
|
public abstract void statusIsLaunching(boolean isLaunching);
|
|
|
|
public void mcaccSwitchUser(View view) {
|
|
showProfileInfo();
|
|
}
|
|
|
|
public void mcaccLogout(View view) {
|
|
//PojavProfile.reset();
|
|
finish();
|
|
}
|
|
|
|
private void showProfileInfo() {
|
|
/*
|
|
new AlertDialog.Builder(this)
|
|
.setTitle("Info player")
|
|
.setMessage(
|
|
"AccessToken=" + profile.getAccessToken() + "\n" +
|
|
"ClientID=" + profile.getClientID() + "\n" +
|
|
"ProfileID=" + profile.getProfileID() + "\n" +
|
|
"Username=" + profile.getUsername() + "\n" +
|
|
"Version=" + profile.getVersion()
|
|
).show();
|
|
*/
|
|
}
|
|
|
|
public void launcherMenu(View view) {
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
builder.setTitle(R.string.mcl_options);
|
|
builder.setItems(R.array.mcl_options, new DialogInterface.OnClickListener(){
|
|
|
|
@Override
|
|
public void onClick(DialogInterface p1, int p2)
|
|
{
|
|
switch (p2) {
|
|
case 0: // Mod installer
|
|
installMod(false);
|
|
break;
|
|
case 1: // Mod installer with java args
|
|
installMod(true);
|
|
break;
|
|
case 2: // Custom controls
|
|
startActivity(new Intent(BaseLauncherActivity.this, CustomControlsActivity.class));
|
|
break;
|
|
case 3: // Settings
|
|
startActivity(new Intent(BaseLauncherActivity.this, LauncherPreferenceActivity.class));
|
|
break;
|
|
case 4: { // About
|
|
final AlertDialog.Builder aboutB = new AlertDialog.Builder(BaseLauncherActivity.this);
|
|
aboutB.setTitle(R.string.mcl_option_about);
|
|
try {
|
|
aboutB.setMessage(Html.fromHtml(String.format(Tools.read(getAssets().open("about_en.txt")),
|
|
Tools.APP_NAME,
|
|
BuildConfig.VERSION_NAME,
|
|
"3.2.3")
|
|
));
|
|
} catch (Exception e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
aboutB.setPositiveButton(android.R.string.ok, null);
|
|
AlertDialog aboutDialog = aboutB.show();
|
|
TextView aboutTv = aboutDialog.findViewById(android.R.id.message);
|
|
aboutTv.setMovementMethod(LinkMovementMethod.getInstance());
|
|
} break;
|
|
}
|
|
}
|
|
});
|
|
builder.show();
|
|
}
|
|
|
|
private void installMod(boolean customJavaArgs) {
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
builder.setTitle(R.string.alerttitle_installmod);
|
|
builder.setNegativeButton(android.R.string.cancel, null);
|
|
|
|
final AlertDialog dialog;
|
|
if (customJavaArgs) {
|
|
final EditText edit = new EditText(this);
|
|
edit.setSingleLine();
|
|
edit.setHint("-jar/-cp /path/to/file.jar ...");
|
|
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener(){
|
|
@Override
|
|
public void onClick(DialogInterface di, int i) {
|
|
Intent intent = new Intent(BaseLauncherActivity.this, JavaGUILauncherActivity.class);
|
|
intent.putExtra("skipDetectMod", true);
|
|
intent.putExtra("javaArgs", edit.getText().toString());
|
|
startActivity(intent);
|
|
}
|
|
});
|
|
dialog = builder.create();
|
|
dialog.setView(edit);
|
|
} else {
|
|
dialog = builder.create();
|
|
FileListView flv = new FileListView(dialog,"jar");
|
|
flv.setFileSelectedListener(new FileSelectedListener(){
|
|
@Override
|
|
public void onFileSelected(File file, String path) {
|
|
Intent intent = new Intent(BaseLauncherActivity.this, JavaGUILauncherActivity.class);
|
|
intent.putExtra("modFile", file);
|
|
startActivity(intent);
|
|
dialog.dismiss();
|
|
|
|
}
|
|
});
|
|
dialog.setView(flv);
|
|
}
|
|
dialog.show();
|
|
}
|
|
|
|
public void launchGame(View v) {
|
|
if (!canBack && mIsAssetsProcessing) {
|
|
mIsAssetsProcessing = false;
|
|
statusIsLaunching(false);
|
|
} else if (canBack) {
|
|
v.setEnabled(false);
|
|
mTask = new MinecraftDownloaderTask(this);
|
|
mTask.execute(mProfile.selectedVersion);
|
|
mCrashView.resetCrashLog = true;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onBackPressed() {
|
|
if (canBack) {
|
|
super.onBackPressed();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected void onPostResume() {
|
|
super.onPostResume();
|
|
System.out.println("call to onPostResume");
|
|
Tools.updateWindowSize(this);
|
|
System.out.println("call to onPostResume; E");
|
|
}
|
|
|
|
@Override
|
|
protected void onResume(){
|
|
super.onResume();
|
|
System.out.println("call to onResume");
|
|
final int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
|
|
final View decorView = getWindow().getDecorView();
|
|
decorView.setSystemUiVisibility(uiOptions);
|
|
System.out.println("call to onResume; E");
|
|
}
|
|
|
|
@Override
|
|
protected void onResumeFragments() {
|
|
super.onResumeFragments();
|
|
new RefreshVersionListTask(this).execute();
|
|
System.out.println("call to onResumeFragments");
|
|
try{
|
|
final ProgressDialog barrier = new ProgressDialog(this);
|
|
barrier.setMessage(getString(R.string.global_waiting));
|
|
barrier.setProgressStyle(barrier.STYLE_SPINNER);
|
|
barrier.setCancelable(false);
|
|
barrier.show();
|
|
|
|
new Thread(new Runnable(){
|
|
|
|
@Override
|
|
public void run()
|
|
{
|
|
while (mConsoleView == null) {
|
|
try {
|
|
Thread.sleep(20);
|
|
} catch (Throwable th) {}
|
|
}
|
|
|
|
try {
|
|
Thread.sleep(100);
|
|
} catch (Throwable th) {}
|
|
|
|
runOnUiThread(new Runnable() {
|
|
@Override
|
|
public void run()
|
|
{
|
|
try {
|
|
mConsoleView.putLog("");
|
|
barrier.dismiss();
|
|
} catch (Throwable th) {
|
|
startActivity(getIntent());
|
|
finish();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}).start();
|
|
|
|
File lastCrashFile = Tools.lastFileModified(Tools.DIR_HOME_CRASH);
|
|
if(CrashFragment.isNewCrash(lastCrashFile) || !mCrashView.getLastCrash().isEmpty()){
|
|
mCrashView.resetCrashLog = false;
|
|
selectTabPage(2);
|
|
} /*else throw new Exception();*/
|
|
} catch(Throwable e) {
|
|
e.printStackTrace();
|
|
// selectTabPage(tabLayout.getSelectedTabPosition());
|
|
}
|
|
System.out.println("call to onResumeFragments; E");
|
|
}
|
|
|
|
// Catching touch exception
|
|
@Override
|
|
public boolean onTouchEvent(MotionEvent event) {
|
|
return super.onTouchEvent(event);
|
|
}
|
|
|
|
protected abstract void selectTabPage(int pageIndex);
|
|
protected abstract float updateWidthHeight();
|
|
}
|