Skip to content

Instantly share code, notes, and snippets.

View tonylukasavage's full-sized avatar
💭
Learning to make games

Tony Lukasavage tonylukasavage

💭
Learning to make games
View GitHub Profile
@tonylukasavage
tonylukasavage / GonzoPreferenceWindow.as
Created July 26, 2011 20:08
Unsexy scroll position hackery
// fontList == s:List
// arrList == s:ArrayList for enumerated fonts
fontList.selectedIndex = -1;
for (var i:uint = 0; i < arrList.length; i++) {
if (arrList.getItemAt(i).fontName == FONT_NAME_TO_MATCH) {
fontList.selectedIndex = i;
fontList.layout.verticalScrollPosition = fontList.dataGroup.contentHeight * (i/(arrList.length-1)) - (fontList.height/2) + 8;
break;
}
@tonylukasavage
tonylukasavage / snip.js
Created September 1, 2011 19:39
cross-platform labels with padding in tableviewrow
var isAndroidValue = undefined;
function isAndroid() {
if (isAndroidValue === undefined) {
isAndroidValue = Ti.Platform.osname;
}
return isAndroidValue;
}
// The trick here is that `left` and `right` would constantly give me the wrong height and truncate the Label text
// when using padded Labels in a TableViewRow on Android. They work fine on iOS though. To get around this I just use
@tonylukasavage
tonylukasavage / app.js
Created September 30, 2011 15:06
Appcelerator: PDF Intent
Ti.UI.setBackgroundColor('#222');
var win = Ti.UI.createWindow({
navBarHidden: true,
exitOnClose: true
});
var button = Ti.UI.createButton({
title: 'open pdf',
height: '60dp',
width: '120dp',
Ti.UI.setBackgroundColor('#222');
var win = Ti.UI.createWindow({
navBarHidden: true,
exitOnClose: true
});
var button = Ti.UI.createButton({
title: 'open pdf',
height: '60dp',
width: '120dp',
var appFilePath = Ti.Filesystem.resourcesDirectory + 'w4.pdf';
var appFile = Ti.Filesystem.getFile(appFilePath);
var tmpFile = undefined,
newPath = undefined;
if (Ti.Filesystem.isExternalStoragePresent()) {
tmpFile = Ti.Filesystem.createTempFile();
newPath = tmpFile.nativePath + '.pdf';
tmpFile.move(newPath);
tmpFile = Ti.Filesystem.getFile(newPath);
button.addEventListener('click', function(e) {
if (tmpFile) {
var intent = Ti.Android.createIntent({
action: Ti.Android.ACTION_VIEW,
type: "application/pdf",
data: tmpFile.nativePath
});
try {
Ti.Android.currentActivity.startActivity(intent);
win.addEventListener('close', function(e) {
tmpFile.deleteFile();
});
win.add(button);
win.open();
@tonylukasavage
tonylukasavage / .gitignore
Created November 29, 2011 14:03
.gitignore for Titanium Mobile projects
tmp
.DS_Store
build/iphone/*
!build/iphone/.gitignore
build/android/*
!build/android/.gitignore
.settings
build.log
.fastdev.lock
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<string name="appname">Cat</string>
</resources>
<!-- ... -->
<!-- TI_MANIFEST -->
<application android:icon="@drawable/appicon"
android:label="@string/app_name" android:name="TestlocApplication"
android:debuggable="false">
<!-- TI_APPLICATION -->
<activity android:name=".TestlocActivity"
android:label="@string/app_name" android:theme="@style/Theme.Titanium"