halysongoncalves / pugnotification Goto Github PK
View Code? Open in Web Editor NEWA powerful library for creating notifications in android platform.
Home Page: http://halysongoncalves.github.io/Pugnotification
License: Apache License 2.0
A powerful library for creating notifications in android platform.
Home Page: http://halysongoncalves.github.io/Pugnotification
License: Apache License 2.0
How to make notification without vibration e without sound
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();
Load#color(int)
throws an exception if the provided resource ID is less than or equal to 0. If it isn't, it propagates the input as-is to NotificationCompat.Builder#setColor(int)
. However, the latter method requires a resolved color, not a color resource ID!
Please handle color resources correctly, just like in Load#ticket(int)
. I'm proposing to change this:
public Load color(int color) {
if (color <= 0) {
throw new IllegalArgumentException("Resource ID Should Not Be Less Than Or Equal To Zero!");
}
this.builder.setColor(color);
return this;
}
to this:
public Load color(@ColorRes int color) {
if (color <= 0) {
throw new IllegalArgumentException("Resource ID Should Not Be Less Than Or Equal To Zero!");
}
this.builder.setColor(PugNotification.mSingleton.mContext.getResources().getColor(color));
return this;
}
Once #1 is resolved, we can add coveralls.io support to it.
Is it possible to use a custom wear notification, using Picasso for the image loading?
How can i update the notification progress bar..
and as well as notification text
It seems the "Big Text" box is looking for a particular big text style and one is not provided by default so we'll see a crash "Big Text Style Must Not Be Empty!". It's not immediately clear what style should be referenced, but working code or a default value would be great.
@halysongoncalves How dowe set notification's on click event !
The sample code doesn't specify it !
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);
}
Hi,
Thanks for this useful library.
I have an IntentService which needs to be started in foreground. I could not find a way to get access to the underlying notification object. If I could have it, I can just pass it to the startForeground of my IntentService. Not having access to the same seems a bit limiting.
-Ankit
The project website should have it's own repo and should be renamed to pugnotification.github.io or anything that denotes the URL to it.
The project pugnotification-sample should be on it's own repo.
It'd be great to add support for features of notifications introduced in Android N .
Namely, RemoteInputs-quick reply and quick actions.
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"/>
Hi
TnQ for this great library.
can u add rtl support for this lib?
Lots of ignored files are pushed onto the repo, exclude them.
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);
I have a question:
Is possible handle the notifications, for example if the user touch one notification, open or continue with another process?
I was reading your code, but I can't found how I could handle the notification
:)
Is it possible to use a custom loader with the largeIcon
option?
I want to load my image from the backend with a custom loader for the icon, but I could not find a way of doing it with custom loader.
Is there any method to set repeating to the AlarmManager, so the notification can be displayed each week on a specific day for example ?
is it possible to make mupltiple notifiactions from an app at the same time...?
Could we do this somehow ?
As with twitter, where you can see the tweet message icon as large icon of the notification.
I put a mp3 in a res/raw
directory
Then
PugNotification.with(getApplicationContext())
.load()
.title(item.getBottle().getName())
.message("Encore un vin dégusté par " + item.getUser().getName())//" + "\n" + item.getBottle().getName()) +"de "+item.getBottle().getVintage() +" en "+ new WineColor(Integer.parseInt(item.getBottle().getColor())).getColorToString() +
.bigTextStyle(item.getUser().getName() + " à dégusté un " + new WineColor(Integer.parseInt(item.getBottle().getColor())).getColorToString() + " nommé " + item.getBottle().getName() + " et lui à donné la note de " + item.getTasting().getRate())
.smallIcon(R.drawable.icon_notif)
.largeIcon(b)
.color(R.color.interaction)
.flags(Notification.DEFAULT_SOUND)
.sound(Uri.parse("android.resource://" + App.getContext().getPackageName() + "/" + R.raw.tire_bouchon3))
.custom()
.setImageLoader(NotificationService.this)
.background(item.getBottle().getLabelPicturePath())
.setPlaceholder(R.drawable.pugnotification_ic_placeholder)
.build();
Did I miss something ?
There's nothing in the library showing the correct way to use the API to pass the intent for clicks. It seems there's more to just calling Load.click(someActivity.class)
since I've tried calling that in the sample code to no avail:
PugNotification.with(mContext).load()
.title(title)
.message(message)
.bigTextStyle(bigtext)
.smallIcon(R.drawable.pugnotification_ic_launcher)
.largeIcon(R.drawable.pugnotification_ic_launcher)
.color(android.R.color.background_dark)
.click(SampleActivity.class)
.custom()
.setImageLoader(SamplePugNotification.this)
.background(url)
.setPlaceholder(R.drawable.pugnotification_ic_placeholder)
.build();
I will be reading more about it, but it'd be nice to have a working example of this in the sample.
Is it possible to use a custom xml layout for the Notification?
self explanatory.
The signature for Load.bigTextStyle()
seems to have been copy pasted a few times to many and we have argument variables claiming to be bigTextStyle
(as if a style resource) when it is in fact the big text.
If i create a notification in a service, which then starts an activity, how can I clear the notification in the activity if the notification isn't required anymore?
Line 8 of PugNotification: public static PugNotification mSingleton = null;
gives a warning:
Do not place Android context classes in static fields; this is a memory leak (and also breaks Instant Run)
A static field will leak contexts.
Any plans to address?
How to lock notification on status bar?
I using this configuration:
PugNotification.with(context).load()
.smallIcon(R.drawable.default_icon)
.title(push.title)
.autoCancel(true)
.message(push.alert)
.flags(Notification.DEFAULT_ALL | Notification.FLAG_AUTO_CANCEL)
.click(pIntent)
.simple().build();
But I can't to lock (fix) notification on status bar, so after swiping I can remove it.
This feature is working on my custom notification:
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder
.setSmallIcon(R.drawable.status_bar_icon)
.setWhen(System.currentTimeMillis())
.setAutoCancel(true)
.setContentTitle(appName)
.setContentText(text)
.setLights(0xffffffff, 1000, 3000)
.setPriority(Notification.PRIORITY_HIGH)
.setContentIntent(pIntent);
builder.setVibrate(new long[]{500, 500, 250, 250, 250, 250, 250});
Notification notification = builder.build();
if (LOCK_MODE)
notification.flags |= Notification.FLAG_AUTO_CANCEL;
NotificationManager manager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(1, notification);
Is it possible to set the notification to be fired on specified date and time?
if the user click the notification, i want to do one of the following operations:
1,launch a activity;
2,open a url in the webview or browser outside;
......
how should i do?
i hope there is a sample for every case, thanks so much.
Is it possible to push heads-up notification?
I'm using a custom sound and the sound doesn't seem to be playing. It's always defaulting to the default sound.
.sound(Uri.parse("android.resource://" + context.getPackageName() + "/" + R.raw.letter_sent))
Custom.build()
checks that it's being called on the main thread while Simple.build()
doesn't care for this. What's the purpose of this check? This makes it so that custom notifications cannot be called straightforwardly from services (if I'm listening for a push notification before shooting a notification).
When i load a background it has a white boarder around it. how do i scale to fit the whole area?
My goal is to show a notification daily on a user-chosen time. I tried Services and AlarmManager. Both failed because the service goes to sleep after a while and the AlarmManager has a bug in KitKat and I dont know how to handle it. Many tutorials are deprecated or simply wrong. So at the end I landed here. I can see that I can create a notification with your library very easy but I cant find an option to define when the notification shall get fired and in which interval.
Can you help me?
An exception is thrown for br.com.goncalves.pugnotification.notification.Load#priority
Priority Should Not Be Less Than Or Equal To Zero!
The acceptable range for Notification priorities range from Acceptable values range from -2 (NotificationCompat.PRIORITY_MIN) to 2 (NotificationCompat.PRIORITY_MAX).
how to use .vibrate(vibrate)
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 ?
@halysongoncalves Is there any way to show native chars? Currently I'm using Turkish letters and they are not displayed correctly.
I've tried URLDecoder.decode("...", charset); but it's not fixing that problem.
hi, I am trying to make this project work but with no luck so far. I tried for hours to do a hello world without Picasso but seems impossible. This is my code:
PugNotification.with(this).load()
.title("title")
.message("message")
.bigTextStyle("bigtext")
.smallIcon(R.drawable.pugnotification_ic_launcher)
.largeIcon(R.drawable.pugnotification_ic_launcher)
.color(android.R.color.background_dark)
.custom()
.setImageLoader(new ImageLoader() {
@Override
public void load(String uri, OnImageLoadingCompleted onCompleted) {
}
@Override
public void load(int imageResId, OnImageLoadingCompleted onCompleted) {
}
})
.background(R.drawable.pugnotification_ic_launcher)
.setPlaceholder(R.drawable.pugnotification_ic_placeholder)
.build();
The result of this code is nothing shown after managing to create a dummy class to get rid of the continuous NullPointer. I do not understand why you need 3 images, a small icon, a large icon and a URL.
If you could provide a simpler example without Picasso would be very appreciated. Is this the reason that nothing is shown?
Regards
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.
I have to use custom font in contentTitle And ContentText..
How can I use this in PugNotification ?
As we use on https://github.com/jhipster/generator-jhipster/blob/master/.gitattributes to control a few aspects of the committed source code.
Example:
docs: http://git-scm.com/book/en/v2/Customizing-Git-Git-Attributes
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?
The PugNotification
class doesn't provide a method that corresponds to NotificationManager#cancel(String, int)
for tag-based cancelation of notifications:
public void cancel(String tag, int identifier) {
NotificationManager notifyManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
notifyManager.cancel(tag, identifier);
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.