Skip to content

Commit 83cab4a

Browse files
committed
Expanded MapActivity, more prefs, home/work overlays
1 parent d2fbc6c commit 83cab4a

File tree

3 files changed

+191
-83
lines changed

3 files changed

+191
-83
lines changed

src/edu/fsu/cs/contextprovider/ContextService.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,11 @@ private void startService() {
119119
IntentFilter restartFilter = new IntentFilter();
120120
restartFilter.addAction(ContextConstants.CONTEXT_RESTART_INTENT);
121121
registerReceiver(restartIntentReceiver, restartFilter);
122-
123-
// if (accuracyPopupEnabled)
124-
// popupTimer.schedule(new ContextPopupTask(), (accuracyPopupPeriod * 1000)); // seconds*1000
125122
}
126123

127124
private void stopService() {
128125
stopMonitors();
129-
// PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(this);
130126
prefs.unregisterOnSharedPreferenceChangeListener(this);
131-
132127
unregisterReceiver(restartIntentReceiver);
133128
unregisterReceiver(contextIntentReceiver);
134129
}
@@ -208,7 +203,6 @@ private void getPrefs() {
208203
accuracyPopupPeriod = prefs.getString(ContextConstants.PREFS_ACCURACY_POPUP_FREQ, "45");
209204

210205
locationEnabled = prefs.getBoolean(ContextConstants.PREFS_LOCATION_ENABLED, true);
211-
// locationProximityEnabled = prefs.getBoolean(ContextConstants.PREFS_LOCATION_PROXIMITY_ENABLED, true);
212206
locationPollFreq = prefs.getString(ContextConstants.PREFS_LOCATION_POLL_FREQ, "30");
213207
locationStoreFreq = prefs.getString(ContextConstants.PREFS_LOCATION_STORE_FREQ, "30");
214208

@@ -309,7 +303,6 @@ public void onReceive(Context context, Intent intent) {
309303
placeAccurate = intent.getIntExtra(ContextConstants.PLACE_ACCURATE, 10);
310304
movementAccurate = intent.getIntExtra(ContextConstants.MOVEMENT_ACCURATE, 10);
311305
activityAccurate = intent.getIntExtra(ContextConstants.ACTIVITY_ACCURATE, 10);
312-
313306
// shelterAccurate = intent.getIntExtra(ContextConstants.SHELTER_ACCURATE, 10);
314307
// onPersonAccurate = intent.getIntExtra(ContextConstants.ONPERSON_ACCURATE, 10);
315308
shelterAccurate = intent.getBooleanExtra(ContextConstants.SHELTER_ACCURATE, true);

src/edu/fsu/cs/contextprovider/data/ContextConstants.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ public class ContextConstants {
6969
public static final String SHELTER_ACCURATE = "SHELTER_ACCURATE";
7070
public static final String ONPERSON_ACCURATE = "ONPERSON_ACCURATE";
7171

72+
// map activity
73+
public static final String HOME_COORDINATES = "HOME_COORDINATES";
74+
public static final String WORK_COORDINATES = "WORK_COORDINATES";
75+
7276

7377
// intent IDs
7478
public static final String CONTEXT_STORE_INTENT = "edu.fsu.cs.contextprovider.store";

src/edu/fsu/cs/contextprovider/map/AddPlaceMapActivity.java

Lines changed: 187 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,22 @@
22

33
import java.util.List;
44
import java.util.concurrent.atomic.AtomicReference;
5+
6+
import android.R.bool;
57
import android.app.AlertDialog;
68
import android.content.Context;
79
import android.content.DialogInterface;
810
import android.content.Intent;
11+
import android.content.SharedPreferences;
912
import android.graphics.drawable.Drawable;
1013
import android.location.Criteria;
1114
import android.location.Location;
1215
import android.location.LocationListener;
1316
import android.location.LocationManager;
1417
import android.os.Bundle;
18+
import android.util.Log;
19+
import android.view.Menu;
20+
import android.view.MenuItem;
1521
import android.widget.Toast;
1622

1723
import com.google.android.maps.GeoPoint;
@@ -39,8 +45,15 @@ public class AddPlaceMapActivity extends MapActivity {
3945
private Location currentLocation;
4046
protected final AtomicReference<Place> destinationReference = new AtomicReference<Place>();
4147
protected Drawable destinationDrawable;
48+
protected Drawable placeDrawable;
4249

50+
private boolean DEBUG = true;
51+
4352
private int REQUEST_ID = -1;
53+
54+
SharedPreferences prefs;
55+
private double placeLat;
56+
private double placeLon;
4457

4558
/** Called when the activity is first created. */
4659
@Override
@@ -49,33 +62,15 @@ public void onCreate(Bundle savedInstanceState) {
4962
setContentView(R.layout.placemap);
5063
Intent intent = getIntent();
5164
REQUEST_ID = intent.getIntExtra(ContextConstants.PLACE_REQUEST_ID, -1);
52-
53-
// geopoint for overlayitem
54-
// Double latitude = 37.423156 * 1E6;
55-
// Double longuitude = -122.084917 * 1E6;
56-
// GeoPoint point = new GeoPoint(latitude.intValue(), longuitude.intValue());
57-
58-
// // create new overlayitem
59-
// OverlayItem overlayitem = new OverlayItem(point, "Googleplex", "Google");
60-
// overlay = new PlaceItemizedOverlay(getResources().getDrawable(R.drawable.location));
61-
// overlay.addOverlay(overlayitem);
62-
63-
// add overlay to map
64-
map = (MapView) findViewById(R.id.mapView);
65-
List<Overlay> mapOverlays = map.getOverlays();
66-
// mapOverlays.add(overlay);
6765

66+
getPrefs();
6867

69-
mapOverlays.add(new PlaceOverlay(this));
70-
71-
// MyLocation manage your position and enable compass
72-
MyLocationOverlay myLocationOverlay = new MyLocationOverlay(this, map);
73-
mapOverlays.add(myLocationOverlay);
74-
myLocationOverlay.enableMyLocation();
68+
map = (MapView) findViewById(R.id.mapView);
69+
createOverlay();
7570

7671
// Mapcontroller set zoom and center
7772
mapController = map.getController();
78-
// mapController.setCenter(point);
73+
// mapController.setCenter(point);
7974
mapController.setZoom(16);
8075
map.setBuiltInZoomControls(true);
8176

@@ -84,14 +79,13 @@ public void onCreate(Bundle savedInstanceState) {
8479

8580
// Set the criteria
8681
criteria = new Criteria();
87-
// other option Criteria.ACCURACY_COARSE
88-
criteria.setAccuracy(Criteria.ACCURACY_FINE);
82+
// criteria.setAccuracy(Criteria.ACCURACY_FINE);
83+
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
8984
criteria.setAltitudeRequired(false);
9085
criteria.setBearingRequired(false);
9186
criteria.setCostAllowed(true);
9287
// other options Criteria.POWER_HIGH Criteria.POWER_MEDIUM
9388
criteria.setPowerRequirement(Criteria.POWER_LOW);
94-
9589
}
9690

9791
@Override
@@ -106,10 +100,7 @@ public void onStart() {
106100
Location location = locationManager.getLastKnownLocation(provider);
107101
update(location);
108102
// Start listening for location changes
109-
locationManager.requestLocationUpdates(provider, 60000, // every
110-
// 1min
111-
1000, // change locations min 1km
112-
locationListener);
103+
locationManager.requestLocationUpdates(provider, 60000, /* every 1min */ 1000, /* min 1km */locationListener);
113104
}
114105
}
115106

@@ -124,22 +115,98 @@ public void onStop() {
124115
public void onLocationChanged(Location location) {
125116
update(location);
126117
}
127-
128118
public void onProviderDisabled(String provider) {
129119
update(null);
130120
}
131-
132121
public void onProviderEnabled(String provider) {
133-
// TODO Auto-generated method stub
134-
135122
}
136-
137123
public void onStatusChanged(String provider, int status, Bundle extras) {
138-
// TODO Auto-generated method stub
139-
140124
}
141-
142125
};
126+
127+
public void createOverlay() {
128+
List<Overlay> mapOverlays = map.getOverlays();
129+
130+
switch (REQUEST_ID) {
131+
case ContextConstants.SET_HOME_REQUEST:
132+
if (DerivedMonitor.Home != null) {
133+
OverlayItem overlayitem = new OverlayItem(DerivedMonitor.Home.getGeoPoint(), "Home", "Home");
134+
overlay = new PlaceItemizedOverlay(getResources().getDrawable(R.drawable.home));
135+
overlay.addOverlay(overlayitem);
136+
mapOverlays.add(overlay);
137+
}
138+
break;
139+
case ContextConstants.SET_WORK_REQUEST:
140+
if (DerivedMonitor.Work != null) {
141+
OverlayItem overlayitem = new OverlayItem(DerivedMonitor.Work.getGeoPoint(), "Work", "Work");
142+
overlay = new PlaceItemizedOverlay(getResources().getDrawable(R.drawable.work));
143+
overlay.addOverlay(overlayitem);
144+
mapOverlays.add(overlay);
145+
}
146+
break;
147+
default:
148+
break;
149+
}
150+
151+
mapOverlays.add(new PlaceOverlay(this));
152+
153+
// MyLocation manage your position and enable compass
154+
MyLocationOverlay myLocationOverlay = new MyLocationOverlay(this, map);
155+
mapOverlays.add(myLocationOverlay);
156+
myLocationOverlay.enableMyLocation();
157+
}
158+
159+
160+
private void getPrefs() {
161+
prefs = getSharedPreferences(ContextConstants.CONTEXT_PREFS, MODE_PRIVATE);
162+
163+
switch (REQUEST_ID) {
164+
case ContextConstants.SET_HOME_REQUEST:
165+
166+
break;
167+
case ContextConstants.SET_WORK_REQUEST:
168+
if (DerivedMonitor.Work != null) {
169+
170+
}
171+
break;
172+
default:
173+
break;
174+
}
175+
176+
String placeString = prefs.getString(ContextConstants.HOME_COORDINATES, "");
177+
if (DEBUG) {
178+
// Log.d(TAG, "accuracyDismissDelay: " + accuracyDismissDelay + " dismissDelay: " + dismissDelay);
179+
}
180+
}
181+
182+
183+
// public void createOverlay(){
184+
// mapOverlays=mapView.getOverlays();
185+
// OverlayItem item;
186+
// drawable = this.getResources().getDrawable(R.drawable.icon_map);
187+
// MixOverlay mixOverlay = new MixOverlay(this, drawable);
188+
//
189+
// for(Marker marker:markerList) {
190+
// if(marker.isActive()) {
191+
// GeoPoint point = new GeoPoint((int)(marker.getLatitude()*1E6), (int)(marker.getLongitude()*1E6));
192+
// item = new OverlayItem(point, "", "");
193+
// mixOverlay.addOverlay(item);
194+
// }
195+
// }
196+
// //Solved issue 39: only one overlay with all marker instead of one overlay for each marker
197+
// mapOverlays.add(mixOverlay);
198+
//
199+
// MixOverlay myOverlay;
200+
// drawable = this.getResources().getDrawable(R.drawable.loc_icon);
201+
// myOverlay = new MixOverlay(this, drawable);
202+
//
203+
// item = new OverlayItem(startPoint, "Your Position", "");
204+
// myOverlay.addOverlay(item);
205+
// mapOverlays.add(myOverlay);
206+
// }
207+
208+
209+
143210

144211
private void update(Location location) {
145212
if (location != null) {
@@ -149,12 +216,12 @@ private void update(Location location) {
149216
Double lng = location.getLongitude() * 1E6;
150217
GeoPoint point = new GeoPoint(lat.intValue(), lng.intValue());
151218
mapController.setCenter(point);
219+
mapController.setZoom(15);
152220
Toast.makeText(this, "My Location:" + location.getLatitude() + "," + location.getLongitude(), Toast.LENGTH_LONG);
153-
// get some data in other thread
154-
// RefreshListview
155221
}
156-
}
157-
222+
}
223+
224+
158225
@Override
159226
protected boolean isRouteDisplayed() {
160227
// TODO Auto-generated method stub
@@ -164,42 +231,86 @@ protected boolean isRouteDisplayed() {
164231
public void placeSelected(Place place) {
165232
destinationReference.set(place);
166233
final FloatingPointGeoPoint point = place.getLocation();
167-
168-
// List<Overlay> mapOverlays = map.getOverlays();
169-
// mapOverlays.add(new PlaceOverlay(this));
170-
// OverlayItem overlayitem = new OverlayItem(point.getGeoPoint(), "Home", "Home");
171-
// overlay = new PlaceItemizedOverlay(getResources().getDrawable(R.drawable.home));
172-
// overlay.addOverlay(overlayitem);
173-
174234

175-
new AlertDialog.Builder(this).setMessage("Add Place?").setIcon(R.drawable.location)
176-
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
177-
public void onClick(DialogInterface dialog, int which) {
178-
179-
switch (REQUEST_ID) {
180-
case ContextConstants.SET_HOME_REQUEST:
181-
DerivedMonitor.Home = new FloatingPointGeoPoint(point.getLatitude(), point.getLongitude());
182-
Toast.makeText(getApplicationContext(), "Home Updated\nLat:" + point.getLatitude() +
183-
"\nLon:" + point.getLongitude()+ "\n Press Back to Exit", Toast.LENGTH_LONG).show();
184-
break;
185-
case ContextConstants.SET_WORK_REQUEST:
186-
187-
DerivedMonitor.Work = new FloatingPointGeoPoint(point.getLatitude(), point.getLongitude());
188-
Toast.makeText(getApplicationContext(), "Work Updated\nLat:" + point.getLatitude() +
189-
"\nLon:" + point.getLongitude() + "\n Press Back to Exit", Toast.LENGTH_LONG).show();
190-
break;
191-
default:
192-
break;
193-
}
194-
195-
}
196-
}).setNegativeButton("No", new DialogInterface.OnClickListener() {
197-
public void onClick(DialogInterface dialog, int which) {
198-
// Do nothing, just let another destination be
199-
// chosen.
200-
}
201-
}).show();
235+
// List<Overlay> mapOverlays = map.getOverlays();
236+
// mapOverlays.add(new PlaceOverlay(this));
237+
// OverlayItem overlayitem = new OverlayItem(point.getGeoPoint(),
238+
// "Home", "Home");
239+
// overlay = new
240+
// PlaceItemizedOverlay(getResources().getDrawable(R.drawable.home));
241+
// overlay.addOverlay(overlayitem);
242+
243+
new AlertDialog.Builder(this).setMessage("Add Place?").setIcon(R.drawable.location).setPositiveButton("Yes", new DialogInterface.OnClickListener() {
244+
public void onClick(DialogInterface dialog, int which) {
245+
246+
switch (REQUEST_ID) {
247+
case ContextConstants.SET_HOME_REQUEST:
248+
DerivedMonitor.Home = new FloatingPointGeoPoint(point.getLatitude(), point.getLongitude());
249+
Toast.makeText(getApplicationContext(),
250+
"Home Updated\nLat:" + point.getLatitude() + "\nLon:" + point.getLongitude() + "\n Press Back to Exit", Toast.LENGTH_LONG).show();
251+
break;
252+
case ContextConstants.SET_WORK_REQUEST:
253+
254+
DerivedMonitor.Work = new FloatingPointGeoPoint(point.getLatitude(), point.getLongitude());
255+
Toast.makeText(getApplicationContext(),
256+
"Work Updated\nLat:" + point.getLatitude() + "\nLon:" + point.getLongitude() + "\n Press Back to Exit", Toast.LENGTH_LONG).show();
257+
break;
258+
default:
259+
break;
260+
}
261+
262+
map.invalidate();
263+
createOverlay();
264+
265+
}
266+
}).setNegativeButton("No", new DialogInterface.OnClickListener() {
267+
public void onClick(DialogInterface dialog, int which) {
268+
// Do nothing, just let another destination be chosen.
269+
}
270+
}).show();
271+
}
272+
273+
@Override
274+
public boolean onCreateOptionsMenu(Menu menu) {
275+
int base = Menu.FIRST;
276+
/* define the first */
277+
MenuItem item1 = menu.add(base, base, base, "Map");
278+
MenuItem item2 = menu.add(base, base + 1, base + 1, "Satellite");
279+
MenuItem item3 = menu.add(base, base + 2, base + 2, "My Location");
280+
MenuItem item4 = menu.add(base, base + 3, base + 3, "Return");
281+
282+
/* assign icons to the menu items */
283+
item1.setIcon(android.R.drawable.ic_menu_gallery);
284+
item2.setIcon(android.R.drawable.ic_menu_mapmode);
285+
item3.setIcon(android.R.drawable.ic_menu_mylocation);
286+
item4.setIcon(android.R.drawable.ic_menu_close_clear_cancel);
287+
288+
return true;
289+
}
290+
291+
@Override
292+
public boolean onOptionsItemSelected(MenuItem item) {
293+
switch (item.getItemId()) {
294+
/* Satellite View */
295+
case 1:
296+
map.setSatellite(false);
297+
break;
298+
/* street View */
299+
case 2:
300+
map.setSatellite(true);
301+
break;
302+
/* go to users location */
303+
case 3:
304+
if (currentLocation != null) {
305+
update(currentLocation);
306+
}
307+
break;
308+
/* List View */
309+
case 4:
310+
finish();
311+
break;
312+
}
313+
return true;
202314
}
203-
204315

205316
}

0 commit comments

Comments
 (0)