Skip to content

Instantly share code, notes, and snippets.

View rusticphilosopher's full-sized avatar

Opie Cyrus rusticphilosopher

View GitHub Profile
@rusticphilosopher
rusticphilosopher / 1_6_0_geolocation_blog_source
Created February 11, 2011 00:27
Geolocation blog source
var headingAdded = false;
var locationAdded = false;
Ti.Geolocation.preferredProvider = "gps";
var headingCallback = function(e)
{
Ti.API.info("Received heading callback");
}
Ti.Geolocation.addEventListener('heading', headingCallback);
//Create an empty TCP socket
var socket = Ti.Network.Socket.createTCP();
//Create a socket, connect to another listening socket locally, write some data and then enter read loop
var connectSocket = Ti.Network.Socket.createTCP({
host: 'google.com',
port: 80,
connected: function(e) {
Ti.API.info("Socket <" + e.socket + "> connected to host <" + e.socket.host + ">");
postConnect();
},
error: function(e) {
Ti.API.error("Socket <" + e.socket + "> encountered error when connecting");
//Create a socket and listen for incoming connections
var listenSocket = Ti.Network.Socket.createTCP({
port: 40404,
accepted: function(e) {
// this where you would usually store the e.inbound value somewhere else so it can be used for
// read / write operations elsewhere in the app
Ti.API.info("Listening socket <" + e.socket + "> accepted incoming connection <" + e.inbound + ">");
e.inbound.close(); // close the accepted socket
},
var win = Titanium.UI.currentWindow;
// the following example orientationModes values would set orientation to full sensor
win.orientationModes = [Ti.UI.PORTRAIT, Ti.UI.LANDSCAPE_RIGHT];
win.orientationModes = [Ti.UI.PORTRAIT, Ti.UI.UPSIDE_PORTRAIT, Ti.UI.LANDSCAPE_LEFT]
win.orientationModes = [Ti.UI.UPSIDE_PORTRAIT, Ti.UI.LANDSCAPE_LEFT];
var win = Titanium.UI.currentWindow;
// the following example orientationModes values would set orientation to sensor portrait
win.orientationModes = [Ti.UI.PORTRAIT, Ti.UI.UPSIDE_PORTRAIT];
var win = Titanium.UI.currentWindow;
// the following example orientationModes values would set orientation to sensor landscape
win.orientationModes = [Ti.UI.LANDSCAPE_LEFT, Ti.UI.LANDSCAPE_RIGHT];
var win = Titanium.UI.currentWindow;
// the following example orientationModes values would set (and lock) orientation to portrait
win.orientationModes = [Ti.UI.PORTRAIT];
var win = Titanium.UI.currentWindow;
// the following example orientationModes values would set (and lock) orientation to landscape
win.orientationModes = [Ti.UI.LANDSCAPE_LEFT];
var win = Titanium.UI.currentWindow;
// the following example orientationModes values would reset the orientation modes to full sensor
win.orientationModes = [];