Skip to content

Commit

Permalink
map corrections, bus zindex, infoWindow listener and new color icons for
Browse files Browse the repository at this point in the history
buses compatible 4.4+
  • Loading branch information
TheRolfFR committed Nov 24, 2019
1 parent 64caa2c commit 0febe31
Show file tree
Hide file tree
Showing 43 changed files with 19 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.drawable.DrawableCompat;

import com.google.android.gms.location.LocationListener;
import com.google.android.gms.maps.CameraUpdateFactory;
Expand All @@ -34,8 +33,8 @@
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.maps.model.PolylineOptions;
import com.therolf.optymoNext.R;
import com.therolf.optymoNext.controller.global.GlobalApplication;
import com.therolf.optymoNext.controller.activities.StopActivity;
import com.therolf.optymoNext.controller.global.GlobalApplication;
import com.therolf.optymoNext.controller.global.Utility;
import com.therolf.optymoNextModel.OptymoNetwork;
import com.therolf.optymoNextModel.OptymoStop;
Expand All @@ -62,7 +61,7 @@
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

public class MapActivity extends AppCompatActivity implements OnMapReadyCallback, GoogleMap.OnMarkerClickListener, View.OnClickListener, LocationListener {
public class MapActivity extends AppCompatActivity implements OnMapReadyCallback, View.OnClickListener, LocationListener, GoogleMap.OnInfoWindowClickListener {

private static final int LOCATION_PERMISSION_CODE = 1;
private MyLocationController myLocationController;
Expand All @@ -76,7 +75,7 @@ public class MapActivity extends AppCompatActivity implements OnMapReadyCallback
put("4", 2);
put("1", 1);
}};
private static final int BUS_INDEX = 7;
private static final int BUS_INDEX = 100;
private static final int STOP_Z_INDEX = 8;

private Map<String, BitmapDescriptor> busIcons = new HashMap<>();
Expand All @@ -98,12 +97,11 @@ protected void onCreate(Bundle savedInstanceState) {
findViewById(R.id.map_close_button).setOnClickListener(v -> finish());

// load bus icon
busIcon = bitmapDescriptorFromVector(this, R.drawable.ic_bus);
busIcon = bitmapDescriptorFromVector(this, R.drawable.ic_bus_default);
Set<String> keys = zIndexes.keySet();
for(String key : keys) {
int id = getResources().getIdentifier("colorLine" + key, "color", getPackageName());
int color = ContextCompat.getColor(this, id);
busIcons.put(key, bitmapDescriptorFromVector(this, R.drawable.ic_bus, color));
int id = getResources().getIdentifier("ic_bus_" + key, "drawable", getPackageName());
busIcons.put(key, bitmapDescriptorFromVector(this, id));
}

// map view
Expand Down Expand Up @@ -221,7 +219,7 @@ public void startMap() {
e.printStackTrace();
}

googleMap.setOnMarkerClickListener(this);
googleMap.setOnInfoWindowClickListener(this);
startRepeatingTask();
}

Expand All @@ -238,19 +236,10 @@ public void OnGenerationEnd(boolean returnValue) {
});
}

@SuppressWarnings("SameParameterValue")
private static BitmapDescriptor bitmapDescriptorFromVector(Context context, int vectorId) {
return bitmapDescriptorFromVector(context, vectorId, 0);
}

private static BitmapDescriptor bitmapDescriptorFromVector(Context context, int vectorId, int color) {
BitmapDescriptor result = null;

Drawable vectorDrawable = ContextCompat.getDrawable(context, vectorId);
if(color != 0 && vectorDrawable != null) {
vectorDrawable = vectorDrawable.mutate();
DrawableCompat.setTint(vectorDrawable, color);
}
if (vectorDrawable != null) {
vectorDrawable.setBounds(0, 0, vectorDrawable.getIntrinsicWidth(), vectorDrawable.getIntrinsicHeight());

Expand All @@ -265,13 +254,6 @@ private static BitmapDescriptor bitmapDescriptorFromVector(Context context, int
return result;
}

@Override
public boolean onMarkerClick(Marker marker) {
if(((GlobalApplication) getApplication()).getNetworkController().isGenerated() && ((GlobalApplication) getApplication()).getNetworkController().getStopBySlug(OptymoStop.nameToSlug(marker.getTitle())) != null)
StopActivity.launchStopActivity(this, OptymoStop.nameToSlug(marker.getTitle()));
return false;
}

private final static int INTERVAL = 1000 *10; // 10s = 10000ms
private Handler mHandler = new Handler();
private GetBusMarkers request = null;
Expand Down Expand Up @@ -362,7 +344,18 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis

@Override
public void onLocationChanged(Location location) {
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 14));
// change zoom only if lower
float zoom = googleMap.getCameraPosition().zoom;
if(zoom < 14)
zoom = 14;

googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), zoom));
}

@Override
public void onInfoWindowClick(Marker marker) {
if(((GlobalApplication) getApplication()).getNetworkController().isGenerated() && ((GlobalApplication) getApplication()).getNetworkController().getStopBySlug(OptymoStop.nameToSlug(marker.getTitle())) != null)
StopActivity.launchStopActivity(this, OptymoStop.nameToSlug(marker.getTitle()));
}

@SuppressWarnings("unused")
Expand Down
Binary file added app/src/main/res/drawable-hdpi/ic_bus_1.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-hdpi/ic_bus_2.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-hdpi/ic_bus_3.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-hdpi/ic_bus_4.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-hdpi/ic_bus_5.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-hdpi/ic_bus_8.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-hdpi/ic_bus_default.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-ldpi/ic_bus_1.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-ldpi/ic_bus_2.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-ldpi/ic_bus_3.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-ldpi/ic_bus_4.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-ldpi/ic_bus_5.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-ldpi/ic_bus_8.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-ldpi/ic_bus_default.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-mdpi/ic_bus_1.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-mdpi/ic_bus_2.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-mdpi/ic_bus_3.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-mdpi/ic_bus_4.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-mdpi/ic_bus_5.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-mdpi/ic_bus_8.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-mdpi/ic_bus_default.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-xhdpi/ic_bus_1.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-xhdpi/ic_bus_2.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-xhdpi/ic_bus_3.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-xhdpi/ic_bus_4.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-xhdpi/ic_bus_5.png
Binary file added app/src/main/res/drawable-xhdpi/ic_bus_8.png
Binary file added app/src/main/res/drawable-xhdpi/ic_bus_default.png
Binary file added app/src/main/res/drawable-xxhdpi/ic_bus_1.png
Binary file added app/src/main/res/drawable-xxhdpi/ic_bus_2.png
Binary file added app/src/main/res/drawable-xxhdpi/ic_bus_3.png
Binary file added app/src/main/res/drawable-xxhdpi/ic_bus_4.png
Binary file added app/src/main/res/drawable-xxhdpi/ic_bus_5.png
Binary file added app/src/main/res/drawable-xxhdpi/ic_bus_8.png
Binary file added app/src/main/res/drawable-xxhdpi/ic_bus_default.png
Binary file added app/src/main/res/drawable-xxxhdpi/ic_bus_1.png
Binary file added app/src/main/res/drawable-xxxhdpi/ic_bus_2.png
Binary file added app/src/main/res/drawable-xxxhdpi/ic_bus_3.png
Binary file added app/src/main/res/drawable-xxxhdpi/ic_bus_4.png
Binary file added app/src/main/res/drawable-xxxhdpi/ic_bus_5.png
Binary file added app/src/main/res/drawable-xxxhdpi/ic_bus_8.png

0 comments on commit 0febe31

Please sign in to comment.