From bff078c5f39789588470d839f458290c54291e81 Mon Sep 17 00:00:00 2001 From: Vera-Firefly <1964762970@qq.com> Date: Tue, 29 Oct 2024 10:31:38 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4[UI]:=20=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E7=95=8C=E9=9D=A2=E7=9A=84=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E9=A1=BA=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../firefly/ui/prefs/ChooseMesaListPref.java} | 6 +- .../LauncherPreferenceControlFragment.java | 64 +++- ...auncherPreferenceExperimentalFragment.java | 310 ---------------- .../LauncherPreferenceLauncherFragment.java | 55 --- ...uncherPreferenceMiscellaneousFragment.java | 38 -- .../LauncherPreferenceVideoFragment.java | 336 +++++++++++++++++- .../src/main/res/xml/pref_control.xml | 65 +++- .../src/main/res/xml/pref_experimental.xml | 136 ------- .../src/main/res/xml/pref_launcher.xml | 42 ++- .../src/main/res/xml/pref_main.xml | 25 +- .../src/main/res/xml/pref_misc.xml | 30 +- .../src/main/res/xml/pref_video.xml | 166 ++++++++- 12 files changed, 655 insertions(+), 618 deletions(-) rename app_pojavlauncher/src/main/java/{net/kdt/pojavlaunch/prefs/DeletableListPreference.java => com/firefly/ui/prefs/ChooseMesaListPref.java} (95%) delete mode 100644 app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceExperimentalFragment.java delete mode 100644 app_pojavlauncher/src/main/res/xml/pref_experimental.xml diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/DeletableListPreference.java b/app_pojavlauncher/src/main/java/com/firefly/ui/prefs/ChooseMesaListPref.java similarity index 95% rename from app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/DeletableListPreference.java rename to app_pojavlauncher/src/main/java/com/firefly/ui/prefs/ChooseMesaListPref.java index 4ccbe8ab0..0e4020d1b 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/DeletableListPreference.java +++ b/app_pojavlauncher/src/main/java/com/firefly/ui/prefs/ChooseMesaListPref.java @@ -1,4 +1,4 @@ -package net.kdt.pojavlaunch.prefs; +package com.firefly.ui.prefs; import android.content.Context; import android.util.AttributeSet; @@ -15,12 +15,12 @@ import java.util.Arrays; import java.util.List; -public class DeletableListPreference extends ListPreference { +public class ChooseMesaListPref extends ListPreference { private List defaultLibs; private OnPreferenceChangeListener preferenceChangeListener; - public DeletableListPreference(Context context, AttributeSet attrs) { + public ChooseMesaListPref(Context context, AttributeSet attrs) { super(context, attrs); loadDefaultLibs(context); } diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceControlFragment.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceControlFragment.java index 2954b0605..df8c993d0 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceControlFragment.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceControlFragment.java @@ -1,22 +1,62 @@ package net.kdt.pojavlaunch.prefs.screens; +import android.app.Activity; +import android.content.Intent; import android.content.Context; import android.content.SharedPreferences; import android.hardware.Sensor; import android.hardware.SensorManager; +import android.net.Uri; import android.os.Bundle; +import android.widget.Toast; +import androidx.activity.result.ActivityResultLauncher; +import androidx.activity.result.contract.ActivityResultContracts; import androidx.preference.PreferenceCategory; import net.kdt.pojavlaunch.R; import net.kdt.pojavlaunch.prefs.CustomSeekBarPreference; import net.kdt.pojavlaunch.prefs.LauncherPreferences; +import net.kdt.pojavlaunch.Tools; + +import org.apache.commons.io.IOUtils; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.InputStream; public class LauncherPreferenceControlFragment extends LauncherPreferenceFragment { private boolean mGyroAvailable = false; + private ActivityResultLauncher mouseSettingLauncher; @Override public void onCreatePreferences(Bundle b, String str) { + // Initialize the ActivityResultLauncher for picking an image + mouseSettingLauncher = registerForActivityResult( + new ActivityResultContracts.StartActivityForResult(), + result -> { + if (result.getResultCode() == Activity.RESULT_OK && result.getData() != null) { + Uri currentUri = result.getData().getData(); + try { + File file = new File(Tools.DIR_GAME_HOME, "mouse"); + if (file.exists()) { + file.delete(); + } + + InputStream stream1 = getContext().getContentResolver().openInputStream(currentUri); + FileOutputStream stream = new FileOutputStream(file); + + IOUtils.copy(stream1, stream); + stream.close(); + stream1.close(); + Toast.makeText(getContext(), R.string.notif_mouse, Toast.LENGTH_SHORT).show(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + } + ); + // Get values int longPressTrigger = LauncherPreferences.PREF_LONGPRESS_TRIGGER; int prefButtonSize = (int) LauncherPreferences.PREF_BUTTONSIZE; @@ -26,8 +66,7 @@ public void onCreatePreferences(Bundle b, String str) { float gyroSpeed = LauncherPreferences.PREF_GYRO_SENSITIVITY; float joystickDeadzone = LauncherPreferences.PREF_DEADZONE_SCALE; - - //Triggers a write for some reason which resets the value + // Triggers a write for some reason which resets the value addPreferencesFromResource(R.xml.pref_control); CustomSeekBarPreference seek2 = requirePreference("timeLongPressTrigger", @@ -80,6 +119,24 @@ public void onCreatePreferences(Bundle b, String str) { gyroSampleRateSeek.setRange(5, 50); gyroSampleRateSeek.setValue(gyroSampleRate); gyroSampleRateSeek.setSuffix(" ms"); + + // Custom Mouse + findPreference("control_mouse_setting").setOnPreferenceClickListener(preference -> { + Intent intent = new Intent(Intent.ACTION_PICK); + intent.setType("image/*"); + mouseSettingLauncher.launch(intent); + return true; + }); + + findPreference("control_mouse_remove").setOnPreferenceClickListener(preference -> { + File file = new File(Tools.DIR_GAME_HOME, "mouse"); + if (file.exists()) { + file.delete(); + } + Toast.makeText(getContext(), R.string.notif_mouse1, Toast.LENGTH_SHORT).show(); + return true; + }); + computeVisibility(); } @@ -97,5 +154,4 @@ private void computeVisibility() { requirePreference("gyroInvertY").setVisible(LauncherPreferences.PREF_ENABLE_GYRO); requirePreference("gyroSmoothing").setVisible(LauncherPreferences.PREF_ENABLE_GYRO); } - -} +} \ No newline at end of file diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceExperimentalFragment.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceExperimentalFragment.java deleted file mode 100644 index d9888d8ad..000000000 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceExperimentalFragment.java +++ /dev/null @@ -1,310 +0,0 @@ -package net.kdt.pojavlaunch.prefs.screens; - -import android.content.SharedPreferences; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.widget.EditText; -import android.widget.Toast; - -import androidx.appcompat.app.AlertDialog; -import androidx.preference.ListPreference; -import androidx.preference.Preference; -import androidx.preference.PreferenceCategory; -import androidx.preference.SwitchPreference; - -import com.firefly.ui.dialog.CustomDialog; - -import net.kdt.pojavlaunch.PojavApplication; -import net.kdt.pojavlaunch.R; -import net.kdt.pojavlaunch.Tools; -import net.kdt.pojavlaunch.prefs.DeletableListPreference; -import net.kdt.pojavlaunch.prefs.LauncherPreferences; -import net.kdt.pojavlaunch.utils.MesaUtils; - -import java.util.Set; - -// Experimental Settings for Mesa renderer -public class LauncherPreferenceExperimentalFragment extends LauncherPreferenceFragment { - - private EditText mMesaGLVersion; - private EditText mMesaGLSLVersion; - private String expRenderer; - - @Override - public void onCreatePreferences(Bundle b, String str) { - addPreferencesFromResource(R.xml.pref_experimental); - computeVisibility(); - - final Preference downloadMesa = requirePreference("DownloadMesa", Preference.class); - downloadMesa.setOnPreferenceClickListener((a) -> { - loadMesaList(); - return true; - }); - - final DeletableListPreference CMesaLibP = requirePreference("CMesaLibrary", DeletableListPreference.class); - final ListPreference CDriverModelP = requirePreference("CDriverModels", ListPreference.class); - final ListPreference CMesaLDOP = requirePreference("ChooseMldo", ListPreference.class); - - setListPreference(CMesaLibP, "CMesaLibrary"); - setListPreference(CDriverModelP, "CDriverModels"); - setListPreference(CMesaLDOP, "ChooseMldo"); - - CMesaLibP.setOnPreferenceChangeListener((pre, obj) -> { - Tools.MESA_LIBS = (String) obj; - setListPreference(CDriverModelP, "CDriverModels"); - CDriverModelP.setValueIndex(0); - return true; - }); - - CDriverModelP.setOnPreferenceChangeListener((pre, obj) -> { - Tools.DRIVER_MODEL = (String) obj; - return true; - }); - - CMesaLDOP.setOnPreferenceChangeListener((pre, obj) -> { - Tools.LOADER_OVERRIDE = (String) obj; - return true; - }); - - SwitchPreference expRendererPref = requirePreference("ExperimentalSetup", SwitchPreference.class); - expRendererPref.setOnPreferenceChangeListener((p, v) -> { - onChangeRenderer(); - boolean isExpRenderer = (boolean) v; - if (isExpRenderer) { - onExpRendererDialog(p); - } - return true; - }); - - // Custom GL/GLSL - final PreferenceCategory customMesaVersionPref = requirePreference("customMesaVersionPref", PreferenceCategory.class); - SwitchPreference setSystemVersion = requirePreference("ebSystem", SwitchPreference.class); - setSystemVersion.setOnPreferenceChangeListener((p, v) -> { - boolean set = (boolean) v; - if (!set) return false; - closeOtherCustomMesaPref(customMesaVersionPref); - return true; - }); - - SwitchPreference setSpecificVersion = requirePreference("ebSpecific", SwitchPreference.class); - setSpecificVersion.setOnPreferenceChangeListener((p, v) -> { - boolean set = (boolean) v; - if (!set) return false; - closeOtherCustomMesaPref(customMesaVersionPref); - return true; - }); - - SwitchPreference setGLVersion = requirePreference("ebCustom", SwitchPreference.class); - setGLVersion.setOnPreferenceChangeListener((p, v) -> { - boolean set = (boolean) v; - if (!set) return false; - closeOtherCustomMesaPref(customMesaVersionPref); - return true; - }); - setGLVersion.setOnPreferenceClickListener(preference -> { - showSetGLVersionDialog(); - return true; - }); - - } - - @Override - public void onSharedPreferenceChanged(SharedPreferences p, String s) { - super.onSharedPreferenceChanged(p, s); - computeVisibility(); - } - - private void computeVisibility() { - requirePreference("SpareFrameBuffer").setVisible(LauncherPreferences.PREF_EXP_SETUP); - requirePreference("MesaRendererChoose").setVisible(LauncherPreferences.PREF_EXP_SETUP); - requirePreference("customMesaVersionPref").setVisible(LauncherPreferences.PREF_EXP_SETUP); - requirePreference("customMesaLoaderDriverOverride").setVisible(LauncherPreferences.PREF_EXP_SETUP); - requirePreference("ChooseMldo").setVisible(LauncherPreferences.PREF_LOADER_OVERRIDE); - } - - private void setListPreference(ListPreference listPreference, String preferenceKey) { - Tools.IListAndArry array = null; - String value = listPreference.getValue(); - if (preferenceKey.equals("CMesaLibrary")) { - array = Tools.getCompatibleCMesaLib(getContext()); - boolean have = false; - for (int a = 0; a < array.getList().size(); a++) { - if (array.getList().get(a).equalsIgnoreCase(value)) { - have = true; - break; - } - } - if (!have) { - value = array.getList().get(0); - listPreference.setValue(value); - } - Tools.MESA_LIBS = value; - } else if (preferenceKey.equals("CDriverModels")) { - array = Tools.getCompatibleCDriverModel(getContext()); - Tools.DRIVER_MODEL = value; - } else if (preferenceKey.equals("ChooseMldo")) { - array = Tools.getCompatibleCMesaLDO(getContext()); - Tools.LOADER_OVERRIDE = value; - } - listPreference.setEntries(array.getArray()); - listPreference.setEntryValues(array.getList().toArray(new String[0])); - } - - private void closeOtherCustomMesaPref(PreferenceCategory customMesaVersionPref) { - for (int i = 0; i < customMesaVersionPref.getPreferenceCount(); i++) { - Preference closepref = customMesaVersionPref.getPreference(i); - if (closepref instanceof SwitchPreference) { - ((SwitchPreference) closepref).setChecked(false); - } - } - } - - private void onExpRendererDialog(Preference pre) { - new CustomDialog.Builder(getContext()) - .setTitle(getString(R.string.preference_rendererexp_alertdialog_warning)) - .setMessage(getString(R.string.preference_rendererexp_alertdialog_message)) - .setConfirmListener(R.string.preference_rendererexp_alertdialog_done, customView -> true) - .setCancelListener(R.string.preference_rendererexp_alertdialog_cancel, customView -> { - onChangeRenderer(); - ((SwitchPreference) pre).setChecked(false); - return true; - }) - .setCancelable(false) - .setDraggable(true) - .build() - .show(); - } - - // Custom Mesa GL/GLSL Version - private void showSetGLVersionDialog() { - LayoutInflater inflater = requireActivity().getLayoutInflater(); - View view = inflater.inflate(R.layout.dialog_mesa_version, null); - - mMesaGLVersion = view.findViewById(R.id.mesa_gl_version); - mMesaGLSLVersion = view.findViewById(R.id.mesa_glsl_version); - - mMesaGLVersion.setText(LauncherPreferences.PREF_MESA_GL_VERSION); - mMesaGLSLVersion.setText(LauncherPreferences.PREF_MESA_GLSL_VERSION); - - new CustomDialog.Builder(getContext()) - .setCustomView(view) - .setCancelable(false) - .setConfirmListener(R.string.alertdialog_done, customView -> { - String glVersion = mMesaGLVersion.getText().toString(); - String glslVersion = mMesaGLSLVersion.getText().toString(); - - boolean validGLVersion = isValidVersion(glVersion, "2.8", "4.6"); - boolean validGLSLVersion = isValidVersion(glslVersion, "280", "460"); - - if (!validGLVersion || !validGLSLVersion) { - if (!validGLVersion) { - mMesaGLVersion.setError(getString(R.string.customglglsl_alertdialog_error_gl)); - mMesaGLVersion.requestFocus(); - } - if (!validGLSLVersion) { - mMesaGLSLVersion.setError(getString(R.string.customglglsl_alertdialog_error_glsl)); - mMesaGLSLVersion.requestFocus(); - } - return false; - } - - LauncherPreferences.PREF_MESA_GL_VERSION = glVersion; - LauncherPreferences.PREF_MESA_GLSL_VERSION = glslVersion; - - LauncherPreferences.DEFAULT_PREF.edit() - .putString("mesaGLVersion", LauncherPreferences.PREF_MESA_GL_VERSION) - .putString("mesaGLSLVersion", LauncherPreferences.PREF_MESA_GLSL_VERSION) - .apply(); - - return true; - }) - .setCancelListener(R.string.alertdialog_cancel, customView -> true) - .setDraggable(true) - .build() - .show(); - } - - // Check whether the GL/GLSL version is within the acceptable range - private boolean isValidVersion(String version, String minVersion, String maxVersion) { - try { - float versionNumber = Float.parseFloat(version); - float minVersionNumber = Float.parseFloat(minVersion); - float maxVersionNumber = Float.parseFloat(maxVersion); - - return versionNumber >= minVersionNumber && versionNumber <= maxVersionNumber; - } catch (NumberFormatException e) { - return false; - } - } - - private void onChangeRenderer() { - String rendererValue = LauncherPreferences.DEFAULT_PREF.getString("renderer", null); - if ("mesa_3d".equals(rendererValue)) { - LauncherPreferences.DEFAULT_PREF.edit().putString("renderer", expRenderer).apply(); - } else if ("vulkan_zink".equals(rendererValue) - || "virglrenderer".equals(rendererValue) - || "freedreno".equals(rendererValue) - || "panfrost".equals(rendererValue)) { - expRenderer = LauncherPreferences.DEFAULT_PREF.getString("renderer", null); - LauncherPreferences.DEFAULT_PREF.edit().putString("renderer", "mesa_3d").apply(); - } - } - - private void loadMesaList() { - AlertDialog dialog = new AlertDialog.Builder(requireContext()) - .setMessage(R.string.preference_rendererexp_mesa_download_load) - .show(); - PojavApplication.sExecutorService.execute(() -> { - Set list = MesaUtils.INSTANCE.getMesaList(); - requireActivity().runOnUiThread(() -> { - dialog.dismiss(); - - if (list == null) { - AlertDialog alertDialog1 = new AlertDialog.Builder(requireActivity()) - .setMessage(R.string.preference_rendererexp_mesa_get_fail) - .create(); - alertDialog1.show(); - } else { - final String[] items3 = new String[list.size()]; - list.toArray(items3); - // Add List - AlertDialog alertDialog3 = new AlertDialog.Builder(requireActivity()) - .setTitle(R.string.preference_rendererexp_mesa_select_download) - .setItems(items3, (dialogInterface, i) -> { - if (i < 0 || i > items3.length) - return; - dialogInterface.dismiss(); - downloadMesa(items3[i]); - }) - .create(); - alertDialog3.show(); - } - }); - }); - } - - private void downloadMesa(String version) { - AlertDialog dialog = new AlertDialog.Builder(requireContext()) - .setMessage(R.string.preference_rendererexp_mesa_downloading) - .setCancelable(false) - .show(); - PojavApplication.sExecutorService.execute(() -> { - boolean data = MesaUtils.INSTANCE.downloadMesa(version); - requireActivity().runOnUiThread(() -> { - dialog.dismiss(); - if (data) { - Toast.makeText(requireContext(), R.string.preference_rendererexp_mesa_downloaded, Toast.LENGTH_SHORT) - .show(); - setListPreference(requirePreference("CMesaLibrary", DeletableListPreference.class), "CMesaLibrary"); - } else { - AlertDialog alertDialog1 = new AlertDialog.Builder(requireActivity()) - .setMessage(R.string.preference_rendererexp_mesa_download_fail) - .create(); - alertDialog1.show(); - } - }); - }); - } - -} diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceLauncherFragment.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceLauncherFragment.java index 93926ece0..dd65f4f97 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceLauncherFragment.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceLauncherFragment.java @@ -1,45 +1,18 @@ package net.kdt.pojavlaunch.prefs.screens; -import android.app.Activity; -import android.content.Intent; -import android.net.Uri; import android.os.Bundle; -import android.widget.Toast; import androidx.preference.Preference; import com.firefly.feature.UpdateLauncher; import net.kdt.pojavlaunch.R; -import net.kdt.pojavlaunch.Tools; - -import org.apache.commons.io.IOUtils; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.InputStream; public class LauncherPreferenceLauncherFragment extends LauncherPreferenceFragment { @Override public void onCreatePreferences(Bundle b, String str) { addPreferencesFromResource(R.xml.pref_launcher); - findPreference("control_mouse_setting").setOnPreferenceClickListener((preference) -> { - Intent intent = new Intent(Intent.ACTION_PICK); - intent.setType("image/*"); - startActivityForResult(intent, 1); - return true; - }); - - findPreference("control_mouse_remove").setOnPreferenceClickListener((preference) -> { - File file = new File(Tools.DIR_GAME_HOME, "mouse"); - if (file.exists()) { - file.delete(); - } - Toast.makeText(getContext(), R.string.notif_mouse1, Toast.LENGTH_SHORT).show(); - return true; - }); - Preference updatePreference = requirePreference("update_launcher"); updatePreference.setOnPreferenceClickListener(preference -> { UpdateLauncher updateLauncher = new UpdateLauncher(getContext()); @@ -49,32 +22,4 @@ public void onCreatePreferences(Bundle b, String str) { } - @Override - public void onActivityResult( - int requestCode, int resultCode, final Intent data) { - if (resultCode != Activity.RESULT_OK) { - // Handle error - return; - } - - if (requestCode == 1) {// Get photo picker response for single select. - Uri currentUri = data.getData(); - try { - File file = new File(Tools.DIR_GAME_HOME, "mouse"); - if (file.exists()) { - file.delete(); - } - - InputStream stream1 = getContext().getContentResolver().openInputStream(currentUri); - FileOutputStream stream = new FileOutputStream(file); - - IOUtils.copy(stream1, stream); - stream.close(); - stream1.close(); - Toast.makeText(getContext(), R.string.notif_mouse, Toast.LENGTH_SHORT).show(); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - } } diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceMiscellaneousFragment.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceMiscellaneousFragment.java index d2aea0105..1bb34ece5 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceMiscellaneousFragment.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceMiscellaneousFragment.java @@ -2,50 +2,12 @@ import android.os.Bundle; -import androidx.preference.Preference; -import androidx.preference.SwitchPreference; -import androidx.preference.Preference.OnPreferenceChangeListener; - -import com.firefly.utils.PGWTools; -import com.firefly.ui.dialog.CustomDialog; - import net.kdt.pojavlaunch.R; -import net.kdt.pojavlaunch.Tools; public class LauncherPreferenceMiscellaneousFragment extends LauncherPreferenceFragment { @Override public void onCreatePreferences(Bundle b, String str) { addPreferencesFromResource(R.xml.pref_misc); - Preference driverPreference = requirePreference("zinkPreferSystemDriver"); - if (!Tools.checkVulkanSupport(driverPreference.getContext().getPackageManager())) { - driverPreference.setVisible(false); - } - SwitchPreference useSystemVulkan = requirePreference("zinkPreferSystemDriver", SwitchPreference.class); - useSystemVulkan.setOnPreferenceChangeListener((p, v) -> { - boolean set = (boolean) v; - boolean isAdreno = PGWTools.isAdrenoGPU(); - if (set && isAdreno) { - onCheckGPUDialog(p); - } else { - return true; - } - return false; - }); - } - - private void onCheckGPUDialog(Preference pre) { - new CustomDialog.Builder(getContext()) - .setTitle("No No No No No!") - .setMessage(getString(R.string.worning_system_vulkan_adreno)) - .setConfirmListener(R.string.preference_rendererexp_alertdialog_done, customView -> { - ((SwitchPreference) pre).setChecked(true); - return true; - }) - .setCancelListener(R.string.alertdialog_cancel, customView -> true) - .setCancelable(false) - .setDraggable(true) - .build() - .show(); } } diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceVideoFragment.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceVideoFragment.java index 6dc66fef0..73abc4635 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceVideoFragment.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceVideoFragment.java @@ -2,6 +2,17 @@ import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_NOTCH_SIZE; +import androidx.preference.Preference; +import androidx.preference.PreferenceCategory; +import androidx.preference.SwitchPreference; +import androidx.preference.SwitchPreferenceCompat; +import androidx.preference.ListPreference; +import androidx.preference.Preference.OnPreferenceChangeListener; + +import com.firefly.utils.PGWTools; +import com.firefly.ui.dialog.CustomDialog; +import com.firefly.ui.prefs.ChooseMesaListPref; + import android.content.SharedPreferences; import android.os.Build; import android.os.Bundle; @@ -9,23 +20,29 @@ import android.view.LayoutInflater; import android.view.View; import android.widget.EditText; +import android.widget.Toast; -import androidx.preference.ListPreference; -import androidx.preference.SwitchPreference; -import androidx.preference.SwitchPreferenceCompat; - -import com.firefly.ui.dialog.CustomDialog; +import androidx.appcompat.app.AlertDialog; +import net.kdt.pojavlaunch.PojavApplication; import net.kdt.pojavlaunch.R; import net.kdt.pojavlaunch.Tools; import net.kdt.pojavlaunch.prefs.CustomSeekBarPreference; import net.kdt.pojavlaunch.prefs.LauncherPreferences; +import net.kdt.pojavlaunch.utils.MesaUtils; + +import java.util.Set; /** * Fragment for any settings video related */ public class LauncherPreferenceVideoFragment extends LauncherPreferenceFragment { + private EditText mSetVideoResolution; + private EditText mMesaGLVersion; + private EditText mMesaGLSLVersion; + private String expRenderer; + @Override public void onCreatePreferences(Bundle b, String str) { @@ -71,6 +88,93 @@ public void onCreatePreferences(Bundle b, String str) { return true; }); + Preference driverPreference = requirePreference("zinkPreferSystemDriver"); + if (!Tools.checkVulkanSupport(driverPreference.getContext().getPackageManager())) { + driverPreference.setVisible(false); + } + SwitchPreference useSystemVulkan = requirePreference("zinkPreferSystemDriver", SwitchPreference.class); + useSystemVulkan.setOnPreferenceChangeListener((p, v) -> { + boolean set = (boolean) v; + boolean isAdreno = PGWTools.isAdrenoGPU(); + if (set && isAdreno) { + onCheckGPUDialog(p); + } else { + return true; + } + return false; + }); + + final Preference downloadMesa = requirePreference("DownloadMesa", Preference.class); + downloadMesa.setOnPreferenceClickListener((a) -> { + loadMesaList(); + return true; + }); + + final ChooseMesaListPref CMesaLibP = requirePreference("CMesaLibrary", ChooseMesaListPref.class); + final ListPreference CDriverModelP = requirePreference("CDriverModels", ListPreference.class); + final ListPreference CMesaLDOP = requirePreference("ChooseMldo", ListPreference.class); + + setListPreference(CMesaLibP, "CMesaLibrary"); + setListPreference(CDriverModelP, "CDriverModels"); + setListPreference(CMesaLDOP, "ChooseMldo"); + + CMesaLibP.setOnPreferenceChangeListener((pre, obj) -> { + Tools.MESA_LIBS = (String) obj; + setListPreference(CDriverModelP, "CDriverModels"); + CDriverModelP.setValueIndex(0); + return true; + }); + + CDriverModelP.setOnPreferenceChangeListener((pre, obj) -> { + Tools.DRIVER_MODEL = (String) obj; + return true; + }); + + CMesaLDOP.setOnPreferenceChangeListener((pre, obj) -> { + Tools.LOADER_OVERRIDE = (String) obj; + return true; + }); + + SwitchPreference expRendererPref = requirePreference("ExperimentalSetup", SwitchPreference.class); + expRendererPref.setOnPreferenceChangeListener((p, v) -> { + onChangeRenderer(); + boolean isExpRenderer = (boolean) v; + if (isExpRenderer) { + onExpRendererDialog(p); + } + return true; + }); + + // Custom GL/GLSL + final PreferenceCategory customMesaVersionPref = requirePreference("customMesaVersionPref", PreferenceCategory.class); + SwitchPreference setSystemVersion = requirePreference("ebSystem", SwitchPreference.class); + setSystemVersion.setOnPreferenceChangeListener((p, v) -> { + boolean set = (boolean) v; + if (!set) return false; + closeOtherCustomMesaPref(customMesaVersionPref); + return true; + }); + + SwitchPreference setSpecificVersion = requirePreference("ebSpecific", SwitchPreference.class); + setSpecificVersion.setOnPreferenceChangeListener((p, v) -> { + boolean set = (boolean) v; + if (!set) return false; + closeOtherCustomMesaPref(customMesaVersionPref); + return true; + }); + + SwitchPreference setGLVersion = requirePreference("ebCustom", SwitchPreference.class); + setGLVersion.setOnPreferenceChangeListener((p, v) -> { + boolean set = (boolean) v; + if (!set) return false; + closeOtherCustomMesaPref(customMesaVersionPref); + return true; + }); + setGLVersion.setOnPreferenceClickListener(preference -> { + showSetGLVersionDialog(); + return true; + }); + computeVisibility(); } @@ -81,19 +185,12 @@ public void onSharedPreferenceChanged(SharedPreferences p, String s) { } private void computeVisibility() { - requirePreference("force_vsync", SwitchPreferenceCompat.class) - .setVisible(LauncherPreferences.PREF_USE_ALTERNATE_SURFACE); - } - - private void setListPreference(ListPreference listPreference, String preferenceKey) { - Tools.IListAndArry array = null; - String value = listPreference.getValue(); - if (preferenceKey.equals("renderer")) { - array = Tools.getCompatibleRenderers(getContext()); - Tools.LOCAL_RENDERER = value; - } - listPreference.setEntries(array.getArray()); - listPreference.setEntryValues(array.getList().toArray(new String[0])); + requirePreference("force_vsync", SwitchPreferenceCompat.class).setVisible(LauncherPreferences.PREF_USE_ALTERNATE_SURFACE); + requirePreference("SpareFrameBuffer").setVisible(LauncherPreferences.PREF_EXP_SETUP); + requirePreference("MesaRendererChoose").setVisible(LauncherPreferences.PREF_EXP_SETUP); + requirePreference("customMesaVersionPref").setVisible(LauncherPreferences.PREF_EXP_SETUP); + requirePreference("customMesaLoaderDriverOverride").setVisible(LauncherPreferences.PREF_EXP_SETUP); + requirePreference("ChooseMldo").setVisible(LauncherPreferences.PREF_LOADER_OVERRIDE); } private void setVideoResolutionDialog(CustomSeekBarPreference seek) { @@ -141,4 +238,207 @@ private void setVideoResolutionDialog(CustomSeekBarPreference seek) { .show(); } + private void setListPreference(ListPreference listPreference, String preferenceKey) { + Tools.IListAndArry array = null; + String value = listPreference.getValue(); + if (preferenceKey.equals("CMesaLibrary")) { + array = Tools.getCompatibleCMesaLib(getContext()); + boolean have = false; + for (int a = 0; a < array.getList().size(); a++) { + if (array.getList().get(a).equalsIgnoreCase(value)) { + have = true; + break; + } + } + if (!have) { + value = array.getList().get(0); + listPreference.setValue(value); + } + Tools.MESA_LIBS = value; + } else if (preferenceKey.equals("CDriverModels")) { + array = Tools.getCompatibleCDriverModel(getContext()); + Tools.DRIVER_MODEL = value; + } else if (preferenceKey.equals("ChooseMldo")) { + array = Tools.getCompatibleCMesaLDO(getContext()); + Tools.LOADER_OVERRIDE = value; + } else if (preferenceKey.equals("renderer")) { + array = Tools.getCompatibleRenderers(getContext()); + Tools.LOCAL_RENDERER = value; + } + listPreference.setEntries(array.getArray()); + listPreference.setEntryValues(array.getList().toArray(new String[0])); + } + + private void closeOtherCustomMesaPref(PreferenceCategory customMesaVersionPref) { + for (int i = 0; i < customMesaVersionPref.getPreferenceCount(); i++) { + Preference closepref = customMesaVersionPref.getPreference(i); + if (closepref instanceof SwitchPreference) { + ((SwitchPreference) closepref).setChecked(false); + } + } + } + + + private void onCheckGPUDialog(Preference pre) { + new CustomDialog.Builder(getContext()) + .setTitle("No No No No No!") + .setMessage(getString(R.string.worning_system_vulkan_adreno)) + .setConfirmListener(R.string.preference_rendererexp_alertdialog_done, customView -> { + ((SwitchPreference) pre).setChecked(true); + return true; + }) + .setCancelListener(R.string.alertdialog_cancel, customView -> true) + .setCancelable(false) + .setDraggable(true) + .build() + .show(); + } + + private void onExpRendererDialog(Preference pre) { + new CustomDialog.Builder(getContext()) + .setTitle(getString(R.string.preference_rendererexp_alertdialog_warning)) + .setMessage(getString(R.string.preference_rendererexp_alertdialog_message)) + .setConfirmListener(R.string.preference_rendererexp_alertdialog_done, customView -> true) + .setCancelListener(R.string.preference_rendererexp_alertdialog_cancel, customView -> { + onChangeRenderer(); + ((SwitchPreference) pre).setChecked(false); + return true; + }) + .setCancelable(false) + .setDraggable(true) + .build() + .show(); + } + + // Custom Mesa GL/GLSL Version + private void showSetGLVersionDialog() { + LayoutInflater inflater = requireActivity().getLayoutInflater(); + View view = inflater.inflate(R.layout.dialog_mesa_version, null); + + mMesaGLVersion = view.findViewById(R.id.mesa_gl_version); + mMesaGLSLVersion = view.findViewById(R.id.mesa_glsl_version); + + mMesaGLVersion.setText(LauncherPreferences.PREF_MESA_GL_VERSION); + mMesaGLSLVersion.setText(LauncherPreferences.PREF_MESA_GLSL_VERSION); + + new CustomDialog.Builder(getContext()) + .setCustomView(view) + .setCancelable(false) + .setConfirmListener(R.string.alertdialog_done, customView -> { + String glVersion = mMesaGLVersion.getText().toString(); + String glslVersion = mMesaGLSLVersion.getText().toString(); + + boolean validGLVersion = isValidVersion(glVersion, "2.8", "4.6"); + boolean validGLSLVersion = isValidVersion(glslVersion, "280", "460"); + + if (!validGLVersion || !validGLSLVersion) { + if (!validGLVersion) { + mMesaGLVersion.setError(getString(R.string.customglglsl_alertdialog_error_gl)); + mMesaGLVersion.requestFocus(); + } + if (!validGLSLVersion) { + mMesaGLSLVersion.setError(getString(R.string.customglglsl_alertdialog_error_glsl)); + mMesaGLSLVersion.requestFocus(); + } + return false; + } + + LauncherPreferences.PREF_MESA_GL_VERSION = glVersion; + LauncherPreferences.PREF_MESA_GLSL_VERSION = glslVersion; + + LauncherPreferences.DEFAULT_PREF.edit() + .putString("mesaGLVersion", LauncherPreferences.PREF_MESA_GL_VERSION) + .putString("mesaGLSLVersion", LauncherPreferences.PREF_MESA_GLSL_VERSION) + .apply(); + + return true; + }) + .setCancelListener(R.string.alertdialog_cancel, customView -> true) + .setDraggable(true) + .build() + .show(); + } + + // Check whether the GL/GLSL version is within the acceptable range + private boolean isValidVersion(String version, String minVersion, String maxVersion) { + try { + float versionNumber = Float.parseFloat(version); + float minVersionNumber = Float.parseFloat(minVersion); + float maxVersionNumber = Float.parseFloat(maxVersion); + + return versionNumber >= minVersionNumber && versionNumber <= maxVersionNumber; + } catch (NumberFormatException e) { + return false; + } + } + + private void onChangeRenderer() { + String rendererValue = LauncherPreferences.DEFAULT_PREF.getString("renderer", null); + if ("mesa_3d".equals(rendererValue)) { + LauncherPreferences.DEFAULT_PREF.edit().putString("renderer", expRenderer).apply(); + } else if ("vulkan_zink".equals(rendererValue) + || "virglrenderer".equals(rendererValue) + || "freedreno".equals(rendererValue) + || "panfrost".equals(rendererValue)) { + expRenderer = LauncherPreferences.DEFAULT_PREF.getString("renderer", null); + LauncherPreferences.DEFAULT_PREF.edit().putString("renderer", "mesa_3d").apply(); + } + } + + private void loadMesaList() { + AlertDialog dialog = new AlertDialog.Builder(requireContext()) + .setMessage(R.string.preference_rendererexp_mesa_download_load) + .show(); + PojavApplication.sExecutorService.execute(() -> { + Set list = MesaUtils.INSTANCE.getMesaList(); + requireActivity().runOnUiThread(() -> { + dialog.dismiss(); + + if (list == null) { + AlertDialog alertDialog1 = new AlertDialog.Builder(requireActivity()) + .setMessage(R.string.preference_rendererexp_mesa_get_fail) + .create(); + alertDialog1.show(); + } else { + final String[] items3 = new String[list.size()]; + list.toArray(items3); + // Add List + AlertDialog alertDialog3 = new AlertDialog.Builder(requireActivity()) + .setTitle(R.string.preference_rendererexp_mesa_select_download) + .setItems(items3, (dialogInterface, i) -> { + if (i < 0 || i > items3.length) + return; + dialogInterface.dismiss(); + downloadMesa(items3[i]); + }) + .create(); + alertDialog3.show(); + } + }); + }); + } + + private void downloadMesa(String version) { + AlertDialog dialog = new AlertDialog.Builder(requireContext()) + .setMessage(R.string.preference_rendererexp_mesa_downloading) + .setCancelable(false) + .show(); + PojavApplication.sExecutorService.execute(() -> { + boolean data = MesaUtils.INSTANCE.downloadMesa(version); + requireActivity().runOnUiThread(() -> { + dialog.dismiss(); + if (data) { + Toast.makeText(requireContext(), R.string.preference_rendererexp_mesa_downloaded, Toast.LENGTH_SHORT) + .show(); + setListPreference(requirePreference("CMesaLibrary", ChooseMesaListPref.class), "CMesaLibrary"); + } else { + AlertDialog alertDialog1 = new AlertDialog.Builder(requireActivity()) + .setMessage(R.string.preference_rendererexp_mesa_download_fail) + .create(); + alertDialog1.show(); + } + }); + }); + } + } diff --git a/app_pojavlauncher/src/main/res/xml/pref_control.xml b/app_pojavlauncher/src/main/res/xml/pref_control.xml index f6300e7c3..3d8133f9b 100644 --- a/app_pojavlauncher/src/main/res/xml/pref_control.xml +++ b/app_pojavlauncher/src/main/res/xml/pref_control.xml @@ -14,7 +14,9 @@ + android:title="@string/preference_category_gestures" + app2:iconSpaceReserved="false" + > + android:title="@string/preference_category_buttons" + app2:iconSpaceReserved="false" + > + android:title="@string/preference_category_virtual_mouse" + app2:iconSpaceReserved="false" + > + + + + + + + android:summary="@string/preference_enable_gyro_description" + app2:iconSpaceReserved="false" + /> + + app2:showSeekBarValue="true" + app2:iconSpaceReserved="false" + /> + + app2:showSeekBarValue="true" + app2:iconSpaceReserved="false" + /> + + + android:summary="@string/preference_gyro_invert_x_axis_description" + app2:iconSpaceReserved="false" + /> + + android:summary="@string/preference_gyro_invert_y_axis_description" + app2:iconSpaceReserved="false" + /> + + android:fragment="net.kdt.pojavlaunch.fragments.GamepadMapperFragment" + app2:iconSpaceReserved="false" + /> + + diff --git a/app_pojavlauncher/src/main/res/xml/pref_experimental.xml b/app_pojavlauncher/src/main/res/xml/pref_experimental.xml deleted file mode 100644 index af5d0123c..000000000 --- a/app_pojavlauncher/src/main/res/xml/pref_experimental.xml +++ /dev/null @@ -1,136 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app_pojavlauncher/src/main/res/xml/pref_launcher.xml b/app_pojavlauncher/src/main/res/xml/pref_launcher.xml index 2306a7052..7aa75812e 100644 --- a/app_pojavlauncher/src/main/res/xml/pref_launcher.xml +++ b/app_pojavlauncher/src/main/res/xml/pref_launcher.xml @@ -4,40 +4,56 @@ - + + + android:summary="@string/preference_update_launcher_desc" + app2:iconSpaceReserved="false" + /> + android:summary="@string/preference_force_english_description" + app2:iconSpaceReserved="false" + /> + android:title="@string/preference_enable_log_output_title" + app2:iconSpaceReserved="false" + /> + android:title="@string/preference_quit_launcher_title" + app2:iconSpaceReserved="false" + /> + android:title="@string/zh_setting_set_game_language_title" + app2:iconSpaceReserved="false" + /> + android:title="@string/zh_setting_set_game_language_overridden_title" + app2:iconSpaceReserved="false" + /> + app2:useSimpleSummaryProvider="true" + app2:iconSpaceReserved="false"/> - - - diff --git a/app_pojavlauncher/src/main/res/xml/pref_main.xml b/app_pojavlauncher/src/main/res/xml/pref_main.xml index 1ef1a4aca..8176daadc 100644 --- a/app_pojavlauncher/src/main/res/xml/pref_main.xml +++ b/app_pojavlauncher/src/main/res/xml/pref_main.xml @@ -11,8 +11,17 @@ + + - - - - - + + + android:title="@string/mcl_setting_check_libraries" + /> + + android:title="@string/arc_capes_title" + app2:iconSpaceReserved="false" + /> + + app2:useSimpleSummaryProvider="true" + app2:iconSpaceReserved="false" + /> + - - + android:summary="@string/preference_verify_manifest_description" + app2:iconSpaceReserved="false" + /> diff --git a/app_pojavlauncher/src/main/res/xml/pref_video.xml b/app_pojavlauncher/src/main/res/xml/pref_video.xml index 8135229e9..438f2ff76 100644 --- a/app_pojavlauncher/src/main/res/xml/pref_video.xml +++ b/app_pojavlauncher/src/main/res/xml/pref_video.xml @@ -4,7 +4,11 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file