how to: mobile "hello world" with xamarin and visual studio 2013

33
“HELLO WORLD” WITH XAMARIN AND VISUAL STUDIO 2013 Presented at the Indy .NET Mobile Developers Group, May 2014 Brad Pillow, PillowSoft LLC

Upload: indymobilenetdev

Post on 23-Jun-2015

1.706 views

Category:

Software


4 download

DESCRIPTION

Introductory presentation on "hello world" for mobile, using Xamarin and VS 2013.

TRANSCRIPT

Page 1: How To: Mobile "Hello World" With Xamarin and Visual Studio 2013

“HELLO WORLD” WITH

XAMARIN AND

VISUAL STUDIO 2013Presented at the

Indy .NET Mobile Developers Group, May 2014 Brad Pillow, PillowSoft LLC

Page 2: How To: Mobile "Hello World" With Xamarin and Visual Studio 2013

GETTING STARTED: XAMARIN MAC

• Using Android? Install the Android SDK from here: http://developer.android.com/sdk/index.html#download

• Using iOS? Sign up to be an iOS developer here and then download tools: https://developer.apple.com/programs/ios/

• Developing for iOS or Android? Download Xamarin tools for the PC: http://xamarin.com/download#

• Get your free C# T-Shirt like mine here: https://xamarin.com/sharp-shirt

Page 3: How To: Mobile "Hello World" With Xamarin and Visual Studio 2013

GETTING STARTED: VS2013

• Download VS2013: http://www.visualstudio.com/en-us/downloads (Note: Xamarin will not work with Express versions!)

• Developing for iOS (see previous slide) • Developing for Android (see previous slide) • Developing for Windows Phone 8? Download: https://

dev.windowsphone.com/en-us/downloadsdk • Developing for iOS or Android? Download Xamarin tools for

the PC: http://xamarin.com/download#

Page 4: How To: Mobile "Hello World" With Xamarin and Visual Studio 2013

PREPARING FOR THIS TALK • I updated to the alpha release of Xamarin…i.e. my IDE has

the new look and feel

• I decided to update my Android SDK…bad idea. I got an error when opening the UI layout file, “layout renders disconnected”…see this link for a temporary fix: http://forums.xamarin.com/discussion/14344/disconnected-from-layout-renderer-error-after-updating-android-sdk-tools-to-version-22-6

• Ugh!

Page 5: How To: Mobile "Hello World" With Xamarin and Visual Studio 2013

PROJECT LAYOUT

Page 6: How To: Mobile "Hello World" With Xamarin and Visual Studio 2013

IOS

Page 7: How To: Mobile "Hello World" With Xamarin and Visual Studio 2013

CHOOSING AN IOS PROJECT

Page 8: How To: Mobile "Hello World" With Xamarin and Visual Studio 2013

IOS STARTUP

Page 9: How To: Mobile "Hello World" With Xamarin and Visual Studio 2013

IOS DEFAULT STORYBOARD

• Storyboards are view editing with transition information

• Single view project instantiated a view on startup

Page 10: How To: Mobile "Hello World" With Xamarin and Visual Studio 2013

XAMARIN IOS UI EDITOR

Page 11: How To: Mobile "Hello World" With Xamarin and Visual Studio 2013

IOS RESULT

Page 12: How To: Mobile "Hello World" With Xamarin and Visual Studio 2013

ADD A BUTTON AND CLICK HANDLER

Page 13: How To: Mobile "Hello World" With Xamarin and Visual Studio 2013

ANDROID

Page 14: How To: Mobile "Hello World" With Xamarin and Visual Studio 2013

ANDROID SDK INSTALL

Page 15: How To: Mobile "Hello World" With Xamarin and Visual Studio 2013

CHOOSING AN ANDROID PROJECT

Page 16: How To: Mobile "Hello World" With Xamarin and Visual Studio 2013

STARTING THE EMULATOR

Page 17: How To: Mobile "Hello World" With Xamarin and Visual Studio 2013

STARTING THE EMULATOR

Page 18: How To: Mobile "Hello World" With Xamarin and Visual Studio 2013

ANDROID CODE

Page 19: How To: Mobile "Hello World" With Xamarin and Visual Studio 2013

ANDROID WITH VIEW EDIT

Page 20: How To: Mobile "Hello World" With Xamarin and Visual Studio 2013

ANDROID DEFAULT VIEW

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <Button android:id="@+id/myButton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <Button android:id="@+id/myButton2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello2" /> </LinearLayout>

Page 21: How To: Mobile "Hello World" With Xamarin and Visual Studio 2013

WINDOWS PHONE

Page 22: How To: Mobile "Hello World" With Xamarin and Visual Studio 2013

WINDOWS PHONE 8.1

• If running in a VM like Parallels, you will need to turn on nested virtualization: http://kb.parallels.com/en/115211

Page 23: How To: Mobile "Hello World" With Xamarin and Visual Studio 2013

WP8 NEW PROJECT

Page 24: How To: Mobile "Hello World" With Xamarin and Visual Studio 2013

EMPTY VIEW

Page 25: How To: Mobile "Hello World" With Xamarin and Visual Studio 2013

ADD A BUTTON

Page 26: How To: Mobile "Hello World" With Xamarin and Visual Studio 2013

AND RUN…

Page 27: How To: Mobile "Hello World" With Xamarin and Visual Studio 2013

ADD INTERACTION

Page 29: How To: Mobile "Hello World" With Xamarin and Visual Studio 2013

BUT I JUST WANT TO DRAW A PICTURE

• For now…platform specific

• System.Drawing cross-platform coming from Xamarin

Page 30: How To: Mobile "Hello World" With Xamarin and Visual Studio 2013

F# DSL FOR UI this.mainModel <- new MainViewModel()

! let payButton = Button (text = "Click Me!")

let subtotalLabel = Label (text = "Subtotal:")

let subtotalTextField = TextField ()

let tipPercentLabel = Label (text = "Tip Percent:")

let tipPercentTextField = TextField ()

let tipPercentSlider = Slider(min = 0., max = 100.)

let totalLabel = Label (text = "Total:")

let totalValueTextField = TextField ()

! let tipView = View(content = [

subtotalLabel; subtotalTextField;

tipPercentSlider; tipPercentLabel; tipPercentTextField;

totalLabel; totalValueTextField;

payButton;

loadTemplateButton;

loadMarkdownButton;

webView;

])

! let _ = this.mainModel.TipPercent.Subscribe(fun f -> printfn "slider moved to %f" f)

let _ = this.mainModel.Subtotal.Subscribe(fun f -> printfn “sub-total is %f" f)

! let altUIBindings = [

Command(payButton, this.mainModel.PayCommand );

Command(loadTemplateButton, loadTemplateCommand );

Command(loadMarkdownButton, loadMarkdownCommand );

ValueToFromFloat(tipPercentSlider, this.mainModel.TipPercent);

ValueToFromString(tipPercentTextField, this.mainModel.TipPercent |> floatToStringProperty);

ValueToString(subtotalTextField, this.mainModel.Subtotal |> floatToStringProperty)

ValueFromString(totalValueTextField, this.mainModel.CalculatedTotal |> floatToStringProperty)

]

Page 31: How To: Mobile "Hello World" With Xamarin and Visual Studio 2013

GOOD OPEN SOURCE APPS TO LOOK AT

• My-StepCounter1: builds with the starter version of Xamarin and works on iOS and Android

• Tasky Portable2 : a cross platform task manager. Works on iOS, Android and Windows Phone.

1. https://github.com/MichaelJames6/My-StepCounter 2. http://docs.xamarin.com/content/TaskyPortable/

Page 32: How To: Mobile "Hello World" With Xamarin and Visual Studio 2013

TIPS• On iOS, use the simulator as much as you can. Turn

around is fastest with it.

• On Android, use the device. Turn around is fastest on it. Also the simulator has a nasty restriction on GREF’s (handles to native Java objects form C#, i.e. UI controls).

• On WP8…I don’t know since I don’t have a device.

Page 33: How To: Mobile "Hello World" With Xamarin and Visual Studio 2013

THANKS!