@@ -52,16 +52,17 @@ qui nous permettent d'éliminer beaucoup de code boilerplate. Un exemple
5252valant mieux qu'un long discours :
5353
5454{% highlight java %}
55+ // Activity
5556@EActivity (R.layout.mon_activite) // content view => R.layout.mon_activite
5657public class MyActivity extends Activity {
57- @InjectView // Injection de R.id.titre
58- TextView titre;
59-
60- @DrawableRes (R.drawable.logo)
61- Drawable logo
62-
63- @SystemService
64- SearchManager searchManager;
58+ @InjectView // Injection de R.id.titre
59+ TextView titre;
60+
61+ @DrawableRes (R.drawable.logo)
62+ Drawable logo
63+
64+ @SystemService
65+ SearchManager searchManager;
6566}
6667{% endhighlight %}
6768
@@ -93,18 +94,19 @@ Projet très jeune et peu documenté, pas du tout prêt à être utilisé.
9394ORM basé sur des annotations :
9495
9596{% highlight java %}
97+ // Annotations
9698@DatabaseTable (tableName = "accounts")
9799public class Account {
98- @DatabaseField (id = true)
99- private String name;
100-
101- @DatabaseField(canBeNull = false)
102- private String password;
103- ...
104- Account() {
105- // all persisted classes must define a no-arg constructor with at least package visibility
106- }
107- ...
100+ @DatabaseField (id = true)
101+ private String name;
102+
103+ @DatabaseField(canBeNull = false)
104+ private String password;
105+ ...
106+ Account() {
107+ // all persisted classes must define a no-arg constructor with at least package visibility
108+ }
109+ ...
108110}
109111{% endhighlight %}
110112
@@ -154,28 +156,28 @@ dans une vue XML avec binding:onClick="AddContact") :
154156
155157{% highlight java %}
156158public class ContactManagerModel {
157- private Activity mContext;
158-
159- public CursorSource<ContactRowModel > ContactList = new CursorSource<ContactRowModel >(ContactRowModel.class, new Factory());
160-
161- public BooleanObservable ShowInvisible = new BooleanObservable(false);
162-
163- public Command PopulateList = new Command(){
164- public void Invoke(View view, Object... args) {
165- populateContactList();
166- }
167- };
168- public Command AddContact = new Command(){
169- public void Invoke(View view, Object... args) {
170- launchContactAdder();
171- }
172- };
173-
174- private void populateContactList() {
175- // Build adapter with contact entries
176- Cursor cursor = getContacts();
177- ContactList.setCursor(cursor);
178- }
159+ private Activity mContext;
160+
161+ public CursorSource<ContactRowModel > ContactList = new CursorSource<ContactRowModel >(ContactRowModel.class, new Factory());
162+
163+ public BooleanObservable ShowInvisible = new BooleanObservable(false);
164+
165+ public Command PopulateList = new Command(){
166+ public void Invoke(View view, Object... args) {
167+ populateContactList();
168+ }
169+ };
170+ public Command AddContact = new Command(){
171+ public void Invoke(View view, Object... args) {
172+ launchContactAdder();
173+ }
174+ };
175+
176+ private void populateContactList() {
177+ // Build adapter with contact entries
178+ Cursor cursor = getContacts();
179+ ContactList.setCursor(cursor);
180+ }
179181}
180182{% endhighlight %}
181183
@@ -184,7 +186,7 @@ rend l'édition des vues xml incompatibles avec l'éditeur intégrér au plugin
184186
185187{% highlight xml %}
186188<LinearLayout xmlns: android ="http://...." xmlns: binding ="http://www.gueei.com/android-binding/ " ..>
187- <TextView binding: text ="FirstName" ...
189+ <TextView binding: text ="FirstName" ...
188190{% endhighlight %}
189191
190192Les Activity android se chargent de faire le lien entre le modèle et la vue
@@ -195,13 +197,15 @@ Le framework est très prometteur et permet d'effectuer de la validation de
195197modèle à l'aide d'annotations sur les champs du modèle :
196198
197199{% highlight java %}
200+ // Annotation
198201@Required (ErrorMessage="You must put the login name! (you can try Jean-Michel)")
199202public final Observable<CharSequence > Login;
200203{% endhighlight %}
201204
202205ou encore :
203206
204207{% highlight java %}
208+ // Annotation
205209@Required
206210@EqualsTo (Observable="Password")
207211public final Observable<CharSequence > ConfirmPassword;
@@ -222,28 +226,30 @@ RestTemplate dans ses annotations et ça devient vraiment sympa à coder.
222226Il suffit de coder son service REST :
223227
224228{% highlight java %}
229+ // Annotation
225230@Rest ("http://monserveur.fr/api ")
226231public interface MonServiceRest {
227232
228- @Get("/item/{id}")
229- @Accept(MediaType.APPLICATION_JSON)
230- Item getItem(long id);
233+ @Get("/item/{id}")
234+ @Accept(MediaType.APPLICATION_JSON)
235+ Item getItem(long id);
231236}
232237{% endhighlight %}
233238
234239Puis dans sa vue d'injecter le service et de l'utiliser ensuite :
235240
236241{% highlight java %}
242+ // Annotation
237243@RestService
238244MonServiceRest monServiceRest;
239245
240246@AfterViews
241247@Background
242248void init() {
243- item = monServiceRest.getItem(2L);
244- if(item != null) {
245- showItem();
246- }
249+ item = monServiceRest.getItem(2L);
250+ if(item != null) {
251+ showItem();
252+ }
247253}
248254{% endhighlight %}
249255
@@ -274,4 +280,4 @@ Pour déployer l'application sur un terminal :
274280
275281{% highlight sh %}
276282mvn android: deploy
277- {% endhighlight %}
283+ {% endhighlight %}
0 commit comments