Press on the image to return to the main documentation page.
PageTurnView
Written by Andrew Graham
This PageTurnView inherits the properties and methods of a normal Basic4android view. Some are overriden to provide the correct behaviour of this view, some will work correctly while others may have no, or a detrimental effect when invoked. Experiment will inform.
There are no touch or click events available as the page turning animation swallows all gestures.
Note that the PageTurnerView events run on a separate thread to the main thread. They therefore must not try to manipulate GUI elements or an exception will occur. The RunOnGuiThread method allows an event to invoke a Sub to be run on the main thread.
The GetPages() As Int event is called when the number of pages is required. Return the total number of pages that are available for display.
The GetBitmap(Width as Int, Height As Int, Page as Int) As Bitmap event is called when the Bitmap for the given page number is required. Return the appropriate Bitmap. If the returned Bitmap is not of the requested size it will be displayed scaled to fit.
This library contains a View that presents a Bitmap as a book page and simulates the turning of pages with an animation in reponse to touch events. It is based on an OpenGL implementation by Harri Smått at https://github.com/harism/android_page_curl with additions by Andrew Graham to adapt it for use with Basic4android. This library is based on page_curl-339d9e0.zip whose sources are dated 8/8/11 The library is released under Apache 2.0 and can be used in commercial or personal projects.
Copyright 2011 Harri Smått Copyright 2011 Andrew Graham
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. This is an 'Activity Object', it cannot be declared under Sub Process_Globals.
Events:
GetPages() As Int 'Called when the number of pages is required. Return the number of pages 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 Click LongClick
Allow the last page to curl. The default is to permit this.
BackgroundAsandroid.graphics.drawable.Drawable
Gets or sets the background drawable.
BringToFront
Changes the Z order of this view and brings it to the front.
ColorAsInt [write only]
Sets the background color - or the OpenGL clear color to be more precise. You should call this in Activity_Resume as it is lost on an activity pause.
CurrentPageAsInt
Get or set the current page. Page numbering starts at 0 like an array.
EnabledAsBoolean
HeightAsInt
Initialize (eventNameAsString, smoothnessAsInt)
Initialise the PageViewTurn with its event name and the smoothness of the page turn. The value for this was 10 in version 1.0 but this is insufficient for larger screen higher resolution devices where the line segments making up the page curl can be see.
Invalidate
Invalidates the whole view forcing the view to redraw itself. Redrawing will only happen when the program can process messages. Usually when it finishes running the current code.
Invalidate2 (RectAsandroid.graphics.Rect)
Invalidates the given rectangle. Redrawing will only happen when the program can process messages. Usually when it finishes running the current code.
Invalidates the given rectangle. Redrawing will only happen when the program can process messages. Usually when it finishes running the current code.
IsInitializedAsBoolean
LeftAsInt
OnPause
You must call this method in your Sub OnPause.
OnResume
You must call this method in your Sub OnResume.
RecoverMemory
Force a garbage collection to try to recover all avalable memory.
RecycleBitmap (bitmapAsandroid.graphics.Bitmap)
Free the native object associated with the bitmap, and clear the reference to the pixel data. This operation cannot be reversed, so it should only be called if you are sure there are no further uses for the bitmap.
RemoveView
Removes this view from its parent.
RenderLeftPageAsBoolean [write only]
Sets whether left side page is rendered. This is useful mostly for situations where the right (main) page is aligned to left side of screen and the left page is not visible anyway. The default is to render the left page.
RequestFocusAsBoolean
Tries to set the focus to this view. Returns True if the focus was set.
Causes the specified Sub to be scheduled for execution on the main GUI thread. This mechanism is the only way a thread can access GUI items. This call returns immediately and the Sub will be run at some indeterminate time in the future. Returns True if the Sub was found otherwise returns False.
SendToBack
Changes the Z order of this view and sends it to the back.
Set the visible margins in pixels around a page displayed in the view. This is a conveninece call to SetMArgins that allows dips to be used to specifiy sizes. This must be called after this view has been added to a parent view and its size defined because values are stored as a scaling factor of this views width and height at the time of this call. If the view size is changed subsequently this method will need to be called again.
Set the visible margins in pixels around a page displayed in the view. These values are specified as a scaling factor of the view width or height as appropriate.
TagAsObject
Gets or sets the Tag value. This is a place holder which can used to store additional data.
TopAsInt
TwoPagesAsBoolean [write only]
Sets the view mode. If TwoPages is True then two pages are laid out on the visible area. otherwise the right page occupies the view. The default is one page.
Return a Bitmap containing the text specified rendered onto the background color.
PageCountAsInt [read only]
Return the number of pages in the most recent pagination.
Paginate (textAsString)
Paginate the provided text into lines and pages and store them internally ready for use. The text must end with a Char(10) - CRLF, so the library will add one if this is not so. However, depending on how you build your text it is probably more efficient to ensure that it is already terminated when passed.
Set the parameters of the page to be used to render text onto. Width and height are the size of the page in pixels. Leftmargin and topmargin determine the position of the text within the page and a right and a bottom margin of the same sizes are assumed. Linespacing determines the vertical spacing between lines as a multiple of the normal character height A value of 1.0 specifies the normal spacing, increase or decrease it to change the spacing.
Set the parameters of the Paint that will be used to render the text. These are the same as for Basic4android Canvas.DrawText except for antialias which if True smooths out the edges of what is being drawn.
Top