Cancel the vibration when the app pauses or when is being destroyed.
This commit is contained in:
@@ -33,6 +33,8 @@ public class GameActivity extends SDLActivity {
|
|||||||
|
|
||||||
public Handler handler;
|
public Handler handler;
|
||||||
|
|
||||||
|
protected Vibrator vibrator;
|
||||||
|
|
||||||
|
|
||||||
public static double getDisplayXDPI () {
|
public static double getDisplayXDPI () {
|
||||||
|
|
||||||
@@ -107,6 +109,8 @@ public class GameActivity extends SDLActivity {
|
|||||||
|
|
||||||
protected void onCreate (Bundle state) {
|
protected void onCreate (Bundle state) {
|
||||||
|
|
||||||
|
vibrator = (Vibrator)mSingleton.getSystemService (Context.VIBRATOR_SERVICE);
|
||||||
|
|
||||||
super.onCreate (state);
|
super.onCreate (state);
|
||||||
|
|
||||||
assetManager = getAssets ();
|
assetManager = getAssets ();
|
||||||
@@ -138,6 +142,14 @@ public class GameActivity extends SDLActivity {
|
|||||||
|
|
||||||
@Override protected void onDestroy () {
|
@Override protected void onDestroy () {
|
||||||
|
|
||||||
|
if (vibrator != null) {
|
||||||
|
|
||||||
|
Log.d ("GameActivity", "Cancelling vibration");
|
||||||
|
|
||||||
|
vibrator.cancel ();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
for (Extension extension : extensions) {
|
for (Extension extension : extensions) {
|
||||||
|
|
||||||
extension.onDestroy ();
|
extension.onDestroy ();
|
||||||
@@ -177,6 +189,14 @@ public class GameActivity extends SDLActivity {
|
|||||||
|
|
||||||
@Override protected void onPause () {
|
@Override protected void onPause () {
|
||||||
|
|
||||||
|
if (vibrator != null) {
|
||||||
|
|
||||||
|
Log.d ("GameActivity", "Cancelling vibration");
|
||||||
|
|
||||||
|
vibrator.cancel ();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
super.onPause ();
|
super.onPause ();
|
||||||
|
|
||||||
for (Extension extension : extensions) {
|
for (Extension extension : extensions) {
|
||||||
@@ -371,9 +391,7 @@ public class GameActivity extends SDLActivity {
|
|||||||
|
|
||||||
public static void vibrate (int period, int duration) {
|
public static void vibrate (int period, int duration) {
|
||||||
|
|
||||||
Vibrator v = (Vibrator)mSingleton.getSystemService (Context.VIBRATOR_SERVICE);
|
if (vibrator == null || !vibrator.hasVibrator ()) {
|
||||||
|
|
||||||
if (v == null || !v.hasVibrator()) {
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -383,7 +401,7 @@ public class GameActivity extends SDLActivity {
|
|||||||
|
|
||||||
if (period == 0) {
|
if (period == 0) {
|
||||||
|
|
||||||
v.vibrate (VibrationEffect.createOneShot (duration, VibrationEffect.DEFAULT_AMPLITUDE));
|
vibrator.vibrate (VibrationEffect.createOneShot (duration, VibrationEffect.DEFAULT_AMPLITUDE));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@@ -397,7 +415,7 @@ public class GameActivity extends SDLActivity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
v.vibrate (VibrationEffect.createWaveform (pattern, -1));
|
vibrator.vibrate (VibrationEffect.createWaveform (pattern, -1));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -405,7 +423,7 @@ public class GameActivity extends SDLActivity {
|
|||||||
|
|
||||||
if (period == 0) {
|
if (period == 0) {
|
||||||
|
|
||||||
v.vibrate (duration);
|
vibrator.vibrate (duration);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@@ -419,7 +437,7 @@ public class GameActivity extends SDLActivity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
v.vibrate (pattern, -1);
|
vibrator.vibrate (pattern, -1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user