Skip to content

Commit

Permalink
add icon and comment
Browse files Browse the repository at this point in the history
  • Loading branch information
sangcomz committed Sep 25, 2019
1 parent 004e7ed commit 26998a8
Show file tree
Hide file tree
Showing 26 changed files with 117 additions and 394 deletions.
Binary file added app/src/main/ic_launcher-web.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.PagerSnapHelper
import kotlinx.android.synthetic.main.activity_main.*
import xyz.sangcomz.indicatordecorator.IndicatorItemDecoration
import xyz.sangcomz.indicatordecorator.shape.CircleIndicator
import xyz.sangcomz.indicatordecorator.shape.DrawableIndicator
import xyz.sangcomz.indicatordecorator.shape.SquareIndicator

class MainActivity : AppCompatActivity() {

Expand All @@ -27,10 +29,15 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

viewPager.adapter = adapter
viewPager.addItemDecoration(IndicatorItemDecoration().apply {
viewPager1.adapter = adapter
viewPager1.addItemDecoration(IndicatorItemDecoration().apply {
indicatorShape = CircleIndicator()
})

viewPager2.adapter = adapter
viewPager2.addItemDecoration(IndicatorItemDecoration().apply {
indicatorShape = SquareIndicator()
})
// viewPager.addItemDecoration(LinePagerIndicatorDecoration())

recyclerView.adapter = adapter
PagerSnapHelper().attachToRecyclerView(recyclerView)
Expand Down
21 changes: 21 additions & 0 deletions app/src/main/res/drawable-v24/ic_launcher_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportWidth="512"
android:viewportHeight="512">
<path
android:pathData="M-0,-0l512,-0l-0,511.999l-512,0z">
<aapt:attr name="android:fillColor">
<gradient
android:startY="256.00067"
android:startX="3.0169793E-5"
android:endY="256.00067"
android:endX="511.9996"
android:type="linear">
<item android:offset="0" android:color="#FF43CBFF"/>
<item android:offset="1" android:color="#FF9708CC"/>
</gradient>
</aapt:attr>
</path>
</vector>
34 changes: 0 additions & 34 deletions app/src/main/res/drawable-v24/ic_launcher_foreground.xml

This file was deleted.

170 changes: 0 additions & 170 deletions app/src/main/res/drawable/ic_launcher_background.xml

This file was deleted.

24 changes: 24 additions & 0 deletions app/src/main/res/drawable/ic_launcher_foreground.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="911.51514"
android:viewportHeight="911.51514">
<group android:translateX="199.75757"
android:translateY="199.75757">
<path
android:fillColor="#FF000000"
android:pathData="M476.126,256C476.126,211.772 440.218,175.864 395.99,175.864L116.008,175.864C71.78,175.864 35.872,211.772 35.872,256C35.872,300.228 71.78,336.136 116.008,336.136L395.99,336.136C440.218,336.136 476.126,300.228 476.126,256Z"
android:fillAlpha="0.38"/>
<path
android:pathData="M70.081,256a55,55.001 90.044,1 0,110.001 0a55,55.001 90.044,1 0,-110.001 0z"
android:fillColor="#ffffff"/>
<path
android:pathData="M213.5,256.001a42.5,42.5 90.054,1 0,85.001 0a42.5,42.5 90.054,1 0,-85.001 0z"
android:fillColor="#ffffff"
android:fillAlpha="0.51"/>
<path
android:pathData="M331.725,256.001a42.5,42.5 90.054,1 0,85.001 0a42.5,42.5 90.054,1 0,-85.001 0z"
android:fillColor="#ffffff"
android:fillAlpha="0.5"/>
</group>
</vector>
17 changes: 12 additions & 5 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,26 @@
android:layout_height="0dp"
android:orientation="horizontal"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toTopOf="@+id/viewPager"
app:layout_constraintBottom_toTopOf="@+id/viewPager1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewPager"
android:id="@+id/viewPager1"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="@+id/viewPager2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/recyclerView" />

<androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewPager2"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/viewPager1" />
</androidx.constraintlayout.widget.ConstraintLayout>
4 changes: 2 additions & 2 deletions app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
<background android:drawable="@drawable/ic_launcher_background"/>
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
</adaptive-icon>
4 changes: 2 additions & 2 deletions app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
<background android:drawable="@drawable/ic_launcher_background"/>
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
</adaptive-icon>
Binary file modified app/src/main/res/mipmap-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/mipmap-hdpi/ic_launcher_round.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/mipmap-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/mipmap-mdpi/ic_launcher_round.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/mipmap-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
package xyz.sangcomz.indicatordecorator

import android.content.res.Resources
import android.graphics.Canvas
import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import xyz.sangcomz.indicatordecorator.ext.toDP
import xyz.sangcomz.indicatordecorator.shape.CircleIndicator
import xyz.sangcomz.indicatordecorator.shape.IndicatorShape
import kotlin.math.max

/**
* inspired by https://github.com/bleeding182/recyclerviewItemDecorations
*/
class IndicatorItemDecoration : RecyclerView.ItemDecoration() {

var topOffset = (DP * 4).toInt()
var bottomOffset = (DP * 4).toInt()
/**
* Top Offset with Page Item
*/
var topOffset = 4.toDP().toInt()
/**
* Bottom Offset in View
*/
var bottomOffset = 4.toDP().toInt()
/**
* Padding between indicators.
*/
var indicatorItemPadding = DP * 8
var indicatorItemPadding = 8.toDP()

var indicatorShape: IndicatorShape = CircleIndicator().apply { radius = DP * 4 }
/**
* Indicator shape
* By default it has a circle of radius 4.
*/
var indicatorShape: IndicatorShape = CircleIndicator().apply { radius = 4.toDP() }

override fun onDrawOver(c: Canvas, parent: RecyclerView, state: RecyclerView.State) {
super.onDrawOver(c, parent, state)
Expand All @@ -40,7 +52,6 @@ class IndicatorItemDecoration : RecyclerView.ItemDecoration() {

drawInactiveIndicators(c, indicatorStartX, indicatorPosY, itemCount)


val activePosition = layoutManager.findFirstVisibleItemPosition()
if (activePosition == RecyclerView.NO_POSITION) {
return
Expand Down Expand Up @@ -99,8 +110,4 @@ class IndicatorItemDecoration : RecyclerView.ItemDecoration() {
super.getItemOffsets(outRect, view, parent, state)
outRect.bottom = (topOffset + bottomOffset + indicatorShape.getIndicatorWidth()).toInt()
}

companion object {
private val DP = Resources.getSystem().displayMetrics.density
}
}
Loading

0 comments on commit 26998a8

Please sign in to comment.