DT @02.12.2015: MapInfoWindow vollständig überarbeitet
This commit is contained in:
@@ -15,8 +15,9 @@ import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RatingBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.volley.Request;
|
||||
import com.android.volley.Response;
|
||||
@@ -32,6 +33,7 @@ import com.google.android.gms.maps.model.Marker;
|
||||
import com.google.android.gms.maps.model.MarkerOptions;
|
||||
import com.google.android.gms.maps.model.TileOverlay;
|
||||
import com.google.android.gms.maps.model.TileOverlayOptions;
|
||||
import com.google.maps.android.clustering.Cluster;
|
||||
import com.google.maps.android.clustering.ClusterManager;
|
||||
import com.google.maps.android.heatmaps.HeatmapTileProvider;
|
||||
|
||||
@@ -51,7 +53,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCallbacks<Cursor>, ClusterManager.OnClusterItemInfoWindowClickListener<AppClusterItem>{
|
||||
public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCallbacks<Cursor>, ClusterManager.OnClusterItemInfoWindowClickListener<AppClusterItem>, ClusterManager.OnClusterClickListener<AppClusterItem>, ClusterManager.OnClusterItemClickListener<AppClusterItem>{
|
||||
|
||||
private final static String mActivityTitle = "Risk Map";
|
||||
private static final String TAG = MapsActivity.class.getSimpleName();
|
||||
@@ -65,6 +67,8 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
|
||||
private LatLng myLocation;
|
||||
private LatLng markedLocation;
|
||||
|
||||
private AppClusterItem clickedClusterItem;
|
||||
|
||||
private List<LatLng> mPositionList = new ArrayList<>();
|
||||
|
||||
ClusterManager<AppClusterItem> mClusterManager;
|
||||
@@ -136,13 +140,85 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
|
||||
|
||||
mClusterManager = new ClusterManager<AppClusterItem>(this, mMap);
|
||||
|
||||
//mMap.setOnCameraChangeListener(mClusterManager);
|
||||
mMap.setOnCameraChangeListener(getCameraChangeListener());
|
||||
|
||||
mClusterManager.setRenderer(new OwnIconRendered(MapsActivity.this,mMap,mClusterManager));
|
||||
|
||||
mMap.setOnMarkerClickListener(mClusterManager);
|
||||
mClusterManager.setRenderer(new OwnIconRendered(this, mMap, mClusterManager));
|
||||
mMap.setOnInfoWindowClickListener(mClusterManager);
|
||||
mMap.setInfoWindowAdapter(mClusterManager.getMarkerManager());
|
||||
|
||||
mClusterManager.setOnClusterItemInfoWindowClickListener(this);
|
||||
addClusterMarkers(mClusterManager);
|
||||
|
||||
mClusterManager.setOnClusterClickListener(this);
|
||||
mClusterManager.setOnClusterItemClickListener(this);
|
||||
mClusterManager
|
||||
.setOnClusterItemClickListener(new ClusterManager.OnClusterItemClickListener<AppClusterItem>() {
|
||||
@Override
|
||||
public boolean onClusterItemClick(AppClusterItem item) {
|
||||
clickedClusterItem = item;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
mClusterManager.getMarkerCollection().setOnInfoWindowAdapter(
|
||||
new MyCustomAdapterForItems());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onClusterItemClick(AppClusterItem appClusterItem) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onClusterClick(Cluster<AppClusterItem> cluster) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public class MyCustomAdapterForItems implements GoogleMap.InfoWindowAdapter {
|
||||
|
||||
private final View myContentsView;
|
||||
|
||||
MyCustomAdapterForItems() {
|
||||
myContentsView = getLayoutInflater().inflate(
|
||||
R.layout.map_info_window, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getInfoContents(Marker marker) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getInfoWindow(Marker marker) {
|
||||
|
||||
TextView tvTitle = ((TextView) myContentsView
|
||||
.findViewById(R.id.txt_infowindow_title));
|
||||
TextView tvSnippet = ((TextView) myContentsView
|
||||
.findViewById(R.id.txt_infowindow_description));
|
||||
TextView tvCategory = ((TextView) myContentsView
|
||||
.findViewById(R.id.txt_infowindow_category));
|
||||
LinearLayout layCategory = ((LinearLayout) myContentsView
|
||||
.findViewById(R.id.lay_infowindow_color));
|
||||
TextView tvUsername = ((TextView) myContentsView
|
||||
.findViewById(R.id.txt_infowindow_fromuser));
|
||||
TextView tvPoints = ((TextView) myContentsView
|
||||
.findViewById(R.id.txt_infowindow_points));
|
||||
RatingBar rbScore = ((RatingBar) myContentsView
|
||||
.findViewById(R.id.rb_infowindow_rating));
|
||||
|
||||
if (clickedClusterItem != null) {
|
||||
tvTitle.setText(clickedClusterItem.getTitle());
|
||||
tvSnippet.setText(clickedClusterItem.getSnippet());
|
||||
tvCategory.setText(clickedClusterItem.getCategory());
|
||||
layCategory.setBackgroundColor(Color.parseColor("#" + clickedClusterItem.getColor()));
|
||||
tvUsername.setText(getString(R.string.lbl_mapsinfowindow_author) + ": " + clickedClusterItem.getUsername());
|
||||
tvPoints.setText(getString(R.string.lbl_mapsinfowindow_score) + ": " + clickedClusterItem.getScore());
|
||||
rbScore.setRating(clickedClusterItem.getScoreStars());
|
||||
}
|
||||
return myContentsView;
|
||||
}
|
||||
}
|
||||
|
||||
private void addClusterMarkers(ClusterManager<AppClusterItem> mClusterManager) {
|
||||
@@ -233,7 +309,7 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
|
||||
public Loader<Cursor> onCreateLoader(int arg0, Bundle query) {
|
||||
CursorLoader cLoader = null;
|
||||
if(arg0==0)
|
||||
cLoader = new CursorLoader(getBaseContext(), PlaceProvider.SEARCH_URI, null, null, new String[]{ query.getString("query") }, null);
|
||||
cLoader = new CursorLoader(getBaseContext(), PlaceProvider.SEARCH_URI, null, null, new String[]{query.getString("query") }, null);
|
||||
else if(arg0==1)
|
||||
cLoader = new CursorLoader(getBaseContext(), PlaceProvider.DETAILS_URI, null, null, new String[]{ query.getString("query") }, null);
|
||||
return cLoader;
|
||||
@@ -305,19 +381,8 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
|
||||
|
||||
AppClusterItem offsetItem = new AppClusterItem(incident,pos);
|
||||
myMarkers.add(offsetItem);
|
||||
//mClusterManager.addItem(offsetItem);
|
||||
mPositionList.add(pos);
|
||||
|
||||
/*
|
||||
CircleOptions circleOptions = new CircleOptions()
|
||||
.center(pos)
|
||||
.strokeColor(Color.BLACK)
|
||||
.strokeWidth(0)
|
||||
.fillColor(Color.parseColor("#"+incident.getString("color")))
|
||||
.radius(incident.getInt("radius")); // In meters
|
||||
|
||||
Circle circle = mMap.addCircle(circleOptions);
|
||||
*/
|
||||
}
|
||||
addHeatMap();
|
||||
|
||||
@@ -342,7 +407,7 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
|
||||
@Override
|
||||
protected Map<String, String> getParams() {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("tag", "getincidentswithposition");
|
||||
params.put("tag", "getincidentswithpositionandscore");
|
||||
params.put("uid", user.get("uid"));
|
||||
params.put("token", user.get("token"));
|
||||
|
||||
@@ -361,4 +426,5 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
|
||||
super.onPause();
|
||||
showAd();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@ public class AppClusterItem implements ClusterItem {
|
||||
private String mCatName;
|
||||
private String mCatDescription;
|
||||
private String mColor;
|
||||
private String mUsername;
|
||||
private int mScore;
|
||||
private BitmapDescriptor icon;
|
||||
|
||||
|
||||
@@ -44,6 +46,8 @@ public class AppClusterItem implements ClusterItem {
|
||||
this.mCatName = mIncident.getString("cat_name");
|
||||
this.mCatDescription = mIncident.getString("cat_description");
|
||||
this.mColor = mIncident.getString("color");
|
||||
this.mUsername = mIncident.getString("username");
|
||||
this.mScore = mIncident.getInt("votescore");
|
||||
this.mPosition = pos;
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
@@ -84,6 +88,44 @@ public class AppClusterItem implements ClusterItem {
|
||||
return this.mTitle;
|
||||
}
|
||||
|
||||
public String getCategory(){
|
||||
return this.mCatName;
|
||||
}
|
||||
|
||||
public int getScore() { return this.mScore; }
|
||||
|
||||
public String getUsername() { return this.mUsername; }
|
||||
|
||||
public float getScoreStars() {
|
||||
if(mScore > 0){
|
||||
return 0.5f;
|
||||
}else if(mScore > 2){
|
||||
return 1.0f;
|
||||
}else if(mScore > 4){
|
||||
return 1.5f;
|
||||
}else if(mScore > 6){
|
||||
return 2.0f;
|
||||
}else if(mScore > 8){
|
||||
return 2.5f;
|
||||
}else if(mScore > 10){
|
||||
return 3.0f;
|
||||
}else if(mScore > 12){
|
||||
return 3.5f;
|
||||
}else if(mScore > 14){
|
||||
return 4.0f;
|
||||
}else if(mScore > 16){
|
||||
return 4.5f;
|
||||
}else if(mScore > 18){
|
||||
return 5.0f;
|
||||
}else{
|
||||
return 0f;
|
||||
}
|
||||
}
|
||||
|
||||
public String getColor(){
|
||||
return this.mColor;
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return mID;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="#dedede"/>
|
||||
<solid android:color="#CCdedede"/>
|
||||
<stroke android:width="1dip" android:color="#66808080" />
|
||||
<corners android:radius="3dip"/>
|
||||
<padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
|
||||
|
||||
@@ -1,21 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="200dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:padding="5dp"
|
||||
android:weightSum="1">
|
||||
|
||||
android:background="@drawable/layout_bg">
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:id="@+id/lay_infowindow_color"
|
||||
android:background="#e45151"
|
||||
android:layout_width="5dp"
|
||||
android:layout_marginRight="5dp"
|
||||
android:layout_marginRight="3dp"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
@@ -45,11 +43,44 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="#b9000000"
|
||||
android:text="Category"
|
||||
|
||||
android:paddingBottom="10dp"
|
||||
android:id="@+id/txt_infowindow_category"
|
||||
android:typeface="serif" />
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:id="@+id/lay_infowindow_2"
|
||||
android:background="#55151515"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_marginRight="5dp"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="#b9000000"
|
||||
android:text="Username"
|
||||
android:id="@+id/txt_infowindow_fromuser"
|
||||
android:typeface="serif" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="#b9000000"
|
||||
android:text="Points:"
|
||||
android:id="@+id/txt_infowindow_points"
|
||||
android:typeface="serif" />
|
||||
|
||||
<RatingBar
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/rb_infowindow_rating"
|
||||
style = "?android:attr/ratingBarStyleSmall"
|
||||
android:stepSize="0.5"
|
||||
android:numStars = "5"
|
||||
android:rating = "0"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
@@ -115,5 +115,7 @@
|
||||
<string name="errormsg_couldnotretrieve">Could not retrieve data from server. Please check internet connection.</string>
|
||||
<string name="progress_getdata_text">Please wait...</string>
|
||||
<string name="progress_getdata_title">Retrieve data from server</string>
|
||||
<string name="lbl_mapsinfowindow_author">Author</string>
|
||||
<string name="lbl_mapsinfowindow_score">Score</string>
|
||||
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user