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

Commit 7aab0c1b authored by Winson Chung's avatar Winson Chung
Browse files

Fix issue with PiP actions flashing.

- Instead of recreating the whole layout, only add/hide action views as
  necessary

Bug: 35467434
Test: Launch PiP, tap some actions
Change-Id: Ib3cce253228d737bb699f80298001f08121640e4
parent 4b0d2bf7
Loading
Loading
Loading
Loading
+19 −10
Original line number Diff line number Diff line
@@ -412,16 +412,26 @@ public class PipMenuActivity extends Activity {
        } else {
            actionsContainer.setVisibility(View.VISIBLE);
            if (mActionsGroup != null) {
                mActionsGroup.removeAllViews();
                // Hide extra views
                for (int i = mActions.size(); i < mActionsGroup.getChildCount(); i++) {
                    mActionsGroup.getChildAt(i).setVisibility(View.GONE);
                }
                // Add needed views
                final LayoutInflater inflater = LayoutInflater.from(this);
                while (mActionsGroup.getChildCount() < mActions.size()) {
                    final ImageView actionView = (ImageView) inflater.inflate(
                            R.layout.pip_menu_action, mActionsGroup, false);
                    mActionsGroup.addView(actionView);
                }

                // Recreate the layout
                final boolean isLandscapePip = stackBounds != null &&
                        (stackBounds.width() > stackBounds.height());
                final LayoutInflater inflater = LayoutInflater.from(this);
                for (int i = 0; i < mActions.size(); i++) {
                    final RemoteAction action = mActions.get(i);
                    final ImageView actionView = (ImageView) inflater.inflate(
                            R.layout.pip_menu_action, mActionsGroup, false);
                    final ImageView actionView = (ImageView) mActionsGroup.getChildAt(i);

                    // TODO: Check if the action drawable has changed before we reload it
                    action.getIcon().loadDrawableAsync(this, d -> {
                        d.setTint(Color.WHITE);
                        actionView.setImageDrawable(d);
@@ -439,12 +449,11 @@ public class PipMenuActivity extends Activity {
                        actionView.setAlpha(DISABLED_ACTION_ALPHA);
                        actionView.setEnabled(false);
                    }
                    if (isLandscapePip && i > 0) {

                    // Update the margin between actions
                    LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams)
                            actionView.getLayoutParams();
                        lp.leftMargin = mBetweenActionPaddingLand;
                    }
                    mActionsGroup.addView(actionView);
                    lp.leftMargin = (isLandscapePip && i > 0) ? mBetweenActionPaddingLand : 0;
                }
            }