[Android] Notification for popup

Geoffrey Métais git at videolan.org
Fri Apr 1 12:04:08 CEST 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Mar 31 17:58:13 2016 +0200| [58c4347df8f25769f07bae852380849d6ff26518] | committer: Geoffrey Métais

Notification for popup

> https://code.videolan.org/videolan/vlc-android/commit/58c4347df8f25769f07bae852380849d6ff26518
---

 vlc-android/res/values/strings.xml                 |  2 +
 .../org/videolan/vlc/gui/video/PopupManager.java   | 43 +++++++++++++++++++++-
 2 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index c89a73a..2db0294 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -615,6 +615,8 @@
     <string name="encryption_warning">Warning, encryption is not available for this Android version, password will be stored in a private space but not encrypted</string>
     <string name="store_password">Remember password</string>
     <string name="add_to_playlist">Add to playlist</string>
+    <string name="popup_playback">Playing in a Pop-Up window</string>
+    <string name="popup_expand">Expand video</string>
 
     <string-array name="chroma_formats" translatable="false">
         <item>RGB 32-bit</item>
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/PopupManager.java b/vlc-android/src/org/videolan/vlc/gui/video/PopupManager.java
index db32551..7ad47b7 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/PopupManager.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/PopupManager.java
@@ -24,11 +24,16 @@
 
 package org.videolan.vlc.gui.video;
 
+import android.app.Notification;
+import android.app.PendingIntent;
 import android.content.Context;
+import android.content.Intent;
 import android.graphics.PixelFormat;
 import android.os.Handler;
 import android.os.Looper;
 import android.os.Message;
+import android.support.v4.app.NotificationCompat;
+import android.support.v4.app.NotificationManagerCompat;
 import android.support.v4.view.GestureDetectorCompat;
 import android.util.Log;
 import android.view.GestureDetector;
@@ -38,7 +43,6 @@ import android.view.MotionEvent;
 import android.view.ScaleGestureDetector;
 import android.view.SurfaceView;
 import android.view.View;
-import android.view.ViewGroup;
 import android.view.ViewGroup.LayoutParams;
 import android.view.WindowManager;
 import android.widget.ImageButton;
@@ -79,6 +83,7 @@ public class PopupManager implements PlaybackService.Callback, GestureDetector.O
     }
 
     public void removePopup() {
+        hideNotification();
         if (mRootView == null)
             return;
         mService.setVideoTrackEnabled(false);
@@ -159,6 +164,7 @@ public class PopupManager implements PlaybackService.Callback, GestureDetector.O
         vlcVout.addCallback(mVoutCallBack);
         if (!mService.isPlaying())
             mService.playIndex(mService.getCurrentMediaPosition());
+        showNotification();
     }
 
     @Override
@@ -291,9 +297,11 @@ public class PopupManager implements PlaybackService.Callback, GestureDetector.O
                 break;
             case MediaPlayer.Event.Playing:
                 mPlayPauseButton.setImageResource(R.drawable.ic_pause);
+                showNotification();
                 break;
             case MediaPlayer.Event.Paused:
                 mPlayPauseButton.setImageResource(R.drawable.ic_play);
+                showNotification();
                 break;
         }
     }
@@ -363,4 +371,37 @@ public class PopupManager implements PlaybackService.Callback, GestureDetector.O
         mScaleFactor = 1.0d;
         windowManager.updateViewLayout(mRootView, mRootView.getLayoutParams());
     }
+
+    private void showNotification() {
+        PendingIntent piStop = PendingIntent.getBroadcast(mService, 0,
+                    new Intent(PlaybackService.ACTION_REMOTE_STOP), PendingIntent.FLAG_UPDATE_CURRENT);
+        NotificationCompat.Builder builder = new NotificationCompat.Builder(mService)
+                .setSmallIcon(R.drawable.ic_stat_vlc)
+                .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
+                .setContentTitle(mService.getTitle())
+                .setContentText(mService.getString(R.string.popup_playback))
+                .setAutoCancel(false)
+                .setOngoing(true)
+                .setDeleteIntent(piStop);
+
+        //Switch
+        final Intent notificationIntent = new Intent(PlaybackService.ACTION_REMOTE_SWITCH_VIDEO);
+        PendingIntent piExpand = PendingIntent.getBroadcast(mService, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
+        //PLay Pause
+        PendingIntent piPlay = PendingIntent.getBroadcast(mService, 0, new Intent(PlaybackService.ACTION_REMOTE_PLAYPAUSE), PendingIntent.FLAG_UPDATE_CURRENT);
+
+        if (mService.isPlaying())
+            builder.addAction(R.drawable.ic_pause_w, mService.getString(R.string.pause), piPlay);
+        else
+            builder.addAction(R.drawable.ic_play_w, mService.getString(R.string.play), piPlay);
+        builder.addAction(android.R.drawable.ic_menu_set_as, mService.getString(R.string.popup_expand), piExpand);
+
+        Notification notification = builder.build();
+        mService.startService(new Intent(mService, PlaybackService.class));
+        NotificationManagerCompat.from(mService).notify(42, notification);
+    }
+
+    private void hideNotification() {
+        NotificationManagerCompat.from(mService).cancel(42);
+    }
 }



More information about the Android mailing list