Merge "App title in PiP notification" into rvc-dev am: 29f0eb33f0
Change-Id: Ibb7bcfab03c44b019e661dae363f2842dc7fa1da
This commit is contained in:
@@ -708,7 +708,7 @@ public class PipManager implements BasePipManager, PipTaskOrganizer.PipTransitio
|
|||||||
mActiveMediaSessionListener, null);
|
mActiveMediaSessionListener, null);
|
||||||
updateMediaController(mMediaSessionManager.getActiveSessions(null));
|
updateMediaController(mMediaSessionManager.getActiveSessions(null));
|
||||||
for (int i = mListeners.size() - 1; i >= 0; i--) {
|
for (int i = mListeners.size() - 1; i >= 0; i--) {
|
||||||
mListeners.get(i).onPipEntered();
|
mListeners.get(i).onPipEntered(packageName);
|
||||||
}
|
}
|
||||||
updatePipVisibility(true);
|
updatePipVisibility(true);
|
||||||
}
|
}
|
||||||
@@ -758,7 +758,7 @@ public class PipManager implements BasePipManager, PipTaskOrganizer.PipTransitio
|
|||||||
* because there's no guarantee for the PIP manager be return relavent information
|
* because there's no guarantee for the PIP manager be return relavent information
|
||||||
* correctly. (e.g. {@link isPipShown}).
|
* correctly. (e.g. {@link isPipShown}).
|
||||||
*/
|
*/
|
||||||
void onPipEntered();
|
void onPipEntered(String packageName);
|
||||||
/** Invoked when a PIPed activity is closed. */
|
/** Invoked when a PIPed activity is closed. */
|
||||||
void onPipActivityClosed();
|
void onPipActivityClosed();
|
||||||
/** Invoked when the PIP menu gets shown. */
|
/** Invoked when the PIP menu gets shown. */
|
||||||
|
|||||||
@@ -137,8 +137,8 @@ public class PipMenuActivity extends Activity implements PipManager.Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPipEntered() {
|
public void onPipEntered(String packageName) {
|
||||||
if (DEBUG) Log.d(TAG, "onPipEntered()");
|
if (DEBUG) Log.d(TAG, "onPipEntered(), packageName=" + packageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ import android.content.BroadcastReceiver;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
|
import android.content.pm.ApplicationInfo;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.ParceledListSlice;
|
import android.content.pm.ParceledListSlice;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
@@ -50,6 +52,8 @@ public class PipNotification {
|
|||||||
private static final String ACTION_MENU = "PipNotification.menu";
|
private static final String ACTION_MENU = "PipNotification.menu";
|
||||||
private static final String ACTION_CLOSE = "PipNotification.close";
|
private static final String ACTION_CLOSE = "PipNotification.close";
|
||||||
|
|
||||||
|
private final PackageManager mPackageManager;
|
||||||
|
|
||||||
private final PipManager mPipManager;
|
private final PipManager mPipManager;
|
||||||
|
|
||||||
private final NotificationManager mNotificationManager;
|
private final NotificationManager mNotificationManager;
|
||||||
@@ -59,13 +63,16 @@ public class PipNotification {
|
|||||||
private String mDefaultTitle;
|
private String mDefaultTitle;
|
||||||
private int mDefaultIconResId;
|
private int mDefaultIconResId;
|
||||||
|
|
||||||
|
/** Package name for the application that owns PiP window. */
|
||||||
|
private String mPackageName;
|
||||||
private boolean mNotified;
|
private boolean mNotified;
|
||||||
private String mTitle;
|
private String mMediaTitle;
|
||||||
private Bitmap mArt;
|
private Bitmap mArt;
|
||||||
|
|
||||||
private PipManager.Listener mPipListener = new PipManager.Listener() {
|
private PipManager.Listener mPipListener = new PipManager.Listener() {
|
||||||
@Override
|
@Override
|
||||||
public void onPipEntered() {
|
public void onPipEntered(String packageName) {
|
||||||
|
mPackageName = packageName;
|
||||||
updateMediaControllerMetadata();
|
updateMediaControllerMetadata();
|
||||||
notifyPipNotification();
|
notifyPipNotification();
|
||||||
}
|
}
|
||||||
@@ -73,6 +80,7 @@ public class PipNotification {
|
|||||||
@Override
|
@Override
|
||||||
public void onPipActivityClosed() {
|
public void onPipActivityClosed() {
|
||||||
dismissPipNotification();
|
dismissPipNotification();
|
||||||
|
mPackageName = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -88,6 +96,7 @@ public class PipNotification {
|
|||||||
@Override
|
@Override
|
||||||
public void onMoveToFullscreen() {
|
public void onMoveToFullscreen() {
|
||||||
dismissPipNotification();
|
dismissPipNotification();
|
||||||
|
mPackageName = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -146,6 +155,8 @@ public class PipNotification {
|
|||||||
|
|
||||||
public PipNotification(Context context, BroadcastDispatcher broadcastDispatcher,
|
public PipNotification(Context context, BroadcastDispatcher broadcastDispatcher,
|
||||||
PipManager pipManager) {
|
PipManager pipManager) {
|
||||||
|
mPackageManager = context.getPackageManager();
|
||||||
|
|
||||||
mNotificationManager = (NotificationManager) context.getSystemService(
|
mNotificationManager = (NotificationManager) context.getSystemService(
|
||||||
Context.NOTIFICATION_SERVICE);
|
Context.NOTIFICATION_SERVICE);
|
||||||
|
|
||||||
@@ -188,7 +199,7 @@ public class PipNotification {
|
|||||||
.setShowWhen(true)
|
.setShowWhen(true)
|
||||||
.setWhen(System.currentTimeMillis())
|
.setWhen(System.currentTimeMillis())
|
||||||
.setSmallIcon(mDefaultIconResId)
|
.setSmallIcon(mDefaultIconResId)
|
||||||
.setContentTitle(!TextUtils.isEmpty(mTitle) ? mTitle : mDefaultTitle);
|
.setContentTitle(getNotificationTitle());
|
||||||
if (mArt != null) {
|
if (mArt != null) {
|
||||||
mNotificationBuilder.setStyle(new Notification.BigPictureStyle()
|
mNotificationBuilder.setStyle(new Notification.BigPictureStyle()
|
||||||
.bigPicture(mArt));
|
.bigPicture(mArt));
|
||||||
@@ -220,14 +231,36 @@ public class PipNotification {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!TextUtils.equals(title, mTitle) || art != mArt) {
|
if (!TextUtils.equals(title, mMediaTitle) || art != mArt) {
|
||||||
mTitle = title;
|
mMediaTitle = title;
|
||||||
mArt = art;
|
mArt = art;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getNotificationTitle() {
|
||||||
|
if (!TextUtils.isEmpty(mMediaTitle)) {
|
||||||
|
return mMediaTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String applicationTitle = getApplicationLabel(mPackageName);
|
||||||
|
if (!TextUtils.isEmpty(applicationTitle)) {
|
||||||
|
return applicationTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
return mDefaultTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getApplicationLabel(String packageName) {
|
||||||
|
try {
|
||||||
|
final ApplicationInfo appInfo = mPackageManager.getApplicationInfo(packageName, 0);
|
||||||
|
return mPackageManager.getApplicationLabel(appInfo).toString();
|
||||||
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static PendingIntent createPendingIntent(Context context, String action) {
|
private static PendingIntent createPendingIntent(Context context, String action) {
|
||||||
return PendingIntent.getBroadcast(context, 0,
|
return PendingIntent.getBroadcast(context, 0,
|
||||||
new Intent(action), PendingIntent.FLAG_CANCEL_CURRENT);
|
new Intent(action), PendingIntent.FLAG_CANCEL_CURRENT);
|
||||||
|
|||||||
Reference in New Issue
Block a user