Skip to content

Instantly share code, notes, and snippets.

View dawsontoth's full-sized avatar

Dawson Toth dawsontoth

View GitHub Profile
@dawsontoth
dawsontoth / InfiniteScrollableView.js
Created February 3, 2011 20:54
Infinite scrollable list.
/**
* We're going to create an infinite scrollable list. In this case, we're going to show a date. When you swipe left,
* you'll see yesterday. Then the day before yesterday, and so on. Swiping right shows you tomorrow, and so on.
*/
var win = Ti.UI.createWindow({ backgroundColor: '#fff' });
var isAndroid = Ti.Platform.osname === 'android';
/**
* Track where we are in the infinite scrollable views, and define how large of a step goes between each view.
*/
var currentDate = new Date(), msIntervalBetweenViews = 1000/*ms*/ * 60/*s*/ * 60/*m*/ * 24/*h*/;
@dawsontoth
dawsontoth / InfiniteScrollingTableView.js
Created February 3, 2011 22:49
Infinite loading table view for iOS and Android.
/**
* We're going to create an infinite loading table view. Whenever you get close to the bottom, we'll load more rows.
*/
var win = Ti.UI.createWindow({ backgroundColor: '#fff' });
var isAndroid = Ti.Platform.osname === 'android';
/**
* Create our UI elements.
*/
var table = Ti.UI.createTableView({ top: 0, right: 0, bottom: 0, left: 0 });
@dawsontoth
dawsontoth / app.js
Created February 4, 2011 23:21
CSS Injection on External Websites using Appcelerator Titanium
// create our web view
var win = Ti.UI.createWindow({ backgroundColor: "#fff" });
var web = Ti.UI.createWebView({ url: "http://chicago.craigslist.org/" });
// inject our css when the web view finishes loading (because we need to inject into the head element)
web.addEventListener('load', function () {
// first, specify the CSS file that we should load
var cssFileName = 'styles.css';
// read in the contents
var cssFromFile = Ti.Filesystem.getFile(cssFileName);
@dawsontoth
dawsontoth / validateForm.js
Created February 4, 2011 23:37
Quick Form Validation in Appcelerator Titanium (very simplistic)
function validateForm() {
var formIsValid = true;
function enforceTextFieldMinLength(field, minLength) {
if (!field.value || field.value.length < minLength) {
formIsValid = false;
}
}
function enforceLabelHasText(label) {
if (!label.text) {
formIsValid = false;
@dawsontoth
dawsontoth / ImagesInScrollableView.js
Created February 8, 2011 22:41
Simple Titanium scrollable view with 10 images in it
// put this in an app.js and watch it fly!
var win = Ti.UI.createWindow({ backgroundColor: '#fff' });
var views = [];
for (var i = 0; i < 10; i++) {
views.push(Ti.UI.createImageView({
image: 'KS_nav_ui.png',
top: 0, left: 0,
width: 100,
height: 50
@dawsontoth
dawsontoth / Geolocation.js
Created February 9, 2011 23:35
Constantly Updating Geolocation in Appcelerator Titanium
Titanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST;
Titanium.Geolocation.distanceFilter = 0;
var win = Ti.UI.createWindow({backgroundColor: '#fff'});
var label = Ti.UI.createLabel();
win.add(label);
win.open();
function reportPosition(e) {
if (!e.success || e.error) {
@dawsontoth
dawsontoth / tweetView.js
Created February 10, 2011 04:07
Make tweets and links clickable in Titanium Mobile! Here I make a tweet look just like it does on Twitter, and interact the same too.
/**
* Define our parser class. It takes in some text, and then you can call "linkifyURLs", or one of the other methods,
* and then call "getHTML" to get the fully parsed text back as HTML!
* @param text that you want parsed
*/
function Parser(text) {
var html = text;
var urlRegex = /((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi;
@dawsontoth
dawsontoth / LowLevelMouseHooks.cs
Created February 11, 2011 20:42
Adds some low level mouse hooks to a WPF app, turning any left click into a double click.
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace Dawson.Accessibility
{
/// <summary>
/// Interaction logic for MouseHooker.xaml
/// Derived from http://blogs.msdn.com/b/toub/archive/2006/05/03/589468.aspx
/// </summary>
@dawsontoth
dawsontoth / LightweightClickableGrid.js
Created February 16, 2011 17:45
Lightweight clickable grids in Appcelerator Titanium; put this in an app.js!
/**
* Creates a grid that you can click on.
* @param options
*/
function createGrid(options) {
// default options
var defaultOptions = {
gridViewOptions: {
top: 0,
@dawsontoth
dawsontoth / AndroidMenuNavigation.js
Created February 17, 2011 14:23
Menu based navigation in Appcelerator Titanium that supports the use of the "Back" button to go back a view.
// this is your app.js
// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');
// define our main window and open it. it will be an activity (navBarHidden: true), and will control our child window views
Titanium.UI.createWindow({
navBarHidden: true,
backgroundColor: '#fff',
url: 'mainwindow.js',
exitOnClose: true