Skip to content

Commit

Permalink
FileLogger added to check distance on still state, Speedlist deleted …
Browse files Browse the repository at this point in the history
…due to error on long duration singlemode play, enlarged modal exit button on multimode room create
  • Loading branch information
SNURO committed Nov 8, 2023
1 parent 0de66a8 commit 9a50561
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 14 deletions.
32 changes: 32 additions & 0 deletions android/RunUsAndroid/app/src/main/java/Logging/FileLogger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package Logging;

import android.content.Context;
import android.util.Log;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

// save log to file in device
// you can find log file in directory returned by context.getFilesDir()
// you can navigate in folders of device in Android Studio -> View -> Tool Windows -> Device Explorer
// context.getFilesDir() returns path "/data/data/com.example.runusandroid/files/phenotype_storage_info"

public class FileLogger {

public static void logToFileAndLogcat(Context context, String tag, String message) {
// Log to Logcat
Log.d(tag, message);

// Log to a file
try {
File logFile = new File(context.getFilesDir(), "distance_log.txt");
FileOutputStream outputStream = new FileOutputStream(logFile, true);
String logMessage = message + "\n";
outputStream.write(logMessage.getBytes());
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import Logging.FileLogger;

public class SingleModeFragment extends Fragment {

Expand Down Expand Up @@ -661,20 +662,24 @@ public void onReceive(Context context, Intent intent) {
lastLocation.setLongitude(pathPoints.get(pathPoints.size() - 2).longitude);
// unit : meter -> kilometer
distance += location.distanceTo(lastLocation) / (double) 1000;
if ((int) distance != lastDistanceInt) {
LocalDateTime currentTime = LocalDateTime.now();
Duration iterationDuration = Duration.between(iterationStartTime, currentTime);
long secondsDuration = iterationDuration.getSeconds();
float newPace = (float) (1.0 / (secondsDuration / 3600.0));
if (newPace > maxSpeed)
maxSpeed = newPace;
if (newPace < minSpeed)
minSpeed = newPace;
speedList.add(newPace);
iterationStartTime = currentTime;

}
Log.d("test:distance", "Distance:" + distance);
Log.d("test:distance:5sec", "Last 5 second Distance :" + location.distanceTo(lastLocation) / (double) 1000);
// log distance into file
FileLogger.logToFileAndLogcat(mainActivity, "test:distance:5sec", ""+location.distanceTo(lastLocation) / (double) 1000);
// Below code seems to cause NullPointerException after 10 minutes or so (on Duration.between)
// if ((int) distance != lastDistanceInt) {
// LocalDateTime currentTime = LocalDateTime.now();
// Duration iterationDuration = Duration.between(iterationStartTime, currentTime);
// long secondsDuration = iterationDuration.getSeconds();
// float newPace = (float) (1.0 / (secondsDuration / 3600.0));
// if (newPace > maxSpeed)
// maxSpeed = newPace;
// if (newPace < minSpeed)
// minSpeed = newPace;
// speedList.add(newPace);
// iterationStartTime = currentTime;
//
// }
Log.d("test:distance:total", "Distance:" + distance);
}
}
currentDistanceText.setText(String.format(Locale.getDefault(), "%.2f " + "km", distance));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
android:layout_alignParentEnd="true"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:padding="10dp"
android:background="@android:color/transparent"
android:src="@drawable/ic_close" />
<!-- 그룹명 -->
Expand Down

0 comments on commit 9a50561

Please sign in to comment.