1/* 2 * Copyright (c) 2021-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 */ 15 16import Log from '../../../../../../../../common/src/main/ets/default/Log'; 17import EventManager from "../../../../../../../../common/src/main/ets/default/event/EventManager"; 18import { obtainStartAbility } from "../../../../../../../../common/src/main/ets/default/event/EventUtil"; 19import Constants from '../common/Constants'; 20import StyleConfiguration, { ControlCenterUpTitleStyle } from '../common/StyleConfiguration'; 21 22const TAG = 'Control-UpTitle'; 23 24interface IDirection { 25 direction: string 26} 27 28@Component 29export default struct UpTitle { 30 private touchMoveCallback: Function = (data: IDirection) => {}; 31 private simpleToggleLayoutEditStartCallback: Function = () => {}; 32 startX: number = 0; 33 startY: number = 0; 34 @State moveX: number = 0; 35 @State moveY: number = 0; 36 @State mSettingIsHover: boolean = false; 37 @State mEditIsHover: boolean = false; 38 @State style: ControlCenterUpTitleStyle = StyleConfiguration.getControlCenterUpTitleStyle(); 39 40 aboutToAppear() { 41 Log.showInfo(TAG, 'aboutToAppear'); 42 } 43 44 aboutToDisappear() { 45 Log.showInfo(TAG, 'aboutToDisappear'); 46 } 47 48 build() { 49 Row() { 50 Text($r('app.string.control_center')) 51 .height('100%') 52 .margin({left: this.style.marginLeft}) 53 .fontColor(this.style.fontColor) 54 .fontSize(this.style.fontSize) 55 .fontWeight(FontWeight.Medium) 56 57 Blank().height('100%') 58 59 Stack() { 60 Flex() 61 .backgroundColor(this.mSettingIsHover ? this.style.imageHoverColor : this.style.imageTransparentColor) 62 .clip(new Rect({ 63 width: this.style.imageHoverWidth, 64 height: this.style.imageHoverHeight 65 }).radius(this.style.imageHoverRadius)) 66 .width(this.style.imageHoverWidth) 67 .height(this.style.imageHoverHeight) 68 Image($r('app.media.ic_public_settings')) 69 .objectFit(ImageFit.Contain) 70 .size({ width: this.style.imageWidth, 71 height: this.style.imageHeight }) 72 .fillColor(this.style.titleImageColor) 73 .onClick(this.settingClick.bind(this)) 74 .onHover((isHover) => { 75 this.mSettingIsHover = isHover; 76 }) 77 } 78 .width(this.style.imageHoverWidth) 79 .height(this.style.imageHoverHeight) 80 81 Stack() { 82 Flex() 83 .backgroundColor(this.mEditIsHover ? this.style.imageHoverColor : this.style.imageTransparentColor) 84 .clip(new Rect({ 85 width: this.style.imageHoverWidth, 86 height: this.style.imageHoverHeight 87 }).radius(this.style.imageHoverRadius)) 88 .width(this.style.imageHoverWidth) 89 .height(this.style.imageHoverHeight) 90 Image($r('app.media.ic_public_edit')) 91 .objectFit(ImageFit.Contain) 92 .size({ width: this.style.imageWidth, 93 height: this.style.imageHeight }) 94 .fillColor(this.style.titleImageColor) 95 .onClick(this.editClick.bind(this)) 96 .onHover((isHover) => { 97 this.mEditIsHover = isHover; 98 }) 99 } 100 .width(this.style.imageHoverWidth) 101 .height(this.style.imageHoverHeight) 102 .margin({left: this.style.upTitleSpace, right: this.style.marginRight}) 103 } 104 .width('100%') 105 .height('100%') 106 .alignItems(VerticalAlign.Center) 107 .onTouch(this.touchEvent.bind(this)) 108 } 109 110 settingClick() { 111 Log.showDebug(TAG, `settingClick`); 112 EventManager.publish(obtainStartAbility('com.ohos.settings', 'com.ohos.settings.MainAbility')); 113 } 114 115 editClick() { 116 Log.showDebug(TAG, `editClick`); 117 if (this.simpleToggleLayoutEditStartCallback) { 118 this.simpleToggleLayoutEditStartCallback(); 119 }; 120 } 121 122 touchEvent(event: TouchEvent) { 123 if (event.type == Constants.TOUCHTYPE_DOWN) { 124 this.startX = event.touches[0].screenX; 125 this.startY = event.touches[0].screenY; 126 Log.showDebug(TAG, `quicklySetting touchStart2=======startX: ${this.startX}, startY: ${this.startY}`); 127 } else if (event.type == Constants.TOUCHTYPE_MOVE) { 128 this.moveX = event.touches[0].screenX - this.startX; 129 this.moveY = event.touches[0].screenY - this.startY; 130 } else if (event.type == Constants.TOUCHTYPE_UP) { 131 Log.showDebug(TAG, `quicklySetting touchEnd2, moveX: ${this.moveX}, moveY: ${this.moveY}`); 132 if (this.moveX < -30) { 133 if (this.touchMoveCallback) { 134 this.touchMoveCallback({ 'direction': 'left' }); 135 }; 136 } else if (this.moveX > 30) { 137 if (this.touchMoveCallback) { 138 this.touchMoveCallback({ 'direction': 'right' }); 139 }; 140 }; 141 }; 142 } 143}