Skip to content

Commit

Permalink
see 07/28 log
Browse files Browse the repository at this point in the history
  • Loading branch information
Blankj committed Jul 28, 2019
1 parent 6a836a0 commit 5851344
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 109 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* `19/07/28` [add] NetworkUtils#(un)registerNetworkStatusChangedListener. Publish v1.25.3.
* `19/07/27` [fix] ThreadUtils memory leak.
* `19/07/26` [add] ContainerUtils. Publish v1.25.2.
* `19/07/25` [fix] PermissionUtils' NullPointException.
* `19/07/24` [fix] ZipUtils#unzipFile.
Expand Down
2 changes: 1 addition & 1 deletion README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

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

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

[apiSvg]: https://img.shields.io/badge/API-14+-brightgreen.svg
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ If this project helps you a lot and you want to support the project's developmen

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

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

[apiSvg]: https://img.shields.io/badge/API-14+-brightgreen.svg
Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/main/groovy/Config.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class Config {
static compileSdkVersion = 27
static minSdkVersion = 14
static targetSdkVersion = 27
static versionCode = 1_025_002
static versionName = '1.25.2'// E.g. 1.9.72 => 1,009,072
static versionCode = 1_025_003
static versionName = '1.25.3'// E.g. 1.9.72 => 1,009,072

// lib version
static kotlin_version = '1.3.10'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import com.blankj.common.CommonTitleActivity
import com.blankj.utilcode.pkg.R
import com.blankj.utilcode.util.NetworkUtils
import com.blankj.utilcode.util.SpanUtils
import com.blankj.utilcode.util.Utils
import com.blankj.utilcode.util.ThreadUtils
import com.blankj.utilcode.util.ToastUtils
import kotlinx.android.synthetic.main.activity_network.*
import java.util.concurrent.atomic.AtomicInteger

/**
* ```
Expand All @@ -21,10 +21,7 @@ import java.util.concurrent.atomic.AtomicInteger
* desc : demo about NetworkUtils
* ```
*/
class NetworkActivity : CommonTitleActivity() {

var cur: Int = 0
var count: AtomicInteger = AtomicInteger();
class NetworkActivity : CommonTitleActivity(), NetworkUtils.OnNetworkStatusChangedListener {

companion object {
fun start(context: Context) {
Expand All @@ -33,8 +30,6 @@ class NetworkActivity : CommonTitleActivity() {
}
}

private lateinit var spanSb: SpannableStringBuilder

override fun bindTitle(): CharSequence {
return getString(R.string.demo_network)
}
Expand All @@ -52,6 +47,7 @@ class NetworkActivity : CommonTitleActivity() {
NetworkUtils.setWifiEnabled(isChecked)
updateAboutNetwork()
}
NetworkUtils.registerNetworkStatusChangedListener(this)
}

override fun onResume() {
Expand All @@ -66,18 +62,45 @@ class NetworkActivity : CommonTitleActivity() {
when (view.id) {
R.id.networkOpenWirelessSettingsBtn -> NetworkUtils.openWirelessSettings()
}
updateAboutNetwork()
}

private lateinit var ipV4AddressAsyncTask: Utils.Task<String>
private lateinit var ipV6AddressAsyncTask: Utils.Task<String>
private lateinit var wifiAvailableAsyncTask: Utils.Task<Boolean>
private lateinit var availableAsyncTask: Utils.Task<Boolean>
private lateinit var domainAddressAsyncTask: Utils.Task<String>
private lateinit var task: ThreadUtils.SimpleTask<String>

private fun updateAboutNetwork() {
spanSb = SpanUtils.with(networkAboutTv)
.appendLine("isConnected: " + NetworkUtils.isConnected())

SpanUtils.with(networkAboutTv)
.append(getSpan())
.appendLine("")
.appendLine("")
.appendLine("")
.appendLine("")
.appendLine("Loading...")
.create()

task = object : ThreadUtils.SimpleTask<String>() {

override fun doInBackground(): String {
val sb: StringBuilder = StringBuilder();
sb.appendln("getIPv4Address: ${NetworkUtils.getIPAddress(true)}")
sb.appendln("getIPv6Address: ${NetworkUtils.getIPAddress(false)}")
sb.appendln("isWifiAvailable: ${NetworkUtils.isWifiAvailable()}")
sb.appendln("isAvailable: ${NetworkUtils.isAvailable()}")
sb.appendln("getBaiduDomainAddress: ${NetworkUtils.getDomainAddress("baidu.com")}")
return sb.toString()
}

override fun onSuccess(result: String) {
SpanUtils.with(networkAboutTv)
.append(getSpan())
.append(result)
.create()
}
}
ThreadUtils.executeByCached(task)
}

private fun getSpan(): SpannableStringBuilder {
return SpanUtils().appendLine("isConnected: " + NetworkUtils.isConnected())
.appendLine("getMobileDataEnabled: " + NetworkUtils.getMobileDataEnabled())
.appendLine("isMobileData: " + NetworkUtils.isMobileData())
.appendLine("is4G: " + NetworkUtils.is4G())
Expand All @@ -89,72 +112,23 @@ class NetworkActivity : CommonTitleActivity() {
.appendLine("getIpAddressByWifi: " + NetworkUtils.getIpAddressByWifi())
.appendLine("getGatewayByWifi: " + NetworkUtils.getGatewayByWifi())
.appendLine("getNetMaskByWifi: " + NetworkUtils.getNetMaskByWifi())
.append("getServerAddressByWifi: " + NetworkUtils.getServerAddressByWifi())
.appendLine("getServerAddressByWifi: " + NetworkUtils.getServerAddressByWifi())
.create()
cur += 5

ipV4AddressAsyncTask = NetworkUtils.getIPAddressAsync(true) { data ->
val num = count.get()
if (num >= cur - 5) {
spanSb = SpanUtils().appendLine(spanSb)
.append("getIPv4Address: $data")
.create()
networkAboutTv.text = spanSb
}
count.addAndGet(1)
}
}

ipV6AddressAsyncTask = NetworkUtils.getIPAddressAsync(false) { data ->
val num = count.get()
if (num >= cur - 5) {
spanSb = SpanUtils().appendLine(spanSb)
.append("getIPv6Address: $data")
.create()
networkAboutTv.text = spanSb
}
count.addAndGet(1)
}
override fun onDisconnected() {
ToastUtils.showLong("onDisconnected")
}

wifiAvailableAsyncTask = NetworkUtils.isWifiAvailableAsync { data ->
val num = count.get()
if (num >= cur - 5) {
spanSb = SpanUtils().appendLine(spanSb)
.append("isWifiAvailable: $data")
.create()
networkAboutTv.text = spanSb
}
count.addAndGet(1)
}
override fun onConnected(networkType: NetworkUtils.NetworkType) {

availableAsyncTask = NetworkUtils.isAvailableAsync { data ->
val num = count.get()
if (num >= cur - 5) {
spanSb = SpanUtils().appendLine(spanSb)
.append("isAvailable: $data")
.create()
networkAboutTv.text = spanSb
}
count.addAndGet(1)
}

domainAddressAsyncTask = NetworkUtils.getDomainAddressAsync("baidu.com") { data ->
val num = count.get()
if (num >= cur - 5) {
spanSb = SpanUtils().appendLine(spanSb)
.append("getBaiduDomainAddress: $data")
.create()
networkAboutTv.text = spanSb
}
count.addAndGet(1)
}
ToastUtils.showLong("onConnected: ${networkType.name}")
}

override fun onDestroy() {
ipV4AddressAsyncTask.cancel()
ipV6AddressAsyncTask.cancel()
wifiAvailableAsyncTask.cancel()
availableAsyncTask.cancel()
domainAddressAsyncTask.cancel()
task.cancel()
NetworkUtils.unregisterOnNetworkChangedListener(this)
super.onDestroy()
}
}
4 changes: 2 additions & 2 deletions lib/utilcode/README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

Gradle:
```groovy
implementation 'com.blankj:utilcode:1.25.2'
implementation 'com.blankj:utilcode:1.25.3'
// if u use AndroidX, use the following
implementation 'com.blankj:utilcodex:1.25.2'
implementation 'com.blankj:utilcodex:1.25.3'
```


Expand Down
4 changes: 2 additions & 2 deletions lib/utilcode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

Gradle:
```groovy
implementation 'com.blankj:utilcode:1.25.2'
implementation 'com.blankj:utilcode:1.25.3'
// if u use AndroidX, use the following
implementation 'com.blankj:utilcodex:1.25.2'
implementation 'com.blankj:utilcodex:1.25.3'
```


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private BarUtils() {
* @return the status bar's height
*/
public static int getStatusBarHeight() {
Resources resources = Resources.getSystem();
Resources resources = Utils.getApp().getResources();
int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
return resources.getDimensionPixelSize(resourceId);
}
Expand Down Expand Up @@ -453,7 +453,7 @@ private static void invokePanels(final String methodName) {
* @return the navigation bar's height
*/
public static int getNavBarHeight() {
Resources res = Resources.getSystem();
Resources res = Utils.getApp().getResources();
int resourceId = res.getIdentifier("navigation_bar_height", "dimen", "android");
if (resourceId != 0) {
return res.getDimensionPixelSize(resourceId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,13 @@ private boolean isShouldHideKeyboard(View v, MotionEvent event) {
}

private static int getStatusBarHeight() {
Resources resources = Resources.getSystem();
Resources resources = Utils.getApp().getResources();
int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
return resources.getDimensionPixelSize(resourceId);
}

private static int getNavBarHeight() {
Resources res = Resources.getSystem();
Resources res = Utils.getApp().getResources();
int resourceId = res.getIdentifier("navigation_bar_height", "dimen", "android");
if (resourceId != 0) {
return res.getDimensionPixelSize(resourceId);
Expand Down
Loading

0 comments on commit 5851344

Please sign in to comment.