1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-03 17:02:13 +01:00

add debug features for openTracksObserver

This commit is contained in:
vanous 2022-02-20 15:43:52 +01:00
parent b5632e91d0
commit 79e0c01f60
2 changed files with 94 additions and 0 deletions

View File

@ -35,6 +35,7 @@ import android.content.IntentFilter;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.text.Editable; import android.text.Editable;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.TextWatcher; import android.text.TextWatcher;
@ -70,6 +71,8 @@ import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Random; import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
import java.util.TreeMap; import java.util.TreeMap;
import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.GBApplication;
@ -83,6 +86,8 @@ import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceManager; import nodomain.freeyourgadget.gadgetbridge.devices.DeviceManager;
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession; import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
import nodomain.freeyourgadget.gadgetbridge.entities.Device; import nodomain.freeyourgadget.gadgetbridge.entities.Device;
import nodomain.freeyourgadget.gadgetbridge.externalevents.OpenTracksContentObserver;
import nodomain.freeyourgadget.gadgetbridge.externalevents.OpenTracksController;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample; import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec; import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
@ -508,6 +513,72 @@ public class DebugActivity extends AbstractGBActivity {
} }
}); });
Button startFitnessAppTracking = findViewById(R.id.startFitnessAppTracking);
startFitnessAppTracking.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
OpenTracksController.startRecording(DebugActivity.this);
}
});
Button stopFitnessAppTracking = findViewById(R.id.stopFitnessAppTracking);
stopFitnessAppTracking.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
OpenTracksController.stopRecording(DebugActivity.this);
}
});
Button showStatusFitnessAppTracking = findViewById(R.id.showStatusFitnessAppTracking);
final int delay = 2 * 1000;
showStatusFitnessAppTracking.setOnClickListener(new View.OnClickListener() {
final Handler handler = new Handler();
Runnable runnable;
@Override
public void onClick(View v) {
final AlertDialog.Builder fitnesStatusBuilder = new AlertDialog.Builder(DebugActivity.this);
fitnesStatusBuilder
.setCancelable(false)
.setTitle("openTracksObserver Status")
.setMessage("Starting openTracksObserver watcher, waiting for an update, refreshing every: " + delay + "ms")
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
handler.removeCallbacks(runnable);
}
});
final AlertDialog alert = fitnesStatusBuilder.show();
runnable = new Runnable() {
@Override
public void run() {
LOG.debug("openTracksObserver debug watch dialog running");
handler.postDelayed(this, delay); //schedule next execution
OpenTracksContentObserver openTracksObserver = GBApplication.app().getOpenTracksObserver();
if (openTracksObserver == null) {
LOG.debug("openTracksObserver is null");
alert.cancel();
alert.setMessage("openTracksObserver not running");
alert.show();
return;
}
LOG.debug("openTracksObserver is not null, updating debug view");
long timeSecs = openTracksObserver.getTimeMillisChange() / 1000;
float distanceCM = openTracksObserver.getDistanceMeterChange() * 100;
LOG.debug("Time: " + timeSecs + " distanceCM " + distanceCM);
alert.cancel();
alert.setMessage("TimeSec: " + timeSecs + " distanceCM " + distanceCM);
alert.show();
}
};
handler.postDelayed(runnable, delay);
}
});
} }

View File

@ -233,6 +233,29 @@
grid:layout_columnSpan="2" grid:layout_columnSpan="2"
grid:layout_gravity="fill_horizontal" /> grid:layout_gravity="fill_horizontal" />
<Button
android:id="@+id/startFitnessAppTracking"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pref_device_action_fitness_app_control_start"
grid:layout_columnSpan="2"
grid:layout_gravity="fill_horizontal" />
<Button
android:id="@+id/stopFitnessAppTracking"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pref_device_action_fitness_app_control_stop"
grid:layout_columnSpan="2"
grid:layout_gravity="fill_horizontal" />
<Button
android:id="@+id/showStatusFitnessAppTracking"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Fit.App.Track. Status"
grid:layout_columnSpan="2"
grid:layout_gravity="fill_horizontal" />
</androidx.gridlayout.widget.GridLayout> </androidx.gridlayout.widget.GridLayout>
</ScrollView> </ScrollView>