Fix init of new core

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

View file

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

View file

@ -1,6 +1,8 @@
package net.osmand.plus.views; package net.osmand.plus.views;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import android.content.Context; import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.MotionEvent; import android.view.MotionEvent;
@ -23,29 +25,49 @@ public class OsmAndMapSurfaceView extends SurfaceView implements Callback {
super(context); super(context);
init(); init();
} }
@Override
public void setOnClickListener(OnClickListener l) {
super.setOnClickListener(l);
this.onClickListener = l;
}
private void init() { private void init() {
getHolder().addCallback(this); getHolder().addCallback(this);
mapView = new OsmandMapTileView();
mapView.initView(this);
} }
@Override @Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
mapView.refreshMap(); if(mapView != null) {
mapView.refreshMap();
}
} }
@Override @Override
public void surfaceCreated(SurfaceHolder holder) { public void surfaceCreated(SurfaceHolder holder) {
mapView.refreshMap(); if(mapView != null) {
mapView.refreshMap();
}
} }
@Override @Override
public void surfaceDestroyed(SurfaceHolder holder) { public void surfaceDestroyed(SurfaceHolder holder) {
} }
public void setMapView(OsmandMapTileView mapView) {
this.mapView = mapView;
mapView.setView(this);
}
@Override @Override
public boolean onTrackballEvent(MotionEvent event) { public boolean onTrackballEvent(MotionEvent event) {
if(mapView == null) {
return super.onTrackballEvent(event);
}
Boolean r = mapView.onTrackballEvent(event); Boolean r = mapView.onTrackballEvent(event);
if(r == null) { if(r == null) {
return super.onTrackballEvent(event); return super.onTrackballEvent(event);
@ -53,13 +75,11 @@ public class OsmAndMapSurfaceView extends SurfaceView implements Callback {
return r; return r;
} }
@Override
public void setOnClickListener(OnClickListener l) {
super.setOnClickListener(l);
this.onClickListener = l;
}
@Override @Override
public boolean onKeyDown(int keyCode, KeyEvent event) { public boolean onKeyDown(int keyCode, KeyEvent event) {
if(mapView == null) {
return super.onKeyDown(keyCode, event);
}
Boolean r = mapView.onKeyDown(keyCode, event); Boolean r = mapView.onKeyDown(keyCode, event);
if(r == null) { if(r == null) {
return super.onKeyDown(keyCode, event); return super.onKeyDown(keyCode, event);
@ -69,12 +89,22 @@ public class OsmAndMapSurfaceView extends SurfaceView implements Callback {
@Override @Override
public boolean onTouchEvent(MotionEvent event) { public boolean onTouchEvent(MotionEvent event) {
if(onClickListener != null) { if(mapView == null) {
return super.onTouchEvent(event); return super.onTouchEvent(event);
} }
return mapView.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() { public OsmandMapTileView getMapView() {
return mapView; return mapView;

View file

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