Commit ded027d3 authored by Albert Vaca Cintora's avatar Albert Vaca Cintora

Revert "Added MPRIS controls from the notifications panel"

This reverts commit 816a6f5c.

Conflicts:
	src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisActivity.java
	src/org/kde/kdeconnect/Plugins/MprisPlugin/NotificationPanel.java
	src/org/kde/kdeconnect/Plugins/MprisPlugin/NotificationReturnSlot.java
parent e1cec047
......@@ -175,9 +175,6 @@
</intent-filter>
</activity>
<receiver android:name="org.kde.kdeconnect.Plugins.MprisPlugin.NotificationReturnSlot"></receiver>
<service android:name="org.kde.kdeconnect.Plugins.NotificationsPlugin.NotificationReceiver"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
<intent-filter>
......
......@@ -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;
......@@ -50,7 +50,6 @@ public class MprisActivity extends ActionBarActivity {
private String deviceId;
private final Handler positionSeekUpdateHandler = new Handler();
private Runnable positionSeekUpdateRunnable = null;
private NotificationPanel nPanel = null;
private String targetPlayer = null;
private static String milisToProgress(long milis) {
......@@ -69,7 +68,6 @@ public class MprisActivity extends ActionBarActivity {
text.append(seconds);
return text.toString();
}
protected void connectToPlugin() {
BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
......@@ -166,9 +164,6 @@ public class MprisActivity extends ActionBarActivity {
findViewById(R.id.ff_button).setVisibility(View.VISIBLE);
findViewById(R.id.positionSeek).setVisibility(View.VISIBLE);
}
//If there was a panel already, this will override it
nPanel = new NotificationPanel(getApplicationContext(), device, player);
}
@Override
......
/*
* Copyright 2014 Da-Jin Chu <dajinchu@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.kde.kdeconnect.Plugins.MprisPlugin;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder;
import android.util.Log;
import android.widget.RemoteViews;
import org.kde.kdeconnect.Device;
import org.kde.kdeconnect.Helpers.NotificationsHelper;
import org.kde.kdeconnect_tp.R;
public class NotificationPanel {
private static final int notificationId = 182144338; //Random number, fixed id to make sure we don't produce more than one notification
private String deviceId;
private String player;
private NotificationManager nManager;
private NotificationCompat.Builder nBuilder;
private RemoteViews remoteView;
public NotificationPanel(Context context, Device device, String player) {
this.deviceId = device.getDeviceId();
this.player = player;
//FIXME: When the mpris plugin gets destroyed and recreated, we should add this listener again
final MprisPlugin mpris = (MprisPlugin)device.getPlugin("plugin_mpris");
if (mpris != null) {
mpris.setPlayerStatusUpdatedHandler("notification", new Handler() {
@Override
public void handleMessage(Message msg) {
String song = mpris.getCurrentSong();
boolean isPlaying = mpris.isPlaying();
updateStatus(song, isPlaying);
}
});
}
Intent launch = new Intent(context, MprisActivity.class);
launch.putExtra("deviceId", deviceId);
launch.putExtra("player", player);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(MprisActivity.class);
stackBuilder.addNextIntent(launch);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
remoteView = new RemoteViews(context.getPackageName(), R.layout.mpris_notification);
nBuilder = new NotificationCompat.Builder(context)
.setContentTitle("KDE Connect")
.setLocalOnly(true)
.setSmallIcon(android.R.drawable.ic_media_play)
.setContentIntent(resultPendingIntent)
.setOngoing(true);
String deviceName = device.getName();
String playerOnDevice = context.getString(R.string.mpris_player_on_device, player, deviceName);
remoteView.setTextViewText(R.id.notification_player, playerOnDevice);
Intent playpause = new Intent(context, NotificationReturnSlot.class);
playpause.putExtra("action", "play");
playpause.putExtra("deviceId", deviceId);
playpause.putExtra("player", player);
PendingIntent btn1 = PendingIntent.getBroadcast(context, NotificationsHelper.getUniqueId(), playpause, 0);
remoteView.setOnClickPendingIntent(R.id.notification_play_pause, btn1);
Intent next = new Intent(context, NotificationReturnSlot.class);
next.putExtra("action", "next");
next.putExtra("deviceId", deviceId);
next.putExtra("player", player);
PendingIntent btn2 = PendingIntent.getBroadcast(context, NotificationsHelper.getUniqueId(), next, 0);
remoteView.setOnClickPendingIntent(R.id.notification_next, btn2);
Intent prev = new Intent(context, NotificationReturnSlot.class);
prev.putExtra("action", "prev");
prev.putExtra("deviceId", deviceId);
prev.putExtra("player", player);
PendingIntent btn3 = PendingIntent.getBroadcast(context, NotificationsHelper.getUniqueId(), prev, 0);
remoteView.setOnClickPendingIntent(R.id.notification_prev, btn3);
nBuilder.setContent(remoteView);
nManager.notify(notificationId, nBuilder.build());
}
protected void updateStatus(String songName, boolean isPlaying) {
if (remoteView == null) return;
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(notificationId, nBuilder.build());
}
public void dismiss() {
nManager.cancel(notificationId);
remoteView = null;
}
public String getPlayer() {
return player;
}
public String getDeviceId() {
return deviceId;
}
}
\ No newline at end of file
/*
* Copyright 2014 Da-Jin Chu <dajinchu@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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");
final String player = intent.getStringExtra("player");
//Log.e("onReceive",""+deviceId+player);
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.setPlayer(player);
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.setPlayer(player);
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.setPlayer(player);
mpris.sendAction("Previous");
}
});
}
}
}
......@@ -105,7 +105,6 @@ public class MainActivity extends ActionBarActivity {
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment