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

Commit f010ed63 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Only show app icon + limit 2 lines toast on targetSdk S+" into sc-dev

parents a7aa1caa c797217b
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -38,8 +38,6 @@
    <!-- The new animations to/from lockscreen and AOD! -->
    <bool name="flag_lockscreen_animations">false</bool>

    <bool name="flag_toast_style">false</bool>

    <bool name="flag_pm_lite">false</bool>

    <bool name="flag_alarm_tile">false</bool>
+0 −4
Original line number Diff line number Diff line
@@ -61,10 +61,6 @@ public class FeatureFlags {
        return mFlagReader.isEnabled(R.bool.flag_conversations);
    }

    public boolean isToastStyleEnabled() {
        return mFlagReader.isEnabled(R.bool.flag_toast_style);
    }

    public boolean isMonetEnabled() {
        return mFlagReader.isEnabled(R.bool.flag_monet);
    }
+45 −22
Original line number Diff line number Diff line
@@ -22,16 +22,19 @@ import android.annotation.Nullable;
import android.app.Application;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.UserHandle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ToastPresenter;

import com.android.internal.R;
import com.android.launcher3.icons.IconFactory;
@@ -52,7 +55,6 @@ public class SystemUIToast implements ToastPlugin.Toast {
    private final String mPackageName;
    private final int mUserId;
    private final LayoutInflater mLayoutInflater;
    private final boolean mToastStyleEnabled;

    final int mDefaultX = 0;
    final int mDefaultHorizontalMargin = 0;
@@ -66,15 +68,14 @@ public class SystemUIToast implements ToastPlugin.Toast {
    @Nullable private final Animator mOutAnimator;

    SystemUIToast(LayoutInflater layoutInflater, Context context, CharSequence text,
            String packageName, int userId, boolean toastStyleEnabled, int orientation) {
            String packageName, int userId, int orientation) {
        this(layoutInflater, context, text, null, packageName, userId,
                toastStyleEnabled, orientation);
                orientation);
    }

    SystemUIToast(LayoutInflater layoutInflater, Context context, CharSequence text,
            ToastPlugin.Toast pluginToast, String packageName, int userId,
            boolean toastStyleEnabled, int orientation) {
        mToastStyleEnabled = toastStyleEnabled;
            int orientation) {
        mLayoutInflater = layoutInflater;
        mContext = context;
        mText = text;
@@ -167,23 +168,45 @@ public class SystemUIToast implements ToastPlugin.Toast {
            return mPluginToast.getView();
        }

        View toastView;
        if (mToastStyleEnabled) {
            toastView = mLayoutInflater.inflate(
        final View toastView = mLayoutInflater.inflate(
                    com.android.systemui.R.layout.text_toast, null);
            ((TextView) toastView.findViewById(com.android.systemui.R.id.text)).setText(mText);
        final TextView textView = toastView.findViewById(com.android.systemui.R.id.text);
        final ImageView iconView = toastView.findViewById(com.android.systemui.R.id.icon);
        textView.setText(mText);

        ApplicationInfo appInfo = null;
        try {
            appInfo = mContext.getPackageManager()
                    .getApplicationInfoAsUser(mPackageName, 0, mUserId);
        } catch (PackageManager.NameNotFoundException e) {
            Log.e(TAG, "Package name not found package=" + mPackageName
                    + " user=" + mUserId);
        }

        if (appInfo != null && appInfo.targetSdkVersion < Build.VERSION_CODES.S) {
            // no two-line limit
            textView.setMaxLines(Integer.MAX_VALUE);

            // no app icon
            toastView.findViewById(com.android.systemui.R.id.icon).setVisibility(View.GONE);
        } else {
            Drawable icon = getBadgedIcon(mContext, mPackageName, mUserId);
            if (icon == null) {
                toastView.findViewById(com.android.systemui.R.id.icon).setVisibility(View.GONE);
                iconView.setVisibility(View.GONE);
            } else {
                ((ImageView) toastView.findViewById(com.android.systemui.R.id.icon))
                        .setImageDrawable(icon);
                iconView.setImageDrawable(icon);
                if (appInfo.labelRes != 0) {
                    try {
                        Resources res = mContext.getPackageManager().getResourcesForApplication(
                                appInfo,
                                new Configuration(mContext.getResources().getConfiguration()));
                        iconView.setContentDescription(res.getString(appInfo.labelRes));
                    } catch (PackageManager.NameNotFoundException e) {
                        Log.d(TAG, "Cannot find application resources for icon label.");
                    }
                }
            }
        } else {
            toastView = ToastPresenter.getTextToastView(mContext, mText);
        }

        return toastView;
    }

@@ -205,18 +228,14 @@ public class SystemUIToast implements ToastPlugin.Toast {
            return mPluginToast.getInAnimation();
        }

        return mToastStyleEnabled
                ? ToastDefaultAnimation.Companion.toastIn(getView())
                : null;
        return ToastDefaultAnimation.Companion.toastIn(getView());
    }

    private Animator createOutAnimator() {
        if (isPluginToast() && mPluginToast.getOutAnimation() != null) {
            return mPluginToast.getOutAnimation();
        }
        return mToastStyleEnabled
                ? ToastDefaultAnimation.Companion.toastOut(getView())
                : null;
        return ToastDefaultAnimation.Companion.toastOut(getView());
    }

    /**
@@ -225,6 +244,10 @@ public class SystemUIToast implements ToastPlugin.Toast {
     */
    public static Drawable getBadgedIcon(@NonNull Context context, String packageName,
            int userId) {
        if (!(context.getApplicationContext() instanceof Application)) {
            return null;
        }

        final ApplicationsState appState =
                ApplicationsState.getInstance((Application) context.getApplicationContext());
        if (!appState.isUserAdded(userId)) {
+3 −8
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ import com.android.systemui.dump.DumpManager;
import com.android.systemui.plugins.PluginListener;
import com.android.systemui.plugins.ToastPlugin;
import com.android.systemui.shared.plugins.PluginManager;
import com.android.systemui.statusbar.FeatureFlags;

import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -43,17 +42,14 @@ public class ToastFactory implements Dumpable {
    // only one ToastPlugin can be connected at a time.
    private ToastPlugin mPlugin;
    private final LayoutInflater mLayoutInflater;
    private final boolean mToastStyleEnabled;

    @Inject
    public ToastFactory(
            LayoutInflater layoutInflater,
            PluginManager pluginManager,
            DumpManager dumpManager,
            FeatureFlags featureFlags) {
            DumpManager dumpManager) {
        mLayoutInflater = layoutInflater;
        dumpManager.registerDumpable("ToastFactory", this);
        mToastStyleEnabled = featureFlags.isToastStyleEnabled();
        pluginManager.addPluginListener(
                new PluginListener<ToastPlugin>() {
                    @Override
@@ -77,10 +73,10 @@ public class ToastFactory implements Dumpable {
            int userId, int orientation) {
        if (isPluginAvailable()) {
            return new SystemUIToast(mLayoutInflater, context, text, mPlugin.createToast(text,
                    packageName, userId), packageName, userId, mToastStyleEnabled, orientation);
                    packageName, userId), packageName, userId, orientation);
        }
        return new SystemUIToast(mLayoutInflater, context, text, packageName, userId,
                mToastStyleEnabled, orientation);
                orientation);
    }

    private boolean isPluginAvailable() {
@@ -91,6 +87,5 @@ public class ToastFactory implements Dumpable {
    public void dump(@NonNull FileDescriptor fd, @NonNull PrintWriter pw, @NonNull String[] args) {
        pw.println("ToastFactory:");
        pw.println("    mAttachedPlugin=" + mPlugin);
        pw.println("    mToastStyleEnabled=" + mToastStyleEnabled);
    }
}
+5 −17
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.systemui.toast;
import static android.content.res.Configuration.ORIENTATION_PORTRAIT;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.annotation.MainThread;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -34,7 +35,8 @@ import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.IAccessibilityManager;
import android.widget.ToastPresenter;

import com.android.internal.annotations.VisibleForTesting;
import androidx.annotation.VisibleForTesting;

import com.android.systemui.SystemUI;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.statusbar.CommandQueue;
@@ -60,11 +62,11 @@ public class ToastUI extends SystemUI implements CommandQueue.Callbacks {
    private final AccessibilityManager mAccessibilityManager;
    private final ToastFactory mToastFactory;
    private final ToastLogger mToastLogger;
    private SystemUIToast mToast;
    @Nullable private ToastPresenter mPresenter;
    @Nullable private ITransientNotificationCallback mCallback;
    private ToastOutAnimatorListener mToastOutAnimatorListener;

    @VisibleForTesting SystemUIToast mToast;
    private int mOrientation = ORIENTATION_PORTRAIT;

    @Inject
@@ -191,7 +193,7 @@ public class ToastUI extends SystemUI implements CommandQueue.Callbacks {
    /**
     * Once the out animation for a toast is finished, start showing the next toast.
     */
    class ToastOutAnimatorListener implements Animator.AnimatorListener {
    class ToastOutAnimatorListener extends AnimatorListenerAdapter {
        final ToastPresenter mPrevPresenter;
        final ITransientNotificationCallback mPrevCallback;
        @Nullable Runnable mShowNextToastRunnable;
@@ -209,10 +211,6 @@ public class ToastUI extends SystemUI implements CommandQueue.Callbacks {
            mShowNextToastRunnable = runnable;
        }

        @Override
        public void onAnimationStart(Animator animation) {
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            mPrevPresenter.hide(mPrevCallback);
@@ -221,15 +219,5 @@ public class ToastUI extends SystemUI implements CommandQueue.Callbacks {
            }
            mToastOutAnimatorListener = null;
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            onAnimationEnd(animation);
        }

        @Override
        public void onAnimationRepeat(Animator animation) {

        }
    }
}
Loading