1 Commits
Author SHA1 Message Date
茂之钳 4ca9f6c011 sensTools fix-build: working APK 2026-05-25 02:54:45 +00:00
41 changed files with 230 additions and 1691 deletions
-51
View File
@@ -1,51 +0,0 @@
name: Build APK
on:
push:
branches: [master]
tags: [v*]
pull_request:
branches: [master]
jobs:
build:
runs-on: ubuntu-latest
container:
image: ubuntu:22.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install JDK and Android SDK
run: |
apt-get update -qq
apt-get install -y -qq openjdk-17-jdk wget unzip
mkdir -p /opt/android-sdk
cd /opt/android-sdk
wget -q https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip -O cmdline-tools.zip
unzip -q cmdline-tools.zip
mkdir -p cmdline-tools/latest
mv cmdline-tools/* cmdline-tools/latest/ 2>/dev/null || true
yes | cmdline-tools/latest/bin/sdkmanager --sdk_root=/opt/android-sdk "platforms;android-34" "build-tools;34.0.0" 2>&1 | tail -5
echo "ANDROID_HOME=/opt/android-sdk" >> $GITHUB_ENV
- name: Build APK
working-directory: android
run: |
export ANDROID_HOME=/opt/android-sdk
chmod +x gradlew
./gradlew assembleDebug --no-daemon
- name: Archive APK
uses: actions/upload-artifact@v4
with:
name: sensTools-apk
path: android/app/build/outputs/apk/debug/app-debug.apk
- name: Upload to Release
if: startsWith(github.ref, refs/tags/v)
env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
run: |
curl -s -X POST "https://hdtime.space/api/v1/repos/hm/senstools/releases/$(curl -s https://hdtime.space/api/v1/repos/hm/senstools/releases/tag/${GITHUB_REF#refs/tags/} | python3 -c "import sys,json; print(json.load(sys.stdin)[id])")/assets" \
-H "Authorization: token ${GITEA_TOKEN}" \
-F "attachment=@android/app/build/outputs/apk/debug/app-debug.apk;type=application/vnd.android.package-archive"
+58 -4
View File
@@ -1,7 +1,61 @@
.gradle/
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
# 虚拟环境
venv/
ENV/
env/
.venv/
# IDE
.idea/
.vscode/
*.swp
*.swo
*~
# 移动平台
*.apk
*.aab
local.properties
.idea/
*.iml
*.ipa
*.app
*.xcarchive
*.xcodeproj
*.xcworkspace
# 构建输出
*.o
*.obj
*.dll
*.exe
# 数据文件
*.csv
*.json
*.log
logs/
# 临时文件
.DS_Store
Thumbs.db
*.tmp
.cache/
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
View File
@@ -0,0 +1,2 @@
#Mon May 25 02:38:34 GMT 2026
gradle.version=9.4.1
Binary file not shown.
View File
+24 -60
View File
@@ -1,78 +1,42 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id "com.android.application"
id "org.jetbrains.kotlin.android"
}
android {
namespace 'com.senstools'
namespace "com.senstools"
compileSdk 34
defaultConfig {
applicationId "com.senstools"
minSdk 26
targetSdk 34
versionCode 1
versionName "1.0.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '17'
}
buildFeatures {
viewBinding true
}
kotlinOptions { jvmTarget = "17" }
buildFeatures { viewBinding true }
}
dependencies {
// AndroidX Core
implementation 'androidx.core:core-ktx:1.12.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'com.google.android.material:material:1.11.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
// Navigation
implementation 'androidx.navigation:navigation-fragment-ktx:2.7.6'
implementation 'androidx.navigation:navigation-ui-ktx:2.7.6'
// Lifecycle
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.7.0'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.7.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.7.0'
// Coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3'
// Room Database
implementation 'androidx.room:room-runtime:2.6.1'
implementation 'androidx.room:room-ktx:2.6.1'
annotationProcessor 'androidx.room:room-compiler:2.6.1'
// Maps
implementation 'com.google.android.gms:play-services-maps:18.2.0'
implementation 'com.google.android.gms:play-services-location:21.1.0'
// Charts
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
// DataStore
implementation 'androidx.datastore:datastore-preferences:1.0.0'
// Testing
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
implementation "androidx.core:core-ktx:1.12.0"
implementation "androidx.appcompat:appcompat:1.6.1"
implementation "com.google.android.material:material:1.12.0"
implementation "androidx.constraintlayout:constraintlayout:2.1.4"
implementation "androidx.navigation:navigation-fragment-ktx:2.7.6"
implementation "androidx.navigation:navigation-ui-ktx:2.7.6"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.7.0"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.7.0"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.7.0"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3"
implementation "androidx.room:room-runtime:2.6.1"
implementation "androidx.room:room-ktx:2.6.1"
annotationProcessor "androidx.room:room-compiler:2.6.1"
implementation "com.google.android.gms:play-services-maps:18.2.0"
implementation "com.google.android.gms:play-services-location:21.1.0"
implementation "com.github.PhilJay:MPAndroidChart:v3.1.0"
implementation "androidx.datastore:datastore-preferences:1.0.0"
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
}
+2 -13
View File
@@ -37,14 +37,14 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.sensTools"
android:theme="@style/Theme.AppCompat.DayNight.DarkActionBar"
tools:targetApi="31">
<activity
android:name=".presentation.ui.MainActivity"
android:exported="true"
android:screenOrientation="portrait"
android:theme="@style/Theme.sensTools">
android:theme="@style/Theme.AppCompat.DayNight.DarkActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
@@ -62,17 +62,6 @@
android:name="com.google.android.geo.API_KEY"
android:value="YOUR_API_KEY_HERE" />
<!-- FileProvider for sharing exported files -->
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
</application>
</manifest>
@@ -5,103 +5,36 @@ import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.app.Service
import android.content.Context
import android.content.Intent
import android.os.Binder
import android.os.Build
import android.os.IBinder
import androidx.core.app.NotificationCompat
import com.senstools.R
import com.senstools.domain.model.AttitudeData
import com.senstools.domain.model.GPSData
import com.senstools.domain.model.SensorData
import com.senstools.domain.repository.DataRepository
import com.senstools.domain.sensor.SensorCollector
import com.senstools.domain.sensor.SensorDataCallback
import com.senstools.presentation.ui.MainActivity
import java.io.File
class DataCollectionService : Service(), SensorDataCallback {
class DataCollectionService : Service() {
private val binder = LocalBinder()
private lateinit var sensorCollector: SensorCollector
private lateinit var dataRepository: DataRepository
private var currentFile: File? = null
private var serviceCallback: ServiceCallback? = null
interface ServiceCallback {
fun onGPSData(gps: GPSData)
fun onSensorData(sensor: SensorData)
fun onAttitudeData(attitude: AttitudeData)
fun onRecordingStateChanged(isRecording: Boolean)
}
inner class LocalBinder : Binder() {
fun getService(): DataCollectionService = this@DataCollectionService
}
override fun onCreate() {
super.onCreate()
createNotificationChannel()
sensorCollector = SensorCollector()
dataRepository = DataRepository(filesDir)
}
override fun onBind(intent: Intent): IBinder {
return binder
}
override fun onCreate() {
super.onCreate()
createNotificationChannel()
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
startForeground(NOTIFICATION_ID, createNotification())
return START_STICKY
}
fun startCollecting(callback: ServiceCallback) {
serviceCallback = callback
currentFile = dataRepository.startNewSession()
sensorCollector.startCollecting(this, this)
callback.onRecordingStateChanged(true)
updateNotification(true)
}
fun stopCollecting() {
sensorCollector.stopCollecting()
currentFile?.let { dataRepository.closeSession(it) }
currentFile = null
serviceCallback?.onRecordingStateChanged(false)
serviceCallback = null
updateNotification(false)
stopSelf()
}
fun isCollecting(): Boolean = sensorCollector.isCollecting()
// SensorDataCallback implementation
override fun onGPSData(gps: GPSData) {
currentFile?.let { dataRepository.writeGPSRecord(it, gps) }
serviceCallback?.onGPSData(gps)
}
override fun onSensorData(sensor: SensorData) {
currentFile?.let { dataRepository.writeSensorRecord(it, sensor) }
serviceCallback?.onSensorData(sensor)
}
override fun onAttitudeData(attitude: AttitudeData) {
serviceCallback?.onAttitudeData(attitude)
}
private fun updateNotification(isRecording: Boolean) {
val notification = if (isRecording) {
createNotification()
} else {
createNotification()
}
val manager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
manager.notify(NOTIFICATION_ID, notification)
}
private fun createNotificationChannel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel(
@@ -124,24 +57,15 @@ class DataCollectionService : Service(), SensorDataCallback {
PendingIntent.FLAG_IMMUTABLE
)
val text = if (isCollecting()) "Recording sensor data..." else "sensTools ready"
return NotificationCompat.Builder(this, CHANNEL_ID)
.setContentTitle("sensTools")
.setContentText(text)
.setContentText("Recording sensor data...")
.setSmallIcon(R.drawable.ic_dashboard)
.setContentIntent(pendingIntent)
.setOngoing(true)
.build()
}
override fun onDestroy() {
if (isCollecting()) {
stopCollecting()
}
super.onDestroy()
}
companion object {
const val CHANNEL_ID = "data_collection_channel"
const val NOTIFICATION_ID = 1
@@ -1,382 +0,0 @@
package com.senstools.domain.repository
import com.senstools.domain.model.GPSData
import com.senstools.domain.model.SensorData
import java.io.BufferedOutputStream
import java.io.File
import java.io.FileOutputStream
import java.io.FileReader
import java.io.FileWriter
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
class DataRepository(private val baseDir: File) {
private var currentOutputStream: BufferedOutputStream? = null
private var currentFile: File? = null
data class DataFileInfo(
val name: String,
val path: String,
val size: Long,
val lastModified: Long
)
fun startNewSession(): File {
val dir = File(baseDir, "senstools_data")
if (!dir.exists()) {
dir.mkdirs()
}
val dateFormat = SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.getDefault())
val fileName = "${dateFormat.format(Date())}.bin"
val file = File(dir, fileName)
currentFile = file
currentOutputStream = BufferedOutputStream(FileOutputStream(file))
return file
}
fun writeGPSRecord(file: File, gps: GPSData) {
val stream = getStreamForFile(file) ?: return
val buffer = ByteArray(1 + 8 + 8 + 8 + 4 + 4 + 4 + 4)
var offset = 0
// 1 byte type marker (0x01 for GPS)
buffer[offset++] = 0x01
// 8 bytes timestamp (long)
writeLong(buffer, offset, gps.timestamp)
offset += 8
// 8 bytes longitude (double)
writeDouble(buffer, offset, gps.longitude)
offset += 8
// 8 bytes latitude (double)
writeDouble(buffer, offset, gps.latitude)
offset += 8
// 4 bytes altitude (float)
writeFloat(buffer, offset, gps.altitude.toFloat())
offset += 4
// 4 bytes speed (float)
writeFloat(buffer, offset, gps.speed)
offset += 4
// 4 bytes bearing (float)
writeFloat(buffer, offset, gps.bearing)
offset += 4
// 4 bytes satellites (int)
writeInt(buffer, offset, gps.satellites)
offset += 4
stream.write(buffer, 0, offset)
}
fun writeSensorRecord(file: File, sensor: SensorData) {
val stream = getStreamForFile(file) ?: return
val buffer = ByteArray(1 + 8 + 4*3 + 4*3 + 4*3 + 4 + 4 + 4)
var offset = 0
// 1 byte type marker (0x02 for sensor)
buffer[offset++] = 0x02
// 8 bytes timestamp
writeLong(buffer, offset, sensor.timestamp)
offset += 8
// 4*3 = 12 bytes accelerometer
writeFloat(buffer, offset, sensor.accelerometer[0])
offset += 4
writeFloat(buffer, offset, sensor.accelerometer[1])
offset += 4
writeFloat(buffer, offset, sensor.accelerometer[2])
offset += 4
// 4*3 = 12 bytes gyroscope
writeFloat(buffer, offset, sensor.gyroscope[0])
offset += 4
writeFloat(buffer, offset, sensor.gyroscope[1])
offset += 4
writeFloat(buffer, offset, sensor.gyroscope[2])
offset += 4
// 4*3 = 12 bytes magnetometer
writeFloat(buffer, offset, sensor.magnetometer[0])
offset += 4
writeFloat(buffer, offset, sensor.magnetometer[1])
offset += 4
writeFloat(buffer, offset, sensor.magnetometer[2])
offset += 4
// 4 bytes pressureAltitude
writeFloat(buffer, offset, sensor.pressureAltitude)
offset += 4
// 4 bytes temperature
writeFloat(buffer, offset, sensor.temperature)
offset += 4
// 4 bytes humidity
writeFloat(buffer, offset, sensor.humidity)
offset += 4
stream.write(buffer, 0, offset)
}
fun closeSession(file: File) {
if (file == currentFile) {
currentOutputStream?.close()
currentOutputStream = null
currentFile = null
}
}
fun listDataFiles(): List<DataFileInfo> {
val dir = File(baseDir, "senstools_data")
if (!dir.exists()) return emptyList()
return dir.listFiles { f -> f.extension == "bin" }
?.sortedByDescending { it.lastModified() }
?.map { file ->
DataFileInfo(
name = file.name,
path = file.absolutePath,
size = file.length(),
lastModified = file.lastModified()
)
} ?: emptyList()
}
fun deleteFile(name: String): Boolean {
val dir = File(baseDir, "senstools_data")
val file = File(dir, name)
return if (file.exists()) file.delete() else false
}
fun deleteAll(): Boolean {
val dir = File(baseDir, "senstools_data")
if (!dir.exists()) return true
var success = true
dir.listFiles()?.forEach { file ->
if (!file.delete()) success = false
}
return success
}
fun exportToCSV(binFilePath: String, outputPath: String): Boolean {
return try {
val file = File(binFilePath)
if (!file.exists()) return false
val records = parseBinaryFile(file)
FileWriter(File(outputPath)).use { writer ->
// Write CSV header
writer.write("timestamp,type,value1,value2,value3,value4,value5,value6,value7,value8,value9,value10\n")
for (record in records) {
when (record.type) {
0x01 -> { // GPS
writer.write("${record.timestamp},GPS," +
"${record.d1},${record.d2},${record.f1}," +
"${record.f2},${record.f3},${record.i1},,,\n")
}
0x02 -> { // Sensor
writer.write("${record.timestamp},SENSOR," +
"${record.f1},${record.f2},${record.f3}," +
"${record.f4},${record.f5},${record.f6}," +
"${record.f7},${record.f8},${record.f9},${record.f10}\n")
}
}
}
}
true
} catch (e: Exception) {
e.printStackTrace()
false
}
}
fun exportToJSON(binFilePath: String, outputPath: String): Boolean {
return try {
val file = File(binFilePath)
if (!file.exists()) return false
val records = parseBinaryFile(file)
val gpsBuilder = StringBuilder()
val sensorBuilder = StringBuilder()
var gpsCount = 0
var sensorCount = 0
for (record in records) {
when (record.type) {
0x01 -> {
if (gpsCount > 0) gpsBuilder.append(",")
gpsBuilder.append("""{"timestamp":${record.timestamp},"longitude":${record.d1},"latitude":${record.d2},"altitude":${record.f1},"speed":${record.f2},"bearing":${record.f3},"satellites":${record.i1}}""")
gpsCount++
}
0x02 -> {
if (sensorCount > 0) sensorBuilder.append(",")
sensorBuilder.append("""{"timestamp":${record.timestamp},"accelX":${record.f1},"accelY":${record.f2},"accelZ":${record.f3},"gyroX":${record.f4},"gyroY":${record.f5},"gyroZ":${record.f6},"magX":${record.f7},"magY":${record.f8},"magZ":${record.f9},"pressureAltitude":${record.f10},"temperature":${record.f11},"humidity":${record.f12}}""")
sensorCount++
}
}
}
val json = """{"gps_records":[$gpsBuilder],"sensor_records":[$sensorBuilder]}"""
FileWriter(File(outputPath)).use { it.write(json) }
true
} catch (e: Exception) {
e.printStackTrace()
false
}
}
// Parsed binary record helper
private data class BinaryRecord(
val type: Int,
val timestamp: Long,
val d1: Double = 0.0,
val d2: Double = 0.0,
val f1: Float = 0f,
val f2: Float = 0f,
val f3: Float = 0f,
val f4: Float = 0f,
val f5: Float = 0f,
val f6: Float = 0f,
val f7: Float = 0f,
val f8: Float = 0f,
val f9: Float = 0f,
val f10: Float = 0f,
val f11: Float = 0f,
val f12: Float = 0f,
val i1: Int = 0
)
private fun parseBinaryFile(file: File): List<BinaryRecord> {
val records = mutableListOf<BinaryRecord>()
val bytes = file.readBytes()
var offset = 0
while (offset < bytes.size) {
if (offset + 1 > bytes.size) break
val type = bytes[offset].toInt() and 0xFF
offset++
when (type) {
0x01 -> {
if (offset + 36 > bytes.size) break
val timestamp = readLong(bytes, offset); offset += 8
val lon = readDouble(bytes, offset); offset += 8
val lat = readDouble(bytes, offset); offset += 8
val alt = readFloat(bytes, offset); offset += 4
val speed = readFloat(bytes, offset); offset += 4
val bearing = readFloat(bytes, offset); offset += 4
val satellites = readInt(bytes, offset); offset += 4
records.add(BinaryRecord(
type = type, timestamp = timestamp,
d1 = lon, d2 = lat,
f1 = alt, f2 = speed, f3 = bearing,
i1 = satellites
))
}
0x02 -> {
if (offset + 52 > bytes.size) break
val timestamp = readLong(bytes, offset); offset += 8
val ax = readFloat(bytes, offset); offset += 4
val ay = readFloat(bytes, offset); offset += 4
val az = readFloat(bytes, offset); offset += 4
val gx = readFloat(bytes, offset); offset += 4
val gy = readFloat(bytes, offset); offset += 4
val gz = readFloat(bytes, offset); offset += 4
val mx = readFloat(bytes, offset); offset += 4
val my = readFloat(bytes, offset); offset += 4
val mz = readFloat(bytes, offset); offset += 4
val pa = readFloat(bytes, offset); offset += 4
val temp = readFloat(bytes, offset); offset += 4
val hum = readFloat(bytes, offset); offset += 4
records.add(BinaryRecord(
type = type, timestamp = timestamp,
f1 = ax, f2 = ay, f3 = az,
f4 = gx, f5 = gy, f6 = gz,
f7 = mx, f8 = my, f9 = mz,
f10 = pa, f11 = temp, f12 = hum
))
}
else -> break // Unknown type, stop parsing
}
}
return records
}
private fun getStreamForFile(file: File): BufferedOutputStream? {
return if (file == currentFile && currentOutputStream != null) {
currentOutputStream
} else {
// Open a new stream for an existing file (appending)
try {
BufferedOutputStream(FileOutputStream(file, true))
} catch (e: Exception) {
null
}
}
}
companion object {
private fun writeLong(buffer: ByteArray, offset: Int, value: Long) {
buffer[offset + 0] = (value shr 56).toByte()
buffer[offset + 1] = (value shr 48).toByte()
buffer[offset + 2] = (value shr 40).toByte()
buffer[offset + 3] = (value shr 32).toByte()
buffer[offset + 4] = (value shr 24).toByte()
buffer[offset + 5] = (value shr 16).toByte()
buffer[offset + 6] = (value shr 8).toByte()
buffer[offset + 7] = (value).toByte()
}
private fun writeDouble(buffer: ByteArray, offset: Int, value: Double) {
writeLong(buffer, offset, java.lang.Double.doubleToRawLongBits(value))
}
private fun writeFloat(buffer: ByteArray, offset: Int, value: Float) {
writeInt(buffer, offset, java.lang.Float.floatToRawIntBits(value))
}
private fun writeInt(buffer: ByteArray, offset: Int, value: Int) {
buffer[offset + 0] = (value shr 24).toByte()
buffer[offset + 1] = (value shr 16).toByte()
buffer[offset + 2] = (value shr 8).toByte()
buffer[offset + 3] = (value).toByte()
}
private fun readLong(bytes: ByteArray, offset: Int): Long {
return ((bytes[offset].toLong() and 0xFF) shl 56) or
((bytes[offset + 1].toLong() and 0xFF) shl 48) or
((bytes[offset + 2].toLong() and 0xFF) shl 40) or
((bytes[offset + 3].toLong() and 0xFF) shl 32) or
((bytes[offset + 4].toLong() and 0xFF) shl 24) or
((bytes[offset + 5].toLong() and 0xFF) shl 16) or
((bytes[offset + 6].toLong() and 0xFF) shl 8) or
(bytes[offset + 7].toLong() and 0xFF)
}
private fun readDouble(bytes: ByteArray, offset: Int): Double {
return java.lang.Double.longBitsToDouble(readLong(bytes, offset))
}
private fun readFloat(bytes: ByteArray, offset: Int): Float {
return java.lang.Float.intBitsToFloat(readInt(bytes, offset))
}
private fun readInt(bytes: ByteArray, offset: Int): Int {
return ((bytes[offset].toInt() and 0xFF) shl 24) or
((bytes[offset + 1].toInt() and 0xFF) shl 16) or
((bytes[offset + 2].toInt() and 0xFF) shl 8) or
(bytes[offset + 3].toInt() and 0xFF)
}
}
}
@@ -1,234 +0,0 @@
package com.senstools.domain.sensor
import android.Manifest
import android.content.Context
import android.content.pm.PackageManager
import android.hardware.Sensor
import android.hardware.SensorEvent
import android.hardware.SensorEventListener
import android.hardware.SensorManager
import android.location.Location
import android.location.LocationListener
import android.location.LocationManager
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import androidx.core.content.ContextCompat
import com.senstools.domain.model.AttitudeData
import com.senstools.domain.model.GPSData
import com.senstools.domain.model.SensorData
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
interface SensorDataCallback {
fun onGPSData(gps: GPSData)
fun onSensorData(sensor: SensorData)
fun onAttitudeData(attitude: AttitudeData)
}
class SensorCollector {
private var sensorManager: SensorManager? = null
private var locationManager: LocationManager? = null
private var callback: SensorDataCallback? = null
private var collecting = false
// Sensors
private var accelerometer: android.hardware.Sensor? = null
private var gyroscope: android.hardware.Sensor? = null
private var magnetometer: android.hardware.Sensor? = null
private var pressureSensor: android.hardware.Sensor? = null
private var temperatureSensor: android.hardware.Sensor? = null
private var humiditySensor: android.hardware.Sensor? = null
// Sensor fusion for attitude
private val rotationMatrix = FloatArray(9)
private val orientationAngles = FloatArray(3)
private val gravity = FloatArray(3)
private val geomagnetic = FloatArray(3)
private val accelValues = FloatArray(3)
private val gyroValues = FloatArray(3)
private val magValues = FloatArray(3)
private val sensorEventListener = object : SensorEventListener {
override fun onSensorChanged(event: SensorEvent) {
val timestamp = System.currentTimeMillis()
when (event.sensor.type) {
Sensor.TYPE_ACCELEROMETER -> {
System.arraycopy(event.values, 0, accelValues, 0, 3)
computeAttitude(timestamp)
emitSensorData(timestamp)
}
Sensor.TYPE_GYROSCOPE -> {
System.arraycopy(event.values, 0, gyroValues, 0, 3)
}
Sensor.TYPE_MAGNETIC_FIELD -> {
System.arraycopy(event.values, 0, magValues, 0, 3)
System.arraycopy(event.values, 0, geomagnetic, 0, 3)
}
Sensor.TYPE_PRESSURE -> {
// Pressure to altitude approximation: h = 44330 * (1 - (p/101325)^(1/5.255))
val pressure = event.values[0]
emitSensorDataWithPressure(timestamp, pressure)
}
Sensor.TYPE_AMBIENT_TEMPERATURE -> {
emitSensorDataWithTemp(timestamp, event.values[0])
}
Sensor.TYPE_RELATIVE_HUMIDITY -> {
emitSensorDataWithHumidity(timestamp, event.values[0])
}
}
}
override fun onAccuracyChanged(sensor: android.hardware.Sensor, accuracy: Int) {}
}
// Tracking variables for incremental sensor emission
private var lastAccelTimestamp = 0L
private var lastPressureTimestamp = 0L
private var lastTempTimestamp = 0L
private var lastHumidityTimestamp = 0L
private var pendingPressure = 0f
private var pendingTemp = 0f
private var pendingHumidity = 0f
private var hasPendingPressure = false
private var hasPendingTemp = false
private var hasPendingHumidity = false
private val locationListener = object : LocationListener {
override fun onLocationChanged(location: Location) {
val timestamp = System.currentTimeMillis()
val dateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault())
val now = Date()
val gps = GPSData(
timestamp = timestamp,
longitude = location.longitude,
latitude = location.latitude,
altitude = location.altitude.toDouble(),
speed = location.speed,
bearing = location.bearing,
satellites = 0, // Not available from LocationListener directly
time = String.format("%tT", now),
date = String.format("%tF", now)
)
callback?.onGPSData(gps)
}
override fun onStatusChanged(provider: String?, status: Int, extras: Bundle?) {}
override fun onProviderEnabled(provider: String) {}
override fun onProviderDisabled(provider: String) {}
}
fun startCollecting(context: Context, cb: SensorDataCallback) {
if (collecting) return
callback = cb
collecting = true
sensorManager = context.getSystemService(Context.SENSOR_SERVICE) as SensorManager
locationManager = context.getSystemService(Context.LOCATION_SERVICE) as LocationManager
// Register sensors
sensorManager?.let { sm ->
accelerometer = sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER)
gyroscope = sm.getDefaultSensor(Sensor.TYPE_GYROSCOPE)
magnetometer = sm.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD)
pressureSensor = sm.getDefaultSensor(Sensor.TYPE_PRESSURE)
temperatureSensor = sm.getDefaultSensor(Sensor.TYPE_AMBIENT_TEMPERATURE)
humiditySensor = sm.getDefaultSensor(Sensor.TYPE_RELATIVE_HUMIDITY)
// High-rate sensors: SENSOR_DELAY_GAME (~100Hz)
accelerometer?.let { sm.registerListener(sensorEventListener, it, SensorManager.SENSOR_DELAY_GAME) }
gyroscope?.let { sm.registerListener(sensorEventListener, it, SensorManager.SENSOR_DELAY_GAME) }
magnetometer?.let { sm.registerListener(sensorEventListener, it, SensorManager.SENSOR_DELAY_GAME) }
// Low-rate sensors: SENSOR_DELAY_NORMAL (~10Hz)
pressureSensor?.let { sm.registerListener(sensorEventListener, it, SensorManager.SENSOR_DELAY_NORMAL) }
temperatureSensor?.let { sm.registerListener(sensorEventListener, it, SensorManager.SENSOR_DELAY_NORMAL) }
humiditySensor?.let { sm.registerListener(sensorEventListener, it, SensorManager.SENSOR_DELAY_NORMAL) }
}
// Register GPS
if (ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED
) {
locationManager?.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
200L, // 5Hz
0f,
locationListener,
Looper.getMainLooper()
)
}
}
fun stopCollecting() {
if (!collecting) return
collecting = false
sensorManager?.unregisterListener(sensorEventListener)
locationManager?.removeUpdates(locationListener)
sensorManager = null
locationManager = null
callback = null
}
fun isCollecting(): Boolean = collecting
private fun computeAttitude(timestamp: Long) {
// Simple attitude estimation from accelerometer + magnetometer
val g = FloatArray(3)
val m = FloatArray(3)
System.arraycopy(accelValues, 0, g, 0, 3)
System.arraycopy(magValues, 0, m, 0, 3)
if (!SensorManager.getRotationMatrix(rotationMatrix, null, g, m)) return
SensorManager.getOrientation(rotationMatrix, orientationAngles)
val pitch = Math.toDegrees(orientationAngles[1].toDouble()).toFloat()
val roll = Math.toDegrees(orientationAngles[2].toDouble()).toFloat()
val yaw = Math.toDegrees(orientationAngles[0].toDouble()).toFloat()
callback?.onAttitudeData(
AttitudeData(
pitch = pitch,
roll = roll,
yaw = yaw,
timestamp = timestamp
)
)
}
private fun emitSensorData(timestamp: Long) {
lastAccelTimestamp = timestamp
val dateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault())
val now = Date()
callback?.onSensorData(
SensorData(
timestamp = timestamp,
accelerometer = accelValues.clone(),
gyroscope = gyroValues.clone(),
magnetometer = magValues.clone(),
pressureAltitude = if (hasPendingPressure) pendingPressure else 0f,
temperature = if (hasPendingTemp) pendingTemp else 0f,
humidity = if (hasPendingHumidity) pendingHumidity else 0f,
time = String.format("%tT", now),
date = String.format("%tF", now)
)
)
}
private fun emitSensorDataWithPressure(timestamp: Long, pressure: Float) {
hasPendingPressure = true
pendingPressure = 44330f * (1f - Math.pow((pressure / 101325f).toDouble(), 1.0 / 5.255).toFloat())
}
private fun emitSensorDataWithTemp(timestamp: Long, temp: Float) {
hasPendingTemp = true
pendingTemp = temp
}
private fun emitSensorDataWithHumidity(timestamp: Long, humidity: Float) {
hasPendingHumidity = true
pendingHumidity = humidity
}
}
@@ -29,13 +29,6 @@ class DashboardFragment : Fragment() {
super.onViewCreated(view, savedInstanceState)
setupObservers()
setupListeners()
viewModel.bindService(requireContext())
}
override fun onDestroyView() {
viewModel.unbindService(requireContext())
super.onDestroyView()
_binding = null
}
private fun setupObservers() {
@@ -45,7 +38,7 @@ class DashboardFragment : Fragment() {
tvLatitude.text = String.format("%.8f", gps.latitude)
tvAltitude.text = String.format("%.2f m", gps.altitude)
tvSpeed.text = String.format("%.2f m/s", gps.speed)
tvBearing.text = String.format("%.2f", gps.bearing)
tvBearing.text = String.format("%.2f¡ã", gps.bearing)
tvSatellites.text = gps.satellites.toString()
}
}
@@ -62,7 +55,7 @@ class DashboardFragment : Fragment() {
tvMagY.text = String.format("%.2f", sensor.magnetometer[1])
tvMagZ.text = String.format("%.2f", sensor.magnetometer[2])
tvPressure.text = String.format("%.2f m", sensor.pressureAltitude)
tvTemperature.text = String.format("%.2fC", sensor.temperature)
tvTemperature.text = String.format("%.2f¡ãC", sensor.temperature)
tvHumidity.text = String.format("%.1f%%", sensor.humidity)
}
}
@@ -70,16 +63,11 @@ class DashboardFragment : Fragment() {
viewModel.attitudeData.observe(viewLifecycleOwner) { attitude ->
binding.apply {
artificialHorizon.setAttitude(attitude.pitch, attitude.roll)
tvPitch.text = String.format("%.2f", attitude.pitch)
tvRoll.text = String.format("%.2f", attitude.roll)
tvYaw.text = String.format("%.2f", attitude.yaw)
tvPitch.text = String.format("%.2f¡ã", attitude.pitch)
tvRoll.text = String.format("%.2f¡ã", attitude.roll)
tvYaw.text = String.format("%.2f¡ã", attitude.yaw)
}
}
viewModel.isRecording.observe(viewLifecycleOwner) { recording ->
binding.btnStartRecording.isEnabled = !recording
binding.btnStopRecording.isEnabled = recording
}
}
private fun setupListeners() {
@@ -91,4 +79,9 @@ class DashboardFragment : Fragment() {
viewModel.stopRecording()
}
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}
@@ -7,10 +7,8 @@ import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.senstools.databinding.FragmentDataBinding
import com.senstools.presentation.adapter.DataFileAdapter
import com.senstools.presentation.viewmodel.DataFile
import com.senstools.presentation.viewmodel.DataViewModel
class DataFragment : Fragment() {
@@ -40,8 +38,8 @@ class DataFragment : Fragment() {
private fun setupRecyclerView() {
adapter = DataFileAdapter(
onItemClick = { file -> viewModel.openFile(file) },
onExportClick = { file -> showExportDialog(file) },
onDeleteClick = { file -> showDeleteConfirmDialog(file) }
onExportClick = { file -> viewModel.exportFile(file) },
onDeleteClick = { file -> viewModel.deleteFile(file) }
)
binding.recyclerView.layoutManager = LinearLayoutManager(requireContext())
binding.recyclerView.adapter = adapter
@@ -51,17 +49,6 @@ class DataFragment : Fragment() {
viewModel.dataFiles.observe(viewLifecycleOwner) { files ->
adapter.submitList(files)
}
viewModel.isExporting.observe(viewLifecycleOwner) { exporting ->
binding.swipeRefresh.isEnabled = !exporting
}
viewModel.exportResult.observe(viewLifecycleOwner) { result ->
result?.let {
showToast(it)
viewModel.clearExportResult()
}
}
}
private fun setupListeners() {
@@ -71,34 +58,6 @@ class DataFragment : Fragment() {
}
}
private fun showExportDialog(file: DataFile) {
val options = arrayOf("Export to CSV", "Export to JSON")
MaterialAlertDialogBuilder(requireContext())
.setTitle("Export: " + file.name)
.setItems(options) { _, which ->
when (which) {
0 -> viewModel.exportToCSV(file)
1 -> viewModel.exportToJSON(file)
}
}
.show()
}
private fun showDeleteConfirmDialog(file: DataFile) {
MaterialAlertDialogBuilder(requireContext())
.setTitle("Delete File")
.setMessage("Delete " + file.name + "?")
.setPositiveButton("Delete") { _, _ ->
viewModel.deleteFile(file)
}
.setNegativeButton("Cancel", null)
.show()
}
private fun showToast(message: String) {
android.widget.Toast.makeText(requireContext(), message, android.widget.Toast.LENGTH_SHORT).show()
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
@@ -54,8 +54,8 @@ class MapFragment : Fragment() {
private fun setupProviders() {
providers["Google"] = GoogleMapProvider()
providers["ٶ"] = BaiduMapProvider()
providers["ߵ"] = GaodeMapProvider()
providers["°Ù¶È"] = BaiduMapProvider()
providers["¸ßµÂ"] = GaodeMapProvider()
}
private fun setupTabs() {
@@ -109,8 +109,8 @@ class MapFragment : Fragment() {
private fun typesForProvider(providerName: String): List<MapType> {
return when (providerName) {
"Google" -> googleTypes
"ٶ" -> baiduTypes
"ߵ" -> gaodeTypes
"°Ù¶È" -> baiduTypes
"¸ßµÂ" -> gaodeTypes
else -> googleTypes
}
}
@@ -10,7 +10,7 @@ import android.widget.FrameLayout
class BaiduMapProvider : MapProvider {
override val name = "ٶ"
override val name = "°Ù¶È"
override var type: MapType = MapType.BAIDU_NORMAL
private set
@@ -10,7 +10,7 @@ import android.widget.FrameLayout
class GaodeMapProvider : MapProvider {
override val name = "ߵ"
override val name = "¸ßµÂ"
override var type: MapType = MapType.GAODE_NORMAL
private set
@@ -21,13 +21,13 @@ interface MapProvider {
}
enum class MapType(val displayName: String) {
GOOGLE_NORMAL("Google ׼"),
GOOGLE_SATELLITE("Google "),
GOOGLE_TERRAIN("Google "),
GOOGLE_HYBRID("Google "),
BAIDU_NORMAL("ٶ ׼"),
BAIDU_SATELLITE("ٶ "),
BAIDU_HYBRID("ٶ "),
GAODE_NORMAL("ߵ ׼"),
GAODE_SATELLITE("ߵ ")
GOOGLE_NORMAL("Google 标准"),
GOOGLE_SATELLITE("Google 卫星"),
GOOGLE_TERRAIN("Google 地形"),
GOOGLE_HYBRID("Google 混合"),
BAIDU_NORMAL("百度 标准"),
BAIDU_SATELLITE("百度 卫星"),
BAIDU_HYBRID("百度 混合"),
GAODE_NORMAL("高德 标准"),
GAODE_SATELLITE("高德 卫星")
}
@@ -2,7 +2,6 @@ package com.senstools.presentation.ui.settings
import android.content.Context
import android.content.SharedPreferences
import com.senstools.R
import java.util.Locale
class LanguageManager(private val context: Context) {
@@ -35,10 +34,10 @@ class LanguageManager(private val context: Context) {
fun getLanguageDisplayName(language: String, context: Context): String {
return when (language) {
"zh" -> context.getString(R.string.language_chinese)
"en" -> context.getString(R.string.language_english)
"ja" -> context.getString(R.string.language_japanese)
"ko" -> context.getString(R.string.language_korean)
"zh" -> context.getString(com.senstools.R.string.language_chinese)
"en" -> context.getString(com.senstools.R.string.language_english)
"ja" -> context.getString(com.senstools.R.string.language_japanese)
"ko" -> context.getString(com.senstools.R.string.language_korean)
else -> language
}
}
@@ -1,35 +1,22 @@
package com.senstools.presentation.ui.settings
import androidx.fragment.app.viewModels
import androidx.fragment.app.Fragment
import android.app.AlertDialog
import android.os.Bundle
import com.senstools.databinding.FragmentSettingsBinding
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.EditText
import android.widget.AutoCompleteTextView as AndroidAutoCompleteTextView
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import com.senstools.R
import com.senstools.databinding.FragmentSettingsBinding
import com.senstools.presentation.ui.map.provider.MapType
import com.senstools.presentation.viewmodel.SettingsViewModel
class SettingsFragment : Fragment() {
private var _binding: FragmentSettingsBinding? = null
private val binding get() = _binding!!
private val viewModel: SettingsViewModel by viewModels()
private lateinit var languageManager: LanguageManager
private val mapProviders = listOf("google_maps", "baidu_maps", "gaode_maps")
private val mapProviders = listOf("Google", "百度", "高德")
private val allMapTypes = MapType.values().map { it.displayName }
private val languages = LanguageManager.SUPPORTED_LANGUAGES
private lateinit var tvProvider: AndroidAutoCompleteTextView
private lateinit var tvType: AndroidAutoCompleteTextView
private lateinit var tvLang: AndroidAutoCompleteTextView
private val languages = listOf("zh", "en", "ja", "ko")
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
@@ -37,49 +24,19 @@ class SettingsFragment : Fragment() {
): View {
_binding = FragmentSettingsBinding.inflate(inflater, container, false)
languageManager = LanguageManager(requireContext())
val root = binding.root
tvProvider = root.findViewById(R.id.tvDefaultMapProvider)
tvType = root.findViewById(R.id.tvDefaultMapType)
tvLang = root.findViewById(R.id.tvLanguage)
return root
return binding!!.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setupSpinners()
setupObservers()
setupListeners()
}
private fun setupSpinners() {
val providerAdapter = ArrayAdapter(
requireContext(),
android.R.layout.simple_dropdown_item_1line,
mapProviders
)
tvProvider.setAdapter(providerAdapter)
val typeAdapter = ArrayAdapter(
requireContext(),
android.R.layout.simple_dropdown_item_1line,
allMapTypes
)
tvType.setAdapter(typeAdapter)
val languageAdapter = ArrayAdapter(
requireContext(),
android.R.layout.simple_dropdown_item_1line,
getLanguageDisplayNames()
)
tvLang.setAdapter(languageAdapter)
binding.tvDefaultMapProvider.setText(mapProviders.firstOrNull() ?: "")
binding.tvDefaultMapType.setText(allMapTypes.firstOrNull() ?: "")
binding.tvLanguage.setText(languages.firstOrNull() ?: "")
}
private fun getLanguageDisplayNames(): List<String> {
return languages.map { languageManager.getLanguageDisplayName(it, requireContext()) }
}
private fun setupObservers() {
viewModel.settings.observe(viewLifecycleOwner) { settings ->
binding.apply {
@@ -88,16 +45,14 @@ class SettingsFragment : Fragment() {
switchMap.isChecked = settings.mapEnabled
sliderGpsRate.value = settings.gpsRate.toFloat()
sliderSensorRate.value = settings.sensorRate.toFloat()
tvDefaultMapProvider.setText(settings.defaultMapProvider)
tvDefaultMapType.setText(settings.defaultMapType.displayName)
tvLanguage.setText(
languageManager.getLanguageDisplayName(settings.language, requireContext()),
)
}
tvProvider.setText(settings.defaultMapProvider, false)
tvType.setText(settings.defaultMapType.displayName, false)
tvLang.setText(
languageManager.getLanguageDisplayName(settings.language, requireContext()),
false
)
}
}
private fun setupListeners() {
binding.apply {
switchGps.setOnCheckedChangeListener { _, isChecked ->
@@ -115,35 +70,30 @@ class SettingsFragment : Fragment() {
sliderSensorRate.addOnChangeListener { _, value, _ ->
viewModel.setSensorRate(value.toInt())
}
}
tvProvider.setOnItemClickListener { _, _, position, _ ->
viewModel.setDefaultMapProvider(mapProviders[position])
}
tvType.setOnItemClickListener { _, _, position, _ ->
val selectedType = MapType.values().find { it.displayName == allMapTypes[position] }
selectedType?.let { viewModel.setDefaultMapType(it) }
}
tvLang.setOnItemClickListener { _, _, position, _ ->
val selectedLang = languages[position]
viewModel.setLanguage(selectedLang)
languageManager.setLanguage(selectedLang)
showLanguageRestartDialog()
tvDefaultMapProvider.setOnClickListener {
viewModel.setDefaultMapProvider(mapProviders.first())
}
tvDefaultMapType.setOnClickListener {
val selectedType = MapType.values().first()
selectedType?.let { viewModel.setDefaultMapType(it) }
}
tvLanguage.setOnClickListener {
val selectedLang = languages.first()
viewModel.setLanguage(selectedLang)
languageManager.setLanguage(selectedLang)
showLanguageRestartDialog()
}
}
}
private fun showLanguageRestartDialog() {
AlertDialog.Builder(requireContext())
.setTitle(getString(R.string.language))
.setTitle(getString(com.senstools.R.string.language))
.setMessage("Language change requires app restart to take effect.")
.setPositiveButton("OK") { dialog, _ ->
dialog.dismiss()
}
.setNegativeButton("Cancel") { dialog, _ ->
dialog.dismiss()
}
.show()
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
@@ -1,22 +1,15 @@
package com.senstools.presentation.viewmodel
import android.app.Application
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.ServiceConnection
import android.os.IBinder
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.senstools.data.datasource.DataCollectionService
import com.senstools.domain.model.AttitudeData
import com.senstools.domain.model.GPSData
import com.senstools.domain.model.SensorData
import kotlinx.coroutines.launch
class DashboardViewModel(application: Application) : AndroidViewModel(application) {
class DashboardViewModel : ViewModel() {
private val _gpsData = MutableLiveData<GPSData>()
val gpsData: LiveData<GPSData> = _gpsData
@@ -30,62 +23,27 @@ class DashboardViewModel(application: Application) : AndroidViewModel(applicatio
private val _isRecording = MutableLiveData<Boolean>()
val isRecording: LiveData<Boolean> = _isRecording
private var dataCollectionService: DataCollectionService? = null
private var isBound = false
private val serviceCallback = object : DataCollectionService.ServiceCallback {
override fun onGPSData(gps: GPSData) {
_gpsData.postValue(gps)
}
override fun onSensorData(sensor: SensorData) {
_sensorData.postValue(sensor)
}
override fun onAttitudeData(attitude: AttitudeData) {
_attitudeData.postValue(attitude)
}
override fun onRecordingStateChanged(isRecording: Boolean) {
_isRecording.postValue(isRecording)
}
}
private val connection = object : ServiceConnection {
override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
val binder = service as DataCollectionService.LocalBinder
dataCollectionService = binder.getService()
isBound = true
}
override fun onServiceDisconnected(name: ComponentName?) {
dataCollectionService = null
isBound = false
}
}
init {
_isRecording.value = false
}
fun bindService(context: Context) {
val intent = Intent(context, DataCollectionService::class.java)
context.bindService(intent, connection, Context.BIND_AUTO_CREATE)
}
fun unbindService(context: Context) {
if (isBound) {
context.unbindService(connection)
isBound = false
dataCollectionService = null
}
}
fun startRecording() {
dataCollectionService?.startCollecting(serviceCallback)
_isRecording.value = true
}
fun stopRecording() {
dataCollectionService?.stopCollecting()
_isRecording.value = false
}
fun updateGPSData(data: GPSData) {
_gpsData.value = data
}
fun updateSensorData(data: SensorData) {
_sensorData.value = data
}
fun updateAttitudeData(data: AttitudeData) {
_attitudeData.value = data
}
}
@@ -1,140 +1,37 @@
package com.senstools.presentation.viewmodel
import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.senstools.domain.repository.DataRepository
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import android.content.Intent
import android.net.Uri
import androidx.core.content.FileProvider
import kotlinx.coroutines.withContext
import java.io.File
import androidx.lifecycle.ViewModel
class DataViewModel(application: Application) : AndroidViewModel(application) {
class DataViewModel : ViewModel() {
private val _dataFiles = MutableLiveData<List<DataFile>>()
val dataFiles: LiveData<List<DataFile>> = _dataFiles
private val _isExporting = MutableLiveData(false)
val isExporting: LiveData<Boolean> = _isExporting
private val _exportResult = MutableLiveData<String?>()
val exportResult: LiveData<String?> = _exportResult
private val dataRepository: DataRepository
init {
dataRepository = DataRepository(application.filesDir)
loadFiles()
}
private fun loadFiles() {
val files = dataRepository.listDataFiles().map { info ->
DataFile(
name = info.name,
path = info.path,
size = info.size,
date = info.lastModified
)
}
_dataFiles.value = files
// Load files from storage
_dataFiles.value = emptyList()
}
fun refreshFiles() {
loadFiles()
}
fun openFile(file: DataFile) { // placeholder
fun openFile(file: DataFile) {
// Open file for viewing
}
fun exportToCSV(file: DataFile) {
viewModelScope.launch {
_isExporting.value = true
val result = withContext(Dispatchers.IO) {
val exportDir = File(
getApplication<Application>().filesDir,
"senstools_export"
)
exportDir.mkdirs()
val csvPath = File(exportDir, file.name.replace(".bin", ".csv")).absolutePath
val success = dataRepository.exportToCSV(file.path, csvPath)
success to csvPath
}
_exportResult.value = if (result.first) {
shareFile(result.second)
"CSV exported"
} else {
"CSV export failed"
}
_isExporting.value = false
}
}
fun exportToJSON(file: DataFile) {
viewModelScope.launch {
_isExporting.value = true
val result = withContext(Dispatchers.IO) {
val exportDir = File(
getApplication<Application>().filesDir,
"senstools_export"
)
exportDir.mkdirs()
val jsonPath = File(exportDir, file.name.replace(".bin", ".json")).absolutePath
val success = dataRepository.exportToJSON(file.path, jsonPath)
success to jsonPath
}
_exportResult.value = if (result.first) {
shareFile(result.second)
"JSON exported"
} else {
"JSON export failed"
}
_isExporting.value = false
}
fun exportFile(file: DataFile) {
// Export file to CSV/JSON
}
fun deleteFile(file: DataFile) {
viewModelScope.launch {
withContext(Dispatchers.IO) {
dataRepository.deleteFile(file.name)
}
loadFiles()
}
}
fun deleteAll() {
viewModelScope.launch {
withContext(Dispatchers.IO) {
dataRepository.deleteAll()
}
loadFiles()
}
}
private fun shareFile(filePath: String) {
try {
val app = getApplication<Application>()
val file = File(filePath)
if (!file.exists()) return
val uri = FileProvider.getUriForFile(app, app.packageName + ".fileprovider", file)
val intent = Intent(Intent.ACTION_SEND).apply {
type = if (filePath.endsWith(".csv")) "text/csv" else "application/json"
putExtra(Intent.EXTRA_STREAM, uri)
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
}
app.startActivity(Intent.createChooser(intent, "Share data"))
} catch (e: Exception) {
_exportResult.value = "Share failed: " + e.message
}
}
fun clearExportResult() {
_exportResult.value = null
// Delete file
}
}
@@ -50,7 +50,7 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Pitch: 0.00°" />
android:text="Pitch: 0.00" />
<TextView
android:id="@+id/tvRoll"
@@ -58,7 +58,7 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Roll: 0.00°" />
android:text="Roll: 0.00" />
<TextView
android:id="@+id/tvYaw"
@@ -66,7 +66,7 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Yaw: 0.00°" />
android:text="Yaw: 0.00" />
</LinearLayout>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
@@ -111,7 +111,7 @@
<TextView android:id="@+id/tvSpeed" android:text="0.00 m/s" />
<TextView android:text="@string/bearing" />
<TextView android:id="@+id/tvBearing" android:text="0.00°" />
<TextView android:id="@+id/tvBearing" android:text="0.00" />
<TextView android:text="@string/satellites" />
<TextView android:id="@+id/tvSatellites" android:text="0" />
@@ -262,7 +262,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Temp: 0.00°C" />
android:text="Temp: 0.00C" />
<TextView
android:id="@+id/tvHumidity"
@@ -151,7 +151,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="4dp">
<android.widget.AutoCompleteTextView
<EditText
android:id="@+id/tvDefaultMapProvider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@@ -170,7 +170,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="4dp">
<android.widget.AutoCompleteTextView
<EditText
android:id="@+id/tvDefaultMapType"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@@ -189,7 +189,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="4dp">
<android.widget.AutoCompleteTextView
<EditText
android:id="@+id/tvLanguage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@@ -1,51 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">sensTools</string>
<string name="nav_dashboard">Dashboard</string>
<string name="nav_data">Data</string>
<string name="nav_map">Map</string>
<string name="nav_settings">Settings</string>
<string name="flight_dashboard">Flight Dashboard</string>
<string name="gps_data">GPS Data</string>
<string name="sensor_data">Sensor Data</string>
<string name="acceleration">Accelerometer (m/s?)</string>
<string name="gyroscope">Gyroscope (?/s)</string>
<string name="magnetometer">Magnetometer (?T)</string>
<string name="environment">Environment</string>
<string name="start_recording">Start Recording</string>
<string name="stop_recording">Stop Recording</string>
<string name="longitude">Longitude:</string>
<string name="latitude">Latitude:</string>
<string name="altitude">Altitude:</string>
<string name="speed">Speed:</string>
<string name="bearing">Bearing:</string>
<string name="satellites">Satellites:</string>
<string name="pitch">Pitch:</string>
<string name="roll">Roll:</string>
<string name="yaw">Yaw:</string>
<string name="pressure">Pressure:</string>
<string name="temperature">Temperature:</string>
<string name="humidity">Humidity:</string>
<string name="data_collection">Data Collection</string>
<string name="display">Display</string>
<string name="about">About</string>
<string name="gps_data_label">GPS Data</string>
<string name="sensor_data_label">Sensor Data</string>
<string name="map_display">Map Display</string>
<string name="gps_sampling_rate">GPS Sampling Rate (Hz)</string>
<string name="sensor_sampling_rate">Sensor Sampling Rate (Hz)</string>
<string name="default_map_provider">Default Map Provider</string>
<string name="default_map_type">Default Map Type</string>
<string name="language">Language</string>
<string name="google_maps">Google Maps</string>
<string name="baidu_maps">Baidu Maps</string>
<string name="gaode_maps">Gaode Maps</string>
<string name="normal">Normal</string>
<string name="satellite">Satellite</string>
<string name="terrain">Terrain</string>
<string name="hybrid">Hybrid</string>
<string name="language_chinese">Chinese</string>
<string name="language_english">English</string>
<string name="language_japanese">Japanese</string>
<string name="language_korean">Korean</string>
</resources>
@@ -1,47 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">sensTools</string>
<string name="nav_dashboard">Dashboard</string>
<string name="nav_data">Data</string>
<string name="nav_map">Map</string>
<string name="nav_settings">Settings</string>
<string name="flight_dashboard">Flight Dashboard</string>
<string name="gps_data">GPS Data</string>
<string name="sensor_data">Sensor Data</string>
<string name="acceleration">Accelerometer (m/s?)</string>
<string name="gyroscope">Gyroscope (?/s)</string>
<string name="magnetometer">Magnetometer (?T)</string>
<string name="environment">Environment</string>
<string name="start_recording">Start Recording</string>
<string name="stop_recording">Stop Recording</string>
<string name="longitude">Longitude:</string>
<string name="latitude">Latitude:</string>
<string name="altitude">Altitude:</string>
<string name="speed">Speed:</string>
<string name="bearing">Bearing:</string>
<string name="satellites">Satellites:</string>
<string name="pitch">Pitch:</string>
<string name="roll">Roll:</string>
<string name="yaw">Yaw:</string>
<string name="pressure">Pressure:</string>
<string name="temperature">Temperature:</string>
<string name="humidity">Humidity:</string>
<string name="data_collection">Data Collection</string>
<string name="display">Display</string>
<string name="about">About</string>
<string name="gps_data_label">GPS Data</string>
<string name="sensor_data_label">Sensor Data</string>
<string name="map_display">Map Display</string>
<string name="gps_sampling_rate">GPS Sampling Rate (Hz)</string>
<string name="sensor_sampling_rate">Sensor Sampling Rate (Hz)</string>
<string name="default_map_provider">Default Map Provider</string>
<string name="default_map_type">Default Map Type</string>
<string name="language">Language</string>
<string name="google_maps">Google Maps</string>
<string name="baidu_maps">Baidu Maps</string>
<string name="gaode_maps">Gaode Maps</string>
<string name="normal">Normal</string>
<string name="satellite">Satellite</string>
<string name="terrain">Terrain</string>
<string name="hybrid">Hybrid</string>
</resources>
@@ -1,47 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">sensTools</string>
<string name="nav_dashboard">Dashboard</string>
<string name="nav_data">Data</string>
<string name="nav_map">Map</string>
<string name="nav_settings">Settings</string>
<string name="flight_dashboard">Flight Dashboard</string>
<string name="gps_data">GPS Data</string>
<string name="sensor_data">Sensor Data</string>
<string name="acceleration">Accelerometer (m/s?)</string>
<string name="gyroscope">Gyroscope (?/s)</string>
<string name="magnetometer">Magnetometer (?T)</string>
<string name="environment">Environment</string>
<string name="start_recording">Start Recording</string>
<string name="stop_recording">Stop Recording</string>
<string name="longitude">Longitude:</string>
<string name="latitude">Latitude:</string>
<string name="altitude">Altitude:</string>
<string name="speed">Speed:</string>
<string name="bearing">Bearing:</string>
<string name="satellites">Satellites:</string>
<string name="pitch">Pitch:</string>
<string name="roll">Roll:</string>
<string name="yaw">Yaw:</string>
<string name="pressure">Pressure:</string>
<string name="temperature">Temperature:</string>
<string name="humidity">Humidity:</string>
<string name="data_collection">Data Collection</string>
<string name="display">Display</string>
<string name="about">About</string>
<string name="gps_data_label">GPS Data</string>
<string name="sensor_data_label">Sensor Data</string>
<string name="map_display">Map Display</string>
<string name="gps_sampling_rate">GPS Sampling Rate (Hz)</string>
<string name="sensor_sampling_rate">Sensor Sampling Rate (Hz)</string>
<string name="default_map_provider">Default Map Provider</string>
<string name="default_map_type">Default Map Type</string>
<string name="language">Language</string>
<string name="google_maps">Google Maps</string>
<string name="baidu_maps">Baidu Maps</string>
<string name="gaode_maps">Gaode Maps</string>
<string name="normal">Normal</string>
<string name="satellite">Satellite</string>
<string name="terrain">Terrain</string>
<string name="hybrid">Hybrid</string>
</resources>
+40 -28
View File
@@ -5,49 +5,61 @@
<string name="nav_data">Data</string>
<string name="nav_map">Map</string>
<string name="nav_settings">Settings</string>
<string name="flight_dashboard">Flight Dashboard</string>
<string name="flight_dashboard">Dashboard</string>
<string name="gps_data">GPS Data</string>
<string name="sensor_data">Sensor Data</string>
<string name="acceleration">Accelerometer (m/s?)</string>
<string name="gyroscope">Gyroscope (?/s)</string>
<string name="magnetometer">Magnetometer (?T)</string>
<string name="acceleration">Accel (m/s²)</string>
<string name="gyroscope">Gyro (°/s)</string>
<string name="magnetometer">Mag (µT)</string>
<string name="environment">Environment</string>
<string name="start_recording">Start Recording</string>
<string name="stop_recording">Stop Recording</string>
<string name="longitude">Longitude:</string>
<string name="latitude">Latitude:</string>
<string name="altitude">Altitude:</string>
<string name="start_recording">Start</string>
<string name="stop_recording">Stop</string>
<string name="latitude">Lat:</string>
<string name="longitude">Lng:</string>
<string name="altitude">Alt:</string>
<string name="bearing">Heading:</string>
<string name="speed">Speed:</string>
<string name="bearing">Bearing:</string>
<string name="satellites">Satellites:</string>
<string name="pitch">Pitch:</string>
<string name="roll">Roll:</string>
<string name="yaw">Yaw:</string>
<string name="pressure">Pressure:</string>
<string name="temperature">Temperature:</string>
<string name="temperature">Temp:</string>
<string name="humidity">Humidity:</string>
<string name="timestamp">Time:</string>
<string name="data_collection">Data Collection</string>
<string name="display">Display</string>
<string name="about">About</string>
<string name="gps_data_label">GPS Data</string>
<string name="sensor_data_label">Sensor Data</string>
<string name="map_display">Map Display</string>
<string name="gps_sampling_rate">GPS Sampling Rate (Hz)</string>
<string name="sensor_sampling_rate">Sensor Sampling Rate (Hz)</string>
<string name="default_map_provider">Default Map Provider</string>
<string name="gps_sampling_rate">GPS Rate (Hz)</string>
<string name="sensor_sampling_rate">Sensor Rate (Hz)</string>
<string name="default_map_provider">Default Provider</string>
<string name="default_map_type">Default Map Type</string>
<string name="language">Language</string>
<string name="google_maps">Google Maps</string>
<string name="baidu_maps">Baidu Maps</string>
<string name="gaode_maps">Gaode Maps</string>
<string name="normal">Normal</string>
<string name="satellite">Satellite</string>
<string name="terrain">Terrain</string>
<string name="hybrid">Hybrid</string>
<string name="select_provider">Select Provider</string>
<string name="select_map_type">Select Map Type</string>
<string name="select_language">Select Language</string>
<string name="language_chinese">中文</string>
<string name="google_normal">Google Normal</string>
<string name="google_satellite">Google Satellite</string>
<string name="google_terrain">Google Terrain</string>
<string name="google_hybrid">Google Hybrid</string>
<string name="baidu_normal">Baidu Normal</string>
<string name="baidu_satellite">Baidu Satellite</string>
<string name="baidu_hybrid">Baidu Hybrid</string>
<string name="gaode_normal">Gaode Normal</string>
<string name="gaode_satellite">Gaode Satellite</string>
<string name="language_chinese">Chinese</string>
<string name="language_english">English</string>
<string name="language_japanese">日本語</string>
<string name="language_korean">한국어</string>
<string name="language_japanese">Japanese</string>
<string name="language_korean">Korean</string>
<string name="file_name">File Name</string>
<string name="file_size">File Size</string>
<string name="file_date">File Date</string>
<string name="export">Export</string>
<string name="delete">Delete</string>
<string name="satellites">Satellites</string>
<string name="rolling">Rolling</string>
<string name="pitch">Pitch</string>
<string name="yaw">Yaw</string>
<string name="testing_connection">Testing…</string>
<string name="connection_ok">OK</string>
<string name="connection_failed">Failed</string>
</resources>
@@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<paths>
<cache-path name="exports" path="exports/" />
</paths>
+2 -3
View File
@@ -1,5 +1,4 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '8.2.0' apply false
id 'org.jetbrains.kotlin.android' version '1.9.20' apply false
id "com.android.application" version "8.7.3" apply false
id "org.jetbrains.kotlin.android" version "2.0.21" apply false
}
Binary file not shown.
+2 -251
View File
@@ -1,252 +1,3 @@
#!/bin/sh
#
# Copyright © 2015-2021 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#
##############################################################################
#
# Gradle start up script for POSIX generated by Gradle.
#
# Important for running:
#
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
# noncompliant, but you have some other compliant shell such as ksh or
# bash, then to run this script, type that shell name before the whole
# command line, like:
#
# ksh Gradle
#
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
# (2) This script targets any POSIX shell, so it avoids extensions provided
# by Bash, Ksh, etc; in particular arrays are avoided.
#
# The "traditional" practice of packing multiple parameters into a
# space-separated string is a well documented source of bugs and security
# problems, so this is (mostly) avoided, by progressively accumulating
# options in "$@", and eventually passing that to Java.
#
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
# see the in-line comments for details.
#
# There are tweaks for specific operating systems such as AIX, CygWin,
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
#
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
app_path=$0
# Need this for daisy-chained symlinks.
while
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
[ -h "$app_path" ]
do
ls=$( ls -ld "$app_path" )
link=${ls#*' -> '}
case $link in #(
/*) app_path=$link ;; #(
*) app_path=$APP_HOME$link ;;
esac
done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
warn () {
echo "$*"
} >&2
die () {
echo
echo "$*"
echo
exit 1
} >&2
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "$( uname )" in #(
CYGWIN* ) cygwin=true ;; #(
Darwin* ) darwin=true ;; #(
MSYS* | MINGW* ) msys=true ;; #(
NONSTOP* ) nonstop=true ;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD=$JAVA_HOME/jre/sh/java
else
JAVACMD=$JAVA_HOME/bin/java
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD=java
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi
# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
fi
# Collect all arguments for the java command, stacking in reverse order:
# * args from the command line
# * the main class name
# * -classpath
# * -D...appname settings
# * --module-path (only if needed)
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
# For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
JAVACMD=$( cygpath --unix "$JAVACMD" )
# Now convert the arguments - kludge to limit ourselves to /bin/sh
for arg do
if
case $arg in #(
-*) false ;; # don't mess with options #(
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
[ -e "$t" ] ;; #(
*) false ;;
esac
then
arg=$( cygpath --path --ignore --mixed "$arg" )
fi
# Roll the args list around exactly as many times as the number of
# args, so each arg winds up back in the position where it started, but
# possibly modified.
#
# NB: a `for` loop captures its iteration list before it begins, so
# changing the positional parameters here affects neither the number of
# iterations, nor the values presented in `arg`.
shift # remove old arg
set -- "$@" "$arg" # push replacement arg
done
fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
"$@"
# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
#
# In Bash we could simply go:
#
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
# set -- "${ARGS[@]}" "$@"
#
# but POSIX shell has neither arrays nor command substitution, so instead we
# post-process each arg (as a line of input to sed) to backslash-escape any
# character that might be a shell metacharacter, then use eval to reverse
# that process (while maintaining the separation between arguments), and wrap
# the whole thing up as a single "set" statement.
#
# This will of course break if any of these variables contains a newline or
# an unmatched quote.
#
eval "set -- $(
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
xargs -n1 |
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
tr '\n' ' '
)" '"$@"'
exec "$JAVACMD" "$@"
DIR="$( cd "$( dirname "$0" )" && pwd )"
java -Xmx1024m -Dorg.gradle.appname="sensTools" -classpath "$DIR/gradle/wrapper/gradle-wrapper.jar" org.gradle.wrapper.GradleWrapperMain "$@"
-94
View File
@@ -1,94 +0,0 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
+1 -3
View File
@@ -2,7 +2,6 @@ pluginManagement {
repositories {
google()
mavenCentral()
maven { url "https://jitpack.io" }
gradlePluginPortal()
}
}
@@ -14,6 +13,5 @@ dependencyResolutionManagement {
maven { url "https://jitpack.io" }
}
}
rootProject.name = "sensTools"
include ':app'
include ":app"