notecipher / app / src / info / guardianproject / notepadbot / LinedEditText.java @ 7018009a
History | View | Annotate | Download (1.26 KB)
1 |
package info.guardianproject.notepadbot; |
---|---|
2 |
|
3 |
import android.content.Context; |
4 |
import android.graphics.Canvas; |
5 |
import android.graphics.Paint; |
6 |
import android.graphics.Rect; |
7 |
import android.util.AttributeSet; |
8 |
import android.widget.EditText; |
9 |
|
10 |
/**
|
11 |
* A custom EditText that draws lines between each line of text that is displayed.
|
12 |
*/
|
13 |
public class LinedEditText extends EditText { |
14 |
private Rect mRect;
|
15 |
private Paint mPaint; |
16 |
private boolean showLines; |
17 |
|
18 |
// we need this constructor for LayoutInflater
|
19 |
public LinedEditText(Context context, AttributeSet attrs) { |
20 |
super(context, attrs);
|
21 |
|
22 |
mRect = new Rect();
|
23 |
mPaint = new Paint(); |
24 |
mPaint.setStyle(Paint.Style.STROKE);
|
25 |
mPaint.setColor(getResources().getColor(R.color.gray)); |
26 |
|
27 |
showLines = Settings.getNoteLinesOption(context); |
28 |
} |
29 |
|
30 |
@Override
|
31 |
protected void onDraw(Canvas canvas) { |
32 |
int height = canvas.getHeight();
|
33 |
int curHeight = 0; |
34 |
int baseline = getLineBounds(0, mRect); |
35 |
if(showLines) {
|
36 |
for (curHeight = baseline + 3; curHeight < height; curHeight += getLineHeight()) { |
37 |
canvas.drawLine(mRect.left, curHeight, mRect.right, curHeight, mPaint); |
38 |
} |
39 |
} |
40 |
super.onDraw(canvas);
|
41 |
} |
42 |
} |