summaryrefslogtreecommitdiffstats
path: root/app/src/main/java
diff options
context:
space:
mode:
authorbt <bt@rctt.net>2026-05-04 01:22:33 +0200
committerbt <bt@rctt.net>2026-05-04 01:22:33 +0200
commitf4c07069c1604c45a6a57b30338bd5a32887e24a (patch)
treeaaa8bc1577721f63d3d4c80e47a3b2e7d3b496b7 /app/src/main/java
parent5c282707a9c8183f165adabb478d4315afaf3676 (diff)
downloadnetmon-f4c07069c1604c45a6a57b30338bd5a32887e24a.tar.gz
netmon-f4c07069c1604c45a6a57b30338bd5a32887e24a.zip
Create "CellView"
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/net/rctt/netmon/CellView.kt57
-rw-r--r--app/src/main/java/net/rctt/netmon/MainActivity.kt72
2 files changed, 76 insertions, 53 deletions
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)
}
}