ב-Android 9 נוספה תמיכה בהטמעה של סוגים שונים של חיתוכי מסך במכשירים. החלקים החסרים במסך מאפשרים ליצור חוויות סוחפות מקצה לקצה, ועדיין משאירים מקום לחיישנים חשובים בחלק הקדמי של המכשירים.
איור 1. מגרעת במסך בחלק העליון במרכז
Android 9 תומך בסוגי החיתוכים הבאים:
- המרכז למעלה: חיתוך במרכז הקצה העליון
- חלק עליון לא ממורכז: יכול להיות שהגזרה נמצאת בפינה או מעט לא ממורכזת
- למטה: חיתוך בחלק התחתון
- שני חורים: חור אחד בחלק העליון וחור אחד בחלק התחתון
דוגמאות ומקור
הקוד הבא של מנהל החלונות ב-PhoneWindowManager.java מראה איך מסגרות התצוגה מוסטות לאזור הבטוח כש-LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS
לא מוגדר.
// 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 מעבדת את האזור החתוך, וצריכה לקבוע איפה היא יכולה לצייר. PhoneStatusBarView.java מספק דוגמה לתצוגה שקובעת איפה נמצא החלק החסר במסך, מה הגודל שלו והאם השוליים הפנימיים מסרגל הניווט לא חופפים לאזור החלק החסר במסך.
על ידי ביטול ברירת המחדל של onApplyWindowInsets()
, תצוגה יכולה לקבוע איפה החיתוך נמצא ולעדכן את הפריסה שלה בהתאם.
@Override
public WindowInsets onApplyWindowInsets(WindowInsets insets) {
if (updateOrientationAndCutout(mLastOrientation)) {
updateLayoutForCutout();
requestLayout();
}
return super.onApplyWindowInsets(insets);
}
בשיטות האלה מפורט איך מתבצעת ההתאמה של החלקים החסרים בשורת הסטטוס בכל המקרים (כלומר, בחלק העליון באמצע, בחלק העליון לא באמצע, בחלק התחתון ובשני חלקים חסרים בכל הסיבובים).
דרישות
כדי לוודא שהאפליקציות לא ייפגעו מהחלקים החסרים, צריך לוודא ש:
- שורת הסטטוס מתרחבת לפחות לגובה של החיתוך בפריסה לאורך
- האזור החתוך צריך להיות מוקף בפסים שחורים במצב מסך מלא ובמצב לרוחב
יכול להיות שיש במכשיר חור אחד בכל קצה קצר (למעלה ולמטה).
מידע נוסף זמין במאמר בנושא CDD.
הטמעה
כדי להטמיע חיתוכי תצוגה במכשיר, צריך להגדיר את הערכים הבאים בממשק המשתמש של המערכת.
ערך | תיאור |
---|---|
quick_qs_offset_height
|
מגדיר את השוליים העליונים של חלונית ההגדרות המהירות. השעון והסוללה מוצגים בחלק שמעל החלונית. בתיקייה values-land, מגדירים את הערך |
quick_qs_total_height
|
הגובה הכולל של חלונית ההגדרות המהירות (חלונית ההגדרות המהירות המכווצת) כשלוח ההתראות מורחב, כולל הרווח שמעל החלונית שמכילה את השעון.
בגלל האופן שבו ההגדרות המהירות מסודרות, צריך לדעת באופן סטטי את הגובה הכולל של חלונית ההגדרות המהירות (כולל ההיסט), ולכן צריך לשנות את הערך הזה באותו דלתא |
status_bar_height_portrait
|
גובה ברירת המחדל של שורת המצב מנקודת המבט של המסגרת. ברוב המכשירים, ערך ברירת המחדל הוא 24dp. אם יש חיתוך, צריך להגדיר את הערך הזה לגובה של החיתוך. אפשר להגדיר את הגובה של החלק הזה כך שיהיה גדול יותר מהחלק החתוך. |
status_bar_height_landscape
|
הגובה של שורת הסטטוס בפריסה לרוחב. החלקים החתוכים נתמכים רק בקצוות הקצרים של המכשיר, כך שגובה שורת המצב תמיד יהיה ללא שינוי. במכשיר ללא חיתוך, הערך הזה שווה ל- |
config_mainBuiltInDisplayCutout
|
הנתיב שמגדיר את הצורה של החיתוך. זוהי מחרוזת שאפשר לנתח באמצעות אפשר לציין את |
config_fillMainBuiltinDisplayCutout
|
ערך בוליאני שקובע אם לצייר את נתיב החיתוך (שמוגדר למעלה) בתוכנה. אפשר להשתמש בו כדי לחקות חיתוך או כדי למלא חיתוך פיזי כדי להשיג החלקה. אם הערך הוא True, התא |
ההגדרות שמוגדרות כברירת מחדל מופיעות בקובצי dimens
האלה:
דוגמה לשכבת-על של חיתוך מדומה:
<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>
אימות
כדי לאמת את ההטמעה של חיתוכי המסך, מריצים את בדיקות ה-CTS בכתובת tests/framework/base/windowmanager/src/android/server/wm.