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

Commit 7af771a5 authored by Mady Mellor's avatar Mady Mellor
Browse files

Update BubbleMetadata#setDesiredHeight to be in DPs

Also adds a method to set via res id as well.

Fixes: 127713900
Test: atest NotificationTest; manual - in test app set DP value
Change-Id: Ibc33fff6ca2115d703b0710ba512d98f89135cb2
parent c9a92abc
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -5481,6 +5481,7 @@ package android.app {
    method public boolean getAutoExpandBubble();
    method @Nullable public android.app.PendingIntent getDeleteIntent();
    method public int getDesiredHeight();
    method @DimenRes public int getDesiredHeightResId();
    method @NonNull public android.graphics.drawable.Icon getIcon();
    method @NonNull public android.app.PendingIntent getIntent();
    method public boolean getSuppressInitialNotification();
@@ -5495,6 +5496,7 @@ package android.app {
    method @NonNull public android.app.Notification.BubbleMetadata.Builder setAutoExpandBubble(boolean);
    method @NonNull public android.app.Notification.BubbleMetadata.Builder setDeleteIntent(@Nullable android.app.PendingIntent);
    method @NonNull public android.app.Notification.BubbleMetadata.Builder setDesiredHeight(int);
    method @NonNull public android.app.Notification.BubbleMetadata.Builder setDesiredHeightResId(@DimenRes int);
    method @NonNull public android.app.Notification.BubbleMetadata.Builder setIcon(@NonNull android.graphics.drawable.Icon);
    method @NonNull public android.app.Notification.BubbleMetadata.Builder setIntent(@NonNull android.app.PendingIntent);
    method @NonNull public android.app.Notification.BubbleMetadata.Builder setSuppressInitialNotification(boolean);
+41 −4
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.app;
import static com.android.internal.util.ContrastColorUtil.satisfiesTextContrast;

import android.annotation.ColorInt;
import android.annotation.DimenRes;
import android.annotation.DrawableRes;
import android.annotation.IdRes;
import android.annotation.IntDef;
@@ -8519,6 +8520,7 @@ public class Notification implements Parcelable
        private PendingIntent mDeleteIntent;
        private Icon mIcon;
        private int mDesiredHeight;
        @DimenRes private int mDesiredHeightResId;
        private int mFlags;

        /**
@@ -8545,10 +8547,11 @@ public class Notification implements Parcelable
        private static final int FLAG_SUPPRESS_INITIAL_NOTIFICATION = 0x00000002;

        private BubbleMetadata(PendingIntent expandIntent, PendingIntent deleteIntent,
                Icon icon, int height) {
                Icon icon, int height, @DimenRes int heightResId) {
            mPendingIntent = expandIntent;
            mIcon = icon;
            mDesiredHeight = height;
            mDesiredHeightResId = heightResId;
            mDeleteIntent = deleteIntent;
        }

@@ -8560,6 +8563,7 @@ public class Notification implements Parcelable
            if (in.readInt() != 0) {
                mDeleteIntent = PendingIntent.CREATOR.createFromParcel(in);
            }
            mDesiredHeightResId = in.readInt();
        }

        /**
@@ -8598,13 +8602,22 @@ public class Notification implements Parcelable
        }

        /**
         * @return the ideal height for the floating window that app content defined by
         * @return the ideal height, in DPs, for the floating window that app content defined by
         * {@link #getIntent()} for this bubble.
         */
        public int getDesiredHeight() {
            return mDesiredHeight;
        }

        /**
         * @return the resId of ideal height for the floating window that app content defined by
         * {@link #getIntent()} for this bubble.
         */
        @DimenRes
        public int getDesiredHeightResId() {
            return mDesiredHeightResId;
        }

        /**
         * @return whether this bubble should auto expand when it is posted.
         *
@@ -8652,6 +8665,7 @@ public class Notification implements Parcelable
            if (mDeleteIntent != null) {
                mDeleteIntent.writeToParcel(out, 0);
            }
            out.writeInt(mDesiredHeightResId);
        }

        private void setFlags(int flags) {
@@ -8666,6 +8680,7 @@ public class Notification implements Parcelable
            private PendingIntent mPendingIntent;
            private Icon mIcon;
            private int mDesiredHeight;
            @DimenRes private int mDesiredHeightResId;
            private int mFlags;
            private PendingIntent mDeleteIntent;

@@ -8718,13 +8733,35 @@ public class Notification implements Parcelable
            }

            /**
             * Sets the desired height for the app content defined by
             * Sets the desired height in DPs for the app content defined by
             * {@link #setIntent(PendingIntent)}, this height may not be respected if there is not
             * enough space on the screen or if the provided height is too small to be useful.
             * <p>
             * If {@link #setDesiredHeightResId(int)} was previously called on this builder, the
             * previous value set will be cleared after calling this method, and this value will
             * be used instead.
             */
            @NonNull
            public BubbleMetadata.Builder setDesiredHeight(int height) {
                mDesiredHeight = Math.max(height, 0);
                mDesiredHeightResId = 0;
                return this;
            }


            /**
             * Sets the desired height via resId for the app content defined by
             * {@link #setIntent(PendingIntent)}, this height may not be respected if there is not
             * enough space on the screen or if the provided height is too small to be useful.
             * <p>
             * If {@link #setDesiredHeight(int)} was previously called on this builder, the
             * previous value set will be cleared after calling this method, and this value will
             * be used instead.
             */
            @NonNull
            public BubbleMetadata.Builder setDesiredHeightResId(@DimenRes int heightResId) {
                mDesiredHeightResId = heightResId;
                mDesiredHeight = 0;
                return this;
            }

@@ -8786,7 +8823,7 @@ public class Notification implements Parcelable
                    throw new IllegalStateException("Must supply an icon for the bubble");
                }
                BubbleMetadata data = new BubbleMetadata(mPendingIntent, mDeleteIntent,
                        mIcon, mDesiredHeight);
                        mIcon, mDesiredHeight, mDesiredHeightResId);
                data.setFlags(mFlags);
                return data;
            }
+35 −7
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.ShapeDrawable;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserHandle;
import android.provider.Settings;
import android.service.notification.StatusBarNotification;
import android.util.AttributeSet;
@@ -455,30 +456,38 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList
    void updateHeight() {
        if (usingActivityView()) {
            Notification.BubbleMetadata data = mEntry.getBubbleMetadata();
            int desiredHeight;
            float desiredHeight;
            if (data == null) {
                // This is a contentIntent based bubble, lets allow it to be the max height
                // as it was forced into this mode and not prepared to be small
                desiredHeight = mStackView.getMaxExpandedHeight();
            } else {
                desiredHeight = data.getDesiredHeight() > 0
                        ? data.getDesiredHeight()
                        : mMinHeight;
                boolean useRes = data.getDesiredHeightResId() != 0;
                float desiredPx;
                if (useRes) {
                    desiredPx = getDimenForPackageUser(data.getDesiredHeightResId(),
                            mEntry.notification.getPackageName(),
                            mEntry.notification.getUser().getIdentifier());
                } else {
                    desiredPx = data.getDesiredHeight()
                            * getContext().getResources().getDisplayMetrics().density;
                }
                desiredHeight = desiredPx > 0 ? desiredPx : mMinHeight;
            }
            int chromeHeight = mPermissionView.getVisibility() != View.VISIBLE
                    ? mHeaderHeight
                    : mPermissionHeight;
            int max = mStackView.getMaxExpandedHeight() - chromeHeight - mPointerView.getHeight()
                    - mPointerMargin;
            int height = Math.min(desiredHeight, max);
            float height = Math.min(desiredHeight, max);
            height = Math.max(height, mMinHeight);
            LayoutParams lp = (LayoutParams) mActivityView.getLayoutParams();
            mNeedsNewHeight =  lp.height != height;
            if (!mKeyboardVisible) {
                // If the keyboard is visible... don't adjust the height because that will cause
                // a configuration change and the keyboard will be lost.
                lp.height = height;
                mBubbleHeight = height;
                lp.height = (int) height;
                mBubbleHeight = (int) height;
                mActivityView.setLayoutParams(lp);
                mNeedsNewHeight = false;
            }
@@ -710,4 +719,23 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList
                mStackView.getNormalizedXPosition(),
                mStackView.getNormalizedYPosition());
    }

    private int getDimenForPackageUser(int resId, String pkg, int userId) {
        Resources r;
        if (pkg != null) {
            try {
                if (userId == UserHandle.USER_ALL) {
                    userId = UserHandle.USER_SYSTEM;
                }
                r = mPm.getResourcesForApplicationAsUser(pkg, userId);
                return r.getDimensionPixelSize(resId);
            } catch (PackageManager.NameNotFoundException ex) {
                // Uninstalled, don't care
            } catch (Resources.NotFoundException e) {
                // Invalid res id, return 0 and user our default
                Log.e(TAG, "Couldn't find desired height res id", e);
            }
        }
        return 0;
    }
}