Skip to content

Commit

Permalink
#4 WindowInset Keyboard Sample Screen
Browse files Browse the repository at this point in the history
  • Loading branch information
lee-ji-hoon committed Sep 10, 2024
1 parent c494948 commit 75453c9
Show file tree
Hide file tree
Showing 14 changed files with 209 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ android {
dependencies {
implementation(project(":feature:window"))
implementation(project(":feature:compose-layout"))
implementation(project(":feature:inset-animation"))
implementation(project(":base"))

implementation(libs.androidx.compose.activity)
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
android:name="com.sample.feature.window.WindowSampleActivity"
android:exported="true">
</activity>

<activity
android:name="com.sample.feature.inset_animation.InsetAnimationSampleActivity"
android:exported="true">
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.sample.feature.compose_layout.LayoutSampleModifyColumn
import com.sample.feature.compose_layout.LayoutSampleModifyGrid
import com.sample.feature.compose_layout.LayoutSampleModifyRow
import com.sample.feature.compose_layout.LayoutSampleScreen
import com.sample.feature.inset_animation.InsetAnimationSampleActivity
import com.sample.feature.window.WindowSampleActivity

@Composable
Expand Down Expand Up @@ -47,6 +48,15 @@ fun PlaygroundNavigation() {
}
}

composable(route = PlaygroundNavigation.InsetAnimation.route) {
Box(modifier = Modifier.fillMaxSize()) {
LaunchedEffect(Unit) {
val intent = Intent(context, InsetAnimationSampleActivity::class.java)
startWindowActivity.launch(intent)
}
}
}

layoutSampleGraph(navController::navigate)
}
}
Expand Down Expand Up @@ -90,6 +100,10 @@ sealed interface PlaygroundNavigation {
override val route: String = "window"
}

data object InsetAnimation : PlaygroundNavigation {
override val route: String = "inset_animation"
}

data object Layout : PlaygroundNavigation {
override val route: String = "layout"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ private val playGroundStates = listOf(
description = "Cutout, Immersive, SystemBars에 대한 예제입니다.",
navigationRoute = PlaygroundNavigation.Window
),
PlayGroundState(
name = "Inset_Animation",
description = "Window Inset Animation Sample",
navigationRoute = PlaygroundNavigation.InsetAnimation
),
PlayGroundState(
name = "Layout",
description = "Layout에 대한 예제입니다.",
Expand Down
1 change: 1 addition & 0 deletions feature/inset-animation/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
19 changes: 19 additions & 0 deletions feature/inset-animation/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
plugins {
id("playground.android.library")
id("playground.android.hilt")
}

android {
namespace = "com.sample.feature.window"

buildFeatures {
viewBinding = true
}
}

dependencies {
implementation(libs.androidx.compose.activity)
implementation(libs.androidx.appcompat)
implementation(libs.androidx.core.ktx)
implementation(libs.material)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.sample.inset_animation

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.sample.inset_animation.test", appContext.packageName)
}
}
4 changes: 4 additions & 0 deletions feature/inset-animation/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.sample.feature.inset_animation

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import com.sample.feature.window.databinding.ActivityInsetAnimationSampleBinding


class InsetAnimationSampleActivity : AppCompatActivity() {

private val binding by lazy { ActivityInsetAnimationSampleBinding.inflate(layoutInflater) }

private val adapter = ItemAdapter()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(binding.root)
enableEdgeToEdge()

binding.recyclerView.adapter = adapter
val items = List(1000) { index ->
Item(index, "Item $index")
}
adapter.submitList(items)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.sample.feature.inset_animation

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.sample.feature.window.R

data class Item(val id: Int, val text: String)

class ItemAdapter : ListAdapter<Item, ItemAdapter.ItemViewHolder>(ItemDiffCallback()) {

class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
private val textView: TextView = itemView.findViewById(R.id.text_view)

fun bind(item: Item) {
textView.text = item.text
}
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.item_view, parent, false)
return ItemViewHolder(view)
}

override fun onBindViewHolder(holder: ItemViewHolder, position: Int) {
holder.bind(getItem(position))
}

companion object {
class ItemDiffCallback : DiffUtil.ItemCallback<Item>() {
override fun areItemsTheSame(oldItem: Item, newItem: Item): Boolean {
return oldItem.id == newItem.id
}

override fun areContentsTheSame(oldItem: Item, newItem: Item): Boolean {
return oldItem == newItem
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@+id/edit_text"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layoutManager="LinearLayoutManager" />

<EditText
android:id="@+id/edit_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="Type here"
android:background="@android:color/white"
android:padding="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
18 changes: 18 additions & 0 deletions feature/inset-animation/src/main/res/layout/item_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">

<TextView
android:id="@+id/text_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.sample.inset_animation

import org.junit.Test

import org.junit.Assert.*

/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}
3 changes: 3 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
@file:Suppress("UnstableApiUsage")

include(":feature:inset-animation")


pluginManagement {
includeBuild("build-logic")
repositories {
Expand Down

0 comments on commit 75453c9

Please sign in to comment.