Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dialog animation #33

Merged
merged 1 commit into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ public CustomViewDialog setMaxDialogWidth(int maxDialogWidth) {
return this;
}

@Override
public CustomViewDialog setDialogAnimations(int styleRes) {
super.setDialogAnimations(styleRes);
return this;
}

@Override
protected void setButtons() {
setButton1(R.id.btn1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@ public ListDialog setMaxDialogWidth(int maxDialogWidth) {
return this;
}

@Override
public ListDialog setDialogAnimations(int styleRes) {
super.setDialogAnimations(styleRes);
return this;
}

@Override
public Button getLeftButton() {
return super.getLeftButton();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ public MessageDialog setMaxDialogWidth(int maxDialogWidth){
return this;
}

@Override
public MessageDialog setDialogAnimations(int styleRes) {
super.setDialogAnimations(styleRes);
return this;
}

@Override
public MessageDialog show(){
super.show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.ContextThemeWrapper;
import android.view.DragEvent;
import android.view.View;

import android.widget.Button;
Expand Down Expand Up @@ -58,7 +59,7 @@ protected SJDialog Builder(Context context, @LayoutRes int layoutResID, @StyleRe
setContentView(layoutResID);
setDialogSize();
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

dialog.getWindow().getAttributes().windowAnimations = R.style.SJDialogAnimation;
setButtons();
if (theme != defaultTheme)
regenerateButtons();
Expand Down Expand Up @@ -438,6 +439,17 @@ protected SJDialog setMaxDialogWidth(int maxDialogWidth) {
return this;
}


/**
* Set animation for a dialog
* @param styleRes style resource
* @return current class
*/
protected SJDialog setDialogAnimations(@StyleRes int styleRes){
dialog.getWindow().getAttributes().windowAnimations = styleRes;
return this;
}

private OneButtonException OneButtonException() {
return new OneButtonException("Trying to access right button when dialog has only one button. Use 'dialogWithTwoButtons()' to fix the problem.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,12 @@ public SetupDialog setMaxDialogWidth(int maxDialogWidth) {

}

@Override
public SetupDialog setDialogAnimations(int styleRes) {
super.setDialogAnimations(styleRes);
return this;
}

@Override
protected void setButtons() {
setButton1(R.id.btn1);
Expand Down
15 changes: 15 additions & 0 deletions SJDialog/src/main/res/anim/slide_in.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
>
<alpha
android:duration="200"
android:fromAlpha="0"
android:toAlpha="1"
/>
<translate
android:duration="300"
android:fromYDelta="5%"
android:toYDelta="0"
/>

</set>
15 changes: 15 additions & 0 deletions SJDialog/src/main/res/anim/slide_out.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
>
<alpha
android:duration="200"
android:fromAlpha="1"
android:toAlpha="0"
/>
<translate
android:duration="300"
android:fromYDelta="0"
android:toYDelta="5%"
/>

</set>
5 changes: 5 additions & 0 deletions SJDialog/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@
<item name="android:textColor">@color/md_theme_onError</item>
</style>

<style name="SJDialogAnimation">
<item name="android:windowEnterAnimation">@anim/slide_in</item>
<item name="android:windowExitAnimation">@anim/slide_out</item>
</style>

</resources>