Skip to content

Commit

Permalink
Feat[joystick]: add setting for absolute finger tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
artdeell committed Dec 10, 2023
1 parent 2a95a30 commit 8da6924
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ public class ControlJoystickData extends ControlData {

/* Whether the joystick can stay forward */
public boolean forwardLock = false;
/*
* Whether the finger tracking is absolute (joystick jumps to where you touched)
* or relative (joystick stays in the center)
*/
public boolean absolute = false;

public ControlJoystickData(){
super();
Expand All @@ -12,5 +17,6 @@ public ControlJoystickData(){
public ControlJoystickData(ControlJoystickData properties) {
super(properties);
forwardLock = properties.forwardLock;
absolute = properties.absolute;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private void init(ControlJoystickData data, ControlLayout layout) {
mControlData = data;
setProperties(preProcessProperties(data, layout));
setDeadzone(35);
setFixedCenter(false);
setFixedCenter(data.absolute);
setAutoReCenterButton(true);

injectBehaviors();
Expand Down Expand Up @@ -91,7 +91,10 @@ public void setProperties(ControlData properties, boolean changePos) {
mControlData = (ControlJoystickData) properties;
mControlData.isHideable = true;
ControlInterface.super.setProperties(properties, changePos);
postDelayed(() -> setForwardLockDistance(mControlData.forwardLock ? (int) Tools.dpToPx(60) : 0), 10);
postDelayed(() -> {
setForwardLockDistance(mControlData.forwardLock ? (int) Tools.dpToPx(60) : 0);
setFixedCenter(mControlData.absolute);
}, 10);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.SeekBar;
import android.widget.Spinner;
Expand Down Expand Up @@ -75,7 +74,7 @@ public void onLayoutChange(View v, int left, int top, int right, int bottom, int
};
protected EditText mNameEditText, mWidthEditText, mHeightEditText;
@SuppressLint("UseSwitchCompatOrMaterialCode")
protected Switch mToggleSwitch, mPassthroughSwitch, mSwipeableSwitch, mForwardLockSwitch;
protected Switch mToggleSwitch, mPassthroughSwitch, mSwipeableSwitch, mForwardLockSwitch, mAbsoluteTrackingSwitch;
protected Spinner mOrientationSpinner;
protected TextView[] mKeycodeTextviews = new TextView[4];
protected SeekBar mStrokeWidthSeekbar, mCornerRadiusSeekbar, mAlphaSeekbar;
Expand Down Expand Up @@ -274,6 +273,7 @@ public void loadValues(ControlData data) {
mOrientationTextView.setVisibility(GONE);
mOrientationSpinner.setVisibility(GONE);
mForwardLockSwitch.setVisibility(GONE);
mAbsoluteTrackingSwitch.setVisibility(GONE);

mNameEditText.setText(data.name);
mWidthEditText.setText(String.valueOf(data.getWidth()));
Expand Down Expand Up @@ -351,6 +351,9 @@ public void loadJoystickValues(ControlJoystickData data) {

mForwardLockSwitch.setVisibility(VISIBLE);
mForwardLockSwitch.setChecked(data.forwardLock);

mAbsoluteTrackingSwitch.setVisibility(VISIBLE);
mAbsoluteTrackingSwitch.setChecked(data.absolute);
}

/**
Expand Down Expand Up @@ -383,6 +386,7 @@ private void bindLayout() {
mPassthroughSwitch = mScrollView.findViewById(R.id.checkboxPassThrough);
mSwipeableSwitch = mScrollView.findViewById(R.id.checkboxSwipeable);
mForwardLockSwitch = mScrollView.findViewById(R.id.checkboxForwardLock);
mAbsoluteTrackingSwitch = mScrollView.findViewById(R.id.checkboxAbsoluteFingerTracking);
mKeycodeSpinners[0] = mScrollView.findViewById(R.id.editMapping_spinner_1);
mKeycodeSpinners[1] = mScrollView.findViewById(R.id.editMapping_spinner_2);
mKeycodeSpinners[2] = mScrollView.findViewById(R.id.editMapping_spinner_3);
Expand Down Expand Up @@ -498,6 +502,12 @@ public void afterTextChanged(Editable s) {
((ControlJoystickData) mCurrentlyEditedButton.getProperties()).forwardLock = isChecked;
}
});
mAbsoluteTrackingSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
if (internalChanges) return;
if(mCurrentlyEditedButton.getProperties() instanceof ControlJoystickData){
((ControlJoystickData) mCurrentlyEditedButton.getProperties()).absolute = isChecked;
}
});

mAlphaSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,15 @@
app:layout_constraintTop_toBottomOf="@id/checkboxSwipeable"
tools:ignore="UseSwitchCompatOrMaterialXml" />

<Switch
android:id="@+id/checkboxAbsoluteFingerTracking"
android:layout_width="match_parent"
android:layout_height="@dimen/_36sdp"
android:text="@string/customctrl_absolute_tracking"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/checkboxForwardLock"
tools:ignore="UseSwitchCompatOrMaterialXml"/>

<!-- BACKGROUND COLOR SECTION -->
<fr.spse.extended_view.ExtendedTextView
android:id="@+id/editBackgroundColor_textView"
Expand All @@ -346,7 +355,7 @@

app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/checkboxForwardLock" />
app:layout_constraintTop_toBottomOf="@id/checkboxAbsoluteFingerTracking" />


<!-- STROKE WIDTH -->
Expand Down
1 change: 1 addition & 0 deletions app_pojavlauncher/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
<string name="customctrl_passthru">Mouse pass-thru</string>
<string name="customctrl_swipeable">Swipeable</string>
<string name="customctrl_forward_lock">Forward lock</string>
<string name="customctrl_absolute_tracking">Absolute finger tracking</string>
<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>
Expand Down

0 comments on commit 8da6924

Please sign in to comment.