commit 87735faa856ff0c0d33fbee0742e1209e974e954 Author: Stepan Date: Sun May 18 19:35:24 2025 +0200 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +*.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 +.cxx +local.properties diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/AndroidProjectSystem.xml b/.idea/AndroidProjectSystem.xml new file mode 100644 index 0000000..4a53bee --- /dev/null +++ b/.idea/AndroidProjectSystem.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..b86273d --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml new file mode 100644 index 0000000..b268ef3 --- /dev/null +++ b/.idea/deploymentTargetSelector.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..639c779 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/migrations.xml b/.idea/migrations.xml new file mode 100644 index 0000000..f8051a6 --- /dev/null +++ b/.idea/migrations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..74dd639 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..16660f1 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..61f9f31 --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ +# BMI Calculator + +> This is a school homework project. It is created for educational purposes only and is not intended for commercial use. + +## 📁 Main Files + +### Scripts + +- [MainActivity.java](app/src/main/java/com/example/mbi_calculator/MainActivity.java) +- [DetailActivity.java](app/src/main/java/com/example/mbi_calculator/DetailActivity.java) +- [ResultActivity.java](app/src/main/java/com/example/mbi_calculator/ResultActivity.java) +--- +- [BMIResult.java](app/src/main/java/com/example/mbi_calculator/ResultActivity.java) (for intent Extra) + +### Activities + +- [activity_main.xml](/app/src/main/res/layout/activity_main.xml) +- [activity_result.xml](/app/src/main/res/layout/activity_result.xml) +- [activity_detail.xml](/app/src/main/res/layout/activity_detail.xml) + + +## Screenshots + +| activity_main.xml | activity_result.xml | activity_detail.xml | +| --- | --- | --- | +| ![main](readme_media/MainActivity.png) | ![result](readme_media/ResultActivity.png) | ![detail](readme_media/DetailActivity.png) \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts new file mode 100644 index 0000000..4a1e640 --- /dev/null +++ b/app/build.gradle.kts @@ -0,0 +1,47 @@ +plugins { + alias(libs.plugins.android.application) +} + +android { + namespace = "com.example.mbi_calculator" + compileSdk = 35 + + defaultConfig { + applicationId = "com.example.mbi_calculator" + minSdk = 26 + targetSdk = 35 + versionCode = 1 + versionName = "1.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + buildFeatures { + viewBinding = true + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + } +} + +dependencies { + + implementation(libs.appcompat) + implementation(libs.material) + implementation(libs.activity) + implementation(libs.constraintlayout) + testImplementation(libs.junit) + androidTestImplementation(libs.ext.junit) + androidTestImplementation(libs.espresso.core) +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/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 \ No newline at end of file diff --git a/app/src/androidTest/java/com/example/mbi_calculator/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/example/mbi_calculator/ExampleInstrumentedTest.java new file mode 100644 index 0000000..721098f --- /dev/null +++ b/app/src/androidTest/java/com/example/mbi_calculator/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.mbi_calculator; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.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.getInstrumentation().getTargetContext(); + assertEquals("com.example.mbi_calculator", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..bdef789 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/example/mbi_calculator/BMIResult.java b/app/src/main/java/com/example/mbi_calculator/BMIResult.java new file mode 100644 index 0000000..ce759ab --- /dev/null +++ b/app/src/main/java/com/example/mbi_calculator/BMIResult.java @@ -0,0 +1,66 @@ +package com.example.mbi_calculator; + +import java.io.Serializable; + +public class BMIResult implements Serializable { + public enum Gender { + MAN, + WOMAN + } + public enum BMICategory { + UNDERNUTRITION, + NORMAL, + OVERWEIGHT, + OBESITY + } + + public String name; + public Gender gender; + public int age; + public int height; + public int weight; + + public BMIResult(String name, Gender gender, int age, int height, int weight) { + this.name = name; + this.gender = gender; + this.age = age; + this.height = height; + this.weight = weight; + } + + public String getGenderString() { + if(gender == Gender.MAN) + return "Man"; + else + return "Woman"; + } + public String getUserInfo() { + return this.name + " (" + this.age + ", " + this.getGenderString() + ")"; + } + public double getBMIValue() { + double heightM = this.height / 100.0; + return weight / (heightM * heightM); + } + public BMICategory getBMICategory() { + double bmiValue = getBMIValue(); + if(bmiValue < 18.5) + return BMICategory.UNDERNUTRITION; + if(bmiValue >= 18.5 && bmiValue < 25.0) + return BMICategory.NORMAL; + if(bmiValue >= 25.0 && bmiValue < 30.0) + return BMICategory.OVERWEIGHT; + + return BMICategory.OBESITY; + } + public String getBMICategoryString() { + BMICategory cat = getBMICategory(); + if(cat == BMICategory.UNDERNUTRITION) + return "Pothranjenost"; + if(cat == BMICategory.NORMAL) + return "Normalna težina"; + if(cat == BMICategory.OVERWEIGHT) + return "Prekomerna težina"; + + return "Gojaznost"; + } +} diff --git a/app/src/main/java/com/example/mbi_calculator/DetailActivity.java b/app/src/main/java/com/example/mbi_calculator/DetailActivity.java new file mode 100644 index 0000000..cd6f352 --- /dev/null +++ b/app/src/main/java/com/example/mbi_calculator/DetailActivity.java @@ -0,0 +1,50 @@ +package com.example.mbi_calculator; + +import android.content.Intent; +import android.graphics.Typeface; +import android.os.Bundle; +import android.view.View; + +import androidx.activity.EdgeToEdge; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; + +import com.example.mbi_calculator.databinding.ActivityDetailBinding; + +public class DetailActivity extends AppCompatActivity { + + private ActivityDetailBinding binding; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + EdgeToEdge.enable(this); + + binding = ActivityDetailBinding.inflate(getLayoutInflater()); + View view = binding.getRoot(); + setContentView(view); + + binding.detailLowText.setTypeface(null, Typeface.NORMAL); + binding.detailMediumText.setTypeface(null, Typeface.NORMAL); + binding.detailHighText.setTypeface(null, Typeface.NORMAL); + + Intent intent = getIntent(); + BMIResult bmiResult = (BMIResult) intent.getSerializableExtra("EXTRA_BMI_RESULT"); + if(bmiResult != null) { + BMIResult.BMICategory cat = bmiResult.getBMICategory(); + if(cat == BMIResult.BMICategory.UNDERNUTRITION) + binding.detailLowText.setTypeface(null, Typeface.BOLD); + else if(cat == BMIResult.BMICategory.OBESITY) + binding.detailHighText.setTypeface(null, Typeface.BOLD); + else + binding.detailMediumText.setTypeface(null, Typeface.BOLD); + } + } + public void GoHomeBtn(View view) { + Intent detailIntent = new Intent(this, MainActivity.class); + + startActivity(detailIntent); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/mbi_calculator/MainActivity.java b/app/src/main/java/com/example/mbi_calculator/MainActivity.java new file mode 100644 index 0000000..c2d8f35 --- /dev/null +++ b/app/src/main/java/com/example/mbi_calculator/MainActivity.java @@ -0,0 +1,75 @@ +package com.example.mbi_calculator; + +import android.content.Intent; +import android.os.Bundle; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.widget.Toast; + +import androidx.activity.EdgeToEdge; +import androidx.appcompat.app.AppCompatActivity; + +import com.example.mbi_calculator.databinding.ActivityMainBinding; + + +public class MainActivity extends AppCompatActivity { + + private ActivityMainBinding binding; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + EdgeToEdge.enable(this); + + binding = ActivityMainBinding.inflate(getLayoutInflater()); + View view = binding.getRoot(); + setContentView(view); + } + + public void CalculateBMI(View view) { + String name = binding.nameEditText.getText().toString(); + int age = Integer.parseInt(binding.ageEditText.getText().toString()); + int height = Integer.parseInt(binding.heightEditText.getText().toString()); + int weight = Integer.parseInt(binding.weightEditText.getText().toString()); + BMIResult.Gender gender; + + if(binding.manRadioBtn.isChecked()) + gender = BMIResult.Gender.MAN; + else if (binding.womanRadioBtn.isChecked()) + gender = BMIResult.Gender.WOMAN; + else { + Toast.makeText(this, "You are not chosed your gender", Toast.LENGTH_LONG).show(); + return; + } + + BMIResult bmiResult = new BMIResult(name, gender, age, height, weight); + + Intent resultIntent = new Intent(this, ResultActivity.class); + + resultIntent.putExtra("EXTRA_BMI_RESULT", bmiResult); + + startActivity(resultIntent); + } + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.app_bar_menu, menu); + return true; + } + + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + int id = item.getItemId(); + if (id == R.id.miExit) { + finishAffinity(); + return true; + } else if (id == R.id.miDetail) { + Intent detailIntent = new Intent(this, DetailActivity.class); + + startActivity(detailIntent); + return true; + } + return super.onOptionsItemSelected(item); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/mbi_calculator/ResultActivity.java b/app/src/main/java/com/example/mbi_calculator/ResultActivity.java new file mode 100644 index 0000000..61a90a1 --- /dev/null +++ b/app/src/main/java/com/example/mbi_calculator/ResultActivity.java @@ -0,0 +1,45 @@ +package com.example.mbi_calculator; + +import android.content.Intent; +import android.os.Bundle; +import android.view.View; + +import androidx.activity.EdgeToEdge; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; + +import com.example.mbi_calculator.databinding.ActivityResultBinding; + +public class ResultActivity extends AppCompatActivity { + + private ActivityResultBinding binding; + private BMIResult bmiResult; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + EdgeToEdge.enable(this); + + binding = ActivityResultBinding.inflate(getLayoutInflater()); + View view = binding.getRoot(); + setContentView(view); + + Intent intent = getIntent(); + bmiResult = (BMIResult) intent.getSerializableExtra("EXTRA_BMI_RESULT"); + assert bmiResult != null; + binding.nameText.setText(bmiResult.getUserInfo()); + binding.categoryBMIResult.setText(bmiResult.getBMICategoryString() + "(" + String.format("%.2f", bmiResult.getBMIValue()) + ")"); + } + + public void DetailBtn(View view) { + Intent detailIntent = new Intent(this, DetailActivity.class); + + detailIntent.putExtra("EXTRA_BMI_RESULT", bmiResult); + + startActivity(detailIntent); + + overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left); + } +} \ No newline at end of file diff --git a/app/src/main/res/anim/slide_in_right.xml b/app/src/main/res/anim/slide_in_right.xml new file mode 100644 index 0000000..8ea6000 --- /dev/null +++ b/app/src/main/res/anim/slide_in_right.xml @@ -0,0 +1,5 @@ + + diff --git a/app/src/main/res/anim/slide_out_left.xml b/app/src/main/res/anim/slide_out_left.xml new file mode 100644 index 0000000..0197103 --- /dev/null +++ b/app/src/main/res/anim/slide_out_left.xml @@ -0,0 +1,5 @@ + + diff --git a/app/src/main/res/drawable-anydpi/ic_detail.xml b/app/src/main/res/drawable-anydpi/ic_detail.xml new file mode 100644 index 0000000..064b6b5 --- /dev/null +++ b/app/src/main/res/drawable-anydpi/ic_detail.xml @@ -0,0 +1,12 @@ + + + diff --git a/app/src/main/res/drawable-anydpi/ic_exit.xml b/app/src/main/res/drawable-anydpi/ic_exit.xml new file mode 100644 index 0000000..055f309 --- /dev/null +++ b/app/src/main/res/drawable-anydpi/ic_exit.xml @@ -0,0 +1,14 @@ + + + + diff --git a/app/src/main/res/drawable-hdpi/ic_detail.png b/app/src/main/res/drawable-hdpi/ic_detail.png new file mode 100644 index 0000000..d7485b3 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_detail.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_exit.png b/app/src/main/res/drawable-hdpi/ic_exit.png new file mode 100644 index 0000000..e5a1c6e Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_exit.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_detail.png b/app/src/main/res/drawable-mdpi/ic_detail.png new file mode 100644 index 0000000..d3e736d Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_detail.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_exit.png b/app/src/main/res/drawable-mdpi/ic_exit.png new file mode 100644 index 0000000..b211f8a Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_exit.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_detail.png b/app/src/main/res/drawable-xhdpi/ic_detail.png new file mode 100644 index 0000000..9155cbf Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_detail.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_exit.png b/app/src/main/res/drawable-xhdpi/ic_exit.png new file mode 100644 index 0000000..fef4fd0 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_exit.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_detail.png b/app/src/main/res/drawable-xxhdpi/ic_detail.png new file mode 100644 index 0000000..ac2cd20 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_detail.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_exit.png b/app/src/main/res/drawable-xxhdpi/ic_exit.png new file mode 100644 index 0000000..a998758 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_exit.png differ diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_launcher_foreground.xml b/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_detail.xml b/app/src/main/res/layout/activity_detail.xml new file mode 100644 index 0000000..83aa40a --- /dev/null +++ b/app/src/main/res/layout/activity_detail.xml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + +