DEV Community

Cover image for Hide Status Bar, Launch Pop-ups in Methods, System Screen Brightness Monitoring
kouwei qing
kouwei qing

Posted on

Hide Status Bar, Launch Pop-ups in Methods, System Screen Brightness Monitoring

[Daily HarmonyOS Next Knowledge] Hide Status Bar, Launch Pop-ups in Methods, System Screen Brightness Monitoring, Photo Zooming and Dragging, Prevent Screenshots of Input Interfaces

1. How to hide the status bar when pulling down in HarmonyOS?

To always hide the status bar, you can set relevant properties to transparent via the setWindowSystemBarProperties interface.

Reference document: https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-window-V5#setwindowsystembarproperties9

setWindowSystemBarProperties(systemBarProperties: SystemBarProperties): Promise<void>

Sets the properties of the main window's three-key navigation bar and status bar using a Promise asynchronous callback.

This interface does not take effect on 2in1 devices. On other devices, it does not take effect immediately in split-screen mode (i.e., window mode is window.WindowStatusType.SPLIT_SCREEN), free-floating window mode (i.e., window mode is window.WindowStatusType.FLOATING), or free multi-window mode (enabled by clicking the free multi-window button in the device control center). It only takes effect when entering the full-screen main window.

2. How to launch a custom pop-up in a class or function in HarmonyOS? The built-in alert works, but custom prompts cannot be used.

Please refer to the following code example:

Main page

// Set the builder in @entry first, then directly call showTest  
import { customDialogBuilder, changeDialogBuilder, MyShowTest } from ‘…/pages/Page  
let myShowTest = new MyShowTest()  
@Entry  
@Component  
struct Index {  
  @State message: string = Hello World  
  onPageShow(): void {  
    changeDialogBuilder(customDialogBuilder.bind(this))  
  }  

  build() {  
    Row() {  
      Column() {  
        Text(this.message)  
          .fontSize(50)  
          .fontWeight(FontWeight.Bold)  
          .onClick(() => {  
            myShowTest.showTest()  
          })  
      }  
      .width(100%)  
    }  
    .height(100%)  
  }  
}  
Enter fullscreen mode Exit fullscreen mode

Custom class

// custom_dialog.ets  
import promptAction from @ohos.promptAction  
let myDialogBuilder: CustomBuilder;  
let customDialogId: number = 0  

@Builder  
export function customDialogBuilder() {  
  Column() {  
    Text(Custom dialog Message).fontSize(10)  
    Row() {  
      Button(Confirm).onClick(() => {  
        promptAction.closeCustomDialog(customDialogId)  
      })  
      Blank().width(50)  
      Button(Cancel).onClick(() => {  
        promptAction.closeCustomDialog(customDialogId)  
      })  
    }  
  }.height(200).padding(5)  
}  

export function changeDialogBuilder(builder: CustomBuilder) {  
  myDialogBuilder = builder  
}  

export class MyShowTest{  
  showTest() {  
    if (myDialogBuilder === undefined) {  
      return  
    }  
    promptAction.openCustomDialog({  
      builder: myDialogBuilder  
    }).then((dialogId: number) => {  
      customDialogId = dialogId  
    })  
  }  
}  
Enter fullscreen mode Exit fullscreen mode

Modify customDialogBuilder() to the following code (add backGroundColor and width properties to Column) to customize the pop-up background color:

@Builder  
export function customDialogBuilder() {  
  Column() {  
    Text(Custom dialog Message).fontSize(10)  
    Row() {  
      Button(Confirm).onClick(() => {  
        promptAction.closeCustomDialog(customDialogId)  
      })  
      Blank().width(50)  
      Button(Cancel).onClick(() => {  
        promptAction.closeCustomDialog(customDialogId)  
      })  
    }  
  }.height(200).padding(5).backgroundColor(Color.Green).width(100%)  
}  
Enter fullscreen mode Exit fullscreen mode

Using backgroundImage and backgroundImageSize(ImageSize.Cover) instead of backgroundColor can achieve similar effects, but the pop-up width cannot be changed currently.

3. How to monitor the system screen brightness in HarmonyOS? After setting the brightness, the brightness settings in the system control center no longer take effect.

https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-window-V5#ZH-CN_TOPIC_0000001884757714__setwindowbrightness9

Allows the application window to set the screen brightness value using a callback asynchronous callback.

Current screen brightness specification: When the window sets the screen brightness, the control center cannot adjust the system screen brightness. After the window restores the default system brightness, the control center can adjust the system brightness. The brightness value is a floating-point number, ranging from [0.0, 1.0] or -1.0. 1.0 represents the brightest, and -1.0 represents the default brightness.

4. How to achieve the effect of dragging and browsing photos after zooming in, similar to the system photo album in HarmonyOS?

To implement a zooming and browsing effect for images, it is found that using scale to zoom the image can only enlarge the visible part and cannot drag to browse areas outside the image container's visible area. Setting the image component size to achieve zooming cannot center the anchor point area. What solution should be adopted to achieve the drag-and-browse effect after zooming in, similar to the system photo album?

The current codelab "Electronic Album" includes scenarios for image zooming and dragging.

Reference: https://developer.huawei.com/consumer/cn/codelabsPortal/carddetails/tutorials_NEXT-ElectronicAlbum

In addition, third-party libraries are available: https://gitee.com/openharmony-sig/ohos_image_view_zoom

5. How to prevent screenshot or screen recording of the password input interface in HarmonyOS?

Set the setWindowPrivacyMode under window to privacy mode, which prevents the window content from being screenshot or screen recorded. For specific details, refer to the official document: https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-window-V5#setwindowprivacymode9

setWindowPrivacyMode(isPrivacyMode: boolean, callback: AsyncCallback<void>): void

Sets whether the window is in privacy mode using a callback asynchronous callback. The content of a window set to privacy mode cannot be screenshot or screen recorded. This interface can be used in scenarios where screenshot/screen recording needs to be prohibited.

Top comments (0)