From c24a22e30fd76495f90f124c9bb2e78f7334e2b9 Mon Sep 17 00:00:00 2001 From: Sean Maas Date: Wed, 21 Sep 2016 17:53:14 -0400 Subject: [PATCH] Android: Use button IDs to save screen layout Using the drawable caused problems such as not being able to have multiple joysticks. --- .../dolphinemu/overlay/InputOverlay.java | 25 +++++++------------ .../overlay/InputOverlayDrawableButton.java | 10 +------- .../overlay/InputOverlayDrawableJoystick.java | 22 +++++++++------- 3 files changed, 23 insertions(+), 34 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 8e296c4efb..d1159776d0 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 @@ -202,7 +202,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener if (mButtonBeingConfigured == button) { //Persist button position by saving new place. - saveControlPosition(mButtonBeingConfigured.getSharedPrefsId(), mButtonBeingConfigured.getBounds().left, mButtonBeingConfigured.getBounds().top); + saveControlPosition(mButtonBeingConfigured.getId(), mButtonBeingConfigured.getBounds().left, mButtonBeingConfigured.getBounds().top); mButtonBeingConfigured = null; } break; @@ -233,7 +233,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener case MotionEvent.ACTION_POINTER_UP: if (mJoystickBeingConfigured != null) { - saveControlPosition(mJoystickBeingConfigured.getSharedPrefsId(), mJoystickBeingConfigured.getBounds().left, mJoystickBeingConfigured.getBounds().top); + saveControlPosition(mJoystickBeingConfigured.getId(), mJoystickBeingConfigured.getBounds().left, mJoystickBeingConfigured.getBounds().top); mJoystickBeingConfigured = null; } break; @@ -245,7 +245,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener return true; } - private void saveControlPosition(String sharedPrefsId, int x, int y) + private void saveControlPosition(int sharedPrefsId, int x, int y) { final SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(getContext()); SharedPreferences.Editor sPrefsEditor = sPrefs.edit(); @@ -318,15 +318,12 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener // Initialize the InputOverlayDrawableButton. final Bitmap bitmap = resizeBitmap(context, BitmapFactory.decodeResource(res, resId), scale); - // String ID of the Drawable. This is what is passed into SharedPreferences - // to check whether or not a value has been set. Send to button so it can be referenced. - final String drawableId = res.getResourceEntryName(resId); - final InputOverlayDrawableButton overlayDrawable = new InputOverlayDrawableButton(res, bitmap, buttonId, drawableId); + final InputOverlayDrawableButton overlayDrawable = new InputOverlayDrawableButton(res, bitmap, buttonId); // 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(drawableId+"-X", 0f); - int drawableY = (int) sPrefs.getFloat(drawableId+"-Y", 0f); + int drawableX = (int) sPrefs.getFloat(buttonId+"-X", 0f); + int drawableY = (int) sPrefs.getFloat(buttonId+"-Y", 0f); // Intrinsic width and height of the InputOverlayDrawableButton. // For any who may not know, intrinsic width/height @@ -369,14 +366,10 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener final Bitmap bitmapOuter = resizeBitmap(context, BitmapFactory.decodeResource(res, resOuter), 0.30f * overlaySize); final Bitmap bitmapInner = BitmapFactory.decodeResource(res, resInner); - // String ID of the Drawable. This is what is passed into SharedPreferences - // to check whether or not a value has been set. - final String drawableId = res.getResourceEntryName(resOuter); - // 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(drawableId+"-X", 0f); - int drawableY = (int) sPrefs.getFloat(drawableId+"-Y", 0f); + int drawableX = (int) sPrefs.getFloat(joystick+"-X", 0f); + int drawableY = (int) sPrefs.getFloat(joystick+"-Y", 0f); // Now set the bounds for the InputOverlayDrawableJoystick. // This will dictate where on the screen (and the what the size) the InputOverlayDrawableJoystick will be. @@ -389,7 +382,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener = new InputOverlayDrawableJoystick(res, bitmapOuter, bitmapInner, outerRect, innerRect, - joystick, drawableId); + joystick); // Need to set the image's position overlayDrawable.setPosition(drawableX, drawableY); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlayDrawableButton.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlayDrawableButton.java index add3cf4621..8601756faa 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlayDrawableButton.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlayDrawableButton.java @@ -23,7 +23,6 @@ public final class InputOverlayDrawableButton extends BitmapDrawable private int mButtonType; private int mPreviousTouchX, mPreviousTouchY; private int mControlPositionX, mControlPositionY; - private String mSharedPrefsId; /** * Constructor @@ -31,13 +30,11 @@ public final class InputOverlayDrawableButton extends BitmapDrawable * @param res {@link Resources} instance. * @param bitmap {@link Bitmap} to use with this Drawable. * @param buttonType Identifier for this type of button. - * @param sharedPrefsId Identifier for getting X and Y control positions from Shared Preferences. */ - public InputOverlayDrawableButton(Resources res, Bitmap bitmap, int buttonType, String sharedPrefsId) + public InputOverlayDrawableButton(Resources res, Bitmap bitmap, int buttonType) { super(res, bitmap); mButtonType = buttonType; - mSharedPrefsId = sharedPrefsId; } /** @@ -73,11 +70,6 @@ public final class InputOverlayDrawableButton extends BitmapDrawable return true; } - public String getSharedPrefsId() - { - return mSharedPrefsId; - } - public void setPosition(int x, int y) { mControlPositionX = x; diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlayDrawableJoystick.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlayDrawableJoystick.java index 56ac768a5a..885d84cb11 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlayDrawableJoystick.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlayDrawableJoystick.java @@ -24,7 +24,7 @@ public final class InputOverlayDrawableJoystick extends BitmapDrawable private final float[] axises = {0f, 0f}; private final BitmapDrawable ringInner; private int trackId = -1; - private String mSharedPrefsId; + private int mJoystickType; private int mControlPositionX, mControlPositionY; private int mPreviousTouchX, mPreviousTouchY; @@ -37,12 +37,11 @@ public final class InputOverlayDrawableJoystick extends BitmapDrawable * @param rectOuter {@link Rect} which represents the outer joystick bounds. * @param rectInner {@link Rect} which represents the inner joystick bounds. * @param joystick Identifier for which joystick this is. - * @param sharedPrefsId Identifier for getting X and Y control positions from Shared Preferences. */ public InputOverlayDrawableJoystick(Resources res, Bitmap bitmapOuter, Bitmap bitmapInner, Rect rectOuter, Rect rectInner, - int joystick, String sharedPrefsId) + int joystick) { super(res, bitmapOuter); this.setBounds(rectOuter); @@ -54,7 +53,17 @@ public final class InputOverlayDrawableJoystick extends BitmapDrawable this.axisIDs[1] = joystick + 2; this.axisIDs[2] = joystick + 3; this.axisIDs[3] = joystick + 4; - mSharedPrefsId = sharedPrefsId; + mJoystickType = joystick; + } + + /** + * Gets this InputOverlayDrawableJoystick's button ID. + * + * @return this InputOverlayDrawableJoystick's button ID. + */ + public int getId() + { + return mJoystickType; } @Override @@ -168,11 +177,6 @@ public final class InputOverlayDrawableJoystick extends BitmapDrawable ringInner.invalidateSelf(); } - public String getSharedPrefsId() - { - return mSharedPrefsId; - } - public void setPosition(int x, int y) { mControlPositionX = x;