• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 StartApp(AppInfo* app);
79     void ShowLongPressView(AppInfo* app);
80     void UninstallApp(AppInfo* app);
81     void InstallApp(AppInfo* app);
Callback()82     void Callback() override
83     {
84         time_t t = time(nullptr);
85         struct tm* st = localtime(&t);
86         if (st != nullptr) {
87             char tmp[TMP_BUF_SIZE] = {0};
88             int ret = sprintf_s(tmp, sizeof(tmp), "%02d : %02d", st->tm_hour, st->tm_min);
89             if (ret != LAUNCHER_PARAMERROR) {
90                 lableTitle_->SetText(tmp);
91                 timeWeatherView_->SetUpTimeView();
92             }
93         }
94     }
95 
GetSwipeView()96     UISwipeView* GetSwipeView() const
97     {
98         return swipe_;
99     }
100 
101 private:
102     void OnStop();
103     void SetUpSwipe();
104     UIViewGroup* AddViewGroup();
105     UIViewGroup* AddFirstViewGroup();
106     ViewGroupPage* arrPage_[MAX_VIEWGROUP] { nullptr };
107     UISwipeView* swipe_ { nullptr };
108     UILabel* lableTitle_ { nullptr }; // view title time label
109     UILabel* lableTail_ { nullptr };
110     int groupCount_ { 0 };
111     ViewPageListener* arrViewListener_ { nullptr };
112     SwipeLisstener* swipeLisstener_ { nullptr };
113     AppManage* appManage_ { nullptr };
114     LongPressView* lpView_ { nullptr };
115     TimeWeatherView* timeWeatherView_ {nullptr};
116 };
117 
118 class AppEvent {
119 public:
GetInstance(SwipeView * nativeView)120     static AppEvent* GetInstance(SwipeView* nativeView)
121     {
122         if (appEvent_ == nullptr) {
123             appEvent_ = new AppEvent();
124             nativeView_ = nativeView;
125         }
126         return appEvent_;
127     }
128     // app click
129 
ClickEvent(AppInfo * app)130     static bool ClickEvent(AppInfo* app)
131     {
132         nativeView_->StartApp(app);
133         return true;
134     }
135     // app long press show window
136 
LongPressEvent(AppInfo * app)137     static bool LongPressEvent(AppInfo* app)
138     {
139         nativeView_->ShowLongPressView(app);
140         return true;
141     }
142     // app uninstall click
143 
UninstallApp(AppInfo * app)144     static bool UninstallApp(AppInfo* app)
145     {
146         nativeView_->UninstallApp(app);
147         return true;
148     }
149     // none install app used appmanage::InstallApp, this function is invailate
150 
InstallApp(AppInfo * app)151     static bool InstallApp(AppInfo* app)
152     {
153         nativeView_->InstallApp(app);
154         return true;
155     }
156 
157 private:
AppEvent()158     AppEvent() {}
~AppEvent()159     ~AppEvent()
160     {
161         if (appEvent_) {
162             delete appEvent_;
163             appEvent_ = nullptr;
164         }
165     }
166 
167 private:
168     static AppEvent* appEvent_;
169     static SwipeView* nativeView_;
170 };
171 } // namespace OHOS
172 #endif