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?
Related
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.
I want to create notification like here:
Red circle = icon which is always visible. Blue circle = icon that is visible only when you expand.
How do I make such a red circle notification?
must I create 100 images or can I use custom notification like text? Can i join two images together?
I found this:
http://www.framentos.com/en/android-tutorial/2012/02/20/how-to-create-a-custom-notification-on-android/
Custom notification layouts and text colors
But I still don't know how to create this red circle. With this i know how to create blue circle but this I don't need. I am not creating battery!
Any ideas?
The only text that you can put in the notification area/status bar ("red circle") is ticker text, which disappears after it's displayed (setTicker). The purpose of that area is to remind users that a notification is outstanding, using the small icon (setSmallIcon). You could make 100 different icons, one for each percentage, but then you would not be using Android's standard design guidelines for notifications.
I suggest that if you want a battery indicator, use 5 battery icons. One icon would be a "full" battery, along with 1 each for 75%, 50%, 25%, and "very low" (in red). I suspect that most users don't need to see exactly how much battery they have left in the status bar. You can then show the exact numbers and estimated time remaining in the full notification.
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.
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
To improve the perceived startup time of my application, I am using an image as a drawable for my initial activity as described in
http://developer.android.com/resources/articles/window-bg-speed.html
and it works wonders for what it is intended to do. The application seems to be presenting its first screen within a tenth of a second, much before my onCreate is even called.
However... My application, like most applications, should display under the notification bar of the system (it is not windowFullscreen, only windowNoTitle), and the background image I specify will take the size of the full screen, its top part going under the title bar.
My application will then start and as any well-behaved application it will display content adapted to the actual size of the viewport... which means it will not match the background image.
I could possibly leave room at the top of my startup image, but even at the same screen resolution, different devices have different size notification bars, so I can't have it fit the screen smoothly that way either - not even by supplying one image for each existing screen size, because they will have different notification bar sizes.
This happens before even the first line of code of my activity is even executed - that's the whole point of putting a background image there, to give feedback to the user as early as possible, even before the activity is actually started. The only way I can see would be to somehow tell the android framework to fit my window to the region under the bar and not the whole screen, but I couldn't find how to do that. Does anyone have an idea how to make my image closely fit the interface that will then be presented by my activity ?