Download as pdf or txt
Download as pdf or txt
You are on page 1of 56

“DietExpert”

A Project Submitted to
Rajiv Gandhi Proudyogiki Vishwavidyalaya

Towards Partial Fulfillment for the Award of Bachelor of


Engineering in Computer Science & Engineering

Submitted By: Guided By:


Garvita Gehlot(0827CS171076) Prof. Sukrati Agrawal
Department of Computer Science and
Engineering,(AITR), Indore

Acropolis Institute of Technology & Research, Indore


JAN-JULY 2021 Batch
DietExpert

EXAMINER APPROVAL

The Project entitled “DietExpert” submitted by Garvita Gehlot(0827CS171076) has been


examined and is hereby approved towards partial fulfillment for the award of Bachelor
of Engineering degree in Computer Science & Engineering discipline, for which it has
been submitted. It understood that by this approval the undersigned do not necessarily
endorse or approve any statement made, opinion expressed or conclusion drawn
therein, but approve the project only for the purpose for which it has been submitted.

(Internal Examiner) (External Examiner)

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.

Project Guide: Project Coordinator


Prof. Sukarati Agrawal
DietExpert

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.

Keywords: Diet Plan, Diet Consultant, BMI.


“Where the vision is one year, cultivate flowers;

Where the vision is ten years, cultivate trees;

Where the vision is eternity, cultivate people.” –


Oriental Saying
List of Figures

Fig1. Organizational and Functional chart

Fig2. Comparisons with existing diet applications

Fig3. Block Diagram

Fig4. Diagram of Prototype Model

Fig5. User Use Case Diagram

Fig6. Dietitian Use Case Diagram

Fig7. Admin Use Case Diagram

Fig8. User Sequence Model

Fig9. Dietitian Sequence Model

Fig10. Admin Sequence Model

Fig.11. Source Code

Fig12. Source Code

Fig13. Application Layout (Welcome Screen)

Fig 13.1. Sign-up Screen

Fig. 13.2. Profile Screen

Fig 13.3. BMI calculation Screen


List of Abbreviations
Fig – Figure

BMI – Body Mass Index


Table of Content
Chapter1. Introduction…………………………………………………………………………………………………………….1

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

Chapter2. Review of Literature…………………………………………………………………………………………………6

2.1. Preliminary Investigation………………………………………………………………………………………..6


2.1.1 Current System……………………………………………………………………….…………………………….7
2.2. Limitations of Current System…………………………………………………………………………………8
2.3 Requirement Identification and Analysis for Project…………………………………………………9

Chapter3. Proposed Systems …………………………………………………………………………………………………10

3.1 Proposed System……………………………………………………………………………………………………10


3.2 Benefits of Proposed System …………………………………………………………………………………11
3.3 Block Diagram…………………………………………………………………………………………………………xx
3.4 Diagram of Prototype………………………………………………………………………………………………xx

3.4.1 Advantage of Prototype……………………………………………………………………………xx


3.4.2 Disadvantage of Prototype……………………………………………………………………….xx

3.5 Data Modeling Language…………………………………………………………………………………………xx

3.5.1 Use Case Diagram………………………………………………………………………………………xx

3.5.2 Sequence Diagram……………………………………………………………………………………..xx

3.6 Deployment Requirements……………………………………………………………………………………..xx

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.

4. Unaware of amount of fat required by body.

Thus, the system implemented has the following objectives:

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.

1. It calculates your BMI and tells you which diet to follow.

2. Diet plan varies from person to person and by age.

3. It is easy to use because of its simple interface and speech recognition.


1.4 Scope of the Project
The proposed system is fully computerized, which removes all the drawbacks of existing system. In
this proposed system of android artificial intelligence diet consultant, using the technique of artificial
intelligence, you will get access to all the facilities via this application, which is actually provided by a
human dietitian. The main advantage of using this standalone 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.

Some points on proposed system are:

• It calculates your BMI and tells you which diet to follow.


• Diet plan varies from person to person and by age.
• It is easy to use because of its simple interface.

Fig1. Organizational and functional chart


1.5 Report Structure
This project DietExpert is primarily concerned with the balanced and nutrition diet for users and the
whole project report is categorized into five chapters.

Chapter 1: Introduction: Introduces the background of the problem followed by rationale


for the project undertaken. The chapter describes the objectives, scope and applications of the
project. Further, the chapter gives the details of Report Structure including all parts of the report.

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.

Chapter 4: Implementation: Includes the details of different Technology/ Techniques/

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.

2.1 Preliminary Investigation

2.1.1 Current System:

• 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

2.2 Limitation of Current System

The limitations of Current System are:

• 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.

2.3 Requirement Identification and analysis for Project

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

3.1 Proposed System


The proposed system is fully computerized, which removes all the drawbacks of existing
system. In this proposed system of artificial intelligence diet consultant, using the technique of
artificial intelligence, you will get access to all the facilities via this application, which is actually
provided by a human dietitian.

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.

3.2 Benefits of Proposed System

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

Fig 3 Block Diagram

3.4 Diagram of Prototype Model used

Fig4. Diagram of Prototype Model


3.4.1. Advantages of Prototyping

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"

3.4.2. Disadvantages of Prototyping

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.

3.5 Data Modeling Language

3.5.1. Use case diagram:

“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:

USECASE DIGRAM FOR USER:

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.

Fig5. User Use case Diagram

USE CASE DIGRAM FOR Dietitian:

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

USE CASE DIGRAM FOR Admin:

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.

Fig7. Admin Use Case Diagram


3.5.2. Sequence Diagram:

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

User Sequence model

Fig8. User Sequence Model


Dietitian Sequence Diagram

Fig9. Dietitian Sequence Diagram


Admin Sequence diagram

Fig10. Admin Sequence Diagram

3.6 Deployment Requirements

There are various requirements (hardware, software and services) to successfully deploy the
system. These are mentioned below:

3.6.1 Hardware

• 64-bit, x86 Processing system


• Windows 10 or later operating system
• High processing computer system without GPU or with GPU (high performance)
• High-RAM 8GB+
3.6.2 Software

• 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

Fig11. Source Code


Fig12. Source Code
4.3 Application Layout

Fig13. Application Layout (Welcome Screen)


Fig 13.1 SignUp screen
Fig 13.2 Profile Screen
Fig13.3 BMI Calculation Screen
Chapter 5 Conclusion

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

5.2 Future Scope


• This application can be further improved by feedback suggestions from the users.
• This application can be improved with the help of an expert nutritionist who can help us
creating different types of programs for different classification of users.
• The project is easily extensible and can be improved by further incremental releases of
the same.
• We plan to focus on improving the overall performance of the system. Also, interaction
between guider and dietitian through video calling and secure prescription will be
focused upon.
• Some more ways to achieve dietitian will be focused.
Bibliography

[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.

[7] Khan,A. and Hoffmann,A.(2003). ‘Building a case-based diet recommendation system


without a knowledge engineer,’ Artificial Intelligence in Medicine, 27, 155–179.

[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.

[10]Balintfy JL. Menu planning by computer. Communications of the ACM. 1964;7(4):255–259.


doi: 10.1145/364005.364087.

[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;

public class BMI extends AppCompatActivity {

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);

final TextView female_text = findViewById(R.id.female);


final TextView male_text = findViewById(R.id.male);

CardView card_female = findViewById(R.id.cardView_female);


CardView card_male = findViewById(R.id.cardView_male);

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();

Button calculate = findViewById(R.id.calculate);


calculate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CalculateBMI();
}
});

private void 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));
}
});
}

private void CheckWeight() {

final TextView weight_txt = findViewById(R.id.weight);

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());

private void CheckSeekbarStatus() {

SeekBar Seekbar = findViewById(R.id.Seekbar);


Seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean
fromUser) {
String ht = progress + getResources().getString(R.string.cm);
height_txt.setText(ht);
height = (float)(progress)/100;
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {

@Override
public void onStopTrackingTouch(SeekBar seekBar) {

}
});
}

private void CalculateBMI() {

float BMI = weight / (height * height);


Intent intent = new Intent(BMI.this,Bmiresult.class);
intent.putExtra("BMI",BMI);
intent.putExtra("age",age.getText().toString());
startActivity(intent);
}
}
package com.example.vcfitness;

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;

public class Bmiresult extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bmiresult);
Intent intent = getIntent();

float BMI = Math.round((intent.getFloatExtra("BMI", 0) * 100) / 100);


String age_value = intent.getStringExtra("age");

TextView your_bmi = findViewById(R.id.your_bmi);


your_bmi.setText(String.valueOf(BMI));

TextView age = findViewById(R.id.age);


age.setText(age_value);

TextView category = findViewById(R.id.category);


Category category1 = new Category();
category.setText(category1.getCategory(BMI));

TextView condition = findViewById(R.id.condition);


Condition condition1 = new Condition();
condition.setText(condition1.getCategory(BMI));

Button recalculate = findViewById(R.id.recalculate);


recalculate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
updateUI();
}
});

private void updateUI() {


Intent intent1 = new Intent(Bmiresult.this,MainActivity.class);
startActivity(intent1);
fileList();
}

@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>

<?xml version="1.0" encoding="utf-8"?>


<androidx.constraintlayout.widget.ConstraintLayout
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=".Bmiresult">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/your_result"
android:textColor="@android:color/white"
android:textSize="40sp"
android:layout_margin="16dp"
android:textStyle="bold"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
app:layout_constraintBottom_toTopOf="@+id/result_card"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<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;

public class ProfileActivity extends AppCompatActivity {

//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();

//calender datepicker code


Datetxt = findViewById(R.id.txtDate);

final DatePickerDialog.OnDateSetListener date = new


DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int MonthOfYear, int
dayOfMonth) {
myCalender.set(Calendar.YEAR, year);
myCalender.set(Calendar.MONTH, MonthOfYear);
myCalender.set(Calendar.DAY_OF_MONTH, dayOfMonth);
updateLabel();
}
};

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();

public void Change_pp(View view)


{
selectImage();

}
private void loadProfilePicture() throws IOException {

Uri pictureUrl = mAuth.getCurrentUser().getPhotoUrl();


FirebaseStorage storage = FirebaseStorage.getInstance();

StorageReference storageRef = storage.getReferenceFromUrl(pictureUrl.toString());


final File localFile = File.createTempFile("images", "jpg");

//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) {

//use camera to take a picture


if (options[item].equals("Take Photo"))
{
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File f = new
File(android.os.Environment.getExternalStorageDirectory(), "temp.jpg");
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
startActivityForResult(intent, REQUEST_CAMERA);
}
//choose a picture from the gallery
else if (options[item].equals("Choose from Gallery"))
{
Intent intent = new
Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, SELECT_IMAGE);
}
else if (options[item].equals("Cancel")) {
dialog.dismiss();
}
}
});
builder.show();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent
data)
{

//add the image to an imageview to see the picture before uploading


super.onActivityResult(requestCode, resultCode, data);

if(requestCode == SELECT_IMAGE && resultCode == RESULT_OK && data != null &&


data.getData() != null){

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");

private void UploadImageToFireBaseStorage() {

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() {

FirebaseUser user = mAuth.getCurrentUser();

if(user != null && profileimageUrl != null){


UserProfileChangeRequest profile = new
UserProfileChangeRequest.Builder().setPhotoUri(Uri.parse(profileimageUrl)).build();

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();
}
}
});

public void Choose_Date(View view) {

private void updateLabel() {


String myFormat = "dd/MM/yy";
SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.US);

Datetxt.setText(sdf.format(myCalender.getTime()));
}

//load all spinners (dropdown selection)


private void LoadSpinners(){

//Gender spinner

List<String> list = new ArrayList<String>();


list.add("Male");
list.add("Female");
list.add("Other");
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, list);

dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinGender.setAdapter(dataAdapter);

//update users profile in firestore with any updated information


public void update_Profile(View view) {
int weightgoal = Integer.parseInt(txtWeightGoal.getText().toString());
int weight = Integer.parseInt(txtWeight.getText().toString());
int height = Integer.parseInt(txtHeight.getText().toString());
int stepgoal = Integer.parseInt(txtStepGoal.getText().toString());
String birthday = Datetxt.getText().toString();
String gender = spinGender.getSelectedItem().toString();

String userid = mAuth.getUid();

Map<String, Object> user = new HashMap<>();

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);

// Add a new document with a generated ID


db.collection("users").document(userid)
.update(user)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {

Toast.makeText(ProfileActivity.this, "DB Insert success",


Toast.LENGTH_LONG).show();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
//Log.w(TAG, "Error adding document", e);
Toast.makeText(ProfileActivity.this, "DB Insert failed: " + e,
Toast.LENGTH_LONG).show();
}
});

//load users profile information from firestore into a local object


private void LoadProfileInfo()
{

//get current firebase user


FirebaseUser user = mAuth.getCurrentUser();

//get user Id from user


String strUid = user.getUid();

//set a document reference with the userID


DocumentReference docRef = db.collection("users").document(strUid);

//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();

for(int i = 0; i < spinGender.getCount(); i++){


if(spinGender.getItemAtPosition(i).equals(compareValue)){
index = i;
}
}
spinGender.setSelection(index);
}

} else {
//Log.d(TAG, "No such document");
}
} else {
// Log.d(TAG, "get failed with ", task.getException());
}
}
});
}

You might also like