O Android 9 adiciona suporte para implementar diferentes tipos de recortes de tela nos dispositivos. Os recortes de tela permitem que você crie experiências imersivas de ponta a ponta, enquanto ainda permite espaço para sensores importantes na frente dos dispositivos.
Figura 1. Recorte da tela central superior
O Android 9 é compatível com os seguintes tipos de recortes:
- Centro superior: recorte no centro da borda superior
- Parte superior não centralizada: o recorte pode estar no canto ou ligeiramente fora do centro
- Parte inferior: recorte na parte inferior
- Dual: Um recorte na parte superior e outro na parte inferior
Exemplos e fonte
O código do gerenciador de janelas a seguir em PhoneWindowManager.java mostra como os quadros de exibição são inseridos na área segura quando LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS
não está definido.
// Ensure that windows with a DEFAULT or NEVER display cutout mode are laid out in
// the cutout safe zone.
if (cutoutMode != LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS) {
final Rect displayCutoutSafeExceptMaybeBars = mTmpDisplayCutoutSafeExceptMaybeBarsRect;
displayCutoutSafeExceptMaybeBars.set(displayFrames.mDisplayCutoutSafe);
if (layoutInScreen && layoutInsetDecor && !requestedFullscreen
&& cutoutMode == LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT) {
// At the top we have the status bar, so apps that are
// LAYOUT_IN_SCREEN | LAYOUT_INSET_DECOR but not FULLSCREEN
// already expect that there's an inset there and we don't need to exclude
// the window from that area.
displayCutoutSafeExceptMaybeBars.top = Integer.MIN_VALUE;
}
if (layoutInScreen && layoutInsetDecor && !requestedHideNavigation
&& cutoutMode == LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT) {
// Same for the navigation bar.
switch (mNavigationBarPosition) {
case NAV_BAR_BOTTOM:
displayCutoutSafeExceptMaybeBars.bottom = Integer.MAX_VALUE;
break;
case NAV_BAR_RIGHT:
displayCutoutSafeExceptMaybeBars.right = Integer.MAX_VALUE;
break;
case NAV_BAR_LEFT:
displayCutoutSafeExceptMaybeBars.left = Integer.MIN_VALUE;
break;
}
}
if (type == TYPE_INPUT_METHOD && mNavigationBarPosition == NAV_BAR_BOTTOM) {
// The IME can always extend under the bottom cutout if the navbar is there.
displayCutoutSafeExceptMaybeBars.bottom = Integer.MAX_VALUE;
}
// Windows that are attached to a parent and laid out in said parent already avoid
// the cutout according to that parent and don't need to be further constrained.
// Floating IN_SCREEN windows get what they ask for and lay out in the full screen.
// They will later be cropped or shifted using the displayFrame in WindowState,
// which prevents overlap with the DisplayCutout.
if (!attachedInParent && !floatingInScreenWindow) {
mTmpRect.set(pf);
pf.intersectUnchecked(displayCutoutSafeExceptMaybeBars);
parentFrameWasClippedByDisplayCutout |= !mTmpRect.equals(pf);
}
// Make sure that NO_LIMITS windows clipped to the display don't extend under the
// cutout.
df.intersectUnchecked(displayCutoutSafeExceptMaybeBars);
}
O SystemUI é renderizado na área de recorte e precisa determinar onde pode desenhar. PhoneStatusBarView.java fornece um exemplo de visualização que determina onde está o recorte da tela, qual é o seu tamanho e se a inserção da barra de navegação evita ou não a área de recorte.
Ao substituir onApplyWindowInsets()
, uma visualização pode determinar onde está o recorte e atualizar seu layout de acordo.
@Override
public WindowInsets onApplyWindowInsets(WindowInsets insets) {
if (updateOrientationAndCutout(mLastOrientation)) {
updateLayoutForCutout();
requestLayout();
}
return super.onApplyWindowInsets(insets);
}
Esses métodos descrevem como os recortes são tratados na barra de status em todos os casos (ou seja, centro superior, não centralizado superior, inferior e recortes duplos em todas as rotações).
Requisitos
Para garantir que os aplicativos não sejam afetados negativamente por cortes, você deve garantir que:
- A barra de status se estende pelo menos até a altura do recorte no modo retrato
- A área de recorte deve ser colocada em letterbox nos modos de tela cheia e paisagem
Seu dispositivo pode ter até um recorte em cada borda curta (superior e inferior).
Para obter mais informações, consulte o CDD .
Implementação
Para implementar recortes de exibição em seu dispositivo, você deve configurar os seguintes valores para a interface do usuário do sistema.
Valor | Descrição |
---|---|
quick_qs_offset_height | Define a margem superior para o painel de configurações rápidas. O relógio e a bateria são exibidos no espaço acima do painel. Em value-land, defina como |
quick_qs_total_height | Altura total do painel de configurações rápidas (painel de configurações rápidas recolhido) quando a aba de notificação é expandida, incluindo o espaço acima do painel que contém o relógio. Devido à forma como as configurações rápidas são dispostas, a altura total do painel de configurações rápidas (incluindo o deslocamento) deve ser conhecida estaticamente, portanto, esse valor deve ser ajustado pelo mesmo delta |
status_bar_height_portrait | A altura padrão da barra de status da perspectiva da estrutura. Na maioria dos dispositivos, o padrão é 24 dp. Quando houver um recorte, defina este valor para a altura do recorte. Opcionalmente, pode ser mais alto que o recorte, se desejado. |
status_bar_height_landscape | A altura da barra de status na paisagem. Os recortes são suportados apenas nas bordas curtas do dispositivo, portanto, essa sempre será uma altura da barra de status inalterada. Em um dispositivo sem recorte, isso é equivalente a |
config_mainBuiltInDisplayCutout | O caminho que define a forma do recorte. Esta é uma string analisável por |
config_fillMainBuiltinDisplayCutout | Um valor booleano que determina se o caminho de recorte (definido acima) deve ser desenhado no software. Pode ser usado para emular um recorte ou para preencher um recorte físico para obter anti-aliasing. Se verdadeiro, |
Veja estes arquivos dimens
para as definições padrão:
Exemplo de sobreposição para um recorte emulado:
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- The bounding path of the cutout region of the main built-in display.
Must either be empty if there is no cutout region, or a string that is parsable by
{@link android.util.PathParser}.
The path is assumed to be specified in display coordinates with pixel units and in
the display's native orientation, with the origin of the coordinate system at the
center top of the display.
To facilitate writing device-independent emulation overlays, the marker `@dp` can be
appended after the path string to interpret coordinates in dp instead of px units.
Note that a physical cutout should be configured in pixels for the best results.
-->
<string translatable="false" name="config_mainBuiltInDisplayCutout">
M 0,0
L -48, 0
L -44.3940446283, 36.0595537175
C -43.5582133885, 44.4178661152 -39.6, 48.0 -31.2, 48.0
L 31.2, 48.0
C 39.6, 48.0 43.5582133885, 44.4178661152 44.3940446283, 36.0595537175
L 48, 0
Z
@dp
</string>
<!-- Whether the display cutout region of the main built-in display should be forced to
black in software (to avoid aliasing or emulate a cutout that is not physically existent).
-->
<bool name="config_fillMainBuiltInDisplayCutout">true</bool>
<!-- Height of the status bar -->
<dimen name="status_bar_height_portrait">48dp</dimen>
<dimen name="status_bar_height_landscape">28dp</dimen>
<!-- Height of area above QQS where battery/time go (equal to status bar height if > 48dp) -->
<dimen name="quick_qs_offset_height">48dp</dimen>
<!-- Total height of QQS (quick_qs_offset_height + 128) -->
<dimen name="quick_qs_total_height">176dp</dimen>
</resources>
Validação
Para validar sua implementação de recortes de exibição, execute os testes CTS em tests/framework/base/windowmanager/src/android/server/wm .