Code example for TextPaint

Methods: breakText, getTextBounds, setTextSize

0
		if(this.imageHeight <= 0 ){
			//hardcoded image size untill we get the right assest from server.  
			this.imageHeight = (int)(50 * density);
			this.imageWidth = (int)(50 * density);
			this.halfImageInPixels = this.imageHeight >> 1;
			topTextPaint.setTextSize((int)(18 * density));
			subTextPaint.setTextSize((int)(14 * density));
			 
			if(this.itemName != null){
				topTextPaint.getTextBounds(this.itemName, 0, this.itemName.length(), this.topTextBoxRect);
			} 
			if(this.itemDesc != null){
				subTextPaint.getTextBounds(this.itemDesc, 0, this.itemDesc.length(), this.subTextBoxRect);
			} 
		} 
		 
		if(!isTextCalculated && this.isInflated){
			isTextCalculated = true;
			//Get the maximum allowed width of the text to use on the map 
			int layoutPadding = (int)(30 * density);
			this.arrowWidth = arrowMore.getMinimumWidth();
			this.arrowHeight = arrowMore.getMinimumHeight();
			int maxWidth = this.mapView.getWidth()-this.imageWidth-2*VFOverlayItem.paddingX - layoutPadding - arrowWidth;
			int breakTextIndexTop = 1000;
			int breakTextIndexSub = 1000;
			 
			int maxLength = Math.max(this.topTextBoxRect.width(), this.subTextBoxRect.width());
			if(maxLength > maxWidth){
				breakTextIndexTop = topTextPaint.breakText(this.itemName, true, maxWidth, null);
				if(this.itemDesc != null){
					breakTextIndexSub = subTextPaint.breakText(this.itemDesc, true, maxWidth, null);
				} 
			}