Permalink
Browse files

Merge pull request #7400 from zackhow/phone-rumble

Android: Add rumble for phone
  • Loading branch information...
degasus committed Sep 21, 2018
2 parents a61036a + 1f34471 commit 85961f996ef1c142b056c29bd88456bf2d0d00c9
@@ -18,6 +18,7 @@
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.android.providers.tv.permission.READ_EPG_DATA"/>
<uses-permission android:name="com.android.providers.tv.permission.WRITE_EPG_DATA"/>
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:name=".DolphinApplication"
@@ -25,6 +25,7 @@ Triggers/R = `Axis 21`
Triggers/L-Analog = `Axis 20`
Triggers/R-Analog = `Axis 21`
Triggers/Threshold = 90,000000
Rumble/Motor = `Rumble 700`
[GCPad2]
Device = Android/1/Touchscreen
Buttons/A = `Button 0`
@@ -52,6 +53,7 @@ Triggers/R = `Axis 21`
Triggers/L-Analog = `Axis 20`
Triggers/R-Analog = `Axis 21`
Triggers/Threshold = 90,000000
Rumble/Motor = `Rumble 700`
[GCPad3]
Device = Android/2/Touchscreen
Buttons/A = `Button 0`
@@ -79,6 +81,7 @@ Triggers/R = `Axis 21`
Triggers/L-Analog = `Axis 20`
Triggers/R-Analog = `Axis 21`
Triggers/Threshold = 90,000000
Rumble/Motor = `Rumble 700`
[GCPad4]
Device = Android/3/Touchscreen
Buttons/A = `Button 0`
@@ -106,3 +109,4 @@ Triggers/R = `Axis 21`
Triggers/L-Analog = `Axis 20`
Triggers/R-Analog = `Axis 21`
Triggers/Threshold = 90,000000
Rumble/Motor = `Rumble 700`
@@ -133,6 +133,7 @@ Turntable/Effect/Dial = `Axis 621`
Turntable/Crossfade/Left = `Axis 623`
Turntable/Crossfade/Right = `Axis 624`
Source = 1
Rumble/Motor = `Rumble 700`
[Wiimote2]
Device = Android/5/Touchscreen
Buttons/A = `Button 100`
@@ -268,6 +269,7 @@ Turntable/Effect/Dial = `Axis 621`
Turntable/Crossfade/Left = `Axis 623`
Turntable/Crossfade/Right = `Axis 624`
Source = 0
Rumble/Motor = `Rumble 700`
[Wiimote3]
Device = Android/6/Touchscreen
Buttons/A = `Button 100`
@@ -403,6 +405,7 @@ Turntable/Effect/Dial = `Axis 621`
Turntable/Crossfade/Left = `Axis 623`
Turntable/Crossfade/Right = `Axis 624`
Source = 0
Rumble/Motor = `Rumble 700`
[Wiimote4]
Device = Android/7/Touchscreen
Buttons/A = `Button 100`
@@ -538,3 +541,4 @@ Turntable/Effect/Dial = `Axis 621`
Turntable/Crossfade/Left = `Axis 623`
Turntable/Crossfade/Right = `Axis 624`
Source = 0
Rumble/Motor = `Rumble 700`
@@ -7,6 +7,11 @@
package org.dolphinemu.dolphinemu;
import android.app.AlertDialog;
import android.content.Context;
import android.os.Build;
import android.os.VibrationEffect;
import android.os.Vibrator;
import android.preference.PreferenceManager;
import android.view.Surface;
import org.dolphinemu.dolphinemu.activities.EmulationActivity;
@@ -225,6 +230,39 @@ private NativeLibrary()
*/
public static native void onGamePadMoveEvent(String Device, int Axis, float Value);
/**
* Rumble sent from native. Currently only supports phone rumble.
*
* @param padID Ignored for now. Future use would be to pass rumble to a connected controller
* @param state Ignored for now since phone rumble can't just be 'turned' on/off
*/
public static void rumble(int padID, double state)
{
final EmulationActivity emulationActivity = sEmulationActivity.get();
if (emulationActivity == null)
{
Log.warning("[NativeLibrary] EmulationActivity is null");
return;
}
if (PreferenceManager.getDefaultSharedPreferences(emulationActivity)
.getBoolean("phoneRumble", true))
{
Vibrator vibrator = (Vibrator) emulationActivity.getSystemService(Context.VIBRATOR_SERVICE);
if (vibrator != null && vibrator.hasVibrator())
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
{
vibrator.vibrate(VibrationEffect.createOneShot(100, VibrationEffect.DEFAULT_AMPLITUDE));
}
else
{
vibrator.vibrate(100);
}
}
}
}
public static native String GetUserSetting(String gameID, String Section, String Key);
public static native void SetUserSetting(String gameID, String Section, String Key, String Value);
@@ -124,6 +124,7 @@
public static final int MENU_ACTION_EXIT = 22;
public static final int MENU_ACTION_CHANGE_DISC = 23;
public static final int MENU_ACTION_JOYSTICK_REL_CENTER = 24;
public static final int MENU_ACTION_RUMBLE = 25;
private static SparseIntArray buttonsActionsMap = new SparseIntArray();
@@ -163,6 +164,7 @@
buttonsActionsMap.append(R.id.menu_exit, EmulationActivity.MENU_ACTION_EXIT);
buttonsActionsMap.append(R.id.menu_emulation_joystick_rel_center,
EmulationActivity.MENU_ACTION_JOYSTICK_REL_CENTER);
buttonsActionsMap.append(R.id.menu_emulation_rumble, EmulationActivity.MENU_ACTION_RUMBLE);
}
public static void launch(FragmentActivity activity, GameFile gameFile, int position,
@@ -473,6 +475,8 @@ public boolean onCreateOptionsMenu(Menu menu)
// Populate the checkbox value for joystick center on touch
menu.findItem(R.id.menu_emulation_joystick_rel_center)
.setChecked(mPreferences.getBoolean("joystickRelCenter", true));
menu.findItem(R.id.menu_emulation_rumble)
.setChecked(mPreferences.getBoolean("phoneRumble", true));
return true;
}
@@ -504,7 +508,11 @@ public void handleCheckableMenuAction(@MenuAction int menuAction, MenuItem item)
case MENU_ACTION_JOYSTICK_REL_CENTER:
item.setChecked(!item.isChecked());
toggleJoystickRelCenter(item.isChecked());
return;
break;
case MENU_ACTION_RUMBLE:
item.setChecked(!item.isChecked());
toggleRumble(item.isChecked());
break;
}
}
@@ -636,6 +644,13 @@ private void toggleJoystickRelCenter(boolean state)
editor.commit();
}
private void toggleRumble(boolean state)
{
final SharedPreferences.Editor editor = mPreferences.edit();
editor.putBoolean("phoneRumble", state);
editor.apply();
}
private void editControlsPlacement()
{
@@ -98,6 +98,10 @@
android:id="@+id/menu_emulation_joystick_rel_center"
android:checkable="true"
android:title="@string/emulation_control_joystick_rel_center"/>
<item
android:id="@+id/menu_emulation_rumble"
android:checkable="true"
android:title="@string/emulation_control_rumble"/>
</menu>
</item>
@@ -98,11 +98,16 @@
android:id="@+id/menu_emulation_joystick_rel_center"
android:checkable="true"
android:title="@string/emulation_control_joystick_rel_center"/>
<item
android:id="@+id/menu_emulation_rumble"
android:checkable="true"
android:title="@string/emulation_control_rumble"/>
</group>
<item
android:id="@+id/menu_emulation_choose_controller"
android:title="@string/emulation_choose_controller"/>
</menu>
</item>
@@ -271,6 +271,7 @@
<string name="emulation_toggle_all">Toggle All</string>
<string name="emulation_control_scale">Adjust Scale</string>
<string name="emulation_control_joystick_rel_center">Relative Stick Center</string>
<string name="emulation_control_rumble">Rumble</string>
<string name="emulation_choose_controller">Choose Controller</string>
<string name="emulation_controller_changed">You may have to reload the game after changing extensions.</string>
<string name="emulation_touch_button_help">To change the button layout, open the menu -> Configure Controls -> Edit Layout</string>
Oops, something went wrong.

0 comments on commit 85961f9

Please sign in to comment.