commit 35bfe7866a627824222027f919cc4d7c21ca5326 Author: Stepan Date: Sun May 4 12:56:01 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..b2c751a --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ 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..8250bd9 --- /dev/null +++ b/README.md @@ -0,0 +1,19 @@ +# Pizza app + +> This is a school homework project. It is created for educational purposes only and is not intended for commercial use. + +This application contains two activities: one with an order form, and another that displays a success message along with additional information. + +| activity_main.xml | activity_complete.xml | +| ---- | ---- | +| ![main_activity](readme_media/activityPizza.png) | ![complete_activity](readme_media/completedPizza.png) + +## 📁 Main Files + +### Scripts +- [MainActivity.java](app/src/main/java/com/example/domaci_rad_1/MainActivity.java) — handles the order form UI and logic. +- [CompleteOrder.java](app/src/main/java/com/example/domaci_rad_1/CompleteOrder.java) — displays the success message and additional details after the order is submitted. + +### Layouts +- [activity_main.xml](app/src/main/res/layout/activity_main.xml) — layout for the main activity (order form). +- [activity_complete_order.xml](app/src/main/res/layout/activity_main.xml) — layout for the success screen. \ 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..e5ffec0 --- /dev/null +++ b/app/build.gradle.kts @@ -0,0 +1,47 @@ +plugins { + alias(libs.plugins.android.application) +} + +android { + namespace = "com.example.domaci_rad_1" + compileSdk = 35 + + defaultConfig { + applicationId = "com.example.domaci_rad_1" + 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/domaci_rad_1/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/example/domaci_rad_1/ExampleInstrumentedTest.java new file mode 100644 index 0000000..87202c4 --- /dev/null +++ b/app/src/androidTest/java/com/example/domaci_rad_1/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.domaci_rad_1; + +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.domaci_rad_1", 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..7b4eff1 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/example/domaci_rad_1/CompleteOrder.java b/app/src/main/java/com/example/domaci_rad_1/CompleteOrder.java new file mode 100644 index 0000000..0cedc0d --- /dev/null +++ b/app/src/main/java/com/example/domaci_rad_1/CompleteOrder.java @@ -0,0 +1,33 @@ +package com.example.domaci_rad_1; + +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.domaci_rad_1.databinding.ActivityCompleteOrderBinding; + +public class CompleteOrder extends AppCompatActivity { + + private ActivityCompleteOrderBinding binding; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + EdgeToEdge.enable(this); + + binding = ActivityCompleteOrderBinding.inflate(getLayoutInflater()); + View view = binding.getRoot(); + setContentView(view); + + String completedText = getIntent().getStringExtra("completed_text"); + binding.completedText.setText(completedText); + } + public void Backbutton(View view) { + finish(); +; } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/domaci_rad_1/MainActivity.java b/app/src/main/java/com/example/domaci_rad_1/MainActivity.java new file mode 100644 index 0000000..fe09570 --- /dev/null +++ b/app/src/main/java/com/example/domaci_rad_1/MainActivity.java @@ -0,0 +1,172 @@ +package com.example.domaci_rad_1; + +import android.content.Intent; +import android.content.res.Resources; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.CheckBox; + +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.domaci_rad_1.databinding.ActivityMainBinding; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; + +enum SizeType { + NONE, + SMALL, + MEDIUM, + LARGE +} + +public class MainActivity extends AppCompatActivity { + + private SizeType size = SizeType.NONE; + private ArrayList additionalList = new ArrayList(); + + private ActivityMainBinding binding; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + EdgeToEdge.enable(this); + + // View binding + // https://developer.android.com/topic/libraries/view-binding + binding = ActivityMainBinding.inflate(getLayoutInflater()); + View view = binding.getRoot(); + setContentView(view); + + // Automatic event on change value for Radio Group + binding.pizzaSize.setOnCheckedChangeListener((group, checkedId) -> { + if(checkedId == R.id.pizza_size_small) + size = SizeType.SMALL; + + else if (checkedId == R.id.pizza_size_medium) + size = SizeType.MEDIUM; + + else if (checkedId == R.id.pizza_size_large) + size = SizeType.LARGE; + + calculatePriceEvent(); + }); + + // Set handlers on checkboxes + CheckBox[] checkboxes = new CheckBox[] { + binding.cutSlicesCheckbox, + binding.addCutleryCheckbox, + binding.ecoFriendlyCheckbox + }; + for (CheckBox chBox : checkboxes) { + chBox.setOnCheckedChangeListener((group, isChecked) -> { + generateAdditionalList(); + calculatePriceEvent(); + }); + } + + // Set handler on switch + binding.fastDeliverySwitch.setOnCheckedChangeListener((group, isChecked) -> { + calculatePriceEvent(); + }); + } + private void generateAdditionalList() { + ArrayList result = new ArrayList(); + CheckBox[] checkboxes = new CheckBox[] { + binding.cutSlicesCheckbox, + binding.addCutleryCheckbox, + binding.ecoFriendlyCheckbox + }; + for (CheckBox chBox : checkboxes) { + if (chBox.isChecked()) { + result.add(chBox.getText().toString()); + } + } + additionalList = result; + } + protected int calculatePrice() { + return calculatePrice(false); + } + protected int calculatePrice(boolean throwError) { + int price = 0; + + // Calculate size + switch (size) { + case SMALL: + price += 1; + break; + case MEDIUM: + price += 2; + break; + case LARGE: + price += 3; + break; + default: + if(throwError) + throw new RuntimeException("Please, choose pizza size"); + break; + } + + // Additional checkboxes + if(binding.cutSlicesCheckbox.isChecked()) + price += 1; + if(binding.addCutleryCheckbox.isChecked()) + price += 1; + if(binding.ecoFriendlyCheckbox.isChecked()) + price += 2; + + // Fast delivery + if(binding.fastDeliverySwitch.isChecked()) + price += 3; + + return price; + } + protected String getSizeString(SizeType sizeType) { + switch (sizeType) { + case NONE: + return "none"; + case SMALL: + return getString(R.string.small); + case MEDIUM: + return getString(R.string.medium); + case LARGE: + return getString(R.string.large); + } + return "unknown"; + } + protected void calculatePriceEvent() { + int price = calculatePrice(); + binding.totalPriceText.setText(price + "$"); + } + + public void OrderBtn(View view) { + try { + int price = calculatePrice(true); + + Intent intent = new Intent(this, CompleteOrder.class); + + String message = "You ordered " + getSizeString(size) + " pizza with " + calculatePrice() + "$."; + if(!additionalList.isEmpty()) { + message += " Your additional choice: " + String.join(", ", additionalList) + "."; + } + if(binding.fastDeliverySwitch.isChecked()) { + message += " Also your order will be fast delivered"; + } + + intent.putExtra("completed_text", message); + + startActivity(intent); + } + catch (RuntimeException ex) { + binding.errorText.setText(ex.getMessage()); + } + + } +} \ No newline at end of file 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/drawable/order_completed_image.jpg b/app/src/main/res/drawable/order_completed_image.jpg new file mode 100644 index 0000000..e28897b Binary files /dev/null and b/app/src/main/res/drawable/order_completed_image.jpg differ diff --git a/app/src/main/res/drawable/pizza.webp b/app/src/main/res/drawable/pizza.webp new file mode 100644 index 0000000..602e8db Binary files /dev/null and b/app/src/main/res/drawable/pizza.webp differ diff --git a/app/src/main/res/layout/activity_complete_order.xml b/app/src/main/res/layout/activity_complete_order.xml new file mode 100644 index 0000000..49751f8 --- /dev/null +++ b/app/src/main/res/layout/activity_complete_order.xml @@ -0,0 +1,46 @@ + + + + + + + + + +