1/* 2 * Copyright (c) 2023-2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16if (!('finalizeConstruction' in ViewPU.prototype)) { 17 Reflect.set(ViewPU.prototype, 'finalizeConstruction', () => {}); 18} 19 20const LengthMetrics = requireNapi('arkui.node').LengthMetrics; 21const accessibility = requireNapi('accessibility'); 22const intl = requireNapi('intl'); 23 24export var CounterType; 25(function (CounterType) { 26 CounterType[(CounterType['LIST'] = 0)] = 'LIST'; 27 CounterType[(CounterType['COMPACT'] = 1)] = 'COMPACT'; 28 CounterType[(CounterType['INLINE'] = 2)] = 'INLINE'; 29 CounterType[(CounterType['INLINE_DATE'] = 3)] = 'INLINE_DATE'; 30})(CounterType || (CounterType = {})); 31var FocusText; 32(function (FocusText) { 33 FocusText[(FocusText['NONE'] = 0)] = 'NONE'; 34 FocusText[(FocusText['TEXT1'] = 1)] = 'TEXT1'; 35 FocusText[(FocusText['TEXT2'] = 2)] = 'TEXT2'; 36 FocusText[(FocusText['TEXT3'] = 3)] = 'TEXT3'; 37})(FocusText || (FocusText = {})); 38export class CommonOptions {} 39export class InlineStyleOptions extends CommonOptions {} 40export class NumberStyleOptions extends InlineStyleOptions {} 41export class DateData { 42 constructor(year, month, day) { 43 this.year = year; 44 this.month = month; 45 this.day = day; 46 } 47 toString() { 48 let date = this.year.toString() + '-'; 49 let month = 50 this.month < 10 ? '0' + this.month.toString() : this.month.toString(); 51 date += month + '-'; 52 let day = this.day < 10 ? '0' + this.day.toString() : this.day.toString(); 53 date += day; 54 return date; 55 } 56} 57export class DateStyleOptions extends CommonOptions {} 58export class CounterOptions { 59 constructor() { 60 this.type = CounterType.LIST; 61 } 62} 63class CounterResource {} 64// counter color 65CounterResource.BUTTON_BACKGROUD_COLOR = { 66 id: -1, 67 type: 10001, 68 params: ['sys.color.ohos_id_color_button_normal'], 69 bundleName: '__harDefaultBundleName__', 70 moduleName: '__harDefaultModuleName__', 71}; 72CounterResource.BUTTON_ICON_COLOR = { 73 id: -1, 74 type: 10001, 75 params: ['sys.color.ohos_id_color_primary'], 76 bundleName: '__harDefaultBundleName__', 77 moduleName: '__harDefaultModuleName__', 78}; 79CounterResource.BUTTON_BORDER_FOCUSED_COLOR = { 80 id: -1, 81 type: 10001, 82 params: ['sys.color.ohos_id_color_focused_outline'], 83 bundleName: '__harDefaultBundleName__', 84 moduleName: '__harDefaultModuleName__', 85}; 86CounterResource.COUNTER_TEXT_COLOR = { 87 id: -1, 88 type: 10001, 89 params: ['sys.color.ohos_id_color_text_primary'], 90 bundleName: '__harDefaultBundleName__', 91 moduleName: '__harDefaultModuleName__', 92}; 93CounterResource.COUNTER_BORDER_COLOR = { 94 id: -1, 95 type: 10001, 96 params: ['sys.color.ohos_id_color_component_normal'], 97 bundleName: '__harDefaultBundleName__', 98 moduleName: '__harDefaultModuleName__', 99}; 100// button icon 101CounterResource.BUTTON_ADD_ICON = { 102 id: -1, 103 type: 20000, 104 params: ['sys.media.ohos_ic_public_add'], 105 bundleName: '__harDefaultBundleName__', 106 moduleName: '__harDefaultModuleName__', 107}; 108CounterResource.BUTTON_SUB_ICON = { 109 id: -1, 110 type: 20000, 111 params: ['sys.media.ohos_ic_public_minus'], 112 bundleName: '__harDefaultBundleName__', 113 moduleName: '__harDefaultModuleName__', 114}; 115CounterResource.BUTTON_ARROW_UP = { 116 id: -1, 117 type: 20000, 118 params: ['sys.media.ohos_ic_public_arrow_up'], 119 bundleName: '__harDefaultBundleName__', 120 moduleName: '__harDefaultModuleName__', 121}; 122CounterResource.BUTTON_ARROW_DOWN = { 123 id: -1, 124 type: 20000, 125 params: ['sys.media.ohos_ic_public_arrow_down'], 126 bundleName: '__harDefaultBundleName__', 127 moduleName: '__harDefaultModuleName__', 128}; 129// counter size 130CounterResource.BUTTON_BORDER_FOCUSED_WIDTH = '2vp'; 131CounterResource.BUTTON_BORDER_BLUR_WIDTH = '0vp'; 132CounterResource.COUNTER_BORDER_WIDTH_NUMBER = 1; 133CounterResource.COUNTER_LIST_LABEL_SIZE = { 134 id: -1, 135 type: 10002, 136 params: ['sys.float.ohos_id_text_size_body1'], 137 bundleName: '__harDefaultBundleName__', 138 moduleName: '__harDefaultModuleName__', 139}; 140CounterResource.COUNTER_LIST_NUMBER_SIZE = { 141 id: -1, 142 type: 10002, 143 params: ['sys.float.ohos_id_text_size_body1'], 144 bundleName: '__harDefaultBundleName__', 145 moduleName: '__harDefaultModuleName__', 146}; 147CounterResource.COUNTER_COMPACT_LABEL_SIZE = { 148 id: -1, 149 type: 10002, 150 params: ['sys.float.ohos_id_text_size_body2'], 151 bundleName: '__harDefaultBundleName__', 152 moduleName: '__harDefaultModuleName__', 153}; 154CounterResource.COUNTER_NUMBER_SIZE = { 155 id: -1, 156 type: 10002, 157 params: ['sys.float.ohos_id_text_size_body1'], 158 bundleName: '__harDefaultBundleName__', 159 moduleName: '__harDefaultModuleName__', 160}; 161CounterResource.COUNTER_LIST_LEFT_PADDING = { 162 id: -1, 163 type: 10002, 164 params: ['sys.float.ohos_id_default_padding_start'], 165 bundleName: '__harDefaultBundleName__', 166 moduleName: '__harDefaultModuleName__', 167}; 168CounterResource.COUNTER_LIST_RIGHT_PADDING = { 169 id: -1, 170 type: 10002, 171 params: ['sys.float.ohos_id_default_padding_end'], 172 bundleName: '__harDefaultBundleName__', 173 moduleName: '__harDefaultModuleName__', 174}; 175CounterResource.COUNTER_COMPACT_BUTTON_ICON_SIZE = { 176 id: -1, 177 type: 10002, 178 params: ['sys.float.button_icon_size'], 179 bundleName: '__harDefaultBundleName__', 180 moduleName: '__harDefaultModuleName__', 181}; 182CounterResource.COUNTER_COMPACT_CONTAINER_HEIGHT = { 183 id: -1, 184 type: 10002, 185 params: ['sys.float.container_height'], 186 bundleName: '__harDefaultBundleName__', 187 moduleName: '__harDefaultModuleName__', 188}; 189CounterResource.COUNTER_BORDER_WIDTH = { 190 id: -1, 191 type: 10002, 192 params: ['sys.float.border_width'], 193 bundleName: '__harDefaultBundleName__', 194 moduleName: '__harDefaultModuleName__', 195}; 196CounterResource.COUNTER_COMPACT_BUTTON_SIZE = { 197 id: -1, 198 type: 10002, 199 params: ['sys.float.button_size'], 200 bundleName: '__harDefaultBundleName__', 201 moduleName: '__harDefaultModuleName__', 202}; 203CounterResource.COUNTER_COMPACT_CONTAINER_RADIUS = { 204 id: -1, 205 type: 10002, 206 params: ['sys.float.container_radius'], 207 bundleName: '__harDefaultBundleName__', 208 moduleName: '__harDefaultModuleName__', 209}; 210CounterResource.COUNTER_COMPACT_BUTTON_CONTAINER_MARGIN = { 211 id: -1, 212 type: 10002, 213 params: ['sys.float.button_container_margin'], 214 bundleName: '__harDefaultBundleName__', 215 moduleName: '__harDefaultModuleName__', 216}; 217CounterResource.COUNTER_LIST_PADDING = 12; 218CounterResource.COUNTER_LIST_HEIGHT = '48vp'; 219CounterResource.COUNTER_LIST_BUTTON_ICON_SIZE = '20vp'; 220CounterResource.COUNTER_LIST_BUTTON_SIZE = '32vp'; 221CounterResource.COUNTER_LIST_BUTTON_RADIUS = '16vp'; 222CounterResource.COUNTER_LIST_BUTTON_TEXT_DISTANCE = '8vp'; 223CounterResource.COUNTER_LIST_BUTTON_TEXT_MARGIN = 8; 224CounterResource.COUNTER_LIST_FOCUS_BORDER_SIZE = '30vp'; 225CounterResource.COUNTER_LIST_FOCUS_BORDER_RADIUS = '15vp'; 226CounterResource.COUNTER_LIST_BUTTON_HOT_SPOT_X = '-8vp'; 227CounterResource.COUNTER_LIST_BUTTON_HOT_SPOT_Y = '-8vp'; 228CounterResource.COUNTER_COMPACT_BUTTON_RADIUS = '12vp'; 229CounterResource.COUNTER_COMPACT_BUTTON_TEXT_DISTANCE = '10vp'; 230CounterResource.COUNTER_COMPACT_BUTTON_TEXT_MARGIN = 10; 231CounterResource.COUNTER_COMPACT_CONTAINER_LABEL_DISTANCE = '8vp'; 232CounterResource.COUNTER_COMPACT_FOCUS_BORDER_SIZE = '22vp'; 233CounterResource.COUNTER_COMPACT_FOCUS_BORDER_RADIUS = '11vp'; 234CounterResource.COUNTER_INLINE_BUTTON_ICON_WIDTH = '24vp'; 235CounterResource.COUNTER_INLINE_BUTTON_ICON_HEIGHT = '12vp'; 236CounterResource.COUNTER_INLINE_BUTTON_TEXT_DISTANCE = '12vp'; 237CounterResource.COUNTER_INLINE_CONTAINER_HEIGHT = '32vp'; 238CounterResource.COUNTER_INLINE_BUTTON_WIDTH = '32vp'; 239CounterResource.COUNTER_INLINE_BUTTON_HEIGHT = '16vp'; 240CounterResource.COUNTER_INLINE_RADIUS = '8vp'; 241CounterResource.COUNTER_INLINE_FOCUS_BORDER_WIDTH = '28vp'; 242CounterResource.COUNTER_INLINE_FOCUS_BORDER_HEIGHT = '13.5vp'; 243CounterResource.COUNTER_INLINE_DATE_TEXT_MARGIN = 12; 244CounterResource.COUNTER_INLINE_INPUT_TEXT_MARGIN = 12; 245CounterResource.COUNTER_BUTTON_INITIAL_OPACITY = 1; 246CounterResource.COUNTER_BUTTON_DISABLE_OPACITY = 0.4; 247CounterResource.COUNTER_LABEL_MAX_FONT_SIZE_SCALE = 2; 248CounterResource.COUNTER_NUMBER_MAX_FONT_SIZE_SCALE = 1; 249class CounterConstant {} 250CounterConstant.COUNTER_MAX_YEAR = 5000; 251CounterConstant.COUNTER_MIN_YEAR = 1; 252CounterConstant.COUNTER_INITIAL_MONTH = 1; 253CounterConstant.COUNTER_INITIAL_DAY = 1; 254CounterConstant.COUNTER_INITIAL_STEP = 1; 255CounterConstant.COUNTER_TEN_NUMBER = 10; 256CounterConstant.COUNTER_MIN_MONTH = 1; 257CounterConstant.COUNTER_MAX_MONTH = 12; 258CounterConstant.COUNTER_MIN_DAY = 1; 259CounterConstant.KEYCODE_DPAD_UP = 2012; 260CounterConstant.KEYCODE_DPAD_DOWN = 2013; 261CounterConstant.KEYCODE_DPAD_LEFT = 2014; 262CounterConstant.KEYCODE_DPAD_RIGHT = 2015; 263CounterConstant.KEYCODE_MOVE_HOME = 2081; 264CounterConstant.KEYCODE_MOVE_END = 2082; 265CounterConstant.KEYCODE_TAB = 2049; 266CounterConstant.KEYCODE_ESC = 2070; 267CounterConstant.COUNTER_MIN_VALUE = 0; 268CounterConstant.COUNTER_MAX_VALUE = 999; 269CounterConstant.JANUARY = 1; 270CounterConstant.FEBRUARY = 2; 271CounterConstant.MARCH = 3; 272CounterConstant.APRIL = 4; 273CounterConstant.MAY = 5; 274CounterConstant.JUNE = 6; 275CounterConstant.JULY = 7; 276CounterConstant.AUGUST = 8; 277CounterConstant.SEPTEMBER = 9; 278CounterConstant.OCTOBER = 10; 279CounterConstant.NOVEMBER = 11; 280CounterConstant.DECEMBER = 12; 281CounterConstant.BIG_MONTH_DAYS = 31; 282CounterConstant.SMALL_MONTH_DAYS = 30; 283CounterConstant.FEBRUARY_DAYS = 28; 284CounterConstant.AUSPICIOUS_FEBRUARY_DAYS = 29; 285CounterConstant.AUSPICIOUS_FOUR = 4; 286CounterConstant.AUSPICIOUS_HUNDRED = 100; 287CounterConstant.AUSPICIOUS_FOUR_HUNDRED = 400; 288export class CounterComponent extends ViewPU { 289 constructor( 290 parent, 291 params, 292 __localStorage, 293 elmtId = -1, 294 paramsLambda = undefined, 295 extraInfo 296 ) { 297 super(parent, __localStorage, elmtId, extraInfo); 298 if (typeof paramsLambda === 'function') { 299 this.paramsGenerator_ = paramsLambda; 300 } 301 this.__options = new SynchedPropertyObjectOneWayPU( 302 params.options, 303 this, 304 'options' 305 ); 306 this.__type = new ObservedPropertySimplePU(-1, this, 'type'); 307 this.__counterDirection = new ObservedPropertySimplePU( 308 Direction.Auto, 309 this, 310 'counterDirection' 311 ); 312 this.__choverEffect = new ObservedPropertySimplePU( 313 HoverEffect.Auto, 314 this, 315 'choverEffect' 316 ); 317 this.__focusEnable = new ObservedPropertySimplePU( 318 true, 319 this, 320 'focusEnable' 321 ); 322 this.__step = new ObservedPropertySimplePU( 323 CounterConstant.COUNTER_INITIAL_STEP, 324 this, 325 'step' 326 ); 327 this.__inputValue = new ObservedPropertySimplePU('0', this, 'inputValue'); 328 this.__inputYear = new ObservedPropertySimplePU( 329 CounterConstant.COUNTER_MIN_YEAR, 330 this, 331 'inputYear' 332 ); 333 this.__inputMoon = new ObservedPropertySimplePU(0, this, 'inputMoon'); 334 this.__inputDay = new ObservedPropertySimplePU(0, this, 'inputDay'); 335 this.__inputHour = new ObservedPropertySimplePU(0, this, 'inputHour'); 336 this.__inputMinute = new ObservedPropertySimplePU(0, this, 'inputMinute'); 337 this.__inputSecond = new ObservedPropertySimplePU(0, this, 'inputSecond'); 338 this.__subOpacity = new ObservedPropertySimplePU( 339 CounterResource.COUNTER_BUTTON_INITIAL_OPACITY, 340 this, 341 'subOpacity' 342 ); 343 this.__addOpacity = new ObservedPropertySimplePU( 344 CounterResource.COUNTER_BUTTON_INITIAL_OPACITY, 345 this, 346 'addOpacity' 347 ); 348 this.__subBtnStateEffect = new ObservedPropertySimplePU( 349 true, 350 this, 351 'subBtnStateEffect' 352 ); 353 this.__addBtnStateEffect = new ObservedPropertySimplePU( 354 true, 355 this, 356 'addBtnStateEffect' 357 ); 358 this.__focusText = new ObservedPropertySimplePU( 359 FocusText.NONE, 360 this, 361 'focusText' 362 ); 363 this.__hasFocusText1 = new ObservedPropertySimplePU( 364 false, 365 this, 366 'hasFocusText1' 367 ); 368 this.__hasFocusText2 = new ObservedPropertySimplePU( 369 false, 370 this, 371 'hasFocusText2' 372 ); 373 this.__hasFocusText3 = new ObservedPropertySimplePU( 374 false, 375 this, 376 'hasFocusText3' 377 ); 378 this.__subBtnFocusWidh = new ObservedPropertySimplePU( 379 '0vp', 380 this, 381 'subBtnFocusWidh' 382 ); 383 this.__addBtnFocusWidh = new ObservedPropertySimplePU( 384 '0vp', 385 this, 386 'addBtnFocusWidh' 387 ); 388 this.__value = new ObservedPropertySimplePU(0, this, 'value'); 389 this.__year = new ObservedPropertySimplePU(0, this, 'year'); 390 this.__month = new ObservedPropertySimplePU(0, this, 'month'); 391 this.__day = new ObservedPropertySimplePU(0, this, 'day'); 392 this.__hour = new ObservedPropertySimplePU(0, this, 'hour'); 393 this.__minute = new ObservedPropertySimplePU(0, this, 'minute'); 394 this.__second = new ObservedPropertySimplePU(0, this, 'second'); 395 this.__subBtnEnabled = new ObservedPropertySimplePU( 396 true, 397 this, 398 'subBtnEnabled' 399 ); 400 this.__addBtnEnabled = new ObservedPropertySimplePU( 401 true, 402 this, 403 'addBtnEnabled' 404 ); 405 this.__hasInputText1 = new ObservedPropertySimplePU( 406 false, 407 this, 408 'hasInputText1' 409 ); 410 this.__hasInputText2 = new ObservedPropertySimplePU( 411 false, 412 this, 413 'hasInputText2' 414 ); 415 this.__hasInputText3 = new ObservedPropertySimplePU( 416 false, 417 this, 418 'hasInputText3' 419 ); 420 this.__textWidth = new ObservedPropertySimplePU(0, this, 'textWidth'); 421 this.__min = new ObservedPropertySimplePU( 422 CounterConstant.COUNTER_MIN_VALUE, 423 this, 424 'min' 425 ); 426 this.__max = new ObservedPropertySimplePU( 427 CounterConstant.COUNTER_MAX_VALUE, 428 this, 429 'max' 430 ); 431 this.maxYear = CounterConstant.COUNTER_MAX_YEAR; 432 this.minYear = CounterConstant.COUNTER_MIN_YEAR; 433 this.numberStrList = [ 434 '00', 435 '01', 436 '02', 437 '03', 438 '04', 439 '05', 440 '06', 441 '07', 442 '08', 443 '09', 444 ]; 445 this.onHoverIncrease = undefined; 446 this.onHoverDecrease = undefined; 447 this.onFocusIncrease = undefined; 448 this.onFocusDecrease = undefined; 449 this.onBlurIncrease = undefined; 450 this.onBlurDecrease = undefined; 451 this.onChange = undefined; 452 this.onDateChange = undefined; 453 this.timeoutID1 = -1; 454 this.timeoutID2 = -1; 455 this.timeoutID3 = -1; 456 this.numberStyleOptions = new NumberStyleOptions(); 457 this.dateStyleOptions = new DateStyleOptions(); 458 this.inlineStyleOptions = new InlineStyleOptions(); 459 this.timeStamp = 0; 460 this.hasTextWidth = false; 461 this.controller1 = new TextInputController(); 462 this.controller2 = new TextInputController(); 463 this.controller3 = new TextInputController(); 464 this.initFlag = true; 465 this.increaseStr = getContext().resourceManager.getStringSync(125834852); 466 this.reduceStr = getContext().resourceManager.getStringSync(125834853); 467 this.setInitiallyProvidedValue(params); 468 this.declareWatch('options', this.onOptionsChange); 469 this.finalizeConstruction(); 470 } 471 setInitiallyProvidedValue(params) { 472 if (params.type !== undefined) { 473 this.type = params.type; 474 } 475 if (params.counterDirection !== undefined) { 476 this.counterDirection = params.counterDirection; 477 } 478 if (params.choverEffect !== undefined) { 479 this.choverEffect = params.choverEffect; 480 } 481 if (params.focusEnable !== undefined) { 482 this.focusEnable = params.focusEnable; 483 } 484 if (params.step !== undefined) { 485 this.step = params.step; 486 } 487 if (params.inputValue !== undefined) { 488 this.inputValue = params.inputValue; 489 } 490 if (params.inputYear !== undefined) { 491 this.inputYear = params.inputYear; 492 } 493 if (params.inputMoon !== undefined) { 494 this.inputMoon = params.inputMoon; 495 } 496 if (params.inputDay !== undefined) { 497 this.inputDay = params.inputDay; 498 } 499 if (params.inputHour !== undefined) { 500 this.inputHour = params.inputHour; 501 } 502 if (params.inputMinute !== undefined) { 503 this.inputMinute = params.inputMinute; 504 } 505 if (params.inputSecond !== undefined) { 506 this.inputSecond = params.inputSecond; 507 } 508 if (params.subOpacity !== undefined) { 509 this.subOpacity = params.subOpacity; 510 } 511 if (params.addOpacity !== undefined) { 512 this.addOpacity = params.addOpacity; 513 } 514 if (params.subBtnStateEffect !== undefined) { 515 this.subBtnStateEffect = params.subBtnStateEffect; 516 } 517 if (params.addBtnStateEffect !== undefined) { 518 this.addBtnStateEffect = params.addBtnStateEffect; 519 } 520 if (params.focusText !== undefined) { 521 this.focusText = params.focusText; 522 } 523 if (params.hasFocusText1 !== undefined) { 524 this.hasFocusText1 = params.hasFocusText1; 525 } 526 if (params.hasFocusText2 !== undefined) { 527 this.hasFocusText2 = params.hasFocusText2; 528 } 529 if (params.hasFocusText3 !== undefined) { 530 this.hasFocusText3 = params.hasFocusText3; 531 } 532 if (params.subBtnFocusWidh !== undefined) { 533 this.subBtnFocusWidh = params.subBtnFocusWidh; 534 } 535 if (params.addBtnFocusWidh !== undefined) { 536 this.addBtnFocusWidh = params.addBtnFocusWidh; 537 } 538 if (params.value !== undefined) { 539 this.value = params.value; 540 } 541 if (params.year !== undefined) { 542 this.year = params.year; 543 } 544 if (params.month !== undefined) { 545 this.month = params.month; 546 } 547 if (params.day !== undefined) { 548 this.day = params.day; 549 } 550 if (params.hour !== undefined) { 551 this.hour = params.hour; 552 } 553 if (params.minute !== undefined) { 554 this.minute = params.minute; 555 } 556 if (params.second !== undefined) { 557 this.second = params.second; 558 } 559 if (params.subBtnEnabled !== undefined) { 560 this.subBtnEnabled = params.subBtnEnabled; 561 } 562 if (params.addBtnEnabled !== undefined) { 563 this.addBtnEnabled = params.addBtnEnabled; 564 } 565 if (params.hasInputText1 !== undefined) { 566 this.hasInputText1 = params.hasInputText1; 567 } 568 if (params.hasInputText2 !== undefined) { 569 this.hasInputText2 = params.hasInputText2; 570 } 571 if (params.hasInputText3 !== undefined) { 572 this.hasInputText3 = params.hasInputText3; 573 } 574 if (params.textWidth !== undefined) { 575 this.textWidth = params.textWidth; 576 } 577 if (params.min !== undefined) { 578 this.min = params.min; 579 } 580 if (params.max !== undefined) { 581 this.max = params.max; 582 } 583 if (params.maxYear !== undefined) { 584 this.maxYear = params.maxYear; 585 } 586 if (params.minYear !== undefined) { 587 this.minYear = params.minYear; 588 } 589 if (params.numberStrList !== undefined) { 590 this.numberStrList = params.numberStrList; 591 } 592 if (params.onHoverIncrease !== undefined) { 593 this.onHoverIncrease = params.onHoverIncrease; 594 } 595 if (params.onHoverDecrease !== undefined) { 596 this.onHoverDecrease = params.onHoverDecrease; 597 } 598 if (params.onFocusIncrease !== undefined) { 599 this.onFocusIncrease = params.onFocusIncrease; 600 } 601 if (params.onFocusDecrease !== undefined) { 602 this.onFocusDecrease = params.onFocusDecrease; 603 } 604 if (params.onBlurIncrease !== undefined) { 605 this.onBlurIncrease = params.onBlurIncrease; 606 } 607 if (params.onBlurDecrease !== undefined) { 608 this.onBlurDecrease = params.onBlurDecrease; 609 } 610 if (params.onChange !== undefined) { 611 this.onChange = params.onChange; 612 } 613 if (params.onDateChange !== undefined) { 614 this.onDateChange = params.onDateChange; 615 } 616 if (params.timeoutID1 !== undefined) { 617 this.timeoutID1 = params.timeoutID1; 618 } 619 if (params.timeoutID2 !== undefined) { 620 this.timeoutID2 = params.timeoutID2; 621 } 622 if (params.timeoutID3 !== undefined) { 623 this.timeoutID3 = params.timeoutID3; 624 } 625 if (params.numberStyleOptions !== undefined) { 626 this.numberStyleOptions = params.numberStyleOptions; 627 } 628 if (params.dateStyleOptions !== undefined) { 629 this.dateStyleOptions = params.dateStyleOptions; 630 } 631 if (params.inlineStyleOptions !== undefined) { 632 this.inlineStyleOptions = params.inlineStyleOptions; 633 } 634 if (params.timeStamp !== undefined) { 635 this.timeStamp = params.timeStamp; 636 } 637 if (params.hasTextWidth !== undefined) { 638 this.hasTextWidth = params.hasTextWidth; 639 } 640 if (params.controller1 !== undefined) { 641 this.controller1 = params.controller1; 642 } 643 if (params.controller2 !== undefined) { 644 this.controller2 = params.controller2; 645 } 646 if (params.controller3 !== undefined) { 647 this.controller3 = params.controller3; 648 } 649 if (params.initFlag !== undefined) { 650 this.initFlag = params.initFlag; 651 } 652 if (params.increaseStr !== undefined) { 653 this.increaseStr = params.increaseStr; 654 } 655 if (params.reduceStr !== undefined) { 656 this.reduceStr = params.reduceStr; 657 } 658 } 659 updateStateVars(params) { 660 this.__options.reset(params.options); 661 } 662 purgeVariableDependenciesOnElmtId(rmElmtId) { 663 this.__options.purgeDependencyOnElmtId(rmElmtId); 664 this.__type.purgeDependencyOnElmtId(rmElmtId); 665 this.__counterDirection.purgeDependencyOnElmtId(rmElmtId); 666 this.__choverEffect.purgeDependencyOnElmtId(rmElmtId); 667 this.__focusEnable.purgeDependencyOnElmtId(rmElmtId); 668 this.__step.purgeDependencyOnElmtId(rmElmtId); 669 this.__inputValue.purgeDependencyOnElmtId(rmElmtId); 670 this.__inputYear.purgeDependencyOnElmtId(rmElmtId); 671 this.__inputMoon.purgeDependencyOnElmtId(rmElmtId); 672 this.__inputDay.purgeDependencyOnElmtId(rmElmtId); 673 this.__inputHour.purgeDependencyOnElmtId(rmElmtId); 674 this.__inputMinute.purgeDependencyOnElmtId(rmElmtId); 675 this.__inputSecond.purgeDependencyOnElmtId(rmElmtId); 676 this.__subOpacity.purgeDependencyOnElmtId(rmElmtId); 677 this.__addOpacity.purgeDependencyOnElmtId(rmElmtId); 678 this.__subBtnStateEffect.purgeDependencyOnElmtId(rmElmtId); 679 this.__addBtnStateEffect.purgeDependencyOnElmtId(rmElmtId); 680 this.__focusText.purgeDependencyOnElmtId(rmElmtId); 681 this.__hasFocusText1.purgeDependencyOnElmtId(rmElmtId); 682 this.__hasFocusText2.purgeDependencyOnElmtId(rmElmtId); 683 this.__hasFocusText3.purgeDependencyOnElmtId(rmElmtId); 684 this.__subBtnFocusWidh.purgeDependencyOnElmtId(rmElmtId); 685 this.__addBtnFocusWidh.purgeDependencyOnElmtId(rmElmtId); 686 this.__value.purgeDependencyOnElmtId(rmElmtId); 687 this.__year.purgeDependencyOnElmtId(rmElmtId); 688 this.__month.purgeDependencyOnElmtId(rmElmtId); 689 this.__day.purgeDependencyOnElmtId(rmElmtId); 690 this.__hour.purgeDependencyOnElmtId(rmElmtId); 691 this.__minute.purgeDependencyOnElmtId(rmElmtId); 692 this.__second.purgeDependencyOnElmtId(rmElmtId); 693 this.__subBtnEnabled.purgeDependencyOnElmtId(rmElmtId); 694 this.__addBtnEnabled.purgeDependencyOnElmtId(rmElmtId); 695 this.__hasInputText1.purgeDependencyOnElmtId(rmElmtId); 696 this.__hasInputText2.purgeDependencyOnElmtId(rmElmtId); 697 this.__hasInputText3.purgeDependencyOnElmtId(rmElmtId); 698 this.__textWidth.purgeDependencyOnElmtId(rmElmtId); 699 this.__min.purgeDependencyOnElmtId(rmElmtId); 700 this.__max.purgeDependencyOnElmtId(rmElmtId); 701 } 702 aboutToBeDeleted() { 703 this.__options.aboutToBeDeleted(); 704 this.__type.aboutToBeDeleted(); 705 this.__counterDirection.aboutToBeDeleted(); 706 this.__choverEffect.aboutToBeDeleted(); 707 this.__focusEnable.aboutToBeDeleted(); 708 this.__step.aboutToBeDeleted(); 709 this.__inputValue.aboutToBeDeleted(); 710 this.__inputYear.aboutToBeDeleted(); 711 this.__inputMoon.aboutToBeDeleted(); 712 this.__inputDay.aboutToBeDeleted(); 713 this.__inputHour.aboutToBeDeleted(); 714 this.__inputMinute.aboutToBeDeleted(); 715 this.__inputSecond.aboutToBeDeleted(); 716 this.__subOpacity.aboutToBeDeleted(); 717 this.__addOpacity.aboutToBeDeleted(); 718 this.__subBtnStateEffect.aboutToBeDeleted(); 719 this.__addBtnStateEffect.aboutToBeDeleted(); 720 this.__focusText.aboutToBeDeleted(); 721 this.__hasFocusText1.aboutToBeDeleted(); 722 this.__hasFocusText2.aboutToBeDeleted(); 723 this.__hasFocusText3.aboutToBeDeleted(); 724 this.__subBtnFocusWidh.aboutToBeDeleted(); 725 this.__addBtnFocusWidh.aboutToBeDeleted(); 726 this.__value.aboutToBeDeleted(); 727 this.__year.aboutToBeDeleted(); 728 this.__month.aboutToBeDeleted(); 729 this.__day.aboutToBeDeleted(); 730 this.__hour.aboutToBeDeleted(); 731 this.__minute.aboutToBeDeleted(); 732 this.__second.aboutToBeDeleted(); 733 this.__subBtnEnabled.aboutToBeDeleted(); 734 this.__addBtnEnabled.aboutToBeDeleted(); 735 this.__hasInputText1.aboutToBeDeleted(); 736 this.__hasInputText2.aboutToBeDeleted(); 737 this.__hasInputText3.aboutToBeDeleted(); 738 this.__textWidth.aboutToBeDeleted(); 739 this.__min.aboutToBeDeleted(); 740 this.__max.aboutToBeDeleted(); 741 SubscriberManager.Get().delete(this.id__()); 742 this.aboutToBeDeletedInternal(); 743 } 744 get options() { 745 return this.__options.get(); 746 } 747 set options(newValue) { 748 this.__options.set(newValue); 749 } 750 get type() { 751 return this.__type.get(); 752 } 753 set type(newValue) { 754 this.__type.set(newValue); 755 } 756 get counterDirection() { 757 return this.__counterDirection.get(); 758 } 759 set counterDirection(newValue) { 760 this.__counterDirection.set(newValue); 761 } 762 get choverEffect() { 763 return this.__choverEffect.get(); 764 } 765 set choverEffect(newValue) { 766 this.__choverEffect.set(newValue); 767 } 768 get focusEnable() { 769 return this.__focusEnable.get(); 770 } 771 set focusEnable(newValue) { 772 this.__focusEnable.set(newValue); 773 } 774 get step() { 775 return this.__step.get(); 776 } 777 set step(newValue) { 778 this.__step.set(newValue); 779 } 780 get inputValue() { 781 return this.__inputValue.get(); 782 } 783 set inputValue(newValue) { 784 this.__inputValue.set(newValue); 785 } 786 get inputYear() { 787 return this.__inputYear.get(); 788 } 789 set inputYear(newValue) { 790 this.__inputYear.set(newValue); 791 } 792 get inputMoon() { 793 return this.__inputMoon.get(); 794 } 795 set inputMoon(newValue) { 796 this.__inputMoon.set(newValue); 797 } 798 get inputDay() { 799 return this.__inputDay.get(); 800 } 801 set inputDay(newValue) { 802 this.__inputDay.set(newValue); 803 } 804 get inputHour() { 805 return this.__inputHour.get(); 806 } 807 set inputHour(newValue) { 808 this.__inputHour.set(newValue); 809 } 810 get inputMinute() { 811 return this.__inputMinute.get(); 812 } 813 set inputMinute(newValue) { 814 this.__inputMinute.set(newValue); 815 } 816 get inputSecond() { 817 return this.__inputSecond.get(); 818 } 819 set inputSecond(newValue) { 820 this.__inputSecond.set(newValue); 821 } 822 get subOpacity() { 823 return this.__subOpacity.get(); 824 } 825 set subOpacity(newValue) { 826 this.__subOpacity.set(newValue); 827 } 828 get addOpacity() { 829 return this.__addOpacity.get(); 830 } 831 set addOpacity(newValue) { 832 this.__addOpacity.set(newValue); 833 } 834 get subBtnStateEffect() { 835 return this.__subBtnStateEffect.get(); 836 } 837 set subBtnStateEffect(newValue) { 838 this.__subBtnStateEffect.set(newValue); 839 } 840 get addBtnStateEffect() { 841 return this.__addBtnStateEffect.get(); 842 } 843 set addBtnStateEffect(newValue) { 844 this.__addBtnStateEffect.set(newValue); 845 } 846 get focusText() { 847 return this.__focusText.get(); 848 } 849 set focusText(newValue) { 850 this.__focusText.set(newValue); 851 } 852 get hasFocusText1() { 853 return this.__hasFocusText1.get(); 854 } 855 set hasFocusText1(newValue) { 856 this.__hasFocusText1.set(newValue); 857 } 858 get hasFocusText2() { 859 return this.__hasFocusText2.get(); 860 } 861 set hasFocusText2(newValue) { 862 this.__hasFocusText2.set(newValue); 863 } 864 get hasFocusText3() { 865 return this.__hasFocusText3.get(); 866 } 867 set hasFocusText3(newValue) { 868 this.__hasFocusText3.set(newValue); 869 } 870 get subBtnFocusWidh() { 871 return this.__subBtnFocusWidh.get(); 872 } 873 set subBtnFocusWidh(newValue) { 874 this.__subBtnFocusWidh.set(newValue); 875 } 876 get addBtnFocusWidh() { 877 return this.__addBtnFocusWidh.get(); 878 } 879 set addBtnFocusWidh(newValue) { 880 this.__addBtnFocusWidh.set(newValue); 881 } 882 get value() { 883 return this.__value.get(); 884 } 885 set value(newValue) { 886 this.__value.set(newValue); 887 } 888 get year() { 889 return this.__year.get(); 890 } 891 set year(newValue) { 892 this.__year.set(newValue); 893 } 894 get month() { 895 return this.__month.get(); 896 } 897 set month(newValue) { 898 this.__month.set(newValue); 899 } 900 get day() { 901 return this.__day.get(); 902 } 903 set day(newValue) { 904 this.__day.set(newValue); 905 } 906 get hour() { 907 return this.__hour.get(); 908 } 909 set hour(newValue) { 910 this.__hour.set(newValue); 911 } 912 get minute() { 913 return this.__minute.get(); 914 } 915 set minute(newValue) { 916 this.__minute.set(newValue); 917 } 918 get second() { 919 return this.__second.get(); 920 } 921 set second(newValue) { 922 this.__second.set(newValue); 923 } 924 get subBtnEnabled() { 925 return this.__subBtnEnabled.get(); 926 } 927 set subBtnEnabled(newValue) { 928 this.__subBtnEnabled.set(newValue); 929 } 930 get addBtnEnabled() { 931 return this.__addBtnEnabled.get(); 932 } 933 set addBtnEnabled(newValue) { 934 this.__addBtnEnabled.set(newValue); 935 } 936 get hasInputText1() { 937 return this.__hasInputText1.get(); 938 } 939 set hasInputText1(newValue) { 940 this.__hasInputText1.set(newValue); 941 } 942 get hasInputText2() { 943 return this.__hasInputText2.get(); 944 } 945 set hasInputText2(newValue) { 946 this.__hasInputText2.set(newValue); 947 } 948 get hasInputText3() { 949 return this.__hasInputText3.get(); 950 } 951 set hasInputText3(newValue) { 952 this.__hasInputText3.set(newValue); 953 } 954 get textWidth() { 955 return this.__textWidth.get(); 956 } 957 set textWidth(newValue) { 958 this.__textWidth.set(newValue); 959 } 960 get min() { 961 return this.__min.get(); 962 } 963 set min(newValue) { 964 this.__min.set(newValue); 965 } 966 get max() { 967 return this.__max.get(); 968 } 969 set max(newValue) { 970 this.__max.set(newValue); 971 } 972 getTextInputFontSize() { 973 let fontSize = this.resourceToVp(CounterResource.COUNTER_NUMBER_SIZE); 974 let uiContext = this.getUIContext(); 975 let fontSizeScale = uiContext.getHostContext()?.config?.fontSizeScale ?? 1; 976 if (fontSizeScale < 1) { 977 return fontSize + 'fp'; 978 } else { 979 return fontSize + 'vp'; 980 } 981 } 982 getDate(value) { 983 return `[n2] ${value} [n0]`; 984 } 985 getDateYear(value) { 986 let locale = new intl.Locale(); 987 let localeID = locale.toString(); 988 let date = new Date(this.year, this.month - 1, this.day); 989 date.setFullYear(this.year); 990 let dateFormatYear = new intl.DateTimeFormat(localeID, { year: 'numeric' }); 991 let formattedDateYear = dateFormatYear.format(date); 992 return this.getDate(formattedDateYear); 993 } 994 getDateMonth(value) { 995 let locale = new intl.Locale(); 996 let localeID = locale.toString(); 997 let date = new Date(this.year, this.month - 1, this.day); 998 date.setFullYear(this.year); 999 let dateFormatMonth = new intl.DateTimeFormat(localeID, { month: 'long' }); 1000 let formattedDateMonth = dateFormatMonth.format(date); 1001 return this.getDate(formattedDateMonth); 1002 } 1003 getDateDay(value) { 1004 let dateDayMap = new Map([ 1005 [ 1006 1, 1007 getContext().resourceManager.getStringByNameSync( 1008 'First_counter_accessibility_text' 1009 ), 1010 ], 1011 [ 1012 2, 1013 getContext().resourceManager.getStringByNameSync( 1014 'Second_counter_accessibility_text' 1015 ), 1016 ], 1017 [ 1018 3, 1019 getContext().resourceManager.getStringByNameSync( 1020 'Third_counter_accessibility_text' 1021 ), 1022 ], 1023 [ 1024 4, 1025 getContext().resourceManager.getStringByNameSync( 1026 'Fourth_counter_accessibility_text' 1027 ), 1028 ], 1029 [ 1030 5, 1031 getContext().resourceManager.getStringByNameSync( 1032 'Fifth_counter_accessibility_text' 1033 ), 1034 ], 1035 [ 1036 6, 1037 getContext().resourceManager.getStringByNameSync( 1038 'Sixth_counter_accessibility_text' 1039 ), 1040 ], 1041 [ 1042 7, 1043 getContext().resourceManager.getStringByNameSync( 1044 'Seventh_counter_accessibility_text' 1045 ), 1046 ], 1047 [ 1048 8, 1049 getContext().resourceManager.getStringByNameSync( 1050 'Eighth_counter_accessibility_text' 1051 ), 1052 ], 1053 [ 1054 9, 1055 getContext().resourceManager.getStringByNameSync( 1056 'Ninth_counter_accessibility_text' 1057 ), 1058 ], 1059 [ 1060 10, 1061 getContext().resourceManager.getStringByNameSync( 1062 'Tenth_counter_accessibility_text' 1063 ), 1064 ], 1065 [ 1066 11, 1067 getContext().resourceManager.getStringByNameSync( 1068 'Eleventh_counter_accessibility_text' 1069 ), 1070 ], 1071 [ 1072 12, 1073 getContext().resourceManager.getStringByNameSync( 1074 'Twelfth_counter_accessibility_text' 1075 ), 1076 ], 1077 [ 1078 13, 1079 getContext().resourceManager.getStringByNameSync( 1080 'Thirteenth_counter_accessibility_text' 1081 ), 1082 ], 1083 [ 1084 14, 1085 getContext().resourceManager.getStringByNameSync( 1086 'Fourteenth_counter_accessibility_text' 1087 ), 1088 ], 1089 [ 1090 15, 1091 getContext().resourceManager.getStringByNameSync( 1092 'Fifteenth_counter_accessibility_text' 1093 ), 1094 ], 1095 [ 1096 16, 1097 getContext().resourceManager.getStringByNameSync( 1098 'Sixteenth_counter_accessibility_text' 1099 ), 1100 ], 1101 [ 1102 17, 1103 getContext().resourceManager.getStringByNameSync( 1104 'Seventeenth_counter_accessibility_text' 1105 ), 1106 ], 1107 [ 1108 18, 1109 getContext().resourceManager.getStringByNameSync( 1110 'Eighteenth_counter_accessibility_text' 1111 ), 1112 ], 1113 [ 1114 19, 1115 getContext().resourceManager.getStringByNameSync( 1116 'Nineteenth_counter_accessibility_text' 1117 ), 1118 ], 1119 [ 1120 20, 1121 getContext().resourceManager.getStringByNameSync( 1122 'Twentieth_counter_accessibility_text' 1123 ), 1124 ], 1125 [ 1126 21, 1127 getContext().resourceManager.getStringByNameSync( 1128 'TwentyFirst_counter_accessibility_text' 1129 ), 1130 ], 1131 [ 1132 22, 1133 getContext().resourceManager.getStringByNameSync( 1134 'TwentySecond_counter_accessibility_text' 1135 ), 1136 ], 1137 [ 1138 23, 1139 getContext().resourceManager.getStringByNameSync( 1140 'TwentyThird_counter_accessibility_text' 1141 ), 1142 ], 1143 [ 1144 24, 1145 getContext().resourceManager.getStringByNameSync( 1146 'TwentyFourth_counter_accessibility_text' 1147 ), 1148 ], 1149 [ 1150 25, 1151 getContext().resourceManager.getStringByNameSync( 1152 'TwentyFifth_counter_accessibility_text' 1153 ), 1154 ], 1155 [ 1156 26, 1157 getContext().resourceManager.getStringByNameSync( 1158 'TwentySixth_counter_accessibility_text' 1159 ), 1160 ], 1161 [ 1162 27, 1163 getContext().resourceManager.getStringByNameSync( 1164 'TwentySeventh_counter_accessibility_text' 1165 ), 1166 ], 1167 [ 1168 28, 1169 getContext().resourceManager.getStringByNameSync( 1170 'TwentyEighth_counter_accessibility_text' 1171 ), 1172 ], 1173 [ 1174 29, 1175 getContext().resourceManager.getStringByNameSync( 1176 'TwentyNinth_counter_accessibility_text' 1177 ), 1178 ], 1179 [ 1180 30, 1181 getContext().resourceManager.getStringByNameSync( 1182 'Thirtieth_counter_accessibility_text' 1183 ), 1184 ], 1185 [ 1186 31, 1187 getContext().resourceManager.getStringByNameSync( 1188 'ThirtyFirst_counter_accessibility_text' 1189 ), 1190 ], 1191 ]); 1192 return this.getDate(dateDayMap.get(this.day)); 1193 } 1194 convertNumberToString(value) { 1195 if (value >= 0 && value < CounterConstant.COUNTER_TEN_NUMBER) { 1196 return this.numberStrList[value]; 1197 } else { 1198 return value.toString(); 1199 } 1200 } 1201 aboutToAppear() { 1202 let dateTime = new Date(); 1203 this.timeStamp = dateTime.getTime(); 1204 if (this.options !== undefined && this.options !== null) { 1205 this.onOptionsChange(); 1206 } 1207 } 1208 updateNumberStyleOptions() { 1209 if (this.numberStyleOptions.label === undefined) { 1210 this.numberStyleOptions.label = ''; 1211 } 1212 if (this.initFlag) { 1213 this.initFlag = false; 1214 this.value = 1215 this.numberStyleOptions.value !== undefined 1216 ? this.numberStyleOptions.value 1217 : 0; 1218 this.onChange?.(this.value); 1219 this.inputValue = this.value.toString(); 1220 } 1221 if (this.numberStyleOptions.min !== undefined) { 1222 this.min = this.numberStyleOptions.min; 1223 } 1224 if (this.numberStyleOptions.max !== undefined) { 1225 this.max = this.numberStyleOptions.max; 1226 } 1227 if (this.min > this.max) { 1228 this.min = this.max; 1229 } 1230 if (this.numberStyleOptions.textWidth !== undefined) { 1231 this.textWidth = this.numberStyleOptions.textWidth; 1232 if (this.textWidth < 0) { 1233 this.textWidth = 0; 1234 } 1235 this.hasTextWidth = true; 1236 } 1237 if (this.value <= this.min) { 1238 this.value = this.min; 1239 this.onChange?.(this.value); 1240 this.inputValue = this.value.toString(); 1241 } 1242 if (this.value >= this.max) { 1243 this.value = this.max; 1244 this.onChange?.(this.value); 1245 this.inputValue = this.value.toString(); 1246 } 1247 if (this.numberStyleOptions.step !== undefined) { 1248 if (this.numberStyleOptions.step < 1) { 1249 this.step = 1; 1250 } else { 1251 this.step = this.numberStyleOptions.step; 1252 } 1253 } 1254 this.updateButtonStatus(); 1255 this.updateNumberStyleOptionsEvent(); 1256 } 1257 updateNumberStyleOptionsEvent() { 1258 if (this.numberStyleOptions.onHoverIncrease !== undefined) { 1259 this.onHoverIncrease = this.numberStyleOptions.onHoverIncrease; 1260 } 1261 if (this.numberStyleOptions.onHoverDecrease !== undefined) { 1262 this.onHoverDecrease = this.numberStyleOptions.onHoverDecrease; 1263 } 1264 if (this.numberStyleOptions.onFocusIncrease !== undefined) { 1265 this.onFocusIncrease = this.numberStyleOptions.onFocusIncrease; 1266 } 1267 if (this.numberStyleOptions.onFocusDecrease !== undefined) { 1268 this.onFocusDecrease = this.numberStyleOptions.onFocusDecrease; 1269 } 1270 if (this.numberStyleOptions.onBlurIncrease !== undefined) { 1271 this.onBlurIncrease = this.numberStyleOptions.onBlurIncrease; 1272 } 1273 if (this.numberStyleOptions.onBlurDecrease !== undefined) { 1274 this.onBlurDecrease = this.numberStyleOptions.onBlurDecrease; 1275 } 1276 if (this.numberStyleOptions.onChange !== undefined) { 1277 this.onChange = this.numberStyleOptions.onChange; 1278 } 1279 if (this.numberStyleOptions.focusable !== undefined) { 1280 this.focusEnable = this.numberStyleOptions.focusable; 1281 } 1282 } 1283 updateInlineStyleOptions() { 1284 if (this.initFlag) { 1285 this.initFlag = false; 1286 this.value = 1287 this.inlineStyleOptions.value !== undefined 1288 ? this.inlineStyleOptions.value 1289 : 0; 1290 this.onChange?.(this.value); 1291 this.inputValue = this.value.toString(); 1292 } 1293 if (this.inlineStyleOptions.min !== undefined) { 1294 this.min = this.inlineStyleOptions.min; 1295 } 1296 if (this.inlineStyleOptions.max !== undefined) { 1297 this.max = this.inlineStyleOptions.max; 1298 } 1299 if (this.min > this.max) { 1300 this.min = this.max; 1301 } 1302 if (this.inlineStyleOptions.textWidth !== undefined) { 1303 this.textWidth = this.inlineStyleOptions.textWidth; 1304 if (this.textWidth < 0) { 1305 this.textWidth = 0; 1306 } 1307 this.hasTextWidth = true; 1308 } 1309 if (this.value <= this.min) { 1310 this.value = this.min; 1311 this.onChange?.(this.value); 1312 this.inputValue = this.value.toString(); 1313 } 1314 if (this.value >= this.max) { 1315 this.value = this.max; 1316 this.onChange?.(this.value); 1317 this.inputValue = this.value.toString(); 1318 } 1319 if (this.inlineStyleOptions.step !== undefined) { 1320 if (this.inlineStyleOptions.step < 1) { 1321 this.step = 1; 1322 } else { 1323 this.step = this.inlineStyleOptions.step; 1324 } 1325 } 1326 this.updateButtonStatus(); 1327 this.updateInlineStyleOptionsEvent(); 1328 } 1329 updateInlineStyleOptionsEvent() { 1330 if (this.inlineStyleOptions.onHoverIncrease !== undefined) { 1331 this.onHoverIncrease = this.inlineStyleOptions.onHoverIncrease; 1332 } 1333 if (this.inlineStyleOptions.onHoverDecrease !== undefined) { 1334 this.onHoverDecrease = this.inlineStyleOptions.onHoverDecrease; 1335 } 1336 if (this.inlineStyleOptions.onChange !== undefined) { 1337 this.onChange = this.inlineStyleOptions.onChange; 1338 } 1339 if (this.inlineStyleOptions.focusable !== undefined) { 1340 this.focusEnable = this.inlineStyleOptions.focusable; 1341 } 1342 } 1343 updateDateStyleOptions() { 1344 if (this.dateStyleOptions.step !== undefined) { 1345 if (this.dateStyleOptions.step < 1) { 1346 this.step = 1; 1347 } else { 1348 this.step = Math.floor(this.dateStyleOptions.step); 1349 } 1350 } 1351 if (this.dateStyleOptions.onHoverIncrease !== undefined) { 1352 this.onHoverIncrease = this.dateStyleOptions.onHoverIncrease; 1353 } 1354 if (this.dateStyleOptions.onHoverDecrease !== undefined) { 1355 this.onHoverDecrease = this.dateStyleOptions.onHoverDecrease; 1356 } 1357 if ( 1358 this.dateStyleOptions.year !== undefined && 1359 this.dateStyleOptions.year >= this.minYear && 1360 this.dateStyleOptions.year <= this.maxYear 1361 ) { 1362 if (this.year === 0) { 1363 this.year = this.dateStyleOptions.year; 1364 } 1365 } else { 1366 this.year = CounterConstant.COUNTER_MIN_YEAR; 1367 } 1368 if ( 1369 this.dateStyleOptions.month !== undefined && 1370 this.dateStyleOptions.month <= CounterConstant.COUNTER_MAX_MONTH && 1371 this.dateStyleOptions.month >= CounterConstant.COUNTER_MIN_MONTH 1372 ) { 1373 if (this.month === 0) { 1374 this.month = this.dateStyleOptions.month; 1375 } 1376 } else { 1377 this.month = CounterConstant.COUNTER_INITIAL_MONTH; 1378 } 1379 if ( 1380 this.dateStyleOptions.day !== undefined && 1381 this.dateStyleOptions.day <= this.getDayNumber() && 1382 this.dateStyleOptions.day >= CounterConstant.COUNTER_MIN_DAY 1383 ) { 1384 if (this.day === 0) { 1385 this.day = this.dateStyleOptions.day; 1386 } 1387 } else { 1388 this.day = CounterConstant.COUNTER_INITIAL_DAY; 1389 } 1390 if (this.dateStyleOptions.onDateChange !== undefined) { 1391 this.onDateChange = this.dateStyleOptions.onDateChange; 1392 } 1393 if (this.dateStyleOptions.focusable !== undefined) { 1394 this.focusEnable = this.dateStyleOptions.focusable; 1395 } 1396 this.updateDay(); 1397 } 1398 onOptionsChange() { 1399 this.type = this.options.type; 1400 if (this.options.direction) { 1401 this.counterDirection = this.options.direction; 1402 } else { 1403 this.counterDirection = Direction.Auto; 1404 } 1405 if (this.type === CounterType.LIST || this.type === CounterType.COMPACT) { 1406 if (this.options.numberOptions !== undefined) { 1407 this.numberStyleOptions = this.options.numberOptions; 1408 } 1409 this.updateNumberStyleOptions(); 1410 } else if (this.type === CounterType.INLINE) { 1411 if (this.options.inlineOptions !== undefined) { 1412 this.inlineStyleOptions = this.options.inlineOptions; 1413 } 1414 this.updateInlineStyleOptions(); 1415 } else if (this.type === CounterType.INLINE_DATE) { 1416 let options = this.options.dateOptions; 1417 if (options !== undefined) { 1418 options.year = options.year 1419 ? options.year 1420 : CounterConstant.COUNTER_MIN_YEAR; 1421 options.month = options.month 1422 ? options.month 1423 : CounterConstant.COUNTER_MIN_MONTH; 1424 options.day = options.day 1425 ? options.day 1426 : CounterConstant.COUNTER_MIN_DAY; 1427 this.dateStyleOptions = options; 1428 } 1429 this.updateDateStyleOptions(); 1430 } else { 1431 } 1432 } 1433 subValue() { 1434 if (this.subBtnStateEffect) { 1435 this.value -= this.step; 1436 } 1437 if (!this.addBtnStateEffect) { 1438 this.addBtnStateEffect = true; 1439 this.addOpacity = CounterResource.COUNTER_BUTTON_INITIAL_OPACITY; 1440 this.addBtnEnabled = true; 1441 } 1442 if (this.value <= this.min) { 1443 this.value = this.min; 1444 this.subOpacity = CounterResource.COUNTER_BUTTON_DISABLE_OPACITY; 1445 this.subBtnStateEffect = false; 1446 this.subBtnEnabled = false; 1447 } else { 1448 if (this.subOpacity === CounterResource.COUNTER_BUTTON_DISABLE_OPACITY) { 1449 this.subOpacity = CounterResource.COUNTER_BUTTON_INITIAL_OPACITY; 1450 } 1451 if (!this.subBtnStateEffect) { 1452 this.subBtnStateEffect = true; 1453 } 1454 if (!this.subBtnEnabled) { 1455 this.subBtnEnabled = true; 1456 } 1457 } 1458 this.focusText1(); 1459 } 1460 focusText1() { 1461 if (this.type === CounterType.INLINE) { 1462 if (this.focusText === FocusText.NONE) { 1463 this.focusText = FocusText.TEXT1; 1464 this.hasFocusText1 = true; 1465 this.focusWithTarget('InlineTextInput' + this.timeStamp.toString()); 1466 } 1467 } 1468 } 1469 addValue() { 1470 if (this.addBtnStateEffect) { 1471 this.value += this.step; 1472 } 1473 if (!this.subBtnStateEffect) { 1474 this.subBtnStateEffect = true; 1475 this.subOpacity = CounterResource.COUNTER_BUTTON_INITIAL_OPACITY; 1476 this.subBtnEnabled = true; 1477 } 1478 if (this.value >= this.max) { 1479 this.value = this.max; 1480 this.addOpacity = CounterResource.COUNTER_BUTTON_DISABLE_OPACITY; 1481 this.addBtnStateEffect = false; 1482 this.addBtnEnabled = false; 1483 } else { 1484 if (this.addOpacity === CounterResource.COUNTER_BUTTON_DISABLE_OPACITY) { 1485 this.addOpacity = CounterResource.COUNTER_BUTTON_INITIAL_OPACITY; 1486 } 1487 if (!this.addBtnStateEffect) { 1488 this.addBtnStateEffect = true; 1489 } 1490 if (!this.addBtnEnabled) { 1491 this.addBtnEnabled = true; 1492 } 1493 } 1494 this.focusText1(); 1495 } 1496 getDayNumber() { 1497 switch (this.month) { 1498 case CounterConstant.JANUARY: 1499 case CounterConstant.MARCH: 1500 case CounterConstant.MAY: 1501 case CounterConstant.JULY: 1502 case CounterConstant.AUGUST: 1503 case CounterConstant.OCTOBER: 1504 case CounterConstant.DECEMBER: 1505 return CounterConstant.BIG_MONTH_DAYS; 1506 break; 1507 case CounterConstant.APRIL: 1508 case CounterConstant.JUNE: 1509 case CounterConstant.SEPTEMBER: 1510 case CounterConstant.NOVEMBER: 1511 return CounterConstant.SMALL_MONTH_DAYS; 1512 break; 1513 case CounterConstant.FEBRUARY: 1514 if ( 1515 (this.year % CounterConstant.AUSPICIOUS_FOUR === 0 && 1516 this.year % CounterConstant.AUSPICIOUS_HUNDRED !== 0) || 1517 this.year % CounterConstant.AUSPICIOUS_FOUR_HUNDRED === 0 1518 ) { 1519 return CounterConstant.AUSPICIOUS_FEBRUARY_DAYS; 1520 } else { 1521 return CounterConstant.FEBRUARY_DAYS; 1522 } 1523 break; 1524 default: 1525 return CounterConstant.SMALL_MONTH_DAYS; 1526 break; 1527 } 1528 } 1529 accessibilityBroadcastSubDate() { 1530 if (this.focusText === FocusText.TEXT1) { 1531 if (this.subBtnStateEffect) { 1532 this.inputYear = this.year; 1533 this.year -= this.step; 1534 if (!this.hasFocusText1) { 1535 this.hasFocusText1 = true; 1536 } 1537 } 1538 if (!this.addBtnStateEffect) { 1539 this.addBtnStateEffect = true; 1540 this.addOpacity = CounterResource.COUNTER_BUTTON_INITIAL_OPACITY; 1541 this.addBtnEnabled = true; 1542 } 1543 if (this.year <= this.minYear) { 1544 this.subOpacity = CounterResource.COUNTER_BUTTON_DISABLE_OPACITY; 1545 this.subBtnStateEffect = false; 1546 this.subBtnEnabled = false; 1547 } else { 1548 if ( 1549 this.subOpacity === CounterResource.COUNTER_BUTTON_DISABLE_OPACITY 1550 ) { 1551 this.subOpacity = CounterResource.COUNTER_BUTTON_INITIAL_OPACITY; 1552 } 1553 if (!this.subBtnStateEffect) { 1554 this.subBtnStateEffect = true; 1555 } 1556 if (!this.subBtnEnabled) { 1557 this.subBtnEnabled = true; 1558 } 1559 } 1560 try { 1561 let eventInfo = { 1562 type: 'announceForAccessibility', 1563 bundleName: getContext()?.abilityInfo?.bundleName, 1564 triggerAction: 'click', 1565 textAnnouncedForAccessibility: 1566 this.getDateYear(this.year) + 1567 ',' + 1568 this.getDateYear(this.year) + 1569 '/' + 1570 this.getDateMonth(this.month) + 1571 '/' + 1572 this.getDateDay(this.day), 1573 }; 1574 accessibility.sendAccessibilityEvent(eventInfo).then(() => { 1575 console.log('Accessility subYear click send event'); 1576 }); 1577 } catch (exception) { 1578 let code = exception.code; 1579 let message = exception.message; 1580 console.log( 1581 `Accessility subYear faild error code:${code} message:${message}` 1582 ); 1583 } 1584 } else if (this.focusText === FocusText.TEXT2) { 1585 this.month -= this.step % CounterConstant.COUNTER_MAX_MONTH; 1586 if (this.month < CounterConstant.COUNTER_MIN_MONTH) { 1587 this.month += CounterConstant.COUNTER_MAX_MONTH; 1588 } 1589 if (!this.hasFocusText2) { 1590 this.hasFocusText2 = true; 1591 } 1592 try { 1593 let eventInfo = { 1594 type: 'announceForAccessibility', 1595 bundleName: getContext()?.abilityInfo?.bundleName, 1596 triggerAction: 'click', 1597 textAnnouncedForAccessibility: 1598 this.getDateMonth(this.month) + 1599 ',' + 1600 this.getDateYear(this.year) + 1601 '/' + 1602 this.getDateMonth(this.month) + 1603 '/' + 1604 this.getDateDay(this.day), 1605 }; 1606 accessibility.sendAccessibilityEvent(eventInfo).then(() => { 1607 console.log('Accessility subMonth click send event'); 1608 }); 1609 } catch (exception) { 1610 let code = exception.code; 1611 let message = exception.message; 1612 console.log( 1613 `Accessility subMonth faild error code:${code} message:${message}` 1614 ); 1615 } 1616 } else if (this.focusText === FocusText.TEXT3) { 1617 this.day -= this.step % this.getDayNumber(); 1618 if (this.day < CounterConstant.COUNTER_MIN_DAY) { 1619 this.day += this.getDayNumber(); 1620 } 1621 if (!this.hasFocusText3) { 1622 this.hasFocusText3 = true; 1623 } 1624 try { 1625 let eventInfo = { 1626 type: 'announceForAccessibility', 1627 bundleName: getContext()?.abilityInfo?.bundleName, 1628 triggerAction: 'click', 1629 textAnnouncedForAccessibility: 1630 this.getDateDay(this.day) + 1631 ',' + 1632 this.getDateYear(this.year) + 1633 '/' + 1634 this.getDateMonth(this.month) + 1635 '/' + 1636 this.getDateDay(this.day), 1637 }; 1638 accessibility.sendAccessibilityEvent(eventInfo).then(() => { 1639 console.log('Accessility subDay click send event'); 1640 }); 1641 } catch (exception) { 1642 let code = exception.code; 1643 let message = exception.message; 1644 console.log( 1645 `Accessility subDay faild error code:${code} message:${message}` 1646 ); 1647 } 1648 } else { 1649 this.focusDayWitdhSub(); 1650 } 1651 } 1652 subDate() { 1653 if (this.focusText === FocusText.TEXT1) { 1654 if (this.subBtnStateEffect) { 1655 this.inputYear = this.year; 1656 this.year -= this.step; 1657 if (!this.hasFocusText1) { 1658 this.hasFocusText1 = true; 1659 } 1660 } 1661 if (!this.addBtnStateEffect) { 1662 this.addBtnStateEffect = true; 1663 this.addOpacity = CounterResource.COUNTER_BUTTON_INITIAL_OPACITY; 1664 this.addBtnEnabled = true; 1665 } 1666 if (this.year <= this.minYear) { 1667 this.subOpacity = CounterResource.COUNTER_BUTTON_DISABLE_OPACITY; 1668 this.subBtnStateEffect = false; 1669 this.subBtnEnabled = false; 1670 } else { 1671 if ( 1672 this.subOpacity === CounterResource.COUNTER_BUTTON_DISABLE_OPACITY 1673 ) { 1674 this.subOpacity = CounterResource.COUNTER_BUTTON_INITIAL_OPACITY; 1675 } 1676 if (!this.subBtnStateEffect) { 1677 this.subBtnStateEffect = true; 1678 } 1679 if (!this.subBtnEnabled) { 1680 this.subBtnEnabled = true; 1681 } 1682 } 1683 } else if (this.focusText === FocusText.TEXT2) { 1684 this.month -= this.step % CounterConstant.COUNTER_MAX_MONTH; 1685 if (this.month < CounterConstant.COUNTER_MIN_MONTH) { 1686 this.month += CounterConstant.COUNTER_MAX_MONTH; 1687 } 1688 if (!this.hasFocusText2) { 1689 this.hasFocusText2 = true; 1690 } 1691 } else if (this.focusText === FocusText.TEXT3) { 1692 this.day -= this.step % this.getDayNumber(); 1693 if (this.day < CounterConstant.COUNTER_MIN_DAY) { 1694 this.day += this.getDayNumber(); 1695 } 1696 if (!this.hasFocusText3) { 1697 this.hasFocusText3 = true; 1698 } 1699 } else { 1700 this.focusDayWitdhSub(); 1701 } 1702 } 1703 focusDayWitdhSub() { 1704 this.focusText = FocusText.TEXT3; 1705 this.hasFocusText3 = true; 1706 this.day -= this.step % this.getDayNumber(); 1707 if (this.day < CounterConstant.COUNTER_MIN_DAY) { 1708 this.day += this.getDayNumber(); 1709 } 1710 this.focusWithTarget('DateTextInput3' + this.timeStamp.toString()); 1711 } 1712 accessibilityBroadcastAddDate() { 1713 if (this.focusText === FocusText.TEXT1) { 1714 if (this.addBtnStateEffect) { 1715 this.inputYear = this.year; 1716 this.year += this.step; 1717 if (!this.hasFocusText1) { 1718 this.hasFocusText1 = true; 1719 } 1720 } 1721 if (!this.subBtnStateEffect) { 1722 this.subBtnStateEffect = true; 1723 this.subOpacity = CounterResource.COUNTER_BUTTON_INITIAL_OPACITY; 1724 this.subBtnEnabled = true; 1725 } 1726 if (this.year >= this.maxYear) { 1727 this.addOpacity = CounterResource.COUNTER_BUTTON_DISABLE_OPACITY; 1728 this.addBtnStateEffect = false; 1729 this.addBtnEnabled = false; 1730 } else { 1731 if ( 1732 this.addOpacity === CounterResource.COUNTER_BUTTON_DISABLE_OPACITY 1733 ) { 1734 this.addOpacity = CounterResource.COUNTER_BUTTON_INITIAL_OPACITY; 1735 } 1736 if (!this.addBtnStateEffect) { 1737 this.addBtnStateEffect = true; 1738 } 1739 if (!this.addBtnEnabled) { 1740 this.addBtnEnabled = true; 1741 } 1742 } 1743 try { 1744 let eventInfo = { 1745 type: 'announceForAccessibility', 1746 bundleName: getContext()?.abilityInfo?.bundleName, 1747 triggerAction: 'click', 1748 textAnnouncedForAccessibility: 1749 this.getDateYear(this.year) + 1750 ',' + 1751 this.getDateYear(this.year) + 1752 '/' + 1753 this.getDateMonth(this.month) + 1754 '/' + 1755 this.getDateDay(this.day), 1756 }; 1757 accessibility.sendAccessibilityEvent(eventInfo).then(() => { 1758 console.log('Accessility addYear click send event'); 1759 }); 1760 } catch (exception) { 1761 let code = exception.code; 1762 let message = exception.message; 1763 console.log( 1764 `Accessility addYear click faild error code:${code} message:${message}` 1765 ); 1766 } 1767 } else if (this.focusText === FocusText.TEXT2) { 1768 this.month += this.step % CounterConstant.COUNTER_MAX_MONTH; 1769 if (this.month > CounterConstant.COUNTER_MAX_MONTH) { 1770 this.month -= CounterConstant.COUNTER_MAX_MONTH; 1771 } 1772 if (!this.hasFocusText2) { 1773 this.hasFocusText2 = true; 1774 } 1775 try { 1776 let eventInfo = { 1777 type: 'announceForAccessibility', 1778 bundleName: getContext()?.abilityInfo?.bundleName, 1779 triggerAction: 'click', 1780 textAnnouncedForAccessibility: 1781 this.getDateMonth(this.month) + 1782 ',' + 1783 this.getDateYear(this.year) + 1784 '/' + 1785 this.getDateMonth(this.month) + 1786 '/' + 1787 this.getDateDay(this.day), 1788 }; 1789 accessibility.sendAccessibilityEvent(eventInfo).then(() => { 1790 console.log('Accessility addMonth click send event'); 1791 }); 1792 } catch (exception) { 1793 let code = exception.code; 1794 let message = exception.message; 1795 console.log( 1796 `Accessility addMonth faild error code:${code} message:${message}` 1797 ); 1798 } 1799 } else if (this.focusText === FocusText.TEXT3) { 1800 this.day += this.step % this.getDayNumber(); 1801 if (this.day > this.getDayNumber()) { 1802 this.day -= this.getDayNumber(); 1803 } 1804 if (!this.hasFocusText3) { 1805 this.hasFocusText3 = true; 1806 } 1807 try { 1808 let eventInfo = { 1809 type: 'announceForAccessibility', 1810 bundleName: getContext()?.abilityInfo?.bundleName, 1811 triggerAction: 'click', 1812 textAnnouncedForAccessibility: 1813 this.getDateDay(this.day) + 1814 ',' + 1815 this.getDateYear(this.year) + 1816 '/' + 1817 this.getDateMonth(this.month) + 1818 '/' + 1819 this.getDateDay(this.day), 1820 }; 1821 accessibility.sendAccessibilityEvent(eventInfo).then(() => { 1822 console.log('Accessility addDay click send event'); 1823 }); 1824 } catch (exception) { 1825 let code = exception.code; 1826 let message = exception.message; 1827 console.log( 1828 `Accessility addDay faild error code:${code} message:${message}` 1829 ); 1830 } 1831 } else { 1832 this.focusDayWithAdd(); 1833 } 1834 } 1835 addDate() { 1836 if (this.focusText === FocusText.TEXT1) { 1837 if (this.addBtnStateEffect) { 1838 this.inputYear = this.year; 1839 this.year += this.step; 1840 if (!this.hasFocusText1) { 1841 this.hasFocusText1 = true; 1842 } 1843 } 1844 if (!this.subBtnStateEffect) { 1845 this.subBtnStateEffect = true; 1846 this.subOpacity = CounterResource.COUNTER_BUTTON_INITIAL_OPACITY; 1847 this.subBtnEnabled = true; 1848 } 1849 if (this.year >= this.maxYear) { 1850 this.addOpacity = CounterResource.COUNTER_BUTTON_DISABLE_OPACITY; 1851 this.addBtnStateEffect = false; 1852 this.addBtnEnabled = false; 1853 } else { 1854 if ( 1855 this.addOpacity === CounterResource.COUNTER_BUTTON_DISABLE_OPACITY 1856 ) { 1857 this.addOpacity = CounterResource.COUNTER_BUTTON_INITIAL_OPACITY; 1858 } 1859 if (!this.addBtnStateEffect) { 1860 this.addBtnStateEffect = true; 1861 } 1862 if (!this.addBtnEnabled) { 1863 this.addBtnEnabled = true; 1864 } 1865 } 1866 } else if (this.focusText === FocusText.TEXT2) { 1867 this.month += this.step % CounterConstant.COUNTER_MAX_MONTH; 1868 if (this.month > CounterConstant.COUNTER_MAX_MONTH) { 1869 this.month -= CounterConstant.COUNTER_MAX_MONTH; 1870 } 1871 if (!this.hasFocusText2) { 1872 this.hasFocusText2 = true; 1873 } 1874 } else if (this.focusText === FocusText.TEXT3) { 1875 this.day += this.step % this.getDayNumber(); 1876 if (this.day > this.getDayNumber()) { 1877 this.day -= this.getDayNumber(); 1878 } 1879 if (!this.hasFocusText3) { 1880 this.hasFocusText3 = true; 1881 } 1882 } else { 1883 this.focusDayWithAdd(); 1884 } 1885 } 1886 focusDayWithAdd() { 1887 this.focusText = FocusText.TEXT3; 1888 this.hasFocusText3 = true; 1889 this.day += this.step % this.getDayNumber(); 1890 if (this.day > this.getDayNumber()) { 1891 this.day -= this.getDayNumber(); 1892 } 1893 this.focusWithTarget('DateTextInput3' + this.timeStamp.toString()); 1894 } 1895 updateInlineEnableSate() { 1896 if (this.value >= this.max) { 1897 this.addOpacity = CounterResource.COUNTER_BUTTON_DISABLE_OPACITY; 1898 this.addBtnStateEffect = false; 1899 this.addBtnEnabled = false; 1900 } else { 1901 this.addOpacity = CounterResource.COUNTER_BUTTON_INITIAL_OPACITY; 1902 this.addBtnStateEffect = true; 1903 this.addBtnEnabled = true; 1904 } 1905 if (this.value <= this.min) { 1906 this.subOpacity = CounterResource.COUNTER_BUTTON_DISABLE_OPACITY; 1907 this.subBtnStateEffect = false; 1908 this.subBtnEnabled = false; 1909 } else { 1910 this.subOpacity = CounterResource.COUNTER_BUTTON_INITIAL_OPACITY; 1911 this.subBtnStateEffect = true; 1912 this.subBtnEnabled = true; 1913 } 1914 } 1915 updateDateEnableSate() { 1916 if (this.year === this.maxYear && this.focusText === FocusText.TEXT1) { 1917 this.addOpacity = CounterResource.COUNTER_BUTTON_DISABLE_OPACITY; 1918 this.addBtnStateEffect = false; 1919 this.addBtnEnabled = false; 1920 } else { 1921 if (this.addOpacity === CounterResource.COUNTER_BUTTON_DISABLE_OPACITY) { 1922 this.addOpacity = CounterResource.COUNTER_BUTTON_INITIAL_OPACITY; 1923 } 1924 if (!this.addBtnStateEffect) { 1925 this.addBtnStateEffect = true; 1926 } 1927 if (!this.addBtnEnabled) { 1928 this.addBtnEnabled = true; 1929 } 1930 } 1931 if (this.year === this.minYear && this.focusText === FocusText.TEXT1) { 1932 this.subOpacity = CounterResource.COUNTER_BUTTON_DISABLE_OPACITY; 1933 this.subBtnStateEffect = false; 1934 this.subBtnEnabled = false; 1935 } else { 1936 if (this.subOpacity === CounterResource.COUNTER_BUTTON_DISABLE_OPACITY) { 1937 this.subOpacity = CounterResource.COUNTER_BUTTON_INITIAL_OPACITY; 1938 } 1939 if (!this.subBtnStateEffect) { 1940 this.subBtnStateEffect = true; 1941 } 1942 if (!this.subBtnEnabled) { 1943 this.subBtnEnabled = true; 1944 } 1945 } 1946 } 1947 updateDay() { 1948 if (this.day > this.getDayNumber()) { 1949 this.day = this.getDayNumber(); 1950 } 1951 } 1952 resetFocusText() { 1953 this.focusText = FocusText.NONE; 1954 this.hasFocusText1 = false; 1955 this.hasFocusText2 = false; 1956 this.hasFocusText3 = false; 1957 } 1958 resetFocusButton() { 1959 if (this.addBtnFocusWidh === CounterResource.BUTTON_BORDER_FOCUSED_WIDTH) { 1960 this.addBtnFocusWidh = CounterResource.BUTTON_BORDER_BLUR_WIDTH; 1961 this.onBlurIncrease && this.onBlurIncrease(); 1962 } 1963 if (this.subBtnFocusWidh === CounterResource.BUTTON_BORDER_FOCUSED_WIDTH) { 1964 this.subBtnFocusWidh = CounterResource.BUTTON_BORDER_BLUR_WIDTH; 1965 this.onBlurDecrease && this.onBlurDecrease(); 1966 } 1967 } 1968 homeFocusText() { 1969 this.focusWithTarget('DateTextInput1' + this.timeStamp.toString()); 1970 } 1971 endFocusText() { 1972 this.focusWithTarget('DateTextInput3' + this.timeStamp.toString()); 1973 } 1974 homeFirstValue() { 1975 this.value = this.min; 1976 if (!this.addBtnStateEffect) { 1977 this.addBtnStateEffect = true; 1978 this.addOpacity = CounterResource.COUNTER_BUTTON_INITIAL_OPACITY; 1979 this.addBtnEnabled = true; 1980 } 1981 } 1982 endLastValue() { 1983 this.value = this.max; 1984 if (!this.subBtnStateEffect) { 1985 this.subBtnStateEffect = true; 1986 this.subOpacity = CounterResource.COUNTER_BUTTON_INITIAL_OPACITY; 1987 this.subBtnEnabled = true; 1988 } 1989 } 1990 updateButtonStatus() { 1991 if (this.value <= this.min) { 1992 if (!this.addBtnStateEffect && this.max != this.min) { 1993 this.addBtnStateEffect = true; 1994 this.addOpacity = CounterResource.COUNTER_BUTTON_INITIAL_OPACITY; 1995 this.addBtnEnabled = true; 1996 } 1997 this.subOpacity = CounterResource.COUNTER_BUTTON_DISABLE_OPACITY; 1998 this.subBtnStateEffect = false; 1999 this.subBtnEnabled = false; 2000 } 2001 if (this.value >= this.max) { 2002 if (!this.subBtnStateEffect && this.max != this.min) { 2003 this.subBtnStateEffect = true; 2004 this.subOpacity = CounterResource.COUNTER_BUTTON_INITIAL_OPACITY; 2005 this.subBtnEnabled = true; 2006 } 2007 this.addOpacity = CounterResource.COUNTER_BUTTON_DISABLE_OPACITY; 2008 this.addBtnStateEffect = false; 2009 this.addBtnEnabled = false; 2010 } 2011 } 2012 getValue() { 2013 if (this.inputValue == undefined) { 2014 this.inputValue = ''; 2015 } 2016 return this.hasInputText1 ? this.inputValue : this.value.toString(); 2017 } 2018 getValueLength() { 2019 return this.getValue().length > 0 ? this.getValue().length : 1; 2020 } 2021 getYear() { 2022 let year = this.year.toString(); 2023 if (year.length === 1) { 2024 year = '000' + year; 2025 } else if (year.length === 2) { 2026 year = '00' + year; 2027 } else if (year.length === 3) { 2028 year = '0' + year; 2029 } else { 2030 year = year; 2031 } 2032 return year; 2033 } 2034 focusWithTarget(key) { 2035 setTimeout(() => { 2036 let res = focusControl.requestFocus(key); 2037 if (res) { 2038 console.log('Request success'); 2039 } else { 2040 console.log('Request failed'); 2041 } 2042 }); 2043 } 2044 focusCurrentText(text) { 2045 if (text === FocusText.TEXT1) { 2046 if (this.focusText === FocusText.NONE) { 2047 this.focusText = FocusText.TEXT1; 2048 } 2049 if (!this.hasFocusText1) { 2050 this.hasFocusText1 = true; 2051 } 2052 } else if (text === FocusText.TEXT2) { 2053 if (this.focusText === FocusText.NONE) { 2054 this.focusText = FocusText.TEXT2; 2055 } 2056 if (!this.hasFocusText2) { 2057 this.hasFocusText2 = true; 2058 } 2059 } else if (text === FocusText.TEXT3) { 2060 if (this.focusText === FocusText.NONE) { 2061 this.focusText = FocusText.TEXT3; 2062 } 2063 if (!this.hasFocusText3) { 2064 this.hasFocusText3 = true; 2065 } 2066 } else { 2067 } 2068 } 2069 getMaxLength() { 2070 if (this.max.toString().length > this.min.toString().length) { 2071 return this.max.toString().length + 1; 2072 } else { 2073 return this.min.toString().length + 1; 2074 } 2075 } 2076 resourceToVp(value) { 2077 try { 2078 if (value.id !== -1) { 2079 return px2vp(getContext(this).resourceManager.getNumber(value.id)); 2080 } else { 2081 return px2vp( 2082 getContext(this).resourceManager.getNumberByName( 2083 value.params[0].split('.')[2] 2084 ) 2085 ); 2086 } 2087 } catch (error) { 2088 return CounterResource.COUNTER_LIST_PADDING; 2089 } 2090 } 2091 getAccessibilityResource(resource) { 2092 let accessibilityResource = ''; 2093 try { 2094 if (typeof resource === 'string') { 2095 accessibilityResource = resource; 2096 } else { 2097 accessibilityResource = getContext()?.resourceManager?.getStringSync( 2098 resource?.id 2099 ); 2100 } 2101 } catch (error) { 2102 let code = error.code; 2103 let message = error.message; 2104 console.log( 2105 `Get accessility resource error code:${code} message:${message}` 2106 ); 2107 } 2108 return accessibilityResource; 2109 } 2110 initialRender() { 2111 this.observeComponentCreation2((elmtId, isInitialRender) => { 2112 If.create(); 2113 if (this.type === CounterType.LIST) { 2114 this.ifElseBranchUpdateFunction(0, () => { 2115 this.observeComponentCreation2((elmtId, isInitialRender) => { 2116 RelativeContainer.create(); 2117 RelativeContainer.direction(this.counterDirection); 2118 RelativeContainer.width('100%'); 2119 RelativeContainer.height(CounterResource.COUNTER_LIST_HEIGHT); 2120 }, RelativeContainer); 2121 this.observeComponentCreation2((elmtId, isInitialRender) => { 2122 Text.create(this.numberStyleOptions.label); 2123 Text.direction(this.counterDirection); 2124 Text.fontSize(CounterResource.COUNTER_LIST_LABEL_SIZE); 2125 Text.maxFontScale( 2126 CounterResource.COUNTER_LABEL_MAX_FONT_SIZE_SCALE 2127 ); 2128 Text.fontColor(CounterResource.COUNTER_TEXT_COLOR); 2129 Text.margin({ 2130 start: LengthMetrics.vp( 2131 this.resourceToVp(CounterResource.COUNTER_LIST_LEFT_PADDING) 2132 ), 2133 }); 2134 Text.alignRules({ 2135 center: { anchor: '__container__', align: VerticalAlign.Center }, 2136 start: { anchor: '__container__', align: HorizontalAlign.Start }, 2137 end: { anchor: 'Row1', align: HorizontalAlign.Start }, 2138 }); 2139 Text.id('Text'); 2140 }, Text); 2141 Text.pop(); 2142 this.observeComponentCreation2((elmtId, isInitialRender) => { 2143 Row.create(); 2144 Row.direction(this.counterDirection); 2145 Row.height(CounterResource.COUNTER_LIST_BUTTON_SIZE); 2146 Row.margin({ 2147 end: LengthMetrics.vp( 2148 this.resourceToVp(CounterResource.COUNTER_LIST_RIGHT_PADDING) 2149 ), 2150 }); 2151 Row.alignRules({ 2152 center: { anchor: '__container__', align: VerticalAlign.Center }, 2153 end: { anchor: '__container__', align: HorizontalAlign.End }, 2154 }); 2155 Row.tabIndex(0); 2156 Row.id('Row1'); 2157 }, Row); 2158 this.observeComponentCreation2((elmtId, isInitialRender) => { 2159 Stack.create(); 2160 Stack.direction(this.counterDirection); 2161 Stack.width(CounterResource.COUNTER_LIST_BUTTON_SIZE); 2162 Stack.height(CounterResource.COUNTER_LIST_BUTTON_SIZE); 2163 Stack.borderRadius(CounterResource.COUNTER_LIST_BUTTON_RADIUS); 2164 Stack.borderWidth(this.subBtnFocusWidh); 2165 Stack.borderColor(CounterResource.BUTTON_BORDER_FOCUSED_COLOR); 2166 Stack.clip(true); 2167 }, Stack); 2168 this.observeComponentCreation2((elmtId, isInitialRender) => { 2169 Image.create(CounterResource.BUTTON_SUB_ICON); 2170 Image.direction(this.counterDirection); 2171 Image.width(CounterResource.COUNTER_LIST_BUTTON_ICON_SIZE); 2172 Image.height(CounterResource.COUNTER_LIST_BUTTON_ICON_SIZE); 2173 Image.fillColor(CounterResource.BUTTON_ICON_COLOR); 2174 Image.opacity(this.subOpacity); 2175 }, Image); 2176 this.observeComponentCreation2((elmtId, isInitialRender) => { 2177 Button.createWithLabel({ 2178 type: ButtonType.Circle, 2179 stateEffect: this.subBtnStateEffect, 2180 }); 2181 Button.accessibilityText({ 2182 id: -1, 2183 type: 10003, 2184 params: ['sys.string.reduce_used_for_accessibility_text'], 2185 bundleName: '__harDefaultBundleName__', 2186 moduleName: '__harDefaultModuleName__', 2187 }); 2188 Button.accessibilityDescription( 2189 this.value === this.min ? '' : this.reduceStr 2190 ); 2191 Button.direction(this.counterDirection); 2192 Button.width(CounterResource.COUNTER_LIST_BUTTON_SIZE); 2193 Button.height(CounterResource.COUNTER_LIST_BUTTON_SIZE); 2194 Button.responseRegion({ 2195 x: CounterResource.COUNTER_LIST_BUTTON_HOT_SPOT_X, 2196 y: CounterResource.COUNTER_LIST_BUTTON_HOT_SPOT_Y, 2197 width: '150%', 2198 height: '150%', 2199 }); 2200 Button.groupDefaultFocus(true); 2201 Button.backgroundColor(CounterResource.BUTTON_BACKGROUD_COLOR); 2202 Button.opacity(this.subOpacity); 2203 Button.enabled(this.subBtnEnabled); 2204 Button.key('ListSubButton' + this.timeStamp.toString()); 2205 Button.onKeyEvent(event => { 2206 this.subBtnFocusWidh = 2207 CounterResource.BUTTON_BORDER_FOCUSED_WIDTH; 2208 if (event.keyCode === CounterConstant.KEYCODE_ESC) { 2209 this.resetFocusButton(); 2210 event.stopPropagation(); 2211 } 2212 if ( 2213 event.type === KeyType.Down && 2214 event.keyCode === CounterConstant.KEYCODE_MOVE_HOME 2215 ) { 2216 event.stopPropagation(); 2217 this.homeFirstValue(); 2218 this.focusWithTarget( 2219 'ListAddButton' + this.timeStamp.toString() 2220 ); 2221 } 2222 if ( 2223 event.type === KeyType.Down && 2224 event.keyCode === CounterConstant.KEYCODE_MOVE_END 2225 ) { 2226 event.stopPropagation(); 2227 if (this.addBtnStateEffect) { 2228 this.addBtnStateEffect = false; 2229 this.addOpacity = 2230 CounterResource.COUNTER_BUTTON_DISABLE_OPACITY; 2231 this.addBtnEnabled = false; 2232 } 2233 this.endLastValue(); 2234 this.focusWithTarget( 2235 'ListAddButton' + this.timeStamp.toString() 2236 ); 2237 } 2238 }); 2239 Button.onClick(event => { 2240 this.subValue(); 2241 this.onChange?.(this.value); 2242 if ( 2243 event.source === SourceType.Mouse || 2244 event.source === SourceType.TouchScreen 2245 ) { 2246 this.subBtnFocusWidh = CounterResource.BUTTON_BORDER_BLUR_WIDTH; 2247 } 2248 try { 2249 let eventInfo = { 2250 type: 'announceForAccessibility', 2251 bundleName: getContext()?.abilityInfo?.bundleName, 2252 triggerAction: 'click', 2253 textAnnouncedForAccessibility: this.value?.toString(), 2254 }; 2255 accessibility.sendAccessibilityEvent(eventInfo).then(() => { 2256 console.log('Accessility subValue click send event'); 2257 }); 2258 } catch (exception) { 2259 let code = exception.code; 2260 let message = exception.message; 2261 console.log( 2262 `Accessility subValue faild error code:${code} message:${message}` 2263 ); 2264 } 2265 }); 2266 Gesture.create(GesturePriority.Low); 2267 LongPressGesture.create({ repeat: true }); 2268 LongPressGesture.onAction(event => { 2269 if (event.repeat) { 2270 this.subValue(); 2271 this.onChange?.(this.value); 2272 } 2273 this.subBtnFocusWidh = CounterResource.BUTTON_BORDER_BLUR_WIDTH; 2274 }); 2275 LongPressGesture.onActionEnd(() => { 2276 try { 2277 let eventInfo = { 2278 type: 'announceForAccessibility', 2279 bundleName: getContext()?.abilityInfo?.bundleName, 2280 triggerAction: 'common', 2281 textAnnouncedForAccessibility: this.value?.toString(), 2282 }; 2283 accessibility.sendAccessibilityEvent(eventInfo).then(() => { 2284 console.log('Accessility subValue longPress send event'); 2285 }); 2286 } catch (exception) { 2287 let code = exception.code; 2288 let message = exception.message; 2289 console.log( 2290 `Accessility subValue longPress faild error code:${code} message:${message}` 2291 ); 2292 } 2293 }); 2294 LongPressGesture.pop(); 2295 Gesture.pop(); 2296 Button.hoverEffect(this.choverEffect); 2297 Button.onHover(isHover => { 2298 this.onHoverDecrease && this.onHoverDecrease(isHover); 2299 }); 2300 Button.focusable(this.focusEnable); 2301 Button.onFocus(() => { 2302 this.subBtnFocusWidh = 2303 CounterResource.BUTTON_BORDER_FOCUSED_WIDTH; 2304 this.onFocusDecrease && this.onFocusDecrease(); 2305 this.updateButtonStatus(); 2306 }); 2307 Button.onBlur(() => { 2308 this.subBtnFocusWidh = CounterResource.BUTTON_BORDER_BLUR_WIDTH; 2309 this.onBlurDecrease && this.onBlurDecrease(); 2310 }); 2311 }, Button); 2312 Button.pop(); 2313 Stack.pop(); 2314 this.observeComponentCreation2((elmtId, isInitialRender) => { 2315 If.create(); 2316 if (this.hasTextWidth) { 2317 this.ifElseBranchUpdateFunction(0, () => { 2318 this.observeComponentCreation2((elmtId, isInitialRender) => { 2319 Text.create(this.value.toString()); 2320 Text.accessibilityText( 2321 this.getAccessibilityResource( 2322 this.numberStyleOptions.label 2323 ) + 2324 '[n2]' + 2325 this.value.toString() + 2326 '[n0]' 2327 ); 2328 Text.direction(this.counterDirection); 2329 Text.width(this.textWidth.toString()); 2330 Text.textAlign(TextAlign.Center); 2331 Text.fontSize(CounterResource.COUNTER_LIST_NUMBER_SIZE); 2332 Text.maxFontScale( 2333 CounterResource.COUNTER_NUMBER_MAX_FONT_SIZE_SCALE 2334 ); 2335 Text.fontColor(CounterResource.COUNTER_TEXT_COLOR); 2336 Text.margin({ 2337 start: LengthMetrics.vp( 2338 CounterResource.COUNTER_LIST_BUTTON_TEXT_MARGIN 2339 ), 2340 end: LengthMetrics.vp( 2341 CounterResource.COUNTER_LIST_BUTTON_TEXT_MARGIN 2342 ), 2343 }); 2344 }, Text); 2345 Text.pop(); 2346 }); 2347 } else { 2348 this.ifElseBranchUpdateFunction(1, () => { 2349 this.observeComponentCreation2((elmtId, isInitialRender) => { 2350 Text.create(this.value.toString()); 2351 Text.accessibilityText( 2352 this.getAccessibilityResource( 2353 this.numberStyleOptions.label 2354 ) + 2355 '[n2]' + 2356 this.value.toString() + 2357 '[n0]' 2358 ); 2359 Text.direction(this.counterDirection); 2360 Text.textAlign(TextAlign.Center); 2361 Text.fontSize(CounterResource.COUNTER_LIST_NUMBER_SIZE); 2362 Text.maxFontScale( 2363 CounterResource.COUNTER_NUMBER_MAX_FONT_SIZE_SCALE 2364 ); 2365 Text.fontColor(CounterResource.COUNTER_TEXT_COLOR); 2366 Text.margin({ 2367 start: LengthMetrics.vp( 2368 CounterResource.COUNTER_LIST_BUTTON_TEXT_MARGIN 2369 ), 2370 end: LengthMetrics.vp( 2371 CounterResource.COUNTER_LIST_BUTTON_TEXT_MARGIN 2372 ), 2373 }); 2374 }, Text); 2375 Text.pop(); 2376 }); 2377 } 2378 }, If); 2379 If.pop(); 2380 this.observeComponentCreation2((elmtId, isInitialRender) => { 2381 Stack.create(); 2382 Stack.direction(this.counterDirection); 2383 Stack.width(CounterResource.COUNTER_LIST_BUTTON_SIZE); 2384 Stack.height(CounterResource.COUNTER_LIST_BUTTON_SIZE); 2385 Stack.borderRadius(CounterResource.COUNTER_LIST_BUTTON_RADIUS); 2386 Stack.borderWidth(this.addBtnFocusWidh); 2387 Stack.borderColor(CounterResource.BUTTON_BORDER_FOCUSED_COLOR); 2388 Stack.clip(true); 2389 }, Stack); 2390 this.observeComponentCreation2((elmtId, isInitialRender) => { 2391 Image.create(CounterResource.BUTTON_ADD_ICON); 2392 Image.direction(this.counterDirection); 2393 Image.width(CounterResource.COUNTER_LIST_BUTTON_ICON_SIZE); 2394 Image.height(CounterResource.COUNTER_LIST_BUTTON_ICON_SIZE); 2395 Image.fillColor(CounterResource.BUTTON_ICON_COLOR); 2396 Image.opacity(this.addOpacity); 2397 }, Image); 2398 this.observeComponentCreation2((elmtId, isInitialRender) => { 2399 Button.createWithLabel({ 2400 type: ButtonType.Circle, 2401 stateEffect: this.addBtnStateEffect, 2402 }); 2403 Button.accessibilityText({ 2404 id: -1, 2405 type: 10003, 2406 params: ['sys.string.increase_used_for_accessibility_text'], 2407 bundleName: '__harDefaultBundleName__', 2408 moduleName: '__harDefaultModuleName__', 2409 }); 2410 Button.accessibilityDescription( 2411 this.value === this.max ? '' : this.increaseStr 2412 ); 2413 Button.direction(this.counterDirection); 2414 Button.width(CounterResource.COUNTER_LIST_BUTTON_SIZE); 2415 Button.height(CounterResource.COUNTER_LIST_BUTTON_SIZE); 2416 Button.responseRegion({ 2417 x: CounterResource.COUNTER_LIST_BUTTON_HOT_SPOT_X, 2418 y: CounterResource.COUNTER_LIST_BUTTON_HOT_SPOT_Y, 2419 width: '150%', 2420 height: '150%', 2421 }); 2422 Button.backgroundColor(CounterResource.BUTTON_BACKGROUD_COLOR); 2423 Button.opacity(this.addOpacity); 2424 Button.enabled(this.addBtnEnabled); 2425 Button.key('ListAddButton' + this.timeStamp.toString()); 2426 Button.onKeyEvent(event => { 2427 this.addBtnFocusWidh = 2428 CounterResource.BUTTON_BORDER_FOCUSED_WIDTH; 2429 if (event.keyCode === CounterConstant.KEYCODE_ESC) { 2430 this.resetFocusButton(); 2431 event.stopPropagation(); 2432 } 2433 if ( 2434 event.type === KeyType.Down && 2435 event.keyCode === CounterConstant.KEYCODE_MOVE_HOME 2436 ) { 2437 event.stopPropagation(); 2438 this.homeFirstValue(); 2439 if (this.subBtnStateEffect) { 2440 this.subBtnStateEffect = false; 2441 this.subOpacity = 2442 CounterResource.COUNTER_BUTTON_DISABLE_OPACITY; 2443 this.subBtnEnabled = false; 2444 } 2445 this.focusWithTarget( 2446 'ListAddButton' + this.timeStamp.toString() 2447 ); 2448 } 2449 if ( 2450 event.type === KeyType.Down && 2451 event.keyCode === CounterConstant.KEYCODE_MOVE_END 2452 ) { 2453 event.stopPropagation(); 2454 this.endLastValue(); 2455 this.focusWithTarget( 2456 'ListSubButton' + this.timeStamp.toString() 2457 ); 2458 } 2459 }); 2460 Button.onClick(event => { 2461 this.addValue(); 2462 this.onChange?.(this.value); 2463 if ( 2464 event.source === SourceType.Mouse || 2465 event.source === SourceType.TouchScreen 2466 ) { 2467 this.addBtnFocusWidh = CounterResource.BUTTON_BORDER_BLUR_WIDTH; 2468 } 2469 try { 2470 let eventInfo = { 2471 type: 'announceForAccessibility', 2472 bundleName: getContext()?.abilityInfo?.bundleName, 2473 triggerAction: 'click', 2474 textAnnouncedForAccessibility: this.value?.toString(), 2475 }; 2476 accessibility.sendAccessibilityEvent(eventInfo).then(() => { 2477 console.log('Accessility addValue click send event'); 2478 }); 2479 } catch (exception) { 2480 let code = exception.code; 2481 let message = exception.message; 2482 console.log( 2483 `Accessility addValue click longPress faild error code:${code} message:${message}` 2484 ); 2485 } 2486 }); 2487 Gesture.create(GesturePriority.Low); 2488 LongPressGesture.create({ repeat: true }); 2489 LongPressGesture.onAction(event => { 2490 if (event.repeat) { 2491 this.addValue(); 2492 this.onChange?.(this.value); 2493 } 2494 this.addBtnFocusWidh = CounterResource.BUTTON_BORDER_BLUR_WIDTH; 2495 }); 2496 LongPressGesture.onActionEnd(() => { 2497 try { 2498 let eventInfo = { 2499 type: 'announceForAccessibility', 2500 bundleName: getContext()?.abilityInfo?.bundleName, 2501 triggerAction: 'common', 2502 textAnnouncedForAccessibility: this.value?.toString(), 2503 }; 2504 accessibility.sendAccessibilityEvent(eventInfo).then(() => { 2505 console.log('Accessility addValue longPress send event'); 2506 }); 2507 } catch (exception) { 2508 let code = exception.code; 2509 let message = exception.message; 2510 console.log( 2511 `Accessility addValue longPress longPress faild error code:${code} message:${message}` 2512 ); 2513 } 2514 }); 2515 LongPressGesture.pop(); 2516 Gesture.pop(); 2517 Button.hoverEffect(this.choverEffect); 2518 Button.onHover(isHover => { 2519 this.onHoverIncrease && this.onHoverIncrease(isHover); 2520 }); 2521 Button.focusable(this.focusEnable); 2522 Button.onFocus(() => { 2523 this.addBtnFocusWidh = 2524 CounterResource.BUTTON_BORDER_FOCUSED_WIDTH; 2525 this.onFocusIncrease && this.onFocusIncrease(); 2526 this.updateButtonStatus(); 2527 }); 2528 Button.onBlur(() => { 2529 this.addBtnFocusWidh = CounterResource.BUTTON_BORDER_BLUR_WIDTH; 2530 this.onBlurIncrease && this.onBlurIncrease(); 2531 }); 2532 }, Button); 2533 Button.pop(); 2534 Stack.pop(); 2535 Row.pop(); 2536 RelativeContainer.pop(); 2537 }); 2538 } else if (this.type === CounterType.COMPACT) { 2539 this.ifElseBranchUpdateFunction(1, () => { 2540 this.observeComponentCreation2((elmtId, isInitialRender) => { 2541 Column.create(); 2542 }, Column); 2543 this.observeComponentCreation2((elmtId, isInitialRender) => { 2544 Row.create(); 2545 Row.direction(this.counterDirection); 2546 Row.tabIndex(0); 2547 Row.height(CounterResource.COUNTER_COMPACT_CONTAINER_HEIGHT); 2548 Row.align(Alignment.Center); 2549 Row.borderWidth(CounterResource.COUNTER_BORDER_WIDTH); 2550 Row.borderColor(CounterResource.COUNTER_BORDER_COLOR); 2551 Row.borderRadius(CounterResource.COUNTER_COMPACT_CONTAINER_RADIUS); 2552 }, Row); 2553 this.observeComponentCreation2((elmtId, isInitialRender) => { 2554 Stack.create(); 2555 Stack.width(CounterResource.COUNTER_COMPACT_BUTTON_SIZE); 2556 Stack.height(CounterResource.COUNTER_COMPACT_BUTTON_SIZE); 2557 Stack.borderRadius(CounterResource.COUNTER_COMPACT_BUTTON_RADIUS); 2558 Stack.borderWidth(this.subBtnFocusWidh); 2559 Stack.borderColor(CounterResource.BUTTON_BORDER_FOCUSED_COLOR); 2560 Stack.margin({ 2561 start: LengthMetrics.vp( 2562 this.resourceToVp( 2563 CounterResource.COUNTER_COMPACT_BUTTON_CONTAINER_MARGIN 2564 ) 2565 ), 2566 }); 2567 Stack.clip(true); 2568 }, Stack); 2569 this.observeComponentCreation2((elmtId, isInitialRender) => { 2570 Image.create(CounterResource.BUTTON_SUB_ICON); 2571 Image.direction(this.counterDirection); 2572 Image.width(CounterResource.COUNTER_COMPACT_BUTTON_ICON_SIZE); 2573 Image.height(CounterResource.COUNTER_COMPACT_BUTTON_ICON_SIZE); 2574 Image.fillColor(CounterResource.BUTTON_ICON_COLOR); 2575 Image.opacity(this.subOpacity); 2576 }, Image); 2577 this.observeComponentCreation2((elmtId, isInitialRender) => { 2578 Button.createWithLabel({ 2579 type: ButtonType.Circle, 2580 stateEffect: this.subBtnStateEffect, 2581 }); 2582 Button.accessibilityText({ 2583 id: -1, 2584 type: 10003, 2585 params: ['sys.string.reduce_used_for_accessibility_text'], 2586 bundleName: '__harDefaultBundleName__', 2587 moduleName: '__harDefaultModuleName__', 2588 }); 2589 Button.accessibilityDescription( 2590 this.value === this.min ? '' : this.reduceStr 2591 ); 2592 Button.direction(this.counterDirection); 2593 Button.width(CounterResource.COUNTER_COMPACT_BUTTON_SIZE); 2594 Button.height(CounterResource.COUNTER_COMPACT_BUTTON_SIZE); 2595 Button.backgroundColor(CounterResource.BUTTON_BACKGROUD_COLOR); 2596 Button.opacity(this.subOpacity); 2597 Button.enabled(this.subBtnEnabled); 2598 Button.key('CompactSubButton' + this.timeStamp.toString()); 2599 Button.onKeyEvent(event => { 2600 this.subBtnFocusWidh = 2601 CounterResource.BUTTON_BORDER_FOCUSED_WIDTH; 2602 if (event.keyCode === CounterConstant.KEYCODE_ESC) { 2603 this.resetFocusButton(); 2604 event.stopPropagation(); 2605 } 2606 if ( 2607 event.type === KeyType.Down && 2608 event.keyCode === CounterConstant.KEYCODE_MOVE_HOME 2609 ) { 2610 event.stopPropagation(); 2611 this.homeFirstValue(); 2612 this.focusWithTarget( 2613 'CompactAddButton' + this.timeStamp.toString() 2614 ); 2615 } 2616 if ( 2617 event.type === KeyType.Down && 2618 event.keyCode === CounterConstant.KEYCODE_MOVE_END 2619 ) { 2620 event.stopPropagation(); 2621 this.endLastValue(); 2622 if (this.addBtnStateEffect) { 2623 this.addBtnStateEffect = false; 2624 this.addOpacity = 2625 CounterResource.COUNTER_BUTTON_DISABLE_OPACITY; 2626 this.addBtnEnabled = false; 2627 } 2628 this.focusWithTarget( 2629 'CompactSubButton' + this.timeStamp.toString() 2630 ); 2631 } 2632 }); 2633 Button.onClick(event => { 2634 this.subValue(); 2635 this.onChange?.(this.value); 2636 if ( 2637 event.source === SourceType.Mouse || 2638 event.source === SourceType.TouchScreen 2639 ) { 2640 this.subBtnFocusWidh = CounterResource.BUTTON_BORDER_BLUR_WIDTH; 2641 } 2642 try { 2643 let eventInfo = { 2644 type: 'announceForAccessibility', 2645 bundleName: getContext()?.abilityInfo?.bundleName, 2646 triggerAction: 'click', 2647 textAnnouncedForAccessibility: this.value?.toString(), 2648 }; 2649 accessibility.sendAccessibilityEvent(eventInfo).then(() => { 2650 console.log('Accessility subValue click send event'); 2651 }); 2652 } catch (exception) { 2653 let code = exception.code; 2654 let message = exception.message; 2655 console.log( 2656 `Accessility subValue click longPress faild error code:${code} message:${message}` 2657 ); 2658 } 2659 }); 2660 Gesture.create(GesturePriority.Low); 2661 LongPressGesture.create({ repeat: true }); 2662 LongPressGesture.onAction(event => { 2663 if (event.repeat) { 2664 this.subValue(); 2665 this.onChange?.(this.value); 2666 } 2667 if ( 2668 event.source === SourceType.Mouse || 2669 event.source === SourceType.TouchScreen 2670 ) { 2671 this.subBtnFocusWidh = CounterResource.BUTTON_BORDER_BLUR_WIDTH; 2672 } 2673 }); 2674 LongPressGesture.onActionEnd(() => { 2675 try { 2676 let eventInfo = { 2677 type: 'announceForAccessibility', 2678 bundleName: getContext()?.abilityInfo?.bundleName, 2679 triggerAction: 'common', 2680 textAnnouncedForAccessibility: this.value?.toString(), 2681 }; 2682 accessibility.sendAccessibilityEvent(eventInfo).then(() => { 2683 console.log('Accessility subValue longPress send event'); 2684 }); 2685 } catch (exception) { 2686 let code = exception.code; 2687 let message = exception.message; 2688 console.log( 2689 `Accessility subValue longPress longPress faild error code:${code} message:${message}` 2690 ); 2691 } 2692 }); 2693 LongPressGesture.pop(); 2694 Gesture.pop(); 2695 Button.hoverEffect(this.choverEffect); 2696 Button.onHover(isHover => { 2697 this.onHoverDecrease && this.onHoverDecrease(isHover); 2698 }); 2699 Button.focusable(this.focusEnable); 2700 Button.groupDefaultFocus(true); 2701 Button.onFocus(() => { 2702 this.subBtnFocusWidh = 2703 CounterResource.BUTTON_BORDER_FOCUSED_WIDTH; 2704 this.onFocusDecrease && this.onFocusDecrease(); 2705 this.updateButtonStatus(); 2706 }); 2707 Button.onBlur(() => { 2708 this.subBtnFocusWidh = CounterResource.BUTTON_BORDER_BLUR_WIDTH; 2709 this.onBlurDecrease && this.onBlurDecrease(); 2710 }); 2711 }, Button); 2712 Button.pop(); 2713 Stack.pop(); 2714 this.observeComponentCreation2((elmtId, isInitialRender) => { 2715 If.create(); 2716 if (this.hasTextWidth) { 2717 this.ifElseBranchUpdateFunction(0, () => { 2718 this.observeComponentCreation2((elmtId, isInitialRender) => { 2719 Text.create(this.value.toString()); 2720 Text.accessibilityText( 2721 this.getAccessibilityResource( 2722 this.numberStyleOptions.label 2723 ) + 2724 '[n2]' + 2725 this.value.toString() + 2726 '[n0]' 2727 ); 2728 Text.textAlign(TextAlign.Center); 2729 Text.fontSize(CounterResource.COUNTER_NUMBER_SIZE); 2730 Text.maxFontScale( 2731 CounterResource.COUNTER_NUMBER_MAX_FONT_SIZE_SCALE 2732 ); 2733 Text.fontColor(CounterResource.COUNTER_TEXT_COLOR); 2734 Text.width(this.textWidth.toString()); 2735 Text.margin({ 2736 start: LengthMetrics.vp( 2737 CounterResource.COUNTER_COMPACT_BUTTON_TEXT_MARGIN 2738 ), 2739 end: LengthMetrics.vp( 2740 CounterResource.COUNTER_COMPACT_BUTTON_TEXT_MARGIN 2741 ), 2742 }); 2743 }, Text); 2744 Text.pop(); 2745 }); 2746 } else { 2747 this.ifElseBranchUpdateFunction(1, () => { 2748 this.observeComponentCreation2((elmtId, isInitialRender) => { 2749 Text.create(this.value.toString()); 2750 Text.accessibilityText( 2751 this.getAccessibilityResource( 2752 this.numberStyleOptions.label 2753 ) + 2754 '[n2]' + 2755 this.value.toString() + 2756 '[n0]' 2757 ); 2758 Text.direction(this.counterDirection); 2759 Text.textAlign(TextAlign.Center); 2760 Text.fontSize(CounterResource.COUNTER_NUMBER_SIZE); 2761 Text.maxFontScale( 2762 CounterResource.COUNTER_NUMBER_MAX_FONT_SIZE_SCALE 2763 ); 2764 Text.fontColor(CounterResource.COUNTER_TEXT_COLOR); 2765 Text.margin({ 2766 start: LengthMetrics.vp( 2767 CounterResource.COUNTER_COMPACT_BUTTON_TEXT_MARGIN 2768 ), 2769 end: LengthMetrics.vp( 2770 CounterResource.COUNTER_COMPACT_BUTTON_TEXT_MARGIN 2771 ), 2772 }); 2773 }, Text); 2774 Text.pop(); 2775 }); 2776 } 2777 }, If); 2778 If.pop(); 2779 this.observeComponentCreation2((elmtId, isInitialRender) => { 2780 Stack.create(); 2781 Stack.direction(this.counterDirection); 2782 Stack.width(CounterResource.COUNTER_COMPACT_BUTTON_SIZE); 2783 Stack.height(CounterResource.COUNTER_COMPACT_BUTTON_SIZE); 2784 Stack.borderRadius(CounterResource.COUNTER_COMPACT_BUTTON_RADIUS); 2785 Stack.borderWidth(this.addBtnFocusWidh); 2786 Stack.borderColor(CounterResource.BUTTON_BORDER_FOCUSED_COLOR); 2787 Stack.margin({ 2788 end: LengthMetrics.vp( 2789 this.resourceToVp( 2790 CounterResource.COUNTER_COMPACT_BUTTON_CONTAINER_MARGIN 2791 ) 2792 ), 2793 }); 2794 Stack.clip(true); 2795 }, Stack); 2796 this.observeComponentCreation2((elmtId, isInitialRender) => { 2797 Image.create(CounterResource.BUTTON_ADD_ICON); 2798 Image.direction(this.counterDirection); 2799 Image.width(CounterResource.COUNTER_COMPACT_BUTTON_ICON_SIZE); 2800 Image.height(CounterResource.COUNTER_COMPACT_BUTTON_ICON_SIZE); 2801 Image.fillColor(CounterResource.BUTTON_ICON_COLOR); 2802 Image.opacity(this.addOpacity); 2803 }, Image); 2804 this.observeComponentCreation2((elmtId, isInitialRender) => { 2805 Button.createWithLabel({ 2806 type: ButtonType.Circle, 2807 stateEffect: this.addBtnStateEffect, 2808 }); 2809 Button.accessibilityText({ 2810 id: -1, 2811 type: 10003, 2812 params: ['sys.string.increase_used_for_accessibility_text'], 2813 bundleName: '__harDefaultBundleName__', 2814 moduleName: '__harDefaultModuleName__', 2815 }); 2816 Button.accessibilityDescription( 2817 this.value === this.max ? '' : this.increaseStr 2818 ); 2819 Button.direction(this.counterDirection); 2820 Button.width(CounterResource.COUNTER_COMPACT_BUTTON_SIZE); 2821 Button.height(CounterResource.COUNTER_COMPACT_BUTTON_SIZE); 2822 Button.backgroundColor(CounterResource.BUTTON_BACKGROUD_COLOR); 2823 Button.opacity(this.addOpacity); 2824 Button.enabled(this.addBtnEnabled); 2825 Button.key('CompactAddButton' + this.timeStamp.toString()); 2826 Button.onKeyEvent(event => { 2827 this.addBtnFocusWidh = 2828 CounterResource.BUTTON_BORDER_FOCUSED_WIDTH; 2829 if (event.keyCode === CounterConstant.KEYCODE_ESC) { 2830 this.resetFocusButton(); 2831 event.stopPropagation(); 2832 } 2833 if ( 2834 event.type === KeyType.Down && 2835 event.keyCode === CounterConstant.KEYCODE_MOVE_HOME 2836 ) { 2837 event.stopPropagation(); 2838 this.homeFirstValue(); 2839 if (this.subBtnStateEffect) { 2840 this.subBtnStateEffect = false; 2841 this.subOpacity = 2842 CounterResource.COUNTER_BUTTON_DISABLE_OPACITY; 2843 this.subBtnEnabled = false; 2844 } 2845 this.focusWithTarget( 2846 'CompactAddButton' + this.timeStamp.toString() 2847 ); 2848 } 2849 if ( 2850 event.type === KeyType.Down && 2851 event.keyCode === CounterConstant.KEYCODE_MOVE_END 2852 ) { 2853 event.stopPropagation(); 2854 this.endLastValue(); 2855 this.focusWithTarget( 2856 'CompactSubButton' + this.timeStamp.toString() 2857 ); 2858 } 2859 }); 2860 Button.onClick(event => { 2861 this.addValue(); 2862 this.onChange?.(this.value); 2863 if ( 2864 event.source === SourceType.Mouse || 2865 event.source === SourceType.TouchScreen 2866 ) { 2867 this.addBtnFocusWidh = CounterResource.BUTTON_BORDER_BLUR_WIDTH; 2868 } 2869 try { 2870 let eventInfo = { 2871 type: 'announceForAccessibility', 2872 bundleName: getContext()?.abilityInfo?.bundleName, 2873 triggerAction: 'click', 2874 textAnnouncedForAccessibility: this.value?.toString(), 2875 }; 2876 accessibility.sendAccessibilityEvent(eventInfo).then(() => { 2877 console.log('Accessility addValue click send event'); 2878 }); 2879 } catch (exception) { 2880 let code = exception.code; 2881 let message = exception.message; 2882 console.log( 2883 `Accessility addValue click longPress faild error code:${code} message:${message}` 2884 ); 2885 } 2886 }); 2887 Gesture.create(GesturePriority.Low); 2888 LongPressGesture.create({ repeat: true }); 2889 LongPressGesture.onAction(event => { 2890 if (event.repeat) { 2891 this.addValue(); 2892 this.onChange?.(this.value); 2893 } 2894 if ( 2895 event.source === SourceType.Mouse || 2896 event.source === SourceType.TouchScreen 2897 ) { 2898 this.addBtnFocusWidh = CounterResource.BUTTON_BORDER_BLUR_WIDTH; 2899 } 2900 }); 2901 LongPressGesture.onActionEnd(() => { 2902 try { 2903 let eventInfo = { 2904 type: 'announceForAccessibility', 2905 bundleName: getContext()?.abilityInfo?.bundleName, 2906 triggerAction: 'common', 2907 textAnnouncedForAccessibility: this.value?.toString(), 2908 }; 2909 accessibility.sendAccessibilityEvent(eventInfo).then(() => { 2910 console.log('Accessility addValue longPress send event'); 2911 }); 2912 } catch (exception) { 2913 let code = exception.code; 2914 let message = exception.message; 2915 console.log( 2916 `Accessility addValue longPress longPress faild error code:${code} message:${message}` 2917 ); 2918 } 2919 }); 2920 LongPressGesture.pop(); 2921 Gesture.pop(); 2922 Button.hoverEffect(this.choverEffect); 2923 Button.onHover(isHover => { 2924 this.onHoverIncrease && this.onHoverIncrease(isHover); 2925 }); 2926 Button.focusable(this.focusEnable); 2927 Button.onFocus(() => { 2928 this.addBtnFocusWidh = 2929 CounterResource.BUTTON_BORDER_FOCUSED_WIDTH; 2930 this.onFocusIncrease && this.onFocusIncrease(); 2931 this.updateButtonStatus(); 2932 }); 2933 Button.onBlur(() => { 2934 this.addBtnFocusWidh = CounterResource.BUTTON_BORDER_BLUR_WIDTH; 2935 this.onBlurIncrease && this.onBlurIncrease(); 2936 }); 2937 }, Button); 2938 Button.pop(); 2939 Stack.pop(); 2940 Row.pop(); 2941 this.observeComponentCreation2((elmtId, isInitialRender) => { 2942 Text.create(this.numberStyleOptions.label); 2943 Text.direction(this.counterDirection); 2944 Text.margin({ 2945 top: CounterResource.COUNTER_COMPACT_CONTAINER_LABEL_DISTANCE, 2946 }); 2947 Text.fontSize(CounterResource.COUNTER_COMPACT_LABEL_SIZE); 2948 Text.maxFontScale( 2949 CounterResource.COUNTER_LABEL_MAX_FONT_SIZE_SCALE 2950 ); 2951 Text.fontColor(CounterResource.COUNTER_TEXT_COLOR); 2952 Text.align(Alignment.Top); 2953 }, Text); 2954 Text.pop(); 2955 Column.pop(); 2956 }); 2957 } else if (this.type === CounterType.INLINE) { 2958 this.ifElseBranchUpdateFunction(2, () => { 2959 this.observeComponentCreation2((elmtId, isInitialRender) => { 2960 Row.create(); 2961 Row.direction(this.counterDirection); 2962 Row.height(CounterResource.COUNTER_INLINE_CONTAINER_HEIGHT); 2963 Row.borderWidth(CounterResource.COUNTER_BORDER_WIDTH); 2964 Row.borderColor(CounterResource.COUNTER_BORDER_COLOR); 2965 Row.borderRadius(CounterResource.COUNTER_INLINE_RADIUS); 2966 Row.clip(true); 2967 }, Row); 2968 this.observeComponentCreation2((elmtId, isInitialRender) => { 2969 If.create(); 2970 if (this.hasTextWidth) { 2971 this.ifElseBranchUpdateFunction(0, () => { 2972 this.observeComponentCreation2((elmtId, isInitialRender) => { 2973 RelativeContainer.create(); 2974 RelativeContainer.direction(this.counterDirection); 2975 RelativeContainer.margin({ 2976 start: LengthMetrics.vp( 2977 CounterResource.COUNTER_INLINE_INPUT_TEXT_MARGIN 2978 ), 2979 end: LengthMetrics.vp( 2980 CounterResource.COUNTER_INLINE_INPUT_TEXT_MARGIN 2981 ), 2982 }); 2983 RelativeContainer.height('100%'); 2984 RelativeContainer.width(this.textWidth); 2985 }, RelativeContainer); 2986 this.observeComponentCreation2((elmtId, isInitialRender) => { 2987 TextInput.create({ 2988 text: this.hasInputText1 2989 ? this.inputValue 2990 : this.value.toString(), 2991 controller: this.controller1, 2992 }); 2993 TextInput.accessibilityDescription({ 2994 id: -1, 2995 type: 10003, 2996 params: [ 2997 'sys.string.input_counter_double_click_description', 2998 ], 2999 bundleName: '__harDefaultBundleName__', 3000 moduleName: '__harDefaultModuleName__', 3001 }); 3002 TextInput.alignRules({ 3003 center: { 3004 anchor: '__container__', 3005 align: VerticalAlign.Center, 3006 }, 3007 middle: { 3008 anchor: '__container__', 3009 align: HorizontalAlign.Center, 3010 }, 3011 }); 3012 TextInput.width( 3013 Math.min(this.getValueLength() * 9.6, this.textWidth) 3014 ); 3015 TextInput.height('20vp'); 3016 TextInput.padding(0); 3017 TextInput.borderRadius(0); 3018 TextInput.textAlign(TextAlign.Center); 3019 TextInput.type(InputType.PhoneNumber); 3020 TextInput.copyOption(CopyOptions.None); 3021 TextInput.fontSize(this.getTextInputFontSize()); 3022 TextInput.fontWeight(FontWeight.Medium); 3023 TextInput.fontColor( 3024 this.hasFocusText1 3025 ? Color.White 3026 : CounterResource.COUNTER_TEXT_COLOR 3027 ); 3028 TextInput.maxLength(this.getMaxLength()); 3029 TextInput.backgroundColor( 3030 this.hasFocusText1 3031 ? CounterResource.BUTTON_BORDER_FOCUSED_COLOR 3032 : Color.Transparent 3033 ); 3034 TextInput.key('InlineTextInput' + this.timeStamp.toString()); 3035 TextInput.onKeyEvent(event => { 3036 this.focusCurrentText(FocusText.TEXT1); 3037 if (event.keyCode === CounterConstant.KEYCODE_ESC) { 3038 this.resetFocusText(); 3039 event.stopPropagation(); 3040 } 3041 if ( 3042 event.type === KeyType.Down && 3043 event.keyCode === CounterConstant.KEYCODE_DPAD_UP 3044 ) { 3045 this.addValue(); 3046 event.stopPropagation(); 3047 } 3048 if ( 3049 event.type === KeyType.Down && 3050 event.keyCode === CounterConstant.KEYCODE_MOVE_HOME 3051 ) { 3052 event.stopPropagation(); 3053 this.focusWithTarget( 3054 'InlineTextInput' + this.timeStamp.toString() 3055 ); 3056 } 3057 if ( 3058 event.type === KeyType.Down && 3059 event.keyCode === CounterConstant.KEYCODE_MOVE_END 3060 ) { 3061 event.stopPropagation(); 3062 this.focusWithTarget( 3063 'InlineTextInput' + this.timeStamp.toString() 3064 ); 3065 } 3066 if ( 3067 event.type === KeyType.Down && 3068 event.keyCode === CounterConstant.KEYCODE_DPAD_DOWN 3069 ) { 3070 this.subValue(); 3071 event.stopPropagation(); 3072 } 3073 if ( 3074 event.type === KeyType.Down && 3075 event.keyCode === CounterConstant.KEYCODE_DPAD_LEFT 3076 ) { 3077 this.focusWithTarget( 3078 'InlineTextInput' + this.timeStamp.toString() 3079 ); 3080 event.stopPropagation(); 3081 } 3082 if ( 3083 event.type === KeyType.Down && 3084 event.keyCode === CounterConstant.KEYCODE_DPAD_RIGHT 3085 ) { 3086 this.focusWithTarget( 3087 'InlineTextInput' + this.timeStamp.toString() 3088 ); 3089 event.stopPropagation(); 3090 } 3091 }); 3092 TextInput.onChange(value => { 3093 this.inputValue = value; 3094 for (let i = 0; i < value.length; i++) { 3095 let c = value[i]; 3096 if (c === '+' || c === '*' || c === '#') { 3097 this.value -= 1; 3098 this.value += 1; 3099 this.inputValue = this.value.toString(); 3100 return; 3101 } 3102 if (c === '-' && i !== 0) { 3103 this.inputValue = c; 3104 break; 3105 } 3106 } 3107 this.hasInputText1 = true; 3108 let c = value[value.length - 1]; 3109 if (value.length === this.getMaxLength()) { 3110 this.inputValue = c; 3111 } 3112 if (this.timeoutID1 !== -1) { 3113 clearTimeout(this.timeoutID1); 3114 this.timeoutID1 = -1; 3115 } 3116 if ( 3117 this.inputValue !== '' && 3118 Number(this.inputValue) <= this.max && 3119 Number(this.inputValue) >= this.min 3120 ) { 3121 this.value = Number(this.inputValue); 3122 this.onChange?.(this.value); 3123 this.hasInputText1 = false; 3124 } else { 3125 if ( 3126 Number(this.inputValue) > this.max || 3127 (Number(this.inputValue) < this.min && 3128 this.inputValue.length <= this.min.toString().length) 3129 ) { 3130 this.inputValue = c; 3131 } 3132 if (value.length < this.getMaxLength()) { 3133 this.timeoutID1 = setTimeout(() => { 3134 if ( 3135 this.inputValue !== '' && 3136 Number(this.inputValue) <= this.max && 3137 Number(this.inputValue) >= this.min 3138 ) { 3139 this.value = Number(this.inputValue); 3140 this.onChange?.(this.value); 3141 } 3142 this.inputValue = this.value.toString(); 3143 this.hasInputText1 = false; 3144 this.updateInlineEnableSate(); 3145 }, 1500); 3146 } 3147 } 3148 this.updateInlineEnableSate(); 3149 }); 3150 TextInput.onSubmit(enterKey => { 3151 if (this.timeoutID1 != -1) { 3152 clearTimeout(this.timeoutID1); 3153 this.timeoutID1 = -1; 3154 } 3155 this.hasInputText1 = false; 3156 this.value -= 1; 3157 if ( 3158 Number(this.inputValue) >= this.min && 3159 Number(this.inputValue) <= this.max 3160 ) { 3161 this.value = Number(this.inputValue); 3162 this.onChange?.(this.value); 3163 this.updateInlineEnableSate(); 3164 } else { 3165 this.value += 1; 3166 this.inputValue = this.value.toString(); 3167 } 3168 }); 3169 TextInput.focusable(true); 3170 TextInput.focusOnTouch(true); 3171 TextInput.onFocus(() => { 3172 this.focusText = FocusText.TEXT1; 3173 this.hasFocusText1 = true; 3174 this.controller1.caretPosition( 3175 this.value.toString().length 3176 ); 3177 }); 3178 TextInput.onBlur(() => { 3179 this.focusText = FocusText.NONE; 3180 this.hasFocusText1 = false; 3181 }); 3182 TextInput.onClick(event => { 3183 this.focusText = FocusText.TEXT1; 3184 this.hasFocusText1 = true; 3185 this.focusWithTarget( 3186 'InlineTextInput' + this.timeStamp.toString() 3187 ); 3188 this.controller1.caretPosition( 3189 this.value.toString().length 3190 ); 3191 }); 3192 }, TextInput); 3193 RelativeContainer.pop(); 3194 }); 3195 } else { 3196 this.ifElseBranchUpdateFunction(1, () => { 3197 this.observeComponentCreation2((elmtId, isInitialRender) => { 3198 Row.create(); 3199 Row.direction(this.counterDirection); 3200 Row.margin({ 3201 start: LengthMetrics.vp( 3202 CounterResource.COUNTER_INLINE_INPUT_TEXT_MARGIN 3203 ), 3204 end: LengthMetrics.vp( 3205 CounterResource.COUNTER_INLINE_INPUT_TEXT_MARGIN 3206 ), 3207 }); 3208 }, Row); 3209 this.observeComponentCreation2((elmtId, isInitialRender) => { 3210 TextInput.create({ 3211 text: this.hasInputText1 3212 ? this.inputValue 3213 : this.value.toString(), 3214 controller: this.controller1, 3215 }); 3216 TextInput.accessibilityDescription({ 3217 id: -1, 3218 type: 10003, 3219 params: [ 3220 'sys.string.input_counter_double_click_description', 3221 ], 3222 bundleName: '__harDefaultBundleName__', 3223 moduleName: '__harDefaultModuleName__', 3224 }); 3225 TextInput.direction(this.counterDirection); 3226 TextInput.width(this.getValueLength() * 9.6); 3227 TextInput.height('20vp'); 3228 TextInput.padding(0); 3229 TextInput.borderRadius(0); 3230 TextInput.textAlign(TextAlign.Center); 3231 TextInput.type(InputType.PhoneNumber); 3232 TextInput.copyOption(CopyOptions.None); 3233 TextInput.fontSize(this.getTextInputFontSize()); 3234 TextInput.fontWeight(FontWeight.Medium); 3235 TextInput.fontColor( 3236 this.hasFocusText1 3237 ? Color.White 3238 : CounterResource.COUNTER_TEXT_COLOR 3239 ); 3240 TextInput.maxLength(this.getMaxLength()); 3241 TextInput.backgroundColor( 3242 this.hasFocusText1 3243 ? CounterResource.BUTTON_BORDER_FOCUSED_COLOR 3244 : Color.Transparent 3245 ); 3246 TextInput.key('InlineTextInput' + this.timeStamp.toString()); 3247 TextInput.onKeyEvent(event => { 3248 this.focusCurrentText(FocusText.TEXT1); 3249 if (event.keyCode === CounterConstant.KEYCODE_ESC) { 3250 this.resetFocusText(); 3251 event.stopPropagation(); 3252 } 3253 if ( 3254 event.type === KeyType.Down && 3255 event.keyCode === CounterConstant.KEYCODE_DPAD_UP 3256 ) { 3257 this.addValue(); 3258 event.stopPropagation(); 3259 } 3260 if ( 3261 event.type === KeyType.Down && 3262 event.keyCode === CounterConstant.KEYCODE_DPAD_DOWN 3263 ) { 3264 this.subValue(); 3265 event.stopPropagation(); 3266 } 3267 if ( 3268 event.type === KeyType.Down && 3269 event.keyCode === CounterConstant.KEYCODE_DPAD_LEFT 3270 ) { 3271 this.focusWithTarget( 3272 'InlineTextInput' + this.timeStamp.toString() 3273 ); 3274 event.stopPropagation(); 3275 } 3276 if ( 3277 event.type === KeyType.Down && 3278 event.keyCode === CounterConstant.KEYCODE_DPAD_RIGHT 3279 ) { 3280 this.focusWithTarget( 3281 'InlineTextInput' + this.timeStamp.toString() 3282 ); 3283 event.stopPropagation(); 3284 } 3285 }); 3286 TextInput.onChange(value => { 3287 this.inputValue = value; 3288 for (let i = 0; i < value.length; i++) { 3289 let c = value[i]; 3290 if (c === '+' || c === '*' || c === '#') { 3291 this.value -= 1; 3292 this.value += 1; 3293 this.inputValue = this.value.toString(); 3294 return; 3295 } 3296 if (c === '-' && i !== 0) { 3297 this.inputValue = c; 3298 break; 3299 } 3300 } 3301 this.hasInputText1 = true; 3302 let c = value[value.length - 1]; 3303 if (value.length === this.getMaxLength()) { 3304 this.inputValue = c; 3305 } 3306 if (this.timeoutID1 !== -1) { 3307 clearTimeout(this.timeoutID1); 3308 this.timeoutID1 = -1; 3309 } 3310 if ( 3311 this.inputValue !== '' && 3312 Number(this.inputValue) <= this.max && 3313 Number(this.inputValue) >= this.min 3314 ) { 3315 this.value = Number(this.inputValue); 3316 this.onChange?.(this.value); 3317 this.hasInputText1 = false; 3318 } else { 3319 if ( 3320 Number(this.inputValue) > this.max || 3321 (Number(this.inputValue) < this.min && 3322 this.inputValue.length <= this.min.toString().length) 3323 ) { 3324 this.inputValue = c; 3325 } 3326 if (value.length < this.getMaxLength()) { 3327 this.timeoutID1 = setTimeout(() => { 3328 if ( 3329 this.inputValue !== '' && 3330 Number(this.inputValue) <= this.max && 3331 Number(this.inputValue) >= this.min 3332 ) { 3333 this.value = Number(this.inputValue); 3334 this.onChange?.(this.value); 3335 } 3336 this.inputValue = this.value.toString(); 3337 this.hasInputText1 = false; 3338 this.updateInlineEnableSate(); 3339 }, 1500); 3340 } 3341 } 3342 this.updateInlineEnableSate(); 3343 }); 3344 TextInput.onSubmit(enterKey => { 3345 if (this.timeoutID1 !== -1) { 3346 clearTimeout(this.timeoutID1); 3347 this.timeoutID1 = -1; 3348 } 3349 this.hasInputText1 = false; 3350 this.value -= 1; 3351 if ( 3352 Number(this.inputValue) >= this.min && 3353 Number(this.inputValue) <= this.max 3354 ) { 3355 this.value = Number(this.inputValue); 3356 this.onChange?.(this.value); 3357 this.updateInlineEnableSate(); 3358 } else { 3359 this.value += 1; 3360 this.inputValue = this.value.toString(); 3361 } 3362 }); 3363 TextInput.focusable(true); 3364 TextInput.focusOnTouch(true); 3365 TextInput.onFocus(() => { 3366 this.focusText = FocusText.TEXT1; 3367 this.hasFocusText1 = true; 3368 this.controller1.caretPosition( 3369 this.value.toString().length 3370 ); 3371 }); 3372 TextInput.onBlur(() => { 3373 this.focusText = FocusText.NONE; 3374 this.hasFocusText1 = false; 3375 }); 3376 TextInput.onClick(event => { 3377 this.focusText = FocusText.TEXT1; 3378 this.hasFocusText1 = true; 3379 this.focusWithTarget( 3380 'InlineTextInput' + this.timeStamp.toString() 3381 ); 3382 this.controller1.caretPosition( 3383 this.value.toString().length 3384 ); 3385 }); 3386 }, TextInput); 3387 Row.pop(); 3388 }); 3389 } 3390 }, If); 3391 If.pop(); 3392 this.observeComponentCreation2((elmtId, isInitialRender) => { 3393 Column.create(); 3394 Column.direction(this.counterDirection); 3395 Column.width(CounterResource.COUNTER_INLINE_BUTTON_WIDTH); 3396 Column.height(CounterResource.COUNTER_INLINE_CONTAINER_HEIGHT); 3397 Column.borderWidth({ 3398 start: LengthMetrics.vp( 3399 CounterResource.COUNTER_BORDER_WIDTH_NUMBER 3400 ), 3401 }); 3402 Column.borderColor(CounterResource.COUNTER_BORDER_COLOR); 3403 }, Column); 3404 this.observeComponentCreation2((elmtId, isInitialRender) => { 3405 Stack.create(); 3406 Stack.direction(this.counterDirection); 3407 Stack.width(CounterResource.COUNTER_INLINE_BUTTON_WIDTH); 3408 Stack.height(CounterResource.COUNTER_INLINE_BUTTON_HEIGHT); 3409 Stack.padding({ top: '1vp' }); 3410 Stack.borderWidth({ bottom: '1vp' }); 3411 Stack.borderColor(CounterResource.COUNTER_BORDER_COLOR); 3412 Stack.clip(true); 3413 }, Stack); 3414 this.observeComponentCreation2((elmtId, isInitialRender) => { 3415 Rect.create(); 3416 Rect.direction(this.counterDirection); 3417 Rect.width(CounterResource.COUNTER_INLINE_FOCUS_BORDER_WIDTH); 3418 Rect.height(CounterResource.COUNTER_INLINE_FOCUS_BORDER_HEIGHT); 3419 Rect.radius([ 3420 ['0vp', '0vp'], 3421 [ 3422 CounterResource.COUNTER_INLINE_RADIUS, 3423 CounterResource.COUNTER_INLINE_RADIUS, 3424 ], 3425 ['0vp', '0vp'], 3426 ['0vp', '0vp'], 3427 ]); 3428 Rect.strokeWidth(this.addBtnFocusWidh); 3429 Rect.stroke(CounterResource.BUTTON_BORDER_FOCUSED_COLOR); 3430 Rect.margin({ end: LengthMetrics.vp(2) }); 3431 Rect.fillOpacity(0); 3432 }, Rect); 3433 this.observeComponentCreation2((elmtId, isInitialRender) => { 3434 Image.create(CounterResource.BUTTON_ARROW_UP); 3435 Image.direction(this.counterDirection); 3436 Image.width(CounterResource.COUNTER_INLINE_BUTTON_ICON_WIDTH); 3437 Image.height(CounterResource.COUNTER_INLINE_BUTTON_ICON_HEIGHT); 3438 Image.fillColor(CounterResource.BUTTON_ICON_COLOR); 3439 Image.opacity(this.addOpacity); 3440 }, Image); 3441 this.observeComponentCreation2((elmtId, isInitialRender) => { 3442 Button.createWithLabel({ 3443 type: ButtonType.Normal, 3444 stateEffect: this.addBtnStateEffect, 3445 }); 3446 Button.accessibilityText({ 3447 id: -1, 3448 type: 10003, 3449 params: ['sys.string.increase_used_for_accessibility_text'], 3450 bundleName: '__harDefaultBundleName__', 3451 moduleName: '__harDefaultModuleName__', 3452 }); 3453 Button.accessibilityDescription( 3454 this.value === this.max ? '' : this.increaseStr 3455 ); 3456 Button.direction(this.counterDirection); 3457 Button.width(CounterResource.COUNTER_INLINE_BUTTON_WIDTH); 3458 Button.height(CounterResource.COUNTER_INLINE_BUTTON_HEIGHT); 3459 Button.backgroundColor(Color.Transparent); 3460 Button.opacity(this.addOpacity); 3461 Button.enabled(this.addBtnEnabled); 3462 Button.onClick(event => { 3463 this.addValue(); 3464 if ( 3465 event.source === SourceType.Mouse || 3466 event.source === SourceType.TouchScreen 3467 ) { 3468 this.addBtnFocusWidh = CounterResource.BUTTON_BORDER_BLUR_WIDTH; 3469 } 3470 try { 3471 let eventInfo = { 3472 type: 'announceForAccessibility', 3473 bundleName: getContext()?.abilityInfo?.bundleName, 3474 triggerAction: 'click', 3475 textAnnouncedForAccessibility: this.value?.toString(), 3476 }; 3477 accessibility.sendAccessibilityEvent(eventInfo).then(() => { 3478 console.log('Accessility addValue click send event'); 3479 }); 3480 } catch (exception) { 3481 let code = exception.code; 3482 let message = exception.message; 3483 console.log( 3484 `Accessility addValue click longPress faild error code:${code} message:${message}` 3485 ); 3486 } 3487 }); 3488 Gesture.create(GesturePriority.Low); 3489 LongPressGesture.create({ repeat: true }); 3490 LongPressGesture.onAction(event => { 3491 if (event.repeat) { 3492 this.addValue(); 3493 } 3494 this.addBtnFocusWidh = CounterResource.BUTTON_BORDER_BLUR_WIDTH; 3495 }); 3496 LongPressGesture.onActionEnd(() => { 3497 try { 3498 let eventInfo = { 3499 type: 'announceForAccessibility', 3500 bundleName: getContext()?.abilityInfo?.bundleName, 3501 triggerAction: 'common', 3502 textAnnouncedForAccessibility: this.value?.toString(), 3503 }; 3504 accessibility.sendAccessibilityEvent(eventInfo).then(() => { 3505 console.log('Accessility addValue longPress send event'); 3506 }); 3507 } catch (exception) { 3508 let code = exception.code; 3509 let message = exception.message; 3510 console.log( 3511 `Accessility addValue longPress faild error code:${code} message:${message}` 3512 ); 3513 } 3514 }); 3515 LongPressGesture.pop(); 3516 Gesture.pop(); 3517 Button.hoverEffect(this.choverEffect); 3518 Button.onHover(isHover => { 3519 this.onHoverIncrease && this.onHoverIncrease(isHover); 3520 }); 3521 Button.focusable(false); 3522 Button.onFocus(() => { 3523 this.addBtnFocusWidh = 3524 CounterResource.BUTTON_BORDER_FOCUSED_WIDTH; 3525 this.onFocusIncrease && this.onFocusIncrease(); 3526 }); 3527 Button.onBlur(() => { 3528 this.addBtnFocusWidh = CounterResource.BUTTON_BORDER_BLUR_WIDTH; 3529 this.onBlurIncrease && this.onBlurIncrease(); 3530 }); 3531 }, Button); 3532 Button.pop(); 3533 Stack.pop(); 3534 this.observeComponentCreation2((elmtId, isInitialRender) => { 3535 Stack.create(); 3536 Stack.direction(this.counterDirection); 3537 Stack.width(CounterResource.COUNTER_INLINE_BUTTON_WIDTH); 3538 Stack.height(CounterResource.COUNTER_INLINE_BUTTON_HEIGHT); 3539 Stack.clip(true); 3540 }, Stack); 3541 this.observeComponentCreation2((elmtId, isInitialRender) => { 3542 Rect.create(); 3543 Rect.direction(this.counterDirection); 3544 Rect.width(CounterResource.COUNTER_INLINE_FOCUS_BORDER_WIDTH); 3545 Rect.height(CounterResource.COUNTER_INLINE_FOCUS_BORDER_HEIGHT); 3546 Rect.radius([ 3547 ['0vp', '0vp'], 3548 ['0vp', '0vp'], 3549 [ 3550 CounterResource.COUNTER_INLINE_RADIUS, 3551 CounterResource.COUNTER_INLINE_RADIUS, 3552 ], 3553 ['0vp', '0vp'], 3554 ]); 3555 Rect.strokeWidth(this.subBtnFocusWidh); 3556 Rect.stroke(CounterResource.BUTTON_BORDER_FOCUSED_COLOR); 3557 Rect.margin({ 3558 top: LengthMetrics.vp(1), 3559 end: LengthMetrics.vp(1), 3560 bottom: LengthMetrics.vp(2), 3561 }); 3562 Rect.fillOpacity(0); 3563 }, Rect); 3564 this.observeComponentCreation2((elmtId, isInitialRender) => { 3565 Image.create(CounterResource.BUTTON_ARROW_DOWN); 3566 Image.direction(this.counterDirection); 3567 Image.width(CounterResource.COUNTER_INLINE_BUTTON_ICON_WIDTH); 3568 Image.height(CounterResource.COUNTER_INLINE_BUTTON_ICON_HEIGHT); 3569 Image.fillColor(CounterResource.BUTTON_ICON_COLOR); 3570 Image.opacity(this.subOpacity); 3571 }, Image); 3572 this.observeComponentCreation2((elmtId, isInitialRender) => { 3573 Button.createWithLabel({ 3574 type: ButtonType.Normal, 3575 stateEffect: this.subBtnStateEffect, 3576 }); 3577 Button.accessibilityText({ 3578 id: -1, 3579 type: 10003, 3580 params: ['sys.string.reduce_used_for_accessibility_text'], 3581 bundleName: '__harDefaultBundleName__', 3582 moduleName: '__harDefaultModuleName__', 3583 }); 3584 Button.accessibilityDescription( 3585 this.value === this.min ? '' : this.reduceStr 3586 ); 3587 Button.direction(this.counterDirection); 3588 Button.width(CounterResource.COUNTER_INLINE_BUTTON_WIDTH); 3589 Button.height(CounterResource.COUNTER_INLINE_BUTTON_HEIGHT); 3590 Button.backgroundColor(Color.Transparent); 3591 Button.opacity(this.subOpacity); 3592 Button.enabled(this.subBtnEnabled); 3593 Button.onClick(event => { 3594 this.subValue(); 3595 if ( 3596 event.source === SourceType.Mouse || 3597 event.source === SourceType.TouchScreen 3598 ) { 3599 this.subBtnFocusWidh = CounterResource.BUTTON_BORDER_BLUR_WIDTH; 3600 } 3601 try { 3602 let eventInfo = { 3603 type: 'announceForAccessibility', 3604 bundleName: getContext()?.abilityInfo?.bundleName, 3605 triggerAction: 'click', 3606 textAnnouncedForAccessibility: this.value?.toString(), 3607 }; 3608 accessibility.sendAccessibilityEvent(eventInfo).then(() => { 3609 console.log('Accessility subValue click send event'); 3610 }); 3611 } catch (exception) { 3612 let code = exception.code; 3613 let message = exception.message; 3614 console.log( 3615 `Accessility subValue click faild error code:${code} message:${message}` 3616 ); 3617 } 3618 }); 3619 Gesture.create(GesturePriority.Low); 3620 LongPressGesture.create({ repeat: true }); 3621 LongPressGesture.onAction(event => { 3622 if (event.repeat) { 3623 this.subValue(); 3624 } 3625 this.subBtnFocusWidh = CounterResource.BUTTON_BORDER_BLUR_WIDTH; 3626 }); 3627 LongPressGesture.onActionEnd(() => { 3628 try { 3629 let eventInfo = { 3630 type: 'announceForAccessibility', 3631 bundleName: getContext()?.abilityInfo?.bundleName, 3632 triggerAction: 'common', 3633 textAnnouncedForAccessibility: this.value?.toString(), 3634 }; 3635 accessibility.sendAccessibilityEvent(eventInfo).then(() => { 3636 console.log('Accessility subValue longPress send event'); 3637 }); 3638 } catch (exception) { 3639 let code = exception.code; 3640 let message = exception.message; 3641 console.log( 3642 `Accessility subValue longPress faild error code:${code} message:${message}` 3643 ); 3644 } 3645 }); 3646 LongPressGesture.pop(); 3647 Gesture.pop(); 3648 Button.hoverEffect(this.choverEffect); 3649 Button.onHover(isHover => { 3650 this.onHoverDecrease && this.onHoverDecrease(isHover); 3651 }); 3652 Button.focusable(false); 3653 Button.onFocus(() => { 3654 this.subBtnFocusWidh = 3655 CounterResource.BUTTON_BORDER_FOCUSED_WIDTH; 3656 this.onFocusDecrease && this.onFocusDecrease(); 3657 }); 3658 Button.onBlur(() => { 3659 this.subBtnFocusWidh = CounterResource.BUTTON_BORDER_BLUR_WIDTH; 3660 this.onBlurDecrease && this.onBlurDecrease(); 3661 }); 3662 }, Button); 3663 Button.pop(); 3664 Stack.pop(); 3665 Column.pop(); 3666 Row.pop(); 3667 }); 3668 } else if (this.type === CounterType.INLINE_DATE) { 3669 this.ifElseBranchUpdateFunction(3, () => { 3670 this.observeComponentCreation2((elmtId, isInitialRender) => { 3671 Row.create(); 3672 Row.direction(this.counterDirection); 3673 Row.height(CounterResource.COUNTER_INLINE_CONTAINER_HEIGHT); 3674 Row.borderWidth(CounterResource.COUNTER_BORDER_WIDTH); 3675 Row.borderColor(CounterResource.COUNTER_BORDER_COLOR); 3676 Row.borderRadius(CounterResource.COUNTER_INLINE_RADIUS); 3677 Row.clip(true); 3678 }, Row); 3679 this.observeComponentCreation2((elmtId, isInitialRender) => { 3680 Row.create(); 3681 Row.direction(this.counterDirection); 3682 Row.width('92vp'); 3683 Row.height(CounterResource.COUNTER_INLINE_CONTAINER_HEIGHT); 3684 Row.margin({ 3685 start: LengthMetrics.vp( 3686 CounterResource.COUNTER_INLINE_DATE_TEXT_MARGIN 3687 ), 3688 end: LengthMetrics.vp( 3689 CounterResource.COUNTER_INLINE_DATE_TEXT_MARGIN 3690 ), 3691 }); 3692 }, Row); 3693 this.observeComponentCreation2((elmtId, isInitialRender) => { 3694 TextInput.create({ 3695 text: this.hasInputText1 3696 ? this.inputYear.toString() 3697 : this.getYear(), 3698 controller: this.controller1, 3699 }); 3700 TextInput.accessibilityText(this.getDateYear(this.year)); 3701 TextInput.accessibilityDescription({ 3702 id: -1, 3703 type: 10003, 3704 params: ['sys.string.input_counter_double_click_description'], 3705 bundleName: '__harDefaultBundleName__', 3706 moduleName: '__harDefaultModuleName__', 3707 }); 3708 TextInput.direction(this.counterDirection); 3709 TextInput.type(InputType.Number); 3710 TextInput.copyOption(CopyOptions.None); 3711 TextInput.fontSize(this.getTextInputFontSize()); 3712 TextInput.fontWeight(FontWeight.Medium); 3713 TextInput.fontColor( 3714 this.hasFocusText1 3715 ? Color.White 3716 : CounterResource.COUNTER_TEXT_COLOR 3717 ); 3718 TextInput.maxLength(5); 3719 TextInput.padding(0); 3720 TextInput.backgroundColor( 3721 this.hasFocusText1 3722 ? CounterResource.BUTTON_BORDER_FOCUSED_COLOR 3723 : Color.Transparent 3724 ); 3725 TextInput.width('38vp'); 3726 TextInput.height('20vp'); 3727 TextInput.borderRadius(0); 3728 TextInput.borderWidth(0); 3729 TextInput.key('DateTextInput1' + this.timeStamp.toString()); 3730 TextInput.onKeyEvent(event => { 3731 this.focusCurrentText(FocusText.TEXT1); 3732 if (event.keyCode === CounterConstant.KEYCODE_ESC) { 3733 this.resetFocusText(); 3734 event.stopPropagation(); 3735 } 3736 if ( 3737 event.type === KeyType.Down && 3738 event.keyCode === CounterConstant.KEYCODE_DPAD_UP 3739 ) { 3740 this.addDate(); 3741 event.stopPropagation(); 3742 } 3743 if ( 3744 event.type === KeyType.Down && 3745 event.keyCode === CounterConstant.KEYCODE_DPAD_DOWN 3746 ) { 3747 this.subDate(); 3748 event.stopPropagation(); 3749 } 3750 if ( 3751 event.type === KeyType.Down && 3752 event.keyCode === CounterConstant.KEYCODE_MOVE_HOME 3753 ) { 3754 this.homeFocusText(); 3755 event.stopPropagation(); 3756 } 3757 if ( 3758 event.type === KeyType.Down && 3759 event.keyCode === CounterConstant.KEYCODE_MOVE_END 3760 ) { 3761 this.endFocusText(); 3762 event.stopPropagation(); 3763 } 3764 if ( 3765 event.type === KeyType.Down && 3766 event.keyCode === CounterConstant.KEYCODE_DPAD_LEFT 3767 ) { 3768 this.focusWithTarget( 3769 'DateTextInput1' + this.timeStamp.toString() 3770 ); 3771 event.stopPropagation(); 3772 } 3773 if ( 3774 event.type === KeyType.Down && 3775 event.keyCode === CounterConstant.KEYCODE_DPAD_RIGHT 3776 ) { 3777 this.focusWithTarget( 3778 'DateTextInput2' + this.timeStamp.toString() 3779 ); 3780 } 3781 }); 3782 TextInput.onChange(value => { 3783 if (value.length !== 4) { 3784 this.hasInputText1 = true; 3785 } 3786 this.inputYear = Number(value); 3787 if (value.length === 5) { 3788 this.inputYear = this.inputYear % 10; 3789 } 3790 if (this.timeoutID1 !== -1) { 3791 clearTimeout(this.timeoutID1); 3792 this.timeoutID1 = -1; 3793 } 3794 this.timeoutID1 = setTimeout(() => { 3795 this.hasInputText1 = false; 3796 this.inputYear = this.year; 3797 this.updateDateEnableSate(); 3798 this.updateDay(); 3799 }, 1500); 3800 if ( 3801 this.inputYear >= this.minYear && 3802 this.inputYear <= this.maxYear 3803 ) { 3804 this.year = this.inputYear; 3805 this.updateDateEnableSate(); 3806 this.updateDay(); 3807 } 3808 if (value.length === 4) { 3809 let date = new DateData(this.year, this.month, this.day); 3810 this.onDateChange?.(date); 3811 } 3812 }); 3813 TextInput.onSubmit(enterKey => { 3814 if (this.timeoutID1 !== -1) { 3815 clearTimeout(this.timeoutID1); 3816 this.timeoutID1 = -1; 3817 } 3818 this.hasInputText1 = false; 3819 this.year -= 1; 3820 if ( 3821 this.inputYear >= this.minYear && 3822 this.inputYear <= this.maxYear 3823 ) { 3824 this.year = this.inputYear; 3825 } else { 3826 this.year += 1; 3827 this.inputYear = this.year; 3828 } 3829 this.updateDateEnableSate(); 3830 this.updateDay(); 3831 }); 3832 TextInput.tabIndex(0); 3833 TextInput.focusOnTouch(true); 3834 TextInput.focusable(true); 3835 TextInput.onFocus(() => { 3836 this.focusText = FocusText.TEXT1; 3837 this.hasFocusText1 = true; 3838 this.updateDateEnableSate(); 3839 this.controller1.caretPosition(this.getYear().length); 3840 }); 3841 TextInput.onBlur(() => { 3842 this.focusText = FocusText.NONE; 3843 this.hasFocusText1 = false; 3844 this.updateDateEnableSate(); 3845 }); 3846 TextInput.onClick(event => { 3847 this.focusText = FocusText.TEXT1; 3848 this.hasFocusText1 = true; 3849 this.updateDateEnableSate(); 3850 this.controller1.caretPosition(this.getYear().length); 3851 }); 3852 }, TextInput); 3853 this.observeComponentCreation2((elmtId, isInitialRender) => { 3854 Text.create('/'); 3855 Text.accessibilityLevel('no'); 3856 Text.direction(this.counterDirection); 3857 Text.textAlign(TextAlign.Center); 3858 Text.fontSize(CounterResource.COUNTER_NUMBER_SIZE); 3859 Text.maxFontScale( 3860 CounterResource.COUNTER_NUMBER_MAX_FONT_SIZE_SCALE 3861 ); 3862 Text.fontColor(CounterResource.COUNTER_TEXT_COLOR); 3863 Text.width('8vp'); 3864 }, Text); 3865 Text.pop(); 3866 this.observeComponentCreation2((elmtId, isInitialRender) => { 3867 TextInput.create({ 3868 text: this.hasInputText2 3869 ? this.inputMoon.toString() 3870 : this.convertNumberToString(this.month), 3871 controller: this.controller2, 3872 }); 3873 TextInput.accessibilityText(this.getDateMonth(this.month)); 3874 TextInput.accessibilityDescription({ 3875 id: -1, 3876 type: 10003, 3877 params: ['sys.string.input_counter_double_click_description'], 3878 bundleName: '__harDefaultBundleName__', 3879 moduleName: '__harDefaultModuleName__', 3880 }); 3881 TextInput.direction(this.counterDirection); 3882 TextInput.type(InputType.Number); 3883 TextInput.copyOption(CopyOptions.None); 3884 TextInput.fontSize(this.getTextInputFontSize()); 3885 TextInput.fontWeight(FontWeight.Medium); 3886 TextInput.fontColor( 3887 this.hasFocusText2 3888 ? Color.White 3889 : CounterResource.COUNTER_TEXT_COLOR 3890 ); 3891 TextInput.maxLength(3); 3892 TextInput.padding(0); 3893 TextInput.backgroundColor( 3894 this.hasFocusText2 3895 ? CounterResource.BUTTON_BORDER_FOCUSED_COLOR 3896 : Color.Transparent 3897 ); 3898 TextInput.width('19vp'); 3899 TextInput.height('20vp'); 3900 TextInput.borderRadius(0); 3901 TextInput.key('DateTextInput2' + this.timeStamp.toString()); 3902 TextInput.onKeyEvent(event => { 3903 this.focusCurrentText(FocusText.TEXT2); 3904 if (event.keyCode === CounterConstant.KEYCODE_ESC) { 3905 this.resetFocusText(); 3906 event.stopPropagation(); 3907 } 3908 if ( 3909 event.type === KeyType.Down && 3910 event.keyCode === CounterConstant.KEYCODE_DPAD_DOWN 3911 ) { 3912 this.subDate(); 3913 this.updateDay(); 3914 event.stopPropagation(); 3915 } 3916 if ( 3917 event.type === KeyType.Down && 3918 event.keyCode === CounterConstant.KEYCODE_DPAD_UP 3919 ) { 3920 this.addDate(); 3921 this.updateDay(); 3922 event.stopPropagation(); 3923 } 3924 if ( 3925 event.type === KeyType.Down && 3926 event.keyCode === CounterConstant.KEYCODE_MOVE_HOME 3927 ) { 3928 this.homeFocusText(); 3929 event.stopPropagation(); 3930 } 3931 if ( 3932 event.type === KeyType.Down && 3933 event.keyCode === CounterConstant.KEYCODE_MOVE_END 3934 ) { 3935 this.endFocusText(); 3936 event.stopPropagation(); 3937 } 3938 if ( 3939 event.type === KeyType.Down && 3940 event.keyCode === CounterConstant.KEYCODE_DPAD_LEFT 3941 ) { 3942 this.focusWithTarget( 3943 'DateTextInput1' + this.timeStamp.toString() 3944 ); 3945 } 3946 if ( 3947 event.type === KeyType.Down && 3948 event.keyCode === CounterConstant.KEYCODE_DPAD_RIGHT 3949 ) { 3950 this.focusWithTarget( 3951 'DateTextInput3' + this.timeStamp.toString() 3952 ); 3953 } 3954 if ( 3955 event.type === KeyType.Down && 3956 event.keyCode === CounterConstant.KEYCODE_TAB 3957 ) { 3958 event.stopPropagation(); 3959 this.focusWithTarget( 3960 'DateTextInput1' + this.timeStamp.toString() 3961 ); 3962 } 3963 }); 3964 TextInput.onChange(value => { 3965 this.inputMoon = Number(value); 3966 if (value.length !== 2) { 3967 this.hasInputText2 = true; 3968 } 3969 if (value.length === 3) { 3970 this.inputMoon = this.inputMoon % 10; 3971 } 3972 if (this.timeoutID2 !== -1) { 3973 clearTimeout(this.timeoutID2); 3974 this.timeoutID2 = -1; 3975 } 3976 this.timeoutID2 = setTimeout(() => { 3977 this.hasInputText2 = false; 3978 this.month -= 1; 3979 if (this.inputMoon >= 1 && this.inputMoon <= 12) { 3980 this.month = this.inputMoon; 3981 } else { 3982 this.month += 1; 3983 this.inputMoon = this.month; 3984 } 3985 this.updateDay(); 3986 }, 1000); 3987 if (value.length === 2) { 3988 this.hasInputText2 = false; 3989 this.month -= 1; 3990 if (this.inputMoon >= 1 && this.inputMoon <= 12) { 3991 this.month = this.inputMoon; 3992 let date = new DateData(this.year, this.month, this.day); 3993 this.onDateChange?.(date); 3994 } else { 3995 this.month += 1; 3996 this.inputMoon = this.month; 3997 } 3998 this.updateDay(); 3999 } 4000 }); 4001 TextInput.onSubmit(enterKey => { 4002 if (this.timeoutID2 !== -1) { 4003 clearTimeout(this.timeoutID2); 4004 this.timeoutID2 = -1; 4005 } 4006 this.hasInputText2 = false; 4007 this.month -= 1; 4008 if (this.inputMoon >= 1 && this.inputMoon <= 12) { 4009 this.month = this.inputMoon; 4010 this.updateDay(); 4011 } else { 4012 this.month += 1; 4013 } 4014 }); 4015 TextInput.focusOnTouch(true); 4016 TextInput.tabIndex(-1); 4017 TextInput.focusable(true); 4018 TextInput.onFocus(() => { 4019 this.focusText = FocusText.TEXT2; 4020 this.hasFocusText2 = true; 4021 this.controller2.caretPosition( 4022 this.convertNumberToString(this.month).length 4023 ); 4024 }); 4025 TextInput.onBlur(() => { 4026 this.focusText = FocusText.NONE; 4027 this.hasFocusText2 = false; 4028 }); 4029 TextInput.onClick(event => { 4030 this.focusText = FocusText.TEXT2; 4031 this.hasFocusText2 = true; 4032 this.controller2.caretPosition( 4033 this.convertNumberToString(this.month).length 4034 ); 4035 }); 4036 }, TextInput); 4037 this.observeComponentCreation2((elmtId, isInitialRender) => { 4038 Text.create('/'); 4039 Text.accessibilityLevel('no'); 4040 Text.direction(this.counterDirection); 4041 Text.textAlign(TextAlign.Center); 4042 Text.fontSize(CounterResource.COUNTER_NUMBER_SIZE); 4043 Text.maxFontScale( 4044 CounterResource.COUNTER_NUMBER_MAX_FONT_SIZE_SCALE 4045 ); 4046 Text.fontColor(CounterResource.COUNTER_TEXT_COLOR); 4047 Text.width('8vp'); 4048 }, Text); 4049 Text.pop(); 4050 this.observeComponentCreation2((elmtId, isInitialRender) => { 4051 TextInput.create({ 4052 text: this.hasInputText3 4053 ? this.inputDay.toString() 4054 : this.convertNumberToString(this.day), 4055 controller: this.controller3, 4056 }); 4057 TextInput.accessibilityText(this.getDateDay(this.day)); 4058 TextInput.accessibilityDescription({ 4059 id: -1, 4060 type: 10003, 4061 params: ['sys.string.input_counter_double_click_description'], 4062 bundleName: '__harDefaultBundleName__', 4063 moduleName: '__harDefaultModuleName__', 4064 }); 4065 TextInput.direction(this.counterDirection); 4066 TextInput.type(InputType.Number); 4067 TextInput.copyOption(CopyOptions.None); 4068 TextInput.fontSize(this.getTextInputFontSize()); 4069 TextInput.fontWeight(FontWeight.Medium); 4070 TextInput.fontColor( 4071 this.hasFocusText3 4072 ? Color.White 4073 : CounterResource.COUNTER_TEXT_COLOR 4074 ); 4075 TextInput.maxLength(3); 4076 TextInput.padding(0); 4077 TextInput.backgroundColor( 4078 this.hasFocusText3 4079 ? CounterResource.BUTTON_BORDER_FOCUSED_COLOR 4080 : Color.Transparent 4081 ); 4082 TextInput.width('19vp'); 4083 TextInput.height('20vp'); 4084 TextInput.borderRadius(0); 4085 TextInput.key('DateTextInput3' + this.timeStamp.toString()); 4086 TextInput.onKeyEvent(event => { 4087 this.focusCurrentText(FocusText.TEXT3); 4088 if (event.keyCode === CounterConstant.KEYCODE_ESC) { 4089 this.resetFocusText(); 4090 event.stopPropagation(); 4091 } 4092 if ( 4093 event.type === KeyType.Down && 4094 event.keyCode === CounterConstant.KEYCODE_DPAD_DOWN 4095 ) { 4096 this.subDate(); 4097 event.stopPropagation(); 4098 } 4099 if ( 4100 event.type === KeyType.Down && 4101 event.keyCode === CounterConstant.KEYCODE_DPAD_UP 4102 ) { 4103 this.addDate(); 4104 event.stopPropagation(); 4105 } 4106 if ( 4107 event.type === KeyType.Down && 4108 event.keyCode === CounterConstant.KEYCODE_MOVE_HOME 4109 ) { 4110 this.homeFocusText(); 4111 event.stopPropagation(); 4112 } 4113 if ( 4114 event.type === KeyType.Down && 4115 event.keyCode === CounterConstant.KEYCODE_MOVE_END 4116 ) { 4117 this.endFocusText(); 4118 event.stopPropagation(); 4119 } 4120 if ( 4121 event.type === KeyType.Down && 4122 event.keyCode === CounterConstant.KEYCODE_DPAD_LEFT 4123 ) { 4124 this.focusWithTarget( 4125 'DateTextInput2' + this.timeStamp.toString() 4126 ); 4127 } 4128 if ( 4129 event.type === KeyType.Down && 4130 event.keyCode === CounterConstant.KEYCODE_DPAD_RIGHT 4131 ) { 4132 this.focusWithTarget( 4133 'DateTextInput3' + this.timeStamp.toString() 4134 ); 4135 event.stopPropagation(); 4136 } 4137 if ( 4138 event.type === KeyType.Down && 4139 event.keyCode === CounterConstant.KEYCODE_TAB 4140 ) { 4141 event.stopPropagation(); 4142 this.focusWithTarget( 4143 'DateTextInput1' + this.timeStamp.toString() 4144 ); 4145 } 4146 }); 4147 TextInput.onChange(value => { 4148 this.inputDay = Number(value); 4149 if (value.length !== 2) { 4150 this.hasInputText3 = true; 4151 } 4152 if (value.length === 3) { 4153 this.inputDay = this.inputDay % 10; 4154 } 4155 if (this.timeoutID3 !== -1) { 4156 clearTimeout(this.timeoutID3); 4157 this.timeoutID3 = -1; 4158 } 4159 this.timeoutID3 = setTimeout(() => { 4160 this.hasInputText3 = false; 4161 this.day -= 1; 4162 if ( 4163 this.inputDay >= 1 && 4164 this.inputDay <= this.getDayNumber() 4165 ) { 4166 this.day = this.inputDay; 4167 } else { 4168 this.day += 1; 4169 this.inputDay = this.day; 4170 } 4171 }, 1000); 4172 if (value.length === 2) { 4173 this.hasInputText3 = false; 4174 this.day -= 1; 4175 if ( 4176 this.inputDay >= 1 && 4177 this.inputDay <= this.getDayNumber() 4178 ) { 4179 this.day = this.inputDay; 4180 let date = new DateData(this.year, this.month, this.day); 4181 this.onDateChange?.(date); 4182 } else { 4183 this.day += 1; 4184 this.inputDay = this.day; 4185 } 4186 } 4187 }); 4188 TextInput.onSubmit(enterKey => { 4189 if (this.timeoutID3 !== -1) { 4190 clearTimeout(this.timeoutID3); 4191 this.timeoutID3 = -1; 4192 } 4193 this.hasInputText3 = false; 4194 this.day -= 1; 4195 if (this.inputDay >= 1 && this.inputDay <= this.getDayNumber()) { 4196 this.day = this.inputDay; 4197 } else { 4198 this.day += 1; 4199 } 4200 }); 4201 TextInput.tabIndex(-2); 4202 TextInput.focusOnTouch(true); 4203 TextInput.focusable(true); 4204 TextInput.onFocus(() => { 4205 this.focusText = FocusText.TEXT3; 4206 this.hasFocusText3 = true; 4207 this.controller3.caretPosition( 4208 this.convertNumberToString(this.day).length 4209 ); 4210 }); 4211 TextInput.onBlur(() => { 4212 this.focusText = FocusText.NONE; 4213 this.hasFocusText3 = false; 4214 }); 4215 TextInput.onClick(event => { 4216 this.focusText = FocusText.TEXT3; 4217 this.hasFocusText3 = true; 4218 this.controller3.caretPosition( 4219 this.convertNumberToString(this.day).length 4220 ); 4221 }); 4222 }, TextInput); 4223 Row.pop(); 4224 this.observeComponentCreation2((elmtId, isInitialRender) => { 4225 Column.create(); 4226 Column.direction(this.counterDirection); 4227 Column.width(CounterResource.COUNTER_INLINE_BUTTON_WIDTH); 4228 Column.height(CounterResource.COUNTER_INLINE_CONTAINER_HEIGHT); 4229 Column.borderWidth({ 4230 start: LengthMetrics.vp( 4231 CounterResource.COUNTER_BORDER_WIDTH_NUMBER 4232 ), 4233 }); 4234 Column.borderColor(CounterResource.COUNTER_BORDER_COLOR); 4235 }, Column); 4236 this.observeComponentCreation2((elmtId, isInitialRender) => { 4237 Stack.create(); 4238 Stack.width(CounterResource.COUNTER_INLINE_BUTTON_WIDTH); 4239 Stack.height(CounterResource.COUNTER_INLINE_BUTTON_HEIGHT); 4240 Stack.padding({ top: '1vp' }); 4241 Stack.borderWidth({ bottom: '1vp' }); 4242 Stack.borderColor(CounterResource.COUNTER_BORDER_COLOR); 4243 Stack.clip(true); 4244 }, Stack); 4245 this.observeComponentCreation2((elmtId, isInitialRender) => { 4246 Rect.create(); 4247 Rect.direction(this.counterDirection); 4248 Rect.width(CounterResource.COUNTER_INLINE_FOCUS_BORDER_WIDTH); 4249 Rect.height(CounterResource.COUNTER_INLINE_FOCUS_BORDER_HEIGHT); 4250 Rect.radius([ 4251 ['0vp', '0vp'], 4252 [ 4253 CounterResource.COUNTER_INLINE_RADIUS, 4254 CounterResource.COUNTER_INLINE_RADIUS, 4255 ], 4256 ['0vp', '0vp'], 4257 ['0vp', '0vp'], 4258 ]); 4259 Rect.strokeWidth(this.addBtnFocusWidh); 4260 Rect.stroke(CounterResource.BUTTON_BORDER_FOCUSED_COLOR); 4261 Rect.margin({ end: LengthMetrics.vp(1) }); 4262 Rect.fillOpacity(0); 4263 }, Rect); 4264 this.observeComponentCreation2((elmtId, isInitialRender) => { 4265 Image.create(CounterResource.BUTTON_ARROW_UP); 4266 Image.direction(this.counterDirection); 4267 Image.width(CounterResource.COUNTER_INLINE_BUTTON_ICON_WIDTH); 4268 Image.height(CounterResource.COUNTER_INLINE_BUTTON_ICON_HEIGHT); 4269 Image.fillColor(CounterResource.BUTTON_ICON_COLOR); 4270 Image.opacity(this.addOpacity); 4271 }, Image); 4272 this.observeComponentCreation2((elmtId, isInitialRender) => { 4273 Button.createWithLabel({ 4274 type: ButtonType.Normal, 4275 stateEffect: this.addBtnStateEffect, 4276 }); 4277 Button.accessibilityText({ 4278 id: -1, 4279 type: 10003, 4280 params: ['sys.string.increase_used_for_accessibility_text'], 4281 bundleName: '__harDefaultBundleName__', 4282 moduleName: '__harDefaultModuleName__', 4283 }); 4284 Button.accessibilityDescription({ 4285 id: -1, 4286 type: 10003, 4287 params: ['sys.string.increase_counter_double_click_description'], 4288 bundleName: '__harDefaultBundleName__', 4289 moduleName: '__harDefaultModuleName__', 4290 }); 4291 Button.direction(this.counterDirection); 4292 Button.width(CounterResource.COUNTER_INLINE_BUTTON_WIDTH); 4293 Button.height(CounterResource.COUNTER_INLINE_BUTTON_HEIGHT); 4294 Button.backgroundColor(Color.Transparent); 4295 Button.opacity(this.addOpacity); 4296 Button.enabled(this.addBtnEnabled); 4297 Button.onClick(event => { 4298 this.accessibilityBroadcastAddDate(); 4299 if ( 4300 event.source === SourceType.Mouse || 4301 event.source === SourceType.TouchScreen 4302 ) { 4303 this.addBtnFocusWidh = CounterResource.BUTTON_BORDER_BLUR_WIDTH; 4304 } 4305 }); 4306 Gesture.create(GesturePriority.Low); 4307 LongPressGesture.create({ repeat: true }); 4308 LongPressGesture.onAction(event => { 4309 if (event.repeat) { 4310 this.addDate(); 4311 } 4312 this.addBtnFocusWidh = CounterResource.BUTTON_BORDER_BLUR_WIDTH; 4313 }); 4314 LongPressGesture.onActionEnd(() => { 4315 this.accessibilityBroadcastAddDate(); 4316 }); 4317 LongPressGesture.pop(); 4318 Gesture.pop(); 4319 Button.hoverEffect(this.choverEffect); 4320 Button.onHover(isHover => { 4321 this.onHoverIncrease && this.onHoverIncrease(isHover); 4322 }); 4323 Button.focusable(false); 4324 Button.onFocus(() => { 4325 this.addBtnFocusWidh = 4326 CounterResource.BUTTON_BORDER_FOCUSED_WIDTH; 4327 this.onFocusIncrease && this.onFocusIncrease(); 4328 }); 4329 Button.onBlur(() => { 4330 this.addBtnFocusWidh = CounterResource.BUTTON_BORDER_BLUR_WIDTH; 4331 this.onBlurIncrease && this.onBlurIncrease(); 4332 }); 4333 }, Button); 4334 Button.pop(); 4335 Stack.pop(); 4336 this.observeComponentCreation2((elmtId, isInitialRender) => { 4337 Stack.create(); 4338 Stack.width(CounterResource.COUNTER_INLINE_BUTTON_WIDTH); 4339 Stack.height(CounterResource.COUNTER_INLINE_BUTTON_HEIGHT); 4340 Stack.clip(true); 4341 }, Stack); 4342 this.observeComponentCreation2((elmtId, isInitialRender) => { 4343 Rect.create(); 4344 Rect.direction(this.counterDirection); 4345 Rect.width(CounterResource.COUNTER_INLINE_FOCUS_BORDER_WIDTH); 4346 Rect.height(CounterResource.COUNTER_INLINE_FOCUS_BORDER_HEIGHT); 4347 Rect.radius([ 4348 ['0vp', '0vp'], 4349 ['0vp', '0vp'], 4350 [ 4351 CounterResource.COUNTER_INLINE_RADIUS, 4352 CounterResource.COUNTER_INLINE_RADIUS, 4353 ], 4354 ['0vp', '0vp'], 4355 ]); 4356 Rect.strokeWidth(this.subBtnFocusWidh); 4357 Rect.stroke(CounterResource.BUTTON_BORDER_FOCUSED_COLOR); 4358 Rect.margin({ 4359 top: LengthMetrics.vp(1), 4360 end: LengthMetrics.vp(1), 4361 bottom: LengthMetrics.vp(2), 4362 }); 4363 Rect.fillOpacity(0); 4364 }, Rect); 4365 this.observeComponentCreation2((elmtId, isInitialRender) => { 4366 Image.create(CounterResource.BUTTON_ARROW_DOWN); 4367 Image.direction(this.counterDirection); 4368 Image.width(CounterResource.COUNTER_INLINE_BUTTON_ICON_WIDTH); 4369 Image.height(CounterResource.COUNTER_INLINE_BUTTON_ICON_HEIGHT); 4370 Image.fillColor(CounterResource.BUTTON_ICON_COLOR); 4371 Image.opacity(this.subOpacity); 4372 }, Image); 4373 this.observeComponentCreation2((elmtId, isInitialRender) => { 4374 Button.createWithLabel({ 4375 type: ButtonType.Normal, 4376 stateEffect: this.subBtnStateEffect, 4377 }); 4378 Button.accessibilityText({ 4379 id: -1, 4380 type: 10003, 4381 params: ['sys.string.reduce_used_for_accessibility_text'], 4382 bundleName: '__harDefaultBundleName__', 4383 moduleName: '__harDefaultModuleName__', 4384 }); 4385 Button.accessibilityDescription({ 4386 id: -1, 4387 type: 10003, 4388 params: ['sys.string.reduce_counter_double_click_description'], 4389 bundleName: '__harDefaultBundleName__', 4390 moduleName: '__harDefaultModuleName__', 4391 }); 4392 Button.direction(this.counterDirection); 4393 Button.width(CounterResource.COUNTER_INLINE_BUTTON_WIDTH); 4394 Button.height(CounterResource.COUNTER_INLINE_BUTTON_HEIGHT); 4395 Button.backgroundColor(Color.Transparent); 4396 Button.opacity(this.subOpacity); 4397 Button.enabled(this.subBtnEnabled); 4398 Button.onClick(event => { 4399 this.accessibilityBroadcastSubDate(); 4400 if ( 4401 event.source === SourceType.Mouse || 4402 event.source === SourceType.TouchScreen 4403 ) { 4404 this.subBtnFocusWidh = CounterResource.BUTTON_BORDER_BLUR_WIDTH; 4405 } 4406 }); 4407 Gesture.create(GesturePriority.Low); 4408 LongPressGesture.create({ repeat: true }); 4409 LongPressGesture.onAction(event => { 4410 if (event.repeat) { 4411 this.subDate(); 4412 } 4413 this.subBtnFocusWidh = CounterResource.BUTTON_BORDER_BLUR_WIDTH; 4414 }); 4415 LongPressGesture.onActionEnd(() => { 4416 this.accessibilityBroadcastSubDate(); 4417 }); 4418 LongPressGesture.pop(); 4419 Gesture.pop(); 4420 Button.hoverEffect(this.choverEffect); 4421 Button.onHover(isHover => { 4422 this.onHoverDecrease && this.onHoverDecrease(isHover); 4423 }); 4424 Button.focusable(false); 4425 Button.onFocus(() => { 4426 this.subBtnFocusWidh = 4427 CounterResource.BUTTON_BORDER_FOCUSED_WIDTH; 4428 this.onFocusDecrease && this.onFocusDecrease(); 4429 }); 4430 Button.onBlur(() => { 4431 this.subBtnFocusWidh = CounterResource.BUTTON_BORDER_BLUR_WIDTH; 4432 this.onBlurDecrease && this.onBlurDecrease(); 4433 }); 4434 }, Button); 4435 Button.pop(); 4436 Stack.pop(); 4437 Column.pop(); 4438 Row.pop(); 4439 }); 4440 } else { 4441 this.ifElseBranchUpdateFunction(4, () => {}); 4442 } 4443 }, If); 4444 If.pop(); 4445 } 4446 rerender() { 4447 this.updateDirtyElements(); 4448 } 4449} 4450 4451export default { 4452 CommonOptions, 4453 NumberStyleOptions, 4454 InlineStyleOptions, 4455 DateStyleOptions, 4456 CounterType, 4457 DateData, 4458 CounterOptions, 4459 CounterComponent, 4460}; 4461