From c82d87d6e8ab6093682b5f4bf4b4a88dbdd99b46 Mon Sep 17 00:00:00 2001 From: Dimitar Tachev Date: Tue, 5 Dec 2017 15:26:31 +0200 Subject: [PATCH 1/2] Improved the dimensions logging in the demos, remove unused method, bump the version. --- demo-angular/app/app.component.ts | 18 +++++++++++++++--- demo/app/main-page.ts | 20 ++++++++++++++++---- src/camera.ios.ts | 13 ------------- src/package.json | 4 ++-- 4 files changed, 33 insertions(+), 22 deletions(-) diff --git a/demo-angular/app/app.component.ts b/demo-angular/app/app.component.ts index 62f616e..383b5dd 100644 --- a/demo-angular/app/app.component.ts +++ b/demo-angular/app/app.component.ts @@ -2,6 +2,8 @@ import { Component } from '@angular/core'; import { takePicture, requestPermissions } from 'nativescript-camera'; import { ImageSource } from 'tns-core-modules/image-source'; import { ImageAsset } from 'tns-core-modules/image-asset'; +import { layout } from 'tns-core-modules/utils/utils'; +import * as app from "tns-core-modules/application"; @Component({ selector: 'my-app', @@ -13,12 +15,22 @@ export class AppComponent { onTakePictureTap(args) { takePicture({ width: 180, height: 180, keepAspectRatio: true, saveToGallery: this.saveToGallery }) - .then((imageAsset) => { + .then((imageAsset: any) => { + this.cameraImage = imageAsset; + + // if you need image source let source = new ImageSource(); source.fromAsset(imageAsset).then((source) => { - console.log(`Size: ${source.width}x${source.height}`); + let width = source.width; + let height = source.height; + if (app.android) { + // the android dimensions are in device pixels + width = layout.toDeviceIndependentPixels(width); + height = layout.toDeviceIndependentPixels(height); + } + + console.log(`Size: ${width}x${height}`); }); - this.cameraImage = imageAsset; }, (error) => { console.log("Error: " + error); }); diff --git a/demo/app/main-page.ts b/demo/app/main-page.ts index 4afa9fd..ae4cef8 100644 --- a/demo/app/main-page.ts +++ b/demo/app/main-page.ts @@ -4,6 +4,8 @@ import { View } from 'tns-core-modules/ui/core/view'; import { takePicture, requestPermissions } from "nativescript-camera"; import * as appModule from "tns-core-modules/application"; import * as imageSourceModule from "tns-core-modules/image-source"; +import { layout } from 'tns-core-modules/utils/utils'; +import * as app from "tns-core-modules/application"; import * as trace from "tns-core-modules/trace"; trace.addCategories(trace.categories.Debug); @@ -13,7 +15,7 @@ export function navigatingTo(args: EventData) { let page = args.object; let picturePath = null; - page.bindingContext = fromObject({cameraImage: picturePath, saveToGallery: true}); + page.bindingContext = fromObject({ cameraImage: picturePath, saveToGallery: true }); } export function onRequestPermissionsTap(args: EventData) { @@ -26,13 +28,23 @@ export function onRequestPermissionsTap(args: EventData) { export function onTakePictureTap(args: EventData) { let page = (args.object).page; let saveToGallery = page.bindingContext.get("saveToGallery"); - takePicture({width: 180, height: 180, keepAspectRatio: true, saveToGallery: saveToGallery}). + takePicture({ width: 180, height: 180, keepAspectRatio: true, saveToGallery: saveToGallery }). then((imageAsset) => { + page.bindingContext.set("cameraImage", imageAsset); + + // if you need image source let source = new imageSourceModule.ImageSource(); source.fromAsset(imageAsset).then((source) => { - console.log(`Size: ${source.width}x${source.height}`); + let width = source.width; + let height = source.height; + if (app.android) { + // the android dimensions are in device pixels + width = layout.toDeviceIndependentPixels(width); + height = layout.toDeviceIndependentPixels(height); + } + + console.log(`Size: ${width}x${height}`); }); - page.bindingContext.set("cameraImage", imageAsset); }, (err) => { console.log("Error -> " + err.message); diff --git a/src/camera.ios.ts b/src/camera.ios.ts index 7b7e86a..87447bd 100644 --- a/src/camera.ios.ts +++ b/src/camera.ios.ts @@ -37,19 +37,6 @@ class UIImagePickerControllerDelegateImpl extends NSObject implements UIImagePic return this; } - // create date from a string with format yyyy:MM:dd HH:mm:ss (like the format used in image description) - private createDateFromString(value: string): Date { - let year = parseInt(value.substr(0, 4)); - let month = parseInt(value.substr(5, 2)); - let date = parseInt(value.substr(8, 2)); - - let hour = parseInt(value.substr(11, 2)); - let minutes = parseInt(value.substr(14, 2)); - let seconds = parseInt(value.substr(17, 2)); - - return new Date(year, month - 1, date, hour, minutes, seconds); - } - imagePickerControllerDidFinishPickingMediaWithInfo(picker, info): void { if (info) { let currentDate: Date = new Date(); diff --git a/src/package.json b/src/package.json index a3fe754..2a0675c 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "nativescript-camera", - "version": "3.1.4", + "version": "3.4.0", "description": "Provides API for using device camera", "repository": { "type": "git", @@ -21,7 +21,7 @@ "test.android": "npm i && npm run tsc && npm run tslint && cd ../demo && tns build android && tns test android --justlaunch", "test.ios": "npm i && npm run tsc && npm run tslint && cd ../demo && tns build ios && tns test ios --justlaunch", "tslint": "cd .. && tslint \"**/*.ts\" --config tslint.json --exclude \"**/node_modules/**\"", - "plugin.link": "npm link && cd ../demo && npm link nativescript-camera && cd ../src", + "plugin.link": "npm link && cd ../demo && npm link nativescript-camera", "plugin.tscwatch": "npm run tsc -- -w", "demo.ios": "npm i && npm run tsc && cd ../demo && tns run ios --syncAllFiles", "demo.android": "npm i && npm run tsc && cd ../demo && tns run android --syncAllFiles", From 28fe9d72586519510cce2095080936eb1c809f66 Mon Sep 17 00:00:00 2001 From: Dimitar Tachev Date: Tue, 5 Dec 2017 16:23:08 +0200 Subject: [PATCH 2/2] Improve the demos ensuring permissions requested before taking a picture. --- demo-angular/app/app.component.html | 5 +-- demo-angular/app/app.component.ts | 46 +++++++++++++-------------- demo/app/main-page.ts | 48 ++++++++++++++--------------- demo/app/main-page.xml | 5 +-- src/package.json | 2 +- 5 files changed, 48 insertions(+), 58 deletions(-) diff --git a/demo-angular/app/app.component.html b/demo-angular/app/app.component.html index b13e6a9..7c4bd42 100644 --- a/demo-angular/app/app.component.html +++ b/demo-angular/app/app.component.html @@ -4,8 +4,5 @@ - - - - + \ No newline at end of file diff --git a/demo-angular/app/app.component.ts b/demo-angular/app/app.component.ts index 383b5dd..df5a244 100644 --- a/demo-angular/app/app.component.ts +++ b/demo-angular/app/app.component.ts @@ -14,32 +14,30 @@ export class AppComponent { public cameraImage: ImageAsset; onTakePictureTap(args) { - takePicture({ width: 180, height: 180, keepAspectRatio: true, saveToGallery: this.saveToGallery }) - .then((imageAsset: any) => { - this.cameraImage = imageAsset; - - // if you need image source - let source = new ImageSource(); - source.fromAsset(imageAsset).then((source) => { - let width = source.width; - let height = source.height; - if (app.android) { - // the android dimensions are in device pixels - width = layout.toDeviceIndependentPixels(width); - height = layout.toDeviceIndependentPixels(height); - } + requestPermissions().then( + () => { + takePicture({ width: 180, height: 180, keepAspectRatio: true, saveToGallery: this.saveToGallery }) + .then((imageAsset: any) => { + this.cameraImage = imageAsset; - console.log(`Size: ${width}x${height}`); - }); - }, (error) => { - console.log("Error: " + error); - }); - } + // if you need image source + let source = new ImageSource(); + source.fromAsset(imageAsset).then((source) => { + let width = source.width; + let height = source.height; + if (app.android) { + // the android dimensions are in device pixels + width = layout.toDeviceIndependentPixels(width); + height = layout.toDeviceIndependentPixels(height); + } - onRequestPermissionsTap() { - requestPermissions().then( - () => console.log('got permissions'), - () => console.log('permissions rejected') + console.log(`Size: ${width}x${height}`); + }); + }, (error) => { + console.log("Error: " + error); + }); + }, + () => alert('permissions rejected') ); } } diff --git a/demo/app/main-page.ts b/demo/app/main-page.ts index ae4cef8..fb46ca3 100644 --- a/demo/app/main-page.ts +++ b/demo/app/main-page.ts @@ -18,35 +18,33 @@ export function navigatingTo(args: EventData) { page.bindingContext = fromObject({ cameraImage: picturePath, saveToGallery: true }); } -export function onRequestPermissionsTap(args: EventData) { - requestPermissions().then( - () => console.log('got permissions'), - () => console.log('permissions rejected') - ); -} - export function onTakePictureTap(args: EventData) { let page = (args.object).page; let saveToGallery = page.bindingContext.get("saveToGallery"); - takePicture({ width: 180, height: 180, keepAspectRatio: true, saveToGallery: saveToGallery }). - then((imageAsset) => { - page.bindingContext.set("cameraImage", imageAsset); + requestPermissions().then( + () => { + takePicture({ width: 180, height: 180, keepAspectRatio: true, saveToGallery: saveToGallery }). + then((imageAsset) => { + page.bindingContext.set("cameraImage", imageAsset); - // if you need image source - let source = new imageSourceModule.ImageSource(); - source.fromAsset(imageAsset).then((source) => { - let width = source.width; - let height = source.height; - if (app.android) { - // the android dimensions are in device pixels - width = layout.toDeviceIndependentPixels(width); - height = layout.toDeviceIndependentPixels(height); - } + // if you need image source + let source = new imageSourceModule.ImageSource(); + source.fromAsset(imageAsset).then((source) => { + let width = source.width; + let height = source.height; + if (app.android) { + // the android dimensions are in device pixels + width = layout.toDeviceIndependentPixels(width); + height = layout.toDeviceIndependentPixels(height); + } - console.log(`Size: ${width}x${height}`); - }); + console.log(`Size: ${width}x${height}`); + }); + }, + (err) => { + console.log("Error -> " + err.message); + }); }, - (err) => { - console.log("Error -> " + err.message); - }); + () => alert('permissions rejected') + ); } \ No newline at end of file diff --git a/demo/app/main-page.xml b/demo/app/main-page.xml index 9779999..a99150d 100644 --- a/demo/app/main-page.xml +++ b/demo/app/main-page.xml @@ -5,9 +5,6 @@ - -