Barcode Scanner add button inside scanning page - ionic-framework

I have implemented Barcode Scanner for my Ionic project for both iOS and Android.
But when my Scanner starts, I want to add a button inside the view and add an event to it.
I am using phonegap-plugin-barcodescanner plugin
Please help me with how to append something inside the scanning view.

If you want to add stuff to the layout of your scanner, you need to write code in the plugin itself.
YOU CANNOT INTERACT DIRECTLY WITH THE SCANNER FROM THE JS.
In fact, the plugin you use uses cordova.exec in order to launch the scanner view by passing it arguments.
For Android, you just have to know Java and some XML.
For iOS, you have to know Objective-C / Swift.
For Android, you may have 4 files to modify :
plugin.xml : home of all you dependencies
Your_Activity.java : java file which permits to interact with the scanner view itself by calling buttons, textviews, layouts, etc...
Your_Main.java : java file which gets and returns parameters from the js file of your plugin
Your_Layout.xml : xml file in res/layout which is composed of xml attributes interpreted by java
Beside that, I found two good plug-ins for cordova/ionic apps from GitHub :
phonegap/phonegap-plugin-barcodescanner
tjwoon/csZBar
And there's the expensive one, Scandit, which resolves all of your problems for about 200$ per month, check the pricing for every solution they propose.
If you use their SDK, you may be able to interact with the scanner view from js files because of their work, but they're the only company I know to do that. (perhaps ManateeWorks...)
Under this part is what I've been doing since mid-July, in order to give you ideas.
I'm currently making an ANDROID scanner layout for my ionic app.
You can find my GitHub repository here, I forked it from tjwoon's csZBar and I added some stuff my ionic app needs.
I guarantee nothing, but I'm pretty sure I'll implement an iOS layout soon (at least I'll try), and unfortunately I don't really know android / iOS mobile programming.
Here's a screenshot of the layout
I made a "tab bar" composed of 3 image buttons, a "top bar" composed of text views & image buttons. The scanner is embedded between these two.
There are pop-ups for the app's features, which pause the scanner and respond to click events.
See the README and Java files (csZBar/android/) for more information.
Don't hesitate to ask questions and/or inspect my code.
Warning
1) It's currently on development so use it at your own risks (use branch master, not develop)
2) I only modified the android part, not the iOS!
3) It doesn't work for Windows phone...

After adding plugin, installngCordova with bower install ngCordova
Add link to ng-cordova.js JS file above reference to cordova.js:
index.html
<script src="lib/ngCordova/dist/ng-cordova.js"></script>
<script src="cordova.js"></script>
Also, don't forget to add ngCordova module:
app.js
angular.module('myApp', ['ngCordova'])
Now you're ready to use the plugin like this:
Controller:
var module = angular.module('starter.controllers', []);
module.controller('BarcodeCtrl', function($scope, $cordovaBarcodeScanner, $ionicPlatform) {
$ionicPlatform.ready(function(){
$scope.scan = function() {
$cordovaBarcodeScanner
.scan()
.then(function(barcodeData) {
alert(JSON.stringify(barcodeData));
}, function(error) {
alert(error);
});
};
});
});
View:
<button ng-click="scan()">Scan</button>

Related

Customizing page transitions with Convertigo

I am currently building a cross-platform mobile application with Convertigo Studio, and the iOS default transition between pages does not fit well with the design : I would like the transitions between pages in the iOS app to be identical to the Android ones.
I have narrowed the problem to the Ionic navCtrl.push() call, probably made by the Convertigo PushPage component.
According to this blog post, it is possible to force transitions with the animation field of the call configuration object :
this.navCtrl.push(MyPageComponent, null, {animate: true, animation: "transition-android"});
Convertigo Studio allows me to edit the animate and duration fields, but not animation.
Without patching the Studio, is there a way to override the iOS default page transition ?
Yes in 7.5.7 version Convertigo studio does not expose the transition type property for push pages. This has been added in 7.6
Nevertheless, you can customize your template (The mobilebuildet_tpl_7_5_7 project in the workspace) the add a default transition into the app module this way :
in ionicTpl/src/app/app.module.ts
Change line
IonicModule.forRoot(MyApp, {}, deepLinkConfig)
to
IonicModule.forRoot(MyApp, {
pageTransition: 'ios-transition'
}, deepLinkConfig)
This way, all page transitions can be set to iOS or Android mode whatever the app runs on.
Do not forget to reload your project (Right click on project->Reload your project) to have the MobileBuilder to regenerate the Ionic project sources and re-execute the app viewer to rebuild the app.
Hope That Helps !

MobileFirst 7.1 BusyIndicator showing weird characters

I'm developing an hybrid app on MobileFirst 7.1, with Ionic libraries.
In a .js file I globally define
var busyIndicator = new WL.BusyIndicator ("content", {text: "DUMMY TEXT"});
but when I call for it to show, i.e.
busyIndicator.show();
I always get the same message, ignoring the text I put in the text field:
Image link here
I'm testing this on Android devices (Huawei P7 Ascend, Samsung Galaxy J5, both with Android 5.1). On the Android Mobile Simulator the message displays just fine.
p.s. "content" matches my html id, I tried putting null instead of "content" but to no avail.
A workaround
define in some common .js file
function showMyIndicator() {
busyIndicator.__options.text="Custom loading text";
busyIndicator.show();
}
and call showMyIndicator() each time you would call busyIndicator.show().
busyIndicator.hide() can be called normally (although you might want to define some 'hideMyIndicator()' function for homogeneity).
What is happening?
It appears that, as soon as I load (jQuery $.load() ) some new content in order to change page, the text fileld of the busyIndicator object defaults to "[(')ههههههه Loading]", which is defined in every native project inside messages.json.
That file is full of those weird signs, no idea about why.
Update
There's something corrupted in my project which causes those .json files to be generated with wrong characters, a freshly generated project didn't show the same issues so creating a new one and move the resources in there might do the trick.

what's happens with transition pages in iPhone

why i having a problem in the iPhone but android work good
problem usually occurs between the pages in IOS
for example :
when go to other page usually go and back in the same time without click the back button .
You should use the fix recommended by Ionic team:
https://gist.github.com/IgorMinar/863acd413e3925bf282c
Place downloaded file into www/js folder.
Add script tag in index.html: <script src="js/ngIOS9UIWebViewPatch.js"></script>
Add new dependency in app.js: angular.module('myApp', ['ngRoute', 'ngIOS9UIWebViewPatch'])
More info about that bug: http://blog.ionic.io/preparing-for-ios-9/

Webview elements inspection for testing

We have a web view in our app which is being detected as a single webpage element (android.webkit.WebView). not showing the layout hierarchy to inspect individual UI components. I have tried to inspect the elements using 'UI Automator Viewer' and 'Appium Inspector' and same results. Is there any other tool which can be used for inspecting web views? Please advise!
UIAutomatorViewer is able to see native elements only. Everything underneath WebView is web elements. You need to switch from native to web context.
Link
This functionality was broken in Android Lollipop but appears to have recently been fixed with Android System Webview v44, try upgrading webview and inspecting then

Native HTML5 Drag and Drop in Mobile Safari (iPad, iPod, iPhone)?

I've successfully implemented native HTML5 Drag and Drop for moving HTML elements inside a page (just, say, a div from one place to another, nothing related to interacting with the host OS' files whatsoever). This works fine in Chrome and Safari on a PC but I can't start a drag operation in my iPad's Safari.
I've found this so far:
Using Drag and Drop From JavaScript
Safari, Dashboard, and WebKit-based
applications include support for
customizing the behavior of drag and
drop operations within your HTML
pages.
Note: This technology is supported
only on desktop versions of Safari.
For iPhone OS, use DOM Touch,
described in Handling Events (part of
Safari Web Content Guide) and Safari
DOM Additions Reference.
Here. But it's outdated (2009-06-08).
Doe's anyone know if it is possible to use native HTML5 in Mobile Safari? (I don't want javascript-framework like solutions like jQuery UI).
Thanks!
I've just been trying to get native drag&drop working in ios safari (ipad pro with 14.0.1), and I'm updating this answer as it kept coming up as my first google result (and no other q&a seems to be up to date).
Following https://developer.apple.com/library/archive/documentation/AppleApplications/Conceptual/SafariJSProgTopics/DragAndDrop.html
I have found native html5 drag&drop now works in safari, with a few specific notes;
You MUST set some data in OnDragStart's event; (the effect settings seem to be optional) Event.dataTransfer.setData('text/plain', 'hello');
you MUST Event.preventDefault(); in OnDrop otherwise safari will load the data you added (unless that's your intention)
OnDragOver event handler needs Event.preventDefault(); otherwise drop fails (unless intended, as docuemnted)
On ios safari, if you set OnDragStart's Event.dataTransfer.dropEffect='copy' and in OnDragOver's Event.dataTransfer.dropEffect='link' the drop fails (no OnDrop()); Seems to be the only combination that fails
I thought you required
CSS -webkit-user-drag: Element; and `-webkit-user-drop: element;
or if you prefer
Element.style.setProperty('webkitUserDrag','element');
Element.style.setProperty('webkitUserDrop','element');
but it seems just the usual draggable attribute is enough
Element.setAttribute('draggable',true);
This seems to be the bare minimum to drag & drop an element
Element.setAttribute('draggable',true);
function OnDragOver(Event)
{
Element.setAttribute('DragOver',true);
Event.stopPropagation(); // let child accept and don't pass up to parent element
Event.preventDefault(); // ios to accept drop
Event.dataTransfer.dropEffect = 'copy';// move has no icon? adding copy shows +
}
function OnDragLeave(Event)
{
Element.removeAttribute('DragOver');
}
function OnDrop(Event)
{
Element.removeAttribute('DragOver');
Event.preventDefault(); // dont let page attempt to load our data
Event.stopPropagation();
}
function OnDragStart(Event)
{
Event.stopPropagation(); // let child take the drag
Event.dataTransfer.dropEffect = 'move';
Event.dataTransfer.setData('text/plain', 'hello');
}
Element.addEventListener('dragstart',OnDragStart);
Element.addEventListener('drop',OnDrop);
Element.addEventListener('dragover',OnDragOver);
Element.addEventListener('dragleave',OnDragLeave);
Touch events do work now on Safari too (including Mobile). This article has nice code snippets that you can start from:
http://www.html5rocks.com/en/mobile/touch/