use of com.google.android.gms.maps.model.UrlTileProvider in project iNaturalistAndroid by inaturalist.
the class TaxonActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
requestWindowFeature(Window.FEATURE_PROGRESS);
super.onCreate(savedInstanceState);
final ActionBar actionBar = getSupportActionBar();
mApp = (INaturalistApp) getApplicationContext();
mHelper = new ActivityHelper(this);
Intent intent = getIntent();
if (savedInstanceState == null) {
mTaxon = (BetterJSONObject) intent.getSerializableExtra(TAXON);
mObservation = (BetterJSONObject) intent.getSerializableExtra(OBSERVATION);
mDownloadTaxon = intent.getBooleanExtra(DOWNLOAD_TAXON, false);
mTaxonSuggestion = intent.getIntExtra(TAXON_SUGGESTION, TAXON_SUGGESTION_NONE);
mMapBoundsSet = false;
mIsTaxonomyListExpanded = false;
} else {
mTaxon = (BetterJSONObject) savedInstanceState.getSerializable(TAXON);
mObservation = (BetterJSONObject) savedInstanceState.getSerializable(OBSERVATION);
mDownloadTaxon = savedInstanceState.getBoolean(DOWNLOAD_TAXON);
mMapBoundsSet = savedInstanceState.getBoolean("mMapBoundsSet");
mTaxonSuggestion = savedInstanceState.getInt(TAXON_SUGGESTION);
mIsTaxonomyListExpanded = savedInstanceState.getBoolean("mIsTaxonomyListExpanded");
}
setContentView(R.layout.taxon_page);
mScrollView = (ScrollView) findViewById(R.id.scroll_view);
mPhotosContainer = (ViewGroup) findViewById(R.id.taxon_photos_container);
mNoPhotosContainer = (ViewGroup) findViewById(R.id.no_taxon_photos_container);
mPhotosViewPager = (HackyViewPager) findViewById(R.id.taxon_photos);
mPhotosIndicator = (CirclePageIndicator) findViewById(R.id.photos_indicator);
mTaxonName = (TextView) findViewById(R.id.taxon_name);
mTaxonScientificName = (TextView) findViewById(R.id.taxon_scientific_name);
mWikipediaSummary = (TextView) findViewById(R.id.wikipedia_summary);
mConservationStatusContainer = (ViewGroup) findViewById(R.id.conservation_status_container);
mConservationStatus = (TextView) findViewById(R.id.conservation_status);
mConservationSource = (TextView) findViewById(R.id.conservation_source);
((ScrollableMapFragment) getSupportFragmentManager().findFragmentById(R.id.observations_map)).getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.setMyLocationEnabled(false);
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
mMap.getUiSettings().setAllGesturesEnabled(false);
mMap.getUiSettings().setZoomControlsEnabled(false);
// Set the tile overlay (for the taxon's observations map)
TileProvider tileProvider = new UrlTileProvider(512, 512) {
@Override
public URL getTileUrl(int x, int y, int zoom) {
String s = String.format(INaturalistService.API_HOST + "/colored_heatmap/%d/%d/%d.png?taxon_id=%d", zoom, x, y, mTaxon.getInt("id"));
try {
return new URL(s);
} catch (MalformedURLException e) {
throw new AssertionError(e);
}
}
};
TileOverlay tileOverlay = mMap.addTileOverlay(new TileOverlayOptions().tileProvider(tileProvider));
mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
@Override
public void onMapClick(LatLng latLng) {
Intent intent = new Intent(TaxonActivity.this, TaxonMapActivity.class);
intent.putExtra(TaxonMapActivity.TAXON_ID, mTaxon.getInt("id"));
intent.putExtra(TaxonMapActivity.TAXON_NAME, actionBar.getTitle());
CameraPosition position = mMap.getCameraPosition();
intent.putExtra(TaxonMapActivity.MAP_LATITUDE, position.target.latitude);
intent.putExtra(TaxonMapActivity.MAP_LONGITUDE, position.target.longitude);
intent.putExtra(TaxonMapActivity.MAP_ZOOM, position.zoom);
intent.putExtra(TaxonMapActivity.OBSERVATION, mObservation);
startActivity(intent);
}
});
}
});
mViewOnINat = (ViewGroup) findViewById(R.id.view_on_inat);
mLoadingPhotos = (ProgressBar) findViewById(R.id.loading_photos);
mTaxonButtons = (ViewGroup) findViewById(R.id.taxon_buttons);
mSelectTaxon = (ViewGroup) findViewById(R.id.select_taxon);
mCompareTaxon = (ViewGroup) findViewById(R.id.compare_taxon);
mTaxonicIcon = (ImageView) findViewById(R.id.taxon_iconic_taxon);
mTaxonInactive = (ViewGroup) findViewById(R.id.taxon_inactive);
mTaxonButtons.setVisibility(mTaxonSuggestion != TAXON_SUGGESTION_NONE ? View.VISIBLE : View.GONE);
mSelectTaxon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Taxon selected - return that taxon back
Intent intent = new Intent();
Bundle bundle = new Bundle();
JSONObject taxon = mTaxon.getJSONObject();
bundle.putString(TaxonSearchActivity.ID_NAME, TaxonUtils.getTaxonName(TaxonActivity.this, taxon));
bundle.putString(TaxonSearchActivity.TAXON_NAME, taxon.optString("name"));
bundle.putString(TaxonSearchActivity.ICONIC_TAXON_NAME, taxon.optString("iconic_taxon_name"));
if (taxon.has("default_photo") && !taxon.isNull("default_photo"))
bundle.putString(TaxonSearchActivity.ID_PIC_URL, taxon.optJSONObject("default_photo").optString("square_url"));
bundle.putBoolean(TaxonSearchActivity.IS_CUSTOM, false);
bundle.putInt(TaxonSearchActivity.TAXON_ID, taxon.optInt("id"));
intent.putExtras(bundle);
setResult(RESULT_OK, intent);
finish();
}
});
mCompareTaxon.setVisibility(mTaxonSuggestion == TAXON_SUGGESTION_COMPARE_AND_SELECT ? View.VISIBLE : View.GONE);
mCompareTaxon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Show taxon comparison screen - we do this by indicating the calling activity (TaxonSuggestions/CompareSuggestions)
// that the user select this taxon for comparison
Intent intent = new Intent();
setResult(RESULT_COMPARE_TAXON, intent);
finish();
}
});
mViewOnINat.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String inatNetwork = mApp.getInaturalistNetworkMember();
String inatHost = mApp.getStringResourceByName("inat_host_" + inatNetwork);
Locale deviceLocale = getResources().getConfiguration().locale;
String deviceLanguage = deviceLocale.getLanguage();
String taxonUrl = String.format("%s/taxa/%d?locale=%s", inatHost, mTaxon.getInt("id"), deviceLanguage);
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(taxonUrl));
startActivity(i);
}
});
mTaxonomyIcon = (ImageView) findViewById(R.id.taxonomy_info);
mTaxonomyList = (ListView) findViewById(R.id.taxonomy_list);
mTaxonomyIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mHelper.confirm(getString(R.string.about_this_section), getString(R.string.taxonomy_info), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}, null, R.string.got_it, 0);
}
});
// Make sure the user will be able to scroll/zoom the map (since it's inside a ScrollView)
((ScrollableMapFragment) getSupportFragmentManager().findFragmentById(R.id.observations_map)).setListener(new ScrollableMapFragment.OnTouchListener() {
@Override
public void onTouch() {
mScrollView.requestDisallowInterceptTouchEvent(true);
}
});
actionBar.setHomeButtonEnabled(true);
actionBar.setLogo(R.drawable.ic_arrow_back);
actionBar.setDisplayHomeAsUpEnabled(true);
loadTaxon();
}
use of com.google.android.gms.maps.model.UrlTileProvider in project iNaturalistAndroid by inaturalist.
the class TaxonMapActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
requestWindowFeature(Window.FEATURE_PROGRESS);
super.onCreate(savedInstanceState);
ActionBar actionBar = getSupportActionBar();
mApp = (INaturalistApp) getApplicationContext();
mHelper = new ActivityHelper(this);
Intent intent = getIntent();
if (savedInstanceState == null) {
mTaxonId = intent.getIntExtra(TAXON_ID, 0);
mTaxonName = intent.getStringExtra(TAXON_NAME);
mMapLongitude = intent.getDoubleExtra(MAP_LONGITUDE, 0);
mMapLatitude = intent.getDoubleExtra(MAP_LATITUDE, 0);
mMapZoom = intent.getFloatExtra(MAP_ZOOM, 0);
mObservation = (BetterJSONObject) intent.getSerializableExtra(OBSERVATION);
} else {
mTaxonId = savedInstanceState.getInt(TAXON_ID);
mTaxonName = savedInstanceState.getString(TAXON_NAME);
mMapLongitude = savedInstanceState.getDouble(MAP_LONGITUDE, 0);
mMapLatitude = savedInstanceState.getDouble(MAP_LATITUDE, 0);
mMapZoom = savedInstanceState.getFloat(MAP_ZOOM, 0);
mObservation = (BetterJSONObject) savedInstanceState.getSerializable(OBSERVATION);
}
setContentView(R.layout.taxon_map);
((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.observations_map)).getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.setMyLocationEnabled(true);
mMap.getUiSettings().setZoomControlsEnabled(true);
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
// Set the tile overlay (for the taxon's observations map)
TileProvider tileProvider = new UrlTileProvider(256, 256) {
@Override
public URL getTileUrl(int x, int y, int zoom) {
String s = String.format(INaturalistService.API_HOST + "/colored_heatmap/%d/%d/%d.png?taxon_id=%d", zoom, x, y, mTaxonId);
try {
return new URL(s);
} catch (MalformedURLException e) {
throw new AssertionError(e);
}
}
};
TileOverlay tileOverlay = mMap.addTileOverlay(new TileOverlayOptions().tileProvider(tileProvider));
if (mObservation != null) {
boolean markerOnly = false;
boolean updateCamera = false;
final Observation obs = new Observation(mObservation);
mHelper.addMapPosition(mMap, obs, mObservation, markerOnly, updateCamera);
mHelper.centerObservationImmediate(mMap, obs);
}
}
});
actionBar.setHomeButtonEnabled(true);
actionBar.setLogo(R.drawable.ic_arrow_back);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle(mTaxonName);
}
use of com.google.android.gms.maps.model.UrlTileProvider in project iNaturalistAndroid by inaturalist.
the class ExploreActivity method refreshObservations.
private void refreshObservations() {
if (mLoadingObservationsGrid == null) {
// View hasn't loaded yet
return;
}
refreshFilterBar(mObservationsGridFilterBar);
refreshFilterBar(mObservationsMapFilterBar);
mObservationsGrid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View view, int position, long arg3) {
JSONObject item = (JSONObject) view.getTag();
Intent intent = new Intent(ExploreActivity.this, ObservationViewerActivity.class);
intent.putExtra("observation", item.toString());
intent.putExtra("read_only", true);
intent.putExtra("reload", true);
startActivityForResult(intent, VIEW_OBSERVATION_REQUEST_CODE);
try {
JSONObject eventParams = new JSONObject();
eventParams.put(AnalyticsClient.EVENT_PARAM_VIA, AnalyticsClient.EVENT_VALUE_EXPLORE_GRID);
AnalyticsClient.getInstance().logEvent(AnalyticsClient.EVENT_NAME_NAVIGATE_OBS_DETAILS, eventParams);
} catch (JSONException e) {
e.printStackTrace();
}
}
});
if (mTotalResults[VIEW_TYPE_OBSERVATIONS] == NOT_LOADED) {
if (mObservationsViewMode == OBSERVATIONS_VIEW_MODE_GRID) {
mLoadingObservationsGrid.setVisibility(View.VISIBLE);
} else {
mLoadingObservationsGrid.setVisibility(View.GONE);
}
mObservationsGrid.setVisibility(View.GONE);
mObservationsGridEmpty.setVisibility(View.GONE);
mObservationsMapContainer.setVisibility(View.GONE);
} else {
mLoadingObservationsGrid.setVisibility(View.GONE);
if (mResults[VIEW_TYPE_OBSERVATIONS].size() == 0) {
mObservationsGridEmpty.setVisibility(View.VISIBLE);
} else {
mObservationsGridEmpty.setVisibility(View.GONE);
}
Runnable setObsInGrid = new Runnable() {
@Override
public void run() {
if ((mGridAdapter != null) && (mCurrentResultsPage[VIEW_TYPE_OBSERVATIONS] > 1)) {
// New results appended - don't reload the entire adapter
mGridAdapter.notifyDataSetChanged();
} else if (mObservationsGrid.getColumnWidth() > 0) {
mGridAdapter = new ObservationGridAdapter(ExploreActivity.this, mObservationsGrid.getColumnWidth(), mResults[VIEW_TYPE_OBSERVATIONS]);
mObservationsGrid.setAdapter(mGridAdapter);
} else if (mObservationsGrid.getColumnWidth() == 0) {
mObservationsGrid.postDelayed(this, 100);
}
}
};
mObservationsGrid.post(setObsInGrid);
mObservationsGrid.setVisibility(View.VISIBLE);
}
loadListViewOffset(mObservationsGrid, getIntent().getExtras(), "mList" + VIEW_TYPE_OBSERVATIONS);
mObservationsGrid.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if ((firstVisibleItem + visibleItemCount >= totalItemCount - 9) && (totalItemCount > 0)) {
// The end has been reached - load more observations
loadNextResultsPage(VIEW_TYPE_OBSERVATIONS, false);
}
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
});
if (mObservationsViewMode == OBSERVATIONS_VIEW_MODE_GRID) {
mObservationsViewModeGrid.setSelected(true);
mObservationsViewModeGrid.setColorFilter(Color.parseColor("#ffffff"));
mObservationsViewModeMap.setSelected(false);
mObservationsViewModeMap.setColorFilter(Color.parseColor("#676767"));
mLoadingObservationsGrid.setVisibility(View.VISIBLE);
mObservationsMapContainer.setVisibility(View.GONE);
} else {
mObservationsViewModeGrid.setSelected(false);
mObservationsViewModeGrid.setColorFilter(Color.parseColor("#676767"));
mObservationsViewModeMap.setSelected(true);
mObservationsViewModeMap.setColorFilter(Color.parseColor("#ffffff"));
mLoadingObservationsGrid.setVisibility(View.GONE);
mObservationsMapContainer.setVisibility(View.VISIBLE);
mMapHide.setVisibility(View.GONE);
mObservationsGrid.setVisibility(View.GONE);
mObservationsGridEmpty.setVisibility(View.GONE);
}
mObservationsViewModeGrid.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mObservationsViewMode = OBSERVATIONS_VIEW_MODE_GRID;
refreshObservations();
}
});
mObservationsViewModeMap.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mObservationsViewMode = OBSERVATIONS_VIEW_MODE_MAP;
refreshObservations();
}
});
mObservationsChangeMapLayers.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mObservationsMapType == GoogleMap.MAP_TYPE_SATELLITE) {
mObservationsMapType = GoogleMap.MAP_TYPE_TERRAIN;
} else {
mObservationsMapType = GoogleMap.MAP_TYPE_SATELLITE;
}
refreshMapType();
}
});
refreshMapType();
mRedoObservationsSearch.setVisibility(mMapMoved ? View.VISIBLE : View.GONE);
mPerformingSearch.setVisibility(mLoadingNextResults[VIEW_TYPE_OBSERVATIONS] ? View.VISIBLE : View.GONE);
mRedoObservationSearchIcon.setVisibility(mLoadingNextResults[VIEW_TYPE_OBSERVATIONS] ? View.GONE : View.VISIBLE);
mRedoObservationsSearchText.setTextColor(mLoadingNextResults[VIEW_TYPE_OBSERVATIONS] ? Color.parseColor("#8A000000") : Color.parseColor("#000000"));
mRedoObservationsSearch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Re-search under the current map bounds
VisibleRegion vr = mObservationsMap.getProjection().getVisibleRegion();
LatLngBounds bounds = new LatLngBounds(new LatLng(vr.nearLeft.latitude, vr.farLeft.longitude), new LatLng(vr.farRight.latitude, vr.farRight.longitude));
mSearchFilters.mapBounds = bounds;
// Clear out the place (search by map bounds only)
mSearchFilters.place = null;
if ((mLastMapBounds != null) && (mInitialLocationBounds != null) && (mLastMapBounds.equals(mInitialLocationBounds) == true)) {
mSearchFilters.isCurrentLocation = true;
} else {
mSearchFilters.isCurrentLocation = false;
}
resetResults(true);
loadAllResults();
mPerformingSearch.setVisibility(View.VISIBLE);
mRedoObservationSearchIcon.setVisibility(View.GONE);
mRedoObservationsSearchText.setTextColor(Color.parseColor("#8A000000"));
}
});
if (mSearchFilters.place != null) {
// Show the boundaries/border of the place on the map
addPlaceLayerToMap(mSearchFilters.place);
}
// Set the tile overlay (for the taxon's observations map)
TileProvider tileProvider = new UrlTileProvider(256, 256) {
@Override
public URL getTileUrl(int x, int y, int zoom) {
String s = String.format(INaturalistService.API_HOST + "/%s/%d/%d/%d.png?%s", zoom <= 9 ? "colored_heatmap" : "points", zoom, x, y, mSearchFilters.toUrlQueryString());
try {
return new URL(s);
} catch (MalformedURLException e) {
throw new AssertionError(e);
}
}
};
if (mObservationsMap != null) {
TileOverlay tileOverlay = mObservationsMap.addTileOverlay(new TileOverlayOptions().tileProvider(tileProvider));
}
}
use of com.google.android.gms.maps.model.UrlTileProvider in project android-samples by googlemaps.
the class TileOverlayDemoActivity method onMapReady.
@Override
public void onMapReady(GoogleMap map) {
map.setMapType(GoogleMap.MAP_TYPE_NONE);
TileProvider tileProvider = new UrlTileProvider(256, 256) {
@Override
public synchronized URL getTileUrl(int x, int y, int zoom) {
// The moon tile coordinate system is reversed. This is not normal.
int reversedY = (1 << zoom) - y - 1;
String s = String.format(Locale.US, MOON_MAP_URL_FORMAT, zoom, x, reversedY);
URL url = null;
try {
url = new URL(s);
} catch (MalformedURLException e) {
throw new AssertionError(e);
}
return url;
}
};
mMoonTiles = map.addTileOverlay(new TileOverlayOptions().tileProvider(tileProvider));
mTransparencyBar.setOnSeekBarChangeListener(this);
}
Aggregations