In my android app, I have a google maps v2 inside a fragment with marker of places. When I touch in a marker, it displays a RelativeLayout with the name of the marker. However, I would like that when I touch anywhere in the map, this RelativeLayout is hidden.
My code is this:
fragment_mapa.xml
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"
android:gravity="center" />
<RelativeLayout
android:id="#+id/sliding_up"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#fff"
android:orientation="vertical"
android:layout_alignParentBottom="true"
android:clickable="true"
android:focusable="false"
android:animateLayoutChanges="true"
android:visibility="invisible" >
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="14sp"
android:gravity="center_vertical"
android:paddingLeft="10dp"/>
</RelativeLayout>
Code where it creates the markers and onClick method to display the RelativeLayout
public void addItemsToMap() {
appState.mapa.clear();
if (appState.lista.isEmpty()) {
appState.readPlaces(5000, 0, appState.idCategoria);
}
appState.mapa.setOnMarkerClickListener(this);
appState.mapa.setOnInfoWindowClickListener(getInfoWindowClickListener());
LatLng miPosicion = new LatLng(obtLatitud, obtLongitud);
appState.mapa.addMarker(new MarkerOptions()
.position(miPosicion)
.title("Mi posición")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.location_icon)));
for (int i = 0; i < appState.lista.size(); i++) {
LatLng posItem = new LatLng(appState.lista.get(i).latitud,appState.lista.get(i).longitud);
appState.mapa.addMarker(new MarkerOptions()
.position(posItem)
.title(appState.lista.get(i).nombre)
.snippet(appState.lista.get(i).descripcion)
/*.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher))*/);
Log.v("MAPA", "Marker " + i + ": " + appState.lista.get(i).nombre);
}
}
#Override
public boolean onMarkerClick(final Marker marker) {
if(marker != null) {
//marker.showInfoWindow();
RelativeLayout slideLayout;
slideLayout = (RelativeLayout) findViewById(R.id.sliding_up);
slideLayout.setVisibility(View.VISIBLE);
Animation slide = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_up);
slideLayout.startAnimation(slide);
TextView t;
t = (TextView) findViewById(R.id.name);
t.setText(marker.getTitle());
return true;
} else {
RelativeLayout slideLayout;
slideLayout = (RelativeLayout) findViewById(R.id.sliding_up);
slideLayout.setVisibility(View.INVISIBLE);
return false;
}
}
// try this :
map.setOnMapClickListener(new OnMapClickListener() {
#Override
public void onMapClick(LatLng arg0) {
}
});
Related
This has to be the most absurd thing ever.
I have a RecyclerView with repeated custom items. Inside these items, there are a few textfields, buttons and a single MapView.
The issue is that when the list loads, the MapView only displays the Google logo and no other tile or detail (or marker). However, when I tap once on the map, it shows the marker I added. On the next tap, it loads a pixellated map. On another tap, it loads a better quality map. On further clicks it adds the text labels for nearby locations. LatLngBounds are also not working but that's a secondary problem.
Why is this happening?
My code is as follows:
JobAdapter.java
public class JobAdapter extends RecyclerView.Adapter<JobAdapter.ViewHolder>
{
private Context context;
private static List<Job> jobList;
private HashSet<MapView> mapViews = new HashSet<>();
private GoogleMap googleMap;
public JobAdapter(Context con, List<Job> jobs)
{
context = con;
jobList = jobs;
}
#Override
public int getItemCount()
{
return jobList.size();
}
#Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
{
Context context = parent.getContext();
LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.listitem_booking, parent, false);
ViewHolder viewHolder = new ViewHolder(view);
mapViews.add(viewHolder.mapView);
return viewHolder;
}
#Override
public void onBindViewHolder(ViewHolder holder, int position)
{
Job job = jobList.get(position);
holder.mapView.setClickable(false);
if(job.getJobType().equalsIgnoreCase("Now"))
{
holder.pickup.setBackgroundColor(ContextCompat.getColor(context, R.color.lightRed));
}
holder.pickup.setText(job.getPickupAddress());
if(job.getDestinationAddress() != null && !job.getDestinationAddress().equalsIgnoreCase(""))
{
holder.destination.setText(job.getDestinationAddress());
}
else
{
holder.destination.setVisibility(View.GONE);
}
holder.person.setText(job.getContact());
holder.datetime.setText(job.getDate() + " at " + job.getTime());
}
class ViewHolder extends RecyclerView.ViewHolder implements /*View.OnClickListener,*/ OnMapReadyCallback
{
#BindView(R.id.pickup)
TextView pickup;
#BindView(R.id.destination)
TextView destination;
#BindView(R.id.person)
TextView person;
#BindView(R.id.datetime)
TextView datetime;
#BindView(R.id.map_listitem)
MapView mapView;
#BindView(R.id.acceptJob)
Button acceptJob;
#BindView(R.id.declineJob)
Button declineJob;
#BindView(R.id.buttonLayout)
LinearLayout buttonLayout;
private ViewHolder(View itemView)
{
super(itemView);
ButterKnife.bind(this, itemView);
// itemView.setOnClickListener(this);
mapView.onCreate(null);
mapView.getMapAsync(this);
}
private void addMarkers(Job job)
{
googleMap.clear();
boolean hasDestination = true;
String[] destinationLatlng = null;
LatLng destination = null;
if(job.getDestinationAddress() == null || job.getDestinationAddress().equalsIgnoreCase(""))
{
hasDestination = false;
}
else
{
destinationLatlng = job.getDestinationLatLong().split(",");
destination = new LatLng(Double.valueOf(destinationLatlng[0]), Double.parseDouble(destinationLatlng[1]));
}
final String[] pickupLatlng = job.getPickupLatLong().split(",");
final LatLng pickup = new LatLng(Double.valueOf(pickupLatlng[0]), Double.parseDouble(pickupLatlng[1]));
if(hasDestination)
{
googleMap.addMarker(new MarkerOptions()
.position(pickup)
.title(job.getPickupAddress()));
googleMap.addMarker(new MarkerOptions()
.position(destination)
.title(job.getDestinationAddress()));
LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(pickup);
builder.include(destination);
LatLngBounds bounds = builder.build();
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(bounds, 5);
googleMap.animateCamera(cameraUpdate);
}
else
{
googleMap.addMarker(new MarkerOptions()
.position(pickup)
.title(job.getPickupAddress()));
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(pickup, 15);
googleMap.animateCamera(cameraUpdate);
}
}
/*#Override
public void onClick(View view)
{
final Job job = jobList.get(getAdapterPosition());
}*/
#Override
public void onMapReady(GoogleMap gMap)
{
googleMap = gMap;
addMarkers(jobList.get(getAdapterPosition()));
}
}
}
listitem_booking
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:map="http://schemas.android.com/tools"
android:orientation="vertical"
app:cardElevation="2dp"
android:layout_marginBottom="8dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/pickup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="4dp"
android:paddingEnd="4dp"
android:paddingTop="2dp"
android:paddingBottom="2dp"
android:textSize="16sp"
android:text="Complex"
android:background="#color/lessLightGreen"
android:gravity="center_vertical"
android:drawableStart="#drawable/google_maps"
android:drawablePadding="2dp"
android:textColor="#color/colorPrimaryText"/>
<TextView
android:id="#+id/destination"
android:layout_below="#id/pickup"
android:text="Golra"
android:visibility="visible"
android:drawableStart="#drawable/directions"
android:drawablePadding="2dp"
style="#style/listitem_secondary_text"/>
<TextView
android:id="#+id/person"
android:drawablePadding="2dp"
android:layout_below="#id/destination"
android:text="Asfandyar Khan"
android:drawableStart="#drawable/account"
style="#style/listitem_secondary_text"/>
<TextView
android:id="#+id/datetime"
android:layout_below="#id/person"
android:text="7th April 2017 at 9:00am"
android:drawableStart="#drawable/time"
style="#style/listitem_secondary_text"/>
<com.google.android.gms.maps.MapView
android:id="#+id/map_listitem"
android:layout_width="match_parent"
android:layout_height="170dp"
android:layout_marginTop="2dp"
android:layout_below="#id/datetime"
map:liteMode="true"
android:padding="10dp"/>
<LinearLayout
android:id="#+id/buttonLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#id/map_listitem"
android:gravity="end"
android:layout_margin="4dp">
<Button
android:backgroundTint="#color/colorPrimary"
android:textColor="#android:color/white"
android:id="#+id/acceptJob"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Accept"/>
<Button
android:backgroundTint="#color/darkRed"
android:textColor="#android:color/white"
android:id="#+id/declineJob"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Decline"/>
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
I've tried various things but nothing seems to be working.
Try adding onResume, like this:
mapView.onCreate(null);
mapView.getMapAsync(this);
mapView.onResume();
Edit:
I've just noticed you are using
map:liteMode="true"
Try removing it (at least to test) or adding the following to the xml:
map:cameraZoom="15"
map:mapType="normal"
Either way, I think the onResume is needed.
When I use liteMode it sometimes takes a few seconds (about 5) for the map to show after the logo.
There might another issue in your code. The "map" should be:
xmlns:map="http://schemas.android.com/apk/res-auto"
but not:
xmlns:map="http://schemas.android.com/tools"
I have a map in a fragment in a navigation drawer. Now the code for the map is found in the MainActivity.java of the navigation drawer. I have a for loop inside onMapReady which pin markers on my map. Now each iteration of the for loop takes retrieved data from Firebase, to be able to pin the markers. The retrieved data also contains URLs for images and I need to use those URLs to display an image in the infowindow of each marker. I've tried to understand the other solutions provided but I haven't got any idea how to implement this.
this is my code so far my code:
#Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
...
for (infoToStore details : info) {
marker = mMap.addMarker(new MarkerOptions()
.position(new LatLng(Double.parseDouble(details.getLat()), Double.parseDouble(details.getLng())))
.title(details.getName())
.snippet(details.getDesc()));
}
}
EDIT
I've tried to implement it as follows but the infowindow is blank; not showing the TextViews nor the ImageView.
#Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
for (final infoToStore details : info) {
marker = mMap.addMarker(new MarkerOptions()
.position(new LatLng(Double.parseDouble(details.getLat()), Double.parseDouble(details.getLng())))
.title(details.getName())
.snippet(details.getDesc()));
mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
#Override
public View getInfoWindow(Marker marker) {
return null;
}
#Override
public View getInfoContents(Marker marker) {
View v = getLayoutInflater().inflate(R.layout.popup, null);
TextView name = (TextView) v.findViewById(R.id.name);
TextView desc = (TextView) v.findViewById(R.id.desc);
ImageView image = (ImageView) v.findViewById(R.id.image);
name.setText(marker.getTitle());
desc.setText(marker.getSnippet());
Picasso.with(getApplicationContext())
.load(URLString)
.into(image);
return v;
}
});
}
}
here's the popup.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/image"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/name"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/desc"/>
</LinearLayout>
Try this:
Create a Global Marker Variable
private Marker marker;
Now in your onMapReady() call
mMap.setInfoWindowAdapter(new CustomInfoWindowAdapter());
Create your CustomInfoWindowAdapter class and add the following code..
private class CustomInfoWindowAdapter implements InfoWindowAdapter {
private View view;
public CustomInfoWindowAdapter() {
view = getLayoutInflater().inflate(R.layout.popup,null);
}
#Override
public View getInfoContents(Marker marker) {
if (MainActivity.this.marker != null
&& MainActivity.this.marker.isInfoWindowShown()) {
MainActivity.this.marker.hideInfoWindow();
MainActivity.this.marker.showInfoWindow();
}
return null;
}
#Override
public View getInfoWindow(final Marker marker) {
MainActivity.this.marker = marker;
TextView name = (TextView) view.findViewById(R.id.name);
TextView desc = (TextView) view.findViewById(R.id.desc);
ImageView image = (ImageView) view.findViewById(R.id.image);
Picasso.with(getApplicationContext())
.load(URLString)
.error(R.mipmap.ic_launcher) // will be displayed if the image cannot be loaded
.into(image);
final String title = marker.getTitle();
if (title != null) {
name.setText(title);
} else {
name.setText("Default");
}
final String snippet = marker.getSnippet();
if (snippet != null) {
desc.setText(snippet);
} else {
desc.setText("Deafult");
}
//getInfoContents(marker);
return view;
}
}
your imageview is very large...which blocks the textView: try this layout in your popup
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="#+id/image"
android:layout_width="40dp"
android:layout_height="40dp"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:src="#mipmap/ic_launcher" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Sample Text"
android:textColor="#000000"
android:textSize="15sp" />
<TextView
android:id="#+id/desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Sample Text2"
android:textColor="#000000"
android:textSize="12sp" />
</LinearLayout>
And for different image you need a arraylist of imageURL for different markers in the map.
I'm facing the problem about get detail information(data) from marker to NestedScrollView of BottomSheet.
When I clicked marker, NestedScrollView will scroll up from bottom and display corresponding data. Im using json to get data.
My source code:
public class SeekingMapActivity extends AppCompatActivity implements
GoogleApiClient.OnConnectionFailedListener,
GoogleApiClient.ConnectionCallbacks,
View.OnClickListener {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_seeking_main);
...
ArrayList<HashMap<String, String>> location = null;
String url = "myURL";
try {
JSONArray data = new JSONArray(getHttpGet(url));
location = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map;
for (int i = 0; i < data.length(); i++) {
JSONObject c = data.getJSONObject(i);
map = new HashMap<String, String>();
map.put("title", c.getString("title"));
map.put("avatar", c.getString("avatar"));
map.put("lat", c.getString("lat"));
map.put("mapLong", c.getString("mapLong"));
map.put("address", c.getString("address"));
location.add(map);
}
} catch (JSONException e) {
e.printStackTrace();
}
// googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
IconGenerator tc = new IconGenerator(this);
String price = "1200K";
Bitmap bmp = tc.makeIcon(price); // pass the text you want.
lat = Double.parseDouble(location.get(0).get("lat").toString());
mapLong = Double.parseDouble(location.get(0).get("mapLong").toString());
LatLng coordinate = new LatLng(lat, mapLong);
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
googleMap.getUiSettings().setMapToolbarEnabled(false);
googleMap.getUiSettings().setRotateGesturesEnabled(true); // Enable RotateGestures
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(coordinate, 15));
for (int i = 0; i < location.size(); i++) {
lat = Double.parseDouble(location.get(i).get("lat").toString());
mapLong = Double.parseDouble(location.get(i).get("mapLong").toString());
String title = location.get(i).get("title").toString();
String avatar = location.get(i).get("avatar".toString());
String address = location.get(i).get("address").toString();
MarkerOptions marker = new MarkerOptions().position(new LatLng(lat, mapLong))
.title(title)
.snippet(address)
.icon(BitmapDescriptorFactory.fromBitmap(bmp)); // .anchor(0.5f, 0.6f)
googleMap.addMarker(marker);
googleMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener()
{
#Override
public boolean onMarkerClick(Marker arg0) {
if(isClick==false)
mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
else
mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
isClick=!isClick;
// Toast.makeText(SeekingMapActivity.this, arg0.getTitle(), Toast.LENGTH_SHORT).show();// display toast
return true;
}
});
}
}
...
}
Layout of BottomSheet:
<android.support.v4.widget.NestedScrollView
android:id="#+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="270dp"
android:clipToPadding="true"
android:background="#color/white"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
> <!-- android:background="#android:color/background_holo_light" -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/mercedes"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="1,200,000"
android:textSize="20dp"
android:textStyle="bold"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/textView1b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Số cửa: 4 cửa"
android:textSize="14dp"/>
<!-- android:textAppearance="?android:attr/textAppearanceMedium" -->
<TextView
android:id="#+id/textView1c"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Số ghế: 4 chỗ"
android:textSize="14dp"/>
</LinearLayout>
<TextView
android:id="#+id/textView1d"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Địa chỉ: Quân Cầu giấy, Hà Nội"
android:textSize="14dp" />
<TextView
android:id="#+id/textView1e"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="KIỂM TRA TÌNH TRẠNG XE"
android:textStyle="bold"
android:textColor="#color/greenColor"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
I don't know how to get data from maker to NestedScrollView
Example:
When click: Marker A, data of marker A will display on NestedScrollView
Marker B, data of marker B will display on NestedScrollView
If you need more information, I will post more!
1 - Create model class with your attributes like title, avatar, address etc...
2 - Create an Arraylist of your model type
3 - Add all those data in your arraylist
4 - Now in onMarkerClick method of your marker, iterate for loop and compare title or unique id of that marker with position of your arrayList title/unique id like below:
googleMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
#Override
public boolean onMarkerClick(Marker marker) {
for (int i = 0; i < arrayList.size(); i++) {
if (marker.getTitle().equals(finalMSearchResultModel.getRecords().get(i).getHotelName())) {
// YOUR ACTION GOES HERE
}
}
return false;
}
});
I can't see correct data on my Coordinator Layout: I mean, my layout seems correctly set and my java class is correct too.
But when I launch my application I don't see error but my activity have TextView, Image and WebView not initialized with passed data.
I tried to inflate all content with traditional
(TextView) findViewById(R.id.my_id) and with butterknife.ButterKnife library, same result.
Here my activity
public class EventDetailsActivity extends AppCompatActivity implements OnMapReadyCallback, GoogleMap.OnMapClickListener {
private long eventID;
private String eventTitle;
private String eventDesc;
private String eventDate;
private String eventTime;
private String eventImageUrl;
private String eventAddress;
private Double lat;
private Double lng;
private int maxBookings;
#InjectView(R.id.event_title) TextView eventTitleTv;
#InjectView(R.id.event_address) TextView eventAddressTv;
#InjectView(R.id.event_start_date) TextView eventDateTv;
#InjectView(R.id.event_start_time) TextView eventTimeTv;
#InjectView(R.id.event_image) ImageView imageEventView;
#InjectView(R.id.map_address) TextView evetMapAddress;
#InjectView(R.id.event_desc) WebView mWebView;
#InjectView(R.id.toolbar) Toolbar toolbar;
#InjectView(R.id.collapsing_toolbar) CollapsingToolbarLayout collapsingToolbarLayout;
#InjectView(R.id.btnJoin) AppCompatButton btnJoin;
#InjectView(R.id.open_map_button) FloatingActionButton openMapButton;
private MapFragment googleMap;
private GoogleMap map;
private Event event;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initActivityTransitions();
setContentView(R.layout.event_details_activity);
ButterKnife.inject(this);
btnJoin.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
showDialogPlus();
}
});
openMapButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
openMapDetail();
}
});
try {
inizializeToolbar();
if (savedInstanceState == null) {
Bundle extras = getIntent().getExtras();
event = extras == null ? null : (Event) extras.getSerializable(Const.EVENT_OBJECT);
} else {
event = (Event) savedInstanceState.getSerializable(Const.EVENT_OBJECT);
}
eventTitle = event.getEventName();
eventDesc = event.getEventContent();
eventDate = event.getEventStartDate();
eventTime = event.getEventStartTime();
eventImageUrl = event.getEventImageUrl();
lat = event.getLocationLatitude();
lng = event.getLocationLongitude();
eventAddress = event.getLocationAddress();
eventID = event.getEventId();
maxBookings = 10;
Log.d("EVENT", "__event title " + eventTitle);
Log.d("EVENT", "__event eventDesc " + eventDesc);
Log.d("EVENT", "__event eventDate " + eventDate);
Log.d("EVENT", "__event eventTime " + eventTime);
Log.d("EVENT", "__event eventImageUrl " + eventImageUrl);
Log.d("EVENT", "__event lat " + lat);
Log.d("EVENT", "__event lng " + lng);
Log.d("EVENT", "__event eventAddress " + eventAddress);
Log.d("EVENT", "__event eventTitle " + eventTitle);
Log.d("EVENT", "__event evv name " + event.getEventName());
initializeMap();
loadImage();
loadTextViews();
} catch (Exception e) {
e.printStackTrace();
}
}
private void initActivityTransitions() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Slide transition = new Slide();
transition.excludeTarget(android.R.id.statusBarBackground, true);
getWindow().setEnterTransition(transition);
getWindow().setReturnTransition(transition);
}
}
private void inizializeToolbar() {
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
collapsingToolbarLayout.setTitle(eventTitle);
collapsingToolbarLayout.setCollapsedTitleTextColor(Color.WHITE);
collapsingToolbarLayout.setExpandedTitleColor(Color.TRANSPARENT);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
finish();
}
});
}
private void loadTextViews(){
eventTitleTv.setText("TITOLO DELL'EVENTO");
eventAddressTv.setText(eventAddress);
evetMapAddress.setText(eventAddress + " -> ");
setEventDesc();
eventDateTv.setText(Utils.getDateFromString(eventDate));
eventTimeTv.setText(Utils.getTimeFromString(eventTime));
}
private void loadImage(){
final ProgressBar progressView = (ProgressBar) findViewById(R.id.loader);
progressView.getIndeterminateDrawable().setColorFilter(getApplicationContext().getResources().getColor(R.color.ColorPrimary), android.graphics.PorterDuff.Mode.MULTIPLY);
Picasso.with(getApplicationContext())
.load(eventImageUrl)
.fit().centerCrop()
.placeholder(R.drawable.event_placeholder_grey_2)
.into(imageEventView, new Callback() {
#Override
public void onSuccess() {
progressView.setVisibility(View.GONE);
}
#Override
public void onError() {
progressView.setVisibility(View.GONE);
}
});
}
private void showDialogPlus() {
Holder holder = new ViewHolder(R.layout.event_prenotation);
OnClickListener clickListener = new OnClickListener() {
#Override
public void onClick(DialogPlus dialog, View view) {
Spinner mySpinner=(Spinner) dialog.getHolderView().findViewById(R.id.spinner);
String bookValue = mySpinner.getSelectedItem().toString();;
int numberPerson = Integer.parseInt(bookValue);
switch (view.getId()) {
case R.id.btnJoin:
Intent intent = new Intent(getApplicationContext(), ConfirmPrenotationActivity.class);
Bundle bun = new Bundle();
bun.putInt(Const.NUMBER_PRENOT, numberPerson);
bun.putString(Const.EVENT_TITLE, eventTitle);
bun.putLong(Const.EVENT_ID, eventID);
bun.putSerializable(Const.EVENT_OBJECT, event);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtras(bun);
getApplicationContext().startActivity(intent);
break;
}
//dialog.dismiss();
}
};
OnItemClickListener itemClickListener = new OnItemClickListener() {
#Override
public void onItemClick(DialogPlus dialog, Object item, View view, int position) {
//TextView textView = (TextView) view.findViewById(R.id.text_view);
//String clickedAppName = textView.getText().toString();
// dialog.dismiss();
// Toast.makeText(MainActivity.this, clickedAppName + " clicked", Toast.LENGTH_LONG).show();
}
};
OnDismissListener dismissListener = new OnDismissListener() {
#Override
public void onDismiss(DialogPlus dialog) {
// Toast.makeText(MainActivity.this, "dismiss listener invoked!", Toast.LENGTH_SHORT).show();
}
};
OnCancelListener cancelListener = new OnCancelListener() {
#Override
public void onCancel(DialogPlus dialog) {
// Toast.makeText(MainActivity.this, "cancel listener invoked!", Toast.LENGTH_SHORT).show();
}
};
final DialogPlus dialog = DialogPlus.newDialog(this)
.setContentHolder(holder)
.setCancelable(true)
.setGravity(Gravity.BOTTOM)
.setOnClickListener(clickListener)
.setOnItemClickListener(new OnItemClickListener() {
#Override public void onItemClick(DialogPlus dialog, Object item, View view, int position) {
Log.d("DialogPlus", "onItemClick() called with: " + "item = [" +
item + "], position = [" + position + "]");
}
})
.setOnDismissListener(dismissListener)
//.setExpanded(expanded)
//.setContentWidth(800)
.setContentHeight(ViewGroup.LayoutParams.WRAP_CONTENT)
.setOnCancelListener(cancelListener)
.setOverlayBackgroundResource(android.R.color.transparent)
//.setContentBackgroundResource(R.drawable.corner_background)
//.setOutMostMargin(0, 100, 0, 0)
.create();
Spinner spinner = (Spinner) dialog.findViewById(R.id.spinner);
initializeSpinner(spinner);
dialog.show();
}
public void initializeSpinner(Spinner spin){
ArrayList<String> options = new ArrayList<String>();
for(int i=1; i<= maxBookings; i++){
options.add(""+i);
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.spinner_style, options) {
public View getView(int position, View convertView,ViewGroup parent) {
View v = super.getView(position, convertView, parent);
((TextView) v).setTextSize(18);
return v;
}
public View getDropDownView(int position, View convertView,ViewGroup parent) {
View v = super.getDropDownView(position, convertView,parent);
//((TextView) v).setGravity(Gravity.CENTER);
return v;
}
};
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spin.setAdapter(adapter);
}
public void setEventDesc(){
mWebView.setBackgroundColor(Color.TRANSPARENT);
StringBuilder sb = new StringBuilder();
sb.append("<html><body>");
sb.append("<p align=\"justify\">");
sb.append(eventDesc);
sb.append("</p>");
sb.append("</body></html>");
//mWebView.loadData(sb.toString(), "text/html", "utf-8");
mWebView.loadData(sb.toString(), "text/html; charset=utf-8", "utf-8");
}
#TargetApi(Build.VERSION_CODES.M)
public void initializeMap() {
if (googleMap == null) {
googleMap = (MapFragment) getFragmentManager()
.findFragmentById(R.id.map);
googleMap.getMapAsync(this);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_event_details, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
switch (id) {
case R.id.share_button:
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, getEventInfoToShare());
startActivity(Intent.createChooser(shareIntent, "Share link using"));
return true;
default:
// If we got here, the user's action was not recognized.
// Invoke the superclass to handle it.
return super.onOptionsItemSelected(item);
}
}
private String getEventInfoToShare(){
StringBuilder infoEvent = new StringBuilder();
infoEvent.append("Ciao, vorrei consigliarti un evento :-)");
infoEvent.append(System.getProperty("line.separator"));
infoEvent.append(System.getProperty("line.separator"));
infoEvent.append(eventTitle);
infoEvent.append(System.getProperty("line.separator"));
infoEvent.append(eventAddress);
infoEvent.append(System.getProperty("line.separator"));
infoEvent.append(System.getProperty("line.separator"));
infoEvent.append(eventDesc.substring(0, Math.min(eventDesc.length(), 200)));
infoEvent.append("...continua");
infoEvent.append(System.getProperty("line.separator"));
infoEvent.append(System.getProperty("line.separator"));
infoEvent.append("Visita -> www.dayroma.it");
return infoEvent.toString();
}
#Override
public void onBackPressed() {
finish();
super.onBackPressed();
}
#Override
public void onMapReady(GoogleMap googleMap) {
map = googleMap;
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
map.setOnMapClickListener(this);
googleMap.getUiSettings().setScrollGesturesEnabled(false);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lat, lng), 15.0f));
map.addMarker(new MarkerOptions()
.position(new LatLng(lat, lng))
.title(eventTitle));
map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
#Override
public boolean onMarkerClick(Marker marker) {
openMapDetail();
return true;
}
});
}
public void openMapDetail(){
Intent i = new Intent(getApplicationContext(), MapsDetailActivity.class);
Bundle bun = new Bundle();
bun.putDouble(Const.EVENT_LAT, lat);
bun.putDouble(Const.EVENT_LONG, lng);
bun.putString(Const.EVENT_TITLE, eventTitle);
bun.putString(Const.EVENT_ADDRESS, eventAddress);
bun.putString(Const.EVENT_IMG_LINK, eventImageUrl);
bun.putSerializable(Const.EVENT_OBJECT, event);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtras(bun);
getApplicationContext().startActivity(i);
}
#Override
public void onMapClick(LatLng latLng) {
openMapDetail();
}
}
And here the layout:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
>
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="#dimen/image_event_detail_height"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true"
>
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="#color/ColorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp"
android:fitsSystemWindows="true"
>
<util.SquareImageView
android:id="#+id/event_image"
android:layout_width="match_parent"
android:layout_height="#dimen/image_event_detail_height"
android:maxHeight="#dimen/image_event_detail_height"
android:scaleType="centerCrop"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax"/>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="#+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<!--<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ProgressBar
android:id="#+id/loader"
android:layout_width="75dip"
android:layout_height="75dip"
android:layout_gravity="center"
android:indeterminate="true"
android:layout_centerInParent="true"
/>
</RelativeLayout>-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:background="#drawable/google_cards_background_bottom"
android:gravity="left"
android:orientation="vertical" >
<!-- Titolo Evento -->
<TextView
android:id="#+id/event_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:layout_marginLeft="10dp"
android:textStyle="bold"
android:layout_marginRight="16dp"
android:layout_marginTop="20dp"
android:text="Eat at Joe"
android:textColor="#color/ColorPrimary"
android:textSize="18sp"
/>
<!-- indirizzo -->
<TextView
android:id="#+id/event_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="9dp"
android:layout_marginBottom="1dp"
android:background="#android:color/transparent"
android:text="data inizio"
android:textColor="#color/material_grey_500"
android:textSize="14sp"
android:drawableLeft="#drawable/ic_position_black_18dp"
android:drawablePadding="2dip"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="left"
android:orientation="horizontal" >
<!-- data inizio evento-->
<TextView
android:id="#+id/event_start_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="10dp"
android:layout_marginBottom="10dp"
android:background="#android:color/transparent"
android:text="data inizio"
android:textColor="#color/material_grey_500"
android:textSize="14sp"
android:drawableLeft="#drawable/calendar_black_18dp"
android:drawablePadding="2dip"
/>
<!-- ora inizio evento-->
<TextView
android:id="#+id/event_start_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="3dp"
android:layout_marginBottom="20dp"
android:background="#android:color/transparent"
android:text="data inizio"
android:textColor="#color/material_grey_500"
android:textSize="14sp"
android:drawableLeft="#drawable/clock_18dp"
android:drawablePadding="2dip"
/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#android:color/darker_gray"/>
</LinearLayout>
<!-- DETTAGLI -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:background="#drawable/rounded_shape"
>
<TextView
android:id="#+id/event_detail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="5dp"
android:layout_marginLeft="15dp"
android:layout_marginBottom="3dp"
android:background="#android:color/transparent"
android:text="Dettagli"
android:textColor="#color/black"
android:textStyle="bold"
android:textSize="17sp"
android:gravity="center"
/>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical" >
<WebView
android:id="#+id/event_desc"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:hardwareAccelerated="true"
/>
</ScrollView>
</LinearLayout>
<!-- FINE DETTAGLI -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:foreground="#color/dark_trasparent"
>
<fragment xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="#dimen/map_height"
map:cameraTargetLat="41.890122"
map:cameraTargetLng="12.494248"
map:cameraTilt="30"
map:cameraZoom="15"
tools:ignore="MissingPrefix"
android:clickable="false"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<!-- Maps Address -->
<TextView
android:id="#+id/map_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="22dp"
android:layout_gravity="center_vertical|center_horizontal"
android:background="#android:color/transparent"
android:text="via Cristoforo Colombo 24"
android:textColor="#color/white"
android:textSize="18sp"
android:drawableLeft="#drawable/ic_position_white_18dp"
/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="#+id/open_map_button"
app:layout_anchor="#id/app_bar_layout"
app:layout_anchorGravity="bottom|right|end"
app:backgroundTint="#color/ColorPrimary"
android:tint="#color/cpb_grey"
android:src="#drawable/navigation_black_24dp"
style="#style/floatButtonStyle"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/buttons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_alignParentBottom="true"
android:background="#00ffffff"
>
<android.support.v7.widget.AppCompatButton
android:id="#+id/btnJoin"
android:background="#drawable/rounded_button_red"
android:layout_width="fill_parent"
android:textSize="17dp"
android:textStyle="bold"
android:textColor="#color/white"
android:layout_height="#dimen/fixed_bottom_button_height"
android:layout_margin="10dp"
android:layout_centerHorizontal="true"
android:text="#string/join_event"
/>
</LinearLayout>
</RelativeLayout>
It seems a simple problem but I've never had like this before: here a screenshot of my activity, it should be visualize an event details.
Screenshot Activity
This activity is opened when a user click on an event and is fill with event data: data are correctly set because I can see all from log.
I really don't understand why TextViews, ImageView and other element are not filled with data.
Thank you for help
I can't see any closing tag for Coordinator layout in your xml file. If you haven't missed it in question then probably that is the reason for this strange behavior.
Add this at the end of your xml code and things should work better.
</android.support.design.widget.CoordinatorLayout>
Or, if that is just the mistake in question then please update your question. Whatever it is do let me know.
now i displayed the default rectangle shape using this code.
this.infoWindow = (ViewGroup)getLayoutInflater().inflate(R.layout.newcustomdialog, null);
this.infoImage=(ImageView)infoWindow.findViewById(R.id.graphicimage);
this.infoTitle = (TextView)infoWindow.findViewById(R.id.balloon_item_title);
this.infoSnippet = (TextView)infoWindow.findViewById(R.id.balloon_item_snippet);
this.close=(Button)infoWindow.findViewById(R.id.close_img_button);
this.infoButton = (Button)infoWindow.findViewById(R.id.more);
//
// Setting custom OnTouchListener which deals with the pressed state
// so it shows up
this.infoButtonListener = new OnInfoWindowElemTouchListener(HomeScreen.this,infoButton)
{
#Override
protected void onClickConfirmed(View v, Marker marker) {
// v.setVisibility(View.GONE);
// Here we can perform some action triggered after clicking the button
Toast.makeText(HomeScreen.this, marker.getTitle() + "'s button clicked!", Toast.LENGTH_SHORT).show();
}
};
//oraii
this.exitButtonListener=new OnInfoWindowExitListener(HomeScreen.this,infoWindow) {
#Override
protected void onClickConfirmed(View v, Marker marker) {
// TODO Auto-generated method stub
}
};
this.infoButton.setOnTouchListener(infoButtonListener);
this.close.setOnTouchListener(exitButtonListener);
map.setInfoWindowAdapter(new InfoWindowAdapter() {
public View getInfoWindow(Marker marker) {
return null;
}
public View getInfoContents(Marker marker) {
// Setting up the infoWindow with current's marker info
StringTokenizer st2 = new StringTokenizer(marker.getTitle(), ",");
String imageurl="";
String title="";
String eventid="";
while (st2.hasMoreElements()) {
eventid=st2.nextElement().toString();
imageurl=st2.nextElement().toString();
title=st2.nextElement().toString();
}
EventId=eventid;
infoTitle.setText(title);
infoSnippet.setText(marker.getSnippet());
imageLoader.DisplayImage(imageurl,HomeScreen.this, infoImage);
infoButtonListener.setMarker(marker);
exitButtonListener.setMarker(marker);
// We must call this to set the current marker and infoWindow references
// to the MapWrapperLayout
mapWrapperLayout.setMarkerWithInfoWindow(marker, infoWindow);
return infoWindow;
}
});
i want to change the shape to heart shape means custom shape like a chart dialog shape..how to do that one .. plz help me if any body knows.
custom_infowindow.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="110dp"
android:layout_height="110dp"
android:orientation="vertical"
android:background="#drawable/heart"
android:gravity="center"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<Button
android:layout_width="40dp"
android:layout_height="20dp"
android:layout_alignParentTop="true"
android:layout_marginLeft="60dp"
android:layout_marginTop="15dp"
android:text="Click!"
android:textColor="#ffffff"
android:textSize="10dp"
android:background="#373737"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="HELLO"
android:textColor="#FF0000"
android:padding="10dp"
android:layout_centerInParent="true"
android:background="#00000000"
/>
</RelativeLayout>
</LinearLayout>
this is your heart shape layout..copy and paste it in drable folder of your application...lolz
Download it
just inflate the above view into custom info window..!
mMap.setInfoWindowAdapter(new InfoWindowAdapter() {
public View getInfoWindow(Marker arg0) {
View v = getLayoutInflater().inflate(R.layout.custom_infowindow, null);
return v;
}
public View getInfoContents(Marker arg0) {
//View v = getLayoutInflater().inflate(R.layout.custom_infowindow, null);
return null;
}
});
this is just image i have created..you can add image better than me...if this works let me know...:)