#Region Project Attributes
#ApplicationLabel: Nav Drawer Blur
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
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 listviewtest As ListView
Dim NavDrawer As AHNavigationDrawer
'ListView inside Nav Drawer
Dim LV1 As ListView
'Panel holds NavDrawer's content
Dim pContent As Panel
'Amount to descend when drawer opens
Dim descendAmount As Int = 20dip
'The blur layers!
Dim iv_layer1, iv_layer2 As ImageView
'Bitmaps for the blur layers!
Dim pshot, bshot 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:
'Activity.LoadLayout("l1")
Activity.Title = "Slide out drawer"
LV1.Initialize("LV1")
'Initialize the navigation drawer.
NavDrawer.Initialize("NavDrawer", Activity, 240dip)
'We add the ListView to our NavigationPanel and set it up
NavDrawer.NavigationPanel.AddView(LV1, 0, 100dip, 100%x, 100%y)
NavDrawer.NavigationPanel.Color = Colors.ARGB(88,98,98,98)
LV1.AddTwoLinesAndBitmap("Load Images","",LoadBitmap(File.DirAssets,"selected_checkbox.png"))
LV1.AddTwoLinesAndBitmap("Menu Item 2","",LoadBitmap(File.DirAssets,"selected_unselectedpng.png"))
LV1.TwoLinesAndBitmap.ItemHeight = 96dip
LV1.TwoLinesAndBitmap.ImageView.Top = (96dip - 48dip) / 2
LV1.TwoLinesAndBitmap.ImageView.Width = 48dip
LV1.TwoLinesAndBitmap.ImageView.Height = 48dip
LV1.TwoLinesAndBitmap.ImageView.Left = 20dip
LV1.TwoLinesAndBitmap.Label.Top = (96dip - 48dip) / 2
LV1.TwoLinesAndBitmap.Label.Height = 48dip
LV1.TwoLinesAndBitmap.Label.Left = 20dip + 48dip + 20dip
LV1.TwoLinesAndBitmap.Label.Gravity = Gravity.CENTER_VERTICAL
'Remove the fade on the background when drawer is open
SetScrimColor(NavDrawer, Colors.Transparent)
pContent.Initialize("")
NavDrawer.ContentPanel.AddView(pContent, 0 ,0, 100%x, 100%y)
pContent.Color = Colors.Black
'Send behind the drawer
pContent.SendToBack
'Set up the blur layers
iv_layer1.Initialize("")
iv_layer2.Initialize("")
iv_layer1.Gravity = Gravity.FILL
iv_layer2.Gravity = Gravity.FILL
'pContent.LoadLayout("1")
listviewtest.Initialize("")
listviewtest.AddSingleLine("monday")
listviewtest.AddSingleLine("tuesday")
listviewtest.AddSingleLine("wednesday")
listviewtest.AddSingleLine("thursday")
listviewtest.AddSingleLine("friday")
pContent.AddView(listviewtest, 20dip, 20dip, 50%x, 50%y)
pContent.AddView(iv_layer1,0dip,0,pContent.Width,pContent.Height)
pContent.AddView(iv_layer2,0dip,0,pContent.Width,pContent.Height)
pContent.Color = Colors.Black
End Sub
Sub Activity_Resume
DoEvents
DoEvents
pshot = ScrShotWalter
Dim UIUtils As UIUtils
UIUtils.blurOnThread(pshot, 20, "Blur")
DoEvents
DoEvents
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub iv_Click
NavDrawer.OpenDrawer
End Sub
'Animate on sliding the drawer
Sub NavDrawer_DrawerSlide (Position As Float, DrawerGravity As Int)
Dim Offset As Int = Position * descendAmount
pContent.Left = Offset
pContent.top = Offset
pContent.Width = 100%x - 2 * (Offset)
pContent.Height = 100%y - 2 * (Offset)
iv_layer1.Width = pContent.Width
iv_layer1.Height = pContent.Height
iv_layer2.Width = pContent.Width
iv_layer2.Height = pContent.Height
setAlpha(iv_layer2, Position)
End Sub
'Set up bitmaps once blur is complete
Sub Blur_End(retBitmap As Bitmap)
Log("blurred")
bshot = retBitmap
iv_layer1.Bitmap = pshot
iv_layer2.Bitmap = bshot
iv_layer1.Gravity = Gravity.FILL
iv_layer2.Gravity = Gravity.FILL
setAlpha(iv_layer2, 0)
End Sub
' HELPER FUNCTIONS -----------------------------------------------------------
Sub setAlpha(v As View, value As Float)
Dim r As Reflector
r.Target = v
r.RunMethod2("setAlpha",value, "java.lang.float")
End Sub
Sub SetScrimColor(Nav As AHNavigationDrawer, Color As Int)
Dim r As Reflector
r.Target = Nav
r.Target = r.GetField("mNavDrawer")
r.RunMethod4("setScrimColor", Array As Object(Color), Array As String("java.lang.int"))
End Sub
'Take a screenshot - code provided by Sir Walter 2F
Sub ScrShotWalter As Bitmap
' Take a screenshot.
Dim Obj1, Obj2 As Reflector
Dim bmp As Bitmap
Dim c As Canvas
Dim now, i As Long
Obj1.Target = Obj1.GetActivityBA
Obj1.Target = Obj1.GetField("vg")
bmp.InitializeMutable(Activity.Width, Activity.Height)
c.Initialize2(bmp)
Dim args(1) As Object
Dim types(1) As String
Obj2.Target = c
Obj2.Target = Obj2.GetField("canvas")
args(0) = Obj2.Target
types(0) = "android.graphics.Canvas"
Obj1.RunMethod4("draw", args, types)
Return bmp
End Sub