forked from len0rd/rockbox
Move android notification display format logic to java code (no functional change, this is used by FS #11902).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29132 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
a448d8bac7
commit
ef980355c8
2 changed files with 19 additions and 27 deletions
|
@ -5,6 +5,7 @@ import java.lang.reflect.Method;
|
||||||
|
|
||||||
import org.rockbox.R;
|
import org.rockbox.R;
|
||||||
import org.rockbox.RockboxActivity;
|
import org.rockbox.RockboxActivity;
|
||||||
|
import org.rockbox.RockboxWidgetProvider;
|
||||||
|
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
|
@ -82,12 +83,15 @@ public class RunForegroundManager
|
||||||
api.stopForeground();
|
api.stopForeground();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateNotification(String title, String content, String ticker)
|
public void updateNotification(String title, String artist, String album)
|
||||||
{
|
{
|
||||||
RemoteViews views = mNotification.contentView;
|
RemoteViews views = mNotification.contentView;
|
||||||
views.setTextViewText(R.id.title, title);
|
views.setTextViewText(R.id.title, title);
|
||||||
views.setTextViewText(R.id.content, content);
|
views.setTextViewText(R.id.content, artist+"\n"+album);
|
||||||
mNotification.tickerText = ticker;
|
if (artist.equals(""))
|
||||||
|
mNotification.tickerText = title;
|
||||||
|
else
|
||||||
|
mNotification.tickerText = title+" - "+artist;
|
||||||
mNM.notify(R.string.notification, mNotification);
|
mNM.notify(R.string.notification, mNotification);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ extern jobject RockboxService_instance;
|
||||||
|
|
||||||
static jmethodID updateNotification;
|
static jmethodID updateNotification;
|
||||||
static jobject NotificationManager_instance;
|
static jobject NotificationManager_instance;
|
||||||
static jstring headline, content, ticker;
|
static jstring title, artist, album;
|
||||||
|
|
||||||
#define NZV(a) (a && a[0])
|
#define NZV(a) (a && a[0])
|
||||||
|
|
||||||
|
@ -45,37 +45,24 @@ static void track_changed_callback(void *param)
|
||||||
if (id3)
|
if (id3)
|
||||||
{
|
{
|
||||||
/* passing NULL to DeleteLocalRef() is OK */
|
/* passing NULL to DeleteLocalRef() is OK */
|
||||||
e->DeleteLocalRef(env_ptr, headline);
|
e->DeleteLocalRef(env_ptr, title);
|
||||||
e->DeleteLocalRef(env_ptr, content);
|
e->DeleteLocalRef(env_ptr, artist);
|
||||||
e->DeleteLocalRef(env_ptr, ticker);
|
e->DeleteLocalRef(env_ptr, album);
|
||||||
|
|
||||||
char buf[200];
|
char buf[200];
|
||||||
const char * title = id3->title;
|
const char * ptitle = id3->title;
|
||||||
if (!title)
|
if (!ptitle)
|
||||||
{ /* pass the filename as title if id3 info isn't available */
|
{ /* pass the filename as title if id3 info isn't available */
|
||||||
title =
|
ptitle =
|
||||||
strip_extension(buf, sizeof(buf), strrchr(id3->path,'/') + 1);
|
strip_extension(buf, sizeof(buf), strrchr(id3->path,'/') + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* do text for the notification area in the scrolled-down statusbar */
|
title = e->NewStringUTF(env_ptr, ptitle);
|
||||||
headline = e->NewStringUTF(env_ptr, title);
|
artist = e->NewStringUTF(env_ptr, id3->artist ?: "");
|
||||||
|
album = e->NewStringUTF(env_ptr, id3->album ?: "");
|
||||||
|
|
||||||
/* add a \n so that android does split into two lines */
|
|
||||||
snprintf(buf, sizeof(buf), "%s\n%s", id3->artist ?: "", id3->album ?: "");
|
|
||||||
content = e->NewStringUTF(env_ptr, buf);
|
|
||||||
|
|
||||||
/* now do the text for the notification in the statusbar itself */
|
|
||||||
if (NZV(id3->artist))
|
|
||||||
{ /* title - artist */
|
|
||||||
snprintf(buf, sizeof(buf), "%s - %s", title, id3->artist);
|
|
||||||
ticker = e->NewStringUTF(env_ptr, buf);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ /* title */
|
|
||||||
ticker = e->NewStringUTF(env_ptr, title);
|
|
||||||
}
|
|
||||||
e->CallVoidMethod(env_ptr, NotificationManager_instance,
|
e->CallVoidMethod(env_ptr, NotificationManager_instance,
|
||||||
updateNotification, headline, content, ticker);
|
updateNotification, title, artist, album);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,5 +79,6 @@ void notification_init(void)
|
||||||
"(Ljava/lang/String;"
|
"(Ljava/lang/String;"
|
||||||
"Ljava/lang/String;"
|
"Ljava/lang/String;"
|
||||||
"Ljava/lang/String;)V");
|
"Ljava/lang/String;)V");
|
||||||
|
|
||||||
add_event(PLAYBACK_EVENT_TRACK_CHANGE, false, track_changed_callback);
|
add_event(PLAYBACK_EVENT_TRACK_CHANGE, false, track_changed_callback);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue