Android: Add on-screen fast forward button
This commit is contained in:
@ -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() {
|
||||
|
||||
@ -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()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user