-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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-26390] Android: Connect getters with background drawables for Unit test purposes. #10393
Conversation
FR Passed. Waiting for CR and Merge. Hexadecimal values displayed for colors. |
@ypbnv , Can you please fix the unit test failures. Thanks. |
@lokeshchdhry Removing this out of 7.5.0. Will schedule it for 8.0.0, since we need to clarify what approach will be the most suitable for the PR's purpose. |
@ypbnv , Did we finalize any approach for this PR ? Is it good to merge ? |
@lokeshchdhry Not really. |
"softKeyboardOnFocus", | ||
"transform", | ||
"elevation", | ||
"touchTestId", |
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 change is removing "touchTestId", but that's probably fine since it's not referenced anywhere else in the code. Our iOS code doesn't have any references to it either.
return transcriptColorIntToString(((PaintDrawable) simpleDrawable).getPaint().getColor()); | ||
} | ||
// Get the backgroundDrawable background as a StateListDrawable. | ||
StateListDrawable stateListDrawable = ((StateListDrawable) simpleDrawable); |
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.
We need to do an instanceof
check on the StateListDrawable
to avoid the issue mentioned here...
#10744
if (state != TiUIHelper.BACKGROUND_DEFAULT_STATE_1) { | ||
return null; | ||
} | ||
return transcriptColorIntToString(((PaintDrawable) simpleDrawable).getPaint().getColor()); |
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.
We need to do an instanceof
check on PaintDrawable
.
Log.w(TAG, "Unable to access a method for reflection."); | ||
} catch (InvocationTargetException e) { | ||
Log.w(TAG, "Unable to invoke a method for reflection."); | ||
} |
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.
Let's catch all exceptions here as shown in my other PR.
I'll close my PR once this PR resolves the same issue.
public static String transcriptColorIntToString(int colorInt) | ||
{ | ||
return String.format("#%08X", 0xFFFFFFFF & colorInt); | ||
} |
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.
I think this function should be moved to our TiColorHelper
class.
And would you mind renaming the function from transcriptColorIntToString(int)
to hexStringFrom(int)
please?
I say this because Titanium also supports an "rgba(0,0,0,0)" color string as well, which if we were to support it in the future, I would name it rgbaStringFrom(int)
.
…for TiView. Replace Strings in property accessors list for Ti.View with proper constants.
CR: PASS TEST CASE from #10744
var window = Ti.UI.createWindow();
var textField = Ti.UI.createTextField({
value: "Hello World",
width: "80%",
color: "white",
backgroundColor: "black",
borderColor: "white",
// backgroundDisabledColor: "gray",
// enabled: false,
});
window.add(textField);
window.open();
Ti.API.info("### textField.backgroundDisabledColor: " + textField.backgroundDisabledColor);
Ti.API.info("### JSON.stringify(textField): " + JSON.stringify(textField)); |
|
Reverted to returning the property string by default for parity and to satisfy our test cases. |
FR Passed.Works as expected. |
…Unit test purposes. (tidev#10393) * Connect different color states with the colors in the Android object for TiView. Replace Strings in property accessors list for Ti.View with proper constants. * fix(android): rename methods and add validation * fix(android): formatting * fix(android): return property by default
JIRA: https://jira.appcelerator.org/browse/TIMOB-26390
Description:
Connect the getters for different color states for Ti.UI.View with the Android object representing it.
Extract the method for getting colors for state in Ti.UIHelper.
Expose the states we assign for custom background drawables.
Guard for backwards compatibility.
Replace the String properties in Ti.UI.View with the proper TiC constants.
NOTE: This introduces behavior that may be classified as "breaking". Prior to this PR color state properties that have not been defined would return
undefined
and now that is replaced withnull
. Also colors set with predefined words ( like "green", "cyan", "yellow" ) will now return the hexadecimal value with alpha channel. For instance setting abackgroundColor
toblue
will afterwards return the value#FF0000FF
. Please, let me know what do you think about these changes and if they need reworking, mention in the docs or anything that this PR is missing.The failed unit tests show pretty well what I had in mind with "breaking" change. Having a list with predefined color words for specific color values does solve the problem ( I personally don't like this approach because there may be a difference in naming specific color values across platforms** ). I see we have a defined color map, but it may need a bit of a rework to help in this case.
** A good example is Android - they are supporting both words "green" and "lime" according to their docs:
https://developer.android.com/reference/android/graphics/Color.html#parseColor(java.lang.String)
Which is great, but the result of the call of
Color.parseColor()
with both parameters is the same. Judging by the code it is more likely a bug, because there is no point in having two keys with the same value in their color map.Test case:
The added unit test should suffice, but here is a code sample
app.js