Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Hitchikers guide to Modern Android Development

931 views

Published on

Hitchikers guide to Modern Android Development from Voxxed Days Istanbul, MobCon Bulgaria and DroidCon Dubai

  • Be the first to comment

Hitchikers guide to Modern Android Development

  1. 1. Murat Yener @yenerm Hitchhikers Guide to Modern Android Development
  2. 2. Murat Yener @yenerm Hitchhikers Guide to Modern Android Development
  3. 3. Soo, who am I?!? Java, Web, Mobile, GWT, Flex Developer Android Developer at Intel Eclipse Comitter Book Author (Java EE Design Patterns) GDG Istanbul Organizer since 2009 Conference Speaker (JavaOne, Devoxx, EclipseCon..)
  4. 4. Soo, who am I?!? Java, Web, Mobile, GWT, Flex Developer Android Developer at Intel Eclipse Comitter Book Author (Java EE Design Patterns) GDG Istanbul Organizer since 2009 Conference Speaker (JavaOne, Devoxx, EclipseCon..)
  5. 5. ABOUT US Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat it.
  6. 6. SOCIAL MEDIA Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat it. History of Android
  7. 7. 5 pre-historic (cupcake, donut)
  8. 8. 6 genesis (eclair, froyo, gingerbread)
  9. 9. 7 (r)evolution (>4.0)
  10. 10. 8 modern era 5.0 APIS Android Studio Material Design Wear Gradle Libraries
  11. 11. 9 Android OS • Notifications (metadata) • Camera 2.0 • Job Scheduler • Printing Framework • Multiple Sim (>=5.1)
  12. 12. 9 Android OS • Notifications (metadata) • Camera 2.0 • Job Scheduler • Printing Framework • Multiple Sim (>=5.1) VISIBILITY_PRIVATE VISIBILITY_PUBLIC VISIBILITY_SECRET
  13. 13. 9 Android OS • Notifications (metadata) • Camera 2.0 • Job Scheduler • Printing Framework • Multiple Sim (>=5.1)
  14. 14. 9 Android OS • Notifications (metadata) • Camera 2.0 • Job Scheduler • Printing Framework • Multiple Sim (>=5.1) CameraManager manager = (CameraManager) getSystemService(CAMERA_SERVICE); manager.openCamera(cameraId, mStateCallback, null); private CameraDevice.StateCallback mStateCallback = new CameraDevice.StateCallback() { @Override public void onOpened(CameraDevice camera) { try { mPreviewBuilder = camera(CameraDevice.TEMPLATE_PREVIEW); } catch (CameraAccessException e){ e.printStackTrace(); } //… try { mCameraDevice.createCaptureSession(Arrays.asList(surface), mPreviewStateCallback, null); } catch (CameraAccessException e) { e.printStackTrace();} } }; private CameraCaptureSession.StateCallback mPreviewStateCallback = new CameraCaptureSession.StateCallback() { @Override public void onConfigured(CameraCaptureSession session) {…} };
  15. 15. 9 Android OS • Notifications (metadata) • Camera 2.0 • Job Scheduler • Printing Framework • Multiple Sim (>=5.1)
  16. 16. 9 Android OS • Notifications (metadata) • Camera 2.0 • Job Scheduler • Printing Framework • Multiple Sim (>=5.1) JobInfo uploadTask = new JobInfo.Builder(mJobId, mServiceComponent /* JobService component */) .setRequiredNetworkCapabilities(JobInfo.NetworkType.UNMETERED) .build(); JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE); jobScheduler.schedule(uploadTask);
  17. 17. 9 Android OS • Notifications (metadata) • Camera 2.0 • Job Scheduler • Printing Framework • Multiple Sim (>=5.1)
  18. 18. 9 Android OS • Notifications (metadata) • Camera 2.0 • Job Scheduler • Printing Framework • Multiple Sim (>=5.1) mPdfRenderer = new PdfRenderer(mFileDescriptor); int x=mPdfRenderer.getPageCount(); mCurrentPage = mPdfRenderer.openPage(x); bitmap = Bitmap.createBitmap(mCurrentPage.getWidth(), mCurrentPage.getHeight(),Bitmap.Config.ARGB_8888); mCurrentPage.render(bitmap, null, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);
  19. 19. 9 Android OS • Notifications (metadata) • Camera 2.0 • Job Scheduler • Printing Framework • Multiple Sim (>=5.1)
  20. 20. 9 Android OS • Notifications (metadata) • Camera 2.0 • Job Scheduler • Printing Framework • Multiple Sim (>=5.1) SubscriptionManager.OnSubscriptionsChangedListener{…}
  21. 21. 9 Android OS • Notifications (metadata) • Camera 2.0 • Job Scheduler • Printing Framework • Multiple Sim (>=5.1)
  22. 22. 10 Material Design A material metaphor is the unifying theory of a rationalized space and a system of motion. The material is grounded in tactile reality, inspired by the study of paper and ink, yet technologically advanced and open to imagination and magic..
  23. 23. 11 Surfaces • Paper like surfaces • Multiple layers (up to 10) • Scrolls till end or behind
  24. 24. 12 Layout • 2 Keylines.. • Keyline 1 @ 16dp • Keyline 2 @ 72dp
  25. 25. 13 Colors and Theming • Main and accent color • Primary: toolbars • Primary.Dark: status bar
  26. 26. 14 Palette API • Get color palette from your pics • Vibrant, Muted • Swatch
  27. 27. 14 Palette API • Get color palette from your pics • Vibrant, Muted • Swatch PaletteItem darkMuted = palette.getDarkMutedColor(); PaletteItem muted = palette.getMutedColor(); PaletteItem lightMuted = palette.getLightMutedColor(); PaletteItem vibrant = palette.getVibrantColor(); PaletteItem lightVibrant = palette.getLightVibrantColor(); PaletteItem darkVibrant = palette.getDarkVibrantColor();
  28. 28. 14 Palette API • Get color palette from your pics • Vibrant, Muted • Swatch
  29. 29. 14 Palette API • Get color palette from your pics • Vibrant, Muted • Swatch Palette.Swatch swatch = palette.getVibrantSwatch(); if (swatch != null) { titleView.setBackgroundColor(swatch.getRgb()); titleView.setTextColor(swatch.getTitleTextColor()); }
  30. 30. 14 Palette API • Get color palette from your pics • Vibrant, Muted • Swatch
  31. 31. 15 Animation • Authentic Motion: realistic swift movement • Responsive Interaction: respond to user • Meaningful Transitions: physics, not random moves • Delightful Details: small makes change
  32. 32. 15 Animation • Authentic Motion: realistic swift movement • Responsive Interaction: respond to user • Meaningful Transitions: physics, not random moves • Delightful Details: small makes change
  33. 33. 16 New Platforms • teachings of Google Glass… • Android Wear • Android Auto • Android TV
  34. 34. 17 Google Glass • development: GDK for native apps or Glassware for HTML • limitations: no touch screen, limited input / battery / cpu, actions! (start a run, take a photo)
  35. 35. 18 Android Wear - Notifications Automatically works! -Phone transmits notifications to wear -You can code wear only notifications
  36. 36. 19 Android Wear -Development dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.google.android.support:wearable:+' compile 'com.google.android.gms:play-services-wearable:+' } 1
  37. 37. 20 Android Wear -Development 2 <activity android:name="MyNoteActivity"> <intent-filter> <action android:name="android.intent.action.SEND" /> <category android:name="com.google.android.voicesearch.SELF_NOTE" /> </intent-filter> </activity>
  38. 38. 21 private void displaySpeechRecognizer() { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); startActivityForResult(intent, SPEECH_REQUEST_CODE); } Android Wear -Development 3
  39. 39. 22 Android Wear -Development 4 // Build the notification and add the action via WearableExtender Notification notification = new NotificationCompat.Builder(mContext) .setSmallIcon(R.drawable.ic_message) .setContentTitle(getString(R.string.title)) .setContentText(getString(R.string.content)) .extend(new WearableExtender().addAction(action)) .build();
  40. 40. 23 Nexus Player - Development <activity android:name=".TvMainActivity“ > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LEANBACK_LAUNCHER" /> </intent-filter> </activity> compile "com.android.support:leanback-v17:21.0.+“
  41. 41. 24 Android Studio - Basics • IntelliJ based • Graduated from beta! • Better drag and drop UI designer
  42. 42. 25 Android Studio - Gradle apply plugin: ‘com.android.application' android { compileSdkVersion 21 buildToolsVersion "21.1.2" defaultConfig { applicationId "com.devchronicles.example" minSdkVersion 21 targetSdkVersion 21 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:palette-v7:21.0.0' }
  43. 43. 26 Tools • Android Device Monitor • Battery Historian • Faster Emulator
  44. 44. 26 Tools • Android Device Monitor • Battery Historian • Faster Emulator
  45. 45. 26 Tools • Android Device Monitor • Battery Historian • Faster Emulator
  46. 46. 27 Libraries “No man is an island..” -Jon Bon Jovi
  47. 47. 28 Greenbus • Event Driven • Event dispatch via bus • Uses reflection • Easy/clean compile 'de.greenrobot:eventbus:2.4.0'
  48. 48. 28 Greenbus • Event Driven • Event dispatch via bus • Uses reflection • Easy/clean public class SampleEvent { String message; } Subscriber: eventBus.register(this); public void onEvent(SampleEvent event) { event.message }; Producer: eventBus.post(event); compile 'de.greenrobot:eventbus:2.4.0'
  49. 49. 28 Greenbus • Event Driven • Event dispatch via bus • Uses reflection • Easy/clean compile 'de.greenrobot:eventbus:2.4.0'
  50. 50. 29 • From creators of greenbus • Standart sqlite • No ‘create table’ etc.. • Generator for model and dao GreenDAO compile 'de.greenrobot:greendao'
  51. 51. 29 • From creators of greenbus • Standart sqlite • No ‘create table’ etc.. • Generator for model and dao GreenDAO new DaoMaster.DevOpenHelper(this, "notes-db", null); daoMaster = new DaoMaster(db); daoSession = daoMaster.newSession(); noteDao = daoSession.getNoteDao(); Note note = new Note(null, noteText, comment, new Date()); noteDao.insert(note); compile 'de.greenrobot:greendao'
  52. 52. 29 • From creators of greenbus • Standart sqlite • No ‘create table’ etc.. • Generator for model and dao GreenDAO compile 'de.greenrobot:greendao'
  53. 53. 30 JobQueue • Easy to prioritize • Delay • or group jobs compile 'com.path:android-priority-jobqueue:1.1.2'
  54. 54. 30 JobQueue • Easy to prioritize • Delay • or group jobs jobManager.addJobInBackground(new PostTweetJob(status)); public class PostTweetJob extends Job { public static final int PRIORITY = 1; public PostTweetJob(String text) { super(new Params(PRIORITY).requireNetwork().persist()); } @Override public void onAdded() {} @Override public void onRun() throws Throwable { webservice.postTweet(text); } @Override protected boolean shouldReRunOnThrowable(Throwable throwable) {} compile 'com.path:android-priority-jobqueue:1.1.2'
  55. 55. 30 JobQueue • Easy to prioritize • Delay • or group jobs compile 'com.path:android-priority-jobqueue:1.1.2'
  56. 56. 31 Dagger • Dependency Injection • Standard javax.inject • Compile time code generation compile 'com.squareup:dagger:1.1.2' compile 'com.squareup:dagger-compiler:1.1.2'
  57. 57. 31 Dagger • Dependency Injection • Standard javax.inject • Compile time code generation class CoffeeMaker { @Inject Heater heater; @Inject Pump pump; ... } @Module class DripCoffeeModule { @Provides Heater provideHeater() { return new ElectricHeater(); } @Provides Pump providePump(Thermosiphon pump) { return pump; } } compile 'com.squareup:dagger:1.1.2' compile 'com.squareup:dagger-compiler:1.1.2'
  58. 58. 31 Dagger • Dependency Injection • Standard javax.inject • Compile time code generation compile 'com.squareup:dagger:1.1.2' compile 'com.squareup:dagger-compiler:1.1.2'
  59. 59. 32 Retrofit • Turns your REST api to Java Interface • Uses OkHttp • synchronous, asynchronous, observable compile 'com.squareup.retrofit:retrofit:1.9.0'
  60. 60. 32 Retrofit • Turns your REST api to Java Interface • Uses OkHttp • synchronous, asynchronous, observable public interface GitHubService { @GET("/users/{user}/repos") List<Repo> listRepos(@Path("user") String user); } RestAdapter restAdapter = new RestAdapter.Builder() .setEndpoint("https://api.github.com") .build(); GitHubService service = restAdapter.create(GitHubService.class); List<Repo> repos = service.listRepos("octocat"); compile 'com.squareup.retrofit:retrofit:1.9.0'
  61. 61. 32 Retrofit • Turns your REST api to Java Interface • Uses OkHttp • synchronous, asynchronous, observable compile 'com.squareup.retrofit:retrofit:1.9.0'
  62. 62. 33 Volley • Super easy • Internal queue • Internal cache • separate thread • not good for large downloads compile 'com.squareup.retrofit:retrofit:1.9.0'
  63. 63. 33 Volley • Super easy • Internal queue • Internal cache • separate thread • not good for large downloads RequestQueue queue = Volley.newRequestQueue(this); StringRequest stringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() { @Override public void onResponse(String response) { //.. } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { //.. } }); queue.add(stringRequest); compile 'com.squareup.retrofit:retrofit:1.9.0'
  64. 64. 33 Volley • Super easy • Internal queue • Internal cache • separate thread • not good for large downloads compile 'com.squareup.retrofit:retrofit:1.9.0'
  65. 65. Come join the fun, join a GDG!! @yenerm @gdgistanbul murat@muratyener.com

×