diff options
| -rw-r--r-- | app/build.gradle.kts | 1 | ||||
| -rw-r--r-- | app/src/main/java/net/rctt/netmon/CellView.kt | 102 | ||||
| -rw-r--r-- | app/src/main/java/net/rctt/netmon/MainActivity.kt | 64 | ||||
| -rw-r--r-- | app/src/main/res/layout/activity_main.xml | 30 | ||||
| -rw-r--r-- | app/src/main/res/layout/cell_view.xml | 88 | ||||
| -rw-r--r-- | app/src/main/res/values-night/themes.xml | 4 |
6 files changed, 186 insertions, 103 deletions
diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 5daff8f..a5348d6 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -50,4 +50,5 @@ dependencies { testImplementation(libs.junit) androidTestImplementation(libs.androidx.junit) androidTestImplementation(libs.androidx.espresso.core) + implementation("com.androidplot:androidplot-core:1.5.11") }
\ No newline at end of file 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 diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index f3a3014..993e933 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -9,12 +9,13 @@ tools:context=".MainActivity"> <LinearLayout - android:layout_width="match_parent" + android:layout_width="0dp" android:layout_height="match_parent" android:orientation="vertical" + app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="parent" > + app:layout_constraintTop_toTopOf="parent"> <TextView android:id="@+id/haederCell" @@ -25,7 +26,7 @@ <ScrollView android:layout_width="match_parent" - android:layout_height="400dp"> + android:layout_height="wrap_content"> <LinearLayout android:id="@+id/cellsList" @@ -34,29 +35,6 @@ android:orientation="vertical" /> </ScrollView> - <View - android:id="@+id/divider" - android:layout_width="match_parent" - android:layout_height="1dp" - android:background="?android:attr/listDivider" /> - - <TextView - android:id="@+id/headerStatus" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:text="Status" - android:textSize="20sp" /> - - <ScrollView - android:layout_width="match_parent" - android:layout_height="match_parent"> - - <LinearLayout - android:id="@+id/statusView" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:orientation="vertical"/> - </ScrollView> </LinearLayout> </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file diff --git a/app/src/main/res/layout/cell_view.xml b/app/src/main/res/layout/cell_view.xml index 4b58958..7361930 100644 --- a/app/src/main/res/layout/cell_view.xml +++ b/app/src/main/res/layout/cell_view.xml @@ -1,32 +1,86 @@ <?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:ap="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" - android:layout_width="match_parent" - android:layout_height="match_parent"> + android:layout_width="wrap_content" + android:layout_height="wrap_content" + tools:ignore="HardcodedText"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> - <TextView - android:id="@+id/type" - android:layout_width="wrap_content" + <LinearLayout + android:layout_width="match_parent" android:layout_height="wrap_content" - android:text="TextView" /> + android:orientation="horizontal"> - <TextView - android:id="@+id/id" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:text="TextView" /> + <LinearLayout + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginEnd="10dp" + android:orientation="vertical"> - <TextView - android:id="@+id/power" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:text="TextView" /> + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Type" /> + + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Id" /> + + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Power" /> + + </LinearLayout> + + <LinearLayout + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:orientation="vertical"> + + <TextView + android:id="@+id/type" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="type" /> + + <TextView + android:id="@+id/id" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="id" /> + + <TextView + android:id="@+id/power" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="power" /> + + </LinearLayout> + + <com.androidplot.xy.XYPlot + style="@style/APDefacto.Dark" + android:id="@+id/power_chart" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:layout_marginHorizontal="10dp" + ap:graphHeightMode="fill" + ap:graphWidthMode="fill" + ap:legendVisible="false" + ap:graphMarginTop="0dp" + ap:graphMarginBottom="-20dp" + ap:graphMarginLeft="-20dp" + ap:graphMarginRight="10dp" + ap:lineLabels="" + /> + + </LinearLayout> <View android:id="@+id/divider2" diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml index 01829d8..9b38736 100644 --- a/app/src/main/res/values-night/themes.xml +++ b/app/src/main/res/values-night/themes.xml @@ -1,7 +1,5 @@ <resources xmlns:tools="http://schemas.android.com/tools"> - <!-- Base application theme. --> <style name="Base.Theme.Netmon" parent="Theme.Material3.DayNight.NoActionBar"> - <!-- Customize your dark theme here. --> - <!-- <item name="colorPrimary">@color/my_dark_primary</item> --> + <item name="android:windowBackground">#FF000000</item> </style> </resources>
\ No newline at end of file |
