“Cleveland Public Golf”

Presented to:

Dr. Victor Matos

Department of Computer and Information Science

Cleveland, Ohio

Presented by:

Jason Goode (CSU 2238742)

November 11, 2009

  1. Purpose

The purpose of this exercise was to create a useful golf application. This was to done by gathering available information and presenting it with a functional user interface.

  1. Introduction

The applicationinitially launches a ListView within a ListActivity. The onCreate method calls a custom adapter, IconAdapter, to bind the data to the ListView. The IconAdapter stores each icon within an ArrayList, displays them in the ListView and provides services for the data.

The user can interact with the application through the option menu, context menu and dialog boxes. The option menu provides a “Quit” option for the user. The context menu can be used initiate a phone call to each course when the ListView is pressed and held. It launches an ACTION_CALL intent for the selected phone number in that phone array.

A dialog box is created when an onListItemClick event is fired. This will present the user with three options: Tee Time, Web Page and Map. Each of these options launches an ACTION_VIEW intent. The “Tee Time” button opens the browser with the contents of the url array. Here the user has access to the courses reservation service. The “Web Page” button opens the browser to the course website with the contents of the page array. The “Map” button uses the Google API to present a map based upon coordinates in the lat and lon arrays.

  1. XML

<?xmlversion="1.0"encoding="utf-8"?>

AbsoluteLayout

android:id="@+id/widget0"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

xmlns:android="

LinearLayout

android:id="@+id/widget28"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:background="#ffffffff"

android:orientation="vertical"

android:layout_x="0px"

android:layout_y="0px"

ListView

android:id="@id/android:list"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:textColor="#ffffff"

android:visibility="visible"

android:background="#000000"

</ListView</LinearLayout</AbsoluteLayout

  1. Main Activity

importandroid.app.AlertDialog;

importandroid.app.ListActivity;

importandroid.app.AlertDialog.Builder;

importandroid.content.DialogInterface;

importandroid.content.Intent;

importandroid.net.Uri;

importandroid.os.Bundle;

importandroid.view.ContextMenu;

importandroid.view.Menu;

importandroid.view.MenuItem;

importandroid.view.View;

importandroid.webkit.WebView;

importandroid.widget.ListView;

importandroid.widget.Toast;

publicclassHW4newextendsListActivity{

ListViewList;

IconAdaptermAdapter;

WebViewbrowser;

intPos;

Stringurl[]={"

"

"

Stringname[]={"Big Met Golf Course","Little Met Golf Course","Manakiki Golf Course",

"Mastick Woods Golf Course","Shawnee Hills Golf Course","Sleepy Hollow Golf Course",

Washington Golf Learning Center"};

Stringaddress[]={"Rocky River Reservation 4811 Valley Parkway Fariview Park",

"Rocky River Reservation 18599 Old Lorain Road Cleveland",

"North Chagrin Reservation 35501 Eddy Road Willoughby Hills",

"Rocky River Reservation 19900 Puritas Road Cleveland",

"Bedford Reservation 18753 Egbert Road Bedford",

"Brecksville Reservation 9445 Brecksville Road Brecksville",

"Washington Reservation 3841 Washington Park Blvd. Village of Newburgh Heights"};

Stringphone[]={"tel:(440) 331-1070","tel:(216) 941-9672","tel:(440) 942-2500","tel:(216) 267-5626",

"tel:(440) 232-7184","tel:(440) 526-4285","tel:(216) 641-1864"};

Stringpage[]={"

"

"

"

"

"

"

inticon[]={R.drawable.icon_big_met,R.drawable.icon_little_met,R.drawable.icon_manikiki,

R.drawable.icon_mastick_woods,R.drawable.icon_shawnee_hills,R.drawable.icon_sleepy_hollow,

R.drawable.icon_washington};

Doublelat[]={41.44773,41.45140,41.59409,41.43869,41.37926,41.30494,41.45427};

Doublelon[]={-81.83681,-81.82728,-81.43075,-81.84148,-81.53696,-81.62714,-81.66209};

publicstaticfinalintCall_bmet=Menu.FIRST;

publicstaticfinalintCall_lmet=Menu.FIRST+1;

publicstaticfinalintCall_manikiki=Menu.FIRST+2;

publicstaticfinalintCall_mastick=Menu.FIRST+3;

publicstaticfinalintCall_shawnee=Menu.FIRST+4;

publicstaticfinalintCall_sleepy=Menu.FIRST+5;

publicstaticfinalintCall_washington=Menu.FIRST+6;

publicstaticfinalintQuit=Menu.FIRST+7;

@Override

publicvoidonCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);

// Use a custom layout file

setContentView(R.layout.main);

// Set up our adapteYesr

mAdapter=newIconAdapter(this);

//initialize course information

for(intk=0;k<7;k++){

mAdapter.addPhotos(k);

}

//bind icons to the listview

setListAdapter(mAdapter);

//notify context menu

registerForContextMenu(getListView());

}

//@Override

protectedvoidonListItemClick(ListViewparent,Viewv,intposition,longid){

super.onListItemClick(parent,v,position,id);

//set position of the selected item

Pos=position;

//create item dialog box

AlertDialogdiaBox=createDialogBox();

diaBox.show();

}

//@Override

publicbooleanonCreateOptionsMenu(Menumenu){

super.onCreateOptionsMenu(menu);

populateOptionMenu(menu);

returntrue;

}

//@Override

publicvoidonCreateContextMenu(ContextMenumenu,Viewv,

ContextMenu.ContextMenuInfomenuInfo){

populateContextMenu(menu);

}

@Override

publicbooleanonOptionsItemSelected(MenuItemitem){

super.onOptionsItemSelected(item);

applyOptionMenu(item);

returnfalse;

}

@Override

publicbooleanonContextItemSelected(MenuItemitem){

super.onContextItemSelected(item);

applyContextMenu(item);

returnfalse;

}

privatevoidpopulateOptionMenu(Menumenu){

menu.add(Menu.NONE,Quit,Menu.NONE,"Quit");

}

privatevoidpopulateContextMenu(Menumenu){

menu.add(Menu.NONE,Call_bmet,Menu.NONE,"Call Big Met");

menu.add(Menu.NONE,Call_lmet,Menu.NONE,"Call Little Met");

menu.add(Menu.NONE,Call_manikiki,Menu.NONE,"Call Manikiki");

menu.add(Menu.NONE,Call_mastick,Menu.NONE,"Call Mastick Woods");

menu.add(Menu.NONE,Call_shawnee,Menu.NONE,"Call Shawnee Hills");

menu.add(Menu.NONE,Call_sleepy,Menu.NONE,"Call Sleepy Hollow");

menu.add(Menu.NONE,Call_washington,Menu.NONE,"Call Washington Center");

}

privateAlertDialogcreateDialogBox(){

//AlertDialog myQuittingDialogBox =

BuilderBox=newAlertDialog.Builder(this);

//set title, and icon

Box.setTitle(name[Pos]);

Box.setIcon(icon[Pos]);

//set three option buttons

Box.setPositiveButton("Tee Time",newDialogInterface.OnClickListener(){

publicvoidonClick(DialogInterfacedialog,intwhichButton){

Intentactivity;

activity=newIntent(Intent.ACTION_VIEW,Uri.parse(url[Pos]));

startActivity(activity);

}

});//setPositiveButton

Box.setNeutralButton("Web Page",newDialogInterface.OnClickListener(){

publicvoidonClick(DialogInterfacedialog,intwhichButton){

Intentactivity;

activity=newIntent(Intent.ACTION_VIEW,Uri.parse(page[Pos]));

startActivity(activity);

}

});//setNeutralButton

Box.setNegativeButton("Map",newDialogInterface.OnClickListener(){

publicvoidonClick(DialogInterfacedialog,intwhichButton){

Intentactivity;

Uriuri=Uri.parse("geo:"+lat[Pos].toString()+","+lon[Pos].toString());

activity=newIntent(Intent.ACTION_VIEW,uri);

startActivity(activity);

}

});//setNegativeButton

returnBox.show();

}

privatevoidapplyOptionMenu(MenuItemitem){

finish();

}

privatevoidapplyContextMenu(MenuItemitem){

Intentactivity;

switch(item.getItemId()){

case(Call_bmet):

try{

activity=newIntent(Intent.ACTION_CALL,Uri.parse(phone[0]));

startActivity(activity);

}

catch(Exceptione){

Toast.makeText(getBaseContext(),e.getMessage(),

Toast.LENGTH_LONG).show();

}

break;

case(Call_lmet):

try{

activity=newIntent(Intent.ACTION_CALL,Uri.parse(phone[1]));

startActivity(activity);

}

catch(Exceptione){

Toast.makeText(getBaseContext(),e.getMessage(),

Toast.LENGTH_LONG).show();

}

break;

case(Call_manikiki):

try{

activity=newIntent(Intent.ACTION_CALL,Uri.parse(phone[2]));

startActivity(activity);

}

catch(Exceptione){

Toast.makeText(getBaseContext(),e.getMessage(),

Toast.LENGTH_LONG).show();

}

break;

case(Call_mastick):

try{

activity=newIntent(Intent.ACTION_CALL,Uri.parse(phone[3]));

startActivity(activity);

}

catch(Exceptione){

Toast.makeText(getBaseContext(),e.getMessage(),

Toast.LENGTH_LONG).show();

}

break;

case(Call_shawnee):

try{

activity=newIntent(Intent.ACTION_CALL,Uri.parse(phone[4]));

startActivity(activity);

}

catch(Exceptione){

Toast.makeText(getBaseContext(),e.getMessage(),

Toast.LENGTH_LONG).show();

}

break;

case(Call_sleepy):

try{

activity=newIntent(Intent.ACTION_CALL,Uri.parse(phone[5]));

startActivity(activity);

}

catch(Exceptione){

Toast.makeText(getBaseContext(),e.getMessage(),

Toast.LENGTH_LONG).show();

}

break;

case(Call_washington):

try{

activity=newIntent(Intent.ACTION_CALL,Uri.parse(phone[6]));

startActivity(activity);

}

catch(Exceptione){

Toast.makeText(getBaseContext(),e.getMessage(),

Toast.LENGTH_LONG).show();

}

break;

}

}

}

  1. List Adapter

import java.util.ArrayList;

import android.content.Context;

import android.view.View;

import android.view.ViewGroup;

import android.view.ViewGroup.LayoutParams;

import android.widget.AbsListView;

import android.widget.BaseAdapter;

import android.widget.ImageView;

public class IconAdapter extends BaseAdapter {

//course icons

private Integer[] mPhotoPool = {

R.drawable.big_met,R.drawable.little_met,R.drawable.manakiki,

R.drawable.mastick_woods,R.drawable.shawnee_hills,R.drawable.sleepy_hollow,

R.drawable.washington};

//initiate a list to hold the icons

private ArrayList<Integer> mPhotos = new ArrayList<Integer>();

public IconAdapter(Context c) {

mContext = c;

}

public int getCount() {

return mPhotos.size();

}

public Object getItem(int position) {

return position;

}

public long getItemId(int position) {

return position;

}

public View getView(int position, View convertView, ViewGroup parent) {

// Make an ImageView to show a photo

ImageView iv = new ImageView(mContext);

iv.setImageResource(mPhotos.get(position));

iv.setAdjustViewBounds(true);

iv.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.WRAP_CONTENT,

LayoutParams.WRAP_CONTENT));

return iv;

}

private Context mContext;

public void addPhotos(int whichPhoto) {

int newPhoto = mPhotoPool[whichPhoto];

mPhotos.add(newPhoto);

notifyDataSetChanged();

}

}

  1. Screen Shots

  1. References

Murphy, Mark L., Beginning Android. Apress. Berkley, CA. 2009.

HW #4Page 1