Mtmini Project54

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

NATIONAL ENGINEERING COLLEGE DEPARTMENT OF INFORMATION TECHNOLOGY

2115035

MINI PROJECT- FITNESS TRACKING APPLICATION

AIM:

The aim of this project is to develop a fitness tracking application using java programming
language in android.

PROCEDURE:

 Open android studio and open a new project.


 To begin a new project, click file -> new-> New project
 A dialog box will appear, where we have to enter project name. Make sure that
name has no space between words and must be of lower case alphabets.
 Select the language as java.
 Select the API version and set their version as 30.
 Click next -> finish.
 Open the activity_main.xml layout file in Android Studio.
 Design the user interface by adding relevant elements such as text views, buttons, input
fields, and other UI components.
 Consider incorporating elements specific to fitness tracking, such as exercise entry fields,
progress trackers, and visual representations of fitness data.
 Open the MainActivity.java file in Android Studio.
 Implement the necessary functions to handle user interactions, such as button clicks or input
validations.
 Perform Computational operations for tracking fitness data such as steps, distance, calories
burned, etc.
 Finally run the project .

19IT66C –MOBILE TECHNOLOGIES LABORATORY 1


NATIONAL ENGINEERING COLLEGE DEPARTMENT OF INFORMATION TECHNOLOGY
2115035
JAVA CODE :

MainActivity.java:

package com.easyfitness.intro;

import android.content.Intent;
import android.os.Bundle;
import com.easyfitness.DAO.DAOProfile;
import com.easyfitness.R;
import com.heinrichreimersoftware.materialintro.app.IntroActivity;
import com.heinrichreimersoftware.materialintro.slide.FragmentSlide;
import com.heinrichreimersoftware.materialintro.slide.SimpleSlide;
import com.heinrichreimersoftware.materialintro.slide.Slide;

public class MainIntroActivity extends IntroActivity {

public static final String EXTRA_FULLSCREEN =


"com.heinrichreimersoftware.materialintro.demo.EXTRA_FULLSCREEN";
public static final String EXTRA_SCROLLABLE =
"com.heinrichreimersoftware.materialintro.demo.EXTRA_SCROLLABLE";
public static final String EXTRA_CUSTOM_FRAGMENTS =
"com.heinrichreimersoftware.materialintro.demo.EXTRA_CUSTOM_FRAGMENTS";
public static final String EXTRA_PERMISSIONS =
"com.heinrichreimersoftware.materialintro.demo.EXTRA_PERMISSIONS";
public static final String EXTRA_SHOW_BACK =
"com.heinrichreimersoftware.materialintro.demo.EXTRA_SHOW_BACK";
public static final String EXTRA_SHOW_NEXT =
"com.heinrichreimersoftware.materialintro.demo.EXTRA_SHOW_NEXT";
public static final String EXTRA_SKIP_ENABLED =
"com.heinrichreimersoftware.materialintro.demo.EXTRA_SKIP_ENABLED";
public static final String EXTRA_FINISH_ENABLED =
"com.heinrichreimersoftware.materialintro.demo.EXTRA_FINISH_ENABLED";
public static final String EXTRA_GET_STARTED_ENABLED =
"com.heinrichreimersoftware.materialintro.demo.EXTRA_GET_STARTED_ENABLED";

@Override
protected void onCreate(Bundle savedInstanceState) {
Intent intent = getIntent();

boolean customFragments = intent.getBooleanExtra(EXTRA_CUSTOM_FRAGMENTS, true);


boolean permissions = intent.getBooleanExtra(EXTRA_PERMISSIONS, true);
boolean showBack = intent.getBooleanExtra(EXTRA_SHOW_BACK, true);
boolean showNext = intent.getBooleanExtra(EXTRA_SHOW_NEXT, true);
boolean skipEnabled = intent.getBooleanExtra(EXTRA_SKIP_ENABLED, false);
boolean finishEnabled = intent.getBooleanExtra(EXTRA_FINISH_ENABLED, true);
boolean getStartedEnabled = intent.getBooleanExtra(EXTRA_GET_STARTED_ENABLED,
false);

setFullscreen(false);

super.onCreate(savedInstanceState);
19IT66C – MOBILE TECHNOLOGIES LABORATORY 2
NATIONAL ENGINEERING COLLEGE DEPARTMENT OF INFORMATION TECHNOLOGY
2115035

setButtonBackFunction(skipEnabled ? BUTTON_BACK_FUNCTION_SKIP :
BUTTON_BACK_FUNCTION_BACK);
setButtonNextFunction(finishEnabled ? BUTTON_NEXT_FUNCTION_NEXT_FINISH :
BUTTON_NEXT_FUNCTION_NEXT);
setButtonBackVisible(showBack);
setButtonNextVisible(showNext);
setButtonCtaVisible(getStartedEnabled);
setButtonCtaTintMode(BUTTON_CTA_TINT_MODE_TEXT);

addSlide(new SimpleSlide.Builder()
.title(R.string.introSlide1Title)
.description(R.string.introSlide1Text)
.image(R.drawable.web_hi_res_512)
.background(R.color.launcher_background)
.backgroundDark(R.color.launcher_background)
.scrollable(true)
.build());

addSlide(new SimpleSlide.Builder()
.title(R.string.introSlide2Title)
.description(R.string.introSlide2Text)
.image(R.drawable.bench_hi_res_512)
.background(R.color.launcher_background)
.backgroundDark(R.color.launcher_background)
.scrollable(true)
.build());

addSlide(new SimpleSlide.Builder()
.title(R.string.titleSlideEssential)
.description(R.string.textSlideEssential)
.image(R.drawable.idea_hi_res_485)
.background(R.color.launcher_background)
.backgroundDark(R.color.launcher_background)
.scrollable(true)
.build());

addSlide(new SimpleSlide.Builder()
.title(R.string.titleSlideOpenSource)
.description(R.string.textSlideOpenSource)
.image(R.drawable.group_hi_res_512)
.background(R.color.launcher_background)
.backgroundDark(R.color.launcher_background)
.scrollable(true)
.build());

DAOProfile mDbProfils = new DAOProfile(this.getApplicationContext());

if (mDbProfils.getCount() == 0) {

19IT66C – MOBILE TECHNOLOGIES LABORATORY 3


NATIONAL ENGINEERING COLLEGE DEPARTMENT OF INFORMATION TECHNOLOGY
2115035
final Slide profileSlide = new FragmentSlide.Builder()
.background(R.color.launcher_background)
.backgroundDark(R.color.launcher_background)
.fragment(NewProfileFragment.newInstance())
.build();
addSlide(profileSlide);
}
}
}

MeasureFit.java

package com.easyfitness.bodymeasures;

import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.cardview.widget.CardView;

import com.easyfitness.BtnClickListener;
import com.easyfitness.DAO.bodymeasures.DAOBodyMeasure;
import com.easyfitness.R;
import com.easyfitness.enums.Unit;
import com.easyfitness.utils.DateConverter;

import java.util.Date;

public class BodyMeasureCursorAdapter extends CursorAdapter {

private final LayoutInflater mInflater;


BtnClickListener mClickListener = null;
private Context mContext = null;

public BodyMeasureCursorAdapter(Context context, Cursor c, int flags, BtnClickListener mD) {

super(context, c, flags);
mContext = context;
mClickListener = mD;
mInflater = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

@Override
public void bindView(View view, Context context, Cursor cursor) {
19IT66C – MOBILE TECHNOLOGIES LABORATORY 4
NATIONAL ENGINEERING COLLEGE DEPARTMENT OF INFORMATION TECHNOLOGY
2115035

TextView t0 = view.findViewById(R.id.LIST_BODYMEASURE_ID);
t0.setText(cursor.getString(0));

TextView t1 = view.findViewById(R.id.LIST_BODYMEASURE_DATE);
Date date =
DateConverter.DBDateStrToDate(cursor.getString(cursor.getColumnIndex(DAOBodyMeasure.DATE))
);
String dateStr = DateConverter.dateToLocalDateStr(date, mContext);
t1.setText(dateStr);

float measure = cursor.getFloat(cursor.getColumnIndex(DAOBodyMeasure.MEASURE));


Unit unit = Unit.fromInteger(cursor.getInt(cursor.getColumnIndex(DAOBodyMeasure.UNIT)));

String t2Str = String.format("%.1f", measure) + unit.toString();

TextView t2 = view.findViewById(R.id.LIST_BODYMEASURE_WEIGHT);
t2.setText(t2Str);

CardView cdView = view.findViewById(R.id.CARDVIEW);

int mFirstColorOdd = 0;
if (cursor.getPosition() % 2 == mFirstColorOdd) {

cdView.setCardBackgroundColor(context.getResources().getColor(R.color.record_background_even));
}
else {

cdView.setCardBackgroundColor(context.getResources().getColor(R.color.record_background_
odd));
}

ImageView editImg = view.findViewById(R.id.editButton);


editImg.setTag(cursor.getLong(cursor.getColumnIndex(DAOBodyMeasure.KEY)));
editImg.setOnClickListener(v -> {
if (mClickListener != null)
mClickListener.onBtnClick(v);
});

ImageView deletImg = view.findViewById(R.id.deleteButton);


deletImg.setTag(cursor.getLong(cursor.getColumnIndex(DAOBodyMeasure.KEY)));
deletImg.setOnClickListener(v -> {
if (mClickListener != null)
mClickListener.onBtnClick(v);
});

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return mInflater.inflate(R.layout.bodymeasure_row, parent, false);
}
19IT66C – MOBILE TECHNOLOGIES LABORATORY 5
NATIONAL ENGINEERING COLLEGE DEPARTMENT OF INFORMATION TECHNOLOGY
2115035

ExerciseDetailsPagerFragment.java :

package com.easyfitness.machines;

import android.app.AlertDialog;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;

import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;
import androidx.viewpager.widget.ViewPager.OnPageChangeListener;

import com.easyfitness.DAO.DAOMachine;
import com.easyfitness.DAO.DAOProfile;
import com.easyfitness.DAO.Machine;
import com.easyfitness.DAO.Profile;
import com.easyfitness.DAO.record.DAORecord;
import com.easyfitness.DAO.record.Record;
import com.easyfitness.MainActivity;
import com.easyfitness.R;
import com.easyfitness.fonte.FonteHistoryFragment;
import com.github.ivbaranov.mfb.MaterialFavoriteButton;
import com.ogaclejapan.smarttablayout.SmartTabLayout;
import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItemAdapter;
import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItems;

import java.util.List;

public class ExerciseDetailsPager extends Fragment {


Toolbar top_toolbar = null;
long machineIdArg = 0;
long machineProfilIdArg = 0;
FragmentPagerItemAdapter pagerAdapter = null;
ViewPager mViewPager = null;
SmartTabLayout viewPagerTab = null;
ImageButton deleteButton = null;
ImageButton saveButton = null;
MaterialFavoriteButton favoriteButton = null;
Machine machine = null;
boolean isFavorite = false;
19IT66C – MOBILE TECHNOLOGIES LABORATORY 6
NATIONAL ENGINEERING COLLEGE DEPARTMENT OF INFORMATION TECHNOLOGY
2115035
boolean toBeSaved = false;
DAOMachine mDbMachine = null;
private final View.OnClickListener onClickToolbarItem = v -> {
// Handle presses on the action bar items
if (v.getId() == R.id.deleteButton) {
deleteMachine();
} else {
getActivity().onBackPressed();
}
};
DAORecord mDbRecord = null;
private String name;
private int id;

/**
* Create a new instance of DetailsFragment, initialized to
* show the text at 'index'.
*/
public static ExerciseDetailsPager newInstance(long machineId, long machineProfile) {
ExerciseDetailsPager f = new ExerciseDetailsPager();

// Supply index input as an argument.


Bundle args = new Bundle();
args.putLong("machineID", machineId);
args.putLong("machineProfile", machineProfile);
f.setArguments(args);

return f;
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

View view = inflater.inflate(R.layout.exercise_pager, container, false);

// Locate the viewpager in activity_main.xml


mViewPager = view.findViewById(R.id.exercise_viewpager);

if (mViewPager.getAdapter() == null) {

Bundle args = this.getArguments();


machineIdArg = args.getLong("machineID");
machineProfilIdArg = args.getLong("machineProfile");

pagerAdapter = new FragmentPagerItemAdapter(

getChildFragmentManager(), FragmentPagerItems.with(this.getContext())

.add(getString(R.string.MachineLabel), MachineDetailsFragment.class, args)


.add(getString(R.string.HistoryLabel), FonteHistoryFragment.class, args)
.create());
19IT66C – MOBILE TECHNOLOGIES LABORATORY 7
NATIONAL ENGINEERING COLLEGE DEPARTMENT OF INFORMATION TECHNOLOGY
2115035

mViewPager.setAdapter(pagerAdapter);

viewPagerTab = view.findViewById(R.id.exercise_pagertab);
viewPagerTab.setViewPager(mViewPager);

viewPagerTab.setOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}

@Override
public void onPageSelected(int position) {
Fragment frag1 = pagerAdapter.getPage(position);
if (frag1 != null)
frag1.onHiddenChanged(false); // Refresh data
}

@Override
public void onPageScrollStateChanged(int state) {
}
});
}

mDbRecord = new DAORecord(getContext());


mDbMachine = new DAOMachine(getContext());
machine = mDbMachine.getMachine(machineIdArg);

((MainActivity) getActivity()).getActivityToolbar().setVisibility(View.GONE);
top_toolbar = view.findViewById(R.id.actionToolbarMachine);
top_toolbar.setNavigationIcon(R.drawable.ic_back);
top_toolbar.setNavigationOnClickListener(onClickToolbarItem);

deleteButton = view.findViewById(R.id.deleteButton);
deleteButton.setOnClickListener(onClickToolbarItem);
favoriteButton = view.findViewById(R.id.favButton);
favoriteButton.setOnClickListener(v -> {
MaterialFavoriteButton mFav = (MaterialFavoriteButton) v;
boolean t = mFav.isFavorite();
mFav.setFavoriteAnimated(!t);
isFavorite = !t;
saveMachine();
});
favoriteButton.setFavorite(machine.getFavorite());

return view;
}

private void saveMachine() {


final Machine newMachine = getExerciseFragment().getMachine();

// Si le nom n'a pas ete modifie.


19IT66C – MOBILE TECHNOLOGIES LABORATORY 8
NATIONAL ENGINEERING COLLEGE DEPARTMENT OF INFORMATION TECHNOLOGY
2115035
newMachine.setFavorite(favoriteButton.isFavorite());

getExerciseFragment().requestForSave();
}

private void deleteMachine() {


// afficher un message d'alerte
AlertDialog.Builder deleteDialogBuilder = new AlertDialog.Builder(this.getActivity());

deleteDialogBuilder.setTitle(getActivity().getResources().getText(R.string.global_confirm));

deleteDialogBuilder.setMessage(getActivity().getResources().getText(R.string.deleteMachine_confirm_
text));

// Si oui, supprimer la base de donnee et refaire un Start.


deleteDialogBuilder.setPositiveButton(this.getResources().getString(R.string.global_yes), (dialog,
which) -> {
// Suppress the machine
mDbMachine.delete(machine);
// Suppress the associated Fontes records
deleteRecordsAssociatedToMachine();
getActivity().onBackPressed();
});

deleteDialogBuilder.setNegativeButton(this.getResources().getString(R.string.global_no), (dialog,
which) -> {
// Do nothing
dialog.dismiss();
});

AlertDialog deleteDialog = deleteDialogBuilder.create();


deleteDialog.show();
}

private void deleteRecordsAssociatedToMachine() {

DAORecord mDbRecord = new DAORecord(getContext());


DAOProfile mDbProfil = new DAOProfile(getContext());

Profile lProfile = mDbProfil.getProfile(this.machineProfilIdArg);

List<Record> listRecords = mDbRecord.getAllRecordByMachineStrArray(lProfile,


machine.getName());

for (Record record : listRecords) {


mDbRecord.deleteRecord(record.getId());
}
}

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear();
19IT66C – MOBILE TECHNOLOGIES LABORATORY 9
NATIONAL ENGINEERING COLLEGE DEPARTMENT OF INFORMATION TECHNOLOGY
2115035

// Inflate the menu items for use in the action bar


inflater.inflate(R.menu.machine_details_menu, menu);

MenuItem item = menu.findItem(R.id.saveButton);


item.setVisible(toBeSaved);

super.onCreateOptionsMenu(menu, inflater);
}

public MachineDetailsFragment getExerciseFragment() {


return (MachineDetailsFragment) pagerAdapter.getPage(0);
}

public FonteHistoryFragment getHistoricFragment() {


return (FonteHistoryFragment) pagerAdapter.getPage(1);
}

public FragmentPagerItemAdapter getViewPagerAdapter() {

return (FragmentPagerItemAdapter) ((ViewPager)


getView().findViewById(R.id.exercise_viewpager)).getAdapter();
}

@Override
public void onActivityCreated(Bundle savedInstanceState) {

super.onActivityCreated(savedInstanceState);
}

// invoked when the activity may be temporarily destroyed, save the instance state here
@Override
public void onSaveInstanceState(Bundle outState) {
// call superclass to save any view hierarchy
super.onSaveInstanceState(outState);
}

@Override
public void onHiddenChanged(boolean hidden) {
if (!hidden) {
if (getViewPagerAdapter() != null) {
Fragment frag1;

for (int i = 0; i < 3; i++) {


frag1 = getViewPagerAdapter().getPage(i);
if (frag1 != null)
frag1.onHiddenChanged(false); // Refresh data
}
}
}
}
}
19IT66C – MOBILE TECHNOLOGIES LABORATORY 10
NATIONAL ENGINEERING COLLEGE DEPARTMENT OF INFORMATION TECHNOLOGY
2115035

OUTPUT:

19IT66C – MOBILE TECHNOLOGIES LABORATORY 11


NATIONAL ENGINEERING COLLEGE DEPARTMENT OF INFORMATION TECHNOLOGY
2115035

19IT66C – MOBILE TECHNOLOGIES LABORATORY 12


NATIONAL ENGINEERING COLLEGE DEPARTMENT OF INFORMATION TECHNOLOGY
2115035

19IT66C – MOBILE TECHNOLOGIES LABORATORY 13


NATIONAL ENGINEERING COLLEGE DEPARTMENT OF INFORMATION TECHNOLOGY
2115035

RESULT:

Thus the mobile application for creating the fitness tracking application was
developed and executed successfully.

19IT66C – MOBILE TECHNOLOGIES LABORATORY 14

You might also like