You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
implementing MediaSession using MPRIS
NotificationManager will now ignore MediaStyle notifications
This commit is contained in:
@@ -54,6 +54,7 @@ public class Notification implements Parcelable {
|
||||
PendingIntent intent;
|
||||
String iconPath;
|
||||
boolean ongoing;
|
||||
Style style;
|
||||
|
||||
public String toString() {
|
||||
return "Notification [" + title + ", " + text + ", " + actions + "]";
|
||||
@@ -151,6 +152,7 @@ public class Notification implements Parcelable {
|
||||
}
|
||||
|
||||
public Builder setStyle(Style style) {
|
||||
notification.style = style;
|
||||
if (style instanceof MediaStyle) {
|
||||
notification.ongoing = true;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package android.app;
|
||||
|
||||
import android.app.Notification.MediaStyle;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -10,6 +11,10 @@ public class NotificationManager {
|
||||
public void cancelAll() {}
|
||||
|
||||
public void notify(String tag, int id, Notification notification) {
|
||||
if (notification.style instanceof MediaStyle) {
|
||||
return; // MPRIS is handled by MediaSession implementation
|
||||
}
|
||||
|
||||
System.out.println("notify(" + tag + ", " + id + ", " + notification + ") called");
|
||||
long builder = nativeInitBuilder();
|
||||
for (Notification.Action action : notification.actions) {
|
||||
|
||||
@@ -6,24 +6,39 @@ import android.os.Bundle;
|
||||
|
||||
public class MediaDescription {
|
||||
|
||||
public Uri iconUri;
|
||||
public CharSequence title;
|
||||
public CharSequence subtitle;
|
||||
|
||||
public static class Builder {
|
||||
|
||||
MediaDescription description = new MediaDescription();
|
||||
|
||||
public Builder setMediaId(String mediaId) {return this;}
|
||||
|
||||
public Builder setTitle(CharSequence title) {return this;}
|
||||
public Builder setTitle(CharSequence title) {
|
||||
description.title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setSubtitle(CharSequence subtitle) {return this;}
|
||||
public Builder setSubtitle(CharSequence subtitle) {
|
||||
description.subtitle = subtitle;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setDescription(CharSequence description) {return this;}
|
||||
|
||||
public Builder setIconBitmap(Bitmap iconBitmap) {return this;}
|
||||
|
||||
public Builder setIconUri(Uri iconUri) {return this;}
|
||||
public Builder setIconUri(Uri iconUri) {
|
||||
description.iconUri = iconUri;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setExtras(Bundle extras) {return this;}
|
||||
|
||||
public MediaDescription build() {
|
||||
return new MediaDescription();
|
||||
return description;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,12 +10,20 @@ import android.os.Handler;
|
||||
|
||||
public class MediaSession {
|
||||
|
||||
private List<QueueItem> queue;
|
||||
|
||||
public static final class Token {}
|
||||
|
||||
public static abstract class Callback {}
|
||||
|
||||
public static class QueueItem {
|
||||
public QueueItem(MediaDescription description, long id) {}
|
||||
long id;
|
||||
MediaDescription description;
|
||||
|
||||
public QueueItem(MediaDescription description, long id) {
|
||||
this.description = description;
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
|
||||
public MediaSession(Context context, String tag) {}
|
||||
@@ -26,19 +34,41 @@ public class MediaSession {
|
||||
|
||||
public void setFlags(int flags) {}
|
||||
|
||||
public void setCallback(Callback callback, Handler handler) {}
|
||||
public void setCallback(Callback callback, Handler handler) {
|
||||
nativeSetCallback(callback);
|
||||
}
|
||||
|
||||
public void setCallback(Callback callback) {}
|
||||
public void setCallback(Callback callback) {
|
||||
nativeSetCallback(callback);
|
||||
}
|
||||
|
||||
public void setMediaButtonReceiver(PendingIntent pendingIntent) {}
|
||||
|
||||
public void setActive(boolean active) {}
|
||||
|
||||
public void setPlaybackState(PlaybackState state) {}
|
||||
public void setPlaybackState(PlaybackState state) {
|
||||
String title = null;
|
||||
String subTitle = null;
|
||||
String artUrl = null;
|
||||
if (queue != null) for (QueueItem item : queue) {
|
||||
if (item.id == state.activeQueueItemId) {
|
||||
title = item.description.title.toString();
|
||||
subTitle = item.description.subtitle.toString();
|
||||
artUrl = item.description.iconUri.toString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
nativeSetState(state.state, state.actions, state.position, state.updateTime, title, subTitle, artUrl);
|
||||
}
|
||||
|
||||
public void setMetadata(MediaMetadata metadata) {}
|
||||
|
||||
public void setQueue(List<QueueItem> queue) {}
|
||||
public void setQueue(List<QueueItem> queue) {
|
||||
this.queue = queue;
|
||||
}
|
||||
|
||||
public void release() {}
|
||||
|
||||
protected native void nativeSetState(int state, long actions, long position, long updateTime, String title, String subTitle, String artUrl);
|
||||
protected native void nativeSetCallback(Callback callback);
|
||||
}
|
||||
|
||||
@@ -2,20 +2,49 @@ package android.media.session;
|
||||
|
||||
public class PlaybackState {
|
||||
|
||||
public class Builder {
|
||||
public int state;
|
||||
public long position;
|
||||
public float playbackSpeed;
|
||||
public long updateTime;
|
||||
public long actions;
|
||||
public long activeQueueItemId;
|
||||
|
||||
public Builder setState(int state, long position, float playbackSpeed, long updateTime) {return this;}
|
||||
public static class Builder {
|
||||
|
||||
PlaybackState state;
|
||||
|
||||
public Builder() {
|
||||
state = new PlaybackState();
|
||||
}
|
||||
|
||||
public Builder(PlaybackState from) {
|
||||
state = from;
|
||||
}
|
||||
|
||||
public Builder setState(int state, long position, float playbackSpeed, long updateTime) {
|
||||
this.state.state = state;
|
||||
this.state.position = position;
|
||||
this.state.playbackSpeed = playbackSpeed;
|
||||
this.state.updateTime = updateTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setBufferedPosition(long bufferedPosition) {return this;}
|
||||
|
||||
public Builder setActions(long actions) {return this;}
|
||||
public Builder setActions(long actions) {
|
||||
state.actions = actions;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setErrorMessage(CharSequence errorMessage) {return this;}
|
||||
|
||||
public Builder setActiveQueueItemId(long activeQueueItemId) {return this;}
|
||||
public Builder setActiveQueueItemId(long activeQueueItemId) {
|
||||
state.activeQueueItemId = activeQueueItemId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PlaybackState build() {
|
||||
return new PlaybackState();
|
||||
return state;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user