Skip to content

Commit 5dbc540

Browse files
Merge pull request #81 from Botts-Innovative-Research/78-add-a-progress-indicator
add loading to start/stop fab
2 parents 31e6c62 + 5fe3307 commit 5dbc540

3 files changed

Lines changed: 41 additions & 6 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24"
5+
android:viewportHeight="24">
6+
<path
7+
android:pathData="M12,4V2C6.48,2 2,6.48 2,12h2c0,-4.42 3.58,-8 8,-8z"
8+
android:fillColor="@android:color/white" />
9+
</vector>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:drawable="@drawable/ic_loading"
4+
android:pivotX="50%"
5+
android:pivotY="50%" />

sensorhub-android-app/src/org/sensorhub/android/DashboardFragment.java

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,19 +184,38 @@ private void updateFabIcon() {
184184
}
185185
}
186186

187+
private void showFabProgress() {
188+
if (fab == null) return;
189+
fab.setImageResource(R.drawable.ic_loading_animated);
190+
fab.setEnabled(false);
191+
}
192+
193+
private void hideFabProgress() {
194+
if (fab == null) return;
195+
fab.setEnabled(true);
196+
updateFabIcon();
197+
}
198+
187199
private void stopHub() {
188-
Toast.makeText(requireContext(), R.string.stopping_sensorhub, Toast.LENGTH_SHORT).show();
200+
showFabProgress();
201+
newStatusMessage(getString(R.string.stopping_sensorhub));
189202
stopRefreshingStatus();
190-
provider.stopSensorHub();
191-
updateFabIcon();
192203
hideVideoPreview();
193204
clearTextureView();
194205
videoStatusCard.setVisibility(View.GONE);
195206
if (videoControlsOverlay != null) videoControlsOverlay.setVisibility(View.GONE);
196207
currentZoomLevel = 0;
197208
if (meshtasticCard != null) meshtasticCard.setVisibility(View.GONE);
198-
newStatusMessage(getString(R.string.sensorhub_stopped));
199-
requireActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
209+
provider.stopSensorHub();
210+
211+
// Brief delay to let the service finish stopping on its background thread
212+
displayHandler.postDelayed(() -> {
213+
if (!isAdded()) return;
214+
hideFabProgress();
215+
updateFabIcon();
216+
newStatusMessage(getString(R.string.sensorhub_stopped));
217+
requireActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
218+
}, 1000);
200219
}
201220

202221
private void clearTextureView() {
@@ -248,7 +267,7 @@ public void onClick(DialogInterface dialog, int whichButton) {
248267
showVideoConfigErrorPopup();
249268
newStatusMessage(getString(R.string.video_config_error));
250269
} else {
251-
Toast.makeText(requireContext(), R.string.starting_sensorhub, Toast.LENGTH_SHORT).show();
270+
showFabProgress();
252271
newStatusMessage(getString(R.string.starting_sensorhub));
253272
provider.getSostClients().clear();
254273
provider.getConSysClients().clear();
@@ -297,6 +316,7 @@ private void pollHubReady() {
297316

298317
if (!provider.isOshStarted()) {
299318
provider.setOshStarted(true);
319+
hideFabProgress();
300320
updateFabIcon();
301321
serverStatusContainer.removeAllViews();
302322
serverCardViews.clear();
@@ -309,6 +329,7 @@ private void pollHubReady() {
309329
} else if (hubPollAttempts < HUB_POLL_MAX_ATTEMPTS) {
310330
displayHandler.postDelayed(this::pollHubReady, HUB_POLL_INTERVAL_MS);
311331
} else {
332+
hideFabProgress();
312333
newStatusMessage(getString(R.string.sensorhub_start_failed));
313334
updateFabIcon();
314335
}

0 commit comments

Comments
 (0)