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 / SVGProduct.js
Created Oct 30, 2015
How to use SVG as autogenerated raster image
View SVGProduct.js
// app/lib/SVGProduct.js
function getImageFileFromSVG(svgOpts, name) {
var file = Ti.Filesystem.getFile(Ti.Filesystem.applicationCacheDirectory,
Ti.Utils.md5HexDigest(JSON.stringify(svgOpts)));
if (!file.exists()) {
var SVG = require('com.geraudbourdin.svgview');
if (!file.write(SVG.createView(svgOpts).toImage())) {
Ti.API.error("Can't save to file. Product:", name);
return null;
@falkolab
falkolab / index.js
Created Oct 29, 2015
How to use SVG as View backgroundImage
View index.js
$.getView().backgroundImage = getImageFileFromSVG({
image : "/images/hearts.svg",
width : 400,
height : 400,
top : 0,
left : 0
});
function getImageFileFromSVG(svgOpts) {
var file = Ti.Filesystem.getFile(Ti.Filesystem.applicationCacheDirectory,
@falkolab
falkolab / momentLang.js
Last active Feb 11, 2016
Set Moment locale to the Titanium SDK Ti.Locale.currentLocale
View momentLang.js
var moment = require('alloy/moment');
// First add languages that support your application
var languages = ['ru', 'nl', 'fr', 'fr-ca'];
// Full language list: https://github.com/appcelerator/alloy/tree/master/Alloy/builtins/moment/lang
// You must explicit way to require language files in order to compiler saw their.
require('alloy/moment/lang/ru');
require('alloy/moment/lang/nl');
require('alloy/moment/lang/fr');
@falkolab
falkolab / fixmenu.js
Last active Feb 14, 2016
Fix for not displayed ActionBar menu in Titanium SDK
View fixmenu.js
// Not rendered menu fix
// Author: Andrey Tkachenko, falkolab
// Source: https://gist.github.com/falkolab/29ab007f4981f1d747f2
exports.fix = function(win) {
if (win.activity) {
win.addEventListener('open', function fixMenu(evt) {
evt.source.removeEventListener(evt.type, fixMenu);
var activity = evt.source.activity;
if (activity.onCreateOptionsMenu) {
activity.onCreateOptionsMenu = _.partial(function(func, e) {
@falkolab
falkolab / alloy.js
Last active Oct 15, 2015
Android VERSION_CODES for Titanium SDK
View alloy.js
Alloy.Globals.Android = Alloy.Globals.Android || {};
_.extend(Alloy.Globals.Android.VERSION_CODES, {
CUR_DEVELOPMENT: 10000,
BASE: 1,
BASE_1_1: 2,
CUPCAKE: 3,
DONUT: 4,
ECLAIR: 5,
ECLAIR_0_1: 6,
ECLAIR_MR1: 7,
View demo.js
var args = arguments[0] || {};var url = "https://api.github.com/search/repositories?q=pushed:>2015-09-01&order=desc";
var page = 1,
loading = false;
function init() {
$.activityIndicator.show();
load(function(items) {
$.list.setItems(transform(items));
$.activityIndicator.hide();
@falkolab
falkolab / index.js
Last active Sep 22, 2015
Memory leak test case for Titanium SDK
View index.js
function doClick(e) {
Alloy.createController("test").getView().open();
}
$.index.open();
@falkolab
falkolab / base.js
Last active Sep 4, 2015
View proxy remain in memory after window closed. https://yadi.sk/i/jmtrY-I0isR3g
View base.js
exports.setMenuItemEnabled = function(menuItem, isEnabled) {
if(OS_ANDROID) {
if(Alloy.Globals.isAndroid3Plus && menuItem.actionView) {
menuItem.actionView.touchEnabled = isEnabled;
}
menuItem.setEnabled(isEnabled);
}
};
@falkolab
falkolab / TelephonyInfoProxy.java
Last active Sep 11, 2017
Titanium android module proxy to check whether the phone is dual SIM
View TelephonyInfoProxy.java
// http://stackoverflow.com/a/17499889/506724
package com.falkolab.drunkmode.platform;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Method;
import java.util.ArrayList;
import org.appcelerator.kroll.KrollProxy;