diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index a4a2d9ca..71f3a4bc 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -175,6 +175,9 @@
+
+
+
diff --git a/res/layout/notification_layout.xml b/res/layout/notification_layout.xml
new file mode 100644
index 00000000..5e45b4a7
--- /dev/null
+++ b/res/layout/notification_layout.xml
@@ -0,0 +1,40 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisActivity.java b/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisActivity.java
index 646eb978..5aa33543 100644
--- a/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisActivity.java
+++ b/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisActivity.java
@@ -37,9 +37,9 @@ import android.widget.Spinner;
import android.widget.TextView;
import org.kde.kdeconnect.Backends.BaseLink;
+import org.kde.kdeconnect.Backends.BaseLinkProvider;
import org.kde.kdeconnect.BackgroundService;
import org.kde.kdeconnect.Device;
-import org.kde.kdeconnect.Backends.BaseLinkProvider;
import org.kde.kdeconnect.NetworkPackage;
import org.kde.kdeconnect_tp.R;
@@ -54,6 +54,7 @@ public class MprisActivity extends ActionBarActivity {
private final Handler positionSeekUpdateHandler = new Handler();
private Runnable positionSeekUpdateRunnable;
private boolean positionSeekUpdateScheduled = false;
+ NotificationPanel nPanel;
private static String milisToProgress(long milis) {
int length = (int)(milis / 1000); //From milis to seconds
@@ -71,6 +72,7 @@ public class MprisActivity extends ActionBarActivity {
text.append(seconds);
return text.toString();
}
+
protected void connectToPlugin() {
final String deviceId = getIntent().getStringExtra("deviceId");
@@ -119,7 +121,7 @@ public class MprisActivity extends ActionBarActivity {
} else {
((ImageButton) findViewById(R.id.play_button)).setImageResource(android.R.drawable.ic_media_play);
}
-
+ nPanel.updateStatus(s,isPlaying);
}
});
}
@@ -279,6 +281,9 @@ public class MprisActivity extends ActionBarActivity {
deviceId = getIntent().getStringExtra("deviceId");
+ nPanel = new NotificationPanel(this, deviceId);
+
+
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
String interval_time_str = prefs.getString(getString(R.string.mpris_time_key),
getString(R.string.mpris_time_default));
diff --git a/src/org/kde/kdeconnect/Plugins/MprisPlugin/NotificationPanel.java b/src/org/kde/kdeconnect/Plugins/MprisPlugin/NotificationPanel.java
new file mode 100644
index 00000000..d7926390
--- /dev/null
+++ b/src/org/kde/kdeconnect/Plugins/MprisPlugin/NotificationPanel.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2014 Da-Jin Chu
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+*/
+package org.kde.kdeconnect.Plugins.MprisPlugin;
+
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.content.Context;
+import android.content.Intent;
+import android.support.v4.app.NotificationCompat;
+import android.util.Log;
+import android.widget.RemoteViews;
+
+import org.kde.kdeconnect_tp.R;
+
+public class NotificationPanel {
+
+ String deviceId;
+
+ private MprisActivity parent;
+ private NotificationManager nManager;
+ private NotificationCompat.Builder nBuilder;
+ private RemoteViews remoteView;
+
+ public NotificationPanel(MprisActivity parent, String deviceId) {
+ this.parent = parent;
+ this.deviceId = deviceId;
+ nBuilder = new NotificationCompat.Builder(parent)
+ .setContentTitle("Mpris Activity")
+ .setSmallIcon(android.R.drawable.ic_media_play)
+ .setOngoing(true);
+
+ remoteView = new RemoteViews(parent.getPackageName(), R.layout.notification_layout);
+
+ //set the button listeners
+ setListeners(remoteView);
+ nBuilder.setContent(remoteView);
+
+ nManager = (NotificationManager) parent.getSystemService(Context.NOTIFICATION_SERVICE);
+ nManager.notify(2, nBuilder.build());
+ }
+
+ public void updateStatus(String songName, boolean isPlaying){
+ remoteView.setTextViewText(R.id.notification_song, songName);
+ if(isPlaying){
+ remoteView.setImageViewResource(R.id.notification_play_pause, android.R.drawable.ic_media_pause);
+ }else{
+ remoteView.setImageViewResource(R.id.notification_play_pause, android.R.drawable.ic_media_play);
+ }
+ nBuilder.setContent(remoteView);
+ nManager.notify(2,nBuilder.build());
+ }
+
+ public void setListeners(RemoteViews view){
+ Intent playpause = new Intent(parent,NotificationReturnSlot.class);
+ playpause.putExtra("action", "play");
+ playpause.putExtra("deviceId",deviceId);
+ Log.i("Panel", deviceId);
+ PendingIntent btn1 = PendingIntent.getBroadcast(parent, 1, playpause, 0);
+ view.setOnClickPendingIntent(R.id.notification_play_pause, btn1);
+
+ Intent next = new Intent(parent, NotificationReturnSlot.class);
+ next.putExtra("action", "next");
+ next.putExtra("deviceId",deviceId);
+ PendingIntent btn2 = PendingIntent.getBroadcast(parent, 2, next, 0);
+ view.setOnClickPendingIntent(R.id.notification_next, btn2);
+
+ Intent prev = new Intent(parent, NotificationReturnSlot.class);
+ prev.putExtra("action", "prev");
+ prev.putExtra("deviceId",deviceId);
+ PendingIntent btn3 = PendingIntent.getBroadcast(
+ parent, 3, prev, 0);
+ view.setOnClickPendingIntent(R.id.notification_prev, btn3);
+ }
+
+ public void notificationCancel() {
+ nManager.cancel(2);
+ }
+}
\ No newline at end of file
diff --git a/src/org/kde/kdeconnect/Plugins/MprisPlugin/NotificationReturnSlot.java b/src/org/kde/kdeconnect/Plugins/MprisPlugin/NotificationReturnSlot.java
new file mode 100644
index 00000000..8f72c1f2
--- /dev/null
+++ b/src/org/kde/kdeconnect/Plugins/MprisPlugin/NotificationReturnSlot.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2014 Da-Jin Chu
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License or (at your option) version 3 or any later version
+ * accepted by the membership of KDE e.V. (or its successor approved
+ * by the membership of KDE e.V.), which shall act as a proxy
+ * defined in Section 14 of version 3 of the license.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+*/
+package org.kde.kdeconnect.Plugins.MprisPlugin;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.util.Log;
+
+import org.kde.kdeconnect.BackgroundService;
+import org.kde.kdeconnect.Device;
+
+public class NotificationReturnSlot extends BroadcastReceiver {
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ String action = intent.getStringExtra("action");
+ final String deviceId = intent.getStringExtra("deviceId");
+ Log.i("NotificationReturnSlot", action+deviceId);
+ if (action.equals("play")) {
+ BackgroundService.RunCommand(context, new BackgroundService.InstanceCallback() {
+ @Override
+ public void onServiceStart(BackgroundService service) {
+ Device device = service.getDevice(deviceId);
+ MprisPlugin mpris = (MprisPlugin) device.getPlugin("plugin_mpris");
+ if (mpris == null) return;
+ mpris.sendAction("PlayPause");
+ }
+ });
+ } else if (action.equals("next")) {
+ BackgroundService.RunCommand(context, new BackgroundService.InstanceCallback() {
+ @Override
+ public void onServiceStart(BackgroundService service) {
+ Device device = service.getDevice(deviceId);
+ MprisPlugin mpris = (MprisPlugin) device.getPlugin("plugin_mpris");
+ if (mpris == null) return;
+ mpris.sendAction("Next");
+ }
+ });
+ }else if(action.equals("prev")){
+ BackgroundService.RunCommand(context, new BackgroundService.InstanceCallback() {
+ @Override
+ public void onServiceStart(BackgroundService service) {
+ Device device = service.getDevice(deviceId);
+ MprisPlugin mpris = (MprisPlugin) device.getPlugin("plugin_mpris");
+ if (mpris == null) return;
+ mpris.sendAction("Previous");
+ }
+ });
+ }
+ }
+}
diff --git a/src/org/kde/kdeconnect/UserInterface/MainActivity.java b/src/org/kde/kdeconnect/UserInterface/MainActivity.java
index 99fcddc3..de6aee79 100644
--- a/src/org/kde/kdeconnect/UserInterface/MainActivity.java
+++ b/src/org/kde/kdeconnect/UserInterface/MainActivity.java
@@ -105,6 +105,7 @@ public class MainActivity extends ActionBarActivity {
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM);
+
}