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-26390] Android: Connect getters with background drawables for Unit test purposes. #10393

Merged
merged 4 commits into from
May 2, 2019

Conversation

ypbnv
Copy link
Contributor

@ypbnv ypbnv commented Oct 23, 2018

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 with null. Also colors set with predefined words ( like "green", "cyan", "yellow" ) will now return the hexadecimal value with alpha channel. For instance setting a backgroundColor to blue 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

var win = Ti.UI.createWindow(),
	view = Ti.UI.createView({
		width: 100,
		height: 100,
		borderColor: 'green',
		borderWidth: 5,
		backgroundColor: 'red',
		backgroundSelectedColor: 'green',
		backgroundFocusedColor: 'blue',
		backgroundDisabledColor: 'gray'
	}),
	button = Ti.UI.createButton();

win.add(view);
win.add(button);

button.addEventListener('click', function () {
	Ti.API.info('backgroundColor is ' + view.getBackgroundColor());
	Ti.API.info('backgroundSelectedColor is ' + view.getBackgroundSelectedColor());
	Ti.API.info('backgroundFocusedColor is ' + view.backgroundFocusedColor);
	Ti.API.info('backgroundDisabledColor is ' + view.backgroundDisabledColor);
});
win.open();

@ypbnv ypbnv added this to the 7.5.0 milestone Oct 23, 2018
@keerthi1032
Copy link
Contributor

FR Passed. Waiting for CR and Merge. Hexadecimal values displayed for colors.
Test Environment:
Operating System
Name = Mac OS X
Version = 10.13.6
Architecture = 64bit
Node.js
Node.js Version = 8.12.0
npm Version = 6.4.1
Titanium CLI
CLI Version = 5.1.1
Titanium SDK
SDK Version = Local 7.5.0.v20181023053605 build
Device =Samsung s5 Android 6
Emulator = pixel android 7, Sony Xperia S android 4.1.1

@lokeshchdhry
Copy link
Contributor

@ypbnv , Can you please fix the unit test failures. Thanks.

@ypbnv
Copy link
Contributor Author

ypbnv commented Oct 25, 2018

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

@lokeshchdhry
Copy link
Contributor

@ypbnv , Did we finalize any approach for this PR ? Is it good to merge ?

@ypbnv
Copy link
Contributor Author

ypbnv commented Dec 3, 2018

@lokeshchdhry Not really.
@garymathews, @jquick-axway When you get the chance can you take a look at the note in the description?

"softKeyboardOnFocus",
"transform",
"elevation",
"touchTestId",
Copy link
Contributor

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

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

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

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

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

ypbnv and others added 2 commits May 1, 2019 13:50
…for TiView.

Replace Strings in property accessors list for Ti.View with proper constants.
@garymathews
Copy link
Contributor

CR: PASS

TEST CASE from #10744
  1. Build and run the below code on Android.
  2. Verify that the app does not crash on startup.
  3. Uncomment the 2 lines of code below.
  4. Rebuild and rerun the app on Android.
  5. Verify that the displayed TextField now has a gray background.
  6. In the log, verify that you see the following message. ("#FF888888" is the color "gray".)
    [INFO] : ### textField.backgroundDisabledColor: #FF888888
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));

@build
Copy link
Contributor

build commented May 1, 2019

Messages
📖

💾 Here's the generated SDK zipfile.

📖

✅ All tests are passing
Nice one! All 3727 tests are passing.
(There are 466 tests skipped)

Generated by 🚫 dangerJS against ca28331

@tidev tidev deleted a comment from build May 1, 2019
@garymathews
Copy link
Contributor

Reverted to returning the property string by default for parity and to satisfy our test cases.

@keerthi1032
Copy link
Contributor

FR Passed.Works as expected.
Test Environment:
Operating System
Name = Mac OS X
Version = 10.13.6
Architecture = 64bit
Node.js
Node.js Version = 8.9.1
npm Version = 5.5.1
Titanium CLI
CLI Version = 5.1.1
Titanium SDK
SDK Version = local sdk 8.1.0.v20190501153539
CLI =7.0.11-1
Studio =5.1.2.201903111843
Device =Samsung s5 android 6,pixel android 9
Emulator =pixel 3xl android 9

@keerthi1032 keerthi1032 merged commit 3d1569d into tidev:master May 2, 2019
vijaysingh-axway pushed a commit to vijaysingh-axway/titanium_mobile that referenced this pull request May 3, 2019
…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
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

7 participants