Skip to content

Commit 3872548

Browse files
authored
fix: gyroscope screen crash and UI (#2651)
1 parent 045b2b8 commit 3872548

File tree

3 files changed

+38
-31
lines changed

3 files changed

+38
-31
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,11 @@ private void writeLogToFile(long timestamp, float readingX, float readingY, floa
425425
}
426426

427427
private void visualizeData() {
428+
if (!isAdded()) return;
428429
for (int i = 0; i < gyroscopeViewFragments.size(); i++) {
429430
GyroscopeViewFragment fragment = gyroscopeViewFragments.get(i);
431+
if (!fragment.isAdded()) continue;
432+
430433
long timeElapsed = (System.currentTimeMillis() - startTime) / 1000;
431434
if (timeElapsed != fragment.getPreviousTimeElapsed()) {
432435
fragment.setPreviousTimeElapsed(timeElapsed);
Lines changed: 32 additions & 31 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/gyro_linearlayout"
2+
<ScrollView
33
xmlns:android="http://schemas.android.com/apk/res/android"
44
xmlns:tools="http://schemas.android.com/tools"
55
android:layout_width="match_parent"
66
android:layout_height="match_parent"
7-
android:fitsSystemWindows="true"
8-
android:orientation="vertical"
9-
tools:context="io.pslab.activity.GyroscopeActivity">
7+
android:fitsSystemWindows="true">
108

11-
<fragment
12-
android:id="@+id/gyroscope_x_axis_fragment"
13-
android:name="io.pslab.fragment.GyroscopeViewFragment"
9+
<LinearLayout
10+
android:id="@+id/gyro_linearlayout"
1411
android:layout_width="match_parent"
15-
android:layout_height="0dp"
16-
android:layout_weight="1"
17-
android:layout_margin="5dp"
18-
tools:layout="@layout/gyroscope_list_item" />
12+
android:layout_height="wrap_content"
13+
android:orientation="vertical"
14+
tools:context="io.pslab.activity.GyroscopeActivity">
1915

20-
<fragment
21-
android:id="@+id/gyroscope_y_axis_fragment"
22-
android:name="io.pslab.fragment.GyroscopeViewFragment"
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/gyroscope_list_item" />
16+
<fragment
17+
android:id="@+id/gyroscope_x_axis_fragment"
18+
android:name="io.pslab.fragment.GyroscopeViewFragment"
19+
android:layout_width="match_parent"
20+
android:layout_height="@dimen/gyroscope_fragment_height"
21+
android:layout_margin="@dimen/gyroscope_fragment_margin"
22+
tools:layout="@layout/gyroscope_list_item" />
2823

29-
<fragment
30-
android:id="@+id/gyroscope_z_axis_fragment"
31-
android:name="io.pslab.fragment.GyroscopeViewFragment"
32-
android:layout_width="match_parent"
33-
android:layout_height="0dp"
34-
android:layout_weight="1"
35-
android:layout_marginTop="5dp"
36-
android:layout_marginLeft="5dp"
37-
android:layout_marginRight="5dp"
38-
android:layout_marginBottom="10dp"
39-
tools:layout="@layout/gyroscope_list_item" />
40-
</LinearLayout>
24+
<fragment
25+
android:id="@+id/gyroscope_y_axis_fragment"
26+
android:name="io.pslab.fragment.GyroscopeViewFragment"
27+
android:layout_width="match_parent"
28+
android:layout_height="@dimen/gyroscope_fragment_height"
29+
android:layout_margin="@dimen/gyroscope_fragment_margin"
30+
tools:layout="@layout/gyroscope_list_item" />
31+
32+
<fragment
33+
android:id="@+id/gyroscope_z_axis_fragment"
34+
android:name="io.pslab.fragment.GyroscopeViewFragment"
35+
android:layout_width="match_parent"
36+
android:layout_height="@dimen/gyroscope_fragment_height"
37+
android:layout_margin="@dimen/gyroscope_fragment_margin"
38+
tools:layout="@layout/gyroscope_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,4 +421,7 @@
421421
<dimen name="text_size_osc">13sp</dimen>
422422
<dimen name="text_size_9sp">9sp</dimen>
423423

424+
<dimen name="gyroscope_fragment_height">300dp</dimen>
425+
<dimen name="gyroscope_fragment_margin">5dp</dimen>
426+
424427
</resources>

0 commit comments

Comments
 (0)