Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Week1 과제 #4

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
Open
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,39 @@ package com.example.composearticle
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign.Companion.Justify
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent { }
setContent {
ComposeArticleApp()
}
}
}

@Preview(showBackground = true)
@Composable
fun ComposeArticleApp() {
ArticleCard(
title = stringResource(R.string.main_title),
shortDescription = stringResource(R.string.main_short_description),
longDescription = stringResource(R.string.main_long_description),
imagePainter = painterResource(id = R.drawable.bg_compose_background),
)
}

@Composable
Expand All @@ -28,10 +46,29 @@ private fun ArticleCard(
imagePainter: Painter,
modifier: Modifier = Modifier,
) {
Column() { }
}

@Preview(showBackground = true)
@Composable
fun DefaultPreview() {
Column(modifier = modifier) {
Image(
painter = imagePainter,
contentDescription = null,
modifier = Modifier.fillMaxWidth(),
)
Text(
text = title,
fontSize = 24.sp,
modifier = Modifier
.padding(16.dp),
)
Text(
text = shortDescription,
textAlign = Justify,
modifier = Modifier
.padding(horizontal = 16.dp),
)
Text(
text = longDescription,
textAlign = Justify,
modifier = Modifier
.padding(16.dp),
)
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@
<string name="title_jetpack_compose_tutorial">Jetpack Compose tutorial</string>
<string name="compose_short_desc">Jetpack Compose is a modern toolkit for building native Android UI. Compose simplifies and accelerates UI development on Android with less code, powerful tools, and intuitive Kotlin APIs.</string>
<string name="compose_long_desc">In this tutorial, you build a simple UI component with declarative functions. You call Compose functions to say what elements you want and the Compose compiler does the rest. Compose is built around Composable functions. These functions let you define your app\'s UI programmatically because they let you describe how it should look and provide data dependencies, rather than focus on the process of the UI\'s construction, such as initializing an element and then attaching it to a parent. To create a Composable function, you add the @Composable annotation to the function name.</string>

<!-- main -->
<string name="main_title">Jetpack Compose Tutorial</string>
<string name="main_short_description">Jetpack Compose is a modern toolkit for building native Android UI. Compose simplifies and accelerates UI development on Android with less code, powerful tools, and intuitive Kotlin APIs.</string>
<string name="main_long_description">In this tutorial, you build a simple UI component with declarative functions. You call Compose functions to say what elements you want and the Compose compiler does the rest. Compose is built around Composable functions. These functions let you define your app\'s UI programmatically because they let you describe how it should look and provide data dependencies, rather than focus on the process of the UI\'s construction, such as initializing an element and then attaching it to a parent. To create a Composable function, you add the @Composable annotation to the function name.</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.foundation.layout.* // ktlint-disable no-wildcard-imports
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
Expand All @@ -17,20 +15,51 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.example.composequadrant.ui.theme.ComposeQuadrantTheme

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent { }
setContent {
ComposeQuadrantApp()
}
}
}

@Preview(showBackground = true)
@Composable
fun ComposeQuadrantApp() {
Column() {
Row() { }
Row() { }
fun ComposeQuadrantApp(modifier: Modifier = Modifier) {
Column(
modifier = modifier
.fillMaxSize(),
) {
Row(Modifier.weight(1f)) {
ComposableInfoCard(
title = stringResource(R.string.main_text_composable_title),
description = stringResource(R.string.main_text_composable_description),
backgroundColor = Color.Green,
modifier = Modifier.weight(1f),
)
ComposableInfoCard(
title = stringResource(R.string.main_image_composable_title),
description = stringResource(R.string.main_image_composable_description),
backgroundColor = Color.Yellow,
modifier = Modifier.weight(1f),
)
}
Row(Modifier.weight(1f)) {
ComposableInfoCard(
title = stringResource(R.string.main_row_composable_title),
description = stringResource(R.string.main_row_composable_description),
backgroundColor = Color.Cyan,
modifier = Modifier.weight(1f),
)
ComposableInfoCard(
title = stringResource(R.string.main_column_composable_title),
description = stringResource(R.string.main_column_composable_description),
backgroundColor = Color.LightGray,
modifier = Modifier.weight(1f),
)
}
}
}

Expand All @@ -39,12 +68,25 @@ private fun ComposableInfoCard(
title: String,
description: String,
backgroundColor: Color,
modifier: Modifier = Modifier
modifier: Modifier = Modifier,
) {
Column( ) { }
Column(
modifier = modifier
.background(backgroundColor)
.padding(16.dp)
.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
) {
Text(
text = title,
fontWeight = FontWeight.Bold,
modifier = Modifier
.padding(bottom = 16.dp),
)
Text(
text = description,
textAlign = TextAlign.Justify,
)
}
}


@Preview(showBackground = true)
@Composable
fun DefaultPreview() { }
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,12 @@
<string name="third_description">A layout composable that places its children in a horizontal sequence.</string>
<string name="fourth_title">Column composable</string>
<string name="fourth_description">A layout composable that places its children in a vertical sequence.</string>
<string name="main_text_composable_title">Text Composable</string>
<string name="main_text_composable_description">Displays text and follows Material Design guidelines.</string>
<string name="main_image_composable_title">Image Composable</string>
<string name="main_image_composable_description">Creates a composable that lays out and draws a given Painter class object.</string>
<string name="main_row_composable_title">Row Composable</string>
<string name="main_row_composable_description">A layout composable that places its children in a horizontal sequence.</string>
<string name="main_column_composable_title">Column Composable</string>
<string name="main_column_composable_description">A layout composable that places its children in a vertical sequence.</string>
</resources>
15 changes: 15 additions & 0 deletions week1/challenge/Lemonade/.gitignore
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions week1/challenge/Lemonade/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
63 changes: 63 additions & 0 deletions week1/challenge/Lemonade/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}

android {
namespace 'com.example.lemonade'
compileSdk 33

defaultConfig {
applicationId "com.example.lemonade"
minSdk 24
targetSdk 33
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion '1.2.0'
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}

dependencies {

implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.3.1'
implementation "androidx.compose.ui:ui:$compose_ui_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_ui_version"
implementation 'androidx.compose.material:material:1.2.0'
testImplementation 'junit:junit:4.13.2'
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_ui_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_ui_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_ui_version"
}
21 changes: 21 additions & 0 deletions week1/challenge/Lemonade/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example.lemonade

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.example.lemonade", appContext.packageName)
}
}
27 changes: 27 additions & 0 deletions week1/challenge/Lemonade/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.Lemonade"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.Lemonade">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Loading