Professional Documents
Culture Documents
G9 Dietexpert Report
G9 Dietexpert Report
A Project Submitted to
Rajiv Gandhi Proudyogiki Vishwavidyalaya
EXAMINER APPROVAL
Date: Date:
DietExpert
GUIDE RECOMMENDATION
This is to certify that the work embodied in this project entitled “DietExpert” submitted by
Garvita Gehlot(0827CS171076) is a satisfactory account of the bonafide work done under the
supervision of Dr. Kamal Kumar Sethi, is recommended towards partial fulfillment for the
award of the Bachelor of Engineering (Computer Science & Engineering) degree by Rajiv Gandhi
Proudyogiki Vishwavidhyalaya, Bhopal.
STUDENTS UNDERTAKING
This is to certify that the project entitled “DietExpert” has been developed by us under the
supervision of Dr. Kamal Kumar Sethi. The whole responsibility of work done in this project is
ours. The sole intention of this work is only for practical learning and research.
We further declare that to the best of our knowledge, this report does not contain any part of any
work which has been submitted for the award of any degree either in this University or in any other
University / Deemed University without proper citation and if the same work is found then we are
liable for explanation to this.
Garvita Gehlot(0827CS171076)
ACKNOWLEDGEMENT
We thank the almighty Lord for giving me the strength and courage to sail out through the tough
and reach on shore safely.
There are number of people without whom this projects work would not have been feasible.
Their high academic standards and personal integrity provided me with continuous guidance and
support.
We owe a debt of sincere gratitude, deep sense of reverence and respect to our guide and mentor
Dr. Kamal Kumar Sethi, Professor, AITR, Indore for his motivation, sagacious guidance, constant
encouragement, vigilant supervision and valuable critical appreciation throughout this project
work, which helped us to successfully complete the project on time.
We express profound gratitude and heartfelt thanks to Dr Kamal Kumar Sethi, HOD CSE, AITR
Indore for his support, suggestion and inspiration for carrying out this project. I am very much
thankful to other faculty and staff members of CSE Dept, AITR Indore for providing me all
support, help and advice during the project. We would be failing in our duty if do not
acknowledge the support and guidance received from Dr S C Sharma, Director, AITR, Indore
whenever needed. We take opportunity to convey my regards to the management of Acropolis
Institute, Indore for extending academic and administrative support and providing me all
necessary facilities for project to achieve our objectives.
We are grateful to our parent and family members who have always loved and supported us
unconditionally. To all of them, we want to say “Thank you”, for being the best family that one
could ever have and without whom none of this would have been possible.
Garvita Gehlot(0827CS171076)
EXECUTIVE SUMMARY
DietExpert
This project is submitted to Rajiv Gandhi Proudyogiki Vishwavidhyalaya, Bhopal(MP), India for
partial fulfillment of Bachelor of Engineering in Computer Science & Engineering branch under
the sagacious guidance and vigilant supervision of Dr. Kamal Kumar Sethi.
With great advancements in Android, we have offered an approach for development in the field of
diet consultant. In this project, user calculates their BMI with the help of internal activities. When a
user provide proper inputs to the system their BMI is generated with help to it desirable diet plan is
been generated. We have used Android to develop the front-end of this application and Java for
behind –the- scenes operations. Android Studio was our editor of preference. Adding all these
technologies together, we progressed to building a hand on project.
1.1. Overview………………………………………………………………………………………..……………………1
1.2. Abstract…………………………….…………………………………………..…………………………………….2
1.3. Problem statement and Objective………………………....……………………………………………3
1.4. Scope of Project…………………………………………………………………………………………………..4
1.5. Report Structure………………………………………………………………………………………………….5
3.6.1 Hardware……………………………………………………………………………………………………xx
3.6.2 Software…………………………………………………………………………………………………….xx
Chapter4. Implementation……………………………………………………………………………………………………..xx
4.1 Introduction…………………………………………………………………………………………………………….xx
4.2 Procedures………………………………………………………………………………………………………………xx
4.3 Application Layout…………………………………………………………………………………………………..xx
Chapter5. Conclusion………………………………………………………………………………………………………………xx
5.1 Conclusion………………………………………………………………………………………………………………xx
5.2 Future Scope………..…………………………………………………………………………………………………xx
Bibliography……………………………………………………………………………………………………………………………xx
Source Code……………………………………………………………………………………………………………………………xx
Chapter1. INTRODUCTION
1.1 Overview
Virtual dietitian android application is an application which provides a generic diet to its users. It acts
as a diet consultant similar to a real Dietitian. This system acts in a similar way as that of a dietitian.
A person in order to know his/her diet plan needs to give some information to the dietitian such as its
body type, weight, height and working hour details. Similar way this system also provides the diet
plan according to the information entered by the user. The system asks all his data from the user and
processes it to provide the diet plan to the user.
Thus, the user does not need to visit any dietitian which also saves time and the user can get the
required diet plan in just a click. The system will give more accurate results as it accepts the data
entered by the user and processes it depending on some metrics already known to the application on
the basis of which a diet plan is generated and ask the user if the user accepts the diet plan.
If not accepted the system may also give and alternative diet plan. This application not only provides
the user a proper & healthy diet but also provides the user all the workout information. There is a
card for Work out details for all the workout programs for each body part. If a user wants to stay fit
and eat healthy, he can surely follow the program provided to him.
In recent years, the number of overweight people has increased significantly, so much that the World
Health Organization (WHO) has called obesity an epidemic illness, since it can cause a very wide range
of further health consequences; like high blood pressure, diabetes, cardiovascular diseases .
The Application also has a card for Health Facts on the home screen, which will provide all the general
knowledge and some amazing facts on our human body and body parts.
This Application can be a vital part of a user if he wishes to maintain his health and body perfectly and
follow the diet plan & the workout plan provided to the user.
1.2 Abstract
This application provides the user with a complex algorithm which can provide the user with a diet
plan based on his/her characteristics like height, weight, BMI, gender etc. Everyone today dreams of
healthy life cycle.
In Today’s busy life healthy body is dream for everyone to have a proper balanced diet. A balanced
diet is important because your organs and tissues need proper nutrition to work effectively. Without
good nutrition, your body is more prone to disease, infection, fatigue, and poor performance.
Children with a poor diet run the risk of growth and developmental problems and poor academic
performance, and bad eating habits can persist for the rest of their lives.
At the core of a balanced diet are foods that are low in unnecessary fats and sugars and high in
vitamins, minerals, and other nutrients. The following food groups are essential parts of a balanced
diet. Calories play a vital role in our growth and energy.
A good diet can help you manipulate calorie intake based on your requirements. The proposed
application will provide the user with a user-friendly User-Interface where they can create an account,
manage their account and get the diet by the click of just one button. If the user is allergic to some
kind of food, it also has the feature to contact an actual dietitian to consult. And there’s also a page
where the user can just read some interesting facts on health and human body.
This application will save a lot of user’s time by not actually visiting a dietitian and getting everything
done on their phone.
1.3 Problem Statement and Objective
Diet is matter of concern for everyone. Everybody dream of a balance diet and eat healthy but when
it comes to taste we all fail to do so because health and taste don’t go hand in hand. Every few of us
follow diet plans strictly and often fail to do so. In the existing AI Diet Consultant system, you have to
hire a dietitian in order to get advice. Hiring a nutrition doctor will not only waste your time and
efforts for calling them, going to them and so on but also cost you very high as their charges per
month are very high. The moment will also arrive when they will not available for you and you have to
search for some other dietitian urgently.
If any new user come for diet schedule, dietitian and his staff has to search the user details and they
have to find the dietitian schedule for that particular diet. Here searching for eligible diet takes lots of
time. And sometimes some users’ details may be missed.
1. According to current health survey in India there are more than 70% of people suffer from one or
the other disease.
2. This is because they don’t know how much they should eat.
3. People avoid going to nutritionists or diet planner because of their high fees.
The proposed system is fully computerized, which removes all the drawbacks of existing system. The
main advantage of using this standalone web application is that the time required by the people to
travel to the dietitian will be reduced and also it reduces the cost of hiring dietitians for some
particular purpose.
Also, this application offers more than one diet plan also, for some particular kind of functionalities of
human bodies. All the users have some common services like changing password, updating details,
searching for details, checking the details, mailing to administrator, and reading the material
uploaded by admin if the user is a student. Administrator has to do the services like adding events,
achievements and he can reply to the mails sent by users. He can upload materials, search for diet
details, and he has the right to approve the same.
Chapter 2: Review of Literature: Explores the work done in the area of Project
undertaken and discusses the limitations of existing system and highlights the issues and challenges of
project area. The chapter finally ends up with the requirement identification for project work based
on finding drawn from reviewed literature and end user interactions.
Chapter 3: Proposed System: Starts with the project proposal based on requirement
identified, followed by benefits of the project. The chapter also illustrate software engineering
paradigm used along with different design representation. The chapter also includes block diagram
and details of major modules of the project. Chapter also gives insights of different type of feasibility
study carried out for the project undertaken. Later it gives details of the different deployment
requirements for the developed project.
Tools/ Programming Languages used in developing the Project. The chapter also includes the different
user interface designed in project along with their functionality. Further it discusses the experiment
results along with testing of the project. The chapter ends with evaluation of project on different
parameters like accuracy and efficiency.
Chapter 5: Conclusion: Concludes with objective wise analysis of results and limitation of
present work which is then followed by suggestions and recommendations for further improvement.
Chapter2. Review of Literature
Review of Literature:
Diet Consultant is a term we all are familiar with this word ad we all have thought to have one at
some point of time. Instead of using AI diet consultant people are physically going to the dietician. In
the existing diet consultant system, you have to hire a dietitian in order to get advice. Also, there is a
high chance of misinterpretation of data as well as occurrence of errors. Moreover, it is time
consuming. With the increase in volume of patients in the health care institutes, traditional method of
management has gone out of phase. Some of the applications were paid-to-use and some were free,
we wanted to build our project to be free to all. We started gathering information on the existing
system and how it works and also a real dietitian works and calculates a diet based on a person’s
details like height, age, weight, gender etc.
• In the existing AI Diet Consultant system, you have to hire a dietitian in order to get
advice. Hiring a nutrition doctor will not only waste your time and efforts for calling
them, going to them and so on but also cost you very high as their charges per
month are very high.
• There are various application being build keeping this idea in mind but still no such
solution of an diet consultant with AI build in is not been implemented right now.
• Applications for calculation of BMI are separated from diet consultant and using two
applications for a same use is not a good idea for users.
• Most of the applications are either doctor specific and are not friendly to over
pocket.
• Application either gives diet charts or cal/gm charts but limited number of them
would give a proper user friendly diet plans.
Fig 2. Comparisons chart of different existing diet applications
• There are various application being build keeping this idea in mind but still no such
solution of an diet consultant with AI build in is not been implemented right now.
• Applications for calculation of BMI are separated from diet consultant and using two
applications for a same use is not a good idea for users.
• Most of the applications are either doctor specific and are not friendly to over
pocket.
• Application either gives diet charts or cal/gm charts but limited number of them
would give a proper user friendly diet plans.
As people across the globe are becoming more interested in watching their weight, eating more
healthy food and avoiding junk food, a system that can measure calories and nutrition in every day
meals can be very useful for maintaining our health. Food calorie and nutrition measurement system
is very beneficial for dietitians and patients to measure and manage the daily food intake. However,
each person has a unique dietary pattern and has different health issues so a dietitian creates a meal
plan depending on each case.
Chapter3. Proposed Systems
The main advantage of using this standalone web application is that the time required by the
people to travel to the dietitian will be reduced and also it reduces the cost of hiring dietitians
for some particular purpose.
After evaluation of almost 51 application based on their rating and maximum number of
downloads there are certain limitations for each and every applications. The current system
had a lot of challenges that are overcome by this system:
• Economic: The proposed system is economic and tries to balance between computation
power and performance.
• High-Quality Outputs: The Outputs generated will be higher quality than the available
alternatives while also cheaper than others.
• Man Power: It will not be necessary to hire a person to see just tiny details and for work
which required fast results.
• 24 x 7 Availability: Since, it’s a Web Application It is on 24x7 and can be accessed
anytime and anywhere.
3.3 Block Diagram
1-The software designer and implementer can obtain feedback from the users early in the
project.
2-The client and the contractor can compare if the software made matches the software
specification, according to which the software program is built.
3-It also allows the software engineer some insight into the accuracy of initial project
estimates and whether the deadlines and milestones proposed can be successfully met"
1-Often clients expect that a few minor changes to the prototype will more than suffice their
needs. They fail to realize that no consideration was given to the overall quality of the
software in the rush to develop the prototype.
2-The developers may lose focus on the real purpose of the prototype and compromise the
quality of the product. For example, they may employ some of the inefficient algorithms or
inappropriate programming languages used in developing the prototype. This mainly due to
laziness and an over reliance on familiarity with seemingly easier methods.
3-A prototype will hardly be acceptable in court in the event that the client does not agree
that the developer has discharged his/her obligations. For this reason using the prototype as
the software specification is normally reserved for software development within an
organization.
“A use case depicts a set of activities performed to produce some output result. Each use case
describes how an external user triggers an event to which the system must respond”
In our use case diagram, we have three actors:
Actor 1: The main actor of the system is the User, he can write reports and rate dietitians, the
user can organize his shopping list, he can request a diet plan and organize his meals.
Actor 2: The secondary actor is the Dietitian, the actions done by dietitian are: Dietitian can
login. Dietitian can communicate with users. Dietitian can update meals Dietitian can update
account Dietitian can update items in the database and descriptions.
Fig6. Dietitian Use Case Diagram
Actor 3: The third actor is the administrator of the system -log in -Admin can update account -
Admin can manage dietitian Hire or fire dietitians -The admin can manage his account
information, user, and reports.
The sequence diagram shows interactions in the system between objects put together
respecting the sequence. It shows the message exchanged between the objects and what kind
of interactions are done. In the diet application we look at the exchange between the actors
and the system as well as the database.
In the diet application: The login process: is the same to the user, dietitian or the admin, it is
different when it comes to the database
There are various requirements (hardware, software and services) to successfully deploy the
system. These are mentioned below:
3.6.1 Hardware
• Android Studio
• Java Development Kit
• JDBC
Chapter 4 Implementation
4.1 Introduction: This chapter focuses on procedures, reports, layouts and report layouts.
4.2 Procedures:
I would like to mention that the application contains many important functions associated
with each other, but here I chose the most important functions of the project from my point of
view and frequent most of the application because of its importance.
1-onCreate () the first thing that happens when you run your application is often put in it
Activities related to the layout of buttons and menu.
2-getApplicationContext () we use it for Returns the context for all activities running in
application. This example of using two Procedures in the same function
5.1 Conclusion
This is to conclude that the project that we undertook was worked upon with a sincere effort.
Most of the requirements have been fulfilled up to the mark and the requirements which have
been remaining, can be completed with a short extension. This project would definitely satisfy
all the requirements of the college and would be beneficial for the students and the college
staff.
With the proposed application on mobile phones, we will be able to bring the Dietitian App on
the palm of every individual. The application can be deployed on the cloud by integrating
different servers through the cloud in its future iterations. With respect to the feedback of the
App users’ further improvements can be incorporated within the system to make it more users
friendly. In our approach for implementing this project is we have implemented a virtual
dietitian using android. Our system comprises of main components such as of a user login and
an admin login. The software system allows the user to create their profiles and upload all
their details and their BMI are calculated by the system.
The admin can check each user details and can remove faulty accounts. People, who are in
need of a serious health care but are busy with their schedules, can start using our application
and start following the diet and workout programs. With the help of this application, user
doesn’t have to go to an actual dietitian he can have a dietitian in the palm of his hands
[1]Prof. DV Chandran, Sayali Adarkar, Apoorva Joshi, Preeti Kajbajd,, “Digital Medicine: An
android based application for health care system”, IRJET, Volume-4, 04Apr-2017.
[2]Hilde A.E Geraedts, Wiebren Zijlstra, Wei Zhang, Sophie L.W. Spoorenberg, “Home Based
Exercise Program Driven By Tablet Application & Mobility Monitoring, Public Health Research”,
Volume 14-E12, Feb-2017.
[3]Rodrigo Zenun Franco, Julie Anne Lovegrove, Rosalind Fallaize, Foustina Hwang, Popular
Nutrition-Related Mobile Apps: A Feature Assessment, JMIR MHEALTH & UHEALTH, Volume-4
Issue-3, Aug-2016.
[4] Oxford handbook of nutrition and dietetics edited by Joan Webster-Gandy, Angela
Madden and Michelle Holdsworth
[5] Hong, S. M. and Kim, G. (2005). 'Web Expert System for Nutrition Counseling and Menu
Management,' J Community Nutrition, 72 ,107 -113.
[6] Horn, W., C. Popow, S. Miksch, and A. Seyfang. (2002), ‘Benefits of a Knowledge- based
System for Parenteral Nutrition Support: a Report after 5 Years of Routin Daily Use,’
Proceedings of the 15th European Conference on Artificial Intelligence (ECAI 2002), van
Harmelen, F. (Ed.), 613–617.
[8] Chen, Y. , Hsu, C. Y. , Liu, . L and Yang, S. (2012), 'Constructing a nutrition diagnosis expert
system,' Expert System with Application, 39(2) , 2132–2156
[9] Becerra-Fernandez, I., Gonzalez, A., & Sabherwal, R. (2004). Knowledge management:
Challenges, solutions and technologies. New Jersey: Pearson Education Inc.
[11] Heart, Lung, and Blood Institute; National Institutes of Health, authors. Interactive menu
planner.
[12] Eckstein E F. Menu planning by computer: the random approach. J Am Diet Assoc. 1967
Dec;51(6):529–33.
[13] Marling CR, Petot GJ, Sterling L. Integrating case-based and rule-based reasoning to meet
multiple design constraints. Computational Intelligence. 1999;5(3):308–332. doi:
10.1111/0824-7935.00095.
Source Code
package com.example.vcfitness;
import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.TextView;
float height,weight;
TextView height_txt,age;
int count_weight = 50,count_age = 19;
RelativeLayout weight_plus, weight_minus, age_plus, age_minus;
boolean male_clk = true, female_clk = true, check1 = true, check2 = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
height_txt = findViewById(R.id.height_txt);
age_minus = findViewById(R.id.age_minus);
age_plus = findViewById(R.id.age_plus);
weight_minus = findViewById(R.id.weight_minus);
weight_plus = findViewById(R.id.weight_plus);
card_male.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (check1) {
if (male_clk) {
male_text.setTextColor(Color.parseColor("#FFFFFF"));
male_text.setCompoundDrawablesWithIntrinsicBounds(0,R.drawable.male_white,0,0);
male_clk = false;
check2 = false;
} else {
male_text.setTextColor(Color.parseColor("#8D8E99"));
male_text.setCompoundDrawablesWithIntrinsicBounds(0,R.drawable.male,0,0);
male_clk = true;
check2 = true;
}
}
}
});
card_female.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (check2) {
if (female_clk) {
female_text.setTextColor(Color.parseColor("#FFFFFF"));
female_text.setCompoundDrawablesWithIntrinsicBounds(0,R.drawable.female_white,0,0);
female_clk = false;
check1 = false;
}
else {
female_text.setTextColor(Color.parseColor("#8D8E99"));
female_text.setCompoundDrawablesWithIntrinsicBounds(0,R.drawable.female,0,0);
female_clk = true;
check1 = true;
}
}
}
});
CheckSeekbarStatus();
CheckWeight();
CheckAge();
age = findViewById(R.id.age);
age_plus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
count_age++;
age.setText(String.valueOf(count_age));
}
});
age_minus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
count_age--;
age.setText(String.valueOf(count_age));
}
});
}
weight_plus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
count_weight++;
weight_txt.setText(String.valueOf(count_weight));
}
});
weight_minus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
count_weight--;
weight_txt.setText(String.valueOf(count_weight));
}
});
weight = Float.parseFloat(weight_txt.getText().toString());
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
}
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bmiresult);
Intent intent = getIntent();
@Override
public void onBackPressed() {
super.onBackPressed();
updateUI();
}
}
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Dashboard">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="405dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="350dp"
android:background="@drawable/backgroundgradient"
android:orientation="vertical">
<ImageView
android:id="@+id/imageviewD"
android:layout_marginTop="50dp"
android:onClick="Change_pp"
android:layout_gravity="center_horizontal"
android:layout_width="125dp"
android:layout_height="125dp"
android:src="@drawable/pp"
/>
<TextView
android:id="@+id/lblFullName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_gravity="center_horizontal"
android:text=""
android:textColor="#FFF"
android:textStyle="bold"
android:textSize="21sp"/>
</LinearLayout>
<androidx.cardview.widget.CardView
android:layout_width="400dp"
android:layout_height="120dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="275dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="3">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Photos"
android:textSize="20sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:text="125"
android:textColor="@android:color/holo_blue_dark"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Steps"
android:textSize="20sp" />
<TextView
android:id="@+id/txtSteps"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:text="825"
android:textColor="@android:color/holo_blue_dark"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Weight"
android:textSize="20sp" />
<TextView
android:id="@+id/CardWeight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:text=""
android:textColor="@android:color/holo_blue_dark"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
</RelativeLayout>
<GridLayout
android:columnOrderPreserved="false"
android:rowCount="3"
android:columnCount="2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alignmentMode="alignMargins">
<androidx.cardview.widget.CardView
android:id="@+id/Profile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
app:cardElevation="6dp"
app:cardCornerRadius="12dp"
android:layout_margin="12dp"
android:onClick="btnProfile"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:padding="16dp">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/ic_person_black_24dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Profile"
android:textColor="#6f6f6f"
android:textSize="18sp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="@+id/Daily_weight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
app:cardElevation="6dp"
app:cardCornerRadius="12dp"
android:layout_margin="12dp"
android:onClick="AddDailyWeight"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:padding="16dp">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/ic_add_black_24dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Daily Weight"
android:textColor="#6f6f6f"
android:textSize="18sp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="@+id/bmi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
app:cardElevation="6dp"
app:cardCornerRadius="12dp"
android:layout_margin="12dp"
android:onClick="Bmi_Calculator"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:padding="16dp">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/ic_bmi"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BMI Calculator"
android:textColor="#6f6f6f"
android:textSize="18sp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
app:cardElevation="6dp"
app:cardCornerRadius="12dp"
android:layout_margin="12dp"
>
<LinearLayout
android:onClick="View_Goals"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:padding="16dp">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/ic_fitness_center_black_24dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Goals"
android:textColor="#6f6f6f"
android:textSize="18sp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
app:cardElevation="6dp"
app:cardCornerRadius="12dp"
android:layout_margin="12dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:padding="16dp">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/ic_directions_walk_black_24dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Steps"
android:textColor="#6f6f6f"
android:textSize="18sp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
app:cardElevation="6dp"
app:cardCornerRadius="12dp"
android:layout_margin="12dp"
android:onClick="btnGallery"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:padding="16dp">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/ic_photo_camera_black_24dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gallery"
android:textColor="#6f6f6f"
android:textSize="18sp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
app:cardElevation="6dp"
app:cardCornerRadius="12dp"
android:layout_margin="12dp"
android:onClick="Logout"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:padding="16dp">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/ic_exit_to_app_black_24dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Logout"
android:textColor="#6f6f6f"
android:textSize="18sp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</GridLayout>
</LinearLayout>
</ScrollView>
<androidx.cardview.widget.CardView
android:id="@+id/result_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginRight="16dp"
app:cardBackgroundColor="@color/card_background"
app:cardCornerRadius="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:padding="20dp">
<TextView
android:id="@+id/condition"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:textColor="#5ADC65"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="@+id/your_bmi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:textColor="@android:color/white"
android:textSize="50sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/normal_bmi_range"
android:textColor="#8D8E99"
android:textSize="21sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/_18_5_25_kg_m2"
android:textColor="@android:color/white"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/your_age"
android:textColor="@color/colorAccent"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="@+id/age"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:textSize="20sp" />
<TextView
android:id="@+id/category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="8dp"
android:gravity="center_horizontal"
android:textColor="@android:color/white"
android:textSize="20sp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<Button
android:id="@+id/recalculate"
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="176dp"
android:background="@drawable/calculate_btn"
android:text="@string/recalculate"
android:textColor="@android:color/white"
android:textSize="17sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="@+id/diet"
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="92dp"
android:background="@drawable/calculate_btn"
android:text="@string/diet"
android:textColor="@android:color/white"
android:textSize="17sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
package com.example.vcfitness;
import android.app.DatePickerDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.UserProfileChangeRequest;
import com.google.firebase.firestore.DocumentReference;
import com.google.firebase.firestore.DocumentSnapshot;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.QueryDocumentSnapshot;
import com.google.firebase.firestore.QuerySnapshot;
import com.google.firebase.storage.FileDownloadTask;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.StorageReference;
import com.google.firebase.storage.UploadTask;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
//Firebase declarations
private StorageReference mStorageRef;
StorageReference profileRef;
FirebaseAuth mAuth;
FirebaseFirestore db = FirebaseFirestore.getInstance();
//intent requests
private static final int IMAGE_GALLERY_RESULT = 10;
private static final int SELECT_IMAGE = 1;
private static final int REQUEST_CAMERA= 2;
//public fields
Uri uripp;
String profileimageUrl;
final Calendar myCalender = Calendar.getInstance();
//objects from UI
ImageView imageview;
Spinner spinGender;
EditText Datetxt;
TextView lblWeight;
EditText txtWeight;
EditText txtHeight;
EditText txtWeightGoal;
EditText txtStepGoal;
TextView txtfullname;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
//Initilisation of UI components
imageview = findViewById(R.id.imgProfilePic);
txtfullname = findViewById(R.id.txtName);
txtWeight = findViewById(R.id.txtWeight);
txtHeight = findViewById(R.id.txtHeight);
txtWeightGoal = findViewById(R.id.txtWeightGoal);
txtStepGoal = findViewById(R.id.txtStepGoal);
lblWeight = findViewById(R.id.weightCard);
spinGender = findViewById(R.id.spinGender);
//Firebase
mStorageRef = FirebaseStorage.getInstance().getReference();
mAuth = FirebaseAuth.getInstance();
//calling method to load user info from firestore (collection user) and display
to user
LoadProfileInfo();
Datetxt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new DatePickerDialog(ProfileActivity.this, date,
myCalender.get(Calendar.YEAR), myCalender.get(Calendar.MONTH),
myCalender.get(Calendar.DAY_OF_MONTH)).show();
}
});
LoadSpinners();
}
private void loadProfilePicture() throws IOException {
//Glide.with(this).load(pictureUrl).into(imageview) ;
storageRef.getFile(localFile)
.addOnSuccessListener(new
OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
// Successfully downloaded data to local file
// ...
Bitmap pp = BitmapFactory.decodeFile(String.valueOf(localFile));
imageview.setImageBitmap(pp);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle failed download
// ...
}
});
}
//select image from user gallery or snap a picture using the camera
private void selectImage() {
final CharSequence[] options = { "Take Photo", "Choose from Gallery","Cancel" };
AlertDialog.Builder builder = new AlertDialog.Builder(ProfileActivity.this);
builder.setTitle("Add Photo!");
builder.setItems(options, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int item) {
uripp = data.getData();
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(),
uripp);
imageview.setImageBitmap(bitmap);
UploadImageToFireBaseStorage();
} catch (IOException e) {
e.printStackTrace();
}
}
else if (requestCode == REQUEST_CAMERA && resultCode == RESULT_OK && data != null
&& data.getData() != null){
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
if(uripp != null)
{
//add the image to firebase storage and set the url to the users display
picture when 'SaveUserInfo() is called
profileRef = mStorageRef.child("ProfilePictures/" + mAuth.getUid() +
".jpg");
profileRef.putFile(uripp).addOnSuccessListener(new
OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
profileimageUrl = profileRef.getDownloadUrl().toString();
saveUserInfo();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(ProfileActivity.this, e.getMessage(),
Toast.LENGTH_LONG).show();
}
});
}
}
private void saveUserInfo() {
user.updateProfile(profile).addOnCompleteListener(new
OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if(task.isSuccessful()){
Toast.makeText(ProfileActivity.this, "Profile Picture Updated",
Toast.LENGTH_SHORT).show();
}
}
});
Datetxt.setText(sdf.format(myCalender.getTime()));
}
//Gender spinner
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinGender.setAdapter(dataAdapter);
user.put("step_goal", stepgoal);
user.put("gender", gender);
user.put("weight", weight);
user.put("height", height);
user.put("weight_goal", weightgoal);
user.put("birthday", birthday);
//get all data in the document and store into a local object
docRef
.get()
.addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot document = task.getResult();
if (document.exists()) {
String strFullName = document.get("firstName").toString() + " " +
document.get("surname").toString();
txtfullname.setText(strFullName);
if(document.get("weight") != null){
txtWeight.setText(document.get("weight").toString());
lblWeight.setText(document.get("weight").toString());
}
if(document.get("height") != null){
txtHeight.setText(document.get("height").toString());
}
if(document.get("weight_goal") != null){
txtWeightGoal.setText(document.get("weight_goal").toString());
}
if(document.get("step_goal") != null){
txtStepGoal.setText(document.get("step_goal").toString());
}
if(document.get("birthday") != null){
Datetxt.setText(document.get("birthday").toString());
}
if(document.get("gender") != null){
int index = 0;
String compareValue = document.get("gender").toString();
} else {
//Log.d(TAG, "No such document");
}
} else {
// Log.d(TAG, "get failed with ", task.getException());
}
}
});
}