1 /* 2 * Copyright (c) 2021 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 16 #include "ability_touchevent.h" 17 #include "ability_impl.h" 18 #include "app_log_wrapper.h" 19 #include "ability_post_event_timeout.h" 20 21 namespace OHOS { 22 namespace AppExecFwk { AbilityTouchEventHandle(std::shared_ptr<AbilityImpl> abilityImpl)23AbilityTouchEventHandle::AbilityTouchEventHandle(std::shared_ptr<AbilityImpl> abilityImpl) : abilityImpl_(abilityImpl) 24 { 25 APP_LOGI("AbilityTouchEventHandle is created"); 26 } 27 ~AbilityTouchEventHandle()28AbilityTouchEventHandle::~AbilityTouchEventHandle() 29 { 30 APP_LOGI("AbilityTouchEventHandle is destroyed"); 31 } 32 33 #ifdef MMI_COMPILE 34 /** 35 * @brief Called back when on touch. 36 */ OnTouch(const TouchEvent & touchEvent)37bool AbilityTouchEventHandle::OnTouch(const TouchEvent &touchEvent) 38 { 39 APP_LOGI("AbilityTouchEventHandle::OnTouch called."); 40 bool ret = false; 41 if (abilityImpl_ == nullptr) { 42 APP_LOGE("AbilityTouchEventHandle::OnTouch abilityImpl_ is nullptr"); 43 return ret; 44 } 45 46 std::string taskHead("OnTouch"); 47 std::string taskCodeAction = std::to_string(touchEvent.GetAction()); 48 std::string taskCodePhase = std::to_string(touchEvent.GetPhase()); 49 std::string taskSplit("-"); 50 auto timeOut = 51 abilityImpl_->CreatePostEventTimeouter(taskHead + taskCodeAction + taskSplit + taskCodePhase + taskSplit); 52 if (timeOut == nullptr) { 53 APP_LOGW("AbilityTouchEventHandle::OnTouch timeouter Create return nullptr"); 54 ret = abilityImpl_->DoTouchEvent(touchEvent); 55 } else { 56 timeOut->TimingBegin(); 57 ret = abilityImpl_->DoTouchEvent(touchEvent); 58 timeOut->TimeEnd(); 59 } 60 61 APP_LOGI("AbilityImpl::DoTouchEvent action: %{public}d phase: %{public}d.", 62 touchEvent.GetAction(), 63 touchEvent.GetPhase()); 64 return ret; 65 } 66 #endif 67 } // namespace AppExecFwk 68 } // namespace OHOS