1/* 2 * Copyright (c) 2023 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 16export default class Timer { 17 private static TAG = '[Timer]:' 18 public static readonly ALIAS = 'Timer' 19 public static readonly TIMER_OFF = 'off' 20 public static readonly TIMER_TWO_SECONDS = '2' 21 public static readonly TIMER_FIVE_SECONDS = '5' 22 public static readonly TIMER_TEN_SECONDS = '10' 23 public static readonly DEFAULT_VALUE = $r('app.string.off') 24 public static readonly RESOURCE_OFF = Timer.DEFAULT_VALUE 25 public static readonly RESOURCE_TWO_SECONDS = $r('app.string.timer_2_seconds') 26 public static readonly RESOURCE_FIVE_SECONDS = $r('app.string.timer_5_seconds') 27 public static readonly RESOURCE_TEN_SECONDS = $r('app.string.timer_10_seconds') 28 public static readonly RESOURCE_OFF_ALREADY = $r('app.string.already_off') 29 30 public static convertToResource(timer: string): Resource { 31 switch (timer) { 32 case Timer.TIMER_OFF: 33 return Timer.RESOURCE_OFF 34 case Timer.TIMER_TWO_SECONDS: 35 return Timer.RESOURCE_TWO_SECONDS 36 case Timer.TIMER_FIVE_SECONDS: 37 return Timer.RESOURCE_FIVE_SECONDS 38 case Timer.TIMER_TEN_SECONDS: 39 return Timer.RESOURCE_TEN_SECONDS 40 default: 41 return Timer.RESOURCE_OFF 42 } 43 } 44 45 public static convertToString(res: Resource): string { 46 if (res.id === Timer.RESOURCE_OFF.id) { 47 return Timer.TIMER_OFF 48 } else if(res.id === Timer.RESOURCE_TWO_SECONDS.id) { 49 return Timer.TIMER_TWO_SECONDS 50 } else if(res.id === Timer.RESOURCE_FIVE_SECONDS.id) { 51 return Timer.TIMER_FIVE_SECONDS 52 } else if(res.id === Timer.RESOURCE_TEN_SECONDS.id) { 53 return Timer.TIMER_TEN_SECONDS 54 } 55 } 56}