diff options
| author | bt <bt@rctt.net> | 2026-05-04 01:22:33 +0200 |
|---|---|---|
| committer | bt <bt@rctt.net> | 2026-05-04 01:22:33 +0200 |
| commit | f4c07069c1604c45a6a57b30338bd5a32887e24a (patch) | |
| tree | aaa8bc1577721f63d3d4c80e47a3b2e7d3b496b7 | |
| parent | 5c282707a9c8183f165adabb478d4315afaf3676 (diff) | |
| download | netmon-f4c07069c1604c45a6a57b30338bd5a32887e24a.tar.gz netmon-f4c07069c1604c45a6a57b30338bd5a32887e24a.zip | |
Create "CellView"
| -rw-r--r-- | .idea/inspectionProfiles/Project_Default.xml | 10 | ||||
| -rw-r--r-- | app/build.gradle.kts | 2 | ||||
| -rw-r--r-- | app/src/main/java/net/rctt/netmon/CellView.kt | 57 | ||||
| -rw-r--r-- | app/src/main/java/net/rctt/netmon/MainActivity.kt | 72 | ||||
| -rw-r--r-- | app/src/main/res/layout/activity_main.xml | 2 | ||||
| -rw-r--r-- | app/src/main/res/layout/cell_view.xml | 38 | ||||
| -rw-r--r-- | app/src/main/res/values-night/styles.xml | 6 | ||||
| -rw-r--r-- | app/src/main/res/values/attrs_cell_view.xml | 8 | ||||
| -rw-r--r-- | app/src/main/res/values/colors.xml | 4 | ||||
| -rw-r--r-- | app/src/main/res/values/styles.xml | 6 |
10 files changed, 150 insertions, 55 deletions
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..146ab09 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,10 @@ +<component name="InspectionProjectProfileManager"> + <profile version="1.0"> + <option name="myName" value="Project Default" /> + <inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false"> + <option name="processCode" value="true" /> + <option name="processLiterals" value="true" /> + <option name="processComments" value="true" /> + </inspection_tool> + </profile> +</component>
\ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 21281d3..5daff8f 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -12,7 +12,7 @@ android { defaultConfig { applicationId = "net.rctt.netmon" - minSdk = 29 + minSdk = 30 targetSdk = 36 versionCode = 1 versionName = "1.0" diff --git a/app/src/main/java/net/rctt/netmon/CellView.kt b/app/src/main/java/net/rctt/netmon/CellView.kt new file mode 100644 index 0000000..3f00caf --- /dev/null +++ b/app/src/main/java/net/rctt/netmon/CellView.kt @@ -0,0 +1,57 @@ +package net.rctt.netmon + +import android.content.Context +import android.telephony.CellIdentityNr +import android.telephony.CellInfoGsm +import android.telephony.CellInfoLte +import android.telephony.CellInfoNr +import android.telephony.CellInfoTdscdma +import android.telephony.CellInfoWcdma +import android.view.LayoutInflater +import android.widget.TextView +import androidx.constraintlayout.widget.ConstraintLayout + + +class CellView : ConstraintLayout{ + var type: TextView + var id: TextView + var power: TextView + + constructor(ctx: Context) : super(ctx) { + LayoutInflater.from(context).inflate(R.layout.cell_view, this) + type = findViewById(R.id.type) + id = findViewById(R.id.id) + power = findViewById(R.id.power) + } + + fun set(cell: CellInfoGsm){ + type.text = "gsm" + id.text = cell.cellIdentity.cid.toString() + power.text = cell.cellSignalStrength.dbm.toString() + } + + fun set(cell: CellInfoLte){ + type.text = "lte" + id.text= cell.cellIdentity.ci.toString() + power.text = cell.cellSignalStrength.dbm.toString() + } + + fun set(cell: CellInfoNr){ + type.text = "nr" + var cellId = cell.cellIdentity as CellIdentityNr + id.text = cellId.nci.toString() + power.text = cell.cellSignalStrength.dbm.toString() + } + + fun set(cell: CellInfoTdscdma){ + type.text = "tdscdma" + id.text = cell.cellIdentity.cid.toString() + power.text = cell.cellSignalStrength.dbm.toString() + } + + fun set(cell: CellInfoWcdma){ + type.text = "wcmda" + id .text= cell.cellIdentity.cid.toString() + power.text = cell.cellSignalStrength.dbm.toString() + } +} diff --git a/app/src/main/java/net/rctt/netmon/MainActivity.kt b/app/src/main/java/net/rctt/netmon/MainActivity.kt index b3a6d37..9b6c7ec 100644 --- a/app/src/main/java/net/rctt/netmon/MainActivity.kt +++ b/app/src/main/java/net/rctt/netmon/MainActivity.kt @@ -11,10 +11,8 @@ import android.telephony.CellInfoLte import android.telephony.CellInfoNr import android.telephony.CellInfoTdscdma import android.telephony.CellInfoWcdma -import android.telephony.PhoneStateListener import android.telephony.TelephonyManager import android.telephony.TelephonyManager.CellInfoCallback -import android.util.Log import android.widget.LinearLayout import android.widget.TextView import androidx.activity.enableEdgeToEdge @@ -25,13 +23,10 @@ import androidx.core.view.ViewCompat import androidx.core.view.WindowInsetsCompat import java.text.SimpleDateFormat import java.util.Date -import java.util.Timer -import java.util.TimerTask - class MainActivity : AppCompatActivity() { lateinit var statusView: LinearLayout - lateinit var cellView: LinearLayout + lateinit var cellsList: LinearLayout lateinit var tel: TelephonyManager @@ -46,7 +41,7 @@ class MainActivity : AppCompatActivity() { } statusView = findViewById(R.id.statusView) - cellView = findViewById(R.id.cellView) + cellsList = findViewById(R.id.cellsList) val pLoc = ContextCompat.checkSelfPermission( applicationContext, @@ -66,55 +61,23 @@ class MainActivity : AppCompatActivity() { @RequiresPermission(Manifest.permission.ACCESS_FINE_LOCATION) override fun run() { refresh() - mainHandler.postDelayed(this, 100) + mainHandler.postDelayed(this, 1000) } }) } @RequiresPermission(Manifest.permission.ACCESS_FINE_LOCATION) fun refresh() { - log("refreshing") - tel.requestCellInfoUpdate(mainExecutor, object : CellInfoCallback() { @RequiresPermission(Manifest.permission.ACCESS_FINE_LOCATION) override fun onCellInfo(cellList: List<CellInfo?>) { - cellView.removeAllViews() - for (cell in cellList) { - when (cell) { - is CellInfoGsm -> { - logDetected("GSM") - } - - is CellInfoLte -> { - val id = cell.cellIdentity - if (id.ci == 2147483647) { - continue - } - - logDetected("LTE") - logCell("CID: ${id.ci}") - logCell("PCI: ${id.pci}") - logCell("TAC: ${id.tac}") - logCell("EARFCN ${id.earfcn}") - logCell("BANDWIDTH: ${id.bandwidth}") - logCell("RSRP: ${cell.cellSignalStrength.rsrp}") - logCell("DBM: ${cell.cellSignalStrength.dbm}") - logCell("STATUS: ${cell.cellConnectionStatus}") - logCell("") - } - - is CellInfoNr -> { - logDetected("NR") - } + cellsList.removeAllViews() - is CellInfoTdscdma -> { - logDetected("TDSCDMA") - } - - is CellInfoWcdma -> { - logDetected("WCDMA") - } + for (cell in cellList) { + if (cell == null) { + continue } + addCellView(cell) } } }) @@ -129,14 +92,17 @@ class MainActivity : AppCompatActivity() { statusView.addView(msg) } - fun logDetected(text: String) { - log("detected $text cell") - } + @SuppressLint("SetTextI18n") + fun addCellView(cell :CellInfo){ + val cellData = CellView(this) + when (cell) { + is CellInfoGsm -> cellData.set(cell) + is CellInfoLte -> cellData.set(cell) + is CellInfoNr -> cellData.set(cell) + is CellInfoTdscdma -> cellData.set(cell) + is CellInfoWcdma -> cellData.set(cell) + } - fun logCell(text: String) { - val msg = TextView(this) - msg.text = text - cellView.addView(msg) - Log.d("NETMON", text) + cellsList.addView(cellData) } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index e7c0e2c..f3a3014 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -28,7 +28,7 @@ android:layout_height="400dp"> <LinearLayout - android:id="@+id/cellView" + android:id="@+id/cellsList" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" /> diff --git a/app/src/main/res/layout/cell_view.xml b/app/src/main/res/layout/cell_view.xml new file mode 100644 index 0000000..4b58958 --- /dev/null +++ b/app/src/main/res/layout/cell_view.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="utf-8"?> +<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical"> + + <TextView + android:id="@+id/type" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="TextView" /> + + <TextView + android:id="@+id/id" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="TextView" /> + + <TextView + android:id="@+id/power" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="TextView" /> + + <View + android:id="@+id/divider2" + android:layout_width="match_parent" + android:layout_height="1dp" + android:background="?android:attr/listDivider" /> + </LinearLayout> + +</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file diff --git a/app/src/main/res/values-night/styles.xml b/app/src/main/res/values-night/styles.xml new file mode 100644 index 0000000..04e74eb --- /dev/null +++ b/app/src/main/res/values-night/styles.xml @@ -0,0 +1,6 @@ +<resources> + <style name="Widget.Theme.Netmon.MyView" parent=""> + <item name="android:background">@color/gray_600</item> + <item name="exampleColor">@color/light_blue_600</item> + </style> +</resources>
\ No newline at end of file diff --git a/app/src/main/res/values/attrs_cell_view.xml b/app/src/main/res/values/attrs_cell_view.xml new file mode 100644 index 0000000..2a0577c --- /dev/null +++ b/app/src/main/res/values/attrs_cell_view.xml @@ -0,0 +1,8 @@ +<resources> + <declare-styleable name="CellView"> + <attr name="exampleString" format="string" /> + <attr name="exampleDimension" format="dimension" /> + <attr name="exampleColor" format="color" /> + <attr name="exampleDrawable" format="color|reference" /> + </declare-styleable> +</resources>
\ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index c8524cd..e2337bb 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -2,4 +2,8 @@ <resources> <color name="black">#FF000000</color> <color name="white">#FFFFFFFF</color> + <color name="light_blue_400">#FF29B6F6</color> + <color name="light_blue_600">#FF039BE5</color> + <color name="gray_400">#FFBDBDBD</color> + <color name="gray_600">#FF757575</color> </resources>
\ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml new file mode 100644 index 0000000..5ed5dd0 --- /dev/null +++ b/app/src/main/res/values/styles.xml @@ -0,0 +1,6 @@ +<resources> + <style name="Widget.Theme.Netmon.MyView" parent=""> + <item name="android:background">@color/gray_400</item> + <item name="exampleColor">@color/light_blue_400</item> + </style> +</resources>
\ No newline at end of file |
