help me with page turn view

ryoma

New Member
i refer to example on library for "page turn view" i want to modify this page turn view.. i want to make it interface look like a book...currently i make it black and white as background.. i wanted to make image background on it and at the description i also want to add image.. this is my code at the moment.. anyone can help me?? which part i need to modify and what code should i put it.. ty =)
:sign0085:

'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim PageNumber As Int ' save page number during device rotation

Dim ipsum1 As String
Dim ipsum2 As String
ipsum1 = "**MEMANDIKAN JENAZAH**"
ipsum2 = "Perbuatan meratakan air ke seluruh badan Jenazah dengan tujuan untuk menghilangkan najis dan juga supaya jezah bersih dan suci"

' Dim x As Bitmap
' x.Initialize(File .DirAssets."contact1.png")

Dim paracount As Int : paracount = 1
Dim LeftMargin As Int : LeftMargin = 10dip
Dim TopMargin As Int : TopMargin = 10dip
Dim LineSpacing As Int : LineSpacing = 1
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 PageTurner As PageTurnView
Dim Pager As TextPaginator
Dim Font1 As Typeface
End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("memandikan")
PageTurner.Initialize("PageTurner", 20)
Activity.AddView(PageTurner, 10dip, 10dip, Activity.Width - 20dip, Activity.Height - 20dip)

If Activity.Width > Activity.Height Then
PageTurner.TwoPages = True ' the default is False
PageTurner.RenderLeftPage = True ' the default is True
Pager.SetPageParameters(Pager.ALIGN_NORMAL, PageTurner.Width/2 - 12dip, LeftMargin, PageTurner.Height - 12dip, TopMargin, LineSpacing)
PageTurner.SetMarginPixels(6dip, 6dip, 6dip, 6dip)
Else
PageTurner.TwoPages = False
PageTurner.RenderLeftPage = False
Pager.SetPageParameters(Pager.ALIGN_CENTER, PageTurner.Width - 20dip, LeftMargin, PageTurner.Height - 20dip, TopMargin, LineSpacing)
PageTurner.SetMarginPixels(10dip, 10dip, 10dip, 10dip)
End If
PageTurner.AllowLastPageCurl = False ' the default is true

Font1 = Font1.CreateNew(Typeface.SERIF, Typeface.STYLE_BOLD)
Dim text As String
For i = 0 To paracount - 1
text = text & ipsum1 & CRLF & ipsum2 & CRLF & CRLF
Next
Pager.SetPaintParameters(Font1, 19, Colors.Black, True)
Pager.Paginate(text)


End Sub

Sub Activity_Resume
PageTurner.CurrentPage = PageNumber
PageTurner.Color = Colors.LightGray ' otherwise it gets lost on Pause and Resume without a Create
PageTurner.OnResume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
PageNumber = PageTurner.CurrentPage
PageTurner.OnPause
End Sub

' This is run on the main thread to display any exception in PageTurner_GetBitmap
Sub ShowPTError(title As String, msg As String)
Msgbox(msg, title)
End Sub



Sub PageTurner_GetBitmap(Width As Int, Height As Int, Page As Int) As Bitmap 'Called when the Bitmap for the given page number is required. Return the Bitmap
' As this is running on a separate thread exceptions will cause the application to force close
' and not report the exception as would happen on the main thread so we use a Try Catch block
' to trap any errors
Dim bmp As Bitmap
Dim cnv As Canvas
bmp.InitializeMutable(Width, Height) ' do this here so we have a valid return in case of an exception
Try
'File.OpenInput("bad", "filename") ' this would cause an exception to be reported on the main thread
If Page = 0 Then
cnv.Initialize2(bmp)
cnv.DrawColor(Colors.Black)
cnv.DrawText( "A Book", Width/2, 100dip, Typeface.DEFAULT, 24, Colors.White, "CENTER")
Return bmp
Else If Page = Pager.PageCount + 1 Then
cnv.Initialize2(bmp)
cnv.DrawColor(Colors.Black)
cnv.DrawText( "The End", Width/2, 100dip, Typeface.DEFAULT, 24, Colors.White, "CENTER")
Return bmp
Else
Return Pager.GetPageBitmap(Page - 1, Colors.Transparent)
End If
Catch
' catch and report any exceptions on the rendering thread to the main thread
PTException
End Try
Return bmp ' if we don't return something valid we will cause an exception on the rendering thread
End Sub

Sub PageTurner_GetPages() As Int 'Called when the number of pages is required. Return the number of pages
' This is running on a separate thread and I have seen a NullPointerException in here on closing the app
' Presumably the Pager object was destroyed before the OpenGL thread was stopped so we trap any error
Try
Return Pager.PageCount + 2
Catch
Return 0 ' if we don't return something valid we will cause an exception on the rendering thread
End Try
End Sub

Sub PTException()
Dim Ex As ExceptionEx
Dim where As String
Ex = LastException
Dim args(2) As Object
args(0) = LastException.Message
where = Ex.StackTraceElement(2) ' get Java line of error
args(1) = where
PageTurner.RunOnGuiThread("ShowPTError", args)
End Sub
 
Top