Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Android Fundamentals What is Android Software stack for mobile devices SDK provides tools and APIs to develop apps Major Components Image source: http://developer.android.com/guide/basics/what-is-android.html Applications Ships with core set of apps, written in Java Developers have access to core APIs Views used to build application Content providers – access data from other apps Resource manager – access to local strings, graphics Notification manager – display custom alerts Activity manager – manages app lifecycle Libraries C/C++ Media libraries – A/V, images Surface manager – 2D/3D graphic layers LibWebCore – web browser engine SGL – 2D graphics engine 3D – hardware or software acceleration FreeType – BMP and vector fonts SQLite – database engine Runtime and Kernel Includes core set of libraries Provides most of core Java libraries Each app runs in its own process Own instance of the Dalvik Virtual Machine Linux 2.6 is used for core system services Abstraction layer between HW & SW stacks Main Components of Android Activities Services Content Providers Broadcast Receivers Activity Single page user interface Most apps have multiple activities Callable from other apps (if you allow it) Service No user interface Runs in background Started and stopped by activities Content Provider Manages shared set of application data Data may be shared between apps or be private Performs data handling functions Broadcast Receiver Listens for system wide (intent) broadcasts Intent filter limits which intents cared about Similar to an interrupt handler Redirects to appropriate activity or service Intents Allows an activity, service or broadcast receiver to link to another Within or between apps Allows apps to use components of others Image source: Mednieks, Dornin, Meike, Nakamura. Programming Android User Interfaces Images from Android Design http://developer.android.com/design/get-started/ui-overview.html User Interface Basics Recall the basic unit of an Android application is an Activity An Activity displays the user interface 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 controls a specific rectangular region of the screen responsible for drawing itself handles events Subclass “widgets” provide user interface objects: text fields, buttons, labels serves as means of interaction with user Images from Android Design http://developer.android.com/design/building-blocks/index.html View & ViewGroup ViewGroup objects act like containers for View objects one or more Views are grouped together Subclass “layouts” provide different layout architectures: LinearLayout – displays Views in linear direction either horizontally or vertically default is horizontal text field, two radio buttons, and button in a vertical orientation RelativeLayout – displays Views in relative position to each other an id needs to be assigned to elements for reference 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 ViewGroup Layout TableLayout – displays Views in table form with rows and columns buttons for the calculator are in table form Some other layouts from base class android.view.ViewGroup: AbsoluteLayout FrameLayout ScrollView Image from Android Basics & User Interfaces http://www3.ntu.edu.sg/home/ehchua/programming/android/Android_BasicsUI.html Common Attributes View and ViewGroup attributes: layout_width layout_height layout_margintop layout_marginbottom layout_marginleft layout_marginright layout_x layout_y LinearLayout and TableLayout attributes: layout_gravity – specifies how child Views are positioned 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 View Hierarchy Parent nodes contain and organize layout of child nodes 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 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 each element in XML is a View or ViewGroup object Image from Android Developers http://developer.android.com/guide/topics/ui/index.html Input Events Define to inform the system of user interaction Event listener is defined and registered with the View object View class has a collection of On<SomeEvent>Listener: View.OnClickListener View.OnTouchListener View.OnKeyListener Example: OnTouch, when the user touches a defined View object on the screen define View.OnTouchListener register the View object with setOnTouchListener() Application Menus Two types of menus Options menu – typically when an application is running accessed by pressing the MENU button on the device Context menu – typically used for displaying specific information about an item accessed by pressing and hold down on an object Images from Android User Interfaces http://eagle.phys.utk.edu/guidry/android/androidUserInterface.html Application Menus Options menus allow users quick access to an application’s functions, preferences and settings Structured using a View hierarchy Handle their own events, no need to register event listeners Selections handled by methods define onCreateOptionsMenu() define onCreateContectMenu() onOptionsItemSelected() onContextItemSelected() Items for menus can be declared in an XML file like an application layout Hardware Systems/Sensors Images from Z-DeviceTest app https://market.android.com/details?id=zausan.zdevicetest&hl=en 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 Sensor Constants public static final float GRAVITY_EARTH = 9.80665 public static final float LIGHT_FULLMOON = 0.25 public static final float MAGNETIC_FIELD_EARTH_MIN = 30.0 public static final float PRESSURE_STANDARD_ATMOSPHERE = 1013.25 public static final float GRAVITY_THE_ISLAND = 4.815162 public static final float GRAVITY_DEATH_STAR_I = 3.5303614E-7 Bluetooth BluetoothAdapter Local radio state Discover devices BluetoothServerSocket Receives connection requests Returns a BluetoothSocket when connected BluetoothSocket InputStream object OutputStream object Location LocationManager locman = (LocationManager) getSystemService(Context.LOCATION_SERVICE) Location loc = locman.getLastKnownLocation(String provider) GPS_PROVIDER NETWORK_PROVIDER Location Listener private class MyLocListener implements LocationListener 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) References https://market.android.com/details?id=zausan.zdevicetest&hl=en https://market.android.com/details?id=com.fivasim.androsensor&hl= en http://developer.android.com/reference Mednicks, Dornin, Meike, Nakamura, Programming Android http://developer.android.com 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://eagle.phys.utk.edu/guidry/android/androidUserInterface.html Ableson, Sen, King, Ortiz: Android In Action – Third Edition