Skip to content
This repository was archived by the owner on Nov 5, 2023. It is now read-only.

Commit 0e9dcfc

Browse files
author
Mike
committed
[CheckNetwork] Added CheckNetwork Class, Improvements on sample app, Added information on ReadMe
1 parent 18aef30 commit 0e9dcfc

File tree

7 files changed

+86
-19
lines changed

7 files changed

+86
-19
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,15 @@
1-
# zenith
1+
# Zenith
2+
3+
### All in one utility tool for Android (more details soon!)
4+
5+
Gradle
6+
7+
```
8+
repositories {
9+
maven { url "https://jitpack.io" }
10+
}
11+
```
12+
13+
```
14+
compile 'com.github.ekimual:zenith:1.0.0'
15+
```

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,11 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.mikelau">
44

5-
<uses-permission android:name="android.permission.CAMERA" />
6-
7-
<uses-feature android:name="android.hardware.camera" />
8-
<uses-feature android:name="android.hardware.camera.autofocus" />
9-
10-
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
11-
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
5+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
6+
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
127

138
<application
9+
android:name=".ApplicationController"
1410
android:allowBackup="false"
1511
android:icon="@mipmap/ic_launcher"
1612
android:label="@string/app_name"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.mikelau
2+
3+
import android.app.Application
4+
import com.mikelau.zenith.utils.DebugLog
5+
6+
class ApplicationController : Application() {
7+
8+
override fun onCreate() {
9+
super.onCreate()
10+
11+
// Initialize DebugLog
12+
DebugLog.isProduction = false
13+
}
14+
15+
}

app/src/main/java/com/mikelau/MainActivity.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,23 @@ package com.mikelau
22

33
import android.os.Bundle
44
import android.support.v7.app.AppCompatActivity
5+
import com.mikelau.zenith.utils.CheckNetwork
6+
import com.mikelau.zenith.utils.DebugLog
57

68
class MainActivity : AppCompatActivity() {
79

810
override fun onCreate(savedInstanceState: Bundle?) {
911
super.onCreate(savedInstanceState)
1012
setContentView(R.layout.activity_main)
1113

14+
// DebugLog Test
15+
DebugLog.showError(this, "HELLO")
16+
DebugLog.showError(this, "HEY")
17+
DebugLog.showError(this, "HI")
18+
19+
// CheckNetwork Test
20+
CheckNetwork.isInternetAvailable(this)
21+
1222
}
1323

1424
}

zenith/src/main/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
22
package="com.mikelau.zenith">
3+
4+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
35
<application
46
android:label="@string/app_name"
57
android:supportsRtl="true">
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.mikelau.zenith.utils
2+
3+
import android.content.Context
4+
import android.net.ConnectivityManager
5+
import android.net.NetworkInfo
6+
7+
object CheckNetwork {
8+
9+
private var mNetwork: NetworkInfo? = null
10+
11+
// Check if network is available and accessible
12+
fun isInternetAvailable(context: Context): Boolean {
13+
try {
14+
mNetwork = (context
15+
.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager)
16+
.activeNetworkInfo
17+
} catch (e: Exception) {
18+
DebugLog.showError(context, "Check Network: " + e.message)
19+
}
20+
21+
return if (mNetwork == null) {
22+
DebugLog.showError(context, "Network Connection Not Available")
23+
false
24+
} else {
25+
if (mNetwork!!.isConnected) {
26+
DebugLog.showError(context, "Network Connection Available")
27+
true
28+
} else {
29+
DebugLog.showError(context, "Network Connection Not Available")
30+
true
31+
}
32+
}
33+
}
34+
35+
}

zenith/src/main/java/com/mikelau/zenith/utils/DebugLog.kt

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
package com.mikelau.zenith.utils
22

3-
43
import android.content.Context
54
import android.util.Log
65

76
/**
8-
* Created by Mike on 7/26/2016.
9-
*
107
* Simple logger for checking, testing and monitoring (only enabled in non-production build)
118
*/
129
object DebugLog {
1310

14-
var isProduction: Boolean = false
11+
var isProduction: Boolean = true
1512
/**
1613
* Logger to print any message in error for testing
1714
* @param con Current context
@@ -40,16 +37,14 @@ object DebugLog {
4037
fun showException(con: Context?, s: Class<*>?, ex: Throwable) {
4138
if (!isProduction) {
4239
try {
43-
if (con != null)
44-
Log.e(":: " + con.javaClass.simpleName + ".class ::", "\n", ex)
45-
else if (s != null)
46-
Log.e(":: " + s.simpleName + ".class ::", "\n", ex)
47-
else
48-
Log.e(":: DebugLog.class ::", "\n", ex)
40+
when {
41+
con != null -> Log.e(":: " + con.javaClass.simpleName + ".class ::", "\n", ex)
42+
s != null -> Log.e(":: " + s.simpleName + ".class ::", "\n", ex)
43+
else -> Log.e(":: DebugLog.class ::", "\n", ex)
44+
}
4945
} catch (e: Exception) {
5046
Log.e(":: DebugLog.class ::", "\n", e)
5147
}
52-
5348
}
5449
}
5550

0 commit comments

Comments
 (0)