Skip to content

Commit

Permalink
Feat: salt editor for trace
Browse files Browse the repository at this point in the history
  • Loading branch information
zhufucdev committed Jan 1, 2023
1 parent 34e784b commit dc48d5c
Show file tree
Hide file tree
Showing 41 changed files with 2,121 additions and 341 deletions.
115 changes: 0 additions & 115 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,16 @@ dependencies {
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'net.edwardday.serialization:kprefs:0.11.0'
implementation 'net.edwardday.serialization:kprefs:0.12.0'
implementation 'com.github.Redempt:Crunch:1.1.2'
implementation 'com.google.guava:guava:31.1-android'
// Xposed
implementation "com.highcapable.yukihookapi:api:${yuki_version}"
implementation 'io.ktor:ktor-client-core-jvm:2.2.1'
implementation 'io.ktor:ktor-client-android-jvm:2.2.1'
implementation 'io.ktor:ktor-client-serialization-jvm:2.2.1'
implementation 'io.ktor:ktor-client-content-negotiation:2.2.1'
implementation 'io.ktor:ktor-serialization-kotlinx-json:2.2.1'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_ui_version"
compileOnly 'de.robv.android.xposed:api:82'
debugImplementation "androidx.compose.ui:ui-tooling:$compose_ui_version"
Expand All @@ -103,11 +110,6 @@ dependencies {
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
implementation 'com.aventrix.jnanoid:jnanoid:2.0.0'
// Ktor
implementation "io.ktor:ktor-client-core:$ktor_version"
implementation "io.ktor:ktor-client-android:$ktor_version"
implementation "io.ktor:ktor-client-serialization:$ktor_version"
implementation "io.ktor:ktor-client-content-negotiation:$ktor_version"
implementation "io.ktor:ktor-serialization-kotlinx-json:$ktor_version"

// AMap SDK
implementation 'com.amap.api:3dmap:9.5.0'
Expand Down
79 changes: 24 additions & 55 deletions app/src/main/java/com/zhufucdev/motion_emulator/Utility.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import android.content.pm.ApplicationInfo
import android.content.res.Configuration
import android.content.res.Resources
import android.util.TypedValue
import android.view.View
import androidx.annotation.AttrRes
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.compose.ui.geometry.Offset
import androidx.navigation.NavController
import com.amap.api.maps.AMap
import com.amap.api.maps.MapView
import com.amap.api.maps.AMapUtils
import com.amap.api.maps.MapsInitializer
import com.amap.api.maps.model.LatLng
import com.amap.api.maps.model.LatLngBounds
Expand All @@ -20,6 +20,7 @@ import com.zhufucdev.motion_emulator.hook_frontend.Emulation
import com.zhufucdev.motion_emulator.hook_frontend.EmulationRef
import io.ktor.client.*
import io.ktor.client.call.*
import io.ktor.client.call.body
import io.ktor.client.engine.android.*
import io.ktor.client.plugins.*
import io.ktor.client.plugins.contentnegotiation.*
Expand Down Expand Up @@ -79,7 +80,18 @@ suspend fun getAddress(location: LatLng): String? {
fun Double.toFixed(n: Int): String {
val df = DecimalFormat(buildString {
append("#.")
for (i in 0..n) {
repeat(n) {
append("#")
}
})
df.roundingMode = RoundingMode.HALF_UP
return df.format(this)
}

fun Float.toFixed(n: Int): String {
val df = DecimalFormat(buildString {
append("#.")
repeat(n) {
append("#")
}
})
Expand Down Expand Up @@ -155,19 +167,18 @@ operator fun FloatArray.times(other: Float): FloatArray {
}

fun Point.toLatLng(): LatLng = LatLng(latitude, longitude)
fun Vector2D.toLatLng(): LatLng = LatLng(x, y)
fun LatLng.toPoint(): Point = Point(latitude, longitude)

fun skipAmapFuckingLicense(context: Context) {
MapsInitializer.updatePrivacyShow(context, true, true)
MapsInitializer.updatePrivacyAgree(context, true)
}

/**
* Treat [Point] as a 2d vector and calculate
* the length
*/
fun Point.lenTo(other: Point): Double =
sqrt((latitude - other.latitude).pow(2) + (longitude - other.longitude).pow(2))
fun Vector2D.lenTo(other: Vector2D): Double =
sqrt((x - other.x).pow(2) + (y - other.y).pow(2))

fun Vector2D.toPoint() = Point(x, y)

fun AMap.unifyTheme(resources: Resources) {
mapType = if (isDarkModeEnabled(resources)) AMap.MAP_TYPE_NIGHT else AMap.MAP_TYPE_NORMAL
Expand All @@ -193,51 +204,6 @@ fun List<Point>.bounds(): LatLngBounds =
operator fun LatLng.minus(other: LatLng) =
LatLng(latitude - other.latitude, longitude - other.longitude)

object MapFixUtil {
private const val pi = 3.14159265358979324
private const val a = 6378245.0
private const val ee = 0.00669342162296594323
fun transform(wgLat: Double, wgLon: Double): DoubleArray {
val latlng = DoubleArray(2)
if (outOfChina(wgLat, wgLon)) {
latlng[0] = wgLat
latlng[1] = wgLon
return latlng
}
var dLat = transformLat(wgLon - 105.0, wgLat - 35.0)
var dLon = transformLon(wgLon - 105.0, wgLat - 35.0)
val radLat = wgLat / 180.0 * pi
var magic = sin(radLat)
magic = 1 - ee * magic * magic
val sqrtMagic = sqrt(magic)
dLat = dLat * 180.0 / (a * (1 - ee) / (magic * sqrtMagic) * pi)
dLon = dLon * 180.0 / (a / sqrtMagic * cos(radLat) * pi)
latlng[0] = wgLat - dLat
latlng[1] = wgLon - dLon
return latlng
}

private fun outOfChina(lat: Double, lon: Double): Boolean {
return if (lon < 72.004 || lon > 137.8347) true else lat < 0.8293 || lat > 55.8271
}

private fun transformLat(x: Double, y: Double): Double {
var ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * sqrt(abs(x))
ret += (20.0 * sin(6.0 * x * pi) + 20.0 * sin(2.0 * x * pi)) * 2.0 / 3.0
ret += (20.0 * sin(y * pi) + 40.0 * sin(y / 3.0 * pi)) * 2.0 / 3.0
ret += (160.0 * sin(y / 12.0 * pi) + 320 * sin(y * pi / 30.0)) * 2.0 / 3.0
return ret
}

private fun transformLon(x: Double, y: Double): Double {
var ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * sqrt(abs(x))
ret += (20.0 * sin(6.0 * x * pi) + 20.0 * sin(2.0 * x * pi)) * 2.0 / 3.0
ret += (20.0 * sin(x * pi) + 40.0 * sin(x / 3.0 * pi)) * 2.0 / 3.0
ret += (150.0 * sin(x / 12.0 * pi) + 300.0 * sin(x / 30.0 * pi)) * 2.0 / 3.0
return ret
}
}

fun AppCompatActivity.initializeToolbar(
toolbar: Toolbar,
navController: NavController? = null
Expand All @@ -254,8 +220,11 @@ fun Emulation.ref() =
EmulationRef(trace.id, motion.ref(), cells.ref(), velocity, repeat, satelliteCount)

fun <T : Referable> Box<T>.ref() =
when(this) {
when (this) {
is EmptyBox<T> -> EMPTY_REF
is BlockBox<T> -> BLOCK_REF
else -> value?.id ?: NULL_REF
}

fun Vector2D.toOffset() = Offset(x.toFloat(), y.toFloat())
fun Offset.toVector2d() = Vector2D(x * 1.0, y * 1.0)
5 changes: 5 additions & 0 deletions app/src/main/java/com/zhufucdev/motion_emulator/data/Box.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,8 @@ inline fun <reified T> Box<T>.encodeToString(): String =
is BlockBox -> BLOCK_REF
else -> value?.let { Json.encodeToString(serializer<T>(), it) } ?: "null"
}


class MutableBox<T>(var value: T)

fun <T> T.mutbox() = MutableBox(this)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.zhufucdev.motion_emulator.data

/**
* Array of [Vector2D]s, forming a closed shape
* on a plane or something similar, like the earth.
*/
interface ClosedShape {
val points: List<Vector2D>
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,15 @@ abstract class DataStore<T : Referable> {
data[record.id] = record
}
}
data.keys.forEach {
if (it !in existingIds) {
data.remove(it)
}
val removed = data.keys.filter { it !in existingIds }
removed.forEach {
data.remove(it)
}
}
}

fun store(record: T) {
if (data.containsKey(record.id)) return
fun store(record: T, overwrite: Boolean = false) {
if (data.containsKey(record.id) && !overwrite) return

File(rootDir, record.storeName).outputStream().use {
Json.encodeToStream(dataSerializer, record, it)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
package com.zhufucdev.motion_emulator.data

import android.content.Context
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.decodeFromStream
import kotlinx.serialization.json.encodeToStream
import kotlinx.serialization.serializer
import java.io.File

/**
* Basic motion record unit
Expand Down
Loading

0 comments on commit dc48d5c

Please sign in to comment.