summaryrefslogtreecommitdiff
path: root/Source/Android/app/src/main/java
diff options
context:
space:
mode:
authorzackhow <zackhow@gmail.com>2018-09-08 13:29:06 -0400
committerzackhow <zackhow@gmail.com>2018-09-21 17:18:30 -0400
commitafe59c50c49bdd2aca947b3a343d379a81c2942a (patch)
treeb82fb0e1842f185109cdf43c914b83a3f774f0d8 /Source/Android/app/src/main/java
parent85961f996ef1c142b056c29bd88456bf2d0d00c9 (diff)
Android: add profile for portrait touch overlay
Diffstat (limited to 'Source/Android/app/src/main/java')
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlay.java132
1 files changed, 72 insertions, 60 deletions
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlay.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlay.java
index e8be35ee7a..07930bc6f7 100644
--- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlay.java
+++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlay.java
@@ -9,6 +9,7 @@ package org.dolphinemu.dolphinemu.overlay;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
+import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@@ -235,6 +236,10 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
int fingerPositionX = (int) event.getX(pointerIndex);
int fingerPositionY = (int) event.getY(pointerIndex);
+ String orientation =
+ getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT ?
+ "-Portrait" : "";
+
// Maybe combine Button and Joystick as subclasses of the same parent?
// Or maybe create an interface like IMoveableHUDControl?
@@ -269,7 +274,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
// Persist button position by saving new place.
saveControlPosition(mButtonBeingConfigured.getId(),
mButtonBeingConfigured.getBounds().left,
- mButtonBeingConfigured.getBounds().top);
+ mButtonBeingConfigured.getBounds().top, orientation);
mButtonBeingConfigured = null;
}
break;
@@ -306,7 +311,8 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
{
// Persist button position by saving new place.
saveControlPosition(mDpadBeingConfigured.getId(0),
- mDpadBeingConfigured.getBounds().left, mDpadBeingConfigured.getBounds().top);
+ mDpadBeingConfigured.getBounds().left, mDpadBeingConfigured.getBounds().top,
+ orientation);
mDpadBeingConfigured = null;
}
break;
@@ -339,7 +345,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
{
saveControlPosition(mJoystickBeingConfigured.getId(),
mJoystickBeingConfigured.getBounds().left,
- mJoystickBeingConfigured.getBounds().top);
+ mJoystickBeingConfigured.getBounds().top, orientation);
mJoystickBeingConfigured = null;
}
break;
@@ -380,47 +386,47 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
}
}
- private void addGameCubeOverlayControls()
+ private void addGameCubeOverlayControls(String orientation)
{
if (mPreferences.getBoolean("buttonToggleGc0", true))
{
overlayButtons.add(initializeOverlayButton(getContext(), R.drawable.gcpad_a,
- R.drawable.gcpad_a_pressed, ButtonType.BUTTON_A));
+ R.drawable.gcpad_a_pressed, ButtonType.BUTTON_A, orientation));
}
if (mPreferences.getBoolean("buttonToggleGc1", true))
{
overlayButtons.add(initializeOverlayButton(getContext(), R.drawable.gcpad_b,
- R.drawable.gcpad_b_pressed, ButtonType.BUTTON_B));
+ R.drawable.gcpad_b_pressed, ButtonType.BUTTON_B, orientation));
}
if (mPreferences.getBoolean("buttonToggleGc2", true))
{
overlayButtons.add(initializeOverlayButton(getContext(), R.drawable.gcpad_x,
- R.drawable.gcpad_x_pressed, ButtonType.BUTTON_X));
+ R.drawable.gcpad_x_pressed, ButtonType.BUTTON_X, orientation));
}
if (mPreferences.getBoolean("buttonToggleGc3", true))
{
overlayButtons.add(initializeOverlayButton(getContext(), R.drawable.gcpad_y,
- R.drawable.gcpad_y_pressed, ButtonType.BUTTON_Y));
+ R.drawable.gcpad_y_pressed, ButtonType.BUTTON_Y, orientation));
}
if (mPreferences.getBoolean("buttonToggleGc4", true))
{
overlayButtons.add(initializeOverlayButton(getContext(), R.drawable.gcpad_z,
- R.drawable.gcpad_z_pressed, ButtonType.BUTTON_Z));
+ R.drawable.gcpad_z_pressed, ButtonType.BUTTON_Z, orientation));
}
if (mPreferences.getBoolean("buttonToggleGc5", true))
{
overlayButtons.add(initializeOverlayButton(getContext(), R.drawable.gcpad_start,
- R.drawable.gcpad_start_pressed, ButtonType.BUTTON_START));
+ R.drawable.gcpad_start_pressed, ButtonType.BUTTON_START, orientation));
}
if (mPreferences.getBoolean("buttonToggleGc6", true))
{
overlayButtons.add(initializeOverlayButton(getContext(), R.drawable.gcpad_l,
- R.drawable.gcpad_l_pressed, ButtonType.TRIGGER_L));
+ R.drawable.gcpad_l_pressed, ButtonType.TRIGGER_L, orientation));
}
if (mPreferences.getBoolean("buttonToggleGc7", true))
{
overlayButtons.add(initializeOverlayButton(getContext(), R.drawable.gcpad_r,
- R.drawable.gcpad_r_pressed, ButtonType.TRIGGER_R));
+ R.drawable.gcpad_r_pressed, ButtonType.TRIGGER_R, orientation));
}
if (mPreferences.getBoolean("buttonToggleGc8", true))
{
@@ -428,56 +434,57 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
R.drawable.gcwii_dpad_pressed_one_direction,
R.drawable.gcwii_dpad_pressed_two_directions,
ButtonType.BUTTON_UP, ButtonType.BUTTON_DOWN,
- ButtonType.BUTTON_LEFT, ButtonType.BUTTON_RIGHT));
+ ButtonType.BUTTON_LEFT, ButtonType.BUTTON_RIGHT, orientation));
}
if (mPreferences.getBoolean("buttonToggleGc9", true))
{
overlayJoysticks.add(initializeOverlayJoystick(getContext(), R.drawable.gcwii_joystick_range,
- R.drawable.gcwii_joystick, R.drawable.gcwii_joystick_pressed, ButtonType.STICK_MAIN));
+ R.drawable.gcwii_joystick, R.drawable.gcwii_joystick_pressed, ButtonType.STICK_MAIN,
+ orientation));
}
if (mPreferences.getBoolean("buttonToggleGc10", true))
{
overlayJoysticks.add(initializeOverlayJoystick(getContext(), R.drawable.gcwii_joystick_range,
- R.drawable.gcpad_c, R.drawable.gcpad_c_pressed, ButtonType.STICK_C));
+ R.drawable.gcpad_c, R.drawable.gcpad_c_pressed, ButtonType.STICK_C, orientation));
}
}
- private void addWiimoteOverlayControls()
+ private void addWiimoteOverlayControls(String orientation)
{
if (mPreferences.getBoolean("buttonToggleWii0", true))
{
overlayButtons.add(initializeOverlayButton(getContext(), R.drawable.wiimote_a,
- R.drawable.wiimote_a_pressed, ButtonType.WIIMOTE_BUTTON_A));
+ R.drawable.wiimote_a_pressed, ButtonType.WIIMOTE_BUTTON_A, orientation));
}
if (mPreferences.getBoolean("buttonToggleWii1", true))
{
overlayButtons.add(initializeOverlayButton(getContext(), R.drawable.wiimote_b,
- R.drawable.wiimote_b_pressed, ButtonType.WIIMOTE_BUTTON_B));
+ R.drawable.wiimote_b_pressed, ButtonType.WIIMOTE_BUTTON_B, orientation));
}
if (mPreferences.getBoolean("buttonToggleWii2", true))
{
overlayButtons.add(initializeOverlayButton(getContext(), R.drawable.wiimote_one,
- R.drawable.wiimote_one_pressed, ButtonType.WIIMOTE_BUTTON_1));
+ R.drawable.wiimote_one_pressed, ButtonType.WIIMOTE_BUTTON_1, orientation));
}
if (mPreferences.getBoolean("buttonToggleWii3", true))
{
overlayButtons.add(initializeOverlayButton(getContext(), R.drawable.wiimote_two,
- R.drawable.wiimote_two_pressed, ButtonType.WIIMOTE_BUTTON_2));
+ R.drawable.wiimote_two_pressed, ButtonType.WIIMOTE_BUTTON_2, orientation));
}
if (mPreferences.getBoolean("buttonToggleWii4", true))
{
overlayButtons.add(initializeOverlayButton(getContext(), R.drawable.wiimote_plus,
- R.drawable.wiimote_plus_pressed, ButtonType.WIIMOTE_BUTTON_PLUS));
+ R.drawable.wiimote_plus_pressed, ButtonType.WIIMOTE_BUTTON_PLUS, orientation));
}
if (mPreferences.getBoolean("buttonToggleWii5", true))
{
overlayButtons.add(initializeOverlayButton(getContext(), R.drawable.wiimote_minus,
- R.drawable.wiimote_minus_pressed, ButtonType.WIIMOTE_BUTTON_MINUS));
+ R.drawable.wiimote_minus_pressed, ButtonType.WIIMOTE_BUTTON_MINUS, orientation));
}
if (mPreferences.getBoolean("buttonToggleWii6", true))
{
overlayButtons.add(initializeOverlayButton(getContext(), R.drawable.wiimote_home,
- R.drawable.wiimote_home_pressed, ButtonType.WIIMOTE_BUTTON_HOME));
+ R.drawable.wiimote_home_pressed, ButtonType.WIIMOTE_BUTTON_HOME, orientation));
}
if (mPreferences.getBoolean("buttonToggleWii7", true))
{
@@ -487,7 +494,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
R.drawable.gcwii_dpad_pressed_one_direction,
R.drawable.gcwii_dpad_pressed_two_directions,
ButtonType.WIIMOTE_RIGHT, ButtonType.WIIMOTE_LEFT,
- ButtonType.WIIMOTE_UP, ButtonType.WIIMOTE_DOWN));
+ ButtonType.WIIMOTE_UP, ButtonType.WIIMOTE_DOWN, orientation));
}
else
{
@@ -495,87 +502,87 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
R.drawable.gcwii_dpad_pressed_one_direction,
R.drawable.gcwii_dpad_pressed_two_directions,
ButtonType.WIIMOTE_UP, ButtonType.WIIMOTE_DOWN,
- ButtonType.WIIMOTE_LEFT, ButtonType.WIIMOTE_RIGHT));
+ ButtonType.WIIMOTE_LEFT, ButtonType.WIIMOTE_RIGHT, orientation));
}
}
}
- private void addNunchukOverlayControls()
+ private void addNunchukOverlayControls(String orientation)
{
if (mPreferences.getBoolean("buttonToggleWii8", true))
{
overlayButtons.add(initializeOverlayButton(getContext(), R.drawable.nunchuk_c,
- R.drawable.nunchuk_c_pressed, ButtonType.NUNCHUK_BUTTON_C));
+ R.drawable.nunchuk_c_pressed, ButtonType.NUNCHUK_BUTTON_C, orientation));
}
if (mPreferences.getBoolean("buttonToggleWii9", true))
{
overlayButtons.add(initializeOverlayButton(getContext(), R.drawable.nunchuk_z,
- R.drawable.nunchuk_z_pressed, ButtonType.NUNCHUK_BUTTON_Z));
+ R.drawable.nunchuk_z_pressed, ButtonType.NUNCHUK_BUTTON_Z, orientation));
}
if (mPreferences.getBoolean("buttonToggleWii10", true))
{
overlayJoysticks.add(initializeOverlayJoystick(getContext(), R.drawable.gcwii_joystick_range,
R.drawable.gcwii_joystick, R.drawable.gcwii_joystick_pressed,
- ButtonType.NUNCHUK_STICK));
+ ButtonType.NUNCHUK_STICK, orientation));
}
}
- private void addClassicOverlayControls()
+ private void addClassicOverlayControls(String orientation)
{
if (mPreferences.getBoolean("buttonToggleClassic0", true))
{
overlayButtons.add(initializeOverlayButton(getContext(), R.drawable.classic_a,
- R.drawable.classic_a_pressed, ButtonType.CLASSIC_BUTTON_A));
+ R.drawable.classic_a_pressed, ButtonType.CLASSIC_BUTTON_A, orientation));
}
if (mPreferences.getBoolean("buttonToggleClassic1", true))
{
overlayButtons.add(initializeOverlayButton(getContext(), R.drawable.classic_b,
- R.drawable.classic_b_pressed, ButtonType.CLASSIC_BUTTON_B));
+ R.drawable.classic_b_pressed, ButtonType.CLASSIC_BUTTON_B, orientation));
}
if (mPreferences.getBoolean("buttonToggleClassic2", true))
{
overlayButtons.add(initializeOverlayButton(getContext(), R.drawable.classic_x,
- R.drawable.classic_x_pressed, ButtonType.CLASSIC_BUTTON_X));
+ R.drawable.classic_x_pressed, ButtonType.CLASSIC_BUTTON_X, orientation));
}
if (mPreferences.getBoolean("buttonToggleClassic3", true))
{
overlayButtons.add(initializeOverlayButton(getContext(), R.drawable.classic_y,
- R.drawable.classic_y_pressed, ButtonType.CLASSIC_BUTTON_Y));
+ R.drawable.classic_y_pressed, ButtonType.CLASSIC_BUTTON_Y, orientation));
}
if (mPreferences.getBoolean("buttonToggleClassic4", true))
{
overlayButtons.add(initializeOverlayButton(getContext(), R.drawable.wiimote_plus,
- R.drawable.wiimote_plus_pressed, ButtonType.CLASSIC_BUTTON_PLUS));
+ R.drawable.wiimote_plus_pressed, ButtonType.CLASSIC_BUTTON_PLUS, orientation));
}
if (mPreferences.getBoolean("buttonToggleClassic5", true))
{
overlayButtons.add(initializeOverlayButton(getContext(), R.drawable.wiimote_minus,
- R.drawable.wiimote_minus_pressed, ButtonType.CLASSIC_BUTTON_MINUS));
+ R.drawable.wiimote_minus_pressed, ButtonType.CLASSIC_BUTTON_MINUS, orientation));
}
if (mPreferences.getBoolean("buttonToggleClassic6", true))
{
overlayButtons.add(initializeOverlayButton(getContext(), R.drawable.wiimote_home,
- R.drawable.wiimote_home_pressed, ButtonType.CLASSIC_BUTTON_HOME));
+ R.drawable.wiimote_home_pressed, ButtonType.CLASSIC_BUTTON_HOME, orientation));
}
if (mPreferences.getBoolean("buttonToggleClassic7", true))
{
overlayButtons.add(initializeOverlayButton(getContext(), R.drawable.classic_l,
- R.drawable.classic_l_pressed, ButtonType.CLASSIC_TRIGGER_L));
+ R.drawable.classic_l_pressed, ButtonType.CLASSIC_TRIGGER_L, orientation));
}
if (mPreferences.getBoolean("buttonToggleClassic8", true))
{
overlayButtons.add(initializeOverlayButton(getContext(), R.drawable.classic_r,
- R.drawable.classic_r_pressed, ButtonType.CLASSIC_TRIGGER_R));
+ R.drawable.classic_r_pressed, ButtonType.CLASSIC_TRIGGER_R, orientation));
}
if (mPreferences.getBoolean("buttonToggleClassic9", true))
{
overlayButtons.add(initializeOverlayButton(getContext(), R.drawable.classic_zl,
- R.drawable.classic_zl_pressed, ButtonType.CLASSIC_BUTTON_ZL));
+ R.drawable.classic_zl_pressed, ButtonType.CLASSIC_BUTTON_ZL, orientation));
}
if (mPreferences.getBoolean("buttonToggleClassic10", true))
{
overlayButtons.add(initializeOverlayButton(getContext(), R.drawable.classic_zr,
- R.drawable.classic_zr_pressed, ButtonType.CLASSIC_BUTTON_ZR));
+ R.drawable.classic_zr_pressed, ButtonType.CLASSIC_BUTTON_ZR, orientation));
}
if (mPreferences.getBoolean("buttonToggleClassic11", true))
{
@@ -583,19 +590,19 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
R.drawable.gcwii_dpad_pressed_one_direction,
R.drawable.gcwii_dpad_pressed_two_directions,
ButtonType.CLASSIC_DPAD_UP, ButtonType.CLASSIC_DPAD_DOWN,
- ButtonType.CLASSIC_DPAD_LEFT, ButtonType.CLASSIC_DPAD_RIGHT));
+ ButtonType.CLASSIC_DPAD_LEFT, ButtonType.CLASSIC_DPAD_RIGHT, orientation));
}
if (mPreferences.getBoolean("buttonToggleClassic12", true))
{
overlayJoysticks.add(initializeOverlayJoystick(getContext(), R.drawable.gcwii_joystick_range,
R.drawable.gcwii_joystick, R.drawable.gcwii_joystick_pressed,
- ButtonType.CLASSIC_STICK_LEFT));
+ ButtonType.CLASSIC_STICK_LEFT, orientation));
}
if (mPreferences.getBoolean("buttonToggleClassic13", true))
{
overlayJoysticks.add(initializeOverlayJoystick(getContext(), R.drawable.gcwii_joystick_range,
R.drawable.gcwii_joystick, R.drawable.gcwii_joystick_pressed,
- ButtonType.CLASSIC_STICK_RIGHT));
+ ButtonType.CLASSIC_STICK_RIGHT, orientation));
}
}
@@ -606,33 +613,37 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
overlayDpads.removeAll(overlayDpads);
overlayJoysticks.removeAll(overlayJoysticks);
+ String orientation =
+ getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT ?
+ "-Portrait" : "";
+
// Add all the enabled overlay items back to the HashSet.
if (EmulationActivity.isGameCubeGame() || mPreferences.getInt("wiiController", 3) == 0)
{
- addGameCubeOverlayControls();
+ addGameCubeOverlayControls(orientation);
}
else if (mPreferences.getInt("wiiController", 3) == 4)
{
- addClassicOverlayControls();
+ addClassicOverlayControls(orientation);
}
else
{
- addWiimoteOverlayControls();
+ addWiimoteOverlayControls(orientation);
if (mPreferences.getInt("wiiController", 3) == 3)
{
- addNunchukOverlayControls();
+ addNunchukOverlayControls(orientation);
}
}
invalidate();
}
- private void saveControlPosition(int sharedPrefsId, int x, int y)
+ private void saveControlPosition(int sharedPrefsId, int x, int y, String orientation)
{
final SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(getContext());
SharedPreferences.Editor sPrefsEditor = sPrefs.edit();
- sPrefsEditor.putFloat(sharedPrefsId + "-X", x);
- sPrefsEditor.putFloat(sharedPrefsId + "-Y", y);
+ sPrefsEditor.putFloat(sharedPrefsId + orientation + "-X", x);
+ sPrefsEditor.putFloat(sharedPrefsId + orientation + "-Y", y);
sPrefsEditor.apply();
}
@@ -667,7 +678,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
* @return An {@link InputOverlayDrawableButton} with the correct drawing bounds set.
*/
private static InputOverlayDrawableButton initializeOverlayButton(Context context,
- int defaultResId, int pressedResId, int buttonId)
+ int defaultResId, int pressedResId, int buttonId, String orientation)
{
// Resources handle for fetching the initial Drawable resource.
final Resources res = context.getResources();
@@ -733,8 +744,8 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
// The X and Y coordinates of the InputOverlayDrawableButton on the InputOverlay.
// These were set in the input overlay configuration menu.
- int drawableX = (int) sPrefs.getFloat(buttonId + "-X", 0f);
- int drawableY = (int) sPrefs.getFloat(buttonId + "-Y", 0f);
+ int drawableX = (int) sPrefs.getFloat(buttonId + orientation + "-X", 0f);
+ int drawableY = (int) sPrefs.getFloat(buttonId + orientation + "-Y", 0f);
int width = overlayDrawable.getWidth();
int height = overlayDrawable.getHeight();
@@ -769,7 +780,8 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
int buttonUp,
int buttonDown,
int buttonLeft,
- int buttonRight)
+ int buttonRight,
+ String orientation)
{
// Resources handle for fetching the initial Drawable resource.
final Resources res = context.getResources();
@@ -812,8 +824,8 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
// The X and Y coordinates of the InputOverlayDrawableDpad on the InputOverlay.
// These were set in the input overlay configuration menu.
- int drawableX = (int) sPrefs.getFloat(buttonUp + "-X", 0f);
- int drawableY = (int) sPrefs.getFloat(buttonUp + "-Y", 0f);
+ int drawableX = (int) sPrefs.getFloat(buttonUp + orientation + "-X", 0f);
+ int drawableY = (int) sPrefs.getFloat(buttonUp + orientation + "-Y", 0f);
int width = overlayDrawable.getWidth();
int height = overlayDrawable.getHeight();
@@ -839,7 +851,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
* @return the initialized {@link InputOverlayDrawableJoystick}.
*/
private static InputOverlayDrawableJoystick initializeOverlayJoystick(Context context,
- int resOuter, int defaultResInner, int pressedResInner, int joystick)
+ int resOuter, int defaultResInner, int pressedResInner, int joystick, String orientation)
{
// Resources handle for fetching the initial Drawable resource.
final Resources res = context.getResources();
@@ -860,8 +872,8 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
// The X and Y coordinates of the InputOverlayDrawableButton on the InputOverlay.
// These were set in the input overlay configuration menu.
- int drawableX = (int) sPrefs.getFloat(joystick + "-X", 0f);
- int drawableY = (int) sPrefs.getFloat(joystick + "-Y", 0f);
+ int drawableX = (int) sPrefs.getFloat(joystick + orientation + "-X", 0f);
+ int drawableY = (int) sPrefs.getFloat(joystick + orientation + "-Y", 0f);
// Decide inner scale based on joystick ID
float innerScale;