SlideShare une entreprise Scribd logo
1  sur  41
Télécharger pour lire hors ligne
Android Camera
                       the making of
                               MarsJUG

                       Aix en Provence - Marseille
                           6 Décembre 2012



@cfalguiere
jeudi 6 décembre 12
Claude Falguière
                      Architecte Technique Valtech
                      http://cfalguiere.wordpress.com
                      Duchess France, Paris JUG, Devoxx4Kids




@cfalguiere
jeudi 6 décembre 12
Objectif
  questions           apprendre
                      gadget fun pour Devoxx
                      alimenter un hacker space Duchess




@cfalguiere
jeudi 6 décembre 12
IDE
                      ADT : Eclipse + Plugins ADT + SDK

                      Eclipse




                      http://developer.android.com
@cfalguiere
jeudi 6 décembre 12
IDE
                      ADT : Eclipse + Plugins ADT + SDK

                      Plugins




                      http://developer.android.com
@cfalguiere
jeudi 6 décembre 12
IDE
                      ADT : Eclipse + Plugins ADT + SDK

                      Platform Tools




                      http://developer.android.com
@cfalguiere
jeudi 6 décembre 12
IDE                 Android Virtual Device (AVD)




@cfalguiere
jeudi 6 décembre 12
Hello               Hello World

                       onCreate
                       onPause
                       onResume
                       onDestroy



                      Activity      GroupView    Hello World
                                     (layout)




                                      TextView



@cfalguiere
jeudi 6 décembre 12
Hello



                      Activity        GroupView                  Hello World
                                       (layout)
                                                                           Go




                                 TextView            ImageView

                                            Button


@cfalguiere
jeudi 6 décembre 12
Camera                         SurfaceHolder

                      Camera
                                   (layout)


                      Activity   SurfaceView




@cfalguiere
jeudi 6 décembre 12
Camera                         SurfaceHolder

                      Camera
                                   (layout)


                      Activity   SurfaceView




@cfalguiere
jeudi 6 décembre 12
Camera                    open
                            release
                                         Camera




                      Activity        RelativeLayout




                                             SurfaceView              SurfaceHolder
                                                                          surfaceCreated
                                                                          surfaceDestroyed
                                                                          surfaceChanged
                                           CameraPreview

                                                           startPreview
                                                           stopPreview     Camera

@cfalguiere
jeudi 6 décembre 12
Camera

                      Activity   RelativeLayout




                                       FrameLayout



                                       SurfaceView


@cfalguiere                           CameraPreview
jeudi 6 décembre 12
Cameralayout/main_activity.xml
                      <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/
                      android"
                          xmlns:tools="http://schemas.android.com/tools"
                          android:layout_width="match_parent"
                          android:layout_height="match_parent"
                          tools:context=".MainActivity" >

                          <FrameLayout
                              android:id="@+id/cameraPreviewFrame"
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:layout_alignParentLeft="true"
                              android:layout_alignParentTop="true" >
                          </FrameLayout>

                          <Button
                              android:id="@+id/saveButton"
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:layout_alignParentBottom="true"
                              android:layout_alignParentLeft="true"
                              android:background="@drawable/camera_icon"
                              android:onClick="whenSave" />

                      </RelativeLayout>
@cfalguiere
jeudi 6 décembre 12
Camera              MainActivity.java
                      	   protected void onCreate(Bundle savedInstanceState) {
                      	   	 super.onCreate(savedInstanceState);

                               setContentView(R.layout.activity_main);

                               mCamera = Camera.open();

                               CameraPreview cameraPreview = new CameraPreview(this, mCamera);
                               FrameLayout previewFrame =
                                   (FrameLayout) findViewById(R.id.cameraPreviewFrame);
                               previewFrame.addView(cameraPreview);
                               ...



                      CameraPreview.java
                          public CameraPreview(Context context, Camera camera) {
                               super(context);
                               mCamera = camera;
                               mHolder = getHolder();
                               mHolder.addCallback(this);
                              ...




@cfalguiere
jeudi 6 décembre 12
Camera                   manifest.xml


                      <?xml version="1.0" encoding="utf-8"?>
                      <manifest xmlns:android="http://schemas.android.com/apk/res/android"
                          package="com.example.duchescamera"
                          android:versionCode="1"
                          android:versionName="1.0" >

                         <uses-sdk
                             android:minSdkVersion="8"
                             android:targetSdkVersion="17" />

                         <application
                             android:allowBackup="true"
                             android:icon="@drawable/ic_launcher"
                             android:label="@string/app_name"
                             android:screenOrientation="landscape">
                             <activity
                                 android:name="com.example.duchescamera.MainActivity"
                                 android:label="@string/app_name" >
                                ...



@cfalguiere
jeudi 6 décembre 12
Camera                   manifest.xml


                      <?xml version="1.0" encoding="utf-8"?>
                      <manifest xmlns:android="http://schemas.android.com/apk/res/android"
                          package="com.example.duchescameramini2"
                          android:versionCode="1"
                          android:versionName="1.0" >

                         <uses-sdk
                             android:minSdkVersion="8"
                             android:targetSdkVersion="17" />

                         <!-- will make use of camera -->
                         <uses-feature android:name="android.hardware.camera"
                                       android:required="true" />
                         <uses-permission android:name="android.permission.CAMERA" />




@cfalguiere
jeudi 6 décembre 12
Camera
                                            SurfaceView
                      RelativeLayout


                      Orientation par      Orientation par
                      défaut du device   défaut de la camera




@cfalguiere
jeudi 6 décembre 12
open
                      setCameraDisplay (holder)

                            startPreview

                           takePicture

                            stopPreview

                               release


@cfalguiere
jeudi 6 décembre 12
Photo




                      layout/main_activity.xml
                               <Button
                                   android:id="@+id/saveButton"
                                   android:layout_width="wrap_content"
                                   android:layout_height="wrap_content"
                                   android:layout_alignParentBottom="true"
                                   android:layout_alignParentLeft="true"
                                   android:background="@drawable/camera_icon"
                                   android:onClick="whenSave" />
@cfalguiere
jeudi 6 décembre 12
Photo                   whenSave
                                                   takePicture
                                  Activity                       Camera

                                                                             onPictureTaken
                                       onShutter

                              ShutterCallback        RawCallback          PictureCallback
                                  «Click»                                 générer le fichier




                      MainActivity.java
                         public void whenSave(View view) {
                        	 	 	 mCamera.takePicture(shutterCallback,
                                                      null,
                                                      jpegPictureCallback);
                        }




@cfalguiere
jeudi 6 décembre 12
Photo                   MainActivity.java

                           private SoundPool mSoundPool;
                           private int mShutterSoundId;
                           private float mShutterSoundVolume = 0.5f;

                      	    protected void onCreate(Bundle savedInstanceState) {
                      	    	 super.onCreate(savedInstanceState);

                            	 mSoundPool = new SoundPool(1, AudioManager.STREAM_NOTIFICATION, 0);
                            	 mShutterSoundId = mSoundPool.load(this, R.raw.camera_click, 1);
                              ...




                           public void whenSave(View view) {
                              Camera.ShutterCallback shutterCallback = new Camera.ShutterCallback(
                                  public void onShutter() {
                                      mSoundPool.play(mShutterSoundId, mShutterSoundVolume,
                                                   mShutterSoundVolume, 1, 0, 1);
                                  }
                              };
                              mCamera.takePicture(shutterCallback, null, mJpegPictureCallback);
                              ...




@cfalguiere
jeudi 6 décembre 12
Photo                   PictureCallback
                      	    public void onPictureTaken(byte[] data, Camera camera) {
                      	    	   try {
                      	    	   	   Bitmap photo = BitmapFactory.decodeByteArray(data, 0,data.length);

                      	    	   	   // Create a new, empty bitmap with the original size.
                      	    	   	   Bitmap bitmap = Bitmap.createBitmap(photo.getWidth(),
                                                                     photo.getHeight(),
                      	    	   	   	   	                               photo.getConfig());
                                   Canvas canvas = new Canvas(bitmap);
                      	    	   	   canvas.drawBitmap(photo, 0, 0, null);	    	

                      	    	   	   // save file
                      	    	   	   File pictureFile = getOutputMediaFile();
                      	    	       FileOutputStream fos = new FileOutputStream(pictureFile);	   	
                                     bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos);	
                      	    	       addPictureToGalery(pictureFile.getPath());

                      	    	   } catch (Exception e) {
                      	    	   	   Log.d(TAG, "ERROR Could not save picture: " + e.getMessage());
                      	    	   }
                      	    }




@cfalguiere
jeudi 6 décembre 12
Photo               PictureCallback


                      	   private void addPictureToGalery(String path) {
                      	   	 Intent mediaScanIntent =
                                          new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
                      	   	 Uri contentUri = Uri.fromFile(new File(path));
                      	   	 mediaScanIntent.setData(contentUri);
                      	   	 mActivity.sendBroadcast(mediaScanIntent);
                      	   }




@cfalguiere
jeudi 6 décembre 12
Incrustation
                      Activity    RelativeLayout




                                        FrameLayout




                                 ImageView          SurfaceView
                       onDraw

                                 DrawView          CameraPreview
@cfalguiere
jeudi 6 décembre 12
Incrustation
                      onDraw           DuchessSprite

                                                       Canvas

                      DrawPreview   draw                        y


                                                       x




@cfalguiere
jeudi 6 décembre 12
Incrustation
                      onDraw                 DuchessSprite



                                      draw
                      DrawPreview                                  Canvas




                                       draw


                                              MoveFeedbackSprite
                               draw


                                       RotationFeedbackSprite

@cfalguiere
jeudi 6 décembre 12
Incrustation        DuchessSprite.java
                      	   private Bitmap bitmap;   // the actual bitmap
                      	
                          public void draw(Canvas canvas, float ratio) {
                      	   	 Matrix matrix = new Matrix();
                      	   	 float s = 1 / bitmapScale;
                      	   	 int cw = Math.round(bitmap.getWidth() / 2);
                      	   	 int ch = Math.round(bitmap.getHeight() / 2);
                      	   	

                      	   	   canvas.drawBitmap(bitmap, matrix, null);	   	
                      	   }




@cfalguiere
jeudi 6 décembre 12
Incrustation        DuchessSprite.java
                      	   private Bitmap bitmap;   // the actual bitmap
                      	
                          public void draw(Canvas canvas, float ratio) {
                      	   	 Matrix matrix = new Matrix();
                      	   	 float s = 1 / bitmapScale;
                      	   	 int cw = Math.round(bitmap.getWidth() / 2);
                      	   	 int ch = Math.round(bitmap.getHeight() / 2);
                      	   	 matrix.setScale(s, s, cw, ch);
                      	   	
                      	   	 canvas.drawBitmap(bitmap, matrix, null);	 	
                      	   }




@cfalguiere
jeudi 6 décembre 12
Incrustation        DuchessSprite.java
                      	   private Bitmap bitmap;   // the actual bitmap
                      	
                          public void draw(Canvas canvas, float ratio) {
                      	   	 Matrix matrix = new Matrix();
                      	   	 float s = 1 / bitmapScale;
                      	   	 int cw = Math.round(bitmap.getWidth() / 2);
                      	   	 int ch = Math.round(bitmap.getHeight() / 2);
                      	   	 matrix.setScale(s, s, cw, ch);
                      	   	 matrix.postTranslate(centerX - cw, centerY - ch);
                      	   	
                      	   	 canvas.drawBitmap(bitmap, matrix, null);	 	
                      	   }




@cfalguiere
jeudi 6 décembre 12
Incrustation        DuchessSprite.java
                      	   private Bitmap bitmap;   // the actual bitmap
                      	
                          public void draw(Canvas canvas, float ratio) {
                      	   	 Matrix matrix = new Matrix();
                      	   	 float s = 1 / bitmapScale;
                      	   	 int cw = Math.round(bitmap.getWidth() / 2);
                      	   	 int ch = Math.round(bitmap.getHeight() / 2);
                      	   	 matrix.setScale(s, s, cw, ch);
                      	   	 matrix.postTranslate(centerX - cw, centerY - ch);
                      	   	 matrix.postScale(ratio, ratio);

                      	   	   canvas.drawBitmap(bitmap, matrix, null);	   	
                      	   }




@cfalguiere
jeudi 6 décembre 12
DrawView.java

                      public boolean onTouchEvent(MotionEvent event) {
                      	
                      	      final int action = event.getAction();

                          	
                          switch (action & MotionEvent.ACTION_MASK) {
                         		   case MotionEvent.ACTION_DOWN: {
                                       mDuchess.handleActionDown((int)event.getX(),
                                                       (int)event.getY()); // update touched
                                 	 break;
                      	               }
                      	               case MotionEvent.ACTION_MOVE: {
                      	            	      if (mDuchess.isTouched()) {
                       	        	 	       mDuchess.setCenterX((int)event.getX());
                      	         	 	           mDuchess.setCenterY((int)event.getY());
                      	         	 	          invalidate();
                          	    	          }
                      	         	         break;
                      	               }
                      	               case MotionEvent.ACTION_UP: {
                      	                 if (mDuchess.isTouched()) {
                      	        	              	 mDuchess.setTouched(false);
                      	        	            }
                      	        	            reak;
                      	             }
                           }
                           return true;
                      }


@cfalguiere
jeudi 6 décembre 12
Incrustation
                           onTouchEvent
                                                DrawView




                      	   public DrawView(Context context, DuchessSprite duchess) {
                      	   	 super(context);
                      	   	 ...
                      	   	
                               // make the Panel focusable so it can handle events
                               setFocusable(true);
                               setFocusableInTouchMode(true);
                          	
                          }
                      	




@cfalguiere
jeudi 6 décembre 12
Merci


  Questions           Claude Falguière
                      @cfalguiere
                      goo.gl/4mmJQ
@cfalguiere
jeudi 6 décembre 12
@cfalguiere
jeudi 6 décembre 12
Lab 0
                      Installer ADT
                      http://developer.android.com/sdk/index.html



                      Installer git (préférable)



                      http://developer.android.com


@cfalguiere
jeudi 6 décembre 12
Lab 1               Créez un repo Git (git init)

                      Créez un workspace Eclipse sur la racine
                      du repo

                      Créez un projet dans Eclipse
                      • New «Android Application Project»
                      • (Facultatif) choisissez l’icone Photo dans Clipart
                      • une activité MainActivity par défaut
                      Lancez l’application dans le simulateur
                      • Créez un AVD Galaxy Nexus
                      • Exécutez dans le simulateur
                      Lancez l’application sur un device connecté
@cfalguiere
jeudi 6 décembre 12
Lab 2
                      Affichez la caméra dans votre application
                      vous aurez besoin
                      • de modifier le layout (RelativeLayout et
                          FrameLayout)
                      •   d’implémenter un SurfaceView
                      •   de la feature android.hardware.camera
                      •   de la permission android.permission.CAMERA
                      •   de corriger l’orientation




@cfalguiere
jeudi 6 décembre 12
Lab 3               Ajoutez le bouton et prennez une photo
                      (Facultatif) ajoutez le son

                      vous aurez besoin
                      • du composant graphique Button
                      • de l’icône du bouton : drawable/camera_icon.png
                      • de l’implémentation du PictureCallback
                      • de la permission
                       android.permission.WRITE_EXTERNAL_STORAGE
                      • du fichier son camera_click.ogg (Facultatif)
                      • de la classe SoundPool (Facultatif)



@cfalguiere
jeudi 6 décembre 12
Lab 4               Ajoutez une vue ImageView custom et
                      affichez Duchess


                      vous aurez besoin
                      • de l’image du sprite : drawable/
                          duchessfr_shadow.png
                      •   de l’implémentation du Sprite DuchessSprite




@cfalguiere
jeudi 6 décembre 12
Lab 5
                      Ajoutez la possibilité de déplacer le sprite

                      (Facultatif) affichez un feedback visuel

                      vous aurez besoin
                      • de l’implémentation du Sprite DragFeedbackSprite
                       (Facultatif)




@cfalguiere
jeudi 6 décembre 12

Contenu connexe

Similaire à Pres android nuit de l'info v3

Play framework - Human Talks Grenoble - 12.02.2013
Play framework - Human Talks Grenoble - 12.02.2013Play framework - Human Talks Grenoble - 12.02.2013
Play framework - Human Talks Grenoble - 12.02.2013Xavier NOPRE
 
Android Lab Test : La prévisualisation de la caméra (français)
Android Lab Test : La prévisualisation de la caméra (français)Android Lab Test : La prévisualisation de la caméra (français)
Android Lab Test : La prévisualisation de la caméra (français)Bruno Delb
 
La mobilité dans Drupal
La mobilité dans DrupalLa mobilité dans Drupal
La mobilité dans DrupalAdyax
 
Jug Lausanne Android Janvier2013
Jug Lausanne Android Janvier2013Jug Lausanne Android Janvier2013
Jug Lausanne Android Janvier2013jeromevdl
 
Lbv Dev Meetup #2
 Lbv Dev Meetup #2 Lbv Dev Meetup #2
Lbv Dev Meetup #2LbvDev
 
Initiation à la réalité augmentée sur Windows Phone 7.5 (Mango)
Initiation à la réalité augmentée sur Windows Phone 7.5 (Mango)Initiation à la réalité augmentée sur Windows Phone 7.5 (Mango)
Initiation à la réalité augmentée sur Windows Phone 7.5 (Mango)Microsoft
 
Introduction à Android
Introduction à AndroidIntroduction à Android
Introduction à AndroidYoann Gotthilf
 
Patterns et bonnes pratiques autour de JavaScript
Patterns et bonnes pratiques autour de JavaScriptPatterns et bonnes pratiques autour de JavaScript
Patterns et bonnes pratiques autour de JavaScriptMicrosoft Technet France
 
Comment trouver et fixer des memory leaks dans une app Vue/Nuxt
Comment trouver et fixer des memory leaks dans une app Vue/NuxtComment trouver et fixer des memory leaks dans une app Vue/Nuxt
Comment trouver et fixer des memory leaks dans une app Vue/NuxtJonathanMartin201
 
Sauvegarder et restaurer l'état des applications mobiles
Sauvegarder et restaurer l'état des applications mobilesSauvegarder et restaurer l'état des applications mobiles
Sauvegarder et restaurer l'état des applications mobilespprem
 
Function oop - bonnes pratiques ms tech days
Function   oop - bonnes pratiques ms tech daysFunction   oop - bonnes pratiques ms tech days
Function oop - bonnes pratiques ms tech daysJean-Pierre Vincent
 
Android Lab Test : Le WIFI (français)
Android Lab Test : Le WIFI (français)Android Lab Test : Le WIFI (français)
Android Lab Test : Le WIFI (français)Bruno Delb
 
Initiation au développement mobile sous Android
Initiation au développement mobile sous AndroidInitiation au développement mobile sous Android
Initiation au développement mobile sous AndroidAbdelkader Rhouati
 
Développer une application android en 2015
Développer une application android  en 2015Développer une application android  en 2015
Développer une application android en 2015Florent Champigny
 

Similaire à Pres android nuit de l'info v3 (20)

Tutorial android
Tutorial androidTutorial android
Tutorial android
 
Play framework - Human Talks Grenoble - 12.02.2013
Play framework - Human Talks Grenoble - 12.02.2013Play framework - Human Talks Grenoble - 12.02.2013
Play framework - Human Talks Grenoble - 12.02.2013
 
Android Lab Test : La prévisualisation de la caméra (français)
Android Lab Test : La prévisualisation de la caméra (français)Android Lab Test : La prévisualisation de la caméra (français)
Android Lab Test : La prévisualisation de la caméra (français)
 
Android2017 cours2
Android2017 cours2Android2017 cours2
Android2017 cours2
 
La mobilité dans Drupal
La mobilité dans DrupalLa mobilité dans Drupal
La mobilité dans Drupal
 
Jug Lausanne Android Janvier2013
Jug Lausanne Android Janvier2013Jug Lausanne Android Janvier2013
Jug Lausanne Android Janvier2013
 
Lbv Dev Meetup #2
 Lbv Dev Meetup #2 Lbv Dev Meetup #2
Lbv Dev Meetup #2
 
TP_2.pdf
TP_2.pdfTP_2.pdf
TP_2.pdf
 
Android introvf
Android introvfAndroid introvf
Android introvf
 
Initiation à la réalité augmentée sur Windows Phone 7.5 (Mango)
Initiation à la réalité augmentée sur Windows Phone 7.5 (Mango)Initiation à la réalité augmentée sur Windows Phone 7.5 (Mango)
Initiation à la réalité augmentée sur Windows Phone 7.5 (Mango)
 
Introduction à Android
Introduction à AndroidIntroduction à Android
Introduction à Android
 
Chap android
Chap androidChap android
Chap android
 
Backbonejs presentation
Backbonejs presentationBackbonejs presentation
Backbonejs presentation
 
Patterns et bonnes pratiques autour de JavaScript
Patterns et bonnes pratiques autour de JavaScriptPatterns et bonnes pratiques autour de JavaScript
Patterns et bonnes pratiques autour de JavaScript
 
Comment trouver et fixer des memory leaks dans une app Vue/Nuxt
Comment trouver et fixer des memory leaks dans une app Vue/NuxtComment trouver et fixer des memory leaks dans une app Vue/Nuxt
Comment trouver et fixer des memory leaks dans une app Vue/Nuxt
 
Sauvegarder et restaurer l'état des applications mobiles
Sauvegarder et restaurer l'état des applications mobilesSauvegarder et restaurer l'état des applications mobiles
Sauvegarder et restaurer l'état des applications mobiles
 
Function oop - bonnes pratiques ms tech days
Function   oop - bonnes pratiques ms tech daysFunction   oop - bonnes pratiques ms tech days
Function oop - bonnes pratiques ms tech days
 
Android Lab Test : Le WIFI (français)
Android Lab Test : Le WIFI (français)Android Lab Test : Le WIFI (français)
Android Lab Test : Le WIFI (français)
 
Initiation au développement mobile sous Android
Initiation au développement mobile sous AndroidInitiation au développement mobile sous Android
Initiation au développement mobile sous Android
 
Développer une application android en 2015
Développer une application android  en 2015Développer une application android  en 2015
Développer une application android en 2015
 

Plus de Claude Falguiere

H2O , Le machine learning sans coder ou presque - Devoxx france 2016
H2O , Le machine learning sans coder ou presque - Devoxx france 2016H2O , Le machine learning sans coder ou presque - Devoxx france 2016
H2O , Le machine learning sans coder ou presque - Devoxx france 2016Claude Falguiere
 
Pres perf human talks mars 2015
Pres perf human talks mars 2015Pres perf human talks mars 2015
Pres perf human talks mars 2015Claude Falguiere
 
Presentation devoxx4kids à iut-agile
Presentation devoxx4kids à iut-agilePresentation devoxx4kids à iut-agile
Presentation devoxx4kids à iut-agileClaude Falguiere
 
Le monitoring à l'heure de DevOps et Big Data
Le monitoring à l'heure de DevOps et Big DataLe monitoring à l'heure de DevOps et Big Data
Le monitoring à l'heure de DevOps et Big DataClaude Falguiere
 
Présentation du user group Duchess France au GDG de Nantes
Présentation du user group Duchess France au GDG de NantesPrésentation du user group Duchess France au GDG de Nantes
Présentation du user group Duchess France au GDG de NantesClaude Falguiere
 
Présentation de Page Speed au GDG de Nantes
Présentation de Page Speed au GDG de NantesPrésentation de Page Speed au GDG de Nantes
Présentation de Page Speed au GDG de NantesClaude Falguiere
 
Présentation Performances Montpellier
Présentation Performances Montpellier Présentation Performances Montpellier
Présentation Performances Montpellier Claude Falguiere
 
Performance test - YaJUG Octobre 2012
Performance test - YaJUG Octobre 2012Performance test - YaJUG Octobre 2012
Performance test - YaJUG Octobre 2012Claude Falguiere
 
La marmite Intro session NoSQL
La marmite Intro session NoSQLLa marmite Intro session NoSQL
La marmite Intro session NoSQLClaude Falguiere
 
Analyse de données avec Incanter
Analyse de données avec IncanterAnalyse de données avec Incanter
Analyse de données avec IncanterClaude Falguiere
 
Analyse de données avec Incanter
Analyse de données avec IncanterAnalyse de données avec Incanter
Analyse de données avec IncanterClaude Falguiere
 
Quickie Incanter/Clojure à Devoxx France 2012
Quickie Incanter/Clojure à Devoxx France 2012Quickie Incanter/Clojure à Devoxx France 2012
Quickie Incanter/Clojure à Devoxx France 2012Claude Falguiere
 
Deploiement continu breizh camp
Deploiement continu breizh campDeploiement continu breizh camp
Deploiement continu breizh campClaude Falguiere
 
Deploiement continu AgileFfrance 2011
Deploiement continu AgileFfrance 2011Deploiement continu AgileFfrance 2011
Deploiement continu AgileFfrance 2011Claude Falguiere
 

Plus de Claude Falguiere (20)

H2O , Le machine learning sans coder ou presque - Devoxx france 2016
H2O , Le machine learning sans coder ou presque - Devoxx france 2016H2O , Le machine learning sans coder ou presque - Devoxx france 2016
H2O , Le machine learning sans coder ou presque - Devoxx france 2016
 
Pres perf human talks mars 2015
Pres perf human talks mars 2015Pres perf human talks mars 2015
Pres perf human talks mars 2015
 
Devoxx 2014 monitoring
Devoxx 2014 monitoringDevoxx 2014 monitoring
Devoxx 2014 monitoring
 
Devoxx 2014 Monitoring
Devoxx 2014 Monitoring Devoxx 2014 Monitoring
Devoxx 2014 Monitoring
 
Presentation devoxx4kids à iut-agile
Presentation devoxx4kids à iut-agilePresentation devoxx4kids à iut-agile
Presentation devoxx4kids à iut-agile
 
Le monitoring à l'heure de DevOps et Big Data
Le monitoring à l'heure de DevOps et Big DataLe monitoring à l'heure de DevOps et Big Data
Le monitoring à l'heure de DevOps et Big Data
 
Présentation du user group Duchess France au GDG de Nantes
Présentation du user group Duchess France au GDG de NantesPrésentation du user group Duchess France au GDG de Nantes
Présentation du user group Duchess France au GDG de Nantes
 
Présentation de Page Speed au GDG de Nantes
Présentation de Page Speed au GDG de NantesPrésentation de Page Speed au GDG de Nantes
Présentation de Page Speed au GDG de Nantes
 
Présentation Performances Montpellier
Présentation Performances Montpellier Présentation Performances Montpellier
Présentation Performances Montpellier
 
Performance test - YaJUG Octobre 2012
Performance test - YaJUG Octobre 2012Performance test - YaJUG Octobre 2012
Performance test - YaJUG Octobre 2012
 
La marmite Intro session NoSQL
La marmite Intro session NoSQLLa marmite Intro session NoSQL
La marmite Intro session NoSQL
 
Analyse de données avec Incanter
Analyse de données avec IncanterAnalyse de données avec Incanter
Analyse de données avec Incanter
 
Analyse de données avec Incanter
Analyse de données avec IncanterAnalyse de données avec Incanter
Analyse de données avec Incanter
 
Incanter bigdata jsc2012
Incanter bigdata jsc2012Incanter bigdata jsc2012
Incanter bigdata jsc2012
 
Quickie Incanter/Clojure à Devoxx France 2012
Quickie Incanter/Clojure à Devoxx France 2012Quickie Incanter/Clojure à Devoxx France 2012
Quickie Incanter/Clojure à Devoxx France 2012
 
Diagnostic performances
Diagnostic performancesDiagnostic performances
Diagnostic performances
 
Diagnostic performances
Diagnostic performancesDiagnostic performances
Diagnostic performances
 
Usine logicielle ios
Usine logicielle iosUsine logicielle ios
Usine logicielle ios
 
Deploiement continu breizh camp
Deploiement continu breizh campDeploiement continu breizh camp
Deploiement continu breizh camp
 
Deploiement continu AgileFfrance 2011
Deploiement continu AgileFfrance 2011Deploiement continu AgileFfrance 2011
Deploiement continu AgileFfrance 2011
 

Pres android nuit de l'info v3

  • 1. Android Camera the making of MarsJUG Aix en Provence - Marseille 6 Décembre 2012 @cfalguiere jeudi 6 décembre 12
  • 2. Claude Falguière Architecte Technique Valtech http://cfalguiere.wordpress.com Duchess France, Paris JUG, Devoxx4Kids @cfalguiere jeudi 6 décembre 12
  • 3. Objectif questions apprendre gadget fun pour Devoxx alimenter un hacker space Duchess @cfalguiere jeudi 6 décembre 12
  • 4. IDE ADT : Eclipse + Plugins ADT + SDK Eclipse http://developer.android.com @cfalguiere jeudi 6 décembre 12
  • 5. IDE ADT : Eclipse + Plugins ADT + SDK Plugins http://developer.android.com @cfalguiere jeudi 6 décembre 12
  • 6. IDE ADT : Eclipse + Plugins ADT + SDK Platform Tools http://developer.android.com @cfalguiere jeudi 6 décembre 12
  • 7. IDE Android Virtual Device (AVD) @cfalguiere jeudi 6 décembre 12
  • 8. Hello Hello World onCreate onPause onResume onDestroy Activity GroupView Hello World (layout) TextView @cfalguiere jeudi 6 décembre 12
  • 9. Hello Activity GroupView Hello World (layout) Go TextView ImageView Button @cfalguiere jeudi 6 décembre 12
  • 10. Camera SurfaceHolder Camera (layout) Activity SurfaceView @cfalguiere jeudi 6 décembre 12
  • 11. Camera SurfaceHolder Camera (layout) Activity SurfaceView @cfalguiere jeudi 6 décembre 12
  • 12. Camera open release Camera Activity RelativeLayout SurfaceView SurfaceHolder surfaceCreated surfaceDestroyed surfaceChanged CameraPreview startPreview stopPreview Camera @cfalguiere jeudi 6 décembre 12
  • 13. Camera Activity RelativeLayout FrameLayout SurfaceView @cfalguiere CameraPreview jeudi 6 décembre 12
  • 14. Cameralayout/main_activity.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/ android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <FrameLayout android:id="@+id/cameraPreviewFrame" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" > </FrameLayout> <Button android:id="@+id/saveButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:background="@drawable/camera_icon" android:onClick="whenSave" /> </RelativeLayout> @cfalguiere jeudi 6 décembre 12
  • 15. Camera MainActivity.java protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mCamera = Camera.open(); CameraPreview cameraPreview = new CameraPreview(this, mCamera); FrameLayout previewFrame = (FrameLayout) findViewById(R.id.cameraPreviewFrame); previewFrame.addView(cameraPreview); ... CameraPreview.java public CameraPreview(Context context, Camera camera) { super(context); mCamera = camera; mHolder = getHolder(); mHolder.addCallback(this); ... @cfalguiere jeudi 6 décembre 12
  • 16. Camera manifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.duchescamera" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:screenOrientation="landscape"> <activity android:name="com.example.duchescamera.MainActivity" android:label="@string/app_name" > ... @cfalguiere jeudi 6 décembre 12
  • 17. Camera manifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.duchescameramini2" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> <!-- will make use of camera --> <uses-feature android:name="android.hardware.camera" android:required="true" /> <uses-permission android:name="android.permission.CAMERA" /> @cfalguiere jeudi 6 décembre 12
  • 18. Camera SurfaceView RelativeLayout Orientation par Orientation par défaut du device défaut de la camera @cfalguiere jeudi 6 décembre 12
  • 19. open setCameraDisplay (holder) startPreview takePicture stopPreview release @cfalguiere jeudi 6 décembre 12
  • 20. Photo layout/main_activity.xml <Button android:id="@+id/saveButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:background="@drawable/camera_icon" android:onClick="whenSave" /> @cfalguiere jeudi 6 décembre 12
  • 21. Photo whenSave takePicture Activity Camera onPictureTaken onShutter ShutterCallback RawCallback PictureCallback «Click» générer le fichier MainActivity.java public void whenSave(View view) { mCamera.takePicture(shutterCallback, null, jpegPictureCallback); } @cfalguiere jeudi 6 décembre 12
  • 22. Photo MainActivity.java private SoundPool mSoundPool; private int mShutterSoundId; private float mShutterSoundVolume = 0.5f; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mSoundPool = new SoundPool(1, AudioManager.STREAM_NOTIFICATION, 0); mShutterSoundId = mSoundPool.load(this, R.raw.camera_click, 1); ... public void whenSave(View view) { Camera.ShutterCallback shutterCallback = new Camera.ShutterCallback( public void onShutter() { mSoundPool.play(mShutterSoundId, mShutterSoundVolume, mShutterSoundVolume, 1, 0, 1); } }; mCamera.takePicture(shutterCallback, null, mJpegPictureCallback); ... @cfalguiere jeudi 6 décembre 12
  • 23. Photo PictureCallback public void onPictureTaken(byte[] data, Camera camera) { try { Bitmap photo = BitmapFactory.decodeByteArray(data, 0,data.length); // Create a new, empty bitmap with the original size. Bitmap bitmap = Bitmap.createBitmap(photo.getWidth(), photo.getHeight(), photo.getConfig()); Canvas canvas = new Canvas(bitmap); canvas.drawBitmap(photo, 0, 0, null); // save file File pictureFile = getOutputMediaFile(); FileOutputStream fos = new FileOutputStream(pictureFile); bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos); addPictureToGalery(pictureFile.getPath()); } catch (Exception e) { Log.d(TAG, "ERROR Could not save picture: " + e.getMessage()); } } @cfalguiere jeudi 6 décembre 12
  • 24. Photo PictureCallback private void addPictureToGalery(String path) { Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); Uri contentUri = Uri.fromFile(new File(path)); mediaScanIntent.setData(contentUri); mActivity.sendBroadcast(mediaScanIntent); } @cfalguiere jeudi 6 décembre 12
  • 25. Incrustation Activity RelativeLayout FrameLayout ImageView SurfaceView onDraw DrawView CameraPreview @cfalguiere jeudi 6 décembre 12
  • 26. Incrustation onDraw DuchessSprite Canvas DrawPreview draw y x @cfalguiere jeudi 6 décembre 12
  • 27. Incrustation onDraw DuchessSprite draw DrawPreview Canvas draw MoveFeedbackSprite draw RotationFeedbackSprite @cfalguiere jeudi 6 décembre 12
  • 28. Incrustation DuchessSprite.java private Bitmap bitmap; // the actual bitmap public void draw(Canvas canvas, float ratio) { Matrix matrix = new Matrix(); float s = 1 / bitmapScale; int cw = Math.round(bitmap.getWidth() / 2); int ch = Math.round(bitmap.getHeight() / 2); canvas.drawBitmap(bitmap, matrix, null); } @cfalguiere jeudi 6 décembre 12
  • 29. Incrustation DuchessSprite.java private Bitmap bitmap; // the actual bitmap public void draw(Canvas canvas, float ratio) { Matrix matrix = new Matrix(); float s = 1 / bitmapScale; int cw = Math.round(bitmap.getWidth() / 2); int ch = Math.round(bitmap.getHeight() / 2); matrix.setScale(s, s, cw, ch); canvas.drawBitmap(bitmap, matrix, null); } @cfalguiere jeudi 6 décembre 12
  • 30. Incrustation DuchessSprite.java private Bitmap bitmap; // the actual bitmap public void draw(Canvas canvas, float ratio) { Matrix matrix = new Matrix(); float s = 1 / bitmapScale; int cw = Math.round(bitmap.getWidth() / 2); int ch = Math.round(bitmap.getHeight() / 2); matrix.setScale(s, s, cw, ch); matrix.postTranslate(centerX - cw, centerY - ch); canvas.drawBitmap(bitmap, matrix, null); } @cfalguiere jeudi 6 décembre 12
  • 31. Incrustation DuchessSprite.java private Bitmap bitmap; // the actual bitmap public void draw(Canvas canvas, float ratio) { Matrix matrix = new Matrix(); float s = 1 / bitmapScale; int cw = Math.round(bitmap.getWidth() / 2); int ch = Math.round(bitmap.getHeight() / 2); matrix.setScale(s, s, cw, ch); matrix.postTranslate(centerX - cw, centerY - ch); matrix.postScale(ratio, ratio); canvas.drawBitmap(bitmap, matrix, null); } @cfalguiere jeudi 6 décembre 12
  • 32. DrawView.java public boolean onTouchEvent(MotionEvent event) { final int action = event.getAction(); switch (action & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: { mDuchess.handleActionDown((int)event.getX(), (int)event.getY()); // update touched break; } case MotionEvent.ACTION_MOVE: { if (mDuchess.isTouched()) { mDuchess.setCenterX((int)event.getX()); mDuchess.setCenterY((int)event.getY()); invalidate(); } break; } case MotionEvent.ACTION_UP: { if (mDuchess.isTouched()) { mDuchess.setTouched(false); } reak; } } return true; } @cfalguiere jeudi 6 décembre 12
  • 33. Incrustation onTouchEvent DrawView public DrawView(Context context, DuchessSprite duchess) { super(context); ... // make the Panel focusable so it can handle events setFocusable(true); setFocusableInTouchMode(true); } @cfalguiere jeudi 6 décembre 12
  • 34. Merci Questions Claude Falguière @cfalguiere goo.gl/4mmJQ @cfalguiere jeudi 6 décembre 12
  • 36. Lab 0 Installer ADT http://developer.android.com/sdk/index.html Installer git (préférable) http://developer.android.com @cfalguiere jeudi 6 décembre 12
  • 37. Lab 1 Créez un repo Git (git init) Créez un workspace Eclipse sur la racine du repo Créez un projet dans Eclipse • New «Android Application Project» • (Facultatif) choisissez l’icone Photo dans Clipart • une activité MainActivity par défaut Lancez l’application dans le simulateur • Créez un AVD Galaxy Nexus • Exécutez dans le simulateur Lancez l’application sur un device connecté @cfalguiere jeudi 6 décembre 12
  • 38. Lab 2 Affichez la caméra dans votre application vous aurez besoin • de modifier le layout (RelativeLayout et FrameLayout) • d’implémenter un SurfaceView • de la feature android.hardware.camera • de la permission android.permission.CAMERA • de corriger l’orientation @cfalguiere jeudi 6 décembre 12
  • 39. Lab 3 Ajoutez le bouton et prennez une photo (Facultatif) ajoutez le son vous aurez besoin • du composant graphique Button • de l’icône du bouton : drawable/camera_icon.png • de l’implémentation du PictureCallback • de la permission android.permission.WRITE_EXTERNAL_STORAGE • du fichier son camera_click.ogg (Facultatif) • de la classe SoundPool (Facultatif) @cfalguiere jeudi 6 décembre 12
  • 40. Lab 4 Ajoutez une vue ImageView custom et affichez Duchess vous aurez besoin • de l’image du sprite : drawable/ duchessfr_shadow.png • de l’implémentation du Sprite DuchessSprite @cfalguiere jeudi 6 décembre 12
  • 41. Lab 5 Ajoutez la possibilité de déplacer le sprite (Facultatif) affichez un feedback visuel vous aurez besoin • de l’implémentation du Sprite DragFeedbackSprite (Facultatif) @cfalguiere jeudi 6 décembre 12