標籤: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;}
2.在LockPatternView中設定手勢密碼預設、正確和錯誤的顯示圖片,其實那個圈圈的大小是根據你的圖片的大小變化的
注意: 這裡的三個圖片的大小是一樣的
畫手勢的預設圖片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);
4.判斷有沒有手勢密碼
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的哪裡就可以了
6.手勢密碼頂部記錄區,這裡的小圓圈是可以在這裡設定大小和間距的,這裡是比較麻煩的地區,需要你非常的細心設定。
注意: 這裡的背景切圖一定要做好,要美工給你標出大小和間距,
<LinearLayoutandroid: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>
7.
至於底部按鈕、提示文字、背景顏色等都是很容易解決的
積累一些吧,就算你不是很懂這裡的代碼,你也可以做你的手勢密碼。
源碼下載:http://download.csdn.net/detail/pcaxb/8747015
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。
Android手勢密碼LockPatternView、LockPasswordUtils、LockPatternUtils等分析