Skip to content

Commit 3429483

Browse files
author
Parminder
committed
dev: minStatusMargin added
1 parent 78d591e commit 3429483

5 files changed

Lines changed: 30 additions & 11 deletions

File tree

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/jugnoo/com/learningcustomvviews/StatusView.kt

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ class StatusView @JvmOverloads constructor(
7171
currentStatusRadius = circleRadius * (1 + value)
7272
}
7373

74+
/**
75+
* A min margin that there should be between every adjacent status Text
76+
* Note# This only applies if obeyLineLength is set to false
77+
*/
78+
var minMarginStatusText: Float by OnLayoutProp(10.0f.pxValue())
7479

7580
/**
7681
* Set true to obey Status Text i.e alphabets or words belonging to one line would not cross
@@ -335,7 +340,8 @@ class StatusView @JvmOverloads constructor(
335340
* Stores all the drawing data that is used while drawing on canvas
336341
*/
337342
private var drawingData = mutableListOf<Item>()
338-
private var currentStatusRadius:Float by OnLayoutProp(circleRadius);
343+
private var currentStatusRadius:Float by OnLayoutProp(circleRadius)
344+
private var lineLengthComputed = 0.0f
339345

340346

341347

@@ -376,6 +382,7 @@ class StatusView @JvmOverloads constructor(
376382
drawLabels = a.getBoolean(R.styleable.StatusView_drawCount, drawLabels)
377383
obeyLineLength = a.getBoolean(R.styleable.StatusView_obeyLineLength, obeyLineLength)
378384
lineGap = a.getDimension(R.styleable.StatusView_lineGap, lineGap)
385+
minMarginStatusText = a.getDimension(R.styleable.StatusView_minMarginStatus, minMarginStatusText)
379386
labelTopMargin = a.getDimension(R.styleable.StatusView_labelTopMargin, labelTopMargin)
380387

381388

@@ -518,6 +525,7 @@ class StatusView @JvmOverloads constructor(
518525
override fun getSuggestedMinimumWidth(): Int {
519526

520527

528+
lineLengthComputed = lineLength
521529
var extraWidth = if(obeyLineLength){
522530
setWidthDataForObeyingLineLength()
523531
}else{
@@ -533,7 +541,7 @@ class StatusView @JvmOverloads constructor(
533541
extraWidth *= 2
534542
}
535543

536-
return ((statusCount * (2 * (circleRadius + (circleStrokeWidth/2)))) + ((statusCount - 1) * ( lineLength + (lineGap * 2))) + extraWidth).toInt()
544+
return ((statusCount * (2 * (circleRadius + (circleStrokeWidth/2)))) + ((statusCount - 1) * ( lineLengthComputed + (lineGap * 2))) + extraWidth).toInt()
537545
}
538546

539547

@@ -686,7 +694,7 @@ class StatusView @JvmOverloads constructor(
686694
}
687695
}else{
688696
lastPoint.x += lineGap
689-
lineItem = LineItem(PointF(lastPoint.x, lastPoint.y), PointF(lastPoint.x + lineLength, lastPoint.y), linePaint)
697+
lineItem = LineItem(PointF(lastPoint.x, lastPoint.y), PointF(lastPoint.x + lineLengthComputed, lastPoint.y), linePaint)
690698
lastPoint.x = lineItem.end.x + lineGap + (circleStrokeWidth / 2)
691699
}
692700

@@ -771,17 +779,18 @@ class StatusView @JvmOverloads constructor(
771779

772780
val widestLineData: StatusTextWidthInfo = getStatusTextWidthInfo(statusData.map { it.text }, mTextPaintStatus)
773781

774-
lineLength += widestLineData.widestStatus.width - minStatusWidth(widestLineData.widestStatus.pos)
782+
lineLengthComputed += widestLineData.widestStatus.width - minStatusWidth(widestLineData.widestStatus.pos)
775783

776784
widestLineData.subordinateWidestStatus?.run {
777785
val minStatusWidth = minStatusWidth(pos)
778786

779787
if (width > minStatusWidth) {
780-
lineLength += width - minStatusWidth
788+
lineLengthComputed += width - minStatusWidth
781789
}
782790
}
783791

784792

793+
var addPadding = false
785794
for (pos in 0 until statusData.size) {
786795
val item = statusData[pos]
787796
when (pos) {
@@ -802,7 +811,15 @@ class StatusView @JvmOverloads constructor(
802811
}
803812
else -> item.width = widestLineData.widestStatus.width
804813
}
814+
if(minMarginStatusText> 0 && !addPadding && pos in 1 until statusData.size){
815+
if(minStatusWidth(pos)+minStatusWidth(pos-1) - (item.width+statusData[pos-1].width)<minMarginStatusText){
816+
addPadding = true
817+
}
805818

819+
}
820+
}
821+
if(addPadding){
822+
lineLengthComputed+= minMarginStatusText
806823
}
807824
return extraWidth
808825
}
@@ -811,7 +828,7 @@ class StatusView @JvmOverloads constructor(
811828
private fun minStatusWidth(pos:Int): Float {
812829

813830
var circleRadius = this.circleRadius
814-
val lineWidth = (lineLength + lineGap*2)
831+
val lineWidth = (lineLengthComputed + lineGap*2)
815832

816833
if(isShowingCurrentStatus() && pos==currentCountIndex()){
817834
circleRadius = currentStatusRadius

app/src/main/res/layout/activity_main.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525
app:statusCount="3"
2626
app:currentCount="1"
2727
app:circleRadius="30dp"
28+
app:minMarginStatus="20dp"
2829
app:lineLength="50dp"
29-
app:obeyLineLength="true"
30+
app:obeyLineLength="false"
3031
app:currentStatusZoom="0.0"
3132
app:drawCount="true"
3233
app:textSize="20sp"

app/src/main/res/values/attrs.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<attr name="drawCount" format="boolean"/>
3737
<attr name="obeyLineLength" format="boolean"/>
3838
<attr name="lineGap" format="dimension"/>
39+
<attr name="minMarginStatus" format="dimension"/>
3940
<attr name="labelTopMargin" format="dimension"/>
4041
<attr name="currentStatusZoom" format="float"/>
4142
<attr name="android:entries" />

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
<string name="customViewLabel">Fan Control</string>
44

55
<string-array name="statuses">
6-
<item>pamDreqwewqeq1i</item>
7-
<item>pamDreqwewqeqi</item>
8-
<item>pamDrqwwi</item>
6+
<item>pamDreeeeeee</item>
7+
<item>pamDreeeeeee</item>
8+
<item>pamDrqww</item>
99
</string-array>
1010
</resources>

0 commit comments

Comments
 (0)