summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authord34d <clark@cyngn.com>2015-08-25 19:13:46 -0700
committerSteve Kondik <steve@cyngn.com>2015-10-27 15:12:09 -0700
commitaa19010d9fac5e4bc8a12f94b4007ee3c7502e06 (patch)
tree24e0150835e0d6d9b3e541b64fd11cc995f7f89b
parent956451ac799e7aaa596871ef8a7f96872c1f2da1 (diff)
downloadframeworks_base-aa19010d9fac5e4bc8a12f94b4007ee3c7502e06.zip
frameworks_base-aa19010d9fac5e4bc8a12f94b4007ee3c7502e06.tar.gz
frameworks_base-aa19010d9fac5e4bc8a12f94b4007ee3c7502e06.tar.bz2
Show icon of package associated with Toast
For all those times you have some random app or background service that posts a Toast and you have no idea who's posting it. This adds an icon badge to the top left corner of the Toast to show the app's icon the Toast belongs to. Change-Id: I82bf23664eea134f3b1f89ad5a99f6be73906ba8
-rw-r--r--core/java/android/widget/Toast.java14
-rw-r--r--core/res/res/layout/transient_notification.xml19
2 files changed, 29 insertions, 4 deletions
diff --git a/core/java/android/widget/Toast.java b/core/java/android/widget/Toast.java
index 207f675..4b31af0 100644
--- a/core/java/android/widget/Toast.java
+++ b/core/java/android/widget/Toast.java
@@ -21,9 +21,11 @@ import android.annotation.StringRes;
import android.app.INotificationManager;
import android.app.ITransientNotification;
import android.content.Context;
+import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.PixelFormat;
+import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.RemoteException;
import android.os.ServiceManager;
@@ -400,6 +402,18 @@ public class Toast {
if (context == null) {
context = mView.getContext();
}
+
+ ImageView appIcon = (ImageView) mView.findViewById(android.R.id.icon);
+ if (appIcon != null) {
+ PackageManager pm = context.getPackageManager();
+ Drawable icon = null;
+ try {
+ icon = pm.getApplicationIcon(packageName);
+ } catch (PackageManager.NameNotFoundException e) {
+ // nothing to do
+ }
+ appIcon.setImageDrawable(icon);
+ }
mWM = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
// We can resolve the Gravity here by using the Locale for getting
// the layout direction
diff --git a/core/res/res/layout/transient_notification.xml b/core/res/res/layout/transient_notification.xml
index daa9faf..fb1b430 100644
--- a/core/res/res/layout/transient_notification.xml
+++ b/core/res/res/layout/transient_notification.xml
@@ -18,24 +18,35 @@
*/
-->
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
- android:background="?android:attr/toastFrameBackground">
+ android:clipChildren="false">
<TextView
android:id="@android:id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_weight="1"
android:layout_gravity="center_horizontal"
+ android:layout_marginTop="-16dp"
+ android:layout_marginStart="-16dp"
+ android:layout_toRightOf="@android:id/icon"
+ android:layout_below="@android:id/icon"
android:textAppearance="@style/TextAppearance.Toast"
android:textColor="@color/bright_foreground_dark"
android:shadowColor="#BB000000"
android:shadowRadius="2.75"
+ android:background="?android:attr/toastFrameBackground"
/>
-</LinearLayout>
+ <ImageView
+ android:id="@android:id/icon"
+ android:layout_width="24dp"
+ android:layout_height="24dp"
+ android:layout_alignParentTop="true"
+ android:layout_alignParentStart="true"/>
+
+</RelativeLayout>