Skip to content

Instantly share code, notes, and snippets.

Build type APK size
Without optimization 31.5MB
With optimization 23.2MB
@hboregio
hboregio / tasks.gradle
Created November 22, 2016 13:10
Gradle task to call an external bash script
task optimizePngs(type: Exec) {
group = 'Optimizations'
description = 'Reduce the PNG size using PNGQuant'
def absolutePath = file('..') // Get project absolute path
commandLine "$absolutePath/scripts/optimize_png.sh", "$absolutePath/app/src"
}
@hboregio
hboregio / optimize_png.sh
Created November 22, 2016 13:08
Bash script to optimize png files
#!/bin/bash
if [ $# -lt 1 ]
then
echo "Missing argument"
echo "Usage : $0 <APPLICATION_PROJECT_DIRECTORY>"
exit 1;
fi
APPLICATION_PROJECT_DIRECTORY=$1
echo "Optimizing PNGs with pngquant"
// BasePresenter.java (Base class for all our Presenters)
public abstract class BasePresenter<V> {
private WeakReference<V> mView;
public void bindView(@NonNull V view) {
mView = new WeakReference<>(view);
}
public void unbindView() {
private void fetchFeed() {
RestClient.getInstance().getUser(new ResultsListener<User>() {
@Override
public void onSuccess(String feed) {
Log.i("Feed: " + feed);
}
@Override
import com.loopj.android.http.AsyncHttpResponseHandler;
/**
* Singleton RestClient
*/
public class RestClient {
private static RestClient sInstance = null;
public static RestClient getInstance() {
public interface ResultsListener<T> {
public void onSuccess(T result);
public void onFailure(Throwable e);
}
public class Api {
private static final String BASE_URL = "https://my.api.com/";
private static AsyncHttpClient aSyncClient;
private static String USER_AGENT = "Our Custom User Agent";
static {
// setup asynchronous client
aSyncClient = new AsyncHttpClient();
{
list: [
{
defid: 7191449,
word: "dental rush",
author: "amatwiedle",
permalink: "http://dental-rush.urbanup.com/7191449",
other_definitions: 0,
definition: "The act of brushing your teeth multiple times right before a dentist appointment.",
example: "Guy 1: You going to the dentist? guy 2: Yah, I had a dental rush this morning.",
public class MiActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MiAsyncTask task = new MiAsyncTask(new Callback() {
public void finished() {
Toast.makeText(MiActivity.this, “Tarea terminada.”, Toast.LENGTH_SHORT).show();