Prez android annotations
-
Upload
paris-android-user-group -
Category
Technology
-
view
1.464 -
download
1
Transcript of Prez android annotations
sponsorisé par eBusiness Information, groupe Excilys
AndroidAnnotationsSimple and powerful Android code!
jeudi 8 mars 12
SPEAKERS
•Pierre-Yves RICAU (@Piwai)
•Alexandre THOMAS (@AleksThomas)
jeudi 8 mars 12
CE SOIR
•Dev Android, les trucs pas sexy
•AndroidAnnotations à la rescousse!
•Live coding
jeudi 8 mars 12
ANDROID
jeudi 8 mars 12
jeudi 8 mars 12
APPLICATIONS SÉRIEUSES
jeudi 8 mars 12
Activity = God Object
jeudi 8 mars 12
Activity = God Object
jeudi 8 mars 12
POURQUOI ?
jeudi 8 mars 12
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
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
ET SI VOTRE CODE RESSEMBLAIT À ÇA ?
jeudi 8 mars 12
@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
@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
@EActivity(R.layout.main)public class EditActivity extends Activity {
@Background void doSomeBackgroundWork() { } @UiThread void updateUI() { }}
SIMPLER THREADING
jeudi 8 mars 12
@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
@EBeanpublic class SomeBean {
@Bean SomeOtherBean dependency1;}
INJECTION DE DÉPENDANCES
jeudi 8 mars 12
@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
TAKE THAT, ANDROID GOD!
jeudi 8 mars 12
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
public final class EditActivity_ extends EditActivity{
// Ugly Android code goes here
}
SOUS-CLASSE GÉNÉRÉE
jeudi 8 mars 12
startActivity(new Intent(this, EditActivity_.class));
EditActivity_.intent(this).start();
<activity android:name=".EditActivity_" />
PIÈGES CLASSIQUES
jeudi 8 mars 12
AVANTAGES
• Compile time = no runtime overhead
• Code debuggable & readable
•No vendor lock-in!
jeudi 8 mars 12
OPEN SOURCE
jeudi 8 mars 12
PRODUCTIVITÉ
VuzZzQuality of life, Geolocalized.
Développée en 48h
jeudi 8 mars 12
CODE PROPRE
Live coding!Nettoyage de printemps
jeudi 8 mars 12
QUESTIONS?
•http://androidannotations.org
•@AndAnnotations
jeudi 8 mars 12