资源简介
详细博文请看:http://blog.csdn.net/abren32/article/details/48683625
代码片段和文件信息
package com.jerry.testproject.widget.lockview;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import com.jerry.testproject.R;
import java.util.ArrayList;
import java.util.List;
/**
* 九宫格解锁控件
* Created by Jerry on 2015/9/21.
*/
public class LockView extends View {
private Bitmap mNormalBitmap;
private Bitmap mPressBitmap;
private Bitmap mErrorBitmap;
private float mPointRadius;
// 手指在屏幕上的位置
private float mX mY;
// 标记当前是否在绘制状态
private boolean isDraw = false;
// 三种状态下的画笔
private Paint mPaint mPressPaint mErrorPaint;
// 九个点
private Point[][] mPoints = new Point[3][3];
// 被选中的点
private List mSelectedPoints = new ArrayList<>();
// 绘制正确的点位置
private List mPassPositions = new ArrayList<>();
private OnDrawFinishedListener mListener;
public LockView(Context context) {
this(context null);
}
public LockView(Context context AttributeSet attrs) {
this(context attrs 0);
}
public LockView(Context context AttributeSet attrs int defstyleAttr) {
super(context attrs defstyleAttr);
}
@Override
protected void onSizeChanged(int w int h int oldw int oldh) {
super.onSizeChanged(w h oldw oldh);
init();
}
@Override
protected void onDraw(Canvas canvas) {
// 绘制点
drawPoints(canvas);
// 绘制连线
drawLines(canvas);
}
private void init() {
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPressPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mErrorPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
// 按下状态的画笔
mPressPaint.setColor(Color.parseColor(“#00B7EE“));
mPressPaint.setStrokeWidth(7);
// 错误状态的画笔
mErrorPaint.setColor(Color.parseColor(“#FB0C13“));
mErrorPaint.setStrokeWidth(7);
// 加载三种状态图片
mNormalBitmap = BitmapFactory.decodeResource(getResources() R.drawable.lock_point_normal);
mPressBitmap = BitmapFactory.decodeResource(getResources() R.drawable.lock_point_press);
mErrorBitmap = BitmapFactory.decodeResource(getResources() R.drawable.lock_point_error);
mPointRadius = mNormalBitmap.getWidth() / 2;
// 当前视图的大小
int width = getWidth();
int height = getHeight();
// 九宫格点的偏移量
int offSet = Math.abs(width - height) / 2;
// x、y轴上的偏移量
int offSetX = 0 offSetY = 0;
int pointItemWidth = 0; // 每个点所占用方格的宽度
if (width > height){ // 横屏的时候
offSetX = offSet;
offSetY = 0;
pointItemWidth = height / 4;
}
if
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 10016 2015-09-23 17:14 lockview\LockView.java
文件 11117 2015-09-21 15:25 lockview\lock_point_error.png
文件 11713 2015-09-21 15:24 lockview\lock_point_normal.png
文件 10429 2015-09-21 15:25 lockview\lock_point_press.png
文件 651 2015-09-23 16:35 lockview\Point.java
目录 0 2015-09-23 17:56 lockview
----------- --------- ---------- ----- ----
43926 6
评论
共有 条评论