# Broccoli **Repository Path**: hihopeorg/Broccoli ## Basic Information - **Project Name**: Broccoli - **Description**: 提供预加载占位效果 - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-06-16 - **Last Updated**: 2021-11-03 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Broccoli 本项目是基于开源项目Broccoli进行ohos化的移植和开发,可以通过项目标签以及github地址(https://github.com/samlss/Broccoli )追踪到原项目版本 #### 项目介绍 - 项目名称:Broccoli - 所属系列:ohos的第三方组件适配移植 - 功能:提供预加载占位效果。 - 项目移植状态:完成 - 调用差异:无 - 项目作者和维护人:hihope - 联系方式:hihope@hoperun.com - 原项目Doc地址:https://github.com/samlss/Broccoli - 原项目基线版本:master - 编程语言:Java #### 演示效果 ![Image text](/screenshot/Broccoli.gif) #### 安装教程 方法1. 1. 准备har包Broccoli.har。 2. 启动 DevEco Studio,将har包导入工程目录“entry->libs”下。 3. 在moudle级别下的build.gradle文件中添加依赖,在dependences标签中增加对libs目录下har包的引用。 ``` repositories { flatDir { dirs 'libs' } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) implementation(name: 'Broccoli', ext: 'har') .... } ``` 方法2. 1. 在工程的build.gradle的allprojects中,添加HAR所在的Maven仓地址 ``` repositories { maven { url 'http://106.15.92.248:8081/repository/Releases/' } } ``` 2. 在应用模块的build.gradle的dependencies闭包中,添加如下代码: ``` dependencies { implementation 'me.samlss.ohos:broccoli:1.0.0' } ``` #### 使用说明 1. 通过```addPlaceholders```添加需要预加载效果的控件: ```java mBroccoli = new Broccoli(); mBroccoli.addPlaceholders((ComponentContainer) findComponentById(ResourceTable.Id_root), ResourceTable.Id_tv_view_time, ResourceTable.Id_tv_collect_time, ResourceTable.Id_tv_price, ResourceTable.Id_iv_clock, ResourceTable.Id_tv_time, ResourceTable.Id_iv_calendar, ResourceTable.Id_iv_location, ResourceTable.Id_tv_location, ResourceTable.Id_iv_arrow_right, ResourceTable.Id_iv_logo, ResourceTable.Id_tv_organizer_name, ResourceTable.Id_tv_organizer_description, ResourceTable.Id_tv_fans, ResourceTable.Id_tv_fans_number, ResourceTable.Id_tv_events, ResourceTable.Id_tv_events_number, ResourceTable.Id_tv_follow, ResourceTable.Id_tv_station); ``` 或者也可以这样添加预加载的自定义背景和动画: ```java int placeholderColor = Color.getIntColor("#DDDDDD"); mBroccoli = new Broccoli(); mBroccoli.addPlaceholders( new PlaceholderParameter.Builder() .setView(findComponentById(ResourceTable.Id_iv_head)) .setDrawable(DrawableUtils.createOvalDrawable(placeholderColor)) .setAnimation(locationAnimation) .build(), new PlaceholderParameter.Builder() .setView(findComponentById(ResourceTable.Id_tv_name)) .setDrawable(DrawableUtils.createRectangleDrawable(placeholderColor, 0)) .build() } ``` 2. 之后调用```show()```展示预加载效果: ```java mBroccoli.show(); ``` 3. 请求到数据之后清除预加载效果: ```java mBroccoli.removeAllPlaceholders(); ``` #### 版本迭代 - v1.0.0 #### 版权和许可信息 ``` Copyright 2018 samlss Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ```