Prez android annotations

27
sponsorisé par eBusiness Information, groupe Excilys AndroidAnnotations Simple and powerful Android code! jeudi 8 mars 12

Transcript of Prez android annotations

Page 1: Prez android annotations

sponsorisé par eBusiness Information, groupe Excilys

AndroidAnnotationsSimple and powerful Android code!

jeudi 8 mars 12

Page 2: Prez android annotations

SPEAKERS

•Pierre-Yves RICAU (@Piwai)

•Alexandre THOMAS (@AleksThomas)

jeudi 8 mars 12

Page 3: Prez android annotations

CE SOIR

•Dev Android, les trucs pas sexy

•AndroidAnnotations à la rescousse!

•Live coding

jeudi 8 mars 12

Page 4: Prez android annotations

ANDROID

jeudi 8 mars 12

Page 5: Prez android annotations

jeudi 8 mars 12

Page 6: Prez android annotations

APPLICATIONS SÉRIEUSES

jeudi 8 mars 12

Page 7: Prez android annotations

Activity = God Object

jeudi 8 mars 12

Page 8: Prez android annotations

Activity = God Object

jeudi 8 mars 12

Page 9: Prez android annotations

POURQUOI ?

jeudi 8 mars 12

Page 10: Prez android annotations

void doSomeCrazyStuff(Param param) { new AsyncTask<Param, Progress, Void>() { @Override protected Void doInBackground(Param... params) { Param myParam = params[0]; publishProgress(new Progress()); mySuperDownloader.downloadStuff(myParam); return null; } protected void onProgressUpdate(Progress... values) { Progress myProgress = values[0]; updateProgress(myProgress); }; protected void onPostExecute(Void result) { // ... };

}.execute(param); }

ASYNCTASK

jeudi 8 mars 12

Page 11: Prez android annotations

NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

TextView myTextView = (TextView) findViewById(R.id.someId);

findViewById(R.id.textView).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { handler.postDelayed(new Runnable() { @Override public void run() { // ... } }, 500); } });

jeudi 8 mars 12

Page 12: Prez android annotations

ET SI VOTRE CODE RESSEMBLAIT À ÇA ?

jeudi 8 mars 12

Page 13: Prez android annotations

@EActivity(R.layout.main)public class EditActivity extends Activity {

@ViewById(R.id.titleTextView) TextView title;

@ViewById EditText editText; @AfterViews void initTitle() { title.setText("42"); }}

SIMPLER VIEW HANDLING

jeudi 8 mars 12

Page 14: Prez android annotations

@EActivity(R.layout.main)public class EditActivity extends Activity { @Click(R.id.downloadButton) void startDownloading() { }

@Click void myButtonClicked() { }}

SIMPLER EVENT HANDLING

jeudi 8 mars 12

Page 15: Prez android annotations

@EActivity(R.layout.main)public class EditActivity extends Activity {

@Background void doSomeBackgroundWork() { } @UiThread void updateUI() { }}

SIMPLER THREADING

jeudi 8 mars 12

Page 16: Prez android annotations

@Rest("http://www.stuff.com")public interface StuffClient { @Get("/stuff/{userId}?search={search}") Stuff getStuff(String search, String userId); @Post("/stuff/{userId}") void updateStuff(Stuff stuff, String userId);

}

REST CLIENT

jeudi 8 mars 12

Page 17: Prez android annotations

@EBeanpublic class SomeBean {

@Bean SomeOtherBean dependency1;}

INJECTION DE DÉPENDANCES

jeudi 8 mars 12

Page 18: Prez android annotations

@EActivity(R.layout.main)public class EditActivity extends Activity { @ViewById EditText searchInput; @RestService RestClient restClient; @Bean Datastore datastore; @Click void downloadButtonClicked() { doSomeBackgroundWork(searchInput.getText().toString()); } @Background void doSomeBackgroundWork(String search) { Stuff stuff = restClient.getStuff(search); datastore.saveStuff(stuff); updateUI(stuff); } @UiThread void updateUI(Stuff stuff) { // Show stuff }}

TOUT ENSEMBLE!

jeudi 8 mars 12

Page 19: Prez android annotations

TAKE THAT, ANDROID GOD!

jeudi 8 mars 12

Page 20: Prez android annotations

AndroidAnnotations

COMMENT ?

• Java 6 Annotation Processor

• Génération de code à la compilation

• Exécuter automatiquement par javac

Simple and powerful Android code!

jeudi 8 mars 12

Page 21: Prez android annotations

public final class EditActivity_ extends EditActivity{

// Ugly Android code goes here

}

SOUS-CLASSE GÉNÉRÉE

jeudi 8 mars 12

Page 22: Prez android annotations

startActivity(new Intent(this, EditActivity_.class));

EditActivity_.intent(this).start();

<activity android:name=".EditActivity_" />

PIÈGES CLASSIQUES

jeudi 8 mars 12

Page 23: Prez android annotations

AVANTAGES

• Compile time = no runtime overhead

• Code debuggable & readable

•No vendor lock-in!

jeudi 8 mars 12

Page 24: Prez android annotations

OPEN SOURCE

jeudi 8 mars 12

Page 25: Prez android annotations

PRODUCTIVITÉ

VuzZzQuality of life, Geolocalized.

Développée en 48h

jeudi 8 mars 12

Page 26: Prez android annotations

CODE PROPRE

Live coding!Nettoyage de printemps

jeudi 8 mars 12

Page 27: Prez android annotations

QUESTIONS?

•http://androidannotations.org

•@AndAnnotations

jeudi 8 mars 12