弧形applist 672/1
authorcheng <chengyf@zhihuishixun.com>
Sat, 10 Aug 2024 07:20:39 +0000 (15:20 +0800)
committercheng <chengyf@zhihuishixun.com>
Sat, 10 Aug 2024 07:20:39 +0000 (15:20 +0800)
code/sdk/application/wearable/fd230app/nativeui/applist/include/AppItemView.h
code/sdk/application/wearable/fd230app/nativeui/applist/include/ApplistAdapter.h
code/sdk/application/wearable/fd230app/nativeui/applist/include/ApplistView.h
code/sdk/application/wearable/fd230app/nativeui/applist/src/AppItemView.cpp
code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistAdapter.cpp
code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistView.cpp
code/sdk/application/wearable/fd230app/nativeui/themestyle/include/ThemeStyleModel.h

index 1c644c7..dc37cc2 100644 (file)
@@ -16,6 +16,7 @@
 #include "components/ui_image_view.h"
 #include "ApplistModel.h"
 #include "UiConfig.h"
+#include "components/ui_transform_group.h"
 
 namespace OHOS {
 class AppItemView : public UIViewGroup {
@@ -64,6 +65,26 @@ private:
     FootballItemView &operator = (const FootballItemView &);
     AppItem itemInfo_ = { VIEW_INVALID, nullptr, nullptr, nullptr,nullptr, STR_EXERCISE_GENERAL,nullptr };
 };
+
+class ArcScaleListItemView : public UITransformGroup
+{
+public:
+    ArcScaleListItemView();
+    ~ArcScaleListItemView();
+
+    void SetItemInfo(const AppItem &itemInfo);
+    AppViewId GetViewId();
+    const char * GetAppUid();
+
+    ArcScaleListItemView(const ArcScaleListItemView &) = delete;
+    ArcScaleListItemView &operator=(const ArcScaleListItemView &) = delete;
+
+private:
+    UIImageView * image_{nullptr};
+    UILabelExt * label_{nullptr};
+    AppItem itemInfo_ = { VIEW_INVALID, nullptr, nullptr, nullptr, nullptr, STR_EXERCISE_GENERAL, nullptr };
+};
+
 }
 
 #endif
index 46a42aa..81eaf54 100644 (file)
@@ -51,5 +51,27 @@ private:
     std::list<AppItem> listData_;
     UIView::OnClickListener *itemClickListener_;
 };
+
+
+class ArcScaleListItemAdapter : public AbstractAdapter 
+{
+public:
+    ArcScaleListItemAdapter();
+    ~ArcScaleListItemAdapter() override;
+
+    UIView* GetView(UIView* inView, int16_t index) override;
+    uint16_t GetCount() override;
+    void AddListItem(const AppItem &item);
+
+    void SetItemClickListener(UIView::OnClickListener *itemClickListener)
+    {
+        itemClickListener_ = itemClickListener;
+    }
+
+private:
+    List<AppItem> nodeList_;
+    UIView::OnClickListener * itemClickListener_;
+};
+
 }
 #endif
\ No newline at end of file
index b5a2388..79c6130 100644 (file)
@@ -20,6 +20,8 @@
 #include "drag_event.h"
 #include "UiConfig.h"
 #include "components/ui_label_ext.h"
+#include "components/ui_transform_list.h"
+
 namespace OHOS {
 class AppListOnDragListener : public UIView::OnDragListener {
 public:
@@ -142,6 +144,15 @@ private:
     ImageInfo* footballDefaultImg_ = nullptr;
     FootballAnimatorCallback* callback_ = nullptr;
     Animator* enterAnimator_ = nullptr;
+
+    // arc scale list
+    void ArcScaleListStyleOnStart(void);
+    void ArcScaleListStyleOnSetUpView(void);
+    void ArcScaleListStyleOnStop(void);
+    UIViewGroup * ArcScaleListGroup_{nullptr};
+    UITransformList * ArcScaleList_{nullptr};
+    ArcScaleListItemAdapter * ArcScaleListAdapter_{nullptr};
+    UIView::OnDragListener * ArcScaleListDragListener_{nullptr};
 };
 }
 #endif // APPLIST_VIEW_H
\ No newline at end of file
index e329bb7..3554dfa 100644 (file)
@@ -134,4 +134,79 @@ namespace OHOS {
     {
         return itemInfo_.uid;
     }
+
+
+    #define ARC_SCALE_LIST_ITEM_WIDTH (400)
+    #define ARC_SCALE_LIST_ITEM_HEIGHT (130) // (100)
+    #define ARC_SCALE_LIST_IMAGE_X (10)//(30)
+    #define ARC_SCALE_LIST_IMAGE_WIDTH (100)
+    #define ARC_SCALE_LIST_IMAGE_HEIGHT (100)
+    #define ARC_SCALE_LIST_TEXT_X (ARC_SCALE_LIST_IMAGE_X + ARC_SCALE_LIST_IMAGE_WIDTH)
+    #define ARC_SCALE_LIST_TEXT_WIDTH (ARC_SCALE_LIST_ITEM_WIDTH - ARC_SCALE_LIST_TEXT_X)
+    #define ARC_SCALE_LIST_TEXT_HEIGHT (100)
+
+    ArcScaleListItemView::ArcScaleListItemView()
+    {
+        Resize(ARC_SCALE_LIST_ITEM_WIDTH, ARC_SCALE_LIST_ITEM_HEIGHT);
+        SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT);
+        // SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full);
+        SetTouchable(true);
+
+        if (image_ == nullptr) {
+            image_ = new UIImageView();
+            if (image_ == nullptr) {
+                return ;
+            }
+        }
+        image_->SetPosition(ARC_SCALE_LIST_IMAGE_X, 0, ARC_SCALE_LIST_IMAGE_WIDTH, ARC_SCALE_LIST_IMAGE_HEIGHT);
+        image_->SetResizeMode(UIImageView::ImageResizeMode::CENTER);
+
+        if (label_ == nullptr) {
+            label_ = new UILabelExt();
+            if (label_ == nullptr) {
+                delete image_;
+                image_ = nullptr;
+                return ;
+            }
+        }
+        label_->SetPosition(ARC_SCALE_LIST_TEXT_X, 0, ARC_SCALE_LIST_TEXT_WIDTH, ARC_SCALE_LIST_TEXT_HEIGHT);
+        label_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT);
+        label_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 40);  // 40: item font size
+        label_->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS);
+        label_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+
+        Add(image_);
+        Add(label_);
+    }
+
+    ArcScaleListItemView::~ArcScaleListItemView()
+    {
+        RemoveAll();
+        if (image_ != nullptr) {
+            delete image_;
+            image_ = nullptr;
+        }
+        if (label_ != nullptr) {
+            delete label_;
+            label_ = nullptr;
+        }
+    }
+
+    void ArcScaleListItemView::SetItemInfo(const AppItem &itemInfo)
+    {
+        itemInfo_ = itemInfo;
+        image_->SetSrc(itemInfo.iconSmall);
+        label_->SetTextId(itemInfo.TextId);
+    }
+
+    AppViewId ArcScaleListItemView::GetViewId()
+    {
+        return itemInfo_.id;
+    }
+
+    const char *ArcScaleListItemView::GetAppUid()
+    {
+        return itemInfo_.uid;
+    }    
+
 }
index 8e26721..c3716f2 100644 (file)
@@ -56,4 +56,62 @@ void ApplistAdapter::AddListItem(const AppItem &item)
 {
     listData_.push_back(item);
 }
+
+
+ArcScaleListItemAdapter::ArcScaleListItemAdapter()
+{
+    //
+}
+
+ArcScaleListItemAdapter::~ArcScaleListItemAdapter()
+{
+    // ClearData();
+    nodeList_.Clear();
+}
+
+uint16_t ArcScaleListItemAdapter::GetCount()
+{
+    return nodeList_.Size();
+}
+
+void ArcScaleListItemAdapter::AddListItem(const AppItem &item)
+{
+    nodeList_.PushBack(item);
+}
+
+UIView * ArcScaleListItemAdapter::GetView(UIView* inView, int16_t index)
+{
+    if (nodeList_.IsEmpty() || index > nodeList_.Size() - 1 || index < 0) {
+        return nullptr;
+    }
+
+    ListNode<AppItem>* node = nodeList_.Begin();
+    for (uint16_t i = 0; i < index; i++) {
+        node = node->next_;
+    }
+
+    ArcScaleListItemView * item = nullptr;
+    if (inView == nullptr) 
+    {
+        // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ArcScaleListItemAdapter::GetView [%d]", __LINE__);
+        item = new ArcScaleListItemView();
+        if (nullptr == item)
+            return nullptr;
+    } 
+    else 
+    {
+        // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ArcScaleListItemAdapter::GetView [%d]", __LINE__);
+        item = static_cast<ArcScaleListItemView*>(inView);
+    }
+
+    if (item != nullptr) 
+    {
+        item->SetViewIndex(index);
+
+        item->SetItemInfo(node->data_);
+        item->SetOnClickListener(itemClickListener_);
+    }
+    return item;
+}
+
 } // namespace OHOS
index 66c5c12..6929aa7 100644 (file)
@@ -120,7 +120,18 @@ namespace OHOS {
             hexagonsView->SetDraggable(false);
             hexagonsView->Scale(1.0f, itemView->GetViewIndex()); // switch focus to click view
             type = TransitionType::TRANSITION_HEXAGONS;
-        } else {
+        } 
+        else if(AppListStyle::ARC_SCALE_LIST_STYLE == style)
+        {
+            ArcScaleListItemView * itemView = dynamic_cast<ArcScaleListItemView *>(&view);
+            if(nullptr == itemView)
+            {
+                return false;
+            }
+            viewId = itemView->GetViewId();
+            uid = (char *)itemView->GetAppUid();
+        }
+        else {
             AppItemView *itemView = dynamic_cast<AppItemView *>(&view);
             if (itemView == nullptr) {
                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "itemView is nullptr", viewId);
index 6d24541..0307661 100644 (file)
@@ -18,6 +18,13 @@ static constexpr int16 NUM_2 = 2;
 static constexpr int16 MAX_SCROLL_DIS = 1000;
 static constexpr int16 ROTATE_FACTOR_2 = 2;
 
+#define ARC_SCALE_LIST_SCALE_FACTOR (350)//(400)
+#define ARC_SCALE_LIST_X (25)
+#define ARC_SCALE_LIST_Y (30)
+#define ARC_SCALE_LIST_WIDTH (Screen::GetInstance().GetWidth() - ARC_SCALE_LIST_X)
+#define ARC_SCALE_LIST_HEIGHT (Screen::GetInstance().GetHeight() - ARC_SCALE_LIST_Y * 2)
+
+
 ApplistView::ApplistView()
 {
     WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::ApplistView ");
@@ -52,6 +59,22 @@ ApplistView::~ApplistView()
         callback_ = nullptr;
     }
     enterAnimator_ = nullptr;
+
+    if(nullptr != ArcScaleListAdapter_)
+    {
+        delete ArcScaleListAdapter_;
+        ArcScaleListAdapter_ = nullptr;
+    }
+    if(nullptr != ArcScaleList_)
+    {
+        delete ArcScaleList_;
+        ArcScaleList_ = nullptr;
+    }
+    if(nullptr != ArcScaleListGroup_)
+    {
+        delete ArcScaleListGroup_;
+        ArcScaleListGroup_ = nullptr;
+    }
     WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::~ApplistView end...");
 }
 
@@ -64,7 +87,12 @@ void ApplistView::OnStart()
         FootballStyleOnStart();
     } else if (style == AppListStyle::HEXAGONS_STYLE) {
         HexagonsStyleOnStart();
-    } else {
+    }
+    else if(AppListStyle::ARC_SCALE_LIST_STYLE == style)
+    {
+        ArcScaleListStyleOnStart();
+    }
+    else {
         ListStyleOnStart();
     }
     WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::OnStart end...");
@@ -172,6 +200,98 @@ void ApplistView::ListStyleOnStart()
     WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::ListStyleOnStart end...");
 }
 
+static bool TransformItemBaseOnPosition(UITransformList* list, UIView* item)
+{
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TransformItemBaseOnPosition [%d]", __LINE__);
+    if (list == nullptr || item == nullptr) {
+        return false;
+    }
+    if (item->GetViewType() != UI_TRANSFORM_GROUP) {
+        return false;
+    }
+    UITransformGroup * group = dynamic_cast<UITransformGroup*>(item);
+    if (group == nullptr) {
+        return false;
+    }
+
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TransformItemBaseOnPosition [%d]", __LINE__);
+    int16_t w = group->GetWidth();
+    int16_t h = group->GetHeight();
+    if (list->GetDirection() == UIList::VERTICAL) {
+        int16_t midY = list->GetY() + (list->GetHeight() >> 1);
+        int16_t y = group->GetY();
+        int offset = (y + (h >> 1) - midY);
+        int temp = EasingEquation::SineEaseIn(0, ARC_SCALE_LIST_SCALE_FACTOR, abs(offset), ARC_SCALE_LIST_SCALE_FACTOR);
+        float scale = 1.0 - (static_cast<float>(temp) / ARC_SCALE_LIST_SCALE_FACTOR);
+        group->Scale(Vector2<float>(scale, scale), Vector2<float>(w >> 1,  h >> 1));
+        if ((y <= midY) && (y + group->GetHeight() >= midY)) {
+            return true;
+        }
+    }
+    return false;
+}
+
+void ApplistView::ArcScaleListStyleOnStart(void)
+{
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ApplistView::ArcScaleListStyleOnStart [%d]", __LINE__);
+    if(nullptr == ArcScaleListGroup_)
+    {
+        ArcScaleListGroup_ = new UIViewGroup();
+        if(nullptr == ArcScaleListGroup_)
+            return;
+
+        ArcScaleListGroup_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
+        // ArcScaleListGroup_->SetPosition(0, 0);
+        // ArcScaleListGroup_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
+        ArcScaleListGroup_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE);
+        ArcScaleListGroup_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
+        // ArcScaleListGroup_->RemoveAll();
+
+        SetContainerView(ArcScaleListGroup_);
+    }
+
+    if(nullptr == ArcScaleListAdapter_)
+    {
+        ArcScaleListAdapter_ = new ArcScaleListItemAdapter();
+        if(nullptr == ArcScaleListAdapter_)
+            return;
+        
+        ArcScaleListAdapter_->SetItemClickListener(presenter_);
+    }
+    
+    if (nullptr == ArcScaleList_)
+    {
+        ArcScaleList_ = new UITransformList();
+        if (nullptr == ArcScaleList_)
+            return;
+    
+        ArcScaleList_->SetPosition(ARC_SCALE_LIST_X, ARC_SCALE_LIST_Y, ARC_SCALE_LIST_WIDTH, ARC_SCALE_LIST_HEIGHT);
+        ArcScaleList_->SetItemTransformFunc(&TransformItemBaseOnPosition);
+        ArcScaleList_->SetAdapter(ArcScaleListAdapter_);
+        ArcScaleList_->SetThrowDrag(true);
+        ArcScaleList_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT);
+        ArcScaleList_->SetScrollBlankSize(40);//(50);
+        ArcScaleList_->SetMaxScrollDistance(1000); // 1000: max scroll distance
+        ArcScaleList_->SetSwipeACCLevel(800); // 800: compensation distance
+        ArcScaleList_->SetDragACCLevel(5); // 5: drag acceleration
+        ArcScaleList_->SetYScrollBarVisible(true);
+        // ArcScaleList_->SetScrollStateListener(presenter_);
+
+        ArcScaleList_->SetRotateFactor(ROTATE_FACTOR_2);
+        ArcScaleList_->RequestFocus();
+
+        if(nullptr == ArcScaleListDragListener_)
+        {
+            ArcScaleListDragListener_ = new AppListOnDragListener();
+            if (nullptr == ArcScaleListDragListener_)
+                return;
+        }
+        ArcScaleList_->SetOnDragListener(ArcScaleListDragListener_);
+
+        ArcScaleListGroup_->Add(ArcScaleList_);
+    }
+}
+
 void ApplistView::OnSetUpView()
 {
     WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ApplistView::OnSetUpView");
@@ -181,7 +301,12 @@ void ApplistView::OnSetUpView()
         FootballStyleOnSetUpView();
     } else if (style == AppListStyle::HEXAGONS_STYLE) {
         HexagonsStyleOnSetUpView();
-    } else {
+    } 
+    else if(AppListStyle::ARC_SCALE_LIST_STYLE == style)
+    {
+        ArcScaleListStyleOnSetUpView();
+    } 
+    else {
         ListStyleOnSetUpView();
     }
 }
@@ -228,6 +353,11 @@ void ApplistView::ListStyleOnSetUpView()
     return;
 }
 
+void ApplistView::ArcScaleListStyleOnSetUpView(void)
+{
+    // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ApplistView::ArcScaleListStyleOnSetUpView [%d]", __LINE__);
+}
+
 void ApplistView::OnTearDownView()
 {
     WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::OnTearDownView");
@@ -251,7 +381,13 @@ void ApplistView::OnStop()
             RootView::GetInstance()->ClearOnKeyActListener();
         } else if (style == AppListStyle::HEXAGONS_STYLE) {
             HexagonsStyleOnStop();//蜂窝
-        } else {
+        }
+        else if(AppListStyle::ARC_SCALE_LIST_STYLE == style)
+        {
+            ArcScaleListStyleOnStop();
+            RootView::GetInstance()->ClearOnKeyActListener();
+        }
+        else {
             ListStyleOnStop();//list
             RootView::GetInstance()->ClearOnKeyActListener();
         }
@@ -265,6 +401,10 @@ void ApplistView::OnStop()
         {
             ListStyleOnStop();
         }
+        else if(AppListStyle::ARC_SCALE_LIST_STYLE == ThemeStyleModel::GetInstance().GetPreApplistStyle())
+        {
+            ArcScaleListStyleOnStop();
+        }
         ThemeStyleModel::GetInstance().SetTheSameSliceChangeFlag(false);
     }
     WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::OnStop end...");
@@ -322,6 +462,15 @@ void ApplistView::ListStyleOnStop()
     WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::ListStyleOnStop end...");
 }
 
+void ApplistView::ArcScaleListStyleOnStop(void)
+{
+    if(nullptr != ArcScaleListGroup_)
+    {
+        // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ApplistView::ArcScaleListStyleOnStop [%d]", __LINE__);
+        ArcScaleListGroup_->RemoveAll();
+    }
+}
+
 void ApplistView::AddAppItemToList(const AppItem &item)
 {
     AppListStyle style = presenter_->GetCurrentStyle();
@@ -341,7 +490,12 @@ void ApplistView::AddAppItemToList(const AppItem &item)
         itemView->SetOnClickListener(presenter_);
         hexagonsList_->Add(itemView);
         listHexagonsView_.PushBack(itemView);
-    } else {
+    }
+    else if(AppListStyle::ARC_SCALE_LIST_STYLE == style)
+    {
+        ArcScaleListAdapter_->AddListItem(item);
+    }
+    else {
         listAdapter_->AddListItem(item);
     }
 }
@@ -353,7 +507,12 @@ void ApplistView::ClearAppItemToList()
         FootballStyleOnStop();
     } else if (style == AppListStyle::HEXAGONS_STYLE) {
         HexagonsStyleOnStop();
-    } else {
+    }
+    else if(AppListStyle::ARC_SCALE_LIST_STYLE == style)
+    {
+        ArcScaleListStyleOnStop();
+    }
+    else {
         listAdapter_->ClearItem();
     }
 }
@@ -366,7 +525,12 @@ void ApplistView::RefreshAppList(void)
         footballList_->RefreshIcosahedron();
     } else if (style == AppListStyle::HEXAGONS_STYLE) {
         hexagonsList_->LayoutChildren(true);
-    } else {
+    }
+    else if(AppListStyle::ARC_SCALE_LIST_STYLE == style)
+    {
+        ArcScaleList_->RefreshList();
+    }
+    else {
         contentList_->RefreshList();
     }
 }
index 9bc8fbb..31f82aa 100644 (file)
@@ -21,12 +21,14 @@ namespace OHOS
     static constexpr const char *THEMESTYLE_VALUE_LIST = "list";
     static constexpr const char *THEMESTYLE_VALUE_HEXAGONS = "hexagons";
     static constexpr const char *THEMESTYLE_VALUE_FOOTBALL = "football";
+    static constexpr const char * THEMESTYLE_VALUE_ARC_SCALE_LIST = "arc_scale_list";
 
     typedef enum : uint16_t
     {
         APPLIST_STYLE,  // 列表显示
         HEXAGONS_STYLE, // 蜂窝显示
         FOOTBALL_STYLE, //足球
+        ARC_SCALE_LIST_STYLE,
         MAX_THEME_STYLE,
     } ThemeStyle;
 
@@ -35,6 +37,7 @@ namespace OHOS
         {ThemeStyle::APPLIST_STYLE, THEMESTYLE_VALUE_LIST},
         {ThemeStyle::HEXAGONS_STYLE, THEMESTYLE_VALUE_HEXAGONS},
         {ThemeStyle::FOOTBALL_STYLE, THEMESTYLE_VALUE_FOOTBALL},
+        {ThemeStyle::ARC_SCALE_LIST_STYLE, THEMESTYLE_VALUE_ARC_SCALE_LIST},
         // 在此处添加更多的映射关系
     };
 
@@ -43,6 +46,7 @@ namespace OHOS
         {THEMESTYLE_VALUE_LIST, ThemeStyle::APPLIST_STYLE},
         {THEMESTYLE_VALUE_HEXAGONS, ThemeStyle::HEXAGONS_STYLE},
         {THEMESTYLE_VALUE_FOOTBALL, ThemeStyle::FOOTBALL_STYLE},
+        {THEMESTYLE_VALUE_ARC_SCALE_LIST, ThemeStyle::ARC_SCALE_LIST_STYLE},
         // 在此处添加更多的映射关系
     };