Presentation is loading. Please wait.

Presentation is loading. Please wait.

Crash Course in Android Development. 2 Content  Installing the ADT  Hardware and OS requirements  Java  ADT Bundle  Eclipse Project Setup  Drawing.

Similar presentations


Presentation on theme: "Crash Course in Android Development. 2 Content  Installing the ADT  Hardware and OS requirements  Java  ADT Bundle  Eclipse Project Setup  Drawing."— Presentation transcript:

1 Crash Course in Android Development

2 2 Content  Installing the ADT  Hardware and OS requirements  Java  ADT Bundle  Eclipse Project Setup  Drawing in Android  Animation in Android

3 3 John Casey  Dr John Casey  Email: jcasey@unitec.ac.nzjcasey@unitec.ac.nz  Room 3008, building 183  Phone: 815-4321 ext. 6003

4 4 My Experience  Oracle Certified Java Programmer (OCJP)  Programmer  P2P, Sockets, Distributed Systems, Information Retrieval  Motor Registry System – State of Tasmania  Fines and Infringement Notices Database – State of Tasmania  LifeLink - Births, Deaths and Marriages State of NSW  Mobile Research Projects  …  Educator  Deakin University, Melbourne  Unitec

5 5 Android Gremlins  SDK is very complicated  There are 4-5 separate components to install and configure and something can go wrong at each stage  The Android SDK has lots of bugs  Android can have weird interactions with the OS and Hardware  Many give up after failing to install and configure Java, Android and Eclipse

6 6 First Steps  Work out whether you are running a 32-bit or 64-bit OS  Control Panel- >System and Security->System

7 7 Do you have Java Installed?  http://www.oracle.com/technetwork/java/javase/ downloads/index.html http://www.oracle.com/technetwork/java/javase/ downloads/index.html

8 8 Download 32-bit OR 64-bit Version

9 9 Java already installed?  Drop to a Command Prompt

10 10 Download the ADT Bundle  https://developer.android.com/sdk/index.html https://developer.android.com/sdk/index.html  The number of bits must match! for OS, Java and ADT Bundle

11 11 Download the ADT Bundle  Make a cup of tea / coffee while the ADT Bundle downloads  385 MB later.... Extract the ADT Bundle.

12 12 Extract the ADT Bundle  Extract files to c:\android-adt

13 13 Open the SDK Manager

14 14 Update the SDK  Be careful not to download the Google Glass packages  Android 4.3.1 API 18 is a good stable version of Android

15 15  More Coffee...

16 16 Run Eclipse

17 17 Update Eclipse

18 18 Android Developer Toolkit  Lots of steps where things can go wrong  Can alternatively build your own environment OR you can also use Android Studio Beta  Follow the steps outlined above though and you can’t go too far wrong  Haven’t even started coding yet :D

19 19 Android Need to Know  Nice to know a general purpose programming language like Java / C#  Nice to know a bit about Object Oriented programming  Variables + Functions  Inheritance and Subclassing  Functions and parameters  A bit about XML  Have a lot of patience – Lots of bugs + Gotchas

20 20 Starting Eclipse  Keep the default workspace:  C:\Program Files\Eclipse Android\Workspace  API19 only available on lab machines

21 21 New Android Project  Use the wizard...  File ->New -> Other -> Android ->Android Project

22 22  Match up the version of Android with the version that you downloaded!  Minimum version should also point to Android 18

23 23

24 24

25 25

26 26

27 27

28 28 Android Projects  Main class file is the Activity public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); }

29 29 Android Structure  Source Code folder  Generated Code folder  Resource folder  Images  Layouts  Menus  Strings  AndroidManifest.xml

30 Android Manifest <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.test“ android:versionCode="1“ android:versionName="1.0" > <application android:allowBackup="true“ android:icon="@drawable/ic_launcher" android:label="@string/app_name“ android:theme="@style/AppTheme" > <activity android:name=".MainActivity" android:label="@string/app_name" >

31 31 Android Manifest  Defines configuration of the project using XML  Defines project resources  Images and Icons  Layouts  Menus  Hardware needed  Etc.  Defines the main activity for the Android Project 31

32 32 First Android Project – Stick Man  We will hard code everything to make it easier  Won’t be touching anything in the resources directory

33 33 Stick Man and House  Create a new View class

34 34 Stickman and House  Extend / inherit from android.view.View  Set the package  Class name  Superclass  Tick create constructors from super class.

35 35 Stickman and House package com.example.test; import android.content.Context; import android.util.AttributeSet; import android.view.View; public class StickmanHouse extends View { public StickmanHouse(Context context) { super(context); } public StickmanHouse(Context context, AttributeSet attrs) { super(context, attrs); } public StickmanHouse(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); }

36 36 Drawing in Android  Can draw various graphical primitives in Android using a View classes onDraw(Canvas canvas) method  By default onDraw(Canvas canvas) does not do anything...

37 37 Drawing in Android  The Canvas co-ordinate system starts at the top-left hand corner of the screen  Paint objects are used to control the size, style and colour of the shapes drawn by the Canvas object paint.setColor(Color.RED); canvas.drawCircle(left, top, 10, paint);

38 38 Stickman and House  By default the StickmanHouse view does not draw anything  The super classes onDraw(Canvas canvas) method does not do anything  You will need to import android.graphics.*;  Implement the onDraw method as follows @Override protected void onDraw(Canvas canvas) { Paint paint = new Paint(); paint.setColor(Color.RED); canvas.drawCircle(50, 50, 15, paint); }

39 39 Link StickmanView to MainActivity package com.example.test; import android.app.Activity; import android.os.Bundle; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new StickmanHouse(getApplicationContext())); }

40 40 Setting up the Emulator  Choose the Java perspective  Window -> Open Perspective -> Java

41 41 Setting up the Emulator  Press the Android Virtual Device button  It looks like a little mobile phone

42 42 Setting up the Emulator  Press the new button

43 43 Create new Virtual Device  Set the following parameters  Keep the device screen smaller – larger devices are very slow  Select an x86 CPU  Press OK

44 44 Start the new Virtual Device  Takes about 5 – 10 minutes to start depending on your hardware

45 45 Emulator

46 46 Running your App – Right Click Project

47 47 Running your App  Right Click Project  Select Run As  Android Application  The application will run on your emulator (eventually)...

48 48 Activity  Build a stickman figure in teams of 2 people, using canvas methods such as:  canvas.drawRect(25, 125, 150, 250, paint);  canvas.drawLine(200,125,200,200,paint);  canvas.drawCircle(200, 115, 15, paint);  canvas.drawArc(new RectF(200-10,115- 8,200+10,115+8 ), 0, 180, true, paint);

49 49 What have we done?  A lot on project setup  Create project  Create emulator  A bit on object oriented programming  A bit on object creation / allocation  A lot on drawing objects using the canvas and paint objects  Basics of Java language

50 50 Bouncing Ball Animation  Declare global integer variables  Use global vars to specify co-ordinates of the circle  Use invalidate() method to force a screen redraw

51 Animation Code int x = 0; int y = 0; @Override protected void onDraw(Canvas canvas) { Paint paint = new Paint(); paint.setColor(Color.RED); canvas.drawCircle(x,y, 15, paint); x = x +1; y = y +1; invalidate(); }  We need some guard conditions otherwise the circle will cont. to move to the right forever.

52 Boundary Guards int x = 150; int y = 0; int deltax = 1; int deltay = 1; @Override protected void onDraw(Canvas canvas) { Paint paint = new Paint(); paint.setColor(Color.RED); canvas.drawCircle(x,y, 15, paint); if(x > getWidth()) { deltax = -1; } x = x +deltax; y = y +deltay; invalidate(); }  New delta variables to control movement  New guard conditions to reflect ball movement on right hand side  Your job implement guard conditions for the top, bottom and left sides

53 53 Summary  Basic animation  Global variables  Math operators  Assignments operators  If statements  Challenge get more circles on screen using arrays  Get them to collide with each other  If you want to learn more take the Mobile class over Summer / Sem 1, 2015.


Download ppt "Crash Course in Android Development. 2 Content  Installing the ADT  Hardware and OS requirements  Java  ADT Bundle  Eclipse Project Setup  Drawing."

Similar presentations


Ads by Google