Skip to content

Instantly share code, notes, and snippets.

View parallelcross's full-sized avatar

Matthew Wear parallelcross

View GitHub Profile
@parallelcross
parallelcross / kotlin.md
Last active August 29, 2015 14:14
Droidcon MTL CFP

I built an app with Kotlin, and my client still paid me

A few months ago I started a rewrite project for a client, and they agreed to let me use Kotlin despite the fact I had never written anything substantial in the language prior. I thought it would be fun to learn something new, but was surprised by how much more productive this new tool made me. In this talk you will learn about Kotlin, my experience writing a real production app in it, and why you should give it serious consideration.

Kotlin is a language developed by JetBrains for the JVM. It includes language features such as lambdas, data classes, extension methods and null safety, that will make even the best developer write more accurate, easier to read and maintain code. I plan to give everyone a working understanding of the syntax, features, risks and most importantly what I learned from building a production app in Kotlin. The only prerequisite for the talk will be a decent understanding of Java and Android app construction.

private ObjectAnimator animateRegularProgress(int finalProgress) {
ObjectAnimator animation = ObjectAnimator.ofInt(regularProgressBar, PROPERTY_NAME, 0, finalProgress);
animation.setDuration(ANIM_PROGRESS);
animation.setInterpolator(new LinearInterpolator());
return animation;
}
private void animateTextProgress(float end, float total, ObjectAnimator barAnimationToCoupleTo) {
package com.mozu.mozuandroidinstoreassistant.app.loaders;
import com.mozu.api.MozuApiContext;
import com.mozu.api.contracts.productadmin.LocationInventoryCollection;
import com.mozu.api.contracts.productruntime.Product;
import com.mozu.api.resources.commerce.catalog.admin.products.LocationInventoryResource;
import rx.Observable;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
package com.mozu.mozuandroidinstoreassistant.app.loaders;
import com.mozu.api.MozuApiContext;
import com.mozu.api.contracts.productadmin.LocationInventoryCollection;
import com.mozu.api.contracts.productruntime.Product;
import com.mozu.api.resources.commerce.catalog.admin.products.LocationInventoryResource;
import rx.Observable;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
@parallelcross
parallelcross / InventoryRetriever.java
Created September 8, 2014 18:59
Using RxJava to load Inventory Date instead of a loader
package com.mozu.mozuandroidinstoreassistant.app.loaders;
import com.mozu.api.MozuApiContext;
import com.mozu.api.contracts.productadmin.LocationInventoryCollection;
import com.mozu.api.contracts.productruntime.Product;
import com.mozu.api.resources.commerce.catalog.admin.products.LocationInventoryResource;
import rx.Observable;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
public class ReboundScaleActivity extends Activity implements View.OnTouchListener, SpringListener {
private static double TENSION = 800;
private static double DAMPER = 20; //friction
private ImageView mImageToAnimate;
private SpringSystem mSpringSystem;
private Spring mSpring;
@Override
public class ReboundTranslateActivity extends Activity implements View.OnClickListener, SpringListener {
private static double TENSION = 800;
private static double DAMPER = 20; //friction
private ImageView mImageToAnimate;
private SpringSystem mSpringSystem;
private Spring mSpring;
private boolean mMovedUp = false;
Bitmap bitmap = ((BitmapDrawable)viewHolder.productImage.getDrawable()).getBitmap();
int [] colors = new int[1];
colors[0] = bitmap.getPixel(0, 0);
Bitmap backgroundBitmap = Bitmap.createBitmap(colors, 1, 1, Bitmap.Config.ARGB_8888);
viewHolder.productImage.setBackgroundDrawable(new BitmapDrawable(backgroundBitmap));
@parallelcross
parallelcross / SortListWithoutComparator.java
Created August 6, 2014 17:19
Sort a list in Java with Comparator when you can't extend the class to implement the interface.
Collections.sort(tenants, new ScopeComparator());
public class ScopeComparator implements Comparator<Scope> {
@Override
public int compare(Scope lhs, Scope rhs) {
return lhs.getName().compareTo(rhs.getName());
}
@parallelcross
parallelcross / HowToAttachAFragmentListenerToActivity.java
Last active August 29, 2015 14:01
I used to always call a setListener method on my fragment after it was instantiated, but recently this is how I've started attaching my fragment's listener. I like it because it doesn't require the client of the fragment to remember to set the listener, and throws a runtime exception if they don't implement the listener.
private CategoryFragmentListener mListener = sCategoryListener;
private static CategoryFragmentListener sCategoryListener = new CategoryFragmentListener() {
@Override
public void onLeafCategoryChosen() {
}
};