From b6df86f49a07b473f88970973b5e79e0a74f8f04 Mon Sep 17 00:00:00 2001 From: David Madl Date: Sun, 22 Mar 2026 09:20:13 +0100 Subject: [PATCH] chore: generic LstForegroundService housekeeping --- .../at/lockstep/app/LstForegroundService.java | 16 ++++++++++------ app/src/main/res/values/strings.xml | 1 + 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/at/lockstep/app/LstForegroundService.java b/app/src/main/java/at/lockstep/app/LstForegroundService.java index e98cc5a..56cd573 100644 --- a/app/src/main/java/at/lockstep/app/LstForegroundService.java +++ b/app/src/main/java/at/lockstep/app/LstForegroundService.java @@ -23,6 +23,8 @@ import androidx.core.app.NotificationCompat; import java.io.FileNotFoundException; import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; import at.lockstep.filter.StepDetector; import at.lockstep.pb.PlaybackEngine; @@ -129,7 +131,7 @@ public class LstForegroundService extends Service implements SensorEventListener return; } - startForeground(NOTIFICATION_ID, buildNotification("Lockstep is reading your steps ...")); + startForeground(NOTIFICATION_ID, buildNotification()); if (wakeLock != null && !wakeLock.isHeld()) { // TODO: provide a timeout reasonable for a run @@ -137,6 +139,8 @@ public class LstForegroundService extends Service implements SensorEventListener } if (accelerometer != null && sensorManager != null) { + // TODO: use a HandlerThread to handle sensor events in background thread, not the main thread + // see https://stackoverflow.com/q/17681870/1616948 sensorManager.registerListener( this, accelerometer, @@ -200,11 +204,11 @@ public class LstForegroundService extends Service implements SensorEventListener @Override public void onAccuracyChanged(Sensor sensor, int accuracy) {} - private Notification buildNotification(String contentText) { + private Notification buildNotification() { return new NotificationCompat.Builder(this, CHANNEL_ID) - .setContentTitle("Lockstep is reading your pace.") - .setContentText(contentText) - .setSmallIcon(android.R.drawable.ic_menu_compass) + .setContentTitle(getString(R.string.app_name)) + .setContentText(getString(R.string.notification_text)) + .setSmallIcon(getApplicationInfo().icon) .setOngoing(true) .build(); } @@ -213,7 +217,7 @@ public class LstForegroundService extends Service implements SensorEventListener if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel( CHANNEL_ID, - "Lockstep", + getString(R.string.app_name), NotificationManager.IMPORTANCE_LOW ); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 35a425e..4752872 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,3 +1,4 @@ Lockstep + Reading your steps … \ No newline at end of file