Skip to content

Repository files navigation

DialogAndroid - Easy Dialog


Simple way to use Dialog Fragment


Content List


Download

Add maven jitpack.io and dependencies in build.gradle (Project) :

// build.gradle projectallprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
// build.gradle app/moduledependencies {
...
implementation 'com.google.android.material:material:1.3.0'
implementation 'com.github.gzeinnumer:DialogAndroid:version'
implementation 'com.github.gzeinnumer:SimpleMaterialStyle:last-vesion'//check on https://github.com/gzeinnumer/SimpleMaterialStyle
}

Feature List


Tech stack and 3rd library

  • Material.io (docs)
  • agrawalsuneet/DotLoadersPack-Android (docs)
  • DialogFragment (docs)

Usage

First Step. Use MaterialComponents in your style :

<stylename="AppTheme"parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
</style>
<stylename="CustomDialogStyle"parent="Theme.MaterialComponents.Light.Dialog">
<itemname="colorPrimary">@color/colorPrimary</item>
<itemname="colorPrimaryDark">@color/colorPrimaryDark</item>
<itemname="colorAccent">@color/colorAccent</item>
<itemname="android:windowMinWidthMajor">80%</item>
<itemname="android:windowMinWidthMinor">80%</item>
<itemname="android:windowEnterAnimation">@anim/anim_in</item>
<itemname="android:windowExitAnimation">@anim/anim_out</item>
</style>

Add This Line to res/color.xml. Important

<?xml version="1.0" encoding="utf-8"?>
<resources>
<colorname="colorPrimary">#6200EE</color>
<colorname="colorPrimaryDark">#3700B3</color>
<colorname="colorAccent">#03DAC5</color>
</resources>

If you want to change default font, add custom_font.ttf to your res directory res->font. Than add this style to your style.xml/themes.xml

If you want to change default margin in dialog, add dimens.xml to your res directory res->value->dimens.xml.

ConfirmDialog

Dialog with 1 Title, 1 Content, 1 Negative Button, 1 Positive Button.

newConfirmDialog(getSupportFragmentManager())
.setTitle("ini title")
.setContent("ini content")
.onCancelPressedCallBack(newConfirmDialog.OnCancelPressed() {
@OverridepublicvoidonCancelPressed() {
Toast.makeText(MainActivity.this, "Cancel", Toast.LENGTH_SHORT).show();
}
})
.onOkPressedCallBack(newConfirmDialog.OnOkPressed() {
@OverridepublicvoidonOkPressed() {
Toast.makeText(MainActivity.this, "Ok", Toast.LENGTH_SHORT).show();
}
})
.show();

or you can write code like this :

ConfirmDialogdialog = newConfirmDialog(getSupportFragmentManager())
.setTitle("ini title")
.setContent("ini content");
dialog.onCancelPressedCallBack(newConfirmDialog.OnCancelPressed() {
@OverridepublicvoidonCancelPressed() {
Toast.makeText(MainActivity.this, "Cancel", Toast.LENGTH_SHORT).show();
}
});
dialog.onOkPressedCallBack(newConfirmDialog.OnOkPressed() {
@OverridepublicvoidonOkPressed() {
Toast.makeText(MainActivity.this, "Ok", Toast.LENGTH_SHORT).show();
}
});
dialog.show();

To enable CanceledOnTouchOutside :

newConfirmDialog(getSupportFragmentManager())
.setCanceledOnTouchOutside(true)

Preview :

ConfirmDialog -> Customize

You can Customize your dialog UI. ReadMore.


InfoDialog

Dialog with 1 Title, 1 Content, 1 Positif Button.

Code :

newInfoDialog(getSupportFragmentManager())
.setDialogType(DialogType.DialogSuccess)
.setTitle("ini title")
.setContent("ini content")
.onOkPressedCallBack(newInfoDialog.OnOkPressed() {
@OverridepublicvoidonOkPressed() {
Toast.makeText(MainActivity.this, "Ok", Toast.LENGTH_SHORT).show();
}
})
.show();

To enable CanceledOnTouchOutside :

newInfoDialog(getSupportFragmentManager())
.setCanceledOnTouchOutside(true)

To set auto Click Button Ok :

newInfoDialog(getSupportFragmentManager())
.autoDismisOnSecond(10)

Preview :

InfoDialog -> Customize

You can Customize your dialog UI. ReadMore.


NumberPickerDialog

Dialog with 1 Title, 1 Content, 1 Positif Button, 1 Negatif Button, 1 EditText, 1 Add Button, 1 Substract Button.

Code :

newNumberPickerDialog(getSupportFragmentManager())
.setLastValue(12)
.setTitle("ini title")
.setContent("ini content")
.onOkPressedCallBack(newNumberPickerDialog.OnOkPressed() {
@OverridepublicvoidonOkPressed(intvalue) {
Toast.makeText(MainActivity.this, "Nilai nya " + value, Toast.LENGTH_SHORT).show();
}
})
.onCancelPressedCallBack(newNumberPickerDialog.OnCancelPressed() {
@OverridepublicvoidonCancelPressed() {
Toast.makeText(MainActivity.this, "Cancel", Toast.LENGTH_SHORT).show();
}
})
.show();

To enable CanceledOnTouchOutside :

newNumberPickerDialog(getSupportFragmentManager())
.setCanceledOnTouchOutside(true)

Preview :

NumberPickerDialog -> Customize

You can Customize your dialog UI. ReadMore.


LoadingDialog

Dialog with 1 Title, 1 Animation Loading that you can use.

Code :

LoadingDialogloadingDialog = newLoadingDialog(getSupportFragmentManager())
.setContent("ini content");
loadingDialog.show();
loadingDialog.dismis();

Preview :

LoadingDialog -> Customize

You can Customize your dialog UI. ReadMore.


SingleDatePickerDialog

Dialog with Calender like in material.io that you can use to pick single date.

Code :

newSingleDatePickerDialog(getSupportFragmentManager())
.setTimeZone("GMT")
.setTitle("Pilih tanggal")
.setSelectedToday(true)
.setTimeFormat("dd/MM/yyyy") //pastikan polanya sama
.setStartDate("1/08/2020") //pastikan polanya sama
.setEndDate("31/12/2020") //pastikan polanya sama
.onOkPressedCallBack(newSingleDatePickerDialog.OnOkPressed() {
@OverridepublicvoidonOkPressed(Stringvalue) {
Toast.makeText(MainActivity.this, value, Toast.LENGTH_SHORT).show();
}
})
.build()
.show();
  • setTimeZone() optional . default value GMT.
  • setTimeFormat() optional. default value dd-MM-yyyy.
  • setStartDate() optional.
  • setEndDate() optional.

Preview :

SingleDatePickerDialog -> Customize

You can Customize your dialog UI. ReadMore.


MultiDatePickerDialog

Dialog with Calender like in material.io that you can use to pick date with range.

Code :

newMultiDatePickerDialog(getSupportFragmentManager())
.setTimeZone("GMT")
.setTitle("Pilih tanggal")
.setTimeFormat("dd/MM/yyyy") //pastikan 3 pola ini sama
.setStartDate("1/08/2020") //pastikan 3 pola ini sama
.setEndDate("31/12/2020") //pastikan 3 pola ini sama
.onOkPressedCallBack(newMultiDatePickerDialog.OnOkPressed() {
@OverridepublicvoidonOkPressed(StringfirstDate, StringsecondDate) {
Toast.makeText(MainActivity.this, firstDate + " - " + secondDate, Toast.LENGTH_SHORT).show();
}
})
.build()
.show();
  • setTimeZone() optional . default value GMT.
  • setTimeFormat() optional. default value dd-MM-yyyy.
  • setStartDate() optional.
  • setEndDate() optional.

Preview :

MultiDataPickerDialog -> Customize

You can Customize your dialog UI. ReadMore.


TimeDialog

Dialog with Calender like in material.io that you can use to pick date with range.

Code :

newTimeDialog(getSupportFragmentManager())
.setTitle("Time")
.setHour(17)
.setMinute(17)
.setTimeFormat(TimeFormat.CLOCK_24H) //TimeFormat.CLOCK_12H
.addOnPositiveButtonClickListener(newTimeDialogPositiveCallBack() {
@OverridepublicvoidtimeResult(inthours, intminutes) {
Toast.makeText(MainActivity.this, hours+":"+minutes, Toast.LENGTH_SHORT).show();
}
})
.build()
.show();
  • setTitle() optional . default value Pick Time.
  • setHour() optional. default value 0.
  • setMinute() optional. default value 0.
  • setTimeFormat() optional. default value TimeFormat.CLOCK_12H.

Preview :

TimeFormat.CLOCK_12HTimeFormat.CLOCK_24H

DebugDialog

Dialog for debug.

Code :

newDebugDialog(getSupportFragmentManager())
.setAnimationStyle(R.style.CustomDialogStyle)
.setContent(DumpJSON.msg1)
.onOkPressedCallBack(() -> {
//ok action
})
.show();

Example Code/App

Sample Code And App


Version

  • 1.0.5
    • First Release
  • 1.0.6
    • Add Custom Animation
  • 1.0.7
    • SetDefault Animation
  • 1.0.9
    • Fix Animation
  • 2.0.0
    • Enable or disable TextAllCaps
  • 2.0.1
    • Bugs Fixing
  • 2.0.2
    • add enable CanceledOnTouchOutside
  • 2.0.3
    • Bugs Fixing Style
  • 2.0.4
    • Color
  • 2.1.1
    • Add Auto Click
  • 2.1.2
    • Bug Fixing
  • 2.1.5
    • Bug Fixing
  • 2.1.6
    • Bug Fixing
  • 2.1.9
    • Bug Fixing
  • 2.2.1
    • Bug Fixing
  • 2.2.2
    • Change color method
  • 3.0.0
    • Support SDK 16
  • 3.1.0
    • Spesial Button Color Contained
  • 3.1.1
    • More Space Button Parent
  • 3.2.0
    • Time Picker
  • 3.2.1
    • Bug Fixing
  • 3.2.2
    • Bug Fixing
  • 3.2.3
    • Bug Fixing
  • 3.2.4
    • Remove Default Animation and Color
  • 3.2.5
    • Bug Color
  • 3.2.6
    • Bug Color
  • 3.2.7
    • Bug Color
  • 3.2.8
    • Bug Fixing
  • 3.2.9
    • Bug Fixing
  • 3.3.0
    • Remove Space From Button
  • 3.3.1
    • Add CharSequence to Title and Content
  • 3.3.2
    • Improve Space Between TextButton
  • 3.3.3
    • Spesial For Debug Dialog
  • 3.3.4
    • New Space
  • 3.3.5
    • Space
  • 3.3.7
    • Copy Text From DebugDialog
  • 3.3.8
    • Remove Dot

Contribution

You can sent your constibution to branchopen-pull.


Copyright 2020 M. Fadli Zein

Releases

Packages

Contributors

Languages