Skip to content

Commit

Permalink
Wrap all UTiLs in example app
Browse files Browse the repository at this point in the history
  • Loading branch information
FokkeZB committed Apr 28, 2015
1 parent 22ba8ef commit 4a13eaa
Show file tree
Hide file tree
Showing 102 changed files with 9,760 additions and 601 deletions.
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
ui/test/app
.DS_Store
Resources
build.log
build
npm-debug.log
tmp
.map
.project
.settings
Thumbs.db
59 changes: 28 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,54 +1,51 @@
# UTiL [![Titanium](http://www-static.appcelerator.com/badges/titanium-git-badge-sq.png)](http://www.appcelerator.com/titanium/) [![Alloy](http://www-static.appcelerator.com/badges/alloy-git-badge-sq.png)](http://www.appcelerator.com/alloy/)
A collection of utility scripts for [Appcelerator](http://www.appcelerator.com)'s [Titanium](http://www.appcelerator.com/platform) and it's [Alloy](http://projects.appcelerator.com/alloy/docs/Alloy-bootstrap/index.html) MVC framework.
A collection of utility libraries for [Appcelerator](http://www.appcelerator.com)'s [Titanium](http://www.appcelerator.com/platform) and it's [Alloy](http://projects.appcelerator.com/alloy/docs/Alloy-bootstrap/index.html) MVC framework. The app contains samples and tests for some of the libraries.

*This is a public, but personal library of utility scripts. They may change at any time without notice! Feel free to fork and contribute, but I'll decide what PR's to accept based on their potential use for my projects.*
*This is a public, but personal library. It may change at any time without notice! Feel free to fork and contribute, but I'll decide what PR's to accept based on their potential use for my own projects.*

## [Error Reporter](https://github.com/FokkeZB/UTiL/tree/master/reporter)
CommonJS module using `yy.logcatcher` to let the user report run-time errors.

## [update](https://github.com/FokkeZB/UTiL/tree/master/update)
CommonJS module checking for updates of the app.
## XCallbackURL: [docs](docs/XCallbackURL.md) / [source](app/lib/XCallbackURL.js)
CommonJS module for parsing URLs according to the X-Callback-URL standard.

## [ui](https://github.com/FokkeZB/UTiL/tree/master/ui)
CommonJS module extending some `Ti.UI.create*` factories.
## Alloy: [docs](docs/alloy.md) / [source](app/lib/alloy.js)
CommonJS module to allow modules built for Alloy to function in classic projects.

## [XP.UI](https://github.com/FokkeZB/UTiL/tree/master/xp.ui)
CommonJS module providing cross-platform UI elements.
## Gate: [docs](docs/gate.md) / [source](app/lib/gate.js) / [example](app/controllers/gate.js)
CommonJS module providing simple mathematical question as parental gate for kids apps.

## [Urban Airport](https://github.com/FokkeZB/UTiL/tree/master/urbanairport)
CommonJS module wrapping Appcelerator's iOS and Android modules for Urban Airship.
## Image: [docs](docs/image.md) / [source](app/lib/image.js) / [example](app/controllers/image.js)
CommonJS module providing image manipulation methods.

## [Share](https://github.com/FokkeZB/UTiL/tree/master/share)
CommonJS module providing a one-in-all social sharing solution for iOS and Android.
## Menu: [docs](docs/menu.md) / [source](app/lib/menu.js)
CommonJS module for managing the Android Activity Menu and ActionBar.

## [Rate](https://github.com/FokkeZB/UTiL/tree/master/rate)
## Rate: [docs](docs/rate.md) / [source](app/lib/rate.js)
CommonJS module popping the 'rate-my-app' question at just the right time.

## [Parental Gate](https://github.com/FokkeZB/UTiL/tree/master/gate)
CommonJS module providing simple mathematical question as parental gate for kids apps.
## Reporter: [docs](docs/reporter.md) / [source](app/lib/reporter.js)
CommonJS module using `yy.logcatcher` to let the user report run-time errors.

## [Faceboost](https://github.com/FokkeZB/UTiL/tree/master/faceboost)
CommonJS module wrapping the Facebook module with additional methods.
## Share: [docs](docs/share.md) / [source](app/lib/share.js)
CommonJS module providing a one-in-all social sharing solution for iOS and Android.

## [Menu](https://github.com/FokkeZB/UTiL/tree/master/menu)
CommonJS module for managing the Android Activity Menu and ActionBar.
## UI: [docs](docs/ui.md) / [source](app/lib/ui.js) / [example](app/controllers/ui`.js)
CommonJS module extending some `Ti.UI.create*` factories.

## [Validate](https://github.com/FokkeZB/UTiL/tree/master/validate)
CommonJS module providing validation.
## Update: [docs](docs/update.md) / [source](app/lib/update.js)
CommonJS module checking for updates of the app.

## [Alloy](https://github.com/FokkeZB/UTiL/tree/master/alloy)
CommonJS module to allow modules built for Alloy to function in classic projects.
## Urban Airport: [docs](docs/urbanairport.md) / [source](app/lib/urbanairport.js)
CommonJS module wrapping Appcelerator's iOS and Android modules for Urban Airship.

## [Image](https://github.com/FokkeZB/UTiL/tree/master/image)
CommonJS module providing image manipulation methods.
## Validate: [docs](docs/validate.md) / [source](app/lib/validate.js)
CommonJS module providing validation.

## [XCallbackURL](https://github.com/FokkeZB/UTiL/tree/master/XCallbackURL)
CommonJS module for parsing URLs according to the X-Callback-URL standard.
## XP.UI: [docs](docs/xp.ui.md) / [source](app/lib/xp.ui.js)
CommonJS module providing cross-platform UI elements.

# License

<pre>
Copyright 2013 Fokke Zandbergen
Copyright 2013-2015 Fokke Zandbergen

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
11 changes: 11 additions & 0 deletions app/alloy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// The contents of this file will be executed before any of
// your view controllers are ever executed, including the index.
// You have access to all functionality on the `Alloy` namespace.
//
// This is a great place to do any initialization for your app
// or create any global variables/functions that you'd like to
// make available throughout your app. You can easily make things
// accessible globally by attaching them to the `Alloy.Globals`
// object. For example:
//
// Alloy.Globals.someGlobalFunction = function(){};
Binary file added app/assets/android/appicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/android/default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added app/assets/iphone/Default-568h@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/iphone/Default-667h@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/iphone/Default-Landscape-736h@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/iphone/Default-Landscape.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/iphone/Default-Landscape@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/iphone/Default-Portrait-736h@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/iphone/Default-Portrait.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/iphone/Default-Portrait@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/iphone/Default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/iphone/Default@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/iphone/appicon-60.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/iphone/appicon-60@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/iphone/appicon-60@3x.png
Binary file added app/assets/iphone/appicon-72.png
Binary file added app/assets/iphone/appicon-72@2x.png
Binary file added app/assets/iphone/appicon-Small-50.png
Binary file added app/assets/iphone/appicon-Small.png
Binary file added app/assets/iphone/appicon-Small@2x.png
Binary file added app/assets/iphone/appicon.png
Binary file added app/assets/iphone/appicon@2x.png
Binary file added app/assets/iphone/iTunesArtwork
Binary file not shown.
Binary file added app/assets/iphone/iTunesArtwork@2x
Binary file not shown.
11 changes: 11 additions & 0 deletions app/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"global": {},
"env:development": {},
"env:test": {},
"env:production": {},
"os:android": {},
"os:ios": {},
"os:mobileweb": {},
"os:windows": {},
"dependencies": {}
}
54 changes: 54 additions & 0 deletions app/controllers/gate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
var gate = require('gate');

(function constructor(args) {

showStatus();

// Optionally override settings
gate.locked = true; // Lock/Unlock gate
gate.from = 1; // Minimum for random 'x'
gate.to = 10; // Maximum for random 'y'

// Optionally override texts (also via i18n)
gate.title = 'Checking your IQ'; // gate_title
gate.message = 'How much is %s ?'; // gate_message
gate.button = 'Try'; // gate_button
gate.error_title = 'You failed big time!'; // gate_error_title
gate.error_message = 'No, you stupid! It was %s !'; // gate_error_message
gate.error_button = 'OK'; // gate_error_button

})(arguments[0] || {});

function onKeeperClick() {

gate.keeper(function (success) {

// Returns TRUE if the gate was unlocked or question was answered OK
if (success) {
alert('This alert is something for adults only.');
}

// On FALSE an error dialog will be shown
// No further action needed in most cases
});

}

function onToggleClick() {

gate.toggle(function (locked) {
// Returns TRUE if gate is now locked
// Presents question only to unlock, not to lock

showStatus(locked);
});
}

function showStatus(locked) {

if (arguments.length === 0) {
locked = gate.locked;
}

$.statusLabel.text = locked ? 'Locked' : 'Unlocked';
}
25 changes: 25 additions & 0 deletions app/controllers/image.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var image = require('image');

(function constructor(args) {})(arguments[0] || {});

function onSelectClick() {

image.select(function (err, media) {

if (err) {
return alert(err);
}

var dp = $.imageView.rect;

$.imageView.image = image.crop(media, dp);

var px = image.dpToPixels(dp);

Ti.UI.createAlertDialog({
title: 'ImageView in DP: ' + dp.width + 'x' + dp.height,
message: 'Image in PX: ' + px.width + 'x' + px.height
}).show();
});

}
5 changes: 5 additions & 0 deletions app/controllers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function doClick(e) {
alert($.label.text);
}

$.index.open();
20 changes: 20 additions & 0 deletions app/controllers/ui.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(function constructor(args) {

$.singleBtn.addEventListenerSingle(onSingleClick);
$.onceBtn.addEventListenerOnce('click', onOnceClick);

})(arguments[0] || {});

function onSingleClick(e) {
alert('I will now block for a while');

for (var i = 0; i < 1000000; i++) {
Ti.Platform.createUUID();
}

alert('You can now click me again');
}

function onOnceClick(e) {
alert('You can not click me again');
}
1 change: 1 addition & 0 deletions app/controllers/xp.ui.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(function constructor(args) {})(arguments[0] || {});
File renamed without changes.
File renamed without changes.
133 changes: 133 additions & 0 deletions app/lib/image.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
var logicalDensityFactor;

exports.crop = crop;
exports.dpToPixels = dpToPixels;
exports.select = select;

function crop(blob, options, height) {

if (typeof options !== 'object') {
options = {
width: options,
height: height
}
}

if (!blob.width || !blob.width) {
return blob;
}

// https://jira.appcelerator.org/browse/TIMOB-4865
if (options.fix !== false) {
blob = blob.imageAsResized(blob.width, blob.height);
}

if (options.hires !== false) {
options = dpToPixels(options);
}

if (options.width && options.height) {
var blob_ratio = blob.width / blob.height;
var ratio = options.width / options.height;

if (blob_ratio !== ratio) {

// Cut left and right
if (blob_ratio > ratio) {
blob = blob.imageAsCropped({
width: Math.round(blob.height * ratio),
});
}

// Cut top and bottom
else {
blob = blob.imageAsCropped({
height: Math.round(blob.width / ratio)
});
}
}

if (blob.width !== options.width || blob.height !== options.height) {
blob = blob.imageAsResized(options.width, options.height);
}

return blob

} else {
return blob.imageAsCropped(options);
}
}

function dpToPixels(dimension) {

if (!logicalDensityFactor) {
logicalDensityFactor = Ti.Platform.displayCaps.logicalDensityFactor;
}

if (typeof dimension === 'number') {
return dimension * logicalDensityFactor;
}

if (dimension.width) {
dimension.width = dimension.width * logicalDensityFactor;
}

if (dimension.height) {
dimension.height = dimension.height * logicalDensityFactor;
}

return dimension;
}

function select(opts, callback) {

if (arguments.length === 1) {
callback = opts;
opts = {};
}

if (!Ti.Media.isCameraSupported) {
return _select('openPhotoGallery', opts, callback);
}

var dialog = Ti.UI.createOptionDialog({
options: [L('image_select_camera'), L('image_select_gallery'), L('cancel')],
cancel: 2
});

dialog.addEventListener('click', function (e) {

if (e.index === 0) {
_select('showCamera', opts, _callback);
} else if (e.index === 1) {
_select('openPhotoGallery', opts, _callback);
}
});

dialog.show();
}

function _select(fn, opts, callback) {

if (arguments.length === 2 && _.isFunction(opts)) {
callback = opts;
opts = {};
}

var defaults = {
mediaTypes: [Ti.Media.MEDIA_TYPE_PHOTO]
};

if (callback) {
defaults.success = function (e) {
callback(null, e.media);
};
defaults.error = function (e) {
callback(e.error);
};
}

opts = _.defaults(opts || {}, defaults);

Ti.Media[fn](opts);
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 4a13eaa

Please sign in to comment.