Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Andrey Tkachenko falkolab

🏠
Working from home
  • Russian Federation
View GitHub Profile
@falkolab
falkolab / README.md
Last active Jul 18, 2017
How to use latest Alloy with appc CLI
View README.md

If you want to use latest alloy with appc CLI command:

  1. Update Alloy: [sudo] npm install -g alloy

  2. Create file in your project <project root>/plugins/global.alloy/1.0/hooks/global_alloy_hook.js with content:

exports.init = function (logger, config, cli, appc) {
	delete process.env.ALLOY_PATH;
};
@falkolab
falkolab / example.js
Created Mar 17, 2016
How to access to file in storage card `/sdcard/anyfolder/myfile` in Titanium SDK
View example.js
// need storage permission to be added in manifest
function getFileFromExternalStorage(path) {
if(Ti.Filesystem.isExternalStoragePresent()) {
var file = Ti.Filesystem.getFile(Ti.Filesystem.externalStorageDirectory, path);
var newPath = file.nativePath.split(Ti.Filesystem.separator + Ti.App.id).join('');
file = Ti.Filesystem.getFile(newPath);
if(file.exists()) return file;
}
return null;
}
@falkolab
falkolab / alloy.js
Last active Mar 14, 2017
Application launch manager for Titanium SDK
View alloy.js
require('runner').on('run', function(evt) {
// evt.source - runner module reference
var hc = Alloy.CFG.homeController;
// home window launch
Alloy.createController(hc.name, hc.args).getView().open();
});
@falkolab
falkolab / bbcode2html.js
Created Feb 6, 2016
Android: HTML tags and localized strings for Titanium SDK.
View bbcode2html.js
/* Escapes a string for use with regular expressions */
function escapeString(input) {
return input.replace(/([\,\!\\\^\$\{\}\[\]\(\)\.\*\+\?\|\<\>\-\&])/g,
function(c){return "\\" + c;});
}
/* replaces all */
function replaceAll(search, input, replacement, ignore) {
return input.replace(
new RegExp(escapeString(search), "g"+(ignore?"i":"")),
@falkolab
falkolab / fix_timob20357.js
Last active Mar 14, 2016
Fix for Titanium SDK bug TC-5848 (Button 9-patch)
View fix_timob20357.js
/*
Created by: Andrey Tkachenko falko.lab@gmail.com
Source: https://gist.github.com/falkolab/c56585874223216e85d3
This is fix code for https://jira.appcelerator.org/browse/TIMOB-20357
!!! You must use only $.addListener for fixed button NOT button.addEventListener
`win` argument can be omited if controller root is Window already.
example:
@falkolab
falkolab / resizeToContainer.js
Created Jan 28, 2016
Titanium SDK helper to resize
View resizeToContainer.js
function resizePhoto(blob, size) {
var measurement = require('alloy/measurement'), w, h;
if (blob.width / blob.height >= size.width / size.height) {
w = measurement.dpToPX(size.width);
h = blob.height * measurement.dpToPX(size.width) / blob.width;
} else {
w = blob.width * measurement.dpToPX(size.height) / blob.height;
h = measurement.dpToPX(size.height);
@falkolab
falkolab / demo.js
Created Dec 5, 2015
underscore string mixin
View demo.js
//******** underscore.string ***********
var _ = require("alloy/underscore")._;
// Import Underscore.string to separate object,
// because there are conflict functions (include, reverse, contains)
_.str = require('underscore.string');
// Mix in non-conflict functions to Underscore namespace if you want
_.mixin(_.str.exports());
@falkolab
falkolab / alloy.js
Last active Feb 7, 2016
Network state monitor for Titanium SDK
View alloy.js
require('networkMonitor').init();
@falkolab
falkolab / callLog.js
Created Nov 27, 2015
list view databinding helper
View callLog.js
exports.populateCallLog = function(listview, items) {
var helper = require('listViewHelper');
return helper.populate(listview, items, false /*no merge*/, function sectionGenerator(lv, items) {
var moment = require("alloy/moment");
var headerViewCtrl = Alloy.createController('modules/call/log/pickerSectionHeaderView');
var dateTitle,
item = items[0],
utcTime = new Date(),
@falkolab
falkolab / actionBarMenuItem.js
Created Nov 5, 2015
Icon font MenuItem in ActionBar menu for Titanium SDK
View actionBarMenuItem.js
var args = arguments[0] || {};
if(__parentSymbol) {
// recreate menu item
$.getTopLevelViews().length = 0;
__parentSymbol.removeItem(9999);
$.__views.menuItem = __parentSymbol.add(
_.extend(_.pick(args, Alloy.Android.menuItemCreateArgs), {
actionView: $.actionView
})