diff --git a/P02_HealthCalculator/Somyaguglani/Day2 Task/.gitignore b/P02_HealthCalculator/Somyaguglani/Day2 Task/.gitignore new file mode 100644 index 00000000..2b75303a --- /dev/null +++ b/P02_HealthCalculator/Somyaguglani/Day2 Task/.gitignore @@ -0,0 +1,13 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild diff --git a/P02_HealthCalculator/Somyaguglani/Day2 Task/.idea/encodings.xml b/P02_HealthCalculator/Somyaguglani/Day2 Task/.idea/encodings.xml new file mode 100644 index 00000000..15a15b21 --- /dev/null +++ b/P02_HealthCalculator/Somyaguglani/Day2 Task/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/P02_HealthCalculator/Somyaguglani/Day2 Task/.idea/gradle.xml b/P02_HealthCalculator/Somyaguglani/Day2 Task/.idea/gradle.xml new file mode 100644 index 00000000..2996d531 --- /dev/null +++ b/P02_HealthCalculator/Somyaguglani/Day2 Task/.idea/gradle.xml @@ -0,0 +1,15 @@ + + + + + + \ No newline at end of file diff --git a/P02_HealthCalculator/Somyaguglani/Day2 Task/.idea/misc.xml b/P02_HealthCalculator/Somyaguglani/Day2 Task/.idea/misc.xml new file mode 100644 index 00000000..37a75096 --- /dev/null +++ b/P02_HealthCalculator/Somyaguglani/Day2 Task/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/P02_HealthCalculator/Somyaguglani/Day2 Task/.idea/render.experimental.xml b/P02_HealthCalculator/Somyaguglani/Day2 Task/.idea/render.experimental.xml new file mode 100644 index 00000000..8ec256a5 --- /dev/null +++ b/P02_HealthCalculator/Somyaguglani/Day2 Task/.idea/render.experimental.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/P02_HealthCalculator/Somyaguglani/Day2 Task/.idea/runConfigurations.xml b/P02_HealthCalculator/Somyaguglani/Day2 Task/.idea/runConfigurations.xml new file mode 100644 index 00000000..7f68460d --- /dev/null +++ b/P02_HealthCalculator/Somyaguglani/Day2 Task/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/P02_HealthCalculator/Somyaguglani/Day2 Task/app/.gitignore b/P02_HealthCalculator/Somyaguglani/Day2 Task/app/.gitignore new file mode 100644 index 00000000..796b96d1 --- /dev/null +++ b/P02_HealthCalculator/Somyaguglani/Day2 Task/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/P02_HealthCalculator/Somyaguglani/Day2 Task/app/build.gradle b/P02_HealthCalculator/Somyaguglani/Day2 Task/app/build.gradle new file mode 100644 index 00000000..2f881ffb --- /dev/null +++ b/P02_HealthCalculator/Somyaguglani/Day2 Task/app/build.gradle @@ -0,0 +1,29 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 29 + buildToolsVersion "29.0.0" + defaultConfig { + applicationId "com.example.bmrcalculator" + minSdkVersion 22 + targetSdkVersion 29 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'androidx.appcompat:appcompat:1.0.2' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test:runner:1.2.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' +} diff --git a/P02_HealthCalculator/Somyaguglani/Day2 Task/app/proguard-rules.pro b/P02_HealthCalculator/Somyaguglani/Day2 Task/app/proguard-rules.pro new file mode 100644 index 00000000..f1b42451 --- /dev/null +++ b/P02_HealthCalculator/Somyaguglani/Day2 Task/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/androidTest/java/com/example/bmrcalculator/ExampleInstrumentedTest.java b/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/androidTest/java/com/example/bmrcalculator/ExampleInstrumentedTest.java new file mode 100644 index 00000000..a755b573 --- /dev/null +++ b/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/androidTest/java/com/example/bmrcalculator/ExampleInstrumentedTest.java @@ -0,0 +1,27 @@ +package com.example.bmrcalculator; + +import android.content.Context; + +import androidx.test.InstrumentationRegistry; +import androidx.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("com.example.bmrcalculator", appContext.getPackageName()); + } +} diff --git a/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/AndroidManifest.xml b/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/AndroidManifest.xml new file mode 100644 index 00000000..0e8c68b4 --- /dev/null +++ b/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/AndroidManifest.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/ic_launcher-web.png b/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/ic_launcher-web.png new file mode 100644 index 00000000..45933e95 Binary files /dev/null and b/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/ic_launcher-web.png differ diff --git a/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/java/com/example/bmrcalculator/BMIActivity.java b/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/java/com/example/bmrcalculator/BMIActivity.java new file mode 100644 index 00000000..75ce00f3 --- /dev/null +++ b/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/java/com/example/bmrcalculator/BMIActivity.java @@ -0,0 +1,138 @@ +package com.example.bmrcalculator; + +import androidx.appcompat.app.AppCompatActivity; + +import android.content.Intent; +import android.os.Bundle; +import android.text.TextUtils; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.RadioButton; +import android.widget.RadioGroup; +import android.widget.TextView; + +public class BMIActivity extends AppCompatActivity { + EditText bmi_weight,bmi_height,bmi_age; + TextView ans,bfp,bmi_gender; + Button bmi_cal; + int no = 0; + double find_ans=0.0; + double find_weight,find_height,find_bfp,find_age; + RadioGroup bmi_radiogroup; + RadioButton bmi_radiobutton; + + @Override + public void onBackPressed() { + finish(); + } + + @Override + + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_choosing); + bmi_weight= findViewById(R.id.et_bmi_weight); + bmi_height= findViewById(R.id.et_bmi_height); + bmi_cal= findViewById(R.id.btn_bmi_cal); + ans= findViewById(R.id.tv_bmi_ans); + bfp = findViewById(R.id.tv_bmi_bodyfat); + bmi_radiogroup= findViewById(R.id.rgroup_bmi_radiogroup); + bmi_gender= findViewById(R.id.tv_bmi_gender); + bmi_age= findViewById(R.id.et_bmi_age); + + + + + + bmi_cal.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + + if (TextUtils.isEmpty(bmi_height.getText().toString())) { + bmi_height.setError("Enter height"); + return; + }else if (TextUtils.isEmpty(bmi_age.getText().toString())) { + bmi_age.setError("Enter weight"); + return; + } + else if (TextUtils.isEmpty(bmi_weight.getText().toString())) { + bmi_weight.setError("Enter weight"); + return; + }else if (bmi_radiogroup.getCheckedRadioButtonId() == -1) + { + bmi_gender.setError("Choose gender"); + return ; + } + else{ + + + find_weight= Double.parseDouble(bmi_weight.getText().toString()); + find_age= Double.parseDouble(bmi_age.getText().toString()); + find_height= Double.parseDouble(bmi_height.getText().toString()); + find_ans= find_weight/(find_height*find_height); + + //logic for bmi + ans.setText(Double.toString((Double.parseDouble(String.format("0.2%f",find_ans))))+ " kg/m*m"); + + if(find_ans<16) + ((TextView)(findViewById(R.id.tv_print_stuff))).setText(R.string.severe_underweighgt); + else if(find_ans>=16 && find_ans<16.9) + ((TextView)(findViewById(R.id.tv_print_stuff))).setText(R.string.moderate_weight); + else if(find_ans>=17 && find_ans<18.4) + ((TextView)(findViewById(R.id.tv_print_stuff))).setText("Underweight"); + else if(find_ans>=18.5 && find_ans<24.9) + ((TextView)(findViewById(R.id.tv_print_stuff))).setText("Normal"); + else if(find_ans>=25 && find_ans<29.9) + ((TextView)(findViewById(R.id.tv_print_stuff))).setText("Overweight"); + else if(find_ans>=30 && find_ans<34.9) + ((TextView)(findViewById(R.id.tv_print_stuff))).setText("Obese Class 1"); + else if(find_ans>=35 && find_ans<39.9) + ((TextView)(findViewById(R.id.tv_print_stuff))).setText("Obese Class 2"); + else if(find_ans>=40) + ((TextView)(findViewById(R.id.tv_print_stuff))).setText("Obese Class 3"); + + //logic for bmi over + + + //logic for bfp + + if(no==1){ + + if(find_age>= 0 && find_age<=17) + find_bfp= 1.51*find_ans-0.70*find_age+1.4; + else if(find_age>=18) + find_bfp= 1.2*find_ans + 0.23*find_age -5.4; + + }else if(no==2){ + + if(find_age>= 0 && find_age<=17) + find_bfp= 1.51*find_ans-0.70*find_age-2.2; + else if(find_age>=18) + find_bfp= 1.2*find_ans + 0.23*find_age -16.2; + + } + + bfp.setText(Double.toString((Double.parseDouble(String.format("0.2%f",find_bfp))))+ " %"); + + //logic for bfp over + + } + } + }); + + + } + public void Check_gender(View view) { + switch(view.getId()){ + + case R.id.rbtn_bmi_male: + no=2; + break; + case R.id.rbtn_bmi_female: + no=1; + break; + + } + } +} diff --git a/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/java/com/example/bmrcalculator/ChoosingActivity.java b/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/java/com/example/bmrcalculator/ChoosingActivity.java new file mode 100644 index 00000000..d0762537 --- /dev/null +++ b/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/java/com/example/bmrcalculator/ChoosingActivity.java @@ -0,0 +1,64 @@ +package com.example.bmrcalculator; + +import androidx.appcompat.app.AppCompatActivity; + +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.ImageButton; + +public class ChoosingActivity extends AppCompatActivity { + + ImageButton bmi,bmr; + + + @Override + public void onBackPressed() { + new AlertDialog.Builder(ChoosingActivity.this) + .setMessage("Are you sure you want to exit?") + .setCancelable(false) + .setIcon(android.R.drawable.ic_dialog_alert) + .setPositiveButton("Ok", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + finishAffinity(); + } + }) + .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + + } + }) + .show(); + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_choosing); + + bmi= findViewById(R.id.imbtn_bmi); + bmr = findViewById(R.id.imbtn_bmr); + + bmi.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent i = new Intent(ChoosingActivity.this,BMIActivity.class); + startActivity(i); + } + }); + bmr.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent i = new Intent(ChoosingActivity.this,MainActivity.class); + startActivity(i); + } + }); + + + + } +} diff --git a/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/java/com/example/bmrcalculator/MainActivity.java b/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/java/com/example/bmrcalculator/MainActivity.java new file mode 100644 index 00000000..8969fad6 --- /dev/null +++ b/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/java/com/example/bmrcalculator/MainActivity.java @@ -0,0 +1,130 @@ +package com.example.bmrcalculator; + +import androidx.appcompat.app.AppCompatActivity; + +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.content.Intent; +import android.os.Bundle; +import android.text.TextUtils; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.RadioButton; +import android.widget.RadioGroup; +import android.widget.TextView; + +public class MainActivity extends AppCompatActivity { + + EditText age,weight,height; + int gen = 0 ; + TextView gender; + Button calculate; + RadioGroup radiogroup; + RadioButton radiobutton; + int find_age; + double find_ans=0.0; + double find_weight,find_height; + + @Override + public void onBackPressed() { + finish();; + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + + radiogroup= findViewById(R.id.rgroup_radiogroup); + age = findViewById(R.id.et_age); + weight= findViewById(R.id.et_weight); + height= findViewById(R.id.et_height); + calculate= findViewById(R.id.btn_calculate); + gender= findViewById(R.id.tv_gender); + + + calculate.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if(TextUtils.isEmpty(age.getText().toString())) { + age.setError("Enter age"); + return; + } + else if (TextUtils.isEmpty(height.getText().toString())) { + height.setError("Enter height"); + return; + } + else if (TextUtils.isEmpty(weight.getText().toString())) { + weight.setError("Enter weight"); + return; + } + + else if (radiogroup.getCheckedRadioButtonId() == -1) + { + gender.setError("Choose gender"); + return ; + }else{ + + find_age= Integer.parseInt(age.getText().toString()); + find_weight= Double.parseDouble(weight.getText().toString()); + find_height= Double.parseDouble(height.getText().toString()); + + + if(gen==1){ + + if(find_age>=10 && find_age<=17) + find_ans= 13.4*find_weight + 692; + else if(find_age>=18 && find_age<=29) + find_ans= 14.8*find_weight + 487; + else if(find_age>=30 && find_age<=59) + find_ans= 8.3*find_weight + 846; + else if (find_age>=60) + find_ans = 9.247*find_weight+ 3.098*find_height - 4.330*find_age + 447.593; + + + }else if(gen==2){ + + + if(find_age>=10 && find_age<=17) + find_ans= 17.7*find_weight + 657; + else if(find_age>=18 && find_age<=29) + find_ans= 15.1*find_weight + 692; + else if(find_age>=30 && find_age<=59) + find_ans= 11.5*find_weight + 873; + else if (find_age>=60) + find_ans = 13.397*find_weight+ 4.799*find_height - 5.677*find_age + 88.362; + + + } + + Intent intent = new Intent(MainActivity.this,OtherActivity.class); + intent.putExtra("ANS",Double.toString(Double.parseDouble(String.format("%.2f", find_ans)))); + startActivity(intent); + + + + + } + } + }); + + + + + } + + public void Check_gender(View view) { + switch(view.getId()){ + + case R.id.rbtn_male: + gen=2; + break; + case R.id.rbtn_female: + gen=1; + break; + + } + } +} diff --git a/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/java/com/example/bmrcalculator/OtherActivity.java b/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/java/com/example/bmrcalculator/OtherActivity.java new file mode 100644 index 00000000..c512299f --- /dev/null +++ b/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/java/com/example/bmrcalculator/OtherActivity.java @@ -0,0 +1,27 @@ +package com.example.bmrcalculator; + +import androidx.appcompat.app.AppCompatActivity; + +import android.content.Intent; +import android.os.Bundle; +import android.widget.TextView; + +public class OtherActivity extends AppCompatActivity { + + @Override + public void onBackPressed() { + finish(); + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_other); + + if(getIntent()!=null){ + ((TextView)(findViewById(R.id.tv_ans))).setText(getIntent().getStringExtra("ANS") + " cal/day"); + + } + + } +} diff --git a/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 00000000..1f6bb290 --- /dev/null +++ b/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/res/drawable/bmi_pic.jpg b/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/res/drawable/bmi_pic.jpg new file mode 100644 index 00000000..a49849b7 Binary files /dev/null and b/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/res/drawable/bmi_pic.jpg differ diff --git a/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/res/drawable/bmr_pic.jpg b/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/res/drawable/bmr_pic.jpg new file mode 100644 index 00000000..d511b033 Binary files /dev/null and b/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/res/drawable/bmr_pic.jpg differ diff --git a/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/res/drawable/btn_calculate_background.xml b/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/res/drawable/btn_calculate_background.xml new file mode 100644 index 00000000..8949020c --- /dev/null +++ b/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/res/drawable/btn_calculate_background.xml @@ -0,0 +1,11 @@ + + + + + + + + \ No newline at end of file diff --git a/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/res/drawable/healthy_pic.jpg b/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/res/drawable/healthy_pic.jpg new file mode 100644 index 00000000..8031dac9 Binary files /dev/null and b/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/res/drawable/healthy_pic.jpg differ diff --git a/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/res/drawable/healthyimagetwo_pic.jpg b/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/res/drawable/healthyimagetwo_pic.jpg new file mode 100644 index 00000000..c1c7a047 Binary files /dev/null and b/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/res/drawable/healthyimagetwo_pic.jpg differ diff --git a/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/res/drawable/ic_launcher_background.xml b/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 00000000..2408e30d --- /dev/null +++ b/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/res/layout/activity_bmi.xml b/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/res/layout/activity_bmi.xml new file mode 100644 index 00000000..29a5e57a --- /dev/null +++ b/P02_HealthCalculator/Somyaguglani/Day2 Task/app/src/main/res/layout/activity_bmi.xml @@ -0,0 +1,199 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +