يتيح الإصدار 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
|
لتحديد الهامش العلوي للوحة الإعدادات السريعة. الساعة والبطارية يتم عرضها في المساحة فوق اللوحة. في value-land، تم ضبطها على |
quick_qs_total_height
|
إجمالي الارتفاع للوحة الإعدادات السريعة (تم تصغير الإعدادات السريعة لوحة) عند توسيع مركز الإشعارات، بما في ذلك المساحة أعلاه اللوحة التي تحتوي على الساعة.
نظرًا لطريقة عرض الإعدادات السريعة، يكون الارتفاع الإجمالي
لوحة الإعدادات السريعة (بما في ذلك الإزاحة) بشكل ثابت،
لذا يجب تعديل هذه القيمة من خلال الدلتا نفسها
|
status_bar_height_portrait
|
الارتفاع التلقائي لشريط الحالة من منظور إطار العمل في معظم الأجهزة، يتم ضبط القيمة التلقائية على 24 وحدة بكسل مستقلة الكثافة (dp). عندما يكون هناك رسم مقطوعة، اضبط هذا قيمة لارتفاع الصورة المقطوعة. يمكن أن تكون أطول من الصورة المقطوعة اختياريًا إذا رغبت في ذلك. |
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.