Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Test code:
- /**
- * Create a new `Ti.UI.TabGroup`.
- */
- var tabGroup = Ti.UI.createTabGroup();
- /**
- * Add the two created tabs to the tabGroup object.
- */
- tabGroup.addTab(createTab("Tab 1", "I am Window 1", "assets/images/tab1.png"));
- tabGroup.addTab(createTab("Tab 2", "I am Window 2", "assets/images/tab2.png"));
- /**
- * Open the tabGroup
- */
- tabGroup.open();
- /**
- * Creates a new Tab and configures it.
- *
- * @param {String} title The title used in the `Ti.UI.Tab` and it's included `Ti.UI.Window`
- * @param {String} message The title displayed in the `Ti.UI.Label`
- * @return {String} icon The icon used in the `Ti.UI.Tab`
- */
- function createTab(title, message, icon) {
- var win = Ti.UI.createWindow({
- title: title,
- backgroundColor: '#fff'
- });
- var label = Ti.UI.createLabel({
- text: message,
- color: "#333",
- font: {
- fontSize: 20
- }
- });
- win.add(label);
- var tab = Ti.UI.createTab({
- title: title,
- icon: icon,
- window: win
- });
- return tab;
- }
- // added during app creation. this will automatically login to
- // ACS for your application and then fire an event (see below)
- // when connected or errored. if you do not use ACS in your
- // application as a client, you should remove this block
- (function(){
- var ACS = require('ti.cloud'),
- env = Ti.App.deployType.toLowerCase() === 'production' ? 'production' : 'development',
- username = Ti.App.Properties.getString('acs-username-'+env),
- password = Ti.App.Properties.getString('acs-password-'+env);
- // if not configured, just return
- if (!env || !username || !password) { return; }
- /**
- * Appcelerator Cloud (ACS) Admin User Login Logic
- *
- * fires login.success with the user as argument on success
- * fires login.failed with the result as argument on error
- */
- ACS.Users.login({
- login:username,
- password:password,
- }, function(result){
- if (env==='development') {
- Ti.API.info('ACS Login Results for environment `'+env+'`:');
- Ti.API.info(result);
- }
- if (result && result.success && result.users && result.users.length){
- Ti.App.fireEvent('login.success',result.users[0],env);
- Ti.API.info("Welcome Rakhi");
- //var phto1=Titanium.Filesystem.resourcesDirectory.getFile('tab1.png');
- var phto1 = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,'tab1.png');
- ACS.Objects.create({
- classname: 'cars',
- fields: {
- make: 'nissan',
- color: 'blue',
- year: 2005,
- photo:phto1
- }
- }, function (e) {
- if (e.success) {
- var car = e.cars[0];
- Ti.API.info('Creation Success:\n' +
- 'id: ' + car.id + '\n' +
- 'make: ' + car.make + '\n' +
- 'color: ' + car.color + '\n' +
- 'year: ' + car.year + '\n' +
- 'photo: ' + car.photo + '\n' +
- 'created_at: ' + car.created_at);
- var savedcarId= car.id;
- Ti.API.info('Saved car ID' +savedcarId);
- var updatephto = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory,'tab2@3x.png');
- if(savedcarId){
- Ti.API.info('Saved car ID+++' +savedcarId);
- ACS.Objects.update({
- classname: 'cars',
- id: savedcarId,
- fields: {
- color: 'purple',
- mileage: 10000,
- photo:updatephto
- }
- }, function (e) {
- if (e.success) {
- var car = e.cars[0];
- Ti.API.info('Update Successful:\n' +
- 'id: ' + car.id + '\n' +
- 'make: ' + car.make + '\n' +
- 'color: ' + car.color + '\n' +
- 'year: ' + car.year + '\n' +
- 'photo: ' + car.photo + '\n' +
- 'mileage: ' + car.mileage + '\n' +
- 'updated_at: ' + car.updated_at);
- } else {
- alert('Error:\n' +
- ((e.error && e.message) || JSON.stringify(e)));
- }
- });
- }else{
- Ti.API.info('Update falied');
- }
- } else {
- alert('Error:\n' +
- ((e.error && e.message) || JSON.stringify(e)));
- }
- });
- } else {
- Ti.App.fireEvent('login.failed',result,env);
- }
- });
- })();
- Console logs:
- [INFO] : I/System.out: ActivityRecorder: before org.appcelerator.titanium.TiActivity@f4fc27a_onCreate(), launchUrl = null
- [INFO] : I/System.out: ActivityRecorder: before org.appcelerator.titanium.TiActivity@f4fc27a_onCreate(), launchUrl = null
- [INFO] : I/System.out: ActivityRecorder: after org.appcelerator.titanium.TiActivity@f4fc27a_onCreate(), launchUrl = null
- [INFO] : I/System.out: ActivityRecorder: after org.appcelerator.titanium.TiActivity@f4fc27a_onCreate(), launchUrl = null
- [INFO] : OpenGLRenderer: Initialized EGL, version 1.4
- [WARN] : EGL_emulation: eglSurfaceAttrib not implemente
- [INFO] : ACS Login Results for environment `development`:
- [INFO] : [object Object]
- [INFO] : Welcome Rakhi
- [INFO] : Creation Success:
- [INFO] : id: 5ac5e1fc04120102212c539a
- [INFO] : make: nissan
- [INFO] : color: blue
- [INFO] : year: 2005
- [INFO] : photo: [object Object]
- [INFO] : created_at: 2018-04-05T08:44:44+0000
- [INFO] : Saved car ID5ac5e1fc04120102212c539a
- [INFO] : Saved car ID+++5ac5e1fc04120102212c539a
- [WARN] : TiBaseFile: (main) [8229,8229] Method is not supported org.appcelerator.titanium.io.TiResourceFile : getParent
- [INFO] : Update Successful:
- [INFO] : id: 5ac5e1fc04120102212c539a
- [INFO] : make: nissan
- [INFO] : color: purple
- [INFO] : year: 2005
- [INFO] : photo: [object Object]
- [INFO] : mileage: 10000
- [INFO] : updated_at: 2018-04-05T08:44:47+0000
- [INFO] : APSAnalyticsService: Analytics Service Started
- [INFO] : APSAnalyticsService: Stopping Analytics Service
Add Comment
Please, Sign In to add comment