标签:android手势密码 lockpatternview lockpasswordutils lockpatternutils 手机密码分析
Android手势密码LockPatternView、LockPasswordUtils、LockPatternUtils
在使用别人写的这个手势密码的时候,我们通常是有自己的需求,可能这里的代码很多也很复杂,有没有什么很多注释,要把整个代码弄明白是要花很多时间而且基础要非常好的,可能在赶项目的时候没有时间去研究,下面我列出一些关键的地方,方便修改代码。
1.在创建手势密码的时候CreateGesturePasswordActivity中
下面是手势密码设置的时候界面的一些变化,和要处理的一些事情
switch (mUiStage) {
case Introduction:
//刚进去的时候 // 重试的时候
mLockPatternView.clearPattern();
break;
case HelpScreen:
//刚进去的时候
mLockPatternView.setPattern(DisplayMode.Animate, mAnimatePattern);
break;
case ChoiceTooShort:
//设置短了松开
mLockPatternView.setDisplayMode(DisplayMode.Wrong);
postClearPatternRunnable();
break;
case FirstChoiceValid:
//设置对了松开
break;
case NeedToConfirm:
//点击继续
mLockPatternView.clearPattern();
updatePreviewViews();
break;
case ConfirmWrong:
//第二次和第一次的不一样
mLockPatternView.setDisplayMode(DisplayMode.Wrong);
postClearPatternRunnable();
break;
case ChoiceConfirmed:
//第二次和第一次的一样
break;
}注意: 这里的三个图片的大小是一样的
画手势的默认图片 mBitmapCircleDefault = getBitmapFor(R.drawable.gesture_pattern_item_bg); 画手势正确的图片 mBitmapCircleGreen = getBitmapFor(R.drawable.gesture_pattern_selected); 画手势错误的图片 mBitmapCircleRed = getBitmapFor(R.drawable.gesture_pattern_selected_wrong);
3.在LockPatternView中设置手势密码连接线的颜色红色和黄色
这里的颜色你可能要改变多个地方的颜色
设置黄色 mPathPaint.setColor(Color.RED); 设置红色 mPathPaint.setColor(Color.YELLOW);
if (App.getInstance().getLockPatternUtils().savedPatternExists()) {
//如果这里是true就是有手势密码,false就是没有手势密码
}5.清除手势密码重新创建
String LOCK_PATTERN_FILE = "gesture.key";
String dataSystemDirectory = context.getFilesDir() .getAbsolutePath();
File file = new File(dataSystemDirectory , LOCK_PATTERN_FILE);
if (file.isFile()) { file.delete(); }
然后跳转到UnlockGesturePasswordActivity.class不到CreateGesturePasswordActivity.java的哪里就可以了 注意: 这里的背景切图一定要做好,要美工给你标出大小和间距,
<LinearLayout
android:id="@+id/gesturepwd_setting_preview"
android:layout_width="40.0dip"
android:layout_height="40.0dip"
android:layout_gravity="center_horizontal"
android:background="@drawable/gesture_create_grid_bg"
android:orientation="vertical"
android:padding="5.0dip" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="6.0dip" >
<View
android:id="@+id/gesturepwd_setting_preview_0"
android:layout_width="6.0dip"
android:layout_height="6.0dip"
android:background="@drawable/trans" />
<View
android:id="@+id/gesturepwd_setting_preview_1"
android:layout_width="6.0dip"
android:layout_height="6.0dip"
android:layout_marginLeft="6.0dip"
android:background="@drawable/trans" />
<View
android:id="@+id/gesturepwd_setting_preview_2"
android:layout_width="6.0dip"
android:layout_height="6.0dip"
android:layout_marginLeft="6.0dip"
android:background="@drawable/trans" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="6.0dip"
android:layout_marginTop="6.0dip" >
<View
android:id="@+id/gesturepwd_setting_preview_3"
android:layout_width="6.0dip"
android:layout_height="6.0dip"
android:background="@drawable/trans" />
<View
android:id="@+id/gesturepwd_setting_preview_4"
android:layout_width="6.0dip"
android:layout_height="6.0dip"
android:layout_marginLeft="6.0dip"
android:background="@drawable/trans" />
<View
android:id="@+id/gesturepwd_setting_preview_5"
android:layout_width="6.0dip"
android:layout_height="6.0dip"
android:layout_marginLeft="6.0dip"
android:background="@drawable/trans" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="6.0dip"
android:layout_marginTop="6.0dip" >
<View
android:id="@+id/gesturepwd_setting_preview_6"
android:layout_width="6.0dip"
android:layout_height="6.0dip"
android:background="@drawable/trans" />
<View
android:id="@+id/gesturepwd_setting_preview_7"
android:layout_width="6.0dip"
android:layout_height="6.0dip"
android:layout_marginLeft="6.0dip"
android:background="@drawable/trans" />
<View
android:id="@+id/gesturepwd_setting_preview_8"
android:layout_width="6.0dip"
android:layout_height="6.0dip"
android:layout_marginLeft="6.0dip"
android:background="@drawable/trans" />
</LinearLayout>
</LinearLayout>
至于底部按钮、提示文字、背景颜色等都是很容易解决的
积累一些吧,就算你不是很懂这里的代码,你也可以做你的手势密码。
版权声明:本文为博主原创文章,未经博主允许不得转载。
Android手势密码LockPatternView、LockPasswordUtils、LockPatternUtils等分析
标签:android手势密码 lockpatternview lockpasswordutils lockpatternutils 手机密码分析
原文地址:http://blog.csdn.net/pcaxb/article/details/47375323