Skip to content

Commit

Permalink
탭 레이아웃 만들고 뷰페이저 연결함
Browse files Browse the repository at this point in the history
  • Loading branch information
bokdoll committed Sep 22, 2019
1 parent 5529edf commit 8369e2f
Show file tree
Hide file tree
Showing 21 changed files with 409 additions and 24 deletions.
10 changes: 10 additions & 0 deletions SeoulSantaAndroid/.idea/codeStyles/Project.xml

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

5 changes: 5 additions & 0 deletions SeoulSantaAndroid/.idea/codeStyles/codeStyleConfig.xml

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

2 changes: 1 addition & 1 deletion SeoulSantaAndroid/.idea/misc.xml

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

6 changes: 6 additions & 0 deletions SeoulSantaAndroid/.idea/vcs.xml

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

11 changes: 10 additions & 1 deletion SeoulSantaAndroid/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,20 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'


//Design, Layout, etc.
implementation 'com.google.android.material:material:1.0.0-rc01'
implementation 'com.github.bumptech.glide:glide:4.9.0'
implementation "androidx.recyclerview:recyclerview:1.0.0"
implementation 'com.squareup.retrofit2:retrofit:2.6.1'
implementation 'com.squareup.retrofit2:converter-gson:2.6.1'
}
2 changes: 1 addition & 1 deletion SeoulSantaAndroid/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity android:name=".MainActivity" >
<activity android:name=".ui.home.MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.yamgang.seoulsantaandroid.ui.badge

import android.content.Context
import android.net.Uri
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup

import com.yamgang.seoulsantaandroid.R

class BadgeFragment : Fragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_badge, container, false)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.yamgang.seoulsantaandroid.ui.home

import android.content.Context
import android.net.Uri
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup

import com.yamgang.seoulsantaandroid.R

class HomeFragment : Fragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_home, container, false)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.yamgang.seoulsantaandroid.ui.home

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import com.yamgang.seoulsantaandroid.R
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

viewInit()
}

private fun viewInit(){
vp_main_act_pager.apply{
adapter = MainTabFragmentStatePagerAdapter(supportFragmentManager, 4)
offscreenPageLimit = 4
}

tl_main_act_bottom_bar.setupWithViewPager(vp_main_act_pager, true)

val tabLayout: View = this.layoutInflater.inflate(R.layout.tab_main_activity, null, false)
tl_main_act_bottom_bar.getTabAt(0)!!.customView = tabLayout.findViewById(R.id.btn_tab_main_act_home)
tl_main_act_bottom_bar.getTabAt(1)!!.customView = tabLayout.findViewById(R.id.btn_tab_main_act_map)
tl_main_act_bottom_bar.getTabAt(2)!!.customView = tabLayout.findViewById(R.id.btn_tab_main_act_search)
tl_main_act_bottom_bar.getTabAt(3)!!.customView = tabLayout.findViewById(R.id.btn_tab_main_act_badge)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.yamgang.seoulsantaandroid.ui.home

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentStatePagerAdapter
import com.yamgang.seoulsantaandroid.ui.badge.BadgeFragment
import com.yamgang.seoulsantaandroid.ui.home.HomeFragment
import com.yamgang.seoulsantaandroid.ui.map.MapFragment
import com.yamgang.seoulsantaandroid.ui.search.SearchFragment

class MainTabFragmentStatePagerAdapter(fm: FragmentManager, private val fragmentCount: Int) :
FragmentStatePagerAdapter(fm) {

override fun getItem(position: Int): Fragment {
when (position) {
0 -> return HomeFragment()
1 -> return MapFragment()
2 -> return SearchFragment()
3 -> return BadgeFragment()
else -> return HomeFragment()
}
}

override fun getCount(): Int = fragmentCount

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.yamgang.seoulsantaandroid.ui.map

import android.content.Context
import android.net.Uri
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup

import com.yamgang.seoulsantaandroid.R

class MapFragment : Fragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_map, container, false)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.yamgang.seoulsantaandroid.ui.search

import android.content.Context
import android.net.Uri
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup

import com.yamgang.seoulsantaandroid.R

class SearchFragment : Fragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_search, container, false)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.yamgang.seoulsantaandroid.util

import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import androidx.core.view.MotionEventCompat
import androidx.viewpager.widget.ViewPager

class SwipeDisabledViewPager : ViewPager {
var enable = false

constructor(ctx: Context) : super(ctx)

constructor(ctx: Context, attrs: AttributeSet) : super(ctx, attrs)

override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean {

if (enable) {
return super.onInterceptTouchEvent(ev)
} else {
if (MotionEventCompat.getActionMasked(ev) == MotionEvent.ACTION_MOVE) {
// ignore move action
} else {
if (super.onInterceptTouchEvent(ev)) {
super.onTouchEvent(ev)
}
}
return false
}
}

override fun onTouchEvent(ev: MotionEvent?): Boolean {
if (enable) {
return super.onTouchEvent(ev)
} else {
return MotionEventCompat.getActionMasked(ev) != MotionEvent.ACTION_MOVE && super.onTouchEvent(ev)
}
}

override fun setCurrentItem(item: Int, smoothScroll: Boolean) {
super.setCurrentItem(item, false)
}

override fun setCurrentItem(item: Int) {
super.setCurrentItem(item, false)
}

fun setPagingEnabled(enable: Boolean) {
this.enable = enable
}
}
31 changes: 22 additions & 9 deletions SeoulSantaAndroid/app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,28 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
tools:context=".ui.home.MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<com.yamgang.seoulsantaandroid.util.SwipeDisabledViewPager
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:id="@+id/vp_main_act_pager"
app:layout_constraintBottom_toTopOf="@+id/tl_main_act_bottom_bar">
</com.yamgang.seoulsantaandroid.util.SwipeDisabledViewPager>

<com.google.android.material.tabs.TabLayout
android:background="@android:color/white"
android:layout_width="0dp"
android:layout_height="50dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:id="@+id/tl_main_act_bottom_bar"
app:tabIndicatorColor="@android:color/transparent"
app:tabRippleColor="@android:color/transparent"/>

</androidx.constraintlayout.widget.ConstraintLayout>
14 changes: 14 additions & 0 deletions SeoulSantaAndroid/app/src/main/res/layout/fragment_badge.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.badge.BadgeFragment">

<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="BADGE"/>

</FrameLayout>
14 changes: 14 additions & 0 deletions SeoulSantaAndroid/app/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.home.HomeFragment">

<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="HOME"/>

</FrameLayout>
13 changes: 13 additions & 0 deletions SeoulSantaAndroid/app/src/main/res/layout/fragment_map.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.map.MapFragment">

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="MAP"/>

</FrameLayout>
Loading

0 comments on commit 8369e2f

Please sign in to comment.