Added option to pause playback on incoming call (enabled by default).

This commit is contained in:
Felix Ableitner 2014-05-01 20:55:06 +02:00
parent 38815cae34
commit e90039e7e8
6 changed files with 55 additions and 4 deletions

View file

@ -8,7 +8,8 @@
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-sdk
android:minSdkVersion="8"

View file

@ -10,7 +10,7 @@ Android 2.2 (Gingerbread) or higher is required.
[Download](http://f-droid.org/repository/browse/?fdid=com.github.nutomic.controldlna)
Note about permissions: All permissions are required for UPNP (for the necessary wifi access). The app does not connect to the internet at all.
Permissions: READ_PHONE_STATE is required to pause playback on phone call. All other permissions are required for UPnP functionality. ControlDLNA does not access the internet.
## Building

View file

@ -42,6 +42,9 @@
<!-- Title for the SettingsActivity -->
<string name="settings_title">Preferences</string>
<!-- Title for the pause playback on call preference -->
<string name="incoming_phone_call_pause">Pause playback on incoming phone call</string>
<!-- Title for the contact developer preference -->
<string name="contact_dev_title">Contact Developer</string>

View file

@ -1,6 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference
android:key="incoming_phone_call_pause"
android:title="@string/incoming_phone_call_pause"
android:defaultValue="true" />
<Preference
android:key="contact_dev"
android:title="@string/contact_dev_title" />

View file

@ -41,6 +41,7 @@ import com.github.nutomic.controldlna.R;
public class PreferencesActivity extends PreferenceActivity {
public static final String KEY_INCOMING_PHONE_CALL_PAUSE = "incoming_phone_call_pause";
private static final String KEY_CONTACT_DEV = "contact_dev";
private Preference mContactDev;

View file

@ -41,12 +41,14 @@ import org.teleal.cling.support.model.item.MusicTrack;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.support.v4.app.NotificationCompat;
import android.support.v7.media.MediaControlIntent;
import android.support.v7.media.MediaItemStatus;
@ -54,10 +56,13 @@ import android.support.v7.media.MediaRouteSelector;
import android.support.v7.media.MediaRouter;
import android.support.v7.media.MediaRouter.ControlRequestCallback;
import android.support.v7.media.MediaRouter.RouteInfo;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import com.github.nutomic.controldlna.R;
import com.github.nutomic.controldlna.gui.MainActivity;
import com.github.nutomic.controldlna.gui.PreferencesActivity;
import com.github.nutomic.controldlna.gui.RouteFragment;
import com.github.nutomic.controldlna.utility.LoadImageTask;
@ -144,7 +149,7 @@ public class MediaRouterPlayService extends Service {
intent.setAction("showRouteFragment");
Notification notification = new NotificationCompat.Builder(MediaRouterPlayService.this)
.setContentIntent(PendingIntent.getActivity(MediaRouterPlayService.this, 0,
intent, 0))
intent, 0))
.setContentTitle(title)
.setContentText(artist)
.setLargeIcon(result)
@ -156,11 +161,47 @@ public class MediaRouterPlayService extends Service {
}
/**
* Listens for incoming phone calls and pauses playback then.
*/
private class PhoneCallListener extends PhoneStateListener {
private boolean mPausedForCall = false;
@Override
public void onCallStateChanged(int state, String incomingNumber) {
if (!PreferenceManager.getDefaultSharedPreferences(MediaRouterPlayService.this)
.getBoolean(PreferencesActivity.KEY_INCOMING_PHONE_CALL_PAUSE, true)) {
return;
}
if (TelephonyManager.CALL_STATE_RINGING == state ||
TelephonyManager.CALL_STATE_OFFHOOK == state) {
// phone ringing or call active
pause();
mPausedForCall = true;
}
if (mPausedForCall && TelephonyManager.CALL_STATE_IDLE == state) {
// run when class initial and phone call ended
resume();
mPausedForCall = false;
}
}
}
@Override
public void onCreate() {
super.onCreate();
mMediaRouter = MediaRouter.getInstance(this);
pollStatus();
PhoneCallListener phoneListener = new PhoneCallListener();
TelephonyManager telephonyManager = (TelephonyManager) this
.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(phoneListener,
PhoneStateListener.LISTEN_CALL_STATE);
}
@Override