Skip to content

Commit

Permalink
Merge pull request #7400 from zackhow/phone-rumble
Browse files Browse the repository at this point in the history
Android: Add rumble for phone
  • Loading branch information
degasus committed Sep 21, 2018
2 parents a61036a + 1f34471 commit 85961f9
Show file tree
Hide file tree
Showing 12 changed files with 415 additions and 61 deletions.
1 change: 1 addition & 0 deletions Source/Android/app/src/main/AndroidManifest.xml
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions Source/Android/app/src/main/assets/GCPadNew.ini
Expand Up @@ -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`
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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`
4 changes: 4 additions & 0 deletions Source/Android/app/src/main/assets/WiimoteNew.ini
Expand Up @@ -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`
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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`
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Expand Up @@ -124,6 +124,7 @@ public final class EmulationActivity extends AppCompatActivity
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();
Expand Down Expand Up @@ -163,6 +164,7 @@ public final class EmulationActivity extends AppCompatActivity
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,
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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()
{
Expand Down
4 changes: 4 additions & 0 deletions Source/Android/app/src/main/res/menu/menu_emulation.xml
Expand Up @@ -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>

Expand Down
5 changes: 5 additions & 0 deletions Source/Android/app/src/main/res/menu/menu_emulation_wii.xml
Expand Up @@ -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>

Expand Down
1 change: 1 addition & 0 deletions Source/Android/app/src/main/res/values/strings.xml
Expand Up @@ -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>
Expand Down

0 comments on commit 85961f9

Please sign in to comment.