Back to project page android_tutorial_projects.
The source code is released under:
Copyright (c) 2013, Uthcode All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redi...
If you think the Android project android_tutorial_projects listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.uthcode.todolist; /* ww w . jav a2 s .c o m*/ import android.content.Context; import android.content.res.Resources; import android.graphics.Canvas; import android.graphics.Paint; import android.util.AttributeSet; import android.widget.CheckBox; // Sometimes none of the built-in controls meet your needs. public class ToDoListItemView extends CheckBox { private Integer item; public void initlayout() { final float scale = this.getResources().getDisplayMetrics().density; this.setPadding(this.getPaddingLeft() + (int)(15.0f * scale + 10.0f), this.getPaddingTop(), this.getPaddingRight(), this.getPaddingBottom()); } public ToDoListItemView(Context context) { super(context); initlayout(); } public ToDoListItemView(Context context, AttributeSet attrs) { super(context, attrs); initlayout(); } public int getItem() { return item; } public void setItem(Integer item) { this.item = item; } // We override onDraw method to modify the View's appearance @Override public void onDraw(Canvas canvas) { // Get a reference to resources table. final Resources resources = getResources(); // Anti-aliasing is important when drawing text as anti-aliased // text is significantly easier to read. final Paint marginPaint = new Paint(Paint.ANTI_ALIAS_FLAG); // Margin paint brush marginPaint.setColor(resources.getColor(R.color.margin_color)); final Paint linePaint = new Paint(Paint.ANTI_ALIAS_FLAG); // Line paint brush linePaint.setColor(resources.getColor(R.color.line_color)); // Get the paper background color final int paperColor = resources.getColor(R.color.paper_color); // Get the margin width. final int marginWidth = (int) resources.getDimension(R.dimen.margin); // Fill entire canvas bitmap with paper color. canvas.drawColor(paperColor); // Draw ruled line final int lineX1 = 0; final int lineY1 = getMeasuredHeight(); final int lineX2 = getMeasuredWidth(); final int lineY2 = getMeasuredHeight(); canvas.drawLine(lineX1, lineY1, lineX2, lineY2, linePaint); // Draw margin final int marginX1 = marginWidth; final int marginY1 = 0; final int marginX2 = marginWidth; final int marginY2 = getMeasuredHeight(); canvas.drawLine(marginX1, marginY1, marginX2, marginY2, marginPaint); // Move the text across from the margin //canvas.translate(marginWidth, 0); // Render the text as usual using the TextView base class. super.onDraw(canvas); } }