On Github studgent / slides
→ Repetitieve code!
@Override public void onPause(){ LocationUtil.getInstance(this).onPause(); super.onPause(); }
@Override public void onResume(){ LocationUtil.getInstance(this).onResume(); super.onResume(); }
public void updateOverlay(int az) { for (POIView v : pois) { float bearing = devLoc.bearingTo( LocationUtil.getLocationFromLatLng( v.getPoi().getLocation() ) ); float t = ((az - bearing) + 180) % 360 - 180; if (t > fov) { // Do not draw, because poi is outside fov v.setVisibility(View.INVISIBLE); } else { float offset = ((az - bearing) + 180) % 360 - 180; offset = (offset / fov) * screenWidth; v.setTranslationX( -offset + ( screenWidth/2 - v.getMinWidth()/2 ) ); // Force visibility with a SurfaceHolder beneath this view v.setVisibility(View.VISIBLE); v.requestLayout(); } } }
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { minWidth = 0; int minHeight = 0; int textWidth = (int) tpaint.measureText(poi.getName()); int iconWidth = (int) (circleRadius*2 + cpaint.getStrokeWidth()*2); minWidth = Math.max(textWidth, iconWidth); minHeight = screenHeight; setMeasuredDimension( MeasureSpec.makeMeasureSpec(minWidth, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(minHeight, MeasureSpec.EXACTLY) ); }