Titanium Appcelerator Video Player Back Button on Android - titanium

I am new to Titanium App Development. I am making a title list of videos using a ListView. When I click on an item, the specific video plays fine. However when I press the back button in Android, the application exits instead of going back to the previous list of videos. I have tried android:back and androidback event of the window but still the same. How should I fix this??? By the way I am using the Alloy Framework in Titanium
index.js
videos.fetch({query: 'select * from '+ videos.config.adapter.collection_name + ' where video_id = '+ vid_id});
var args;
for (var vd=0 ; vd < videos.length; vd++){
var e = JSON.parse(JSON.stringify(videos.at(vd)));
args = {
parent_id : lsn_sub,
video_data : e.video_data
};
console.log(args.video_data);
var mediaview = Alloy.createController("media", args).getView();
mediaview.open();
media.js
var parent_view = args.parent_id;
var vid_media = args.video_data;
console.log("parent source: "+parent_view);
console.log($.vid_media.url);
$.vid_media.url = vid_media ;
$.media.addEventListener('androidback', function(e){
alert("android back");
});
views/media.xml
<Alloy>
<Window class="container">
<VideoPlayer id="vid_media" ns="Ti.Media" ></VideoPlayer>
</Window>
The back button exits the application, not going back to previous screen.

Set the model property of your second window true.
<SecondWindow class="container" modal="true"></SecondWindow>
Also set modal and exitOnClose true on your first window if you want to close the app when user press android back on your first screen.
<FirstWindow class="container" modal="true" exitOnClose></FirstWindow >
there is no to add android:back event for it.
Hope this will help you

Thank you for the great help #suraj and #victor, but I figured it out already.
The reason for it to be not working is because I was testing it only in the simulator, not on a real device. When I run it on the real device, the 'back button' of the android actually works fine. It stops my video and goes back to the previous screen.
We should really test on a real device rather than relying on a simulator. Have a great day! :)

Another possible solution
is to cancel the bubbling effect of the androidback event,
$.media.addEventListener('androidback', function(e) {
e.cancelBubble = true;
[...Your logic here...]
}

Related

appcelerator how close the window of index from another window

everyone
I am using titanium with alloy, I have two windows which are index.js and main.js.
The window of index.js will be opened when the app run, there is a button in index, main will be opened if someone click the button. Main have another button which is used to close the index.
As you see, I am trying to close index window in main window.
Everything works fine in IOS, but when I test it in Android, I found a strange problem: when I click the button in main.js to close index window, all windows(both of index and main) are closed.
I tried many methods, like use Ti.APP.trigger/Ti.APP.addEventListener and send $.index or a callback function to main.js.
Could anyone help me, thanks.
in index.js use this
$.index.exitOnClose = false
Your solution is to set this property : exitOnClose = false as answered by #genocsb. It's available only on Android.
Actually, this property tells that which window should close the app upon closing the window itself. So, by default, the very first window has the its property exitOnClose = true.
In your case, do something like this:
- index.js
Alloy.Globals.Index = $.index;
Alloy.Globals.Index.open();
// If you will do this and press back button on index screen, then you will land to splash screen.
// Alloy.Globals.Index.exitOnClose = false;
- main.js
$.button.addEventListener('click', function (){
$.main.exitOnClose = true; // setting it to true will cause your app to close from main.xml screen on back button press
Alloy.Globals.Index.exitOnClose = false; // setting it to false here will ensure that you will not land to splash screen if back button is pressed.
Alloy.Globals.Index.close();
Alloy.Globals.Index = null;
});

bootstrap show.bs.modal event won't fire

I have a problem with my modal events. None of them I tested worked.
I'm using Bootstrap 3.3.6 and I tested my code in a jsfiddle and everything is working well there.
Here's my js :
$('#delete').on('show.bs.modal', function(e) {
var title = $(e.relatedTarget).data('title');
var id = $(e.relatedTarget).data('id');
document.getElementById('id').value = id;
document.getElementById('title').innerHTML = title;
});
I have no errors in my console, the modal shows up but the event isn't fired. I've tried show, shown and loaded.
Thank you for your help
Before asking this question, I haven't tested the .modal('show) method.
I got an error and after few checkups it's because I had two different versions of Jquery.
Problem solved after removing one.

Durandal view no more displayed if user click quickly on menus

I use Durandal 2.0 & Breeze in my SPA.
I have a sidebar menu for my drivers (Chauffeurs) where user can click on submenus (Récents, Disponibles, Indisponibles) for calling my view with different parameters. This will fill a koGrid with data. The data is fetched in the activate call and the binding of the koGrid is done in the compositionComplete.
Everything goes well most of the time. Things goes wrong when I click very quickly on submenus (calling the same view). Example: I click on 'Récents' and immediately (without waiting for the view to display) I click on 'Disponibles'.
I have the following for the activate:
var activate = function (filterParam) {
filter(filterParam);
pagedDataSource.getDataFunction = getData;
pagedDataSource.getPredicatesFunction = getPredicates;
return pagedDataSource.reload();
};
And I have the following code for the compositionComplete:
var compositionComplete = function (view) {
bindEventToList(view, '.kgCellText', gotoDetails);
$('#mySearchGrid').attr('data-bind', 'koGrid: gridOptions');
ko.applyBindings(vm, document.getElementById('mySearchGrid'));
};
When I trace the activity, I noted that if user click quickly on submenus, the activate does not have the time to finish and is called again (for the second click of the user) and the compositionComplete does not execute. Then after that, nothing more happened visually. It seems blocked.
Any idea how can I prevent this problem?
Thanks.
The migration to the latest Durandal version 2.0.1 fixed the problem.

Unable to move cursor to position 0 in Titanium.UI.TextArea

I have a TextArea in a modal Window. When the modal window is displayed, I want the focus to be set to this TextArea. I also want the TextArea to have default text when it is displayed & the cursor to be at the beginning of this text.
I call focus() on TextArea when modal window is displayed & in the focus() handler, I set the text that I want & call setSelection(0, 0) to move the cursor to position 0.
This doesn't seem to be working as the cursor remains at the end of the set text.
I am using the latest version of the SDK.
It would be great if someone could help me fix this issue. Thanks!
Titanium SDK: 3.0.2 Target platform: IOS only
Here's the code:
// 'statusUpdateArea' is my TextArea
$.tabbedBarNav.addEventListener('click',function(e)
{
statusUpdateArea.focus();
}
statusUpdateArea.addEventListener('focus',function()
{
statusUpdateArea.setValue(" - I am here'");
//API to set cursor at beginning doesn't work!!!!!! [or I don'tknow how to use it :( ]
statusUpdateArea.setSelection(0, 0);
});
Don't focus. setSelection will focus the text area for you. Focusing is preventing the selection from being properly set. Uncomment the .focus call to see it not work.
Try the following. It works for me on iOS with Titanium SDK 3.x.
var win = Ti.UI.createWindow({
backgroundColor: '#fff'
});
var textArea = Ti.UI.createTextArea({
value: 'Some text.'
});
win.add(textArea);
win.addEventListener('open', function(evt) {
// textArea.focus();
textArea.setSelection(0, 0);
});
win.open();
Use hintText for default..You cant set the text like that.. actual setSelection is not for cusor movement . it is used to select a part of value in text field...so u cant use that method...use hint text and let the user to type ..later on u can add the default text to value of text feild it might be useful..
I got the answer to this on the Appcelerator dev forum. There seems to be a bug with the implementation on IOS:
Appcelerator Dev forum

SharePoint 2010 Modal Dialog from JSOM not working

The idea is simple: create a web part page in SP Designer 2010 that allows a new list item to be created, and then use some javascript from the CSOM to pop the page in a modal dialog from another page. The problem is that a dialog box comes up and briefly flashes that it is loading content, but then it disappears and I'm left with a refreshed version of the page I just clicked from. Here's my code . . .
//attach a click delegate to the table containing the following button(s)
<button type='button' class='ms-listheaderlabel'>Close</button>
//on button clicked event, call the following function
function openModalDialog(dialogPage, closeCallback) {
var options = [];
options.title = unescape("Close Ticket");
options.allowMaximize = true;
options.showClose = true;
options.autoSize = true;
options.url = dialogPage;
options.dialogReturnValueCallback = Function.createDelegate(null, closeCallback);
SP.UI.ModalDialog.showModalDialog(options);
};
. . . where dialogPage is the url for the form I created (same site, SitePages library) and closeCallback is an anonymous function passed in to handle the return value from the dialog. I've tried calling the page directly and it loads just fine. Pop up blocker is completely off. Using IE9 and tried 8 compatability mode as well as another machine with straight IE8. System modals work just fine. Any ideas out there?
I am going through the exact same issue right now. What I have discovered so far is if I use
<input type="button" value="Try Me" onclick="openModalDialogBox()" />
it works as expected. But if I use an asp:button to do the same thing it fails. I think it may have to do with the postback to the server, but I could be wrong about that.
I am just switching my buttons to inputs.
Tim