Agenda. Overview of Xamarin and Xamarin.Android Xamarin.Android fundamentals Creating a detail screen

Similar documents
Creating a Custom ListView

Diving into Android. By Jeroen Tietema. Jeroen Tietema,

INTRODUCTION COS MOBILE DEVELOPMENT WHAT IS ANDROID CORE OS. 6-Android Basics.key - February 21, Linux-based.

Practical 1.ListView example

EECS 4443 Mobile User Interfaces. More About Layouts. Scott MacKenzie. York University. Overview (Review)

Xamarin for C# Developers

Upon completion of the second part of the lab the students will have:

EECS 4443 Mobile User Interfaces. More About Layouts. Scott MacKenzie. York University

Developing Android Applications Introduction to Software Engineering Fall Updated 1st November 2015

Android HelloWorld - Example. Tushar B. Kute,

Adapter.

Produced by. Mobile Application Development. David Drohan Department of Computing & Mathematics Waterford Institute of Technology

Our First Android Application

ListView (link) An ordered collection of selectable choices. key attributes in XML:

Steps to Set Up the Environment of Xamarin in Visual

Android. Mobile operating system developed by Google A complete stack. Based on the Linux kernel Open source under the Apache 2 license

Mobile Programming Lecture 1. Getting Started

Android Application Development

Android UI Development

Introduction to Android development

Real-Time Embedded Systems

Android Basics. Android UI Architecture. Android UI 1

Introduction to Android

INTRODUCTION TO ANDROID

Embedded Systems Programming - PA8001

Topics of Discussion

ANDROID USER INTERFACE

User Interface Design & Development

Getting Started. Dr. Miguel A. Labrador Department of Computer Science & Engineering

COMP4521 EMBEDDED SYSTEMS SOFTWARE

Produced by. Mobile Application Development. David Drohan Department of Computing & Mathematics Waterford Institute of Technology

Introduction to Mobile Development

10.1 Introduction. Higher Level Processing. Word Recogniton Model. Text Output. Voice Signals. Spoken Words. Syntax, Semantics, Pragmatics

Android Programming Lecture 2 9/7/2011

Android development. Outline. Android Studio. Setting up Android Studio. 1. Set up Android Studio. Tiberiu Vilcu. 2.

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Saving State

Solving an Android Threading Problem

Overview. Lecture: Implicit Calling via Share Implicit Receiving via Share Launch Telephone Launch Settings Homework

Introduction to Xamarin Cross Platform Mobile App Development

Android Exam AND-401 Android Application Development Version: 7.0 [ Total Questions: 129 ]

Android App Development. Mr. Michaud ICE Programs Georgia Institute of Technology

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Managing Screen Orientation

Developing Android Applications

CS 4330/5390: Mobile Application Development Exam 1

EMBEDDED SYSTEMS PROGRAMMING UI Specification: Approaches

ListView Containers. Resources. Creating a ListView

When programming in groups of people, it s essential to version the code. One of the most popular versioning tools is git. Some benefits of git are:

AdFalcon Android Native Ad SDK Developer's Guide. AdFalcon Mobile Ad Network Product of Noqoush Mobile Media Group

Mobile Programming Lecture 5. Composite Views, Activities, Intents and Filters

Activities and Fragments

Android Specifics. Jonathan Diehl (Informatik 10) Hendrik Thüs (Informatik 9)

MVC Apps Basic Widget Lifecycle Logging Debugging Dialogs

Tablets have larger displays than phones do They can support multiple UI panes / user behaviors at the same time

Introduction to Android

MS_40541 Build Native Cross-Platform Mobile Apps with a Shared C# Business Logic for ios, Android, and UWP in C#.NET with Xamarin and Visual Studio

Programming with Android: Introduction. Layouts. Dipartimento di Informatica: Scienza e Ingegneria Università di Bologna

Comp 595MC/L: Mobile Computing CSUN Computer Science Department Fall 2013 Midterm

ANDROID SDK. Developers Guide

XML Tutorial. NOTE: This course is for basic concepts of XML in line with our existing Android Studio project.

Understand applications and their components. activity service broadcast receiver content provider intent AndroidManifest.xml

ANDROID SYLLABUS. Advanced Android

The World of List View. Romain Guy and Adam Powell May 19, 2010

Android Beginners Workshop

CS 370 Android Basics D R. M I C H A E L J. R E A L E F A L L

Austin Mobile.NET Develops Group

Android App Development

Learn about Android Content Providers and SQLite

Software Practice 3 Before we start Today s lecture Today s Task Team organization

UI Fragment.

Vienos veiklos būsena. Theory

CMSC436: Fall 2013 Week 3 Lab

BCA 6. Question Bank

Intents. Your first app assignment

Mobila applikationer och trådlösa nät, HI1033, HT2012

SD Module-1 Android Dvelopment

Fragments. Lecture 11

In this Class Mark shows you how to put applications into packages and how to run them through the command line.

EMBEDDED SYSTEMS PROGRAMMING Application Basics

Mobile Technologies JULY 24, 2018

Build Cross Platform Video Chat Apps With Xamarin

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar

Introduction to Android Development

ActionBar. import android.support.v7.app.actionbaractivity; public class MyAppBarActivity extends ActionBarActivity { }

Building User Interface for Android Mobile Applications II

Mobile Computing Practice # 2c Android Applications - Interface

BSCS 514- Computer Graphics. Course Supervisor : Dr. Humera Tariq Hands on Lab Sessions: Mr. Faraz Naqvi

Produced by. Mobile Application Development. David Drohan Department of Computing & Mathematics Waterford Institute of Technology

CPET 565 Mobile Computing Systems CPET/ITC 499 Mobile Computing. Lab & Demo 2 (Part 1-2) Hello-Goodbye App Tutorial

Java & Android. Java Fundamentals. Madis Pink 2016 Tartu

Android Development Crash Course

Lecture 14. Android Application Development

List-Based Widgets: Lists, Grids, and Scroll Views

AdFalcon Android Native Ad SDK Developer's Guide. AdFalcon Mobile Ad Network Product of Noqoush Mobile Media Group

Lifecycle Callbacks and Intents

Applications. Marco Ronchetti Università degli Studi di Trento

Programming with Android: Android for Tablets. Dipartimento di Scienze dell Informazione Università di Bologna

Mobile Computing Fragments

CS 235AM, Mobile Application Development: Android Spring 2016

A Crash Course to Android Mobile Platform

Getting Started With Android Feature Flags

Transcription:

Gill Cleeren

Agenda Overview of Xamarin and Xamarin.Android Xamarin.Android fundamentals Creating a detail screen Lists and navigation Navigating from master to detail Optimizing the application Preparing for store deployment

Targets of this talk Understanding the fundamentals of Android app development with Xamarin See how a fully working app can be built

The demo scenario Android Coffee Store Manager List of coffees Navigation to details page

DEMO Looking at the finished application

Overview of Xamarin and Xamarin.Android

Hello Xamarin Xamarin enables developers to reach all major mobile platforms! Native User Interface Native Performance Shared Code Across Platforms C# &.NET Framework Toolset on top of Visual Studio Enables VS to create native ios and Android apps Commercial product

Write Everything in C# ios, Android, Windows, Windows Phone, Mac Billions of Devices covered!

The Xamarin platform Xamarin Xamarin.Android Xamarin.iOS Xamarin Forms

Xamarin.Android exposes many extra device types

Xamarin.Android Anything you can do in Java/Android can be done in C# and Visual Studio (or Xamarin Studio) with Xamarin!

How Xamarin works on Android Mono VM + Java VM execute side-by-side (supports both Dalvik and ART) Mono VM JITs IL into native code and executes most of your code Can utilize native libraries directly as well as.net BCL

A word on code-sharing Xamarin brings development time through the use of code-sharing Possible (currently!) using Shared projects: allows organizing the shared code #if directives for platform specific code PCL include the platforms we want to support Abstract to interfaces where platforms have specific implementations Standard library Now becoming a possibility Wider range than PCL

Target architecture for a Xamarin app

Preparing for Android development

What you need for Xamarin.Android development Xamarin license (Xamarin.Android) Free with VS Community Edition PC or Mac Visual Studio or Visual Studio for Mac Android SDK and Emulators (installed via Xamarin setup) Emulator Device (not really required but...)

Installing Xamarin.Android

A word on emulators Setup will install some basic emulators for you They re great for drinking a lot of coffee

Alternatives for the default emulators Possible options Genymotion -Requires VirtualBox under the hood HAXM drivers Android Player from Xamarin Microsoft Android emulator Hyper-V

DEMO A quick look at the development setup

Xamarin.Android fundamentals

File New Project

File New Project

Fundamental #1: Activities Apps are collections of activities A view == an activity (for now ) Apps don t have an entry point No single code line which is called by the OS Apps start when Android creates one of the classes of the app App then gets loaded into memory

Fundamental #1: Activities When opening an application, the OS creates the first Activity Activity is a specific class Defines UI and behaviour for a single task Corresponds to a single app screen App gets loaded in memory User launches app Activity Android loads app In memory OS

Fundamental #1: Activities One activity needs to be the entry point for the app: MainLauncher=True

Activity lifecycle

Activity lifecycle We can of course override these methods OnCreate: Create views, initialize variables, and do other prep work before the user sees the Activity This method is called only once when the Activity is loaded into memory OnResume Perform any tasks that need to happen every time the Activity returns to the device screen OnPause Perform any tasks that need to happen every time the Activity leaves the device screen

Activity lifecycle in effect

Fundamental #2: Views The layout of the app is contained in *.axml files AXML: Android designer file / Android XML First view of the app is named Main.axml Can be any name really AXML files live in the Resources/layout folder

The designer for Xamarin.Android views

The designer for Xamarin.Android views

View code

Connecting and accessing controls from code Linking a view with an activity is done using SetContentView

Connecting and accessing controls from code We can name controls using the ID property The Android designer maps the control to the Resource class and assigns it a resource ID The code representation of a control is linked to the visual representation of the control in the designer via the Id property

Connecting and accessing controls from code Once we have created the controls, we can access them from code Field name is used for lookup

Fundamental #3: Application manifest An Android app contains a manifest file Contains a list of all resources, properties that make up the application Also contains name, list of permissions that the application has received Images *.axml Icons Others Android Manifest file

DEMO Creating our first Android application together!

Navigation and lists

Fundamental #4: ListViews and adapters Used very commonly in Android Common way to present lists of rows Each row is represented using a standard style or customized Consists out of ListView: visual part Adapter: feeds data to ListView

Fundamental #4: ListViews and adapters

Important classes ListView ListActivity BaseAdapter ArrayAdapter & ArrayAdapter<T>

ListActivity and the built-in ArrayAdapter<T> [Activity(Label = "Coffees", MainLauncher = true, Icon = "@drawable/icon")] public class CoffeeScreenActivity: ListActivity { string[] coffees; } protected override void OnCreate(Bundle bundle) { base.oncreate(bundle); coffees= new string[] { "Coffee 1","Coffee 2", "Coffee 3"}; ListAdapter = new ArrayAdapter<String>( this, Android.Resource.Layout.SimpleListItem1, coffees); }

Implementing your own adapter In most cases, the ArrayAdapter won t be enough We ll need to create our own adapter Inherits from BaseAdapter Things we need to implement Count: To tell the control how many rows are in the data GetView: To return a View for each row, populated with data. This method has a parameter for the ListView to pass in an existing, unused row for re-use GetItemId: Return a row identifier (typically the row number, although it can be any long value that you like) this[int] indexer: To return the data associated with a particular row number

Handling row clicks To handle row clicks, we need to implement OnListItemClick protected override void OnListItemClick(ListView l, View v, int position, long id) { var t = items[position]; //do something }

DEMO Adding a ListView and an adapter

Customizing the ListView with other row views

Customizing the ListView with other row views

Customizing the ListView with other row views

DEMO Using the built-in row views

Creating your own row views Custom row layouts are AXML files in Resources/layout Are loaded by Id using a custom adapter View can contain any number of display classes with custom colors, fonts

Creating your own row view <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="8dp" android:orientation="horizontal"> <ImageView android:id="@+id/coffeeimageview" android:layout_width="50dp" android:layout_height="50dp" android:padding="5dp" /> <LinearLayout android:id="@+id/textfields" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingleft="10dip"> <TextView android:id="@+id/coffeenametext" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/pricetext" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> </LinearLayout>

Using your custom row view public override View GetView(int position, View convertview, ViewGroup parent) { //custom view var item = items[position]; if (convertview == null) { convertview = context.layoutinflater.inflate (Resource.Layout.CoffeeRowView, null); } convertview.findviewbyid<imageview> (Resource.Id.CoffeeImageView).SetImageResource( imagerepository.imagenametoresourceint(item.imageid.tostring())); convertview.findviewbyid<textview> (Resource.Id.CoffeeNameText).Text = item.coffeename; convertview.findviewbyid<textview> (Resource.Id.PriceText).Text = item.price.tostring(); } return convertview;

DEMO Adding our own custom row view

Fundamental #5: Intents An Intent is an abstract concept for some sort of operation that should be performed in Android Navigating to another activity Often, launching an external application (= built-in) with the intent of doing something Make a phone call Launch a URI Map an address An intent often consist out of What the intent is The data needed for the intent Phone number to call

Intent of making a phone call ActionCall asks Android for an Activity to make a phone call

Intent of navigating to another screen StartActivity can be used to start another activity PutExtra() is used to pass data from one activity to the other var intent = new Intent (); intent.setclass (this, typeof(coffeedetailactivity)); intent.putextra ("selectedcoffeeid", t.coffeeid); StartActivity (intent);

Receiving information from the intent protected override void OnCreate (Bundle bundle) { base.oncreate (bundle); SetContentView (Resource.Layout.Main); var selectedcoffeeid = Intent.Extras.GetInt ("selectedcoffeeid", 0); } Coffee coffee = DataService.GetCoffeeById (selectedcoffeeid);

DEMO Navigating from the List to the Detail page

Optimizing the application

Managing strings in strings.xml We can have Android store string values for us <?xml version="1.0" encoding="utf-8"?> <resources> <string name="hello">hello World, Click Me!</string> <string name="app_name">androidcoffeestore</string> <string name="coffeenamelabel">coffee name</string> </resources> <TextView android:text="@string/coffeenamelabel" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/coffeenamelabel" />

Making the app multi-language

Application drawables We can add drawables: application icons Adding all resolutions makes sure the icons look good on all screens Filenames are the same Folder name identifies the resolution

Application drawables We can select an image in the project properties This now becomes the icon for the application within Android

DEMO Adding resources and drawables to the application

Deploying to the store

Publishing your work Marketplace is most common option Often, more than one is used (Google Play, Amazon, GetJar ) Email or website is often for a more closed distribution Also require less work to prepare the application for distribution Google Play is best known store Allows users to discover, download, rate, and pay for applications by clicking a single icon either on their device or on their computer Google Play also provides tools to assist in the analysis of sales and market trends and to control which devices and users may download an application

Summary Xamarin.Android leverages your C# knowledge to build apps for Android Concepts of Android mean a learning curve

Thanks!

Q&A