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

Commit c9aae16b authored by Ivan Tkachenko's avatar Ivan Tkachenko
Browse files

Fix bubble user education if bubble is on the right (part 2)

When the manage user education is shown on the Phone:
* It's always on the left for LTR languages and on the right for the RTL.

When the manage user education is shown on the Tablet:
* It's pinned to the same side of the screen where the bubble stack is

Note: Screenshots attached in the bug comments

Bug: 302520752
Test: manual
Flag: none
Change-Id: Ib65f3108843ff79df22f1bef2dd484619c76e53a
parent 24aa50c6
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -1298,6 +1298,9 @@ public class BubbleStackView extends FrameLayout
        return shouldShow;
    }

    /**
     * Show manage education if should show and was not showing before.
     */
    private void maybeShowManageEdu() {
        if (!shouldShowManageEdu()) {
            return;
@@ -1306,7 +1309,16 @@ public class BubbleStackView extends FrameLayout
            mManageEduView = new ManageEducationView(mContext, mPositioner);
            addView(mManageEduView);
        }
        mManageEduView.show(mExpandedBubble.getExpandedView());
        showManageEdu();
    }

    /**
     * Show manage education if was not showing before.
     */
    private void showManageEdu() {
        if (mExpandedBubble == null || mExpandedBubble.getExpandedView() == null) return;
        mManageEduView.show(mExpandedBubble.getExpandedView(),
                mStackAnimationController.isStackOnLeftSide());
    }

    @VisibleForTesting
@@ -1386,7 +1398,7 @@ public class BubbleStackView extends FrameLayout
            removeView(mManageEduView);
            mManageEduView = new ManageEducationView(mContext, mPositioner);
            addView(mManageEduView);
            mManageEduView.show(mExpandedBubble.getExpandedView());
            showManageEdu();
        }
    }

+100 −38
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ import android.content.Context
import android.graphics.Color
import android.graphics.Rect
import android.graphics.drawable.ColorDrawable
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@@ -32,10 +33,10 @@ import com.android.wm.shell.animation.Interpolators
 * User education view to highlight the manage button that allows a user to configure the settings
 * for the bubble. Shown only the first time a user expands a bubble.
 */
class ManageEducationView constructor(context: Context, positioner: BubblePositioner)
    : LinearLayout(context) {
class ManageEducationView(context: Context, positioner: BubblePositioner) : LinearLayout(context) {

    private val TAG = if (BubbleDebugConfig.TAG_WITH_CLASS_NAME) "ManageEducationView"
    private val TAG =
        if (BubbleDebugConfig.TAG_WITH_CLASS_NAME) "ManageEducationView"
        else BubbleDebugConfig.TAG_BUBBLES

    private val ANIMATE_DURATION: Long = 200
@@ -62,7 +63,7 @@ class ManageEducationView constructor(context: Context, positioner: BubblePositi

    override fun setLayoutDirection(layoutDirection: Int) {
        super.setLayoutDirection(layoutDirection)
        setDrawableDirection()
        setDrawableDirection(layoutDirection == LAYOUT_DIRECTION_LTR)
    }

    override fun onFinishInflate() {
@@ -71,8 +72,10 @@ class ManageEducationView constructor(context: Context, positioner: BubblePositi
    }

    private fun setButtonColor() {
        val typedArray = mContext.obtainStyledAttributes(intArrayOf(
                com.android.internal.R.attr.colorAccentPrimary))
        val typedArray =
            mContext.obtainStyledAttributes(
                intArrayOf(com.android.internal.R.attr.colorAccentPrimary)
            )
        val buttonColor = typedArray.getColor(0 /* index */, Color.TRANSPARENT)
        typedArray.recycle()

@@ -81,11 +84,11 @@ class ManageEducationView constructor(context: Context, positioner: BubblePositi
        gotItButton.setBackgroundDrawable(ColorDrawable(buttonColor))
    }

    private fun setDrawableDirection() {
    private fun setDrawableDirection(isOnLeft: Boolean) {
        manageView.setBackgroundResource(
            if (resources.configuration.layoutDirection == View.LAYOUT_DIRECTION_RTL)
                R.drawable.bubble_stack_user_education_bg_rtl
            else R.drawable.bubble_stack_user_education_bg)
            if (isOnLeft) R.drawable.bubble_stack_user_education_bg
            else R.drawable.bubble_stack_user_education_bg_rtl
        )
    }

    /**
@@ -93,34 +96,22 @@ class ManageEducationView constructor(context: Context, positioner: BubblePositi
     * bubble stack is expanded for the first time.
     *
     * @param expandedView the expandedView the user education is shown on top of.
     * @param isStackOnLeft the bubble stack position on the screen
     */
    fun show(expandedView: BubbleExpandedView) {
    fun show(expandedView: BubbleExpandedView, isStackOnLeft: Boolean) {
        setButtonColor()
        if (visibility == VISIBLE) return

        bubbleExpandedView = expandedView
        expandedView.taskView?.setObscuredTouchRect(Rect(positioner.screenRect))

        layoutParams.width = if (positioner.isLargeScreen || positioner.isLandscape)
            context.resources.getDimensionPixelSize(R.dimen.bubbles_user_education_width)
        else ViewGroup.LayoutParams.MATCH_PARENT

        alpha = 0f
        visibility = View.VISIBLE
        expandedView.getManageButtonBoundsOnScreen(realManageButtonRect)
        val isRTL = mContext.resources.configuration.layoutDirection == LAYOUT_DIRECTION_RTL
        if (isRTL) {
            val rightPadding = positioner.screenRect.right - realManageButtonRect.right -
                    expandedView.manageButtonMargin
            manageView.setPadding(manageView.paddingLeft, manageView.paddingTop,
                    rightPadding, manageView.paddingBottom)
        } else {
            manageView.setPadding(realManageButtonRect.left - expandedView.manageButtonMargin,
            manageView.paddingTop, manageView.paddingRight, manageView.paddingBottom)
        }
        layoutManageView(realManageButtonRect, expandedView.manageButtonMargin, isStackOnLeft)

        post {
            manageButton
                .setOnClickListener {
            manageButton.setOnClickListener {
                hide()
                expandedView.requireViewById<View>(R.id.manage_button).performClick()
            }
@@ -130,11 +121,6 @@ class ManageEducationView constructor(context: Context, positioner: BubblePositi
            val offsetViewBounds = Rect()
            manageButton.getDrawingRect(offsetViewBounds)
            manageView.offsetDescendantRectToMyCoords(manageButton, offsetViewBounds)
            if (isRTL && (positioner.isLargeScreen || positioner.isLandscape)) {
                translationX = (positioner.screenRect.right - width).toFloat()
            } else {
                translationX = 0f
            }
            translationY = (realManageButtonRect.top - offsetViewBounds.top).toFloat()
            bringToFront()
            animate()
@@ -145,6 +131,79 @@ class ManageEducationView constructor(context: Context, positioner: BubblePositi
        setShouldShow(false)
    }

    /**
     * On tablet the user education is aligned to the left or to right side depending on where the
     * stack is positioned when collapsed. On phone the user education follows the layout direction.
     *
     * @param manageButtonRect the manage button rect on the screen
     * @param manageButtonMargin the manage button margin
     * @param isStackOnLeft the bubble stack position on the screen
     */
    private fun layoutManageView(
        manageButtonRect: Rect,
        manageButtonMargin: Int,
        isStackOnLeft: Boolean
    ) {
        val isLTR = resources.configuration.layoutDirection == LAYOUT_DIRECTION_LTR
        val isPinnedLeft = if (positioner.isLargeScreen) isStackOnLeft else isLTR
        val paddingHorizontal =
            resources.getDimensionPixelSize(R.dimen.bubble_user_education_padding_horizontal)

        // The user education view background image direction
        setDrawableDirection(isPinnedLeft)

        // The user education view layout gravity
        gravity = if (isPinnedLeft) Gravity.LEFT else Gravity.RIGHT

        // The user education view width
        manageView.layoutParams.width =
            when {
                // Left-to-Right direction and the education is on the right side
                isLTR && !isPinnedLeft ->
                    positioner.screenRect.right -
                        (manageButtonRect.left - manageButtonMargin - paddingHorizontal)
                // Right-to-Left direction and the education is on the left side
                !isLTR && isPinnedLeft ->
                    manageButtonRect.right + manageButtonMargin + paddingHorizontal
                // Large screen and the education position matches the layout direction
                positioner.isLargeScreen -> ViewGroup.LayoutParams.WRAP_CONTENT
                // Small screen, landscape orientation
                positioner.isLandscape ->
                    resources.getDimensionPixelSize(R.dimen.bubbles_user_education_width)
                // Otherwise
                else -> ViewGroup.LayoutParams.MATCH_PARENT
            }

        // The user education view margin on the opposite side of where it's pinned
        (manageView.layoutParams as MarginLayoutParams).apply {
            val edgeMargin =
                resources.getDimensionPixelSize(R.dimen.bubble_user_education_margin_horizontal)
            leftMargin = if (isPinnedLeft) 0 else edgeMargin
            rightMargin = if (isPinnedLeft) edgeMargin else 0
        }

        // The user education view padding
        manageView.apply {
            val paddingLeft =
                if (isLTR && isPinnedLeft) {
                    // Offset on the left to align with the manage button
                    manageButtonRect.left - manageButtonMargin
                } else {
                    // Use default padding
                    paddingHorizontal
                }
            val paddingRight =
                if (!isLTR && !isPinnedLeft) {
                    // Offset on the right to align with the manage button
                    positioner.screenRect.right - manageButtonRect.right - manageButtonMargin
                } else {
                    // Use default padding
                    paddingHorizontal
                }
            setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom)
        }
    }

    fun hide() {
        bubbleExpandedView?.taskView?.setObscuredTouchRect(null)
        if (visibility != VISIBLE || isHiding) return
@@ -160,8 +219,11 @@ class ManageEducationView constructor(context: Context, positioner: BubblePositi
    }

    private fun setShouldShow(shouldShow: Boolean) {
        context.getSharedPreferences(context.packageName, Context.MODE_PRIVATE)
                .edit().putBoolean(PREF_MANAGED_EDUCATION, !shouldShow).apply()
        context
            .getSharedPreferences(context.packageName, Context.MODE_PRIVATE)
            .edit()
            .putBoolean(PREF_MANAGED_EDUCATION, !shouldShow)
            .apply()
    }
}