Skip to content

Commit

Permalink
Merge pull request #4236 from SeannyM/android-buttons
Browse files Browse the repository at this point in the history
Android: Wiimote on-screen buttons + more
  • Loading branch information
dolphin-emu-bot committed Sep 30, 2016
2 parents 025dce8 + a317953 commit 394c50f
Show file tree
Hide file tree
Showing 25 changed files with 556 additions and 68 deletions.
2 changes: 1 addition & 1 deletion Source/Android/app/src/main/assets/WiimoteNew.ini
Expand Up @@ -33,7 +33,7 @@ Tilt/Modifier/Range = 50,000000
Shake/X = `Button 132`
Shake/Y = `Button 133`
Shake/Z = `Button 134`
Extension = None
Extension = Nunchuk
Nunchuk/Buttons/C = `Button 200`
Nunchuk/Buttons/Z = `Button 201`
Nunchuk/Stick/Up = `Axis 203`
Expand Down
Expand Up @@ -2,13 +2,17 @@

import android.app.Activity;
import android.app.ActivityOptions;
import android.app.AlertDialog;
import android.app.Fragment;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.hardware.usb.UsbManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;
import android.view.InputDevice;
import android.view.KeyEvent;
Expand Down Expand Up @@ -48,13 +52,17 @@ public final class EmulationActivity extends AppCompatActivity

private String mSubmenuFragmentTag;

private SharedPreferences mPreferences;

// So that MainActivity knows which view to invalidate before the return animation.
private int mPosition;

private boolean mDeviceHasTouchScreen;
private boolean mSystemUiVisible;
private boolean mMenuVisible;

private static boolean mIsGameCubeGame;

/**
* Handlers are a way to pass a message to an Activity telling it to do something
* on the UI thread. This Handler responds to any message, even blank ones, by
Expand Down Expand Up @@ -209,6 +217,10 @@ public void run()
menuFragment.setTitleText(mSelectedTitle);
}
}

mPreferences = PreferenceManager.getDefaultSharedPreferences(this);

mIsGameCubeGame = (NativeLibrary.GetPlatform(path) == 0);
}

@Override
Expand Down Expand Up @@ -383,13 +395,92 @@ public void onMenuItemClicked(int id)
{
switch (id)
{
// Enable/Disable input overlay.
// Enable/Disable specific buttons or the entire input overlay.
case R.id.menu_emulation_input_overlay:
{
EmulationFragment emulationFragment = (EmulationFragment) getFragmentManager()
.findFragmentByTag(EmulationFragment.FRAGMENT_TAG);
boolean[] enabledButtons = new boolean[11];
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.emulation_toggle_input);
if (mIsGameCubeGame)
{
for (int i = 0; i < enabledButtons.length; i++)
{
enabledButtons[i] = mPreferences.getBoolean("buttonToggleGc" + i, true);
}
builder.setMultiChoiceItems(R.array.gcpadButtons, enabledButtons,
new DialogInterface.OnMultiChoiceClickListener()
{
@Override
public void onClick(DialogInterface dialog, int indexSelected, boolean isChecked)
{
SharedPreferences.Editor editor = mPreferences.edit();

emulationFragment.toggleInputOverlayVisibility();
if (mPreferences.getBoolean("buttonToggleGc" + indexSelected, true))
{
// If the button is enabled, disable it.
editor.putBoolean("buttonToggleGc" + indexSelected, false);
}
else
{
// If the button is disabled, enable it.
editor.putBoolean("buttonToggleGc" + indexSelected, true);
}
editor.apply();
}
});
}
else
{
for (int i = 0; i < enabledButtons.length; i++)
{
enabledButtons[i] = mPreferences.getBoolean("buttonToggleWii" + i, true);
}
builder.setMultiChoiceItems(R.array.wiimoteButtons, enabledButtons,
new DialogInterface.OnMultiChoiceClickListener()
{
@Override
public void onClick(DialogInterface dialog, int indexSelected, boolean isChecked)
{
SharedPreferences.Editor editor = mPreferences.edit();

if (mPreferences.getBoolean("buttonToggleWii" + indexSelected, true))
{
// If the button is enabled, disable it.
editor.putBoolean("buttonToggleWii" + indexSelected, false);
}
else
{
// If the button is disabled, enable it.
editor.putBoolean("buttonToggleWii" + indexSelected, true);
}

editor.apply();
}
});
}
builder.setNeutralButton(getString(R.string.emulation_toggle_all), new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialogInterface, int i)
{
EmulationFragment emulationFragment = (EmulationFragment) getFragmentManager()
.findFragmentByTag(EmulationFragment.FRAGMENT_TAG);
emulationFragment.toggleInputOverlayVisibility();
}
});
builder.setPositiveButton(getString(R.string.emulation_done), new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialogInterface, int i)
{
EmulationFragment emulationFragment = (EmulationFragment) getFragmentManager()
.findFragmentByTag(EmulationFragment.FRAGMENT_TAG);
emulationFragment.refreshInputOverlay();
}
});

AlertDialog alertDialog = builder.create();
alertDialog.show();

return;
}
Expand Down Expand Up @@ -667,6 +758,11 @@ public String getSelectedTitle()
return mSelectedTitle;
}

public static boolean isGameCubeGame()
{
return mIsGameCubeGame;
}

public static void launch(Activity activity, String path, String title, String screenshotPath, int position, View sharedView)
{
Intent launcher = new Intent(activity, EmulationActivity.class);
Expand Down
Expand Up @@ -162,6 +162,11 @@ public void toggleInputOverlayVisibility()
editor.apply();
}

public void refreshInputOverlay()
{
mInputOverlay.refreshControls();
}

@Override
public void surfaceCreated(SurfaceHolder holder)
{
Expand Down

0 comments on commit 394c50f

Please sign in to comment.