-
-
Save valokafor/4a69301cc7c131a7702f to your computer and use it in GitHub Desktop.
This class is what provides the lines in the Note editor edit text.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.okason.simplenoteapp.models; | |
import android.content.Context; | |
import android.graphics.Canvas; | |
import android.graphics.Color; | |
import android.graphics.Paint; | |
import android.graphics.Rect; | |
import android.util.AttributeSet; | |
import android.widget.EditText; | |
/** | |
* Created by Valentine on 9/21/2015. | |
*/ | |
public class LinedEditText extends EditText{ | |
private Rect rect; | |
private Paint paint; | |
public LinedEditText(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
rect = new Rect(); | |
paint = new Paint(); | |
paint.setStyle(Paint.Style.STROKE); | |
paint.setColor(Color.parseColor("#e5e500")); | |
} | |
public void setLineColor(int color) { | |
paint.setColor(color); | |
} | |
@Override | |
protected void onDraw(Canvas canvas) { | |
int height = getHeight(); | |
int lineHeight = getLineHeight(); | |
int count = height / lineHeight; | |
// For long text with scrolling | |
if (getLineCount() > count) { | |
count = getLineCount(); | |
} | |
// Draw first line | |
int baseline = getLineBounds(0, rect); | |
for (int i = 0; i < count; i++) { | |
canvas.drawLine(rect.left, baseline + 1, rect.right, baseline + 1, paint); | |
// Draw next line | |
baseline += getLineHeight(); | |
} | |
super.onDraw(canvas); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment