Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
liyujiang-gzu committed Feb 11, 2022
1 parent 657d455 commit 39d2b33
Show file tree
Hide file tree
Showing 7 changed files with 254 additions and 86 deletions.
91 changes: 12 additions & 79 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,89 +1,22 @@
# 项目说明

> 2020.05.14
安卓圆角图片控件,支持分别设置上下左右四个角,通过Path实现绘制,在ListView/RecyclerView里比较丝滑。

## 开发环境
![效果图](/screenshot.jpg)

- JDK 1.8
- Android Studio Latest Version
- Android SDK 30
- Gradle Latest Version
- Plugin@FindViewByME
- Plugin@GsonFormatPlus
## 例子演示:

## 协作工具

- xiaopiu:产品原型协作
- 蓝湖:UI 设计稿协作
- git:程序代码协作

## 模板文件

- .github/workflows 自动化工作流
- .gitignore 通用的 GIT 版本控制文件忽略规则
- build.gradle 项目构建管理
- gradle.properties 通用的项目配置
- app/proguard-common.pro 通用的混淆规则
- gradle/common.gradle 通用的项目配置,包括 GIT 提交信息、打包排除文件、静态检查白名单等
- gradle/config.gradle 构建配置,包括指定 SDK 版本、是否启用 X86 支持、是否启用混淆
- gradle/dependency.gradle 第三方依赖项集中管理
- gradle/git.gradle 基于 GIT 进行版本号得到 APP 版本号
- gradle/publish.gradle 项目打包发布到 Maven 仓库
- gradle/app.gradle 通用的 APK 打包配置,包括解决依赖冲突、分环境分渠道打包、分包、自动签名、归档备份等
- gradle/library.gradle 通用的库项目配置

## 镜像加速

在天朝使用 jcenter、mavenCentral 及 google 三个远程仓库,Gradle Sync 会很慢,
google 仓库甚至需要`科学上网`才能访问。
为了加快速度,优先用 [阿里云仓库服务](https://maven.aliyun.com/mvn/view) 的仓库作为下载源,
将本项目的[gradle/init.d/init.gradle](/gradle/init.d/init.gradle)复制到`{USER_HOME}/.gradle/`下即可,
`USER_HOME`在 Windows 上大约为`C:/Users/liyujiang/.gradle/`,在 Linux 上大约为`/home/liyujiang/.gradle/`
`init.d/init.gradle`内容为:

```gradle
buildscript {
repositories {
maven { url 'https://maven.aliyun.com/repositories/jcenter' }
maven { url 'https://maven.aliyun.com/repositories/google' }
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
}
}
allprojects {
repositories {
maven { url 'https://maven.aliyun.com/repositories/jcenter' }
maven { url 'https://maven.aliyun.com/repositories/google' }
maven { url 'https://maven.aliyun.com/repository/central' }
maven { url "https://www.jitpack.io" }
}
}
```xml
<com.github.gzuliyujiang.RoundCornerImage.RoundCornerImageView
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginStart="10dp"
android:scaleType="fitXY"
android:src="@android:drawable/sym_def_app_icon"
app:lyj_cornerSize="30dp"
app:lyj_cornerType="left_falling"/>
```

## 远程真机

- 免费 [华为远程真机云调试](https://developer.huawei.com/consumer/cn/agconnect/cloud-adjust)
- 免费 [小米云测平台远程真机租用](https://testit.miui.com/remote)
- 免费 [VIVO 云测平台远程真机](https://vcl.vivo.com.cn/#/machine/picking)
- 免费 [OPPO 云测平台远程真机](https://open.oppomobile.com/cloudmachine/device/list-plus)
- 免费 [三星远程开发测试平台真机调试](http://samsung.smarterapps.cn/index.php?app=home&mod=Index&act=samsung)
- 新人试用 ~~腾讯 WeTest 云真机调试、阿里 EMAS 移动测试远程真机、百度 MTC 远程真机调试、Testin 远程真机测试、AllTesting 真机测试~~

## 架构模式

模块化/组件化。

- 通过模块化/组件化组织代码,面向接口编程,尽可能做到高内聚、低耦合、重复用。
- 模块可分为多种类型,一般分为:基础库(日志打印、网络请求、图片加载等)、三方包(微信登录、统计分析、消息推送等)、业务组件(会员中心、商城等)。
- 常见组件间通信方式:直接依赖(耦合太重,不推荐)、事件或广播(难以溯源,不推荐)、路由(如 @alibaba/ARouter)、面向接口(推荐)。
- 模块化/组件化业务独立,每个业务作为单独的组件,代码实现分离,不会搅在一起。
- 模块化/组件化便于协作,每个开发人员只关心自己负责的模块/组件,每个模块/组件作为一个子工程,没有太多的耦合。
- 模块化/组件化便于维护,各模块/组件管理自己的代码、布局、资源,主工程可以方便添加与移除。

## 设计模式

MVVM:Model-View-ViewModel。使用谷歌架构组件`ViewModel``LiveData``DataBinding`实现。

## 许可协议

```text
Expand Down
106 changes: 100 additions & 6 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,108 @@
~ See the Mulan PSL v2 for more details.
-->

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp">

<TextView
<com.github.gzuliyujiang.RoundCornerImage.RoundCornerImageView
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_gravity="center_horizontal"
android:scaleType="fitXY"
android:src="@android:drawable/sym_def_app_icon"
app:lyj_cornerSize="30dp"
app:lyj_cornerType="all" />

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="90dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:orientation="horizontal">

<com.github.gzuliyujiang.RoundCornerImage.RoundCornerImageView
android:layout_width="90dp"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@android:drawable/sym_def_app_icon"
app:lyj_cornerSize="30dp"
app:lyj_cornerType="left" />

<View
android:layout_width="50dp"
android:layout_height="match_parent"
android:background="#C78E69" />

<com.github.gzuliyujiang.RoundCornerImage.RoundCornerImageView
android:layout_width="90dp"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@android:drawable/sym_def_app_icon"
app:lyj_cornerSize="30dp"
app:lyj_cornerType="right" />

</LinearLayout>

<LinearLayout
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Hello World!" />
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:gravity="center"
android:orientation="vertical">

<com.github.gzuliyujiang.RoundCornerImage.RoundCornerImageView
android:layout_width="match_parent"
android:layout_height="90dp"
android:scaleType="fitXY"
android:src="@android:drawable/sym_def_app_icon"
app:lyj_cornerSize="30dp"
app:lyj_cornerType="top" />

<View
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#C78E69" />

<com.github.gzuliyujiang.RoundCornerImage.RoundCornerImageView
android:layout_width="match_parent"
android:layout_height="90dp"
android:scaleType="fitXY"
android:src="@android:drawable/sym_def_app_icon"
app:lyj_cornerSize="30dp"
app:lyj_cornerType="bottom" />

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="90dp"
android:layout_marginTop="10dp"
android:gravity="center"
android:orientation="horizontal">

<com.github.gzuliyujiang.RoundCornerImage.RoundCornerImageView
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginStart="10dp"
android:scaleType="fitXY"
android:src="@android:drawable/sym_def_app_icon"
app:lyj_cornerSize="30dp"
app:lyj_cornerType="left_falling" />

<com.github.gzuliyujiang.RoundCornerImage.RoundCornerImageView
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginStart="10dp"
android:scaleType="fitXY"
android:src="@android:drawable/sym_def_app_icon"
app:lyj_cornerSize="30dp"
app:lyj_cornerType="right_falling" />

</LinearLayout>

</RelativeLayout>
</LinearLayout>
2 changes: 1 addition & 1 deletion library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
~ See the Mulan PSL v2 for more details.
-->

<manifest package="com.github.gzuliyujiang.library" />
<manifest package="com.github.gzuliyujiang.RoundCornerImage" />
Empty file removed library/src/main/java/.gitkeep
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* Copyright (c) 2016-present 贵州纳雍穿青人李裕江<[email protected]>
*
* The software is licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
*/

package com.github.gzuliyujiang.RoundCornerImage;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Path;
import android.util.AttributeSet;
import android.widget.ImageView;

/**
* 圆角图片,支持分别设置上下左右四个角
*
* @author liyujiang
* @since 2018/2/2
*/
public class RoundCornerImageView extends ImageView {
private static final int CORNER_TYPE_ALL = 0;
private static final int CORNER_TYPE_LEFT = 1;
private static final int CORNER_TYPE_TOP = 2;
private static final int CORNER_TYPE_RIGHT = 3;
private static final int CORNER_TYPE_BOTTOM = 4;
private static final int CORNER_TYPE_LEFT_FALLING = 5;
private static final int CORNER_TYPE_RIGHT_FALLING = 6;
private static final float CORNER_SIZE_DIP = 3;
private final Path path = new Path();
private float width, height;
private final int cornerType;
private final float cornerSize;

public RoundCornerImageView(Context context) {
this(context, null);
}

public RoundCornerImageView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}

public RoundCornerImageView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray t = context.obtainStyledAttributes(attrs, R.styleable.RoundCornerImageView);
cornerType = t.getInteger(R.styleable.RoundCornerImageView_lyj_cornerType, CORNER_TYPE_ALL);
cornerSize = t.getDimension(R.styleable.RoundCornerImageView_lyj_cornerSize, CORNER_SIZE_DIP * getResources().getDisplayMetrics().density);
t.recycle();
}

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
width = getWidth();
height = getHeight();
}

@Override
protected void onDraw(Canvas canvas) {
if (width > cornerSize && height > cornerSize) {
// 左上点
path.moveTo(cornerSize, 0);
// 上边线
path.lineTo(width - cornerSize, 0);
// 右上角
if (cornerType == CORNER_TYPE_ALL || cornerType == CORNER_TYPE_RIGHT ||
cornerType == CORNER_TYPE_TOP || cornerType == CORNER_TYPE_LEFT_FALLING) {
path.quadTo(width, 0, width, cornerSize);
} else {
path.lineTo(width, 0);
}
// 右边线
path.lineTo(width, height - cornerSize);
// 右下角
if (cornerType == CORNER_TYPE_ALL || cornerType == CORNER_TYPE_RIGHT ||
cornerType == CORNER_TYPE_BOTTOM || cornerType == CORNER_TYPE_RIGHT_FALLING) {
path.quadTo(width, height, width - cornerSize, height);
} else {
path.lineTo(width, height);
}
// 下边线
path.lineTo(cornerSize, height);
// 左下角
if (cornerType == CORNER_TYPE_ALL || cornerType == CORNER_TYPE_LEFT ||
cornerType == CORNER_TYPE_BOTTOM || cornerType == CORNER_TYPE_LEFT_FALLING) {
path.quadTo(0, height, 0, height - cornerSize);
} else {
path.lineTo(0, height);
}
// 左边线
path.lineTo(0, cornerSize);
// 左上角
if (cornerType == CORNER_TYPE_ALL || cornerType == CORNER_TYPE_LEFT ||
cornerType == CORNER_TYPE_TOP || cornerType == CORNER_TYPE_RIGHT_FALLING) {
path.quadTo(0, 0, cornerSize, 0);
} else {
path.lineTo(0, 0);
}
canvas.clipPath(path);
}
super.onDraw(canvas);
}

}
29 changes: 29 additions & 0 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!--
~ Copyright (c) 2016-present 贵州纳雍穿青人李裕江<[email protected]>
~
~ The software is licensed under the Mulan PSL v2.
~ You can use this software according to the terms and conditions of the Mulan PSL v2.
~ You may obtain a copy of Mulan PSL v2 at:
~ http://license.coscl.org.cn/MulanPSL2
~ THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
~ IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
~ PURPOSE.
~ See the Mulan PSL v2 for more details.
-->

<resources>

<declare-styleable name="RoundCornerImageView">
<attr name="lyj_cornerType" format="enum">
<enum name="all" value="0" />
<enum name="left" value="1" />
<enum name="top" value="2" />
<enum name="right" value="3" />
<enum name="bottom" value="4" />
<enum name="left_falling" value="5" />
<enum name="right_falling" value="6" />
</attr>
<attr name="lyj_cornerSize" format="dimension|reference" />
</declare-styleable>

</resources>
Binary file added screenshot.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 39d2b33

Please sign in to comment.