Skip to content

Commit

Permalink
analyze and restart
Browse files Browse the repository at this point in the history
  • Loading branch information
matiastucci committed May 19, 2016
1 parent 22ca537 commit 114e16c
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 8 deletions.
14 changes: 13 additions & 1 deletion app/pages/home/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,20 @@

<ion-content class="home" padding>

<div class="start" (click)="presentActionSheet()">
<div class="start" *ngIf="!srcImage" (click)="presentActionSheet()">
<ion-icon name="camera"></ion-icon>
</div>

<div *ngIf="srcImage" class="">
<img id="image" src="{{ srcImage }}" />
<button block (click)="analyze()">
<ion-icon name="search"></ion-icon>
Read
</button>
<button block (click)="restart()">
<ion-icon name="refresh"></ion-icon>
Restart
</button>
</div>

</ion-content>
55 changes: 48 additions & 7 deletions app/pages/home/home.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,77 @@
import {Platform, Page, NavController, ActionSheet} from 'ionic-angular';
import {Page, Loading, NavController, ActionSheet} from 'ionic-angular';
import {Camera} from 'ionic-native';

@Page({
templateUrl: 'build/pages/home/home.html'
})
export class HomePage {
constructor(private platform: Platform, private nav: NavController) { }

srcImage: string;

constructor(private nav: NavController) { }

presentActionSheet() {
let actionSheet = ActionSheet.create({
buttons: [
{
text: 'Choose Photo',
handler: () => {
console.log('Choose Photo');
this.getPicture(0); // 1 == Library
}
},
{
text: 'Take Photo',
handler: () => {
console.log('Take Photo');
this.getPicture(1); // 1 == Camera
}
},
{
text: 'Cancel',
role: 'cancel',
text: 'Demo Photo',
handler: () => {
console.log('Cancel clicked');
this.srcImage = 'demo.png';
}
},
{
text: 'Cancel',
role: 'cancel'
}
]
});
this.nav.present(actionSheet);
}

getPicture (sourceType: number) {
// You can check the values here:
// https://github.com/driftyco/ionic-native/blob/master/src/plugins/camera.ts
Camera.getPicture({
quality: 100,
destinationType: 0, // DATA_URL
sourceType: sourceType,
allowEdit: true,
saveToPhotoAlbum: false,
correctOrientation: true
}).then(imageData => {
this.srcImage = `data:image/jpeg;base64,${imageData}`;
}, error => {
console.log(`ERROR -> ${JSON.stringify(error)}`);
});
}

analyze () {
let loading = Loading.create({
content: 'Reading...'
});
this.nav.present(loading);
OCRAD(document.getElementById('image'), text => {
loading.dismiss();
console.log(text);
alert(text);
});
}

restart () {
this.srcImage = '';
this.presentActionSheet();
}

}

0 comments on commit 114e16c

Please sign in to comment.