A powerful library for creating notifications in android platform.

Overview

Android Arsenal Maven Central Build Status Coverage Status Join the chat at https://gitter.im/halysongoncalves/pugnotification

soon

Download

Download the latest AAR or grab via Maven:

<dependency>
  <groupId>com.github.halysongoncalves</groupId>
  <artifactId>pugnotification</artifactId>
  <version>1.8.1</version>
</dependency>

or Gradle:

compile 'com.github.halysongoncalves:pugnotification:1.8.1'

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. Magic? Lie? I summarize in: productivity. To further improve productivity, pugnotification from release 1.2.0 now has support Android Wear.

PugNotification.with(context)
    .load()
    .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();

Many common pitfalls in building cases are handled automatically by PugNotification:

Custom Notifications depend on RemoteViews and Android has RemoteView support for Api's below Jelly Bean. Notifications without no messages and title does not make sense there. In addition to these treatments, there are other held by Picasso Library Square:

Handling ImageView recycling and download cancelation in an adapter. Complex image transformations with minimal memory use. Automatic memory and disk caching.

Simple Notification

Simple notification with just text and message.

PugNotification.with(context)
    .load()
    .title(title)
    .message(message)
    .bigTextStyle(bigtext)
    .smallIcon(R.drawable.pugnotification_ic_launcher)
    .largeIcon(R.drawable.pugnotification_ic_launcher)
    .flags(Notification.DEFAULT_ALL)
    .simple()
    .build();

Progress Notification

Simple notification with progress.

PugNotification.with(context)
    .load()
    .identifier(identifier)
    .smallIcon(R.drawable.pugnotification_ic_launcher)
    .progress()
    .value(progress,max, indeterminate)
    .build();
PugNotification.with(context)
    .load()
    .identifier(identifier)
    .smallIcon(R.drawable.pugnotification_ic_launcher)
    .progress()
    .update(identifier,progress,max, indeterminate)
    .build();

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:

PugNotification.with(context)
    .load()
    .title(title)
    .message(message)
    .bigTextStyle(bigtext)
    .smallIcon(R.drawable.pugnotification_ic_launcher)
    .largeIcon(R.drawable.pugnotification_ic_launcher)
    .flags(Notification.DEFAULT_ALL)
    .color(android.R.color.background_dark)
    .custom()
    .background(url)
    .setImageLoader(Callback)
    .setPlaceholder(R.drawable.pugnotification_ic_placeholder)
    .build();  

Wear Notification

PugNotification from release 1.2.0 started to support all types of notifications to Android Wear. We try to anticipate us to make life easier for developers to develop applications for wearable.

PugNotification.with(mContext).load()
    .smallIcon(R.drawable.pugnotification_ic_launcher)
    .autoCancel(true)
    .largeIcon(R.drawable.pugnotification_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();

What's New

*1.8.1

Fix Message Spanned length check

*1.8.0

Adding method for cancellation in tag-based notifications. And added validation to ensure that the color assigned in the method is @ColorRes.

*1.7.0

Added a new type of notification, progress. Now you can assign the basic features of a notification, while also adding a progressbar in the notification.

It was also added new method: ongoing (). With it possible to make false removing the notification.

*1.6.0

Fixed bug that did not allow the award of a sound and made some organizations and otimizaçnoes the code.

Now it is necessary to set one of the flag's: Notification.DEFAULT_ALL, Notification.DEFAULT_SOUND, Notification.DEFAULT_VIBRATE or Notification.DEFAULT_LIGHTS

*1.5.0

Method has been added that allows informing the existing configuration of the default notice. By default it is already configured with Notification.DEFAULT_ALL if you want to change just inform the new configuration in the defaults method (int defaults).

*1.4.0

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) {
            }
        };
    }

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

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.**

Contributing

If you would like to contribute code you can do so through GitHub by forking the repository and sending a pull request.

When submitting code, please make every effort to follow existing conventions and style in order to keep the code as readable as possible. Please also make sure your code compiles by running gradlew clean and gradlew assemble.

License

Copyright 2013 Halyson L. Gonçalves, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Comments
  • Image problem: drawable-nodpi\pugnotification_ic_placeholder.png

    Image problem: drawable-nodpi\pugnotification_ic_placeholder.png

    AAPT err(Facade for 1388311168): D:\Test\app\build\intermediates\exploded-aar\com.github.halysongoncalves\pugnotification\1.8.0\res\drawable-nodpi\pugnotification_ic_placeholder.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited.

    DONE 
    opened by hateum 5
  • Can I add FLAG_NO_CLEAR

    Can I add FLAG_NO_CLEAR

    Can I write this with pugnotification library ?

    Notification noti = new NotificationCompat.Builder(this).setContentTitle("Title").setSmallIcon(R.drawable.icon).build();
    noti.flags |= Notification.FLAG_NO_CLEAR;
    nm.notify(MAIN_NOTIFICATION, noti);
    
    DONE 
    opened by sytolk 5
  • Making an option to not use large icon in PugNotification

    Making an option to not use large icon in PugNotification

    Not setting a default LargeIcon, to make an option to use or not use a large icon in notification. Otherwise I'll get an Android icon (R.drawable.pugnotification_ic_launcher) plus smallIcon in notification.

    I tested it in Sample App and it works. Just comment .largeIcon() line in PugNotification builder to test.

    Review on Reviewable

    DONE 
    opened by burnermanx 5
  • Allow library to load large icon bitmap

    Allow library to load large icon bitmap

    What do you think about having the library taken care of the bitmap decoding for the large icon ?

    I was thinking that maybe you can overload the method, something like the following:

    public class Load {
    
        // Current method
        public Load largeIcon(Bitmap bitmap ) {
          ...
        }
    
        // New method
        public Load largeIcon(int largeIcon) {
            if (largeIcon <= 0) {
                throw new IllegalArgumentException("Resource ID Should Not Be Less Than Or Equal To Zero!");
            }
            Bitmap bitmap = BitmapFactory.decodeResource( 
                   mNotification.mContext.getResources(), largeIcon )
            this.mBuilder.setLargeIcon(bitmap);
            return this;
        }
    

    Would you take a PR for this ?

    DONE 
    opened by robertoestivill 5
  • Buttons not showing in custom notification

    Buttons not showing in custom notification

    This works fine and show the buttons: PugNotification.with(this) .load() .title(...) .message(...) .smallIcon(...) .largeIcon(..) .button(...), .button(...) .simple() .build();

    This doesn't: PugNotification.with(this) .load() .title(...) .message(...) .smallIcon(...) .largeIcon(..) .button(...), .button(...) .custom() .build();

    BACKLOG 
    opened by Shailevy 4
  • Add additional flags to Simple

    Add additional flags to Simple

    You can write

    FlagNotification.with(this).load()
                    .identifier(MAIN_NOTIFICATION)
                    .smallIcon(R.drawable.icon)
                    .autoCancel(false)
                    .largeIcon(R.drawable.icon)
                    .title("Title")
                    .simple()
                    .build(Notification.FLAG_NO_CLEAR);
    
    

    Review on Reviewable

    DONE 
    opened by sytolk 3
  • Is it possible to use an image loading library other than Picasso ?

    Is it possible to use an image loading library other than Picasso ?

    I'm using UIL in my application, and I don't want to add Picasso as a dependency.

    Perhaps it is a good idea to add an interface for customizing the image loading operations ?

    Something like

    interface ImageLoader {
          public void load(String url, Drawable placeholder, Notification target);
    }
    
    DONE 
    opened by R4md4c 3
  • start a service on click

    start a service on click

    When passing activity to click it works without an issue, but if I pass an service class to it, it just doesn't fire.

    Any ideas?

    here's my code:

    
    PugNotification.with(this)
                    .load()
                    .largeIcon(R.drawable.ic_notif)
                    .smallIcon(R.drawable.ic_notif_small)
                    .title("Start Service")
                    .message("in background")
                    .click(MyService.class)
                    .simple()
                    .build();
    

    Manifest:

    
    <service
                android:name=".MyService"
                android:enabled="true"
                android:exported="true"/>
    
    DONE 
    opened by eboye 2
  • Notification Progress for indeterminate progress

    Notification Progress for indeterminate progress

    Is there any way to have a progress notification with an indeterminate progress? Something which just says loading with an google indeterminate progressbar as below?

    https://github.com/DreaminginCodeZH/MaterialProgressBar

    DONE 
    opened by GeorgeChackungal 2
  • Fix messageSpanned length check

    Fix messageSpanned length check

    When you pass a messageSpanned, the method checks message member and not the messageSpanned parameter which is not correct and causes null pointer exception

    Review on Reviewable

    DONE 
    opened by aminelaadhari 2
  • Fix messageSpanned length check

    Fix messageSpanned length check

    When you pass a messageSpanned, the method checks message member and not the messageSpanned parameter which is not correct and causes null pointer exception

    Review on Reviewable

    opened by aminelaadhari 2
  • Is this library still managed ?

    Is this library still managed ?

    I have seen lots of issues regarding Oreo channel integration using PugNotification , so is it working , i am considering to use this in my production app

    opened by Zulqurnain 1
  • java.lang.IllegalStateException: Method call should happen from the main thread

    java.lang.IllegalStateException: Method call should happen from the main thread

    I am trying the following code to show Custom Notification but the app is crashing giving java.lang.IllegalStateException: Method call should happen from the main thread.

    PendingIntent pendingIntent;
            String url = data.get(CommonConsts.NOTIFICATION_KEY_URL);
            String thumbUrl = data.get(CommonConsts.THUMB_URL_KEY);
    
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    
            // Use TaskStackBuilder to build the back stack and get the PendingIntent
            pendingIntent =
                    TaskStackBuilder.create(this)
                            // add all of DetailsActivity's parents to the stack,
                            // followed by DetailsActivity itself
                            .addNextIntentWithParentStack(browserIntent)
                            .getPendingIntent(0, PendingIntent.FLAG_ONE_SHOT);
    
            Custom mLoad = null;
            if (pendingIntent != null) {
                mLoad = PugNotification.with(getBaseContext()).load()
                        .smallIcon(R.mipmap.ic_launcher)
                        .autoCancel(true)
                        .largeIcon(R.mipmap.ic_launcher)
                        .title(title == null ? this.getString(R.string.app_name) +
                                " Alert" : title)
                        .message(messageBody)
                        .bigTextStyle(messageBody, messageBody)
                        .priority(Notification.PRIORITY_MAX)
                        .flags(Notification.DEFAULT_ALL)
                        .when(1)
                        .button(R.drawable.ic_chrome_reader_mode_black_18dp, getString(R.string.read_more), pendingIntent)
                        .click(pendingIntent)
                        .custom()
                        .setImageLoader(new ImageLoader() {
                            @Override
                            public void load(String uri, OnImageLoadingCompleted onCompleted) {
                                viewTarget = getViewTarget(onCompleted);
                                Picasso.with(getBaseContext()).load(uri).into(viewTarget);
                            }
    
                            @Override
                            public void load(int imageResId, OnImageLoadingCompleted onCompleted) {
    
                            }
                        })
                        .setPlaceholder(R.drawable.pugnotification_ic_placeholder)
                        .background(thumbUrl);
            }
    
            if (mLoad != null) {
                mLoad.build();
            }
    
    Complete Exception:
    Process: psl99.com.pakistan_super_league, PID: 19021
    java.lang.IllegalStateException: Method call should happen from the main thread. at br.com.goncalves.pugnotification.notification.Custom.build(Custom.java:119) at psl99.com.pakistan_super_league.services.MyFirebaseMessagingService.showNewsArticleNotification(MyFirebaseMessagingService.java:276) at psl99.com.pakistan_super_league.services.MyFirebaseMessagingService.sendNotification(MyFirebaseMessagingService.java:150)
    atpsl99.com.pakistan_super_league.services.MyFirebaseMessagingService.onMessageReceived(MyFirebaseMessagingService.java:111)
    at com.google.firebase.messaging.FirebaseMessagingService.handleIntent(Unknown Source)
    at com.google.firebase.iid.zzc.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
    at java.lang.Thread.run(Thread.java:762)
    
    opened by Shajeel-Afzal 0
  • Image Loading with Glide

    Image Loading with Glide

    Thanks for creating this awesome Library for showing Push Notifications. Can you please tell us how to use Glide with this library instead of Picasso?

    Regards

    • Shajeel
    opened by Shajeel-Afzal 0
  • Vibrate with prefrence Screen

    Vibrate with prefrence Screen

    hi i set a setting with a boolean on it means notiffication have vibrate and off it means vibrate is off but its not working on vibrate off this is my code public class AlarmReceiver extends BroadcastReceiver { long[] vibrate; @Override public void onReceive(Context context, Intent intent) { SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context); String alarm = pref.getString("key_notifications_new_message_ringtone","default ringtone"); Uri uri = Uri.parse(alarm); boolean vibre = pref.getBoolean("key_vibrate",false); if (vibre){ vibrate = new long[] {200,700}; }else { vibrate = new long[] {0,0}; } { Bundle bundle = intent.getExtras(); String name = bundle.getString("name"); String id = bundle.getString("tourId"); PugNotification.with(context) .load() .title("name") .message("id") .bigTextStyle("bigtext") .smallIcon(R.drawable.pugnotification_ic_launcher) .largeIcon(R.drawable.pugnotification_ic_launcher) .sound(uri) .autoCancel(true) .vibrate(vibrate) .simple() .build(); } } and this is the error i just want to off the vibrate with this switch java.lang.RuntimeException: Unable to start receiver app.mma.PokerInfo.exTourList.AlarmReceiver: java.lang.IllegalArgumentException: Vibrate Time 0 Invalid!

    opened by osairon 0
Owner
Halyson Lima Gonçalves
Graduated in Information Systems from UFV (Federal University of Viçosa), I have more than 8 years of experience in Mobile Development.
Halyson Lima Gonçalves
This is a library to help creating expanding views with animation in Android

About the Library inspiration This library is strongly inspired in this concept from Hila Peleg in dribble. See it below Working example For more deta

Diego Bezerra 944 Dec 27, 2022
Android library for creating an expandable to full screen view inside a viewgroup composition.

Expandable Panel Android Library Check ExpandablePanel Demo application on GooglePlay: Details This Android library implements the expand by sliding l

Jorge Castillo 422 Nov 10, 2022
Android Material Json Form Wizard is a library for creating beautiful form based wizards within your app just by defining json in a particular format.

Android Json Wizard Android Json Wizard is a library for creating beautiful form based wizards within your app just by defining json in a particular f

Vijay Rawat 355 Nov 11, 2022
Library for creating blur effects under Android UI elements

BlurTutorial Meet BlurTutorial, an Android-based library made by Cleveroad Hurry to check our newest library that helps to blur the background in Andr

Cleveroad 150 Dec 16, 2022
⚡️A highly customizable, powerful and easy-to-use alerting library for Android.

Flashbar A highly customizable, powerful and easy-to-use alerting library for Android. Specs This library allows you to show messages or alerts in you

Aritra Roy 1.7k Dec 7, 2022
Simple and powerful library to emulate iOS's "3D Touch" preview functionality on Android.

Android 3D Touch - PeekView iOS uses 3D Touch as a way to "peek" into full content, such as emails, pictures, web searches, etc. While they have dedic

Luke Klinker 502 Dec 29, 2022
GreenDroid is a development library for the Android platform. It makes UI developments easier and consistent through your applications.

#GreenDroid Foreword : This project, initially initiated by me, Cyril Mottier, is not maintained anymore and can be considered as deprecated. As a con

Cyril Mottier 2.6k Jan 4, 2023
Dynamic Speedometer and Gauge for Android. amazing, powerful, and multi shape :zap:

SpeedView Dynamic Speedometer, Gauge for Android. amazing, powerful, and multi shape ⚡ , you can change (colors, bar width, shape, text, font ...every

Anas Altair 1.2k Jan 3, 2023
WizardTower - What will eventually be a Roguelike about being a powerful wizard, with a tower.

Wizard Tower Roguelike by sgibber2018 Description: This is a Roguelike I've been wanting to make for a long time. The premise is really simple: you ar

Sam Gibson 0 Jan 5, 2022
This is a sample Android Studio project that shows the necessary code to create a note list widget, And it's an implementation of a lesson on the Pluralsight platform, but with some code improvements

NoteKeeper-Custom-Widgets This is a sample Android Studio project that shows the necessary code to create a note list widget, And it's an implementati

Ibrahim Mushtaha 3 Oct 29, 2022
Multi Roots TreeView implementation for Android Platform with a lot of options and customization

Multi roots TreeView :palm_tree: implementation for Android Platform with a lot of options and customization

Amr Hesham 112 Jan 3, 2023
Beagle is an open-source framework for cross-platform development using the concept of Server-Driven UI.

Beagle Getting Started · Learn the Basics · Contribute Beagle is an open-source framework for cross-platform development using the concept of Server-D

ZUP IT INNOVATION 657 Dec 28, 2022
A new canvas drawing library for Android. Aims to be the Fabric.js for Android. Supports text, images, and hand/stylus drawing input. The library has a website and API docs, check it out

FabricView - A new canvas drawing library for Android. The library was born as part of a project in SD Hacks (www.sdhacks.io) on October 3rd. It is cu

Antwan Gaggi 1k Dec 13, 2022
Android StackBlur is a library that can perform a blurry effect on a Bitmap based on a gradient or radius, and return the result. The library is based on the code of Mario Klingemann.

Android StackBlur Android StackBlur is a library that can perform a blurry effect on a Bitmap based on a gradient or radius, and return the result. Th

Enrique López Mañas 3.6k Dec 29, 2022
Android library providing bread crumbs to the support library fragments.

Hansel And Gretel Android library providing bread crumbs for compatibility fragments. Usage For a working implementation of this project see the sampl

Jake Wharton 163 Nov 25, 2022
Android library used to create an awesome Android UI based on a draggable element similar to the last YouTube graphic component.

Draggable Panel DEPRECATED. This project is not maintained anymore. Draggable Panel is an Android library created to build a draggable user interface

Pedro Vicente Gómez Sánchez 3k Dec 6, 2022
TourGuide is an Android library that aims to provide an easy way to add pointers with animations over a desired Android View

TourGuide TourGuide is an Android library. It lets you add pointer, overlay and tooltip easily, guiding users on how to use your app. Refer to the exa

Tan Jun Rong 2.6k Jan 5, 2023
Bubbles for Android is an Android library to provide chat heads capabilities on your apps. With a fast way to integrate with your development.

Bubbles for Android Bubbles for Android is an Android library to provide chat heads capabilities on your apps. With a fast way to integrate with your

Txus Ballesteros 1.5k Jan 2, 2023
Wizard Pager is a library that provides an example implementation of a Wizard UI on Android, it's based of Roman Nurik's wizard pager (https://github.com/romannurik/android-wizardpager)

Wizard Pager Wizard Pager is a library that provides an example implementation of a Wizard UI on Android, it's based of Roman Nurik's wizard pager (ht

Julián Suárez 520 Nov 11, 2022