public static void showActivity(Activity context, SelectedItems selectedItems) { Uri initalUri = null; final Intent intent = new Intent().setClass(context, MapGeoPickerActivity.class); if ((selectedItems != null) && (selectedItems.size() > 0)) { intent.putExtra(EXTRA_SELECTED_ITEMS, selectedItems.toString()); IGeoPoint initialPoint = FotoSql.execGetPosition(context, selectedItems.first().intValue()); if (initialPoint != null) { GeoUri PARSER = new GeoUri(GeoUri.OPT_PARSE_INFER_MISSING); initalUri = Uri.parse( PARSER.toUriString( initialPoint.getLatitude(), initialPoint.getLongitude(), IGeoPointInfo.NO_ZOOM)); intent.setData(initalUri); } GalleryFilterParameter filter = new GalleryFilterParameter(); filter.setNonGeoOnly(true); intent.putExtra(EXTRA_FILTER, filter.toString()); } intent.setAction(Intent.ACTION_VIEW); if (Global.debugEnabled) { Log.d( Global.LOG_CONTEXT, context.getClass().getSimpleName() + " > MapGeoPickerActivity.showActivity@" + initalUri); } context.startActivity(intent); }
private GeoPointDto getGeoPointDtoFromIntent(Intent intent) { final Uri uri = (intent != null) ? intent.getData() : null; String uriAsString = (uri != null) ? uri.toString() : null; GeoPointDto pointFromIntent = null; if (uriAsString != null) { Toast.makeText( this, getString(R.string.app_name) + ": received " + uriAsString, Toast.LENGTH_LONG) .show(); pointFromIntent = (GeoPointDto) mGeoUriParser.fromUri(uriAsString, new GeoPointDto()); if (GeoPointDto.isEmpty(pointFromIntent)) pointFromIntent = null; } return pointFromIntent; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); Intent intent = this.getIntent(); GeoPointDto geoPointFromIntent = getGeoPointDtoFromIntent(intent); // no geo: from intent: use last used value mSaveLastUsedGeoToSharedPrefs = (geoPointFromIntent == null); String lastGeoUri = sharedPref.getString(STATE_LAST_GEO, "geo:53,8?z=6"); IGeoPointInfo lastGeo = mGeoUriParser.fromUri(lastGeoUri); if ((geoPointFromIntent != null) && (lastGeo != null)) { // apply default values if part is missing if (Double.isNaN(geoPointFromIntent.getLongitude())) geoPointFromIntent.setLongitude(lastGeo.getLongitude()); if (Double.isNaN(geoPointFromIntent.getLatitude())) geoPointFromIntent.setLatitude(lastGeo.getLatitude()); if (geoPointFromIntent.getZoomMin() == IGeoPointInfo.NO_ZOOM) geoPointFromIntent.setZoomMin(lastGeo.getZoomMin()); } IGeoPointInfo initalZoom = (mSaveLastUsedGeoToSharedPrefs) ? lastGeo : geoPointFromIntent; String extraTitle = intent.getStringExtra(EXTRA_TITLE); if (extraTitle == null && (geoPointFromIntent == null)) { extraTitle = getString(R.string.app_map_title); } if (extraTitle == null) { this.requestWindowFeature(Window.FEATURE_NO_TITLE); } setContentView(R.layout.activity_map_geo_picker); if (extraTitle != null) { this.setTitle(extraTitle); } else { setNoTitle(); } mMap = (PickerLocationMapFragment) getFragmentManager().findFragmentById(R.id.fragment_map); mMap.STATE_LAST_VIEWPORT = "ignore"; // do not use last viewport in settings GeoRectangle rectangle = null; int zoom = ZoomUtil.NO_ZOOM; if ((savedInstanceState == null) && (initalZoom != null)) { rectangle = new GeoRectangle(); zoom = initalZoom.getZoomMin(); rectangle.setLogituedMin(initalZoom.getLongitude()).setLatitudeMin(initalZoom.getLatitude()); rectangle.setLogituedMax(initalZoom.getLongitude()).setLatitudeMax(initalZoom.getLatitude()); } // else (savedInstanceState != null) restore after rotation. fragment takes care of restoring // map pos String selectedItemsString = intent.getStringExtra(EXTRA_SELECTED_ITEMS); SelectedItems selectedItems = (selectedItemsString != null) ? new SelectedItems().parse(selectedItemsString) : null; String filter = null; // for debugging: where does the filter come from String dbgFilter = null; if (intent != null) { filter = intent.getStringExtra(EXTRA_FILTER); } this.mSaveLastUsedFilterToSharedPrefs = (filter == null); // false if controlled via intent if (savedInstanceState != null) { filter = savedInstanceState.getString(STATE_Filter); if (filter != null) dbgFilter = "filter from savedInstanceState=" + filter; } if (this.mSaveLastUsedFilterToSharedPrefs) { filter = sharedPref.getString(STATE_Filter, null); if (filter != null) dbgFilter = "filter from sharedPref=" + filter; } this.mFilter = new GalleryFilterParameter(); if (filter != null) { GalleryFilterParameter.parse(filter, this.mFilter); } if (Global.debugEnabled) { Log.i(Global.LOG_CONTEXT, debugPrefix + dbgFilter + " => " + this.mFilter); } mMap.defineNavigation(this.mFilter, geoPointFromIntent, rectangle, zoom, selectedItems); }