From d7eecaf9530b7951c5d57fa76319b875b11def92 Mon Sep 17 00:00:00 2001 From: adeptofstroggus Date: Thu, 25 Dec 2025 22:16:11 +0300 Subject: [PATCH] =?UTF-8?q?=D0=92=D1=8B=D0=B3=D1=80=D1=83=D0=B7=D0=BA?= =?UTF-8?q?=D0=B0=20=D1=82=D0=B5=D1=81=D1=82=D0=B0=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/.gitignore | 1 + app/build.gradle.kts | 43 ++++ app/proguard-rules.pro | 21 ++ .../laba2_2/ExampleInstrumentedTest.java | 26 +++ app/src/main/AndroidManifest.xml | 25 +++ .../com/adeptofstroggus/laba2_2/Adapter.java | 45 +++++ .../com/adeptofstroggus/laba2_2/Item.java | 20 ++ .../adeptofstroggus/laba2_2/MainActivity.java | 95 +++++++++ .../adeptofstroggus/laba2_2/ViewHolder.java | 46 +++++ .../res/drawable/ic_launcher_background.xml | 170 ++++++++++++++++ .../res/drawable/ic_launcher_foreground.xml | 30 +++ app/src/main/res/layout/activity_main.xml | 32 +++ app/src/main/res/layout/dialog_add_item.xml | 50 +++++ app/src/main/res/layout/item_layout.xml | 54 +++++ .../main/res/mipmap-anydpi/ic_launcher.xml | 6 + .../res/mipmap-anydpi/ic_launcher_round.xml | 6 + app/src/main/res/mipmap-hdpi/ic_launcher.webp | Bin 0 -> 1404 bytes .../res/mipmap-hdpi/ic_launcher_round.webp | Bin 0 -> 2898 bytes app/src/main/res/mipmap-mdpi/ic_launcher.webp | Bin 0 -> 982 bytes .../res/mipmap-mdpi/ic_launcher_round.webp | Bin 0 -> 1772 bytes .../main/res/mipmap-xhdpi/ic_launcher.webp | Bin 0 -> 1900 bytes .../res/mipmap-xhdpi/ic_launcher_round.webp | Bin 0 -> 3918 bytes .../main/res/mipmap-xxhdpi/ic_launcher.webp | Bin 0 -> 2884 bytes .../res/mipmap-xxhdpi/ic_launcher_round.webp | Bin 0 -> 5914 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.webp | Bin 0 -> 3844 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.webp | Bin 0 -> 7778 bytes app/src/main/res/values-night/themes.xml | 7 + app/src/main/res/values/colors.xml | 5 + app/src/main/res/values/strings.xml | 3 + app/src/main/res/values/themes.xml | 9 + app/src/main/res/xml/backup_rules.xml | 13 ++ .../main/res/xml/data_extraction_rules.xml | 19 ++ .../laba2_2/ExampleUnitTest.java | 17 ++ build.gradle.kts | 4 + gradle.properties | 21 ++ gradle/libs.versions.toml | 22 +++ gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 59203 bytes gradle/wrapper/gradle-wrapper.properties | 6 + gradlew | 185 ++++++++++++++++++ gradlew.bat | 89 +++++++++ settings.gradle.kts | 24 +++ 41 files changed, 1094 insertions(+) create mode 100644 app/.gitignore create mode 100644 app/build.gradle.kts create mode 100644 app/proguard-rules.pro create mode 100644 app/src/androidTest/java/com/adeptofstroggus/laba2_2/ExampleInstrumentedTest.java create mode 100644 app/src/main/AndroidManifest.xml create mode 100644 app/src/main/java/com/adeptofstroggus/laba2_2/Adapter.java create mode 100644 app/src/main/java/com/adeptofstroggus/laba2_2/Item.java create mode 100644 app/src/main/java/com/adeptofstroggus/laba2_2/MainActivity.java create mode 100644 app/src/main/java/com/adeptofstroggus/laba2_2/ViewHolder.java create mode 100644 app/src/main/res/drawable/ic_launcher_background.xml create mode 100644 app/src/main/res/drawable/ic_launcher_foreground.xml create mode 100644 app/src/main/res/layout/activity_main.xml create mode 100644 app/src/main/res/layout/dialog_add_item.xml create mode 100644 app/src/main/res/layout/item_layout.xml create mode 100644 app/src/main/res/mipmap-anydpi/ic_launcher.xml create mode 100644 app/src/main/res/mipmap-anydpi/ic_launcher_round.xml create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher.webp create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher_round.webp create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher.webp create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher_round.webp create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher.webp create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher.webp create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp create mode 100644 app/src/main/res/values-night/themes.xml create mode 100644 app/src/main/res/values/colors.xml create mode 100644 app/src/main/res/values/strings.xml create mode 100644 app/src/main/res/values/themes.xml create mode 100644 app/src/main/res/xml/backup_rules.xml create mode 100644 app/src/main/res/xml/data_extraction_rules.xml create mode 100644 app/src/test/java/com/adeptofstroggus/laba2_2/ExampleUnitTest.java create mode 100644 build.gradle.kts create mode 100644 gradle.properties create mode 100644 gradle/libs.versions.toml create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100755 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle.kts 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..6b0a8db --- /dev/null +++ b/app/build.gradle.kts @@ -0,0 +1,43 @@ +plugins { + alias(libs.plugins.android.application) +} + +android { + namespace = "com.adeptofstroggus.laba2_2" + compileSdk = 36 + + defaultConfig { + applicationId = "com.adeptofstroggus.laba2_2" + minSdk = 31 + targetSdk = 36 + versionCode = 1 + versionName = "1.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + 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/adeptofstroggus/laba2_2/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/adeptofstroggus/laba2_2/ExampleInstrumentedTest.java new file mode 100644 index 0000000..2a35905 --- /dev/null +++ b/app/src/androidTest/java/com/adeptofstroggus/laba2_2/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.adeptofstroggus.laba2_2; + +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.adeptofstroggus.laba2_2", 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..e2d8658 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/adeptofstroggus/laba2_2/Adapter.java b/app/src/main/java/com/adeptofstroggus/laba2_2/Adapter.java new file mode 100644 index 0000000..f719a66 --- /dev/null +++ b/app/src/main/java/com/adeptofstroggus/laba2_2/Adapter.java @@ -0,0 +1,45 @@ +package com.adeptofstroggus.laba2_2; + +import android.os.Debug; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import java.util.ArrayList; +import java.util.List; + +public class Adapter extends RecyclerView.Adapter { + public List itemsList; + + public Adapter() { + this.itemsList = new ArrayList<>(); + } + + public void addItem(Item item){ + itemsList.add(item); + } + + + @NonNull + @Override + public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + View itemView = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.item_layout, parent, false); + return new ViewHolder(itemView); + } + + @Override + public void onBindViewHolder(ViewHolder holder, int position) { + Item currentItem = itemsList.get(position); + holder.bind(currentItem); + } + + @Override + public int getItemCount() { + return itemsList.size(); + } +} + diff --git a/app/src/main/java/com/adeptofstroggus/laba2_2/Item.java b/app/src/main/java/com/adeptofstroggus/laba2_2/Item.java new file mode 100644 index 0000000..69f50f2 --- /dev/null +++ b/app/src/main/java/com/adeptofstroggus/laba2_2/Item.java @@ -0,0 +1,20 @@ +package com.adeptofstroggus.laba2_2; + +public class Item { + public String name; + private Integer value; + + public void incValue(){ + value += 1; + } + public void decValue(){ + value -= 1; + } + public Integer getValue(){ + return value; + } + Item(String name, Integer value){ + this.name = name; + this.value = value; + } +} diff --git a/app/src/main/java/com/adeptofstroggus/laba2_2/MainActivity.java b/app/src/main/java/com/adeptofstroggus/laba2_2/MainActivity.java new file mode 100644 index 0000000..1991ca5 --- /dev/null +++ b/app/src/main/java/com/adeptofstroggus/laba2_2/MainActivity.java @@ -0,0 +1,95 @@ +package com.adeptofstroggus.laba2_2; + +import android.app.AlertDialog; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; + +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 androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import java.util.ArrayList; +import java.util.List; + +public class MainActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + EdgeToEdge.enable(this); + setContentView(R.layout.activity_main); + ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { + Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); + v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); + return insets; + }); + + Item item1_debug = new Item("Пакета травы", 2); + Item item2_debug = new Item("Ампулы мескалина", 75); + Item item3_debug = new Item("Упаковка кислоты", 5); + + Adapter adapter = new Adapter(); + adapter.addItem(item1_debug); + adapter.addItem(item2_debug); + adapter.addItem(item3_debug); + adapter.notifyDataSetChanged(); + RecyclerView recyclerView = findViewById(R.id.recyclerView); + + recyclerView.setAdapter(adapter); + recyclerView.setLayoutManager(new LinearLayoutManager(this)); + + Button addButton = findViewById(R.id.addButton); + addButton.setOnClickListener(v -> showAddDialog(adapter.itemsList, adapter)); + } + + private void showAddDialog(List itemsList, Adapter adapter) { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle("Добавить элемент"); + + // Создаем layout для ввода данных + View dialogView = LayoutInflater.from(this).inflate(R.layout.dialog_add_item, null); + EditText nameEditText = dialogView.findViewById(R.id.nameInput); + EditText numberEditText = dialogView.findViewById(R.id.numberInput); + + builder.setView(dialogView); + builder.setPositiveButton("Добавить", (dialog, which) -> { + String name; + int number; + + try { + name = nameEditText.getText().toString(); + if(name == "") { + name = "Безымянный элемент"; + } + } + catch (Exception e) { + name = "Безымянный"; + } + + try { + number = Integer.parseInt(numberEditText.getText().toString()); + } + catch (Exception e) { + number = 0; + } + + + + Item newItem = new Item(name, number); + itemsList.add(newItem); + adapter.notifyItemInserted(itemsList.size() - 1); + }); + + + + builder.setNegativeButton("Отмена", (dialog, which) -> dialog.dismiss()); + builder.show(); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/adeptofstroggus/laba2_2/ViewHolder.java b/app/src/main/java/com/adeptofstroggus/laba2_2/ViewHolder.java new file mode 100644 index 0000000..b0442fc --- /dev/null +++ b/app/src/main/java/com/adeptofstroggus/laba2_2/ViewHolder.java @@ -0,0 +1,46 @@ +package com.adeptofstroggus.laba2_2; + +import android.view.View; +import android.widget.Button; +import android.widget.TextView; + +import androidx.recyclerview.widget.RecyclerView; + +public class ViewHolder extends RecyclerView.ViewHolder { + TextView nameTextView; + TextView numberTextView; + Button plusButton; + Button minusButton; + + private void UpdateText(Item item){ + numberTextView.setText(item.getValue().toString()); + } + public ViewHolder(View itemView) { + super(itemView); + nameTextView = itemView.findViewById(R.id.name); + numberTextView = itemView.findViewById(R.id.number); + plusButton = itemView.findViewById(R.id.plusButton); + minusButton = itemView.findViewById(R.id.minusButton); + } + + public void bind(Item item) { + nameTextView.setText(item.name); + numberTextView.setText(String.valueOf(item.getValue())); + // Обработка событий кнопок + plusButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + item.incValue(); + UpdateText(item); + } + }); + + minusButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + item.decValue(); + UpdateText(item); + } + }); + } +} 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_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..1e4ba92 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,32 @@ + + + + + +