v0.6.2a: added functionality for audio muting during phone calls

This commit is contained in:
Evan Debenham 2017-10-31 22:37:06 -04:00
parent 62a6c4be34
commit 99156c0005
3 changed files with 53 additions and 20 deletions

View File

@ -21,22 +21,6 @@
package com.watabou.noosa;
import java.util.ArrayList;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import com.watabou.glscripts.Script;
import com.watabou.gltextures.TextureCache;
import com.watabou.glwrap.ScreenConfigChooser;
import com.watabou.glwrap.Vertexbuffer;
import com.watabou.input.Keys;
import com.watabou.input.Touchscreen;
import com.watabou.noosa.audio.Music;
import com.watabou.noosa.audio.Sample;
import com.watabou.utils.BitmapCache;
import com.watabou.utils.SystemTime;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.pm.PackageManager.NameNotFoundException;
@ -53,6 +37,22 @@ import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.View;
import com.watabou.glscripts.Script;
import com.watabou.gltextures.TextureCache;
import com.watabou.glwrap.ScreenConfigChooser;
import com.watabou.glwrap.Vertexbuffer;
import com.watabou.input.Keys;
import com.watabou.input.Touchscreen;
import com.watabou.noosa.audio.Music;
import com.watabou.noosa.audio.Sample;
import com.watabou.utils.BitmapCache;
import com.watabou.utils.SystemTime;
import java.util.ArrayList;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
public class Game extends Activity implements GLSurfaceView.Renderer, View.OnTouchListener {
public static Game instance;
@ -144,11 +144,14 @@ public class Game extends Activity implements GLSurfaceView.Renderer, View.OnTou
setContentView( view );
}
private boolean paused = false;
@Override
public void onStart() {
super.onStart();
now = 0;
paused = false;
view.onResume();
Music.INSTANCE.resume();
@ -163,6 +166,7 @@ public class Game extends Activity implements GLSurfaceView.Renderer, View.OnTou
scene.pause();
}
paused = true;
view.onPause();
Script.reset();
@ -170,6 +174,10 @@ public class Game extends Activity implements GLSurfaceView.Renderer, View.OnTou
Sample.INSTANCE.pause();
}
public boolean isPaused(){
return paused;
}
@Override
public void onDestroy() {
super.onDestroy();

View File

@ -21,13 +21,15 @@
package com.watabou.noosa.audio;
import java.io.IOException;
import com.watabou.noosa.Game;
import android.content.res.AssetFileDescriptor;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import com.watabou.noosa.Game;
import java.io.IOException;
public enum Music implements MediaPlayer.OnPreparedListener, MediaPlayer.OnErrorListener {
@ -138,4 +140,22 @@ public enum Music implements MediaPlayer.OnPreparedListener, MediaPlayer.OnError
public boolean isEnabled() {
return enabled;
}
public static final PhoneStateListener callMute = new PhoneStateListener(){
@Override
public void onCallStateChanged(int state, String incomingNumber)
{
if( state == TelephonyManager.CALL_STATE_RINGING ) {
INSTANCE.pause();
} else if( state == TelephonyManager.CALL_STATE_IDLE ) {
if (!Game.instance.isPaused()) {
INSTANCE.resume();
}
}
super.onCallStateChanged(state, incomingNumber);
}
};
}

View File

@ -24,6 +24,8 @@ package com.shatteredpixel.shatteredpixeldungeon;
import android.content.pm.ActivityInfo;
import android.os.Build;
import android.os.Bundle;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
@ -149,6 +151,9 @@ public class ShatteredPixelDungeon extends Game {
Music.INSTANCE.enable( music() );
Sample.INSTANCE.enable( soundFx() );
Sample.INSTANCE.volume( SFXVol()/10f );
TelephonyManager mgr = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
mgr.listen(Music.callMute, PhoneStateListener.LISTEN_CALL_STATE);
Sample.INSTANCE.load(
Assets.SND_CLICK,