mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-15 07:39:00 -04:00
[WIP,NOT USEFUL] UI for Multi-runtime manager
This commit is contained in:
parent
ed5ef3c749
commit
7d00a2aee3
@ -2,14 +2,21 @@ package net.kdt.pojavlaunch;
|
||||
|
||||
import android.app.*;
|
||||
import android.content.*;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.provider.OpenableColumns;
|
||||
import android.text.*;
|
||||
import android.text.method.*;
|
||||
import android.view.*;
|
||||
import android.widget.*;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.*;
|
||||
import com.kdt.pickafile.*;
|
||||
import java.io.*;
|
||||
import net.kdt.pojavlaunch.fragments.*;
|
||||
import net.kdt.pojavlaunch.multirt.MultiRTConfigDialog;
|
||||
import net.kdt.pojavlaunch.multirt.MultiRTUtils;
|
||||
import net.kdt.pojavlaunch.prefs.*;
|
||||
import net.kdt.pojavlaunch.tasks.*;
|
||||
|
||||
@ -22,6 +29,7 @@ public abstract class BaseLauncherActivity extends BaseActivity {
|
||||
public CrashFragment mCrashView;
|
||||
public ProgressBar mLaunchProgress;
|
||||
public Spinner mVersionSelector;
|
||||
public MultiRTConfigDialog mRuntimeConfigDialog;
|
||||
public TextView mLaunchTextStatus, mTextVersion;
|
||||
|
||||
public JMinecraftVersionList mVersionList;
|
||||
@ -171,10 +179,12 @@ public abstract class BaseLauncherActivity extends BaseActivity {
|
||||
}
|
||||
}
|
||||
};
|
||||
LauncherPreferences.DEFAULT_PREF.registerOnSharedPreferenceChangeListener(listRefreshListener);
|
||||
}
|
||||
LauncherPreferences.DEFAULT_PREF.registerOnSharedPreferenceChangeListener(listRefreshListener);
|
||||
new RefreshVersionListTask(this).execute();
|
||||
System.out.println("call to onResumeFragments");
|
||||
mRuntimeConfigDialog = new MultiRTConfigDialog();
|
||||
mRuntimeConfigDialog.prepare(this);
|
||||
try{
|
||||
final ProgressDialog barrier = new ProgressDialog(this);
|
||||
barrier.setMessage(getString(R.string.global_waiting));
|
||||
@ -224,7 +234,61 @@ public abstract class BaseLauncherActivity extends BaseActivity {
|
||||
}
|
||||
System.out.println("call to onResumeFragments; E");
|
||||
}
|
||||
|
||||
public String getFileName(Uri uri) {
|
||||
String result = null;
|
||||
if (uri.getScheme().equals("content")) {
|
||||
Cursor cursor = getContentResolver().query(uri, null, null, null, null);
|
||||
try {
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
|
||||
}
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
if (result == null) {
|
||||
result = uri.getPath();
|
||||
int cut = result.lastIndexOf('/');
|
||||
if (cut != -1) {
|
||||
result = result.substring(cut + 1);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||
super.onActivityResult(requestCode,resultCode,data);
|
||||
if(requestCode == MultiRTConfigDialog.MULTIRT_PICK_RUNTIME && resultCode == Activity.RESULT_OK) {
|
||||
if (data != null) {
|
||||
final Uri uri = data.getData();
|
||||
final ProgressDialog barrier = new ProgressDialog(this);
|
||||
barrier.setMessage(getString(R.string.global_waiting));
|
||||
barrier.setProgressStyle(barrier.STYLE_SPINNER);
|
||||
barrier.setCancelable(false);
|
||||
barrier.show();
|
||||
Thread t = new Thread(()->{
|
||||
try {
|
||||
MultiRTUtils.installRuntimeNamed(getContentResolver().openInputStream(uri), getFileName(uri),
|
||||
(resid, stuff) -> BaseLauncherActivity.this.runOnUiThread(
|
||||
() -> barrier.setMessage(BaseLauncherActivity.this.getString(resid,stuff))));
|
||||
}catch (IOException e) {
|
||||
Tools.showError(BaseLauncherActivity.this
|
||||
,e);
|
||||
}
|
||||
BaseLauncherActivity.this.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
barrier.dismiss();
|
||||
mRuntimeConfigDialog.refresh();
|
||||
mRuntimeConfigDialog.dialog.show();
|
||||
}
|
||||
});
|
||||
});
|
||||
t.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Catching touch exception
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
|
@ -0,0 +1,49 @@
|
||||
package net.kdt.pojavlaunch.multirt;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import net.kdt.pojavlaunch.BaseLauncherActivity;
|
||||
import net.kdt.pojavlaunch.R;
|
||||
|
||||
public class MultiRTConfigDialog {
|
||||
public static final int MULTIRT_PICK_RUNTIME = 2048;
|
||||
public static final int MULTIRT_PICK_RUNTIME_NORETURN = 2049;
|
||||
public AlertDialog dialog;
|
||||
public RecyclerView dialogView;
|
||||
public void prepare(BaseLauncherActivity ctx) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
|
||||
builder.setTitle(R.string.multirt_config_title);
|
||||
dialogView = new RecyclerView(ctx);
|
||||
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(ctx);
|
||||
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
|
||||
dialogView.setLayoutManager(linearLayoutManager);
|
||||
dialogView.setAdapter(new RTRecyclerViewAdapter(this));
|
||||
builder.setView(dialogView);
|
||||
builder.setPositiveButton(R.string.multirt_config_add, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
/* Initialte import */
|
||||
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
intent.setType("application/x-xz");
|
||||
ctx.startActivityForResult(intent,MULTIRT_PICK_RUNTIME);
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.mcn_exit_call, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
dialog = builder.create();
|
||||
}
|
||||
public void refresh() {
|
||||
dialogView.getAdapter().notifyDataSetChanged();
|
||||
}
|
||||
}
|
@ -1,7 +1,8 @@
|
||||
package net.kdt.pojavlaunch.utils;
|
||||
package net.kdt.pojavlaunch.multirt;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.system.Os;
|
||||
import android.util.Log;
|
||||
|
||||
import net.kdt.pojavlaunch.R;
|
||||
import net.kdt.pojavlaunch.Tools;
|
||||
@ -32,25 +33,31 @@ public class MultiRTUtils {
|
||||
public String versionString;
|
||||
public int javaVersion;
|
||||
}
|
||||
public static interface ProgressReporterThingy {
|
||||
void reportStringProgress(int resid, Object ... stuff);
|
||||
}
|
||||
private static File runtimeFolder = new File(Tools.MULTIRT_HOME);
|
||||
private static final String JAVA_VERSION_str = "JAVA_VERSION=\"";
|
||||
public static List<Runtime> getRuntimes() {
|
||||
ArrayList<Runtime> ret = new ArrayList<>();
|
||||
System.out.println("Fetch runtime list");
|
||||
for(File f : runtimeFolder.listFiles()) {
|
||||
ret.add(read(f.getName()));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
public static Runtime installRuntimeNamed(InputStream runtimeInputStream, String name) throws IOException {
|
||||
public static Runtime installRuntimeNamed(InputStream runtimeInputStream, String name, ProgressReporterThingy thingy) throws IOException {
|
||||
File dest = new File(runtimeFolder,"/"+name);
|
||||
File tmp = new File(dest,"temporary");
|
||||
if(dest.exists()) FileUtils.deleteDirectory(dest);
|
||||
dest.mkdirs();
|
||||
FileOutputStream fos = new FileOutputStream(tmp);
|
||||
thingy.reportStringProgress(R.string.multirt_progress_caching);
|
||||
IOUtils.copy(runtimeInputStream,fos);
|
||||
fos.close();
|
||||
runtimeInputStream.close();
|
||||
uncompressTarXZ(tmp,dest);
|
||||
uncompressTarXZ(tmp,dest,thingy);
|
||||
tmp.delete();
|
||||
return read(name);
|
||||
}
|
||||
@ -74,17 +81,17 @@ public class MultiRTUtils {
|
||||
if(_JAVA_VERSION_index != -1) {
|
||||
_JAVA_VERSION_index += JAVA_VERSION_str.length();
|
||||
String javaVersion = content.substring(_JAVA_VERSION_index,content.indexOf('"',_JAVA_VERSION_index));
|
||||
String[] javaVersionSplit = javaVersion.split(".");
|
||||
int javaVersionInt;
|
||||
if(javaVersionSplit[0].equals("1")) {
|
||||
javaVersionInt = Integer.parseInt(javaVersionSplit[1]);
|
||||
}else{
|
||||
javaVersionInt = Integer.parseInt(javaVersionSplit[0]);
|
||||
}
|
||||
Runtime r = new Runtime(name);
|
||||
r.javaVersion = javaVersionInt;
|
||||
r.versionString = javaVersion;
|
||||
retur = r;
|
||||
String[] javaVersionSplit = javaVersion.split("\\.");
|
||||
int javaVersionInt;
|
||||
if (javaVersionSplit[0].equals("1")) {
|
||||
javaVersionInt = Integer.parseInt(javaVersionSplit[1]);
|
||||
} else {
|
||||
javaVersionInt = Integer.parseInt(javaVersionSplit[0]);
|
||||
}
|
||||
Runtime r = new Runtime(name);
|
||||
r.javaVersion = javaVersionInt;
|
||||
r.versionString = javaVersion;
|
||||
retur = r;
|
||||
}else{
|
||||
retur = new Runtime(name);
|
||||
}
|
||||
@ -94,7 +101,7 @@ public class MultiRTUtils {
|
||||
cache.put(name,retur);
|
||||
return retur;
|
||||
}
|
||||
private static void uncompressTarXZ(final File tarFile, final File dest) throws IOException {
|
||||
private static void uncompressTarXZ(final File tarFile, final File dest, final ProgressReporterThingy thingy) throws IOException {
|
||||
dest.mkdirs();
|
||||
TarArchiveInputStream tarIn = null;
|
||||
|
||||
@ -121,6 +128,7 @@ public class MultiRTUtils {
|
||||
}
|
||||
final String tarEntryName = tarEntry.getName();
|
||||
// publishProgress(null, "Unpacking " + tarEntry.getName());
|
||||
thingy.reportStringProgress(R.string.global_unpacking,tarEntryName);
|
||||
File destPath = new File(dest, tarEntry.getName());
|
||||
if (tarEntry.isSymbolicLink()) {
|
||||
destPath.getParentFile().mkdirs();
|
@ -0,0 +1,96 @@
|
||||
package net.kdt.pojavlaunch.multirt;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Color;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import net.kdt.pojavlaunch.R;
|
||||
import net.kdt.pojavlaunch.Tools;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class RTRecyclerViewAdapter extends RecyclerView.Adapter {
|
||||
MultiRTConfigDialog dialog;
|
||||
public RTRecyclerViewAdapter(MultiRTConfigDialog dialog) {
|
||||
this.dialog = dialog;
|
||||
}
|
||||
@NonNull
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View recyclableView = LayoutInflater.from(parent.getContext()).inflate(R.layout.multirt_recyclable_view,parent,false);
|
||||
return new RTViewHolder(recyclableView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
||||
final List<MultiRTUtils.Runtime> runtimes = MultiRTUtils.getRuntimes();
|
||||
((RTViewHolder)holder).bindRuntime(runtimes.get(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return MultiRTUtils.getRuntimes().size();
|
||||
}
|
||||
public class RTViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
|
||||
final TextView javaVersionView;
|
||||
final TextView fullJavaVersionView;
|
||||
final ColorStateList defaultColors;
|
||||
final Context ctx;
|
||||
MultiRTUtils.Runtime currentRuntime;
|
||||
public RTViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
javaVersionView = itemView.findViewById(R.id.multirt_view_java_version);
|
||||
fullJavaVersionView = itemView.findViewById(R.id.multirt_view_java_version_full);
|
||||
itemView.findViewById(R.id.multirt_view_removebtn).setOnClickListener(this);
|
||||
defaultColors = fullJavaVersionView.getTextColors();
|
||||
ctx = itemView.getContext();
|
||||
}
|
||||
public void bindRuntime(MultiRTUtils.Runtime rt) {
|
||||
currentRuntime = rt;
|
||||
if(rt.versionString != null) {
|
||||
javaVersionView.setText(ctx.getString(R.string.multirt_java_ver, rt.name, rt.javaVersion));
|
||||
fullJavaVersionView.setText(rt.versionString);
|
||||
fullJavaVersionView.setTextColor(defaultColors);
|
||||
|
||||
}else{
|
||||
javaVersionView.setText(rt.name);
|
||||
fullJavaVersionView.setText(R.string.multirt_runtime_corrupt);
|
||||
fullJavaVersionView.setTextColor(Color.RED);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (currentRuntime != null) {
|
||||
final ProgressDialog barrier = new ProgressDialog(ctx);
|
||||
barrier.setMessage(ctx.getString(R.string.global_waiting));
|
||||
barrier.setProgressStyle(barrier.STYLE_SPINNER);
|
||||
barrier.setCancelable(false);
|
||||
barrier.show();
|
||||
Thread t = new Thread(()->{
|
||||
try {
|
||||
MultiRTUtils.removeRuntimeNamed(currentRuntime.name);
|
||||
}catch (IOException e) {
|
||||
Tools.showError(itemView.getContext(),e);
|
||||
}
|
||||
v.post(() ->{
|
||||
barrier.dismiss();
|
||||
RTRecyclerViewAdapter.this.notifyDataSetChanged();
|
||||
dialog.dialog.show();
|
||||
});
|
||||
});
|
||||
t.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package net.kdt.pojavlaunch.prefs;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import net.kdt.pojavlaunch.BaseLauncherActivity;
|
||||
import net.kdt.pojavlaunch.multirt.MultiRTConfigDialog;
|
||||
|
||||
public class RuntimeManagerPreference extends Preference{
|
||||
public RuntimeManagerPreference(Context ctx) {
|
||||
this(ctx, null);
|
||||
}
|
||||
|
||||
public RuntimeManagerPreference(Context ctx, AttributeSet attrs) {
|
||||
super(ctx, attrs);
|
||||
setPersistent(false);
|
||||
}
|
||||
@Override
|
||||
protected void onClick() {
|
||||
super.onClick();
|
||||
((BaseLauncherActivity)this.getContext()).mRuntimeConfigDialog.dialog.show();
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/multirt_view_java_version"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:text="Java 8"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.0" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/multirt_view_java_version_full"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="4dp"
|
||||
android:text="1.8.0_292"
|
||||
android:textSize="10sp"
|
||||
app:layout_constraintStart_toStartOf="@+id/multirt_view_java_version"
|
||||
app:layout_constraintTop_toBottomOf="@+id/multirt_view_java_version" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/multirt_view_removebtn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="8dp"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/multirt_view_java_version_full"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@+id/multirt_view_java_version"
|
||||
app:srcCompat="@drawable/ic_remove" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -211,4 +211,12 @@
|
||||
<string name="memory_warning_msg">The current amount of free RAM (%d) is lower than allocated RAM (%d), which may lead to crashes. Change the allocation if the game crashes.</string>
|
||||
<string name="mcl_memory_allocation">Memory allocation</string>
|
||||
<string name="mcl_memory_allocation_subtitle">Controls how much memory is given to Minecraft</string>
|
||||
<string name="multirt_java_ver">%s (Java %d)</string>
|
||||
<string name="multirt_runtime_corrupt">Corrupted Java Runtime</string>
|
||||
<string name="multirt_config_title">Java VMs</string>
|
||||
<string name="multirt_config_add">Add new</string>
|
||||
<string name="multirt_config_add_subtitle">Import new Java VM</string>
|
||||
<string name="multirt_title">Runtime Manager</string>
|
||||
<string name="multirt_subtitle">Manage installed Java VMs</string>
|
||||
<string name="multirt_progress_caching">Caching...</string>
|
||||
</resources>
|
||||
|
@ -10,7 +10,9 @@
|
||||
android:summary="@string/mcl_setting_subtitle_uninstalljre"
|
||||
android:title="@string/mcl_setting_title_uninstalljre"
|
||||
app2:icon="@drawable/rm_jre" />
|
||||
|
||||
<net.kdt.pojavlaunch.prefs.RuntimeManagerPreference
|
||||
android:summary="@string/multirt_subtitle"
|
||||
android:title="@string/multirt_title"/>
|
||||
<androidx.preference.ListPreference
|
||||
android:title="@string/mcl_setting_category_renderer"
|
||||
android:key="renderer"
|
||||
|
Loading…
x
Reference in New Issue
Block a user