1/* 2 * Copyright (c) 2022 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 */ 15import { keySourceListData, numberSourceListData, symbolSourceListData, keySourceListType, sourceListType 16} from '../model/keyboardKeyData' 17import { InputHandler } from '../model/KeyboardController' 18import styleConfiguration from '../common/styleConfiguration' 19import Log from '../model/Log' 20import deviceInfo from '@ohos.deviceInfo' 21 22let deviceType = deviceInfo.deviceType 23let TAG: string = 'index->' 24//�д�Сд�İ������ 25@Component 26struct keyItemNumber { 27 private keyValue: keySourceListType 28 @Link inputStyle: any 29 @Link upper: number 30 31 @Styles pressedStyles() { 32 .backgroundColor("#AEB3BD") 33 } 34 35 @Styles normalStyles() { 36 .backgroundColor("#ffffff") 37 } 38 39 build() { 40 Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { 41 if (this.inputStyle.deviceType == 'phone_landSpace') { 42 Stack({ alignContent: Alignment.TopEnd }) { 43 Text(this.upper === 0 ? this.keyValue.content : this.keyValue.upperContent) 44 .fontSize(this.inputStyle.en_fontSize) 45 .fontColor('#000') 46 .fontWeight(FontWeight.Regular) 47 .width('100%') 48 .height('100%') 49 .textAlign(TextAlign.Center) 50 Text(this.keyValue.title) 51 .fontSize(this.inputStyle.litterNumberFontSize) 52 .fontColor('#000') 53 .fontWeight(FontWeight.Regular) 54 .width('12vp') 55 .height('12vp') 56 .textAlign(TextAlign.Center) 57 .margin({ top: 1, right: 1 }) 58 } 59 .width('100%') 60 .height('100%') 61 } else { 62 Text(this.keyValue.title) 63 .fontSize(this.inputStyle.litterNumberFontSize) 64 .fontColor('#606060') 65 .fontWeight(FontWeight.Regular) 66 .margin({ top: 4 }) 67 Text(this.upper === 0 ? this.keyValue.content : this.keyValue.upperContent) 68 .fontSize(this.inputStyle.en_fontSize) 69 .fontColor('#000') 70 .fontWeight(FontWeight.Regular) 71 } 72 } 73 .backgroundColor('#ffffff') 74 .borderRadius(4) 75 .onClick(() => { 76 if (this.upper === 0) { 77 InputHandler.getInstance().insertText(this.keyValue.content); 78 } else { 79 if (this.upper === 1) { 80 this.upper = 0 81 } 82 InputHandler.getInstance().insertText(this.keyValue.upperContent); 83 } 84 }) 85 .width(this.inputStyle.basicButtonWidth) 86 .height('100%') 87 .shadow({ radius: 1, color: '#76787c', offsetY: 3 }) 88 .stateStyles({ 89 normal: this.normalStyles, pressed: this.pressedStyles 90 }) 91 } 92} 93 94//��Сд�İ������ 95@Component 96struct keyItem { 97 private keyValue: keySourceListType 98 private color: string 99 @Link inputStyle: any 100 @Styles pressedStyles() { 101 .backgroundColor("#AEB3BD") 102 } 103 104 @Styles normalStyles() { 105 .backgroundColor("#ffffff") 106 } 107 108 build() { 109 Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { 110 Text(this.keyValue.content) 111 .fontSize(this.inputStyle.symbol_fontSize) 112 .fontColor('#000') 113 } 114 .backgroundColor('#fff') 115 .borderRadius(4) 116 .width(this.inputStyle.basicButtonWidth) 117 .height('100%') 118 .shadow({ radius: 1, color: '#76787c', offsetY: 3 }) 119 .padding({ top: '5%', bottom: '5%' }) 120 .onClick(() => { 121 InputHandler.getInstance().insertText(this.keyValue.content); 122 }) 123 .stateStyles({ 124 normal: this.normalStyles, pressed: this.pressedStyles 125 }) 126 } 127} 128 129//��Сд�Ļ�ɫ��� 130@Component 131struct keyItemGray { 132 private keyValue: string 133 @Link inputStyle: any 134 @Link menuType: number 135 136 @Styles pressedStyles() { 137 .backgroundColor("#868b95") 138 } 139 140 @Styles normalStyles() { 141 .backgroundColor("#a8abb7") 142 } 143 144 build() { 145 Stack() { 146 Text(this.keyValue).fontSize(this.inputStyle.switchNumberFontSize).fontColor('black') 147 } 148 .backgroundColor('#a8abb7') 149 .borderRadius(4) 150 .onClick(() => { 151 if (this.keyValue === "?123") { 152 this.menuType = 1 153 } else if (this.keyValue === "=/\<") { 154 this.menuType = 2 155 } else if (this.keyValue === 'ABC') { 156 this.menuType = 0 157 } 158 }) 159 .height('100%') 160 .width(this.inputStyle.switchButtonWidth) 161 .shadow({ radius: 1, color: '#76787c', offsetY: 3 }) 162 .stateStyles({ 163 normal: this.normalStyles, pressed: this.pressedStyles 164 }) 165 } 166} 167 168//ɾ����� 169@Component 170struct deleteItem { 171 @Link inputStyle: any 172 @Styles pressedStyles() { 173 .backgroundColor("#868b95") 174 } 175 176 @Styles normalStyles() { 177 .backgroundColor("#a8abb7") 178 } 179 180 build() { 181 Stack() { 182 Image($rawfile('delete.svg')) 183 .width(this.inputStyle.featurePicSize) 184 .height(this.inputStyle.featurePicSize) 185 } 186 .backgroundColor('#a8abb7') 187 .borderRadius(4) 188 .onClick(() => { 189 InputHandler.getInstance().deleteBackward(1); 190 }) 191 .width(this.inputStyle.switchButtonWidth) 192 .height('100%') 193 .shadow({ radius: 1, color: '#76787c', offsetY: 3 }) 194 .stateStyles({ 195 normal: this.normalStyles, pressed: this.pressedStyles 196 }) 197 } 198} 199 200//������� 201@Component 202struct returnItem { 203 private returnWidth: any 204 @Link inputStyle: any 205 @Styles pressedStyles() { 206 .backgroundColor("#868b95") 207 } 208 209 @Styles normalStyles() { 210 .backgroundColor("#a8abb7") 211 } 212 213 build() { 214 Stack() { 215 Image($rawfile('return.svg')) 216 .width(this.inputStyle.returnPicSize) 217 .height(this.inputStyle.returnPicSize) 218 } 219 .backgroundColor('#a8abb7') 220 .width(this.returnWidth) 221 .borderRadius(4) 222 .height('100%') 223 .shadow({ radius: 1, color: '#76787c', offsetY: 3 }) 224 .onClick(() => { 225 InputHandler.getInstance().sendKeyFunction(); 226 }) 227 .stateStyles({ 228 normal: this.normalStyles, pressed: this.pressedStyles 229 }) 230 } 231} 232 233//�ո���� 234@Component 235struct spaceItem { 236 private spaceWith: any 237 @Link inputStyle: any 238 @Styles pressedStyles() { 239 .backgroundColor("#AEB3BD") 240 } 241 242 @Styles normalStyles() { 243 .backgroundColor("#ffffff") 244 } 245 246 build() { 247 Stack() { 248 Text('space') 249 .fontSize(this.inputStyle.symbol_fontSize) 250 .fontColor('black') 251 } 252 .backgroundColor('#ffffff') 253 .width(this.spaceWith) 254 .borderRadius(4) 255 .height('100%') 256 .onClick(() => { 257 InputHandler.getInstance().insertText(' '); 258 }) 259 .shadow({ radius: 1, color: '#76787c', offsetY: 3 }) 260 .stateStyles({ 261 normal: this.normalStyles, pressed: this.pressedStyles 262 }) 263 } 264} 265 266//key���� 267@Component 268struct keyMenu { 269 private keyList: keySourceListType[] 270 @Link inputStyle: any 271 @State public upper: number = 0 272 @Link menuType: number 273 274 @Styles pressedStyles() { 275 .backgroundColor("#868b95") 276 } 277 278 @Styles normalStyles() { 279 .backgroundColor("#a8abb7") 280 } 281 282 build() { 283 Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) { 284 Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { 285 ForEach(this.keyList.slice(0, 10), (item: keySourceListType) => { 286 keyItemNumber({ keyValue: item, upper: $upper, inputStyle: $inputStyle }) 287 }, (item: keySourceListType) => item.content) 288 } 289 .width('100%') 290 .height(this.inputStyle.basicButtonHeight) 291 .margin({ top: this.inputStyle.paddingTop }) 292 293 Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { 294 Stack() { 295 }.width('4%').height(0) 296 297 ForEach(this.keyList.slice(10, 19), (item: keySourceListType) => { 298 keyItemNumber({ keyValue: item, upper: $upper, inputStyle: $inputStyle }) 299 }, (item: keySourceListType) => item.content) 300 Stack() { 301 }.width('4%').height(0) 302 } 303 .width('100%') 304 .height(this.inputStyle.basicButtonHeight) 305 .margin({ top: this.inputStyle.paddingTop }) 306 307 Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { 308 Stack() { 309 Image($rawfile(this.upper === 1 ? 'shift light.svg' : this.upper === 2 ? 'shift light long.svg' : 'shift.svg')) 310 .width(this.inputStyle.featurePicSize) 311 .height(this.inputStyle.featurePicSize) 312 } 313 .backgroundColor('#a8abb7') 314 .borderRadius(4) 315 .onClick(() => { 316 if (this.upper === 0) { 317 this.upper = 1 318 } else if (this.upper === 1) { 319 this.upper = 2 320 } else if (this.upper === 2) { 321 this.upper = 0 322 } 323 }) 324 .height('100%') 325 .width(this.inputStyle.switchButtonWidth) 326 .shadow({ radius: 1, color: '#76787c', offsetY: 3 }) 327 .stateStyles({ 328 normal: this.normalStyles, pressed: this.pressedStyles 329 }) 330 331 332 ForEach(this.keyList.slice(19), (item: keySourceListType) => { 333 keyItemNumber({ keyValue: item, upper: $upper, inputStyle: $inputStyle }) 334 }, (item: keySourceListType) => item.content) 335 deleteItem({ inputStyle: $inputStyle }) 336 } 337 .width('100%') 338 .height(this.inputStyle.basicButtonHeight) 339 .margin({ top: this.inputStyle.paddingTop }) 340 341 Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { 342 keyItemGray({ keyValue: '?123', menuType: $menuType, inputStyle: $inputStyle }) 343 keyItem({ 344 keyValue: { content: ',', title: ',', upperContent: ',' }, 345 color: '#a8abb7', 346 inputStyle: $inputStyle 347 }) 348 spaceItem({ spaceWith: this.inputStyle.spaceButtonWidth_1, inputStyle: $inputStyle }) 349 350 keyItem({ 351 keyValue: { content: '.', title: '.', upperContent: '.' }, 352 color: '#a8abb7', 353 inputStyle: $inputStyle 354 }) 355 returnItem({ returnWidth: this.inputStyle.returnButtonWidthType_1, inputStyle: $inputStyle }) 356 } 357 .width('100%') 358 .height(this.inputStyle.basicButtonHeight) 359 .margin({ top: this.inputStyle.paddingTop }) 360 361 } 362 .width('100%') 363 .height('100%') 364 .padding({ 365 left: this.inputStyle.paddingLeftRight, 366 right: this.inputStyle.paddingLeftRight 367 }) 368 } 369} 370 371//���ּ��� 372@Component 373struct numberMenu { 374 private numberList: sourceListType[] 375 @Link inputStyle: any 376 @Link menuType: number 377 378 @Styles pressedStyles() { 379 .backgroundColor("#AEB3BD") 380 } 381 382 @Styles normalStyles() { 383 .backgroundColor("#ffffff") 384 } 385 386 build() { 387 Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) { 388 Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { 389 ForEach(this.numberList.slice(0, 10), (item: sourceListType) => { 390 keyItem({ 391 keyValue: { content: item.content, title: item.content, upperContent: item.content }, 392 color: '#ffffff', 393 inputStyle: $inputStyle 394 }) 395 }, (item: sourceListType) => item.content) 396 } 397 .width('100%') 398 .height(this.inputStyle.basicButtonHeight) 399 .margin({ top: this.inputStyle.paddingTop }) 400 401 Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { 402 ForEach(this.numberList.slice(10, 20), (item: sourceListType) => { 403 keyItem({ 404 keyValue: { content: item.content, title: item.content, upperContent: item.content }, 405 color: '#ffffff', 406 inputStyle: $inputStyle 407 }) 408 }, (item: sourceListType) => item.content) 409 } 410 .width('100%') 411 .height(this.inputStyle.basicButtonHeight) 412 .margin({ top: this.inputStyle.paddingTop }) 413 414 Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { 415 keyItemGray({ keyValue: '=/\<', menuType: $menuType, inputStyle: $inputStyle }) 416 ForEach(this.numberList.slice(20), (item: sourceListType) => { 417 keyItem({ 418 keyValue: { content: item.content, title: item.content, upperContent: item.content }, 419 color: '#ffffff', 420 inputStyle: $inputStyle 421 }) 422 }, (item: sourceListType) => item.content) 423 deleteItem({ inputStyle: $inputStyle }) 424 } 425 .width('100%') 426 .height(this.inputStyle.basicButtonHeight) 427 .margin({ top: this.inputStyle.paddingTop }) 428 429 Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { 430 keyItemGray({ keyValue: 'ABC', menuType: $menuType, inputStyle: $inputStyle }) 431 keyItem({ 432 keyValue: { content: '_', title: '_', upperContent: '_' }, 433 color: '#a8abb7', 434 inputStyle: $inputStyle 435 }) 436 keyItem({ 437 keyValue: { content: ',', title: ',', upperContent: ',' }, 438 color: '#a8abb7', 439 inputStyle: $inputStyle 440 }) 441 442 spaceItem({ spaceWith: this.inputStyle.spaceButtonWidth_2, inputStyle: $inputStyle }) 443 keyItem({ 444 keyValue: { content: '.', title: '.', upperContent: '.' }, 445 color: '#a8abb7', 446 inputStyle: $inputStyle 447 }) 448 returnItem({ returnWidth: this.inputStyle.returnButtonWidthType_2, inputStyle: $inputStyle }) 449 } 450 .width('100%') 451 .height(this.inputStyle.basicButtonHeight) 452 .margin({ top: this.inputStyle.paddingTop }) 453 } 454 .padding({ 455 left: this.inputStyle.paddingLeftRight, 456 right: this.inputStyle.paddingLeftRight 457 }) 458 } 459} 460 461//���ż��� 462@Component 463struct symbolMenu { 464 private symbolList: sourceListType[] 465 @Link inputStyle: any 466 @Link menuType: number 467 468 @Styles pressedStyles() { 469 .backgroundColor("#AEB3BD") 470 } 471 472 @Styles normalStyles() { 473 .backgroundColor("#ffffff") 474 } 475 476 build() { 477 Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) { 478 Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { 479 ForEach(this.symbolList.slice(0, 10), (item: sourceListType) => { 480 keyItem({ 481 keyValue: { content: item.content, title: item.content, upperContent: item.content }, 482 color: '#ffffff', inputStyle: $inputStyle 483 }) 484 }, (item: sourceListType) => item.content) 485 } 486 .width('100%') 487 .height(this.inputStyle.basicButtonHeight) 488 .margin({ top: this.inputStyle.paddingTop }) 489 490 Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { 491 ForEach(this.symbolList.slice(10, 20), (item: sourceListType) => { 492 keyItem({ 493 keyValue: { content: item.content, title: item.content, upperContent: item.content }, 494 color: '#ffffff', inputStyle: $inputStyle 495 }) 496 }, (item: sourceListType) => item.content) 497 } 498 .width('100%') 499 .height(this.inputStyle.basicButtonHeight) 500 .margin({ top: this.inputStyle.paddingTop }) 501 502 Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { 503 keyItemGray({ keyValue: '?123', menuType: $menuType, inputStyle: $inputStyle }) 504 ForEach(this.symbolList.slice(20), (item: sourceListType) => { 505 keyItem({ 506 keyValue: { content: item.content, title: item.content, upperContent: item.content }, 507 color: '#ffffff', inputStyle: $inputStyle 508 }) 509 }, (item: sourceListType) => item.content) 510 deleteItem({ inputStyle: $inputStyle }) 511 } 512 .width('100%') 513 .height(this.inputStyle.basicButtonHeight) 514 .margin({ top: this.inputStyle.paddingTop }) 515 516 517 Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { 518 keyItemGray({ keyValue: 'ABC', menuType: $menuType, inputStyle: $inputStyle }) 519 keyItem({ 520 keyValue: { content: '<', title: '<', upperContent: '<' }, 521 color: '#a8abb7', 522 inputStyle: $inputStyle 523 }) 524 keyItem({ 525 keyValue: { content: '>', title: '>', upperContent: '>' }, 526 color: '#a8abb7', 527 inputStyle: $inputStyle 528 }) 529 spaceItem({ spaceWith: this.inputStyle.spaceButtonWidth_2, inputStyle: $inputStyle }) 530 keyItem({ 531 keyValue: { content: '.', title: '.', upperContent: '.' }, 532 color: '#a8abb7', 533 inputStyle: $inputStyle 534 }) 535 returnItem({ returnWidth: this.inputStyle.returnButtonWidthType_2, inputStyle: $inputStyle }) 536 } 537 .width('100%') 538 .height(this.inputStyle.basicButtonHeight) 539 .margin({ top: this.inputStyle.paddingTop }) 540 } 541 .padding({ 542 left: this.inputStyle.paddingLeftRight, 543 right: this.inputStyle.paddingLeftRight 544 }) 545 } 546} 547 548//������ť 549@Component 550struct downMenu { 551 @Link inputStyle: any 552 build() { 553 Flex({ justifyContent: FlexAlign.End, alignItems: ItemAlign.Center }) { 554 Stack() { 555 Image($rawfile('down.svg')) 556 .width(this.inputStyle.downMenuPicWidth) 557 .height(this.inputStyle.downMenuPicHeight) 558 .onClick(() => { 559 InputHandler.getInstance().hideKeyboardSelf(); 560 }) 561 } 562 .width(this.inputStyle.downMenuWidth) 563 .borderRadius(4) 564 .height('100%') 565 } 566 .width('100%') 567 .height(this.inputStyle.downMenuHeight) 568 .padding(1) 569 .backgroundColor('#ffffff') 570 .borderColor('#33000000') 571 .borderWidth(0.5) 572 } 573} 574 575@Entry 576@Component 577struct Index { 578 private keyList: keySourceListType[]= keySourceListData 579 private numberList: sourceListType[]= numberSourceListData 580 private symbolList: sourceListType[]= symbolSourceListData 581 @State menuType: number= 0 582 @StorageLink('isLandscape') @Watch('change') isLandscape: boolean = false 583 @StorageLink('isRkDevice') isRkDevice: boolean = false; 584 @StorageLink('inputStyle') inputStyle: any = styleConfiguration.getInputStyle(this.isLandscape, this.isRkDevice, deviceType); 585 onBackPress(): boolean{ 586 Log.showInfo(TAG, 'kikaInput onBackPress'); 587 InputHandler.getInstance().hideKeyboardSelf(); 588 return true; 589 } 590 591 change() { 592 AppStorage.Set('inputStyle', styleConfiguration.getInputStyle(this.isLandscape, this.isRkDevice, deviceType)) 593 } 594 build() { 595 Stack() { 596 Column() { 597 downMenu({ inputStyle: $inputStyle }) 598 Column() { 599 if (this.menuType === 0) { 600 keyMenu({ 601 keyList: this.keyList, 602 menuType: $menuType, 603 inputStyle: $inputStyle 604 }) 605 } else if (this.menuType === 1) { 606 numberMenu({ 607 numberList: this.numberList, 608 menuType: $menuType, 609 inputStyle: $inputStyle }) 610 } else { 611 symbolMenu({ 612 symbolList: this.symbolList, 613 menuType: $menuType, 614 inputStyle: $inputStyle }) 615 } 616 617 }.width('100%') 618 .height(this.inputStyle.keyboardHeight) 619 .backgroundColor('#D5D7DD') 620 }.height('100%') 621 } 622 } 623}