Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Rafael Bellotti
committed
Nov 28, 2017
0 parents
commit c7d2d89
Showing
4 changed files
with
321 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,226 @@ | ||
var ImageLib = require('imagelib'); | ||
|
||
var dropdownOptions = []; | ||
var defaultText = "Aguarde..."; | ||
var currentValue = -1; | ||
var callbackFunction = function(){}; | ||
|
||
$.initialize = function(options, newText,callback) | ||
{ | ||
dropdownOptions = []; | ||
|
||
dropdownOptions = options.slice(); | ||
dropdownOptions.splice(0,0,newText); | ||
|
||
callbackFunction = (typeof callback == "undefined") ? function(){} : callback; | ||
|
||
if (OS_IOS) | ||
{ | ||
var imageDropdownIcon = ImageLib.createFromFile("images/icon_arrow_down.png"); | ||
var imageViewDropdownIcon = imageDropdownIcon.getViewByWidth(20); | ||
|
||
$.viewDropdownIconHolder.add(imageViewDropdownIcon); | ||
$.labelFieldText.text = newText; | ||
defaultText = newText; | ||
|
||
dropdownOptions.push('Cancelar'); | ||
|
||
var cancelPosition = dropdownOptions.length - 1; | ||
|
||
optionDialog.setOptions(dropdownOptions); | ||
optionDialog.setCancel(cancelPosition); | ||
|
||
$.viewContainer.removeEventListener('click', eventFunctioniOS); | ||
$.viewContainer.addEventListener('click', eventFunctioniOS); | ||
|
||
$.viewDropdownIconHolder.removeEventListener('click',eventFunctioniOS); | ||
$.viewDropdownIconHolder.addEventListener('click',eventFunctioniOS); | ||
|
||
|
||
} | ||
|
||
else if (OS_ANDROID) | ||
{ | ||
|
||
|
||
$.pickerColumn.removeAllChildren(); | ||
|
||
for (var i = 0; i < dropdownOptions.length; i++) | ||
{ | ||
$.pickerColumn.addRow( Ti.UI.createPickerRow ( {title:dropdownOptions[i], color: "#666666"} ) ); | ||
} | ||
|
||
$.picker.removeEventListener('change', eventFunctionAndroid); | ||
$.picker.addEventListener('change', eventFunctionAndroid); | ||
|
||
$.picker.setSelectedRow(0, 1); | ||
$.picker.setSelectedRow(0, 0); | ||
} | ||
}; | ||
|
||
//Retorna -1 caso seja o valor padrão | ||
$.getDropdownValue = function() | ||
{ | ||
return currentValue; | ||
}; | ||
|
||
$.setDropdownValue = function(value) | ||
{ | ||
if (OS_IOS) | ||
{ | ||
for (var i = 0; i < dropdownOptions.length; i++) | ||
{ | ||
if (value == dropdownOptions[i]) | ||
{ | ||
currentValue = value; | ||
$.labelFieldText.text = currentValue; | ||
break; | ||
} | ||
|
||
} | ||
|
||
} | ||
else | ||
{ | ||
var pickerRow = dropdownOptions.indexOf(value); | ||
if (pickerRow != -1) | ||
{ | ||
currentValue = value; | ||
$.picker.setSelectedRow(0, pickerRow); | ||
} | ||
} | ||
}; | ||
|
||
$.getSelectedIndex = function() | ||
{ | ||
var index = dropdownOptions.indexOf(currentValue); | ||
return (OS_IOS) ? index : index - 1; | ||
}; | ||
|
||
$.setVisibility = function(value) | ||
{ | ||
var topValue = (value) ? 10 : 0; | ||
setTop(topValue); | ||
|
||
if (OS_IOS) | ||
{ | ||
var heightValue = (value) ? Ti.UI.SIZE : 0; | ||
|
||
$.viewContainer.setVisible(value); | ||
$.viewContainer.height = heightValue; | ||
} | ||
else if (OS_ANDROID) | ||
{ | ||
var heightValue = (value) ? 45 : 0; | ||
|
||
$.pickerWrapper.setVisible(value); | ||
$.pickerWrapper.height = heightValue; | ||
} | ||
}; | ||
|
||
function setTop(topValue) | ||
{ | ||
if (OS_IOS) | ||
{ | ||
$.viewContainer.top = topValue; | ||
} | ||
else if (OS_ANDROID) | ||
{ | ||
$.pickerWrapper.top = topValue; | ||
} | ||
} | ||
|
||
$.setLeft = function(left) | ||
{ | ||
if (OS_IOS) | ||
{ | ||
$.viewContainer.left = left; | ||
} | ||
else if (OS_ANDROID) | ||
{ | ||
$.pickerWrapper.left = left; | ||
} | ||
}; | ||
|
||
$.setWidth = function(width) | ||
{ | ||
if (OS_IOS) | ||
{ | ||
$.viewContainer.width = width; | ||
} | ||
else if (OS_ANDROID) | ||
{ | ||
$.pickerWrapper.width = width; | ||
} | ||
}; | ||
|
||
$.setTop = setTop; | ||
|
||
/*$.setPickerFont = function(font) | ||
{ | ||
$.pickerColumn.font = font; | ||
}*/ | ||
|
||
$.resetValue = function() | ||
{ | ||
if (OS_IOS) | ||
{ | ||
currentValue = defaultText; | ||
$.labelFieldText.text = currentValue; | ||
} | ||
else if (OS_ANDROID) | ||
{ | ||
currentValue = dropdownOptions[0]; | ||
$.picker.setSelectedRow(0, 0); | ||
} | ||
}; | ||
|
||
|
||
if (OS_ANDROID) | ||
{ | ||
function eventFunctionAndroid(event) | ||
{ | ||
if (event.rowIndex == 0) | ||
{ | ||
currentValue = -1; | ||
} | ||
else | ||
{ | ||
currentValue = dropdownOptions[event.rowIndex]; | ||
} | ||
|
||
callbackFunction(currentValue); | ||
} | ||
} | ||
|
||
else if (OS_IOS) | ||
{ | ||
var optionDialogSettings = { | ||
cancel: 0, | ||
options: ['Cancelar'], | ||
selectedIndex: 0, | ||
title: 'Selecione uma opção' | ||
}; | ||
|
||
var optionDialog = Ti.UI.createOptionDialog(optionDialogSettings); | ||
|
||
|
||
optionDialog.addEventListener('click', function (event) | ||
{ | ||
if (event.index != dropdownOptions.length - 1) | ||
{ | ||
currentValue = (event.index == 0) ? -1 : dropdownOptions[event.index]; | ||
$.labelFieldText.text = dropdownOptions[event.index]; | ||
|
||
callbackFunction(currentValue); | ||
} | ||
}); | ||
|
||
|
||
function eventFunctioniOS(event) | ||
{ | ||
optionDialog.show(); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
".container": | ||
{ | ||
height: "45", | ||
left: "5%", | ||
right:"5%", | ||
width:"90%", | ||
paddingLeft: 1 | ||
} | ||
|
||
".pickerBox": | ||
{ | ||
right: 45, | ||
height: 45, | ||
left: 1 | ||
} | ||
|
||
".pickerBox[platform=android]": | ||
{ | ||
// right: 7.5, | ||
//left: 5, | ||
width: "95%" | ||
} | ||
|
||
".pickerBox[platform=ios]": | ||
{ | ||
right: 53 | ||
} | ||
|
||
".horizontal": | ||
{ | ||
layout: "horizontal" | ||
} | ||
|
||
".fontLarge": | ||
{ | ||
font: | ||
{ | ||
fontSize:16 | ||
} | ||
} | ||
|
||
".foregroundBlue": | ||
{ | ||
color:"#366f90" | ||
} | ||
|
||
".foregroundBlack": | ||
{ | ||
color:"#666666" | ||
} | ||
|
||
".hintTextLightGray": | ||
{ | ||
hintTextColor:"#c4c4c4", | ||
} | ||
|
||
".borderCurved": | ||
{ | ||
borderRadius: 5 | ||
} | ||
|
||
".borderWhite": | ||
{ | ||
borderColor:"#fff" | ||
} | ||
|
||
".backgroundTransparent": | ||
{ | ||
backgroundColor:"transparent" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<Alloy> | ||
<View class="container borderCurved borderTransparent backgroundWhite" id="viewContainer" platform="ios" top="10"> | ||
<Label class="pickerBox fontLarge foregroundBlack backgroundTransparent" id="labelFieldText" text="Aguarde..."/> | ||
<View bubbleParent="false" class="backgroundTransparent" height="45" id="viewDropdownIconHolder" right="7.5" width="45"/> | ||
</View> | ||
<View class="container backgroundWhite borderCurved" id="pickerWrapper" platform="android" top="10"> | ||
<Picker class="pickerBox" id="picker"> | ||
<PickerColumn id="pickerColumn"/> | ||
</Picker> | ||
</View> | ||
</Alloy> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"id": "dropdownField", | ||
"name": "dropdownField", | ||
"description" : "Dropdown field for iOS and Android", | ||
"author": "Rafael Bellotti", | ||
"version": "1.0", | ||
"copyright":"Copyright (c) 2017", | ||
"license":"Public Domain", | ||
"min-alloy-version": "1.0", | ||
"min-titanium-version":"2.1", | ||
"tags":"", | ||
"platforms":"android,ios" | ||
} |