diff --git a/MaterialDialogLibrary/src/main/java/com/shreyaspatil/MaterialDialog/AbstractDialog.java b/MaterialDialogLibrary/src/main/java/com/shreyaspatil/MaterialDialog/AbstractDialog.java index c10fdb5..ccb61ca 100644 --- a/MaterialDialogLibrary/src/main/java/com/shreyaspatil/MaterialDialog/AbstractDialog.java +++ b/MaterialDialogLibrary/src/main/java/com/shreyaspatil/MaterialDialog/AbstractDialog.java @@ -223,6 +223,13 @@ public void onDismiss(android.content.DialogInterface dialogInterface) { }); } + /** + * @return {@link LottieAnimationView} from the Dialog. + */ + public LottieAnimationView getAnimationView() { + return mAnimationView; + } + private void showCallback() { if (mOnShowListener != null) { mOnShowListener.onShow(this); diff --git a/app/src/main/java/com/shreyaspatil/MaterialDialogExample/MainActivity.java b/app/src/main/java/com/shreyaspatil/MaterialDialogExample/MainActivity.java index c276054..9100930 100644 --- a/app/src/main/java/com/shreyaspatil/MaterialDialogExample/MainActivity.java +++ b/app/src/main/java/com/shreyaspatil/MaterialDialogExample/MainActivity.java @@ -2,6 +2,7 @@ import android.os.Bundle; import android.view.View; +import android.widget.Button; import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; @@ -9,19 +10,73 @@ import com.shreyaspatil.MaterialDialog.BottomSheetMaterialDialog; import com.shreyaspatil.MaterialDialog.MaterialDialog; import com.shreyaspatil.MaterialDialog.interfaces.DialogInterface; -import com.shreyaspatil.MaterialDialog.interfaces.OnCancelListener; -import com.shreyaspatil.MaterialDialog.interfaces.OnDismissListener; -import com.shreyaspatil.MaterialDialog.interfaces.OnShowListener; -public class MainActivity extends AppCompatActivity { +public class MainActivity extends AppCompatActivity implements View.OnClickListener { + + private MaterialDialog mSimpleDialog; + private MaterialDialog mAnimatedDialog; + private BottomSheetMaterialDialog mSimpleBottomSheetDialog; + private BottomSheetMaterialDialog mAnimatedBottomSheetDialog; + + private Button mButtonSimpleDialog; + private Button mButtonAnimatedDialog; + private Button mButtonBottomSheetDialog; + private Button mButtonAnimatedBottomSheetDialog; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + mButtonSimpleDialog = findViewById(R.id.button_simple_dialog); + mButtonAnimatedDialog = findViewById(R.id.button_animated_dialog); + mButtonBottomSheetDialog = findViewById(R.id.button_simple_bottomsheet_dialog); + mButtonAnimatedBottomSheetDialog = findViewById(R.id.button_animated_bottomsheet_dialog); + + // Simple Material Dialog + mSimpleDialog = new MaterialDialog.Builder(this) + .setTitle("Delete?") + .setMessage("Are you sure want to delete this file?") + .setCancelable(false) + .setPositiveButton("Delete", R.drawable.ic_delete, new MaterialDialog.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + Toast.makeText(getApplicationContext(), "Deleted!", Toast.LENGTH_SHORT).show(); + dialogInterface.dismiss(); + } + }) + .setNegativeButton("Cancel", R.drawable.ic_close, new MaterialDialog.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int which) { + Toast.makeText(getApplicationContext(), "Cancelled!", Toast.LENGTH_SHORT).show(); + dialogInterface.dismiss(); + } + }) + .build(); + + // Simple BottomSheet Material Dialog + mSimpleBottomSheetDialog = new BottomSheetMaterialDialog.Builder(this) + .setTitle("Delete?") + .setMessage("Are you sure want to delete this file?") + .setCancelable(false) + .setPositiveButton("Delete", R.drawable.ic_delete, new BottomSheetMaterialDialog.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + Toast.makeText(getApplicationContext(), "Deleted!", Toast.LENGTH_SHORT).show(); + dialogInterface.dismiss(); + } + }) + .setNegativeButton("Cancel", R.drawable.ic_close, new BottomSheetMaterialDialog.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int which) { + Toast.makeText(getApplicationContext(), "Cancelled!", Toast.LENGTH_SHORT).show(); + dialogInterface.dismiss(); + } + }) + .build(); + // Animated Simple Material Dialog - final MaterialDialog alertDialog = new MaterialDialog.Builder(this) + mAnimatedDialog = new MaterialDialog.Builder(this) .setTitle("Delete?") .setMessage("Are you sure want to delete this file?") .setCancelable(false) @@ -43,7 +98,7 @@ public void onClick(DialogInterface dialogInterface, int which) { .build(); // Animated BottomSheet Material Dialog - final BottomSheetMaterialDialog sheetDialog = new BottomSheetMaterialDialog.Builder(this) + mAnimatedBottomSheetDialog = new BottomSheetMaterialDialog.Builder(this) .setTitle("Delete?") .setMessage("Are you sure want to delete this file?") .setCancelable(false) @@ -64,39 +119,30 @@ public void onClick(DialogInterface dialogInterface, int which) { .setAnimation("delete_anim.json") .build(); - findViewById(R.id.button_smdialog).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - alertDialog.show(); - } - }); - - findViewById(R.id.button_bsdialog).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - sheetDialog.show(); - } - }); - - sheetDialog.setOnCancelListener(new OnCancelListener() { - @Override - public void onCancel(DialogInterface dialogInterface) { - System.out.println("CANCELLED"); - } - }); - - sheetDialog.setOnShowListener(new OnShowListener() { - @Override - public void onShow(DialogInterface dialogInterface) { - System.out.println("SHOWED"); - } - }); - - sheetDialog.setOnDismissListener(new OnDismissListener() { - @Override - public void onDismiss(DialogInterface dialogInterface) { - System.out.println("DISMISS"); - } - }); + mButtonSimpleDialog.setOnClickListener(this); + mButtonBottomSheetDialog.setOnClickListener(this); + mButtonAnimatedDialog.setOnClickListener(this); + mButtonAnimatedBottomSheetDialog.setOnClickListener(this); + } + + @Override + public void onClick(View view) { + switch (view.getId()) { + case R.id.button_simple_dialog : + mSimpleDialog.show(); + break; + + case R.id.button_simple_bottomsheet_dialog : + mSimpleBottomSheetDialog.show(); + break; + + case R.id.button_animated_dialog : + mAnimatedDialog.show(); + break; + + case R.id.button_animated_bottomsheet_dialog : + mAnimatedBottomSheetDialog.show(); + break; + } } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index e963823..1ac5340 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -6,24 +6,47 @@ tools:context=".MainActivity"> + android:text="Simple Bottomsheet Material Dialog" /> + + + + \ No newline at end of file