修改上拉列表的效果,后续还要优化
authorCaisking <3449750381@qq.com>
Wed, 13 Mar 2024 10:33:35 +0000 (18:33 +0800)
committerCaisking <3449750381@qq.com>
Wed, 13 Mar 2024 10:33:35 +0000 (18:33 +0800)
code/sdk/application/wearable/fd230app/nativeui/dialupdate/src/DialUpdateModel.cpp
code/sdk/application/wearable/fd230app/nativeui/dialupdate/src/DialUpdateView.cpp
code/sdk/application/wearable/fd230app/nativeui/key/src/KeyInputListener.cpp
code/sdk/application/wearable/fd230app/nativeui/main/src/MainViewSample.cpp
code/sdk/application/wearable/fd230app/nativeui/message/src/MessageCardView.cpp
code/sdk/application/wearable/fd230app/nativeui/message/src/MessagePresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/message/src/MessageView.cpp

index 1dd9544..958592f 100644 (file)
@@ -17,7 +17,7 @@
 #include "ui_resource_image.h"
 #include "common/image_cache_manager.h"
 
-#define  DIAL_DIR "user/res/dials"
+#define DIAL_DIR "user/res/dials"
 
 // 表盘名称||表盘缩约图||表盘路径
 DialInfo_1 dialInfo_1[MAX_DIALNUM_1];
@@ -32,78 +32,71 @@ void read_dial(void)
 {
     DIR *dirp = opendir(DIAL_DIR);
     // 遍历文件
-    dial_num=0;
-    if (dirp != NULL) 
+    dial_num = 0;
+    if (dirp != NULL)
     {
-        while (dirent * ret=readdir(dirp))
+        while (dirent *ret = readdir(dirp))
         {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"file_name %s \r\n",ret->d_name);
-            if(dialInfo_1[dial_num].dialPath)
+            //WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE, "file_name %s \r\n", ret->d_name);
+            if (dialInfo_1[dial_num].dialPath)
             {
-                free((void*)dialInfo_1[dial_num].dialPath);
-                dialInfo_1[dial_num].dialPath=NULL;
+                free((void *)dialInfo_1[dial_num].dialPath);
+                dialInfo_1[dial_num].dialPath = NULL;
             }
-            char path[124]={0};
+            char path[124] = {0};
 
-            sprintf(path,"user/res/dials/%s",ret->d_name);
-            char * str_1=(char*) malloc(sizeof(path));
-            strcpy(str_1,path);
-            dialInfo_1[dial_num].dialPath=str_1;
+            sprintf(path, "user/res/dials/%s", ret->d_name);
+            char *str_1 = (char *)malloc(sizeof(path));
+            strcpy(str_1, path);
+            dialInfo_1[dial_num].dialPath = str_1;
 
-            if(dialInfo_1[dial_num].thumbnailPath)
+            if (dialInfo_1[dial_num].thumbnailPath)
             {
-                free((void*)dialInfo_1[dial_num].thumbnailPath);
-                dialInfo_1[dial_num].thumbnailPath=NULL;
+                free((void *)dialInfo_1[dial_num].thumbnailPath);
+                dialInfo_1[dial_num].thumbnailPath = NULL;
             }
-            char path_1[124]={0};
-            sprintf(path_1,"user/res/dialupdate/%s",ret->d_name);
-            str_1=(char*) malloc(sizeof(path_1));
-            strcpy(str_1,path_1);
-            dialInfo_1[dial_num].thumbnailPath=str_1;
+            char path_1[124] = {0};
+            sprintf(path_1, "user/res/dialupdate/%s", ret->d_name);
+            str_1 = (char *)malloc(sizeof(path_1));
+            strcpy(str_1, path_1);
+            dialInfo_1[dial_num].thumbnailPath = str_1;
 
-            if(dialInfo_1[dial_num].title)
+            if (dialInfo_1[dial_num].title)
             {
-                free((void*)dialInfo_1[dial_num].title);
-                dialInfo_1[dial_num].title=NULL;
+                free((void *)dialInfo_1[dial_num].title);
+                dialInfo_1[dial_num].title = NULL;
             }
-            FILE * fp = fopen(path, "rb");
-            if (fp == nullptr) 
+            FILE *fp = fopen(path, "rb");
+            if (fp == nullptr)
             {
                 return;
             }
-            OHOS::DialHeader* data = static_cast<OHOS::DialHeader*>
-            (OHOS::DialBinParser::GetInstance()->MallocAndReadBuf(fp, sizeof(OHOS::DialHeader)));
-            
-            char * str_2=(char*) malloc(sizeof(data->dialName));
-            strcpy(str_2,data->dialName);
-            dialInfo_1->imageOffset=data->imageOffset;
-            dialInfo_1[dial_num++].title=str_2;
+            OHOS::DialHeader *data = static_cast<OHOS::DialHeader *>(OHOS::DialBinParser::GetInstance()->MallocAndReadBuf(fp, sizeof(OHOS::DialHeader)));
 
+            char *str_2 = (char *)malloc(sizeof(data->dialName));
+            strcpy(str_2, data->dialName);
+            dialInfo_1->imageOffset = data->imageOffset;
+            dialInfo_1[dial_num++].title = str_2;
 
-
-
-
-            
             fclose(fp);
             UIFree(data);
         }
     }
-     
+
     // 关闭目录
     closedir(dirp);
 }
 
 void printf_dial(void)
 {
-    for(int i=0;i<dial_num;i++)
+    for (int i = 0; i < dial_num; i++)
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"file_name %s \r\n", dialInfo_1[i].dialPath);
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"file_title %s \r\n", dialInfo_1[i].title);
-       
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE, "file_name %s \r\n", dialInfo_1[i].dialPath);
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE, "file_title %s \r\n", dialInfo_1[i].title);
     }
-     WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"num %d \r\n",dial_num );
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE, "num %d \r\n", dial_num);
 }
-    //{"默认表盘", "user/res/dialupdate/defult_dial.bin", "user/res/dials/defult_dial.bin"}
+//{"默认表盘", "user/res/dialupdate/defult_dial.bin", "user/res/dials/defult_dial.bin"}
 namespace OHOS
 {
     DialUpdateModel::DialUpdateModel() {}
@@ -123,7 +116,7 @@ namespace OHOS
     uint8_t DialUpdateModel::GetDialConfigPath()
     {
         read_dial();
-        printf_dial();
+        // printf_dial();
         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetDialConfigPath:%d", Current_dial);
         return Current_dial;
     }
index e73b277..08a57d7 100644 (file)
@@ -38,13 +38,13 @@ namespace OHOS
             delete container_;
             container_ = nullptr;
         }
-        
-        for(int i=0;i<dial_num;i++)
+
+        for (int i = 0; i < dial_num; i++)
         {
-            if(Button[i]!=NULL)
+            if (Button[i] != NULL)
             {
                 delete Button[i];
-                Button[i]=NULL;
+                Button[i] = NULL;
             }
         }
         g_pDialUpdateView = nullptr;
@@ -194,11 +194,10 @@ namespace OHOS
         // button2_->SetVisible(true);
     }
 
-   
     void DialUpdateView::init_button()
     {
         // read_dial();
-        printf_dial(); // dial_num
+        // printf_dial(); // dial_num
         uint8_t fileid = DialUpdateModel::GetInstance()->GetDialConfigPath();
         for (int i = fileid; i < dial_num + fileid; i++)
         {
index 6cfd5a9..a3cb9d0 100644 (file)
@@ -159,7 +159,6 @@ namespace OHOS
                         if (!MainViewSample::GetInstance()->IsMainClockPage()) // 当前页面为主表盘的其他页面时,切换回主表盘页面
                         {
                             MainViewSample::GetInstance()->SwitchToClockPage();
-                            RootView::GetInstance()->Invalidate(); // 刷新界面
                         }
                         else
                         {
index 98bdb09..eb9bfdc 100644 (file)
@@ -177,7 +177,7 @@ namespace OHOS
         VerticalViewInit();
         VertViewLoad();
         mainSwipeGroup->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
-        mainSwipeGroup->SetAnimatorTime(50); // 50: animator drag time(ms);
+        mainSwipeGroup->SetAnimatorTime(10); // 50: animator drag time(ms);
         mainSwipeGroup->SetLoopState(true);
         mainSwipeGroup->EnableScreenCap(true); // 屏幕截图展示,取消使用实时绘制
         mainSwipeGroup->RegisterSwipeCallback(callback);
@@ -256,10 +256,10 @@ namespace OHOS
 
         messageView->SetViewId("messageView");
         messageView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
-        messageView->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT);
         messageView->PreLoad();
         messageView->SetDraggable(false);
         messageView->SetIntercept(true);
+        messageView->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT);
 #endif
 /* -------------------------------------------------------------------------- */
 #if 0
@@ -340,7 +340,7 @@ namespace OHOS
         }
 #endif
         // DialUpdateModel::GetInstance()->LoadDialConfigFromJson();
-        //read_dial();
+        // read_dial();
         uint8_t fileid = DialUpdateModel::GetInstance()->GetDialConfigPath();
         std::string filePath = dialInfo_1[fileid].dialPath;
         mainClockView->SetDial(filePath);
@@ -374,8 +374,8 @@ namespace OHOS
         UIView::OnLongPressListener *buttonLongPress = static_cast<UIView::OnLongPressListener *>(MainPresenterSample::GetInstance());
         mainClockView->SetOnLongPressListener(buttonLongPress);
         // Add to rootView
-        //mainClockView->Add(changebut);
-        //changebut->SetVisible(true);
+        // mainClockView->Add(changebut);
+        // changebut->SetVisible(true);
 #endif
         return mainClockView;
     }
index 856346e..5d1355d 100644 (file)
@@ -48,6 +48,7 @@ namespace OHOS
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MessageView->SetupViewPage() == false!");
             return false;
         }
+        messageview->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT);
         Add(messageview);
         messageview->GetList()->RefreshList(); // 刷新列表
         return true;
index 581d7b9..fe41259 100644 (file)
@@ -60,12 +60,13 @@ namespace OHOS
 
     bool MessagePresenter::OnDrag(UIView &view, const DragEvent &event)
     {
-
+#if 0
         if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT &&
             (event.GetDeltaX() > 20) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY()))))
         {
             NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST);
         }
+#endif
         return true;
     }
 
@@ -74,7 +75,7 @@ namespace OHOS
         UNUSED(event);
         MessageItemView *messageItemView = static_cast<MessageItemView *>(&view);
         int index = messageItemView->GetMessageListIndex();
-        printf("%d\n",index);//测试点击是否有效
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "index:%d", index);
         if (index >= p_MessageModel->GetMessageListNum())
         {
             WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingPresenter::OnClick is no index");
index 62b6a8f..f34673f 100644 (file)
@@ -7,12 +7,12 @@
 
 namespace OHOS
 {
-
+    static constexpr uint8_t NUM_2 = 2;
     static MessageView *g_pMessageView{nullptr};
 
     MessageView::MessageView()
     {
-        UIViewGroup::SetPosition(43, 120, 466, 466);
+        UIViewGroup::SetPosition(42, 120, 380, 960);
         g_pMessageView = this;
     }
 
@@ -36,28 +36,16 @@ namespace OHOS
         {
             scrollView = new UIScrollView();
         }
-        scrollView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
-        scrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
-        scrollView->SetScrollBlankSize(20);
+        scrollView->SetPosition(0, 0, 380, 466);
+        // scrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
+        scrollView->SetScrollBlankSize(35);
         scrollView->SetReboundSize(50);
         scrollView->SetTouchable(true);
         scrollView->SetDraggable(true);
+        scrollView->SetDirection(1);
         draglistener = static_cast<UIView::OnDragListener *>(MessagePresenter::GetInstance());
         scrollView->SetOnDragListener(draglistener);
         /* -------------------------------------------------------------------------- */
-        if (title == nullptr)
-        {
-            title = new UILabel();
-        }
-        title->SetPosition(173, 52, 120, 35);
-        title->Resize(120, 35);
-        title->SetStyle(STYLE_TEXT_FONT, 30);
-        title->SetStyle(STYLE_LINE_HEIGHT, 36);
-        title->SetText("信息通知");
-        title->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS);
-        title->SetStyle(STYLE_TEXT_COLOR, Color::White().full);
-        title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
-        /* -------------------------------------------------------------------------- */
         // UIList 的适配器
         p_MessageListAdapter = new MessageListAdapter();
         p_MessageListAdapter->SetItemClickListener(presenter_);
@@ -66,7 +54,7 @@ namespace OHOS
             MessageList = new UIList();
         }
         MessageList->SetPosition(43, 120, 380, 600);
-        MessageList->SetStyle(STYLE_BACKGROUND_COLOR, 0x00000000);
+        MessageList->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT);
     }
 
     void MessageView::DeInitView()
@@ -112,12 +100,12 @@ namespace OHOS
     void MessageView::OnSetUpView()
     {
         View<MessagePresenter>::OnSetUpView();
-        scrollView->Add(title);
+        // scrollView->Add(title);
         scrollView->Add(MessageList);
-        scrollView->SetBackgroundBlur(10000);
+        scrollView->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT);
         RootView::GetInstance()->Add(scrollView);
         MessageList->SetAdapter(p_MessageListAdapter);
-        MessageList->RefreshList(); // 刷新列表
+        // MessageList->RefreshList(); // 刷新列表
         Draw();
     }
 
@@ -146,16 +134,21 @@ namespace OHOS
         {
             MessageList = new UIList();
         }
-        MessageList->SetPosition(0, 0, 380, 600);
-        MessageList->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000);
-        MessageList->SetScrollBlankSize(10);
-        MessageList->EnableAutoAlign(true);
-        MessageList->RefreshList(); // 刷新列表
+        MessageList->SetPosition(0, 0);
+        MessageList->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
         MessageList->SetDraggable(true);
-        MessageList->SetThrowDrag(false);
-        MessageList->SetLoopState(true);
-
-        // MessageList->SetYScrollBarVisible(true);
+        MessageList->SetThrowDrag(true);
+        MessageList->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT);
+        //MessageList->SetOpaScale(100);
+
+        MessageList->SetScrollBlankSize(100);
+        MessageList->SetReboundSize(50);
+        MessageList->SetSelectPosition(HORIZONTAL_RESOLUTION / 2); // middle position
+        MessageList->SetDirection(1);
+        UIView::OnClickListener *list1Click = static_cast<UIView::OnClickListener *>(MessagePresenter::GetInstance());
+        MessageList->SetOnClickListener(list1Click);
+        UIView::OnDragListener *list1Drag = static_cast<UIView::OnDragListener *>(MessagePresenter::GetInstance());
+        MessageList->SetOnDragListener(list1Drag);
         Add(MessageList);
         MessageList->SetAdapter(p_MessageListAdapter);
         MessageList->SetVisible(true);