Displaying text as an icon in the status bar - android

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

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: Change layout based on phone's default text size

Is there any way to change the layout of your app based on what text size the phone is set to? I know you can set your text so it will be static (stay the same size) but I've had some users complain because the app doesn't look good because of the large text. These are mainly older people who need the large text and it would be nice if there was an easy way to accomplish this without splitting one activity into two separate ones so they could still use it. Any ideas?

what is the screen area returned by getWindowManager().getDefaultDisplay()?

I am trying to get the available screen area of my app programmatically.
To do so I am using getWindowManager().getDefaultDisplay().getSize() . However I am not quite sure of what is exactly the screen area corresponding to this 'Default Display Window'.
It seems to incorporate the whole screen (including the notification bar) except the navigation bar. Is this correct ? Are there exceptions ?
From the documentation:
Gets the size of the display, in pixels.
Note that this value should not be used for computing layouts, since a
device will typically have screen decoration (such as a status bar)
along the edges of the display that reduce the amount of application
space available from the size returned here. Layouts should instead
use the window size.
The size is adjusted based on the current rotation of the display.
The size returned by this method does not necessarily represent the
actual raw size (native resolution) of the display. The returned size
may be adjusted to exclude certain system decoration elements that are
always visible. It may also be scaled to provide compatibility with
older applications that were originally designed for smaller displays.
Emphasis mine. So yes, it's possible they might exclude the navigation bar from it, but not necessarily.
Yes, it includes all space usable by your application (i.e., not counting OS level components like the status and notification bar).
However, the size does change based on whether use you methods such as setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); which hides the notification and status bar and gives your application temporarily more room.

How to create a custom notification on Android. Text instead of image

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.

Android Notification Dynamic Icon

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.

Categories

Resources