Thursday, December 22, 2011

Titanium Image Gallery

Creating an Image Gallery that scrolls side to side isn't terribly difficult with Titanium.

Here is how I did it:

// put this in a file, for instance "ImageGallery.js"
var ImageGallery = {};
(function() {

    ImageGallery.imageViewArray = [];
    ImageGallery.imageNameArray = [];
    ImageGallery.Gallery = null;
    ImageGallery.createGallery = function(params) {
        if (params.Images) {
            ImageGallery.imageNameArray = params.Images;
        ImageGallery.Gallery.addEventListener('click', function(e){});
        for(var i = 0; i < ImageGallery.imageNameArray.length ; i++){
            ImageGallery.Gallery.views[i].image = ImageGallery.imageNameArray[i];
        ImageGallery.nextImageIndex = 1;
        return ImageGallery.Gallery;
    ImageGallery.init = function(params) {
        var imageParams = {
            width:Ti.Platform.displayCaps.platformWidth - 4,
        for(var i = 0; i < ImageGallery.imageNameArray.length ; i++){
            ImageGallery.imageViewArray[i] = Titanium.UI.createImageView(imageParams);
        var p = {
            width: 310,
            height: 450,
            top: 5,
            left: 5,
            borderWidth: 2,
            borderColor: '#000',
            showPagingControl: false,
            pagingControlColor: '#fff',
        for (var prop in params) {
            p[prop] = params[prop];
        p.views = ImageGallery.imageViewArray;
        p.backgroundColor = "#000";
        ImageGallery.Gallery = Titanium.UI.createScrollableView(p);

 Assuming that you include the file above in your view, you then can use it like so:

var gallery = ImageGallery.createGallery(

                // here images is an array of image URLs

What do you think?

Thursday, November 03, 2011

PHP and writing to Apache logs

Printing to STDERR is quite easy, once you figure it out!

file_put_contents('php://stderr', print_r($your_string, TRUE));

Of course, you can also replace 'stderr' with 'stdout'.

You could also use error_log but it truncates long strings ...

Saturday, July 16, 2011

Android App Piracy

As you may know, I have a bunch of apps on the Android market. Recently, I have been fielding questions from users that have had problems with my app. Turns out their contacts were being deleted. Their contacts were receiving lewd photos and messages.

After some digging around, it became clear that they downloaded pirated versions of my apps. Aside from feeling glad that people too cheap to buy something that costs the same as a bag of chips and a soda got what was coming to them, I was inclined to post a message about piracy on my apps home page.

Basically, the gist of what I posted is this:

Would you openly give all of the data on your phone to a third party that you did not know or trust? By downloading applications from sources where the original author did not intend to publish them, you are doing just that.

Most paid applications on the market implement some form of weak licensing that Google endorses. Unfortunately, this licensing is very easy to beat. In order to beat it, pirates must add their own bits of source code to apps.

So ask yourself, what would stop them from injecting more code, to say, read all of your contacts and send them to a third party? Or, reading your banking details?

Some will read this post and assume that I am just trying to protect my interests. Well, of course I am. But understand, my claims are real:
The list could go on and on ... Basically, they all say the same thing; Download applications from sources that you trust (Android Market, App Store, etc) and not pirate web sites.

In the end, is the couple of bucks you save worth all of the headache of having your information stolen, your accounts hacked and your life turned upside down?

A little bit of brain goes a long way.