I'm trying to use Picasso now for my Custom Marker's Images. I was previously using a Bitmap and setting individual Marker's InfoWindow Images with those Bitmaps with the help of a HashMap. But I like how Picasso will cache the Images for me and helps scale them etc.
public class HomeActivity extends FragmentActivity implements OnMapReadyCallback, LocationListener, GoogleMap.OnMapLongClickListener, DetailsDialog.DialogListener, PictureDialog.FinishedMemorySaving {
private GoogleMap mMap;
private LocationManager locationManager;
private Location location;
private String provider, title, desc;
private LatLng latlng;
private Memory memory;
private FragmentManager fm;
private HashMap<String, Memory> markers;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
markers = new HashMap<>();
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
provider = locationManager.getBestProvider(new Criteria(), false);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
location = locationManager.getLastKnownLocation(provider);
locationManager.requestLocationUpdates(provider, 400, 1, this);
if(location != null){
Log.i("App Info", "Location found");
} else {
Log.i("App Info", "Location not found");
}
}
//.....OTHER METHODS WORKING DELETED NOT NEEDED FOR THIS.....
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker marker) {
return null;
}
@Override
public View getInfoContents(Marker marker) {
View view = getLayoutInflater().inflate(R.layout.marker_layout, null);
Bitmap bit = null;
ImageView markerImage = (ImageView)view.findViewById(R.id.markerImage);
TextView markerTitle = (TextView)view.findViewById(R.id.markerTitle);
TextView markerDate = (TextView)view.findViewById(R.id.markerDate);
if(markers != null && markers.size() > 0){
// ADDED THE CALLBACK ALONG WITH MARKER
Picasso.with(getApplicationContext())
.load(markers.get(marker.getId()).getImageMem())
.centerInside()
.fit()
.into(markerImage, new MarkerCallback(marker));
markerTitle.setText(markers.get(marker.getId()).getTitleMem());
markerDate.setText(markers.get(marker.getId()).getFormatedDate());
}
return view;
}
});
}
public void setImages(String markerID, View view){
Log.i("PATH TESTER 2", markers.get(markerID).getImageMem());
}
@Override
public void showMemory(Memory memory) {
String markerID;
Toast.makeText(getApplicationContext(), "The Minions have saved your Memory!", Toast.LENGTH_SHORT).show();
markerID = mMap.addMarker(new MarkerOptions().title(memory.getTitleMem()).position(memory.getLocationMem())).getId();
Log.i("PATH TESTER", memory.getImageMem());
markers.put(markerID, memory);
mMap.moveCamera(CameraUpdateFactory.newLatLng(memory.getLocationMem()));
}
public class MarkerCallback implements Callback {
Marker marker=null;
MarkerCallback(Marker marker) {
this.marker=marker;
}
@Override
public void onError() {
Log.e(getClass().getSimpleName(), "Error loading thumbnail!");
}
@Override
public void onSuccess() {
if (marker != null && marker.isInfoWindowShown()) {
marker.hideInfoWindow();
marker.showInfoWindow();
}
}
}
}
Is there something I'm not doing right? The path is coming through fine and is correct. I've also set an ImageView in a dialog with the same path and it worked. Thanks for any help given.
EDIT:
I now seem to be getting the Error coming up that results in the MarkerCallBack when ever I click on the marker. It doesn't seem to set the actual Image on the marker though :/. Hope someone can help!