Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0d624b04 authored by d34d's avatar d34d Committed by Abhisek Devkota
Browse files

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
parent 8693a023
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -20,9 +20,11 @@ import android.annotation.IntDef;
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;
@@ -399,6 +401,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
+15 −4
Original line number Diff line number Diff line
@@ -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>