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

沉默蜂B4A安卓编程

国内资料最全的B4A资料库

 
 
 

日志

 
 

[消息框类]Message (二)  

2014-03-11 13:54:23|  分类: 官网类库 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
下面是类模块Message的代码:

'Class module

'code to put in main
'************************************************************
' declare scale as float in process_globals
' declare your msg object in globals
' add warningicon.png to files

'Sub Activity_Resume
'scale1 = 1.0 ' just for the font, does not relate to the class scale
'mymsg.Initialize("Main", "mymsg", Colors.yellow ,Colors.yellow, 24*scale1, Colors.White, 20*scale1 ,Colors.Yellow, Activity.width,Activity.height)
'Activity.AddView(mymsg.AsView,0,0,100%x,100%y)
''mymsg.SetScale(1.1) ' this changes the size of the msg.
''mymsg.Set_Button_Font_Size(18*scale1)
'end sub

'Sub Activity_KeyPress (KeyCode As Int) As Boolean 'return true if you want to consume the event
'If KeyCode = KeyCodes.KEYCODE_BACK Then
'   mymsg.set_type(false)
'   mymsg.Show("Exit","Do you want to exit ?", LoadBitmap(File.DirAssets,"warningicon.png"),"Yes","", "No")
'End If
'Return True
'End Sub
'
'Sub mymsg_results(result As Int)
'If result = DialogResponse.POSITIVE Then Activity.Finish
'mymsg.set_type(true) ' critical to return the type to true for other messages.
'End Sub

'use: 
'if mymsg.Show("Vote","Do you like this message ?", LoadBitmap(File.DirAssets,"warningicon.png"),"Yes","Cancel", "No") = DialogResponse.POSITIVE Then...

'middle or right buttons will not appear if the their text is "" .

'*************************************************************************


Sub Class_Globals
Private MModule As Object
Private background,frame , p, line  As Panel
Private btn(3) As Button
Private titlelbl, msglbl As Label
Private iv As ImageView
Private result As Int = 0
Private scale, SF As Float 
Private ModalMsg As Boolean = True ' not using the return sub in the main activity
Private event As String
Private AW, AH As Int
Private phone As phone
End Sub

'初始化对象
'Module = 所在窗体的名称,字符串形式,如""Main
'Eventname = 事件名称
'Frame =对话框边框颜色
'TitleColor = 标题文本颜色
'TitleSize = 标题文本字体大小
'MsgColor = 消息文本颜色
'MsgSize = 消息文本字体大小
'LineColor = 消息框内部那条水平线条颜色
'ActivityWidth = 消息框所在窗体宽度,一般填100%x
'ActivityHeight = 消息框所在窗体高度,一般填100%y
Public Sub Initialize(Module As Object, Eventname As String,FrameColor As Int, TitleColor As Int, TitleSize As Int, MsgColor As Int, MsgSize As Int,LineColor As Int, ActivityWidth As Int, ActivityHeight As Int)

AW = ActivityWidth
AH = ActivityHeight
Dim clr(2) As Int
Dim dw As GradientDrawable

SF =  Max(AW,AH)/800 
scale = SF
MModule = Module
event = Eventname

background.Initialize("bg")
frame.Initialize("")
iv.Initialize("")
p.Initialize("")
line.Initialize("")
titlelbl.Initialize("")
msglbl.Initialize("")

background.Color = Colors.ARGB(170,0,0,0)
frame.Color = FrameColor
p.Color = Colors.DarkGray
titlelbl.TextSize = TitleSize * scale
titlelbl.TextColor = TitleColor
titlelbl.Gravity = Gravity.CENTER
msglbl.TextSize = MsgSize * scale
msglbl.TextColor = MsgColor
msglbl.Gravity = Gravity.CENTER
line.Color = LineColor
clr(0) = Colors.white
clr(1) = Colors.RGB(80,80,80)
dw.Initialize("TOP_BOTTOM",clr)
dw.CornerRadius = 5dip
For i = 0 To 2
btn(i).Initialize("button")
btn(i).background = dw
btn(i).TextSize = MsgSize*scale
btn(i).Textcolor = Colors.black
Next
btn(0).Tag = DialogResponse.POSITIVE
btn(1).Tag = DialogResponse.CANCEL
btn(2).Tag = DialogResponse.NEGATIVE

iv.Gravity = Gravity.FILL

background.AddView(frame,AW/2-130dip*scale, AH/2-105dip*scale, 250dip*scale, 210dip*scale)
frame.AddView(p,5dip*scale, 5dip*scale,240dip*scale,200dip*scale)
p.AddView(iv,15dip*scale,5dip*scale,40dip*scale,40dip*scale)
p.AddView(titlelbl,70dip*scale,5dip*scale,165dip*scale,40dip*scale)
p.AddView(line,0,50dip*scale,p.Width,3dip*scale)
p.AddView(msglbl,5dip*scale,60dip*scale,230dip*scale,80dip*scale)
p.AddView(btn(0),5dip*scale,145dip*scale,73dip*scale,50dip*scale)
p.AddView(btn(1),83dip*scale,145dip*scale,74dip*scale,50dip*scale)
p.AddView(btn(2),162dip*scale,145dip*scale,73dip*scale,50dip*scale)
background.Visible = False
End Sub

'如果set_type参数值为 True ,将不用  main activity 里的返回子函数,而是返回 “ show“ 里的调用子函数
'不管set_type参数值为False,或 True ,点击出来的消息框中的任意一个按钮,
'都会调用 Message对象中的事件 button_click
'If True - will not use the return sub in the main activity, but return the call from  "Show" .
Public Sub set_type(Modal As Boolean)
ModalMsg = Modal 
End Sub

'增加或减少对话框的大小,但保持它为中心。SizeFactor = 1是没有改变。
'Increase or Decrease the dialog size, but keeps it centered. SizeFactor = 1 is no change.
Public Sub SetScale(SizeFactor As Float)
scale = SF * SizeFactor
frame.SetLayout(AW/2-130dip*scale, AH/2-105dip*scale, 250dip*scale, 210dip*scale)
p.SetLayout(5dip*scale, 5dip*scale,240dip*scale,200dip*scale)
iv.SetLayout(15dip*scale,5dip*scale,40dip*scale,40dip*scale)
titlelbl.SetLayout(70dip*scale,5dip*scale,165dip*scale,40dip*scale)
line.SetLayout(0,50dip*scale,p.Width,3dip*scale)
msglbl.SetLayout(5dip*scale,60dip*scale,230dip*scale,80dip*scale)
btn(0).SetLayout(5dip*scale,145dip*scale,73dip*scale,50dip*scale)
btn(1).SetLayout(83dip*scale,145dip*scale,74dip*scale,50dip*scale)
btn(2).SetLayout(162dip*scale,145dip*scale,73dip*scale,50dip*scale)
End Sub

'显示对话框
'如果参数midtext或righttext用"",按钮将不会显示。
'Title = 标题文本
'Text = 消息内容
'Bitmap = 图标对象,不采用图标,标题文本也不会居中显示,最好显示图标,不想用图标可以用NULL
'LeftText = 左边按钮文本,此按钮点击后返回-1, (这个对话框最多允许出现3个按钮,但至少应出现一个)
'MidText = 中间按钮文本,此按钮点击后返回-3, 不想出现此按钮,这个参数用""
'RightText= 右边按钮文本,此按钮点击后返回-2, 不想出现此按钮,这个参数用""
'If midtext or righttext are passed as "" - the buttons will not show.
Public Sub Show(Title As String, Text As String, Bitmap As Bitmap, LeftText As String, MidText As String, RightText As String)

titlelbl.Text = Title
msglbl.Text = Text
btn(0).Text = LeftText
If MidText = "" Then
btn(1).Visible = False
If RightText = "" Then
btn(2).Visible = False
btn(0).Left = 65dip*scale
btn(0).Width = 110dip*scale
Else
btn(0).SetLayout(5dip*scale,145dip*scale,110dip*scale,50dip*scale)
btn(2).SetLayout(125dip*scale,145dip*scale,110dip*scale,50dip*scale)
btn(2).Text = RightText
btn(2).Visible = True
End If
Else
btn(0).SetLayout(5dip*scale,145dip*scale,73dip*scale,50dip*scale)
btn(1).SetLayout(83dip*scale,145dip*scale,74dip*scale,50dip*scale)
btn(2).SetLayout(162dip*scale,145dip*scale,73dip*scale,50dip*scale)
btn(1).Text = MidText
btn(2).Text = RightText
btn(1).Visible = True
btn(2).Visible = True
End If 

If Bitmap.IsInitialized Then
iv.Bitmap = Bitmap
iv.Visible = True
Else
iv.Visible = False
End If
background.Visible = True
background.BringToFront
If ModalMsg Then
If AW>AH Then 
Phone.SetScreenOrientation(0)
Else 
Phone.SetScreenOrientation(1)
End If
result = 0
Do While result = 0
DoEvents
Loop
Phone.SetScreenOrientation(-1)
Return result
Else

End If

End Sub

Public Sub AsView As View
Return background
End Sub

Public Sub Set_Button_Font_Size(FontSize As Int)
For i = 0 To 2
btn(i).TextSize = FontSize * scale
Next
End Sub

Public Sub Frame_Color(color As Int)
frame.color = color
End Sub

Public Sub Line_Color(color As Int)
line.color = color
End Sub

Private Sub button_click

Log("button_click")
Dim B As Button
B = Sender
result = B.Tag
If ModalMsg = False Then CallSubDelayed2(MModule,event & "_results",result)
background.Visible = False
End Sub

Private Sub bg_click
Log("bg_click")
End Sub

Private Sub bg_long_click
Log("bg_long_click")
End Sub




  评论这张
 
阅读(231)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

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

页脚

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