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 SwipeLisstener : public UISwipeView::OnSwipeListener { 52 public: SwipeLisstener(LongPressView * view,UISwipeView * swipe,UILabel * lable)53 SwipeLisstener(LongPressView* view, UISwipeView* swipe, UILabel* lable) 54 : view_(view), swipe_(swipe), lable_(lable) {}; ~SwipeLisstener()55 ~SwipeLisstener() {}; OnSwipe(UISwipeView & view)56 virtual void OnSwipe(UISwipeView& view) override 57 { 58 char buf[TMP_BUF_SIZE] = { 0 }; 59 if (sprintf_s(buf, sizeof(buf), ".%d.", swipe_->GetCurrentPage() + 1) < 0) { 60 return; 61 } 62 lable_->SetText(buf); 63 view_->RemoveLview(); 64 } 65 66 private: 67 LongPressView* view_ { nullptr }; 68 UISwipeView* swipe_ { nullptr }; 69 UILabel* lable_ { nullptr }; 70 }; 71 72 class SwipeView : public Task, public NativeBase { 73 public: 74 SwipeView() = delete; 75 SwipeView(UILabel* titlellable, UILabel* taillable); 76 virtual ~SwipeView(); 77 void OnSetUpView(); 78 void BundleInfoScan(BundleInfo* pBundleInfos, int count); 79 void StartApp(AppInfo* app); 80 void ShowLongPressView(AppInfo* app); 81 void UninstallApp(AppInfo* app); 82 void InstallApp(AppInfo* app); Callback()83 void Callback() override 84 { 85 time_t t = time(nullptr); 86 struct tm* st = localtime(&t); 87 if (st != nullptr) { 88 char tmp[TMP_BUF_SIZE] = {0}; 89 int ret = sprintf_s(tmp, sizeof(tmp), "%02d : %02d", st->tm_hour, st->tm_min); 90 if (ret != LAUNCHER_PARAMERROR) { 91 lableTitle_->SetText(tmp); 92 timeWeatherView_->SetUpTimeView(); 93 } 94 } 95 } 96 GetSwipeView()97 UISwipeView* GetSwipeView() const 98 { 99 return swipe_; 100 } 101 102 private: 103 void OnStop(); 104 void SetUpSwipe(); 105 UIViewGroup* AddViewGroup(); 106 UIViewGroup* AddFirstViewGroup(); 107 ViewGroupPage* arrPage_[MAX_VIEWGROUP] { nullptr }; 108 UISwipeView* swipe_ { nullptr }; 109 UILabel* lableTitle_ { nullptr }; // view title time label 110 UILabel* lableTail_ { nullptr }; 111 int groupCount_ { 0 }; 112 ViewPageListener* arrViewListener_ { nullptr }; 113 SwipeLisstener* swipeLisstener_ { nullptr }; 114 AppManage* appManage_ { nullptr }; 115 LongPressView* lpView_ { nullptr }; 116 TimeWeatherView* timeWeatherView_ {nullptr}; 117 }; 118 119 class AppEvent { 120 public: GetInstance(SwipeView * nativeView)121 static AppEvent* GetInstance(SwipeView* nativeView) 122 { 123 if (appEvent_ == nullptr) { 124 appEvent_ = new AppEvent(); 125 nativeView_ = nativeView; 126 } 127 return appEvent_; 128 } 129 // app click 130 ClickEvent(AppInfo * app)131 static bool ClickEvent(AppInfo* app) 132 { 133 nativeView_->StartApp(app); 134 return true; 135 } 136 // app long press show window 137 LongPressEvent(AppInfo * app)138 static bool LongPressEvent(AppInfo* app) 139 { 140 nativeView_->ShowLongPressView(app); 141 return true; 142 } 143 // app uninstall click 144 UninstallApp(AppInfo * app)145 static bool UninstallApp(AppInfo* app) 146 { 147 nativeView_->UninstallApp(app); 148 return true; 149 } 150 // none install app used appmanage::InstallApp, this function is invailate 151 InstallApp(AppInfo * app)152 static bool InstallApp(AppInfo* app) 153 { 154 nativeView_->InstallApp(app); 155 return true; 156 } 157 158 private: AppEvent()159 AppEvent() {} ~AppEvent()160 ~AppEvent() 161 { 162 if (appEvent_) { 163 delete appEvent_; 164 appEvent_ = nullptr; 165 } 166 } 167 168 private: 169 static AppEvent* appEvent_; 170 static SwipeView* nativeView_; 171 }; 172 } // namespace OHOS 173 #endif