Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions 7weeks/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# OS files
.DS_Store

# Built application files
*.apk
*.ap_
*.aab

# Files for the ART/Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/
out/
release/

# Gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log

# Android Studio Navigation editor temp files
.navigation/

# Android Studio captures folder
captures/

# IntelliJ
*.iml
.idea

# Keystore files
# Uncomment the following lines if you do not want to check your keystore files in.
#*.jks
#*.keystore

# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild

# Google Services (e.g. APIs or Firebase)
# google-services.json

# Freeline
freeline.py
freeline/
freeline_project_description.json

# fastlane
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
fastlane/readme.md

# Version control
vcs.xml

# lint
lint/intermediates/
lint/generated/
lint/outputs/
lint/tmp/
# lint/reports/
157 changes: 157 additions & 0 deletions 7weeks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
## ViewGroup

- Android의 모든 위젯은 View를 상속하여 구현하고 있다.

![View hierarchy](https://o7planning.org/en/10423/cache/images/i/1189616.png)

### 주요 ViewGroup 종류와 사용법

#### LinearLayout

- 명칭에서 알 수 있듯이 선형 모양의 레이아웃
- `orientation` 이라는 필수 속성이 필요하며 지정하지 않을 경우 `horizontal` 이 기본

```xml
<LinearLayout
android:layout_width="match_parent|wrap_content"
android:layout_height="match_parent|wrap_content"
android:orientation="vertical|horizontal">
<!-- other code -->
</LinearLayout>
```

#### RelativeLayout

- 부모 또는 특정 View를 기준으로 특정 View의 상대 위치를 지정할 수 있는 레이아웃

```xml
<RelativeLayout
android:layout_width="match_parent|wrap_content"
android:layout_height="match_parent|wrap_content">

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/textView1" />
<!-- other code -->
</RelativeLayout>
```

#### FrameLayout

- 하나의 View 위젯을 표현하기 위한 레이아웃
- 단, 레이아웃 하위에 여러 View 위젯을 추가할 순 있다.

```xml
<FrameLayout
android:layout_width="match_parent|wrap_content"
android:layout_height="match_parent|wrap_content">

<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/abc" />
<!-- other code -->
</FrameLayout>
```

#### ConstraintLayout

- 뷰와 뷰 사이에 제약조건을 설정하여 위젯을 배치하기 위한 레이아웃
- 속성이 엄청나게 많습니다. ~~(알아서 찾아보세요...)~~

```xml
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent|wrap_content"
android:layout_height="match_parent|wrap_content">

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<!-- other code -->
</androidx.constraintlayout.widget.ConstraintLayout>
```

### 주요 Widget 종류와 사용법

#### RecyclerView

- 기존의 ListView의 단점과 성능을 개선하여 제공되는 위젯
- ViewHolder 패턴을 강제하여 아이템 View의 재사용성을 적극 활용한다.

```xml
<RecyclerView
android:id="@+id/exampleList"
android:layout_width="match_parent|wrap_content"
android:layout_height="match_parent|wrap_content" />
```

```kotlin
fun setupRecyclerView() {
ExampleAdapter adapter = new ExampleAdapter()
LinearLayoutManager layoutManager = new LayoutManager(this)
with(exampleList) {
this.layoutManager = layoutManager
this.adapter = adpater
}
}
```

```kotlin
class ExampleAdapter : RecyclerView.Adapter<ExampleHolder>() {
private var dataSet = mutableListOf<String>()

fun addItems(items: List<String>) {
dataSet.addAll(items)
notifyDataSetChanged()
}

fun updateItems(items: List<String>) {
dataSet = items as MutableList<String>
notifyDataSetChanged()
}

class ExampleHolder(val containerView: View) : RecyclerView.ViewHolder(view) {
// other code
}


abstract class LayoutContainerViewHolder(override val containerView: View) : RecyclerView.ViewHolder(containerView)

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ExampleHolder {
return ExampleHolder(
LayoutInflater.from(parent.context).inflate(R.layout.item_example, parent, false)
)
}

override fun onBindViewHolder(holder: ExampleHolder, position: Int) {
// otehr code...
}

override fun getItemCount(): Int = dataSet.size
}
```

#### ViewPager

- 스와이프 액션을 통해 화면을 이동하기 위한 위젯
- ~~샘플 코드 귀찮아요...~~

```xml
<android.support.v4.view.ViewPager
android:id="@+id/examplePager"
android:layout_width="match_parent|wrap_content"
android:layout_height="match_parent|wrap_content" />
```

1 change: 1 addition & 0 deletions 7weeks/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
45 changes: 45 additions & 0 deletions 7weeks/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 28
buildToolsVersion "29.0.0"
defaultConfig {
applicationId "io.cro.example"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

implementation 'com.squareup.retrofit2:retrofit:2.6.1'
implementation 'com.squareup.retrofit2:converter-gson:2.6.1'

implementation 'com.google.code.gson:gson:2.8.5'

implementation 'com.jakewharton.timber:timber:4.7.1'

testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
21 changes: 21 additions & 0 deletions 7weeks/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 io.cro.example

import androidx.test.InstrumentationRegistry
import androidx.test.runner.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.getTargetContext()
assertEquals("io.cro.example", appContext.packageName)
}
}
27 changes: 27 additions & 0 deletions 7weeks/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"
package="io.cro.example">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".ExampleApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:networkSecurityConfig="@xml/network_security_config"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".RetrofitActivity"></activity>
<activity android:name=".LegacyActivity" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

</manifest>
11 changes: 11 additions & 0 deletions 7weeks/app/src/main/java/io/cro/example/ExampleApplication.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.cro.example

import android.app.Application
import timber.log.Timber

class ExampleApplication : Application() {
override fun onCreate() {
super.onCreate()
Timber.plant(Timber.DebugTree())
}
}
Loading