diff --git a/MaterialDialogLibrary/src/main/java/com/shreyaspatil/MaterialDialog/AbstractDialog.java b/MaterialDialogLibrary/src/main/java/com/shreyaspatil/MaterialDialog/AbstractDialog.java index c2f2407..f1c1333 100644 --- a/MaterialDialogLibrary/src/main/java/com/shreyaspatil/MaterialDialog/AbstractDialog.java +++ b/MaterialDialogLibrary/src/main/java/com/shreyaspatil/MaterialDialog/AbstractDialog.java @@ -44,6 +44,7 @@ public class AbstractDialog implements DialogInterface { protected String mAnimationFile; protected LottieAnimationView mAnimationView; protected Boolean showInLandscape; + protected Integer height; protected OnDismissListener mOnDismissListener; protected OnCancelListener mOnCancelListener; @@ -59,7 +60,9 @@ protected AbstractDialog(@NonNull Activity mActivity, @NonNull DialogButton mNegativeButton, @RawRes int mAnimationResId, @NonNull String mAnimationFile, - @NonNull Boolean showInLandscape) { + @NonNull Boolean showInLandscape, + @NonNull Integer height + ) { this.mActivity = mActivity; this.title = title; this.message = message; @@ -69,6 +72,7 @@ protected AbstractDialog(@NonNull Activity mActivity, this.mAnimationResId = mAnimationResId; this.mAnimationFile = mAnimationFile; this.showInLandscape = showInLandscape; + this.height = height; } protected View createView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container) { @@ -154,6 +158,13 @@ public void onClick(View view) { } } + if (mAnimationView.getVisibility() == View.VISIBLE && height != -1) { + ViewGroup.LayoutParams params = mAnimationView.getLayoutParams(); + params.height = this.height; + mAnimationView.setLayoutParams(params); + mAnimationView.requestLayout(); + } + // Apply Styles TypedArray a = mActivity.getTheme().obtainStyledAttributes(R.styleable.MaterialDialog); diff --git a/MaterialDialogLibrary/src/main/java/com/shreyaspatil/MaterialDialog/BottomSheetMaterialDialog.java b/MaterialDialogLibrary/src/main/java/com/shreyaspatil/MaterialDialog/BottomSheetMaterialDialog.java index 4ca55fc..9ea4bf4 100644 --- a/MaterialDialogLibrary/src/main/java/com/shreyaspatil/MaterialDialog/BottomSheetMaterialDialog.java +++ b/MaterialDialogLibrary/src/main/java/com/shreyaspatil/MaterialDialog/BottomSheetMaterialDialog.java @@ -33,8 +33,10 @@ protected BottomSheetMaterialDialog(@NonNull final Activity mActivity, @NonNull DialogButton mNegativeButton, @RawRes int mAnimationResId, @NonNull String mAnimationFile, - @NonNull Boolean mShowInLandscape) { - super(mActivity, title, message, mCancelable, mPositiveButton, mNegativeButton, mAnimationResId, mAnimationFile, mShowInLandscape); + @NonNull Boolean mShowInLandscape, + @NonNull Integer mHeight + ) { + super(mActivity, title, message, mCancelable, mPositiveButton, mNegativeButton, mAnimationResId, mAnimationFile, mShowInLandscape, mHeight); // Init Dialog, Create Bottom Sheet Dialog mDialog = new BottomSheetDialog(mActivity); @@ -94,6 +96,7 @@ public static class Builder { private int animationResId = NO_ANIMATION; private String animationFile; private Boolean showInLandscape = false; + private Integer height = -1; /** * @param activity where BottomSheet Material Dialog is to be built. @@ -219,12 +222,23 @@ public Builder setShowInLandscape(@NonNull Boolean showInLandscape) { return this; } + /** It sets the showInLandscape property to allow or not the animation to be shown in landscape orientation + * + * @param height sets the height of the animation wrapper + * @return this, for chaining. + */ + @NonNull + public Builder setAnimationHeight(@NonNull Integer height) { + this.height = height; + return this; + } + /** * Build the {@link BottomSheetMaterialDialog}. */ @NonNull public BottomSheetMaterialDialog build() { - return new BottomSheetMaterialDialog(activity, title, message, isCancelable, positiveButton, negativeButton, animationResId, animationFile, showInLandscape); + return new BottomSheetMaterialDialog(activity, title, message, isCancelable, positiveButton, negativeButton, animationResId, animationFile, showInLandscape, height); } } diff --git a/MaterialDialogLibrary/src/main/java/com/shreyaspatil/MaterialDialog/MaterialDialog.java b/MaterialDialogLibrary/src/main/java/com/shreyaspatil/MaterialDialog/MaterialDialog.java index 243684a..dc37147 100644 --- a/MaterialDialogLibrary/src/main/java/com/shreyaspatil/MaterialDialog/MaterialDialog.java +++ b/MaterialDialogLibrary/src/main/java/com/shreyaspatil/MaterialDialog/MaterialDialog.java @@ -26,8 +26,10 @@ protected MaterialDialog(@NonNull final Activity mActivity, @NonNull DialogButton mNegativeButton, @RawRes int mAnimationResId, @NonNull String mAnimationFile, - @NonNull Boolean mShowInLandscape) { - super(mActivity, title, message, mCancelable, mPositiveButton, mNegativeButton, mAnimationResId, mAnimationFile, mShowInLandscape); + @NonNull Boolean mShowInLandscape, + @NonNull Integer mHeight + ) { + super(mActivity, title, message, mCancelable, mPositiveButton, mNegativeButton, mAnimationResId, mAnimationFile, mShowInLandscape, mHeight); // Init Dialog final AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); @@ -58,6 +60,7 @@ public static class Builder { private int animationResId = NO_ANIMATION; private String animationFile; private Boolean showInLandscape = false; + private Integer height = -1; /** * @param activity where Material Dialog is to be built. @@ -171,12 +174,23 @@ public Builder setShowInLandscape(@NonNull Boolean showInLandscape) { return this; } + /** It sets the showInLandscape property to allow or not the animation to be shown in landscape orientation + * + * @param height sets the height of the animation wrapper + * @return this, for chaining. + */ + @NonNull + public Builder setAnimationHeight(@NonNull Integer height) { + this.height = height; + return this; + } + /** * Build the {@link MaterialDialog}. */ @NonNull public MaterialDialog build() { - return new MaterialDialog(activity, title, message, isCancelable, positiveButton, negativeButton, animationResId, animationFile, showInLandscape); + return new MaterialDialog(activity, title, message, isCancelable, positiveButton, negativeButton, animationResId, animationFile, showInLandscape, height); } } } diff --git a/MaterialDialogLibrary/src/main/res/layout-land/layout_alert_dialog.xml b/MaterialDialogLibrary/src/main/res/layout-land/layout_alert_dialog.xml index 2f7dc94..e5b19f2 100644 --- a/MaterialDialogLibrary/src/main/res/layout-land/layout_alert_dialog.xml +++ b/MaterialDialogLibrary/src/main/res/layout-land/layout_alert_dialog.xml @@ -21,7 +21,7 @@ android:layout_width="match_parent" android:layout_height="175dp" android:layout_alignParentTop="true" - android:scaleType="centerCrop" + android:scaleType="fitCenter" android:visibility="visible" app:lottie_autoPlay="true" app:lottie_loop="true" /> diff --git a/MaterialDialogLibrary/src/main/res/layout/layout_alert_dialog.xml b/MaterialDialogLibrary/src/main/res/layout/layout_alert_dialog.xml index b12ae82..c26b4bc 100644 --- a/MaterialDialogLibrary/src/main/res/layout/layout_alert_dialog.xml +++ b/MaterialDialogLibrary/src/main/res/layout/layout_alert_dialog.xml @@ -24,7 +24,7 @@ app:lottie_loop="true" android:visibility="visible" android:layout_alignParentTop="true" - android:scaleType="centerCrop" + android:scaleType="fitCenter" app:lottie_autoPlay="true"/>