diff --git a/app/src/main/java/umairayub/madialogdemoapp/MainActivity.java b/app/src/main/java/umairayub/madialogdemoapp/MainActivity.java index fccb3e3..0b69e63 100644 --- a/app/src/main/java/umairayub/madialogdemoapp/MainActivity.java +++ b/app/src/main/java/umairayub/madialogdemoapp/MainActivity.java @@ -5,6 +5,7 @@ import android.os.Bundle; import android.view.View; import android.widget.Button; +import android.widget.LinearLayout; import androidx.appcompat.app.AppCompatActivity; @@ -14,6 +15,7 @@ public class MainActivity extends AppCompatActivity { Button btn1, btn2, btn3, btn4, btn5, btn6, btn7; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -27,7 +29,6 @@ protected void onCreate(Bundle savedInstanceState) { btn7 = (Button) findViewById(R.id.btn7); - btn1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -51,15 +52,14 @@ public void onClick(View view) { public void onClick(View view) { new MaDialog.Builder(MainActivity.this) .setMessage("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis scelerisque, turpis et fringilla malesuada, leo velit ullamcorper enim, quis iaculis metus urna ut ligula. Sed malesuada lacinia massa, a accumsan justo condimentum vel.") - .setPositiveButtonText("Yes") - .setNegativeButtonText("Cancel") - .setPositiveButtonListener(new MaDialogListener() { + .setButtonOrientation(LinearLayout.HORIZONTAL) + .AddNewButton(R.style.AppTheme, "Yes", new MaDialogListener() { @Override public void onClick() { } }) - .setNegativeButtonListener(new MaDialogListener() { + .AddNewButton(R.style.AppTheme, "No", new MaDialogListener() { @Override public void onClick() { @@ -75,15 +75,13 @@ public void onClick(View view) { .setTitle("Basic with Title + Buttons") .setMessage("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis scelerisque, turpis et fringilla malesuada, leo velit ullamcorper enim, quis iaculis metus urna ut ligula. Sed malesuada lacinia massa, a accumsan justo condimentum vel. ") - .setPositiveButtonText("Yes") - .setNegativeButtonText("Cancel") - .setPositiveButtonListener(new MaDialogListener() { + .AddNewButton(R.style.AppTheme, "Yes", new MaDialogListener() { @Override public void onClick() { } }) - .setNegativeButtonListener(new MaDialogListener() { + .AddNewButton(R.style.AppTheme, "Cancel", new MaDialogListener() { @Override public void onClick() { @@ -99,15 +97,13 @@ public void onClick(View view) { .setTitle("Basic with Image + Title + Buttons") .setMessage("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis scelerisque, turpis et fringilla malesuada, leo velit ullamcorper enim, quis iaculis metus urna ut ligula. Sed malesuada lacinia massa, a accumsan justo condimentum vel.") .setImage(R.drawable.image) - .setPositiveButtonText("Yes") - .setNegativeButtonText("Cancel") - .setPositiveButtonListener(new MaDialogListener() { + .AddNewButton(R.style.AppTheme, "Yes", new MaDialogListener() { @Override public void onClick() { } }) - .setNegativeButtonListener(new MaDialogListener() { + .AddNewButton(R.style.AppTheme, "Cancel", new MaDialogListener() { @Override public void onClick() { @@ -123,17 +119,13 @@ public void onClick(View view) { .setTitle("Basic with GIF + Title + Buttons") .setMessage("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis scelerisque, turpis et fringilla malesuada, leo velit ullamcorper enim, quis iaculis metus urna ut ligula. Sed malesuada lacinia massa, a accumsan justo condimentum vel.") .setGif(R.drawable.dragon) - .setPositiveButtonText("Yes") - .setNegativeButtonText("Cancel") - .setCustomFont(R.font.press_start_2p) - - .setPositiveButtonListener(new MaDialogListener() { + .AddNewButton(R.style.AppTheme, "Yes", new MaDialogListener() { @Override public void onClick() { } }) - .setNegativeButtonListener(new MaDialogListener() { + .AddNewButton(R.style.AppTheme, "Cancel", new MaDialogListener() { @Override public void onClick() { diff --git a/madialog/src/main/java/umairayub/madialog/MaDialog.java b/madialog/src/main/java/umairayub/madialog/MaDialog.java index b82d090..4878b2c 100644 --- a/madialog/src/main/java/umairayub/madialog/MaDialog.java +++ b/madialog/src/main/java/umairayub/madialog/MaDialog.java @@ -5,6 +5,8 @@ import android.graphics.Color; import android.graphics.Typeface; import android.graphics.drawable.ColorDrawable; +import android.os.Build; +import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; import android.view.Window; @@ -13,14 +15,19 @@ import android.widget.LinearLayout; import android.widget.TextView; +import androidx.annotation.StyleRes; import androidx.core.content.res.ResourcesCompat; import com.bumptech.glide.Glide; +import java.util.ArrayList; +import java.util.List; + public class MaDialog { public static class Builder { + AlertDialog alertDialog; private MaDialogListener positiveButtonListener, negativeButtonListener; @@ -38,7 +45,10 @@ public static class Builder { backgroundColor, image, gif, - font_id; + font_id, + buttonOrientation; + + private List