Skip to content

Instantly share code, notes, and snippets.

View 2hamed's full-sized avatar
🏠
Working from home

Hamed Momeni 2hamed

🏠
Working from home
View GitHub Profile
private var recordRadius: Float = 0f
private val recordRect = RectF()
private val recordPaint = Paint().apply {
color = Color.RED
}
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
if (measuredHeight > 0 && measuredWidth > 0) {
...
enum class Mode {
Idle, Ready, Recording, Loading
}
override fun onDraw(canvas: Canvas) {
canvas.drawCircle(cx, cy, radius, outerPaint)
canvas.drawCircle(cx, cy, radius - radiusDiff, innerPaint)
}
private val radiusDiff = dpToPx(10).toFloat()
private val innerPaint = Paint().apply {
color = Color.WHITE
isAntiAlias = true
}
private val outerPaint = Paint().apply {
color = Color.parseColor("#99FFFFFF")
strokeWidth = radiusDiff.toFloat()
style = Paint.Style.FILL
private var cx: Float = 0f // x coordinate of the center
private var cy: Float = 0f // y coordinate of the center
private var radius: Float = 0f // the radius of the view = min(width, height) * 0.95
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
if (measuredHeight > 0 && measuredWidth > 0) {
cx = measuredWidth / 2f
cy = measuredHeight / 2f
radius = Math.min(measuredHeight, measuredWidth) / 2 * 0.95f - paddingBottom
class RecordButton : View {
constructor(context: Context) : super(context)
constructor(context: Context, attributeSet: AttributeSet) : super(context, attributeSet)
}
navEvents.subscribe {
when (it.destination) {
NavEvent.Destination.ONE -> navController.popBackStack(R.id.fragmentOne, false)
NavEvent.Destination.TWO -> navController.navigate(R.id.action_fragmentOne_to_fragmentTwo)
NavEvent.Destination.THREE -> when (navController.currentDestination!!.id) {
R.id.fragmentOne -> navController.navigate(R.id.action_fragmentOne_to_fragmentThree)
R.id.fragmentTwo -> navController.navigate(R.id.action_fragmentTwo_to_fragmentThree)
}
NavEvent.Destination.FOUR -> navController.navigate(R.id.action_fragmentTwo_to_fragmentFour)
}
class FragmentOne: Fragment() {
@Inject
lateinit var navEvents: PublishProcessor<NavEvent>
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
(context!!.applicationContext as App).di.inject(this)
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View =
inflater.inflate(R.layout.fragment_one, container, false)
navEvents.subscribe {
when (it.destination) {
NavEvent.Destination.ONE -> navController.popBackStack(R.id.fragmentOne, false)
NavEvent.Destination.TWO -> navController.navigate(R.id.action_fragmentOne_to_fragmentTwo)
NavEvent.Destination.THREE -> navController.navigate(R.id.action_fragmentOne_to_fragmentThree)
NavEvent.Destination.FOUR -> navController.navigate(R.id.action_fragmentTwo_to_fragmentFour)
}
}
class MainActivity : AppCompatActivity() {
@Inject
lateinit var navEvents: PublishProcessor<NavEvent>
lateinit var navController: NavController
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)