Presentation is loading. Please wait.

Presentation is loading. Please wait.

Android Fundamentals. What is Android Software stack for mobile devices Software stack for mobile devices SDK provides tools and APIs to develop apps.

Similar presentations


Presentation on theme: "Android Fundamentals. What is Android Software stack for mobile devices Software stack for mobile devices SDK provides tools and APIs to develop apps."— Presentation transcript:

1 Android Fundamentals

2 What is Android Software stack for mobile devices Software stack for mobile devices SDK provides tools and APIs to develop apps SDK provides tools and APIs to develop apps

3 Major Components Image source: http://developer.android.com/guide/basics/what-is-android.html

4 Applications Ships with core set of apps, written in Java Ships with core set of apps, written in Java Developers have access to core APIs Developers have access to core APIs Views used to build application Views used to build application Content providers – access data from other apps Content providers – access data from other apps Resource manager – access to local strings, graphics Resource manager – access to local strings, graphics Notification manager – display custom alerts Notification manager – display custom alerts Activity manager – manages app lifecycle Activity manager – manages app lifecycle

5 Libraries C/C++ C/C++ Media libraries – A/V, images Media libraries – A/V, images Surface manager – 2D/3D graphic layers Surface manager – 2D/3D graphic layers LibWebCore – web browser engine LibWebCore – web browser engine SGL – 2D graphics engine SGL – 2D graphics engine 3D – hardware or software acceleration 3D – hardware or software acceleration FreeType – BMP and vector fonts FreeType – BMP and vector fonts SQLite – database engine SQLite – database engine

6 Runtime and Kernel Includes core set of libraries Includes core set of libraries Provides most of core Java libraries Provides most of core Java libraries Each app runs in its own process Each app runs in its own process Own instance of the Dalvik Virtual Machine Own instance of the Dalvik Virtual Machine Linux 2.6 is used for core system services Linux 2.6 is used for core system services Abstraction layer between HW & SW stacks Abstraction layer between HW & SW stacks

7 Main Components of Android Activities Activities Services Services Content Providers Content Providers Broadcast Receivers Broadcast Receivers

8 Activity Single page user interface Single page user interface Most apps have multiple activities Most apps have multiple activities Callable from other apps (if you allow it) Callable from other apps (if you allow it)

9 Service No user interface No user interface Runs in background Runs in background Started and stopped by activities Started and stopped by activities

10 Content Provider Manages shared set of application data Manages shared set of application data Data may be shared between apps or be private Data may be shared between apps or be private Performs data handling functions Performs data handling functions

11 Broadcast Receiver Listens for system wide (intent) broadcasts Listens for system wide (intent) broadcasts Intent filter limits which intents cared about Intent filter limits which intents cared about Similar to an interrupt handler Similar to an interrupt handler Redirects to appropriate activity or service Redirects to appropriate activity or service

12 Intents Allows an activity, service or broadcast receiver to link to another Allows an activity, service or broadcast receiver to link to another Within or between apps Within or between apps Allows apps to use components of others Allows apps to use components of others Image source: Mednieks, Dornin, Meike, Nakamura. Programming Android

13 User Interfaces Images from Android Design http://developer.android.com/design/get-started/ui-overview.html

14 User Interface Basics Recall the basic unit of an Android application is an Activity Recall the basic unit of an Android application is an Activity An Activity displays the user interface An Activity displays the user interface User Interfaces are built from View and ViewGroup object instances of the View class User Interfaces are built from View and ViewGroup object instances of the View class View objects are data structures that store content and layout parameters View objects are data structures that store content and layout parameters controls a specific rectangular region of the screen controls a specific rectangular region of the screen responsible for drawing itself responsible for drawing itself handles events handles events Subclass “widgets” provide user interface objects: Subclass “widgets” provide user interface objects: text fields, buttons, labels text fields, buttons, labels serves as means of interaction with user serves as means of interaction with user Images from Android Design http://developer.android.com/design/building-blocks/index.html

15 View & ViewGroup ViewGroup objects act like containers for View objects ViewGroup objects act like containers for View objects one or more Views are grouped together one or more Views are grouped together Subclass “layouts” provide different layout architectures: Subclass “layouts” provide different layout architectures: LinearLayout – displays Views in linear direction either horizontally or vertically LinearLayout – displays Views in linear direction either horizontally or vertically default is horizontal default is horizontal text field, two radio buttons, and button text field, two radio buttons, and button in a vertical orientation RelativeLayout – displays Views in relative position to each other RelativeLayout – displays Views in relative position to each other an id needs to be assigned to elements for an id needs to be assigned to elements forreference text field, two radio buttons, and button text field, two radio buttons, and button in relative position Images from Android Basics & User Interfaces http://www3.ntu.edu.sg/home/ehchua/programming/android/Android_BasicsUI.html

16 ViewGroup Layout TableLayout – displays Views in table form with rows and columns TableLayout – displays Views in table form with rows and columns buttons for the calculator are in table form buttons for the calculator are in table form Some other layouts from base class android.view.ViewGroup: Some other layouts from base class android.view.ViewGroup: AbsoluteLayout AbsoluteLayout FrameLayout FrameLayout ScrollView ScrollView Image from Android Basics & User Interfaces http://www3.ntu.edu.sg/home/ehchua/programming/android/Android_BasicsUI.html

17 Common Attributes View and ViewGroup attributes: View and ViewGroup attributes: layout_width layout_width layout_height layout_height layout_margintop layout_margintop layout_marginbottom layout_marginbottom layout_marginleft layout_marginleft layout_marginright layout_marginright layout_x layout_x layout_y layout_y LinearLayout and TableLayout attributes: LinearLayout and TableLayout attributes: layout_gravity – specifies how child Views are positioned layout_gravity – specifies how child Views are positioned layout_weight – specifies how much space is to be allocated, total must equal 1 layout_weight – specifies how much space is to be allocated, total must equal 1 Images from Understanding User Interface In Android http://mobiforge.com/designing/story/understanding-user-interface-android-part-1-layouts

18 View Hierarchy Parent nodes contain and organize layout of child nodes Parent nodes contain and organize layout of child nodes Child nodes are responsible for drawing themselves at the request of the parent Child nodes are responsible for drawing themselves at the request of the parent control and respond to user input contained within their region of the display control and respond to user input contained within their region of the display The Activity that displays a particular screen calls the setContentView() method to draw the screen defined by the hierarchy The Activity that displays a particular screen calls the setContentView() method to draw the screen defined by the hierarchy XML layout files typically used for defining layouts and expressing view hierarchies XML layout files typically used for defining layouts and expressing view hierarchies each element in XML is a View or ViewGroup object each element in XML is a View or ViewGroup object Image from Android Developers http://developer.android.com/guide/topics/ui/index.html

19 Input Events Define to inform the system of user interaction Define to inform the system of user interaction Event listener is defined and registered with the View object Event listener is defined and registered with the View object View class has a collection of On Listener: View class has a collection of On Listener: View.OnClickListener View.OnClickListener View.OnTouchListener View.OnTouchListener View.OnKeyListener View.OnKeyListener Example: OnTouch, when the user touches a defined View object on the screen Example: OnTouch, when the user touches a defined View object on the screen define View.OnTouchListener define View.OnTouchListener register the View object with setOnTouchListener() register the View object with setOnTouchListener()

20 Application Menus Two types of menus Two types of menus Options menu – typically when an application is running Options menu – typically when an application is running accessed by pressing the MENU button on the device accessed by pressing the MENU button on the device Context menu – typically used for displaying specific information about an item Context menu – typically used for displaying specific information about an item accessed by pressing and hold down on an object accessed by pressing and hold down on an object Images from Android User Interfaces http://eagle.phys.utk.edu/guidry/android/androidUserInterface.html

21 Application Menus Options menus allow users quick access to an application’s functions, preferences and settings Options menus allow users quick access to an application’s functions, preferences and settings Structured using a View hierarchy Structured using a View hierarchy define onCreateOptionsMenu() define onCreateOptionsMenu() define onCreateContectMenu() define onCreateContectMenu() Handle their own events, no need to register event listeners Handle their own events, no need to register event listeners Selections handled by methods Selections handled by methods onOptionsItemSelected() onOptionsItemSelected() onContextItemSelected() onContextItemSelected() Items for menus can be declared in an XML file like an application layout Items for menus can be declared in an XML file like an application layout

22 Hardware Systems/Sensors Images from Z-DeviceTest app https://market.android.com/details?id=zausan.zdevicetest&hl=en

23 Sensors public class SensorActivity extends Activity, implements SensorEventListener { … SensorManager mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE); Sensor mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); … mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL); public void onSensorChanged(SensorEvent event) { }…} Image from AndroSensor app https://market.android.com/details?id=com.fivasim.androsensor&hl=en

24 Sensor Constants public static final float GRAVITY_EARTH = 9.80665 public static final float GRAVITY_EARTH = 9.80665 public static final float LIGHT_FULLMOON = 0.25 public static final float LIGHT_FULLMOON = 0.25 public static final float MAGNETIC_FIELD_EARTH_MIN = 30.0 public static final float MAGNETIC_FIELD_EARTH_MIN = 30.0 public static final float PRESSURE_STANDARD_ATMOSPHERE = 1013.25 public static final float PRESSURE_STANDARD_ATMOSPHERE = 1013.25 public static final float GRAVITY_THE_ISLAND = 4.815162 public static final float GRAVITY_THE_ISLAND = 4.815162 public static final float GRAVITY_DEATH_STAR_I = 3.5303614E-7 public static final float GRAVITY_DEATH_STAR_I = 3.5303614E-7

25 Bluetooth BluetoothAdapter Local radio state Local radio state Discover devices Discover devicesBluetoothServerSocket Receives connection requests Receives connection requests Returns a BluetoothSocket when connected Returns a BluetoothSocket when connectedBluetoothSocket InputStream object InputStream object OutputStream object OutputStream object

26 Location LocationManager locman = (LocationManager) getSystemService(Context.LOCATION_SERVICE ) Location loc = locman.getLastKnownLocation(String provider) NETWORK_PROVIDER GPS_PROVIDER

27 Location Listener private class MyLocListener implements LocationListener onLocationChanged(Location location) onLocationChanged(Location location) ) requestLocationUpdates(long minTime, float minDistance, Criteria criteria, PendingIntent intent) public void addProximityAlert (double latitude, double longitude, float radius, long expiration, PendingIntent intent)

28 References https://market.android.com/details?id=zausan.zdevicetest&hl=en https://market.android.com/details?id=zausan.zdevicetest&hl=en https://market.android.com/details?id=zausan.zdevicetest&hl=en https://market.android.com/details?id=com.fivasim.androsensor&hl= en https://market.android.com/details?id=com.fivasim.androsensor&hl= en https://market.android.com/details?id=com.fivasim.androsensor&hl= en https://market.android.com/details?id=com.fivasim.androsensor&hl= en http://developer.android.com/reference http://developer.android.com/reference http://developer.android.com/reference Mednicks, Dornin, Meike, Nakamura, Programming Android Mednicks, Dornin, Meike, Nakamura, Programming Android http://developer.android.com http://developer.android.com http://developer.android.com http://www3.ntu.edu.sg/home/ehchua/programming/android/Android_B asicsUI.html http://www3.ntu.edu.sg/home/ehchua/programming/android/Android_B asicsUI.html http://www3.ntu.edu.sg/home/ehchua/programming/android/Android_B asicsUI.html http://www3.ntu.edu.sg/home/ehchua/programming/android/Android_B asicsUI.html http://phandroid.com/2011/05/11/10-tips-for-android-ui-design/ http://phandroid.com/2011/05/11/10-tips-for-android-ui-design/ http://phandroid.com/2011/05/11/10-tips-for-android-ui-design/ http://eagle.phys.utk.edu/guidry/android/androidUserInterface.html http://eagle.phys.utk.edu/guidry/android/androidUserInterface.html Ableson, Sen, King, Ortiz: Android In Action – Third Edition Ableson, Sen, King, Ortiz: Android In Action – Third Edition


Download ppt "Android Fundamentals. What is Android Software stack for mobile devices Software stack for mobile devices SDK provides tools and APIs to develop apps."

Similar presentations


Ads by Google