Skip to content

Instantly share code, notes, and snippets.

View QGao's full-sized avatar

Qing Gao QGao

  • Mountain View, CA
View GitHub Profile
@QGao
QGao / app.js
Created December 2, 2011 23:08
A sample of using convertPointToView
var win = Ti.UI.createWindow(
{ backgroundColor: 'black' }
);
var center1 = {'x': 100, 'y':100};
var center2 = {'x': 100, 'y':250};
var lastIndex = 1;
var background = Ti.UI.createView({ backgroundColor:"#444444", });
var view = Ti.UI.createView({ backgroundColor:'red', center:center1, width:100, height:100, zIndex:lastIndex++, });
var view2 = Ti.UI.createView({ backgroundColor:'green', center:center2, width:100, height:100, zIndex:lastIndex, });
background.addEventListener('touchstart', function(e){
@QGao
QGao / "DO NOT BACKUP" flag for iCloud
Created December 6, 2011 01:07
A sample shows how to set the "DO NOT BACKUP" flag in TiSDK
var newDir = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,'mydir');
Ti.API.info("Created mydir: " + newDir.createDirectory());
Ti.API.info('newdir ' + newDir);
var newFile = Titanium.Filesystem.getFile(newDir.nativePath,'backup.txt');
if(newFile.exists()){
newFile.write("I should be backed up!");
newFile.remoteBackup = true;
//or we can set the whole folder to be iCloudable
//newDir.remoteBackup = true;
}
@QGao
QGao / md5
Created December 7, 2011 02:04
TiSDK MD5 sample
var win = Ti.UI.createWindow({ backgroundColor: 'red' });
var md5 = Ti.Utils.md5HexDigest(win.toImage());
var label = Ti.UI.createLabel({
text:md5
});
win.add(label);
win.open();
@QGao
QGao / gist:1473514
Created December 13, 2011 19:30
toImage to png file sample
var win = Ti.UI.createWindow({
backgroundColor:'#fff'
});
var view = Ti.UI.createImageView({
height: 200,
backgroundColor:'#f00'
})
win.add(view);
@QGao
QGao / gist:1473515
Created December 13, 2011 19:30
toImage to png file sample
var win = Ti.UI.createWindow({
backgroundColor:'#fff'
});
var view = Ti.UI.createImageView({
height: 200,
backgroundColor:'#f00'
})
win.add(view);
@QGao
QGao / gist:1650137
Created January 20, 2012 23:11
A n ice singleton patten sample from Rick
/**
* A singleton object
*
* Singleton objects are useful but use them sparingly. By using singletons
* you are creating dependencies in your software that might not be necessary.
* If you find yourself using this over and over again you probably need
* to rethink what you're doing. Remember, in general, globals are bad.
*/
var Preferences = {
fbToken: '1234',
@QGao
QGao / gist:2564011
Created May 1, 2012 00:37
A sample for sending email.
var win = Ti.UI.createWindow();
var label1 = Ti.UI.createLabel
({
text:'Some Documents listed',
font:{fontWeight:'bold', fontSize:14},
color: '#8c0000',
height: 'auto',
left: 10,
top:10
-------content of app.js--------
Ti.include('somefolder/platform.js');
Ti.include('somefolder/API.js');
Ti.include('somefolder/modules.js');
Ti.include('somefolder/UI.js');
MyApp = {
Platform:{},
API:{},
Modules:{},
var lineItemsSection = Ti.UI.createTableViewSection({
headerView : lineItemsHeaderView
});
var rows = [];
for(var i = 0; i < itemCount; i++) {
var tableViewRow = Ti.UI.createTableViewRow({
id : "lineItemDetails",
data : data[i],
/**
* Global singleton
*/
var APP = {
/**
* This sets up global events, persistant things
* throughout the app, etc. Only should be called
* when the app is booted.
*/