@@ -4,6 +4,7 @@ import android.annotation.SuppressLint
4
4
import android.graphics.*
5
5
import android.os.Bundle
6
6
import android.os.Handler
7
+ import android.os.Looper
7
8
import android.view.View
8
9
import android.view.ViewGroup
9
10
import android.view.animation.CycleInterpolator
@@ -13,20 +14,22 @@ import androidx.appcompat.app.AppCompatActivity
13
14
import androidx.core.view.*
14
15
import com.google.android.material.math.MathUtils
15
16
import io.devlight.xtreeivi.cornercutlinearlayout.CornerCutLinearLayout
17
+ import io.devlight.xtreeivi.sample.databinding.ActivityShowcaseBinding
16
18
import io.devlight.xtreeivi.sample.extensions.*
17
- import kotlinx.android.synthetic.main.activity_showcase.*
18
19
import kotlin.math.hypot
19
20
import kotlin.math.min
20
21
import kotlin.math.roundToInt
21
22
import kotlin.math.sqrt
22
23
23
24
class MainActivity : AppCompatActivity () {
24
25
25
- private val handler = Handler ()
26
+ private lateinit var viewBinding: ActivityShowcaseBinding
27
+
28
+ private val handler = Handler (Looper .getMainLooper())
26
29
private lateinit var runnable: Runnable
27
30
private val lineCountRunnable = object : Runnable {
28
31
override fun run () {
29
- with (txt_showcase_custom_view_area_provider ? : return ) {
32
+ with (viewBinding.txtShowcaseCustomViewAreaProvider ) {
30
33
maxLines = maxLines.let {
31
34
if ((it + 1 ) <= 5 ) it + 1
32
35
else 1
@@ -38,14 +41,15 @@ class MainActivity : AppCompatActivity() {
38
41
39
42
override fun onCreate (savedInstanceState : Bundle ? ) {
40
43
super .onCreate(savedInstanceState)
41
- setContentView(R .layout.activity_showcase)
44
+ viewBinding = ActivityShowcaseBinding .inflate(layoutInflater)
45
+ setContentView(viewBinding.root)
42
46
43
47
// region Custom Corner Cut
44
48
val inset = resources.displayMetrics.density * 8
45
49
val eyeRadius = resources.displayMetrics.density * 3
46
50
val halfOpenMouthAngle = 35.0F
47
51
val pacmanMouthPath = Path ()
48
- ccll_showcase_custom_lt_rb .setCornerCutProvider { _, cutout, cutEdge, rectF ->
52
+ viewBinding.ccllShowcaseCustomLtRb .setCornerCutProvider { _, cutout, cutEdge, rectF ->
49
53
when (cutEdge) {
50
54
CornerCutLinearLayout .CornerCutFlag .START_TOP -> {
51
55
rectF.inset(inset, inset)
@@ -99,7 +103,7 @@ class MainActivity : AppCompatActivity() {
99
103
var lastMillis = - 1L
100
104
var isClockwise = true
101
105
val rotationDuration = 2000L
102
- ccll_showcase_custom_lt_exceed_bounds .setCornerCutProvider(
106
+ viewBinding.ccllShowcaseCustomLtExceedBounds .setCornerCutProvider(
103
107
{ view, _, _, _ ->
104
108
val matrix = Matrix ()
105
109
val pb = view.paddedBounds
@@ -142,15 +146,15 @@ class MainActivity : AppCompatActivity() {
142
146
currentRotationAngle = maxMouthOpenHalfAngle
143
147
isClockwise = false
144
148
}
145
- ccll_showcase_custom_lt_exceed_bounds? .invalidateCornerCutPath()
149
+ viewBinding.ccllShowcaseCustomLtExceedBounds .invalidateCornerCutPath()
146
150
handler.removeCallbacks(this )
147
151
handler.postDelayed(this , 32L )
148
152
}
149
153
}
150
154
// endregion
151
155
152
156
// region Custom Child Corner Cut
153
- ccll_showcase_custom_child_cut_provider .setChildCornerCutProvider { view, cutout, _, rectF, _, _ ->
157
+ viewBinding.ccllShowcaseCustomChildCutProvider .setChildCornerCutProvider { view, cutout, _, rectF, _, _ ->
154
158
// rectF.inset(-40.0F, 0.0F)
155
159
cutout.moveTo(rectF.centerX(), rectF.top)
156
160
cutout.arcTo(
@@ -187,7 +191,7 @@ class MainActivity : AppCompatActivity() {
187
191
true
188
192
}
189
193
190
- ccll_showcase_custom_child_cut_provider_mixed .setChildCornerCutProvider(
194
+ viewBinding.ccllShowcaseCustomChildCutProviderMixed .setChildCornerCutProvider(
191
195
{ _: CornerCutLinearLayout , _: Path , cutSide: Int , rectF: RectF , _: View ? , _: View ? ->
192
196
val matrix = Matrix ()
193
197
when (cutSide) {
@@ -251,7 +255,7 @@ class MainActivity : AppCompatActivity() {
251
255
}
252
256
)
253
257
254
- ccll_showcase_custom_view_area_provider .setCustomViewAreaProvider { view, path, rectF ->
258
+ viewBinding.ccllShowcaseCustomViewAreaProvider .setCustomViewAreaProvider { view, path, rectF ->
255
259
val offset = view[0 ].marginEnd
256
260
val cornerRadius = rectF.height() / 4.0F
257
261
val tailCircleRadius = cornerRadius / 2.0F
@@ -321,7 +325,7 @@ class MainActivity : AppCompatActivity() {
321
325
val tempPath = Path ()
322
326
val tempRectF = RectF ()
323
327
324
- ccll_showcase_custom_view_area_provider_2 .setCustomViewAreaProvider { view, path, _ ->
328
+ viewBinding.ccllShowcaseCustomViewAreaProvider2 .setCustomViewAreaProvider { view, path, _ ->
325
329
view.forEach {
326
330
tempPath.rewind()
327
331
if (it is CornerCutLinearLayout ) {
@@ -352,7 +356,7 @@ class MainActivity : AppCompatActivity() {
352
356
}
353
357
}
354
358
355
- ccll_showcase_custom_view_area_provider_2_child_1 .addCustomCutoutProvider { _, cutout, rectF ->
359
+ viewBinding.ccllShowcaseCustomViewAreaProvider2Child1 .addCustomCutoutProvider { _, cutout, rectF ->
356
360
val width = rectF.width()
357
361
val height = rectF.height()
358
362
cutout.moveTo(rectF.centerX(), rectF.top)
@@ -371,7 +375,7 @@ class MainActivity : AppCompatActivity() {
371
375
val waveLineHeight = resources.getDimension(R .dimen.offset_48)
372
376
val halfWaveLineHeight = waveLineHeight / 2.0F
373
377
val halfWaveLineCutWidth = waveLineCutWidth / 2.0F
374
- ccll_showcase_custom_view_area_provider_2 .addCustomCutoutProvider { _, cutout, rectF ->
378
+ viewBinding.ccllShowcaseCustomViewAreaProvider2 .addCustomCutoutProvider { _, cutout, rectF ->
375
379
cutout.moveTo(rectF.left, rectF.centerY() - halfWaveLineCutWidth)
376
380
cutout.lineTo(
377
381
rectF.left + rectF.width() / 4.0F ,
@@ -396,7 +400,7 @@ class MainActivity : AppCompatActivity() {
396
400
}
397
401
398
402
399
- ccll_showcase_custom_view_area_provider_2 .doOnNonNullSizeLayout {
403
+ viewBinding.ccllShowcaseCustomViewAreaProvider2 .doOnNonNullSizeLayout {
400
404
val firstChild = it[0 ]
401
405
val lastChild = it[2 ]
402
406
val middleChild = it[1 ]
@@ -442,7 +446,7 @@ class MainActivity : AppCompatActivity() {
442
446
.setInterpolator(CycleInterpolator (0.5F ))
443
447
.setDuration(4000L )
444
448
.setUpdateListener {
445
- ccll_showcase_custom_view_area_provider_2 .invalidateCornerCutPath()
449
+ viewBinding.ccllShowcaseCustomViewAreaProvider2 .invalidateCornerCutPath()
446
450
}
447
451
.withEndAction {
448
452
animateLastChild()
@@ -456,33 +460,33 @@ class MainActivity : AppCompatActivity() {
456
460
// endregion
457
461
458
462
// region Cut Properties
459
- ccll_showcase_depth_and_length .doOnNonNullSizeLayout {
463
+ viewBinding.ccllShowcaseDepthAndLength .doOnNonNullSizeLayout {
460
464
val depth =
461
- (ccll_showcase_depth_and_length. width - ccll_showcase_depth_and_length. paddingEnd - ccll_showcase_depth_and_length .childEndSideCornerCutDepth / 2.0F ).roundToInt()
462
- v_showcase_bounds_depth_offset? .updateLayoutParams<FrameLayout .LayoutParams > {
465
+ (viewBinding.ccllShowcaseDepthAndLength. width - viewBinding.ccllShowcaseDepthAndLength. paddingEnd - viewBinding.ccllShowcaseDepthAndLength .childEndSideCornerCutDepth / 2.0F ).roundToInt()
466
+ viewBinding.vShowcaseBoundsDepthOffset .updateLayoutParams<FrameLayout .LayoutParams > {
463
467
marginStart = depth
464
468
}
465
469
}
466
470
467
- ccll_showcase_depth_and_length_offset .doOnNonNullSizeLayout {
468
- ccll_showcase_depth_and_length_offset .childEndSideCornerCutDepthOffset =
471
+ viewBinding.ccllShowcaseDepthAndLengthOffset .doOnNonNullSizeLayout {
472
+ viewBinding.ccllShowcaseDepthAndLengthOffset .childEndSideCornerCutDepthOffset =
469
473
it.paddedBounds.width() - it.childStartSideCornerCutDepth
470
474
}
471
475
472
- v_showcase_max_cut .duplicateViewSizeContinuously(
473
- ccll_showcase_max_cut ,
474
- transformWidth = { (ccll_showcase_max_cut .paddedBounds.width() / 2 ).roundToInt() },
475
- transformHeight = { (ccll_showcase_max_cut .paddedBounds.height() / 2 ).roundToInt() },
476
+ viewBinding.vShowcaseMaxCut .duplicateViewSizeContinuously(
477
+ viewBinding.ccllShowcaseMaxCut ,
478
+ transformWidth = { (viewBinding.ccllShowcaseMaxCut .paddedBounds.width() / 2 ).roundToInt() },
479
+ transformHeight = { (viewBinding.ccllShowcaseMaxCut .paddedBounds.height() / 2 ).roundToInt() },
476
480
)
477
481
478
- v_showcase_max_cut_equal .duplicateViewSizeContinuously(
479
- ccll_showcase_max_cut_equal ,
482
+ viewBinding.vShowcaseMaxCutEqual .duplicateViewSizeContinuously(
483
+ viewBinding.ccllShowcaseMaxCutEqual ,
480
484
transformWidth = {
481
- ccll_showcase_max_cut_equal .paddedBounds.let { min(it.width(), it.height()) / 2 }
485
+ viewBinding.ccllShowcaseMaxCutEqual .paddedBounds.let { min(it.width(), it.height()) / 2 }
482
486
.roundToInt()
483
487
},
484
488
transformHeight = {
485
- ccll_showcase_max_cut_equal .paddedBounds.let { min(it.width(), it.height()) / 2 }
489
+ viewBinding.ccllShowcaseMaxCutEqual .paddedBounds.let { min(it.width(), it.height()) / 2 }
486
490
.roundToInt()
487
491
},
488
492
)
@@ -514,8 +518,8 @@ class MainActivity : AppCompatActivity() {
514
518
playAnimation()
515
519
}
516
520
}
517
- ccll_showcase_max_cut .doOnNonNullSizeLayout(action)
518
- ccll_showcase_max_cut_equal .doOnNonNullSizeLayout(action)
521
+ viewBinding.ccllShowcaseMaxCut .doOnNonNullSizeLayout(action)
522
+ viewBinding.ccllShowcaseMaxCutEqual .doOnNonNullSizeLayout(action)
519
523
// endregion
520
524
521
525
// region Custom Divider
@@ -548,9 +552,9 @@ class MainActivity : AppCompatActivity() {
548
552
diamondDotDividerPath.close()
549
553
diamondDotDividerPath.offset(- triangleBaseWidth / 2.0F , 0.0F )
550
554
551
- ccll_showcase_custom_divider_provider .doOnNonNullSizeLayout {
552
- val pb = ccll_showcase_custom_divider_provider .paddedBounds
553
- ccll_showcase_custom_divider_provider .customDividerProviderPaint.shader =
555
+ viewBinding.ccllShowcaseCustomDividerProvider .doOnNonNullSizeLayout {
556
+ val pb = viewBinding.ccllShowcaseCustomDividerProvider .paddedBounds
557
+ viewBinding.ccllShowcaseCustomDividerProvider .customDividerProviderPaint.shader =
554
558
RadialGradient (
555
559
pb.centerX(),
556
560
pb.centerY(),
@@ -561,7 +565,7 @@ class MainActivity : AppCompatActivity() {
561
565
)
562
566
}
563
567
564
- ccll_showcase_custom_divider_provider .setCustomDividerProvider { _, dividerPath, dividerPaint, showDividerFlag, dividerTypeIndex, rectF ->
568
+ viewBinding.ccllShowcaseCustomDividerProvider .setCustomDividerProvider { _, dividerPath, dividerPaint, showDividerFlag, dividerTypeIndex, rectF ->
565
569
when (showDividerFlag) {
566
570
CornerCutLinearLayout .CustomDividerShowFlag .CONTAINER_BEGINNING -> {
567
571
dividerPaint.style = Paint .Style .STROKE
@@ -632,7 +636,7 @@ class MainActivity : AppCompatActivity() {
632
636
true
633
637
)
634
638
635
- ccll_showcase_custom_divider_provider_mixed .setCustomDividerProvider { _, dividerPath, dividerPaint, showDividerFlag, dividerTypeIndex, rectF ->
639
+ viewBinding.ccllShowcaseCustomDividerProviderMixed .setCustomDividerProvider { _, dividerPath, dividerPaint, showDividerFlag, dividerTypeIndex, rectF ->
636
640
when (showDividerFlag) {
637
641
CornerCutLinearLayout .CustomDividerShowFlag .MIDDLE -> {
638
642
dividerPaint.style = Paint .Style .STROKE
@@ -753,9 +757,7 @@ class MainActivity : AppCompatActivity() {
753
757
754
758
override fun onPause () {
755
759
super .onPause()
756
- if (::runnable.isInitialized) {
757
- handler.removeCallbacks(runnable)
758
- }
760
+ if (::runnable.isInitialized) handler.removeCallbacks(runnable)
759
761
handler.removeCallbacks(lineCountRunnable)
760
762
}
761
763
}
0 commit comments