summaryrefslogtreecommitdiffstats
path: root/app/src/main/java
diff options
context:
space:
mode:
authorbt <bt@rctt.net>2026-05-07 01:02:21 +0200
committerbt <bt@rctt.net>2026-05-07 01:02:21 +0200
commite81ce6af3d97a51e51f676f32e739d0f174323c7 (patch)
tree9a45cac8bdd1fefb82fcb01cf2221dcbe5a3b6f8 /app/src/main/java
parentf4c07069c1604c45a6a57b30338bd5a32887e24a (diff)
downloadnetmon-e81ce6af3d97a51e51f676f32e739d0f174323c7.tar.gz
netmon-e81ce6af3d97a51e51f676f32e739d0f174323c7.zip
Add power graph
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/net/rctt/netmon/CellView.kt102
-rw-r--r--app/src/main/java/net/rctt/netmon/MainActivity.kt64
2 files changed, 109 insertions, 57 deletions
diff --git a/app/src/main/java/net/rctt/netmon/CellView.kt b/app/src/main/java/net/rctt/netmon/CellView.kt
index 3f00caf..d991d48 100644
--- a/app/src/main/java/net/rctt/netmon/CellView.kt
+++ b/app/src/main/java/net/rctt/netmon/CellView.kt
@@ -1,57 +1,109 @@
package net.rctt.netmon
import android.content.Context
-import android.telephony.CellIdentityNr
+import android.graphics.Color
import android.telephony.CellInfoGsm
import android.telephony.CellInfoLte
import android.telephony.CellInfoNr
import android.telephony.CellInfoTdscdma
import android.telephony.CellInfoWcdma
+import android.util.Log
import android.view.LayoutInflater
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
-
+import com.androidplot.xy.LineAndPointFormatter
+import com.androidplot.xy.SimpleXYSeries
+import com.androidplot.xy.XYPlot
class CellView : ConstraintLayout{
- var type: TextView
- var id: TextView
- var power: TextView
+ var cellId: Number
+ var power: Int
+ var powerHistory: MutableList<Number>
+
+ var typeView: TextView
+ var idView: TextView
+ var powerView: TextView
+ var powerChartView: XYPlot
+ var powerChartSeries: SimpleXYSeries
+
+ constructor(ctx: Context, id: Number) : super(ctx) {
+ cellId = id
+ power = 0
- 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)
+ typeView = findViewById(R.id.type)
+ idView = findViewById(R.id.id)
+ powerView = findViewById(R.id.power)
+ powerChartView = findViewById(R.id.power_chart)
+ powerHistory = mutableListOf()
+ powerChartSeries= SimpleXYSeries(
+ powerHistory,
+ SimpleXYSeries.ArrayFormat.Y_VALS_ONLY,
+ "Series"
+ )
+ populatePowerChart()
+
+ idView.text = cellId.toString()
}
fun set(cell: CellInfoGsm){
- type.text = "gsm"
- id.text = cell.cellIdentity.cid.toString()
- power.text = cell.cellSignalStrength.dbm.toString()
+ power = cell.cellSignalStrength.dbm
+ typeView.text = "GSM"
+ powerView.text = power.toString()
}
fun set(cell: CellInfoLte){
- type.text = "lte"
- id.text= cell.cellIdentity.ci.toString()
- power.text = cell.cellSignalStrength.dbm.toString()
+ power = cell.cellSignalStrength.dbm
+ typeView.text = "LTE"
+ powerView.text = power.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()
+ power = cell.cellSignalStrength.dbm
+ typeView.text = "NR"
+ powerView.text = power.toString()
}
fun set(cell: CellInfoTdscdma){
- type.text = "tdscdma"
- id.text = cell.cellIdentity.cid.toString()
- power.text = cell.cellSignalStrength.dbm.toString()
+ power = cell.cellSignalStrength.dbm
+ typeView.text = "TDSCDMA"
+ powerView.text = power.toString()
}
fun set(cell: CellInfoWcdma){
- type.text = "wcmda"
- id .text= cell.cellIdentity.cid.toString()
- power.text = cell.cellSignalStrength.dbm.toString()
+ power = cell.cellSignalStrength.dbm
+ typeView.text = "WCDMA"
+ powerView.text = power.toString()
+ }
+
+ fun refresh() {
+ powerChartView.removeSeries(powerChartSeries)
+
+ powerHistory.removeAt(1)
+ powerHistory.add(power)
+
+ val seriesData = mutableListOf<Number>()
+
+ for (p in powerHistory) {
+ seriesData.add(p)
+ }
+
+ powerChartSeries = SimpleXYSeries(
+ seriesData,
+ SimpleXYSeries.ArrayFormat.Y_VALS_ONLY,
+ "Series"
+ )
+
+ val series1Format = LineAndPointFormatter(Color.RED, Color.GREEN, Color.BLUE, null)
+
+ Log.d("ASD", seriesData.toString())
+
+ powerChartView.addSeries(powerChartSeries, series1Format)
+ }
+
+ fun populatePowerChart() {
+ repeat(20) {
+ powerHistory.add(-100)
+ }
}
}
diff --git a/app/src/main/java/net/rctt/netmon/MainActivity.kt b/app/src/main/java/net/rctt/netmon/MainActivity.kt
index 9b6c7ec..bc0f136 100644
--- a/app/src/main/java/net/rctt/netmon/MainActivity.kt
+++ b/app/src/main/java/net/rctt/netmon/MainActivity.kt
@@ -5,6 +5,7 @@ import android.annotation.SuppressLint
import android.os.Bundle
import android.os.Handler
import android.os.Looper
+import android.telephony.CellIdentityNr
import android.telephony.CellInfo
import android.telephony.CellInfoGsm
import android.telephony.CellInfoLte
@@ -25,10 +26,9 @@ import java.text.SimpleDateFormat
import java.util.Date
class MainActivity : AppCompatActivity() {
- lateinit var statusView: LinearLayout
- lateinit var cellsList: LinearLayout
-
+ lateinit var cellsListView: LinearLayout
lateinit var tel: TelephonyManager
+ lateinit var cellsList: HashMap<Number, CellView>
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@@ -40,18 +40,8 @@ class MainActivity : AppCompatActivity() {
insets
}
- statusView = findViewById(R.id.statusView)
- cellsList = findViewById(R.id.cellsList)
-
- val pLoc = ContextCompat.checkSelfPermission(
- applicationContext,
- Manifest.permission.ACCESS_FINE_LOCATION
- )
- if (pLoc == -1) {
- log("Location permission required")
- return
- }
- log("Ready")
+ cellsList = HashMap()
+ cellsListView = findViewById(R.id.cellsList)
tel = getSystemService(TELEPHONY_SERVICE) as TelephonyManager
@@ -71,7 +61,7 @@ class MainActivity : AppCompatActivity() {
tel.requestCellInfoUpdate(mainExecutor, object : CellInfoCallback() {
@RequiresPermission(Manifest.permission.ACCESS_FINE_LOCATION)
override fun onCellInfo(cellList: List<CellInfo?>) {
- cellsList.removeAllViews()
+ cellsListView.removeAllViews()
for (cell in cellList) {
if (cell == null) {
@@ -83,26 +73,36 @@ class MainActivity : AppCompatActivity() {
})
}
- @SuppressLint("SimpleDateFormat", "SetTextI18n")
- fun log(text: String) {
- val sdf = SimpleDateFormat("hh:mm:ss")
- val date = sdf.format(Date())
- val msg = TextView(this)
- msg.text = "$date $text"
- statusView.addView(msg)
- }
-
@SuppressLint("SetTextI18n")
fun addCellView(cell :CellInfo){
- val cellData = CellView(this)
+ val id = getCellId(cell)
+ var cellView = cellsList[id]
+ if (cellView == null) {
+ cellView = CellView(this, id)
+ cellsList[id] = cellView
+ }
+
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)
+ is CellInfoGsm -> cellView.set(cell)
+ is CellInfoLte -> cellView.set(cell)
+ is CellInfoNr -> cellView.set(cell)
+ is CellInfoTdscdma -> cellView.set(cell)
+ is CellInfoWcdma -> cellView.set(cell)
}
- cellsList.addView(cellData)
+ cellView.refresh()
+ cellsListView.addView(cellView)
}
}
+
+fun getCellId(cell: CellInfo) : Number {
+ when (cell) {
+ is CellInfoGsm -> return cell.cellIdentity.cid
+ is CellInfoLte -> return cell.cellIdentity.ci
+ is CellInfoNr -> return (cell.cellIdentity as CellIdentityNr).nci
+ is CellInfoTdscdma -> return cell.cellIdentity.cid
+ is CellInfoWcdma -> return cell.cellIdentity.cid
+ }
+
+ return 0
+} \ No newline at end of file