Skip to content

Commit 5851344

Browse files
committed
see 07/28 log
1 parent 6a836a0 commit 5851344

File tree

11 files changed

+194
-109
lines changed

11 files changed

+194
-109
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
* `19/07/28` [add] NetworkUtils#(un)registerNetworkStatusChangedListener. Publish v1.25.3.
2+
* `19/07/27` [fix] ThreadUtils memory leak.
13
* `19/07/26` [add] ContainerUtils. Publish v1.25.2.
24
* `19/07/25` [fix] PermissionUtils' NullPointException.
35
* `19/07/24` [fix] ZipUtils#unzipFile.

README-CN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
[frame]: https://raw.githubusercontent.com/Blankj/AndroidUtilCode/master/art/auc_frame.png
4747

48-
[aucSvg]: https://img.shields.io/badge/AndroidUtilCode-v1.25.2-brightgreen.svg
48+
[aucSvg]: https://img.shields.io/badge/AndroidUtilCode-v1.25.3-brightgreen.svg
4949
[auc]: https://github.com/Blankj/AndroidUtilCode
5050

5151
[apiSvg]: https://img.shields.io/badge/API-14+-brightgreen.svg

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ If this project helps you a lot and you want to support the project's developmen
4545

4646
[frame]: https://raw.githubusercontent.com/Blankj/AndroidUtilCode/master/art/auc_frame.png
4747

48-
[aucSvg]: https://img.shields.io/badge/AndroidUtilCode-v1.25.2-brightgreen.svg
48+
[aucSvg]: https://img.shields.io/badge/AndroidUtilCode-v1.25.3-brightgreen.svg
4949
[auc]: https://github.com/Blankj/AndroidUtilCode
5050

5151
[apiSvg]: https://img.shields.io/badge/API-14+-brightgreen.svg

buildSrc/src/main/groovy/Config.groovy

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class Config {
1414
static compileSdkVersion = 27
1515
static minSdkVersion = 14
1616
static targetSdkVersion = 27
17-
static versionCode = 1_025_002
18-
static versionName = '1.25.2'// E.g. 1.9.72 => 1,009,072
17+
static versionCode = 1_025_003
18+
static versionName = '1.25.3'// E.g. 1.9.72 => 1,009,072
1919

2020
// lib version
2121
static kotlin_version = '1.3.10'

feature/utilcode/pkg/src/main/java/com/blankj/utilcode/pkg/feature/network/NetworkActivity.kt

+48-74
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import com.blankj.common.CommonTitleActivity
99
import com.blankj.utilcode.pkg.R
1010
import com.blankj.utilcode.util.NetworkUtils
1111
import com.blankj.utilcode.util.SpanUtils
12-
import com.blankj.utilcode.util.Utils
12+
import com.blankj.utilcode.util.ThreadUtils
13+
import com.blankj.utilcode.util.ToastUtils
1314
import kotlinx.android.synthetic.main.activity_network.*
14-
import java.util.concurrent.atomic.AtomicInteger
1515

1616
/**
1717
* ```
@@ -21,10 +21,7 @@ import java.util.concurrent.atomic.AtomicInteger
2121
* desc : demo about NetworkUtils
2222
* ```
2323
*/
24-
class NetworkActivity : CommonTitleActivity() {
25-
26-
var cur: Int = 0
27-
var count: AtomicInteger = AtomicInteger();
24+
class NetworkActivity : CommonTitleActivity(), NetworkUtils.OnNetworkStatusChangedListener {
2825

2926
companion object {
3027
fun start(context: Context) {
@@ -33,8 +30,6 @@ class NetworkActivity : CommonTitleActivity() {
3330
}
3431
}
3532

36-
private lateinit var spanSb: SpannableStringBuilder
37-
3833
override fun bindTitle(): CharSequence {
3934
return getString(R.string.demo_network)
4035
}
@@ -52,6 +47,7 @@ class NetworkActivity : CommonTitleActivity() {
5247
NetworkUtils.setWifiEnabled(isChecked)
5348
updateAboutNetwork()
5449
}
50+
NetworkUtils.registerNetworkStatusChangedListener(this)
5551
}
5652

5753
override fun onResume() {
@@ -66,18 +62,45 @@ class NetworkActivity : CommonTitleActivity() {
6662
when (view.id) {
6763
R.id.networkOpenWirelessSettingsBtn -> NetworkUtils.openWirelessSettings()
6864
}
69-
updateAboutNetwork()
7065
}
7166

72-
private lateinit var ipV4AddressAsyncTask: Utils.Task<String>
73-
private lateinit var ipV6AddressAsyncTask: Utils.Task<String>
74-
private lateinit var wifiAvailableAsyncTask: Utils.Task<Boolean>
75-
private lateinit var availableAsyncTask: Utils.Task<Boolean>
76-
private lateinit var domainAddressAsyncTask: Utils.Task<String>
67+
private lateinit var task: ThreadUtils.SimpleTask<String>
7768

7869
private fun updateAboutNetwork() {
79-
spanSb = SpanUtils.with(networkAboutTv)
80-
.appendLine("isConnected: " + NetworkUtils.isConnected())
70+
71+
SpanUtils.with(networkAboutTv)
72+
.append(getSpan())
73+
.appendLine("")
74+
.appendLine("")
75+
.appendLine("")
76+
.appendLine("")
77+
.appendLine("Loading...")
78+
.create()
79+
80+
task = object : ThreadUtils.SimpleTask<String>() {
81+
82+
override fun doInBackground(): String {
83+
val sb: StringBuilder = StringBuilder();
84+
sb.appendln("getIPv4Address: ${NetworkUtils.getIPAddress(true)}")
85+
sb.appendln("getIPv6Address: ${NetworkUtils.getIPAddress(false)}")
86+
sb.appendln("isWifiAvailable: ${NetworkUtils.isWifiAvailable()}")
87+
sb.appendln("isAvailable: ${NetworkUtils.isAvailable()}")
88+
sb.appendln("getBaiduDomainAddress: ${NetworkUtils.getDomainAddress("baidu.com")}")
89+
return sb.toString()
90+
}
91+
92+
override fun onSuccess(result: String) {
93+
SpanUtils.with(networkAboutTv)
94+
.append(getSpan())
95+
.append(result)
96+
.create()
97+
}
98+
}
99+
ThreadUtils.executeByCached(task)
100+
}
101+
102+
private fun getSpan(): SpannableStringBuilder {
103+
return SpanUtils().appendLine("isConnected: " + NetworkUtils.isConnected())
81104
.appendLine("getMobileDataEnabled: " + NetworkUtils.getMobileDataEnabled())
82105
.appendLine("isMobileData: " + NetworkUtils.isMobileData())
83106
.appendLine("is4G: " + NetworkUtils.is4G())
@@ -89,72 +112,23 @@ class NetworkActivity : CommonTitleActivity() {
89112
.appendLine("getIpAddressByWifi: " + NetworkUtils.getIpAddressByWifi())
90113
.appendLine("getGatewayByWifi: " + NetworkUtils.getGatewayByWifi())
91114
.appendLine("getNetMaskByWifi: " + NetworkUtils.getNetMaskByWifi())
92-
.append("getServerAddressByWifi: " + NetworkUtils.getServerAddressByWifi())
115+
.appendLine("getServerAddressByWifi: " + NetworkUtils.getServerAddressByWifi())
93116
.create()
94-
cur += 5
95-
96-
ipV4AddressAsyncTask = NetworkUtils.getIPAddressAsync(true) { data ->
97-
val num = count.get()
98-
if (num >= cur - 5) {
99-
spanSb = SpanUtils().appendLine(spanSb)
100-
.append("getIPv4Address: $data")
101-
.create()
102-
networkAboutTv.text = spanSb
103-
}
104-
count.addAndGet(1)
105-
}
117+
}
106118

107-
ipV6AddressAsyncTask = NetworkUtils.getIPAddressAsync(false) { data ->
108-
val num = count.get()
109-
if (num >= cur - 5) {
110-
spanSb = SpanUtils().appendLine(spanSb)
111-
.append("getIPv6Address: $data")
112-
.create()
113-
networkAboutTv.text = spanSb
114-
}
115-
count.addAndGet(1)
116-
}
119+
override fun onDisconnected() {
120+
ToastUtils.showLong("onDisconnected")
121+
}
117122

118-
wifiAvailableAsyncTask = NetworkUtils.isWifiAvailableAsync { data ->
119-
val num = count.get()
120-
if (num >= cur - 5) {
121-
spanSb = SpanUtils().appendLine(spanSb)
122-
.append("isWifiAvailable: $data")
123-
.create()
124-
networkAboutTv.text = spanSb
125-
}
126-
count.addAndGet(1)
127-
}
123+
override fun onConnected(networkType: NetworkUtils.NetworkType) {
128124

129-
availableAsyncTask = NetworkUtils.isAvailableAsync { data ->
130-
val num = count.get()
131-
if (num >= cur - 5) {
132-
spanSb = SpanUtils().appendLine(spanSb)
133-
.append("isAvailable: $data")
134-
.create()
135-
networkAboutTv.text = spanSb
136-
}
137-
count.addAndGet(1)
138-
}
139125

140-
domainAddressAsyncTask = NetworkUtils.getDomainAddressAsync("baidu.com") { data ->
141-
val num = count.get()
142-
if (num >= cur - 5) {
143-
spanSb = SpanUtils().appendLine(spanSb)
144-
.append("getBaiduDomainAddress: $data")
145-
.create()
146-
networkAboutTv.text = spanSb
147-
}
148-
count.addAndGet(1)
149-
}
126+
ToastUtils.showLong("onConnected: ${networkType.name}")
150127
}
151128

152129
override fun onDestroy() {
153-
ipV4AddressAsyncTask.cancel()
154-
ipV6AddressAsyncTask.cancel()
155-
wifiAvailableAsyncTask.cancel()
156-
availableAsyncTask.cancel()
157-
domainAddressAsyncTask.cancel()
130+
task.cancel()
131+
NetworkUtils.unregisterOnNetworkChangedListener(this)
158132
super.onDestroy()
159133
}
160134
}

lib/utilcode/README-CN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
Gradle:
44
```groovy
5-
implementation 'com.blankj:utilcode:1.25.2'
5+
implementation 'com.blankj:utilcode:1.25.3'
66
77
// if u use AndroidX, use the following
8-
implementation 'com.blankj:utilcodex:1.25.2'
8+
implementation 'com.blankj:utilcodex:1.25.3'
99
```
1010

1111

lib/utilcode/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
Gradle:
44
```groovy
5-
implementation 'com.blankj:utilcode:1.25.2'
5+
implementation 'com.blankj:utilcode:1.25.3'
66
77
// if u use AndroidX, use the following
8-
implementation 'com.blankj:utilcodex:1.25.2'
8+
implementation 'com.blankj:utilcodex:1.25.3'
99
```
1010

1111

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ private BarUtils() {
5757
* @return the status bar's height
5858
*/
5959
public static int getStatusBarHeight() {
60-
Resources resources = Resources.getSystem();
60+
Resources resources = Utils.getApp().getResources();
6161
int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
6262
return resources.getDimensionPixelSize(resourceId);
6363
}
@@ -453,7 +453,7 @@ private static void invokePanels(final String methodName) {
453453
* @return the navigation bar's height
454454
*/
455455
public static int getNavBarHeight() {
456-
Resources res = Resources.getSystem();
456+
Resources res = Utils.getApp().getResources();
457457
int resourceId = res.getIdentifier("navigation_bar_height", "dimen", "android");
458458
if (resourceId != 0) {
459459
return res.getDimensionPixelSize(resourceId);

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -306,13 +306,13 @@ private boolean isShouldHideKeyboard(View v, MotionEvent event) {
306306
}
307307

308308
private static int getStatusBarHeight() {
309-
Resources resources = Resources.getSystem();
309+
Resources resources = Utils.getApp().getResources();
310310
int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
311311
return resources.getDimensionPixelSize(resourceId);
312312
}
313313

314314
private static int getNavBarHeight() {
315-
Resources res = Resources.getSystem();
315+
Resources res = Utils.getApp().getResources();
316316
int resourceId = res.getIdentifier("navigation_bar_height", "dimen", "android");
317317
if (resourceId != 0) {
318318
return res.getDimensionPixelSize(resourceId);

0 commit comments

Comments
 (0)