Skip to content

Instantly share code, notes, and snippets.

@himalay
himalay / app.js
Last active August 29, 2015 14:17 — forked from FokkeZB/app.js
http://developer.android.com/guide/topics/resources/providing-resources.html#ScreenAspectQualifier
if ((Ti.Platform.displayCaps.platformWidth / Ti.Platform.displayCaps.platformHeight) < (((Ti.Gesture.orientation === Ti.UI.LANDSCAPE_LEFT)) ? (320 / 240) : (240 / 320)))) {
Ti.API.info('I am LONG');
} else {
Ti.API.info('I am NOTLONG');
}
@himalay
himalay / index.xml
Last active August 29, 2015 14:17 — forked from FokkeZB/index.xml
Need a Window on IOS but a View on Android in Alloy?
<Alloy>
<Window module="xp.ui">
<Label>Hello World</Label>
</Window>
</Alloy>
@himalay
himalay / app.tss
Last active August 29, 2015 14:17 — forked from FokkeZB/app.tss
Hide titlebar on Android launch/splash screen
// app/styles/app.tss
"Window": {
navBarHidden: false
}
@himalay
himalay / share.js
Last active August 29, 2015 14:17 — forked from FokkeZB/share.js
A simple example of using Android intents to share texts, URLs and files like you could do using 0x82's ShareKit module (https://marketplace.appcelerator.com/apps/741) or any other similar module (TiSocial: https://github.com/viezel/TiSocial.Framework) for iOS
function share(options) {
if (OS_ANDROID) {
var intent = Ti.Android.createIntent({
action: Ti.Android.ACTION_SEND
});
intent.putExtra(Ti.Android.EXTRA_SUBJECT, options.title);
@himalay
himalay / index.tss
Last active August 29, 2015 14:17 — forked from FokkeZB/index.tss
Who said you can't do padding in Titanium (Alloy)?
"#wrapper": {
// Set wrapper to adjust it's size to it's contents
width: Ti.UI.SIZE,
height: Ti.UI.SIZE,
// Set stuff like borders and backgrounds on the wrapper
backgroundColor: "red"
}
@himalay
himalay / app.js
Last active August 29, 2015 14:17 — forked from FokkeZB/app.js
Code Revisions 2 Stars 8 Forks 1 Embed URL HTTPS clone URL You can clone with HTTPS or SSH. Embedding a YouTube video in Titanium
var win = Ti.UI.createWindow();
var webView = Ti.UI.createWebView({
url: 'http://www.youtube.com/embed/' + myVideoID + '?autoplay=1&autohide=1&cc_load_policy=0&color=white&controls=0&fs=0&iv_load_policy=3&modestbranding=1&rel=0&showinfo=0',
enableZoomControls: false,
scalesPageToFit: false,
scrollsToTop: false,
showScrollbars: false
});
@himalay
himalay / singletap.js
Last active August 29, 2015 14:17 — forked from FokkeZB/singletap.js
Snippet from Blain Hamon on how to prevent Titanium from queing up multiple tap events
function handleOnce(funct) {
var flag = false;
return function(e) {
if (flag) return;
flag = true;
setTimeout(function() {
flag = false;
}, 0);
funct(e);
@himalay
himalay / app.js
Last active August 29, 2015 14:17 — forked from FokkeZB/app.js
How to decide what window to open first in Titanium Alloy. You can remove all markup from the index.xml view (the file itself must be there!) and then create another controller based on your logic.
/* /Resources/app.js - Generated by Alloy, here to understand the flow */
var Alloy = require("alloy"), _ = Alloy._, Backbone = Alloy.Backbone;
Alloy.createController("index");
@himalay
himalay / README.md
Last active August 29, 2015 14:17 — forked from FokkeZB/README.md
Setting default unit of measurement.

To make sure your lay-outs look pretty much the same on all devices, including the thousands of different Android resolutions and densities, it's always best to use the 'dp' unit. However, typing '10dp' instead of 10 is quite a pain. A pain you can easily take away by changing the default unit in your tiapp.xml.

@himalay
himalay / CROP.md
Last active August 29, 2015 14:17 — forked from FokkeZB/CROP.md
Image (cropping) CommonJS lib for Titanium CROP.md Often I need to display a user-provided picture in an ImageView in such a way that the whole ImageView is filled with as much of the picture possible. This is how I do it: var image = require('image'); Ti.Media.showCamera({ mediaTypes: [Ti.Media.MEDIA_TYPE_PHOTO], success: function (e) { myImage…

Often I need to display a user-provided picture in an ImageView in such a way that the whole ImageView is filled with as much of the picture possible.

This is how I do it:

var image = require('image');

Ti.Media.showCamera({
        mediaTypes: [Ti.Media.MEDIA_TYPE_PHOTO],
 success: function (e) {