1/* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15import {AsyncCallback} from './basic'; 16import image from './@ohos.multimedia.image'; 17 18/** 19 * System wallpaper 20 * @sysCap SystemCapability.Miscservices.Wallpaper 21 * @devices phone, tablet, tv, wearable, car 22 * @import import wallpaper from '@ohos.app.wallpaper'; 23 * @since 7 24 */ 25declare namespace wallpaper { 26 enum WallpaperType { 27 /** 28 * Indicates the home screen wallpaper. 29 */ 30 WALLPAPER_SYSTEM, 31 /** 32 * Indicates the lock screen wallpaper. 33 */ 34 WALLPAPER_LOCKSCREEN 35 } 36 37 /** 38 * Obtains the wallpaper colors for the wallpaper of the specified type. 39 * @param wallpaperType Indicates the wallpaper type. 40 * @return RgbaColor type of array callback function 41 */ 42 function getColors(wallpaperType: WallpaperType, callback: AsyncCallback<Array<RgbaColor>>): void; 43 function getColors(wallpaperType: WallpaperType): Promise<Array<RgbaColor>>; 44 45 /** 46 * Obtains the ID of the wallpaper of the specified type. 47 * @param wallpaperType Indicates the wallpaper type. 48 * @return an integer greater than or equal to {@code 0} representing the wallpaper ID 49 * if the specified type of wallpaper has been set; returns {@code -1} otherwise. 50 * The return value is an integer ranging from -1 to 2^31 - 1. 51 */ 52 function getId(wallpaperType: WallpaperType, callback: AsyncCallback<number>): void; 53 function getId(wallpaperType: WallpaperType): Promise<number>; 54 55 /** 56 * Obtains the minimum height of the wallpaper. 57 * @return the minimum height, in pixels; returns {@code 0} if no wallpaper has been set. 58 */ 59 function getMinHeight(callback: AsyncCallback<number>): void; 60 function getMinHeight(): Promise<number>; 61 62 /** 63 * Obtains the minimum width of the wallpaper. 64 * @return the minimum width, in pixels; returns {@code 0} if no wallpaper has been set. 65 */ 66 function getMinWidth(callback: AsyncCallback<number>): void; 67 function getMinWidth(): Promise<number>; 68 69 /** 70 * Checks whether to allow the application to change the wallpaper for the current user. 71 * @return true if the application is allowed to set a wallpaper for the current user; 72 */ 73 function isChangePermitted(callback: AsyncCallback<boolean>): void; 74 function isChangePermitted(): Promise<boolean>; 75 76 /** 77 * Checks whether a user is allowed to set wallpapers. 78 * @return true if a user is allowed to set wallpapers; returns false otherwise. 79 */ 80 function isOperationAllowed(callback: AsyncCallback<boolean>): void; 81 function isOperationAllowed(): Promise<boolean>; 82 83 /** 84 * Removes a wallpaper of the specified type and restores the default one. 85 * @param wallpaperType Indicates the wallpaper type. 86 * @permission ohos.permission.SET_WALLPAPER 87 */ 88 function reset(wallpaperType: WallpaperType, callback: AsyncCallback<void>): void; 89 function reset(wallpaperType: WallpaperType): Promise<void>; 90 91 /** 92 * Sets a wallpaper of the specified type based on the uri path from a JPEG or PNG file or the pixel map of a PNG file. 93 * @param source Indicates the uri path from a JPEG or PNG file or the pixel map of the PNG file. 94 * @param wallpaperType Indicates the wallpaper type. 95 * @permission ohos.permission.SET_WALLPAPER 96 */ 97 function setWallpaper(source: string | image.PixelMap, wallpaperType: WallpaperType, callback: AsyncCallback<void>): void; 98 function setWallpaper(source: string | image.PixelMap, wallpaperType: WallpaperType): Promise<void>; 99 100 /** 101 * Obtains the default pixel map of a wallpaper of the specified type. 102 * @param wallpaperType Indicates the wallpaper type. 103 * @return the default pixel map. 104 * @permission ohos.permission.GET_WALLPAPER 105 * @permission ohos.permission.READ_USER_STORAGE 106 * @systemapi Hide this for inner system use. 107 */ 108 function getPixelMap(wallpaperType: WallpaperType, callback: AsyncCallback<image.PixelMap>): void; 109 function getPixelMap(wallpaperType: WallpaperType): Promise<image.PixelMap>; 110 111 /** 112 * Registers a listener for wallpaper color changes to receive notifications about the changes. 113 * @param type The incoming colorChange table open receiver pick a color change wallpaper wallpaper color changes 114 * @param callback Provides dominant colors of the wallpaper. 115 */ 116 function on(type: 'colorChange', callback: (colors: Array<RgbaColor>, wallpaperType: WallpaperType) => void): void; 117 118 /** 119 * Unregisters a listener for wallpaper color changes. 120 * @param type Incoming 'colorChange' table delete receiver to pick up a color change wallpaper wallpaper color changes 121 * @param callback Provides dominant colors of the wallpaper. 122 */ 123 function off(type: 'colorChange', callback?: (colors: Array<RgbaColor>, wallpaperType: WallpaperType) => void): void; 124 125 interface RgbaColor { 126 /** 127 * Said the red value, the range is 0 to 255. 128 */ 129 red: number; 130 /** 131 * Said the green value, the range is 0 to 255. 132 */ 133 green: number; 134 /** 135 * Said the blue value, the range is 0 to 255. 136 */ 137 blue: number; 138 /** 139 * Said the alpha value, the range is 0 to 255. 140 */ 141 alpha: number; 142 } 143} 144 145export default wallpaper; 146