Skip to content

AdvancedExtendedUsage_en

Kongzue edited this page Sep 14, 2024 · 2 revisions

🌐 View 简体中文文档 | 繁體中文文檔

🆙 Advanced Extension Usage

DialogX Structure Diagram

DialogX Structure Diagram

Properties Effective for Individual Components

Even though global configurations are available, developers can still make specific settings for individual components.

For example, if the global configuration is set to prevent dialogs from closing by clicking outside the dialog area, but you want BottomDialog to be an exception, you can use the following configuration:

BottomDialog.overrideCancelable = BaseDialog.BOOLEAN.TRUE;

You can also make separate settings for the animations of components, such as:

BottomDialog.overrideEnterDuration = 100;    // Entrance animation duration is 100 milliseconds
BottomDialog.overrideExitDuration = 100;     // Exit animation duration is 100 milliseconds
BottomDialog.overrideEnterAnimRes = R.anim.anim_dialogx_top_enter;  // Entrance animation resource
BottomDialog.overrideExitAnimRes = R.anim.anim_dialogx_top_exit;    // Exit animation resource

This method allows you to override the entrance and exit animations for a specific component. Note that these methods will not affect other components globally, only the animation effects of the specific component.

Priority: Instance method setting > Component override setting > Global setting.

Additionally, FullScreenDialog only offers animation duration settings and does not provide animation resource settings (this component only allows up and down entrance and exit animations);

CustomDialog has additional overrideMaskEnterAnimRes and overrideMaskExitAnimRes to override the animation effects of the background mask, setting it to 0 will cancel the animation.

At this time, other dialog components in the current project will still follow the global configuration, while dialogs with properties effective for individual components will be based on their individual settings.

Note that this configuration should be distinguished from the properties set for a single dialog instance, for example:

BottomDialog.build()
        ...
        .setCancelable(true)   
        .show();

Overriding Part of the Theme

For instance, if you want to display PopTip toast prompts not as defined by the theme (e.g., at the bottom of the screen) but according to your own requirements (e.g., in the center of the screen), you can adjust the behavior of the dialog by overriding the theme, for example:

DialogX.globalStyle = new MaterialStyle(){
    @Override
    public PopTipSettings popTipSettings() {
        return new PopTipSettings() {
            @Override
            public ALIGN align() {
                return ALIGN.CENTER;
            }
        };
    }
};

Fully Customizing Open and Close Animations

Please note this method is for situations where you need to fully control the content and details of the dialog. If you just want to change the overall animation without controlling the details, please refer to the custom open and close animation section for a specific dialog, such as 《Basic Dialogs MessageDialog and InputDialog - Customizing Open and Close Animations》

Using the DialogXAnimInterface, you can fully customize the open and close animations.

Since the internal elements of DialogX dialog components are exposed, you can easily access and manipulate them. With this, combined with DialogXAnimInterface, which handles the animation behavior of opening and closing the dialog, you can fully utilize it to achieve your desired effect.

For example, for a CustomDialog, you can control its opening and closing animations like this:

CustomDialog.show(new OnBindView<CustomDialog>(R.layout.layout_custom_dialog) {
            @Override
            public void onBind(final CustomDialog dialog, View v) {
                //...
            }
        })
        // Implement fully custom animation effects
        .setDialogXAnimImpl(new DialogXAnimInterface<CustomDialog>() {
            @Override
            public void doShowAnim(CustomDialog customDialog, ViewGroup dialogBodyView) {
                // Custom animation implementation
            }
            @Override
            public void do

ExitAnim(CustomDialog customDialog, ViewGroup dialogBodyView) {
                // Custom exit animation implementation
            }
        });

For animProgress, it essentially acts as an inverse callback executor. Since the duration of the animation is uncertain, you need to notify DialogX what stage your animation has reached so that the dialog can act accordingly. For example, the closing animation process should go from 1f to 0f, and after completion, the dialog should be destroyed. So, when animProgress.run(0f) is executed, the destruction process will commence. The opening animation should go from 0f to 1f, and when animProgress.run(1f) is executed, the opening animation of the dialog is fully complete.

Queue Dialogs

In some scenarios, there's a need for "modal" dialogs, i.e., creating multiple dialogs at once, forming a queue, and displaying them one by one. When one dialog closes, the next one automatically starts. In this case, you can use queue dialogs to accomplish this.

Here's an example code. In DialogX.showDialogList(...), build multiple dialogs. Note that these dialogs must be in an unstarted state, built using .build() method, separated by “,” to form a queue, and they will start automatically.

DialogX.showDialogList(
        // Multiple dialogs built and separated by commas
);

During use, you can stop the display of the subsequent queue dialogs at any time using .cleanDialogList().

Implementation Mode (Experimental)

Window Implementation Mode

DialogX defaults to using the View implementation mode, self-adapting to the lifecycle. You can also choose the Window implementation solution (similar to AlertDialog). Note that using the Window implementation mode is experimental and has certain risks and known bugs. You can enable the Window implementation mode using:

DialogX.implIMPLMode= DialogX.IMPL_MODE.WINDOW;

WindowUtil provides interfaces for additional customization of WindowManager.LayoutParams:

WindowUtil.windowSettings = new WindowUtil.WindowSettings() {
    @Override
    public WindowManager.LayoutParams overrideWindowLayoutParamsInterface(Context context, View dialogView, WindowManager.LayoutParams originWindowLayoutParams) {
        // Handle originWindowLayoutParams...
        return originWindowLayoutParams;
    }

    @Override
    public ViewGroup overrideRootView(Context context) {
        // Customize the root layout, the dialog layout will be added to the root layout, return null means use the default FrameLayout
        return null;
    }
};

DialogFragment Implementation Method

In the latest version 0.0.41.beta4, the DialogFragment implementation method is provided. Use the following method to enable DialogFragment implementation:

DialogX.implIMPLMode= DialogX.IMPL_MODE.DIALOG_FRAGMENT;

No pending issues have been found in this mode so far, but it is still not recommended for use in production environments.

FloatingActivity Implementation Method

Similar to Window, a transparent-bottom Activity is used as the underlying bearer for the dialog. This approach can, to some extent, be launched from the background (PendingIntent).

DialogX.implIMPLMode= DialogX.IMPL_MODE.FLOATING_ACTIVITY;
Clone this wiki locally