[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

api[cordova] code

NativeObject
 subclass: #Cordova
 instanceVariableNames: ''
 category: #Cordova!
Cordova comment: '
	Root of Cordova framework hierarchy.
	Apache Cordova is a set of device APIs that allow a mobile app developer to access native device function such as the camera or accelerometer.
	http://cordova.io
	@2013 Alejandro Reimondo - aleReimondo@smalltalking.net
'!
"Smalltalk
  definePool: #Cva8Constants
  with: #(
	#( #CameraDataUrl 0 )
	#( #CameraFileUri 1 )
	#( #CameraPhotolibrary 0 )
	#( #CameraCamera 1 )
	#( #CameraSavedPhotoAlbum 2 )
	#( #CameraJPEG 0 )
	#( #CameraPNG 1 )
	#( #CameraPicture 0 )
	#( #CameraVideo 1 )
	#( #CameraAllMedia 2 )
	#( #ConnectionUnknown #unknown )
	#( #ConnectionEthernet #ethernet )
	#( #ConnectionWifi #wifi )
	#( #ConnectionCell2G #2g )
	#( #ConnectionCell3G #3g )
	#( #ConnectionCell4G #4g )
	#( #ConnectionCell #cell )
	#( #ConnectionNone #none )
  )"!

Cordova
 subclass: #Cva8AsyncObject
 instanceVariableNames: 'id'
 category: #Cordova!

#(	#Acceleration #Device #Cva8Events
	#MediaFileData
	#CompassHeading #Contact
	#ContactAddress #ContactField #ContactName #ContactOrganization
	#FileEntity #FileAccessor #Metadata #Cva8File #DirectoryReader
	#FileTransfer #FileUploadOptions #FileUploadResult
	#GeoPosition #GeoCoordinates #Notification
	#Cva8SQLTransaction #Cva8SQLResultSet
	#Cva8LocalStorage
	#Cva8App
) do: [:each|
	Cordova subclass: each instanceVariableNames: '' category: #Cordova
].!
#(	#Accelerometer #Camera
	#Capture #Compass #Connection
	#Geolocation #MediaFile
	#Cva8DataBase
) do: [:each|
	Cva8AsyncObject subclass: each instanceVariableNames: '' category: #Cordova
].!
#(	#CaptureAudio #CaptureImage #CaptureVideo
) do: [:each|
	Capture subclass: each instanceVariableNames: '' category: #Cordova
].!
#(	#FileReader #FileWriter
) do: [:each|
	FileAccessor subclass: each instanceVariableNames: '' category: #Cordova
].!
#(	#FileSystem #FileSystemElement
) do: [:each|
	FileEntity subclass: each instanceVariableNames: '' category: #Cordova
].!
#(	#DirectoryEntry #FileEntry
) do: [:each|
	FileSystemElement subclass: each instanceVariableNames: '' category: #Cordova
].!
Compass
 subclass: #CompassFilter
 instanceVariableNames: ''
 category: #Cordova!
Cva8AsyncObject
 subclass: #Contacts
 instanceVariableNames: ' fields '
 category: #Cordova!

Cva8App comment: '
	Exposes (java)methods in DroidGap that can be called from S8.'!
Acceleration comment: '
	Accelerometer data captured at a specific point in time.'!
CompassHeading comment: '
	Compass data captured at a specific point in time.'!
Connection comment: '
	Checks the active network connection that is being used.
	A fast way to determine the device network connection state, and type of connection.'!

Accelerometer comment: '
	The accelerometer is a motion sensor that detects the change (delta) in movement relative to the current device orientation.
	The accelerometer can detect 3D movement along the x, y, and z axis.
'!
Camera comment: '
	The camera object provides access to the device default camera application.
	Open the device default camera application so that the user can take a picture.
	Once the photo is taken, the camera application closes and your application is restored.
'!
MediaFile comment: '
	Properties of a media capture file.
'.
MediaFile buildGetters: #( #name #fullPath #type #lastModifiedDate #size ).!
MediaFileData comment: '
	Format information about a captured media file.
'.
MediaFileData buildGetters: #(
	#height #width
	#codecs #bitrate
	#duration
).!
Compass comment: '
	The compass is a sensor that detects the direction that the device is pointed.
	It measures the heading in degrees from 0 to 359.99.
'!
CompassFilter comment: '
	The CompassFilter is a sensor that detects the heading that the device is pointed.
	It measures the heading in degrees from 0 to 359.99.
'!
Contact comment: '
	Describe a contact, such as a user personal or business contact.
'.
Contact	buildAccessors: #(
	#id #displayName #name #nickname #phoneNumbers
	#emails #addresses #ims #organizations
	#birthday #note #photos #categories #urls
).!
ContactAddress comment: '
	A single address of a contact.
	A Contact object can have one or more addresses.
'.
ContactAddress buildAccessors: #(
	#pref #type #formatted #streetAddress #locality
	#region #postalCode #country
).!
ContactField comment: '
	Generic fields in a Contact object.
	Some properties that are stored as ContactField objects include email addresses, phone numbers, and urls.
'.
ContactField buildAccessors: #(
	#type #value #pref
).!
ContactName comment: '
	Name related properties of a contact.
'.
ContactName buildAccessors: #(
	#formatted #familyName #givenName #middleName #honorificPrefix #honorificSuffix
).!
ContactOrganization comment: '
	Organization related properties of a contact.
'.
ContactOrganization buildAccessors: #(
	#pref #type #name #department #title
).!
Device comment: '
	Describes the device hardware and software.
'.
Device buildAccessors: #(
	#name #cordova #platform #uuid #version
).!
FileEntity buildGetters: #( #name #fullPath ).!
FileSystem comment: '
	Instances represents information about the file system.
	The name of the file system will be unique across the list of exposed file systems.
	The root property contains a DirectoryEntry object which represents the root directory of the file system.
'.!
FileSystemElement buildBooleanGetter: #isFile; buildBooleanGetter: #isDirectory.!
DirectoryEntry comment: '
	Instances represents a directory on a file system.
	It is defined in the W3C Directories and Systems specification.
'.!
FileEntry comment: '
	Instances represents a file on a file system.
	It is defined in the W3C Directories and Systems specification.
'.!
Metadata comment: '
	Instances supplies information about the state of a file or directory.
'.
Metadata buildGetters: #( #modificationTime ).!
Cva8File comment: '
	Instances contains attributes of a single file.
'.
Cva8File buildGetters: #( #name #fullPath #type #lastModifiedDate #size ).!
FileAccessor comment: '
	Abstract interface to read/write files from the devices file system.
'.
FileAccessor buildAccessors: #(
	#readyState #error
	#onprogress
	#onabort #onerror
).!
FileReader comment: '
	FileReader is a way to read files from the devices file system.
	Files can be read as text or as a base64 data encoded string.
	Users register their own event listners to receive the loadstart, progress, load, loadend, error and abort events.
'.
FileReader buildAccessors: #(
	#result	#onloadstart #onload #onloadend
).!
FileWriter comment: '
	FileWriter is a way to write files from the devices file system.
	Users register their own event listeners to receive the writestart, progress, write, writeend, error and abort events.
	A FileWriter is created for a single file.
	You can use it to write to a file multiple times.
	The FileWriter maintains the file position and length attributes, so you can seek and write anywhere in the file.
	By default, the FileWriter writes to the beginning of the file (will overwrite existing data).
'.
FileWriter buildAccessors: #(
	#fileName #length #position
	#onwritestart #onwrite #onwriteend
).!
FileTransfer comment: '
	Instances allows you to upload files to a server.
'.!
FileUploadOptions comment: '
	Specify additional parameters to the upload script.
'.
FileUploadOptions buildAccessors: #(
	#fileKey #fileName #mimeType #params #chunkedMode
).!
FileUploadResult comment: '
	A file upload succeded. Instance has report information.
'.
FileUploadResult buildGetters: #(
	#bytesSent #responseCode #response
).!
Geolocation comment: '
	Instances provide access to the device GPS sensor. 
	Geolocation provides location information for the device, such as latitude and longitude.
	Common sources of location information include Global Positioning System (GPS) and location inferred from network signals such as IP address, RFID, WiFi and Bluetooth MAC addresses, and GSM/CDMA cell IDs.
	No guarantee is given that the API returns the device actual location.
	This API is based on the W3C Geo location API Specification.
'.!
GeoPosition comment: '
	Instances contain coordinates created by geolocation API.
'.
GeoPosition buildGetters: #( #timestamp ).!
GeoCoordinates comment: '
	Instances contain geoggraphic coordinates of a GeoPosition.
'.
GeoCoordinates buildAccessors: #(
	#latitude #longitude #altitude
	#accuracy #altitudeAccuracy
	#heading #speed
).!
Notification comment: '
	Visual, audible, and tactile device notifications.
'.!
Cva8DataBase comment: '
	Provides access to the devices storage options. 
	This API is based on the W3C Web SQL Database Specification and W3C Web Storage API Specification.
	Some devices already provide an implementation of this spec.
'.!
Cva8SQLTransaction comment: '
	Execute SQL statements against the Database.
'.!
Cva8SQLResultSet comment: '
	The result of executeSql message object has three properties.
	The first is the insertId which will return the row number of a success SQL insert statement.
	If the SQL statement is not an insert then the insertId is not set.
	The rowAffected is always 0 for a SQL select statement.
	For insert or update statements it returns the number of rows that have been modified.
	The final property is of type SQLResultSetList and it contains the data returned from a SQL select statement.
'.
Cva8SQLResultSet buildGetters: #( #insertId #rowAffected ).!
Cva8LocalStorage comment: '
	Provides access to a W3C Storage interface.
	http://dev.w3.org/html5/webstorage/#the-localstorage-attribute
'.!

! Cordova class methodsFor: #accessing !
accelerometer
	" Return the default instance. "

	^Accelerometer default! !

! Cordova class methodsFor: #accessing !
camera
	" Return the default instance. "

	^Camera default! !

! Cordova class methodsFor: #accessing !
captureAudio
	" Return the default instance. "

	^CaptureAudio default! !

! Cordova class methodsFor: #accessing !
captureImage
	" Return the default instance. "

	^CaptureImage default! !

! Cordova class methodsFor: #accessing !
captureVideo
	" Return the default instance. "

	^CaptureVideo default! !

! Cordova class methodsFor: #accessing !
compass
	" Return the default instance. "

	^Compass default! !

! Cordova class methodsFor: #accessing !
compassFilter
	" Return the default instance. "

	^CompassFilter default! !

! Cordova class methodsFor: #accessing !
connection
	" Return the default instance. "

	^Connection default! !

! Cordova class methodsFor: #accessing !
geolocation
	" Return the default instance. "

	^Geolocation default! !

! Cordova class methodsFor: #accessing !
notification
	" Return the default instance. "

	^Notification default! !

! Cordova class methodsFor: #accessing !
database
	" Return the default instance. "

	^Cva8DataBase! !

! Cordova class methodsFor: #accessing !
localStorage
	" Return the default instance. "

	^Cva8LocalStorage default! !

! Cordova class methodsFor: #accessing !
events
	" Return the default instance. "

	^Cva8Events default! !

! Cordova class methodsFor: #accessing !
device
	" Return the default instance. "

	^Device default! !

! Cordova class methodsFor: #accessing !
app
	" Return the default instance. "

	^Cva8App default! !

! Cordova class methodsFor: #services !
fileSystem
	" Return the fileSystem support (it is an async service, please read class side messages on FileEntity). "

	^FileSystem service! !

! Cordova class methodsFor: #services !
directory
	" Return the directory support (it is an async service, please read class side messages on FileEntity). "

	^DirectoryEntry service! !

! Cordova class methodsFor: #services !
file
	" Return the file support (it is an async service, please read class side messages on FileEntity). "

	^FileEntry service! !

! Cordova class methodsFor: #events !
constructEventsTriggered
	" Private - Return the events managed by instances of the receiver. "

	^super constructEventsTriggered , self cva8Events! !

! Cordova class methodsFor: #events !
cva8Events
	" Private - Return the events managed by Cordova.
	This method can be refined by subclasses to implement cordova hooks. "

	^Array new! !

! Cordova methodsFor: #events !
cva8Events
	" Private - Return the events managed by Cordova. "

	^self class cva8Events! !

! Cordova methodsFor: #events !
when: anEvent evaluate: anAction
	" Register anAction to the be evaluated when the receiver triggers the event. "

	((self cva8Events includes: anEvent) and: [
		(self hasActionForEvent: anEvent) not]) ifTrue: [
		self whenCordova: anEvent evaluate: anAction
	].
	^super when: anEvent evaluate: anAction! !

! Cordova methodsFor: #private !
whenCordova: anEvent evaluate: anAction
	" Private - Register anAction to the be evaluated when the receiver triggers the event. "

	^self implementedBySubclass! !

! Cordova class methodsFor: #events !
when: eventName do: aBlock
	" Return the default instance. "

	^self events when: eventName do: aBlock! !

! Cordova class methodsFor: #private !
errorBlock: errorBlock
	" Private - Return an error handler for errorBlock. "

	errorBlock isNil ifTrue: [
		^[:error| self error: self name ,': ' ,(self descriptionOf: error) ]
	].
	^errorBlock! !

! Cordova class methodsFor: #private !
descriptionOf: anError
	" Private - Return an error description for anError. "

	| code |
	[	anError#message notNil ifTrue: [ ^anError#message ].
		code := anError#code.
		code notNil ifTrue: [
			self errorCodeTable do: [:tuple|
				tuple first == code ifTrue: [ ^tuple last ,' error.' ].
			].
		].
		(self isObject: anError) ifFalse: [ ^(JS @ anError) description ].
	] on: Error do: [:ex| self print: 'Error reporting ' ,anError toString,' (' ,ex description,')' ].
	^'Unknon error ' ,anError toString! !

! Cordova class methodsFor: #private !
errorCodeTable
	" Private - Return an error code/description table. "

	^Array new! !

! Cva8AsyncObject class methodsFor: #events !
constructEventsTriggered
	" Private - Return the events managed by instances of the receiver. "

	^super constructEventsTriggered , #(
		#value:
		#error
	)! !

! Cordova methodsFor: #private !
errorBlock: errorBlock
	" Private - Return an error handler for errorBlock. "

	^self class errorBlock: errorBlock! !

! Cordova class methodsFor: #native !
js
	" Return a wrapper on the javascript library (or nil). "

	^JS @ (Smalltalk jsObjectAt: #Cordova ifAbsent: [])! !

! Cordova class methodsFor: #api !
addConstructor: aBlock
	" Register a constructor to be evaluated on cordovaReady. "

	#{cordova} #addConstructor: aBlock! !

! Cordova class methodsFor: #api !
addDocumentEventHandler: event
	" Register a document event handler. "

	^#{cordova} #addDocumentEventHandler: event! !

! Cordova class methodsFor: #api !
addStickyDocumentEventHandler: event
	" Register a document event handler. "

	^#{cordova} #addStickyDocumentEventHandler: event! !

! Cordova class methodsFor: #api !
addWindowEventHandler: event
	" Register a window event handler. "

	^#{cordova} #addWindowEventHandler: event! !

! Cordova class methodsFor: #api !
removeDocumentEventHandler: event
	" Remove a document event handler. "

	#{cordova} #removeDocumentEventHandler: event! !

! Cordova class methodsFor: #api !
removeWindowEventHandler: event
	" Remove a window event handler. "

	#{cordova} #removeWindowEventHandler: event! !

! Cordova class methodsFor: #api !
fireDocumentEvent: type data: data noDetach: aBoolean

	#{cordova} #fireDocumentEvent: type data: data noDetach: aBoolean! !

! Cordova class methodsFor: #api !
fireWindowEvent: type data: data

	#{cordova} #fireWindowEvent: type data: data! !

! Cordova class methodsFor: #api !
version
	" Returns the version string. "

	^#{cordova} basicAt: #version! !

! Cordova class methodsFor: #callbacks !
callbackId
	" Returns the callbackId. "

	^#{cordova} basicAt: #callbackId! !

! Cordova class methodsFor: #callbacks !
callbackStatus
	" Returns the callbackStatus literal. "

	^#{cordova} basicAt: #callbackStatus! !

! Cordova class methodsFor: #callbacks !
callbacks
	" Returns the callbacks table. "

	^#{cordova} basicAt: #callbacks! !

! Cordova class methodsFor: #api !
platformId
	" Returns the platform Id string. "

	^#{cordova} basicAt: #platformId! !

! Cordova class methodsFor: #api !
getOriginalHandlers
	" Returns the oroginal event handlers. "

	^#{cordova} getOriginalHandlers! !

! Cordova class methodsFor: #api !
getOriginalHandlers
	" Returns the original event handlers. "

	^#{cordova} getOriginalHandlers! !

! Cordova class methodsFor: #api !
require: id
	" Returns the jsObject exposed by loaded library id. "

	^#{cordova} #require: id! !

! Cordova class methodsFor: #api !
exec: successBlock fail: failBlock service: service action: action args: args
	" Execute the action on service with args. "

	^#{cordova} #exec: successBlock fail: failBlock service: service action: action args: args! !

! Cordova class methodsFor: #api !
define: id factory: factory

	^#{cordova} #define: id factory: factory! !


! Cva8AsyncObject methodsFor: #evaluation !
do: aBlock
	" Evaluate aBlock when async data is obtained from the default instance of the receiver. "

	^self default do: aBlock! !

! Cva8AsyncObject class methodsFor: #evaluation !
do: aBlock onError: errorBlock with: options
	" Evaluate aBlock when async data is obtained from the default instance of the receiver.
	In case of error, the error block will be evaluated. "

	^self default do: aBlock onError: errorBlock with: options! !

! Cva8AsyncObject class methodsFor: #evaluation !
do: aBlock onError: errorBlock
	" Evaluate aBlock when async data is obtained from the default instance of the receiver.
	In case of error, the error block will be evaluated. "

	^self default do: aBlock onError: errorBlock! !

! Cva8AsyncObject class methodsFor: #evaluation !
watch: aBlock
	" Evaluate aBlock when async data is obtained from the default instance of the receiver at regular interval. "

	^self default watch: aBlock! !

! Cva8AsyncObject class methodsFor: #evaluation !
watch: aBlock onError: errorBlock with: options
	" Evaluate aBlock when async data is obtained from the default instance of the receiver at regular interval.
	In case of error, the error block will be evaluated. "

	^self default watch: aBlock onError: errorBlock with: options! !

! Cva8AsyncObject class methodsFor: #evaluation !
watch: aBlock onError: errorBlock
	" Evaluate aBlock when async data is obtained from the default instance of the receiver at regular interval.
	In case of error, the error block will be evaluated. "

	^self default watch: aBlock onError: errorBlock! !

! Cva8AsyncObject methodsFor: #accessing !
id
	" Private - Return the current instance id (or nil). "

	^id! !

! Cva8AsyncObject methodsFor: #accessing !
id: anID
	" Private - Set the current instance id (or nil).
	Stop the receiver if currently running.
	"

	self stop.
	id := anID.! !

! Cva8AsyncObject methodsFor: #accessing !
isWorking
	" Return true if the receiver is working. "

	^id notNil! !

! Cva8AsyncObject methodsFor: #initialize !
release
	" Release the allocated resources of the receiver. "

	self stop.
	^super release! !

! Cva8AsyncObject methodsFor: #actions !
stop
	" Stop the receiver (if actually working). "

	self isWorking ifTrue: [ self releaseID ]! !

! Cva8AsyncObject methodsFor: #private !
releaseID
	" Release internal resources of the receiver. "

	| old |
	old := self id.
	ifd := nil.
	self clearID: old.! !

! Cva8AsyncObject methodsFor: #private !
clearID: anId
	" Private - Release internal resource of the receiver. "

	^self implementedBySubclass! !

! Cva8AsyncObject methodsFor: #accessing !
defaultValueBlock
	" Return the default block for processing data obtained from the receiver.
	Default implementation trigger events.
	"

	^[:anObject| self triggerEvent: #value: with: anObject ]! !

! Cva8AsyncObject methodsFor: #accessing !
defaultErrorBlock
	" Return the default error block to evaluate when error was detected while obtaining data from the receiver.
	Default implementation trigger events.
	"

	^[ self triggerEvent: #error ]! !

! Cva8AsyncObject methodsFor: #accessing !
valueFromData: data
	" Return the value (anObject)computed from data of the receiver.
	Default implementation return the raw data object (jsObject).
	This method can be refined by the subclasses.
	"

	^data! !

! Cva8AsyncObject methodsFor: #accessing !
defaultOptions
	" Return default options to get data with the receiver.
	The default implementation return nul.
	This method MUST be reimplemented when library need custom defaults.
	"

	^#{null}! !

! Cva8AsyncObject methodsFor: #accessing !
optionsFrom: options
	" Return the options data object (jsObject).
	The default action return the argument.
	This method can be refined by subclasses to handle weak options.
	"

	(self isObject: options) ifFalse: [ ^options ].
	options isNil ifTrue: [ ^self defaultOptions ].
	options isArray ifTrue: [ ^self optionsFromArray: options ].
	^options! !

! Cva8AsyncObject methodsFor: #options !
optionsFromArray: anArray
	" Return the options data object from anArray literal. "

	| result |
	result := ComposedAssociations new.
	anArray do: [:tuple| result add: tuple first -> tuple last ].
	^result json! !

! Cva8AsyncObject methodsFor: #evaluation !
do: aBlock
	" Evaluate aBlock when async data is obtained from the receiver. "

	^self do: aBlock onError: nil! !

! Cva8AsyncObject methodsFor: #evaluation !
do: aBlock onError: errorBlock
	" Evaluate aBlock when async data is obtained from the receiver.
	In case of error, the error block will be evaluated.
	Return the receiver and trigger threads to compute the value.
	The default action for block and error will trigger events when appropiate.
	"

	^self do: aBlock onError: errorBlock with: nil! !

! Cva8AsyncObject methodsFor: #evaluation !
do: aBlock onError: errorBlock with: options
	" Evaluate aBlock when async data is obtained from the receiver.
	In case of error, the error block will be evaluated.
	Return the receiver and trigger threads to compute the value.
	The default action for block and error will trigger events when appropiate.
	"

	aBlock isNil ifTrue: [ ^self do: self defaultValueBlock onError: errorBlock with: options ].
	errorBlock isNil ifTrue: [ ^self do: aBlock onError: self defaultErrorBlock with: options ].
	^self
		valueDoing: [:data| aBlock value: (self valueFromData: data) ]
		onError: (self errorBlock: errorBlock)
		with: (self optionsFrom: options)! !

! Cva8AsyncObject methodsFor: #evaluation !
valueDoing: aBlock onError: errorBlock with: options
	" Private - Evaluate aBlock when async data is obtained from the receiver.
	In case of error, the error block will be evaluated.
	Return the receiver and trigger threads to compute the value.
	"

	^self implementedBySubclass! !

! Cva8AsyncObject methodsFor: #evaluation !
watch: aBlock onError: errorBlock with: options
	" Evaluate aBlock when async data is obtained from the receiver at regular interval.
	In case of error, the error block will be evaluated.
	The default action for block and error will trigger events when appropiate.
	"

	aBlock isNil ifTrue: [ ^self watch: self defaultValueBlock onError: errorBlock with: options ].
	errorBlock isNil ifTrue: [ ^self watch: aBlock onError: self defaultErrorBlock with: options ].
	self id: (self
		watchDoing: [:data| aBlock value: (self valueFromData: data) ]
		onError: (self errorBlock: errorBlock)
		with: (self optionsFrom: options))! !

! Cva8AsyncObject methodsFor: #evaluation !
watch: aBlock onError: errorBlock
	" Evaluate aBlock when async data is obtained from the receiver at regular interval.
	In case of error, the error block will be evaluated.
	The default action for block and error will trigger events when appropiate.
	"

	^self watch: aBlock onError: errorBlock with: nil! !

! Cva8AsyncObject methodsFor: #evaluation !
watch: aBlock
	" Evaluate aBlock when async data is obtained from the receiver at regular interval.
	The default action for block and error will trigger events when appropiate.
	"

	^self watch: aBlock onError: nil! !

! Cva8AsyncObject methodsFor: #evaluation !
watchDoing: aBlock onError: errorBlock with: options
	" Private - Evaluate aBlock when async data is obtained from the receiver at regular interval.
	In case of error, the error block will be evaluated.
	Must return the watch ID needed to track/release watch thread.
	"

	^self implementedBySubclass! !

! Cva8AsyncObject methodsFor: #evaluation !
watchDoing: aBlock
	" Private - Evaluate aBlock when async data is obtained from the receiver at regular interval. "

	^self watchDoing: aBlock onError: nil! !

! Acceleration methodsFor: #accessing !
x
	" Return the coordinate of the receiver.
	Amount of motion on the x-axis. Range [0, 1] "

	^handle#x! !

! Acceleration methodsFor: #accessing !
y
	" Return the coordinate of the receiver.
	Amount of motion on the y-axis. Range [0, 1] "

	^handle#y! !

! Acceleration methodsFor: #accessing !
z
	" Return the coordinate of the receiver.
	Amount of motion on the z-axis. Range [0, 1] "

	^handle#z! !

! Acceleration methodsFor: #accessing !
timeStamp
	" Return the timeStamp of the receiver.
	Creation timestamp in milliseconds. (DOMTimeStamp) "

	^handle#timestamp! !

! Accelerometer class methodsFor: #accessing !
default
	" Return the default/global instance of the receiver. "

	^self @ #{navigator}#accelerometer! !

! Accelerometer methodsFor: #accessing !
defaultOptions
	" Return default options to get data with the receiver. "

	^self optionsFromArray: #( #( #frequency 3000 ) )! !

! Accelerometer methodsFor: #evaluation !
valueDoing: aBlock onError: errorBlock with: options
	" Private - Evaluate aBlock when async data is obtained from the receiver. "

	self handle #getCurrentAcceleration: aBlock onError: errorBlock! !

! Accelerometer methodsFor: #evaluation !
watchDoing: aBlock onError: errorBlock with: options
	" Private - Evaluate aBlock when async data is obtained from the receiver at regular interval. "

	self handle #watchAcceleration: aBlock onError: errorBlock with: options! !

! Accelerometer methodsFor: #accessing !
valueFromData: data
	" Return the value (anObject)computed from data of the receiver. "

	^Acceleration @ data! !

! Accelerometer methodsFor: #accessing !
optionsFrom: options
	" Return the options data object (jsObject). "

	options isNumber ifTrue: [
		^self optionFrom: (Array with: #frequency with: options)
	].
	^super optionsFrom: options! !

! Accelerometer methodsFor: #private !
clearID: anId
	" Private - Release internal resource of the receiver. "

	^self handle #clearWatch: anId! !

! Camera class methodsFor: #accessing !
default
	" Return the default/global instance of the receiver. "

	^self @ #{navigator}#camera! !

! Camera methodsFor: #evaluation !
valueDoing: aBlock onError: errorBlock with: options
	" Private - Evaluate aBlock when async data is obtained from the receiver. "

	self handle #getPicture: aBlock onError: errorBlock with: options! !

! Camera methodsFor: #cleanup !
cleanUp: aBlock onError: errorBlock
	" Cleans up the image files that were taken by the camera, that were stored in a temporary storage location. "

	self handle #cleanup: aBlock onError: errorBlock! !

! Camera methodsFor: #evaluation !
watchDoing: aBlock onError: errorBlock with: options
	" Private - Evaluate aBlock when async data is obtained from the receiver at regular interval. "

	^self invalidMessage! !

! Camera methodsFor: #private !
clearID: anId
	" Private - Release internal resource of the receiver. "

	^self invalidMessage! !

! Camera methodsFor: #options !
quality: quality
destinationType: destinationType
sourceType: sourceType
allowEdit: allowEdit
encodingType: encodingType
targetWidth: targetWidth
targetHeight: targetHeight
	" Return a set of options for the receiver. "

	| tuples add |
	tuples := Array new.
	add := [:aName :aValue| aValue notNil ifTrue: [
		tuples add: (Array with: aName with: aValue)
		] ].
	add
		value: #quality value: quality;
		value: #destinationType value: destinationType;
		value: #sourceType value: sourceType;
		value: #allowEdit value: allowEdit;
		value: #encodingType value: encodingType;
		value: #targetWidth value: targetWidth;
		value: #targetHeight value: targetHeight;
		yourself.
	^self optionsFromArray: tuples! !

! Camera methodsFor: #accessing !
defaultOptions
	" Return default options to get data with the receiver. "

	^self
		quality: 75 destinationType: 0
		sourceType: 1 allowEdit: false
		encodingType: 0
		targetWidth: 100 targetHeight: 100! !

! Capture class methodsFor: #accessing !
default
	" Return the default/global instance of the receiver. "

	^self @ #{navigator}#device#capture! !

! Capture class methodsFor: #private !
errorCodeTable
	" Private - Return an error code/description table. "

	^#(
		#(  0 'Internal' )
		#(  1 'Application busy' )
		#(  2 'Invalid argument' )
		#(  3 'No media files' )
		#(  4 'Not supported' )
	)! !

! Capture methodsFor: #evaluation !
watchDoing: aBlock onError: errorBlock with: options
	" Private - Evaluate aBlock when async data is obtained from the receiver at regular interval. "

	^self invalidMessage! !

! Capture methodsFor: #private !
clearID: anId
	" Private - Release internal resource of the receiver. "

	^self invalidMessage! !

! Capture methodsFor: #options !
limit: limit
duration: duration
mode: mode
	" Return a set of options for the receiver. "

	| tuples add |
	tuples := Array new.
	add := [:aName :aValue| aValue notNil ifTrue: [
		tuples add: (Array with: aName with: aValue)
		] ].
	add
		value: #limit value: limit;
		value: #duration value: duration;
		value: #mode value: mode;
		yourself.
	^self optionsFromArray: tuples! !

! Capture methodsFor: #options !
limit: limit mode: mode
	" Return a set of options for the receiver. "

	^self limit: limit duration: nil mode: mode! !

! Capture methodsFor: #accessing !
valueFromData: data
	" Return the value (anObject)computed from data of the receiver. "

	^data collect: [:each| MediaFile @ each ]! !

! CaptureAudio methodsFor: #evaluation !
valueDoing: aBlock onError: errorBlock with: options
	" Private - Evaluate aBlock when async data is obtained from the receiver. "

	self handle #captureAudio: aBlock onError: errorBlock with: options! !

! CaptureAudio methodsFor: #accessing !
defaultOptions
	" Return default options to get data with the receiver. "

	^self limit: 3 duration: 10 mode: nil! !

! CaptureImage methodsFor: #evaluation !
valueDoing: aBlock onError: errorBlock with: options
	" Private - Evaluate aBlock when async data is obtained from the receiver. "

	self handle #captureImage: aBlock onError: errorBlock with: options! !

! CaptureImage methodsFor: #accessing !
defaultOptions
	" Return default options to get data with the receiver. "

	^self limit: 3 duration: nil mode: nil! !

! CaptureVideo methodsFor: #evaluation !
valueDoing: aBlock onError: errorBlock with: options
	" Private - Evaluate aBlock when async data is obtained from the receiver. "

	self handle #captureVideo: aBlock onError: errorBlock with: options! !

! CaptureVideo methodsFor: #accessing !
defaultOptions
	" Return default options to get data with the receiver. "

	^self limit: 3 duration: nil mode: nil! !

! MediaFile methodsFor: #accessing !
valueFromData: data
	" Return the value (anObject)computed from data of the receiver. "

	^data collect: [:each| MediaFileData @ each ]! !

! MediaFile methodsFor: #evaluation !
valueDoing: aBlock onError: errorBlock with: options
	" Private - Evaluate aBlock when async data is obtained from the receiver. "

	self handle #getFormatData: aBlock onError: errorBlock with: options! !


! MediaFileData methodsFor: #accessing !
extent
	" Return the extent of the receiver. "

	^self width @ self height! !

! Compass class methodsFor: #accessing !
default
	" Return the default/global instance of the receiver. "

	^self @ #{navigator}#compass! !

! Compass class methodsFor: #private !
errorCodeTable
	" Private - Return an error code/description table. "

	^#(
		#(  0 'Internal' )
		#( 20 'Not supported' )
	)! !

! Compass methodsFor: #accessing !
valueFromData: data
	" Return the value (anObject)computed from data of the receiver. "

	^CompassHeading @ data! !

! Compass methodsFor: #evaluation !
valueDoing: aBlock onError: errorBlock with: options
	" Private - Evaluate aBlock when async data is obtained from the receiver. "

	self handle #getCurrentHeading: aBlock onError: errorBlock with: options! !

! Compass methodsFor: #evaluation !
watchDoing: aBlock onError: errorBlock with: options
	" Private - Evaluate aBlock when async data is obtained from the receiver at regular interval. "

	self handle #watchHeading: aBlock onError: errorBlock with: options! !

! Compass methodsFor: #private !
clearID: anId
	" Private - Release internal resource of the receiver. "

	self handle #clearWatch: anId! !

! Compass methodsFor: #options !
frequency: frequency
filter: filter
	" Return a set of options for the receiver. "

	| tuples add |
	tuples := Array new.
	add := [:aName :aValue| aValue notNil ifTrue: [
		tuples add: (Array with: aName with: aValue)
		] ].
	add
		value: #frequency value: frequency;
		value: #filter value: filter;
		yourself.
	^self optionsFromArray: tuples! !

! Compass methodsFor: #accessing !
defaultOptions
	" Return default options to get data with the receiver. "

	^self frequency: 100 filter: nil! !

! CompassFilter methodsFor: #evaluation !
watchDoing: aBlock onError: errorBlock with: options
	" Private - Evaluate aBlock when async data is obtained from the receiver at regular interval. "

	self handle #watchHeadingFilter: aBlock onError: errorBlock with: options! !

! CompassFilter methodsFor: #private !
clearID: anId
	" Private - Release internal resource of the receiver. "

	self handle #clearWatchFilter: anId! !

! CompassHeading methodsFor: #accessing !
magneticHeading
	" Return the heading of the receiver.
	The heading in degrees from 0 - 359.99 at a single moment in time. (Number) "

	^handle#magneticHeading! !

! CompassHeading methodsFor: #accessing !
trueHeading
	" Return the heading of the receiver.
	The heading relative to the geographic North Pole in degrees 0 - 359.99 at a single moment in time.
	A negative value indicates that the true heading could not be determined. (Number) "

	^handle#trueHeading! !

! CompassHeading methodsFor: #accessing !
headingAccuracy
	" Return the heading accuracy of the receiver.
	The deviation in degrees between the reported heading and the true heading. (Number) "

	^handle#headingAccuracy! !

! CompassHeading methodsFor: #accessing !
timeStamp
	" Return the timeStamp of the receiver.
	The time at which this heading was determined. (milliseconds) "

	^handle#timestamp! !

! Connection class methodsFor: #accessing !
default
	" Return the default/global instance of the receiver. "

	^self @ #{navigator}#connection! !

! Connection methodsFor: #accessing !
type
	" Return the type of the receiver. "

	^handle#type! !

! Contacts class methodsFor: #accessing !
default
	" Return the default/global instance of the receiver. "

	^self @ #{navigator}#contacts! !

! Contacts class methodsFor: #private !
errorCodeTable
	" Private - Return an error code/description table. "

	^#(	#(  0 'Unknown' )
		#(  1 'Invalid argument' )
		#(  2 'Timeout' )
		#(  3 'Pending operation' )
		#(  4 'IO' )
		#(  5 'Not supported' )
		#(  20 'Permission denied' )
	)! !

! Contacts methodsFor: #evaluation !
watchDoing: aBlock onError: errorBlock with: options
	" Private - Evaluate aBlock when async data is obtained from the receiver at regular interval. "

	^self invalidMessage! !

! Contacts methodsFor: #accessing !
valueFromData: data
	" Return the value (anObject)computed from data of the receiver. "

	^data collect: [:each| Contact @ each ]! !

! Contacts methodsFor: #evaluation !
valueDoing: aBlock onError: errorBlock with: options
	" Private - Evaluate aBlock when async data is obtained from the receiver. "

	self handle #find: self fields onSuccess: aBlock onError: errorBlock with: options! !

! Contacts methodsFor: #accessing !
fields
	" Return the fields of the receiver. "

	fields isNil ifTrue: [ self initializeFields ].
	^fields! !

! Contacts methodsFor: #accessing !
fields: anArray
	" Set the fields of the receiver. "

	fields := anArray! !

! Contacts methodsFor: #initialize !
initializeFields
	" Private - Initialize the fields of the receiver. "

	self fields: (Array with: '*') "default will find all fields"! !

! Contacts methodsFor: #creation !
newContact: properties
	" Return a new contact of the receiver. "

	^Contact @ (self handle #create: properties)! !

! Contact methodsFor: #copying !
clone
	" Return a new contact that is a deep copy of the receiver, with id set to null. "

	^self class new @ self handle clone! !

! Contact methodsFor: #copying !
remove
	" Remove the receiver from device database. "

	self handle remove! !

! Contact methodsFor: #copying !
save
	" Save the receiver to device database.
	Saves a new contact to the device contacts database, or updates an existing contact if a contact with the same id already exists. "

	self handle save! !

! Contacts methodsFor: #options !
filter: filter
multiple: multiple
	" Return a set of options for the receiver. "

	| tuples add |
	tuples := Array new.
	add := [:aName :aValue| aValue notNil ifTrue: [
		tuples add: (Array with: aName with: aValue)
		] ].
	add
		value: #filter value: filter;
		value: #multiple value: multiple;
		yourself.
	^self optionsFromArray: tuples! !

! Contacts methodsFor: #accessing !
defaultOptions
	" Return default options to get data with the receiver. "

	^self filter: nil multiple: false! !

! Device class methodsFor: #accessing !
default
	" Return the default/global instance of the receiver. "

	^self @ #{window}#device! !

! Cva8Events class methodsFor: #accessing !
default
	" Return the default/global instance of the receiver. "

	^self @ #{navigator}! !

! Cva8Events class methodsFor: #events !
cva8Events
	" Private - Return the events managed by Cordova. "

	^#(	#deviceReady #deviceready
		#pause #resume
		#online #offline
		#backButton #backbutton
		#menuButton #menubutton
		#searchButton #searchbutton
		#startCallButton #startcallbutton
		#endCallButton #endcallbutton
		#volumeDownButton #volumedownbutton
		#volumeUpButton #volumeupbutton
	)! !

! Cva8Events methodsFor: #private !
whenCordova: anEvent evaluate: anAction
	" Private - Register anAction to the be evaluated when the receiver triggers the event. "

	#{document}
		#addEventListener: anEvent asLowercase
		doing: [ self triggerEvent: anEvent. ]
		useCapture: false! !

! Cva8Events methodsFor: #initialize !
initializeHandle
	" Private - Initialize the native handle. "

	handle := #unused! !

! FileAccessor class methodsFor: #events !
cva8Events
	" Private - Return the events managed by Cordova. "

	^#(	#progress: #progress #onProgress: #onProgress #onprogress
		#abort #onAbort #onabort
		#error #error: #onError: #onError #onerror
	)! !

! FileAccessor methodsFor: #private !
onEventName: anEvent
	" Private - Return the cordova name for onxxx event. "

	| selector |
	selector := (anEvent upTo: $:) asLowercase.
	(selector copyFrom: 1 to: 2) = #on ifFalse: [ ^#on , selector ].
	^selector! !

! FileAccessor methodsFor: #private !
whenCordova: anEvent evaluate: anAction
	" Private - Register anAction to the be evaluated when the receiver triggers the event. "

	| action |
	action := (anEvent includes: $:)
		ifTrue: [ [:argument| self triggerEvent: anEvent with: argument ] ]
		ifFalse: [ [ self triggerEvent: anEvent ] ].
	self handle basicAt: (self onEventName: anEvent) put: action.! !

! FileAccessor methodsFor: #actions !
abort
	" Abort operation. "

	self handle abort! !

! FileReader class methodsFor: #events !
cva8Events
	" Private - Return the events managed by Cordova. "

	^#(	#loadStart: #loadStart #onLoadStart: #onLoadStart #onloadstart
		#load: #load #onLoad: #onLoad #onload
		#loadEnd: #loadEnd #onLoadEnd: #onLoadEnd #onloadend
	), super cva8Events! !

! FileReader methodsFor: #initialize !
initializeHandle
	" Private - Initialize the native handle. "

	handle := {'new FileReader()'}! !

! FileReader methodsFor: #actions !
readAsDataURL: file
	" Start a read operation on file as a data URL encoded. "

	self handle #readAsDataURL: file! !

! FileReader methodsFor: #actions !
readAsText: file
	" Start a read text operation on file. "

	self handle #readAsText: file! !

! FileReader methodsFor: #actions !
readAsText: file encode: encode
	" Start a read text operation on file.
	encoding is the encoding to use to encode the file content.
	Default is UTF8.
	"

	self handle #readAsText: file encode: encode! !

! FileWriter class methodsFor: #events !
cva8Events
	" Private - Return the events managed by Cordova. "

	^#(	#writeStart: #writeStart #onWriteStart: #onWriteStart #onwritestart
		#write: #write #onWrite: #onWrite #onwrite
		#writeEnd: #writeEnd #onWriteEnd: #onWriteEnd #onwriteend
	), super cva8Events! !

! FileWriter methodsFor: #actions !
write: aString
	" Write aString onto destination file. "

	self handle #write: aString! !

! FileWriter methodsFor: #actions !
seek: offset
	" Seek destination file to offset (zero indexed). "

	self handle #seek: offset! !

! FileWriter methodsFor: #actions !
truncate: offset
	" Truncate destination file to offset (zero indexed). "

	self handle #truncate: offset! !

! FileEntity class methodsFor: #accessing !
service
	" Return the (async)service to access instances of the receiver. "

	^self! !

! FileEntity class methodsFor: #services !
with: uri do: aBlock onError: errorBlock
	" Evaluate aBlock with an instance of the receiver, when succeding access.
	Evaluate errorBlock in case on error accessing the resource.
	Return the receiver.
	"

	| action |
	action := [:data| aBlock value: self @ data ].
	#{window} #resolveLocalFileSystemURI: uri
		onSuccess: action
		onError: (self errorBlock: errorBlock)! !

! FileEntity class methodsFor: #services !
with: uri do: aBlock
	" Evaluate aBlock with an instance of the receiver, when succeding access. "

	^self with: uri do: aBlock onError: nil! !

! FileEntity class methodsFor: #private !
errorCodeTable
	" Private - Return an error code/description table. "

	^#(	#(  1 'Entry not found' )
		#(  2 'Security' )
		#(  3 'Abort' )
		#(  4 'Not readable' )
		#(  5 'Encoding' )
		#(  6 'No modification allowed' )
		#(  7 'Invalid state' )
		#(  8 'Syntax' )
		#(  9 'Invalid modification' )
		#( 10 'Quota exceeded' )
		#( 11 'Type mismatch' )
		#( 11 'Path exists' )
	)! !

! FileSystem class methodsFor: #services !
temporaryDo: aBlock onError: errorBlock
	" Evaluate aBlock with an instance of the receiver, when succeding access.
	Evaluate errorBlock in case on error accessing file system.
	Return the receiver.
	"

	self type: 0 do: aBlock onError: errorBlock.! !

! FileSystem class methodsFor: #services !
temporaryDo: aBlock
	" Evaluate aBlock with an instance of the receiver, when succeding access. "

	^self temporaryDo: aBlock onError: nil! !

! FileSystem class methodsFor: #services !
persistentDo: aBlock onError: errorBlock
	" Evaluate aBlock with an instance of the receiver, when succeding access.
	Evaluate errorBlock in case on error accessing file system.
	Return the receiver.
	"

	self type: 1 do: aBlock onError: errorBlock.! !

! FileSystem class methodsFor: #services !
persistentDo: aBlock
	" Evaluate aBlock with an instance of the receiver, when succeding access. "

	^self persistentDo: aBlock onError: nil! !

! FileSystem class methodsFor: #services !
resourceDo: aBlock onError: errorBlock
	" Evaluate aBlock with an instance of the receiver, when succeding access.
	Evaluate errorBlock in case on error accessing file system.
	Return the receiver.
	"

	self type: 2 do: aBlock onError: errorBlock.! !

! FileSystem class methodsFor: #services !
resourceDo: aBlock
	" Evaluate aBlock with an instance of the receiver, when succeding access. "

	^self resourceDo: aBlock onError: nil! !

! FileSystem class methodsFor: #services !
applicationDo: aBlock onError: errorBlock
	" Evaluate aBlock with an instance of the receiver, when succeding access.
	Evaluate errorBlock in case on error accessing file system.
	Return the receiver.
	"

	self type: 3 do: aBlock onError: errorBlock.! !

! FileSystem class methodsFor: #services !
applicationDo: aBlock
	" Evaluate aBlock with an instance of the receiver, when succeding access. "

	^self applicationDo: aBlock onError: nil! !

! FileSystem class methodsFor: #private !
type: aConstant do: aBlock onError: errorBlock
	" Private - Evaluate aBlock with an instance of the receiver, when succeding access. "

	| action |
	action := [:data| aBlock value: self @ data ].
	#{window} #requestFileSystem: aConstant
		requiredSize: 0
		onSuccess: action
		onError: (self errorBlock: errorBlock)! !

! FileSystem methodsFor: #accessing !
root
	" Return the root directory of the receiver. "

	^DirectoryEntry @ handle#root! !

! FileSystemElement class methodsFor: 'instance creation' !
entryFrom: anEntryHandle
	" Return an instance of the receiver. "

	anEntryHandle#isFile == true ifTrue: [ ^FileEntry @ anEntryHandle ].
	anEntryHandle#isDirectory == true ifTrue: [ ^DirectoryEntry @ anEntryHandle ].
	^self error: 'Invalid handle'! !

! FileSystemElement methodsFor: #actions !
withMetadataDo: aBlock onError: errorBlock
	" Evaluate aBlock on metadata of the receiver. "

	| action |
	action := [:data| aBlock value: Metadata @ data ].
	self handle
		#getMetadata: action
		onError: (self errorBlock: errorBlock)! !

! FileSystemElement methodsFor: #actions !
withMetadataDo: aBlock
	" Evaluate aBlock on metadata of the receiver. "

	^self withMetadataDo: aBlock onError: nil! !

! FileSystemElement methodsFor: #actions !
moveTo: parent as: newName doing: aBlock onError: errorBlock
	" Move the receiver to new location. "

	| action target |
	newName notNil
		ifTrue: [ target := newName ]
		ifFalse: [ #{null} ].
	action := [:data| aBlock value: FileEntry @ data ].
	self handle
		#moveTo: parent as: target
		doing: action onError: (self errorBlock: errorBlock)! !

! FileSystemElement methodsFor: #actions !
moveTo: parent as: newName doing: aBlock
	" Move the receiver to new location. "

	^self moveTo: parent as: newName doing: aBlock onError: nil! !

! FileSystemElement methodsFor: #actions !
copyTo: parent as: newName doing: aBlock onError: errorBlock
	" Copy the receiver to new location. "

	| action target |
	newName notNil
		ifTrue: [ target := newName ]
		ifFalse: [ #{null} ].
	action := [:data| aBlock value: FileEntry @ data ].
	self handle
		#copyTo: parent as: target
		doing: action onError: (self errorBlock: errorBlock)! !

! FileSystemElement methodsFor: #actions !
copyTo: parent as: newName doing: aBlock
	" Copy the receiver to new location. "

	^self copyTo: parent as: newName doing: aBlock onError: nil! !

! FileSystemElement methodsFor: #accessing !
uri
	" Return a URI that can be used to locate the receiver. "

	^self handle toURI! !

! FileSystemElement methodsFor: #accessing !
parent
	" Return the parent directory of the receiver. "

	^DirectoryEntry @ self handle getParent! !

! FileEntry methodsFor: #accessing !
withWriterDo: aBlock onError: errorBlock
	" Evaluate aBlock with a FileWriter on the receiver. "

	| action |
	action := [:data| aBlock value: FileWriter @ data ].
	self handle
		#createWriter: action
		onError: (self errorBlock: errorBlock)! !

! FileEntry methodsFor: #accessing !
withWriterDo: aBlock
	" Evaluate aBlock with a FileWriter on the receiver. "

	^self withWriterDo: aBlock onError: nil! !

! FileEntry methodsFor: #accessing !
writerDo: aBlock
	" Evaluate aBlock with a FileWriter on the receiver. "

	^self withWriterDo: aBlock onError: nil! !

! FileEntry methodsFor: #accessing !
withFileDo: aBlock onError: errorBlock
	" Evaluate aBlock with a File on the receiver. "

	| action |
	action := [:data| aBlock value: Cva8File @ data ].
	self handle
		#file: action
		onError: (self errorBlock: errorBlock)! !

! FileEntry methodsFor: #accessing !
withFileDo: aBlock
	" Evaluate aBlock with a File on the receiver. "

	^self withFileDo: aBlock onError: nil! !

! FileEntry methodsFor: #accessing !
fileDo: aBlock
	" Evaluate aBlock with a File on the receiver. "

	^self withFileDo: aBlock onError: nil! !

! FileEntry methodsFor: #accessing !
fileDo: aBlock onError: errorBlock
	" Evaluate aBlock with a File on the receiver. "

	^self withFileDo: aBlock onError: errorBlock! !

! DirectoryEntry methodsFor: #accessing !
removeDoing: aZeroArgumentBlock onError: errorBlock
	" Remove the receiver. "

	self handle
		#remove: aZeroArgumentBlock
		onError: (self errorBlock: errorBlock)! !

! DirectoryEntry methodsFor: #accessing !
removeDoing: aZeroArgumentBlock
	" Remove the receiver. "

	^self removeDoing: aZeroArgumentBlock onError: nil! !

! DirectoryEntry methodsFor: #accessing !
removeRecursivelyDoing: aZeroArgumentBlock onError: errorBlock
	" Delete the receiver and all of its contents.
	In the event of an error (e.g. trying to delete a directory that contains a file that cannot be removed), some of the contents of the directory may be deleted.
	It is an error to attempt to delete the root directory of a filesystem.
	"

	self handle
		#removeRecursively: aZeroArgumentBlock
		onError: (self errorBlock: errorBlock)! !

! DirectoryEntry methodsFor: #accessing !
removeRecursivelyDoing: aZeroArgumentBlock
	" Delete the receiver and all of its contents. "

	^self removeRecursivelyDoing: aZeroArgumentBlock onError: nil! !

! DirectoryEntry methodsFor: #accessing !
reader
	" Return a reader on the receiver. "

	^DirectoryReader @ self handle createReader! !

! DirectoryEntry methodsFor: #accessing !
withDirectory: pathName options: options do: aBlock onError: errorBlock
	" Creates or looks up an existing directory.
	It is an error to attempt to create a directory whose immediate parent does not yet exist.
	pathName is the path to the directory to be looked up or created.
	Either an absolute path, or a relative path from the receiver.
	"

	| action |
	options isArray ifTrue: [
		^self withDirectory: pathName
			options: (options inject: Object new into: [:result :tuple|
				result basicAt: tuple first put: tuple last; yourself
			]) do: aBlock onError: errorBlock
	].
	action := [:data| aBlock value: self class @ data ].
	self handle
		#getDirectory: pathName
		with: (options isNil ifTrue: [#{null}] ifFalse: [options])
		doing: action onError: (self errorBlock: errorBlock)! !

! DirectoryEntry methodsFor: #accessing !
withDirectory: pathName options: options do: aBlock
	" Creates or looks up an existing directory.
	pathName is the path to the directory to be looked up or created.
	Either an absolute path, or a relative path from the receiver.
	"

	^self withDirectory: pathName options: options do: aBlock onError: nil! !

! DirectoryEntry methodsFor: #accessing !
withDirectory: pathName do: aBlock
	" Creates or looks up an existing directory.
	pathName is the path to the directory to be looked up or created.
	Either an absolute path, or a relative path from the receiver.
	"

	^self withDirectory: pathName options: nil do: aBlock onError: nil! !

! DirectoryEntry methodsFor: #accessing !
withFile: pathName options: options do: aBlock onError: errorBlock
	" Creates or looks up a file in the receiver.
	It is an error to attempt to create a file whose immediate parent does not yet exist.
	"

	| action |
	options isArray ifTrue: [
		^self withFile: pathName
			options: (options inject: Object new into: [:result :tuple|
				result basicAt: tuple first put: tuple last; yourself
			]) do: aBlock onError: errorBlock
	].
	action := [:data| aBlock value: FileEntry @ data ].
	self handle
		#getFile: pathName
		with: (options isNil ifTrue: [#{null}] ifFalse: [options])
		doing: action onError: (self errorBlock: errorBlock)! !

! DirectoryEntry methodsFor: #accessing !
withFile: pathName options: options do: aBlock
	" Creates or looks up a file in the receiver. "

	^self withFile: pathName options: options do: aBlock onError: nil! !

! DirectoryEntry methodsFor: #accessing !
withFile: pathName do: aBlock
	" Creates or looks up a file in the receiver. "

	^self withFile: pathName options: nil do: aBlock onError: nil! !

! DirectoryReader methodsFor: #accessing !
entriesDo: aBlock onError: errorBlock
	" Evaluate aBlock for entries in the receiver. "

	| action |
	action := [:entries| aBlock value: (entries collect: [:each| FileSystemElement entryFrom: each ]) ].
	self handle
		#readEntries: action
		onError: (self errorBlock: errorBlock)! !

! DirectoryReader methodsFor: #accessing !
entriesDo: aBlock
	" Evaluate aBlock for entries in the receiver. "

	^self entriesDo: aBlock onError: nil! !

! DirectoryReader methodsFor: #accessing !
withEntriesDo: aBlock
	" Evaluate aBlock for entries in the receiver. "

	^self entriesDo: aBlock onError: nil! !

! FileTransfer methodsFor: #actions !
upload: fileURI to: serverURL doing: aBlock onError: errorBlock options: options
	" Provides a way to upload files to a remote server using an HTTP multi-part POST request.
	Both HTTP and HTTPS protocols are supported.
	Optional parameters can be specified by passing aFileUploadOptions to the upload method.
	On successful upload, aBlock with aFileUploadResult.
	If an error occurs, the errorBlock is evaluated with aFileTransferError.
	"

	| action |
	action := [:data| aBlock value: FileUploadResult @ data ].
	self handle
		#upload: fileURI to: serverURL doing: action
		onError: (self errorBlock: errorBlock)
		options: (self optionsFrom: options)! !

! FileTransfer methodsFor: #actions !
upload: fileURI to: serverURL doing: aBlock onError: errorBlock
	" Provides a way to upload files to a remote server using an HTTP multi-part POST request. "

	^self upload: fileURI to: serverURL doing: aBlock onError: errorBlock options: nil! !

! FileTransfer methodsFor: #actions !
upload: fileURI to: serverURL doing: aBlock options: options
	" Provides a way to upload files to a remote server using an HTTP multi-part POST request. "

	^self upload: fileURI to: serverURL doing: aBlock onError: nil options: options! !

! FileTransfer methodsFor: #actions !
upload: fileURI to: serverURL doing: aBlock
	" Provides a way to upload files to a remote server using an HTTP multi-part POST request. "

	^self upload: fileURI to: serverURL doing: aBlock onError: nil options: nil! !

! FileTransfer class methodsFor: #private !
errorCodeTable
	" Private - Return an error code/description table. "

	^#(
		#(  1 'File not found' )
		#(  2 'Invalid URL' )
		#(  3 'Connection' )
	)! !

! FileTransfer methodsFor: #private !
optionsFrom: options
	" Private - Return a FileUploadOptions from options. "

	options isNil ifTrue: [ ^#{null} ].
	options isArray ifTrue: [ ^(FileUploadOptions fromArray: options) handle ].
	^options! !

! FileUploadOptions class methodsFor: 'instance creation' !
fromArray: options
	" Return an instance of the receiver. "

	^self new initialize: options! !

! FileUploadOptions methodsFor: #initialize !
initializeHandle
	" Private - Initialize the native handle. "

	handle := Object new.! !

! FileUploadOptions methodsFor: #initialize !
initialize: options
	" Private - Initialize the receiver. "

	self set: self handle with: options.! !

! FileUploadOptions methodsFor: #private !
set: anObject with: array
	" Private - Set anObject with tuples in array.
	Return anObject.
	"

	array do: [:tuple|
		anObject
			basicAt: tuple first
			put: (tuple last isArray
				ifTrue: [ self set: Object new with: tuple last ]
				ifFalse: [ tuple last ])
	].
	^anObject! !

! Geolocation class methodsFor: #accessing !
default
	" Return the default/global instance of the receiver. "

	^self @ #{navigator}#geolocation! !

! Geolocation methodsFor: #evaluation !
valueDoing: aBlock onError: errorBlock with: options
	" Private - Evaluate aBlock when async data is obtained from the receiver. "

	self handle #getCurrentPosition: aBlock onError: errorBlock! !

! Geolocation methodsFor: #evaluation !
watchDoing: aBlock onError: errorBlock with: options
	" Private - Evaluate aBlock when async data is obtained from the receiver at regular interval. "

	self handle #watchPosition: aBlock onError: errorBlock with: options! !

! Geolocation methodsFor: #private !
clearID: anId
	" Private - Release internal resource of the receiver. "

	^self handle #clearWatch: anId! !

! Geolocation methodsFor: #accessing !
valueFromData: data
	" Return the value (anObject)computed from data of the receiver. "

	^GeoPosition @ data! !

! Geolocation class methodsFor: #private !
errorCodeTable
	" Private - Return an error code/description table. "

	^#(
		#(  1 'Permission denied' )
		#(  2 'Position unavailable' )
		#(  3 'Timeout' )
	)! !

! Geolocation methodsFor: #accessing !
defaultOptions
	" Return default options to get data with the receiver. "

	^self optionsFromArray: #(
		#( #maximumAge 3000 )
		#( #timeout 5000 )
	),(Array with: (Array with: #enableHighAccuracy with: true))! !

! GeoPosition methodsFor: #accessing !
coordinates
	" Return the geographic coordinates in the receiver. "

	^GeoCoordinates @ handle#coords! !

! GeoPosition methodsFor: #accessing !
coords
	" Return the geographic coordinates in the receiver. "

	^self coordinates! !

! Notification class methodsFor: #accessing !
default
	" Return the default/global instance of the receiver. "

	^self @ #{navigator}#notification! !

! Notification methodsFor: #alert !
alert: message
	" Show a custom alert or dialog box. "

	^self handle #alert: message asString! !

! Notification methodsFor: #alert !
alert: message doing: dissmissAction
	" Show a custom alert or dialog box. "

	^self handle #alert: message asString doing: dissmissAction! !

! Notification methodsFor: #alert !
alert: message doing: dissmissAction title: title buttonName: buttonName
	" Show a custom alert or dialog box. "

	^self handle #alert: message asString doing: dissmissAction title: title buttonName: buttonName! !

! Notification methodsFor: #alert !
alert: message doing: dissmissAction title: title
	" Show a custom alert or dialog box. "

	^self handle #alert: message asString doing: dissmissAction title: title! !

! Notification methodsFor: #alert !
alert: message title: title buttonName: buttonName
	" Show a custom alert or dialog box. "

	^self handle #alert: message asString doing: [] title: title buttonName: buttonName! !

! Notification methodsFor: #alert !
alert: message title: title
	" Show a custom alert or dialog box. "

	^self handle #alert: message asString doing: [] title: title! !

! Notification methodsFor: #confirmation !
confirm: message doing: oneArgumentBlock title: title buttonNames: buttonNames
	" Show a custom confirmation dialog box. "

	^self handle #confirm: message doing: oneArgumentBlock title: title buttonNames: buttonNames! !

! Notification methodsFor: #confirmation !
confirm: message doing: oneArgumentBlock title: title
	" Show a custom confirmation dialog box. "

	^self handle #confirm: message doing: oneArgumentBlock title: title! !

! Notification methodsFor: #confirmation !
confirm: message doing: oneArgumentBlock
	" Show a custom confirmation dialog box. "

	^self handle #confirm: message doing: oneArgumentBlock! !

! Notification methodsFor: #beep !
beep: times
	" The device will play beep sound. "

	^self handle #beep: times! !

! Notification methodsFor: #beep !
beep
	" The device will play beep sound. "

	^self beep: 1! !

! Notification methodsFor: #vibration !
vibrate: milliseconds
	" Vibrates the device for the specified amount of time. "

	^self handle #vibrate: milliseconds! !

! Notification methodsFor: #vibration !
vibrate
	" Vibrates the device during 1 second. "

	^self vibrate: 1000! !

! Cva8DataBase class methodsFor: #open !
open: name version: version displayName: displayName size: size
	" Return an instance of the receiver "

	^self @ (#{window} #openDatabase: name version: version displayName: displayName size: size)! !

! Cva8DataBase methodsFor: #database !
changeVersion: from to: to
	" Change the version of the receiver "

	self handle #changeVersion: from to: to! !

! Cva8DataBase methodsFor: #evaluation !
valueDoing: aBlock onError: errorBlock with: options
	" Private - Evaluate aBlock when async data is obtained from the receiver. "

	self handle
		#transaction: aBlock
		 onError: (self errorBlock: errorBlock)
		 onSuccess: (self optionsFrom: options)! !

! Cva8DataBase methodsFor: #evaluation !
transaction: aBlock onError: errorBlock
	" Evaluate aBlock to execute a transaction in the receiver. "

	^self do: aBlock onError: errorBlock! !

! Cva8DataBase methodsFor: #accessing !
defaultOptions
	" Return default options to get data with the receiver.
	The default implementation return an ignore success block"

	^[ "success ignored" ]! !

! Cva8DataBase methodsFor: #accessing !
valueFromData: data
	" Return the value (anObject)computed from data of the receiver. "

	^Cva8SQLTransaction @ data! !

! Cva8SQLTransaction methodsFor: #evaluation !
executeSql: sqlString parameters: parameters onResult: aBlock onError: errorBlock
	" Execute the SQL string in the receiver. "

	^self handle #executeSql: sqlString
		parameters: parameters
		success: [:tx :data | aBlock value: (self valueFromData: data) ]
		onError: (self errorBlock: errorBlock)! !

! Cva8SQLTransaction methodsFor: #evaluation !
executeSql: sqlString
	" Execute the SQL string in the receiver. "

	^self	executeSql: sqlString parameters: #()
		onResult: [:ignored| ] onError: nil! !

! Cva8SQLTransaction methodsFor: #evaluation !
execute: sqlString
	" Execute the SQL string in the receiver. "

	^self executeSql: sqlString! !

! Cva8SQLTransaction methodsFor: #evaluation !
, sqlString
	" Execute the SQL string in the receiver. "

	^self executeSql: sqlString! !

! Cva8SQLTransaction methodsFor: #evaluation !
executeAll: sqlStrings
	" Execute the SQL strings in the receiver. "

	sqlStrings do: [:each| self execute: each ]! !

! Cva8SQLTransaction class methodsFor: #private !
errorCodeTable
	" Private - Return an error code/description table. "

	^#(
		#(  0 'Internal' )
		#(  1 'Version' )
		#(  2 'Too large' )
		#(  3 'Quota' )
		#(  4 'Syntax' )
		#(  5 'Constraint' )
		#(  6 'Timeout' )
	)! !

! Cva8SQLTransaction methodsFor: #accessing !
valueFromData: data
	" Return the value (anObject)computed from data of the receiver. "

	^Cva8SQLResultSet @ data! !

! Cva8SQLResultSet methodsFor: #private !
rowsDo: aBlock
	" Evaluate aBlock with the rows of results in the receiver.
	Return a collection with the results of evaluation.
	"

	| rows |
	rows := handle#rows.
	^rows notNil ifTrue: [
		(0 to: rows#length - 1) collect: [:index|
			aBlock evaluateWith: (rows #item: index)
		]
	]! !

! Cva8SQLResultSet methodsFor: #private !
rows
	" Return a collection with the results of evaluation of the receiver. "

	^self rowsDo: [:row| row ]! !

! Cva8LocalStorage class methodsFor: #accessing !
default
	" Return the default/global instance of the receiver. "

	^self @ #{window}#localStorage! !

! Cva8LocalStorage methodsFor: #accessing !
key: offset
	" Return the name of the key at the position specified. "

	^self handle #key: offset! !

! Cva8LocalStorage methodsFor: #accessing !
keyAt: index
	" Return the name of the key at index (ONE indexed). "

	^self key: index - 1! !

! Cva8LocalStorage methodsFor: #accessing !
keysDo: aBlock
	" Evaluate aBlock with the keys of the receiver. "

	| key index |
	index := 0.
	[	key := self key: index.
		key notNil ] whileTrue: [
		aBlock value: key.
		index := index + 1.
	]! !

! Cva8LocalStorage methodsFor: #accessing !
keys
	" Return the keys of the receiver. "

	| result |
	result := Array new.
	self keysDo: [:each| result add: each ].
	^result! !

! Cva8LocalStorage methodsFor: #accessing !
isEmpty
	" Return true if the receiver is empty. "

	self keysDo: [:each| ^false ].
	^true! !

! Cva8LocalStorage methodsFor: #accessing !
notEmpty
	" Return true if the receiver has at least one key. "

	^self isEmpty not! !

! Cva8LocalStorage methodsFor: #accessing !
do: aBlock
	" Evaluate aBlock with all values in the receiver. "

	self keysDo: [:key| aBlock value: (self at: key) ]! !

! Cva8LocalStorage methodsFor: #accessing !
associationsDo: aBlock
	" Evaluate aBlock with all key/value associations in the receiver. "

	self keysDo: [:key| aBlock value: (Association key: key value: (self at: key)) ]! !

! Cva8LocalStorage methodsFor: #accessing !
at: key
	" Return the value at key. "

	^self handle #getItem: key! !

! Cva8LocalStorage methodsFor: #accessing !
at: key put: value
	" Set the value at key. "

	^self handle #setItem: key value: value! !

! Cva8LocalStorage methodsFor: #accessing !
remove: key
	" Remove the value at key. "

	^self handle #removeItem: key! !

! Cva8LocalStorage methodsFor: #reset !
clear
	" Clear the receiver's contents. "

	^self handle clear! !

! Cva8App class methodsFor: #accessing !
default
	" Return the default/global instance of the receiver. "

	^self @ #{cordova}! !

! Cva8App methodsFor: #exec !
exec: success fail: fail service: service action: action args: args
	" Execute the request. "

	^self handle
		#exec: (self asJson: success)
		 fail: (self asJson: fail)
		 service: (self asJson: service)
		 action: (self asJson: action)
		 args: args! !

! Cva8App methodsFor: #exec !
action: action args: args

	^self exec: nil fail: nil service: #App action: action args: args! !

! Cva8App methodsFor: #exec !
action: action

	^self action: action args: #()! !

! Cva8App methodsFor: #actions !
clearCache

	^self action: #clearCache! !

! Cva8App methodsFor: #actions !
loadUrl: url options: options

	^self action: #loadUrl args: (Array with: url with: options)! !

! Cva8App methodsFor: #actions !
loadUrl: url

	^self action: #loadUrl args: (Array with: url)! !

! Cva8App methodsFor: #actions !
cancelLoadUrl

	^self action: #cancelLoadUrl! !

! Cva8App methodsFor: #actions !
clearHistory

	^self action: #clearHistory! !

! Cva8App methodsFor: #actions !
backHistory

	^self action: #backHistory! !

! Cva8App methodsFor: #actions !
exit

	^self action: #exitApp! !

! Cva8App methodsFor: #actions !
overrideBackbutton: aBoolean

	^self action: #overrideBackbutton args: (Array with: aBoolean)! !

EventManager
 subclass: #CordovaPlugin
 instanceVariableNames: ' '
 classVariableNames: ' '
 category: #Cordova!
CordovaPlugin comment: '
	Abstract implementation of interface to cordova plugin.
	@2014 Alejandro Reimondo - aleReimondo@smalltalking.net
'!

! CordovaPlugin class methodsFor: #events !
constructEventsTriggered
	" Private - Return the events managed by instances of the receiver. "

	^#(	#success: #success #error:
	) , super constructEventsTriggered! !

! CordovaPlugin methodsFor: #notifications !
succeeded: action with: arg
	" Private - Execution succeeded. "

	^self
		triggerEvent: #success: with: arg
		ifNotHandled: [ self triggerEvent: #success ]! !

! CordovaPlugin methodsFor: #notifications !
failed: action with: arg
	" Private - Execution failed. "

	^self
		triggerEvent: #error: with: arg
		ifNotHandled: [ self error: arg ]! !

! CordovaPlugin methodsFor: #services !
service
	" Private - Return the service string. "

	^self implementedBySubclass: #service! !

! CordovaPlugin methodsFor: #evaluating !
evaluate: action withArguments: anArray
	" Return the result of evaluating the action on service with arguments anArray. "

	^Cordova
		exec: [:arg| self succeeded: action with: arg ]
		fail: [:err| self failed: action with: err ]
		service: self service action: action
		args: anArray! !