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 16 #include <iostream> 17 #include <refbase.h> 18 #include <unistd.h> 19 20 #include "window.h" 21 #include "wm_common.h" 22 #include "window_option.h" 23 #include "window_manager.h" 24 25 #include "future.h" 26 27 namespace OHOS { 28 namespace Rosen { 29 class WaterMarkFlagChangedListenerFuture : public IWaterMarkFlagChangedListener { 30 public: OnWaterMarkFlagUpdate(bool showWaterMark)31 void OnWaterMarkFlagUpdate(bool showWaterMark) override 32 { 33 future_.SetValue(showWaterMark); 34 }; 35 RunnableFuture<bool> future_; 36 static constexpr long WAIT_TIME = 20000; 37 }; 38 } 39 } 40 41 using namespace OHOS; 42 using namespace OHOS::Rosen; 43 main(int argc,char * argv[])44int main(int argc, char* argv[]) 45 { 46 std::cout << "===========================Start===========================" << std::endl; 47 48 std::cout << "RegisterWaterMarkFlagChangedListener" << std::endl; 49 sptr<WaterMarkFlagChangedListenerFuture> listener = new WaterMarkFlagChangedListenerFuture(); 50 if (listener == nullptr) { 51 return 0; 52 } 53 WindowManager::GetInstance().RegisterWaterMarkFlagChangedListener(listener); 54 55 std::cout << "You can open a window with water mark flag in during 20s" << std::endl; 56 auto result = listener->future_.GetResult(WaterMarkFlagChangedListenerFuture::WAIT_TIME); 57 std::cout << "callback result = " << result << std::endl; 58 59 listener->future_.Reset(result); 60 std::cout << "You can close the window, hide it, or change the flag in during 20s" << std::endl; 61 result = listener->future_.GetResult(WaterMarkFlagChangedListenerFuture::WAIT_TIME); 62 std::cout << "callback result = " << result << std::endl; 63 64 WindowManager::GetInstance().UnregisterWaterMarkFlagChangedListener(listener); 65 std::cout << "============================End============================" << std::endl; 66 return 0; 67 }