diff --git a/common/src/main/ets/util/ResourceUtil.ets b/common/src/main/ets/util/ResourceUtil.ets index 9e21099a9ca6d3f7fb69847261678f2bcf75e8c7..12b126c0646bb7db6a22a93aaa15d98f7f927341 100644 --- a/common/src/main/ets/util/ResourceUtil.ets +++ b/common/src/main/ets/util/ResourceUtil.ets @@ -14,20 +14,35 @@ */ import { common } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; -let uiContext:UIContext +let uiContext: UIContext export async function getStringArray(resource: Resource, UIContext: UIContext): Promise> { uiContext = UIContext let context = UIContext.getHostContext() as common.UIAbilityContext; - let menuList: Array = await context.resourceManager.getStringArrayValue(resource); + let menuList: Array = []; + try { + menuList = await context.resourceManager.getStringArrayValue(resource.id); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'getStringArray', `getStringArrayValue failed, error code=${err.code}, message=${err.message}`); + } return menuList; } export function getString(resource: Resource): string { let context = uiContext.getHostContext() as common.UIAbilityContext; - return context.resourceManager.getStringSync(resource); + let result = ''; + try { + result = context.resourceManager.getStringSync(resource.id); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'getString', `getStringSync failed, error code=${err.code}, message=${err.message}`); + } + return result; } @Builder @@ -90,18 +105,30 @@ function addAction(title: string) { case getString($r('app.string.queue')): case getString($r('app.string.stack')): case getString($r('app.string.array_list')): - uiContext.getRouter().pushUrl({ url: 'pages/AddInformationView', params: { 'title': title } }) + uiContext.getRouter() + .pushUrl({ url: 'pages/AddInformationView', params: { 'title': title } }) + .catch((err: BusinessError) => { + hilog.error(0x0000, 'addAction', `pushUrl failed, error code=${err.code}, message=${err.message}`); + }) break; case getString($r('app.string.hash_map')): case getString($r('app.string.light_weight_map')): case getString($r('app.string.plain_array')): case getString($r('app.string.tree_map')): - uiContext.getRouter().pushUrl({ url: 'pages/AddKeyValuePairView', params: { 'title': title } }) + uiContext.getRouter() + .pushUrl({ url: 'pages/AddKeyValuePairView', params: { 'title': title } }) + .catch((err: BusinessError) => { + hilog.error(0x0000, 'addAction', `pushUrl failed, error code=${err.code}, message=${err.message}`); + }) break; case getString($r('app.string.hash_set')): case getString($r('app.string.light_weight_set')): case getString($r('app.string.tree_set')): - uiContext.getRouter().pushUrl({ url: 'pages/AddStringView', params: { 'title': title } }) + uiContext.getRouter() + .pushUrl({ url: 'pages/AddStringView', params: { 'title': title } }) + .catch((err: BusinessError) => { + hilog.error(0x0000, 'addAction', `pushUrl failed, error code=${err.code}, message=${err.message}`); + }) break; default: break; diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index e552273852a42ee063f8a3070c27790698ea8c1d..25589ebe104ad7da81a960b694d68121d6843633 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -17,6 +17,7 @@ import { display } from '@kit.ArkUI'; import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; import { window } from '@kit.ArkUI'; import { logger } from '@ohos/common'; +import { BusinessError } from '@kit.BasicServicesKit'; const BREAKPOINT_MD: number = 600; const BREAKPOINT_BIG: number = 840; @@ -31,19 +32,24 @@ export default class EntryAbility extends UIAbility { } updateBreakpoint(windowWidth: number): void { - let windowWidthVp: number = windowWidth / (display.getDefaultDisplaySync().densityDPI / PARAMS_PX_TO_VP); - let curBp: string; - if (windowWidthVp < BREAKPOINT_MD) { - curBp = 'sm'; - } else if (windowWidthVp < BREAKPOINT_BIG) { - curBp = 'md'; - } else { - curBp = 'lg'; + try { + let windowWidthVp: number = windowWidth / (display.getDefaultDisplaySync().densityDPI / PARAMS_PX_TO_VP); + let curBp: string; + if (windowWidthVp < BREAKPOINT_MD) { + curBp = 'sm'; + } else if (windowWidthVp < BREAKPOINT_BIG) { + curBp = 'md'; + } else { + curBp = 'lg'; + } + logger.info(TAG, 'window width: ' + windowWidth + ', window width vp: ' + windowWidthVp + ', breakpoint: ' + curBp); + AppStorage.setOrCreate('currentBreakpoint', curBp); + AppStorage.setOrCreate('windowWidth', windowWidthVp); + AppStorage.setOrCreate('isSplitMode', curBp === 'sm' || 'md' ? false : true); + } catch (error) { + let err = error as BusinessError; + logger.error(TAG, `updateBreakpoint failed, error code=${err.code}, message=${err.message}`); } - logger.info(TAG, 'window width: ' + windowWidth + ', window width vp: ' + windowWidthVp + ', breakpoint: ' + curBp); - AppStorage.setOrCreate('currentBreakpoint', curBp); - AppStorage.setOrCreate('windowWidth', windowWidthVp); - AppStorage.setOrCreate('isSplitMode', curBp === 'sm' || 'md' ? false : true); } onDestroy(): void { @@ -55,20 +61,27 @@ export default class EntryAbility extends UIAbility { logger.info(TAG, 'Ability onWindowStageCreate'); windowStage.getMainWindow().then((windowObj: window.Window) => { - let windowWidth: number = windowObj.getWindowProperties().windowRect.width; - this.updateBreakpoint(windowWidth); - windowObj.on('windowSizeChange', (newSize: window.Size) => { - let windowWidth: number = newSize.width; + try { + let windowWidth: number = windowObj.getWindowProperties().windowRect.width; this.updateBreakpoint(windowWidth); + windowObj.on('windowSizeChange', (newSize: window.Size) => { + let windowWidth: number = newSize.width; + this.updateBreakpoint(windowWidth); - if (windowObj.getWindowProperties().isFullScreen) { - logger.info(TAG, 'isFullScreen'); - } - if (windowObj.getWindowProperties().isLayoutFullScreen) { - logger.info(TAG, 'isLayoutFullScreen'); - } - }); - }); + if (windowObj.getWindowProperties().isFullScreen) { + logger.info(TAG, 'isFullScreen'); + } + if (windowObj.getWindowProperties().isLayoutFullScreen) { + logger.info(TAG, 'isLayoutFullScreen'); + } + }); + } catch (error) { + let err = error as BusinessError; + logger.error(TAG, `onWindowStageCreate failed, error code=${err.code}, message=${err.message}`); + } + }).catch((err: BusinessError) => { + logger.error(TAG, `getMainWindow failed, error code=${err.code}, message=${err.message}`); + }) windowStage.loadContent('pages/Index', (err, data) => { if (err.code) { diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index a7d4f7f8ddac6561ae7f77523eb2905654516366..8fada32c90507a35f68b95b37ea181e05a70bb51 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -14,9 +14,10 @@ */ import { common } from '@kit.AbilityKit'; -import { router } from '@kit.ArkUI'; import { MenuList } from '@ohos/menuitems'; import { getString, logger } from '@ohos/common'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; const TAG: string = 'Index'; @@ -32,7 +33,12 @@ struct Index { @State title: string = ''; aboutToAppear() { - this.title = this.context.resourceManager.getStringSync($r('app.string.lable_name').id); + try { + this.title = this.context.resourceManager.getStringSync($r('app.string.lable_name').id); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, TAG, `getStringSync failed, error code=${err.code}, message=${err.message}`); + } } build() { diff --git a/feature/capabilities/src/main/ets/capabilities/Uri.ets b/feature/capabilities/src/main/ets/capabilities/Uri.ets index 8774a00a8b1cc80d9b068a0287cf04ba3e1f5036..2f644b7c9940e30edabb2394943da0223d689d4a 100644 --- a/feature/capabilities/src/main/ets/capabilities/Uri.ets +++ b/feature/capabilities/src/main/ets/capabilities/Uri.ets @@ -14,9 +14,10 @@ */ import { uri } from '@kit.ArkTS'; -import { promptAction } from '@kit.ArkUI'; import { customTitle } from '@ohos/common'; import { ColumnOperation } from '../components/ColumnOperation'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; @Builder export function UriBuilder() { @@ -40,10 +41,15 @@ export struct Uri { UriResolution() { if (this.output.indexOf('://') === -1) { - this.UIContext.getPromptAction().showToast({ - message: 'Please enter a correct URI.', - duration: 3000 - }); + try { + this.UIContext.getPromptAction().showToast({ + message: 'Please enter a correct URI.', + duration: 3000 + }); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'Uri', `showToast failed, error code=${err.code}, message=${err.message}`); + } } else { this.host = this.URI.host; this.fragment = this.URI.fragment; diff --git a/feature/capabilities/src/main/ets/components/DeleteView.ets b/feature/capabilities/src/main/ets/components/DeleteView.ets index 136403d0618b3f786fcaccdc45ec311b02f78a57..44cb54b9771170b87275ca262abd309b4d885146 100644 --- a/feature/capabilities/src/main/ets/components/DeleteView.ets +++ b/feature/capabilities/src/main/ets/components/DeleteView.ets @@ -15,7 +15,7 @@ @Component export struct DeleteView { - private enable: boolean = false; + enable: boolean = false; build() { Row() { diff --git a/feature/capabilities/src/main/ets/components/arraylistcomponents/ArrayListDataSource.ets b/feature/capabilities/src/main/ets/components/arraylistcomponents/ArrayListDataSource.ets index 291591579486a485273d3eec98c4205e2a56b0d4..9d89778ff278e36f2b9ec05ceef2d5e3c31be93c 100644 --- a/feature/capabilities/src/main/ets/components/arraylistcomponents/ArrayListDataSource.ets +++ b/feature/capabilities/src/main/ets/components/arraylistcomponents/ArrayListDataSource.ets @@ -16,6 +16,8 @@ import { ArrayList } from '@kit.ArkTS'; import { BaseDataSource } from '@ohos/common'; import { Information } from '../../model/Information'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; export class ArrayListDataSource extends BaseDataSource { private dataArr: ArrayList = new ArrayList(); @@ -29,14 +31,24 @@ export class ArrayListDataSource extends BaseDataSource { } public addData(information: Information): void { - this.dataArr.add(information); - this.notifyDataAdd(this.dataArr.length - 1); - this.notifyDataReload(); + try { + this.dataArr.add(information); + this.notifyDataAdd(this.dataArr.length - 1); + this.notifyDataReload(); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'ArrayListDataSource', `addData failed, error code=${err.code}, message=${err.message}`); + } } public deleteData(index: number): void { - this.dataArr.removeByIndex(index); - this.notifyDataDelete(index); - this.notifyDataReload(); + try { + this.dataArr.removeByIndex(index); + this.notifyDataDelete(index); + this.notifyDataReload(); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'ArrayListDataSource', `deleteData failed, error code=${err.code}, message=${err.message}`); + } } } \ No newline at end of file diff --git a/feature/capabilities/src/main/ets/components/dequecomponents/DequeDataSource.ets b/feature/capabilities/src/main/ets/components/dequecomponents/DequeDataSource.ets index cec2700b7f6dec83e7ee250c598fcc84712cd553..aa0b3f02b9628f0a79fed3e4a1114c3f3339ded1 100644 --- a/feature/capabilities/src/main/ets/components/dequecomponents/DequeDataSource.ets +++ b/feature/capabilities/src/main/ets/components/dequecomponents/DequeDataSource.ets @@ -16,6 +16,8 @@ import { Deque } from '@kit.ArkTS'; import { BaseDataSource } from '@ohos/common'; import { Information } from '../../model/Information'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; export class DequeDataSource extends BaseDataSource { private deque = new Deque(); @@ -29,34 +31,54 @@ export class DequeDataSource extends BaseDataSource { } public insertFront(information: Information): void { - this.deque.insertFront(information); - this.deque.forEach((value, index) => { - value.clickAble = index === 0 || index === this.deque.length - 1; - }); - this.notifyDataReload(); + try { + this.deque.insertFront(information); + this.deque.forEach((value, index) => { + value.clickAble = index === 0 || index === this.deque.length - 1; + }); + this.notifyDataReload(); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'DequeDataSource', `insertFront failed, error code=${err.code}, message=${err.message}`); + } } public insertEnd(information: Information): void { - this.deque.insertEnd(information); - this.deque.forEach((value, index) => { - value.clickAble = index === 0 || index === this.deque.length - 1; - }); - this.notifyDataReload(); + try { + this.deque.insertEnd(information); + this.deque.forEach((value, index) => { + value.clickAble = index === 0 || index === this.deque.length - 1; + }); + this.notifyDataReload(); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'DequeDataSource', `insertEnd failed, error code=${err.code}, message=${err.message}`); + } } public deleteFront(): void { - this.deque.popFirst(); - this.deque.forEach((value, index) => { - value.clickAble = index === 0 || index === this.deque.length - 1; - }); - this.notifyDataReload(); + try { + this.deque.popFirst(); + this.deque.forEach((value, index) => { + value.clickAble = index === 0 || index === this.deque.length - 1; + }); + this.notifyDataReload(); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'DequeDataSource', `deleteFront failed, error code=${err.code}, message=${err.message}`); + } } public deleteEnd(): void { - this.deque.popLast(); - this.deque.forEach((value, index) => { - value.clickAble = index === 0 || index === this.deque.length - 1; - }); - this.notifyDataReload(); + try { + this.deque.popLast(); + this.deque.forEach((value, index) => { + value.clickAble = index === 0 || index === this.deque.length - 1; + }); + this.notifyDataReload(); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'DequeDataSource', `deleteEnd failed, error code=${err.code}, message=${err.message}`); + } } } \ No newline at end of file diff --git a/feature/capabilities/src/main/ets/components/linkedlistcomponents/LinkedListDataSource.ets b/feature/capabilities/src/main/ets/components/linkedlistcomponents/LinkedListDataSource.ets index d74ecc4c49b723e0b432a67134ec1e5c9626ed6a..1307825a06ac9462a61fb744efdee9562489ab3f 100644 --- a/feature/capabilities/src/main/ets/components/linkedlistcomponents/LinkedListDataSource.ets +++ b/feature/capabilities/src/main/ets/components/linkedlistcomponents/LinkedListDataSource.ets @@ -16,6 +16,8 @@ import { LinkedList } from '@kit.ArkTS'; import { BaseDataSource } from '@ohos/common'; import { Information } from '../../model/Information'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; export class LinkedListDataSource extends BaseDataSource { private linkedList: LinkedList = new LinkedList(); @@ -29,26 +31,47 @@ export class LinkedListDataSource extends BaseDataSource { } public addData(item: Information): void { - this.linkedList.add(item); - this.notifyDataAdd(this.linkedList.length - 1); - this.notifyDataReload(); + try { + this.linkedList.add(item); + this.notifyDataAdd(this.linkedList.length - 1); + this.notifyDataReload(); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'LinkedListDataSource', `addData failed, error code=${err.code}, message=${err.message}`); + } } public deleteFirst(): void { - this.linkedList.removeFirst(); - this.notifyDataDelete(0); - this.notifyDataReload(); + try { + this.linkedList.removeFirst(); + this.notifyDataDelete(0); + this.notifyDataReload(); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'LinkedListDataSource', `deleteFirst failed, error code=${err.code}, message=${err.message}`); + } } public deleteLast(): void { - this.linkedList.removeLast(); - this.notifyDataDelete(this.linkedList.length - 1); - this.notifyDataReload(); + try { + this.linkedList.removeLast(); + this.notifyDataDelete(this.linkedList.length - 1); + this.notifyDataReload(); + + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'LinkedListDataSource', `deleteLast failed, error code=${err.code}, message=${err.message}`); + } } public deleteData(index: number): void { - this.linkedList.removeByIndex(index); - this.notifyDataDelete(index); - this.notifyDataReload(); + try { + this.linkedList.removeByIndex(index); + this.notifyDataDelete(index); + this.notifyDataReload(); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'LinkedListDataSource', `deleteData failed, error code=${err.code}, message=${err.message}`); + } } } \ No newline at end of file diff --git a/feature/capabilities/src/main/ets/components/listcomponents/ListDataSource.ets b/feature/capabilities/src/main/ets/components/listcomponents/ListDataSource.ets index 30cffb7a8c814e9d4895e5c490f5abd00957e8eb..3332f8673ecaded2e8ecb7ca84cfe7972891cde2 100644 --- a/feature/capabilities/src/main/ets/components/listcomponents/ListDataSource.ets +++ b/feature/capabilities/src/main/ets/components/listcomponents/ListDataSource.ets @@ -16,6 +16,8 @@ import { List} from '@kit.ArkTS'; import { BaseDataSource } from '@ohos/common'; import { Information } from '../../model/Information'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; export class ListDateSource extends BaseDataSource { private dataArr: List = new List(); @@ -25,18 +27,34 @@ export class ListDateSource extends BaseDataSource { } public getData(index: number): Information { - return this.dataArr.get(index); + try { + return this.dataArr.get(index); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'ListDateSource', `getData failed, error code=${err.code}, message=${err.message}`); + return new Information('', 0, ''); + } } public addData(information: Information): void { - this.dataArr.add(information); - this.notifyDataAdd(this.dataArr.length - 1); - this.notifyDataReload(); + try { + this.dataArr.add(information); + this.notifyDataAdd(this.dataArr.length - 1); + this.notifyDataReload(); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'ListDateSource', `addData failed, error code=${err.code}, message=${err.message}`); + } } public deleteData(index: number): void { - this.dataArr.removeByIndex(index); - this.notifyDataDelete(index); - this.notifyDataReload(); + try { + this.dataArr.removeByIndex(index); + this.notifyDataDelete(index); + this.notifyDataReload(); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'ListDateSource', `deleteData failed, error code=${err.code}, message=${err.message}`); + } } } \ No newline at end of file diff --git a/feature/capabilities/src/main/ets/components/plainarraycomponents/PlainArrayDataSource.ets b/feature/capabilities/src/main/ets/components/plainarraycomponents/PlainArrayDataSource.ets index ce2a98daf491c79f95a1f1fe46029d8b5bf52a73..0d9a31c00161ed168a76b226b7445d10516ab261 100644 --- a/feature/capabilities/src/main/ets/components/plainarraycomponents/PlainArrayDataSource.ets +++ b/feature/capabilities/src/main/ets/components/plainarraycomponents/PlainArrayDataSource.ets @@ -16,6 +16,8 @@ import { PlainArray, ArrayList } from '@kit.ArkTS'; import { BaseDataSource } from '@ohos/common'; import { KeyValuePair } from '../../model/KeyValuePair'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; export class PlainArrayDataSource extends BaseDataSource { private dataArr: PlainArray = new PlainArray(); @@ -26,27 +28,43 @@ export class PlainArrayDataSource extends BaseDataSource { } public getData(index: number): KeyValuePair { - let key: number = this.arr[index]; - let value: string = this.dataArr.get(key); - this.dataArr.get(this.arr[index]); - let keyValuePair: KeyValuePair = new KeyValuePair(`${this.arr[index]}`, value); + let keyValuePair: KeyValuePair = new KeyValuePair('', ''); + try { + let key: number = this.arr[index]; + let value: string = this.dataArr.get(key); + this.dataArr.get(this.arr[index]); + keyValuePair = new KeyValuePair(`${this.arr[index]}`, value); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'PlainArrayDataSource', `getData failed, error code=${err.code}, message=${err.message}`); + } return keyValuePair; } public addData(keyValuePair: KeyValuePair): void { - let key: number = Number(keyValuePair.key); - if (!this.dataArr.has(key)) { - this.arr.add(key) + try { + let key: number = Number(keyValuePair.key); + if (!this.dataArr.has(key)) { + this.arr.add(key) + } + this.dataArr.add(key, keyValuePair.value); + this.notifyDataAdd(this.dataArr.length - 1); + this.notifyDataReload(); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'PlainArrayDataSource', `addData failed, error code=${err.code}, message=${err.message}`); } - this.dataArr.add(key, keyValuePair.value); - this.notifyDataAdd(this.dataArr.length - 1); - this.notifyDataReload(); } public deleteData(index: number): void { - this.dataArr.removeAt(index); - this.arr.removeByIndex(index); - this.notifyDataDelete(index); - this.notifyDataReload(); + try { + this.dataArr.removeAt(index); + this.arr.removeByIndex(index); + this.notifyDataDelete(index); + this.notifyDataReload(); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'PlainArrayDataSource', `deleteData failed, error code=${err.code}, message=${err.message}`); + } } } \ No newline at end of file diff --git a/feature/capabilities/src/main/ets/components/queuecomponents/QueueDataSource.ets b/feature/capabilities/src/main/ets/components/queuecomponents/QueueDataSource.ets index cc87291b9f9bcaa0d7f98352b95a590d17c720bf..f17a94457b3b00b2481d93ac62376af3d0a725df 100644 --- a/feature/capabilities/src/main/ets/components/queuecomponents/QueueDataSource.ets +++ b/feature/capabilities/src/main/ets/components/queuecomponents/QueueDataSource.ets @@ -16,6 +16,8 @@ import { Queue } from '@kit.ArkTS'; import { BaseDataSource } from '@ohos/common'; import { Information } from '../../model/Information'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; export class QueueDataSource extends BaseDataSource { private dataArr: Queue = new Queue(); @@ -29,20 +31,30 @@ export class QueueDataSource extends BaseDataSource { } public addData(information: Information): void { - this.dataArr.add(information); - this.dataArr.forEach((value, index) => { - value.clickAble = index === 0; - }); - this.notifyDataAdd(this.dataArr.length - 1); - this.notifyDataReload(); + try { + this.dataArr.add(information); + this.dataArr.forEach((value, index) => { + value.clickAble = index === 0; + }); + this.notifyDataAdd(this.dataArr.length - 1); + this.notifyDataReload(); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'QueueDataSource', `addData failed, error code=${err.code}, message=${err.message}`); + } } public deleteData(): void { - this.dataArr.pop(); - this.dataArr.forEach((value, index) => { - value.clickAble = index === 0; - }); - this.notifyDataDelete(0); - this.notifyDataReload(); + try { + this.dataArr.pop(); + this.dataArr.forEach((value, index) => { + value.clickAble = index === 0; + }); + this.notifyDataDelete(0); + this.notifyDataReload(); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'QueueDataSource', `deleteData failed, error code=${err.code}, message=${err.message}`); + } } } \ No newline at end of file diff --git a/feature/capabilities/src/main/ets/components/stackcomponents/StackDataSource.ets b/feature/capabilities/src/main/ets/components/stackcomponents/StackDataSource.ets index 7ba43e94da43a1c09d79306f12637dcbe9f7bb44..6fed018c082b39a21641724c3b816c61540d7937 100644 --- a/feature/capabilities/src/main/ets/components/stackcomponents/StackDataSource.ets +++ b/feature/capabilities/src/main/ets/components/stackcomponents/StackDataSource.ets @@ -16,6 +16,8 @@ import { Stack } from '@kit.ArkTS'; import { BaseDataSource } from '@ohos/common'; import { Information } from '../../model/Information'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; export class StackDataSource extends BaseDataSource { private dataArr: Stack = new Stack(); @@ -29,20 +31,30 @@ export class StackDataSource extends BaseDataSource { } public addData(information: Information): void { - this.dataArr.push(information); + try { + this.dataArr.push(information); this.dataArr.forEach((value, index) => { value.clickAble = index === this.dataArr.length - 1; }); this.notifyDataAdd(this.dataArr.length - 1); this.notifyDataReload(); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'StackDataSource', `addData failed, error code=${err.code}, message=${err.message}`); + } } public deleteData(): void { - this.dataArr.pop(); - this.dataArr.forEach((value, index) => { - value.clickAble = index === this.dataArr.length - 1; - }); - this.notifyDataDelete(this.dataArr.length - 1); - this.notifyDataReload(); + try { + this.dataArr.pop(); + this.dataArr.forEach((value, index) => { + value.clickAble = index === this.dataArr.length - 1; + }); + this.notifyDataDelete(this.dataArr.length - 1); + this.notifyDataReload(); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'StackDataSource', `deleteData failed, error code=${err.code}, message=${err.message}`); + } } } \ No newline at end of file diff --git a/feature/capabilities/src/main/ets/components/treemapcomponents/TreeMapDataSource.ets b/feature/capabilities/src/main/ets/components/treemapcomponents/TreeMapDataSource.ets index 4e1074c624a80814e9f2973f8036e040d7cdfcd2..617ae453ecb16b8f5a327849e26e3a0ce96f6b30 100644 --- a/feature/capabilities/src/main/ets/components/treemapcomponents/TreeMapDataSource.ets +++ b/feature/capabilities/src/main/ets/components/treemapcomponents/TreeMapDataSource.ets @@ -16,6 +16,8 @@ import { TreeMap, ArrayList } from '@kit.ArkTS'; import { BaseDataSource } from '@ohos/common'; import { KeyValuePair } from '../../model/KeyValuePair'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; export class TreeMapDataSource extends BaseDataSource { private dataArr: TreeMap = new TreeMap(); @@ -26,27 +28,43 @@ export class TreeMapDataSource extends BaseDataSource { } public getData(index: number): KeyValuePair { - let key: string = this.arr[index]; - let value: string = this.dataArr.get(key); - this.dataArr.get(this.arr[index]); - let keyValuePair: KeyValuePair = new KeyValuePair(`${this.arr[index]}`, value); + let keyValuePair: KeyValuePair = new KeyValuePair('', ''); + try { + let key: string = this.arr[index]; + let value: string = this.dataArr.get(key); + this.dataArr.get(this.arr[index]); + keyValuePair = new KeyValuePair(`${this.arr[index]}`, value); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'TreeMapDataSource', `getData failed, error code=${err.code}, message=${err.message}`); + } return keyValuePair; } public addData(keyValuePair: KeyValuePair): void { - if (!this.dataArr.hasKey(keyValuePair.key)) { - this.arr.add(keyValuePair.key) + try { + if (!this.dataArr.hasKey(keyValuePair.key)) { + this.arr.add(keyValuePair.key) + } + this.dataArr.set(keyValuePair.key, keyValuePair.value); + this.notifyDataChange(this.dataArr.length - 1); + this.notifyDataReload(); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'TreeMapDataSource', `addData failed, error code=${err.code}, message=${err.message}`); } - this.dataArr.set(keyValuePair.key, keyValuePair.value); - this.notifyDataChange(this.dataArr.length - 1); - this.notifyDataReload(); } public deleteData(key: string): void { - this.dataArr.remove(key); - let index = this.arr.getIndexOf(key); - this.arr.remove(key); - this.notifyDataDelete(index); - this.notifyDataReload(); + try { + this.dataArr.remove(key); + let index = this.arr.getIndexOf(key); + this.arr.remove(key); + this.notifyDataDelete(index); + this.notifyDataReload(); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'TreeMapDataSource', `deleteData failed, error code=${err.code}, message=${err.message}`); + } } } \ No newline at end of file diff --git a/feature/capabilities/src/main/ets/components/treesetcomponents/TreeSetDataSource.ets b/feature/capabilities/src/main/ets/components/treesetcomponents/TreeSetDataSource.ets index 5a2c50d0e8dc28861495cd29a4955918edda56db..66adb53919737bd460b1f29831bae1ce4627d6a6 100644 --- a/feature/capabilities/src/main/ets/components/treesetcomponents/TreeSetDataSource.ets +++ b/feature/capabilities/src/main/ets/components/treesetcomponents/TreeSetDataSource.ets @@ -15,6 +15,8 @@ import { TreeSet, ArrayList } from '@kit.ArkTS'; import { BaseDataSource } from '@ohos/common'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; export class TreeSetDataSource extends BaseDataSource { private dataArr: TreeSet = new TreeSet(); @@ -29,16 +31,27 @@ export class TreeSetDataSource extends BaseDataSource { } public addData(value: string): void { - this.dataArr.add(value); - this.arr.add(value); - this.notifyDataAdd(this.dataArr.length - 1); - this.notifyDataReload(); + try { + this.dataArr.add(value); + this.arr.add(value); + this.notifyDataAdd(this.dataArr.length - 1); + this.notifyDataReload(); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'TreeSetDataSource', `addData failed, error code=${err.code}, message=${err.message}`); + } } public deleteData(value: string, index: number): void { - this.dataArr.remove(value); - this.arr.removeByIndex(index); - this.notifyDataDelete(index); - this.notifyDataReload(); + try { + + this.dataArr.remove(value); + this.arr.removeByIndex(index); + this.notifyDataDelete(index); + this.notifyDataReload(); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'TreeSetDataSource', `deleteData failed, error code=${err.code}, message=${err.message}`); + } } } \ No newline at end of file diff --git a/feature/capabilities/src/main/ets/components/utilcomponents/scopehelper/SleepView.ets b/feature/capabilities/src/main/ets/components/utilcomponents/scopehelper/SleepView.ets index eb6e9383953201708fcc265c35f4c75c7744bebe..77b08ead2ebd4bef816abbe67db3645dfbd48a72 100644 --- a/feature/capabilities/src/main/ets/components/utilcomponents/scopehelper/SleepView.ets +++ b/feature/capabilities/src/main/ets/components/utilcomponents/scopehelper/SleepView.ets @@ -17,6 +17,8 @@ import { util } from '@kit.ArkTS'; import { getString } from '@ohos/common'; import { InputItem } from './InputItem'; import { ScopeNumber } from '../../../model/ScopeNumber'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; const ZERO: number = 0; const SLEEP_TIME_SHORT: number = 7; @@ -25,7 +27,6 @@ const SLEEP_TIME_LONG: number = 10; @Component export struct SleepView { UIContext = this.getUIContext() - @State shortTime: number = ZERO; @State longTime: number = ZERO; @@ -75,13 +76,18 @@ export struct SleepView { } sleepRange() { - if (this.shortTime <= ZERO || this.longTime <= ZERO) { - this.UIContext.getPromptAction().showToast({ message: $r("app.string.scope_sleep_tips") }); - return; - } - if (this.longTime <= this.shortTime) { - this.UIContext.getPromptAction().showToast({ message: $r("app.string.scope_sleep_tips_less") }); - return; + try { + if (this.shortTime <= ZERO || this.longTime <= ZERO) { + this.UIContext.getPromptAction().showToast({ message: $r("app.string.scope_sleep_tips") }); + return; + } + if (this.longTime <= this.shortTime) { + this.UIContext.getPromptAction().showToast({ message: $r("app.string.scope_sleep_tips_less") }); + return; + } + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'SleepView', `sleepRange showToast failed, error code=${err.code}, message=${err.message}`); } let timeLower = new ScopeNumber(SLEEP_TIME_SHORT); let timeUpper = new ScopeNumber(SLEEP_TIME_LONG); diff --git a/feature/capabilities/src/main/ets/components/utilcomponents/scopehelper/TempView.ets b/feature/capabilities/src/main/ets/components/utilcomponents/scopehelper/TempView.ets index f75f0b94021f0262eb7533191ce715ee1c179f56..deba86f458aac3911116bb0d98b0d8369af55087 100644 --- a/feature/capabilities/src/main/ets/components/utilcomponents/scopehelper/TempView.ets +++ b/feature/capabilities/src/main/ets/components/utilcomponents/scopehelper/TempView.ets @@ -17,6 +17,8 @@ import { util } from '@kit.ArkTS'; import { getString } from '@ohos/common'; import { InputItem } from './InputItem'; import { ScopeNumber } from '../../../model/ScopeNumber'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; const ZERO: number = 0; const TEMPERATURE_MIN: number = 36; @@ -88,7 +90,12 @@ export struct TempView { tempRange() { if (this.tempMorning <= ZERO || this.tempNoon <= ZERO || this.tempNight <= ZERO) { - this.UIContext.getPromptAction().showToast({ message: $r("app.string.scope_temp_tips") }); + try { + this.UIContext.getPromptAction().showToast({ message: $r("app.string.scope_temp_tips") }); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'TempView', `tempRange showToast failed, error code=${err.code}, message=${err.message}`); + } return; } let arr = [this.tempMorning, this.tempNoon, this.tempNight].sort(); diff --git a/feature/capabilities/src/main/ets/util/ConvertXmlUtil.ets b/feature/capabilities/src/main/ets/util/ConvertXmlUtil.ets index 8fed6083a9dd81adcdd8c1025da0d5038ebe6b56..2d13ac098b2a7b5f310eb8f5b2c084db1bc0f720 100644 --- a/feature/capabilities/src/main/ets/util/ConvertXmlUtil.ets +++ b/feature/capabilities/src/main/ets/util/ConvertXmlUtil.ets @@ -15,6 +15,8 @@ import { convertxml, util, xml } from '@kit.ArkTS'; import { logger } from '@ohos/common'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; const TAG: string = 'ConvertXmlUtil'; @@ -47,7 +49,7 @@ export function parserNode(strXml: string): string { let parser: xml.XmlPullParser = new xml.XmlPullParser(arrBuffer.buffer as object as ArrayBuffer, 'UTF-8'); let str: string = ''; const tagFunc = (name: string, value: string): boolean => { - let tagStr = name + ' '+ value; + let tagStr = name + ' ' + value; str += 'tag-' + tagStr + `\n`; return true; }; @@ -95,7 +97,13 @@ export function convertNode(input: string): string { }; let conv = new convertxml.ConvertXML(); logger.info(TAG, 'convertNode new ConvertXML'); - let result = JSON.stringify(conv.fastConvertToJSObject(input, options)); + let result = ''; + try { + result = JSON.stringify(conv.fastConvertToJSObject(input, options)); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'convertNode', `fastConvertToJSObject failed, error code=${err.code}, message=${err.message}`); + } logger.info(TAG, `convertNode conv.convert result = ${result}`); return result; } \ No newline at end of file diff --git a/feature/capabilities/src/main/ets/util/LRUCacheUtil.ets b/feature/capabilities/src/main/ets/util/LRUCacheUtil.ets index cf2b0d7c49b7ff8ff2f52217b4d7b72555bfcc87..053ac84cb8cb03708c8176d31d8de1a8083841a7 100644 --- a/feature/capabilities/src/main/ets/util/LRUCacheUtil.ets +++ b/feature/capabilities/src/main/ets/util/LRUCacheUtil.ets @@ -15,6 +15,8 @@ import { common } from '@kit.AbilityKit'; import { util } from '@kit.ArkTS'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; export let lruBuffer: util.LRUCache = new util.LRUCache(); @@ -64,7 +66,13 @@ export function operationLog(): string { export function getString(resource: Resource) { let context = uiContext.getHostContext() as common.UIAbilityContext; - let resultStr = context.resourceManager.getStringSync(resource); + let resultStr = ''; + try { + resultStr = context.resourceManager.getStringSync(resource.id); + } catch (error) { + let err = error as BusinessError; + hilog.error(0x0000, 'getString', `getStringSync failed, error code=${err.code}, message=${err.message}`); + } return resultStr; } diff --git a/feature/capabilities/src/main/module.json5 b/feature/capabilities/src/main/module.json5 index 2dcb73957dd5c4f0ccfcf3b991cd9210d5b33e15..7b7ca280b589114095c210c682c4ea58c4e43460 100644 --- a/feature/capabilities/src/main/module.json5 +++ b/feature/capabilities/src/main/module.json5 @@ -20,6 +20,12 @@ "deviceTypes": [ "phone" ], - "routerMap": "$profile:route_map" - } + "routerMap": "$profile:route_map", + "metadata": [ + { + "name": "UseTsHar", + "value": "true" + } + ] + }, } \ No newline at end of file diff --git a/hvigor/hvigor-config.json5 b/hvigor/hvigor-config.json5 index f70ecd4112d94f9aa555adf898d53f18bf58f3e9..a2a2e3781820ac1b548a01481b50e88b0f2e5cfa 100644 --- a/hvigor/hvigor-config.json5 +++ b/hvigor/hvigor-config.json5 @@ -1,5 +1,5 @@ { - "modelVersion": "5.0.0", + "modelVersion": "5.0.5", "dependencies": { } } \ No newline at end of file diff --git a/oh-package.json5 b/oh-package.json5 index 63b7e70f30e15cce7101472f034a9819aeb81c1a..f704344c61cd3b7da416409002ad80288ceebcc7 100644 --- a/oh-package.json5 +++ b/oh-package.json5 @@ -1,5 +1,5 @@ { - "modelVersion": "5.0.0", + "modelVersion": "5.0.5", "license": "ISC", "devDependencies": { },