Skip to content

Commit

Permalink
调整[UI]: 调整设置界面的功能顺序
Browse files Browse the repository at this point in the history
  • Loading branch information
Vera-Firefly committed Oct 29, 2024
1 parent 5c5c2fb commit bff078c
Show file tree
Hide file tree
Showing 12 changed files with 655 additions and 618 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.kdt.pojavlaunch.prefs;
package com.firefly.ui.prefs;

import android.content.Context;
import android.util.AttributeSet;
Expand All @@ -15,12 +15,12 @@
import java.util.Arrays;
import java.util.List;

public class DeletableListPreference extends ListPreference {
public class ChooseMesaListPref extends ListPreference {

private List<String> defaultLibs;
private OnPreferenceChangeListener preferenceChangeListener;

public DeletableListPreference(Context context, AttributeSet attrs) {
public ChooseMesaListPref(Context context, AttributeSet attrs) {
super(context, attrs);
loadDefaultLibs(context);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Intent> 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;
Expand All @@ -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",
Expand Down Expand Up @@ -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();
}

Expand All @@ -97,5 +154,4 @@ private void computeVisibility() {
requirePreference("gyroInvertY").setVisible(LauncherPreferences.PREF_ENABLE_GYRO);
requirePreference("gyroSmoothing").setVisible(LauncherPreferences.PREF_ENABLE_GYRO);
}

}
}
Loading

0 comments on commit bff078c

Please sign in to comment.