Android: Add on-screen fast forward button

This commit is contained in:
Connor McLaughlin 2021-02-27 14:58:42 +10:00
parent d0ace6ed5a
commit 7bd11d38ac
7 changed files with 110 additions and 6 deletions

View file

@ -12,12 +12,19 @@ import android.view.View;
* TODO: document your custom view class.
*/
public final class TouchscreenControllerButtonView extends View {
public enum Hotkey
{
NONE,
FAST_FORWARD
}
private Drawable mUnpressedDrawable;
private Drawable mPressedDrawable;
private boolean mPressed = false;
private boolean mHapticFeedback = false;
private int mControllerIndex = -1;
private int mButtonCode = -1;
private Hotkey mHotkey = Hotkey.NONE;
private String mConfigName;
public TouchscreenControllerButtonView(Context context) {
@ -95,6 +102,10 @@ public final class TouchscreenControllerButtonView extends View {
mButtonCode = code;
}
public void setHotkey(Hotkey hotkey) {
mHotkey = hotkey;
}
public void setConfigName(String name) {
mConfigName = name;
}
@ -110,6 +121,17 @@ public final class TouchscreenControllerButtonView extends View {
private void updateControllerState() {
if (mButtonCode >= 0)
AndroidHostInterface.getInstance().setControllerButtonState(mControllerIndex, mButtonCode, mPressed);
switch (mHotkey)
{
case FAST_FORWARD:
AndroidHostInterface.getInstance().setFastForwardEnabled(mPressed);
break;
case NONE:
default:
break;
}
}
public Drawable getPressedDrawable() {

View file

@ -204,6 +204,9 @@ public class TouchscreenControllerView extends FrameLayout {
linkAxisToButtons(mMainView, R.id.controller_axis_left, "LeftAxis", "");
linkAxis(mMainView, R.id.controller_axis_right, "RightAxis", "Right");
linkHotkeyButton(mMainView, R.id.controller_button_fast_forward, TouchscreenControllerButtonView.Hotkey.FAST_FORWARD);
reloadButtonTranslation();
requestLayout();
}
@ -262,6 +265,15 @@ public class TouchscreenControllerView extends FrameLayout {
return true;
}
private void linkHotkeyButton(View view, int id, TouchscreenControllerButtonView.Hotkey hotkey) {
TouchscreenControllerButtonView buttonView = (TouchscreenControllerButtonView) view.findViewById(id);
if (buttonView == null)
return;
buttonView.setHotkey(hotkey);
mButtonViews.add(buttonView);
}
private int dpToPixels(float dp) {
return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, getResources().getDisplayMetrics()));
}

View file

@ -0,0 +1,17 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M0.6615,0.6614L23.7969,0.6614v23.0L0.6615,23.7969Z"
android:strokeAlpha="1"
android:strokeLineJoin="round"
android:strokeWidth="0.26458332"
android:fillColor="#00000000"
android:strokeColor="#e6e6e6"
android:strokeLineCap="round" />
<path
android:fillColor="#e6e6e6"
android:pathData="M4,18l8.5,-6L4,6v12zM13,6v12l8.5,-6L13,6z"/>
</vector>

View file

@ -0,0 +1,17 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M0.6615,0.6614L23.7969,0.6614v23.0L0.6615,23.7969Z"
android:strokeAlpha="1"
android:strokeLineJoin="round"
android:strokeWidth="0.26458332"
android:fillColor="#4d4d4d"
android:strokeColor="#e6e6e6"
android:strokeLineCap="round" />
<path
android:fillColor="#e6e6e6"
android:pathData="M4,18l8.5,-6L4,6v12zM13,6v12l8.5,-6L13,6z"/>
</vector>

View file

@ -55,7 +55,7 @@
android:id="@+id/controller_button_start"
android:layout_width="40dp"
android:layout_height="25dp"
android:layout_marginStart="80dp"
android:layout_marginStart="70dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
@ -68,7 +68,7 @@
android:id="@+id/controller_button_select"
android:layout_width="40dp"
android:layout_height="25dp"
android:layout_marginEnd="50dp"
android:layout_marginEnd="70dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
@ -133,4 +133,16 @@
android:paddingRight="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<com.github.stenzek.duckstation.TouchscreenControllerButtonView
android:id="@+id/controller_button_fast_forward"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_marginBottom="50dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:pressedDrawable="@drawable/ic_controller_fast_forward_pressed"
app:unpressedDrawable="@drawable/ic_controller_fast_forward" />
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -55,7 +55,7 @@
android:id="@+id/controller_button_start"
android:layout_width="40dp"
android:layout_height="25dp"
android:layout_marginStart="80dp"
android:layout_marginStart="70dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
@ -68,7 +68,7 @@
android:id="@+id/controller_button_select"
android:layout_width="40dp"
android:layout_height="25dp"
android:layout_marginEnd="50dp"
android:layout_marginEnd="70dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
@ -198,4 +198,16 @@
app:layout_constraintStart_toStartOf="parent"
app:pressedDrawable="@drawable/ic_controller_up_button_pressed"
app:unpressedDrawable="@drawable/ic_controller_up_button" />
<com.github.stenzek.duckstation.TouchscreenControllerButtonView
android:id="@+id/controller_button_fast_forward"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_marginBottom="50dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:pressedDrawable="@drawable/ic_controller_fast_forward_pressed"
app:unpressedDrawable="@drawable/ic_controller_fast_forward" />
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -107,7 +107,7 @@
android:id="@+id/controller_button_start"
android:layout_width="40dp"
android:layout_height="25dp"
android:layout_marginStart="80dp"
android:layout_marginStart="70dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
@ -120,7 +120,7 @@
android:id="@+id/controller_button_select"
android:layout_width="40dp"
android:layout_height="25dp"
android:layout_marginEnd="50dp"
android:layout_marginEnd="70dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
@ -172,4 +172,16 @@
app:layout_constraintEnd_toEndOf="parent"
app:pressedDrawable="@drawable/ic_controller_circle_button_pressed"
app:unpressedDrawable="@drawable/ic_controller_circle_button" />
<com.github.stenzek.duckstation.TouchscreenControllerButtonView
android:id="@+id/controller_button_fast_forward"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_marginBottom="50dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:pressedDrawable="@drawable/ic_controller_fast_forward_pressed"
app:unpressedDrawable="@drawable/ic_controller_fast_forward" />
</androidx.constraintlayout.widget.ConstraintLayout>