PointView.java
package com.jackie.lockpattern; import android.graphics.Point; /** * Created by Jackie on 2015/12/25. * 自定义点对象 */ public class PointView extends Point { //用于转化密码的下标 public int index; public PointView(int x, int y) { super(x, y); } public int getIndex() { return index; } public void setIndex(int index) { this.index = index; } }MainActivity.java
package com.jackie.lockpattern; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class MainActivity extends Activity implements LockPatternView.OnPatternChangeListener { private TextView mLockPatternHint; private LockPatternView mLockPatternView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mLockPatternHint = (TextView) findViewById(R.id.lock_pattern_hint); mLockPatternView = (LockPatternView) findViewById(R.id.lock_pattern_view); mLockPatternView.setOnPatternChangeListener(this); } @Override public void onPatternChange(String patternPassword) { if (patternPassword == null) { mLockPatternHint.setText("至少5个点"); } else { mLockPatternHint.setText(patternPassword); } } @Override public void onPatternStarted(boolean isStarted) { if (isStarted) { mLockPatternHint.setText("请绘制图案"); } } }效果图如下:
附上源码地址:https://github.com/shineflower/LockPattern.git
以上就是Android实现九宫格图案解锁功能的全部内容,希望对大家的学习有所帮助,也希望大家多多支持五二脚本。