1、Java CodesJava Android CodesActivity AndroidManifest.xml Home.java package com.wpirl; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import com.wpirl.activity.Dire
2、ctoryActivity; import com.wpirl.activity.MapActivity; import com.wpirl.activity.RouteActivity; import com.wpirl.map.Map; import com.wpirl.positioning.Positioning; public class Home extends Activity implements OnClickListener private Button btnMapActivity; private Button btnRouteActivity; private But
3、ton btnDirectoryActivity; /* Called when the activity is first created. */ Override public void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); setContentView(R.layout.home); btnMapActivity = (Button) findViewById(R.id.btnMapActivity); btnMapActivity.setOnClickListener(this);
4、 btnRouteActivity = (Button) findViewById(R.id.btnRouteActivity); btnRouteActivity.setOnClickListener(this); btnDirectoryActivity = (Button) findViewById(R.id.btnDirectoryActivity); btnDirectoryActivity.setOnClickListener(this); initialize(); public void onClick(View v) if (v = btnMapActivity) start
5、Activity(new Intent(Home.this, MapActivity.class); else if (v = btnRouteActivity) startActivity(new Intent(Home.this, RouteActivity.class); else if (v = btnDirectoryActivity) startActivity(new Intent(Home.this, DirectoryActivity.class); /* * Initialize all the static classes */ private void initiali
6、ze() Map.initialize(); Positioning.initialize(); Home.xml Directory.java package com.wpirl.activity; import java.util.Arrays; import android.app.ExpandableListActivity; import android.content.Intent; import android.os.Bundle; import android.view.ContextMenu; import android.view.Gravity; import andro
7、id.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.view.ContextMenu.ContextMenuInfo; import android.widget.AbsListView; import android.widget.BaseExpandableListAdapter; import android.widget.ExpandableListAdapter; import android.widget
8、.ExpandableListView; import android.widget.TextView; import android.widget.Toast; import android.widget.ExpandableListView.ExpandableListContextMenuInfo; import com.wpirl.map.GraphNode; import com.wpirl.map.Map; public class DirectoryActivity extends ExpandableListActivity private static final int M
9、ENU_VIEW_DETAIL = Menu.FIRST + 1; private static final int MENU_FROM_HERE = Menu.FIRST + 2; private static final int MENU_TO_HERE = Menu.FIRST + 3; / Sample data set. childreni contains the children (String) for groupsi. private final String groups = Room, Name ; private String children = new String
10、2; ExpandableListAdapter adapter; Override public void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); / Set up our adapter adapter = new DirectoryExpandableListAdapter(); children0 = Map.getRooms(); Arrays.sort(children0); children1 = Map.getPeople(); Arrays.sort(children1);
11、 setListAdapter(adapter); registerForContextMenu(getExpandableListView(); Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) menu.setHeaderTitle(Menu); menu.add(0, MENU_VIEW_DETAIL, 0, View Detail); menu.add(0, MENU_FROM_HERE, 0, From Here); menu.add(0, MENU
12、_TO_HERE, 0, To Here); Override public boolean onContextItemSelected(MenuItem item) ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) item.getMenuInfo(); String title = (TextView) info.targetView).getText().toString(); int type = ExpandableListView.getPackedPositionType(info.packe
13、dPosition); int id = item.getItemId(); /* * If the menu clicked is the child */ if (type = ExpandableListView.PACKED_POSITION_TYPE_CHILD) GraphNode node = Map.searchDetail(title); switch (id) case MENU_VIEW_DETAIL: StringBuilder sb = new StringBuilder();sb.append(Detail informationn); sb.append(Room
14、 ID: + node.room + n); sb.append(Name: + node.person + n); Toast.makeText(this, sb.toString(), Toast.LENGTH_LONG).show(); break; case MENU_FROM_HERE: Map.setRoutingSource(node); startActivity(new Intent(this, RouteActivity.class); break; case MENU_TO_HERE: Map.setRoutingDestination(node); startActiv
15、ity(new Intent(this, RouteActivity.class); break; return true; /* * If the menu clicked is the group */ else if (type = ExpandableListView.PACKED_POSITION_TYPE_GROUP) int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition); if (groupPos = 0) Toast.makeText( this, This group con
16、tains the list of rooms in this building, Toast.LENGTH_SHORT).show(); else Toast.makeText( this, This group contains the list of names in this building, Toast.LENGTH_SHORT).show(); return true; return false; /* * */ public class DirectoryExpandableListAdapter extends BaseExpandableListAdapter public
17、 Object getChild(int groupPosition, int childPosition) return childrengroupPositionchildPosition; public long getChildId(int groupPosition, int childPosition) return childPosition; public int getChildrenCount(int groupPosition) return childrengroupPosition.length; public TextView getGenericView() /
18、Layout parameters for the ExpandableListView AbsListView.LayoutParams lp = new AbsListView.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, 64); TextView textView = new TextView(DirectoryActivity.this); textView.setLayoutParams(lp); / Center the text verticallytextView.setGravity(Gravity.CENTER_VER
19、TICAL | Gravity.LEFT);/ Set the text starting position textView.setPadding(36, 0, 0, 0);return textView; public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) TextView textView = getGenericView();textView.setText(getChild(groupPositio
20、n, childPosition).toString();return textView; public Object getGroup(int groupPosition) return groupsgroupPosition;public int getGroupCount() return groups.length;public long getGroupId(int groupPosition) return groupPosition; public View getGroupView(int groupPosition, boolean isExpanded, View conv
21、ertView, ViewGroup parent) TextView textView = getGenericView();textView.setText(getGroup(groupPosition).toString(); return textView;public boolean isChildSelectable(int groupPosition, int childPosition) return true; public boolean hasStableIds() return true; RouteActivity.java package com.wpirl.act
22、ivity; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; import android.widget.Button; import android.widget.Toast;
23、import com.wpirl.R; import com.wpirl.map.GraphNode; import com.wpirl.map.Map; public class RouteActivity extends Activity implements OnClickListener private GraphNode source; private GraphNode destination; private AutoCompleteTextView textViewSource; private AutoCompleteTextView textViewDestination;
24、 private Button btnSearch; Override protected void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); setContentView(R.layout.route); String database = Map.getDatabase(Map.DATABASE_PERSON + Map.DATABASE_ROOM); ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_dropdown_item_1line, database); btnSearch = (Button) findViewById(R.id.btnSearchRoute); btnSearch.setOnClickListener(this); textViewSource = (AutoCompleteTextView) findViewById(R.id.editSource); textViewSource.setAdapter(adapter); textViewDestination = (AutoCompleteTextView) findViewById(R.id.edi
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1