Android Open Source - android-bubble-text Cursor Drawable






From Project

Back to project page android-bubble-text.

License

The source code is released under:

MIT License

If you think the Android project android-bubble-text listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.oliveira.bubble;
// w  w w.  ja  v  a2 s .c o  m
import android.content.Context;
import android.graphics.*;
import android.text.TextPaint;

public class CursorDrawable {

    private final Paint paint;
    private ChipsEditText editText;
    private float textSize;
    private float cursorWidth;
    private AwesomeBubble bubble;
    public int color = 0xffffffff;

    public CursorDrawable(ChipsEditText editText, float textSize, float cursorWidth, Context context) {

        this.editText = editText;
        this.paint = new Paint();

        paint.setAntiAlias(true);
        paint.setFakeBoldText(true);
        paint.setStyle(Paint.Style.FILL);
        paint.setTextAlign(Paint.Align.LEFT);
        this.textSize = textSize;
        this.cursorWidth = cursorWidth;

        bubble = new AwesomeBubble(" ", 100, DefaultBubbles.get(DefaultBubbles.GRAY_WHITE_TEXT, context, (int)editText.getTextSize()), new TextPaint());
    }

    public void draw(Canvas canvas, boolean blink) {

        Point p = editText.getCursorPosition();
        canvas.save();
        canvas.translate(p.x, p.y);

        if (editText.manualModeOn) {

            int x_offset;
            int y_offset = bubble.style.bubblePadding;
            int y_h = bubble.getHeight() - 2*bubble.style.bubblePadding;

            canvas.translate(0, -BubbleSpanImpl.lineCorrectionLogic(
                    editText.getSelectionStart(),
                    editText,
                    bubble));

            if (editText.manualStart == editText.getSelectionStart()) {
                bubble.draw(canvas);
                x_offset = - bubble.getWidth()/2;
            } else {
                x_offset = 2*bubble.style.bubblePadding;
            }

            if (blink) {
                paint.setColor(0xffffffff);
                canvas.drawRect(0 - x_offset, y_offset, cursorWidth - x_offset, y_offset + y_h, paint);
            }

        } else if (blink) {
            paint.setColor(color);
            canvas.drawRect(0, 0, cursorWidth, textSize, paint);
        }
        canvas.restore();
    }

    public Point bubble_offset() {

        int x_offset = 0;
        int y_offset = 0;

        if (editText.manualModeOn) {
            y_offset = - bubble.getHeight();
            if (editText.manualStart == editText.getSelectionStart()) {
                x_offset = -bubble.getWidth() / 2;
            } else {
                x_offset = 2 * bubble.style.bubblePadding;
            }
        }

        return new Point(x_offset, y_offset);
    }

    public void setColor(int color) {
        this.color = color;
    }
}




Java Source Code List

com.asolutions.widget.RowLayout.java
com.oliveira.bubble.AutoCompleteManager.java
com.oliveira.bubble.AutoCompletePopover.java
com.oliveira.bubble.AwesomeBubble.java
com.oliveira.bubble.BubbleSpanImpl.java
com.oliveira.bubble.BubbleSpan.java
com.oliveira.bubble.BubbleStyle.java
com.oliveira.bubble.ChipsEditText.java
com.oliveira.bubble.ChipsTextView.java
com.oliveira.bubble.CursorDrawable.java
com.oliveira.bubble.DefaultBubbles.java
com.oliveira.bubble.ILayoutCallback.java
com.oliveira.bubble.Linkify.java
com.oliveira.bubble.MultilineEditText.java
com.oliveira.bubble.Regex.java
com.oliveira.bubble.TappableSpan.java
com.oliveira.bubble.Utils.java