Skip to content

Commit 5d98e67

Browse files
Dimitar TachevDimitar Tachev
Dimitar Tachev
authored and
Dimitar Tachev
committed
Unify structure with the plugin seed.
1 parent ec78dfa commit 5d98e67

File tree

167 files changed

+2531
-75
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

167 files changed

+2531
-75
lines changed

.github/issue_template.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
### Make sure to check the demo app(s) for sample usage
2+
3+
### Make sure to check the existing issues in this repository
4+
5+
### If the demo apps cannot help and there is no issue for your problem, tell us about it
6+
Please, ensure your title is less than 63 characters long and starts with a capital
7+
letter.
8+
9+
### Which platform(s) does your issue occur on?
10+
- iOS/Android/Both
11+
- iOS/Android versions
12+
- emulator or device. What type of device?
13+
14+
### Please, provide the following version numbers that your issue occurs with:
15+
16+
- CLI: (run `tns --version` to fetch it)
17+
- Cross-platform modules: (check the 'version' attribute in the
18+
`node_modules/tns-core-modules/package.json` file in your project)
19+
- Runtime(s): (look for the `"tns-android"` and `"tns-ios"` properties in the `package.json` file of your project)
20+
- Plugin(s): (look for the version numbers in the `package.json` file of your
21+
project and paste your dependencies and devDependencies here)
22+
23+
### Please, tell us how to recreate the issue in as much detail as possible.
24+
Describe the steps to reproduce it.
25+
26+
### Is there any code involved?
27+
- provide a code example to recreate the problem
28+
- (EVEN BETTER) provide a .zip with application or refer to a repository with application where the problem is reproducible.

.gitignore

Lines changed: 22 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,24 @@
1-
# Logs
2-
logs
3-
*.log
4-
npm-debug.log*
1+
.vscode
2+
.idea
53
.DS_Store
6-
7-
# Runtime data
8-
pids
9-
*.pid
10-
*.seed
11-
12-
# Directory for instrumented libs generated by jscoverage/JSCover
13-
lib-cov
14-
15-
# Coverage directory used by tools like istanbul
16-
coverage
17-
18-
# nyc test coverage
19-
.nyc_output
20-
21-
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
22-
.grunt
23-
24-
# node-waf configuration
25-
.lock-wscript
26-
27-
# Compiled binary addons (http://nodejs.org/api/addons.html)
28-
build/Release
29-
30-
# Dependency directories
4+
*.js
5+
*.js.map
6+
*.log
7+
src/*.d.ts
8+
!src/index.d.ts
9+
!src/references.d.ts
10+
!src/scripts/*.js
11+
!seed-tests/*.js
12+
seed-tests/seed-copy/**/*.*
13+
seed-tests/seed-copy-new-git-repo/**/*.*
14+
!demo*/karma.conf.js
15+
!demo*/app/tests/*.js
16+
demo*/*.d.ts
17+
!demo*/references.d.ts
18+
demo*/lib
19+
demo*/platforms
3120
node_modules
32-
platforms
33-
jspm_packages
34-
35-
# Optional npm cache directory
36-
.npm
37-
38-
# Optional REPL history
39-
.node_repl_history
40-
41-
#Exclude all javascript (js) and (js.map) files from source code
42-
**/*.js
43-
**/*.map
44-
!examples/CameraTestAngular/webpack.*.js
45-
46-
# Dist directory where create script produces plugin installation files
47-
dist
48-
49-
# Ignoring .vscode (Visual Studio Code) internal directory
50-
.vscode
21+
publish/src
22+
publish/package
23+
demo*/report/report.html
24+
demo*/report/stats.json

.travis.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
matrix:
2+
include:
3+
- stage: "Lint"
4+
language: node_js
5+
os: linux
6+
node_js: "6"
7+
script: cd src && npm run ci.tslint && cd ../demo && npm run ci.tslint
8+
- stage: "WebPack"
9+
os: osx
10+
env:
11+
- Platform="iOS"
12+
osx_image: xcode8.3
13+
language: node_js
14+
node_js: "6"
15+
jdk: oraclejdk8
16+
script: cd demo && npm run build.plugin && npm i && npm run build-ios-bundle
17+
- language: android
18+
os: linux
19+
env:
20+
- Platform="Android"
21+
jdk: oraclejdk8
22+
before_install: nvm install 6.10.3
23+
script: cd demo && npm run build.plugin && npm i && npm run build-android-bundle
24+
- stage: "Build and Test"
25+
env:
26+
- BuildAndroid="25"
27+
language: android
28+
os: linux
29+
jdk: oraclejdk8
30+
before_install: nvm install stable
31+
script:
32+
- cd src && npm i && npm run tsc && cd ../demo && tns build android
33+
- os: osx
34+
env:
35+
- BuildiOS="10.3"
36+
- Xcode="8.3"
37+
osx_image: xcode8.3
38+
language: node_js
39+
node_js: "6"
40+
jdk: oraclejdk8
41+
script:
42+
- cd src && npm i && npm run tsc && cd ../demo && tns build ios
43+
- os: linux
44+
language: android
45+
dist: precise
46+
sudo: required
47+
jdk: oraclejdk8
48+
before_script:
49+
- echo no | android create avd --force -n test -t android-21 -b armeabi-v7a
50+
- emulator -avd test -no-audio -no-window &
51+
- android-wait-for-emulator
52+
before_install:
53+
- nvm install 6
54+
script: cd src && npm run test.android
55+
- os: osx
56+
language: node_js
57+
node_js: "6"
58+
jdk: oraclejdk8
59+
osx_image: xcode8.3
60+
script: cd src && npm run test.ios
61+
62+
android:
63+
components:
64+
- tools
65+
- platform-tools
66+
- build-tools-25.0.2
67+
- android-25
68+
- extra-android-m2repository
69+
- sys-img-armeabi-v7a-android-21
70+
71+
install:
72+
- echo no | npm install -g nativescript
73+
- tns usage-reporting disable
74+
- tns error-reporting disable

README.md

Lines changed: 148 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,152 @@
1-
# nativescript-camera
2-
NativeScript plugin to empower using device camera.
1+
# NativeScript Camera
32

4-
## Build
3+
Welcome to the `nativescript-camera` plugin for NativeScript framework
54

6-
Run the create script in the root of the repo:
5+
## (Optional) Prerequisites / Requirements
6+
7+
- installed [NativeScript-CLI](https://github.com/NativeScript/nativescript-cli)
8+
9+
# Working with the camera plugin
10+
11+
## Overview
12+
13+
Almost every mobile application needs the option to capture, save and share images.
14+
The NativeScript camera plugin was designed for the first two parts of the job (taking a picture and optionally saving to device storage).
15+
16+
## Installation
17+
18+
Navigate to project folder and run NativeScript-CLI command
19+
```
20+
tns plugin add nativescript-camera
21+
```
22+
23+
Plugin could be added as a standard npm dependency running command
24+
```
25+
npm install nativescript-camera --save
26+
```
27+
28+
> Note: the `--save` flag will add the plugin as dependency in your package.json file
29+
30+
### Requesting permissions
31+
32+
Newer API levels of Android and iOS versions are requiring explicit permissions in order the application
33+
to have access to the camera and to be able to save photos to the device. Once the user has granted permissions the camera module can be used.
34+
35+
```
36+
camera.requestPermissions();
37+
```
38+
39+
> Note: Older versions won't be affected by the usage of the requestPermissions method.
40+
41+
## Usage
42+
43+
### Requesting permissions
44+
45+
Newer API levels of Android and iOS versions are requiring explicit permissions in order the application
46+
to have access to the camera and to be able to save photos to the device. Once the user has granted permissions the camera module can be used.
47+
48+
```
49+
camera.requestPermissions();
50+
```
51+
52+
> Note: Older versions won't be affected by the usage of the requestPermissions method.
53+
54+
### Using the camera module to take a picture
55+
56+
Using the camera module is relatively simple.
57+
However, there are some points that need a little bit more explanation.
58+
59+
In order to use the camera module, just require it, as shown in Example 1:
60+
61+
> Example 1: Require camera module in the application
62+
``` JavaScript
63+
var camera = require("nativescript-camera");
64+
```
65+
``` TypeScript
66+
import * as camera from "nativescript-camera";
767
```
8-
./create.sh
68+
69+
Then you are ready to use it:
70+
> Example 2: How to take a picture and to recieve image asset
71+
``` JavaScript
72+
var imageModule = require("ui/image");
73+
camera.takePicture()
74+
.then(function (imageAsset) {
75+
console.log("Result is an image asset instance");
76+
var image = new imageModule.Image();
77+
image.src = imageAsset;
78+
}).catch(function (err) {
79+
console.log("Error -> " + err.message);
80+
});
81+
```
82+
``` TypeScript
83+
import { Image } from "ui/image";
84+
camera.takePicture({).
85+
then((imageAsset) => {
86+
console.log("Result is an image asset instance");
87+
var image = new Image();
88+
image.src = imageAsset;
89+
}).catch((err) => {
90+
console.log("Error -> " + err.message);
91+
});
992
```
10-
This will create a `nativescript-camera-*.tgz` file (* stands for version) within ./dist folder.
93+
94+
The code in __Example 2__ will start the native platform camera application. After taking the picture and tapping the button `Save` (Android) or `use image` (iOS), the promise will resolve the `then` part and image asset will be set as `src` of the `ui/image` control.
95+
96+
### Using the options to take memory efficient picture
97+
98+
__Example 2__ shows how to take a picture using the NativeScript camera module. However, it takes a huge image (even mid-level devices has a 5MP camera, which results in a image 2580x2048, which in bitmap means approximately 15 MB). In many cases you don't need such a huge picture to show an image with 100x100 size, so taking a big picture is just a waste of memory. The camera takePicture() method accepts an optional parameter that could help in that case. With that optional parameter, you could set some properties like:
99+
100+
* __width__: The desired width of the picture (in device independent pixels).
101+
* __height__: The desired height of the picture (in device independent pixels).
102+
* __keepAspectRatio__: A boolean parameter that indicates if the aspect ratio should be kept.
103+
* __saveToGallery__: A boolean parameter that indicates if the taken photo will be saved in "Photos" for Android and in "Camera Roll" in iOS
104+
* __cameraFacing__: Start with either the "front" or "rear" (default) camera of the device. The current implementation doesn't work on all Android devices, in which case it falls back to the default behavior.
105+
106+
What does `device independent pixels` mean? The NativeScript layout mechanism uses device-independent pixels when measuring UI controls. This allows you to declare one layout and this layout will look similar to all devices (no matter the device's display resolution). In order to get a proper image quality for high resolution devices (like iPhone retina and Android Full HD), camera will return an image with bigger dimensions. For example, if we request an image that is 100x100, on iPhone 6 the actual image will be 200x200 (since its display density factor is 2 -> 100*2x100*2).
107+
Setting the `keepAspectRatio` property could result in a different than requested width or height. The camera will return an image with the correct aspect ratio but generally only one (from width and height) will be the same as requested; the other value will be calculated in order to preserve the aspect of the original image.
108+
109+
__Example 3__ shows how to use the options parameter:
110+
> Example 3: How to setup `width`, `height`, `keepAspectRatio` and `saveToGallery` properties for the camera module
111+
112+
``` JavaScript
113+
var imageModule = require("ui/image");
114+
115+
var options = { width: 300, height: 300, keepAspectRatio: false, saveToGallery: true };
116+
camera.takePicture(options)
117+
.then(function (imageAsset) {
118+
console.log("Size: " + imageAsset.options.width + "x" + imageAsset.options.height);
119+
console.log("keepAspectRatio: " + imageAsset.options.keepAspectRatio);
120+
console.log("Photo saved in Photos/Gallery for Android or in Camera Roll for iOS");
121+
}).catch(function (err) {
122+
console.log("Error -> " + err.message);
123+
});
124+
```
125+
``` TypeScript
126+
import { Image } from "ui/image";
127+
128+
var options = { width: 300, height: 300, keepAspectRatio: false, saveToGallery: true };
129+
camera.takePicture(options).
130+
then((imageAsset) => {
131+
console.log("Size: " + imageAsset.options.width + "x" + imageAsset.options.height);
132+
console.log("keepAspectRatio: " + imageAsset.options.keepAspectRatio);
133+
console.log("Photo saved in Photos/Gallery for Android or in Camera Roll for iOS");
134+
}).catch((err) => {
135+
console.log("Error -> " + err.message);
136+
});
137+
```
138+
139+
### Check if the device has available camera
140+
141+
The first thing that the developers should check if the device has an available camera.
142+
The method isAvaiable will return true if the camera hardware is ready to use or false if otherwise.
143+
144+
```
145+
var isAvailable = camera.isAvailable();
146+
```
147+
148+
> Note: This method will return false when used in iOS simulator (as the simulator does not have camera hardware)
149+
150+
## License
151+
152+
Apache License Version 2.0, January 2004

demo-angular/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Example for using nativescript-camera plugin
2+
## This example demonstrates how to use plugin with nativescript-angular and webpack
3+
4+
Steps to start example.
5+
6+
1. npm install
7+
2. Due to a bug with the used version of @angular, a single line from file
8+
node_modules/@angular/compiler/index.js (line 38: export * from './src/template_parser/template_ast';) should be deleted, since its duplicated.
9+
3. tns platform add android - to add platform before starting webpack process
10+
4. npm run start-android
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="__PACKAGE__"
4+
android:versionCode="1"
5+
android:versionName="1.0">
6+
7+
<supports-screens
8+
android:smallScreens="true"
9+
android:normalScreens="true"
10+
android:largeScreens="true"
11+
android:xlargeScreens="true"/>
12+
13+
<uses-sdk
14+
android:minSdkVersion="17"
15+
android:targetSdkVersion="__APILEVEL__"/>
16+
17+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
18+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
19+
<uses-permission android:name="android.permission.INTERNET"/>
20+
21+
<application
22+
android:name="com.tns.NativeScriptApplication"
23+
android:allowBackup="true"
24+
android:icon="@drawable/icon"
25+
android:label="@string/app_name"
26+
android:theme="@style/AppTheme">
27+
28+
<activity
29+
android:name="com.tns.NativeScriptActivity"
30+
android:label="@string/title_activity_kimera"
31+
android:configChanges="keyboardHidden|orientation|screenSize"
32+
android:theme="@style/LaunchScreenTheme">
33+
34+
<meta-data android:name="SET_THEME_ON_LAUNCH" android:resource="@style/AppTheme" />
35+
36+
<intent-filter>
37+
<action android:name="android.intent.action.MAIN" />
38+
<category android:name="android.intent.category.LAUNCHER" />
39+
</intent-filter>
40+
</activity>
41+
<activity android:name="com.tns.ErrorReportActivity"/>
42+
</application>
43+
</manifest>

0 commit comments

Comments
 (0)