Nice way waiting for asynctask job

It might be good example especially for billing api IAP for Android.

public void waitTillAsyncFinishOrTimeout(int tries=3, long spanTime=1000){

	boolean success = false;
	boolean inProgress = true;

	AnyTask provider = new AnyTask(new AnyListener() {
		@Override
		public void onReady() {
			success = true;
			inProgress = false;
		}
	});

	synchronized (OBJECT_LOCK) {
		int triesCount = 0;
		while (inProgress && triesCount < tries) {
			try {
				OBJECT_LOCK.wait(spanTime);
				triesCount ++;
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

	if (success) {
		...
	}
}

Example gradle with incrementing version (based on commits count)

Just an example how use commits count value as a build number of app.

buildscript {
    //...
}

repositories {
    //...
}

def cmd = ‘git rev-list –all –count’ def gitVersion = cmd.execute().text.trim().toInteger() println “=== Building version ” + gitVersion.toString()

android {
    compileSdkVersion 23
    buildToolsVersion '23.0.3'

    defaultConfig {
        //...

versionCode gitVersion versionName “1.0.” + gitVersion

    }

    lintOptions {
        abortOnError false
    }

    buildTypes {
        release {
            minifyEnabled false
        }
    }

    signingConfigs {
        release {
            //...
        }
    }

    productFlavors {
        play {
            //...
        }
    }
}

dependencies {
    //...
}

Script to convert jpeg to webp – github

#/bin/sh
# Inpiration: http://engineeringblog.yelp.com/2016/05/yelp-android-app-went-on-a-diet.html
# `-lossless` not used to give support for Android 4.0+

# Make sure cwebp is installed.
if ! type "cwebp" > /dev/null; then
    echo "Please install cwebp to continue:"
    echo "brew install webp"
    exit 1
fi

# Convert all the images in the project that are not converted.
for f in $(find . -name "*.jpg")
  do
    echo "Converting $f"
    oldSize=$(du -h $f)
    cwebp -pass 10 -m 6 -mt -jpeg_like -q 60 $f -o "${f/%.jpg/.webp}" &>/dev/null
    newSize=$(du -h ${f/%.jpg/.webp})
    echo "The image was compressed: $oldSize -> $newSize"
    rm $f
done

https://gist.github.com/SandroMachado/9ee516bbd36768ca3844876c50cf4618

Webp for all! (Android devices) – github

Webp is a library we use at EverythingMe Launcher since we love webp. We use it to save bandwidth as well as shrinking our APK sizes.
Webp is an adaptation of chromium’s webp decoder, and an addition of a JNI wrapper to easily use it it in your java code.

https://github.com/EverythingMe/webp-android