From 6cd0a9c1bbbb25ee9d44ebcf9b96a6fc9be5554f Mon Sep 17 00:00:00 2001 From: DarkN3ss Date: Fri, 29 Jul 2016 10:27:11 +1200 Subject: [PATCH] Adds one radius circle around search location when search is finished (#317) --- .../pokemap/views/map/MapWrapperFragment.java | 197 ++++++++++-------- 1 file changed, 108 insertions(+), 89 deletions(-) diff --git a/app/src/main/java/com/omkarmoghe/pokemap/views/map/MapWrapperFragment.java b/app/src/main/java/com/omkarmoghe/pokemap/views/map/MapWrapperFragment.java index 582d6c88..866120de 100644 --- a/app/src/main/java/com/omkarmoghe/pokemap/views/map/MapWrapperFragment.java +++ b/app/src/main/java/com/omkarmoghe/pokemap/views/map/MapWrapperFragment.java @@ -312,18 +312,18 @@ private void updateMarkers() { int markerSize = getResources().getDimensionPixelSize(R.dimen.pokestop_marker); RemoteImageLoader.load( - pokestop.hasLurePokemon() ? lurePokeStopImageUrl : pokeStopImageUrl, - markerSize, markerSize, null, - getActivity(), - new RemoteImageLoader.Callback() { - @Override - public void onFetch(Bitmap bitmap) { - - BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(bitmap); - marker.setIcon(bitmapDescriptor); - marker.setZIndex(pokestop.hasLurePokemon() ? 1.0f : 0.5f); + pokestop.hasLurePokemon() ? lurePokeStopImageUrl : pokeStopImageUrl, + markerSize, markerSize, null, + getActivity(), + new RemoteImageLoader.Callback() { + @Override + public void onFetch(Bitmap bitmap) { + + BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(bitmap); + marker.setIcon(bitmapDescriptor); + marker.setZIndex(pokestop.hasLurePokemon() ? 1.0f : 0.5f); + } } - } ); } } else if (pokestopsList != null && !pokestopsList.isEmpty() && !mPref.getShowPokestops()) { @@ -345,17 +345,17 @@ public void onFetch(Bitmap bitmap) { int markerSize = getResources().getDimensionPixelSize(R.dimen.gym_marker); RemoteImageLoader.load( - gymTeamImageUrls.get(gym.getOwnedByTeam().getNumber()), - markerSize, markerSize, null, - getActivity(), - new RemoteImageLoader.Callback() { - @Override - public void onFetch(Bitmap bitmap) { - - BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(bitmap); - marker.setIcon(bitmapDescriptor); + gymTeamImageUrls.get(gym.getOwnedByTeam().getNumber()), + markerSize, markerSize, null, + getActivity(), + new RemoteImageLoader.Callback() { + @Override + public void onFetch(Bitmap bitmap) { + + BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(bitmap); + marker.setIcon(bitmapDescriptor); + } } - } ); } } else if(gymsList != null && !gymsList.isEmpty() && !mPref.getShowGyms()){ @@ -393,28 +393,28 @@ private void setPokestopsMarkers(final PokestopsEvent event) { if (!markerKeys.contains(pokestop.getId()) && distanceFromCenterInMeters <= MapHelper.convertStepsToRadius(mPref.getSteps())) { - RemoteImageLoader.load( - pokestop.hasLurePokemon() ? lurePokeStopImageUrl : pokeStopImageUrl, - markerSize, markerSize, null, - getActivity(), - new RemoteImageLoader.Callback() { - @Override - public void onFetch(Bitmap bitmap) { - - BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(bitmap); - - Marker marker = mGoogleMap.addMarker(new MarkerOptions() - .position(new LatLng(pokestop.getLatitude(), pokestop.getLongitude())) - .title(getString(R.string.pokestop)) - .icon(bitmapDescriptor) - .zIndex(MapHelper.LAYER_POKESTOPS) - .alpha(pokestop.hasLurePokemon() ? 1.0f : 0.5f) - .anchor(0.5f, 0.5f)); - - //adding pokemons to list to be removed on next search - pokestopsList.put(pokestop.getId(), new PokestopMarkerExtended(pokestop, marker)); + RemoteImageLoader.load( + pokestop.hasLurePokemon() ? lurePokeStopImageUrl : pokeStopImageUrl, + markerSize, markerSize, null, + getActivity(), + new RemoteImageLoader.Callback() { + @Override + public void onFetch(Bitmap bitmap) { + + BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(bitmap); + + Marker marker = mGoogleMap.addMarker(new MarkerOptions() + .position(new LatLng(pokestop.getLatitude(), pokestop.getLongitude())) + .title(getString(R.string.pokestop)) + .icon(bitmapDescriptor) + .zIndex(MapHelper.LAYER_POKESTOPS) + .alpha(pokestop.hasLurePokemon() ? 1.0f : 0.5f) + .anchor(0.5f, 0.5f)); + + //adding pokemons to list to be removed on next search + pokestopsList.put(pokestop.getId(), new PokestopMarkerExtended(pokestop, marker)); + } } - } ); } } @@ -443,26 +443,26 @@ private void setGymsMarkers(final GymsEvent event){ if (!markerKeys.contains(gym.getId()) && distanceFromCenterInMeters <= MapHelper.convertStepsToRadius(mPref.getSteps())) { RemoteImageLoader.load( - gymTeamImageUrls.get(gym.getOwnedByTeam().getNumber()), - markerSize, markerSize, null, - getActivity(), - new RemoteImageLoader.Callback() { - @Override - public void onFetch(Bitmap bitmap) { - - BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(bitmap); - - Marker marker = mGoogleMap.addMarker(new MarkerOptions() - .position(new LatLng(gym.getLatitude(), gym.getLongitude())) - .title(getString(R.string.gym)) - .icon(bitmapDescriptor) - .zIndex(MapHelper.LAYER_GYMS) - .anchor(0.5f, 0.5f)); - - // adding gyms to list to be removed on next search - gymsList.put(gym.getId(), new GymMarkerExtended(gym, marker)); + gymTeamImageUrls.get(gym.getOwnedByTeam().getNumber()), + markerSize, markerSize, null, + getActivity(), + new RemoteImageLoader.Callback() { + @Override + public void onFetch(Bitmap bitmap) { + + BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(bitmap); + + Marker marker = mGoogleMap.addMarker(new MarkerOptions() + .position(new LatLng(gym.getLatitude(), gym.getLongitude())) + .title(getString(R.string.gym)) + .icon(bitmapDescriptor) + .zIndex(MapHelper.LAYER_GYMS) + .anchor(0.5f, 0.5f)); + + // adding gyms to list to be removed on next search + gymsList.put(gym.getId(), new GymMarkerExtended(gym, marker)); + } } - } ); } } @@ -488,31 +488,31 @@ private void setPokemonMarkers(final List pokeList){ if (showablePokemonIDs.contains(pokemonId)) { RemoteImageLoader.load( - "http://serebii.net/pokemongo/pokemon/"+PokemonIdUtils.getCorrectPokemonImageId(pokemonId.getNumber())+".png", - markerSize, markerSize, null, - getActivity(), - new RemoteImageLoader.Callback() { - @Override - public void onFetch(Bitmap bitmap) { - - BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(bitmap); - - //Setting marker since we got image - //int resourceID = getResources().getIdentifier("p" + poke.getPokemonId().getNumber(), "drawable", getActivity().getPackageName()); - final Marker marker = mGoogleMap.addMarker(new MarkerOptions() - .position(new LatLng(poke.getLatitude(), poke.getLongitude())) - .title(PokemonIdUtils.getLocalePokemonName(getContext(), poke.getPokemonId().name())) - .icon(bitmapDescriptor) - .zIndex(MapHelper.LAYER_POKEMONS) - .anchor(0.5f, 0.5f)); - - //adding pokemons to list to be removed on next search - PokemonMarkerExtended markerExtended = new PokemonMarkerExtended(poke, marker); - markerList.put(poke.getSpawnPointId(), markerExtended); - MarkerRefreshController.getInstance().postMarker(markerExtended); - + "http://serebii.net/pokemongo/pokemon/"+PokemonIdUtils.getCorrectPokemonImageId(pokemonId.getNumber())+".png", + markerSize, markerSize, null, + getActivity(), + new RemoteImageLoader.Callback() { + @Override + public void onFetch(Bitmap bitmap) { + + BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(bitmap); + + //Setting marker since we got image + //int resourceID = getResources().getIdentifier("p" + poke.getPokemonId().getNumber(), "drawable", getActivity().getPackageName()); + final Marker marker = mGoogleMap.addMarker(new MarkerOptions() + .position(new LatLng(poke.getLatitude(), poke.getLongitude())) + .title(PokemonIdUtils.getLocalePokemonName(getContext(), poke.getPokemonId().name())) + .icon(bitmapDescriptor) + .zIndex(MapHelper.LAYER_POKEMONS) + .anchor(0.5f, 0.5f)); + + //adding pokemons to list to be removed on next search + PokemonMarkerExtended markerExtended = new PokemonMarkerExtended(poke, marker); + markerList.put(poke.getSpawnPointId(), markerExtended); + MarkerRefreshController.getInstance().postMarker(markerExtended); + + } } - } ); //Increase founded pokemon counter @@ -598,6 +598,25 @@ private String getExpirationBreakdown(long millis) { public void onEvent(CatchablePokemonEvent event) { setPokemonMarkers(event.getCatchablePokemon()); drawCatchedPokemonCircle(event.getLat(), event.getLongitude()); + if(nianticManager.getCurrentScan() == 1) { + currentCenter.setLatitude(event.getLat()); + currentCenter.setLongitude(event.getLongitude()); + } + if(nianticManager.getCurrentScan() == nianticManager.getPendingSearch()) + { + if (mGoogleMap != null) { + + if (mPref.getShowScannedPlaces()) { + double radiusInMeters = MapHelper.convertStepsToRadius(mPref.getSteps()); + int strokeColor = 0x44DC990D; // outline + int shadeColor = 0x44DCD90D; // fill + + CircleOptions circleOptions = new CircleOptions().center(new LatLng(currentCenter.getLatitude(), currentCenter.getLongitude())).radius(radiusInMeters).fillColor(shadeColor).strokeColor(strokeColor).strokeWidth(8); + clearPokemonCircles(); + userSelectedPositionCircles.add(mGoogleMap.addCircle(circleOptions)); + } + } + } } /** @@ -651,10 +670,10 @@ public void onEvent(GymsEvent event) { * @param event */ - @Subscribe(threadMode = ThreadMode.MAIN) - public void onEvent(MarkerExpired event){ - removeExpiredMarker(event.getData()); - } + @Subscribe(threadMode = ThreadMode.MAIN) + public void onEvent(MarkerExpired event){ + removeExpiredMarker(event.getData()); + } @Subscribe(threadMode = ThreadMode.MAIN) public void onEvent(MarkerUpdate event){