public class ListDeliveriesActivity extends ListActivity {
private SQLiteDatabase db;
private Cursor cursor;
private View dlvheaderView;
private String alicplate;
private double asitelat;
private double asitelng;
private double adeplat;
private double adeplng;
private double acurrlat;
private double acurrlng;
private LatLng siteLatLng;
public LatLng depotLatLng;
public LatLng currentLatLng;
private final String dlvQuery = "SELECT _id, Licenseplate, "+
"DepLatitude, DepLongitude, " +
"SiteLatitude, SiteLongitude, " +
"Latitude, Longitude FROM Drivers " +
"WHERE Projectname = ? " +
"ORDER BY Licenseplate;";
[USER=1021285]@override[/USER]
// We will be using a simple LISTVIEW here in this module
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// grab the projectname to identify all trucks working on this project
Bundle b = new Bundle();
b = getIntent().getExtras();
String aprojectname = b.getString("tagprjname");
//
String[] dbFields = new String[]{
AssetLocationDBHelper.FLD_Licenseplate,
AssetLocationDBHelper.FLD_Latitude,
AssetLocationDBHelper.FLD_Longitude
};
int[] xmlFields = new int[] {
R.id.licplate,
R.id.currentlat,
R.id.currentlng
};
ListView listDeliveries = getListView();
LayoutInflater inflater = getLayoutInflater();
dlvheaderView = inflater.inflate(R.layout.activity_list_deliveries, listDeliveries, false);
// TODO
// Cursor for this project's list of vehicle locations.
try {
SQLiteOpenHelper assetlocationDBhelper = new AssetLocationDBHelper(this);
SQLiteDatabase db = assetlocationDBhelper.getReadableDatabase();
cursor = db.rawQuery(dlvQuery, new String[]{aprojectname});
CursorAdapter listAdapter = new SimpleCursorAdapter(this,
R.layout.deliveries_list,
cursor,
dbFields,
xmlFields,
0);
// move the cursor to point to the first record
listDeliveries.addHeaderView(dlvheaderView);
listDeliveries.setAdapter(listAdapter);
} catch (SQLiteException ex) {
Toast toast = Toast.makeText(this, "ERROR(2) database unavailable", Toast.LENGTH_SHORT);
toast.show();
}
}
[USER=1021285]@override[/USER]
protected void onResume(){
super.onResume();
}
[USER=1021285]@override[/USER]
public void onListItemClick(ListView listDeliveriesView,
View itemView,
int position,
long id) {
cursor = (Cursor) listDeliveriesView.getItemAtPosition(position);
alicplate = cursor.getString(cursor.getColumnIndexOrThrow("Licenseplate"));
//alicplate = cursor.getString(0);
// location of depot
adeplat = cursor.getDouble(cursor.getColumnIndexOrThrow("DepLatitude"));
//adeplat = cursor.getDouble(1);
//adeplng = cursor.getDouble(cursor.getColumnIndexOrThrow("DepLongitude"));
//adeplng = cursor.getDouble(3);
//depotLatLng = new LatLng(adeplat,adeplng);
// location of pour site
/**
asitelat = cursor.getDouble(cursor.getColumnIndexOrThrow("SiteLatitude"));
asitelng = cursor.getDouble(cursor.getColumnIndexOrThrow("SiteLongitude"));
siteLatLng = new LatLng(asitelat,asitelng);
// current location of truck
acurrlat = cursor.getDouble(cursor.getColumnIndexOrThrow("Latitude"));
acurrlng = cursor.getDouble(cursor.getColumnIndexOrThrow("Longitude"));
currentLatLng = new LatLng(acurrlat, acurrlng);
***/
Toast toast = Toast.makeText(this, alicplate + String.valueOf(adeplat), Toast.LENGTH_LONG);
toast.show();
//makeBundle();
}
private void makeBundle(){
Bundle args = new Bundle();
args.putParcelable("depotLatLng", depotLatLng);
args.putParcelable("siteLatLng", siteLatLng);
args.putParcelable("currentLatLng", currentLatLng);
//
Intent intent = new Intent(ListDeliveriesActivity.this,ShowMapsActivity.class);
intent.putExtra("bundle", args);
//startActivity(intent);
}
} // end of ListDeliveriesActivity