Android 9 menambahkan dukungan untuk menerapkan berbagai jenis potongan layar di perangkat. Potongan layar memungkinkan Anda membuat pengalaman imersif dari tepi ke tepi sekaligus memberikan ruang bagi sensor penting di bagian depan perangkat.
Gambar 1. Potongan layar tengah atas
Android 9 mendukung jenis potongan berikut:
- Tengah atas: Potongan di tengah tepi atas
- Bagian atas tidak di tengah: Potongan mungkin berada di sudut atau sedikit tidak di tengah
- Bawah: Potongan di bagian bawah
- Ganda: Satu potongan di atas dan satu di bawah
Contoh dan sumber
Kode pengelola jendela berikut di
PhoneWindowManager.java
menunjukkan cara menyisipkan frame tampilan ke area aman saat
LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS
tidak ditetapkan.
// 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);
}
SystemUI dirender di area potongan, dan perlu menentukan tempat ia dapat digambar. PhoneStatusBarView.java memberikan contoh tampilan yang menentukan lokasi potongan layar, seberapa besar ukurannya, dan apakah inset dari menu nav menghindari area potongan atau tidak.
Dengan mengganti onApplyWindowInsets()
, tampilan dapat menentukan lokasi potongan
dan memperbarui tata letaknya dengan tepat.
@Override
public WindowInsets onApplyWindowInsets(WindowInsets insets) {
if (updateOrientationAndCutout(mLastOrientation)) {
updateLayoutForCutout();
requestLayout();
}
return super.onApplyWindowInsets(insets);
}
Metode ini menguraikan cara potongan layar ditangani di status bar dalam semua kasus (yaitu, tengah atas, atas tidak di tengah, bawah, dan potongan layar ganda dalam semua rotasi).
Persyaratan
Untuk memastikan aplikasi tidak terpengaruh secara negatif oleh potongan, Anda harus memastikan bahwa:
- Status bar diperluas setidaknya hingga tinggi potongan layar dalam mode potret
- Area potongan harus diberi letterbox dalam mode layar penuh dan lanskap
Perangkat Anda dapat memiliki maksimal satu potongan layar di setiap tepi pendek (atas dan bawah).
Untuk mengetahui informasi selengkapnya, lihat CDD.
Implementasi
Untuk menerapkan potongan layar di perangkat, Anda harus mengonfigurasi nilai berikut untuk UI Sistem.
Nilai | Deskripsi |
---|---|
quick_qs_offset_height
|
Menentukan margin atas untuk panel setelan cepat. Jam dan baterai ditampilkan di ruang di atas panel. Di values-land, ditetapkan ke |
quick_qs_total_height
|
Total tinggi panel setelan cepat (panel setelan cepat diciutkan) saat menu notifikasi diperluas, termasuk ruang di atas panel yang berisi jam.
Karena tata letak setelan cepat, tinggi total panel setelan cepat (termasuk offset) harus diketahui secara statis, sehingga nilai ini harus disesuaikan dengan delta yang sama
|
status_bar_height_portrait
|
Tinggi default status bar dari perspektif framework. Di sebagian besar perangkat, nilai defaultnya adalah 24 dp. Jika ada potongan, tetapkan nilai ini ke tinggi potongan. Dapat secara opsional lebih tinggi dari potongan jika diinginkan. |
status_bar_height_landscape
|
Tinggi status bar dalam lanskap. Potongan hanya didukung di tepi pendek perangkat, sehingga tinggi status bar ini akan selalu tidak berubah. Pada perangkat tanpa potongan, ini setara dengan
|
config_mainBuiltInDisplayCutout
|
Jalur yang menentukan bentuk potongan. Ini adalah string yang dapat diuraikan oleh
|
config_fillMainBuiltinDisplayCutout
|
Nilai boolean yang menentukan apakah akan menggambar jalur potongan (ditetapkan di atas) dalam software. Dapat digunakan untuk meniru potongan, atau untuk mengisi potongan fisik guna mencapai anti-aliasing. Jika benar, |
Lihat file dimens
ini untuk mengetahui definisi default:
Contoh overlay untuk potongan yang diemulasi:
<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>
Validasi
Untuk memvalidasi penerapan potongan layar, jalankan pengujian CTS di tests/framework/base/windowmanager/src/android/server/wm.