mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-22 09:58:08 +00:00
Added MPRIS controls from the notifications panel
This commit is contained in:
parent
26b321ee76
commit
816a6f5c79
@ -175,6 +175,9 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<receiver android:name="org.kde.kdeconnect.Plugins.MprisPlugin.NotificationReturnSlot"></receiver>
|
||||||
|
|
||||||
|
|
||||||
<service android:name="org.kde.kdeconnect.Plugins.NotificationsPlugin.NotificationReceiver"
|
<service android:name="org.kde.kdeconnect.Plugins.NotificationsPlugin.NotificationReceiver"
|
||||||
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
|
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
|
40
res/layout/notification_layout.xml
Normal file
40
res/layout/notification_layout.xml
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="64dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/notification_song"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
|
android:text="Song Name"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:paddingLeft="3dp" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/notification_prev"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="10dp"
|
||||||
|
android:src="@android:drawable/ic_media_previous" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/notification_play_pause"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="10dp"
|
||||||
|
android:src="@android:drawable/ic_media_play" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/notification_next"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="10dp"
|
||||||
|
android:src="@android:drawable/ic_media_next" />
|
||||||
|
|
||||||
|
|
||||||
|
</LinearLayout>
|
@ -37,9 +37,9 @@ import android.widget.Spinner;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import org.kde.kdeconnect.Backends.BaseLink;
|
import org.kde.kdeconnect.Backends.BaseLink;
|
||||||
|
import org.kde.kdeconnect.Backends.BaseLinkProvider;
|
||||||
import org.kde.kdeconnect.BackgroundService;
|
import org.kde.kdeconnect.BackgroundService;
|
||||||
import org.kde.kdeconnect.Device;
|
import org.kde.kdeconnect.Device;
|
||||||
import org.kde.kdeconnect.Backends.BaseLinkProvider;
|
|
||||||
import org.kde.kdeconnect.NetworkPackage;
|
import org.kde.kdeconnect.NetworkPackage;
|
||||||
import org.kde.kdeconnect_tp.R;
|
import org.kde.kdeconnect_tp.R;
|
||||||
|
|
||||||
@ -54,6 +54,7 @@ public class MprisActivity extends ActionBarActivity {
|
|||||||
private final Handler positionSeekUpdateHandler = new Handler();
|
private final Handler positionSeekUpdateHandler = new Handler();
|
||||||
private Runnable positionSeekUpdateRunnable;
|
private Runnable positionSeekUpdateRunnable;
|
||||||
private boolean positionSeekUpdateScheduled = false;
|
private boolean positionSeekUpdateScheduled = false;
|
||||||
|
NotificationPanel nPanel;
|
||||||
|
|
||||||
private static String milisToProgress(long milis) {
|
private static String milisToProgress(long milis) {
|
||||||
int length = (int)(milis / 1000); //From milis to seconds
|
int length = (int)(milis / 1000); //From milis to seconds
|
||||||
@ -71,6 +72,7 @@ public class MprisActivity extends ActionBarActivity {
|
|||||||
text.append(seconds);
|
text.append(seconds);
|
||||||
return text.toString();
|
return text.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void connectToPlugin() {
|
protected void connectToPlugin() {
|
||||||
|
|
||||||
final String deviceId = getIntent().getStringExtra("deviceId");
|
final String deviceId = getIntent().getStringExtra("deviceId");
|
||||||
@ -119,7 +121,7 @@ public class MprisActivity extends ActionBarActivity {
|
|||||||
} else {
|
} else {
|
||||||
((ImageButton) findViewById(R.id.play_button)).setImageResource(android.R.drawable.ic_media_play);
|
((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");
|
deviceId = getIntent().getStringExtra("deviceId");
|
||||||
|
|
||||||
|
nPanel = new NotificationPanel(this, deviceId);
|
||||||
|
|
||||||
|
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
String interval_time_str = prefs.getString(getString(R.string.mpris_time_key),
|
String interval_time_str = prefs.getString(getString(R.string.mpris_time_key),
|
||||||
getString(R.string.mpris_time_default));
|
getString(R.string.mpris_time_default));
|
||||||
|
@ -0,0 +1,95 @@
|
|||||||
|
/*
|
||||||
|
* 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.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);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
* 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");
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -105,6 +105,7 @@ public class MainActivity extends ActionBarActivity {
|
|||||||
|
|
||||||
ActionBar actionBar = getSupportActionBar();
|
ActionBar actionBar = getSupportActionBar();
|
||||||
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM);
|
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user