Skip to content

Commit

Permalink
Adding functionality of displayTimeUnits
Browse files Browse the repository at this point in the history
  • Loading branch information
rehmanmuradali committed May 11, 2020
1 parent 1ac21de commit b7669fe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
app:m_arc_stroke_color="@android:color/white"
app:m_circle_stroke_color="@color/colorPrimary"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
/>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public class CircularView extends AppCompatTextView {

// Show Text or not
private boolean shouldDisplayTimer = true;
private boolean shouldDisplayTimeUnit = true;

//Timer Callback
private CircularViewCallback circularViewCallback;
Expand Down Expand Up @@ -225,9 +226,14 @@ private void setTextOfTextViewWithSeconds(long value) {
unit = "\nseconds";
}

int highlightedTextLength = numberString.length();
if (shouldDisplayTimeUnit) {
numberString += unit;
}

//To resize the text size according to length
SpannableString spannableString = new SpannableString(numberString + unit);
spannableString.setSpan(new RelativeSizeSpan(getTextProportion(numberString)), 0, numberString.length(), 0);
SpannableString spannableString = new SpannableString(numberString);
spannableString.setSpan(new RelativeSizeSpan(getTextProportion(numberString)), 0, highlightedTextLength, 0);

if (shouldDisplayTimer) {

Expand Down Expand Up @@ -399,6 +405,7 @@ public void setOptions(OptionsBuilder optionBuilder) {
this.circularViewCallback = optionBuilder.circularViewCallback;
this.shouldDisplayTimer = optionBuilder.shouldDisplayTimer;
this.customText = optionBuilder.customText;
this.shouldDisplayTimeUnit = optionBuilder.shouldDisplayTimeUnit;
setTextOfTextViewWithSeconds(counterInSeconds);
}

Expand All @@ -410,6 +417,7 @@ public static class OptionsBuilder {
private boolean shouldDisplayTimer = true;
private String customText = null;
private long counterInSeconds = INFINITE;
private boolean shouldDisplayTimeUnit = true;


public OptionsBuilder setCircularViewCallback(CircularViewCallback circularViewCallback) {
Expand All @@ -436,6 +444,11 @@ public OptionsBuilder setCounterInSeconds(long counterInSeconds) {
return this;
}

public OptionsBuilder shouldDisplayTimeUnit(boolean shouldDisplayTimeUnit) {
this.shouldDisplayTimeUnit = shouldDisplayTimeUnit;
return this;
}


}

Expand Down

0 comments on commit b7669fe

Please sign in to comment.