Skip to content

Instantly share code, notes, and snippets.

View nuno's full-sized avatar

Nuno Costa nuno

View GitHub Profile
// I am pretty sure there is a sexier approach, but this works nicely
var isPhone5 = Ti.Platform.displayCaps.platformHeight == 568;
parse568hImages = function(imagePath) {
if (isPhone5){
// Do this because the filename could contain dots
imagePath = imagePath.replace(".png","-568h@2x.png");
imagePath = imagePath.replace(".jpg","-568h@2x.jpg");
imagePath = imagePath.replace(".jpeg","-568h@2x.jpeg");
}
@nuno
nuno / gist:6660509
Last active December 23, 2015 16:09 — forked from benbahrenburg/gist:1103324
Saving XHR Results to a file
var xhr = Titanium.Network.createHTTPClient();
xhr.onload = function()
{
var results = this.responseText;
Ti.API.info('Results from xhr Lookup = ' + results );
var supportDir = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,'my_support');
if(!supportDir.exists()){
supportDir.createDirectory();
}
@nuno
nuno / foo.js
Created September 22, 2013 16:28 — forked from skypanther/foo.js
Within functions, arguments gives access to any parameters passed to the function. But it's a funky object, not a true array. I'm sure the following behavior is documented, but it caught me off-guard. So I thought I'd share.
var myFunction = function() {
if(typeof arguments[0] == 'function') {
arguments[0](); // throws error: [object Object] is not a function
// but this works
var cb = arguments[0];
cb();
}
};
myFunction(function() {
@nuno
nuno / app.js
Created September 22, 2013 16:29 — forked from skypanther/app.js
Cache Remote Images
var Utils = {
/* modified version of https://gist.github.com/1243697
* adds detection of file extension rather than hard-coding .jpg as in the original
*/
_getExtension: function(fn) {
// from http://stackoverflow.com/a/680982/292947
var re = /(?:\.([^.]+))?$/;
var tmpext = re.exec(fn)[1];
return (tmpext) ? tmpext : '';
},
@nuno
nuno / titaniumAlphaColor
Last active December 18, 2019 15:01
Transparency in background of views in Appcelerator Titanium Titanium supports the RGBA color space which means you can use transparent colors! Via: https://coderwall.com/p/pu4isw
var viewWithTransparentBackground = Titanium.UI.createView({
backgroundColor: 'rgba(0,0,0,0.5)' // RGB way: Black background at 0.5 alpha
});
//OR
var viewWithTransparentBackground = Titanium.UI.createView({
backgroundColor: "#50ff0000" // hex way: red background at 0.5 alpha
});
@nuno
nuno / loader
Created September 29, 2013 02:24 — forked from artanisdesign/loader
var CircleLoaderView = require("CircleLoaderView");
var myloader = new CircleLoaderView({
width : 200,
centerWidth : 100,
backgroundColor : "#fff",
tintColor : "blue",
textColor : "red",
labelFontSize : 28
@nuno
nuno / file.tss
Last active December 24, 2015 13:09
Android Horizontal "scrollView"
"#scrollView": {
layout:"horizontal",
contentWidth: Ti.UI.SIZE, //andoid important
height:260,
scrollType:"horizontal",
horizontalWrap: false //andoid important
},
".view": {
height:260,
width:220,
function doClickMenu(evt){
alert(evt.source.title);
}
// we need to do some things to the Window once it is properly instanciated, so we add an event listener to its OPEN event
$.win.addEventListener('open',function(){
var actionBar = $.win.activity.actionBar; // get a handle to the action bar
actionBar.title='My App'; // change the App Title
actionBar.displayHomeAsUp=true; // Show the "angle" pointing back
actionBar.onHomeIconItemSelected = function() { // what to do when the "home" icon is pressed
var PX = require('com.pixate.framework');
PX.styleSheetFromFilePathWithOrigin({
monitor: true,
origin: 0,
filename: '/path/to/file.css'
});
PX.styleSheetFromFilePathWithOrigin({
monitor: true,
origin: 0,
filename: '/path/to/second_file.css'
@nuno
nuno / TiDocs.sh
Created November 3, 2013 12:53 — forked from eric-hu/TiDocs.sh
#! /bin/sh
# Run this from the folder you want to be the parent of your docs
# By default, generated docs go into
# titanium_mobile/dist/apidoc/ti_mobile_docs/
#
# This can be changed below
git clone https://github.com/appcelerator/titanium_mobile.git
cd titanium_mobile
sudo apt-get install python-setuptools python-dev