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
[TIMOB-1618] Android: Expose "minimumFontSize" on Android (Parity) #8724
Conversation
# Conflicts: # android/modules/ui/src/java/ti/modules/titanium/ui/LabelProxy.java
Added minimumFontSize property with the same behaviour as on iPhone
Added property minimumFontSize
Implemented parity behaviour for the property minimumFontSize on Android.
Correction: replaced missing font padding implementation
Added import declarations.
Renamed PROPERTY_MINIMUM_FONT_SIZE
if (tv != null) { | ||
if (autoshrinkSetFontSize != null) { | ||
if (tv.getTextSize() == TiConvert.toFloat(autoshrinkSetFontSize)) { | ||
if (propertySetFontSize != null ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use getFontProperties()
instead? Making propertySetFontSize
redundant.
String[] fontProperties = TiUIHelper.getFontProperties(proxy.getProperties());
if (fontProperties.length > TiUIHelper.FONT_SIZE_POSITION && fontProperties[TiUIHelper.FONT_SIZE_POSITION] != null) {
tv.setTextSize(TiUIHelper.getSizeUnits(fontProperties[TiUIHelper.FONT_SIZE_POSITION]), TiUIHelper.getSize(fontProperties[TiUIHelper.FONT_SIZE_POSITION]));
} else {
tv.setTextSize(TiUIHelper.getSizeUnits(null), TiUIHelper.getSize(null));
}
|
||
TextPaint textPaint = tv.getPaint(); | ||
if (textPaint != null) { | ||
float stringWidth = textPaint.measureText((tv.getText()).toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary brackets around (tv.getText())
if (textPaint != null) { | ||
float stringWidth = textPaint.measureText((tv.getText()).toString()); | ||
int textViewWidth = tv.getWidth(); | ||
if (textViewWidth < stringWidth && stringWidth != 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... && stringWidth > 0
int textViewWidth = tv.getWidth(); | ||
if (textViewWidth < stringWidth && stringWidth != 0) { | ||
float fontSize = (textViewWidth / stringWidth) * tv.getTextSize(); | ||
autoshrinkSetFontSize = fontSize > TiConvert.toFloat(minimumFontSize) ? String.valueOf(fontSize) : minimumFontSize; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TiConvert.toFloat(minimumFontSize, 0)
Comments addressed! Not sure about the |
@@ -49,6 +51,9 @@ | |||
private float shadowX = 0f; | |||
private float shadowY = 0f; | |||
private int shadowColor = Color.TRANSPARENT; | |||
private String minimumFontSize = null; | |||
private String propertySetFontSize = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be removed
@@ -207,6 +257,9 @@ public void processProperties(KrollDict d) | |||
tv.setHighlightColor(TiConvert.toColor(d, TiC.PROPERTY_HIGHLIGHTED_COLOR)); | |||
} | |||
if (d.containsKey(TiC.PROPERTY_FONT)) { | |||
if ((d.getKrollDict(TiC.PROPERTY_FONT)).containsKey("fontSize")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be removed
} else if (key.equals(TiC.PROPERTY_FONT)) { | ||
if (((HashMap) newValue).containsKey("fontSize")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be removed
@garymathews PR updated. Happy new year! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Important note: I suggest we add the same fix to TextField
|
||
/** | ||
* Method used to decrease the fontsize of the text to fit the width | ||
* fontsize should be >= than the property minimumFontSize |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keeping in format with other descriptions and docs:
- change >= into greater than or equal to like for maxAge and other examples. This is the description so it's supposed to be wordy?
type: Number | ||
platforms: [iphone, ipad] | ||
since: {iphone: "0.8.0", ipad: "0.8.0", android: "6.1.0"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- place android part first in
since: {...}
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
other examples always have android first. I think it's in alphabetical order
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, it's random. Usually the API added first comes first and the new one is added to it. But there're really no guidelines for that one.
@@ -166,8 +166,13 @@ properties: | |||
summary: Minimum font size when the font is sized based on the contents. | |||
description: | | |||
Enables font scaling to fit and forces the label content to be limited to a single line. | |||
|
|||
On Android, setting this property will force the `ellipsize` property to be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keeping in format with existing docs:
- make
ellipsize
into link to property link? - either edit into or append
default: <Titanium.UI.TEXT_ELLIPSIZE_TRUNCATE_END> on Android
...and so and so behavior on iOS, etc...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we can link it. But the default value suggestion should not be done, since the default is undefined, so behaving as not set. Otherwise it confuse the developers if they should set TEXT_ELLIPSIZE_*
constants instead of font-sizes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry my bad, did review twice, first time added this comment. "lost" first review so inputted comments again then it looked like I had two reviews. Removed new and updated second review and this was left I guess from first time... 👍
/** | ||
* @module.api | ||
*/ | ||
public static final String PROPERTY_MINIMUM_FONT_SIZE = "minimumFontSize"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keeping in format with TiC:
- properties are in alphabetical order so place after PROPERTY_MIN_AGE.
- refactor to
PROPERTY_MIN_FONT_SIZE
likePROPERTY_MIN_AGE
. not sure whyPROPERTY_MIN_AGE
,PROPERTY_MIN_UPDATE_DISTANCE
,PROPERTY_MIN_UPDATE_TIME
do not have@module.api
tag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has to be PROPERTY_MINIMUM_FONT_SIZE
. The constants are based on the camel case name that injects _
chars instead of the camel-case style.
type: Number | ||
platforms: [iphone, ipad] | ||
since: {iphone: "0.8.0", ipad: "0.8.0", android: "6.1.0"} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- remove new line.
* fontsize should be >= than the property minimumFontSize | ||
* @param view | ||
*/ | ||
private void adjustTextFontSize(View v){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- refactor variable to
view
or change@param view
to@param v
Good idea to also implement it on the text field. @fmerzadyan do you want to take-over the PR? I just did some cleanup, the deep-dive should be done by an Android Pro :-) |
@hansemannn haha ~ not that good but sure 👍 |
CR and FT passed |
FR Passed.
Appc Studio : 4.8.1.201612050850 |
@hansemannn , What about the Will merge the PR once this is confirmed. EDIT: Talked this with frakie & he pointed me to a ticket TIMOB-24298 already created for this. |
I think @m1ga talked about that a while ago, but for this specific 6.1.0 ticket, we will go with the labels first. |
JIRA: https://jira.appcelerator.org/browse/TIMOB-1618
Continuing from #5909, thank you @lgolu!