Heads-up notifications

A notification is a message that Android displays outside an app to provide updates, reminders, and other timely information to users. In the Android Automotive OS, a notification can be displayed either as a heads-up notification (HUN) or in the Notification panel (or in both). This page explains how to customize HUNs.

Notification

Figure 1. Notification

By overriding the configuration values detailed below, you can customize HUNs in two ways:

  • Position
  • Animation

When customizing a HUN, be sure to determine how it is affected by the Z-order of system bars. If the Z-order of a system bar is 10 or higher, it appears on top of the HUNs. For example, if the HUN is displayed at the top of the screen and the top system bar has a Z-order of 10, the top system bar is displayed on top of the HUN unless the HUN animation helper is customized to offset the final position of the HUN by the height of the top system bar.

Related documentation

config_showHeadsUpNotificationOnBottom

A HUN can be displayed either on the top or bottom of the screen based on the configuration value config_showHeadsUpNotificationOnBottom. Set to false by default, this value sets the final position of the notification at the top of the screen.

Default notification

Figure 2. Default HUN

config_headsUpNotificationAnimationHelper

There are multiple ways of how the notification should appear on screen and leave the screen. A set of default animator helper classes are provided and can be switched out by overriding config_headsUpNotificationAnimationHelper.

com.android.car.notification.headsup.animationhelper.CarHeadsUpNotificationTopAnimationHelper

Animates the HUN to transition from the initial position, down to the final position, to visible, and then to invisible.

Top Animation Helper

Figure 3. Top Animation Helper

com.android.car.notification.headsup.animationhelper.CarHeadsUpNotificationBottomAnimationHelper

Animates the HUN to transition from the initial position, to the final position, to visible, and then to invisible.

Bottom Animation Helper

Figure 4. Bottom Animation Helper

com.android.car.notification.headsup.animationhelper.CarHeadsUpNotificationRightAnimationHelper

Animates the HUN to transition from the initial position left, to the final position, to visible, and then to invisible.

Right animation helper Right animation helper

Figure 5. Right Animation Helper

Custom animation helper

Should additional customization be required, the animator helper classes can be overridden or a custom animator helper class can be used provided the help class implements the HeadsUpNotificationAnimationHelper interface as shown in this code snippet:

[...]

public class SampleAnimationHelper implements
       HeadsUpNotificationAnimationHelper {

   @Override
   public AnimatorSet getAnimateInAnimator(Context context, View view) {
       return (AnimatorSet) AnimatorInflater.loadAnimator(
               context, R.animator.heads_up_notification_transition_in);
   }

   @Override
   public AnimatorSet getAnimateOutAnimator(Context context, View view) {
       return (AnimatorSet) AnimatorInflater.loadAnimator(
               context, R.animator.heads_up_notification_transition_out);
   }

   @Override
   public void resetHUNPosition(View view) {
       view.setY(-1 * view.getHeight());
       view.setAlpha(0);
   }
}