fix layout for different screen support

git-svn-id: https://osmand.googlecode.com/svn/trunk@433 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-08-03 19:21:45 +00:00
parent 5461e726a6
commit cffd20848d
8 changed files with 95 additions and 41 deletions

View file

@ -8,22 +8,28 @@ package com.osmand;
*/ */
public class ToDoConstants { 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 // TODO max 85
// ! 81. Add some objects to POI category (1) to add them into OSM 2) to help navigation) // ! 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(?), // highway (?), traffic_calming (?), barrier(?), military(?-), landuse (?), office(?), man_made(?), power(?),
// railway( station, subway?) - issue 17 // railway( station, subway?) - issue 17
// 82. Rotate map according compass // 82. Rotate map according compass
// TODO BUGS Android // TODO BUGS Android
// !! 3. different screens better support // !! 3. different screens better support
/// 3.1 after search_address_online.xml (+) /// 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 (+) // FavoritesLayer, OsmBugsLayer, POIMapLayer, TransportInfoLayer, TransportStopsLayer (+)
// PointLocationLayer, PointNavigationLayer, YandexTrafficLayer // PointLocationLayer, PointNavigationLayer, YandexTrafficLayer(+)
// 3.3 route_info_list_item.xml - ShowRouteInfoActivity, main.xml // 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.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 (+) // 4. Icon back to location (+)
// Improvements // Improvements
@ -44,12 +50,6 @@ public class ToDoConstants {
// 63. Support simple offline routing(require new index file) (?) // 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 // BUGS Swing
// DONE ANDROID : // DONE ANDROID :

View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView android:id="@+id/direction" android:layout_width="48dp" android:layout_height="48dp"/>
<TextView android:text="" android:id="@+id/distance" android:layout_marginLeft ="5dp" android:textSize="23sp"
android:layout_width="70dp" android:layout_height="wrap_content"></TextView>
<TextView android:text="" android:id="@+id/description" android:layout_weight="1" android:textSize="23sp"
android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<TextView android:text="" android:id="@+id/time" android:layout_marginLeft ="5dp"
android:layout_width="65dp" android:layout_height="wrap_content" android:textSize="23sp"></TextView>
</LinearLayout>

View file

@ -4,12 +4,12 @@
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<ImageView android:id="@+id/direction" android:layout_width="32dp" android:layout_height="32dp"></ImageView> <ImageView android:id="@+id/direction" android:layout_width="32dp" android:layout_height="32dp" />
<TextView android:text="@+id/TextView01" android:id="@+id/distance" android:layout_marginLeft ="5dp" <TextView android:text="" android:id="@+id/distance" android:layout_marginLeft ="5dp"
android:layout_width="50dp" android:layout_height="wrap_content"></TextView> android:layout_width="50dp" android:layout_height="wrap_content"></TextView>
<TextView android:text="@+id/TextView02" android:id="@+id/description" android:layout_weight="1" <TextView android:text="" android:id="@+id/description" android:layout_weight="1"
android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<TextView android:text="@+id/TextView02" android:id="@+id/time" android:layout_marginLeft ="5dp" <TextView android:text="" android:id="@+id/time" android:layout_marginLeft ="5dp"
android:layout_width="45dp" android:layout_height="wrap_content"></TextView> android:layout_width="45dp" android:layout_height="wrap_content"></TextView>

View file

@ -14,10 +14,12 @@ import android.graphics.ColorFilter;
import android.graphics.Matrix; import android.graphics.Matrix;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Path; import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.Paint.Style; import android.graphics.Paint.Style;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.location.Location; import android.location.Location;
import android.os.Bundle; import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -41,6 +43,7 @@ public class ShowRouteInfoActivity extends ListActivity {
private RoutingHelper helper; private RoutingHelper helper;
private TextView header; private TextView header;
private DisplayMetrics dm;
@Override @Override
public void onCreate(Bundle icicle) { public void onCreate(Bundle icicle) {
@ -52,6 +55,8 @@ public class ShowRouteInfoActivity extends ListActivity {
lv.addHeaderView(header); lv.addHeaderView(header);
setContentView(lv); setContentView(lv);
dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
} }
@Override @Override
@ -62,10 +67,18 @@ public class ShowRouteInfoActivity extends ListActivity {
int minutes = (helper.getLeftTime() / 60) % 60; int minutes = (helper.getLeftTime() / 60) % 60;
header.setText(MessageFormat.format(getString(R.string.route_general_information), MapUtils.getFormattedDistance(dist), 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())); setListAdapter(new RouteInfoAdapter(RoutingHelper.getInstance(this).getRouteDirections()));
} }
public void onListItemClick(ListView parent, View v, int position, long id) { public void onListItemClick(ListView parent, View v, int position, long id) {
if(position == 0){
return;
}
RouteDirectionInfo item = ((RouteInfoAdapter)getListAdapter()).getItem(position - 1); RouteDirectionInfo item = ((RouteInfoAdapter)getListAdapter()).getItem(position - 1);
Location loc = helper.getLocationFromRouteDirection(item); Location loc = helper.getLocationFromRouteDirection(item);
if(loc != null){ if(loc != null){
@ -78,9 +91,9 @@ public class ShowRouteInfoActivity extends ListActivity {
class RouteDrawable extends Drawable { class RouteDrawable extends Drawable {
Paint paintRouteDirection; Paint paintRouteDirection;
Path p = new Path(); Path p = new Path();
Matrix m = new Matrix(); Path dp = new Path();
public RouteDrawable(){ public RouteDrawable(){
m.setScale(0.33f, 0.33f);
paintRouteDirection = new Paint(); paintRouteDirection = new Paint();
paintRouteDirection.setStyle(Style.FILL_AND_STROKE); paintRouteDirection.setStyle(Style.FILL_AND_STROKE);
paintRouteDirection.setColor(Color.rgb(100, 0, 255)); paintRouteDirection.setColor(Color.rgb(100, 0, 255));
@ -88,13 +101,21 @@ public class ShowRouteInfoActivity extends ListActivity {
} }
@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){ public void setRouteType(TurnType t){
MapInfoLayer.calcTurnPath(p, t, m); MapInfoLayer.calcTurnPath(p, t, null);
onBoundsChange(getBounds());
} }
@Override @Override
public void draw(Canvas canvas) { public void draw(Canvas canvas) {
canvas.drawPath(p, paintRouteDirection); canvas.drawPath(dp, paintRouteDirection);
} }
@Override @Override

View file

@ -494,8 +494,10 @@ public class MapInfoLayer implements OsmandMapLayer {
pathForTurn.close(); pathForTurn.close();
} }
pathForTurn.close(); pathForTurn.close();
if(transform != null){
pathForTurn.transform(transform); pathForTurn.transform(transform);
} }
}
@Override @Override
public void destroyLayer() { public void destroyLayer() {

View file

@ -1,5 +1,6 @@
package com.osmand.views; package com.osmand.views;
import android.content.Context;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Matrix; import android.graphics.Matrix;
@ -9,6 +10,8 @@ import android.graphics.PointF;
import android.graphics.RectF; import android.graphics.RectF;
import android.graphics.Paint.Style; import android.graphics.Paint.Style;
import android.location.Location; import android.location.Location;
import android.util.DisplayMetrics;
import android.view.WindowManager;
import com.osmand.OsmandSettings.ApplicationMode; import com.osmand.OsmandSettings.ApplicationMode;
import com.osmand.osm.MapUtils; import com.osmand.osm.MapUtils;
@ -27,12 +30,13 @@ public class PointLocationLayer implements OsmandMapLayer {
private ApplicationMode appMode = ApplicationMode.DEFAULT; private ApplicationMode appMode = ApplicationMode.DEFAULT;
protected Location lastKnownLocation = null; protected Location lastKnownLocation = null;
private DisplayMetrics dm;
private OsmandMapTileView view; private OsmandMapTileView view;
private Float heading = null; private Float heading = null;
private void initUI() { private void initUI() {
location = new Paint(); location = new Paint();
location.setColor(Color.BLUE); location.setColor(Color.BLUE);
@ -66,6 +70,9 @@ public class PointLocationLayer implements OsmandMapLayer {
public void initLayer(OsmandMapTileView view) { public void initLayer(OsmandMapTileView view) {
this.view = view; this.view = view;
initUI(); 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)) { if (isLocationVisible(lastKnownLocation)) {
int locationX = view.getMapXForPoint(lastKnownLocation.getLongitude()); int locationX = view.getMapXForPoint(lastKnownLocation.getLongitude());
int locationY = view.getMapYForPoint(lastKnownLocation.getLatitude()); int locationY = view.getMapYForPoint(lastKnownLocation.getLatitude());
int radius = MapUtils.getLengthXFromMeters(view.getFloatZoom(), view.getLatitude(), view.getLongitude(), lastKnownLocation int radius = MapUtils.getLengthXFromMeters(view.getFloatZoom(), view.getLatitude(), view.getLongitude(),
.getAccuracy(), view.getTileSize(), view.getWidth()); lastKnownLocation.getAccuracy(), view.getTileSize(), view.getWidth());
if(appMode == ApplicationMode.CAR){ if(appMode == ApplicationMode.CAR){
if(!lastKnownLocation.hasBearing()){ if(!lastKnownLocation.hasBearing()){
canvas.drawCircle(locationX, locationY, RADIUS * 2.5f, location); canvas.drawCircle(locationX, locationY, RADIUS * 2.5f * dm.density, location);
canvas.drawCircle(locationX, locationY, RADIUS * 2.5f, bearingOver); canvas.drawCircle(locationX, locationY, RADIUS * 2.5f * dm.density, bearingOver);
} }
} else { } else {
canvas.drawCircle(locationX, locationY, RADIUS, location); canvas.drawCircle(locationX, locationY, RADIUS * dm.density, location);
canvas.drawCircle(locationX, locationY, RADIUS, bearingOver); canvas.drawCircle(locationX, locationY, RADIUS * dm.density, bearingOver);
} }
if (radius > RADIUS) { if (radius > RADIUS) {
canvas.drawCircle(locationX, locationY, radius, area); canvas.drawCircle(locationX, locationY, radius, area);
@ -102,14 +109,14 @@ public class PointLocationLayer implements OsmandMapLayer {
if(lastKnownLocation.hasBearing()){ if(lastKnownLocation.hasBearing()){
float bearing = lastKnownLocation.getBearing(); float bearing = lastKnownLocation.getBearing();
int radiusBearing = 30; int radiusBearing = (int) (30 * dm.density);
if(lastKnownLocation.hasSpeed() && appMode != ApplicationMode.CAR){ if(lastKnownLocation.hasSpeed() && appMode != ApplicationMode.CAR){
radiusBearing = radiusBearing =
Math.max(MapUtils.getLengthXFromMeters(view.getFloatZoom(), view.getLatitude(), view.getLongitude(), Math.max(MapUtils.getLengthXFromMeters(view.getFloatZoom(), view.getLatitude(), view.getLongitude(),
lastKnownLocation.getSpeed(), view.getTileSize(), view.getWidth()) * 2, radiusBearing); lastKnownLocation.getSpeed(), view.getTileSize(), view.getWidth()) * 2, radiusBearing);
radiusBearing = Math.min(radiusBearing, view.getHeight() / 4); radiusBearing = Math.min(radiusBearing, view.getHeight() / 4);
} }
radiusBearing += RADIUS /2; radiusBearing += RADIUS * dm.density /2;
pathForDirection.reset(); pathForDirection.reset();
pathForDirection.moveTo(0, 0); pathForDirection.moveTo(0, 0);
@ -119,13 +126,13 @@ public class PointLocationLayer implements OsmandMapLayer {
Matrix m = new Matrix(); Matrix m = new Matrix();
m.reset(); m.reset();
if(appMode == ApplicationMode.CAR){ 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); m.postTranslate(0, -radiusBearing/2);
} else if(appMode == ApplicationMode.BICYCLE){ } else if(appMode == ApplicationMode.BICYCLE){
m.postScale(2f, radiusBearing); m.postScale(2 * dm.density, radiusBearing);
m.postTranslate(0, -radiusBearing/2); m.postTranslate(0, -radiusBearing/2);
} else { } else {
m.postScale(1, radiusBearing * 0.5f); m.postScale(dm.density, radiusBearing * 0.5f);
m.postTranslate(0, -radiusBearing); m.postTranslate(0, -radiusBearing);
} }
m.postTranslate(locationX, locationY); m.postTranslate(locationX, locationY);

View file

@ -1,5 +1,6 @@
package com.osmand.views; package com.osmand.views;
import android.content.Context;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Matrix; import android.graphics.Matrix;
@ -8,6 +9,8 @@ import android.graphics.Path;
import android.graphics.PointF; import android.graphics.PointF;
import android.graphics.Paint.Style; import android.graphics.Paint.Style;
import android.location.Location; import android.location.Location;
import android.util.DisplayMetrics;
import android.view.WindowManager;
import com.osmand.osm.LatLon; import com.osmand.osm.LatLon;
@ -21,6 +24,7 @@ public class PointNavigationLayer implements OsmandMapLayer {
private OsmandMapTileView view; private OsmandMapTileView view;
private Path pathForDirection; private Path pathForDirection;
private float[] calculations = new float[2]; private float[] calculations = new float[2];
private DisplayMetrics dm;
private void initUI() { private void initUI() {
@ -34,6 +38,9 @@ public class PointNavigationLayer implements OsmandMapLayer {
public void initLayer(OsmandMapTileView view) { public void initLayer(OsmandMapTileView view) {
this.view = view; this.view = view;
dm = new DisplayMetrics();
WindowManager wmgr = (WindowManager) view.getContext().getSystemService(Context.WINDOW_SERVICE);
wmgr.getDefaultDisplay().getMetrics(dm);
initUI(); initUI();
} }
@ -48,7 +55,7 @@ public class PointNavigationLayer implements OsmandMapLayer {
int locationX = view.getMapXForPoint(pointToNavigate.getLongitude()); int locationX = view.getMapXForPoint(pointToNavigate.getLongitude());
int locationY = view.getMapYForPoint(pointToNavigate.getLatitude()); int locationY = view.getMapYForPoint(pointToNavigate.getLatitude());
canvas.drawCircle(locationX, locationY, RADIUS, point); canvas.drawCircle(locationX, locationY, RADIUS * dm.density, point);
} else { } else {
Location.distanceBetween(view.getLatitude(), view.getLongitude(), pointToNavigate.getLatitude(), Location.distanceBetween(view.getLatitude(), view.getLongitude(), pointToNavigate.getLatitude(),
pointToNavigate.getLongitude(), calculations); pointToNavigate.getLongitude(), calculations);
@ -61,8 +68,8 @@ public class PointNavigationLayer implements OsmandMapLayer {
float radiusBearing = DIST_TO_SHOW; float radiusBearing = DIST_TO_SHOW;
Matrix m = new Matrix(); Matrix m = new Matrix();
m.reset(); m.reset();
m.postScale(RADIUS * 2, RADIUS * 2); m.postScale(RADIUS * dm.density * 2, RADIUS * 2 * dm.density);
m.postTranslate(0, -radiusBearing); m.postTranslate(0, - radiusBearing * dm.density );
m.postTranslate(view.getCenterPointX(), view.getCenterPointY()); m.postTranslate(view.getCenterPointX(), view.getCenterPointY());
m.postRotate(bearing, view.getCenterPointX(), view.getCenterPointY()); m.postRotate(bearing, view.getCenterPointX(), view.getCenterPointY());
pathForDirection.transform(m); pathForDirection.transform(m);

View file

@ -168,8 +168,8 @@ public class RouteInfoLayer implements OsmandMapLayer, IRouteInformationListener
if(isVisible()){ if(isVisible()){
border.set(layout.getLeft() - 10 * dm.density, layout.getTop() - 4 * dm.density, border.set(layout.getLeft() - 10 * dm.density, layout.getTop() - 4 * dm.density,
layout.getRight() - 5 * dm.density, layout.getBottom() + 4 * dm.density); layout.getRight() - 5 * dm.density, layout.getBottom() + 4 * dm.density);
canvas.drawRoundRect(border, 5, 5, paintBorder); canvas.drawRoundRect(border, 5 * dm.density, 5 * dm.density, paintBorder);
canvas.drawRoundRect(border, 5, 5, paintBlack); canvas.drawRoundRect(border, 5 * dm.density, 5 * dm.density, paintBlack);
List<RouteDirectionInfo> dir = routingHelper.getRouteDirections(); List<RouteDirectionInfo> dir = routingHelper.getRouteDirections();
if(dir != null && directionInfo < dir.size() && directionInfo >= 0){ if(dir != null && directionInfo < dir.size() && directionInfo >= 0){
canvas.rotate(view.getRotate(), view.getCenterPointX(), view.getCenterPointY()); canvas.rotate(view.getRotate(), view.getCenterPointX(), view.getCenterPointY());
@ -178,8 +178,8 @@ public class RouteInfoLayer implements OsmandMapLayer, IRouteInformationListener
Location loc = routingHelper.getLocationFromRouteDirection(info); Location loc = routingHelper.getLocationFromRouteDirection(info);
int x = view.getRotatedMapXForPoint(loc.getLatitude(), loc.getLongitude()); int x = view.getRotatedMapXForPoint(loc.getLatitude(), loc.getLongitude());
int y = view.getRotatedMapYForPoint(loc.getLatitude(), loc.getLongitude()); int y = view.getRotatedMapYForPoint(loc.getLatitude(), loc.getLongitude());
canvas.drawCircle(x, y, 5, paintBorder); canvas.drawCircle(x, y, 5 * dm.density, paintBorder);
canvas.drawCircle(x, y, 5, paintBlack); canvas.drawCircle(x, y, 5 * dm.density, paintBlack);
if (textView.getText().length() > 0) { if (textView.getText().length() > 0) {
canvas.translate(x - textView.getWidth() / 2, y - textView.getHeight() - 12); canvas.translate(x - textView.getWidth() / 2, y - textView.getHeight() - 12);