android.text.StaticLayout Java Examples

The following examples show how to use android.text.StaticLayout. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: XERUNG   Author: mityung   File: MaterialMultiAutoCompleteTextView.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @return True, if adjustments were made that require the view to be invalidated.
 */
private boolean adjustBottomLines() {
  // Bail out if we have a zero width; lines will be adjusted during next layout.
  if (getWidth() == 0) {
    return false;
  }
  int destBottomLines;
  textPaint.setTextSize(bottomTextSize);
  if (tempErrorText != null || helperText != null) {
    Layout.Alignment alignment = (getGravity() & Gravity.RIGHT) == Gravity.RIGHT || isRTL() ?
      Layout.Alignment.ALIGN_OPPOSITE : (getGravity() & Gravity.LEFT) == Gravity.LEFT ?
      Layout.Alignment.ALIGN_NORMAL : Layout.Alignment.ALIGN_CENTER;
    textLayout = new StaticLayout(tempErrorText != null ? tempErrorText : helperText, textPaint, getWidth() - getBottomTextLeftOffset() - getBottomTextRightOffset() - getPaddingLeft() - getPaddingRight(), alignment, 1.0f, 0.0f, true);
    destBottomLines = Math.max(textLayout.getLineCount(), minBottomTextLines);
  } else {
    destBottomLines = minBottomLines;
  }
  if (bottomLines != destBottomLines) {
    getBottomLinesAnimator(destBottomLines).start();
  }
  bottomLines = destBottomLines;
  return true;
}
 
Example #2
Source Project: XERUNG   Author: mityung   File: MaterialMultiAutoCompleteTextView.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @return True, if adjustments were made that require the view to be invalidated.
 */
private boolean adjustBottomLines() {
  // Bail out if we have a zero width; lines will be adjusted during next layout.
  if (getWidth() == 0) {
    return false;
  }
  int destBottomLines;
  textPaint.setTextSize(bottomTextSize);
  if (tempErrorText != null || helperText != null) {
    Layout.Alignment alignment = (getGravity() & Gravity.RIGHT) == Gravity.RIGHT || isRTL() ?
      Layout.Alignment.ALIGN_OPPOSITE : (getGravity() & Gravity.LEFT) == Gravity.LEFT ?
      Layout.Alignment.ALIGN_NORMAL : Layout.Alignment.ALIGN_CENTER;
    textLayout = new StaticLayout(tempErrorText != null ? tempErrorText : helperText, textPaint, getWidth() - getBottomTextLeftOffset() - getBottomTextRightOffset() - getPaddingLeft() - getPaddingRight(), alignment, 1.0f, 0.0f, true);
    destBottomLines = Math.max(textLayout.getLineCount(), minBottomTextLines);
  } else {
    destBottomLines = minBottomLines;
  }
  if (bottomLines != destBottomLines) {
    getBottomLinesAnimator(destBottomLines).start();
  }
  bottomLines = destBottomLines;
  return true;
}
 
Example #3
Source Project: material-components-android   Author: material-components   File: CollapsingTextHelper.java    License: Apache License 2.0 6 votes vote down vote up
private StaticLayout createStaticLayout(int maxLines, float availableWidth, boolean isRtl) {
  StaticLayout textLayout = null;
  try {
    textLayout =
        StaticLayoutBuilderCompat.obtain(text, textPaint, (int) availableWidth)
            .setEllipsize(TruncateAt.END)
            .setIsRtl(isRtl)
            .setAlignment(ALIGN_NORMAL)
            .setIncludePad(false)
            .setMaxLines(maxLines)
            .build();
  } catch (StaticLayoutBuilderCompatException e) {
    Log.e(TAG, e.getCause().getMessage(), e);
  }

  return checkNotNull(textLayout);
}
 
Example #4
Source Project: Yahala-Messenger   Author: wmhameed   File: PopupAudioView.java    License: MIT License 6 votes vote down vote up
public void updateProgress() {
    if (currentMessageObject == null) {
        return;
    }

    if (!seekBar.isDragging()) {
        seekBar.setProgress(currentMessageObject.audioProgress);
    }

    int duration = 0;
    if (!MediaController.getInstance().isPlayingAudio(currentMessageObject)) {
        duration = currentMessageObject.messageOwner.tl_message.media.audio.duration;
    } else {
        duration = currentMessageObject.audioProgressSec;
    }
    String timeString = String.format("%02d:%02d", duration / 60, duration % 60);
    if (lastTimeString == null || lastTimeString != null && !lastTimeString.equals(timeString)) {
        timeWidth = (int) Math.ceil(timePaint.measureText(timeString));
        timeLayout = new StaticLayout(timeString, timePaint, timeWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
    }
    invalidate();
}
 
Example #5
Source Project: ChangeTabLayout   Author: simplezhli   File: ChangeTextView.java    License: Apache License 2.0 6 votes vote down vote up
private void resetting(){
        float size;
        //字体随滑动变化
        if (level == 5000) {
            size = textSize * 1.1f;
        }else if(level == 10000 || level == 0){
            size = textSize * 1f;
        }else{
            float value = (level / 5000f) - 1f;
            size = textSize + textSize * (1 - Math.abs(value))* 0.1f;
        }

        mTextPaint.setTextSize(size);
        mTextPaint.setColor(defaultTabTextColor);
        int num = (getMeasuredWidth() - indicatorPadding) / (int) size; // 一行可以放下的字数,默认放置两行文字

//        mStaticLayout = new StaticLayout(text, mTextPaint, getMeasuredWidth() - indicatorPadding, Layout.Alignment.ALIGN_NORMAL, 1.0F, 0.0F, false);
        mStaticLayout = new StaticLayout(text, 0, text.length() > num * 2 ?  num * 2 : text.length(), mTextPaint, getMeasuredWidth() - indicatorPadding,
                Layout.Alignment.ALIGN_NORMAL, 1.0F, 0.0F, false);

    }
 
Example #6
Source Project: MousePaint   Author: android-cjj   File: HtmlTextView.java    License: MIT License 6 votes vote down vote up
public void resizeText(int paramInt1, int paramInt2) {
    CharSequence localCharSequence = getText();
    if ((localCharSequence == null) || (localCharSequence.length() == 0) || (paramInt2 <= 0) || (paramInt1 <= 0))
        return;
    TextPaint localTextPaint = getPaint();
    StaticLayout localStaticLayout = new StaticLayout(localCharSequence, localTextPaint, paramInt1, Layout.Alignment.ALIGN_NORMAL, 1.25F, 0.0F, true);
    int i = localStaticLayout.getLineCount();
    int j = paramInt2 / (localStaticLayout.getHeight() / i);
    if (i > j) {
        int k = localStaticLayout.getLineStart(j - 1);
        int m = localStaticLayout.getLineEnd(j - 1);
        float f1 = localStaticLayout.getLineWidth(j - 1);
        float f2 = localTextPaint.measureText(this.mEllipsis);
        while (paramInt1 < f1 + f2) {
            m--;
            f1 = localTextPaint.measureText(localCharSequence.subSequence(k, m + 1).toString());
        }
        setText(localCharSequence.subSequence(0, m) + this.mEllipsis);
    }
    setMaxLines(j);
    this.mNeedsResize = false;
}
 
Example #7
Source Project: RetroMusicPlayer   Author: deepshooter   File: LyricView.java    License: GNU General Public License v3.0 6 votes vote down vote up
public void setLyricFile(File file, String charsetName) {
    if (file != null && file.exists()) {
        try {
            setupLyricResource(new FileInputStream(file), charsetName);

            for (int i = 0; i < mLyricInfo.songLines.size(); i++) {

                StaticLayout staticLayout = new StaticLayout(mLyricInfo.songLines.get(i).content, mTextPaint,
                        (int) getRawSize(TypedValue.COMPLEX_UNIT_DIP, DEFAULT_MAX_LENGTH),
                        Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);

                if (staticLayout.getLineCount() > 1) {
                    mEnableLineFeed = true;
                    mExtraHeight = mExtraHeight + (staticLayout.getLineCount() - 1) * mTextHeight;
                }

                mLineFeedRecord.add(i, mExtraHeight);

            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    } else {
        invalidateView();
    }
}
 
Example #8
Source Project: Rhythm   Author: Actinarium   File: DimensionsLabel.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void draw(Canvas canvas, Rect drawableBounds) {
    final int intWidth = drawableBounds.width();
    // Make the label text based on width, height, and scale factor
    String text = prettyPrintDips(intWidth, mScaleFactor) + ' ' + MULTIPLY + ' '
            + prettyPrintDips(drawableBounds.height(), mScaleFactor);

    // Use StaticLayout, which will calculate text dimensions nicely, then position the box using Gravity.apply()
    // (although that's one instantiation per draw call...)
    // This is what happens if you're obsessed with perfection like me
    StaticLayout layout = new StaticLayout(text, mTextPaint, intWidth, Layout.Alignment.ALIGN_NORMAL, 1f, 0f, false);
    Gravity.apply(mGravity, (int) (layout.getLineMax(0) + 0.5), layout.getHeight(), drawableBounds, mTemp);

    // Draw background
    canvas.drawRect(mTemp, mBackgroundPaint);

    // We have to translate the canvas ourselves, since layout can only draw itself at (0, 0)
    canvas.save();
    canvas.translate(mTemp.left, mTemp.top);
    layout.draw(canvas);
    canvas.restore();
}
 
Example #9
Source Project: StepView   Author: shuhart   File: StepView.java    License: Apache License 2.0 6 votes vote down vote up
private int measureStepsHeight() {
    textLayouts = new StaticLayout[steps.size()];
    textPaint.setTextSize(textSize);
    int max = 0;
    for (int i = 0; i < steps.size(); i++) {
        String text = steps.get(i);
        Layout.Alignment alignment =
                isRtl() ? Layout.Alignment.ALIGN_OPPOSITE : Layout.Alignment.ALIGN_NORMAL;
        textLayouts[i] = new StaticLayout(
                text,
                textPaint,
                getMeasuredWidth() / steps.size(),
                alignment,
                1,
                0,
                true
        );
        int height = textLayouts[i].getHeight();
        max = Math.max(height, max);
    }
    return max;
}
 
Example #10
Source Project: Telegram   Author: DrKLO   File: TextSelectionHelper.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
protected int getLineHeight() {
    if (selectedView != null && selectedView.getMessageObject() != null) {
        MessageObject object = selectedView.getMessageObject();
        StaticLayout layout = null;
        if (isDescription) {
            layout = selectedView.getDescriptionlayout();
        } else if (selectedView.hasCaptionLayout()) {
            layout = selectedView.getCaptionLayout();
        } else if (object.textLayoutBlocks != null) {
            layout = object.textLayoutBlocks.get(0).textLayout;
        }
        if (layout == null) {
            return 0;
        }
        int lineHeight = layout.getLineBottom(0) - layout.getLineTop(0);
        return lineHeight;
    }
    return 0;
}
 
Example #11
Source Project: secure-quick-reliable-login   Author: kalaspuffar   File: DocumentPrintUtils.java    License: MIT License 6 votes vote down vote up
public static int drawTextBlock(Canvas canvas, String text, Layout.Alignment alignment, TextPaint textPaint, int y, int margin) {
    int width = canvas.getWidth() - (margin * 2);

    StaticLayout staticLayout = new StaticLayout(
            text,
            textPaint,
            width,
            alignment,
            1,
            0,
            false);

    canvas.save();
    canvas.translate(margin, y);
    staticLayout.draw(canvas);
    canvas.restore();

    return staticLayout.getHeight();
}
 
Example #12
Source Project: TelePlus-Android   Author: TelePlusDev   File: HintDialogCell.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void checkUnreadCounter(int mask) {
    if (mask != 0 && (mask & MessagesController.UPDATE_MASK_READ_DIALOG_MESSAGE) == 0 && (mask & MessagesController.UPDATE_MASK_NEW_MESSAGE) == 0) {
        return;
    }
    TLRPC.TL_dialog dialog = MessagesController.getInstance(currentAccount).dialogs_dict.get(dialog_id);
    if (dialog != null && dialog.unread_count != 0) {
        if (lastUnreadCount != dialog.unread_count) {
            lastUnreadCount = dialog.unread_count;
            String countString = String.format("%d", dialog.unread_count);
            countWidth = Math.max(AndroidUtilities.dp(12), (int) Math.ceil(Theme.dialogs_countTextPaint.measureText(countString)));
            countLayout = new StaticLayout(countString, Theme.dialogs_countTextPaint, countWidth, Layout.Alignment.ALIGN_CENTER, 1.0f, 0.0f, false);
            if (mask != 0) {
                invalidate();
            }
        }
    } else if (countLayout != null) {
        if (mask != 0) {
            invalidate();
        }
        lastUnreadCount = 0;
        countLayout = null;
    }
}
 
Example #13
Source Project: Overchan-Android   Author: miku-nyan   File: FlowTextHelperImpl.java    License: GNU General Public License v3.0 6 votes vote down vote up
public static boolean flowText(SpannableStringBuilder ss, int width, int height, int textFullWidth, TextPaint textPaint) {
    StaticLayout l = new StaticLayout(ss, 0, ss.length(), textPaint, textFullWidth - width, Layout.Alignment.ALIGN_NORMAL, 1.0F, 0, false);
    int lines = 0;
    while (lines < l.getLineCount() && l.getLineBottom(lines) < height) ++lines;
    ++lines;
    
    int endPos;
    if (lines < l.getLineCount()) {
        endPos = l.getLineStart(lines);
    } else {
        return false;
    }
    if (ss.charAt(endPos-1) != '\n' && ss.charAt(endPos-1) != '\r') {
        if (ss.charAt(endPos-1) == ' ') {
            ss.replace(endPos-1, endPos, "\n");
        } else {
            ss.insert(endPos, "\n");
        }
    }
    
    ss.setSpan(new FloatingMarginSpan(lines, width), 0, endPos, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return true;
}
 
Example #14
Source Project: empty-state-recyclerview   Author: tylersuehr7   File: TextStateDisplay.java    License: MIT License 6 votes vote down vote up
private void configureTextLayouts(final int availableWidth) {
    if (!textLayoutsConfigured) {
        final int totalNeededPadding = getPaddingLeft() + getPaddingRight();

        // Create new static layout only if needed!
        if ((titleLayout.getWidth() + totalNeededPadding) > availableWidth) {
            this.titleLayout = new StaticLayout(title,
                    titlePaint,
                    availableWidth - totalNeededPadding,
                    Layout.Alignment.ALIGN_NORMAL,
                    1.15f, 0, false);
        }

        // Create new static layout only if needed!
        if ((subtitleLayout.getWidth() + totalNeededPadding) > availableWidth) {
            this.subtitleLayout = new StaticLayout(subtitle,
                    subtitlePaint,
                    availableWidth - totalNeededPadding,
                    Layout.Alignment.ALIGN_NORMAL,
                    1.15f, 0, false);
        }

        textLayoutsConfigured = true;
    }
}
 
Example #15
Source Project: UltimateAndroid   Author: cymcsg   File: AutofitTextView.java    License: Apache License 2.0 5 votes vote down vote up
private static int getLineCount(CharSequence text, TextPaint paint, float size, float width,
                                DisplayMetrics displayMetrics) {
    paint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, size,
            displayMetrics));
    StaticLayout layout = new StaticLayout(text, paint, (int)width,
            Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, true);
    return layout.getLineCount();
}
 
Example #16
Source Project: Yahala-Messenger   Author: wmhameed   File: ChatBaseCell.java    License: MIT License 5 votes vote down vote up
@SuppressLint("DrawAllocation")
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    try {
        if (currentMessageObject == null) {
            super.onLayout(changed, left, top, right, bottom);
            return;
        }

        if (changed || !wasLayout) {
            layoutWidth = getMeasuredWidth();
            layoutHeight = getMeasuredHeight();

            timeLayout = new StaticLayout(currentTimeString, currentTimePaint, timeWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
            if (!media) {
                if (currentMessageObject.messageOwner.getOut() != 1) {
                    timeX = backgroundWidth - OSUtilities.dp(9) - timeWidth + (isChat ? OSUtilities.dp(52) : 0);
                } else {
                    timeX = layoutWidth - timeWidth - OSUtilities.dpf(38.5f);
                }
            } else {
                if (currentMessageObject.messageOwner.getOut() != 1) {
                    timeX = backgroundWidth - OSUtilities.dp(4) - timeWidth + (isChat ? OSUtilities.dp(52) : 0);
                } else {
                    timeX = layoutWidth - timeWidth - OSUtilities.dpf(42.0f);
                }
            }

            if (isAvatarVisible) {
                avatarImage.imageX = OSUtilities.dp(6);
                avatarImage.imageY = layoutHeight - OSUtilities.dp(45);
                avatarImage.imageW = OSUtilities.dp(42);
                avatarImage.imageH = OSUtilities.dp(42);
            }

            wasLayout = true;
        }
    } catch (Exception e) {
    }
}
 
Example #17
Source Project: a   Author: 804463258   File: PageLoader.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void drawScaledText(Canvas canvas, String line, float lineWidth, TextPaint paint, float top,int y,List<TxtLine> txtLists) {
    float x = mMarginLeft;

    if (isFirstLineOfParagraph(line)) {
        canvas.drawText(indent, x, top, paint);
        float bw = StaticLayout.getDesiredWidth(indent, paint);
        x += bw;
        line = line.substring(readBookControl.getIndent());
    }
    int gapCount = line.length() - 1;
    int i = 0;

    TxtLine txtList = new TxtLine();//每一行pzl
    txtList.CharsData = new ArrayList<TxtChar>();//pzl

    float d = ((mDisplayWidth - (mMarginLeft + mMarginRight)) - lineWidth) / gapCount;
    for (; i < line.length(); i++) {
        String c = String.valueOf(line.charAt(i));
        float cw = StaticLayout.getDesiredWidth(c, paint);
        canvas.drawText(c, x, top, paint);
        //pzl
        TxtChar txtChar = new TxtChar();
        txtChar.chardata = line.charAt(i);
        if(i==0) txtChar.charWidth = cw + d/2;
        if(i==gapCount) txtChar.charWidth = cw + d/2;
        txtChar.charWidth = cw + d;
        ;//字宽
        //txtChar.Index = y;//每页每个字的位置
        txtList.CharsData.add(txtChar);
        //pzl
        x += cw + d;
    }
    txtLists.set(y, txtList);//pzl

}
 
Example #18
Source Project: Telegram-FOSS   Author: Telegram-FOSS-Team   File: TextSelectionHelper.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void drawLine(Canvas canvas, StaticLayout layout, int line, int start, int end) {
    layout.getSelectionPath(start, end, path);
    if (path.lastBottom < layout.getLineBottom(line)) {
        int lineBottom = layout.getLineBottom(line);
        int lineTop = layout.getLineTop(line);
        float lineH = lineBottom - lineTop;
        float lineHWithoutSpaсing = path.lastBottom - lineTop;
        canvas.save();
        canvas.scale(1f, lineH / lineHWithoutSpaсing, 0, lineTop);
        canvas.drawPath(path, selectionPaint);
        canvas.restore();
    } else {
        canvas.drawPath(path, selectionPaint);
    }
}
 
Example #19
Source Project: Telegram   Author: DrKLO   File: TextSelectionHelper.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void drawLine(Canvas canvas, StaticLayout layout, int line, int start, int end) {
    layout.getSelectionPath(start, end, path);
    if (path.lastBottom < layout.getLineBottom(line)) {
        int lineBottom = layout.getLineBottom(line);
        int lineTop = layout.getLineTop(line);
        float lineH = lineBottom - lineTop;
        float lineHWithoutSpaсing = path.lastBottom - lineTop;
        canvas.save();
        canvas.scale(1f, lineH / lineHWithoutSpaсing, 0, lineTop);
        canvas.drawPath(path, selectionPaint);
        canvas.restore();
    } else {
        canvas.drawPath(path, selectionPaint);
    }
}
 
Example #20
Source Project: Telegram-FOSS   Author: Telegram-FOSS-Team   File: TextSelectionHelper.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected int[] offsetToCord(int offset) {
    fillLayoutForOffset(offset, layoutBlock);

    StaticLayout layout = layoutBlock.layout;
    if (layout == null || offset > layout.getText().length()) {
        return tmpCoord;
    }
    int line = layout.getLineForOffset(offset);
    tmpCoord[0] = (int) (layout.getPrimaryHorizontal(offset) + layoutBlock.xOffset);
    tmpCoord[1] = layout.getLineBottom(line);
    tmpCoord[1] += layoutBlock.yOffset;
    return tmpCoord;
}
 
Example #21
Source Project: Telegram-FOSS   Author: Telegram-FOSS-Team   File: TextSelectionHint.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void drawSelection(Canvas canvas, StaticLayout layout, int selectionStart, int selectionEnd) {
    int startLine = layout.getLineForOffset(selectionStart);
    int endLine = layout.getLineForOffset(selectionEnd);
    int startX = (int) layout.getPrimaryHorizontal(selectionStart);
    int endX = (int) layout.getPrimaryHorizontal(selectionEnd);
    if (startLine == endLine) {
        canvas.drawRect(startX, layout.getLineTop(startLine), endX, layout.getLineBottom(startLine), selectionPaint);
    } else {
        canvas.drawRect(startX, layout.getLineTop(startLine), layout.getLineWidth(startLine), layout.getLineBottom(startLine), selectionPaint);
        canvas.drawRect(0, layout.getLineTop(endLine), endX, layout.getLineBottom(endLine), selectionPaint);
        for (int i = startLine + 1; i < endLine; i++) {
            canvas.drawRect(0, layout.getLineTop(i), layout.getLineWidth(i), layout.getLineBottom(i), selectionPaint);
        }
    }
}
 
Example #22
Source Project: Telegram   Author: DrKLO   File: TextSelectionHelper.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected int[] offsetToCord(int offset) {
    fillLayoutForOffset(offset, layoutBlock);

    StaticLayout layout = layoutBlock.layout;
    if (layout == null || offset > layout.getText().length()) {
        return tmpCoord;
    }
    int line = layout.getLineForOffset(offset);
    tmpCoord[0] = (int) (layout.getPrimaryHorizontal(offset) + layoutBlock.xOffset);
    tmpCoord[1] = layout.getLineBottom(line);
    tmpCoord[1] += layoutBlock.yOffset;
    return tmpCoord;
}
 
Example #23
Source Project: StepView   Author: shuhart   File: StepView.java    License: Apache License 2.0 5 votes vote down vote up
private int getMaxLineWidth(StaticLayout layout) {
    int lineCount = layout.getLineCount();
    int max = 0;
    for (int i = 0; i < lineCount; i++) {
        max = (int) Math.max(layout.getLineWidth(i), max);
    }
    return max;
}
 
Example #24
Source Project: TelePlus-Android   Author: TelePlusDev   File: EditTextBoldCursor.java    License: GNU General Public License v2.0 5 votes vote down vote up
public StaticLayout getErrorLayout(int width) {
    if (TextUtils.isEmpty(errorText)) {
        return null;
    } else {
        return new StaticLayout(errorText, errorPaint, width, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
    }
}
 
Example #25
Source Project: Telegram-FOSS   Author: Telegram-FOSS-Team   File: HintDialogCell.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void update(int mask) {
    if ((mask & MessagesController.UPDATE_MASK_STATUS) != 0) {
        if (currentUser != null) {
            currentUser = MessagesController.getInstance(currentAccount).getUser(currentUser.id);
            imageView.invalidate();
            invalidate();
        }
    }
    if (mask != 0 && (mask & MessagesController.UPDATE_MASK_READ_DIALOG_MESSAGE) == 0 && (mask & MessagesController.UPDATE_MASK_NEW_MESSAGE) == 0) {
        return;
    }
    TLRPC.Dialog dialog = MessagesController.getInstance(currentAccount).dialogs_dict.get(dialog_id);
    if (dialog != null && dialog.unread_count != 0) {
        if (lastUnreadCount != dialog.unread_count) {
            lastUnreadCount = dialog.unread_count;
            String countString = String.format("%d", dialog.unread_count);
            countWidth = Math.max(AndroidUtilities.dp(12), (int) Math.ceil(Theme.dialogs_countTextPaint.measureText(countString)));
            countLayout = new StaticLayout(countString, Theme.dialogs_countTextPaint, countWidth, Layout.Alignment.ALIGN_CENTER, 1.0f, 0.0f, false);
            if (mask != 0) {
                invalidate();
            }
        }
    } else if (countLayout != null) {
        if (mask != 0) {
            invalidate();
        }
        lastUnreadCount = 0;
        countLayout = null;
    }
}
 
Example #26
Source Project: UPMiss   Author: qiujuer   File: SimpleDateView.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void drawText(Canvas canvas) {
    int left = getPaddingLeft();

    int count = canvas.save();
    canvas.translate(left, mSelectHPoint - mTexts[0].getHeight() / 2);
    mTexts[0].draw(canvas);

    for (int i = 1; i < 7; i++) {
        StaticLayout layout = mTexts[i];
        canvas.translate(mItemWidth, 0);
        layout.draw(canvas);
    }

    canvas.restoreToCount(count);
}
 
Example #27
Source Project: TelePlus-Android   Author: TelePlusDev   File: WebPlayerView.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void setDuration(int value) {
    if (duration == value || value < 0 || isStream) {
        return;
    }
    duration = value;
    durationLayout = new StaticLayout(String.format(Locale.US, "%d:%02d", duration / 60, duration % 60), textPaint, AndroidUtilities.dp(1000), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
    if (durationLayout.getLineCount() > 0) {
        durationWidth = (int) Math.ceil(durationLayout.getLineWidth(0));
    }
    invalidate();
}
 
Example #28
Source Project: TelePlus-Android   Author: TelePlusDev   File: WebPlayerView.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void setProgress(int value) {
    if (progressPressed || value < 0 || isStream) {
        return;
    }
    progress = value;
    progressLayout = new StaticLayout(String.format(Locale.US, "%d:%02d", progress / 60, progress % 60), textPaint, AndroidUtilities.dp(1000), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
    invalidate();
}
 
Example #29
Source Project: TelePlus-Android   Author: TelePlusDev   File: PopupAudioView.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void updateProgress() {
    if (currentMessageObject == null) {
        return;
    }

    if (!seekBar.isDragging()) {
        seekBar.setProgress(currentMessageObject.audioProgress);
    }

    int duration = 0;
    if (!MediaController.getInstance().isPlayingMessage(currentMessageObject)) {
        for (int a = 0; a < currentMessageObject.getDocument().attributes.size(); a++) {
            TLRPC.DocumentAttribute attribute = currentMessageObject.getDocument().attributes.get(a);
            if (attribute instanceof TLRPC.TL_documentAttributeAudio) {
                duration = attribute.duration;
                break;
            }
        }
    } else {
        duration = currentMessageObject.audioProgressSec;
    }
    String timeString = String.format("%02d:%02d", duration / 60, duration % 60);
    if (lastTimeString == null || lastTimeString != null && !lastTimeString.equals(timeString)) {
        timeWidth = (int)Math.ceil(timePaint.measureText(timeString));
        timeLayout = new StaticLayout(timeString, timePaint, timeWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
    }
    invalidate();
}
 
Example #30
Source Project: TelePlus-Android   Author: TelePlusDev   File: EditTextOutline.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected void onDraw(Canvas canvas) {
    if (mCache != null && mStrokeColor != Color.TRANSPARENT) {
        if (mUpdateCachedBitmap) {
            final int w = getMeasuredWidth() - getPaddingLeft() - getPaddingRight();
            final int h = getMeasuredHeight();
            final String text = getText().toString();

            mCanvas.setBitmap(mCache);
            mCanvas.drawColor(0, PorterDuff.Mode.CLEAR);

            float strokeWidth = mStrokeWidth > 0 ? mStrokeWidth : (float)Math.ceil(getTextSize() / 11.5f);
            mPaint.setStrokeWidth(strokeWidth);
            mPaint.setColor(mStrokeColor);
            mPaint.setTextSize(getTextSize());
            mPaint.setTypeface(getTypeface());
            mPaint.setStyle(Paint.Style.FILL_AND_STROKE);

            StaticLayout sl = new StaticLayout(text, mPaint, w, Layout.Alignment.ALIGN_CENTER, 1, 0, true);

            mCanvas.save();
            float a = (h - getPaddingTop() - getPaddingBottom() - sl.getHeight()) / 2.0f;
            mCanvas.translate(getPaddingLeft(), a + getPaddingTop());
            sl.draw(mCanvas);
            mCanvas.restore();

            mUpdateCachedBitmap = false;
        }
        canvas.drawBitmap(mCache, 0, 0, mPaint);
    }
    super.onDraw(canvas);
}