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-18053] Android: fix picker row text color #8651

Merged
merged 3 commits into from Dec 5, 2016

Conversation

frankieandone
Copy link
Contributor

@frankieandone frankieandone commented Dec 1, 2016

Last PR for issue didn't solve all bugs. Text color behaved weird if color not set for all rows.

TEST CASE
Comment and uncomment colors in each picker row.

var win = Ti.UI.createWindow({
    exitOnClose: true,
    layout: 'vertical',
    backgroundColor: 'black'
});

var picker = Ti.UI.createPicker({
    top: 50
});

var data = [];
data[0] = Ti.UI.createPickerRow({
    title: 'Bananas',
    color: 'yellow'
});
data[1] = Ti.UI.createPickerRow({
    title: 'Strawberries',
    // color: 'red'
});
data[2] = Ti.UI.createPickerRow({
    title: 'Mangos',
    color: 'orange'
});
data[3] = Ti.UI.createPickerRow({
    title: 'Grapes',
    // color: 'purple'
});

picker.add(data);
picker.selectionIndicator = true;

win.add(picker);
win.open();

EXPECTED
A picker row's text color should only be set if specified otherwise should be default color.

JIRA: https://jira.appcelerator.org/browse/TIMOB-18053

final int color = TiConvert.toColor(rowProxy.getProperties(), TiC.PROPERTY_COLOR);
tv.setTextColor(color);
} else {
tv.setTextColor(Color.WHITE);
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of defining the text color as white, it would be better to obtain the default color and set it back to that.

private static int defaultTextColor = 0;
...
public static class TiSpinnerAdapter<T> extends ArrayAdapter<T>
{
    ...
    private void styleTextView(int position, TextView tv) {
        ...
        if (rowProxy.hasProperty(TiC.PROPERTY_COLOR)) {
            // obtain default text color
            if (!defaultTextColor) {
                defaultTextColor = tv.getCurrentTextColor();
            }
            final int color = TiConvert.toColor(rowProxy.getProperties(), TiC.PROPERTY_COLOR);
            tv.setTextColor(color);
        } else {
            tv.setTextColor(defaultTextColor);
        }
    ...
...

@frankieandone
Copy link
Contributor Author

Updated.

@garymathews
Copy link
Contributor

Looks good, but since DEFAULT_TEXT_COLOR is not a constant it should use camel-case instead of snake-case.

@garymathews
Copy link
Contributor

CR: PASS
FT: PASS

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

2 participants