Added view and delete context menu options
This commit is contained in:
parent
434cc249ed
commit
1f4f5938b5
5
res/menu/favorite_context_menu.xml
Normal file
5
res/menu/favorite_context_menu.xml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item android:title="@string/view_arrivals" android:id="@+id/view"></item>
|
||||||
|
<item android:title="@string/delete" android:id="@+id/delete"></item>
|
||||||
|
</menu>
|
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">Don\'t Miss The Bart</string>
|
<string name="app_name">Bart Catcher</string>
|
||||||
<string name="favorite_routes">Favorite Routes</string>
|
<string name="favorite_routes">Favorite Routes</string>
|
||||||
<string name="empty_favorites_list_message">Press the menu button and select "Add
|
<string name="empty_favorites_list_message">Press the menu button and select "Add
|
||||||
favorite" to
|
favorite" to
|
||||||
@ -10,9 +10,15 @@
|
|||||||
<string name="origin">Origin</string>
|
<string name="origin">Origin</string>
|
||||||
<string name="destination">Destination</string>
|
<string name="destination">Destination</string>
|
||||||
<string name="save">Save</string>
|
<string name="save">Save</string>
|
||||||
<string name="cancel">Cancel</string>
|
|
||||||
<string name="error_matching_origin_and_destination">The origin and destination stations must be different</string>
|
<string name="error_matching_origin_and_destination">The origin and destination stations must be different</string>
|
||||||
<string name="error_null_destination">You must select a destination station</string>
|
<string name="error_null_destination">You must select a destination station</string>
|
||||||
<string name="error_null_origin">You must select an origin station</string>
|
<string name="error_null_origin">You must select an origin station</string>
|
||||||
<string name="arrival_wait_message">Please wait while real time arrival data is loaded...</string>
|
<string name="arrival_wait_message">Please wait while real time arrival data is loaded...</string>
|
||||||
|
<string name="no_data_message">No arrival data is currently available for this route</string>
|
||||||
|
<string name="view">View</string>
|
||||||
|
<string name="view_arrivals">View arrivals</string>
|
||||||
|
<string name="delete">Delete</string>
|
||||||
|
<string name="yes">Yes</string>
|
||||||
|
<string name="cancel">Cancel</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -1,24 +1,40 @@
|
|||||||
package com.dougkeen.bart;
|
package com.dougkeen.bart;
|
||||||
|
|
||||||
import com.dougkeen.bart.data.FavoritesColumns;
|
import android.app.AlertDialog;
|
||||||
|
import android.app.Dialog;
|
||||||
import android.app.ListActivity;
|
import android.app.ListActivity;
|
||||||
|
import android.app.AlertDialog.Builder;
|
||||||
import android.content.ContentUris;
|
import android.content.ContentUris;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
|
import android.database.CursorWrapper;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.view.ContextMenu;
|
||||||
|
import android.view.ContextMenu.ContextMenuInfo;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.AdapterView.AdapterContextMenuInfo;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.SimpleCursorAdapter;
|
import android.widget.SimpleCursorAdapter;
|
||||||
import android.widget.SimpleCursorAdapter.ViewBinder;
|
import android.widget.SimpleCursorAdapter.ViewBinder;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.dougkeen.bart.data.CursorUtils;
|
||||||
|
import com.dougkeen.bart.data.FavoritesColumns;
|
||||||
|
|
||||||
public class FavoritesDashboardActivity extends ListActivity {
|
public class FavoritesDashboardActivity extends ListActivity {
|
||||||
|
private static final int DIALOG_DELETE_EVENT = 0;
|
||||||
|
|
||||||
protected Cursor mQuery;
|
protected Cursor mQuery;
|
||||||
|
|
||||||
|
private Uri mCurrentlySelectedUri;
|
||||||
|
|
||||||
|
private String mCurrentlySelectedRouteName;
|
||||||
|
|
||||||
/** Called when the activity is first created. */
|
/** Called when the activity is first created. */
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
@ -54,6 +70,8 @@ public class FavoritesDashboardActivity extends ListActivity {
|
|||||||
});
|
});
|
||||||
|
|
||||||
setListAdapter(adapter);
|
setListAdapter(adapter);
|
||||||
|
|
||||||
|
registerForContextMenu(getListView());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -80,4 +98,74 @@ public class FavoritesDashboardActivity extends ListActivity {
|
|||||||
startActivity(new Intent(Intent.ACTION_VIEW,
|
startActivity(new Intent(Intent.ACTION_VIEW,
|
||||||
ContentUris.withAppendedId(Constants.FAVORITE_CONTENT_URI, id)));
|
ContentUris.withAppendedId(Constants.FAVORITE_CONTENT_URI, id)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreateContextMenu(ContextMenu menu, View v,
|
||||||
|
ContextMenuInfo menuInfo) {
|
||||||
|
super.onCreateContextMenu(menu, v, menuInfo);
|
||||||
|
|
||||||
|
MenuInflater inflater = getMenuInflater();
|
||||||
|
inflater.inflate(R.menu.favorite_context_menu, menu);
|
||||||
|
|
||||||
|
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
|
||||||
|
CursorWrapper item = (CursorWrapper) getListAdapter().getItem(
|
||||||
|
info.position);
|
||||||
|
Station orig = Station.getByAbbreviation(CursorUtils.getString(item,
|
||||||
|
FavoritesColumns.FROM_STATION));
|
||||||
|
Station dest = Station.getByAbbreviation(CursorUtils.getString(item,
|
||||||
|
FavoritesColumns.TO_STATION));
|
||||||
|
mCurrentlySelectedRouteName = orig.name + " - " + dest.name;
|
||||||
|
menu.setHeaderTitle(mCurrentlySelectedRouteName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onContextItemSelected(MenuItem item) {
|
||||||
|
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
|
||||||
|
.getMenuInfo();
|
||||||
|
mCurrentlySelectedUri = ContentUris.withAppendedId(
|
||||||
|
Constants.FAVORITE_CONTENT_URI,
|
||||||
|
info.id);
|
||||||
|
|
||||||
|
if (item.getItemId() == R.id.view) {
|
||||||
|
startActivity(new Intent(Intent.ACTION_VIEW, mCurrentlySelectedUri));
|
||||||
|
return true;
|
||||||
|
} else if (item.getItemId() == R.id.delete) {
|
||||||
|
showDialog(DIALOG_DELETE_EVENT);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return super.onContextItemSelected(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Dialog onCreateDialog(int id) {
|
||||||
|
if (id == DIALOG_DELETE_EVENT && mCurrentlySelectedUri != null) {
|
||||||
|
final AlertDialog.Builder builder = new Builder(this);
|
||||||
|
builder.setTitle(mCurrentlySelectedRouteName);
|
||||||
|
builder.setCancelable(false);
|
||||||
|
builder.setMessage("Are you sure you want to delete this route?");
|
||||||
|
builder.setPositiveButton(R.string.yes,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
getContentResolver().delete(mCurrentlySelectedUri,
|
||||||
|
null, null);
|
||||||
|
mCurrentlySelectedUri = null;
|
||||||
|
mCurrentlySelectedRouteName = null;
|
||||||
|
removeDialog(DIALOG_DELETE_EVENT);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
builder.setNegativeButton(R.string.cancel,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
mCurrentlySelectedUri = null;
|
||||||
|
mCurrentlySelectedRouteName = null;
|
||||||
|
removeDialog(DIALOG_DELETE_EVENT);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return builder.create();
|
||||||
|
}
|
||||||
|
return super.onCreateDialog(id);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -113,6 +113,12 @@ public class ViewArrivalsActivity extends ListActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void processLatestArrivals(RealTimeArrivals result) {
|
protected void processLatestArrivals(RealTimeArrivals result) {
|
||||||
|
if (result.getArrivals().isEmpty()) {
|
||||||
|
((TextView) findViewById(android.R.id.empty))
|
||||||
|
.setText(R.string.no_data_message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Arrival firstArrival = null;
|
Arrival firstArrival = null;
|
||||||
final List<Arrival> arrivals = result.getArrivals();
|
final List<Arrival> arrivals = result.getArrivals();
|
||||||
if (mArrivalsAdapter.getCount() > 0) {
|
if (mArrivalsAdapter.getCount() > 0) {
|
||||||
|
@ -12,4 +12,9 @@ public final class CursorUtils {
|
|||||||
cursor.close();
|
cursor.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final String getString(Cursor cursor, FavoritesColumns column) {
|
||||||
|
return cursor.getString(cursor.getColumnIndex(column.string));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user