注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

沉默蜂B4A安卓编程

国内资料最全的B4A资料库

 
 
 

日志

 
 

[例程]手势密码  

2015-09-04 18:01:18|  分类: B4A例程 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
[例程]手势密码 - 沉默蜂 - 沉默蜂B4A安卓编程实战资料
 


这是某人编写的例程,很不错,于是发到博客上,所需 库 rsimageprocessing

#Region  Project Attributes 
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName: 
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes 
#FullScreen: False
#IncludeTitle: False
#End Region

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim timerTmp As Timer
End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.

' Dim IV1,IV2,IV3,IV4,IV5,IV6,IV7,IV8,IV9 As ImageView
Dim Pnl_PLBG As Panel
Type TPosXY(x As Int,y As Int)
Dim Pnl_PLTop As Panel
Dim cvs,cvs1 As Canvas
Dim itemW,itemWHalf As Int
Dim XY(9) As TPosXY
Dim ls As List
Dim srcX,srcY As Int
Dim Pnl_smallLock As Panel
Dim smallIV(9),IV(9) As ImageView
Dim isHidePath As Boolean
Dim lockPointWhite,lockPointBlue As Bitmap
End Sub

Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
timerTmp.Initialize("timerTmp",1000)
Activity.LoadLayout("L1")

lockPointWhite.Initialize(File.DirAssets,"eqe.png")
lockPointBlue.Initialize(File.DirAssets,"eqd.png")
' Pnl_PLBG.Left= (100%x-Pnl_PLBG.Width)/2
' Pnl_smallLock.Left= (100%x-Pnl_smallLock.Width)/2
initLockPic
cvs.Initialize(Pnl_PLTop)
cvs1.Initialize(Pnl_PLBG)

ls.Initialize
createSmallLock
isHidePath= False
' Dim bmp1,bmp2 As Bitmap
' bmp1.Initialize(File.DirAssets,"lock_pattern_point_area_default.png")
' bmp2= myFunction.CreateScaledBitmap(bmp1,IV(1).Width,IV(1).Height)
' ImageToFile(bmp1,File.Combine(File.DirRootExternal,"bmp1.png"))
' ImageToFile(bmp2,File.Combine(File.DirRootExternal,"bmp2.png"))
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub



Sub Pnl_PLTop_Touch (Action As Int, X As Float, Y As Float)
If Pnl_PLBG.Enabled=False Then Return
Dim i,color As Int
If isHidePath Then
color= Colors.Transparent
Else
color= Colors.ARGB(200,255,255,255)
End If
Select Action
Case 0 ' DOWN 
i= isInPoint(X,Y)
If i<>-1 Then
If ls.IndexOf(i)=-1 Then
srcX= XY(i).X
srcY= XY(i).Y
cvs.DrawLine(X,Y,X,Y,color,8dip)
Pnl_PLTop.Invalidate
setIVStyle(i,1)
ls.Add(i)
End If
End If
Case 1 'up
cvs.DrawColor(Colors.Transparent)
Pnl_PLTop.Invalidate
Pnl_PLBG.Enabled= False
If ls.Size=0 Then Return
If ls.Size<3 Then
For i=0 To ls.Size-1 
setIVStyle(ls.Get(i),2)
Next
dawRedLine
ToastMessageShow("密码太短,请连接至少3个点",True)
Else
' For i=0 To ls.Size-1 
' setIVStyle(ls.Get(i),2)
' Next
ToastMessageShow("请确认密码",True)
End If
dawRedLine
setSmallIVStyle
timerTmp.Enabled= True
Case 2 'move
If (isInPoint(srcX,srcY)=-1) Then 
i= isInPoint(X,Y)
If i=-1 Then
Return
Else
srcX=XY(i).X
srcY=XY(i).Y
End If
End If
cvs.DrawColor(Colors.Transparent)
cvs.DrawLine(srcX,srcY,X,Y,color,8dip)
Pnl_PLTop.Invalidate
i= isInPoint(X,Y)
If i<>-1 Then
If ls.IndexOf(i)=-1 Then
cvs1.DrawLine(srcX,srcY,XY(i).X,XY(i).Y,color,8dip)
Pnl_PLBG.Invalidate
srcX= XY(i).X
srcY= XY(i).Y
cvs.DrawLine(srcX,srcY,X,Y,color,8dip)
Pnl_PLTop.Invalidate
setIVStyle(i,1)
ls.Add(i)
End If
End If
End Select
End Sub

Sub isInPoint(x As Int,y As Int)As Int
Dim i As Int
Dim xb,yb As Boolean
For i=0 To XY.Length-1
xb= False
yb= False
If (x>=XY(i).x-itemWHalf)AND(x<=XY(i).x+itemWHalf) Then xb= True
If (y>=XY(i).y-itemWHalf)AND(y<=XY(i).y+itemWHalf) Then yb= True
If xb AND yb Then Exit
Next
If i>= XY.Length Then
Return -1
Else
Return i
End If
End Sub

Sub setIVStyle(index As Int,style As Int)
If isHidePath Then Return
drawLockPattern(IV(index),style)
End Sub

Sub drawLockPattern(v As View,style As Int)
Dim c As Canvas
Dim r As Rect
Dim bmp As Bitmap
c.Initialize(v)
c.DrawColor(Colors.Transparent)
Select style
Case 0'默认状态
bmp.Initialize(File.DirAssets,"lock_pattern_point_area_default.png")
bmp=myFunction.CreateScaledBitmap(bmp,v.Width,v.Height)
r.Initialize(0,0,v.Width,v.Height)
c.DrawBitmap(bmp,r,r)
myFunction.recycleBMP(bmp)
bmp.Initialize(File.DirAssets,"lock_pattern_btn_derault.png")
bmp= myFunction.CreateScaledBitmap(bmp,v.Width,v.Height)
c.DrawBitmap(bmp,r,r)
myFunction.recycleBMP(bmp)
Case 1'选中状态
bmp.Initialize(File.DirAssets,"lock_pattern_point_area_green.png")
bmp=myFunction.CreateScaledBitmap(bmp,v.Width,v.Height)
r.Initialize(0,0,v.Width,v.Height)
c.DrawBitmap(bmp,r,r)
myFunction.recycleBMP(bmp)
bmp.Initialize(File.DirAssets,"lock_pattern_btn_touch.png")
bmp=myFunction.CreateScaledBitmap(bmp,v.Width,v.Height)
c.DrawBitmap(bmp,r,r)
myFunction.recycleBMP(bmp)
' Case 2'密码正确状态
' bmp.Initialize(File.DirAssets,"lock_pattern_point_area_green.png")
' sr.Initialize(0,0,bmp.Width,bmp.Height)
' dr.Initialize(0,0,v.Width,v.Height)
' c.DrawBitmap(bmp,sr,dr)
' recycleBMP(bmp)
' bmp.Initialize(File.DirAssets,"lock_pattern_btn_touch.png")
' sr.Initialize(0,0,bmp.Width,bmp.Height)
' dr.Initialize(0,0,v.Width,v.Height)
' c.DrawBitmap(bmp,sr,dr)
' recycleBMP(bmp)
Case 2'密码错误状态
bmp.Initialize(File.DirAssets,"lock_pattern_point_area_red.png")
bmp=myFunction.CreateScaledBitmap(bmp,v.Width,v.Height)
r.Initialize(0,0,v.Width,v.Height)
c.DrawBitmap(bmp,r,r)
myFunction.recycleBMP(bmp)
bmp.Initialize(File.DirAssets,"lock_pattern_btn_touch.png")
bmp=myFunction.CreateScaledBitmap(bmp,v.Width,v.Height)
c.DrawBitmap(bmp,r,r)
myFunction.recycleBMP(bmp)
End Select
End Sub

Sub timerTmp_Tick
timerTmp.Enabled= False
clearSamllIVStyle
For i=0 To ls.Size-1 
setIVStyle(ls.Get(i),0)
' setSmallIVStyle(ls.Get(i))
Next
cvs.DrawColor(Colors.Transparent)
cvs1.DrawColor(Colors.RGB(192,192,192))
Pnl_PLBG.Invalidate
ls.clear
srcX=0
srcY=0
Pnl_PLBG.Enabled= True
End Sub

Sub createSmallLock
Dim iw As Int
Dim space,i,l,t,m,r As Int
Dim bmp As Bitmap
space=Pnl_smallLock.Width*0.1
iw= (Pnl_smallLock.Width-4*space)/3
r=0
bmp= LoadBitmap(File.DirAssets,"eqe.png")
For i=0 To smallIV.Length-1
m= i Mod 3
l= (m+1)*space+ m*iw 
If m=0 Then
r=r+1
t= r*space+(r-1)*iw
End If
smallIV(i).Initialize("")
Pnl_smallLock.AddView(smallIV(i),l,t,iw,iw)
smallIV(i).Gravity= Gravity.FILL
smallIV(i).Bitmap= bmp
Next
End Sub

Sub setSmallIVStyle
Dim i As Int
For i=0 To ls.Size-1
smallIV(ls.Get(i)).Bitmap= lockPointBlue
Next
End Sub

Sub clearSamllIVStyle
Dim i As Int
For i=0 To smallIV.Length-1
smallIV(i).Bitmap = lockPointWhite
Next
End Sub

Sub initLockPic
Dim i,l,t,m,r As Int
Dim space As Int'=20dip
space=Pnl_PLBG.Width*0.1
itemW= (Pnl_PLBG.Width-4*space)/3
itemWHalf= itemW/3
r=0
For i=0 To smallIV.Length-1
m= i Mod 3
l= (m+1)*space+ m*itemW
If m=0 Then
r=r+1
t= r*space+(r-1)*itemW
End If
IV(i).Initialize("")
Pnl_PLBG.AddView(IV(i),l,t,itemW,itemW)
IV(i).Gravity= Gravity.FILL
XY(i).x= IV(i).Left+itemW/2
XY(i).y= IV(i).Top+itemW/2
drawLockPattern(IV(i),0)
Next
End Sub

'将保存图片文件
Sub ImageToFile(bmp As Bitmap,fileName As String)
Dim Out As OutputStream
Out= File.OpenOutput(fileName, "", False)
bmp.WriteToStream(Out,80,"JPEG")
Out.Close
End Sub

Sub dawRedLine
If ls.Size=0 Then Return
Dim p As Path
Dim m As Int
m= ls.Get(0)
p.Initialize(XY(m).x,XY(m).y)
For i=1 To ls.Size-1
m= ls.Get(i)
p.LineTo(XY(m).x,XY(m).y)
Next
cvs.DrawColor(Colors.Transparent)
cvs.DrawPath(p,Colors.ARGB(200,255,0,0),False,8dip)
End Sub


  评论这张
 
阅读(155)| 评论(1)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017