Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all 8068 articles
Browse latest View live

WebView: detect close event (Facebook login stucks app on blank page)

$
0
0

Hi,

I'm trying to build a very basic app (Android) and I need to include a (remote) mobile website with Facebook login. I do it with a WebView, and my website uses the FB JS SDK.

The user is indeed prompted for his credentials when hitting the FB button. Yet, this creates a new window (a popup on desktop), that closes itself once the user has authorized the app. But "closing" the popup in a webview actually means that the screen goes blank and nothing happens (except a weird warning in loop: Unsafe JavaScript attempt to access frame with URL http://my.website.me/ from frame with URL https://m.facebook.com/dialog/oauth?access_token=PTEE...&app_id=XXX&client_id=XXX&display=touch&domain=my.website.me&e2e=%7B%7D&origin=2&redirect_uri=http%3A%2F%2Fstatic.ak.facebook.com%2Fconnect%2Fxd_arbiter%2Fxx.js%3Fversion%3D41%23cb%3Dfxxx%26domain%3Dmy.website.me%26origin%3Dhttp%253A%252F%252Fsmy.website.me%2Fxxx%26relation%3Dopener%26frame%3Dxxx&response_type=token%2Csigned_request&scope=public_profile%2Cemail&sdk=joey. Domains, protocols and ports must match.).

From there, I can hit the back button to return to my website but this is obviously an UX no-go.

So, I need either:

  • to detect the window.close event to redirect the user once he's logged in,
  • to find a better way to do this.

For the first option I can inject some JS in the FB login page with evalJS but I'm not sure how to transmit back the "I'm gonna close myself" event to Titanium. Docs say it's not possible but Titanium sees stuff happening on the webpage since my debug log shows the console.log output. So there is some kind of communication, how could I use it?

For the second option I'm open to any suggestion, of course!

The real goal here just being to log in with Facebook. (I don't want to use Titanium's Facebook API to pass some auth token to the website because if my user needs to share something later, the problem will be the same with the ShareDialog)

Thank you!


Textfield Magnifying Glass

$
0
0

magnify glass appears black , not all device in ios .

how to create an xml for this?

$
0
0

Cloud.Users.create({ email: 'test@mycompany.com', first_name: 'test_firstname', last_name: 'test_lastname', password: 'test_password', password_confirmation: 'test_password' }, function (e) { if (e.success) { var user = e.users[0]; alert('Success:\n' + 'id: ' + user.id + '\n' + 'sessionId: ' + Cloud.sessionId + '\n' + 'first name: ' + user.first_name + '\n' + 'last name: ' + user.last_name);

        Ti.AppProperties.setBool("isLoggedIn", true);
        Ti.AppProperties.setString("sessionId", Cloud.sessionId);


        $.login.close();

} else {
    alert('Error:\n' + ((e.error && e.message) || JSON.stringify(e)));
}

});

Problem with ti.cloudpush

$
0
0

Hi,

I have a problem to include module ti.cloudpush (for Android Notification with ACS). When I test this code

var CloudPush = require('ti.cloudpush');
var deviceToken = null;
I obtain this error (Console) [ERROR] : CloudpushModuleImplementation: (KrollRuntimeThread) [248,248] Problem parsingacs-push-api-url: java.net.MalformedURLException

CloudPush module is add to my tiApp project. In tiapp.xml

<property name="acs-oauth-secret-production" type="string">xxxxx</property>
    <property name="acs-oauth-key-production" type="string">xxxxx</property>
    <property name="acs-api-key-production" type="string">xxxxx</property>
    <property name="acs-oauth-secret-development" type="string">xxxxx</property>
    <property name="acs-oauth-key-development" type="string">xxxxx</property>
    <property name="acs-api-key-development" type="string">xxxxx</property>
    <property name="acs-api-key" type="string">xxxxx</property>
// I have hide my key & OAuth but it's good, because it work with iOS
[Test on device Nexus 5] + Alloy

Thanks for your help !

Alloy memory/context related issues

$
0
0

Hi,

I am working on an Android Alloy app that has two very weird issues and I was hoping that someone could give me a hand.

The app is using the com.tripvi.drawerlayout and that might be related although I am not sure how.

Problem 1:

Occasionally after starting the app clicking on a link to open another window with a call to Alloy.createController('newWindow') I get an error that Alloy has not been defined. The error appears to be because of me defining fonts and other screen parameters in newWindow.tss using Alloy.Globals.ThemeXXXX variables.

Killing and restarting the app makes everything work as expected. I have not figured out how to reliably reproduce this problem. It happens from time to time and only if the app has previously been exited from (exitOnClose=true in the main window for the app) and the app has not been removed from the Android's recent apps list.

The interesting thing is that the main screen shows up just fine with all of its content and there are plenty of styles that use Alloy.Globals.... references in it. Why would Alloy become undefined all of a sudden?

I have tried to override the android:back event and not allow the users to ever exit the app and that helps avoid the problem but it does not feel right.

Problem 2:

The main screen of the app has a ScrollView, which is populated at initial launch with some data. (Code very much like the example on how to use ScrollView instead of TableView). User activity refreshes the ScrollView from time to time and everything is working EXCEPT .... when the app is restarted (like with problem 1) it can no longer update the ScrollView unless the app is cleared from Android's recent apps list and started again.

To refresh the view in the controller for the main screen I use an event handler for my own event inside of which calls to $.scrollViewName.removeAllChildren() and $.scrollViewName.add() do the update of the scroll view.

I changed the code a bit to store $.scrollViewName into a global variable

Alloy.Globals.myScrollView = $.scrollViewName

and updated the refresh code to use the gloval variable instead.

That made things work regardless of how the app was started. I am not sure I understand why and it feels like it might offer a clue to what is behind Problem 1, which is why I have described it.

What is so special about removing the app from the Android's recent apps list? It would appear that when the user used the back button to exit the app it did not completely clean up something. and removing the app from the recent apps list cleans it up. Is there any way to address this?

It feels like something similar to finish() on current activity before exit would help but It is not a call to Ti.Android.currentActivity.finish() - I have tried that and did not change a thing.

Is it possible that the drawerlayout plugin is somehow responsible for this?

I have not provided any code examples because I am not really sure what to include. Problem 1 cannot be reproduced consistently - perhaps once every 10-15 times I start the app but never after fresh install.

Any suggestions as to what to look for?

Thank you much!

How to get html content remotely and open localy

$
0
0

I want to get the content remotely for a html page and open localy in the webview. But I want this html to have access to the Ti namespace, so it implies that the html must be running localy.

Have tried to create the webview passing the content as the "html" parameter, but Ti namespace doesnt work that way.

Then, I tried to write the content to a html file on Ti.Filesystem.applicationDataDirectory. The page opens OK, but the Ti namespace doesnt work on the html either.

Finaly, I created a html file in assets folder on the project and when I get the html code I try to write on it so I could open using 'url' : '/myfile.html'. But when I try to write it gives java.io.IOException: read only

How can I achieve this? Again: I'm trying to get a html content remotely and run localy so I can have access to Ti namespace.

Thanks

Sqlite Issue

$
0
0

i store decimals in tb using datatype (decimal,float or real) and work it, but when i try to store 23.80, is not storing the 0. what can i do?

[ERROR] Application Installer abnormal process termination. Process exit value was 1

$
0
0

I made a sample demo in Android native and test it in Emulator it is working fine. But when I am trying to run the Titanium Application I am unable to test it on emulator as I am getting the below error : [ERROR] Application Installer abnormal process termination. Process exit value was 1. I am testing this on Windows 7 with Titanium SDK 3.4.1 GA . I install most of the API but even than I am facing the same issue .


How to create new Control in Titanium

$
0
0

I know, we can play a lot with Alloy Widgets, which can be customized for reusable controls, but I am looking for simple way to create a lightweight custom control, that can be created in Alloy tags as well as in Javascript.

For example, creating a simple Icon control, derived from Image (or wrap image or a view), adds little extra functionality.

unable to create projects Run 'titanium help' for available commands

$
0
0

Hello there !!!

I am a beginner in the world of titanium software. I would like a very charitable assistance with the software. I can not create a new project "Mobile app project", I often have an answer like: "Run 'titanium help' for available commands."

Is someone can guide me on this? this several days I'm stuck and that documentation Appcelerator does not really help me solve the problem.

What to do to solve it?

What is $.label.text in titanium alloy application?

$
0
0

Hi all

I am learning titanium alloy for past couple of hours, when I created a titanium alloy project it has by default created me a hello world application.

index.xml

<Alloy>
    <Window class="container">
        <Label id="label" onClick="doClick">Hello, World</Label>
    </Window>
</Alloy>
// index.js
function doClick(e) {
    alert($.label.text);
}
 
$.index.open();
Here my question is ** what is $.label? ** is $. is used here to refer a tag's id attribute's value ? Could some one please help me in understanding this ?

Thanks

Varun Krishna. P

New Alloy Project Fails to Build - Missing extension: public.vcs.subversion

$
0
0

When I create a new Alloy based project, it fails to build and gives the following error:

[INFO] :   Invoking xcodebuild
[ERROR] :  2014-11-22 09:08:45.820 xcodebuild[34884:669122] [MT] DVTAssertions: Warning in /SourceCache/IDEFrameworks/IDEFrameworks-6604/IDEFoundation/SourceControl/Model/IDESourceControlManager.m:423
[ERROR] :  Details:  Error Domain=com.apple.dt.IDESourceControlErrorDomain Code=-1 "Missing extension: public.vcs.subversion" UserInfo=0x7f8809b64e40 {NSLocalizedDescription=Missing extension: public.vcs.subversion}
[ERROR] :  Object:   <IDESourceControlManager: 0x7f8809c24dd0>
[ERROR] :  Method:   -loadRepositories
[ERROR] :  Thread:   <NSThread: 0x7f88085148a0>{number = 1, name = main}
[ERROR] :  Please file a bug at http://bugreport.apple.com with this warning message and any useful information you can provide.
[ERROR] :  2014-11-22 09:08:46.917 xcodebuild[34884:669435]  DeveloperPortal: Using pre-existing current store at URL (file:///Users/Spencer/Library/Developer/Xcode/DeveloperPortal%206.1.db).
[ERROR] :  ** BUILD FAILED **
[ERROR] :  The following build commands failed:
[ERROR] :   Ld build/Debug-iphonesimulator/Alloy.app/Alloy normal i386
[ERROR] :   GenerateDSYMFile build/Debug-iphonesimulator/Alloy.app.dSYM build/Debug-iphonesimulator/Alloy.app/Alloy
[ERROR] :  (2 failures)
I don't seem to have any problems with Xcode, or with classic Titanium projects. I found very little help via Google. The few answers I have seen suggest linking the system SVN version to the XCode SVN version, or shutting off version control in XCode preferences altogether. None of which has worked.

Has anyone else seen this issue?

[NSThread start]: Thread creation failed with error 35

$
0
0

Hi,

my iOS app hangs when running for a while, and with running i mean not closed manually but paused and resumed. It then seems not to complete http request and doesn't react to any touch interaction.

In the Console in Organizer i get the error

"[NSThread start]: Thread creation failed with error 35"

multiple times per second.

After the app crashed i saw that it has spawned several thousand threads in the crashlog on the device.

I have no clue where to search for the problem.

What does the error mean? What can i do about it?

I'm using SDK 3.2.0/Alloy 1.3.0

Thanks, Joe.

Android Error

$
0
0

i have a function with a tableview when i press a button, made a action in all rows in tableview. the problem is when total of rows is more than 3 throws me next error and application close:

[WARN] :   dalvikvm: Last 10 entries in JNI local reference table:
[WARN] :   dalvikvm:   502: 0xb6717ae0 cls=Lti/modules/titanium/ui/TableViewRowProxy; (108 bytes)
[WARN] :   dalvikvm:   503: 0xb68af918 cls=Lti/modules/titanium/ui/TableViewRowProxy; (108 bytes)
[WARN] :   dalvikvm:   504: 0xb67b3b78 cls=Lti/modules/titanium/ui/TableViewSectionProxy; (108 bytes)
[WARN] :   dalvikvm:   505: 0xb676bca8 cls=[Lti/modules/titanium/ui/TableViewRowProxy; (52 bytes)
[WARN] :   dalvikvm:   506: 0xb692fea8 cls=Lti/modules/titanium/ui/TableViewRowProxy; (108 bytes)
[WARN] :   dalvikvm:   507: 0xb6c109d8 cls=Lti/modules/titanium/ui/TableViewRowProxy; (108 bytes)
[WARN] :   dalvikvm:   508: 0xb68b71a0 cls=Lti/modules/titanium/ui/TableViewRowProxy; (108 bytes)
[WARN] :   dalvikvm:   509: 0xb6b427a8 cls=Lti/modules/titanium/ui/TableViewRowProxy; (108 bytes)
[WARN] :   dalvikvm:   510: 0xb69764a8 cls=Lti/modules/titanium/ui/TableViewRowProxy; (108 bytes)
[WARN] :   dalvikvm:   511: 0xb6707498 cls=Lti/modules/titanium/ui/TableViewRowProxy; (108 bytes)
[WARN] :   dalvikvm: JNI local reference table summary (512 entries):
[WARN] :   dalvikvm:    19 of Lti/modules/titanium/ui/TextFieldProxy; 100B (8 unique)
[WARN] :   dalvikvm:     2 of Lti/modules/titanium/ui/TextFieldProxy; 108B (1 unique)
[WARN] :   dalvikvm:    21 of Lti/modules/titanium/ui/LabelProxy; 100B (9 unique)
[WARN] :   dalvikvm:    55 of Lti/modules/titanium/ui/TableViewSectionProxy; 108B (1 unique)
[WARN] :   dalvikvm:     1 of [Lti/modules/titanium/ui/TableViewRowProxy; 52B
[WARN] :   dalvikvm:    21 of Lti/modules/titanium/ui/ButtonProxy; 100B (9 unique)
[WARN] :   dalvikvm:   393 of Lti/modules/titanium/ui/TableViewRowProxy; 108B (9 unique)
[WARN] :   dalvikvm: Memory held directly by tracked refs is 3840 bytes
[INFO] :   dalvikvm: "KrollRuntimeThread" prio=5 tid=8 RUNNABLE
[ERROR] :  dalvikvm: Failed adding to JNI local ref table (has 512 entries)
[INFO] :   dalvikvm:   | group="main" sCount=0 dsCount=0 obj=0xb65a62c0 self=0x9163ec8
[INFO] :   dalvikvm:   | sysTid=1775 nice=0 sched=0/0 cgrp=[fopen-error:2] handle=152453104
[INFO] :   dalvikvm:   at org.appcelerator.kroll.runtime.v8.V8Object.nativeFireEvent(Native Method)
[INFO] :   dalvikvm:   at org.appcelerator.kroll.runtime.v8.V8Object.fireEvent(V8Object.java:62)
[INFO] :   dalvikvm:   at org.appcelerator.kroll.KrollProxy.doFireEvent(KrollProxy.java:884)
[INFO] :   dalvikvm:   at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1107)
[INFO] :   dalvikvm:   at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:347)
[INFO] :   dalvikvm:   at android.os.Handler.dispatchMessage(Handler.java:95)
[INFO] :   dalvikvm:   at android.os.Looper.loop(Looper.java:130)
[INFO] :   dalvikvm:   at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:112)
[INFO] :   dalvikvm:
[ERROR] :  dalvikvm: VM aborting
what is this error? memory leak?

bluetooth connectivity in titanium for android

$
0
0

how can we create bluetooth connectivity in titianium 3.x for android apps


Can't run ./AndroidStudio in Ubuntu

$
0
0

Ubuntu 12.04

I unzipped the file titanium.studio.linux.gtk.x86_64.zip in ~/titanium

i have followed the Guide for installation..

when i write: giovanni@qwerty-desktop:~/.titanium$ ./TitaniumStudio

bash: ./TitaniumStudio: impossible to run the binary file

giovanni@qwerty-desktop:~/.titanium$ sudo ./TitaniumStudio

./TitaniumStudio: 5: ./TitaniumStudio: Syntax error: "(" unexpected

Help!

Where is ACS plans & pricing? and how can I manage my NODE ACS apps?

$
0
0

Hi there! I'm interesting on use ACS but I can't find where is the plans and pricings... when I click on Upgrade my account that leads me to plans & pricing page, it returns to appcelerator home page...

And another thing is... where can I find my uploaded node ACS apps? I run my link for my app and it says that will be avaible soon =/

Thanks

Know if GPS is enabled

$
0
0

Greetings

I am using the GPS, and I need to do the following algorithm:

a)Enable GPS b) is GPS enabled? YES: continue NO: go to a) c) draw current position on map.

In the 2nd step I'm using the following code:

var succeed = false;
    while (succeed == false) {
        Titanium.Geolocation.getCurrentPosition(function(e) {
            if (e.success || !e.error) {
                succeed = true;
            }
        });
    }
But that while loop crashes my app; there is any callback function or any way to stop the app until the device get connected?

Thanks.

List all WiFi connected devices

$
0
0

Hi,

I need to develop an application that requires listing out all the devices [iphone/ipad/Mac] that are in the current local wifi network. Can any body point me to a sample tutorial on this. Is it possible to list out devices in lcoal wifi network using Bonjour?

Thank you Rush

ServiceBase error!!

$
0
0

Hey guys, this is a question for the heavy wieghts. As ive mentioned before in my last question i am new, now the issue i am having in validateting my sign in user info ; on my app. I belive it has something to do with the connection between my app and the api on my sever. Below is a copy of the error i have found using the debug function. Plz help!

This my error report

[ERROR] : XMLModule: (KrollRuntimeThread) [32405,32405] Error parsing XML [ERROR] : XMLModule: org.xml.sax.SAXParseException: Unexpected token (position:TEXT []@1:3 in java.io.InputStreamReader@423bf438) [ERROR] : XMLModule: at org.apache.harmony.xml.parsers.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:146) [ERROR] : XMLModule: at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:107) [ERROR] : XMLModule: at ti.modules.titanium.xml.XMLModule.parse(XMLModule.java:82) [ERROR] : XMLModule: at ti.modules.titanium.xml.XMLModule.parse(XMLModule.java:68) [ERROR] : XMLModule: at ti.modules.titanium.network.TiHTTPClient.getResponseXML(TiHTTPClient.java:700) [ERROR] : XMLModule: at ti.modules.titanium.network.HTTPClientProxy.getResponseXML(HTTPClientProxy.java:107) [ERROR] : XMLModule: at org.appcelerator.kroll.runtime.v8.V8Object.nativeCallProperty(Native Method) [ERROR] : XMLModule: at org.appcelerator.kroll.runtime.v8.V8Object.callProperty(V8Object.java:73) [ERROR] : XMLModule: at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1121) [ERROR] : XMLModule: at android.os.Handler.dispatchMessage(Handler.java:95) [ERROR] : XMLModule: at android.os.Looper.loop(Looper.java:137) [ERROR] : XMLModule: at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:112) [ERROR] : TiHttpClient: (KrollRuntimeThread) [3,32408] Error parsing XML [ERROR] : TiHttpClient: org.xml.sax.SAXParseException: Unexpected token (position:TEXT []@1:3 in java.io.InputStreamReader@423bf438) [ERROR] : TiHttpClient: at org.apache.harmony.xml.parsers.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:146) [ERROR] : TiHttpClient: at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:107) [ERROR] : TiHttpClient: at ti.modules.titanium.xml.XMLModule.parse(XMLModule.java:82) [ERROR] : TiHttpClient: at ti.modules.titanium.xml.XMLModule.parse(XMLModule.java:68) [ERROR] : TiHttpClient: at ti.modules.titanium.network.TiHTTPClient.getResponseXML(TiHTTPClient.java:700) [ERROR] : TiHttpClient: at ti.modules.titanium.network.HTTPClientProxy.getResponseXML(HTTPClientProxy.java:107) [ERROR] : TiHttpClient: at org.appcelerator.kroll.runtime.v8.V8Object.nativeCallProperty(Native Method) [ERROR] : TiHttpClient: at org.appcelerator.kroll.runtime.v8.V8Object.callProperty(V8Object.java:73) [ERROR] : TiHttpClient: at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1121) [ERROR] : TiHttpClient: at android.os.Handler.dispatchMessage(Handler.java:95) [ERROR] : TiHttpClient: at android.os.Looper.loop(Looper.java:137) [ERROR] : TiHttpClient: at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:112)

this is the specified .js

var ServiceBase = { /****************************** ****** ATTRIBUTES HERE ******************************/ //////////////////////////////// //ErrorHandle: {} //Request: {},//Request Object Handle Functions : {}, // Normal Functions

/******************************
 ****** METHODS HERE
 ******************************/
////////////////////////////////

/**
 * Contruct method
 */
constructor : function() {
    alert('constructor');
}

};

ServiceBase.ErrorHandle = { throwErrorMessage : function(msg) { if (msg.ErrorMessage.indexOf('ASIHTTPRequestError') !== -1) { alert(L('_core_request_timeout_try_again')); } else { alert(msg.ErrorMessage); } } };

ServiceBase.Request = { /****************************** ****** ATTRIBUTES HERE ******************************/ //////////////////////////////// loadingIndicator : null, timeout : 20000, isTinyIndicator : false, clientRequest : null,

/******************************
 ****** METHOD HERE
 ******************************/
////////////////////////////////
loadIndicator : function(indicator) {
    this.isTinyIndicator = false;
    this.loadingIndicator = indicator;
},
loadTinyIndicator : function(indicator) {
    this.isTinyIndicator = true;
    this.loadingIndicator = indicator;
},

validateJsonError : function(json, silence) {
    if (!json) {
        ServiceBase.ErrorHandle.throwErrorMessage({ErrorMessage:'Error on JSON structure.'});
        return false;
    }
    if (!json.status) {
        if (silence) {

        } else {
            ServiceBase.ErrorHandle.throwErrorMessage(json.content);
        }
        return false;
    }
    return json.content;

},


validateXmlError : function(xml, silence) {
    if (!xml) {
        ServiceBase.ErrorHandle.throwErrorMessage({ErrorMessage:'please try again.'});
        return false;
    }
    var error_xml = xml.documentElement.getElementsByTagName(&quot;Error&quot;);
    if (error_xml.getLength() &gt; 0) {
        var message_xml = xml.documentElement.getElementsByTagName(&quot;Message&quot;);
        if (message_xml.getLength() &gt; 0) {
            if (silence) {
                //Ti.API.info(message_xml.item(0).textContent.trim());
            } else {
                ServiceBase.ErrorHandle.throwErrorMessage({ErrorMessage:errMsg});
            }

        }
        return false;
    }

    var itemList = xml.documentElement.getElementsByTagName(&quot;Items&quot;);
    if (!itemList || itemList.getLength() == 0) {
        if (silence) {

        } else {
            ServiceBase.ErrorHandle.throwErrorMessage({ErrorMessage:&quot;Can't get item list.&quot;});
        }

        return false;
    }

    return itemList.item(0);

},

/**
 *
 * @param {String} URL
 * @param {Object} Optional {responseType, timeout, options}
 */
GET : function(URL, Optional) {

    if ( typeof Optional != 'object') {
        ServiceBase.ErrorHandle.throwErrorMessage({ErrorMessage:'Invalid type of GET request params.'});
        return;
    }
    var self = this;
    var btnLoading = null;
    //SHOW INDICATOR IF AVAILABLE
    if ( typeof (Optional.silence) == 'undefined' || !Optional.silence) {
        if ( typeof Optional.indicator != 'undefined') {
            btnLoading = Optional.indicator.getChildren()[0];
            btnLoading.setText(L('_core_loading'));
            Optional.indicator.enabled = false;
        } else if (self.loadingIndicator) {
            if (this.isTinyIndicator) {//Change Loading more button
                btnLoading = this.loadingIndicator.getChildren()[0];
                btnLoading.setText(L('_core_loading'));
                this.loadingIndicator.enabled = false;
            } else {
                self.loadingIndicator.showIndicator();
            }
        }
    }

    // var xhr = Ti.Network.createHTTPClient({
    this.clientRequest = Ti.Network.createHTTPClient({
        onload : function(e) {

            //HIDE INDICATOR IF AVAILABLE
            if ( typeof (Optional.silence) == 'undefined' || !Optional.silence) {
                if ( typeof Optional.indicator != 'undefined') {
                    btnLoading.setText(L('_core_load_more'));
                    Optional.indicator.enabled = true;
                } else if (self.loadingIndicator) {
                    if (self.isTinyIndicator) {//Change Loading more button
                        btnLoading.setText(L('_core_load_more'));
                        //btnLoading.setEnabled(true);
                        self.loadingIndicator.enabled = true;
                    } else {
                        self.loadingIndicator.hide();
                    }
                }
            }

            var responseValue = '';
            if (Optional.responseType == 'XML') {

                //CHECK IF VALIDDING XML RETURN
                var silence = false;
                if ( typeof (Optional.silence) != 'undefined' &amp;&amp; Optional.silence) {
                    silence = true;
                }

                if (!( responseValue = self.validateXmlError(this.responseXML, silence))) {

                    //IF recall function valid, revolk
                    if ( typeof Optional.onfail == 'function') {
                        Optional.onfail(e);
                    }
                    return;
                }
                //responseValue = this.repsonseXML;
            } else if (Optional.responseType == 'JSON') {
                //CHECK IF VALIDDING JSON RETURN
                var silence = false;
                if ( typeof (Optional.silence) != 'undefined' &amp;&amp; Optional.silence) {
                    silence = true;
                }
                if (!( responseValue = self.validateJsonError(JSON.parse(this.responseText), silence))) {
                    //IF recall function valid, revolk
                    if ( typeof Optional.onfail == 'function') {
                        Optional.onfail(e);
                    }
                    return;
                }
            }

            //IF recall function valid, revolk
            if ( typeof Optional.recallFunction == 'function') {
                Optional.recallFunction(responseValue);
            }
            /*if (!Ti.UI.Android) {
             this.clientRequest = null;
             }*/

        },
        onerror : function(e) {
            //HIDE INDICATOR IF AVAILABLE
            if ( typeof (Optional.silence) == 'undefined' || !Optional.silence) {
                if ( typeof Optional.indicator != 'undefined') {
                    btnLoading.setText(L('_core_load_more'));
                    Optional.indicator.enabled = true;
                } else if (self.loadingIndicator) {
                    if (self.isTinyIndicator) {//Change Loading more button
                        btnLoading.setText(L('_core_load_more'));
                        //btnLoading.setEnabled(true);
                        self.loadingIndicator.enabled = true;
                    } else {
                        self.loadingIndicator.hide();
                    }
                }
            }
            //Ti.API.debug(e.error);
            if ( typeof (Optional.silence) == 'undefined' || !Optional.silence) {
                //Network Error
                ServiceBase.ErrorHandle.throwErrorMessage({ErrorMessage:'Your network is not connected. Please try again!'});
            } else {
                Ti.API.debug(e.error);
            }
            //IF recall function valid, revolk
            if ( typeof Optional.onfail == 'function') {
                Optional.onfail(e);
            }

        },

    });
    var timeout = this.timeout;
    if ( typeof Optional.timeout != 'undefined') {
        timeout = Optional.timeout;
    } else if ( typeof Ti.App.NetworkTimeout != 'undefined') {
        timeout = Ti.App.NetworkTimeout;
    }
    this.clientRequest.setTimeout(timeout);

    this.clientRequest.open(&quot;GET&quot;, URL);
    this.clientRequest.setRequestHeader(&quot;User-Agent&quot;, Ti.App.FAKE_USERAGENT);

    this.clientRequest.send();
},
/**
 *
 * @param {String} URL
 * @param {Object} Optional {responseType, timeout, options}
 */
POST : function(URL, Optional) {

    if ( typeof Optional != 'object') {
        ServiceBase.ErrorHandle.throwErrorMessage({ErrorMessage:'Invalid type of POST request params.'});
        return;
    }

    var self = this;
    var btnLoading = null;
    //SHOW INDICATOR IF AVAILABLE
    if ( typeof (Optional.silence) == 'undefined' || !Optional.silence) {
        if ( typeof Optional.indicator != 'undefined') {
            btnLoading = Optional.indicator.getChildren()[0];
            btnLoading.setText(L('_core_loading'));
            Optional.indicator.enabled = false;
        } else if (self.loadingIndicator) {
            if (this.isTinyIndicator) {//Change Loading more button
                btnLoading = this.loadingIndicator.getChildren()[0];
                btnLoading.setText(L('_core_loading'));
                this.loadingIndicator.enabled = false;
            } else {
                self.loadingIndicator.showIndicator();
            }
        }
    }
    var xhr = Ti.Network.createHTTPClient({
        onload : function(e) {

            //HIDE INDICATOR IF AVAILABLE
            if ( typeof (Optional.silence) == 'undefined' || !Optional.silence) {
                if ( typeof Optional.indicator != 'undefined') {
                    btnLoading.setText(L('_core_load_more'));
                    Optional.indicator.enabled = true;
                } else if (self.loadingIndicator) {
                    if (self.isTinyIndicator) {//Change Loading more button
                        btnLoading.setText(L('_core_load_more'));
                        //btnLoading.setEnabled(true);
                        self.loadingIndicator.enabled = true;
                    } else {
                        self.loadingIndicator.hide();
                    }
                }
            }

            var responseValue = '';
            if (Optional.responseType == 'XML') {
                //CHECK IF VALIDDING XML RETURN
                var silence = false;
                if ( typeof (Optional.silence) != 'undefined' &amp;&amp; Optional.silence) {
                    silence = true;
                }
                if (!( responseValue = self.validateXmlError(this.responseXML, silence))) {
                    if ( typeof Optional.onfail == 'function') {
                        Optional.onfail(e);
                    }
                    return;
                }
                //responseValue = this.repsonseXML;
            } else if (Optional.responseType == 'JSON') {
                //CHECK IF VALIDDING XML RETURN
                var silence = false;
                if ( typeof (Optional.silence) != 'undefined' &amp;&amp; Optional.silence) {
                    silence = true;

                }


                if (!( responseValue = self.validateJsonError(JSON.parse(this.responseText), silence))) {
                    //IF recall function valid, revolk
                    if ( typeof Optional.onfail == 'function') {
                        Optional.onfail(e);
                    }
                    return;
                }
            }

            //IF recall function valid, revolk
            if ( typeof Optional.recallFunction == 'function') {
                Optional.recallFunction(responseValue);
            }
            //Ti.API.debug(this.responseText);
        },
        onerror : function(e) {

            //HIDE INDICATOR IF AVAILABLE
            if ( typeof (Optional.silence) == 'undefined' || !Optional.silence) {
                if ( typeof Optional.indicator != 'undefined') {
                    btnLoading.setText(L('_core_load_more'));
                    Optional.indicator.enabled = true;
                } else if (self.loadingIndicator) {
                    if (self.isTinyIndicator) {//Change Loading more button
                        btnLoading.setText(L('_core_load_more'));
                        //btnLoading.setEnabled(true);
                        self.loadingIndicator.enabled = true;
                    } else {
                        self.loadingIndicator.hide();
                    }
                }
            }
            //Ti.API.debug(e.error);
            if ( typeof (Optional.silence) == 'undefined' || !Optional.silence) {
                ServiceBase.ErrorHandle.throwErrorMessage({ErrorMessage:'Your network is not connected. Please try again!'});
            } else {
                Ti.API.debug(e.error);
            }

            //IF recall function valid, revolk
            if ( typeof Optional.onfail == 'function') {
                Optional.onfail(e);
            }
        },
        //timeout : 5000

    });
    var timeout = this.timeout;
    if ( typeof Optional.timeout != 'undefined') {
        timeout = Optional.timeout;
    } else if ( typeof Ti.App.NetworkTimeout != 'undefined') {
        timeout = Ti.App.NetworkTimeout;
    }
    xhr.setTimeout(timeout);
    xhr.open(&quot;POST&quot;, URL);
    xhr.setRequestHeader(&quot;User-Agent&quot;, Ti.App.FAKE_USERAGENT);

    xhr.send(Optional.options);
    return xhr;
}

};

ServiceBase.Functions.openNewWindow = function(windowURL, parameterOptions) {

 if (!parameterOptions) {
    parameterOptions = {
        options : {}
    };
 }
 if ( typeof parameterOptions.options == 'undefined') {
    parameterOptions.options = {};
 }

var new_window = Titanium.UI.createWindow({
    url : windowURL,
    backgroundImage : Ti.App.Theme.Body_BkgImage,
    backgroundColor : Ti.App.Theme.Body_BkgColor,
    navBarHidden : true,
    parameterOptions : parameterOptions.options,
    zIndex : 2,
});
new_window.setReturnValues = function(options) {
    this.parameterOptions = options;
};
if ( typeof (parameterOptions.returnFunction) != 'undefined') {
    new_window.addEventListener('close', function(e) {
        parameterOptions.returnFunction(new_window.parameterOptions);
    });
};

new_window.open();
//Check ANDROID APP IN BACKGROUND
if (Ti.UI.Android) {
    new_window.addEventListener('open', function() {
        var activity = new_window.getActivity();
        activity.addEventListener('resume', function(e) {

            Ti.App.appFocus = true;
        });
        activity.addEventListener('pause', function(e) {

            Ti.App.appFocus = false;
        });
    });
}
return new_window;

};

ServiceBase.Functions.generateIndicator = function() { if (Ti.UI.currentWindow && typeof Ti.UI.currentWindow != 'undefined' && typeof Ti.UI.currentWindow.indicator != 'undefined') { return Ti.UI.currentWindow.indicator; } var activityIndicator = Ti.UI.createActivityIndicator({ color : '#ffffff', font : { fontFamily : Ti.App.Theme.Core_FFamily, fontSize : 18, fontWeight : 'bold' }, message : L('_core_loading'), style : (Ti.Platform.name === 'iPhone OS' ? Ti.UI.iPhone.ActivityIndicatorStyle.BIG : Ti.UI.ActivityIndicatorStyle.BIG), backgroundColor : '#000000', borderColor : '#eeeeee', borderRadius : 10, borderWidth : 3, width : iWidthIndicator, zIndex : 1100, height : 200

});
var view = Ti.UI.createView({
    backgroundColor : '#111111',
    top : 0,
    left : 0,
    bottom : 0,
    right : 0,
    opacity : 0.4,
    zIndex : 1005
});
activityIndicator.show();
view.indicator = activityIndicator;

view.add(activityIndicator);
view.showIndicator = function() {
    this.show();
    setTimeout(function() {
        view.hide();
    }, 240000);
    this.indicator.show();
};
view.hide();

if (!Ti.UI.currentWindow || typeof Ti.UI.currentWindow == 'undefined') {//Seperate Indicator
    return view;
}

//Add indicator for current view
Ti.UI.currentWindow.indicator = view;
Ti.UI.currentWindow.add(Ti.UI.currentWindow.indicator);

Ti.UI.currentWindow.indicator.indicator.setTop((Ti.Platform.displayCaps.getPlatformHeight() - 200) / 2);
Ti.UI.currentWindow.indicator.indicator.setBottom((Ti.Platform.displayCaps.getPlatformHeight() - 200) / 2);

Ti.UI.currentWindow.addEventListener('close', function(e) {
    Ti.UI.currentWindow.remove(Ti.UI.currentWindow.indicator);
});
return Ti.UI.currentWindow.indicator;

};

ServiceBase.Functions.generateLoadingMore = function(eventFunction, adsEnable) { // When scroll to the end of Table, add loading row and get more results from server // LodingMore row

var height = 0, footer_ads = null;

var loadingMoreButton = Ti.UI.createView({
    width : 'auto',
    height : iHeightFooter + height,
    //selectionStyle : Ti.UI.iPhone.TableViewSeparatorStyle.NONE,
    editable : false,
    enabled : true
});

var lbLoadingMore = Ti.UI.createLabel({
    text : L('_core_load_more'),
    textAlign : 'center',
    color : '#51595c',
    font : {
        fontSize : font15,
        fontWeight : 'bold',
        fontFamily : Ti.App.Theme.Core_FFamily,
    },
    left : 0,
    top : 0,
    bottom : height,
    right : 0,
});
loadingMoreButton.add(lbLoadingMore);
if (footer_ads) {
    loadingMoreButton.add(footer_ads);
}

loadingMoreButton.addEventListener('click', function(e) {

    var rowItem = e.source;

    while ( typeof (rowItem.parent) != 'undefined' &amp;&amp; typeof rowItem.enabled == 'undefined') {
        rowItem = rowItem.parent;
    }
    if (rowItem.enabled) {
        eventFunction();
    };
});

/*loadingMoreButton.addEventListener('postlayout',function(e){



 })*/

return loadingMoreButton;

}; /** * For the view render function which uses paginator. * @param {Object} options {viewFunction, urlFunction, layout} * @return void */ ServiceBase.Functions.renderPagingView = function(options) {

//Attach Loading More
if ( typeof options.layout.bodyView.loadingMore == 'undefined') {
    options.layout.bodyView.loadingMore = ServiceBase.Functions.generateLoadingMore(function() {
        options.layout.buildBody(options.layout);
    }, true);
    //ADD Tiny Loading Indicator
    //ServiceBase.Request.loadTinyIndicator(options.layout.bodyView.loadingMore);
    options.layout.bodyView.add(options.layout.bodyView.loadingMore);
    options.layout.bodyView.loadingMore.fireEvent('click');
    return;
}
//.Validate options
if ( typeof options.layout.bodyView.Option_PageId == 'undefined') {
    options.layout.bodyView.Option_PageId = 1;
    options.layout.bodyView.Option_ItemPerPage = '15';

}
//BUILD URL
var URL = options.urlFunction(options.layout.bodyView.Option_PageId, options.layout.bodyView.Option_ItemPerPage);
var tab_index = options.layout.getCurrentTabIndex();
options.layout.setCurrentTabLoading(true);
ServiceBase.Request.GET(URL, {
    responseType : 'JSON',
    recallFunction : function(json) {
        //Check still in the same tab or not

        if (tab_index !== null &amp;&amp; options.layout.getCurrentTabIndex() !== null &amp;&amp; tab_index !== options.layout.getCurrentTabIndex()) {
            return;
        }

        if (options.layout.bodyView.DataParams) {
            options.layout.bodyView.DataParams = null;
        }

        options.layout.bodyView.DataParams = json;

        if ( typeof options.viewFunction != 'undefined' &amp;&amp; options.layout.bodyView.DataParams) {
            options.viewFunction(options.layout);
        }
        options.layout.setCurrentTabLoading(false);
    },
    indicator : options.layout.bodyView.loadingMore,
});

}; /** * Clear view content * @param {Object TiUIView} view * @return {Object} / ServiceBase.Functions.clearViewContent = function(view) { / var children = view.getChildren(); for (var i = 0; i < children.length; i++) { view.remove(children[i]); } return view; */ var childLen = view.getChildren().length; for (var i = 0; i < childLen; i++) { view.remove(view.children[((childLen - 1) - i)]); view.children[((childLen - 1) - i)] = null; } return view; }; /** * Set Label View Folowing Row * @param {Object} options * @return {Ti.UI.View} */ ServiceBase.Functions.createLabelView = function(options) { options.layout = 'horizontal'; options.height = Titanium.UI.SIZE; //options.borderWidth = 1; //options.borderColor = 'blue'; options.lLine = 0; //options.lRowAvailable = options.width;

var labelView = Ti.UI.createView(options);
if (options.width) {
    labelView.lRowAvailable = options.width;
} else {
    labelView.lRowAvailable = labelView.toImage().width;
    labelView.width = labelView.lRowAvailable;
}

//get Line number method
labelView.getRows = function() {
    if (this.lRowAvailable == this.width)
        return this.lLine;
    return this.lLine + 1;
};
//Get Char width method
labelView.getCharWidth = function(font_data, character, params) {
    if ( typeof font_data[character] == 'undefined') {
        params.text = character;
        params.width = 'auto';
        var lbl = Ti.UI.createLabel(params);
        font_data[character] = lbl.toImage().width;
        font_data.isUpdated = true;
    }
    return font_data[character] &lt; 100 ? font_data[character] : 0;
    //Trick ON IOS : the width of one character can't be greater than 100
};
//labelView.lRowAvailable = labelView.width;
labelView.addLabel = function(params) {
    var text = '';
    if ( typeof params.text != 'undefined') {
        //params.text = &quot;An Egyptian court is deciding whether or not ex-President Hosni Mubarak should be released.The former leader is awaiting a retrial for conspiring to kill protesters during the revolution that toppled him.Reports that the court had ruled he should remain in custody on other charges have not been confirmed.Mr Mubarak's lawyer argues he has spent the maximum time in prison under temporary detention, Egyptian media report.But he remains in custody on fraud charges.Last June, Mr Mubarak was sentenced to life in prison for killings committed during the 2011 uprising that ended his rule, but in January a retrial was ordered.Corruption chargesThere were chaotic scenes on Saturday as the judge presiding over the retrial, Mustafa Hassan Abdullah, withdrew from the case citing his unease in overseeing the proceedings.The case has been referred to a different court, which is expected to appoint a new panel to hear the retrial.About 850 people were killed in the 2011 crackdown during the 2011 uprising which ended Mr Mubarak's rule.He and former interior minister Habib al-Adly were sentenced to life in prison for conspiring to kill protesters.But both will be re-tried after they successfully appealed against their convictions, with Egypt's Court of Cassation citing procedural failings.Mr Al-Adly will also be re-tried for corruption charges, for which he was sentenced to five and 12 years.Hosni Mubarak and his two sons, Gamal and Alaa, will also be re-tried for corruption charges, of which they were found not guilty the first time round.The former leader has been in poor health since his arrest and appeared on a stretcher during his first trial and Saturday's hearing.Deaths during the uprising were largely blamed on the police at the time, but last week a report was leaked which implicated the army in serious human rights abuses at the time, including the killing and torture of protesters.The leaked chapter, reportedly presented to President Mohammed Morsi late last year, contains testimony relating to civilians detained at military checkpoints who were never seen again and reports that the army delivered unidentified bodies to coroners.Egypt's Defence Minister Abdel Fatah al-Sissi denied the accusations, calling them a betrayal....&quot;;
        //Remove Endline param
        //params.text = params.text.replace('\r','');
        //params.text = params.text.replace('\n','\t');

        text = params.text;
    }

    params.horizontalWrap = false;
    params.width = 'auto';
    params.height = 'auto';
    //params.borderWidth = '1';
    //params.borderColor = 'red';

    //Get FONT data
    var font_size = 'default', font_weight = 'normal', is_updated = false;
    if ( typeof params.font != 'undefined') {
        if ( typeof params.font.fontSize != 'undefined') {
            font_size = params.font.fontSize;
        }
        if ( typeof params.font.fontWeight != 'undefined') {
            font_weight = params.font.fontWeight;
        }
    }

    var font_name = font_size + '_' + font_weight;

    var font_data = Ti.App[font_name];
    //Ti.App.Properties.getObject(font_name);
    if (!font_data) {
        var font_data = Ti.App.Properties.getObject(font_name);
    }
    if (!font_data) {

        params.text = 'a';
        var lbl = Ti.UI.createLabel(params);
        var height = lbl.toImage().height;
        font_data = {
            isUpdated : false,
            height : height,

        };
        is_updated = true;
    } else {
        //
    }

    //Check height
    params.height = font_data.height;

    //Process
    var current_pointer = 0, text_length = text.length;
    while (current_pointer &lt; text_length) {

        var sub_label = '', sub_st_length = 0, sub_pointer = current_pointer, last_space = -1, last_space_width = 0;
        //var new_row = (this.lRowAvailable == this.width)? true : false;
        while (sub_pointer &lt; text_length &amp;&amp; (text.charAt(sub_pointer) !== '\n') &amp;&amp; sub_st_length + this.getCharWidth(font_data, text.charAt(sub_pointer), params) &lt;= this.lRowAvailable) {
            sub_st_length = sub_st_length + this.getCharWidth(font_data, text.charAt(sub_pointer), params);

            if (text.charAt(sub_pointer) == ' ' || text.charAt(sub_pointer) == '\t' || text.charAt(sub_pointer) == '.') {
                last_space = sub_pointer;
                last_space_width = sub_st_length;
            }
            sub_pointer++;
        }
        //New line
        if (text.charAt(sub_pointer) === '\n') {
            sub_st_length = this.lRowAvailable;
            last_space = sub_pointer;
            last_space_width = sub_st_length;
            sub_pointer++;
        }

        if (current_pointer === sub_pointer) {//New line
            if (this.lRowAvailable === this.width) {//Width to small

                break;
            }
            this.lRowAvailable = this.width;
            this.lLine++;
            continue;
        }

        //Check if current is a space
        if (sub_pointer &gt;= text_length || text.charAt(sub_pointer) == ' ' || text.charAt(sub_pointer) == '\t') {

            last_space_width = sub_st_length;
            //add label
            params.text = text.substring(current_pointer, sub_pointer);
            params.width = last_space_width;
            last_space = sub_pointer - 1;
        } else {
            if (last_space &lt; 0) {
                if (this.lRowAvailable &lt; this.width) {
                    this.lRowAvailable = this.width;
                    this.lLine++;
                    //
                    continue;
                }

                last_space = sub_pointer - 1;
                last_space_width = sub_st_length;

            }
            //add label
            params.text = text.substring(current_pointer, last_space + 1);
            params.width = last_space_width;
        }

        var lbl = Ti.UI.createLabel(params);
        if ( typeof params.clickListener != 'undefined') {
            lbl.addEventListener('click', params.clickListener);
        }
        this.add(lbl);

        current_pointer = last_space + 1;
        if (current_pointer &gt;= text_length) {//END OF STRING
            this.lRowAvailable -= last_space_width;
            break;
        }
        this.lRowAvailable = this.width;
        this.lLine++;

    }

    //Save to memory
    if (is_updated || font_data.isUpdated) {
        font_data.isUpdated = false;
        Ti.App.Properties.setObject(font_name, font_data);
        Ti.App[font_name] = font_data;
        //
    }
    return;
};

return labelView;

}; /** * Convert HTML to Array * @param {Object} html * @return {Array} */ ServiceBase.Functions.htmlToArray = function(html) { var out = [];

//html = ' hello ds &lt;a href=';//http://fdsf.cssd&quot;&gt;fsdsf df&lt;/a&gt; hdsf &lt;a href=&quot;tocha mi len&quot;&gt;hole shit&lt;/a&gt; he he';
var tmp = html.split(/(&lt;a\shref=&quot;|&lt;\/a&gt;)/gi);
var i = 0;
while (i &lt; tmp.length) {
    if (tmp[i] == '&lt;/a&gt;') {
        i++;
        continue;
    }
    if (tmp[i] == '&lt;a href=&quot;' &amp;&amp; i + 2 &lt; tmp.length &amp;&amp; tmp[i + 2] == '&lt;/a&gt;') {
        var click_link = tmp[i + 1].split('&quot;&gt;');
        if (click_link.length &gt; 1) {
            out.push({
                href : click_link[0],
                text : click_link[1]
            });
        } else {
            out.push({
                href : null,
                text : click_link[0]
            });
        }

        i += 2;
    } else {
        out.push({
            href : null,
            text : tmp[i]
        });
    }
    i++;
}
//
return out;

};

/** * truncateString * @param {Object} string * @param {Integer} length * @return {Object} string */ ServiceBase.Functions.truncateString = function(string, length) { if (string != null && string.length > length) { return string.substr(0, length) + '...'; } else { return string; } };

ServiceBase.Functions.setSizePhoto = function(imageView, widthFull) { var imageWidth = imageView.getWidth(); var imageHeight = imageView.getHeight(); var percent = (widthFull) / imageWidth; if (imageWidth > widthFull) { imageView.setWidth(widthFull); imageView.setHeight(percent * imageHeight); } else { if (widthFull > 500) { imageView.setWidth(widthFull); imageView.setHeight(percent * imageHeight); } else { imageView.setWidth(imageWidth); imageView.setHeight(imageHeight); }

}

}; /** * CACHE HANDLE */ ServiceBase.Functions.setSizeItemImage = function(self) { var winWidth = Titanium.Platform.displayCaps.platformWidth; self.leftMargin = 10; self.iWidthItemImage = 145; self.columns = 2; self.allMargin = self.leftMargin * (self.columns + 1); if (winWidth < 320) { self.iWidthItemImage = 90; self.columns = 2; } else { while ((winWidth - (self.iWidthItemImage * self.columns + self.allMargin)) > self.iWidthItemImage) { self.columns = self.columns + 1; self.allMargin = self.leftMargin * (self.columns + 1); } } if ((winWidth - (self.iWidthItemImage * self.columns + self.allMargin)) > self.leftMargin) { self.iWidthItemImage = self.iWidthItemImage + ((winWidth - (self.iWidthItemImage * self.columns + self.allMargin))) / self.columns; } self.leftMargin = (winWidth - (self.iWidthItemImage * self.columns)) / (self.columns + 1); };

ServiceBase.Functions.generateContentAction = function(itemFeed) { if (itemFeed.LastActivity.ActivityType == 'create') { if (itemFeed.PluginKey == 'friends' && itemFeed.EntityType == 'friend_add') { if (itemFeed.ContentAction[0] != null && itemFeed.ContentAction[0].user2 != null) { return 'and ' + '<a href="' + API_SERVICE_URL + 'user/' + itemFeed.ContentAction[0].user2.DisplayName + '"\>' + itemFeed.ContentAction[0].user2.DisplayName + '</a> are now friends'; } } } if (itemFeed.LastActivity.ContentActivity == null) { return ''; } return itemFeed.LastActivity.ContentActivity; };

/** * Show header Notification View * @param {Object} data * @return {Object} */ ServiceBase.Functions.showNotifiedAlert = function(data) { if (Ti.App.notifiedBoxVisible) {//Message box is opening, do nothing return; }

if (!Ti.App.appFocus) {//APP doesn't focus, go to direct detail
    var object_type = data.object_type;
    var object_id = data.object_id;
    if (object_type &amp;&amp; object_id) {
        ServiceBase.Functions.goToNotifiedObject(object_type, object_id);
        return;
    }
}

var notified_window = Ti.UI.createWindow({
    backgroundColor : 'transparent',
    top : -iHeightHeader - 5,
    left : 0,
    right : 0,
    height : iHeightHeader + 5,
    backgroundImage : Ti.App.Theme.Core_Theme_Url + '/core/images/bkg_header.png',
    zIndex : 10006,
    cutOut : 'stop',
    data : data,
    clicked : false
});
if (Ti.UI.Android) {
    notified_window.addEventListener('open', function() {
        return;
    });
}
Ti.App.notifiedBoxVisible = true;
notified_window.open();
var viewAvatar = Ti.UI.createImageView({
    image : data.user_avatar,
    width : 40,
    height : 40,
    top : 5,
    left : 5,
    cutOut : 'stop',
    data : data,
});
notified_window.add(viewAvatar);
if (Ti.Android) {
    var label_content = Ti.UI.createLabel({
        backgroundColor : 'transparent',
        top : 0,
        left : 50,
        right : 0,
        color : Ti.App.Theme.Core_TitleHeaderColor,
        height : Ti.UI.SIZE,
        text : data.message,
        cutOut : 'stop',
        data : data,
    });
} else {
    var label_content = Ti.UI.createLabel({
        backgroundColor : 'transparent',
        top : 0,
        left : 50,
        right : 0,
        color : Ti.App.Theme.Core_TitleHeaderColor,
        height : Ti.UI.SIZE,
        text : data.alert,
        cutOut : 'stop',
        data : data,
    });
}
notified_window.addEventListener('click', function(e) {

    notified_window.clicked = true;
    var object_type = notified_window.data.object_type;
    var object_id = notified_window.data.object_id;


    if (object_type &amp;&amp; object_id) {
        ServiceBase.Functions.goToNotifiedObject(object_type, object_id);
    }
});
notified_window.add(label_content);

notified_window.addEventListener('close', function(e) {
    var interval = setInterval(function() {

        if (e.source.top &lt;= 0) {
            clearInterval(interval);
            return;
        }
        e.source.top = e.source.top - 1;

    }, 5);
});


notified_window.open();
var interval = setInterval(function() {
    if (notified_window.top &gt;= 0) {
        clearInterval(interval);
        return;
    }
    notified_window.top = notified_window.top + 1;

}, 5);
setTimeout(function() {
    Ti.App.notifiedBoxVisible = false;
    notified_window.close();
}, 8000);

};

/** * Go to Notified Object Window * @param {Object} object_type * @param {Object} object_id */ ServiceBase.Functions.goToNotifiedObject = function(object_type, object_id) {

var advanceOptions = {};
var URL = null;
var strType = object_type;
var EntityId = object_id;
switch (strType) {
    case 'blogs': {
        URL = '/ui/blog/controllers/blogdetail.js';
        advanceOptions = {
            BlogId : EntityId,
        };
        break;
    }
    case 'forum': {
        URL = '/ui/forum/controllers/topicdetail.js';
        advanceOptions = {
            TopicId : EntityId,
        };
        break;
    }
    case 'event': {
        URL = '/ui/event/controllers/eventdetail.js';
        advanceOptions = {
            EventId : EntityId,
        };
        break;
    }
    case 'video': {
        URL = '/ui/video/controllers/videodetail.js';
        advanceOptions = {
            VideoId : EntityId,
        };
        break;
    }
    case 'groups': {
        URL = '/ui/group/controllers/groupdetail.js';
        advanceOptions = {
            GroupId : EntityId,
        };
        break;
    }
    case 'photo': {
        URL = '/ui/photo/controllers/photodetail.js';
        advanceOptions = {
            PhotoId : EntityId,
        };
        break;
    }
    case 'links': {
        URL = '/ui/link/controllers/linkdetail.js';
        advanceOptions = {
            LinkId : EntityId,
        };
        break;
    }
    case 'virtualgifts': {
        URL = '/ui/core/controllers/giftdetail.js';
        advanceOptions = {
            GiftId : EntityId,
        };
        break;
    }
    default:
        break;
}

if (!URL) {
    return;
}
ServiceBase.Functions.openNewWindow(URL, {
    returnFunction : function(returnParams) {
        //...
    },
    options : advanceOptions,
});

};

ServiceBase.Cache = {

};

Viewing all 8068 articles
Browse latest View live




Latest Images