Buttering Android

Butterknife on Android

Robots taste better with unicorn butter.

Mark Eschbach

Contact

@drakgremlin

https://meschbach.com/

About Me

I've been building software forever.

First serious project was a microkernel while in high school.

I've written a lot of Java over the years.

Butterknife

So much WET

On construction


public void onCreate( Bundle savedData ){
	super.onCreate( savedData );
	setContextView(R.layout.welcome_unicorns);
	state = new RainbowStateManager();

	//Repeated for each view we need to configure
	awesomeSwitch = (Switch)findViewByID( R.id.awesome_switch );
	awesomeSwitch.setOnCheckListener( new OnCheckListener() {
		toggleAwesomeness();
	});

	rainbowSwitch = (Switch)findViewByID( R.id.rainbow_switch );
	rainbowSwitch.setOnCheckListener( new OnCheckListener() {
		toggleRainbows();
	});

	fartButton = (Switch)findViewByID( R.id.fart_button );
	fartButton.setOnClickListener( new OnClickListener() {
		validateInput();
	});
}

On verification


public void validateInput(){
	EditText firstName = (EditText)findViewByID(R.id.first_name);
	EditText lastName = (EditText)findViewByID(R.id.last_name);

	//some validation here
	if( valid ){ gottoNextActivity(); }else{ complain(); }
}

Automated Churning

Boiler Plate


	public void onCreate( Bundle savedData ){
		super.onCreate( savedData );
		setContextView(R.layout.welcome_unicorns);
		state = new RainbowStateManager();
		Butterknife.inject(this);
	}

The Wiring


public class MilkingActivity extends UnicornActivity {
	@BindView(R.id.rainbow_swtich) Switch rainbowSwitch;
	@BindView(R.id.awesome_swtich) Switch awesomeSwitch;
	@BindView(R.id.first_name ) EditText firstName;
	@BindView(R.id.last_name ) EditText lastName;

	...Other code...
}

The Butter


public class MilkingActivity extends UnicornActivity {
	...
	@OnClickListener( R.id.fart_butter )
	public void validateInput(){
	}
	...
}

v1 to v2