Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: FileLogger added, Speedlist deleted (unused), enlarged modal exit button, added dummy profile #40

Merged
merged 2 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#CCCCCC" />
<size android:width="120dp" android:height="120dp" />
</shape>
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,28 @@
android:layout_height="match_parent"
tools:context=".ui.user_setting.UserSettingFragment">

<ImageView
android:id="@+id/profile_picture_bg"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@drawable/circle_profile_picture"
android:scaleType="center"
app:layout_constraintBottom_toTopOf="@+id/LogoutBtn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ImageView
android:id="@+id/profile_picture"
android:layout_width="70dp"
android:layout_height="70dp"
android:scaleType="fitCenter"
app:layout_constraintBottom_toTopOf="@+id/LogoutBtn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/single_mode" />

<TextView
android:id="@+id/text_user_setting"
android:layout_width="match_parent"
Expand Down
Loading