From cffd20848d54178430e6780fce6de99f7359d4d7 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 3 Aug 2010 19:21:45 +0000 Subject: [PATCH] fix layout for different screen support git-svn-id: https://osmand.googlecode.com/svn/trunk@433 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8 --- .../src/com/osmand/ToDoConstants.java | 22 ++++++------- .../res/layout-large/route_info_list_item.xml | 17 ++++++++++ OsmAnd/res/layout/route_info_list_item.xml | 8 ++--- .../activities/ShowRouteInfoActivity.java | 31 ++++++++++++++++--- OsmAnd/src/com/osmand/views/MapInfoLayer.java | 4 ++- .../com/osmand/views/PointLocationLayer.java | 31 ++++++++++++------- .../osmand/views/PointNavigationLayer.java | 15 ++++++--- .../src/com/osmand/views/RouteInfoLayer.java | 8 ++--- 8 files changed, 95 insertions(+), 41 deletions(-) create mode 100644 OsmAnd/res/layout-large/route_info_list_item.xml diff --git a/DataExtractionOSM/src/com/osmand/ToDoConstants.java b/DataExtractionOSM/src/com/osmand/ToDoConstants.java index bafe493fa6..eca7d8fb11 100644 --- a/DataExtractionOSM/src/com/osmand/ToDoConstants.java +++ b/DataExtractionOSM/src/com/osmand/ToDoConstants.java @@ -8,22 +8,28 @@ package com.osmand; */ public class ToDoConstants { + // TODO swing + // 9. Fix issues with big files (such as netherlands) - save memory (!) - very slow due to transport index ! + // Current result : for big file (1 - task 60-80% time, 90% memory) (?) + // !! 10. Improve address indexing (use relations). (?) // SLOBODSKAYA 157, 95 + // use relation "a6" (to accumulate streets!), "a3" to read all cities & define boundaries for city (& define that street in city). + // TODO max 85 // ! 81. Add some objects to POI category (1) to add them into OSM 2) to help navigation) // highway (?), traffic_calming (?), barrier(?), military(?-), landuse (?), office(?), man_made(?), power(?), // railway( station, subway?) - issue 17 // 82. Rotate map according compass - // TODO BUGS Android // !! 3. different screens better support /// 3.1 after search_address_online.xml (+) - // 3.2 Fix all layers (MapInfoLayer, RouteInfoLayer!) + // 3.2 Fix all layers (RouteInfoLayer+! // FavoritesLayer, OsmBugsLayer, POIMapLayer, TransportInfoLayer, TransportStopsLayer (+) - // PointLocationLayer, PointNavigationLayer, YandexTrafficLayer - // 3.3 route_info_list_item.xml - ShowRouteInfoActivity, main.xml + // PointLocationLayer, PointNavigationLayer, YandexTrafficLayer(+) + // 3.3 route_info_list_item.xml, ShowRouteInfoActivity, main.xml (+) // 3.4 Fix map zoom by default map (in 1.5 for high density) OsmandMapTileView - // 3.5 Touch distance events : MultiTouchSupport, AnimateDraggingMapThread (? timeMove) + // 3.5 MapInfoLayer + // 3.6 Touch distance events : MultiTouchSupport, AnimateDraggingMapThread (? timeMove) // 4. Icon back to location (+) // Improvements @@ -44,12 +50,6 @@ public class ToDoConstants { // 63. Support simple offline routing(require new index file) (?) - // TODO swing - // 9. Fix issues with big files (such as netherlands) - save memory (!) - very slow due to transport index ! - // Current result : for big file (1 - task 60-80% time, 90% memory) (?) - // !! 10. Improve address indexing (use relations). (?) // SLOBODSKAYA 157, 95 - // use relation "a6" (to accumulate streets!), "a3" to read all cities & define boundaries for city (& define that street in city). - // BUGS Swing // DONE ANDROID : diff --git a/OsmAnd/res/layout-large/route_info_list_item.xml b/OsmAnd/res/layout-large/route_info_list_item.xml new file mode 100644 index 0000000000..222e27af1f --- /dev/null +++ b/OsmAnd/res/layout-large/route_info_list_item.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + diff --git a/OsmAnd/res/layout/route_info_list_item.xml b/OsmAnd/res/layout/route_info_list_item.xml index fe414738a2..054eda2417 100644 --- a/OsmAnd/res/layout/route_info_list_item.xml +++ b/OsmAnd/res/layout/route_info_list_item.xml @@ -4,12 +4,12 @@ android:layout_width="fill_parent" android:layout_height="wrap_content"> - - + - - diff --git a/OsmAnd/src/com/osmand/activities/ShowRouteInfoActivity.java b/OsmAnd/src/com/osmand/activities/ShowRouteInfoActivity.java index 9d1eb15ef8..5cff412bd9 100644 --- a/OsmAnd/src/com/osmand/activities/ShowRouteInfoActivity.java +++ b/OsmAnd/src/com/osmand/activities/ShowRouteInfoActivity.java @@ -14,10 +14,12 @@ import android.graphics.ColorFilter; import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.Path; +import android.graphics.Rect; import android.graphics.Paint.Style; import android.graphics.drawable.Drawable; import android.location.Location; import android.os.Bundle; +import android.util.DisplayMetrics; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -41,6 +43,7 @@ public class ShowRouteInfoActivity extends ListActivity { private RoutingHelper helper; private TextView header; + private DisplayMetrics dm; @Override public void onCreate(Bundle icicle) { @@ -52,6 +55,8 @@ public class ShowRouteInfoActivity extends ListActivity { lv.addHeaderView(header); setContentView(lv); + dm = new DisplayMetrics(); + getWindowManager().getDefaultDisplay().getMetrics(dm); } @Override @@ -61,11 +66,19 @@ public class ShowRouteInfoActivity extends ListActivity { int hours = helper.getLeftTime() / (60 * 60); int minutes = (helper.getLeftTime() / 60) % 60; header.setText(MessageFormat.format(getString(R.string.route_general_information), MapUtils.getFormattedDistance(dist), - hours, minutes)); + hours, minutes)); + float f = Math.min(dm.widthPixels/dm.densityDpi,dm.heightPixels/dm.densityDpi); + if (f >= 3) { + // large screen + header.setTextSize(dm.scaledDensity * 23); + } setListAdapter(new RouteInfoAdapter(RoutingHelper.getInstance(this).getRouteDirections())); } public void onListItemClick(ListView parent, View v, int position, long id) { + if(position == 0){ + return; + } RouteDirectionInfo item = ((RouteInfoAdapter)getListAdapter()).getItem(position - 1); Location loc = helper.getLocationFromRouteDirection(item); if(loc != null){ @@ -78,23 +91,31 @@ public class ShowRouteInfoActivity extends ListActivity { class RouteDrawable extends Drawable { Paint paintRouteDirection; Path p = new Path(); - Matrix m = new Matrix(); + Path dp = new Path(); + public RouteDrawable(){ - m.setScale(0.33f, 0.33f); paintRouteDirection = new Paint(); paintRouteDirection.setStyle(Style.FILL_AND_STROKE); paintRouteDirection.setColor(Color.rgb(100, 0, 255)); paintRouteDirection.setAntiAlias(true); } + + @Override + protected void onBoundsChange(Rect bounds) { + Matrix m = new Matrix(); + m.setScale(bounds.width()/96f, bounds.height()/96f); + p.transform(m, dp); + } public void setRouteType(TurnType t){ - MapInfoLayer.calcTurnPath(p, t, m); + MapInfoLayer.calcTurnPath(p, t, null); + onBoundsChange(getBounds()); } @Override public void draw(Canvas canvas) { - canvas.drawPath(p, paintRouteDirection); + canvas.drawPath(dp, paintRouteDirection); } @Override diff --git a/OsmAnd/src/com/osmand/views/MapInfoLayer.java b/OsmAnd/src/com/osmand/views/MapInfoLayer.java index e5d834d60a..263af8d2e2 100644 --- a/OsmAnd/src/com/osmand/views/MapInfoLayer.java +++ b/OsmAnd/src/com/osmand/views/MapInfoLayer.java @@ -494,7 +494,9 @@ public class MapInfoLayer implements OsmandMapLayer { pathForTurn.close(); } pathForTurn.close(); - pathForTurn.transform(transform); + if(transform != null){ + pathForTurn.transform(transform); + } } @Override diff --git a/OsmAnd/src/com/osmand/views/PointLocationLayer.java b/OsmAnd/src/com/osmand/views/PointLocationLayer.java index 986ecb215f..cc1ea250fe 100644 --- a/OsmAnd/src/com/osmand/views/PointLocationLayer.java +++ b/OsmAnd/src/com/osmand/views/PointLocationLayer.java @@ -1,5 +1,6 @@ package com.osmand.views; +import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Matrix; @@ -9,6 +10,8 @@ import android.graphics.PointF; import android.graphics.RectF; import android.graphics.Paint.Style; import android.location.Location; +import android.util.DisplayMetrics; +import android.view.WindowManager; import com.osmand.OsmandSettings.ApplicationMode; import com.osmand.osm.MapUtils; @@ -27,11 +30,12 @@ public class PointLocationLayer implements OsmandMapLayer { private ApplicationMode appMode = ApplicationMode.DEFAULT; protected Location lastKnownLocation = null; - + private DisplayMetrics dm; private OsmandMapTileView view; private Float heading = null; + private void initUI() { location = new Paint(); @@ -66,6 +70,9 @@ public class PointLocationLayer implements OsmandMapLayer { public void initLayer(OsmandMapTileView view) { this.view = view; initUI(); + dm = new DisplayMetrics(); + WindowManager wmgr = (WindowManager) view.getContext().getSystemService(Context.WINDOW_SERVICE); + wmgr.getDefaultDisplay().getMetrics(dm); } @@ -80,17 +87,17 @@ public class PointLocationLayer implements OsmandMapLayer { if (isLocationVisible(lastKnownLocation)) { int locationX = view.getMapXForPoint(lastKnownLocation.getLongitude()); int locationY = view.getMapYForPoint(lastKnownLocation.getLatitude()); - int radius = MapUtils.getLengthXFromMeters(view.getFloatZoom(), view.getLatitude(), view.getLongitude(), lastKnownLocation - .getAccuracy(), view.getTileSize(), view.getWidth()); + int radius = MapUtils.getLengthXFromMeters(view.getFloatZoom(), view.getLatitude(), view.getLongitude(), + lastKnownLocation.getAccuracy(), view.getTileSize(), view.getWidth()); if(appMode == ApplicationMode.CAR){ if(!lastKnownLocation.hasBearing()){ - canvas.drawCircle(locationX, locationY, RADIUS * 2.5f, location); - canvas.drawCircle(locationX, locationY, RADIUS * 2.5f, bearingOver); + canvas.drawCircle(locationX, locationY, RADIUS * 2.5f * dm.density, location); + canvas.drawCircle(locationX, locationY, RADIUS * 2.5f * dm.density, bearingOver); } } else { - canvas.drawCircle(locationX, locationY, RADIUS, location); - canvas.drawCircle(locationX, locationY, RADIUS, bearingOver); + canvas.drawCircle(locationX, locationY, RADIUS * dm.density, location); + canvas.drawCircle(locationX, locationY, RADIUS * dm.density, bearingOver); } if (radius > RADIUS) { canvas.drawCircle(locationX, locationY, radius, area); @@ -102,14 +109,14 @@ public class PointLocationLayer implements OsmandMapLayer { if(lastKnownLocation.hasBearing()){ float bearing = lastKnownLocation.getBearing(); - int radiusBearing = 30; + int radiusBearing = (int) (30 * dm.density); if(lastKnownLocation.hasSpeed() && appMode != ApplicationMode.CAR){ radiusBearing = Math.max(MapUtils.getLengthXFromMeters(view.getFloatZoom(), view.getLatitude(), view.getLongitude(), lastKnownLocation.getSpeed(), view.getTileSize(), view.getWidth()) * 2, radiusBearing); radiusBearing = Math.min(radiusBearing, view.getHeight() / 4); } - radiusBearing += RADIUS /2; + radiusBearing += RADIUS * dm.density /2; pathForDirection.reset(); pathForDirection.moveTo(0, 0); @@ -119,13 +126,13 @@ public class PointLocationLayer implements OsmandMapLayer { Matrix m = new Matrix(); m.reset(); if(appMode == ApplicationMode.CAR){ - m.postScale(2.5f, radiusBearing * 1.5f); + m.postScale(2.5f * dm.density, radiusBearing * 1.5f); m.postTranslate(0, -radiusBearing/2); } else if(appMode == ApplicationMode.BICYCLE){ - m.postScale(2f, radiusBearing); + m.postScale(2 * dm.density, radiusBearing); m.postTranslate(0, -radiusBearing/2); } else { - m.postScale(1, radiusBearing * 0.5f); + m.postScale(dm.density, radiusBearing * 0.5f); m.postTranslate(0, -radiusBearing); } m.postTranslate(locationX, locationY); diff --git a/OsmAnd/src/com/osmand/views/PointNavigationLayer.java b/OsmAnd/src/com/osmand/views/PointNavigationLayer.java index b50614fc26..cf1a2fec59 100644 --- a/OsmAnd/src/com/osmand/views/PointNavigationLayer.java +++ b/OsmAnd/src/com/osmand/views/PointNavigationLayer.java @@ -1,5 +1,6 @@ package com.osmand.views; +import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Matrix; @@ -8,6 +9,8 @@ import android.graphics.Path; import android.graphics.PointF; import android.graphics.Paint.Style; import android.location.Location; +import android.util.DisplayMetrics; +import android.view.WindowManager; import com.osmand.osm.LatLon; @@ -21,6 +24,7 @@ public class PointNavigationLayer implements OsmandMapLayer { private OsmandMapTileView view; private Path pathForDirection; private float[] calculations = new float[2]; + private DisplayMetrics dm; private void initUI() { @@ -34,6 +38,9 @@ public class PointNavigationLayer implements OsmandMapLayer { public void initLayer(OsmandMapTileView view) { this.view = view; + dm = new DisplayMetrics(); + WindowManager wmgr = (WindowManager) view.getContext().getSystemService(Context.WINDOW_SERVICE); + wmgr.getDefaultDisplay().getMetrics(dm); initUI(); } @@ -48,7 +55,7 @@ public class PointNavigationLayer implements OsmandMapLayer { int locationX = view.getMapXForPoint(pointToNavigate.getLongitude()); int locationY = view.getMapYForPoint(pointToNavigate.getLatitude()); - canvas.drawCircle(locationX, locationY, RADIUS, point); + canvas.drawCircle(locationX, locationY, RADIUS * dm.density, point); } else { Location.distanceBetween(view.getLatitude(), view.getLongitude(), pointToNavigate.getLatitude(), pointToNavigate.getLongitude(), calculations); @@ -58,11 +65,11 @@ public class PointNavigationLayer implements OsmandMapLayer { pathForDirection.lineTo(0.5f, 1.5f); pathForDirection.lineTo(-0.5f, 1.5f); pathForDirection.lineTo(0, 0); - float radiusBearing = DIST_TO_SHOW ; + float radiusBearing = DIST_TO_SHOW; Matrix m = new Matrix(); m.reset(); - m.postScale(RADIUS * 2, RADIUS * 2); - m.postTranslate(0, -radiusBearing); + m.postScale(RADIUS * dm.density * 2, RADIUS * 2 * dm.density); + m.postTranslate(0, - radiusBearing * dm.density ); m.postTranslate(view.getCenterPointX(), view.getCenterPointY()); m.postRotate(bearing, view.getCenterPointX(), view.getCenterPointY()); pathForDirection.transform(m); diff --git a/OsmAnd/src/com/osmand/views/RouteInfoLayer.java b/OsmAnd/src/com/osmand/views/RouteInfoLayer.java index 371048a4f5..5085b8d2a9 100644 --- a/OsmAnd/src/com/osmand/views/RouteInfoLayer.java +++ b/OsmAnd/src/com/osmand/views/RouteInfoLayer.java @@ -168,8 +168,8 @@ public class RouteInfoLayer implements OsmandMapLayer, IRouteInformationListener if(isVisible()){ border.set(layout.getLeft() - 10 * dm.density, layout.getTop() - 4 * dm.density, layout.getRight() - 5 * dm.density, layout.getBottom() + 4 * dm.density); - canvas.drawRoundRect(border, 5, 5, paintBorder); - canvas.drawRoundRect(border, 5, 5, paintBlack); + canvas.drawRoundRect(border, 5 * dm.density, 5 * dm.density, paintBorder); + canvas.drawRoundRect(border, 5 * dm.density, 5 * dm.density, paintBlack); List dir = routingHelper.getRouteDirections(); if(dir != null && directionInfo < dir.size() && directionInfo >= 0){ canvas.rotate(view.getRotate(), view.getCenterPointX(), view.getCenterPointY()); @@ -178,8 +178,8 @@ public class RouteInfoLayer implements OsmandMapLayer, IRouteInformationListener Location loc = routingHelper.getLocationFromRouteDirection(info); int x = view.getRotatedMapXForPoint(loc.getLatitude(), loc.getLongitude()); int y = view.getRotatedMapYForPoint(loc.getLatitude(), loc.getLongitude()); - canvas.drawCircle(x, y, 5, paintBorder); - canvas.drawCircle(x, y, 5, paintBlack); + canvas.drawCircle(x, y, 5 * dm.density, paintBorder); + canvas.drawCircle(x, y, 5 * dm.density, paintBlack); if (textView.getText().length() > 0) { canvas.translate(x - textView.getWidth() / 2, y - textView.getHeight() - 12);