Skip to content

Commit

Permalink
Show icon of package associated with Toast
Browse files Browse the repository at this point in the history
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
  • Loading branch information
0xD34D authored and ciwrl committed Aug 26, 2015
1 parent 8693a02 commit 0d624b0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
14 changes: 14 additions & 0 deletions core/java/android/widget/Toast.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
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;
Expand Down Expand Up @@ -399,6 +401,18 @@ public void handleShow() {
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
Expand Down
19 changes: 15 additions & 4 deletions core/res/res/layout/transient_notification.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>


0 comments on commit 0d624b0

Please sign in to comment.