Android Notification Dynamic Icon - android

Is it possible to overlay a notification icon with some text/int? or is it possible to generate a custom icon on the fly?
For example I have the current icon displayed for my notification, I would like to be able to display for example the number 2 within the red box.
As this is not a count of notifications ( so not the red bubble ), the setting the "number" in the notification will not work.
Will I have to just create an individual icon for every possible number I wish to display? Or is there a better way of achieving this?

Try using AnimationDrawable's. You can use them to combine multiple drawables into a single one, and select the one you want to display. I really think, this is the way to go.
More info: AnimationDrawable
Off course, you will have to provide individual drawables for all your Integers you want to display, but this way, you can easily change the appearance of your notifications

Notification.Builder
Has two methods:
setLargeIcon(Bitmap icon)
and
setSmallIcon(int icon)
Since the small Icon only seems to take a resource ID I think you'd have to provide a drawable resource for every possible number you want then you could select which one to use at run time.
The Large icon however takes a Bitmap, so you should be able to generate one with some java code and pass it in.
Truthfully though I don't exactly know what the difference is between the Large and Small icons. I don't have much experiences with Notifications in general. You might luck out and find that setLargeIcon will work for what you need. But it might also be that you can only use a Bitmap object for the image that is shown when the notification bar is pulled down, not the one that is shown while it is collapsed.

Related

Display text as notification icon

I am trying to display a notification to the user displaying a counter as the icon instead of an actual icon.
This is what I'm trying to achieve
What I've tried so far
int myCounter = 0;
setSmallIcon(myCounter); // actually the notification won't even display if its not an actual icon
setTickerText(String.valueOf(myCounter)); // This is actualy something different
setLargeIcon(myBitmapWithText); // I also tried generating a bitmap with text, but it won't display since the resource needs to be in the app-package itself
from what I've read, I can use an AnimatedDrawable but its really not logical to create like 50 different drawables to accomplish that task, unless I have no other option :)
I'm at the end of my wits with this one, how can I achieve the above result?

Android - Choosing a option shown by circle shaped touch objects

I have provided a picture below so you can get a better understanding. Basically I want the user to pick a number from 1-10 which is shown by circles (Only 1 number can be picked at a time). Lets say I pick number 10, as you can see on the picture I want the circle to stroke and change the color when the number is picked (indicating to the user that the number has been chosen). After the number is picked and you press the "blue button", I want to get the value picked to do other calculations.
This is how I want it to be
I feel having a touch based circle is the best way to do it, rather than using a spinner because it take more time. Now the question is how to do this without code duplication or redundancy and how to achieve this in the best way possible. I am thinking I have to create a circle object (Possibly button shaped like circles) 10 times and put text on them, group them in array?..etc or is there a more efficient way to do this.
I'm sure there's better ways to achieve this but I suggest a simple solution as you wanted !!!
Now the question is how to do this without code duplication or redundancy?
You can create a xml file in your drawable folder and put two different oval shapes in that: defaultShape and pickedShape, Use <solid> and <stroke> tags to customize your shapes as you like, and then apply it to your buttons' background.
In order to handle the picking of your button you should implement same onClickListenerfor all 10 buttons, if one of them is picked save it to a temp variable like Button pickedButton, in your listener your check if pickedButton is not null change its background to defaultShape, and assign the new picked one to the pickedButton and then change its background to pickedShape.
Hope you find it helpful.

Android: 9-patch image vs Shape vs Multi icon

Some people from our company create some rule about UI design for Web, Android and iOS. They give us a bunch of icon for each platform. But when i look at Android platform icon, they using multi icon to create 1 icon. For example, button background, they use these 3 icon, 1 for left side, 1 for right size and 1 stretchable for middle.
I think this is how web normally design button background. But i don't think i should do the same for Android (Maybe iOS also don't do it this way but since i only work with iOS for a short time, i not really sure). Normally i would use a Shape or 9-patch drawable for this kind of background. So here i have 2 question:
Which 1 should i use for button background in this example. A shape? A 9-patch drawable? Or multiple icon like this? And which one is worst to use?
If i must have to use multiple icon like this, how to put multiple icon like them into single background?
If their way of doing thing here is incorrect, i need some good reason to talk to them and make them change their mind. So any1 please help me clear about this problem.
Thank you!
9-patch should be the first choice and then is shape. Don't use 3 icon.
9-patch is more easy to use and easy to change if the further design changes. When using shape, you need to define the corresponding XML. If in next version, the background color changes, you need to modify the XML, but with 9-patch you just need to replace the resource file.
The other benefit is that, 9-patch can be created in UI side, programmer's don't have to re-manipulate it if the resource is correctly created. But with shape, programmer needs to know the RGB color, and need to code the XML.
3 icon is not suitable here. First, you have other better options. Second, 3 icon means you need to create 3 views for each of them. Third, the button should have different effect when user click it, with other two options you can simply define selectors, but with 3 icon, there's no elegant solution.

Displaying text as an icon in the status bar

I know that this questions has been asked, but there have been no answers. There are several apps that display both an Icon and a number with it (for example, if Android downloads more updates than will fit on the status bar, there is a download icon with a small number representing how many more icons would be displayed). Other apps display a % value or temperature. It was suggested that these apps simply have N icons (so, if temperature runs from 50C to 75C there would be 26 images (of various formats) that would be included with the code. What is worse is that if 70F - 105F were also required, the number of images would be very large.
What I would like to do is simply provide text that I could draw in a certain color (i.e 75F in green, but 99F in red), or change the background color, etc. Is there ANY WAY to do this without having to create 25+ images to represent each value? Note that I WANT the number in the status bar, not as a custom view when you click on the notification.
From the API, the icon is a resource that is passed to the Notification class as an integer. It would seem the only way to make this work is to dynamically create that icon and stuff it in the resources. Is this, or any other method, possible?
Note: I have looked at using the .number field of the Notification class. Although this gives me a number over the icon, it is not really what I am looking for, and, does not allow me to do a clean implementation (plus the number is really tiny).
Thanks in advance.
Marty

Android: How can I get the transparent region in an image

How can I get the transparent region in an image in android?
My problem is that I have images with transparent areas and I need to let the user click on regions and handle the click event only when they clicked on the actual colored regions of the image. How can I do this in android?
I saw that Drawable Has a getTrasnsparentRegion method but the default implementation returns null. So I need to overwrite it and put this implementation there.
Thank you,
If you used a bitmap you could then call getPixel(x,y) using the coodinate information provided from the click. I think getPixel returns an argb color value, you could then use this to see if that pixel is transparent.
Maybe there is a web api where you can send it an image and it will clear out white space, maybe picnik.
I know android apps can use each other, maybe find an app that can make white space transparent, though I doubt there is one with magic wand like capabilities. I know you would need to get at the developer of the app.

Categories

Resources