Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Le Guide de Développement pour Android

Le Guide de Développement pour Android

Auteurs : Simon Debaecke & Christophe Leemans

Support de la présentation donnée le 27 novembre 2012 dans le cadre du cours de développement mobile Android.

Simon Debaecke

November 27, 2012
Tweet

Other Decks in Programming

Transcript

  1. Disparition du bouton Menu remplacé par un équivalent dans l’ActionBar

    smartphones UNIFICATION DES INTERFACES Android 2 tablettes Android 3
  2. Recopier les interfaces depuis d’autres OS Fenêtres modales et boites

    de dialogues Absolute Layout Mesures en px Plus de 4 onglets EVITER
  3. Ressources adaptées aux écrans Larges et évidentes cibles cliquables Gérer

    le cycle de vie & le changement d’orientation Réduire la redondance de code CORRECT
  4. 1 <selector> 2 <item android:drawable="@drawable/foo_disabled" 3 android:state_enabled="false"> 4 <item android:drawable="@drawable/foo_pressed"

    5 android:state_pressed="true"> 6 <item android:drawable="@drawable/foo_focused" 7 android:state_focused="true"> 8 <item android:drawable="@drawable/foo_default"> 9 </selector> RETOUR VISUEL
  5. If an error is possible, someone will make it. Donald

    Norman (author of "The Design of Everyday Things”)
  6. L’UIThread ne peut être bloqué 1 private class MyTask extends

    AsyncTask<Param, Progress, Result> { ... }
  7. 1 private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> { 2

    protected Long doInBackground(URL... urls) { 3 int count = urls.length; 4 long totalSize = 0; 5 for (int i = 0; i < count; i++) { 6 totalSize += Downloader.downloadFile(urls[i]); 7 publishProgress((int) ((i / (float) count) * 100)); 8 if (isCancelled()) break; 9 } 10 11 return totalSize; 12 } 13 14 protected void onProgressUpdate(Integer... progress) { 15 setProgressPercent(progress[0]); 16 } 17 18 protected void onPostExecute(Long result) { 19 showDialog("Downloaded " + result + " bytes"); 20 } 21 }
  8. Android 1.5 Android 1.6 Android 3 Tâches sérialisées Pool de

    threads Par défaut : Tâches sérialisées
  9. 1 public View getView(int position, View convertView, ViewGroup parent) {

    2 3 if (convertView == null) { 4 convertView = inflater.inflate(R.layout.your_layout, false); 5 } 6 7 TextView text = (TextView) convertView.findViewById(R.id.text); 8 text.setText("Position " + position); 9 10 return convertView; 11 } VIEW RECYCLING
  10. 1 public View getView(int position, View convertView, ViewGroup parent) {

    2 ViewHolder holder; 3 if (convertView == null) { 4 convertView = inflater.inflate(R.layout.your_layout, false); 5 6 holder = new ViewHolder(); 7 holder.text = (TextView) convertView.findViewById(R.id.text); 8 convertView.setTag(holder); 9 } else { 10 holder = (ViewHolder) convertView.getTag(); 11 } 12 } 13 holder.text.setText("Position " + position); 14 return convertView; 15 } 16 17 private static class ViewHolder { 18 public TextView text; 19 } VIEW HOLDER PATTERN
  11. Pour aller plus loin : http://goo.gl/LN7Cg GreenDroid : Handling emptiness

    Sectioning your ListView Create fancy ListViews Add several clickable areas Enlarged touchable areas
  12. Android Annotations ActionBar Sherlock Library Support Android Annotations Spring RestTemplate

    ActionBar Sherlock Library Support Android Annotations Spring RestTemplate ActionBar Sherlock NineOldAndroids Support Library ACRA Basic REST Full Maven Eclipse
  13. 1 public class MyActi extends Activity { 2 @Override 3

    protected void onCreate(Bundle savedInstanceState) { 4 ... 5 requestWindowFeature(Window.FEATURE_NO_TITLE); 6 getWindow().setFlags(FLAG_FULLSCREEN, FLAG_FULLSCREEN); 7 } 8 } 1 @NoTitle 2 @Fullscreen 3 public class MyActi extends Activity { 4 @Override 5 protected void onCreate(Bundle savedInstanceState) { 6 ... 7 } 8 } ACTIVITÉ PLEIN ÉCRAN
  14. 1 View updateBookmarksButton1 = findViewById(R.id.updateBookmarksButton1); 2 updateBookmarksButton1.setOnClickListener(new OnClickListener() { 3

    @Override 4 public void onClick(View v) { 5 updateBookmarksClicked(); 6 } 7 }); 8 9 View updateBookmarksButton2 = findViewById(R.id.updateBookmarksButton2); 10 11 updateBookmarksButton2.setOnClickListener(new OnClickListener() { 12 @Override 13 public void onClick(View v) { 14 updateBookmarksClicked(); 15 } 16 }); CLIC SUR UN BOUTON
  15. 1 class UpdateBookmarksTask extends AsyncTask<String, Void, Bookmarks> { 2 3

    @Override 4 protected Bookmarks doInBackground(String... params) { 5 ... 6 } 7 8 @Override 9 protected void onPostExecute(Bookmarks result) { 10 ... 11 } 12 } 1 @Background 2 void searchAsync(String searchString, String userId) { 3 Bookmarks bookmarks = restClient.getBookmarks(searchString, userId); 4 updateBookmarks(bookmarks); 5 } TÂCHE ASYNCHRONE
  16. 1 class AndroidWay extends Activity { 2 TextView name; 3

    ImageView thumbnail; 4 LocationManager loc; 5 Drawable icon; 6 String myName; 7 8 public void onCreate(Bundle savedInstanceState) { 9 super.onCreate(savedInstanceState); 10 setContentView(R.layout.main); 11 name = (TextView) findViewById(R.id.name); 12 thumbnail = (ImageView) findViewById(R.id.thumbnail); 13 loc = (LocationManager) 14 getSystemService(Activity.LOCATION_SERVICE); 15 icon = getResources().getDrawable(R.drawable.icon); 16 myName = getString(R.string.app_name); 17 name.setText( "Hello, " + myName ); 18 } 19 }
  17. 1 class RoboWay extends RoboActivity { 2 @InjectView(R.id.name) TextView name;

    3 @InjectView(R.id.thumbnail) ImageView thumbnail; 4 @InjectResource(R.drawable.icon) Drawable icon; 5 @InjectResource(R.string.app_name) String myName; 6 @Inject LocationManager loc; 7 8 public void onCreate(Bundle savedInstanceState) { 9 super.onCreate(savedInstanceState); 10 setContentView(R.layout.main); 11 name.setText( "Hello, " + myName ); 12 } 13 }
  18. Développé par Google Réponse à la fragmentation des versions Données

    recueillies au cours d'une période de 14 jours se terminant le 1er Novembre 2012
  19. HTTP - RestTemplate + Jackson + Google Gson + Simple

    XML Serialization + Android Rome Feed Reader JSON XML RSS Atom CLIENT REST
  20. HTTP - RestTemplate 1 String url = "https://ajax.googleapis.com/ajax/services/search/web?v=1.0&q={query}"; 2 3

    RestTemplate restTemplate = new RestTemplate(); 4 restTemplate.getMessageConverters().add(new StringHttpMessageConverter()); 5 6 String result = restTemplate.getForObject(url, String.class, "Ma recherche"); CLIENT REST
  21. “ Every non-trivial program has at least one bug. “

    Murphy … pour tous les autres, il y a Robotium. Scénarios de test pour UI
  22. 1 public class EditorTest extends ActivityInstrumentationTestCase2<EditorActivity> { 2 3 solo.sendKey(Solo.MENU);

    4 5 solo.clickOnText("Preferences"); 6 7 Assert.assertTrue(solo.searchText("rtf")); 8 9 solo.goBack(); 10 11 solo.enterText(2, "robotium"); 12 13 solo.clickOnButton("Save"); 14 15 }
  23. 1 public class EditorTest extends ActivityInstrumentationTestCase2<EditorActivity> { 2 3 public

    class LaunchSettings extends UiAutomatorTestCase { 4 getUiDevice().pressHome(); 5 UiObject allAppsButton = new UiObject(new 6 UiSelector().description("Apps")); 7 allAppsButton.clickAndWaitForNewWindow(); 8 UiObject settingsValidation = new UiObject(new UiSelector() 9 .packageName("com.android.settings")); 10 assertTrue("Unable to detect Settings", settingsValidation.exists()); 11 } 12 }
  24. FrAndroid DevTips Cyril Mottier’s blog Videos Google I/O Roman Nurik

    Blog officiel : http://android-developers.blogspot.fr/ Particulièrement http://developer.android.com/training/index.html Tutoriels sur http://www.androidhive.info/