日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

【Android Lock Pattern】图案解锁(一):LockPatternView源代码

發布時間:2025/6/17 Android 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【Android Lock Pattern】图案解锁(一):LockPatternView源代码 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

選擇Settings -> Security ->Set up screen lock

設置屏幕鎖

選擇Pattern

設置圖案

在我的真機HTC Desire(Android 2.2)上,截圖如下:

Android是一個開源的操作系統,所以我們可以通過下載該控件的源代碼重用該控件。

?

1、LockPatterView源代碼

圖案解鎖控件,對應著framework層的LockPatterView類,如下所示:

源代碼:https://github.com/android/platform_frameworks_base/blob/master/core/java/com/android/internal/widget/LockPatternView.java

?

2、修改

下載的LockPatternView.java文件,無法在項目中直接使用,需要進行修改。

1)添加圖片文件

添加6張圖片文件到res/drawable:

對應LockPatternView.java的代碼

mBitmapBtnDefault = getBitmapFor(R.drawable.btn_code_lock_default_holo); mBitmapBtnTouched = getBitmapFor(R.drawable.btn_code_lock_touched_holo); mBitmapCircleDefault = getBitmapFor(R.drawable.indicator_code_lock_point_area_default_holo); mBitmapCircleGreen = getBitmapFor(R.drawable.indicator_code_lock_point_area_green_holo); mBitmapCircleRed = getBitmapFor(R.drawable.indicator_code_lock_point_area_red_holo);mBitmapArrowGreenUp = getBitmapFor(R.drawable.indicator_code_lock_drag_direction_green_up); mBitmapArrowRedUp = getBitmapFor(R.drawable.indicator_code_lock_drag_direction_red_up);

btn_code_lock_default_holo.png

btn_code_lock_touched_holo.png

indicator_code_lock_point_area_default_holo.png

indicator_code_lock_point_area_green_holo.png

indicator_code_lock_point_area_red_holo.png

indicator_code_lock_drag_direction_green_up.png

indicator_code_lock_drag_direction_red_up.png

?

2)添加attrs配置文件

添加attrs.xml文件到res/values

<?xml version="1.0" encoding="utf-8"?> <resources><declare-styleable name="LockPatternView"><attr name="aspect" format="string" /></declare-styleable> </resources>

?

3)更新strings配置文件

在res/strings.xml添加新的<string/>

<!-- Accessibility description sent when user starts drawing a lock pattern. --> <string name="lockscreen_access_pattern_start">Pattern started</string> <!-- Accessibility description sent when the pattern times out and is cleared. --> <string name="lockscreen_access_pattern_cleared">Pattern cleared</string> <!-- Accessibility description sent when user adds a cell to the pattern. --> <string name="lockscreen_access_pattern_cell_added">Cell added</string> <!-- Accessibility description sent when user completes drawing a pattern. --> <string name="lockscreen_access_pattern_detected">Pattern completed</string>

?

4)修改代碼

修改mPaddingLeft為getPaddingLeft(),mPaddingRight為getPaddingRight(),mPaddingTop為getPaddingTop(),mPaddingBottom為getPaddingBottom()

修改mContext為getContext()

修改方法private void sendAccessEvent(int resId)

private void sendAccessEvent(int resId) {setContentDescription(getContext().getString(resId));sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);setContentDescription(null); }

?

5)添加類LockPatternUtils

新建LockPatternUtils.java文件,實現public static String patternToString(List<LockPatternView.Cell> pattern)和public static List<LockPatternView.Cell> stringToPattern(String string)方法

具體可以參考Android的LockPatternUtils類

源代碼:https://github.com/android/platform_frameworks_base/blob/master/core/java/com/android/internal/widget/LockPatternUtils.java

?

3、使用

LockPatternView的使用與其它View相同,并提供了事件的回調處理的方法public void setOnPatternListener(OnPatternListener onPatternListener)和接口LockPatternView.OnPatternListener

?

參考:http://www.eoeandroid.com/forum.php?mod=viewthread&tid=231102

?

?

轉載于:https://www.cnblogs.com/dyingbleed/archive/2012/12/03/2800007.html

總結

以上是生活随笔為你收集整理的【Android Lock Pattern】图案解锁(一):LockPatternView源代码的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。