Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This is a test harness for your module
- // You should do something interesting in this harness
- // to test out the module and to provide instructions
- // to users on how to use it by example.
- // open a single window
- var window = Ti.UI.createWindow({
- backgroundColor : 'black',
- layout : 'vertical'
- });
- // From code.google.com: API Key
- var google_api_key = 'XXX';
- // From URL of code.google.com
- var google_project_id = '123';
- // The e-mail that created the project on code.google.com
- var google_sender_id = 'xxx@gmail.com';
- // From Appcelerator App Page
- var geoloqi_app_token = '17a6f-2294d65389369ec02c4529f7405f3923d9a199c5';
- var geoloqi_client_id = '116be7160ead35692dbf2842efc897f1';
- var geoloqi_secret = 'ff9cd1d688e81af374e29f0c4b4cbea4';
- var geoloqi = require('ti.geoloqi');
- geoloqi.addEventListener(geoloqi.ON_VALIDATE, function(e) {
- Ti.API.debug("Validation Error: error_code: " + e.error_code + ", error_description: " + e.error_description);
- });
- geoloqi.addEventListener(geoloqi.LOCATION_CHANGED, function(e) {
- Ti.API.debug("LOCATION_CHANGED: Location: " + e.location);
- });
- geoloqi.addEventListener(geoloqi.LOCATION_UPLOADED, function(e) {
- Ti.API.debug("LOCATION_UPLOADED: number: " + e);
- });
- geoloqi.addEventListener(geoloqi.TRACKER_PROFILE_CHANGED, function(e) {
- Ti.API.debug("TRACKER_PROFILE_CHANGED: OLD_PROFILE: " + e.OLD_PROFILE + ", NEW_PROFILE: " + e.NEW_PROFILE);
- });
- geoloqi.init({
- clientId : geoloqi_client_id,
- clientSecret : geoloqi_secret,
- trackingProfile : 'PASSIVE',
- lowBatteryTracking : true,
- allowAnonymousUsers : false,
- pushAccount : google_sender_id,
- pushSender : google_project_id,
- //account : 'perminder.singh@globallogic.com', // I've never seen 'account' in api.
- icon : 'push_icon'
- }, {
- onSuccess : function() {
- Ti.API.debug('init:onSuccess Called');
- //Ti.API.debug('init:Session: ' + JSON.stringify(geoloqi.session));
- //Ti.API.debug('init:Tracker: ' + JSON.stringify(geoloqi.tracker));
- if (geoloqi.session != null) {
- login.setEnabled('true');
- create.setEnabled('true');
- }
- if (Ti.Platform.osname !== "android") {
- Ti.Network.registerForPushNotifications({
- types : [Titanium.Network.NOTIFICATION_TYPE_ALERT],
- callback : function(data) {
- geoloqi.iOS.handlePush(data);
- },
- success : function(data) {
- Ti.API.info("Push Registered for " + data.deviceToken);
- geoloqi.iOS.registerDeviceToken(data.deviceToken, "live");
- },
- error : function(data) {
- Ti.API.info("Could Not Register For Push" + data.error + data.type);
- }
- });
- }
- },
- onFailure : function(e) {
- Ti.API.debug('init:onFailure Called: error_code: ' + e.error_code + ', error_description: ' + e.error_description);
- }
- });
- var header = Titanium.UI.createLabel({
- text : 'Geoloqi Android SDK',
- height : '80',
- width : '100%',
- backgroundColor : '#444444',
- color : 'white',
- font : {
- fontSize : 20,
- fontWeight : 'bold'
- },
- textAlign : Titanium.UI.TEXT_ALIGNMENT_CENTER
- });
- var onSuccess = Titanium.UI.createLabel({
- text : 'onSuccess',
- top : '10',
- height : 'auto',
- width : '100%',
- color : 'white',
- backgroundColor : '#444444',
- textAlign : Titanium.UI.TEXT_ALIGNMENT_LEFT
- });
- var onComplete = Titanium.UI.createLabel({
- text : 'onComplete',
- top : '10',
- height : 'auto',
- width : '100%',
- color : 'white',
- backgroundColor : '#444444',
- textAlign : Titanium.UI.TEXT_ALIGNMENT_LEFT
- });
- var onFailure = Titanium.UI.createLabel({
- text : 'onFailure',
- top : '10',
- height : 'auto',
- width : '100%',
- color : 'white',
- backgroundColor : '#444444',
- textAlign : Titanium.UI.TEXT_ALIGNMENT_LEFT
- });
- var login = Titanium.UI.createButton({
- title : 'login',
- top : 10,
- width : 100,
- height : 50,
- enabled : false
- });
- var create = Titanium.UI.createButton({
- title : 'create user',
- top : 10,
- width : 100,
- height : 50,
- enabled : false
- });
- var update = Titanium.UI.createButton({
- title : 'Update',
- top : 10,
- width : 100,
- height : 50,
- enabled : false
- });
- create.addEventListener('click', function(e) {
- geoloqi.session.postRequest("user/create", {
- "client_id" : geoloqi_client_id,
- "client_secret" : geoloqi_secret,
- "username" : "bob2",
- "password" : "bob2",
- "device_id" : Ti.Platform.id, // Never Saved
- "mac" : Ti.Platform.macaddress // Never Saved
- }, {
- onSuccess : function(e) {
- update.setEnabled('true');
- onSuccess.setText(e);
- },
- onFailure : function(e) {
- onFailure.setText(e);
- },
- onComplete : function(e) {
- onComplete.setText(e);
- }
- });
- });
- /** Try and Update this user with device_id and mac. Doesn't do anything. **/
- update.addEventListener('click', function(e) {
- geoloqi.session.postRequest("user/update/" + geoloqi.session.getUserId(), {
- "client_id" : geoloqi_client_id,
- "client_secret" : geoloqi_secret,
- "device_id" : Ti.Platform.id,
- "mac" : Ti.Platform.macaddress,
- }, {
- onSuccess : function(e) {
- onSuccess.setText(e);
- },
- onFailure : function(e) {
- onFailure.setText(e);
- },
- onComplete : function(e) {
- onComplete.setText(e);
- }
- });
- });
- window.add(header);
- window.add(onSuccess);
- window.add(onComplete);
- window.add(onFailure);
- window.add(create);
- window.add(update);
- window.open();
Add Comment
Please, Sign In to add comment