鸿蒙开源组件——OSS依赖项及其关联的许可库

jacksky
发布于 2021-11-15 18:30
浏览
0收藏

LicenseAdapter

项目介绍

  • 项目名称:LicenseAdapter
  • 所属系列:openharmony的第三方组件适配移植
  • 功能:LicenseAdapter是一个易于使用的库,它提供了一个RecyclerView适配器来显示OSS依赖项及其关联的许可证。
  • 项目移植状态:主功能完成
  • 调用差异:无
  • 开发版本:sdk6,DevEco Studio 2.2 Beta1
  • 基线版本: Release v3.2.0

效果演示鸿蒙开源组件——OSS依赖项及其关联的许可库-鸿蒙开发者社区

安装教程

1.在moudle级别下的build.gradle文件中添加依赖

// 添加maven仓库

repositories {
    maven {
        url 'https://s01.oss.sonatype.org/content/repositories/releases/'
    }
}

// 添加依赖库

dependencies { implementation 'com.gitee.chinasoft_ohos:licenseAdapter:1.0.0' }

2.在工程的build.gradle的allprojects中,添加HAR所在的Maven仓地址

// 添加maven仓库

 maven {
        url 'http://106.15.92.248:8081/repository/Releases/' 
    }

3.在应用模块的build.gradle的dependencies,添加如下代码: // 添加依赖库

dependencies {
    implementation 'com.jakewharton.ohos:disklrucache:1.0.0'
}

在sdk6,DevEco Studio 2.2 Beta1下项目可直接运行 如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, 并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下

使用说明

实现效果:点击右侧图标,动画效果,远程获取到license认证内容并展现。点击红色标题名字,跳转到浏览器打开网页。
在entry的build.gradle 引入
    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
        testImplementation 'junit:junit:4.13'
        ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.200'
        dependencies { implementation 'com.gitee.chinasoft_ohos:licenseAdapter:0.0.1-SNAPSHOT' }
    }
在library库 build.gradle引入
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    testImplementation 'junit:junit:4.13'
}

现在项目重写DependentLayout包含的控件如下定义:

XML中添加entry的布局文件ability_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<DependentLayout
    xmlns:ohos="http://schemas.huawei.com/res/ohos"
    ohos:height="match_content"
    ohos:width="match_parent"
    >
    <DependentLayout
        ohos:id="$+id:layout"
        ohos:height="50vp"
        ohos:width="match_parent"
        ohos:background_element="$color:colorTitle"
        >
     <Text
      ohos:height="match_content"
      ohos:width="match_content"
      ohos:left_margin="20vp"
      ohos:vertical_center="true"
      ohos:text="$string:app_name"
      ohos:text_size="18fp"
      ohos:text_color="#ffffff"
         />
    </DependentLayout>
    <ListContainer
            ohos:id="$+id:listContainer"
            ohos:height="match_parent"
            ohos:width="match_parent"
            ohos:below="$id:layout"
            />
</DependentLayout>

XML中添加library的布局文件list_item.xml:

<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
    xmlns:ohos="http://schemas.huawei.com/res/ohos"
    ohos:height="match_content"
    ohos:width="match_parent"
    ohos:orientation="vertical"
    ohos:padding="5vp">

    <DirectionalLayout
        ohos:id="$+id:layout_Dire"
        ohos:height="match_content"
        ohos:width="match_parent"
        ohos:orientation="horizontal"
        ohos:long_click_enabled="false"
        >
        <DirectionalLayout
            ohos:id="$+id:layout_name"
            ohos:height="match_content"
            ohos:width="match_parent"
            ohos:weight="1"
            ohos:left_padding="20vp"
            ohos:orientation="vertical"
            >
            <Text
                ohos:id="$+id:text1"
                ohos:height="match_content"
                ohos:width="match_content"
                ohos:text_color="$color:text_bg"
                ohos:multiple_lines="true"
                ohos:text_size="20fp"
                ohos:text=""
                >
            </Text>
            <Text
                ohos:id="$+id:text2"
                ohos:height="match_content"
                ohos:width="match_content"
                ohos:multiple_lines="true"
                ohos:text_size="15fp">
            </Text>
        </DirectionalLayout>
        <DependentLayout
            ohos:height="match_content"
            ohos:width="match_content"
            ohos:right_margin="12vp"
            >
            <Image
                ohos:id="$+id:image1"
                ohos:height="30vp"
                ohos:center_in_parent="true"
                ohos:width="20vp"
                ohos:background_element="$media:ic_expand_more_black_12dp"
                ></Image>
        </DependentLayout>
    </DirectionalLayout>

    <DirectionalLayout
        ohos:id="$+id:layout_license"
        ohos:height="match_content"
        ohos:width="match_content"
        ohos:visibility="hide"
        >

        <Text
            ohos:id="$+id:licenseNme"
            ohos:height="40vp"
            ohos:width="match_content"
            ohos:horizontal_center="true"
            ohos:multiple_lines="true"
            ohos:padding="5vp"
            ohos:text=""
            ohos:text_alignment="center"
            ohos:text_size="15vp"
            />

        <Text
            ohos:id="$+id:licenseId"
            ohos:height="match_content"
            ohos:width="match_content"
            ohos:horizontal_center="true"
            ohos:multiple_lines="true"
            ohos:padding="10vp"
            ohos:scrollable="true"
            ohos:text="License contents"
            ohos:text_alignment="horizontal_center"
            ohos:text_size="15vp"
            ohos:top_padding="1vp"
            />
    </DirectionalLayout>
</DirectionalLayout>

一、加载显示数据列表

1.设置状态栏颜色

WindowManager.getInstance().getTopWindow().get().setStatusBarColor(getColor(ResourceTable.Color_colorPrimary));

2.加载需要展示的适配器列表内容

 List<Library> licenses = new ArrayList<>();
 ListContainer list = (ListContainer) findComponentById(ResourceTable.Id_listContainer);
 list.setLongClickable(false);
 list.setReboundEffect(false);
 list.setLayoutManager(new DirectionalLayoutManager());
 list.setItemProvider(new LicenseAdapter(this, licenses));

3.初始化获取license及动画效果

3.1动画效果展开和收缩

      expand(Component component, boolean isAnimator)  //展开内容效果
      collapse(Component component)//收缩效果
public LicenseAdapter(Context context,  List<Library> datas) {
    this.context = context;
    List<ExpandableLibrary> wrappedLibraries = new ArrayList<>();
    for (Library library : datas) {
      wrappedLibraries.add(new ExpandableLibrary(library, this));
     }
    this.datas = Collections.unmodifiableList(wrappedLibraries);
  }

测试信息

CodeCheck代码测试无异常

CloudTest代码测试无异常

病毒安全检测通过

当前版本demo功能与原组件基本无差异

版本迭代

  • 1.0.0

版权和许可信息

   Copyright 2016-2017 Shimizu Yasuhiro (yshrsmz)

    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.

LicenseAdapter-master.zip 1.37M 6次下载
已于2021-11-15 18:30:21修改
收藏
回复
举报
回复
    相关推荐