DummyLauncher Preferences

This commit is contained in:
downthecrop 2023-07-30 21:43:15 -07:00
parent 176bfbcef0
commit 1b30b48496
9 changed files with 175 additions and 41 deletions

View file

@ -2,6 +2,7 @@ package net.kdt.pojavlaunch;
import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
@ -15,7 +16,17 @@ import android.view.Window;
import android.widget.Button;
import android.widget.Toast;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.kdt.mcgui.ProgressLayout;
import net.kdt.pojavlaunch.extra.ExtraConstants;
import net.kdt.pojavlaunch.extra.ExtraCore;
import net.kdt.pojavlaunch.prefs.screens.LauncherPreferenceFragment;
import net.kdt.pojavlaunch.progresskeeper.ProgressKeeper;
import net.kdt.pojavlaunch.services.ProgressServiceKeeper;
import java.io.File;
import java.io.FileOutputStream;
@ -29,6 +40,8 @@ public class DummyLauncher extends BaseActivity {
private Button playSD;
private static final int FILE_SELECT_CODE_JSON = 0;
private static final int FILE_SELECT_CODE_ZIP = 1;
private ProgressServiceKeeper mProgressServiceKeeper;
private ProgressLayout mProgressLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -37,16 +50,30 @@ public class DummyLauncher extends BaseActivity {
fab = findViewById(R.id.myFab);
playHD = findViewById(R.id.playHD);
playSD = findViewById(R.id.playSD);
mProgressLayout = findViewById(R.id.progress_layout);
ProgressKeeper.addTaskCountListener((mProgressServiceKeeper = new ProgressServiceKeeper(this)));
ProgressKeeper.addTaskCountListener(mProgressLayout);
mProgressLayout.observe(ProgressLayout.UNPACK_RUNTIME);
mProgressLayout.observe(ProgressLayout.INSTALL_MODPACK);
playHD.setOnClickListener(view -> {
Log.i("downthecrop","hello from play HD touch");
// Launch MainActivity.java here and call runCraft()
if(mProgressLayout.hasProcesses()){
Toast.makeText(this, R.string.tasks_ongoing, Toast.LENGTH_LONG).show();
return;
}
Intent intent = new Intent(DummyLauncher.this, MainActivity.class);
startActivity(intent);
});
playSD.setOnClickListener(view -> {
Log.i("downthecrop","hello from play SD touch");
if(mProgressLayout.hasProcesses()){
Toast.makeText(this, R.string.tasks_ongoing, Toast.LENGTH_LONG).show();
return;
}
Intent intent = new Intent(DummyLauncher.this, JavaGUILauncherActivity.class);
startActivity(intent);
});
@ -57,33 +84,8 @@ public class DummyLauncher extends BaseActivity {
@SuppressLint("ClickableViewAccessibility")
private void showBottomDialog() {
final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.bottomsheetlayout);
dialog.show();
dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.getWindow().setGravity(Gravity.BOTTOM);
final Button loadConfig = dialog.findViewById(R.id.loadConfig);
final Button loadPlugin = dialog.findViewById(R.id.loadPlugin);
loadConfig.setOnTouchListener((v, event) -> {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
showFileChooser(FILE_SELECT_CODE_JSON);
return true;
}
return false;
});
loadPlugin.setOnTouchListener((v, event) -> {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
showFileChooser(FILE_SELECT_CODE_ZIP);
return true;
}
return false;
});
MyDialogFragment dialog = new MyDialogFragment();
dialog.show(getSupportFragmentManager(), "tag");
}
private void showFileChooser(int requestCode) {
@ -149,4 +151,9 @@ public class DummyLauncher extends BaseActivity {
super.onActivityResult(requestCode, resultCode, data);
}
@Override
protected void onDestroy() {
super.onDestroy();
ProgressKeeper.removeTaskCountListener(mProgressServiceKeeper);
}
}

View file

@ -0,0 +1,115 @@
package net.kdt.pojavlaunch;
import android.app.Dialog;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import net.kdt.pojavlaunch.extra.ExtraConstants;
import net.kdt.pojavlaunch.extra.ExtraCore;
import net.kdt.pojavlaunch.extra.ExtraListener;
import net.kdt.pojavlaunch.prefs.screens.LauncherPreferenceFragment;
public class MyDialogFragment extends DialogFragment {
private static final int FILE_SELECT_CODE_JSON = 0;
private static final int FILE_SELECT_CODE_ZIP = 1;
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Dialog dialog = new Dialog(getActivity());
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.bottomsheetlayout);
dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.getWindow().setGravity(Gravity.BOTTOM);
final Button loadConfig = dialog.findViewById(R.id.loadConfig);
final Button loadPlugin = dialog.findViewById(R.id.loadPlugin);
loadConfig.setOnTouchListener((v, event) -> {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
showFileChooser(FILE_SELECT_CODE_JSON);
return true;
}
return false;
});
loadPlugin.setOnTouchListener((v, event) -> {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
showFileChooser(FILE_SELECT_CODE_ZIP);
return true;
}
return false;
});
// Load the PreferenceFragment in the Dialog
FragmentManager fm = getChildFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
LauncherPreferenceFragment prefFragment = new LauncherPreferenceFragment();
ft.replace(R.id.prefContainer, prefFragment);
ft.commit();
ExtraCore.addExtraListener(ExtraConstants.BACK_PREFERENCE, mBackPreferenceListener);
return dialog;
}
/* Listener for the back button in settings */
private final ExtraListener<String> mBackPreferenceListener = (key, value) -> {
if(value.equals("true")) {
// This is a very messy way to do things but it works.
FragmentManager fm = getChildFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
LauncherPreferenceFragment prefFragment = new LauncherPreferenceFragment();
ft.replace(R.id.prefContainer, prefFragment);
ft.commit();
}
return false;
};
private void showFileChooser(int requestCode) {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
switch(requestCode){
case FILE_SELECT_CODE_JSON:
intent.setType("application/json");
intent.addCategory(Intent.CATEGORY_OPENABLE);
break;
case FILE_SELECT_CODE_ZIP:
intent.setType("application/zip");
intent.addCategory(Intent.CATEGORY_OPENABLE);
break;
default:
intent.setType("*/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
}
try {
startActivityForResult(
Intent.createChooser(intent, "Select a File to Upload"),
requestCode);
} catch (android.content.ActivityNotFoundException ex) {
// Potentially direct the user to the Market with a Dialog
Toast.makeText(this.getContext(), "Please install a File Manager.",
Toast.LENGTH_SHORT).show();
}
}
}

View file

@ -178,6 +178,8 @@ public final class Tools {
getCacioJavaArgs(javaArgList, runtime.javaVersion == 8);
javaArgList.add("-DpluginDir="+ Tools.DIR_DATA + "/plugins/");
javaArgList.add("-DglfwWidth="+CallbackBridge.windowWidth);
javaArgList.add("-DglfwHeight="+CallbackBridge.windowHeight);
javaArgList.add("-DconfigFile="+Tools.DIR_DATA + "/config.json");
javaArgList.add("-cp");
javaArgList.add(getLWJGL3ClassPath()+":"+Tools.DIR_DATA+"/rt4.jar");

View file

@ -1,10 +1,13 @@
package net.kdt.pojavlaunch.prefs;
import android.app.Activity;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import androidx.preference.Preference;
import net.kdt.pojavlaunch.LauncherActivity;
import net.kdt.pojavlaunch.R;
import net.kdt.pojavlaunch.extra.ExtraConstants;
import net.kdt.pojavlaunch.extra.ExtraCore;

View file

@ -22,7 +22,7 @@ public class LauncherPreferenceVideoFragment extends LauncherPreferenceFragment
addPreferencesFromResource(R.xml.pref_video);
//Disable notch checking behavior on android 8.1 and below.
findPreference("ignoreNotch").setVisible(Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && PREF_NOTCH_SIZE > 0);
findPreference("ignoreNotch").setVisible(Build.VERSION.SDK_INT >= Build.VERSION_CODES.P);
CustomSeekBarPreference seek5 = findPreference("resolutionRatio");
seek5.setMin(25);

View file

@ -61,4 +61,11 @@
app:layout_constraintEnd_toEndOf="@+id/imageView2"
tools:srcCompat="@tools:sample/avatars" />
<com.kdt.mcgui.ProgressLayout
android:id="@+id/progress_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -13,7 +13,13 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
android:orientation="vertical">
<FrameLayout
android:id="@+id/prefContainer"
android:layout_width="match_parent"
android:layout_height="400dp"
/>
<LinearLayout
android:layout_width="match_parent"
@ -73,10 +79,10 @@
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:hint="Username"
android:background="#6F000000"
android:textColor="#ffffff"
android:hint="Username"
android:padding="10dp"
android:textColor="#ffffff"
android:textSize="16sp" />
<com.google.android.material.textfield.TextInputEditText
@ -84,10 +90,10 @@
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="#6F000000"
android:hint="Password"
android:inputType="textPassword"
android:padding="10dp"
android:background="#6F000000"
android:textColor="#ffffff"
android:textSize="16sp" />
@ -197,16 +203,10 @@
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<ImageView
android:layout_width="70dp"
android:layout_height="wrap_content"
android:layout_gravity="center|top"
android:scaleType="centerCrop"
app:srcCompat="@drawable/ic_gamepad_pointer" />
</LinearLayout>