Showing
6 changed files
with
133 additions
and
19 deletions
| 1 | +package com.example.vip | ||
| 2 | + | ||
| 3 | +import android.content.Context | ||
| 4 | +import android.util.AttributeSet | ||
| 5 | +import android.util.TypedValue | ||
| 6 | +import android.widget.ImageView | ||
| 7 | +import android.widget.LinearLayout | ||
| 8 | + | ||
| 9 | +class CircleIndicator: LinearLayout { | ||
| 10 | + | ||
| 11 | + private var mContext: Context? = null | ||
| 12 | + | ||
| 13 | + private var mDefaultCircle: Int = 0 | ||
| 14 | + private var mSelectCircle: Int = 0 | ||
| 15 | + | ||
| 16 | + private var imageDot: MutableList<ImageView> = mutableListOf() | ||
| 17 | + | ||
| 18 | + // 4.5dp 를 픽셀 단위로 바꿉니다. | ||
| 19 | + private val temp = TypedValue.applyDimension( | ||
| 20 | + TypedValue.COMPLEX_UNIT_DIP, 4.5f, resources.displayMetrics) | ||
| 21 | + | ||
| 22 | + constructor(context: Context) : super(context) { | ||
| 23 | + mContext = context | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { | ||
| 27 | + mContext = context | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + /** | ||
| 31 | + * 기본 점 생성 | ||
| 32 | + * @param count 점의 갯수 | ||
| 33 | + * @param defaultCircle 기본 점의 이미지 | ||
| 34 | + * @param selectCircle 선택된 점의 이미지 | ||
| 35 | + * @param position 선택된 점의 포지션 | ||
| 36 | + */ | ||
| 37 | + fun createDotPanel(count: Int, defaultCircle: Int, selectCircle: Int, position: Int) { | ||
| 38 | + | ||
| 39 | + this.removeAllViews() | ||
| 40 | + | ||
| 41 | + mDefaultCircle = defaultCircle | ||
| 42 | + mSelectCircle = selectCircle | ||
| 43 | + | ||
| 44 | + for (i in 0 until count) { | ||
| 45 | + imageDot.add(ImageView(mContext).apply { setPadding(temp.toInt(), 0, temp.toInt(), 0) }) | ||
| 46 | + this.addView(imageDot[i]) | ||
| 47 | + } | ||
| 48 | + //인덱스 선택 | ||
| 49 | + selectDot(position) | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + /** | ||
| 53 | + * 선택된 점 표시 | ||
| 54 | + * @param position | ||
| 55 | + */ | ||
| 56 | + fun selectDot(position: Int) { | ||
| 57 | + for (i in imageDot.indices) { | ||
| 58 | + if (i == position) { | ||
| 59 | + imageDot[i].setImageResource(mSelectCircle) | ||
| 60 | + } else { | ||
| 61 | + imageDot[i].setImageResource(mDefaultCircle) | ||
| 62 | + } | ||
| 63 | + } | ||
| 64 | + } | ||
| 65 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| ... | @@ -177,7 +177,7 @@ class DetailActivity : AppCompatActivity() { | ... | @@ -177,7 +177,7 @@ class DetailActivity : AppCompatActivity() { |
| 177 | setSupportActionBar(toolbar) | 177 | setSupportActionBar(toolbar) |
| 178 | 178 | ||
| 179 | // 2. 툴바 왼쪽 버튼 설정 | 179 | // 2. 툴바 왼쪽 버튼 설정 |
| 180 | - supportActionBar!!.setDisplayHomeAsUpEnabled(true) // 왼쪽 버튼 사용 여부 true | 180 | + supportActionBar!!.setDisplayHomeAsUpEnabled(false) // 왼쪽 버튼 사용 여부 true |
| 181 | supportActionBar!!.setHomeAsUpIndicator(R.drawable.return_page) // 왼쪽 버튼 아이콘 설정 | 181 | supportActionBar!!.setHomeAsUpIndicator(R.drawable.return_page) // 왼쪽 버튼 아이콘 설정 |
| 182 | supportActionBar!!.setDisplayShowTitleEnabled(false) // 타이틀 안보이게 하기 | 182 | supportActionBar!!.setDisplayShowTitleEnabled(false) // 타이틀 안보이게 하기 |
| 183 | 183 | ... | ... |
| ... | @@ -12,7 +12,9 @@ import android.widget.Toast | ... | @@ -12,7 +12,9 @@ import android.widget.Toast |
| 12 | import androidx.appcompat.app.ActionBar | 12 | import androidx.appcompat.app.ActionBar |
| 13 | import androidx.appcompat.app.AlertDialog | 13 | import androidx.appcompat.app.AlertDialog |
| 14 | import androidx.appcompat.app.AppCompatActivity | 14 | import androidx.appcompat.app.AppCompatActivity |
| 15 | +import androidx.core.app.ActivityCompat.finishAffinity | ||
| 15 | import androidx.core.content.ContextCompat | 16 | import androidx.core.content.ContextCompat |
| 17 | +import androidx.core.content.ContextCompat.startActivity | ||
| 16 | import androidx.viewpager.widget.ViewPager | 18 | import androidx.viewpager.widget.ViewPager |
| 17 | import com.google.android.material.bottomnavigation.BottomNavigationView | 19 | import com.google.android.material.bottomnavigation.BottomNavigationView |
| 18 | import com.google.android.material.snackbar.Snackbar | 20 | import com.google.android.material.snackbar.Snackbar |
| ... | @@ -150,6 +152,25 @@ class SignInActivity : AppCompatActivity() { | ... | @@ -150,6 +152,25 @@ class SignInActivity : AppCompatActivity() { |
| 150 | val viewpageradapter = ViewPagerAdapter(this) | 152 | val viewpageradapter = ViewPagerAdapter(this) |
| 151 | viewpager.adapter = viewpageradapter | 153 | viewpager.adapter = viewpageradapter |
| 152 | 154 | ||
| 155 | + | ||
| 156 | + viewpager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener{ | ||
| 157 | + override fun onPageScrollStateChanged(p0: Int) { | ||
| 158 | + | ||
| 159 | + } | ||
| 160 | + | ||
| 161 | + override fun onPageScrolled(p0: Int, p1: Float, p2: Int) { | ||
| 162 | + | ||
| 163 | + } | ||
| 164 | + | ||
| 165 | + override fun onPageSelected(p0: Int) { | ||
| 166 | + ciMainActivity.selectDot(p0) | ||
| 167 | + } | ||
| 168 | + | ||
| 169 | + }) | ||
| 170 | + | ||
| 171 | + //init indicator | ||
| 172 | + ciMainActivity.createDotPanel(3, R.drawable.indicator_dot_off, R.drawable.indicator_dot_on, 0) | ||
| 173 | + | ||
| 153 | // 1. 툴바 사용 설정 | 174 | // 1. 툴바 사용 설정 |
| 154 | setSupportActionBar(toolbar) | 175 | setSupportActionBar(toolbar) |
| 155 | 176 | ... | ... |
| 1 | +<?xml version="1.0" encoding="utf-8"?> | ||
| 2 | +<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
| 3 | + android:shape="oval"> | ||
| 4 | + <solid | ||
| 5 | + android:color="#FFF"/> | ||
| 6 | + | ||
| 7 | + <size | ||
| 8 | + android:height="7dp" | ||
| 9 | + android:width="7dp"/> | ||
| 10 | +</shape> | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | +<?xml version="1.0" encoding="utf-8"?> | ||
| 2 | +<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
| 3 | + android:shape="oval"> | ||
| 4 | + | ||
| 5 | + <solid | ||
| 6 | + android:color="#29ABE2"/> | ||
| 7 | + | ||
| 8 | + <size | ||
| 9 | + android:height="7dp" | ||
| 10 | + android:width="7dp"/> | ||
| 11 | + | ||
| 12 | +</shape> | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| ... | @@ -34,24 +34,6 @@ | ... | @@ -34,24 +34,6 @@ |
| 34 | android:src="@drawable/toolbar_logo" /> | 34 | android:src="@drawable/toolbar_logo" /> |
| 35 | </androidx.appcompat.widget.Toolbar> | 35 | </androidx.appcompat.widget.Toolbar> |
| 36 | 36 | ||
| 37 | - <LinearLayout | ||
| 38 | - android:layout_width="match_parent" | ||
| 39 | - android:layout_height="wrap_content" | ||
| 40 | - android:layout_gravity="top" | ||
| 41 | - android:layout_weight="1" | ||
| 42 | - android:gravity="top" | ||
| 43 | - android:orientation="horizontal"> | ||
| 44 | - | ||
| 45 | - <androidx.viewpager.widget.ViewPager | ||
| 46 | - android:id="@+id/welcomeViewPager" | ||
| 47 | - android:layout_width="match_parent" | ||
| 48 | - android:layout_height="262dp" | ||
| 49 | - android:layout_gravity="top" | ||
| 50 | - android:layout_weight="1"> | ||
| 51 | - | ||
| 52 | - </androidx.viewpager.widget.ViewPager> | ||
| 53 | - </LinearLayout> | ||
| 54 | - | ||
| 55 | <!-- | 37 | <!-- |
| 56 | <LinearLayout | 38 | <LinearLayout |
| 57 | android:layout_width="match_parent" | 39 | android:layout_width="match_parent" |
| ... | @@ -86,6 +68,30 @@ | ... | @@ -86,6 +68,30 @@ |
| 86 | </LinearLayout> | 68 | </LinearLayout> |
| 87 | --> | 69 | --> |
| 88 | 70 | ||
| 71 | + <FrameLayout | ||
| 72 | + android:layout_width="match_parent" | ||
| 73 | + android:layout_height="wrap_content"> | ||
| 74 | + | ||
| 75 | + <androidx.viewpager.widget.ViewPager | ||
| 76 | + android:id="@+id/welcomeViewPager" | ||
| 77 | + android:layout_width="match_parent" | ||
| 78 | + android:layout_height="262dp" | ||
| 79 | + android:layout_gravity="top" | ||
| 80 | + android:layout_weight="1"> | ||
| 81 | + | ||
| 82 | + </androidx.viewpager.widget.ViewPager> | ||
| 83 | + | ||
| 84 | + <com.example.vip.CircleIndicator | ||
| 85 | + android:id="@+id/ciMainActivity" | ||
| 86 | + android:layout_width="wrap_content" | ||
| 87 | + android:layout_height="wrap_content" | ||
| 88 | + android:layout_gravity="bottom|center_horizontal" | ||
| 89 | + android:layout_marginBottom="20dp" | ||
| 90 | + app:layout_constraintBottom_toBottomOf="parent" | ||
| 91 | + app:layout_constraintEnd_toEndOf="parent" | ||
| 92 | + app:layout_constraintStart_toStartOf="parent" /> | ||
| 93 | + </FrameLayout> | ||
| 94 | + | ||
| 89 | <LinearLayout | 95 | <LinearLayout |
| 90 | android:layout_width="match_parent" | 96 | android:layout_width="match_parent" |
| 91 | android:layout_height="wrap_content" | 97 | android:layout_height="wrap_content" | ... | ... |
-
Please register or login to post a comment