From d2d82b12526e912688bde8582e98b31f82e43b3d Mon Sep 17 00:00:00 2001 From: Mohammad Sadman Sharar Sayem Date: Thu, 15 Jan 2026 19:43:43 -0700 Subject: [PATCH] lab 2 city code --- code/.gitignore | 15 ++ code/.idea/.name | 1 + code/.idea/AndroidProjectSystem.xml | 6 + code/.idea/compiler.xml | 6 + code/.idea/deploymentTargetSelector.xml | 10 + code/.idea/gradle.xml | 18 ++ code/.idea/migrations.xml | 10 + code/.idea/misc.xml | 10 + code/.idea/runConfigurations.xml | 17 ++ code/.idea/vcs.xml | 6 + code/app/.gitignore | 1 + code/app/build.gradle.kts | 44 +++ code/app/proguard-rules.pro | 21 ++ .../listycity/ExampleInstrumentedTest.java | 26 ++ code/app/src/main/AndroidManifest.xml | 25 ++ .../com/example/listycity/MainActivity.java | 94 +++++++ .../res/drawable/ic_launcher_background.xml | 170 ++++++++++++ .../res/drawable/ic_launcher_foreground.xml | 30 +++ .../app/src/main/res/layout/activity_main.xml | 68 +++++ code/app/src/main/res/layout/content.xml | 11 + .../res/mipmap-anydpi-v26/ic_launcher.xml | 6 + .../mipmap-anydpi-v26/ic_launcher_round.xml | 6 + .../src/main/res/mipmap-hdpi/ic_launcher.webp | Bin 0 -> 1404 bytes .../res/mipmap-hdpi/ic_launcher_round.webp | Bin 0 -> 2898 bytes .../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 code/app/src/main/res/values-night/themes.xml | 7 + code/app/src/main/res/values/colors.xml | 9 + code/app/src/main/res/values/strings.xml | 3 + code/app/src/main/res/values/themes.xml | 17 ++ code/app/src/main/res/xml/backup_rules.xml | 13 + .../main/res/xml/data_extraction_rules.xml | 19 ++ .../example/listycity/ExampleUnitTest.java | 17 ++ code/build.gradle.kts | 4 + code/gradle.properties | 21 ++ code/gradle/libs.versions.toml | 22 ++ code/gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 45457 bytes code/gradle/wrapper/gradle-wrapper.properties | 8 + code/gradlew | 251 ++++++++++++++++++ code/gradlew.bat | 94 +++++++ code/settings.gradle.kts | 24 ++ 47 files changed, 1110 insertions(+) create mode 100644 code/.gitignore create mode 100644 code/.idea/.name create mode 100644 code/.idea/AndroidProjectSystem.xml create mode 100644 code/.idea/compiler.xml create mode 100644 code/.idea/deploymentTargetSelector.xml create mode 100644 code/.idea/gradle.xml create mode 100644 code/.idea/migrations.xml create mode 100644 code/.idea/misc.xml create mode 100644 code/.idea/runConfigurations.xml create mode 100644 code/.idea/vcs.xml create mode 100644 code/app/.gitignore create mode 100644 code/app/build.gradle.kts create mode 100644 code/app/proguard-rules.pro create mode 100644 code/app/src/androidTest/java/com/example/listycity/ExampleInstrumentedTest.java create mode 100644 code/app/src/main/AndroidManifest.xml create mode 100644 code/app/src/main/java/com/example/listycity/MainActivity.java create mode 100644 code/app/src/main/res/drawable/ic_launcher_background.xml create mode 100644 code/app/src/main/res/drawable/ic_launcher_foreground.xml create mode 100644 code/app/src/main/res/layout/activity_main.xml create mode 100644 code/app/src/main/res/layout/content.xml create mode 100644 code/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml create mode 100644 code/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml create mode 100644 code/app/src/main/res/mipmap-hdpi/ic_launcher.webp create mode 100644 code/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp create mode 100644 code/app/src/main/res/mipmap-mdpi/ic_launcher.webp create mode 100644 code/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp create mode 100644 code/app/src/main/res/mipmap-xhdpi/ic_launcher.webp create mode 100644 code/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp create mode 100644 code/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp create mode 100644 code/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp create mode 100644 code/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp create mode 100644 code/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp create mode 100644 code/app/src/main/res/values-night/themes.xml create mode 100644 code/app/src/main/res/values/colors.xml create mode 100644 code/app/src/main/res/values/strings.xml create mode 100644 code/app/src/main/res/values/themes.xml create mode 100644 code/app/src/main/res/xml/backup_rules.xml create mode 100644 code/app/src/main/res/xml/data_extraction_rules.xml create mode 100644 code/app/src/test/java/com/example/listycity/ExampleUnitTest.java create mode 100644 code/build.gradle.kts create mode 100644 code/gradle.properties create mode 100644 code/gradle/libs.versions.toml create mode 100644 code/gradle/wrapper/gradle-wrapper.jar create mode 100644 code/gradle/wrapper/gradle-wrapper.properties create mode 100755 code/gradlew create mode 100644 code/gradlew.bat create mode 100644 code/settings.gradle.kts diff --git a/code/.gitignore b/code/.gitignore new file mode 100644 index 00000000..aa724b77 --- /dev/null +++ b/code/.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/code/.idea/.name b/code/.idea/.name new file mode 100644 index 00000000..cb67bab4 --- /dev/null +++ b/code/.idea/.name @@ -0,0 +1 @@ +ListyCity \ No newline at end of file diff --git a/code/.idea/AndroidProjectSystem.xml b/code/.idea/AndroidProjectSystem.xml new file mode 100644 index 00000000..4a53bee8 --- /dev/null +++ b/code/.idea/AndroidProjectSystem.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/code/.idea/compiler.xml b/code/.idea/compiler.xml new file mode 100644 index 00000000..b86273d9 --- /dev/null +++ b/code/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/code/.idea/deploymentTargetSelector.xml b/code/.idea/deploymentTargetSelector.xml new file mode 100644 index 00000000..b268ef36 --- /dev/null +++ b/code/.idea/deploymentTargetSelector.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/code/.idea/gradle.xml b/code/.idea/gradle.xml new file mode 100644 index 00000000..97f0a8e1 --- /dev/null +++ b/code/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/code/.idea/migrations.xml b/code/.idea/migrations.xml new file mode 100644 index 00000000..f8051a6f --- /dev/null +++ b/code/.idea/migrations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/code/.idea/misc.xml b/code/.idea/misc.xml new file mode 100644 index 00000000..74dd639e --- /dev/null +++ b/code/.idea/misc.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/code/.idea/runConfigurations.xml b/code/.idea/runConfigurations.xml new file mode 100644 index 00000000..16660f1d --- /dev/null +++ b/code/.idea/runConfigurations.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/code/.idea/vcs.xml b/code/.idea/vcs.xml new file mode 100644 index 00000000..6c0b8635 --- /dev/null +++ b/code/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/code/app/.gitignore b/code/app/.gitignore new file mode 100644 index 00000000..42afabfd --- /dev/null +++ b/code/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/code/app/build.gradle.kts b/code/app/build.gradle.kts new file mode 100644 index 00000000..4acd1dfc --- /dev/null +++ b/code/app/build.gradle.kts @@ -0,0 +1,44 @@ +plugins { + alias(libs.plugins.android.application) +} + +android { + namespace = "com.example.listycity" + compileSdk { + version = release(36) + } + + defaultConfig { + applicationId = "com.example.listycity" + minSdk = 24 + 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/code/app/proguard-rules.pro b/code/app/proguard-rules.pro new file mode 100644 index 00000000..481bb434 --- /dev/null +++ b/code/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/code/app/src/androidTest/java/com/example/listycity/ExampleInstrumentedTest.java b/code/app/src/androidTest/java/com/example/listycity/ExampleInstrumentedTest.java new file mode 100644 index 00000000..7b7c2106 --- /dev/null +++ b/code/app/src/androidTest/java/com/example/listycity/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.listycity; + +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.listycity", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/code/app/src/main/AndroidManifest.xml b/code/app/src/main/AndroidManifest.xml new file mode 100644 index 00000000..7c439aa7 --- /dev/null +++ b/code/app/src/main/AndroidManifest.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/code/app/src/main/java/com/example/listycity/MainActivity.java b/code/app/src/main/java/com/example/listycity/MainActivity.java new file mode 100644 index 00000000..84eb86e7 --- /dev/null +++ b/code/app/src/main/java/com/example/listycity/MainActivity.java @@ -0,0 +1,94 @@ +package com.example.listycity; + +import android.os.Bundle; +import android.view.View; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.EditText; +import android.widget.ListView; + +import androidx.activity.EdgeToEdge; +import androidx.appcompat.app.AppCompatActivity; + +import java.util.ArrayList; +import java.util.Arrays; +import androidx.appcompat.widget.Toolbar; + +public class MainActivity extends AppCompatActivity { + + ListView cityList; + ArrayAdapter cityAdapter; + ArrayList datalist; + + Button addCityButton, deleteCityButton, confirmAddButton; + EditText cityInput; + + boolean deleteMode = false; // STATE FLAG + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + EdgeToEdge.enable(this); + setContentView(R.layout.activity_main); + Toolbar toolbar = findViewById(R.id.top_bar); + setSupportActionBar(toolbar); + + + cityList = findViewById(R.id.city_list); + addCityButton = findViewById(R.id.add_city_button); + deleteCityButton = findViewById(R.id.delete_city_button); + confirmAddButton = findViewById(R.id.confirm_add_button); + cityInput = findViewById(R.id.city_input); + + String[] cities = { + "Edmonton", "Vancouver", "Moscow", "Sydney", + "Berlin", "Vienna", "Tokyo", "Beijing", + "Osaka", "New Delhi" + }; + + datalist = new ArrayList<>(Arrays.asList(cities)); + + cityAdapter = new ArrayAdapter<>( + this, + R.layout.content, + datalist + ); + + cityList.setAdapter(cityAdapter); + + // ADD CITY BUTTON + addCityButton.setOnClickListener(v -> { + deleteMode = false; + cityInput.setVisibility(View.VISIBLE); + confirmAddButton.setVisibility(View.VISIBLE); + }); + + // CONFIRM ADD + confirmAddButton.setOnClickListener(v -> { + String city = cityInput.getText().toString().trim(); + + if (!city.isEmpty()) { + datalist.add(city); + cityAdapter.notifyDataSetChanged(); + cityInput.setText(""); + } + + cityInput.setVisibility(View.GONE); + confirmAddButton.setVisibility(View.GONE); + }); + + // DELETE MODE BUTTON + deleteCityButton.setOnClickListener(v -> { + deleteMode = true; + }); + + // LIST ITEM CLICK + cityList.setOnItemClickListener((parent, view, position, id) -> { + if (deleteMode) { + datalist.remove(position); + cityAdapter.notifyDataSetChanged(); + deleteMode = false; // exit delete mode after one delete + } + }); + } +} \ No newline at end of file diff --git a/code/app/src/main/res/drawable/ic_launcher_background.xml b/code/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 00000000..07d5da9c --- /dev/null +++ b/code/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/code/app/src/main/res/drawable/ic_launcher_foreground.xml b/code/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 00000000..2b068d11 --- /dev/null +++ b/code/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/code/app/src/main/res/layout/activity_main.xml b/code/app/src/main/res/layout/activity_main.xml new file mode 100644 index 00000000..bd88a7bd --- /dev/null +++ b/code/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,68 @@ + + + + + + + +