From b3c152c02463b761bf4845c17e7099e2af6b5c23 Mon Sep 17 00:00:00 2001 From: KaushalVasava Date: Tue, 25 Jul 2023 14:44:08 +0530 Subject: [PATCH 1/2] Update dependencies --- app/build.gradle | 24 ++++++++++++------------ build.gradle | 8 ++++---- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 75677b5..c35e5f3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -5,12 +5,12 @@ plugins { android { namespace 'com.lahsuak.apps.jetpackcomposebasic' - compileSdk 33 + compileSdk 34 defaultConfig { applicationId "com.lahsuak.apps.jetpackcomposebasic" minSdk 23 - targetSdk 33 + targetSdk 34 versionCode 1 versionName "1.0" @@ -27,17 +27,17 @@ android { } } compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = '1.8' + jvmTarget = '17' } buildFeatures { compose true } composeOptions { - kotlinCompilerExtensionVersion '1.1.1' + kotlinCompilerExtensionVersion '1.4.3' } packagingOptions { resources { @@ -48,15 +48,15 @@ android { dependencies { - implementation 'androidx.core:core-ktx:1.9.0' - implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1' - implementation 'androidx.activity:activity-compose:1.6.1' + implementation 'androidx.core:core-ktx:1.10.1' + implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1' + implementation 'androidx.activity:activity-compose:1.7.2' implementation "androidx.compose.ui:ui:$compose_version" implementation "androidx.compose.ui:ui-tooling-preview:$compose_version" - implementation 'androidx.compose.material3:material3:1.1.0-alpha03' + implementation 'androidx.compose.material3:material3:1.2.0-alpha03' testImplementation 'junit:junit:4.13.2' - androidTestImplementation 'androidx.test.ext:junit:1.1.4' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0' + androidTestImplementation 'androidx.test.ext:junit:1.1.5' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version" debugImplementation "androidx.compose.ui:ui-tooling:$compose_version" debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version" diff --git a/build.gradle b/build.gradle index e868fc8..b0f2f02 100644 --- a/build.gradle +++ b/build.gradle @@ -1,10 +1,10 @@ buildscript { ext { - compose_version = '1.3.2' + compose_version = '1.4.3' } }// Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { - id 'com.android.application' version '7.3.0' apply false - id 'com.android.library' version '7.3.0' apply false - id 'org.jetbrains.kotlin.android' version '1.6.10' apply false + id 'com.android.application' version '8.0.2' apply false + id 'com.android.library' version '8.0.2' apply false + id 'org.jetbrains.kotlin.android' version '1.8.10' apply false } \ No newline at end of file From fc4c99bdc66626e918a45c10ce061fc03b1bc04a Mon Sep 17 00:00:00 2001 From: KaushalVasava Date: Tue, 25 Jul 2023 15:48:28 +0530 Subject: [PATCH 2/2] Add constraintLayout to build Indian Flag --- app/build.gradle | 2 + .../apps/jetpackcomposebasic/MainActivity.kt | 77 +++++++++++++++---- 2 files changed, 66 insertions(+), 13 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index c35e5f3..5963dac 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -60,4 +60,6 @@ dependencies { androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version" debugImplementation "androidx.compose.ui:ui-tooling:$compose_version" debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version" + + implementation "androidx.constraintlayout:constraintlayout-compose:1.0.1" } \ No newline at end of file diff --git a/app/src/main/java/com/lahsuak/apps/jetpackcomposebasic/MainActivity.kt b/app/src/main/java/com/lahsuak/apps/jetpackcomposebasic/MainActivity.kt index 187ee32..334b460 100644 --- a/app/src/main/java/com/lahsuak/apps/jetpackcomposebasic/MainActivity.kt +++ b/app/src/main/java/com/lahsuak/apps/jetpackcomposebasic/MainActivity.kt @@ -3,13 +3,23 @@ package com.lahsuak.apps.jetpackcomposebasic import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.shape.CircleShape 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.draw.clip +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.layout.layoutId import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import androidx.constraintlayout.compose.ChainStyle +import androidx.constraintlayout.compose.ConstraintLayout +import androidx.constraintlayout.compose.ConstraintSet +import androidx.constraintlayout.compose.Dimension import com.lahsuak.apps.jetpackcomposebasic.ui.theme.JetPackComposeBasicTheme class MainActivity : ComponentActivity() { @@ -22,29 +32,70 @@ class MainActivity : ComponentActivity() { modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background ) { - Greeting("Android") + IndianFlagScreen() } } } } } -/*** -Composable functions : -A composable function is a regular function annotated with @Composable. -This enables your function to call other @Composable functions within it. -You can see how the Greeting function is marked as @Composable. -This function will produce a piece of UI hierarchy displaying the given input, -String. Text is a composable function provided by the library. -***/ + @Composable -fun Greeting(name: String) { - Text(text = "Hello $name!") +fun IndianFlagScreen() { + val constraints = ConstraintSet { + val orangeBox = createRefFor("orangebox") + val greenBox = createRefFor("greenbox") + val circle = createRefFor("circle") + + constrain(orangeBox) { + top.linkTo(parent.top) + start.linkTo(parent.start) + end.linkTo(parent.end) + bottom.linkTo(circle.top) + width = Dimension.fillToConstraints + height = Dimension.value(260.dp) + } + constrain(circle) { + top.linkTo(parent.top) + bottom.linkTo(parent.bottom) + start.linkTo(parent.start) + end.linkTo(parent.end) + width = Dimension.value(100.dp) + height = Dimension.value(100.dp) + } + constrain(greenBox) { + top.linkTo(circle.bottom) + bottom.linkTo(parent.bottom) + start.linkTo(parent.start) + end.linkTo(parent.end) + width = Dimension.fillToConstraints + height = Dimension.value(260.dp) + } + createVerticalChain(orangeBox, circle, greenBox, chainStyle = ChainStyle.SpreadInside) + } + ConstraintLayout(constraints, modifier = Modifier.background(Color.White).fillMaxSize()) { + Box( + modifier = Modifier + .background(Color(0xFFFB8C00)) + .layoutId("orangebox") + ) + Box( + modifier = Modifier + .clip(CircleShape) + .background(Color.Blue) + .layoutId("circle") + ) + Box( + modifier = Modifier + .background(Color(0xFF2EB734)) + .layoutId("greenbox") + ) + } } @Preview(showBackground = true) @Composable fun DefaultPreview() { JetPackComposeBasicTheme { - Greeting("Android") + IndianFlagScreen() } } \ No newline at end of file