Android Wear Notification Layout - two lines in peek and ambient - android

I've noticed that Weather Timeline (for instance) displays notifications with two lines in both peek and ambient. I would like to replicate this for my requirements, but I'm not able to do so. I've tried InboxStyle and BigTextStyle to no avail. The icon position is also different, making it possible to display more of the title.
Is this possible somehow, or is it because Weather Timeline is a "wear app"?
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("TestTitle")
.setContentText("TestContextTextLoremIpsum");

The notification card may cover a significant portion of the screen, depending on the system UI style. Your watch face should adapt to these situations by ensuring that users can still tell the time while the notification card is present.
You need to determine the free space above the peek card so you can adapt your watch face, use WatchFaceService.Engine.getPeekCardPosition() method. This provide about its location when it's peeking at the bottom and allowing the watch face to be exposed.
Watch faces should not interfere with system UI elements, as described in Accommodate System UI Elements. If your watch face has a light background or shows information near the bottom of the screen, you may have to configure the size of notification cards or enable background protection.
#Override
public void onCreate(SurfaceHolder holder) {
super.onCreate(holder);
// configure the system UI
setWatchFaceStyle(new WatchFaceStyle.Builder(AnalogWatchFaceService.this)
.setCardPeekMode(WatchFaceStyle.PEEK_MODE_SHORT)
.setBackgroundVisibility(WatchFaceStyle
.BACKGROUND_VISIBILITY_INTERRUPTIVE)
.setShowSystemUiTime(false)
.build());
...
}
The code snippet above configures peeking cards to be a single line tall, the background of a peeking card to show only briefly and only for interruptive notifications, and the system time not to be shown.

Related

Display notifications on all Android devices consistently

I need to display a notification with text, image and two buttons.
I'm using NotificationCompat from support library and everything works great until I start to test it on different devices.
Here's the same notification on 3 different devices:
There are some problems here:
Device 1 (Nexus 5, 6.0): message text is missing, image is cropped.
Device 2 (Emulator, 7.0): image is heavily cropped
Device 3 (Xiaomi mi5s, 6.0): message text is missing, action text is black and is almost invisible
Other defects I was able to reproduce: white action icons on white background; image not being displayed (samsung galaxy s8 plus, android 7.0); action buttons not being displayed.
In the end, two biggest problems are: some parts of notification not showing and action icons or action texts having almost the same color as background.
Here's my code to show the notification:
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setContentTitle("Test title");
builder.setContentText("Test notification text description");
builder.setAutoCancel(true);
builder.setSmallIcon(R.drawable.ic_launcher);
builder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI);
builder.setContentIntent(pendingIntentContent);
NotificationCompat.Style style;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && image != null) {
style = new NotificationCompat.BigPictureStyle().bigPicture(image);
builder.setStyle(style);
}
builder.addAction(R.drawable.ic_share_vector, "SHARE", pendingIntentShare);
if(pendingIntentBookMark != null){
builder.addAction(R.drawable.ic_bookmark, "SAVE", pendingIntentBookMark);
}
return builder.build();
I was considering using my own layout, but I can't find a way to understand what is the main color of the device. Some devices use white notifications on black background, some use black notifications on black background and so on. Notification will look alien if it uses a different color.
I understand that I can blame particular devices for this problems, but I still need my notifications to work pretty much anywhere and look more or less consistently (without major glitches such as invisible text or missing elements).
Is there a way to set action buttons background and text color so they will always be visible?
Is there a way to know which colors does device use for its notifications area and for notification backgrounds?
Is there something other than BigPictureStyle that I can use?
I just hope that somebody had the same issues and found any sort of workaround.

android wear watch: use setPeekOpacityMode() for opacity, use setCardPeekMode for height

The android developer page gives the following information on the variable option for peek cards:
When this peek mode is selected, peek cards will be as tall as needed, while maintaining enough space at the top to draw the system time and status icons.
How can one tell the card how much space it has?
I ask because my cards seem to be displaying as short but the face adjusts to the size of the cards and two lined cards are desired.
EDIT: I did not get the behavior that I was looking for because I used the wrong method to change the settings. Since the integers being called had meanings for the function, the program operated.
.setCardPeekMode(WatchFaceStyle.PEEK_MODE_VARIABLE)
.setPeekOpacityMode(WatchFaceStyle.PEEK_OPACITY_MODE_TRANSLUCENT
PEEK_OPACITY_MODE_TRANSLUCENT is the same value (1) as PEEK_MODE_SHORT so the second line over rode the first.
The correct code is:
.setCardPeekMode(WatchFaceStyle.PEEK_MODE_VARIABLE)
.setPeekOpacityMode(WatchFaceStyle.PEEK_OPACITY_MODE_TRANSLUCENT)
The card may cover a significant portion of the screen, depending on the system UI style. Your watch face should adapt to these situations by ensuring that users can still tell the time while the notification card is present.
To determine the free space above the peek card so you can adapt your watch face, use the WatchFaceService.Engine.getPeekCardPosition() method.
Watch faces should not interfere with system UI elements, as described in Accommodate System UI Elements. If your watch face has a light background or shows information near the bottom of the screen, you may have to configure the size of notification cards or enable background protection.
#Override
public void onCreate(SurfaceHolder holder) {
super.onCreate(holder);
// configure the system UI
setWatchFaceStyle(new WatchFaceStyle.Builder(AnalogWatchFaceService.this)
.setCardPeekMode(WatchFaceStyle.PEEK_MODE_SHORT)
.setBackgroundVisibility(WatchFaceStyle
.BACKGROUND_VISIBILITY_INTERRUPTIVE)
.setShowSystemUiTime(false)
.build());
...
}
The code snippet above configures peeking cards to be a single line tall, the background of a peeking card to show only briefly and only for interruptive notifications, and the system time not to be shown.
Update
Or you can use relative measurements, we all know that devices has different sizes and resolutions.
Must get the width and height by using Canvas.getWidth() and 'Canvas.getHeight()` methods ans set the positions of your graphic elements using values that are fraction of the detected screen size. If you resize the elements of your watch face in response to a peek card, use values that are some fraction of the remaining space above the card to redraw your watch face.
Be sure to use .setCardPeekMode() for the height of the card and
.setPeekOpacityMode() for translucency.
Because the same integer values are called for height and opacity, it is possible to use WatchFaceStyle.PEEK_OPACITY_MODE_OPAQUE in setCardPeekMood and WatchFaceStyle.PEEK_OPACITY_MODE_TRANSLUCENT in setPeekOpacityMode(). This can cause undesired effects.

Zoomed, cropped icon in notification

I'm creating a notification using NotificationCompat.Builder. To set the large icon part of it, I'm using this:
bob = new NotificationCompat.Builder(context)
.setLargeIcon(bm)
.setAutoCancel(true)
.setSmallIcon(R.drawable.ic_launcher256)
.setContentTitle(context.getResources().getString(R.string.app_name))
.setContentText(message)
.setPriority(Notification.PRIORITY_HIGH);
The smallicon is displaying fine, but on some devices the large icon is zoomed in, and therefore cropped. On other devices (handily, all the ones I can test it on) it works perfectly.
I'm not aware of any restrictions on what size this icon must be. It's coming out of the users contacts list, so I can't control what goes in there, although I suppose I could resize/reformat it if that were the problem.
I'll continue to debug this (focussing on the logic which obtains the bitmap) but thought I'd ask in case I've overlooked something (non) obvious. Perhaps it's possible for people to set contact photos on their devices which aren't suitable for notifications without some pre-processing.
It's not really documented. :(
You can see from the base template layout that the icon is just dunked in an ImageView with android:scaleType="center", so anything bigger than the box (#dimen/notification_large_icon_widthx#dimen/notification_large_icon_height) will just get cropped as it overflows its bounds.
The answer, then, as you can see from dimens.xml, is 64x64dp. You'll want to scale your Bitmaps accordingly before posting the notification.

Possible to continuously update text in the notification area?

I would like a to place persistent text in the notification area that updates once every second. setTicker() in the NotificationCompat.Builder class will not work, because it hides everything else in the notification area. I am only looking to place text there that is a few characters long, taking up only a small piece of the notification area.
One way I think this can be done is by calling setSmallIcon(), and somehow using this small icon area to display text. I took a screenshot of an app's notification that I believe to be using this strategy. Notice the 165 KB/s:
You shouldn't use the ticker text of the notification to update the user. This text is shown when the notification is posted.
Like the screenshot it uses setSmallIcon like you mentioned.
You can create a bitmap and draw text on with the canvas API, then updating your current ongoing notification
Example how to draw text on bitmap
This will change the icon in the statusbar and visible for the user.

Android: Initial size of window, notification bar size and background image

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 ?

Categories

Resources