The presentation covers basic intro to Android, how to get started with development, including instructions on setup, common UI usages like menus, dialogs; details on services like Sensors, Location and Google Maps
It also covers ideas on how to test including details on shell and installation instructions without using Eclipse
6. Version history http://en.wikipedia.org/wiki/Android_version_history Version Name Release Date Beta 5 November 2007 1.0 23 September 2008 Android Market, Google account integration, maps … 1.1 9 February 2009 resolved issues, API changes … 1.5 Cupcake 30 April 2009 Widgets, upload to YouTube and Picasa … 1.6 Donut 15 September 2009 WVGA / CDMA support, Google navigation, Search enhancement … 2.0/2.1 Éclair 26 October 2009 / 12 January 2010 Live wallpaper, multiple screen resolutions, Camera flash … 2.2 Froyo 20 May 2010 Chrome’s V8 JavaScript engine, upload file in browser … 2.3 Gingerbread 6 December 2010 Voice and Video support in Gtalk … 3.0 / 3.1 Honeycomb 22 February 2011 / 10 May 2011 Released for tablets Ice Cream Sandwich Q4 2011 combination of Gingerbread and Honeycomb into a "cohesive whole"
22. Specifying details for AVD SD Card must be at least 9MB or left blank Skin allows to choose resolution / form factor for the device you want to emulate Name the device and select the target (the version of Platform that you want to emulate. Note that the list will be pulled out from the list of platforms you have installed on your machine (you can see in <sdk>platforms folder)
29. Create new app Specify the project name as it should appear in your workspace Specify the target platform – depending on the device you are expecting this to run on Application Name – as will appear on the device Create Activity – the first activity that will be launched when app starts
30. What is generated? Named as the Create Activity specified when creating the app, this extends android.app.Activity and serves as the “screen” that is shown to the user Auto generated file. DON’T MANIPULATE. Contains reference to all resources. Used in activities to access the resources Contains resources – layouts, images, values to be used in app – referenced via R Contains the icon which will be used on device for your app. Any more images that you use in the app must be added here. Add versions based on resolution to each of the folders Layouts specify the screens look and feel – think of it as HTML. Typically, you will have one layout for each activity. Main.xml is generated by default to correspond to the initial activity created by default Gives details like package, activity to be launched when app starts, permissions and intents – app configuration file of sorts Contains values specified as type, name and value. Can be of types other than string (say colors) Gives flexibility of configuring based on environment – one set for each environment Contains all the source code
31.
32.
33.
34.
35.
36.
37.
38.
39. UI Concepts: Context Menu @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu. context_menu, menu); } @Override public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); switch (item.getItemId()) { case R.id. ctx_menu_item_option_1: showToast("context menu option 1 selected", getApplicationContext()); return true; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState setContentView(R.layout.alert); txtAlertName = (EditText)findViewById(R.id.txtAlertName); registerForContextMenu(txtAlertName);
41. UI Concepts: Alerts / Dialogs int duration = Toast. LENGTH_SHORT; Toast toast = Toast. makeText(appContext, message, duration); toast.show(); TimePickerDialog.OnTimeSetListener mTimeSetListener = new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { //TODO : When user selects time }}; TimePickerDialog timePicker = new TimePickerDialog(this, mTimeSetListener, mHour, mMinute, true); timePicker.show(); DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { //TODO : when user selects Date }}; DatePickerDialog datePicker = new DatePickerDialog(this, mDateSetListener, cyear, cmonth, cday); datePicker.show(); Toast DatePickerDialog TimePickerDialog
42. UI Concepts: Alerts / Dialogs ProgressDialog dialog = new ProgressDialog( DemoAlerts.this); dialog.setMessage("This is the content you want to show - like please wait while we fetch your account details..."); dialog.setProgressStyle(ProgressDialog. STYLE_SPINNER); // dialog.setProgressStyle(ProgressDialog. STYLE_HORIZONTAL);// this gives progress bar dialog.show(); AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setTitle("This is the title for the window"); alertDialog.setMessage("The dialog message goes here. This can be any text and as per the length, it will wrap this."); alertDialog.setButton("Btn1", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) {//TODO on button click } }); alertDialog.setButton2("Btn2", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) {//TODO on button click } }); alertDialog.setButton3("Btn3", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) {//TODO on button click } }); alertDialog.setIcon(R.drawable. icon); alertDialog.show(); ProgressDialog AlertDialog
43.
44.
45.
46.
47. Sensors Example - orientation values[0]: Azimuth, angle between the magnetic north direction and the y-axis, around the z-axis (0 to 359). 0=North, 90=East, 180=South, 270=West values[1]: Pitch, rotation around x-axis (-180 to 180), with positive values when the z-axis moves toward the y-axis. values[2]: Roll, rotation around y-axis (-90 to 90), with positive values when the x-axis moves toward the z-axis.
48.
49. Sensor testing : snapshots from phone Azimuth around 0 – phone is pointing in the North direction Azimuth around 90 – phone is pointing in the East direction Azimuth around 180 – phone is pointing in the South direction Azimuth around 270 – phone is pointing in the West direction Pitch around 0 – phone is “lying flat” Pitch around -90 – phone is “standing” Pitch around 90 – phone is “standing on its head” Roll around 0 – phone is “lying flat” Roll around -90 – phone is “standing on its side”
50.
51.
52.
53.
54.
55.
56.
57.
58.
59. Maps : respond to location update To add zoom controls: mapView = (MapView)findViewById(R.id. mapview); mapView.setBuiltInZoomControls(true); To show the location on map In the onCreate method : MapController mc = mapView.getController(); In listener : public void onLocationChanged(Location loc) { … … GeoPoint p = new GeoPoint( (int) (loc.getLatitude() * 1E6), (int) (loc.getLongitude() * 1E6)); mc.animateTo(p); mc.setZoom(13); To set view of map mapView.setSatellite(true); mapView.setStreetView(true); http://mobiforge.com/developing/story/using-google-maps-android
60.
61. Maps : add marker Add Markers //get the overlays and clear it List<Overlay> mapOverlays = mapView.getOverlays(); mapOverlays.clear(); //first we need to define the drawable using one of the icons Drawable drawable = this.getResources().getDrawable(R.drawable. icon_map_marker); //initialize the itemized overlay using the current marker CustomItemizedOverlay mapOverlay = new CustomItemizedOverlay(drawable); GeoPoint point = new GeoPoint((int) (( loc.getLatitude()) * 1E6), (int) ((loc.getLongitude()) * 1E6)); OverlayItem overlayitem = new OverlayItem(point, "title", "snippet"); mapOverlay.addOverlay(overlayitem); mapOverlays.add(mapOverlay); mapView.invalidate(); class CustomItemizedOverlay extends ItemizedOverlay
62. Maps : keep adding markers public void AddLocationToMap(Location loc) { //get the overlays and clear it List<Overlay> mapOverlays = mapView.getOverlays(); mapOverlays.clear(); GeoPoint point = new GeoPoint((int) (( loc.getLatitude()) * 1E6), (int) ((loc.getLongitude()) * 1E6)); String addressForPoint = ""; addressForPoint = GetAddressFromPoint(point, getApplicationContext()); lblAddress.setText(addressForPoint); //create an overlay items OverlayItem overlayitem = new OverlayItem(point, "Address : " + addressForPoint, "snippet"); //add it to the our customized overlay item list itemizedOverlay.addOverlay(overlayitem); //add the current list to mapOverlays mapOverlays.add(itemizedOverlay); //invalidate will force to redraw the map mapView.invalidate(); }