主界面添加applist
author罗正yun <1732036298@qq.com>
Thu, 18 Jan 2024 02:22:27 +0000 (10:22 +0800)
committer罗正yun <1732036298@qq.com>
Thu, 18 Jan 2024 02:22:27 +0000 (10:22 +0800)
code/sdk/application/wearable/nativeapp/CMakeLists.txt
code/sdk/application/wearable/nativeapp/nativeui/applist/include/ApplistCardView.h [new file with mode: 0644]
code/sdk/application/wearable/nativeapp/nativeui/applist/include/ApplistPresenter.h
code/sdk/application/wearable/nativeapp/nativeui/applist/include/ApplistView.h
code/sdk/application/wearable/nativeapp/nativeui/applist/src/ApplistCardView.cpp [new file with mode: 0644]
code/sdk/application/wearable/nativeapp/nativeui/applist/src/ApplistView.cpp
code/sdk/application/wearable/nativeapp/nativeui/main/include/MainViewSample.h
code/sdk/application/wearable/nativeapp/nativeui/main/src/MainViewSample.cpp
code/sdk/application/wearable/nativeapp/nativeui/screensetting/include/ScreenModels.h

index 5bb4508..9f84f84 100755 (executable)
@@ -90,6 +90,7 @@ set(SOURCES
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/applist/src/ApplistModel.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/applist/src/ApplistPresenter.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/applist/src/ApplistView.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/applist/src/ApplistCardView.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/clock/src/MainClockView.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/bloodoxygen/src/BloodOxygenView.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/bloodoxygen/src/BloodBandoffView.cpp
diff --git a/code/sdk/application/wearable/nativeapp/nativeui/applist/include/ApplistCardView.h b/code/sdk/application/wearable/nativeapp/nativeui/applist/include/ApplistCardView.h
new file mode 100644 (file)
index 0000000..8bd6cc8
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef APP_LIST_CARD_VIEW_H
+#define APP_LIST_CARD_VIEW_H
+
+#include "components/root_view.h"
+#include "components/ui_card_page.h"
+#include "wearable_log.h"
+#include "ApplistView.h"
+
+namespace OHOS
+{
+    class ApplistCardView : public UICardPage
+    {
+    public:
+        ApplistCardView();
+        virtual ~ApplistCardView();
+        bool InitView(void);
+        void PreLoad(void) override;
+        void UnLoad(void) override;
+
+    private:
+        void ClearAll(void);
+        ApplistView *applistView{nullptr};
+        bool viewiInitStatus{false};
+    };
+}
+#endif
index fd60401..844f498 100755 (executable)
@@ -34,7 +34,10 @@ namespace OHOS {
         int GetHeadItemY(void);
         uint8_t GetListItemNum(void);
         ApplistView* GetAppListView();
-
+        ApplistModel *GetApplistModelPtr(void)
+        {
+            return model;
+        }
     private:
         ApplistModel *model{nullptr};
         KeyInputListener *keyActListenr{nullptr};
index 88be5fe..1383e00 100755 (executable)
@@ -46,11 +46,11 @@ public:
             WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AppList : Can not continue drag!!");
             return false;
         }
-        if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) &&
-            (event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) {
-            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Applist Ondrag!!");
-            NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE, TRANSITION_ZOOM);
-        }
+        // if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) &&
+        //     (event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) {
+        //     WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Applist Ondrag!!");
+        //     NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE, TRANSITION_ZOOM);
+        // }
 
         return false;
     }
@@ -66,7 +66,7 @@ private:
 };
 
 class ApplistPresenter;
-class ApplistView : public View<ApplistPresenter>, public ListScrollListener {
+class ApplistView : public View<ApplistPresenter>, public ListScrollListener ,public UIViewGroup{
 public:
     ApplistView();
     virtual ~ApplistView();
@@ -75,7 +75,9 @@ public:
     virtual void OnSetUpView() override;
     virtual void OnTearDownView() override;
     virtual void OnStop() override;
-
+    bool InitPage();
+    bool SetupViewPage(ApplistView *applistView);
+    ApplistPresenter *g_ApplistPresenter{nullptr};
     void AddAppItemToList(const AppItem &item);
     void ClearAppItemToList();
     void OnItemSelected(int16 index, UIView *view) override;
diff --git a/code/sdk/application/wearable/nativeapp/nativeui/applist/src/ApplistCardView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/applist/src/ApplistCardView.cpp
new file mode 100644 (file)
index 0000000..34d85ff
--- /dev/null
@@ -0,0 +1,68 @@
+#include "ApplistCardView.h"
+
+namespace OHOS
+{
+    ApplistCardView::ApplistCardView()
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistCardView::ApplistCardView()");
+        SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
+    }
+
+    ApplistCardView::~ApplistCardView()
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistCardView::~ApplistCardView()");
+        ClearAll();
+    }
+
+    void ApplistCardView::ClearAll(void)
+    {
+        if (viewiInitStatus == true)
+        {
+            RemoveAll();
+            if (applistView != nullptr)
+            {
+                delete applistView;
+                applistView = nullptr;
+            }
+        }
+    }
+
+    bool ApplistCardView::InitView(void)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistCardView::InitView()");
+        applistView = new ApplistView();
+        if (applistView == nullptr)
+        {
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherView::new mainweatherView fail!");
+            return false;
+        }
+        if (applistView->InitPage() == false)
+        {
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherView->InitPage() == false!");
+            return false;
+        }
+        if (applistView->SetupViewPage(applistView) == false)
+        {
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "applistView->SetupViewPage() == false!");
+            return false;
+        }
+        Add(applistView);
+        viewiInitStatus = true;
+        return true;
+    }
+
+    void ApplistCardView::PreLoad(void)
+    {
+        if (!viewiInitStatus)
+        {
+            InitView();
+            viewiInitStatus = true;
+        }
+    }
+
+    void ApplistCardView::UnLoad(void)
+    {
+    
+    }
+
+}
\ No newline at end of file
index 7dcd95d..bf1dd63 100755 (executable)
@@ -17,6 +17,7 @@ static constexpr int16 MAX_SCROLL_DIS = 1000;
 ApplistView::ApplistView()
 {
     WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::ApplistView ");
+    UIViewGroup::SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
 }
 
 ApplistView::~ApplistView()
@@ -30,6 +31,73 @@ ApplistView::~ApplistView()
     dragListener = nullptr;
 }
 
+//初始化页面
+bool ApplistView::InitPage()
+{
+    WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " ApplistView::InitPage");
+    g_ApplistPresenter = new ApplistPresenter();
+    g_ApplistPresenter->GetApplistModelPtr()->initApplist();
+    //BaseView::RootView(Color::Black().full);
+    listAdapter_ = new ApplistAdapter();
+    if (listAdapter_ == nullptr) {
+        return false;
+    }
+    listAdapter_->SetItemClickListener(g_ApplistPresenter);
+
+    contentList_ = new UIList(UIList::VERTICAL);
+    if (contentList_ == nullptr) {
+        return false;
+    }
+    contentList_->SetPosition(0, 0);
+    contentList_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
+    contentList_->SetScrollBlankSize(VERTICAL_RESOLUTION / NUM_2);
+    contentList_->SetSelectPosition(VERTICAL_RESOLUTION / NUM_2); // middle position
+    contentList_->SetDraggable(true);
+    contentList_->SetThrowDrag(true);
+    contentList_->EnableAutoAlign(true);
+    contentList_->SetScrollStateListener(this);
+    contentList_->SetMaxScrollDistance(MAX_SCROLL_DIS);
+    contentList_->SetVisible(true);
+    Add(contentList_);
+    dragListener = new AppListOnDragListener();
+    if (dragListener == nullptr) {
+        return false;
+    }
+    contentList_->SetOnDragListener(dragListener);
+    
+    return true;
+}
+
+//设置页面视图
+bool ApplistView::SetupViewPage(ApplistView *applistView)
+{
+    WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " ApplistView::SetupViewPage");
+    const AppItem *itemInfo = g_ApplistPresenter->GetApplistModelPtr()->GetApplistItems();
+    for (uint8 i = 0; i < g_ApplistPresenter->GetApplistModelPtr()->GetAppListNum(); i++) {
+            applistView->AddAppItemToList(itemInfo[i]);
+    }
+    /* -------------------------------------------------------------------------- */
+    if (contentList_ == nullptr || listAdapter_ == nullptr) {
+        return false;
+    }
+    uint16_t startIndex = 0;
+    int16_t headY = 0;
+    if (g_ApplistPresenter->GetStartIndex() >= g_ApplistPresenter->GetListItemNum()) {
+        startIndex = g_ApplistPresenter->GetListItemNum() - 1;
+        headY = VERTICAL_RESOLUTION / NUM_2;
+    } else {
+        startIndex = g_ApplistPresenter->GetStartIndex();
+        headY = g_ApplistPresenter->GetHeadItemY();
+        if (headY == 0) {
+            headY = VERTICAL_RESOLUTION / NUM_2;
+        }
+    }
+    contentList_->SetStartIndex(startIndex);
+    contentList_->SetAdapter(listAdapter_);
+    contentList_->ScrollBy(headY);
+    return true;
+}
+
 void ApplistView::OnStart()
 {
     WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::OnStart ");
index a1e044c..21689df 100755 (executable)
@@ -31,6 +31,7 @@
 #include "dial/include/Digital_clockView.h"
 #include "blood/include/BloodView.h"
 #include "traing/include/TraingView.h"
+#include "ApplistCardView.h"
 namespace OHOS
 {
     class MainPresenterSample;
@@ -52,7 +53,7 @@ namespace OHOS
         UICardPage *InitBloodOxygenPage(void);
         UICardPage *InitWeatherPage(void);
         UICardPage *InitTrainingPage(void);
-
+        UICardPage *InitApplistPage(void);
         void AnimatorStart(int pageIndex);
         void AnimatorStop(void);
         uint16_t GetHorCurrentPage() const
@@ -83,7 +84,7 @@ namespace OHOS
         Digital_clockView *dialView{nullptr};
         BloodView *bloodView{nullptr};
         TraingView *traingView{nullptr};
-
+        ApplistCardView *applistCardView{nullptr};
         /* -------------------------------------------------------------------------- */
         UICardPage *recordCard[MAX_CARD]{nullptr};
         bool pageStatus[MAX_CARD]{false};
index 302608a..bcd2c56 100755 (executable)
@@ -31,6 +31,7 @@ namespace OHOS
         {COMPASS, &MainViewSample::InitCompassPage},
         {BloodOxygen, &MainViewSample::InitBloodOxygenPage},
         {TRAINING, &MainViewSample::InitTrainingPage},
+        {APPLIST,&MainViewSample::InitApplistPage}
     };
 
     MainViewSample::MainViewSample()
@@ -114,6 +115,16 @@ namespace OHOS
         {
             delete bloodView;
             bloodView = nullptr;
+        }
+         if(traingView != nullptr)
+        {
+            delete traingView;
+            traingView = nullptr;
+        }
+        if(applistCardView != nullptr)
+        {
+            delete applistCardView;
+            applistCardView = nullptr;
         }
         g_pMainView = nullptr;
     }
@@ -341,6 +352,18 @@ namespace OHOS
         return traingView;
     }
 
+    //主界面功能列表界面
+    UICardPage *MainViewSample::InitApplistPage(void)
+    {
+        applistCardView = new ApplistCardView();
+        if(applistCardView == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "applistCardView new fail");
+            return nullptr;
+        }
+        return applistCardView;
+    }
+
     UICardPage *MainViewSample::CreatePage(int32_t StreamId)
     {
         uint16_t i;