42
28 th May 2015, NED University ANDROID DEVELOPMENT WORKSHOP Daniel Muhammad Idrees

2 Day Android Workshop

Embed Size (px)

Citation preview

Page 1: 2 Day Android Workshop

28th May 2015, NED University

ANDROID DEVELOPMENT WORKSHOP

Daniel Muhammad Idrees

Page 2: 2 Day Android Workshop

• Software Engineer - Interactive Health Solutions (www.ihsinformatics.com) (Dec 2013 – Present)

• Lead Android Trainer – SkillOrbit(www.skillorbit.com) (May 2015 – Present)

• Private Tutor and Trainer (Dec 2014 – Present)

• Internee - Open Integrated Solutions (May 2012 – Sept

2012)

• Computer & Information Systems Engineer (NED University, Batch 2009-10)

• O Levels Teacher (2009 – May 2015)Email: [email protected] LinkedIn: www.linkedin.com/in/danielmidreesFacebook: www.facebook.com/daniel.mi

Page 3: 2 Day Android Workshop

What to Expect?

• Guidance• Counseling• Mentorship

Page 4: 2 Day Android Workshop

What not to Expect?

Spoon Feeding!

Page 5: 2 Day Android Workshop
Page 6: 2 Day Android Workshop

Variables• Data Types

o Primitive Typeso Non-primitive Types

• Local Variableso Choosing Data Typeo Declaring (String string;)o Initializing (string = “Hello”)

• Access Modifiers• Class (static) Variables• Instance (non-static) Variables

Page 7: 2 Day Android Workshop

Primitive Data Types

Page 8: 2 Day Android Workshop

Non-Primitive Data Types• User-created• Nullable• Also called “Reference Types”• Examples:

o Arrayso Stringo Lists

Page 9: 2 Day Android Workshop

Access Modifiers• Access Modifiers

o Publico Privateo Protectedo Default

Page 10: 2 Day Android Workshop

Operators

• Airthematic (+, -, *, /, ++, --, %)• Relational (==, >=, <=, !=, >, <)• Logical (&& , | |, !)

Page 11: 2 Day Android Workshop

Controlling Flow of Execution

• Conditionso if – elseo switch

• Loopso foro while

• Special Control Statementso break, continueo Returno try-catch-finally

Page 12: 2 Day Android Workshop

Function• Signatures• Naming• Parameters• Returning Values• Static/Non-static Functions• Calling Functions

Page 13: 2 Day Android Workshop

Arrays• Arrays

o Collection of Similar Items in Sequenceo Contains values or referenceso Fixed, Finite Length

• Length• Index• Initialization• Enhanced for loop

Page 14: 2 Day Android Workshop

Best Coding Practices

• Indentation

• Naming Convention• Use of Comments

Page 15: 2 Day Android Workshop

Be an Engineer!Not a Mechanic!

Page 16: 2 Day Android Workshop

Object Oriented Programming• Objects and Classes

o Object: Instance of a Classo Class: Blueprint of an Object

Page 17: 2 Day Android Workshop

Pillars of OOP• Inheritance

• Polymorphismo Method Overloadingo Method Overriding

Page 18: 2 Day Android Workshop

Pillars of OOP• Abstraction

o Biggest Challenge in OOPo Relevant Attributes and Behavioro Abstract and Concrete Classes

• Encapsulationo Hiding Datao Hiding Implementationo Access/Mutate (simply, get/set)

Page 19: 2 Day Android Workshop

Interfaces• Why Not Multiple Inheritance?• Interfaces are Pure Abstract Classes• Rules

o No Instanceso No Constructorso Only Method Signatureso Only static final Members

Page 20: 2 Day Android Workshop

Read more JAVA from:

• Java Actually by Khalid A. Mughal• The Complete Reference Java by Herbert Schildt• http://www.tutorialspoint.com/java/• http://www.javatpoint.com/java-tutorial

Take Help From:• Stackoverflow• Google!

Page 21: 2 Day Android Workshop
Page 22: 2 Day Android Workshop

Introduction to Android

Development

Page 23: 2 Day Android Workshop

Manifest File<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.package.default" android:versionCode="1" android:versionName="1.0" >

<uses-sdk android:minSdkVersion="11" android:targetSdkVersion="21" />

<application> <activity android:name="com.resume.daniyalmuhammadidrees.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application></manifest>

Page 24: 2 Day Android Workshop
Page 25: 2 Day Android Workshop

Strings.xml

<rescource

<string name="app_name">The name of your App!</string>

</resource>

@String/app_name “The name of your App!”

Page 26: 2 Day Android Workshop

Layout.xml• Types of Layouts

o LinearLayouto RelativeLayouto TableLayouto GridLayouto FrameLayouto Fragment

• Views (Buttons, TextView, EditText etc)• ViewGroup (Invisible container, contains Views)

Page 27: 2 Day Android Workshop

Width and Height of Views

android:layout_width="match_parent"android:layout_height="match_parent“

android:layout_width=“fill_parent"android:layout_height=“fill_parent“

android:layout_width=“wrap_content"android:layout_height=“wrap_content“

• wrap_content ( Take only as much as you need)• match_parent (Take everything you can )• fill_parent (Take as much as your parent have)

Page 28: 2 Day Android Workshop

Accessing views through code

Page 29: 2 Day Android Workshop

Activity Lifecycle• Activity• Lifecycle Methods

Page 30: 2 Day Android Workshop

Orientation• Landscape and Portrait• Changing Orientation of Device• Emulator shortcut key ‘Left Ctrl + F11’• Setting fix Orientation of an Activity

Page 31: 2 Day Android Workshop

More on UI• Padding

• Margin

• Gravity

• Weightsum

Weightsum = 3

Layout_weight (View)= 1

Page 32: 2 Day Android Workshop

Linear Layout• Arrange views in a line vertically or horizontally. • Views can have Layout Weight and Layout

Gravity.

Page 33: 2 Day Android Workshop

Relative Layout• Place views with respect to other view or Parent• Views inside RL does not have Layout Weight and

Layout Gravity.

Page 34: 2 Day Android Workshop

Table Layout• Arrange views in rows and columns.• TableRow is MATCH_PARENT in width and

WRAP_CONTENT in height• <TableRows> (Views) </TableRows>• Columns in a row will be equal to number of

views in that row.

Page 35: 2 Day Android Workshop

Grid Layout• Arrange views in rows and columns.• Available in API Level 14 and higher.• Set Row Count and Column Count.

Page 36: 2 Day Android Workshop

Frame Layout• Views are stacked on top of each other.

Page 37: 2 Day Android Workshop

ScrollView• ScrollView• HorizontalScrollView

Page 38: 2 Day Android Workshop

• Events• Listener• Example of Button Click

Concept of Listener

Page 39: 2 Day Android Workshop

Custom Button• Design an Image of a Button.

• Design an Image of a pressed Button.

• Create an xml file in drawable folder.

• Call that xml in your layout View.

http://angrytools.com/android/button/http://www.dibbus.com/2011/02/gradient-buttons-for-android/

Click

Click

Page 40: 2 Day Android Workshop

Building Blocks of Android

• ActivitiesSomething which user interacts with.

• ServicesSomething that runs in the background.

• Broadcast ReceiversRespond to broadcast messages by

applications or the system itself.• Intents

Messenger carrying message.

Page 41: 2 Day Android Workshop

• Used to start a new Activity• Used to start a Service• Used to get notifications from Broadcast

Receivers • <Intent-filter>• Explicit Intents (there is a target)• Implicit Intents (there is no SPECIFIC target)

Intents

Page 42: 2 Day Android Workshop

Thank You!