fix layout for diff screens

git-svn-id: https://osmand.googlecode.com/svn/trunk@432 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-08-03 16:49:56 +00:00
parent 16091c2846
commit 5461e726a6
3 changed files with 43 additions and 8 deletions

View file

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.osmand.views.OsmandMapTileView android:id="@+id/MapView" android:layout_width="fill_parent" android:layout_height="fill_parent"></com.osmand.views.OsmandMapTileView>
<com.osmand.views.OsmZoomControls android:id="@+id/ZoomControls"
android:layout_marginRight="8dp" android:layout_marginBottom="6dp"
android:layout_width="120dp" android:layout_height="wrap_content" android:layout_gravity="bottom|right"/>
<ImageButton android:layout_gravity="bottom|left" android:id="@+id/BackToMenu" android:background="@drawable/back_menu"
android:layout_width="96dp" android:layout_height="96dp"/>
<ImageButton android:layout_gravity="top|right" android:layout_marginTop="96dp" android:id="@+id/BackToLocation" android:background="@drawable/back_location"
android:layout_width="64dp" android:layout_height="64dp"/>
<LinearLayout android:layout_width="wrap_content" android:id="@+id/RouteLayout" android:orientation="horizontal" android:layout_height="wrap_content" android:layout_gravity="bottom|center" android:layout_marginBottom="12dp">
<Button android:layout_width="wrap_content" android:id="@+id/PreviousButton" android:layout_height="wrap_content" android:background="@android:drawable/ic_media_previous"/>
<Button android:layout_width="wrap_content" android:id="@+id/InfoButton" android:layout_height="wrap_content" android:background="@android:drawable/ic_dialog_info" android:layout_marginLeft="12dp"/>
<Button android:layout_width="wrap_content" android:id="@+id/NextButton" android:layout_height="wrap_content" android:background="@android:drawable/ic_media_next" android:layout_marginLeft="12dp" android:layout_marginRight="15dp"/>
</LinearLayout>
</FrameLayout>

View file

@ -5,12 +5,13 @@
android:layout_height="fill_parent">
<com.osmand.views.OsmandMapTileView android:id="@+id/MapView" android:layout_width="fill_parent" android:layout_height="fill_parent"></com.osmand.views.OsmandMapTileView>
<com.osmand.views.OsmZoomControls android:id="@+id/ZoomControls"
android:layout_marginRight="3dp" android:layout_marginBottom="2dp"
android:layout_width="100dp" android:layout_height="wrap_content" android:layout_gravity="bottom|right"/>
<ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|left" android:id="@+id/BackToMenu" android:background="@drawable/back_menu"></ImageButton>
<ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top|right" android:layout_marginTop="64dp" android:id="@+id/BackToLocation" android:background="@drawable/back_location"></ImageButton>
<LinearLayout android:layout_width="wrap_content" android:id="@+id/RouteLayout" android:orientation="horizontal" android:layout_height="wrap_content" android:layout_gravity="bottom|center" android:layout_marginBottom="12dp" >
<LinearLayout android:layout_width="wrap_content" android:id="@+id/RouteLayout" android:orientation="horizontal" android:layout_height="wrap_content" android:layout_gravity="bottom|center" android:layout_marginBottom="12dp">
<Button android:layout_width="wrap_content" android:id="@+id/PreviousButton" android:layout_height="wrap_content" android:background="@android:drawable/ic_media_previous"/>
<Button android:layout_width="wrap_content" android:id="@+id/InfoButton" android:layout_height="wrap_content" android:background="@android:drawable/ic_dialog_info" android:layout_marginLeft="8dp"/>
<Button android:layout_width="wrap_content" android:id="@+id/NextButton" android:layout_height="wrap_content" android:background="@android:drawable/ic_media_next" android:layout_marginLeft="8dp" android:layout_marginRight="15dp"/>

View file

@ -2,6 +2,7 @@ package com.osmand.views;
import java.util.List;
import android.content.Context;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.Color;
@ -11,8 +12,10 @@ import android.graphics.RectF;
import android.graphics.Paint.Style;
import android.location.Location;
import android.os.Handler;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
@ -25,7 +28,8 @@ import com.osmand.activities.RoutingHelper.RouteDirectionInfo;
public class RouteInfoLayer implements OsmandMapLayer, IRouteInformationListener {
private final int TEXT_SIZE = 150;
private static final int BASE_TEXT_SIZE = 150;
private int textSize = BASE_TEXT_SIZE;
private OsmandMapTileView view;
private final RoutingHelper routingHelper;
@ -43,6 +47,8 @@ public class RouteInfoLayer implements OsmandMapLayer, IRouteInformationListener
private TextView textView;
private Paint paintLightBorder;
private DisplayMetrics dm;
public RouteInfoLayer(RoutingHelper routingHelper, LinearLayout layout){
this.routingHelper = routingHelper;
@ -67,7 +73,7 @@ public class RouteInfoLayer implements OsmandMapLayer, IRouteInformationListener
Location l = routingHelper.getLocationFromRouteDirection(info);
if(info.descriptionRoute != null){
textView.setText(info.descriptionRoute);
textView.layout(0, 0, TEXT_SIZE, (int) ((textView.getPaint().getTextSize()+4) * textView.getLineCount()));
textView.layout(0, 0, textSize, (int) ((textView.getPaint().getTextSize()+4) * textView.getLineCount()));
}
view.getAnimatedDraggingThread().startMoving(view.getLatitude(), view.getLongitude(),
l.getLatitude(), l.getLongitude(),
@ -89,7 +95,7 @@ public class RouteInfoLayer implements OsmandMapLayer, IRouteInformationListener
Location l = routingHelper.getLocationFromRouteDirection(info);
if(info.descriptionRoute != null){
textView.setText(info.descriptionRoute);
textView.layout(0, 0, TEXT_SIZE, (int) ((textView.getPaint().getTextSize() + 4) * textView.getLineCount()));
textView.layout(0, 0, textSize, (int) ((textView.getPaint().getTextSize() + 4) * textView.getLineCount()));
}
view.getAnimatedDraggingThread().startMoving(view.getLatitude(), view.getLongitude(),
l.getLatitude(), l.getLongitude(),
@ -128,6 +134,11 @@ public class RouteInfoLayer implements OsmandMapLayer, IRouteInformationListener
@Override
public void initLayer(OsmandMapTileView view) {
this.view = view;
dm = new DisplayMetrics();
WindowManager wmgr = (WindowManager) view.getContext().getSystemService(Context.WINDOW_SERVICE);
wmgr.getDefaultDisplay().getMetrics(dm);
textSize = (int) (BASE_TEXT_SIZE * dm.density);
uiHandler = new Handler();
border = new RectF();
paintBorder = new Paint();
@ -142,20 +153,21 @@ public class RouteInfoLayer implements OsmandMapLayer, IRouteInformationListener
paintBlack.setAntiAlias(true);
textView = new TextView(view.getContext());
LayoutParams lp = new LayoutParams(TEXT_SIZE, LayoutParams.WRAP_CONTENT);
LayoutParams lp = new LayoutParams(textSize, LayoutParams.WRAP_CONTENT);
textView.setLayoutParams(lp);
textView.setTextSize(16);
textView.setTextColor(Color.argb(255, 0, 0, 0));
textView.setMinLines(1);
textView.setMaxLines(4);
textView.setGravity(Gravity.CENTER_HORIZONTAL);
textBorder = new RectF(-2, -1, TEXT_SIZE + 2, 0);
textBorder = new RectF(-2, -1, textSize + 2, 0);
}
@Override
public void onDraw(Canvas canvas) {
if(isVisible()){
border.set(layout.getLeft() - 10, layout.getTop() - 3, layout.getRight() - 8, layout.getBottom() + 3);
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);
List<RouteDirectionInfo> dir = routingHelper.getRouteDirections();
@ -178,7 +190,7 @@ public class RouteInfoLayer implements OsmandMapLayer, IRouteInformationListener
textView.draw(canvas);
if (c == 0) {
// special case relayout after on draw method
textView.layout(0, 0, TEXT_SIZE, (int) ((textView.getPaint().getTextSize() + 4) * textView.getLineCount()));
textView.layout(0, 0, textSize, (int) ((textView.getPaint().getTextSize() + 4) * textView.getLineCount()));
view.refreshMap();
}
}