Leanplum / Leanplum-Android-SDK

Leanplum's integrated solution delivers meaningful engagement across messaging and the in-app experience.
https://www.leanplum.com
Apache License 2.0
46 stars 40 forks source link

Add dialog customizer to allow window flags #440

Closed hborisoff closed 3 years ago

hborisoff commented 3 years ago
What Where/Who
JIRA Issue SDK-289
People Involved @hborisoff

Background

Provide interface to customise the Dialog and content View before showing a message. This will allow easy support of devices with notch by providing several lines of code.

Testing steps

Solution was tested with several versions before and after Android O.

The following is an example how to draw fullscreen and behind the notch for Interstitial and Banner templates. You can override each of the methods to support different types of templates.

MessageTemplates.setCustomizer(new DialogCustomizer() {

    @Override
    public void customizeInterstitial(Dialog messageDialog, View messageContent) {
        Window window = messageDialog.getWindow();
        if (window == null) {
            return;
        }

        // hide status bar
        window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

        // draw view fullscreen
        messageContent.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);

        // draw under notch
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P){
            window.getAttributes().layoutInDisplayCutoutMode =
                WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
        }
    }

    @Override
    public void customizeBanner(Dialog messageDialog, View messageContent) {
        customizeInterstitial(messageDialog, messageContent);
    }
});
hfhchan commented 3 years ago

This doesn't get called for RichHtmlController when isFullscreen() is true.

hborisoff commented 3 years ago

@hfhchan Thank you for reporting that!

We fixed it in #463 and it will available in next release.