Skip to content
This repository was archived by the owner on May 3, 2021. It is now read-only.

Commit 7e85506

Browse files
committed
Text size bug fix
Affected all lowercase and first word uppoer case modes
1 parent 2aede08 commit 7e85506

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

app/src/main/java/com/layoutxml/twelveish/MyWatchFace.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import android.support.wearable.complications.rendering.ComplicationDrawable;
3535
import android.support.wearable.watchface.CanvasWatchFaceService;
3636
import android.support.wearable.watchface.WatchFaceStyle;
37-
import android.util.Log;
3837
import android.util.SparseArray;
3938
import android.view.SurfaceHolder;
4039
import android.view.WindowInsets;
@@ -53,7 +52,6 @@
5352

5453
public class MyWatchFace extends CanvasWatchFaceService {
5554
private static Typeface NORMAL_TYPEFACE = Typeface.create("sans-serif-light", Typeface.NORMAL);
56-
private static final String TAG = "MyWatchFace";
5755

5856
private static final long INTERACTIVE_UPDATE_RATE_MS = TimeUnit.SECONDS.toMillis(1);
5957
private static final int MSG_UPDATE_TIME = 0;
@@ -620,6 +618,7 @@ public void onVisibilityChanged(boolean visible) {
620618
unregisterReceiver();
621619
}
622620
updateTimer();
621+
significantTimeChange = true;
623622
}
624623

625624
private void registerReceiver() {
@@ -710,6 +709,7 @@ public void onAmbientModeChanged(boolean inAmbientMode) {
710709
mTextPaint2.setColor(mainColor);
711710
}
712711
updateTimer();
712+
significantTimeChange = true;
713713
}
714714

715715
@Override
@@ -884,16 +884,16 @@ else if (hourText > 12 && !militaryTextTime)
884884
}
885885
float textSize;
886886
if (!complicationLeftSet && !complicationRightSet) {
887-
textSize = getTextSizeForWidth(bounds.width() - 32, (firstSeparator > bounds.height() / 4 + mChinSize) ? bounds.height() - 2 * firstSeparator - 32 : bounds.height() / 2 - mChinSize - 32, text2, true);
887+
textSize = getTextSizeForWidth(bounds.width() - 32, (firstSeparator > bounds.height() / 4 + mChinSize) ? bounds.height() - firstSeparator - bounds.height()/4 - 32 : bounds.height() / 2 - mChinSize - 32, text2, true);
888888
x = bounds.width() / 2;
889889
} else if (complicationLeftSet && !complicationRightSet) {
890-
textSize = getTextSizeForWidth(bounds.width() * 3 / 4 - 24, (firstSeparator > bounds.height() / 4 + mChinSize) ? bounds.height() - 2 * firstSeparator - 32 : bounds.height() / 2 - mChinSize - 32, text2, false);
890+
textSize = getTextSizeForWidth(bounds.width() * 3 / 4 - 24, (firstSeparator > bounds.height() / 4 + mChinSize) ? bounds.height() - firstSeparator - bounds.height()/4 - 32 : bounds.height() / 2 - mChinSize - 32, text2, false);
891891
x = bounds.width() * 5 / 8 - 16;
892892
} else if (!complicationLeftSet && complicationRightSet) {
893-
textSize = getTextSizeForWidth(bounds.width() * 3 / 4 - 24, (firstSeparator > bounds.height() / 4 + mChinSize) ? bounds.height() - 2 * firstSeparator - 32 : bounds.height() / 2 - mChinSize - 32, text2, false);
893+
textSize = getTextSizeForWidth(bounds.width() * 3 / 4 - 24, (firstSeparator > bounds.height() / 4 + mChinSize) ? bounds.height() - firstSeparator - bounds.height()/4 - 32 : bounds.height() / 2 - mChinSize - 32, text2, false);
894894
x = bounds.width() * 3 / 8 + 16;
895895
} else {
896-
textSize = getTextSizeForWidth(bounds.width() / 2 - 16, (firstSeparator > bounds.height() / 4 + mChinSize) ? bounds.height() - 2 * firstSeparator - 32 : bounds.height() / 2 - mChinSize - 32, text2, false);
896+
textSize = getTextSizeForWidth(bounds.width() / 2 - 16, (firstSeparator > bounds.height() / 4 + mChinSize) ? bounds.height() - firstSeparator - bounds.height()/4 - 32 : bounds.height() / 2 - mChinSize - 32, text2, false);
897897
x = bounds.width() / 2;
898898
}
899899
float y=0;
@@ -1214,6 +1214,7 @@ private void handleUpdateTimeMessage() {
12141214
}
12151215

12161216
private float getTextSizeForWidth(float desiredWidth, float desiredHeight, String text, boolean addMargin) {
1217+
text = text.toUpperCase();
12171218
float min = Integer.MAX_VALUE, linecount = 0;
12181219
for (String line : text.split("\n")) {
12191220
if (!line.equals(""))
@@ -1231,13 +1232,6 @@ private float getTextSizeForWidth(float desiredWidth, float desiredHeight, Strin
12311232
if (desiredTextSize2 < min)
12321233
min = desiredTextSize2;
12331234
}
1234-
Paint newPaint = mTextPaint2;
1235-
newPaint.setTextSize(min);
1236-
while (newPaint.measureText("|", 0, "|".length()) / 5 > 6) { //6 is the burn in protection shifting limit in pixels
1237-
min -= 2;
1238-
newPaint.setTextSize(min);
1239-
}
1240-
Log.d(TAG,"linecount "+linecount);
12411235
return min;
12421236
}
12431237
}

0 commit comments

Comments
 (0)