از 27 مارس 2025، توصیه می کنیم از android-latest-release
به جای aosp-main
برای ساختن و کمک به AOSP استفاده کنید. برای اطلاعات بیشتر، به تغییرات AOSP مراجعه کنید.
اجرای نور شب
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
تحقیقات نشان می دهد که نور آبی صفحه نمایش می تواند تاثیر منفی بر خواب داشته باشد. اندروید 7.1.1 قابلیتی به نام Night Light را معرفی کرد که میزان نور آبی ساطع شده از نمایشگر دستگاه را کاهش می دهد تا با نور طبیعی زمان و مکان کاربر مطابقت بیشتری داشته باشد. اندروید 8.0 یک ویژگی اضافی را معرفی کرد که به کاربران کنترل بیشتری بر شدت افکت نور شب می دهد. Android 10 سرویس سیستم COLOR_DISPLAY_SERVICE
را با سطح API سیستم معرفی میکند تا به سیستم، تنظیمات و رابط کاربری سیستم کنترل بیشتری بر روی همه تغییر رنگها، از جمله نور شب، بدهد.
Night Light به یک پیادهسازی Hardware Composer HAL 2.0 (HWC 2) نیاز دارد که میتواند ماتریس ارسال شده به setColorTransform
را برای اجرای رنگآمیزی بدون تأثیر بر قدرت، عملکرد و سازگاری برنامه اعمال کند.
پیاده سازی
سازندگان دستگاه می توانند اجرای پیش فرض این ویژگی را با استفاده از پرچم های زیر که در frameworks/base/core/res/res/values/config.xml
تعریف شده اند، فعال کنند.
<!-- Control whether Night display is available. This should only be enabled
on devices with HWC 2 color transform support. -->
<bool name="config_nightDisplayAvailable">false</bool>
<!-- Default mode to control how Night display is automatically activated.
One of the following values (see NightDisplayController.java):
0 - AUTO_MODE_DISABLED
1 - AUTO_MODE_CUSTOM
2 - AUTO_MODE_TWILIGHT
-->
<integer name="config_defaultNightDisplayAutoMode">0</integer>
<!-- Default time when Night display is automatically activated.
Represented as milliseconds from midnight (e.g. 79200000 == 10pm). -->
<integer name="config_defaultNightDisplayCustomStartTime">79200000</integer>
<!-- Default time when Night display is automatically deactivated.
Represented as milliseconds from midnight (e.g. 21600000 == 6am). -->
<integer name="config_defaultNightDisplayCustomEndTime">21600000</integer>
<!-- Minimum color temperature, in Kelvin, supported by Night display. -->
<integer name="config_nightDisplayColorTemperatureMin">2596</integer>
<!-- Default color temperature, in Kelvin, to tint the screen when Night display is
activated. -->
<integer name="config_nightDisplayColorTemperatureDefault">2850</integer>
<!-- Maximum color temperature, in Kelvin, supported by Night display. -->
<integer name="config_nightDisplayColorTemperatureMax">4082</integer>
کد بین چارچوب، خدمات سیستم، رابط کاربری سیستم و تنظیمات تقسیم شده است. عملکرد اصلی توسط ColorDisplayManager
(با پشتیبانی ColorDisplayService
) کنترل می شود.
سازندگان دستگاه باید رمپ رنگ را بر اساس ویژگی های صفحه نمایش دستگاه از جمله نقطه سفید، وسعت و رنگ دلخواه سفارشی کنند. با استفاده از یک پوشش پیکربندی، میتوانید رمپ رنگ را بدون تغییر پیادهسازی پایه تغییر دهید. این پیکربندی به عنوان یک معادله درجه دوم برای هر یک از قرمز، سبز و آبی، به شکل v res = v a t 2 + v b t + v y-int بیان می شود که در آن t ورودی دما بر حسب کلوین است، همانطور که در مشخص شده است. محدوده بین config_nightDisplayColorTemperatureMin
و config_nightDisplayColorTemperatureMax
(همانطور که در بخش قبل توضیح داده شد)، و v a ، v b ، و v y-int به ترتیب ضریب a، b-ضریب و y-برق برای منحنی اولیه داده شده هستند، به عنوان در زیر نشان داده شده است.
<string-array name="config_nightDisplayColorTemperatureCoefficientsNative">
<!-- R a-coefficient --> <item>0.0</item>
<!-- R b-coefficient --> <item>0.0</item>
<!-- R y-intercept --> <item>1.0</item>
<!-- G a-coefficient --> <item>-0.00000000962353339</item>
<!-- G b-coefficient --> <item>0.000153045476</item>
<!-- G y-intercept --> <item>0.390782778</item>
<!-- B a-coefficient --> <item>-0.0000000189359041</item>
<!-- B b-coefficient --> <item>0.000302412211</item>
<!-- B y-intercept --> <item>-0.198650895</item>
</string-array>
<string-array name="config_nightDisplayColorTemperatureCoefficients">
<!-- R a-coefficient --> <item>0.0</item>
<!-- R b-coefficient --> <item>0.0</item>
<!-- R y-intercept --> <item>1.0</item>
<!-- G a-coefficient --> <item>-0.00000000962353339</item>
<!-- G b-coefficient --> <item>0.000153045476</item>
<!-- G y-intercept --> <item>0.390782778</item>
<!-- B a-coefficient --> <item>-0.0000000189359041</item>
<!-- B b-coefficient --> <item>0.000302412211</item>
<!-- B y-intercept --> <item>-0.198650895</item>
</string-array>
ویژگی های رابط کاربری
از آنجایی که Night Light یک ویژگی برای کاربر است، کاربران باید بتوانند آن را کنترل کنند. اجرای کامل تنظیمات در بستهها/برنامهها/پروژه تنظیمات پروژه منبع باز Android (AOSP) وجود دارد که سازندگان دستگاه میتوانند برای اجرای تنظیمات خود به آن مراجعه کنند. پیادهکنندهها باید Settings.ACTION_NIGHT_DISPLAY_SETTINGS
انجام دهند.ACTION_NIGHT_DISPLAY_SETTINGS برای افشای این تنظیم.
تنظیمات
تنظیمات Night Light در Settings > Display > Night Light هستند. از آنجا، کاربران می توانند درباره نور شب بیاموزند، برنامه آن را تنظیم کنند و آن را روشن یا خاموش کنند.
- به صورت خودکار روشن شود
- هرگز: نور شب هرگز به طور خودکار روشن نمی شود و باید با کلید روشن/خاموش دستی فعال شود.
- برنامه زمانی سفارشی: چراغ شب در زمان شروع مشخص شده [پیشفرض: 10:30 شب] روشن میشود و در زمان پایان مشخص شده خاموش میشود [پیشفرض: 6:30 صبح].
- غروب تا طلوع آفتاب: نور شب هنگام غروب روشن و با طلوع خورشید خاموش می شود. زمان طلوع و غروب خورشید به مکان دستگاه و زمان سال بستگی دارد.
- روشن/خاموش: کلیدی که وضعیت فعلی نور شب را کنترل می کند. این حالت به قوانین خودکار موجود احترام می گذارد. برای مثال، اگر نور شب در ساعت 5:30 بعد از ظهر روشن شود (قبل از اینکه قانون خودکار آن را در ساعت 10:30 شب روشن کند)، نور شب همچنان در ساعت 6:30 صبح خاموش می شود و اگر نور شب در ساعت 5 خاموش شود. :30 صبح (قبل از اینکه ساعت 6:30 صبح خاموش شود)، همچنان در ساعت 10:30 شب روشن می شود
- شدت: Seekbar که سطح رنگ را با لغزش از گرم به سرد کنترل می کند. هنگامی که Night Light فعال نیست، می توان نوار جستجو را غیرفعال کرد.
- متن اطلاع رسانی: به کاربر آموزش می دهد که نور شب چه کاری انجام می دهد و چرا.
تنظیمات مشروط
وقتی نور شب روشن است در بالای تنظیمات قابل مشاهده است.
کاشی تنظیمات سریع
کاشی تنظیمات سریع مانند کلید روشن / خاموش در تنظیمات > نمایشگر > نور شب رفتار می کند.
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و OpenJDK علامتهای تجاری یا علامتهای تجاری ثبتشده Oracle و/یا وابستههای آن هستند.
تاریخ آخرین بهروزرسانی 2025-07-29 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","easyToUnderstand","thumb-up"],["مشکلم را برطرف کرد","solvedMyProblem","thumb-up"],["غیره","otherUp","thumb-up"]],[["اطلاعاتی که نیاز دارم وجود ندارد","missingTheInformationINeed","thumb-down"],["بیشازحد پیچیده/ مراحل بسیار زیاد","tooComplicatedTooManySteps","thumb-down"],["قدیمی","outOfDate","thumb-down"],["مشکل ترجمه","translationIssue","thumb-down"],["مشکل کد / نمونهها","samplesCodeIssue","thumb-down"],["غیره","otherDown","thumb-down"]],["تاریخ آخرین بهروزرسانی 2025-07-29 بهوقت ساعت هماهنگ جهانی."],[],[],null,["# Implement night light\n\nResearch suggests that blue light from screens can have a negative impact on\nsleep. Android 7.1.1 introduced a feature called Night Light that reduces the\namount of blue light emitted by the device display to better match the natural\nlight of the user's time of day and location. Android 8.0 introduced an additional\nfeature that gives users more control over the intensity of the Night Light effect.\nAndroid 10 introduces the\n`COLOR_DISPLAY_SERVICE` system service, with a system API\nsurface to give the system, Settings, and System UI more control over all color\ntransforms, including Night Light.\n\n\nNight Light requires a\n[Hardware\nComposer HAL 2.0](/docs/core/graphics/implement-hwc) (HWC 2) implementation that can apply the matrix passed to\n`setColorTransform` to perform tinting without impacting power,\nperformance, and app compatibility.\n\nImplementation\n--------------\n\n\nDevice manufacturers can enable the default implementation of the feature by\nusing the following flags defined in\n[frameworks/base/core/res/res/values/config.xml](https://android.googlesource.com/platform/frameworks/base/+/android16-release/core/res/res/values/config.xml)\n\n```\n \u003c!-- Control whether Night display is available. This should only be enabled\n on devices with HWC 2 color transform support. --\u003e\n \u003cbool name=\"config_nightDisplayAvailable\"\u003efalse\u003c/bool\u003e\n \u003c!-- Default mode to control how Night display is automatically activated.\n One of the following values (see NightDisplayController.java):\n 0 - AUTO_MODE_DISABLED\n 1 - AUTO_MODE_CUSTOM\n 2 - AUTO_MODE_TWILIGHT\n --\u003e\n \u003cinteger name=\"config_defaultNightDisplayAutoMode\"\u003e0\u003c/integer\u003e\n \u003c!-- Default time when Night display is automatically activated.\n Represented as milliseconds from midnight (e.g. 79200000 == 10pm). --\u003e\n \u003cinteger name=\"config_defaultNightDisplayCustomStartTime\"\u003e79200000\u003c/integer\u003e\n \u003c!-- Default time when Night display is automatically deactivated.\n Represented as milliseconds from midnight (e.g. 21600000 == 6am). --\u003e\n \u003cinteger name=\"config_defaultNightDisplayCustomEndTime\"\u003e21600000\u003c/integer\u003e\n\n \u003c!-- Minimum color temperature, in Kelvin, supported by Night display. --\u003e\n \u003cinteger name=\"config_nightDisplayColorTemperatureMin\"\u003e2596\u003c/integer\u003e\n \u003c!-- Default color temperature, in Kelvin, to tint the screen when Night display is\n activated. --\u003e\n \u003cinteger name=\"config_nightDisplayColorTemperatureDefault\"\u003e2850\u003c/integer\u003e\n \u003c!-- Maximum color temperature, in Kelvin, supported by Night display. --\u003e\n \u003cinteger name=\"config_nightDisplayColorTemperatureMax\"\u003e4082\u003c/integer\u003e\n```\n\n\nThe code is divided between framework, system services, System UI, and Settings. The\ncore functionality is controlled by `ColorDisplayManager` (backed by\n`ColorDisplayService`).\n\n\nDevice manufacturers should customize the color ramp based on the characteristics of the\ndevice's display panel, including white point, gamut, and desired color. You can change the\ncolor ramp without changing the base implementation by using a configuration overlay.\nThis configuration is expressed as a quadratic equation for each of red, green, and blue,\nin the form v~res~ = v~a~t^2^ + v~b~t + v~y-int~\nwhere t is the temperature input in Kelvin, as specified in the range between\n`config_nightDisplayColorTemperatureMin` and\n`config_nightDisplayColorTemperatureMax` (as described\nin the previous section), and v~a~, v~b~, and v~y-int~ are the\na-coefficient, b-coefficient, and y-intercept, respectively, for the given primary's curve,\nas indicated below. \n\n```\n \u003cstring-array name=\"config_nightDisplayColorTemperatureCoefficientsNative\"\u003e\n \u003c!-- R a-coefficient --\u003e \u003citem\u003e0.0\u003c/item\u003e\n \u003c!-- R b-coefficient --\u003e \u003citem\u003e0.0\u003c/item\u003e\n \u003c!-- R y-intercept --\u003e \u003citem\u003e1.0\u003c/item\u003e\n \u003c!-- G a-coefficient --\u003e \u003citem\u003e-0.00000000962353339\u003c/item\u003e\n \u003c!-- G b-coefficient --\u003e \u003citem\u003e0.000153045476\u003c/item\u003e\n \u003c!-- G y-intercept --\u003e \u003citem\u003e0.390782778\u003c/item\u003e\n \u003c!-- B a-coefficient --\u003e \u003citem\u003e-0.0000000189359041\u003c/item\u003e\n \u003c!-- B b-coefficient --\u003e \u003citem\u003e0.000302412211\u003c/item\u003e\n \u003c!-- B y-intercept --\u003e \u003citem\u003e-0.198650895\u003c/item\u003e\n \u003c/string-array\u003e\n\n \u003cstring-array name=\"config_nightDisplayColorTemperatureCoefficients\"\u003e\n \u003c!-- R a-coefficient --\u003e \u003citem\u003e0.0\u003c/item\u003e\n \u003c!-- R b-coefficient --\u003e \u003citem\u003e0.0\u003c/item\u003e\n \u003c!-- R y-intercept --\u003e \u003citem\u003e1.0\u003c/item\u003e\n \u003c!-- G a-coefficient --\u003e \u003citem\u003e-0.00000000962353339\u003c/item\u003e\n \u003c!-- G b-coefficient --\u003e \u003citem\u003e0.000153045476\u003c/item\u003e\n \u003c!-- G y-intercept --\u003e \u003citem\u003e0.390782778\u003c/item\u003e\n \u003c!-- B a-coefficient --\u003e \u003citem\u003e-0.0000000189359041\u003c/item\u003e\n \u003c!-- B b-coefficient --\u003e \u003citem\u003e0.000302412211\u003c/item\u003e\n \u003c!-- B y-intercept --\u003e \u003citem\u003e-0.198650895\u003c/item\u003e\n \u003c/string-array\u003e\n```\n\nUI features\n-----------\n\n\nBecause Night Light is a user-facing feature, users need to be able to control\nit. There is a full implementation of the settings in the Android Open Source\nProject (AOSP)\n[packages/apps/Settings](https://android.googlesource.com/platform/packages/apps/Settings/)\nproject that device manufacturers can reference for their Settings\nimplementation. Implementers must handle the\n[Settings.ACTION_NIGHT_DISPLAY_SETTINGS](https://developer.android.com/reference/android/provider/Settings.html#ACTION_NIGHT_DISPLAY_SETTINGS)\nintent to expose this setting.\n\n### Settings\n\n\nThe settings for Night Light are in *Settings \\\u003e Display \\\u003e Night\nLight*. From there, users can learn about Night Light, set its schedule,\nand turn it on or off.\n\n- **Turn On Automatically**\n - **Never:** Night Light will never turn on automatically and must be activated with the manual **On / Off** toggle.\n - **Custom schedule:** Night Light turns on at a specified **Start time** \\[default: 10:30 p.m.\\] and off at a specified **End time** \\[default: 6:30 a.m.\\].\n - **Sunset to sunrise:** Night Light turns on at sunset and off at sunrise. The time for sunrise and sunset depends on the device location and the time of year.\n- **On / Off:** Toggle that controls the current state of Night Light. This state respects existing automatic rules. For example, if Night Light is toggled on at 5:30 p.m. (before the automatic rule would turn it on at 10:30 p.m.), Night Light will still turn off at 6:30 a.m. And if Night Light is toggled off at 5:30 a.m. (before it turns off at 6:30 a.m.), it will still turn on at 10:30 p.m.\n- **Intensity:** [Seekbar](https://developer.android.com/reference/android/widget/SeekBar.html) that controls the tint level by sliding from warm to cool. The seekbar can be disabled when Night Light is not activated.\n- **Informational text:** Teaches the user what Night Light does and why.\n\n### Settings conditional\n\n\nVisible at the top of Settings when Night Light is on.\n\n### Quick Settings tile\n\n\nThe Quick Settings tile behaves identically to the **On / Off**\ntoggle in *Settings \\\u003e Display \\\u003e Night Light*."]]