From 6e23ddd935b55f8f52e1db6af6fffaa5e8c73ea9 Mon Sep 17 00:00:00 2001 From: glasolin Date: Tue, 7 Nov 2023 18:39:44 +0300 Subject: [PATCH 1/3] - added ActivityA --- app/build.gradle | 30 +++++++++++- app/src/main/AndroidManifest.xml | 17 +++++-- .../otus/gpb/homework/activities/ActivityA.kt | 46 +++++++++++++++++++ app/src/main/res/values/strings.xml | 1 + build.gradle | 6 +-- gradle.properties | 6 ++- gradle/wrapper/gradle-wrapper.properties | 2 +- 7 files changed, 97 insertions(+), 11 deletions(-) create mode 100644 app/src/main/java/otus/gpb/homework/activities/ActivityA.kt diff --git a/app/build.gradle b/app/build.gradle index 3c3711b..b4d4629 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -5,16 +5,19 @@ plugins { } android { - compileSdk 32 + compileSdk 34 defaultConfig { applicationId "otus.gpb.homework.activities" minSdk 23 - targetSdk 32 + targetSdk 34 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + vectorDrawables { + useSupportLibrary true + } } buildTypes { @@ -30,6 +33,18 @@ android { kotlinOptions { jvmTarget = '1.8' } + buildFeatures { + compose true + } + composeOptions { + kotlinCompilerExtensionVersion '1.4.8' + } + packagingOptions { + resources { + excludes += '/META-INF/{AL2.0,LGPL2.1}' + } + } + namespace 'otus.gpb.homework.activities' } detekt { @@ -52,4 +67,15 @@ dependencies { implementation 'androidx.core:core-ktx:1.8.0' implementation 'androidx.appcompat:appcompat:1.5.0' implementation 'com.google.android.material:material:1.6.1' + implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1' + implementation 'androidx.activity:activity-compose:1.7.0' + implementation platform('androidx.compose:compose-bom:2023.03.00') + implementation 'androidx.compose.ui:ui' + implementation 'androidx.compose.ui:ui-graphics' + implementation 'androidx.compose.ui:ui-tooling-preview' + implementation 'androidx.compose.material3:material3' + androidTestImplementation platform('androidx.compose:compose-bom:2023.03.00') + androidTestImplementation 'androidx.compose.ui:ui-test-junit4' + debugImplementation 'androidx.compose.ui:ui-tooling' + debugImplementation 'androidx.compose.ui:ui-test-manifest' } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f318e6c..e60e570 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,7 +1,6 @@ + xmlns:tools="http://schemas.android.com/tools"> + tools:targetApi="31"> + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/otus/gpb/homework/activities/ActivityA.kt b/app/src/main/java/otus/gpb/homework/activities/ActivityA.kt new file mode 100644 index 0000000..4ba06d1 --- /dev/null +++ b/app/src/main/java/otus/gpb/homework/activities/ActivityA.kt @@ -0,0 +1,46 @@ +package otus.gpb.homework.activities + +import android.os.Bundle +import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Surface +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.tooling.preview.Preview +import otus.gpb.homework.activities.ui.theme.ActivitiesTheme + +class ActivityA : ComponentActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContent { + ActivitiesTheme { + // A surface container using the 'background' color from the theme + Surface( + modifier = Modifier.fillMaxSize(), + color = MaterialTheme.colorScheme.background + ) { + Greeting("Android") + } + } + } + } +} + +@Composable +fun Greeting(name: String, modifier: Modifier = Modifier) { + Text( + text = "Hello $name!", + modifier = modifier + ) +} + +@Preview(showBackground = true) +@Composable +fun GreetingPreview() { + ActivitiesTheme { + Greeting("Android") + } +} \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 08ea3c6..07b6b16 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,3 +1,4 @@ Activities + ActivityA \ No newline at end of file diff --git a/build.gradle b/build.gradle index 07c0e9a..018ca3b 100644 --- a/build.gradle +++ b/build.gradle @@ -1,8 +1,8 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { - id 'com.android.application' version '7.2.0' apply false - id 'com.android.library' version '7.2.0' apply false - id 'org.jetbrains.kotlin.android' version '1.6.21' apply false + id 'com.android.application' version '8.1.2' apply false + id 'com.android.library' version '8.1.2' apply false + id 'org.jetbrains.kotlin.android' version '1.8.22' apply false id "io.gitlab.arturbosch.detekt" version "1.21.0" } diff --git a/gradle.properties b/gradle.properties index cd0519b..0b84a9b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ # http://www.gradle.org/docs/current/userguide/build_environment.html # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. -org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 +org.gradle.jvmargs=-Xmx4096m -Dfile.encoding=UTF-8 # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects @@ -20,4 +20,6 @@ kotlin.code.style=official # Enables namespacing of each library's R class so that its R class includes only the # resources declared in the library itself and none from the library's dependencies, # thereby reducing the size of the R class for that library -android.nonTransitiveRClass=true \ No newline at end of file +android.nonTransitiveRClass=true +android.defaults.buildfeatures.buildconfig=true +android.nonFinalResIds=false \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a577dba..fcb8cae 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Sat Aug 27 13:57:30 MSK 2022 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME From c9d459286dfa82721b4b52f5ed1fea386efb051b Mon Sep 17 00:00:00 2001 From: glasolin Date: Tue, 14 Nov 2023 20:18:27 +0300 Subject: [PATCH 2/3] - added ActivityB --- .../otus/gpb/homework/activities/ActivityA.kt | 35 +++++-------------- .../otus/gpb/homework/activities/ActivityB.kt | 21 +++++++++++ app/src/main/res/layout/activity_a.xml | 24 +++++++++++++ app/src/main/res/layout/activity_b.xml | 24 +++++++++++++ app/src/main/res/values/colors.xml | 4 +++ app/src/main/res/values/strings.xml | 6 ++++ build.gradle | 4 +-- 7 files changed, 90 insertions(+), 28 deletions(-) create mode 100644 app/src/main/java/otus/gpb/homework/activities/ActivityB.kt create mode 100644 app/src/main/res/layout/activity_a.xml create mode 100644 app/src/main/res/layout/activity_b.xml diff --git a/app/src/main/java/otus/gpb/homework/activities/ActivityA.kt b/app/src/main/java/otus/gpb/homework/activities/ActivityA.kt index 4ba06d1..26b5218 100644 --- a/app/src/main/java/otus/gpb/homework/activities/ActivityA.kt +++ b/app/src/main/java/otus/gpb/homework/activities/ActivityA.kt @@ -12,35 +12,18 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Preview import otus.gpb.homework.activities.ui.theme.ActivitiesTheme -class ActivityA : ComponentActivity() { +class ActivityA : ComponentActivity(R.layout.activity_a) { + lateinit var button:Button override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContent { - ActivitiesTheme { - // A surface container using the 'background' color from the theme - Surface( - modifier = Modifier.fillMaxSize(), - color = MaterialTheme.colorScheme.background - ) { - Greeting("Android") - } - } - } + val id=(applicationContext as App).id + button=findViewById(R.id.openb) } -} -@Composable -fun Greeting(name: String, modifier: Modifier = Modifier) { - Text( - text = "Hello $name!", - modifier = modifier - ) -} + override fun onStart() { + super.onStart() + button.onClickListener { -@Preview(showBackground = true) -@Composable -fun GreetingPreview() { - ActivitiesTheme { - Greeting("Android") + } } -} \ No newline at end of file +} diff --git a/app/src/main/java/otus/gpb/homework/activities/ActivityB.kt b/app/src/main/java/otus/gpb/homework/activities/ActivityB.kt new file mode 100644 index 0000000..68a3c25 --- /dev/null +++ b/app/src/main/java/otus/gpb/homework/activities/ActivityB.kt @@ -0,0 +1,21 @@ +package otus.gpb.homework.activities + +import android.os.Bundle +import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Surface +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.tooling.preview.Preview +import otus.gpb.homework.activities.ui.theme.ActivitiesTheme + +class ActivityB : ComponentActivity(R.layout.activity_b) { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + } + + +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_a.xml b/app/src/main/res/layout/activity_a.xml new file mode 100644 index 0000000..06d0243 --- /dev/null +++ b/app/src/main/res/layout/activity_a.xml @@ -0,0 +1,24 @@ + + + +