Initial commit

This commit is contained in:
Siniša Sovilj
2021-01-08 16:08:25 +01:00
commit cbb13d94a0
110 changed files with 9165 additions and 0 deletions

View File

@@ -0,0 +1,93 @@
/**
* Subproject: "ksdtoolkit-mobapp".
*
* @author [Siniša Sovilj](mailto:sinisa.sovilj@unipu.hr)
*/
plugins {
id("com.android.application")
/**
* !!! Problems if "kotlin-android" and "kotlin-android-extensions" are included with plugin "com.android.application"
* - SOLUTION: Use full names e.g. "org.jetbrains.kotlin.android.extensions", so that
* pluginManagement in settings.gradle.kts can recognize name.
*/
id("org.jetbrains.kotlin.android")
id("org.jetbrains.kotlin.android.extensions")
}
android {
compileSdkVersion(28)
buildToolsVersion("29.0.3")
defaultConfig {
applicationId = "hr.unipu.mobilesimulatorapp"
minSdkVersion(24)
targetSdkVersion(28)
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
testBuildType = "debug"
buildTypes {
getByName("debug") {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
getByName("release") {
isMinifyEnabled = true
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}
compileOptions {
setSourceCompatibility(JavaVersion.VERSION_1_8)
setTargetCompatibility(JavaVersion.VERSION_1_8)
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
}
dependencies {
implementation(project(path = ":ksdtoolkit-core", configuration = "default"))
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
api("com.google.android.material:material:1.3.0-alpha04")
implementation("com.github.PhilJay:MPAndroidChart:v3.1.0")
implementation("org.jetbrains.kotlin:kotlin-reflect:1.4.20")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.20")
implementation("androidx.core:core-ktx:1.3.2")
implementation("androidx.appcompat:appcompat:1.2.0")
implementation("androidx.constraintlayout:constraintlayout:2.0.4")
testImplementation("junit:junit:4.13.1")
testImplementation("org.mockito:mockito-core:3.1.0")
testImplementation("androidx.test:core:1.3.0")
androidTestImplementation("androidx.test:core:1.3.0")
androidTestImplementation("androidx.test:core-ktx:1.3.0")
androidTestImplementation("androidx.test:runner:1.3.0")
androidTestImplementation("androidx.test:rules:1.3.0")
androidTestImplementation("org.hamcrest:hamcrest-library:1.3")
androidTestImplementation("androidx.test.espresso:espresso-core:3.3.0")
androidTestImplementation("androidx.test.ext:junit:1.1.2")
androidTestImplementation("androidx.test.ext:junit-ktx:1.1.2")
androidTestImplementation("androidx.test.uiautomator:uiautomator:2.2.0")
}
tasks.register("appStart") {
dependsOn(":ksdtoolkit-mobapp:installDebug")
doLast {
exec {
commandLine("cmd", "/c", "adb", "shell", "am", "start", "-n", "hr.unipu.mobilesimulatorapp/.MobSimulatorApp")
}
}
}

View File

@@ -0,0 +1,21 @@
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official

View File

@@ -0,0 +1,106 @@
package hr.unipu.mobilesimulatorapp
import android.app.PendingIntent.getActivity
import android.content.pm.PackageManager
import androidx.core.content.ContextCompat.startActivity
import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.launchActivity
import androidx.test.ext.junit.rules.activityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import hr.unipu.ksdtoolkit.entities.Model
import hr.unipu.ksdtoolkit.models.ModelGenericSD
import hr.unipu.ksdtoolkit.models.ModelInnovationDiffusion
import hr.unipu.ksdtoolkit.simulations.Simulation
import org.hamcrest.CoreMatchers.*
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers
import org.junit.*
import org.junit.runner.RunWith
import org.slf4j.LoggerFactory
/**
* Instrumented test, which will execute on an Android device or emulator.
* - These tests have access to Instrumentation APIs, give you access to information such as the Context of the app
* you are testing, and let you control the app under test from your test code.
* - The Gradle build interprets these test source sets in the same manner as it does for your project's app source
* sets, which allows you to create tests based on build variants.
* - More info: https://developer.android.com/training/testing/unit-testing/instrumented-unit-tests
*/
@RunWith(AndroidJUnit4::class) // AndroidJUnit4 as default test runner.
class MobSimulatorInstrumentedTest {
@After fun launchApp() {
launchActivity<MobSimulatorApp>()
Thread.sleep(30000) // Automatic Testing closes app after tests are finished.
// Manual testing needs this pause for postponing the app closing.
}
private val model: Model
private var simulation: Simulation
init {
// Create generic model.
//model = ModelGenericSD()
model = ModelInnovationDiffusion()
// Create the simulation.
simulation = Simulation(model)
// Add results handlers.
MobSimulatorApp.simulation = simulation // Add simulation (and model) objects to app companion.
simulation.addSimulationEventListener(MobSimulator())
// Run the simulation
simulation.run()
}
/**
* Testing that simulation results are accessible from the mobile app.
*/
@Test fun mobSimulatorTest() {
// Initial test that testing framework is working.
// - Testing that context of the app under test is correct.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertThat(appContext.packageName, containsString("hr.unipu.mobilesimulatorapp"))
// Testing that model is accessible from the mobile app.
Assert.assertNotNull(model.name)
LoggerFactory.getLogger(javaClass).info("\n---modelTest---")
// Testing that simulation is accessible from the mobile app.
// - Testing that model is passed to simulation.
Assert.assertNotNull(MobSimulatorApp.simulation.model.name)
LoggerFactory.getLogger(javaClass).info("\n---simulationTest---")
// Testing that MobSimulatorApp contains all data series.
val entities = MobSimulatorApp.simulation.model.modelEntitiesKeys
for (entity in entities) {
Assert.assertThat(MobSimulatorApp.seriesName.toString(), containsString(entity))
}
LoggerFactory.getLogger(javaClass).info("---mobSimulatorTest---")
// Testing that MobSimulatorApp contains all simulation data values.
val values = simulation.model.modelEntitiesValues
for ((index, value) in values.withIndex()) {
Assert.assertThat(
MobSimulatorApp.seriesValue[index][0].y.toString().replace(",", ".").toDouble(),
`is`(Matchers.closeTo(value.replace(",", ".").toDouble(), 0.001))
)
}
}
}

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="hr.unipu.mobilesimulatorapp">
<application
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:theme="@style/Theme.MyApp">
<activity android:name=".MobSimulatorApp">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@@ -0,0 +1,27 @@
package hr.unipu.mobilesimulatorapp
import hr.unipu.ksdtoolkit.entities.Constant
import hr.unipu.ksdtoolkit.entities.Model
import hr.unipu.ksdtoolkit.simulations.ISimulationEventHandler
/**
* Class that implements the [SimulationEventListener] interface and controls the chart printing on Android.
*
* @author [Siniša Sovilj](mailto:sinisa.sovilj@unipu.hr)
*/
class MobSimulator : ISimulationEventHandler {
override fun simulationInitialized(model: Model) {
MobSimulatorApp.addConstants(model.entities.filterValues { it is Constant })
MobSimulatorApp.addSeriesNames(model.modelEntitiesKeys)
}
override fun timeStepCalculated(model: Model) {
MobSimulatorApp.addSeriesValues(model.modelEntitiesValues, model.currentTime)
}
override fun simulationFinished(model: Model) {
MobSimulatorApp.simulationFinished = true
}
}

View File

@@ -0,0 +1,248 @@
package hr.unipu.mobilesimulatorapp
import android.annotation.SuppressLint
import android.content.pm.ActivityInfo
import android.graphics.Color
import android.os.Bundle
import android.text.InputType
import android.util.TypedValue
import android.view.View
import android.view.ViewGroup
import android.widget.*
import androidx.appcompat.app.AppCompatActivity
import com.github.mikephil.charting.charts.LineChart
import com.github.mikephil.charting.components.YAxis
import com.github.mikephil.charting.data.Entry
import com.github.mikephil.charting.data.LineData
import com.github.mikephil.charting.data.LineDataSet
import com.github.mikephil.charting.highlight.Highlight
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet
import com.github.mikephil.charting.listener.OnChartValueSelectedListener
import hr.unipu.ksdtoolkit.entities.ModelEntity
import hr.unipu.ksdtoolkit.models.ModelInnovationDiffusion
import hr.unipu.ksdtoolkit.simulations.Simulation
import org.slf4j.LoggerFactory
/**
* Android mobile simulator app - for chart plotting and interactive simulation.
*
* @author [Siniša Sovilj](mailto:sinisa.sovilj@unipu.hr)
*/
class MobSimulatorApp : AppCompatActivity() {
init {
/**---Creating: model, simulation and run.---**/
// 1. Create a demo model.
val model = ModelInnovationDiffusion() // Or other models: ModelGenericSD(), ModelTestSpeed(), etc.
// 2. Create the simulation.
simulation = Simulation(model)
// 3. Add results handlers
simulation.addSimulationEventListener(MobSimulator())
// 4. Run simulation (so that all expressions are invoked for time=0).
simulation.run()
}
companion object {
public lateinit var simulation: Simulation
public var simulationFinished: Boolean = false
public var seriesName: ArrayList<String> = ArrayList()
public var seriesValue: ArrayList<ArrayList<Entry>> = ArrayList()
public var constantsName: ArrayList<String> = ArrayList()
public var constantsValue: ArrayList<Entry> = ArrayList()
public var time: ArrayList<Double> = ArrayList()
public val lineDataSets: ArrayList<LineDataSet> = ArrayList()
fun addSeriesNames(modelEntityNames: List<String>) {
seriesName = ArrayList()
seriesValue = ArrayList()
for (modelEntityName in modelEntityNames) {
seriesName.add(modelEntityName)
seriesValue.add(ArrayList<Entry>())
lineDataSets.add(LineDataSet(null, ""))
}
}
fun addSeriesValues(modelEntityValues: List<String>, currentTime: Double) {
time.add(currentTime)
for (i in 0..modelEntityValues.indices.last) {
val valueString = modelEntityValues[i]
val value = valueString.toFloat()
val entry = Entry(currentTime.toFloat(), value)
seriesValue[i].add(entry)
}
}
fun addConstants(modelEntityConstants: Map<String, ModelEntity>) {
constantsName = ArrayList()
constantsValue = ArrayList()
for (modelEntityConstant in modelEntityConstants) {
constantsName.add(modelEntityConstant.key)
val value = modelEntityConstant.value.currentValue.toFloat()
val entry = Entry(0f, value)
constantsValue.add(entry)
}
}
}
@SuppressLint("SourceLockedOrientationActivity")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
LoggerFactory.getLogger(javaClass).info("---onCreate() invoked.---")
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)
drawUI()
}
/**
* Creating layout programmatically (dynamically).
*/
private fun drawUI() {
LoggerFactory.getLogger(javaClass).info("---drawUI() invoked.---")
val rootLayout = ScrollView(this)
rootLayout.layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
val linearLayoutHorizontal = LinearLayout(this)
val linearLayoutHorizontalParams = LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
linearLayoutHorizontal.orientation = LinearLayout.HORIZONTAL
rootLayout.addView(linearLayoutHorizontal, linearLayoutHorizontalParams)
val linearLayoutVertical = LinearLayout(this)
linearLayoutVertical.id = R.id.insertPoint
linearLayoutVertical.layoutParams = LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
linearLayoutVertical.orientation = LinearLayout.VERTICAL
linearLayoutHorizontal.addView(linearLayoutVertical)
for (s in MobSimulatorApp.constantsName) {
val textView = TextView(this)
textView.layoutParams = LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
textView.text = s
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10F)
linearLayoutVertical.addView(textView)
val editText = EditText(this)
editText.layoutParams = LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
editText.setEms(5)
editText.inputType = InputType.TYPE_CLASS_NUMBER
val indexOfEntity = simulation.model.modelEntitiesKeys.indexOf(s)
editText.setText(simulation.model.modelEntitiesValues[indexOfEntity])
editText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10F)
editText.setOnFocusChangeListener(object : View.OnFocusChangeListener {
override fun onFocusChange(v: View?, hasFocus: Boolean) {
if (!hasFocus) {
val newValue = editText.text.toString().toDouble()
val modelVariableName = textView.text
simulation.model.entities[modelVariableName]?.equation = { newValue }
refreshUI()
}
}
})
linearLayoutVertical.addView(editText)
}
val lineChart = LineChart(this)
val myColorsPalette = intArrayOf(
Color.rgb(217, 80, 138),
Color.rgb(254, 149, 7),
Color.rgb(254, 247, 120),
Color.rgb(106, 167, 134),
Color.rgb(53, 194, 209),
Color.rgb(64, 89, 128),
Color.rgb(149, 165, 124),
Color.rgb(217, 184, 162),
Color.rgb(191, 134, 134),
Color.rgb(179, 48, 80)
)
val numberOfColorInPalette = myColorsPalette.size
for (i in seriesValue.indices) {
lineDataSets[i] = LineDataSet(seriesValue[i], seriesName[i])
lineDataSets[i].color = myColorsPalette[i.rem(numberOfColorInPalette)]
lineDataSets[i].circleHoleColor = myColorsPalette[i.rem(numberOfColorInPalette)]
lineDataSets[i].setCircleColor(myColorsPalette[i.rem(numberOfColorInPalette)])
lineDataSets[i].setDrawValues(false)
lineDataSets[i].setAxisDependency(YAxis.AxisDependency.LEFT)
}
lineChart.data = LineData(lineDataSets as List<ILineDataSet>?)
lineChart.setOnChartValueSelectedListener(object : OnChartValueSelectedListener {
override fun onValueSelected(e: Entry?, h: Highlight?) {
fun Float.format(digits: Int) = "%.${digits}f".format(this)
val tooltipText = "x=${e?.x?.format(2)}, y=${e?.y?.format(2)}"
LoggerFactory.getLogger(javaClass).info("---Value selected: $tooltipText---")
Toast.makeText(this@MobSimulatorApp, tooltipText, Toast.LENGTH_SHORT).show()
}
override fun onNothingSelected() { }
})
lineChart.layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 250F, this.resources.displayMetrics).toInt()
)
lineChart.id = R.id.lineChart
linearLayoutHorizontal.addView(lineChart)
setContentView(rootLayout);
}
private fun runSimulation() {
LoggerFactory.getLogger(javaClass).info("---runSimulation() invoked.---")
if (MobSimulatorApp.simulationFinished == false) {
val doesNotContainMobSimulatorListener = simulation.outputHandlers.filterIsInstance(MobSimulator()::class.java).isEmpty()
if (doesNotContainMobSimulatorListener) {
simulation.addSimulationEventListener(MobSimulator())
}
simulation.run()
}
}
private fun refreshUI() {
LoggerFactory.getLogger(javaClass).info("---refreshUI() invoked.---")
MobSimulatorApp.simulationFinished = false
runSimulation()
drawUI()
}
}

View File

@@ -0,0 +1,11 @@
.chart-series-line{
-fx-stroke-width: 1px;
-fx-stroke:#eedede;
-fx-effect: null;
}
.chart-vertical-grid-lines {
-fx-stroke: #cccccc;
}
.chart-horizontal-grid-lines {
-fx-stroke: #cccccc;
}

View File

@@ -0,0 +1,45 @@
.chart-plot-background {
-fx-border-color: black;
-fx-border-width: 4px;
/*-fx-border-insets: -2px;*/
-fx-background: white;
}
.axis:top {
-fx-border-color: transparent;
}
.axis:right {
-fx-border-color: transparent;
}
.axis:bottom {
-fx-border-color: transparent;
}
.axis:left {
-fx-border-color: transparent;
}
.chart-vertical-grid-lines {
-fx-stroke: transparent;
}
.chart-horizontal-grid-lines {
-fx-stroke: transparent;
}
.chart-legend {
-fx-background-color: white;
-fx-padding: 20px;
}
/*.chart-major-vertical-grid-lines {*/
/* -fx-stroke: #dddddd;*/
/* -fx-stroke-width: 1.0;*/
/*}*/
/*.chart-major-horizontal-grid-lines {*/
/* -fx-stroke: #dddddd;*/
/* -fx-stroke-width: 1.0;*/
/*}*/

View File

@@ -0,0 +1,21 @@
.chart {
-fx-padding: 10px;
-fx-background: white;
/*-fx-background-image: url("icon.png");*/
}
.chart-content {
-fx-padding: 30px;
}
.chart-legend {
-fx-background-color: transparent;
-fx-padding: 20px;
}
.chart-legend-item-symbol{
-fx-background-radius: 0;
}
.chart-legend-item{
-fx-text-fill: #191970;
}

View File

@@ -0,0 +1,30 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
<aapt:attr name="android:fillColor">
<gradient
android:endX="85.84757"
android:endY="92.4963"
android:startX="42.9492"
android:startY="49.59793"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
</vector>

View File

@@ -0,0 +1,170 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillColor="#3DDC84"
android:pathData="M0,0h108v108h-108z" />
<path
android:fillColor="#00000000"
android:pathData="M9,0L9,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,0L19,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,0L29,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,0L39,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,0L49,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,0L59,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,0L69,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,0L79,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M89,0L89,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M99,0L99,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,9L108,9"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,19L108,19"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,29L108,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,39L108,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,49L108,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,59L108,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,69L108,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,79L108,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,89L108,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,99L108,99"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,29L89,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,39L89,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,49L89,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,59L89,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,69L89,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,79L89,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,19L29,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,19L39,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,19L49,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,19L59,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,19L69,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,19L79,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
</vector>

View File

@@ -0,0 +1,115 @@
<?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"-->
<!-- tools:context=".MobViewerApp">-->
<LinearLayout
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"
tools:context=".MobSimulatorApp"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/insert_point"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- <com.google.android.material.textfield.TextInputLayout-->
<!-- style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"-->
<!-- android:layout_width="125dp"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:hint="CONTACT_RATE"-->
<!-- android:textSize="10sp">-->
<!-- <com.google.android.material.textfield.TextInputEditText-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:text="0.01"-->
<!-- android:textSize="10sp"/>-->
<!-- </com.google.android.material.textfield.TextInputLayout>-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CONTACT_RATE"
android:textSize="10sp"></TextView>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="5"
android:inputType="textPersonName"
android:text="100"
android:textSize="10sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ADVERTISING_EFFECTIVENESS"
android:textSize="10sp"></TextView>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="5"
android:inputType="textPersonName"
android:text="0.011"
android:textSize="10sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TOTAL_POPULATION"
android:textSize="10sp"></TextView>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="5"
android:inputType="textPersonName"
android:text="10000"
android:textSize="10sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ADOPTION_FRACTION"
android:textSize="10sp"></TextView>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="5"
android:inputType="textPersonName"
android:text="0.015"
android:textSize="10sp"/>
</LinearLayout>
<com.github.mikephil.charting.charts.LineChart
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/line_chart" />
</LinearLayout>
<!-- <TextView-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:text="Hello World!"-->
<!-- app:layout_constraintBottom_toBottomOf="parent"-->
<!-- app:layout_constraintLeft_toLeftOf="parent"-->
<!-- app:layout_constraintRight_toRightOf="parent"-->
<!-- app:layout_constraintTop_toTopOf="parent" />-->
<!--</androidx.constraintlayout.widget.ConstraintLayout>-->

View File

@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<!--<androidx.constraintlayout.widget.ConstraintLayout-->
<!-- xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"-->
<!-- android:layout_height="match_parent">-->
<LinearLayout
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"
tools:context=".MobSimulatorApp"
android:orientation="vertical">
<TextView
android:id="@+id/constantName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CONSTANT"
android:textSize="10sp">
</TextView>
<EditText
android:id="@+id/constantValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="5"
android:inputType="textPersonName"
android:text="0.0"
android:textSize="10sp"/>
</LinearLayout>
<!-- <com.google.android.material.textfield.TextInputLayout-->
<!-- xmlns:android="http://schemas.android.com/apk/res/android"-->
<!-- xmlns:tools="http://schemas.android.com/tools"-->
<!-- android:layout_width="125dp"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:id="@+id/textInputLayout"-->
<!-- android:textSize="6sp"-->
<!-- tools:ignore="MissingConstraints">-->
<!-- <com.google.android.material.textfield.TextInputEditText-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:textSize="12sp"-->
<!-- android:id="@+id/textInputEditText" />-->
<!-- </com.google.android.material.textfield.TextInputLayout>-->
<!--</androidx.constraintlayout.widget.ConstraintLayout>-->

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#6200EE</color>
<color name="colorPrimaryDark">#3700B3</color>
<color name="colorAccent">#03DAC5</color>
</resources>

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="activity_horizontal_margin">5px</dimen>
<dimen name="activity_vertical_margin">5px</dimen>
</resources>

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item type="id" name="insertPoint"/>
<item type="id" name="lineChart"/>
</resources>

View File

@@ -0,0 +1,4 @@
<resources>
<string name="app_name">MobSimulator</string>
<string name="input">input</string>
</resources>

View File

@@ -0,0 +1,36 @@
<resources>
<!-- Base application theme. -->
<!-- <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">-->
<!-- &lt;!&ndash; Customize your theme here. &ndash;&gt;-->
<!-- <item name="colorPrimary">@color/colorPrimary</item>-->
<!-- <item name="colorPrimaryDark">@color/colorPrimaryDark</item>-->
<!-- <item name="colorAccent">@color/colorAccent</item>-->
<!-- </style>-->
<style name="Theme.MyApp" parent="Theme.MaterialComponents.Light">
<item name="textAppearanceHeadline1">@style/TextAppearance.MaterialComponents.Headline1</item>
<item name="textAppearanceHeadline2">@style/TextAppearance.MaterialComponents.Headline2</item>
<item name="textAppearanceHeadline3">@style/TextAppearance.MaterialComponents.Headline3</item>
<item name="textAppearanceHeadline4">@style/TextAppearance.MaterialComponents.Headline4</item>
<item name="textAppearanceHeadline5">@style/TextAppearance.MaterialComponents.Headline5</item>
<item name="textAppearanceHeadline6">@style/TextAppearance.MaterialComponents.Headline6</item>
<item name="textAppearanceSubtitle1">@style/TextAppearance.MaterialComponents.Subtitle1</item>
<item name="textAppearanceSubtitle2">@style/TextAppearance.MaterialComponents.Subtitle2</item>
<item name="textAppearanceBody1">@style/TextAppearance.MaterialComponents.Body1</item>
<item name="textAppearanceBody2">@style/TextAppearance.MaterialComponents.Body2</item>
<item name="textAppearanceCaption">@style/TextAppearance.MaterialComponents.Caption</item>
<item name="textAppearanceButton">@style/TextAppearance.MaterialComponents.Button</item>
<item name="textAppearanceOverline">@style/TextAppearance.MaterialComponents.Overline</item>
</style>
<style name="TextAppearence.App.TextInputLayout" parent="@android:style/TextAppearance">
<item name="android:textSize">6sp</item>
</style>
</resources>

View File

@@ -0,0 +1,60 @@
package hr.unipu.mobilesimulatorapp
import hr.unipu.ksdtoolkit.entities.Model
import hr.unipu.ksdtoolkit.models.*
import hr.unipu.ksdtoolkit.simulations.Simulation
import org.hamcrest.CoreMatchers
import org.junit.Test
import org.junit.Assert.*
import org.slf4j.LoggerFactory
/**
* Local unit test, which will execute on local JVM.
* - Use these tests to minimize execution time when your tests have no Android framework dependencies or
* when you can mock the Android framework dependencies.
* - More info: https://developer.android.com/training/testing/unit-testing/local-unit-tests
*/
class MobSimulatorLocalUnitTest {
private val model: Model
private var simulation: Simulation
init {
// Create generic model.
model = ModelGenericSD()
// Create the simulation.
simulation = Simulation(model)
// Add results handlers.
MobSimulatorApp.simulation = simulation // Add simulation (and model) objects to app companion.
simulation.addSimulationEventListener(MobSimulator())
// Run the simulation
//simulation.run()
}
// Testing that model is accessible from mobile app.
@Test fun modelTest() {
LoggerFactory.getLogger(javaClass).info("\n---modelTest---")
// Testing that model is created.
assertThat(MobSimulatorApp.simulation.model.name, CoreMatchers.`is`("Generic SD Model"))
}
// Testing that simulation is accessible from mobile app.
@Test fun simulationTest() {
LoggerFactory.getLogger(javaClass).info("\n---simulationTest---")
// Testing that model is passed to simulation.
assertThat(MobSimulatorApp.simulation.model.name, CoreMatchers.`is`("Generic SD Model"))
}
}