diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index a2c295c26b6b8709a1b427a11244fdb98dcf56c6..246e3dd07f1c5a425979214fe1f1ece20963bf51 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -21,6 +21,8 @@ import NormalBrush from '../viewmodel/IBrush'; import Paint from '../viewmodel/Paint'; import { CommonConstants } from '../common/CommonConstants'; import { myPaintSheet } from '../view/myPaintSheet'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BusinessError } from '@kit.BasicServicesKit'; @Entry @Component @@ -57,23 +59,28 @@ struct DrawCanvas { this.mPaint.setColor(CommonConstants.BLACK); this.mPaint.setGlobalAlpha(CommonConstants.ONE); this.mBrush = new NormalBrush(); - display.on('foldStatusChange', (data: display.FoldStatus) => { - if (data === 2) { - this.scaleValueX = 0.5; - this.pinchValueX = 0.5; - this.scaleValueY = 1; - this.pinchValueY = 1; - this.context.clearRect(0, 0, this.context.width, this.context.height); - this.drawInvoker.execute(this.context); - } else if (data === 1) { - this.scaleValueX = 1; - this.scaleValueY = 1; - this.pinchValueX = 1; - this.pinchValueY = 1; - this.context.clearRect(0, 0, this.context.width, this.context.height); - this.drawInvoker.execute(this.context); - } - }) + try { + display.on('foldStatusChange', (data: display.FoldStatus) => { + if (data === 2) { + this.scaleValueX = 0.5; + this.pinchValueX = 0.5; + this.scaleValueY = 1; + this.pinchValueY = 1; + this.context.clearRect(0, 0, this.context.width, this.context.height); + this.drawInvoker.execute(this.context); + } else if (data === 1) { + this.scaleValueX = 1; + this.scaleValueY = 1; + this.pinchValueX = 1; + this.pinchValueY = 1; + this.context.clearRect(0, 0, this.context.width, this.context.height); + this.drawInvoker.execute(this.context); + } + }) + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'Index', `listen foldStatusChange failed. code=${err.code}, message=${err.message}`); + } } createDraw() { diff --git a/entry/src/main/ets/viewmodel/DrawInvoker.ets b/entry/src/main/ets/viewmodel/DrawInvoker.ets index c82999fd746b37272b596d2de240c91cc5651b50..4ad0b2257d04d03af1833de678776bde718a4e53 100644 --- a/entry/src/main/ets/viewmodel/DrawInvoker.ets +++ b/entry/src/main/ets/viewmodel/DrawInvoker.ets @@ -15,6 +15,8 @@ import { List } from '@kit.ArkTS'; import DrawPath from './IDraw'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BusinessError } from '@kit.BasicServicesKit'; export default class DrawInvoker { // Draw list. @@ -23,22 +25,37 @@ export default class DrawInvoker { private redoList: Array = new Array(); add(command: DrawPath): void { - this.drawPathList.add(command); + try { + this.drawPathList.add(command); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'DrawInvoker', `list add failed. code=${err.code}, message=${err.message}`); + } this.redoList = []; } clear(): void { if (this.drawPathList.length > 0 || this.redoList.length > 0) { - this.drawPathList.clear(); + try { + this.drawPathList.clear(); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'DrawInvoker', `list clear failed. code=${err.code}, message=${err.message}`); + } this.redoList = []; } } undo(): void { if (this.drawPathList.length > 0) { - let undo: DrawPath = this.drawPathList.get(this.drawPathList.length - 1); - this.drawPathList.removeByIndex(this.drawPathList.length - 1); - this.redoList.push(undo) + try { + let undo: DrawPath = this.drawPathList.get(this.drawPathList.length - 1); + this.drawPathList.removeByIndex(this.drawPathList.length - 1); + this.redoList.push(undo) + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'DrawInvoker', `undo failed. code=${err.code}, message=${err.message}`); + } } } @@ -46,15 +63,25 @@ export default class DrawInvoker { if (this.redoList.length > 0) { let redoCommand = this.redoList[this.redoList.length - 1]; this.redoList.pop(); - this.drawPathList.add(redoCommand); + try { + this.drawPathList.add(redoCommand); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'DrawInvoker', `list add failed. code=${err.code}, message=${err.message}`); + } } } execute(context: CanvasRenderingContext2D): void { if (this.drawPathList !== null) { - this.drawPathList.forEach((element: DrawPath) => { - element.draw(context); - }); + try { + this.drawPathList.forEach((element: DrawPath) => { + element.draw(context); + }); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'DrawInvoker', `execute failed. code=${err.code}, message=${err.message}`); + } } }