1/* 2 * Copyright (c) 2023 Hunan OpenValley Digital Industry Development 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 stationary from '@ohos.stationary'; 17import { ColumnOperation } from '../components/ColumnOperation'; 18 19@Component 20export struct StationaryManager { 21 @State result: string = ''; 22 23 build() { 24 Scroll() { 25 Column() { 26 Row() { 27 Text(this.result) 28 .fontWeight(FontWeight.Medium) 29 .fontSize(20) 30 } 31 .alignItems(VerticalAlign.Top) 32 .width('100%') 33 .backgroundColor($r("app.color.white")) 34 .height(160) 35 .padding(16) 36 .borderRadius(20) 37 .margin({ top: 16 }) 38 ColumnOperation({ operationRes: $r('app.strarray.stationary_operations'), doOperation: this.doOperation }) 39 } 40 .width('100%') 41 .padding(4) 42 } 43 .scrollBar(BarState.Off) 44 } 45 46 doOperation = async (index: number) => { 47 switch (index) { 48 case 0: 49 try { 50 stationary.on('still', stationary.ActivityEvent.ENTER_EXIT, 3, (data) => { 51 this.result = `on still success:${JSON.stringify(data)}`; 52 }) 53 this.result = ``; 54 } catch (err) { 55 this.result = `on still fail:${JSON.stringify(err)}`; 56 } 57 break 58 case 1: 59 try { 60 stationary.off('still', stationary.ActivityEvent.ENTER_EXIT, (data) => { 61 this.result = `off still success:${JSON.stringify(data)}`; 62 }) 63 this.result = ``; 64 } catch (err) { 65 this.result = `off still fail:${JSON.stringify(err)}`; 66 } 67 break 68 case 2: 69 try { 70 stationary.once('still', (data) => { 71 this.result = `once still success:${JSON.stringify(data)}`; 72 }) 73 } catch (err) { 74 this.result = `once still fail:${JSON.stringify(err)}`; 75 } 76 break 77 default: 78 break 79 } 80 } 81}