怎么在Android應用中實現一個圖案解鎖功能-創新互聯

這期內容當中小編將會給大家帶來有關怎么在Android應用中實現一個圖案解鎖功能,文章內容豐富且以專業的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

我們提供的服務有:網站設計、網站建設、微信公眾號開發、網站優化、網站認證、雙峰ssl等。為近1000家企事業單位解決了網站和推廣的問題。提供周到的售前咨詢和貼心的售后服務,是有科學管理、有技術的雙峰網站制作公司

1.最關健的就是那個自定義九宮格View,代碼來自framework下:LockPatternView,原生系統用的圖片資源比較多,好像有7、8張吧,而且繪制的比較復雜,我找尋半天,眼睛都找瞎了,發現解壓的QQ里面就3張圖片,一個圈圈,兩個點,沒辦法,只能修改代碼了,在修改的過程中,才發現,其實可以把原生的LockPatternView給簡化,繪制更少的圖片,達到更好的效果??偣矁灮校孩偃サ袅诉B線的箭頭,②原生的連線只有白色一種,改成根據不同狀態顯示黃色和紅色兩張色,③.原生view是先畫點再畫線,使得線覆蓋在點的上面,影響美觀,改成先畫連線再畫點。

關健部分代碼onDraw函數:

@Override 
protected void onDraw(Canvas canvas) { 
 final ArrayList<Cell> pattern = mPattern; 
 final int count = pattern.size(); 
 final boolean[][] drawLookup = mPatternDrawLookup; 
 
 if (mPatternDisplayMode == DisplayMode.Animate) { 
 
 // figure out which circles to draw 
 
 // + 1 so we pause on complete pattern 
 final int oneCycle = (count + 1) * MILLIS_PER_CIRCLE_ANIMATING; 
 final int spotInCycle = (int) (SystemClock.elapsedRealtime() - mAnimatingPeriodStart) 
 % oneCycle; 
 final int numCircles = spotInCycle / MILLIS_PER_CIRCLE_ANIMATING; 
 
 clearPatternDrawLookup(); 
 for (int i = 0; i < numCircles; i++) { 
 final Cell cell = pattern.get(i); 
 drawLookup[cell.getRow()][cell.getColumn()] = true; 
 } 
 
 // figure out in progress portion of ghosting line 
 
 final boolean needToUpdateInProgressPoint = numCircles > 0 
 && numCircles < count; 
 
 if (needToUpdateInProgressPoint) { 
 final float percentageOfNextCircle = ((float) (spotInCycle % MILLIS_PER_CIRCLE_ANIMATING)) 
  / MILLIS_PER_CIRCLE_ANIMATING; 
 
 final Cell currentCell = pattern.get(numCircles - 1); 
 final float centerX = getCenterXForColumn(currentCell.column); 
 final float centerY = getCenterYForRow(currentCell.row); 
 
 final Cell nextCell = pattern.get(numCircles); 
 final float dx = percentageOfNextCircle 
  * (getCenterXForColumn(nextCell.column) - centerX); 
 final float dy = percentageOfNextCircle 
  * (getCenterYForRow(nextCell.row) - centerY); 
 mInProgressX = centerX + dx; 
 mInProgressY = centerY + dy; 
 } 
 // TODO: Infinite loop here... 
 invalidate(); 
 } 
 
 final float squareWidth = mSquareWidth; 
 final float squareHeight = mSquareHeight; 
 
 float radius = (squareWidth * mDiameterFactor * 0.5f); 
 mPathPaint.setStrokeWidth(radius); 
 
 final Path currentPath = mCurrentPath; 
 currentPath.rewind(); 
 
 // TODO: the path should be created and cached every time we hit-detect 
 // a cell 
 // only the last segment of the path should be computed here 
 // draw the path of the pattern (unless the user is in progress, and 
 // we are in stealth mode) 
 final boolean drawPath = (!mInStealthMode || mPatternDisplayMode == DisplayMode.Wrong); 
 
 // draw the arrows associated with the path (unless the user is in 
 // progress, and 
 // we are in stealth mode) 
 boolean oldFlag = (mPaint.getFlags() & Paint.FILTER_BITMAP_FLAG) != 0; 
 mPaint.setFilterBitmap(true); // draw with higher quality since we 
   // render with transforms 
 // draw the lines 
 if (drawPath) { 
 boolean anyCircles = false; 
 for (int i = 0; i < count; i++) { 
 Cell cell = pattern.get(i); 
 
 // only draw the part of the pattern stored in 
 // the lookup table (this is only different in the case 
 // of animation). 
 if (!drawLookup[cell.row][cell.column]) { 
 break; 
 } 
 anyCircles = true; 
 
 float centerX = getCenterXForColumn(cell.column); 
 float centerY = getCenterYForRow(cell.row); 
 if (i == 0) { 
 currentPath.moveTo(centerX, centerY); 
 } else { 
 currentPath.lineTo(centerX, centerY); 
 } 
 } 
 
 // add last in progress section 
 if ((mPatternInProgress || mPatternDisplayMode == DisplayMode.Animate) 
 && anyCircles) { 
 currentPath.lineTo(mInProgressX, mInProgressY); 
 } 
 // chang the line color in different DisplayMode 
 if (mPatternDisplayMode == DisplayMode.Wrong) 
 mPathPaint.setColor(Color.RED); 
 else 
 mPathPaint.setColor(Color.YELLOW); 
 canvas.drawPath(currentPath, mPathPaint); 
 } 
 
 // draw the circles 
 final int paddingTop = getPaddingTop(); 
 final int paddingLeft = getPaddingLeft(); 
 
 for (int i = 0; i < 3; i++) { 
 float topY = paddingTop + i * squareHeight; 
 // float centerY = mPaddingTop + i * mSquareHeight + (mSquareHeight 
 // / 2); 
 for (int j = 0; j < 3; j++) { 
 float leftX = paddingLeft + j * squareWidth; 
 drawCircle(canvas, (int) leftX, (int) topY, drawLookup[i][j]); 
 } 
 } 
 
 mPaint.setFilterBitmap(oldFlag); // restore default flag 
} 

文章名稱:怎么在Android應用中實現一個圖案解鎖功能-創新互聯
標題來源:http://m.kartarina.com/article36/diccpg.html

成都網站建設公司_創新互聯,為您提供手機網站建設、做網站、Google、建站公司標簽優化小程序開發

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

成都網站建設公司
主站蜘蛛池模板: 亚洲aⅴ无码专区在线观看| 精品无码中文视频在线观看| 精品一区二区三区无码视频| 无码专区国产无套粉嫩白浆内射| 久久午夜无码鲁丝片午夜精品| 国产亚洲精久久久久久无码AV| 亚洲Av无码一区二区二三区| 亚洲国产综合无码一区二区二三区| 久久无码无码久久综合综合 | 精品久久久久久久无码久中文字幕| 国产精品亚洲专区无码唯爱网| 一本一道av中文字幕无码| 久久人午夜亚洲精品无码区| 中文字幕丰满伦子无码| 毛片亚洲AV无码精品国产午夜| 精品人妻系列无码一区二区三区| 亚洲精品无码日韩国产不卡?V| 亚洲AV成人无码久久WWW| 色窝窝无码一区二区三区色欲| 中文字幕无码精品亚洲资源网| 国产精品无码翘臀在线观看| 亚洲av无码专区在线| 无码国产精品一区二区免费模式 | 亚洲精品中文字幕无码蜜桃| 无码不卡中文字幕av| 亚州AV综合色区无码一区| 无码av免费网站| 久久精品中文字幕无码| 亚洲中文字幕无码久久综合网| 韩国免费a级作爱片无码| 色欲香天天综合网无码| 国产精品亚洲专区无码唯爱网| 无码中文字幕一区二区三区| 中文字幕人成无码免费视频| AV无码久久久久不卡网站下载| AV无码精品一区二区三区| 蜜桃无码一区二区三区| 亚洲精品无码国产片| 亚洲日韩av无码中文| 色综合色国产热无码一| 永久免费无码网站在线观看|