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
File renamed without changes.
3 changes: 3 additions & 0 deletions Assignment_11/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion newProject/.idea/misc.xml → Assignment_11/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ android {
defaultConfig {
applicationId = "com.example.assignment"
minSdk = 34
targetSdk = 34
versionCode = 1
versionName = "1.0"

Expand All @@ -33,6 +32,9 @@ android {
kotlinOptions {
jvmTarget = "1.8"
}
buildFeatures {
viewBinding = true
}
}

dependencies {
Expand All @@ -42,6 +44,7 @@ dependencies {
implementation(libs.material)
implementation(libs.androidx.activity)
implementation(libs.androidx.constraintlayout)
implementation(libs.androidx.viewpager2)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.example.assignment

import android.graphics.Color
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment

class ColorFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
val view = View(requireContext())
view.layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)

val colorOrder = arguments?.getInt(COLOR_ORDER) ?: 0
val colors = listOf(
Color.RED,
Color.rgb(255, 127, 0),
Color.YELLOW,
Color.GREEN,
Color.BLUE,
Color.rgb(75, 0, 130),
Color.rgb(137, 119, 173)
)
view.setBackgroundColor(colors[colorOrder])

return view
}

companion object {
private const val COLOR_ORDER = "order"

fun newInstance(order: Int): ColorFragment {
val fragment = ColorFragment()
val bundle = Bundle()
bundle.putInt(COLOR_ORDER, order)
fragment.arguments = bundle
return fragment
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.example.assignment

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.viewpager2.widget.ViewPager2
import com.example.assignment.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity() {
private lateinit var viewPager: ViewPager2
private lateinit var binding: ActivityMainBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)

viewPager = binding.viewPager
val bottomNavigationView = binding.bottomNavigationView

setViewPagerAdapterForPageType(ViewPagerAdapter.PageType.COLOR)

bottomNavigationView.setOnItemSelectedListener { item ->
when (item.itemId) {
R.id.rainbow_menu -> setViewPagerAdapterForPageType(ViewPagerAdapter.PageType.COLOR)
R.id.number_menu -> setViewPagerAdapterForPageType(ViewPagerAdapter.PageType.NUMBER)
R.id.alphabet_menu -> setViewPagerAdapterForPageType(ViewPagerAdapter.PageType.ALPHABET)
}
true
}


}

private fun setViewPagerAdapterForPageType(pageType: ViewPagerAdapter.PageType) {
viewPager.adapter = ViewPagerAdapter(this, pageType)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.example.assignment

import android.graphics.Typeface
import android.os.Bundle
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment

class TextFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
val textView = TextView(requireContext()).apply {
layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
gravity = Gravity.CENTER
textSize = 80F
setTypeface(typeface, Typeface.BOLD)

text = arguments?.getString(TEXT_ORDER) ?: ""
}

return textView
}

companion object {
private const val TEXT_ORDER = "order"

fun newInstance(order: String): TextFragment {
val fragment = TextFragment()
val bundle = Bundle()
bundle.putString(TEXT_ORDER, order)
fragment.arguments = bundle
return fragment
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.example.assignment

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter

class ViewPagerAdapter(fragmentActivity: FragmentActivity, private val type: PageType) :
FragmentStateAdapter(fragmentActivity) {
enum class PageType {
COLOR, NUMBER, ALPHABET
}

override fun getItemCount(): Int {
return when (type) {
PageType.COLOR -> 7
PageType.NUMBER -> 11
PageType.ALPHABET -> 26
}
}

override fun createFragment(order: Int): Fragment {
return when (type) {
PageType.COLOR -> ColorFragment.newInstance(order)
PageType.NUMBER -> TextFragment.newInstance((0..10).toList()[order].toString())
PageType.ALPHABET -> TextFragment.newInstance(('A'..'Z').toList()[order].toString())
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M3,13h8L11,3L3,3v10zM3,21h8v-6L3,15v6zM13,21h8L21,11h-8v10zM13,3v6h8L21,3h-8z" />
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M10,20v-6h4v6h5v-8h3L12,3 2,12h3v8z" />
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M12,22c1.1,0 2,-0.9 2,-2h-4c0,1.1 0.89,2 2,2zM18,16v-5c0,-3.07 -1.64,-5.64 -4.5,-6.32L13.5,4c0,-0.83 -0.67,-1.5 -1.5,-1.5s-1.5,0.67 -1.5,1.5v0.68C7.63,5.36 6,7.92 6,11v5l-2,2v1h16v-1l-2,-2z" />
</vector>
20 changes: 20 additions & 0 deletions Assignment_11/app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<LinearLayout 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"
android:orientation="vertical">

<androidx.viewpager2.widget.ViewPager2
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />

<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:menu="@menu/bottom_nav_menu" />


</LinearLayout>
18 changes: 18 additions & 0 deletions Assignment_11/app/src/main/res/menu/bottom_nav_menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/rainbow_menu"
android:icon="@drawable/ic_dashboard_black_24dp"
android:title="@string/rainbow_text" />

<item
android:id="@+id/number_menu"
android:icon="@drawable/ic_home_black_24dp"
android:title="@string/number_text" />

<item
android:id="@+id/alphabet_menu"
android:icon="@drawable/ic_notifications_black_24dp"
android:title="@string/alphabet_text" />

</menu>
6 changes: 6 additions & 0 deletions Assignment_11/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<resources>
<string name="app_name">assignment</string>
<string name="rainbow_text">무지개</string>
<string name="number_text">숫자</string>
<string name="alphabet_text">알파벳</string>
</resources>
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ appcompat = "1.7.0"
material = "1.12.0"
activity = "1.9.3"
constraintlayout = "2.2.0"
viewpager2 = "1.1.0"

[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
androidx-viewpager2 = { module = "androidx.viewpager2:viewpager2", version.ref = "viewpager2" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

This file was deleted.

19 changes: 0 additions & 19 deletions newProject/app/src/main/res/layout/activity_main.xml

This file was deleted.

3 changes: 0 additions & 3 deletions newProject/app/src/main/res/values/strings.xml

This file was deleted.