camera function cc (#683)

This commit is contained in:
oblomov 2023-11-27 19:48:30 +01:00 committed by GitHub
parent 77201b6aa2
commit 4ba878fc69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 176 additions and 1 deletions

View File

@ -0,0 +1,132 @@
CLASS z2ui5_cl_cc_camera_picture DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
CLASS-METHODS get_js
RETURNING
VALUE(r_js) TYPE string.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS z2ui5_cl_cc_camera_picture IMPLEMENTATION.
METHOD get_js.
r_js = ` debugger; jQuery.sap.declare("z2ui5.CameraPicture"); sap.ui.require([` && |\n| &&
` "sap/ui/core/Control"` && |\n| &&
`], function (Control) {` && |\n| &&
` "use strict";` && |\n| &&
` return Control.extend("z2ui5.CameraPicture", {` && |\n| &&
` metadata: {` && |\n| &&
` properties: {` && |\n| &&
` id: { type: "string" },` && |\n| &&
` value: { type: "string" },` && |\n| &&
` press: { type: "string" },` && |\n| &&
` autoplay: { type: "boolean", defaultValue: true }` && |\n| &&
` },` && |\n| &&
` events: {` && |\n| &&
` "OnPhoto": {` && |\n| &&
` allowPreventDefault: true,` && |\n| &&
` parameters: {` && |\n| &&
` "photo": {` && |\n| &&
` type: "string"` && |\n| &&
` }` && |\n| &&
` }` && |\n| &&
` }` && |\n| &&
` },` && |\n| &&
` },` && |\n| &&
|\n| &&
` capture: function (oEvent) {` && |\n| &&
|\n| &&
` var video = document.querySelector("#zvideo");` && |\n| &&
` var canvas = document.getElementById('zcanvas');` && |\n| &&
` var resultb64 = "";` && |\n| &&
` canvas.width = 200;` && |\n| &&
` canvas.height = 200;` && |\n| &&
` canvas.getContext('2d').drawImage(video, 0, 0, 200, 200);` && |\n| &&
` resultb64 = canvas.toDataURL();` && |\n| &&
` this.setProperty("value", resultb64);` && |\n| &&
` this.fireOnPhoto({` && |\n| &&
` "photo": resultb64` && |\n| &&
` });` && |\n| &&
` },` && |\n| &&
|\n| &&
` onPicture: function (oEvent) {` && |\n| &&
|\n| &&
` if (!this._oScanDialog) {` && |\n| &&
` this._oScanDialog = new sap.m.Dialog({` && |\n| &&
` title: "Device Photo Function",` && |\n| &&
` contentWidth: "640px",` && |\n| &&
` contentHeight: "480px",` && |\n| &&
` horizontalScrolling: false,` && |\n| &&
` verticalScrolling: false,` && |\n| &&
` stretchOnPhone: true,` && |\n| &&
` content: [` && |\n| &&
` new sap.ui.core.HTML({` && |\n| &&
` id: this.getId() + 'PictureContainer',` && |\n| &&
` content: '<video width="600px" height="400px" autoplay="true" id="zvideo">'` && |\n| &&
` }),` && |\n| &&
` new sap.m.Button({` && |\n| &&
` text: "Capture",` && |\n| &&
` press: function (oEvent) {` && |\n| &&
` this.capture();` && |\n| &&
` this._oScanDialog.close();` && |\n| &&
` }.bind(this)` && |\n| &&
` }),` && |\n| &&
` new sap.ui.core.HTML({` && |\n| &&
` content: '<canvas hidden id="zcanvas" style="overflow:auto"></canvas>'` && |\n| &&
` }),` && |\n| &&
` ],` && |\n| &&
` endButton: new sap.m.Button({` && |\n| &&
` text: "Cancel",` && |\n| &&
` press: function (oEvent) {` && |\n| &&
` this._oScanDialog.close();` && |\n| &&
` }.bind(this)` && |\n| &&
` }),` && |\n| &&
` });` && |\n| &&
` }` && |\n| &&
|\n| &&
` this._oScanDialog.open();` && |\n| &&
|\n| &&
` setTimeout(function () {` && |\n| &&
` var video = document.querySelector('#zvideo');` && |\n| &&
` if (navigator.mediaDevices.getUserMedia) {` && |\n| &&
` navigator.mediaDevices.getUserMedia({video: { facingMode: { exact: "environment" } } })` && |\n| &&
` // navigator.mediaDevices.enumerateDevices({ video: true })` && |\n| &&
` .then(function (stream) {` && |\n| &&
` debugger; video.srcObject = stream;` && |\n| &&
` })` && |\n| &&
` .catch(function (err0r) {` && |\n| &&
` console.log("Something went wrong!");` && |\n| &&
` });` && |\n| &&
` }` && |\n| &&
` }.bind(this), 300);` && |\n| &&
|\n| &&
` },` && |\n| &&
|\n| &&
` renderer: function (oRM, oControl) {` && |\n| &&
|\n| &&
` var oButton = new sap.m.Button({` && |\n| &&
` icon: "sap-icon://camera",` && |\n| &&
` text: "Camera",` && |\n| &&
` press: oControl.onPicture.bind(oControl),` && |\n| &&
` });` && |\n| &&
` oRM.renderControl(oButton);` && |\n| &&
|\n| &&
` },` && |\n| &&
` });` && |\n| &&
`});`.
ENDMETHOD.
ENDCLASS.

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>Z2UI5_CL_CC_CAMERA_PICTURE</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>MediaService - take a picture</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>

View File

@ -5,6 +5,16 @@ CLASS z2ui5_cl_xml_view_cc DEFINITION
PUBLIC SECTION.
METHODS camera_picture
IMPORTING
id TYPE clike OPTIONAL
value TYPE clike OPTIONAL
press TYPE clike OPTIONAL
autoplay TYPE clike OPTIONAL
OnPhoto TYPE clike OPTIONAL
RETURNING
VALUE(result) TYPE REF TO z2ui5_cl_xml_view.
METHODS bwip_js
IMPORTING
bcid TYPE clike OPTIONAL
@ -278,4 +288,19 @@ endmethod.
ENDMETHOD.
METHOD camera_picture.
result = mo_view.
mo_view->_generic( name = `CameraPicture`
ns = `z2ui5`
t_prop = VALUE #(
( n = `id` v = id )
( n = `value` v = value )
( n = `press` v = press )
( n = `OnPhoto` v = OnPhoto )
( n = `autoplay` v = z2ui5_cl_fw_utility=>boolean_abap_2_json( autoplay ) )
) ).
ENDMETHOD.
ENDCLASS.

View File

@ -456,9 +456,11 @@ CLASS Z2UI5_CL_FW_HTTP_HANDLER IMPLEMENTATION.
` definition: sap.z2ui5.oResponse.PARAMS.S_VIEW.XML,` && |\n| &&
` controller: sap.z2ui5.oController,` && |\n| &&
` }).then(oView => {` && |\n| &&
` try{` && |\n| &&
` var oview_model = new sap.ui.model.json.JSONModel(sap.z2ui5.oResponse.OVIEWMODEL);` && |\n| &&
` oview_model.setSizeLimit(sap.z2ui5.JSON_MODEL_LIMIT);` && |\n| &&
` oView.setModel(oview_model);` && |\n| &&
` try { oView.setModel(oview_model); } catch (e) { oView.setModel(oview_model); }` && |\n| &&
` } catch (e){ sap.m.MessageBox.error( 'Error while creating Main View - ' + e.message); }` && |\n| &&
` if (sap.z2ui5.oParent) {` && |\n| &&
` sap.z2ui5.oParent.removeAllPages();` && |\n| &&
` sap.z2ui5.oParent.insertPage(oView);` && |\n| &&