Skip to content

Commit

Permalink
refactor and clean up code, update README
Browse files Browse the repository at this point in the history
  • Loading branch information
o-bagge committed Mar 11, 2024
1 parent 4bcb0a0 commit d3e5c59
Show file tree
Hide file tree
Showing 72 changed files with 197 additions and 186 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import 'dart:io';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:open_earable/apps/posture_tracker/model/earable_attitude_tracker.dart';
import 'package:open_earable/apps/posture_tracker/view/posture_tracker_view.dart';
import 'package:open_earable/apps/neck_stretch/view/stretch_app_view.dart';
import 'package:open_earable/apps/tightness/tightness.dart';
import 'package:open_earable/apps/recorder/lib/recorder.dart';
import 'package:open_earable/apps/jump_height_test/jump_height_test.dart';
import 'package:open_earable/apps_tab/posture_tracker/model/earable_attitude_tracker.dart';
import 'package:open_earable/apps_tab/posture_tracker/view/posture_tracker_view.dart';
import 'package:open_earable/apps_tab/neck_stretch/view/stretch_app_view.dart';
import 'package:open_earable/apps_tab/tightness/tightness.dart';
import 'package:open_earable/apps_tab/recorder/lib/recorder.dart';
import 'package:open_earable/apps_tab/jump_height_test/jump_height_test.dart';
import 'package:open_earable_flutter/src/open_earable_flutter.dart';
import 'global_theme.dart';
import 'package:open_earable/apps/jump_rope_counter/jump_rope_counter.dart';
import 'apps/powernapper/home_screen.dart';
import '../shared/global_theme.dart';
import 'package:open_earable/apps_tab/jump_rope_counter/jump_rope_counter.dart';
import 'powernapper/home_screen.dart';

class AppInfo {
final String logoPath;
Expand All @@ -34,7 +34,7 @@ class AppsTab extends StatelessWidget {
List<AppInfo> sampleApps(BuildContext context) {
return [
AppInfo(
logoPath: "lib/apps/recorder/assets/logo.png",
logoPath: "lib/apps_tab/recorder/assets/logo.png",
title: "Recorder",
description: "Record data from OpenEarable",
onTap: () {
Expand All @@ -48,7 +48,7 @@ class AppsTab extends StatelessWidget {
}),
AppInfo(
logoPath:
"lib/apps/posture_tracker/assets/logo.png", //iconData: Icons.face_6,
"lib/apps_tab/posture_tracker/assets/logo.png", //iconData: Icons.face_6,
title: "Posture Tracker",
description: "Get feedback on bad posture",
onTap: () {
Expand All @@ -63,7 +63,8 @@ class AppsTab extends StatelessWidget {
_openEarable)))));
}),
AppInfo(
logoPath: "lib/apps/jump_height_test/assets/logo.png", //Icons.height,
logoPath:
"lib/apps_tab/jump_height_test/assets/logo.png", //Icons.height,
title: "Jump Height Test",
description: "Measure the height of your jumps",
onTap: () {
Expand All @@ -78,7 +79,7 @@ class AppsTab extends StatelessWidget {
}),
AppInfo(
logoPath:
"lib/apps/jump_rope_counter/assets/logo.png", //iconData: Icons.keyboard_double_arrow_up,
"lib/apps_tab/jump_rope_counter/assets/logo.png", //iconData: Icons.keyboard_double_arrow_up,
title: "Jump Rope Counter",
description: "Count your rope skips",
onTap: () {
Expand All @@ -92,8 +93,8 @@ class AppsTab extends StatelessWidget {
}),
AppInfo(
logoPath:
"lib/apps/powernapper/assets/logo.png", //iconData: Icons.face_5,
title: "Powernapping",
"lib/apps_tab/powernapper/assets/logo.png", //iconData: Icons.face_5,
title: "Powernapper",
description: "Time starts when you're asleep",
onTap: () {
Navigator.push(
Expand All @@ -106,7 +107,7 @@ class AppsTab extends StatelessWidget {
}),
AppInfo(
logoPath:
"lib/apps/tightness/assets/logo.png", //iconData: Icons.music_note,
"lib/apps_tab/tightness/assets/logo.png", //iconData: Icons.music_note,
title: "Tightness Meter",
description: "Practice your sense of rythm",
onTap: () {
Expand All @@ -119,7 +120,7 @@ class AppsTab extends StatelessWidget {
child: TightnessMeter(_openEarable)))));
}),
AppInfo(
logoPath: "lib/apps/neck_stretch/assets/logo.png",
logoPath: "lib/apps_tab/neck_stretch/assets/logo.png",
title: "Guided Neck Stretch",
description: "Relax your neck with a stretch.",
onTap: () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'package:flutter/material.dart';
import 'package:open_earable/apps/jump_height_test/jump_height_chart.dart';
import 'package:open_earable/apps_tab/jump_height_test/jump_height_chart.dart';
import 'dart:async';
import 'package:open_earable_flutter/src/open_earable_flutter.dart';
import 'package:simple_kalman/simple_kalman.dart';
import 'dart:math';
import '../../widgets/earable_not_connected_warning.dart';
import 'package:open_earable/shared/earable_not_connected_warning.dart';

/// An app that lets you test your jump height using an OpenEarable device.
class JumpHeightTest extends StatefulWidget {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:open_earable/widgets/earable_not_connected_warning.dart';
import 'package:open_earable/shared/earable_not_connected_warning.dart';
import 'package:open_earable_flutter/src/open_earable_flutter.dart';
import 'dart:async';
import 'package:intl/intl.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:async';

import 'package:open_earable/apps/neck_stretch/view_model/stretch_view_model.dart';
import 'package:open_earable/apps_tab/neck_stretch/view_model/stretch_view_model.dart';
import 'package:open_earable_flutter/src/open_earable_flutter.dart';

/// Enum for the neck stretch states
Expand Down Expand Up @@ -33,32 +33,32 @@ extension NeckStretchStateExtension on NeckStretchState {
String get assetPathNeckFront {
switch (this) {
case NeckStretchState.rightNeckStretch:
return 'lib/apps/neck_stretch/assets/Neck_Right_Stretch.png';
return 'lib/apps_tab/neck_stretch/assets/Neck_Right_Stretch.png';
case NeckStretchState.leftNeckStretch:
return 'lib/apps/neck_stretch/assets/Neck_Left_Stretch.png';
return 'lib/apps_tab/neck_stretch/assets/Neck_Left_Stretch.png';
default:
return 'lib/apps/neck_stretch/assets/Neck_Front.png';
return 'lib/apps_tab/neck_stretch/assets/Neck_Front.png';
}
}

/// Gets the corresponding asset path for the side eck image
String get assetPathNeckSide {
switch (this) {
case NeckStretchState.mainNeckStretch:
return 'lib/apps/neck_stretch/assets/Neck_Main_Stretch.png';
return 'lib/apps_tab/neck_stretch/assets/Neck_Main_Stretch.png';
default:
return 'lib/apps/neck_stretch/assets/Neck_Side.png';
return 'lib/apps_tab/neck_stretch/assets/Neck_Side.png';
}
}

/// Gets the corresponding asset path for the Head Front Image
String get assetPathHeadFront {
return 'lib/apps/neck_stretch/assets/Head_Front.png';
return 'lib/apps_tab/neck_stretch/assets/Head_Front.png';
}

/// Gets the corresponding asset path for the Head Side Image
String get assetPathHeadSide {
return 'lib/apps/neck_stretch/assets/Head_Side.png';
return 'lib/apps_tab/neck_stretch/assets/Head_Side.png';
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import 'package:flutter/material.dart';

import 'package:open_earable/apps/posture_tracker/model/attitude_tracker.dart';
import 'package:open_earable/apps/neck_stretch/view/stretch_tracker_view.dart';
import 'package:open_earable/apps/neck_stretch/view/stretch_tutorial_view.dart';
import 'package:open_earable/apps/neck_stretch/view_model/stretch_view_model.dart';
import 'package:open_earable/apps/neck_stretch/model/stretch_state.dart';
import 'package:open_earable/apps/neck_stretch/view/stretch_settings_view.dart';
import 'package:open_earable/apps/neck_stretch/view/stretch_stats_view.dart';
import 'package:open_earable/global_theme.dart';
import 'package:open_earable/apps_tab/posture_tracker/model/attitude_tracker.dart';
import 'package:open_earable/apps_tab/neck_stretch/view/stretch_tracker_view.dart';
import 'package:open_earable/apps_tab/neck_stretch/view/stretch_tutorial_view.dart';
import 'package:open_earable/apps_tab/neck_stretch/view_model/stretch_view_model.dart';
import 'package:open_earable/apps_tab/neck_stretch/model/stretch_state.dart';
import 'package:open_earable/apps_tab/neck_stretch/view/stretch_settings_view.dart';
import 'package:open_earable/apps_tab/neck_stretch/view/stretch_stats_view.dart';
import 'package:open_earable/shared/global_theme.dart';

import 'package:open_earable_flutter/src/open_earable_flutter.dart';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:open_earable/apps/neck_stretch/model/stretch_state.dart';
import 'package:open_earable/apps/posture_tracker/view/arc_painter.dart';
import 'package:open_earable/apps/neck_stretch/model/stretch_colors.dart';

import 'package:open_earable/apps_tab/neck_stretch/model/stretch_state.dart';
import 'package:open_earable/apps_tab/posture_tracker/view/arc_painter.dart';
import 'package:open_earable/apps_tab/neck_stretch/model/stretch_colors.dart';

class StretchArcPainter extends CustomPainter {
/// the angle of rotation
Expand All @@ -13,10 +12,11 @@ class StretchArcPainter extends CustomPainter {
final NeckStretchState stretchState;
final bool isFront;

StretchArcPainter({required this.angle,
this.angleThreshold = 0,
this.stretchState = NeckStretchState.noStretch,
required this.isFront});
StretchArcPainter(
{required this.angle,
this.angleThreshold = 0,
this.stretchState = NeckStretchState.noStretch,
required this.isFront});

@override
void paint(Canvas canvas, Size size) {
Expand Down Expand Up @@ -69,39 +69,41 @@ class StretchArcPainter extends CustomPainter {
);
} else {
angleOvershootPath.addArc(
Rect.fromCircle(center: center, radius: radius),
// create a rectangle from the center and radius
startAngle + angle.sign * angleThreshold, // start angle
// If you are facing the wrong direction you don't need to draw this
!_isWrongStretchDirection() ? angle.sign * (angle.abs() - angleThreshold) : 0, // sweep angle
);
Rect.fromCircle(center: center, radius: radius),
// create a rectangle from the center and radius
startAngle + angle.sign * angleThreshold, // start angle
// If you are facing the wrong direction you don't need to draw this
!_isWrongStretchDirection()
? angle.sign * (angle.abs() - angleThreshold)
: 0, // sweep angle
);
}

Paint angleOvershootPaint = Paint()
..color = _getOvershootColor()
..style = PaintingStyle.stroke
..strokeCap = StrokeCap.round
..strokeWidth = 5.0;
..color = _getOvershootColor()
..style = PaintingStyle.stroke
..strokeCap = StrokeCap.round
..strokeWidth = 5.0;

Path thresholdPath = Path();
thresholdPath.addArc(
Rect.fromCircle(center: center, radius: radius),
// create a rectangle from the center and radius
_getStartAngle(startAngle, angleThreshold), // start angle
_getThreshold(angleThreshold), // sweep angle
Rect.fromCircle(center: center, radius: radius),
// create a rectangle from the center and radius
_getStartAngle(startAngle, angleThreshold), // start angle
_getThreshold(angleThreshold), // sweep angle
);

Paint thresholdPaint = Paint()
..color = _getThresholdColor()
..style = PaintingStyle.stroke
..strokeCap = StrokeCap.round
..strokeWidth = 5.0;
..color = _getThresholdColor()
..style = PaintingStyle.stroke
..strokeCap = StrokeCap.round
..strokeWidth = 5.0;

// Draw the path on the canvas
canvas.drawPath(thresholdPath, thresholdPaint);
canvas.drawPath(anglePath, anglePaint);
if (angle.abs() > angleThreshold.abs()) {
canvas.drawPath(angleOvershootPath, angleOvershootPaint);
canvas.drawPath(angleOvershootPath, angleOvershootPaint);
}
}

Expand All @@ -125,15 +127,19 @@ class StretchArcPainter extends CustomPainter {
switch (this.stretchState) {
case NeckStretchState.rightNeckStretch:
case NeckStretchState.leftNeckStretch:
return threshold + (0.775 * pi); // Will place the dark grey area till the start of the neck
return threshold +
(0.775 *
pi); // Will place the dark grey area till the start of the neck
default:
return 2 * threshold;
}
}

switch (this.stretchState) {
case NeckStretchState.mainNeckStretch:
return threshold + (0.8 * pi); // Will place the dark grey area till the start of the neck
return threshold +
(0.8 *
pi); // Will place the dark grey area till the start of the neck
default:
return 2 * threshold;
}
Expand Down Expand Up @@ -164,7 +170,7 @@ class StretchArcPainter extends CustomPainter {
/// or is positive (should stretch that part)
bool _isNegativeOvershoot() {
return (this.isFront &&
this.stretchState == NeckStretchState.mainNeckStretch) ||
this.stretchState == NeckStretchState.mainNeckStretch) ||
(!this.isFront &&
(this.stretchState == NeckStretchState.leftNeckStretch ||
this.stretchState == NeckStretchState.rightNeckStretch));
Expand Down Expand Up @@ -193,13 +199,9 @@ class StretchArcPainter extends CustomPainter {

/// Gets the right indicator color depending on stretch angle and part
Color _getIndicatorColor() {
if(_isNegativeOvershoot())
return goodStretchColor;


if(_isWrongStretchDirection())
return badStretchIndicatorColor;
if (_isNegativeOvershoot()) return goodStretchColor;

if (_isWrongStretchDirection()) return badStretchIndicatorColor;

return goodStretchIndicatorColor;
}
Expand All @@ -209,4 +211,4 @@ class StretchArcPainter extends CustomPainter {
// check if oldDelegate is an ArcPainter and if the angle is the same
return oldDelegate is ArcPainter && oldDelegate.angle != this.angle;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:open_earable/apps/neck_stretch/model/stretch_state.dart';
import 'package:open_earable/apps/neck_stretch/view/stretch_arc_painter.dart';
import 'package:open_earable/apps_tab/neck_stretch/model/stretch_state.dart';
import 'package:open_earable/apps_tab/neck_stretch/view/stretch_arc_painter.dart';

/// A widget that displays the roll of the head and neck for the meditation.
class StretchRollView extends StatelessWidget {
Expand Down Expand Up @@ -44,8 +44,11 @@ class StretchRollView extends StatelessWidget {
fontSize: 30,
fontWeight: FontWeight.bold)),
CustomPaint(
painter:
StretchArcPainter(angle: this.roll, angleThreshold: this.angleThreshold, stretchState: this.stretchState, isFront: _isFront()),
painter: StretchArcPainter(
angle: this.roll,
angleThreshold: this.angleThreshold,
stretchState: this.stretchState,
isFront: _isFront()),
child: Padding(
padding: EdgeInsets.all(10),
child: ClipOval(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:open_earable/apps/neck_stretch/model/stretch_state.dart';
import 'package:open_earable/apps/neck_stretch/view_model/stretch_view_model.dart';
import 'package:open_earable/apps_tab/neck_stretch/model/stretch_state.dart';
import 'package:open_earable/apps_tab/neck_stretch/view_model/stretch_view_model.dart';
import 'package:provider/provider.dart';
import 'dart:core';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:open_earable/apps/neck_stretch/model/stretch_state.dart';
import 'package:open_earable/apps/neck_stretch/view_model/stretch_view_model.dart';
import 'package:open_earable/apps_tab/neck_stretch/model/stretch_state.dart';
import 'package:open_earable/apps_tab/neck_stretch/view_model/stretch_view_model.dart';

class StretchStatsView extends StatefulWidget {
final StretchViewModel _viewModel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:open_earable/apps/neck_stretch/view/stretch_roll_view.dart';
import 'package:open_earable/apps/neck_stretch/view_model/stretch_view_model.dart';
import 'package:open_earable/apps/neck_stretch/model/stretch_state.dart';
import 'package:open_earable/apps/neck_stretch/view/stretch_settings_view.dart';
import 'package:open_earable/apps/neck_stretch/model/stretch_colors.dart';
import 'package:open_earable/apps_tab/neck_stretch/view/stretch_roll_view.dart';
import 'package:open_earable/apps_tab/neck_stretch/view_model/stretch_view_model.dart';
import 'package:open_earable/apps_tab/neck_stretch/model/stretch_state.dart';
import 'package:open_earable/apps_tab/neck_stretch/view/stretch_settings_view.dart';
import 'package:open_earable/apps_tab/neck_stretch/model/stretch_colors.dart';

class StretchTrackerView extends StatefulWidget {
final StretchViewModel _viewModel;
Expand Down
Loading

0 comments on commit d3e5c59

Please sign in to comment.