ZadakNotification

Re - Coding Pug Notification for support notification in Android Oreo.

ZadakNotification

Download

Step 1:

Add it in your root build.gradle at the end of repositories:

allprojects {
		repositories {
			maven { url 'https://jitpack.io' }
		}
	}
Groovy

Step 2:

Add the dependency:

 implementation 'com.github.mehrdadsafari:ZadakNotification:0.0.2'
Groovy

Introduction

Screenshots

You're probably tired of writing code to display notifications in your applications, the library abstracts all the notifications construction process for you in a single line of code. this library support Android Wear.

ZadakNotification.with(context)
    .load()
    .notificationChannelId(CHANNEL_ID)
    .identifier(identifier)
    .title(title)
    .message(message)
    .bigTextStyle(bigtext)
    .smallIcon(smallIcon)
    .largeIcon(largeIcon)
    .flags(Notification.DEFAULT_ALL)
    .button(icon, title, pendingIntent)
    .click(cctivity, bundle)
    .dismiss(activity, bundle)
    .color(color)
    .ticker(ticker)
    .when(when)
    .vibrate(vibrate)
    .lights(color, ledOnMs, ledOfMs)
    .sound(sound) 
    .autoCancel(autoCancel)
    .simple()
    .build();
Java

Simple Notification

Simple notification with just text and message.

ZadakNotification.with(context)
    .load()
    .notificationChannelId(CHANNEL_ID)
    .title(title)
    .message(message)
    .bigTextStyle(bigtext)
    .smallIcon(R.drawable.ic_launcher)
    .largeIcon(R.drawable.ic_launcher)
    .flags(Notification.DEFAULT_ALL)
    .simple()
    .build();
Java

Progress Notification

Simple notification with progress.

ZadakNotification.with(context)
    .load()
    .notificationChannelId(CHANNEL_ID)
    .identifier(identifier)
    .smallIcon(R.drawable.ic_launcher)
    .progress()
    .value(progress,max, indeterminate)
    .build();
Java
ZadakNotification.with(context)
    .load()
    .notificationChannelId(CHANNEL_ID)
    .identifier(identifier)
    .smallIcon(R.drawable.ic_launcher)
    .progress()
    .update(identifier,progress,max, indeterminate)
    .build();
Java

Custom Notification

We have changed the way the library handles the download images for custom notifications. Previously disrespectfully because of the Picasso library. But many users were asking for the option of being able to choose how to download the image.
So we serve the requests and modify the library to allow the download of image management as an example:

ZadakNotification.with(context)
    .load()
    .notificationChannelId(CHANNEL_ID)
    .title(title)
    .message(message)
    .bigTextStyle(bigtext)
    .smallIcon(R.drawable.ic_launcher)
    .largeIcon(R.drawable.ic_launcher)
    .flags(Notification.DEFAULT_ALL)
    .color(android.R.color.background_dark)
    .custom()
    .background(url)
    .setImageLoader(Callback)
    .setPlaceholder(R.drawable.ic_placeholder)
    .build();  
Java

Wear Notification

ZadakNotification.with(mContext).load()
    .notificationChannelId(CHANNEL_ID)
    .smallIcon(R.drawable.ic_launcher)
    .autoCancel(true)
    .largeIcon(R.drawable.ic_launcher)
    .title(title)
    .message(message)
    .bigTextStyle(bigtext)
    .flags(Notification.DEFAULT_ALL)
    .wear()
    .background(Bitmap)
    .setRemoteInput(icon, title, pendingIntent, remoteInput)
    .setPages(List<Notification> listNotification)
    .setHideIcon(Boolean)
    .build();
Java

Now just the client implement the ImageLoader interface and implement a way to manage the download of the image. Below we use the Picasso:

    @Override
    public void load(String uri, final OnImageLoadingCompleted onCompleted) {
        viewTarget = getViewTarget(onCompleted);
        Picasso.with(this).load(uri).into(viewTarget);
    }
    
    private static Target getViewTarget(final OnImageLoadingCompleted onCompleted) {
        return new Target() {
            @Override
            public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                onCompleted.imageLoadingCompleted(bitmap);
            }

            @Override
            public void onBitmapFailed(Drawable errorDrawable) {
            }

            @Override
            public void onPrepareLoad(Drawable placeHolderDrawable) {
            }
        };
    }
Java

ZadakNotification supports placeholders if download the image in the background is not successful. The library already have a default placeholder size 622x384.

Important note

For disable the swipe delete notification use

.setOngoing(true)

Cancel Notification

ZadakNotification.with(mContext).cancel(identifier);

ProGuard

If you use the Picasso to manage the download of the image, add the line below to your proguard file:

-dontwarn com.squareup.okhttp.**

GitHub