desmistificando o phonegap (cordova)

74
Desmistificando o PhoneGap/Cordova Loiane Groner http://loiane.com

Upload: loiane-groner

Post on 05-Aug-2015

553 views

Category:

Technology


5 download

TRANSCRIPT

Page 1: Desmistificando o Phonegap (Cordova)

Desmistificando o PhoneGap/Cordova

Loiane Groner http://loiane.com

Page 2: Desmistificando o Phonegap (Cordova)

• 9+ XP TI

• Java, Sencha, Phonegap

• http://loiane.com

• @loiane

• Meus livros:

Loiane Groner

Page 3: Desmistificando o Phonegap (Cordova)

Motivação

Page 4: Desmistificando o Phonegap (Cordova)

Preciso de uma APP

Page 5: Desmistificando o Phonegap (Cordova)
Page 6: Desmistificando o Phonegap (Cordova)

IDE Emulador Store Usuário final

IDE Emulador Store Usuário final

IDE Emulador Store Usuário final

Page 7: Desmistificando o Phonegap (Cordova)
Page 8: Desmistificando o Phonegap (Cordova)

Phonegap

Page 9: Desmistificando o Phonegap (Cordova)

Framework JavaScript open source para desenvolvimento de apps mobile híbridas

Page 10: Desmistificando o Phonegap (Cordova)

Híbrido?

Page 11: Desmistificando o Phonegap (Cordova)
Page 12: Desmistificando o Phonegap (Cordova)

Nativo Web

Page 13: Desmistificando o Phonegap (Cordova)
Page 14: Desmistificando o Phonegap (Cordova)
Page 15: Desmistificando o Phonegap (Cordova)
Page 16: Desmistificando o Phonegap (Cordova)

Como funciona

Page 17: Desmistificando o Phonegap (Cordova)

Seu Código

Page 18: Desmistificando o Phonegap (Cordova)

Web View Nativa (Browser)Seu Código

Page 19: Desmistificando o Phonegap (Cordova)

APIs Nativas

Web View Nativa (Browser)Seu Código

Page 20: Desmistificando o Phonegap (Cordova)

App Nativa: .apk, .ipa, etcAPIs Nativas

Web View Nativa (Browser)Seu Código

Page 21: Desmistificando o Phonegap (Cordova)
Page 22: Desmistificando o Phonegap (Cordova)

Interface de uma app phonegap

É uma instância do browser nativo

100% largura e altura

Browser nativo (WebView)sem barra de favoritos

sem barra para mudar url

Page 23: Desmistificando o Phonegap (Cordova)

O que instalar

Page 24: Desmistificando o Phonegap (Cordova)

Phonegap CLI Corvova CLI

Page 25: Desmistificando o Phonegap (Cordova)

http://nodejs.org/

Page 26: Desmistificando o Phonegap (Cordova)

sudo npm install -g cordova

sudo npm install -g phonegap

Linux ou Mac OS

Page 27: Desmistificando o Phonegap (Cordova)

npm install -g cordova

npm install -g phonegap

Windows

Page 28: Desmistificando o Phonegap (Cordova)

Phonegap Phonegap Dev App

Phonegap Build Phonegap Enterprise

Cordova Comunidade Código fonte

Plugins APIs

Ponte com plataforma nativa

Page 29: Desmistificando o Phonegap (Cordova)

Criando um projeto

Page 30: Desmistificando o Phonegap (Cordova)

phonegap create hello com.loiane.hello HelloWorld

cordova create hello com.loiane.hello HelloWorld

Page 31: Desmistificando o Phonegap (Cordova)

Testando e emulando localmente

Page 32: Desmistificando o Phonegap (Cordova)
Page 33: Desmistificando o Phonegap (Cordova)

Plugins:

acesso recursos do device

Page 34: Desmistificando o Phonegap (Cordova)
Page 35: Desmistificando o Phonegap (Cordova)

cordova plugin add org.apache.cordova.camera

phonegap plugin add org.apache.cordova.camera

Page 36: Desmistificando o Phonegap (Cordova)

cordova plugin add cordova-plugin-camera

> 5.x

https://www.npmjs.com/package/cordova-plugin-camera

Page 37: Desmistificando o Phonegap (Cordova)

function capturePhoto() { navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50, destinationType: destinationType.DATA_URL }); }

Page 38: Desmistificando o Phonegap (Cordova)

function capturePhoto() { navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50, destinationType: destinationType.DATA_URL }); }

function onPhotoDataSuccess(imageData) { var smallImage = document.getElementById('smallImage'); smallImage.style.display = 'block'; smallImage.src = "data:image/jpeg;base64," + imageData; }

Page 39: Desmistificando o Phonegap (Cordova)

function capturePhoto() { navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50, destinationType: destinationType.DATA_URL }); }

function onPhotoDataSuccess(imageData) { var smallImage = document.getElementById('smallImage'); smallImage.style.display = 'block'; smallImage.src = "data:image/jpeg;base64," + imageData; }

<button onclick="capturePhoto();">Capturar foto</button> <br> <img style="display:none;" id="smallImage" src="" />

Page 40: Desmistificando o Phonegap (Cordova)
Page 41: Desmistificando o Phonegap (Cordova)

import android.app.Activity;import android.content.Intent;import android.graphics.Bitmap;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.ImageView;

public class MyCameraActivity extends Activity { private static final int CAMERA_REQUEST = 1888; private ImageView imageView;

@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); this.imageView = (ImageView)this.findViewById(R.id.imageView1); Button photoButton = (Button) this.findViewById(R.id.button1); photoButton.setOnClickListener(new View.OnClickListener() {

@Override public void onClick(View v) { Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(cameraIntent, CAMERA_REQUEST); } }); }

protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) { Bitmap photo = (Bitmap) data.getExtras().get("data"); imageView.setImageBitmap(photo); } } }

Page 42: Desmistificando o Phonegap (Cordova)

- (BOOL) startCameraControllerFromViewController: (UIViewController*) controller usingDelegate: (id <UIImagePickerControllerDelegate, UINavigationControllerDelegate>) delegate { if (([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera] == NO) || (delegate == nil) || (controller == nil)) return NO; UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init]; cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera; // Displays a control that allows the user to choose picture or // movie capture, if both are available: cameraUI.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType: UIImagePickerControllerSourceTypeCamera]; // Hides the controls for moving & scaling pictures, or for // trimming movies. To instead show the controls, use YES. cameraUI.allowsEditing = NO; cameraUI.delegate = delegate; [controller presentModalViewController: cameraUI animated: YES]; return YES;}

Page 43: Desmistificando o Phonegap (Cordova)

// Check to see if the camera is available on the device.if (PhotoCaptureDevice.AvailableSensorLocations.Contains(CameraSensorLocation.Back) || PhotoCaptureDevice.AvailableSensorLocations.Contains(CameraSensorLocation.Front)){ // Initialize the camera, when available. if (PhotoCaptureDevice.AvailableSensorLocations.Contains(CameraSensorLocation.Back)) { // Use the back camera. System.Collections.Generic.IReadOnlyList<Windows.Foundation.Size> SupportedResolutions = PhotoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Back); Windows.Foundation.Size res = SupportedResolutions[0]; this.captureDevice = await PhotoCaptureDevice.OpenAsync(CameraSensorLocation.Back, res); } else { // Otherwise, use the front camera. System.Collections.Generic.IReadOnlyList<Windows.Foundation.Size> SupportedResolutions = PhotoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Front); Windows.Foundation.Size res = SupportedResolutions[0]; this.captureDevice = await PhotoCaptureDevice.OpenAsync(CameraSensorLocation.Front, res); } ... ... ...

//Set the VideoBrush source to the camera. viewfinderBrush.SetSource(this.captureDevice);

// The event is fired when the shutter button receives a half press. CameraButtons.ShutterKeyHalfPressed += OnButtonHalfPress;

// The event is fired when the shutter button receives a full press. CameraButtons.ShutterKeyPressed += OnButtonFullPress;

// The event is fired when the shutter button is released. CameraButtons.ShutterKeyReleased += OnButtonRelease; }else{ // The camera is not available. this.Dispatcher.BeginInvoke(delegate() { // Write message. txtDebug.Text = "A Camera is not available on this phone."; });}

Page 44: Desmistificando o Phonegap (Cordova)

Trabalhando com Views

Page 45: Desmistificando o Phonegap (Cordova)
Page 46: Desmistificando o Phonegap (Cordova)

Topcoat

DOM

Architecture

UI

Full Stack

Page 47: Desmistificando o Phonegap (Cordova)
Page 48: Desmistificando o Phonegap (Cordova)
Page 49: Desmistificando o Phonegap (Cordova)

<ion-tabs>

<ion-tab title="Home" icon="ion-home"> <ion-nav-view name="home"></ion-nav-view> </ion-tab>

<ion-tab title="About" icon="ion-information"> <ion-nav-view name="about"></ion-nav-view> </ion-tab>

<ion-tab title="Contact" icon="ion-ios7-world"> <ion-nav-view name="contact"></ion-nav-view> </ion-tab>

</ion-tabs>

Page 50: Desmistificando o Phonegap (Cordova)

Fazendo build

Page 51: Desmistificando o Phonegap (Cordova)

Enviando pra App Store

Page 52: Desmistificando o Phonegap (Cordova)
Page 53: Desmistificando o Phonegap (Cordova)

cordova platform add android

Add Plataforma

phonegap platform add android

Page 54: Desmistificando o Phonegap (Cordova)
Page 55: Desmistificando o Phonegap (Cordova)
Page 56: Desmistificando o Phonegap (Cordova)

Phonegap Build

apps open source: grátis (github)apps código privado: pago

Page 57: Desmistificando o Phonegap (Cordova)
Page 58: Desmistificando o Phonegap (Cordova)
Page 59: Desmistificando o Phonegap (Cordova)
Page 60: Desmistificando o Phonegap (Cordova)
Page 61: Desmistificando o Phonegap (Cordova)
Page 62: Desmistificando o Phonegap (Cordova)

Processo de enviar para apps store é nativo

Page 63: Desmistificando o Phonegap (Cordova)

Processo de enviar para apps store é nativo

Page 64: Desmistificando o Phonegap (Cordova)

Exemplos de Apps

Page 65: Desmistificando o Phonegap (Cordova)

http://phonegap.com/app/

Page 66: Desmistificando o Phonegap (Cordova)

http://showcase.ionicframework.com/

Page 67: Desmistificando o Phonegap (Cordova)

http://www.jqmgallery.com/

Page 68: Desmistificando o Phonegap (Cordova)
Page 69: Desmistificando o Phonegap (Cordova)
Page 70: Desmistificando o Phonegap (Cordova)

Quero Aprender!

Page 71: Desmistificando o Phonegap (Cordova)
Page 72: Desmistificando o Phonegap (Cordova)

Topcoat

DOM

Architecture

UI

Full Stack

Page 73: Desmistificando o Phonegap (Cordova)

http://loiane.com

fb.com/loianegroner

@loiane

https://github.com/loiane

youtube.com/user/Loianeg

Page 74: Desmistificando o Phonegap (Cordova)

Obrigada!