From 43574320e22735145e5dc1071a70a5f42b566536 Mon Sep 17 00:00:00 2001 From: lvyuanyuan Date: Wed, 20 Aug 2025 16:17:01 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=84=E8=8C=83=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entry/src/main/ets/modules/Crease.ets | 11 +++--- .../entry/src/main/ets/modules/Folder.ets | 37 ++++++++++--------- .../main/ets/modules/NavigationComponent.ets | 20 +++++----- .../entry/src/main/ets/modules/PinchImage.ets | 14 +++---- .../src/main/ets/modules/PopupComponent.ets | 23 ++++++------ .../entry/src/main/ets/modules/Scroll.ets | 2 +- .../src/main/ets/modules/ScrollParent.ets | 4 +- .../entry/src/main/ets/utils/source_add1.ets | 3 +- .../src/main/ets/view/AdjustContentView.ets | 12 ++++-- .../entry/src/main/ets/view/WorkerPort.ets | 25 ++++++++----- .../entry/src/main/ets/view/newBuffer1.ets | 31 +++++++++------- 11 files changed, 97 insertions(+), 85 deletions(-) diff --git a/FoldableGuilde/entry/src/main/ets/modules/Crease.ets b/FoldableGuilde/entry/src/main/ets/modules/Crease.ets index fec47eb8..e168b3a5 100644 --- a/FoldableGuilde/entry/src/main/ets/modules/Crease.ets +++ b/FoldableGuilde/entry/src/main/ets/modules/Crease.ets @@ -1,18 +1,17 @@ // [Start crease] -import display from '@ohos.display'; -import { Callback } from '@ohos.base'; -@Entry +import { display } from '@kit.ArkUI'; + @Component export struct Crease { - @State status: string = "1" + @State status: string = '1'; // Register for monitoring at startup aboutToAppear() { let callback: Callback = (data: display.FoldStatus) => { console.info('Listening enabled. Data: ' + JSON.stringify(data)); // Get the folding crease area, the left and top attributes are the left and upper boundaries of the rectangular area, and the width and height attributes are the width and height of the rectangular area。 - this.status = data.toString() + " " + display.getCurrentFoldCreaseRegion().creaseRects[0].left + " " + display.getCurrentFoldCreaseRegion().creaseRects[0].top - + " " + display.getCurrentFoldCreaseRegion().creaseRects[0].width + " " + display.getCurrentFoldCreaseRegion().creaseRects[0].height; + this.status = data.toString() + ' ' + display.getCurrentFoldCreaseRegion().creaseRects[0].left + ' ' + display.getCurrentFoldCreaseRegion().creaseRects[0].top + + ' ' + display.getCurrentFoldCreaseRegion().creaseRects[0].width + ' ' + display.getCurrentFoldCreaseRegion().creaseRects[0].height; }; try { display.on('foldStatusChange', callback); diff --git a/FoldableGuilde/entry/src/main/ets/modules/Folder.ets b/FoldableGuilde/entry/src/main/ets/modules/Folder.ets index e92c284c..042a4f86 100644 --- a/FoldableGuilde/entry/src/main/ets/modules/Folder.ets +++ b/FoldableGuilde/entry/src/main/ets/modules/Folder.ets @@ -1,36 +1,36 @@ // [Start Folder] -@Entry @Component export struct Folder { - @State len_wid: number = 480 - @State w: string = "40%" + @State len_wid: number = 480; + @State w: string = '40%'; + build() { Column() { // UpperItems puts the required id hovering to the upper half of the screen into upperItems, and the other components will be stacked in the lower half of the screen - FolderStack({ upperItems: ["upperitemsId"] }) { + FolderStack({ upperItems: ['upperitemsId'] }) { // This Column will automatically move up to the upper half of the screen Column() { - Text("video zone").height("100%").width("100%").textAlign(TextAlign.Center).fontSize(25) - }.backgroundColor(Color.Pink).width("100%").height("100%").id("upperitemsId") + Text('video zone').height('100%').width('100%').textAlign(TextAlign.Center).fontSize(25) + }.backgroundColor(Color.Pink).width('100%').height('100%').id('upperitemsId') // The following two Column are stacked in the lower half screen area Column() { - Text("video title") - .width("100%") + Text('video title') + .width('100%') .height(50) .textAlign(TextAlign.Center) .backgroundColor(Color.Red) .fontSize(25) - }.width("100%").height("100%").justifyContent(FlexAlign.Start) + }.width('100%').height('100%').justifyContent(FlexAlign.Start) Column() { - Text("video bar") - .width("100%") + Text('video bar') + .width('100%') .height(50) .textAlign(TextAlign.Center) .backgroundColor(Color.Red) .fontSize(25) - }.width("100%").height("100%").justifyContent(FlexAlign.End) + }.width('100%').height('100%').justifyContent(FlexAlign.End) } .backgroundColor(Color.Yellow) // Whether to start the dynamic effect @@ -40,26 +40,27 @@ export struct Folder { // FolderStack callback callback when the folding state changes .onFolderStateChange((msg) => { if (msg.foldStatus === FoldStatus.FOLD_STATUS_EXPANDED) { - console.info("The device is currently in the expanded state") + console.info('The device is currently in the expanded state'); } else if (msg.foldStatus === FoldStatus.FOLD_STATUS_HALF_FOLDED) { - console.info("The device is currently in the half folded state") + console.info('The device is currently in the half folded state'); } else { // ............. } }) // If the folderStack does not fill the full screen of the page, it can be used as an ordinary Stack .alignContent(Alignment.Bottom) - .height("100%") - .width("100%") + .height('100%') + .width('100%') .borderWidth(1) .backgroundColor(Color.Yellow) } - .height("100%") - .width("100%") + .height('100%') + .width('100%') .borderWidth(1) .backgroundColor(Color.Pink) .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.BOTTOM]) } } + // [End Folder] \ No newline at end of file diff --git a/FoldableGuilde/entry/src/main/ets/modules/NavigationComponent.ets b/FoldableGuilde/entry/src/main/ets/modules/NavigationComponent.ets index 0639dbde..51c837bb 100644 --- a/FoldableGuilde/entry/src/main/ets/modules/NavigationComponent.ets +++ b/FoldableGuilde/entry/src/main/ets/modules/NavigationComponent.ets @@ -1,8 +1,7 @@ // [Start NavigationComponent] -@Entry @Component export struct NavigationComponent { - @State TooTmp: ToolbarItem = {'value': "func", 'action': ()=> {}} + @State TooTmp: ToolbarItem = {'value': 'func', 'action': ()=> {}}; private arr: number[] = [1, 2, 3]; build() { @@ -10,12 +9,12 @@ export struct NavigationComponent { // Root view container for routing navigation Navigation() { List({ space: 12 }) { - ForEach(this.arr, (item:string) => { + ForEach(this.arr, (item: string) => { ListItem() { // Navigation component, which provides click response processing by default, does not require developers to customize click event logic。 Navigation() { - Text("NavRouter" + item) - .width("100%") + Text('NavRouter' + item) + .width('100%') .height(72) .backgroundColor('#FFFFFF') .borderRadius(24) @@ -24,17 +23,17 @@ export struct NavigationComponent { .textAlign(TextAlign.Center) // Non-home page display content NavDestination() { - Text("NavDestinationContent" + item) + Text('NavDestinationContent' + item) } - .title("NavDestinationTitle" + item) + .title('NavDestinationTitle' + item) } } - }, (item:string):string => item) + }, (item: string): string => item) } - .width("90%") + .width('90%') .margin({ top: 12 }) } - .title("主标题") + .title('主标题') .mode(NavigationMode.Auto) } .height('100%') @@ -42,4 +41,5 @@ export struct NavigationComponent { .backgroundColor('#F1F3F5') } } + // [End NavigationComponent] \ No newline at end of file diff --git a/FoldableGuilde/entry/src/main/ets/modules/PinchImage.ets b/FoldableGuilde/entry/src/main/ets/modules/PinchImage.ets index 1740b683..21f6905d 100644 --- a/FoldableGuilde/entry/src/main/ets/modules/PinchImage.ets +++ b/FoldableGuilde/entry/src/main/ets/modules/PinchImage.ets @@ -1,19 +1,18 @@ // [Start PinchImage] -@Entry @Component export struct PinchImage { - list: string[] = ['image1','image2','image3','image4','image5','image6'] + list: string[] = ['image1', 'image2', 'image3', 'image4', 'image5', 'image6'] @State GridColumn: string = '1fr 1fr 1fr' @State GridRow: string = '1fr 1fr' build() { - Column(){ + Column() { Grid() { ForEach(this.list, (item: string) => { GridItem() { Text(item) }.backgroundColor(Color.Grey) - }) + }, (item: string) => item) } .columnsTemplate(this.GridColumn) .rowsTemplate(this.GridRow) @@ -21,8 +20,8 @@ export struct PinchImage { .columnsGap(12) } // Change the layout of the Grid when two-finger scaling is triggered - .gesture(PinchGesture({fingers:2}).onActionUpdate((event:GestureEvent)=>{ - if (event.scale>1) { + .gesture(PinchGesture({ fingers: 2 }).onActionUpdate((event: GestureEvent) => { + if (event.scale > 1) { // Increase animation effect this.getUIContext().animateTo({ duration: 500 @@ -30,7 +29,7 @@ export struct PinchImage { // When the two-finger scaling ratio is > 1, the number of Grid columns becomes 2 this.GridColumn = '1fr 1fr'; }) - }else { + } else { this.getUIContext().animateTo({ duration: 500 }, () => { @@ -41,4 +40,5 @@ export struct PinchImage { })) } } + // [End PinchImage] \ No newline at end of file diff --git a/FoldableGuilde/entry/src/main/ets/modules/PopupComponent.ets b/FoldableGuilde/entry/src/main/ets/modules/PopupComponent.ets index cafecb89..879cbd97 100644 --- a/FoldableGuilde/entry/src/main/ets/modules/PopupComponent.ets +++ b/FoldableGuilde/entry/src/main/ets/modules/PopupComponent.ets @@ -1,28 +1,28 @@ // [Start PopupExample] -@Entry @Component export struct PopupExample { - @State customPopup1: boolean = false - @State customPopup2: boolean = false + @State customPopup1: boolean = false; + @State customPopup2: boolean = false; + build() { Row() { - Button("popup1") - .onClick(()=>{ - this.customPopup1 = !this.customPopup1 + Button('popup1') + .onClick(() => { + this.customPopup1 = !this.customPopup1; }) // Bind the Popup window to the component and align it near the edge .bindPopup(this.customPopup1, { - message: "this is a popup1", + message: 'this is a popup1', popupColor: Color.Pink, }) Blank() - Button("popup2") - .onClick(()=>{ - this.customPopup2 = !this.customPopup2 + Button('popup2') + .onClick(() => { + this.customPopup2 = !this.customPopup2; }) // Bind the Popup window to the component and align it near the edge .bindPopup(this.customPopup2, { - message: "this is a popup2", + message: 'this is a popup2', popupColor: Color.Pink, }) } @@ -30,4 +30,5 @@ export struct PopupExample { .height('100%') } } + // [End PopupExample] \ No newline at end of file diff --git a/FoldableGuilde/entry/src/main/ets/modules/Scroll.ets b/FoldableGuilde/entry/src/main/ets/modules/Scroll.ets index 6a103cf1..3bcb9181 100644 --- a/FoldableGuilde/entry/src/main/ets/modules/Scroll.ets +++ b/FoldableGuilde/entry/src/main/ets/modules/Scroll.ets @@ -17,7 +17,7 @@ export struct ScrollComponent { ListItem() { Text('北京').fontSize(24) } - }) + }, (item: string) => item) } .onScrollStart(() => { if (this.scroll_stop_timeout) { diff --git a/FoldableGuilde/entry/src/main/ets/modules/ScrollParent.ets b/FoldableGuilde/entry/src/main/ets/modules/ScrollParent.ets index 636aa914..a776cd27 100644 --- a/FoldableGuilde/entry/src/main/ets/modules/ScrollParent.ets +++ b/FoldableGuilde/entry/src/main/ets/modules/ScrollParent.ets @@ -22,7 +22,7 @@ export struct NestedScroll { ListItem() { Text(this.context).fontSize(16) } - }) + }, (item: string) => item) } Web({ src: $rawfile("scroll.html"), controller: this.controller }) @@ -40,7 +40,7 @@ export struct NestedScroll { ListItem() { Text(this.context).fontSize(16) } - }) + }, (item: string) => item) } }.width("95%") } diff --git a/FoldableGuilde/entry/src/main/ets/utils/source_add1.ets b/FoldableGuilde/entry/src/main/ets/utils/source_add1.ets index 5f0cbd9d..261cae9d 100644 --- a/FoldableGuilde/entry/src/main/ets/utils/source_add1.ets +++ b/FoldableGuilde/entry/src/main/ets/utils/source_add1.ets @@ -1,4 +1,3 @@ -@Entry @Component // [Start ScrollTest] export struct ScrollTest { @@ -16,7 +15,7 @@ export struct ScrollTest { ListItem() { Text('北京').fontSize(24) } - }) + }, (item: string) => item) // [EndExclude ScrollTest] } .onScrollFrameBegin((offset: number, state: ScrollState) => { diff --git a/ImageEditTaskPool/entry/src/main/ets/view/AdjustContentView.ets b/ImageEditTaskPool/entry/src/main/ets/view/AdjustContentView.ets index 6a22217a..61efe46e 100644 --- a/ImageEditTaskPool/entry/src/main/ets/view/AdjustContentView.ets +++ b/ImageEditTaskPool/entry/src/main/ets/view/AdjustContentView.ets @@ -225,6 +225,7 @@ struct SliderCustom { // [EndExclude postProcess_start] }) } + // [StartExclude postProcess_start] updatePixelMap(ret: ArrayBuffer) { const newPixel = this.pixelMap as image.PixelMap; @@ -234,6 +235,7 @@ struct SliderCustom { this.deviceListDialogController.close(); this.postState = true; } + // [EndExclude postProcess_start] // [End postProcess_start] } @@ -271,6 +273,7 @@ function splitTask(buffers: ArrayBuffer[], type: AdjustId, sliderValue: number, } return group; } + // [End postProcess_start] @Concurrent @@ -312,10 +315,11 @@ function splitArrayBuffer(buffer: ArrayBuffer, n: number): ArrayBuffer[] { } return result; } + // [StartExclude split_buffer1] -function buffer(bufferArray:ESObject, taskNum: number, sliderValue: number, value: number){ - let Workers:ESObject -// [EndExclude split_buffer1] +function buffer(bufferArray: ESObject, taskNum: number, sliderValue: number, value: number) { + let Workers: ESObject + // [EndExclude split_buffer1] // Assign the split pixels to the Worker instance. const buffers: ArrayBuffer[] = splitArrayBuffer(bufferArray, taskNum); let messages: MessageItem[] = []; @@ -354,7 +358,7 @@ function mergeArrayBuffers(buffers: Object[]) { return mergedBuffer; } -function taskNum(WorkerName:string){ +function taskNum(WorkerName: string) { // [Start task1] let taskNum: number = 14; // The number of concurrent tasks is controlled, which can be adjusted according to the demand. let curTaskNum: number = taskNum <= 64 ? taskNum : 64; // Control allows up to 64 Worker instances to run at the same time. diff --git a/ImageEditTaskPool/entry/src/main/ets/view/WorkerPort.ets b/ImageEditTaskPool/entry/src/main/ets/view/WorkerPort.ets index 2d756400..f8956eee 100644 --- a/ImageEditTaskPool/entry/src/main/ets/view/WorkerPort.ets +++ b/ImageEditTaskPool/entry/src/main/ets/view/WorkerPort.ets @@ -1,24 +1,26 @@ -import { buffer, MessageEvents } from '@kit.ArkTS'; +import { MessageEvents } from '@kit.ArkTS'; import { CommonConstants } from '../common/constant/CommonConstants'; import { AngelRange, HSVIndex, RGBIndex } from '../viewModel/OptionViewModel'; -let WorkerPort:ESObject; -let WorkerBuffer:ESObject; + +let WorkerPort: ESObject; +let WorkerBuffer: ESObject; // [Start WorkerPort] // The child thread receives the task and calculates it. WorkerPort.onmessage = (event: MessageEvents) => { - let bufferArray:ArrayBuffer = event.data.buf; - let last:number = event.data.last; - let cur :number= event.data.cur; - let index:number = event.data.index; + let bufferArray: ArrayBuffer = event.data.buf; + let last: number = event.data.last; + let cur: number = event.data.cur; + let index: number = event.data.index; let buffer = adjustImageValue(bufferArray, last, cur); // Pixel calculation execution - let output :ESObject= new WorkerBuffer(buffer, index); + let output: ESObject = new WorkerBuffer(buffer, index); WorkerPort.postMessage(output); // Send the calculation result to the main thread. } -function adjustImageValue(bufferArray: ArrayBuffer, last: number, cur: number, hsvIndex?: number):ArrayBuffer{ +function adjustImageValue(bufferArray: ArrayBuffer, last: number, cur: number, hsvIndex?: number): ArrayBuffer { return execColorInfo(bufferArray, last, cur, HSVIndex.VALUE); } + // Picture pixel calculation function execColorInfo(bufferArray: ArrayBuffer, last: number, cur: number, hsvIndex: number) { // ... @@ -35,10 +37,12 @@ function execColorInfo(bufferArray: ArrayBuffer, last: number, cur: number, hsvI } return newBufferArr; } + // [End WorkerPort] function colorTransform(rgbValue: number): number { return Number((rgbValue / 255).toFixed(2)); } + function rgb2hsv(red: number, green: number, blue: number): number[] { let hsvH: number = 0, hsvS: number = 0, hsvV: number = 0; const rgbR: number = colorTransform(red); @@ -69,7 +73,8 @@ function rgb2hsv(red: number, green: number, blue: number): number[] { } return [hsvH, hsvS, hsvV]; } -function hsv2rgb(hue: number, saturation: number, value: number):ESObject { + +function hsv2rgb(hue: number, saturation: number, value: number): ESObject { let rgbR: number = 0, rgbG: number = 0, rgbB: number = 0; if (saturation === 0) { rgbR = rgbG = rgbB = Math.round((value * 255) / 100); diff --git a/ImageEditTaskPool/entry/src/main/ets/view/newBuffer1.ets b/ImageEditTaskPool/entry/src/main/ets/view/newBuffer1.ets index 98bf574c..57ddca78 100644 --- a/ImageEditTaskPool/entry/src/main/ets/view/newBuffer1.ets +++ b/ImageEditTaskPool/entry/src/main/ets/view/newBuffer1.ets @@ -1,26 +1,27 @@ let Workers: ESObject; -let taskNum:number=1; -let allocation:number=1 -let index:number=0 -let messages:number[]; -let n=0; -let curTaskNum=2 -let that=this -function test(){ -// [Start buffer_test] +let taskNum: number = 1; +let allocation: number = 1 +let index: number = 0 +let messages: number[]; +let n = 0; +let curTaskNum = 2 +let that = this + +function test() { + // [Start buffer_test] let num = 0; // Number of tasks processed let newBuffers: ArrayBuffer[] = []; for (let i = 0; i < taskNum; i++) { newBuffers[i] = new ArrayBuffer(0); // Initialize calculation result data of each task } - Workers[index].onmessage = (e:ESObject) => { + Workers[index].onmessage = (e: ESObject) => { newBuffers[e.data.index] = e.data.buffer; // The main thread receives the calculation result. num = num + 1; // Number of tasks completed +1 - if (allocation != 0) { // If the total task has not been processed, reuse the sub-thread to continue processing the remaining tasks. + if (allocation !== 0) { // If the total task has not been processed, reuse the sub-thread to continue processing the remaining tasks. Workers[index].postMessage(messages[n]); n += 1; allocation = allocation - 1; - } else if (num == taskNum) { + } else if (num === taskNum) { for (let i = 0; i < curTaskNum; i++) { Workers[i].terminate(); // When all tasks are processed, the child thread is destroyed. } @@ -28,11 +29,12 @@ function test(){ that.updatePixelMap(entireArrayBuffer); // Refresh the UI according to the calculation result. } } -// [End buffer_test] + // [End buffer_test] } + // [Start buffer_test] // Merge the calculation results of all tasks. -function mergeArrayBuffers(buffers:ArrayBuffer[]) { +function mergeArrayBuffers(buffers: ArrayBuffer[]) { // Calculate the combined total length. let totalLength = buffers.reduce((length, buffer) => { length += buffer.byteLength; @@ -51,4 +53,5 @@ function mergeArrayBuffers(buffers:ArrayBuffer[]) { } return mergedBuffer; } + // [End buffer_test] -- Gitee