CB-9745 Camera plugin docs should be generated from the source
Moved docs to jsdocs comments in the code, removed redundancy. Moved Quirks and extra examples to errata sections of the docs TEMPLATE.md, linked the jsdoc comments to these sections. Added dependencies to common plugin docs template and husky (precommit hook to regen the docs automatically). Added gen-docs command to re-generate the docs. Extended TOC manually [to include classes containing only one member](https://github.com/jsdoc2md/jsdoc-to-markdown/issues/34) (CameraPopoverHandle and CameraPopoverOptions). Extended the docs via DMD template to include "Installation", "How to contribute" and "Docs are generated" warning. github: close #129
This commit is contained in:
parent
454a6f518c
commit
f20dfae735
10
.gitignore
vendored
10
.gitignore
vendored
@ -12,12 +12,4 @@ Thumbs.db
|
||||
*.swp
|
||||
*.user
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/node_modules/**
|
||||
|
456
README.md
456
README.md
@ -29,73 +29,244 @@ Although the object is attached to the global scoped `navigator`, it is not avai
|
||||
console.log(navigator.camera);
|
||||
}
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
This requires cordova 5.0+
|
||||
|
||||
cordova plugin add cordova-plugin-camera
|
||||
Older versions of cordova can still install via the __deprecated__ id
|
||||
|
||||
## API
|
||||
- Camera
|
||||
- navigator.camera.getPicture(success, fail, options)
|
||||
- CameraOptions
|
||||
- CameraPopoverHandle
|
||||
- CameraPopoverOptions
|
||||
- navigator.camera.cleanup
|
||||
cordova plugin add org.apache.cordova.camera
|
||||
It is also possible to install via repo url directly ( unstable )
|
||||
|
||||
cordova plugin add https://github.com/apache/cordova-plugin-camera.git
|
||||
|
||||
|
||||
## How to Contribute
|
||||
|
||||
## navigator.camera.getPicture
|
||||
Contributors are welcome! And we need your contributions to keep the project moving forward. You can [report bugs](https://issues.apache.org/jira/issues/?jql=project%20%3D%20CB%20AND%20status%20in%20(Open%2C%20%22In%20Progress%22%2C%20Reopened)%20AND%20resolution%20%3D%20Unresolved%20AND%20component%20%3D%20%22Plugin%20Camera%22%20ORDER%20BY%20priority%20DESC%2C%20summary%20ASC%2C%20updatedDate%20DESC), improve the documentation, or [contribute code](https://github.com/apache/cordova-plugin-camera/pulls).
|
||||
|
||||
Takes a photo using the camera, or retrieves a photo from the device's
|
||||
image gallery. The image is passed to the success callback as a
|
||||
base64-encoded `String`, or as the URI for the image file. The method
|
||||
itself returns a `CameraPopoverHandle` object that can be used to
|
||||
reposition the file selection popover.
|
||||
There is a specific [contributor workflow](http://wiki.apache.org/cordova/ContributorWorkflow) we recommend. Start reading there. More information is available on [our wiki](http://wiki.apache.org/cordova).
|
||||
|
||||
navigator.camera.getPicture(cameraSuccess, cameraError, cameraOptions);
|
||||
:warning: **Found an issue?** File it on [JIRA issue tracker](https://issues.apache.org/jira/issues/?jql=project%20%3D%20CB%20AND%20status%20in%20(Open%2C%20%22In%20Progress%22%2C%20Reopened)%20AND%20resolution%20%3D%20Unresolved%20AND%20component%20%3D%20%22Plugin%20Camera%22%20ORDER%20BY%20priority%20DESC%2C%20summary%20ASC%2C%20updatedDate%20DESC).
|
||||
|
||||
#### Description
|
||||
**Have a solution?** Send a [Pull Request](https://github.com/apache/cordova-plugin-camera/pulls).
|
||||
|
||||
The `camera.getPicture` function opens the device's default camera
|
||||
application that allows users to snap pictures. This behavior occurs
|
||||
by default, when `Camera.sourceType` equals
|
||||
`Camera.PictureSourceType.CAMERA`. Once the user snaps the photo, the
|
||||
camera application closes and the application is restored.
|
||||
In order for your changes to be accepted, you need to sign and submit an Apache [ICLA](http://www.apache.org/licenses/#clas) (Individual Contributor License Agreement). Then your name will appear on the list of CLAs signed by [non-committers](https://people.apache.org/committer-index.html#unlistedclas) or [Cordova committers](http://people.apache.org/committers-by-project.html#cordova).
|
||||
|
||||
If `Camera.sourceType` is `Camera.PictureSourceType.PHOTOLIBRARY` or
|
||||
`Camera.PictureSourceType.SAVEDPHOTOALBUM`, then a dialog displays
|
||||
that allows users to select an existing image. The
|
||||
`camera.getPicture` function returns a `CameraPopoverHandle` object,
|
||||
which can be used to reposition the image selection dialog, for
|
||||
example, when the device orientation changes.
|
||||
**And don't forget to test and document your code.**
|
||||
|
||||
The return value is sent to the `cameraSuccess` callback function, in
|
||||
one of the following formats, depending on the specified
|
||||
`cameraOptions`:
|
||||
|
||||
- A `String` containing the base64-encoded photo image.
|
||||
## This documentation is generated by a tool
|
||||
|
||||
- A `String` representing the image file location on local storage (default).
|
||||
:warning: Run `npm install` in the plugin repo to enable automatic docs generation if you plan to send a PR.
|
||||
[jsdoc-to-markdown](https://www.npmjs.com/package/jsdoc-to-markdown) is used to generate the docs.
|
||||
Documentation consists of template and API docs produced from the plugin JS code and should be regenerated before each commit (done automatically via [husky](https://github.com/typicode/husky), running `npm run gen-docs` script as a `precommit` hook - see `package.json` for details).
|
||||
|
||||
You can do whatever you want with the encoded image or URI, for
|
||||
example:
|
||||
|
||||
- Render the image in an `<img>` tag, as in the example below
|
||||
---
|
||||
|
||||
- Save the data locally (`LocalStorage`, [Lawnchair](http://brianleroux.github.com/lawnchair/), etc.)
|
||||
# API Reference
|
||||
|
||||
- Post the data to a remote server
|
||||
|
||||
__NOTE__: Photo resolution on newer devices is quite good. Photos
|
||||
selected from the device's gallery are not downscaled to a lower
|
||||
quality, even if a `quality` parameter is specified. To avoid common
|
||||
memory problems, set `Camera.destinationType` to `FILE_URI` rather
|
||||
than `DATA_URL`.
|
||||
* [camera](#module_camera)
|
||||
* [.getPicture(successCallback, errorCallback, options)](#module_camera.getPicture)
|
||||
* [.cleanup()](#module_camera.cleanup)
|
||||
* [.onError](#module_camera.onError) : <code>function</code>
|
||||
* [.onSuccess](#module_camera.onSuccess) : <code>function</code>
|
||||
* [.CameraOptions](#module_camera.CameraOptions) : <code>Object</code>
|
||||
|
||||
#### Supported Platforms
|
||||
|
||||
        
|
||||
* [Camera](#module_Camera)
|
||||
* [.DestinationType](#module_Camera.DestinationType) : <code>enum</code>
|
||||
* [.EncodingType](#module_Camera.EncodingType) : <code>enum</code>
|
||||
* [.MediaType](#module_Camera.MediaType) : <code>enum</code>
|
||||
* [.PictureSourceType](#module_Camera.PictureSourceType) : <code>enum</code>
|
||||
* [.PopoverArrowDirection](#module_Camera.PopoverArrowDirection) : <code>enum</code>
|
||||
* [.Direction](#module_Camera.Direction) : <code>enum</code>
|
||||
|
||||
#### Example
|
||||
* [CameraPopoverHandle](#module_CameraPopoverHandle)
|
||||
* [CameraPopoverOptions](#module_CameraPopoverOptions)
|
||||
|
||||
---
|
||||
|
||||
<a name="module_camera"></a>
|
||||
## camera
|
||||
<a name="module_camera.getPicture"></a>
|
||||
### camera.getPicture(successCallback, errorCallback, options)
|
||||
Takes a photo using the camera, or retrieves a photo from the device's
image gallery. The image is passed to the success callback as a
base64-encoded `String`, or as the URI for the image file.
The `camera.getPicture` function opens the device's default camera
application that allows users to snap pictures by default - this behavior occurs,
when `Camera.sourceType` equals [`Camera.PictureSourceType.CAMERA`](#module_Camera.PictureSourceType).
Once the user snaps the photo, the camera application closes and the application is restored.
If `Camera.sourceType` is `Camera.PictureSourceType.PHOTOLIBRARY` or
`Camera.PictureSourceType.SAVEDPHOTOALBUM`, then a dialog displays
that allows users to select an existing image. The
`camera.getPicture` function returns a [`CameraPopoverHandle`](#module_CameraPopoverHandle) object,
which can be used to reposition the image selection dialog, for
example, when the device orientation changes.
The return value is sent to the [`cameraSuccess`](#module_camera.onSuccess) callback function, in
one of the following formats, depending on the specified
`cameraOptions`:
- A `String` containing the base64-encoded photo image.
- A `String` representing the image file location on local storage (default).
You can do whatever you want with the encoded image or URI, for
example:
- Render the image in an `<img>` tag, as in the example below
- Save the data locally (`LocalStorage`, [Lawnchair](http://brianleroux.github.com/lawnchair/), etc.)
- Post the data to a remote server
__NOTE__: Photo resolution on newer devices is quite good. Photos
selected from the device's gallery are not downscaled to a lower
quality, even if a `quality` parameter is specified. To avoid common
memory problems, set `Camera.destinationType` to `FILE_URI` rather
than `DATA_URL`.
__Supported Platforms__
        
* [More examples](#camera-getPicture-examples)
* [Quirks](#camera-getPicture-quirks)
|
||||
|
||||
**Kind**: static method of <code>[camera](#module_camera)</code>
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| successCallback | <code>[onSuccess](#module_camera.onSuccess)</code> | |
|
||||
| errorCallback | <code>[onError](#module_camera.onError)</code> | |
|
||||
| options | <code>[CameraOptions](#module_camera.CameraOptions)</code> | CameraOptions |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
navigator.camera.getPicture(cameraSuccess, cameraError, cameraOptions);
|
||||
```
|
||||
<a name="module_camera.cleanup"></a>
|
||||
### camera.cleanup()
|
||||
Removes intermediate image files that are kept in temporary storage
after calling [`camera.getPicture`](#module_camera.getPicture). Applies only when the value of
`Camera.sourceType` equals `Camera.PictureSourceType.CAMERA` and the
`Camera.destinationType` equals `Camera.DestinationType.FILE_URI`.
__Supported Platforms__
        
|
||||
|
||||
**Kind**: static method of <code>[camera](#module_camera)</code>
|
||||
**Example**
|
||||
```js
|
||||
navigator.camera.cleanup(onSuccess, onFail);
function onSuccess() {
console.log("Camera cleanup success.")
}
function onFail(message) {
alert('Failed because: ' + message);
}
|
||||
```
|
||||
<a name="module_camera.onError"></a>
|
||||
### camera.onError : <code>function</code>
|
||||
Callback function that provides an error message.
|
||||
|
||||
**Kind**: static typedef of <code>[camera](#module_camera)</code>
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| message | <code>string</code> | The message is provided by the device's native code. |
|
||||
|
||||
<a name="module_camera.onSuccess"></a>
|
||||
### camera.onSuccess : <code>function</code>
|
||||
Callback function that provides the image data.
|
||||
|
||||
**Kind**: static typedef of <code>[camera](#module_camera)</code>
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| imageData | <code>string</code> | Base64 encoding of the image data, _or_ the image file URI, depending on [`cameraOptions`](#module_camera.CameraOptions) in effect. |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
// Show image
//
function cameraCallback(imageData) {
var image = document.getElementById('myImage');
image.src = "data:image/jpeg;base64," + imageData;
}
|
||||
```
|
||||
<a name="module_camera.CameraOptions"></a>
|
||||
### camera.CameraOptions : <code>Object</code>
|
||||
Optional parameters to customize the camera settings.
* [Quirks](#CameraOptions-quirks)
|
||||
|
||||
**Kind**: static typedef of <code>[camera](#module_camera)</code>
|
||||
**Properties**
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| quality | <code>number</code> | <code>50</code> | Quality of the saved image, expressed as a range of 0-100, where 100 is typically full resolution with no loss from file compression. (Note that information about the camera's resolution is unavailable.) |
|
||||
| destinationType | <code>[DestinationType](#module_Camera.DestinationType)</code> | <code>FILE_URI</code> | Choose the format of the return value. |
|
||||
| sourceType | <code>[PictureSourceType](#module_Camera.PictureSourceType)</code> | <code>CAMERA</code> | Set the source of the picture. |
|
||||
| allowEdit | <code>Boolean</code> | <code>true</code> | Allow simple editing of image before selection. |
|
||||
| encodingType | <code>[EncodingType](#module_Camera.EncodingType)</code> | <code>JPEG</code> | Choose the returned image file's encoding. |
|
||||
| targetWidth | <code>number</code> | | Width in pixels to scale image. Must be used with `targetHeight`. Aspect ratio remains constant. |
|
||||
| targetHeight | <code>number</code> | | Height in pixels to scale image. Must be used with `targetWidth`. Aspect ratio remains constant. |
|
||||
| mediaType | <code>[MediaType](#module_Camera.MediaType)</code> | <code>PICTURE</code> | Set the type of media to select from. Only works when `PictureSourceType` is `PHOTOLIBRARY` or `SAVEDPHOTOALBUM`. |
|
||||
| correctOrientation | <code>Boolean</code> | | Rotate the image to correct for the orientation of the device during capture. |
|
||||
| saveToPhotoAlbum | <code>Boolean</code> | | Save the image to the photo album on the device after capture. |
|
||||
| popoverOptions | <code>[CameraPopoverOptions](#module_CameraPopoverOptions)</code> | | iOS-only options that specify popover location in iPad. |
|
||||
| cameraDirection | <code>[Direction](#module_Camera.Direction)</code> | <code>BACK</code> | Choose the camera to use (front- or back-facing). |
|
||||
|
||||
---
|
||||
|
||||
<a name="module_Camera"></a>
|
||||
## Camera
|
||||
<a name="module_Camera.DestinationType"></a>
|
||||
### Camera.DestinationType : <code>enum</code>
|
||||
**Kind**: static enum property of <code>[Camera](#module_Camera)</code>
|
||||
**Properties**
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| DATA_URL | <code>number</code> | <code>0</code> | Return base64 encoded string |
|
||||
| FILE_URI | <code>number</code> | <code>1</code> | Return file uri (content://media/external/images/media/2 for Android) |
|
||||
| NATIVE_URI | <code>number</code> | <code>2</code> | Return native uri (eg. asset-library://... for iOS) |
|
||||
|
||||
<a name="module_Camera.EncodingType"></a>
|
||||
### Camera.EncodingType : <code>enum</code>
|
||||
**Kind**: static enum property of <code>[Camera](#module_Camera)</code>
|
||||
**Properties**
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| JPEG | <code>number</code> | <code>0</code> | Return JPEG encoded image |
|
||||
| PNG | <code>number</code> | <code>1</code> | Return PNG encoded image |
|
||||
|
||||
<a name="module_Camera.MediaType"></a>
|
||||
### Camera.MediaType : <code>enum</code>
|
||||
**Kind**: static enum property of <code>[Camera](#module_Camera)</code>
|
||||
**Properties**
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| PICTURE | <code>number</code> | <code>0</code> | Allow selection of still pictures only. DEFAULT. Will return format specified via DestinationType |
|
||||
| VIDEO | <code>number</code> | <code>1</code> | Allow selection of video only, ONLY RETURNS URL |
|
||||
| ALLMEDIA | <code>number</code> | <code>2</code> | Allow selection from all media types |
|
||||
|
||||
<a name="module_Camera.PictureSourceType"></a>
|
||||
### Camera.PictureSourceType : <code>enum</code>
|
||||
**Kind**: static enum property of <code>[Camera](#module_Camera)</code>
|
||||
**Properties**
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| PHOTOLIBRARY | <code>number</code> | <code>0</code> | Choose image from picture library (same as SAVEDPHOTOALBUM for Android) |
|
||||
| CAMERA | <code>number</code> | <code>1</code> | Take picture from camera |
|
||||
| SAVEDPHOTOALBUM | <code>number</code> | <code>2</code> | Choose image from picture library (same as PHOTOLIBRARY for Android) |
|
||||
|
||||
<a name="module_Camera.PopoverArrowDirection"></a>
|
||||
### Camera.PopoverArrowDirection : <code>enum</code>
|
||||
Matches iOS UIPopoverArrowDirection constants to specify arrow location on popover.
|
||||
|
||||
**Kind**: static enum property of <code>[Camera](#module_Camera)</code>
|
||||
**Properties**
|
||||
|
||||
| Name | Type | Default |
|
||||
| --- | --- | --- |
|
||||
| ARROW_UP | <code>number</code> | <code>1</code> |
|
||||
| ARROW_DOWN | <code>number</code> | <code>2</code> |
|
||||
| ARROW_LEFT | <code>number</code> | <code>4</code> |
|
||||
| ARROW_RIGHT | <code>number</code> | <code>8</code> |
|
||||
| ARROW_ANY | <code>number</code> | <code>15</code> |
|
||||
|
||||
<a name="module_Camera.Direction"></a>
|
||||
### Camera.Direction : <code>enum</code>
|
||||
**Kind**: static enum property of <code>[Camera](#module_Camera)</code>
|
||||
**Properties**
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| BACK | <code>number</code> | <code>0</code> | Use the back-facing camera |
|
||||
| FRONT | <code>number</code> | <code>1</code> | Use the front-facing camera |
|
||||
|
||||
---
|
||||
|
||||
<a name="module_CameraPopoverOptions"></a>
|
||||
## CameraPopoverOptions
|
||||
iOS-only parameters that specify the anchor element location and arrow
direction of the popover when selecting images from an iPad's library
or album.
Note that the size of the popover may change to adjust to the
direction of the arrow and orientation of the screen. Make sure to
account for orientation changes when specifying the anchor element
location.
|
||||
|
||||
|
||||
| Param | Type | Default | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| [x] | <code>Number</code> | <code>0</code> | x pixel coordinate of screen element onto which to anchor the popover. |
|
||||
| [y] | <code>Number</code> | <code>32</code> | y pixel coordinate of screen element onto which to anchor the popover. |
|
||||
| [width] | <code>Number</code> | <code>320</code> | width, in pixels, of the screen element onto which to anchor the popover. |
|
||||
| [height] | <code>Number</code> | <code>480</code> | height, in pixels, of the screen element onto which to anchor the popover. |
|
||||
| [arrowDir] | <code>[PopoverArrowDirection](#module_Camera.PopoverArrowDirection)</code> | <code>ARROW_ANY</code> | Direction the arrow on the popover should point. |
|
||||
|
||||
---
|
||||
|
||||
<a name="module_CameraPopoverHandle"></a>
|
||||
## CameraPopoverHandle
|
||||
A handle to an image picker popover.
__Supported Platforms__
        
|
||||
|
||||
**Example**
|
||||
```js
|
||||
var cameraPopoverHandle = navigator.camera.getPicture(onSuccess, onFail,
{
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
popoverOptions: new CameraPopoverOptions(300, 300, 100, 100, Camera.PopoverArrowDirection.ARROW_ANY)
});
// Reposition the popover if the orientation changes.
window.onorientationchange = function() {
var cameraPopoverOptions = new CameraPopoverOptions(0, 0, 100, 100, Camera.PopoverArrowDirection.ARROW_ANY);
cameraPopoverHandle.setPosition(cameraPopoverOptions);
}
|
||||
```
|
||||
---
|
||||
|
||||
|
||||
## `camera.getPicture` Errata
|
||||
|
||||
#### Example <a name="camera-getPicture-examples"></a>
|
||||
|
||||
Take a photo and retrieve it as a base64-encoded image:
|
||||
|
||||
@ -132,7 +303,7 @@ Take a photo and retrieve the image's file location:
|
||||
|
||||
<preference name="CameraUsesGeolocation" value="false" />
|
||||
|
||||
#### Amazon Fire OS Quirks
|
||||
#### Amazon Fire OS Quirks <a name="camera-getPicture-quirks"></a>
|
||||
|
||||
Amazon Fire OS uses intents to launch the camera activity on the device to capture
|
||||
images, and on phones with low memory, the Cordova activity may be killed. In this
|
||||
@ -174,71 +345,8 @@ Tizen only supports a `destinationType` of
|
||||
`Camera.DestinationType.FILE_URI` and a `sourceType` of
|
||||
`Camera.PictureSourceType.PHOTOLIBRARY`.
|
||||
|
||||
## CameraOptions
|
||||
|
||||
Optional parameters to customize the camera settings.
|
||||
|
||||
{ quality : 75,
|
||||
destinationType : Camera.DestinationType.DATA_URL,
|
||||
sourceType : Camera.PictureSourceType.CAMERA,
|
||||
allowEdit : true,
|
||||
encodingType: Camera.EncodingType.JPEG,
|
||||
targetWidth: 100,
|
||||
targetHeight: 100,
|
||||
popoverOptions: CameraPopoverOptions,
|
||||
saveToPhotoAlbum: false };
|
||||
|
||||
- __quality__: Quality of the saved image, expressed as a range of 0-100, where 100 is typically full resolution with no loss from file compression. The default is 50. _(Number)_ (Note that information about the camera's resolution is unavailable.)
|
||||
|
||||
- __destinationType__: Choose the format of the return value. The default is FILE_URI. Defined in `navigator.camera.DestinationType` _(Number)_
|
||||
|
||||
Camera.DestinationType = {
|
||||
DATA_URL : 0, // Return image as base64-encoded string
|
||||
FILE_URI : 1, // Return image file URI
|
||||
NATIVE_URI : 2 // Return image native URI (e.g., assets-library:// on iOS or content:// on Android)
|
||||
};
|
||||
|
||||
- __sourceType__: Set the source of the picture. The default is CAMERA. Defined in `navigator.camera.PictureSourceType` _(Number)_
|
||||
|
||||
Camera.PictureSourceType = {
|
||||
PHOTOLIBRARY : 0,
|
||||
CAMERA : 1,
|
||||
SAVEDPHOTOALBUM : 2
|
||||
};
|
||||
|
||||
- __allowEdit__: Allow simple editing of image before selection. _(Boolean)_
|
||||
|
||||
- __encodingType__: Choose the returned image file's encoding. Default is JPEG. Defined in `navigator.camera.EncodingType` _(Number)_
|
||||
|
||||
Camera.EncodingType = {
|
||||
JPEG : 0, // Return JPEG encoded image
|
||||
PNG : 1 // Return PNG encoded image
|
||||
};
|
||||
|
||||
- __targetWidth__: Width in pixels to scale image. Must be used with __targetHeight__. Aspect ratio remains constant. _(Number)_
|
||||
|
||||
- __targetHeight__: Height in pixels to scale image. Must be used with __targetWidth__. Aspect ratio remains constant. _(Number)_
|
||||
|
||||
- __mediaType__: Set the type of media to select from. Only works when `PictureSourceType` is `PHOTOLIBRARY` or `SAVEDPHOTOALBUM`. Defined in `nagivator.camera.MediaType` _(Number)_
|
||||
|
||||
Camera.MediaType = {
|
||||
PICTURE: 0, // allow selection of still pictures only. DEFAULT. Will return format specified via DestinationType
|
||||
VIDEO: 1, // allow selection of video only, WILL ALWAYS RETURN FILE_URI
|
||||
ALLMEDIA : 2 // allow selection from all media types
|
||||
};
|
||||
|
||||
- __correctOrientation__: Rotate the image to correct for the orientation of the device during capture. _(Boolean)_
|
||||
|
||||
- __saveToPhotoAlbum__: Save the image to the photo album on the device after capture. _(Boolean)_
|
||||
|
||||
- __popoverOptions__: iOS-only options that specify popover location in iPad. Defined in `CameraPopoverOptions`.
|
||||
|
||||
- __cameraDirection__: Choose the camera to use (front- or back-facing). The default is BACK. Defined in `navigator.camera.Direction` _(Number)_
|
||||
|
||||
Camera.Direction = {
|
||||
BACK : 0, // Use the back-facing camera
|
||||
FRONT : 1 // Use the front-facing camera
|
||||
};
|
||||
## `CameraOptions` Errata <a name="CameraOptions-quirks"></a>
|
||||
|
||||
#### Amazon Fire OS Quirks
|
||||
|
||||
@ -311,133 +419,3 @@ with the Google Plus Photos application. Other crops may not work.
|
||||
You may also comment or up-vote the related issue in the [issue tracker](https://issues.apache.org/jira/browse/CB-2083)
|
||||
|
||||
- Ignores the `mediaType` property of `cameraOptions` as the Windows Phone SDK does not provide a way to choose videos from PHOTOLIBRARY.
|
||||
|
||||
|
||||
## CameraError
|
||||
|
||||
onError callback function that provides an error message.
|
||||
|
||||
function(message) {
|
||||
// Show a helpful message
|
||||
}
|
||||
|
||||
#### Description
|
||||
|
||||
- __message__: The message is provided by the device's native code. _(String)_
|
||||
|
||||
|
||||
## cameraSuccess
|
||||
|
||||
onSuccess callback function that provides the image data.
|
||||
|
||||
function(imageData) {
|
||||
// Do something with the image
|
||||
}
|
||||
|
||||
#### Description
|
||||
|
||||
- __imageData__: Base64 encoding of the image data, _or_ the image file URI, depending on `cameraOptions` in effect. _(String)_
|
||||
|
||||
#### Example
|
||||
|
||||
// Show image
|
||||
//
|
||||
function cameraCallback(imageData) {
|
||||
var image = document.getElementById('myImage');
|
||||
image.src = "data:image/jpeg;base64," + imageData;
|
||||
}
|
||||
|
||||
|
||||
## CameraPopoverHandle
|
||||
|
||||
A handle to the popover dialog created by `navigator.camera.getPicture`.
|
||||
|
||||
#### Description
|
||||
|
||||
- __setPosition__: Set the position of the popover. Takes the `CameraPopoverOptions` that specify the new position.
|
||||
|
||||
#### Supported Platforms
|
||||
|
||||
        
|
||||
|
||||
#### Example
|
||||
|
||||
var cameraPopoverHandle = navigator.camera.getPicture(onSuccess, onFail,
|
||||
{ destinationType: Camera.DestinationType.FILE_URI,
|
||||
sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
|
||||
popoverOptions: new CameraPopoverOptions(300, 300, 100, 100, Camera.PopoverArrowDirection.ARROW_ANY)
|
||||
});
|
||||
|
||||
// Reposition the popover if the orientation changes.
|
||||
window.onorientationchange = function() {
|
||||
var cameraPopoverOptions = new CameraPopoverOptions(0, 0, 100, 100, Camera.PopoverArrowDirection.ARROW_ANY);
|
||||
cameraPopoverHandle.setPosition(cameraPopoverOptions);
|
||||
}
|
||||
|
||||
## CameraPopoverOptions
|
||||
|
||||
iOS-only parameters that specify the anchor element location and arrow
|
||||
direction of the popover when selecting images from an iPad's library
|
||||
or album.
|
||||
|
||||
{ x : 0,
|
||||
y : 32,
|
||||
width : 320,
|
||||
height : 480,
|
||||
arrowDir : Camera.PopoverArrowDirection.ARROW_ANY
|
||||
};
|
||||
|
||||
#### Description
|
||||
|
||||
- __x__: x pixel coordinate of screen element onto which to anchor the popover. _(Number)_
|
||||
|
||||
- __y__: y pixel coordinate of screen element onto which to anchor the popover. _(Number)_
|
||||
|
||||
- __width__: width, in pixels, of the screen element onto which to anchor the popover. _(Number)_
|
||||
|
||||
- __height__: height, in pixels, of the screen element onto which to anchor the popover. _(Number)_
|
||||
|
||||
- __arrowDir__: Direction the arrow on the popover should point. Defined in `Camera.PopoverArrowDirection` _(Number)_
|
||||
|
||||
Camera.PopoverArrowDirection = {
|
||||
ARROW_UP : 1, // matches iOS UIPopoverArrowDirection constants
|
||||
ARROW_DOWN : 2,
|
||||
ARROW_LEFT : 4,
|
||||
ARROW_RIGHT : 8,
|
||||
ARROW_ANY : 15
|
||||
};
|
||||
|
||||
Note that the size of the popover may change to adjust to the
|
||||
direction of the arrow and orientation of the screen. Make sure to
|
||||
account for orientation changes when specifying the anchor element
|
||||
location.
|
||||
|
||||
## navigator.camera.cleanup
|
||||
|
||||
Removes intermediate photos taken by the camera from temporary
|
||||
storage.
|
||||
|
||||
navigator.camera.cleanup( cameraSuccess, cameraError );
|
||||
|
||||
#### Description
|
||||
|
||||
Removes intermediate image files that are kept in temporary storage
|
||||
after calling `camera.getPicture`. Applies only when the value of
|
||||
`Camera.sourceType` equals `Camera.PictureSourceType.CAMERA` and the
|
||||
`Camera.destinationType` equals `Camera.DestinationType.FILE_URI`.
|
||||
|
||||
#### Supported Platforms
|
||||
|
||||
        
|
||||
|
||||
#### Example
|
||||
|
||||
navigator.camera.cleanup(onSuccess, onFail);
|
||||
|
||||
function onSuccess() {
|
||||
console.log("Camera cleanup success.")
|
||||
}
|
||||
|
||||
function onFail(message) {
|
||||
alert('Failed because: ' + message);
|
||||
}
|
||||
|
185
jsdoc2md/TEMPLATE.md
Normal file
185
jsdoc2md/TEMPLATE.md
Normal file
@ -0,0 +1,185 @@
|
||||
{{>cdv-license~}}
|
||||
|
||||
# cordova-plugin-camera
|
||||
|
||||
This plugin defines a global `navigator.camera` object, which provides an API for taking pictures and for choosing images from
|
||||
the system's image library.
|
||||
|
||||
{{>cdv-header device-ready-warning-obj='navigator.camera' npmName='cordova-plugin-camera' cprName='org.apache.cordova.camera' pluginName='Plugin Camera' repoUrl='https://github.com/apache/cordova-plugin-camera' }}
|
||||
|
||||
---
|
||||
|
||||
# API Reference
|
||||
|
||||
{{#orphans~}}
|
||||
{{>member-index}}
|
||||
{{/orphans}}
|
||||
* [CameraPopoverHandle](#module_CameraPopoverHandle)
|
||||
* [CameraPopoverOptions](#module_CameraPopoverOptions)
|
||||
|
||||
---
|
||||
|
||||
{{#modules~}}
|
||||
{{>header~}}
|
||||
{{>body~}}
|
||||
{{>members~}}
|
||||
|
||||
---
|
||||
|
||||
{{/modules}}
|
||||
|
||||
## `camera.getPicture` Errata
|
||||
|
||||
#### Example <a name="camera-getPicture-examples"></a>
|
||||
|
||||
Take a photo and retrieve it as a base64-encoded image:
|
||||
|
||||
navigator.camera.getPicture(onSuccess, onFail, { quality: 50,
|
||||
destinationType: Camera.DestinationType.DATA_URL
|
||||
});
|
||||
|
||||
function onSuccess(imageData) {
|
||||
var image = document.getElementById('myImage');
|
||||
image.src = "data:image/jpeg;base64," + imageData;
|
||||
}
|
||||
|
||||
function onFail(message) {
|
||||
alert('Failed because: ' + message);
|
||||
}
|
||||
|
||||
Take a photo and retrieve the image's file location:
|
||||
|
||||
navigator.camera.getPicture(onSuccess, onFail, { quality: 50,
|
||||
destinationType: Camera.DestinationType.FILE_URI });
|
||||
|
||||
function onSuccess(imageURI) {
|
||||
var image = document.getElementById('myImage');
|
||||
image.src = imageURI;
|
||||
}
|
||||
|
||||
function onFail(message) {
|
||||
alert('Failed because: ' + message);
|
||||
}
|
||||
|
||||
#### Preferences (iOS)
|
||||
|
||||
- __CameraUsesGeolocation__ (boolean, defaults to false). For capturing JPEGs, set to true to get geolocation data in the EXIF header. This will trigger a request for geolocation permissions if set to true.
|
||||
|
||||
<preference name="CameraUsesGeolocation" value="false" />
|
||||
|
||||
#### Amazon Fire OS Quirks <a name="camera-getPicture-quirks"></a>
|
||||
|
||||
Amazon Fire OS uses intents to launch the camera activity on the device to capture
|
||||
images, and on phones with low memory, the Cordova activity may be killed. In this
|
||||
scenario, the image may not appear when the cordova activity is restored.
|
||||
|
||||
#### Android Quirks
|
||||
|
||||
Android uses intents to launch the camera activity on the device to capture
|
||||
images, and on phones with low memory, the Cordova activity may be killed. In this
|
||||
scenario, the image may not appear when the Cordova activity is restored.
|
||||
|
||||
#### Browser Quirks
|
||||
|
||||
Can only return photos as base64-encoded image.
|
||||
|
||||
#### Firefox OS Quirks
|
||||
|
||||
Camera plugin is currently implemented using [Web Activities](https://hacks.mozilla.org/2013/01/introducing-web-activities/).
|
||||
|
||||
#### iOS Quirks
|
||||
|
||||
Including a JavaScript `alert()` in either of the callback functions
|
||||
can cause problems. Wrap the alert within a `setTimeout()` to allow
|
||||
the iOS image picker or popover to fully close before the alert
|
||||
displays:
|
||||
|
||||
setTimeout(function() {
|
||||
// do your thing here!
|
||||
}, 0);
|
||||
|
||||
#### Windows Phone 7 Quirks
|
||||
|
||||
Invoking the native camera application while the device is connected
|
||||
via Zune does not work, and triggers an error callback.
|
||||
|
||||
#### Tizen Quirks
|
||||
|
||||
Tizen only supports a `destinationType` of
|
||||
`Camera.DestinationType.FILE_URI` and a `sourceType` of
|
||||
`Camera.PictureSourceType.PHOTOLIBRARY`.
|
||||
|
||||
|
||||
## `CameraOptions` Errata <a name="CameraOptions-quirks"></a>
|
||||
|
||||
#### Amazon Fire OS Quirks
|
||||
|
||||
- Any `cameraDirection` value results in a back-facing photo.
|
||||
|
||||
- Ignores the `allowEdit` parameter.
|
||||
|
||||
- `Camera.PictureSourceType.PHOTOLIBRARY` and `Camera.PictureSourceType.SAVEDPHOTOALBUM` both display the same photo album.
|
||||
|
||||
#### Android Quirks
|
||||
|
||||
- Any `cameraDirection` value results in a back-facing photo.
|
||||
|
||||
- Android also uses the Crop Activity for allowEdit, even though crop should work and actually pass the cropped image back to Cordova, the only one that works consistently is the one bundled
|
||||
with the Google Plus Photos application. Other crops may not work.
|
||||
|
||||
- `Camera.PictureSourceType.PHOTOLIBRARY` and `Camera.PictureSourceType.SAVEDPHOTOALBUM` both display the same photo album.
|
||||
|
||||
#### BlackBerry 10 Quirks
|
||||
|
||||
- Ignores the `quality` parameter.
|
||||
|
||||
- Ignores the `allowEdit` parameter.
|
||||
|
||||
- `Camera.MediaType` is not supported.
|
||||
|
||||
- Ignores the `correctOrientation` parameter.
|
||||
|
||||
- Ignores the `cameraDirection` parameter.
|
||||
|
||||
#### Firefox OS Quirks
|
||||
|
||||
- Ignores the `quality` parameter.
|
||||
|
||||
- `Camera.DestinationType` is ignored and equals `1` (image file URI)
|
||||
|
||||
- Ignores the `allowEdit` parameter.
|
||||
|
||||
- Ignores the `PictureSourceType` parameter (user chooses it in a dialog window)
|
||||
|
||||
- Ignores the `encodingType`
|
||||
|
||||
- Ignores the `targetWidth` and `targetHeight`
|
||||
|
||||
- `Camera.MediaType` is not supported.
|
||||
|
||||
- Ignores the `correctOrientation` parameter.
|
||||
|
||||
- Ignores the `cameraDirection` parameter.
|
||||
|
||||
#### iOS Quirks
|
||||
|
||||
- When using `destinationType.FILE_URI`, photos are saved in the application's temporary directory. The contents of the application's temporary directory is deleted when the application ends.
|
||||
|
||||
#### Tizen Quirks
|
||||
|
||||
- options not supported
|
||||
|
||||
- always returns a FILE URI
|
||||
|
||||
#### Windows Phone 7 and 8 Quirks
|
||||
|
||||
- Ignores the `allowEdit` parameter.
|
||||
|
||||
- Ignores the `correctOrientation` parameter.
|
||||
|
||||
- Ignores the `cameraDirection` parameter.
|
||||
|
||||
- Ignores the `saveToPhotoAlbum` parameter. IMPORTANT: All images taken with the wp7/8 cordova camera API are always copied to the phone's camera roll. Depending on the user's settings, this could also mean the image is auto-uploaded to their OneDrive. This could potentially mean the image is available to a wider audience than your app intended. If this a blocker for your application, you will need to implement the CameraCaptureTask as documented on msdn : [http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh394006.aspx](http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh394006.aspx)
|
||||
You may also comment or up-vote the related issue in the [issue tracker](https://issues.apache.org/jira/browse/CB-2083)
|
||||
|
||||
- Ignores the `mediaType` property of `cameraOptions` as the Windows Phone SDK does not provide a way to choose videos from PHOTOLIBRARY.
|
11
package.json
11
package.json
@ -41,6 +41,15 @@
|
||||
"peerDependencies": {
|
||||
"cordova-plugin-file": ">=2.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"precommit": "npm run gen-docs && git add README.md",
|
||||
"gen-docs": "jsdoc2md --template \"jsdoc2md/TEMPLATE.md\" \"www/**/*.js\" --plugin \"dmd-plugin-cordova-plugin\" > README.md"
|
||||
},
|
||||
"author": "Apache Software Foundation",
|
||||
"license": "Apache 2.0"
|
||||
"license": "Apache 2.0",
|
||||
"devDependencies": {
|
||||
"dmd-plugin-cordova-plugin": "^0.1.0",
|
||||
"husky": "^0.10.1",
|
||||
"jsdoc-to-markdown": "^1.2.0"
|
||||
}
|
||||
}
|
||||
|
121
www/Camera.js
121
www/Camera.js
@ -25,6 +25,13 @@ var argscheck = require('cordova/argscheck'),
|
||||
// XXX: commented out
|
||||
//CameraPopoverHandle = require('./CameraPopoverHandle');
|
||||
|
||||
/**
|
||||
* @namespace navigator
|
||||
*/
|
||||
|
||||
/**
|
||||
* @exports camera
|
||||
*/
|
||||
var cameraExport = {};
|
||||
|
||||
// Tack on the Camera Constants to the base camera plugin.
|
||||
@ -33,14 +40,95 @@ for (var key in Camera) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a picture from source defined by "options.sourceType", and returns the
|
||||
* image as defined by the "options.destinationType" option.
|
||||
* Callback function that provides an error message.
|
||||
* @callback module:camera.onError
|
||||
* @param {string} message - The message is provided by the device's native code.
|
||||
*/
|
||||
|
||||
* The defaults are sourceType=CAMERA and destinationType=FILE_URI.
|
||||
/**
|
||||
* Callback function that provides the image data.
|
||||
* @callback module:camera.onSuccess
|
||||
* @param {string} imageData - Base64 encoding of the image data, _or_ the image file URI, depending on [`cameraOptions`]{@link module:camera.CameraOptions} in effect.
|
||||
* @example
|
||||
* // Show image
|
||||
* //
|
||||
* function cameraCallback(imageData) {
|
||||
* var image = document.getElementById('myImage');
|
||||
* image.src = "data:image/jpeg;base64," + imageData;
|
||||
* }
|
||||
*/
|
||||
|
||||
/**
|
||||
* Optional parameters to customize the camera settings.
|
||||
* * [Quirks](#CameraOptions-quirks)
|
||||
* @typedef module:camera.CameraOptions
|
||||
* @type {Object}
|
||||
* @property {number} [quality=50] - Quality of the saved image, expressed as a range of 0-100, where 100 is typically full resolution with no loss from file compression. (Note that information about the camera's resolution is unavailable.)
|
||||
* @property {module:Camera.DestinationType} [destinationType=FILE_URI] - Choose the format of the return value.
|
||||
* @property {module:Camera.PictureSourceType} [sourceType=CAMERA] - Set the source of the picture.
|
||||
* @property {Boolean} [allowEdit=true] - Allow simple editing of image before selection.
|
||||
* @property {module:Camera.EncodingType} [encodingType=JPEG] - Choose the returned image file's encoding.
|
||||
* @property {number} [targetWidth] - Width in pixels to scale image. Must be used with `targetHeight`. Aspect ratio remains constant.
|
||||
* @property {number} [targetHeight] - Height in pixels to scale image. Must be used with `targetWidth`. Aspect ratio remains constant.
|
||||
* @property {module:Camera.MediaType} [mediaType=PICTURE] - Set the type of media to select from. Only works when `PictureSourceType` is `PHOTOLIBRARY` or `SAVEDPHOTOALBUM`.
|
||||
* @property {Boolean} [correctOrientation] - Rotate the image to correct for the orientation of the device during capture.
|
||||
* @property {Boolean} [saveToPhotoAlbum] - Save the image to the photo album on the device after capture.
|
||||
* @property {module:CameraPopoverOptions} [popoverOptions] - iOS-only options that specify popover location in iPad.
|
||||
* @property {module:Camera.Direction} [cameraDirection=BACK] - Choose the camera to use (front- or back-facing).
|
||||
*/
|
||||
|
||||
/**
|
||||
* @description Takes a photo using the camera, or retrieves a photo from the device's
|
||||
* image gallery. The image is passed to the success callback as a
|
||||
* base64-encoded `String`, or as the URI for the image file.
|
||||
*
|
||||
* @param {Function} successCallback
|
||||
* @param {Function} errorCallback
|
||||
* @param {Object} options
|
||||
* The `camera.getPicture` function opens the device's default camera
|
||||
* application that allows users to snap pictures by default - this behavior occurs,
|
||||
* when `Camera.sourceType` equals [`Camera.PictureSourceType.CAMERA`]{@link module:Camera.PictureSourceType}.
|
||||
* Once the user snaps the photo, the camera application closes and the application is restored.
|
||||
*
|
||||
* If `Camera.sourceType` is `Camera.PictureSourceType.PHOTOLIBRARY` or
|
||||
* `Camera.PictureSourceType.SAVEDPHOTOALBUM`, then a dialog displays
|
||||
* that allows users to select an existing image. The
|
||||
* `camera.getPicture` function returns a [`CameraPopoverHandle`]{@link module:CameraPopoverHandle} object,
|
||||
* which can be used to reposition the image selection dialog, for
|
||||
* example, when the device orientation changes.
|
||||
*
|
||||
* The return value is sent to the [`cameraSuccess`]{@link module:camera.onSuccess} callback function, in
|
||||
* one of the following formats, depending on the specified
|
||||
* `cameraOptions`:
|
||||
*
|
||||
* - A `String` containing the base64-encoded photo image.
|
||||
*
|
||||
* - A `String` representing the image file location on local storage (default).
|
||||
*
|
||||
* You can do whatever you want with the encoded image or URI, for
|
||||
* example:
|
||||
*
|
||||
* - Render the image in an `<img>` tag, as in the example below
|
||||
*
|
||||
* - Save the data locally (`LocalStorage`, [Lawnchair](http://brianleroux.github.com/lawnchair/), etc.)
|
||||
*
|
||||
* - Post the data to a remote server
|
||||
*
|
||||
* __NOTE__: Photo resolution on newer devices is quite good. Photos
|
||||
* selected from the device's gallery are not downscaled to a lower
|
||||
* quality, even if a `quality` parameter is specified. To avoid common
|
||||
* memory problems, set `Camera.destinationType` to `FILE_URI` rather
|
||||
* than `DATA_URL`.
|
||||
*
|
||||
* __Supported Platforms__
|
||||
*
|
||||
*         
|
||||
*
|
||||
* * [More examples](#camera-getPicture-examples)
|
||||
*
|
||||
* * [Quirks](#camera-getPicture-quirks)
|
||||
* @example
|
||||
* navigator.camera.getPicture(cameraSuccess, cameraError, cameraOptions);
|
||||
* @param {module:camera.onSuccess} successCallback
|
||||
* @param {module:camera.onError} errorCallback
|
||||
* @param {module:camera.CameraOptions} options CameraOptions
|
||||
*/
|
||||
cameraExport.getPicture = function(successCallback, errorCallback, options) {
|
||||
argscheck.checkArgs('fFO', 'Camera.getPicture', arguments);
|
||||
@ -68,6 +156,27 @@ cameraExport.getPicture = function(successCallback, errorCallback, options) {
|
||||
//return new CameraPopoverHandle();
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes intermediate image files that are kept in temporary storage
|
||||
* after calling [`camera.getPicture`]{@link module:camera.getPicture}. Applies only when the value of
|
||||
* `Camera.sourceType` equals `Camera.PictureSourceType.CAMERA` and the
|
||||
* `Camera.destinationType` equals `Camera.DestinationType.FILE_URI`.
|
||||
*
|
||||
* __Supported Platforms__
|
||||
*
|
||||
*         
|
||||
*
|
||||
* @example
|
||||
* navigator.camera.cleanup(onSuccess, onFail);
|
||||
*
|
||||
* function onSuccess() {
|
||||
* console.log("Camera cleanup success.")
|
||||
* }
|
||||
*
|
||||
* function onFail(message) {
|
||||
* alert('Failed because: ' + message);
|
||||
* }
|
||||
*/
|
||||
cameraExport.cleanup = function(successCallback, errorCallback) {
|
||||
exec(successCallback, errorCallback, "Camera", "cleanup", []);
|
||||
};
|
||||
|
@ -19,35 +19,70 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @module Camera
|
||||
*/
|
||||
module.exports = {
|
||||
/**
|
||||
* @enum {number}
|
||||
*/
|
||||
DestinationType:{
|
||||
DATA_URL: 0, // Return base64 encoded string
|
||||
FILE_URI: 1, // Return file uri (content://media/external/images/media/2 for Android)
|
||||
NATIVE_URI: 2 // Return native uri (eg. asset-library://... for iOS)
|
||||
/** Return base64 encoded string */
|
||||
DATA_URL: 0,
|
||||
/** Return file uri (content://media/external/images/media/2 for Android) */
|
||||
FILE_URI: 1,
|
||||
/** Return native uri (eg. asset-library://... for iOS) */
|
||||
NATIVE_URI: 2
|
||||
},
|
||||
/**
|
||||
* @enum {number}
|
||||
*/
|
||||
EncodingType:{
|
||||
JPEG: 0, // Return JPEG encoded image
|
||||
PNG: 1 // Return PNG encoded image
|
||||
/** Return JPEG encoded image */
|
||||
JPEG: 0,
|
||||
/** Return PNG encoded image */
|
||||
PNG: 1
|
||||
},
|
||||
/**
|
||||
* @enum {number}
|
||||
*/
|
||||
MediaType:{
|
||||
PICTURE: 0, // allow selection of still pictures only. DEFAULT. Will return format specified via DestinationType
|
||||
VIDEO: 1, // allow selection of video only, ONLY RETURNS URL
|
||||
ALLMEDIA : 2 // allow selection from all media types
|
||||
/** Allow selection of still pictures only. DEFAULT. Will return format specified via DestinationType */
|
||||
PICTURE: 0,
|
||||
/** Allow selection of video only, ONLY RETURNS URL */
|
||||
VIDEO: 1,
|
||||
/** Allow selection from all media types */
|
||||
ALLMEDIA : 2
|
||||
},
|
||||
/**
|
||||
* @enum {number}
|
||||
*/
|
||||
PictureSourceType:{
|
||||
PHOTOLIBRARY : 0, // Choose image from picture library (same as SAVEDPHOTOALBUM for Android)
|
||||
CAMERA : 1, // Take picture from camera
|
||||
SAVEDPHOTOALBUM : 2 // Choose image from picture library (same as PHOTOLIBRARY for Android)
|
||||
/** Choose image from picture library (same as SAVEDPHOTOALBUM for Android) */
|
||||
PHOTOLIBRARY : 0,
|
||||
/** Take picture from camera */
|
||||
CAMERA : 1,
|
||||
/** Choose image from picture library (same as PHOTOLIBRARY for Android) */
|
||||
SAVEDPHOTOALBUM : 2
|
||||
},
|
||||
/**
|
||||
* Matches iOS UIPopoverArrowDirection constants to specify arrow location on popover.
|
||||
* @enum {number}
|
||||
*/
|
||||
PopoverArrowDirection:{
|
||||
ARROW_UP : 1, // matches iOS UIPopoverArrowDirection constants to specify arrow location on popover
|
||||
ARROW_UP : 1,
|
||||
ARROW_DOWN : 2,
|
||||
ARROW_LEFT : 4,
|
||||
ARROW_RIGHT : 8,
|
||||
ARROW_ANY : 15
|
||||
},
|
||||
/**
|
||||
* @enum {number}
|
||||
*/
|
||||
Direction:{
|
||||
/** Use the back-facing camera */
|
||||
BACK: 0,
|
||||
/** Use the front-facing camera */
|
||||
FRONT: 1
|
||||
}
|
||||
};
|
||||
|
@ -22,6 +22,7 @@
|
||||
var exec = require('cordova/exec');
|
||||
|
||||
/**
|
||||
* @ignore in favour of ios' one
|
||||
* A handle to an image picker popover.
|
||||
*/
|
||||
var CameraPopoverHandle = function() {
|
||||
|
@ -22,15 +22,30 @@
|
||||
var Camera = require('./Camera');
|
||||
|
||||
/**
|
||||
* Encapsulates options for iOS Popover image picker
|
||||
* @namespace navigator
|
||||
*/
|
||||
var CameraPopoverOptions = function(x,y,width,height,arrowDir){
|
||||
|
||||
/**
|
||||
* iOS-only parameters that specify the anchor element location and arrow
|
||||
* direction of the popover when selecting images from an iPad's library
|
||||
* or album.
|
||||
* Note that the size of the popover may change to adjust to the
|
||||
* direction of the arrow and orientation of the screen. Make sure to
|
||||
* account for orientation changes when specifying the anchor element
|
||||
* location.
|
||||
* @module CameraPopoverOptions
|
||||
* @param {Number} [x=0] - x pixel coordinate of screen element onto which to anchor the popover.
|
||||
* @param {Number} [y=32] - y pixel coordinate of screen element onto which to anchor the popover.
|
||||
* @param {Number} [width=320] - width, in pixels, of the screen element onto which to anchor the popover.
|
||||
* @param {Number} [height=480] - height, in pixels, of the screen element onto which to anchor the popover.
|
||||
* @param {module:Camera.PopoverArrowDirection} [arrowDir=ARROW_ANY] - Direction the arrow on the popover should point.
|
||||
*/
|
||||
var CameraPopoverOptions = function (x, y, width, height, arrowDir) {
|
||||
// information of rectangle that popover should be anchored to
|
||||
this.x = x || 0;
|
||||
this.y = y || 32;
|
||||
this.width = width || 320;
|
||||
this.height = height || 480;
|
||||
// The direction of the popover arrow
|
||||
this.arrowDir = arrowDir || Camera.PopoverArrowDirection.ARROW_ANY;
|
||||
};
|
||||
|
||||
|
@ -21,10 +21,36 @@
|
||||
|
||||
var exec = require('cordova/exec');
|
||||
|
||||
/**
|
||||
* @namespace navigator
|
||||
*/
|
||||
|
||||
/**
|
||||
* A handle to an image picker popover.
|
||||
*
|
||||
* __Supported Platforms__
|
||||
*
|
||||
*         
|
||||
*
|
||||
* @example
|
||||
* var cameraPopoverHandle = navigator.camera.getPicture(onSuccess, onFail,
|
||||
* {
|
||||
* destinationType: Camera.DestinationType.FILE_URI,
|
||||
* sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
|
||||
* popoverOptions: new CameraPopoverOptions(300, 300, 100, 100, Camera.PopoverArrowDirection.ARROW_ANY)
|
||||
* });
|
||||
*
|
||||
* // Reposition the popover if the orientation changes.
|
||||
* window.onorientationchange = function() {
|
||||
* var cameraPopoverOptions = new CameraPopoverOptions(0, 0, 100, 100, Camera.PopoverArrowDirection.ARROW_ANY);
|
||||
* cameraPopoverHandle.setPosition(cameraPopoverOptions);
|
||||
* }
|
||||
* @module CameraPopoverHandle
|
||||
*/
|
||||
var CameraPopoverHandle = function() {
|
||||
/** Set the position of the popover.
|
||||
* @param {module:CameraPopoverOptions} popoverOptions
|
||||
*/
|
||||
this.setPosition = function(popoverOptions) {
|
||||
var args = [ popoverOptions ];
|
||||
exec(null, null, "Camera", "repositionPopover", args);
|
||||
|
Loading…
x
Reference in New Issue
Block a user