google: Add maps view for larger screens.

This commit is contained in:
Andreas Schildbach 2012-03-23 16:07:30 +01:00
parent 0aa10ed8ca
commit 18b453e02c
21 changed files with 1096 additions and 5 deletions

View file

@ -379,6 +379,8 @@
android:name=".plans.PlanContentProvider"
android:authorities="de.schildbach.oeffi.plans"
android:exported="false" />
<uses-library android:name="com.google.android.maps" />
</application>
</manifest>

View file

@ -23,6 +23,7 @@ dependencies {
compile 'com.github.tony19:logback-android:1.1.1-8'
compile 'com.google.code.findbugs:jsr305:3.0.0'
testCompile 'junit:junit:4.12'
provided files('libs/maps.jar')
}
android {

BIN
oeffi/libs/maps.jar Normal file

Binary file not shown.

View file

@ -88,4 +88,19 @@
<include layout="@layout/navigation_drawer" />
</android.support.v4.widget.DrawerLayout>
<FrameLayout
android:id="@+id/directions_map_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:foreground="@drawable/view_shadow_right"
android:foregroundGravity="left|fill_vertical" >
<de.schildbach.oeffi.OeffiMapView
android:id="@+id/directions_map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:apiKey="@string/maps_api_key"
android:clickable="true" />
</FrameLayout>
</LinearLayout>

View file

@ -134,4 +134,19 @@
</LinearLayout>
</FrameLayout>
<FrameLayout
android:id="@+id/directions_trip_details_map_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:foreground="@drawable/view_shadow_right"
android:foregroundGravity="left|fill_vertical" >
<de.schildbach.oeffi.OeffiMapView
android:id="@+id/directions_trip_details_map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:apiKey="@string/maps_api_key"
android:clickable="true" />
</FrameLayout>
</LinearLayout>

View file

@ -65,4 +65,19 @@
</LinearLayout>
</FrameLayout>
<FrameLayout
android:id="@+id/network_picker_map_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:foreground="@drawable/view_shadow_right"
android:foregroundGravity="left|fill_vertical" >
<de.schildbach.oeffi.OeffiMapView
android:id="@+id/network_picker_map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:apiKey="@string/maps_api_key"
android:clickable="true" />
</FrameLayout>
</LinearLayout>

View file

@ -398,4 +398,19 @@
<include layout="@layout/navigation_drawer" />
</android.support.v4.widget.DrawerLayout>
<FrameLayout
android:id="@+id/stations_map_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:foreground="@drawable/view_shadow_right"
android:foregroundGravity="left|fill_vertical" >
<de.schildbach.oeffi.OeffiMapView
android:id="@+id/stations_map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:apiKey="@string/maps_api_key"
android:clickable="true" />
</FrameLayout>
</LinearLayout>

View file

@ -74,4 +74,19 @@
</FrameLayout>
</LinearLayout>
<FrameLayout
android:id="@+id/stations_station_details_map_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:foreground="@drawable/view_shadow_right"
android:foregroundGravity="left|fill_vertical" >
<de.schildbach.oeffi.OeffiMapView
android:id="@+id/stations_station_details_map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:apiKey="@string/maps_api_key"
android:clickable="true" />
</FrameLayout>
</LinearLayout>

View file

@ -25,6 +25,8 @@
<item name="trips_overview_entry_public_box_fraction" type="fraction">75%</item>
<dimen name="layout_list_width">390dp</dimen>
<integer name="max_departures_per_station">6</integer>
</resources>

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="layout_navigation_drawer_width">@dimen/layout_list_width</dimen>
<bool name="layout_map_show">true</bool>
</resources>

View file

@ -27,4 +27,6 @@
<item name="trips_overview_entry_public_box_fraction" type="fraction">70%</item>
<dimen name="trip_details_stop_offset">8sp</dimen>
<dimen name="layout_list_width">420dp</dimen>
</resources>

View file

@ -42,7 +42,10 @@
<dimen name="map_trip_stroke_width_selected">12dp</dimen>
<dimen name="map_trip_stroke_width_selected_glow">24dp</dimen>
<dimen name="layout_navigation_drawer_width">300dp</dimen>
<dimen name="layout_list_width">360dp</dimen>
<bool name="layout_list_show">true</bool>
<bool name="layout_map_show">false</bool>
<bool name="layout_navigation_drawer_footer_show">false</bool>
<integer name="max_departures_per_station">5</integer>

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="MissingTranslation">
<!-- release -->
<string name="maps_api_key">0_5QxtRHdv6pmRUua3pONjL2g8sntEaJMU_e69w</string>
</resources>

View file

@ -47,6 +47,8 @@ public class Constants {
public static final int MAX_NUMBER_OF_STOPS = 150;
public static final int MAX_HISTORY_ENTRIES = 50;
public static final float BEARING_ACCURACY_THRESHOLD = 0.5f;
public static final int INITIAL_MAP_ZOOM_LEVEL_NETWORK = 12;
public static final int INITIAL_MAP_ZOOM_LEVEL = 17;
public static final int MAX_TRIES_ON_IO_PROBLEM = 2;
public static final Locale DEFAULT_LOCALE = Locale.GERMAN;

View file

@ -20,23 +20,28 @@ package de.schildbach.oeffi;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.android.maps.MapActivity;
import de.schildbach.oeffi.network.NetworkResources;
import de.schildbach.oeffi.util.ErrorReporter;
import de.schildbach.pte.NetworkId;
import de.schildbach.pte.dto.ResultHeader;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.ActivityManager.TaskDescription;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.format.DateUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
public abstract class OeffiActivity extends Activity {
public abstract class OeffiActivity extends MapActivity {
protected SharedPreferences prefs;
private static final Logger log = LoggerFactory.getLogger(OeffiActivity.class);
@ -50,6 +55,27 @@ public abstract class OeffiActivity extends Activity {
prefs = PreferenceManager.getDefaultSharedPreferences(this);
}
protected void updateFragments(final int listFrameResId, final int mapFrameResId) {
final Resources res = getResources();
final View listFrame = findViewById(listFrameResId);
final boolean listShow = res.getBoolean(R.bool.layout_list_show);
listFrame.setVisibility(isInMultiWindowMode() || listShow ? View.VISIBLE : View.GONE);
final View mapFrame = findViewById(mapFrameResId);
final boolean mapShow = res.getBoolean(R.bool.layout_map_show);
mapFrame.setVisibility(!isInMultiWindowMode() && mapShow ? View.VISIBLE : View.GONE);
listFrame.getLayoutParams().width = listShow && mapShow ? res.getDimensionPixelSize(R.dimen.layout_list_width)
: LinearLayout.LayoutParams.MATCH_PARENT;
final ViewGroup navigationDrawer = (ViewGroup) findViewById(R.id.navigation_drawer_layout);
if (navigationDrawer != null) {
final View child = navigationDrawer.getChildAt(1);
child.getLayoutParams().width = res.getDimensionPixelSize(R.dimen.layout_navigation_drawer_width);
}
}
protected String prefsGetNetwork() {
return prefs.getString(Constants.PREFS_KEY_NETWORK_PROVIDER, null);
}
@ -83,6 +109,11 @@ public abstract class OeffiActivity extends Activity {
return ((Application) getApplication()).packageInfo().firstInstallTime;
}
@Override
protected final boolean isRouteDisplayed() {
return false;
}
protected final MyActionBar getMyActionBar() {
return (MyActionBar) findViewById(R.id.action_bar);
}

View file

@ -0,0 +1,662 @@
package de.schildbach.oeffi;
import java.util.ArrayList;
import java.util.List;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;
import de.schildbach.oeffi.stations.LineView;
import de.schildbach.oeffi.stations.Station;
import de.schildbach.pte.dto.Location;
import de.schildbach.pte.dto.Point;
import de.schildbach.pte.dto.Product;
import de.schildbach.pte.dto.Trip;
import de.schildbach.pte.dto.Trip.Leg;
import de.schildbach.pte.dto.Trip.Public;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Path.FillType;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.widget.TextView;
public class OeffiMapView extends MapView {
private FromViaToAware fromViaToAware = null;
private TripAware tripAware = null;
private StationsAware stationsAware = null;
private LocationAware locationAware = null;
private AreaAware areaAware = null;
private boolean firstLocation = true;
private boolean zoomLocked = true;
private final int AREA_FILL_COLOR = Color.parseColor("#22000000");
public OeffiMapView(final Context context) {
this(context, null, 0);
}
public OeffiMapView(final Context context, final AttributeSet attrs) {
this(context, attrs, 0);
}
public OeffiMapView(final Context context, final AttributeSet attrs, final int defStyle) {
super(context, attrs, defStyle);
final Resources res = context.getResources();
final LayoutInflater inflater = LayoutInflater.from(context);
final float stationFontSize = res.getDimension(R.dimen.font_size_normal);
final float tripStrokeWidth = res.getDimension(R.dimen.map_trip_stroke_width);
final float tripStrokeWidthSelected = res.getDimension(R.dimen.map_trip_stroke_width_selected);
final float tripStrokeWidthSelectedGlow = res.getDimension(R.dimen.map_trip_stroke_width_selected_glow);
final Drawable startIcon = drawablePointer(R.drawable.ic_maps_indicator_startpoint_list, 2);
final Drawable pointIcon = drawableCenter(R.drawable.ic_maps_product_default, 2);
final Drawable endIcon = drawablePointer(R.drawable.ic_maps_indicator_endpoint_list, 2);
final Drawable deviceLocationIcon = drawableCenter(R.drawable.location_on, 2);
final Drawable referenceLocationIcon = drawablePointer(R.drawable.da_marker_red, 2);
final Drawable glowIcon = drawableCenter(R.drawable.station_glow, 2);
final Drawable stationDefaultIcon = drawableCenter(R.drawable.ic_maps_product_default, 2);
final Drawable stationHighspeedIcon = drawableCenter(R.drawable.product_highspeed_color_22dp, 2);
final Drawable stationTrainIcon = drawableCenter(R.drawable.product_train_color_22dp, 2);
final Drawable stationSuburbanIcon = drawableCenter(R.drawable.product_suburban_color_22dp, 2);
final Drawable stationSubwayIcon = drawableCenter(R.drawable.product_subway_color_22dp, 2);
final Drawable stationTramIcon = drawableCenter(R.drawable.product_tram_color_22dp, 2);
final Drawable stationBusIcon = drawableCenter(R.drawable.product_bus_color_22dp, 2);
final Drawable stationFerryIcon = drawableCenter(R.drawable.product_ferry_color_22dp, 2);
final Drawable stationCablecarIcon = drawableCenter(R.drawable.product_cablecar_color_22dp, 2);
final Drawable stationCallIcon = drawableCenter(R.drawable.product_call_color_22dp, 2);
getController().setZoom(Constants.INITIAL_MAP_ZOOM_LEVEL);
getOverlays().add(new Overlay() {
@Override
public void draw(final Canvas canvas, final MapView mapView, final boolean shadow) {
if (!shadow) {
final Projection projection = mapView.getProjection();
final android.graphics.Point point = new android.graphics.Point();
if (areaAware != null) {
final Point[] area = areaAware.getArea();
if (area != null) {
final Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setStyle(Paint.Style.FILL);
paint.setColor(AREA_FILL_COLOR);
final Path path = pointsToPath(projection, area);
path.close();
path.setFillType(FillType.INVERSE_WINDING);
canvas.drawPath(path, paint);
}
}
if (fromViaToAware != null) {
final List<Point> path = new ArrayList<>(3);
final Point from = fromViaToAware.getFrom();
if (from != null)
path.add(from);
final Point via = fromViaToAware.getVia();
if (via != null)
path.add(via);
final Point to = fromViaToAware.getTo();
if (to != null)
path.add(to);
if (path.size() >= 2) {
final Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setStrokeCap(Paint.Cap.ROUND);
paint.setColor(Color.DKGRAY);
paint.setAlpha(92);
paint.setStrokeWidth(tripStrokeWidth);
canvas.drawPath(pointsToPath(projection, path), paint);
}
if (from != null) {
projection.toPixels(new GeoPoint(from.lat, from.lon), point);
drawAt(canvas, startIcon, point.x, point.y, false);
}
if (to != null) {
projection.toPixels(new GeoPoint(to.lat, to.lon), point);
drawAt(canvas, endIcon, point.x, point.y, false);
}
}
if (tripAware != null) {
final Trip trip = tripAware.getTrip();
final Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setStrokeCap(Paint.Cap.ROUND);
// first paint all unselected legs
for (final Trip.Leg leg : trip.legs) {
if (!tripAware.isSelectedLeg(leg)) {
final Path path = pointsToPath(projection, leg.path);
paint.setColor(leg instanceof Public ? Color.RED : Color.DKGRAY);
paint.setAlpha(92);
paint.setStrokeWidth(tripStrokeWidth);
canvas.drawPath(path, paint);
}
}
// then paint selected legs
for (final Trip.Leg leg : trip.legs) {
if (tripAware.isSelectedLeg(leg)) {
final List<Point> points = leg.path;
final Path path = pointsToPath(projection, points);
paint.setColor(Color.GREEN);
paint.setAlpha(92);
paint.setStrokeWidth(tripStrokeWidthSelectedGlow);
canvas.drawPath(path, paint);
paint.setColor(leg instanceof Public ? Color.RED : Color.DKGRAY);
paint.setAlpha(128);
paint.setStrokeWidth(tripStrokeWidthSelected);
canvas.drawPath(path, paint);
if (leg instanceof Public && !points.isEmpty()) {
final Public publicLeg = (Public) leg;
final int lat;
final int lon;
final int size = points.size();
if (size >= 2) {
final int pivot = size / 2;
final Point p1 = points.get(pivot - 1);
final Point p2 = points.get(pivot);
lat = (p1.lat + p2.lat) / 2;
lon = (p1.lon + p2.lon) / 2;
} else if (size == 1) {
final Point p = points.get(0);
lat = p.lat;
lon = p.lon;
} else {
lat = 0;
lon = 0;
}
projection.toPixels(new GeoPoint(lat, lon), point);
final LineView lineView = (LineView) inflater.inflate(R.layout.map_trip_line, null);
lineView.setLine(publicLeg.line);
lineView.measure(MeasureSpec.makeMeasureSpec(MeasureSpec.UNSPECIFIED, 0),
MeasureSpec.makeMeasureSpec(MeasureSpec.UNSPECIFIED, 0));
final int width = lineView.getMeasuredWidth();
final int height = lineView.getMeasuredHeight();
lineView.layout(point.x - width / 2, point.y - height / 2, point.x + width / 2,
point.y + height / 2);
// since point.x is ignored in layout (why?), we need to translate canvas
// ourselves
canvas.save();
canvas.translate(point.x - width / 2, point.y - height / 2);
lineView.draw(canvas);
canvas.restore();
}
}
}
// then paint decorators
final Leg firstLeg = trip.legs.get(0);
final Leg lastLeg = trip.legs.get(trip.legs.size() - 1);
for (final Trip.Leg leg : trip.legs) {
if (!leg.path.isEmpty()) {
final Point firstPoint = leg.path.get(0);
final Point lastPoint = leg.path.get(leg.path.size() - 1);
if (firstPoint == lastPoint) {
projection.toPixels(new GeoPoint(firstPoint.lat, firstPoint.lon), point);
drawAt(canvas, startIcon, point.x, point.y, false);
} else if (leg == firstLeg || leg == lastLeg) {
if (leg == firstLeg) {
projection.toPixels(new GeoPoint(firstPoint.lat, firstPoint.lon), point);
drawAt(canvas, startIcon, point.x, point.y, false);
}
if (leg == lastLeg) {
projection.toPixels(new GeoPoint(lastPoint.lat, lastPoint.lon), point);
drawAt(canvas, endIcon, point.x, point.y, false);
}
} else {
projection.toPixels(new GeoPoint(firstPoint.lat, firstPoint.lon), point);
drawAt(canvas, pointIcon, point.x, point.y, false);
projection.toPixels(new GeoPoint(lastPoint.lat, lastPoint.lon), point);
drawAt(canvas, pointIcon, point.x, point.y, false);
}
}
}
}
if (locationAware != null) {
final Point deviceLocation = locationAware.getDeviceLocation();
if (deviceLocation != null) {
projection.toPixels(new GeoPoint(deviceLocation.lat, deviceLocation.lon), point);
drawAt(canvas, deviceLocationIcon, point.x, point.y, false);
}
final Location referenceLocation = locationAware.getReferenceLocation();
if (referenceLocation != null) {
projection.toPixels(new GeoPoint(referenceLocation.lat, referenceLocation.lon), point);
drawAt(canvas, referenceLocationIcon, point.x, point.y, false);
}
}
if (stationsAware != null) {
final List<Station> stations = stationsAware.getStations();
if (stations != null) {
Station selectedStation = null;
for (final Station station : stations) {
if (station.location.hasLocation()) {
projection.toPixels(new GeoPoint(station.location.lat, station.location.lon),
point);
if (stationsAware.isSelectedStation(station.location.id)) {
drawAt(canvas, glowIcon, point.x, point.y, false);
selectedStation = station;
}
final Product product = station.getRelevantProduct();
if (product == null)
drawAt(canvas, stationDefaultIcon, point.x, point.y, false);
else if (product == Product.HIGH_SPEED_TRAIN)
drawAt(canvas, stationHighspeedIcon, point.x, point.y, false);
else if (product == Product.REGIONAL_TRAIN)
drawAt(canvas, stationTrainIcon, point.x, point.y, false);
else if (product == Product.SUBURBAN_TRAIN)
drawAt(canvas, stationSuburbanIcon, point.x, point.y, false);
else if (product == Product.SUBWAY)
drawAt(canvas, stationSubwayIcon, point.x, point.y, false);
else if (product == Product.TRAM)
drawAt(canvas, stationTramIcon, point.x, point.y, false);
else if (product == Product.BUS)
drawAt(canvas, stationBusIcon, point.x, point.y, false);
else if (product == Product.FERRY)
drawAt(canvas, stationFerryIcon, point.x, point.y, false);
else if (product == Product.CABLECAR)
drawAt(canvas, stationCablecarIcon, point.x, point.y, false);
else if (product == Product.ON_DEMAND)
drawAt(canvas, stationCallIcon, point.x, point.y, false);
else
drawAt(canvas, stationDefaultIcon, point.x, point.y, false);
}
}
if (selectedStation != null) {
projection.toPixels(
new GeoPoint(selectedStation.location.lat, selectedStation.location.lon),
point);
final TextView bubble = new TextView(getContext());
bubble.setBackgroundResource(R.drawable.popup_dir_pointer_button);
bubble.setText(selectedStation.location.name);
bubble.setTypeface(Typeface.DEFAULT_BOLD);
bubble.setTextSize(TypedValue.COMPLEX_UNIT_PX, stationFontSize);
bubble.setIncludeFontPadding(false);
bubble.measure(MeasureSpec.makeMeasureSpec(MeasureSpec.UNSPECIFIED, 0),
MeasureSpec.makeMeasureSpec(MeasureSpec.UNSPECIFIED, 0));
final int width = bubble.getMeasuredWidth();
final int height = bubble.getMeasuredHeight();
bubble.layout(point.x - width / 2, point.y - height / 2, point.x + width / 2,
point.y + height / 2);
// since point.x is ignored in layout (why?), we need to translate canvas
// ourselves
canvas.save();
canvas.translate(point.x - width / 2,
point.y - height - stationDefaultIcon.getIntrinsicHeight() / 2.5f);
bubble.draw(canvas);
canvas.restore();
}
}
}
}
}
private Path pointsToPath(final Projection projection, final List<Point> points) {
final Path path = new Path();
path.incReserve(points.size());
final android.graphics.Point point = new android.graphics.Point();
for (final Point p : points) {
projection.toPixels(new GeoPoint(p.lat, p.lon), point);
if (path.isEmpty())
path.moveTo(point.x, point.y);
else
path.lineTo(point.x, point.y);
}
return path;
}
private Path pointsToPath(final Projection projection, final Point[] points) {
final Path path = new Path();
path.incReserve(points.length);
final android.graphics.Point point = new android.graphics.Point();
for (final Point p : points) {
projection.toPixels(new GeoPoint(p.lat, p.lon), point);
if (path.isEmpty())
path.moveTo(point.x, point.y);
else
path.lineTo(point.x, point.y);
}
return path;
}
@Override
public boolean onTap(final GeoPoint p, final MapView mapView) {
final double tappedLat = p.getLatitudeE6() / 1E6;
final double tappedLon = p.getLongitudeE6() / 1E6;
boolean consumed = false;
final float[] distanceBetweenResults = new float[1];
if (tripAware != null) {
int tappedLegIndex = -1;
float tappedPointDistance = 0;
int iRoute = 0;
for (final Leg leg : tripAware.getTrip().legs) {
for (final Point point : leg.path) {
android.location.Location.distanceBetween(tappedLat, tappedLon, point.lat / 1E6,
point.lon / 1E6, distanceBetweenResults);
final float distance = distanceBetweenResults[0];
if (tappedLegIndex == -1 || distance < tappedPointDistance) {
tappedLegIndex = iRoute;
tappedPointDistance = distance;
}
}
iRoute++;
}
if (tappedLegIndex != -1) {
tripAware.selectLeg(tappedLegIndex);
consumed = true;
}
}
if (stationsAware != null) {
Station tappedStation = null;
float tappedStationDistance = 0;
for (final Station station : stationsAware.getStations()) {
android.location.Location.distanceBetween(tappedLat, tappedLon, station.location.lat / 1E6,
station.location.lon / 1E6, distanceBetweenResults);
final float distance = distanceBetweenResults[0];
if (tappedStation == null || distance < tappedStationDistance) {
tappedStation = station;
tappedStationDistance = distance;
}
}
if (locationAware != null) {
if (tappedStation == null) {
stationsAware.selectStation(null);
consumed = true;
} else {
final Point deviceLocation = locationAware.getDeviceLocation();
if (deviceLocation != null) {
android.location.Location.distanceBetween(tappedLat, tappedLon,
deviceLocation.lat / 1E6, deviceLocation.lon / 1E6, distanceBetweenResults);
final float distance = distanceBetweenResults[0];
if (distance < tappedStationDistance) {
stationsAware.selectStation(null);
consumed = true;
}
}
}
}
if (!consumed && tappedStation != null) {
stationsAware.selectStation(tappedStation);
consumed = true;
}
}
return consumed;
}
});
}
public void setFromViaToAware(final FromViaToAware fromViaToAware) {
this.fromViaToAware = fromViaToAware;
invalidate();
}
public void setTripAware(final TripAware tripAware) {
this.tripAware = tripAware;
invalidate();
}
public void setStationsAware(final StationsAware stationsAware) {
this.stationsAware = stationsAware;
invalidate();
}
public void setLocationAware(final LocationAware locationAware) {
this.locationAware = locationAware;
invalidate();
}
public void setAreaAware(final AreaAware areaAware) {
this.areaAware = areaAware;
invalidate();
}
public void animateToLocation(final int lat, final int lon) {
if (lat == 0 && lon == 0)
return;
final GeoPoint point = new GeoPoint(lat, lon);
if (firstLocation)
getController().setCenter(point);
else
getController().animateTo(point);
firstLocation = false;
}
public void zoomToAll(final int maxZoomLevel) {
zoomLocked = true;
final boolean hasLegSelection = tripAware != null && tripAware.hasSelection();
int minLat = Integer.MAX_VALUE, maxLat = Integer.MIN_VALUE;
int minLon = Integer.MAX_VALUE, maxLon = Integer.MIN_VALUE;
boolean anything = false;
if (areaAware != null) {
final Point[] area = areaAware.getArea();
if (area != null) {
for (final Point p : area) {
final int lat = p.lat;
final int lon = p.lon;
if (lat < minLat)
minLat = lat;
if (lat > maxLat)
maxLat = lat;
if (lon < minLon)
minLon = lon;
if (lon > maxLon)
maxLon = lon;
anything = true;
}
}
}
if (fromViaToAware != null) {
final Point from = fromViaToAware.getFrom();
if (from != null) {
if (from.lat < minLat)
minLat = from.lat;
if (from.lat > maxLat)
maxLat = from.lat;
if (from.lon < minLon)
minLon = from.lon;
if (from.lon > maxLon)
maxLon = from.lon;
anything = true;
}
final Point via = fromViaToAware.getVia();
if (via != null) {
if (via.lat < minLat)
minLat = via.lat;
if (via.lat > maxLat)
maxLat = via.lat;
if (via.lon < minLon)
minLon = via.lon;
if (via.lon > maxLon)
maxLon = via.lon;
anything = true;
}
final Point to = fromViaToAware.getTo();
if (to != null) {
if (to.lat < minLat)
minLat = to.lat;
if (to.lat > maxLat)
maxLat = to.lat;
if (to.lon < minLon)
minLon = to.lon;
if (to.lon > maxLon)
maxLon = to.lon;
anything = true;
}
}
if (tripAware != null) {
for (final Leg leg : tripAware.getTrip().legs) {
if (!hasLegSelection || tripAware.isSelectedLeg(leg)) {
for (final Point p : leg.path) {
final int lat = p.lat;
final int lon = p.lon;
if (lat < minLat)
minLat = lat;
if (lat > maxLat)
maxLat = lat;
if (lon < minLon)
minLon = lon;
if (lon > maxLon)
maxLon = lon;
anything = true;
}
}
}
}
if (locationAware != null && !hasLegSelection) {
final Location referenceLocation = locationAware.getReferenceLocation();
if (referenceLocation != null) {
if (referenceLocation.lat < minLat)
minLat = referenceLocation.lat;
if (referenceLocation.lat > maxLat)
maxLat = referenceLocation.lat;
if (referenceLocation.lon < minLon)
minLon = referenceLocation.lon;
if (referenceLocation.lon > maxLon)
maxLon = referenceLocation.lon;
anything = true;
} else {
final Point location = locationAware.getDeviceLocation();
if (location != null) {
if (location.lat < minLat)
minLat = location.lat;
if (location.lat > maxLat)
maxLat = location.lat;
if (location.lon < minLon)
minLon = location.lon;
if (location.lon > maxLon)
maxLon = location.lon;
anything = true;
}
}
}
if (anything) {
final MapController controller = getController();
final float spanLat = (maxLat - minLat) * 1.1f;
final float spanLon = (maxLon - minLon) * 1.1f;
controller.zoomToSpan((int) spanLat, (int) spanLon);
if (getZoomLevel() > maxZoomLevel)
controller.setZoom(maxZoomLevel);
final int centerLat = (maxLat + minLat) / 2;
final int centerLon = (maxLon + minLon) / 2;
controller.setCenter(new GeoPoint(centerLat, centerLon));
}
}
@Override
protected void onSizeChanged(final int w, final int h, final int oldw, final int oldh) {
if (zoomLocked)
zoomToAll(Constants.INITIAL_MAP_ZOOM_LEVEL);
super.onSizeChanged(w, h, oldw, oldh);
}
@Override
public boolean onTouchEvent(final MotionEvent ev) {
zoomLocked = false;
return super.onTouchEvent(ev);
}
private Drawable drawablePointer(final int resId, final int sizeDivider) {
final Resources res = getResources();
final Drawable drawable = res.getDrawable(resId);
drawable.setBounds(-drawable.getIntrinsicWidth() / sizeDivider, -drawable.getIntrinsicHeight(),
drawable.getIntrinsicWidth() / sizeDivider, 0);
return drawable;
}
private Drawable drawableCenter(final int resId, final int sizeDivider) {
final Resources res = getResources();
final Drawable drawable = res.getDrawable(resId);
drawable.setBounds(-drawable.getIntrinsicWidth() / sizeDivider, -drawable.getIntrinsicHeight() / sizeDivider,
drawable.getIntrinsicWidth() / sizeDivider, drawable.getIntrinsicHeight() / sizeDivider);
return drawable;
}
}

View file

@ -36,9 +36,16 @@ import javax.net.ssl.SSLException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import de.schildbach.oeffi.Constants;
import de.schildbach.oeffi.FromViaToAware;
import de.schildbach.oeffi.MyActionBar;
import de.schildbach.oeffi.OeffiMainActivity;
import de.schildbach.oeffi.OeffiMapView;
import de.schildbach.oeffi.R;
import de.schildbach.oeffi.directions.TimeSpec.DepArr;
import de.schildbach.oeffi.directions.list.QueryHistoryAdapter;
@ -55,6 +62,7 @@ import de.schildbach.oeffi.util.ConnectivityBroadcastReceiver;
import de.schildbach.oeffi.util.DialogBuilder;
import de.schildbach.oeffi.util.DividerItemDecoration;
import de.schildbach.oeffi.util.Formats;
import de.schildbach.oeffi.util.GeocoderThread;
import de.schildbach.oeffi.util.LocationUriParser;
import de.schildbach.oeffi.util.Toast;
import de.schildbach.oeffi.util.ToggleImageButton;
@ -68,6 +76,7 @@ import de.schildbach.pte.NetworkProvider.Option;
import de.schildbach.pte.NetworkProvider.WalkSpeed;
import de.schildbach.pte.dto.Location;
import de.schildbach.pte.dto.LocationType;
import de.schildbach.pte.dto.Point;
import de.schildbach.pte.dto.Product;
import de.schildbach.pte.dto.QueryTripsResult;
import de.schildbach.pte.dto.SuggestLocationsResult;
@ -89,7 +98,9 @@ import android.content.DialogInterface.OnCancelListener;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.database.Cursor;
import android.location.Address;
import android.net.ConnectivityManager;
import android.net.Uri;
import android.os.Bundle;
@ -140,6 +151,7 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
private RecyclerView viewQueryHistoryList;
private QueryHistoryAdapter queryHistoryListAdapter;
private TextView connectivityWarningView;
private OeffiMapView mapView;
private TimeSpec time = null;
@ -256,6 +268,8 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
expandForm();
else
collapseForm();
updateMap();
}
});
actionBar.addButton(R.drawable.ic_shuffle_white_24dp, R.string.directions_action_return_trip_title)
@ -292,6 +306,7 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
final LocationView.Listener locationChangeListener = new LocationView.Listener() {
public void changed() {
updateMap();
queryHistoryListAdapter.clearSelectedEntry();
requestFocusFirst();
}
@ -413,6 +428,57 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
queryHistoryListAdapter = new QueryHistoryAdapter(this, network, this, this);
viewQueryHistoryList.setAdapter(queryHistoryListAdapter);
mapView = (OeffiMapView) findViewById(R.id.directions_map);
mapView.getOverlays().add(new Overlay() {
private Location pinLocation;
@Override
public boolean onTap(final GeoPoint p, final MapView mapView) {
pinLocation = Location.coord(p.getLatitudeE6(), p.getLongitudeE6());
final View view = getLayoutInflater().inflate(R.layout.directions_map_pin, null);
final LocationTextView locationView = (LocationTextView) view
.findViewById(R.id.directions_map_pin_location);
final View buttonGroup = view.findViewById(R.id.directions_map_pin_buttons);
buttonGroup.findViewById(R.id.directions_map_pin_button_from).setOnClickListener(new OnClickListener() {
public void onClick(final View v) {
viewFromLocation.setLocation(pinLocation);
mapView.removeAllViews();
}
});
buttonGroup.findViewById(R.id.directions_map_pin_button_to).setOnClickListener(new OnClickListener() {
public void onClick(final View v) {
viewToLocation.setLocation(pinLocation);
mapView.removeAllViews();
}
});
locationView.setLocation(pinLocation);
locationView.setShowLocationType(false);
mapView.removeAllViews();
mapView.addView(view, new MapView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT, p, MapView.LayoutParams.BOTTOM_CENTER));
new GeocoderThread(DirectionsActivity.this, p.getLatitudeE6() / 1E6, p.getLongitudeE6() / 1E6,
new GeocoderThread.Callback() {
public void onGeocoderResult(final Address address) {
pinLocation = LocationView.addressToLocation(address);
locationView.setLocation(pinLocation);
locationView.setShowLocationType(false);
}
public void onGeocoderFail(final Exception exception) {
log.info("Problem in geocoder: {}", exception.getMessage());
}
});
final MapController controller = mapView.getController();
controller.animateTo(p);
return false;
}
});
connectivityReceiver = new ConnectivityBroadcastReceiver(connectivityManager) {
@Override
protected void onConnected() {
@ -490,6 +556,8 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
setActionBarSecondaryTitleFromNetwork();
updateGUI();
updateMap();
updateFragments();
}
@Override
@ -555,6 +623,13 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
super.onDestroy();
}
@Override
public void onConfigurationChanged(final Configuration config) {
super.onConfigurationChanged(config);
updateFragments();
}
@Override
public void onBackPressed() {
if (isNavigationOpen())
@ -572,6 +647,10 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
viewGo.requestFocus();
}
private void updateFragments() {
updateFragments(R.id.navigation_drawer_layout, R.id.directions_map_fragment);
}
private void updateGUI() {
viewFromLocation.setHint(R.string.directions_from);
viewViaLocation.setHint(R.string.directions_via);
@ -674,6 +753,33 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom
builder.show();
}
private void updateMap() {
mapView.removeAllViews();
mapView.setFromViaToAware(new FromViaToAware() {
public Point getFrom() {
final Location from = viewFromLocation.getLocation();
if (from == null || !from.hasLocation())
return null;
return new Point(from.lat, from.lon);
}
public Point getVia() {
final Location via = viewViaLocation.getLocation();
if (via == null || !via.hasLocation() || viewViaLocation.getVisibility() != View.VISIBLE)
return null;
return new Point(via.lat, via.lon);
}
public Point getTo() {
final Location to = viewToLocation.getLocation();
if (to == null || !to.hasLocation())
return null;
return new Point(to.lat, to.lon);
}
});
mapView.zoomToAll(Constants.INITIAL_MAP_ZOOM_LEVEL);
}
private void expandForm() {
initLayoutTransitions(true);

View file

@ -34,7 +34,9 @@ import de.schildbach.oeffi.Constants;
import de.schildbach.oeffi.LocationAware;
import de.schildbach.oeffi.MyActionBar;
import de.schildbach.oeffi.OeffiActivity;
import de.schildbach.oeffi.OeffiMapView;
import de.schildbach.oeffi.R;
import de.schildbach.oeffi.TripAware;
import de.schildbach.oeffi.directions.TimeSpec.DepArr;
import de.schildbach.oeffi.stations.LineView;
import de.schildbach.oeffi.stations.NetworkContentProvider;
@ -65,6 +67,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Color;
@ -118,6 +121,7 @@ public class TripDetailsActivity extends OeffiActivity implements LocationListen
private BroadcastReceiver tickReceiver;
private ViewGroup legsGroup;
private OeffiMapView mapView;
private ToggleImageButton trackButton;
private NetworkId network;
@ -125,6 +129,7 @@ public class TripDetailsActivity extends OeffiActivity implements LocationListen
private Date highlightedTime;
private Location highlightedLocation;
private Point location;
private int selectedLegIndex = -1;
private final Map<Leg, Boolean> legExpandStates = new HashMap<>();
private Intent scheduleTripIntent;
@ -223,12 +228,16 @@ public class TripDetailsActivity extends OeffiActivity implements LocationListen
location = LocationHelper.locationToPoint(lastKnownLocation);
else
location = null;
mapView.setLocationAware(TripDetailsActivity.this);
}
} else {
locationManager.removeUpdates(TripDetailsActivity.this);
location = null;
mapView.setLocationAware(null);
}
mapView.zoomToAll(Constants.INITIAL_MAP_ZOOM_LEVEL);
updateGUI();
}
});
@ -281,6 +290,31 @@ public class TripDetailsActivity extends OeffiActivity implements LocationListen
final TextView disclaimerSourceView = (TextView) findViewById(R.id.directions_trip_details_disclaimer_source);
updateDisclaimerSource(disclaimerSourceView, network.name(), null);
mapView = (OeffiMapView) findViewById(R.id.directions_trip_details_map);
mapView.setTripAware(new TripAware() {
public Trip getTrip() {
return trip;
}
public void selectLeg(final int partIndex) {
selectedLegIndex = partIndex;
mapView.invalidate();
mapView.zoomToAll(Constants.INITIAL_MAP_ZOOM_LEVEL);
}
public boolean hasSelection() {
return selectedLegIndex != -1;
}
public boolean isSelectedLeg(final Leg part) {
if (!hasSelection())
return false;
return trip.legs.get(selectedLegIndex).equals(part);
}
});
mapView.zoomToAll(Constants.INITIAL_MAP_ZOOM_LEVEL);
}
@Override
@ -297,6 +331,7 @@ public class TripDetailsActivity extends OeffiActivity implements LocationListen
registerReceiver(tickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK));
updateGUI();
updateFragments();
}
@Override
@ -321,6 +356,13 @@ public class TripDetailsActivity extends OeffiActivity implements LocationListen
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
}
@Override
public void onConfigurationChanged(final Configuration config) {
super.onConfigurationChanged(config);
updateFragments();
}
private String requestLocationUpdates() {
final Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
@ -347,6 +389,10 @@ public class TripDetailsActivity extends OeffiActivity implements LocationListen
public void onProviderDisabled(final String provider) {
locationManager.removeUpdates(TripDetailsActivity.this);
final String newProvider = requestLocationUpdates();
if (newProvider == null)
mapView.setLocationAware(null);
}
public void onStatusChanged(final String provider, final int status, final Bundle extras) {
@ -364,6 +410,10 @@ public class TripDetailsActivity extends OeffiActivity implements LocationListen
return null;
}
private void updateFragments() {
updateFragments(R.id.directions_trip_details_list_frame, R.id.directions_trip_details_map_frame);
}
private void updateGUI() {
final Date now = new Date();
updateHighlightedTime(now);
@ -378,6 +428,7 @@ public class TripDetailsActivity extends OeffiActivity implements LocationListen
i++;
}
mapView.invalidate();
}
private void updateHighlightedTime(final Date now) {

View file

@ -31,8 +31,13 @@ import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.android.maps.MapActivity;
import de.schildbach.oeffi.AreaAware;
import de.schildbach.oeffi.Constants;
import de.schildbach.oeffi.LocationAware;
import de.schildbach.oeffi.MyActionBar;
import de.schildbach.oeffi.OeffiMapView;
import de.schildbach.oeffi.R;
import de.schildbach.oeffi.network.list.NetworkClickListener;
import de.schildbach.oeffi.network.list.NetworkContextMenuItemListener;
@ -46,16 +51,17 @@ import de.schildbach.oeffi.util.LocationHelper;
import de.schildbach.pte.AbstractNavitiaProvider;
import de.schildbach.pte.NetworkId;
import de.schildbach.pte.NetworkProvider;
import de.schildbach.pte.dto.Location;
import de.schildbach.pte.dto.Point;
import android.Manifest;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.ActivityManager.TaskDescription;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.location.Address;
import android.location.Criteria;
@ -73,8 +79,9 @@ import android.support.v7.widget.RecyclerView;
import android.view.KeyEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
public class NetworkPickerActivity extends Activity implements ActivityCompat.OnRequestPermissionsResultCallback,
public class NetworkPickerActivity extends MapActivity implements ActivityCompat.OnRequestPermissionsResultCallback,
LocationHelper.Callback, NetworkClickListener, NetworkContextMenuItemListener {
public static void start(final Context context) {
final Intent intent = new Intent(context, NetworkPickerActivity.class);
@ -86,6 +93,7 @@ public class NetworkPickerActivity extends Activity implements ActivityCompat.On
private MyActionBar actionBar;
private RecyclerView listView;
private NetworksAdapter listAdapter;
private OeffiMapView mapView;
private final List<NetworkId> lastNetworks = new LinkedList<>();
@ -128,6 +136,8 @@ public class NetworkPickerActivity extends Activity implements ActivityCompat.On
listAdapter = new NetworksAdapter(this, network, this, this);
listView.setAdapter(listAdapter);
mapView = (OeffiMapView) findViewById(R.id.network_picker_map);
if (network == null) {
((FrameLayout) findViewById(R.id.network_picker_firsttime_message_shadow)).setForeground(null);
} else {
@ -137,6 +147,40 @@ public class NetworkPickerActivity extends Activity implements ActivityCompat.On
finish();
}
});
final NetworkId networkId = prefsGetNetworkId();
if (networkId != null) {
backgroundHandler.post(new GetAreaRunnable(NetworkProviderFactory.provider(networkId), handler) {
@Override
protected void onResult(final Point[] area) {
mapView.setAreaAware(new AreaAware() {
final Point[] myArea = area != null && area.length > 1 ? area : null;
public Point[] getArea() {
return myArea;
}
});
mapView.setLocationAware(new LocationAware() {
final Location referenceLocation = area != null && area.length == 1
? Location.coord(area[0]) : null;
public Point getDeviceLocation() {
return deviceLocation;
}
public Location getReferenceLocation() {
return referenceLocation;
}
public Float getDeviceBearing() {
return null;
}
});
mapView.zoomToAll(Constants.INITIAL_MAP_ZOOM_LEVEL_NETWORK);
}
});
}
}
loadLastNetworks();
@ -154,6 +198,7 @@ public class NetworkPickerActivity extends Activity implements ActivityCompat.On
protected void onStart() {
super.onStart();
updateFragments();
maybeStartLocation();
}
@ -210,6 +255,8 @@ public class NetworkPickerActivity extends Activity implements ActivityCompat.On
deviceLocation = here;
mapView.animateToLocation(here.lat, here.lon);
parseIndex();
updateGUI();
@ -232,6 +279,13 @@ public class NetworkPickerActivity extends Activity implements ActivityCompat.On
});
}
@Override
public void onConfigurationChanged(final Configuration config) {
super.onConfigurationChanged(config);
updateFragments();
}
@Override
public boolean onKeyDown(final int keyCode, final KeyEvent event) {
// disable back key if no network is selected
@ -267,8 +321,25 @@ public class NetworkPickerActivity extends Activity implements ActivityCompat.On
}
}
private void updateFragments() {
final Resources res = getResources();
final View listFrame = findViewById(R.id.network_picker_list_frame);
final boolean listShow = res.getBoolean(R.bool.layout_list_show);
listFrame.setVisibility(isInMultiWindowMode() || listShow ? View.VISIBLE : View.GONE);
final View mapFrame = findViewById(R.id.network_picker_map_frame);
final boolean mapShow = res.getBoolean(R.bool.layout_map_show);
mapFrame.setVisibility(!isInMultiWindowMode() && mapShow ? View.VISIBLE : View.GONE);
final LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) listFrame.getLayoutParams();
layoutParams.width = listShow && mapShow ? res.getDimensionPixelSize(R.dimen.layout_list_width)
: LinearLayout.LayoutParams.MATCH_PARENT;
}
private void updateGUI() {
listAdapter.notifyDataSetChanged();
mapView.invalidate();
}
private String prefsGetNetwork() {
@ -490,6 +561,11 @@ public class NetworkPickerActivity extends Activity implements ActivityCompat.On
prefs.edit().putString(Constants.PREFS_KEY_LAST_NETWORK_PROVIDERS, prefsValue.toString()).commit();
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
protected final void setPrimaryColor(final int colorResId) {
final int color = getResources().getColor(colorResId);
actionBar.setBackgroundColor(color);

View file

@ -35,12 +35,14 @@ import javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.android.maps.GeoPoint;
import com.google.common.base.Joiner;
import com.google.common.base.Strings;
import de.schildbach.oeffi.Constants;
import de.schildbach.oeffi.MyActionBar;
import de.schildbach.oeffi.OeffiActivity;
import de.schildbach.oeffi.OeffiMapView;
import de.schildbach.oeffi.R;
import de.schildbach.oeffi.StationsAware;
import de.schildbach.oeffi.network.NetworkProviderFactory;
@ -64,6 +66,7 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Typeface;
@ -127,6 +130,7 @@ public class StationDetailsActivity extends OeffiActivity implements StationsAwa
private DeparturesAdapter listAdapter;
private TextView resultStatusView;
private TextView disclaimerSourceView;
private OeffiMapView mapView;
private BroadcastReceiver tickReceiver;
@ -187,6 +191,9 @@ public class StationDetailsActivity extends OeffiActivity implements StationsAwa
listAdapter = new DeparturesAdapter(this);
listView.setAdapter(listAdapter);
mapView = (OeffiMapView) findViewById(R.id.stations_station_details_map);
mapView.setStationsAware(this);
resultStatusView = (TextView) findViewById(R.id.stations_station_details_result_status);
final Intent intent = getIntent();
@ -292,6 +299,8 @@ public class StationDetailsActivity extends OeffiActivity implements StationsAwa
registerReceiver(tickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK));
load();
updateFragments();
}
@Override
@ -316,6 +325,17 @@ public class StationDetailsActivity extends OeffiActivity implements StationsAwa
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
}
@Override
public void onConfigurationChanged(final Configuration config) {
super.onConfigurationChanged(config);
updateFragments();
}
private void updateFragments() {
updateFragments(R.id.stations_station_details_list_fragment, R.id.stations_station_details_map_fragment);
}
private void updateGUI() {
final List<Departure> selectedDepartures = this.selectedDepartures;
if (selectedDepartures != null) {
@ -517,6 +537,9 @@ public class StationDetailsActivity extends OeffiActivity implements StationsAwa
selectedFavState = FavoriteStationsProvider.favState(getContentResolver(), selectedNetwork, selectedStation);
if (selectedStation.hasLocation())
mapView.getController().animateTo(new GeoPoint(selectedStation.lat, selectedStation.lon));
updateGUI();
actionBar.setPrimaryTitle(selectedStation.name);

View file

@ -40,6 +40,7 @@ import javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.android.maps.GeoPoint;
import com.google.common.base.Strings;
import com.google.common.collect.ComparisonChain;
import com.google.common.collect.Ordering;
@ -49,6 +50,7 @@ import de.schildbach.oeffi.Constants;
import de.schildbach.oeffi.LocationAware;
import de.schildbach.oeffi.MyActionBar;
import de.schildbach.oeffi.OeffiMainActivity;
import de.schildbach.oeffi.OeffiMapView;
import de.schildbach.oeffi.R;
import de.schildbach.oeffi.StationsAware;
import de.schildbach.oeffi.directions.DirectionsActivity;
@ -85,6 +87,7 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.ContentObserver;
import android.database.Cursor;
@ -148,6 +151,7 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
private String accurateLocationProvider, lowPowerLocationProvider;
private MyActionBar actionBar;
private OeffiMapView stationMap;
private RecyclerView stationList;
private LinearLayoutManager stationListLayoutManager;
private StationsAdapter stationListAdapter;
@ -237,6 +241,7 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
}
stationListAdapter.notifyDataSetChanged();
stationMap.invalidate();
}
updateGUI();
@ -286,6 +291,10 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
final Button missingCapabilityButton = (Button) findViewById(R.id.stations_network_missing_capability_button);
missingCapabilityButton.setOnClickListener(selectNetworkListener);
stationMap = (OeffiMapView) findViewById(R.id.stations_map);
stationMap.setStationsAware(this);
stationMap.setLocationAware(this);
connectivityWarningView = (TextView) findViewById(R.id.stations_connectivity_warning_box);
disclaimerSourceView = (TextView) findViewById(R.id.stations_disclaimer_source);
@ -478,6 +487,8 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
registerReceiver(tickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK));
}
stationMap.zoomToAll(Constants.INITIAL_MAP_ZOOM_LEVEL);
setActionBarSecondaryTitleFromNetwork();
updateGUI();
}
@ -497,6 +508,7 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
stationsMap.clear();
stationListAdapter.notifyDataSetChanged();
stationMap.invalidate();
loading = true;
updateDisclaimerSource(disclaimerSourceView, network.name(), null);
@ -507,6 +519,17 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
handler.post(initStationsRunnable);
}
@Override
public void onConfigurationChanged(final Configuration config) {
super.onConfigurationChanged(config);
updateFragments();
}
private void updateFragments() {
updateFragments(R.id.navigation_drawer_layout, R.id.stations_map_fragment);
}
@Override
protected void onPause() {
saveProductFilter();
@ -563,11 +586,15 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
fixedLocation = locations != null && locations.length >= 1 ? locations[0] : null;
if (fixedLocation != null) {
stationMap.animateToLocation(fixedLocation.lat, fixedLocation.lon);
findViewById(R.id.stations_location_clear).setOnClickListener(new OnClickListener() {
public void onClick(final View v) {
fixedLocation = null;
if (deviceLocation != null) {
stationMap.animateToLocation(deviceLocation.lat, deviceLocation.lon);
final float[] distanceBetweenResults = new float[2];
// remove non-favorites and re-calculate distances
@ -645,6 +672,9 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
}
private void updateGUI() {
// fragments
updateFragments();
// filter indicator
final boolean isActive = products.size() < Product.values().length;
filterActionButton.setSelected(isActive);
@ -985,6 +1015,7 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
if (added || changed) {
stationListAdapter.notifyDataSetChanged();
stationMap.invalidate();
}
updateGUI();
@ -1273,6 +1304,12 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
}
}
// scroll map
if (station != null && station.location.hasLocation())
stationMap.getController().animateTo(new GeoPoint(station.location.lat, station.location.lon));
else if (station == null && deviceLocation != null)
stationMap.getController().animateTo(new GeoPoint(deviceLocation.lat, deviceLocation.lon));
postLoadNextVisible(0);
}
@ -1431,6 +1468,9 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware
final double hereLat = here.getLatitude();
final double hereLon = here.getLongitude();
if (deviceLocation == null && fixedLocation == null)
stationMap.animateToLocation((int) (hereLat * 1E6), (int) (hereLon * 1E6));
deviceLocation = Point.fromDouble(hereLat, hereLon);
stationListAdapter.setDeviceLocation(here);