Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/map/CustomInfoWindow.java
package it.reyboz.bustorino.map; | package it.reyboz.bustorino.map; | ||||
import android.annotation.SuppressLint; | import android.annotation.SuppressLint; | ||||
import android.content.Context; | import android.os.Build; | ||||
import android.content.Intent; | |||||
import android.os.Bundle; | |||||
import android.util.Log; | |||||
import android.view.MotionEvent; | import android.view.MotionEvent; | ||||
import android.view.View; | import android.view.View; | ||||
import android.widget.TextView; | import android.widget.TextView; | ||||
import org.osmdroid.api.IMapView; | |||||
import androidx.annotation.NonNull; | |||||
import androidx.annotation.Nullable; | |||||
import org.osmdroid.views.MapView; | import org.osmdroid.views.MapView; | ||||
import org.osmdroid.views.overlay.infowindow.BasicInfoWindow; | import org.osmdroid.views.overlay.infowindow.BasicInfoWindow; | ||||
import it.reyboz.bustorino.ActivityMain; | |||||
import it.reyboz.bustorino.R; | import it.reyboz.bustorino.R; | ||||
public class CustomInfoWindow extends BasicInfoWindow { | public class CustomInfoWindow extends BasicInfoWindow { | ||||
//TODO: Make the action on the Click customizable | |||||
private final TouchResponder touchResponder; | |||||
private final String stopID, name; | |||||
@Override | @Override | ||||
public void onOpen(Object item) { | public void onOpen(Object item) { | ||||
super.onOpen(item); | super.onOpen(item); | ||||
TextView descr_textView = (TextView) mView.findViewById(R.id.bubble_description); | TextView descr_textView = (TextView) mView.findViewById(R.id.bubble_description); | ||||
CharSequence text = descr_textView.getText(); | CharSequence text = descr_textView.getText(); | ||||
if (text==null || !text.toString().isEmpty()){ | if (text==null || !text.toString().isEmpty()){ | ||||
descr_textView.setVisibility(View.VISIBLE); | descr_textView.setVisibility(View.VISIBLE); | ||||
} else | } else | ||||
descr_textView.setVisibility(View.GONE); | descr_textView.setVisibility(View.GONE); | ||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |||||
mView.setElevation(3.2f); | mView.setElevation(3.2f); | ||||
} | } | ||||
} | |||||
@SuppressLint("ClickableViewAccessibility") | @SuppressLint("ClickableViewAccessibility") | ||||
public CustomInfoWindow(MapView mapView, String ID, String stopName) { | public CustomInfoWindow(MapView mapView, String stopID, String name, TouchResponder responder) { | ||||
// get the personalized layout | // get the personalized layout | ||||
super(R.layout.map_popup, mapView); | super(R.layout.map_popup, mapView); | ||||
touchResponder =responder; | |||||
this.stopID = stopID; | |||||
this.name = name; | |||||
// make clickable | // make clickable | ||||
mView.setOnTouchListener((View v, MotionEvent e) -> { | mView.setOnTouchListener((View v, MotionEvent e) -> { | ||||
if (e.getAction() == MotionEvent.ACTION_UP) { | if (e.getAction() == MotionEvent.ACTION_UP) { | ||||
// on click | // on click | ||||
touchResponder.onActionUp(stopID, name); | |||||
// create an intent with these extras | |||||
Intent intent = new Intent(mapView.getContext(), ActivityMain.class); | |||||
Bundle b = new Bundle(); | |||||
b.putString("bus-stop-ID", ID); | |||||
b.putString("bus-stop-display-name", stopName); | |||||
intent.putExtras(b); | |||||
intent.setFlags(Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP); | |||||
// start ActivityMain with the previous intent | |||||
mapView.getContext().startActivity(intent); | |||||
} | } | ||||
return true; | return true; | ||||
}); | }); | ||||
} | } | ||||
public interface TouchResponder{ | |||||
/** | |||||
* React to a click on the stop View | |||||
* @param stopID the stop id | |||||
* @param stopName the stop name | |||||
*/ | |||||
void onActionUp(@NonNull String stopID, @Nullable String stopName); | |||||
} | |||||
} | } |
Public contents are in Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) or GNU Free Documentation License (at your option) unless otherwise noted. · Contact / Register