Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2015-03-13 22:03:51 +01:00
commit 64473b0a87
4 changed files with 86 additions and 43 deletions

View file

@ -58,7 +58,6 @@ import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.media.AudioManager;
import android.net.Uri;
@ -140,12 +139,14 @@ public class MapActivity extends AccessibleActivity {
// Full screen is not used here
// getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
mapView = new OsmandMapTileView();
mapView.init(this);
mapActions = new MapActivityActions(this);
mapLayers = new MapActivityLayers(this);
if (mapViewTrackingUtilities == null) {
mapViewTrackingUtilities = new MapViewTrackingUtilities(app);
}
dashboardOnMap.createDashboardView();
if (app.isApplicationInitializing() || DashboardOnMap.staticVisible) {
dashboardOnMap.setDashboardVisibility(true);
@ -188,8 +189,7 @@ public class MapActivity extends AccessibleActivity {
OsmAndMapSurfaceView surf = (OsmAndMapSurfaceView) findViewById(R.id.MapView);
surf.setVisibility(View.VISIBLE);
mapView = surf.getMapView();
surf.setMapView(mapView);
mapView.setTrackBallDelegate(new OsmandMapTileView.OnTrackBallListener() {
@Override
public boolean onTrackBallEvent(MotionEvent e) {
@ -254,7 +254,7 @@ public class MapActivity extends AccessibleActivity {
atlasMapRendererView.setAzimuth(0);
atlasMapRendererView.setElevationAngle(90);
NativeCoreContext.getMapRendererContext().setMapRendererView(atlasMapRendererView);
mapView = ml.getMapView();
ml.setMapView(mapView);
mapViewTrackingUtilities.setMapView(mapView);
mapView.setMapRender(atlasMapRendererView);
OsmAndMapSurfaceView surf = (OsmAndMapSurfaceView) findViewById(R.id.MapView);

View file

@ -14,22 +14,23 @@ public class OsmAndMapLayersView extends View {
public OsmAndMapLayersView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public OsmAndMapLayersView(Context context) {
super(context);
init();
}
private void init() {
mapView = new OsmandMapTileView();
mapView.initView(this);
public void setMapView(OsmandMapTileView mapView) {
this.mapView = mapView;
mapView.setView(this);
}
@Override
public boolean onTrackballEvent(MotionEvent event) {
if(mapView == null) {
return super.onTrackballEvent(event);
}
Boolean r = mapView.onTrackballEvent(event);
if(r == null) {
return super.onTrackballEvent(event);
@ -39,6 +40,9 @@ public class OsmAndMapLayersView extends View {
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(mapView == null) {
return super.onKeyDown(keyCode, event);
}
Boolean r = mapView.onKeyDown(keyCode, event);
if(r == null) {
return super.onKeyDown(keyCode, event);
@ -48,11 +52,17 @@ public class OsmAndMapLayersView extends View {
@Override
public boolean onTouchEvent(MotionEvent event) {
if(mapView == null) {
return super.onTouchEvent(event);
}
return mapView.onTouchEvent(event);
}
@Override
protected void onDraw(Canvas canvas) {
if(mapView == null) {
return;
}
boolean nightMode = mapView.getApplication().getDaynightHelper().isNightMode();
DrawSettings drawSettings = new DrawSettings(nightMode, false);
mapView.drawOverMap(canvas, mapView.getCurrentRotatedTileBox().copy(), drawSettings);

View file

@ -1,6 +1,8 @@
package net.osmand.plus.views;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.MotionEvent;
@ -24,28 +26,48 @@ public class OsmAndMapSurfaceView extends SurfaceView implements Callback {
init();
}
@Override
public void setOnClickListener(OnClickListener l) {
super.setOnClickListener(l);
this.onClickListener = l;
}
private void init() {
getHolder().addCallback(this);
mapView = new OsmandMapTileView();
mapView.initView(this);
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
if(mapView != null) {
mapView.refreshMap();
}
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
if(mapView != null) {
mapView.refreshMap();
}
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
}
public void setMapView(OsmandMapTileView mapView) {
this.mapView = mapView;
mapView.setView(this);
}
@Override
public boolean onTrackballEvent(MotionEvent event) {
if(mapView == null) {
return super.onTrackballEvent(event);
}
Boolean r = mapView.onTrackballEvent(event);
if(r == null) {
return super.onTrackballEvent(event);
@ -53,13 +75,11 @@ public class OsmAndMapSurfaceView extends SurfaceView implements Callback {
return r;
}
@Override
public void setOnClickListener(OnClickListener l) {
super.setOnClickListener(l);
this.onClickListener = l;
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(mapView == null) {
return super.onKeyDown(keyCode, event);
}
Boolean r = mapView.onKeyDown(keyCode, event);
if(r == null) {
return super.onKeyDown(keyCode, event);
@ -69,12 +89,22 @@ public class OsmAndMapSurfaceView extends SurfaceView implements Callback {
@Override
public boolean onTouchEvent(MotionEvent event) {
if(onClickListener != null) {
if(mapView == null) {
return super.onTouchEvent(event);
}
return mapView.onTouchEvent(event);
}
@Override
protected void onDraw(Canvas canvas) {
if(mapView == null) {
return;
}
boolean nightMode = mapView.getApplication().getDaynightHelper().isNightMode();
DrawSettings drawSettings = new DrawSettings(nightMode, false);
mapView.drawOverMap(canvas, mapView.getCurrentRotatedTileBox().copy(), drawSettings);
}
public OsmandMapTileView getMapView() {
return mapView;

View file

@ -173,9 +173,8 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
// ///////////////////////////// INITIALIZING UI PART ///////////////////////////////////
public void initView(View view) {
application = (OsmandApplication) view.getContext().getApplicationContext();
this.view = view;
public void init(Context ctx) {
application = (OsmandApplication) ctx.getApplicationContext();
paintGrayFill = new Paint();
paintGrayFill.setColor(Color.GRAY);
paintGrayFill.setStyle(Style.FILL);
@ -204,28 +203,27 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
paintImg.setFilterBitmap(true);
// paintImg.setDither(true);
view.setClickable(true);
view.setLongClickable(true);
view.setFocusable(true);
handler = new Handler();
baseHandler = new Handler(application.getResourceManager().getRenderingBufferImageThread().getLooper());
animatedDraggingThread = new AnimateDraggingMapThread(this);
gestureDetector = new GestureDetector(view.getContext(), new MapExplorer(this, new MapTileViewOnGestureListener()));
multiTouchSupport = new MultiTouchSupport(view.getContext(), new MapTileViewMultiTouchZoomListener());
gestureDetector = new GestureDetector(ctx, new MapExplorer(this, new MapTileViewOnGestureListener()));
multiTouchSupport = new MultiTouchSupport(ctx, new MapTileViewMultiTouchZoomListener());
gestureDetector.setOnDoubleTapListener(new MapTileViewOnDoubleTapListener());
WindowManager mgr = (WindowManager) view.getContext().getSystemService(Context.WINDOW_SERVICE);
WindowManager mgr = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
dm = new DisplayMetrics();
mgr.getDefaultDisplay().getMetrics(dm);
currentViewport = new RotatedTileBox.RotatedTileBoxBuilder().
setLocation(0, 0).setZoom(3).setPixelDimensions(view.getWidth(), view.getHeight()).build();
setLocation(0, 0).setZoom(3).setPixelDimensions(100, 100).build();
currentViewport.setDensity(dm.density);
currentViewport.setMapDensity(getSettingsMapDensity());
}
public void setView(View view) {
this.view = view;
view.setClickable(true);
view.setLongClickable(true);
view.setFocusable(true);
}
public Boolean onKeyDown(int keyCode, KeyEvent event) {
@ -469,6 +467,9 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
}
private void refreshMapInternal(DrawSettings drawSettings) {
if(view == null) {
return;
}
final float ratioy = mapPosition == OsmandSettings.BOTTOM_CONSTANT ? 0.85f : 0.5f;
final int cy = (int) (ratioy * view.getHeight());
if (currentViewport.getPixWidth() != view.getWidth() || currentViewport.getPixHeight() != view.getHeight() ||
@ -605,7 +606,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
// this method could be called in non UI thread
public void refreshMap(final boolean updateVectorRendering) {
if (view.isShown()) {
if (view != null && view.isShown()) {
boolean nightMode = application.getDaynightHelper().isNightMode();
DrawSettings drawSettings = new DrawSettings(nightMode, updateVectorRendering);
sendRefreshMapMsg(drawSettings, 20);
@ -785,7 +786,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
handler.post(new Runnable() {
@Override
public void run() {
AccessibleToast.makeText(view.getContext(), msg, Toast.LENGTH_SHORT).show(); //$NON-NLS-1$
AccessibleToast.makeText(application, msg, Toast.LENGTH_SHORT).show(); //$NON-NLS-1$
}
});
}
@ -815,7 +816,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
final int newZoom = getZoom();
if (application.accessibilityEnabled()) {
if (newZoom != initialViewport.getZoom()) {
showMessage(view.getContext().getString(R.string.zoomIs) + " " + newZoom); //$NON-NLS-1$
showMessage(application.getString(R.string.zoomIs) + " " + newZoom); //$NON-NLS-1$
} else {
final LatLon p1 = initialViewport.getLatLonFromPixel(x1, y1);
final LatLon p2 = initialViewport.getLatLonFromPixel(x2, y2);
@ -977,12 +978,14 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
}
public Context getContext() {
return view.getContext();
}
public Resources getResources() {
return view.getResources();
return application.getResources();
}
public Context getContext() {
return view.getContext();
}
public ViewParent getParent() {