Skip to content

Commit 4c0b5c1

Browse files
author
Parminder
committed
dev: Typeface support added
1 parent cc1e326 commit 4c0b5c1

7 files changed

Lines changed: 68 additions & 12 deletions

File tree

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

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.content.Context
44
import android.graphics.*
55
import android.graphics.drawable.Drawable
66
import android.support.annotation.FloatRange
7+
import android.support.v4.content.res.ResourcesCompat
78
import android.support.v4.view.ViewCompat
89
import android.text.Layout
910
import android.text.StaticLayout
@@ -250,6 +251,30 @@ class StatusView @JvmOverloads constructor(
250251
mTextPaintStatus.textSize = textSizeStatus
251252
}
252253

254+
/**
255+
* Text Font of statuses
256+
*/
257+
258+
var statusTypeface:Typeface? by OnLayoutProp(null){
259+
statusTypeface?.run {
260+
mTextPaintStatus.typeface = this
261+
}
262+
263+
}
264+
265+
/**
266+
* Text Font of Labels
267+
*/
268+
269+
var labelsTypeface:Typeface? by OnLayoutProp(null){
270+
labelsTypeface?.run {
271+
mTextPaintLabels.typeface = this
272+
mTextPaintLabelsIncomplete.typeface = this
273+
mTextPaintLabelCurrent.typeface = this
274+
}
275+
276+
}
277+
253278
/**
254279
* A boolean which decides if to draw labels or not
255280
*/
@@ -412,6 +437,24 @@ class StatusView @JvmOverloads constructor(
412437
}
413438
}
414439

440+
try {
441+
val resource: Int = a.getResourceId(R.styleable.StatusView_statusFont, -1)
442+
if (resource != -1) {
443+
statusTypeface = ResourcesCompat.getFont(getContext(), resource)
444+
}
445+
} catch (e: Exception) {
446+
e.printStackTrace()
447+
}
448+
449+
try {
450+
val resource: Int = a.getResourceId(R.styleable.StatusView_labelFont, -1)
451+
if (resource != -1) {
452+
labelsTypeface = ResourcesCompat.getFont(getContext(), resource)
453+
}
454+
} catch (e: Exception) {
455+
e.printStackTrace()
456+
}
457+
415458

416459
} finally {
417460
a.recycle()
@@ -434,16 +477,19 @@ class StatusView @JvmOverloads constructor(
434477
mTextPaintStatus.textAlign = Paint.Align.CENTER
435478
mTextPaintStatus.color = textColorStatus
436479
mTextPaintStatus.textSize = textSizeStatus
437-
438-
480+
statusTypeface?.run {
481+
mTextPaintStatus.typeface = this
482+
}
439483

440484
mLinePaintIncomplete = Paint(mLinePaint)
441485
mLinePaintIncomplete.color = lineColorIncomplete
442486

443487
mLinePaintCurrent = Paint(mLinePaint)
444488
mLinePaintCurrent.color = lineColorCurrent
445489

446-
mTextPaintLabels = TextPaint(mTextPaintStatus)
490+
mTextPaintLabels = TextPaint(Paint.ANTI_ALIAS_FLAG)
491+
mTextPaintLabels.style = Paint.Style.FILL
492+
mTextPaintLabels.textAlign = Paint.Align.CENTER
447493
mTextPaintLabels.textSize = textSizeLabels
448494
mTextPaintLabels.color = textColorLabels
449495

@@ -454,6 +500,13 @@ class StatusView @JvmOverloads constructor(
454500
mTextPaintLabelCurrent = TextPaint(mTextPaintLabels)
455501
mTextPaintLabelCurrent.color = textColorLabelCurrent
456502

503+
labelsTypeface?.run {
504+
mTextPaintLabels.typeface = this
505+
mTextPaintLabelsIncomplete.typeface = this
506+
mTextPaintLabelCurrent.typeface = this
507+
}
508+
509+
457510

458511
}
459512

@@ -533,7 +586,7 @@ class StatusView @JvmOverloads constructor(
533586
}
534587

535588
if(isShowingCurrentStatus()){
536-
extraWidth += (currentStatusRadius-circleRadius)*2;
589+
extraWidth += (currentStatusRadius-circleRadius)*2
537590
}
538591

539592

@@ -838,7 +891,7 @@ class StatusView @JvmOverloads constructor(
838891
circleRadius = currentStatusRadius
839892
}
840893

841-
return (2 * circleRadius + circleStrokeWidth) + lineWidth;
894+
return (2 * circleRadius + circleStrokeWidth) + lineWidth
842895
}
843896

844897
private fun minStatusWidthExtremes(pos:Int): Float {
45.5 KB
Binary file not shown.
123 KB
Binary file not shown.

app/src/main/res/font/pt_sans.ttf

387 KB
Binary file not shown.

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@
2424
app:circleColorType="fillStroke"
2525
app:statusCount="3"
2626
app:currentCount="1"
27-
app:lineLength="5dp"
28-
app:circleRadius="30dp"
29-
app:minStatusMargin="20dp"
27+
app:lineLength="25dp"
28+
app:circleRadius="25dp"
3029
app:obeyLineLength="false"
3130
app:currentStatusZoom="0.0"
3231
app:drawCount="true"
33-
app:textSize="20sp"
32+
app:statusFont="@font/bree_serif"
33+
app:labelFont="@font/pt_sans"
34+
app:textSize="15sp"
3435
app:current_drawable="@drawable/ic_tag_faces_black_24dp"
3536
app:lineColor="@android:color/holo_red_dark"
3637
android:entries="@array/statuses"/>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
<attr name="minStatusMargin" format="dimension"/>
4040
<attr name="labelTopMargin" format="dimension"/>
4141
<attr name="currentStatusZoom" format="float"/>
42+
<attr name="statusFont" format="reference"/>
43+
<attr name="labelFont" format="reference"/>
4244
<attr name="android:entries" />
4345
</declare-styleable>
4446

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>pamewqeqwe</item>
7-
<item>pamewqeqwe</item>
8-
<item>pamDewqe</item>
6+
<item>On the way</item>
7+
<item>Arriving</item>
8+
<item>Delivered</item>
99
</string-array>
1010
</resources>

0 commit comments

Comments
 (0)