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-19199] Android: Picker has 'selectionOpens' property to contro… #6982

Merged
merged 2 commits into from Aug 14, 2015

Conversation

ashcoding
Copy link
Contributor

@ashcoding
Copy link
Contributor Author

New property selectionOpens for Picker.
Test Code:-

// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');

// create tab group
var tabGroup = Titanium.UI.createTabGroup();


//
// create base UI tab and root window
//
var win1 = Titanium.UI.createWindow({  
    title:'Fruit',
    backgroundColor:'#fff'
});
var tab1 = Titanium.UI.createTab({  
    icon:'KS_nav_views.png',
    title:'Fruit',
    window:win1
});

var label1 = Titanium.UI.createLabel({
    color:'#999',
    text:'Pick a fruit',
    font:{fontSize:20,fontFamily:'Helvetica Neue'},
    textAlign:'center',
    width:'auto'
});

win1.add(label1);

//
// create controls tab and root window
//
var win2 = Titanium.UI.createWindow({  
    title:'Veggies',
    backgroundColor:'#fff'
});
var tab2 = Titanium.UI.createTab({  
    icon:'KS_nav_ui.png',
    title:'Veggies',
    window:win2
});

var label2 = Titanium.UI.createLabel({
    color:'#999',
    text:'Pick a veggie',
    font:{fontSize:20,fontFamily:'Helvetica Neue'},
    textAlign:'center',
    width:'auto'
});

win2.add(label2);



//
//  add tabs
//
tabGroup.addTab(tab1);  
tabGroup.addTab(tab2);  


/*
    Code below adds a picker to the ActionBar with different options
    for each tab. In order to have different picker options on each
    tab, the picker is redrawn when you switch tabs but it maintains 
    the selection you chose previously.
*/
var activeTab = 0,
    selectedPickerRow = {
        tab0: 0,
        tab1: 0
    };
function doPickerChange(e) {
    if(activeTab === 0) {
        selectedPickerRow.tab0 = e.rowIndex;
        label1.text = 'You chose: ' + ((e.rowIndex) ? 'Banana' : 'Apple');
    } else {
        selectedPickerRow.tab1 = e.rowIndex;
        label2.text = 'You chose: ' + ((e.rowIndex) ? 'Beans' : 'Corn');
    }
}

tabGroup.addEventListener("open", function () {
    var activity = tabGroup.getActivity();
    activity.onCreateOptionsMenu = function (e) {
        var item, 
            settings,
            data = [],
            menu = e.menu, 
            picker = Ti.UI.createPicker({
                                // Changes for TIMOB-19199
                                // By default, this is set to true. Change this to false to see the changes.
                selectionOpens : false
            });
        menu.clear();
        if (activeTab === 0) {
            data.push(
                Ti.UI.createPickerRow({
                    title: 'Apple',
                    value: '0'
                }));
            data.push(
                Ti.UI.createPickerRow({
                    title: 'Banana',
                    value: '1'
                }));
            picker.add(data);
            picker.addEventListener('change', doPickerChange);
            item = menu.add({
                title: "Apple",
                showAsAction: Ti.Android.SHOW_AS_ACTION_ALWAYS
            });
            item.actionView = picker;
            picker.setSelectedRow(0, selectedPickerRow.tab0, false); //  column, row, [animated]
        } else {
            data.push(
                Ti.UI.createPickerRow({
                    title: 'Corn',
                    value: '0'
                }));
            data.push(
                Ti.UI.createPickerRow({
                    title: 'Beans',
                    value: '1'
                }));
            picker.add(data);
            picker.addEventListener('change', doPickerChange);
            item = menu.add({
                title: "Corn",
                showAsAction: Ti.Android.SHOW_AS_ACTION_ALWAYS
            });
            item.actionView = picker;
            picker.setSelectedRow(0, selectedPickerRow.tab1, false); //  column, row, [animated]
        }
    };
    activity.invalidateOptionsMenu();
});

function redrawMenu() {
    var activity = tabGroup.getActivity();
    activity.invalidateOptionsMenu();
}
tabGroup.addEventListener("focus", function (e) {
    activeTab = e.index;
    redrawMenu();
});


// open tab group
tabGroup.open();

@@ -461,7 +461,9 @@ private void handleSelectRow(int column, int row, boolean animated)
return;
}
((TiUIPicker)peekView()).selectRow(column, row, animated);
((TiUIPicker)peekView()).openPicker();
if (TiConvert.toBoolean(getProperty("selectionOpens"), true)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please create TiC constant for "selectionOpens"

@hieupham007
Copy link
Contributor

Code reviewed and functionally tested. This works for expanding the picker, but when set to true, Tim's issue regarding graphical glitch still persist.

@ashcoding
Copy link
Contributor Author

Comment on TiC addressed.

With regards to the usage of this. In Tim's scenario (if I'm not mistaken), it is not suppose to be expanded when it is initially started. It is only selected. Thus, with this fix, a person can set the selection without having it expanded. I think this solves his issue of having it expanded from the start. This also happens to solve the glitch issue for him as it is not expanded and appearing at the top.

I think this should address the issue for the user. @hieupham007, do you think we should look more into glitch or would this fix be suffice for now?

@hieupham007
Copy link
Contributor

This does not solve it from the start, since the default value is "true". We can either disable this option completely (i.e "false" all the time), or look into this weird glitch.

@hieupham007
Copy link
Contributor

Any update on this?

@ashcoding
Copy link
Contributor Author

I'll set this default to false.

@ashcoding
Copy link
Contributor Author

@hieupham007 Updated it to be false by default.

@ashcoding
Copy link
Contributor Author

Just a note, Travis CI build is failing due to a separate unrelated Grunt issue. Other then that, it is compiling correctly. See this Travis CI build log for more info https://travis-ci.org/appcelerator/titanium_mobile/builds/75535697#L8500

@hieupham007
Copy link
Contributor

Looks good. Merging

hieupham007 added a commit that referenced this pull request Aug 14, 2015
[TIMOB-19199] Android: Picker has 'selectionOpens' property to contro…
@hieupham007 hieupham007 merged commit 7d210cb into tidev:master Aug 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants