appcelerator createwindow makes the whole window black - titanium

I'm using the Titanium to develop an iOS app. I have a main window and I need to open a modal window above it.
I put on the modal window (attached the code) a textArea and two buttons for save and cancel.
The problem is when I open the window, the whole window is turned black.
What do I do wrong? Thanks...
addEvenButton.addEventListener('click', function() {
var eventDesc = '';
var t = Titanium.UI.create2DMatrix();
t = t.scale(0);
var noteWin = Titanium.UI.createWindow({
backgroundColor : '#b4be00',
borderWidth : 8,
borderColor : '#999',
height : 460,
width : 325,
borderRadius : 10,
opacity : 0.92,
modal: true,
transform : t
});
// create first transform to go beyond normal size
var t1 = Titanium.UI.create2DMatrix();
t1 = t1.scale(1.1);
var a = Titanium.UI.createAnimation();
a.transform = t1;
a.duration = 1000;
// when this animation completes, scale to normal size
a.addEventListener('complete', function() {
var t2 = Titanium.UI.create2DMatrix();
t2 = t2.scale(1.0);
noteWin.animate({
transform : t2,
duration : 200
});
});
var noteField = Titanium.UI.createTextArea({
color : 'black',
hintText : 'Enter text description here',
suppressReturn:false,
height : 200,
top : 100,
width : 250,
keyboardType : Titanium.UI.KEYBOARD_NAMEPHONE_PAD,
returnKeyType : Titanium.UI.RETURNKEY_DEFAULT,
borderStyle : Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});
// create a button to close window
var closeButton = Titanium.UI.createButton({
title : 'Save text',
height : 40,
left : 40,
top : 50,
width : 100
});
// create a button to close window
var cancelButton = Titanium.UI.createButton({
title : 'Cancel',
height : 40,
left : 180,
top : 50,
width : 100
});
noteWin.add(noteField);
noteWin.add(closeButton);
noteWin.add(cancelButton);
closeButton.addEventListener('click', function() {
var t3 = Titanium.UI.create2DMatrix();
t3 = t3.scale(0);
noteWin.close({
transform : t3,
duration : 300
});
addEvent('Event', noteField.value);
});
cancelButton.addEventListener('click', function() {
var t3 = Titanium.UI.create2DMatrix();
t3 = t3.scale(0);
noteWin.close({
transform : t3,
duration : 300
});
});
noteWin.addEventListener('singletap', function(e) {
noteField.blur();
});
noteWin.addEventListener('open', function(e) {
noteField.focus();
});
noteWin.open(a);
});

Try to add the "zIndex:1000" property to the modal window to make sure that it is not hidden by another one.

Related

Auto suggest dropdown in titanium example?

I am able to implement auto suggest drop down in jquery .Now I am implementing a same functionality in titanium but when i googled I don't found much in autosuggestion
drop down in titanium .
can you suggest a way of autogestion.
Mean I have a array (element).When I click on textfield it show related element.
Try the following code and modify as per your need. Here I Used array(searchArray) as data storage(You can replace it with database field or source whatever as per your requirement).
//Table view showing your autocomplete values
var tblvAutoComplete = Ti.UI.createTableView({
width : '100%',
backgroundColor : '#EFEFEF',
height : 0,
maxRowHeight : 35,
minRowHeight : 35,
allowSelection : true
});
//Starts auto complete
txtAutoComplete.addEventListener('change', function(e){
var pattern = e.source.value;
var tempArray = PatternMatch(searchArray, pattern);
CreateAutoCompleteList(tempArray);
});
//You got the required value and you clicks the word
tblvAutoComplete.addEventListener('click', function(e){
txtAutoComplete.value = e.rowData.result;
});
//Returns the array which contains a match with the pattern
function PatternMatch(arrayToSearch, pattern){
var searchLen = pattern.length;
arrayToSearch.sort();
var tempArray = [];
for(var index = 0, len = arrayToSearch.length; index< len; index++){
if(arrayToSearch[index].substring(0,searchLen).toUpperCase() === pattern.toUpperCase()){
tempArray.push(arrayToSearch[index]);
}
}
return tempArray;
}
//setting the tableview values
function CreateAutoCompleteList(searchResults){
var tableData = [];
for(var index=0, len = searchResults.length; index < len; index++){
var lblSearchResult = Ti.UI.createLabel({
top : 2,
width : '40%',
height : 34,
left : '5%',
font : { fontSize : 14 },
color : '#000000',
text : searchResults[index]
});
//Creating the table view row
var row = Ti.UI.createTableViewRow({
backgroundColor : 'transparent',
focusable : true,
height : 50,
result : searchResults[index]
});
row.add(lblSearchResult);
tableData.push(row);
}
tblvAutoComplete.setData(tableData);
tblvAutoComplete.height = tableData.length * 35;
}
This code worked for me in both ios and android. Hope your problems get resolved:D

someView.visible = true not working in Titanium

I have a view that is set to show when a button is clicked.
This works but only if the button has been clicked once already.
So it works but not as it should eg. the first time the button is clicked.
I add the view to tableView as soon as it is created later in the code BTW.
here is some code to look at...
var vLabel = Ti.UI.createView({
backgroundColor : 'white',
width : '100%',
height : 46,
bottom : 25
});
var topBorderView = Ti.UI.createView({
backgroundColor : '#d8d8d8',
width : '100%',
height : 1,
top : 0
});
var aLabel = Ti.UI.createLabel({
backgroundColor : 'white',
objName : 'aLabel',
text : "All Points - Takes a few moments to load.",
font : {
fontSize : 12
},
color : '#df0101',
backgroundPaddingTop : 5,
backgroundPaddingBottom : 3,
left : '5%',
width : '90%',
height : 42,
top : 2,
zIndex : 6000,
textAlign : Ti.UI.TEXT_ALIGNMENT_CENTER
});
vLabel.add(topBorderView);
vLabel.add(aLabel);
sortButton.addEventListener('click', function(e) {
vLabel.visible = 1;
vLabel.show();
var loaders = getLoader();
tableView.add(loaders);
loaders.start();
var tempRows = [];
if (content.uid == 998) {
if (e.index == 0) {
tempRows = sortAllPoints(content, e.index);
loaders.stop();
vLabel.visible = false;
tableView.remove(loaders);
tableView.setData(tempRows, {
animationStyle : Titanium.UI.iPhone.RowAnimationStyle.NONE
});
rowMainData = tableView.data;
SearchBar.value = '';
} else {
tempRows = sortAllPoints(content, e.index);
loaders.stop();
vLabel.visible = false;
tableView.remove(loaders);
tableView.setData(tempRows, {
animationStyle : Titanium.UI.iPhone.RowAnimationStyle.NONE
});
rowMainData = tableView.data;
SearchBar.value = '';
}
}
});
Anyone have any clue as to why the view is showing on the 2nd button click but not the first??
Everything else works as it should eg. the loader animation
Thanks a lot,
George.
Lateral Thinking! That's what you need. I had set the position of the view to be relative the bottom of the tableView. This worked while there was nothing in the table eg. it was loading or sorting the content. The answer was to make it's position relative to the top therefore no matter whether the content was being loaded or being sorted it is always visible. Sleep is good for this sort of thing!
use setVisible method:
someView.setVisible = true

Remain data that input in text field

My case is that I want to remain/save entered data on text field and will make a drop down list of my previous entered data when I click on the text field and also if i close and open back the application, the entered data will still be in the drop down list. Example, i entered "abc123" in the text field and i press enter on a button, it will save "abc123" in the drop down list of the text field and if i quit the application and enter again, "abc123" will still be in the drop down list.
var win = Ti.UI.createWindow({
backgroundColor: 'white',
});
var txtfield = Ti.UI.createTextField({
});
var btn = Ti.UI.createButton({
title: 'go'
});
win.add(btn);
win.add(txtfield);
win.open();
You'll need to save the values to SQLite or Ti.App.Properties.
Here is a working example :
var win = Ti.UI.createWindow({
backgroundColor : 'white',
layout : 'vertical'
});
var txtfield = Ti.UI.createTextField({
width : Ti.UI.FILL,
height : Ti.UI.SIZE,
hintText : 'Enter new values...',
top : 0
});
var picker = Ti.UI.createPicker({
top : 10
});
var data = (Ti.App.Properties.hasProperty('itemList')) ? Ti.App.Properties.getList('itemList') : [];
Ti.API.info('data is ' + data);
var m = [];
if (data)
data.forEach(function(item) {
m.push(Ti.UI.createPickerRow({title:item}));
});
Ti.API.info('M is ' + m);
if (m.length > 0)
picker.add(m);
var btn = Ti.UI.createButton({
top : 10,
width : Ti.UI.SIZE,
height : Ti.UI.SIZE,
title : 'go'
});
btn.addEventListener('click', function(e) {
var s = [];
if (Ti.App.Properties.hasProperty('itemList')) {
Ti.API.info('Property found');
s = Ti.App.Properties.getList('itemList');
}
Ti.API.info('S is ' + s);
s.push(txtfield.value);
Ti.App.Properties.setList('itemList', s);
picker.add(Ti.UI.createPickerRow({title:txtfield.value}));
txtfield.value = '';
});
win.add(btn);
win.add(txtfield);
win.add(picker);
win.open();
Definitely recommend to use sessionStorage or localStorage

I can't get my video to play in Titaniums Titanium.Media.createVideoPlayer AP

Using the Titanium.Media.createVideoPlayer API in Android 2.2 can't get the video to play in Titanium 2.1.2 using a Ti.UI.currentWindow.
/**
* #author David
*/
var win = Ti.UI.currentWindow;
//var win = Ti.UI.createWindow({});
var contentURL = "http://assets.appcelerator.com.s3.amazonaws.com/video/media.m4v";
var openButton = Ti.UI.createButton({
title : "Start Video",
top : "0dp",
height : "40dp",
left : "10dp",
right : "10dp"
});
openButton.addEventListener('click', function() {
var activeMovie = Titanium.Media.createVideoPlayer({
url : contentURL,
backgroundColor : 'blue',
movieControlMode : Titanium.Media.VIDEO_CONTROL_DEFAULT,
scalingMode : Titanium.Media.VIDEO_SCALING_ASPECT_FILL,
fullscreen : true,
autoplay : true
});
var closeButton = Ti.UI.createButton({
title : "Exit Video",
top : "0dp",
height : "40dp",
left : "10dp",
right : "10dp"
});
closeButton.addEventListener('click', function() {
activeMovie.hide();
activeMovie.release();
activeMovie = null;
});
activeMovie.add(closeButton);
});
win.add(openButton);

how i add View Array in my scrollView(in Android support)?

i am new App Developer with Titanium. i want to create a window base application. whose run on iphone or ipad or android platform.
When i run application on iphone than run properly, but when i run on Android than it show a msg (Unexpected Error) and after this it is close.
var win1 = Titanium.UI.createWindow({
backgroundColor : '#f0f0f0',
});
var view1 = Titanium.UI.createView({
height : 100,
width : 100,
backgroundColor : '#ff0000',
borderColor : '#000',
});
var scrollView1 = Titanium.UI.createScrollView({
contentHeight : 150,
backgroundColor : '#00ff00',
});
var abc = new Array();
abc[0] = 'images/img.png',
abc[1] = 'images/img1.png',
scrollView1.add(abc);
view1.add(scrollView1);
win1.add(view1);
win1.open();
how i add Array in my scroll view.
in array i store (images path)
please help me,
Thanks in advance,
Try This,
var array = new Array();
array[0] = 'image path';
array[1] = 'image path';
for(a = 0; a<array.length;a++){
var lab1 = Titanium.UI.createLabel({
backgroundImage : array1[a],
height : 75,
width : 75,
backgroundColor : '#712347',
borderRadius : '10',
zIndex : 11,
});
scrLabel.add(lab1);
}
I, Think this is supported, for you.
You can't 'add' an array to a window object - 'add' only takes Titanium Proxy objects - things returned from Ti.UI.create.... methods - as the argument. See my commented code below:
var win1 = Titanium.UI.createWindow({
backgroundColor : '#f0f0f0',
});
var view1 = Titanium.UI.createView({
height : 100,
width : 100,
backgroundColor : '#ff0000',
borderColor : '#000',
});
var scrollView1 = Titanium.UI.createScrollView({
contentHeight : 150,
backgroundColor : '#00ff00',
});
var abc = ['images/img.png', 'images/img1.png'];
// if you want the image paths available as a variable, just set it
scrollView1.abc = abc;
// But I don't understand why you are doing this - you can just access the paths
// from abc directly
view1.add(scrollView1);
// You were adding the scroll view twice: win1.add(scrollView1);
// You want to add the view:
win1.add(view1);
win1.open();
Try this code:
var win1 = Titanium.UI.createWindow({
backgroundColor : '#f0f0f0'
});
var view1 = Titanium.UI.createView({
height : 100,
width : 100,
backgroundColor : '#ff0000',
borderColor : '#000'
});
var scrollView1 = Titanium.UI.createScrollView({
contentHeight : 150,
backgroundColor : '#00ff00'
});
var abc = ['images/img.png','images/img1.png'];
scrollView1.add(abc);
view1.add(scrollView1);
win1.add(view1);
win1.open();
var array = new Array();
array[0] = 'image path';
array[1] = 'image path';
for(a = 0; a<array.length;a++){
var lab1 = Titanium.UI.createImageView({
backgroundImage : array1[a],
height : 75,
width : 75,
backgroundColor : '#712347',
borderRadius : '10',
zIndex : 11,
});
scrLabel.add(lab1);
}