-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
185 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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,17.27L18.18,21l-1.64,-7.03L22,9.24l-7.19,-0.61L12,2 9.19,8.63 2,9.24l5.46,4.73L5.82,21z"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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="#EB3351" | ||
android:pathData="M12,17.27L18.18,21l-1.64,-7.03L22,9.24l-7.19,-0.61L12,2 9.19,8.63 2,9.24l5.46,4.73L5.82,21z" /> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
indicatordecorator/src/main/java/xyz/sangcomz/indicatordecorator/shape/CircleIndicator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package xyz.sangcomz.indicatordecorator.shape | ||
|
||
import android.graphics.Canvas | ||
import android.graphics.Color | ||
import android.graphics.Paint | ||
|
||
class CircleIndicator : IndicatorShape { | ||
private val paint = Paint().apply { isAntiAlias = true } | ||
var colorActive: Int = Color.YELLOW | ||
var colorInactive: Int = Color.GRAY | ||
var radius: Float = 1f | ||
|
||
override var scaleFactor: Float = 1.2f | ||
|
||
override fun getIndicatorWidth() = radius * 2 | ||
|
||
override fun inactiveIndicatorDraw(c: Canvas, x: Float, y: Float) { | ||
paint.color = colorInactive | ||
c.drawCircle(x, y, radius, paint) | ||
} | ||
|
||
override fun activeIndicatorDraw(c: Canvas, x: Float, y: Float) { | ||
paint.color = colorActive | ||
c.drawCircle(x, y, radius * scaleFactor, paint) | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
indicatordecorator/src/main/java/xyz/sangcomz/indicatordecorator/shape/DrawableIndicator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package xyz.sangcomz.indicatordecorator.shape | ||
|
||
import android.graphics.Canvas | ||
import android.graphics.drawable.Drawable | ||
|
||
|
||
class DrawableIndicator( | ||
drawableActive: Drawable, | ||
drawableInActive: Drawable | ||
) : IndicatorShape { | ||
override var scaleFactor: Float = 1f | ||
var width: Float = drawableActive.intrinsicWidth.toFloat() | ||
var drawableActive = drawableActive | ||
var drawableInActive = drawableInActive | ||
|
||
override fun inactiveIndicatorDraw(c: Canvas, x: Float, y: Float) { | ||
drawableInActive.setBounds( | ||
x.toInt(), | ||
(y - width / 2).toInt(), | ||
(x + width).toInt(), | ||
(y + width / 2).toInt() | ||
) | ||
drawableInActive.draw(c) | ||
} | ||
|
||
override fun activeIndicatorDraw(c: Canvas, x: Float, y: Float) { | ||
val scale = ((width * scaleFactor) - width) / 2 | ||
drawableActive.setBounds( | ||
(x - scale).toInt(), | ||
(y - width / 2).toInt(), | ||
(x + width + scale).toInt(), | ||
(y + width / 2).toInt() | ||
) | ||
drawableActive.draw(c) | ||
} | ||
|
||
override fun getIndicatorWidth() = width | ||
} |
10 changes: 10 additions & 0 deletions
10
indicatordecorator/src/main/java/xyz/sangcomz/indicatordecorator/shape/IndicatorShape.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package xyz.sangcomz.indicatordecorator.shape | ||
|
||
import android.graphics.Canvas | ||
|
||
interface IndicatorShape { | ||
var scaleFactor: Float | ||
fun inactiveIndicatorDraw(c: Canvas, x: Float, y: Float) | ||
fun activeIndicatorDraw(c: Canvas, x: Float, y: Float) | ||
fun getIndicatorWidth(): Float | ||
} |
31 changes: 31 additions & 0 deletions
31
indicatordecorator/src/main/java/xyz/sangcomz/indicatordecorator/shape/SquareIndicator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package xyz.sangcomz.indicatordecorator.shape | ||
|
||
import android.graphics.Canvas | ||
import android.graphics.Color | ||
import android.graphics.Paint | ||
|
||
class SquareIndicator : IndicatorShape { | ||
private val paint = Paint().apply { isAntiAlias = true } | ||
var colorActive: Int = Color.RED | ||
var colorInactive: Int = Color.GRAY | ||
var width = 20f | ||
override var scaleFactor = 1.5f | ||
override fun inactiveIndicatorDraw(c: Canvas, x: Float, y: Float) { | ||
paint.color = colorInactive | ||
c.drawRect(x, y - width / 2, x + width, y + width / 2, paint) | ||
} | ||
|
||
override fun activeIndicatorDraw(c: Canvas, x: Float, y: Float) { | ||
paint.color = colorActive | ||
val scale = ((width * scaleFactor) - width) / 2 | ||
c.drawRect( | ||
x - scale, | ||
y - (width * scaleFactor) / 2, | ||
x + width + scale, | ||
y + (width * scaleFactor) / 2, | ||
paint | ||
) | ||
} | ||
|
||
override fun getIndicatorWidth() = width | ||
} |