Git Product home page Git Product logo

cfalertdialog's Introduction

CFAlertDialog Android

Bintray Download Github All Releases Android Arsenal license Twitter URL

CFAlertDialog is a library that helps you display and customise alert dialogs on Android. It offers an adaptive UI support. It’s functionality is almost similar to the native AlertDialog.

You can also check out this library for  iOS here

Types of use cases:

Configuration options:

Requirements :

  • CFAlertDialog works on any device with Android API level 14 and above.

Install using gradle

In your project's build.gradle add the following under dependencies

compile 'com.crowdfire.cfalertdialog:cfalertdialog:1.1.0'

Usage :

The above shown alert types can easily be implemented using the code snippet given below by some small tweaks

// Create Alert using Builder
CFAlertDialog.Builder builder = new CFAlertDialog.Builder(this)
    .setDialogStyle(CFAlertDialog.CFAlertStyle.ALERT)
    .setTitle("You've hit the limit")
    .setMessage("Looks like you've hit your usage limit. Upgrade to our paid plan to continue without any limits.")
    .addButton("UPGRADE", -1, -1, CFAlertActionStyle.POSITIVE, CFAlertActionAlignment.END, (dialog, which) -> {
        Toast.makeText(BaseActivity.this, "Upgrade tapped", Toast.LENGTH_SHORT).show();
        dialog.dismiss();
    })
        
// Show the alert
builder.show();

Customisations :

Alert Type

The alert type will determine the position and animation style for the dialog. You may set this by calling the setAlertStyle method with any of the following values.

CFAlertStyle.NOTIFICATION,
CFAlertStyle.ALERT,
CFAlertStyle.BOTTOM_SHEET

The default type is ALERT.

Title and Message

You can set a custom title and message text in the alert, using the setTitle method on the builder (pass null if you don’t need them).

Title Color and Message Color

You can set a custom title and message text color in the alert, using the setTextColor on the builder.

Text Alignment

You can customise alignment of the title and message. Use the setTextGravity method on the builder with any of the following values:

Gravity.START,
Gravity.CENTER_HORIZONTAL,
Gravity.END
Background color

You can change the background (overlay) color of the alert using the method setBackgroundColor on the builder with the color of your choice.

Dismiss on background tap

This determines whether the Alert dialog is dismissed when user taps on the background. Use the method setCancelable with a boolean value. By default it is set to true. The user will be able to interactively swipe to dismiss the notification dialog if this field is true.

Dismiss automatically

The alert dialog can be dismissed automatically using the method setAutoDismissAfter(long duration).

Header / Footer

You can add header and footer to the dialog. Use the method setHeaderView and setFooterView with any custom View. You can also pass the layout resource directly into the header/footer. Pass null to remove any existing header/footer.

  1. Some examples where you can make the use of header in alert (the dollar image is in header)

builder.setHeaderView(R.layout.dialog_header_layout);
OR
builder.setHeaderView(headerView);
  1. Some examples where you can make the use of footer in alert

builder.setFooterView(R.layout.dialog_footer_layout);
OR
builder.setFooterView(footerView);
Dismiss Callback

You may set a callback when dialog is dismissed with the native setOnDismissListener on the alert object.

CFAlertDialog alertDialog = builder.show();
alertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
    @Override
    public void onDismiss(DialogInterface dialog) {
        
        // Do something here when dialog dismissed.
    }
});

Action Buttons

You may add as many action buttons with the required styles. Use the addButton method on the builder.

builder.addButton("UPGRADE", Color.parseColor("#FFFFFF"), Color.parseColor("#429ef4"), CFAlertActionStyle.POSITIVE, CFAlertActionAlignment.CENTER, new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
        Toast.makeText(context, "Upgrade tapped", Toast.LENGTH_SHORT).show();
        dialog.dismiss();
    }
});
Title

You can set the title of action button to be added.

Action Style

Configure the style of the action button that is to be added to alert view. Set style property of the above method with one of the following Action style

CFAlertActionStyle.DEFAULT,
CFAlertActionStyle.POSITIVE,
CFAlertActionStyle.NEGATIVE
Actions Alignment

Configure the alignment of the action button added to the alert view. Set alignment property of CFAction constructor with one of the following action types

CFAlertActionAlignment.START,   
CFAlertActionAlignment.END,
CFAlertActionAlignment.CENTER,
CFAlertActionAlignment.JUSTIFIED   // Action Button occupies the full width
Callback

Pass an onClickListener to receive callbacks when the action buttons are tapped.

Items

There are 3 types of list supported by default.

Simple List

This will show a simple list view and give a callback when any of the item is tapped.

CFAlertDialog.Builder builder = new CFAlertDialog.Builder(this);
builder.setDialogStyle(CFAlertDialog.CFAlertStyle.ALERT);
builder.setTitle("Select notification tone!");
builder.setItems(new String[]{"None", "Alert", "Delight", "Guitar", "Marbles", "Prompt"}, new OnClickListener() {
    @Override
    public void onClick(DialogInterface dialogInterface, int index) {
        Toast.makeText(context, "Selected:"+index, Toast.LENGTH_SHORT).show();
        dialogInterface.dismiss();
    }
});
builder.show();
Single Choice

This will show a list view with single choice items. It will give a callback when any of the items is selected.

CFAlertDialog.Builder builder = new CFAlertDialog.Builder(this);
builder.setDialogStyle(CFAlertDialog.CFAlertStyle.ALERT);
builder.setTitle("Select notification tone!");
builder.setSingleChoiceItems(new String[]{"None", "Alert", "Delight", "Guitar", "Marbles", "Prompt"}, 3, new OnClickListener() {
    @Override
    public void onClick(DialogInterface dialogInterface, int index) {
        Toast.makeText(context, "Selected:"+index, Toast.LENGTH_SHORT).show();
    }
});
builder.addButton("DONE", -1, -1, CFAlertActionStyle.POSITIVE, CFAlertActionAlignment.END, new OnClickListener() {
    @Override
    public void onClick(DialogInterface dialogInterface, int i) {
        dialogInterface.dismiss();
    }
});
builder.show();
Multiple choice

This will show a list view with multi choice items. It will give a callback when any item is selected/unselected.

CFAlertDialog.Builder builder = new CFAlertDialog.Builder(this);
builder.setDialogStyle(CFAlertDialog.CFAlertStyle.ALERT);
builder.setMessage("Select the topping for your pizza!!!");
builder.setMultiChoiceItems(new String[]{"Spinach", "Red & Yellow pepper", "Baby corn", "Olives", "Chicken"}, new boolean[]{false, false, false, false, false}, new DialogInterface.OnMultiChoiceClickListener() {
    @Override
    public void onClick(DialogInterface dialogInterface, int index, boolean b) {
        Toast.makeText(context, "Row:"+index+" "+(b? "Selected":"Unselected"), Toast.LENGTH_SHORT).show();
    }
});
builder.addButton("NEXT", -1, -1, CFAlertActionStyle.POSITIVE, CFAlertActionAlignment.END, new OnClickListener() {
    @Override
    public void onClick(DialogInterface dialogInterface, int i) {
        dialogInterface.dismiss();
    }
});
builder.show();

License

This code is distributed under the terms and conditions of the MIT license.

cfalertdialog's People

Contributors

neha-gehani avatar rahul-s avatar rishabh876 avatar vipinagrahari avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cfalertdialog's Issues

Adjustable dialog's width

New Issue Checklist

Issue Info

Info Value
Platform Name Android e.g. Android
Platform Version 8.0 e.g. 8.0
CFAlertDialog Version 1.3.0 e.g. 2.1.1
Integration Method gradle e.g. gradle / manually
Xcode Version Android Studio 3.4 e.g. Android Studio 2.3

Issue Description and Steps

Hi,
Is there any ways for me to adjust the dialog's width? Because it looks small on the big tablet like Samsung Galaxy Tab A 10.5".
Thank you in advance!

image

When can we expect support for AndroidX

As android has moved on to AndroidX. Old libraries that do not support AndroidX require an extra step during compilation - Jetifier.

Jetifier tool migrates support-library-dependent libraries to rely on the equivalent AndroidX packages instead. The tool lets you migrate an individual library directly, instead of using the Android gradle plugin bundled with Android Studio.

Jetifier takes extra time during compilation. Making it slow.

Most of the libraries have already moved on to AndroidX. But I can't remove Jetifier until and unless all libraries in my project have support for AndroidX.

When can we expect AndroidX support?

Prevent StatusBar from showing when using CFAlertDialog

My app is fullscreen activity.
when I show the alert dialog it displays status bar. after alert dialog goes away status bar is gone.
how can I prevent showing status bar?

on create method:

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

Also I set the values in my style:

    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>

Action buttons on same line

New Issue Checklist

Issue Info

Info Value
Platform Name Android
Platform Version 7.0
CFAlertDialog Version 1.2.0
Integration Method gradle
Xcode Version 3.0
Repro rate 100%
Repro with our demo prj Yes
Demo project link n/a

Issue Description and Steps

Buttons can't be placed next to each other. When I have two buttons and I align one to START and one to END they appear at the START and END position but below each other. When I give both buttons position END they are both at END but also below each other. Is it possible to put the buttons on the same line?

how to change font for message and text of btn??

New Issue Checklist

Issue Info

Info Value
Platform Name e.g. Android
Platform Version e.g. 6.0
CFAlertDialog Version e.g. 2.1.1
Integration Method e.g. gradle / manually
Xcode Version e.g. Android Studio 2.3
Repro rate e.g. all the time (100%) / sometimes x% / only once
Repro with our demo prj e.g. does it happen with our demo project?
Demo project link e.g. link to a demo project that highlights the issue

Issue Description and Steps

Please fill in the detailed description of the issue (full output of any stack trace, compiler error, ...) and the steps to reproduce the issue.

prompt dialog - feature request

New Issue Checklist

Issue Info

Info Value
Platform Name e.g. Android
Platform Version e.g. 6.0
CFAlertDialog Version e.g. 2.1.1
Integration Method e.g. gradle / manually
Xcode Version e.g. Android Studio 2.3
Repro rate e.g. all the time (100%) / sometimes x% / only once
Repro with our demo prj e.g. does it happen with our demo project?
Demo project link e.g. link to a demo project that highlights the issue

Issue Description and Steps

This is just a feature request, for an edit text component with a callback response for the text entered. Like prompt dialogs

Landscape mode

Hi,
When I show the alert dialog in landscape mode (app works in just landscape mode for tablets), it is shown in small size on the left side. its not centered.
tablet: Sony Experia Tablet S 1280x800

How can I center the CFAlertDialog in landscape mode?

Dialog fragment

New Issue Checklist

Issue Info

Info Value
Platform Name e.g. Android
Platform Version e.g. 6.0
CFAlertDialog Version e.g. 2.1.1
Integration Method e.g. gradle / manually
Xcode Version e.g. Android Studio 2.3
Repro rate e.g. all the time (100%) / sometimes x% / only once
Repro with our demo prj e.g. does it happen with our demo project?
Demo project link e.g. link to a demo project that highlights the issue

Issue Description and Steps

Please fill in the detailed description of the issue (full output of any stack trace, compiler error, ...) and the steps to reproduce the issue.

not full screen in android R

Platform Name Android
Platform Version R
CFAlertDialog Version 1.3.1
Integration Method |gradle
Xcode Version | Android Studio 3.5.5
Repro rate all the time (100%)

The background doesn't fill the whole screen
image

App Crashes when adding editText.

This is what I can see in the logs when the app crashes --

2018-12-02 17:40:38.969 30579-30579/com.example.app W/View: requestLayout() improperly called by android.widget.FrameLayout{c0d8a68 VFE...C.. ......ID 0,0-168,168 #7f080036 app:id/button} during layout: running second layout pass

bintray propertie error when importing

New Issue Checklist

Issue Info

Info Value
Platform Name e.g. Android
Platform Version e.g. 6.0
CFAlertDialog Version e.g. 2.1.1
Integration Method e.g. gradle / manually
Xcode Version e.g. Android Studio 2.3
Repro rate e.g. all the time (100%) / sometimes x% / only once
Repro with our demo prj e.g. does it happen with our demo project?
Demo project link e.g. link to a demo project that highlights the issue

Issue Description and Steps

Please fill in the detailed description of the issue (full output of any stack trace, compiler error, ...) and the steps to reproduce the issue.

error when trying to compile
properties.load(project.rootProject.file('bintray.properties').newDataInputStream())
does not exist

changing back to
properties.load(project.rootProject.file('local.properties').newDataInputStream())
compiles

any clue why this is happenning?

[FR] alertPresented callback

Could you add a onPresented callback ?

I could use that to deffer heavy action after presentation and not to have hickups during animations.

thanks

Crash when using a header

When using a header, I'm getting this crash. I'm running Android 12. The dialog opens fine once, but once dismissed and opened again, it crashes with this:

java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
at android.view.ViewGroup.addViewInner(ViewGroup.java:6084)
at android.view.ViewGroup.addView(ViewGroup.java:5903)
at android.view.ViewGroup.addView(ViewGroup.java:5860)
at com.crowdfire.cfalertdialog.CFAlertDialog.setHeaderView(CFAlertDialog.java:436)
at com.crowdfire.cfalertdialog.CFAlertDialog.populateCardView(CFAlertDialog.java:232)
at com.crowdfire.cfalertdialog.CFAlertDialog.createCardView(CFAlertDialog.java:162)
at com.crowdfire.cfalertdialog.CFAlertDialog.setupSubviews(CFAlertDialog.java:126)
at com.crowdfire.cfalertdialog.CFAlertDialog.onCreate(CFAlertDialog.java:109)
at android.app.Dialog.dispatchOnCreate(Dialog.java:810)
at android.app.Dialog.show(Dialog.java:453)
at com.crowdfire.cfalertdialog.CFAlertDialog.show(CFAlertDialog.java:274)
at com.crowdfire.cfalertdialog.CFAlertDialog$Builder.show(CFAlertDialog.java:1079)

font-family

Can i change the font-family of the dialog elements?

how to implement adding Edittext

New Issue Checklist

Issue Info

Info Value
Platform Name e.g. Android
Platform Version e.g. 6.0
CFAlertDialog Version e.g. 2.1.1
Integration Method e.g. gradle / manually

Issue Description and Steps

how to implement adding Edittext and retrieve data to activity.

lambda operator not supported in java 8

New Issue Checklist

Issue Info

Info Value
Platform Name e.g. Android
Platform Version e.g. 6.0
CFAlertDialog Version e.g. 2.1.1
Integration Method e.g. gradle / manually
Xcode Version e.g. Android Studio 2.3
Repro rate e.g. all the time (100%) / sometimes x% / only once
Repro with our demo prj e.g. does it happen with our demo project?
Demo project link e.g. link to a demo project that highlights the issue

Issue Description and Steps

Please fill in the detailed description of the issue (full output of any stack trace, compiler error, ...) and the steps to reproduce the issue.

Getting rid of statusbar color override?

New Issue Checklist

Issue Info

Info Value
Platform Name Android
Platform Version 9.0
CFAlertDialog Version 1.1.0
Integration Method gradle
IDE Version Android Studio 3.3
Repro rate all the time (100%)
Repro with our demo prj does it happen with our demo project? - YES
Demo project link link to a demo project that highlights the issue

Issue Description and Steps

Hi, great library. Could someone please tell me how do I get rid of the statusbar color getting override? Stock alertDialog doesn't touch or do anything to it which gives a seamless feel but this library makes it light gray which looks bad, especially since my app uses AMOLED dark UI.

Couldn't find the option so opening an issue. Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.