Skip to content

Instantly share code, notes, and snippets.

interface FabulousListener {
fun onClick()
}
class FabulousFragment : Fragment() {
companion object {
fun newInstance() = FabulousFragment()
}
class FabulousActivity : Activity() {
companion object {
fun newIntent(context: Context): Intent = Intent(context, FabulousActivity::class.java)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Commit FabulousFragment instance into FragmentManager
class FabulousActivity : Activity(), FabulousListener {
companion object {
fun newIntent(context: Context): Intent = Intent(context, FabulousActivity::class.java)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Commit FabulousFragment instance into FragmentManager
interface FabulousListener {
fun onClick()
}
class FabulousFragment : Fragment() {
companion object {
fun newInstance() = FabulousFragment()
}
class SegmentedProgressBar @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {
override fun onDraw(canvas: Canvas) {
// Draw something onto the canvas
}
}
class SegmentedProgressBar @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {
@get:ColorInt
var segmentColor: Int = Color.WHITE
var segmentAlpha: Float = 1f
class SegmentedProgressBar @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {
@get:ColorInt
var segmentColor: Int = Color.WHITE
var segmentAlpha: Float = 1f
var segmentCount: Int = 1
class SegmentCoordinatesComputer {
fun segmentCoordinates(position: Int, segmentCount: Int, width: Float, spacing: Float): SegmentCoordinates {
val segmentWidth = (width - spacing * (segmentCount - 1)) / segmentCount
val isLast = position == segmentCount - 1
val topLeft = (segmentWidth + spacing) * position
val bottomLeft = (segmentWidth + spacing) * position
val topRight = segmentWidth * (position + 1) + spacing * position
val bottomRight = segmentWidth * (position + 1) + spacing * position
class SegmentCoordinatesComputer {
fun segmentCoordinates(position: Int, segmentCount: Int, width: Float, spacing: Float): SegmentCoordinates {
[...]
}
fun progressCoordinates(progress: Int, segmentCount: Int, width: Float, spacing: Float): SegmentCoordinates {
val segmentWidth = (width - spacing * (segmentCount - 1)) / segmentCount
val isLast = progress == segmentCount
class SegmentedProgressBar @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {
[...]
@get:ColorInt
var progressColor: Int = Color.GREEN