Skip to content

Draws Labels inside the circles #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 33 additions & 16 deletions app/src/main/java/params/com/statusView/StatusView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,14 @@ class StatusView @JvmOverloads constructor(
* A boolean which decides if to draw labels or not
*/

var drawCount: Boolean by OnValidateProp(false){
setDrawingDimensions()
}

/**
* A boolean which decides if labels should be written inside
*/

var drawLabels: Boolean by OnValidateProp(false){
Copy link
Owner

@params-ing params-ing Nov 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I see you are reusing the old variable drawLabels for new functionality.
This might make sense, but on a newer version people already using the library would get unexpected views & might be confused.
Can you instead create a new variable drawStatusInsideCircle & keep the old one as it is

setDrawingDimensions()
}
Expand Down Expand Up @@ -429,6 +437,7 @@ class StatusView @JvmOverloads constructor(
incompleteDrawable = a.getDrawable(R.styleable.StatusViewScroller_incompleteDrawable)
currentDrawable = a.getDrawable(R.styleable.StatusViewScroller_currentDrawable)
drawLabels = a.getBoolean(R.styleable.StatusViewScroller_drawLabels, drawLabels)
drawCount = a.getBoolean(R.styleable.StatusViewScroller_drawCount, drawCount)
strictObeyLineLength = a.getBoolean(R.styleable.StatusViewScroller_strictObeyLineLength, strictObeyLineLength)
lineGap = a.getDimension(R.styleable.StatusViewScroller_lineGap, lineGap)
minStatusAdjacentMargin = a.getDimension(R.styleable.StatusViewScroller_minStatusAdjacentMargin, minStatusAdjacentMargin)
Expand Down Expand Up @@ -768,31 +777,39 @@ class StatusView @JvmOverloads constructor(
val circleItem = CircleItem(PointF((lastPoint.x + circleRadius), lastPoint.y), circleRadius, circleStrokePaint, circleFillPaint)
lastPoint.x += ((circleRadius) * 2.0f) + (circleStrokeWidth / 2)

if(pos<statusData.size){
if(!drawLabels && pos < statusData.size){
val radii = if(isShowingCurrentStatus() && alignStatusWithCurrent) currentStatusRadius else circleRadius
labelItemText = StatusItemText(circleItem.center.x, circleItem.center.y + radii + circleStrokeWidth/2 + statusTopMargin, statusData[pos].staticLayout)
}



if (itemDrawable != null) {
val width = itemDrawable.intrinsicWidth
val height = itemDrawable.intrinsicHeight
val xPos = circleItem.center.x.toInt()
val yPos = circleItem.center.y.toInt()
val drawableRect = Rect(xPos - width / 2, yPos - height / 2, xPos + width / 2, yPos + height / 2)
statusItemText = LabelItemText(drawableItem = DrawableItem(drawableRect, itemDrawable))
when {
itemDrawable != null -> {
val width = itemDrawable.intrinsicWidth
val height = itemDrawable.intrinsicHeight
val xPos = circleItem.center.x.toInt()
val yPos = circleItem.center.y.toInt()
val drawableRect = Rect(xPos - width / 2, yPos - height / 2, xPos + width / 2, yPos + height / 2)
statusItemText = LabelItemText(drawableItem = DrawableItem(drawableRect, itemDrawable))
}

} else if (drawLabels) {
val text: String = (pos + 1).toString()
val measuringRect = Rect()
textPaintLabel.getTextBounds(text, 0, text.length, measuringRect)
statusItemText = LabelItemText(text, textPaintLabel, circleItem.center.x, circleItem.center.y - measuringRect.exactCenterY())
drawLabels -> {
val text: String = statusData[pos].text
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

statusData[pos].text, this might crash, can you please place a safety check

val measuringRect = Rect()
textPaintLabel.getTextBounds(text, 0, text.length, measuringRect)
statusItemText = LabelItemText(text, textPaintLabel, circleItem.center.x, circleItem.center.y - measuringRect.exactCenterY())
}

drawCount -> {
val text: String = (pos + 1).toString()
val measuringRect = Rect()
textPaintLabel.getTextBounds(text, 0, text.length, measuringRect)
statusItemText = LabelItemText(text, textPaintLabel, circleItem.center.x, circleItem.center.y - measuringRect.exactCenterY())
}
}

drawingData.add(Item(statusItemText, circleItem, lineItem,labelItemText))

drawingData.add(Item(statusItemText, circleItem, lineItem, labelItemText))
}


Expand Down Expand Up @@ -1120,4 +1137,4 @@ class StatusView @JvmOverloads constructor(
}
}

}
}
5 changes: 3 additions & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
app:layout_constraintEnd_toEndOf="parent"
app:stepCount="5"
app:currentCount="4"
app:drawLabels="true"
app:drawLabels="false"
app:drawCount="true"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also can you check if status data is longer like
"ABCD" does it exceed the circle or looks okay.
Actually it does, so we might have to handle it
Screen Shot 2019-11-17 at 5 29 01 PM

android:entries="@array/status"
app:circleColorType="fillStroke"
app:lineGap="5dp"
Expand All @@ -43,4 +44,4 @@



</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
3 changes: 2 additions & 1 deletion app/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<attr name="currentDrawable" format="reference"/>
<attr name="incompleteDrawable" format="reference"/>
<attr name="drawLabels" format="boolean"/>
<attr name="drawCount" format="boolean"/>
<attr name="strictObeyLineLength" format="boolean"/>
<attr name="lineGap" format="dimension"/>
<attr name="minStatusAdjacentMargin" format="dimension"/>
Expand All @@ -46,4 +47,4 @@
</declare-styleable>


</resources>
</resources>