يتيح نظام التشغيل Android 9 إمكانية تنفيذ أنواع مختلفة من فتحات الشاشة على الأجهزة. تتيح لك فتحات الشاشة إنشاء تجارب غامرة من الحافة إلى الحافة مع إتاحة مساحة لأجهزة الاستشعار المهمة في مقدّمة الأجهزة.
الشكل 1. الجزء المقتطع من الشاشة في أعلى الوسط
يتوافق الإصدار 9 من نظام التشغيل Android مع الأنواع التالية من الفتحات:
- في أعلى المنتصف: فتحة في منتصف الحافة العلوية
- الجزء العلوي غير مركّز: قد يكون الجزء المقطوع في الزاوية أو غير مركّز قليلاً
- الأسفل: فتحة في الأسفل
- فتحتان: فتحة واحدة في الأعلى وفتحة واحدة في الأسفل
أمثلة ومصدر
يوضّح رمز إدارة النوافذ التالي في
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);
}
توضّح هذه الطرق كيفية التعامل مع الفتحات في شريط الحالة في جميع الحالات (أي في أعلى المنتصف، وفي أعلى الجانب، وفي الأسفل، وفي الفتحات المزدوجة في جميع أوضاع الدوران).
المتطلبات
لضمان عدم تأثُّر التطبيقات بشكل سلبي بفتحات الشاشة، عليك التأكّد مما يلي:
- يمتد شريط الحالة إلى ارتفاع القطع على الأقل في الوضع العمودي
- يجب أن تكون منطقة القطع محاطة بإطار أسود في وضعَي ملء الشاشة والوضع الأفقي
يمكن أن يحتوي جهازك على فتحة واحدة في كل حافة قصيرة (الجزء العلوي والسفلي).
لمزيد من المعلومات، يُرجى الاطّلاع على مستند وصف التوافق.
التنفيذ
لتنفيذ تصميمات القطع على الشاشة على جهازك، يجب ضبط القيم التالية لواجهة مستخدم النظام.
القيمة | الوصف |
---|---|
quick_qs_offset_height
|
تحدّد هذه السمة الهامش العلوي للوحة الإعدادات السريعة. تظهر الساعة والبطارية في المساحة أعلى اللوحة. في values-land، اضبط القيمة على |
quick_qs_total_height
|
إجمالي ارتفاع لوحة الإعدادات السريعة (لوحة الإعدادات السريعة المصغّرة) عند توسيع مركز الإشعارات، بما في ذلك المساحة أعلى اللوحة التي تحتوي على الساعة
بسبب طريقة عرض الإعدادات السريعة، يجب أن يكون الارتفاع الإجمالي للوحة الإعدادات السريعة جدًا (بما في ذلك الإزاحة) معروفًا بشكل ثابت، لذا يجب تعديل هذه القيمة بمقدار التغيير نفسه |
status_bar_height_portrait
|
الارتفاع التلقائي لشريط الحالة من منظور إطار العمل في معظم الأجهزة، يكون هذا الإعداد تلقائيًا 24dp. عندما يكون هناك موضع مقطوع، اضبط هذه القيمة على ارتفاع الموضع المقطوع. يمكن أن يكون أطول من الجزء المقطوع إذا أردت ذلك. |
status_bar_height_landscape
|
تمثّل هذه السمة ارتفاع شريط الحالة في الوضع الأفقي. لا تتوافق الفتحات إلا مع الحواف القصيرة للجهاز، وبالتالي سيكون ارتفاع شريط الحالة دائمًا بدون تغيير. في جهاز لا يحتوي على فتحة، يكون هذا الإعداد مكافئًا للقيمة |
config_mainBuiltInDisplayCutout
|
المسار الذي يحدّد شكل القطع. هذه السلسلة قابلة للتحليل بواسطة
يمكن تحديد |
config_fillMainBuiltinDisplayCutout
|
قيمة منطقية تحدد ما إذا كان سيتم رسم مسار القطع (المحدّد أعلاه) في البرنامج. يمكن استخدامها لمحاكاة صورة مقصوصة أو لملء صورة مقصوصة فعلية لتحقيق التنعيم. إذا كانت القيمة صحيحة، سيتم ملء |
اطّلِع على ملفات 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.