Slide 1

Slide 1 text

Xamarin for not only Android developers Aleksander Piotrowski @pelotasplus

Slide 2

Slide 2 text

What platform needs to be a rockstar platform

Slide 3

Slide 3 text

IDE Visionary Documentation Jake Wharton Testing tools/services Emulator Third-party components Library Events Blogs/podcasts Programing Language

Slide 4

Slide 4 text

History a rising star

Slide 5

Slide 5 text

2000 Microsoft announces .NET Framework 2001 Mono project launched by Ximian 2003 Ximian bought by Novell 2004 Mono first release 2009 MonoTouch 1.0 2011 MonoAndroid first release 2011 Novell acquired by Attachmate 0000 Xamarin is founded 2012 Xamarin.Mac 2013 Xamarin Studio .NET is 15 years old mono is 11 years old Xamarin.iOS is 7 years old Xamarin.Android is 4 years old modern Xamarin is 2 years old

Slide 6

Slide 6 text

Miguel de Icaza ● never received a degree ● free software developer since 1992 ● Midnight Commander ● early Wine contributor ● worked on Linux Sun SPARC ● later on Linux for SGI Indy ● almost did Internet Explorer port to SPARC ● started GNOME project and created Gnumeric ● started Mono project to implement .NET on Linux source: wikipedia

Slide 7

Slide 7 text

source: wikipedia

Slide 8

Slide 8 text

Pricing not free for personal use

Slide 9

Slide 9 text

command line support good IDE x2 if targeting both iOS and Android

Slide 10

Slide 10 text

Write once run everywhere* * that to run your app on every device make sure it contains nothing else but white background without any other UI elements

Slide 11

Slide 11 text

Supported platforms ● target: ○ Android, iOS, Mac ○ Windows Phone by sharing C# code between projects ● development: ○ Mac: for all platforms excluding Windows ○ Windows: for all platforms by using remote Mac ○ Linux: -

Slide 12

Slide 12 text

What is ● single language for all platforms - C# ● single base library - .NET Base Class Library plus specific libraries for target platforms MonoTouch or Mono.Android ● single runtime for all targeted platforms iOS, Android, Windows Phone ● “performant enough even for demanding games”

Slide 13

Slide 13 text

What is not ● write once and run anywhere ● use one one platform (Mac or Windows) to target them all (iOS, Android, Windows) ● one UI for all target platforms

Slide 14

Slide 14 text

Native vs non-native iOS ● native code at the end ● AOT compiler converts Xamarin app to native ARM code Android ● no final native code ● Xamarin compiler creates IL (Intermediate Language) which is executed at runtime on the device

Slide 15

Slide 15 text

Fat binary vs slim debug build ● Hello world + Base Class Library: 15.8MB ● Hello world + BCL after Linking: 2.9MB ● Hello world debug release: 6KB + Mono Shared components: 10MB source: used to be here http://developer.xamarin.com/guides/android/advanced_topics/linking/

Slide 16

Slide 16 text

IDE one to rule them all

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

IDE ● have to switch manually between iOS and Android in multiplatform projects ● ultra annoying “app is running, are you sure you want to stop it and install new version?” ● cannot compare to IntelliJ aka IDEA ● Visual Studio to the rescue ● overriding methods CMD-I

Slide 19

Slide 19 text

Let’s code and have fun hopefully

Slide 20

Slide 20 text

Let’s code in C# and F# var i = 10; // implicitly typed int i = 10; // explicitly typed #define preprocessor directive ulong, ushort unsigned types async/await for asynchronous programming mandatory break in switch Lambda expression Generics with runtime type support namespaces properties

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

Let’s code in Java or Objective-C ● using Java Native Interface (JNI), or ● using bindings for Java code ● with Objective-C creating binding ● straightforward process, for the second time

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

Project^wSolution structure

Slide 26

Slide 26 text

Solution structure ● References - base .Net classes ● Components ● Packages ● Assets ● Properties ● Resources ● our code ● and even maybe tests...

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

Code sharing

Slide 29

Slide 29 text

Layers ● Data Layer SQLite ● Data Access Layer create, read, update, delete ● Business Logic data model and business logic ● Service Access Layer access REST, parsing JSON ● Application Layer platform specific code but not UI-related ● User Interface Layer UI-related code shared not shared shared shared shared not shared

Slide 30

Slide 30 text

source: https://xamarin.com/forms

Slide 31

Slide 31 text

Code Sharing ● Shared Project ● Portable Class Library

Slide 32

Slide 32 text

Shared Project ● no .dll as an output ● “compiled into” referencing project ● not compiled, if not used ● platform specific code via #if statements ○ #if __MOBILE__ ○ #if __ANDROID__ ● “for personal use only”

Slide 33

Slide 33 text

source: http://developer.xamarin.com/guides/cross-platform/application_fundamentals/shared_projects/

Slide 34

Slide 34 text

Portable Class Library ● using a subset of BCL called Profile ● targets many different (supported) platforms ● no platform-specific libraries allowed ● refactoring of PCL affects all referencing projects ● good for sharing with others

Slide 35

Slide 35 text

source: http://developer.xamarin.com/guides/cross-platform/application_fundamentals/building_cross_platform_applications/sharing_code_options/

Slide 36

Slide 36 text

source: http://developer.xamarin.com/guides/cross-platform/application_fundamentals/building_cross_platform_applications/sharing_code_options/

Slide 37

Slide 37 text

UI design

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

Xamarin Forms

Slide 41

Slide 41 text

source: https://xamarin.com/forms

Slide 42

Slide 42 text

source: video @ https://xamarin.com/forms

Slide 43

Slide 43 text

Forms ● single app screen called a Page ● Page contains layouts (StackLayout, GridLayout) and UI elements (Button, Image, SearchBar, WebView) ● connect actions (click event, long press event) to code which is shared across all platforms ● at the end at run-time all UI elements are mapped to native platform- specific UI components

Slide 44

Slide 44 text

Forms ● can be written in pure code ○ sounds a bit like old school iOS style ● or in XAML layout files ○ sounds more like Android style ○ not supporting existing XAML editor :-/ ○ layouts have supporting class, so called CodeBehind class ● using MVVM pattern

Slide 45

Slide 45 text

source: https://xamarin.com/forms

Slide 46

Slide 46 text

source: https://xamarin.com/forms

Slide 47

Slide 47 text

source: https://xamarin.com/forms

Slide 48

Slide 48 text

source: https://xamarin.com/forms

Slide 49

Slide 49 text

Pros ● data entry apps ● prototypes & proof-of- concept apps ● little platform-specific APIs ● code sharing over custom UI Cons ● specialized interaction required ● highly polished design ● many platform- specific APIs ● custom UI above code sharing

Slide 50

Slide 50 text

Emulator or is it simulator

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

Xamarin Player ● simulate, debug, demo or run Android apps in our fast and hassle-free environment. only Android apps ● integrated with Xamarin Studio and Visual Studio ● native UI on Windows and Mac ● widgets for location and battery ● easy screenshot taking

Slide 55

Slide 55 text

Xamarin Player ● x86 virtual machine with HW acceleration ● VT-x AMD-V ● OpenGL 2.0 ● uses VirtualBox 5.0.4

Slide 56

Slide 56 text

Xamarin Player ● can install non-Xamarin native Android APKs? YES ● supports Google Play Services? YES via installing third-party provided ZIP file ● hmm, sounds like a Genymotion clone? YES indeed

Slide 57

Slide 57 text

Xamarin Player ● free ● less widgets ● better drag & drop ● fixed aspect window scaling ● couple of device configurations ● paid ● more widgets ● drag & drop ● window scaling ● lots of device configurations

Slide 58

Slide 58 text

Documentation for C#, Android, iOS, and ...

Slide 59

Slide 59 text

Documentation ● for all targeted platforms Xamarin.Android, Xamarin.iOS, Xamarin.Forms, Xamarin.Mac and Windows ● Android developer could learn iOS app architecture ● explains not only C# or Xamarin-related aspects but also basics of the platforms ● always with “download as PDF”

Slide 60

Slide 60 text

Documentation ● iOS app fundamentals http://developer.xamarin.com/guides/ios/application_fundamentals/ Protocols, Events, and Delegates ● iOS user interface http://developer.xamarin.com/guides/ios/user_interface/ UIKit, Tables and cells, Storyboards ● platform features http://developer.xamarin.com/guides/ios/platform_features/ Newsstand, HealthKit, and iOS 9 introduction

Slide 61

Slide 61 text

Documentation ● Android app fundamentals http://developer.xamarin.com/guides/android/application_fundamentals/ API levels, Activity lifecycle, Handling rotation ● Android user interface http://developer.xamarin.com/guides/android/user_interface/ Actionbar, Splash screen, List view & adapters, RecyclerView ● platform features http://developer.xamarin.com/guides/android/platform_features/ Fragments, ContentProvider, new Android versions

Slide 62

Slide 62 text

Third-party libraries maven, pip, apt, cocoapods, npm, we want more!

Slide 63

Slide 63 text

Third-party libraries ● components via Xamarin Components Store ● packages via NuGet package manager ● libraries & UI components ● easily to be added to a project

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

Components ● HockeyApp ● Crittercism ● SQLCipher 499$ ● Facebook SDK by Xamarin Inc. ● Parse SDK by Parse Inc. ● Tip of the Day

Slide 66

Slide 66 text

No content

Slide 67

Slide 67 text

Packages ● for Android, iOS, or both ● native C# ● via NuGet packages by .NET Foundation ● 44,015 packages

Slide 68

Slide 68 text

Packages ● Android Support Library, Design Library, RecyclerView by Xamarin ● Android Picasso by jacksierkstra ● iOS SVProgressHUD (wrapper) ● iOS FloatLabelEntry (native) ● Parse.com in 6 versions

Slide 69

Slide 69 text

Packages ● get data from RESTful API and store it in data model ● refit by paulcbetts ● one C# code for Android, iOS and .NET RESTful API data model network service in our app AFNetworking Retrofit Retrofit manually as a dict

Slide 70

Slide 70 text

Packages ● get data from network ● iOS AFNetworking ● Android OkHttp latest is 2.5.0 ● Xamarin ModernHttpClient on iOS NSURLSession on Android OkHttp 2.4.0

Slide 71

Slide 71 text

Testing in case you have time for that

Slide 72

Slide 72 text

Testing ● Xamarin Test Cloud ● Calabash

Slide 73

Slide 73 text

Xamarin Test Cloud ● 1,800 devices and adding 100 monthly ● stars at 1,000 USD/month paid annualy … for 2 apps ● 5,000 USD for 5 apps ● NUnit or Calabash tests ● screenshots, device performance for every step of every test

Slide 74

Slide 74 text

source: https://xamarin.com/test-cloud

Slide 75

Slide 75 text

source: https://xamarin.com/test-cloud

Slide 76

Slide 76 text

Calabash ● automated UI tests ● using Behavior Driven Development approach ● written in Ruby, or Cucumber, or Gherkin

Slide 77

Slide 77 text

source: http://developer.xamarin.com/guides/testcloud/introduction-to-test-cloud/

Slide 78

Slide 78 text

Scenario: Credit card number too short Given I am on the Credit Card Validation Screen When I enter a credit card number that's 16 digits long And I click on the Validate button Then I should see a validation error source: http://developer.xamarin.com/guides/testcloud/calabash/introduction-to-calabash/

Slide 79

Slide 79 text

Community and expensive conference

Slide 80

Slide 80 text

Community ● blogs ● developer advocates and their apps James Montemagno https://github.com/jamesmontemagno ● podcast - Xamarin Podcast http://pca.st/9cXF ● their own WWDC, also quite pricey 1,499$ Xamarin Evolve ● Paul C. Betts and his libraries https://github.com/paulcbetts/

Slide 81

Slide 81 text

IDE Visionary Documentation Jake Wharton Testing tools/services Emulator Third-party components Library Events Blogs/podcasts Programing Language

Slide 82

Slide 82 text

IDE Visionary Documentation Jake Wharton Testing tools/services Emulator Blogs/podcasts Third-party components Library Events Paul C Betts Xamarin Studio Xamarin Podcast Miguel de Icaza Documentation Evolve Xamarin Android Player Components & packages Test Cloud & Calabash Programing Language C#, F#, support native

Slide 83

Slide 83 text

No content