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

Commit d26993eb authored by Ivan Chiang's avatar Ivan Chiang
Browse files

[PM] Support better transition in PIA V2 (6/N)

Fix the layout issue on non-material mode

Flag: android.content.pm.use_pia_v2
Test: manual. screenrecord
Bug: 274120822
Bug: 402448072
Change-Id: Iee1525d369fbeefdcd3b2818b4f3d7d267f957b4
parent 3e2e0b3b
Loading
Loading
Loading
Loading
+60 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.content.DialogInterface;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import androidx.annotation.NonNull;
@@ -35,6 +36,9 @@ import com.android.packageinstaller.v2.model.PackageUtil;
import com.google.android.material.button.MaterialButton;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;

import java.util.ArrayList;
import java.util.List;

/**
 * The utility of UI components.
 */
@@ -249,4 +253,60 @@ public class UiUtil {
                    ColorStateList.valueOf(context.getColor(android.R.color.transparent)));
        }
    }

    /**
     * Update the button bar layout if needed
     */
    public static void updateButtonBarLayoutIfNeeded(@NonNull Context context,
            @NonNull Dialog dialog) {
        // Don't need to handle the material alertdialog case. It has already been handled.
        if (PackageUtil.isMaterialDesignEnabled(context)) {
            return;
        }
        final Button positiveButton = getAlertDialogPositiveButton(dialog);
        if (positiveButton == null) {
            return;
        }

        final ViewGroup parent = (ViewGroup) positiveButton.getParent();
        final List<Integer> visibleButtonIndexList = new ArrayList<>();
        final List<Integer> nonButtonChildIndexList = new ArrayList<>();

        // Get the count of the visible buttons and the non-button children.
        for (int i = 0, count = parent.getChildCount(); i < count; i++) {
            View child = parent.getChildAt(i);
            if (child instanceof Button) {
                if (child.getVisibility() == View.VISIBLE) {
                    visibleButtonIndexList.add(i);
                }
            } else {
                // The width of the layoutParams of the space children is 0 and the weight is 1,
                // don't change the visibility of them
                if (child.getLayoutParams().width != 0) {
                    nonButtonChildIndexList.add(i);
                }
            }
        }

        final int firstVisibleButtonIndex = visibleButtonIndexList.isEmpty()
                ? -1 : visibleButtonIndexList.getFirst();
        final int lastVisibleButtonIndex = visibleButtonIndexList.isEmpty()
                ? -1 : visibleButtonIndexList.getLast();
        // Set the visibility of the non-button children except the space children
        for (int i = 0, count = nonButtonChildIndexList.size(); i < count; i++) {
            final int currentChildIndex = nonButtonChildIndexList.get(i);
            if (visibleButtonIndexList.size() <= 1) {
                parent.getChildAt(currentChildIndex).setVisibility(View.GONE);
            } else {
                if (currentChildIndex < firstVisibleButtonIndex) {
                    parent.getChildAt(currentChildIndex).setVisibility(View.GONE);
                } else if (currentChildIndex > firstVisibleButtonIndex
                        && currentChildIndex < lastVisibleButtonIndex) {
                    parent.getChildAt(currentChildIndex).setVisibility(View.VISIBLE);
                } else {
                    parent.getChildAt(currentChildIndex).setVisibility(View.GONE);
                }
            }
        }
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -188,6 +188,8 @@ public class InstallationFragment extends DialogFragment {
                updateUserActionRequiredUI(mDialog, (InstallUserActionRequired) installStage);
            }
        }

        UiUtil.updateButtonBarLayoutIfNeeded(requireContext(), mDialog);
    }

    private void updateInstallAbortedUI(Dialog dialog, InstallAborted installStage) {
+2 −0
Original line number Diff line number Diff line
@@ -139,6 +139,8 @@ public class UnarchiveFragment extends DialogFragment {
                updateUserActionRequiredUI(mDialog, (UnarchiveUserActionRequired) unarchiveStage);
            }
        }

        UiUtil.updateButtonBarLayoutIfNeeded(requireContext(), mDialog);
    }

    private void updateUnarchiveErrorUI(Dialog dialog, UnarchiveError unarchiveStage) {
+2 −0
Original line number Diff line number Diff line
@@ -126,6 +126,8 @@ public class UninstallationFragment extends DialogFragment {
                updateUserActionRequiredUI(mDialog, (UninstallUserActionRequired) uninstallStage);
            }
        }

        UiUtil.updateButtonBarLayoutIfNeeded(requireContext(), mDialog);
    }

    private void updateUninstallAbortedUI(Dialog dialog, UninstallAborted uninstallStage) {