Skip to content

Commit

Permalink
Merge pull request #102 from vishalduggal/timob-13417
Browse files Browse the repository at this point in the history
[TIMOB-13417] Test cases for timob-13417
  • Loading branch information
srahim committed May 15, 2013
2 parents 012ec04 + 347e149 commit 3a4b2ba
Show file tree
Hide file tree
Showing 6 changed files with 405 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Resources/ui/common/baseui/list_views.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ function list_views(_args) {
var isValidVersion = (Ti.version >= '3.1.0');
var isValidPlatform = isAndroid || isIOS;

var validV2Version = (Ti.version >= '3.2.0');

var listViewDefined = true;
try {
var isdefined = (Ti.UI.LIST_ACCESSORY_TYPE_DETAIL);
Expand Down Expand Up @@ -95,6 +97,24 @@ function list_views(_args) {
]
performanceSection.setItems(performanceDataSet);
sections.push(performanceSection);

//See the validV2Version flag above
if (validV2Version) {
if (isIOS) {
var uienhancementsSection = Ti.UI.createListSection({ headerTitle: 'V2 UI Enhancements'});
var uienhancementsdataset = [
{properties: { title: 'Item Separators', itemId: 'list_v2_custom_separator', accessoryType: Ti.UI.LIST_ACCESSORY_TYPE_DETAIL, height:44}},
{properties: { title: 'Custom Headers & Footers', itemId: 'list_v2_custom_header_footer', accessoryType: Ti.UI.LIST_ACCESSORY_TYPE_DETAIL, height:44}},
{properties: { title: 'Custom Backgrounds', itemId: 'list_v2_custom_backgrounds', accessoryType: Ti.UI.LIST_ACCESSORY_TYPE_DETAIL, height:44}},
{properties: { title: 'Select & Deselect Item', itemId: 'list_v2_select_deselect', accessoryType: Ti.UI.LIST_ACCESSORY_TYPE_DETAIL, height:44}},
{properties: { title: 'Misc UI', itemId: 'list_v2_ui_misc', accessoryType: Ti.UI.LIST_ACCESSORY_TYPE_DETAIL, height:44}},
]
uienhancementsSection.setItems(uienhancementsdataset);
sections.push(uienhancementsSection);
} else {
//TODO Android Specific or remove above check
}
}

listView.setSections(sections);

Expand Down
59 changes: 59 additions & 0 deletions Resources/ui/common/baseui/listview/list_v2_custom_backgrounds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
function list_v2_custom_backgrounds(_args) {
var win = Ti.UI.createWindow({
title:'Custom Backgrounds',
layout:'vertical',
});

var button = Ti.UI.createButton({
left:20,
right:20,
title:'Toggle ListView'
})
win.add(button);

var data = [
{properties:{title:'bgColor red, selectionStyle BLUE', backgroundColor:'red', selectionStyle:Ti.UI.iPhone.ListViewCellSelectionStyle.BLUE}},
{properties:{title:'bgColor green, selectionStyle GRAY', backgroundColor:'green', selectionStyle:Ti.UI.iPhone.ListViewCellSelectionStyle.GRAY}},
{properties:{title:'bgColor cyan, selectionStyle NONE', backgroundColor:'cyan', selectionStyle:Ti.UI.iPhone.ListViewCellSelectionStyle.NONE}},
{properties:{title:'bgColor white, selectedBgColor green', backgroundColor:'white', selectedBackgroundColor:'green'}},
{properties:{title:'bgImage corkboard, selectionStyle BLUE', backgroundImage:'/images/corkboard.jpg', selectionStyle:Ti.UI.iPhone.ListViewCellSelectionStyle.BLUE}},
{properties:{title:'bgImage corkboard, selectedBgImage orangeBar', backgroundImage:'/images/corkboard.jpg', selectedBackgroundImage:'/images/slider_orangebar.png'}},
]

var actualData = [];
var i;
for (i=0; i<100; i++) {
actualData.push(data[i%6]);
}

var section1 = Ti.UI.createListSection();
section1.setItems(actualData);

var listView1 = Ti.UI.createListView({top:10});
listView1.setSections([section1]);

var section2 = Ti.UI.createListSection();
section2.setItems(actualData);

var listView2 = Ti.UI.createListView({style:Ti.UI.iPhone.ListViewStyle.GROUPED, top:10});
listView2.setSections([section2]);

win.add(listView1);

var isGrouped = false;

button.addEventListener('click',function(){
if(isGrouped == false) {
win.remove(listView1);
win.add(listView2);
} else {
win.remove(listView2);
win.add(listView1);
}
isGrouped = !isGrouped;
})

return win;
};

module.exports = list_v2_custom_backgrounds;
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
function list_v2_custom_header_footer(_args) {
var win = Ti.UI.createWindow({
title:'Custom Headers & Footers',
});

var listHeader = Ti.UI.createView({
layout:'horizontal',
height:Ti.UI.SIZE
})
var imageView = Ti.UI.createImageView({
left:5,
width:50,
height:50,
image:'/images/flower.jpg'
})
var label = Ti.UI.createLabel({
left:5,
width:Ti.UI.FILL,
text:'Custom header with an image and a label'
})

listHeader.add(imageView);
listHeader.add(label);

var listFooter = Ti.UI.createLabel({
text:'I am a custom list footer (just a label) but with color',
color:'red'
})

var section = Ti.UI.createListSection();
var data = [];
var i=1;
for (i=1; i<10; i++) {
data.push({properties:{title:'ROW '+i}})
}
section.setItems(data);

var sectionHeaderView = Ti.UI.createLabel({
backgroundColor:'magenta',
text:'I am a section header',
font:{ fontWeight: 'bold', size:'30' },
color: 'white',
width:Ti.UI.FILL,
height:'50 dp',
textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER
})

var sectionFooterView = Ti.UI.createLabel({
backgroundColor:'green',
text:'I am a section footer',
font:{ fontStyle: 'italic', size:'15' },
color: 'white',
width:Ti.UI.FILL,
height:'30 dp',
textAlign: Ti.UI.TEXT_ALIGNMENT_RIGHT
})

section.headerView = sectionHeaderView;
section.footerView = sectionFooterView;

var listView = Ti.UI.createListView({
headerView:listHeader,
footerView:listFooter
});

listView.setSections([section]);

win.add(listView);

return win;
};

module.exports = list_v2_custom_header_footer;
94 changes: 94 additions & 0 deletions Resources/ui/common/baseui/listview/list_v2_custom_separator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
function list_v2_custom_separator(_args) {
var win = Ti.UI.createWindow({
title:'Custom Separator',
layout:'vertical'
});

var platformName = Titanium.Platform.osname;
var isIOS = (platformName == 'iphone' || platformName == 'ipad');

var container = Ti.UI.createView({
layout:'vertical',
height:Ti.UI.SIZE
})

var actionContainer = Ti.UI.createView({
layout:'horizontal',
height:Ti.UI.SIZE
})

var b1 = Ti.UI.createButton({
width:'45%',
left:'2%',
title:'Change Style'
})

var b2 = Ti.UI.createButton({
width:'45%',
left:'4%',
title:'Change Color'
})

actionContainer.add(b1);
actionContainer.add(b2);

var statusLabel = Ti.UI.createLabel({
width:Ti.UI.FILL,
height:Ti.UI.SIZE
})

container.add(actionContainer);
container.add(statusLabel);

win.add(container);

var styleData = [Ti.UI.iPhone.ListViewSeparatorStyle.SINGLE_LINE, Ti.UI.iPhone.ListViewSeparatorStyle.NONE];
var colorData = ['gray','red','green','blue','yellow','transparent'];
var styleCounter = 0;
var colorCounter = 0;

function updateLabel()
{
var text = 'Separator Color is '+colorData[colorCounter]+' Separator Style is ';
if (styleCounter == 0) {
text += 'Single Line';
} else {
text += 'None'
}
statusLabel.text = text;
}

var data = [];
var i=1;
for (i=1; i<100; i++) {
data.push({properties:{title:'ROW '+i}})
}
var listSection1 = Ti.UI.createListSection();
listSection1.setItems(data);

var listView = Ti.UI.createListView({
separatorColor:colorData[colorCounter],
separatorStyle:styleData[styleCounter]
});
listView.setSections([listSection1]);
updateLabel();

win.add(listView);

b1.addEventListener('click',function(){
styleCounter = (styleCounter + 1) % styleData.length;
listView.separatorStyle = styleData[styleCounter];
updateLabel();
})

b2.addEventListener('click',function(){
colorCounter = (colorCounter + 1) % colorData.length;
listView.separatorColor = colorData[colorCounter];
updateLabel();
})

return win;

};

module.exports = list_v2_custom_separator;
85 changes: 85 additions & 0 deletions Resources/ui/common/baseui/listview/list_v2_select_deselect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
function genData(section)
{
var data = [];
for(i=0;i<10;i++){
data.push({properties:{title:'Section '+section+' Item '+i}})
}

return data;
}

function genSections()
{
var sections = [];
for(j=0;j<10;j++){
var section = Ti.UI.createListSection({headerTitle:'Section '+j});
section.setItems(genData(j));
sections.push(section);
}

return sections;
}


function list_v2_select_deselect(_args) {
var win = Ti.UI.createWindow({
title:'Select Deselect',
layout:'vertical'
});

var actionContainer = Ti.UI.createView({
layout:'horizontal',
height:Ti.UI.SIZE
})

var b1 = Ti.UI.createButton({
width:'45%',
left:'2%',
title:'Select Random'
})

var b2 = Ti.UI.createButton({
width:'45%',
left:'4%',
title:'Deselect',
enabled:false
})

actionContainer.add(b1);
actionContainer.add(b2);

win.add(actionContainer);

var listView = Ti.UI.createListView({
sections: genSections(),
top:10
})

win.add(listView);

var sectionIndex;
var itemIndex;

listView.addEventListener('itemclick',function(e){
sectionIndex = e.sectionIndex;
itemIndex = e.itemIndex;
b2.enabled = true;
});

b1.addEventListener('click',function(){
sectionIndex = Math.floor(Math.random()*173)%10;
itemIndex = Math.floor(Math.random()*83)%10;
listView.selectItem(sectionIndex,itemIndex);
b2.enabled = true;
})

b2.addEventListener('click',function(){
listView.deselectItem(sectionIndex,itemIndex);
b2.enabled = false;
})


return win;
}

module.exports = list_v2_select_deselect;

0 comments on commit 3a4b2ba

Please sign in to comment.