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

Commit fe7ec03e authored by Mady Mellor's avatar Mady Mellor
Browse files

Actually use the height specified on bubble metadata

* Lowers default size based on desires of UX
  -> still allows a larger size for 'contentIntent' based bubbles so that
     things forced into a bubble are still reasonably useable
* Ensures the height for activity view will fit on the screen based on
  the position the bubbles expand to and the space needed for the dismiss
  target

Test: manual / with Bubble app adjusted to have a height slider
Bug: 123961288
Change-Id: I31fc31d78fc51ce261ec8d693b4e18cff867ef0d
parent 49df0095
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -1019,8 +1019,8 @@
    <dimen name="bubble_icon_inset">16dp</dimen>
    <!-- Padding around the view displayed when the bubble is expanded -->
    <dimen name="bubble_expanded_view_padding">8dp</dimen>
    <!-- Default height of the expanded view shown when the bubble is expanded -->
    <dimen name="bubble_expanded_default_height">400dp</dimen>
    <!-- Default (and minimum) height of the expanded view shown when the bubble is expanded -->
    <dimen name="bubble_expanded_default_height">180dp</dimen>
    <!-- Height of the triangle that points to the expanded bubble -->
    <dimen name="bubble_pointer_height">4dp</dimen>
    <!-- Width of the triangle that points to the expanded bubble -->
+1 −1
Original line number Diff line number Diff line
@@ -50,6 +50,6 @@ class Bubble {
    public void setEntry(NotificationEntry entry) {
        key = entry.key;
        iconView.update(entry);
        // TODO: should also update the expanded view here (e.g. height change)
        expandedView.update(entry);
    }
}
+43 −11
Original line number Diff line number Diff line
@@ -89,8 +89,8 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList
    private boolean mActivityViewReady = false;
    private PendingIntent mBubbleIntent;

    private int mBubbleHeight;
    private int mDefaultHeight;
    private int mMinHeight;
    private int mHeaderHeight;

    private NotificationEntry mEntry;
    private PackageManager mPm;
@@ -149,7 +149,7 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList
            int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        mPm = context.getPackageManager();
        mDefaultHeight = getResources().getDimensionPixelSize(
        mMinHeight = getResources().getDimensionPixelSize(
                R.dimen.bubble_expanded_default_height);
        try {
            mNotificationManagerService = INotificationManager.Stub.asInterface(
@@ -194,6 +194,8 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList
        viewWrapper.setLayoutTransition(transition);
        viewWrapper.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);

        mHeaderHeight = getContext().getResources().getDimensionPixelSize(
                R.dimen.bubble_expanded_header_height);
        mHeaderView = findViewById(R.id.header_layout);
        mHeaderTextView = findViewById(R.id.header_text);
        mDeepLinkIcon = findViewById(R.id.deep_link_button);
@@ -273,6 +275,21 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList
        mActivityView.setCallback(mStateCallback);
    }

    /**
     * Updates the entry backing this view. This will not re-populate ActivityView, it will
     * only update the deep-links in the header, the title, and the height of the view.
     */
    public void update(NotificationEntry entry) {
        if (entry.key.equals(mEntry.key)) {
            mEntry = entry;
            updateHeaderView();
            updateHeight();
        } else {
            Log.w(TAG, "Trying to update entry with different key, new entry: "
                    + entry.key + " old entry: " + mEntry.key);
        }
    }

    private void updateHeaderView() {
        mSettingsIcon.setContentDescription(getResources().getString(
                R.string.bubbles_settings_button_description, mAppName));
@@ -315,14 +332,6 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList
                removeView(mNotifRow);
                mNotifRow = null;
            }
            Notification.BubbleMetadata data = mEntry.getBubbleMetadata();
            mBubbleHeight = data != null && data.getDesiredHeight() > 0
                    ? data.getDesiredHeight()
                    : mDefaultHeight;
            // XXX: enforce max / min height
            LayoutParams lp = (LayoutParams) mActivityView.getLayoutParams();
            lp.height = mBubbleHeight;
            mActivityView.setLayoutParams(lp);
            mActivityView.setVisibility(VISIBLE);
        } else {
            // Hide activity view if we had it previously
@@ -343,6 +352,28 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList
        return true;
    }

    void updateHeight() {
        if (usingActivityView()) {
            Notification.BubbleMetadata data = mEntry.getBubbleMetadata();
            int 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;
            }
            int max = mStackView.getMaxExpandedHeight() - mHeaderHeight;
            int height = Math.min(desiredHeight, max);
            height = Math.max(height, mMinHeight);
            LayoutParams lp = (LayoutParams) mActivityView.getLayoutParams();
            lp.height = height;
            mActivityView.setLayoutParams(lp);
        }
    }

    @Override
    public void onClick(View view) {
        if (mEntry == null) {
@@ -407,6 +438,7 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList
        } else if (mNotifRow != null) {
            applyRowState(mNotifRow);
        }
        updateHeight();
    }

    /**
+26 −2
Original line number Diff line number Diff line
@@ -99,6 +99,7 @@ public class BubbleStackView extends FrameLayout {
    private int mExpandedAnimateXDistance;
    private int mExpandedAnimateYDistance;
    private int mStatusBarHeight;
    private int mPipDismissHeight;

    private Bubble mExpandedBubble;
    private boolean mIsExpanded;
@@ -159,6 +160,8 @@ public class BubbleStackView extends FrameLayout {
                res.getDimensionPixelSize(R.dimen.bubble_expanded_animate_y_distance);
        mStatusBarHeight =
                res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
        mPipDismissHeight = mContext.getResources().getDimensionPixelSize(
                R.dimen.pip_dismiss_gradient_height);

        mDisplaySize = new Point();
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
@@ -390,8 +393,7 @@ public class BubbleStackView extends FrameLayout {
     */
    public void updateBubble(NotificationEntry entry, boolean updatePosition) {
        Bubble b = mBubbleData.getBubble(entry.key);
        b.iconView.update(entry);
        // TODO: should also update the expanded view here (e.g. height change)
        mBubbleData.updateBubble(entry.key, entry);

        if (updatePosition && !mIsExpanded) {
            // If alerting it gets promoted to top of the stack.
@@ -652,6 +654,20 @@ public class BubbleStackView extends FrameLayout {
                StatsLog.BUBBLE_UICHANGED__ACTION__STACK_MOVED);
    }

    /**
     * Calculates how large the expanded view of the bubble can be. This takes into account the
     * y position when the bubbles are expanded as well as the bounds of the dismiss target.
     */
    int getMaxExpandedHeight() {
        int expandedY = (int) mExpandedAnimationController.getExpandedY();
        int bubbleContainerHeight = mBubbleContainer.getChildAt(0) != null
                ? mBubbleContainer.getChildAt(0).getHeight()
                : 0;
        // PIP dismiss view uses FLAG_LAYOUT_IN_SCREEN so we need to subtract the bottom inset
        int pipDismissHeight = mPipDismissHeight - getBottomInset();
        return mDisplaySize.y - expandedY - mBubbleSize - pipDismissHeight;
    }

    /**
     * Minimum velocity, in pixels/second, required to get from x to destX while being slowed by a
     * given frictional force.
@@ -688,6 +704,14 @@ public class BubbleStackView extends FrameLayout {
        return 0;
    }

    private int getBottomInset() {
        if (getRootWindowInsets() != null) {
            WindowInsets insets = getRootWindowInsets();
            return insets.getSystemWindowInsetBottom();
        }
        return 0;
    }

    private boolean isIntersecting(View view, float x, float y) {
        mTempLoc = view.getLocationOnScreen();
        mTempRect.set(mTempLoc[0], mTempLoc[1], mTempLoc[0] + view.getWidth(),
+2 −2
Original line number Diff line number Diff line
@@ -203,8 +203,8 @@ public class ExpandedAnimationController
    }

    /** The Y value of the row of expanded bubbles. */
    private float getExpandedY() {
        final WindowInsets insets = mLayout.getRootWindowInsets();
    public float getExpandedY() {
        final WindowInsets insets = mLayout != null ? mLayout.getRootWindowInsets() : null;
        if (insets != null) {
            return mBubblePaddingPx + Math.max(
                    mStatusBarHeight,