MultiSmsSender/src/com/hectorone/multismssender/SelectDeliveryActivity.java

102 lines
2.8 KiB
Java
Raw Permalink Normal View History

2010-12-12 02:36:52 +01:00
package com.hectorone.multismssender;
2010-01-22 15:21:33 +01:00
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
2010-01-22 15:21:33 +01:00
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView.AdapterContextMenuInfo;
2010-01-22 15:21:33 +01:00
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
public class SelectDeliveryActivity extends ListActivity {
DeliveryDbAdapter mDbHelper;
2012-11-06 10:35:01 +01:00
public static final int DELETE_ID = Menu.FIRST;
2010-01-22 15:21:33 +01:00
public static final int DELETE_ALL_ID = Menu.FIRST + 1;
2012-11-06 10:35:01 +01:00
public static final int REFRESH_ID = Menu.FIRST + 2;
2010-01-22 15:21:33 +01:00
2012-11-06 10:35:01 +01:00
public static final String PARAM_DELIVERY_ID = "param_delivery_id";
2010-01-22 15:21:33 +01:00
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.delivery_list);
fillData();
registerForContextMenu(getListView());
}
protected void onDestroy() {
super.onDestroy();
}
2012-11-06 10:35:01 +01:00
2010-01-22 15:21:33 +01:00
public void fillData() {
2012-11-06 10:35:01 +01:00
Cursor deliveryCursor = getContentResolver().query(
DeliveryDbAdapter.CONTENT_MESSAGE_URI, null, null, null, null);
2010-01-22 15:21:33 +01:00
startManagingCursor(deliveryCursor);
2012-11-06 10:35:01 +01:00
String[] from = new String[] { DeliveryDbAdapter.KEY_MESSAGE_DATE,
DeliveryDbAdapter.KEY_MESSAGE_NAME };
2010-01-22 15:21:33 +01:00
2012-11-06 10:35:01 +01:00
int[] to = new int[] { R.id.date, R.id.name };
2010-01-22 15:21:33 +01:00
2012-11-06 10:35:01 +01:00
SimpleCursorAdapter notes = new SimpleCursorAdapter(this,
R.layout.delivery_row, deliveryCursor, from, to);
2010-01-22 15:21:33 +01:00
setListAdapter(notes);
}
2012-11-06 10:35:01 +01:00
2010-01-22 15:21:33 +01:00
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
2012-11-06 10:35:01 +01:00
menu.add(0, DELETE_ALL_ID, 0, R.string.remove_all);
2010-01-22 15:21:33 +01:00
return true;
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.add(0, DELETE_ID, 0, R.string.remove);
}
2012-11-06 10:35:01 +01:00
2010-01-22 15:21:33 +01:00
@Override
public boolean onContextItemSelected(MenuItem item) {
2012-11-06 10:35:01 +01:00
switch (item.getItemId()) {
2010-01-22 15:21:33 +01:00
case DELETE_ID:
2012-11-06 10:35:01 +01:00
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
.getMenuInfo();
getContentResolver().delete(DeliveryDbAdapter.CONTENT_MESSAGE_URI,
DeliveryDbAdapter.KEY_MESSAGE_ROWID + "=" + info.id, null);
2010-01-22 15:21:33 +01:00
fillData();
return true;
}
return super.onContextItemSelected(item);
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
2012-11-06 10:35:01 +01:00
switch (item.getItemId()) {
2010-01-22 15:21:33 +01:00
case DELETE_ALL_ID:
2012-11-06 10:35:01 +01:00
getContentResolver().delete(DeliveryDbAdapter.CONTENT_MESSAGE_URI,
null, null);
2010-01-25 17:58:12 +01:00
fillData();
2010-01-22 15:21:33 +01:00
return true;
2012-11-06 10:35:01 +01:00
}
2010-01-22 15:21:33 +01:00
return super.onMenuItemSelected(featureId, item);
}
2012-11-06 10:35:01 +01:00
2010-01-22 15:21:33 +01:00
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
Intent i = new Intent(this, ListEntryActivity.class);
i.putExtra(PARAM_DELIVERY_ID, id);
startActivity(i);
super.onListItemClick(l, v, position, id);
}
}