public SymbolContainer(Point point, Display display, int priority, Bitmap symbol, float theta, boolean alignCenter) { super(point, display, priority); this.symbol = symbol; this.theta = theta; this.alignCenter = alignCenter; if (alignCenter) { double halfWidth = this.symbol.getWidth() / 2d; double halfHeight = this.symbol.getHeight() / 2d; this.boundary = new Rectangle(-halfWidth, -halfHeight, halfWidth, halfHeight); } else { this.boundary = new Rectangle(0, 0, this.symbol.getWidth(), this.symbol.getHeight()); } this.symbol.incrementRefCount(); }
@Override public void run() { if (current != null) { // since we want to keep the green bitmap around, we have to increment // its ref count, otherwise it gets recycled automatically when it is // replaced with the other colour. current.incrementRefCount(); } if (bitmapGreen.equals(current)) { marker.setBitmap(bitmapRed); current = bitmapRed; } else { marker.setBitmap(bitmapGreen); current = bitmapGreen; } redrawLayers(); handler.postDelayed(this, 2000); } }
@Override public void onDestroy() { handler.removeCallbacks(bitmapChanger); // we need to increment the ref count here as otherwise the bitmap gets // destroyed, but we might need to reuse it when this is only part of // a pause/resume cycle. current.incrementRefCount(); super.onDestroy(); bitmapRed.decrementRefCount(); bitmapGreen.decrementRefCount(); } }
@SuppressWarnings("deprecation") @TargetApi(Build.VERSION_CODES.LOLLIPOP) static Marker createTappableMarker(final Context c, int resourceIdentifier, LatLong latLong) { Drawable drawable = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? c.getDrawable(resourceIdentifier) : c.getResources().getDrawable(resourceIdentifier); Bitmap bitmap = AndroidGraphicFactory.convertToBitmap(drawable); bitmap.incrementRefCount(); return new Marker(latLong, bitmap, 0, -bitmap.getHeight() / 2) { @Override public boolean onTap(LatLong geoPoint, Point viewPosition, Point tapPoint) { if (contains(viewPosition, tapPoint)) { Toast.makeText(c, "The Marker was tapped " + geoPoint.toString(), Toast.LENGTH_SHORT).show(); return true; } return false; } }; }
public static Bitmap getBitmapFromTitle(String title, Paint paint) { if (!captionViews.containsKey(title)) { TextView bubbleView = new TextView(context); Utils.setBackground(bubbleView, context.getResources().getDrawable(R.drawable.caption_background)); bubbleView.setGravity(Gravity.CENTER); bubbleView.setMaxEms(20); bubbleView.setTextSize(10); bubbleView.setPadding(5, -2, 5, -2); bubbleView.setTextColor(android.graphics.Color.BLACK); bubbleView.setText(title); //Measure the view at the exact dimensions (otherwise the text won't center correctly) int widthSpec = View.MeasureSpec.makeMeasureSpec(paint.getTextWidth(title), View.MeasureSpec.EXACTLY); int heightSpec = View.MeasureSpec.makeMeasureSpec(paint.getTextHeight(title), View.MeasureSpec.EXACTLY); bubbleView.measure(widthSpec, heightSpec); //Layout the view at the width and height bubbleView.layout(0, 0, paint.getTextWidth(title), paint.getTextHeight(title)); captionViews.put(title, Utils.viewToBitmap(context, bubbleView)); captionViews.get(title).incrementRefCount(); // FIXME: is never reduced! } return captionViews.get(title); }
@SuppressWarnings("deprecation") @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override protected void createLayers() { super.createLayers(); // Bubble overlays for (DummyContent.DummyItem item : DummyContent.ITEMS) { TextView bubbleView = new TextView(this); Utils.setBackground(bubbleView, Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? getDrawable(R.drawable.balloon_overlay_unfocused) : getResources().getDrawable(R.drawable.balloon_overlay_unfocused)); bubbleView.setGravity(Gravity.CENTER); bubbleView.setMaxEms(20); bubbleView.setTextSize(15); bubbleView.setTextColor(Color.BLACK); bubbleView.setText(item.text); bubble = Utils.viewToBitmap(this, bubbleView); bubble.incrementRefCount(); this.mapView.getLayerManager().getLayers().add(new Marker(item.location, bubble, 0, -bubble.getHeight() / 2)); } }
@UiThread void showCarPosition(Cars cars) { if (TaxiApplication.isMapVisible() && cars != null) { //final List<Layer> overlayItems = carsOverlay.getOverlayItems(); //overlayItems.clear(); TextView bubbleView = new TextView(this); Utils.setBackground(bubbleView, getResources().getDrawable(R.drawable.balloon_overlay_unfocused)); bubbleView.setGravity(Gravity.CENTER); bubbleView.setMaxEms(20); bubbleView.setTextSize(15); bubbleView.setTextColor(Color.BLACK); bubbleView.setText(cars.getNumber()); bubble = Utils.viewToBitmap(this, bubbleView); bubble.incrementRefCount(); if (cars.getCurrPosNorth() != null && cars.getCurrPosEast() != null) { Marker marker = new Marker(new LatLong(cars.getCurrPosNorth(), cars.getCurrPosEast()), bubble, 0, -bubble.getHeight() / 2); //marker.setDisplayModel(this.mapViews.get(0).getModel().displayModel); carsOverlay.add(marker); mapView.getLayerManager().getLayers().add(marker); //Log.i(TAG, "Car:" + cars.getNumber()); } //carsOverlay.requestRedraw(); } }
public SymbolContainer(Point point, Display display, int priority, Bitmap symbol, float theta, boolean alignCenter) { super(point, display, priority); this.symbol = symbol; this.theta = theta; this.alignCenter = alignCenter; if (alignCenter) { double halfWidth = this.symbol.getWidth() / 2d; double halfHeight = this.symbol.getHeight() / 2d; this.boundary = new Rectangle(-halfWidth, -halfHeight, halfWidth, halfHeight); } else { this.boundary = new Rectangle(0, 0, this.symbol.getWidth(), this.symbol.getHeight()); } this.symbol.incrementRefCount(); }
bitmapClimbingPeak.incrementRefCount(); balloon = getResources().getDrawable(R.drawable.marker_red); Bitmap markerRedS = AndroidGraphicFactory.convertToBitmap(balloon); markerRedS.incrementRefCount(); Paint paint1; paint1 = AndroidGraphicFactory.INSTANCE.createPaint(); Bitmap bitmapBalloonSN = AndroidGraphicFactory .convertToBitmap(balloon); bitmapBalloonSN.incrementRefCount(); balloon = getResources().getDrawable(R.drawable.balloon_s_s); Bitmap bitmapBalloonSS = AndroidGraphicFactory.convertToBitmap(balloon); bitmapBalloonSS.incrementRefCount(); Paint paint2; paint2 = AndroidGraphicFactory.INSTANCE.createPaint(); bitmapBalloonMN.incrementRefCount(); balloon = getResources().getDrawable(R.drawable.balloon_m_s); Bitmap bitmapBalloonMS = AndroidGraphicFactory .convertToBitmap(balloon); bitmapBalloonMS.incrementRefCount(); Paint paint3; paint3 = AndroidGraphicFactory.INSTANCE.createPaint();
bubbleView.setText(newCRequest.getFullAddress()); bubble = Utils.viewToBitmap(this, bubbleView); bubble.incrementRefCount(); Marker marker = new Marker(new LatLong(newCRequest.getNorth(), newCRequest.getEast()), bubble, 0, -bubble.getHeight() / 2);