Merge pull request #4335 from SeannyM/android-scale
Android: Add custom control scaling
This commit is contained in:
commit
562bc01d0e
|
@ -16,6 +16,7 @@ import android.preference.PreferenceManager;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.view.InputDevice;
|
import android.view.InputDevice;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
@ -24,6 +25,8 @@ import android.view.ViewTreeObserver;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.SeekBar;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.squareup.picasso.Callback;
|
import com.squareup.picasso.Callback;
|
||||||
import com.squareup.picasso.Picasso;
|
import com.squareup.picasso.Picasso;
|
||||||
|
@ -395,12 +398,25 @@ public final class EmulationActivity extends AppCompatActivity
|
||||||
{
|
{
|
||||||
switch (id)
|
switch (id)
|
||||||
{
|
{
|
||||||
|
// Edit the placement of the controls
|
||||||
|
case R.id.menu_emulation_edit_layout:
|
||||||
|
EmulationFragment emulationFragment = (EmulationFragment) getFragmentManager().findFragmentById(R.id.frame_emulation_fragment);
|
||||||
|
if (emulationFragment.isConfiguringControls())
|
||||||
|
{
|
||||||
|
emulationFragment.stopConfiguringControls();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
emulationFragment.startConfiguringControls();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
// Enable/Disable specific buttons or the entire input overlay.
|
// Enable/Disable specific buttons or the entire input overlay.
|
||||||
case R.id.menu_emulation_input_overlay:
|
case R.id.menu_emulation_toggle_controls:
|
||||||
{
|
{
|
||||||
boolean[] enabledButtons = new boolean[11];
|
boolean[] enabledButtons = new boolean[11];
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
builder.setTitle(R.string.emulation_toggle_input);
|
builder.setTitle(R.string.emulation_toggle_controls);
|
||||||
if (mIsGameCubeGame)
|
if (mIsGameCubeGame)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < enabledButtons.length; i++)
|
for (int i = 0; i < enabledButtons.length; i++)
|
||||||
|
@ -485,17 +501,60 @@ public final class EmulationActivity extends AppCompatActivity
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
case R.id.menu_emulation_configure_controls:
|
// Adjust the scale of the overlay controls.
|
||||||
EmulationFragment emulationFragment = (EmulationFragment) getFragmentManager().findFragmentById(R.id.frame_emulation_fragment);
|
case R.id.menu_emulation_adjust_scale:
|
||||||
if (emulationFragment.isConfiguringControls())
|
{
|
||||||
|
LayoutInflater inflater = LayoutInflater.from(this);
|
||||||
|
View view = inflater.inflate(R.layout.dialog_seekbar, null);
|
||||||
|
|
||||||
|
final SeekBar seekbar = (SeekBar) view.findViewById(R.id.seekbar);
|
||||||
|
final TextView value = (TextView) view.findViewById(R.id.text_value);
|
||||||
|
final TextView units = (TextView) view.findViewById(R.id.text_units);
|
||||||
|
|
||||||
|
seekbar.setMax(150);
|
||||||
|
seekbar.setProgress(mPreferences.getInt("controlScale", 50));
|
||||||
|
seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener()
|
||||||
{
|
{
|
||||||
emulationFragment.stopConfiguringControls();
|
public void onStartTrackingTouch(SeekBar seekBar)
|
||||||
}
|
{
|
||||||
else
|
// Do nothing
|
||||||
|
}
|
||||||
|
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
|
||||||
|
{
|
||||||
|
value.setText(String.valueOf(progress + 50));
|
||||||
|
}
|
||||||
|
public void onStopTrackingTouch(SeekBar seekBar)
|
||||||
|
{
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
value.setText(String.valueOf(seekbar.getProgress() + 50));
|
||||||
|
units.setText("%");
|
||||||
|
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
|
builder.setTitle(R.string.emulation_control_scale);
|
||||||
|
builder.setView(view);
|
||||||
|
builder.setPositiveButton(getString(R.string.emulation_done), new DialogInterface.OnClickListener()
|
||||||
{
|
{
|
||||||
emulationFragment.startConfiguringControls();
|
@Override
|
||||||
}
|
public void onClick(DialogInterface dialogInterface, int i)
|
||||||
break;
|
{
|
||||||
|
SharedPreferences.Editor editor = mPreferences.edit();
|
||||||
|
editor.putInt("controlScale", seekbar.getProgress());
|
||||||
|
editor.apply();
|
||||||
|
|
||||||
|
EmulationFragment emulationFragment = (EmulationFragment) getFragmentManager()
|
||||||
|
.findFragmentByTag(EmulationFragment.FRAGMENT_TAG);
|
||||||
|
emulationFragment.refreshInputOverlay();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
AlertDialog alertDialog = builder.create();
|
||||||
|
alertDialog.show();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
case R.id.menu_refresh_wiimotes:
|
case R.id.menu_refresh_wiimotes:
|
||||||
NativeLibrary.RefreshWiimotes();
|
NativeLibrary.RefreshWiimotes();
|
||||||
|
|
|
@ -489,7 +489,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
|
||||||
// SharedPreference to retrieve the X and Y coordinates for the InputOverlayDrawableButton.
|
// SharedPreference to retrieve the X and Y coordinates for the InputOverlayDrawableButton.
|
||||||
final SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(context);
|
final SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
|
|
||||||
// Decide scale based on button ID
|
// Decide scale based on button ID and user preference
|
||||||
float scale;
|
float scale;
|
||||||
|
|
||||||
switch (buttonId)
|
switch (buttonId)
|
||||||
|
@ -525,6 +525,9 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scale *= (sPrefs.getInt("controlScale", 50) + 50);
|
||||||
|
scale /= 100;
|
||||||
|
|
||||||
// Initialize the InputOverlayDrawableButton.
|
// Initialize the InputOverlayDrawableButton.
|
||||||
final Bitmap bitmap = resizeBitmap(context, BitmapFactory.decodeResource(res, resId), scale);
|
final Bitmap bitmap = resizeBitmap(context, BitmapFactory.decodeResource(res, resId), scale);
|
||||||
final InputOverlayDrawableButton overlayDrawable = new InputOverlayDrawableButton(res, bitmap, buttonId);
|
final InputOverlayDrawableButton overlayDrawable = new InputOverlayDrawableButton(res, bitmap, buttonId);
|
||||||
|
@ -572,7 +575,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
|
||||||
// SharedPreference to retrieve the X and Y coordinates for the InputOverlayDrawableDpad.
|
// SharedPreference to retrieve the X and Y coordinates for the InputOverlayDrawableDpad.
|
||||||
final SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(context);
|
final SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
|
|
||||||
// Decide scale based on button ID
|
// Decide scale based on button ID and user preference
|
||||||
float scale;
|
float scale;
|
||||||
|
|
||||||
switch (buttonUp)
|
switch (buttonUp)
|
||||||
|
@ -588,6 +591,9 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scale *= (sPrefs.getInt("controlScale", 50) + 50);
|
||||||
|
scale /= 100;
|
||||||
|
|
||||||
// Initialize the InputOverlayDrawableDpad.
|
// Initialize the InputOverlayDrawableDpad.
|
||||||
final Bitmap bitmap = resizeBitmap(context, BitmapFactory.decodeResource(res, resId), scale);
|
final Bitmap bitmap = resizeBitmap(context, BitmapFactory.decodeResource(res, resId), scale);
|
||||||
final InputOverlayDrawableDpad overlayDrawable = new InputOverlayDrawableDpad(res, bitmap,
|
final InputOverlayDrawableDpad overlayDrawable = new InputOverlayDrawableDpad(res, bitmap,
|
||||||
|
@ -632,8 +638,13 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
|
||||||
// SharedPreference to retrieve the X and Y coordinates for the InputOverlayDrawableJoystick.
|
// SharedPreference to retrieve the X and Y coordinates for the InputOverlayDrawableJoystick.
|
||||||
final SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(context);
|
final SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
|
|
||||||
|
// Decide scale based on user preference
|
||||||
|
float scale = 0.275f;
|
||||||
|
scale *= (sPrefs.getInt("controlScale", 50) + 50);
|
||||||
|
scale /= 100;
|
||||||
|
|
||||||
// Initialize the InputOverlayDrawableJoystick.
|
// Initialize the InputOverlayDrawableJoystick.
|
||||||
final Bitmap bitmapOuter = resizeBitmap(context, BitmapFactory.decodeResource(res, resOuter), 0.275f);
|
final Bitmap bitmapOuter = resizeBitmap(context, BitmapFactory.decodeResource(res, resOuter), scale);
|
||||||
final Bitmap bitmapInner = BitmapFactory.decodeResource(res, resInner);
|
final Bitmap bitmapInner = BitmapFactory.decodeResource(res, resInner);
|
||||||
|
|
||||||
// The X and Y coordinates of the InputOverlayDrawableButton on the InputOverlay.
|
// The X and Y coordinates of the InputOverlayDrawableButton on the InputOverlay.
|
||||||
|
@ -642,15 +653,15 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
|
||||||
int drawableY = (int) sPrefs.getFloat(joystick+"-Y", 0f);
|
int drawableY = (int) sPrefs.getFloat(joystick+"-Y", 0f);
|
||||||
|
|
||||||
// Decide inner scale based on joystick ID
|
// Decide inner scale based on joystick ID
|
||||||
float scale;
|
float innerScale;
|
||||||
|
|
||||||
switch (joystick)
|
switch (joystick)
|
||||||
{
|
{
|
||||||
case ButtonType.STICK_C:
|
case ButtonType.STICK_C:
|
||||||
scale = 1.833f;
|
innerScale = 1.833f;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
scale = 1.375f;
|
innerScale = 1.375f;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -658,7 +669,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
|
||||||
// This will dictate where on the screen (and the what the size) the InputOverlayDrawableJoystick will be.
|
// This will dictate where on the screen (and the what the size) the InputOverlayDrawableJoystick will be.
|
||||||
int outerSize = bitmapOuter.getWidth();
|
int outerSize = bitmapOuter.getWidth();
|
||||||
Rect outerRect = new Rect(drawableX, drawableY, drawableX + outerSize, drawableY + outerSize);
|
Rect outerRect = new Rect(drawableX, drawableY, drawableX + outerSize, drawableY + outerSize);
|
||||||
Rect innerRect = new Rect(0, 0, (int) (outerSize / scale), (int) (outerSize / scale));
|
Rect innerRect = new Rect(0, 0, (int) (outerSize / innerScale), (int) (outerSize / innerScale));
|
||||||
|
|
||||||
// Send the drawableId to the joystick so it can be referenced when saving control position.
|
// Send the drawableId to the joystick so it can be referenced when saving control position.
|
||||||
final InputOverlayDrawableJoystick overlayDrawable
|
final InputOverlayDrawableJoystick overlayDrawable
|
||||||
|
|
|
@ -9,12 +9,12 @@
|
||||||
android:id="@+id/seekbar"
|
android:id="@+id/seekbar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginLeft="@dimen/spacing_xlarge"
|
android:layout_marginLeft="@dimen/spacing_large"
|
||||||
android:layout_marginRight="@dimen/spacing_xlarge"
|
android:layout_marginRight="@dimen/spacing_large"
|
||||||
android:layout_alignParentEnd="true"
|
android:layout_alignParentEnd="true"
|
||||||
android:layout_alignParentStart="true"
|
android:layout_alignParentStart="true"
|
||||||
android:layout_below="@+id/text_value"
|
android:layout_below="@+id/text_value"
|
||||||
android:layout_marginBottom="@dimen/spacing_xlarge"/>
|
android:layout_marginBottom="@dimen/spacing_medlarge"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
@ -23,8 +23,8 @@
|
||||||
android:id="@+id/text_value"
|
android:id="@+id/text_value"
|
||||||
android:layout_alignParentTop="true"
|
android:layout_alignParentTop="true"
|
||||||
android:layout_centerHorizontal="true"
|
android:layout_centerHorizontal="true"
|
||||||
android:layout_marginTop="@dimen/spacing_xlarge"
|
android:layout_marginTop="@dimen/spacing_medlarge"
|
||||||
android:layout_marginBottom="@dimen/spacing_large"/>
|
android:layout_marginBottom="@dimen/spacing_medlarge"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|
|
@ -25,18 +25,6 @@
|
||||||
android:title="@string/emulation_quickload"
|
android:title="@string/emulation_quickload"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- Enable/Disable Input Overlay -->
|
|
||||||
<item
|
|
||||||
android:id="@+id/menu_emulation_input_overlay"
|
|
||||||
android:showAsAction="never"
|
|
||||||
android:title="@string/emulation_toggle_input"/>
|
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/menu_emulation_configure_controls"
|
|
||||||
android:showAsAction="never"
|
|
||||||
android:title="@string/emulation_configure_controls">
|
|
||||||
</item>
|
|
||||||
|
|
||||||
<!-- Save State Slots -->
|
<!-- Save State Slots -->
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_emulation_save_root"
|
android:id="@+id/menu_emulation_save_root"
|
||||||
|
@ -92,4 +80,23 @@
|
||||||
android:title="@string/overlay_slot5"/>
|
android:title="@string/overlay_slot5"/>
|
||||||
</menu>
|
</menu>
|
||||||
</item>
|
</item>
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_emulation_configure_controls"
|
||||||
|
android:showAsAction="never"
|
||||||
|
android:title="@string/emulation_configure_controls">
|
||||||
|
<menu>
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_emulation_edit_layout"
|
||||||
|
android:title="@string/emulation_edit_layout"/>
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_emulation_toggle_controls"
|
||||||
|
android:title="@string/emulation_toggle_controls"/>
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_emulation_adjust_scale"
|
||||||
|
android:title="@string/emulation_control_scale"/>
|
||||||
|
</menu>
|
||||||
|
</item>
|
||||||
</menu>
|
</menu>
|
||||||
|
|
|
@ -211,7 +211,7 @@
|
||||||
<item>2</item>
|
<item>2</item>
|
||||||
<item>+</item>
|
<item>+</item>
|
||||||
<item>-</item>
|
<item>-</item>
|
||||||
<item>Home</item>
|
<item>Home</item>
|
||||||
<item>C</item>
|
<item>C</item>
|
||||||
<item>Z</item>
|
<item>Z</item>
|
||||||
<item>D-Pad</item>
|
<item>D-Pad</item>
|
||||||
|
|
|
@ -355,13 +355,15 @@
|
||||||
<string name="dialog_seekbar_neg">Cancel</string>
|
<string name="dialog_seekbar_neg">Cancel</string>
|
||||||
|
|
||||||
<!-- Emulation Menu -->
|
<!-- Emulation Menu -->
|
||||||
<string name="emulation_toggle_input">Toggle Touch Controls</string>
|
|
||||||
<string name="emulation_toggle_all">Toggle All</string>
|
|
||||||
<string name="emulation_quicksave">Quick Save</string>
|
<string name="emulation_quicksave">Quick Save</string>
|
||||||
<string name="emulation_quickload">Quick Load</string>
|
<string name="emulation_quickload">Quick Load</string>
|
||||||
<string name="emulation_refresh_wiimotes">Refresh Wiimotes</string>
|
<string name="emulation_refresh_wiimotes">Refresh Wiimotes</string>
|
||||||
<string name="emulation_configure_controls">Configure Controls</string>
|
<string name="emulation_configure_controls">Configure Controls</string>
|
||||||
|
<string name="emulation_edit_layout">Edit Layout</string>
|
||||||
<string name="emulation_done">Done</string>
|
<string name="emulation_done">Done</string>
|
||||||
|
<string name="emulation_toggle_controls">Toggle Controls</string>
|
||||||
|
<string name="emulation_toggle_all">Toggle All</string>
|
||||||
|
<string name="emulation_control_scale">Adjust Scale</string>
|
||||||
|
|
||||||
<!-- GC Adapter Menu-->
|
<!-- GC Adapter Menu-->
|
||||||
<string name="gc_adapter_rumble">Enable Vibration</string>
|
<string name="gc_adapter_rumble">Enable Vibration</string>
|
||||||
|
|
Loading…
Reference in New Issue