1 /* 2 * Copyright (c) 2020 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 #ifndef OHOS_SWIPE_VIEW_H 17 #define OHOS_SWIPE_VIEW_H 18 19 #include <cstdio> 20 #include <securec.h> 21 #include <components/ui_label_button.h> 22 #include <components/ui_label.h> 23 #include <components/ui_view_group.h> 24 #include <components/ui_swipe_view.h> 25 #include <components/root_view.h> 26 #include <common/task.h> 27 28 #include "ui_config.h" 29 #include "app_info.h" 30 #include "view_group_page.h" 31 #include "native_base.h" 32 #include "long_press_view.h" 33 #include "app_manage.h" 34 #include "time_weather_view.h" 35 36 namespace OHOS { 37 class ViewPageListener : public UIView::OnClickListener { 38 public: ViewPageListener(LongPressView * view)39 explicit ViewPageListener(LongPressView* view) : view_(view) {} ~ViewPageListener()40 virtual ~ViewPageListener() {} OnClick(UIView & view,const ClickEvent & event)41 bool OnClick(UIView& view, const ClickEvent& event) override 42 { 43 view_->RemoveLview(); 44 return true; 45 } 46 47 private: 48 LongPressView *view_ { nullptr }; 49 }; 50 51 class SwipeListener : public UISwipeView::OnSwipeListener { 52 public: SwipeListener(LongPressView * view,UISwipeView * swipe,UILabel * label)53 SwipeListener(LongPressView* view, UISwipeView* swipe, UILabel* label) 54 : view_(view), swipe_(swipe), label_(label) {}; ~SwipeListener()55 ~SwipeListener() {}; OnSwipe(UISwipeView & view)56 virtual void OnSwipe(UISwipeView& view) override 57 { 58 char buf[TMP_BUF_SIZE] = { 0 }; 59 sprintf_s(buf, sizeof(buf), ".%d.", swipe_->GetCurrentPage() + 1); 60 label_->SetText(buf); 61 view_->RemoveLview(); 62 } 63 64 private: 65 LongPressView* view_ { nullptr }; 66 UISwipeView* swipe_ { nullptr }; 67 UILabel* label_ { nullptr }; 68 }; 69 70 class SwipeView : public Task, public NativeBase { 71 public: 72 SwipeView() = delete; 73 SwipeView(UILabel* titlellabel, UILabel* taillabel); 74 virtual ~SwipeView(); 75 void OnSetUpView(); 76 void StartApp(AppInfo* app); 77 void ShowLongPressView(AppInfo* app); 78 void UninstallApp(AppInfo* app); 79 void InstallApp(AppInfo* app); Callback()80 void Callback() override 81 { 82 char tmp[TMP_BUF_SIZE] = { 0 }; 83 time_t t = time(nullptr); 84 struct tm* st = localtime(&t); 85 if (st != nullptr) { 86 int ret = sprintf_s(tmp, sizeof(tmp), "%02d : %02d", st->tm_hour, st->tm_min); 87 if (ret != LAUNCHER_PARAMERROR) { 88 labelTitle_->SetText(tmp); 89 timeWeatherView_->SetUpTimeView(); 90 } 91 } 92 } 93 GetSwipeView()94 UISwipeView* GetSwipeView() const 95 { 96 return swipe_; 97 } 98 99 private: 100 void OnStop(); 101 void SetUpSwipe(); 102 UIViewGroup* AddViewGroup(); 103 UIViewGroup* AddFirstViewGroup(); 104 ViewGroupPage* arrPage_[MAX_VIEWGROUP] { nullptr }; 105 UISwipeView* swipe_ { nullptr }; 106 UILabel* labelTitle_ { nullptr }; // view title time label 107 UILabel* labelTail_ { nullptr }; 108 int groupCount_ { 0 }; 109 ViewPageListener* arrViewListener_ { nullptr }; 110 SwipeListener* swipeListener_ { nullptr }; 111 AppManage* appManage_ { nullptr }; 112 LongPressView* lpView_ { nullptr }; 113 TimeWeatherView* timeWeatherView_ {nullptr}; 114 }; 115 116 class AppEvent { 117 public: GetInstance(SwipeView * nativeView)118 static AppEvent* GetInstance(SwipeView* nativeView) 119 { 120 if (appEvent_ == nullptr) { 121 appEvent_ = new AppEvent(); 122 nativeView_ = nativeView; 123 } 124 return appEvent_; 125 } 126 // app click 127 ClickEvent(AppInfo * app)128 static bool ClickEvent(AppInfo* app) 129 { 130 nativeView_->StartApp(app); 131 return true; 132 } 133 // app long press show window 134 LongPressEvent(AppInfo * app)135 static bool LongPressEvent(AppInfo* app) 136 { 137 nativeView_->ShowLongPressView(app); 138 return true; 139 } 140 // app uninstall click 141 UninstallApp(AppInfo * app)142 static bool UninstallApp(AppInfo* app) 143 { 144 nativeView_->UninstallApp(app); 145 return true; 146 } 147 // none install app used appmanage::InstallApp, this function is invalid 148 InstallApp(AppInfo * app)149 static bool InstallApp(AppInfo* app) 150 { 151 nativeView_->InstallApp(app); 152 return true; 153 } 154 155 private: AppEvent()156 AppEvent() {} ~AppEvent()157 ~AppEvent() 158 { 159 if (appEvent_) { 160 delete appEvent_; 161 appEvent_ = nullptr; 162 } 163 } 164 165 private: 166 static AppEvent* appEvent_; 167 static SwipeView* nativeView_; 168 }; 169 } // namespace OHOS 170 #endif