Skip to content

Commit

Permalink
Add custom markers for accidents marker in the map. (#24)
Browse files Browse the repository at this point in the history
Also added type resolver for  severity and accident subType (#16)
  • Loading branch information
samuelregev committed Mar 12, 2015
1 parent e342a40 commit 47365a4
Show file tree
Hide file tree
Showing 23 changed files with 253 additions and 10 deletions.
6 changes: 2 additions & 4 deletions AnyWay-CarAccidentMap.iml
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="java-gradle" name="Java-Gradle">
<configuration>
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/classes/main" />
<output-test url="file://$MODULE_DIR$/build/classes/test" />
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
Expand Down
4 changes: 3 additions & 1 deletion app/app.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="AnyWay-CarAccidentMap" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
Expand All @@ -9,6 +9,7 @@
<facet type="android" name="Android">
<configuration>
<option name="SELECTED_BUILD_VARIANT" value="debug" />
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
Expand All @@ -24,6 +25,7 @@
</component>
<component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
Expand Down
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/il/co/anyway/app/FetchAccidents.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ protected ArrayList<Accident> doInBackground(String... params) {
accidentJsonStr = buffer.toString();
} catch (IOException e) {
Log.e(LOG_TAG, "Error ", e);
// If the code didn't successfully get the weather data, there's no point in attemping
// to parse it.
// If the code didn't successfully get the weather data, there's no point in attemping to parse it.
return null;
} finally {
if (urlConnection != null) {
Expand Down
12 changes: 11 additions & 1 deletion app/src/main/java/il/co/anyway/app/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import com.google.android.gms.maps.GoogleMap.OnInfoWindowClickListener;
import com.google.android.gms.maps.GoogleMap.OnMapLongClickListener;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.UiSettings;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.LatLngBounds;
Expand Down Expand Up @@ -142,6 +144,13 @@ private void setUpMap(boolean firstRun) {
// Enable location buttons
map.setMyLocationEnabled(true);

// Hide My Location button
// this because it implemented is the action bar
map.getUiSettings().setMyLocationButtonEnabled(false);

// Disable toolbar on the right bottom corner(taking user to google maps app)
map.getUiSettings().setMapToolbarEnabled(false);

// try to move map to user location, if not succeed go to default
if(firstRun) {
if (!centerMapOnMyLocation())
Expand Down Expand Up @@ -264,8 +273,9 @@ private void addAccidentsToMap(boolean clearMap) {
desc = desc.substring(0, 30).concat("...");

map.addMarker(new MarkerOptions()
.title(a.getTitle())
.title(Utility.getAccidentTypeByIndex(a.getSubType()))
.snippet(desc + "\n" + a.getAddress())
.icon(BitmapDescriptorFactory.fromResource(Utility.getIconForMarker(a.getSeverity(), a.getSubType())))
.position(a.getLocation()));
}
}
Expand Down
236 changes: 236 additions & 0 deletions app/src/main/java/il/co/anyway/app/Utility.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ public class Utility {

private static final String LOG_TAG = Utility.class.getSimpleName();

public static final int SEVERITY_FATAL = 1;
public static final int SEVERITY_SEVERE = 2;
public static final int SEVERITY_LIGHT = 3;
public static final int SEVERITY_VARIOUS = 4;

public static final int ACCIDENT_MULTIPLE = -10;

/**
* Parse JSON string to accidents list
* @param accidentJsonStr JSON string to parse
Expand Down Expand Up @@ -126,4 +133,233 @@ public static String getTimeStamp(String dateStr) {

return getTimeStamp(date);
}

public static String getAccidentTypeByIndex(int accidentSubType) {
String str = "";

switch (accidentSubType) {
case 1:
str = "פגיעה בהולך רגל";
break;
case 2:
str = "התנגשות חזית אל צד";
break;
case 3:
str = "התנגשות חזית באחור";
break;
case 4:
str = "התנגשות צד בצד";
break;
case 5:
str = "התנגשות חזית אל חזית";
break;
case 6:
str = "התנגשות עם רכב שנעצר ללא חניה";
break;
case 7:
str = "התנגשות עם רכב חונה";
break;
case 8:
str = "התנגשות עם עצם דומם";
break;
case 9:
str = "ירידה מהכביש או עלייה למדרכה";
break;
case 10:
str = "התהפכות";
break;
case 11:
str = "החלקה";
break;
case 12:
str = "פגיעה בנוסע בתוך כלי רכב";
break;
case 13:
str = "נפילה ברכב נע";
break;
case 14:
str = "שריפה";
break;
case 15:
str = "אחר";
break;
case 17:
str = "התנגשות אחור אל חזית";
break;
case 18:
str = "התנגשות אחור אל צד";
break;
case 19:
str = "התנגשות עם בעל חיים";
break;
case 20:
str = "פגיעה ממטען של רכב";
break;
}

return str;
}

public static String getAccidentSeverityByIndex(int severity) {
String str = "";

/*
"HUMRAT_TEUNA": {
1: "קטלנית",
2: "קשה",
3: "קלה",
}
*/

return str;
}

public static int getIconForMarker(int severity, int accidentSubType) {

int innerType = 0;

final int ACCIDENT_TYPE_CAR_TO_CAR =-1; // Synthetic type
final int ACCIDENT_TYPE_CAR_TO_OBJECT = -2; // Synthetic type
final int ACCIDENT_TYPE_CAR_TO_PEDESTRIAN = 1;
final int ACCIDENT_TYPE_FRONT_TO_SIDE = 2;
final int ACCIDENT_TYPE_FRONT_TO_REAR = 3;
final int ACCIDENT_TYPE_SIDE_TO_SIDE = 4;
final int ACCIDENT_TYPE_FRONT_TO_FRONT = 5;
final int ACCIDENT_TYPE_WITH_STOPPED_CAR_NO_PARKING = 6;
final int ACCIDENT_TYPE_WITH_STOPPED_CAR_PARKING = 7;
final int ACCIDENT_TYPE_WITH_STILL_OBJECT = 8;
final int ACCIDENT_TYPE_OFF_ROAD_OR_SIDEWALK = 9;
final int ACCIDENT_TYPE_ROLLOVER = 10;
final int ACCIDENT_TYPE_SKID = 11;
final int ACCIDENT_TYPE_HIT_PASSSENGER_IN_CAR = 12;
final int ACCIDENT_TYPE_FALLING_OFF_MOVING_VEHICLE = 13;
final int ACCIDENT_TYPE_FIRE = 14;
final int ACCIDENT_TYPE_OTHER = 15;
final int ACCIDENT_TYPE_BACK_TO_FRONT = 17;
final int ACCIDENT_TYPE_BACK_TO_SIDE = 18;
final int ACCIDENT_TYPE_WITH_ANIMAL = 19;
final int ACCIDENT_TYPE_WITH_VEHICLE_LOAD = 20;

switch (accidentSubType) {

case ACCIDENT_TYPE_CAR_TO_PEDESTRIAN:
innerType = ACCIDENT_TYPE_CAR_TO_PEDESTRIAN;
break;
case ACCIDENT_TYPE_FRONT_TO_SIDE:
innerType = ACCIDENT_TYPE_CAR_TO_CAR;
break;
case ACCIDENT_TYPE_FRONT_TO_REAR:
innerType = ACCIDENT_TYPE_CAR_TO_CAR;
break;
case ACCIDENT_TYPE_SIDE_TO_SIDE:
innerType = ACCIDENT_TYPE_CAR_TO_CAR;
break;
case ACCIDENT_TYPE_FRONT_TO_FRONT:
innerType = ACCIDENT_TYPE_CAR_TO_CAR;
break;
case ACCIDENT_TYPE_WITH_STOPPED_CAR_NO_PARKING:
innerType = ACCIDENT_TYPE_CAR_TO_CAR;
break;
case ACCIDENT_TYPE_WITH_STOPPED_CAR_PARKING:
innerType = ACCIDENT_TYPE_CAR_TO_CAR;
break;
case ACCIDENT_TYPE_WITH_STILL_OBJECT:
innerType = ACCIDENT_TYPE_CAR_TO_OBJECT;
break;
case ACCIDENT_TYPE_OFF_ROAD_OR_SIDEWALK:
innerType = ACCIDENT_TYPE_CAR_TO_OBJECT;
break;
case ACCIDENT_TYPE_ROLLOVER:
innerType = ACCIDENT_TYPE_CAR_TO_OBJECT;
break;
case ACCIDENT_TYPE_SKID:
innerType = ACCIDENT_TYPE_CAR_TO_OBJECT;
break;
case ACCIDENT_TYPE_HIT_PASSSENGER_IN_CAR:
innerType = ACCIDENT_TYPE_CAR_TO_CAR;
break;
case ACCIDENT_TYPE_FALLING_OFF_MOVING_VEHICLE:
innerType = ACCIDENT_TYPE_CAR_TO_OBJECT;
break;
case ACCIDENT_TYPE_FIRE:
innerType = ACCIDENT_TYPE_CAR_TO_OBJECT;
break;
case ACCIDENT_TYPE_OTHER:
innerType = ACCIDENT_TYPE_CAR_TO_OBJECT;
break;
case ACCIDENT_TYPE_BACK_TO_FRONT:
innerType = ACCIDENT_TYPE_CAR_TO_CAR;
break;
case ACCIDENT_TYPE_BACK_TO_SIDE:
innerType = ACCIDENT_TYPE_CAR_TO_CAR;
break;
case ACCIDENT_TYPE_WITH_ANIMAL:
innerType = ACCIDENT_TYPE_CAR_TO_PEDESTRIAN;
break;
case ACCIDENT_TYPE_WITH_VEHICLE_LOAD:
innerType = ACCIDENT_TYPE_CAR_TO_CAR;
break;
}

int icon = 0;

if(accidentSubType == ACCIDENT_MULTIPLE) {
switch(severity) {
case SEVERITY_FATAL:
icon = R.drawable.multiple_lethal;
break;
case SEVERITY_SEVERE:
icon = R.drawable.multiple_severe;
break;
case SEVERITY_LIGHT:
icon = R.drawable.multiple_medium;
break;
case SEVERITY_VARIOUS:
icon = R.drawable.multiple_various;
break;
}
}
else if(severity == SEVERITY_FATAL) {
switch(innerType) {
case ACCIDENT_TYPE_CAR_TO_PEDESTRIAN:
icon = R.drawable.vehicle_person_lethal;
break;
case ACCIDENT_TYPE_CAR_TO_CAR:
icon = R.drawable.vehicle_person_lethal;
break;
case ACCIDENT_TYPE_CAR_TO_OBJECT:
icon = R.drawable.vehicle_object_lethal;
break;
}
}
else if(severity == SEVERITY_SEVERE) {
switch(innerType) {
case ACCIDENT_TYPE_CAR_TO_PEDESTRIAN:
icon = R.drawable.vehicle_person_severe;
break;
case ACCIDENT_TYPE_CAR_TO_CAR:
icon = R.drawable.vehicle_vehicle_severe;
break;
case ACCIDENT_TYPE_CAR_TO_OBJECT:
icon = R.drawable.vehicle_object_severe;
break;
}
}
else if(severity == SEVERITY_LIGHT) {
switch(innerType) {
case ACCIDENT_TYPE_CAR_TO_PEDESTRIAN:
icon = R.drawable.vehicle_person_medium;
break;
case ACCIDENT_TYPE_CAR_TO_CAR:
icon = R.drawable.vehicle_vehicle_medium;
break;
case ACCIDENT_TYPE_CAR_TO_OBJECT:
icon = R.drawable.vehicle_object_medium;
break;
}
}

return icon;
}
}

Binary file added app/src/main/res/drawable/multiple_lethal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/multiple_medium.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/multiple_severe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/multiple_various.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@

<!-- popup layout -->
<string name="icon">Accident logo</string>
<string name="hello_blank_fragment">Hello blank fragment</string>

</resources>

0 comments on commit 47365a4

Please sign in to comment.