Android Programming 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.

List of types:

PageTurnView
TextPaginator

PageTurnView

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

Members:


  AllowLastPageCurl As Boolean [write only]

  Background As android.graphics.drawable.Drawable

  BringToFront

  Color As Int [write only]

  CurrentPage As Int

  Enabled As Boolean

  Height As Int

  Initialize (eventName As String, smoothness As Int)

  Invalidate

  Invalidate2 (Rect As android.graphics.Rect)

  Invalidate3 (Left As Int, Top As Int, Right As Int, Bottom As Int)

  IsInitialized As Boolean

  Left As Int

  OnPause

  OnResume

  RecoverMemory

  RecycleBitmap (bitmap As android.graphics.Bitmap)

  RemoveView

  RenderLeftPage As Boolean [write only]

  RequestFocus As Boolean

  RunOnGuiThread (sub As String, params() As Object) As Boolean

  SendToBack

  SetBackgroundImage (Bitmap As android.graphics.Bitmap)

  SetLayout (Left As Int, Top As Int, Width As Int, Height As Int)

  SetMarginPixels (left As Int, top As Int, right As Int, bottom As Int)

  SetMargins (left As Float, top As Float, right As Float, bottom As Float)

  Tag As Object

  Top As Int

  TwoPages As Boolean [write only]

  Version As Double [read only]

  Visible As Boolean

  Width As Int

Members description:

AllowLastPageCurl As Boolean [write only]
Allow the last page to curl. The default is to permit this.
Background As android.graphics.drawable.Drawable
Gets or sets the background drawable.
BringToFront
Changes the Z order of this view and brings it to the front.
Color As Int [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.
CurrentPage As Int
Get or set the current page. Page numbering starts at 0 like an array.
Enabled As Boolean
Height As Int
Initialize (eventName As String, smoothness As Int)
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 (Rect As android.graphics.Rect)
Invalidates the given rectangle.
Redrawing will only happen when the program can process messages. Usually when it finishes running the current code.
Invalidate3 (Left As Int, Top As Int, Right As Int, Bottom As Int)
Invalidates the given rectangle.
Redrawing will only happen when the program can process messages. Usually when it finishes running the current code.
IsInitialized As Boolean
Left As Int
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 (bitmap As android.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.
RenderLeftPage As Boolean [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.
RequestFocus As Boolean
Tries to set the focus to this view.
Returns True if the focus was set.
RunOnGuiThread (sub As String, params() As Object) As Boolean
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.
SetBackgroundImage (Bitmap As android.graphics.Bitmap)
SetLayout (Left As Int, Top As Int, Width As Int, Height As Int)
Changes the view position and size.
SetMarginPixels (left As Int, top As Int, right As Int, bottom As Int)
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.
SetMargins (left As Float, top As Float, right As Float, bottom As Float)
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.
Tag As Object
Gets or sets the Tag value. This is a place holder which can used to store additional data.
Top As Int
TwoPages As Boolean [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.
Version As Double [read only]
Returns the version number of the library.
Visible As Boolean
Width As Int
Gets or sets the view's width.

TextPaginator

TextPaginator will split a String into pages according to a set of specified page and paint parameters.

The paginated text is stored internally and may be rendered to a Bitmap on demand.

Events:

None

Members:


  ALIGN_CENTER As android.text.Layout.Alignment

  ALIGN_NORMAL As android.text.Layout.Alignment

  ALIGN_OPPOSITE As android.text.Layout.Alignment

  GetPageBitmap (index As Int, backcolor As Int) As android.graphics.Bitmap

  PageCount As Int [read only]

  Paginate (text As String)

  SetPageParameters (alignment As android.text.Layout.Alignment, width As Int, leftmargin As Int, height As Int, topmargin As Int, linespacing As Float)

  SetPaintParameters (typeface As android.graphics.Typeface, textsize As Float, color As Int, antialias As Boolean)

Members description:

ALIGN_CENTER As android.text.Layout.Alignment
ALIGN_NORMAL As android.text.Layout.Alignment
ALIGN_OPPOSITE As android.text.Layout.Alignment
GetPageBitmap (index As Int, backcolor As Int) As android.graphics.Bitmap
Return a Bitmap containing the text specified rendered onto the background color.
PageCount As Int [read only]
Return the number of pages in the most recent pagination.
Paginate (text As String)
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.
SetPageParameters (alignment As android.text.Layout.Alignment, width As Int, leftmargin As Int, height As Int, topmargin As Int, linespacing As Float)
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.
SetPaintParameters (typeface As android.graphics.Typeface, textsize As Float, color As Int, antialias As Boolean)
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