Skip to content

Improved the dimensions logging in the demos, remove unused method, bump the version. #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions demo-angular/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@
<Switch [(ngModel)]="saveToGallery"></Switch>
</StackLayout>
<Image row="1" [src]="cameraImage" stretch="fill" margin="10"></Image>
<StackLayout orientation="horizontal" row="2" padding="10">
<Button text="Take Picture" (tap)='onTakePictureTap($event)'></Button>
<Button text="Request Permissions" (tap)='onRequestPermissionsTap()'></Button>
</StackLayout>
<Button text="Take Picture" (tap)='onTakePictureTap($event)' row="2" padding="10"></Button>
</GridLayout>
40 changes: 25 additions & 15 deletions demo-angular/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -12,22 +14,30 @@ export class AppComponent {
public cameraImage: ImageAsset;

onTakePictureTap(args) {
takePicture({ width: 180, height: 180, keepAspectRatio: true, saveToGallery: this.saveToGallery })
.then((imageAsset) => {
let source = new ImageSource();
source.fromAsset(imageAsset).then((source) => {
console.log(`Size: ${source.width}x${source.height}`);
});
this.cameraImage = imageAsset;
}, (error) => {
console.log("Error: " + error);
});
}

onRequestPermissionsTap() {
requestPermissions().then(
() => console.log('got permissions'),
() => console.log('permissions rejected')
() => {
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);
}

console.log(`Size: ${width}x${height}`);
});
}, (error) => {
console.log("Error: " + error);
});
},
() => alert('permissions rejected')
);
}
}
46 changes: 28 additions & 18 deletions demo/app/main-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -13,28 +15,36 @@ export function navigatingTo(args: EventData) {
let page = <Page>args.object;
let picturePath = null;

page.bindingContext = fromObject({cameraImage: picturePath, saveToGallery: true});
}

export function onRequestPermissionsTap(args: EventData) {
requestPermissions().then(
() => console.log('got permissions'),
() => console.log('permissions rejected')
);
page.bindingContext = fromObject({ cameraImage: picturePath, saveToGallery: true });
}

export function onTakePictureTap(args: EventData) {
let page = <Page>(<View>args.object).page;
let saveToGallery = page.bindingContext.get("saveToGallery");
takePicture({width: 180, height: 180, keepAspectRatio: true, saveToGallery: saveToGallery}).
then((imageAsset) => {
let source = new imageSourceModule.ImageSource();
source.fromAsset(imageAsset).then((source) => {
console.log(`Size: ${source.width}x${source.height}`);
});
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);
}

console.log(`Size: ${width}x${height}`);
});
},
(err) => {
console.log("Error -> " + err.message);
});
},
(err) => {
console.log("Error -> " + err.message);
});
() => alert('permissions rejected')
);
}
5 changes: 1 addition & 4 deletions demo/app/main-page.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
<Switch checked="{{ saveToGallery }}"/>
</StackLayout>
<Image row="1" src="{{ cameraImage }}" id="image" stretch="fill" margin="10"/>
<StackLayout orientation="horizontal" row="2" padding="10">
<Button text="Take Picture" tap="onTakePictureTap" />
<Button text="Request Permissions" tap="onRequestPermissionsTap" />
</StackLayout>
<Button text="Take Picture" tap="onTakePictureTap" row="2" padding="10"/>
</GridLayout>
</Page>
13 changes: 0 additions & 13 deletions src/camera.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nativescript-camera",
"version": "3.1.4",
"version": "3.2.0",
"description": "Provides API for using device camera",
"repository": {
"type": "git",
Expand All @@ -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",
Expand Down