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("Error");
if (error_xml.getLength() > 0) {
var message_xml = xml.documentElement.getElementsByTagName("Message");
if (message_xml.getLength() > 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("Items");
if (!itemList || itemList.getLength() == 0) {
if (silence) {
} else {
ServiceBase.ErrorHandle.throwErrorMessage({ErrorMessage:"Can't get item list."});
}
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' && 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' && 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("GET", URL);
this.clientRequest.setRequestHeader("User-Agent", 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' && 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' && 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("POST", URL);
xhr.setRequestHeader("User-Agent", 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' && 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 && options.layout.getCurrentTabIndex() !== null && 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' && 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] < 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 = "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....";
//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 < 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 < text_length && (text.charAt(sub_pointer) !== '\n') && sub_st_length + this.getCharWidth(font_data, text.charAt(sub_pointer), params) <= 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 >= 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 < 0) {
if (this.lRowAvailable < 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 >= 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 <a href=';//http://fdsf.cssd">fsdsf df</a> hdsf <a href="tocha mi len">hole shit</a> he he';
var tmp = html.split(/(<a\shref="|<\/a>)/gi);
var i = 0;
while (i < tmp.length) {
if (tmp[i] == '</a>') {
i++;
continue;
}
if (tmp[i] == '<a href="' && i + 2 < tmp.length && tmp[i + 2] == '</a>') {
var click_link = tmp[i + 1].split('">');
if (click_link.length > 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 && 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 && 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 <= 0) {
clearInterval(interval);
return;
}
e.source.top = e.source.top - 1;
}, 5);
});
notified_window.open();
var interval = setInterval(function() {
if (notified_window.top >= 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 = {
};