1
I have the following codes (XML and notification respectively) for a notification plus it this small, I would like to let it expanded to suit everything
XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/onGoingNotification"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:background="@color/white"
android:orientation="horizontal">
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:src="@mipmap/without_photo"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:padding="6dp"/>
<TextView
android:id="@+id/sub_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="@+id/next"
android:layout_alignLeft="@+id/previous"
android:layout_alignRight="@+id/next"
android:layout_alignStart="@+id/previous"
android:layout_centerVertical="true"
android:text="sub text"
android:layout_marginLeft="8dp"
android:textColor="@color/black_transparent" />
<ImageButton
android:id="@+id/next"
android:layout_width="48dp"
android:layout_height="48dp"
android:background="@color/transparent"
android:src="@mipmap/ic_next_black"
android:layout_alignTop="@+id/Play_pause"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="18dp"/>
<ImageButton
android:id="@+id/Play_pause"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:layout_marginRight="36dp"
android:layout_toLeftOf="@+id/next"
android:background="@color/transparent"
android:longClickable="true"
android:src="@mipmap/play"
android:layout_marginBottom="8dp" />
<ImageButton
android:id="@+id/previous"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_alignTop="@+id/Play_pause"
android:layout_marginRight="36dp"
android:layout_toLeftOf="@+id/Play_pause"
android:background="@color/transparent"
android:src="@mipmap/ic_prev_black" />
<TextView
android:id="@+id/title_notification"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/sub_title"
android:layout_alignEnd="@+id/sub_title"
android:layout_alignLeft="@+id/sub_title"
android:layout_alignRight="@+id/sub_title"
android:layout_alignStart="@+id/sub_title"
android:layout_marginBottom="18dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/black" />
</RelativeLayout>
and Notification:
private Notification ongoingNotification() {
Intent intent = new Intent(getApplicationContext(),
PlayerService.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
int icon = R.mipmap.ic_notification;
Notification notification = new Notification(icon, "", 0);
String title = "meuplayer";
String msg = "Tocando. Clique para abrir.";
if (currentStreamBeingPlayed != null) {
msg = currentStreamBeingPlayed.getTitle();
}
PendingIntent previousSongPendingIntent = createPendingIntent(PlayerUI.PREVIOUS_SONG);
PendingIntent pausePendingIntent = createPendingIntent(PlayerService.PAUSE);
PendingIntent nextSongPendingIntent = createPendingIntent(PlayerUI.NEXT_SONG);
PendingIntent playPendingIntent = createPendingIntent(PlayerService.PLAY);
PendingIntent PlayerNotificationPendingIntent = createPendingIntent(PlayerService.PLAYERNOTIFICATION);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext());
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.player_notification);
mBuilder.setContent(contentView);
contentView.setOnClickPendingIntent(R.id.onGoingNotification, PlayerNotificationPendingIntent);
contentView.setTextViewText(R.id.title_notification, title);
contentView.setTextViewText(R.id.sub_title, msg);
if (isPlayingNow) {
contentView.setImageViewResource(R.id.Play_pause, R.mipmap.pause);
contentView.setOnClickPendingIntent(R.id.Play_pause, pausePendingIntent);
} else {
contentView.setImageViewResource(R.id.Play_pause, R.mipmap.play);
contentView.setOnClickPendingIntent(R.id.Play_pause, playPendingIntent);
}
contentView.setOnClickPendingIntent(R.id.next, previousSongPendingIntent);
contentView.setOnClickPendingIntent(R.id.previous, nextSongPendingIntent);
if (currentStreamBeingPlayed != null && currentStreamBeingPlayed.getPicture() != null) {
try {
URL urlPicture = new URL(currentStreamBeingPlayed.getPicture());
Bitmap largeIcon = ImageHandler.decodeURLstreamToBitmap(urlPicture, getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width), getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_height));
contentView.setImageViewBitmap(R.id.imageView, largeIcon);
} catch (MalformedURLException e) {
} catch (Resources.NotFoundException e) {
} catch (IOException e) {
}
}
notification.contentView = contentView;
Intent notificationIntent = new Intent(this, PlayerUI.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.contentIntent = contentIntent;
return notification;
}
private PendingIntent createPendingIntent(String type) {
//Create an Intent for the BroadcastReceiver
Intent intent = new Intent(this, PlayerOnGoingNotificationBroadcastReceiver.class);
intent.setAction(type);
//Create the PendingIntent
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
return pendingIntent;
}