Commit 0396be7c authored by Weesinghe W.M.P.D's avatar Weesinghe W.M.P.D

Merge branch 'IT20168186_Health_Monitoring' into 'master'

Add Hydration Tracker

See merge request !6
parents 7268835d eaedfeff
# Default ignored files
/shelf/
/workspace.xml
The Trek
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="11" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="testRunner" value="GRADLE" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
</GradleProjectSettings>
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="Android Studio default JDK" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
\ No newline at end of file
...@@ -257,7 +257,9 @@ ...@@ -257,7 +257,9 @@
<activity <activity
android:name=".activities.ShowPeopleActivity" android:name=".activities.ShowPeopleActivity"
android:exported="false"/> android:exported="false"/>
<activity
android:name=".WaterActivity"
android:exported="false"/>
<meta-data <meta-data
android:name="com.google.ar.core" android:name="com.google.ar.core"
android:value="required" /> android:value="required" />
......
package com.example.thetrek;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DatabaseHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "HydrationTracker.db";
private static final int DATABASE_VERSION = 1;
public static final String TABLE_NAME = "water_intake";
public static final String COLUMN_ID = "id";
public static final String COLUMN_AMOUNT = "amount";
public static final String COLUMN_DATE = "date";
private static final String TABLE_CREATE =
"CREATE TABLE " + TABLE_NAME + " (" +
COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
COLUMN_AMOUNT + " INTEGER, " +
COLUMN_DATE + " TEXT);";
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(TABLE_CREATE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
}
...@@ -92,6 +92,15 @@ public class HomeActivity extends AppCompatActivity { ...@@ -92,6 +92,15 @@ public class HomeActivity extends AppCompatActivity {
} }
}); });
Button healthMonitoringButton = (Button) findViewById(R.id.btn_homeActivity_healthMonitoring);
healthMonitoringButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(v.getContext(), WaterActivity.class);
v.getContext().startActivity(intent);
}
});
Button rewards = (Button) findViewById(R.id.btn_homeActivity_rewards); Button rewards = (Button) findViewById(R.id.btn_homeActivity_rewards);
rewards.setOnClickListener(new View.OnClickListener() { rewards.setOnClickListener(new View.OnClickListener() {
@Override @Override
......
package com.example.thetrek;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView; // Import TextView
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
public class WaterActivity extends AppCompatActivity {
private int totalWaterIntake = 0;
private int dailyHydrationGoal = 2000; // Default goal
private EditText waterIntakeEditText;
private DatabaseHelper dbHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_water);
waterIntakeEditText = findViewById(R.id.waterIntakeEditText);
Button trackButton = findViewById(R.id.trackButton);
Button checkButton = findViewById(R.id.checkButton);
dbHelper = new DatabaseHelper(this);
trackButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String waterIntakeStr = waterIntakeEditText.getText().toString();
if (!waterIntakeStr.isEmpty()) {
int waterIntake = Integer.parseInt(waterIntakeStr);
saveWaterIntake(waterIntake);
waterIntakeEditText.setText("");
totalWaterIntake += waterIntake;
}
}
});
checkButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (totalWaterIntake < dailyHydrationGoal) {
sendNotification("Stay Hydrated", "You have not met your daily hydration goal. Drink more water!");
}
}
});
loadHydrationGoal(); // Load the user's hydration goal from the database
EditText hydrationGoalEditText = findViewById(R.id.hydrationGoalEditText);
Button setGoalButton = findViewById(R.id.setGoalButton);
setGoalButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String goalStr = hydrationGoalEditText.getText().toString();
if (!goalStr.isEmpty()) {
int newGoal = Integer.parseInt(goalStr);
dailyHydrationGoal = newGoal;
saveHydrationGoal(newGoal);
displayCurrentGoal(); // Display the updated goal
}
}
});
displayCurrentGoal(); // Display the initial goal
}
// Save water intake data to the database
private void saveWaterIntake(int amount) {
SQLiteDatabase db = dbHelper.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(DatabaseHelper.COLUMN_AMOUNT, amount);
db.insert(DatabaseHelper.TABLE_NAME, null, values);
db.close();
}
// Load the user's hydration goal from the database
private void loadHydrationGoal() {
SQLiteDatabase db = dbHelper.getReadableDatabase();
Cursor cursor = db.rawQuery("SELECT MAX(" + DatabaseHelper.COLUMN_AMOUNT + ") FROM " + DatabaseHelper.TABLE_NAME, null);
if (cursor.moveToFirst()) {
dailyHydrationGoal = cursor.getInt(0);
}
cursor.close();
db.close();
}
// Save the user's hydration goal to the database
private void saveHydrationGoal(int goal) {
SQLiteDatabase db = dbHelper.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(DatabaseHelper.COLUMN_AMOUNT, goal);
db.insert(DatabaseHelper.TABLE_NAME, null, values);
db.close();
}
// Display the current goal in the TextView
private void displayCurrentGoal() {
TextView currentGoalTextView = findViewById(R.id.currentGoalTextView);
currentGoalTextView.setText("Current Goal: " + dailyHydrationGoal + " ml");
}
private void sendNotification(String title, String message) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "channel_id")
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle(title)
.setContentText(message)
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(0, builder.build());
}
}
...@@ -58,6 +58,13 @@ ...@@ -58,6 +58,13 @@
android:backgroundTint="#5D71C9" android:backgroundTint="#5D71C9"
android:text="Suggestion Predictor" /> android:text="Suggestion Predictor" />
<Button
android:id="@+id/btn_homeActivity_healthMonitoring"
android:layout_width="match_parent"
android:layout_height="65dp"
android:backgroundTint="#5D71C9"
android:text="Health Monitoring" />
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="55dp" android:layout_height="55dp"
......
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background">
<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:text="HydrationWave"
android:textColor="@color/black"
android:textStyle="bold"
android:textSize="24sp" />
<TextView
android:id="@+id/textview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textview"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:text="🌊 Stay Hydrated, Surfer. Catch the Wave of Wellness! 🏄‍♂️ 🌴"
android:textColor="@color/black"
android:textStyle="bold"
android:textSize="16sp" />
<EditText
android:id="@+id/hydrationGoalEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textview2"
android:layout_margin="16dp"
android:hint="Set Daily Hydration Goal (ml)"
android:textColor="@color/black" />
<Button
android:id="@+id/setGoalButton"
android:layout_width="match_parent"
android:layout_height="65dp"
android:layout_below="@+id/hydrationGoalEditText"
android:layout_margin="16dp"
android:text="Set Goal"
android:backgroundTint="#5D71C9" />
<!-- The TextView for displaying the current goal -->
<TextView
android:id="@+id/currentGoalTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/setGoalButton"
android:layout_centerHorizontal="true"
android:layout_margin="16dp"
android:text="Current Goal: 2000 ml"
android:textColor="@color/black" />
<EditText
android:id="@+id/waterIntakeEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/currentGoalTextView"
android:layout_margin="16dp"
android:hint="Enter water intake (ml)"
android:textColor="@color/black" />
<Button
android:id="@+id/trackButton"
android:layout_width="match_parent"
android:layout_height="65dp"
android:layout_below="@+id/waterIntakeEditText"
android:layout_margin="16dp"
android:text="Track"
android:backgroundTint="#5D71C9" />
<Button
android:id="@+id/checkButton"
android:layout_width="match_parent"
android:layout_height="65dp"
android:layout_below="@+id/trackButton"
android:layout_margin="16dp"
android:text="Check Hydration"
android:backgroundTint="#5D71C9" />
</RelativeLayout>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment