Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add an activity to display a list of POIs
- Loading branch information
techxplorer
committed
Feb 28, 2012
1 parent
71e5d03
commit ac2908e
Showing
9 changed files
with
278 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
|
||
} | ||
} |