Search in sources :

Example 1 with VisibleRegion

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);
}
Also used : VisibleRegion(com.google.android.gms.maps.model.VisibleRegion)

Example 2 with VisibleRegion

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));
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) UrlTileProvider(com.google.android.gms.maps.model.UrlTileProvider) TileProvider(com.google.android.gms.maps.model.TileProvider) URL(java.net.URL) VisibleRegion(com.google.android.gms.maps.model.VisibleRegion) UrlTileProvider(com.google.android.gms.maps.model.UrlTileProvider) LatLng(com.google.android.gms.maps.model.LatLng) TileOverlayOptions(com.google.android.gms.maps.model.TileOverlayOptions) LatLngBounds(com.google.android.gms.maps.model.LatLngBounds) JSONException(org.json.JSONException) AbsListView(android.widget.AbsListView) Intent(android.content.Intent) GridView(android.widget.GridView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) Point(android.graphics.Point) TileOverlay(com.google.android.gms.maps.model.TileOverlay) JSONObject(org.json.JSONObject) AdapterView(android.widget.AdapterView)

Example 3 with VisibleRegion

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();
}
Also used : LatLngBounds(com.google.android.gms.maps.model.LatLngBounds) Intent(android.content.Intent) GridView(android.widget.GridView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) Point(android.graphics.Point) VisibleRegion(com.google.android.gms.maps.model.VisibleRegion) List(java.util.List) ArrayList(java.util.ArrayList) LatLng(com.google.android.gms.maps.model.LatLng) ActionBar(android.support.v7.app.ActionBar)

Aggregations

VisibleRegion (com.google.android.gms.maps.model.VisibleRegion)3 Intent (android.content.Intent)2 Point (android.graphics.Point)2 View (android.view.View)2 AbsListView (android.widget.AbsListView)2 AdapterView (android.widget.AdapterView)2 GridView (android.widget.GridView)2 ImageView (android.widget.ImageView)2 ListView (android.widget.ListView)2 TextView (android.widget.TextView)2 LatLng (com.google.android.gms.maps.model.LatLng)2 LatLngBounds (com.google.android.gms.maps.model.LatLngBounds)2 ActionBar (android.support.v7.app.ActionBar)1 TileOverlay (com.google.android.gms.maps.model.TileOverlay)1 TileOverlayOptions (com.google.android.gms.maps.model.TileOverlayOptions)1 TileProvider (com.google.android.gms.maps.model.TileProvider)1 UrlTileProvider (com.google.android.gms.maps.model.UrlTileProvider)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1