Skip to content
Browse files

add an activity to display a list of POIs

  • Loading branch information...
1 parent 71e5d03 commit ac2908e3d3d89aaf59b4d2ac1cb310aca6048e7a techxplorer committed
View
1 AndroidManifest.xml
@@ -77,6 +77,7 @@
<activity android:name=".SettingsActivity"></activity>
<activity android:name="NewPoiActivity"></activity>
<activity android:name="PoiInfoActivity"></activity>
+ <activity android:name="PoiListActivity"></activity>
</application>
</manifest>
View
BIN res/drawable-hdpi/ic_menu_myplaces.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN res/drawable-mdpi/ic_menu_myplaces.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
25 res/layout/poi_list.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical" >
+
+ <TextView
+ android:id="@+id/poi_list_ui_lbl_heading"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_horizontal"
+ android:layout_marginBottom="@dimen/ui_elem_margin_bottom"
+ android:layout_marginLeft="@dimen/ui_elem_margin_left"
+ android:layout_marginRight="@dimen/ui_elem_margin_right"
+ android:text="@string/poi_list_ui_lbl_heading"
+ android:textAppearance="?android:attr/textAppearanceMedium" />
+
+ <ListView
+ android:id="@android:id/android:list"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content" />
+
+
+
+</LinearLayout>
View
16 res/layout/poi_list_entry.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical" >
+
+ <TextView
+ android:id="@+id/poi_list_ui_enty_title"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginBottom="@dimen/ui_elem_margin_bottom"
+ android:layout_marginLeft="@dimen/ui_elem_margin_left"
+ android:layout_marginRight="@dimen/ui_elem_margin_right"
+ android:textAppearance="?android:attr/textAppearanceMedium" />
+
+</LinearLayout>
View
6 res/menu/map_activity.xml
@@ -12,6 +12,12 @@
android:visible="true"
android:icon="@drawable/ic_menu_add">
</item>
+ <item android:id="@+id/menu_map_activity_poi_list"
+ android:enabled="true"
+ android:title="@string/menu_map_activity_poi_list"
+ android:visible="true"
+ android:icon="@drawable/ic_menu_myplaces">
+ </item>
<item android:id="@+id/menu_map_activity_centre_map"
android:enabled="true"
android:title="@string/menu_map_activity_centre_map"
View
8 res/values/strings.xml
@@ -69,11 +69,17 @@
<string name="poi_info_ui_lbl_age">Information Age:</string>
<string name="poi_info_toast_no_record_error">Unable to load required data at this time</string>
+ <!-- POI List Activity -->
+ <string name="poi_list_ui_lbl_heading">List of POIs</string>
+ <string name="poi_list_ui_toast_missing_data">Unable to lookup POI information at this time</string>
+ <string name="poi_list_ui_tiast_missing_poi_id">Unable to lookup POI id at this time</string>
+
<!-- Menu UI -->
<string name="menu_map_activity_preferences">Settings</string>
<string name="menu_map_activity_add_poi">Add POI</string>
- <string name="menu_map_activity_centre_map">Center Map</string>
+ <string name="menu_map_activity_centre_map">Centre Map</string>
<string name="menu_map_activity_close">Close</string>
+ <string name="menu_map_activity_poi_list">List POIs</string>
<!-- System wide strings -->
View
6 src/org/servalproject/maps/MapActivity.java
@@ -330,6 +330,12 @@ public boolean onOptionsItemSelected(MenuItem item) {
Toast.makeText(getApplicationContext(), R.string.map_ui_toast_location_unavailable, Toast.LENGTH_LONG).show();
}
return true;
+ case R.id.menu_map_activity_poi_list:
+ // show the list of poi
+ Log.v(TAG, "show the list of pois");
+ mIntent = new Intent(this, org.servalproject.maps.PoiListActivity.class);
+ startActivity(mIntent);
+ return true;
case R.id.menu_map_activity_close:
// close this activity
finish();
View
217 src/org/servalproject/maps/PoiListActivity.java
@@ -0,0 +1,217 @@
+/*
+ * Copyright (C) 2012 The Serval Project
+ *
+ * This file is part of the Serval Maps Software
+ *
+ * Serval Maps Software is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This source code is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this source code; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package org.servalproject.maps;
+
+import org.servalproject.maps.provider.MapItemsContract;
+
+import android.app.Activity;
+import android.app.ListActivity;
+import android.content.ContentResolver;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.database.Cursor;
+import android.os.Bundle;
+import android.preference.PreferenceManager;
+import android.util.Log;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemClickListener;
+import android.widget.ListView;
+import android.widget.SimpleCursorAdapter;
+import android.widget.Toast;
+
+/**
+ * an activity to display a list of points of interest
+ */
+public class PoiListActivity extends ListActivity implements OnItemClickListener {
+
+ /*
+ * private class level constants
+ */
+ private final boolean V_LOG = true;
+ private final String TAG = "PoiListActivity";
+
+ /*
+ * private class level variables
+ */
+ private long defaultPoiMaxAge = 43200 * 1000;
+ private volatile long poiMaxAge = defaultPoiMaxAge;
+
+ private Cursor cursor;
+
+ /*
+ * create the activity
+ *
+ * (non-Javadoc)
+ * @see android.preference.PreferenceActivity#onCreate(android.os.Bundle)
+ */
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.poi_list);
+
+ // get the data
+ cursor = getCursor();
+
+ if(cursor == null) {
+ Log.e(TAG, "a null cursor was returned when looking up POI info");
+ Toast.makeText(getApplicationContext(), R.string.poi_list_ui_toast_missing_data, Toast.LENGTH_LONG).show();
+ finish();
+ }
+
+ // define the map between columns and layout elements
+ String[] mColumnNames = new String[1];
+ mColumnNames[0] = MapItemsContract.PointsOfInterest.Table.TITLE;
+
+ int[] mLayoutElements = new int[1];
+ mLayoutElements[0] = R.id.poi_list_ui_enty_title;
+
+ // create the data adapter
+ SimpleCursorAdapter mDataAdapter = new SimpleCursorAdapter(
+ this,
+ R.layout.poi_list_entry,
+ cursor,
+ mColumnNames,
+ mLayoutElements);
+
+ setListAdapter(mDataAdapter);
+
+ // get a reference to the list view
+ ListView mListView = getListView();
+ mListView.setTextFilterEnabled(true); // allow filtering by the user by adding in content
+ mListView.setOnItemClickListener(this);
+ }
+
+ /*
+ * get the required data and populate the cursor
+ */
+ private Cursor getCursor() {
+
+ // get the desired maximum age of the poi information
+ SharedPreferences mPreferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
+
+ String mPreference = mPreferences.getString("preferences_map_max_poi_age", null);
+ if(mPreference != null) {
+ poiMaxAge = Long.parseLong(mPreference) * 1000;
+ }
+
+ // get the data
+ String[] mProjection = new String[2];
+ mProjection[0] = MapItemsContract.PointsOfInterest.Table._ID;
+ mProjection[1] = MapItemsContract.PointsOfInterest.Table.TITLE;
+
+ // determine if we need to restrict the list of POIs
+ String mSelection = null;
+ String[] mSelectionArgs = null;
+
+ // restrict the poi content returned if required
+ if(poiMaxAge != -1000) {
+ mSelection = MapItemsContract.PointsOfInterest.Table.TIMESTAMP + " > ? ";
+ mSelectionArgs = new String[1];
+ mSelectionArgs[0] = Long.toString(System.currentTimeMillis() - poiMaxAge);
+ }
+
+ // determine the order by
+ String mOrderBy = MapItemsContract.PointsOfInterest.Table.TITLE + " ASC";
+
+ // get a content resolver
+ ContentResolver mContentResolver = getApplicationContext().getContentResolver();
+
+ // get the data
+ return mContentResolver.query(
+ MapItemsContract.PointsOfInterest.CONTENT_URI,
+ mProjection,
+ mSelection,
+ mSelectionArgs,
+ mOrderBy);
+ }
+
+
+ /*
+ * (non-Javadoc)
+ * @see android.app.Activity#onPause()
+ */
+ @Override
+ public void onPause() {
+
+ // play nice and close the cursor
+ cursor.close();
+ cursor = null;
+ super.onPause();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see android.app.Activity#onResume()
+ */
+ @Override
+ public void onResume() {
+
+ // get the data
+ cursor = getCursor();
+ super.onResume();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see android.app.ListActivity#onDestroy()
+ */
+ @Override
+ public void onDestroy() {
+
+ // play nice and close the cursor if necessary
+ if(cursor != null) {
+ cursor.close();
+ cursor = null;
+ }
+
+ super.onDestroy();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see android.widget.AdapterView.OnItemClickListener#onItemClick(android.widget.AdapterView, android.view.View, int, long)
+ */
+ @Override
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+
+ if(V_LOG) {
+ Log.v(TAG, "item clicked at position: " + position);
+ }
+
+ // work out the id of the item
+ if(cursor.moveToPosition(position) == true) {
+
+ if(V_LOG) {
+ Log.v(TAG, "item in cursor has id: " + cursor.getInt(cursor.getColumnIndex(MapItemsContract.PointsOfInterest.Table._ID)));
+ }
+
+ Intent mIntent = new Intent(this, org.servalproject.maps.PoiInfoActivity.class);
+ mIntent.putExtra("recordId", cursor.getInt(cursor.getColumnIndex(MapItemsContract.PointsOfInterest.Table._ID)));
+ startActivity(mIntent);
+
+ } else {
+ Log.e(TAG, "unable to match list item position to poi id");
+ Toast.makeText(getApplicationContext(), R.string.poi_list_ui_tiast_missing_poi_id, Toast.LENGTH_LONG).show();
+ finish();
+ }
+
+ }
+}

0 comments on commit ac2908e

Please sign in to comment.
Something went wrong with that request. Please try again.