DT @02.12.2015: MapInfoWindow vollständig überarbeitet

This commit is contained in:
Dennis Thießen
2015-12-02 21:28:23 +01:00
parent c9917be028
commit e1dc4d624a
5 changed files with 167 additions and 26 deletions

View File

@@ -15,8 +15,9 @@ import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.View; import android.view.View;
import android.widget.EditText; import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RatingBar;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import com.android.volley.Request; import com.android.volley.Request;
import com.android.volley.Response; 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.MarkerOptions;
import com.google.android.gms.maps.model.TileOverlay; import com.google.android.gms.maps.model.TileOverlay;
import com.google.android.gms.maps.model.TileOverlayOptions; 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.clustering.ClusterManager;
import com.google.maps.android.heatmaps.HeatmapTileProvider; import com.google.maps.android.heatmaps.HeatmapTileProvider;
@@ -51,7 +53,7 @@ import java.util.List;
import java.util.Map; 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 final static String mActivityTitle = "Risk Map";
private static final String TAG = MapsActivity.class.getSimpleName(); 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 myLocation;
private LatLng markedLocation; private LatLng markedLocation;
private AppClusterItem clickedClusterItem;
private List<LatLng> mPositionList = new ArrayList<>(); private List<LatLng> mPositionList = new ArrayList<>();
ClusterManager<AppClusterItem> mClusterManager; ClusterManager<AppClusterItem> mClusterManager;
@@ -136,13 +140,85 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
mClusterManager = new ClusterManager<AppClusterItem>(this, mMap); mClusterManager = new ClusterManager<AppClusterItem>(this, mMap);
//mMap.setOnCameraChangeListener(mClusterManager);
mMap.setOnCameraChangeListener(getCameraChangeListener()); mMap.setOnCameraChangeListener(getCameraChangeListener());
mClusterManager.setRenderer(new OwnIconRendered(MapsActivity.this,mMap,mClusterManager));
mMap.setOnMarkerClickListener(mClusterManager); mMap.setOnMarkerClickListener(mClusterManager);
mClusterManager.setRenderer(new OwnIconRendered(this, mMap, mClusterManager));
mMap.setOnInfoWindowClickListener(mClusterManager); mMap.setOnInfoWindowClickListener(mClusterManager);
mMap.setInfoWindowAdapter(mClusterManager.getMarkerManager());
mClusterManager.setOnClusterItemInfoWindowClickListener(this); mClusterManager.setOnClusterItemInfoWindowClickListener(this);
addClusterMarkers(mClusterManager); 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) { 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) { public Loader<Cursor> onCreateLoader(int arg0, Bundle query) {
CursorLoader cLoader = null; CursorLoader cLoader = null;
if(arg0==0) 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) else if(arg0==1)
cLoader = new CursorLoader(getBaseContext(), PlaceProvider.DETAILS_URI, null, null, new String[]{ query.getString("query") }, null); cLoader = new CursorLoader(getBaseContext(), PlaceProvider.DETAILS_URI, null, null, new String[]{ query.getString("query") }, null);
return cLoader; return cLoader;
@@ -305,19 +381,8 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
AppClusterItem offsetItem = new AppClusterItem(incident,pos); AppClusterItem offsetItem = new AppClusterItem(incident,pos);
myMarkers.add(offsetItem); myMarkers.add(offsetItem);
//mClusterManager.addItem(offsetItem);
mPositionList.add(pos); 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(); addHeatMap();
@@ -342,7 +407,7 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
@Override @Override
protected Map<String, String> getParams() { protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<>(); Map<String, String> params = new HashMap<>();
params.put("tag", "getincidentswithposition"); params.put("tag", "getincidentswithpositionandscore");
params.put("uid", user.get("uid")); params.put("uid", user.get("uid"));
params.put("token", user.get("token")); params.put("token", user.get("token"));
@@ -361,4 +426,5 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
super.onPause(); super.onPause();
showAd(); showAd();
} }
} }

View File

@@ -26,6 +26,8 @@ public class AppClusterItem implements ClusterItem {
private String mCatName; private String mCatName;
private String mCatDescription; private String mCatDescription;
private String mColor; private String mColor;
private String mUsername;
private int mScore;
private BitmapDescriptor icon; private BitmapDescriptor icon;
@@ -44,6 +46,8 @@ public class AppClusterItem implements ClusterItem {
this.mCatName = mIncident.getString("cat_name"); this.mCatName = mIncident.getString("cat_name");
this.mCatDescription = mIncident.getString("cat_description"); this.mCatDescription = mIncident.getString("cat_description");
this.mColor = mIncident.getString("color"); this.mColor = mIncident.getString("color");
this.mUsername = mIncident.getString("username");
this.mScore = mIncident.getInt("votescore");
this.mPosition = pos; this.mPosition = pos;
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
@@ -84,6 +88,44 @@ public class AppClusterItem implements ClusterItem {
return this.mTitle; 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() { public String getID() {
return mID; return mID;
} }

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"> <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" /> <stroke android:width="1dip" android:color="#66808080" />
<corners android:radius="3dip"/> <corners android:radius="3dip"/>
<padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" /> <padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />

View File

@@ -1,21 +1,19 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <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:layout_height="wrap_content"
android:orientation="horizontal" android:orientation="horizontal"
android:padding="5dp" android:padding="5dp"
android:weightSum="1"> android:background="@drawable/layout_bg">
<LinearLayout <LinearLayout
android:orientation="horizontal" android:orientation="horizontal"
android:id="@+id/lay_infowindow_color" android:id="@+id/lay_infowindow_color"
android:background="#e45151" android:background="#e45151"
android:layout_width="5dp" android:layout_width="5dp"
android:layout_marginRight="5dp" android:layout_marginRight="3dp"
android:layout_height="match_parent"> android:layout_height="match_parent">
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
@@ -45,11 +43,44 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textColor="#b9000000" android:textColor="#b9000000"
android:text="Category" android:text="Category"
android:paddingBottom="10dp"
android:id="@+id/txt_infowindow_category" android:id="@+id/txt_infowindow_category"
android:typeface="serif" /> 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>
</LinearLayout> </LinearLayout>

View File

@@ -115,5 +115,7 @@
<string name="errormsg_couldnotretrieve">Could not retrieve data from server. Please check internet connection.</string> <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_text">Please wait...</string>
<string name="progress_getdata_title">Retrieve data from server</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> </resources>