use of com.google.android.gms.maps.model.VisibleRegion in project iNaturalistAndroid by inaturalist.
the class ExploreActivity method onSaveInstanceState.
@Override
protected void onSaveInstanceState(Bundle outState) {
outState.putInt("mActiveViewType", mActiveViewType);
outState.putIntArray("mTotalResults", mTotalResults);
outState.putInt("mObservationsViewMode", mObservationsViewMode);
outState.putIntArray("mCurrentResultsPage", mCurrentResultsPage);
outState.putBooleanArray("mLoadingNextResults", mLoadingNextResults);
outState.putInt("mObservationsMapType", mObservationsMapType);
outState.putBoolean("mMapMoved", mMapMoved);
outState.putSerializable("mSearchFilters", mSearchFilters);
mHelper.saveListToBundle(outState, mResults[VIEW_TYPE_OBSERVATIONS], "mObservations");
mHelper.saveListToBundle(outState, mResults[VIEW_TYPE_SPECIES], "mSpecies");
mHelper.saveListToBundle(outState, mResults[VIEW_TYPE_OBSERVERS], "mObservers");
mHelper.saveListToBundle(outState, mResults[VIEW_TYPE_IDENTIFIERS], "mIdentifiers");
saveListViewOffset(mObservationsGrid, outState, "mList" + VIEW_TYPE_OBSERVATIONS);
saveListViewOffset(mList[VIEW_TYPE_SPECIES], outState, "mList" + VIEW_TYPE_SPECIES);
saveListViewOffset(mList[VIEW_TYPE_OBSERVERS], outState, "mList" + VIEW_TYPE_OBSERVERS);
saveListViewOffset(mList[VIEW_TYPE_IDENTIFIERS], outState, "mList" + VIEW_TYPE_IDENTIFIERS);
if (mObservationsMap != null) {
VisibleRegion vr = mObservationsMap.getProjection().getVisibleRegion();
outState.putParcelable("mapRegion", vr);
}
super.onSaveInstanceState(outState);
}
use of com.google.android.gms.maps.model.VisibleRegion 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.VisibleRegion in project iNaturalistAndroid by inaturalist.
the class ExploreActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActionBar actionBar = getSupportActionBar();
actionBar.setElevation(0);
actionBar.setCustomView(R.layout.explore_action_bar_new);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.getCustomView().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(ExploreActivity.this, ExploreSearchActivity.class);
intent.putExtra(ExploreSearchActivity.SEARCH_FILTERS, mSearchFilters);
startActivityForResult(intent, SEARCH_REQUEST_CODE);
}
});
mHelper = new ActivityHelper(this);
setContentView(R.layout.explore);
if (savedInstanceState == null) {
mActiveViewType = VIEW_TYPE_OBSERVATIONS;
mTotalResults = new int[] { NOT_LOADED, NOT_LOADED, NOT_LOADED, NOT_LOADED };
mResults = (List<JSONObject>[]) new List[] { null, null, null, null };
mSearchFilters = new ExploreSearchFilters();
mLastMapBounds = null;
} else {
mActiveViewType = savedInstanceState.getInt("mActiveViewType");
mTotalResults = savedInstanceState.getIntArray("mTotalResults");
mObservationsViewMode = savedInstanceState.getInt("mObservationsViewMode");
mSearchFilters = (ExploreSearchFilters) savedInstanceState.getSerializable("mSearchFilters");
mCurrentResultsPage = savedInstanceState.getIntArray("mCurrentResultsPage");
mLoadingNextResults = savedInstanceState.getBooleanArray("mLoadingNextResults");
mObservationsMapType = savedInstanceState.getInt("mObservationsMapType", GoogleMap.MAP_TYPE_TERRAIN);
mMapMoved = savedInstanceState.getBoolean("mMapMoved");
mResults = (List<JSONObject>[]) new List[] { null, null, null, null };
mResults[VIEW_TYPE_OBSERVATIONS] = mHelper.loadListFromBundle(savedInstanceState, "mObservations");
mResults[VIEW_TYPE_SPECIES] = mHelper.loadListFromBundle(savedInstanceState, "mSpecies");
mResults[VIEW_TYPE_OBSERVERS] = mHelper.loadListFromBundle(savedInstanceState, "mObservers");
mResults[VIEW_TYPE_IDENTIFIERS] = mHelper.loadListFromBundle(savedInstanceState, "mIdentifiers");
for (int i = 0; i < mResults.length; i++) {
mListViewIndex.put("mList" + i, savedInstanceState.getInt("mList" + i + "Index"));
mListViewOffset.put("mList" + i, savedInstanceState.getInt("mList" + i + "Offset"));
}
VisibleRegion vr = savedInstanceState.getParcelable("mapRegion");
mLastMapBounds = new LatLngBounds(new LatLng(vr.nearLeft.latitude, vr.farLeft.longitude), new LatLng(vr.farRight.latitude, vr.farRight.longitude));
}
onDrawerCreate(savedInstanceState);
// Tab Initialization
initializeTabs();
}
Aggregations