Skip to content

Commit cb6283c

Browse files
authored
Merge pull request Blankj#806 from Blankj/1.23.0
see 01/18 log
2 parents a5fc602 + 928c304 commit cb6283c

File tree

11 files changed

+118
-127
lines changed

11 files changed

+118
-127
lines changed

lib/base/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ dependencies {
1515
api dep.free_proguard
1616
api 'com.r0adkll:slidableactivity:2.0.5'
1717
compileOnly dep.leakcanary.android_no_op
18-
// api 'com.blankj:utilcode:1.22.11'
18+
// api 'com.blankj:utilcode:1.23.0'
1919
}

utilcode/README-CN.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -385,13 +385,14 @@ setBackground : 设置背景
385385

386386
* ### Gson 相关 -> [GsonUtils.java][gson.java] -> [Test][gson.test]
387387
```
388-
getGson : 获取 Gson 对象
389-
toJson : 对象转 Json 串
390-
fromJson : Json 串转对象
391-
getCollectionType: 获取集合类型
392-
getMapType : 获取字典类型
393-
getArrayType : 获取数组类型
394-
getType : 获取类型
388+
getGson : 获取 Gson 对象
389+
toJson : 对象转 Json 串
390+
fromJson : Json 串转对象
391+
getListType : 获取链表类型
392+
getSetType : 获取集合类型
393+
getMapType : 获取字典类型
394+
getArrayType: 获取数组类型
395+
getType : 获取类型
395396
```
396397

397398
* ### 图片相关 -> [ImageUtils.java][image.java] -> [Demo][image.demo]

utilcode/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,8 @@ setBackground
388388
getGson
389389
toJson
390390
fromJson
391-
getCollectionType
391+
getListType
392+
getSetType
392393
getMapType
393394
getArrayType
394395
getType

utilcode/lib/src/main/java/com/blankj/utilcode/util/ColorUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,6 @@ public static int getRandomColor() {
202202
*/
203203
public static int getRandomColor(final boolean supportAlpha) {
204204
int high = supportAlpha ? (int) (Math.random() * 0xFF) << 24 : 0xFF000000;
205-
return high | (int) (Math.random() * 0xFF0000);
205+
return high | (int) (Math.random() * 0xFFFFFF);
206206
}
207207
}

utilcode/lib/src/main/java/com/blankj/utilcode/util/GsonUtils.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66

77
import java.io.Reader;
88
import java.lang.reflect.Type;
9-
import java.util.Collection;
9+
import java.util.List;
1010
import java.util.Map;
11+
import java.util.Set;
1112

1213

1314
/**
@@ -114,13 +115,23 @@ public static <T> T fromJson(final Reader reader, final Type type) {
114115
}
115116

116117
/**
117-
* Return the type of collection with the {@code type}.
118+
* Return the type of {@link List} with the {@code type}.
118119
*
119120
* @param type The type.
120-
* @return the type of collection with the {@code type}
121+
* @return the type of {@link List} with the {@code type}
121122
*/
122-
public static Type getCollectionType(final Type type) {
123-
return TypeToken.getParameterized(Collection.class, type).getType();
123+
public static Type getListType(final Type type) {
124+
return TypeToken.getParameterized(List.class, type).getType();
125+
}
126+
127+
/**
128+
* Return the type of {@link Set} with the {@code type}.
129+
*
130+
* @param type The type.
131+
* @return the type of {@link Set} with the {@code type}
132+
*/
133+
public static Type getSetType(final Type type) {
134+
return TypeToken.getParameterized(Set.class, type).getType();
124135
}
125136

126137
/**

utilcode/lib/src/test/java/com/blankj/utilcode/util/GsonUtilsTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void fromJson() {
4848
GsonUtils.toJson(
4949
GsonUtils.fromJson(
5050
GsonUtils.toJson(result),
51-
GsonUtils.getType(Result.class, GsonUtils.getCollectionType(Person.class))
51+
GsonUtils.getType(Result.class, GsonUtils.getListType(Person.class))
5252
)
5353
)
5454
);
@@ -58,7 +58,7 @@ public void fromJson() {
5858
public void getType() {
5959
Assert.assertEquals(
6060
"java.util.Collection<java.lang.String>",
61-
GsonUtils.getCollectionType(String.class).toString()
61+
GsonUtils.getListType(String.class).toString()
6262
);
6363
Assert.assertEquals(
6464
"java.util.Map<java.lang.String, java.lang.Integer>",
@@ -74,7 +74,7 @@ public void getType() {
7474
);
7575
Assert.assertEquals(
7676
"java.util.Map<java.lang.String, java.util.Collection<java.lang.String>>",
77-
GsonUtils.getMapType(String.class, GsonUtils.getCollectionType(String.class)).toString()
77+
GsonUtils.getMapType(String.class, GsonUtils.getListType(String.class)).toString()
7878
);
7979
}
8080

utilcode/lib/src/test/java/com/blankj/utilcode/util/LogUtilsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public void testObject() {
166166
LogUtils.d((Object) TWO_D_ARRAY);
167167
LogUtils.d(LIST);
168168
LogUtils.d(MAP);
169-
Object o = GsonUtils.fromJson(GsonUtils.toJson(LIST), GsonUtils.getCollectionType(String.class));
169+
Object o = GsonUtils.fromJson(GsonUtils.toJson(LIST), GsonUtils.getListType(String.class));
170170
System.out.println(o);
171171

172172

utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/CoreUtilActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public void snackbarClick(View view) {
170170
}
171171

172172
public void spStaticClick(View view) {
173-
SPStaticActivity.start(this);
173+
SPStaticActivity.Companion.start(this);
174174
}
175175

176176
public void spannableClick(View view) {

utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/spStatic/SPStaticActivity.java

Lines changed: 0 additions & 100 deletions
This file was deleted.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package com.blankj.utilcode.pkg.feature.spStatic
2+
3+
import android.content.Context
4+
import android.content.Intent
5+
import android.os.Bundle
6+
import android.view.View
7+
import com.blankj.lib.base.BaseBackActivity
8+
import com.blankj.utilcode.pkg.R
9+
import com.blankj.utilcode.util.SPStaticUtils
10+
import kotlinx.android.synthetic.main.activity_sp.*
11+
12+
/**
13+
* ```
14+
* author: Blankj
15+
* blog : http://blankj.com
16+
* time : 2018/01/08
17+
* desc : demo about SPUtils
18+
* ```
19+
*/
20+
class SPStaticActivity : BaseBackActivity() {
21+
22+
override fun initData(bundle: Bundle?) {
23+
24+
}
25+
26+
override fun bindLayout(): Int {
27+
return R.layout.activity_sp
28+
}
29+
30+
override fun initView(savedInstanceState: Bundle?, contentView: View) {
31+
spPutStringBtn.setOnClickListener(this)
32+
spPutIntBtn.setOnClickListener(this)
33+
spPutLongBtn.setOnClickListener(this)
34+
spPutFloatBtn.setOnClickListener(this)
35+
spPutBooleanBtn.setOnClickListener(this)
36+
spClearBtn.setOnClickListener(this)
37+
}
38+
39+
override fun doBusiness() {
40+
updateAboutSp()
41+
}
42+
43+
override fun onWidgetClick(view: View) {
44+
when (view.id) {
45+
R.id.spPutStringBtn -> SPStaticUtils.put("STRING", "string")
46+
R.id.spPutIntBtn -> SPStaticUtils.put("INT", 21)
47+
R.id.spPutLongBtn -> SPStaticUtils.put("LONG", java.lang.Long.MAX_VALUE)
48+
R.id.spPutFloatBtn -> SPStaticUtils.put("FLOAT", Math.PI.toFloat())
49+
R.id.spPutBooleanBtn -> SPStaticUtils.put("BOOLEAN", true)
50+
R.id.spClearBtn -> SPStaticUtils.clear()
51+
}
52+
updateAboutSp()
53+
}
54+
55+
private fun updateAboutSp() {
56+
aboutSpTv!!.text = sp2String()
57+
}
58+
59+
companion object {
60+
61+
fun start(context: Context) {
62+
val starter = Intent(context, SPStaticActivity::class.java)
63+
context.startActivity(starter)
64+
}
65+
66+
fun sp2String(): String {
67+
val sb = StringBuilder()
68+
val map = SPStaticUtils.getAll()
69+
for ((key, value) in map) {
70+
sb.append(key)
71+
.append(": ")
72+
.append(value)
73+
.append("\n")
74+
}
75+
return sb.toString()
76+
}
77+
}
78+
}

utilcode/pkg/src/main/res/layout/activity_sp.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,48 +11,48 @@
1111
android:paddingTop="@dimen/spacing_16">
1212

1313
<TextView
14-
android:id="@+id/tv_about_sp"
14+
android:id="@+id/aboutSpTv"
1515
style="@style/TextStyle"
1616
android:layout_width="match_parent"
1717
android:layout_height="wrap_content" />
1818

1919
<Button
20-
android:id="@+id/btn_sp_put_string"
20+
android:id="@+id/spPutStringBtn"
2121
style="@style/WideBtnStyle"
2222
android:layout_width="match_parent"
2323
android:layout_height="wrap_content"
2424
android:text="@string/sp_put_string" />
2525

2626
<Button
27-
android:id="@+id/btn_sp_put_int"
27+
android:id="@+id/spPutIntBtn"
2828
style="@style/WideBtnStyle"
2929
android:layout_width="match_parent"
3030
android:layout_height="wrap_content"
3131
android:text="@string/sp_put_int" />
3232

3333
<Button
34-
android:id="@+id/btn_sp_put_long"
34+
android:id="@+id/spPutLongBtn"
3535
style="@style/WideBtnStyle"
3636
android:layout_width="match_parent"
3737
android:layout_height="wrap_content"
3838
android:text="@string/sp_put_long" />
3939

4040
<Button
41-
android:id="@+id/btn_sp_put_float"
41+
android:id="@+id/spPutFloatBtn"
4242
style="@style/WideBtnStyle"
4343
android:layout_width="match_parent"
4444
android:layout_height="wrap_content"
4545
android:text="@string/sp_put_float" />
4646

4747
<Button
48-
android:id="@+id/btn_sp_put_boolean"
48+
android:id="@+id/spPutBooleanBtn"
4949
style="@style/WideBtnStyle"
5050
android:layout_width="match_parent"
5151
android:layout_height="wrap_content"
5252
android:text="@string/sp_put_boolean" />
5353

5454
<Button
55-
android:id="@+id/btn_sp_clear"
55+
android:id="@+id/spClearBtn"
5656
style="@style/WideBtnStyle"
5757
android:layout_width="match_parent"
5858
android:layout_height="wrap_content"

0 commit comments

Comments
 (0)