diff --git a/FoldableGuilde/entry/src/main/ets/modules/Crease.ets b/FoldableGuilde/entry/src/main/ets/modules/Crease.ets index fec47eb803399d66f39cdd5f54f6188d42d2c646..e168b3a5a02380bed2b73e86fe16aeefcc5b8b07 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 e92c284c0d4bcdcbfc42c9b6932598b6d7531f95..042a4f86e49832944883316ce44cf25cfca27356 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 0639dbde739858db1ad2b8eb211e5a6116554f3b..51c837bb2fa45859b9f15f71d77ba032493aaa68 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 1740b683aed804e4c2db30015f14c804a68f9f4d..21f6905dcabf35fd510a90678e82c0ab744e58ae 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 cafecb89785edc4ef023baa35fe4198df0a9e736..879cbd971eea20636b425e725ec7ec78ae89129b 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 6a103cf1f6dca4f16bd00463ac586eed6d5aa2c4..3bcb9181795efc2c45d92d8fd43b8e0eaca6154a 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 636aa91429f3473a9333abe59c66d7f088f4a16c..a776cd27be7d7902133812cd4ae24fda32373676 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 5f0cbd9db2f18627f1e7af90394b30cca90cfda1..261cae9db1f8bc48c846e9c02fa89bc4eb2840cc 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 6a22217ac5ed91b5c9a250871ba39815b32b0d98..61efe46ed42de612299348d7bac93341d26a4c51 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 2d75640019346d119911e8ba8c4b577a8680c311..f8956eee6419a0a2b1bfc3aa5de2604bc293f571 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 98bf574cc5e4f2037221d612a956ecf9fd9abb3c..57ddca78c4228721d7060c2ff39174d560c71e47 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]