@@ -500,93 +500,31 @@ class StatusView @JvmOverloads constructor(
500
500
currentCount > INVALID_STATUS_COUNT && currentCount < statusCount
501
501
502
502
private fun isShowingCurrentStatus ()=
503
- currentCount > 0 && currentCount <= statusCount
503
+ currentCount in 1 .. statusCount
504
504
505
505
506
506
override fun getSuggestedMinimumWidth (): Int {
507
507
508
- var extraWidthInCase = 0.0f
509
- if (false ){
510
-
511
- val widestLineData: StatusTextWidthInfo = getStatusTextWidthInfo(statusData.map { it.text },mTextPaintStatus)
512
-
513
- lineLength + = widestLineData.widestStatus.width - minStatusWidth(widestLineData.widestStatus.pos)
514
-
515
- widestLineData.subordinateWidestStatus?.run {
516
- val minStatusWidth = minStatusWidth(pos)
517
-
518
- if (width > minStatusWidth) {
519
- lineLength + = width - minStatusWidth
520
- }
521
- }
522
-
523
-
524
- for (pos in 0 until statusData.size) {
525
- val item = statusData[pos]
526
- when (pos) {
527
- 0 , (statusCount - 1 ) -> {
528
-
529
- item.width = if (pos == 0 ) {
530
- widestLineData.extremeLeftStatusWidth
531
- } else {
532
- widestLineData.extremeRightStatusWidth
533
- }
534
-
535
- val extraExtremesWidth = (item.width - minStatusWidthExtremes(pos)) / 2
536
-
537
- if (extraExtremesWidth > 0 ) {
538
- extraWidthInCase + = extraExtremesWidth
539
- }
540
-
541
- }
542
- else -> item.width = widestLineData.widestStatus.width
543
- }
544
-
545
- }
546
-
547
-
548
-
549
-
550
508
509
+ var extraWidth = if (true ){
510
+ setWidthDataForObeyingStatusText()
551
511
}else {
552
- extraWidthInCase+ = setWidthData()
553
-
554
-
512
+ setWidthDataForObeyingLineLength()
555
513
}
556
514
557
-
558
515
if (isShowingCurrentStatus()){
559
- extraWidthInCase + = (currentStatusRadius- circleRadius)* 2 ;
560
- }
561
-
562
- if (statusCount== 1 ) {
563
- extraWidthInCase * = 2
516
+ extraWidth + = (currentStatusRadius- circleRadius)* 2 ;
564
517
}
565
518
566
- return ((statusCount * (2 * (circleRadius + (circleStrokeWidth/ 2 )))) + ((statusCount - 1 ) * ( lineLength + (lineGap * 2 ))) + extraWidthInCase).toInt()
567
- }
568
-
569
-
570
- private fun minStatusWidth (pos : Int ): Float {
571
-
572
- var circleRadius = this .circleRadius
573
- val lineWidth = (lineLength + lineGap* 2 )
574
519
575
- if (isShowingCurrentStatus() && pos == currentCountIndex()) {
576
- circleRadius = currentStatusRadius
520
+ if (statusCount == 1 ) {
521
+ extraWidth * = 2
577
522
}
578
523
579
- return (2 * circleRadius + circleStrokeWidth) + lineWidth;
524
+ return ((statusCount * (2 * ( circleRadius + ( circleStrokeWidth/ 2 )))) + ((statusCount - 1 ) * ( lineLength + (lineGap * 2 ))) + extraWidth).toInt()
580
525
}
581
526
582
- private fun minStatusWidthExtremes (pos : Int ): Float {
583
- var circleRadius = this .circleRadius
584
527
585
- if (isShowingCurrentStatus() && pos== currentCountIndex()){
586
- circleRadius = currentStatusRadius
587
- }
588
- return (2 * circleRadius + circleStrokeWidth)
589
- }
590
528
591
529
592
530
override fun getSuggestedMinimumHeight (): Int {
@@ -702,7 +640,6 @@ class StatusView @JvmOverloads constructor(
702
640
var circleRadius = this .circleRadius
703
641
if (isShowingCurrentStatus() && i== (currentCount- 1 )){
704
642
circleRadius = currentStatusRadius
705
-
706
643
circleStrokePaint = mCircleStrokePaintCurrent
707
644
circleFillPaint = mCircleFillPaintCurrent
708
645
textPaintLabel = mTextPaintLabelCurrent
@@ -775,15 +712,6 @@ class StatusView @JvmOverloads constructor(
775
712
}
776
713
777
714
778
- /* *
779
- * checks if a flagSet contains a flag
780
- *
781
- */
782
-
783
- private fun containsFlag (flagSet : Int , flag : Int ): Boolean {
784
- return flagSet or flag == flagSet
785
- }
786
-
787
715
/* *
788
716
* @param lineLength lineLength of StatusView
789
717
* @param circleRadius circleRadius Of StatusView
@@ -795,47 +723,98 @@ class StatusView @JvmOverloads constructor(
795
723
* It calculates value using findAdjustWidthForExtremes() as assigning the same width as
796
724
* non-extreme may end up giving extraPadding to the view
797
725
*/
798
- private fun setWidthData ():Float {
726
+ private fun setWidthDataForObeyingLineLength ():Float {
799
727
var adjacentExtraWidthForView = 0.0f
800
- for (i in 0 until statusData.size){
801
728
802
- val circleRadius = if (isShowingCurrentStatus() && i== (currentCount- 1 ))currentStatusRadius else circleRadius;
729
+ for (pos in 0 until statusData.size){
730
+
731
+ val item = statusData[pos]
732
+ when (pos) {
733
+ 0 , statusCount - 1 -> {
734
+
735
+ val minStatusWidthExtremes = minStatusWidthExtremes(pos)
736
+ val minStatusWidth = minStatusWidth(pos)
737
+ val statusWidth = getTextWidth(mTextPaintStatus, item.text)
738
+ var extraExtremeWidth = 0.0f
739
+
740
+ if (statusWidth > minStatusWidthExtremes) {
741
+ extraExtremeWidth = Math .min(minStatusWidth - minStatusWidthExtremes, statusWidth - minStatusWidthExtremes) / 2
742
+ }
743
+
744
+ item.width = minStatusWidthExtremes + 2 * extraExtremeWidth
745
+ adjacentExtraWidthForView + = extraExtremeWidth
803
746
804
- if (i== 0 || i== (statusCount- 1 )){
805
- val extraWidth = findAdjustWidthForExtremes(statusData[i].text,lineLength,circleRadius)
806
- adjacentExtraWidthForView+ = extraWidth
807
- val minWidthForExtreme = (2 * circleRadius + circleStrokeWidth)
808
- if (extraWidth> 0 ){
809
- statusData[i].width = minWidthForExtreme + 2 * extraWidth
810
747
811
- }else {
812
- statusData[i].width = minWidthForExtreme
813
748
}
814
- } else {
815
- statusData[i].width = (lineLength + lineGap * 2 ) + ( 2 * circleRadius + circleStrokeWidth)
749
+ else -> item.width = minStatusWidth(pos)
750
+
816
751
}
817
752
}
818
753
return adjacentExtraWidthForView
819
754
}
820
755
821
- /* *
822
- * @param text Status text
823
- * @param lineLength lineLength of StatusView
824
- * @param circleRadius circleRadius Of StatusView
825
- * @return Returns max width that an extreme label would need besides the circle Width
826
- * The return value does not exceed half the linelength on each side, since it would affect the symmetry.
827
- * i.e circleWidth < return value > linelength
828
- */
829
- private fun findAdjustWidthForExtremes (text : String , lineLength : Float , circleRadius : Float ):Float {
830
- val totalWidth = getTextWidth(mTextPaintStatus, text)
831
- val actualWidth = (2 * (circleRadius + circleStrokeWidth/ 2 ))
832
- val extraWidth = Math .max(totalWidth, actualWidth)
833
- return if (extraWidth== totalWidth){
834
- Math .min((lineLength + lineGap* 2 ),(totalWidth- actualWidth))/ 2
835
- }else {
836
- 0.0f
756
+
757
+ private fun setWidthDataForObeyingStatusText (): Float {
758
+ var extraWidth = 0.0f
759
+
760
+ val widestLineData: StatusTextWidthInfo = getStatusTextWidthInfo(statusData.map { it.text }, mTextPaintStatus)
761
+
762
+ lineLength + = widestLineData.widestStatus.width - minStatusWidth(widestLineData.widestStatus.pos)
763
+
764
+ widestLineData.subordinateWidestStatus?.run {
765
+ val minStatusWidth = minStatusWidth(pos)
766
+
767
+ if (width > minStatusWidth) {
768
+ lineLength + = width - minStatusWidth
769
+ }
770
+ }
771
+
772
+
773
+ for (pos in 0 until statusData.size) {
774
+ val item = statusData[pos]
775
+ when (pos) {
776
+ 0 , (statusCount - 1 ) -> {
777
+
778
+ item.width = if (pos == 0 ) {
779
+ widestLineData.extremeLeftStatusWidth
780
+ } else {
781
+ widestLineData.extremeRightStatusWidth
782
+ }
783
+
784
+ val extraExtremesWidth = (item.width - minStatusWidthExtremes(pos)) / 2
785
+
786
+ if (extraExtremesWidth > 0 ) {
787
+ extraWidth + = extraExtremesWidth
788
+ }
789
+
790
+ }
791
+ else -> item.width = widestLineData.widestStatus.width
792
+ }
793
+
794
+ }
795
+ return extraWidth
796
+ }
797
+
798
+
799
+ private fun minStatusWidth (pos : Int ): Float {
800
+
801
+ var circleRadius = this .circleRadius
802
+ val lineWidth = (lineLength + lineGap* 2 )
803
+
804
+ if (isShowingCurrentStatus() && pos== currentCountIndex()){
805
+ circleRadius = currentStatusRadius
837
806
}
838
807
808
+ return (2 * circleRadius + circleStrokeWidth) + lineWidth;
809
+ }
810
+
811
+ private fun minStatusWidthExtremes (pos : Int ): Float {
812
+ var circleRadius = this .circleRadius
813
+
814
+ if (isShowingCurrentStatus() && pos== currentCountIndex()){
815
+ circleRadius = currentStatusRadius
816
+ }
817
+ return (2 * circleRadius + circleStrokeWidth)
839
818
}
840
819
841
820
/* *
@@ -851,7 +830,7 @@ class StatusView @JvmOverloads constructor(
851
830
* @param labelInfo LabelInfo which contains width and text
852
831
* @return Height that the label would require
853
832
*/
854
- private fun setLabelsHeight (textPaint : TextPaint , labelInfo : StatusInfo ):Float {
833
+ private fun setLabelsHeight (textPaint : TextPaint , labelInfo : StatusInfo ):Float {
855
834
val staticLayoutHeight = getStaticLayout(labelInfo.text, textPaint, labelInfo.width)
856
835
labelInfo.staticLayout = staticLayoutHeight
857
836
labelInfo.height = staticLayoutHeight.height.toFloat()
@@ -874,50 +853,6 @@ class StatusView @JvmOverloads constructor(
874
853
}
875
854
876
855
877
- /* *
878
- * Delegate property used to requestLayout if any value changed
879
- */
880
- inner class OnLayoutProp <T > (private var field : T , private inline var func : ()-> Unit ={}){
881
- operator fun setValue (thisRef : Any? ,p : KProperty <* >,v : T ) {
882
- field = v
883
- if (ViewCompat .isLaidOut(this @StatusView)){
884
- drawingData.clear()
885
- func()
886
- requestLayout()
887
-
888
- }
889
-
890
- }
891
- operator fun getValue (thisRef : Any? ,p : KProperty <* >):T {
892
- return field
893
- }
894
-
895
- }
896
-
897
- /* *
898
- * Delegate Property used to invalidate a layout after executing a custom function
899
- */
900
- inner class OnValidateProp <T > (private var field : T , private inline var func : ()-> Unit ={}){
901
- operator fun setValue (thisRef : Any? ,p : KProperty <* >,v : T ) {
902
- field = v
903
- if (ViewCompat .isLaidOut(this @StatusView)){
904
- func()
905
- invalidate()
906
-
907
- }
908
-
909
- }
910
- operator fun getValue (thisRef : Any? ,p : KProperty <* >):T {
911
- return field
912
- }
913
-
914
- }
915
-
916
- private fun Float.pxValue (unit : Int = TypedValue .COMPLEX_UNIT_DIP ):Float {
917
- return TypedValue .applyDimension(unit,this ,resources.displayMetrics)
918
- }
919
-
920
-
921
856
class StatusTextWidthInfo (var widestStatus : StatusWidth , var subordinateWidestStatus : StatusWidth ? =null ,
922
857
var extremeLeftStatusWidth : Float =0.0f , var extremeRightStatusWidth : Float =0.0f )
923
858
@@ -962,7 +897,7 @@ class StatusView @JvmOverloads constructor(
962
897
statusWidthInfo.widestStatus = widestStatus
963
898
statusWidthInfo.subordinateWidestStatus = subordinateWidestStatus
964
899
965
- return statusWidthInfo;
900
+ return statusWidthInfo
966
901
967
902
}
968
903
@@ -980,7 +915,64 @@ class StatusView @JvmOverloads constructor(
980
915
981
916
}
982
917
918
+
919
+ /* *
920
+ * checks if a flagSet contains a flag
921
+ *
922
+ */
923
+
924
+ private fun containsFlag (flagSet : Int , flag : Int ): Boolean {
925
+ return flagSet or flag == flagSet
926
+ }
927
+
928
+
983
929
private fun currentCountIndex () = currentCount- 1
930
+
984
931
private fun statusCountIndex () = statusCount- 1
985
932
933
+
934
+ /* *
935
+ * Delegate property used to requestLayout if any value changed
936
+ */
937
+ inner class OnLayoutProp <T > (private var field : T , private inline var func : ()-> Unit ={}){
938
+ operator fun setValue (thisRef : Any? ,p : KProperty <* >,v : T ) {
939
+ field = v
940
+ if (ViewCompat .isLaidOut(this @StatusView)){
941
+ drawingData.clear()
942
+ func()
943
+ requestLayout()
944
+
945
+ }
946
+
947
+ }
948
+ operator fun getValue (thisRef : Any? ,p : KProperty <* >):T {
949
+ return field
950
+ }
951
+
952
+ }
953
+
954
+ /* *
955
+ * Delegate Property used to invalidate a layout after executing a custom function
956
+ */
957
+ inner class OnValidateProp <T > (private var field : T , private inline var func : ()-> Unit ={}){
958
+ operator fun setValue (thisRef : Any? ,p : KProperty <* >,v : T ) {
959
+ field = v
960
+ if (ViewCompat .isLaidOut(this @StatusView)){
961
+ func()
962
+ invalidate()
963
+
964
+ }
965
+
966
+ }
967
+ operator fun getValue (thisRef : Any? ,p : KProperty <* >):T {
968
+ return field
969
+ }
970
+
971
+ }
972
+
973
+ private fun Float.pxValue (unit : Int = TypedValue .COMPLEX_UNIT_DIP ):Float {
974
+ return TypedValue .applyDimension(unit,this ,resources.displayMetrics)
975
+ }
976
+
977
+
986
978
}
0 commit comments