library/src/main/java/com/alamkanak/weekview/WeekView.java
/**
     * Draw the name of the event on top of the event rectangle.
     *
     * @param event        The event of which the title (and location) should be drawn.
     * @param rect         The rectangle on which the text is to be drawn.
     * @param canvas       The canvas to draw upon.
     * @param originalTop  The original top position of the rectangle. The rectangle may have some of its portion outside of the visible area.
     * @param originalLeft The original left position of the rectangle. The rectangle may have some of its portion outside of the visible area.
     */
Draw the name of the event on top of the event rectangle.
@param event        The event of which the title (and location) should be drawn.
@param rect         The rectangle on which the text is to be drawn.
@param canvas       The canvas to draw upon.
@param originalTop  The original top position of the rectangle. The rectangle may have some of its portion outside of the visible area.
@param originalLeft The original left position of the rectangle. The rectangle may have some of its portion outside of the visible area.
Draw the name of the event on top of the event rectangle . @param event The event of which the title ( and location ) should be drawn . @param rect The rectangle on which the text is to be drawn . @param canvas The canvas to draw upon . @param originalTop The original top position of the rectangle . The rectangle may have some of its portion outside of the visible area . @param originalLeft The original left position of the rectangle . The rectangle may have some of its portion outside of the visible area .
private void drawEventTitle(WeekViewEvent event, RectF rect, Canvas canvas, float originalTop, float originalLeft) {
        if (rect.right - rect.left - mEventPadding * 2 < 0) {
            return;
        }
        if (rect.bottom - rect.top - mEventPadding * 2 < 0) {
            return;
        }
        SpannableStringBuilder bob = new SpannableStringBuilder();
        if (event.getName() != null) {
            bob.append(event.getName());
            bob.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, bob.length(), 0);
            bob.append(' ');
        }
        if (event.getLocation() != null) {
            bob.append(event.getLocation());
        }
        int availableHeight = (int) (rect.bottom - originalTop - mEventPadding * 2);
        int availableWidth = (int) (rect.right - originalLeft - mEventPadding * 2);
        StaticLayout textLayout = new StaticLayout(bob, mEventTextPaint, availableWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
        int lineHeight = textLayout.getHeight() / textLayout.getLineCount();
        if (availableHeight >= lineHeight) {
            float top = originalTop + mEventPadding + (availableHeight - lineHeight) / 2.0f;
            float left = originalLeft + mEventPadding;
            if (event.hasDrawable()) {
                for (int i = 0; i <= 5; i++) {
                    bob.insert(0, " ");
                }
            }
            textLayout = getTruncatedEventTitle(bob, availableHeight, availableWidth, lineHeight, event.isAllDay());
            if (textLayout.getLineCount() > 1) {
                top = originalTop + mEventPadding + (availableHeight - textLayout.getHeight()) / 2.0f;
            }
            if (event.hasDrawable()) {
                Drawable drawable = ContextCompat.getDrawable(getContext(), event.getDrawableId());
                drawable.setBounds((int) left, (int) top, (int) left + mEventDrawableSize, (int) (top + mEventDrawableSize));
                drawable.draw(canvas);
            }
            canvas.save();
            canvas.translate(left, top);
            textLayout.draw(canvas);
            canvas.restore();
        }
    }
private void drawEventTitle ( WeekViewEvent event , RectF rect , Canvas canvas , float originalTop , float originalLeft ) { if ( rect . right - rect . left - mEventPadding * 2 < 0 ) { return ; } if ( rect . bottom - rect . top - mEventPadding * 2 < 0 ) { return ; } SpannableStringBuilder bob = new SpannableStringBuilder ( ) ; if ( event . getName ( ) != null ) { bob . append ( event . getName ( ) ) ; bob . setSpan ( new StyleSpan ( android . graphics . Typeface . BOLD ) , 0 , bob . length ( ) , 0 ) ; bob . append ( ' ' ) ; } if ( event . getLocation ( ) != null ) { bob . append ( event . getLocation ( ) ) ; } int availableHeight = ( int ) ( rect . bottom - originalTop - mEventPadding * 2 ) ; int availableWidth = ( int ) ( rect . right - originalLeft - mEventPadding * 2 ) ; StaticLayout textLayout = new StaticLayout ( bob , mEventTextPaint , availableWidth , Layout . Alignment . ALIGN_NORMAL , 1.0f , 0.0f , false ) ; int lineHeight = textLayout . getHeight ( ) / textLayout . getLineCount ( ) ; if ( availableHeight >= lineHeight ) { float top = originalTop + mEventPadding + ( availableHeight - lineHeight ) / 2.0f ; float left = originalLeft + mEventPadding ; if ( event . hasDrawable ( ) ) { for ( int i = 0 ; i <= 5 ; i ++ ) { bob . insert ( 0 , " " ) ; } } textLayout = getTruncatedEventTitle ( bob , availableHeight , availableWidth , lineHeight , event . isAllDay ( ) ) ; if ( textLayout . getLineCount ( ) > 1 ) { top = originalTop + mEventPadding + ( availableHeight - textLayout . getHeight ( ) ) / 2.0f ; } if ( event . hasDrawable ( ) ) { Drawable drawable = ContextCompat . getDrawable ( getContext ( ) , event . getDrawableId ( ) ) ; drawable . setBounds ( ( int ) left , ( int ) top , ( int ) left + mEventDrawableSize , ( int ) ( top + mEventDrawableSize ) ) ; drawable . draw ( canvas ) ; } canvas . save ( ) ; canvas . translate ( left , top ) ; textLayout . draw ( canvas ) ; canvas . restore ( ) ; } }
Draw the name of the event on top of the event rectangle.
Draw the name of the event on top of the event rectangle .
// Prepare the name of the event. // Prepare the location of the event. // Get text dimensions. // Calculate top. // Calculate left. // Add extra space for drawable. // Get text. // Draw drawable.