Skip to content

Commit c82d87d

Browse files
Dimitar TachevDimitar Tachev
authored andcommitted
Improved the dimensions logging in the demos, remove unused method, bump the version.
1 parent f1cfeb5 commit c82d87d

File tree

4 files changed

+33
-22
lines changed

4 files changed

+33
-22
lines changed

demo-angular/app/app.component.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { Component } from '@angular/core';
22
import { takePicture, requestPermissions } from 'nativescript-camera';
33
import { ImageSource } from 'tns-core-modules/image-source';
44
import { ImageAsset } from 'tns-core-modules/image-asset';
5+
import { layout } from 'tns-core-modules/utils/utils';
6+
import * as app from "tns-core-modules/application";
57

68
@Component({
79
selector: 'my-app',
@@ -13,12 +15,22 @@ export class AppComponent {
1315

1416
onTakePictureTap(args) {
1517
takePicture({ width: 180, height: 180, keepAspectRatio: true, saveToGallery: this.saveToGallery })
16-
.then((imageAsset) => {
18+
.then((imageAsset: any) => {
19+
this.cameraImage = imageAsset;
20+
21+
// if you need image source
1722
let source = new ImageSource();
1823
source.fromAsset(imageAsset).then((source) => {
19-
console.log(`Size: ${source.width}x${source.height}`);
24+
let width = source.width;
25+
let height = source.height;
26+
if (app.android) {
27+
// the android dimensions are in device pixels
28+
width = layout.toDeviceIndependentPixels(width);
29+
height = layout.toDeviceIndependentPixels(height);
30+
}
31+
32+
console.log(`Size: ${width}x${height}`);
2033
});
21-
this.cameraImage = imageAsset;
2234
}, (error) => {
2335
console.log("Error: " + error);
2436
});

demo/app/main-page.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { View } from 'tns-core-modules/ui/core/view';
44
import { takePicture, requestPermissions } from "nativescript-camera";
55
import * as appModule from "tns-core-modules/application";
66
import * as imageSourceModule from "tns-core-modules/image-source";
7+
import { layout } from 'tns-core-modules/utils/utils';
8+
import * as app from "tns-core-modules/application";
79

810
import * as trace from "tns-core-modules/trace";
911
trace.addCategories(trace.categories.Debug);
@@ -13,7 +15,7 @@ export function navigatingTo(args: EventData) {
1315
let page = <Page>args.object;
1416
let picturePath = null;
1517

16-
page.bindingContext = fromObject({cameraImage: picturePath, saveToGallery: true});
18+
page.bindingContext = fromObject({ cameraImage: picturePath, saveToGallery: true });
1719
}
1820

1921
export function onRequestPermissionsTap(args: EventData) {
@@ -26,13 +28,23 @@ export function onRequestPermissionsTap(args: EventData) {
2628
export function onTakePictureTap(args: EventData) {
2729
let page = <Page>(<View>args.object).page;
2830
let saveToGallery = page.bindingContext.get("saveToGallery");
29-
takePicture({width: 180, height: 180, keepAspectRatio: true, saveToGallery: saveToGallery}).
31+
takePicture({ width: 180, height: 180, keepAspectRatio: true, saveToGallery: saveToGallery }).
3032
then((imageAsset) => {
33+
page.bindingContext.set("cameraImage", imageAsset);
34+
35+
// if you need image source
3136
let source = new imageSourceModule.ImageSource();
3237
source.fromAsset(imageAsset).then((source) => {
33-
console.log(`Size: ${source.width}x${source.height}`);
38+
let width = source.width;
39+
let height = source.height;
40+
if (app.android) {
41+
// the android dimensions are in device pixels
42+
width = layout.toDeviceIndependentPixels(width);
43+
height = layout.toDeviceIndependentPixels(height);
44+
}
45+
46+
console.log(`Size: ${width}x${height}`);
3447
});
35-
page.bindingContext.set("cameraImage", imageAsset);
3648
},
3749
(err) => {
3850
console.log("Error -> " + err.message);

src/camera.ios.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,6 @@ class UIImagePickerControllerDelegateImpl extends NSObject implements UIImagePic
3737
return this;
3838
}
3939

40-
// create date from a string with format yyyy:MM:dd HH:mm:ss (like the format used in image description)
41-
private createDateFromString(value: string): Date {
42-
let year = parseInt(value.substr(0, 4));
43-
let month = parseInt(value.substr(5, 2));
44-
let date = parseInt(value.substr(8, 2));
45-
46-
let hour = parseInt(value.substr(11, 2));
47-
let minutes = parseInt(value.substr(14, 2));
48-
let seconds = parseInt(value.substr(17, 2));
49-
50-
return new Date(year, month - 1, date, hour, minutes, seconds);
51-
}
52-
5340
imagePickerControllerDidFinishPickingMediaWithInfo(picker, info): void {
5441
if (info) {
5542
let currentDate: Date = new Date();

src/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-camera",
3-
"version": "3.1.4",
3+
"version": "3.4.0",
44
"description": "Provides API for using device camera",
55
"repository": {
66
"type": "git",
@@ -21,7 +21,7 @@
2121
"test.android": "npm i && npm run tsc && npm run tslint && cd ../demo && tns build android && tns test android --justlaunch",
2222
"test.ios": "npm i && npm run tsc && npm run tslint && cd ../demo && tns build ios && tns test ios --justlaunch",
2323
"tslint": "cd .. && tslint \"**/*.ts\" --config tslint.json --exclude \"**/node_modules/**\"",
24-
"plugin.link": "npm link && cd ../demo && npm link nativescript-camera && cd ../src",
24+
"plugin.link": "npm link && cd ../demo && npm link nativescript-camera",
2525
"plugin.tscwatch": "npm run tsc -- -w",
2626
"demo.ios": "npm i && npm run tsc && cd ../demo && tns run ios --syncAllFiles",
2727
"demo.android": "npm i && npm run tsc && cd ../demo && tns run android --syncAllFiles",

0 commit comments

Comments
 (0)