package com.duome.locus;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Toast;
import com.uucrazy.lib.utils.BitmapUtil;
import com.uucrazy.lib.utils.MathUtil;
import com.uucrazy.lib.utils.RoundUtil;
import com.uucrazy.lib.utils.StringUtil;
/**
*
* 轨迹密码
*
* @author crazy24k@gmail.com
*
*/
public class LocusPassWordView extends View
{
private float w = 0;
private float h = 0;
//
private boolean isCache = false;
//
private Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
//
private Point[][] mPoints = new Point[3][3];
// 圆的半径
private float r = 0;
// 选中的点
private List<Point> sPoints = new ArrayList<Point>();
private boolean checking = false;
private Bitmap locus_round_original;
private Bitmap locus_round_click;
private Bitmap locus_round_click_error;
private Bitmap locus_line;
private Bitmap locus_line_semicircle;
private Bitmap locus_line_semicircle_error;
private Bitmap locus_arrow;
private Bitmap locus_line_error;
private long CLEAR_TIME = 800;
private int passwordMinLength = 5;
private boolean isTouch = true; // 是否可操作
private Matrix mMatrix = new Matrix();
private int lineAlpha = 100;
public LocusPassWordView(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
}
public LocusPassWordView(Context context, AttributeSet attrs)
{
super(context, attrs);
}
public LocusPassWordView(Context context)
{
super(context);
}
@Override
public void onDraw(Canvas canvas)
{
if (!isCache)
{
initCache();
}
drawToCanvas(canvas);
}
private void drawToCanvas(Canvas canvas)
{
// mPaint.setColor(Color.RED);
// Point p1 = mPoints[1][1];
// Rect r1 = new Rect(p1.x - r,p1.y - r,p1.x +
// locus_round_click.getWidth() - r,p1.y+locus_round_click.getHeight()-
// r);
// canvas.drawRect(r1, mPaint);
// 画所有点
for (int i = 0; i < mPoints.length; i++)
{
for (int j = 0; j < mPoints[i].length; j++)
{
Point p = mPoints[i][j];
if (p.state == Point.STATE_CHECK)
{
canvas.drawBitmap(locus_round_click, p.x - r, p.y - r, mPaint);
}
else if (p.state == Point.STATE_CHECK_ERROR)
{
canvas.drawBitmap(locus_round_click_error, p.x - r, p.y - r, mPaint);
}
else
{
canvas.drawBitmap(locus_round_original, p.x - r, p.y - r, mPaint);
}
}
}
// mPaint.setColor(Color.BLUE);
// canvas.drawLine(r1.left+r1.width()/2, r1.top, r1.left+r1.width()/2,
// r1.bottom, mPaint);
// canvas.drawLine(r1.left, r1.top+r1.height()/2, r1.right,
// r1.bottom-r1.height()/2, mPaint);
// 画连线
if (sPoints.size() > 0)
{
int tmpAlpha = mPaint.getAlpha();
mPaint.setAlpha(lineAlpha);
Point tp = sPoints.get(0);
for (int i = 1; i < sPoints.size(); i++)
{
Point p = sPoints.get(i);
drawLine(canvas, tp, p);
tp = p;
}
if (this.movingNoPoint)
{
drawLine(canvas, tp, new Point((int) moveingX, (int) moveingY));
}
mPaint.setAlpha(tmpAlpha);
lineAlpha = mPaint.getAlpha();
}
}
/**
* 初始化Cache信息
*
* @param canvas
*/
private void initCache()
{
w = this.getWidth();
h = this.getHeight();
float x = 0;
float y = 0;
// 以最小的为准
// 纵屏
if (w > h)
{
x = (w - h) / 2;
w = h;
}
// 横屏
else
{
y = (h - w) / 2;
h = w;
}
locus_round_original = BitmapFactory.decodeResource(this.getResources(), R.drawable.locus_round_original);
locus_round_click = BitmapFactory.decodeResource(this.getResources(), R.drawable.locus_round_click);
locus_round_click_error = BitmapFactory.decodeResource(this.getResources(), R.drawable.locus_round_click_error);
locus_line = BitmapFactory.decodeResource(this.getResources(), R.drawable.locus_line);
locus_line_semicircle = BitmapFactory.decodeResource(this.getResources(), R.drawable.locus_line_semicircle);
locus_line_error = BitmapFactory.decodeResource(this.getResources(), R.drawable.locus_line_error);
locus_line_semicircle_error = BitmapFactory.decodeResource(this.getResources(), R.drawable.locus_line_semicircle_error);
locus_arrow = BitmapFactory.decodeResource(this.getResources(), R.drawable.locus_arrow);
// Log.d("Canvas w h :", "w:" + w + " h:" + h);
// 计算圆圈图片的大小
float canvasMinW = w;
if (w > h)
{
canvasMinW = h;
}
float roundMinW = canvasMinW / 8.0f * 2;
float roundW = roundMinW / 2.f;
//
float deviation = canvasMinW % (8 * 2) / 2;
x += deviation;
x += deviation;
if (locus_round_original.getWidth() > roundMinW)
{
float sf = roundMinW * 1.0f / locus_round_original.getWidth(); // 取得缩放比例,将所有的图片进行缩放
locus_round_original = BitmapUtil.zoom(locus_round_original, sf);
locus_round_click = BitmapUtil.zoom(locus_round_click, sf);
locus_round_click_error = BitmapUtil.zoom(locus_round_click_error, sf);
locus_line = BitmapUtil.zoom(locus_line, sf);
locus_line_semicircle = BitmapUtil.zoom(locus_line_semicircle, sf);
locus_line_error = BitmapUtil.zoom(locus_line_error, sf);
locus_line_semicircle_error = BitmapUtil.zoom(locus_line_semicircle_error, sf);
locus_arrow = BitmapUtil.zoom(locus_arrow, sf);
roundW = locus_round_original.getWidth() / 2;
}
mPoints[0][0] = new Point(x + 0 + roundW, y + 0 + roundW);
mPoints[0][1] = new Point(x + w / 2, y + 0 + roundW);
mPoints[0][2] = new Point(x + w - roundW, y + 0 + roundW);
mPoints[1][0] = new Point(x + 0 + roundW, y + h / 2);
mPoints[1][1] = new Point(x + w / 2, y + h / 2);
mPoints[1][2] = new Point(x + w - roundW, y + h / 2);
mPoints[2][0] = new Point(x + 0 + roundW, y + h - roundW);
mPoints[2][1] = new Point(x + w / 2, y + h - roundW);
mPoints[2][2] = new Point(x + w - roundW, y + h - roundW);
int k = 0;
for (Point[] ps : mPoints)
{
for (Point p : ps)
{
p.index = k;
k++;
}
}
r = locus_round_original.getHeight() / 2;// roundW;
isCache = true;
}
/**
* 画两点的连接
*
* @param canvas
* @param a
* @param b
*/
private void drawLine(Canvas canvas, Point a, Point b)
{
float ah = (float) MathUtil.distance(a.x, a.y, b.x, b.y);
float degrees = getDegrees(a, b);
// Log.d("=============x===========", "rotate:" + degrees);
canvas.rotate(degrees, a.x, a.y);
if (a.state == Point.STATE_CHECK_ERROR)
{
mMatrix.setScale((ah - locus_line_semicircle_error.getWidth()) / locus_line_error.getWidth(), 1);
mMatrix.postTranslate(a.x, a.y - locus_line_error.getHeight() / 2.0f);
canvas.drawBitmap(locus_line_error, mMatrix, mPaint);
canvas.drawBitmap(locus_line_semicircle_error, a.x + locus_line_error.getWidth(), a.y - locus_line_error.getHeight() / 2.0f,
mPaint);
}
else
{
mMatrix.setScale((ah - locus_line_semicircle.getWidth()) / locus_line.getWidth(), 1);
mMatrix.postTranslate(a.x, a.y - locus_line.getHeight() / 2.0f);
canvas.drawBitmap(locus_line, mMatrix, mPaint);
canvas.drawBitmap(locus_line_semicircle, a.x + ah - locus_line_semicircle.getWidth(), a.y - locus_line.getHeight() / 2.0f,
mPaint);
}
canvas.drawBitmap(locus_arrow, a.x, a.y - locus_arrow.getHeight() / 2.0f, mPaint);
canvas.rotate(-degrees, a.x, a.y);
}
public float getDegrees(Point a, Point b)
{
float ax = a.x;// a.index % 3;
float ay =
没有合适的资源?快使用搜索试试~ 我知道了~
图案解锁源码,有需要的下载
共158个文件
svn-base:58个
class:22个
png:19个
5星 · 超过95%的资源 需积分: 10 148 下载量 187 浏览量
2012-05-23
13:12:42
上传
评论 1
收藏 1.64MB ZIP 举报
温馨提示
图案解锁源码, 网上找比较少, 忘了哪找的。希望能帮到有需要的人。 进了 作者的 一个群, 我只知道他扣扣是 叫 24k,,, 好像是把。
资源推荐
资源详情
资源评论
收起资源包目录
图案解锁源码,有需要的下载 (158个子文件)
all-wcprops 2KB
all-wcprops 757B
all-wcprops 622B
all-wcprops 589B
all-wcprops 464B
all-wcprops 356B
all-wcprops 203B
all-wcprops 203B
all-wcprops 194B
all-wcprops 94B
all-wcprops 90B
all-wcprops 89B
all-wcprops 83B
all-wcprops 81B
all-wcprops 79B
all-wcprops 79B
all-wcprops 78B
resources.ap_ 241KB
duome-locus.apk 317KB
proguard.cfg 1KB
LocusPassWordView.class 13KB
SetPasswordActivity.class 3KB
BitmapUtil.class 2KB
LoginActivity.class 2KB
LoginActivity$1.class 2KB
SetPasswordActivity$2.class 1KB
SetPasswordActivity$1.class 1KB
StringUtil.class 1KB
MainActivity.class 1KB
R$drawable.class 1KB
MainActivity$1.class 1013B
LoginActivity$2.class 993B
Point.class 712B
LocusPassWordView$1.class 689B
MathUtil.class 669B
R$id.class 557B
RoundUtil.class 544B
R.class 510B
R$layout.class 476B
R$string.class 418B
R$attr.class 331B
LocusPassWordView$OnCompleteListener.class 286B
.classpath 439B
classes.dex 163KB
entries 3KB
entries 1KB
entries 1KB
entries 888B
entries 728B
entries 572B
entries 400B
entries 400B
entries 385B
entries 307B
entries 251B
entries 248B
entries 243B
entries 242B
entries 231B
entries 223B
entries 220B
android-support-v4.jar 137KB
LocusPassWordView.java 16KB
SetPasswordActivity.java 2KB
R.java 2KB
LoginActivity.java 2KB
BitmapUtil.java 2KB
MainActivity.java 831B
StringUtil.java 702B
MathUtil.java 522B
Point.java 476B
RoundUtil.java 335B
bg.png 154KB
locus_button_normal.png 30KB
locus_button_selected.png 30KB
locus_button.png 30KB
locus_button_left_bg.png 27KB
locus_round_original.png 27KB
locus_round_click.png 27KB
locus_round_click_error.png 26KB
locus_button_bg.png 25KB
locus_button_right_bg.png 24KB
icon.png 4KB
locus_arrow.png 3KB
locus_line_semicircle.png 3KB
locus_line_semicircle_error.png 3KB
locus_line.png 3KB
locus_line_error.png 3KB
icon.png 3KB
icon.png 2KB
border.9.png 144B
org.eclipse.jdt.core.prefs 22KB
org.eclipse.jdt.ui.prefs 121B
.project 1KB
default.properties 362B
bg.png.svn-base 154KB
locus_button_normal.png.svn-base 30KB
locus_button_selected.png.svn-base 30KB
locus_button.png.svn-base 30KB
locus_button_left_bg.png.svn-base 27KB
共 158 条
- 1
- 2
zgf1991
- 粉丝: 152
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
前往页