PointInfo[] points = new PointInfo[9];
PointInfo startPoint = null;
int width, height;
int moveX, moveY;
boolean isUp = false;
Context ctx;
StringBuffer lockString = new StringBuffer();
public MmsLockSetPwd(Context context) {
super(context);
ctx = context;
// this.setBackgroundColor(Color.WHITE);
initPaint();
}
public MmsLockSetPwd(Context context, AttributeSet attrs) {
super(context, attrs);
// this.setBackgroundColor(Color.WHITE);
tv_forget_pwd.setVisibility(View.GONE); //zj add
initPaint();
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
width = getWidth();
height = getHeight();
if (width != 0 && height != 0) {
initPoints(points);
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
@Override
protected void onLayout(boolean changed, int left, int top, int right,
int bottom) {
super.onLayout(changed, left, top, right, bottom);
}
private int startX = 0, startY = 0;
@Override
protected void onDraw(Canvas canvas) {
// canvas.drawText(“passwd:” + lockString, 0, 40, textPaint);
if (moveX != 0 && moveY != 0 && startX != 0 && startY != 0) {
// drawLine(canvas, startX, startY, moveX, moveY);
}
drawNinePoint(canvas);
super.onDraw(canvas);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
boolean flag = true;
if (isUp) {
finishDraw();
flag = false;
} else {
handlingEvent(event);
flag = true;
}
return flag;
}
private void handlingEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_MOVE:
moveX = (int) event.getX();
moveY = (int) event.getY();
for (PointInfo temp : points) {
if (temp.isInMyPlace(moveX, moveY)
&& temp.isSelected() == false) {
temp.setSelected(true);
startX = temp.getCenterX();
startY = temp.getCenterY();
int len = lockString.length();
if (len != 0) {
int preId = lockString.charAt(len - 1) - 48;
points[preId].setNextId(temp.getId());
}
lockString.append(temp.getId());
break;
}
}
invalidate(0, height - width, width, height);
break;
case MotionEvent.ACTION_DOWN:
int downX = (int) event.getX();
int downY = (int) event.getY();
for (PointInfo temp : points) {
if (temp.isInMyPlace(downX, downY)) {
temp.setSelected(true);
startPoint = temp;
startX = temp.getCenterX();
startY = temp.getCenterY();
lockString.append(temp.getId());
break;
}
}
invalidate(0, height - width, width, height);
break;
case MotionEvent.ACTION_UP:
startX = startY = moveX = moveY = 0;
isUp = true;
invalidate();
savePwd();
break;
default:
break;
}
}
private void finishDraw() {
for (PointInfo temp : points) {
temp.setSelected(false);
temp.setNextId(temp.getId());
}
lockString.delete(0, lockString.length());
isUp = false;
invalidate();
}
private void initPoints(PointInfo[] points) {
int len = points.length;
int seletedSpacing = (width - selectedBitmapDiameter * 3) / 4;
int seletedX = seletedSpacing;
int seletedY = height - width + seletedSpacing;
int defaultX = seletedX + selectedBitmapRadius - defaultBitmapRadius;
int defaultY = seletedY + selectedBitmapRadius - defaultBitmapRadius;
for (int i = 0; i < len; i++) {
if (i == 3 || i == 6) {
seletedX = seletedSpacing;
seletedY += selectedBitmapDiameter + seletedSpacing;
defaultX = seletedX + selectedBitmapRadius
- defaultBitmapRadius;
defaultY += selectedBitmapDiameter + seletedSpacing;
}
points[i] = new PointInfo(i, defaultX, defaultY, seletedX, seletedY);
seletedX += selectedBitmapDiameter + seletedSpacing;
defaultX += selectedBitmapDiameter + seletedSpacing;
}
}
private void initPaint() {
initLinePaint(linePaint);
initTextPaint(textPaint);
initWhiteLinePaint(whiteLinePaint);
}
/**
- @param paint
*/
private void initTextPaint(Paint paint) {
textPaint.setTextSize(30);
textPaint.setAntiAlias(true);
textPaint.setTypeface(Typeface.MONOSPACE);
}
/**
- @param paint
*/
private void initLinePaint(Paint paint) {
//paint.setColor(Color.GRAY);
paint.setColor(Color.parseColor(“#1E90FF”));
//paint.setStyle(Style.STROKE);
paint.setStyle(Style.FILL);
paint.setStrokeWidth(10);
paint.setAntiAlias(true);
paint.setStrokeCap(Cap.ROUND);
}
/**
- @param paint
*/
private void initWhiteLinePaint(Paint paint) {
//paint.setColor(Color.WHITE);
paint.setColor(Color.parseColor(“#1E90FF”));
paint.setStrokeWidth(8);
paint.setAntiAlias(true);
paint.setStrokeCap(Cap.ROUND);
}
/**
-
@param canvas
*/
private void drawNinePoint(Canvas canvas) {
if (startPoint != null) {
drawEachLine(canvas, startPoint);
}
for (PointInfo pointInfo : points) {
if (pointInfo != null) {
if (pointInfo.isSelected()) {
canvas.drawBitmap(selectedBitmap, pointInfo.getSeletedX(),
pointInfo.getSeletedY(), null);
}else{ // zj add
canvas.drawBitmap(defaultBitmap, pointInfo.getDefaultX(),
pointInfo.getDefaultY(), null);
}
}
}
}
/**
-
@param canvas
-
@param point
*/
private void drawEachLine(Canvas canvas, PointInfo point) {
if (point.hasNextId()) {
int n = point.getNextId();
drawLine(canvas, point.getCenterX(), point.getCenterY(),
points[n].getCenterX(), points[n].getCenterY());
drawEachLine(canvas, points[n]);
}
}
/**
-
@param canvas
-
@param startX
-
@param startY
-
@param stopX
-
@param stopY
*/
private void drawLine(Canvas canvas, float startX, float startY,
float stopX, float stopY) {
canvas.drawLine(startX, startY, stopX, stopY, linePaint);
canvas.drawLine(startX, startY, stopX, stopY, whiteLinePaint);
}
/**
-
@author zkwlx
*/
private class PointInfo {
private int id;
private int nextId;
private boolean selected;
private int defaultX;
private int defaultY;
private int seletedX;
private int seletedY;
public PointInfo(int id, int defaultX, int defaultY, int seletedX,
int seletedY) {
this.id = id;
this.nextId = id;
this.defaultX = defaultX;
this.defaultY = defaultY;
this.seletedX = seletedX;
this.seletedY = seletedY;
}
public boolean isSelected() {
return selected;
}
public void setSelected(boolean selected) {
this.selected = selected;
}
public int getId() {
return id;
}
public int getDefaultX() {
return defaultX;
}
public int getDefaultY() {
return defaultY;
}
public int getSeletedX() {
return seletedX;
}
public int getSeletedY() {
return seletedY;
}
public int getCenterX() {
return seletedX + selectedBitmapRadius;
}
public int getCenterY() {
return seletedY + selectedBitmapRadius;
}
public boolean hasNextId() {
return nextId != id;
}
public int getNextId() {
return nextId;
}
public void setNextId(int nextId) {
this.nextId = nextId;
}
/**
-
@param x
-
@param y
*/
public boolean isInMyPlace(int x, int y) {
boolean inX = x > seletedX
&& x < (seletedX + selectedBitmapDiameter);
boolean inY = y > seletedY
&& y < (seletedY + selectedBitmapDiameter);
return (inX && inY);
}
}
public String getPwd() {
return lockString.toString();
}
public void savePwd() {
Intent intent = new Intent();
SharedPreferences shareDate = ctx.getSharedPreferences(“GUE_PWD”, 0);
boolean isSetFirst = shareDate.getBoolean(“IS_SET_FIRST”, false);
if (isSetFirst) {
String pwd = this.getPwd();
String first_pwd = shareDate.getString(“FIRST_PWD”, “HAVE NO PWD”);
if (pwd.equals(first_pwd)) {
shareDate.edit().clear().commit();
shareDate.edit().putBoolean(“IS_SET”, true).commit();
shareDate.edit().putString(“GUE_PWD”, pwd).commit();
intent.setClass(ctx, MmsLockSetPwdOk.class);
} else {
shareDate.edit().putBoolean(“SECOND_ERROR”, true).commit();
intent.setClass(ctx, MmsLock.class);
}
} else {
shareDate.edit().clear().commit();
shareDate.edit().putString(“FIRST_PWD”, this.getPwd()).commit();
shareDate.edit().putBoolean(“IS_SET_FIRST”, true).commit();
intent.setClass(ctx, MmsLock.class);
}
ctx.startActivity(intent);
((Activity) ctx).finish();
}
}
手势密码设置成功后,让用户输入字符密保,以防遗忘手势密码:
/*
- ZJ add for Mms Lock
*/
package com.android.mms.ui;
import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MmsLockSetPwdOk extends Activity {
//private TextView showInfo;
private EditText secondPwd;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
//this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(com.android.mms.R.layout.mms_lock_res);
//showInfo = (TextView)findViewById(com.android.mms.R.id.res_info);
//SharedPreferences shareDate = getSharedPreferences(“GUE_PWD”, 0);
//String pwd = shareDate.getString(“GUE_PWD”, “HAVE NO PWD !”);
// showInfo.setText("密码是: "+pwd);
//showInfo.setText(com.android.mms.R.string.zj_set_pwd_tip);
}
public void saveSecondPwd(View v){
secondPwd = (EditText)findViewById(com.android.mms.R.id.second_pwd);
String secondStr = secondPwd.getText().toString();
if(secondStr!= null && secondStr.trim().length() != 0){
//获取SharedPreferences对象
// Context ctx = MainActivity.this;
SharedPreferences secondShare = getSharedPreferences(“SECOND_PWD”, MODE_PRIVATE);
//存入数据
Editor editor = secondShare.edit();
editor.putString(“SECOND_KEY”, secondStr);
editor.putBoolean(“SECOND_IS_SET”, true);
editor.commit();
Toast.makeText(this, com.android.mms.R.string.zj_set_pwd_success, Toast.LENGTH_SHORT).show();
finish();
}else{
Toast.makeText(this, com.android.mms.R.string.zj_pwd_null, Toast.LENGTH_SHORT).show();
}
}
}
MmsLockCheckPwd.java:
/*
- ZJ add for Mms Lock
*/
package com.android.mms.ui;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.graphics.Paint.Cap;
import android.graphics.Paint.Style;
//import android.os.Vibrator; // zj Cancel
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;
public class MmsLockCheckPwd extends View {
TextView tv_forget_pwd = (TextView) findViewById(com.android.mms.R.id.zj_lock_forget_pwd);
Paint linePaint = new Paint();
Paint whiteLinePaint = new Paint();
Paint textPaint = new Paint();
Bitmap defaultBitmap = BitmapFactory.decodeResource(getResources(),
com.android.mms.R.drawable.lock);
int defaultBitmapRadius = defaultBitmap.getWidth() / 2;
Bitmap selectedBitmap = BitmapFactory.decodeResource(getResources(),
com.android.mms.R.drawable.indicator_lock_area);
int selectedBitmapDiameter = selectedBitmap.getWidth();
int selectedBitmapRadius = selectedBitmapDiameter / 2;
PointInfo[] points = new PointInfo[9];
PointInfo startPoint = null;
int width, height;
int moveX, moveY;
boolean isUp = false;
Context ctx;
StringBuffer lockString = new StringBuffer();
public MmsLockCheckPwd(Context context) {
super(context);
ctx = context;
// this.setBackgroundColor(Color.WHITE);
initPaint();
}
public MmsLockCheckPwd(Context context, AttributeSet attrs) {
super(context, attrs);
// this.setBackgroundColor(Color.WHITE);
tv_forget_pwd.setVisibility(View.VISIBLE); // zj add
initPaint();
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
width = getWidth();
height = getHeight();
if (width != 0 && height != 0) {
initPoints(points);
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
@Override
protected void onLayout(boolean changed, int left, int top, int right,
int bottom) {
super.onLayout(changed, left, top, right, bottom);
}
private int startX = 0, startY = 0;
@Override
protected void onDraw(Canvas canvas) {
// canvas.drawText(“passwd:” + lockString, 0, 40, textPaint);
if (moveX != 0 && moveY != 0 && startX != 0 && startY != 0) {
// drawLine(canvas, startX, startY, moveX, moveY);
}
drawNinePoint(canvas);
super.onDraw(canvas);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
boolean flag = true;
if (isUp) {
finishDraw();
flag = false;
} else {
handlingEvent(event);
flag = true;
}
return flag;
}
private void handlingEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_MOVE:
moveX = (int) event.getX();
moveY = (int) event.getY();
for (PointInfo temp : points) {
if (temp.isInMyPlace(moveX, moveY)
&& temp.isSelected() == false) {
temp.setSelected(true);
startX = temp.getCenterX();
startY = temp.getCenterY();
int len = lockString.length();
if (len != 0) {
int preId = lockString.charAt(len - 1) - 48;
points[preId].setNextId(temp.getId());
}
lockString.append(temp.getId());
break;
}
}
invalidate(0, height - width, width, height);
break;
case MotionEvent.ACTION_DOWN:
int downX = (int) event.getX();
int downY = (int) event.getY();
for (PointInfo temp : points) {
if (temp.isInMyPlace(downX, downY)) {
temp.setSelected(true);
startPoint = temp;
startX = temp.getCenterX();
startY = temp.getCenterY();
lockString.append(temp.getId());
break;
}
}
invalidate(0, height - width, width, height);
break;
case MotionEvent.ACTION_UP:
startX = startY = moveX = moveY = 0;
isUp = true;
invalidate();
savePwd();
break;
default:
break;
}
}
private void finishDraw() {
for (PointInfo temp : points) {
temp.setSelected(false);
temp.setNextId(temp.getId());
}
lockString.delete(0, lockString.length());
isUp = false;
invalidate();
}
private void initPoints(PointInfo[] points) {
int len = points.length;
int seletedSpacing = (width - selectedBitmapDiameter * 3) / 4;
int seletedX = seletedSpacing;
int seletedY = height - width + seletedSpacing;
int defaultX = seletedX + selectedBitmapRadius - defaultBitmapRadius;
int defaultY = seletedY + selectedBitmapRadius - defaultBitmapRadius;
for (int i = 0; i < len; i++) {
if (i == 3 || i == 6) {
seletedX = seletedSpacing;
seletedY += selectedBitmapDiameter + seletedSpacing;
defaultX = seletedX + selectedBitmapRadius
- defaultBitmapRadius;
defaultY += selectedBitmapDiameter + seletedSpacing;
}
points[i] = new PointInfo(i, defaultX, defaultY, seletedX, seletedY);
seletedX += selectedBitmapDiameter + seletedSpacing;
defaultX += selectedBitmapDiameter + seletedSpacing;
}
}
private void initPaint() {
initLinePaint(linePaint);
initTextPaint(textPaint);
initWhiteLinePaint(whiteLinePaint);
}
private void initTextPaint(Paint paint) {
textPaint.setTextSize(30);
textPaint.setAntiAlias(true);
textPaint.setTypeface(Typeface.MONOSPACE);
}
private void initLinePaint(Paint paint) {
// paint.setColor(Color.GRAY);
paint.setColor(Color.parseColor(“#1E90FF”));
// paint.setStyle(Style.STROKE);
paint.setStyle(Style.FILL);
paint.setStrokeWidth(10);
paint.setAntiAlias(true);
paint.setStrokeCap(Cap.ROUND);
}
private void initWhiteLinePaint(Paint paint) {
// paint.setColor(Color.WHITE);
paint.setColor(Color.parseColor(“#1E90FF”));
paint.setStrokeWidth(8);
paint.setAntiAlias(true);
paint.setStrokeCap(Cap.ROUND);
}
private void drawNinePoint(Canvas canvas) {
if (startPoint != null) {
drawEachLine(canvas, startPoint);
}
for (PointInfo pointInfo : points) {
if (pointInfo != null) {
if (pointInfo.isSelected()) {
canvas.drawBitmap(selectedBitmap, pointInfo.getSeletedX(),
pointInfo.getSeletedY(), null);
} else { // zj add else case
canvas.drawBitmap(defaultBitmap, pointInfo.getDefaultX(),
pointInfo.getDefaultY(), null);
}
}
}
}
/**
-
@param canvas
-
@param point
*/
private void drawEachLine(Canvas canvas, PointInfo point) {
if (point.hasNextId()) {
int n = point.getNextId();
drawLine(canvas, point.getCenterX(), point.getCenterY(),
points[n].getCenterX(), points[n].getCenterY());
drawEachLine(canvas, points[n]);
}
}
/**
-
@param canvas
-
@param startX
-
@param startY
-
@param stopX
-
@param stopY
*/
private void drawLine(Canvas canvas, float startX, float startY,
float stopX, float stopY) {
canvas.drawLine(startX, startY, stopX, stopY, linePaint);
canvas.drawLine(startX, startY, stopX, stopY, whiteLinePaint);
}
private class PointInfo {
private int id;
private int nextId;
private boolean selected;
private int defaultX;
private int defaultY;
private int seletedX;
private int seletedY;
public PointInfo(int id, int defaultX, int defaultY, int seletedX,
int seletedY) {
this.id = id;
this.nextId = id;
this.defaultX = defaultX;
this.defaultY = defaultY;
this.seletedX = seletedX;
this.seletedY = seletedY;
}
public boolean isSelected() {
return selected;
}
public void setSelected(boolean selected) {
this.selected = selected;
}
public int getId() {
return id;
}
public int getDefaultX() {
return defaultX;
}
public int getDefaultY() {
return defaultY;
}
public int getSeletedX() {
return seletedX;
}
public int getSeletedY() {
return seletedY;
}
public int getCenterX() {
return seletedX + selectedBitmapRadius;
}
public int getCenterY() {
return seletedY + selectedBitmapRadius;
}
public boolean hasNextId() {
return nextId != id;
}
public int getNextId() {
return nextId;
}
public void setNextId(int nextId) {
this.nextId = nextId;
}
/**
-
@param x
-
@param y
*/
public boolean isInMyPlace(int x, int y) {
boolean inX = x > seletedX
&& x < (seletedX + selectedBitmapDiameter);
boolean inY = y > seletedY
&& y < (seletedY + selectedBitmapDiameter);
return (inX && inY);
}
}
public String getPwd() {
return lockString.toString();
}
public void savePwd() {
Intent intent = new Intent();
SharedPreferences shareDate = ctx.getSharedPreferences(“GUE_PWD”, 0);
String pwd = this.getPwd();
String first_pwd = shareDate.getString(“GUE_PWD”, “HAVE NO PWD”);
if (pwd.equals(first_pwd)) {
// shareDate.edit().clear().commit();
// shareDate.edit().putBoolean(“IS_SET”, true).commit();
// shareDate.edit().putString(“GUE_PWD”, pwd).commit();
intent.setClass(ctx, MmsLockList.class);
} else {
// shareDate.edit().putBoolean(“SECOND_ERROR”, true).commit();
intent.setClass(ctx, MmsLock.class);
}
ctx.startActivity(intent);
((Activity) ctx).finish();
}
}
到这儿核心功能都贴出来了,布局和资源还有项目代码等以后分离出独立工程的时候附加在后边。
有疑问欢迎交流。
转载请注明出处:周木水的CSDN博客 http://blog.csdn.net/zhoumushui
我的GitHub:周木水的GitHub https://github.com/zhoumushui
洗衣机坏了,有时候按一会儿就可以启动了,今天怎么弄都没效果,大概是启动电容的问题吧,悲剧。
下午去看公司部门间的球赛,我们队再胜一局,维持不败战绩,作为拉拉队员还是很开心的。
今天接着昨天的内容开始~
哎呀,代码在公司,明天再补充。先去学习。
Mms类:
/*
- ZJ add for Mms Lock
*/
package com.android.mms.ui;
public class MmsLockMsg {
int _id;
int thread_id; // 号码区分标识
long address; // 号码
long date; // 日期
int type;//信息类型
// long date_sent; // 发送日期
String body; // 短信内容
String name;
public MmsLockMsg(int id, int thread_id, long address, long date,int type,String body,String name) {
this._id = id;
this.thread_id = thread_id;
this.address = address;
this.date = date;
this.type =type;
this.body = body;
this.name = name;
}
public MmsLockMsg(int thread_id, long address, long date,int type, String body,String name) {
this.thread_id = thread_id;
this.address = address;
this.date = date;
this.type =type;
this.body = body;
this.name = name;
}
public int getId() {
return _id;
}
public int getThreadId() {
return thread_id;
}
public void setThreadId(int thread_id) {
this.thread_id = thread_id;
}
public long getAddress() {
return address;
}
public void setAddress(long address) {
this.address = address;
}
public long getDate() {
return date;
}
public void setDate(long date) {
this.date = date;
}
public int getType(){
return type;
}
public void setType(int type){
this.type=type;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
}
设置手势密码页:
/*
- ZJ add for Mms Lock
*/
package com.android.mms.ui;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Typeface;
import android.graphics.Paint.Cap;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;
public class MmsLockSetPwd extends View {
TextView tv_forget_pwd = (TextView)findViewById(com.android.mms.R.id.zj_lock_forget_pwd);
Paint linePaint = new Paint();
Paint whiteLinePaint = new Paint();
Paint textPaint = new Paint();
Bitmap defaultBitmap = BitmapFactory.decodeResource(getResources(),
com.android.mms.R.drawable.lock);
int defaultBitmapRadius = defaultBitmap.getWidth() / 2;
Bitmap selectedBitmap = BitmapFactory.decodeResource(getResources(),
com.android.mms.R.drawable.indicator_lock_area);
int selectedBitmapDiameter = selectedBitmap.getWidth();
int selectedBitmapRadius = selectedBitmapDiameter / 2;
PointInfo[] points = new PointInfo[9];
PointInfo startPoint = null;
int width, height;
int moveX, moveY;
boolean isUp = false;
Context ctx;
StringBuffer lockString = new StringBuffer();
public MmsLockSetPwd(Context context) {
super(context);
ctx = context;
// this.setBackgroundColor(Color.WHITE);
initPaint();
}
public MmsLockSetPwd(Context context, AttributeSet attrs) {
super(context, attrs);
// this.setBackgroundColor(Color.WHITE);
tv_forget_pwd.setVisibility(View.GONE); //zj add
initPaint();
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
width = getWidth();
height = getHeight();
if (width != 0 && height != 0) {
initPoints(points);
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
@Override
protected void onLayout(boolean changed, int left, int top, int right,
int bottom) {
super.onLayout(changed, left, top, right, bottom);
}
private int startX = 0, startY = 0;
@Override
protected void onDraw(Canvas canvas) {
// canvas.drawText(“passwd:” + lockString, 0, 40, textPaint);
if (moveX != 0 && moveY != 0 && startX != 0 && startY != 0) {
// drawLine(canvas, startX, startY, moveX, moveY);
}
drawNinePoint(canvas);
super.onDraw(canvas);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
boolean flag = true;
if (isUp) {
finishDraw();
flag = false;
} else {
handlingEvent(event);
flag = true;
}
return flag;
}
private void handlingEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_MOVE:
moveX = (int) event.getX();
moveY = (int) event.getY();
for (PointInfo temp : points) {
if (temp.isInMyPlace(moveX, moveY)
&& temp.isSelected() == false) {
temp.setSelected(true);
startX = temp.getCenterX();
startY = temp.getCenterY();
int len = lockString.length();
if (len != 0) {
int preId = lockString.charAt(len - 1) - 48;
points[preId].setNextId(temp.getId());
}
lockString.append(temp.getId());
break;
}
}
invalidate(0, height - width, width, height);
break;
case MotionEvent.ACTION_DOWN:
int downX = (int) event.getX();
int downY = (int) event.getY();
for (PointInfo temp : points) {
if (temp.isInMyPlace(downX, downY)) {
temp.setSelected(true);
startPoint = temp;
startX = temp.getCenterX();
startY = temp.getCenterY();
lockString.append(temp.getId());
break;
}
}
invalidate(0, height - width, width, height);
break;
case MotionEvent.ACTION_UP:
startX = startY = moveX = moveY = 0;
isUp = true;
invalidate();
savePwd();
break;
default:
break;
}
}
private void finishDraw() {
for (PointInfo temp : points) {
temp.setSelected(false);
temp.setNextId(temp.getId());
}
lockString.delete(0, lockString.length());
isUp = false;
invalidate();
}
private void initPoints(PointInfo[] points) {
int len = points.length;
int seletedSpacing = (width - selectedBitmapDiameter * 3) / 4;
int seletedX = seletedSpacing;
int seletedY = height - width + seletedSpacing;
int defaultX = seletedX + selectedBitmapRadius - defaultBitmapRadius;
int defaultY = seletedY + selectedBitmapRadius - defaultBitmapRadius;
for (int i = 0; i < len; i++) {
if (i == 3 || i == 6) {
seletedX = seletedSpacing;
seletedY += selectedBitmapDiameter + seletedSpacing;
defaultX = seletedX + selectedBitmapRadius
- defaultBitmapRadius;
defaultY += selectedBitmapDiameter + seletedSpacing;
}
points[i] = new PointInfo(i, defaultX, defaultY, seletedX, seletedY);
seletedX += selectedBitmapDiameter + seletedSpacing;
defaultX += selectedBitmapDiameter + seletedSpacing;
}
}
private void initPaint() {
initLinePaint(linePaint);
initTextPaint(textPaint);
initWhiteLinePaint(whiteLinePaint);
}
/**
- @param paint
*/
private void initTextPaint(Paint paint) {
textPaint.setTextSize(30);
textPaint.setAntiAlias(true);
textPaint.setTypeface(Typeface.MONOSPACE);
}
/**
- @param paint
*/
private void initLinePaint(Paint paint) {
//paint.setColor(Color.GRAY);
paint.setColor(Color.parseColor(“#1E90FF”));
//paint.setStyle(Style.STROKE);
paint.setStyle(Style.FILL);
paint.setStrokeWidth(10);
paint.setAntiAlias(true);
paint.setStrokeCap(Cap.ROUND);
}
/**
- @param paint
*/
private void initWhiteLinePaint(Paint paint) {
//paint.setColor(Color.WHITE);
paint.setColor(Color.parseColor(“#1E90FF”));
paint.setStrokeWidth(8);
paint.setAntiAlias(true);
paint.setStrokeCap(Cap.ROUND);
}
/**
-
@param canvas
*/
private void drawNinePoint(Canvas canvas) {
if (startPoint != null) {
drawEachLine(canvas, startPoint);
}
for (PointInfo pointInfo : points) {
if (pointInfo != null) {
if (pointInfo.isSelected()) {
canvas.drawBitmap(selectedBitmap, pointInfo.getSeletedX(),
pointInfo.getSeletedY(), null);
}else{ // zj add
canvas.drawBitmap(defaultBitmap, pointInfo.getDefaultX(),
pointInfo.getDefaultY(), null);
}
}
}
}
/**
-
@param canvas
-
@param point
*/
private void drawEachLine(Canvas canvas, PointInfo point) {
if (point.hasNextId()) {
int n = point.getNextId();
drawLine(canvas, point.getCenterX(), point.getCenterY(),
points[n].getCenterX(), points[n].getCenterY());
drawEachLine(canvas, points[n]);
}
}
/**
-
@param canvas
-
@param startX
-
@param startY
-
@param stopX
-
@param stopY
*/
private void drawLine(Canvas canvas, float startX, float startY,
float stopX, float stopY) {
canvas.drawLine(startX, startY, stopX, stopY, linePaint);
canvas.drawLine(startX, startY, stopX, stopY, whiteLinePaint);
}
/**
-
@author zkwlx
*/
private class PointInfo {
private int id;
private int nextId;
private boolean selected;
private int defaultX;
private int defaultY;
private int seletedX;
private int seletedY;
public PointInfo(int id, int defaultX, int defaultY, int seletedX,
int seletedY) {
this.id = id;
this.nextId = id;
this.defaultX = defaultX;
this.defaultY = defaultY;
this.seletedX = seletedX;
this.seletedY = seletedY;
}
public boolean isSelected() {
return selected;
}
public void setSelected(boolean selected) {
this.selected = selected;
}
public int getId() {
return id;
}
public int getDefaultX() {
return defaultX;
}
public int getDefaultY() {
return defaultY;
}
public int getSeletedX() {
return seletedX;
}
public int getSeletedY() {
return seletedY;
}
public int getCenterX() {
return seletedX + selectedBitmapRadius;
}
public int getCenterY() {
return seletedY + selectedBitmapRadius;
}
public boolean hasNextId() {
return nextId != id;
}
public int getNextId() {
return nextId;
}
public void setNextId(int nextId) {
this.nextId = nextId;
}
/**
-
@param x
-
@param y
*/
public boolean isInMyPlace(int x, int y) {
boolean inX = x > seletedX
&& x < (seletedX + selectedBitmapDiameter);
boolean inY = y > seletedY
&& y < (seletedY + selectedBitmapDiameter);
return (inX && inY);
}
}
public String getPwd() {
return lockString.toString();
}
public void savePwd() {
Intent intent = new Intent();
SharedPreferences shareDate = ctx.getSharedPreferences(“GUE_PWD”, 0);
boolean isSetFirst = shareDate.getBoolean(“IS_SET_FIRST”, false);
if (isSetFirst) {
String pwd = this.getPwd();
String first_pwd = shareDate.getString(“FIRST_PWD”, “HAVE NO PWD”);
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级安卓工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年最新Android移动开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Android)
文末
当你打算跳槽的时候,应该把“跳槽成功后,我能学到什么东西?对我的未来发展有什么好处”放在第一位。这些东西才是真正引导你的关键。在跳槽之前尽量“物尽其用”,把手头上的工作做好,最好是完成了某个项目或是得到提升之后再走。跳槽不是目的,而是为了达到最终职业目标的手段
最后祝大家工作升职加薪,面试拿到心仪Offer.
为此我在文末整理了一些关于移动开发者需要的资料,欢迎大家免费领取
领取方式:点击我的GitHub
private boolean selected;
private int defaultX;
private int defaultY;
private int seletedX;
private int seletedY;
public PointInfo(int id, int defaultX, int defaultY, int seletedX,
int seletedY) {
this.id = id;
this.nextId = id;
this.defaultX = defaultX;
this.defaultY = defaultY;
this.seletedX = seletedX;
this.seletedY = seletedY;
}
public boolean isSelected() {
return selected;
}
public void setSelected(boolean selected) {
this.selected = selected;
}
public int getId() {
return id;
}
public int getDefaultX() {
return defaultX;
}
public int getDefaultY() {
return defaultY;
}
public int getSeletedX() {
return seletedX;
}
public int getSeletedY() {
return seletedY;
}
public int getCenterX() {
return seletedX + selectedBitmapRadius;
}
public int getCenterY() {
return seletedY + selectedBitmapRadius;
}
public boolean hasNextId() {
return nextId != id;
}
public int getNextId() {
return nextId;
}
public void setNextId(int nextId) {
this.nextId = nextId;
}
/**
-
@param x
-
@param y
*/
public boolean isInMyPlace(int x, int y) {
boolean inX = x > seletedX
&& x < (seletedX + selectedBitmapDiameter);
boolean inY = y > seletedY
&& y < (seletedY + selectedBitmapDiameter);
return (inX && inY);
}
}
public String getPwd() {
return lockString.toString();
}
public void savePwd() {
Intent intent = new Intent();
SharedPreferences shareDate = ctx.getSharedPreferences(“GUE_PWD”, 0);
boolean isSetFirst = shareDate.getBoolean(“IS_SET_FIRST”, false);
if (isSetFirst) {
String pwd = this.getPwd();
String first_pwd = shareDate.getString(“FIRST_PWD”, “HAVE NO PWD”);
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级安卓工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年最新Android移动开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
[外链图片转存中…(img-YWvevT4d-1711136944088)]
[外链图片转存中…(img-zyT8vGxa-1711136944089)]
[外链图片转存中…(img-8oVYjwya-1711136944089)]
[外链图片转存中…(img-VxOuVsDa-1711136944089)]
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Android)
[外链图片转存中…(img-kzKh1aV6-1711136944090)]
文末
当你打算跳槽的时候,应该把“跳槽成功后,我能学到什么东西?对我的未来发展有什么好处”放在第一位。这些东西才是真正引导你的关键。在跳槽之前尽量“物尽其用”,把手头上的工作做好,最好是完成了某个项目或是得到提升之后再走。跳槽不是目的,而是为了达到最终职业目标的手段
最后祝大家工作升职加薪,面试拿到心仪Offer.
为此我在文末整理了一些关于移动开发者需要的资料,欢迎大家免费领取
领取方式:点击我的GitHub
[外链图片转存中…(img-o6XsDTk7-1711136944090)]
[外链图片转存中…(img-BQLOGPjw-1711136944091)]