Skip to content

Commit d2bd01f

Browse files
fix: accelerometer screen crash and ui (#2656)
Co-authored-by: Marc Nause <[email protected]>
1 parent 3872548 commit d2bd01f

File tree

3 files changed

+37
-32
lines changed

3 files changed

+37
-32
lines changed

app/src/main/java/io/pslab/fragment/AccelerometerDataFragment.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ private void writeLogToFile(long timestamp, float readingX, float readingY, floa
419419
}
420420

421421
private void visualizeData() {
422+
if (!isAdded()) return;
422423
for (int i = 0; i < accelerometerViewFragments.size(); i++) {
423424
AccelerometerViewFragment fragment = accelerometerViewFragments.get(i);
424425
long timeElapsed = (System.currentTimeMillis() - startTime) / 1000;
Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,41 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<LinearLayout android:id="@+id/accelerometer_linearlayout"
3-
xmlns:android="http://schemas.android.com/apk/res/android"
2+
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
43
xmlns:tools="http://schemas.android.com/tools"
54
android:layout_width="match_parent"
65
android:layout_height="match_parent"
7-
android:fitsSystemWindows="true"
8-
android:orientation="vertical"
9-
tools:context="io.pslab.activity.AccelerometerActivity">
6+
android:fitsSystemWindows="true">
107

11-
<fragment
12-
android:id="@+id/accelerometer_x_axis_fragment"
13-
android:name="io.pslab.fragment.AccelerometerViewFragment"
8+
<LinearLayout
9+
android:id="@+id/accelerometer_linearlayout"
1410
android:layout_width="match_parent"
15-
android:layout_height="0dp"
16-
android:layout_weight="1"
17-
android:layout_margin="5dp"
18-
tools:layout="@layout/accelerometer_list_item" />
11+
android:layout_height="wrap_content"
12+
android:orientation="vertical"
13+
android:padding="5dp"
14+
tools:context="io.pslab.activity.AccelerometerActivity">
1915

20-
<fragment
21-
android:id="@+id/accelerometer_y_axis_fragment"
22-
android:name="io.pslab.fragment.AccelerometerViewFragment"
23-
android:layout_width="match_parent"
24-
android:layout_height="0dp"
25-
android:layout_weight="1"
26-
android:layout_margin="5dp"
27-
tools:layout="@layout/accelerometer_list_item" />
16+
<fragment
17+
android:id="@+id/accelerometer_x_axis_fragment"
18+
android:name="io.pslab.fragment.AccelerometerViewFragment"
19+
android:layout_width="match_parent"
20+
android:layout_height="@dimen/accelerometer_fragment_height"
21+
android:layout_marginBottom="@dimen/accelerometer_fragment_margint"
22+
tools:layout="@layout/accelerometer_list_item" />
2823

29-
<fragment
30-
android:id="@+id/accelerometer_z_axis_fragment"
31-
android:name="io.pslab.fragment.AccelerometerViewFragment"
32-
android:layout_width="match_parent"
33-
android:layout_height="0dp"
34-
android:layout_weight="1"
35-
android:layout_marginTop="5dp"
36-
android:layout_marginBottom="10dp"
37-
android:layout_marginLeft="5dp"
38-
android:layout_marginRight="5dp"
39-
tools:layout="@layout/accelerometer_list_item" />
40-
</LinearLayout>
24+
<fragment
25+
android:id="@+id/accelerometer_y_axis_fragment"
26+
android:name="io.pslab.fragment.AccelerometerViewFragment"
27+
android:layout_width="match_parent"
28+
android:layout_height="@dimen/accelerometer_fragment_height"
29+
android:layout_marginBottom="@dimen/accelerometer_fragment_margint"
30+
tools:layout="@layout/accelerometer_list_item" />
31+
32+
<fragment
33+
android:id="@+id/accelerometer_z_axis_fragment"
34+
android:name="io.pslab.fragment.AccelerometerViewFragment"
35+
android:layout_width="match_parent"
36+
android:layout_height="@dimen/accelerometer_fragment_height"
37+
android:layout_marginBottom="@dimen/accelerometer_fragment_margint"
38+
tools:layout="@layout/accelerometer_list_item" />
39+
40+
</LinearLayout>
41+
</ScrollView>

app/src/main/res/values/dimens.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,9 @@
421421
<dimen name="text_size_osc">13sp</dimen>
422422
<dimen name="text_size_9sp">9sp</dimen>
423423

424+
<dimen name="accelerometer_fragment_height">200dp</dimen>
425+
<dimen name="accelerometer_fragment_margint">5dp</dimen>
426+
424427
<dimen name="gyroscope_fragment_height">300dp</dimen>
425428
<dimen name="gyroscope_fragment_margin">5dp</dimen>
426429

0 commit comments

Comments
 (0)