Skip to content

Commit

Permalink
Add support for gif icon in dialogs
Browse files Browse the repository at this point in the history
update README.md
  • Loading branch information
Daniel committed Jun 5, 2020
1 parent 8d540f8 commit ac7d100
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Add this to your module's `build.gradle` file:
```gradle
dependencies {
...
implementation 'com.github.Dan629pl:NordanMaterialDialog:1.0.2'
implementation 'com.github.Dan629pl:NordanMaterialDialog:1.0.3'
}
```
<h1>Nordan Alert Dialog</h1>
Expand All @@ -26,7 +26,7 @@ dependencies {
.setMessage("Your message")
.setPositiveBtnText("Ok")
.setNegativeBtnText("Cancel")
.setIcon(R.drawable.your_drawable)
.setIcon(R.drawable.your_drawable,false)
.setBackgroundColor(R.color.red)
.onPositiveClicked(() -> {/* Do something here */})
.onNegativeClicked(() -> {/* Do something here */})
Expand Down Expand Up @@ -56,6 +56,22 @@ dependencies {
.build().show();
```

<h3>Dialog with Gif icon</h3>

```diff
new NordanAlertDialog.Builder(this)
.setAnimation(Animation.SLIDE)
.isCancellable(false)
.setTitle("Gif Icon")
.setMessage("Library support gif icons!")
.setIcon(R.drawable.success_gif,true)
.setPositiveBtnText("Great!")
.onPositiveClicked(this::showAll)
.build().show();
```
![Gif Dialog](https://github.com/Dan629pl/NordanMaterialDialog/blob/master/img/gifdialog.gif)


<h1>Nordan Loading Dialog</h1>

```diff
Expand Down
13 changes: 11 additions & 2 deletions app/src/main/java/com/nordan/dialog/NordanAlertDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.Window;
import android.widget.ImageView.ScaleType;
import android.widget.RelativeLayout;
import com.google.android.material.button.MaterialButton;
import com.google.android.material.textview.MaterialTextView;
import java.util.Optional;
Expand All @@ -25,6 +27,7 @@ public static class Builder {
private Activity activity;
private Animation animation;
private int icon;
private boolean isGif;
private NordanAlertDialogListener positiveListener;
private NordanAlertDialogListener negativeListener;
private int backgroundColor;
Expand Down Expand Up @@ -65,8 +68,9 @@ public Builder setNegativeBtnText(String negativeBtnText) {
return this;
}

public Builder setIcon(int icon) {
public Builder setIcon(int icon, boolean isGif) {
this.icon = icon;
this.isGif = isGif;
return this;
}

Expand Down Expand Up @@ -194,13 +198,18 @@ private void setInformationDialog(GifImageView iconImg, View view) {
}

private void setCustomDialog(Dialog dialog, GifImageView iconImg, View view) {
RelativeLayout relativeHeader = dialog.findViewById(R.id.relative_header);
if (icon == 0 && backgroundColor == 0) {
dialog.findViewById(R.id.relative_header).setVisibility(View.GONE);
relativeHeader.setVisibility(View.GONE);
return;
}
if (icon != 0) {
iconImg.setImageResource(icon);
iconImg.setVisibility(View.VISIBLE);
if (isGif) {
relativeHeader.getLayoutParams().height = 250;
iconImg.setScaleType(ScaleType.CENTER_CROP);
}
}
if (backgroundColor != 0) {
view.setBackgroundColor(backgroundColor);
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/res/layout/nordan_alert_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@
<RelativeLayout
android:id="@+id/relative_header"
android:layout_width="match_parent"
android:layout_height="70dp">
android:layout_height="wrap_content">
<View
android:id="@+id/background"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_height="80dp"
android:background="@color/transparent" />
<pl.droidsonroids.gif.GifImageView
android:id="@+id/icon"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_height="wrap_content"
android:minHeight="70dp"
android:layout_centerInParent="true"
android:visibility="gone" />
</RelativeLayout>
Expand Down
Binary file added img/gifdialog.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ac7d100

Please sign in to comment.