اندروید 14 ویژگی ها و API های عالی را برای توسعه دهندگان معرفی می کند. موارد زیر به شما کمک می کند تا با ویژگی های برنامه های خود آشنا شوید و با API های مرتبط شروع به کار کنید.
برای فهرست دقیق APIهای اضافه شده، اصلاح شده و حذف شده، گزارش تفاوت API را بخوانید. برای جزئیات بیشتر در مورد APIهای اضافه شده به مرجع Android API مراجعه کنید — برای Android 14، به دنبال APIهایی باشید که در سطح API 34 اضافه شده اند. برای آشنایی با مناطقی که تغییرات پلت فرم ممکن است بر برنامه های شما تأثیر بگذارد، حتماً تغییرات رفتار Android 14 را برای برنامه هایی که Android 14 را هدف قرار می دهند و برای همه برنامه ها بررسی کنید.
بین المللی شدن
ترجیحات زبان برای هر برنامه
Android 14 ویژگی های زبان هر برنامه را که در Android 13 (سطح API 33) معرفی شده بود با این قابلیت های اضافی گسترش می دهد:
ایجاد خودکار
localeConfig
یک برنامه : با شروع Android Studio Giraffe Canary 7 و AGP 8.1.0-alpha07، میتوانید برنامه خود را به گونهای پیکربندی کنید که از اولویتهای زبان هر برنامه بهطور خودکار پشتیبانی کند. بر اساس منابع پروژه شما، افزونه Android Gradle فایلLocaleConfig
را تولید می کند و یک مرجع به آن در فایل مانیفست نهایی اضافه می کند، بنابراین دیگر نیازی به ایجاد یا به روز رسانی فایل به صورت دستی ندارید. AGP از منابع موجود در پوشههایres
ماژولهای برنامه شما و هر وابستگی ماژول کتابخانهای برای تعیین مکانهای گنجاندن در فایلLocaleConfig
استفاده میکند.بهروزرسانیهای پویا برای
localeConfig
یک برنامه : از روشهایsetOverrideLocaleConfig()
وgetOverrideLocaleConfig()
درLocaleManager
برای بهروزرسانی پویا فهرست زبانهای پشتیبانیشده برنامه خود در تنظیمات سیستم دستگاه استفاده کنید. از این انعطافپذیری برای سفارشیسازی فهرست زبانهای پشتیبانیشده در هر منطقه، اجرای آزمایشهای A/B یا ارائه فهرست بهروزرسانیشده از مناطق استفاده کنید، اگر برنامه شما از فشارهای سمت سرور برای محلیسازی استفاده میکند.قابلیت مشاهده زبان برنامه برای ویرایشگرهای روش ورودی (IME) : IMEها می توانند از متد
getApplicationLocales()
برای بررسی زبان برنامه فعلی و تطبیق زبان IME با آن زبان استفاده کنند.
Grammatical Inflection API
3 میلیارد نفر به زبانهای جنسیتی صحبت میکنند: زبانهایی که دستههای دستوری (مانند اسمها، افعال، صفتها و حروف اضافه) بر اساس جنسیت افراد و اشیایی که با آنها صحبت میکنید یا درباره آنها صحبت میکنید، عطف میشوند. به طور سنتی، بسیاری از زبان های جنسیتی از جنسیت دستوری مذکر به عنوان جنسیت پیش فرض یا عمومی استفاده می کنند.
مخاطب قرار دادن کاربران در جنسیت دستوری اشتباه، مانند خطاب قرار دادن زنان در جنسیت دستوری مذکر، می تواند بر عملکرد و نگرش آنها تأثیر منفی بگذارد . در مقابل، یک رابط کاربری با زبانی که به درستی جنسیت گرامری کاربر را منعکس میکند، میتواند تعامل کاربر را بهبود بخشد و تجربه کاربری شخصیتر و طبیعیتر را ارائه دهد.
To help you build a user-centric UI for gendered languages, Android 14 introduces the Grammatical Inflection API, which lets you add support for grammatical gender without refactoring your app.
ترجیحات منطقه ای
Regional preferences enable users to personalize temperature units, the first day of the week, and numbering systems. A European living in the United States might prefer temperature units to be in Celsius rather than Fahrenheit and for apps to treat Monday as the beginning of the week instead of the US default of Sunday.
New Android Settings menus for these preferences provide users with a
discoverable and centralized location to change app preferences. These
preferences also persist through backup and restore. Several APIs and
intents—such as
getTemperatureUnit
and
getFirstDayOfWeek
—
grant your app read access to user preferences, so your app can adjust how it
displays information. You can also register a
BroadcastReceiver
on
ACTION_LOCALE_CHANGED
to handle locale configuration changes when regional preferences change.
To find these settings, open the Settings app and navigate to System > Languages & input > Regional preferences.


دسترسی
مقیاس بندی فونت غیر خطی تا 200٪
با شروع اندروید 14، این سیستم از مقیاس بندی فونت تا 200% پشتیبانی می کند، گزینه های دسترسی اضافی را به کاربران کم بینا ارائه می دهد که با دستورالعمل های دسترسی به محتوای وب (WCAG) مطابقت دارد.
برای جلوگیری از بزرگ شدن عناصر متنی بزرگ روی صفحه، سیستم یک منحنی مقیاسبندی غیرخطی اعمال میکند. این استراتژی مقیاسبندی به این معنی است که متن بزرگ به اندازه متن کوچکتر مقیاس نمیشود. مقیاسبندی غیرخطی فونت به حفظ سلسلهمراتب متناسب بین عناصر با اندازههای مختلف کمک میکند و در عین حال مشکلات مربوط به مقیاسگذاری خطی متن را در درجات بالا کاهش میدهد (مانند قطع شدن متن یا متنی که به دلیل اندازه نمایش بسیار بزرگ خواندن آن سختتر میشود).
برنامه خود را با مقیاس بندی فونت غیرخطی آزمایش کنید

اگر قبلاً از واحدهای پیکسل های مقیاس شده (sp) برای تعریف اندازه متن استفاده می کنید، این گزینه های اضافی و بهبودهای مقیاس بندی به طور خودکار روی متن در برنامه شما اعمال می شوند. با این حال، همچنان باید تست UI را با حداکثر اندازه فونت فعال (200%) انجام دهید تا مطمئن شوید که برنامه شما اندازه فونت را به درستی اعمال میکند و میتواند اندازه فونتهای بزرگتر را بدون تأثیرگذاری بر قابلیت استفاده، در خود جای دهد.
برای فعال کردن اندازه فونت 200٪، مراحل زیر را دنبال کنید:
- برنامه تنظیمات را باز کنید و به Accessibility > Display size and text بروید.
- برای گزینه اندازه قلم ، همانطور که در تصویر همراه با این بخش نشان داده شده است، روی نماد مثبت (+) ضربه بزنید تا حداکثر تنظیم اندازه قلم فعال شود.
برای اندازههای متن از واحدهای پیکسل کوچک شده (sp) استفاده کنید
به یاد داشته باشید که همیشه اندازه متن را در واحدهای sp مشخص کنید . هنگامی که برنامه شما از واحدهای sp استفاده می کند، Android می تواند اندازه متن مورد نظر کاربر را اعمال کند و آن را به طور مناسب مقیاس دهد.
از واحدهای sp برای لایهبندی استفاده نکنید یا ارتفاع دید را با فرض لایهبندی ضمنی تعریف نکنید: با مقیاسبندی فونت غیرخطی، ابعاد sp ممکن است متناسب نباشد، بنابراین 4sp + 20sp ممکن است با 24sp برابر نباشد.
تبدیل واحدهای پیکسل مقیاس شده (sp).
از TypedValue.applyDimension()
برای تبدیل واحدهای sp به پیکسل و از TypedValue.deriveDimension()
برای تبدیل پیکسل ها به sp استفاده کنید. این روش ها منحنی مقیاس بندی غیرخطی مناسب را به طور خودکار اعمال می کنند.
از معادلات کدگذاری سخت با استفاده از Configuration.fontScale
یا DisplayMetrics.scaledDensity
اجتناب کنید. از آنجایی که مقیاس فونت غیرخطی است، فیلد scaledDensity
دیگر دقیق نیست. فیلد fontScale
باید فقط برای مقاصد اطلاعاتی استفاده شود زیرا فونتها دیگر با یک مقدار اسکالر مقیاسبندی نمیشوند.
از واحدهای sp برای lineHeight استفاده کنید
همیشه android:lineHeight
با استفاده از واحدهای sp به جای dp تعریف کنید، بنابراین ارتفاع خط همراه با متن شما مقیاس شود. در غیر این صورت، اگر متن شما sp است اما lineHeight
شما به صورت dp یا px است، مقیاس نمیشود و تنگ به نظر میرسد. TextView به طور خودکار lineHeight
را تصحیح می کند تا نسبت های مورد نظر شما حفظ شود، اما تنها در صورتی که هر دو textSize
و lineHeight
در واحدهای sp تعریف شده باشند.
دوربین و رسانه
Ultra HDR برای تصاویر

اندروید 14 از تصاویر با محدوده دینامیکی بالا (HDR) پشتیبانی می کند که اطلاعات بیشتری را از حسگر هنگام عکس گرفتن حفظ می کند، که رنگ های زنده و کنتراست بیشتر را امکان پذیر می کند. اندروید از فرمت Ultra HDR استفاده میکند که کاملاً با تصاویر JPEG سازگار است و به برنامهها اجازه میدهد تا به طور یکپارچه با تصاویر HDR تعامل داشته باشند و در صورت نیاز آنها را در محدوده دینامیک استاندارد (SDR) نمایش دهند.
رندر کردن این تصاویر در رابط کاربری در HDR زمانی که برنامه شما استفاده از رابط کاربری HDR را برای پنجره فعالیت خود انتخاب میکند، چه از طریق ورودی مانیفست یا در زمان اجرا با فراخوانی Window.setColorMode()
به طور خودکار توسط چارچوب انجام میشود. همچنین می توانید تصاویر ثابت Ultra HDR فشرده شده را در دستگاه های پشتیبانی شده ضبط کنید. با بازیابی رنگ های بیشتر از حسگر، ویرایش در پست می تواند انعطاف پذیرتر باشد. Gainmap
مرتبط با تصاویر Ultra HDR می تواند برای رندر آنها با استفاده از OpenGL یا Vulkan استفاده شود.

اندروید 14 از تصاویر با محدوده دینامیکی بالا (HDR) پشتیبانی می کند که اطلاعات بیشتری را از حسگر هنگام عکس گرفتن حفظ می کند، که رنگ های زنده و کنتراست بیشتر را امکان پذیر می کند. اندروید از فرمت Ultra HDR استفاده میکند که کاملاً با تصاویر JPEG سازگار است و به برنامهها اجازه میدهد تا به طور یکپارچه با تصاویر HDR تعامل داشته باشند و در صورت نیاز آنها را در محدوده دینامیک استاندارد (SDR) نمایش دهند.
رندر کردن این تصاویر در رابط کاربری در HDR زمانی که برنامه شما استفاده از رابط کاربری HDR را برای پنجره فعالیت خود انتخاب میکند، چه از طریق ورودی مانیفست یا در زمان اجرا با فراخوانی Window.setColorMode()
به طور خودکار توسط چارچوب انجام میشود. همچنین می توانید تصاویر ثابت Ultra HDR فشرده شده را در دستگاه های پشتیبانی شده ضبط کنید. با بازیابی رنگ های بیشتر از حسگر، ویرایش در پست می تواند انعطاف پذیرتر باشد. Gainmap
مرتبط با تصاویر Ultra HDR می تواند برای رندر آنها با استفاده از OpenGL یا Vulkan استفاده شود.
زوم، فوکوس، Postview و موارد دیگر در پسوند دوربین
Android 14 upgrades and improves camera extensions, allowing apps to handle longer processing times, which enables improved images using compute-intensive algorithms like low-light photography on supported devices. These features give users an even more robust experience when using camera extension capabilities. Examples of these improvements include:
- Dynamic still capture processing latency estimation provides much more
accurate still capture latency estimates based on the current scene and
environment conditions. Call
CameraExtensionSession.getRealtimeStillCaptureLatency()
to get aStillCaptureLatency
object that has two latency estimation methods. ThegetCaptureLatency()
method returns the estimated latency betweenonCaptureStarted
andonCaptureProcessStarted()
, and thegetProcessingLatency()
method returns the estimated latency betweenonCaptureProcessStarted()
and the final processed frame being available. - Support for capture progress callbacks so that apps can display the current
progress of long-running, still-capture processing operations. You can check
if this feature is available with
CameraExtensionCharacteristics.isCaptureProcessProgressAvailable
, and if it is, you implement theonCaptureProcessProgressed()
callback, which has the progress (from 0 to 100) passed in as a parameter. Extension specific metadata, such as
CaptureRequest.EXTENSION_STRENGTH
for dialing in the amount of an extension effect, such as the amount of background blur withEXTENSION_BOKEH
.Postview Feature for Still Capture in camera extensions, which provides a less-processed image more quickly than the final image. If an extension has increased processing latency, a postview image could be provided as a placeholder to improve UX and switched out later for the final image. You can check if this feature is available with
CameraExtensionCharacteristics.isPostviewAvailable
. Then you can pass anOutputConfiguration
toExtensionSessionConfiguration.setPostviewOutputConfiguration
.Support for
SurfaceView
allowing for a more optimized and power-efficient preview render path.Support for tap to focus and zoom during extension usage.
زوم درون سنسور
When REQUEST_AVAILABLE_CAPABILITIES_STREAM_USE_CASE
in
CameraCharacteristics
contains
SCALER_AVAILABLE_STREAM_USE_CASES_CROPPED_RAW
, your app
can use advanced sensor capabilities to give a cropped RAW stream the same
pixels as the full field of view by using a CaptureRequest
with a RAW target that has stream use case set to
CameraMetadata.SCALER_AVAILABLE_STREAM_USE_CASES_CROPPED_RAW
.
By implementing the request override controls, the updated camera gives users
zoom control even before other camera controls are ready.
صدای USB بدون اتلاف
اندروید 14 از فرمتهای صوتی بدون اتلاف برای تجربه در سطح دوستداران صوتی از طریق هدستهای سیمی USB پشتیبانی میکند. میتوانید از یک دستگاه USB برای ویژگیهای میکسر ترجیحی آن پرس و جو کنید، یک شنونده را برای تغییرات در ویژگیهای میکسر ترجیحی ثبت کنید، و ویژگیهای میکسر را با استفاده از کلاس AudioMixerAttributes
پیکربندی کنید. این کلاس فرمت، مانند ماسک کانال، نرخ نمونه و رفتار میکسر صدا را نشان می دهد. این کلاس امکان ارسال مستقیم صدا را بدون میکس، تنظیم صدا یا جلوه های پردازشی را فراهم می کند.
بهره وری توسعه دهندگان و ابزار
مدیر اعتبار
Android 14 adds Credential Manager as a platform API, with additional support back to Android 4.4 (API level 19) devices through a Jetpack Library using Google Play services. Credential Manager aims to make sign-in easier for users with APIs that retrieve and store credentials with user-configured credential providers. Credential Manager supports multiple sign-in methods, including username and password, passkeys, and federated sign-in solutions (such as Sign-in with Google) in a single API.
Passkeys provide many advantages. For example, passkeys are built on industry standards, can work across different operating systems and browser ecosystems, and can be used with both websites and apps.
For more information, see the Credential Manager and passkeys documentation and the blogpost about Credential Manager and passkeys.
Health Connect
Health Connect یک مخزن روی دستگاه برای داده های سلامت و تناسب اندام کاربر است. این به کاربران اجازه می دهد تا داده ها را بین برنامه های مورد علاقه خود به اشتراک بگذارند، با یک مکان واحد برای کنترل داده هایی که می خواهند با این برنامه ها به اشتراک بگذارند.
در دستگاههایی که نسخههای اندرویدی قبل از Android 14 دارند، Health Connect برای دانلود به عنوان یک برنامه در فروشگاه Google Play در دسترس است. با شروع اندروید 14، Health Connect بخشی از پلتفرم است و بهروزرسانیها را از طریق بهروزرسانیهای سیستم Google Play بدون نیاز به دانلود جداگانه دریافت میکند. با این کار، Health Connect میتواند بهطور مکرر بهروزرسانی شود و برنامههای شما میتوانند متکی باشند که Health Connect در دستگاههای دارای Android نسخه ۱۴ یا بالاتر در دسترس است. کاربران میتوانند با کنترلهای حریم خصوصی که در تنظیمات سیستم یکپارچه شدهاند، از تنظیمات دستگاه خود به Health Connect دسترسی داشته باشند.


Health Connect شامل چندین ویژگی جدید در اندروید 14 است، مانند مسیرهای ورزشی، که به کاربران امکان می دهد مسیری از تمرین خود را به اشتراک بگذارند که می تواند بر روی نقشه تجسم شود. مسیر به عنوان لیستی از مکانهای ذخیره شده در یک پنجره زمانی تعریف میشود و برنامه شما میتواند مسیرها را در جلسات تمرین وارد کند و آنها را به هم گره بزند. برای اطمینان از اینکه کاربران کنترل کاملی بر این داده های حساس دارند، کاربران باید به اشتراک گذاری مسیرهای فردی با سایر برنامه ها را اجازه دهند.
برای اطلاعات بیشتر، به مستندات Health Connection و پست وبلاگ در مورد چه چیزی در سلامت Android جدید است مراجعه کنید.
به روز رسانی OpenJDK 17
Android 14 continues the work of refreshing Android's core libraries to align with the features in the latest OpenJDK LTS releases, including both library updates and Java 17 language support for app and platform developers.
The following features and improvements are included:
- Updated approximately 300
java.base
classes to Java 17 support. - Text Blocks, which introduce multi-line string literals to the Java programming language.
- Pattern Matching for instanceof, which allows an object to
be treated as having a specific type in an
instanceof
without any additional variables. - Sealed classes, which allow you restrict which classes and interfaces can extend or implement them.
Thanks to Google Play system updates (Project Mainline), over 600 million devices are enabled to receive the latest Android Runtime (ART) updates that include these changes. This is part of our commitment to give apps a more consistent, secure environment across devices, and to deliver new features and capabilities to users independent of platform releases.
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
بهبود برای فروشگاه های برنامه
Android 14 introduces several PackageInstaller
APIs that
allow app stores to improve their user experience.
Request install approval before downloading
Installing or updating an app might require user approval.
For example, when an installer making use of the
REQUEST_INSTALL_PACKAGES
permission attempts to install a
new app. In prior Android versions, app stores can only request user approval
after APKs are written to the install session and the
session is committed.
Starting with Android 14, the requestUserPreapproval()
method lets installers request user approval before committing the install
session. This improvement lets an app store defer downloading any APKs until
after the installation has been approved by the user. Furthermore, once a user
has approved installation, the app store can download and install the app in the
background without interrupting the user.
Claim responsibility for future updates
The setRequestUpdateOwnership()
method allows an installer
to indicate to the system that it intends to be responsible for future updates
to an app it is installing. This capability enables update ownership
enforcement, meaning that only the update owner is permitted
to install automatic updates to the app. Update ownership enforcement helps to
ensure that users receive updates only from the expected app store.
Any other installer, including those making use of the
INSTALL_PACKAGES
permission, must receive explicit user
approval in order to install an update. If a user decides to proceed with an
update from another source, update ownership is lost.
Update apps at less-disruptive times
App stores typically want to avoid updating an app that is actively in use because this leads to the app's running processes being killed, which potentially interrupts what the user was doing.
Starting with Android 14, the InstallConstraints
API
gives installers a way to ensure that their app updates happen at an opportune
moment. For example, an app store can call the
commitSessionAfterInstallConstraintsAreMet()
method to
make sure that an update is only committed when the user is no longer
interacting with the app in question.
Seamlessly install optional splits
With split APKs, features of an app can be delivered in separate APK files,
rather than as a monolithic APK. Split APKs allow app stores to optimize the
delivery of different app components. For example, app stores might optimize
based on the properties of the target device. The
PackageInstaller
API has supported splits since its
introduction in API level 22.
In Android 14, the setDontKillApp()
method allows an
installer to indicate that the app's running processes shouldn't be killed when
new splits are installed. App stores can use this feature to seamlessly install
new features of an app while the user is using the app.
بستههای فراداده برنامه
Starting in Android 14, the Android package installer lets you specify app metadata, such as data safety practices, to include on app store pages such as Google Play.
تشخیص زمانی که کاربران از دستگاه عکس می گیرند
To create a more standardized experience for detecting screenshots, Android 14 introduces a privacy-preserving screenshot detection API. This API lets apps register callbacks on a per-activity basis. These callbacks are invoked, and the user is notified, when the user takes a screenshot while that activity is visible.
تجربه کاربری
اقدامات سفارشی اشتراکگذاری و رتبهبندی بهبود یافته
Android 14 updates the system sharesheet to support custom app actions and more informative preview results for users.
Add custom actions
With Android 14, your app can add custom actions to the system sharesheet it invokes.

Improve ranking of Direct Share targets
Android 14 uses more signals from apps to determine the ranking of the direct share targets to provide more helpful results for the user. To provide the most useful signal for ranking, follow the guidance for improving rankings of your Direct Share targets. Communication apps can also report shortcut usage for outgoing and incoming messages.

پشتیبانی از انیمیشن های داخلی و سفارشی برای Predictive Back
Android 13 introduced the predictive back-to-home animation behind a developer option. When used in a supported app with the developer option enabled, swiping back shows an animation indicating that the back gesture exits the app back to the home screen.
Android 14 includes multiple improvements and new guidance for Predictive Back:
- You can set
android:enableOnBackInvokedCallback=true
to opt in to predictive back system animations per-Activity instead of for the entire app. - We've added new system animations to accompany the back-to-home animation from Android 13. The new system animations are cross-activity and cross-task, which you get automatically after migrating to Predictive Back.
- We've added new Material Component animations for Bottom sheets, Side sheets, and Search.
- We've created design guidance for creating custom in-app animations and transitions.
- We've added new APIs to support custom in-app transition animations:
handleOnBackStarted
,handleOnBackProgressed
,handleOnBackCancelled
in
OnBackPressedCallback
onBackStarted
,onBackProgressed
,onBackCancelled
in
OnBackAnimationCallback
- Use
overrideActivityTransition
instead ofoverridePendingTransition
for transitions that respond as the user swipes back.
With this Android 14 preview release, all features of Predictive Back remain behind a developer option. See the developer guide to migrate your app to predictive back, as well as the developer guide to creating custom in-app transitions.
تولیدکننده دستگاه صفحه بزرگ برای هر برنامه لغو می شود
Per-app overrides enable device manufacturers to change the behavior of apps on large screen devices. For example, the FORCE_RESIZE_APP
override instructs the system to resize the app to fit display dimensions (avoiding size compatibility mode) even if resizeableActivity="false"
is set in the app manifest.
Overrides are intended to improve the user experience on large screens.
New manifest properties enable you to disable some device manufacturer overrides for your app.
صفحه نمایش بزرگ کاربر در هر برنامه لغو می شود
Per-app overrides change the behavior of apps on large screen devices. For example, the OVERRIDE_MIN_ASPECT_RATIO_LARGE
device manufacturer override sets the app aspect ratio to 16:9 regardless of the app's configuration.
Android 14 QPR1 enables users to apply per‑app overrides by means of a new settings menu on large screen devices.
اشتراک گذاری صفحه نمایش برنامه
اشتراکگذاری صفحه برنامه به کاربران این امکان را میدهد تا در حین ضبط محتوای صفحه، یک پنجره برنامه را به جای کل صفحه دستگاه به اشتراک بگذارند.
با اشتراکگذاری صفحه برنامه، نوار وضعیت، نوار پیمایش، اعلانها و سایر عناصر رابط کاربری سیستم از صفحه نمایش مشترک حذف میشوند. فقط محتوای برنامه انتخابی به اشتراک گذاشته می شود.
اشتراکگذاری صفحهنمایش برنامه، بهرهوری و حریم خصوصی را بهبود میبخشد و به کاربران امکان میدهد چندین برنامه را اجرا کنند، اما اشتراکگذاری محتوا را به یک برنامه محدود میکند.
پاسخ هوشمند مبتنی بر LLM در Gboard در Pixel 8 Pro
On Pixel 8 Pro devices with the December Feature Drop, developers can try out higher-quality smart replies in Gboard powered by on-device Large Language Models (LLMs) running on Google Tensor.
This feature is available as a limited preview for US English in WhatsApp, Line, and KakaoTalk. It requires using a Pixel 8 Pro device with Gboard as your keyboard.
To try it out, first enable the feature in Settings > Developer Options > AiCore Settings > Enable Aicore Persistent.
Next, open a conversation in a supported app to see LLM-powered Smart Reply in Gboard's suggestion strip in response to incoming messages.
گرافیک
مسیرها قابل پرس و جو و درون یابی هستند
Android's Path
API مکانیزمی قدرتمند و منعطف برای ایجاد و رندر گرافیک برداری است، با قابلیت استروک یا پر کردن یک مسیر، ساخت یک مسیر از قسمت های خط یا منحنی های درجه دوم یا مکعب، انجام عملیات بولی برای به دست آوردن اشکال پیچیده تر یا همه موارد. از اینها به طور همزمان یکی از محدودیت ها توانایی یافتن آنچه در واقع در یک شی Path وجود دارد است. درونیات شی پس از ایجاد برای تماس گیرندگان مبهم است.
برای ایجاد یک Path
، متدهایی مانند moveTo()
، lineTo()
و cubicTo()
را فراخوانی می کنید تا بخش های مسیر را اضافه کنید. اما هیچ راهی برای پرسیدن این مسیر وجود ندارد، بنابراین شما باید آن اطلاعات را در زمان ایجاد حفظ کنید.
با شروع اندروید 14، میتوانید مسیرها را جستجو کنید تا بفهمید داخل آنها چیست. ابتدا باید یک شی PathIterator
با استفاده از Path.getPathIterator
API دریافت کنید:
کاتلین
val path = Path().apply { moveTo(1.0f, 1.0f) lineTo(2.0f, 2.0f) close() } val pathIterator = path.pathIterator
جاوا
Path path = new Path(); path.moveTo(1.0F, 1.0F); path.lineTo(2.0F, 2.0F); path.close(); PathIterator pathIterator = path.getPathIterator();
در مرحله بعد، میتوانید PathIterator
را فراخوانی کنید تا قسمتها را یک به یک تکرار کند و تمام دادههای لازم برای هر بخش را بازیابی کند. این مثال از اشیاء PathIterator.Segment
استفاده می کند که داده ها را برای شما بسته بندی می کند:
کاتلین
for (segment in pathIterator) { println("segment: ${segment.verb}, ${segment.points}") }
جاوا
while (pathIterator.hasNext()) { PathIterator.Segment segment = pathIterator.next(); Log.i(LOG_TAG, "segment: " + segment.getVerb() + ", " + segment.getPoints()); }
PathIterator
همچنین دارای یک نسخه غیر تخصیص دهنده از next()
است که در آن می توانید بافر را برای نگهداری داده های نقطه ارسال کنید.
یکی از موارد مهم استفاده از کوئری داده های Path
، درون یابی است. برای مثال، ممکن است بخواهید بین دو مسیر مختلف متحرک (یا شکلبندی ) کنید. برای سادهتر کردن این مورد، اندروید 14 متد interpolate()
را در Path
نیز شامل میشود. با فرض اینکه دو مسیر ساختار داخلی یکسانی دارند، متد interpolate()
یک Path
جدید با آن نتیجه درون یابی ایجاد می کند. این مثال مسیری را برمی گرداند که شکل آن در نیمه راه است (یک درونیابی خطی 0.5) بین path
و otherPath
:
کاتلین
val interpolatedResult = Path() if (path.isInterpolatable(otherPath)) { path.interpolate(otherPath, .5f, interpolatedResult) }
جاوا
Path interpolatedResult = new Path(); if (path.isInterpolatable(otherPath)) { path.interpolate(otherPath, 0.5F, interpolatedResult); }
کتابخانه مسیر گرافیکی Jetpack API های مشابهی را برای نسخه های قبلی اندروید نیز فعال می کند.
مش های سفارشی با سایه زن های راس و قطعه
Android has long supported drawing triangle meshes with custom shading, but the input mesh format has been limited to a few predefined attribute combinations. Android 14 adds support for custom meshes, which can be defined as triangles or triangle strips, and can, optionally, be indexed. These meshes are specified with custom attributes, vertex strides, varying, and vertex and fragment shaders written in AGSL.
The vertex shader defines the varyings, such as position and color, while the
fragment shader can optionally define the color for the pixel, typically by
using the varyings created by the vertex shader. If color is provided by the
fragment shader, it is then blended with the current Paint
color using the blend mode selected when
drawing the mesh. Uniforms can be passed
into the fragment and vertex shaders for additional flexibility.
رندر بافر سخت افزاری برای Canvas
برای کمک به استفاده از Canvas
API Android برای ترسیم شتاب سختافزاری به یک HardwareBuffer
، Android 14 HardwareBufferRenderer
را معرفی میکند. این API به ویژه زمانی مفید است که مورد استفاده شما شامل ارتباط با ترکیب کننده سیستم از طریق SurfaceControl
برای ترسیم با تأخیر کم باشد.