Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;

import java.util.Objects;

public abstract class BaseDemoActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
private boolean mIsRestore;
Expand Down Expand Up @@ -60,7 +62,7 @@ public void onMapReady(@NonNull GoogleMap map) {
}

private void setUpMap() {
((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMapAsync(this);
((SupportMapFragment) Objects.requireNonNull(getSupportFragmentManager().findFragmentById(R.id.map))).getMapAsync(this);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.content.Context;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.EditorInfo;
Expand Down Expand Up @@ -63,6 +64,9 @@ public class HeatmapsPlacesDemoActivity extends BaseDemoActivity {
private final String TAG = "HeatmapPlacesDemo";

private final LatLng SYDNEY = new LatLng(-33.873651, 151.2058896);
private final LatLng BOULDER = new LatLng(40.0216437819216, -105.25471683073081);

private final LatLng FOCUS = BOULDER;

/**
* The base URL for the radar search request.
Expand All @@ -78,27 +82,28 @@ public class HeatmapsPlacesDemoActivity extends BaseDemoActivity {
/**
* Places API server key.
*/
private static final String API_KEY = "YOUR_KEY_HERE"; // TODO place your own here!
private static final String API_KEY = BuildConfig.PLACES_API_KEY;

/**
* The colors to be used for the different heatmap layers.
*/
private static final int[] HEATMAP_COLORS = {
HeatmapColors.RED.color,
HeatmapColors.BLUE.color,
HeatmapColors.GREEN.color,
HeatmapColors.PINK.color,
HeatmapColors.GREY.color
HeatmapColors.RED.color,
HeatmapColors.BLUE.color,
HeatmapColors.GREEN.color,
HeatmapColors.PINK.color,
HeatmapColors.GREY.color
};

public enum HeatmapColors {
RED (Color.rgb(238, 44, 44)),
BLUE (Color.rgb(60, 80, 255)),
GREEN (Color.rgb(20, 170, 50)),
PINK (Color.rgb(255, 80, 255)),
GREY (Color.rgb(100, 100, 100));
RED(Color.rgb(238, 44, 44)),
BLUE(Color.rgb(60, 80, 255)),
GREEN(Color.rgb(20, 170, 50)),
PINK(Color.rgb(255, 80, 255)),
GREY(Color.rgb(100, 100, 100));

private final int color;

HeatmapColors(int color) {
this.color = color;
}
Expand All @@ -115,7 +120,7 @@ public enum HeatmapColors {
/**
* Stores the TileOverlay corresponding to each of the keywords that have been searched for.
*/
private Hashtable<String, TileOverlay> mOverlays = new Hashtable<String, TileOverlay>();
private final Hashtable<String, TileOverlay> mOverlays = new Hashtable<String, TileOverlay>();

/**
* A layout containing checkboxes for each of the heatmaps rendered.
Expand All @@ -132,6 +137,19 @@ public enum HeatmapColors {
*/
private int mOverlaysInput = 0;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if ("YOUR_API_KEY".equals(API_KEY)) {
Toast.makeText(
this,
"Please sign up for a Places API key and add it to HeatmapsPlacesDemoActivity.API_KEY",
Toast.LENGTH_LONG
).show();
finish();
}
}

@Override
protected int getLayoutId() {
return R.layout.places_demo;
Expand All @@ -152,11 +170,11 @@ protected void startDemo(boolean isRestore) {
mCheckboxLayout = findViewById(R.id.checkboxes);
GoogleMap map = getMap();
if (!isRestore) {
map.moveCamera(CameraUpdateFactory.newLatLngZoom(SYDNEY, 11));
map.moveCamera(CameraUpdateFactory.newLatLngZoom(FOCUS, 11));
}
// Add a circle around Sydney to roughly encompass the results
// Add a circle around FOCUS to roughly encompass the results
map.addCircle(new CircleOptions()
.center(SYDNEY)
.center(FOCUS)
.radius(SEARCH_RADIUS * 1.2)
.strokeColor(Color.RED)
.strokeWidth(4));
Expand All @@ -167,18 +185,13 @@ protected void startDemo(boolean isRestore) {
* Called when a search query is submitted
*/
public void submit(View view) {
if ("YOUR_KEY_HERE".equals(API_KEY)) {
Toast.makeText(this, "Please sign up for a Places API key and add it to HeatmapsPlacesDemoActivity.API_KEY",
Toast.LENGTH_LONG).show();
return;
}
EditText editText = findViewById(R.id.input_text);
String keyword = editText.getText().toString();
if (mOverlays.contains(keyword)) {
Toast.makeText(this, "This keyword has already been inputted :(", Toast.LENGTH_SHORT).show();
} else if (mOverlaysRendered == MAX_CHECKBOXES) {
Toast.makeText(this, "You can only input " + MAX_CHECKBOXES + " keywords. :(", Toast.LENGTH_SHORT).show();
} else if (keyword.length() != 0) {
} else if (!keyword.isEmpty()) {
mOverlaysInput++;
ProgressBar progressBar = findViewById(R.id.progress_bar);
progressBar.setVisibility(View.VISIBLE);
Expand All @@ -202,11 +215,11 @@ public void submit(View view) {
private Collection<LatLng> getPoints(String keyword) {
HashMap<String, LatLng> results = new HashMap<>();

// Calculate four equidistant points around Sydney to use as search centers
// Calculate four equidistant points around FOCUS to use as search centers
// so that four searches can be done.
ArrayList<LatLng> searchCenters = new ArrayList<>(4);
for (int heading = 45; heading < 360; heading += 90) {
searchCenters.add(SphericalUtil.computeOffset(SYDNEY, SEARCH_RADIUS / 2, heading));
searchCenters.add(SphericalUtil.computeOffset(FOCUS, (double) SEARCH_RADIUS / 2, heading));
}

for (int j = 0; j < 4; j++) {
Expand Down
193 changes: 0 additions & 193 deletions library/src/main/java/com/google/maps/android/heatmaps/Gradient.java

This file was deleted.

Loading