Skip to content

Commit

Permalink
Android library for network monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Vishwajith-Shettigar committed Aug 1, 2024
1 parent 0172d78 commit 671b948
Show file tree
Hide file tree
Showing 20 changed files with 157 additions and 11 deletions.
17 changes: 17 additions & 0 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ dependencies {
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0'
implementation project(':networkmonitor')
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
package com.example.network_monitoring

import android.os.Build
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.annotation.RequiresApi
import com.example.networkmonitor.NetworkStatusView

class MainActivity : AppCompatActivity() {
private lateinit var networkStatusView: NetworkStatusView

@RequiresApi(Build.VERSION_CODES.Q)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
networkStatusView = findViewById(R.id.network_status_view)
networkStatusView.setFontFamily(R.font.airstrip)
networkStatusView.startMonitoring(this)
}

override fun onDestroy() {
super.onDestroy()
networkStatusView.onDestroy()
networkStatusView.unregisterNetworkMonitor()
}
}
}
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
android:orientation="vertical"
tools:context=".MainActivity">

<com.example.network_monitoring.NetworkStatusView
<com.example.networkmonitor.NetworkStatusView
android:id="@+id/network_status_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
4 changes: 4 additions & 0 deletions jitpack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
jdk:
- openjdk11
before_install:
- ./scripts/prepareJitpackEnvironment.sh
1 change: 1 addition & 0 deletions networkmonitor/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
57 changes: 57 additions & 0 deletions networkmonitor/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
id 'maven-publish'
}

android {
namespace 'com.example.networkmonitor'
compileSdk 33

defaultConfig {
minSdk 24
targetSdk 33

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
viewBinding {
enabled = true
}
}

dependencies {
implementation 'androidx.core:core-ktx:1.13.1'
implementation 'androidx.appcompat:appcompat:1.6.0'
implementation 'com.google.android.material:material:1.12.0'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0'
}

afterEvaluate {
publishing {
publications {
release(MavenPublication) {
from components.release
groupId = 'com.github.Vishwajith-Shettigar'
artifactId = 'networkmonitor'
version = '1.0.0'
}
}
}
}
Empty file.
21 changes: 21 additions & 0 deletions networkmonitor/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example.networkmonitor

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.example.networkmonitor.test", appContext.packageName)
}
}
5 changes: 5 additions & 0 deletions networkmonitor/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.network_monitoring
package com.example.networkmonitor

import android.content.Context
import android.net.ConnectivityManager
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.network_monitoring
package com.example.networkmonitor

import android.content.Context
import android.graphics.Color
Expand All @@ -13,7 +13,7 @@ import android.widget.LinearLayout
import androidx.core.content.res.ResourcesCompat
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.Observer
import com.example.network_monitoring.databinding.ViewNetworkStatusBinding
import com.example.networkmonitor.databinding.ViewNetworkStatusBinding
import kotlinx.coroutines.*

class NetworkStatusView @JvmOverloads constructor(
Expand Down Expand Up @@ -145,7 +145,7 @@ class NetworkStatusView @JvmOverloads constructor(
}
}

fun onDestroy() {
fun unregisterNetworkMonitor() {
networkMonitor.unregisterCallback()
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.networkmonitor

import org.junit.Test

import org.junit.Assert.*

/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ dependencyResolutionManagement {
}
rootProject.name = "Network_Monitoring"
include ':app'
include ':networkmonitor'

0 comments on commit 671b948

Please sign in to comment.