Skip to content
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

Merged
merged 15 commits into from Jan 27, 2017

Conversation

hansemannn
Copy link
Collaborator

lgolu and others added 9 commits December 30, 2016 12:27
# 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
@garymathews garymathews self-requested a review December 31, 2016 01:58
if (tv != null) {
if (autoshrinkSetFontSize != null) {
if (tv.getTextSize() == TiConvert.toFloat(autoshrinkSetFontSize)) {
if (propertySetFontSize != null ) {
Copy link
Contributor

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());
Copy link
Contributor

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) {
Copy link
Contributor

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;
Copy link
Contributor

Choose a reason for hiding this comment

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

TiConvert.toFloat(minimumFontSize, 0)

@hansemannn
Copy link
Collaborator Author

hansemannn commented Dec 31, 2016

Comments addressed! Not sure about the fontProperties change, but the reason makes sense.

@@ -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;
Copy link
Contributor

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")) {
Copy link
Contributor

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")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be removed

@hansemannn
Copy link
Collaborator Author

@garymathews PR updated. Happy new year!

Copy link
Contributor

@frankieandone frankieandone left a 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
Copy link
Contributor

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"}
Copy link
Contributor

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: {...}.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Why?

Copy link
Contributor

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

Copy link
Collaborator Author

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
Copy link
Contributor

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...

Copy link
Collaborator Author

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.

Copy link
Contributor

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";
Copy link
Contributor

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 like PROPERTY_MIN_AGE. not sure why PROPERTY_MIN_AGE, PROPERTY_MIN_UPDATE_DISTANCE, PROPERTY_MIN_UPDATE_TIME do not have @module.api tag.

Copy link
Collaborator Author

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"}

Copy link
Contributor

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){
Copy link
Contributor

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

@hansemannn
Copy link
Collaborator Author

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 :-)

@frankieandone
Copy link
Contributor

@hansemannn haha ~ not that good but sure 👍

@frankieandone
Copy link
Contributor

CR and FT passed

@lokeshchdhry
Copy link
Contributor

FR Passed.
The minimumFontSize property works fine.
Checked it by code below:

var win = Ti.UI.createWindow({});

var label = Ti.UI.createLabel({
	text:"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
	textColor:'white',
	minimumFontSize:8
});

win.add(label);
win.open();
  1. Checked with different values for minimumFontSize.
  2. Checked it in portrait & landscape mode.
  3. Checked it for alloy app.
    The text scales automatically to the minimum font size specified for the minimumFontSize & works as expected.

Appc Studio : 4.8.1.201612050850
SDK Version : local 6.1.0
Mac OS Version : 10.12.2
Xcode Version : Xcode 8.2.1 Build version 8C1002
Appc CLI AND Appc NPM : {"NPM":"4.2.9-1","CLI":"6.1.0"}
Ti CLI : 5.0.11
Alloy : 1.9.5
Node : v4.6.0
Nexus 6 running 6.0.1, Nexus 6P running 7.1.1 & android emulator 5.1.1

@lokeshchdhry
Copy link
Contributor

lokeshchdhry commented Jan 27, 2017

@hansemannn , What about the minimumFontSize property for textField for android. Are we gonna expose it as well ?

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.

@hansemannn
Copy link
Collaborator Author

I think @m1ga talked about that a while ago, but for this specific 6.1.0 ticket, we will go with the labels first.

@lokeshchdhry lokeshchdhry merged commit 21af827 into tidev:master Jan 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants