Skip to content

Commit 9b7d7d4

Browse files
committed
Merge branch 'master' of github.com:bmeike/ProgrammingAndroid2Examples
2 parents c66f0e1 + 5c6fe07 commit 9b7d7d4

File tree

2 files changed

+87
-64
lines changed

2 files changed

+87
-64
lines changed

MicroJobs/res/values/strings.xml

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,62 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
3-
<string name="app_name">MicroJobs</string>
4-
<string name="show_list">Show List of Jobs</string>
5-
<string name="list_name">List of MicroJobs</string>
6-
<string name="jobs_detail_name">Job Detail</string>
7-
<string name="emp_detail_name">Employer Detail</string>
8-
<string name="add_job_name">Add Job</string>
9-
<string name="edit_job_name">Edit Job</string>
10-
<string name="map_menu_zoom_in">Zoom in</string>
11-
<string name="map_menu_zoom_out">Zoom out</string>
12-
<string name="map_menu_show_list">List jobs</string>
13-
<string name="map_menu_set_satellite">Toggle Satellite</string>
14-
<string name="map_menu_set_map">Toggle Street View</string>
15-
<string name="map_menu_set_traffic">Toggle Traffic View</string>
16-
<string name="list_menu_back_to_map">Back to Map</string>
17-
<string name="list_menu_sort_by_title">Sort by Job Title</string>
18-
<string name="list_menu_sort_by_employer">Sort by Employer</string>
19-
<string name="list_menu_get_employer_detail">Show Employer Info</string>
20-
<string name="list_menu_add_job">Add A New Job</string>
21-
<string name="detail_menu_back_to_list">Back to List of Jobs</string>
22-
<string name="detail_menu_employer_info">Detailed Employer Info</string>
23-
<string name="detail_menu_delete_job">Delete This Job</string>
24-
<string name="detail_menu_edit_job">Edit This Job</string>
3+
<string name="app_name">MicroJobs</string>
4+
<string name="show_list">Show List of Jobs</string>
5+
<string name="list_name">List of MicroJobs</string>
6+
<string name="jobs_detail_name">Job Detail</string>
7+
<string name="emp_detail_name">Employer Detail</string>
8+
<string name="add_job_name">Add Job</string>
9+
<string name="edit_job_name">Edit Job</string>
10+
<string name="map_menu_zoom_in">Zoom in</string>
11+
<string name="map_menu_zoom_out">Zoom out</string>
12+
<string name="map_menu_show_list">List jobs</string>
13+
<string name="map_menu_set_satellite">Toggle Satellite</string>
14+
<string name="map_menu_streetview">Launch Street View</string>
15+
<string name="map_menu_set_traffic">Toggle Traffic View</string>
16+
<string name="list_menu_back_to_map">Back to Map</string>
17+
<string name="list_menu_sort_by_title">Sort by Job Title</string>
18+
<string name="list_menu_sort_by_employer">Sort by Employer</string>
19+
<string name="list_menu_get_employer_detail">Show Employer Info</string>
20+
<string name="list_menu_add_job">Add A New Job</string>
21+
<string name="detail_menu_back_to_list">Back to List of Jobs</string>
22+
<string name="detail_menu_employer_info">Detailed Employer Info</string>
23+
<string name="detail_menu_delete_job">Delete This Job</string>
24+
<string name="detail_menu_edit_job">Edit This Job</string>
2525
<string name="emp_detail_menu_back_to_job_info">Back to Job Info</string>
26-
<string name="db_name">MicroJobs</string>
27-
<string name="MicroJobsDatabase_onCreate">"
28-
CREATE TABLE jobs (_id INTEGER PRIMARY KEY AUTOINCREMENT, employer_id INTEGER, title TEXT, description TEXT, start_time INTEGER, end_time INTEGER, status INTEGER);
29-
CREATE TABLE employers( _id INTEGER, employer_name TEXT, contact_name TEXT, website TEXT, rating INTEGER, street TEXT, city TEXT, state TEXT, zip TEXT, phone TEXT, email TEXT, latitude INTEGER, longitude INTEGER);
30-
CREATE TABLE workers( _id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, username TEXT, passhash TEXT, rating INTEGER, street TEXT, city TEXT, state TEXT, zip TEXT, phone TEXT, email TEXT, loc1_name TEXT, loc1_lat INTEGER, loc1_long INTEGER, loc2_name TEXT, loc2_lat INTEGER, loc2_long INTEGER, loc3_name TEXT, loc3_lat INTEGER, loc3_long INTEGER);
31-
CREATE TABLE status( _id INTEGER PRIMARY KEY AUTOINCREMENT, status TEXT);
32-
INSERT INTO status (_id , status) VALUES (NULL, 'Filled');
33-
INSERT INTO status (_id , status) VALUES (NULL, 'Applied For');
34-
INSERT INTO status (_id , status) VALUES (NULL, 'Open');
35-
INSERT INTO workers(_id, name, username, rating, passhash, street, city, state, zip, phone, email, loc1_name, loc1_lat, loc1_long, loc2_name, loc2_lat, loc2_long, loc3_name, loc3_lat, loc3_long) VALUES (NULL, 'Larry Dickman', 'LD', 50,'', '1 Main Street', 'Boston', 'MA', '01000', '6175551212','Larry@gmail.net', 'Boston', 42358897, -71057795, 'Cambridge, MA', 42359368, -71094208, 'GooglePlex', 37423269,-122084917);
36-
INSERT INTO employers (_id, employer_name, contact_name, website, rating, street, city, state, zip, phone, email, latitude, longitude) VALUES (1, 'Boston Pizza', 'Mike Dukakis', 'www.bostonpizza.com', 40, '40 Boylston Street', 'Boston', 'MA', '01000', '6175551212', 'jobs@BostonPizza.com', 42352299 , -71063979 );
37-
INSERT INTO employers (_id, employer_name, contact_name, website, rating, street, city, state, zip, phone, email, latitude, longitude) VALUES (2, 'New England Hardware', 'Bob Vila', 'www.newenglandhardware.com', 30, '100 Tremont Street', 'Boston', 'MA', '01000', '6175551212', 'jobs@NEH.com', 42357397 , -71061295);
38-
INSERT INTO employers (_id, employer_name, contact_name, website, rating, street, city, state, zip, phone, email, latitude, longitude) VALUES (3, 'Cheers Bar', 'Sam Neal', 'www.cheersbar.com', 50, '10 Newbury Street', 'Boston', 'MA', '01000', '6175551212', 'sam@Cheers.com', 42352466, -71071684);
39-
INSERT INTO employers (_id, employer_name, contact_name, website, rating, street, city, state, zip, phone, email, latitude, longitude) VALUES (4, 'West Coast Lumber', 'Harry Truman', 'www.westcoastlumber.com', 35, '455 W Evelyn Ave', 'Mountain View', 'CA', '94041', '6505551212', 'jobs@westcoastlumber.com', 37393133, -122074941);
40-
INSERT INTO employers (_id, employer_name, contact_name, website, rating, street, city, state, zip, phone, email, latitude, longitude) VALUES (5, 'Google', 'Eric Schmidt', 'www.google.com', 50, '1600 Amphitheatre Parkway', 'Mountain View', 'CA', '94041', '6502530000', 'jobs@google.com', 37423269, -122082667);
41-
INSERT INTO employers (_id, employer_name, contact_name, website, rating, street, city, state, zip, phone, email, latitude, longitude) VALUES (6, 'Shakes Electronics', 'Elvis Presley', 'www.shakes.com', 35, '340 Portage Ave', 'Palo Alto', 'CA', '94306', '6504962000', 'jobs@shakes.com', 37422404, -122137609);
42-
INSERT INTO jobs (_id, employer_id, title, description, start_time, end_time, status) VALUES (NULL, 1, 'Busboy', 'Need a person to help clean tables for a few hours. No experience necessary', 0, 0, 3);
43-
INSERT INTO jobs (_id, employer_id, title, description, start_time, end_time, status) VALUES (NULL, 3, 'Bartender apprentice', 'Help our regular bartender during rush hours. Must be over 21', 0, 0, 2);
44-
INSERT INTO jobs (_id, employer_id, title, description, start_time, end_time, status) VALUES (NULL, 2, 'General help', 'Someone to help stock shelves and open the store', 0,0,1);
45-
INSERT INTO jobs (_id, employer_id, title, description, start_time, end_time, status) VALUES (NULL, 4, 'Carpenter apprentice', 'Assist contract carpenters in assembly of backyard storage sheds.', 0, 0, 1);
46-
INSERT INTO jobs (_id, employer_id, title, description, start_time, end_time, status) VALUES (NULL, 4, 'Store help', 'Help stock shelves', 0, 0, 2);
47-
INSERT INTO jobs (_id, employer_id, title, description, start_time, end_time, status) VALUES (NULL, 5, 'CEO Standin', 'Need impersonator to stand in for Eric Schmidt while on vacation. Must look exactly like Eric Schmidt.', 0, 0, 3);
48-
INSERT INTO jobs (_id, employer_id, title, description, start_time, end_time, status) VALUES (NULL, 5, 'Microsoft Advocate', 'Need lightning rod to promote use of Microsoft tools within Google. Short term position.', 0, 0, 1);
49-
INSERT INTO jobs (_id, employer_id, title, description, start_time, end_time, status) VALUES (NULL, 6, 'Customer support', 'Person to help TV customers understand that, no matter what their current problem, they need a new, bigger HD TV', 0, 0, 2);
50-
INSERT INTO jobs (_id, employer_id, title, description, start_time, end_time, status) VALUES (NULL, 6, 'Game tester', 'Person to test new XBox games for hidden features.', 0, 0, 3);
51-
INSERT INTO jobs (_id, employer_id, title, description, start_time, end_time, status) VALUES (NULL, 4, 'Carpentry teacher', 'Teach customers basic carpentry skills. Must have done commercial work as a finish carpenter.', 0, 0, 1);
52-
INSERT INTO jobs (_id, employer_id, title, description, start_time, end_time, status) VALUES (NULL, 4, 'Medic', 'Skilled in basic First Aid to stop bleeding of carpentry students.', 0, 0, 1);
53-
INSERT INTO jobs (_id, employer_id, title, description, start_time, end_time, status) VALUES (NULL, 1, 'Kitchen help', 'Assist chef in high end pizza kitchen. No experience necessary', 0, 0, 2);
54-
INSERT INTO jobs (_id, employer_id, title, description, start_time, end_time, status) VALUES (NULL, 2, 'Temporary Cashier', 'Must have experience using a cash register.', 0, 0, 1);
55-
"</string>
56-
<string name="MicroJobsDatabase_onUpgrade">"
57-
DROP TABLE IF EXISTS jobs
58-
DROP TABLE IF EXISTS employers
59-
DROP TABLE IF EXISTS workers
60-
DROP TABLE IF EXISTS status
61-
"</string>
26+
<string name="db_name">MicroJobs</string>
27+
<string name="MicroJobsDatabase_onCreate">"
28+
CREATE TABLE jobs (_id INTEGER PRIMARY KEY AUTOINCREMENT, employer_id INTEGER, title TEXT, description TEXT, start_time INTEGER, end_time INTEGER, status INTEGER);
29+
CREATE TABLE employers( _id INTEGER, employer_name TEXT, contact_name TEXT, website TEXT, rating INTEGER, street TEXT, city TEXT, state TEXT, zip TEXT, phone TEXT, email TEXT, latitude INTEGER, longitude INTEGER);
30+
CREATE TABLE workers( _id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, username TEXT, passhash TEXT, rating INTEGER, street TEXT, city TEXT, state TEXT, zip TEXT, phone TEXT, email TEXT, loc1_name TEXT, loc1_lat INTEGER, loc1_long INTEGER, loc2_name TEXT, loc2_lat INTEGER, loc2_long INTEGER, loc3_name TEXT, loc3_lat INTEGER, loc3_long INTEGER);
31+
CREATE TABLE status( _id INTEGER PRIMARY KEY AUTOINCREMENT, status TEXT);
32+
INSERT INTO status (_id , status) VALUES (NULL, 'Filled');
33+
INSERT INTO status (_id , status) VALUES (NULL, 'Applied For');
34+
INSERT INTO status (_id , status) VALUES (NULL, 'Open');
35+
INSERT INTO workers(_id, name, username, rating, passhash, street, city, state, zip, phone, email, loc1_name, loc1_lat, loc1_long, loc2_name, loc2_lat, loc2_long, loc3_name, loc3_lat, loc3_long) VALUES (NULL, 'Larry Dickman', 'LD', 50,'', '1 Main Street', 'Boston', 'MA', '01000', '6175551212','Larry@gmail.net', 'Boston', 42358897, -71057795, 'Cambridge, MA', 42359368, -71094208, 'GooglePlex', 37423269,-122084917);
36+
INSERT INTO employers (_id, employer_name, contact_name, website, rating, street, city, state, zip, phone, email, latitude, longitude) VALUES (1, 'Boston Pizza', 'Mike Dukakis', 'www.bostonpizza.com', 40, '40 Boylston Street', 'Boston', 'MA', '01000', '6175551212', 'jobs@BostonPizza.com', 42352299 , -71063979 );
37+
INSERT INTO employers (_id, employer_name, contact_name, website, rating, street, city, state, zip, phone, email, latitude, longitude) VALUES (2, 'New England Hardware', 'Bob Vila', 'www.newenglandhardware.com', 30, '100 Tremont Street', 'Boston', 'MA', '01000', '6175551212', 'jobs@NEH.com', 42357397 , -71061295);
38+
INSERT INTO employers (_id, employer_name, contact_name, website, rating, street, city, state, zip, phone, email, latitude, longitude) VALUES (3, 'Cheers Bar', 'Sam Neal', 'www.cheersbar.com', 50, '10 Newbury Street', 'Boston', 'MA', '01000', '6175551212', 'sam@Cheers.com', 42352466, -71071684);
39+
INSERT INTO employers (_id, employer_name, contact_name, website, rating, street, city, state, zip, phone, email, latitude, longitude) VALUES (4, 'West Coast Lumber', 'Harry Truman', 'www.westcoastlumber.com', 35, '455 W Evelyn Ave', 'Mountain View', 'CA', '94041', '6505551212', 'jobs@westcoastlumber.com', 37393133, -122074941);
40+
INSERT INTO employers (_id, employer_name, contact_name, website, rating, street, city, state, zip, phone, email, latitude, longitude) VALUES (5, 'Google', 'Eric Schmidt', 'www.google.com', 50, '1600 Amphitheatre Parkway', 'Mountain View', 'CA', '94041', '6502530000', 'jobs@google.com', 37423269, -122082667);
41+
INSERT INTO employers (_id, employer_name, contact_name, website, rating, street, city, state, zip, phone, email, latitude, longitude) VALUES (6, 'Shakes Electronics', 'Elvis Presley', 'www.shakes.com', 35, '340 Portage Ave', 'Palo Alto', 'CA', '94306', '6504962000', 'jobs@shakes.com', 37422404, -122137609);
42+
INSERT INTO jobs (_id, employer_id, title, description, start_time, end_time, status) VALUES (NULL, 1, 'Busboy', 'Need a person to help clean tables for a few hours. No experience necessary', 0, 0, 3);
43+
INSERT INTO jobs (_id, employer_id, title, description, start_time, end_time, status) VALUES (NULL, 3, 'Bartender apprentice', 'Help our regular bartender during rush hours. Must be over 21', 0, 0, 2);
44+
INSERT INTO jobs (_id, employer_id, title, description, start_time, end_time, status) VALUES (NULL, 2, 'General help', 'Someone to help stock shelves and open the store', 0,0,1);
45+
INSERT INTO jobs (_id, employer_id, title, description, start_time, end_time, status) VALUES (NULL, 4, 'Carpenter apprentice', 'Assist contract carpenters in assembly of backyard storage sheds.', 0, 0, 1);
46+
INSERT INTO jobs (_id, employer_id, title, description, start_time, end_time, status) VALUES (NULL, 4, 'Store help', 'Help stock shelves', 0, 0, 2);
47+
INSERT INTO jobs (_id, employer_id, title, description, start_time, end_time, status) VALUES (NULL, 5, 'CEO Standin', 'Need impersonator to stand in for Eric Schmidt while on vacation. Must look exactly like Eric Schmidt.', 0, 0, 3);
48+
INSERT INTO jobs (_id, employer_id, title, description, start_time, end_time, status) VALUES (NULL, 5, 'Microsoft Advocate', 'Need lightning rod to promote use of Microsoft tools within Google. Short term position.', 0, 0, 1);
49+
INSERT INTO jobs (_id, employer_id, title, description, start_time, end_time, status) VALUES (NULL, 6, 'Customer support', 'Person to help TV customers understand that, no matter what their current problem, they need a new, bigger HD TV', 0, 0, 2);
50+
INSERT INTO jobs (_id, employer_id, title, description, start_time, end_time, status) VALUES (NULL, 6, 'Game tester', 'Person to test new XBox games for hidden features.', 0, 0, 3);
51+
INSERT INTO jobs (_id, employer_id, title, description, start_time, end_time, status) VALUES (NULL, 4, 'Carpentry teacher', 'Teach customers basic carpentry skills. Must have done commercial work as a finish carpenter.', 0, 0, 1);
52+
INSERT INTO jobs (_id, employer_id, title, description, start_time, end_time, status) VALUES (NULL, 4, 'Medic', 'Skilled in basic First Aid to stop bleeding of carpentry students.', 0, 0, 1);
53+
INSERT INTO jobs (_id, employer_id, title, description, start_time, end_time, status) VALUES (NULL, 1, 'Kitchen help', 'Assist chef in high end pizza kitchen. No experience necessary', 0, 0, 2);
54+
INSERT INTO jobs (_id, employer_id, title, description, start_time, end_time, status) VALUES (NULL, 2, 'Temporary Cashier', 'Must have experience using a cash register.', 0, 0, 1);
55+
"</string>
56+
<string name="MicroJobsDatabase_onUpgrade">"
57+
DROP TABLE IF EXISTS jobs
58+
DROP TABLE IF EXISTS employers
59+
DROP TABLE IF EXISTS workers
60+
DROP TABLE IF EXISTS status
61+
"</string>
6262
</resources>

MicroJobs/src/com/oreilly/demo/android/pa/microjobs/MicroJobs.java

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import android.graphics.drawable.Drawable;
1010
import android.location.Location;
1111
import android.location.LocationManager;
12+
import android.net.Uri;
1213
import android.os.Bundle;
1314
import android.util.Log;
1415
import android.view.KeyEvent;
@@ -121,6 +122,7 @@ public boolean onTap(GeoPoint p, MapView mvMap1) {
121122
MicroJobsDatabase db;
122123
MyLocationOverlay mMyLocationOverlay;
123124
int latitude, longitude;
125+
double[] curlocation = new double[2];
124126

125127
/**
126128
* Called when the activity is first created.
@@ -151,6 +153,7 @@ public void onCreate(Bundle savedInstanceState) {
151153
public void run() {
152154
mc.animateTo(mMyLocationOverlay.getMyLocation());
153155
mc.setZoom(16);
156+
updateCurLocation(mMyLocationOverlay.getMyLocation());
154157
}
155158
});
156159

@@ -162,7 +165,6 @@ public void run() {
162165
mvMap.setEnabled(true);
163166
mvMap.setSatellite(false);
164167
mvMap.setTraffic(false);
165-
mvMap.setStreetView(false);
166168

167169
// start out with a general zoom
168170
mc.setZoom(16);
@@ -214,6 +216,7 @@ public void onItemSelected(AdapterView<?> parent, View v, int position, long id)
214216
mMyLocationOverlay.getMyLocation();
215217
if (myLocation != null) {
216218
mc.animateTo(myLocation);
219+
updateCurLocation(myLocation);
217220
}
218221
}
219222
catch (Exception e) {
@@ -223,6 +226,7 @@ public void onItemSelected(AdapterView<?> parent, View v, int position, long id)
223226
} else {
224227
mMyLocationOverlay.disableMyLocation();
225228
mc.animateTo(hmLocations.get(vt.getText()));
229+
updateCurLocation(hmLocations.get(vt.getText()));
226230
}
227231
mvMap.invalidate();
228232
}
@@ -268,7 +272,7 @@ public boolean onCreateOptionsMenu(Menu menu) {
268272
menu.add(Menu.NONE, 0, Menu.NONE, getString(R.string.map_menu_zoom_in));
269273
menu.add(Menu.NONE, 1, Menu.NONE, getString(R.string.map_menu_zoom_out));
270274
menu.add(Menu.NONE, 2, Menu.NONE, getString(R.string.map_menu_set_satellite));
271-
menu.add(Menu.NONE, 3, Menu.NONE, getString(R.string.map_menu_set_map));
275+
menu.add(Menu.NONE, 3, Menu.NONE, getString(R.string.map_menu_streetview));
272276
menu.add(Menu.NONE, 4, Menu.NONE, getString(R.string.map_menu_set_traffic));
273277
menu.add(Menu.NONE, 5, Menu.NONE, getString(R.string.map_menu_show_list));
274278
return supRetVal;
@@ -293,8 +297,10 @@ public boolean onOptionsItemSelected(MenuItem item) {
293297
mvMap.setSatellite(!mvMap.isSatellite());
294298
return true;
295299
case 3:
296-
// Toggle street views
297-
mvMap.setStreetView(!mvMap.isStreetView());
300+
// Launch StreetView with lat/lon of center of current map
301+
String uri = "google.streetview:cbll="+curlocation[0]+","+curlocation[1]+"&cbp=1,0,,0,1.0&mz="+mvMap.getZoomLevel();
302+
Intent streetView = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
303+
startActivity(streetView);
298304
return true;
299305
case 4:
300306
// Toggle traffic views
@@ -355,14 +361,31 @@ private void zoomOut() {
355361
*/
356362
private Location getCurrentLocation(LocationManager lm) {
357363
Location l = lm.getLastKnownLocation("gps");
358-
if (null != l) { return l; }
364+
if (null != l) { updateCurLocation(l); return l; }
359365

360366
// getLastKnownLocation returns null if loc provider is not enabled
361367
l = new Location("gps");
362368
l.setLatitude(42.352299);
363369
l.setLatitude(-71.063979);
364-
370+
371+
updateCurLocation(l);
365372
return l;
366373
}
374+
375+
/**
376+
* updates curlocation for streetview use
377+
*/
378+
private void updateCurLocation(GeoPoint point) {
379+
curlocation[0] = ((double) point.getLatitudeE6()) / ((double) 1E6);
380+
curlocation[1] = ((double) point.getLongitudeE6()) / ((double) 1E6);
381+
}
382+
383+
/**
384+
* updates curlocation for streetview use
385+
*/
386+
private void updateCurLocation(Location loc) {
387+
curlocation[0] = loc.getLatitude();
388+
curlocation[1] = loc.getLongitude();
389+
}
367390

368391
}

0 commit comments

Comments
 (0)