已开启
HiSpark_AiFly开发板功能适配 #185
jia_kongfeng创建于 8月31日
HiSpark_AiFly开发板功能适配 #185
已开启
共 87 个文件变更+5801-694
| @@ -59,6 +59,7 @@ Note:If the text contains special characters, please escape them according to th | |||
| 59 | <licensefile></licensefile> | 59 | <licensefile></licensefile> |
| 60 | <policylist> | 60 | <policylist> |
| 61 | <policy name="projectPolicy" desc=""> | 61 | <policy name="projectPolicy" desc=""> |
| 62 | + <policyitem type="copyright" name="Copyright (c) 2026 RKH Corp." path=".*" desc="copyright"/> | ||
| 62 | </policy> | 63 | </policy> |
| 63 | </policylist> | 64 | </policylist> |
| 64 | <filefilterlist> | 65 | <filefilterlist> |
| @@ -8,7 +8,7 @@ | |||
| 8 | 8 | ||
| 9 | ## Introduction<a name="section11660541593"></a> | 9 | ## Introduction<a name="section11660541593"></a> |
| 10 | 10 | ||
| 11 | -This repository provides media-related applications, such as the home screen and settings. | 11 | +This repository provides media-related applications, such as the camera, gallery, home screen, sound recorder, and settings. |
| 12 | 12 | ||
| 13 | **Figure 1** Position of this repository \(in the dotted blue box\) in the multimedia subsystem<a name="fig189881143114217"></a> | 13 | **Figure 1** Position of this repository \(in the dotted blue box\) in the multimedia subsystem<a name="fig189881143114217"></a> |
| 14 | -in-the-multimedia-subsystem.png "position-of-this-repository-(in-the-dotted-blue-box)-in-the-multimedia-subsystem") | 14 | -in-the-multimedia-subsystem.png "position-of-this-repository-(in-the-dotted-blue-box)-in-the-multimedia-subsystem") |
| @@ -21,6 +21,7 @@ applications/sample/camera | |||
| 21 | ├── gallery # Photo gallery | 21 | ├── gallery # Photo gallery |
| 22 | ├── launcher # Home screen | 22 | ├── launcher # Home screen |
| 23 | ├── media # Apps of photographing, video recording, and audio and video playback | 23 | ├── media # Apps of photographing, video recording, and audio and video playback |
| 24 | +├── recorder # Sound recorder app | ||
| 24 | └── setting # Settings | 25 | └── setting # Settings |
| 25 | ``` | 26 | ``` |
| 26 | 27 | ||
| @@ -8,7 +8,7 @@ | |||
| 8 | 8 | ||
| 9 | ## 简介<a name="section11660541593"></a> | 9 | ## 简介<a name="section11660541593"></a> |
| 10 | 10 | ||
| 11 | -CAMERA\_SAMPLE\_APP组件,提供媒体能力开发的相关应用,提供桌面应用和设置应用。 | 11 | +CAMERA\_SAMPLE\_APP组件,提供媒体能力开发的相关应用,包括相机、图库、桌面、录音机和设置等应用。 |
| 12 | 12 | ||
| 13 | **图 1** 媒体子系统架构(蓝色虚线框是sample\_app)<a name="fig189881143114217"></a> | 13 | **图 1** 媒体子系统架构(蓝色虚线框是sample\_app)<a name="fig189881143114217"></a> |
| 14 | .png "媒体子系统架构(蓝色虚线框是sample_app)") | 14 | .png "媒体子系统架构(蓝色虚线框是sample_app)") |
| @@ -21,6 +21,7 @@ applications/sample/camera | |||
| 21 | ├── gallery 图库应用 | 21 | ├── gallery 图库应用 |
| 22 | ├── launcher 桌面应用 | 22 | ├── launcher 桌面应用 |
| 23 | ├── media 拍照录像应用和音视频播放应用 | 23 | ├── media 拍照录像应用和音视频播放应用 |
| 24 | +├── recorder 录音应用 | ||
| 24 | └── setting 设置 | 25 | └── setting 设置 |
| 25 | ``` | 26 | ``` |
| 26 | 27 | ||
| @@ -33,6 +33,7 @@ | |||
| 33 | "syspara_lite", | 33 | "syspara_lite", |
| 34 | "camera_lite", | 34 | "camera_lite", |
| 35 | "media_lite", | 35 | "media_lite", |
| 36 | + "audio_lite", | ||
| 36 | "permission", | 37 | "permission", |
| 37 | "samgr_lite", | 38 | "samgr_lite", |
| 38 | "utils_base" | 39 | "utils_base" |
| @@ -48,6 +49,8 @@ | |||
| 48 | "//applications/sample/camera/cameraApp:cameraApp_hap", | 49 | "//applications/sample/camera/cameraApp:cameraApp_hap", |
| 49 | "//applications/sample/camera/setting:setting_hap", | 50 | "//applications/sample/camera/setting:setting_hap", |
| 50 | "//applications/sample/camera/gallery:gallery_hap", | 51 | "//applications/sample/camera/gallery:gallery_hap", |
| 52 | + "//applications/sample/camera/recorder:recorder_grop", | ||
| 53 | + "//applications/sample/camera/gallery:test_jpeg", | ||
| 51 | "//applications/sample/camera/media:media_sample", | 54 | "//applications/sample/camera/media:media_sample", |
| 52 | "//applications/sample/camera/graphic:graphic_hap", | 55 | "//applications/sample/camera/graphic:graphic_hap", |
| 53 | "//applications/sample/camera/talm:talm_hap" | 56 | "//applications/sample/camera/talm:talm_hap" |
| @@ -56,4 +59,4 @@ | |||
| 56 | "test": [] | 59 | "test": [] |
| 57 | } | 60 | } |
| 58 | } | 61 | } |
| 59 | -} | 62 | +} |
| @@ -34,11 +34,13 @@ shared_library("cameraApp") { | |||
| 34 | 34 | ||
| 35 | include_dirs = [ | 35 | include_dirs = [ |
| 36 | "cameraApp/src/main/cpp", | 36 | "cameraApp/src/main/cpp", |
| 37 | + "..", | ||
| 37 | "${aafwk_lite_path}/interfaces/kits/ability_lite", | 38 | "${aafwk_lite_path}/interfaces/kits/ability_lite", |
| 38 | "${appexecfwk_lite_path}/interfaces/kits/bundle_lite", | 39 | "${appexecfwk_lite_path}/interfaces/kits/bundle_lite", |
| 39 | "${aafwk_lite_path}/interfaces/kits/want_lite", | 40 | "${aafwk_lite_path}/interfaces/kits/want_lite", |
| 40 | "//foundation/multimedia/camera_lite/interfaces/kits", | 41 | "//foundation/multimedia/camera_lite/interfaces/kits", |
| 41 | "//foundation/multimedia/camera_lite/interfaces/kits", | 42 | "//foundation/multimedia/camera_lite/interfaces/kits", |
| 43 | + "//foundation/arkui/ui_lite/frameworks", | ||
| 42 | ] | 44 | ] |
| 43 | ldflags = [ | 45 | ldflags = [ |
| 44 | "-L$ohos_root_path/sysroot/usr/lib", | 46 | "-L$ohos_root_path/sysroot/usr/lib", |
| @@ -20,6 +20,7 @@ | |||
| 20 | 20 | ||
| 21 | #include "ability_manager.h" | 21 | #include "ability_manager.h" |
| 22 | #include "gfx_utils/color.h" | 22 | #include "gfx_utils/color.h" |
| 23 | +#include "imgdecode/cache_manager.h" | ||
| 23 | #include "ui_config.h" | 24 | #include "ui_config.h" |
| 24 | #include "securec.h" | 25 | #include "securec.h" |
| 25 | 26 | ||
| @@ -100,17 +101,20 @@ private: | |||
| 100 | 101 | ||
| 101 | void BackViewSetImage(const char *image) | 102 | void BackViewSetImage(const char *image) |
| 102 | { | 103 | { |
| 104 | + CacheManager::GetInstance().Close(image); | ||
| 103 | backgroundView_->SetSrc(image); | 105 | backgroundView_->SetSrc(image); |
| 104 | int16_t imageWidth = backgroundView_->GetWidth(); | 106 | int16_t imageWidth = backgroundView_->GetWidth(); |
| 105 | int16_t imageHeight = backgroundView_->GetHeight(); | 107 | int16_t imageHeight = backgroundView_->GetHeight(); |
| 106 | - if (imageWidth > SCREEN_WIDTH || imageHeight > SCREEN_HEIGHT) { | 108 | + if (imageWidth > V_GROUP_W() || imageHeight > V_GROUP_H()) { |
| 107 | TransformMap transMap(backgroundView_->GetOrigRect()); | 109 | TransformMap transMap(backgroundView_->GetOrigRect()); |
| 108 | float scaleWidth = 1.0; | 110 | float scaleWidth = 1.0; |
| 109 | float scaleHeight = 1.0; | 111 | float scaleHeight = 1.0; |
| 110 | - if (imageWidth > SCREEN_WIDTH) | 112 | + if (imageWidth > V_GROUP_W() && imageWidth > 0) { |
| 111 | - scaleWidth = static_cast<float>(SCREEN_WIDTH) / imageWidth; | 113 | + scaleWidth = static_cast<float>(V_GROUP_W()) / imageWidth; |
| 112 | - if (imageHeight > SCREEN_HEIGHT) | 114 | + } |
| 113 | - scaleHeight = static_cast<float>(SCREEN_HEIGHT) / imageHeight; | 115 | + if (imageHeight > V_GROUP_H() && imageHeight > 0) { |
| 116 | + scaleHeight = static_cast<float>(V_GROUP_H()) / imageHeight; | ||
| 117 | + } | ||
| 114 | #ifdef KEEP_PICTURE_RECT | 118 | #ifdef KEEP_PICTURE_RECT |
| 115 | float scale = (scaleWidth < scaleHeight) ? scaleWidth : scaleHeight; | 119 | float scale = (scaleWidth < scaleHeight) ? scaleWidth : scaleHeight; |
| 116 | 120 | ||
| @@ -128,8 +132,8 @@ private: | |||
| 128 | imageHeight = imageHeight * scaleHeight; | 132 | imageHeight = imageHeight * scaleHeight; |
| 129 | #endif | 133 | #endif |
| 130 | } | 134 | } |
| 131 | - int16_t imagePosX = (SCREEN_WIDTH - imageWidth) / 2; /* 2 half */ | 135 | + int16_t imagePosX = (V_GROUP_W() - imageWidth) / 2; /* 2 half */ |
| 132 | - int16_t imagePosY = (SCREEN_HEIGHT - imageHeight) / 2; /* 2 half */ | 136 | + int16_t imagePosY = (V_GROUP_H() - imageHeight) / 2; /* 2 half */ |
| 133 | backgroundView_->SetPosition(imagePosX, imagePosY); | 137 | backgroundView_->SetPosition(imagePosX, imagePosY); |
| 134 | } | 138 | } |
| 135 | }; | 139 | }; |
| @@ -243,6 +247,11 @@ private: | |||
| 243 | UILabel *tmLabel; | 247 | UILabel *tmLabel; |
| 244 | void StartGallery(void) | 248 | void StartGallery(void) |
| 245 | { | 249 | { |
| 250 | +#ifdef MEDIA_INTERFACE_V1_0 | ||
| 251 | + if (cManager_) { | ||
| 252 | + cManager_->SampleCameraStop(); | ||
| 253 | + } | ||
| 254 | +#endif | ||
| 246 | Want want1 = { nullptr }; | 255 | Want want1 = { nullptr }; |
| 247 | ElementName element = { nullptr }; | 256 | ElementName element = { nullptr }; |
| 248 | SetElementBundleName(&element, "com.huawei.gallery"); | 257 | SetElementBundleName(&element, "com.huawei.gallery"); |
| @@ -259,9 +268,9 @@ private: | |||
| 259 | return; | 268 | return; |
| 260 | } | 269 | } |
| 261 | g_curButtonIdx = 1; | 270 | g_curButtonIdx = 1; |
| 262 | - bttnLeft->SetPosition(LEFT_BUTTON_X, LEFT_BUTTON_Y, LEFT_BUTTON_W, LEFT_BUTTON_H); | 271 | + bttnLeft->SetPosition(LEFT_BUTTON_X(), LEFT_BUTTON_Y(), LEFT_BUTTON_W(), LEFT_BUTTON_H()); |
| 263 | - bttnMidle->SetPosition(MID_BUTTON_X, MID_BUTTON_Y, MID_BUTTON_W, MID_BUTTON_H); | 272 | + bttnMidle->SetPosition(MID_BUTTON_X(), MID_BUTTON_Y(), MID_BUTTON_W(), MID_BUTTON_H()); |
| 264 | - bttnRight->SetPosition(RIGHT_BUTTON_X, RIGHT_BUTTON_Y, RIGHT_BUTTON_W, RIGHT_BUTTON_H); | 273 | + bttnRight->SetPosition(RIGHT_BUTTON_X(), RIGHT_BUTTON_Y(), RIGHT_BUTTON_W(), RIGHT_BUTTON_H()); |
| 265 | bttnMidle->SetSrc(UI_IMAGE_PATH"ic_camera_shutter.png"); | 274 | bttnMidle->SetSrc(UI_IMAGE_PATH"ic_camera_shutter.png"); |
| 266 | bttnRight->SetSrc(UI_IMAGE_PATH"ic_camera_video.png"); | 275 | bttnRight->SetSrc(UI_IMAGE_PATH"ic_camera_video.png"); |
| 267 | } else { | 276 | } else { |
| @@ -275,8 +284,8 @@ private: | |||
| 275 | { | 284 | { |
| 276 | if (g_curButtonIdx != 2) { /* 2 record */ | 285 | if (g_curButtonIdx != 2) { /* 2 record */ |
| 277 | g_curButtonIdx = 2; /* 2 record */ | 286 | g_curButtonIdx = 2; /* 2 record */ |
| 278 | - bttnRight->SetPosition(MID_BUTTON_X, MID_BUTTON_Y, MID_BUTTON_W, MID_BUTTON_H); | 287 | + bttnRight->SetPosition(MID_BUTTON_X(), MID_BUTTON_Y(), MID_BUTTON_W(), MID_BUTTON_H()); |
| 279 | - bttnMidle->SetPosition(RIGHT_BUTTON_X, RIGHT_BUTTON_Y, RIGHT_BUTTON_W, RIGHT_BUTTON_H); | 288 | + bttnMidle->SetPosition(RIGHT_BUTTON_X(), RIGHT_BUTTON_Y(), RIGHT_BUTTON_W(), RIGHT_BUTTON_H()); |
| 280 | 289 | ||
| 281 | bttnMidle->SetSrc(UI_IMAGE_PATH"ic_camera_record_camra.png"); | 290 | bttnMidle->SetSrc(UI_IMAGE_PATH"ic_camera_record_camra.png"); |
| 282 | bttnRight->SetSrc(UI_IMAGE_PATH"ic_camera_record.png"); | 291 | bttnRight->SetSrc(UI_IMAGE_PATH"ic_camera_record.png"); |
| @@ -324,17 +333,20 @@ private: | |||
| 324 | 333 | ||
| 325 | void BackViewSetImage(const char *image) | 334 | void BackViewSetImage(const char *image) |
| 326 | { | 335 | { |
| 336 | + CacheManager::GetInstance().Close(image); | ||
| 327 | backgroundView_->SetSrc(image); | 337 | backgroundView_->SetSrc(image); |
| 328 | int16_t imageWidth = backgroundView_->GetWidth(); | 338 | int16_t imageWidth = backgroundView_->GetWidth(); |
| 329 | int16_t imageHeight = backgroundView_->GetHeight(); | 339 | int16_t imageHeight = backgroundView_->GetHeight(); |
| 330 | - if (imageWidth > SCREEN_WIDTH || imageHeight > SCREEN_HEIGHT) { | 340 | + if (imageWidth > V_GROUP_W() || imageHeight > V_GROUP_H()) { |
| 331 | TransformMap transMap(backgroundView_->GetOrigRect()); | 341 | TransformMap transMap(backgroundView_->GetOrigRect()); |
| 332 | float scaleWidth = 1.0; | 342 | float scaleWidth = 1.0; |
| 333 | float scaleHeight = 1.0; | 343 | float scaleHeight = 1.0; |
| 334 | - if (imageWidth > SCREEN_WIDTH) | 344 | + if (imageWidth > V_GROUP_W() && imageWidth > 0) { |
| 335 | - scaleWidth = static_cast<float>(SCREEN_WIDTH) / imageWidth; | 345 | + scaleWidth = static_cast<float>(V_GROUP_W()) / imageWidth; |
| 336 | - if (imageHeight > SCREEN_HEIGHT) | 346 | + } |
| 337 | - scaleHeight = static_cast<float>(SCREEN_HEIGHT) / imageHeight; | 347 | + if (imageHeight > V_GROUP_H() && imageHeight > 0) { |
| 348 | + scaleHeight = static_cast<float>(V_GROUP_H()) / imageHeight; | ||
| 349 | + } | ||
| 338 | float scale = (scaleWidth < scaleHeight) ? scaleWidth : scaleHeight; | 350 | float scale = (scaleWidth < scaleHeight) ? scaleWidth : scaleHeight; |
| 339 | 351 | ||
| 340 | transMap.Scale(Vector2<float>(scale, scale), Vector2<float>(0, 0)); | 352 | transMap.Scale(Vector2<float>(scale, scale), Vector2<float>(0, 0)); |
| @@ -343,8 +355,8 @@ private: | |||
| 343 | imageWidth = imageWidth * scale; | 355 | imageWidth = imageWidth * scale; |
| 344 | imageHeight = imageHeight * scale; | 356 | imageHeight = imageHeight * scale; |
| 345 | } | 357 | } |
| 346 | - int16_t imagePosX = (SCREEN_WIDTH - imageWidth) / 2; /* 2 half */ | 358 | + int16_t imagePosX = (V_GROUP_W() - imageWidth) / 2; /* 2 half */ |
| 347 | - int16_t imagePosY = (SCREEN_HEIGHT - imageHeight) / 2; /* 2 half */ | 359 | + int16_t imagePosY = (V_GROUP_H() - imageHeight) / 2; /* 2 half */ |
| 348 | backgroundView_->SetPosition(imagePosX, imagePosY); | 360 | backgroundView_->SetPosition(imagePosX, imagePosY); |
| 349 | } | 361 | } |
| 350 | }; | 362 | }; |
| @@ -378,12 +390,14 @@ void CameraAbilitySlice::SetHead(void) | |||
| 378 | { | 390 | { |
| 379 | backIcon = new UIImageView(); | 391 | backIcon = new UIImageView(); |
| 380 | backIcon->SetTouchable(true); | 392 | backIcon->SetTouchable(true); |
| 393 | + backIcon->SetAutoEnable(false); | ||
| 394 | + backIcon->SetResizeMode(UIImageView::ImageResizeMode::COVER); | ||
| 381 | backIcon->SetSrc(UI_IMAGE_PATH"ic_back.png"); | 395 | backIcon->SetSrc(UI_IMAGE_PATH"ic_back.png"); |
| 382 | - backIcon->SetPosition(BACK_LABEL_X, BACK_LABEL_Y, BACK_LABEL_W, BACK_LABEL_H); | 396 | + backIcon->SetPosition(BACK_LABEL_X(), BACK_LABEL_Y(), BACK_LABEL_W(), BACK_LABEL_H()); |
| 383 | 397 | ||
| 384 | backBttn = new UIImageView(); | 398 | backBttn = new UIImageView(); |
| 385 | backBttn->SetTouchable(true); | 399 | backBttn->SetTouchable(true); |
| 386 | - backBttn->SetPosition(0, 0, BACK_LABEL_W * 4, BACK_LABEL_H * 4); /* 4 cups of icon size */ | 400 | + backBttn->SetPosition(0, 0, BACK_LABEL_W() * 4, BACK_LABEL_H() * 4); /* 4 cups of icon size */ |
| 387 | backBttn->SetStyle(STYLE_BACKGROUND_OPA, 0); | 401 | backBttn->SetStyle(STYLE_BACKGROUND_OPA, 0); |
| 388 | auto backBttnonClick = [this](UIView &view, const Event &event) -> bool { | 402 | auto backBttnonClick = [this](UIView &view, const Event &event) -> bool { |
| 389 | printf("############ from launcher enter #############\n"); | 403 | printf("############ from launcher enter #############\n"); |
| @@ -397,28 +411,29 @@ void CameraAbilitySlice::SetHead(void) | |||
| 397 | backIcon->SetOnClickListener(buttonListener_); | 411 | backIcon->SetOnClickListener(buttonListener_); |
| 398 | 412 | ||
| 399 | txtMsgLabel = new UILabel(); | 413 | txtMsgLabel = new UILabel(); |
| 400 | - txtMsgLabel->SetPosition(TXT_LABEL_X, TXT_LABEL_Y, TXT_LABEL_W, TXT_LABEL_H); | 414 | + txtMsgLabel->SetPosition(TXT_LABEL_X(), TITLE_LABEL_Y(), TITLE_LABEL_WIDTH(), TITLE_LABEL_HEIGHT()); |
| 401 | txtMsgLabel->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_LEFT, UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); | 415 | txtMsgLabel->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_LEFT, UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); |
| 402 | 416 | ||
| 403 | - txtMsgLabel->SetFont((const char *)TTF_PATH, FONT_SIZE); | 417 | + txtMsgLabel->SetFont((const char *)TTF_PATH, static_cast<uint8_t>(VScale(TITLE_LABEL_FONT_SIZE_REF))); |
| 404 | 418 | ||
| 405 | - txtMsgLabel->SetAlign(TEXT_ALIGNMENT_LEFT); | 419 | + txtMsgLabel->SetStyle(STYLE_TEXT_COLOR, Color::Black().full); |
| 406 | - txtMsgLabel->SetStyle(STYLE_TEXT_COLOR, Color::ColorTo32(Color::White())); | ||
| 407 | txtMsgLabel->SetStyle(STYLE_BACKGROUND_OPA, 0); | 420 | txtMsgLabel->SetStyle(STYLE_BACKGROUND_OPA, 0); |
| 408 | txtMsgLabel->SetText((char *)"相机"); | 421 | txtMsgLabel->SetText((char *)"相机"); |
| 409 | 422 | ||
| 410 | recordImage = new UIImageView(); | 423 | recordImage = new UIImageView(); |
| 411 | recordImage->SetTouchable(false); | 424 | recordImage->SetTouchable(false); |
| 425 | + recordImage->SetAutoEnable(false); | ||
| 426 | + recordImage->SetResizeMode(UIImageView::ImageResizeMode::CONTAIN); | ||
| 412 | recordImage->SetSrc(UI_IMAGE_PATH"ic_timer.png"); | 427 | recordImage->SetSrc(UI_IMAGE_PATH"ic_timer.png"); |
| 413 | - recordImage->SetPosition(RECORD_IMAGE_X, RECORD_IMAGE_Y, RECORD_IMAGE_W, RECORD_IMAGE_H); | 428 | + recordImage->SetPosition(RECORD_IMAGE_X(), RECORD_IMAGE_Y(), RECORD_IMAGE_W(), RECORD_IMAGE_H()); |
| 414 | recordImage->SetStyle(STYLE_BACKGROUND_OPA, 0); | 429 | recordImage->SetStyle(STYLE_BACKGROUND_OPA, 0); |
| 415 | 430 | ||
| 416 | tmLabel = new UILabel(); | 431 | tmLabel = new UILabel(); |
| 417 | - tmLabel->SetPosition(TIME_LABEL_X, TIME_LABEL_Y, TIME_LABEL_W, TIME_LABEL_H); | 432 | + tmLabel->SetPosition(TIME_LABEL_X(), TIME_LABEL_Y(), TIME_LABEL_W(), TIME_LABEL_H()); |
| 418 | tmLabel->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_LEFT, UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); | 433 | tmLabel->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_LEFT, UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); |
| 419 | tmLabel->SetText("00:00"); | 434 | tmLabel->SetText("00:00"); |
| 420 | 435 | ||
| 421 | - tmLabel->SetFont((const char *)TTF_PATH, FONT_SIZE); | 436 | + tmLabel->SetFont((const char *)TTF_PATH, static_cast<uint8_t>(VScale(FONT_SIZE))); |
| 422 | 437 | ||
| 423 | tmLabel->SetStyle(STYLE_TEXT_COLOR, Color::ColorTo32(Color::White())); | 438 | tmLabel->SetStyle(STYLE_TEXT_COLOR, Color::ColorTo32(Color::White())); |
| 424 | tmLabel->SetStyle(STYLE_BACKGROUND_OPA, 0); | 439 | tmLabel->SetStyle(STYLE_BACKGROUND_OPA, 0); |
| @@ -430,42 +445,76 @@ void CameraAbilitySlice::SetHead(void) | |||
| 430 | } | 445 | } |
| 431 | 446 | ||
| 432 | void CameraAbilitySlice::SetBottom(void) | 447 | void CameraAbilitySlice::SetBottom(void) |
| 448 | +{ | ||
| 449 | + SetBottomScroll(); | ||
| 450 | + SetBottomLeftButton(); | ||
| 451 | + SetBottomMidButton(); | ||
| 452 | + SetBottomRightButton(); | ||
| 453 | + SetBottomRecordButton(); | ||
| 454 | + SetBottomSliderAndAnimator(); | ||
| 455 | + SetBottomButtonListeners(); | ||
| 456 | +} | ||
| 457 | + | ||
| 458 | +void CameraAbilitySlice::SetBottomScroll(void) | ||
| 433 | { | 459 | { |
| 434 | scroll = new UIScrollView(); | 460 | scroll = new UIScrollView(); |
| 435 | scroll->SetStyle(STYLE_BACKGROUND_COLOR, Color::ColorTo32(Color::White())); | 461 | scroll->SetStyle(STYLE_BACKGROUND_COLOR, Color::ColorTo32(Color::White())); |
| 436 | scroll->SetStyle(STYLE_BACKGROUND_OPA, 0); | 462 | scroll->SetStyle(STYLE_BACKGROUND_OPA, 0); |
| 437 | - scroll->SetPosition(SCROLL_VIEW_X, SCROLL_VIEW_Y, SCROLL_VIEW_W, SCROLL_VIEW_H); | 463 | + scroll->SetPosition(SCROLL_VIEW_X(), SCROLL_VIEW_Y(), SCROLL_VIEW_W(), SCROLL_VIEW_H()); |
| 438 | scroll->SetHorizontalScrollState(true); | 464 | scroll->SetHorizontalScrollState(true); |
| 439 | scroll->SetVerticalScrollState(false); | 465 | scroll->SetVerticalScrollState(false); |
| 440 | scroll->SetXScrollBarVisible(false); | 466 | scroll->SetXScrollBarVisible(false); |
| 441 | scroll->SetYScrollBarVisible(false); | 467 | scroll->SetYScrollBarVisible(false); |
| 468 | +} | ||
| 442 | 469 | ||
| 470 | +void CameraAbilitySlice::SetBottomLeftButton(void) | ||
| 471 | +{ | ||
| 443 | bttnLeft = new UIImageView(); | 472 | bttnLeft = new UIImageView(); |
| 444 | bttnLeft->SetTouchable(true); | 473 | bttnLeft->SetTouchable(true); |
| 445 | - bttnLeft->SetPosition(LEFT_BUTTON_X, LEFT_BUTTON_Y, LEFT_BUTTON_W, LEFT_BUTTON_H); | 474 | + bttnLeft->SetPosition(LEFT_BUTTON_X(), LEFT_BUTTON_Y(), LEFT_BUTTON_W(), LEFT_BUTTON_H()); |
| 475 | + bttnLeft->SetAutoEnable(false); | ||
| 476 | + bttnLeft->SetResizeMode(UIImageView::ImageResizeMode::COVER); | ||
| 446 | bttnLeft->SetSrc(UI_IMAGE_PATH"ic_camera_photo.png"); | 477 | bttnLeft->SetSrc(UI_IMAGE_PATH"ic_camera_photo.png"); |
| 447 | bttnLeft->SetStyle(STYLE_BACKGROUND_OPA, 0); | 478 | bttnLeft->SetStyle(STYLE_BACKGROUND_OPA, 0); |
| 479 | +} | ||
| 448 | 480 | ||
| 481 | +void CameraAbilitySlice::SetBottomMidButton(void) | ||
| 482 | +{ | ||
| 449 | bttnMidle = new UIImageView(); | 483 | bttnMidle = new UIImageView(); |
| 450 | bttnMidle->SetTouchable(true); | 484 | bttnMidle->SetTouchable(true); |
| 485 | + bttnMidle->SetAutoEnable(false); | ||
| 486 | + bttnMidle->SetResizeMode(UIImageView::ImageResizeMode::COVER); | ||
| 451 | bttnMidle->SetSrc(UI_IMAGE_PATH"ic_camera_shutter.png"); | 487 | bttnMidle->SetSrc(UI_IMAGE_PATH"ic_camera_shutter.png"); |
| 452 | - bttnMidle->SetPosition(MID_BUTTON_X, MID_BUTTON_Y, MID_BUTTON_W, MID_BUTTON_H); | 488 | + bttnMidle->SetPosition(MID_BUTTON_X(), MID_BUTTON_Y(), MID_BUTTON_W(), MID_BUTTON_H()); |
| 453 | bttnMidle->SetStyle(STYLE_BACKGROUND_OPA, 0); | 489 | bttnMidle->SetStyle(STYLE_BACKGROUND_OPA, 0); |
| 490 | +} | ||
| 454 | 491 | ||
| 492 | +void CameraAbilitySlice::SetBottomRightButton(void) | ||
| 493 | +{ | ||
| 455 | bttnRight = new UIImageView(); | 494 | bttnRight = new UIImageView(); |
| 456 | bttnRight->SetTouchable(true); | 495 | bttnRight->SetTouchable(true); |
| 457 | - bttnRight->SetPosition(RIGHT_BUTTON_X, RIGHT_BUTTON_Y, RIGHT_BUTTON_W, RIGHT_BUTTON_H); | 496 | + bttnRight->SetPosition(RIGHT_BUTTON_X(), RIGHT_BUTTON_Y(), RIGHT_BUTTON_W(), RIGHT_BUTTON_H()); |
| 497 | + bttnRight->SetAutoEnable(false); | ||
| 498 | + bttnRight->SetResizeMode(UIImageView::ImageResizeMode::COVER); | ||
| 458 | bttnRight->SetSrc(UI_IMAGE_PATH"ic_camera_video.png"); | 499 | bttnRight->SetSrc(UI_IMAGE_PATH"ic_camera_video.png"); |
| 459 | bttnRight->SetStyle(STYLE_BACKGROUND_OPA, 0); | 500 | bttnRight->SetStyle(STYLE_BACKGROUND_OPA, 0); |
| 501 | +} | ||
| 460 | 502 | ||
| 503 | +void CameraAbilitySlice::SetBottomRecordButton(void) | ||
| 504 | +{ | ||
| 461 | bttnRecord = new UIImageView(); | 505 | bttnRecord = new UIImageView(); |
| 462 | bttnRecord->SetTouchable(true); | 506 | bttnRecord->SetTouchable(true); |
| 463 | - bttnRecord->SetPosition(RIGHT_BUTTON_X, RIGHT_BUTTON_Y, RIGHT_BUTTON_W, RIGHT_BUTTON_H); | 507 | + bttnRecord->SetPosition(RIGHT_BUTTON_X(), RIGHT_BUTTON_Y(), RIGHT_BUTTON_W(), RIGHT_BUTTON_H()); |
| 508 | + bttnRecord->SetAutoEnable(false); | ||
| 509 | + bttnRecord->SetResizeMode(UIImageView::ImageResizeMode::CONTAIN); | ||
| 464 | bttnRecord->SetSrc(UI_IMAGE_PATH"ic_camera_record_pause.png"); | 510 | bttnRecord->SetSrc(UI_IMAGE_PATH"ic_camera_record_pause.png"); |
| 465 | bttnRecord->SetStyle(STYLE_BACKGROUND_OPA, 0); | 511 | bttnRecord->SetStyle(STYLE_BACKGROUND_OPA, 0); |
| 466 | bttnRecord->SetVisible(false); | 512 | bttnRecord->SetVisible(false); |
| 467 | bttnRecord->Invalidate(); | 513 | bttnRecord->Invalidate(); |
| 514 | +} | ||
| 468 | 515 | ||
| 516 | +void CameraAbilitySlice::SetBottomSliderAndAnimator(void) | ||
| 517 | +{ | ||
| 469 | slider = new UISlider(); | 518 | slider = new UISlider(); |
| 470 | slider->SetPosition(-1, -1, 1, 1); | 519 | slider->SetPosition(-1, -1, 1, 1); |
| 471 | 520 | ||
| @@ -473,7 +522,10 @@ void CameraAbilitySlice::SetBottom(void) | |||
| 473 | gTaskView_->TaskStart(); | 522 | gTaskView_->TaskStart(); |
| 474 | 523 | ||
| 475 | animator_ = new SliderAnimator(slider, background_, surfaceView, cam_manager, 10000); /* 10000 = 10s */ | 524 | animator_ = new SliderAnimator(slider, background_, surfaceView, cam_manager, 10000); /* 10000 = 10s */ |
| 525 | +} | ||
| 476 | 526 | ||
| 527 | +void CameraAbilitySlice::SetBottomButtonListeners(void) | ||
| 528 | +{ | ||
| 477 | UIImageView *imageV[BUTTON_NUMS] = {bttnLeft, bttnMidle, bttnRight, bttnRecord}; | 529 | UIImageView *imageV[BUTTON_NUMS] = {bttnLeft, bttnMidle, bttnRight, bttnRecord}; |
| 478 | for (int i = 0; i < BUTTON_NUMS; i++) { | 530 | for (int i = 0; i < BUTTON_NUMS; i++) { |
| 479 | bttnImageClick[i] = | 531 | bttnImageClick[i] = |
| @@ -496,13 +548,15 @@ void CameraAbilitySlice::OnStart(const Want &want) | |||
| 496 | printf("CameraAbilitySlice onstart \n"); | 548 | printf("CameraAbilitySlice onstart \n"); |
| 497 | 549 | ||
| 498 | surfaceView = new UISurfaceView(); | 550 | surfaceView = new UISurfaceView(); |
| 499 | - surfaceView->SetPosition(V_GROUP_X, V_GROUP_Y, V_GROUP_W, V_GROUP_H); | 551 | + surfaceView->SetPosition(V_GROUP_X(), V_GROUP_Y(), V_GROUP_W(), V_GROUP_H()); |
| 500 | surfaceView->GetSurface()->SetWidthAndHeight(IMAGE_WIDTH, IMAGE_HEIGHT); | 552 | surfaceView->GetSurface()->SetWidthAndHeight(IMAGE_WIDTH, IMAGE_HEIGHT); |
| 501 | 553 | ||
| 502 | background_ = new UIImageView(); | 554 | background_ = new UIImageView(); |
| 503 | background_->SetTouchable(false); | 555 | background_->SetTouchable(false); |
| 556 | + background_->SetAutoEnable(false); | ||
| 557 | + background_->SetResizeMode(UIImageView::ImageResizeMode::COVER); | ||
| 504 | background_->SetSrc("/userdata/tmp.jpg"); | 558 | background_->SetSrc("/userdata/tmp.jpg"); |
| 505 | - background_->SetPosition(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); | 559 | + background_->SetPosition(0, 0, V_GROUP_W(), V_GROUP_H()); |
| 506 | background_->SetVisible(true); | 560 | background_->SetVisible(true); |
| 507 | background_->Invalidate(); | 561 | background_->Invalidate(); |
| 508 | 562 | ||
| @@ -519,7 +573,7 @@ void CameraAbilitySlice::OnStart(const Want &want) | |||
| 519 | 573 | ||
| 520 | RootView *rootView = RootView::GetWindowRootView(); | 574 | RootView *rootView = RootView::GetWindowRootView(); |
| 521 | rootView->SetPosition(0, 0); | 575 | rootView->SetPosition(0, 0); |
| 522 | - rootView->Resize(SCREEN_WIDTH, SCREEN_HEIGHT); | 576 | + rootView->Resize(V_GROUP_W(), V_GROUP_H()); |
| 523 | rootView->SetStyle(STYLE_BACKGROUND_COLOR, Color::ColorTo32(Color::Black())); | 577 | rootView->SetStyle(STYLE_BACKGROUND_COLOR, Color::ColorTo32(Color::Black())); |
| 524 | 578 | ||
| 525 | rootView->Add(surfaceView); | 579 | rootView->Add(surfaceView); |
| @@ -581,5 +635,10 @@ void CameraAbilitySlice::OnStop() | |||
| 581 | { | 635 | { |
| 582 | printf("CameraAbilitySlice::OnStop\n"); | 636 | printf("CameraAbilitySlice::OnStop\n"); |
| 583 | AbilitySlice::OnStop(); | 637 | AbilitySlice::OnStop(); |
| 638 | +#ifdef MEDIA_INTERFACE_V1_0 | ||
| 639 | + if (cam_manager) { | ||
| 640 | + cam_manager->SampleCameraStop(); | ||
| 641 | + } | ||
| 642 | +#endif | ||
| 584 | } | 643 | } |
| 585 | } | 644 | } |
| @@ -137,6 +137,13 @@ private: | |||
| 137 | 137 | ||
| 138 | void SetHead(); | 138 | void SetHead(); |
| 139 | void SetBottom(); | 139 | void SetBottom(); |
| 140 | + void SetBottomScroll(); | ||
| 141 | + void SetBottomLeftButton(); | ||
| 142 | + void SetBottomMidButton(); | ||
| 143 | + void SetBottomRightButton(); | ||
| 144 | + void SetBottomRecordButton(); | ||
| 145 | + void SetBottomSliderAndAnimator(); | ||
| 146 | + void SetBottomButtonListeners(); | ||
| 140 | }; | 147 | }; |
| 141 | } | 148 | } |
| 142 | 149 | ||
| @@ -579,6 +579,16 @@ void SampleCameraStateMng::SetStop(int s) | |||
| 579 | gPreviewSta_ = MEDIA_STATE_IDLE; | 579 | gPreviewSta_ = MEDIA_STATE_IDLE; |
| 580 | } | 580 | } |
| 581 | 581 | ||
| 582 | +#ifdef MEDIA_INTERFACE_V1_0 | ||
| 583 | +void SampleCameraStateMng::ReleaseCamera() | ||
| 584 | +{ | ||
| 585 | + if (cam_ != nullptr) { | ||
| 586 | + cam_->Release(); | ||
| 587 | + cam_ = nullptr; | ||
| 588 | + } | ||
| 589 | +} | ||
| 590 | +#endif | ||
| 591 | + | ||
| 582 | bool SampleCameraStateMng::RecordState() | 592 | bool SampleCameraStateMng::RecordState() |
| 583 | { | 593 | { |
| 584 | return (gRecordSta_ == MEDIA_STATE_START); | 594 | return (gRecordSta_ == MEDIA_STATE_START); |
| @@ -594,6 +604,9 @@ SampleCameraManager::~SampleCameraManager() | |||
| 594 | { | 604 | { |
| 595 | if (CamStateMng) { | 605 | if (CamStateMng) { |
| 596 | CamStateMng->SetStop(1); | 606 | CamStateMng->SetStop(1); |
| 607 | +#ifdef MEDIA_INTERFACE_V1_0 | ||
| 608 | + CamStateMng->ReleaseCamera(); | ||
| 609 | +#endif | ||
| 597 | delete CamStateMng; | 610 | delete CamStateMng; |
| 598 | CamStateMng = nullptr; | 611 | CamStateMng = nullptr; |
| 599 | } | 612 | } |
| @@ -87,6 +87,9 @@ public: | |||
| 87 | void SetPause(); | 87 | void SetPause(); |
| 88 | void SetResume(Surface *mSurface); | 88 | void SetResume(Surface *mSurface); |
| 89 | void SetStop(int s); | 89 | void SetStop(int s); |
| 90 | +#ifdef MEDIA_INTERFACE_V1_0 | ||
| 91 | + void ReleaseCamera(); | ||
| 92 | +#endif | ||
| 90 | bool RecordState(); | 93 | bool RecordState(); |
| 91 | bool CameraIsReady(); | 94 | bool CameraIsReady(); |
| 92 | bool IsCaptureOver(void); | 95 | bool IsCaptureOver(void); |
| @@ -16,139 +16,284 @@ | |||
| 16 | #ifndef __UI_CONFIG_H__ | 16 | #ifndef __UI_CONFIG_H__ |
| 17 | #define __UI_CONFIG_H__ | 17 | #define __UI_CONFIG_H__ |
| 18 | 18 | ||
| 19 | +#include <common/screen.h> | ||
| 20 | + | ||
| 19 | #ifdef __cplusplus | 21 | #ifdef __cplusplus |
| 20 | extern "C" { | 22 | extern "C" { |
| 21 | #endif | 23 | #endif |
| 22 | 24 | ||
| 23 | -#define LCD_CH_55 0 | 25 | +/* Screen-aware scaling helpers — designed for 1920x1080 reference. |
| 24 | -#define LCD_CH_70 1 | 26 | + * Default fallback resolution is 960x480 when Screen reports 0. */ |
| 25 | -#define LCD_CH_SEL LCD_CH_55 | 27 | +static constexpr int16_t DESIGN_WIDTH = 1920; |
| 28 | +static constexpr int16_t DESIGN_HEIGHT = 1080; | ||
| 29 | +static constexpr int16_t DEFAULT_SCR_WIDTH = 960; | ||
| 30 | +static constexpr int16_t DEFAULT_SCR_HEIGHT = 480; | ||
| 31 | +static constexpr int16_t HALF_DIVISOR = 2; | ||
| 32 | +static constexpr int16_t THIRD_DIVISOR = 3; | ||
| 33 | +static constexpr int16_t MID_BUTTON_COL_INDEX = 1; | ||
| 34 | +static constexpr int16_t RIGHT_BUTTON_COL_INDEX = 2; | ||
| 26 | 35 | ||
| 27 | -#define LCD_MODE_HORIZONTAL 0 | 36 | +static constexpr int16_t BUTTON_ICON_S_REF = 120; |
| 28 | -#define LCD_MODE_VERTICAL 1 | 37 | +static constexpr int16_t BUTTON_ICON_B_REF = 228; |
| 29 | -#define LCD_MODE_SELECT LCD_MODE_HORIZONTAL | 38 | +static constexpr int16_t TITLE_HEIGHT_REF = 80; |
| 39 | +static constexpr int16_t ICON_B_REF = 50; | ||
| 40 | +static constexpr int16_t ICON_M_REF = 36; | ||
| 41 | +static constexpr int16_t ICON_S_REF = 12; | ||
| 42 | +static constexpr int16_t BACK_LABEL_OFFSET_X = 30; | ||
| 43 | +static constexpr int16_t TXT_LABEL_WIDTH_MULTIPLIER = 3; | ||
| 44 | +static constexpr int16_t TIME_LABEL_GAP_X = 14; | ||
| 45 | +static constexpr int16_t SCROLL_VIEW_MARGIN_BOTTOM = 30; | ||
| 46 | +static constexpr int16_t SCROLL_VIEW_EXTRA_H = 6; | ||
| 47 | +static constexpr int16_t TITLE_LABEL_WIDTH_REF = 100; | ||
| 48 | +static constexpr int16_t TITLE_LABEL_HEIGHT_REF = 70; | ||
| 49 | +static constexpr uint16_t TITLE_LABEL_FONT_SIZE_REF = 25; | ||
| 30 | 50 | ||
| 31 | -#if (LCD_CH_SEL==LCD_CH_55) | 51 | +static inline int16_t ScrWidth() |
| 32 | -#if (LCD_MODE_SELECT==LCD_MODE_HORIZONTAL) | 52 | +{ |
| 33 | -#define SCREEN_WIDTH 960 | 53 | + uint16_t w = OHOS::Screen::GetInstance().GetWidth(); |
| 34 | -#define SCREEN_HEIGHT 480 | 54 | + return (w == 0) ? DEFAULT_SCR_WIDTH : static_cast<int16_t>(w); |
| 35 | -#else | 55 | +} |
| 36 | -#define SCREEN_WIDTH 480 | 56 | +static inline int16_t ScrHeight() |
| 37 | -#define SCREEN_HEIGHT 960 | 57 | +{ |
| 38 | -#endif | 58 | + uint16_t h = OHOS::Screen::GetInstance().GetHeight(); |
| 39 | -#elif (LCD_CH_SEL==LCD_CH_70) | 59 | + return (h == 0) ? DEFAULT_SCR_HEIGHT : static_cast<int16_t>(h); |
| 40 | -#if (LCD_MODE_SELECT==LCD_MODE_HORIZONTAL) | 60 | +} |
| 41 | -#define SCREEN_WIDTH 1024 | 61 | +static inline int16_t HScale(int16_t ref) |
| 42 | -#define SCREEN_HEIGHT 600 | 62 | +{ |
| 43 | -#else | 63 | + return static_cast<int16_t>( |
| 44 | -#define SCREEN_WIDTH 600 | 64 | + static_cast<int32_t>(ref) * ScrWidth() / DESIGN_WIDTH); |
| 45 | -#define SCREEN_HEIGHT 1024 | 65 | +} |
| 46 | -#endif | 66 | +static inline int16_t VScale(int16_t ref) |
| 47 | -#else | 67 | +{ |
| 48 | -#error "no such type LCD SIZE select!!!" | 68 | + return static_cast<int16_t>( |
| 49 | -// exit (1) | 69 | + static_cast<int32_t>(ref) * ScrHeight() / DESIGN_HEIGHT); |
| 50 | -#endif | 70 | +} |
| 51 | 71 | ||
| 72 | +/* Orientation detection: horizontal if width >= height, else vertical */ | ||
| 73 | +static inline bool IsHorizontalMode() | ||
| 74 | +{ | ||
| 75 | + return ScrWidth() >= ScrHeight(); | ||
| 76 | +} | ||
| 77 | + | ||
| 78 | +static inline int16_t TITLE_LABEL_Y() | ||
| 79 | +{ | ||
| 80 | + return 0; | ||
| 81 | +} | ||
| 82 | +static inline int16_t TITLE_LABEL_WIDTH() | ||
| 83 | +{ | ||
| 84 | + return HScale(TITLE_LABEL_WIDTH_REF); | ||
| 85 | +} | ||
| 86 | + | ||
| 87 | +/* Base starting point */ | ||
| 52 | #define START_X 0 | 88 | #define START_X 0 |
| 53 | #define START_Y 0 | 89 | #define START_Y 0 |
| 54 | -#define BUTTON_ICON_SW 60 | ||
| 55 | -#define BUTTON_ICON_SH 60 | ||
| 56 | -#define BUTTON_ICON_BW 114 | ||
| 57 | -#define BUTTON_ICON_BH 114 | ||
| 58 | 90 | ||
| 59 | -#define TITLE_HEIGHT 80 | 91 | +/* Button icon sizes — scaled from 1920x1080 reference */ |
| 92 | +static inline int16_t BUTTON_ICON_SW() | ||
| 93 | +{ | ||
| 94 | + return HScale(BUTTON_ICON_S_REF); | ||
| 95 | +} | ||
| 96 | +static inline int16_t BUTTON_ICON_SH() | ||
| 97 | +{ | ||
| 98 | + return VScale(BUTTON_ICON_S_REF); | ||
| 99 | +} | ||
| 100 | +static inline int16_t BUTTON_ICON_BW() | ||
| 101 | +{ | ||
| 102 | + return HScale(BUTTON_ICON_B_REF); | ||
| 103 | +} | ||
| 104 | +static inline int16_t BUTTON_ICON_BH() | ||
| 105 | +{ | ||
| 106 | + return VScale(BUTTON_ICON_B_REF); | ||
| 107 | +} | ||
| 60 | 108 | ||
| 61 | -#define ICON_B_WIDTH 50 | 109 | +static inline int16_t TITLE_HEIGHT() |
| 62 | -#define ICON_B_HEIGHT 50 | 110 | +{ |
| 63 | -#define ICON_M_WIDTH 36 | 111 | + return VScale(TITLE_HEIGHT_REF); |
| 64 | -#define ICON_M_HEIGHT 36 | 112 | +} |
| 65 | -#define ICON_S_WIDTH 12 | 113 | +static inline int16_t TITLE_LABEL_HEIGHT() |
| 66 | -#define ICON_S_HEIGHT 12 | 114 | +{ |
| 115 | + return TITLE_HEIGHT(); | ||
| 116 | +} | ||
| 67 | 117 | ||
| 68 | -// coord define | 118 | +static inline int16_t ICON_B_WIDTH() |
| 69 | -#define V_GROUP_X START_X | 119 | +{ |
| 70 | -#define V_GROUP_Y START_Y | 120 | + return HScale(ICON_B_REF); |
| 71 | -#define V_GROUP_W SCREEN_WIDTH | 121 | +} |
| 72 | -#define V_GROUP_H SCREEN_HEIGHT | 122 | +static inline int16_t ICON_B_HEIGHT() |
| 123 | +{ | ||
| 124 | + return VScale(ICON_B_REF); | ||
| 125 | +} | ||
| 126 | +static inline int16_t ICON_M_WIDTH() | ||
| 127 | +{ | ||
| 128 | + return HScale(ICON_M_REF); | ||
| 129 | +} | ||
| 130 | +static inline int16_t ICON_M_HEIGHT() | ||
| 131 | +{ | ||
| 132 | + return VScale(ICON_M_REF); | ||
| 133 | +} | ||
| 134 | +static inline int16_t ICON_S_WIDTH() | ||
| 135 | +{ | ||
| 136 | + return HScale(ICON_S_REF); | ||
| 137 | +} | ||
| 138 | +static inline int16_t ICON_S_HEIGHT() | ||
| 139 | +{ | ||
| 140 | + return VScale(ICON_S_REF); | ||
| 141 | +} | ||
| 73 | 142 | ||
| 74 | -#if (LCD_MODE_SELECT==LCD_MODE_HORIZONTAL) | 143 | +/* coord define — using runtime screen dimensions */ |
| 75 | -#define BACK_LABEL_X (START_X + 30) | 144 | +static inline int16_t V_GROUP_X() |
| 76 | -#define BACK_LABEL_Y ((TITLE_HEIGHT - ICON_M_HEIGHT) / 2) | 145 | +{ |
| 77 | -#define BACK_LABEL_W ICON_M_WIDTH | 146 | + return START_X; |
| 78 | -#define BACK_LABEL_H ICON_M_HEIGHT | 147 | +} |
| 148 | +static inline int16_t V_GROUP_Y() | ||
| 149 | +{ | ||
| 150 | + return START_Y; | ||
| 151 | +} | ||
| 152 | +static inline int16_t V_GROUP_W() | ||
| 153 | +{ | ||
| 154 | + return ScrWidth(); | ||
| 155 | +} | ||
| 156 | +static inline int16_t V_GROUP_H() | ||
| 157 | +{ | ||
| 158 | + return ScrHeight(); | ||
| 159 | +} | ||
| 79 | 160 | ||
| 80 | -#define TXT_LABEL_X (BACK_LABEL_X + BUTTON_ICON_SW) | 161 | +/* Layout computed from runtime screen size and scaled icon sizes */ |
| 81 | -#define TXT_LABEL_Y (START_Y + (TITLE_HEIGHT - ICON_B_HEIGHT) / 2) | 162 | +static inline int16_t BACK_LABEL_X() |
| 82 | -#define TXT_LABEL_W (ICON_B_WIDTH * 3) | 163 | +{ |
| 83 | -#define TXT_LABEL_H ICON_B_HEIGHT | 164 | + return START_X + HScale(BACK_LABEL_OFFSET_X); |
| 165 | +} | ||
| 166 | +static inline int16_t BACK_LABEL_Y() | ||
| 167 | +{ | ||
| 168 | + return (TITLE_HEIGHT() - ICON_M_HEIGHT()) / HALF_DIVISOR; | ||
| 169 | +} | ||
| 170 | +static inline int16_t BACK_LABEL_W() | ||
| 171 | +{ | ||
| 172 | + return ICON_M_WIDTH(); | ||
| 173 | +} | ||
| 174 | +static inline int16_t BACK_LABEL_H() | ||
| 175 | +{ | ||
| 176 | + return ICON_M_HEIGHT(); | ||
| 177 | +} | ||
| 84 | 178 | ||
| 85 | -#define RECORD_IMAGE_X (SCREEN_WIDTH / 2 - BUTTON_ICON_SW) | 179 | +static inline int16_t TXT_LABEL_X() |
| 86 | -#define RECORD_IMAGE_Y (START_Y + (TITLE_HEIGHT - ICON_S_HEIGHT) / 2) | 180 | +{ |
| 87 | -#define RECORD_IMAGE_W ICON_S_WIDTH | 181 | + return BACK_LABEL_X() + BUTTON_ICON_SW(); |
| 88 | -#define RECORD_IMAGE_H ICON_S_HEIGHT | 182 | +} |
| 183 | +static inline int16_t TXT_LABEL_Y() | ||
| 184 | +{ | ||
| 185 | + return START_Y + (TITLE_HEIGHT() - ICON_B_HEIGHT()) / HALF_DIVISOR; | ||
| 186 | +} | ||
| 187 | +static inline int16_t TXT_LABEL_W() | ||
| 188 | +{ | ||
| 189 | + return ICON_B_WIDTH() * TXT_LABEL_WIDTH_MULTIPLIER; | ||
| 190 | +} | ||
| 191 | +static inline int16_t TXT_LABEL_H() | ||
| 192 | +{ | ||
| 193 | + return ICON_B_HEIGHT(); | ||
| 194 | +} | ||
| 89 | 195 | ||
| 90 | -#define TIME_LABEL_X (RECORD_IMAGE_X + RECORD_IMAGE_W + 14) | 196 | +static inline int16_t RECORD_IMAGE_X() |
| 91 | -#define TIME_LABEL_Y (START_Y + (TITLE_HEIGHT - ICON_B_HEIGHT) / 2) | 197 | +{ |
| 92 | -#define TIME_LABEL_W (SCREEN_WIDTH-(RECORD_IMAGE_X + RECORD_IMAGE_W + 14)) | 198 | + return ScrWidth() / HALF_DIVISOR - BUTTON_ICON_SW(); |
| 93 | -#define TIME_LABEL_H ICON_B_HEIGHT | 199 | +} |
| 200 | +static inline int16_t RECORD_IMAGE_Y() | ||
| 201 | +{ | ||
| 202 | + return START_Y + (TITLE_HEIGHT() - ICON_S_HEIGHT()) / HALF_DIVISOR; | ||
| 203 | +} | ||
| 204 | +static inline int16_t RECORD_IMAGE_W() | ||
| 205 | +{ | ||
| 206 | + return ICON_S_WIDTH(); | ||
| 207 | +} | ||
| 208 | +static inline int16_t RECORD_IMAGE_H() | ||
| 209 | +{ | ||
| 210 | + return ICON_S_HEIGHT(); | ||
| 211 | +} | ||
| 94 | 212 | ||
| 95 | -#define SCROLL_VIEW_X START_X | 213 | +static inline int16_t TIME_LABEL_X() |
| 96 | -#define SCROLL_VIEW_Y ((SCREEN_HEIGHT - BUTTON_ICON_BH) - 30) | 214 | +{ |
| 97 | -#define SCROLL_VIEW_W SCREEN_WIDTH | 215 | + return RECORD_IMAGE_X() + RECORD_IMAGE_W() + HScale(TIME_LABEL_GAP_X); |
| 98 | -#define SCROLL_VIEW_H (BUTTON_ICON_BH + 6) | 216 | +} |
| 217 | +static inline int16_t TIME_LABEL_Y() | ||
| 218 | +{ | ||
| 219 | + return START_Y + (TITLE_HEIGHT() - ICON_B_HEIGHT()) / HALF_DIVISOR; | ||
| 220 | +} | ||
| 221 | +static inline int16_t TIME_LABEL_W() | ||
| 222 | +{ | ||
| 223 | + return ScrWidth() - (RECORD_IMAGE_X() + RECORD_IMAGE_W() + HScale(TIME_LABEL_GAP_X)); | ||
| 224 | +} | ||
| 225 | +static inline int16_t TIME_LABEL_H() | ||
| 226 | +{ | ||
| 227 | + return ICON_B_HEIGHT(); | ||
| 228 | +} | ||
| 99 | 229 | ||
| 100 | -#define LEFT_BUTTON_X (SCREEN_WIDTH / 3) | 230 | +static inline int16_t SCROLL_VIEW_X() |
| 101 | -#define LEFT_BUTTON_Y ((SCROLL_VIEW_H - BUTTON_ICON_SH) / 2) | 231 | +{ |
| 102 | -#define LEFT_BUTTON_W BUTTON_ICON_SW | 232 | + return START_X; |
| 103 | -#define LEFT_BUTTON_H BUTTON_ICON_SH | 233 | +} |
| 104 | -#define MID_BUTTON_X (((SCREEN_WIDTH / 3) - BUTTON_ICON_BW) / 2 + 1 * (SCREEN_WIDTH / 3)) | 234 | +static inline int16_t SCROLL_VIEW_Y() |
| 105 | -#define MID_BUTTON_Y ((SCROLL_VIEW_H - BUTTON_ICON_BH) / 2) | 235 | +{ |
| 106 | -#define MID_BUTTON_W BUTTON_ICON_BW | 236 | + return (ScrHeight() - BUTTON_ICON_BH()) - VScale(SCROLL_VIEW_MARGIN_BOTTOM) - BUTTON_ICON_BH() / HALF_DIVISOR; |
| 107 | -#define MID_BUTTON_H BUTTON_ICON_BH | 237 | +} |
| 108 | -#define RIGHT_BUTTON_X (2 * (SCREEN_WIDTH / 3) - BUTTON_ICON_SW) | 238 | +static inline int16_t SCROLL_VIEW_W() |
| 109 | -#define RIGHT_BUTTON_Y ((SCROLL_VIEW_H - BUTTON_ICON_SH) / 2) | 239 | +{ |
| 110 | -#define RIGHT_BUTTON_W BUTTON_ICON_SW | 240 | + return ScrWidth(); |
| 111 | -#define RIGHT_BUTTON_H BUTTON_ICON_SH | 241 | +} |
| 242 | +static inline int16_t SCROLL_VIEW_H() | ||
| 243 | +{ | ||
| 244 | + return BUTTON_ICON_BH() + VScale(SCROLL_VIEW_EXTRA_H) + BUTTON_ICON_BH() / HALF_DIVISOR; | ||
| 245 | +} | ||
| 112 | 246 | ||
| 113 | -#else | 247 | +static inline int16_t LEFT_BUTTON_X() |
| 114 | -#define BACK_LABEL_X (START_X + 30) | 248 | +{ |
| 115 | -#define BACK_LABEL_Y ((BUTTON_ICON_SH - ICON_M_HEIGHT) / 2) | 249 | + return (ScrWidth() / THIRD_DIVISOR) - BUTTON_ICON_SW() / HALF_DIVISOR; |
| 116 | -#define BACK_LABEL_W ICON_M_WIDTH | 250 | +} |
| 117 | -#define BACK_LABEL_H ICON_M_HEIGHT | 251 | +static inline int16_t LEFT_BUTTON_Y() |
| 252 | +{ | ||
| 253 | + return (SCROLL_VIEW_H() - BUTTON_ICON_SH()) / HALF_DIVISOR; | ||
| 254 | +} | ||
| 255 | +static inline int16_t LEFT_BUTTON_W() | ||
| 256 | +{ | ||
| 257 | + return BUTTON_ICON_SW(); | ||
| 258 | +} | ||
| 259 | +static inline int16_t LEFT_BUTTON_H() | ||
| 260 | +{ | ||
| 261 | + return BUTTON_ICON_SH(); | ||
| 262 | +} | ||
| 118 | 263 | ||
| 119 | -#define TXT_LABEL_X (BACK_LABEL_X + BUTTON_ICON_SW) | 264 | +static inline int16_t MID_BUTTON_X() |
| 120 | -#define TXT_LABEL_Y (START_Y + (BUTTON_ICON_SH - ICON_B_HEIGHT) / 2) | 265 | +{ |
| 121 | -#define TXT_LABEL_W (ICON_B_WIDTH * 3) | 266 | + return (ScrWidth() / HALF_DIVISOR) - BUTTON_ICON_BW() / HALF_DIVISOR; |
| 122 | -#define TXT_LABEL_H ICON_B_HEIGHT | 267 | +} |
| 268 | +static inline int16_t MID_BUTTON_Y() | ||
| 269 | +{ | ||
| 270 | + return (SCROLL_VIEW_H() - BUTTON_ICON_BH()) / HALF_DIVISOR; | ||
| 271 | +} | ||
| 272 | +static inline int16_t MID_BUTTON_W() | ||
| 273 | +{ | ||
| 274 | + return BUTTON_ICON_BW(); | ||
| 275 | +} | ||
| 276 | +static inline int16_t MID_BUTTON_H() | ||
| 277 | +{ | ||
| 278 | + return BUTTON_ICON_BH(); | ||
| 279 | +} | ||
| 123 | 280 | ||
| 124 | -#define RECORD_IMAGE_X (SCREEN_WIDTH / 2 - BUTTON_ICON_SW) | 281 | +static inline int16_t RIGHT_BUTTON_X() |
| 125 | -#define RECORD_IMAGE_Y (START_Y + (BUTTON_ICON_SH - ICON_S_HEIGHT) / 2) | 282 | +{ |
| 126 | -#define RECORD_IMAGE_W ICON_S_WIDTH | 283 | + return (RIGHT_BUTTON_COL_INDEX * (ScrWidth() / THIRD_DIVISOR)) - BUTTON_ICON_SW() / HALF_DIVISOR; |
| 127 | -#define RECORD_IMAGE_H ICON_S_HEIGHT | 284 | +} |
| 128 | - | 285 | +static inline int16_t RIGHT_BUTTON_Y() |
| 129 | -#define TIME_LABEL_X (RECORD_IMAGE_X + RECORD_IMAGE_W + 14) | 286 | +{ |
| 130 | -#define TIME_LABEL_Y (START_Y + (BUTTON_ICON_SH - ICON_B_HEIGHT) / 2) | 287 | + return (SCROLL_VIEW_H() - BUTTON_ICON_SH()) / HALF_DIVISOR; |
| 131 | -#define TIME_LABEL_W (BUTTON_ICON_SW * 2) | 288 | +} |
| 132 | -#define TIME_LABEL_H ICON_B_HEIGHT | 289 | +static inline int16_t RIGHT_BUTTON_W() |
| 133 | - | 290 | +{ |
| 134 | -#define SCROLL_VIEW_X START_X | 291 | + return BUTTON_ICON_SW(); |
| 135 | -#define SCROLL_VIEW_Y ((SCREEN_HEIGHT - BUTTON_ICON_BH) - 10) | 292 | +} |
| 136 | -#define SCROLL_VIEW_W SCREEN_WIDTH | 293 | +static inline int16_t RIGHT_BUTTON_H() |
| 137 | -#define SCROLL_VIEW_H (BUTTON_ICON_BH + 6) | 294 | +{ |
| 138 | - | 295 | + return BUTTON_ICON_SH(); |
| 139 | -#define LEFT_BUTTON_X (SCREEN_WIDTH / 3) | 296 | +} |
| 140 | -#define LEFT_BUTTON_Y ((SCROLL_VIEW_H - BUTTON_ICON_SH) / 2) | ||
| 141 | -#define LEFT_BUTTON_W BUTTON_ICON_SW | ||
| 142 | -#define LEFT_BUTTON_H BUTTON_ICON_SH | ||
| 143 | -#define MID_BUTTON_X (((SCREEN_WIDTH / 3) - BUTTON_ICON_BW) / 2 + 1 * (SCREEN_WIDTH / 3)) | ||
| 144 | -#define MID_BUTTON_Y ((SCROLL_VIEW_H - BUTTON_ICON_SH) / 2) | ||
| 145 | -#define MID_BUTTON_W BUTTON_ICON_SW | ||
| 146 | -#define MID_BUTTON_H BUTTON_ICON_SH | ||
| 147 | -#define RIGHT_BUTTON_X (2 * (SCREEN_WIDTH / 3) - BUTTON_ICON_SW) | ||
| 148 | -#define RIGHT_BUTTON_Y ((SCROLL_VIEW_H - BUTTON_ICON_SH) / 2) | ||
| 149 | -#define RIGHT_BUTTON_W BUTTON_ICON_SW | ||
| 150 | -#define RIGHT_BUTTON_H BUTTON_ICON_SH | ||
| 151 | -#endif | ||
| 152 | 297 | ||
| 153 | #define UI_IMAGE_PATH \ | 298 | #define UI_IMAGE_PATH \ |
| 154 | "/storage/app/run/com.huawei.camera/cameraApp/assets/cameraApp/resources/base/media/" | 299 | "/storage/app/run/com.huawei.camera/cameraApp/assets/cameraApp/resources/base/media/" |
| @@ -13,20 +13,32 @@ | |||
| 13 | 13 | ||
| 14 | import("//build/lite/config/hap_pack.gni") | 14 | import("//build/lite/config/hap_pack.gni") |
| 15 | 15 | ||
| 16 | +config("hilog_dir") { | ||
| 17 | + include_dirs = | ||
| 18 | + [ "//base/hiviewdfx/hilog_lite/interfaces/native/innerkits/hilog/" ] | ||
| 19 | +} | ||
| 20 | +config("hilog_lite_dir") { | ||
| 21 | + include_dirs = | ||
| 22 | + [ "//base/hiviewdfx/hilog_lite/interfaces/native/kits/hilog_lite/" ] | ||
| 23 | +} | ||
| 24 | + | ||
| 16 | shared_library("gallery") { | 25 | shared_library("gallery") { |
| 17 | sources = [ | 26 | sources = [ |
| 18 | "src/gallery_ability.cpp", | 27 | "src/gallery_ability.cpp", |
| 19 | "src/gallery_ability_slice.cpp", | 28 | "src/gallery_ability_slice.cpp", |
| 20 | "src/picture_ability_slice.cpp", | 29 | "src/picture_ability_slice.cpp", |
| 21 | "src/player_ability_slice.cpp", | 30 | "src/player_ability_slice.cpp", |
| 31 | + "src/image_decoder.cpp", | ||
| 22 | ] | 32 | ] |
| 23 | 33 | ||
| 24 | include_dirs = [ | 34 | include_dirs = [ |
| 25 | "include", | 35 | "include", |
| 36 | + "..", | ||
| 26 | "${aafwk_lite_path}/interfaces/kits/ability_lite", | 37 | "${aafwk_lite_path}/interfaces/kits/ability_lite", |
| 27 | "${appexecfwk_lite_path}/interfaces/kits/bundle_lite", | 38 | "${appexecfwk_lite_path}/interfaces/kits/bundle_lite", |
| 28 | "${aafwk_lite_path}/interfaces/kits/want_lite", | 39 | "${aafwk_lite_path}/interfaces/kits/want_lite", |
| 29 | "//foundation/multimedia/media_lite/interfaces/kits/player_lite", | 40 | "//foundation/multimedia/media_lite/interfaces/kits/player_lite", |
| 41 | + "//foundation/arkui/ui_lite/frameworks", | ||
| 30 | ] | 42 | ] |
| 31 | 43 | ||
| 32 | deps = [ | 44 | deps = [ |
| @@ -41,6 +53,19 @@ shared_library("gallery") { | |||
| 41 | "//foundation/systemabilitymgr/samgr_lite/samgr:samgr", | 53 | "//foundation/systemabilitymgr/samgr_lite/samgr:samgr", |
| 42 | ] | 54 | ] |
| 43 | 55 | ||
| 56 | + if (defined(ohos_lite)) { | ||
| 57 | + if (ohos_kernel_type == "liteos_m") { | ||
| 58 | + configs += [ ":hilog_lite_dir" ] | ||
| 59 | + deps += [ "//base/hiviewdfx/hilog_lite/frameworks/mini:hilog_lite" ] | ||
| 60 | + } else if (ohos_kernel_type == "liteos_a") { | ||
| 61 | + configs += [ ":hilog_dir" ] | ||
| 62 | + deps += [ | ||
| 63 | + "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared", | ||
| 64 | + "//third_party/bounds_checking_function:libsec_shared", | ||
| 65 | + ] | ||
| 66 | + } | ||
| 67 | + } | ||
| 68 | + | ||
| 44 | ldflags = [ "-shared" ] | 69 | ldflags = [ "-shared" ] |
| 45 | 70 | ||
| 46 | ldflags += [ "-lstdc++" ] | 71 | ldflags += [ "-lstdc++" ] |
| @@ -58,7 +83,26 @@ shared_library("gallery") { | |||
| 58 | "OHOS_APPEXECFWK_BMS_BUNDLEMANAGER", | 83 | "OHOS_APPEXECFWK_BMS_BUNDLEMANAGER", |
| 59 | "ENABLE_WINDOW=1", | 84 | "ENABLE_WINDOW=1", |
| 60 | "ABILITY_WINDOW_SUPPORT", | 85 | "ABILITY_WINDOW_SUPPORT", |
| 86 | + "HILOG_ENABLE", | ||
| 61 | ] | 87 | ] |
| 88 | + | ||
| 89 | + # image decode for jpeg/png | ||
| 90 | + deps += [ | ||
| 91 | + "//third_party/libjpeg-turbo:libjpeg", | ||
| 92 | + "//third_party/libpng:libpng", | ||
| 93 | + ] | ||
| 94 | + defines += [ | ||
| 95 | + "ENABLE_JPEG = 1", | ||
| 96 | + "ENABLE_PNG = 1", | ||
| 97 | + ] | ||
| 98 | +} | ||
| 99 | + | ||
| 100 | +copy("test_jpeg") { | ||
| 101 | + sources = [ | ||
| 102 | + "resources/photos/photo1.jpeg", | ||
| 103 | + "resources/photos/photo2.jpeg" | ||
| 104 | + ] | ||
| 105 | + outputs = [ "${root_out_dir}/system/internal/{{source_file_part}}" ] | ||
| 62 | } | 106 | } |
| 63 | 107 | ||
| 64 | hap_pack("gallery_hap") { | 108 | hap_pack("gallery_hap") { |
| @@ -22,6 +22,7 @@ | |||
| 22 | #include <components/ui_scroll_view.h> | 22 | #include <components/ui_scroll_view.h> |
| 23 | #include "event_listener.h" | 23 | #include "event_listener.h" |
| 24 | #include "gallery_config.h" | 24 | #include "gallery_config.h" |
| 25 | +#include "image_decoder.h" | ||
| 25 | 26 | ||
| 26 | namespace OHOS { | 27 | namespace OHOS { |
| 27 | class GalleryAbilitySlice : public AbilitySlice { | 28 | class GalleryAbilitySlice : public AbilitySlice { |
| @@ -41,9 +42,12 @@ private: | |||
| 41 | void ClearThumb(); | 42 | void ClearThumb(); |
| 42 | void ClearPictureList(const UIView* view); | 43 | void ClearPictureList(const UIView* view); |
| 43 | void InitTitle(); | 44 | void InitTitle(); |
| 45 | + void InitTitleBackArea(); | ||
| 46 | + void InitTitleLabels(); | ||
| 44 | void InitPictureList(); | 47 | void InitPictureList(); |
| 45 | - void AddAllPictures(const Point& pos, int16_t numInLine); | 48 | + void AddAllPictures(const Point& pos, int16_t numInLine, std::string directoryPath); |
| 46 | UIView* CreateImageItem(const Point& pos, const char* imageName, const char* imagePath); | 49 | UIView* CreateImageItem(const Point& pos, const char* imageName, const char* imagePath); |
| 50 | + void AddVideoItemViews(UIViewGroup* imageItem, UIImageView* imageView, const char* imageName); | ||
| 47 | EventListener* GetImageClickListener(const char* path); | 51 | EventListener* GetImageClickListener(const char* path); |
| 48 | void DeleteAllData(); | 52 | void DeleteAllData(); |
| 49 | void DeleteAllFilesInDir(const char* path); | 53 | void DeleteAllFilesInDir(const char* path); |
| @@ -63,6 +67,7 @@ private: | |||
| 63 | char videoTagIconAbsolutePath[MAX_PATH_LENGTH] = { 0 }; | 67 | char videoTagIconAbsolutePath[MAX_PATH_LENGTH] = { 0 }; |
| 64 | uint16_t pictureOnClickListenerCount_ { 0 }; | 68 | uint16_t pictureOnClickListenerCount_ { 0 }; |
| 65 | EventListener* pictureOnClickListener_[MAX_PICTURE_COUNT] = { nullptr }; | 69 | EventListener* pictureOnClickListener_[MAX_PICTURE_COUNT] = { nullptr }; |
| 70 | + ImageDecoder* imageDecoder_ { nullptr }; | ||
| 66 | }; | 71 | }; |
| 67 | } | 72 | } |
| 68 | #endif // OHOS_GALLERY_ABILITY_SLICE_H | 73 | #endif // OHOS_GALLERY_ABILITY_SLICE_H |
| @@ -16,10 +16,88 @@ | |||
| 16 | #ifndef OHOS_GALLERY_CONFIG_H | 16 | #ifndef OHOS_GALLERY_CONFIG_H |
| 17 | #define OHOS_GALLERY_CONFIG_H | 17 | #define OHOS_GALLERY_CONFIG_H |
| 18 | 18 | ||
| 19 | +#include "components/ui_view_group.h" | ||
| 20 | +#include "graphic_config.h" | ||
| 21 | +#include <common/screen.h> | ||
| 22 | + | ||
| 23 | +#define GALLERY_BACKGROUND_COLOR Color::ColorTo32(Color::GetColorFromRGB(0xdd, 0xdd, 0xdd)) | ||
| 24 | + | ||
| 19 | namespace OHOS { | 25 | namespace OHOS { |
| 26 | +/* Screen-aware scaling helpers — designed for 1920x1080 reference. | ||
| 27 | + * Default fallback resolution is 960x480 when Screen reports 0. */ | ||
| 28 | +constexpr int16_t DESIGN_WIDTH = 1920; | ||
| 29 | +constexpr int16_t DESIGN_HEIGHT = 1080; | ||
| 30 | +constexpr int16_t DEFAULT_SCR_WIDTH = 960; | ||
| 31 | +constexpr int16_t DEFAULT_SCR_HEIGHT = 480; | ||
| 32 | +constexpr uint16_t MIN_FONT_SIZE = 14; | ||
| 33 | + | ||
| 34 | +constexpr int16_t BACK_ICON_POS_X_REF = 38; | ||
| 35 | +constexpr int16_t BACK_ICON_POS_Y_REF = 17; | ||
| 36 | +constexpr int16_t BACK_ICON_SIZE_REF = 36; | ||
| 37 | +constexpr int16_t THUMBNAIL_SIZE_REF = 236; | ||
| 38 | +constexpr int16_t VIDEO_TAG_POS_X_REF = 10; | ||
| 39 | +constexpr int16_t VIDEO_TAG_POS_Y_OFFSET_REF = 37; | ||
| 40 | +constexpr int16_t VIDEO_TAG_SIZE_REF = 27; | ||
| 41 | +constexpr int16_t LABEL_OFFSET_X_REF = 60; | ||
| 42 | +constexpr int16_t LABEL_WIDTH_REF = 200; | ||
| 43 | +constexpr int16_t LABEL_HEIGHT_REF = 70; | ||
| 44 | +constexpr uint16_t GALLERY_FONT_SIZE_REF = 25; | ||
| 45 | +constexpr uint16_t GALLERY_DELETE_FONT_SIZE_REF = 22; | ||
| 46 | +constexpr int16_t DELETE_LABEL_WIDTH_REF = 150; | ||
| 47 | +constexpr uint16_t STATUS_BAR_GROUP_HEIGHT_REF = 96; | ||
| 48 | +constexpr uint16_t TOGGLE_BUTTON_OFFSET_X_REF = 36; | ||
| 49 | +constexpr uint16_t TOGGLE_BUTTON_OFFSET_Y_REF = 18; | ||
| 50 | +constexpr uint16_t TOGGLE_BUTTON_SIZE_REF = 60; | ||
| 51 | +constexpr uint16_t CURRENT_TIME_LABEL_WIDTH_REF = 60; | ||
| 52 | +constexpr uint16_t TOTAL_TIME_LABEL_WIDTH_REF = 90; | ||
| 53 | +constexpr uint16_t SLIDER_Y_REF = 2; | ||
| 54 | +constexpr uint16_t SLIDER_HEIGHT_REF = 3; | ||
| 55 | +constexpr uint16_t SLIDER_MARGIN_RIGHT_REF = 20; | ||
| 56 | +constexpr uint16_t KNOB_WIDTH_REF = 25; | ||
| 57 | +constexpr uint16_t PLAYER_FONT_SIZE_REF = 18; | ||
| 58 | + | ||
| 59 | +static inline int16_t GetScrWidth() | ||
| 60 | +{ | ||
| 61 | + uint16_t w = Screen::GetInstance().GetWidth(); | ||
| 62 | + return (w == 0) ? DEFAULT_SCR_WIDTH : static_cast<int16_t>(w); | ||
| 63 | +} | ||
| 64 | +static inline int16_t GetScrHeight() | ||
| 65 | +{ | ||
| 66 | + uint16_t h = Screen::GetInstance().GetHeight(); | ||
| 67 | + return (h == 0) ? DEFAULT_SCR_HEIGHT : static_cast<int16_t>(h); | ||
| 68 | +} | ||
| 69 | +static inline int16_t HScale(int16_t ref) | ||
| 70 | +{ | ||
| 71 | + return static_cast<int16_t>( | ||
| 72 | + static_cast<int32_t>(ref) * Screen::GetInstance().GetWidth() / DESIGN_WIDTH); | ||
| 73 | +} | ||
| 74 | +static inline int16_t VScale(int16_t ref) | ||
| 75 | +{ | ||
| 76 | + return static_cast<int16_t>( | ||
| 77 | + static_cast<int32_t>(ref) * Screen::GetInstance().GetHeight() / DESIGN_HEIGHT); | ||
| 78 | +} | ||
| 79 | +static inline int16_t UScale(int16_t ref) | ||
| 80 | +{ | ||
| 81 | + float rw = static_cast<float>(Screen::GetInstance().GetWidth()) / | ||
| 82 | + static_cast<float>(DESIGN_WIDTH); | ||
| 83 | + float rh = static_cast<float>(Screen::GetInstance().GetHeight()) / | ||
| 84 | + static_cast<float>(DESIGN_HEIGHT); | ||
| 85 | + return static_cast<int16_t>(ref * ((rw < rh) ? rw : rh)); | ||
| 86 | +} | ||
| 87 | +static inline uint16_t FontScale(uint16_t ref) | ||
| 88 | +{ | ||
| 89 | + int32_t s = static_cast<int32_t>(ref) * Screen::GetInstance().GetHeight() / DESIGN_HEIGHT; | ||
| 90 | + return static_cast<uint16_t>(s < MIN_FONT_SIZE ? MIN_FONT_SIZE : s); | ||
| 91 | +} | ||
| 92 | +static inline bool IsScrRes(int16_t w, int16_t h) | ||
| 93 | +{ | ||
| 94 | + return Screen::GetInstance().GetWidth() == w && Screen::GetInstance().GetHeight() == h; | ||
| 95 | +} | ||
| 96 | + | ||
| 20 | /** icon resource file path */ | 97 | /** icon resource file path */ |
| 21 | static const char* const BACK_ICON_PATH = "/gallery/assets/gallery/resources/drawable/ic_back.png"; | 98 | static const char* const BACK_ICON_PATH = "/gallery/assets/gallery/resources/drawable/ic_back.png"; |
| 22 | -static const char* const VIDEO_TAG_ICON_PATH = "/gallery/assets/gallery/resources/drawable/ic_gallery_video_tag.png"; | 99 | +static const char* const VIDEO_TAG_ICON_PATH = |
| 100 | + "/gallery/assets/gallery/resources/drawable/ic_gallery_video_tag.png"; | ||
| 23 | static const char* const VIDEO_PALY_PATH = "/gallery/assets/gallery/resources/drawable/ic_gallery_play.png"; | 101 | static const char* const VIDEO_PALY_PATH = "/gallery/assets/gallery/resources/drawable/ic_gallery_play.png"; |
| 24 | static const char* const VIDEO_PAUSE_PATH = "/gallery/assets/gallery/resources/drawable/ic_gallery_pause.png"; | 102 | static const char* const VIDEO_PAUSE_PATH = "/gallery/assets/gallery/resources/drawable/ic_gallery_pause.png"; |
| 25 | 103 | ||
| @@ -29,38 +107,100 @@ static constexpr uint16_t MAX_PATH_LENGTH = 512; | |||
| 29 | /** thumb, photo, and video folder path */ | 107 | /** thumb, photo, and video folder path */ |
| 30 | static const char* const THUMBNAIL_DIRECTORY = "/userdata/thumb"; | 108 | static const char* const THUMBNAIL_DIRECTORY = "/userdata/thumb"; |
| 31 | static const char* const PHOTO_DIRECTORY = "/userdata/photo"; | 109 | static const char* const PHOTO_DIRECTORY = "/userdata/photo"; |
| 110 | +#ifdef MEDIA_INTERFACE_V1_0 | ||
| 111 | +static const char* const VIDEO_SOURCE_DIRECTORY = "/userdata/photo"; | ||
| 112 | +#else | ||
| 32 | static const char* const VIDEO_SOURCE_DIRECTORY = "/userdata/video"; | 113 | static const char* const VIDEO_SOURCE_DIRECTORY = "/userdata/video"; |
| 114 | +#endif | ||
| 33 | 115 | ||
| 34 | -/** general page configuration */ | 116 | +/** general page configuration — runtime screen aware */ |
| 117 | +static inline int ROOT_VIEW_WIDTH() | ||
| 118 | +{ | ||
| 119 | + return GetScrWidth(); | ||
| 120 | +} | ||
| 121 | +static inline int ROOT_VIEW_HEIGHT() | ||
| 122 | +{ | ||
| 123 | + return GetScrHeight(); | ||
| 124 | +} | ||
| 35 | static constexpr int ROOT_VIEW_POSITION_X = 0; | 125 | static constexpr int ROOT_VIEW_POSITION_X = 0; |
| 36 | static constexpr int ROOT_VIEW_POSITION_Y = 0; | 126 | static constexpr int ROOT_VIEW_POSITION_Y = 0; |
| 37 | -static constexpr int ROOT_VIEW_WIDTH = 960; | ||
| 38 | -static constexpr int ROOT_VIEW_HEIGHT = 480; | ||
| 39 | static constexpr uint16_t ROOT_VIEW_OPACITY = 255; | 127 | static constexpr uint16_t ROOT_VIEW_OPACITY = 255; |
| 40 | 128 | ||
| 41 | static const char* const FONT_NAME = "SourceHanSansSC-Regular.otf"; | 129 | static const char* const FONT_NAME = "SourceHanSansSC-Regular.otf"; |
| 42 | 130 | ||
| 43 | -/** back icon 36 x 36 */ | 131 | +/** back icon 36 x 36 — scaled from 36 at 1920x1080 */ |
| 44 | -static constexpr int16_t BACK_ICON_POSITION_X = 38; | 132 | +static inline int16_t BACK_ICON_POSITION_X() |
| 45 | -static constexpr int16_t BACK_ICON_POSITION_Y = 17; | 133 | +{ |
| 134 | + return HScale(BACK_ICON_POS_X_REF); | ||
| 135 | +} | ||
| 136 | +static inline int16_t BACK_ICON_POSITION_Y() | ||
| 137 | +{ | ||
| 138 | + return VScale(BACK_ICON_POS_Y_REF); | ||
| 139 | +} | ||
| 140 | +static inline int16_t BACK_ICON_WIDTH() | ||
| 141 | +{ | ||
| 142 | + return HScale(BACK_ICON_SIZE_REF); | ||
| 143 | +} | ||
| 144 | +static inline int16_t BACK_ICON_HEIGHT() | ||
| 145 | +{ | ||
| 146 | + return VScale(BACK_ICON_SIZE_REF); | ||
| 147 | +} | ||
| 46 | 148 | ||
| 47 | -/** THUMBNAIL */ | 149 | +/** THUMBNAIL — scaled proportionally from 1920x1080 */ |
| 48 | -static constexpr int16_t THUMBNAIL_RESOLUTION_X = 120; | 150 | +static inline int16_t THUMBNAIL_RESOLUTION_X() |
| 49 | -static constexpr int16_t THUMBNAIL_RESOLUTION_Y = 120; | 151 | +{ |
| 152 | + return HScale(THUMBNAIL_SIZE_REF); | ||
| 153 | +} | ||
| 154 | +static inline int16_t THUMBNAIL_RESOLUTION_Y() | ||
| 155 | +{ | ||
| 156 | + return VScale(THUMBNAIL_SIZE_REF); | ||
| 157 | +} | ||
| 50 | static constexpr int16_t THUMBNAIL_SPACE = 4; | 158 | static constexpr int16_t THUMBNAIL_SPACE = 4; |
| 51 | static constexpr int16_t THUMBNAIL_COLUMN = 3; | 159 | static constexpr int16_t THUMBNAIL_COLUMN = 3; |
| 52 | 160 | ||
| 53 | -static constexpr int16_t VIDEO_TAG_POSITION_X = 10; | 161 | +static inline int16_t VIDEO_TAG_POSITION_X() |
| 54 | -static constexpr int16_t VIDEO_TAG_POSITION_Y = THUMBNAIL_RESOLUTION_Y - 37; | 162 | +{ |
| 163 | + return HScale(VIDEO_TAG_POS_X_REF); | ||
| 164 | +} | ||
| 165 | +static inline int16_t VIDEO_TAG_POSITION_Y() | ||
| 166 | +{ | ||
| 167 | + return THUMBNAIL_RESOLUTION_Y() - VScale(VIDEO_TAG_POS_Y_OFFSET_REF); | ||
| 168 | +} | ||
| 169 | +static inline int16_t VIDEO_TAG_WIDTH() | ||
| 170 | +{ | ||
| 171 | + return HScale(VIDEO_TAG_SIZE_REF); | ||
| 172 | +} | ||
| 173 | +static inline int16_t VIDEO_TAG_HEIGHT() | ||
| 174 | +{ | ||
| 175 | + return VScale(VIDEO_TAG_SIZE_REF); | ||
| 176 | +} | ||
| 55 | 177 | ||
| 56 | /** title */ | 178 | /** title */ |
| 57 | -static constexpr int16_t LABEL_POSITION_X = BACK_ICON_POSITION_X + 60; | 179 | +static inline int16_t LABEL_POSITION_X() |
| 180 | +{ | ||
| 181 | + return BACK_ICON_POSITION_X() + HScale(LABEL_OFFSET_X_REF); | ||
| 182 | +} | ||
| 58 | static constexpr int16_t LABEL_POSITION_Y = 0; | 183 | static constexpr int16_t LABEL_POSITION_Y = 0; |
| 59 | -static constexpr int16_t LABEL_WIDTH = 100; | 184 | +static inline int16_t LABEL_WIDTH() |
| 60 | -static constexpr int16_t LABEL_HEIGHT = 70; | 185 | +{ |
| 61 | -static constexpr uint16_t GALLERY_FONT_SIZE = 25; | 186 | + return HScale(LABEL_WIDTH_REF); |
| 62 | -static constexpr uint16_t GALLERY_DELETE_FONT_SIZE = 22; | 187 | +} |
| 63 | -static constexpr int16_t DELETE_LABEL_WIDTH = 150; | 188 | +static inline int16_t LABEL_HEIGHT() |
| 189 | +{ | ||
| 190 | + return VScale(LABEL_HEIGHT_REF); | ||
| 191 | +} | ||
| 192 | +static inline uint16_t GALLERY_FONT_SIZE() | ||
| 193 | +{ | ||
| 194 | + return FontScale(GALLERY_FONT_SIZE_REF); | ||
| 195 | +} | ||
| 196 | +static inline uint16_t GALLERY_DELETE_FONT_SIZE() | ||
| 197 | +{ | ||
| 198 | + return FontScale(GALLERY_DELETE_FONT_SIZE_REF); | ||
| 199 | +} | ||
| 200 | +static inline int16_t DELETE_LABEL_WIDTH() | ||
| 201 | +{ | ||
| 202 | + return HScale(DELETE_LABEL_WIDTH_REF); | ||
| 203 | +} | ||
| 64 | 204 | ||
| 65 | /** prefix and File Type */ | 205 | /** prefix and File Type */ |
| 66 | static const char* const PHOTO_PREFIX = "photo"; | 206 | static const char* const PHOTO_PREFIX = "photo"; |
| @@ -68,28 +208,81 @@ static const char* const AVAILABEL_SOURCE_TYPE = ".mp4"; | |||
| 68 | static const char* const AVAILABEL_SOURCE_TYPE_MP4 = ".MP4"; | 208 | static const char* const AVAILABEL_SOURCE_TYPE_MP4 = ".MP4"; |
| 69 | 209 | ||
| 70 | /** playback status bar */ | 210 | /** playback status bar */ |
| 71 | -static constexpr uint16_t STATUS_BAR_GROUP_HEIGHT = 96; | 211 | +static inline uint16_t STATUS_BAR_GROUP_HEIGHT() |
| 72 | -static constexpr uint16_t TOGGLE_BUTTON_OFFSET_X = 36; | 212 | +{ |
| 73 | -static constexpr uint16_t TOGGLE_BUTTON_OFFSET_Y = 18; | 213 | + return VScale(STATUS_BAR_GROUP_HEIGHT_REF); |
| 74 | -static constexpr uint16_t TOGGLE_BUTTON_WIDTH = 60; | 214 | +} |
| 75 | -static constexpr uint16_t TOGGLE_BUTTON_HEIGHT = 60; | 215 | +static inline uint16_t TOGGLE_BUTTON_OFFSET_X() |
| 216 | +{ | ||
| 217 | + return HScale(TOGGLE_BUTTON_OFFSET_X_REF); | ||
| 218 | +} | ||
| 219 | +static inline uint16_t TOGGLE_BUTTON_OFFSET_Y() | ||
| 220 | +{ | ||
| 221 | + return VScale(TOGGLE_BUTTON_OFFSET_Y_REF); | ||
| 222 | +} | ||
| 223 | +static inline uint16_t TOGGLE_BUTTON_WIDTH() | ||
| 224 | +{ | ||
| 225 | + return HScale(TOGGLE_BUTTON_SIZE_REF); | ||
| 226 | +} | ||
| 227 | +static inline uint16_t TOGGLE_BUTTON_HEIGHT() | ||
| 228 | +{ | ||
| 229 | + return VScale(TOGGLE_BUTTON_SIZE_REF); | ||
| 230 | +} | ||
| 76 | 231 | ||
| 77 | -static constexpr uint16_t CURRENT_TIME_LABEL_X = TOGGLE_BUTTON_OFFSET_X + TOGGLE_BUTTON_WIDTH + TOGGLE_BUTTON_OFFSET_Y; | 232 | +static inline uint16_t CURRENT_TIME_LABEL_X() |
| 233 | +{ | ||
| 234 | + return TOGGLE_BUTTON_OFFSET_X() + TOGGLE_BUTTON_WIDTH() + TOGGLE_BUTTON_OFFSET_Y(); | ||
| 235 | +} | ||
| 78 | static constexpr uint16_t CURRENT_TIME_LABEL_Y = 0; | 236 | static constexpr uint16_t CURRENT_TIME_LABEL_Y = 0; |
| 79 | -static constexpr uint16_t CURRENT_TIME_LABEL_WIDTH = 60; | 237 | +static inline uint16_t CURRENT_TIME_LABEL_WIDTH() |
| 80 | -static constexpr uint16_t CURRENT_TIME_LABEL_HEIGHT = STATUS_BAR_GROUP_HEIGHT; | 238 | +{ |
| 239 | + return HScale(CURRENT_TIME_LABEL_WIDTH_REF); | ||
| 240 | +} | ||
| 241 | +static inline uint16_t CURRENT_TIME_LABEL_HEIGHT() | ||
| 242 | +{ | ||
| 243 | + return STATUS_BAR_GROUP_HEIGHT(); | ||
| 244 | +} | ||
| 81 | 245 | ||
| 82 | -static constexpr uint16_t TOTAL_TIME_LABEL_WIDTH = 90; | 246 | +static inline uint16_t TOTAL_TIME_LABEL_WIDTH() |
| 83 | -static constexpr uint16_t TOTAL_TIME_LABEL_HEIGHT = STATUS_BAR_GROUP_HEIGHT; | 247 | +{ |
| 84 | -static constexpr uint16_t TOTAL_TIME_LABEL_X = ROOT_VIEW_WIDTH - TOTAL_TIME_LABEL_WIDTH; | 248 | + return HScale(TOTAL_TIME_LABEL_WIDTH_REF); |
| 249 | +} | ||
| 250 | +static inline uint16_t TOTAL_TIME_LABEL_HEIGHT() | ||
| 251 | +{ | ||
| 252 | + return STATUS_BAR_GROUP_HEIGHT(); | ||
| 253 | +} | ||
| 254 | +static inline uint16_t TOTAL_TIME_LABEL_X() | ||
| 255 | +{ | ||
| 256 | + return ROOT_VIEW_WIDTH() - TOTAL_TIME_LABEL_WIDTH(); | ||
| 257 | +} | ||
| 85 | static constexpr uint16_t TOTAL_TIME_LABEL_Y = 0; | 258 | static constexpr uint16_t TOTAL_TIME_LABEL_Y = 0; |
| 86 | 259 | ||
| 87 | -static constexpr uint16_t SLIDER_X = CURRENT_TIME_LABEL_X + CURRENT_TIME_LABEL_WIDTH; | 260 | +static inline uint16_t SLIDER_X() |
| 88 | -static constexpr uint16_t SLIDER_Y = 2; | 261 | +{ |
| 89 | -static constexpr uint16_t SLIDER_HEIGHT = 3; | 262 | + return CURRENT_TIME_LABEL_X() + CURRENT_TIME_LABEL_WIDTH(); |
| 90 | -static constexpr uint16_t SLIDER_WIDTH = ROOT_VIEW_WIDTH - SLIDER_X - TOTAL_TIME_LABEL_WIDTH - 20; | 263 | +} |
| 91 | -static constexpr uint16_t KNOB_WIDTH = 25; | 264 | +static inline uint16_t SLIDER_Y() |
| 265 | +{ | ||
| 266 | + return VScale(SLIDER_Y_REF); | ||
| 267 | +} | ||
| 268 | +static inline uint16_t SLIDER_HEIGHT() | ||
| 269 | +{ | ||
| 270 | + return VScale(SLIDER_HEIGHT_REF); | ||
| 271 | +} | ||
| 272 | +static inline uint16_t SLIDER_WIDTH() | ||
| 273 | +{ | ||
| 274 | + return ROOT_VIEW_WIDTH() - SLIDER_X() - TOTAL_TIME_LABEL_WIDTH() - | ||
| 275 | + HScale(SLIDER_MARGIN_RIGHT_REF); | ||
| 276 | +} | ||
| 277 | +static inline uint16_t KNOB_WIDTH() | ||
| 278 | +{ | ||
| 279 | + return HScale(KNOB_WIDTH_REF); | ||
| 280 | +} | ||
| 281 | + | ||
| 282 | +static inline uint16_t PLAYER_FONT_SIZE() | ||
| 283 | +{ | ||
| 284 | + return FontScale(PLAYER_FONT_SIZE_REF); | ||
| 285 | +} | ||
| 92 | 286 | ||
| 93 | -static constexpr uint16_t PLAYER_FONT_SIZE = 18; | ||
| 94 | } // namespace OHOS | 287 | } // namespace OHOS |
| 95 | -#endif // OHOS_GALLERY_CONFIG_H | 288 | +#endif // OHOS_GALLERY_CONFIG_H |
| @@ -0,0 +1,70 @@ | |||
| 1 | +/* | ||
| 2 | + * Copyright (c) 2026 RKH Corp. | ||
| 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 | + */ | ||
| 15 | + | ||
| 16 | +#ifndef GALLERY_LOG_H | ||
| 17 | +#define GALLERY_LOG_H | ||
| 18 | + | ||
| 19 | +#ifdef HILOG_ENABLE | ||
| 20 | + | ||
| 21 | +#ifndef LOG_DOMAIN | ||
| 22 | +#define LOG_DOMAIN 0xD0000 | ||
| 23 | +#endif | ||
| 24 | + | ||
| 25 | +#ifndef LOG_TAG | ||
| 26 | +#define LOG_TAG "[GALLERY]" | ||
| 27 | +#endif | ||
| 28 | + | ||
| 29 | +#include <hilog/log.h> | ||
| 30 | + | ||
| 31 | +#ifdef __cplusplus | ||
| 32 | +extern "C" { | ||
| 33 | +#endif | ||
| 34 | + | ||
| 35 | +#define FILE_NAME (strrchr((__FILE__), '/') ? strrchr((__FILE__), '/') + 1 : (__FILE__)) | ||
| 36 | + | ||
| 37 | +#define LOGD(fmt, ...) HILOG_DEBUG(LOG_APP, "[%s:%d] " fmt, FILE_NAME, __LINE__, ##__VA_ARGS__) | ||
| 38 | +#define LOGI(fmt, ...) HILOG_INFO(LOG_APP, "[%s:%d] " fmt, FILE_NAME, __LINE__, ##__VA_ARGS__) | ||
| 39 | +#define LOGW(fmt, ...) HILOG_WARN(LOG_APP, "[%s:%d] " fmt, FILE_NAME, __LINE__, ##__VA_ARGS__) | ||
| 40 | +#define LOGE(fmt, ...) HILOG_ERROR(LOG_APP, "[%s:%d] " fmt, FILE_NAME, __LINE__, ##__VA_ARGS__) | ||
| 41 | +#define LOGF(fmt, ...) HILOG_FATAL(LOG_APP, "[%s:%d] " fmt, FILE_NAME, __LINE__, ##__VA_ARGS__) | ||
| 42 | + | ||
| 43 | +#ifdef __cplusplus | ||
| 44 | +} | ||
| 45 | +#endif | ||
| 46 | + | ||
| 47 | +#else | ||
| 48 | + | ||
| 49 | +#include <stdio.h> | ||
| 50 | +#include <string.h> | ||
| 51 | + | ||
| 52 | +#ifdef __cplusplus | ||
| 53 | +extern "C" { | ||
| 54 | +#endif | ||
| 55 | + | ||
| 56 | +#define FILE_NAME (strrchr((__FILE__), '/') ? strrchr((__FILE__), '/') + 1 : (__FILE__)) | ||
| 57 | + | ||
| 58 | +#define LOGD(fmt, ...) printf("[D][GALLERY][%s:%d] " fmt "\n", FILE_NAME, __LINE__, ##__VA_ARGS__) | ||
| 59 | +#define LOGI(fmt, ...) printf("[I][GALLERY][%s:%d] " fmt "\n", FILE_NAME, __LINE__, ##__VA_ARGS__) | ||
| 60 | +#define LOGW(fmt, ...) printf("[W][GALLERY][%s:%d] " fmt "\n", FILE_NAME, __LINE__, ##__VA_ARGS__) | ||
| 61 | +#define LOGE(fmt, ...) printf("[E][GALLERY][%s:%d] " fmt "\n", FILE_NAME, __LINE__, ##__VA_ARGS__) | ||
| 62 | +#define LOGF(fmt, ...) printf("[F][GALLERY][%s:%d] " fmt "\n", FILE_NAME, __LINE__, ##__VA_ARGS__) | ||
| 63 | + | ||
| 64 | +#ifdef __cplusplus | ||
| 65 | +} | ||
| 66 | +#endif | ||
| 67 | + | ||
| 68 | +#endif | ||
| 69 | + | ||
| 70 | +#endif /* GALLERY_LOG_H */ | ||
| @@ -0,0 +1,71 @@ | |||
| 1 | +/* | ||
| 2 | + * Copyright (c) 2026 RKH Corp. | ||
| 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 | + */ | ||
| 15 | + | ||
| 16 | +#ifndef GALLERY_IMAGE_DECODER_H | ||
| 17 | +#define GALLERY_IMAGE_DECODER_H | ||
| 18 | + | ||
| 19 | +#include <memory> | ||
| 20 | +#include <string> | ||
| 21 | +#include <functional> | ||
| 22 | +#include <thread> | ||
| 23 | +#include <vector> | ||
| 24 | +#include <queue> | ||
| 25 | +#include <mutex> | ||
| 26 | +#include <condition_variable> | ||
| 27 | +#include <atomic> | ||
| 28 | + | ||
| 29 | +#include <common/image.h> | ||
| 30 | +#include <ability_event_handler.h> | ||
| 31 | + | ||
| 32 | +namespace OHOS { | ||
| 33 | + | ||
| 34 | +class ImageDecoder { | ||
| 35 | +public: | ||
| 36 | + ImageDecoder(AbilityEventHandler* handler, size_t threadCount = 1); | ||
| 37 | + | ||
| 38 | + ~ImageDecoder(); | ||
| 39 | + | ||
| 40 | + void DecodeImage(const std::string& imagePath, std::function<void(ImageInfo)> uiCallback); | ||
| 41 | + | ||
| 42 | + void Start(); | ||
| 43 | + void Stop(); | ||
| 44 | + bool IsRunning(); | ||
| 45 | + | ||
| 46 | +private: | ||
| 47 | + struct DecodeTask { | ||
| 48 | + std::string imagePath; | ||
| 49 | + std::function<void(ImageInfo)> callback; | ||
| 50 | + }; | ||
| 51 | + | ||
| 52 | + void WorkerThread(); | ||
| 53 | + bool TryGetTask(DecodeTask& task); | ||
| 54 | + void HandleTask(const DecodeTask& task); | ||
| 55 | + void NotifyCallback(const DecodeTask& task, const ImageInfo& imageInfo); | ||
| 56 | + | ||
| 57 | + ImageInfo DoDecode(const std::string& imagePath); | ||
| 58 | + | ||
| 59 | +private: | ||
| 60 | + std::vector<std::thread> workerThreads_; // 工作线程池 | ||
| 61 | + std::queue<DecodeTask> taskQueue_; // 任务队列 | ||
| 62 | + std::mutex queueMutex_; // 队列互斥锁 | ||
| 63 | + std::condition_variable taskCond_; // 任务条件变量 | ||
| 64 | + std::atomic<bool> isRunning_; // 运行状态标记 | ||
| 65 | + int maxThreadCount_; // 最大任务个数 | ||
| 66 | + | ||
| 67 | + AbilityEventHandler *eventHandler_ = nullptr; | ||
| 68 | +}; | ||
| 69 | + | ||
| 70 | +} | ||
| 71 | +#endif // GALLERY_IMAGE_DECODER_H | ||
| @@ -19,6 +19,7 @@ | |||
| 19 | #include <ability_loader.h> | 19 | #include <ability_loader.h> |
| 20 | #include "components/ui_image_view.h" | 20 | #include "components/ui_image_view.h" |
| 21 | #include "components/ui_view_group.h" | 21 | #include "components/ui_view_group.h" |
| 22 | +#include "components/ui_label.h" | ||
| 22 | #include "event_listener.h" | 23 | #include "event_listener.h" |
| 23 | #include "gallery_config.h" | 24 | #include "gallery_config.h" |
| 24 | 25 | ||
| @@ -36,12 +37,13 @@ protected: | |||
| 36 | 37 | ||
| 37 | private: | 38 | private: |
| 38 | void Clear(); | 39 | void Clear(); |
| 39 | - void InitTitle(); | 40 | + void InitTitle(const char* imageName); |
| 40 | void InitPicture(const char* path); | 41 | void InitPicture(const char* path); |
| 41 | 42 | ||
| 42 | RootView* rootView_ { nullptr }; | 43 | RootView* rootView_ { nullptr }; |
| 43 | UIViewGroup* backArea_ { nullptr }; | 44 | UIViewGroup* backArea_ { nullptr }; |
| 44 | UIImageView* backIcon_ { nullptr }; | 45 | UIImageView* backIcon_ { nullptr }; |
| 46 | + UILabel* titleLabel_ { nullptr }; | ||
| 45 | EventListener* backIconListener_ { nullptr }; | 47 | EventListener* backIconListener_ { nullptr }; |
| 46 | UIImageView* picture_ { nullptr }; | 48 | UIImageView* picture_ { nullptr }; |
| 47 | char backIconAbsolutePath[MAX_PATH_LENGTH] = { 0 }; | 49 | char backIconAbsolutePath[MAX_PATH_LENGTH] = { 0 }; |
| @@ -122,7 +122,7 @@ private: | |||
| 122 | void Clear(); | 122 | void Clear(); |
| 123 | void ShowErrorTips(); | 123 | void ShowErrorTips(); |
| 124 | void SetUpRootView(); | 124 | void SetUpRootView(); |
| 125 | - void SetUpBackArea(const char* pathHeader); | 125 | + void SetUpBackArea(const char* pathHeader, const char* imageName); |
| 126 | void SetUpVideoPlayer(const Want &want); | 126 | void SetUpVideoPlayer(const Want &want); |
| 127 | bool SetUpSurfaceView(); | 127 | bool SetUpSurfaceView(); |
| 128 | void SetUpProgress(int64_t duration); | 128 | void SetUpProgress(int64_t duration); |
| @@ -137,6 +137,7 @@ private: | |||
| 137 | RootView* rootView_ { nullptr }; | 137 | RootView* rootView_ { nullptr }; |
| 138 | UIViewGroup* backArea_ { nullptr }; | 138 | UIViewGroup* backArea_ { nullptr }; |
| 139 | UIImageView* backIcon_ { nullptr }; | 139 | UIImageView* backIcon_ { nullptr }; |
| 140 | + UILabel* titleLabel_ { nullptr }; | ||
| 140 | UISurfaceView* surfaceView_ { nullptr }; | 141 | UISurfaceView* surfaceView_ { nullptr }; |
| 141 | UIViewGroup* animatorGroup_ { nullptr }; | 142 | UIViewGroup* animatorGroup_ { nullptr }; |
| 142 | UIToggleButton* toggleButton_ { nullptr }; | 143 | UIToggleButton* toggleButton_ { nullptr }; |
| @@ -0,0 +1,20 @@ | |||
| 1 | +# Copyright (c) 2026 RKH Corp. | ||
| 2 | +# Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | +# you may not use this file except in compliance with the License. | ||
| 4 | +# You may obtain a copy of the License at | ||
| 5 | +# | ||
| 6 | +# http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | +# | ||
| 8 | +# Unless required by applicable law or agreed to in writing, software | ||
| 9 | +# distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | +# See the License for the specific language governing permissions and | ||
| 12 | +# limitations under the License. | ||
| 13 | + | ||
| 14 | +copy("test_jpeg") { | ||
| 15 | + sources = [ | ||
| 16 | + "photo1.jpeg", | ||
| 17 | + "photo2.jpeg" | ||
| 18 | + ] | ||
| 19 | + outputs = [ "${root_out_dir}/system/internal/{{source_file_part}}" ] | ||
| 20 | +} | ||
| @@ -14,39 +14,39 @@ | |||
| 14 | */ | 14 | */ |
| 15 | 15 | ||
| 16 | #include "gallery_ability.h" | 16 | #include "gallery_ability.h" |
| 17 | +#include "gallery_log.h" | ||
| 17 | 18 | ||
| 18 | namespace OHOS { | 19 | namespace OHOS { |
| 19 | REGISTER_AA(GalleryAbility) | 20 | REGISTER_AA(GalleryAbility) |
| 20 | 21 | ||
| 21 | void GalleryAbility::OnStart(const Want &want) | 22 | void GalleryAbility::OnStart(const Want &want) |
| 22 | { | 23 | { |
| 23 | - printf("GalleryAbility::OnStart\n"); | 24 | + LOGI("GalleryAbility::OnStart"); |
| 24 | SetMainRoute("GalleryAbilitySlice"); | 25 | SetMainRoute("GalleryAbilitySlice"); |
| 25 | - | ||
| 26 | Ability::OnStart(want); | 26 | Ability::OnStart(want); |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | void GalleryAbility::OnInactive() | 29 | void GalleryAbility::OnInactive() |
| 30 | { | 30 | { |
| 31 | - printf("GalleryAbility::OnInactive\n"); | 31 | + LOGI("GalleryAbility::OnInactive"); |
| 32 | Ability::OnInactive(); | 32 | Ability::OnInactive(); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | void GalleryAbility::OnActive(const Want &want) | 35 | void GalleryAbility::OnActive(const Want &want) |
| 36 | { | 36 | { |
| 37 | - printf("GalleryAbility::OnActive\n"); | 37 | + LOGI("GalleryAbility::OnActive"); |
| 38 | Ability::OnActive(want); | 38 | Ability::OnActive(want); |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | void GalleryAbility::OnBackground() | 41 | void GalleryAbility::OnBackground() |
| 42 | { | 42 | { |
| 43 | - printf("GalleryAbility::OnBackground\n"); | 43 | + LOGI("GalleryAbility::OnBackground"); |
| 44 | Ability::OnBackground(); | 44 | Ability::OnBackground(); |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | void GalleryAbility::OnStop() | 47 | void GalleryAbility::OnStop() |
| 48 | { | 48 | { |
| 49 | - printf("GalleryAbility::OnStop\n"); | 49 | + LOGI("GalleryAbility::OnStop"); |
| 50 | Ability::OnStop(); | 50 | Ability::OnStop(); |
| 51 | } | 51 | } |
| 52 | } | 52 | } |
| @@ -16,24 +16,29 @@ | |||
| 16 | #include "gallery_ability_slice.h" | 16 | #include "gallery_ability_slice.h" |
| 17 | #include "ability_env.h" | 17 | #include "ability_env.h" |
| 18 | #include "ability_manager.h" | 18 | #include "ability_manager.h" |
| 19 | +#include <ability_event_handler.h> | ||
| 19 | #include "picture_ability_slice.h" | 20 | #include "picture_ability_slice.h" |
| 20 | 21 | ||
| 21 | #include "gfx_utils/file.h" | 22 | #include "gfx_utils/file.h" |
| 23 | +#include "gfx_utils/mem_api.h" | ||
| 22 | #include "securec.h" | 24 | #include "securec.h" |
| 23 | 25 | ||
| 26 | +#include "gallery_log.h" | ||
| 27 | +#include "image_decoder.h" | ||
| 28 | + | ||
| 24 | namespace OHOS { | 29 | namespace OHOS { |
| 25 | REGISTER_AS(GalleryAbilitySlice) | 30 | REGISTER_AS(GalleryAbilitySlice) |
| 26 | 31 | ||
| 27 | GalleryAbilitySlice::~GalleryAbilitySlice() | 32 | GalleryAbilitySlice::~GalleryAbilitySlice() |
| 28 | { | 33 | { |
| 29 | - printf("~GalleryAbilitySlice() | start \n"); | 34 | + LOGI("~GalleryAbilitySlice() | start"); |
| 30 | Clear(); | 35 | Clear(); |
| 31 | - printf("~GalleryAbilitySlice() | end \n"); | 36 | + LOGI("~GalleryAbilitySlice() | end"); |
| 32 | } | 37 | } |
| 33 | 38 | ||
| 34 | void GalleryAbilitySlice::Clear() | 39 | void GalleryAbilitySlice::Clear() |
| 35 | { | 40 | { |
| 36 | - printf("GalleryAbilitySlice::Clear() | start \n"); | 41 | + LOGI("GalleryAbilitySlice::Clear() | start"); |
| 37 | if (backIcon_ != nullptr) { | 42 | if (backIcon_ != nullptr) { |
| 38 | delete backIcon_; | 43 | delete backIcon_; |
| 39 | backIcon_ = nullptr; | 44 | backIcon_ = nullptr; |
| @@ -58,6 +63,10 @@ void GalleryAbilitySlice::Clear() | |||
| 58 | delete deleteLabel_; | 63 | delete deleteLabel_; |
| 59 | deleteLabel_ = nullptr; | 64 | deleteLabel_ = nullptr; |
| 60 | } | 65 | } |
| 66 | + if (imageDecoder_ != nullptr) { | ||
| 67 | + delete imageDecoder_; | ||
| 68 | + imageDecoder_ = nullptr; | ||
| 69 | + } | ||
| 61 | 70 | ||
| 62 | ClearThumb(); | 71 | ClearThumb(); |
| 63 | 72 | ||
| @@ -65,12 +74,12 @@ void GalleryAbilitySlice::Clear() | |||
| 65 | RootView::DestroyWindowRootView(rootView_); | 74 | RootView::DestroyWindowRootView(rootView_); |
| 66 | rootView_ = nullptr; | 75 | rootView_ = nullptr; |
| 67 | } | 76 | } |
| 68 | - printf("GalleryAbilitySlice::Clear() | end \n"); | 77 | + LOGI("GalleryAbilitySlice::Clear() | end"); |
| 69 | } | 78 | } |
| 70 | 79 | ||
| 71 | void GalleryAbilitySlice::ClearThumb() | 80 | void GalleryAbilitySlice::ClearThumb() |
| 72 | { | 81 | { |
| 73 | - printf("GalleryAbilitySlice::ClearThumb() | start \n"); | 82 | + LOGI("GalleryAbilitySlice::ClearThumb() | start"); |
| 74 | if (picContainer_ != nullptr) { | 83 | if (picContainer_ != nullptr) { |
| 75 | delete picContainer_; | 84 | delete picContainer_; |
| 76 | picContainer_ = nullptr; | 85 | picContainer_ = nullptr; |
| @@ -94,12 +103,12 @@ void GalleryAbilitySlice::ClearThumb() | |||
| 94 | } | 103 | } |
| 95 | pictureCount_ = 0; | 104 | pictureCount_ = 0; |
| 96 | pictureOnClickListenerCount_ = 0; | 105 | pictureOnClickListenerCount_ = 0; |
| 97 | - printf("GalleryAbilitySlice::ClearThumb() | end \n"); | 106 | + LOGI("GalleryAbilitySlice::ClearThumb() | end"); |
| 98 | } | 107 | } |
| 99 | 108 | ||
| 100 | void GalleryAbilitySlice::ClearPictureList(const UIView* view) | 109 | void GalleryAbilitySlice::ClearPictureList(const UIView* view) |
| 101 | { | 110 | { |
| 102 | - printf("GalleryAbilitySlice::ClearPictureList() | start \n"); | 111 | + LOGI("GalleryAbilitySlice::ClearPictureList() | start"); |
| 103 | if (view == nullptr || !(view->IsViewGroup())) { | 112 | if (view == nullptr || !(view->IsViewGroup())) { |
| 104 | return; | 113 | return; |
| 105 | } | 114 | } |
| @@ -113,100 +122,123 @@ void GalleryAbilitySlice::ClearPictureList(const UIView* view) | |||
| 113 | delete child; | 122 | delete child; |
| 114 | child = childNext; | 123 | child = childNext; |
| 115 | } | 124 | } |
| 116 | - printf("GalleryAbilitySlice::ClearPictureList() | end \n"); | 125 | + LOGI("GalleryAbilitySlice::ClearPictureList() | end"); |
| 117 | } | 126 | } |
| 118 | 127 | ||
| 119 | void GalleryAbilitySlice::InitTitle() | 128 | void GalleryAbilitySlice::InitTitle() |
| 120 | { | 129 | { |
| 121 | - printf("GalleryAbilitySlice::InitTitle | start \n"); | 130 | + LOGI("GalleryAbilitySlice::InitTitle | start"); |
| 131 | + InitTitleBackArea(); | ||
| 132 | + InitTitleLabels(); | ||
| 133 | +} | ||
| 134 | + | ||
| 135 | +void GalleryAbilitySlice::InitTitleBackArea() | ||
| 136 | +{ | ||
| 122 | backIcon_ = new UIImageView(); | 137 | backIcon_ = new UIImageView(); |
| 123 | - backIcon_->SetPosition(BACK_ICON_POSITION_X, BACK_ICON_POSITION_Y); | 138 | + backIcon_->SetAutoEnable(false); |
| 139 | + backIcon_->SetResizeMode(UIImageView::ImageResizeMode::CONTAIN); | ||
| 140 | + backIcon_->SetPosition(BACK_ICON_POSITION_X(), BACK_ICON_POSITION_Y(), BACK_ICON_WIDTH(), BACK_ICON_HEIGHT()); | ||
| 124 | backIcon_->SetSrc(backIconAbsolutePath); | 141 | backIcon_->SetSrc(backIconAbsolutePath); |
| 125 | backIcon_->SetTouchable(true); | 142 | backIcon_->SetTouchable(true); |
| 126 | 143 | ||
| 127 | backArea_ = new UIViewGroup(); | 144 | backArea_ = new UIViewGroup(); |
| 128 | - backArea_->SetPosition(0, 0, LABEL_POSITION_X, LABEL_HEIGHT); | 145 | + backArea_->SetPosition(0, 0, LABEL_POSITION_X(), LABEL_HEIGHT()); |
| 129 | backArea_->SetStyle(STYLE_BACKGROUND_OPA, 0); | 146 | backArea_->SetStyle(STYLE_BACKGROUND_OPA, 0); |
| 130 | backArea_->SetTouchable(true); | 147 | backArea_->SetTouchable(true); |
| 131 | 148 | ||
| 132 | auto onClick = [this] (UIView& view, const Event& event) -> bool { | 149 | auto onClick = [this] (UIView& view, const Event& event) -> bool { |
| 133 | - printf("############ Next AS enter #############\n"); | 150 | + LOGI("############ Next AS enter #############"); |
| 134 | TerminateAbility(); | 151 | TerminateAbility(); |
| 135 | - printf("############ Next AS exit #############\n"); | 152 | + LOGI("############ Next AS exit #############"); |
| 136 | return true; | 153 | return true; |
| 137 | }; | 154 | }; |
| 138 | backIconListener_ = new EventListener(onClick, nullptr); | 155 | backIconListener_ = new EventListener(onClick, nullptr); |
| 139 | backIcon_->SetOnClickListener(backIconListener_); | 156 | backIcon_->SetOnClickListener(backIconListener_); |
| 140 | backArea_->SetOnClickListener(backIconListener_); | 157 | backArea_->SetOnClickListener(backIconListener_); |
| 141 | 158 | ||
| 159 | + backArea_->Add(backIcon_); | ||
| 160 | + rootView_->Add(backArea_); | ||
| 161 | +} | ||
| 162 | + | ||
| 163 | +void GalleryAbilitySlice::InitTitleLabels() | ||
| 164 | +{ | ||
| 142 | titleLabel_ = new UILabel(); | 165 | titleLabel_ = new UILabel(); |
| 143 | - titleLabel_->SetPosition(LABEL_POSITION_X, LABEL_POSITION_Y, LABEL_WIDTH, LABEL_HEIGHT); | 166 | + titleLabel_->SetPosition(LABEL_POSITION_X(), LABEL_POSITION_Y, LABEL_WIDTH(), LABEL_HEIGHT()); |
| 144 | titleLabel_->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_LEFT, UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); | 167 | titleLabel_->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_LEFT, UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); |
| 145 | - titleLabel_->SetFont(FONT_NAME, GALLERY_FONT_SIZE); | 168 | + titleLabel_->SetFont(FONT_NAME, GALLERY_FONT_SIZE()); |
| 169 | + titleLabel_->SetStyle(STYLE_TEXT_COLOR, Color::Black().full); | ||
| 170 | + titleLabel_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); | ||
| 146 | titleLabel_->SetText("照片"); | 171 | titleLabel_->SetText("照片"); |
| 147 | 172 | ||
| 148 | deleteLabel_ = new UILabel(); | 173 | deleteLabel_ = new UILabel(); |
| 149 | - deleteLabel_->SetPosition(ROOT_VIEW_WIDTH - DELETE_LABEL_WIDTH, LABEL_POSITION_Y, | 174 | + deleteLabel_->SetPosition(ROOT_VIEW_WIDTH() - DELETE_LABEL_WIDTH(), LABEL_POSITION_Y, |
| 150 | - DELETE_LABEL_WIDTH, LABEL_HEIGHT); | 175 | + DELETE_LABEL_WIDTH(), LABEL_HEIGHT()); |
| 151 | deleteLabel_->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_LEFT, | 176 | deleteLabel_->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_LEFT, |
| 152 | UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); | 177 | UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); |
| 153 | - deleteLabel_->SetFont(FONT_NAME, GALLERY_DELETE_FONT_SIZE); | 178 | + deleteLabel_->SetFont(FONT_NAME, GALLERY_DELETE_FONT_SIZE()); |
| 179 | + deleteLabel_->SetStyle(STYLE_TEXT_COLOR, Color::Black().full); | ||
| 180 | + deleteLabel_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); | ||
| 154 | deleteLabel_->SetText("全部删除"); | 181 | deleteLabel_->SetText("全部删除"); |
| 155 | deleteLabel_->SetTouchable(true); | 182 | deleteLabel_->SetTouchable(true); |
| 156 | auto deleteClick = [this] (UIView& view, const Event& event) -> bool { | 183 | auto deleteClick = [this] (UIView& view, const Event& event) -> bool { |
| 157 | - printf("############ DeleteAllData click enter #############\n"); | 184 | + LOGI("############ DeleteAllData click enter #############"); |
| 158 | DeleteAllData(); | 185 | DeleteAllData(); |
| 159 | - printf("############ DeleteAllData click exit #############\n"); | 186 | + LOGI("############ DeleteAllData click exit #############"); |
| 160 | return true; | 187 | return true; |
| 161 | }; | 188 | }; |
| 162 | deleteClickListener_ = new EventListener(deleteClick, nullptr); | 189 | deleteClickListener_ = new EventListener(deleteClick, nullptr); |
| 163 | deleteLabel_->SetOnClickListener(deleteClickListener_); | 190 | deleteLabel_->SetOnClickListener(deleteClickListener_); |
| 164 | 191 | ||
| 165 | - backArea_->Add(backIcon_); | ||
| 166 | - rootView_->Add(backArea_); | ||
| 167 | rootView_->Add(titleLabel_); | 192 | rootView_->Add(titleLabel_); |
| 168 | rootView_->Add(deleteLabel_); | 193 | rootView_->Add(deleteLabel_); |
| 169 | } | 194 | } |
| 170 | 195 | ||
| 171 | void GalleryAbilitySlice::InitPictureList() | 196 | void GalleryAbilitySlice::InitPictureList() |
| 172 | { | 197 | { |
| 173 | - printf("GalleryAbilitySlice::InitPictureList | start \n"); | 198 | + LOGI("GalleryAbilitySlice::InitPictureList | start"); |
| 174 | picContainer_ = new UIScrollView(); | 199 | picContainer_ = new UIScrollView(); |
| 175 | - picContainer_->SetPosition(0, LABEL_POSITION_Y + LABEL_HEIGHT); | 200 | + picContainer_->SetPosition(0, LABEL_POSITION_Y + LABEL_HEIGHT()); |
| 176 | - picContainer_->Resize(ROOT_VIEW_WIDTH, (THUMBNAIL_RESOLUTION_Y + THUMBNAIL_SPACE) * THUMBNAIL_COLUMN); | 201 | + picContainer_->Resize(ROOT_VIEW_WIDTH(), ROOT_VIEW_HEIGHT() - (LABEL_POSITION_Y + LABEL_HEIGHT())); |
| 177 | picContainer_->SetStyle(STYLE_BACKGROUND_OPA, 0); | 202 | picContainer_->SetStyle(STYLE_BACKGROUND_OPA, 0); |
| 203 | + picContainer_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Silver().full); | ||
| 178 | rootView_->Add(picContainer_); | 204 | rootView_->Add(picContainer_); |
| 179 | 205 | ||
| 180 | picList_ = new UIViewGroup(); | 206 | picList_ = new UIViewGroup(); |
| 181 | - picList_->SetPosition(0, 0, ROOT_VIEW_WIDTH, ROOT_VIEW_HEIGHT); | 207 | + picList_->SetPosition(0, 0, ROOT_VIEW_WIDTH(), ROOT_VIEW_HEIGHT()); |
| 182 | picList_->SetStyle(STYLE_BACKGROUND_OPA, 0); | 208 | picList_->SetStyle(STYLE_BACKGROUND_OPA, 0); |
| 183 | 209 | ||
| 184 | - int16_t numInLine = (ROOT_VIEW_WIDTH + THUMBNAIL_SPACE) / (THUMBNAIL_RESOLUTION_X + THUMBNAIL_SPACE); | 210 | + int16_t numInLine = (ROOT_VIEW_WIDTH() + THUMBNAIL_SPACE) / (THUMBNAIL_RESOLUTION_X() + THUMBNAIL_SPACE); |
| 185 | - int16_t offset = ((ROOT_VIEW_WIDTH + THUMBNAIL_SPACE) % (THUMBNAIL_RESOLUTION_X + THUMBNAIL_SPACE)) / 2; // 2: half | 211 | + int16_t offset = ((ROOT_VIEW_WIDTH() + THUMBNAIL_SPACE) % |
| 186 | - AddAllPictures(Point { offset, 0 }, numInLine); | 212 | + (THUMBNAIL_RESOLUTION_X() + THUMBNAIL_SPACE)) / 2; // 2: half |
| 213 | + AddAllPictures(Point { offset, 0 }, numInLine, PHOTO_DIRECTORY); | ||
| 214 | +#ifndef MEDIA_INTERFACE_V1_0 | ||
| 215 | + AddAllPictures(Point { offset, 0 }, numInLine, VIDEO_SOURCE_DIRECTORY); | ||
| 216 | +#endif | ||
| 187 | 217 | ||
| 188 | - int16_t totalHeight = (pictureCount_ / numInLine) * (THUMBNAIL_RESOLUTION_Y + THUMBNAIL_SPACE); | 218 | + int16_t totalHeight = (pictureCount_ / numInLine) * (THUMBNAIL_RESOLUTION_Y() + THUMBNAIL_SPACE); |
| 189 | if ((pictureCount_ % numInLine) != 0) { | 219 | if ((pictureCount_ % numInLine) != 0) { |
| 190 | - totalHeight += THUMBNAIL_RESOLUTION_Y + THUMBNAIL_SPACE; | 220 | + totalHeight += THUMBNAIL_RESOLUTION_Y() + THUMBNAIL_SPACE; |
| 191 | } | 221 | } |
| 192 | - picList_->Resize(ROOT_VIEW_WIDTH, totalHeight); | 222 | + picList_->Resize(ROOT_VIEW_WIDTH(), totalHeight); |
| 193 | - printf("------------ totalHeight : %d ------------", totalHeight); | 223 | + LOGI("------------ totalHeight : %d ------------", totalHeight); |
| 194 | picContainer_->Add(picList_); | 224 | picContainer_->Add(picList_); |
| 195 | } | 225 | } |
| 196 | 226 | ||
| 197 | -void GalleryAbilitySlice::AddAllPictures(const Point& pos, int16_t numInLine) | 227 | +void GalleryAbilitySlice::AddAllPictures(const Point& pos, int16_t numInLine, std::string directoryPath) |
| 198 | { | 228 | { |
| 199 | - printf("GalleryAbilitySlice::AddAllPictures | start | %d\n", numInLine); | 229 | + LOGI("GalleryAbilitySlice::AddAllPictures | start | %d", numInLine); |
| 200 | Point imagePos = pos; | 230 | Point imagePos = pos; |
| 201 | - DIR* drip = opendir(THUMBNAIL_DIRECTORY); | 231 | + LOGI("opendir: %s", directoryPath.c_str()); |
| 232 | + DIR* drip = opendir(directoryPath.c_str()); | ||
| 202 | if (drip == nullptr) { | 233 | if (drip == nullptr) { |
| 203 | return; | 234 | return; |
| 204 | } | 235 | } |
| 205 | struct dirent* info = nullptr; | 236 | struct dirent* info = nullptr; |
| 206 | while ((info = readdir(drip)) != nullptr && pictureCount_ < MAX_PICTURE_COUNT) { | 237 | while ((info = readdir(drip)) != nullptr && pictureCount_ < MAX_PICTURE_COUNT) { |
| 238 | + LOGI("readdir for: %s", info->d_name); | ||
| 207 | uint16_t imageNameLen = static_cast<uint16_t>(strlen(info->d_name)); | 239 | uint16_t imageNameLen = static_cast<uint16_t>(strlen(info->d_name)); |
| 208 | if (imageNameLen > MAX_PATH_LENGTH || (strcmp(info->d_name, ".") == 0) || (strcmp(info->d_name, "..") == 0)) { | 240 | if (imageNameLen > MAX_PATH_LENGTH || (strcmp(info->d_name, ".") == 0) || (strcmp(info->d_name, "..") == 0)) { |
| 209 | - printf("GalleryAbilitySlice::AddAllPictures | imageNameLen > MAX_PATH_LENGTH | %d\n", imageNameLen); | 241 | + LOGW("GalleryAbilitySlice::AddAllPictures | imageNameLen > MAX_PATH_LENGTH | %d", imageNameLen); |
| 210 | continue; | 242 | continue; |
| 211 | } | 243 | } |
| 212 | char* imageName = new char[imageNameLen + 1](); | 244 | char* imageName = new char[imageNameLen + 1](); |
| @@ -214,62 +246,89 @@ void GalleryAbilitySlice::AddAllPictures(const Point& pos, int16_t numInLine) | |||
| 214 | pictureName_[pictureCount_] = imageName; | 246 | pictureName_[pictureCount_] = imageName; |
| 215 | pictureCount_++; | 247 | pictureCount_++; |
| 216 | 248 | ||
| 217 | - uint16_t pathLen = static_cast<uint16_t>(strlen(THUMBNAIL_DIRECTORY)) + imageNameLen + 1; | 249 | + uint16_t pathLen = static_cast<uint16_t>(strlen(directoryPath.c_str())) + imageNameLen + 1; |
| 218 | if (pathLen > MAX_PATH_LENGTH) { | 250 | if (pathLen > MAX_PATH_LENGTH) { |
| 219 | - printf("GalleryAbilitySlice::AddAllPictures | pathLen > MAX_PATH_LENGTH | %d\n", pathLen); | 251 | + LOGW("GalleryAbilitySlice::AddAllPictures | pathLen > MAX_PATH_LENGTH | %d", pathLen); |
| 220 | continue; | 252 | continue; |
| 221 | } | 253 | } |
| 222 | char* imagePath = new char[pathLen + 1](); | 254 | char* imagePath = new char[pathLen + 1](); |
| 223 | - if (sprintf_s(imagePath, pathLen + 1, "%s/%s", THUMBNAIL_DIRECTORY, info->d_name) < 0) { | 255 | + if (sprintf_s(imagePath, pathLen + 1, "%s/%s", directoryPath.c_str(), info->d_name) < 0) { |
| 224 | - printf("GalleryAbilitySlice::AddAllPictures | sprintf_s error\n"); | 256 | + LOGE("GalleryAbilitySlice::AddAllPictures | sprintf_s error"); |
| 225 | delete[] imagePath; | 257 | delete[] imagePath; |
| 226 | continue; | 258 | continue; |
| 227 | } | 259 | } |
| 228 | 260 | ||
| 261 | + LOGI("add image: pos:[%d, %d], name:%s, path:%s", imagePos.x, imagePos.y, imageName, imagePath); | ||
| 229 | picList_->Add(CreateImageItem(imagePos, imageName, imagePath)); | 262 | picList_->Add(CreateImageItem(imagePos, imageName, imagePath)); |
| 230 | delete[] imagePath; | 263 | delete[] imagePath; |
| 231 | 264 | ||
| 232 | if ((pictureCount_ % numInLine) == 0) { | 265 | if ((pictureCount_ % numInLine) == 0) { |
| 233 | imagePos.x = pos.x; | 266 | imagePos.x = pos.x; |
| 234 | - imagePos.y += THUMBNAIL_RESOLUTION_Y + THUMBNAIL_SPACE; | 267 | + imagePos.y += THUMBNAIL_RESOLUTION_Y() + THUMBNAIL_SPACE; |
| 235 | } else { | 268 | } else { |
| 236 | - imagePos.x += THUMBNAIL_RESOLUTION_X + THUMBNAIL_SPACE; | 269 | + imagePos.x += THUMBNAIL_RESOLUTION_X() + THUMBNAIL_SPACE; |
| 237 | } | 270 | } |
| 238 | } | 271 | } |
| 239 | delete info; | 272 | delete info; |
| 240 | closedir(drip); | 273 | closedir(drip); |
| 241 | } | 274 | } |
| 242 | 275 | ||
| 276 | +void GalleryAbilitySlice::AddVideoItemViews(UIViewGroup* imageItem, UIImageView* imageView, const char* imageName) | ||
| 277 | +{ | ||
| 278 | + UIImageView* videoTag = new UIImageView(); | ||
| 279 | + std::string videoTagFielPath = videoTagIconAbsolutePath; | ||
| 280 | + videoTag->SetPosition(VIDEO_TAG_POSITION_X(), VIDEO_TAG_POSITION_Y(), VIDEO_TAG_WIDTH(), VIDEO_TAG_HEIGHT()); | ||
| 281 | + videoTag->SetTouchable(true); | ||
| 282 | + videoTag->SetOnClickListener(imageView->GetOnClickListener()); | ||
| 283 | + imageDecoder_->DecodeImage(videoTagFielPath, [videoTag, videoTagFielPath](ImageInfo imageInfo) { | ||
| 284 | + LOGI("do SetSrc for img, filePath:%s, dataSize:%u", videoTagFielPath.c_str(), imageInfo.dataSize); | ||
| 285 | + videoTag->SetSrc(&imageInfo); | ||
| 286 | + }); | ||
| 287 | + | ||
| 288 | + UILabel* labelView = new UILabel(); | ||
| 289 | + labelView->SetPosition(0, 0, THUMBNAIL_RESOLUTION_X(), THUMBNAIL_RESOLUTION_Y()); | ||
| 290 | + labelView->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, | ||
| 291 | + UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); | ||
| 292 | + labelView->SetLineBreakMode(UILabel::LineBreakMode::LINE_BREAK_ELLIPSIS); | ||
| 293 | + labelView->SetFont(FONT_NAME, GALLERY_FONT_SIZE()); | ||
| 294 | + labelView->SetStyle(STYLE_TEXT_COLOR, Color::White().full); | ||
| 295 | + labelView->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); | ||
| 296 | + labelView->SetText(imageName); | ||
| 297 | + | ||
| 298 | + imageItem->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); | ||
| 299 | + imageItem->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); | ||
| 300 | + imageItem->Add(videoTag); | ||
| 301 | + imageItem->Add(labelView); | ||
| 302 | +} | ||
| 303 | + | ||
| 243 | UIView* GalleryAbilitySlice::CreateImageItem(const Point& pos, const char* imageName, const char* imagePath) | 304 | UIView* GalleryAbilitySlice::CreateImageItem(const Point& pos, const char* imageName, const char* imagePath) |
| 244 | { | 305 | { |
| 245 | UIImageView* imageView = new UIImageView(); | 306 | UIImageView* imageView = new UIImageView(); |
| 246 | imageView->SetAutoEnable(false); | 307 | imageView->SetAutoEnable(false); |
| 247 | - imageView->Resize(THUMBNAIL_RESOLUTION_X, THUMBNAIL_RESOLUTION_Y); | 308 | + imageView->Resize(THUMBNAIL_RESOLUTION_X(), THUMBNAIL_RESOLUTION_Y()); |
| 248 | - imageView->SetSrc(imagePath); | ||
| 249 | pictureOnClickListener_[pictureOnClickListenerCount_] = GetImageClickListener(imageName); | 309 | pictureOnClickListener_[pictureOnClickListenerCount_] = GetImageClickListener(imageName); |
| 250 | imageView->SetOnClickListener(pictureOnClickListener_[pictureOnClickListenerCount_++]); | 310 | imageView->SetOnClickListener(pictureOnClickListener_[pictureOnClickListenerCount_++]); |
| 251 | imageView->SetTouchable(true); | 311 | imageView->SetTouchable(true); |
| 252 | - | 312 | + imageView->SetResizeMode(UIImageView::FILL); |
| 253 | - if (strncmp(imageName, PHOTO_PREFIX, strlen(PHOTO_PREFIX)) == 0) { | ||
| 254 | - imageView->SetPosition(pos.x, pos.y); | ||
| 255 | - return imageView; | ||
| 256 | - } | ||
| 257 | imageView->SetPosition(0, 0); | 313 | imageView->SetPosition(0, 0); |
| 258 | 314 | ||
| 259 | UIViewGroup* imageItem = new UIViewGroup(); | 315 | UIViewGroup* imageItem = new UIViewGroup(); |
| 260 | imageItem->SetStyle(STYLE_BACKGROUND_OPA, 0); | 316 | imageItem->SetStyle(STYLE_BACKGROUND_OPA, 0); |
| 261 | - imageItem->SetPosition(pos.x, pos.y, THUMBNAIL_RESOLUTION_X, THUMBNAIL_RESOLUTION_Y); | 317 | + imageItem->SetPosition(pos.x, pos.y, THUMBNAIL_RESOLUTION_X(), THUMBNAIL_RESOLUTION_Y()); |
| 262 | imageItem->SetTouchable(true); | 318 | imageItem->SetTouchable(true); |
| 263 | imageItem->SetOnClickListener(imageView->GetOnClickListener()); | 319 | imageItem->SetOnClickListener(imageView->GetOnClickListener()); |
| 264 | - | ||
| 265 | - UIImageView* videoTag = new UIImageView(); | ||
| 266 | - videoTag->SetPosition(VIDEO_TAG_POSITION_X, VIDEO_TAG_POSITION_Y); | ||
| 267 | - videoTag->SetSrc(videoTagIconAbsolutePath); | ||
| 268 | - videoTag->SetTouchable(true); | ||
| 269 | - videoTag->SetOnClickListener(imageView->GetOnClickListener()); | ||
| 270 | - | ||
| 271 | imageItem->Add(imageView); | 320 | imageItem->Add(imageView); |
| 272 | - imageItem->Add(videoTag); | 321 | + |
| 322 | + std::string filePath(imagePath); | ||
| 323 | + if (filePath.find(AVAILABEL_SOURCE_TYPE) != std::string::npos || \ | ||
| 324 | + filePath.find(AVAILABEL_SOURCE_TYPE_MP4) != std::string::npos) { | ||
| 325 | + AddVideoItemViews(imageItem, imageView, imageName); | ||
| 326 | + } else { | ||
| 327 | + imageDecoder_->DecodeImage(filePath, [imageView, filePath](ImageInfo imageInfo) { | ||
| 328 | + LOGI("do SetSrc for img, filePath:%s, dataSize:%u", filePath.c_str(), imageInfo.dataSize); | ||
| 329 | + imageView->SetSrc(&imageInfo); | ||
| 330 | + }); | ||
| 331 | + } | ||
| 273 | 332 | ||
| 274 | return imageItem; | 333 | return imageItem; |
| 275 | } | 334 | } |
| @@ -277,28 +336,29 @@ UIView* GalleryAbilitySlice::CreateImageItem(const Point& pos, const char* image | |||
| 277 | EventListener* GalleryAbilitySlice::GetImageClickListener(const char* path) | 336 | EventListener* GalleryAbilitySlice::GetImageClickListener(const char* path) |
| 278 | { | 337 | { |
| 279 | auto onClick = [this, path] (UIView& view, const Event& event) -> bool { | 338 | auto onClick = [this, path] (UIView& view, const Event& event) -> bool { |
| 280 | - printf("############ Next AS enter #############\n"); | 339 | + LOGI("############ Next AS enter #############"); |
| 281 | Want wantData = { nullptr }; | 340 | Want wantData = { nullptr }; |
| 282 | - printf("------- imagePath: %s \n", path); | 341 | + LOGI("------- imagePath: %s ", path); |
| 283 | bool ret = SetWantData(&wantData, path, strlen(path) + 1); | 342 | bool ret = SetWantData(&wantData, path, strlen(path) + 1); |
| 284 | if (!ret) { | 343 | if (!ret) { |
| 285 | - printf("############ SetWantData error #############\n"); | 344 | + LOGE("############ SetWantData error #############"); |
| 286 | return ret; | 345 | return ret; |
| 287 | } | 346 | } |
| 288 | AbilitySlice* nextSlice = nullptr; | 347 | AbilitySlice* nextSlice = nullptr; |
| 289 | - if (strncmp(path, PHOTO_PREFIX, strlen(PHOTO_PREFIX)) == 0) { | 348 | + std::string filePath(path); |
| 290 | - printf("--------- enter PictureAbilitySlice \n"); | 349 | + if (filePath.find(AVAILABEL_SOURCE_TYPE) != std::string::npos) { |
| 291 | - nextSlice = AbilityLoader::GetInstance().GetAbilitySliceByName("PictureAbilitySlice"); | 350 | + LOGI("--------- enter PlayerAbilitySlice"); |
| 292 | - } else { | ||
| 293 | - printf("--------- enter PlayerAbilitySlice \n"); | ||
| 294 | nextSlice = AbilityLoader::GetInstance().GetAbilitySliceByName("PlayerAbilitySlice"); | 351 | nextSlice = AbilityLoader::GetInstance().GetAbilitySliceByName("PlayerAbilitySlice"); |
| 352 | + } else { | ||
| 353 | + LOGI("--------- enter PictureAbilitySlice"); | ||
| 354 | + nextSlice = AbilityLoader::GetInstance().GetAbilitySliceByName("PictureAbilitySlice"); | ||
| 295 | } | 355 | } |
| 296 | if (nextSlice == nullptr) { | 356 | if (nextSlice == nullptr) { |
| 297 | - printf("undefined nextSlice\n"); | 357 | + LOGW("undefined nextSlice"); |
| 298 | } else { | 358 | } else { |
| 299 | Present(*nextSlice, wantData); | 359 | Present(*nextSlice, wantData); |
| 300 | } | 360 | } |
| 301 | - printf("############ Next AS exit #############\n"); | 361 | + LOGI("############ Next AS exit #############"); |
| 302 | return true; | 362 | return true; |
| 303 | }; | 363 | }; |
| 304 | return new EventListener(onClick, nullptr); | 364 | return new EventListener(onClick, nullptr); |
| @@ -328,23 +388,23 @@ void GalleryAbilitySlice::DeleteAllFilesInDir(const char* path) | |||
| 328 | uint16_t fileNameLen = static_cast<uint16_t>(strlen(info->d_name)); | 388 | uint16_t fileNameLen = static_cast<uint16_t>(strlen(info->d_name)); |
| 329 | uint16_t pathLen = static_cast<uint16_t>(strlen(path)) + fileNameLen + 1; | 389 | uint16_t pathLen = static_cast<uint16_t>(strlen(path)) + fileNameLen + 1; |
| 330 | if (pathLen > MAX_PATH_LENGTH) { | 390 | if (pathLen > MAX_PATH_LENGTH) { |
| 331 | - printf("GalleryAbilitySlice::AddAllPictures | pathLen > MAX_PATH_LENGTH | %d\n", pathLen); | 391 | + LOGW("GalleryAbilitySlice::AddAllPictures | pathLen > MAX_PATH_LENGTH | %d", pathLen); |
| 332 | continue; | 392 | continue; |
| 333 | } | 393 | } |
| 334 | char* filePath = new char[pathLen + 1](); | 394 | char* filePath = new char[pathLen + 1](); |
| 335 | if (sprintf_s(filePath, pathLen + 1, "%s/%s", path, info->d_name) < 0) { | 395 | if (sprintf_s(filePath, pathLen + 1, "%s/%s", path, info->d_name) < 0) { |
| 336 | - printf("GalleryAbilitySlice::AddAllPictures | sprintf_s error\n"); | 396 | + LOGE("GalleryAbilitySlice::AddAllPictures | sprintf_s error"); |
| 337 | delete[] filePath; | 397 | delete[] filePath; |
| 338 | continue; | 398 | continue; |
| 339 | } | 399 | } |
| 340 | if (unlink(filePath) != 0) { | 400 | if (unlink(filePath) != 0) { |
| 341 | - printf("unlink file error | %s\n", filePath); | 401 | + LOGE("unlink file error | %s", filePath); |
| 342 | } | 402 | } |
| 343 | delete[] filePath; | 403 | delete[] filePath; |
| 344 | } | 404 | } |
| 345 | delete info; | 405 | delete info; |
| 346 | closedir(drip); | 406 | closedir(drip); |
| 347 | - printf("GalleryAbilitySlice::DeleteAllFilesInDir() | success | %s\n", path); | 407 | + LOGI("GalleryAbilitySlice::DeleteAllFilesInDir() | success | %s", path); |
| 348 | } | 408 | } |
| 349 | 409 | ||
| 350 | void GalleryAbilitySlice::OnStart(const Want &want) | 410 | void GalleryAbilitySlice::OnStart(const Want &want) |
| @@ -353,19 +413,21 @@ void GalleryAbilitySlice::OnStart(const Want &want) | |||
| 353 | 413 | ||
| 354 | rootView_ = RootView::GetWindowRootView(); | 414 | rootView_ = RootView::GetWindowRootView(); |
| 355 | rootView_->SetPosition(ROOT_VIEW_POSITION_X, ROOT_VIEW_POSITION_Y); | 415 | rootView_->SetPosition(ROOT_VIEW_POSITION_X, ROOT_VIEW_POSITION_Y); |
| 356 | - rootView_->Resize(ROOT_VIEW_WIDTH, ROOT_VIEW_HEIGHT); | 416 | + rootView_->Resize(ROOT_VIEW_WIDTH(), ROOT_VIEW_HEIGHT()); |
| 357 | - rootView_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); | 417 | + rootView_->SetStyle(STYLE_BACKGROUND_COLOR, Color::White().full); |
| 358 | 418 | ||
| 359 | const char* pathHeader = GetSrcPath(); | 419 | const char* pathHeader = GetSrcPath(); |
| 360 | if (sprintf_s(backIconAbsolutePath, MAX_PATH_LENGTH, "%s%s", pathHeader, BACK_ICON_PATH) < 0) { | 420 | if (sprintf_s(backIconAbsolutePath, MAX_PATH_LENGTH, "%s%s", pathHeader, BACK_ICON_PATH) < 0) { |
| 361 | - printf("GalleryAbilitySlice::OnStart | backIconAbsolutePath error"); | 421 | + LOGE("GalleryAbilitySlice::OnStart | backIconAbsolutePath error"); |
| 362 | return; | 422 | return; |
| 363 | } | 423 | } |
| 364 | if (sprintf_s(videoTagIconAbsolutePath, MAX_PATH_LENGTH, "%s%s", pathHeader, VIDEO_TAG_ICON_PATH) < 0) { | 424 | if (sprintf_s(videoTagIconAbsolutePath, MAX_PATH_LENGTH, "%s%s", pathHeader, VIDEO_TAG_ICON_PATH) < 0) { |
| 365 | - printf("GalleryAbilitySlice::OnStart | videoTagIconAbsolutePath error"); | 425 | + LOGE("GalleryAbilitySlice::OnStart | videoTagIconAbsolutePath error"); |
| 366 | return; | 426 | return; |
| 367 | } | 427 | } |
| 368 | 428 | ||
| 429 | + imageDecoder_ = new ImageDecoder(AbilityEventHandler::GetCurrentHandler(), 1); | ||
| 430 | + | ||
| 369 | InitTitle(); | 431 | InitTitle(); |
| 370 | InitPictureList(); | 432 | InitPictureList(); |
| 371 | SetUIContent(rootView_); | 433 | SetUIContent(rootView_); |
| @@ -373,25 +435,28 @@ void GalleryAbilitySlice::OnStart(const Want &want) | |||
| 373 | 435 | ||
| 374 | void GalleryAbilitySlice::OnInactive() | 436 | void GalleryAbilitySlice::OnInactive() |
| 375 | { | 437 | { |
| 376 | - printf("GalleryAbilitySlice::OnInactive\n"); | 438 | + LOGI("GalleryAbilitySlice::OnInactive"); |
| 377 | AbilitySlice::OnInactive(); | 439 | AbilitySlice::OnInactive(); |
| 378 | } | 440 | } |
| 379 | 441 | ||
| 380 | void GalleryAbilitySlice::OnActive(const Want &want) | 442 | void GalleryAbilitySlice::OnActive(const Want &want) |
| 381 | { | 443 | { |
| 382 | - printf("GalleryAbilitySlice::OnActive\n"); | 444 | + LOGI("GalleryAbilitySlice::OnActive"); |
| 383 | AbilitySlice::OnActive(want); | 445 | AbilitySlice::OnActive(want); |
| 446 | + if (!imageDecoder_->IsRunning()) { | ||
| 447 | + imageDecoder_->Start(); | ||
| 448 | + } | ||
| 384 | } | 449 | } |
| 385 | 450 | ||
| 386 | void GalleryAbilitySlice::OnBackground() | 451 | void GalleryAbilitySlice::OnBackground() |
| 387 | { | 452 | { |
| 388 | - printf("GalleryAbilitySlice::OnBackground\n"); | 453 | + LOGI("GalleryAbilitySlice::OnBackground"); |
| 389 | AbilitySlice::OnBackground(); | 454 | AbilitySlice::OnBackground(); |
| 390 | } | 455 | } |
| 391 | 456 | ||
| 392 | void GalleryAbilitySlice::OnStop() | 457 | void GalleryAbilitySlice::OnStop() |
| 393 | { | 458 | { |
| 394 | - printf("GalleryAbilitySlice::OnStop\n"); | 459 | + LOGI("GalleryAbilitySlice::OnStop"); |
| 395 | AbilitySlice::OnStop(); | 460 | AbilitySlice::OnStop(); |
| 396 | Clear(); | 461 | Clear(); |
| 397 | } | 462 | } |
| @@ -0,0 +1,230 @@ | |||
| 1 | +/* | ||
| 2 | + * Copyright (c) 2026 RKH Corp. | ||
| 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 | + */ | ||
| 15 | + | ||
| 16 | +#include <chrono> | ||
| 17 | +#include <iostream> | ||
| 18 | +#include <sstream> | ||
| 19 | + | ||
| 20 | +#include <ability_event_handler.h> | ||
| 21 | +#include <gfx_utils/file.h> | ||
| 22 | + | ||
| 23 | +#if ENABLE_JPEG | ||
| 24 | +#include "jpeglib.h" | ||
| 25 | +#endif | ||
| 26 | +#if ENABLE_PNG | ||
| 27 | +#include "png.h" | ||
| 28 | +#endif | ||
| 29 | +#include <imgdecode/file_img_decoder.h> | ||
| 30 | +#include <imgdecode/jpeg_img_decoder.h> | ||
| 31 | +#include <imgdecode/png_img_decoder.h> | ||
| 32 | + | ||
| 33 | +#include "image_decoder.h" | ||
| 34 | +#include "gallery_log.h" | ||
| 35 | + | ||
| 36 | +namespace OHOS { | ||
| 37 | + | ||
| 38 | +enum GalleryImageType { | ||
| 39 | + IMG_PNG, | ||
| 40 | + IMG_JPEG, | ||
| 41 | + IMG_GIF, | ||
| 42 | + IMG_UNKNOWN, | ||
| 43 | +}; | ||
| 44 | +const static uint8_t IMG_BYTES_TO_CHECK = 4; // 4: check 4 bytes of image file | ||
| 45 | + | ||
| 46 | +GalleryImageType CheckImgType(const char* src) | ||
| 47 | +{ | ||
| 48 | + char buf[IMG_BYTES_TO_CHECK] = {0}; | ||
| 49 | +#ifdef _WIN32 | ||
| 50 | + int32_t fd = open(src, O_RDONLY | O_BINARY); | ||
| 51 | +#else | ||
| 52 | + int32_t fd = open(src, O_RDONLY); | ||
| 53 | +#endif | ||
| 54 | + if (fd < 0) { | ||
| 55 | + LOGE("can't open %s\n", src); | ||
| 56 | + return IMG_UNKNOWN; | ||
| 57 | + } | ||
| 58 | + if (read(fd, buf, IMG_BYTES_TO_CHECK) != IMG_BYTES_TO_CHECK) { | ||
| 59 | + close(fd); | ||
| 60 | + return IMG_UNKNOWN; | ||
| 61 | + } | ||
| 62 | + close(fd); | ||
| 63 | +#if ENABLE_PNG | ||
| 64 | + if (!png_sig_cmp(reinterpret_cast<png_const_bytep>(buf), 0, IMG_BYTES_TO_CHECK)) { | ||
| 65 | + return IMG_PNG; | ||
| 66 | + } | ||
| 67 | +#endif | ||
| 68 | +#if ENABLE_JPEG | ||
| 69 | + // 0xFF 0xD8: JPEG file's header | ||
| 70 | + if ((static_cast<uint8_t>(buf[0]) == 0xFF) && (static_cast<uint8_t>(buf[1]) == 0xD8)) { | ||
| 71 | + return IMG_JPEG; | ||
| 72 | + } | ||
| 73 | +#endif | ||
| 74 | + if ((static_cast<uint8_t>(buf[0]) == 0x47) && (static_cast<uint8_t>(buf[1]) == 0x49) && | ||
| 75 | + (static_cast<uint8_t>(buf[2]) == 0x46)) { // 2: array index of GIF file's header | ||
| 76 | + return IMG_GIF; | ||
| 77 | + } | ||
| 78 | + return IMG_UNKNOWN; | ||
| 79 | +} | ||
| 80 | + | ||
| 81 | +ImageDecoder::ImageDecoder(AbilityEventHandler* handler, size_t threadCount) : isRunning_(false), | ||
| 82 | + maxThreadCount_(threadCount), | ||
| 83 | + eventHandler_(handler) | ||
| 84 | +{ | ||
| 85 | +} | ||
| 86 | + | ||
| 87 | +ImageDecoder::~ImageDecoder() | ||
| 88 | +{ | ||
| 89 | + Stop(); | ||
| 90 | +} | ||
| 91 | + | ||
| 92 | +void ImageDecoder::DecodeImage(const std::string& imagePath, std::function<void(ImageInfo)> uiCallback) | ||
| 93 | +{ | ||
| 94 | + std::lock_guard<std::mutex> lock(queueMutex_); | ||
| 95 | + taskQueue_.push({imagePath, uiCallback}); | ||
| 96 | + taskCond_.notify_one(); | ||
| 97 | +} | ||
| 98 | + | ||
| 99 | +void ImageDecoder::Start() | ||
| 100 | +{ | ||
| 101 | + isRunning_ = true; | ||
| 102 | + for (size_t i = 0; i < maxThreadCount_; ++i) { | ||
| 103 | + workerThreads_.emplace_back(&ImageDecoder::WorkerThread, this); | ||
| 104 | + } | ||
| 105 | +} | ||
| 106 | + | ||
| 107 | +void ImageDecoder::Stop() | ||
| 108 | +{ | ||
| 109 | + if (!isRunning_) return; | ||
| 110 | + | ||
| 111 | + isRunning_ = false; | ||
| 112 | + taskCond_.notify_all(); | ||
| 113 | + | ||
| 114 | + for (auto& thread : workerThreads_) { | ||
| 115 | + if (thread.joinable()) { | ||
| 116 | + thread.join(); | ||
| 117 | + } | ||
| 118 | + } | ||
| 119 | + workerThreads_.clear(); | ||
| 120 | +} | ||
| 121 | + | ||
| 122 | +bool ImageDecoder::IsRunning() | ||
| 123 | +{ | ||
| 124 | + return isRunning_; | ||
| 125 | +} | ||
| 126 | + | ||
| 127 | +bool ImageDecoder::TryGetTask(DecodeTask& task) | ||
| 128 | +{ | ||
| 129 | + std::unique_lock<std::mutex> lock(queueMutex_); | ||
| 130 | + taskCond_.wait(lock, [this]() { | ||
| 131 | + return !isRunning_ || !taskQueue_.empty(); | ||
| 132 | + }); | ||
| 133 | + | ||
| 134 | + if (isRunning_ && !taskQueue_.empty()) { | ||
| 135 | + task = std::move(taskQueue_.front()); | ||
| 136 | + taskQueue_.pop(); | ||
| 137 | + return true; | ||
| 138 | + } | ||
| 139 | + return false; | ||
| 140 | +} | ||
| 141 | + | ||
| 142 | +void ImageDecoder::HandleTask(const DecodeTask& task) | ||
| 143 | +{ | ||
| 144 | + if (!isRunning_) { | ||
| 145 | + return; | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + ImageInfo imageInfo = DoDecode(task.imagePath); | ||
| 149 | + NotifyCallback(task, imageInfo); | ||
| 150 | +} | ||
| 151 | + | ||
| 152 | +void ImageDecoder::NotifyCallback(const DecodeTask& task, const ImageInfo& imageInfo) | ||
| 153 | +{ | ||
| 154 | + if (eventHandler_) { | ||
| 155 | + eventHandler_->PostTask([task, imageInfo]() { | ||
| 156 | + task.callback(imageInfo); | ||
| 157 | + }); | ||
| 158 | + } | ||
| 159 | +} | ||
| 160 | + | ||
| 161 | +void ImageDecoder::WorkerThread() | ||
| 162 | +{ | ||
| 163 | +#ifndef __LITEOS_A__ | ||
| 164 | + pid_t tid = gettid(); | ||
| 165 | + LOGI("WorkerThread started, tid:%d", tid); | ||
| 166 | +#endif | ||
| 167 | + while (isRunning_) { | ||
| 168 | + DecodeTask task; | ||
| 169 | + bool hasTask = TryGetTask(task); | ||
| 170 | + if (hasTask) { | ||
| 171 | + HandleTask(task); | ||
| 172 | + } | ||
| 173 | + } | ||
| 174 | +#ifndef __LITEOS_A__ | ||
| 175 | + LOGI("WorkerThread exit, tid: %d", tid); | ||
| 176 | +#endif | ||
| 177 | +} | ||
| 178 | + | ||
| 179 | +ImageInfo ImageDecoder::DoDecode(const std::string& imagePath) | ||
| 180 | +{ | ||
| 181 | +#ifndef __LITEOS_A__ | ||
| 182 | + pid_t tid = gettid(); | ||
| 183 | + LOGI("DoDecode start. path: %s (tid:%d)", imagePath.c_str(), tid); | ||
| 184 | +#endif | ||
| 185 | + FileImgDecoder::ImgResDsc desc = {0}; | ||
| 186 | + FileImgDecoder* decoder = nullptr; | ||
| 187 | + GalleryImageType type = CheckImgType(imagePath.c_str()); | ||
| 188 | + if (type == IMG_PNG) { | ||
| 189 | + decoder = &(PngImgDecoder::GetInstance()); | ||
| 190 | + } else if (type == IMG_JPEG) { | ||
| 191 | + decoder = &(JpegImgDecoder::GetInstance()); | ||
| 192 | + } else { | ||
| 193 | + LOGE("DoDecode imageType(%d) not supported!", type); | ||
| 194 | + return desc.imgInfo; | ||
| 195 | + } | ||
| 196 | + | ||
| 197 | + if (decoder == nullptr) { | ||
| 198 | + LOGE("DoDecode decoder is null"); | ||
| 199 | + return desc.imgInfo; | ||
| 200 | + } | ||
| 201 | + | ||
| 202 | + desc.path = imagePath.c_str(); | ||
| 203 | + RetCode ret = decoder->Open(desc); | ||
| 204 | + if (ret != RetCode::OK) { | ||
| 205 | + LOGE("DoDecode decoder open failed"); | ||
| 206 | + return desc.imgInfo; | ||
| 207 | + } | ||
| 208 | + | ||
| 209 | + ret = decoder->GetHeader(desc); | ||
| 210 | + if (ret != RetCode::OK) { | ||
| 211 | + LOGE("DoDecode decoder get header failed"); | ||
| 212 | + decoder->Close(desc); | ||
| 213 | + return desc.imgInfo; | ||
| 214 | + } | ||
| 215 | + | ||
| 216 | + ret = decoder->ReadToCache(desc); | ||
| 217 | + if (ret != RetCode::OK) { | ||
| 218 | + LOGE("DoDecode decoder read to cache failed"); | ||
| 219 | + decoder->Close(desc); | ||
| 220 | + return desc.imgInfo; | ||
| 221 | + } | ||
| 222 | + | ||
| 223 | +#ifndef __LITEOS_A__ | ||
| 224 | + LOGI("DoDecode end. path: %s (tid:%d) result:%d, imageInfo.data:%p", imagePath.c_str(), | ||
| 225 | + tid, ret, desc.imgInfo.data); | ||
| 226 | +#endif | ||
| 227 | + return desc.imgInfo; | ||
| 228 | +} | ||
| 229 | +} | ||
| 230 | + | ||
| @@ -18,6 +18,7 @@ | |||
| 18 | #include "gallery_config.h" | 18 | #include "gallery_config.h" |
| 19 | #include "gfx_utils/file.h" | 19 | #include "gfx_utils/file.h" |
| 20 | #include "securec.h" | 20 | #include "securec.h" |
| 21 | +#include "gallery_log.h" | ||
| 21 | 22 | ||
| 22 | namespace OHOS { | 23 | namespace OHOS { |
| 23 | REGISTER_AS(PictureAbilitySlice) | 24 | REGISTER_AS(PictureAbilitySlice) |
| @@ -29,7 +30,7 @@ PictureAbilitySlice::~PictureAbilitySlice() | |||
| 29 | 30 | ||
| 30 | void PictureAbilitySlice::Clear() | 31 | void PictureAbilitySlice::Clear() |
| 31 | { | 32 | { |
| 32 | - printf("PictureAbilitySlice::Clear() | start \n"); | 33 | + LOGI("PictureAbilitySlice::Clear() | start"); |
| 33 | if (backIcon_ != nullptr) { | 34 | if (backIcon_ != nullptr) { |
| 34 | delete backIcon_; | 35 | delete backIcon_; |
| 35 | backIcon_ = nullptr; | 36 | backIcon_ = nullptr; |
| @@ -50,66 +51,78 @@ void PictureAbilitySlice::Clear() | |||
| 50 | RootView::DestroyWindowRootView(rootView_); | 51 | RootView::DestroyWindowRootView(rootView_); |
| 51 | rootView_ = nullptr; | 52 | rootView_ = nullptr; |
| 52 | } | 53 | } |
| 53 | - printf("PictureAbilitySlice::Clear() | end \n"); | 54 | + LOGI("PictureAbilitySlice::Clear() | end"); |
| 54 | } | 55 | } |
| 55 | 56 | ||
| 56 | -void PictureAbilitySlice::InitTitle() | 57 | +void PictureAbilitySlice::InitTitle(const char* imageName) |
| 57 | { | 58 | { |
| 58 | - printf("PictureAbilitySlice::InitTitle | start \n"); | 59 | + LOGI("PictureAbilitySlice::InitTitle | start"); |
| 59 | backIcon_ = new UIImageView(); | 60 | backIcon_ = new UIImageView(); |
| 60 | - backIcon_->SetPosition(BACK_ICON_POSITION_X, BACK_ICON_POSITION_Y); | 61 | + backIcon_->SetAutoEnable(false); |
| 62 | + backIcon_->SetResizeMode(UIImageView::ImageResizeMode::CONTAIN); | ||
| 63 | + backIcon_->SetPosition(BACK_ICON_POSITION_X(), BACK_ICON_POSITION_Y(), BACK_ICON_WIDTH(), BACK_ICON_HEIGHT()); | ||
| 61 | backIcon_->SetSrc(backIconAbsolutePath); | 64 | backIcon_->SetSrc(backIconAbsolutePath); |
| 62 | backIcon_->SetTouchable(true); | 65 | backIcon_->SetTouchable(true); |
| 63 | 66 | ||
| 64 | backArea_ = new UIViewGroup(); | 67 | backArea_ = new UIViewGroup(); |
| 65 | - backArea_->SetPosition(0, 0, LABEL_POSITION_X, LABEL_HEIGHT); | 68 | + backArea_->SetPosition(0, 0, LABEL_POSITION_X(), LABEL_HEIGHT()); |
| 66 | backArea_->SetStyle(STYLE_BACKGROUND_OPA, 0); | 69 | backArea_->SetStyle(STYLE_BACKGROUND_OPA, 0); |
| 67 | backArea_->SetTouchable(true); | 70 | backArea_->SetTouchable(true); |
| 68 | 71 | ||
| 69 | auto onClick = [this] (UIView &view, const Event &event) -> bool { | 72 | auto onClick = [this] (UIView &view, const Event &event) -> bool { |
| 70 | - printf("############ terminate AS enter #############\n"); | 73 | + LOGI("############ terminate AS enter #############\n"); |
| 71 | Terminate(); | 74 | Terminate(); |
| 72 | - printf("############ terminate AS exit #############\n"); | 75 | + LOGI("############ terminate AS exit #############\n"); |
| 73 | return true; | 76 | return true; |
| 74 | }; | 77 | }; |
| 75 | backIconListener_ = new EventListener(onClick, nullptr); | 78 | backIconListener_ = new EventListener(onClick, nullptr); |
| 76 | backIcon_->SetOnClickListener(backIconListener_); | 79 | backIcon_->SetOnClickListener(backIconListener_); |
| 77 | backArea_->SetOnClickListener(backIconListener_); | 80 | backArea_->SetOnClickListener(backIconListener_); |
| 78 | 81 | ||
| 82 | + titleLabel_ = new UILabel(); | ||
| 83 | + titleLabel_->SetPosition(LABEL_POSITION_X(), LABEL_POSITION_Y, LABEL_WIDTH(), LABEL_HEIGHT()); | ||
| 84 | + titleLabel_->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_LEFT, UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); | ||
| 85 | + titleLabel_->SetFont(FONT_NAME, GALLERY_FONT_SIZE()); | ||
| 86 | + titleLabel_->SetStyle(STYLE_TEXT_COLOR, Color::Black().full); | ||
| 87 | + titleLabel_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); | ||
| 88 | + titleLabel_->SetText(imageName); | ||
| 89 | + | ||
| 79 | backArea_->Add(backIcon_); | 90 | backArea_->Add(backIcon_); |
| 80 | rootView_->Add(backArea_); | 91 | rootView_->Add(backArea_); |
| 92 | + rootView_->Add(titleLabel_); | ||
| 81 | } | 93 | } |
| 82 | 94 | ||
| 83 | void PictureAbilitySlice::InitPicture(const char* path) | 95 | void PictureAbilitySlice::InitPicture(const char* path) |
| 84 | { | 96 | { |
| 85 | - printf("PictureAbilitySlice::InitPicture | start | %s\n", path); | 97 | + LOGI("PictureAbilitySlice::InitPicture | start | %s\n", path); |
| 86 | picture_ = new UIImageView(); | 98 | picture_ = new UIImageView(); |
| 87 | picture_->SetSrc(path); | 99 | picture_->SetSrc(path); |
| 88 | int16_t imageWidth = picture_->GetWidth(); | 100 | int16_t imageWidth = picture_->GetWidth(); |
| 89 | int16_t imageHeight = picture_->GetHeight(); | 101 | int16_t imageHeight = picture_->GetHeight(); |
| 90 | - if (imageWidth > ROOT_VIEW_WIDTH || imageHeight > ROOT_VIEW_HEIGHT) { | 102 | + LOGI("imageWidth:%d, imageHeight:%d", imageWidth, imageHeight); |
| 103 | + if (imageWidth > ROOT_VIEW_WIDTH() || imageHeight > ROOT_VIEW_HEIGHT()) { | ||
| 91 | TransformMap transMap(picture_->GetOrigRect()); | 104 | TransformMap transMap(picture_->GetOrigRect()); |
| 92 | float scaleWidth = 1.0; | 105 | float scaleWidth = 1.0; |
| 93 | float scaleHeight = 1.0; | 106 | float scaleHeight = 1.0; |
| 94 | - if (imageWidth > ROOT_VIEW_WIDTH) { | 107 | + if (imageWidth > ROOT_VIEW_WIDTH()) { |
| 95 | - scaleWidth = static_cast<float>(ROOT_VIEW_WIDTH) / imageWidth; | 108 | + scaleWidth = static_cast<float>(ROOT_VIEW_WIDTH()) / imageWidth; |
| 96 | - printf("########## scaleWidth: %f \n", scaleWidth); | 109 | + LOGI("########## scaleWidth: %f", scaleWidth); |
| 97 | } | 110 | } |
| 98 | - if (imageHeight > ROOT_VIEW_HEIGHT) { | 111 | + if (imageHeight > ROOT_VIEW_HEIGHT()) { |
| 99 | - scaleHeight = static_cast<float>(ROOT_VIEW_HEIGHT) / imageHeight; | 112 | + scaleHeight = static_cast<float>(ROOT_VIEW_HEIGHT()) / imageHeight; |
| 100 | - printf("########## scaleHeight: %f \n", scaleHeight); | 113 | + LOGI("########## scaleHeight: %f", scaleHeight); |
| 101 | } | 114 | } |
| 102 | float scale = (scaleWidth < scaleHeight) ? scaleWidth : scaleHeight; | 115 | float scale = (scaleWidth < scaleHeight) ? scaleWidth : scaleHeight; |
| 103 | - printf("########## scale: %f \n", scale); | 116 | + LOGI("########## scale: %f", scale); |
| 104 | transMap.Scale(Vector2<float>(scale, scale), Vector2<float>(0, 0)); | 117 | transMap.Scale(Vector2<float>(scale, scale), Vector2<float>(0, 0)); |
| 105 | picture_->SetTransformMap(transMap); | 118 | picture_->SetTransformMap(transMap); |
| 106 | picture_->SetTransformAlgorithm(TransformAlgorithm::NEAREST_NEIGHBOR); | 119 | picture_->SetTransformAlgorithm(TransformAlgorithm::NEAREST_NEIGHBOR); |
| 107 | imageWidth = imageWidth * scale; | 120 | imageWidth = imageWidth * scale; |
| 108 | imageHeight = imageHeight * scale; | 121 | imageHeight = imageHeight * scale; |
| 109 | } | 122 | } |
| 110 | - int16_t imagePosX = (ROOT_VIEW_WIDTH - imageWidth) / 2; // 2: half | 123 | + int16_t imagePosX = (ROOT_VIEW_WIDTH() - imageWidth) / 2; // 2: half |
| 111 | - int16_t imagePosY = (ROOT_VIEW_HEIGHT - imageHeight) / 2; // 2: half | 124 | + int16_t imagePosY = (ROOT_VIEW_HEIGHT() - imageHeight) / 2; // 2: half |
| 112 | - printf("########## image pos x: %d | y: %d \n", imagePosX, imagePosY); | 125 | + LOGI("########## image pos x: %d | y: %d", imagePosX, imagePosY); |
| 113 | picture_->SetPosition(imagePosX, imagePosY); | 126 | picture_->SetPosition(imagePosX, imagePosY); |
| 114 | 127 | ||
| 115 | rootView_->Add(picture_); | 128 | rootView_->Add(picture_); |
| @@ -117,23 +130,23 @@ void PictureAbilitySlice::InitPicture(const char* path) | |||
| 117 | 130 | ||
| 118 | void PictureAbilitySlice::OnStart(const Want &want) | 131 | void PictureAbilitySlice::OnStart(const Want &want) |
| 119 | { | 132 | { |
| 120 | - printf("######### PictureAbilitySlice::OnStart\n"); | 133 | + LOGI("######### PictureAbilitySlice::OnStart\n"); |
| 121 | - printf("receive the data -> %s\n", reinterpret_cast<char*>(want.data)); | 134 | + LOGI("receive the data -> %s\n", reinterpret_cast<char*>(want.data)); |
| 122 | AbilitySlice::OnStart(want); | 135 | AbilitySlice::OnStart(want); |
| 123 | 136 | ||
| 124 | rootView_ = RootView::GetWindowRootView(); | 137 | rootView_ = RootView::GetWindowRootView(); |
| 125 | rootView_->SetPosition(ROOT_VIEW_POSITION_X, ROOT_VIEW_POSITION_Y); | 138 | rootView_->SetPosition(ROOT_VIEW_POSITION_X, ROOT_VIEW_POSITION_Y); |
| 126 | - rootView_->Resize(ROOT_VIEW_WIDTH, ROOT_VIEW_HEIGHT); | 139 | + rootView_->Resize(ROOT_VIEW_WIDTH(), ROOT_VIEW_HEIGHT()); |
| 127 | - rootView_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); | 140 | + rootView_->SetStyle(STYLE_BACKGROUND_COLOR, Color::White().full); |
| 128 | 141 | ||
| 129 | uint16_t imagePathLen = strlen(PHOTO_DIRECTORY) + strlen(reinterpret_cast<char*>(want.data)) + 1; | 142 | uint16_t imagePathLen = strlen(PHOTO_DIRECTORY) + strlen(reinterpret_cast<char*>(want.data)) + 1; |
| 130 | if (imagePathLen > MAX_PATH_LENGTH) { | 143 | if (imagePathLen > MAX_PATH_LENGTH) { |
| 131 | - printf("---- imagePathLen > MAX_PATH_LENGTH | %d", imagePathLen); | 144 | + LOGI("---- imagePathLen > MAX_PATH_LENGTH | %d", imagePathLen); |
| 132 | return; | 145 | return; |
| 133 | } | 146 | } |
| 134 | char* imagePath = new char[imagePathLen + 1](); | 147 | char* imagePath = new char[imagePathLen + 1](); |
| 135 | if (sprintf_s(imagePath, imagePathLen + 1, "%s/%s", PHOTO_DIRECTORY, reinterpret_cast<char*>(want.data)) < 0) { | 148 | if (sprintf_s(imagePath, imagePathLen + 1, "%s/%s", PHOTO_DIRECTORY, reinterpret_cast<char*>(want.data)) < 0) { |
| 136 | - printf("PictureAbilitySlice::OnStart | imagePath\n"); | 149 | + LOGE("PictureAbilitySlice::OnStart | imagePath\n"); |
| 137 | delete[] imagePath; | 150 | delete[] imagePath; |
| 138 | imagePath = nullptr; | 151 | imagePath = nullptr; |
| 139 | return; | 152 | return; |
| @@ -141,14 +154,14 @@ void PictureAbilitySlice::OnStart(const Want &want) | |||
| 141 | 154 | ||
| 142 | const char* pathHeader = GetSrcPath(); | 155 | const char* pathHeader = GetSrcPath(); |
| 143 | if (sprintf_s(backIconAbsolutePath, MAX_PATH_LENGTH, "%s%s", pathHeader, BACK_ICON_PATH) < 0) { | 156 | if (sprintf_s(backIconAbsolutePath, MAX_PATH_LENGTH, "%s%s", pathHeader, BACK_ICON_PATH) < 0) { |
| 144 | - printf("PictureAbilitySlice::OnStart | backIconAbsolutePath\n"); | 157 | + LOGE("PictureAbilitySlice::OnStart | backIconAbsolutePath\n"); |
| 145 | delete[] imagePath; | 158 | delete[] imagePath; |
| 146 | imagePath = nullptr; | 159 | imagePath = nullptr; |
| 147 | return; | 160 | return; |
| 148 | } | 161 | } |
| 149 | 162 | ||
| 150 | InitPicture(imagePath); | 163 | InitPicture(imagePath); |
| 151 | - InitTitle(); | 164 | + InitTitle(reinterpret_cast<char*>(want.data)); |
| 152 | delete[] imagePath; | 165 | delete[] imagePath; |
| 153 | 166 | ||
| 154 | SetUIContent(rootView_); | 167 | SetUIContent(rootView_); |
| @@ -156,25 +169,25 @@ void PictureAbilitySlice::OnStart(const Want &want) | |||
| 156 | 169 | ||
| 157 | void PictureAbilitySlice::OnInactive() | 170 | void PictureAbilitySlice::OnInactive() |
| 158 | { | 171 | { |
| 159 | - printf("PictureAbilitySlice::OnInactive\n"); | 172 | + LOGI("PictureAbilitySlice::OnInactive\n"); |
| 160 | AbilitySlice::OnInactive(); | 173 | AbilitySlice::OnInactive(); |
| 161 | } | 174 | } |
| 162 | 175 | ||
| 163 | void PictureAbilitySlice::OnActive(const Want &want) | 176 | void PictureAbilitySlice::OnActive(const Want &want) |
| 164 | { | 177 | { |
| 165 | - printf("PictureAbilitySlice::OnActive\n"); | 178 | + LOGI("PictureAbilitySlice::OnActive\n"); |
| 166 | AbilitySlice::OnActive(want); | 179 | AbilitySlice::OnActive(want); |
| 167 | } | 180 | } |
| 168 | 181 | ||
| 169 | void PictureAbilitySlice::OnBackground() | 182 | void PictureAbilitySlice::OnBackground() |
| 170 | { | 183 | { |
| 171 | - printf("PictureAbilitySlice::OnBackground\n"); | 184 | + LOGI("PictureAbilitySlice::OnBackground\n"); |
| 172 | AbilitySlice::OnBackground(); | 185 | AbilitySlice::OnBackground(); |
| 173 | } | 186 | } |
| 174 | 187 | ||
| 175 | void PictureAbilitySlice::OnStop() | 188 | void PictureAbilitySlice::OnStop() |
| 176 | { | 189 | { |
| 177 | - printf("PictureAbilitySlice::OnStop\n"); | 190 | + LOGI("PictureAbilitySlice::OnStop\n"); |
| 178 | AbilitySlice::OnStop(); | 191 | AbilitySlice::OnStop(); |
| 179 | Clear(); | 192 | Clear(); |
| 180 | } | 193 | } |
| @@ -21,6 +21,7 @@ | |||
| 21 | #include "ability_manager.h" | 21 | #include "ability_manager.h" |
| 22 | #include "components/ui_image_view.h" | 22 | #include "components/ui_image_view.h" |
| 23 | #include "gfx_utils/file.h" | 23 | #include "gfx_utils/file.h" |
| 24 | +#include "gallery_log.h" | ||
| 24 | 25 | ||
| 25 | using OHOS::Media::Player; | 26 | using OHOS::Media::Player; |
| 26 | using OHOS::Media::Source; | 27 | using OHOS::Media::Source; |
| @@ -32,11 +33,11 @@ REGISTER_AS(PlayerAbilitySlice) | |||
| 32 | 33 | ||
| 33 | PlayerAbilitySlice::~PlayerAbilitySlice() | 34 | PlayerAbilitySlice::~PlayerAbilitySlice() |
| 34 | { | 35 | { |
| 35 | - printf("################ ~PlayerAbilitySlice enter\n"); | 36 | + LOGI("################ ~PlayerAbilitySlice enter"); |
| 36 | 37 | ||
| 37 | /** released in DestoryPlayer(). */ | 38 | /** released in DestoryPlayer(). */ |
| 38 | 39 | ||
| 39 | - printf("################ ~PlayerAbilitySlice exit\n"); | 40 | + LOGI("################ ~PlayerAbilitySlice exit"); |
| 40 | } | 41 | } |
| 41 | 42 | ||
| 42 | std::shared_ptr<Player> PlayerAbilitySlice::CreatePlayer() | 43 | std::shared_ptr<Player> PlayerAbilitySlice::CreatePlayer() |
| @@ -50,7 +51,7 @@ std::shared_ptr<Player> PlayerAbilitySlice::CreatePlayer() | |||
| 50 | 51 | ||
| 51 | void PlayerAbilitySlice::Clear() | 52 | void PlayerAbilitySlice::Clear() |
| 52 | { | 53 | { |
| 53 | - printf("PlayerAbilitySlice::Clear | enter\n"); | 54 | + LOGI("PlayerAbilitySlice::Clear | enter"); |
| 54 | if (backIconListener_ != nullptr) { | 55 | if (backIconListener_ != nullptr) { |
| 55 | delete backIconListener_; | 56 | delete backIconListener_; |
| 56 | backIconListener_ = nullptr; | 57 | backIconListener_ = nullptr; |
| @@ -103,21 +104,22 @@ void PlayerAbilitySlice::Clear() | |||
| 103 | RootView::DestroyWindowRootView(rootView_); | 104 | RootView::DestroyWindowRootView(rootView_); |
| 104 | rootView_ = nullptr; | 105 | rootView_ = nullptr; |
| 105 | } | 106 | } |
| 106 | - printf("PlayerAbilitySlice::Clear() | end\n"); | 107 | + LOGI("PlayerAbilitySlice::Clear() | end"); |
| 107 | } | 108 | } |
| 108 | 109 | ||
| 109 | void PlayerAbilitySlice::ShowErrorTips() | 110 | void PlayerAbilitySlice::ShowErrorTips() |
| 110 | { | 111 | { |
| 111 | errorTips_ = new UILabel(); | 112 | errorTips_ = new UILabel(); |
| 112 | - errorTips_->SetPosition(ROOT_VIEW_POSITION_X, ROOT_VIEW_POSITION_Y, ROOT_VIEW_WIDTH, ROOT_VIEW_HEIGHT); | 113 | + errorTips_->SetPosition(ROOT_VIEW_POSITION_X, ROOT_VIEW_POSITION_Y, ROOT_VIEW_WIDTH(), ROOT_VIEW_HEIGHT()); |
| 113 | errorTips_->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, | 114 | errorTips_->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, |
| 114 | UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); | 115 | UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); |
| 115 | - errorTips_->SetFont(FONT_NAME, GALLERY_FONT_SIZE); | 116 | + errorTips_->SetFont(FONT_NAME, GALLERY_FONT_SIZE()); |
| 116 | errorTips_->SetText("视频播放错误"); | 117 | errorTips_->SetText("视频播放错误"); |
| 117 | 118 | ||
| 118 | - rootView_->Add(backArea_); | ||
| 119 | rootView_->Add(errorTips_); | 119 | rootView_->Add(errorTips_); |
| 120 | + rootView_->Add(backArea_); | ||
| 120 | rootView_->Add(backIcon_); | 121 | rootView_->Add(backIcon_); |
| 122 | + rootView_->Add(titleLabel_); | ||
| 121 | SetUIContent(rootView_); | 123 | SetUIContent(rootView_); |
| 122 | } | 124 | } |
| 123 | 125 | ||
| @@ -128,23 +130,27 @@ void PlayerAbilitySlice::SetUpRootView() | |||
| 128 | } | 130 | } |
| 129 | rootView_ = RootView::GetWindowRootView(); | 131 | rootView_ = RootView::GetWindowRootView(); |
| 130 | rootView_->SetPosition(ROOT_VIEW_POSITION_X, ROOT_VIEW_POSITION_Y); | 132 | rootView_->SetPosition(ROOT_VIEW_POSITION_X, ROOT_VIEW_POSITION_Y); |
| 131 | - rootView_->Resize(ROOT_VIEW_WIDTH, ROOT_VIEW_HEIGHT); | 133 | + rootView_->Resize(ROOT_VIEW_WIDTH(), ROOT_VIEW_HEIGHT()); |
| 132 | rootView_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); | 134 | rootView_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); |
| 133 | } | 135 | } |
| 134 | 136 | ||
| 135 | -void PlayerAbilitySlice::SetUpBackArea(const char* pathHeader) | 137 | +void PlayerAbilitySlice::SetUpBackArea(const char* pathHeader, const char* imageName) |
| 136 | { | 138 | { |
| 137 | auto onClick = [this] (UIView &view, const Event &event) -> bool { | 139 | auto onClick = [this] (UIView &view, const Event &event) -> bool { |
| 138 | - printf("############ PlayerAbilitySlice terminate AS enter #############\n"); | 140 | + LOGI("############ PlayerAbilitySlice terminate AS enter #############"); |
| 139 | Terminate(); | 141 | Terminate(); |
| 140 | - printf("############ PlayerAbilitySlice terminate AS exit #############\n"); | 142 | + LOGI("############ PlayerAbilitySlice terminate AS exit #############"); |
| 141 | return true; | 143 | return true; |
| 142 | }; | 144 | }; |
| 143 | backIcon_ = new UIImageView(); | 145 | backIcon_ = new UIImageView(); |
| 144 | - backIcon_->SetPosition(BACK_ICON_POSITION_X, BACK_ICON_POSITION_Y); | 146 | + backIcon_->SetAutoEnable(false); |
| 147 | + backIcon_->SetResizeMode(UIImageView::ImageResizeMode::CONTAIN); | ||
| 148 | + backIcon_->SetPosition(BACK_ICON_POSITION_X(), BACK_ICON_POSITION_Y(), BACK_ICON_WIDTH(), BACK_ICON_HEIGHT()); | ||
| 149 | + backIcon_->SetStyle(STYLE_BACKGROUND_OPA, 0); | ||
| 150 | + backIcon_->SetStyle(STYLE_BACKGROUND_COLOR, Color::White().full); | ||
| 145 | 151 | ||
| 146 | if (sprintf_s(backIconAbsolutePath, MAX_PATH_LENGTH, "%s%s", pathHeader, BACK_ICON_PATH) < 0) { | 152 | if (sprintf_s(backIconAbsolutePath, MAX_PATH_LENGTH, "%s%s", pathHeader, BACK_ICON_PATH) < 0) { |
| 147 | - printf("PlayerAbilitySlice::OnStart | backIconAbsolutePath | %s\n", pathHeader); | 153 | + LOGE("PlayerAbilitySlice::OnStart | backIconAbsolutePath | %s\n", pathHeader); |
| 148 | return; | 154 | return; |
| 149 | } | 155 | } |
| 150 | backIcon_->SetSrc(backIconAbsolutePath); | 156 | backIcon_->SetSrc(backIconAbsolutePath); |
| @@ -153,13 +159,22 @@ void PlayerAbilitySlice::SetUpBackArea(const char* pathHeader) | |||
| 153 | backIcon_->SetOnClickListener(backIconListener_); | 159 | backIcon_->SetOnClickListener(backIconListener_); |
| 154 | 160 | ||
| 155 | backArea_ = new UIViewGroup(); | 161 | backArea_ = new UIViewGroup(); |
| 156 | - backArea_->SetPosition(0, 0, LABEL_POSITION_X, LABEL_HEIGHT); | 162 | + backArea_->SetPosition(0, 0, LABEL_POSITION_X(), LABEL_HEIGHT()); |
| 157 | backArea_->SetStyle(STYLE_BACKGROUND_OPA, 0); | 163 | backArea_->SetStyle(STYLE_BACKGROUND_OPA, 0); |
| 158 | backArea_->SetTouchable(true); | 164 | backArea_->SetTouchable(true); |
| 159 | backArea_->SetOnClickListener(backIconListener_); | 165 | backArea_->SetOnClickListener(backIconListener_); |
| 160 | 166 | ||
| 167 | + titleLabel_ = new UILabel(); | ||
| 168 | + titleLabel_->SetPosition(LABEL_POSITION_X(), LABEL_POSITION_Y, LABEL_WIDTH(), LABEL_HEIGHT()); | ||
| 169 | + titleLabel_->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_LEFT, UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); | ||
| 170 | + titleLabel_->SetFont(FONT_NAME, GALLERY_FONT_SIZE()); | ||
| 171 | + titleLabel_->SetStyle(STYLE_TEXT_COLOR, Color::Black().full); | ||
| 172 | + titleLabel_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); | ||
| 173 | + titleLabel_->SetText(imageName); | ||
| 174 | + | ||
| 161 | rootView_->Add(backArea_); | 175 | rootView_->Add(backArea_); |
| 162 | rootView_->Add(backIcon_); | 176 | rootView_->Add(backIcon_); |
| 177 | + rootView_->Add(titleLabel_); | ||
| 163 | } | 178 | } |
| 164 | 179 | ||
| 165 | void PlayerAbilitySlice::SetUpVideoPlayer(const Want &want) | 180 | void PlayerAbilitySlice::SetUpVideoPlayer(const Want &want) |
| @@ -173,16 +188,16 @@ void PlayerAbilitySlice::SetUpVideoPlayer(const Want &want) | |||
| 173 | int8_t ret = sprintf_s(videoPlayer_->filePath, videoPathLen + 1, "%s/%s", VIDEO_SOURCE_DIRECTORY, | 188 | int8_t ret = sprintf_s(videoPlayer_->filePath, videoPathLen + 1, "%s/%s", VIDEO_SOURCE_DIRECTORY, |
| 174 | reinterpret_cast<char*>(want.data)); | 189 | reinterpret_cast<char*>(want.data)); |
| 175 | if (ret < 0) { | 190 | if (ret < 0) { |
| 176 | - printf("PlayerAbilitySlice::OnStart | videoPlayer_->filePath | %s\n", reinterpret_cast<char*>(want.data)); | 191 | + LOGE("PlayerAbilitySlice::OnStart | videoPlayer_->filePath | %s", reinterpret_cast<char*>(want.data)); |
| 177 | return; | 192 | return; |
| 178 | } | 193 | } |
| 179 | ret = sprintf_s(&videoPlayer_->filePath[videoPathLen - strlen(AVAILABEL_SOURCE_TYPE)], | 194 | ret = sprintf_s(&videoPlayer_->filePath[videoPathLen - strlen(AVAILABEL_SOURCE_TYPE)], |
| 180 | strlen(AVAILABEL_SOURCE_TYPE) + 1, "%s", AVAILABEL_SOURCE_TYPE); | 195 | strlen(AVAILABEL_SOURCE_TYPE) + 1, "%s", AVAILABEL_SOURCE_TYPE); |
| 181 | if (ret < 0) { | 196 | if (ret < 0) { |
| 182 | - printf("PlayerAbilitySlice::OnStart | videoPlayer_->filePath \n"); | 197 | + LOGE("PlayerAbilitySlice::OnStart | videoPlayer_->filePath"); |
| 183 | return; | 198 | return; |
| 184 | } | 199 | } |
| 185 | - printf("------########### mp4 file path | %s\n", videoPlayer_->filePath); | 200 | + LOGI("------########### mp4 file path | %s", videoPlayer_->filePath); |
| 186 | 201 | ||
| 187 | videoPlayer_->adapter = PlayerAbilitySlice::CreatePlayer(); | 202 | videoPlayer_->adapter = PlayerAbilitySlice::CreatePlayer(); |
| 188 | std::string uri(videoPlayer_->filePath); | 203 | std::string uri(videoPlayer_->filePath); |
| @@ -199,32 +214,31 @@ bool PlayerAbilitySlice::SetUpSurfaceView() | |||
| 199 | int32_t width = 0; | 214 | int32_t width = 0; |
| 200 | int32_t height = 0; | 215 | int32_t height = 0; |
| 201 | videoPlayer_->adapter->GetVideoWidth(width); | 216 | videoPlayer_->adapter->GetVideoWidth(width); |
| 202 | - printf("[%s,%d] width:%d\n", __func__, __LINE__, width); | ||
| 203 | videoPlayer_->adapter->GetVideoHeight(height); | 217 | videoPlayer_->adapter->GetVideoHeight(height); |
| 204 | - printf("[%s,%d] height:%d\n", __func__, __LINE__, height); | 218 | + LOGI("width:%d, height:%d", width, height); |
| 205 | 219 | ||
| 206 | if (width <= 0 || height <= 0) { | 220 | if (width <= 0 || height <= 0) { |
| 207 | videoPlayer_->adapter->Release(); | 221 | videoPlayer_->adapter->Release(); |
| 208 | delete videoPlayer_; | 222 | delete videoPlayer_; |
| 209 | videoPlayer_ = nullptr; | 223 | videoPlayer_ = nullptr; |
| 210 | - printf("******** width <= 0 || height <= 0 | return \n"); | 224 | + LOGE("******** width <= 0 || height <= 0 | return"); |
| 211 | ShowErrorTips(); | 225 | ShowErrorTips(); |
| 212 | return false; | 226 | return false; |
| 213 | } | 227 | } |
| 214 | - float ratio_x = static_cast<float>(width) / ROOT_VIEW_WIDTH; | 228 | + float ratio_x = static_cast<float>(width) / ROOT_VIEW_WIDTH(); |
| 215 | - float ratio_y = static_cast<float>(height) / ROOT_VIEW_HEIGHT; | 229 | + float ratio_y = static_cast<float>(height) / ROOT_VIEW_HEIGHT(); |
| 216 | uint16_t surfaceViewWidth; | 230 | uint16_t surfaceViewWidth; |
| 217 | uint16_t surfaceViewHeight; | 231 | uint16_t surfaceViewHeight; |
| 218 | uint16_t surfaceViewPositionX = 0; | 232 | uint16_t surfaceViewPositionX = 0; |
| 219 | uint16_t surfaceViewPositionY = 0; | 233 | uint16_t surfaceViewPositionY = 0; |
| 220 | if (ratio_x > ratio_y) { | 234 | if (ratio_x > ratio_y) { |
| 221 | - surfaceViewWidth = ROOT_VIEW_WIDTH; | 235 | + surfaceViewWidth = ROOT_VIEW_WIDTH(); |
| 222 | surfaceViewHeight = height / ratio_x; | 236 | surfaceViewHeight = height / ratio_x; |
| 223 | - surfaceViewPositionY = (ROOT_VIEW_HEIGHT - surfaceViewHeight) / 2; // 2: half | 237 | + surfaceViewPositionY = (ROOT_VIEW_HEIGHT() - surfaceViewHeight) / 2; // 2: half |
| 224 | } else { | 238 | } else { |
| 225 | surfaceViewWidth = width / ratio_y; | 239 | surfaceViewWidth = width / ratio_y; |
| 226 | - surfaceViewHeight = ROOT_VIEW_HEIGHT; | 240 | + surfaceViewHeight = ROOT_VIEW_HEIGHT(); |
| 227 | - surfaceViewPositionX = (ROOT_VIEW_WIDTH - surfaceViewWidth) / 2; // 2: half | 241 | + surfaceViewPositionX = (ROOT_VIEW_WIDTH() - surfaceViewWidth) / 2; // 2: half |
| 228 | } | 242 | } |
| 229 | 243 | ||
| 230 | surfaceView_ = new UISurfaceView(); | 244 | surfaceView_ = new UISurfaceView(); |
| @@ -241,14 +255,14 @@ bool PlayerAbilitySlice::SetUpSurfaceView() | |||
| 241 | void PlayerAbilitySlice::SetUpProgress(int64_t duration) | 255 | void PlayerAbilitySlice::SetUpProgress(int64_t duration) |
| 242 | { | 256 | { |
| 243 | slider_ = new UISlider(); | 257 | slider_ = new UISlider(); |
| 244 | - slider_->SetPosition(SLIDER_X, SLIDER_Y, SLIDER_WIDTH, STATUS_BAR_GROUP_HEIGHT); | 258 | + slider_->SetPosition(SLIDER_X(), SLIDER_Y(), SLIDER_WIDTH(), STATUS_BAR_GROUP_HEIGHT()); |
| 245 | - slider_->SetValidHeight(SLIDER_HEIGHT); | 259 | + slider_->SetValidHeight(SLIDER_HEIGHT()); |
| 246 | - slider_->SetValidWidth(SLIDER_WIDTH - KNOB_WIDTH); | 260 | + slider_->SetValidWidth(SLIDER_WIDTH() - KNOB_WIDTH()); |
| 247 | - slider_->SetRange(SLIDER_WIDTH, 0); | 261 | + slider_->SetRange(SLIDER_WIDTH(), 0); |
| 248 | slider_->SetValue(0); | 262 | slider_->SetValue(0); |
| 249 | - slider_->SetKnobWidth(KNOB_WIDTH); | 263 | + slider_->SetKnobWidth(KNOB_WIDTH()); |
| 250 | - slider_->SetSliderRadius(SLIDER_HEIGHT, SLIDER_HEIGHT); | 264 | + slider_->SetSliderRadius(SLIDER_HEIGHT(), SLIDER_HEIGHT()); |
| 251 | - slider_->SetKnobRadius(KNOB_WIDTH / 2); // 2: half | 265 | + slider_->SetKnobRadius(KNOB_WIDTH() / 2); // 2: half |
| 252 | slider_->SetKnobStyle(STYLE_BACKGROUND_COLOR, Color::White().full); | 266 | slider_->SetKnobStyle(STYLE_BACKGROUND_COLOR, Color::White().full); |
| 253 | slider_->SetBackgroundStyle(STYLE_BACKGROUND_COLOR, 0x1A888888); | 267 | slider_->SetBackgroundStyle(STYLE_BACKGROUND_COLOR, 0x1A888888); |
| 254 | slider_->SetBackgroundStyle(STYLE_BACKGROUND_OPA, 90); // 90: opacity is 90 | 268 | slider_->SetBackgroundStyle(STYLE_BACKGROUND_OPA, 90); // 90: opacity is 90 |
| @@ -263,19 +277,19 @@ void PlayerAbilitySlice::SetUpAnimatorGroup(const char* pathHeader) | |||
| 263 | { | 277 | { |
| 264 | int64_t duration = 0; | 278 | int64_t duration = 0; |
| 265 | videoPlayer_->adapter->GetDuration(duration); | 279 | videoPlayer_->adapter->GetDuration(duration); |
| 266 | - printf("[%s,%d] GetDuration:%lld\n", __func__, __LINE__, duration); | 280 | + LOGI("[%s,%d] GetDuration:%lld", __func__, __LINE__, duration); |
| 267 | 281 | ||
| 268 | animatorGroup_ = new UIViewGroup(); | 282 | animatorGroup_ = new UIViewGroup(); |
| 269 | - animatorGroup_->SetPosition(0, ROOT_VIEW_HEIGHT - STATUS_BAR_GROUP_HEIGHT, | 283 | + animatorGroup_->SetPosition(0, ROOT_VIEW_HEIGHT() - STATUS_BAR_GROUP_HEIGHT(), |
| 270 | - ROOT_VIEW_WIDTH, STATUS_BAR_GROUP_HEIGHT); | 284 | + ROOT_VIEW_WIDTH(), STATUS_BAR_GROUP_HEIGHT()); |
| 271 | animatorGroup_->SetStyle(STYLE_BACKGROUND_OPA, 0); | 285 | animatorGroup_->SetStyle(STYLE_BACKGROUND_OPA, 0); |
| 272 | 286 | ||
| 273 | totalTimeLabel_ = new UILabel(); | 287 | totalTimeLabel_ = new UILabel(); |
| 274 | - totalTimeLabel_->SetPosition(TOTAL_TIME_LABEL_X, TOTAL_TIME_LABEL_Y, | 288 | + totalTimeLabel_->SetPosition(TOTAL_TIME_LABEL_X(), TOTAL_TIME_LABEL_Y, |
| 275 | - TOTAL_TIME_LABEL_WIDTH, TOTAL_TIME_LABEL_HEIGHT); | 289 | + TOTAL_TIME_LABEL_WIDTH(), TOTAL_TIME_LABEL_HEIGHT()); |
| 276 | totalTimeLabel_->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_LEFT, | 290 | totalTimeLabel_->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_LEFT, |
| 277 | UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); | 291 | UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); |
| 278 | - totalTimeLabel_->SetFont(FONT_NAME, PLAYER_FONT_SIZE); | 292 | + totalTimeLabel_->SetFont(FONT_NAME, PLAYER_FONT_SIZE()); |
| 279 | int64_t second = duration / 1000; // 1000: 1s = 1000ms | 293 | int64_t second = duration / 1000; // 1000: 1s = 1000ms |
| 280 | char timer[6]; // 6: length of time label | 294 | char timer[6]; // 6: length of time label |
| 281 | if (sprintf_s(timer, sizeof(timer), "%02lld:%02lld", second / 60, second % 60) < 0) { // 60: 1minute = 60s | 295 | if (sprintf_s(timer, sizeof(timer), "%02lld:%02lld", second / 60, second % 60) < 0) { // 60: 1minute = 60s |
| @@ -287,10 +301,10 @@ void PlayerAbilitySlice::SetUpAnimatorGroup(const char* pathHeader) | |||
| 287 | animatorGroup_->Add(totalTimeLabel_); | 301 | animatorGroup_->Add(totalTimeLabel_); |
| 288 | 302 | ||
| 289 | currentTimeLabel_ = new UILabel(); | 303 | currentTimeLabel_ = new UILabel(); |
| 290 | - currentTimeLabel_->SetPosition(CURRENT_TIME_LABEL_X, CURRENT_TIME_LABEL_Y, | 304 | + currentTimeLabel_->SetPosition(CURRENT_TIME_LABEL_X(), CURRENT_TIME_LABEL_Y, |
| 291 | - CURRENT_TIME_LABEL_WIDTH, CURRENT_TIME_LABEL_HEIGHT); | 305 | + CURRENT_TIME_LABEL_WIDTH(), CURRENT_TIME_LABEL_HEIGHT()); |
| 292 | currentTimeLabel_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Red().full); | 306 | currentTimeLabel_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Red().full); |
| 293 | - currentTimeLabel_->SetFont(FONT_NAME, PLAYER_FONT_SIZE); | 307 | + currentTimeLabel_->SetFont(FONT_NAME, PLAYER_FONT_SIZE()); |
| 294 | currentTimeLabel_->SetText("00:00"); | 308 | currentTimeLabel_->SetText("00:00"); |
| 295 | currentTimeLabel_->SetTextColor(Color::White()); | 309 | currentTimeLabel_->SetTextColor(Color::White()); |
| 296 | currentTimeLabel_->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_LEFT, | 310 | currentTimeLabel_->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_LEFT, |
| @@ -308,24 +322,24 @@ void PlayerAbilitySlice::SetUpToggleButton(const char* pathHeader) | |||
| 308 | { | 322 | { |
| 309 | toggleButton_ = new UIToggleButton(); | 323 | toggleButton_ = new UIToggleButton(); |
| 310 | toggleButton_->SetTouchable(false); | 324 | toggleButton_->SetTouchable(false); |
| 311 | - toggleButton_->SetPosition(TOGGLE_BUTTON_OFFSET_X, TOGGLE_BUTTON_OFFSET_Y, | 325 | + toggleButton_->SetPosition(TOGGLE_BUTTON_OFFSET_X(), TOGGLE_BUTTON_OFFSET_Y(), |
| 312 | - TOGGLE_BUTTON_WIDTH, TOGGLE_BUTTON_HEIGHT); | 326 | + TOGGLE_BUTTON_WIDTH(), TOGGLE_BUTTON_HEIGHT()); |
| 313 | toggleButton_->SetState(true); | 327 | toggleButton_->SetState(true); |
| 314 | 328 | ||
| 315 | if (sprintf_s(videoPlayAbsolutePath, MAX_PATH_LENGTH, "%s%s", pathHeader, VIDEO_PALY_PATH) < 0) { | 329 | if (sprintf_s(videoPlayAbsolutePath, MAX_PATH_LENGTH, "%s%s", pathHeader, VIDEO_PALY_PATH) < 0) { |
| 316 | - printf("PlayerAbilitySlice::OnStart | videoPlayAbsolutePath\n"); | 330 | + LOGE("PlayerAbilitySlice::OnStart | videoPlayAbsolutePath"); |
| 317 | return; | 331 | return; |
| 318 | } | 332 | } |
| 319 | 333 | ||
| 320 | if (sprintf_s(videoPauseAbsolutePath, MAX_PATH_LENGTH, "%s%s", pathHeader, VIDEO_PAUSE_PATH) < 0) { | 334 | if (sprintf_s(videoPauseAbsolutePath, MAX_PATH_LENGTH, "%s%s", pathHeader, VIDEO_PAUSE_PATH) < 0) { |
| 321 | - printf("PlayerAbilitySlice::OnStart | videoPauseAbsolutePath\n"); | 335 | + LOGE("PlayerAbilitySlice::OnStart | videoPauseAbsolutePath"); |
| 322 | return; | 336 | return; |
| 323 | } | 337 | } |
| 324 | toggleButton_->SetImages(videoPauseAbsolutePath, videoPlayAbsolutePath); | 338 | toggleButton_->SetImages(videoPauseAbsolutePath, videoPlayAbsolutePath); |
| 325 | onClickListener_ = new ToggleBtnListener(toggleButton_, videoPlayer_, animator_, surfaceView_); | 339 | onClickListener_ = new ToggleBtnListener(toggleButton_, videoPlayer_, animator_, surfaceView_); |
| 326 | 340 | ||
| 327 | toggleButtonArea_ = new UIViewGroup(); | 341 | toggleButtonArea_ = new UIViewGroup(); |
| 328 | - toggleButtonArea_->SetPosition(0, 0, TOGGLE_BUTTON_OFFSET_X + TOGGLE_BUTTON_WIDTH, STATUS_BAR_GROUP_HEIGHT); | 342 | + toggleButtonArea_->SetPosition(0, 0, TOGGLE_BUTTON_OFFSET_X() + TOGGLE_BUTTON_WIDTH(), STATUS_BAR_GROUP_HEIGHT()); |
| 329 | toggleButtonArea_->SetTouchable(true); | 343 | toggleButtonArea_->SetTouchable(true); |
| 330 | toggleButtonArea_->SetOnClickListener(onClickListener_); | 344 | toggleButtonArea_->SetOnClickListener(onClickListener_); |
| 331 | toggleButtonArea_->Add(toggleButton_); | 345 | toggleButtonArea_->Add(toggleButton_); |
| @@ -335,7 +349,7 @@ void PlayerAbilitySlice::SetUpToggleButton(const char* pathHeader) | |||
| 335 | 349 | ||
| 336 | void PlayerAbilitySlice::OnStart(const Want &want) | 350 | void PlayerAbilitySlice::OnStart(const Want &want) |
| 337 | { | 351 | { |
| 338 | - printf("@@@@@ PlayerAbilitySlice::OnStart\n"); | 352 | + LOGI("@@@@@ PlayerAbilitySlice::OnStart"); |
| 339 | AbilitySlice::OnStart(want); | 353 | AbilitySlice::OnStart(want); |
| 340 | 354 | ||
| 341 | SetUpRootView(); | 355 | SetUpRootView(); |
| @@ -347,7 +361,7 @@ void PlayerAbilitySlice::OnStart(const Want &want) | |||
| 347 | if (!SetUpSurfaceView()) { | 361 | if (!SetUpSurfaceView()) { |
| 348 | return; | 362 | return; |
| 349 | } | 363 | } |
| 350 | - SetUpBackArea(pathHeader); | 364 | + SetUpBackArea(pathHeader, reinterpret_cast<char*>(want.data)); |
| 351 | SetUpAnimatorGroup(pathHeader); | 365 | SetUpAnimatorGroup(pathHeader); |
| 352 | 366 | ||
| 353 | SetUIContent(rootView_); | 367 | SetUIContent(rootView_); |
| @@ -357,24 +371,24 @@ void PlayerAbilitySlice::OnStart(const Want &want) | |||
| 357 | animator_->SetToggleBtnListener(onClickListener_); | 371 | animator_->SetToggleBtnListener(onClickListener_); |
| 358 | animator_->Start(); | 372 | animator_->Start(); |
| 359 | 373 | ||
| 360 | - printf("## @@@@@ PlayerAbilitySlice::OnStart | end \n"); | 374 | + LOGI("## @@@@@ PlayerAbilitySlice::OnStart | end "); |
| 361 | } | 375 | } |
| 362 | 376 | ||
| 363 | void PlayerAbilitySlice::OnInactive() | 377 | void PlayerAbilitySlice::OnInactive() |
| 364 | { | 378 | { |
| 365 | - printf("PlayerAbilitySlice::OnInactive\n"); | 379 | + LOGI("PlayerAbilitySlice::OnInactive"); |
| 366 | AbilitySlice::OnInactive(); | 380 | AbilitySlice::OnInactive(); |
| 367 | } | 381 | } |
| 368 | 382 | ||
| 369 | void PlayerAbilitySlice::OnActive(const Want &want) | 383 | void PlayerAbilitySlice::OnActive(const Want &want) |
| 370 | { | 384 | { |
| 371 | - printf("PlayerAbilitySlice::OnActive\n"); | 385 | + LOGI("PlayerAbilitySlice::OnActive"); |
| 372 | AbilitySlice::OnActive(want); | 386 | AbilitySlice::OnActive(want); |
| 373 | } | 387 | } |
| 374 | 388 | ||
| 375 | void PlayerAbilitySlice::OnBackground() | 389 | void PlayerAbilitySlice::OnBackground() |
| 376 | { | 390 | { |
| 377 | - printf("PlayerAbilitySlice::OnBackground\n"); | 391 | + LOGI("PlayerAbilitySlice::OnBackground"); |
| 378 | AbilitySlice::OnBackground(); | 392 | AbilitySlice::OnBackground(); |
| 379 | } | 393 | } |
| 380 | 394 | ||
| @@ -393,7 +407,7 @@ void PlayerAbilitySlice::OnStop() | |||
| 393 | videoPlayer_ = nullptr; | 407 | videoPlayer_ = nullptr; |
| 394 | } | 408 | } |
| 395 | Clear(); | 409 | Clear(); |
| 396 | - printf("PlayerAbilitySlice::OnStop\n"); | 410 | + LOGI("PlayerAbilitySlice::OnStop"); |
| 397 | AbilitySlice::OnStop(); | 411 | AbilitySlice::OnStop(); |
| 398 | } | 412 | } |
| 399 | 413 | ||
| @@ -448,11 +462,11 @@ bool ToggleBtnListener::OnClick(UIView &view, const ClickEvent& event) | |||
| 448 | if (button_->GetState()) { | 462 | if (button_->GetState()) { |
| 449 | videoPlayer_->adapter->Play(); | 463 | videoPlayer_->adapter->Play(); |
| 450 | animator_->Resume(); | 464 | animator_->Resume(); |
| 451 | - printf("ToggleBtnListener::OnClick | play\n"); | 465 | + LOGI("ToggleBtnListener::OnClick | play"); |
| 452 | } else { | 466 | } else { |
| 453 | videoPlayer_->adapter->Pause(); | 467 | videoPlayer_->adapter->Pause(); |
| 454 | animator_->Pause(); | 468 | animator_->Pause(); |
| 455 | - printf("ToggleBtnListener::OnClick | pause\n"); | 469 | + LOGI("ToggleBtnListener::OnClick | pause"); |
| 456 | } | 470 | } |
| 457 | button_->Invalidate(); | 471 | button_->Invalidate(); |
| 458 | return true; | 472 | return true; |
| @@ -13,6 +13,35 @@ | |||
| 13 | 13 | ||
| 14 | import("//build/lite/config/hap_pack.gni") | 14 | import("//build/lite/config/hap_pack.gni") |
| 15 | 15 | ||
| 16 | +_is_hi3516 = !defined(media_interface_upgrade) | ||
| 17 | +_res_src = "launcher/src/main/resources" | ||
| 18 | +_res_dst = "$target_out_dir/launcher_resources" | ||
| 19 | + | ||
| 20 | +action("launcher_prepare_resources") { | ||
| 21 | + script = "//applications/sample/camera/launcher/copy_resources.py" | ||
| 22 | + _res_base = "launcher/src/main/resources/base/media" | ||
| 23 | + inputs = [ | ||
| 24 | + "$_res_base/background.png", | ||
| 25 | + "$_res_base/weather.png", | ||
| 26 | + ] | ||
| 27 | + if (!_is_hi3516) { | ||
| 28 | + inputs += [ "$_res_base/background_1920x1080.png" ] | ||
| 29 | + } | ||
| 30 | + outputs = [ "$_res_dst/.stamp" ] | ||
| 31 | + args = [ | ||
| 32 | + "--src", | ||
| 33 | + rebase_path(_res_src), | ||
| 34 | + "--dst", | ||
| 35 | + rebase_path(_res_dst), | ||
| 36 | + ] | ||
| 37 | + if (_is_hi3516) { | ||
| 38 | + args += [ | ||
| 39 | + "--exclude", | ||
| 40 | + "base/media/background_1920x1080.png", | ||
| 41 | + ] | ||
| 42 | + } | ||
| 43 | +} | ||
| 44 | + | ||
| 16 | shared_library("launcher") { | 45 | shared_library("launcher") { |
| 17 | sources = [ | 46 | sources = [ |
| 18 | "launcher/src/main/cpp/app_info.cpp", | 47 | "launcher/src/main/cpp/app_info.cpp", |
| @@ -37,6 +66,7 @@ shared_library("launcher") { | |||
| 37 | 66 | ||
| 38 | include_dirs = [ | 67 | include_dirs = [ |
| 39 | "launcher/src/main/cpp", | 68 | "launcher/src/main/cpp", |
| 69 | + "..", | ||
| 40 | "${aafwk_lite_path}/interfaces/kits/ability_lite", | 70 | "${aafwk_lite_path}/interfaces/kits/ability_lite", |
| 41 | "${appexecfwk_lite_path}/interfaces/kits/bundle_lite", | 71 | "${appexecfwk_lite_path}/interfaces/kits/bundle_lite", |
| 42 | "${aafwk_lite_path}/interfaces/kits/want_lite", | 72 | "${aafwk_lite_path}/interfaces/kits/want_lite", |
| @@ -47,16 +77,23 @@ shared_library("launcher") { | |||
| 47 | "ABILITY_WINDOW_SUPPORT", | 77 | "ABILITY_WINDOW_SUPPORT", |
| 48 | "OHOS_APPEXECFWK_BMS_BUNDLEMANAGER", | 78 | "OHOS_APPEXECFWK_BMS_BUNDLEMANAGER", |
| 49 | ] | 79 | ] |
| 80 | + | ||
| 81 | + if (_is_hi3516) { | ||
| 82 | + defines += [ "LAUNCHER_NO_BACKGROUND=1" ] | ||
| 83 | + } | ||
| 50 | } | 84 | } |
| 51 | 85 | ||
| 52 | hap_pack("launcher_hap") { | 86 | hap_pack("launcher_hap") { |
| 53 | - deps = [ ":launcher" ] | 87 | + deps = [ |
| 88 | + ":launcher", | ||
| 89 | + ":launcher_prepare_resources", | ||
| 90 | + ] | ||
| 54 | mode = "hap" | 91 | mode = "hap" |
| 55 | json_path = "launcher/src/main/config.json" | 92 | json_path = "launcher/src/main/config.json" |
| 56 | ability_so_path = "$root_out_dir/liblauncher.so" | 93 | ability_so_path = "$root_out_dir/liblauncher.so" |
| 57 | force = "true" | 94 | force = "true" |
| 58 | cert_profile = "cert/com.huawei.launcher_AppProvision_release.p7b" | 95 | cert_profile = "cert/com.huawei.launcher_AppProvision_release.p7b" |
| 59 | - resources_path = "launcher/src/main/resources" | 96 | + resources_path = _res_dst |
| 60 | hap_name = "launcher" | 97 | hap_name = "launcher" |
| 61 | privatekey = "HOS Application Provision Release" | 98 | privatekey = "HOS Application Provision Release" |
| 62 | } | 99 | } |
| @@ -0,0 +1,81 @@ | |||
| 1 | +#!/usr/bin/env python3 | ||
| 2 | +# Copyright (c) 2020 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 | + | ||
| 15 | +"""把 resources 目录复制到构建目录,可选排除指定相对路径的文件。 | ||
| 16 | + | ||
| 17 | +用法: | ||
| 18 | + copy_resources.py --src <src_dir> --dst <dst_dir> \ | ||
| 19 | + [--exclude <posix_rel_path>] ... | ||
| 20 | + | ||
| 21 | +排除路径是相对 --src 的 posix 风格路径,例如: | ||
| 22 | + base/media/background_1920x1080.png | ||
| 23 | +""" | ||
| 24 | + | ||
| 25 | +import argparse | ||
| 26 | +import os | ||
| 27 | +import shutil | ||
| 28 | + | ||
| 29 | + | ||
| 30 | +def _norm_posix(path): | ||
| 31 | + """归一化为相对 src 的 posix 路径,用于和 --exclude 比对。""" | ||
| 32 | + return path.replace("\\", "/").lstrip("./") | ||
| 33 | + | ||
| 34 | + | ||
| 35 | +def copy_tree(src, dst, excludes): | ||
| 36 | + """递归复制 src 到 dst,跳过 excludes 中的相对路径文件。""" | ||
| 37 | + excl_set = {_norm_posix(p) for p in excludes} | ||
| 38 | + for root, _dirs, files in os.walk(src): | ||
| 39 | + rel_root = os.path.relpath(root, src).replace("\\", "/") | ||
| 40 | + if rel_root == ".": | ||
| 41 | + rel_root = "" | ||
| 42 | + for name in files: | ||
| 43 | + rel = name if not rel_root else f"{rel_root}/{name}" | ||
| 44 | + rel_norm = _norm_posix(rel) | ||
| 45 | + if rel_norm in excl_set: | ||
| 46 | + continue | ||
| 47 | + src_file = os.path.join(root, name) | ||
| 48 | + dst_file = os.path.join(dst, rel_norm) | ||
| 49 | + os.makedirs(os.path.dirname(dst_file), exist_ok=True) | ||
| 50 | + shutil.copy2(src_file, dst_file) | ||
| 51 | + | ||
| 52 | + | ||
| 53 | +def main(): | ||
| 54 | + ap = argparse.ArgumentParser(description="Copy resources tree.") | ||
| 55 | + ap.add_argument("--src", required=True, help="source resources dir") | ||
| 56 | + ap.add_argument("--dst", required=True, help="destination dir") | ||
| 57 | + ap.add_argument( | ||
| 58 | + "--exclude", | ||
| 59 | + action="append", | ||
| 60 | + default=[], | ||
| 61 | + help="posix rel path to exclude (repeatable)", | ||
| 62 | + ) | ||
| 63 | + args = ap.parse_args() | ||
| 64 | + | ||
| 65 | + if not os.path.isdir(args.src): | ||
| 66 | + raise FileNotFoundError(f"source dir not found: {args.src}") | ||
| 67 | + | ||
| 68 | + # 每次构建重新生成副本,保证排除策略生效。 | ||
| 69 | + if os.path.exists(args.dst): | ||
| 70 | + shutil.rmtree(args.dst) | ||
| 71 | + os.makedirs(args.dst, exist_ok=True) | ||
| 72 | + | ||
| 73 | + copy_tree(args.src, args.dst, args.exclude) | ||
| 74 | + | ||
| 75 | + # 写一个 stamp 文件作为 GN action 的 outputs 占位。 | ||
| 76 | + with open(os.path.join(args.dst, ".stamp"), "w", encoding="utf-8") as f: | ||
| 77 | + f.write("done\n") | ||
| 78 | + | ||
| 79 | + | ||
| 80 | +if __name__ == "__main__": | ||
| 81 | + main() | ||
| @@ -23,6 +23,10 @@ AppInfo::AppInfo() | |||
| 23 | } | 23 | } |
| 24 | void AppInfo::Release() | 24 | void AppInfo::Release() |
| 25 | { | 25 | { |
| 26 | + if (iconView_) { | ||
| 27 | + delete iconView_; | ||
| 28 | + iconView_ = nullptr; | ||
| 29 | + } | ||
| 26 | if (button_) { | 30 | if (button_) { |
| 27 | delete button_; | 31 | delete button_; |
| 28 | button_ = nullptr; | 32 | button_ = nullptr; |
| @@ -50,6 +54,7 @@ void AppInfo::ReSet() | |||
| 50 | { | 54 | { |
| 51 | button_ = nullptr; | 55 | button_ = nullptr; |
| 52 | lable_ = nullptr; | 56 | lable_ = nullptr; |
| 57 | + iconView_ = nullptr; | ||
| 53 | appClickListener_ = nullptr; | 58 | appClickListener_ = nullptr; |
| 54 | appLpListener_ = nullptr; | 59 | appLpListener_ = nullptr; |
| 55 | } | 60 | } |
| @@ -57,15 +62,14 @@ void AppInfo::ReSet() | |||
| 57 | void AppInfo::SetButton(UILabelButton* button) | 62 | void AppInfo::SetButton(UILabelButton* button) |
| 58 | { | 63 | { |
| 59 | button->SetPosition(buttonXY_.x, buttonXY_.y, buttonHV_.x, buttonHV_.y); | 64 | button->SetPosition(buttonXY_.x, buttonXY_.y, buttonHV_.x, buttonHV_.y); |
| 60 | - button->SetFont(FOND_PATH, LAUNCHER_FOND_ID); | 65 | + button->SetFont(FOND_PATH, static_cast<uint8_t>(FontScale(LAUNCHER_FOND_ID))); |
| 61 | button->SetStyleForState(STYLE_BORDER_RADIUS, BUTTON_RADIUS, UIButton::PRESSED); | 66 | button->SetStyleForState(STYLE_BORDER_RADIUS, BUTTON_RADIUS, UIButton::PRESSED); |
| 62 | button->SetStyleForState(STYLE_BACKGROUND_OPA, TOTAL_OPACITY, UIButton::PRESSED); | 67 | button->SetStyleForState(STYLE_BACKGROUND_OPA, TOTAL_OPACITY, UIButton::PRESSED); |
| 63 | button->SetStyleForState(STYLE_BORDER_OPA, TOTAL_OPACITY, UIButton::PRESSED); | 68 | button->SetStyleForState(STYLE_BORDER_OPA, TOTAL_OPACITY, UIButton::PRESSED); |
| 64 | button->SetStyle(STYLE_BORDER_RADIUS, BUTTON_RADIUS); | 69 | button->SetStyle(STYLE_BORDER_RADIUS, BUTTON_RADIUS); |
| 65 | button->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY); | 70 | button->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY); |
| 66 | button->SetStyle(STYLE_BORDER_OPA, TOTAL_OPACITY); | 71 | button->SetStyle(STYLE_BORDER_OPA, TOTAL_OPACITY); |
| 67 | - button->SetStyle(STYLE_TEXT_COLOR, Color::ColorTo32(Color::White())); | 72 | + button->SetStyle(STYLE_TEXT_COLOR, Color::ColorTo32(Color::Black())); |
| 68 | - button->SetImageSrc(appIconDir_, appIconDir_); | ||
| 69 | button_ = button; | 73 | button_ = button; |
| 70 | } | 74 | } |
| 71 | 75 | ||
| @@ -79,7 +83,7 @@ void AppInfo::SetLable(UILabel* lable) | |||
| 79 | lable->SetText(appName_); | 83 | lable->SetText(appName_); |
| 80 | } | 84 | } |
| 81 | lable->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_TOP); | 85 | lable->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_TOP); |
| 82 | - lable->SetFont(FOND_PATH, APP_FOND_ID); | 86 | + lable->SetFont(FOND_PATH, static_cast<uint8_t>(FontScale(APP_FOND_ID))); |
| 83 | lable->SetStyle(STYLE_BORDER_RADIUS, LABLE_RADIUS); | 87 | lable->SetStyle(STYLE_BORDER_RADIUS, LABLE_RADIUS); |
| 84 | lable->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY); | 88 | lable->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY); |
| 85 | lable_ = lable; | 89 | lable_ = lable; |
| @@ -19,6 +19,7 @@ | |||
| 19 | #include <components/ui_label_button.h> | 19 | #include <components/ui_label_button.h> |
| 20 | #include <components/ui_label.h> | 20 | #include <components/ui_label.h> |
| 21 | #include <components/ui_view_group.h> | 21 | #include <components/ui_view_group.h> |
| 22 | +#include <components/ui_image_view.h> | ||
| 22 | 23 | ||
| 23 | #include "native_base.h" | 24 | #include "native_base.h" |
| 24 | #include "ui_config.h" | 25 | #include "ui_config.h" |
| @@ -49,6 +50,7 @@ public: | |||
| 49 | 50 | ||
| 50 | UILabelButton* button_ { nullptr }; | 51 | UILabelButton* button_ { nullptr }; |
| 51 | UILabel* lable_ { nullptr }; | 52 | UILabel* lable_ { nullptr }; |
| 53 | + UIImageView* iconView_ { nullptr }; | ||
| 52 | 54 | ||
| 53 | UIView::OnLongPressListener* appLpListener_ { nullptr }; | 55 | UIView::OnLongPressListener* appLpListener_ { nullptr }; |
| 54 | UIView::OnClickListener* appClickListener_ { nullptr }; | 56 | UIView::OnClickListener* appClickListener_ { nullptr }; |
| @@ -63,6 +65,7 @@ public: | |||
| 63 | char appName_[TMP_BUF_SIZE] = { 0 }; | 65 | char appName_[TMP_BUF_SIZE] = { 0 }; |
| 64 | char abilityName_[TMP_BUF_SIZE] = { 0 }; | 66 | char abilityName_[TMP_BUF_SIZE] = { 0 }; |
| 65 | char appIconDir_[TMP_BUF_SIZE] = { 0 }; | 67 | char appIconDir_[TMP_BUF_SIZE] = { 0 }; |
| 68 | + bool isSystemApp_ = false; | ||
| 66 | }; | 69 | }; |
| 67 | 70 | ||
| 68 | class AppClickListener : public UIView::OnClickListener { | 71 | class AppClickListener : public UIView::OnClickListener { |
| @@ -55,6 +55,7 @@ bool AppManage::GetAailityInfosByBundleName(const char* bundleName, AppInfo* pAp | |||
| 55 | strlen(pBundleInfo->bigIconPath)); | 55 | strlen(pBundleInfo->bigIconPath)); |
| 56 | pApp->appIconDir_[strlen(pBundleInfo->bigIconPath)] = 0; | 56 | pApp->appIconDir_[strlen(pBundleInfo->bigIconPath)] = 0; |
| 57 | } | 57 | } |
| 58 | + pApp->isSystemApp_ = pBundleInfo->isSystemApp; | ||
| 58 | return true; | 59 | return true; |
| 59 | } | 60 | } |
| 60 | } | 61 | } |
| @@ -90,15 +91,29 @@ bool AppManage::GetAppInstallInfo(const char* bundleName) | |||
| 90 | return false; | 91 | return false; |
| 91 | } | 92 | } |
| 92 | 93 | ||
| 94 | +void AppManage::GetAppUninstallInfo(const char* bundleName) | ||
| 95 | +{ | ||
| 96 | + if (bundleName == nullptr) { | ||
| 97 | + return; | ||
| 98 | + } | ||
| 99 | + for (int i = 0; i < size_; i++) { | ||
| 100 | + if (viewPage_[i] && viewPage_[i]->RemoveApp(bundleName)) { | ||
| 101 | + return; | ||
| 102 | + } | ||
| 103 | + } | ||
| 104 | +} | ||
| 105 | + | ||
| 93 | void AppManage::MyBundleStateCallback( | 106 | void AppManage::MyBundleStateCallback( |
| 94 | const uint8_t installType, const uint8_t resultCode, const void* resultMessage, const char* bundleName, void* data) | 107 | const uint8_t installType, const uint8_t resultCode, const void* resultMessage, const char* bundleName, void* data) |
| 95 | { | 108 | { |
| 96 | - if (installType == 0) { // install update | 109 | + if (resultCode == 0 && bundleName != nullptr) { |
| 97 | - if (resultCode == 0 && bundleName != nullptr) { | 110 | + char tmpName[TMP_BUF_SIZE] = {0}; |
| 98 | - char tmpName[TMP_BUF_SIZE] = {0}; | 111 | + if (memcpy_s(tmpName, sizeof(tmpName), bundleName, strlen(bundleName)) == LAUNCHER_SUCCESS) { |
| 99 | - if (memcpy_s(tmpName, sizeof(tmpName), bundleName, strlen(bundleName)) == LAUNCHER_SUCCESS) { | 112 | + tmpName[strlen(bundleName)] = 0; |
| 100 | - tmpName[strlen(bundleName)] = 0; | 113 | + if (installType == 0) { // install update |
| 101 | GetAppInstallInfo(tmpName); | 114 | GetAppInstallInfo(tmpName); |
| 115 | + } else if (installType == 1) { // uninstall | ||
| 116 | + GetAppUninstallInfo(tmpName); | ||
| 102 | } | 117 | } |
| 103 | } | 118 | } |
| 104 | } | 119 | } |
| @@ -134,7 +149,11 @@ bool AppManage::InstallApp(AppInfo* app) | |||
| 134 | 149 | ||
| 135 | bool AppManage::UnInstallApp(AppInfo* app) | 150 | bool AppManage::UnInstallApp(AppInfo* app) |
| 136 | { | 151 | { |
| 137 | - return Uninstall(app->appName_, nullptr, MyBundleOwnCallback); | 152 | + if (app->isSystemApp_) { |
| 153 | + return false; | ||
| 154 | + } | ||
| 155 | + InstallParam installParam = {0, false}; | ||
| 156 | + return Uninstall(app->appName_, &installParam, MyBundleOwnCallback); | ||
| 138 | } | 157 | } |
| 139 | 158 | ||
| 140 | bool AppManage::StartApp(AppInfo* app) | 159 | bool AppManage::StartApp(AppInfo* app) |
| @@ -46,6 +46,7 @@ private: | |||
| 46 | static void MyBundleOwnCallback(const uint8_t resultCode, const void* resultMessage); | 46 | static void MyBundleOwnCallback(const uint8_t resultCode, const void* resultMessage); |
| 47 | static bool GetAailityInfosByBundleName(const char* bundleName, AppInfo* pApp); | 47 | static bool GetAailityInfosByBundleName(const char* bundleName, AppInfo* pApp); |
| 48 | static bool GetAppInstallInfo(const char* bundleName); | 48 | static bool GetAppInstallInfo(const char* bundleName); |
| 49 | + static void GetAppUninstallInfo(const char* bundleName); | ||
| 49 | 50 | ||
| 50 | private: | 51 | private: |
| 51 | BundleStatusCallback callBackParam_ { nullptr }; | 52 | BundleStatusCallback callBackParam_ { nullptr }; |
| @@ -33,7 +33,7 @@ LongPressView::LongPressView(UninstallApp uninstall) | |||
| 33 | buttUninstall_->SetStyleForState(STYLE_BORDER_RADIUS, BUTTON_RADIUS, UIButton::PRESSED); | 33 | buttUninstall_->SetStyleForState(STYLE_BORDER_RADIUS, BUTTON_RADIUS, UIButton::PRESSED); |
| 34 | buttUninstall_->SetStyleForState(STYLE_BACKGROUND_OPA, HALF_OPACITY, UIButton::PRESSED); | 34 | buttUninstall_->SetStyleForState(STYLE_BACKGROUND_OPA, HALF_OPACITY, UIButton::PRESSED); |
| 35 | buttUninstall_->SetText("卸载"); | 35 | buttUninstall_->SetText("卸载"); |
| 36 | - buttUninstall_->SetFont(FOND_PATH, LAUNCHER_FOND_ID); | 36 | + buttUninstall_->SetFont(FOND_PATH, static_cast<uint8_t>(FontScale(LAUNCHER_FOND_ID))); |
| 37 | buttUninstall_->SetOnClickListener(this); | 37 | buttUninstall_->SetOnClickListener(this); |
| 38 | 38 | ||
| 39 | buttCancle_ = new UILabelButton(); | 39 | buttCancle_ = new UILabelButton(); |
| @@ -43,7 +43,7 @@ LongPressView::LongPressView(UninstallApp uninstall) | |||
| 43 | buttCancle_->SetStyleForState(STYLE_BORDER_RADIUS, BUTTON_RADIUS, UIButton::PRESSED); | 43 | buttCancle_->SetStyleForState(STYLE_BORDER_RADIUS, BUTTON_RADIUS, UIButton::PRESSED); |
| 44 | buttCancle_->SetStyleForState(STYLE_BACKGROUND_OPA, HALF_OPACITY, UIButton::PRESSED); | 44 | buttCancle_->SetStyleForState(STYLE_BACKGROUND_OPA, HALF_OPACITY, UIButton::PRESSED); |
| 45 | buttCancle_->SetText("取消"); | 45 | buttCancle_->SetText("取消"); |
| 46 | - buttCancle_->SetFont(FOND_PATH, LAUNCHER_FOND_ID); | 46 | + buttCancle_->SetFont(FOND_PATH, static_cast<uint8_t>(FontScale(LAUNCHER_FOND_ID))); |
| 47 | buttCancle_->SetOnClickListener(this); | 47 | buttCancle_->SetOnClickListener(this); |
| 48 | 48 | ||
| 49 | viewGroup_->Add(buttUninstall_); | 49 | viewGroup_->Add(buttUninstall_); |
| @@ -69,18 +69,34 @@ void LongPressView::RemoveLview() | |||
| 69 | 69 | ||
| 70 | void LongPressView::Show(UIViewGroup* viewParent, AppInfo* pApp) | 70 | void LongPressView::Show(UIViewGroup* viewParent, AppInfo* pApp) |
| 71 | { | 71 | { |
| 72 | - const int16_t HEIGHT_DISCOUNT = 3; | ||
| 73 | const int16_t WIDTH_DISCOUNT = 2; | 72 | const int16_t WIDTH_DISCOUNT = 2; |
| 74 | bStatus_ = true; | 73 | bStatus_ = true; |
| 75 | viewParent_ = viewParent; | 74 | viewParent_ = viewParent; |
| 76 | app_ = pApp; | 75 | app_ = pApp; |
| 77 | - viewGroup_->SetPosition(pApp->buttonXY_.x / WIDTH_DISCOUNT + pApp->button_->GetWidth(), | 76 | + |
| 78 | - pApp->buttonXY_.y / WIDTH_DISCOUNT + pApp->button_->GetHeight(), pApp->button_->GetWidth(), | 77 | + int16_t popupWidth = pApp->buttonHV_.x; |
| 79 | - (pApp->button_->GetHeight() * WIDTH_DISCOUNT) / HEIGHT_DISCOUNT + pApp->button_->GetHeight() / WIDTH_DISCOUNT); | 78 | + int16_t popupX = pApp->buttonXY_.x + (pApp->buttonHV_.x - popupWidth) / 2; |
| 80 | - buttUninstall_->SetPosition(0, 0, | 79 | + int16_t popupY = pApp->buttonXY_.y + pApp->buttonHV_.y; |
| 81 | - pApp->button_->GetWidth(), pApp->button_->GetHeight() / WIDTH_DISCOUNT); | 80 | + |
| 82 | - buttCancle_->SetPosition(0, (pApp->button_->GetHeight() * WIDTH_DISCOUNT) / HEIGHT_DISCOUNT, | 81 | + if (pApp->isSystemApp_) { |
| 83 | - pApp->button_->GetWidth(), pApp->button_->GetHeight() / WIDTH_DISCOUNT); | 82 | + // System app: replace uninstall text with "系统应用" |
| 83 | + int16_t popupHeight = pApp->buttonHV_.y * WIDTH_DISCOUNT; | ||
| 84 | + viewGroup_->SetPosition(popupX, popupY, popupWidth, popupHeight); | ||
| 85 | + buttUninstall_->SetVisible(true); | ||
| 86 | + buttUninstall_->SetText("系统应用"); | ||
| 87 | + buttUninstall_->SetPosition(0, 0, popupWidth, popupHeight / WIDTH_DISCOUNT); | ||
| 88 | + buttCancle_->SetText("取消"); | ||
| 89 | + buttCancle_->SetPosition(0, popupHeight / WIDTH_DISCOUNT, popupWidth, popupHeight / WIDTH_DISCOUNT); | ||
| 90 | + } else { | ||
| 91 | + // Non-system app: show uninstall and cancel buttons | ||
| 92 | + int16_t popupHeight = pApp->buttonHV_.y * WIDTH_DISCOUNT; | ||
| 93 | + viewGroup_->SetPosition(popupX, popupY, popupWidth, popupHeight); | ||
| 94 | + buttUninstall_->SetVisible(true); | ||
| 95 | + buttUninstall_->SetText("卸载"); | ||
| 96 | + buttUninstall_->SetPosition(0, 0, popupWidth, popupHeight / WIDTH_DISCOUNT); | ||
| 97 | + buttCancle_->SetText("取消"); | ||
| 98 | + buttCancle_->SetPosition(0, popupHeight / WIDTH_DISCOUNT, popupWidth, popupHeight / WIDTH_DISCOUNT); | ||
| 99 | + } | ||
| 84 | viewGroup_->SetVisible(true); | 100 | viewGroup_->SetVisible(true); |
| 85 | viewParent_->Add(viewGroup_); | 101 | viewParent_->Add(viewGroup_); |
| 86 | viewParent_->Invalidate(); | 102 | viewParent_->Invalidate(); |
| @@ -58,10 +58,10 @@ void MainAbilitySlice::SetHead() | |||
| 58 | sprintf_s(tmp, sizeof(tmp), "%02d : %02d", st->tm_hour, st->tm_min); | 58 | sprintf_s(tmp, sizeof(tmp), "%02d : %02d", st->tm_hour, st->tm_min); |
| 59 | UILabel* label = new UILabel(); | 59 | UILabel* label = new UILabel(); |
| 60 | rootview_->Add(label); | 60 | rootview_->Add(label); |
| 61 | - label->SetPosition(0, 0, Screen::GetInstance().GetWidth(), LABLE_TITLE_HEIGHT); | 61 | + label->SetPosition(0, 0, GetScrWidth(), LABLE_TITLE_HEIGHT); |
| 62 | label->SetText(tmp); | 62 | label->SetText(tmp); |
| 63 | label->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_TOP); | 63 | label->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_TOP); |
| 64 | - label->SetFont(FOND_PATH, LAUNCHER_FOND_ID); | 64 | + label->SetFont(FOND_PATH, static_cast<uint8_t>(FontScale(LAUNCHER_FOND_ID))); |
| 65 | label->SetStyle(STYLE_TEXT_COLOR, Color::ColorTo32(Color::White())); | 65 | label->SetStyle(STYLE_TEXT_COLOR, Color::ColorTo32(Color::White())); |
| 66 | label->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY); | 66 | label->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY); |
| 67 | 67 | ||
| @@ -72,13 +72,13 @@ void MainAbilitySlice::SetTail() | |||
| 72 | { | 72 | { |
| 73 | UILabel* label = new UILabel(); | 73 | UILabel* label = new UILabel(); |
| 74 | rootview_->Add(label); | 74 | rootview_->Add(label); |
| 75 | - label->SetPosition(0, Screen::GetInstance().GetHeight() - LABLE_TAIL_HEIGHT, | 75 | + label->SetPosition(0, GetScrHeight() - LABLE_TAIL_HEIGHT, |
| 76 | - Screen::GetInstance().GetWidth(), LABLE_TAIL_HEIGHT); | 76 | + GetScrWidth(), LABLE_TAIL_HEIGHT); |
| 77 | char buf[TMP_BUF_SIZE] = { 0 }; | 77 | char buf[TMP_BUF_SIZE] = { 0 }; |
| 78 | sprintf_s(buf, sizeof(buf), ".%d.", 1); | 78 | sprintf_s(buf, sizeof(buf), ".%d.", 1); |
| 79 | label->SetText(buf); | 79 | label->SetText(buf); |
| 80 | label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); | 80 | label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); |
| 81 | - label->SetFont(FOND_PATH, LAUNCHER_FOND_ID); | 81 | + label->SetFont(FOND_PATH, static_cast<uint8_t>(FontScale(LAUNCHER_FOND_ID))); |
| 82 | label->SetStyle(STYLE_TEXT_COLOR, Color::ColorTo32(Color::White())); | 82 | label->SetStyle(STYLE_TEXT_COLOR, Color::ColorTo32(Color::White())); |
| 83 | label->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY); | 83 | label->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY); |
| 84 | 84 | ||
| @@ -90,8 +90,10 @@ void MainAbilitySlice::SetImageView() | |||
| 90 | uiImageView_ = new UIImageView(); | 90 | uiImageView_ = new UIImageView(); |
| 91 | // modify image view height | 91 | // modify image view height |
| 92 | 92 | ||
| 93 | - uiImageView_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); | 93 | + uiImageView_->SetPosition(0, 0, GetScrWidth(), GetScrHeight()); |
| 94 | uiImageView_->SetStyle(STYLE_BACKGROUND_COLOR, Color::ColorTo32(Color::White())); | 94 | uiImageView_->SetStyle(STYLE_BACKGROUND_COLOR, Color::ColorTo32(Color::White())); |
| 95 | + uiImageView_->SetAutoEnable(false); | ||
| 96 | + uiImageView_->SetResizeMode(UIImageView::ImageResizeMode::COVER); | ||
| 95 | uiImageView_->SetSrc(TABLE_BACKGROUND); | 97 | uiImageView_->SetSrc(TABLE_BACKGROUND); |
| 96 | uiImageView_->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); | 98 | uiImageView_->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); |
| 97 | rootview_->Add(uiImageView_); | 99 | rootview_->Add(uiImageView_); |
| @@ -109,10 +111,12 @@ void MainAbilitySlice::OnStart(const Want& want) | |||
| 109 | AbilitySlice::OnStart(want); | 111 | AbilitySlice::OnStart(want); |
| 110 | rootview_ = RootView::GetWindowRootView(); | 112 | rootview_ = RootView::GetWindowRootView(); |
| 111 | rootview_->SetPosition(0, 0); | 113 | rootview_->SetPosition(0, 0); |
| 112 | - rootview_->Resize(Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); | 114 | + rootview_->Resize(GetScrWidth(), GetScrHeight()); |
| 113 | rootview_->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); | 115 | rootview_->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); |
| 114 | rootview_->SetStyle(STYLE_BACKGROUND_COLOR, Color::ColorTo32(Color::GetColorFromRGB(0x30, 0x30, 0x30))); | 116 | rootview_->SetStyle(STYLE_BACKGROUND_COLOR, Color::ColorTo32(Color::GetColorFromRGB(0x30, 0x30, 0x30))); |
| 115 | - | 117 | +#ifndef LAUNCHER_NO_BACKGROUND |
| 118 | + SetImageView(); | ||
| 119 | +#endif | ||
| 116 | SetHead(); | 120 | SetHead(); |
| 117 | SetTail(); | 121 | SetTail(); |
| 118 | SetSwipe(); | 122 | SetSwipe(); |
| @@ -46,8 +46,8 @@ SwipeView::~SwipeView() | |||
| 46 | void SwipeView::SetUpSwipe() | 46 | void SwipeView::SetUpSwipe() |
| 47 | { | 47 | { |
| 48 | swipe_ = new UISwipeView(); | 48 | swipe_ = new UISwipeView(); |
| 49 | - swipe_->SetPosition(0, LABLE_TITLE_HEIGHT, Screen::GetInstance().GetWidth(), | 49 | + swipe_->SetPosition(0, LABLE_TITLE_HEIGHT, GetScrWidth(), |
| 50 | - Screen::GetInstance().GetHeight() - LABLE_TITLE_HEIGHT - LABLE_TAIL_HEIGHT); | 50 | + GetScrHeight() - LABLE_TITLE_HEIGHT - LABLE_TAIL_HEIGHT); |
| 51 | swipe_->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY); | 51 | swipe_->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY); |
| 52 | swipe_->SetLoopState(true); | 52 | swipe_->SetLoopState(true); |
| 53 | swipe_->SetAnimatorTime(20); // set swipe view animator time 20s | 53 | swipe_->SetAnimatorTime(20); // set swipe view animator time 20s |
| @@ -62,8 +62,8 @@ UIViewGroup* SwipeView::AddViewGroup() | |||
| 62 | if (viewGroup == nullptr) { | 62 | if (viewGroup == nullptr) { |
| 63 | return viewGroup; | 63 | return viewGroup; |
| 64 | } | 64 | } |
| 65 | - viewGroup->SetPosition(0, LABLE_TITLE_HEIGHT, Screen::GetInstance().GetWidth(), | 65 | + viewGroup->SetPosition(0, LABLE_TITLE_HEIGHT, GetScrWidth(), |
| 66 | - Screen::GetInstance().GetHeight() - LABLE_TITLE_HEIGHT - LABLE_TAIL_HEIGHT); | 66 | + GetScrHeight() - LABLE_TITLE_HEIGHT - LABLE_TAIL_HEIGHT); |
| 67 | viewGroup->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY); | 67 | viewGroup->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY); |
| 68 | groupCount_++; | 68 | groupCount_++; |
| 69 | ViewGroupPage* page = new ViewGroupPage(viewGroup); | 69 | ViewGroupPage* page = new ViewGroupPage(viewGroup); |
| @@ -75,8 +75,8 @@ UIViewGroup* SwipeView::AddViewGroup() | |||
| 75 | UIViewGroup* SwipeView::AddFirstViewGroup() | 75 | UIViewGroup* SwipeView::AddFirstViewGroup() |
| 76 | { | 76 | { |
| 77 | UIViewGroup* firstView = new UIViewGroup(); | 77 | UIViewGroup* firstView = new UIViewGroup(); |
| 78 | - firstView->SetPosition(0, LABLE_TITLE_HEIGHT, Screen::GetInstance().GetWidth(), | 78 | + firstView->SetPosition(0, LABLE_TITLE_HEIGHT, GetScrWidth(), |
| 79 | - Screen::GetInstance().GetHeight() - LABLE_TITLE_HEIGHT - LABLE_TAIL_HEIGHT); | 79 | + GetScrHeight() - LABLE_TITLE_HEIGHT - LABLE_TAIL_HEIGHT); |
| 80 | firstView->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY); | 80 | firstView->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY); |
| 81 | 81 | ||
| 82 | UIViewGroup* viewTimeWeather = new UIViewGroup(); | 82 | UIViewGroup* viewTimeWeather = new UIViewGroup(); |
| @@ -113,8 +113,8 @@ void SwipeView::OnSetUpView() | |||
| 113 | AddFirstViewGroup(); | 113 | AddFirstViewGroup(); |
| 114 | AddViewGroup(); | 114 | AddViewGroup(); |
| 115 | AddViewGroup(); | 115 | AddViewGroup(); |
| 116 | - double scale0 = 0.6; | 116 | + double scale0 = 0.5; |
| 117 | - double scale1 = 0.69; | 117 | + double scale1 = 0.55; |
| 118 | // Reserved. Touch and hold to add a page. | 118 | // Reserved. Touch and hold to add a page. |
| 119 | arrPage_[0]->SetMatrix(APP_ROW_COUNT, APP_COL_COUNT); | 119 | arrPage_[0]->SetMatrix(APP_ROW_COUNT, APP_COL_COUNT); |
| 120 | arrPage_[0]->SetScale(scale0); | 120 | arrPage_[0]->SetScale(scale0); |
| @@ -134,6 +134,16 @@ void SwipeView::OnSetUpView() | |||
| 134 | 134 | ||
| 135 | void SwipeView::BundleInfoScan(BundleInfo* pBundleInfos, int count) | 135 | void SwipeView::BundleInfoScan(BundleInfo* pBundleInfos, int count) |
| 136 | { | 136 | { |
| 137 | + // Sort by bundleName to ensure consistent icon positions across restarts | ||
| 138 | + for (int i = 0; i < count - 1; i++) { | ||
| 139 | + for (int j = i + 1; j < count; j++) { | ||
| 140 | + if (strcmp(pBundleInfos[i].bundleName, pBundleInfos[j].bundleName) > 0) { | ||
| 141 | + BundleInfo temp = pBundleInfos[i]; | ||
| 142 | + pBundleInfos[i] = pBundleInfos[j]; | ||
| 143 | + pBundleInfos[j] = temp; | ||
| 144 | + } | ||
| 145 | + } | ||
| 146 | + } | ||
| 137 | for (int j = 0; j < count; j++) { | 147 | for (int j = 0; j < count; j++) { |
| 138 | for (int i = 0; i < groupCount_; i++) { | 148 | for (int i = 0; i < groupCount_; i++) { |
| 139 | if (memcmp(LAUNCHER_BUNDLE_NAME, pBundleInfos[j].bundleName, strlen(pBundleInfos[j].bundleName)) == 0) { | 149 | if (memcmp(LAUNCHER_BUNDLE_NAME, pBundleInfos[j].bundleName, strlen(pBundleInfos[j].bundleName)) == 0) { |
| @@ -163,6 +173,7 @@ void SwipeView::BundleInfoScan(BundleInfo* pBundleInfos, int count) | |||
| 163 | strlen(pBundleInfos[j].bigIconPath)); | 173 | strlen(pBundleInfos[j].bigIconPath)); |
| 164 | app->appIconDir_[strlen(pBundleInfos[j].bigIconPath)] = 0; | 174 | app->appIconDir_[strlen(pBundleInfos[j].bigIconPath)] = 0; |
| 165 | } | 175 | } |
| 176 | + app->isSystemApp_ = pBundleInfos[j].isSystemApp; | ||
| 166 | if (arrPage_[i]->AddApp(app)) { | 177 | if (arrPage_[i]->AddApp(app)) { |
| 167 | break; | 178 | break; |
| 168 | } | 179 | } |
| @@ -18,15 +18,24 @@ | |||
| 18 | 18 | ||
| 19 | #include "time_weather_view.h" | 19 | #include "time_weather_view.h" |
| 20 | 20 | ||
| 21 | + | ||
| 21 | namespace OHOS { | 22 | namespace OHOS { |
| 22 | static constexpr int16_t DISPLATE_PICESE = 2; | 23 | static constexpr int16_t DISPLATE_PICESE = 2; |
| 23 | -static constexpr int16_t BLANK_H = 5; | 24 | +/* Scaled values from 1920x1080 reference */ |
| 24 | -static constexpr int16_t BLANK_TW = 15; | 25 | +static constexpr int16_t BLANK_H_SCALE = 8; |
| 25 | -static constexpr int16_t BLANK_W = 100; | 26 | +static constexpr int16_t BLANK_TW_SCALE = 22; |
| 26 | -static constexpr int16_t BIGLABEL_H = 100; | 27 | +static constexpr int16_t BLANK_W_SCALE = 150; |
| 27 | -static constexpr int16_t SMALLLABEL_H = 35; | 28 | +static constexpr int16_t BIGLABEL_H_SCALE = 150; |
| 28 | -static constexpr int16_t IMAGE_H = 40; | 29 | +static constexpr int16_t SMALLLABEL_H_SCALE = 52; |
| 29 | -static constexpr int16_t IMAGE_W = 40; | 30 | +static constexpr int16_t IMAGE_H_SCALE = 60; |
| 31 | +static constexpr int16_t IMAGE_W_SCALE = 60; | ||
| 32 | +static inline int16_t BLANK_H() { return VScale(BLANK_H_SCALE); } | ||
| 33 | +static inline int16_t BLANK_TW() { return HScale(BLANK_TW_SCALE); } | ||
| 34 | +static inline int16_t BLANK_W() { return HScale(BLANK_W_SCALE); } | ||
| 35 | +static inline int16_t BIGLABEL_H() { return VScale(BIGLABEL_H_SCALE); } | ||
| 36 | +static inline int16_t SMALLLABEL_H() { return VScale(SMALLLABEL_H_SCALE); } | ||
| 37 | +static inline int16_t IMAGE_H() { return UScale(IMAGE_H_SCALE); } | ||
| 38 | +static inline int16_t IMAGE_W() { return UScale(IMAGE_W_SCALE); } | ||
| 30 | const char* g_weekDate[WEEK_DAY_MAX] = {"星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"}; | 39 | const char* g_weekDate[WEEK_DAY_MAX] = {"星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"}; |
| 31 | 40 | ||
| 32 | TimeWeatherView::TimeWeatherView(UIViewGroup* viewGroup) | 41 | TimeWeatherView::TimeWeatherView(UIViewGroup* viewGroup) |
| @@ -73,24 +82,24 @@ void TimeWeatherView::SetUpTimeView() | |||
| 73 | if (ret == LAUNCHER_PARAMERROR) { return; } | 82 | if (ret == LAUNCHER_PARAMERROR) { return; } |
| 74 | if (viewTime_ == nullptr) { | 83 | if (viewTime_ == nullptr) { |
| 75 | viewTime_ = new UIViewGroup(); | 84 | viewTime_ = new UIViewGroup(); |
| 76 | - viewTime_->SetPosition(BLANK_TW, BLANK_H, viewGroup_->GetWidth() - BLANK_W, | 85 | + viewTime_->SetPosition(BLANK_TW(), BLANK_H(), viewGroup_->GetWidth() - BLANK_W(), |
| 77 | - viewGroup_->GetHeight() / DISPLATE_PICESE - SMALLLABEL_H); | 86 | + viewGroup_->GetHeight() / DISPLATE_PICESE - SMALLLABEL_H()); |
| 78 | viewTime_->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY); | 87 | viewTime_->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY); |
| 79 | UILabel* lable = new UILabel(); | 88 | UILabel* lable = new UILabel(); |
| 80 | - lable->SetPosition(BLANK_TW, BLANK_H, viewTime_->GetWidth(), BIGLABEL_H); | 89 | + lable->SetPosition(BLANK_TW(), BLANK_H(), viewTime_->GetWidth(), BIGLABEL_H()); |
| 81 | lable->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_BOTTOM); | 90 | lable->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_BOTTOM); |
| 82 | lable->SetText(hour_min); | 91 | lable->SetText(hour_min); |
| 83 | - lable->SetFont(FOND_PATH, BIGLAUNCHER_FOND_ID); | 92 | + lable->SetFont(FOND_PATH, static_cast<uint8_t>(FontScale(BIGLAUNCHER_FOND_ID))); |
| 84 | lable->SetStyle(STYLE_TEXT_COLOR, Color::ColorTo32(Color::White())); | 93 | lable->SetStyle(STYLE_TEXT_COLOR, Color::ColorTo32(Color::White())); |
| 85 | lable->SetStyle(STYLE_BORDER_RADIUS, LABLE_RADIUS); | 94 | lable->SetStyle(STYLE_BORDER_RADIUS, LABLE_RADIUS); |
| 86 | lable->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY); | 95 | lable->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY); |
| 87 | lable->SetViewId("labletime"); | 96 | lable->SetViewId("labletime"); |
| 88 | 97 | ||
| 89 | UILabel* lable2 = new UILabel(); | 98 | UILabel* lable2 = new UILabel(); |
| 90 | - lable2->SetPosition(BLANK_TW, BLANK_H + BIGLABEL_H + BLANK_H, viewTime_->GetWidth(), SMALLLABEL_H); | 99 | + lable2->SetPosition(BLANK_TW(), BLANK_H() + BIGLABEL_H() + BLANK_H(), viewTime_->GetWidth(), SMALLLABEL_H()); |
| 91 | lable2->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_TOP); | 100 | lable2->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_TOP); |
| 92 | lable2->SetText(date); | 101 | lable2->SetText(date); |
| 93 | - lable2->SetFont(FOND_PATH, LAUNCHER_FOND_ID); | 102 | + lable2->SetFont(FOND_PATH, static_cast<uint8_t>(FontScale(LAUNCHER_FOND_ID))); |
| 94 | 103 | ||
| 95 | lable2->SetStyle(STYLE_TEXT_COLOR, Color::ColorTo32(Color::White())); | 104 | lable2->SetStyle(STYLE_TEXT_COLOR, Color::ColorTo32(Color::White())); |
| 96 | lable2->SetStyle(STYLE_BORDER_RADIUS, LABLE_RADIUS); | 105 | lable2->SetStyle(STYLE_BORDER_RADIUS, LABLE_RADIUS); |
| @@ -142,33 +151,36 @@ void TimeWeatherView::SetUpWeatherView() | |||
| 142 | { | 151 | { |
| 143 | const int16_t countTimes = 6; | 152 | const int16_t countTimes = 6; |
| 144 | viewweather_ = new UIViewGroup(); | 153 | viewweather_ = new UIViewGroup(); |
| 145 | - viewweather_->SetPosition(BLANK_W, viewGroup_->GetHeight() / DISPLATE_PICESE - SMALLLABEL_H, | 154 | + viewweather_->SetPosition(BLANK_W(), viewGroup_->GetHeight() / DISPLATE_PICESE - SMALLLABEL_H(), |
| 146 | - viewGroup_->GetWidth() / DISPLATE_PICESE + BLANK_TW, DISPLATE_PICESE * (BLANK_H + SMALLLABEL_H) + BLANK_H); | 155 | + viewGroup_->GetWidth() / DISPLATE_PICESE + BLANK_TW(), |
| 156 | + DISPLATE_PICESE * (BLANK_H() + SMALLLABEL_H()) + BLANK_H()); | ||
| 147 | viewweather_->SetStyle(STYLE_BACKGROUND_OPA, HALF_OPACITY); | 157 | viewweather_->SetStyle(STYLE_BACKGROUND_OPA, HALF_OPACITY); |
| 148 | viewweather_->SetStyle(STYLE_BORDER_RADIUS, GROUP_VIEW_RADIUS); | 158 | viewweather_->SetStyle(STYLE_BORDER_RADIUS, GROUP_VIEW_RADIUS); |
| 149 | viewweather_->SetStyle(STYLE_BACKGROUND_COLOR, Color::ColorTo32(Color::Gray())); | 159 | viewweather_->SetStyle(STYLE_BACKGROUND_COLOR, Color::ColorTo32(Color::Gray())); |
| 150 | 160 | ||
| 151 | UIImageView* uiImageView = new UIImageView(); | 161 | UIImageView* uiImageView = new UIImageView(); |
| 152 | - uiImageView->SetPosition(BLANK_TW, BLANK_H * countTimes, IMAGE_W, IMAGE_H); | 162 | + uiImageView->SetPosition(BLANK_TW(), BLANK_H(), IMAGE_W(), IMAGE_H()); |
| 163 | + uiImageView->SetAutoEnable(false); | ||
| 164 | + uiImageView->SetResizeMode(UIImageView::ImageResizeMode::CONTAIN); | ||
| 153 | uiImageView->SetSrc(RES_WEATHER); | 165 | uiImageView->SetSrc(RES_WEATHER); |
| 154 | - uiImageView->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); | 166 | + uiImageView->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY); |
| 155 | 167 | ||
| 156 | UILabel* lable = new UILabel(); | 168 | UILabel* lable = new UILabel(); |
| 157 | - lable->SetPosition(BLANK_TW + IMAGE_W, BLANK_H, | 169 | + lable->SetPosition(BLANK_TW() + IMAGE_W(), BLANK_H(), |
| 158 | - viewweather_->GetWidth() - IMAGE_W - BLANK_TW - BLANK_TW - BLANK_TW, SMALLLABEL_H); | 170 | + viewweather_->GetWidth() - IMAGE_W() - BLANK_TW() - BLANK_TW() - BLANK_TW(), SMALLLABEL_H()); |
| 159 | lable->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); | 171 | lable->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); |
| 160 | lable->SetText("室内温度 26℃"); | 172 | lable->SetText("室内温度 26℃"); |
| 161 | - lable->SetFont(FOND_PATH, LAUNCHER_FOND_ID); | 173 | + lable->SetFont(FOND_PATH, static_cast<uint8_t>(FontScale(LAUNCHER_FOND_ID))); |
| 162 | lable->SetStyle(STYLE_TEXT_COLOR, Color::ColorTo32(Color::White())); | 174 | lable->SetStyle(STYLE_TEXT_COLOR, Color::ColorTo32(Color::White())); |
| 163 | lable->SetStyle(STYLE_BORDER_RADIUS, LABLE_RADIUS); | 175 | lable->SetStyle(STYLE_BORDER_RADIUS, LABLE_RADIUS); |
| 164 | lable->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY); | 176 | lable->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY); |
| 165 | 177 | ||
| 166 | UILabel* lable2 = new UILabel(); | 178 | UILabel* lable2 = new UILabel(); |
| 167 | - lable2->SetPosition(BLANK_TW + IMAGE_W, SMALLLABEL_H + BLANK_H + BLANK_H, | 179 | + lable2->SetPosition(BLANK_TW() + IMAGE_W(), SMALLLABEL_H() + BLANK_H() + BLANK_H(), |
| 168 | - viewweather_->GetWidth() - IMAGE_W - BLANK_TW - BLANK_TW - BLANK_TW, SMALLLABEL_H); | 180 | + viewweather_->GetWidth() - IMAGE_W() - BLANK_TW() - BLANK_TW() - BLANK_TW(), SMALLLABEL_H()); |
| 169 | lable2->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); | 181 | lable2->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); |
| 170 | lable2->SetText("空气污染指数 136"); | 182 | lable2->SetText("空气污染指数 136"); |
| 171 | - lable2->SetFont(FOND_PATH, LAUNCHER_FOND_ID); | 183 | + lable2->SetFont(FOND_PATH, static_cast<uint8_t>(FontScale(LAUNCHER_FOND_ID))); |
| 172 | lable2->SetStyle(STYLE_TEXT_COLOR, Color::ColorTo32(Color::White())); | 184 | lable2->SetStyle(STYLE_TEXT_COLOR, Color::ColorTo32(Color::White())); |
| 173 | lable2->SetStyle(STYLE_BORDER_RADIUS, LABLE_RADIUS); | 185 | lable2->SetStyle(STYLE_BORDER_RADIUS, LABLE_RADIUS); |
| 174 | lable2->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY); | 186 | lable2->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY); |
| @@ -18,25 +18,78 @@ | |||
| 18 | 18 | ||
| 19 | #include <cstdint> | 19 | #include <cstdint> |
| 20 | #include <securec.h> | 20 | #include <securec.h> |
| 21 | +#include <common/screen.h> | ||
| 21 | 22 | ||
| 22 | namespace OHOS { | 23 | namespace OHOS { |
| 23 | -static constexpr int16_t LABLE_TITLE_HEIGHT = 30; // tail lable height | 24 | +/* Screen-aware scaling helpers — designed for 1920x1080 reference. |
| 24 | -static constexpr int16_t LABLE_TAIL_HEIGHT = 30; | 25 | + * Default fallback resolution is 960x480 when Screen reports 0. */ |
| 25 | -static constexpr int16_t APP_WIDTH_COUNT = 7; // blank + app + blank + app + blank | 26 | +constexpr int16_t DESIGN_WIDTH = 1920; |
| 26 | -static constexpr int16_t APP_HEIGHT_COUNT = 4; // app + lable + app + lable | 27 | +constexpr int16_t DESIGN_HEIGHT = 1080; |
| 27 | -static constexpr int16_t MAX_VIEWGROUP = 3; // swipe window count | 28 | +constexpr uint16_t MIN_FONT_SIZE = 14; |
| 28 | -static constexpr int16_t APP_ROW_COUNT = 2; // a swipe view app count in row | 29 | +constexpr int16_t APP_ICON_SIZE_REF = 132; |
| 29 | -static constexpr int16_t APP_COL_COUNT = 3; // a sswipe view app count in col | 30 | +constexpr int16_t DEFAULT_SCR_WIDTH = 960; |
| 30 | -static constexpr int16_t LAUNCHER_FOND_ID = 16; // other view fond id | 31 | +constexpr int16_t DEFAULT_SCR_HEIGHT = 480; |
| 31 | -static constexpr int16_t APP_FOND_ID = 16; // app name fond id | 32 | + |
| 32 | -static constexpr int16_t BIGLAUNCHER_FOND_ID = 48; // time big fond id | 33 | +inline int16_t GetScrWidth() |
| 33 | -static constexpr int16_t TOTAL_OPACITY = 0; // transparent | 34 | +{ |
| 34 | -static constexpr int16_t HALF_OPACITY = 50; // diaphanous | 35 | + uint16_t w = Screen::GetInstance().GetWidth(); |
| 35 | -static constexpr int16_t UN_OPACITY = 255; // opaque | 36 | + return (w == 0) ? DEFAULT_SCR_WIDTH : static_cast<int16_t>(w); |
| 36 | -static constexpr int16_t BUTTON_RADIUS = 20; // app icon radius | 37 | +} |
| 37 | -static constexpr int16_t LABLE_RADIUS = 0; // lable icon radius | 38 | +inline int16_t GetScrHeight() |
| 38 | -static constexpr int16_t TITLE_LABLE_OPACITY = 255; // translucent | 39 | +{ |
| 39 | -static constexpr int16_t GROUP_VIEW_RADIUS = 20; // view radius | 40 | + uint16_t h = Screen::GetInstance().GetHeight(); |
| 41 | + return (h == 0) ? DEFAULT_SCR_HEIGHT : static_cast<int16_t>(h); | ||
| 42 | +} | ||
| 43 | +inline int16_t HScale(int16_t ref) | ||
| 44 | +{ | ||
| 45 | + return static_cast<int16_t>( | ||
| 46 | + static_cast<int32_t>(ref) * Screen::GetInstance().GetWidth() / DESIGN_WIDTH); | ||
| 47 | +} | ||
| 48 | +inline int16_t VScale(int16_t ref) | ||
| 49 | +{ | ||
| 50 | + return static_cast<int16_t>( | ||
| 51 | + static_cast<int32_t>(ref) * Screen::GetInstance().GetHeight() / DESIGN_HEIGHT); | ||
| 52 | +} | ||
| 53 | +inline int16_t UScale(int16_t ref) | ||
| 54 | +{ | ||
| 55 | + float rw = static_cast<float>(Screen::GetInstance().GetWidth()) / | ||
| 56 | + static_cast<float>(DESIGN_WIDTH); | ||
| 57 | + float rh = static_cast<float>(Screen::GetInstance().GetHeight()) / | ||
| 58 | + static_cast<float>(DESIGN_HEIGHT); | ||
| 59 | + return static_cast<int16_t>(ref * ((rw < rh) ? rw : rh)); | ||
| 60 | +} | ||
| 61 | +inline uint16_t FontScale(uint16_t ref) | ||
| 62 | +{ | ||
| 63 | + int32_t s = static_cast<int32_t>(ref) * Screen::GetInstance().GetHeight() / DESIGN_HEIGHT; | ||
| 64 | + return static_cast<uint16_t>(s < MIN_FONT_SIZE ? MIN_FONT_SIZE : s); | ||
| 65 | +} | ||
| 66 | +inline bool IsScrRes(int16_t w, int16_t h) | ||
| 67 | +{ | ||
| 68 | + return Screen::GetInstance().GetWidth() == w && Screen::GetInstance().GetHeight() == h; | ||
| 69 | +} | ||
| 70 | + | ||
| 71 | +constexpr int16_t LABLE_TITLE_HEIGHT = 30; // tail lable height | ||
| 72 | +constexpr int16_t LABLE_TAIL_HEIGHT = 30; | ||
| 73 | +constexpr int16_t APP_WIDTH_COUNT = 7; // blank + app + blank + app + blank | ||
| 74 | +constexpr int16_t APP_HEIGHT_COUNT = 4; // app + lable + app + lable | ||
| 75 | +constexpr int16_t MAX_VIEWGROUP = 3; // swipe window count | ||
| 76 | +constexpr int16_t APP_ROW_COUNT = 2; // a swipe view app count in row | ||
| 77 | +constexpr int16_t APP_COL_COUNT = 3; // a sswipe view app count in col | ||
| 78 | +constexpr int16_t LAUNCHER_FOND_ID = 24; // other view fond id | ||
| 79 | +constexpr int16_t APP_FOND_ID = 24; // app name fond id | ||
| 80 | +constexpr int16_t BIGLAUNCHER_FOND_ID = 72; // time big fond id | ||
| 81 | +constexpr int16_t TOTAL_OPACITY = 0; // transparent | ||
| 82 | +constexpr int16_t HALF_OPACITY = 50; // diaphanous | ||
| 83 | +constexpr int16_t UN_OPACITY = 255; // opaque | ||
| 84 | +constexpr int16_t BUTTON_RADIUS = 20; // app icon radius | ||
| 85 | +constexpr int16_t LABLE_RADIUS = 0; // lable icon radius | ||
| 86 | +constexpr int16_t TITLE_LABLE_OPACITY = 255; // translucent | ||
| 87 | +constexpr int16_t GROUP_VIEW_RADIUS = 20; // view radius | ||
| 88 | +/* App icon size — scaled from the 1920x1080 reference */ | ||
| 89 | +inline int16_t APP_ICON_SIZE() | ||
| 90 | +{ | ||
| 91 | + return HScale(APP_ICON_SIZE_REF); | ||
| 92 | +} | ||
| 40 | 93 | ||
| 41 | #ifndef TMP_BUF_SIZE | 94 | #ifndef TMP_BUF_SIZE |
| 42 | #define TMP_BUF_SIZE 128 | 95 | #define TMP_BUF_SIZE 128 |
| @@ -44,8 +97,9 @@ static constexpr int16_t GROUP_VIEW_RADIUS = 20; // view radius | |||
| 44 | 97 | ||
| 45 | #define LAUNCHER_BUNDLE_NAME "com.huawei.launcher" | 98 | #define LAUNCHER_BUNDLE_NAME "com.huawei.launcher" |
| 46 | #define SCREENSAVER_BUNDLE_NAME "com.huawei.screensaver" | 99 | #define SCREENSAVER_BUNDLE_NAME "com.huawei.screensaver" |
| 100 | +/* Background image — always use the high-res 1920x1080 version, COVER mode scales it down */ | ||
| 47 | #define TABLE_BACKGROUND \ | 101 | #define TABLE_BACKGROUND \ |
| 48 | - "/storage/app/run/com.huawei.launcher/launcher/assets/launcher/resources/base/media/background.png" | 102 | + "/storage/app/run/com.huawei.launcher/launcher/assets/launcher/resources/base/media/background_1920x1080.png" |
| 49 | #define RES_WEATHER "/storage/app/run/com.huawei.launcher/launcher/assets/launcher/resources/base/media/weather.png" | 103 | #define RES_WEATHER "/storage/app/run/com.huawei.launcher/launcher/assets/launcher/resources/base/media/weather.png" |
| 50 | #define FOND_PATH "SourceHanSansSC-Regular.otf" | 104 | #define FOND_PATH "SourceHanSansSC-Regular.otf" |
| 51 | 105 | ||
| @@ -80,8 +80,8 @@ void ViewGroupPage::CalculateAppPosition(AppInfo* pAppInfo, int16_t row, int16_t | |||
| 80 | int16_t w = viewGroup_->GetWidth(); | 80 | int16_t w = viewGroup_->GetWidth(); |
| 81 | 81 | ||
| 82 | const double scale = scale_; | 82 | const double scale = scale_; |
| 83 | - const int16_t blank1 = 10; | 83 | + const int16_t blank1 = 15; |
| 84 | - const int16_t blank2 = 30; | 84 | + const int16_t blank2 = 45; |
| 85 | const int16_t labelH = 2; | 85 | const int16_t labelH = 2; |
| 86 | int16_t width = static_cast<int16_t>(static_cast<double>(w) / static_cast<double>(scale * col_ + col_ + scale)); | 86 | int16_t width = static_cast<int16_t>(static_cast<double>(w) / static_cast<double>(scale * col_ + col_ + scale)); |
| 87 | int16_t heightB = width; | 87 | int16_t heightB = width; |
| @@ -91,10 +91,10 @@ void ViewGroupPage::CalculateAppPosition(AppInfo* pAppInfo, int16_t row, int16_t | |||
| 91 | int16_t xL = xB; | 91 | int16_t xL = xB; |
| 92 | int16_t yL = yB + heightB + blank1; | 92 | int16_t yL = yB + heightB + blank1; |
| 93 | 93 | ||
| 94 | - pAppInfo->buttonXY_.x = xB; | 94 | + pAppInfo->buttonXY_.x = xB + (width - APP_ICON_SIZE()) / 2; // 2: half of the app icon size |
| 95 | - pAppInfo->buttonXY_.y = yB; | 95 | + pAppInfo->buttonXY_.y = yB + (heightB - APP_ICON_SIZE()) / 2; // 2: half of the app icon size |
| 96 | - pAppInfo->buttonHV_.x = width; | 96 | + pAppInfo->buttonHV_.x = APP_ICON_SIZE(); |
| 97 | - pAppInfo->buttonHV_.y = heightB; | 97 | + pAppInfo->buttonHV_.y = APP_ICON_SIZE(); |
| 98 | 98 | ||
| 99 | pAppInfo->lableXY_.x = xL; | 99 | pAppInfo->lableXY_.x = xL; |
| 100 | pAppInfo->lableXY_.y = yL; | 100 | pAppInfo->lableXY_.y = yL; |
| @@ -111,7 +111,17 @@ void ViewGroupPage::SetUpApp(AppInfo *pAppInfo) | |||
| 111 | pAppInfo->SetButton(button); | 111 | pAppInfo->SetButton(button); |
| 112 | pAppInfo->SetLable(lable); | 112 | pAppInfo->SetLable(lable); |
| 113 | 113 | ||
| 114 | + /* Create a UIImageView for the app icon with proper scaling */ | ||
| 115 | + pAppInfo->iconView_ = new UIImageView(); | ||
| 116 | + pAppInfo->iconView_->SetPosition(pAppInfo->buttonXY_.x, pAppInfo->buttonXY_.y, | ||
| 117 | + pAppInfo->buttonHV_.x, pAppInfo->buttonHV_.y); | ||
| 118 | + pAppInfo->iconView_->SetAutoEnable(false); | ||
| 119 | + pAppInfo->iconView_->SetResizeMode(UIImageView::ImageResizeMode::COVER); | ||
| 120 | + pAppInfo->iconView_->SetSrc(pAppInfo->appIconDir_); | ||
| 121 | + pAppInfo->iconView_->SetTouchable(false); | ||
| 122 | + | ||
| 114 | pAppInfo->SetListener(pAppInfo); | 123 | pAppInfo->SetListener(pAppInfo); |
| 124 | + viewGroup_->Add(pAppInfo->iconView_); | ||
| 115 | viewGroup_->Add(button); | 125 | viewGroup_->Add(button); |
| 116 | viewGroup_->Add(lable); | 126 | viewGroup_->Add(lable); |
| 117 | viewGroup_->Invalidate(); | 127 | viewGroup_->Invalidate(); |
| @@ -159,6 +169,9 @@ bool ViewGroupPage::RemoveApp(const char* pAppName) | |||
| 159 | row_col_[app->data_->row_col_.x][app->data_->row_col_.y] = false; | 169 | row_col_[app->data_->row_col_.x][app->data_->row_col_.y] = false; |
| 160 | viewGroup_->Remove(app->data_->button_); | 170 | viewGroup_->Remove(app->data_->button_); |
| 161 | viewGroup_->Remove(app->data_->lable_); | 171 | viewGroup_->Remove(app->data_->lable_); |
| 172 | + if (app->data_->iconView_) { | ||
| 173 | + viewGroup_->Remove(app->data_->iconView_); | ||
| 174 | + } | ||
| 162 | viewGroup_->Invalidate(); | 175 | viewGroup_->Invalidate(); |
| 163 | appInfo_.Remove(app); | 176 | appInfo_.Remove(app); |
| 164 | return true; | 177 | return true; |
| @@ -45,7 +45,7 @@ executable("audio_capture_sample") { | |||
| 45 | "//foundation/multimedia/audio_lite/frameworks:audio_capturer_lite", | 45 | "//foundation/multimedia/audio_lite/frameworks:audio_capturer_lite", |
| 46 | "//third_party/bounds_checking_function:libsec_shared", | 46 | "//third_party/bounds_checking_function:libsec_shared", |
| 47 | ] | 47 | ] |
| 48 | - output_dir = "$root_out_dir/dev_tools" | 48 | + output_dir = "$root_out_dir/usr" |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | executable("player_sample") { | 51 | executable("player_sample") { |
| @@ -63,7 +63,7 @@ executable("player_sample") { | |||
| 63 | "//foundation/multimedia/media_lite/frameworks/player_lite:player_lite", | 63 | "//foundation/multimedia/media_lite/frameworks/player_lite:player_lite", |
| 64 | "//third_party/bounds_checking_function:libsec_shared", | 64 | "//third_party/bounds_checking_function:libsec_shared", |
| 65 | ] | 65 | ] |
| 66 | - output_dir = "$root_out_dir/dev_tools" | 66 | + output_dir = "$root_out_dir/usr" |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | lite_component("media_sample") { | 69 | lite_component("media_sample") { |
| @@ -284,6 +284,11 @@ int main(int argc, char *argv[]) | |||
| 284 | AudioCapturerInfo info; | 284 | AudioCapturerInfo info; |
| 285 | info.inputSource = AUDIO_MIC; | 285 | info.inputSource = AUDIO_MIC; |
| 286 | info.bitWidth = BIT_WIDTH_16; | 286 | info.bitWidth = BIT_WIDTH_16; |
| 287 | + // deviceId = "0", fix ipc deserialization parsing on the audio caputure server side | ||
| 288 | + info.deviceId = "0"; | ||
| 289 | + info.streamType = TYPE_MEDIA; | ||
| 290 | + info.deviceType = AUDIO_DEVICE_MIC_LOCAL; | ||
| 291 | + | ||
| 287 | AudioCodecFormat audioFormat = GetAudioFormat(); | 292 | AudioCodecFormat audioFormat = GetAudioFormat(); |
| 288 | if (audioFormat == FORMAT_BUTT) { | 293 | if (audioFormat == FORMAT_BUTT) { |
| 289 | return -1; | 294 | return -1; |
| @@ -305,7 +310,8 @@ int main(int argc, char *argv[]) | |||
| 305 | } | 310 | } |
| 306 | frameCount = audioCap.GetFrameCount(); | 311 | frameCount = audioCap.GetFrameCount(); |
| 307 | std::cout << "GetFrameCount " << frameCount << std::endl; | 312 | std::cout << "GetFrameCount " << frameCount << std::endl; |
| 308 | - g_audioSourceProcessInput.framesize = frameCount * 0x400; | 313 | + // framesize * 2 = 8192 |
| 314 | + g_audioSourceProcessInput.framesize = 8192; | ||
| 309 | g_audioSourceProcessInput.buffer = new uint8_t[g_audioSourceProcessInput.framesize]; | 315 | g_audioSourceProcessInput.buffer = new uint8_t[g_audioSourceProcessInput.framesize]; |
| 310 | 316 | ||
| 311 | RumCmd(audioCap); | 317 | RumCmd(audioCap); |
| @@ -360,8 +360,8 @@ static int SetSurface(TestSample &sample) | |||
| 360 | } | 360 | } |
| 361 | sample.surface->SetUserData("region_position_x", "0"); | 361 | sample.surface->SetUserData("region_position_x", "0"); |
| 362 | sample.surface->SetUserData("region_position_y", "0"); | 362 | sample.surface->SetUserData("region_position_y", "0"); |
| 363 | - sample.surface->SetUserData("region_width", "480"); | 363 | + sample.surface->SetUserData("region_width", "1920"); |
| 364 | - sample.surface->SetUserData("region_height", "480"); | 364 | + sample.surface->SetUserData("region_height", "1080"); |
| 365 | int32_t ret = sample.adapter->SetVideoSurface(sample.surface); | 365 | int32_t ret = sample.adapter->SetVideoSurface(sample.surface); |
| 366 | sample.setSurfaceCost = GetCurTimeMs() - begin; | 366 | sample.setSurfaceCost = GetCurTimeMs() - begin; |
| 367 | if (ret != 0) { | 367 | if (ret != 0) { |
| @@ -891,9 +891,16 @@ int main(int argc, char **argv) | |||
| 891 | PlayProcess(sample); | 891 | PlayProcess(sample); |
| 892 | 892 | ||
| 893 | sleep(1); | 893 | sleep(1); |
| 894 | + Format formatSetLayerPriority; | ||
| 895 | + int maxLayerPriority = 3; | ||
| 896 | + formatSetLayerPriority.PutIntValue(LAYER_PRIORITY, maxLayerPriority); | ||
| 897 | + sample.adapter->SetParameter(formatSetLayerPriority); | ||
| 894 | 898 | ||
| 895 | SampleCmd(sample); | 899 | SampleCmd(sample); |
| 896 | EndStreamSourceThread(sample); | 900 | EndStreamSourceThread(sample); |
| 901 | + int minLayerPriority = 0; | ||
| 902 | + formatSetLayerPriority.PutIntValue(LAYER_PRIORITY, minLayerPriority); | ||
| 903 | + sample.adapter->SetParameter(formatSetLayerPriority); | ||
| 897 | int32_t ret = sample.adapter->Stop(); | 904 | int32_t ret = sample.adapter->Stop(); |
| 898 | printf("Stop, ret:%d\n", ret); | 905 | printf("Stop, ret:%d\n", ret); |
| 899 | 906 | ||
| @@ -0,0 +1,111 @@ | |||
| 1 | +# Copyright (c) 2026 RKH Corp. | ||
| 2 | +# Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | +# you may not use this file except in compliance with the License. | ||
| 4 | +# You may obtain a copy of the License at | ||
| 5 | +# | ||
| 6 | +# http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | +# | ||
| 8 | +# Unless required by applicable law or agreed to in writing, software | ||
| 9 | +# distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | +# See the License for the specific language governing permissions and | ||
| 12 | +# limitations under the License. | ||
| 13 | + | ||
| 14 | +import("//build/lite/config/hap_pack.gni") | ||
| 15 | + | ||
| 16 | +config("hilog_dir") { | ||
| 17 | + include_dirs = | ||
| 18 | + [ "//base/hiviewdfx/hilog_lite/interfaces/native/innerkits/hilog/" ] | ||
| 19 | +} | ||
| 20 | +config("hilog_lite_dir") { | ||
| 21 | + include_dirs = | ||
| 22 | + [ "//base/hiviewdfx/hilog_lite/interfaces/native/kits/hilog_lite/" ] | ||
| 23 | +} | ||
| 24 | + | ||
| 25 | +shared_library("recorder") { | ||
| 26 | + sources = [ | ||
| 27 | + "src/recorder_ability.cpp", | ||
| 28 | + "src/recorder_ability_main_slice.cpp", | ||
| 29 | + "src/recorder_list_adapter.cpp", | ||
| 30 | + "src/media_utils.cpp", | ||
| 31 | + ] | ||
| 32 | + | ||
| 33 | + include_dirs = [ | ||
| 34 | + "include", | ||
| 35 | + "..", | ||
| 36 | + "${aafwk_lite_path}/interfaces/kits/ability_lite", | ||
| 37 | + "${appexecfwk_lite_path}/interfaces/kits/bundle_lite", | ||
| 38 | + "${aafwk_lite_path}/interfaces/kits/want_lite", | ||
| 39 | + "//foundation/multimedia/media_lite/interfaces/kits/player_lite", | ||
| 40 | + ] | ||
| 41 | + | ||
| 42 | + deps = [ | ||
| 43 | + "${aafwk_lite_path}/frameworks/ability_lite:aafwk_abilitykit_lite", | ||
| 44 | + "${appexecfwk_lite_path}/frameworks/bundle_lite:bundle", | ||
| 45 | + "//foundation/arkui/ui_lite:ui_lite", | ||
| 46 | + "//foundation/distributeddatamgr/kv_store/interfaces/inner_api/kv_store:kv_store", | ||
| 47 | + "//foundation/graphic/graphic_utils_lite:utils_lite", | ||
| 48 | + "//foundation/graphic/surface_lite", | ||
| 49 | + "//foundation/multimedia/media_lite/frameworks/player_lite:player_lite", | ||
| 50 | + "//foundation/multimedia/media_lite/frameworks/recorder_lite:recorder_lite", | ||
| 51 | + "//foundation/systemabilitymgr/samgr_lite/samgr:samgr", | ||
| 52 | + ] | ||
| 53 | + | ||
| 54 | + if (defined(ohos_lite)) { | ||
| 55 | + if (ohos_kernel_type == "liteos_m") { | ||
| 56 | + configs += [ ":hilog_lite_dir" ] | ||
| 57 | + deps += [ "//base/hiviewdfx/hilog_lite/frameworks/mini:hilog_lite" ] | ||
| 58 | + } else if (ohos_kernel_type == "liteos_a") { | ||
| 59 | + configs += [ ":hilog_dir" ] | ||
| 60 | + deps += [ | ||
| 61 | + "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared", | ||
| 62 | + "//third_party/bounds_checking_function:libsec_shared", | ||
| 63 | + ] | ||
| 64 | + } | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + cflags = [ "-Wall" ] | ||
| 68 | + cflags_cc = cflags | ||
| 69 | + ldflags = [ "-shared" ] | ||
| 70 | + ldflags += [ "-lstdc++" ] | ||
| 71 | + ldflags += [ "-lpthread" ] | ||
| 72 | + ldflags += [ "-L$ohos_root_path/sysroot/usr/lib" ] | ||
| 73 | + ldflags += [ "-Wl,-rpath-link=$ohos_root_path/sysroot/usr/lib" ] | ||
| 74 | + ldflags += [ | ||
| 75 | + "-lui", | ||
| 76 | + "-lsurface", | ||
| 77 | + "-lplayer_lite", | ||
| 78 | + "-lability", | ||
| 79 | + ] | ||
| 80 | + | ||
| 81 | + defines = [ | ||
| 82 | + "OHOS_APPEXECFWK_BMS_BUNDLEMANAGER", | ||
| 83 | + "ENABLE_WINDOW=1", | ||
| 84 | + "ABILITY_WINDOW_SUPPORT", | ||
| 85 | + "HILOG_ENABLE", | ||
| 86 | + # "USE_RECORDER_FD" | ||
| 87 | + "USE_RECORDER_API", | ||
| 88 | + "USE_PLAYER_API" | ||
| 89 | + ] | ||
| 90 | +} | ||
| 91 | + | ||
| 92 | +hap_pack("recorder_hap") { | ||
| 93 | + deps = [ ":recorder" ] | ||
| 94 | + mode = "hap" | ||
| 95 | + json_path = "config.json" | ||
| 96 | + ability_so_path = "$root_out_dir/librecorder.so" | ||
| 97 | + force = "true" | ||
| 98 | + cert_profile = "cert/recorder_AppProvision_Release.p7b" | ||
| 99 | + resources_path = "resources" | ||
| 100 | + hap_name = "recorder" | ||
| 101 | + privatekey = "HOS Application Provision Release" | ||
| 102 | +} | ||
| 103 | + | ||
| 104 | +group("recorder_grop") { | ||
| 105 | + deps = [] | ||
| 106 | + if (defined(media_interface_upgrade)) { | ||
| 107 | + deps += [ | ||
| 108 | + ":recorder_hap", | ||
| 109 | + ] | ||
| 110 | + } | ||
| 111 | +} | ||
Binary files do not support preview
| @@ -0,0 +1,89 @@ | |||
| 1 | +{ | ||
| 2 | + "app": { | ||
| 3 | + "bundleName": "com.huawei.recorder", | ||
| 4 | + "vendor": "huawei", | ||
| 5 | + "version": { | ||
| 6 | + "code": 1, | ||
| 7 | + "name": "1.0" | ||
| 8 | + }, | ||
| 9 | + "apiVersion": { | ||
| 10 | + "compatible": 3, | ||
| 11 | + "target": 4 | ||
| 12 | + } | ||
| 13 | + }, | ||
| 14 | + "deviceConfig": { | ||
| 15 | + "default": { | ||
| 16 | + } | ||
| 17 | + }, | ||
| 18 | + "module": { | ||
| 19 | + "package": "com.huawei.recorder", | ||
| 20 | + "name": ".MyHarmonyAbilityPackage", | ||
| 21 | + "deviceType": [ | ||
| 22 | + "phone", | ||
| 23 | + "tv", | ||
| 24 | + "tablet", | ||
| 25 | + "pc", | ||
| 26 | + "car", | ||
| 27 | + "smartWatch", | ||
| 28 | + "sportsWatch", | ||
| 29 | + "smartVision" | ||
| 30 | + ], | ||
| 31 | + "distro": { | ||
| 32 | + "deliveryWithInstall": true, | ||
| 33 | + "moduleName": "recorder", | ||
| 34 | + "moduleType": "entry" | ||
| 35 | + }, | ||
| 36 | + "abilities": [ | ||
| 37 | + { | ||
| 38 | + "name": "RecorderAbility", | ||
| 39 | + "icon": "assets/recorder/resources/drawable/recorder.png", | ||
| 40 | + "label": "test app 1", | ||
| 41 | + "launchType": "standard", | ||
| 42 | + "type": "page", | ||
| 43 | + "visible": true | ||
| 44 | + } | ||
| 45 | + ], | ||
| 46 | + "reqPermissions": [ | ||
| 47 | + { | ||
| 48 | + "name": "ohos.permission.MODIFY_AUDIO_SETTINGS", | ||
| 49 | + "reason": "SYSTEM_GRANT", | ||
| 50 | + "usedScene": { | ||
| 51 | + "ability": [ | ||
| 52 | + ".FormAbility" | ||
| 53 | + ], | ||
| 54 | + "when": "inuse" | ||
| 55 | + } | ||
| 56 | + }, | ||
| 57 | + { | ||
| 58 | + "name": "ohos.permission.READ_MEDIA", | ||
| 59 | + "reason": "USER_GRANT", | ||
| 60 | + "usedScene": { | ||
| 61 | + "ability": [ | ||
| 62 | + ".FormAbility" | ||
| 63 | + ], | ||
| 64 | + "when": "inuse" | ||
| 65 | + } | ||
| 66 | + }, | ||
| 67 | + { | ||
| 68 | + "name": "ohos.permission.READ_MEDIA_AUDIO", | ||
| 69 | + "reason": "USER_GRANT", | ||
| 70 | + "usedScene": { | ||
| 71 | + "ability": [ | ||
| 72 | + ".FormAbility" | ||
| 73 | + ], | ||
| 74 | + "when": "inuse" | ||
| 75 | + } | ||
| 76 | + }, | ||
| 77 | + { | ||
| 78 | + "name": "ohos.permission.MICROPHONE", | ||
| 79 | + "reason": "USER_GRANT", | ||
| 80 | + "usedScene": { | ||
| 81 | + "ability": [ | ||
| 82 | + ".FormAbility" | ||
| 83 | + ], | ||
| 84 | + "when": "inuse" | ||
| 85 | + } | ||
| 86 | + } | ||
| 87 | + ] | ||
| 88 | + } | ||
| 89 | +} | ||
| @@ -0,0 +1,68 @@ | |||
| 1 | +/* | ||
| 2 | + * Copyright (c) 2026 RKH Corp. | ||
| 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 | + */ | ||
| 15 | + | ||
| 16 | +#ifndef OHOS_EVENT_LISTENER_H | ||
| 17 | +#define OHOS_EVENT_LISTENER_H | ||
| 18 | + | ||
| 19 | +#include <components/ui_view.h> | ||
| 20 | +#include <functional> | ||
| 21 | +#include <utility> | ||
| 22 | + | ||
| 23 | +namespace OHOS { | ||
| 24 | +using OnEventFunc = std::function<bool(UIView &view, const Event &event)>; | ||
| 25 | + | ||
| 26 | +class EventListener : | ||
| 27 | + public UIView::OnClickListener, | ||
| 28 | + public UIView::OnLongPressListener { | ||
| 29 | +public: | ||
| 30 | + EventListener() = delete; | ||
| 31 | + ~EventListener() override = default; | ||
| 32 | + | ||
| 33 | + EventListener(OnEventFunc onClick, OnEventFunc onLongPress) | ||
| 34 | + { | ||
| 35 | + onClick_ = std::move(onClick); | ||
| 36 | + onLongPress_ = std::move(onLongPress); | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + bool OnClick(UIView& view, const ClickEvent &event) override | ||
| 40 | + { | ||
| 41 | + if (!onClick_) { | ||
| 42 | + return false; | ||
| 43 | + } | ||
| 44 | + UIView *currentView = &view; | ||
| 45 | + if (currentView == nullptr) { | ||
| 46 | + return false; | ||
| 47 | + } | ||
| 48 | + return onClick_(*currentView, event); | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + bool OnLongPress(UIView& view, const LongPressEvent &event) override | ||
| 52 | + { | ||
| 53 | + if (!onLongPress_) { | ||
| 54 | + return false; | ||
| 55 | + } | ||
| 56 | + UIView *currentView = &view; | ||
| 57 | + if (currentView == nullptr) { | ||
| 58 | + return false; | ||
| 59 | + } | ||
| 60 | + return onLongPress_(*currentView, event); | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | +private: | ||
| 64 | + OnEventFunc onClick_ {}; | ||
| 65 | + OnEventFunc onLongPress_ {}; | ||
| 66 | +}; | ||
| 67 | +} | ||
| 68 | +#endif // OHOS_EVENT_LISTENER_H | ||
| @@ -0,0 +1,80 @@ | |||
| 1 | +/* | ||
| 2 | + * Copyright (c) 2026 RKH Corp. | ||
| 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 | + */ | ||
| 15 | + | ||
| 16 | +#ifndef OHOS_MEDIA_UTILS_H | ||
| 17 | +#define OHOS_MEDIA_UTILS_H | ||
| 18 | + | ||
| 19 | +#include <memory> | ||
| 20 | + | ||
| 21 | +#ifdef USE_RECORDER_API | ||
| 22 | +#include <recorder.h> | ||
| 23 | +#endif | ||
| 24 | +#ifdef USE_PLAYER_API | ||
| 25 | +#include <player.h> | ||
| 26 | +#endif | ||
| 27 | + | ||
| 28 | +namespace OHOS { | ||
| 29 | +class MediaUtils { | ||
| 30 | +public: | ||
| 31 | + ~MediaUtils(); | ||
| 32 | + | ||
| 33 | + // Recorder | ||
| 34 | +#ifdef USE_RECORDER_API | ||
| 35 | + bool SetRecorderCallback(Media::RecorderCallback* recorderCallback); | ||
| 36 | +#endif | ||
| 37 | + bool StartRecord(); | ||
| 38 | + bool StopRecord(); | ||
| 39 | + | ||
| 40 | + // Player | ||
| 41 | +#ifdef USE_PLAYER_API | ||
| 42 | + bool SetPlayerCallback(Media::PlayerCallback* playerCallback); | ||
| 43 | +#endif | ||
| 44 | + bool StartPlay(const char* filePath); | ||
| 45 | + bool PausePlay(); | ||
| 46 | + bool StopPlay(); | ||
| 47 | + | ||
| 48 | +private: | ||
| 49 | + bool InitRecorder(); | ||
| 50 | + bool CloseRecorder(); | ||
| 51 | + bool MoveFiles(); | ||
| 52 | + bool EnsureRecorderDirectory(); | ||
| 53 | + bool StartRecorderService(); | ||
| 54 | + | ||
| 55 | + bool InitPlayer(const char* filePath); | ||
| 56 | + bool ClosePlayer(); | ||
| 57 | + | ||
| 58 | +private: | ||
| 59 | +#ifdef USE_RECORDER_API | ||
| 60 | + std::shared_ptr<Media::Recorder> recorder_; | ||
| 61 | + Media::RecorderCallback* recorderCallback_ { nullptr }; | ||
| 62 | + std::shared_ptr<Media::RecorderCallback> recorderCallbackPtr_; | ||
| 63 | +#endif | ||
| 64 | + | ||
| 65 | +#ifdef USE_PLAYER_API | ||
| 66 | + std::shared_ptr<Media::Player> player_; | ||
| 67 | + Media::PlayerCallback* playerCallback_ { nullptr }; | ||
| 68 | + std::shared_ptr<Media::PlayerCallback> playerCallbackPtr_; | ||
| 69 | +#endif | ||
| 70 | +#ifdef USE_RECORDER_FD | ||
| 71 | + int32_t recordFd_ = -1; | ||
| 72 | +#endif | ||
| 73 | + | ||
| 74 | + bool recording_ = false; | ||
| 75 | + bool playing_ = false; | ||
| 76 | + bool paused_ = false; | ||
| 77 | +}; | ||
| 78 | +} | ||
| 79 | + | ||
| 80 | +#endif // OHOS_RECORDER_ABILITY_H | ||
| @@ -0,0 +1,32 @@ | |||
| 1 | +/* | ||
| 2 | + * Copyright (c) 2026 RKH Corp. | ||
| 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 | + */ | ||
| 15 | + | ||
| 16 | +#ifndef OHOS_RECORDER_ABILITY_H | ||
| 17 | +#define OHOS_RECORDER_ABILITY_H | ||
| 18 | + | ||
| 19 | +#include <ability_loader.h> | ||
| 20 | + | ||
| 21 | +namespace OHOS { | ||
| 22 | +class RecorderAbility : public Ability { | ||
| 23 | +protected: | ||
| 24 | + void OnStart(const Want &want) override; | ||
| 25 | + void OnInactive() override; | ||
| 26 | + void OnActive(const Want &want) override; | ||
| 27 | + void OnBackground() override; | ||
| 28 | + void OnStop() override; | ||
| 29 | +}; | ||
| 30 | +} | ||
| 31 | + | ||
| 32 | +#endif // OHOS_RECORDER_ABILITY_H | ||
| @@ -0,0 +1,120 @@ | |||
| 1 | +/* | ||
| 2 | + * Copyright (c) 2026 RKH Corp. | ||
| 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 | + */ | ||
| 15 | + | ||
| 16 | +#ifndef OHOS_RECORDER_ABILITY_MAIN_SLICE_H | ||
| 17 | +#define OHOS_RECORDER_ABILITY_MAIN_SLICE_H | ||
| 18 | + | ||
| 19 | +#include <ability_slice.h> | ||
| 20 | +#include <components/ui_image_view.h> | ||
| 21 | +#include <components/ui_label.h> | ||
| 22 | +#include <components/ui_list.h> | ||
| 23 | +#include <components/abstract_adapter.h> | ||
| 24 | +#include <event_listener.h> | ||
| 25 | + | ||
| 26 | +#include "recorder_config.h" | ||
| 27 | +#include "recorder_list_adapter.h" | ||
| 28 | +#include "media_utils.h" | ||
| 29 | +#include "task_helper.h" | ||
| 30 | + | ||
| 31 | +namespace OHOS { | ||
| 32 | +class RecorderAbilityMainSlice : public AbilitySlice, Media::PlayerCallback, Media::RecorderCallback { | ||
| 33 | +public: | ||
| 34 | + RecorderAbilityMainSlice() = default; | ||
| 35 | + ~RecorderAbilityMainSlice() override; | ||
| 36 | + | ||
| 37 | +public: | ||
| 38 | + // Media::PlayerCallback overrides | ||
| 39 | + void OnPlaybackComplete() override; | ||
| 40 | + void OnError(int32_t errorType, int32_t errorCode) override; | ||
| 41 | + void OnInfo(int type, int extra) override; | ||
| 42 | + void OnVideoSizeChanged(int width, int height) override {} | ||
| 43 | + void OnRewindToComplete() override {} | ||
| 44 | +protected: | ||
| 45 | + void OnStart(const Want &want) override; | ||
| 46 | + void OnInactive() override; | ||
| 47 | + void OnActive(const Want &want) override; | ||
| 48 | + void OnBackground() override; | ||
| 49 | + void OnStop() override; | ||
| 50 | + | ||
| 51 | +private: | ||
| 52 | + void InitTitle(); | ||
| 53 | + void InitRecordList(); | ||
| 54 | + void InitRecordCtrl(); | ||
| 55 | + void InitRecordLabels(); | ||
| 56 | + void InitRecordButtons(); | ||
| 57 | + void InitRecordListeners(); | ||
| 58 | + void AddRecordControlsToRoot(); | ||
| 59 | + bool InitImagePath(char* absolutePath, const char* pathHeader, const char* resourcePath, const char* errorTag); | ||
| 60 | + void InitRootView(); | ||
| 61 | + bool InitIconPaths(const char* pathHeader); | ||
| 62 | + void Start(); | ||
| 63 | + void Stop(); | ||
| 64 | + void Pause(); | ||
| 65 | + void Resume(); | ||
| 66 | + void Cancel(); | ||
| 67 | + | ||
| 68 | + // recorder timer | ||
| 69 | + void StartTimer(); | ||
| 70 | + void PauseTimer(); | ||
| 71 | + void ResumeTimer(); | ||
| 72 | + void StopTimer(); | ||
| 73 | + void UpdateRecordTime(); | ||
| 74 | + void UpdateDurationLabel(); | ||
| 75 | + | ||
| 76 | + void ReloadItems(); | ||
| 77 | + | ||
| 78 | + void OnItemPlay(int16_t index, const RecordItem& item); | ||
| 79 | + void OnItemDelete(int16_t index, const RecordItem& item); | ||
| 80 | + | ||
| 81 | + RootView* rootView_ { nullptr }; | ||
| 82 | + UIViewGroup* titleBar_ { nullptr }; | ||
| 83 | + UIImageView* backButton_ { nullptr }; | ||
| 84 | + EventListener* backButtonListener_ { nullptr }; | ||
| 85 | + UILabel* titleLabel_ { nullptr }; | ||
| 86 | + UILabel* noticeLabel_ { nullptr }; | ||
| 87 | + UILabel* durationLabel_ { nullptr }; | ||
| 88 | + UIImageView* fsImageView_ { nullptr }; | ||
| 89 | + | ||
| 90 | + UIImageView* startButton_ { nullptr }; // start/stop | ||
| 91 | + UIImageView* pauseButton_ { nullptr }; // pause/resume | ||
| 92 | + UIImageView* cancelButton_ { nullptr }; | ||
| 93 | + | ||
| 94 | + EventListener* startButtonListener_ { nullptr }; | ||
| 95 | + EventListener* stopButtonListener_ { nullptr }; | ||
| 96 | + EventListener* pauseButtonListener_ { nullptr }; | ||
| 97 | + EventListener* resumeButtonListener_ { nullptr }; | ||
| 98 | + EventListener* cancelButtonListener_ { nullptr }; | ||
| 99 | + | ||
| 100 | + UILabel* listLabel_ { nullptr }; | ||
| 101 | + UIList* list_ { nullptr }; | ||
| 102 | + RecorderListAdapter* adapter_ { nullptr }; | ||
| 103 | + std::string durationTime_; | ||
| 104 | + MediaUtils mediaUtils_; | ||
| 105 | + | ||
| 106 | + // recorder timer | ||
| 107 | + std::shared_ptr<Task> recordTimeUpdateTask_; | ||
| 108 | + uint32_t lastRecordTime_; | ||
| 109 | + uint32_t recordDuration_; | ||
| 110 | + | ||
| 111 | + char backIconAbsolutePath[MAX_PATH_LENGTH] = { 0 }; | ||
| 112 | + char fsIconAbsolutePath[MAX_PATH_LENGTH] = { 0 }; | ||
| 113 | + char startIconAbsolutePath[MAX_PATH_LENGTH] = { 0 }; | ||
| 114 | + char stopIconAbsolutePath[MAX_PATH_LENGTH] = { 0 }; | ||
| 115 | + char pauseIconAbsolutePath[MAX_PATH_LENGTH] = { 0 }; | ||
| 116 | + char resumeIconAbsolutePath[MAX_PATH_LENGTH] = { 0 }; | ||
| 117 | + char cancelIconAbsolutePath[MAX_PATH_LENGTH] = { 0 }; | ||
| 118 | +}; | ||
| 119 | +} | ||
| 120 | +#endif // OHOS_RECORDER_ABILITY_MAIN_SLICE_H | ||
| @@ -0,0 +1,52 @@ | |||
| 1 | +/* | ||
| 2 | + * Copyright (c) 2026 RKH Corp. | ||
| 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 | + */ | ||
| 15 | + | ||
| 16 | +#ifndef OHOS_RECORDER_ABILITY_SLICE_H | ||
| 17 | +#define OHOS_RECORDER_ABILITY_SLICE_H | ||
| 18 | + | ||
| 19 | +#include <ability_slice.h> | ||
| 20 | +#include <components/root_view.h> | ||
| 21 | +#include <components/ui_label.h> | ||
| 22 | +#include <components/ui_image_view.h> | ||
| 23 | +#include <event_listener.h> | ||
| 24 | + | ||
| 25 | +#include "recorder_config.h" | ||
| 26 | + | ||
| 27 | +namespace OHOS { | ||
| 28 | +class RecorderAbilitySlice : public AbilitySlice { | ||
| 29 | +public: | ||
| 30 | + RecorderAbilitySlice() = default; | ||
| 31 | + ~RecorderAbilitySlice() override; | ||
| 32 | +protected: | ||
| 33 | + void OnStart(const Want &want) override; | ||
| 34 | + void OnInactive() override; | ||
| 35 | + void OnActive(const Want &want) override; | ||
| 36 | + void OnBackground() override; | ||
| 37 | + void OnStop() override; | ||
| 38 | + | ||
| 39 | +private: | ||
| 40 | + void SetUpRootView(); | ||
| 41 | + void SetUpBackArea(); | ||
| 42 | + | ||
| 43 | +private: | ||
| 44 | + RootView* rootView_ { nullptr }; | ||
| 45 | + UIViewGroup* backArea_ { nullptr }; | ||
| 46 | + UIImageView* backIcon_ { nullptr }; | ||
| 47 | + UILabel* titleLabel_ { nullptr }; | ||
| 48 | + EventListener* backIconListener_ { nullptr }; | ||
| 49 | + char backIconAbsolutePath[MAX_PATH_LENGTH] = { 0 }; | ||
| 50 | +}; | ||
| 51 | +} // namespace OHOS | ||
| 52 | +#endif // OHOS_RECORDER_ABILITY_SLICE_H | ||