Skip to content

Commit d668cdf

Browse files
committed
update docs
1 parent 273fc25 commit d668cdf

File tree

5 files changed

+83
-6
lines changed

5 files changed

+83
-6
lines changed

README.md

+52
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,66 @@ EasyAndroid.init(application)
3131

3232
- [EasyDimension](./docs/EasyDimension.md)
3333
> 用于灵活的进行设备尺寸单位转换
34+
35+
用法示例
36+
```
37+
// 转换10dp到px
38+
EasyDimension.withDIP(10).toPX()
39+
// 转换30sp到MM
40+
EasyDimension.withSP(30).toMM()
41+
```
3442
- [EasyFormatter](./docs/EasyFormatter.md)
3543
> 用于对任意类型数据,进行格式化输出。便于展示查看
44+
45+
用法示例:
46+
```
47+
val any:Any = create()// 创建待格式化数据
48+
val result:String = EasyFormatter.DEFAULT.format(any)// 使用formatter实例进行格式化
49+
val result2:String = any.easyFormat()// 或者使用扩展函数。直接格式化
50+
```
51+
3652
- [EasyLog](./docs/EasyLog.md)
3753
> 用于简单的进行日志打印输出,支持格式化输出、自定义打印格式。
54+
55+
用法示例:
56+
```
57+
val any:Any = create()// 创建待打印数据
58+
EasyLog.DEFAULT.d(any)// 使用默认log实例进行数据打印. 以Log.d()的方式进行输出
59+
any.easyLogE()// 使用扩展函数直接进行数据打印,以Log.e()的方式进行输出
60+
```
3861
- [EasyToast](./docs/EasyToast.md)
3962
> 用于进行Toast提示,可很简单的指定输出样式。
63+
64+
用法示例:
65+
```
66+
val message:String = create()// 创建待提示数据
67+
EasyToast.DEFAULT.show(message)// 使用系统样式进行输出
68+
EasyToast.create(layoutID:Int, tvID:Int, duration:Int).show(message)// 使用自定义样式进行输出
69+
```
4070
- [EasyReflect](./docs/EasyReflect.md)
4171
> 对常规的反射操作进行封装。达到更便于使用反射的效果
72+
73+
用法示例:
74+
```
75+
// 以类名Test为例
76+
class Test(val name:String) {
77+
fun wrap(name:String):String = "包裹后的数据$name"
78+
}
79+
80+
// 创建Reflect实例:
81+
var reflect = EasyReflect.create(Test())
82+
83+
// 为name字段赋值:
84+
reflect.setField("name", "EasyReflect")
85+
// 读取name字段的值:"EasyReflect"
86+
val value = reflect.getValue("name")
87+
88+
// 调用方法wrap方法,并传入参数value
89+
reflect.call("wrap", value)
90+
// 调用wrap方法,并获取返回值: "包裹后的数据EasyReflect"
91+
val result = reflect.callWithReturn("wrap", value).get<String>()
92+
```
93+
4294
- [APIs](./docs/APIs.md)
4395
> 提供的一些其他零散的类库APIs
4496

app/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ dependencies {
3636
if (useLocal) {
3737
implementation project(':utils')
3838
} else {
39-
implementation 'com.github.yjfnypeu:EasyAndroid:1.0.0'
39+
implementation 'com.github.yjfnypeu:EasyAndroid:1.0.1'
4040
}
4141
}

docs/EasyDimension.md

+7-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ EasyDimension用于快速的在系统提供的各种尺寸间(PX, DIP, SP, IN, P
1313
1. 传入待转换尺寸
1414

1515
```kotlin
16-
// value为原始数值。unit为数值单位。
17-
// unit单位使用系统提供的尺寸单位,如TypedValue.COMPLEX_UNIT_PX, TypedValue.COMPLEX_UNIT_DIP
18-
dimension = EasyDimension.create(value, unit)
16+
dimension = EasyDimension.withPX(value:Float)//原始尺寸单位PX
17+
dimension = EasyDimension.withDIP(value:Float)//原始尺寸单位PX
18+
dimension = EasyDimension.withSP(value:Float)//原始尺寸单位SP
19+
dimension = EasyDimension.withPT(value:Float)//原始尺寸单位PT
20+
dimension = EasyDimension.withIN(value:Float)//原始尺寸单位IN
21+
dimension = EasyDimension.withMM(value:Float)//原始尺寸单位MM
1922
```
2023

2124
2. 输出转换后的不同尺寸的数值
@@ -33,5 +36,5 @@ dimension.toMM()
3336

3437
将30dp转换为px
3538
```kotlin
36-
val pxResult = EasyDimension.create(30, TypedValue.COMPLEX_UNIT_DIP).toPX()
39+
val pxResult = EasyDimension.withDIP(30).toPX()
3740
```

utils/src/main/java/com/haoge/easyandroid/Extensions.kt

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ package com.haoge.easyandroid
22

33
import android.app.Dialog
44
import com.haoge.easyandroid.easy.EasyFormatter
5+
import com.haoge.easyandroid.easy.EasyLog
56
import com.haoge.easyandroid.safe.SafeDialogHandle
67

78
fun Dialog?.safeShow() = SafeDialogHandle.safeShowDialog(this)
89
fun Dialog?.safeDismiss() = SafeDialogHandle.safeDismissDialog(this)
9-
fun Any?.easyFormat():String = EasyFormatter.DEFAULT.format(this)
10+
fun Any?.easyFormat():String = EasyFormatter.DEFAULT.format(this)
11+
fun Any?.easyLogD() = EasyLog.DEFAULT.d(this)
12+
fun Any?.easyLogE() = EasyLog.DEFAULT.e(this)

utils/src/main/java/com/haoge/easyandroid/easy/EasyDimension.kt

+19
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,28 @@ class EasyDimension private constructor(private val pixel:Float, private val met
2323
fun toMM() = pixel / metrics.xdpi / (1.0f / 25.4f)
2424

2525
companion object {
26+
@JvmStatic
2627
fun create(value:Float, unit:Int): EasyDimension {
2728
val metrics = SingleCache.getApplicationContext().resources.displayMetrics
2829
return EasyDimension(TypedValue.applyDimension(unit, value, metrics), metrics!!)
2930
}
31+
32+
@JvmStatic
33+
fun withPX(value:Float) = create(value, TypedValue.COMPLEX_UNIT_PX)
34+
35+
@JvmStatic
36+
fun withDIP(value:Float) = create(value, TypedValue.COMPLEX_UNIT_DIP)
37+
38+
@JvmStatic
39+
fun withSP(value:Float) = create(value, TypedValue.COMPLEX_UNIT_SP)
40+
41+
@JvmStatic
42+
fun withPT(value:Float) = create(value, TypedValue.COMPLEX_UNIT_PT)
43+
44+
@JvmStatic
45+
fun withIN(value:Float) = create(value, TypedValue.COMPLEX_UNIT_IN)
46+
47+
@JvmStatic
48+
fun withMM(value:Float) = create(value, TypedValue.COMPLEX_UNIT_MM)
3049
}
3150
}

0 commit comments

Comments
 (0)