Initial commit (files only)

This commit is contained in:
robin committed 2026-07-08 16:48:29 +02:00
commit ed0a6cb185
88 files changed
+2809

No files matched your search

+1
View File
@@ -0,0 +1 @@
/build
+96
View File
@@ -0,0 +1,96 @@
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.getByName
import org.gradle.kotlin.dsl.release
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.compose)
}
android {
namespace = "de.schanbro.screenity"
compileSdk = 36
defaultConfig {
applicationId = "de.schanbro.screenity"
minSdk = 29
targetSdk = 36
val gitVersion = System.getenv("APP_VERSION") ?: "0.0.1-local"
versionName = gitVersion.removePrefix("v")
versionCode = (System.currentTimeMillis() / 600000).toInt()
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
signingConfigs {
create("release") {
storeFile = file("keystore.jks")
storePassword = System.getenv("KEY_STORE_PASSWORD")
keyAlias = System.getenv("ALIAS")
keyPassword = System.getenv("KEY_PASSWORD")
}
}
buildTypes {
release {
isMinifyEnabled = false
// Hier kommt alles in EINEN Block:
signingConfig = signingConfigs.getByName("release")
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = "11"
}
buildFeatures {
compose = true
}
// Optional: Damit die Datei auf GitHub auch den richtigen Namen hat
applicationVariants.all {
outputs.all {
val output = this as com.android.build.gradle.internal.api.ApkVariantOutputImpl
output.outputFileName = "Screenity-${versionName}.apk"
}
}
}
dependencies {
implementation(libs.androidx.compose.animation)
val workVersion = "2.9.0" // Prüfe hier gern auf die aktuellste Version
implementation("androidx.work:work-runtime-ktx:$workVersion")
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.activity.compose)
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.compose.ui)
implementation(libs.androidx.compose.ui.graphics)
implementation(libs.androidx.compose.ui.tooling.preview)
implementation(libs.androidx.compose.material3)
implementation(libs.androidx.navigation.compose)
implementation(libs.androidx.ui)
implementation(libs.androidx.material3)
implementation(libs.androidx.ui.graphics)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
androidTestImplementation(platform(libs.androidx.compose.bom))
androidTestImplementation(libs.androidx.compose.ui.test.junit4)
debugImplementation(libs.androidx.compose.ui.tooling)
debugImplementation(libs.androidx.compose.ui.test.manifest)
implementation("androidx.compose.material:material-icons-extended")
implementation("com.squareup.okhttp3:okhttp:4.12.0")
implementation("com.google.code.gson:gson:2.10.1")
implementation("androidx.glance:glance-appwidget:1.1.0") // Oder aktuellste Version
implementation("androidx.glance:glance-material3:1.1.0")
}
+21
View File
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
@@ -0,0 +1,24 @@
package de.schanbro.screenity
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("de.schanbro.screenity", appContext.packageName)
}
}
+48
View File
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.PACKAGE_USAGE_STATS" tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/screenity_edited"
android:label="@string/app_name"
android:roundIcon="@mipmap/screenity_edited_round"
android:supportsRtl="true"
android:theme="@style/Theme.Screenity">
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.Screenity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".WidgetConfigActivity"
android:exported="true">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE"/>
</intent-filter>
</activity>
<receiver
android:name=".ScreentimeWidgetReceiver"
android:exported="true">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/screentime_widget_info" />
</receiver>
</application>
</manifest>
@@ -0,0 +1,50 @@
package de.schanbro.screenity
import android.content.Context
import android.provider.Settings
import com.google.gson.Gson
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import okhttp3.*
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody.Companion.toRequestBody
import java.text.SimpleDateFormat
import java.util.*
data class DeviceFullData(
val device_id: String,
val device_name: String,
val reports: Map<String, DayReport>
)
// --- NETZWERK LOGIK ---
suspend fun sendDataToServer(
context: Context,
url: String,
totalMs: Long,
usageList: List<AppUsageInfo>,
detailedEvents: List<ScreenEvent>
): Boolean = withContext(Dispatchers.IO) {
if (url.isBlank()) return@withContext false
val client = OkHttpClient()
val reportData = mapOf(
"device_id" to Settings.Secure.getString(context.contentResolver, Settings.Secure.ANDROID_ID),
"device_name" to android.os.Build.MODEL,
"report_date" to SimpleDateFormat("yyyy-MM-dd", Locale.US).format(Date()),
"total_screen_time_ms" to totalMs,
"apps" to usageList.map { mapOf("app_name" to it.appName, "usage_ms" to it.usageMs) }
)
try {
val body = Gson().toJson(reportData).toRequestBody("application/json".toMediaType())
val request = Request.Builder().url("${url.trim().removeSuffix("/")}/report").post(body).build()
client.newCall(request).execute().isSuccessful
} catch (e: Exception) { false }
}
suspend fun getSummaryFromServer(url: String): ServerSummary = withContext(Dispatchers.IO) {
val client = OkHttpClient()
val request = Request.Builder().url("${url.trim().removeSuffix("/")}/summary").build()
val response = client.newCall(request).execute()
if (!response.isSuccessful) throw Exception("Code: ${response.code}")
Gson().fromJson(response.body?.string(), ServerSummary::class.java)
}
@@ -0,0 +1,164 @@
package de.schanbro.screenity
import android.content.Context
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Refresh
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.google.gson.Gson
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import okhttp3.OkHttpClient
import okhttp3.Request
import java.text.SimpleDateFormat
import java.util.*
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun DeviceDetailScreen(deviceId: String, onBack: () -> Unit) {
val context = LocalContext.current
val scope = rememberCoroutineScope()
val prefs = remember { context.getSharedPreferences("ScreenityPrefs", Context.MODE_PRIVATE) }
val serverUrl = prefs.getString("server_url", "") ?: ""
var isLoading by remember { mutableStateOf(true) }
var appsFromToday by remember { mutableStateOf<List<AppUsageDetail>>(emptyList()) }
var deviceName by remember { mutableStateOf("Gerät") }
val todayStr = SimpleDateFormat("yyyy-MM-dd", Locale.US).format(Date())
fun fetch() {
android.util.Log.d("SCREENITY_CHECK", "1. fetch() gestartet für ID: $deviceId")
if (serverUrl.isBlank()) return
scope.launch {
isLoading = true
try {
val client = OkHttpClient()
val fullUrl = "${serverUrl.trim().removeSuffix("/")}/summary"
val request = Request.Builder().url(fullUrl).build()
val response = withContext(Dispatchers.IO) { client.newCall(request).execute() }
if (response.isSuccessful) {
// WICHTIG: Body nur einmal auslesen und in Variable speichern
val responseBodyString = withContext(Dispatchers.IO) { response.body?.string() } ?: ""
android.util.Log.d("SCREENITY_CHECK", "2. JSON geladen, Länge: ${responseBodyString.length}")
if (responseBodyString.isNotBlank()) {
try {
val fullSummary = Gson().fromJson(responseBodyString, ServerSummary::class.java)
// Gerät in der Liste suchen
val device = fullSummary.devices.find { it.device_id.trim() == deviceId.trim() }
if (device != null) {
deviceName = device.device_name
android.util.Log.d("SCREENITY_CHECK", "3. Gerät gefunden: ${device.device_name}")
// Report für heute heraussuchen
val report = device.reports?.get(todayStr)
if (report != null) {
appsFromToday = report.apps ?: emptyList()
android.util.Log.d("SCREENITY_CHECK", "4. Apps für heute gefunden: ${appsFromToday.size}")
} else {
android.util.Log.w("SCREENITY_CHECK", "Hinweis: Kein Report für $todayStr vorhanden.")
// Debug: Zeige welche Tage da sind
android.util.Log.d("SCREENITY_CHECK", "Verfügbare Tage: ${device.reports?.keys}")
}
} else {
android.util.Log.e("SCREENITY_CHECK", "Fehler: Gerät mit ID $deviceId nicht in Liste.")
}
} catch (e: Exception) {
android.util.Log.e("SCREENITY_CHECK", "Parsing-Fehler: ${e.message}")
android.util.Log.d("SCREENITY_CHECK", "Fehlerhaftes JSON: $responseBodyString")
}
}
} else {
android.util.Log.e("SCREENITY_CHECK", "Server Fehler-Code: ${response.code}")
}
} catch (e: Exception) {
android.util.Log.e("SCREENITY_CHECK", "Netzwerk-Fehler: ${e.message}")
}
isLoading = false
}
}
LaunchedEffect(Unit) { fetch() }
ScreenWrapper(
title = "Details: $deviceName",
headerAction = {
IconButton(onClick = { fetch() }) {
Icon(Icons.Default.Refresh, contentDescription = "Aktualisieren")
}
}
) {
if (isLoading) {
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
CircularProgressIndicator()
}
} else {
Column(Modifier.fillMaxSize()) {
Text(
text = "App-Nutzung heute ($todayStr):",
style = MaterialTheme.typography.titleMedium,
color = MaterialTheme.colorScheme.primary,
modifier = Modifier.padding(bottom = 16.dp)
)
if (appsFromToday.isEmpty()) {
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Text("Keine detaillierten Daten für heute gefunden.", style = MaterialTheme.typography.bodyMedium)
}
} else {
LazyColumn(
modifier = Modifier.fillMaxSize(),
contentPadding = PaddingValues(bottom = 24.dp)
) {
items(appsFromToday.sortedByDescending { it.usage_ms }) { app ->
AppUsageRow(app)
HorizontalDivider(modifier = Modifier.padding(vertical = 4.dp), thickness = 0.5.dp)
}
}
}
}
}
}
}
@Composable
fun AppUsageRow(app: AppUsageDetail) {
val h = app.usage_ms / 3600000
val m = (app.usage_ms % 3600000) / 60000
val s = (app.usage_ms % 60000) / 1000
Row(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 12.dp),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = app.app_name,
modifier = Modifier.weight(1f),
style = MaterialTheme.typography.bodyLarge
)
Text(
text = if (h > 0) String.format("%dh %02dm", h, m) else String.format("%dm %02ds", m, s),
style = MaterialTheme.typography.bodyMedium,
fontWeight = FontWeight.Bold,
fontFamily = androidx.compose.ui.text.font.FontFamily.Monospace
)
}
}
@@ -0,0 +1,148 @@
package de.schanbro.screenity
import android.app.usage.UsageEvents
import android.app.usage.UsageStatsManager
import android.content.Context
import android.content.Intent
import android.provider.Settings
import android.widget.Toast
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.CloudUpload
import androidx.compose.material.icons.filled.Refresh
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.google.gson.Gson
import com.google.gson.annotations.SerializedName
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody.Companion.toRequestBody
import java.text.SimpleDateFormat
import java.util.*
data class DeviceSummary(
val device_id: String,
val device_name: String,
val total_screen_time_hours: Double,
val today_ms: Long,
val reports: Map<String, DayReport>? // Wichtig: Hier müssen die Reports drin sein!
)
data class DayReport(
@SerializedName("total_screen_time_ms") val totalMs: Long,
val apps: List<AppUsageDetail>? = null
)
data class AppUsageDetail(
@SerializedName("app_name") val app_name: String,
@SerializedName("usage_ms") val usage_ms: Long
)
@Composable
fun DevicesScreen(onNavigateToDetail: (String) -> Unit) {
val context = LocalContext.current
val scope = rememberCoroutineScope()
val prefs = remember { context.getSharedPreferences("ScreenityPrefs", Context.MODE_PRIVATE) }
val serverUrl = prefs.getString("server_url", "") ?: ""
var devicesList by remember { mutableStateOf(emptyList<DeviceSummary>()) }
var isLoading by remember { mutableStateOf(false) }
fun fetch() {
if (serverUrl.isBlank()) return
scope.launch {
isLoading = true
try {
val result = getSummaryFromServer(serverUrl)
// Hier greifen wir auf die Liste der Geräte zu:
val fetchedDevices = result.devices
devicesList = fetchedDevices
// --- AB HIER NEU: Echte Geräte für das Widget sichern ---
// Wir ziehen uns alle Gerätenamen aus der Liste heraus
val deviceNames = fetchedDevices.map { it.device_name }.toSet()
// Wir speichern das Set in den SharedPreferences ab
prefs.edit().putStringSet("known_device_ids", deviceNames).apply()
// --- ENDE NEU ---
} catch (e: Exception) {
// Fehlerbehandlung (z.B. Loggen oder Toast)
}
isLoading = false
}
}
LaunchedEffect(Unit) { fetch() }
ScreenWrapper(
title = stringResource(R.string.devices_overview),
headerAction = {
IconButton(onClick = { fetch() }) {
Icon(Icons.Default.Refresh, contentDescription = null)
}
}
) {
if (isLoading) {
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
CircularProgressIndicator()
}
} else {
LazyColumn(modifier = Modifier.fillMaxSize()) {
items(
items = devicesList,
key = { it.device_id }
) { device ->
DeviceUsageRow(
device = device,
onClick = { onNavigateToDetail(device.device_id) }
)
}
}
}
}
}
@Composable
fun DeviceUsageRow(device: DeviceSummary, onClick: () -> Unit) {
val h = device.today_ms / 3600000
val m = (device.today_ms % 3600000) / 60000
Card(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 6.dp)
.clickable { onClick() },
elevation = CardDefaults.cardElevation(2.dp)
) {
Row(
modifier = Modifier.padding(16.dp),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Column(modifier = Modifier.weight(1f)) {
Text(device.device_name, style = MaterialTheme.typography.titleMedium)
Text("ID: ${device.device_id.take(8)}...", style = MaterialTheme.typography.labelSmall, color = MaterialTheme.colorScheme.onSurfaceVariant)
}
Text(
text = String.format("%dh %02dm", h, m),
fontFamily = androidx.compose.ui.text.font.FontFamily.Monospace,
style = MaterialTheme.typography.titleLarge,
color = MaterialTheme.colorScheme.primary
)
}
}
}
@@ -0,0 +1,288 @@
package de.schanbro.screenity
import android.app.usage.UsageEvents
import android.app.usage.UsageStatsManager
import android.content.Context
import android.content.Intent
import android.provider.Settings
import android.widget.Toast
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.CloudUpload
import androidx.compose.material.icons.filled.Refresh
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.google.gson.Gson
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody.Companion.toRequestBody
import java.text.SimpleDateFormat
import java.util.*
// --- DATENMODELL ---
data class AppUsageInfo(
val appName: String,
val usageMs: Long
)
@Composable
@Preview
fun LocalScreen() {
val context = LocalContext.current
val scope = rememberCoroutineScope()
val snackbarHostState = remember { SnackbarHostState() }
val prefs = remember { context.getSharedPreferences("ScreenityPrefs", Context.MODE_PRIVATE) }
val serverUrl = prefs.getString("server_url", "") ?: ""
var usageList by remember { mutableStateOf<List<AppUsageInfo>>(emptyList()) }
var totalMs by remember { mutableLongStateOf(0L) }
val detailedEvents = getDetailedEvents(context)
var isSending by remember { mutableStateOf(false) }
fun load() {
scope.launch {
// getTodayUsageEvents solltest du am besten auch auf suspend umstellen!
usageList = getTodayUsageEvents(context)
// Hier rufen wir unsere neue asynchrone Funktion auf
totalMs = getTotalScreenTime(context)
}
}
// Beim ersten Start des Screens laden
LaunchedEffect(Unit) {
load()
}
Scaffold(snackbarHost = { SnackbarHost(snackbarHostState) }) { padding ->
ScreenWrapper(
title = stringResource(R.string.this_device),
headerAction = {
IconButton(onClick = { load() }) { Icon(Icons.Default.Refresh, null) }
}
) {
TotalTimeCard(totalMs)
Spacer(Modifier.height(12.dp))
val successMessage = stringResource(R.string.sent)
val errorMessage = stringResource(R.string.error)
Button(
onClick = {
scope.launch {
isSending = true
val ok = sendDataToServer(context, serverUrl, totalMs, usageList, detailedEvents)
snackbarHostState.showSnackbar(if(ok) successMessage else errorMessage)
isSending = false
}
},
modifier = Modifier.fillMaxWidth(),
enabled = !isSending && serverUrl.isNotBlank()
) {
if (isSending) CircularProgressIndicator(Modifier.size(20.dp))
else Text(stringResource(R.string.upload_data))
}
Spacer(Modifier.height(12.dp)) // Kleiner Abstand zur Liste
LazyColumn(Modifier.weight(1f)) {
items(usageList) { app -> AppUsageRow(app) }
}
}
}
}
// --- UI KOMPONENTEN ---
@Composable
fun TotalTimeCard(totalMs: Long) {
val h = totalMs / 3600000
val m = (totalMs % 3600000) / 60000
val s = (totalMs % 60000) / 1000
Card(
modifier = Modifier.fillMaxWidth(),
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.primaryContainer)
) {
Column(Modifier.padding(16.dp)) {
Text(text = stringResource(R.string.all_time), style = MaterialTheme.typography.titleSmall, color = MaterialTheme.colorScheme.primary)
Text(
text = String.format("%02dh %02dm %02ds", h, m, s),
style = MaterialTheme.typography.displayMedium,
fontFamily = androidx.compose.ui.text.font.FontFamily.Monospace
)
}
}
}
@Composable
fun AppUsageRow(app: AppUsageInfo) {
val hours = app.usageMs / 3600000
val minutes = (app.usageMs % 3600000) / 60000
val seconds = (app.usageMs % 60000) / 1000
Card(modifier = Modifier.fillMaxWidth().padding(vertical = 4.dp)) {
Row(
modifier = Modifier.padding(16.dp),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Text(app.appName, modifier = Modifier.weight(1f), style = MaterialTheme.typography.titleSmall)
Text(
text = String.format("%02dh %02dm %02ds", hours, minutes, seconds),
fontFamily = androidx.compose.ui.text.font.FontFamily.Monospace,
color = MaterialTheme.colorScheme.primary,
style = MaterialTheme.typography.bodyMedium
)
}
}
}
// --- SYSTEM LOGIK (PROFI-METHODEN) ---
suspend fun getTodayUsageEvents(context: Context): List<AppUsageInfo> = withContext(Dispatchers.IO) {
val usm = context.getSystemService(Context.USAGE_STATS_SERVICE) as UsageStatsManager
val calendar = Calendar.getInstance().apply {
set(Calendar.HOUR_OF_DAY, 0); set(Calendar.MINUTE, 0); set(Calendar.SECOND, 0); set(Calendar.MILLISECOND, 0)
}
val events = usm.queryEvents(calendar.timeInMillis, System.currentTimeMillis())
val event = UsageEvents.Event()
val appUsageMap = mutableMapOf<String, Long>()
val openApps = mutableMapOf<String, Long>()
var lastActivePackageName: String? = null
var screenOnTime: Long? = null
while (events.hasNextEvent()) {
events.getNextEvent(event)
val packageName = event.packageName
when (event.eventType) {
UsageEvents.Event.MOVE_TO_FOREGROUND -> {
// Wenn der Bildschirm gerade erst angegangen ist UND direkt eine NEUE App startet,
// löschen wir den Verdacht, dass die alte App weiterlief!
if (screenOnTime != null && packageName != lastActivePackageName) {
screenOnTime = null
}
// Falls der Verdacht stimmte und die ALTE App weiterlief:
if (screenOnTime != null && lastActivePackageName != null) {
openApps[lastActivePackageName] = screenOnTime!!
screenOnTime = null
}
openApps[packageName] = event.timeStamp
lastActivePackageName = packageName
}
UsageEvents.Event.MOVE_TO_BACKGROUND -> {
val start = openApps.remove(packageName)
if (start != null) {
val duration = event.timeStamp - start
appUsageMap[packageName] = appUsageMap.getOrDefault(packageName, 0L) + duration
}
}
UsageEvents.Event.SCREEN_NON_INTERACTIVE -> {
val now = event.timeStamp
openApps.forEach { (pkg, start) ->
appUsageMap[pkg] = appUsageMap.getOrDefault(pkg, 0L) + (now - start)
}
openApps.clear()
screenOnTime = null
}
UsageEvents.Event.SCREEN_INTERACTIVE -> {
// Wir merken uns NUR den Zeitpunkt. Wir tragen die App noch nicht als "laufend" ein!
// Wir warten ab, was das nächste Event sagt.
screenOnTime = event.timeStamp
}
}
}
// Am Ende der Schleife: Falls der Bildschirm an ging und DANACH kein Event mehr kam,
// lief die letzte App tatsächlich weiter.
if (screenOnTime != null && lastActivePackageName != null) {
openApps[lastActivePackageName] = screenOnTime!!
}
// Abrechnung bis JETZT
val now = System.currentTimeMillis()
openApps.forEach { (pkg, start) ->
appUsageMap[pkg] = appUsageMap.getOrDefault(pkg, 0L) + (now - start)
}
val pm = context.packageManager
appUsageMap.map { (pkg, ms) ->
val name = try { pm.getApplicationLabel(pm.getApplicationInfo(pkg, 0)).toString() } catch (e: Exception) { pkg }
AppUsageInfo(name, ms)
}.sortedByDescending { it.usageMs }
}
suspend fun getTotalScreenTime(context: Context): Long = withContext(Dispatchers.IO) {
val usm = context.getSystemService(Context.USAGE_STATS_SERVICE) as UsageStatsManager
val calendar = Calendar.getInstance().apply {
set(Calendar.HOUR_OF_DAY, 0)
set(Calendar.MINUTE, 0)
set(Calendar.SECOND, 0)
set(Calendar.MILLISECOND, 0)
}
val events = usm.queryEvents(calendar.timeInMillis, System.currentTimeMillis())
val event = UsageEvents.Event()
var totalTime = 0L
var sessionStartTime = 0L
val openApps = mutableSetOf<String>()
while (events.hasNextEvent()) {
events.getNextEvent(event)
val packageName = event.packageName
when (event.eventType) {
UsageEvents.Event.MOVE_TO_FOREGROUND -> {
if (openApps.isEmpty()) {
sessionStartTime = event.timeStamp
}
openApps.add(packageName)
}
UsageEvents.Event.MOVE_TO_BACKGROUND -> {
openApps.remove(packageName)
if (openApps.isEmpty() && sessionStartTime != 0L) {
totalTime += (event.timeStamp - sessionStartTime)
sessionStartTime = 0L
}
}
UsageEvents.Event.SCREEN_NON_INTERACTIVE -> {
if (sessionStartTime != 0L) {
totalTime += (event.timeStamp - sessionStartTime)
sessionStartTime = 0L
}
openApps.clear()
}
}
}
if (sessionStartTime != 0L) {
totalTime += (System.currentTimeMillis() - sessionStartTime)
}
// Das Ergebnis wird automatisch zurückgegeben
return@withContext totalTime
}
@@ -0,0 +1,268 @@
package de.schanbro.screenity
import android.content.Context
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.scaleIn
import androidx.compose.animation.scaleOut
import androidx.compose.animation.slideInHorizontally
import androidx.compose.animation.slideOutHorizontally
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.List
import androidx.compose.material.icons.filled.Edit
import androidx.compose.material.icons.filled.Info
import androidx.compose.material.icons.filled.Today
import androidx.compose.material.icons.filled.Devices
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material3.Button
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import androidx.compose.foundation.layout.height
import androidx.compose.material.icons.filled.PinDrop
import de.schanbro.screenity.ui.theme.ScreenityTheme
import androidx.compose.runtime.LaunchedEffect
import androidx.work.Constraints
import androidx.work.ExistingPeriodicWorkPolicy
import androidx.work.NetworkType
import androidx.work.PeriodicWorkRequestBuilder
import androidx.work.WorkManager
import java.util.concurrent.TimeUnit
sealed class Screen(val route: String) {
object Today : Screen("today_screen")
object Local : Screen("local_screen")
object Devices : Screen("devices_screen")
object Settings : Screen("settings_screen")
object DeviceDetail : Screen("device_detail/{deviceId}")
}
class MainActivity : ComponentActivity() {
@OptIn(ExperimentalMaterial3Api::class)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
ScreenityTheme {
val context = androidx.compose.ui.platform.LocalContext.current
val prefs = remember { context.getSharedPreferences("ScreenityPrefs", android.content.Context.MODE_PRIVATE) }
var serverUrl by remember {
mutableStateOf(prefs.getString("server_url", "") ?: "")
}
val savedInterval = prefs.getInt("upload_interval_mins", 15)
if (serverUrl.isBlank()) {
// Zeige Setup, wenn keine URL da ist
SetupScreen(onUrlSaved = { neueUrl ->
prefs.edit().putString("server_url", neueUrl).apply()
serverUrl = neueUrl // State-Update triggert Re-Composition
})
} else {
LaunchedEffect(serverUrl) {
if (serverUrl.isNotBlank()) {
// 1. SOFORTIGER UPLOAD BEIM APP-START
val totalMs = getTotalScreenTime(context)
val usageList = getTodayUsageEvents(context)
val detailedEvents = getDetailedEvents(applicationContext)
sendDataToServer(context, serverUrl, totalMs, usageList, detailedEvents)
// 2. 15-MINUTEN-AUTOMATISIERUNG EINRICHTEN
val constraints = Constraints.Builder()
.setRequiredNetworkType(NetworkType.CONNECTED) // Nur wenn Internet da ist
.build()
val uploadWorkRequest = PeriodicWorkRequestBuilder<UploadWorker>(
15, TimeUnit.MINUTES // Alle 15 Minuten (Minimum bei Android!)
)
.setConstraints(constraints)
.build()
// Dem System übergeben
WorkManager.getInstance(context).enqueueUniquePeriodicWork(
"ScreentimeUploadWork",
ExistingPeriodicWorkPolicy.KEEP, // Behält den alten Timer, falls die App neu startet
uploadWorkRequest
)
}
}
val navController = rememberNavController()
val currentBackStack by navController.currentBackStackEntryAsState()
val currentRoute = currentBackStack?.destination?.route
Scaffold(
modifier = Modifier.fillMaxSize(),
topBar = {
TopAppBar(
title = { Text(stringResource(R.string.app_name)) },
colors = TopAppBarDefaults.topAppBarColors(
containerColor = MaterialTheme.colorScheme.primaryContainer,
titleContentColor = MaterialTheme.colorScheme.primary
)
)
},
bottomBar = {
NavigationBar {
NavigationBarItem(
selected = currentRoute == Screen.Today.route,
onClick = { navController.navigate(Screen.Today.route) },
icon = { Icon(Icons.Default.Today, contentDescription = null) },
label = { Text(stringResource(R.string.Today)) }
)
NavigationBarItem(
selected = currentRoute == Screen.Local.route,
onClick = { navController.navigate(Screen.Local.route) },
icon = { Icon(Icons.Default.PinDrop, contentDescription = null) },
label = { Text(stringResource(R.string.Local)) }
)
NavigationBarItem(
selected = currentRoute == Screen.Devices.route,
onClick = { navController.navigate(Screen.Devices.route) },
icon = {
Icon(
Icons.Default.Devices,
contentDescription = null
)
},
label = { Text(stringResource(R.string.Devices)) }
)
NavigationBarItem(
selected = currentRoute == Screen.Settings.route,
onClick = { navController.navigate(Screen.Settings.route) },
icon = {
Icon(
Icons.Default.Settings,
contentDescription = null
)
},
label = { Text(stringResource(R.string.Settings)) }
)
}
}
) { innerPadding ->
NavHost(
navController = navController,
startDestination = de.schanbro.screenity.Screen.Today.route,
modifier = Modifier.padding(innerPadding),
enterTransition = { fadeIn(animationSpec = tween(220)) + scaleIn(initialScale = 0.92f) },
exitTransition = { fadeOut(animationSpec = tween(90)) },
popEnterTransition = { fadeIn(animationSpec = tween(220)) },
popExitTransition = { fadeOut(animationSpec = tween(90)) + scaleOut(targetScale = 0.92f) }
) {
composable(de.schanbro.screenity.Screen.Today.route) {
TodayScreen()
}
composable(de.schanbro.screenity.Screen.Local.route) {
LocalScreen()
}
composable(de.schanbro.screenity.Screen.Devices.route) {
DevicesScreen(onNavigateToDetail = { id ->
navController.navigate("device_detail/$id")
})
}
composable(de.schanbro.screenity.Screen.Settings.route) {
SettingsScreen()
}
composable(Screen.DeviceDetail.route) { backStackEntry ->
val deviceId = backStackEntry.arguments?.getString("deviceId") ?: ""
DeviceDetailScreen(
deviceId = deviceId,
onBack = { navController.popBackStack() } // Geht zurück zum TodayScreen
)
}
}
}
}
}
}
}
}
@Composable
fun SetupScreen(onUrlSaved: (String) -> Unit) {
var urlInput by remember { mutableStateOf("") }
Column(
modifier = Modifier.fillMaxSize().padding(24.dp),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(stringResource(R.string.welcome)+"!", style = MaterialTheme.typography.headlineSmall)
Text(stringResource(R.string.pls_enter_url))
Spacer(Modifier.height(16.dp))
OutlinedTextField(
value = urlInput,
onValueChange = { urlInput = it },
label = { Text(stringResource(R.string.ex_server_url)) },
modifier = Modifier.fillMaxWidth(),
placeholder = { Text("http://...") }
)
Spacer(Modifier.height(16.dp))
Button(
onClick = { if (urlInput.isNotBlank()) onUrlSaved(urlInput) },
modifier = Modifier.fillMaxWidth(),
enabled = urlInput.startsWith("http") // Kleine Sicherheitssperre
) {
Text(stringResource(R.string.connect_and_start))
}
}
}
fun updateUploadWork(context: Context, intervalMinutes: Long) {
val constraints = Constraints.Builder()
.setRequiredNetworkType(NetworkType.CONNECTED)
.build()
val uploadWorkRequest = PeriodicWorkRequestBuilder<UploadWorker>(
intervalMinutes, TimeUnit.MINUTES
)
.setConstraints(constraints)
.build()
// UPDATE steht hier für "REPLACE"
// Wenn sich das Intervall ändert, bricht Android den alten Timer ab
// und fängt mit der neuen Zeit von vorne an zu zählen!
WorkManager.getInstance(context).enqueueUniquePeriodicWork(
"ScreentimeUploadWork",
ExistingPeriodicWorkPolicy.REPLACE,
uploadWorkRequest
)
}
@@ -0,0 +1,87 @@
package de.schanbro.screenity
import android.content.Context
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.glance.GlanceId
import androidx.glance.GlanceModifier
import androidx.glance.appwidget.GlanceAppWidget
import androidx.glance.appwidget.GlanceAppWidgetReceiver
import androidx.glance.appwidget.GlanceAppWidgetManager
import androidx.glance.appwidget.provideContent
import androidx.glance.background
import androidx.glance.layout.*
import androidx.glance.text.FontWeight
import androidx.glance.text.Text
import androidx.glance.text.TextStyle
import androidx.glance.unit.ColorProvider
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
class ScreentimeWidget : GlanceAppWidget() {
override suspend fun provideGlance(context: Context, id: GlanceId) {
val appWidgetId = GlanceAppWidgetManager(context).getAppWidgetId(id)
val prefs = context.getSharedPreferences("ScreenityPrefs", Context.MODE_PRIVATE)
// 1. Welche Geräte hat der Nutzer in der Config gewählt?
val selectedDevices = prefs.getStringSet("widget_${appWidgetId}_devices", emptySet()) ?: emptySet()
val serverUrl = prefs.getString("server_url", "") ?: ""
var totalMs = 0L
// 2. ECHTE DATEN VOM SERVER HOLEN
if (serverUrl.isNotBlank()) {
try {
val result = withContext(Dispatchers.IO) {
getSummaryFromServer(serverUrl)
}
// HIER IST DIE KORREKTUR: Wir greifen erst auf .devices zu!
val allDevices = result.devices
// Jetzt können wir filtern
val filteredDevices = allDevices.filter { it.device_id in selectedDevices || it.device_name in selectedDevices }
totalMs = filteredDevices.sumOf { it.today_ms }
} catch (e: Exception) {
// Bei Netzwerkfehlern bleibt totalMs einfach auf 0 oder du nimmst einen Cache
}
}
// Zeit in Stunden und Minuten umrechnen
val hours = totalMs / 3600000
val minutes = (totalMs % 3600000) / 60000
val totalTimeText = String.format("%02dh %02dm", hours, minutes)
provideContent {
Column(
modifier = GlanceModifier
.fillMaxSize()
.background(Color.White)
.padding(12.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
text = "Gesamtzeit",
style = TextStyle(fontWeight = FontWeight.Bold, color = ColorProvider(Color.Black))
)
Spacer(GlanceModifier.height(4.dp))
Text(
text = totalTimeText,
style = TextStyle(fontWeight = FontWeight.Bold, color = ColorProvider(Color.Blue))
)
Spacer(GlanceModifier.height(4.dp))
Text(
text = "${selectedDevices.size} Geräte",
style = TextStyle(color = ColorProvider(Color.Gray))
)
}
}
}
}
class ScreentimeWidgetReceiver : GlanceAppWidgetReceiver() {
override val glanceAppWidget: GlanceAppWidget = ScreentimeWidget()
}
@@ -0,0 +1,150 @@
package de.schanbro.screenity
import android.content.Context
import androidx.compose.foundation.layout.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.CheckCircle
import androidx.compose.material.icons.filled.Error
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import de.schanbro.screenity.ui.theme.SuccessGreen
import kotlinx.coroutines.launch
import kotlin.math.roundToInt
// 1. ConnectionState erweitert, um Fehlermeldungen direkt mitzuführen
sealed class ConnectionState {
object Idle : ConnectionState()
object Loading : ConnectionState()
object Success : ConnectionState()
data class Error(val message: String) : ConnectionState() // Fehler trägt seine Nachricht selbst!
}
@Composable
fun SettingsScreen() {
val context = LocalContext.current
val scope = rememberCoroutineScope()
val prefs = remember { context.getSharedPreferences("ScreenityPrefs", Context.MODE_PRIVATE) }
var urlInput by remember { mutableStateOf(prefs.getString("server_url", "") ?: "") }
var status by remember { mutableStateOf<ConnectionState>(ConnectionState.Idle) }
// Intervall auslesen (Standard: 15 Minuten)
var selectedInterval by remember { mutableIntStateOf(prefs.getInt("upload_interval_mins", 15)) }
ScreenWrapper(title = stringResource(R.string.Settings)) {
OutlinedTextField(
value = urlInput,
onValueChange = { urlInput = it; status = ConnectionState.Idle },
label = { Text(stringResource(R.string.server_url)) },
modifier = Modifier.fillMaxWidth()
)
Spacer(Modifier.height(24.dp))
// --- MATERIAL 3 SLIDER ---
Text(
text = "Upload-Intervall: $selectedInterval Minuten",
style = MaterialTheme.typography.titleSmall
)
Slider(
value = selectedInterval.toFloat(),
onValueChange = {
selectedInterval = it.roundToInt()
},
valueRange = 15f..120f,
steps = 6
)
// Kleine Beschriftung unter dem Slider
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween
) {
Text("15 min", style = MaterialTheme.typography.bodySmall)
Text("120 min", style = MaterialTheme.typography.bodySmall)
}
Spacer(Modifier.height(32.dp))
val errorMessage = stringResource(R.string.error)
Button(
onClick = {
// 1. Einstellungen speichern
prefs.edit()
.putString("server_url", urlInput)
.putInt("upload_interval_mins", selectedInterval)
.apply()
// 2. WorkManager mit neuem Intervall updaten!
updateUploadWork(context, selectedInterval.toLong())
scope.launch {
status = ConnectionState.Loading
try {
getSummaryFromServer(urlInput)
status = ConnectionState.Success
} catch (e: Exception) {
val detail = e.localizedMessage ?: errorMessage
status = ConnectionState.Error(detail)
}
}
},
modifier = Modifier.fillMaxWidth()
) {
Text(stringResource(R.string.save_and_try))
}
Spacer(Modifier.height(24.dp))
ConnectionStatusWidget(state = status)
}
}
@Composable
fun ConnectionStatusWidget(state: ConnectionState) {
when (state) {
is ConnectionState.Loading -> {
Box(Modifier.fillMaxWidth(), contentAlignment = Alignment.Center) {
CircularProgressIndicator()
}
}
is ConnectionState.Success -> {
Row(verticalAlignment = Alignment.CenterVertically) {
Icon(Icons.Default.CheckCircle, "OK", tint = SuccessGreen)
Spacer(Modifier.width(8.dp))
Text(
text = stringResource(R.string.connection_successful),
color = SuccessGreen,
style = MaterialTheme.typography.titleSmall
)
}
}
is ConnectionState.Error -> {
Row(verticalAlignment = Alignment.CenterVertically) {
Icon(Icons.Default.Error, stringResource(R.string.error), tint = MaterialTheme.colorScheme.error)
Spacer(Modifier.width(8.dp))
Column {
Text(
text = stringResource(R.string.server_not_reachable),
color = MaterialTheme.colorScheme.error,
style = MaterialTheme.typography.titleSmall
)
Text(
text = state.message,
color = MaterialTheme.colorScheme.error,
style = MaterialTheme.typography.bodySmall
)
}
}
}
else -> {}
}
}
@@ -0,0 +1,42 @@
package de.schanbro.screenity
import androidx.compose.foundation.layout.*
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
// Das ist wie eine CSS-Klasse für die Screen-Struktur!
@Composable
fun ScreenWrapper(
title: String,
headerAction: @Composable (() -> Unit)? = null,
content: @Composable ColumnScope.() -> Unit
) {
Column(
modifier = Modifier
.fillMaxSize()
.padding(16.dp) // Zentrales Padding für die gesamte App
) {
// Einheitlicher Header für alle Screens
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.Top
) {
Text(
text = title,
style = MaterialTheme.typography.headlineMedium,
color = MaterialTheme.colorScheme.onSurface
)
headerAction?.invoke()
}
Spacer(Modifier.height(16.dp))
// Hier wird der eigentliche Inhalt des Screens eingesetzt
content()
}
}
@@ -0,0 +1,112 @@
package de.schanbro.screenity
import android.app.usage.UsageEvents
import android.app.usage.UsageStatsManager
import android.content.Context
import android.content.Intent
import android.provider.Settings
import android.widget.Toast
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.CloudUpload
import androidx.compose.material.icons.filled.Refresh
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.google.gson.Gson
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody.Companion.toRequestBody
import java.text.SimpleDateFormat
import java.util.*
data class ServerSummary(
val devices: List<DeviceSummary>,
val total_all_devices_hours: Double,
val today_total_all_devices_ms: Long
)
@Composable
fun TodayScreen() {
val context = LocalContext.current
val scope = rememberCoroutineScope()
val prefs = remember { context.getSharedPreferences("ScreenityPrefs", Context.MODE_PRIVATE) }
val serverUrl = prefs.getString("server_url", "") ?: ""
var summary by remember { mutableStateOf<ServerSummary?>(null) }
var isLoading by remember { mutableStateOf(false) }
fun fetch() {
if (serverUrl.isBlank()) return
scope.launch {
isLoading = true
try {
summary = getSummaryFromServer(serverUrl)
} catch (e: Exception) {
}
isLoading = false
}
}
LaunchedEffect(Unit) { fetch() }
ScreenWrapper(
title = stringResource(R.string.all_time),
headerAction = {
IconButton(onClick = { fetch() }) {
Icon(Icons.Default.Refresh, contentDescription = null)
}
}
) {
if (isLoading) {
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
CircularProgressIndicator()
}
} else {
summary?.let {
// Nutzt die bereits definierte Card für die große Anzeige
TotalAllDevicesCard(it.today_total_all_devices_ms)
}
}
}
}
@Composable
fun TotalAllDevicesCard(totalMs: Long) {
val h = totalMs / 3600000
val m = (totalMs % 3600000) / 60000
val s = (totalMs % 60000) / 1000
Card(
modifier = Modifier
.fillMaxWidth()
.padding(bottom = 16.dp),
colors = CardDefaults.cardColors(
containerColor = MaterialTheme.colorScheme.tertiaryContainer
)
) {
Column(Modifier.padding(16.dp)) {
Text(
text = stringResource(R.string.all_time),
style = MaterialTheme.typography.titleSmall,
color = MaterialTheme.colorScheme.onTertiary
)
Text(
text = String.format("%02dh %02dm %02ds", h, m, s),
style = MaterialTheme.typography.displayMedium,
fontFamily = androidx.compose.ui.text.font.FontFamily.Monospace
)
}
}
}
@@ -0,0 +1,46 @@
package de.schanbro.screenity
import android.content.Context
import androidx.work.CoroutineWorker
import androidx.work.WorkerParameters
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
class UploadWorker(
appContext: Context,
workerParams: WorkerParameters
) : CoroutineWorker(appContext, workerParams) {
override suspend fun doWork(): Result = withContext(Dispatchers.IO) {
val prefs = applicationContext.getSharedPreferences("ScreenityPrefs", Context.MODE_PRIVATE)
val serverUrl = prefs.getString("server_url", "") ?: ""
if (serverUrl.isBlank()) {
return@withContext Result.failure()
}
try {
// 1. Daten sammeln (Nutzt deine optimierten Funktionen!)
val totalMs = getTotalScreenTime(applicationContext)
val usageList = getTodayUsageEvents(applicationContext)
val detailedEvents = getDetailedEvents(applicationContext)
// 2. An den Server senden (deine bestehende Funktion)
val success = sendDataToServer(
applicationContext,
serverUrl,
totalMs,
usageList,
detailedEvents
)
if (success) {
Result.success()
} else {
Result.retry() // Android versucht es später nochmal, falls der Server offline war
}
} catch (e: Exception) {
Result.failure()
}
}
}
@@ -0,0 +1,46 @@
package de.schanbro.screenity
import android.annotation.SuppressLint
import android.app.usage.UsageEvents
import android.app.usage.UsageStatsManager
import android.content.Context
import java.util.Calendar
data class ScreenEvent(
val timestamp: Long,
val type: String, // "SCREEN_ON", "SCREEN_OFF", "APP_OPEN", "APP_CLOSE"
val packageName: String? = null
)
@SuppressLint("ServiceCast")
fun getDetailedEvents(context: Context): List<ScreenEvent> {
val usageStatsManager = context.getSystemService(Context.USAGE_STATS_SERVICE) as UsageStatsManager
val calendar = Calendar.getInstance()
calendar.set(Calendar.HOUR_OF_DAY, 0)
calendar.set(Calendar.MINUTE, 0)
calendar.set(Calendar.SECOND, 0)
val events = usageStatsManager.queryEvents(calendar.timeInMillis, System.currentTimeMillis())
val eventList = mutableListOf<ScreenEvent>()
val event = UsageEvents.Event()
while (events.hasNextEvent()) {
events.getNextEvent(event)
val type = when (event.eventType) {
UsageEvents.Event.SCREEN_INTERACTIVE -> "SCREEN_ON"
UsageEvents.Event.SCREEN_NON_INTERACTIVE -> "SCREEN_OFF"
UsageEvents.Event.ACTIVITY_RESUMED -> "APP_OPEN"
UsageEvents.Event.ACTIVITY_PAUSED -> "APP_CLOSE"
else -> null
}
if (type != null) {
eventList.add(ScreenEvent(
timestamp = event.timeStamp,
type = type,
packageName = if (type.startsWith("APP")) event.packageName else null
))
}
}
return eventList
}
@@ -0,0 +1,103 @@
package de.schanbro.screenity
import android.app.Activity
import android.appwidget.AppWidgetManager
import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
class WidgetConfigActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val appWidgetId = intent?.extras?.getInt(
AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID
) ?: AppWidgetManager.INVALID_APPWIDGET_ID
if (appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
finish()
return
}
setContent {
MaterialTheme {
Surface(modifier = Modifier.fillMaxSize()) {
WidgetConfigScreen(appWidgetId = appWidgetId) {
val resultValue = Intent().apply {
putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId)
}
setResult(Activity.RESULT_OK, resultValue)
finish()
}
}
}
}
}
}
@Composable
fun WidgetConfigScreen(appWidgetId: Int, onFinished: () -> Unit) {
val context = LocalContext.current
val prefs = remember { context.getSharedPreferences("ScreenityPrefs", Context.MODE_PRIVATE) }
// ECHTE DATEN: Wir lesen die bekannten Geräte-IDs aus den SharedPreferences
// (Diese Liste füllst du am besten immer auf, wenn du Daten vom Server erfolgreich abrufst)
val deviceIds = remember {
prefs.getStringSet("known_device_ids", setOf("Dieses Gerät")) ?: setOf("Dieses Gerät")
}.toList()
val selectedDevices = remember { mutableStateListOf<String>() }
Column(modifier = Modifier.padding(16.dp)) {
Text("Widget konfigurieren", style = MaterialTheme.typography.headlineSmall)
Spacer(Modifier.height(8.dp))
Text("Wähle die Geräte aus, deren Zeit addiert werden soll:", style = MaterialTheme.typography.bodyMedium)
Spacer(Modifier.height(16.dp))
// LazyColumn für den Fall, dass du sehr viele Geräte hast
LazyColumn(modifier = Modifier.weight(1f)) {
items(deviceIds) { deviceId ->
Row(
modifier = Modifier.fillMaxWidth().padding(vertical = 4.dp),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Text(deviceId, style = MaterialTheme.typography.bodyLarge)
Checkbox(
checked = selectedDevices.contains(deviceId),
onCheckedChange = { checked ->
if (checked) selectedDevices.add(deviceId) else selectedDevices.remove(deviceId)
}
)
}
}
}
Spacer(Modifier.height(16.dp))
Button(
onClick = {
// Konfiguration für dieses spezifische Widget speichern
prefs.edit().putStringSet("widget_${appWidgetId}_devices", selectedDevices.toSet()).apply()
onFinished()
},
modifier = Modifier.fillMaxWidth(),
enabled = selectedDevices.isNotEmpty()
) {
Text("Widget erstellen")
}
}
}
@@ -0,0 +1,12 @@
package de.schanbro.screenity.ui.theme
import androidx.compose.ui.graphics.Color
val Purple80 = Color(0xFFD0BCFF)
val PurpleGrey80 = Color(0xFFCCC2DC)
val Pink80 = Color(0xFFEFB8C8)
val Purple40 = Color(0xFF6650a4)
val PurpleGrey40 = Color(0xFF625b71)
val Pink40 = Color(0xFF7D5260)
val SuccessGreen = Color(0xFF4CAF50)
@@ -0,0 +1,58 @@
package de.schanbro.screenity.ui.theme
import android.app.Activity
import android.os.Build
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
private val DarkColorScheme = darkColorScheme(
primary = Purple80,
secondary = PurpleGrey80,
tertiary = Pink80
)
private val LightColorScheme = lightColorScheme(
primary = Purple40,
secondary = PurpleGrey40,
tertiary = Pink40
/* Other default colors to override
background = Color(0xFFFFFBFE),
surface = Color(0xFFFFFBFE),
onPrimary = Color.White,
onSecondary = Color.White,
onTertiary = Color.White,
onBackground = Color(0xFF1C1B1F),
onSurface = Color(0xFF1C1B1F),
*/
)
@Composable
fun ScreenityTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
// Dynamic color is available on Android 12+
dynamicColor: Boolean = true,
content: @Composable () -> Unit
) {
val colorScheme = when {
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
val context = LocalContext.current
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
}
darkTheme -> DarkColorScheme
else -> LightColorScheme
}
MaterialTheme(
colorScheme = colorScheme,
typography = Typography,
content = content
)
}
@@ -0,0 +1,81 @@
package de.schanbro.screenity.ui.theme
import androidx.compose.material3.Typography
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.sp
// Set of Material typography styles to start with
val Typography = Typography(
displayMedium = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Black,
fontSize = 32.sp,
lineHeight = 40.sp,
letterSpacing = 0.sp
),
headlineLarge = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Black,
fontSize = 32.sp,
lineHeight = 40.sp,
letterSpacing = 0.sp
),
headlineMedium = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Black,
fontSize = 28.sp,
lineHeight = 36.sp,
letterSpacing = 0.sp
),
headlineSmall = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Bold,
fontSize = 24.sp,
lineHeight = 32.sp,
letterSpacing = 0.sp
),
titleLarge = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Bold,
fontSize = 20.sp,
lineHeight = 28.sp,
letterSpacing = 0.sp
),
titleMedium = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Bold,
fontSize = 18.sp,
lineHeight = 24.sp,
letterSpacing = 0.15.sp
),
titleSmall = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Medium,
fontSize = 14.sp,
lineHeight = 20.sp,
letterSpacing = 0.1.sp
),
bodyLarge = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 16.sp,
lineHeight = 24.sp,
letterSpacing = 0.5.sp
),
bodyMedium = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 14.sp,
lineHeight = 20.sp,
letterSpacing = 0.25.sp
),
labelSmall = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Medium,
fontSize = 11.sp,
lineHeight = 16.sp,
letterSpacing = 0.5.sp
)
)
@@ -0,0 +1,14 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="123.38dp"
android:height="123.45dp"
android:viewportWidth="123.38"
android:viewportHeight="123.45">
<path
android:pathData="M10.44,92.38 L82.86,19.62A32.17,32.02 90,1 0,50.46 73.01L72.92,50.44A32.17,32.02 90,1 1,40.52 103.83l72.42,-72.76"
android:strokeWidth="5.1"
android:fillColor="#00000000"
android:strokeColor="#000000"
android:fillType="evenOdd"
android:strokeLineCap="square"/>
</vector>
@@ -0,0 +1,10 @@
<?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="#1976D2"
android:pathData="M0,0h108v108h-108z" />
</vector>
@@ -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>
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="utf-8"?>
<vector
android:height="108dp"
android:width="108dp"
android:viewportHeight="108"
android:viewportWidth="108"
xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#3DDC84"
android:pathData="M0,0h108v108h-108z"/>
<path android:fillColor="#00000000" android:pathData="M9,0L9,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,0L19,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M29,0L29,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M39,0L39,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M49,0L49,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M59,0L59,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M69,0L69,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M79,0L79,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M89,0L89,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M99,0L99,108"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,9L108,9"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,19L108,19"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,29L108,29"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,39L108,39"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,49L108,49"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,59L108,59"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,69L108,69"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,79L108,79"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,89L108,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M0,99L108,99"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,29L89,29"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,39L89,39"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,49L89,49"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,59L89,59"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,69L89,69"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M19,79L89,79"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M29,19L29,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M39,19L39,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M49,19L49,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M59,19L59,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M69,19L69,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
<path android:fillColor="#00000000" android:pathData="M79,19L79,89"
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
</vector>
@@ -0,0 +1,19 @@
<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="123.38"
android:viewportHeight="123.45">
<group android:scaleX="0.6871102"
android:scaleY="0.6875"
android:translateX="20.08758"
android:translateY="16.538586">
<path
android:pathData="M10.44,92.38 L82.86,19.62A32.17,32.02 90,1 0,50.46 73.01L72.92,50.44A32.17,32.02 90,1 1,40.52 103.83l72.42,-72.76"
android:strokeWidth="5.1"
android:fillColor="#00000000"
android:strokeColor="#000000"
android:fillType="evenOdd"
android:strokeLineCap="square"/>
</group>
</vector>
Binary file not shown.
@@ -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="@color/screenity_edited_background"/>
<foreground android:drawable="@drawable/screenity_edited_foreground"/>
</adaptive-icon>
@@ -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="@color/screenity_edited_background"/>
<foreground android:drawable="@drawable/screenity_edited_foreground"/>
</adaptive-icon>
@@ -0,0 +1,6 @@
<?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" />
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>
@@ -0,0 +1,6 @@
<?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" />
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 982 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

+28
View File
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="Today">Today</string>
<string name="Devices">Devices</string>
<string name="Settings">Settings</string>
<string name="welcome">Welcome</string>
<string name="pls_enter_url">Please enter the server-URL to start.</string>
<string name="local_usagetime">Local time of usage</string>
<string name="refresh">Refresh</string>
<string name="no_data_permission">Couldn\'t find any data. Did you gave the permission?</string>
<string name="open_settings">Open settings!</string>
<string name="Local">Local</string>
<string name="all_time">All time</string>
<string name="ex_server_url">Server-URL (e. g. http://192.168.178.50:5000)</string>
<string name="connect_and_start">Connect and start</string>
<string name="devices_overview">Overview of devices</string>
<string name="all_devices_together">All devices combined</string>
<string name="this_device">This divice</string>
<string name="sent">Sent</string>
<string name="error">Error</string>
<string name="upload_data">Upload data</string>
<string name="server_url">Server-URL</string>
<string name="save_and_try">Save and try</string>
<string name="connection_successful">Connection successful!</string>
<string name="server_not_reachable">Server not reachable</string>
<string name="server_response">Server responses with code:</string>
<string name="unknown_network_error">Unknown network error</string>
</resources>
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="Today">Aujourd’hui</string>
<string name="Devices">Appareils</string>
<string name="Settings">Paramètres</string>
<string name="welcome">Bienvenue</string>
<string name="pls_enter_url">Veuillez saisir l’URL du serveur pour démarrer</string>
<string name="local_usagetime">Temps locale de utiliser</string>
<string name="refresh">Acutaliser</string>
<string name="no_data_permission">Grrrr les francais!!!</string>
<string name="open_settings">Ouvrir les parametrès!</string>
<string name="Local">Locale</string>
<string name="all_time">Tout les temps</string>
<string name="ex_server_url">L\'URL du serveur (p. e. http://192.168.178.50:5000)</string>
<string name="connect_and_start">Connecter et parir</string>
<string name="devices_overview">\?</string>
<string name="all_devices_together">\?</string>
<string name="this_device">Ce appareil</string>
<string name="sent">\?</string>
<string name="error">\?</string>
<string name="upload_data">\?</string>
<string name="server_url">L\'URL du serveur</string>
<string name="save_and_try">Saver et essayer</string>
<string name="connection_successful">\?</string>
<string name="server_not_reachable">\?</string>
<string name="server_response">Codé:</string>
<string name="unknown_network_error">\?</string>
</resources>
+28
View File
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="Today">\?</string>
<string name="server_response">\?</string>
<string name="unknown_network_error">\?</string>
<string name="Devices">\?</string>
<string name="Settings">\?</string>
<string name="welcome">\?</string>
<string name="pls_enter_url">\?</string>
<string name="local_usagetime">\?</string>
<string name="all_time">\?</string>
<string name="ex_server_url">\?</string>
<string name="refresh">\?</string>
<string name="no_data_permission">\?</string>
<string name="open_settings">\?</string>
<string name="Local">\?</string>
<string name="connect_and_start">\?</string>
<string name="devices_overview">\?</string>
<string name="all_devices_together">\?</string>
<string name="this_device">\?</string>
<string name="sent">\?</string>
<string name="error">\?</string>
<string name="upload_data">\?</string>
<string name="server_url">\?</string>
<string name="save_and_try">\?</string>
<string name="connection_successful">\?</string>
<string name="server_not_reachable">\?</string>
</resources>
+10
View File
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="purple_200">#FFBB86FC</color>
<color name="purple_500">#FF6200EE</color>
<color name="purple_700">#FF3700B3</color>
<color name="teal_200">#FF03DAC5</color>
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
</resources>
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="screenity_edited_background">#3DDC84</color>
</resources>
+28
View File
@@ -0,0 +1,28 @@
<resources>
<string name="app_name" translatable="false">Screenity</string>
<string name="Today">Heute</string>
<string name="Devices">Geräte</string>
<string name="Settings">Einstellungen</string>
<string name="welcome">Willkommen</string>
<string name="pls_enter_url">Bitte gib die Server-URL ein, um zu starten.</string>
<string name="local_usagetime">Lokale Nutzungszeit</string>
<string name="refresh">Aktualisieren</string>
<string name="no_data_permission">Keine Daten gefunden. Hast du die Berechtigung erteilt?</string>
<string name="open_settings">Einstellungen öffnen!</string>
<string name="Local">Lokal</string>
<string name="all_time">Gesamte Bildschirmzeit</string>
<string name="ex_server_url">Server URL (z.B. http://192.168.178.50:5000)</string>
<string name="connect_and_start">Verbinden und Starten</string>
<string name="devices_overview">Geräteübersicht</string>
<string name="all_devices_together">Alle Geräte kombiniert</string>
<string name="this_device">Dieses Gerät</string>
<string name="sent">Gesendet</string>
<string name="error">Fehler</string>
<string name="upload_data">Daten hochladen</string>
<string name="server_url">Server URL</string>
<string name="save_and_try">Speichern und testen</string>
<string name="connection_successful">Verbindung erfolgreich!</string>
<string name="server_not_reachable">Server nicht erreichbar</string>
<string name="server_response">Server antwortet mit Code:</string>
<string name="unknown_network_error">Unbekannter Netzwerkfehler</string>
</resources>
+5
View File
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Screenity" parent="android:Theme.Material.Light.NoActionBar" />
</resources>
+13
View File
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?><!--
Sample backup rules file; uncomment and customize as necessary.
See https://developer.android.com/guide/topics/data/autobackup
for details.
Note: This file is ignored for devices older than API 31
See https://developer.android.com/about/versions/12/backup-restore
-->
<full-backup-content>
<!--
<include domain="sharedpref" path="."/>
<exclude domain="sharedpref" path="device.xml"/>
-->
</full-backup-content>
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?><!--
Sample data extraction rules file; uncomment and customize as necessary.
See https://developer.android.com/about/versions/12/backup-restore#xml-changes
for details.
-->
<data-extraction-rules>
<cloud-backup>
<!-- TODO: Use <include> and <exclude> to control what is backed up.
<include .../>
<exclude .../>
-->
</cloud-backup>
<!--
<device-transfer>
<include .../>
<exclude .../>
</device-transfer>
-->
</data-extraction-rules>
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="110dp"
android:minHeight="110dp"
android:updatePeriodMillis="900000"
android:configure="de.schanbro.screenity.WidgetConfigActivity"
android:resizeMode="horizontal|vertical"
android:widgetCategory="home_screen">
</appwidget-provider>
Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

@@ -0,0 +1,17 @@
package de.schanbro.screenity
import org.junit.Test
import org.junit.Assert.*
/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}